svgedit/dist/editor/extensions/ext-storage/ext-storage.js

23 lines
75 KiB
JavaScript
Raw Normal View History

var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(e){var t={exports:{}};return e(t,t.exports),t.exports}var check=function(e){return e&&e.Math==Math&&e},t=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof e&&e)||function(){return this}()||Function("return this")(),fails=function(e){try{return!!e()}catch(e){return!0}},r=!fails((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),n={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i={f:o&&!n.call({1:2},1)?function propertyIsEnumerable(e){var t=o(this,e);return!!t&&t.enumerable}:n},createPropertyDescriptor=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},a={}.toString,classofRaw=function(e){return a.call(e).slice(8,-1)},c="".split,u=fails((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==classofRaw(e)?c.call(e,""):Object(e)}:Object,requireObjectCoercible=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},toIndexedObject=function(e){return u(requireObjectCoercible(e))},isObject=function(e){return"object"==typeof e?null!==e:"function"==typeof e},toPrimitive=function(e,t){if(!isObject(e))return e;var r,n;if(t&&"function"==typeof(r=e.toString)&&!isObject(n=r.call(e)))return n;if("function"==typeof(r=e.valueOf)&&!isObject(n=r.call(e)))return n;if(!t&&"function"==typeof(r=e.toString)&&!isObject(n=r.call(e)))return n;throw TypeError("Can't convert object to primitive value")},s={}.hasOwnProperty,has=function(e,t){return s.call(e,t)},l=t.document,f=isObject(l)&&isObject(l.createElement),documentCreateElement=function(e){return f?l.createElement(e):{}},h=!r&&!fails((function(){return 7!=Object.defineProperty(documentCreateElement("div"),"a",{get:function(){return 7}}).a})),p=Object.getOwnPropertyDescriptor,d={f:r?p:function getOwnPropertyDescriptor(e,t){if(e=toIndexedObject(e),t=toPrimitive(t,!0),h)try{return p(e,t)}catch(e){}if(has(e,t))return createPropertyDescriptor(!i.f.call(e,t),e[t])}},anObject=function(e){if(!isObject(e))throw TypeError(String(e)+" is not an object");return e},v=Object.defineProperty,y={f:r?v:function defineProperty(e,t,r){if(anObject(e),t=toPrimitive(t,!0),anObject(r),h)try{return v(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(e[t]=r.value),e}},g=r?function(e,t,r){return y.f(e,t,createPropertyDescriptor(1,r))}:function(e,t,r){return e[t]=r,e},setGlobal=function(e,r){try{g(t,e,r)}catch(n){t[e]=r}return r},m=t["__core-js_shared__"]||setGlobal("__core-js_shared__",{}),b=Function.toString;"function"!=typeof m.inspectSource&&(m.inspectSource=function(e){return b.call(e)});var S,w,x,E=m.inspectSource,P=t.WeakMap,O="function"==typeof P&&/native code/.test(E(P)),k=createCommonjsModule((function(e){(e.exports=function(e,t){return m[e]||(m[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.7.0",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),L=0,A=Math.random(),uid=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++L+A).toString(36)},R=k("keys"),sharedKey=function(e){return R[e]||(R[e]=uid(e))},j={},_=t.WeakMap;if(O){var I=m.state||(m.state=new _),T=I.get,C=I.has,U=I.set;S=function(e,t){return t.facade=e,U.call(I,e,t),t},w=function(e){return T.call(I,e)||{}},x=function(e){return C.call(I,e)}}else{var G=sharedKey("state");j[G]=!0,S=function(e,t){return t.facade=e,g(e,G,t),t},w=function(e){return has(e,G)?e[G]:{}},x=function(e){return has(e,G)}}var N={set:S,get:w,has:x,enforce:function(e){return x(e)?w(e):S(e,{})},getterFor:function(e){return function(t){var r;if(!isObject(t)||(r=w(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return r}}},M=createCommonjsModule((function(e){var r=N.get,n=N.enforce,o=String(String).split("String");(e.exports=function(e,r,i,a){var c,u=!!a&&!!a.unsafe,s=!!a&&!!a.enumerab
2020-09-10 06:24:38 +00:00
/**
2020-09-11 23:27:47 +00:00
* @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).
2020-09-10 06:24:38 +00:00
*
2020-09-11 23:27:47 +00:00
* 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
2020-09-10 06:24:38 +00:00
*
2020-09-11 23:27:47 +00:00
* @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 Mi=function(){var e=_asyncToGenerator(regeneratorRuntime.mark((function _callee(e){var t;return regeneratorRuntime.wrap((function _callee$(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,__variableDynamicImportRuntime0__("./locale/".concat(encodeURIComponent(e),".js"));case 3:t=r.sent,r.next=12;break;case 6:return r.prev=6,r.t0=r.catch(0),console.error("Missing translation (".concat(e,") - using 'en'")),r.next=11,Promise.resolve().then((function(){return Bi}));case 11:t=r.sent;case 12:return r.abrupt("return",t.default);case 13:case"end":return r.stop()}}),_callee,null,[[0,6]])})));return function loadExtensionTranslation(t){return e.apply(this,arguments)}}(),Di={name:"storage",init:function init(e){var t=e.$,r=this,n=r.canvas,o=r.curConfig,i=o.emptyStorageOnDecline,a=o.noStorageOnLoad,c=o.forceStorage,u=r.storage,s=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(u){var t="svgedit-"+r.curConfig.canvasName;e?u.setItem(t,e):u.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&&(u?u.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 _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var n,o,f,h,p,d,v,y,g,m,b,S,w,x,E,P,O,k;return regeneratorRuntime.wrap((function _callee2$(L){for(;;)switch(L.prev=L.next){case 0:return e.lang,n=new URL(top.location).searchParams.get("storagePrompt"),L.next=4,Mi(r.pref("lang"));case 4:if(o=L.sent,f=o.message,h=o.storagePrefsAndContent,p=o.storagePrefsOnly,d=o.storagePrefs,v=o.storageNoPrefsOrContent,y=o.storageNoPrefs,g=o.rememberLabel,m=o.rememberTooltip,!l){L.next=8;break}return L.abrupt("return");case 8:if(l=!0,c||"true"!==n&&("false"===n||document.cookie.match(/(?:^|;\s*)svgeditstore=(?:prefsAndContent|prefsOnly)/))){L.next=44;break}return b=[],u?b.unshift({value:"prefsAndContent",text:h},{value:"prefsOnly",text:p},{value:"noPrefsOrContent",text:v}):b.unshift({value:"prefsOnly",text:d},{value:"noPrefsOrContent",text:y}),S=t("#dialog_container")[0].style.width,w=t("#dialog_container")[0].style.marginLeft,x=t("#dialog_content")[0].style.height,E=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",L.next=20,t.select(f,b,null,null,{label:g,checked:!0,tooltip:m});case 20:if(P=L.sent,O=P.response,k=P.checked,!O||"noPrefsOrContent"===O){L.next=30;break}if(document.cookie="svgeditstore="+encodeURIComponent(O)+"; expires=Fri, 31 Dec 9999 23:59:59 GMT","true"!==n||!k){L.next=28;break}return replaceStoragePrompt(),L.abrupt("return");case 28:L.next=35;break;case 30:if(expireCookie("svgeditstore"),O&&i&&(setSVGContentStorage(""),Object.keys(r.curPrefs).forEach((function(e){e="svg-edit-"+e,u&&u.removeItem(e),expireCookie(e)}))),!O||!k){L.next=35;break}return replaceStoragePrompt("false"),L.abrupt("return");case 35:t("#dialog_container")[0].style.width=S,t("#dialog_container")[0].style.marginLeft=w,t("#dialog_content")[0].style.height=x,t("#dialog_container")[0].style.height=E,setupBeforeUnloadListener(),r.storageP
2020-09-10 06:24:38 +00:00
//# sourceMappingURL=ext-storage.js.map