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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageElementType } from '../model/image-model.js';
|
|
3
|
+
export declare const LoadingPlaceholder: (({ element }: {
|
|
4
|
+
element: ImageElementType;
|
|
5
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
6
|
+
element: ImageElementType;
|
|
7
|
+
}> & {
|
|
8
|
+
readonly type: ({ element }: {
|
|
9
|
+
element: ImageElementType;
|
|
10
|
+
}) => React.JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
export declare const ErrorPlaceholder: (({ element, text }: {
|
|
13
|
+
element: ImageElementType;
|
|
14
|
+
text: string;
|
|
15
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
16
|
+
element: ImageElementType;
|
|
17
|
+
text: string;
|
|
18
|
+
}> & {
|
|
19
|
+
readonly type: ({ element, text }: {
|
|
20
|
+
element: ImageElementType;
|
|
21
|
+
text: string;
|
|
22
|
+
}) => React.JSX.Element;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as t,jsxs as i}from"react/jsx-runtime";import e from"react";import{observer as a}from"mobx-react-lite";import{Arc as r,Group as o,Rect as n,Text as l}from"react-konva";import h from"konva";import{elementOpacity as s}from"./paint-opacity.js";import{useWorkspaceStyle as m}from"./workspace-style.js";export const LoadingPlaceholder=a(({element:a})=>{const l=Math.min(30,a.a.width/4,a.a.height/4),d=e.useRef(null);e.useEffect(()=>{const t=d.current;if(!t){return}const i=new h.Animation(i=>{t.rotate(((null==i?void 0:i.timeDiff)||0)/2)},t.getLayer());return i.start(),()=>{i.stop()}},[]);const{mediaLoadingStyle:c}=m();return i(o,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,listening:!1,opacity:s(a),hideInExport:!a.showInExport,children:[t(n,{width:a.a.width,height:a.a.height,fill:c.fill}),t(r,{ref:d,x:a.a.width/2,y:a.a.height/2,fill:c.textFill,outerRadius:Math.abs(l),innerRadius:Math.max(1,l-5),angle:270})]})});export const ErrorPlaceholder=a(({element:e,text:a})=>{const{mediaErrorStyle:r}=m(),h=Math.max(10,Math.min(30,e.a.width/a.length));return i(o,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:s(e),hideInExport:!e.showInExport,children:[t(n,{width:e.a.width,height:e.a.height,fill:r.fill}),t(l,{text:a,fontSize:h,width:e.a.width,height:e.a.height,align:"center",fill:r.textFill,verticalAlign:"middle",padding:5})]})});
|
|
@@ -4,19 +4,19 @@ export declare const PageControls: (({ store, page, xPadding, yPadding, layout,
|
|
|
4
4
|
page: PageType;
|
|
5
5
|
xPadding: number;
|
|
6
6
|
yPadding: number;
|
|
7
|
-
layout?:
|
|
7
|
+
layout?: 'vertical' | 'horizontal';
|
|
8
8
|
}) => import("react").JSX.Element | null) & import("react").NamedExoticComponent<{
|
|
9
9
|
store: StoreType;
|
|
10
10
|
page: PageType;
|
|
11
11
|
xPadding: number;
|
|
12
12
|
yPadding: number;
|
|
13
|
-
layout?:
|
|
13
|
+
layout?: 'vertical' | 'horizontal';
|
|
14
14
|
}> & {
|
|
15
15
|
readonly type: ({ store, page, xPadding, yPadding, layout, }: {
|
|
16
16
|
store: StoreType;
|
|
17
17
|
page: PageType;
|
|
18
18
|
xPadding: number;
|
|
19
19
|
yPadding: number;
|
|
20
|
-
layout?:
|
|
20
|
+
layout?: 'vertical' | 'horizontal';
|
|
21
21
|
}) => import("react").JSX.Element | null;
|
|
22
22
|
};
|
package/canvas/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{clamp as r}from"../lib/utils.js";import{observer as l,useLocalObservable as s}from"mobx-react-lite";import{action as a,runInAction as c}from"mobx";import{isAlive as d}from"mobx-state-tree";import{ZERO_BLEED as m}from"@polotno/schema";import{Group as u,Image as h,Label as g,Layer as f,Line as p,Rect as x,Shape as v,Stage as b,KonvaRenderer as y,Tag as w,Text as E,Transformer as S}from"react-konva";import{useWorkspaceStyle as X}from"./workspace-style.js";import{ROLES as Y}from"../model/store.js";import k from"konva";import A from"./element.js";import{DrawingLayer as M}from"./drawing-layer.js";import{ensureDragOrder as j,useSnap as I}from"./use-transformer-snap.js";import{useImageLoader as P,useSizedImage as O}from"./image-element.js";import{FadeOverlay as R}from"./fade-overlay.js";import{getCrop as T}from"../utils/crop.js";import{cloneBehind as D}from"../utils/duplicate.js";import{___ as B,____ as C,isCreditVisible as W}from"../utils/validate-key.js";import{getClientRect as G,getCorners as L,getTotalClientRect as V,polygonsIntersect as F}from"../utils/math.js";import{pxToUnitRounded as z,pxToUnitString as _}from"../utils/unit.js";import{isCornerAnchor as U,isRotateAnchor as Z,MAIN_TRANSFORMER_NAME as H}from"../utils/px.js";import{canStretchAxis as J,isAxisAligned as N,leafMinSize as K}from"../utils/selection-transform.js";import{restoreHeldPoint as $}from"./transform-box.js";import{flags as Q}from"../utils/flags.js";import{textOverflowOf as q}from"../utils/text-sizing.js";import{useColor as ee}from"./use-color.js";import{isGradient as te}from"@polotno/core/gradient";import{toDisplayColor as ne}from"@polotno/core/color";import{Html as ie}from"react-konva-utils";import{getParentGroupId as oe,withoutDescendants as re}from"../utils/selection.js";import{nodeReaction as le}from"../utils/mobx.js";import{useEvent as se}from"../hooks/use-event.js";const ae=o.version.startsWith("18.")?o.forwardRef((e,n)=>(o.useLayoutEffect(()=>{y.flushSync()}),t(b,Object.assign({},e,{ref:n})))):b,ce={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},de=e=>{if(!e.length){return null}const t=N(e[0].rotation)?0:e[0].rotation;return e.every(e=>N(e.rotation-t))?t:null},me=e=>e.selectedShapes.filter(t=>{var n;return(null===(n=e.activeTool)||void 0===n?void 0:n.elementId)!==t.id&&!t.pendingEdit}),ue=e=>e.selectedShapes.some(e=>!e.resizable),he=e=>e.selectedShapes.some(e=>!e.draggable),ge=e=>{var t;return 1!==e.selectedElements.length||"group"===(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)},fe=e=>{var t;const n=me(e),i=ge(e),o=null!==(t=de(n))&&void 0!==t?t:0,r=e=>i&&n.length>0&&n.every(t=>J(t,e,o));return{boxRotation:o,canStretchX:r("x"),canStretchY:r("y")}},pe={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){pe[e]=pe[e]||t,Object.assign(pe[e],t)}const xe=e=>t(x,Object.assign({},e,{preventDefault:!1})),ve=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=O(i),s=r?T(r,{width:o.width,height:o.height},"center-middle"):{};return P(l,i,"page background"),t(h,Object.assign({image:r},o,s))},be=e=>{const n=ee({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(x,Object.assign({},e,n))},ye=n=>{var{background:i,transparencyBackgroundColor:r}=n,l=e(n,["background","transparencyBackgroundColor"]);const s=o.useMemo(()=>{if(te(i)){return!0}const e=k.Util.colorToRGBA(i);return!e||e.a<1},[i]),a=o.useMemo(()=>{if(!s||r){return}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[s,r]);return s?t(x,r?Object.assign({fill:r},l,{hideInExport:!0}):Object.assign({fillPatternImage:a},l,{opacity:.1,hideInExport:!0})):null},we=n=>{var{background:i}=n,r=e(n,["background"]);return o.useMemo(()=>!!k.Util.colorToRGBA(i)||te(i),[i])?t(be,Object.assign({fill:i},r)):t(ve,Object.assign({url:i},r))},Ee=l(({selection:e})=>{const{selectionRectStyle:n}=X();return e.visible?t(x,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function Se(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const Xe=l(({gesture:e,store:o})=>{const{transformLabelStyle:r}=X(),{x:l,y:s,width:a,height:c,rotation:d,anchor:m}=e.label;if(void 0===l||void 0===s||void 0===a||void 0===c||void 0===d||void 0===m){return null}const u=G({x:l,y:s,width:a,height:c,rotation:k.Util.radToDeg(d)}),h=null!==m&&Z(m),f=(c/2+70)*Math.cos(d-Math.PI/2),p=(c/2+70)*Math.sin(d-Math.PI/2),x=z({unit:o.unit,dpi:o.dpi,px:a/o.scale,precious:"px"===o.unit?0:1})+" x "+z({unit:o.unit,dpi:o.dpi,px:c/o.scale,precious:"px"===o.unit?0:1})+("px"===o.unit?"":" "+o.unit);return n(i,{children:[n(g,{x:(u.minX+u.maxX)/2+f,y:(u.minY+u.maxY)/2+p,offsetX:14,offsetY:14,visible:h,children:[t(w,{cornerRadius:5,fill:r.fill}),t(E,{align:"center",verticalAlign:"middle",fill:r.textFill,padding:8,text:Se(d).toString()+"°"})]}),n(g,{x:(u.minX+u.maxX)/2,y:u.maxY+20,visible:!h,children:[t(w,{cornerRadius:5,fill:r.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(E,{align:"center",verticalAlign:"middle",fill:r.textFill,padding:8,text:x})]})]})}),Ye=l(({store:e,gesture:t,transformerStyle:n,onChange:i})=>{var r;const l=e.selectedElements.some(e=>e.curveEnabled),s=e.selectedElements.some(e=>!e.visible),a=JSON.stringify(me(e).map(e=>e.id)),c=!ge(e)&&e.selectedElements[0].keepRatio,d=!ge(e)&&"text"===(null===(r=e.selectedElements[0])||void 0===r?void 0:r.type)&&"fit"===q(e.selectedElements[0]),m=t.transforming?null:fe(e);return o.useLayoutEffect(()=>{i()},[e.selectedShapes,a,ue(e),s,he(e),l,c,d,t.transforming,null==m?void 0:m.canStretchX,null==m?void 0:m.canStretchY,null==m?void 0:m.boxRotation,n]),null}),ke=()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")},Ae=l(({page:e})=>{const t=e._exportingOrRendering||e._forceMount;return o.useEffect(()=>{if(t&&d(e)){return e.set({_exportRendered:!0}),()=>{d(e)&&e.set({_exportRendered:!1})}}},[e,t]),null}),Me=l(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(A,{store:n,element:e,onClick:ke},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let je=null;export const registerNextDomDrop=e=>{je=e};const Ie=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),Pe=atob("I2MwMzkyYg=="),Oe=atob("djAuOS4y"),Re=e=>t(i,{children:n(g,{fill:Pe,height:200,children:[t(w,{fill:Pe}),t(E,Object.assign({},e,{fill:"white",text:Ie,height:void 0,padding:10,fontSize:20}))]})}),Te=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),De=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),Be=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),Ce=e=>{const i=1===C(),o=i?De:Te,r=i?230:195;return n(u,Object.assign({},e,{listening:!1,children:[t(x,{fill:Pe,width:r,height:24,cornerRadius:2}),t(E,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(E,{text:Be,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default l(({store:i,page:l,width:d,height:h,pageControlsEnabled:b,components:y,altCloneEnabled:A,groupSelectionMode:P="drill",viewportSize:O,layout:T="vertical",tooltipSafeArea:z,transformerSafeArea:Z})=>{const J=X(),ee=J.transformerStyle,te=ce,ve=l.computedBleed,be=i.bleedVisible?ve:m,Se=l.computedWidth+be.left+be.right,ke=l.computedHeight+be.top+be.bottom,Ie=(d-Se*i.scale)/2,Pe=(h-ke*i.scale)/2,Te={x:-ve.left,y:-ve.top,width:l.computedWidth+ve.left+ve.right,height:l.computedHeight+ve.top+ve.bottom,background:ne(l.background),name:"page-background",preventDefault:!1},De={x:-be.left,y:-be.top,width:Se,height:ke},Be=o.useRef(null),We=o.useRef(null),Ge=o.useRef(null),Le=o.useRef(null),Ve=null==b||b,Fe=o.useRef(!1),[ze,_e]=o.useState(null),Ue=s(()=>({transforming:!1,label:{},setLabel(e){this.label=e},setTransforming(e){this.transforming=e}})),[Ze,He]=o.useState(0),Je=useContextMenu({store:i}),Ne=me(i),Ke=ge(i),$e=()=>{var t,n,o;const r=Be.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=me(i),a=new Set(s.map(e=>e.id)),c=new Map;a.size&&l.find(e=>{const t=e.id();return a.has(t)&&!c.has(t)&&c.set(t,e),!1});const d=s.map(e=>c.get(e.id)).filter(e=>!!e),m=1===i.selectedElements.length,u=m&&(null===(t=i.selectedElements[0])||void 0===t?void 0:t.type)||"many",h=pe[u],g=Object.assign(Object.assign({},te),h||{});h&&("svg"!==u&&"image"!==u&&"gif"!==u||i.selectedElements[0].keepRatio||(g.enabledAnchors=te.enabledAnchors),"text"!==u||!Q.textVerticalResizeEnabled&&"fit"!==q(i.selectedElements[0])||(g.enabledAnchors=null===(n=pe.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===u&&m&&i.selectedElements[0].curveEnabled&&(g.enabledAnchors=pe.many.enabledAnchors));const f=fe(i);(f.canStretchX||f.canStretchY)&&(g.enabledAnchors=[...g.enabledAnchors||[],...f.canStretchX?["middle-left","middle-right"]:[],...f.canStretchY?["top-center","bottom-center"]:[]]);const{boundBoxFunc:p}=ee,x=e(ee,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},g),x),{name:H})),ue(i)&&r.enabledAnchors([]),he(i)&&r.rotateEnabled(!1);const v=r.nodes();if(v.length===d.length&&d.every((e,t)=>v[t]===e)||r.nodes(d),ge(i)&&d.length){const e=de(s);null===e||N(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),d},Qe=se(()=>{var e;if(null===(e=Be.current)||void 0===e?void 0:e.isTransforming()){return}const t=$e();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),j())}),qe=()=>{var e,t;const n=Be.current;if(!n){return}if(!n.isTransforming()){return void Ue.setLabel({})}if(!n.nodes().length){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ue.setLabel({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},et=o.useCallback(()=>{var e;if(null===(e=Be.current)||void 0===e?void 0:e.isTransforming()){return}const t=Be.current;if(!t||!t.nodes().length){return void He(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,c=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let c;c=0===i||180===i?s:l;const d=Math.sin(t)*(c+n),m=-Math.cos(t)*(c+n),u=d*Math.cos(a)-m*Math.sin(a),h=d*Math.sin(a)+m*Math.cos(a);return{x:o+u,y:r+h}},d=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(d(c(0))){return 0}for(const m of[180,270,90]){if(d(c(m))){return m}}return 0}(n,{top:(null==Z?void 0:Z.top)||0,bottom:h-((null==Z?void 0:Z.bottom)||0),left:(null==Z?void 0:Z.left)||0,right:d-((null==Z?void 0:Z.right)||0)},ee.rotateAnchorOffset,t.rotation());He(i)},[Z,d,h]);o.useEffect(()=>{var e;null===(e=Be.current)||void 0===e||e.update(),qe(),et()},[i.scale,et]),o.useEffect(()=>{et()},[i.selectedShapes,et]);const tt=s(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),nt=o.useRef(!1),it=e=>{const t=Ge.current;if(!t||i.role===Y.VIEWER||i.activePage!==l||i.isPlaying||"button"in e.evt&&0!==e.evt.button||1!==t.getPointersPositions().length||!e.target.findAncestor(".elements-container")||!e.target.findAncestor(".element",!0)||!i.selectedShapes.length||he(i)){return}const n=t.getPointerPosition();if(!n){return}const o=$e();if(o.some(t=>t===e.target||t.isAncestorOf(e.target))){return}const r=o.find(e=>!!(e.draggable()&&e.isVisible()&&e.isListening())&&(e instanceof k.Shape?[e]:e instanceof k.Container?e.find("Shape"):[]).some(e=>e.intersects(n)));if(r){for(const[t,n]of k.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||k.DD._dragElements.delete(t)}r._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&r.preventDefault()&&e.evt.preventDefault()}},ot=a(e=>{var t,n,o,r,l,s,a;if(i.role===Y.VIEWER){return}if(nt.current=!1,i.activeTool&&"crop"!==i.activeTool.name){return}const c=e.target.findAncestor(".elements-container"),d=e.target.findAncestor("Transformer"),m=e.target.findAncestor(".page-abs-container");if(c||d||m){return}const u=null===(t=e.target.getStage())||void 0===t?void 0:t.getPointerPosition();u&&(u.x-=null!==(o=null===(n=e.target.getStage())||void 0===n?void 0:n.x())&&void 0!==o?o:0,u.y-=null!==(l=null===(r=e.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,tt.visible=!0,tt.x1=u.x,tt.y1=u.y,tt.x2=u.x,tt.y2=u.y,(null!==(a=null===(s=e.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(tt.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),l=null==i?void 0:i.getBoundingClientRect();if(!o||!l){return}const s=r(l.left-o.left-100,0,Math.max(0,o.width-e.current.width())),a=r(l.top-o.top-100,0,Math.max(0,o.height-e.current.height()));e.current.position({x:-s,y:-a}),e.current.container().style.transform=`translate(${s}px, ${a}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:Ge,containerRef:Le,viewportSize:O}),o.useEffect(()=>{const e=a(e=>{var t,n,i,o,r,l;if(!tt.visible){return}null===(t=Ge.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Ge.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Ge.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Ge.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:tt.x2,y:tt.y2},tt.x2=s.x,tt.y2=s.y}),t=a(()=>{if(!tt.visible){return}if(!Ge.current){return}const e=Ge.current.findOne(".selection"),t=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(t.width&&t.height){const e=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n=[];Ge.current.find(".element").forEach(t=>{var o;const r=i.getElementById(t.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=t.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const c=L(r.a).map(e=>a.point(e));F(e,c)&&n.push(r.top.id)});const o=[...new Set(n)];nt.current=!0,i.selectElements(o)}tt.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",t,{capture:!0}),window.addEventListener("touchend",t,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t)}},[]);const rt=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=V(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:l.computedWidth,height:l.computedHeight,rotation:0},o=G(n),r=[];t.minX>o.maxX&&r.push({distance:t.minX-o.maxX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),t.maxX<o.minX&&r.push({distance:o.minX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),t.minY>o.maxY&&r.push({box1:t,box2:o,distance:t.minY-o.maxY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),t.maxY<o.minY&&r.push({box1:t,box2:o,distance:o.minY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=t.minX>=o.minX&&t.maxX<=o.maxX&&t.minY>=o.minY&&t.maxY<=o.maxY;if(s&&(r.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),r.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),r.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),r.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===r.length&&!s){const e=t.minX<o.maxX&&t.maxX>o.minX,n=t.minY<o.maxY&&t.maxY>o.minY;if(e&&n){const e=(Math.max(t.minY,o.minY)+Math.min(t.maxY,o.maxY))/2,n=(Math.max(t.minX,o.minX)+Math.min(t.maxX,o.maxX))/2;t.minX<o.minX?r.push({distance:o.minX-t.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):r.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),t.maxX>o.maxX?r.push({distance:t.maxX-o.maxX,box1:t,box2:o,points:[{x:o.maxX,y:e},{x:t.maxX,y:e},{x:o.maxX,y:e}]}):r.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),t.minY<o.minY?r.push({box1:t,box2:o,distance:o.minY-t.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}):r.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}),t.maxY>o.maxY?r.push({box1:t,box2:o,distance:t.maxY-o.maxY,points:[{x:n,y:o.maxY},{x:n,y:t.maxY},{x:n,y:o.maxY}]}):r.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:n,y:t.maxY},{x:n,y:o.maxY},{x:n,y:o.maxY}]})}}_e(e=>JSON.stringify(e)===JSON.stringify(r)?e:r)},[i,l]),lt=o.useCallback(()=>{i.distanceGuidesVisible&&i.selectedElements[0]?rt():_e(null)},[i,rt]);o.useEffect(lt,[i.distanceGuidesVisible,lt]);const st=i.distanceGuidesVisible||!!ze;o.useEffect(()=>{if(st){return le(l,()=>i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|"),lt)}},[st,lt]);const at=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Le.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{at.current=!0,clearTimeout(t),t=setTimeout(()=>{at.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Ge.current;if(!e){return}const t=e.container(),n=new Map,o=e=>{var t,i;n.has(e.target)||[e.target,...null!==(i=null===(t=Be.current)||void 0===t?void 0:t.nodes())&&void 0!==i?i:[]].forEach(e=>{n.has(e)||n.set(e,{x:e.x(),y:e.y()})})},r=e=>{e.target===Be.current?n.clear():n.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{e.touches.length>=2&&c(()=>{var e,t;const o=new Map(n);(null===(e=Be.current)||void 0===e?void 0:e.isDragging())&&Be.current.stopDrag(),null===(t=Be.current)||void 0===t||t.nodes().forEach(e=>{var t;const n=o.get(e);e.isDragging()&&e.stopDrag(),n&&(e.setAttrs(n),null===(t=i.getElementById(e.id()))||void 0===t||t.set({x:n.x,y:n.y}))})})};return t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),t.removeEventListener("touchstart",l),t.removeEventListener("touchmove",l)}},[i]);const ct=e=>{if(i.role===Y.VIEWER){return}if(i.activePage!==l&&l.select(),at.current){return}if(nt.current){return}const t=e.evt.shiftKey,n=e.evt.ctrlKey||e.evt.metaKey,o=t||n,r=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),c=e.target.findAncestor(".page-container",!0),d=!(o||r||a||s||c||tt.visible);if(i.activeTool&&"crop"!==i.activeTool.name&&!r&&!a){return}if(d){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Ge.current,t=null==e?void 0:e.getPointerPosition();if(!e||!t){return}const n=e.getAllIntersections(t),o=new Set,r=[];for(const s of[...n].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const t=i.getElementById(e.id()),n=null==t?void 0:t.top;n&&(o.has(n.id)||(o.add(n.id),r.push(n.id)))}if(0===r.length){return}let l;if(1===i.selectedElementsIds.length){const e=i.selectedElementsIds[0],t=r.indexOf(e);l=-1===t?r[0]:r[(t+1)%r.length]}else{l=r[0]}return i.selectElements([l]),void i.selectPages([])}const m=e.target.findAncestor(".element-container",!0),u=(null==m?void 0:m.findOne(".element"))||e.target.findAncestor(".element",!0),h=i.getElementById(null==u?void 0:u.id());h&&"pendingEdit"in h&&h._setImageEditError(null);const g=null==h?void 0:h.top;let f;if("group"===P){f=null==g?void 0:g.id}else if(g){const e=i.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===g.id});f=e?null==h?void 0:h.id:null==g?void 0:g.id}else{f=void 0}const p=null==h?void 0:h.id;if(p&&i.selectedElementsIds.indexOf(p)>=0&&!t){return}const x=!!f&&i.selectedElementsIds.indexOf(f)>=0,v=e.target.findAncestor(".page-container",!0);if(f&&t&&!x){const e=re(i.selectedElementsIds.concat([f]),e=>oe(i,e));i.selectElements(e),i.selectPages([])}else{f&&t&&x?i.selectElements(i.selectedElementsIds.filter(e=>e!==f)):!f||t||x?f&&!t&&x||(v?(t||i.selectElements([]),i.selectPages([l.id])):i.selectPages([])):(i.selectElements([f]),i.selectPages([]))}};I(Be,i);const dt=i.activePage===l,mt=i._selectedPagesIds.includes(l.id),ut=null==y?void 0:y.PageControls,ht=null==y?void 0:y.Tooltip,gt=null==y?void 0:y.ContextMenu,ft=1/i.scale,pt=0/i.scale;return n("div",{ref:Le,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===Y.VIEWER){return}if(!Ge.current){return}Ge.current.setPointersPositions(e);const t=Ge.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Ge.current.getPointerPosition(),r=Ge.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(r.reverse())].map(e=>i.getElementById(e.id())).filter(e=>!!e),a=s[0];je&&n&&(je(n,a,{elements:s,page:l}),je=null)},style:{position:"relative",width:d+"px",height:h+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(dt?" active-page":""),children:[t(ae,{ref:Ge,eventBatchFunc:c,width:Math.min(d,O.width+200),height:Math.min(O.height+200,h),onClick:ct,onTap:ct,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===Y.VIEWER){return}const t=e.target.findAncestor(".element",!0),n=i.getElementById(null==t?void 0:t.id()),o=null==n?void 0:n.top,r=null==o?void 0:o.id;if(!r){return i.selectElements([]),void Je.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),Je.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{it(e),ot(e)},onTouchStart:it,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(ze&&_e(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();rt(n)},onDragStart:e=>{var t;const n=e.target.getStage();if(n&&n.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const n=i.getElementById(null==o?void 0:o.id()),r=null==n?void 0:n.top,l=null==r?void 0:r.id;if(!(n&&i.selectedElementsIds.indexOf(n.id)>=0||l&&i.selectedElementsIds.indexOf(l)>=0)&&l){i.selectElements([l]);const n=$e();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=Be.current)||void 0===t||t.startDrag(e),j()}}ze&&_e(null)},onDragMove:e=>{const t=Be.current;t&&e.target===t&&t.nodes().forEach(e=>{const t=i.getElementById(e.id());!t||t.x===e.x()&&t.y===e.y()||t.set({x:e.x(),y:e.y()})})},pageId:l.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(f,{children:[t(xe,{width:d,height:h,fill:J.workspaceBackgroundColor}),t(u,{x:Ie,y:Pe,scaleX:i.scale,scaleY:i.scale,name:"page-container",children:n(u,{name:"page-container-2",children:[t(u,{x:be.left,y:be.top,children:t(ye,Object.assign({},Te,De,{transparencyBackgroundColor:J.transparencyBackgroundColor}))}),n(u,{isolated:l.hasBlendMode,children:[t(u,{name:"page-background-group",x:be.left,y:be.top,clip:De,children:t(we,Object.assign({},Te))}),n(u,{x:be.left,y:be.top,name:"elements-container",listening:!i.isPlaying&&i.role!==Y.VIEWER,children:[t(x,{name:"elements-area",width:l.computedWidth,height:l.computedHeight,listening:!1}),t(Me,{elements:l.children,store:i}),t(Ae,{page:l})]})]}),t(v,{name:"bleed",fill:J.bleedColor,listening:!1,visible:i.bleedVisible&&(be.top>0||be.right>0||be.bottom>0||be.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:r}=ve,s=l.computedWidth,a=l.computedHeight,c=e._context;c.beginPath(),c.rect(0,0,r+s+i,n+a+o),c.rect(r,n,s,a),c.fillStyle=t.fill(),c.fill("evenodd")}}),B()===Oe&&t(Re,{name:"hit-detection",x:-ft/2-pt,y:-ft/2-pt,width:Se+ft+2*pt,height:ke+ft+2*pt})]})}),t(p,{name:"workspace-background",points:[0,0,d,0,d,h,0,h,0,0,Ie,Pe,Ie,h-Pe,d-Ie,h-Pe,d-Ie,Pe,Ie,Pe],listening:!1,closed:!0,fill:J.workspaceBackgroundColor}),t(u,{x:Ie,y:Pe,scaleX:i.scale,scaleY:i.scale,children:t(x,{name:"page-highlight",hideInExport:!0,x:-ft/2-pt,y:-ft/2-pt,width:Se+ft+2*pt,height:ke+ft+2*pt,stroke:mt?J.activePageBorderColor:J.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(u,{x:Ie+be.left*i.scale,y:Pe+be.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(S,{ref:Be,name:H,rotateAnchorAngle:Ze,onDragStart:e=>{var t;const n=e.target.getStage();n&&n.getPointersPositions().length>=2?e.target.stopDrag():((null===(t=e.evt)||void 0===t?void 0:t.altKey)&&A&&D(i.selectedElements,l,i),Fe.current||(Fe.current=!0,i.history.startTransaction()))},onDragEnd:()=>{Fe.current&&(i.history.endTransaction(),Fe.current=!1),et()},onTransformStart:()=>{Ue.setTransforming(!0),i.history.startTransaction(),We.current=new Map(Ne.map(e=>[e.id,{width:e.width,height:e.height}])),_e(null)},boundBoxFunc:(e,t)=>{var n,o,r,l;const s=null!==(o=null===(n=ee.boundBoxFunc)||void 0===n?void 0:n.call(ee,e,t))&&void 0!==o?o:t,a=Math.abs(s.width)<1||Math.abs(s.height)<1,c=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!c){return e}const d=i.selectedElements;if(1===d.length&&"table"===(null===(r=d[0])||void 0===r?void 0:r.type)){const t=d[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,c=Object.assign({},s);return l<t.minWidth&&(c.width=e.width),a<t.minHeight&&(c.height=e.height),$(c,s,e)}}return Ke&&Ne.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,c=!U(n),d=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,d="x"===e?s:a,m=K(t,e,c,r);return r>=m&&l*d<m}),m=Object.assign({},t),u=t.width*e.width<0,h=t.height*e.height<0,g=u||d("x"),f=h||d("y"),p=f||!c&&g;return(g||!c&&f)&&(m.width=e.width),p&&(m.height=e.height),$(m,t,e)})(e,s,(null===(l=Be.current)||void 0===l?void 0:l.getActiveAnchor())||"",Ne,We.current):s},onTransform:e=>{const t=Be.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{qe()},0)},onTransformEnd:e=>{Ue.setTransforming(!1),Ue.setLabel({}),i.history.endTransaction(),We.current=null,et()},visible:!i.isPlaying}),t(Ye,{store:i,gesture:Ue,transformerStyle:ee,onChange:Qe}),ze&&ze.map(({points:e,distance:o,box1:r,box2:l},s)=>n(u,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(x,Object.assign({},r,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(x,Object.assign({},l,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(p,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(p,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(g,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/i.scale,scaleY:1/i.scale,children:[t(w,{cornerRadius:5,fill:J.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(E,{align:"center",verticalAlign:"middle",fill:J.distanceGuideStyle.labelTextFill,padding:5,text:_({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),l._rendering&&n(u,{children:[t(x,{width:Se,height:ke,fill:"rgba(255,255,255,0.9)"}),t(E,{text:"Rendering...",fontSize:60,width:Se,height:ke,align:"center",verticalAlign:"middle"})]}),ht&&t(ht,{components:y,store:i,page:l,stageRef:Ge,tooltipSafeArea:z}),gt&&t(ie,{children:t(gt,Object.assign({components:y,store:i},Je.props))}),t(R,{store:i,pageId:l.id})]}),t(M,{store:i,page:l,width:d,height:h,scale:i.scale,xPadding:Ie,yPadding:Pe,bleedLeft:be.left,bleedTop:be.top}),t(Xe,{gesture:Ue,store:i}),t(Ee,{selection:tt}),C()>0&&n(u,{hideInExport:!0,children:[t(Ce,{name:"cache-bounds",x:d-(1===C()?250:210),y:h-(1===C()?95:45)}),t(Ce,{name:"cache-bounds-t",x:10,y:10})]}),W()&&t(E,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:d-170,y:h-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(u,{name:"line-guides"})]})}),Ve&&ut&&t(ut,{store:i,page:l,xPadding:Ie,yPadding:Pe,layout:T})]})});
|
|
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{Fragment as t,jsx as n,jsxs as i}from"react/jsx-runtime";import o from"react";import{clamp as r}from"../lib/utils.js";import{observer as l,useLocalObservable as s}from"mobx-react-lite";import{action as a,runInAction as c}from"mobx";import{isAlive as d}from"mobx-state-tree";import{ZERO_BLEED as m}from"@polotno/schema";import{Group as u,Image as h,Label as g,Layer as f,Line as p,Rect as x,Shape as v,Stage as b,KonvaRenderer as y,Tag as w,Text as E,Transformer as S}from"react-konva";import{useWorkspaceStyle as X}from"./workspace-style.js";import{ROLES as Y}from"../model/store.js";import k from"konva";import A from"./element.js";import{DrawingLayer as M}from"./drawing-layer.js";import{ensureDragOrder as j,useSnap as I}from"./use-transformer-snap.js";import{useImageLoader as P,useSizedImage as O}from"./image-element.js";import{FadeOverlay as R}from"./fade-overlay.js";import{getCrop as T}from"../utils/crop.js";import{cloneBehind as D}from"../utils/duplicate.js";import{___ as B,____ as C,isCreditVisible as W}from"../utils/validate-key.js";import{getClientRect as G,getCorners as L,getTotalClientRect as V,polygonsIntersect as F}from"../utils/math.js";import{pxToUnitRounded as z,pxToUnitString as _}from"../utils/unit.js";import{isCornerAnchor as U,isRotateAnchor as Z,MAIN_TRANSFORMER_NAME as H}from"../utils/px.js";import{canStretchAxis as J,isAxisAligned as N,leafMinSize as K}from"../utils/selection-transform.js";import{restoreHeldPoint as $}from"./transform-box.js";import{flags as Q}from"../utils/flags.js";import{textOverflowOf as q}from"../utils/text-sizing.js";import{useColor as ee}from"./use-color.js";import{isGradient as te}from"@polotno/core/gradient";import{toDisplayColor as ne}from"@polotno/core/color";import{Html as ie}from"react-konva-utils";import{getParentGroupId as oe,withoutDescendants as re}from"../utils/selection.js";import{nodeReaction as le}from"../utils/mobx.js";import{useEvent as se}from"../hooks/use-event.js";const ae=o.version.startsWith("18.")?o.forwardRef((e,t)=>(o.useLayoutEffect(()=>{y.flushSync()}),n(b,Object.assign({},e,{ref:t})))):b,ce={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},de=e=>{if(!e.length){return null}const t=N(e[0].rotation)?0:e[0].rotation;return e.every(e=>N(e.rotation-t))?t:null},me=e=>e.selectedShapes.filter(t=>{var n;return(null===(n=e.activeTool)||void 0===n?void 0:n.elementId)!==t.id&&!t.pendingEdit}),ue=e=>e.selectedShapes.some(e=>!e.resizable),he=e=>e.selectedShapes.some(e=>!e.draggable),ge=e=>{var t;return 1!==e.selectedElements.length||"group"===(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)},fe=e=>{var t;const n=me(e),i=ge(e),o=null!==(t=de(n))&&void 0!==t?t:0,r=e=>i&&n.length>0&&n.every(t=>J(t,e,o));return{boxRotation:o,canStretchX:r("x"),canStretchY:r("y")}},pe={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},lottie:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){pe[e]=pe[e]||t,Object.assign(pe[e],t)}const xe=e=>n(x,Object.assign({},e,{preventDefault:!1})),ve=t=>{var{url:i}=t,o=e(t,["url"]);const[r,l]=O(i),s=r?T(r,{width:o.width,height:o.height},"center-middle"):{};return P(l,i,"page background"),n(h,Object.assign({image:r},o,s))},be=e=>{const t=ee({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return n(x,Object.assign({},e,t))},ye=t=>{var{background:i,transparencyBackgroundColor:r}=t,l=e(t,["background","transparencyBackgroundColor"]);const s=o.useMemo(()=>{if(te(i)){return!0}const e=k.Util.colorToRGBA(i);return!e||e.a<1},[i]),a=o.useMemo(()=>{if(!s||r){return}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[s,r]);return s?n(x,r?Object.assign({fill:r},l,{hideInExport:!0}):Object.assign({fillPatternImage:a},l,{opacity:.1,hideInExport:!0})):null},we=t=>{var{background:i}=t,r=e(t,["background"]);return o.useMemo(()=>!!k.Util.colorToRGBA(i)||te(i),[i])?n(be,Object.assign({fill:i},r)):n(ve,Object.assign({url:i},r))},Ee=l(({selection:e})=>{const{selectionRectStyle:t}=X();return e.visible?n(x,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth}):null});function Se(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const Xe=l(({gesture:e,store:o})=>{const{transformLabelStyle:r}=X(),{x:l,y:s,width:a,height:c,rotation:d,anchor:m}=e.label;if(void 0===l||void 0===s||void 0===a||void 0===c||void 0===d||void 0===m){return null}const u=G({x:l,y:s,width:a,height:c,rotation:k.Util.radToDeg(d)}),h=null!==m&&Z(m),f=(c/2+70)*Math.cos(d-Math.PI/2),p=(c/2+70)*Math.sin(d-Math.PI/2),x=z({unit:o.unit,dpi:o.dpi,px:a/o.scale,precious:"px"===o.unit?0:1})+" x "+z({unit:o.unit,dpi:o.dpi,px:c/o.scale,precious:"px"===o.unit?0:1})+("px"===o.unit?"":" "+o.unit);return i(t,{children:[i(g,{x:(u.minX+u.maxX)/2+f,y:(u.minY+u.maxY)/2+p,offsetX:14,offsetY:14,visible:h,children:[n(w,{cornerRadius:5,fill:r.fill}),n(E,{align:"center",verticalAlign:"middle",fill:r.textFill,padding:8,text:Se(d).toString()+"°"})]}),i(g,{x:(u.minX+u.maxX)/2,y:u.maxY+20,visible:!h,children:[n(w,{cornerRadius:5,fill:r.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),n(E,{align:"center",verticalAlign:"middle",fill:r.textFill,padding:8,text:x})]})]})}),Ye=l(({store:e,gesture:t,transformerStyle:n,onChange:i})=>{var r;const l=e.selectedElements.some(e=>e.curveEnabled),s=e.selectedElements.some(e=>!e.visible),a=JSON.stringify(me(e).map(e=>e.id)),c=!ge(e)&&e.selectedElements[0].keepRatio,d=!ge(e)&&"text"===(null===(r=e.selectedElements[0])||void 0===r?void 0:r.type)&&"fit"===q(e.selectedElements[0]),m=t.transforming?null:fe(e);return o.useLayoutEffect(()=>{i()},[e.selectedShapes,a,ue(e),s,he(e),l,c,d,t.transforming,null==m?void 0:m.canStretchX,null==m?void 0:m.canStretchY,null==m?void 0:m.boxRotation,n]),null}),ke=()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")},Ae=l(({page:e})=>{const t=e._exportingOrRendering||e._forceMount;return o.useEffect(()=>{if(t&&d(e)){return e.set({_exportRendered:!0}),()=>{d(e)&&e.set({_exportRendered:!1})}}},[e,t]),null}),Me=l(({elements:e,store:t})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return n(o.Fragment,{children:r.map(e=>n(A,{store:t,element:e,onClick:ke},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let je=null;export const registerNextDomDrop=e=>{je=e};const Ie=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),Pe=atob("I2MwMzkyYg=="),Oe=atob("djAuOS4y"),Re=e=>n(t,{children:i(g,{fill:Pe,height:200,children:[n(w,{fill:Pe}),n(E,Object.assign({},e,{fill:"white",text:Ie,height:void 0,padding:10,fontSize:20}))]})}),Te=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),De=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),Be=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),Ce=e=>{const t=1===C(),o=t?De:Te,r=t?230:195;return i(u,Object.assign({},e,{listening:!1,children:[n(x,{fill:Pe,width:r,height:24,cornerRadius:2}),n(E,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),t&&n(E,{text:Be,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default l(({store:t,page:l,width:d,height:h,pageControlsEnabled:b,components:y,altCloneEnabled:A,groupSelectionMode:P="drill",viewportSize:O,layout:T="vertical",tooltipSafeArea:z,transformerSafeArea:Z})=>{const J=X(),ee=J.transformerStyle,te=ce,ve=l.computedBleed,be=t.bleedVisible?ve:m,Se=l.computedWidth+be.left+be.right,ke=l.computedHeight+be.top+be.bottom,Ie=(d-Se*t.scale)/2,Pe=(h-ke*t.scale)/2,Te={x:-ve.left,y:-ve.top,width:l.computedWidth+ve.left+ve.right,height:l.computedHeight+ve.top+ve.bottom,background:ne(l.background),name:"page-background",preventDefault:!1},De={x:-be.left,y:-be.top,width:Se,height:ke},Be=o.useRef(null),We=o.useRef(null),Ge=o.useRef(null),Le=o.useRef(null),Ve=null==b||b,Fe=o.useRef(!1),[ze,_e]=o.useState(null),Ue=s(()=>({transforming:!1,label:{},setLabel(e){this.label=e},setTransforming(e){this.transforming=e}})),[Ze,He]=o.useState(0),Je=useContextMenu({store:t}),Ne=me(t),Ke=ge(t),$e=()=>{var n,i,o;const r=Be.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=me(t),a=new Set(s.map(e=>e.id)),c=new Map;a.size&&l.find(e=>{const t=e.id();return a.has(t)&&!c.has(t)&&c.set(t,e),!1});const d=s.map(e=>c.get(e.id)).filter(e=>!!e),m=1===t.selectedElements.length,u=m&&(null===(n=t.selectedElements[0])||void 0===n?void 0:n.type)||"many",h=pe[u],g=Object.assign(Object.assign({},te),h||{});h&&("svg"!==u&&"image"!==u&&"gif"!==u&&"lottie"!==u||t.selectedElements[0].keepRatio||(g.enabledAnchors=te.enabledAnchors),"text"!==u||!Q.textVerticalResizeEnabled&&"fit"!==q(t.selectedElements[0])||(g.enabledAnchors=null===(i=pe.text.enabledAnchors)||void 0===i?void 0:i.concat(["bottom-center","top-center"])),"text"===u&&m&&t.selectedElements[0].curveEnabled&&(g.enabledAnchors=pe.many.enabledAnchors));const f=fe(t);(f.canStretchX||f.canStretchY)&&(g.enabledAnchors=[...g.enabledAnchors||[],...f.canStretchX?["middle-left","middle-right"]:[],...f.canStretchY?["top-center","bottom-center"]:[]]);const{boundBoxFunc:p}=ee,x=e(ee,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},g),x),{name:H})),ue(t)&&r.enabledAnchors([]),he(t)&&r.rotateEnabled(!1);const v=r.nodes();if(v.length===d.length&&d.every((e,t)=>v[t]===e)||r.nodes(d),ge(t)&&d.length){const e=de(s);null===e||N(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),d},Qe=se(()=>{var e;if(null===(e=Be.current)||void 0===e?void 0:e.isTransforming()){return}const t=$e();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),j())}),qe=()=>{var e,t;const n=Be.current;if(!n){return}if(!n.isTransforming()){return void Ue.setLabel({})}if(!n.nodes().length){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ue.setLabel({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},et=o.useCallback(()=>{var e;if(null===(e=Be.current)||void 0===e?void 0:e.isTransforming()){return}const t=Be.current;if(!t||!t.nodes().length){return void He(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,c=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let c;c=0===i||180===i?s:l;const d=Math.sin(t)*(c+n),m=-Math.cos(t)*(c+n),u=d*Math.cos(a)-m*Math.sin(a),h=d*Math.sin(a)+m*Math.cos(a);return{x:o+u,y:r+h}},d=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(d(c(0))){return 0}for(const m of[180,270,90]){if(d(c(m))){return m}}return 0}(n,{top:(null==Z?void 0:Z.top)||0,bottom:h-((null==Z?void 0:Z.bottom)||0),left:(null==Z?void 0:Z.left)||0,right:d-((null==Z?void 0:Z.right)||0)},ee.rotateAnchorOffset,t.rotation());He(i)},[Z,d,h]);o.useEffect(()=>{var e;null===(e=Be.current)||void 0===e||e.update(),qe(),et()},[t.scale,et]),o.useEffect(()=>{et()},[t.selectedShapes,et]);const tt=s(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),nt=o.useRef(!1),it=e=>{const n=Ge.current;if(!n||t.role===Y.VIEWER||t.activePage!==l||t.isPlaying||"button"in e.evt&&0!==e.evt.button||1!==n.getPointersPositions().length||!e.target.findAncestor(".elements-container")||!e.target.findAncestor(".element",!0)||!t.selectedShapes.length||he(t)){return}const i=n.getPointerPosition();if(!i){return}const o=$e();if(o.some(t=>t===e.target||t.isAncestorOf(e.target))){return}const r=o.find(e=>!!(e.draggable()&&e.isVisible()&&e.isListening())&&(e instanceof k.Shape?[e]:e instanceof k.Container?e.find("Shape"):[]).some(e=>e.intersects(i)));if(r){for(const[t,n]of k.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||k.DD._dragElements.delete(t)}r._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&r.preventDefault()&&e.evt.preventDefault()}},ot=a(e=>{var n,i,o,r,l,s,a;if(t.role===Y.VIEWER){return}if(nt.current=!1,t.activeTool&&"crop"!==t.activeTool.name){return}const c=e.target.findAncestor(".elements-container"),d=e.target.findAncestor("Transformer"),m=e.target.findAncestor(".page-abs-container");if(c||d||m){return}const u=null===(n=e.target.getStage())||void 0===n?void 0:n.getPointerPosition();u&&(u.x-=null!==(l=null===(i=e.target.getStage())||void 0===i?void 0:i.x())&&void 0!==l?l:0,u.y-=null!==(s=null===(o=e.target.getStage())||void 0===o?void 0:o.y())&&void 0!==s?s:0,tt.visible=!0,tt.x1=u.x,tt.y1=u.y,tt.x2=u.x,tt.y2=u.y,(null!==(a=null===(r=e.target.getStage())||void 0===r?void 0:r.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(tt.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),l=null==i?void 0:i.getBoundingClientRect();if(!o||!l){return}const s=r(l.left-o.left-100,0,Math.max(0,o.width-e.current.width())),a=r(l.top-o.top-100,0,Math.max(0,o.height-e.current.height()));e.current.position({x:-s,y:-a}),e.current.container().style.transform=`translate(${s}px, ${a}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:Ge,containerRef:Le,viewportSize:O}),o.useEffect(()=>{const e=a(e=>{var t,n,i,o,r,l;if(!tt.visible){return}null===(t=Ge.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Ge.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(r=null===(i=Ge.current)||void 0===i?void 0:i.x())&&void 0!==r?r:0,s.y-=null!==(l=null===(o=Ge.current)||void 0===o?void 0:o.y())&&void 0!==l?l:0):s={x:tt.x2,y:tt.y2},tt.x2=s.x,tt.y2=s.y}),n=a(()=>{if(!tt.visible){return}if(!Ge.current){return}const e=Ge.current.findOne(".selection"),n=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){const e=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x+n.width,y:n.y+n.height},{x:n.x,y:n.y+n.height}],i=[];Ge.current.find(".element").forEach(n=>{var o;const r=t.getElementById(n.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=n.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const c=L(r.a).map(e=>a.point(e));F(e,c)&&i.push(r.top.id)});const o=[...new Set(i)];nt.current=!0,t.selectElements(o)}tt.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",n,{capture:!0}),window.addEventListener("touchend",n,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);const rt=o.useCallback(e=>{if(!t.selectedElements[0]){return}if(e&&t.selectedElementsIds.includes(e)){return}const n=V(t.selectedShapes),i=e?t.getElementById(e):{x:0,y:0,width:l.computedWidth,height:l.computedHeight,rotation:0},o=G(i),r=[];n.minX>o.maxX&&r.push({distance:n.minX-o.maxX,box1:n,box2:o,points:[{x:n.minX,y:n.minY+n.height/2},{x:o.maxX,y:n.minY+n.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),n.maxX<o.minX&&r.push({distance:o.minX-n.maxX,box1:n,box2:o,points:[{x:n.maxX,y:n.minY+n.height/2},{x:o.minX,y:n.minY+n.height/2},{x:o.minX,y:o.minY+o.height/2}]}),n.minY>o.maxY&&r.push({box1:n,box2:o,distance:n.minY-o.maxY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),n.maxY<o.minY&&r.push({box1:n,box2:o,distance:o.minY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=n.minX>=o.minX&&n.maxX<=o.maxX&&n.minY>=o.minY&&n.maxY<=o.maxY;if(s&&(r.push({distance:n.minX-o.minX,box1:n,box2:o,points:[{x:n.minX,y:n.minY+n.height/2},{x:o.minX,y:n.minY+n.height/2},{x:o.minX,y:o.minY+o.height/2}]}),r.push({distance:o.maxX-n.maxX,box1:n,box2:o,points:[{x:n.maxX,y:n.minY+n.height/2},{x:o.maxX,y:n.minY+n.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),r.push({box1:n,box2:o,distance:n.minY-o.minY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),r.push({box1:n,box2:o,distance:o.maxY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===r.length&&!s){const e=n.minX<o.maxX&&n.maxX>o.minX,t=n.minY<o.maxY&&n.maxY>o.minY;if(e&&t){const e=(Math.max(n.minY,o.minY)+Math.min(n.maxY,o.maxY))/2,t=(Math.max(n.minX,o.minX)+Math.min(n.maxX,o.maxX))/2;n.minX<o.minX?r.push({distance:o.minX-n.minX,box1:n,box2:o,points:[{x:n.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):r.push({distance:n.minX-o.minX,box1:n,box2:o,points:[{x:n.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),n.maxX>o.maxX?r.push({distance:n.maxX-o.maxX,box1:n,box2:o,points:[{x:o.maxX,y:e},{x:n.maxX,y:e},{x:o.maxX,y:e}]}):r.push({distance:o.maxX-n.maxX,box1:n,box2:o,points:[{x:n.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),n.minY<o.minY?r.push({box1:n,box2:o,distance:o.minY-n.minY,points:[{x:t,y:n.minY},{x:t,y:o.minY},{x:t,y:o.minY}]}):r.push({box1:n,box2:o,distance:n.minY-o.minY,points:[{x:t,y:n.minY},{x:t,y:o.minY},{x:t,y:o.minY}]}),n.maxY>o.maxY?r.push({box1:n,box2:o,distance:n.maxY-o.maxY,points:[{x:t,y:o.maxY},{x:t,y:n.maxY},{x:t,y:o.maxY}]}):r.push({box1:n,box2:o,distance:o.maxY-n.maxY,points:[{x:t,y:n.maxY},{x:t,y:o.maxY},{x:t,y:o.maxY}]})}}_e(e=>JSON.stringify(e)===JSON.stringify(r)?e:r)},[t,l]),lt=o.useCallback(()=>{t.distanceGuidesVisible&&t.selectedElements[0]?rt():_e(null)},[t,rt]);o.useEffect(lt,[t.distanceGuidesVisible,lt]);const st=t.distanceGuidesVisible||!!ze;o.useEffect(()=>{if(st){return le(l,()=>t.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|"),lt)}},[st,lt]);const at=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Le.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{at.current=!0,clearTimeout(t),t=setTimeout(()=>{at.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Ge.current;if(!e){return}const n=e.container(),i=new Map,o=e=>{var t,n;i.has(e.target)||[e.target,...null!==(n=null===(t=Be.current)||void 0===t?void 0:t.nodes())&&void 0!==n?n:[]].forEach(e=>{i.has(e)||i.set(e,{x:e.x(),y:e.y()})})},r=e=>{e.target===Be.current?i.clear():i.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{e.touches.length>=2&&c(()=>{var e,n;const o=new Map(i);(null===(e=Be.current)||void 0===e?void 0:e.isDragging())&&Be.current.stopDrag(),null===(n=Be.current)||void 0===n||n.nodes().forEach(e=>{var n;const i=o.get(e);e.isDragging()&&e.stopDrag(),i&&(e.setAttrs(i),null===(n=t.getElementById(e.id()))||void 0===n||n.set({x:i.x,y:i.y}))})})};return n.addEventListener("touchstart",l,{passive:!0}),n.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),n.removeEventListener("touchstart",l),n.removeEventListener("touchmove",l)}},[t]);const ct=e=>{if(t.role===Y.VIEWER){return}if(t.activePage!==l&&l.select(),at.current){return}if(nt.current){return}const n=e.evt.shiftKey,i=e.evt.ctrlKey||e.evt.metaKey,o=n||i,r=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),c=e.target.findAncestor(".page-container",!0),d=!(o||r||a||s||c||tt.visible);if(t.activeTool&&"crop"!==t.activeTool.name&&!r&&!a){return}if(d){return t.selectElements([]),void t.selectPages([])}if(i&&!n){const e=Ge.current,n=null==e?void 0:e.getPointerPosition();if(!e||!n){return}const i=e.getAllIntersections(n),o=new Set,r=[];for(const s of[...i].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const n=t.getElementById(e.id()),i=null==n?void 0:n.top;i&&(o.has(i.id)||(o.add(i.id),r.push(i.id)))}if(0===r.length){return}let l;if(1===t.selectedElementsIds.length){const e=t.selectedElementsIds[0],n=r.indexOf(e);l=-1===n?r[0]:r[(n+1)%r.length]}else{l=r[0]}return t.selectElements([l]),void t.selectPages([])}const m=e.target.findAncestor(".element-container",!0),u=(null==m?void 0:m.findOne(".element"))||e.target.findAncestor(".element",!0),h=t.getElementById(null==u?void 0:u.id());h&&"pendingEdit"in h&&h._setImageEditError(null);const g=null==h?void 0:h.top;let f;if("group"===P){f=null==g?void 0:g.id}else if(g){const e=t.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===g.id});f=e?null==h?void 0:h.id:null==g?void 0:g.id}else{f=void 0}const p=null==h?void 0:h.id;if(p&&t.selectedElementsIds.indexOf(p)>=0&&!n){return}const x=!!f&&t.selectedElementsIds.indexOf(f)>=0,v=e.target.findAncestor(".page-container",!0);if(f&&n&&!x){const e=re(t.selectedElementsIds.concat([f]),e=>oe(t,e));t.selectElements(e),t.selectPages([])}else{f&&n&&x?t.selectElements(t.selectedElementsIds.filter(e=>e!==f)):!f||n||x?f&&!n&&x||(v?(n||t.selectElements([]),t.selectPages([l.id])):t.selectPages([])):(t.selectElements([f]),t.selectPages([]))}};I(Be,t);const dt=t.activePage===l,mt=t._selectedPagesIds.includes(l.id),ut=null==y?void 0:y.PageControls,ht=null==y?void 0:y.Tooltip,gt=null==y?void 0:y.ContextMenu,ft=1/t.scale,pt=0/t.scale;return i("div",{ref:Le,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),t.role===Y.VIEWER){return}if(!Ge.current){return}Ge.current.setPointersPositions(e);const n=Ge.current.findOne(".elements-container"),i=null==n?void 0:n.getRelativePointerPosition(),o=Ge.current.getPointerPosition(),r=Ge.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(r.reverse())].map(e=>t.getElementById(e.id())).filter(e=>!!e),a=s[0];je&&i&&(je(i,a,{elements:s,page:l}),je=null)},style:{position:"relative",width:d+"px",height:h+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(dt?" active-page":""),children:[n(ae,{ref:Ge,eventBatchFunc:c,width:Math.min(d,O.width+200),height:Math.min(O.height+200,h),onClick:ct,onTap:ct,onContextMenu:e=>{if(e.evt.preventDefault(),t.role===Y.VIEWER){return}const n=e.target.findAncestor(".element",!0),i=t.getElementById(null==n?void 0:n.id()),o=null==i?void 0:i.top,r=null==o?void 0:o.id;if(!r){return t.selectElements([]),void Je.close()}t.selectedElementsIds.indexOf(r)>=0||t.selectElements([r]),Je.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{it(e),ot(e)},onTouchStart:it,onMouseMove:e=>{if(!t.distanceGuidesVisible&&!e.evt.altKey){return void(ze&&_e(null))}const n=e.target.findAncestor(".element",!0),i=null==n?void 0:n.id();rt(i)},onDragStart:e=>{var n;const i=e.target.getStage();if(i&&i.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const i=t.getElementById(null==o?void 0:o.id()),r=null==i?void 0:i.top,l=null==r?void 0:r.id;if(!(i&&t.selectedElementsIds.indexOf(i.id)>=0||l&&t.selectedElementsIds.indexOf(l)>=0)&&l){t.selectElements([l]);const i=$e();e.target.stopDrag(),i.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(n=Be.current)||void 0===n||n.startDrag(e),j()}}ze&&_e(null)},onDragMove:e=>{const n=Be.current;n&&e.target===n&&n.nodes().forEach(e=>{const n=t.getElementById(e.id());!n||n.x===e.x()&&n.y===e.y()||n.set({x:e.x(),y:e.y()})})},pageId:l.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:i(f,{children:[n(xe,{width:d,height:h,fill:J.workspaceBackgroundColor}),n(u,{x:Ie,y:Pe,scaleX:t.scale,scaleY:t.scale,name:"page-container",children:i(u,{name:"page-container-2",children:[n(u,{x:be.left,y:be.top,children:n(ye,Object.assign({},Te,De,{transparencyBackgroundColor:J.transparencyBackgroundColor}))}),i(u,{isolated:l.hasBlendMode,children:[n(u,{name:"page-background-group",x:be.left,y:be.top,clip:De,children:n(we,Object.assign({},Te))}),i(u,{x:be.left,y:be.top,name:"elements-container",listening:!t.isPlaying&&t.role!==Y.VIEWER,children:[n(x,{name:"elements-area",width:l.computedWidth,height:l.computedHeight,listening:!1}),n(Me,{elements:l.children,store:t}),n(Ae,{page:l})]})]}),n(v,{name:"bleed",fill:J.bleedColor,listening:!1,visible:t.bleedVisible&&(be.top>0||be.right>0||be.bottom>0||be.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:r}=ve,s=l.computedWidth,a=l.computedHeight,c=e._context;c.beginPath(),c.rect(0,0,r+s+i,n+a+o),c.rect(r,n,s,a),c.fillStyle=t.fill(),c.fill("evenodd")}}),B()===Oe&&n(Re,{name:"hit-detection",x:-ft/2-pt,y:-ft/2-pt,width:Se+ft+2*pt,height:ke+ft+2*pt})]})}),n(p,{name:"workspace-background",points:[0,0,d,0,d,h,0,h,0,0,Ie,Pe,Ie,h-Pe,d-Ie,h-Pe,d-Ie,Pe,Ie,Pe],listening:!1,closed:!0,fill:J.workspaceBackgroundColor}),n(u,{x:Ie,y:Pe,scaleX:t.scale,scaleY:t.scale,children:n(x,{name:"page-highlight",hideInExport:!0,x:-ft/2-pt,y:-ft/2-pt,width:Se+ft+2*pt,height:ke+ft+2*pt,stroke:mt?J.activePageBorderColor:J.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),i(u,{x:Ie+be.left*t.scale,y:Pe+be.top*t.scale,scaleX:t.scale,scaleY:t.scale,name:"page-abs-container",children:[n(S,{ref:Be,name:H,rotateAnchorAngle:Ze,onDragStart:e=>{var n;const i=e.target.getStage();i&&i.getPointersPositions().length>=2?e.target.stopDrag():((null===(n=e.evt)||void 0===n?void 0:n.altKey)&&A&&D(t.selectedElements,l,t),Fe.current||(Fe.current=!0,t.history.startTransaction()))},onDragEnd:()=>{Fe.current&&(t.history.endTransaction(),Fe.current=!1),et()},onTransformStart:()=>{Ue.setTransforming(!0),t.history.startTransaction(),We.current=new Map(Ne.map(e=>[e.id,{width:e.width,height:e.height}])),_e(null)},boundBoxFunc:(e,n)=>{var i,o,r,l;const s=null!==(l=null===(i=ee.boundBoxFunc)||void 0===i?void 0:i.call(ee,e,n))&&void 0!==l?l:n,a=Math.abs(s.width)<1||Math.abs(s.height)<1,c=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!c){return e}const d=t.selectedElements;if(1===d.length&&"table"===(null===(o=d[0])||void 0===o?void 0:o.type)){const t=d[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,c=Object.assign({},s);return l<t.minWidth&&(c.width=e.width),a<t.minHeight&&(c.height=e.height),$(c,s,e)}}return Ke&&Ne.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,c=!U(n),d=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,d="x"===e?s:a,m=K(t,e,c,r);return r>=m&&l*d<m}),m=Object.assign({},t),u=t.width*e.width<0,h=t.height*e.height<0,g=u||d("x"),f=h||d("y"),p=f||!c&&g;return(g||!c&&f)&&(m.width=e.width),p&&(m.height=e.height),$(m,t,e)})(e,s,(null===(r=Be.current)||void 0===r?void 0:r.getActiveAnchor())||"",Ne,We.current):s},onTransform:e=>{const t=Be.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{qe()},0)},onTransformEnd:e=>{Ue.setTransforming(!1),Ue.setLabel({}),t.history.endTransaction(),We.current=null,et()},visible:!t.isPlaying}),n(Ye,{store:t,gesture:Ue,transformerStyle:ee,onChange:Qe}),ze&&ze.map(({points:e,distance:o,box1:r,box2:l},s)=>i(u,{name:"distances-container",hideInExport:!0,listening:!1,children:[n(x,Object.assign({},r,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),n(x,Object.assign({},l,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),n(p,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(p,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),i(g,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/t.scale,scaleY:1/t.scale,children:[n(w,{cornerRadius:5,fill:J.distanceGuideStyle.labelFill,pointerDirection:"down"}),n(E,{align:"center",verticalAlign:"middle",fill:J.distanceGuideStyle.labelTextFill,padding:5,text:_({unit:t.unit,dpi:t.dpi,px:o})})]})]},s)),l._rendering&&i(u,{children:[n(x,{width:Se,height:ke,fill:"rgba(255,255,255,0.9)"}),n(E,{text:"Rendering...",fontSize:60,width:Se,height:ke,align:"center",verticalAlign:"middle"})]}),ht&&n(ht,{components:y,store:t,page:l,stageRef:Ge,tooltipSafeArea:z}),gt&&n(ie,{children:n(gt,Object.assign({components:y,store:t},Je.props))}),n(R,{store:t,pageId:l.id})]}),n(M,{store:t,page:l,width:d,height:h,scale:t.scale,xPadding:Ie,yPadding:Pe,bleedLeft:be.left,bleedTop:be.top}),n(Xe,{gesture:Ue,store:t}),n(Ee,{selection:tt}),C()>0&&i(u,{hideInExport:!0,children:[n(Ce,{name:"cache-bounds",x:d-(1===C()?250:210),y:h-(1===C()?95:45)}),n(Ce,{name:"cache-bounds-t",x:10,y:10})]}),W()&&n(E,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:d-170,y:h-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),n(u,{name:"line-guides"})]})}),Ve&&ut&&n(ut,{store:t,page:l,xPadding:Ie,yPadding:Pe,layout:T})]})});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const PRESERVED_INLINE_STYLES: readonly [
|
|
2
|
-
export declare const PRESERVED_BLOCK_STYLES: readonly [
|
|
1
|
+
export declare const PRESERVED_INLINE_STYLES: readonly ['text-shadow', 'letter-spacing', 'word-spacing', '-webkit-text-stroke', 'font-variant', 'vertical-align'];
|
|
2
|
+
export declare const PRESERVED_BLOCK_STYLES: readonly ['text-align', 'line-height', 'margin-top', 'margin-bottom', 'text-indent', 'list-style-type'];
|
|
3
3
|
export declare function registerQuillUnrestrictedFontFormats(): void;
|
package/canvas/rect-control.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var r={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}}return r};import{
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var r={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}}return r};import{Fragment as t,jsx as r,jsxs as n}from"react/jsx-runtime";import o from"react";import{Rect as a,Transformer as i}from"react-konva";import{cropBoundBoxFunc as s}from"./transform-box.js";import{useWorkspaceStyle as c}from"./workspace-style.js";export function RectControl({rect:l,onChange:u,nodeRef:f,fixedRef:h,disabled:b=!1,anchors:d,accept:g,crop:p=!1}){const m=o.useRef(null),y=null!=f?f:m,x=o.useRef(null),{innerImageCropTransformerStyle:v}=c(),{boundBoxFunc:j,keepRatio:O,enabledAnchors:w}=v,R=e(v,["boundBoxFunc","keepRatio","enabledAnchors"]),A=p?v:R,k=!p;o.useLayoutEffect(()=>{var e;null===(e=x.current)||void 0===e||e.nodes(y.current?[y.current]:[])},[y]);const F=()=>{const e=y.current,t={x:e.x(),y:e.y(),width:e.width()*e.scaleX(),height:e.height()*e.scaleY()};e.scale({x:1,y:1}),t.width>0&&t.height>0&&(!g||g(t))?(e.size(t),u(t)):e.setAttrs(l)},P=h?s(y,h,"contain",A.boundBoxFunc):(e,t)=>{var r;if(t.width<5||t.height<5){return e}if(g&&(null===(r=y.current)||void 0===r?void 0:r.getParent())){const r=y.current.getParent(),n=r.getAbsoluteTransform().copy().invert().point(t),o=r.getAbsoluteScale();if(!g(Object.assign(Object.assign({},n),{width:t.width/Math.abs(o.x),height:t.height/Math.abs(o.y)}))){return e}}return t};return n(t,{children:[r(a,Object.assign({ref:y},l,{name:"image-tool-rect",fill:k?"rgba(0,0,0,0.001)":void 0,listening:k&&!b,draggable:k&&!b,onTransform:F,onDragMove:F})),r(i,Object.assign({ref:x,keepRatio:!1,rotateEnabled:!1,flipEnabled:!1},d?{enabledAnchors:d}:{},A,{boundBoxFunc:P,visible:!b}))]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{jsx as e,Fragment as o,jsxs as r}from"react/jsx-runtime";import{elementOpacity as n}from"./paint-opacity.js";import i from"react";import{observer as s}from"mobx-react-lite";import{Group as l,Path as a,Rect as c,Shape as d}from"react-konva";import{nodeAutorun as u}from"../utils/mobx.js";import{isAlive as h}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{drawLayout as g}from"render-tag";import{drawTextOnPathLayout as m}from"render-tag/path";import{activeAnchorOf as b,isCornerAnchor as p,isRotateAnchor as x,scaledFontSizeAttrs as y,scaledFontSizeBounds as w,roundedFontSizeAttrs as v,roundedTextDecorationAttrs as j,scaledStyleAttrs as z,roundedGeometryPx as O,roundedPosition as E,textMinResizeWidth as S,transformScale as M}from"../utils/px.js";import{flags as k}from"../utils/flags.js";import{editorTextSizing as R,textOverflowOf as F,textResizeFloorFontSize as Y}from"../utils/text-sizing.js";import{curvedBoxWidth as C,layoutAsSized as I,layoutCurvedTextSizing as X,layoutTextSizing as P,renderTagLayoutAt as A}from"@polotno/core/text-sizing";import{curveLayoutAt as T}from"@polotno/core/curve-glyphs";import{applyFilter as B}from"./apply-filters.js";import{getLineHeight as H,usePrevious as N}from"./text-element.js";import{useFontSpecsLoader as $}from"./text-element/font-specs-loader.js";import{getHtml as D,getCurveTextHeight as W,letterSpacingOverhang as _}from"@polotno/core/text-html";import{useColor as J,withDisplayTextPaints as U}from"./use-color.js";import{toDisplayColor as L}from"@polotno/core/color";import{animatedShadow as V}from"./animated-shadow.js";import{detectSize as q}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as G,trimTrailingLetterSpace as K}from"@polotno/core/background-shape";import{useFadeIn as Q}from"./use-fadein.js";import{incrementLoader as Z}from"../utils/loader.js";import{removeTags as tt}from"@polotno/core/text";import{shadowCastByBackground as et}from"@polotno/core/filters";import{applyOpacityToColor as ot}from"@polotno/core/svg";import{isTouchDevice as rt}from"../utils/screen.js";import{getLimitedFontSize as nt}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as it,extractFontSpecsFromHtml as st,scaleRichTextFontSizesInHtml as lt}from"../utils/rich-text-html.js";import{RichEditor as at}from"./rich-editor.js";import{visiblePlaceholder as ct}from"./text-element/placeholder.js";import{PlacedNode as dt}from"./placed-node.js";import{AutoDeleteEmptyText as ut}from"./text-element/auto-delete-empty-text.js";import{wrapHtmlForRenderTag as ht}from"@polotno/core/reset-style";import{xmlEscape as ft}from"@polotno/core/xml";import{hasMeasuredHeight as gt,resolveTextBoxHeight as mt}from"@polotno/core/text-types";import{TEXT_PRESETS as bt}from"@polotno/core/animation-presets";import{textUnitState as pt}from"../utils/animations.js";export{ht as wrapHtmlForRenderTag};function xt(t,e){return t!==e&&(!k.textVerticalResizeEnabled||t<e)}const yt=({opacity:t,y:e,scale:o,blur:r,from:n,to:i})=>t>=1&&!e&&1===o&&!r&&n<=0&&i>=1;export const RenderTagElement=s(({element:s,store:ht})=>{var wt,vt,jt,zt,Ot,Et,St,Mt,kt,Rt,Ft;const Yt=i.useRef(null),Ct=i.useRef(null),[It,Xt]=i.useState(!1),Pt=i.useRef(s.height),At=i.useRef(null),Tt=rt(),{textVerticalResizeEnabled:Bt}=k,Ht=N(s.fontFamily),Nt=i.useMemo(()=>it(s.text,{fontSize:s.fontSize,fontFamily:s.fontFamily}),[s.text,s.fontSize,s.fontFamily]),$t=i.useMemo(()=>st(Nt,{fontFamily:s.fontFamily,fontWeight:s.fontWeight,fontStyle:s.fontStyle}),[Nt,s.fontFamily,s.fontWeight,s.fontStyle]),[Dt]=$(ht,$t,s.text||s.placeholder),Wt=s._editModeEnabled;Q(Yt);const _t=Dt?s.fontFamily:Ht&&Ht!==s.fontFamily?Ht:"Arial",Jt=J(s).fill,Ut=ct(s.placeholder),Lt=!!Ut&&!tt(s.text),Vt=Lt?ft(Ut):Nt,qt=Lt?.6:n(s),Gt=D(U(s),{fontFamily:_t,color:Jt,forEditor:!0,text:Vt,textIsNormalized:!0}),Kt=s.width||1,Qt=(t,e)=>A(U(t),{getHtmlOptions:{fontFamily:_t,color:Jt,forEditor:!0,text:Vt,textIsNormalized:!0},textUnits:e}),Zt=F(s),te=R(s),ee=s.curveEnabled,oe=JSON.stringify(te),re="fixed"===te.box?s.height:0,ne=It?At.current:null,ie=i.useMemo(()=>{if(ne){return ne.sized}const t=Lt?Object.assign(Object.assign({},s),{text:Vt}):s;try{return ee?Object.assign({curved:!0},X({element:t,sizing:te,layoutAt:T(U(s),{getHtmlOptions:{fontFamily:_t,color:Jt,text:Vt,textIsNormalized:!0}})})):Object.assign({curved:!1},P({element:t,sizing:te,layoutAt:Qt(s)}))}catch(e){return console.error("render-tag layout failed:",e),null}},[Gt,Kt,Dt,ee,oe,re,s.curvePower,s.fontSize,s.width,ne]),se=null!==(wt=null==ne?void 0:ne.width)&&void 0!==wt?wt:Kt,le=ne?s.width/ne.width:1,ae=!1===(null==ie?void 0:ie.curved)?ie.layout:null,ce=(null==ie?void 0:ie.curved)?ie.layout:null,de=s.a.text,ue=s.a.textUnits,he=ue?bt[ue.animation.name].unit:void 0,fe=i.useMemo(()=>{const t="string"==typeof de&&de!==s.text;if(!1!==(null==ie?void 0:ie.curved)||Lt||!t&&!he){return ae}try{return I({element:t?Object.assign(Object.assign({},s),{text:de}):s,sized:ie,sizing:te,layoutAt:Qt(s,he)})}catch(e){return console.error("render-tag layout failed:",e),ae}},[ae,de,he]),ge=ue&&(null==fe?void 0:fe.textUnits),me=i.useMemo(()=>{if(!ue||!ge){return null}const t=ge.map((t,e)=>pt(ue,e,ge.length)),e=e=>!t[e]||yt(t[e]);return t.map((t,o)=>({state:t,slice:yt(t)&&e(o-1)&&e(o+1)}))},[ue,ge]),be=null!==(vt=null==ie?void 0:ie.fontSize)&&void 0!==vt?vt:s.fontSize,pe=null!==(jt=null==ie?void 0:ie.scale)&&void 0!==jt?jt:1,xe=_(s.letterSpacing,be),ye=null!==(zt=null==ne?void 0:ne.overhang)&&void 0!==zt?zt:xe,we=H({fontLoaded:Dt,fontFamily:s.fontFamily,fontSize:be,lineHeight:s.lineHeight}),ve=ee?0:Math.max(null!==(Ot=null==ae?void 0:ae.height)&&void 0!==Ot?Ot:0,be*we),je=ce?ce.bounds:null,ze=je?(s.width-je.width)/2-je.x:0,Oe=i.useMemo(()=>{var t;if(ce&&je){const t=ce.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+ze,y:t.y-je.y})}const e=null!==(t=null==fe?void 0:fe.paintBounds)&&void 0!==t?t:null;return e&&ge?{x:e.x-be,y:e.y-be,width:e.width+2*be,height:e.height+2*be}:e},[fe,ce,je,ze,ge,be]),Ee=i.useMemo(()=>fe?fe.lines.map(t=>K({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},ye)):[],[fe,ye]),Se=i.useRef([]),Me=i.useRef(null),ke=i.useRef(!0),[,Re]=i.useReducer(t=>t+1,0);i.useEffect(()=>{const t=Se.current;t.length>0&&(Se.current=[],t.forEach(t=>t()))});const Fe=i.useCallback((t,e,o,r)=>{const n=Z(`text ${s.id}`),i=()=>{ht.history.ignore(t,e,o).then(()=>{ke.current?(Se.current.push(n),Re()):n()})};r?queueMicrotask(i):i()},[s.id,ht]),Ye=i.useCallback(t=>{const e=null!==Me.current;Me.current=t,e||Fe(()=>{const t=Me.current;Me.current=null,h(s)&&xt(s.height,t)&&s.set({height:t})},!1,!0)},[s,Fe]),Ce=i.useRef(ie);Ce.current=ie,i.useEffect(()=>{if(!Dt){return}if(!ae){return}if(!gt(s)){return void Fe(()=>{h(s)&&(gt(s)||s.set({height:ve}))},void 0,void 0,!0)}if(ht.isPlaying){return}const t=xt(s.height,ve),e=()=>Ye(ve);if("change-font-size"!==Zt||It||Wt||s.curveEnabled){"resize"===Zt&&t&&!It&&e()}else if(ie&&ie.fontSize!==s.fontSize){const{fontSize:t,text:e}=ie;Fe(()=>{if(!h(s)){return}if(Ce.current!==ie||"change-font-size"!==F(s)||s._editModeEnabled){return}const o=y(s,t);Lt||e===s.text||(o.text=e),s.set(o)},!1,!0)}else{t&&e()}}),i.useEffect(()=>()=>{ke.current=!1;const t=Se.current;t.length>0&&(Se.current=[],t.forEach(t=>t()))},[]),i.useLayoutEffect(()=>{if(!Dt||!s.curveEnabled||It){return}if(!je||!je.width){return}const t=t=>t&&Bt?Math.max(t,je.height):je.height,e=t=>C(te,{width:t},je.width);Math.abs(e(s.width)-s.width)<1&&Math.abs(t(s.height)-s.height)<1||Fe(()=>{if(!h(s)){return}const o=e(s.width),r=o-s.width,n=t(s.height),i=n-s.height;if(Math.abs(r)<1&&Math.abs(i)<1){return}const l=s.a.rotation*Math.PI/180,a=-r/2*Math.cos(l),c=-r/2*Math.sin(l);s.set({width:o,height:n,x:s.a.x+a,y:s.a.y+c})},!1,!0,!0)},[Dt,s.curveEnabled,Zt,je,It,Bt,Fe]),i.useEffect(()=>u(s,()=>{const t=Yt.current;t&&B(t,s)}),[fe,ce,s.a.width,s.a.height,ue,s.a.shadowColor,s.a.shadowOffsetX,s.a.shadowOffsetY,s.a.shadowOpacity]);const Ie=mt(s,ve),Xe=ee||!Dt||It||ht.isPlaying||"resize"!==Zt?s.a.height:Bt?Math.max(s.a.height,ve):ve;let Pe=0;ee||"middle"!==s.verticalAlign?ee||"bottom"!==s.verticalAlign||(Pe=Ie-ve*le):Pe=(Ie-ve*le)/2;const Ae=null!==(Et=null==ne?void 0:ne.backgroundPadding)&&void 0!==Et?Et:s.backgroundPadding*(be*we*.5),Te=null!==(St=null==ne?void 0:ne.backgroundCornerRadius)&&void 0!==St?St:s.backgroundCornerRadius*(be*we*.5),Be=s.backgroundEnabled||s.borderSize>0,He=i.useMemo(()=>!Be||s.curveEnabled||s.legacyBackground||0===Ee.length?"":G({rects:Ee,padding:Ae,cornerRadius:Te}),[Be,s.curveEnabled,s.legacyBackground,Ee,Ae,Te]),Ne=i.useRef(null),$e=i.useRef(s.width),De=i.useRef(null),We=i.useRef(null),_e=i.useRef(""),Je=i.useRef(0),Ue=i.useRef(0),Le=i.useRef({fontSize:s.fontSize}),Ve=s.width>0?s.a.width/s.width:1,qe=Ve*le,Ge=V(s),Ke=null!==(Mt=null==ne?void 0:ne.shadow)&&void 0!==Mt?Mt:{shadowBlur:Ge.shadowBlur*pe,shadowOffsetX:Ge.shadowOffsetX*pe,shadowOffsetY:Ge.shadowOffsetY*pe},Qe=Object.assign(Object.assign({},Ke),{shadowColor:Ge.shadowColor,shadowOpacity:Ge.shadowOpacity}),Ze=Object.assign(Object.assign({},Qe),{shadowEnabled:Ge.shadowEnabled&&Be});return r(o,{children:[e(ut,{element:s,store:ht}),Be?s.curveEnabled||s.legacyBackground?e(dt,Object.assign({as:c,element:s,offsetX:Ae/Ve,offsetY:Ae/Ve,scaleX:qe,scaleY:qe,hideInExport:!s.showInExport,listening:!1,opacity:qt,fillEnabled:s.backgroundEnabled,fill:ot(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:L(s.borderColor),strokeWidth:null!==(kt=null==ne?void 0:ne.borderSize)&&void 0!==kt?kt:s.borderSize},Ze,{width:se+2*Ae,height:(null!==(Rt=null==ne?void 0:ne.boxHeight)&&void 0!==Rt?Rt:Ie)+2*Ae,cornerRadius:Te})):e(dt,Object.assign({as:a,element:s,name:"rendertag-background",offsetY:-Pe/qe,scaleX:qe,scaleY:qe,hideInExport:!s.showInExport,listening:!1,visible:He.length>0,opacity:qt,fillEnabled:s.backgroundEnabled,fill:ot(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:L(s.borderColor),strokeWidth:null!==(Ft=null==ne?void 0:ne.borderSize)&&void 0!==Ft?Ft:s.borderSize,lineJoin:Te>0?"round":"miter"},Ze,{data:He})):null,e(dt,Object.assign({as:d,nodeRef:Yt,element:s,selfRectFunc:Oe?()=>Oe:void 0,name:"rendertag-text",scaleX:qe,scaleY:qe,offsetY:qe>0?-Pe/qe:0,width:se,height:Math.max(s.height,ve),listening:!1,visible:!Wt&&!!(ee?ce:ae),editModeEnabled:Wt,opacity:qt,shadowEnabled:Ge.shadowEnabled&&!et(s)},Qe,{hideInExport:!s.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(ee){if(!ce||!je){return}o.save(),o.translate(ze,-je.y),m({layout:ce,ctx:o}),o.restore()}else{if(!fe){return}g({layout:fe,width:se,ctx:o,pixelRatio:1,paintTextUnit:me?t=>{const{state:e,slice:o}=me[t.unit.index];(({unit:t,ctx:e,draw:o},{opacity:r,y:n,scale:i,blur:s,from:l,to:a},c,d)=>{var u;if(!(r<=0||i<=0||a<=l)){if(l>0||a<1){const o="rtl"===(null===(u=t.fragments[0])||void 0===u?void 0:u.direction),[r,n]=o?[1-a,1-l]:[l,a],i=r<=0?t.x-c:t.x+r*t.width,s=n>=1?t.x+t.width+c:t.x+n*t.width;e.beginPath(),e.rect(i,t.y-c,s-i,t.height+2*c),e.clip()}if(e.globalAlpha*=r,n&&e.translate(0,n*c),1!==i){const o=t.x+t.width/2,r=t.y+t.height/2;e.translate(o,r),e.scale(i,i),e.translate(-o,-r)}if(s>0){const t=e.getTransform(),o=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c));e.filter=`blur(${s*c*o}px)`}o({slice:d})}})(t,e,be,o)}:void 0})}}catch(r){console.error("render-tag draw failed:",r)}}}})),e(dt,{as:c,nodeRef:Ct,element:s,name:"element",listening:s.selectable,width:s.a.width,height:Xe,visible:!Wt,draggable:Tt?s.draggable&&s.isSelected:s.draggable,preventDefault:!Tt||s.isSelected,opacity:0,hideInExport:!0,id:s.id,onDragMove:t=>{s.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{s.set(E(t.target))},onDblClick:t=>{s.contentEditable&&(We.current={x:t.evt.clientX,y:t.evt.clientY},s.toggleEditMode(!0))},onDblTap:t=>{var e;if(s.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];We.current=o?{x:o.clientX,y:o.clientY}:null,s.toggleEditMode(!0)}},onTransformStart:t=>{Pt.current=s.height,$e.current=s.width,De.current=null,Ne.current=t.target.position(),_e.current=b(t.target),Je.current=s.a.rotation,Ue.current=s.height,Le.current={fontSize:s.fontSize,minFontSize:s.minFontSize,maxFontSize:s.maxFontSize},At.current=!s.curveEnabled&&["top-left","top-right","bottom-left","bottom-right"].includes(_e.current)?{sized:ie,width:Kt,boxHeight:Ie,backgroundPadding:Ae,backgroundCornerRadius:Te,borderSize:s.borderSize,overhang:xe,shadow:Ke}:null,Xt(!0)},onTransform:e=>{const o=e.target,r=_e.current,n="middle-left"===r||"middle-right"===r,i="top-center"===r||"bottom-center"===r,l=M(o.scaleX());if(n){const e=o.width()*l;let r=Math.max(e,S($e.current,Y(s)));const n=s.toJSON();let i=0;if("fit"===Zt){i=Pt.current}else if(s.curveEnabled){i=W(Object.assign(Object.assign({},n),{width:r}))}else{const{x:e,y:o,width:s,height:l}=n,a=t(n,["x","y","width","height"]),c=`${JSON.stringify(a)}|${_t}|${Dt}|${Jt}`;if(De.current&&De.current.signature===c&&r<=De.current.width){r=De.current.width,i=De.current.height}else{const t=t=>{const e=Object.assign(Object.assign({},n),{width:t});try{return P({element:Object.assign(Object.assign({},e),{text:Vt}),sizing:Object.assign(Object.assign({},te),{fit:{mode:"off"},cutAtBox:!1}),layoutAt:Qt(e)}).layout}catch(wt){const o=D(e,{fontFamily:_t,color:Jt,forEditor:!0,text:Vt,textIsNormalized:!0});return{height:q(o).height,lines:[]}}};let e=t(r);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-xe));o>r+.5&&o<=$e.current+.5&&(r=Math.min(Math.ceil(o),$e.current),e=t(r),De.current={signature:c,width:r,height:e.height}),i=e.height}}r>e&&Ne.current&&o.position(Ne.current),o.width(r),o.scaleX(1),o.scaleY(1);let a=k.textVerticalResizeEnabled?Math.max(i,Pt.current):i;"ellipsis"!==Zt&&"fit"!==Zt||(a=Pt.current),o.height(a),s.set({width:o.width(),height:a,x:o.x(),y:o.y()})}else if(i){const t="resize"===Zt?ee?(null==je?void 0:je.height)||s.fontSize:ve:we*("fit"===te.fit.mode?te.fit.min:s.fontSize),e=o.height()*o.scaleY();if(e<t){if(o.height(t),Ne.current){if("top-center"===_e.current){const e=Je.current*Math.PI/180,r=Ue.current-t;o.x(Ne.current.x-r*Math.sin(e)),o.y(Ne.current.y+r*Math.cos(e))}else{o.position(Ne.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),Ue.current=Math.max(t,e),s.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1);const t=s.fontSize*l;s.set(Object.assign(Object.assign(Object.assign({},w(Le.current,t/Le.current.fontSize)),{letterSpacing:s.letterSpacing,width:o.width()*l,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*l}),z(s,l)))}Ne.current=e.target.position()},onTransformEnd:t=>{At.current=null,Xt(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1);const o=v(s,s.fontSize*e),r=Le.current,n=_e.current;s.set(Object.assign(Object.assign(Object.assign({},o),p(n)&&!x(n)?w(r,o.fontSize/r.fontSize,!0):{}),{width:O(t.target.width()*e),x:O(t.target.x()),y:O(t.target.y()),rotation:O(t.target.rotation()),text:lt(s.text,e)}))}}),Wt&&e(dt,{as:l,element:s,offsetY:-Pe,children:e(f,{divProps:{style:{zIndex:20}},children:e(at,{element:s,fitScale:pe,fitScaleFor:t=>{if(ee){return pe}try{return P({element:Object.assign(Object.assign({},s),{text:t}),sizing:te,layoutAt:A(U(s),{getHtmlOptions:{fontFamily:_t,color:Jt,forEditor:!0,text:t}})}).scale}catch(wt){return pe}},onChange:t=>{if("fit"===Zt){return void s.set({text:t})}const e=nt({oldText:tt(s.text),newText:tt(t),element:s});s.set(Object.assign({text:t},y(s,e)))},onBlur:()=>{h(s)&&(s.set(j(s)),s.toggleEditMode(!1))},clickCoords:We.current})})})]})});
|
|
1
|
+
var t=this&&this.__rest||function(t,e){var r={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}}return r};import{Fragment as e,jsx as r,jsxs as o}from"react/jsx-runtime";import{elementOpacity as n}from"./paint-opacity.js";import i from"react";import{observer as s}from"mobx-react-lite";import{Group as a,Path as l,Rect as c,Shape as d}from"react-konva";import{nodeAutorun as u}from"../utils/mobx.js";import{isAlive as h}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{drawLayout as g}from"render-tag";import{drawTextOnPathLayout as m}from"render-tag/path";import{activeAnchorOf as b,isCornerAnchor as p,isRotateAnchor as x,scaledFontSizeAttrs as y,scaledFontSizeBounds as w,roundedFontSizeAttrs as v,roundedTextDecorationAttrs as j,scaledStyleAttrs as O,roundedGeometryPx as z,roundedPosition as E,textMinResizeWidth as S,transformScale as M}from"../utils/px.js";import{flags as k}from"../utils/flags.js";import{editorTextSizing as R,textOverflowOf as Y,textResizeFloorFontSize as C}from"../utils/text-sizing.js";import{curvedBoxWidth as X,layoutAsSized as P,layoutCurvedTextSizing as F,layoutTextSizing as I,renderTagLayoutAt as T}from"@polotno/core/text-sizing";import{curveLayoutAt as B}from"@polotno/core/curve-glyphs";import{applyFilter as A}from"./apply-filters.js";import{getLineHeight as H}from"./text-element.js";import{liveFitScale as $,useRenderTagSource as D}from"./text-element/render-tag-source.js";import{getHtml as L,getCurveTextHeight as _,letterSpacingOverhang as J}from"@polotno/core/text-html";import{withDisplayTextPaints as N}from"./use-color.js";import{toDisplayColor as U}from"@polotno/core/color";import{animatedShadow as V}from"./animated-shadow.js";import{detectSize as q}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as W,trimTrailingLetterSpace as G}from"@polotno/core/background-shape";import{useFadeIn as K}from"./use-fadein.js";import{incrementLoader as Q}from"../utils/loader.js";import{removeTags as Z}from"@polotno/core/text";import{shadowCastByBackground as tt}from"@polotno/core/filters";import{applyOpacityToColor as et}from"@polotno/core/svg";import{isTouchDevice as rt}from"../utils/screen.js";import{getLimitedFontSize as ot}from"./text-element/max-font-size.js";import{scaleRichTextFontSizesInHtml as nt}from"../utils/rich-text-html.js";import{RichEditor as it}from"./rich-editor.js";import{PlacedNode as st}from"./placed-node.js";import{AutoDeleteEmptyText as at}from"./text-element/auto-delete-empty-text.js";import{wrapHtmlForRenderTag as lt}from"@polotno/core/reset-style";import{hasMeasuredHeight as ct,resolveTextBoxHeight as dt}from"@polotno/core/text-types";import{TEXT_PRESETS as ut,WIPE_DIRECTION as ht}from"@polotno/core/animation-presets";import{textUnitState as ft}from"../utils/animations.js";export{lt as wrapHtmlForRenderTag};function gt(t,e){return t!==e&&(!k.textVerticalResizeEnabled||t<e)}const mt=({opacity:t,y:e,scale:r,blur:o,from:n,to:i,shift:s})=>t>=1&&!e&&1===r&&!o&&n<=0&&i>=1&&!s;export const RenderTagElement=s(({element:s,store:lt})=>{var bt,pt,xt,yt,wt,vt,jt,Ot,zt,Et,St;const Mt=i.useRef(null),kt=i.useRef(null),[Rt,Yt]=i.useState(!1),Ct=i.useRef(s.height),Xt=i.useRef(null),Pt=rt(),{textVerticalResizeEnabled:Ft}=k,{fontLoaded:It,fontFamily:Tt,color:Bt,isPlaceholder:At,normalizedSourceText:Ht,getHtmlOptions:$t}=D(s,lt),Dt=s._editModeEnabled;K(Mt);const Lt=At?.6:n(s),_t=L(N(s),$t),Jt=s.width||1,Nt=(t,e)=>T(N(t),{getHtmlOptions:$t,textUnits:e}),Ut=Y(s),Vt=R(s),qt=s.curveEnabled,Wt=JSON.stringify(Vt),Gt="fixed"===Vt.box?s.height:0,Kt=Rt?Xt.current:null,Qt=i.useMemo(()=>{if(Kt){return Kt.sized}const t=At?Object.assign(Object.assign({},s),{text:Ht}):s;try{return qt?Object.assign({curved:!0},F({element:t,sizing:Vt,layoutAt:B(N(s),{getHtmlOptions:{fontFamily:Tt,color:Bt,text:Ht,textIsNormalized:!0}})})):Object.assign({curved:!1},I({element:t,sizing:Vt,layoutAt:Nt(s)}))}catch(e){return console.error("render-tag layout failed:",e),null}},[_t,Jt,It,qt,Wt,Gt,s.curvePower,s.fontSize,s.width,Kt]),Zt=null!==(bt=null==Kt?void 0:Kt.width)&&void 0!==bt?bt:Jt,te=Kt?s.width/Kt.width:1,ee=!1===(null==Qt?void 0:Qt.curved)?Qt.layout:null,re=(null==Qt?void 0:Qt.curved)?Qt.layout:null,oe=s.a.text,ne=s.a.textUnits,ie=ne?ut[ne.animation.name].unit:void 0,se=i.useMemo(()=>{const t="string"==typeof oe&&oe!==s.text;if(!1!==(null==Qt?void 0:Qt.curved)||At||!t&&!ie){return ee}try{return P({element:t?Object.assign(Object.assign({},s),{text:oe}):s,sized:Qt,sizing:Vt,layoutAt:Nt(s,ie)})}catch(e){return console.error("render-tag layout failed:",e),ee}},[ee,oe,ie]),ae=ne&&(null==se?void 0:se.textUnits),le=i.useMemo(()=>{if(!ne||!ae){return null}const t=ae.map((t,e)=>ft(ne,e,ae.length)),e=e=>!t[e]||mt(t[e]);return t.map((t,r)=>({state:t,slice:mt(t)&&e(r-1)&&e(r+1)}))},[ne,ae]),ce=null!==(pt=null==Qt?void 0:Qt.fontSize)&&void 0!==pt?pt:s.fontSize,de=null!==(xt=null==Qt?void 0:Qt.scale)&&void 0!==xt?xt:1,ue=J(s.letterSpacing,ce),he=null!==(yt=null==Kt?void 0:Kt.overhang)&&void 0!==yt?yt:ue,fe=H({fontLoaded:It,fontFamily:s.fontFamily,fontSize:ce,lineHeight:s.lineHeight}),ge=qt?0:Math.max(null!==(wt=null==ee?void 0:ee.height)&&void 0!==wt?wt:0,ce*fe),me=re?re.bounds:null,be=me?(s.width-me.width)/2-me.x:0,pe=i.useMemo(()=>{var t;if(re&&me){const t=re.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+be,y:t.y-me.y})}const e=null!==(t=null==se?void 0:se.paintBounds)&&void 0!==t?t:null;return e&&ae?{x:e.x-ce,y:e.y-ce,width:e.width+2*ce,height:e.height+2*ce}:e},[se,re,me,be,ae,ce]),xe=i.useMemo(()=>se?se.lines.map(t=>G({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},he)):[],[se,he]),ye=i.useRef([]),we=i.useRef(null),ve=i.useRef(!0),[,je]=i.useReducer(t=>t+1,0);i.useEffect(()=>{const t=ye.current;t.length>0&&(ye.current=[],t.forEach(t=>t()))});const Oe=i.useCallback((t,e,r,o)=>{const n=Q(`text ${s.id}`),i=()=>{lt.history.ignore(t,e,r).then(()=>{ve.current?(ye.current.push(n),je()):n()})};o?queueMicrotask(i):i()},[s.id,lt]),ze=i.useCallback(t=>{const e=null!==we.current;we.current=t,e||Oe(()=>{const t=we.current;we.current=null,h(s)&>(s.height,t)&&s.set({height:t})},!1,!0)},[s,Oe]),Ee=i.useRef(Qt);Ee.current=Qt,i.useEffect(()=>{if(!It){return}if(!ee){return}if(!ct(s)){return void Oe(()=>{h(s)&&(ct(s)||s.set({height:ge}))},void 0,void 0,!0)}if(lt.isPlaying){return}const t=gt(s.height,ge),e=()=>ze(ge);if("change-font-size"!==Ut||Rt||Dt||s.curveEnabled){"resize"===Ut&&t&&!Rt&&e()}else if(Qt&&Qt.fontSize!==s.fontSize){const{fontSize:t,text:e}=Qt;Oe(()=>{if(!h(s)){return}if(Ee.current!==Qt||"change-font-size"!==Y(s)||s._editModeEnabled){return}const r=y(s,t);At||e===s.text||(r.text=e),s.set(r)},!1,!0)}else{t&&e()}}),i.useEffect(()=>()=>{ve.current=!1;const t=ye.current;t.length>0&&(ye.current=[],t.forEach(t=>t()))},[]),i.useLayoutEffect(()=>{if(!It||!s.curveEnabled||Rt){return}if(!me||!me.width){return}const t=t=>t&&Ft?Math.max(t,me.height):me.height,e=t=>X(Vt,{width:t},me.width);Math.abs(e(s.width)-s.width)<1&&Math.abs(t(s.height)-s.height)<1||Oe(()=>{if(!h(s)){return}const r=e(s.width),o=r-s.width,n=t(s.height),i=n-s.height;if(Math.abs(o)<1&&Math.abs(i)<1){return}const a=s.a.rotation*Math.PI/180,l=-o/2*Math.cos(a),c=-o/2*Math.sin(a);s.set({width:r,height:n,x:s.a.x+l,y:s.a.y+c})},!1,!0,!0)},[It,s.curveEnabled,Ut,me,Rt,Ft,Oe]),i.useEffect(()=>u(s,()=>{const t=Mt.current;t&&A(t,s)}),[se,re,s.a.width,s.a.height,ne,s.a.shadowColor,s.a.shadowOffsetX,s.a.shadowOffsetY,s.a.shadowOpacity]);const Se=dt(s,ge),Me=qt||!It||Rt||lt.isPlaying||"resize"!==Ut?s.a.height:Ft?Math.max(s.a.height,ge):ge;let ke=0;qt||"middle"!==s.verticalAlign?qt||"bottom"!==s.verticalAlign||(ke=Se-ge*te):ke=(Se-ge*te)/2;const Re=null!==(vt=null==Kt?void 0:Kt.backgroundPadding)&&void 0!==vt?vt:s.backgroundPadding*(ce*fe*.5),Ye=null!==(jt=null==Kt?void 0:Kt.backgroundCornerRadius)&&void 0!==jt?jt:s.backgroundCornerRadius*(ce*fe*.5),Ce=s.backgroundEnabled||s.borderSize>0,Xe=i.useMemo(()=>!Ce||s.curveEnabled||s.legacyBackground||0===xe.length?"":W({rects:xe,padding:Re,cornerRadius:Ye}),[Ce,s.curveEnabled,s.legacyBackground,xe,Re,Ye]),Pe=i.useRef(null),Fe=i.useRef(s.width),Ie=i.useRef(null),Te=i.useRef(null),Be=i.useRef(""),Ae=i.useRef(0),He=i.useRef(0),$e=i.useRef({fontSize:s.fontSize}),De=s.width>0?s.a.width/s.width:1,Le=De*te,_e=V(s),Je=null!==(Ot=null==Kt?void 0:Kt.shadow)&&void 0!==Ot?Ot:{shadowBlur:_e.shadowBlur*de,shadowOffsetX:_e.shadowOffsetX*de,shadowOffsetY:_e.shadowOffsetY*de},Ne=Object.assign(Object.assign({},Je),{shadowColor:_e.shadowColor,shadowOpacity:_e.shadowOpacity}),Ue=Object.assign(Object.assign({},Ne),{shadowEnabled:_e.shadowEnabled&&Ce});return o(e,{children:[r(at,{element:s,store:lt}),Ce?s.curveEnabled||s.legacyBackground?r(st,Object.assign({as:c,element:s,offsetX:Re/De,offsetY:Re/De,scaleX:Le,scaleY:Le,hideInExport:!s.showInExport,listening:!1,opacity:Lt,fillEnabled:s.backgroundEnabled,fill:et(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:U(s.borderColor),strokeWidth:null!==(zt=null==Kt?void 0:Kt.borderSize)&&void 0!==zt?zt:s.borderSize},Ue,{width:Zt+2*Re,height:(null!==(Et=null==Kt?void 0:Kt.boxHeight)&&void 0!==Et?Et:Se)+2*Re,cornerRadius:Ye})):r(st,Object.assign({as:l,element:s,name:"rendertag-background",offsetY:-ke/Le,scaleX:Le,scaleY:Le,hideInExport:!s.showInExport,listening:!1,visible:Xe.length>0,opacity:Lt,fillEnabled:s.backgroundEnabled,fill:et(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:U(s.borderColor),strokeWidth:null!==(St=null==Kt?void 0:Kt.borderSize)&&void 0!==St?St:s.borderSize,lineJoin:Ye>0?"round":"miter"},Ue,{data:Xe})):null,r(st,Object.assign({as:d,nodeRef:Mt,element:s,selfRectFunc:pe?()=>pe:void 0,name:"rendertag-text",scaleX:Le,scaleY:Le,offsetY:Le>0?-ke/Le:0,width:Zt,height:Math.max(s.height,ge),listening:!1,visible:!Dt&&!!(qt?re:ee),editModeEnabled:Dt,opacity:Lt,shadowEnabled:_e.shadowEnabled&&!tt(s)},Ne,{hideInExport:!s.showInExport,sceneFunc:(t,e)=>{const r=t._context;if(r){try{if(qt){if(!re||!me){return}r.save(),r.translate(be,-me.y),m({layout:re,ctx:r}),r.restore()}else{if(!se){return}g({layout:se,width:Zt,ctx:r,pixelRatio:1,paintTextUnit:le?t=>{const{state:e,slice:r}=le[t.unit.index];(({unit:t,ctx:e,draw:r},{opacity:o,y:n,scale:i,blur:s,from:a,to:l,direction:c,shift:d},u,h)=>{if(!(o<=0||i<=0||l<=a)){if(a>0||l<1||d){const{vertical:r,low:o,high:n,forward:i}=((t,e,r)=>{var o;const n=e?ht[e]:void 0,i="y"===(null==n?void 0:n.axis);let s=i?t.y:t.x,a=s+(i?t.height:t.width);if(i||r){for(const l of t.fragments){s=Math.min(s,i?l.paintTop:l.paintLeft),a=Math.max(a,i?l.paintBottom:l.paintRight)}}return{vertical:i,low:s,high:a,forward:n?n.forward:"rtl"!==(null===(o=t.fragments[0])||void 0===o?void 0:o.direction)}})(t,c,0!==d),s=n-o,[h,f]=i?[a,l]:[1-l,1-a],g=h<=0&&!d?o-u:o+h*s,m=f>=1&&!d?n+u:o+f*s;e.beginPath(),r?e.rect(t.x-u,g,t.width+2*u,m-g):e.rect(g,t.y-u,m-g,t.height+2*u),e.clip();const b=d*s*(i?1:-1);r?e.translate(0,b):e.translate(b,0)}if(e.globalAlpha*=o,n&&e.translate(0,n*u),1!==i){const r=t.x+t.width/2,o=t.y+t.height/2;e.translate(r,o),e.scale(i,i),e.translate(-r,-o)}if(s>0){const t=e.getTransform(),r=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c));e.filter=`blur(${s*u*r}px)`}r({slice:h})}})(t,e,ce,r)}:void 0})}}catch(o){console.error("render-tag draw failed:",o)}}}})),r(st,{as:c,nodeRef:kt,element:s,name:"element",listening:s.selectable,width:s.a.width,height:Me,visible:!Dt,draggable:Pt?s.draggable&&s.isSelected:s.draggable,preventDefault:!Pt||s.isSelected,opacity:0,hideInExport:!0,id:s.id,onDragMove:t=>{s.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{s.set(E(t.target))},onDblClick:t=>{s.contentEditable&&(Te.current={x:t.evt.clientX,y:t.evt.clientY},s.toggleEditMode(!0))},onDblTap:t=>{var e;if(s.contentEditable){const r=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Te.current=r?{x:r.clientX,y:r.clientY}:null,s.toggleEditMode(!0)}},onTransformStart:t=>{Ct.current=s.height,Fe.current=s.width,Ie.current=null,Pe.current=t.target.position(),Be.current=b(t.target),Ae.current=s.a.rotation,He.current=s.height,$e.current={fontSize:s.fontSize,minFontSize:s.minFontSize,maxFontSize:s.maxFontSize},Xt.current=!s.curveEnabled&&["top-left","top-right","bottom-left","bottom-right"].includes(Be.current)?{sized:Qt,width:Jt,boxHeight:Se,backgroundPadding:Re,backgroundCornerRadius:Ye,borderSize:s.borderSize,overhang:ue,shadow:Je}:null,Yt(!0)},onTransform:e=>{const r=e.target,o=Be.current,n="middle-left"===o||"middle-right"===o,i="top-center"===o||"bottom-center"===o,a=M(r.scaleX());if(n){const e=r.width()*a;let o=Math.max(e,S(Fe.current,C(s)));const n=s.toJSON();let i=0;if("fit"===Ut){i=Ct.current}else if(s.curveEnabled){i=_(Object.assign(Object.assign({},n),{width:o}))}else{const{x:e,y:r,width:s,height:a}=n,l=t(n,["x","y","width","height"]),c=`${JSON.stringify(l)}|${Tt}|${It}|${Bt}`;if(Ie.current&&Ie.current.signature===c&&o<=Ie.current.width){o=Ie.current.width,i=Ie.current.height}else{const t=t=>{const e=Object.assign(Object.assign({},n),{width:t});try{return I({element:Object.assign(Object.assign({},e),{text:Ht}),sizing:Object.assign(Object.assign({},Vt),{fit:{mode:"off"},cutAtBox:!1}),layoutAt:Nt(e)}).layout}catch(bt){const r=L(e,$t);return{height:q(r).height,lines:[]}}};let e=t(o);const r=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-ue));r>o+.5&&r<=Fe.current+.5&&(o=Math.min(Math.ceil(r),Fe.current),e=t(o),Ie.current={signature:c,width:o,height:e.height}),i=e.height}}o>e&&Pe.current&&r.position(Pe.current),r.width(o),r.scaleX(1),r.scaleY(1);let l=k.textVerticalResizeEnabled?Math.max(i,Ct.current):i;"ellipsis"!==Ut&&"fit"!==Ut||(l=Ct.current),r.height(l),s.set({width:r.width(),height:l,x:r.x(),y:r.y()})}else if(i){const t="resize"===Ut?qt?(null==me?void 0:me.height)||s.fontSize:ge:fe*("fit"===Vt.fit.mode?Vt.fit.min:s.fontSize),e=r.height()*r.scaleY();if(e<t){if(r.height(t),Pe.current){if("top-center"===Be.current){const e=Ae.current*Math.PI/180,o=He.current-t;r.x(Pe.current.x-o*Math.sin(e)),r.y(Pe.current.y+o*Math.cos(e))}else{r.position(Pe.current)}}}else{r.height(e)}r.scaleY(1),r.scaleX(1),He.current=Math.max(t,e),s.set({x:r.x(),y:r.y(),height:r.height(),rotation:r.rotation()})}else{r.scaleX(1),r.scaleY(1);const t=s.fontSize*a;s.set(Object.assign(Object.assign(Object.assign({},w($e.current,t/$e.current.fontSize)),{letterSpacing:s.letterSpacing,width:r.width()*a,x:r.x(),y:r.y(),rotation:r.rotation(),height:r.height()*a}),O(s,a)))}Pe.current=e.target.position()},onTransformEnd:t=>{Xt.current=null,Yt(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1);const r=v(s,s.fontSize*e),o=$e.current,n=Be.current;s.set(Object.assign(Object.assign(Object.assign({},r),p(n)&&!x(n)?w(o,r.fontSize/o.fontSize,!0):{}),{width:z(t.target.width()*e),x:z(t.target.x()),y:z(t.target.y()),rotation:z(t.target.rotation()),text:nt(s.text,e)}))}}),Dt&&r(st,{as:a,element:s,offsetY:-ke,children:r(f,{divProps:{style:{zIndex:20}},children:r(it,{element:s,fitScale:de,fitScaleFor:t=>qt?de:$(s,Vt,$t,t,de),onChange:t=>{if("fit"===Ut){return void s.set({text:t})}const e=ot({oldText:Z(s.text),newText:Z(t),element:s});s.set(Object.assign({text:t},y(s,e)))},onBlur:()=>{h(s)&&(s.set(j(s)),s.toggleEditMode(!1))},clickCoords:Te.current})})})]})});
|
package/canvas/rich-editor.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Quill from 'quill';
|
|
3
3
|
import { TextElementType } from '../model/text-model.js';
|
|
4
|
+
import type { TableCellType } from '../model/table-model.js';
|
|
4
5
|
import { type LayoutNode, type LayoutText } from 'render-tag';
|
|
5
6
|
import { applyOpacityToColor } from '@polotno/core/svg';
|
|
6
7
|
export { applyOpacityToColor };
|
|
@@ -38,20 +39,22 @@ export declare const createQuill: (node: any, options?: {
|
|
|
38
39
|
placeholder?: string;
|
|
39
40
|
}) => Quill;
|
|
40
41
|
export declare const setQuillContent: (quill: any, html: any) => void;
|
|
41
|
-
export
|
|
42
|
+
export type RichEditorElement = TextElementType | TableCellType;
|
|
43
|
+
export declare const editorHtml: (element: Pick<RichEditorElement, 'text' | 'width' | 'fontSize' | 'fontFamily'>) => string;
|
|
42
44
|
type Point = {
|
|
43
45
|
x: number;
|
|
44
46
|
y: number;
|
|
45
47
|
} | null;
|
|
46
|
-
export declare const RichEditor: ({ onBlur, onChange, element, clickCoords, fitScale, fitScaleFor, }: {
|
|
48
|
+
export declare const RichEditor: ({ onBlur, onChange, element, clickCoords, initialCaret, fitScale, fitScaleFor, }: {
|
|
47
49
|
onBlur: (e?: any) => void;
|
|
48
50
|
onChange: (t: string) => void;
|
|
49
|
-
element:
|
|
51
|
+
element: RichEditorElement;
|
|
50
52
|
clickCoords: Point;
|
|
53
|
+
initialCaret?: 'start' | 'end';
|
|
51
54
|
fitScale?: number;
|
|
52
55
|
fitScaleFor?: (text: string) => number;
|
|
53
56
|
}) => React.JSX.Element;
|
|
54
57
|
export declare function setCursorFromCoords(quill: any, coords: {
|
|
55
58
|
x: number;
|
|
56
59
|
y: number;
|
|
57
|
-
} | null): void;
|
|
60
|
+
} | null, fallbackIndex?: number): void;
|
package/canvas/rich-editor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++){e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(o[n[r]]=t[n[r]])}}return o};import{jsx as e}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{geckoRtlOverhangCss as s,getDir as a,getMeasureCtx as c,getQuillEditorHtml as d,letterSpacingOverhang as u,OVERHANG_PROPERTY as f,textLayoutWidth as p}from"@polotno/core/text-html";import{quillHtmlToModelText as m,isQuillFormatMixed as h,isBoldWeight as g,detachNativeColorsInHtml as b}from"../utils/rich-text-html.js";import{toDisplayColor as v}from"@polotno/core/color";import{resetStyleContent as
|
|
1
|
+
var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++){e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(o[n[r]]=t[n[r]])}}return o};import{jsx as e}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{geckoRtlOverhangCss as s,getDir as a,getMeasureCtx as c,getQuillEditorHtml as d,letterSpacingOverhang as u,OVERHANG_PROPERTY as f,textLayoutWidth as p}from"@polotno/core/text-html";import{quillHtmlToModelText as m,isQuillFormatMixed as h,isBoldWeight as g,detachNativeColorsInHtml as b}from"../utils/rich-text-html.js";import{toDisplayColor as v}from"@polotno/core/color";import{LIST_INDENT_EM as y}from"@polotno/core/css-values";import{resetStyleContent as x,wrapHtmlForRenderTag as w}from"@polotno/core/reset-style";import{layout as S,lineBaselineOffset as k}from"render-tag";import{removeTags as T}from"@polotno/core/text";import{cssFontFamily as q}from"@polotno/core/fonts";import{isGradient as E,firstStopColor as C}from"@polotno/core/gradient";import{getOptimalCaretColor as R}from"./text-element/caret-color.js";import{visiblePlaceholder as F}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as L,PRESERVED_INLINE_STYLES as O,PRESERVED_BLOCK_STYLES as $}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as N,setActiveTextEditor as z,updateActiveTextFormat as j,clearActiveTextEditor as M,getActiveTextEditor as P}from"../utils/text-format-state.js";import D from"../utils/styled.js";import{applyOpacityToColor as H}from"@polotno/core/svg";import{elementDropShadow as A,shadowCastByBackground as I}from"@polotno/core/filters";export{H as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const Q=N;export function syncQuillFormatState(t,e){const o=e?t.getFormat(e):{},n=function(t,e){const o={};if(!e||e.length<=0){return o}const n=t.getContents(e.index,e.length);for(const r of Q){h(n,r)&&(o[r]=!0)}return o}(t,e);r.runInAction(()=>{quillRef.currentFormat=o}),j(o,n,e)}const _="polotno-saved-selection";function W(){const t=window.getSelection();if(!t||0===t.rangeCount||t.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const e=t.getRangeAt(0).cloneRange();CSS.highlights.set(_,new Highlight(e)),X()}function B(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(_)}function X(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(_)&&(document.querySelector(".polotno-portal")||nt(document.activeElement)?X():B())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const rt=document.createElement("style");rt.setAttribute("data-polotno-highlight",""),rt.textContent=`::highlight(${_}) { background-color: Highlight; }`,document.head.appendChild(rt)}export function collectRTText(t,e){"text"===t.type?e.push(t):t.children.forEach(t=>collectRTText(t,e))}export function computeMarkerVars(t){var e,o,n;const r=t.fontSize;if(!r||r<=0){return null}const i=q(t.fontFamily),l=g(t.fontWeight)?700:400,s="italic"===t.fontStyle?"italic":"normal",a=c();a.fontKerning="normal",a.font=`${r}px ${i}`;const d=a.measureText("M"),u=(null!==(e=d.fontBoundingBoxAscent)&&void 0!==e?e:0)/r,f=(null!==(o=d.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,p=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${t.lineHeight};letter-spacing:${t.letterSpacing}em`,m=w(`<div style="${p}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let h;try{h=S({html:m,width:Math.max(12*r,600)})}catch(F){return null}const b=[];collectRTText(h.layoutRoot,b);const v=b.find(t=>"•"===t.text),x=b.find(t=>/^\d/.test(t.text));if(!v){return null}const T=v.style.fontSize,E=v.x,C=v.y-k(T,T*u,T*f),R=y*r;return{bulletLeft:E,bulletTop:C,bulletFontSize:T,numberGap:x?Math.max(0,R-x.x-(null!==(n=x.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=D("div",o.forwardRef)`
|
|
2
2
|
.ql-editor {
|
|
3
3
|
outline: none;
|
|
4
4
|
/* anchor for the absolutely-positioned ::before placeholder below */
|
|
@@ -25,7 +25,7 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
|
|
|
25
25
|
pointer-events: none;
|
|
26
26
|
opacity: 0;
|
|
27
27
|
}
|
|
28
|
-
${
|
|
28
|
+
${x}
|
|
29
29
|
|
|
30
30
|
/* ===== Editor-only list markers (Quill flat-DOM hack) ======================
|
|
31
31
|
Quill emits a FLAT <ol> with per-item data-list + ql-indent classes (not
|
|
@@ -62,7 +62,7 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
|
|
|
62
62
|
}
|
|
63
63
|
.ql-editor li {
|
|
64
64
|
position: relative; /* anchor for the absolutely-positioned ::before */
|
|
65
|
-
padding-inline-start:
|
|
65
|
+
padding-inline-start: ${y}em; /* marker space + per-level indent (start side) */
|
|
66
66
|
}
|
|
67
67
|
.ql-editor li[data-list='ordered'] {
|
|
68
68
|
counter-increment: list-0;
|
|
@@ -89,7 +89,7 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
|
|
|
89
89
|
inset-inline-start: 0;
|
|
90
90
|
top: 0;
|
|
91
91
|
box-sizing: border-box;
|
|
92
|
-
width:
|
|
92
|
+
width: ${y}em;
|
|
93
93
|
text-align: end;
|
|
94
94
|
}
|
|
95
95
|
.ql-editor li[data-list='ordered']::before {
|
|
@@ -166,4 +166,4 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
|
|
|
166
166
|
.ql-editor [style*='background-clip'] {
|
|
167
167
|
-webkit-text-stroke-width: 0;
|
|
168
168
|
}
|
|
169
|
-
`;const
|
|
169
|
+
`;const G=[...O,...$,"header"];let V=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction",...G];export const setQuillFormats=t=>{V=t};let Y=!1;function U(){Y||(Y=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function K(t){return t?"700":"400"}const J=n.import("delta"),Z="data-polotno-rich-text";export const createQuill=(e,o)=>{L();const r=new n(e,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:V});!function(e){const o=e.format.bind(e),n=e.formatText.bind(e),r=e.getFormat.bind(e);e.format=(t,e,n)=>"bold"===t?(U(),o("font-weight",K(e),n)):o(t,e,n),e.formatText=(e,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){U();const{bold:l}=r,s=t(r,["bold"]);return n(e,o,Object.assign(Object.assign({},s),{"font-weight":K(l)}),i)}return n(e,o,r,i)}return"bold"===r?(U(),n(e,o,"font-weight",K(i),l)):n(e,o,r,i,l)},e.getFormat=(...t)=>{const e=r(...t);return e&&null!=e["font-weight"]&&!("bold"in e)&&(e.bold=g(e["font-weight"])),e}}(r);const i=(t,e)=>e.compose((new J).retain(e.length(),{"font-weight":"700"}));r.clipboard.addMatcher("STRONG",i),r.clipboard.addMatcher("B",i);const l=r.clipboard,s=l.onPaste.bind(l);return l.onPaste=(t,e)=>{var o;if(null===(o=e.html)||void 0===o?void 0:o.includes(Z)){return ot(r,()=>s(t,e))}const n=l.convert;l.convert=(...t)=>((t,e)=>{for(const o of t.ops){if(o.attributes){for(const t of e){delete o.attributes[t]}}}return t})(n.apply(l,t),G);try{return s(t,e)}finally{l.convert=n}},r};const tt=(t,e)=>e.insert(t.data),et=(t,e)=>{const o=e.ops[0];return parseFloat(t.style.textIndent)>0&&"string"==typeof(null==o?void 0:o.insert)&&o.insert.startsWith("\t")?e.compose((new J).delete(1)):e};function ot(t,e){const{matchers:o}=t.clipboard,n=o.findIndex(([t])=>t===Node.TEXT_NODE),r=o[n];-1!==n&&(o[n]=[Node.TEXT_NODE,tt]),o.push([Node.ELEMENT_NODE,et]);try{return e()}finally{o.pop(),-1!==n&&(o[n]=r)}}export const setQuillContent=(t,e)=>{const o=ot(t,()=>t.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>",text:""}));t.setContents(o),t.history.clear()};export const editorHtml=t=>d({text:b(t.text),width:t.width,fontSize:t.fontSize,fontFamily:t.fontFamily},t.fontFamily);export const RichEditor=({onBlur:t,onChange:n,element:s,clickCoords:c,initialCaret:d="start",fitScale:h=1,fitScaleFor:g})=>{const b=o.useRef(null),y=o.useRef(!1),x=o.useRef(h);x.current=h;const[w,S]=o.useState(null),k=null!=w?w:h,L=o.useRef(g);L.current=g;const O=t=>({width:p(s.a.width/t,s.letterSpacing,s.fontSize),zoom:1!==t?t:void 0}),$=o.useRef(null),N=o.useRef(void 0),j=()=>`${s.text}\0${s.fontSize}\0${s.fontFamily}`,D=t=>m(t,{fontSize:s.fontSize,fontFamily:s.fontFamily}),H=t=>{setQuillContent(t,editorHtml(s)),$.current=D(t.root.innerHTML),N.current=j()},Q=o.useRef(()=>{}),_=()=>{Q.current(),t()};o.useLayoutEffect(()=>{let t,e,o=!1,i=null,a=null,u=null,f=null,p=null;const m=()=>{if(!o&&b.current){try{t=createQuill(b.current,{placeholder:F(s.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,z({instance:t,store:s.store,element:s});const o=e=>{e&&syncQuillFormatState(t,e)},m=()=>{let e=t.root;if(e.querySelector(".ql-cursor")){e=e.cloneNode(!0);const t=e.querySelector(".ql-cursor");t.replaceWith(t.textContent.replace(/\uFEFF/g,""))}return D(e.innerHTML)},h=()=>{const t=L.current;t&&l(s)&&(t=>{const e=b.current;if(!e){return}const o=O(t);e.style.width=`${o.width}px`,e.style.zoom=void 0===o.zoom?"":String(o.zoom)})(t(m()))},g=()=>{var o,r;if(clearTimeout(e),e=void 0,!l(s)){return}const i=m();if(i===$.current){return}$.current=i,y.current=!0,n(i);const a=t.getContents(),c=s.fill;let d=null,u=!0;for(const t of a.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(o=t.attributes)||void 0===o?void 0:o.gradient){u=!1;break}const e=(null===(r=t.attributes)||void 0===r?void 0:r.color)||c;if(null===d){d=e}else if(e!==d){u=!1;break}}u&&d&&d!==s.fill&&s.set({fill:d})};Q.current=()=>{(void 0!==e||t.composition.isComposing)&&g()},t.on("text-change",()=>{const n=P(),r=n&&n.instance===t?n.lastSelection:null;o(t.getSelection()||r),t.composition.isComposing||h(),void 0===e&&(e=setTimeout(g,10))}),t.on("selection-change",o),t.on("composition-start",()=>S(x.current)),t.on("composition-end",()=>{h(),S(null)}),H(t);const v=b.current.closest(".polotno-workspace-inner"),w=null==v?void 0:v.scrollLeft,k=null==v?void 0:v.scrollTop,T="end"===d?t.getLength()-1:0;c?setCursorFromCoords(t,c,T):t.setSelection(T,0,"api"),v&&void 0!==w&&void 0!==k&&(v.scrollLeft=w,v.scrollTop=k);const q=t.root;f=t=>{const e=t.relatedTarget;(null==e?void 0:e.classList.contains("ql-clipboard"))||(nt(e)||quillRef.pendingToolbarInteraction?W():setTimeout(()=>{quillRef.pendingToolbarInteraction||nt(document.activeElement)?W():(B(),_())},0))},p=()=>{B()},q.addEventListener("blur",f),q.addEventListener("focus",p),i=q,a=e=>{var o,n;const r=t.getSelection();if(!r||0===r.length){return}const i=t.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let s="";if(l&&l.rangeCount>0){const t=l.getRangeAt(0);let e=t.cloneContents(),o=t.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=t.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let t=o;for(;t&&t!==q&&t.nodeType===Node.ELEMENT_NODE;){const o=t.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=t.cloneNode(!1);n.appendChild(e),e=n,t=t.parentNode}}const r=document.createElement("div");r.appendChild(e),s=r.innerHTML}if(null===(o=e.clipboardData)||void 0===o||o.setData("text/plain",i),s){const t=`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div ${Z} style="white-space: pre-wrap; overflow-wrap: break-word;">`+s+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=e.clipboardData)||void 0===n||n.setData("text/html",t)}e.preventDefault()},u=e=>{a&&a(e);const o=t.getSelection();o&&o.length>0&&t.deleteText(o.index,o.length)},i.addEventListener("copy",a),i.addEventListener("cut",u)}catch(m){console.error("RichEditor init failed:",m)}}};return b.current?m():queueMicrotask(m),()=>{o=!0,Q.current(),clearTimeout(e),i&&f&&i.removeEventListener("blur",f),i&&p&&i.removeEventListener("focus",p),B(),i&&a&&u&&(i.removeEventListener("copy",a),i.removeEventListener("cut",u)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),M(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(s,j,t=>{const e=quillRef.editor.instance;if(!e){return}if(y.current){return y.current=!1,void(N.current=t)}if(t===N.current){return}const o=e.getSelection();H(e),o&&(e.setSelection(o.index,o.length),syncQuillFormatState(e,e.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(s,()=>`${s.fontFamily}\0${s.fontSize}\0${s.fontWeight}\0${s.fontStyle}\0${s.lineHeight}\0${s.letterSpacing}\0${a(T(s.text))}`,()=>{const t=b.current;if(!t){return}const e="ltr"===a(T(s.text)),o=computeMarkerVars(s);o&&t.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&e?(t.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),t.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),t.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),t.classList.add("rt-marker-geom")):t.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",_);const t=t=>{var e;const o=t.target;"number"==typeof(null==o?void 0:o.nodeType)&&(null===(e=b.current)||void 0===e?void 0:e.contains(o))||nt(o)||quillRef.pendingToolbarInteraction||(B(),_())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",_),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const X=v(s.fill),G={color:X};X.indexOf("gradient")>=0&&(G["--polotno-gradient"]=X,G.color="transparent"),s.strokeWidth>0&&(G.WebkitTextStroke=`${s.strokeWidth}px ${C(s.stroke)}`,G.paintOrder="stroke fill");const V=E(s.fill)?C(s.fill):R(s),Y=s.shadowEnabled&&!I(s);return e(RichTextContainer,{ref:b,style:Object.assign(Object.assign(Object.assign(Object.assign({},G),{fontSize:s.fontSize,fontFamily:q(s.fontFamily),fontWeight:s.fontWeight,fontStyle:s.fontStyle,"--polotno-text-decoration":s.textDecoration||"none",textTransform:s.textTransform}),O(k)),{[f]:u(s.letterSpacing,s.fontSize)+"px",lineHeight:s.lineHeight,letterSpacing:s.letterSpacing*s.fontSize+"px",textAlign:s.align,opacity:Math.max(s.a.opacity,.2),filter:Y?A({shadowOffsetX:s.shadowOffsetX,shadowOffsetY:s.shadowOffsetY,shadowBlur:s.shadowBlur,shadowColor:s.shadowColor,shadowOpacity:s.shadowOpacity,rotation:s.a.rotation}):void 0,caretColor:V}),dir:a(T(s.text))})};function nt(t){const e=t;return!("function"!=typeof(null==e?void 0:e.closest)||!e.closest(".sketch-picker")&&!e.closest("[data-polotno-keep-focus]")&&!e.closest(".polotno-portal")&&!e.closest(".polotno-toolbar"))}export function setCursorFromCoords(t,e,o=0){if(!t||!e){return}const{x:r,y:i}=e;try{let e=null;if(document.caretRangeFromPoint){e=document.caretRangeFromPoint(r,i)}else if(document.caretPositionFromPoint){const t=document.caretPositionFromPoint(r,i);t&&(e=document.createRange(),e.setStart(t.offsetNode,t.offset))}if(e){const o=n.find(e.startContainer,!0);if(o){const n=o.offset(t.scroll)+e.startOffset;return void t.setSelection(n,0,"api")}}}catch(l){}t.setSelection(o,0,"api")}
|
package/canvas/rules.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as e,jsx as o,jsxs as t}from"react/jsx-runtime";import r from"react";import{getTotalClientRect as i}from"../utils/math.js";import{unitToPx as l}from"../utils/unit.js";import{observer as s}from"mobx-react-lite";import{styled as d}from"../utils/goober.js";import{useWorkspaceStyle as a}from"./workspace-style.js";const n=d("div",r.forwardRef)`
|
|
2
2
|
position: absolute;
|
|
3
3
|
top: 0;
|
|
4
4
|
left: 0;
|
|
@@ -38,4 +38,4 @@ import{jsx as e,jsxs as o,Fragment as t}from"react/jsx-runtime";import r from"re
|
|
|
38
38
|
transform: rotate(90deg);
|
|
39
39
|
transform-origin: left top;
|
|
40
40
|
overflow: hidden;
|
|
41
|
-
`,u=[.1,.2,.5,1,2,5,10,20,25,50,100,200,500,1e3,2e3,5e3,1e4];export const TopRules=s(({store:s,width:d,height:g,pageSizes:f,layout:b="vertical",renderOnlyActivePage:m})=>{const{rulerStyle:y}=a(),v=r.useRef(null);if(!s.activePage){return null}const k="horizontal"===b,w=s.activePage,$=w.computedWidth*s.scale,N=w.computedHeight*s.scale,C=(d-$)/2,S=(g-N)/2,z=(R=e=>l({unitVal:e,dpi:s.dpi,unit:s.unit})*s.scale,u.find(e=>R(e)>30)||1e4);var R;const j=l({unitVal:z,dpi:s.dpi,unit:s.unit})*s.scale,M=Math.round($/j)+1,A=Math.round(N/j)+1,F=i(s.selectedShapes),{backgroundColor:P,textColor:L,borderColor:B,borderSize:D,tickColor:H,tickSize:I}=y;return
|
|
41
|
+
`,u=[.1,.2,.5,1,2,5,10,20,25,50,100,200,500,1e3,2e3,5e3,1e4];export const TopRules=s(({store:s,width:d,height:g,pageSizes:f,layout:b="vertical",renderOnlyActivePage:m})=>{const{rulerStyle:y}=a(),v=r.useRef(null);if(!s.activePage){return null}const k="horizontal"===b,w=s.activePage,$=w.computedWidth*s.scale,N=w.computedHeight*s.scale,C=(d-$)/2,S=(g-N)/2,z=(R=e=>l({unitVal:e,dpi:s.dpi,unit:s.unit})*s.scale,u.find(e=>R(e)>30)||1e4);var R;const j=l({unitVal:z,dpi:s.dpi,unit:s.unit})*s.scale,M=Math.round($/j)+1,A=Math.round(N/j)+1,F=i(s.selectedShapes),{backgroundColor:P,textColor:L,borderColor:B,borderSize:D,tickColor:H,tickSize:I}=y;return o(n,{ref:v,className:"polotno-rulers",style:{display:"flex",flexDirection:"column"},children:t(e,k?{children:[t("div",{style:{display:"flex",flexDirection:"row",position:"sticky",top:0,zIndex:1},children:[o("div",{className:"polotno-ruler-corner",style:{width:"14px",height:"14px",flexShrink:0,marginRight:"-14px",boxSizing:"border-box",backgroundColor:P,borderRight:`${D}px solid ${B}`,borderBottom:`${D}px solid ${B}`,position:"sticky",left:0,zIndex:2}}),(m?[s.activePage]:s.pages).map((e,r)=>{var i;if(!e){return null}const l=f?f[r]:d,a=(l-e.computedWidth*s.scale)/2;return t(p,{style:{width:l+"px",flexShrink:0,position:"relative",backgroundColor:P,color:L,borderBottom:`${D}px solid ${B}`},className:"polotno-x-ruler",children:[[...Array(M)].map((e,t)=>o(h,{className:"polotno-ruler-tick",style:{left:a+t*j+"px",width:j+"px",borderLeft:`${I}px solid ${H}`},children:"px"===s.unit||z>=1?Math.round(z*t):(z*t).toFixed(1)},t)),(null===(i=s.selectedShapes[0])||void 0===i?void 0:i.page)===e&&o("div",{className:"polotno-ruler-selection",style:{position:"absolute",left:a+F.x*s.scale+"px",height:"14px",width:F.width*s.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]},e.id)})]}),t(c,{style:{height:g+"px",position:"sticky",left:0,marginTop:"-14px",backgroundColor:P,color:L,borderRight:`${D}px solid ${B}`},className:"polotno-y-ruler",children:[[...Array(A)].map((e,t)=>o(x,{className:"polotno-ruler-tick",style:{top:S+t*j+"px",width:j+"px",borderLeft:`${I}px solid ${H}`},children:"px"===s.unit||z>=1?Math.round(z*t):(z*t).toFixed(1)},t)),!!s.selectedShapes.length&&o("div",{className:"polotno-ruler-selection",style:{position:"absolute",top:S+F.y*s.scale+"px",width:"14px",height:F.height*s.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]})]}:{children:[t(p,{style:{width:d+"px",backgroundColor:P,color:L,borderBottom:`${D}px solid ${B}`},className:"polotno-x-ruler",children:[[...Array(M)].map((e,t)=>o(h,{className:"polotno-ruler-tick",style:{left:C+t*j+"px",width:j+"px",borderLeft:`${I}px solid ${H}`},children:"px"===s.unit||z>=1?Math.round(z*t):(z*t).toFixed(1)},t)),!!s.selectedShapes.length&&o("div",{className:"polotno-ruler-selection",style:{position:"absolute",left:C+F.x*s.scale+"px",height:"14px",width:F.width*s.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]}),(m?[s.activePage]:s.pages).map((e,r)=>{var i;if(!e){return null}const l=f?f[r]:g,d=(l-e.computedHeight*s.scale)/2,a=0===r?14:0;return t(c,{style:{height:l-a+"px",backgroundColor:P,color:L,borderRight:`${D}px solid ${B}`},className:"polotno-y-ruler",children:[[...Array(A)].map((e,t)=>o(x,{className:"polotno-ruler-tick",style:{top:d+t*j-a+"px",width:j+"px",borderLeft:`${I}px solid ${H}`},children:"px"===s.unit||z>=1?Math.round(z*t):(z*t).toFixed(1)},t)),(null===(i=s.selectedShapes[0])||void 0===i?void 0:i.page)===e&&o("div",{className:"polotno-ruler-selection",style:{position:"absolute",top:d+F.y*s.scale-a+"px",width:"14px",height:F.height*s.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]},e.id)})]})})});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StoreType } from '../model/store.js';
|
|
3
|
+
import type { TableCellType, TableElementType } from '../model/table-model.js';
|
|
4
|
+
export declare const TableCellText: (({ cell, table, store, }: {
|
|
5
|
+
cell: TableCellType;
|
|
6
|
+
table: TableElementType;
|
|
7
|
+
store: StoreType;
|
|
8
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
9
|
+
cell: TableCellType;
|
|
10
|
+
table: TableElementType;
|
|
11
|
+
store: StoreType;
|
|
12
|
+
}> & {
|
|
13
|
+
readonly type: ({ cell, table, store, }: {
|
|
14
|
+
cell: TableCellType;
|
|
15
|
+
table: TableElementType;
|
|
16
|
+
store: StoreType;
|
|
17
|
+
}) => React.JSX.Element;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as t,jsx as e,jsxs as o}from"react/jsx-runtime";import i from"react";import{observer as r}from"mobx-react-lite";import{isAlive as l}from"mobx-state-tree";import{Group as n,Shape as a}from"react-konva";import{Html as m}from"react-konva-utils";import{drawLayout as s}from"render-tag";import{tableCellTextElement as d}from"@polotno/core/table";import{getHtml as c}from"@polotno/core/text-html";import{layoutTextSizing as f,renderTagLayoutAt as u}from"@polotno/core/text-sizing";import{verticalTextOffset as p}from"@polotno/core/text-types";import{editorTextSizing as x,textOverflowOf as h}from"../utils/text-sizing.js";import{getLineHeight as y}from"./text-element.js";import{liveFitScale as g,useRenderTagSource as v}from"./text-element/render-tag-source.js";import{withDisplayTextPaints as b}from"./use-color.js";import{useFadeIn as j}from"./use-fadein.js";import{RichEditor as C}from"./rich-editor.js";export const TableCellText=r(({cell:r,table:w,store:z})=>{var F,S,k;const H=i.useRef(null),{fontLoaded:M,getHtmlOptions:E}=v(r,z),L=r._editModeEnabled;j(H);const O=d(r,r.a),R=x(O),T=h(O),_=c(b(O),E),B=i.useMemo(()=>{try{return f({element:O,sizing:R,layoutAt:u(b(O),{getHtmlOptions:E})})}catch(t){return console.error("render-tag layout failed:",t),null}},[_,O.width,"fixed"===R.box?O.height:0,JSON.stringify(R),M]),D=null!==(F=null==B?void 0:B.fontSize)&&void 0!==F?F:O.fontSize,A=null!==(S=null==B?void 0:B.scale)&&void 0!==S?S:1,I=Math.max(null!==(k=null==B?void 0:B.height)&&void 0!==k?k:0,D*y({fontLoaded:M,fontFamily:O.fontFamily,fontSize:D,lineHeight:O.lineHeight})),J=p(O,I);i.useLayoutEffect(()=>{M&&B&&"resize"===T&&l(r)&&w.setCellContentHeight(r.id,I)});const K=null==B?void 0:B.layout.paintBounds,N=L?w._editClickCoords:null;return o(t,{children:[e(a,{ref:H,name:"table-cell-text",x:O.x,y:O.y+J,width:O.width||1,height:I,selfRectFunc:K?()=>K:void 0,listening:!1,visible:!L&&!!B,editModeEnabled:L,opacity:O.opacity,sceneFunc:t=>{const e=t._context;if(e&&B){try{s({layout:B.layout,width:O.width||1,ctx:e,pixelRatio:1})}catch(o){console.error("render-tag draw failed:",o)}}}}),L&&e(n,{name:"table-cell-editor",x:O.x,y:O.y+J,children:e(m,{divProps:{style:{zIndex:20}},children:e("div",{onKeyDownCapture:t=>{"Tab"===t.key&&t.preventDefault()},children:e(C,{element:r,fitScale:A,fitScaleFor:t=>g(O,R,E,t,A),clickCoords:N,initialCaret:"end",onChange:t=>r.set({text:t}),onBlur:()=>{l(r)&&r.toggleEditMode(!1)}})})})})]})});
|