22 lines
5.9 KiB
JavaScript
22 lines
5.9 KiB
JavaScript
System.register([],(function(e){"use strict";return{execute:function(){function asyncGeneratorStep(e,t,r,n,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(n=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(o)throw a}}return r}(e,t)||function _unsupportedIterableToArray(e,t){if(!e)return;if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _arrayLikeToArray(e,t)}(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}
|
|
/**
|
|
* @file ext-storage.js
|
|
*
|
|
* This extension allows automatic saving of the SVG canvas contents upon
|
|
* page unload (which can later be automatically retrieved upon future
|
|
* editor loads).
|
|
*
|
|
* The functionality was originally part of the SVG Editor, but moved to a
|
|
* separate extension to make the setting behavior optional, and adapted
|
|
* to inform the user of its setting of local data.
|
|
*
|
|
* @license MIT
|
|
*
|
|
* @copyright 2010 Brett Zamir
|
|
* @todo Revisit on whether to use `svgEditor.pref` over directly setting
|
|
* `curConfig` in all extensions for a more public API (not only for `extPath`
|
|
* and `imagePath`, but other currently used config in the extensions)
|
|
* @todo We might provide control of storage settings through the UI besides the
|
|
* initial (or URL-forced) dialog. *
|
|
*/()}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}e("default",{name:"storage",init:function init(e){var t=e.$,r=this,n=r.canvas,o=r.curConfig,a=o.emptyStorageOnDecline,i=o.noStorageOnLoad,s=o.forceStorage,c=r.storage,u=r.updateCanvas;function replaceStoragePrompt(e){e=e?"storagePrompt="+e:"";var t=top.location;t.href.includes("storagePrompt=")?t.href=t.href.replace(/([&?])storagePrompt=[^&]*(&?)/,(function(t,r,n){return(e?r:"")+e+(!e&&n?r:n||"")})):t.href+=(t.href.includes("?")?"&":"?")+e}function setSVGContentStorage(e){if(c){var t="svgedit-"+r.curConfig.canvasName;e?c.setItem(t,e):c.removeItem(t)}}function expireCookie(e){document.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"}function setupBeforeUnloadListener(){window.addEventListener("beforeunload",(function(e){if(document.cookie.match(/(?:^|;\s*)svgeditstore=(?:prefsAndContent|prefsOnly)/)){document.cookie.match(/(?:^|;\s*)svgeditstore=prefsAndContent/)&&setSVGContentStorage(n.getSvgString()),r.setConfig({no_save_warning:!0});var t=r.curPrefs;Object.entries(t).forEach((function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];r="svg-edit-"+r,void 0!==n&&(c?c.setItem(r,n):window.widget?window.widget.setPreferenceForKey(n,r):(n=encodeURIComponent(n),document.cookie=encodeURIComponent(r)+"="+n+"; expires=Fri, 31 Dec 9999 23:59:59 GMT"))}))}}))}var l=!1;return{name:"storage",langReady:function langReady(e){return function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function _next(e){asyncGeneratorStep(a,n,o,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(a,n,o,_next,_throw,"throw",e)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var n,o,f,d,g,p,m,y,h,v,_,x,b,S,w,C,k,P,A;return regeneratorRuntime.wrap((function _callee$(O){for(;;)switch(O.prev=O.next){case 0:return n=e.importLocale,o=new URL(top.location).searchParams.get("storagePrompt"),O.next=4,n();case 4:if(f=O.sent,d=f.message,g=f.storagePrefsAndContent,p=f.storagePrefsOnly,m=f.storagePrefs,y=f.storageNoPrefsOrContent,h=f.storageNoPrefs,v=f.rememberLabel,_=f.rememberTooltip,!l){O.next=8;break}return O.abrupt("return");case 8:if(l=!0,s||"true"!==o&&("false"===o||document.cookie.match(/(?:^|;\s*)svgeditstore=(?:prefsAndContent|prefsOnly)/))){O.next=44;break}return x=[],c?x.unshift({value:"prefsAndContent",text:g},{value:"prefsOnly",text:p},{value:"noPrefsOrContent",text:y}):x.unshift({value:"prefsOnly",text:m},{value:"noPrefsOrContent",text:h}),b=t("#dialog_container")[0].style.width,S=t("#dialog_container")[0].style.marginLeft,w=t("#dialog_content")[0].style.height,C=t("#dialog_container")[0].style.height,t("#dialog_content")[0].style.height="120px",t("#dialog_container")[0].style.height="170px",t("#dialog_container")[0].style.width="800px",t("#dialog_container")[0].style.marginLeft="-400px",r.storagePromptState="waiting",O.next=20,t.select(d,x,null,null,{label:v,checked:!0,tooltip:_});case 20:if(k=O.sent,P=k.response,A=k.checked,!P||"noPrefsOrContent"===P){O.next=30;break}if(document.cookie="svgeditstore="+encodeURIComponent(P)+"; expires=Fri, 31 Dec 9999 23:59:59 GMT","true"!==o||!A){O.next=28;break}return replaceStoragePrompt(),O.abrupt("return");case 28:O.next=35;break;case 30:if(expireCookie("svgeditstore"),P&&a&&(setSVGContentStorage(""),Object.keys(r.curPrefs).forEach((function(e){e="svg-edit-"+e,c&&c.removeItem(e),expireCookie(e)}))),!P||!A){O.next=35;break}return replaceStoragePrompt("false"),O.abrupt("return");case 35:t("#dialog_container")[0].style.width=b,t("#dialog_container")[0].style.marginLeft=S,t("#dialog_content")[0].style.height=w,t("#dialog_container")[0].style.height=C,setupBeforeUnloadListener(),r.storagePromptState="closed",u(!0),O.next=45;break;case 44:i&&!s||setupBeforeUnloadListener();case 45:case"end":return O.stop()}}),_callee)})))()}}}})}}}));
|