polotno 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +22 -7
- package/README.md +1 -1
- package/blueprint/side-panel/text-panel.js +3 -3
- package/blueprint/toolbar/text-toolbar.js +2 -2
- package/blueprint.polotno.css +116 -116
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/image-element.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/quill-font-formats.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.d.ts +0 -4
- package/canvas/rich-editor.js +5 -2
- package/canvas/text-element.js +1 -1
- package/canvas/use-mediabunny-video.js +1 -1
- package/canvas/video-element.js +1 -1
- package/model/group-model.d.ts +2 -12
- package/model/image-model.js +1 -1
- package/model/page-model.d.ts +2 -12
- package/model/store.d.ts +18 -108
- package/model/store.js +1 -1
- package/model/table-model.d.ts +2 -12
- package/model/table-model.js +1 -1
- package/model/text-model.js +1 -1
- package/package.json +28 -28
- package/pages-timeline/audio-track.js +1 -1
- package/pages-timeline/current-time.js +1 -1
- package/pages-timeline/element-track.js +1 -1
- package/pages-timeline/page-preview.js +1 -1
- package/pages-timeline/pages-timeline.js +1 -1
- package/pages-timeline/pages.js +1 -1
- package/pages-timeline/play-button.js +1 -1
- package/pages-timeline/time-ruler.js +1 -1
- package/pages-timeline/track-styles.js +1 -1
- package/polotno.bundle.js +171 -168
- package/primitives/select.d.ts +1 -1
- package/side-panel/images-grid.d.ts +2 -1
- package/side-panel/images-grid.js +1 -1
- package/side-panel/select-svg.js +1 -1
- package/side-panel/text-panel.js +1 -1
- package/side-panel/text-template.d.ts +12 -0
- package/side-panel/text-template.js +1 -0
- package/toolbar/text-toolbar.js +1 -1
- package/toolbar/video-toolbar.js +1 -1
- package/ui.css +2 -2
- package/utils/font-metric.js +1 -1
- package/utils/fonts.js +1 -1
- package/utils/html-to-svg/font-inliner.js +1 -1
- package/utils/html2canvas.js +1 -1
- package/utils/measure-text.js +1 -1
- package/utils/pointer-drag.d.ts +13 -0
- package/utils/pointer-drag.js +1 -0
- package/utils/px.d.ts +2 -0
- package/utils/px.js +1 -1
- package/utils/rich-text-html.js +1 -1
- package/utils/text-format-state.js +1 -1
- package/utils/text-format.js +1 -1
- package/utils/validate-key.js +1 -1
package/utils/rich-text-html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"@polotno/core/rich-text-html";import{parseHtmlRoot as t,cleanupInlineWrappers as e,parsePrimaryFontFamily as r,toNumericWeight as o,extractFontFamiliesFromHtml as n,
|
|
1
|
+
export*from"@polotno/core/rich-text-html";import{parseHtmlRoot as t,cleanupInlineWrappers as e,parsePrimaryFontFamily as r,toNumericWeight as o,extractFontFamiliesFromHtml as n,qlClassToFontFamilyName as i,normalizeRichTextHtml as l}from"@polotno/core/rich-text-html";import{LRUCache as s}from"./lru-cache.js";const c=new s(500);export function htmlInflatesMinContentWidth(e){if(!e||!e.includes("<")){return!1}let r=c.get(e);if(void 0===r){r=!1;const o=t(e);if(o){if(o.querySelector("ol, ul")){r=!0}else{for(const t of o.querySelectorAll("[style]")){if(t.style.fontSize||t.style.letterSpacing){r=!0;break}}}}c.set(e,r)}return r}export function quillHtmlToModelText(t,e){return l(function(t){const e=(t||"").trim();if("<p><br></p>"===e||"<p></p>"===e){return""}if(e.startsWith("<p>")&&e.endsWith("</p>")){const t=e.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(t)){return t}}return t}(t),e)}export function shrinkParagraphStrutForRaster(e){var r;if(!e||!e.includes("<p")){return e}const o=t(e);if(!o){return e}for(const t of Array.from(o.querySelectorAll("p"))){let e=!1;const n=[],i=o.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_TEXT);let l=i.nextNode();for(;l;){if((l.textContent||"").length>0){let o=l.parentElement,i=null;for(;o&&o!==t;){const t=null===(r=o.style)||void 0===r?void 0:r.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){i=e;break}}o=o.parentElement}if(null==i){e=!0;break}n.push(i)}l=i.nextNode()}!e&&n.length>0&&(t.style.fontSize=`${Math.min(...n)}px`)}return o.innerHTML}export function extractFontSpecsFromHtml(e,n){const l=n.fontFamily,s=String(o(n.fontWeight)),c="italic"===n.fontStyle?"italic":"normal",f=new Map,u=(t,e,r)=>{const o=`${t}\0${e}\0${r}`;f.has(o)||f.set(o,{family:t,weight:e,style:r})};if(u(l,s,c),e&&e.includes("<")){const n=t(e);if(n){const t=n.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);let e=t.nextNode();for(;e;){if((e.textContent||"").trim().length>0){let t="",f="",a="",y=e.parentElement;for(;y&&y!==n;){if(!t){if(y.style.fontFamily){t=r(y.style.fontFamily)||""}else{const e=(y.getAttribute("class")||"").split(/\s+/).find(t=>t.startsWith("ql-font-"));e&&(t=i(e))}}f||(y.style.fontWeight?f=String(o(y.style.fontWeight)):"STRONG"!==y.tagName&&"B"!==y.tagName||(f="700")),a||(y.style.fontStyle?a=y.style.fontStyle:"EM"!==y.tagName&&"I"!==y.tagName||(a="italic")),y=y.parentElement}u(t||l,f||s,a||c)}e=t.nextNode()}}}return[...f.values()]}const f={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]};export function isClipGradientSpan(t){return!!(null==t?void 0:t.style)&&("text"===(t.style.getPropertyValue("-webkit-background-clip")||t.style.getPropertyValue("background-clip"))&&t.style.backgroundImage.includes("gradient"))}const u={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>{!function(t){if(isClipGradientSpan(t)){for(const e of["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color"]){t.style.removeProperty(e)}}}(t),t.style.removeProperty("color")},underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")}};export function stripInlineFormat(r,o){var n,i;if(!r||!r.includes("<")){return r}const l=t(r);if(!l){return r}const s=f[o]||[],c=u[o];for(const t of s){let e;for(;e=l.querySelector(t);){const t=e.parentNode;c&&c(e);const r=null===(n=e.getAttribute("style"))||void 0===n?void 0:n.trim();if(r){const o=l.ownerDocument.createElement("span");for(o.setAttribute("style",r);e.firstChild;){o.appendChild(e.firstChild)}t.insertBefore(o,e)}else{for(;e.firstChild;){t.insertBefore(e.firstChild,e)}}t.removeChild(e)}}if(c){for(const t of Array.from(l.querySelectorAll("[style]"))){c(t),(null===(i=t.getAttribute("style"))||void 0===i?void 0:i.trim())||t.removeAttribute("style")}}return e(l),l.innerHTML}const a=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=a;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===a){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(r){var o;if(!r||!r.includes("font-size")){return r}const n=t(r);if(!n){return r}const i=n.querySelectorAll("[style]");for(let t=0;t<i.length;t++){const e=i[t];e.style.fontSize&&(e.style.removeProperty("font-size"),(null===(o=e.getAttribute("style"))||void 0===o?void 0:o.trim())||e.removeAttribute("style"))}return e(n),n.innerHTML}export function stripInlineFontFamilies(r){var o;if(!r||!r.includes("font-family")&&!r.includes("ql-font-")){return r}const n=t(r);if(!n){return r}for(const t of Array.from(n.querySelectorAll("[style]"))){t.style.fontFamily&&(t.style.removeProperty("font-family"),(null===(o=t.getAttribute("style"))||void 0===o?void 0:o.trim())||t.removeAttribute("style"))}for(const t of Array.from(n.querySelectorAll("[class]"))){const e=t.getAttribute("class")||"",r=e.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));r.length!==e.split(/\s+/).filter(Boolean).length&&(r.length?t.setAttribute("class",r.join(" ")):t.removeAttribute("class"))}return e(n),n.innerHTML}export function hasMultipleDistinctInlineFontSizes(e){if(!e||!e.includes("<")){return!1}const r=t(e);if(!r){return!1}const o=new Set;for(const t of r.querySelectorAll("[style]")){const e=t.style.fontSize;if(e){const t=e.match(/^(\d+(?:\.\d+)?)px$/i);if(t&&(o.add(parseFloat(t[1])),o.size>1)){return!0}}}return!1}export function listEffectiveFontFamilies(t,e){const r=[];e&&r.push(e),r.push(...n(t||""));const o=new Set,i=[];for(const n of r){o.has(n)||(o.add(n),i.push(n))}return i.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),i}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"react";import*as e from"mobx";import{
|
|
1
|
+
import*as t from"react";import*as e from"mobx";import{parseFontSizeToPx as o,toNumericWeight as n}from"@polotno/core/rich-text-html";import{isGradient as i}from"@polotno/core/gradient";import{getTextFormat as r,applyTextFormat as l,FORMAT_KEYS as c,DECORATION_TOKENS as a,decorationTokensOf as s,decorationTokensToString as f,decorationToQuillKey as u}from"./text-format.js";const d=e.observable({active:null},{},{deep:!1});export function getActiveTextEditor(){return d.active}export function setActiveTextEditor(t){e.runInAction(()=>{d.active=Object.assign(Object.assign({},t),{currentFormat:{},mixedFormats:{},lastSelection:null})})}export function updateActiveTextFormat(t,o,n){e.runInAction(()=>{d.active&&(d.active=Object.assign(Object.assign({},d.active),{currentFormat:t,mixedFormats:o,lastSelection:n||d.active.lastSelection}))})}export function clearActiveTextEditor(t){e.runInAction(()=>{var e;t&&(null===(e=d.active)||void 0===e?void 0:e.instance)!==t||(d.active=null)})}const m={fontSize:["size"],fontFamily:["font"],fill:["color","gradient"],fontWeight:["font-weight"],fontStyle:["italic"],textDecoration:["underline","strike"]};export const ALL_QUILL_MIXED_KEYS=Array.from(new Set(c.flatMap(t=>m[t])));function p(t,e,i){var r,l;switch(t){case"fontSize":return null!==(r=o(e.size,i.fontSize))&&void 0!==r?r:i.fontSize;case"fontFamily":return e.font?String(e.font):i.fontFamily;case"fill":return e.gradient||(null!==(l=e.color)&&void 0!==l?l:i.fill);case"fontWeight":return null!=e["font-weight"]?n(e["font-weight"]):n(i.fontWeight);case"fontStyle":return e.italic?"italic":i.fontStyle;case"textDecoration":return f(s(i.textDecoration))}}function x(t,e,o){const n=s(o.textDecoration),i=(o,i)=>n.has(o)?"on":e[i]?"mixed":t[i]?"on":"off",r=function(t,e){const o=t=>"on"===t?[!0]:"off"===t?[!1]:[!0,!1],n=[];for(const i of o(t)){for(const t of o(e)){const e=new Set;i&&e.add("underline"),t&&e.add("line-through"),n.push(f(e))}}return n}(i("underline","underline"),i("line-through","strike"));return{value:1===r.length?r[0]:void 0,mixed:r.length>1,values:r}}export function quillToTextFormat(t,e,o){const n={};for(const i of c){if("textDecoration"!==i){if(m[i].some(t=>!0===e[t])){n[i]={value:void 0,mixed:!0,values:[]}}else{const e=p(i,t,o);n[i]={value:e,mixed:!1,values:[e]}}}else{n.textDecoration=x(t,e,o)}}return n}export function attrsToQuillOps(t,e){var o;const r=[];if(void 0!==t.fontFamily&&r.push(["font",t.fontFamily]),void 0!==t.fontSize&&r.push(["size",`${t.fontSize}px`]),void 0!==t.fill&&(i(String(t.fill))?r.push(["color",!1],["gradient",t.fill]):r.push(["gradient",!1],["color",t.fill])),void 0!==t.fontWeight&&r.push(["font-weight",String(n(t.fontWeight))]),void 0!==t.fontStyle&&r.push(["italic","italic"===t.fontStyle]),void 0!==t.textDecoration){const n=null!==(o=null==e?void 0:e.decorationTokens)&&void 0!==o?o:a,i=s(t.textDecoration);for(const t of a){n.includes(t)&&r.push([u(t),i.has(t)])}}return r}function v(t){return((null==t?void 0:t.selectedElements)||[]).filter(t=>"text"===t.type)}function g(t){const e=getActiveTextEditor();return e&&e.instance&&e.store===t?e:null}export function resolveSelectionScope(t,e){const o=t.getSelection()||e||{index:0,length:0},n="function"==typeof t.getLength?t.getLength():0,i=n<=1;return o.length<=0?{scope:"collapsed",sel:o,isEmpty:i}:{scope:o.length>=n-1?"full":"partial",sel:o,isEmpty:i}}export function applyToLiveEditor(t,e,o,n){const i=attrsToQuillOps(e,n);if(!i.length){return}const{scope:r,sel:l}=resolveSelectionScope(t,null!=o?o:null);for(const[c,a]of i){"collapsed"===r?t.format(c,a,"user"):t.formatText(l.index,l.length,c,a,"user")}"collapsed"===r&&updateActiveTextFormat(t.getFormat(l.index,0),{},l)}function h(t,e){const o="function"==typeof t.getLength?t.getLength():0;t.formatText(0,o,e,!0,"api")}export function getTextFormatState(t){const e=g(t),o=v(t),n=!!e||o.length>0;var i;return{format:e?quillToTextFormat(e.currentFormat||{},e.mixedFormats||{},{fontSize:(i=e.element).fontSize,fontFamily:i.fontFamily,fill:i.fill,fontWeight:i.fontWeight,fontStyle:i.fontStyle,textDecoration:i.textDecoration}):r(o),enabled:n,applyTextFormat:(e,o)=>function(t,e,o){const n=g(t);if(!n){return void l(v(t),e,o)}const{scope:i,sel:r,isEmpty:c}=resolveSelectionScope(n.instance,n.lastSelection);"full"===i||"collapsed"===i&&!c?l([n.element],e,o):function(t,e,o,n){var i,r;const l=t.instance,c=t.element;let d=!1;if(n.length>0){if(void 0!==e.fontStyle&&"italic"!==e.fontStyle&&"italic"===c.fontStyle&&(h(l,"italic"),c.set({fontStyle:"normal"}),d=!0),void 0!==e.textDecoration){const t=null!==(i=null==o?void 0:o.decorationTokens)&&void 0!==i?i:a,n=s(e.textDecoration),r=s(c.textDecoration),m=t.filter(t=>!n.has(t)&&r.has(t));for(const e of m){h(l,u(e)),r.delete(e)}m.length&&(c.set({textDecoration:f(r)}),d=!0)}d&&"function"==typeof(null===(r=l.history)||void 0===r?void 0:r.clear)&&l.history.clear()}applyToLiveEditor(l,e,n,o)}(n,e,o,r)}(t,e,o)}}export function observeTextFormatState(t,o){return e.reaction(()=>getTextFormatState(t),t=>o(t),{fireImmediately:!0})}export function useTextFormat(e){const[o,n]=t.useState(()=>getTextFormatState(e));return t.useEffect(()=>observeTextFormatState(e,n),[e]),o}
|
package/utils/text-format.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePrimaryFontFamily as t,parseFontSizeToPx as e,parseHtmlRoot as o,stripInlineFontSizes as n,stripInlineFontFamilies as r,stripInlineFormat as i,toNumericWeight as s,
|
|
1
|
+
import{parsePrimaryFontFamily as t,parseFontSizeToPx as e,parseHtmlRoot as o,stripInlineFontSizes as n,stripInlineFontFamilies as r,stripInlineFormat as i,toNumericWeight as s,qlClassToFontFamilyName as c,isClipGradientSpan as a}from"./rich-text-html.js";export const FORMAT_KEYS=["fontSize","fontFamily","fill","fontWeight","fontStyle","textDecoration"];export const DECORATION_TOKENS=["underline","line-through"];export function decorationTokensOf(t){const e=new Set;for(const o of(t||"").split(/\s+/)){"underline"!==o&&"line-through"!==o||e.add(o)}return e}export function decorationTokensToString(t){return DECORATION_TOKENS.filter(e=>t.has(e)).join(" ")}export function isDecorationActive(t,e){const o=t.textDecoration.values;return o.length>0&&o.every(t=>decorationTokensOf(t).has(e))}export const decorationToQuillKey=t=>"underline"===t?"underline":"strike";function f(o,n,r){switch(n){case"fontSize":return e(o.style.fontSize,r.fontSize);case"fontFamily":{if(o.style.fontFamily){return t(o.style.fontFamily)||void 0}const e=(o.getAttribute("class")||"").split(/\s+/).find(t=>t.startsWith("ql-font-"));return e&&c(e)||void 0}case"fill":return a(o)?o.style.backgroundImage:o.style.color||void 0;case"fontWeight":return o.style.fontWeight?s(o.style.fontWeight):"STRONG"===o.tagName||"B"===o.tagName?700:void 0;case"fontStyle":return o.style.fontStyle?o.style.fontStyle:"EM"===o.tagName||"I"===o.tagName?"italic":void 0;case"textDecoration":return o.style.textDecoration?o.style.textDecoration:"U"===o.tagName?"underline":"S"===o.tagName||"DEL"===o.tagName?"line-through":void 0}}function l(t,e){return"fontWeight"===e?s(t.fontWeight):t[e]}function u(t,e,o){const n={},r=new Set,i=decorationTokensOf(o.textDecoration);let s=t.parentElement;for(;s&&s!==e;){for(const t of FORMAT_KEYS){if("textDecoration"===t){const t=f(s,"textDecoration",o);if("string"==typeof t){for(const e of decorationTokensOf(t)){i.add(e)}}continue}if(r.has(t)){continue}const e=f(s,t,o);void 0!==e&&(n[t]=e,r.add(t))}s=s.parentElement}for(const c of FORMAT_KEYS){"textDecoration"===c||r.has(c)||(n[c]=l(o,c))}return n.textDecoration=decorationTokensToString(i),n}function d(t,e){return 0===t.length?{value:e,mixed:!1,values:void 0===e?[]:[e]}:1===t.length?{value:t[0],mixed:!1,values:t}:{value:void 0,mixed:!0,values:t}}function h(t){const e=function(t){const e=t.text||"";if(!e.includes("<")){if(0===e.trim().length){return[]}const o={};for(const e of FORMAT_KEYS){o[e]=l(t,e)}return[o]}const n=o(e);if(!n){return[]}const r=[],i=n.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);let s=i.nextNode();for(;s;){const e=s;(e.textContent||"").trim().length>0&&r.push(u(e,n,t)),s=i.nextNode()}return r}(t),n={};for(const o of FORMAT_KEYS){const r=[];for(const t of e){const e=t[o];void 0===e||r.includes(e)||r.push(e)}const i=0===r.length?l(t,o):void 0;n[o]=d(r,i)}return n}export function getTextFormat(t){return Array.isArray(t)?function(t){const e={};for(const o of FORMAT_KEYS){const n=[];for(const e of t){for(const t of e[o].values){n.includes(t)||n.push(t)}}e[o]=d(n,void 0)}return e}(t.map(h)):h(t)}function g(t,e){switch(e){case"fontSize":return n(t);case"fontFamily":return r(t);case"fill":return i(t,"color");case"fontWeight":return i(t,"bold");case"fontStyle":return i(t,"italic");case"textDecoration":return i(i(t,"underline"),"strike")}}let x=!1;function T(t){return"string"!=typeof t||/^\d+$/.test(t.trim())||x||(x=!0,console.warn("[polotno] applyTextFormat({ fontWeight }) with a string such as 'bold'/'normal' is deprecated; pass a number (100–900), e.g. 700.")),s(t)}export function patchTextFormat(t,e,o){var n;const r=FORMAT_KEYS.filter(t=>void 0!==e[t]);if(0===r.length){return{attrsToSet:{}}}const s=null!==(n=null==o?void 0:o.decorationTokens)&&void 0!==n?n:DECORATION_TOKENS,c={};let a=t.text||"";for(const f of r){if("textDecoration"===f){const o=decorationTokensOf(e.textDecoration),n=decorationTokensOf(t.textDecoration);for(const t of s){o.has(t)?n.add(t):n.delete(t),a=i(a,decorationToQuillKey(t))}c.textDecoration=decorationTokensToString(n);continue}c[f]="fontWeight"===f?String(T(e.fontWeight)):e[f],a=g(a,f)}return a!==(t.text||"")&&(c.text=a),{attrsToSet:c}}export function applyTextFormat(t,e,o){var n;const r=Array.isArray(t)?t:[t];if(0===r.length){return}const i=t=>{const{attrsToSet:n}=patchTextFormat(t,e,o);Object.keys(n).length&&t.set(n)};if(1===r.length){return void i(r[0])}const s=new Map;for(const c of r){const t=c.store,e=s.get(t)||[];e.push(c),s.set(t,e)}for(const[c,a]of s){(null===(n=null==c?void 0:c.history)||void 0===n?void 0:n.transaction)?c.history.transaction(()=>a.forEach(i)):a.forEach(i)}}
|
package/utils/validate-key.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";export const setKey=e=>{s=e||""};let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"4.
|
|
1
|
+
import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";export const setKey=e=>{s=e||""};let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"4.8.0"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(s)&&!e||r()}
|