polotno 3.20.1 → 3.22.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/THIRD_PARTY_NOTICES.md +8 -8
- package/blueprint/side-panel/select-video.d.ts +74 -0
- package/blueprint.polotno.css +165 -230
- package/canvas/crop-overlay.d.ts +20 -8
- package/canvas/crop-overlay.js +1 -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 +28 -4
- package/canvas/gif-element.js +1 -1
- package/canvas/image-element.js +1 -1
- package/canvas/lottie-element.js +1 -1
- package/canvas/lottie-player.wasm.js +1 -1
- package/canvas/media-resize.d.ts +19 -0
- package/canvas/media-resize.js +1 -0
- package/canvas/page.js +1 -1
- package/canvas/quill-font-formats.d.ts +1 -1
- package/canvas/quill-font-formats.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.js +3 -5
- package/canvas/text-element/render-tag-source.d.ts +5 -0
- package/canvas/text-element/render-tag-source.js +1 -1
- package/canvas/tooltip.js +1 -1
- package/canvas/use-color.js +1 -1
- package/canvas/use-mediabunny-video.js +1 -1
- package/canvas/video-element.js +1 -1
- package/canvas/workspace-canvas.js +1 -1
- package/config.d.ts +1 -1
- package/config.js +1 -1
- package/icons/registry.d.ts +7 -0
- package/icons/registry.js +1 -1
- package/image-tools/host.d.ts +3 -0
- package/image-tools/sessions.js +1 -1
- package/image-tools/target.d.ts +5 -0
- package/image-tools/target.js +1 -1
- package/image-tools/types.d.ts +5 -0
- package/model/crop-mode.d.ts +3 -0
- package/model/crop-mode.js +1 -1
- package/model/figure-model.d.ts +29 -0
- package/model/gif-model.d.ts +40 -0
- package/model/group-model.d.ts +304 -2
- package/model/group-model.js +1 -1
- package/model/history.js +1 -1
- package/model/image-model.d.ts +40 -0
- package/model/image-model.js +1 -1
- package/model/line-model.d.ts +29 -0
- package/model/lottie-model.d.ts +40 -0
- package/model/node-model.d.ts +32 -0
- package/model/node-model.js +1 -1
- package/model/page-model.d.ts +912 -6
- package/model/shape-model.d.ts +29 -0
- package/model/shape-model.js +1 -1
- package/model/store.d.ts +61 -2
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +27 -0
- package/model/table-model.d.ts +37 -1
- package/model/table-model.js +1 -1
- package/model/text-model.d.ts +29 -1
- package/model/text-model.js +1 -1
- package/model/video-model.d.ts +40 -0
- package/package.json +25 -27
- package/polotno.bundle.js +240 -238
- package/primitives/autocomplete.d.ts +11 -0
- package/primitives/autocomplete.js +1 -0
- package/primitives/select.js +1 -1
- package/side-panel/index.d.ts +1 -0
- package/side-panel/index.js +1 -1
- package/side-panel/layers-panel.js +1 -1
- package/side-panel/select-image.js +1 -1
- package/side-panel/select-video.d.ts +74 -0
- package/side-panel/select-video.js +1 -1
- package/side-panel/variables-panel.d.ts +10 -0
- package/side-panel/variables-panel.js +1 -0
- package/side-panel/videos-grid.d.ts +1 -1
- package/side-panel/videos-grid.js +1 -1
- package/toolbar/color-picker.d.ts +8 -0
- package/toolbar/color-picker.js +1 -1
- package/toolbar/download-button.js +1 -1
- package/toolbar/element-container.d.ts +6 -0
- package/toolbar/element-container.js +1 -1
- package/toolbar/figure-toolbar.d.ts +8 -9
- package/toolbar/figure-toolbar.js +1 -1
- package/toolbar/gif-toolbar.d.ts +4 -5
- package/toolbar/gif-toolbar.js +1 -1
- package/toolbar/group-toolbar.d.ts +2 -3
- package/toolbar/group-toolbar.js +1 -1
- package/toolbar/image-toolbar.d.ts +11 -12
- package/toolbar/image-toolbar.js +1 -1
- package/toolbar/index.d.ts +1 -0
- package/toolbar/index.js +1 -1
- package/toolbar/line-toolbar.js +1 -1
- package/toolbar/many-toolbar.d.ts +2 -3
- package/toolbar/many-toolbar.js +1 -1
- package/toolbar/page-toolbar.d.ts +2 -3
- package/toolbar/page-toolbar.js +1 -1
- package/toolbar/svg-toolbar.d.ts +2 -3
- package/toolbar/svg-toolbar.js +1 -1
- package/toolbar/text-toolbar.js +1 -1
- package/toolbar/text-variables.d.ts +15 -0
- package/toolbar/text-variables.js +1 -0
- package/toolbar/toolbar.js +1 -1
- package/toolbar/video-toolbar.js +1 -1
- package/ui.css +1 -1
- package/utils/animations.js +1 -1
- package/utils/clipboard.d.ts +54 -2
- package/utils/l10n.d.ts +32 -0
- package/utils/l10n.js +1 -1
- package/utils/selection-transform.js +1 -1
- package/utils/use-api.d.ts +1 -1
- package/utils/use-api.js +1 -1
- package/utils/validate-key.js +1 -1
package/canvas/video-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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 c}from"../utils/mobx.js";import{Group as h,Image as l,Rect as u}from"react-konva";import{ROLES as m}from"../model/store.js";import{DEFAULT_RETRIES as p,isDeterministicUrl as g,retryDelayMs as f}from"@polotno/core/retry";import v from"konva";import{ErrorPlaceholder as w,LoadingPlaceholder as x}from"./media-placeholders.js";import{incrementLoader as E,triggerLoadError as M}from"../utils/loader.js";import{polotnoError as L}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as C from"@polotno/core/svg";import{activeAnchorOf as b,roundedCropFraction as T,roundedGeometryPx as k,roundedPosition as j,isCornerAnchor as R,scaledStyleAttrs as I,roundedStyleAttrs as S,transformScale as P}from"../utils/px.js";import{useFilteredSource as H}from"./use-filtered-source.js";import{useOffscreenCanvas as W}from"./use-offscreen-canvas.js";import{useEvent as _}from"../hooks/use-event.js";import{useFadeIn as A}from"./use-fadein.js";import{useAnimatedBlur as X}from"./use-animated-blur.js";import{isTouchDevice as Y}from"../utils/screen.js";import{createPlayGate as V,playMedia as D}from"../utils/media.js";import{useMediabunnyVideo as O}from"./use-mediabunny-video.js";import{getElementTimeRange as F,getVideoRestMs as z,isHeldByPreview as U}from"../utils/timeline.js";import{drawReduced as Z,exportKernelEnabled as N,shouldResample as q,sourceSize as $}from"./downscale.js";import{trySetCanvasSize as B}from"../utils/canvas.js";import{useClipImage as G}from"./image-element.js";import{CropOverlay as J,CROP_CORNER_ANCHORS as K}from"./crop-overlay.js";const Q=new window.Image;Q.src=C.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const ee=new window.Image;ee.src=C.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useFlip=(e,t)=>{const{flipX:r,flipY:o}=e,{width:i,height:n}=t?$(t):{},a=e=>{if(!t){return}const i=e.getContext("2d");i&&(i.clearRect(0,0,e.width,e.height),i.save(),i.scale(r?-1:1,o?-1:1),i.drawImage(t,r?-e.width:0,o?-e.height:0,e.width,e.height),i.restore())},s=W((r||o)&&!!i&&!!n,e=>{i&&n&&(e.width=i,e.height=n,a(e))},[r,o,t,i,n]);return[s||t,()=>{s&&a(s)}]};export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var s;const d=Math.floor(Math.max(e.a.width*o,1)),c=Math.floor(Math.max(e.a.height*o,1)),h=Math.min(n*o,d/2,c/2),l=Math.max(e.a.width/r.width,e.a.height/r.height)*o,u=N(e.page)&&!a&&q(l,d,c),{width:m,height:p}=t?$(t):{},g=0===r.x&&0===r.y&&r.width===m&&r.height===p,f=i.useMemo(()=>{if(t&&m&&p){return g&&0===h&&!u?void 0:document.createElement("canvas")}},[t,h,u,g,m,p]),w=()=>{if(!f||!t){return}f.width=d,f.height=c;const e=f.getContext("2d");e&&(h&&(e.beginPath(),e.moveTo(h,0),e.lineTo(d-h,0),e.arc(d-h,h,h,3*Math.PI/2,0,!1),e.lineTo(d,c-h),e.arc(d-h,c-h,h,0,Math.PI/2,!1),e.lineTo(h,c),e.arc(h,c-h,h,Math.PI/2,Math.PI,!1),e.lineTo(0,h),e.arc(h,h,h,Math.PI,3*Math.PI/2,!1),e.clip()),u?Z(e,t,r,f.width,f.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,f.width,f.height))};return i.useLayoutEffect(()=>{w()},[f,e.a.width,e.a.height,r.x,r.y,r.width,r.height,n,o,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,u]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};export const useClip=(e,t,r,o)=>{const[n,a]=G(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,c=i.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),h=null==c?void 0:c.canvas;function l(){if(!c||!h||!t){return}const{width:o,height:i}=$(t);if(!o||!i){return}const n=Math.min(1e4,Math.max(o,Math.ceil(e.a.width*r),1)),a=Math.min(1e4,Math.max(i,Math.ceil(e.a.height*r),1));h.width&&c.width===n&&c.height===a||(B(h,n,a),c.width=n,c.height=a);const s=h.getContext("2d");s&&(s.clearRect(0,0,h.width,h.height),s.save(),s.drawImage(t,0,0,h.width,h.height),s.globalCompositeOperation="destination-in",s.drawImage(c.mask,0,0,h.width,h.height),s.restore())}return i.useLayoutEffect(()=>{var t;if(!c||!(null==n?void 0:n.width)||!n.height){return}const o=Math.max(e.a.width/n.width*r,e.a.height/n.height*r);B(c.mask,Math.min(1e4,Math.max(n.width*o,1)),Math.min(1e4,Math.max(n.height*o,1))),null===(t=c.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,c.mask.width,c.mask.height)},[c,n,e.a.width,e.a.height,r]),i.useLayoutEffect(()=>{l()},[c,t,n,e.a.width,e.a.height,r,...o]),i.useEffect(()=>()=>{c&&v.Util.releaseCanvas(c.canvas,c.mask)},[c]),[d?h:t,l]};const te=document.createElement("canvas");let re=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,s]=i.useState(0),d=i.useRef(void 0),c=i.useRef(void 0),h=i.useRef(void 0);return d.current===e&&c.current===t&&h.current===r||(o.current="loading",n.current=void 0,d.current=e,c.current=t,h.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=g(e)?1:p;let a,d,c,h=0,l=!1,u=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{h+=1;const p=document.createElement("video");function g(){l||(p.removeEventListener("canplay",g),u=!0,o.current="loaded",n.current=p,p.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===p.readyState,c=p.buffered&&p.buffered.length>0&&p.buffered.end(p.buffered.length-1)/p.duration*100>=100;if(r&&c){return}if(l){return}if(!u&&h<i){return null==d||d(),m(p),void(a=setTimeout(v,f(h)))}const g=e.message||(null===(t=p.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+g)),o.current="failed",n.current=void 0,s(Math.random())}c=p,p.addEventListener("canplay",g),p.addEventListener("error",w),d=()=>{p.removeEventListener("canplay",g),p.removeEventListener("error",w)},t&&(p.crossOrigin=t),r&&(p.referrerPolicy=r),p.src=e,p.load()};return v(),()=>{l=!0,clearTimeout(a),null==d||d(),u||m(c)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{re=e};function oe(e){return!e.seeking&&e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=E(a)),"loading"!==e&&n(),"failed"===e&&M(L("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:p})=>{var g,f,M,L,C;const[W,Z]=i.useState(!1),N=i.useRef(null),q=Y(),[B,G]=i.useState(!1),[ie,ne]=re(s.src,"anonymous"),[ae,se]=i.useState(!1),de=p.activePage===s.page,ce=(null===(g=s.page)||void 0===g?void 0:g._exportingOrRendering)&&"loaded"===ne,he=O(s,p,ce);useLoader(ne,s.src,s.id),ie&&(ie.playsInline=!0);const le=ce&&he||ie,[ue,me]=useFlip(s,le),[pe=te,ge]=H(s,ue||te);i.useEffect(()=>{ie&&p.history.ignore(()=>{s.set({duration:1e3*ie.duration})})},[ie]);const fe=i.useMemo(V,[ie]);i.useEffect(()=>{var e;if(!ie){return}const t=!U(s)&&p.isPlaying;if(!de||!t&&!B){return void ie.pause()}B&&(ie.muted=!1,ie.currentTime=s.startTime*ie.duration,D(ie).then(e=>{"refused"===e&&G(!1)}));const r=new v.Animation(()=>{Ae()},null===(e=N.current)||void 0===e?void 0:e.getLayer());r.start();const o=()=>{G(!1),ie.currentTime=s.startTime*ie.duration},i=()=>{ie.currentTime>=s.endTime*ie.duration&&(ie.pause(),ie.currentTime=s.startTime*ie.duration,G(!1))};return ie.addEventListener("ended",o),ie.addEventListener("timeupdate",i),()=>{ie.pause(),r.stop(),ie.removeEventListener("ended",o),ie.removeEventListener("timeupdate",i)}},[ie,B,p.isPlaying,de]),i.useEffect(()=>{ie&&(ie.volume=s.volume)},[ie,s.volume]),i.useEffect(()=>{ie&&(ie.playbackRate=s.speed,ie.preservesPitch=!1)},[ie,s.speed]);const ve=i.useRef(null);i.useEffect(()=>{const e=c(s,()=>{var e,t;if(ie){if(ce&&he){return Ae(),void p.currentTime}if(U(s)){return}const r=p.activePage===s.page,o=s.page._mediaLocalTime,i=s.startTime*ie.duration*1e3,n=ie.duration*(s.endTime-s.startTime)*1e3,{start:a,end:d}=F(s.animations,s.page.duration),c=z(null!=o?o:0,0,a,n,i,s.speed,{windowEnd:d,frameMs:p._renderFrameMs,renderEnd:p._renderEndMs-s.page.startTime}),h=c/1e3,l=null!==o&&o>=a&&o<d;B||(ie.muted=!l,l&&p.isPlaying&&r?ie.paused?(ie.currentTime=h,fe.play(ie)):Math.abs(1e3*ie.currentTime-c)>500&&(ie.currentTime=h):(fe.reset(),ie.paused||ie.pause(),h!==ie.currentTime&&(ie.currentTime=h),!oe(ie)&&!p.isPlaying&&!ve.current&&(ve.current=E(`video ${s.id}`)))),Ae(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ve.current&&(ve.current(),ve.current=null)}},[p,ie,ce,he,B]),i.useEffect(()=>{var e,t;if(!ie){return}if(ce){return null===(e=ve.current)||void 0===e||e.call(ve),void(ve.current=null)}const r=()=>{var e;null===(e=ve.current)||void 0===e||e.call(ve),ve.current=null},o=()=>{oe(ie)&&(Ae(),r())};let i,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(o,20)),ie.addEventListener("timeupdate",o),ie.addEventListener("canplay",o),ie.addEventListener("seeked",o);const a=()=>{ie.paused&&(Ae(),oe(ie)&&r()),n=ie.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in ie&&(n=ie.requestVideoFrameCallback(a)),()=>{clearInterval(i),void 0!==n&&ie.cancelVideoFrameCallback(n),ie.removeEventListener("timeupdate",o),ie.removeEventListener("canplay",o),ie.removeEventListener("seeked",o)}},[null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering,ie,s.id,E,ce]);let{cropX:we,cropY:xe,cropWidth:Ee,cropHeight:Me}=s.a;"loaded"!==ne&&(we=xe=0,Ee=Me=1);const{width:Le,height:ye}=$(pe),Ce=null!==(M=null==ie?void 0:ie.videoWidth)&&void 0!==M?M:0,be=null!==(L=null==ie?void 0:ie.videoHeight)&&void 0!==L?L:0;i.useLayoutEffect(()=>{"loaded"===ne&&Ce>0&&be>0&&s._setSourceSize({width:Ce,height:be},s.src)},[s,s.src,ne,Ce,be]);const Te=y({stretchEnabled:s.stretchEnabled,cropX:we,cropY:xe,cropWidth:Ee,cropHeight:Me,width:s.a.width,height:s.a.height},{width:Le,height:ye}),ke=Te.width,je=Te.height,Re=s.stretchEnabled,Ie=null!==(C=s.cornerRadius)&&void 0!==C?C:0,[Se,Pe]=useCornerRadiusAndCrop(s,pe,Te,p._elementsPixelRatio,Ie,!0);let[He,We]=useClip(s,Se,p._elementsPixelRatio,[Te,Ie,p._elementsPixelRatio]);const _e=X(N,s,He),Ae=_(()=>{var e,t;me(),ge(),Pe(),We(),_e(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Ae()});const Xe=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},Ye="loading"===ne,Ve="failed"===ne,De=!Ye&&!Ve,Oe=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Fe=i.useRef(!1),ze=De?o(s):0;A(N,ze);const Ue=s.selectable||p.role===m.ADMIN;return t(e,{children:r(h,{onMouseEnter:()=>se(!0),onMouseLeave:()=>se(!1),children:[Ye&&t(x,{element:s}),Ve&&t(w,{element:s,text:"Can not load the video..."}),t(l,Object.assign({ref:N,name:"element",id:s.id,image:He,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:ze},a(s),{customCrop:Te,listening:Ue,draggable:q?s.draggable&&s.isSelected:s.draggable,preventDefault:!q||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(j(e.target))},onDblClick:Xe,onDblTap:Xe,onTransformStart:e=>{Z(!0),Fe.current=R(b(e.target)),Oe.current={cropX:s.cropX,cropY:s.cropY,cropWidth:s.cropWidth,cropHeight:s.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=P(t.scaleX()),o=P(t.scaleY());t.scaleX(1),t.scaleY(1);const i=1-ke/Le,n=Math.min(i,Math.max(0,s.cropX)),a=1-je/ye,d=Math.min(a,Math.max(0,s.cropY)),c=Fe.current,h=!c&&r<1&&Oe.current.cropHeight>je/ye;let l=c?s.cropWidth:s.cropWidth*r;h&&(l=s.cropWidth);const u=!c&&o<1&&Oe.current.cropWidth>ke/Le;let m=c?s.cropHeight:s.cropHeight*o;u&&(m=s.cropHeight),Re&&(l=s.cropWidth,m=s.cropHeight);const p=c?Math.min(r,o):1;s.set(Object.assign({cropX:n,cropY:d,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*o,rotation:e.target.rotation(),cropWidth:Math.min(l,1-n),cropHeight:Math.min(m,1-d)},1!==p&&I(s,p)))},onTransformEnd:e=>{const t=e.currentTarget;s.set(Object.assign({width:k(t.width()),height:k(t.height()),x:k(t.x()),y:k(t.y()),rotation:k(e.target.rotation()),cropX:T(s.cropX),cropY:T(s.cropY),cropWidth:T(ke/Le),cropHeight:T(je/ye)},S(s))),Z(!1)}})),!!s.borderSize&&t(u,{x:s.a.x,y:s.a.y,width:Math.max(s.a.width-s.borderSize,0),height:Math.max(s.a.height-s.borderSize,0),opacity:ze,offsetX:-s.borderSize/2,offsetY:-s.borderSize/2,stroke:n(s.borderColor),strokeWidth:s.borderSize,listening:!1,rotation:s.a.rotation,cornerRadius:Math.max(0,Ie-s.borderSize),hideInExport:!s.showInExport}),!p.isPlaying&&t(l,{image:B?ae||q?ee:void 0:Q,x:s.a.x,y:s.a.y,offsetX:-s.a.width/2+15/p.scale,offsetY:-s.a.height/2+15/p.scale,rotation:s.a.rotation,width:30/p.scale,height:30/p.scale,hideInExport:!0,onClick:()=>G(!B),onTap:()=>G(!B)}),s._cropModeEnabled&&"loaded"===ne&&t(J,{element:s,store:p,previewImage:He,sourceImage:pe,sourceWidth:Le,sourceHeight:ye,cropAbsoluteWidth:ke,cropAbsoluteHeight:je,innerAnchors:K})]})})});
|
|
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{Group as c,Image as u,Rect as h}from"react-konva";import{ROLES as m}from"../model/store.js";import{DEFAULT_RETRIES as p,isDeterministicUrl as g,retryDelayMs as f}from"@polotno/core/retry";import v from"konva";import{ErrorPlaceholder as w,LoadingPlaceholder as x}from"./media-placeholders.js";import{incrementLoader as E,triggerLoadError as L}from"../utils/loader.js";import{polotnoError as M}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as C from"@polotno/core/svg";import{roundedPosition as b}from"../utils/px.js";import{useMediaResize as k}from"./media-resize.js";import{useFilteredSource as T}from"./use-filtered-source.js";import{useOffscreenCanvas as j}from"./use-offscreen-canvas.js";import{useEvent as I}from"../hooks/use-event.js";import{useFadeIn as R}from"./use-fadein.js";import{useAnimatedBlur as S}from"./use-animated-blur.js";import{isTouchDevice as P}from"../utils/screen.js";import{createPlayGate as _,playMedia as A}from"../utils/media.js";import{useMediabunnyVideo as V}from"./use-mediabunny-video.js";import{getElementTimeRange as D,getVideoRestMs as z,isHeldByPreview as F}from"../utils/timeline.js";import{drawReduced as O,exportKernelEnabled as H,shouldResample as U,sourceSize as Z}from"./downscale.js";import{trySetCanvasSize as W}from"../utils/canvas.js";import{useClipImage as X}from"./image-element.js";import{CropOverlay as Y,CROP_CORNER_ANCHORS as N}from"./crop-overlay.js";const q=new window.Image;q.src=C.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const $=new window.Image;$.src=C.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useFlip=(e,t)=>{const{flipX:r,flipY:o}=e,{width:i,height:n}=t?Z(t):{},a=e=>{if(!t){return}const i=e.getContext("2d");i&&(i.clearRect(0,0,e.width,e.height),i.save(),i.scale(r?-1:1,o?-1:1),i.drawImage(t,r?-e.width:0,o?-e.height:0,e.width,e.height),i.restore())},s=j((r||o)&&!!i&&!!n,e=>{i&&n&&(e.width=i,e.height=n,a(e))},[r,o,t,i,n]);return[s||t,()=>{s&&a(s)}]};export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var s;const d=Math.floor(Math.max(e.a.width*o,1)),l=Math.floor(Math.max(e.a.height*o,1)),c=Math.min(n*o,d/2,l/2),u=Math.max(e.a.width/r.width,e.a.height/r.height)*o,h=H(e.page)&&!a&&U(u,d,l),{width:m,height:p}=t?Z(t):{},g=0===r.x&&0===r.y&&r.width===m&&r.height===p,f=i.useMemo(()=>{if(t&&m&&p){return g&&0===c&&!h?void 0:document.createElement("canvas")}},[t,c,h,g,m,p]),w=()=>{if(!f||!t){return}f.width=d,f.height=l;const e=f.getContext("2d");e&&(c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(d-c,0),e.arc(d-c,c,c,3*Math.PI/2,0,!1),e.lineTo(d,l-c),e.arc(d-c,l-c,c,0,Math.PI/2,!1),e.lineTo(c,l),e.arc(c,l-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip()),h?O(e,t,r,f.width,f.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,f.width,f.height))};return i.useLayoutEffect(()=>{w()},[f,e.a.width,e.a.height,r.x,r.y,r.width,r.height,n,o,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,h]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};export const useClip=(e,t,r,o)=>{const[n,a]=X(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,l=i.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),c=null==l?void 0:l.canvas;function u(){if(!l||!c||!t){return}const{width:o,height:i}=Z(t);if(!o||!i){return}const n=Math.min(1e4,Math.max(o,Math.ceil(e.a.width*r),1)),a=Math.min(1e4,Math.max(i,Math.ceil(e.a.height*r),1));c.width&&l.width===n&&l.height===a||(W(c,n,a),l.width=n,l.height=a);const s=c.getContext("2d");s&&(s.clearRect(0,0,c.width,c.height),s.save(),s.drawImage(t,0,0,c.width,c.height),s.globalCompositeOperation="destination-in",s.drawImage(l.mask,0,0,c.width,c.height),s.restore())}return i.useLayoutEffect(()=>{var t;if(!l||!(null==n?void 0:n.width)||!n.height){return}const o=Math.max(e.a.width/n.width*r,e.a.height/n.height*r);W(l.mask,Math.min(1e4,Math.max(n.width*o,1)),Math.min(1e4,Math.max(n.height*o,1))),null===(t=l.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,l.mask.width,l.mask.height)},[l,n,e.a.width,e.a.height,r]),i.useLayoutEffect(()=>{u()},[l,t,n,e.a.width,e.a.height,r,...o]),i.useEffect(()=>()=>{l&&v.Util.releaseCanvas(l.canvas,l.mask)},[l]),[d?c:t,u]};const B=document.createElement("canvas");let G=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,s]=i.useState(0),d=i.useRef(void 0),l=i.useRef(void 0),c=i.useRef(void 0);return d.current===e&&l.current===t&&c.current===r||(o.current="loading",n.current=void 0,d.current=e,l.current=t,c.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=g(e)?1:p;let a,d,l,c=0,u=!1,h=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{c+=1;const p=document.createElement("video");function g(){u||(p.removeEventListener("canplay",g),h=!0,o.current="loaded",n.current=p,p.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===p.readyState,l=p.buffered&&p.buffered.length>0&&p.buffered.end(p.buffered.length-1)/p.duration*100>=100;if(r&&l){return}if(u){return}if(!h&&c<i){return null==d||d(),m(p),void(a=setTimeout(v,f(c)))}const g=e.message||(null===(t=p.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+g)),o.current="failed",n.current=void 0,s(Math.random())}l=p,p.addEventListener("canplay",g),p.addEventListener("error",w),d=()=>{p.removeEventListener("canplay",g),p.removeEventListener("error",w)},t&&(p.crossOrigin=t),r&&(p.referrerPolicy=r),p.src=e,p.load()};return v(),()=>{u=!0,clearTimeout(a),null==d||d(),h||m(l)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{G=e};function J(e){return!e.seeking&&e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=E(a)),"loading"!==e&&n(),"failed"===e&&L(M("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:p})=>{var g,f,L,M,C;const[j,O]=i.useState(!1),H=i.useRef(null),U=P(),[W,X]=i.useState(!1),[K,Q]=G(s.a.src,"anonymous"),[ee,te]=i.useState(!1),re=p.activePage===s.page,oe=(null===(g=s.page)||void 0===g?void 0:g._exportingOrRendering)&&"loaded"===Q,ie=V(s,p,oe);useLoader(Q,s.a.src,s.id),K&&(K.playsInline=!0);const ne=oe&&ie||K,[ae,se]=useFlip(s,ne),[de=B,le]=T(s,ae||B);i.useEffect(()=>{K&&p.history.ignore(()=>{s.set({duration:1e3*K.duration})})},[K]);const ce=i.useMemo(_,[K]);i.useEffect(()=>{var e;if(!K){return}const t=!F(s)&&p.isPlaying;if(!re||!t&&!W){return void K.pause()}W&&(K.muted=!1,K.currentTime=s.startTime*K.duration,A(K).then(e=>{"refused"===e&&X(!1)}));const r=new v.Animation(()=>{Te()},null===(e=H.current)||void 0===e?void 0:e.getLayer());r.start();const o=()=>{X(!1),K.currentTime=s.startTime*K.duration},i=()=>{K.currentTime>=s.endTime*K.duration&&(K.pause(),K.currentTime=s.startTime*K.duration,X(!1))};return K.addEventListener("ended",o),K.addEventListener("timeupdate",i),()=>{K.pause(),r.stop(),K.removeEventListener("ended",o),K.removeEventListener("timeupdate",i)}},[K,W,p.isPlaying,re]),i.useEffect(()=>{K&&(K.volume=s.volume)},[K,s.volume]),i.useEffect(()=>{K&&(K.playbackRate=s.speed,K.preservesPitch=!1)},[K,s.speed]);const ue=i.useRef(null);i.useEffect(()=>{const e=l(s,()=>{var e,t;if(K){if(oe&&ie){return Te(),void p.currentTime}if(F(s)){return}const r=p.activePage===s.page,o=s.page._mediaLocalTime,i=s.startTime*K.duration*1e3,n=K.duration*(s.endTime-s.startTime)*1e3,{start:a,end:d}=D(s.animations,s.page.duration),l=z(null!=o?o:0,0,a,n,i,s.speed,{windowEnd:d,frameMs:p._renderFrameMs,renderEnd:p._renderEndMs-s.page.startTime}),c=l/1e3,u=null!==o&&o>=a&&o<d;W||(K.muted=!u,u&&p.isPlaying&&r?K.paused?(K.currentTime=c,ce.play(K)):Math.abs(1e3*K.currentTime-l)>500&&(K.currentTime=c):(ce.reset(),K.paused||K.pause(),c!==K.currentTime&&(K.currentTime=c),!J(K)&&!p.isPlaying&&!ue.current&&(ue.current=E(`video ${s.id}`)))),Te(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ue.current&&(ue.current(),ue.current=null)}},[p,K,oe,ie,W]),i.useEffect(()=>{var e,t;if(!K){return}if(oe){return null===(e=ue.current)||void 0===e||e.call(ue),void(ue.current=null)}const r=()=>{var e;null===(e=ue.current)||void 0===e||e.call(ue),ue.current=null},o=()=>{J(K)&&(Te(),r())};let i,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(o,20)),K.addEventListener("timeupdate",o),K.addEventListener("canplay",o),K.addEventListener("seeked",o);const a=()=>{K.paused&&(Te(),J(K)&&r()),n=K.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in K&&(n=K.requestVideoFrameCallback(a)),()=>{clearInterval(i),void 0!==n&&K.cancelVideoFrameCallback(n),K.removeEventListener("timeupdate",o),K.removeEventListener("canplay",o),K.removeEventListener("seeked",o)}},[null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering,K,s.id,E,oe]);let{cropX:he,cropY:me,cropWidth:pe,cropHeight:ge}=s.a;"loaded"!==Q&&(he=me=0,pe=ge=1);const{width:fe,height:ve}=Z(de),we=null!==(L=null==K?void 0:K.videoWidth)&&void 0!==L?L:0,xe=null!==(M=null==K?void 0:K.videoHeight)&&void 0!==M?M:0;i.useLayoutEffect(()=>{"loaded"===Q&&we>0&&xe>0&&s._setSourceSize({width:we,height:xe},s.a.src)},[s,s.a.src,Q,we,xe]);const Ee=y({fit:s.a.fit,focus:s.focus,stretchEnabled:s.stretchEnabled,cropX:he,cropY:me,cropWidth:pe,cropHeight:ge,width:s.a.width,height:s.a.height},{width:fe,height:ve}),Le=(Ee.width,Ee.height,null!==(C=s.cornerRadius)&&void 0!==C?C:0),[Me,ye]=useCornerRadiusAndCrop(s,de,Ee,p._elementsPixelRatio,Le,!0);let[Ce,be]=useClip(s,Me,p._elementsPixelRatio,[Ee,Le,p._elementsPixelRatio]);const ke=S(H,s,Ce),Te=I(()=>{var e,t;se(),le(),ye(),be(),ke(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Te()});const je=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},Ie="loading"===Q,Re="failed"===Q,Se=!Ie&&!Re,Pe=k(s,Ee,"loaded"===Q?{width:fe,height:ve}:void 0,O),_e=Se?o(s):0;R(H,_e);const Ae=s.selectable||p.role===m.ADMIN;return t(e,{children:r(c,{onMouseEnter:()=>te(!0),onMouseLeave:()=>te(!1),children:[Ie&&t(x,{element:s}),Re&&t(w,{element:s,text:"Can not load the video..."}),t(u,Object.assign({ref:H,name:"element",id:s.id,image:Ce,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:_e},a(s),{customCrop:Ee,listening:Ae,draggable:U?s.draggable&&s.isSelected:s.draggable,preventDefault:!U||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(b(e.target))},onDblClick:je,onDblTap:je},Pe)),!!s.borderSize&&t(h,{x:s.a.x,y:s.a.y,width:Math.max(s.a.width-s.borderSize,0),height:Math.max(s.a.height-s.borderSize,0),opacity:_e,offsetX:-s.borderSize/2,offsetY:-s.borderSize/2,stroke:n(s.borderColor),strokeWidth:s.borderSize,listening:!1,rotation:s.a.rotation,cornerRadius:Math.max(0,Le-s.borderSize),hideInExport:!s.showInExport}),!p.isPlaying&&t(u,{image:W?ee||U?$:void 0:q,x:s.a.x,y:s.a.y,offsetX:-s.a.width/2+15/p.scale,offsetY:-s.a.height/2+15/p.scale,rotation:s.a.rotation,width:30/p.scale,height:30/p.scale,hideInExport:!0,onClick:()=>X(!W),onTap:()=>X(!W)}),s._cropModeEnabled&&"loaded"===Q&&t(Y,{element:s,store:p,previewImage:Ce,sourceImage:de,sourceWidth:fe,sourceHeight:ve,crop:Ee,innerAnchors:N})]})})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as o}from"mobx-react-lite";import n from"./page.js";import{TopRules as l}from"./rules.js";import{AudioElement as i}from"./audio.js";import{handleHotkey as s,handleCopyEvent as a,handleCutEvent as c,handlePasteEvent as u}from"./hotkeys.js";import{t as d}from"../utils/l10n.js";import{WorkspaceStyleProvider as h,useResolvedWorkspaceStyle as g}from"./workspace-style.js";const p=(e,t,r)=>Math.max(t,Math.min(r,e)),f=(e,t)=>Math.sqrt(Math.pow(t.clientX-e.clientX,2)+Math.pow(t.clientY-e.clientY,2)),m=({store:r})=>t("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"},children:[e("p",{children:d("workspace.noPages")}),e("button",{onClick:()=>{r.addPage()},children:d("workspace.addPage")})]}),v=({width:t,height:r,xPadding:o,yPadding:n,backgroundColor:l})=>e("div",{style:{width:t+"px",height:r+"px",backgroundColor:l,paddingLeft:o+"px",paddingRight:o+"px",paddingTop:n+"px",paddingBottom:n+"px",flexShrink:0},children:e("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}})});export const WorkspaceCanvas=o(({store:o,layout:d="vertical",pageControlsEnabled:w,backgroundColor:x,transparencyBackgroundColor:y,pageBorderColor:k,activePageBorderColor:L,bleedColor:T,snapGuideStroke:b,snapGuideStrokeWidth:S,snapGuideDash:M,selectionRectFill:E,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,cropOverlayFill:W,cropGridStyle:B,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:_,distanceGuideStroke:I,distanceLabelFill:Y,distanceLabelTextFill:D,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J,components:Q,onKeyDown:U,onPaste:Z,paddingX:$,paddingY:ee,pageGap:te,altCloneEnabled:re=!0,groupSelectionMode:oe="drill",visiblePagesOffset:ne,renderOnlyActivePage:le,scrollToPageThreshold:ie=.5,tooltipSafeArea:se})=>{var ae;const ce="horizontal"===d,ue=null!=$?$:20,de=null!=ee?ee:55,[he,ge]=r.useState({width:100,height:100}),pe=r.useRef(he),fe=r.useRef(null),me=r.useRef(null),ve=r.useRef(0);let we=0,xe=0,ye=0,ke=0;if(o.bleedVisible){for(const e of o.pages){const t=e.computedBleed;we=Math.max(we,t.left),xe=Math.max(xe,t.right),ye=Math.max(ye,t.top),ke=Math.max(ke,t.bottom)}}const Le=Math.max(...o.pages.map(e=>e.computedWidth)),Te=Math.max(...o.pages.map(e=>e.computedHeight)),be=(null===(ae=o.activePage)||void 0===ae?void 0:ae.computedHeight)||0,Se=Le+we+xe,Me=(le?be:Te)+ye+ke,Ee=async({skipTimeout:e}={skipTimeout:!1})=>{if(e||await new Promise(e=>setTimeout(e,50)),null===fe.current){return}if(!Number.isFinite(Se)||!Number.isFinite(Me)){return}const t=fe.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn("Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:"),console.log(fe.current));const r=me.current.clientWidth||t.width,n={width:r,height:t.height};(pe.current.width!==n.width||pe.current.height!==n.height)&&(ge(n),pe.current=n);const l=(r-2*ue)/Se,i=o.pages.length>1?3.1:2,s=(t.height-de*i)/Me,a=o.pages.length>1?3.1:2,c=(r-ue*a)/Se,u=(t.height-2*de)/Me,d=o.pages.length?Math.max(Math.min(ce?c:l,ce?u:s),.01):1;o.scaleToFit!==d&&(o.setScale(d),o._setScaleToFit(d))};r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[]),r.useEffect(()=>(o._setWorkspaceMounted(!0),()=>o._setWorkspaceMounted(!1)),[o]),r.useEffect(()=>{Ee()},[Se,Me,ee,$]),r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[o.openedSidePanel]),r.useEffect(()=>{o.__()},[]),r.useEffect(()=>{const e=fe.current;if(window.ResizeObserver){const t=new ResizeObserver(()=>{Ee({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(()=>{Ee({skipTimeout:!0})},100);return()=>clearInterval(e)}},[Se,Me]);const Ce=le?1:o.pages.length;let Pe,Re;if(ce){const e=Se*o.scale*Ce;Pe=Math.max(ue,(he.width-e)/Ce/2),Re=Math.max(de,(he.height-Me*o.scale)/2)}else{Pe=Math.max(ue,(he.width-Se*o.scale)/2);const e=Me*o.scale*Ce;Re=Math.max(de,(he.height-e)/Ce/2)}Number.isNaN(Pe)&&(Pe=ue),Number.isNaN(Re)&&(Re=de),r.useEffect(()=>{const e=e=>{U?U(e,o):s(e,o,fe.current)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),r.useEffect(()=>{const e=e=>a(e,o,fe.current),t=e=>c(e,o,fe.current),r=e=>{Z?Z(e,o):u(e,o,fe.current)};return window.addEventListener("copy",e),window.addEventListener("cut",t),window.addEventListener("paste",r),()=>{window.removeEventListener("copy",e),window.removeEventListener("cut",t),window.removeEventListener("paste",r)}},[Z]),r.useEffect(()=>{const e=e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();const t=Math.max(5,o.scaleToFit);let r=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(r=Math.max(r,300/Se)),r=Math.max(r,.01);const n=.03,l=p(e.deltaY<0?o.scale*(1+n):o.scale/(1+n),r,t);return void o.setScale(l)}},t=me.current;return null==t||t.addEventListener("wheel",e),()=>null==t?void 0:t.removeEventListener("wheel",e)},[ce,Se,o]),r.useEffect(()=>{const e=me.current;if(!e){return}const t=e=>{2===e.touches.length&&(ve.current=f(e.touches[0],e.touches[1]))},r=t=>{if(2===t.touches.length&&ve.current>0){t.preventDefault();const r=f(t.touches[0],t.touches[1]),n=r/ve.current,l=Math.max(5,o.scaleToFit);let i=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(i=Math.max(i,300/Se)),i=Math.max(i,.01);const s=o.scale,a=p(s*n,i,l),c=a/s,u=e.getBoundingClientRect(),d=(t.touches[0].clientX+t.touches[1].clientX)/2-u.left,h=(t.touches[0].clientY+t.touches[1].clientY)/2-u.top,g=e.scrollLeft+d,m=e.scrollTop+h;Ne.current=!0,o.setScale(a),e.scrollLeft=g*c-d,e.scrollTop=m*c-h,ve.current=r}},n=()=>{ve.current=0};return e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchmove",r,{passive:!1}),e.addEventListener("touchend",n,{passive:!0}),()=>{e.removeEventListener("touchstart",t),e.removeEventListener("touchmove",r),e.removeEventListener("touchend",n)}},[ce,Se,o]);const Fe=void 0!==te,We=o.pages.map(e=>{if(ce){const t=(e.computedWidth+we+xe)*o.scale;return Fe?t+te:t+2*Pe}{const t=(e.computedHeight+ye+ke)*o.scale;return Fe?t+te:t+2*Re}}),Be=[];let Oe=Fe?ce?Pe:Re:0;for(let e=0;e<We.length;e++){Be.push(Oe),Oe+=We[e]}const ze=We.reduce((e,t)=>e+t,0),je=Fe?ze+(ce?2*Pe:2*Re):ze,Ne=r.useRef(!1),[,He]=r.useReducer(e=>e+1,0);((e,t,o,n,l)=>{const i=r.useRef(0),s=r.useRef(0),a=r.useRef(null),c=r.useRef(null),u=r.useRef(!1),d=r.useRef(n.pages.length);u.current=d.current!==n.pages.length,d.current=n.pages.length,r.useEffect(()=>{const t=e.current,r=()=>{i.current=t.scrollLeft,s.current=t.scrollTop,a.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener("scroll",r),r(),()=>{t.removeEventListener("scroll",r)}},[]),r.useLayoutEffect(()=>{if(!e.current){return}if(u.current){const t=e.current;return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}const t=e.current,r=a.current,o=c.current;if(null===r||null===o){return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}l.current=!0;const n=t.offsetWidth,d=t.offsetHeight,h=(i.current+n/2)/r,g=(s.current+d/2)/o,f=Math.max(0,t.scrollWidth-n),m=Math.max(0,t.scrollHeight-d);t.scrollLeft=p(h*t.scrollWidth-n/2,0,f),t.scrollTop=p(g*t.scrollHeight-d/2,0,m),a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,s.current=t.scrollTop},[o,t])})(me,je,o.scale,o,Ne);const{handleScroll:Ge}=((e,t,o,n,l,i,s,a,c,u)=>{const d=r.useRef(!1),h=r.useRef(null),g=r.useRef(!1),p="horizontal"===c;r.useEffect(()=>{const t=e.current,r=()=>{s.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const f=n.pages.indexOf(n.activePage);return r.useLayoutEffect(()=>{if(a){return}if(!n.activePage){return}if(!e.current){return}if(d.current){return}const r=e.current,i=n.pages.indexOf(n.activePage),s=t[i]||0,c=p?r.scrollLeft:r.scrollTop,h=p?r.scrollWidth-r.clientWidth:r.scrollHeight-r.clientHeight,f=Math.min(s,Math.max(0,h)),m=o[i]||o[0]||0;let v=()=>{};return(Math.abs(f-c)>m*l||g.current)&&(g.current=!0,v=(({element:e,scrollTop:t,scrollLeft:r,duration:o=300,onFinish:n=()=>{}})=>{const l=void 0!==t,i=l?e.scrollTop:e.scrollLeft,s=l?t:r,a=s-i;let c=0,u=!1;if(0===o){return l?e.scrollTop=s:e.scrollLeft=s,()=>{}}const d=()=>{if(u){return}c+=20;const t=h(c,i,a,o);l?e.scrollTop=t:e.scrollLeft=t,c<o?setTimeout(d,20):n()},h=(e,t,r,o)=>(e/=o/2)<1?r/2*e*e+t:-r/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:r},p?{scrollLeft:f}:{scrollTop:f}),{onFinish:()=>{g.current=!1,null==u||u()},duration:n.isPlaying?0:300}))),v},[n.activePage,f,n.isPlaying,a,c]),{handleScroll:e=>{if(a){return}if(g.current){return}d.current=!0,clearTimeout(h.current),h.current=setTimeout(()=>{d.current=!1},300);const r=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3;let o=0;for(let n=t.length-1;n>=0;n--){if(r>=t[n]){o=n;break}}const l=n.pages[o];l&&n.activePage!==l&&l.select()}}})(me,Be,We,o,ie,he,Ne,le,d,He),_e=he.width>=Se*o.scale+2*Pe,Ie=he.height>=Me*o.scale+2*Re,Ye=x||"rgba(232, 232, 232, 0.9)",De=(null==Q?void 0:Q.NoPages)||m,Xe=ce?he.width:he.height,Ae=me.current?ce?me.current.scrollLeft:me.current.scrollTop:0,Ke=e=>{for(let t=Be.length-1;t>=0;t--){if(e>=Be[t]){return t}}return 0},qe=Math.max(0,Ke(Ae)),Ve=Math.min(o.pages.length-1,Ke(Ae+Xe)),Je=null!=ne?ne:1,Qe=Math.max(0,qe-Je),Ue=Math.min(o.pages.length-1,Ve+Je),Ze=g({cropOverlayFill:W,cropGridStyle:B,workspaceBackgroundColor:x,pageBorderColor:k,activePageBorderColor:L,bleedColor:T,transparencyBackgroundColor:y,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,snapGuideStroke:b,snapGuideStrokeWidth:S,snapGuideDash:M,selectionRectFill:E,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,distanceGuideStroke:I,distanceLabelFill:Y,distanceLabelTextFill:D,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:_,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J});return e(h,{value:Ze,children:e("div",{ref:fe,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:Ye,overflow:"hidden"},tabIndex:0,className:"polotno-workspace-container",children:t("div",{ref:me,onScroll:Ge,style:Object.assign({position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"flex",flexDirection:ce?"row":"column",overflow:"auto",overflowX:ce?"auto":_e?"hidden":"auto",overflowY:ce&&Ie?"hidden":"auto"},Fe&&{paddingTop:ce?0:Re,paddingBottom:ce?0:Re,paddingLeft:ce?Pe:0,paddingRight:ce?Pe:0,boxSizing:"border-box"}),className:"polotno-workspace-inner",children:[o.pages.map((t,r)=>{const l=t===o.activePage;if(le&&!l&&!t._exportingOrRendering&&!t._forceMount){return null}const i=l||r>=Qe&&r<=Ue||t._exportingOrRendering||t._forceMount,s=ce?We[r]:Se*o.scale+2*Pe,a=ce?Me*o.scale+2*Re:We[r];if(!i){return e("div",{style:{flexShrink:0},children:e(v,{width:s,height:a,backgroundColor:Ye,xPadding:Pe,yPadding:Re})},t.id)}const c=e(n,{page:t,xPadding:Pe,yPadding:Re,width:s,height:a,store:o,pageControlsEnabled:w,altCloneEnabled:re,groupSelectionMode:oe,components:Q,viewportSize:he,layout:d,tooltipSafeArea:se},t.id);return(t._exportingOrRendering||t._forceMount)&&!l&&le?e("div",{style:{display:"none",flexShrink:0},children:c},t.id):c}),o.rulesVisible&&e(l,{store:o,xPadding:Pe,yPadding:Re,width:Se*o.scale+2*Pe,height:Me*o.scale+2*Re,pageSizes:We,layout:d,renderOnlyActivePage:le}),0===o.pages.length&&e(De,{store:o}),o.audios.map(t=>e(i,{audio:t,store:o},t.id))]})})})});export default WorkspaceCanvas;
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as o}from"mobx-react-lite";import n from"./page.js";import{TopRules as l}from"./rules.js";import{AudioElement as i}from"./audio.js";import{handleHotkey as s,handleCopyEvent as a,handleCutEvent as c,handlePasteEvent as u}from"./hotkeys.js";import{t as d}from"../utils/l10n.js";import{WorkspaceStyleProvider as h,useResolvedWorkspaceStyle as g}from"./workspace-style.js";const p=(e,t,r)=>Math.max(t,Math.min(r,e)),f=(e,t)=>Math.sqrt(Math.pow(t.clientX-e.clientX,2)+Math.pow(t.clientY-e.clientY,2)),m=({store:r})=>t("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"},children:[e("p",{children:d("workspace.noPages")}),e("button",{onClick:()=>{r.addPage()},children:d("workspace.addPage")})]}),v=({width:t,height:r,xPadding:o,yPadding:n,backgroundColor:l})=>e("div",{style:{width:t+"px",height:r+"px",backgroundColor:l,paddingLeft:o+"px",paddingRight:o+"px",paddingTop:n+"px",paddingBottom:n+"px",flexShrink:0},children:e("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}})});export const WorkspaceCanvas=o(({store:o,layout:d="vertical",pageControlsEnabled:w,backgroundColor:x,transparencyBackgroundColor:y,pageBorderColor:k,activePageBorderColor:L,bleedColor:T,snapGuideStroke:b,snapGuideStrokeWidth:S,snapGuideDash:M,selectionRectFill:E,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,cropOverlayFill:W,cropGridStyle:B,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:_,distanceGuideStroke:I,distanceLabelFill:Y,distanceLabelTextFill:D,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J,components:Q,onKeyDown:U,onPaste:Z,paddingX:$,paddingY:ee,pageGap:te,altCloneEnabled:re=!0,groupSelectionMode:oe="drill",visiblePagesOffset:ne,renderOnlyActivePage:le,scrollToPageThreshold:ie=.5,tooltipSafeArea:se})=>{var ae;const ce="horizontal"===d,ue=null!=$?$:20,de=null!=ee?ee:55,[he,ge]=r.useState({width:100,height:100}),pe=r.useRef(he),fe=r.useRef(null),me=r.useRef(null),ve=r.useRef(0);let we=0,xe=0,ye=0,ke=0;if(o.bleedVisible){for(const e of o.pages){const t=e.computedBleed;we=Math.max(we,t.left),xe=Math.max(xe,t.right),ye=Math.max(ye,t.top),ke=Math.max(ke,t.bottom)}}const Le=Math.max(...o.pages.map(e=>e.computedWidth)),Te=Math.max(...o.pages.map(e=>e.computedHeight)),be=(null===(ae=o.activePage)||void 0===ae?void 0:ae.computedHeight)||0,Se=Le+we+xe,Me=(le?be:Te)+ye+ke,Ee=async({skipTimeout:e}={skipTimeout:!1})=>{if(e||await new Promise(e=>setTimeout(e,50)),null===fe.current){return}if(!Number.isFinite(Se)||!Number.isFinite(Me)){return}const t=fe.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn("Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:"),console.log(fe.current));const r=me.current.clientWidth||t.width,n={width:r,height:t.height};(pe.current.width!==n.width||pe.current.height!==n.height)&&(ge(n),pe.current=n);const l=(r-2*ue)/Se,i=o.pages.length>1?3.1:2,s=(t.height-de*i)/Me,a=o.pages.length>1?3.1:2,c=(r-ue*a)/Se,u=(t.height-2*de)/Me,d=o.pages.length?Math.max(Math.min(ce?c:l,ce?u:s),.01):1;o.scaleToFit!==d&&(o.setScale(d),o._setScaleToFit(d))};r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[]),r.useEffect(()=>(o._setWorkspaceMounted(!0),()=>o._setWorkspaceMounted(!1)),[o]),r.useEffect(()=>{Ee()},[Se,Me,ee,$]),r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[o.openedSidePanel]),r.useEffect(()=>{o.__()},[]),r.useEffect(()=>{const e=fe.current;if(window.ResizeObserver){const t=new ResizeObserver(()=>{Ee({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(()=>{Ee({skipTimeout:!0})},100);return()=>clearInterval(e)}},[Se,Me]);const Ce=le?1:o.pages.length;let Pe,Re;if(ce){const e=Se*o.scale*Ce;Pe=Math.max(ue,(he.width-e)/Ce/2),Re=Math.max(de,(he.height-Me*o.scale)/2)}else{Pe=Math.max(ue,(he.width-Se*o.scale)/2);const e=Me*o.scale*Ce;Re=Math.max(de,(he.height-e)/Ce/2)}Number.isNaN(Pe)&&(Pe=ue),Number.isNaN(Re)&&(Re=de),r.useEffect(()=>{const e=e=>{U?U(e,o):s(e,o,fe.current)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[U]),r.useEffect(()=>{const e=e=>a(e,o,fe.current),t=e=>c(e,o,fe.current),r=e=>{Z?Z(e,o):u(e,o,fe.current)};return window.addEventListener("copy",e),window.addEventListener("cut",t),window.addEventListener("paste",r),()=>{window.removeEventListener("copy",e),window.removeEventListener("cut",t),window.removeEventListener("paste",r)}},[Z]),r.useEffect(()=>{const e=e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();const t=Math.max(5,o.scaleToFit);let r=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(r=Math.max(r,300/Se)),r=Math.max(r,.01);const n=.03,l=p(e.deltaY<0?o.scale*(1+n):o.scale/(1+n),r,t);return void o.setScale(l)}},t=me.current;return null==t||t.addEventListener("wheel",e),()=>null==t?void 0:t.removeEventListener("wheel",e)},[ce,Se,o]),r.useEffect(()=>{const e=me.current;if(!e){return}const t=e=>{2===e.touches.length&&(ve.current=f(e.touches[0],e.touches[1]))},r=t=>{if(2===t.touches.length&&ve.current>0){t.preventDefault();const r=f(t.touches[0],t.touches[1]),n=r/ve.current,l=Math.max(5,o.scaleToFit);let i=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(i=Math.max(i,300/Se)),i=Math.max(i,.01);const s=o.scale,a=p(s*n,i,l),c=a/s,u=e.getBoundingClientRect(),d=(t.touches[0].clientX+t.touches[1].clientX)/2-u.left,h=(t.touches[0].clientY+t.touches[1].clientY)/2-u.top,g=e.scrollLeft+d,m=e.scrollTop+h;Ne.current=!0,o.setScale(a),e.scrollLeft=g*c-d,e.scrollTop=m*c-h,ve.current=r}},n=()=>{ve.current=0};return e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchmove",r,{passive:!1}),e.addEventListener("touchend",n,{passive:!0}),()=>{e.removeEventListener("touchstart",t),e.removeEventListener("touchmove",r),e.removeEventListener("touchend",n)}},[ce,Se,o]);const Fe=void 0!==te,We=o.pages.map(e=>{if(ce){const t=(e.computedWidth+we+xe)*o.scale;return Fe?t+te:t+2*Pe}{const t=(e.computedHeight+ye+ke)*o.scale;return Fe?t+te:t+2*Re}}),Be=[];let Oe=Fe?ce?Pe:Re:0;for(let e=0;e<We.length;e++){Be.push(Oe),Oe+=We[e]}const ze=We.reduce((e,t)=>e+t,0),je=Fe?ze+(ce?2*Pe:2*Re):ze,Ne=r.useRef(!1),[,He]=r.useReducer(e=>e+1,0);((e,t,o,n,l)=>{const i=r.useRef(0),s=r.useRef(0),a=r.useRef(null),c=r.useRef(null),u=r.useRef(!1),d=r.useRef(n.pages.length);u.current=d.current!==n.pages.length,d.current=n.pages.length,r.useEffect(()=>{const t=e.current,r=()=>{i.current=t.scrollLeft,s.current=t.scrollTop,a.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener("scroll",r),r(),()=>{t.removeEventListener("scroll",r)}},[]),r.useLayoutEffect(()=>{if(!e.current){return}if(u.current){const t=e.current;return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}const t=e.current,r=a.current,o=c.current;if(null===r||null===o){return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}l.current=!0;const n=t.offsetWidth,d=t.offsetHeight,h=(i.current+n/2)/r,g=(s.current+d/2)/o,f=Math.max(0,t.scrollWidth-n),m=Math.max(0,t.scrollHeight-d);t.scrollLeft=p(h*t.scrollWidth-n/2,0,f),t.scrollTop=p(g*t.scrollHeight-d/2,0,m),a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,s.current=t.scrollTop},[o,t])})(me,je,o.scale,o,Ne);const{handleScroll:Ge}=((e,t,o,n,l,i,s,a,c,u)=>{const d=r.useRef(!1),h=r.useRef(null),g=r.useRef(!1),p="horizontal"===c;r.useEffect(()=>{const t=e.current,r=()=>{s.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const f=n.pages.indexOf(n.activePage);return r.useLayoutEffect(()=>{if(a){return}if(!n.activePage){return}if(!e.current){return}if(d.current){return}const r=e.current,i=n.pages.indexOf(n.activePage),s=t[i]||0,c=p?r.scrollLeft:r.scrollTop,h=p?r.scrollWidth-r.clientWidth:r.scrollHeight-r.clientHeight,f=Math.min(s,Math.max(0,h)),m=o[i]||o[0]||0;let v=()=>{};return(Math.abs(f-c)>m*l||g.current)&&(g.current=!0,v=(({element:e,scrollTop:t,scrollLeft:r,duration:o=300,onFinish:n=()=>{}})=>{const l=void 0!==t,i=l?e.scrollTop:e.scrollLeft,s=l?t:r,a=s-i;let c=0,u=!1;if(0===o){return l?e.scrollTop=s:e.scrollLeft=s,()=>{}}const d=()=>{if(u){return}c+=20;const t=h(c,i,a,o);l?e.scrollTop=t:e.scrollLeft=t,c<o?setTimeout(d,20):n()},h=(e,t,r,o)=>(e/=o/2)<1?r/2*e*e+t:-r/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:r},p?{scrollLeft:f}:{scrollTop:f}),{onFinish:()=>{g.current=!1,null==u||u()},duration:n.isPlaying?0:300}))),v},[n.activePage,f,n.isPlaying,a,c]),{handleScroll:e=>{if(a){return}if(g.current){return}d.current=!0,clearTimeout(h.current),h.current=setTimeout(()=>{d.current=!1},300);const r=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3;let o=0;for(let n=t.length-1;n>=0;n--){if(r>=t[n]){o=n;break}}const l=n.pages[o];l&&n.activePage!==l&&l.select()}}})(me,Be,We,o,ie,he,Ne,le,d,He),_e=he.width>=Se*o.scale+2*Pe,Ie=he.height>=Me*o.scale+2*Re,Ye=x||"rgba(232, 232, 232, 0.9)",De=(null==Q?void 0:Q.NoPages)||m,Xe=ce?he.width:he.height,Ae=me.current?ce?me.current.scrollLeft:me.current.scrollTop:0,Ke=e=>{for(let t=Be.length-1;t>=0;t--){if(e>=Be[t]){return t}}return 0},qe=Math.max(0,Ke(Ae)),Ve=Math.min(o.pages.length-1,Ke(Ae+Xe)),Je=null!=ne?ne:1,Qe=Math.max(0,qe-Je),Ue=Math.min(o.pages.length-1,Ve+Je),Ze=g({cropOverlayFill:W,cropGridStyle:B,workspaceBackgroundColor:x,pageBorderColor:k,activePageBorderColor:L,bleedColor:T,transparencyBackgroundColor:y,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,snapGuideStroke:b,snapGuideStrokeWidth:S,snapGuideDash:M,selectionRectFill:E,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,distanceGuideStroke:I,distanceLabelFill:Y,distanceLabelTextFill:D,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:_,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J});return e(h,{value:Ze,children:e("div",{ref:fe,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:Ye,overflow:"hidden"},tabIndex:0,className:"polotno-workspace-container",children:t("div",{ref:me,onScroll:Ge,style:Object.assign({position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"flex",flexDirection:ce?"row":"column",overflow:"auto",overflowX:ce?"auto":_e?"hidden":"auto",overflowY:ce&&Ie?"hidden":"auto"},Fe&&{paddingTop:ce?0:Re,paddingBottom:ce?0:Re,paddingLeft:ce?Pe:0,paddingRight:ce?Pe:0,boxSizing:"border-box"}),className:"polotno-workspace-inner",children:[o.pages.map((t,r)=>{const l=t===o.activePage;if(le&&!l&&!t._exportingOrRendering&&!t._forceMount){return null}const i=l||r>=Qe&&r<=Ue||t._exportingOrRendering||t._forceMount,s=ce?We[r]:Se*o.scale+2*Pe,a=ce?Me*o.scale+2*Re:We[r];if(!i){return e("div",{style:{flexShrink:0},children:e(v,{width:s,height:a,backgroundColor:Ye,xPadding:Pe,yPadding:Re})},t.id)}const c=e(n,{page:t,xPadding:Pe,yPadding:Re,width:s,height:a,store:o,pageControlsEnabled:w,altCloneEnabled:re,groupSelectionMode:oe,components:Q,viewportSize:he,layout:d,tooltipSafeArea:se},t.id);return(t._exportingOrRendering||t._forceMount)&&!l&&le?e("div",{style:{display:"none",flexShrink:0},children:c},t.id):c}),o.rulesVisible&&e(l,{store:o,xPadding:Pe,yPadding:Re,width:Se*o.scale+2*Pe,height:Me*o.scale+2*Re,pageSizes:We,layout:d,renderOnlyActivePage:le}),0===o.pages.length&&e(De,{store:o}),o.audios.map(t=>e(i,{audio:t,store:o},t.id))]})})})});export default WorkspaceCanvas;
|
package/config.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { setTranslations, getTranslations } from './utils/l10n.js';
|
|
|
16
16
|
export { setIcons, type IconName } from './icons/registry.js';
|
|
17
17
|
export { registerNextDomDrop as unstable_registerNextDomDrop } from './canvas/page.js';
|
|
18
18
|
export { getGoogleFontsListAPI, getGoogleFontImage, setAPI } from './utils/api.js';
|
|
19
|
-
export { setColorsPresetFunc } from './toolbar/color-picker.js';
|
|
19
|
+
export { setColorsPresetFunc, setColorPickerContent, type ColorPickerContentProps, } from './toolbar/color-picker.js';
|
|
20
20
|
export { setQuillFormats as unstable_setQuillFormats } from './canvas/rich-editor.js';
|
|
21
21
|
export { useDownScaling, setDownScalingEnabled } from './utils/flags.js';
|
|
22
22
|
export { useRemoveBackground as unstable_setRemoveBackgroundEnabled, setRemoveBackgroundEnabled, } from './utils/flags.js';
|
package/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{setGoogleFonts,addGlobalFont,removeGlobalFont,replaceGlobalFonts,setGoogleFontsVariants}from"./utils/fonts.js";export{setUploadFunc}from"./side-panel/upload-panel.js";export{setExpandFunc,setReplaceObjectFunc,setRemoveObjectFunc,setUpscaleFunc,setRemoveBackgroundFunc}from"./utils/api.js";export{setFontUploadFunc}from"./side-panel/text-panel.js";export{toggleFadeInAnimation}from"./canvas/use-fadein.js";export{setTransformerStyle,setHighlighterStyle,setInnerImageCropTransformerStyle,setOuterImageCropTransformerStyle}from"./canvas/workspace-style.js";export{setImageLoaderHook as unstable_setImageLoaderHook}from"./canvas/image-element.js";export{registerShapeModel as unstable_registerShapeModel}from"./model/group-model.js";export{registerShapeComponent as unstable_registerShapeComponent}from"./canvas/element.js";export{registerTransformerAttrs as unstable_registerTransformerAttrs}from"./canvas/page.js";export{registerToolbarComponent as unstable_registerToolbarComponent}from"./toolbar/toolbar.js";export{onLoadError,setAssetLoadTimeout,setFontLoadTimeout}from"./utils/loader.js";export{setSnapFilterFunc as unstable_setSnapFilterFunc}from"./canvas/use-transformer-snap.js";export{setTranslations,getTranslations}from"./utils/l10n.js";export{setIcons}from"./icons/registry.js";export{registerNextDomDrop as unstable_registerNextDomDrop}from"./canvas/page.js";export{getGoogleFontsListAPI,getGoogleFontImage,setAPI}from"./utils/api.js";export{setColorsPresetFunc}from"./toolbar/color-picker.js";export{setQuillFormats as unstable_setQuillFormats}from"./canvas/rich-editor.js";export{useDownScaling,setDownScalingEnabled}from"./utils/flags.js";export{useRemoveBackground as unstable_setRemoveBackgroundEnabled,setRemoveBackgroundEnabled}from"./utils/flags.js";export{useHtmlTextRender as unstable_useHtmlTextRender,setRichTextEnabled}from"./utils/flags.js";export{setLegacyRichTextEnabled}from"./utils/flags.js";export{setForceTextFit as unstable_setForceTextFit}from"./utils/flags.js";export{setTextSplitAllowed as unstable_setTextSplitAllowed}from"./utils/flags.js";export{setTextOverflow as unstable_setTextOverflow,setTextOverflow}from"./utils/flags.js";export{setTextVerticalResizeEnabled as unstable_setTextVerticalResizeEnabled,setTextVerticalResizeEnabled}from"./utils/flags.js";export{setAnimationsEnabled as unstable_setAnimationsEnabled,setAnimationsEnabled}from"./utils/flags.js";export{setAiTextEnabled}from"./utils/flags.js";export{setCmykInputEnabled}from"./utils/flags.js";export{setCmykPreview}from"@polotno/core/color";export{setAutoDeleteEmptyText}from"./utils/flags.js";
|
|
1
|
+
export{setGoogleFonts,addGlobalFont,removeGlobalFont,replaceGlobalFonts,setGoogleFontsVariants}from"./utils/fonts.js";export{setUploadFunc}from"./side-panel/upload-panel.js";export{setExpandFunc,setReplaceObjectFunc,setRemoveObjectFunc,setUpscaleFunc,setRemoveBackgroundFunc}from"./utils/api.js";export{setFontUploadFunc}from"./side-panel/text-panel.js";export{toggleFadeInAnimation}from"./canvas/use-fadein.js";export{setTransformerStyle,setHighlighterStyle,setInnerImageCropTransformerStyle,setOuterImageCropTransformerStyle}from"./canvas/workspace-style.js";export{setImageLoaderHook as unstable_setImageLoaderHook}from"./canvas/image-element.js";export{registerShapeModel as unstable_registerShapeModel}from"./model/group-model.js";export{registerShapeComponent as unstable_registerShapeComponent}from"./canvas/element.js";export{registerTransformerAttrs as unstable_registerTransformerAttrs}from"./canvas/page.js";export{registerToolbarComponent as unstable_registerToolbarComponent}from"./toolbar/toolbar.js";export{onLoadError,setAssetLoadTimeout,setFontLoadTimeout}from"./utils/loader.js";export{setSnapFilterFunc as unstable_setSnapFilterFunc}from"./canvas/use-transformer-snap.js";export{setTranslations,getTranslations}from"./utils/l10n.js";export{setIcons}from"./icons/registry.js";export{registerNextDomDrop as unstable_registerNextDomDrop}from"./canvas/page.js";export{getGoogleFontsListAPI,getGoogleFontImage,setAPI}from"./utils/api.js";export{setColorsPresetFunc,setColorPickerContent}from"./toolbar/color-picker.js";export{setQuillFormats as unstable_setQuillFormats}from"./canvas/rich-editor.js";export{useDownScaling,setDownScalingEnabled}from"./utils/flags.js";export{useRemoveBackground as unstable_setRemoveBackgroundEnabled,setRemoveBackgroundEnabled}from"./utils/flags.js";export{useHtmlTextRender as unstable_useHtmlTextRender,setRichTextEnabled}from"./utils/flags.js";export{setLegacyRichTextEnabled}from"./utils/flags.js";export{setForceTextFit as unstable_setForceTextFit}from"./utils/flags.js";export{setTextSplitAllowed as unstable_setTextSplitAllowed}from"./utils/flags.js";export{setTextOverflow as unstable_setTextOverflow,setTextOverflow}from"./utils/flags.js";export{setTextVerticalResizeEnabled as unstable_setTextVerticalResizeEnabled,setTextVerticalResizeEnabled}from"./utils/flags.js";export{setAnimationsEnabled as unstable_setAnimationsEnabled,setAnimationsEnabled}from"./utils/flags.js";export{setAiTextEnabled}from"./utils/flags.js";export{setCmykInputEnabled}from"./utils/flags.js";export{setCmykPreview}from"@polotno/core/color";export{setAutoDeleteEmptyText}from"./utils/flags.js";
|
package/icons/registry.d.ts
CHANGED
|
@@ -73,9 +73,16 @@ declare const defaults: {
|
|
|
73
73
|
'sidePanel.resize': import("lucide-react").LucideIcon;
|
|
74
74
|
'sidePanel.draw': import("lucide-react").LucideIcon;
|
|
75
75
|
'sidePanel.videos': import("lucide-react").LucideIcon;
|
|
76
|
+
'sidePanel.variables': import("lucide-react").LucideIcon;
|
|
77
|
+
'variables.text': import("lucide-react").LucideIcon;
|
|
78
|
+
'variables.image': import("lucide-react").LucideIcon;
|
|
79
|
+
'variables.video': import("lucide-react").LucideIcon;
|
|
80
|
+
'variables.color': import("lucide-react").LucideIcon;
|
|
81
|
+
'variables.boolean': import("lucide-react").LucideIcon;
|
|
76
82
|
'toolbar.opacity': import("lucide-react").LucideIcon;
|
|
77
83
|
'toolbar.filters': import("lucide-react").LucideIcon;
|
|
78
84
|
'toolbar.aiWrite': import("lucide-react").LucideIcon;
|
|
85
|
+
'toolbar.insertVariable': import("lucide-react").LucideIcon;
|
|
79
86
|
'toolbar.duration': import("lucide-react").LucideIcon;
|
|
80
87
|
'toolbar.trim': import("lucide-react").LucideIcon;
|
|
81
88
|
'toolbar.flipHorizontal': import("lucide-react").LucideIcon;
|
package/icons/registry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as
|
|
1
|
+
var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as s,AlignEndVertical as p,AlignHorizontalSpaceAround as c,AlignJustify as m,AlignLeft as d,AlignRight as y,AlignStartHorizontal as u,AlignStartVertical as g,AlignVerticalJustifyCenter as b,AlignVerticalJustifyEnd as f,AlignVerticalJustifyStart as x,AlignVerticalSpaceAround as v,ArrowDown as h,ArrowDownLeft as P,ArrowDownRight as w,ArrowLeft as k,ArrowLeftRight as z,ArrowRight as L,ArrowUp as O,ArrowUpDown as j,ArrowUpLeft as R,ArrowUpRight as T,Ban as B,Bold as I,Braces as W,CaseSensitive as F,Check as C,ChevronDown as D,ChevronLeft as G,ChevronRight as H,ChevronsDown as M,ChevronsUp as S,ChevronUp as V,CloudUpload as E,Contrast as U,Copy as $,CreditCard as _,Crop as J,Edit as K,Eye as N,EyeOff as Z,Files as q,FileText as A,GripVertical as Q,HelpCircle as X,Highlighter as Y,Image as tt,Italic as it,Layers as et,LayoutTemplate as ot,List as nt,ListOrdered as at,Lock as rt,MousePointer as lt,MoreHorizontal as st,PaintBucket as pt,Palette as ct,Pause as mt,Pencil as dt,Pilcrow as yt,Pipette as ut,Play as gt,Plus as bt,Redo2 as ft,Scaling as xt,Scissors as vt,Search as ht,SkipBack as Pt,Settings as wt,Shapes as kt,SlidersHorizontal as zt,Sparkles as Lt,Strikethrough as Ot,TextCursorInput as jt,Timer as Rt,ToggleRight as Tt,Trash2 as Bt,Type as It,Underline as Wt,Undo2 as Ft,Unlock as Ct,Upload as Dt,Video as Gt,Volume2 as Ht,VolumeX as Mt,WandSparkles as St,WrapText as Vt,X as Et,ZoomIn as Ut,ZoomOut as $t}from"lucide-react";import{Instagram as _t,Facebook as Jt,Youtube as Kt,Linkedin as Nt,Twitter as Zt}from"./brand-icons.js";import{NoneIcon as qt,MoveIcon as At,FadeIcon as Qt,ZoomIcon as Xt,RotateIcon as Yt,BlinkIcon as ti,BounceIcon as ii,BlurIcon as ei,CountIcon as oi,PopIcon as ni,RiseIcon as ai,FlipIcon as ri,GrowTurnIcon as li,PulseIcon as si,FloatIcon as pi,ShakeIcon as ci,TypewriterIcon as mi,LineRiseIcon as di,WordRiseIcon as yi,WordFadeIcon as ui,LetterPopIcon as gi,WordBlurIcon as bi,WipeIcon as fi,GlowIcon as xi,KenBurnsIcon as vi,LineWipeIcon as hi,LinePeekIcon as Pi,LetterWaveIcon as wi}from"./animation-icons.js";const ki={"action.duplicate":$,"action.split":vt,"action.rename":dt,"action.remove":Bt,"action.lock":rt,"action.unlock":Ct,"action.undo":Ft,"action.redo":ft,"action.add":bt,"action.more":st,"action.settings":wt,"action.search":ht,"action.close":Et,"action.confirm":C,"action.none":B,"action.visible":N,"action.hidden":Z,"action.dragHandle":Q,"action.eyeDropper":ut,"action.unmuted":Ht,"action.muted":Mt,"action.help":X,"ui.chevronUp":V,"ui.chevronDown":D,"ui.chevronLeft":G,"ui.chevronRight":H,"layering.menu":et,"layering.up":V,"layering.down":D,"layering.top":S,"layering.bottom":M,"text.bold":I,"text.italic":it,"text.underline":Wt,"text.strikethrough":Ot,"text.alignLeft":d,"text.alignCenter":a,"text.alignRight":y,"text.alignJustify":m,"text.valignTop":x,"text.valignMiddle":b,"text.valignBottom":f,"text.uppercase":F,"text.spacing":Vt,"text.bulletList":nt,"text.numberedList":at,"text.paragraph":yt,"text.richText":jt,"text.uploadFont":Dt,"position.alignLeft":g,"position.alignCenter":l,"position.alignRight":p,"position.alignTop":u,"position.alignMiddle":r,"position.alignBottom":s,"position.distributeVertical":v,"position.distributeHorizontal":c,"sidePanel.templates":ot,"sidePanel.text":It,"sidePanel.photos":tt,"sidePanel.elements":kt,"sidePanel.upload":E,"sidePanel.background":pt,"sidePanel.pages":q,"sidePanel.layers":et,"sidePanel.resize":xt,"sidePanel.draw":dt,"sidePanel.videos":Gt,"sidePanel.variables":W,"variables.text":It,"variables.image":tt,"variables.video":Gt,"variables.color":ct,"variables.boolean":Tt,"toolbar.opacity":U,"toolbar.filters":St,"toolbar.aiWrite":Lt,"toolbar.insertVariable":W,"toolbar.duration":Rt,"toolbar.trim":vt,"toolbar.flipHorizontal":z,"toolbar.flipVertical":j,"toolbar.zoomIn":Ut,"toolbar.zoomOut":$t,"toolbar.crop":J,"imageEdit.ai":Lt,"colorPicker.reverseGradient":z,"download.export":Dt,"download.image":tt,"download.pdf":A,"download.video":Gt,"draw.select":lt,"draw.brush":K,"draw.highlighter":Y,"background.colorPicker":ct,"pagesTimeline.play":gt,"pagesTimeline.pause":mt,"pagesTimeline.rewind":Pt,"size.instagram":_t,"size.facebook":Jt,"size.youtube":Kt,"size.linkedin":Nt,"size.twitter":Zt,"size.video":Gt,"size.print":A,"size.businessCard":_,"animation.directionRight":L,"animation.directionLeft":k,"animation.directionUp":O,"animation.directionDown":h,"animation.directionBottomRight":w,"animation.directionBottomLeft":P,"animation.directionTopRight":T,"animation.directionTopLeft":R,"animation.typeMove":At,"animation.typeFade":Qt,"animation.typeZoom":Xt,"animation.typeBlur":ei,"animation.typeCount":oi,"animation.typeRotate":Yt,"animation.typeBlink":ti,"animation.typeBounce":ii,"animation.typePop":ni,"animation.typeRise":ai,"animation.typeFlip":ri,"animation.typeGrowTurn":li,"animation.typePulse":si,"animation.typeFloat":pi,"animation.typeShake":ci,"animation.typeTypewriter":mi,"animation.typeLineRise":di,"animation.typeWordRise":yi,"animation.typeWordFade":ui,"animation.typeLetterPop":gi,"animation.typeWordBlur":bi,"animation.typeWipe":fi,"animation.typeGlow":xi,"animation.typeKenBurns":vi,"animation.typeLineWipe":hi,"animation.typeLinePeek":Pi,"animation.typeLetterWave":wi,"animation.typeNone":qt,"animation.settings":zt},zi=e.map();export const setIcons=o(t=>{for(const i of Object.keys(t)){const e=t[i];null!=e&&("function"==typeof e||"object"==typeof e?zi.set(i,e):console.warn(`polotno: setIcons('${i}') expects a React component, received ${typeof e}. Ignored.`))}});export const resetIcons=o(()=>zi.clear());export const PolotnoIcon=n(e=>{var o,{name:n}=e,a=t(e,["name"]);const r=null!==(o=zi.get(n))&&void 0!==o?o:ki[n];return i(r,Object.assign({"data-pn-icon":""},a))});
|
package/image-tools/host.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export interface ToolTarget extends IAnyStateTreeNode, ImageSnapshot {
|
|
|
27
27
|
readonly resizable: boolean;
|
|
28
28
|
readonly selectable: boolean;
|
|
29
29
|
readonly visible: boolean;
|
|
30
|
+
readonly a: {
|
|
31
|
+
readonly src?: string;
|
|
32
|
+
};
|
|
30
33
|
readonly maskSrc?: string;
|
|
31
34
|
readonly page: ParentNode | null;
|
|
32
35
|
readonly parent: ParentNode | null;
|
package/image-tools/sessions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var n={};for(var r in e){Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++){t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}}return n};import{observable as t,runInAction as n}from"mobx";import{isAlive as r}from"mobx-state-tree";import{getCropRect as o,getImageSize as i}from"@polotno/core/image";import{getVideoSize as s}from"@polotno/core/video";import{imageEditHandlers as a}from"../utils/api.js";import{flags as c}from"../utils/flags.js";import{contains as l,cropFrame as d,frameBox as p,intersection as u,relativeRect as g,sameRect as f,sourceBounds as m,UNIT as b,validRect as h}from"./geometry.js";import{editImage as v}from"./operations.js";import{imageSnapshot as y,toolError as w}from"./target.js";const _=new WeakMap;export const sessionControls=e=>_.get(e);function O(e,o,i,s){var a;const c=o.id,l=t.box((null===(a=o._pendingEdit)||void 0===a?void 0:a.tool)===e?o._pendingEdit:null,{deep:!1}),d=t=>w(e,c,t),p={elementId:c,get pending(){const e=l.get();return r(o)&&!!e&&o._pendingEdit===e},fail:d,assertActive(e){if(!r(o)){throw d("stale-result")}if(o._pendingEdit){throw d("busy")}if(i.activeTool!==e){throw d("stale-result")}},start:e=>(n(()=>{var e;return l.set(null!==(e=o._pendingEdit)&&void 0!==e?e:null)}),e),cancel(e){p.pending&&l.get().cancel(),i.activeTool===e&&i._closeImageTool("discard")},controls:{drafting:!1,close(){},undo:()=>!1,didApply:s}};return p}function j(e){return(t,n)=>{const r=O(e,t,n,()=>{}),o={name:e,elementId:r.elementId,get pending(){return r.pending},cancel:()=>r.cancel(o),async run({options:n}={}){r.assertActive(o),await r.start(v(t,{tool:e,options:n}))}};return _.set(o,r.controls),o}}export const IMAGE_TOOLS={crop:function(a,c){const u=a.id,v=y(a),{src:O,rotation:j,flipX:x,flipY:E,stretchEnabled:I}=v,z=e(v,["src","rotation","flipX","flipY","stretchEnabled"]),A=t.box(b,{deep:!1}),S=t.box(null,{deep:!1});let T=!1,D=!1,P=!1;const k=e=>w("crop",u,e),M=()=>D||!f(A.get(),b),C=e=>{const t=S.get();n(()=>S.set(null)),null==t||t(e)},F=()=>{if(!r(a)){throw k("stale-result")}if(a._pendingEdit||S.get()){throw k("busy")}if(c.activeTool!==G){throw k("stale-result")}},X=e=>{if(!(Math.abs(e.width/v.width-1)<1e-9&&Math.abs(e.height/v.height-1)<1e-9||a.resizable)){throw k("unsupported-target")}},Y=e=>{P=!0;try{c.history._draftChange(()=>a.set(e))}finally{P=!1}T=!0};c.history._startDraft(u,z);const B=()=>{T&&r(a)&&Y(z),T=D=!1,n(()=>A.set(b))},G={elementId:u,name:"crop",get pending(){return!!S.get()},get frame(){return A.get()},setFrame(e){F();const t=a._sourceSize;if(!h(e)||!h(p(v,e))||t&&!l(m(v,t),e)){throw k("invalid-geometry")}X(p(v,e)),n(()=>A.set(Object.freeze(Object.assign({},e)))),D=!1,t&&Y(d(v,t,e))},cancel(){C("canceled"),c.activeTool===G&&c._closeImageTool("discard")},async run(){if(F(),M()&&!a._sourceSize){let e,t=null;const r=new Promise((n,r)=>{e=e=>{t=e,r(k(e))}});n(()=>S.set(e));try{const e=await Promise.race(["video"===a.type?s(v.src):i(v.src),r]);if(t){throw k(t)}a._setSourceSize(e,v.src)}finally{S.get()===e&&n(()=>S.set(null))}}c.activeTool===G&&c._closeImageTool("commit")}};return _.set(G,{get drafting(){return P},close(e){if(C("commit"===e||"discard"===e?"canceled":"stale-result"),"commit"===e||"stale"===e&&T){return(()=>{const e=a._sourceSize;if(!M()||!r(a)||!T&&!e){return c.history._discardDraft()}T||Y(d(v,e,A.get())),c.history._commitDraft()})()}"discard"===e&&B(),c.history._discardDraft()},undo:()=>!!M()&&(C("canceled"),B(),!0),didApply(){},setDraft(e){F();const t=a._sourceSize;if(!t){throw k("busy")}const r=Object.assign(Object.assign({},y(a)),e);X(r),Y(e),D=!0,n(()=>A.set(Object.freeze(g(o(r,t),o(v,t)))))}}),G},expand:function(e,r){let o=y(e);const i=e._pendingEdit,s=t.box("expand"===(null==i?void 0:i.tool)?i.rect:b,{deep:!1}),a=O("expand",e,r,()=>{o=y(e),n(()=>s.set(b))}),c={name:"expand",elementId:a.elementId,get pending(){return a.pending},get frame(){return s.get()},setFrame(e){if(a.assertActive(c),!h(e)||!h(p(o,e))||!h(u(e,b))){throw a.fail("invalid-geometry")}n(()=>s.set(Object.freeze(Object.assign({},e))))},cancel:()=>a.cancel(c),async run({prompt:t,options:n}={}){a.assertActive(c),await a.start(v(e,{tool:"expand",frame:s.get(),prompt:t,options:n}))}};return _.set(c,a.controls),c},inpaint:function(e,r){const o=e._pendingEdit,i=t.box("inpaint"===(null==o?void 0:o.tool)?o.rect:null,{deep:!1}),s=O("inpaint",e,r,()=>n(()=>i.set(null))),a={name:"inpaint",elementId:s.elementId,get pending(){return s.pending},get region(){return i.get()},setRegion(e){if(s.assertActive(a),e&&(!h(e)||!l(b,e))){throw s.fail("invalid-geometry")}n(()=>i.set(e?Object.freeze(Object.assign({},e)):null))},cancel:()=>s.cancel(a),async run(t){s.assertActive(a);const n=i.get();if(!n){throw s.fail("invalid-geometry")}await s.start(v(e,Object.assign(Object.assign({tool:"inpaint"},t),{region:n})))}};return _.set(a,s.controls),a},upscale:j("upscale"),"remove-background":j("remove-background")};export function toolAvailable(e){switch(e){case"crop":return!0;case"expand":return!!a.expand;case"inpaint":return!(!a.replace&&!a.remove);case"upscale":return!!a.upscale;default:return c.removeBackgroundEnabled}}
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var n={};for(var r in e){Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++){t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}}return n};import{observable as t,runInAction as n}from"mobx";import{isAlive as r}from"mobx-state-tree";import{getCropRect as o,getImageSize as i}from"@polotno/core/image";import{getVideoSize as s}from"@polotno/core/video";import{imageEditHandlers as a}from"../utils/api.js";import{flags as c}from"../utils/flags.js";import{contains as l,cropFrame as d,frameBox as p,intersection as u,relativeRect as g,sameRect as f,sourceBounds as m,UNIT as b,validRect as h}from"./geometry.js";import{editImage as v}from"./operations.js";import{imageSnapshot as y,toolError as w}from"./target.js";const _=new WeakMap;export const sessionControls=e=>_.get(e);function O(e,o,i,s){var a;const c=o.id,l=t.box((null===(a=o._pendingEdit)||void 0===a?void 0:a.tool)===e?o._pendingEdit:null,{deep:!1}),d=t=>w(e,c,t),p={elementId:c,get pending(){const e=l.get();return r(o)&&!!e&&o._pendingEdit===e},fail:d,assertActive(e){if(!r(o)){throw d("stale-result")}if(o._pendingEdit){throw d("busy")}if(i.activeTool!==e){throw d("stale-result")}},start:e=>(n(()=>{var e;return l.set(null!==(e=o._pendingEdit)&&void 0!==e?e:null)}),e),cancel(e){p.pending&&l.get().cancel(),i.activeTool===e&&i._closeImageTool("discard")},controls:{drafting:!1,close(){},undo:()=>!1,didApply:s}};return p}function j(e){return(t,n)=>{const r=O(e,t,n,()=>{}),o={name:e,elementId:r.elementId,get pending(){return r.pending},cancel:()=>r.cancel(o),async run({options:n}={}){r.assertActive(o),await r.start(v(t,{tool:e,options:n}))}};return _.set(o,r.controls),o}}export const IMAGE_TOOLS={crop:function(a,c){const u=a.id,v=y(a),{src:O,rotation:j,flipX:x,flipY:E,stretchEnabled:I}=v,z=e(v,["src","rotation","flipX","flipY","stretchEnabled"]),A=t.box(b,{deep:!1}),S=t.box(null,{deep:!1});let T=!1,D=!1,P=!1;const k=e=>w("crop",u,e),M=()=>D||!f(A.get(),b),C=e=>{const t=S.get();n(()=>S.set(null)),null==t||t(e)},F=()=>{if(!r(a)){throw k("stale-result")}if(a._pendingEdit||S.get()){throw k("busy")}if(c.activeTool!==G){throw k("stale-result")}},X=e=>{if(!(Math.abs(e.width/v.width-1)<1e-9&&Math.abs(e.height/v.height-1)<1e-9||a.resizable)){throw k("unsupported-target")}},Y=e=>{P=!0;try{c.history._draftChange(()=>a.set(e))}finally{P=!1}T=!0};c.history._startDraft(u,z);const B=()=>{T&&r(a)&&Y(z),T=D=!1,n(()=>A.set(b))},G={elementId:u,name:"crop",get pending(){return!!S.get()},get frame(){return A.get()},setFrame(e){F();const t=a._sourceSize;if(!h(e)||!h(p(v,e))||t&&!l(m(v,t),e)){throw k("invalid-geometry")}X(p(v,e)),n(()=>A.set(Object.freeze(Object.assign({},e)))),D=!1,t&&Y(d(v,t,e))},cancel(){C("canceled"),c.activeTool===G&&c._closeImageTool("discard")},async run(){if(F(),M()&&!a._sourceSize){let e,t=null;const r=new Promise((n,r)=>{e=e=>{t=e,r(k(e))}});n(()=>S.set(e));try{const e=await Promise.race(["video"===a.type?s(v.src):i(v.src),r]);if(t){throw k(t)}a._setSourceSize(e,v.src)}finally{S.get()===e&&n(()=>S.set(null))}}c.activeTool===G&&c._closeImageTool("commit")}};return _.set(G,{get drafting(){return P},close(e){if(C("commit"===e||"discard"===e?"canceled":"stale-result"),"commit"===e||"stale"===e&&T){return(()=>{const e=a._sourceSize;if(!M()||!r(a)||!T&&!e){return c.history._discardDraft()}T||Y(d(v,e,A.get())),c.history._commitDraft()})()}"discard"===e&&B(),c.history._discardDraft()},undo:()=>!!M()&&(C("canceled"),B(),!0),didApply(){},setDraft(e){F();const t=a._sourceSize;if(!t){throw k("busy")}const r=Object.assign(Object.assign(Object.assign({},y(a)),{fit:void 0}),e);X(r),Y(e),D=!0,n(()=>A.set(Object.freeze(g(o(r,t),o(v,t)))))}}),G},expand:function(e,r){let o=y(e);const i=e._pendingEdit,s=t.box("expand"===(null==i?void 0:i.tool)?i.rect:b,{deep:!1}),a=O("expand",e,r,()=>{o=y(e),n(()=>s.set(b))}),c={name:"expand",elementId:a.elementId,get pending(){return a.pending},get frame(){return s.get()},setFrame(e){if(a.assertActive(c),!h(e)||!h(p(o,e))||!h(u(e,b))){throw a.fail("invalid-geometry")}n(()=>s.set(Object.freeze(Object.assign({},e))))},cancel:()=>a.cancel(c),async run({prompt:t,options:n}={}){a.assertActive(c),await a.start(v(e,{tool:"expand",frame:s.get(),prompt:t,options:n}))}};return _.set(c,a.controls),c},inpaint:function(e,r){const o=e._pendingEdit,i=t.box("inpaint"===(null==o?void 0:o.tool)?o.rect:null,{deep:!1}),s=O("inpaint",e,r,()=>n(()=>i.set(null))),a={name:"inpaint",elementId:s.elementId,get pending(){return s.pending},get region(){return i.get()},setRegion(e){if(s.assertActive(a),e&&(!h(e)||!l(b,e))){throw s.fail("invalid-geometry")}n(()=>i.set(e?Object.freeze(Object.assign({},e)):null))},cancel:()=>s.cancel(a),async run(t){s.assertActive(a);const n=i.get();if(!n){throw s.fail("invalid-geometry")}await s.start(v(e,Object.assign(Object.assign({tool:"inpaint"},t),{region:n})))}};return _.set(a,s.controls),a},upscale:j("upscale"),"remove-background":j("remove-background")};export function toolAvailable(e){switch(e){case"crop":return!0;case"expand":return!!a.expand;case"inpaint":return!(!a.replace&&!a.remove);case"upscale":return!!a.upscale;default:return c.removeBackgroundEnabled}}
|
package/image-tools/target.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export declare function targetSnapshot(element: ToolTarget, store: ToolStore): {
|
|
|
25
25
|
height: number;
|
|
26
26
|
x: number;
|
|
27
27
|
y: number;
|
|
28
|
+
fit?: 'cover' | 'contain';
|
|
29
|
+
focus?: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
28
33
|
src: string;
|
|
29
34
|
rotation: number;
|
|
30
35
|
cropX: number;
|
package/image-tools/target.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getRoot as e,isAlive as t}from"mobx-state-tree";import{polotnoError as r}from"@polotno/core/errors";export function toolError(e,t,o
|
|
1
|
+
import{getRoot as e,isAlive as t}from"mobx-state-tree";import{polotnoError as r}from"@polotno/core/errors";export function toolError(e,t,i,o){return r("TOOL_FAILED",`Image tool ${e}: ${i}`,{reason:i,tool:e,elementId:t},o)}export function imageSnapshot(e){var t;return Object.assign(Object.assign({},e.fit&&{fit:e.fit,focus:e.focus}),{src:null!==(t=e.a.src)&&void 0!==t?t:e.src,x:e.x,y:e.y,width:e.width,height:e.height,rotation:e.rotation,cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight,flipX:e.flipX,flipY:e.flipY,stretchEnabled:e.stretchEnabled})}export function eligible(r,i,o){var n;if(!t(r)||e(r)!==i||"viewer"===i.role||!r.page){return!1}if(!r.contentEditable||"expand"===o&&!r.resizable){return!1}if(("crop"===o||"expand"===o)&&"contain"===r.fit){return!1}if("crop"===o?!["image","svg","video"].includes(r.type)||r.maskSrc:"image"!==r.type){return!1}for(let e=r;e&&e!==r.page;e=null!==(n=e.parent)&&void 0!==n?n:null){if(!e.visible||"admin"!==i.role&&!e.selectable){return!1}}return!0}export function targetSnapshot(r,i){var o,n;if(!t(r)||e(r)!==i){return null}const l=[];for(let e=r.parent;e;e=null!==(n=e.parent)&&void 0!==n?n:null){l.push([e.id,e.selectable,e.visible])}return Object.assign(Object.assign({},imageSnapshot(r)),{selectable:r.selectable,visible:r.visible,contentEditable:r.contentEditable,resizable:r.resizable,maskSrc:r.maskSrc,pageId:null===(o=r.page)||void 0===o?void 0:o.id,ancestors:l,role:i.role})}
|
package/image-tools/types.d.ts
CHANGED
|
@@ -50,6 +50,11 @@ export interface RemoveBackgroundRequest {
|
|
|
50
50
|
}
|
|
51
51
|
export type RemoveBackgroundFunc = (src: string, signal?: AbortSignal, request?: RemoveBackgroundRequest) => Promise<string | ImageEditResult>;
|
|
52
52
|
export interface ImageSnapshot extends Rect {
|
|
53
|
+
fit?: 'cover' | 'contain';
|
|
54
|
+
focus?: {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
};
|
|
53
58
|
src: string;
|
|
54
59
|
rotation: number;
|
|
55
60
|
cropX: number;
|
package/model/crop-mode.d.ts
CHANGED
package/model/crop-mode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{observable as e}from"mobx";export const cropMode=o=>{const t=e.box(null,{deep:!1});return{views:{get _cropModeEnabled(){var e;const t=null===(e=o.store)||void 0===e?void 0:e.activeTool;return"crop"===(null==t?void 0:t.name)&&t.elementId===o.id},get _cropEnabled(){var e;return!!(null===(e=o.store)||void 0===e?void 0:e.canUseTool("crop",o.id))},get _sourceSize(){const
|
|
1
|
+
import{observable as e}from"mobx";export const cropMode=o=>{const t=e.box(null,{deep:!1});return{views:{get _cropModeEnabled(){var e;const t=null===(e=o.store)||void 0===e?void 0:e.activeTool;return"crop"===(null==t?void 0:t.name)&&t.elementId===o.id},get _cropEnabled(){var e;return!!(null===(e=o.store)||void 0===e?void 0:e.canUseTool("crop",o.id))},get _sourceSize(){var e;const i=t.get();return(null==i?void 0:i.src)===(null!==(e=o.filled.src)&&void 0!==e?e:o.src)?i.size:null}},actions:{_setSourceSize(e,o){if(e.width<=0||e.height<=0||!Number.isFinite(e.width+e.height)){return}const i=t.get();(null==i?void 0:i.src)===o&&i.size.width===e.width&&i.size.height===e.height||t.set({src:o,size:Object.assign({},e)})},toggleCropMode(e){var t,i;const l=o.store;if(!l){return}const n="crop"===(null===(t=l.activeTool)||void 0===t?void 0:t.name)&&l.activeTool.elementId===o.id;(null!=e?e:!n)?l.canUseTool("crop",o.id)&&l.setTool("crop",{elementId:o.id}):n&&(null===(i=l.activeTool)||void 0===i||i.run().catch(()=>{}))},cancelCropMode(){var e;const t=null===(e=o.store)||void 0===e?void 0:e.activeTool;(null==t?void 0:t.elementId)===o.id&&"crop"===t.name&&t.cancel()}}}};
|
package/model/figure-model.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
6
6
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
7
7
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
8
8
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
9
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
10
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
9
11
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
10
12
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
11
13
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -61,6 +63,13 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
61
63
|
}, {
|
|
62
64
|
readonly page: any;
|
|
63
65
|
readonly store: any;
|
|
66
|
+
readonly filled: Partial<{
|
|
67
|
+
text?: string;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
src?: string;
|
|
70
|
+
fill?: string;
|
|
71
|
+
visible?: boolean;
|
|
72
|
+
}>;
|
|
64
73
|
readonly top: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
65
74
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
66
75
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -68,6 +77,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
68
77
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
69
78
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
70
79
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
80
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
81
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
71
82
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
72
83
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
73
84
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -80,6 +91,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
80
91
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
81
92
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
82
93
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
94
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
95
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
83
96
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
84
97
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
85
98
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -92,6 +105,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
92
105
|
opacity: number | undefined;
|
|
93
106
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
94
107
|
custom: any;
|
|
108
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
109
|
+
href: string | undefined;
|
|
95
110
|
visible: boolean | undefined;
|
|
96
111
|
selectable: boolean | undefined;
|
|
97
112
|
removable: boolean | undefined;
|
|
@@ -103,6 +118,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
103
118
|
name: string;
|
|
104
119
|
opacity: number;
|
|
105
120
|
custom: any;
|
|
121
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
122
|
+
href: string | undefined;
|
|
106
123
|
visible: boolean;
|
|
107
124
|
selectable: boolean;
|
|
108
125
|
removable: boolean;
|
|
@@ -114,6 +131,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
114
131
|
name: string;
|
|
115
132
|
opacity: number;
|
|
116
133
|
custom: any;
|
|
134
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
135
|
+
href: string | undefined;
|
|
117
136
|
visible: boolean;
|
|
118
137
|
selectable: boolean;
|
|
119
138
|
removable: boolean;
|
|
@@ -131,6 +150,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
131
150
|
name: string;
|
|
132
151
|
opacity: number;
|
|
133
152
|
custom: any;
|
|
153
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
154
|
+
href: string | undefined;
|
|
134
155
|
visible: boolean;
|
|
135
156
|
selectable: boolean;
|
|
136
157
|
removable: boolean;
|
|
@@ -142,6 +163,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
142
163
|
name: string;
|
|
143
164
|
opacity: number;
|
|
144
165
|
custom: any;
|
|
166
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
167
|
+
href: string | undefined;
|
|
145
168
|
visible: boolean;
|
|
146
169
|
selectable: boolean;
|
|
147
170
|
removable: boolean;
|
|
@@ -181,6 +204,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
181
204
|
opacity: number | undefined;
|
|
182
205
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
183
206
|
custom: any;
|
|
207
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
208
|
+
href: string | undefined;
|
|
184
209
|
visible: boolean | undefined;
|
|
185
210
|
selectable: boolean | undefined;
|
|
186
211
|
removable: boolean | undefined;
|
|
@@ -192,6 +217,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
192
217
|
name: string;
|
|
193
218
|
opacity: number;
|
|
194
219
|
custom: any;
|
|
220
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
221
|
+
href: string | undefined;
|
|
195
222
|
visible: boolean;
|
|
196
223
|
selectable: boolean;
|
|
197
224
|
removable: boolean;
|
|
@@ -203,6 +230,8 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
|
|
|
203
230
|
name: string;
|
|
204
231
|
opacity: number;
|
|
205
232
|
custom: any;
|
|
233
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
234
|
+
href: string | undefined;
|
|
206
235
|
visible: boolean;
|
|
207
236
|
selectable: boolean;
|
|
208
237
|
removable: boolean;
|
package/model/gif-model.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
6
6
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
7
7
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
8
8
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
9
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
10
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
9
11
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
10
12
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
11
13
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -52,6 +54,17 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
52
54
|
showInExport: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
53
55
|
} & {
|
|
54
56
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
57
|
+
fit: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<"contain" | "cover">>;
|
|
58
|
+
focus: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<{
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
}, {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
}, {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
}>>;
|
|
55
68
|
width: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
56
69
|
height: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
57
70
|
src: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -74,6 +87,13 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
74
87
|
}, {
|
|
75
88
|
readonly page: any;
|
|
76
89
|
readonly store: any;
|
|
90
|
+
readonly filled: Partial<{
|
|
91
|
+
text?: string;
|
|
92
|
+
placeholder?: string;
|
|
93
|
+
src?: string;
|
|
94
|
+
fill?: string;
|
|
95
|
+
visible?: boolean;
|
|
96
|
+
}>;
|
|
77
97
|
readonly top: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
78
98
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
79
99
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -81,6 +101,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
81
101
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
82
102
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
83
103
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
104
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
105
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
84
106
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
85
107
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
86
108
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -93,6 +115,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
93
115
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
94
116
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
95
117
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
118
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
119
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
96
120
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
97
121
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
98
122
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -105,6 +129,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
105
129
|
opacity: number | undefined;
|
|
106
130
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
107
131
|
custom: any;
|
|
132
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
133
|
+
href: string | undefined;
|
|
108
134
|
visible: boolean | undefined;
|
|
109
135
|
selectable: boolean | undefined;
|
|
110
136
|
removable: boolean | undefined;
|
|
@@ -116,6 +142,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
116
142
|
name: string;
|
|
117
143
|
opacity: number;
|
|
118
144
|
custom: any;
|
|
145
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
146
|
+
href: string | undefined;
|
|
119
147
|
visible: boolean;
|
|
120
148
|
selectable: boolean;
|
|
121
149
|
removable: boolean;
|
|
@@ -127,6 +155,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
127
155
|
name: string;
|
|
128
156
|
opacity: number;
|
|
129
157
|
custom: any;
|
|
158
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
159
|
+
href: string | undefined;
|
|
130
160
|
visible: boolean;
|
|
131
161
|
selectable: boolean;
|
|
132
162
|
removable: boolean;
|
|
@@ -144,6 +174,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
144
174
|
name: string;
|
|
145
175
|
opacity: number;
|
|
146
176
|
custom: any;
|
|
177
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
178
|
+
href: string | undefined;
|
|
147
179
|
visible: boolean;
|
|
148
180
|
selectable: boolean;
|
|
149
181
|
removable: boolean;
|
|
@@ -155,6 +187,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
155
187
|
name: string;
|
|
156
188
|
opacity: number;
|
|
157
189
|
custom: any;
|
|
190
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
191
|
+
href: string | undefined;
|
|
158
192
|
visible: boolean;
|
|
159
193
|
selectable: boolean;
|
|
160
194
|
removable: boolean;
|
|
@@ -211,6 +245,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
211
245
|
opacity: number | undefined;
|
|
212
246
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
213
247
|
custom: any;
|
|
248
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
249
|
+
href: string | undefined;
|
|
214
250
|
visible: boolean | undefined;
|
|
215
251
|
selectable: boolean | undefined;
|
|
216
252
|
removable: boolean | undefined;
|
|
@@ -222,6 +258,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
222
258
|
name: string;
|
|
223
259
|
opacity: number;
|
|
224
260
|
custom: any;
|
|
261
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
262
|
+
href: string | undefined;
|
|
225
263
|
visible: boolean;
|
|
226
264
|
selectable: boolean;
|
|
227
265
|
removable: boolean;
|
|
@@ -233,6 +271,8 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
233
271
|
name: string;
|
|
234
272
|
opacity: number;
|
|
235
273
|
custom: any;
|
|
274
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
275
|
+
href: string | undefined;
|
|
236
276
|
visible: boolean;
|
|
237
277
|
selectable: boolean;
|
|
238
278
|
removable: boolean;
|