polotno 2.36.7 → 2.36.8
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/canvas/html-element.js +2 -2
- package/canvas/page.js +1 -1
- package/canvas/text-element.d.ts +1 -1
- package/canvas/text-element.js +1 -1
- package/model/group-model.d.ts +1 -0
- package/model/history.js +1 -1
- package/model/store.d.ts +1 -1
- package/model/store.js +1 -1
- package/model/text-model.d.ts +1 -0
- package/model/text-model.js +1 -1
- package/package.json +1 -1
- package/polotno.bundle.js +7 -7
- package/utils/__tests__/clipboard.test.d.ts +1 -0
- package/utils/__tests__/fonts.test.d.ts +1 -0
- package/utils/__tests__/gradient.test.d.ts +1 -0
- package/utils/__tests__/image-dpi.test.d.ts +1 -0
- package/utils/__tests__/loader.test.d.ts +1 -0
- package/utils/__tests__/luma.test.d.ts +1 -0
- package/utils/__tests__/svg.test.d.ts +1 -0
- package/utils/__tests__/text.test.d.ts +1 -0
- package/utils/fonts.d.ts +3 -2
- package/utils/fonts.js +1 -1
- package/utils/validate-key.js +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/utils/fonts.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export declare function addGlobalFont(font: FONT): void;
|
|
|
7
7
|
export declare function removeGlobalFont(fontFamily: string): void;
|
|
8
8
|
export declare function replaceGlobalFonts(fonts: Array<FONT>): void;
|
|
9
9
|
export declare function measureFontDom(fontName: string, fallback?: string, fontStyle?: string, fontWeight?: string): number;
|
|
10
|
-
export declare const isFontLoaded: (fontName: string) => boolean;
|
|
11
|
-
export declare function
|
|
10
|
+
export declare const isFontLoaded: (fontName: string, fontStyle?: string, fontWeight?: string) => boolean;
|
|
11
|
+
export declare function _setFontLoadedForTesting(key: string, value: boolean): void;
|
|
12
|
+
export declare function loadFont(fontName: string, fontStyle: string, fontWeight: string): Promise<void>;
|
|
12
13
|
export declare function setGoogleFontsVariants(variants: string): void;
|
|
13
14
|
export declare function getGoogleFontsVariants(): string;
|
|
14
15
|
export declare function getGoogleFontsUrl(fontName: string): string;
|
package/utils/fonts.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"mobx";import{triggerLoadError as e,getFontLoadTimeout as o}from"./loader.js";let n=t.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),r=t.observable({value:!1});export function isGoogleFontChanged(){return r.value}export function setGoogleFonts(t){"default"!==t?(r.value=!0,n.splice(0,n.length),n.push(...t)):r.value=!1}export function getFontsList(){return n}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const e=globalFonts.findIndex(e=>e.fontFamily===t);-1!==e&&globalFonts.splice(e,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}var s="Some test text;?#D-ПРИВЕТ!1230o9u8i7y6t5r4e3w2q1";let a;function l(t,e="sans-serif",o="normal",n="normal"){a||(a=document.createElement("canvas"));var r=a.getContext("2d");return r.font=`${o} ${n} 40px '${t}', ${e}`,r.measureText(s).width}export function measureFontDom(t,e="sans-serif",o="normal",n="normal"){if("undefined"==typeof document||!document.body){return 0}const r=document.createElement("span");r.textContent=s,r.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${n} 90px '${t}', ${e};\n `,document.body.appendChild(r);const a=r.getBoundingClientRect().width;return r.remove(),a}const i={Arial:!0};export const isFontLoaded=t=>Object.keys(i).some(e=>e.startsWith(t+"_"))||!!i[t];export async function loadFont(t,n,r
|
|
1
|
+
import*as t from"mobx";import{triggerLoadError as e,getFontLoadTimeout as o}from"./loader.js";let n=t.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),r=t.observable({value:!1});export function isGoogleFontChanged(){return r.value}export function setGoogleFonts(t){"default"!==t?(r.value=!0,n.splice(0,n.length),n.push(...t)):r.value=!1}export function getFontsList(){return n}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const e=globalFonts.findIndex(e=>e.fontFamily===t);-1!==e&&globalFonts.splice(e,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}var s="Some test text;?#D-ПРИВЕТ!1230o9u8i7y6t5r4e3w2q1";let a;function l(t,e="sans-serif",o="normal",n="normal"){a||(a=document.createElement("canvas"));var r=a.getContext("2d");return r.font=`${o} ${n} 40px '${t}', ${e}`,r.measureText(s).width}export function measureFontDom(t,e="sans-serif",o="normal",n="normal"){if("undefined"==typeof document||!document.body){return 0}const r=document.createElement("span");r.textContent=s,r.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${n} 90px '${t}', ${e};\n `,document.body.appendChild(r);const a=r.getBoundingClientRect().width;return r.remove(),a}const i={Arial:!0};export const isFontLoaded=(t,e,o)=>e&&o?!!i[`${t}_${e}_${o}`]:Object.keys(i).some(e=>e.startsWith(t+"_"))||!!i[t];export function _setFontLoadedForTesting(t,e){e?i[t]=!0:delete i[t]}export async function loadFont(t,n,r){var c;const u=`${t}_${n}_${r}`;if(i[u]){return}const f=!!(null===(c=document.fonts)||void 0===c?void 0:c.load),m=function(t="normal",e="normal"){a||(a=document.createElement("canvas"));var o=a.getContext("2d");return o.font=`${t} ${e} 40px sans-serif`,o.measureText(s).width}(n,r);if(f){try{await document.fonts.load(`${n} ${r} 16px '${t}'`);if(m!==l(t,"sans-serif",n,r)){return void(i[u]=!0)}}catch(x){}}const d=function(t="normal",e="normal"){a||(a=document.createElement("canvas"));var o=a.getContext("2d");return o.font=`${t} ${e} 40px serif`,o.measureText(s).width}(n,r),p=l(t,"sans-serif",n,r),g=Math.min(6e3,o())/60;for(let e=0;e<g;e++){const e=l(t,"sans-serif",n,r),o=l(t,"serif",n,r);if(e!==p||e!==m||o!==d){return await new Promise(t=>setTimeout(t,100)),void(i[u]=!0)}await new Promise(t=>setTimeout(t,60))}console.warn(`Timeout for loading font "${t}". Looks like polotno can't load it. Is it a correct font family?`),e(`Timeout for loading font "${t}"`)}const c={};let u="400,400italic,700,700italic";export function setGoogleFontsVariants(t){u=t}export function getGoogleFontsVariants(){return u}export function getGoogleFontsUrl(t){return`https://fonts.googleapis.com/css?family=${t.replace(/ /g,"+")}:${u}`}export function injectGoogleFont(t){if(c[t]){return}const e=getGoogleFontsUrl(t),o=document.createElement("link");o.type="text/css",o.href=e,o.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(o),c[t]=!0}const f={};let m;export function injectCustomFont(t){const e=t.fontFamily;if(f[e]){return}if(!t.url&&!t.styles){return}const o=t.styles||(t.url?[{src:`url("${t.url}")`}]:[]),n=(m||(m=document.getElementById("polotno-font-style"),m||(m=document.createElement("style"),m.id="polotno-font-style",document.head.appendChild(m)),m)).sheet;o.forEach(t=>{n.insertRule(`\n @font-face{\n font-family:'${e}';\n src:${t.src};\n font-style:${t.fontStyle||"normal"};\n font-weight:${t.fontWeight||"normal"};\n font-display:swap; /* optional but recommended */\n }`,n.cssRules.length)}),f[t.fontFamily]=!0}
|
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||"";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:"2.36.
|
|
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||"";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:"2.36.8"})});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,o){s=e,await isKeyPaid(e)&&!o||r()}
|