24 lines
6.9 KiB
JavaScript
24 lines
6.9 KiB
JavaScript
function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,r;function resume(t,r){try{var n=e[t](r),o=n.value,a=o instanceof _AwaitValue;Promise.resolve(a?o.wrapped:o).then((function(e){a?resume("return"===t?"return":"next",e):settle(n.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,n){switch(e){case"return":t.resolve({value:n,done:!0});break;case"throw":t.reject(n);break;default:t.resolve({value:n,done:!1})}(t=t.next)?resume(t.key,t.arg):r=null}this._invoke=function send(e,n){return new Promise((function(o,a){var i={key:e,arg:n,resolve:o,reject:a,next:null};r?r=r.next=i:(t=r=i,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}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 _arrayWithHoles(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)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}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}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.")}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},_AsyncGenerator.prototype.throw=function(e){return this._invoke("throw",e)},_AsyncGenerator.prototype.return=function(e){return this._invoke("return",e)};
|
|
/**
|
|
* @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. *
|
|
*/
|
|
var e={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,p,y,g,m,h,v,_,b,x,w,k,S,A,P,C;return regeneratorRuntime.wrap((function _callee$(I){for(;;)switch(I.prev=I.next){case 0:return n=e.importLocale,o=new URL(top.location).searchParams.get("storagePrompt"),I.next=4,n();case 4:if(f=I.sent,d=f.message,p=f.storagePrefsAndContent,y=f.storagePrefsOnly,g=f.storagePrefs,m=f.storageNoPrefsOrContent,h=f.storageNoPrefs,v=f.rememberLabel,_=f.rememberTooltip,!l){I.next=8;break}return I.abrupt("return");case 8:if(l=!0,s||"true"!==o&&("false"===o||document.cookie.match(/(?:^|;\s*)svgeditstore=(?:prefsAndContent|prefsOnly)/))){I.next=44;break}return b=[],c?b.unshift({value:"prefsAndContent",text:p},{value:"prefsOnly",text:y},{value:"noPrefsOrContent",text:m}):b.unshift({value:"prefsOnly",text:g},{value:"noPrefsOrContent",text:h}),x=t("#dialog_container")[0].style.width,w=t("#dialog_container")[0].style.marginLeft,k=t("#dialog_content")[0].style.height,S=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",I.next=20,t.select(d,b,null,null,{label:v,checked:!0,tooltip:_});case 20:if(A=I.sent,P=A.response,C=A.checked,!P||"noPrefsOrContent"===P){I.next=30;break}if(document.cookie="svgeditstore="+encodeURIComponent(P)+"; expires=Fri, 31 Dec 9999 23:59:59 GMT","true"!==o||!C){I.next=28;break}return replaceStoragePrompt(),I.abrupt("return");case 28:I.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||!C){I.next=35;break}return replaceStoragePrompt("false"),I.abrupt("return");case 35:t("#dialog_container")[0].style.width=x,t("#dialog_container")[0].style.marginLeft=w,t("#dialog_content")[0].style.height=k,t("#dialog_container")[0].style.height=S,setupBeforeUnloadListener(),r.storagePromptState="closed",u(!0),I.next=45;break;case 44:i&&!s||setupBeforeUnloadListener();case 45:case"end":return I.stop()}}),_callee)})))()}}}};export default e;
|
|
//# sourceMappingURL=ext-storage.js.map
|