polotno 3.19.1 → 3.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +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-lib.d.ts +1 -1
- package/utils/html2canvas.js +1 -1
- package/utils/image-dpi.d.ts +1 -1
- package/utils/image-dpi.js +1 -1
- package/utils/insert-file.js +1 -1
- package/utils/l10n.d.ts +1 -0
- package/utils/l10n.js +1 -1
- package/utils/lottie.d.ts +12 -0
- package/utils/lottie.js +1 -0
- package/utils/math.d.ts +4 -4
- package/utils/px.d.ts +3 -0
- package/utils/px.js +1 -1
- package/utils/react-color/components/common/Checkboard.d.ts +12 -12
- package/utils/react-color/components/common/Swatch.d.ts +6 -6
- package/utils/react-color/helpers/interaction.d.ts +6 -6
- package/utils/reactcss/components/active.d.ts +6 -6
- package/utils/reactcss/components/hover.d.ts +6 -6
- package/utils/rich-text-html.js +1 -1
- package/utils/selection-colors.js +1 -1
- package/utils/selection-transform.d.ts +4 -4
- package/utils/selection-transform.js +1 -1
- package/utils/split-element.js +1 -1
- package/utils/text-format-state.d.ts +1 -0
- package/utils/text-format-state.js +1 -1
- package/utils/text-format.d.ts +2 -2
- package/utils/text-sizing.d.ts +1 -1
- package/utils/timeline.d.ts +30 -2
- package/utils/timeline.js +1 -1
- package/utils/to-html.js +1 -1
- package/utils/to-svg.js +1 -1
- package/utils/validate-key.js +1 -1
- package/canvas/downscale-bands.d.ts +0 -10
- package/canvas/downscale-bands.js +0 -1
- package/canvas/downscale-kernel.d.ts +0 -7
- package/canvas/downscale-kernel.js +0 -1
- package/canvas/downscale-kernel.wasm.d.ts +0 -1
- package/canvas/downscale-kernel.wasm.js +0 -1
- package/canvas/downscale-passes.d.ts +0 -7
- package/canvas/downscale-passes.js +0 -1
package/canvas/apply-filters.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{isAlive as e}from"mobx-state-tree";import{applyFiltersToCanvas as t,getFilterAttrs as r}from"@polotno/core/filters";import{hasPixelFilters as i}from"@polotno/core/pixel-filters";export{getEffectiveBlurRadius,getElementBlurRadius}from"@polotno/core/filters";export function getFilterAttrs(e,t={enabled:e.blurEnabled,radius:e.blurRadius}){return r(e,e.filters.entries(),t)}export function hasActiveFilters(e){return i(e,e.filters.keys())}export function applyFiltersToCanvas(r,i){e(i)&&t(r,i,i.filters.entries())}export function getFiltersDepsKey(t){if(!e(t)){return""}const r=[];return t.filters.forEach((e,t)=>{r.push(t+":"+e.intensity)}),[t.brightnessEnabled&&t.brightness,t.blurEnabled&&t.blurRadius,t.sepiaEnabled,t.grayscaleEnabled,...r].join("|")}export function applyFilter(t,r){var i;if(!t||!e(r)){return}const s={enabled:r.a.blurEnabled,radius:r.a.blurRadius},l=getFilterAttrs(r,s),n={};s.enabled&&"text"===r.type&&r.lineHeight<1&&(n.offset=r.fontSize),t.setAttrs(l),l.filters.length?t.cache(Object.assign(Object.assign({},n),{pixelRatio:r.store._elementsPixelRatio})):t.clearCache(),null===(i=t.getLayer())||void 0===i||i.batchDraw()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as e,jsx as o,jsxs as n}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{PolotnoIcon as l}from"../../icons/registry.js";import{t as r}from"../../utils/l10n.js";import{useDuplicateElement as a}from"../../toolbar/use-duplicate-element.js";import{useRemoveElement as i}from"../../toolbar/use-remove-element.js";import{useLock as s}from"../../toolbar/use-lock.js";import{ContextMenu as c}from"@base-ui/react/context-menu";import{DropdownMenuContent as d,DropdownMenuItem as m,DropdownMenuSeparator as u,DropdownMenuSub as h,DropdownMenuSubContent as p,DropdownMenuSubTrigger as v}from"../../primitives/dropdown-menu.js";export const ContextMenu=t(({store:t,isOpen:b,offset:w,setIsOpen:f})=>{var x;const{disabled:y,duplicate:E}=a({store:t}),{disabled:C,remove:R}=i({store:t}),{disabled:g,lock:S,locked:M}=s({store:t}),j=o(l,M?{name:"action.lock"}:{name:"action.unlock"});if(0===t.selectedElements.length){return null}const k={getBoundingClientRect:()=>({x:w.x,y:w.y,width:0,height:0,top:w.y,left:w.x,right:w.x,bottom:w.y,toJSON(){}})};return o(c.Root,{open:b,onOpenChange:e=>{e||f(!1)},children:n(d,{align:"start",anchor:k,className:"polotno-context-menu",children:[n(m,{onSelect:e=>{e.preventDefault(),S()},disabled:g,children:[j,o("span",{children:r(M?"contextMenu.unlock":"contextMenu.lock")})]}),n(m,{onSelect:()=>{E()},disabled:y,children:[o(l,{name:"action.duplicate"}),o("span",{children:r("contextMenu.duplicate")})]}),n(m,{onSelect:()=>{R()},disabled:C,children:[o(l,{name:"action.remove"}),o("span",{children:r("contextMenu.remove")})]}),o(u,{}),n(h,{children:[n(v,{children:[o(l,{name:"layering.menu"}),o("span",{children:r("toolbar.layering")})]}),n(p,{className:"polotno-context-menu",children:[n(m,{onSelect:e=>{e.preventDefault(),t.selectedElements.forEach(e=>e.moveTop())},disabled:!t.selectedElements.some(e=>{var o;return null===(o=e.parent)||void 0===o?void 0:o.canMoveElementsTop([e.id])}),children:[o(l,{name:"layering.top"}),o("span",{children:r("toolbar.toForward")})]}),n(m,{onSelect:e=>{e.preventDefault(),t.selectedElements.forEach(e=>e.moveUp())},disabled:!t.selectedElements.some(e=>{var o;return null===(o=e.parent)||void 0===o?void 0:o.canMoveElementsUp([e.id])}),children:[o(l,{name:"layering.up"}),o("span",{children:r("toolbar.up")})]}),n(m,{onSelect:e=>{e.preventDefault(),t.selectedElements.forEach(e=>e.moveDown())},disabled:!t.selectedElements.some(e=>{var o;return null===(o=e.parent)||void 0===o?void 0:o.canMoveElementsDown([e.id])}),children:[o(l,{name:"layering.down"}),o("span",{children:r("toolbar.down")})]}),n(m,{onSelect:e=>{e.preventDefault(),t.selectedElements.forEach(e=>e.moveBottom())},disabled:!t.selectedElements.some(e=>{var o;return null===(o=e.parent)||void 0===o?void 0:o.canMoveElementsBottom([e.id])}),children:[o(l,{name:"layering.bottom"}),o("span",{children:r("toolbar.toBottom")})]})]})]}),"table"===(null===(x=t.selectedElements[0])||void 0===x?void 0:x.type)&&(()=>{var l;const a=t.selectedElements[0],i=a.focusedCells[0],s=null!=i,c=null!==(l=a.getFocusedCellRange())&&void 0!==l?l:i?{minRow:i.row,maxRow:i.row,minCol:i.col,maxCol:i.col}:{minRow:0,maxRow:0,minCol:0,maxCol:0},{minRow:d,maxRow:h,minCol:p,maxCol:v}=c,b=h>d,w=v>p;return n(e,{children:[s&&n(e,{children:[o(u,{}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.addRow(d)})},children:o("span",{children:r("toolbar.insertRowAbove")})}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.addRow(h+1)})},children:o("span",{children:r("toolbar.insertRowBelow")})}),o(m,{disabled:a.rows<=h-d+1,onSelect:()=>{t.history.transaction(()=>{a.removeRowRange(d,h)})},children:o("span",{children:r(b?"toolbar.deleteRows":"toolbar.deleteRow")})}),o(u,{}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.addColumn(p)})},children:o("span",{children:r("toolbar.insertColumnLeft")})}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.addColumn(v+1)})},children:o("span",{children:r("toolbar.insertColumnRight")})}),o(m,{disabled:a.cols<=v-p+1,onSelect:()=>{t.history.transaction(()=>{a.removeColumnRange(p,v)})},children:o("span",{children:r(w?"toolbar.deleteColumns":"toolbar.deleteColumn")})})]}),o(u,{}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.distributeRowsEvenly()})},children:o("span",{children:r("toolbar.distributeRowsEvenly")})}),o(m,{onSelect:()=>{t.history.transaction(()=>{a.distributeColumnsEvenly()})},children:o("span",{children:r("toolbar.distributeColumnsEvenly")})})]})})()]})})});
|
package/canvas/crop-overlay.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface CropHost {
|
|
|
13
13
|
type CropWrite = (props: Record<string, number>) => void;
|
|
14
14
|
export declare const cropDraftWriter: (target: {
|
|
15
15
|
id: string;
|
|
16
|
-
}, store: Pick<StoreType,
|
|
16
|
+
}, store: Pick<StoreType, 'activeTool'>) => CropWrite;
|
|
17
17
|
export declare const commitCropSource: (e: Konva.KonvaEventObject<Event>, element: CropHost, write: CropWrite, sourceWidth: number, sourceHeight: number, windowWidth: number, windowHeight: number) => void;
|
|
18
18
|
interface CropOverlayElement extends CropHost {
|
|
19
19
|
readonly id: string;
|
package/canvas/crop-overlay.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as o,jsx as t,jsxs as e}from"react/jsx-runtime";import r from"react";import{observer as i}from"mobx-react-lite";import{Group as n,Image as a,Line as c,Rect as l,Transformer as s}from"react-konva";import{Portal as d}from"react-konva-utils";import{useWorkspaceStyle as h}from"./workspace-style.js";import{cropBoundBoxFunc as m}from"./transform-box.js";import{clamp as u}from"../lib/utils.js";import{RectControl as p}from"./rect-control.js";import{ParentFrame as g}from"./parent-frame.js";import{frameBox as f,relativeRect as v}from"../image-tools/geometry.js";import{sessionControls as x}from"../image-tools/sessions.js";export const CROP_CORNER_ANCHORS=["top-left","top-right","bottom-left","bottom-right"];const b={enabledAnchors:CROP_CORNER_ANCHORS,rotateEnabled:!1,borderEnabled:!1},y=({width:e,height:r})=>{const{cropGridStyle:i}=h();return i&&e>0&&r>0?t(o,{children:[[e/3,0,e/3,r],[2*e/3,0,2*e/3,r],[0,r/3,e,r/3],[0,2*r/3,e,2*r/3]].map((o,e)=>t(c,Object.assign({},i,{points:o,strokeScaleEnabled:!1,listening:!1}),e))}):null};export const cropDraftWriter=(o,t)=>{const e=t.activeTool;return r=>{"crop"===(null==e?void 0:e.name)&&e.elementId===o.id&&t.activeTool===e&&x(e).setDraft(r)}};export const commitCropSource=(o,t,e,r,i,n,a)=>{const c=o.target;Math.round(c.x())>0&&(c.x(0),c.scaleX(1)),Math.round(c.y())>0&&(c.y(0),c.scaleY(1));const l=c.width()*c.scaleX(),s=c.height()*c.scaleY(),d=Math.min(1,n/l),h=Math.min(1,a/s),m=u(-c.x()/l,0,1-d),p=u(-c.y()/s,0,1-h);c.setAttrs({x:-m*r,y:-p*i,scaleX:1,scaleY:1}),e({cropX:m,cropY:p,cropWidth:d,cropHeight:h})};export const CropOverlay=i(({element:o,store:i,previewImage:c,sourceImage:u,sourceWidth:x,sourceHeight:w,cropAbsoluteWidth:j,cropAbsoluteHeight:E,innerAnchors:O,onSourceTouchMove:C,onSourceTouchEnd:R})=>{var S,M,T,I,A,X;const Y=h(),H=r.useRef(null),W=r.useRef(null),k=r.useRef(null),D=i.activeTool,B="crop"===(null==D?void 0:D.name)&&D.pending,F=cropDraftWriter(o,i);r.useLayoutEffect(()=>{k.current.nodes([H.current])},[]),r.useEffect(()=>{var t;const e=null===(t=H.current)||void 0===t?void 0:t.getStage(),r=t=>{B||t.target.findAncestor(".image-tool-controls",!0)||o.toggleCropMode(!1)};return null==e||e.on("click",r),null==e||e.on("tap",r),()=>{null==e||e.off("click",r),null==e||e.off("tap",r)}},[o,B]);const N=o=>{var t;B||(C&&(null===(t=o.evt.touches)||void 0===t?void 0:t.length)>2&&o.target.stopDrag(),commitCropSource(o,0,F,x,w,j,E))},_={x:0,y:0,width:j,height:E},P=o.a.width/j,z=o.a.height/E,G=Math.max(window.innerWidth,window.innerHeight,null!==(A=null===(M=null===(S=H.current)||void 0===S?void 0:S.getStage())||void 0===M?void 0:M.width())&&void 0!==A?A:0,null!==(X=null===(I=null===(T=H.current)||void 0===T?void 0:T.getStage())||void 0===I?void 0:I.height())&&void 0!==X?X:0)/i.scale;return t(d,{selector:".page-abs-container",enabled:!0,children:e(g,{elementId:o.id,children:[t(l,{name:"image-tool-dim",hideInExport:!0,x:-G,y:-G,width:3*G,height:3*G,fill:Y.cropOverlayFill}),t(a,{hideInExport:!0,listening:!1,image:c,x:o.a.x,y:o.a.y,width:o.a.width,height:o.a.height,rotation:o.a.rotation,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur}),e(n,{name:"image-tool-controls",hideInExport:!0,x:o.a.x,y:o.a.y,rotation:o.a.rotation,scaleX:P,scaleY:z,children:[t(a,{ref:H,image:u,width:x,height:w,opacity:.4,draggable:!B,x:-o.cropX*x,y:-o.cropY*w,onDragMove:N,onTransform:N,onTouchMove:B?void 0:C,onTouchEnd:B?void 0:R}),t(s,Object.assign({ref:k},b,Y.outerImageCropTransformerStyle,{visible:!B,boundBoxFunc:m(H,W,"cover",Y.outerImageCropTransformerStyle.boundBoxFunc)})),t(p,{crop:!0,nodeRef:W,fixedRef:H,rect:_,disabled:!o.resizable||B,anchors:O,onChange:t=>{var e;const r=o.cropX+t.x/x,i=o.cropY+t.y/w,n=f(Object.assign(Object.assign({},o),{rotation:o.a.rotation}),v(t,_));null===(e=W.current)||void 0===e||e.position({x:0,y:0}),F(Object.assign(Object.assign({},n),{cropX:r,cropY:i,cropWidth:Math.min(t.width/x,1-r),cropHeight:Math.min(t.height/w,1-i)}))}}),t(y,{width:j,height:E})]})]})})});
|
package/canvas/downscale.d.ts
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
type
|
|
2
|
-
export declare function sourceSize(image: DownscaleSource): {
|
|
3
|
-
width: number;
|
|
4
|
-
height: number;
|
|
5
|
-
};
|
|
6
|
-
export declare const RESAMPLE_PIXEL_BUDGET = 16000000;
|
|
7
|
-
export declare function shouldResample(ratio: number, deviceWidth: number, deviceHeight: number): boolean;
|
|
1
|
+
export { BAND_ROWS, drawReduced, forceDownscaleEngine, loadDownscaleKernel, planBands, setDownscaleBandRows, resampleCanvas, shouldResample, sourceSize, RESAMPLE_PIXEL_BUDGET, type AxisFilter, type DownscaleEngine, type SourceRegion, } from '@polotno/core/downscale';
|
|
8
2
|
export declare function exportKernelEnabled(page: {
|
|
9
3
|
_exporting?: boolean;
|
|
10
4
|
_rendering?: boolean;
|
|
11
5
|
} | undefined): boolean;
|
|
12
|
-
export interface AxisFilter {
|
|
13
|
-
starts: Int32Array;
|
|
14
|
-
counts: Int32Array;
|
|
15
|
-
weights: Float32Array;
|
|
16
|
-
maxTaps: number;
|
|
17
|
-
}
|
|
18
|
-
export type DownscaleEngine = 'wasm' | 'js';
|
|
19
|
-
export declare function forceDownscaleEngine(engine?: DownscaleEngine | 'refused'): void;
|
|
20
|
-
export interface SourceRegion {
|
|
21
|
-
x: number;
|
|
22
|
-
y: number;
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
}
|
|
26
|
-
export declare function resampleCanvas(image: DownscaleSource, region: SourceRegion, destWidth: number, destHeight: number, dest?: SourceRegion): HTMLCanvasElement | undefined;
|
|
27
|
-
export declare function drawReduced(ctx: CanvasRenderingContext2D, image: DownscaleSource, crop: SourceRegion, width: number, height: number, dest?: SourceRegion): void;
|
|
28
|
-
export {};
|
package/canvas/downscale.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{flags as e}from"../utils/flags.js";export{BAND_ROWS,drawReduced,forceDownscaleEngine,loadDownscaleKernel,planBands,setDownscaleBandRows,resampleCanvas,shouldResample,sourceSize,RESAMPLE_PIXEL_BUDGET}from"@polotno/core/downscale";export function exportKernelEnabled(n){return Boolean(null==n?void 0:n._exporting)&&!(null==n?void 0:n._rendering)&&e.imageDownScalingEnabled}
|
package/canvas/element.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ type ShapeProps = {
|
|
|
6
6
|
element: ShapeType;
|
|
7
7
|
onClick: Function;
|
|
8
8
|
};
|
|
9
|
-
export declare function registerShapeComponent(type: string, component: React.ComponentType<ShapeProps>
|
|
9
|
+
export declare function registerShapeComponent<T extends ShapeType = ShapeType>(type: string, component: React.ComponentType<Omit<ShapeProps, 'element'> & {
|
|
10
|
+
element: T;
|
|
11
|
+
}>): void;
|
|
10
12
|
declare const Element: ((props: ShapeProps) => React.JSX.Element | null) & React.NamedExoticComponent<ShapeProps> & {
|
|
11
13
|
readonly type: (props: ShapeProps) => React.JSX.Element | null;
|
|
12
14
|
};
|
package/canvas/element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as e,jsx as t,jsxs as o}from"react/jsx-runtime";import{createElement as r}from"react";import n from"react";import{observer as i}from"mobx-react-lite";import{ROLES as s}from"../model/store.js";import l from"konva";import{MAIN_TRANSFORMER_NAME as a}from"../utils/px.js";import{TextElement as m}from"./text-element.js";import{ImageElement as d}from"./image-element.js";import{HTMLElement as c}from"./html-element.js";import{RenderTagElement as f}from"./render-tag-element.js";import{LineElement as p}from"./line-element.js";import{VideoElement as u}from"./video-element.js";import{FigureElement as g}from"./figure-element.js";import{GifElement as v}from"./gif-element.js";import{LottieElement as h}from"./lottie-element.js";import{TableElement as x}from"./table-element.js";import{Group as y}from"react-konva";import{Highlighter as b}from"./highlighter.js";import{PlacedNode as j}from"./placed-node.js";import{forEveryChild as w}from"../model/group-model.js";import{flags as E}from"../utils/flags.js";import{blendModeOf as T,isIsolatedGroup as M}from"@polotno/core/page";const R={text:m,image:d,svg:d,line:p,video:u,figure:g,group:i(e=>{var o;const{element:n,store:i}=e,l=n,{children:a}=l,m=n.selectable||i.role===s.ADMIN,d=l.a;return t(j,{as:y,element:l,offsetX:d.offsetX,offsetY:d.offsetY,scaleX:d.scaleX,scaleY:d.scaleY,opacity:d.opacity,isolated:M(l),globalCompositeOperation:null!==(o=T(l))&&void 0!==o?o:"source-over",listening:m,hideInExport:!n.showInExport,id:n.id,clipFunc:d.wipe&&l._restingBbox?C(l._restingBbox,d.wipe):void 0,children:a.map(t=>r(X,Object.assign({},e,{key:t.id,store:i,element:t})))})}),gif:v,lottie:h,table:x};export function registerShapeComponent(e,t){R[e]=t}const S=(e,t)=>{const o=[];w(e,e=>{"group"!==e.type&&o.push(e.a)});const r=[];o.forEach(e=>{const t=[{x:0,y:0},{x:0+e.width,y:0},{x:0+e.width,y:0+e.height},{x:0,y:0+e.height}],o=new l.Transform;o.translate(e.x,e.y),o.rotate(l.Util.degToRad(e.rotation)),t.forEach(e=>{const t=o.point(e);r.push(t)})});const n=new l.Transform;n.rotate(-l.Util.degToRad(t));let i=1/0,s=1/0,a=-1/0,m=-1/0;r.forEach(e=>{const t=n.point(e);i=Math.min(i,t.x),s=Math.min(s,t.y),a=Math.max(a,t.x),m=Math.max(m,t.y)}),n.invert();const d=n.point({x:i,y:s});return{x:d.x,y:d.y,width:a-i,height:m-s,rotation:t}},I=".polotnoElementHover",O=new WeakMap;const k=1e6,C=(e,t)=>o=>{var r;const n="x"===t.axis?e.width:e.height,i=t.from<=0?-k:t.from*n,s=t.to>=1?k:t.to*n,[a,m,d,c]="x"===t.axis?[i,s,-k,k]:[-k,k,i,s];o.save(),o.translate(e.x,e.y),o.rotate(l.Util.degToRad(null!==(r=e.rotation)&&void 0!==r?r:0)),o.rect(a,d,m-a,c-d),o.restore()},U=(e,t)=>{const o=l.Util.degToRad(e.rotation);return(new l.Transform).translate(e.x,e.y).rotate(o).translate(e.width/2,0).scale(t,1).translate(-e.width/2,0).rotate(-o).translate(-e.x,-e.y).decompose()},X=i(r=>{var i,s;const{element:l,store:m}=r,[d,p]=n.useState(!1),u="group"===(null===(i=l.parent)||void 0===i?void 0:i.type),g="group"!==l.type||u?null:m.selectedElements,v=!!g&&1===g.length&&g[0]!==l&&g[0].top===l,[h,x]=n.useState(!1),j=n.useRef(null),w=l.visible,M=()=>{var e,t;return null!==(t=null===(e=j.current)||void 0===e?void 0:e.getStage())&&void 0!==t?t:null},k=n.useRef(void 0),X=()=>{var e;return k.current||(k.current=null===(e=M())||void 0===e?void 0:e.findOne(`.${a}`)),k.current};n.useEffect(()=>{const e=M();if(!e){return}const t=function(e,t,o,r){var n;const{subscribers:i}=function(e,t){const o=O.get(e);if(o){return o}const r={subscribers:new Map},n=e=>{var t,o;const n=r.hoveredId;r.hoveredId=e,n&&n!==e&&(null===(t=r.subscribers.get(n))||void 0===t||t.forEach(e=>e(!1))),e&&(null===(o=r.subscribers.get(e))||void 0===o||o.forEach(e=>e(!0)))};return e.on(`mouseover${I}`,e=>{var o,r;const i=e.target.findAncestor(".element",!0);n(null===(r=null===(o=t.getElementById(null==i?void 0:i.id()))||void 0===o?void 0:o.top)||void 0===r?void 0:r.id)}),e.on(`mouseleave${I}`,()=>n(void 0)),O.set(e,r),r}(e,t),s=null!==(n=i.get(o))&&void 0!==n?n:new Set;return i.set(o,s),s.add(r),()=>{s.delete(r),s.size||(i.delete(o),i.size||(e.off(I),O.delete(e)))}}(e,m,l.id,p);return()=>{t(),p(!1)}},[w,l.id]),n.useEffect(()=>{if(!v){return}const e=M(),t=X();if(!e||!t){return}x(!1);const o=()=>x(!0),r=()=>x(!1);return e.on("dragstart",o),e.on("dragend",r),t.on("transformstart",o),t.on("transformend",r),()=>{e.off("dragstart",o),e.off("dragend",r),t.off("transformstart",o),t.off("transformend",r)}},[w,v]);let Y=R[r.element.type];if("text"===r.element.type&&(E.renderTagTextEnabled?Y=f:E.htmlRenderEnabled&&(Y=c)),!w){return null}if(!Y){return console.error("Can not find component for "+r.element.type),null}const B="group"===l.type?void 0:T(l),F="group"===l.type?null:l.a,$=null==F?void 0:F.wipe,z=null==F?void 0:F.flipScale;return o(e,{children:[t(y,Object.assign({name:"element-container",ref:j,visible:l.active,listening:l.active,isolated:!!B,opacity:B?l.a.opacity:1,globalCompositeOperation:null!=B?B:"source-over",clipFunc:$?C(F,$):void 0},void 0===z?null:U(F,z),{children:t(Y,Object.assign({},r))})),((d||v)&&!u||l.isHighlighted)&&l.active&&!l.isSelectedDirectly&&!h&&t(b,{element:"group"===l.type?{a:S(l,v?"rotation"in g[0]?g[0].rotation:0:d&&(null===(s=X())||void 0===s?void 0:s.rotation())||0)}:l})]})});export default X;
|
package/canvas/fade-overlay.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as t,jsx as e,jsxs as n}from"react/jsx-runtime";import r from"react";import{observer as s}from"mobx-react-lite";import{Circle as i,Ellipse as a,Group as o,Line as l,Rect as c}from"react-konva";import{ROLES as d}from"../model/store.js";import{fadeStopColor as u,insertFadeStop as f}from"../utils/fade-gradient.js";import{moveStop as p,safe01 as g}from"../utils/stops.js";import{getFadeStopFocus as v,getSelectedFadeStop as m,setSelectedFadeStop as x}from"../utils/fade-overlay.js";import{useWorkspaceStyle as y}from"./workspace-style.js";import{t as h}from"../utils/l10n.js";import{readClipFade as b,writeClipFade as j}from"../utils/clip-fade.js";import{isAlive as S}from"mobx-state-tree";export const FadeOverlay=s(({store:s,pageId:M})=>{var O,k,E;const w=1===s.selectedElements.length?s.selectedElements[0]:null;let D=!!w;for(let t=w;t;t="group"===(null===(O=t.parent)||void 0===O?void 0:O.type)?t.parent:null){D=D&&t.visible&&t.active}const R=!D||s.role===d.VIEWER||s.isPlaying||(null===(k=null==w?void 0:w.page)||void 0===k?void 0:k.id)!==M||!("clipSrc"in w)||"_cropModeEnabled"in w&&w._cropModeEnabled?null:b(w.clipSrc),F=!!R,P=null==R?void 0:R.fade,A=Math.min(m(s),(null!==(E=null==P?void 0:P.stops.length)&&void 0!==E?E:1)-1),L=t=>{w&&R&&S(w)&&w.set({clipSrc:j(t,R.baseSrc)})},T=t=>{var e,n;x(s,t);const r=v(s);(null==r?void 0:r.elementId)===(null==w?void 0:w.id)&&(null==r?void 0:r.onSelectStop(t))||null===(n=null===(e=W.current)||void 0===e?void 0:e.getStage())||void 0===n||n.container().focus({preventScroll:!0})},{transformerStyle:I}=y(),W=r.useRef(null),z=r.useRef(null),B=r.useRef(!1),V=r.useRef(!1),X=r.useRef(null);if(r.useLayoutEffect(()=>{const t=W.current,e=null==t?void 0:t.getLayer();if(!t||!e||!w){return}const n=w.id,r=()=>{var e;const r=null===(e=t.getStage())||void 0===e?void 0:e.findOne("#"+n),s=t.getParent(),i=!!(null==r?void 0:r.isVisible());if(t.visible(i),!r||!s||!i){return}const a=s.getAbsoluteTransform().copy().invert();a.multiply(r.getAbsoluteTransform()),t.setAttrs(a.decompose())};return r(),e.on("beforeDraw",r),()=>{e.off("beforeDraw",r)}}),r.useLayoutEffect(()=>{var t,e,n;B.current||!F&&!V.current||(V.current=F,z.current=null!==(n=null===(t=W.current)||void 0===t?void 0:t.getLayer())&&void 0!==n?n:z.current,null===(e=z.current)||void 0===e||e.drawHit())}),r.useEffect(()=>{var t,e;if(!F){return}const n=null===(e=null===(t=W.current)||void 0===t?void 0:t.getStage())||void 0===e?void 0:e.container();if(!n){return}const r=n.getAttribute("tabindex");n.tabIndex=-1;const i=t=>{if(document.activeElement!==n||!["Delete","Backspace"].includes(t.key)){return}if(t.preventDefault(),t.stopPropagation(),!w||!S(w)||!("clipSrc"in w)){return}const e=b(w.clipSrc);if(!e||e.fade.stops.length<=2){return}const r=m(s);s.history.transaction(()=>w.set({clipSrc:j(Object.assign(Object.assign({},e.fade),{stops:e.fade.stops.filter((t,e)=>e!==r)}),e.baseSrc)})),x(s,Math.max(0,r-1))};return n.addEventListener("keydown",i),()=>{n.removeEventListener("keydown",i),null===r?n.removeAttribute("tabindex"):n.setAttribute("tabindex",r),x(s,0),n.style.cursor="",n.title="",B.current&&(B.current=!1,s.history.endTransaction())}},[s,null==w?void 0:w.id,F]),!P||!w){return null}const{width:Y,height:_}=w.a;if(Y<=0||_<=0){return null}const H=s.scale||1,q=Math.min(12/H,Y/10,_/10),C=Math.min(5/H,q/2),G=Math.min(24/H,2*q),J=t=>({x:t.x*Y,y:t.y*_}),K=t=>({x:Math.max(q/Y,Math.min(1-q/Y,t.x)),y:Math.max(q/_,Math.min(1-q/_,t.y))}),N=t=>K({x:t.x()/Y,y:t.y()/_}),Q=t=>{var e;const n=((null===(e=W.current)||void 0===e?void 0:e.getAbsoluteRotation())||0)+("y"===t?90:0);return["ew-resize","nwse-resize","ns-resize","nesw-resize"][(Math.round(n/45)%4+4)%4]},U=t=>"function"==typeof t?t():t,Z=(t,e)=>({onMouseEnter:n=>{const r=n.target.getStage().container();r.style.cursor=U(t),r.title=e},onMouseLeave:t=>{if(B.current){return}const e=t.target.getStage().container();e.style.cursor="",e.title=""}}),$=()=>{var t;const e=null===(t=W.current)||void 0===t?void 0:t.getRelativePointerPosition();"radial"===P.shape&&e&&(X.current={position:e,radius:P.radius})},tt=(t,e,n,r="grab")=>Object.assign(Object.assign({draggable:!0,dragDistance:0,stroke:n===A?String(I.anchorStroke):void 0!==n&&P.stops[n].alpha>.5?"#fff":"#222",strokeWidth:2,strokeScaleEnabled:!1,hitStrokeWidth:Math.max(0,G-2*C)},Z(r,t)),{onMouseDown:t=>{t.cancelBubble=!0,$(),void 0!==n&&(t.evt.preventDefault(),T(n))},onTouchStart:t=>{t.cancelBubble=!0,$(),void 0!==n&&(t.evt.preventDefault(),T(n))},onDragStart:t=>{t.target.getStage().container().style.cursor="grab"===r?"grabbing":U(r),B.current=!0,s.history.startTransaction()},onDragMove:t=>e(t.target),onDragEnd:t=>{t.target.getStage().container().style.cursor=U(r),B.current=!1,X.current=null,s.history.endTransaction()}}),et=t=>({fill:u(P.stops[t].alpha)}),nt=[{stroke:"#222"},{stroke:"#fff",dash:[4,4]}],rt=J("linear"===P.shape?P.start:P.center),st=J("linear"===P.shape?P.end:{x:P.center.x-P.radius.x,y:P.center.y}),it=st.x-rt.x,at=st.y-rt.y,ot=t=>({x:rt.x+it*t,y:rt.y+at*t}),lt=t=>g(((t.x-rt.x)*it+(t.y-rt.y)*at)/(it*it+at*at||1)),ct=t=>{var e,n;t.cancelBubble=!0;const r=t.target.getRelativePointerPosition();if(!r){return}const i=f(P.stops,lt(r));null===(n=null===(e=W.current)||void 0===e?void 0:e.getStage())||void 0===n||n.container().focus({preventScroll:!0}),x(s,i.index),s.history.transaction(()=>L(Object.assign(Object.assign({},P),{stops:i.stops})))},dt=n(t,{children:[nt.map((t,n)=>e(l,Object.assign({},t,{listening:1===n,strokeWidth:1.5,name:"fade-axis-guide"},Z("copy",h("toolbar.clipFade.addStop")),{points:[rt.x,rt.y,st.x,st.y],strokeScaleEnabled:!1,hitStrokeWidth:10,onMouseDown:ct,onTouchStart:ct}),n)),P.stops.map((t,n)=>0===t.offset||"linear"===P.shape&&1===t.offset?null:e(i,Object.assign({name:"fade-stop-anchor"},J(K({x:ot(t.offset).x/Y,y:ot(t.offset).y/_})),{radius:C},et(n),tt(h("toolbar.clipFade.stopOpacity"),e=>((t,e)=>{const n=P.stops.findIndex(e=>e.id===t),r=p(P.stops,n,lt(e.position()));e.position(ot(r.stops[r.index].offset)),x(s,r.index),L(Object.assign(Object.assign({},P),{stops:r.stops}))})(t.id,e),n)),t.id))]});let ut;if("linear"===P.shape){const r=(t,e)=>{const n=N(e),r=J("start"===t?P.end:P.start);Math.hypot(n.x*Y-r.x,n.y*_-r.y)<1/H?e.position(J(P[t])):(e.position(J(n)),L(Object.assign(Object.assign({},P),{[t]:n})))};ut=n(t,{children:[dt,e(i,Object.assign({name:"fade-axis-anchor fade-start"},J(K(P.start)),{radius:C},et(0),tt(h("toolbar.clipFade.start"),t=>r("start",t),0))),e(i,Object.assign({name:"fade-axis-anchor fade-end"},J(K(P.end)),{radius:C},et(P.stops.length-1),tt(h("toolbar.clipFade.end"),t=>r("end",t),P.stops.length-1)))]})}else{const r=J(P.center),s=P.radius.x*Y,o=P.radius.y*_,l=t=>{const e=N(t),n={x:Math.max(Math.min(.5,P.radius.x),Math.min(Math.max(.5,1-P.radius.x),e.x)),y:Math.max(Math.min(.5,P.radius.y),Math.min(Math.max(.5,1-P.radius.y),e.y))};t.position(J(n)),L(Object.assign(Object.assign({},P),{center:n}))},d=(t,e)=>{var n;const r="x"===t?Y:_,s=X.current;if(!s){return}const i=null===(n=W.current)||void 0===n?void 0:n.getRelativePointerPosition();if(!i){return}const a=i[t],o=Math.max(.001,Math.min(P.center[t],1-P.center[t])),l=Math.min(o,Math.max(.001,s.radius[t]+(a-s.position[t])/r*("x"===t?1:-1)));e.position(J(K("x"===t?{x:P.center.x+l,y:P.center.y}:{x:P.center.x,y:P.center.y-l}))),L(Object.assign(Object.assign({},P),{radius:Object.assign(Object.assign({},P.radius),{[t]:l})}))};ut=n(t,{children:[nt.map((t,n)=>e(a,Object.assign({},t,{strokeWidth:1.5,x:r.x,y:r.y,radiusX:s,radiusY:o,strokeScaleEnabled:!1,listening:!1}),n)),dt,e(c,Object.assign({name:"fade-center"},J(K(P.center)),{offsetX:C,offsetY:C,width:2*C,height:2*C},et(0),tt(h("toolbar.clipFade.center"),l,0,"move"))),e(i,Object.assign({name:"fade-radius-x"},J(K({x:(r.x+s)/Y,y:P.center.y})),{radius:C,fill:"#fff"},tt(h("toolbar.clipFade.radius"),t=>d("x",t),void 0,()=>Q("x")))),e(i,Object.assign({name:"fade-radius-y"},J(K({x:P.center.x,y:(r.y-o)/_})),{radius:C,fill:"#fff"},tt(h("toolbar.clipFade.radius"),t=>d("y",t),void 0,()=>Q("y"))))]})}return e(o,{ref:W,name:"fade-overlay",hideInExport:!0,children:ut})});
|
package/canvas/figure-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as e,jsx as t,jsxs as r}from"react/jsx-runtime";import a from"react";import{animatedShadow as o}from"./animated-shadow.js";import{observer as s}from"mobx-react-lite";import{Group as i,Rect as n,Shape as h}from"react-konva";import{ROLES as l}from"../model/store.js";import c from"konva";import{getFigureFillClip as d,subTypeToPathDataFunc as m}from"@polotno/core/figure-to-svg";import{isOpaquePaint as g}from"@polotno/core/gradient";import{isTouchDevice as p}from"../utils/screen.js";import{activeAnchorOf as f,isCornerAnchor as u,scaledStyleAttrs as b,roundedStyleAttrs as k,roundedGeometryAttrs as w,roundedPosition as j,transformScale as x}from"../utils/px.js";import{useColor as y}from"./use-color.js";import{PlacedNode as v}from"./placed-node.js";import{elementOpacity as P,paintOpacity as T}from"./paint-opacity.js";const M=(e,t)=>{e.beginPath();for(const{command:r,points:a}of t){switch(r){case"L":e.lineTo(a[0],a[1]);break;case"M":e.moveTo(a[0],a[1]);break;case"C":e.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case"Q":e.quadraticCurveTo(a[0],a[1],a[2],a[3]);break;case"A":e.ellipse(a[0],a[1],a[2],a[3],a[6],a[4],a[4]+a[5],!a[7]);break;case"z":e.closePath()}}},O={};export const FigureElement=s(({element:S,store:E})=>{const R=a.useRef(null),D=a.useRef(!1),W=S.selectable||E.role===l.ADMIN,C=p(),F=Math.min(S.strokeWidth,S.width/2,S.height/2),I=y(S,S.fill,"fill"),z=Object.assign(Object.assign(Object.assign({width:S.a.width,height:S.a.height},I),o(S)),{preventDefault:!C||S.isSelected,hideInExport:!S.showInExport}),A=y(S,S.stroke,"stroke"),X=Object.assign(Object.assign({},A),{strokeWidth:2*F,dash:S.dash.map(e=>e*F)}),Y=Math.max(0,10-Math.min(S.a.width,S.a.height)),q=d({subType:S.subType,width:S.a.width,height:S.a.height,cornerRadius:S.cornerRadius,strokeWidth:F,stroke:S.stroke,dash:S.dash,opacity:T(S)}),L=!S.a.shadowEnabled||g(S.fill)?q:null,N=(Q=S.subType,O[Q]||(O[Q]=(B=m(Q),s(({element:o,fillProps:s,strokeProps:i,hitStrokeWidth:l,fillClip:d})=>{const m=B({width:o.a.width,height:o.a.height,cornerRadius:o.cornerRadius}),g=a.useMemo(()=>c.Path.parsePathData(m),[m]),p=a.useMemo(()=>d?c.Path.parsePathData(d):null,[d]),f=!!p;return r(e,{children:[t(n,{width:o.a.width,height:o.a.height,fill:"transparent",hitStrokeWidth:l}),t(h,Object.assign({},s,i,{perfectDrawEnabled:f,shadowForStrokeEnabled:f,selfRectFunc:e=>({x:0,y:0,width:e.width(),height:e.height()}),sceneFunc:(e,t)=>{e.save(),p?(M(e,g),e.clip(),M(e,p),e.clip()):M(e,g),e.fillShape(t),e.restore(),e.save(),M(e,g),e.clip(),e.strokeShape(t),e.restore()}}))]})}))),O[Q]||i);var Q,B;return t(e,{children:t(v,{as:i,nodeRef:R,element:S,id:S.id,opacity:P(S),listening:W,draggable:C?S.draggable&&S.isSelected:S.draggable,name:"element",onDragMove:e=>{S.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{S.set(j(e.target))},onTransformStart:e=>{D.current=u(f(e.target))},onTransform:e=>{const t={x:x(e.target.scaleX()),y:x(e.target.scaleY())};e.target.scaleX(1),e.target.scaleY(1);const r=D.current?Math.min(t.x,t.y):1;S.set(Object.assign({width:S.width*t.x,height:S.height*t.y,x:e.target.x(),y:e.target.y(),rotation:e.target.rotation()},1!==r&&b(S,r)))},onTransformEnd:()=>{S.set(Object.assign(Object.assign({},w(S)),k(S)))},children:t(N,{element:S,fillProps:z,strokeProps:X,hitStrokeWidth:Y,fillClip:L})})})});
|
package/canvas/gif-element.d.ts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StoreType } from '../model/store.js';
|
|
3
3
|
import { VideoElementType } from '../model/video-model.js';
|
|
4
|
+
import { ImageElementType } from '../model/image-model.js';
|
|
5
|
+
import Konva from 'konva';
|
|
6
|
+
export declare function useRasterPipeline(element: ImageElementType, pixelRatio: number, source: HTMLCanvasElement | undefined, crop: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}, imageRef: React.RefObject<Konva.Image | null>, isTransforming: boolean): readonly [HTMLCanvasElement | HTMLVideoElement | undefined, () => void];
|
|
12
|
+
export declare const RasterNode: (({ element, store, nodeRef, image, opacity, onTransformingChange, }: {
|
|
13
|
+
element: ImageElementType;
|
|
14
|
+
store: StoreType;
|
|
15
|
+
nodeRef: React.RefObject<Konva.Image | null>;
|
|
16
|
+
image: HTMLCanvasElement | HTMLVideoElement | undefined;
|
|
17
|
+
opacity: number;
|
|
18
|
+
onTransformingChange: (transforming: boolean) => void;
|
|
19
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
20
|
+
element: ImageElementType;
|
|
21
|
+
store: StoreType;
|
|
22
|
+
nodeRef: React.RefObject<Konva.Image | null>;
|
|
23
|
+
image: HTMLCanvasElement | HTMLVideoElement | undefined;
|
|
24
|
+
opacity: number;
|
|
25
|
+
onTransformingChange: (transforming: boolean) => void;
|
|
26
|
+
}> & {
|
|
27
|
+
readonly type: ({ element, store, nodeRef, image, opacity, onTransformingChange, }: {
|
|
28
|
+
element: ImageElementType;
|
|
29
|
+
store: StoreType;
|
|
30
|
+
nodeRef: React.RefObject<Konva.Image | null>;
|
|
31
|
+
image: HTMLCanvasElement | HTMLVideoElement | undefined;
|
|
32
|
+
opacity: number;
|
|
33
|
+
onTransformingChange: (transforming: boolean) => void;
|
|
34
|
+
}) => React.JSX.Element;
|
|
35
|
+
};
|
|
4
36
|
type Props = {
|
|
5
37
|
store: StoreType;
|
|
6
38
|
element: VideoElementType;
|
package/canvas/gif-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fragment as e,jsx as t,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import i from"react";import{toDisplayColor as n}from"@polotno/core/color";import{animatedShadow as a}from"./animated-shadow.js";import{observer as s}from"mobx-react-lite";import{isAlive as d}from"mobx-state-tree";import{nodeAutorun as l}from"../utils/mobx.js";import{isHeldByPreview as m}from"../utils/timeline.js";import{Image as c,Rect as h}from"react-konva";import{ROLES as u}from"../model/store.js";import{parseGIF as f,decompressFrames as g}from"gifuct-js";import{useClip as p,useCornerRadiusAndCrop as v,useFlip as w}from"./video-element.js";import{useImageLoader as x}from"./image-element.js";import{fetchBytesWithRetry as y}from"@polotno/core/retry";import{dataUrlToBytes as j}from"@polotno/core/image-bytes";import{ErrorPlaceholder as b,LoadingPlaceholder as R}from"./media-placeholders.js";import{useFilteredSource as E}from"./use-filtered-source.js";import{useOffscreenCanvas as I}from"./use-offscreen-canvas.js";import{useFadeIn as S}from"./use-fadein.js";import{useAnimatedBlur as T}from"./use-animated-blur.js";import{isTouchDevice as z}from"../utils/screen.js";import{activeAnchorOf as C,isCornerAnchor as D,scaledStyleAttrs as M,roundedStyleAttrs as O,roundedGeometryAttrs as k,roundedPosition as F,transformScale as L}from"../utils/px.js";import{useEvent as P}from"../hooks/use-event.js";import{PlacedNode as X}from"./placed-node.js";import{refCountedCache as Y}from"../utils/ref-counted.js";async function _(e){var t;const r=null!==(t=j(e))&&void 0!==t?t:await y(e),o=f(new Uint8Array(r).buffer),i=g(o,!0).map(e=>({patch:new Uint8ClampedArray(e.patch),delay:e.delay,width:e.dims.width,height:e.dims.height,left:e.dims.left,top:e.dims.top,disposalType:e.disposalType}));return{frames:i,duration:i.reduce((e,t)=>e+t.delay,0),dimensions:{width:o.lsd.width,height:o.lsd.height}}}const A=Y(),G=[],N={width:0,height:0};function U(e,t,r){const o=t.getContext("2d"),i=r.getContext("2d");if(!o||!i){return}2===e.disposalType&&o.clearRect(0,0,t.width,t.height),r.width=e.width,r.height=e.height;const n=i.createImageData(e.width,e.height);n.data.set(e.patch),i.putImageData(n,0,0),o.drawImage(r,e.left,e.top)}export function useRasterPipeline(e,t,r,o,n,a){var s;const l=null!==(s=e.cornerRadius)&&void 0!==s?s:0,[m,c]=w(e,r),[h,u]=E(e,m),[f,g]=v(e,h,o,t,l,a||e._cropModeEnabled),[x,y]=p(e,f,t,[o,l]),j=T(n,e,x),b=P(()=>{d(e)&&(c(),u(),g(),y(),j())});return i.useLayoutEffect(()=>{var e,t;null===(t=null===(e=n.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}),[x,b]}export const RasterNode=s(({element:o,store:s,nodeRef:d,image:l,opacity:m,onTransformingChange:f})=>{var g;const p=i.useRef(!1),v=z();S(d,m);const w=o.selectable||s.role===u.ADMIN,x=null!==(g=o.cornerRadius)&&void 0!==g?g:0;return r(e,{children:[t(X,Object.assign({as:c,nodeRef:d,element:o,name:"element",id:o.id,image:l,width:o.a.width||1,height:o.a.height||1,opacity:m},a(o),{listening:w,draggable:v?o.draggable&&o.isSelected:o.draggable,preventDefault:!v||o.isSelected,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set(F(e.target))},onTransformStart:e=>{f(!0),p.current=D(C(e.target))},onTransform:e=>{const t=e.currentTarget,r=L(t.scaleX()),i=L(t.scaleY());t.scaleX(1),t.scaleY(1);const n=p.current?Math.min(r,i):1;o.set(Object.assign({x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:t.rotation()},1!==n&&M(o,n)))},onTransformEnd:()=>{o.set(Object.assign(Object.assign({},k(o)),O(o))),f(!1)}})),!!o.borderSize&&t(X,{as:h,element:o,width:Math.max(o.a.width-o.borderSize,0),height:Math.max(o.a.height-o.borderSize,0),opacity:m,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2,stroke:n(o.borderColor),strokeWidth:o.borderSize,listening:!1,cornerRadius:Math.max(0,x-o.borderSize),hideInExport:!o.showInExport})]})});export const GifElement=s(({element:n,store:a})=>{const[s,d]=i.useState(!1),c=i.useRef(null),[h,u,f,g]=function(e){var t,r,o,n;const[a,s]=i.useState(()=>{var t;return{url:e,gif:null===(t=A.get(e))||void 0===t?void 0:t.value}});i.useEffect(()=>{const[t,r]=function(e){const[t,r]=A.acquire(e,()=>{const t={decoded:_(e)};return t.decoded.then(e=>{t.value=e},()=>A.remove(e,t)),t});return[t.decoded,r]}(e);let o=!0;return t.then(t=>{o&&s({url:e,gif:t})},t=>{o&&(console.error("Failed to load GIF:",t),s({url:e,failed:!0}))}),()=>{o=!1,r()}},[e]);const{gif:d,failed:l}=a.url===e?a:{gif:null===(t=A.get(e))||void 0===t?void 0:t.value,failed:!1},m=d?"loaded":l?"failed":"loading";return[null!==(r=null==d?void 0:d.frames)&&void 0!==r?r:G,null!==(o=null==d?void 0:d.duration)&&void 0!==o?o:0,null!==(n=null==d?void 0:d.dimensions)&&void 0!==n?n:N,m]}(n.src);x(g,n.src,n.id);const p=e=>{e.width=f.width,e.height=f.height,U(h[0],e,document.createElement("canvas"))},v=I(h.length>0,p,[h,f]);i.useEffect(()=>{if(!v){return}const e=document.createElement("canvas");p(v),z();let t=0;const r=r=>{const o=(e=>{const t=e%u;let r=0;for(let o=0;o<h.length;o++){if(r+=h[o].delay,r>t){return o}}return 0})(r);o!==t&&(U(h[o],v,e),z(),c.current.getLayer().draw(),t=o)};let o=0;const i=l(n,()=>{if(m(n)){return}clearInterval(o);const e=n.page._mediaLocalTime;null!==e?r(e):a.isPlaying||n.page._exportingOrRendering?r(0):o=window.setInterval(()=>r(performance.now()),16)});return()=>{i(),clearInterval(o)}},[h,u]),i.useEffect(()=>{u&&a.history.ignore(()=>{n.set({duration:u})})},[u]);let{cropX:w,cropY:y,cropWidth:j,cropHeight:E}=n.a;"loaded"!==g&&(w=y=0,j=E=1);const S={x:f.width*w,y:f.height*y,width:f.width*j,height:f.height*E},[T,z]=useRasterPipeline(n,a._elementsPixelRatio,v,S,c,s),C="loading"===g,D="failed"===g,M=C||D?0:o(n);return r(e,{children:[C&&t(R,{element:n}),D&&t(b,{element:n,text:"Cannot load the GIF..."}),t(RasterNode,{element:n,store:a,nodeRef:c,image:T,opacity:M,onTransformingChange:d})]})});
|
package/canvas/hotkeys.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StoreType } from '../model/store.js';
|
|
2
|
-
import { TableElementType } from '../model/table-model.js';
|
|
2
|
+
import type { TableElementType } from '../model/table-model.js';
|
|
3
3
|
export declare function getWorkspaceEventScope(store: StoreType, workspaceContainer?: HTMLElement | null): {
|
|
4
4
|
handle: boolean;
|
|
5
5
|
table: TableElementType | null;
|
package/canvas/hotkeys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ROLES as e}from"../model/store.js";import{copyToEvent as t,cutToEvent as o,
|
|
1
|
+
import{ROLES as e}from"../model/store.js";import{copyToEvent as t,cutToEvent as o,escapeText as l,pasteFromEvent as n,insertTextElement as r}from"../utils/clipboard.js";import{duplicateElements as i}from"../utils/duplicate.js";import{alignBottom as c,alignCenter as a,alignLeft as s,alignMiddle as d,alignRight as u,alignTop as f}from"../utils/alignment.js";import{richTextToPlainText as p}from"@polotno/core/text";const v="rgba(191, 191, 191, 100)";function y(e){if(1!==e.selectedElements.length){return null}const t=e.selectedElements[0];return"table"!==t.type?null:t}function h(e,t,o){const l=e.visibleCellAt(t,o);l&&e.focusCell(l.id)}function m(e,t,o){const l=e.rows*e.cols,n=t.row*e.cols+t.col;for(let r=1;r<=l;r++){const t=((n+o*r)%l+l)%l,i=e.getCell(Math.floor(t/e.cols),t%e.cols);if(i&&!i.mergedInto){return i}}}function g(e=document.querySelector(".polotno-workspace-container")){var t;const o=document.activeElement,l=null==o?void 0:o.closest(".polotno-workspace-container"),n=!!l&&l!==e,r="INPUT"===(null==o?void 0:o.tagName)||"TEXTAREA"===(null==o?void 0:o.tagName)||!!(null==o?void 0:o.isContentEditable),i=!(!o||!(null==e?void 0:e.contains(o))),c=document.activeElement===e||i;return{workspaceContainer:e,otherWorkspace:n,activeIsEditable:r,activeIsInsideWorkspace:i,isWorkspaceActive:c,hasOutsideTextSelection:!c&&((null===(t=window.getSelection())||void 0===t?void 0:t.toString().length)||0)>0}}export function getWorkspaceEventScope(t,o){if(t.role===e.VIEWER){return{handle:!1,table:null}}const l=g(o);if(l.otherWorkspace||l.activeIsEditable||l.hasOutsideTextSelection){return{handle:!1,table:null}}const n=y(t);return{handle:!0,table:n&&n._focusedCellIds.length>0&&!n._editingCellId?n:null}}export function handleHotkey(t,o,l){var n,p,w,E,k,D,C,x,K,b,A;if(o.role===e.VIEWER){return}const R=g(l);if(R.otherWorkspace){return}const T=R.activeIsEditable&&!R.activeIsInsideWorkspace,S=y(o);if(!T&&S&&function(e,t,o){const l=t._focusedCellIds.length>0,n=!!t._editingCellId;if(!l&&!n){return!1}if(n){if("Escape"===e.key){return e.preventDefault(),t.exitCellEdit(),!0}if("Tab"===e.key){e.preventDefault();const o=t.editingCell;t.exitCellEdit();const l=o&&m(t,o,e.shiftKey?-1:1);return l&&t.enterCellEdit(l.id),!0}return!0}if("Escape"===e.key){return e.preventDefault(),t.clearCellFocus(),!0}const r=t.focusedCells[0],i=r&&t.visibleCellAt(r.row,r.col);if(!i){return!1}const{row:c,col:a}=i;if("Enter"===e.key){return e.preventDefault(),t.enterCellEdit(i.id),!0}if("Tab"===e.key){e.preventDefault();const o=m(t,i,e.shiftKey?-1:1);return o&&t.focusCell(o.id),!0}if("ArrowRight"===e.key||"ArrowLeft"===e.key||"ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),e.shiftKey){const o=function(e){const t=e.cells.find(t=>t.id===e._anchorCellId);if(!t){return null}const o=e.focusedCells;if(o.length<=1){return{row:t.row,col:t.col}}let l=1/0,n=-1,r=1/0,i=-1;for(const c of o){c.row<l&&(l=c.row),c.row>n&&(n=c.row),c.col<r&&(r=c.col),c.col>i&&(i=c.col)}return{row:t.row===l?n:l,col:t.col===r?i:r}}(t)||{row:c,col:a};let l=o.row,n=o.col;"ArrowRight"===e.key&&(n=Math.min(o.col+1,t.cols-1)),"ArrowLeft"===e.key&&(n=Math.max(o.col-1,0)),"ArrowDown"===e.key&&(l=Math.min(o.row+1,t.rows-1)),"ArrowUp"===e.key&&(l=Math.max(o.row-1,0)),t.focusCellRange(l,n)}else{"ArrowRight"===e.key&&h(t,c,Math.min(a+i.colSpan,t.cols-1)),"ArrowLeft"===e.key&&h(t,c,Math.max(a-1,0)),"ArrowDown"===e.key&&h(t,Math.min(c+i.rowSpan,t.rows-1),a),"ArrowUp"===e.key&&h(t,Math.max(c-1,0),a)}return!0}const s=e.ctrlKey||e.metaKey;if(!(s||e.shiftKey||e.altKey||"Delete"!==e.key&&"Backspace"!==e.key)){return e.preventDefault(),t.focusedCells.forEach(e=>{e.set({text:""})}),!0}if(s&&e.shiftKey&&!e.altKey&&"Equal"===e.code){e.preventDefault();const l=t.getFocusedCellRange(),n=l?l.maxRow+1:c+1;return o.history.transaction(()=>{t.addRow(n)}),!0}if(s&&e.shiftKey&&e.altKey&&"Equal"===e.code){e.preventDefault();const l=t.getFocusedCellRange(),n=l?l.maxCol+1:a+1;return o.history.transaction(()=>{t.addColumn(n)}),!0}if(s&&!e.shiftKey&&"Backspace"===e.code){const l=t.getFocusedCellRange();if(l&&0===l.minCol&&l.maxCol===t.cols-1&&t.rows>1){return e.preventDefault(),o.history.transaction(()=>{t.removeRowRange(l.minRow,l.maxRow)}),!0}}if(s&&e.shiftKey&&"Backspace"===e.code){const l=t.getFocusedCellRange();if(l&&0===l.minRow&&l.maxRow===t.rows-1&&t.cols>1){return e.preventDefault(),o.history.transaction(()=>{t.removeColumnRange(l.minCol,l.maxCol)}),!0}}return s&&"KeyA"===e.code?(e.preventDefault(),t.cells.forEach(e=>{t.focusCell(e.id,!0)}),!0):!s||"z"!==e.key.toLowerCase()&&"y"!==e.key.toLowerCase()}(t,S,o)){return}if(R.activeIsEditable){return}if(R.hasOutsideTextSelection){return}if(o.activeTool&&"crop"!==o.activeTool.name&&"Escape"===t.key&&R.isWorkspaceActive){return t.preventDefault(),void o._closeImageTool("discard")}if("Alt"===t.key){const e=R.workspaceContainer;return void((R.isWorkspaceActive||o.distanceGuidesVisible||e&&e.matches(":hover"))&&t.preventDefault())}if("Escape"===t.key||"Enter"===t.key){const e=o._hasCroppedImages;if(e&&("Escape"===t.key||R.isWorkspaceActive)){return t.preventDefault(),void("Escape"===t.key?e.cancelCropMode():(null===(n=o.activeTool)||void 0===n?void 0:n.pending)||e.toggleCropMode(!1))}}const W=o.selectedElements.filter(e=>e.removable).map(e=>e.id),I=!!o.activeTool&&"crop"!==o.activeTool.name;46!==t.keyCode&&8!==t.keyCode||I||o.deleteElements(W);const M=t.ctrlKey||t.metaKey,L=t.shiftKey,P=t.altKey;if("Escape"===t.key){return t.preventDefault(),void("draw"===o.tool?o.setTool("selection"):o.selectElements([]))}if(M&&!L&&"z"===t.key.toLowerCase()){return t.preventDefault(),void o.history.undo()}if(M&&(L&&"z"===t.key.toLowerCase()||"y"===t.key.toLowerCase())){return t.preventDefault(),void o.history.redo()}if(M&&"KeyA"===t.code){t.preventDefault();const e=null===(p=o.activePage)||void 0===p?void 0:p.children.filter(e=>e.selectable),l=(null==e?void 0:e.map(e=>e.id))||[];o.selectElements(l)}if(M&&("Equal"===t.code||"Minus"===t.code)){return t.preventDefault(),void o.setScale(o.scale+("Equal"===t.code?.1:-.1))}if(!I&&!o.selectedShapes.some(e=>"pendingEdit"in e&&e.pendingEdit)){if("ArrowDown"===t.code){t.preventDefault();const e=t.shiftKey?10:1;o.selectedShapes.forEach(t=>{t.draggable&&t.set({y:t.y+e})})}if("ArrowUp"===t.code){t.preventDefault();const e=t.shiftKey?10:1;o.selectedShapes.forEach(t=>{t.draggable&&t.set({y:t.y-e})})}if("ArrowLeft"===t.code){t.preventDefault();const e=t.shiftKey?10:1;o.selectedShapes.forEach(t=>{t.draggable&&t.set({x:t.x-e})})}if("ArrowRight"===t.code){t.preventDefault();const e=t.shiftKey?10:1;o.selectedShapes.forEach(t=>{t.draggable&&t.set({x:t.x+e})})}if(M&&"KeyG"===t.code){t.preventDefault();const e=o.selectedElements[0];if(e&&"group"===e.type){const t=e;o.ungroupElements([t.id])}else{o.groupElements(o.selectedElements.map(e=>e.id))}}if(M&&"KeyD"===t.code&&(t.preventDefault(),i(o.selectedElements,o)),"KeyT"!==t.code||M||(t.preventDefault(),r(o,"Sample Text",{fontFamily:"Roboto"})),"KeyR"===t.code&&!M){t.preventDefault();const e={type:"figure",x:o.width/4,y:o.height/4,width:300,height:300,fill:v,stroke:"#0c0c0c",strokeWidth:0,subType:"rect"};null===(w=o.activePage)||void 0===w||w.addElement(e)}if("KeyL"===t.code&&!M){t.preventDefault();const e=(null!==(K=null===(E=o.activePage)||void 0===E?void 0:E.computedWidth)&&void 0!==K?K:0)/3,l={type:"line",x:(null!==(b=null===(k=o.activePage)||void 0===k?void 0:k.computedWidth)&&void 0!==b?b:0)/2-e/2,y:(null!==(A=null===(D=o.activePage)||void 0===D?void 0:D.computedHeight)&&void 0!==A?A:0)/2,width:e,color:v};null===(C=o.activePage)||void 0===C||C.addElement(l)}if("KeyO"===t.code&&!M){t.preventDefault(),t.preventDefault();const e={type:"figure",x:o.width/4,y:o.height/4,width:300,height:300,fill:v,stroke:"#0c0c0c",strokeWidth:0,subType:"circle"};null===(x=o.activePage)||void 0===x||x.addElement(e)}P&&("KeyA"===t.code&&(t.preventDefault(),s(o)),"KeyD"===t.code&&(t.preventDefault(),u(o)),"KeyS"===t.code&&(t.preventDefault(),c(o)),"KeyW"===t.code&&(t.preventDefault(),f(o)),"KeyV"===t.code&&(t.preventDefault(),d(o)),"KeyH"===t.code&&(t.preventDefault(),a(o))),"BracketRight"===t.code&&(t.preventDefault(),o.selectedElements.forEach(e=>M?e.moveUp():e.moveTop())),"BracketLeft"===t.code&&(t.preventDefault(),o.selectedElements.forEach(e=>M?e.moveDown():e.moveBottom()))}}function w(e,t){const o=e.focusedCells.map(e=>p(e.text)).join("\n");t.clipboardData.setData("text/plain",o||" "),t.preventDefault()}export function handleCopyEvent(e,o,l){const n=getWorkspaceEventScope(o,l);n.handle&&e.clipboardData&&(n.table?w(n.table,e):t(o,e))}export function handleCutEvent(e,t,l){const n=getWorkspaceEventScope(t,l);if(n.handle&&e.clipboardData){if(n.table){const o=n.table;return w(o,e),void t.history.transaction(()=>{o.focusedCells.forEach(e=>e.set({text:""}))})}o(t,e)}}export function handlePasteEvent(e,t,o){const r=getWorkspaceEventScope(t,o);if(!r.handle){return}const i=r.table;n(t,e,{onText:i?e=>{var t;return null===(t=i.focusedCells[0])||void 0===t?void 0:t.set({text:l(e)})}:void 0})}
|
package/canvas/html-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{toDisplayColor as i}from"@polotno/core/color";import{elementOpacity as n}from"./paint-opacity.js";import{observer as a}from"mobx-react-lite";import{Group as s,Image as l,Path as c,Rect as d}from"react-konva";import{activeAnchorOf as f,scaledFontSizeAttrs as h,roundedFontSizeAttrs as u,roundedTextDecorationAttrs as g,roundedGeometryPx as m,roundedPosition as p,textMinResizeWidth as x,transformScale as y}from"../utils/px.js";import b from"konva";import{isAlive as w}from"mobx-state-tree";import{nodeAutorun as S}from"../utils/mobx.js";import{flags as v}from"../utils/flags.js";import{textOverflowOf as E}from"../utils/text-sizing.js";import{layoutTextSizing as z,legacyTextOverflow as k,renderTagLayoutAt as O,resolveTextSizing as j}from"@polotno/core/text-sizing";import{applyFilter as F}from"./apply-filters.js";import{getLineHeight as M,useFontFamiliesLoader as R,usePrevious as Y}from"./text-element.js";import{getCurvePath as X}from"@polotno/core/text-html";import{useColor as C,withDisplayTextPaints as I}from"./use-color.js";import{useWorkspaceStyle as A}from"./workspace-style.js";import{detectSize as P,detectLineRects as $,htmlToCanvas as B}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as T}from"@polotno/core/background-shape";import{useFadeIn as W}from"./use-fadein.js";import{Html as H}from"react-konva-utils";import{incrementLoader as _,triggerLoadError as D}from"../utils/loader.js";import{removeTags as L}from"@polotno/core/text";import{cssFontFamily as J}from"@polotno/core/fonts";import{shadowCastByBackground as N}from"@polotno/core/filters";import*as q from"../utils/fonts.js";import{isTouchDevice as V}from"../utils/screen.js";import{getLimitedFontSize as G}from"./text-element/max-font-size.js";import{AutoDeleteEmptyText as K}from"./text-element/auto-delete-empty-text.js";import{useDelayer as Q}from"./use-delayer.js";import{geckoRtlOverhangCss as U,getHtml as Z,letterSpacingOverhang as tt,OVERHANG_PROPERTY as et,textLayoutWidth as ot}from"@polotno/core/text-html";import{hasMeasuredHeight as rt,resolveTextBoxHeight as it}from"@polotno/core/text-types";import{normalizeRichTextHtml as nt,extractFontFamiliesFromHtml as at,scaleRichTextFontSizesInHtml as st}from"../utils/rich-text-html.js";import{RichEditor as lt,RichTextContainer as ct,applyOpacityToColor as dt,quillRef as ft,createQuill as ht,setQuillContent as ut,setQuillFormats as gt,syncQuillFormatState as mt,setCursorFromCoords as pt}from"./rich-editor.js";export{ft as quillRef,ht as createQuill,ut as setQuillContent,gt as setQuillFormats,mt as syncQuillFormatState,pt as setCursorFromCoords};function xt(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const yt=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),bt=navigator.userAgent.includes("Firefox");export const HTMLElement=a(({element:a,store:ft})=>{var ht,ut,gt;const{textOverflowIndicatorStyle:mt}=A(),pt=r.useRef(null),[wt,St]=r.useState(),[vt,Et]=r.useState(!1),[zt,kt]=r.useState(!1),Ot=r.useRef(a.height),jt=a.fontSize/3,Ft=ot(a.a.width,a.letterSpacing,a.fontSize)+2*jt,{textVerticalResizeEnabled:Mt}=v,Rt=Y(a.fontFamily),Yt=r.useMemo(()=>nt(a.text,{fontSize:a.fontSize,fontFamily:a.fontFamily}),[a.text,a.fontSize,a.fontFamily]),Xt=r.useMemo(()=>[...new Set([a.fontFamily,...at(Yt)])].filter(Boolean),[a.fontFamily,Yt]),[Ct]=R(ft,Xt,a.fontStyle,a.fontWeight,a.text||a.placeholder),It=a._editModeEnabled,At=It&&!(null===(ht=a.page)||void 0===ht?void 0:ht._exporting);W(pt);const Pt=Ct?a.fontFamily:Rt!==a.fontFamily?Rt:"Arial",$t=C(a).fill,Bt=Z(I(a),{fontFamily:Pt,color:$t,textOverflow:E(a)}),Tt=function(t,e){return e&&/dir="rtl"|direction: rtl/.test(t)?`<div class="polotno-overhang" style="${et}: ${e}px">${t}</div><style>${U(".polotno-overhang [dir]:not(.polotno-overhang [dir] [dir])")}</style>`:t}(Bt,tt(a.letterSpacing,a.fontSize)),Wt=r.useRef([]),Ht=r.useRef(!0),[,_t]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=Wt.current;t.length>0&&(Wt.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{Ht.current=!1;const t=Wt.current;t.length>0&&(Wt.current=[],t.forEach(t=>t()))},[]);let{width:Dt,height:Lt}=function(t,e,o){return r.useMemo(()=>P(t),[t,e.width,o])}(Tt,a,Ct);r.useEffect(()=>{if(!Ct){return}const t=(t,e,o,r)=>{const i=_(`text ${a.id}`),n=()=>{ft.history.ignore(t,e,o).then(()=>{Ht.current?(Wt.current.push(i),_t()):i()})};r?queueMicrotask(n):n()};if(a.curveEnabled&&Math.abs(Dt-a.width)>1&&!vt&&t(()=>{if(w(a)&&Math.abs(Dt-a.width)>1){const t=a.x+a.width/2;a.set({width:Dt,x:t-Dt/2})}},!1,!0),!rt(a)){return void t(()=>{w(a)&&(rt(a)||a.set({height:Lt}))},void 0,void 0,!0)}const e=k(E(a));if("change-font-size"!==e||vt||It||a.curveEnabled){"resize"===e&&(Mt&&a.height<Lt&&!vt&&t(()=>{w(a)&&a.set({height:Lt})},!1,!0),Mt||a.height===Lt||vt||t(()=>{w(a)&&a.set({height:Lt})},!1,!0))}else{const o=z({element:a,sizing:j({text:a.text,width:a.width,height:a.height,fontSize:a.fontSize,maxLines:a.maxLines,curveEnabled:a.curveEnabled},{textOverflow:e,textSplitAllowed:v.textSplitAllowed}),layoutAt:O(a,{getHtmlOptions:{fontFamily:a.fontFamily}})});o.fontSize!==a.fontSize?t(()=>{if(!w(a)){return}const t=h(a,o.fontSize);o.text!==a.text&&(t.text=o.text),a.set(t)},!1,!0):a.height!==Lt&&(Mt&&a.height<Lt?t(()=>{w(a)&&a.set({height:Lt})},!1,!0):Mt||t(()=>{w(a)&&a.set({height:Lt})},!1,!0))}});const Jt=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await B(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),Nt=r.useRef(0),qt=r.useRef(null);r.useEffect(()=>{vt||At||(async()=>{Nt.current++;const t=Nt.current;let e=_(`text ${a.id} ${t}`);qt.current&&qt.current(),qt.current=e,kt(!0);let o=null;const r=yt?5:1;for(let n=0;n<r;n++){const e=n>0?Jt:B;try{if(o=await e({skipCache:n>0,html:Tt,width:Dt||a.width||1,height:it(a,Lt)||1,fontFamily:Pt,fontFamilies:at(Tt),resolveFont:t=>ft.fonts.find(e=>e.fontFamily===t)||q.globalFonts.find(e=>e.fontFamily===t),padding:jt,pixelRatio:ft._elementsPixelRatio,font:ft.fonts.find(t=>t.fontFamily===Pt)||q.globalFonts.find(t=>t.fontFamily===Pt)}),t!==Nt.current){return}if((yt||bt)&&o&&xt(o)){await new Promise(t=>setTimeout(t,50*(n+1)));continue}break}catch(i){console.error(i),D(`Error rendering rich text with id ${a.id}`);break}}o?St(o):e?(e(),e=null):console.error("Finish function is called twice!"),kt(!1)})()},[Tt,vt,Lt,At,Pt,a.height,ft._elementsPixelRatio,Ct]);const[Vt,Gt]=Q(zt,300),[Kt]=Q(vt,300,!0),Qt=Kt||Vt;r.useEffect(()=>{var t;if(!Qt){return S(a,()=>{const t=pt.current;F(t,a)})}null===(t=pt.current)||void 0===t||t.clearCache()},[wt,Qt,a.shadowColor,a.shadowOffsetX,a.shadowOffsetY,a.shadowOpacity]),r.useEffect(()=>{wt&&!zt&&qt.current&&(qt.current(),qt.current=null)},[wt,zt]),r.useLayoutEffect(()=>{if(!Ct){return}if(!a.curveEnabled){return}const t=new b.TextPath({data:X(a.a.width,a.a.height,a.curvePower,a.a.fontSize),text:L(a.text),letterSpacing:a.letterSpacing*a.a.fontSize,fontSize:a.a.fontSize,fontFamily:J(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,align:"center",textBaseline:"middle",fill:a.fill}),e=t.getSelfRect().width;if(e){const t=e-a.a.width,o=a.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{w(a)&&a.set({width:e,x:a.a.x+r,y:a.a.y+i})})}t.destroy()},[Ct,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),r.useEffect(()=>()=>{qt.current&&qt.current()},[]);const Ut=it(a,Lt);let Zt=0;"middle"===a.verticalAlign&&(Zt=(Ut-Lt)/2),"bottom"===a.verticalAlign&&(Zt=Ut-Lt);const te=M({fontLoaded:Ct,fontFamily:a.fontFamily,fontSize:a.fontSize,lineHeight:a.lineHeight}),ee=a.backgroundPadding*(a.fontSize*te*.5),oe=a.backgroundCornerRadius*(a.fontSize*te*.5),re=r.useMemo(()=>{if(!a.backgroundEnabled&&!a.borderSize||a.curveEnabled||a.legacyBackground){return""}const t=$(Bt);if(0===t.length){return""}const e=t.map(t=>({left:t.left+jt,right:t.right+jt,top:t.top+jt,bottom:t.bottom+jt}));return T({rects:e,padding:ee,cornerRadius:oe})},[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.legacyBackground,Bt,Ct,ee,oe,jt]),ie=V(),ne=X(a.a.width,Lt,a.curvePower,a.fontSize),ae=r.useRef(null),se=r.useRef(a.width),le=r.useRef(""),ce=r.useRef(0),de=r.useRef(0),fe=r.useRef(null),he=It&&a.strokeWidth>0&&!a.curveEnabled,ue=Dt>0?Ft/(Dt+2*jt):1,ge=a.shadowEnabled&&!N(a),me={shadowEnabled:a.shadowEnabled&&(N(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return o(e,{children:[t(K,{element:a,store:ft}),a.curveEnabled||a.legacyBackground?t(d,Object.assign({x:a.a.x,y:a.a.y,offsetX:ee/ue,offsetY:ee/ue,rotation:a.a.rotation,scaleX:ue,scaleY:ue,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled||a.borderSize>0,opacity:n(a),fillEnabled:a.backgroundEnabled,fill:dt(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,width:a.width+2*ee,height:Ut+2*ee,cornerRadius:oe},me)):t(c,Object.assign({name:"html-background",x:a.a.x,y:a.a.y,offsetX:jt/ue,offsetY:(jt-Zt)/ue,rotation:a.a.rotation,scaleX:ue,scaleY:ue,hideInExport:!a.showInExport,listening:!1,visible:(a.backgroundEnabled||a.borderSize>0)&&re.length>0,opacity:n(a),fillEnabled:a.backgroundEnabled,fill:dt(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:oe>0?"round":"miter",data:re},me)),t(c,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,data:ne,stroke:mt.stroke,strokeWidth:1,visible:!1}),t(d,{ref:pt,name:"element",x:a.a.x,y:a.a.y,listening:a.selectable,rotation:a.a.rotation,width:a.a.width,height:a.a.height,visible:!Qt,draggable:ie?a.draggable&&a.isSelected:a.draggable,preventDefault:!ie||a.isSelected,opacity:It?0:n(a),hideInExport:!a.showInExport,onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{a.set(p(t.target))},id:a.id,onDblClick:t=>{a.contentEditable&&(fe.current={x:t.evt.clientX,y:t.evt.clientY},a.toggleEditMode(!0))},onDblTap:t=>{var e;if(a.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];fe.current=o?{x:o.clientX,y:o.clientY}:null,a.toggleEditMode(!0)}},onTransformStart:t=>{Et(!0),Ot.current=a.height,se.current=a.width,ae.current=t.target.position(),le.current=f(t.target),ce.current=a.a.rotation,de.current=a.height},onTransform:t=>{const e=t.target,o=le.current,r="middle-left"===o||"middle-right"===o,i="top-center"===o||"bottom-center"===o,n=y(e.scaleX());if(r){const t=e.width()*n,o=x(se.current,a.fontSize);let r=t;t<o&&(r=o,ae.current&&e.position(ae.current)),e.width(r),e.scaleX(1),e.scaleY(1);const i=Z(Object.assign(Object.assign({},a.toJSON()),{width:r}),{fontFamily:Pt,color:$t,textOverflow:E(a)}),s=P(i).height,l=v.textVerticalResizeEnabled?Math.max(s,Ot.current):s;e.height(l),a.set({width:e.width(),height:l,x:e.x(),y:e.y()})}else if(i){const t="resize"===E(a),o="number"==typeof a.lineHeight?a.lineHeight:1,r=t?Lt:o*a.fontSize,i=e.height()*e.scaleY();if(i<r){if(e.height(r),ae.current){if("top-center"===le.current){const t=ce.current*Math.PI/180,o=de.current-r;e.x(ae.current.x-o*Math.sin(t)),e.y(ae.current.y+o*Math.cos(t))}else{e.position(ae.current)}}}else{e.height(i)}e.scaleY(1),e.scaleX(1),de.current=Math.max(r,i),a.set({x:e.x(),y:e.y(),height:e.height(),rotation:e.rotation()})}else{e.scaleX(1),e.scaleY(1),a.set({fontSize:a.fontSize*n,letterSpacing:a.letterSpacing,width:e.width()*n,x:e.x(),y:e.y(),rotation:e.rotation(),height:e.height()*n,shadowBlur:a.shadowBlur*n,shadowOffsetX:a.shadowOffsetX*n,shadowOffsetY:a.shadowOffsetY*n,strokeWidth:a.strokeWidth*n,borderSize:a.borderSize*n,text:st(a.text,n)})}ae.current=t.target.position()},onTransformEnd:t=>{Et(!1),kt(!0);const e=y(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},u(a,a.fontSize*e)),{width:m(t.target.width()*e),x:m(t.target.x()),y:m(t.target.y()),rotation:m(t.target.rotation()),text:st(a.text,e)}))}}),t(l,Object.assign({ref:pt,image:wt,x:a.a.x,y:a.a.y,offsetX:jt,offsetY:jt-Zt,listening:!1,rotation:a.a.rotation,width:Ft,height:Ft*((null!==(ut=null==wt?void 0:wt.height)&&void 0!==ut?ut:0)/((null==wt?void 0:wt.width)||1)||1),visible:!Qt&&!It,opacity:n(a)},me,{shadowEnabled:ge,hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled||vt||Qt})),(Qt&&!It||he)&&t(s,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-Zt,children:t(H,{divProps:{style:{pointerEvents:"none"}},children:t(ct,{dangerouslySetInnerHTML:{__html:Tt},style:{pointerEvents:"none",opacity:a.a.opacity,textShadow:ge?`${a.shadowOffsetX}px ${a.shadowOffsetY}px ${a.shadowBlur}px ${dt(a.shadowColor,null!==(gt=a.shadowOpacity)&&void 0!==gt?gt:1)}`:void 0}})})}),It&&t(s,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-Zt,children:t(H,{divProps:{style:{zIndex:20}},children:t(lt,{element:a,onChange:t=>{const e=G({oldText:L(a.text),newText:L(t),element:a});a.set(Object.assign({text:t},h(a,e)))},onBlur:t=>{w(a)&&(a.set(g(a)),a.toggleEditMode(!1),Gt(!0))},clickCoords:fe.current})})})]})});
|
|
1
|
+
import{Fragment as t,jsx as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{toDisplayColor as i}from"@polotno/core/color";import{elementOpacity as n}from"./paint-opacity.js";import{observer as a}from"mobx-react-lite";import{Group as s,Image as l,Path as c,Rect as d}from"react-konva";import{activeAnchorOf as f,scaledFontSizeAttrs as h,roundedFontSizeAttrs as u,roundedTextDecorationAttrs as g,roundedGeometryPx as m,roundedPosition as p,textMinResizeWidth as x,transformScale as y}from"../utils/px.js";import b from"konva";import{isAlive as w}from"mobx-state-tree";import{nodeAutorun as S}from"../utils/mobx.js";import{flags as v}from"../utils/flags.js";import{textOverflowOf as E}from"../utils/text-sizing.js";import{layoutTextSizing as z,legacyTextOverflow as k,renderTagLayoutAt as O,resolveTextSizing as j}from"@polotno/core/text-sizing";import{applyFilter as F}from"./apply-filters.js";import{getLineHeight as M,useFontFamiliesLoader as R,usePrevious as Y}from"./text-element.js";import{getCurvePath as X}from"@polotno/core/text-html";import{useColor as C,withDisplayTextPaints as I}from"./use-color.js";import{useWorkspaceStyle as A}from"./workspace-style.js";import{detectSize as P,detectLineRects as $,htmlToCanvas as B}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as T}from"@polotno/core/background-shape";import{useFadeIn as W}from"./use-fadein.js";import{Html as H}from"react-konva-utils";import{incrementLoader as _,triggerLoadError as D}from"../utils/loader.js";import{removeTags as L}from"@polotno/core/text";import{cssFontFamily as J}from"@polotno/core/fonts";import{shadowCastByBackground as N}from"@polotno/core/filters";import*as q from"../utils/fonts.js";import{isTouchDevice as V}from"../utils/screen.js";import{getLimitedFontSize as G}from"./text-element/max-font-size.js";import{AutoDeleteEmptyText as K}from"./text-element/auto-delete-empty-text.js";import{useDelayer as Q}from"./use-delayer.js";import{geckoRtlOverhangCss as U,getHtml as Z,letterSpacingOverhang as tt,OVERHANG_PROPERTY as et,textLayoutWidth as ot}from"@polotno/core/text-html";import{hasMeasuredHeight as rt,resolveTextBoxHeight as it}from"@polotno/core/text-types";import{normalizeRichTextHtml as nt,extractFontFamiliesFromHtml as at,scaleRichTextFontSizesInHtml as st}from"../utils/rich-text-html.js";import{RichEditor as lt,RichTextContainer as ct,applyOpacityToColor as dt,quillRef as ft,createQuill as ht,setQuillContent as ut,setQuillFormats as gt,syncQuillFormatState as mt,setCursorFromCoords as pt}from"./rich-editor.js";export{ft as quillRef,ht as createQuill,ut as setQuillContent,gt as setQuillFormats,mt as syncQuillFormatState,pt as setCursorFromCoords};function xt(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const yt=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),bt=navigator.userAgent.includes("Firefox");export const HTMLElement=a(({element:a,store:ft})=>{var ht,ut,gt;const{textOverflowIndicatorStyle:mt}=A(),pt=r.useRef(null),[wt,St]=r.useState(),[vt,Et]=r.useState(!1),[zt,kt]=r.useState(!1),Ot=r.useRef(a.height),jt=a.fontSize/3,Ft=ot(a.a.width,a.letterSpacing,a.fontSize)+2*jt,{textVerticalResizeEnabled:Mt}=v,Rt=Y(a.fontFamily),Yt=r.useMemo(()=>nt(a.text,{fontSize:a.fontSize,fontFamily:a.fontFamily}),[a.text,a.fontSize,a.fontFamily]),Xt=r.useMemo(()=>[...new Set([a.fontFamily,...at(Yt)])].filter(Boolean),[a.fontFamily,Yt]),[Ct]=R(ft,Xt,a.fontStyle,a.fontWeight,a.text||a.placeholder),It=a._editModeEnabled,At=It&&!(null===(ht=a.page)||void 0===ht?void 0:ht._exporting);W(pt);const Pt=Ct?a.fontFamily:Rt!==a.fontFamily?Rt:"Arial",$t=C(a).fill,Bt=Z(I(a),{fontFamily:Pt,color:$t,textOverflow:E(a)}),Tt=function(t,e){return e&&/dir="rtl"|direction: rtl/.test(t)?`<div class="polotno-overhang" style="${et}: ${e}px">${t}</div><style>${U(".polotno-overhang [dir]:not(.polotno-overhang [dir] [dir])")}</style>`:t}(Bt,tt(a.letterSpacing,a.fontSize)),Wt=r.useRef([]),Ht=r.useRef(!0),[,_t]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=Wt.current;t.length>0&&(Wt.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{Ht.current=!1;const t=Wt.current;t.length>0&&(Wt.current=[],t.forEach(t=>t()))},[]);let{width:Dt,height:Lt}=function(t,e,o){return r.useMemo(()=>P(t),[t,e.width,o])}(Tt,a,Ct);r.useEffect(()=>{if(!Ct){return}const t=(t,e,o,r)=>{const i=_(`text ${a.id}`),n=()=>{ft.history.ignore(t,e,o).then(()=>{Ht.current?(Wt.current.push(i),_t()):i()})};r?queueMicrotask(n):n()};if(a.curveEnabled&&Math.abs(Dt-a.width)>1&&!vt&&t(()=>{if(w(a)&&Math.abs(Dt-a.width)>1){const t=a.x+a.width/2;a.set({width:Dt,x:t-Dt/2})}},!1,!0),!rt(a)){return void t(()=>{w(a)&&(rt(a)||a.set({height:Lt}))},void 0,void 0,!0)}const e=k(E(a));if("change-font-size"!==e||vt||It||a.curveEnabled){"resize"===e&&(Mt&&a.height<Lt&&!vt&&t(()=>{w(a)&&a.set({height:Lt})},!1,!0),Mt||a.height===Lt||vt||t(()=>{w(a)&&a.set({height:Lt})},!1,!0))}else{const o=z({element:a,sizing:j({text:a.text,width:a.width,height:a.height,fontSize:a.fontSize,maxLines:a.maxLines,curveEnabled:a.curveEnabled},{textOverflow:e,textSplitAllowed:v.textSplitAllowed}),layoutAt:O(a,{getHtmlOptions:{fontFamily:a.fontFamily}})});o.fontSize!==a.fontSize?t(()=>{if(!w(a)){return}const t=h(a,o.fontSize);o.text!==a.text&&(t.text=o.text),a.set(t)},!1,!0):a.height!==Lt&&(Mt&&a.height<Lt?t(()=>{w(a)&&a.set({height:Lt})},!1,!0):Mt||t(()=>{w(a)&&a.set({height:Lt})},!1,!0))}});const Jt=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await B(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),Nt=r.useRef(0),qt=r.useRef(null);r.useEffect(()=>{vt||At||(async()=>{Nt.current++;const t=Nt.current;let e=_(`text ${a.id} ${t}`);qt.current&&qt.current(),qt.current=e,kt(!0);let o=null;const r=yt?5:1;for(let n=0;n<r;n++){const e=n>0?Jt:B;try{if(o=await e({skipCache:n>0,html:Tt,width:Dt||a.width||1,height:it(a,Lt)||1,fontFamily:Pt,fontFamilies:at(Tt),resolveFont:t=>ft.fonts.find(e=>e.fontFamily===t)||q.globalFonts.find(e=>e.fontFamily===t),padding:jt,pixelRatio:ft._elementsPixelRatio,font:ft.fonts.find(t=>t.fontFamily===Pt)||q.globalFonts.find(t=>t.fontFamily===Pt)}),t!==Nt.current){return}if((yt||bt)&&o&&xt(o)){await new Promise(t=>setTimeout(t,50*(n+1)));continue}break}catch(i){console.error(i),D(`Error rendering rich text with id ${a.id}`);break}}o?St(o):e?(e(),e=null):console.error("Finish function is called twice!"),kt(!1)})()},[Tt,vt,Lt,At,Pt,a.height,ft._elementsPixelRatio,Ct]);const[Vt,Gt]=Q(zt,300),[Kt]=Q(vt,300,!0),Qt=Kt||Vt;r.useEffect(()=>{var t;if(!Qt){return S(a,()=>{const t=pt.current;F(t,a)})}null===(t=pt.current)||void 0===t||t.clearCache()},[wt,Qt,a.shadowColor,a.shadowOffsetX,a.shadowOffsetY,a.shadowOpacity]),r.useEffect(()=>{wt&&!zt&&qt.current&&(qt.current(),qt.current=null)},[wt,zt]),r.useLayoutEffect(()=>{if(!Ct){return}if(!a.curveEnabled){return}const t=new b.TextPath({data:X(a.a.width,a.a.height,a.curvePower,a.a.fontSize),text:L(a.text),letterSpacing:a.letterSpacing*a.a.fontSize,fontSize:a.a.fontSize,fontFamily:J(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,align:"center",textBaseline:"middle",fill:a.fill}),e=t.getSelfRect().width;if(e){const t=e-a.a.width,o=a.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{w(a)&&a.set({width:e,x:a.a.x+r,y:a.a.y+i})})}t.destroy()},[Ct,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),r.useEffect(()=>()=>{qt.current&&qt.current()},[]);const Ut=it(a,Lt);let Zt=0;"middle"===a.verticalAlign&&(Zt=(Ut-Lt)/2),"bottom"===a.verticalAlign&&(Zt=Ut-Lt);const te=M({fontLoaded:Ct,fontFamily:a.fontFamily,fontSize:a.fontSize,lineHeight:a.lineHeight}),ee=a.backgroundPadding*(a.fontSize*te*.5),oe=a.backgroundCornerRadius*(a.fontSize*te*.5),re=r.useMemo(()=>{if(!a.backgroundEnabled&&!a.borderSize||a.curveEnabled||a.legacyBackground){return""}const t=$(Bt);if(0===t.length){return""}const e=t.map(t=>({left:t.left+jt,right:t.right+jt,top:t.top+jt,bottom:t.bottom+jt}));return T({rects:e,padding:ee,cornerRadius:oe})},[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.legacyBackground,Bt,Ct,ee,oe,jt]),ie=V(),ne=X(a.a.width,Lt,a.curvePower,a.fontSize),ae=r.useRef(null),se=r.useRef(a.width),le=r.useRef(""),ce=r.useRef(0),de=r.useRef(0),fe=r.useRef(null),he=It&&a.strokeWidth>0&&!a.curveEnabled,ue=Dt>0?Ft/(Dt+2*jt):1,ge=a.shadowEnabled&&!N(a),me={shadowEnabled:a.shadowEnabled&&(N(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return o(t,{children:[e(K,{element:a,store:ft}),a.curveEnabled||a.legacyBackground?e(d,Object.assign({x:a.a.x,y:a.a.y,offsetX:ee/ue,offsetY:ee/ue,rotation:a.a.rotation,scaleX:ue,scaleY:ue,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled||a.borderSize>0,opacity:n(a),fillEnabled:a.backgroundEnabled,fill:dt(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,width:a.width+2*ee,height:Ut+2*ee,cornerRadius:oe},me)):e(c,Object.assign({name:"html-background",x:a.a.x,y:a.a.y,offsetX:jt/ue,offsetY:(jt-Zt)/ue,rotation:a.a.rotation,scaleX:ue,scaleY:ue,hideInExport:!a.showInExport,listening:!1,visible:(a.backgroundEnabled||a.borderSize>0)&&re.length>0,opacity:n(a),fillEnabled:a.backgroundEnabled,fill:dt(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:oe>0?"round":"miter",data:re},me)),e(c,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,data:ne,stroke:mt.stroke,strokeWidth:1,visible:!1}),e(d,{ref:pt,name:"element",x:a.a.x,y:a.a.y,listening:a.selectable,rotation:a.a.rotation,width:a.a.width,height:a.a.height,visible:!Qt,draggable:ie?a.draggable&&a.isSelected:a.draggable,preventDefault:!ie||a.isSelected,opacity:It?0:n(a),hideInExport:!a.showInExport,onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{a.set(p(t.target))},id:a.id,onDblClick:t=>{a.contentEditable&&(fe.current={x:t.evt.clientX,y:t.evt.clientY},a.toggleEditMode(!0))},onDblTap:t=>{var e;if(a.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];fe.current=o?{x:o.clientX,y:o.clientY}:null,a.toggleEditMode(!0)}},onTransformStart:t=>{Et(!0),Ot.current=a.height,se.current=a.width,ae.current=t.target.position(),le.current=f(t.target),ce.current=a.a.rotation,de.current=a.height},onTransform:t=>{const e=t.target,o=le.current,r="middle-left"===o||"middle-right"===o,i="top-center"===o||"bottom-center"===o,n=y(e.scaleX());if(r){const t=e.width()*n,o=x(se.current,a.fontSize);let r=t;t<o&&(r=o,ae.current&&e.position(ae.current)),e.width(r),e.scaleX(1),e.scaleY(1);const i=Z(Object.assign(Object.assign({},a.toJSON()),{width:r}),{fontFamily:Pt,color:$t,textOverflow:E(a)}),s=P(i).height,l=v.textVerticalResizeEnabled?Math.max(s,Ot.current):s;e.height(l),a.set({width:e.width(),height:l,x:e.x(),y:e.y()})}else if(i){const t="resize"===E(a),o="number"==typeof a.lineHeight?a.lineHeight:1,r=t?Lt:o*a.fontSize,i=e.height()*e.scaleY();if(i<r){if(e.height(r),ae.current){if("top-center"===le.current){const t=ce.current*Math.PI/180,o=de.current-r;e.x(ae.current.x-o*Math.sin(t)),e.y(ae.current.y+o*Math.cos(t))}else{e.position(ae.current)}}}else{e.height(i)}e.scaleY(1),e.scaleX(1),de.current=Math.max(r,i),a.set({x:e.x(),y:e.y(),height:e.height(),rotation:e.rotation()})}else{e.scaleX(1),e.scaleY(1),a.set({fontSize:a.fontSize*n,letterSpacing:a.letterSpacing,width:e.width()*n,x:e.x(),y:e.y(),rotation:e.rotation(),height:e.height()*n,shadowBlur:a.shadowBlur*n,shadowOffsetX:a.shadowOffsetX*n,shadowOffsetY:a.shadowOffsetY*n,strokeWidth:a.strokeWidth*n,borderSize:a.borderSize*n,text:st(a.text,n)})}ae.current=t.target.position()},onTransformEnd:t=>{Et(!1),kt(!0);const e=y(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},u(a,a.fontSize*e)),{width:m(t.target.width()*e),x:m(t.target.x()),y:m(t.target.y()),rotation:m(t.target.rotation()),text:st(a.text,e)}))}}),e(l,Object.assign({ref:pt,image:wt,x:a.a.x,y:a.a.y,offsetX:jt,offsetY:jt-Zt,listening:!1,rotation:a.a.rotation,width:Ft,height:Ft*((null!==(ut=null==wt?void 0:wt.height)&&void 0!==ut?ut:0)/((null==wt?void 0:wt.width)||1)||1),visible:!Qt&&!It,opacity:n(a)},me,{shadowEnabled:ge,hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled||vt||Qt})),(Qt&&!It||he)&&e(s,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-Zt,children:e(H,{divProps:{style:{pointerEvents:"none"}},children:e(ct,{dangerouslySetInnerHTML:{__html:Tt},style:{pointerEvents:"none",opacity:a.a.opacity,textShadow:ge?`${a.shadowOffsetX}px ${a.shadowOffsetY}px ${a.shadowBlur}px ${dt(a.shadowColor,null!==(gt=a.shadowOpacity)&&void 0!==gt?gt:1)}`:void 0}})})}),It&&e(s,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-Zt,children:e(H,{divProps:{style:{zIndex:20}},children:e(lt,{element:a,onChange:t=>{const e=G({oldText:L(a.text),newText:L(t),element:a});a.set(Object.assign({text:t},h(a,e)))},onBlur:t=>{w(a)&&(a.set(g(a)),a.toggleEditMode(!1),Gt(!0))},clickCoords:fe.current})})})]})});
|
|
@@ -2,53 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import { StoreType } from '../model/store.js';
|
|
3
3
|
import { ImageElementType } from '../model/image-model.js';
|
|
4
4
|
import { type ImageStatus } from './use-image.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
height: number;
|
|
9
|
-
deviceWidth: number;
|
|
10
|
-
deviceHeight: number;
|
|
11
|
-
phaseX: number;
|
|
12
|
-
phaseY: number;
|
|
13
|
-
spanX: number;
|
|
14
|
-
spanY: number;
|
|
15
|
-
aligned: boolean;
|
|
16
|
-
} | {
|
|
17
|
-
position: {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
};
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
deviceWidth: number;
|
|
24
|
-
deviceHeight: number;
|
|
25
|
-
phaseX: number;
|
|
26
|
-
phaseY: number;
|
|
27
|
-
spanX: number;
|
|
28
|
-
spanY: number;
|
|
29
|
-
aligned: boolean;
|
|
30
|
-
};
|
|
5
|
+
import { maskCompositeSize, svgSourceRatio } from '@polotno/core/image-buffer';
|
|
6
|
+
export { maskCompositeSize, svgSourceRatio };
|
|
7
|
+
declare const alignToPixelGrid: (element: ImageElementType, pixelRatio: number, ratio: number, enabled: boolean) => import("@polotno/core/image-buffer").PixelGridAlignment;
|
|
31
8
|
export declare const useSizeFixer: (src: string) => string;
|
|
32
|
-
export declare function svgSourceRatio(element: {
|
|
33
|
-
cropWidth: number;
|
|
34
|
-
cropHeight: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
}, image: {
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
}, svgPixelRatio: number): number;
|
|
41
|
-
export declare function maskCompositeSize(shapeRaster: {
|
|
42
|
-
width: number;
|
|
43
|
-
height: number;
|
|
44
|
-
}, element: {
|
|
45
|
-
width: number;
|
|
46
|
-
height: number;
|
|
47
|
-
stretchEnabled?: boolean;
|
|
48
|
-
}): {
|
|
49
|
-
width: number;
|
|
50
|
-
height: number;
|
|
51
|
-
};
|
|
52
9
|
export declare const useCornerRadiusAndCrop: (element: ImageElementType, image: HTMLImageElement | HTMLCanvasElement | undefined, crop: {
|
|
53
10
|
x: number;
|
|
54
11
|
y: number;
|
|
@@ -64,11 +21,10 @@ type ImageProps = {
|
|
|
64
21
|
element: ImageOrSVGElementType;
|
|
65
22
|
};
|
|
66
23
|
export declare const setImageLoaderHook: (customImageLoaderHook: any) => void;
|
|
67
|
-
export declare const useCanvasImage: (src: string, crossOrigin?:
|
|
24
|
+
export declare const useCanvasImage: (src: string, crossOrigin?: 'anonymous' | 'use-credentials') => [HTMLImageElement | undefined, ImageStatus];
|
|
68
25
|
export declare const useSizedImage: (src: string) => readonly [HTMLImageElement | undefined, ImageStatus];
|
|
69
26
|
export declare const useClipImage: (src: string) => readonly [HTMLImageElement | undefined, ImageStatus];
|
|
70
27
|
export declare const useImageLoader: (status: string, src?: string, id?: string) => void;
|
|
71
28
|
export declare const ImageElement: (({ element, store }: ImageProps) => React.JSX.Element) & React.NamedExoticComponent<ImageProps> & {
|
|
72
29
|
readonly type: ({ element, store }: ImageProps) => React.JSX.Element;
|
|
73
30
|
};
|
|
74
|
-
export {};
|