polotno 4.19.1 → 4.20.1
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 +8 -2
- package/THIRD_PARTY_NOTICES.md +2871 -0
- package/blueprint/canvas/context-menu/context-menu.js +1 -1
- package/blueprint/canvas/page-controls.d.ts +3 -3
- package/blueprint/pages-timeline/pages-timeline.js +2 -2
- package/blueprint/pages-timeline/play-button.js +2 -2
- package/blueprint/side-panel/animations-panel.d.ts +1 -1
- package/blueprint/side-panel/draw-panel.js +2 -2
- package/blueprint/side-panel/effect-card.js +3 -3
- package/blueprint/side-panel/effects-panel.d.ts +1 -1
- package/blueprint/side-panel/effects-panel.js +1 -1
- package/blueprint/side-panel/elements-panel.d.ts +1 -1
- package/blueprint/side-panel/select-video.d.ts +19 -19
- package/blueprint/side-panel/videos-grid.d.ts +4 -4
- package/blueprint/toolbar/animations-picker.d.ts +1 -1
- package/blueprint/toolbar/element-container.d.ts +1 -1
- package/blueprint/toolbar/figure-toolbar.js +1 -1
- package/blueprint/toolbar/filters-picker.d.ts +1 -1
- package/blueprint/toolbar/filters-picker.js +1 -1
- package/blueprint/toolbar/group-button.js +1 -1
- package/blueprint/toolbar/image-remove-background-button.js +1 -1
- package/blueprint/toolbar/image-toolbar.js +1 -1
- package/blueprint/toolbar/line-toolbar.js +1 -1
- package/blueprint/toolbar/page-toolbar.d.ts +1 -1
- package/blueprint/toolbar/position-picker.js +1 -1
- package/blueprint/toolbar/sketch.d.ts +5 -5
- package/blueprint/toolbar/svg-toolbar.js +1 -1
- package/blueprint/toolbar/table-toolbar.js +1 -1
- package/blueprint/toolbar/text-ai-write.js +1 -1
- package/blueprint/toolbar/text-toolbar.d.ts +1 -1
- package/blueprint.polotno.css +164 -153
- package/canvas/apply-filters.d.ts +2 -6
- package/canvas/apply-filters.js +1 -1
- package/canvas/context-menu/context-menu.js +1 -1
- package/canvas/crop-overlay.d.ts +1 -1
- package/canvas/crop-overlay.js +1 -1
- package/canvas/downscale.d.ts +1 -24
- package/canvas/downscale.js +1 -1
- package/canvas/element.d.ts +3 -1
- package/canvas/element.js +1 -1
- package/canvas/fade-overlay.js +1 -1
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.d.ts +32 -0
- package/canvas/gif-element.js +1 -1
- package/canvas/hotkeys.d.ts +1 -1
- package/canvas/hotkeys.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/image-element.d.ts +4 -48
- package/canvas/image-element.js +1 -1
- package/canvas/image-tool-controls.js +1 -1
- package/canvas/line-element.js +1 -1
- package/canvas/lottie-element.d.ts +11 -0
- package/canvas/lottie-element.js +1 -0
- package/canvas/lottie-player.d.ts +2 -0
- package/canvas/lottie-player.js +1 -0
- package/canvas/lottie-player.wasm.d.ts +1 -0
- package/canvas/lottie-player.wasm.js +1 -0
- package/canvas/media-placeholders.d.ts +23 -0
- package/canvas/media-placeholders.js +1 -0
- package/canvas/page-controls.d.ts +3 -3
- package/canvas/page.js +1 -1
- package/canvas/quill-font-formats.d.ts +2 -2
- package/canvas/rect-control.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.d.ts +7 -4
- package/canvas/rich-editor.js +5 -5
- package/canvas/rules.js +2 -2
- package/canvas/table-cell-text.d.ts +18 -0
- package/canvas/table-cell-text.js +1 -0
- package/canvas/table-element.js +1 -1
- package/canvas/text-element/caret-color.d.ts +3 -1
- package/canvas/text-element/render-tag-source.d.ts +33 -0
- package/canvas/text-element/render-tag-source.js +1 -0
- package/canvas/text-element.d.ts +1 -1
- package/canvas/text-element.js +1 -1
- package/canvas/use-color.d.ts +5 -5
- package/canvas/use-filtered-source.js +1 -1
- package/canvas/use-mediabunny-video.js +1 -1
- package/canvas/use-transformer-snap.d.ts +2 -2
- package/canvas/video-element.d.ts +4 -2
- package/canvas/video-element.js +1 -1
- package/icons/animation-icons.d.ts +1 -0
- package/icons/animation-icons.js +1 -1
- package/icons/registry.d.ts +35 -32
- package/icons/registry.js +1 -1
- package/image-tools/geometry.d.ts +2 -2
- package/image-tools/target.d.ts +6 -6
- package/image-tools/target.js +1 -1
- package/lib/utils.d.ts +1 -1
- package/model/figure-model.d.ts +10 -10
- package/model/gif-model.d.ts +10 -10
- package/model/group-model.d.ts +393 -84
- package/model/group-model.js +1 -1
- package/model/image-model.d.ts +10 -10
- package/model/image-tools.d.ts +1 -1
- package/model/line-model.d.ts +10 -10
- package/model/lottie-model.d.ts +242 -0
- package/model/lottie-model.js +5 -0
- package/model/node-model.d.ts +8 -8
- package/model/page-model.d.ts +1186 -297
- package/model/page-model.js +1 -1
- package/model/shape-model.d.ts +11 -11
- package/model/shape-model.js +1 -1
- package/model/store.d.ts +30 -26
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +9 -9
- package/model/table-model.d.ts +127 -20
- package/model/table-model.js +1 -1
- package/model/text-model.d.ts +9 -9
- package/model/video-model.d.ts +10 -10
- package/package.json +36 -55
- package/pages-timeline/pages-timeline.js +1 -1
- package/pages-timeline/track-styles.d.ts +12 -12
- package/polotno-app.d.ts +1 -1
- package/polotno.bundle.js +183 -179
- package/primitives/button.d.ts +4 -4
- package/primitives/dialog.d.ts +4 -4
- package/primitives/dropdown-menu.d.ts +18 -18
- package/primitives/input-group.d.ts +1 -1
- package/primitives/popover.d.ts +4 -4
- package/primitives/select.d.ts +5 -5
- package/primitives/tooltip.d.ts +3 -3
- package/side-panel/animations-panel.js +1 -1
- package/side-panel/background-panel.js +1 -1
- package/side-panel/draw-panel.js +1 -1
- package/side-panel/effect-card.js +1 -1
- package/side-panel/effects-panel.js +1 -1
- package/side-panel/photos-panel.js +1 -1
- package/side-panel/select-lottie.d.ts +11 -0
- package/side-panel/select-lottie.js +1 -0
- package/side-panel/select-video.d.ts +19 -19
- package/side-panel/size-panel.js +1 -1
- package/side-panel/unsplash-credit.d.ts +4 -1
- package/side-panel/unsplash-credit.js +1 -1
- package/side-panel/upload-panel.js +1 -1
- package/themes/carbon.css +1 -1
- package/toolbar/gif-toolbar.d.ts +3 -0
- package/toolbar/gif-toolbar.js +1 -1
- package/toolbar/group-button.js +1 -1
- package/toolbar/html-toolbar.d.ts +1 -0
- package/toolbar/html-toolbar.js +3 -3
- package/toolbar/image-remove-background-button.js +1 -1
- package/toolbar/index.d.ts +1 -1
- package/toolbar/index.js +1 -1
- package/toolbar/line-toolbar.js +1 -1
- package/toolbar/position-picker.js +1 -1
- package/toolbar/table-toolbar.js +1 -1
- package/toolbar/text-ai-write.js +1 -1
- package/toolbar/text-toolbar.js +1 -1
- package/toolbar/toolbar-shared.d.ts +15 -4
- package/toolbar/toolbar-shared.js +1 -1
- package/toolbar/toolbar.js +1 -1
- package/ui.css +2 -2
- package/utils/animations.d.ts +47 -44
- package/utils/animations.js +1 -1
- package/utils/base64.d.ts +1 -2
- package/utils/base64.js +1 -1
- package/utils/clipboard.d.ts +19 -18
- package/utils/clipboard.js +1 -1
- package/utils/fade-gradient.d.ts +1 -1
- package/utils/file.d.ts +4 -3
- package/utils/file.js +1 -1
- package/utils/font-metric.d.ts +29 -28
- package/utils/fonts.js +1 -1
- package/utils/gif-encoder.d.ts +35 -0
- package/utils/gif-encoder.js +1 -0
- package/utils/gif-lib.d.ts +6 -10
- package/utils/gif-lib.js +1 -1
- package/utils/gif-worker.d.ts +1 -0
- package/utils/gif-worker.js +3 -0
- package/utils/html2canvas.js +1 -1
- package/utils/image-dpi.d.ts +1 -1
- package/utils/image-dpi.js +1 -1
- package/utils/insert-file.js +1 -1
- package/utils/l10n.d.ts +1 -0
- package/utils/l10n.js +1 -1
- package/utils/lottie.d.ts +12 -0
- package/utils/lottie.js +1 -0
- package/utils/math.d.ts +4 -4
- package/utils/px.d.ts +3 -0
- package/utils/px.js +1 -1
- package/utils/react-color/components/common/Checkboard.d.ts +12 -12
- package/utils/react-color/components/common/Swatch.d.ts +6 -6
- package/utils/react-color/helpers/interaction.d.ts +6 -6
- package/utils/reactcss/components/active.d.ts +6 -6
- package/utils/reactcss/components/hover.d.ts +6 -6
- package/utils/rich-text-html.js +1 -1
- package/utils/selection-colors.js +1 -1
- package/utils/selection-transform.d.ts +4 -4
- package/utils/selection-transform.js +1 -1
- package/utils/split-element.js +1 -1
- package/utils/text-format-state.d.ts +1 -0
- package/utils/text-format-state.js +1 -1
- package/utils/text-format.d.ts +2 -2
- package/utils/text-sizing.d.ts +1 -1
- package/utils/timeline.d.ts +30 -2
- package/utils/timeline.js +1 -1
- package/utils/to-html.js +1 -1
- package/utils/to-svg.js +1 -1
- package/utils/validate-key.js +1 -1
- package/canvas/downscale-bands.d.ts +0 -10
- package/canvas/downscale-bands.js +0 -1
- package/canvas/downscale-kernel.d.ts +0 -7
- package/canvas/downscale-kernel.js +0 -1
- package/canvas/downscale-kernel.wasm.d.ts +0 -1
- package/canvas/downscale-kernel.wasm.js +0 -1
- package/canvas/downscale-passes.d.ts +0 -7
- package/canvas/downscale-passes.js +0 -1
package/utils/rich-text-html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"@polotno/core/rich-text-html";import{
|
|
1
|
+
export*from"@polotno/core/rich-text-html";import{hasMarkup as t,parseHtmlRoot as e,cleanupInlineWrappers as r,extractFontFamiliesFromHtml as o,normalizeRichTextHtml as n,scaleRichTextFontSizesInHtml as i}from"@polotno/core/rich-text-html";import{containsCmykColor as l,isCmykColor as s,toDisplayColor as c}from"@polotno/core/color";import{buildStyleAttribute as u,mapStyleAttributes as f,parseStyleAttribute as a,stripPriority as p,styleAttributeRanges as y}from"@polotno/core/style-attribute";import{sameColors as d}from"@polotno/core/svg";import{isGradient as m,parseColor as b}from"@polotno/core/gradient";import{LRUCache as v}from"./lru-cache.js";const h="data-native-";export function nativeColorAttribute(t){return h+t}const g=t=>s(t)||m(t)&&l(t);export function readNativeColor(t,e){var r;const o=t.getAttribute(nativeColorAttribute(e));if(null!==o){const n=null===(r=t.style)||void 0===r?void 0:r.getPropertyValue(e);return g(o)&&n&&function(t,e,r){const o=c(r);if(!m(o)){return d(e,o)}const n=function(t,e){if("undefined"==typeof document){return null}const r=document.createElement("span");return r.style.setProperty(t,e),r.style.getPropertyValue(t)||null}(t,o);if(null!==n){return n===e}if(!m(e)){return!1}const i=b(e),l=b(o);return i.rotation===l.rotation&&i.stops.length===l.stops.length&&i.stops.every((t,e)=>Math.abs(t.offset-l.stops[e].offset)<.001&&d(t.color,l.stops[e].color))}(e,n,o)?o:""}const n=a(t.getAttribute("style"))[e];return n&&g(n)?n:""}export function detachNativeColorsInHtml(t){if(!l(t)){return t}const r=e(t);return r?(function(t){for(const e of Array.from(t.querySelectorAll("[style]"))){const t=e.getAttribute("style");if(!l(t)){continue}const r=a(t);for(const[o,n]of Object.entries(r)){g(n)&&(e.setAttribute(nativeColorAttribute(o),n),r[o]=c(n))}e.setAttribute("style",u(r))}}(r),r.innerHTML):t}export function attachNativeColorsInHtml(t){if(!t||!t.includes(h)){return t}const o=e(t);if(!o){return t}let n=!1;for(const e of Array.from(o.querySelectorAll("*"))){for(const{name:t}of Array.from(e.attributes)){if(!t.startsWith(h)){continue}const r=t.slice(12),o=readNativeColor(e,r);if(e.removeAttribute(t),!o){n=!0;continue}const i=a(e.getAttribute("style"));i[r]=o,e.setAttribute("style",u(i))}}return n&&r(o),o.innerHTML}function x(t,e){if(!l(t)){return e(t)}const r=detachNativeColorsInHtml(t),o=e(r);return o===r?t:attachNativeColorsInHtml(o)}export function scaleRichTextFontSizesInHtml(t,e){return x(t,t=>i(t,e))}const A=new v(500);export function htmlInflatesMinContentWidth(t){if(!t||!t.includes("<")){return!1}let r=A.get(t);if(void 0===r){r=!1;const o=e(t);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}}}}A.set(t,r)}return r}export function quillHtmlToModelText(t,e){return attachNativeColorsInHtml(n(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(t){var r;if(!t||!t.includes("<p")){return t}const o=e(t);if(!o){return t}for(const e of Array.from(o.querySelectorAll("p"))){let t=!1;const n=[],i=o.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let l=i.nextNode();for(;l;){if((l.textContent||"").length>0){let o=l.parentElement,i=null;for(;o&&o!==e;){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){t=!0;break}n.push(i)}l=i.nextNode()}!t&&n.length>0&&(e.style.fontSize=`${Math.min(...n)}px`)}return o.innerHTML}const S={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")||!!readNativeColor(t,"background-image")))}const C={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")},"text-transform":t=>t.style.removeProperty("text-transform")};export function stripInlineFormat(o,n){return x(o,o=>function(o,n){var i,l;if(!o||!t(o)){return o}const s=e(o);if(!s){return o}const c=S[n]||[],u=C[n];for(const t of c){let e;for(;e=s.querySelector(t);){const t=e.parentNode;u&&u(e);const r=null===(i=e.getAttribute("style"))||void 0===i?void 0:i.trim();if(r){const o=s.ownerDocument.createElement("span");o.setAttribute("style",r);for(const{name:t,value:r}of Array.from(e.attributes)){t.startsWith(h)&&o.setAttribute(t,r)}for(;e.firstChild;){o.appendChild(e.firstChild)}t.insertBefore(o,e)}else{for(;e.firstChild;){t.insertBefore(e.firstChild,e)}}t.removeChild(e)}}if(u){for(const t of Array.from(s.querySelectorAll("[style]"))){u(t),(null===(l=t.getAttribute("style"))||void 0===l?void 0:l.trim())||t.removeAttribute("style")}}return r(s),s.innerHTML}(o,n))}const k=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=k;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===k){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){return x(t,I)}function I(o){var n;if(!o||!o.includes("font-size")||!t(o)){return o}const i=e(o);if(!i){return o}const l=i.querySelectorAll("[style]");for(let t=0;t<l.length;t++){const e=l[t];e.style.fontSize&&(e.style.removeProperty("font-size"),(null===(n=e.getAttribute("style"))||void 0===n?void 0:n.trim())||e.removeAttribute("style"))}return r(i),i.innerHTML}export function stripInlineFontFamilies(t){return x(t,N)}function N(o){var n;if(!o||!o.includes("font-family")&&!o.includes("ql-font-")||!t(o)){return o}const i=e(o);if(!i){return o}for(const t of Array.from(i.querySelectorAll("[style]"))){t.style.fontFamily&&(t.style.removeProperty("font-family"),(null===(n=t.getAttribute("style"))||void 0===n?void 0:n.trim())||t.removeAttribute("style"))}for(const t of Array.from(i.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 r(i),i.innerHTML}export function hasMultipleDistinctInlineFontSizes(t){if(!t||!t.includes("<")){return!1}const r=e(t);if(!r){return!1}const o=new Set;for(const e of r.querySelectorAll("[style]")){const t=e.style.fontSize;if(t){const e=t.match(/^(\d+(?:\.\d+)?)px$/i);if(e&&(o.add(parseFloat(e[1])),o.size>1)){return!0}}}return!1}export function listEffectiveFontFamilies(t,e){const r=[];e&&r.push(e),r.push(...o(t||""));const n=new Set,i=[];for(const o of r){n.has(o)||(n.add(o),i.push(o))}return i.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),i}const T=t=>t.color&&!(t=>"text"===(t["-webkit-background-clip"]||t["background-clip"])&&!!t["background-image"])(t)?p(t.color):null;export function listInlineTextColors(t){const e=[];return y(t||"").forEach(([r,o],n)=>{const i=T(a(t.slice(r,o)));i&&e.push({index:n,color:i})}),e}export function setInlineTextColor(t,e,r){let o=-1;return f(t||"",t=>{o+=1;const n=a(t);return e.includes(o)&&T(n)?(n.color=r,u(n)):t})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"konva";import*as t from"@polotno/core/svg";import{isGradient as
|
|
1
|
+
import o from"konva";import*as t from"@polotno/core/svg";import{isGradient as r}from"@polotno/core/gradient";import{containsCmykColor as e,formatCmykColor as l,parseCmykColor as s}from"@polotno/core/color";import{isMedia as c}from"./px.js";import{listInlineTextColors as n,setInlineTextColor as p}from"./rich-text-html.js";const a=(o,r)=>Array.from(o.keys()).find(o=>t.sameColors(o,r));export const getColorsReplace=o=>o.colorsReplace;export const getSvgColor=(o,t)=>{const r=a(o,t);return o.get(r||"")||t};export const replaceSvgColor=(o,t,r)=>{const e=a(getColorsReplace(o),t)||t;o.replaceColor(e,r)};export const colorKey=t=>{if(r(t)){return t}if(e(t)){const o=s(t);return o?l(o):t}const c=o.Util.colorToRGBA(t);return c?`${c.r},${c.g},${c.b},${c.a}`:t};export const collectSelectionColors=(o,t)=>{const r=new Map,e=(o,t,e=!0)=>{if(!o){return}const l=colorKey(o),s=r.get(l)||{color:o,slots:[]};s.slots.push({apply:t,gradient:e}),r.set(l,s)},l=(o,t,r=!0)=>{e(o[t],r=>o.set({[t]:r}),r)};return o.forEach(o=>{var r;if(o.styleEditable){if("figure"!==o.type&&"text"!==o.type||(l(o,"fill"),o.strokeWidth>0&&l(o,"stroke")),"line"===o.type&&l(o,"color",!1),(c(o.type)||"text"===o.type)&&o.borderSize>0&&l(o,"borderColor","text"!==o.type),"text"===o.type){const t=o;t.backgroundEnabled&&l(o,"backgroundColor",!1),n(t.text).forEach(({index:o,color:r})=>{e(r,r=>t.set({text:p(t.text,[o],r)}),!1)})}if("svg"===o.type){const l=o;if(l.maskSrc){return}null===(r=t(l.src))||void 0===r||r.forEach(o=>{e(getSvgColor(getColorsReplace(l),o),t=>replaceSvgColor(l,o,t))})}}}),Array.from(r.values()).sort((o,t)=>t.slots.length-o.slots.length)};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { StoreType } from '../model/store.js';
|
|
2
2
|
import type { ShapeType } from '../model/shape-model.js';
|
|
3
3
|
export declare const isAxisAligned: (rotation: number) => boolean;
|
|
4
|
-
export declare const canStretchAxis: (element: ShapeType, axis:
|
|
5
|
-
export declare const leafMinSize: (element: ShapeType, axis:
|
|
4
|
+
export declare const canStretchAxis: (element: ShapeType, axis: 'x' | 'y', boxRotation: number) => boolean;
|
|
5
|
+
export declare const leafMinSize: (element: ShapeType, axis: 'x' | 'y', isEdgeDrag: boolean, startSize: number) => number;
|
|
6
6
|
type Box = {
|
|
7
7
|
x: number;
|
|
8
8
|
y: number;
|
|
@@ -12,8 +12,8 @@ type Box = {
|
|
|
12
12
|
export declare const getSelectionBox: (store: StoreType) => Box | null;
|
|
13
13
|
export declare const canResizeSelection: (store: StoreType) => boolean;
|
|
14
14
|
export declare const canMoveSelection: (store: StoreType) => boolean;
|
|
15
|
-
export declare const resizeSelection: (store: StoreType, axis:
|
|
16
|
-
export declare const moveSelection: (store: StoreType, axis:
|
|
15
|
+
export declare const resizeSelection: (store: StoreType, axis: 'x' | 'y', size: number) => void;
|
|
16
|
+
export declare const moveSelection: (store: StoreType, axis: 'x' | 'y', value: number) => void;
|
|
17
17
|
export declare const canFitSelectionToPage: (store: StoreType) => boolean;
|
|
18
18
|
export declare const fitSelectionToPage: (store: StoreType) => void;
|
|
19
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{getTotalClientRect as t}from"./math.js";import{roundedGeometryAttrs as n,roundedGeometryPx as i,roundedStyleAttrs as o,scaledFontSizeBounds as s,isMedia as r,scaledStyleAttrs as c,textMinResizeWidth as h,textMinWidthIsMeasured as a}from"./px.js";import{textResizeFloorFontSize as l}from"./text-sizing.js";export const isAxisAligned=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1};export const canStretchAxis=(e,t,n)=>{if(!isAxisAligned(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!a(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":case"lottie":return!e.keepRatio;default:return!1}};export const leafMinSize=(e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?h(i,l(e)):1};const x=e=>{const[t]=e.selectedElements;return 1===e.selectedElements.length&&"group"!==t.type?t:null};export const getSelectionBox=e=>{const n=x(e);if(n){const{x:e,y:t,width:i,height:o}=n;return{x:e,y:t,width:i,height:o}}const i=e.selectedShapes;return i.length?t(i):null};const p=e=>!e.pendingEdit;export const canResizeSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.resizable&&p(e))};export const canMoveSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.draggable&&p(e))};const g=(e,t,n)=>{e.set(t),e.setHeightRedistribute(n),e.set({x:i(e.x),y:i(e.y),width:i(e.width)}),e._resetBaseRowHeights()},d=(e,t,i)=>{const r=i.x+(e.x-i.x)*t,h=i.y+(e.y-i.y)*t;if("table"===e.type){return void g(e,{x:r,y:h,width:e.width*t},e.height*t)}const{fontSize:a,minFontSize:l,maxFontSize:x}=e;e.set(Object.assign({x:r,y:h,width:e.width*t,height:e.height*t},c(e,t))),e.set(Object.assign(Object.assign({},n(e)),o(e))),"text"===e.type&&e.set(s({minFontSize:l,maxFontSize:x},e.fontSize/a,!0))};export const resizeSelection=(t,i,o)=>{const s=getSelectionBox(t),c="x"===i?null==s?void 0:s.width:null==s?void 0:s.height;if(!(s&&c&&o>0&&canResizeSelection(t))){return}const h=t.selectedShapes,a=x(t),l=h.every(e=>!r(e.type))&&(a?((e,t)=>"text"===e.type?"x"===t&&!e.curveEnabled:canStretchAxis(e,t,e.rotation))(a,i):h.every(e=>canStretchAxis(e,i,0))),p=Math.max(...h.flatMap(e=>(l?[i]:["x","y"]).map(t=>{const n="x"===t?e.width:e.height,i=leafMinSize(e,t,l,n);return n>=i?i/n:0}))),y=Math.max(o/c,p),u={x:s.x,y:s.y};t.history.transaction(()=>{h.forEach(t=>{l?((t,i,o,s)=>{const[r,c]="x"===i?["x","width"]:["y","height"],h={[r]:s[r]+(t[r]-s[r])*o,[c]:t[c]*o};if("table"===t.type){const{height:n=t.height}=h,i=e(h,["height"]);return void g(t,i,n)}t.set(h),t.set(n(t))})(t,i,y,u):d(t,y,u)})})};const y=(e,t,n)=>{e.forEach(e=>{e.set({x:i(e.x+t),y:i(e.y+n)})})};export const moveSelection=(e,t,n)=>{const i=getSelectionBox(e);if(!i||!Number.isFinite(n)||!canMoveSelection(e)){return}const o=n-("x"===t?i.x:i.y);e.history.transaction(()=>{y(e.selectedShapes,"x"===t?o:0,"y"===t?o:0)})};export const canFitSelectionToPage=e=>canResizeSelection(e)&&canMoveSelection(e);export const fitSelectionToPage=e=>{var n;const i=e.selectedShapes,o=null===(n=i[0])||void 0===n?void 0:n.page;if(!o||!canFitSelectionToPage(e)){return}const s=t(i);if(!s.width||!s.height){return}const r=Math.min(o.computedWidth/s.width,o.computedHeight/s.height);e.history.transaction(()=>{i.forEach(e=>d(e,r,{x:s.x,y:s.y}));const e=t(i);y(i,(o.computedWidth-e.width)/2-e.x,(o.computedHeight-e.height)/2-e.y)})};
|
package/utils/split-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getElementTimeRange as t,getVideoRestMs as e,MIN_DURATION as n}from"./timeline.js";import{clamp as i}from"../lib/utils.js";export function canSplitAtPlayhead(e,i){var a;const o=null===(a=e.page)||void 0===a?void 0:a.duration;if(!o){return!1}const{start:r,end:s}=t(e.animations,o);return i>r+n&&i<s-n}export function splitElementAtPlayhead(n,a){if(!canSplitAtPlayhead(n,a)){return null}const o=n.page.duration,{start:r}=t(n.animations,o),s=n.clone({},{skipSelect:!0});if(s.setZIndex(n.zIndex+1),n.setAnimation("exit",{name:"none",delay:o-a,enabled:!0}),s.setAnimation("enter",{name:"none",delay:a,enabled:!0}),"video"===n.type){const t=(n.endTime-n.startTime)*n.duration,o=n.speed||1;if(t>0){const d=e(a,0,r,t,n.startTime*n.duration,o),l=i(d/n.duration,n.startTime,n.endTime);s.set({startTime:l}),(a-r)*o<t&&n.set({endTime:l})}}return s}
|
|
1
|
+
import{getElementTimeRange as t,getVideoRestMs as e,MIN_DURATION as n}from"./timeline.js";import{clamp as i}from"../lib/utils.js";export function canSplitAtPlayhead(e,i){var a;if("lottie"===e.type){return!1}const o=null===(a=e.page)||void 0===a?void 0:a.duration;if(!o){return!1}const{start:r,end:s}=t(e.animations,o);return i>r+n&&i<s-n}export function splitElementAtPlayhead(n,a){if(!canSplitAtPlayhead(n,a)){return null}const o=n.page.duration,{start:r}=t(n.animations,o),s=n.clone({},{skipSelect:!0});if(s.setZIndex(n.zIndex+1),n.setAnimation("exit",{name:"none",delay:o-a,enabled:!0}),s.setAnimation("enter",{name:"none",delay:a,enabled:!0}),"video"===n.type){const t=(n.endTime-n.startTime)*n.duration,o=n.speed||1;if(t>0){const d=e(a,0,r,t,n.startTime*n.duration,o),l=i(d/n.duration,n.startTime,n.endTime);s.set({startTime:l}),(a-r)*o<t&&n.set({endTime:l})}}return s}
|
|
@@ -42,6 +42,7 @@ export type TextFormatState = {
|
|
|
42
42
|
applyTextFormat: (attrs: TextFormatAttrs, opts?: ApplyTextFormatOptions) => void;
|
|
43
43
|
enabled: boolean;
|
|
44
44
|
};
|
|
45
|
+
export declare function activeFor(store: any): ActiveTextEditor | null;
|
|
45
46
|
export declare function restoreEditorSelection(quill: Quill, range: Range): void;
|
|
46
47
|
export declare function resolveSelectionScope(quill: any, fallbackSelection: {
|
|
47
48
|
index: number;
|
|
@@ -1 +1 @@
|
|
|
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 a,DECORATION_TOKENS as c,decorationTokensOf as s,decorationTokensToString as f,decorationToQuillKey as u}from"./text-format.js";const m=e.observable({active:null},{},{deep:!1});export function getActiveTextEditor(){return m.active}export function setActiveTextEditor(t){e.runInAction(()=>{m.active=Object.assign(Object.assign({},t),{currentFormat:{},mixedFormats:{},lastSelection:null})})}export function updateActiveTextFormat(t,o,n){e.runInAction(()=>{m.active&&(m.active=Object.assign(Object.assign({},m.active),{currentFormat:t,mixedFormats:o,lastSelection:n||m.active.lastSelection}))})}export function clearActiveTextEditor(t){e.runInAction(()=>{var e;t&&(null===(e=m.active)||void 0===e?void 0:e.instance)!==t||(m.active=null)})}const x={fontSize:["size"],fontFamily:["font"],fill:["color","gradient"],fontWeight:["font-weight"],fontStyle:["italic"],textDecoration:["underline","strike"],textTransform:["text-transform"]};export const ALL_QUILL_MIXED_KEYS=Array.from(new Set(a.flatMap(t=>x[t])));function
|
|
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 a,DECORATION_TOKENS as c,decorationTokensOf as s,decorationTokensToString as f,decorationToQuillKey as u}from"./text-format.js";const m=e.observable({active:null},{},{deep:!1});export function getActiveTextEditor(){return m.active}export function setActiveTextEditor(t){e.runInAction(()=>{m.active=Object.assign(Object.assign({},t),{currentFormat:{},mixedFormats:{},lastSelection:null})})}export function updateActiveTextFormat(t,o,n){e.runInAction(()=>{m.active&&(m.active=Object.assign(Object.assign({},m.active),{currentFormat:t,mixedFormats:o,lastSelection:n||m.active.lastSelection}))})}export function clearActiveTextEditor(t){e.runInAction(()=>{var e;t&&(null===(e=m.active)||void 0===e?void 0:e.instance)!==t||(m.active=null)})}const x={fontSize:["size"],fontFamily:["font"],fill:["color","gradient"],fontWeight:["font-weight"],fontStyle:["italic"],textDecoration:["underline","strike"],textTransform:["text-transform"]};export const ALL_QUILL_MIXED_KEYS=Array.from(new Set(a.flatMap(t=>x[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));case"textTransform":return e["text-transform"]||i.textTransform||"none"}}function d(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 a){if("textDecoration"!==i){if(x[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=d(t,e,o)}}return n}export function attrsToQuillOps(t,e,o){var r;const l=[];if(void 0!==t.fontFamily&&l.push(["font",t.fontFamily]),void 0!==t.fontSize&&l.push(["size",`${t.fontSize}px`]),void 0!==t.fill&&(i(String(t.fill))?l.push(["color",!1],["gradient",t.fill]):l.push(["gradient",!1],["color",t.fill])),void 0!==t.fontWeight&&l.push(["font-weight",String(n(t.fontWeight))]),void 0!==t.fontStyle&&l.push(["italic","italic"===t.fontStyle]),void 0!==t.textDecoration){const o=null!==(r=null==e?void 0:e.decorationTokens)&&void 0!==r?r:c,n=s(t.textDecoration);for(const t of c){o.includes(t)&&l.push([u(t),n.has(t)])}}return void 0!==t.textTransform&&l.push(["text-transform",t.textTransform!==o&&t.textTransform]),l}function v(t){const e=[];for(const o of(null==t?void 0:t.selectedElements)||[]){"text"===o.type?e.push(o):"table"===o.type&&e.push(...o.textCells)}return e}export function activeFor(t){const e=getActiveTextEditor();return e&&e.instance&&e.store===t?e:null}export function restoreEditorSelection(t,e){t.composition.isComposing||(t.update(),t.setSelection(e))}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,i){const r=attrsToQuillOps(e,n,i);if(!r.length){return}const{scope:l,sel:a}=resolveSelectionScope(t,null!=o?o:null);for(const[c,s]of r){"collapsed"===l?t.format(c,s,"user"):t.formatText(a.index,a.length,c,s,"user")}"collapsed"===l&&updateActiveTextFormat(t.getFormat(a.index,0),{},a)}function g(t,e){const o="function"==typeof t.getLength?t.getLength():0;t.formatText(0,o,e,!0,"api")}export function getTextFormatState(t){const e=activeFor(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,textTransform:i.textTransform}):r(o),enabled:n,applyTextFormat:(e,o)=>function(t,e,o){const n=activeFor(t);if(!n){return void l(v(t),e,o)}const{scope:i,sel:r,isEmpty:a}=resolveSelectionScope(n.instance,n.lastSelection);"full"===i||"collapsed"===i&&!a?l([n.element],e,o):function(t,e,o,n){var i,r;const l=t.instance,a=t.element;let m=!1;if(n.length>0){if(void 0!==e.fontStyle&&"italic"!==e.fontStyle&&"italic"===a.fontStyle&&(g(l,"italic"),a.set({fontStyle:"normal"}),m=!0),void 0!==e.textDecoration){const t=null!==(r=null==o?void 0:o.decorationTokens)&&void 0!==r?r:c,n=s(e.textDecoration),i=s(a.textDecoration),x=t.filter(t=>!n.has(t)&&i.has(t));for(const e of x){g(l,u(e)),i.delete(e)}x.length&&(a.set({textDecoration:f(i)}),m=!0)}m&&"function"==typeof(null===(i=l.history)||void 0===i?void 0:i.clear)&&l.history.clear()}applyToLiveEditor(l,e,n,o,a.textTransform)}(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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const FORMAT_KEYS: readonly [
|
|
1
|
+
export declare const FORMAT_KEYS: readonly ['fontSize', 'fontFamily', 'fill', 'fontWeight', 'fontStyle', 'textDecoration', 'textTransform'];
|
|
2
2
|
export type FormatKey = (typeof FORMAT_KEYS)[number];
|
|
3
3
|
export type FormatValue<T> = {
|
|
4
4
|
value: T | undefined;
|
|
@@ -31,7 +31,7 @@ export type ApplyTextFormatOptions = {
|
|
|
31
31
|
export declare function decorationTokensOf(value: string | undefined): Set<DecorationToken>;
|
|
32
32
|
export declare function decorationTokensToString(tokens: Set<DecorationToken>): string;
|
|
33
33
|
export declare function isDecorationActive(f: TextFormat, token: DecorationToken): boolean;
|
|
34
|
-
export declare const decorationToQuillKey: (t: DecorationToken) =>
|
|
34
|
+
export declare const decorationToQuillKey: (t: DecorationToken) => 'underline' | 'strike';
|
|
35
35
|
export interface TextFormatElement {
|
|
36
36
|
type?: string;
|
|
37
37
|
text: string;
|
package/utils/text-sizing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TextSizing, type TextSizingElement } from '@polotno/core/text-sizing';
|
|
2
2
|
import type { TextOverflow } from '@polotno/core/text-html';
|
|
3
|
-
export declare const textOverflowOf: (element: Pick<TextSizingElement,
|
|
3
|
+
export declare const textOverflowOf: (element: Pick<TextSizingElement, 'textOverflow'>) => TextOverflow;
|
|
4
4
|
export declare function editorTextSizing(element: TextSizingElement): TextSizing;
|
|
5
5
|
export declare function textResizeFloorFontSize(element: TextSizingElement): number;
|
package/utils/timeline.d.ts
CHANGED
|
@@ -10,7 +10,35 @@ export declare function getElementTimeRange(animations: readonly AnimationTiming
|
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
12
|
};
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function localTimeOn(time: number, startTime: number, duration: number): number | null;
|
|
14
|
+
export declare function isHeldByPreview(self: {
|
|
15
|
+
id: string;
|
|
16
|
+
store: {
|
|
17
|
+
animatedElementsIds: readonly string[];
|
|
18
|
+
};
|
|
19
|
+
}): boolean;
|
|
20
|
+
type PreviewNode = {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
parent?: PreviewNode | null;
|
|
24
|
+
};
|
|
25
|
+
export declare function getPlayheadLocalTime(self: PreviewNode & {
|
|
26
|
+
page?: {
|
|
27
|
+
playheadLocalTime: number | null;
|
|
28
|
+
startTime: number;
|
|
29
|
+
duration: number;
|
|
30
|
+
} | null;
|
|
31
|
+
store: {
|
|
32
|
+
animatedElementsIds: readonly string[];
|
|
33
|
+
_previewHold: number | null;
|
|
34
|
+
getElementById(id: string): PreviewNode | undefined;
|
|
35
|
+
};
|
|
36
|
+
}): number | null;
|
|
14
37
|
export declare function revealElementAtPlayhead(element: any): void;
|
|
15
|
-
|
|
38
|
+
type VideoFrameSampling = {
|
|
39
|
+
windowEnd?: number;
|
|
40
|
+
frameMs?: number;
|
|
41
|
+
renderEnd?: number;
|
|
42
|
+
};
|
|
43
|
+
export declare function getVideoRestMs(currentTime: number, pageStartTime: number, enterStart: number, trimDurationMs: number, offsetMs: number, speed?: number, { windowEnd, frameMs, renderEnd, }?: VideoFrameSampling): number;
|
|
16
44
|
export {};
|
package/utils/timeline.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const MIN_DURATION=100;const e=(e,t)=>{const n=e.animations.find(e=>e.type===t);n&&n.enabled||e.setAnimation(t,{name:"none",enabled:!0})};export function setElementTimeRange(t,n,a,i){const
|
|
1
|
+
export const MIN_DURATION=100;const e=(e,t)=>{const n=e.animations.find(e=>e.type===t);n&&n.enabled||e.setAnimation(t,{name:"none",enabled:!0})};export function setElementTimeRange(t,n,a,i){const r=Math.min(Math.max(a,0),n-100),o=Math.min(Math.max(i,r+100),n);e(t,"enter"),e(t,"exit"),t.setAnimation("enter",{delay:r}),t.setAnimation("exit",{delay:Math.max(0,n-o)})}export function getElementTimeRange(e,t){const n=null==e?void 0:e.find(e=>"enter"===e.type),a=null==e?void 0:e.find(e=>"exit"===e.type),i=Math.max(0,Math.min(t,(null==n?void 0:n.enabled)?n.delay:0)),r=Math.min(t,(null==a?void 0:a.enabled)?t-a.delay:t);return{start:i,end:Math.max(i,r)}}export function localTimeOn(e,t,n){const a=e-t;return a<0||a>n?null:Math.min(a,Math.max(0,n-1))}export function isHeldByPreview(e){const t=e.store.animatedElementsIds;return t.length>0&&!t.includes(e.id)}function t(e,t){for(let n=null==e?void 0:e.parent;"group"===(null==n?void 0:n.type);n=n.parent){if(n===t){return!0}}return!1}export function getPlayheadLocalTime(e){const n=e.page;if(!n){return null}if(!isHeldByPreview(e)){return n.playheadLocalTime}const a=e.store._previewHold;return null===a||e.store.animatedElementsIds.some(n=>{const a=e.store.getElementById(n);return t(e,a)||t(a,e)})?null:localTimeOn(a,n.startTime,n.duration)}export function revealElementAtPlayhead(e){const t=e.store,n=e.page;if("playhead"!==t.timingPreview||!n){return}const{start:a,end:i}=getElementTimeRange(e.animations,n.duration),r=t.effectiveTime-n.startTime;if(r>=a&&r<i){return}const o=Math.max(a,Math.min(r,Math.max(a,i-1)));t.setCurrentTime(n.startTime+o)}export function getVideoRestMs(e,t,n,a,i,r=1,{windowEnd:o=1/0,frameMs:l=0,renderEnd:m=1/0}={}){const s=(e||t)-t-n,d=Math.min(o,m-t)-n,u=a/r,c=Math.floor(d/u)*u;return c>0&&s>=c&&d-c<l?Math.max(0,a-1)+i:(s<=0?0:s*r%a)+i}
|
package/utils/to-html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,o){var e={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(r=Object.getOwnPropertySymbols(t);l<r.length;l++){o.indexOf(r[l])<0&&Object.prototype.propertyIsEnumerable.call(t,r[l])&&(e[r[l]]=t[r[l]])}}return e};export*from"@polotno/html-export";import{jsonToHTML as o,jsonToDOM as e}from"@polotno/html-export";import{flags as r}from"./flags.js";export const jsonToDOM=o=>{var{json:
|
|
1
|
+
var t=this&&this.__rest||function(t,o){var e={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(r=Object.getOwnPropertySymbols(t);l<r.length;l++){o.indexOf(r[l])<0&&Object.prototype.propertyIsEnumerable.call(t,r[l])&&(e[r[l]]=t[r[l]])}}return e};export*from"@polotno/html-export";import{jsonToHTML as o,jsonToDOM as e}from"@polotno/html-export";import{flags as r}from"./flags.js";import{getKey as l}from"./validate-key.js";export const jsonToDOM=o=>{var{json:n}=o,s=t(o,["json"]);return e(n,Object.assign({key:l(),textOverflow:r.textOverflow,textSplitAllowed:r.textSplitAllowed},s))};export const jsonToHTML=e=>{var{json:n}=e,s=t(e,["json"]);return o(n,Object.assign({key:l(),textOverflow:r.textOverflow,textSplitAllowed:r.textSplitAllowed},s))};console.warn('"polotno/utils/to-html" is deprecated, use the "@polotno/html-export" package instead');
|
package/utils/to-svg.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var o=this&&this.__rest||function(o,t){var
|
|
1
|
+
var o=this&&this.__rest||function(o,t){var e={};for(var r in o){Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r])}if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++){t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}}return e};export*from"@polotno/svg-export";import{jsonToSVG as t,jsonToDOM as e}from"@polotno/svg-export";import{getKey as r}from"./validate-key.js";export const jsonToDOM=t=>{var{json:n}=t,s=o(t,["json"]);return e(n,Object.assign({key:r()},s))};export const jsonToSVG=e=>{var{json:n}=e,s=o(e,["json"]);return t(n,Object.assign({key:r()},s))};console.warn('"polotno/utils/to-svg" is deprecated, use the "@polotno/svg-export" package instead');
|
package/utils/validate-key.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"mobx";import{
|
|
1
|
+
import*as e from"mobx";import{NO_KEY_MESSAGE as o,NO_VALID_MESSAGE as t,NOT_PAID_MESSAGE as n,NOT_PAID_STYLE as a}from"@polotno/core/validate-key";import{getAPI as i}from"./api.js";import{removeBackgroundState as r}from"./flags.js";const s=e.observable({value:!1}),l=e.observable({value:"v1"});export const ___=()=>l.value;const c=e.observable({value:0});export const ____=()=>c.value;export const isCreditVisible=()=>s.value;const d=e.action(()=>{s.value=!0});let u="";export const getKey=()=>u||"";export const setKey=e=>{u=e||""};let p="undefined"!=typeof window?window.location.origin:"";const v="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,f="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===p&&v&&(p="headless"),"file://"===p&&f&&(p="electron");const m=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${p}" here: https://polotno.com/cabinet`;let g=fetch;export const __=e=>{g=e};export async function isKeyPaid(s){for(let u=0;u<5;u++){try{const d=await g(i()+"/validate-key",{method:"POST",body:JSON.stringify({key:s,sdkVersion:"4.20.1"})});if(e.runInAction(()=>{l.value=d.headers.get("x-api-version")||""}),!s){return console.error(o),e.runInAction(()=>{c.value=1}),!1}if(200!==d.status){await new Promise(e=>setTimeout(e,3e3));continue}const u=await d.json();return u.is_valid||(console.error(t),e.runInAction(()=>{c.value=1})),u.is_paid||(console.log(n,a),e.runInAction(()=>{0===c.value&&(c.value=2)})),u.is_domain_valid||console.log(m,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{r.defaultEnabled=u.remove_background_enabled}),u.is_paid||!1}catch(d){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(u)&&!e||d()}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const BAND_ROWS = 64;
|
|
2
|
-
export declare function setDownscaleBandRows(rows?: number): void;
|
|
3
|
-
export declare function bandRows(dstH: number): number;
|
|
4
|
-
export interface Band {
|
|
5
|
-
y0: number;
|
|
6
|
-
y1: number;
|
|
7
|
-
srcFirst: number;
|
|
8
|
-
srcCount: number;
|
|
9
|
-
}
|
|
10
|
-
export declare function planBands(starts: Int32Array, counts: Int32Array, dstH: number): Band[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const BAND_ROWS=64;let t;export function setDownscaleBandRows(n){t=n}export function bandRows(n){return Math.min(null!=t?t:64,n)}export function planBands(t,n,o){const r=[],s=bandRows(o);for(let e=0;e<o;e+=s){const a=Math.min(o,e+s);let c=1/0,u=-1/0;for(let o=e;o<a;o++){0!==n[o]&&(c=Math.min(c,t[o]),u=Math.max(u,t[o]+n[o]-1))}r.push(u<c?{y0:e,y1:a,srcFirst:0,srcCount:0}:{y0:e,y1:a,srcFirst:c,srcCount:u-c+1})}return r}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AxisFilter, DownscaleEngine } from './downscale.js';
|
|
2
|
-
export declare const loadDownscaleKernel: () => Promise<boolean>;
|
|
3
|
-
export interface RowSource {
|
|
4
|
-
width: number;
|
|
5
|
-
rows(first: number, count: number): Uint8ClampedArray;
|
|
6
|
-
}
|
|
7
|
-
export declare function runResample(source: RowSource, dstW: number, dstH: number, filterX: AxisFilter, filterY: AxisFilter, unsharpStrength: number, engine?: DownscaleEngine): ImageData;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{DOWNSCALE_KERNEL_WASM as t}from"./downscale-kernel.wasm.js";import{bandRows as s,planBands as e}from"./downscale-bands.js";import{decodeBase64 as r}from"../utils/base64.js";import*as n from"./downscale-passes.js";let a,o=!1;const l=(async()=>{try{return a=await WebAssembly.compile(r(t)),!0}catch(s){return!1}})();export const loadDownscaleKernel=()=>l;export function runResample(t,r,l,c,i,m,w){const u=t.width,p=e(i.starts,i.counts,l),y=Math.max(0,...p.map(t=>t.srcCount)),h=function(t,e,r,n,a,o){let l=0;const c=t=>{const s=l;return l+=16*Math.ceil(t/16),s},i=t*e;return{srcU8:c(4*i),srcU16:c(8*i),rows:c(r*e*16),columns:c(r*s(n)*16),out:c(r*n*4),scratch:c(3*r*16),rowBuf:c(16*t),startsX:c(4*r),countsX:c(4*r),weightsX:c(a.weights.byteLength),startsY:c(4*s(n)),countsY:c(4*n),weightsY:c(o.weights.byteLength),bytes:l}}(u,y,r,l,c,i),f="js"===w?void 0:a;if("wasm"===w&&!f){throw new Error("downscale kernel unavailable")}let g,d;if(f){o||(o=!0,function(){const t=new Uint8ClampedArray(262144);for(let r=0;r<t.length;r++){t[r]=31*r&255}const s=function(t){const s=new Int32Array(t),e=new Int32Array(t).fill(2),r=new Float32Array(256).fill(.5);for(let n=0;n<t;n++){s[n]=2*n}return{starts:s,counts:e,weights:r,maxTaps:2}}(128),e={width:256,rows:(s,e)=>t.subarray(256*s*4,256*(s+e)*4)};for(let r=0;r<8;r++){runResample(e,128,128,s,s,.1,"wasm")}}());const t=Math.ceil(h.bytes/65536),s=new WebAssembly.Memory({initial:t,maximum:t});d=new WebAssembly.Instance(f,{env:{memory:s}}).exports,g=s.buffer}else{g=new ArrayBuffer(h.bytes),d=function(t){const s=(s,e)=>new Uint8ClampedArray(t,s,e),e=(s,e)=>new Uint16Array(t,s,e),r=(s,e)=>new Float32Array(t,s,e),a=(s,e,n,a,o)=>({starts:new Int32Array(t,s,a),counts:new Int32Array(t,e,a),weights:r(n,a*o),maxTaps:o});return{toPremultiplied:(t,r,a)=>n.toPremultiplied(s(t,4*a),e(r,4*a)),resampleRows:(t,s,o,l,c,i,m,w,u,p)=>n.resampleRows(e(t,l*c*4),l,c,i,a(m,w,u,i,p),r(s,i*c*4)),resampleColumns:(t,s,e,o,l,c,i,m)=>n.resampleColumns(r(t),e,o,a(l,c,i,o,m),r(s,e*o)),fromPremultiplied:(t,e,a)=>n.fromPremultiplied(r(t,4*a),s(e,4*a)),magicSharpen:(t,e,a,o)=>n.magicSharpen(s(t,a*o*4),r(e,9*a),a,o),gatedUnsharp:(t,e,r,a,o)=>n.gatedUnsharp(s(t,r*a*4),s(e,12*r),r,a,o)}}(g)}new Int32Array(g,h.startsX,r).set(c.starts),new Int32Array(g,h.countsX,r).set(c.counts),new Float32Array(g,h.weightsX,c.weights.length).set(c.weights),new Int32Array(g,h.countsY,l).set(i.counts),new Float32Array(g,h.weightsY,i.weights.length).set(i.weights);const A=new Int32Array(g,h.startsY,s(l)),b=new Uint8ClampedArray(g,h.srcU8,u*y*4);for(const s of p){const e=s.y1-s.y0;s.srcCount>0&&b.set(t.rows(s.srcFirst,s.srcCount));for(let t=0;t<e;t++){A[t]=i.starts[s.y0+t]-s.srcFirst}d.toPremultiplied(h.srcU8,h.srcU16,u*s.srcCount),d.resampleRows(h.srcU16,h.rows,h.rowBuf,u,s.srcCount,r,h.startsX,h.countsX,h.weightsX,c.maxTaps),d.resampleColumns(h.rows,h.columns,4*r,e,h.startsY,h.countsY+4*s.y0,h.weightsY+s.y0*i.maxTaps*4,i.maxTaps),d.fromPremultiplied(h.columns,h.out+s.y0*r*4,e*r)}return d.magicSharpen(h.out,h.scratch,r,l),m>0&&d.gatedUnsharp(h.out,h.scratch,r,l,m),new ImageData(new Uint8ClampedArray(g,h.out,r*l*4),r,l)}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DOWNSCALE_KERNEL_WASM: string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DOWNSCALE_KERNEL_WASM = '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';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AxisFilter } from './downscale.js';
|
|
2
|
-
export declare function toPremultiplied(src: Uint8ClampedArray, dst: Uint16Array): void;
|
|
3
|
-
export declare function resampleRows(src: Uint16Array, srcW: number, srcRows: number, dstW: number, filter: AxisFilter, dst: Float32Array): void;
|
|
4
|
-
export declare function resampleColumns(src: Float32Array, rowFloats: number, rows: number, filter: AxisFilter, dst: Float32Array): void;
|
|
5
|
-
export declare function fromPremultiplied(src: Float32Array, dst: Uint8ClampedArray): void;
|
|
6
|
-
export declare function magicSharpen(data: Uint8ClampedArray, tmp: Float32Array, width: number, height: number): void;
|
|
7
|
-
export declare function gatedUnsharp(data: Uint8ClampedArray, ring: Uint8ClampedArray, width: number, height: number, strength: number): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function toPremultiplied(t,o){for(let n=0;n<t.length;n+=4){const e=t[n+3];o[n]=t[n]*e,o[n+1]=t[n+1]*e,o[n+2]=t[n+2]*e,o[n+3]=e}}export function resampleRows(t,o,n,e,s,l){const{starts:r,counts:c,weights:f,maxTaps:a}=s;let i=0;for(let m=0;m<n;m++){const n=m*o*4;for(let o=0;o<e;o++){const e=c[o],s=o*a;let m=n+4*r[o],h=0,u=0,p=0,x=0;for(let o=0;o<e;o++,m+=4){const n=f[s+o];h+=t[m]*n,u+=t[m+1]*n,p+=t[m+2]*n,x+=t[m+3]*n}l[i++]=h,l[i++]=u,l[i++]=p,l[i++]=x}}}export function resampleColumns(t,o,n,e,s){const{starts:l,counts:r,weights:c,maxTaps:f}=e;for(let a=0;a<n;a++){const n=r[a],e=a*f,i=a*o;s.fill(0,i,i+o);for(let r=0;r<n;r++){const n=c[e+r],f=(l[a]+r)*o;for(let e=0;e<o;e++){s[i+e]+=t[f+e]*n}}}}export function fromPremultiplied(t,o){for(let n=0;n<o.length;n+=4){const e=t[n+3];if(e>.001){const s=1/e;o[n]=t[n]*s,o[n+1]=t[n+1]*s,o[n+2]=t[n+2]*s}else{o[n]=0,o[n+1]=0,o[n+2]=0}o[n+3]=e}}const t=-.25;export function magicSharpen(o,n,e,s){const l=3*e,r=t=>t%3*l;let c=0;for(let f=0;f<s;f++){for(const u=Math.min(f+1,s-1);c<=u;c++){const s=r(c);for(let l=0;l<e;l++){const r=4*(c*e+l),f=4*(c*e+Math.max(0,l-1)),a=4*(c*e+Math.min(e-1,l+1)),i=o[f+3]>0?t:0,m=o[a+3]>0?t:0,h=t-i+1.5+(t-m),u=s+3*l;for(let t=0;t<3;t++){n[u+t]=h*o[r+t]+i*o[f+t]+m*o[a+t]}}}const l=Math.max(0,f-1),a=Math.min(s-1,f+1),i=r(f),m=r(l),h=r(a);for(let s=0;s<e;s++){const r=4*(f*e+s);if(0===o[r+3]){continue}const c=o[4*(l*e+s)+3]>0?t:0,u=o[4*(a*e+s)+3]>0?t:0,p=t-c+1.5+(t-u),x=3*s;for(let t=0;t<3;t++){o[r+t]=p*n[i+x+t]+c*n[m+x+t]+u*n[h+x+t]}}}}export function gatedUnsharp(t,o,n,e,s){const l=4*n,r=t=>t%3*l,c=[0,0,0];let f=0;for(let a=0;a<e;a++){for(const n=Math.min(a+1,e-1);f<=n;f++){o.set(t.subarray(f*l,(f+1)*l),r(f))}const i=r(a),m=r(Math.max(0,a-1)),h=r(Math.min(e-1,a+1)),u=a*l;for(let e=0;e<n;e++){const l=4*e,r=i+l;if(0===o[r+3]){continue}let f=e>0?r-4:r;0===o[f+3]&&(f=r);let a=e<n-1?r+4:r;0===o[a+3]&&(a=r);let p=m+l;0===o[p+3]&&(p=r);let x=h+l;0===o[x+3]&&(x=r);let M=0;for(let t=0;t<3;t++){c[t]=4*o[r+t]-o[f+t]-o[a+t]-o[p+t]-o[x+t],M=Math.max(M,Math.abs(c[t]))}if(M<=47){continue}const g=s*Math.min(1,(M-47)/19);for(let n=0;n<3;n++){t[u+l+n]=o[r+n]+c[n]*g}}}}
|