-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
36 lines (36 loc) · 16.7 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(a){return a.raw=a};$jscomp.createTemplateTagFirstArgWithRaw=function(a,b){a.raw=b;return a};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};$jscomp.getGlobal=function(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(a,b){var c=$jscomp.propertyToPolyfillSymbol[b];if(null==c)return a[b];c=a[c];return void 0!==c?c:a[b]};
$jscomp.polyfill=function(a,b,c,d){b&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(a,b,c,d):$jscomp.polyfillUnisolated(a,b,c,d))};$jscomp.polyfillUnisolated=function(a,b,c,d){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))return;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})};
$jscomp.polyfillIsolated=function(a,b,c,d){var e=a.split(".");a=1===e.length;d=e[0];d=!a&&d in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var f=0;f<e.length-1;f++){var g=e[f];if(!(g in d))return;d=d[g]}e=e[e.length-1];c=$jscomp.IS_SYMBOL_NATIVE&&"es6"===c?d[e]:null;b=b(c);null!=b&&(a?$jscomp.defineProperty($jscomp.polyfills,e,{configurable:!0,writable:!0,value:b}):b!==c&&($jscomp.propertyToPolyfillSymbol[e]=$jscomp.IS_SYMBOL_NATIVE?$jscomp.global.Symbol(e):$jscomp.POLYFILL_PREFIX+e,e=
$jscomp.propertyToPolyfillSymbol[e],$jscomp.defineProperty(d,e,{configurable:!0,writable:!0,value:b})))};$jscomp.underscoreProtoCanBeSet=function(){var a={a:!0},b={};try{return b.__proto__=a,b.a}catch(c){}return!1};$jscomp.setPrototypeOf=$jscomp.TRUST_ES6_POLYFILLS&&"function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null;
$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};$jscomp.generator={};
$jscomp.generator.ensureIteratorResultIsObject_=function(a){if(!(a instanceof Object))throw new TypeError("Iterator result "+a+" is not an object");};$jscomp.generator.Context=function(){this.isRunning_=!1;this.yieldAllIterator_=null;this.yieldResult=void 0;this.nextAddress=1;this.finallyAddress_=this.catchAddress_=0;this.finallyContexts_=this.abruptCompletion_=null};
$jscomp.generator.Context.prototype.start_=function(){if(this.isRunning_)throw new TypeError("Generator is already running");this.isRunning_=!0};$jscomp.generator.Context.prototype.stop_=function(){this.isRunning_=!1};$jscomp.generator.Context.prototype.jumpToErrorHandler_=function(){this.nextAddress=this.catchAddress_||this.finallyAddress_};$jscomp.generator.Context.prototype.next_=function(a){this.yieldResult=a};
$jscomp.generator.Context.prototype.throw_=function(a){this.abruptCompletion_={exception:a,isException:!0};this.jumpToErrorHandler_()};$jscomp.generator.Context.prototype["return"]=function(a){this.abruptCompletion_={"return":a};this.nextAddress=this.finallyAddress_};$jscomp.generator.Context.prototype.jumpThroughFinallyBlocks=function(a){this.abruptCompletion_={jumpTo:a};this.nextAddress=this.finallyAddress_};$jscomp.generator.Context.prototype.yield=function(a,b){this.nextAddress=b;return{value:a}};
$jscomp.generator.Context.prototype.yieldAll=function(a,b){var c=$jscomp.makeIterator(a),d=c.next();$jscomp.generator.ensureIteratorResultIsObject_(d);if(d.done)this.yieldResult=d.value,this.nextAddress=b;else return this.yieldAllIterator_=c,this.yield(d.value,b)};$jscomp.generator.Context.prototype.jumpTo=function(a){this.nextAddress=a};$jscomp.generator.Context.prototype.jumpToEnd=function(){this.nextAddress=0};
$jscomp.generator.Context.prototype.setCatchFinallyBlocks=function(a,b){this.catchAddress_=a;void 0!=b&&(this.finallyAddress_=b)};$jscomp.generator.Context.prototype.setFinallyBlock=function(a){this.catchAddress_=0;this.finallyAddress_=a||0};$jscomp.generator.Context.prototype.leaveTryBlock=function(a,b){this.nextAddress=a;this.catchAddress_=b||0};
$jscomp.generator.Context.prototype.enterCatchBlock=function(a){this.catchAddress_=a||0;a=this.abruptCompletion_.exception;this.abruptCompletion_=null;return a};$jscomp.generator.Context.prototype.enterFinallyBlock=function(a,b,c){c?this.finallyContexts_[c]=this.abruptCompletion_:this.finallyContexts_=[this.abruptCompletion_];this.catchAddress_=a||0;this.finallyAddress_=b||0};
$jscomp.generator.Context.prototype.leaveFinallyBlock=function(a,b){var c=this.finallyContexts_.splice(b||0)[0];if(c=this.abruptCompletion_=this.abruptCompletion_||c){if(c.isException)return this.jumpToErrorHandler_();void 0!=c.jumpTo&&this.finallyAddress_<c.jumpTo?(this.nextAddress=c.jumpTo,this.abruptCompletion_=null):this.nextAddress=this.finallyAddress_}else this.nextAddress=a};$jscomp.generator.Context.prototype.forIn=function(a){return new $jscomp.generator.Context.PropertyIterator(a)};
$jscomp.generator.Context.PropertyIterator=function(a){this.object_=a;this.properties_=[];for(var b in a)this.properties_.push(b);this.properties_.reverse()};$jscomp.generator.Context.PropertyIterator.prototype.getNext=function(){for(;0<this.properties_.length;){var a=this.properties_.pop();if(a in this.object_)return a}return null};$jscomp.generator.Engine_=function(a){this.context_=new $jscomp.generator.Context;this.program_=a};
$jscomp.generator.Engine_.prototype.next_=function(a){this.context_.start_();if(this.context_.yieldAllIterator_)return this.yieldAllStep_(this.context_.yieldAllIterator_.next,a,this.context_.next_);this.context_.next_(a);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.return_=function(a){this.context_.start_();var b=this.context_.yieldAllIterator_;if(b)return this.yieldAllStep_("return"in b?b["return"]:function(c){return{value:c,done:!0}},a,this.context_["return"]);this.context_["return"](a);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.throw_=function(a){this.context_.start_();if(this.context_.yieldAllIterator_)return this.yieldAllStep_(this.context_.yieldAllIterator_["throw"],a,this.context_.next_);this.context_.throw_(a);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.yieldAllStep_=function(a,b,c){try{var d=a.call(this.context_.yieldAllIterator_,b);$jscomp.generator.ensureIteratorResultIsObject_(d);if(!d.done)return this.context_.stop_(),d;var e=d.value}catch(f){return this.context_.yieldAllIterator_=null,this.context_.throw_(f),this.nextStep_()}this.context_.yieldAllIterator_=null;c.call(this.context_,e);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.nextStep_=function(){for(;this.context_.nextAddress;)try{var a=this.program_(this.context_);if(a)return this.context_.stop_(),{value:a.value,done:!1}}catch(b){this.context_.yieldResult=void 0,this.context_.throw_(b)}this.context_.stop_();if(this.context_.abruptCompletion_){a=this.context_.abruptCompletion_;this.context_.abruptCompletion_=null;if(a.isException)throw a.exception;return{value:a["return"],done:!0}}return{value:void 0,done:!0}};
$jscomp.generator.Generator_=function(a){this.next=function(b){return a.next_(b)};this["throw"]=function(b){return a.throw_(b)};this["return"]=function(b){return a.return_(b)};this[Symbol.iterator]=function(){return this}};$jscomp.generator.createGenerator=function(a,b){var c=new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(b));$jscomp.setPrototypeOf&&a.prototype&&$jscomp.setPrototypeOf(c,a.prototype);return c};
$jscomp.asyncExecutePromiseGenerator=function(a){function b(d){return a.next(d)}function c(d){return a["throw"](d)}return new Promise(function(d,e){function f(g){g.done?d(g.value):Promise.resolve(g.value).then(b,c).then(f,e)}f(a.next())})};$jscomp.asyncExecutePromiseGeneratorFunction=function(a){return $jscomp.asyncExecutePromiseGenerator(a())};$jscomp.asyncExecutePromiseGeneratorProgram=function(a){return $jscomp.asyncExecutePromiseGenerator(new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(a)))};
var application=require("application"),$jscomp$destructuring$var0=require("application"),editDocument=$jscomp$destructuring$var0.editDocument,viewport=require("viewport"),$jscomp$destructuring$var1=require("scenegraph"),selection=$jscomp$destructuring$var1.selection,Artboard=$jscomp$destructuring$var1.Artboard,Color=$jscomp$destructuring$var1.Color,scenegraph=require("scenegraph"),fs=require("uxp").storage,panel,rootWidth=5E4,panelWidth=0,scaleFactor=0,viewportZoomFactor=viewport.zoomFactor,viewportBoundsX=
viewport.bounds.x,viewportBoundsY=viewport.bounds.y,updateInterval,firstTime=!0;
function create(){var a="true"==window.localStorage.getItem("crosshair")?"checked":"",b="true"==window.localStorage.getItem("dark_mode")?"checked":"",c="true"==window.localStorage.getItem("ghost_mode")?"checked":"";a='<style>\n #main {width: 100%; height: 100%; position: relative;}\n #preview {width: 100%; height: auto; position: relative; overflow: hidden; background: rgba(204, 204, 204, 0.5);}\n #preview:before {content: ""; display: block; padding-top: 100%;}\n #preview #center {width: 0px; height: 0px; position: absolute; left: 50%; top: 50%;}\n #preview #center .miniArtboard {position: absolute; background: #fff; border: 1px solid #777; z-index: 2;}\n #preview #center #miniViewport {position: absolute; border: 2px solid blue; z-index: 3;}\n #preview #center #horizontalPointer, #preview #center #verticalPointer {position: absolute; background: #CCC; opacity: 0.5; z-index: 1;}\n #footer {width: 100%; position: fixed; bottom: 0; left: 0; line-height: 150%;}\n #settings {width: 100%; display: block;}\n #settings li {width: 100%; display: flex; flex-direction: row; justify-content: space-between;}\n #settings li h3 {margin: 0;}\n .dark_mode #preview {background: rgba(15, 15, 15, 0.75);}\n .dark_mode #miniViewport {border: 2px solid #FD7422!important;}\n .dark_mode .miniArtboard {border: none!important;}\n .dark_mode #horizontalPointer, .dark_mode #verticalPointer {background: #303031!important;}\n #ghost {position: fixed; left: -12px; right: -12px; top: -12px; bottom: 0; overflow: hidden; z-index: -1;}\n #ghost #ghostCenter {width: 0px; height: 0px; position: absolute; left: 50%; top: 50%;}\n #ghost #ghostCenter .ghostArtboard {position: absolute; border: 1px solid #CDCDCD; background: #fff; overflow: hidden;}\n #ghost #ghostCenter .ghostArtboard img {width: 100%;}\n </style>\n <div id="main">\n <div id="preview" title="Click to jump into specific viewport">\n <div id="center"></div>\n </div>\n <div id="footer">\n <ul id="settings">\n <li title="Axis lines for viewport\'s position"><h3>Crosshair</h3><input type="checkbox" id="updateSetting" name="crosshair" '+a+
' /></li>\n <li title="Alternative style of the minimap"><h3>Dark mode</h3><input type="checkbox" id="updateSetting" name="dark_mode" '+b+' /></li>\n <li title="Artboards will be visible underneath plugin\'s panel"><h3>Ghost mode</h3><input type="checkbox" id="updateSetting" name="ghost_mode" '+c+' /></li>\n <li> </li>\n <li><h3><a href="https://minimap.xdplugins.co">Learn more</a></h3></li>\n </ul>\n </div>\n </div>\n <div id="ghost">\n <div id="ghostCenter"></div>\n </div>\n ';
panel=document.createElement("div");panel.innerHTML=a;panel.querySelectorAll("#updateSetting").forEach(function(d){d.addEventListener("click",function(){var e=this;return $jscomp.asyncExecutePromiseGeneratorProgram(function(f){window.localStorage.setItem(e.name,e.checked?!0:!1);return f.yield(generateMinimap(),0)})})});return panel}
function generateMinimap(){var a,b,c,d,e,f,g,k,l,m,n,h,p;return $jscomp.asyncExecutePromiseGeneratorProgram(function(q){a=document.getElementById("preview");b=document.getElementById("center");for(scaleFactor=rootWidth/a.offsetWidth;b.firstChild;)b.removeChild(b.firstChild);"true"==window.localStorage.getItem("dark_mode")?document.getElementById("main").setAttribute("class","dark_mode"):document.getElementById("main").removeAttribute("class");c=document.createElement("div");c.setAttribute("id","miniViewport");
c.style.width=viewport.bounds.width/scaleFactor;c.style.height=viewport.bounds.height/scaleFactor;c.style.left=viewport.bounds.x/scaleFactor;c.style.top=viewport.bounds.y/scaleFactor;b.appendChild(c);for(d=0;d<scenegraph.root.children.length;d++)e=scenegraph.root.children.at(d),e instanceof Artboard&&(f=document.createElement("div"),f.setAttribute("class","miniArtboard"),f.setAttribute("id","miniArtboard-"+d),f.style.width=e.width/scaleFactor,f.style.height=e.height/scaleFactor,f.style.left=e.globalBounds.x/
scaleFactor,f.style.top=e.globalBounds.y/scaleFactor,b.appendChild(f));"true"==window.localStorage.getItem("crosshair")&&(g=document.createElement("div"),g.setAttribute("id","horizontalPointer"),g.style.width=rootWidth/scaleFactor,g.style.height=viewport.bounds.height/scaleFactor,g.style.left=rootWidth/scaleFactor/2*-1,g.style.top=viewport.bounds.y/scaleFactor,b.appendChild(g),k=document.createElement("div"),k.setAttribute("id","verticalPointer"),k.style.height=rootWidth/scaleFactor,k.style.width=
viewport.bounds.width/scaleFactor,k.style.top=rootWidth/scaleFactor/2*-1,k.style.left=viewport.bounds.x/scaleFactor,b.appendChild(k));if("true"==window.localStorage.getItem("ghost_mode")){for(l=document.getElementById("ghostCenter");l.firstChild;)l.removeChild(l.firstChild);for(m=0;m<scenegraph.root.children.length;m++)n=scenegraph.root.children.at(m),h=document.createElement("div"),h.setAttribute("class","ghostArtboard"),h.setAttribute("id","ghostArtboard-"+m),h.style.width=n.width*viewport.zoomFactor,
h.style.height=n.height*viewport.zoomFactor,h.style.left=n.globalBounds.x*viewport.zoomFactor,h.style.top=n.globalBounds.y*viewport.zoomFactor,l.appendChild(h),l.style.left=panel.offsetWidth-viewport.bounds.x*viewport.zoomFactor+24,l.style.top=panel.offsetHeight-viewport.bounds.y*viewport.zoomFactor-panel.offsetHeight-88}else for(p=document.getElementById("ghostCenter");p.firstChild;)p.removeChild(p.firstChild);q.jumpToEnd()})}
function initializeDefaultSettings(){var a,b;return $jscomp.asyncExecutePromiseGeneratorProgram(function(c){a=[];a.crosshair=!0;a.dark_mode=!1;a.ghost_mode=!1;for(b in a)window.localStorage.getItem(b)||window.localStorage.setItem(b,a[b]);c.jumpToEnd()})}
function show(a){var b;return $jscomp.asyncExecutePromiseGeneratorProgram(function(c){if(1==c.nextAddress)return panel?c.jumpTo(2):c.yield(a.node.appendChild(create()),2);if(4!=c.nextAddress)return c.yield(initializeDefaultSettings(),4);b=document.getElementById("preview");b.addEventListener("click",function(d){editDocument({editLabel:"Scroll into viewport"},function(){var e=b.getBoundingClientRect(),f=document.getElementById("miniViewport");viewport.scrollIntoView((d.clientX-e.left-f.offsetWidth/
2-b.offsetWidth/2)*scaleFactor,(d.clientY-e.top-f.offsetHeight/2-b.offsetHeight/2)*scaleFactor,viewport.bounds.width,viewport.bounds.height)})});updateInterval=setInterval(function(){return $jscomp.asyncExecutePromiseGeneratorProgram(function(d){if(panel.offsetWidth==panelWidth&&viewport.zoomFactor==viewportZoomFactor&&viewport.bounds.x==viewportBoundsX&&viewport.bounds.y==viewportBoundsY)return d.jumpTo(0);panelWidth=panel.offsetWidth;viewportZoomFactor=viewport.zoomFactor;viewportBoundsX=viewport.bounds.x;
viewportBoundsY=viewport.bounds.y;return d.yield(generateMinimap(),0)})},20);c.jumpToEnd()})}function hide(a){}function update(){return $jscomp.asyncExecutePromiseGeneratorProgram(function(a){if(1==a.nextAddress)return firstTime?a.jumpTo(2):a.yield(generateMinimap(),2);firstTime=!1;a.jumpToEnd()})}module.exports={panels:{Minimap:{show:show,hide:hide,update:update}}};