storeshot 0.1.0 → 0.2.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/CHANGELOG.md +28 -0
- package/CONTRIBUTING.md +6 -0
- package/README.md +36 -8
- package/THIRD_PARTY_LICENSES.txt +29 -0
- package/THIRD_PARTY_NOTICES.md +28 -3
- package/dist/chunk-I7JOE7XJ.js +299 -0
- package/dist/chunk-I7JOE7XJ.js.map +1 -0
- package/dist/cli.js +669 -342
- package/dist/cli.js.map +1 -1
- package/dist/node-renderer-FMVPIQAG.js +517 -0
- package/dist/node-renderer-FMVPIQAG.js.map +1 -0
- package/dist/ui/artwork/cc0-laurels/LICENSE +121 -0
- package/dist/ui/artwork/cc0-laurels/README.md +16 -0
- package/dist/ui/artwork/cc0-laurels/laurel-branch.svg +95 -0
- package/dist/ui/artwork/cc0-laurels/laurel-pair-wide.svg +88 -0
- package/dist/ui/artwork/cc0-laurels/laurel-wreath-classic.svg +45 -0
- package/dist/ui/artwork/cc0-laurels/laurel-wreath-natural.svg +75 -0
- package/dist/ui/assets/AssetsView-FCqaKK4x.js +1 -0
- package/dist/ui/assets/SetEditor-BxiRSHKv.js +440 -0
- package/dist/ui/assets/{index-DPDaBFld.js → index-BrRqpj-U.js} +2 -2
- package/dist/ui/assets/index-KYX154p7.css +2 -0
- package/dist/ui/assets/{shared-BiRg4I01.js → shared-stFaxZuu.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/docs/cli.md +141 -0
- package/docs/images/storeshot-editor.png +0 -0
- package/docs/releasing.md +80 -122
- package/fonts/Geist-Variable.ttf +0 -0
- package/package.json +3 -1
- package/dist/ui/assets/AssetsView-D0lbK5rm.js +0 -1
- package/dist/ui/assets/SetEditor-BBUlgGT0.js +0 -440
- package/dist/ui/assets/index-DfZBqsD3.css +0 -2
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import{a as e,i as t,n}from"./shared-stFaxZuu.js";import{$ as r,$t as i,A as a,An as o,Ar as s,At as c,B as l,Bt as u,C as d,Cn as f,Cr as p,Ct as m,D as h,Dn as g,Dr as _,Dt as v,E as y,En as b,Er as x,Et as S,F as C,Fn as w,Ft as T,G as E,Gn as D,Gt as O,H as k,Ht as A,I as j,In as M,It as N,J as ee,Jn as P,Jt as F,K as I,Kn as L,Kt as te,L as R,Ln as z,Lt as ne,M as re,Mr as B,Mt as ie,N as ae,Nr as oe,Nt as V,O as se,On as ce,Or as le,Ot as H,P as ue,Pn as de,Pt as U,Q as fe,Qn as pe,Qt as me,R as he,Rt as ge,S as _e,Sn as ve,Sr as ye,St as be,T as xe,Tn as Se,Tr as Ce,Tt as we,U as W,Ut as G,V as Te,Vn as Ee,Vt as De,W as Oe,Wt as ke,X as Ae,Xn as je,Xt as Me,Y as Ne,Yt as Pe,Z as Fe,Zn as K,Zt as Ie,_ as Le,_n as Re,_r as ze,_t as Be,a as Ve,an as He,ar as Ue,at as We,b as Ge,bn as Ke,bt as qe,c as Je,cn as Ye,cr as Xe,ct as Ze,d as Qe,dn as $e,dr as et,dt as tt,en as nt,er as rt,et as it,f as at,fn as ot,fr as st,ft as ct,g as lt,gn as ut,gr as dt,gt as ft,h as pt,hn as mt,hr as ht,ht as gt,i as _t,in as vt,ir as yt,it as bt,j as xt,jr as St,jt as Ct,k as wt,kn as Tt,kt as Et,l as Dt,ln as Ot,lr as kt,lt as At,m as jt,mr as Mt,mt as Nt,n as Pt,nn as Ft,nr as It,nt as Lt,o as Rt,on as zt,or as Bt,ot as Vt,p as Ht,pn as Ut,pr as Wt,pt as Gt,q as Kt,qn as qt,qt as Jt,r as Yt,rn as Xt,rr as Zt,rt as Qt,s as $t,sn as en,sr as tn,st as nn,t as rn,tn as an,tr as on,tt as sn,u as cn,un as ln,ur as un,ut as dn,v as fn,vn as pn,vr as mn,vt as hn,w as gn,wn as _n,wr as vn,wt as yn,x as bn,xn,xr as Sn,xt as Cn,y as wn,yn as Tn,yt as En,z as Dn,zt as On}from"./index-BrRqpj-U.js";var kn=St(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),An=St(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),jn=St(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),Mn=St(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Nn=St(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),Pn=St(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),Fn=St(`chevrons-up`,[[`path`,{d:`m17 11-5-5-5 5`,key:`e8nh98`}],[`path`,{d:`m17 18-5-5-5 5`,key:`2avn1x`}]]),In=St(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),Ln=St(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),Rn=St(`flip-horizontal-2`,[[`path`,{d:`m3 7 5 5-5 5V7`,key:`couhi7`}],[`path`,{d:`m21 7-5 5 5 5V7`,key:`6ouia7`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 14v2`,key:`8jcxud`}],[`path`,{d:`M12 8v2`,key:`1woqiv`}],[`path`,{d:`M12 2v2`,key:`tus03m`}]]),zn=St(`flip-vertical-2`,[[`path`,{d:`m17 3-5 5-5-5h10`,key:`1ftt6x`}],[`path`,{d:`m17 21-5-5-5 5h10`,key:`1m0wmu`}],[`path`,{d:`M4 12H2`,key:`rhcxmi`}],[`path`,{d:`M10 12H8`,key:`s88cx1`}],[`path`,{d:`M16 12h-2`,key:`10asgb`}],[`path`,{d:`M22 12h-2`,key:`14jgyd`}]]),Bn=St(`folder-up`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`m9 13 3-3 3 3`,key:`1pxg3c`}]]),Vn=St(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Hn=St(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),Un=St(`pipette`,[[`path`,{d:`m12 9-8.414 8.414A2 2 0 0 0 3 18.828v1.344a2 2 0 0 1-.586 1.414A2 2 0 0 1 3.828 21h1.344a2 2 0 0 0 1.414-.586L15 12`,key:`1y3wsu`}],[`path`,{d:`m18 9 .4.4a1 1 0 1 1-3 3l-3.8-3.8a1 1 0 1 1 3-3l.4.4 3.4-3.4a1 1 0 1 1 3 3z`,key:`110lr1`}],[`path`,{d:`m2 22 .414-.414`,key:`jhxm08`}]]),Wn=St(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),Gn=St(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),Kn=St(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),qn=St(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Jn=St(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),Yn=St(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),Xn=St(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),Zn=St(`type`,[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]),Qn=St(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),q=oe(B(),1),$n=q.createContext(void 0);function er(e=!0){let t=q.useContext($n);if(t===void 0&&!e)throw Error(Ue(25));return t}var tr=q.createContext(void 0);function nr(e){let t=q.useContext(tr);if(t===void 0&&!e)throw Error(Ue(33));return t}var rr=q.createContext(void 0);function ir(e){let t=q.useContext(rr);if(t===void 0&&!e)throw Error(Ue(36));return t}function ar(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,{events:l}=a.useState(`floatingTreeRoot`),u=a.useState(`open`),d=er(!0),f=d!==void 0;return q.useMemo(()=>({id:r,role:`menuitem`,tabIndex:u&&n?0:-1,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&l.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&l.emit(`close`,{domEvent:e,reason:M})},onMouseUp(e){if(d){let t=d.initialCursorPointRef.current;if(d.initialCursorPointRef.current=null,f&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||f&&!_n&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!f||e.button===2)&&(!c||c.type===`regular-item`)&&s.current.click()}}),[t,n,r,l,i,u,a,o,s,d,f,c])}var or={type:`regular-item`};function sr(e){let{closeOnClick:t,disabled:n=!1,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=a.useState(`disabled`),d=n||u,f=q.useRef(null),{getButtonProps:p,buttonRef:m}=yt({disabled:d,focusableWhenDisabled:!0,native:s,composite:!0}),h=ar({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:f,itemMetadata:c}),g=q.useCallback(e=>Bt(h,{onMouseEnter(){c.type===`submenu-trigger`&&c.setActive()}},e,p),[h,p,c]),_=Zt(f,m);return q.useMemo(()=>({getItemProps:g,itemRef:_}),[g,_])}var cr=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.highlighted=`data-highlighted`,e}({}),lr={checked(e){return e?{[cr.checked]:``}:{[cr.unchecked]:``}},...je},ur=q.createContext(void 0);function dr(){let e=q.useContext(ur);if(e===void 0)throw Error(Ue(31));return e}var J=ze(),fr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=q.useState(void 0),c=pe(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,J.jsx)(ur.Provider,{value:s,children:c})}),pr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=b(a),c=dr();return tn(()=>(c(s),()=>{c(void 0)}),[c,s]),pe(`div`,e,{ref:t,props:{id:s,role:`presentation`,...o}})}),mr=q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:u,...d}=e,f=l({label:a}),p=nr(!0),m=b(i),{store:h}=ir(),g=h.useState(`isActive`,f.index),_=h.useState(`itemProps`),{getItemProps:v,itemRef:y}=sr({closeOnClick:c,disabled:s,highlighted:g,id:m,store:h,nativeButton:o,nodeId:p?.context.nodeId,itemMetadata:or});return pe(`div`,e,{state:{disabled:s,highlighted:g},props:[_,d,v],ref:[y,t,f.ref]})}),hr={...L,...je},gr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,{store:s}=ir(),{side:c,align:l}=nr(),u=k(!0)!=null,d=s.useState(`open`),f=s.useState(`transitionStatus`),p=s.useState(`popupProps`),m=s.useState(`mounted`),h=s.useState(`instantType`),g=s.useState(`activeTriggerElement`),_=s.useState(`parent`),y=s.useState(`lastOpenChangeReason`),b=s.useState(`rootId`),x=s.useState(`floatingRootContext`),S=s.useState(`floatingTreeRoot`),C=s.useState(`closeDelay`),w=s.useState(`activeTriggerElement`),E=s.useState(`hoverEnabled`),D=s.useState(`disabled`),O=s.useState(`openMethod`),A=_.type===`context-menu`;Jt({open:d,ref:s.context.popupRef,onComplete(){d&&s.context.onOpenChangeComplete?.(!0)}}),q.useEffect(()=>{function e(e){s.setOpen(!1,ce(e.reason,e.domEvent))}return S.events.on(`close`,e),()=>{S.events.off(`close`,e)}},[S.events,s]),T(x,{enabled:E&&!D&&!A&&_.type!==`menubar`,closeDelay:C});let j=q.useCallback(e=>{s.set(`popupElement`,e)},[s]),M=pe(`div`,e,{state:{transitionStatus:f,side:c,align:l,open:d,nested:_.type===`menu`,instant:h},ref:[t,s.context.popupRef,j],stateAttributesMapping:hr,props:[p,{onKeyDown(e){u&&v.has(e.key)&&e.stopPropagation()}},I(f),o,{"data-rootownerid":b}]}),N=_.type===void 0||A;return(g||_.type===`menubar`&&y!==`outside-press`)&&(N=!0),(0,J.jsx)(Xt,{context:x,openInteractionType:O,modal:A,disabled:!m,returnFocus:a===void 0?N:a,initialFocus:_.type!==`menu`,restoreFocus:!0,externalTree:_.type===`menubar`?void 0:S,previousFocusableElement:w,nextFocusableElement:_.type===void 0?s.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:_.type===void 0?s.context.beforeContentFocusGuardRef:void 0,children:M})}),_r=q.createContext(void 0);function vr(){let e=q.useContext(_r);if(e===void 0)throw Error(Ue(32));return e}var yr=q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i}=ir();return i.useState(`mounted`)||n?(0,J.jsx)(_r.Provider,{value:n,children:(0,J.jsx)(Ot,{ref:t,...r})}):null}),br=q.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=ln,style:g,..._}=e,{store:v}=ir(),y=vr(),b=er(!0),x=v.useState(`parent`),S=v.useState(`floatingRootContext`),C=v.useState(`floatingTreeRoot`),w=v.useState(`mounted`),T=v.useState(`open`),D=v.useState(`modal`),O=v.useState(`openMethod`),k=v.useState(`activeTriggerElement`),A=v.useState(`transitionStatus`),j=v.useState(`positionerElement`),M=v.useState(`instantType`),N=v.useState(`hasViewport`),P=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),L=v.useState(`floatingParentNodeId`),te=S.useState(`domReferenceElement`),R=q.useRef(null),z=F(j,!1,!1),ne=n,re=c,B=l,ie=s,ae=h;x.type===`context-menu`&&(ne=n??x.context?.anchor,ie??=`start`,!o&&ie!==`center`&&(B=e.alignOffset??2,re=e.sideOffset??-5));let oe=o,V=ie;x.type===`menu`?(oe??=`inline-end`,V??=`start`,ae=e.collisionAvoidance??$e):x.type===`menubar`&&(oe??=x.context.orientation===`vertical`?`inline-end`:`bottom`,V??=`start`);let se=x.type===`context-menu`,le=Kt({anchor:ne,floatingRootContext:S,positionMethod:b?`fixed`:r,mounted:w,side:oe,sideOffset:re,align:V,alignOffset:B,arrowPadding:se?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:y,disableAnchorTracking:m,collisionAvoidance:ae,shiftCrossAxis:se&&!(`side`in ae&&ae.side===`flip`),externalTree:C,adaptiveOrigin:N?ee:void 0});q.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,ce(Ee)))}return C.events.on(`menuopenchange`,e),()=>{C.events.off(`menuopenchange`,e)}},[v,C.events,I]),q.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,ce(t))}return C.events.on(`menuopenchange`,e),()=>{C.events.off(`menuopenchange`,e)}},[C.events,v]);let H=Se();q.useEffect(()=>{T||H.clear()},[T,H]),q.useEffect(()=>{function e(e){if(!(!T||e.nodeId!==v.select(`floatingParentNodeId`)))if(e.target&&k&&k!==e.target){let e=v.select(`closeDelay`);e>0?H.isStarted()||H.start(e,()=>{v.setOpen(!1,ce(Ee))}):v.setOpen(!1,ce(Ee))}else H.clear()}return C.events.on(`itemhover`,e),()=>{C.events.off(`itemhover`,e)}},[C.events,T,k,v,H]),q.useEffect(()=>{let e={open:T,nodeId:I,parentNodeId:L,reason:v.select(`lastOpenChangeReason`)};C.events.emit(`menuopenchange`,e)},[C.events,T,v,I,L]),tn(()=>{let e=te,t=R.current;if(e&&(R.current=e),t&&e&&e!==t){v.set(`instantType`,void 0);let e=new AbortController;return z(()=>{v.set(`instantType`,`trigger-change`)},e.signal),()=>{e.abort()}}},[te,z,v]);let ue={open:T,side:le.side,align:le.align,anchorHidden:le.anchorHidden,nested:x.type===`menu`,instant:M},de=x.type===`menubar`&&x.context.modal;Oe(T&&(de||D&&P!==`trigger-hover`),O===`touch`,j,k);let U=E(e,ue,{styles:le.positionerStyles,transitionStatus:A,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!w,inert:!T}),fe=w&&x.type!==`menu`&&(x.type!==`menubar`&&D&&P!==`trigger-hover`||x.type===`menubar`&&x.context.modal),pe=null;return x.type===`menubar`?pe=x.context.contentElement:x.type===void 0&&(pe=k),(0,J.jsxs)(tr.Provider,{value:le,children:[fe&&(0,J.jsx)(Cn,{ref:x.type===`context-menu`||x.type===`nested-context-menu`?x.context.internalBackdropRef:null,inert:be(!T),cutout:pe}),(0,J.jsx)(vt,{id:I,children:(0,J.jsx)(Ae,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,children:U})})]})}),xr=q.createContext(void 0);function Sr(){let e=q.useContext(xr);if(e===void 0)throw Error(Ue(34));return e}var Cr=q.memo(q.forwardRef(function(e,t){let{render:n,className:r,value:i,defaultValue:a,onValueChange:o,disabled:s=!1,style:c,"aria-labelledby":l,...u}=e,[d,f]=q.useState(void 0),[p,m]=bt({controlled:i,default:a,name:`MenuRadioGroup`}),h=Xe((e,t)=>{o?.(e,t),!t.isCanceled&&m(e)}),g=pe(`div`,e,{state:{disabled:s},ref:t,props:{role:`group`,"aria-labelledby":l??d,"aria-disabled":s||void 0,...u}}),_=q.useMemo(()=>({value:p,setValue:h,disabled:s}),[p,h,s]);return(0,J.jsx)(ur.Provider,{value:f,children:(0,J.jsx)(xr.Provider,{value:_,children:g})})})),wr=q.createContext(void 0);function Tr(){let e=q.useContext(wr);if(e===void 0)throw Error(Ue(35));return e}var Er=q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,value:u,style:d,...f}=e,p=l({label:a}),m=nr(!0),h=b(i),{store:g}=ir(),_=g.useState(`isActive`,p.index),v=g.useState(`itemProps`),{value:y,setValue:x,disabled:S}=Sr(),C=S||s,w=y===u,{getItemProps:T,itemRef:E}=sr({closeOnClick:c,disabled:C,highlighted:_,id:h,store:g,nativeButton:o,nodeId:m?.context.nodeId,itemMetadata:or}),D=q.useMemo(()=>({disabled:C,highlighted:_,checked:w}),[C,_,w]);function O(e){let t=ce(M,e.nativeEvent,void 0,{preventUnmountOnClose(){}});x(u,t)}let k=pe(`div`,e,{state:D,stateAttributesMapping:lr,props:[v,{role:`menuitemradio`,"aria-checked":w,onClick:O},f,T],ref:[E,t,p.ref]});return(0,J.jsx)(wr.Provider,{value:D,children:k})}),Dr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=Tr(),c=q.useRef(null),{transitionStatus:l,setMounted:u}=Pe(s.checked);return Jt({open:s.checked,ref:c,onComplete(){s.checked||u(!1)}}),pe(`span`,e,{state:{checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:l},stateAttributesMapping:lr,ref:[t,c],props:{"aria-hidden":!0,...o},enabled:a||s.checked})}),Or=q.createContext(null);function kr(e){let t=q.useContext(Or);if(t===null&&!e)throw Error(Ue(5));return t}var Ar={...ne,disabled:nt(e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled),modal:nt(e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0)),openMethod:nt(e=>e.openMethod),allowMouseEnter:nt(e=>e.allowMouseEnter),highlightItemOnHover:nt(e=>e.highlightItemOnHover),stickIfOpen:nt(e=>e.stickIfOpen),parent:nt(e=>e.parent),rootId:nt(e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId),activeIndex:nt(e=>e.activeIndex),isActive:nt((e,t)=>e.activeIndex===t),hoverEnabled:nt(e=>e.hoverEnabled),instantType:nt(e=>e.instantType),lastOpenChangeReason:nt(e=>e.openChangeReason),floatingTreeRoot:nt(e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot),floatingNodeId:nt(e=>e.floatingNodeId),floatingParentNodeId:nt(e=>e.floatingParentNodeId),itemProps:nt(e=>e.itemProps),closeDelay:nt(e=>e.closeDelay),hasViewport:nt(e=>e.hasViewport),keyboardEventRelay:nt(e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)})},jr=class e extends Ie{constructor(e){super({...Mr(),...e},{positionerRef:q.createRef(),popupRef:q.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},allowMouseUpTriggerRef:{current:!1},triggerFocusTargetRef:q.createRef(),beforeContentFocusGuardRef:q.createRef(),onOpenChangeComplete:void 0,triggerElements:new ge},Ar),this.unsubscribeParentListener=this.observe(`parent`,e=>{if(this.unsubscribeParentListener?.(),e.type===`menu`){let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);this.unsubscribeParentListener=e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);t===i&&n===a&&r===o||(t=i,n=a,r=o,this.notifyAll())}),this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef;return}e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef),this.unsubscribeParentListener=null})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}static useStore(t,n){let r=kt(()=>new e(n)).current;return t??r}unsubscribeParentListener=null};function Mr(){return{...N(),disabled:!1,modal:!0,openMethod:null,allowMouseEnter:!1,highlightItemOnHover:!0,stickIfOpen:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new Ye,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:on,keyboardEventRelay:void 0,closeDelay:0,hasViewport:!1}}var Nr=q.createContext(void 0);function Pr(){return q.useContext(Nr)}var Fr=me(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,defaultOpen:a=!1,disabled:o=!1,modal:s,loopFocus:c=!0,orientation:l=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:_=!0}=e,v=er(!0),y=ir(!0),b=kr(!0),x=Pr(),S=q.useMemo(()=>x&&y?{type:`menu`,store:y.store}:b?{type:`menubar`,context:b}:v&&!y?{type:`context-menu`,context:v}:{type:void 0},[v,y,b,x]),C=jr.useStore(p?.store,{open:a,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:S});G(C,n,a,h),C.useControlledProp(`openProp`,n),C.useControlledProp(`triggerIdProp`,m),C.useContextCallback(`onOpenChangeComplete`,i);let w=g(),T=g(),E=C.useState(`floatingTreeRoot`),D=zt(E),k=en(),j=C.useState(`open`),M=C.useState(`activeTriggerElement`),N=C.useState(`positionerElement`),ee=C.useState(`hoverEnabled`),P=C.useState(`disabled`),F=C.useState(`lastOpenChangeReason`),I=C.useState(`parent`),L=C.useState(`activeIndex`),te=C.useState(`payload`),R=C.useState(`floatingParentNodeId`),z=q.useRef(null),ne=q.useRef(I.type!==`context-menu`),re=Se(),B=q.useRef(!0),ae=Se(),oe=R!=null,{openMethod:se,triggerProps:le}=En(j);C.useSyncedValues({disabled:o,highlightItemOnHover:_,modal:I.type===void 0?s:void 0,openMethod:se,rootId:w}),A(C);let{forceUnmount:H}=ke(j,C,()=>{C.update({allowMouseEnter:!1,stickIfOpen:!0})});tn(()=>{v&&!y?C.update({parent:{type:`context-menu`,context:v},floatingNodeId:D,floatingParentNodeId:k}):y&&C.update({floatingNodeId:D,floatingParentNodeId:k})},[v,y,D,k,C]),q.useEffect(()=>{if(j||(z.current=null),I.type===`context-menu`){if(!j){re.clear(),ne.current=!1;return}re.start(500,()=>{ne.current=!0})}},[re,j,I.type]),tn(()=>{!j&&!ee&&C.set(`hoverEnabled`,!0)},[j,ee,C]);let ue=Xe((e,t)=>{let n=t.reason;if(j===e&&t.trigger===M&&F===n)return;let i=u(t);if(!e&&t.trigger==null&&(t.trigger=M??void 0),r?.(e,t),t.isCanceled)return;C.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&a?.type===`click`&&a.pointerType===`touch`&&!B.current)return;e&&n===`trigger-focus`?(B.current=!1,ae.start(300,()=>{B.current=!0})):(B.current=!0,ae.clear());let o=(n===`trigger-press`||n===`item-press`)&&a.detail===0&&a?.isTrusted,s=!e&&(n===`escape-key`||n==null),c={open:e,openChangeReason:n};z.current=t.event??null,De(c,e,t.trigger,i()),C.update(c),I.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?C.set(`instantType`,`group`):o||s?C.set(`instantType`,o?`click`:`dismiss`):C.set(`instantType`,void 0)}),U=Me({popupStore:C,floatingId:T,nested:k!=null,onOpenChange:ue}),fe=U.context.events;q.useEffect(()=>{let e=({open:e,eventDetails:t})=>ue(e,t);return fe.on(`setOpen`,e),()=>{fe?.off(`setOpen`,e)}},[fe,ue]);let pe=q.useCallback(()=>{C.setOpen(!1,ce(de))},[C]);q.useImperativeHandle(d,()=>({unmount:H,close:pe}),[H,pe]);let me;I.type===`context-menu`&&(me=I.context),q.useImperativeHandle(me?.positionerRef,()=>N,[N]),q.useImperativeHandle(me?.actionsRef,()=>({setOpen:ue}),[ue]);let he=an(U,{enabled:!P,bubbles:{escapeKey:f&&I.type===`menu`},outsidePress(){return I.type!==`context-menu`||z.current?.type===`contextmenu`||ne.current},externalTree:oe?E:void 0}),ge=Ne(),_e=q.useCallback(e=>{C.select(`activeIndex`)!==e&&C.set(`activeIndex`,e)},[C]),ve=V(U,{enabled:!P,listRef:C.context.itemDomElements,activeIndex:L,nested:I.type!==void 0,loopFocus:c,orientation:l,parentOrientation:I.type===`menubar`?I.context.orientation:void 0,rtl:ge===`rtl`,disabledIndices:rt,onNavigate:_e,openOnArrowKeyDown:I.type!==`context-menu`,externalTree:oe?E:void 0,focusItemOnHover:_}),ye=q.useCallback(e=>{C.context.typingRef.current=e},[C]),be=ie(U,{enabled:!P,listRef:C.context.itemLabels,elementsRef:C.context.itemDomElements,activeIndex:L,resetMs:500,onMatch:e=>{j&&e!==L&&C.set(`activeIndex`,e)},onTyping:ye});O(C,{floatingRootContext:U,activeTriggerProps:q.useMemo(()=>{let e=Bt(be.reference,ve.reference,he.reference,{onMouseMove(){C.set(`allowMouseEnter`,!0)}},le);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=j,e},[C,be.reference,ve.reference,he.reference,le,j]),inactiveTriggerProps:q.useMemo(()=>{let e=Bt(ve.trigger,he.trigger,le);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[ve.trigger,he.trigger,le]),popupProps:q.useMemo(()=>Bt(On,{id:T,role:`menu`,"aria-labelledby":M?.id,onMouseMove(){C.set(`allowMouseEnter`,!0),I.type===`menu`&&C.set(`hoverEnabled`,!1)},onClick(){C.select(`hoverEnabled`)&&C.set(`hoverEnabled`,!1)},onKeyDown(e){let t=C.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},be.floating,ve.floating,he.floating),[M,T,I.type,C,be.floating,ve.floating,he.floating]),itemProps:ve.item??on});let xe=q.useMemo(()=>({store:C,parent:S}),[C,S]),Ce=(0,J.jsx)(rr.Provider,{value:xe,children:typeof t==`function`?t({payload:te}):t});return I.type===void 0||I.type===`context-menu`?(0,J.jsx)(He,{externalTree:E,children:Ce}):Ce});function Ir(e){let t=ir().store,n=q.useMemo(()=>({parentMenu:t}),[t]);return(0,J.jsx)(Nr.Provider,{value:n,children:(0,J.jsx)(Fr,{...e})})}function Lr(e){if(Wt(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`)??void 0;if(!Mt(e))return Lr(un(e))}var Rr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,label:a,id:o,nativeButton:s=!1,openOnHover:c=!0,delay:u=100,closeDelay:d=0,disabled:f=!1,...p}=e,m=l({label:a}),h=nr(),{store:g}=ir(),_=b(o),v=g.useState(`open`),y=g.useState(`floatingRootContext`),x=g.useState(`floatingTreeRoot`),S=g.useState(`triggerPopupId`,_),C=te(_,g),w=q.useCallback(e=>{let t=C(e);return e!==null&&g.select(`open`)&&g.select(`activeTriggerId`)==null&&g.update({activeTriggerId:_,activeTriggerElement:e,closeDelay:d}),t},[C,d,g,_]),T=q.useRef(null),E=q.useCallback(e=>{T.current=e,g.set(`activeTriggerElement`,e)},[g]),D=Pr();if(!D?.parentMenu)throw Error(Ue(37));g.useSyncedValue(`closeDelay`,d);let O=D.parentMenu,k=g.useState(`disabled`),A=O.useState(`disabled`),j=f||k||A,M=O.useState(`itemProps`),N=O.useState(`isActive`,m.index),ee=q.useMemo(()=>({type:`submenu-trigger`,setActive(){O.select(`highlightItemOnHover`)&&O.set(`activeIndex`,m.index)}}),[O,m.index]),{getItemProps:F,itemRef:I}=sr({closeOnClick:!1,disabled:j,highlighted:N,id:_,store:g,typingRef:O.context.typingRef,nativeButton:s,itemMetadata:ee,nodeId:h?.context.nodeId}),L=U(y,{enabled:g.useState(`hoverEnabled`)&&c&&!j,handleClose:Ct({blockPointerEvents:!0}),mouseOnly:!0,move:!0,restMs:u,delay:{open:u,close:d},shouldOpen:u>0?()=>O.select(`allowMouseEnter`):void 0,triggerElementRef:T,externalTree:x,isClosing:()=>g.select(`transitionStatus`)===`ending`}),R=Ft(y,{enabled:!j,event:`mousedown`,toggle:!c,ignoreMouse:c,stickIfOpen:!1}).reference??on,z=g.useState(`triggerProps`,!0);return delete z.id,pe(`div`,e,{state:{disabled:j,highlighted:N,open:v},stateAttributesMapping:P,props:[R,L,z,M,{"aria-controls":S,tabIndex:v||N?0:-1,onBlur(){N&&O.set(`activeIndex`,null)}},p,F],ref:[t,m.ref,I,w,E]})});function zr(e){let[t,n]=q.useState({getBoundingClientRect(){return DOMRect.fromRect({width:0,height:0,x:0,y:0})}}),r=q.useRef(null),i=q.useRef(null),a=q.useRef(null),o=q.useRef(null),s=q.useRef(!0),c=q.useRef(null),l=g(),u=q.useMemo(()=>({anchor:t,setAnchor:n,actionsRef:a,backdropRef:r,internalBackdropRef:i,positionerRef:o,allowMouseUpTriggerRef:s,initialCursorPointRef:c,rootId:l}),[t,l]);return(0,J.jsx)($n.Provider,{value:u,children:(0,J.jsx)(rr.Provider,{value:void 0,children:(0,J.jsx)(Fr,{...e})})})}var Br=500,Vr=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{setAnchor:s,actionsRef:c,internalBackdropRef:l,backdropRef:u,positionerRef:d,allowMouseUpTriggerRef:f,initialCursorPointRef:p,rootId:m}=er(!1),{store:h}=ir(!1),g=h.useState(`open`),_=h.useState(`disabled`),v=q.useRef(null),y=q.useRef(null),b=Se(),x=Se(),S=q.useRef(!1);function C(e,t,n){let r=n.type.startsWith(`touch`);p.current={x:e,y:t},s({getBoundingClientRect(){return DOMRect.fromRect({width:r?10:0,height:r?10:0,x:e,y:t})}}),S.current=!1,c.current?.setOpen(!0,ce(D,n)),x.start(Br,()=>{S.current=!0})}function w(e){_||(f.current=!0,ve(e),C(e.clientX,e.clientY,e.nativeEvent),Re(Ut(v.current),`mouseup`,e=>{if(f.current=!1,!S.current)return;x.clear(),S.current=!1;let t=xn(e);Ke(d.current,t)||m&&t&&Lr(t)===m||c.current?.setOpen(!1,ce(o,e))},{once:!0}))}function T(e){if(!_&&(f.current=!1,e.touches.length===1)){e.stopPropagation();let t=e.touches[0];y.current={x:t.clientX,y:t.clientY},b.start(Br,()=>{y.current&&C(y.current.x,y.current.y,e.nativeEvent)})}}function E(e){if(b.isStarted()&&y.current&&e.touches.length===1){let t=e.touches[0],n=Math.abs(t.clientX-y.current.x),r=Math.abs(t.clientY-y.current.y);(n>10||r>10)&&b.clear()}}function O(){b.clear(),y.current=null}return q.useEffect(()=>{function e(e){if(_)return;let t=xn(e);(Ke(v.current,t)||Ke(l.current,t)||Ke(u.current,t))&&e.preventDefault()}return Re(Ut(v.current),`contextmenu`,e)},[u,_,l]),pe(`div`,e,{state:{open:g},ref:[v,t],props:[{onContextMenu:w,onTouchStart:T,onTouchMove:E,onTouchEnd:O,onTouchCancel:O,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:qt})}),Hr=new Map;function Ur(e,t){let n=JSON.stringify({locale:re(e),options:t}),r=Hr.get(n);if(r)return r;let i=new Intl.NumberFormat(e,t);return Hr.set(n,i),i}function Wr(e,t,n){return e==null?``:Ur(t,n).format(e)}function Gr(e,t,n){return(e-t)*100/(n-t)}var Kr=q.createContext(void 0);function qr(){let e=q.useContext(Kr);if(e===void 0)throw Error(Ue(53));return e}var Jr=function(e){return e.scrollAreaCornerHeight=`--scroll-area-corner-height`,e.scrollAreaCornerWidth=`--scroll-area-corner-width`,e}({});function Yr(e,t,n){if(!e)return 0;let r=getComputedStyle(e),i=n===`x`?`Inline`:`Block`;return n===`x`&&t===`margin`?parseFloat(r[`${t}InlineStart`])*2:parseFloat(r[`${t}${i}Start`])+parseFloat(r[`${t}${i}End`])}var Xr=function(e){return e.orientation=`data-orientation`,e.hovering=`data-hovering`,e.scrolling=`data-scrolling`,e.hasOverflowX=`data-has-overflow-x`,e.hasOverflowY=`data-has-overflow-y`,e.overflowXStart=`data-overflow-x-start`,e.overflowXEnd=`data-overflow-x-end`,e.overflowYStart=`data-overflow-y-start`,e.overflowYEnd=`data-overflow-y-end`,e}({}),Zr=function(e){return e.scrolling=`data-scrolling`,e.hasOverflowX=`data-has-overflow-x`,e.hasOverflowY=`data-has-overflow-y`,e.overflowXStart=`data-overflow-x-start`,e.overflowXEnd=`data-overflow-x-end`,e.overflowYStart=`data-overflow-y-start`,e.overflowYEnd=`data-overflow-y-end`,e}({}),Qr={hasOverflowX:e=>e?{[Zr.hasOverflowX]:``}:null,hasOverflowY:e=>e?{[Zr.hasOverflowY]:``}:null,overflowXStart:e=>e?{[Zr.overflowXStart]:``}:null,overflowXEnd:e=>e?{[Zr.overflowXEnd]:``}:null,overflowYStart:e=>e?{[Zr.overflowYStart]:``}:null,overflowYEnd:e=>e?{[Zr.overflowYEnd]:``}:null,cornerHidden:()=>null},$r={x:0,y:0},ei={width:0,height:0},ti={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},ni={x:!0,y:!0,corner:!0},ri=q.forwardRef(function(e,t){let{render:n,className:r,overflowEdgeThreshold:i,style:a,...o}=e,{xStart:s,xEnd:c,yStart:l,yEnd:u}=ii(i),d=b(),f=Se(),p=Se(),{nonce:m,disableStyleElements:h}=Te(),[g,_]=q.useState(!1),[v,y]=q.useState(!1),[x,S]=q.useState(!1),[C,w]=q.useState(!1),[T,E]=q.useState(!1),[D,O]=q.useState(ei),[k,A]=q.useState(ei),[j,M]=q.useState(ti),[N,ee]=q.useState(ni),P=q.useRef(null),F=q.useRef(null),I=q.useRef(null),L=q.useRef(null),te=q.useRef(null),R=q.useRef(null),z=q.useRef(null),ne=q.useRef(!1),re=q.useRef(0),B=q.useRef(0),ie=q.useRef(0),ae=q.useRef(0),oe=q.useRef(`vertical`),V=q.useRef($r),se=Xe(e=>{let t=e.x-V.current.x,n=e.y-V.current.y;V.current=e,n!==0&&(S(!0),f.start(500,()=>{S(!1)})),t!==0&&(y(!0),p.start(500,()=>{y(!1)}))}),ce=Xe(e=>{e.button===0&&(ne.current=!0,re.current=e.clientY,B.current=e.clientX,oe.current=e.currentTarget.getAttribute(Xr.orientation),F.current&&(ie.current=F.current.scrollTop,ae.current=F.current.scrollLeft),te.current&&oe.current===`vertical`&&te.current.setPointerCapture(e.pointerId),R.current&&oe.current===`horizontal`&&R.current.setPointerCapture(e.pointerId))}),le=Xe(e=>{if(!ne.current)return;let t=e.clientY-re.current,n=e.clientX-B.current;if(F.current){let r=F.current.scrollHeight,i=F.current.clientHeight,a=F.current.scrollWidth,o=F.current.clientWidth;if(te.current&&I.current&&oe.current===`vertical`){let n=Yr(I.current,`padding`,`y`),a=Yr(te.current,`margin`,`y`),o=te.current.offsetHeight,s=t/(I.current.offsetHeight-o-n-a);F.current.scrollTop=ie.current+s*(r-i),e.preventDefault(),S(!0),f.start(500,()=>{S(!1)})}if(R.current&&L.current&&oe.current===`horizontal`){let t=Yr(L.current,`padding`,`x`),r=Yr(R.current,`margin`,`x`),i=R.current.offsetWidth,s=n/(L.current.offsetWidth-i-t-r);F.current.scrollLeft=ae.current+s*(a-o),e.preventDefault(),y(!0),p.start(500,()=>{y(!1)})}}}),H=Xe(e=>{ne.current=!1,te.current&&oe.current===`vertical`&&te.current.hasPointerCapture(e.pointerId)&&te.current.releasePointerCapture(e.pointerId),R.current&&oe.current===`horizontal`&&R.current.hasPointerCapture(e.pointerId)&&R.current.releasePointerCapture(e.pointerId)});function ue(e){w(e.pointerType===`touch`)}function de(e){if(ue(e),e.pointerType!==`touch`){let t=Ke(P.current,e.target);_(t)}}let U=q.useMemo(()=>({scrolling:v||x,hasOverflowX:!N.x,hasOverflowY:!N.y,overflowXStart:j.xStart,overflowXEnd:j.xEnd,overflowYStart:j.yStart,overflowYEnd:j.yEnd,cornerHidden:N.corner}),[v,x,N.x,N.y,N.corner,j]),fe={role:`presentation`,onPointerEnter:de,onPointerMove:de,onPointerDown:ue,onPointerLeave(){_(!1)},style:{position:`relative`,[Jr.scrollAreaCornerHeight]:`${D.height}px`,[Jr.scrollAreaCornerWidth]:`${D.width}px`}},me=pe(`div`,e,{state:U,ref:[t,P],props:[fe,o],stateAttributesMapping:Qr}),he=q.useMemo(()=>({handlePointerDown:ce,handlePointerMove:le,handlePointerUp:H,handleScroll:se,cornerSize:D,setCornerSize:O,thumbSize:k,setThumbSize:A,hasMeasuredScrollbar:T,setHasMeasuredScrollbar:E,touchModality:C,cornerRef:z,scrollingX:v,setScrollingX:y,scrollingY:x,setScrollingY:S,hovering:g,setHovering:_,viewportRef:F,rootRef:P,scrollbarYRef:I,scrollbarXRef:L,thumbYRef:te,thumbXRef:R,rootId:d,hiddenState:N,setHiddenState:ee,overflowEdges:j,setOverflowEdges:M,viewportState:U,overflowEdgeThreshold:{xStart:s,xEnd:c,yStart:l,yEnd:u}}),[ce,le,H,se,D,k,T,C,v,y,x,S,g,_,d,N,j,U,s,c,l,u]);return(0,J.jsxs)(Kr.Provider,{value:he,children:[!h&&W.getElement(m),me]})});function ii(e){if(typeof e==`number`){let t=Math.max(0,e);return{xStart:t,xEnd:t,yStart:t,yEnd:t}}return{xStart:Math.max(0,e?.xStart||0),xEnd:Math.max(0,e?.xEnd||0),yStart:Math.max(0,e?.yStart||0),yEnd:Math.max(0,e?.yEnd||0)}}var ai=q.createContext(void 0),oi=function(e){return e.scrollAreaOverflowXStart=`--scroll-area-overflow-x-start`,e.scrollAreaOverflowXEnd=`--scroll-area-overflow-x-end`,e.scrollAreaOverflowYStart=`--scroll-area-overflow-y-start`,e.scrollAreaOverflowYEnd=`--scroll-area-overflow-y-end`,e}({}),si=!1;function ci(){si||f||(typeof CSS<`u`&&`registerProperty`in CSS&&[oi.scrollAreaOverflowXStart,oi.scrollAreaOverflowXEnd,oi.scrollAreaOverflowYStart,oi.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:`<length>`,inherits:!1,initialValue:`0px`})}catch{}}),si=!0)}var li=q.forwardRef(function(e,t){let{render:n,className:i,style:a,...o}=e,{viewportRef:s,scrollbarYRef:c,scrollbarXRef:l,thumbYRef:u,thumbXRef:d,cornerRef:f,cornerSize:p,setCornerSize:m,setThumbSize:h,rootId:g,setHiddenState:_,hiddenState:v,setHasMeasuredScrollbar:y,handleScroll:b,setHovering:x,setOverflowEdges:S,overflowEdges:C,overflowEdgeThreshold:w,scrollingX:T,scrollingY:E}=qr(),D=Ne(),O=q.useRef(!0),k=q.useRef([NaN,NaN,NaN,NaN]),A=Se(),j=Se(),M=Xe(()=>{let e=s.current,t=c.current,n=l.current,i=u.current,a=d.current,o=f.current;if(!e)return;let g=e.scrollHeight,v=e.scrollWidth,b=e.clientHeight,x=e.clientWidth,C=e.scrollTop,T=e.scrollLeft,E=k.current,O=Number.isNaN(E[0]);if(E[0]=b,E[1]=g,E[2]=x,E[3]=v,O&&y(!0),g===0||v===0)return;let A=ui(e),j=A.y,M=A.x,N=x/v,ee=b/g,P=Math.max(0,v-x),F=Math.max(0,g-b),I=0,L=0;if(!M){let e=0;e=it(D===`rtl`?-T:T,0,P),I=r(e,P),L=P-I}let te=j?0:it(C,0,F),R=j?0:r(te,F),z=j?0:F-R,ne=M?0:x,re=j?0:b,B=0,ie=0;!M&&!j&&(B=t?.offsetWidth||0,ie=n?.offsetHeight||0);let ae=p.width===0&&p.height===0,oe=ae?B:0,V=ae?ie:0,se=Yr(n,`padding`,`x`),ce=Yr(t,`padding`,`y`),le=Yr(a,`margin`,`x`),H=Yr(i,`margin`,`y`),ue=ne-se-le,de=re-ce-H,U=n?Math.min(n.offsetWidth-oe,ue):ue,fe=t?Math.min(t.offsetHeight-V,de):de,pe=Math.max(16,U*N),me=Math.max(16,fe*ee);if(h(e=>e.height===me&&e.width===pe?e:{width:pe,height:me}),t&&i){let e=t.offsetHeight-me-ce-H,n=g-b,r=n===0?0:C/n,a=Math.min(e,Math.max(0,r*e));i.style.transform=`translate3d(0,${a}px,0)`}if(n&&a){let e=n.offsetWidth-pe-se-le,t=v-x,r=t===0?0:T/t,i=D===`rtl`?it(r*e,-e,0):it(r*e,0,e);a.style.transform=`translate3d(${i}px,0,0)`}let he=[[oi.scrollAreaOverflowXStart,I],[oi.scrollAreaOverflowXEnd,L],[oi.scrollAreaOverflowYStart,R],[oi.scrollAreaOverflowYEnd,z]];for(let[t,n]of he)e.style.setProperty(t,`${n}px`);o&&(M||j?m({width:0,height:0}):!M&&!j&&m({width:B,height:ie})),_(e=>di(e,A));let ge={xStart:!M&&I>w.xStart,xEnd:!M&&L>w.xEnd,yStart:!j&&R>w.yStart,yEnd:!j&&z>w.yEnd};S(e=>e.xStart===ge.xStart&&e.xEnd===ge.xEnd&&e.yStart===ge.yStart&&e.yEnd===ge.yEnd?e:ge)});tn(()=>{s.current&&ci()},[s]),tn(()=>{queueMicrotask(M)},[M,v,D,w.xStart,w.xEnd,w.yStart,w.yEnd]),tn(()=>{s.current?.matches(`:hover`)&&x(!0)},[s,x]),tn(()=>{let e=s.current;if(typeof ResizeObserver>`u`||!e)return;let t=!1,n=new ResizeObserver(()=>{if(!t){t=!0;let n=k.current;if(n[0]===e.clientHeight&&n[1]===e.scrollHeight&&n[2]===e.clientWidth&&n[3]===e.scrollWidth)return}M()});return n.observe(e),j.start(0,()=>{let t=e.getAnimations({subtree:!0});t.length!==0&&Promise.allSettled(t.map(e=>e.finished)).then(M).catch(()=>{})}),()=>{n.disconnect(),j.clear()}},[M,s,j]);function N(){O.current=!1}let ee={role:`presentation`,...g&&{"data-id":`${g}-viewport`},tabIndex:v.x&&v.y?-1:0,className:W.className,style:{overflow:`scroll`},onScroll(){s.current&&(M(),O.current||b({x:s.current.scrollLeft,y:s.current.scrollTop}),A.start(100,()=>{O.current=!0}))},onWheel:N,onTouchMove:N,onPointerMove:N,onPointerEnter:N,onKeyDown:N},P=q.useMemo(()=>({scrolling:T||E,hasOverflowX:!v.x,hasOverflowY:!v.y,overflowXStart:C.xStart,overflowXEnd:C.xEnd,overflowYStart:C.yStart,overflowYEnd:C.yEnd,cornerHidden:v.corner}),[T,E,v.x,v.y,v.corner,C]),F=pe(`div`,e,{ref:[t,s],state:P,props:[ee,o],stateAttributesMapping:Qr}),I=q.useMemo(()=>({computeThumbPosition:M}),[M]);return(0,J.jsx)(ai.Provider,{value:I,children:F})});function ui(e){let t=e.clientHeight>=e.scrollHeight,n=e.clientWidth>=e.scrollWidth;return{y:t,x:n,corner:t||n}}function di(e,t){return e.y===t.y&&e.x===t.x&&e.corner===t.corner?e:t}var fi=q.createContext(void 0);function pi(){let e=q.useContext(fi);if(e===void 0)throw Error(Ue(54));return e}var mi=function(e){return e.scrollAreaThumbHeight=`--scroll-area-thumb-height`,e.scrollAreaThumbWidth=`--scroll-area-thumb-width`,e}({}),hi=q.forwardRef(function(e,t){let{render:n,className:r,orientation:i=`vertical`,keepMounted:a=!1,style:o,...s}=e,{hovering:c,scrollingX:l,scrollingY:u,hiddenState:d,overflowEdges:f,scrollbarYRef:p,scrollbarXRef:m,viewportRef:h,thumbYRef:g,thumbXRef:_,handlePointerDown:v,handlePointerUp:y,handleScroll:b,rootId:x,thumbSize:S,hasMeasuredScrollbar:C}=qr(),w={hovering:c,scrolling:{horizontal:l,vertical:u}[i],orientation:i,hasOverflowX:!d.x,hasOverflowY:!d.y,overflowXStart:f.xStart,overflowXEnd:f.xEnd,overflowYStart:f.yStart,overflowYEnd:f.yEnd,cornerHidden:d.corner},T=Ne(),E=!C&&!a,D=i===`vertical`?d.y:d.x,O=a||!D;q.useEffect(()=>{if(!O)return;let e=h.current,t=i===`vertical`?p.current:m.current;if(!t)return;function n(n){if(!e||!t||n.ctrlKey)return;let r=i===`horizontal`,a=r?`scrollLeft`:`scrollTop`,o=r?n.deltaX:n.deltaY;if(o===0)return;let s=r?e.scrollWidth-e.clientWidth:e.scrollHeight-e.clientHeight,c=r&&T===`rtl`?-s:0,l=r&&T===`rtl`?0:s,u=e[a];u<=c&&o<0||u>=l&&o>0||(n.preventDefault(),e[a]=Math.min(l,Math.max(c,u+o)),b({x:e.scrollLeft,y:e.scrollTop}))}return Re(t,`wheel`,n,{passive:!1})},[T,b,i,m,p,O,h]);let k={...x&&{"data-id":`${x}-scrollbar`},onPointerDown(e){if(e.button!==0)return;let t=xn(e.nativeEvent),n=i===`vertical`?g.current:_.current;if(!(n&&Ke(n,t))&&h.current){if(g.current&&p.current&&i===`vertical`){let t=Yr(g.current,`margin`,`y`),n=Yr(p.current,`padding`,`y`),r=g.current.offsetHeight,i=p.current.getBoundingClientRect(),a=e.clientY-i.top-r/2-n+t/2,o=h.current.scrollHeight,s=h.current.clientHeight,c=a/(p.current.offsetHeight-r-n-t)*(o-s);h.current.scrollTop=c}if(_.current&&m.current&&i===`horizontal`){let t=Yr(_.current,`margin`,`x`),n=Yr(m.current,`padding`,`x`),r=_.current.offsetWidth,i=m.current.getBoundingClientRect(),a=e.clientX-i.left-r/2-n+t/2,o=h.current.scrollWidth,s=h.current.clientWidth,c=a/(m.current.offsetWidth-r-n-t),l;T===`rtl`?(l=(1-c)*(o-s),h.current.scrollLeft<=0&&(l=-l)):l=c*(o-s),h.current.scrollLeft=l}b({x:h.current.scrollLeft,y:h.current.scrollTop}),v(e)}},onPointerUp:y,onPointerCancel:y,style:{position:`absolute`,touchAction:`none`,WebkitUserSelect:`none`,userSelect:`none`,visibility:E?`hidden`:void 0,...i===`vertical`&&{top:0,bottom:`var(${Jr.scrollAreaCornerHeight})`,insetInlineEnd:0,[mi.scrollAreaThumbHeight]:`${S.height}px`},...i===`horizontal`&&{insetInlineStart:0,insetInlineEnd:`var(${Jr.scrollAreaCornerWidth})`,bottom:0,[mi.scrollAreaThumbWidth]:`${S.width}px`}}},A=pe(`div`,e,{ref:[t,i===`vertical`?p:m],state:w,props:[k,s],stateAttributesMapping:Qr}),j=q.useMemo(()=>({orientation:i}),[i]);return O?(0,J.jsx)(fi.Provider,{value:j,children:A}):null}),gi=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{thumbYRef:o,thumbXRef:s,handlePointerDown:c,handlePointerMove:l,handlePointerUp:u,setScrollingX:d,setScrollingY:f,scrollingX:p,scrollingY:m,hasMeasuredScrollbar:h}=qr(),{orientation:g}=pi(),_={scrolling:g===`horizontal`?p:m,orientation:g};function v(e){g===`vertical`&&f(!1),g===`horizontal`&&d(!1),u(e)}return pe(`div`,e,{ref:[t,g===`vertical`?o:s],state:_,props:[{onPointerDown:c,onPointerMove:l,onPointerUp:v,onPointerCancel:v,style:{visibility:h?void 0:`hidden`,...g===`vertical`&&{height:`var(${mi.scrollAreaThumbHeight})`},...g===`horizontal`&&{width:`var(${mi.scrollAreaThumbWidth})`}}},a]})}),_i=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{cornerRef:o,cornerSize:s,hiddenState:c}=qr(),l=pe(`div`,e,{ref:[t,o],props:[{style:{position:`absolute`,bottom:0,insetInlineEnd:0,width:s.width,height:s.height}},a]});return c.corner?null:l});function vi(e,t){return e-t}function yi(e,t,n){let r=e.slice();return r[t]=n,r.sort(vi)}function bi(e,t,n,r,i,a){let o=e;return o=it(o,n,r),i&&(o=yi(a,t,it(o,a[t-1]??-1/0,a[t+1]??1/0))),o}function xi(e,t,n){if(!Array.isArray(e))return!0;let r=e.reduce((e,t,n,r)=>(n===r.length-1||e.push(Math.abs(t-r[n+1])),e),[]);return Math.min(...r)>=t*n}var Si={activeThumbIndex:()=>null,max:()=>null,min:()=>null,minStepsBetweenValues:()=>null,step:()=>null,values:()=>null,...At},Ci=q.createContext(void 0);function wi(){let e=q.useContext(Ci);if(e===void 0)throw Error(Ue(62));return e}function Ti(e){return`key`in e?z:w}function Ei(e,t){return typeof e==`number`&&typeof t==`number`?e===t:Array.isArray(e)&&Array.isArray(t)?sn(e,t):!1}var Di=q.forwardRef(function(e,t){let{"aria-labelledby":n,className:r,defaultValue:i,disabled:a=!1,id:o,format:s,largeStep:c=10,locale:l,render:u,max:d=100,min:f=0,minStepsBetweenValues:p=0,form:m,name:h,onValueChange:g,onValueCommitted:_,orientation:v=`horizontal`,step:y=1,thumbCollisionBehavior:x=`push`,thumbAlignment:S=`center`,value:C,style:w,...T}=e,E=b(o),D=Fe(E),O=Xe(g),k=Xe(_),{clearErrors:A}=nn(),{state:j,disabled:M,name:N,setTouched:ee,setDirty:P,validityData:F,validation:I}=Ze(),{labelId:L}=Vt(),[te,R]=q.useState(),z=n??fe(L,te),ne=M||a,re=N??h,[B,ie]=bt({controlled:C,default:i??f,name:`Slider`}),ae=q.useRef(null),oe=q.useRef(null),V=q.useRef([]),se=q.useRef(null),le=q.useRef(null),H=q.useRef(-1),ue=q.useRef(null),de=q.useRef(`none`),U=ut(s),[me,he]=q.useState(-1),[ge,_e]=q.useState(-1),[ve,ye]=q.useState(!1),[be,xe]=q.useState(()=>new Map),[Se,Ce]=q.useState([void 0,void 0]),we=Xe(e=>{he(e),e!==-1&&_e(e)});Qt(I.inputRef,E,B,void 0,!ne,h),qe(B,()=>{A(re),I.change(B);let e=F.initialValue,t;t=Array.isArray(B)&&Array.isArray(e)?!sn(B,e):B!==e,P(t)});let W=Xe(e=>{e&&(oe.current=e)}),G=Array.isArray(B),Te=q.useMemo(()=>G?B.slice().sort(vi):[it(B,f,d)],[d,f,G,B]),Ee=Xe((e,t)=>{if(Number.isNaN(e)||Ei(e,B))return!1;let n=t??ce(`none`,void 0,void 0,{activeThumbIndex:-1}),r=n.event,i=new(r.constructor??Event)(r.type,r);return Object.defineProperty(i,"target",{writable:!0,value:{value:e,name:re}}),n.event=i,O(e,n),n.isCanceled?!1:(de.current=n.reason,ie(e),!0)}),De=Xe((e,t,n)=>{let r=bi(e,t,f,d,G,Te);if(xi(r,y,p)){let e=Ti(n),i=Ee(r,ce(e,n.nativeEvent,void 0,{activeThumbIndex:t}));ee(!0),i&&k(r,Tt(e,n.nativeEvent))}});tn(()=>{let e=Tn(Ut(ae.current));ne&&Ke(ae.current,e)&&e.blur()},[ne]),ne&&me!==-1&&we(-1);let Oe=q.useMemo(()=>({...j,activeThumbIndex:me,disabled:ne,dragging:ve,orientation:v,max:d,min:f,minStepsBetweenValues:p,step:y,values:Te}),[j,me,ne,ve,d,f,p,v,y,Te]),ke=q.useMemo(()=>({active:me,controlRef:oe,disabled:ne,dragging:ve,validation:I,formatOptionsRef:U,handleInputChange:De,indicatorPosition:Se,inset:S!==`center`,labelId:z,rootLabelId:D,largeStep:c,lastUsedThumbIndex:ge,lastChangeReasonRef:de,form:m,locale:l,max:d,min:f,minStepsBetweenValues:p,name:re,onValueCommitted:k,orientation:v,pressedInputRef:se,pressedThumbCenterOffsetRef:le,pressedThumbIndexRef:H,pressedValuesRef:ue,registerFieldControlRef:W,renderBeforeHydration:S===`edge`,setActive:we,setDragging:ye,setIndicatorPosition:Ce,setLabelId:R,setValue:Ee,state:Oe,step:y,thumbCollisionBehavior:x,thumbMap:be,thumbRefs:V,values:Te}),[me,oe,z,D,ne,ve,I,U,De,Se,c,ge,de,m,l,d,f,p,re,k,v,se,le,H,ue,W,we,ye,Ce,R,Ee,Oe,y,x,S,be,V,Te]),je=pe(`div`,e,{state:Oe,ref:[t,ae],props:[{"aria-labelledby":z,id:E,role:`group`},T,e=>I.getValidationProps(ne,e)],stateAttributesMapping:Si});return(0,J.jsx)(Ci.Provider,{value:ke,children:(0,J.jsx)(Ae,{elementsRef:V,onMapChange:xe,children:je})})});function Oi(e){let t=e.getBoundingClientRect();return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}}function ki(e){if(e===0)return 0;if(Math.abs(e)<1){let t=e.toExponential().split(`e-`),n=t[0].split(`.`)[1];return(n?n.length:0)+parseInt(t[1],10)}let t=e.toString().split(`.`)[1];return t?t.length:0}function Ai(e,t,n){let r=Math.round((e-n)/t)*t+n;return Number(r.toFixed(Math.max(ki(t),ki(n))))}function ji({values:e,index:t,nextValue:n,min:r,max:i,step:a,minStepsBetweenValues:o,initialValues:s}){if(e.length===0)return[];let c=e.slice(),l=a*o,u=c.length-1,d=s??e;c[t]=it(n,r+t*l,i-(u-t)*l);for(let e=t+1;e<=u;e+=1){let t=c[e-1]+l,n=i-(u-e)*l,r=d[e]??c[e],a=Math.max(c[e],t);r<a&&(a=Math.max(r,t)),c[e]=it(a,t,n)}for(let e=t-1;e>=0;--e){let t=c[e+1]-l,n=r+e*l,i=d[e]??c[e],a=Math.min(c[e],t);i>a&&(a=Math.min(i,t)),c[e]=it(a,n,t)}for(let e=0;e<=u;e+=1)c[e]=Number(c[e].toFixed(12));return c}function Mi({behavior:e,values:t,currentValues:n,initialValues:r,pressedIndex:i,nextValue:a,min:o,max:s,step:c,minStepsBetweenValues:l}){let u=n??t,d=r??t;if(!(u.length>1))return{value:a,thumbIndex:0,didSwap:!1};let f=c*l;switch(e){case`swap`:{let e=u[i],t=1e-7,n=u.slice(),r=n[i-1],p=n[i+1],m=it(a,r==null?o:r+f,p==null?s:p-f),h=Number(m.toFixed(12));n[i]=h;let g=a>e,_=a<e,v=g&&p!=null&&a>=p-t,y=_&&r!=null&&a<=r+t;if(!v&&!y)return{value:n,thumbIndex:i,didSwap:!1};let b=v?i+1:i-1,x=n.map((e,t)=>t===i?h:d[t]??u[t]),S=a;S=v?Math.max(a,n[b]):Math.min(a,n[b]);let C=ji({values:n,index:b,nextValue:S,min:o,max:s,step:c,minStepsBetweenValues:l,initialValues:x}),w=v?b-1:b+1;if(w>=0&&w<C.length){let e=C[w-1],t=C[w+1],n=e==null?o:e+f;n=Math.max(n,o+w*f);let r=t==null?s:t-f;r=Math.min(r,s-(C.length-1-w)*f);let i=it(h,n,r);C[w]=Number(i.toFixed(12))}return{value:C,thumbIndex:b,didSwap:!0}}case`push`:return{value:ji({values:u,index:i,nextValue:a,min:o,max:s,step:c,minStepsBetweenValues:l}),thumbIndex:i,didSwap:!1};default:{let e=u.slice(),t=e[i-1],n=e[i+1],r=it(a,t==null?o:t+f,n==null?s:n-f);return e[i]=Number(r.toFixed(12)),{value:e,thumbIndex:i,didSwap:!1}}}}var Ni=2;function Pi(e,t){if(!e)return{start:0,end:0};function n(e){let t=e==null?0:parseFloat(e);return Number.isNaN(t)?0:t}let r=t?`Top`:`InlineStart`,i=t?`Bottom`:`InlineEnd`;return{start:n(e[`border${r}Width`])+n(e[`padding${r}`]),end:n(e[`border${i}Width`])+n(e[`padding${i}`])}}function Fi(e,t){if(t.current!=null&&e.changedTouches){let n=e;for(let e=0;e<n.changedTouches.length;e+=1){let r=n.changedTouches[e];if(r.identifier===t.current)return{x:r.clientX,y:r.clientY}}return null}return{x:e.clientX,y:e.clientY}}var Ii=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{disabled:o,dragging:s,inset:c,lastChangeReasonRef:l,max:u,min:d,minStepsBetweenValues:f,onValueCommitted:p,orientation:m,pressedInputRef:h,pressedThumbCenterOffsetRef:g,pressedThumbIndexRef:_,pressedValuesRef:v,registerFieldControlRef:y,renderBeforeHydration:b,setActive:x,setDragging:S,setValue:C,state:w,step:T,thumbCollisionBehavior:E,thumbRefs:D,values:O}=wi(),k=Ne(),A=O.length>1,j=m===`vertical`,M=q.useRef(null),N=q.useRef(null),ee=Xe(e=>{e&&N.current==null&&(N.current=et(e).getComputedStyle(e))}),P=q.useRef(null),F=q.useRef(0),I=q.useRef(0),L=q.useRef(null),te=ut(O);function R(e){_.current!==e&&(_.current=e);let t=D.current[e];if(!t){g.current=null,h.current=null;return}h.current=t.querySelector(`input[type="range"]`)}function z(){_.current=-1,g.current=null,h.current=null}function ne(e){return st(e)?D.current.some(t=>!st(t)||!Ke(t,e)?!1:t.querySelector(`input[type="range"]`)?.disabled===!0):!1}function re(e){let t=M.current,n=_.current;if(!t||!A&&(n<0||n>=O.length))return null;let{width:r,height:i,bottom:a,left:o,right:s}=t.getBoundingClientRect(),c=Pi(N.current,j),l=I.current,p=(j?i:r)-c.start-c.end-l*2,m=g.current??0,h=e.x-m,y=e.y-m,b=it(((j?a-y-c.end:(k===`rtl`?s-h:h-o)-c.start)-l)/p,0,1),x=(u-d)*b+d;return x=Ai(x,T,d),x=it(x,d,u),A?n<0?null:Mi({behavior:E,values:O,currentValues:te.current??O,initialValues:v.current,pressedIndex:n,nextValue:x,min:d,max:u,step:T,minStepsBetweenValues:f}):{value:x,thumbIndex:n,didSwap:!1}}function B(e){v.current=A?O.slice():null,L.current=null,te.current=O;let t=_.current,n=t;if(t>-1&&t<O.length){if(O[t]===u){let e=t;for(;e>0&&O[e-1]===u;)--e;n=e}}else{let t=j?`y`:`x`,r;n=-1;for(let i=0;i<D.current.length;i+=1){let a=D.current[i];if(st(a)&&!a.querySelector(`input[type="range"]`)?.disabled){let o=Oi(a),s=Math.abs(e[t]-o[t]);(r===void 0||s<=r)&&(n=i,r=s)}}}if(n>-1&&n!==t&&R(n),c){let e=D.current[n];if(st(e)){let t=e.getBoundingClientRect();I.current=t[j?`height`:`width`]/2}}}function ie(e){let t=D.current?.[e]?.querySelector(`input[type="range"]`);t&&t.focus({preventScroll:!0,focusVisible:!1})}function ae(e,t,n){let r=C(e.value,ce(t,n,void 0,{activeThumbIndex:e.thumbIndex}));return r&&(L.current=e.value,te.current=Array.isArray(e.value)?e.value:[e.value],e.didSwap&&R(e.thumbIndex)),r}let oe=Xe(e=>{let t=Fi(e,P);if(t==null)return;if(F.current+=1,e.type===`pointermove`&&e.buttons===0){V(e);return}let n=re(t);n!=null&&xi(n.value,T,f)&&(!s&&F.current>Ni&&S(!0),ae(n,`drag`,e)&&n.didSwap&&ie(n.thumbIndex))}),V=Xe(e=>{if(x(-1),S(!1),h.current=null,g.current=null,L.current!=null){let t=l.current;p(L.current,Tt(t,e))}`pointerType`in e&&M.current?.hasPointerCapture(e.pointerId)&&M.current?.releasePointerCapture(e.pointerId),_.current=-1,P.current=null,v.current=null,L.current=null,le()}),se=Xe(e=>{if(o)return;if(ne(xn(e))){z();return}let t=e.changedTouches[0];t!=null&&(P.current=t.identifier);let n=Fi(e,P);if(n!=null){B(n);let t=re(n);if(t==null)return;ie(t.thumbIndex),ae(t,`track-press`,e)&&t.didSwap&&ie(t.thumbIndex)}F.current=0;let r=Ut(M.current);r.addEventListener(`touchmove`,oe,{passive:!0}),r.addEventListener(`touchend`,V,{passive:!0})}),le=Xe(()=>{let e=Ut(M.current);e.removeEventListener(`pointermove`,oe),e.removeEventListener(`pointerup`,V),e.removeEventListener(`touchmove`,oe),e.removeEventListener(`touchend`,V),v.current=null,L.current=null}),H=mt();return q.useEffect(()=>{let e=M.current;if(!e)return()=>le();let t=Re(e,`touchstart`,se,{passive:!0});return()=>{t(),H.cancel(),le()}},[le,se,M,H]),q.useEffect(()=>{o&&le()},[o,le]),pe(`div`,e,{state:w,ref:[t,y,M,ee],props:[{"data-base-ui-slider-control":b?``:void 0,onPointerDown(e){let t=M.current,n=xn(e.nativeEvent);if(!t||o||e.defaultPrevented||!st(n)||e.button!==0)return;if(ne(n)){z();return}let r=Fi(e,P);if(r!=null){B(r);let n=re(r);if(n==null)return;Ke(D.current[n.thumbIndex],Tn(Ut(t)))?e.preventDefault():H.request(()=>{ie(n.thumbIndex)}),S(!0),g.current==null&&ae(n,`track-press`,e.nativeEvent)&&n.didSwap&&ie(n.thumbIndex)}e.nativeEvent.pointerId&&t.setPointerCapture(e.nativeEvent.pointerId),F.current=0;let i=Ut(M.current);i.addEventListener(`pointermove`,oe,{passive:!0}),i.addEventListener(`pointerup`,V,{once:!0})}},a],stateAttributesMapping:Si})}),Li=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{state:o}=wi();return pe(`div`,e,{state:o,ref:t,props:[{style:{position:`relative`}},a],stateAttributesMapping:Si})}),Ri=i();function zi(){return It}function Bi(){return!1}function Vi(){return!0}function Hi(){return(0,Ri.useSyncExternalStore)(zi,Bi,Vi)}var Ui=function(e){return e.index=`data-index`,e.dragging=`data-dragging`,e.orientation=`data-orientation`,e.disabled=`data-disabled`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.focused=`data-focused`,e}({}),Wi=new Set([...v,c,Et]);function Gi(e,t,n,r){if(!(t<0))return e.length===2?t===0?`${Wr(e[t],r,n)} start range`:`${Wr(e[t],r,n)} end range`:n?Wr(e[t],r,n):void 0}function Ki(e,t,n,r,i){let a=n===1?e+t:e-t;return it(Number(a.toFixed(Math.max(ki(e),ki(t),ki(r)))),r,i)}var qi=q.forwardRef(function(e,t){let{render:n,children:r,className:i,"aria-describedby":a,"aria-label":o,"aria-labelledby":s,"aria-valuetext":u,disabled:d=!1,getAriaLabel:f,getAriaValueText:p,id:h,index:g,inputRef:_,onBlur:y,onFocus:x,onKeyDown:C,tabIndex:w,style:T,...E}=e,{nonce:D}=Te(),O=b(h),{active:k,lastUsedThumbIndex:A,controlRef:j,disabled:M,validation:N,formatOptionsRef:ee,handleInputChange:P,inset:F,labelId:I,largeStep:L,locale:te,max:R,min:z,minStepsBetweenValues:ne,form:re,name:B,orientation:ie,pressedInputRef:ae,pressedThumbCenterOffsetRef:oe,pressedThumbIndexRef:V,renderBeforeHydration:se,setActive:ce,setIndicatorPosition:le,state:ue,step:de,values:U}=wi(),fe=Ne(),me=d||M,he=U.length>1,ge=ie===`vertical`,_e=fe===`rtl`,{setTouched:ve,setFocused:ye,validationMode:be}=Ze(),xe=q.useRef(null),Se=q.useRef(null),Ce=q.useRef(!1),W=b(),G=We(),Ee=he?W:G,{ref:De,index:Oe}=l({metadata:q.useMemo(()=>({inputId:Ee}),[Ee])}),ke=he?g??Oe:0,Ae=ke===U.length-1,je=U[ke],Me=Gr(je,z,R),[Pe,Fe]=q.useState(),K=Hi(),Ie=A>=0&&A<U.length?A:-1,Le=Xe(()=>{let e=j.current,t=xe.current;if(!e||!t)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=ge?`height`:`width`,a=r[i]-n[i],o=(n[i]/2+a*Me/100)/r[i]*100,s=Number.isFinite(o)?o:void 0;Fe(s),ke===0?le(e=>[s,e[1]]):Ae&&le(e=>[e[0],s])});tn(()=>{F&&queueMicrotask(Le)},[Le,F]),tn(()=>{F&&Le()},[Le,F,Me]),tn(()=>{if(!F)return;let e=j.current,t=xe.current;if(!e||!t)return;let n=et(e).ResizeObserver;if(typeof n!=`function`)return;let r=new n(Le);return r.observe(e),r.observe(t),()=>{r.disconnect()}},[j,Le,F]);let Re=ge?`bottom`:`insetInlineStart`,ze=ge?`left`:`top`,Be;he?k===ke?Be=2:Ie===ke&&(Be=1):k===ke&&(Be=1);let Ve;Ve=F?{"--position":`${Pe??0}%`,visibility:se&&K||Pe===void 0?`hidden`:void 0,position:`absolute`,[Re]:`var(--position)`,[ze]:`50%`,translate:`${(ge||!_e?-1:1)*50}% ${(ge?1:-1)*50}%`,zIndex:Be}:Number.isFinite(Me)?{position:`absolute`,[Re]:`${Me}%`,[ze]:`50%`,translate:`${(ge||!_e?-1:1)*50}% ${(ge?1:-1)*50}%`,zIndex:Be}:ot;let He;ie===`vertical`&&(He=_e?`vertical-rl`:`vertical-lr`);let Ue=typeof f==`function`?f(ke):o,Ge=Bt({"aria-label":Ue,"aria-labelledby":s??(Ue==null?I:void 0),"aria-describedby":a,"aria-orientation":ie,"aria-valuenow":je,"aria-valuetext":typeof p==`function`?p(Wr(je,te,ee.current??void 0),je,ke):u??Gi(U,ke,ee.current??void 0,te),disabled:me,form:re,id:Ee,max:R,min:z,name:B,onChange(e){P(e.currentTarget.valueAsNumber,ke,e)},onFocus(e){let t=Ce.current;Ce.current=!1,ce(ke),ye(!0),t&&e.stopPropagation()},onBlur(e){if(Ce.current){e.stopPropagation();return}xe.current&&(ce(-1),ve(!0),ye(!1),be===`onBlur`&&N.commit(bi(je,ke,z,R,he,U)))},onKeyDown(e){if(e.defaultPrevented||!Wi.has(e.key))return;v.has(e.key)&&e.stopPropagation();let t=null,n=Ai(je,de,z);switch(e.key){case S:t=Ki(n,e.shiftKey?L:de,1,z,R);break;case we:t=Ki(n,e.shiftKey?L:de,_e?-1:1,z,R);break;case m:t=Ki(n,e.shiftKey?L:de,-1,z,R);break;case yn:t=Ki(n,e.shiftKey?L:de,_e?1:-1,z,R);break;case c:t=Ki(n,L,1,z,R);break;case Et:t=Ki(n,L,-1,z,R);break;case`End`:t=R,he&&(t=Number.isFinite(U[ke+1])?U[ke+1]-de*ne:R);break;case H:t=z,he&&(t=Number.isFinite(U[ke-1])?U[ke-1]+de*ne:z);break;default:break}if(t!==null){let n=e.currentTarget;pn(n)||(Ce.current=!0,n.blur(),n.focus({preventScroll:!0,focusVisible:!0})),P(t,ke,e),e.preventDefault()}},step:de,style:{...ot,width:`100%`,height:`100%`,writingMode:He},tabIndex:w??void 0,type:`range`,value:je??``},e=>N.getValidationProps(me,e),{onKeyDown:C}),Ke=Zt(Se,N.inputRef,_);return pe(`div`,e,{state:ue,ref:[t,De,xe],props:[{[Ui.index]:ke,children:(0,J.jsxs)(q.Fragment,{children:[r,(0,J.jsx)(`input`,{ref:Ke,...Ge,suppressHydrationWarning:!0}),F&&K&&se&&Ae&&(0,J.jsx)(`script`,{nonce:D,dangerouslySetInnerHTML:{__html:'!function(){const t=document.currentScript?.parentElement;if(!t)return;const e=t.closest("[data-base-ui-slider-control]");if(!e)return;const r=e.querySelector("[data-base-ui-slider-indicator]"),i=e.getBoundingClientRect(),n="vertical"===e.getAttribute("data-orientation")?"height":"width",o=e.querySelectorAll(\'input[type="range"]\'),l=o.length>1,s=o.length-1;let a=null,u=null;for(let t=0;t<o.length;t+=1){const e=o[t],y=parseFloat(e.getAttribute("value")??"");if(Number.isNaN(y))return;const c=e.parentElement;if(!c)return;const p=parseFloat(e.getAttribute("max")??"100"),g=parseFloat(e.getAttribute("min")??"0"),b=c?.getBoundingClientRect(),d=i[n]-b[n],m=100*(y-g)/(p-g),v=(b[n]/2+d*m/100)/i[n]*100;c.style.setProperty("--position",`${v}%`),Number.isFinite(v)&&(c.style.removeProperty("visibility"),r&&(0===t?(a=v,r.style.setProperty("--start-position",`${v}%`),l||r.style.removeProperty("visibility")):t===s&&(u=v-(a??0),r.style.setProperty("--end-position",`${v}%`),r.style.setProperty("--relative-size",`${u}%`),r.style.removeProperty("visibility"))))}}();'},suppressHydrationWarning:!0})]}),id:O,onBlur:y,onFocus:x,onPointerDown(e){if(!me){if(V.current=ke,xe.current!=null){let t=ie===`horizontal`?`x`:`y`,n=Oi(xe.current),r=(ie===`horizontal`?e.clientX:e.clientY)-n[t];oe.current=r}Se.current!=null&&ae.current!==Se.current&&(ae.current=Se.current)}},style:Ve,suppressHydrationWarning:se||void 0},E],stateAttributesMapping:Si})});function Ji(e,t,n,r,i,a){let o=n===void 0||t&&r===void 0?`hidden`:void 0,s=e?`bottom`:`insetInlineStart`,c=e?`height`:`width`,l={visibility:i&&a?`hidden`:o,position:e?`absolute`:`relative`,[e?`width`:`height`]:`inherit`};return l[`--start-position`]=`${n??0}%`,t?(l[`--relative-size`]=`${(r??0)-(n??0)}%`,l[s]=`var(--start-position)`,l[c]=`var(--relative-size)`,l):(l[s]=0,l[c]=`var(--start-position)`,l)}function Yi(e,t,n,r){let i=e?`bottom`:`insetInlineStart`,a=e?`height`:`width`,o={position:e?`absolute`:`relative`,[e?`width`:`height`]:`inherit`};if(!t)return o[i]=0,o[a]=`${n}%`,o;let s=r-n;return o[i]=`${n}%`,o[a]=`${s}%`,o}var Xi=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{indicatorPosition:o,inset:s,max:c,min:l,orientation:u,renderBeforeHydration:d,state:f,values:p}=wi(),m=Hi(),h=u===`vertical`,g=p.length>1,_=s?Ji(h,g,o[0],o[1],d,m):Yi(h,g,Gr(p[0],l,c),Gr(p[p.length-1],l,c));return pe(`div`,e,{state:f,ref:t,props:[{"data-base-ui-slider-indicator":d?``:void 0,style:_,suppressHydrationWarning:d||void 0},a],stateAttributesMapping:Si})});function Zi({...e}){return(0,J.jsx)(zr,{"data-slot":`context-menu`,...e})}function Qi({className:e,...t}){return(0,J.jsx)(Vr,{"data-slot":`context-menu-trigger`,className:mn(`select-none`,e),...t})}function $i({className:e,align:t=`start`,alignOffset:n=4,side:r=`right`,sideOffset:i=0,...a}){return(0,J.jsx)(yr,{children:(0,J.jsx)(br,{className:`isolate z-50 outline-none`,align:t,alignOffset:n,side:r,sideOffset:i,children:(0,J.jsx)(gr,{"data-slot":`context-menu-content`,className:mn(`z-50 max-h-(--available-height) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...a})})})}function ea({...e}){return(0,J.jsx)(fr,{"data-slot":`context-menu-group`,...e})}function ta({className:e,inset:t,...n}){return(0,J.jsx)(pr,{"data-slot":`context-menu-label`,"data-inset":t,className:mn(`px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7`,e),...n})}function na({className:e,inset:t,variant:n=`default`,...r}){return(0,J.jsx)(mr,{"data-slot":`context-menu-item`,"data-inset":t,"data-variant":n,className:mn(`group/context-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 focus:*:[svg]:text-accent-foreground data-[variant=destructive]:*:[svg]:text-destructive`,e),...r})}function ra({...e}){return(0,J.jsx)(Ir,{"data-slot":`context-menu-sub`,...e})}function ia({className:e,inset:t,children:n,...r}){return(0,J.jsxs)(Rr,{"data-slot":`context-menu-sub-trigger`,"data-inset":t,className:mn(`flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r,children:[n,(0,J.jsx)(Nn,{className:`ml-auto`})]})}function aa({...e}){return(0,J.jsx)($i,{"data-slot":`context-menu-sub-content`,className:`shadow-lg`,side:`right`,...e})}function oa({...e}){return(0,J.jsx)(Cr,{"data-slot":`context-menu-radio-group`,...e})}function sa({className:e,children:t,inset:n,...r}){return(0,J.jsxs)(Er,{"data-slot":`context-menu-radio-item`,"data-inset":n,className:mn(`relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r,children:[(0,J.jsx)(`span`,{className:`pointer-events-none absolute right-2`,children:(0,J.jsx)(Dr,{children:(0,J.jsx)(s,{})})}),t]})}function ca({className:e,...t}){return(0,J.jsx)(Gt,{"data-slot":`context-menu-separator`,className:mn(`-mx-1 my-1 h-px bg-border`,e),...t})}function la({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`context-menu-shortcut`,className:mn(`ml-auto text-xs tracking-widest text-muted-foreground group-focus/context-menu-item:text-accent-foreground`,e),...t})}function ua({className:e,children:t,...n}){return(0,J.jsxs)(ri,{"data-slot":`scroll-area`,className:mn(`relative`,e),...n,children:[(0,J.jsx)(li,{"data-slot":`scroll-area-viewport`,className:`size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1`,children:t}),(0,J.jsx)(da,{}),(0,J.jsx)(_i,{})]})}function da({className:e,orientation:t=`vertical`,...n}){return(0,J.jsx)(hi,{"data-slot":`scroll-area-scrollbar`,"data-orientation":t,orientation:t,className:mn(`flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent`,e),...n,children:(0,J.jsx)(gi,{"data-slot":`scroll-area-thumb`,className:`relative flex-1 rounded-full bg-border`})})}function fa({className:e,defaultValue:t,value:n,min:r=0,max:i=100,...a}){let o=Array.isArray(n)?n:Array.isArray(t)?t:[r,i];return(0,J.jsx)(Di,{className:mn(`data-horizontal:w-full data-vertical:h-full`,e),"data-slot":`slider`,defaultValue:t,value:n,min:r,max:i,thumbAlignment:`edge`,...a,children:(0,J.jsxs)(Ii,{className:`relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:min-h-40 data-vertical:w-auto data-vertical:flex-col`,children:[(0,J.jsx)(Li,{"data-slot":`slider-track`,className:`relative grow overflow-hidden rounded-full bg-muted select-none data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1`,children:(0,J.jsx)(Xi,{"data-slot":`slider-range`,className:`bg-primary select-none data-horizontal:h-full data-vertical:w-full`})}),Array.from({length:o.length},(e,t)=>(0,J.jsx)(qi,{"data-slot":`slider-thumb`,className:`relative block size-3 shrink-0 rounded-full border border-ring bg-white ring-ring/50 transition-[color,box-shadow] select-none after:absolute after:-inset-2 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 disabled:pointer-events-none disabled:opacity-50`},t))]})})}var pa=[`decor`,`lines`,`laurels`],ma=`Tabler Icons`,ha=`Wikimedia Commons`,ga=[{id:`tabler-grid-pattern`,name:`Grid pattern`,category:`decor`,url:`/artwork/tabler/filled/grid-pattern.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-sparkles`,name:`Sparkles`,category:`decor`,url:`/artwork/tabler/filled/sparkles.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-stars`,name:`Stars`,category:`decor`,url:`/artwork/tabler/filled/stars.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-scribble`,name:`Scribble`,category:`lines`,url:`/artwork/tabler/outline/scribble.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-underline`,name:`Underline`,category:`lines`,url:`/artwork/tabler/outline/underline.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-laurel-wreath`,name:`Laurel wreath`,category:`laurels`,url:`/artwork/tabler/filled/laurel-wreath.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-laurel-wreath-1`,name:`Laurel wreath 1`,category:`laurels`,url:`/artwork/tabler/filled/laurel-wreath-1.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-laurel-wreath-2`,name:`Laurel wreath 2`,category:`laurels`,url:`/artwork/tabler/filled/laurel-wreath-2.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`tabler-laurel-wreath-3`,name:`Laurel wreath 3`,category:`laurels`,url:`/artwork/tabler/filled/laurel-wreath-3.svg`,width:24,height:24,attribution:ma,license:`MIT`},{id:`cc0-laurel-wreath-classic`,name:`Classic laurel wreath`,category:`laurels`,url:`/artwork/cc0-laurels/laurel-wreath-classic.svg`,width:564.23,height:574.03,attribution:ha,license:`CC0-1.0`},{id:`cc0-laurel-wreath-natural`,name:`Natural laurel wreath`,category:`laurels`,url:`/artwork/cc0-laurels/laurel-wreath-natural.svg`,width:595.3,height:519.9,attribution:ha,license:`CC0-1.0`},{id:`cc0-laurel-branch`,name:`Laurel branch`,category:`laurels`,url:`/artwork/cc0-laurels/laurel-branch.svg`,width:244.14168,height:307.26953,attribution:ha,license:`CC0-1.0`},{id:`cc0-laurel-pair-wide`,name:`Wide laurel pair`,category:`laurels`,url:`/artwork/cc0-laurels/laurel-pair-wide.svg`,width:555,height:288,attribution:ha,license:`CC0-1.0`}],_a=new Map(ga.map(e=>[e.id,e]));function va(e){return _a.get(e)}function ya(e){return{decor:`Decor`,lines:`Lines`,laurels:`Laurels`}[e]}function ba({open:e,onClose:t,onSelect:n}){let[r,i]=(0,q.useState)(pa[0]);if(!e)return null;let a=ga.filter(e=>e.category===r);return(0,J.jsxs)(`div`,{className:`absolute left-12 top-0 flex max-h-[min(620px,calc(100vh-110px))] w-72 flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-xl`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between border-b px-3 py-2.5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-semibold`,children:`Add artwork`}),(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Reusable open-licensed vectors`})]}),(0,J.jsx)(K,{"aria-label":`Close artwork picker`,size:`icon-xs`,type:`button`,variant:`ghost`,onClick:t,children:(0,J.jsx)(p,{className:`size-3.5`})})]}),(0,J.jsx)(`div`,{className:`flex shrink-0 gap-1 border-b p-2`,children:pa.map(e=>(0,J.jsx)(K,{"aria-pressed":r===e,className:`h-7 px-2.5 text-xs`,size:`sm`,type:`button`,variant:r===e?`secondary`:`ghost`,onClick:()=>i(e),children:ya(e)},e))}),(0,J.jsx)(ua,{className:`min-h-0 flex-1`,children:(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-2 p-3`,children:a.map(e=>(0,J.jsx)(K,{"aria-label":`Add ${e.name}`,className:`group aspect-square h-auto overflow-hidden p-2 text-foreground`,title:`${e.name} · ${e.attribution} · ${e.license}`,type:`button`,variant:`outline`,onClick:()=>n(e),children:(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`size-full bg-current transition-transform group-hover:scale-105`,style:{maskImage:`url(${e.url})`,maskPosition:`center`,maskRepeat:`no-repeat`,maskSize:`contain`,WebkitMaskImage:`url(${e.url})`,WebkitMaskPosition:`center`,WebkitMaskRepeat:`no-repeat`,WebkitMaskSize:`contain`}})},e.id))})}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-t px-3 py-2 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(Kn,{className:`size-3.5`}),`MIT and CC0 artwork. All vectors can be recolored.`]})]})}var xa=Object.defineProperty,Sa=(e,t)=>{let n={};for(var r in e)xa(n,r,{get:e[r],enumerable:!0});return t||xa(n,Symbol.toStringTag,{value:`Module`}),n};function Ca(e){return Ca=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Ca(e)}function wa(e){var t=function(e,t){if(Ca(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Ca(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}(e,`string`);return Ca(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=wa(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Ta=class{constructor(){Y(this,`browserShadowBlurConstant`,1),Y(this,`DPI`,96),Y(this,`devicePixelRatio`,typeof window<`u`?window.devicePixelRatio:1),Y(this,`perfLimitSizeTotal`,2097152),Y(this,`maxCacheSideLimit`,4096),Y(this,`minCacheSideLimit`,256),Y(this,`disableStyleCopyPaste`,!1),Y(this,`enableGLFiltering`,!0),Y(this,`textureSize`,4096),Y(this,`forceGLPutImageData`,!1),Y(this,`cachesBoundsOfCurve`,!1),Y(this,`fontPaths`,{}),Y(this,`NUM_FRACTION_DIGITS`,4)}},X=new class extends Ta{constructor(e){super(),this.configure(e)}configure(e={}){Object.assign(this,e)}addFonts(e={}){this.fontPaths={...this.fontPaths,...e}}removeFonts(e=[]){e.forEach(e=>{delete this.fontPaths[e]})}clearFonts(){this.fontPaths={}}restoreDefaults(e){let t=new Ta,n=e?.reduce((e,n)=>(e[n]=t[n],e),{})||t;this.configure(n)}},Ea=(e,...t)=>console[e](`fabric`,...t),Da=class extends Error{constructor(e,t){super(`fabric: ${e}`,t)}},Oa=class extends Da{constructor(e){super(`${e} 'options.signal' is in 'aborted' state`)}},ka=class{},Aa=class extends ka{testPrecision(e,t){let n=`precision ${t} float;\nvoid main(){}`,r=e.createShader(e.FRAGMENT_SHADER);return!!r&&(e.shaderSource(r,n),e.compileShader(r),!!e.getShaderParameter(r,e.COMPILE_STATUS))}queryWebGL(e){let t=e.getContext(`webgl`);t&&(this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.GLPrecision=[`highp`,`mediump`,`lowp`].find(e=>this.testPrecision(t,e)),t.getExtension(`WEBGL_lose_context`).loseContext(),Ea(`log`,`WebGL: max texture size ${this.maxTextureSize}`))}isSupported(e){return!!this.maxTextureSize&&this.maxTextureSize>=e}},ja={},Ma,Na=()=>Ma||={document,window,isTouchSupported:`ontouchstart`in window||`ontouchstart`in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Aa,dispose(){},copyPasteData:ja},Pa=()=>Na().document,Fa=()=>Na().window,Ia=()=>Math.max(X.devicePixelRatio??Fa().devicePixelRatio,1),La=new class{constructor(){Y(this,`boundsOfCurveCache`,{}),this.charWidthsCache=new Map}getFontCache({fontFamily:e,fontStyle:t,fontWeight:n}){e=e.toLowerCase();let r=this.charWidthsCache;r.has(e)||r.set(e,new Map);let i=r.get(e),a=`${t.toLowerCase()}_${(n+``).toLowerCase()}`;return i.has(a)||i.set(a,new Map),i.get(a)}clearFontCache(e){e?this.charWidthsCache.delete((e||``).toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(e){let{perfLimitSizeTotal:t}=X,n=Math.sqrt(t*e);return[Math.floor(n),Math.floor(t/n)]}},Ra=`7.4.0`;function za(){}var Ba=Math.PI/2,Va=Math.PI/4,Ha=2*Math.PI,Ua=Math.PI/180,Wa=Object.freeze([1,0,0,1,0,0]),Ga=`center`,Ka=`left`,qa=`bottom`,Ja=`right`,Ya=`none`,Xa=/\r?\n/,Za=`moving`,Qa=`scaling`,$a=`rotating`,eo=`rotate`,to=`skewing`,no=`resizing`,ro=`modifyPoly`,io=`changed`,ao=`scale`,oo=`scaleX`,so=`scaleY`,co=`skewX`,lo=`skewY`,uo=`fill`,fo=`stroke`,po=`modified`,mo=`normal`,ho=`json`,Z=new class{constructor(){this[ho]=new Map,this.svg=new Map}has(e){return this[ho].has(e)}getClass(e){let t=this[ho].get(e);if(!t)throw new Da(`No class registered for ${e}`);return t}setClass(e,t){t?this[ho].set(t,e):(this[ho].set(e.type,e),this[ho].set(e.type.toLowerCase(),e))}getSVGClass(e){return this.svg.get(e)}setSVGClass(e,t){this.svg.set(t??e.type.toLowerCase(),e)}},go=new class extends Array{remove(e){let t=this.indexOf(e);t>-1&&this.splice(t,1)}cancelAll(){let e=this.splice(0);return e.forEach(e=>e.abort()),e}cancelByCanvas(e){if(!e)return[];let t=this.filter(t=>t.target===e||typeof t.target==`object`&&t.target?.canvas===e);return t.forEach(e=>e.abort()),t}cancelByTarget(e){if(!e)return[];let t=this.filter(t=>t.target===e);return t.forEach(e=>e.abort()),t}},_o=class{constructor(){Y(this,`__eventListeners`,{})}on(e,t){if(this.__eventListeners||={},typeof e==`object`)return Object.entries(e).forEach(([e,t])=>{this.on(e,t)}),()=>this.off(e);if(t){let n=e;return this.__eventListeners[n]||(this.__eventListeners[n]=[]),this.__eventListeners[n].push(t),()=>this.off(n,t)}return()=>!1}once(e,t){if(typeof e==`object`){let t=[];return Object.entries(e).forEach(([e,n])=>{t.push(this.once(e,n))}),()=>t.forEach(e=>e())}if(t){let n=this.on(e,function(...e){t.call(this,...e),n()});return n}return()=>!1}_removeEventListener(e,t){if(this.__eventListeners[e])if(t){let n=this.__eventListeners[e],r=n.indexOf(t);r>-1&&n.splice(r,1)}else this.__eventListeners[e]=[]}off(e,t){if(this.__eventListeners)if(e===void 0)for(let e in this.__eventListeners)this._removeEventListener(e);else typeof e==`object`?Object.entries(e).forEach(([e,t])=>{this._removeEventListener(e,t)}):this._removeEventListener(e,t)}fire(e,t){if(!this.__eventListeners)return;let n=this.__eventListeners[e]?.concat();if(n)for(let e=0;e<n.length;e++)n[e].call(this,t||{})}},vo=(e,t)=>{let n=e.indexOf(t);return n!==-1&&e.splice(n,1),e},yo=e=>{if(e===0)return 1;switch(Math.abs(e)/Ba){case 1:case 3:return 0;case 2:return-1}return Math.cos(e)},bo=e=>{if(e===0)return 0;let t=e/Ba,n=Math.sign(e);switch(t){case 1:return n;case 2:return 0;case 3:return-n}return Math.sin(e)},Q=class e{constructor(e=0,t=0){typeof e==`object`?(this.x=e.x,this.y=e.y):(this.x=e,this.y=t)}add(t){return new e(this.x+t.x,this.y+t.y)}addEquals(e){return this.x+=e.x,this.y+=e.y,this}scalarAdd(t){return new e(this.x+t,this.y+t)}scalarAddEquals(e){return this.x+=e,this.y+=e,this}subtract(t){return new e(this.x-t.x,this.y-t.y)}subtractEquals(e){return this.x-=e.x,this.y-=e.y,this}scalarSubtract(t){return new e(this.x-t,this.y-t)}scalarSubtractEquals(e){return this.x-=e,this.y-=e,this}multiply(t){return new e(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new e(this.x*t,this.y*t)}scalarMultiplyEquals(e){return this.x*=e,this.y*=e,this}divide(t){return new e(this.x/t.x,this.y/t.y)}scalarDivide(t){return new e(this.x/t,this.y/t)}scalarDivideEquals(e){return this.x/=e,this.y/=e,this}eq(e){return this.x===e.x&&this.y===e.y}lt(e){return this.x<e.x&&this.y<e.y}lte(e){return this.x<=e.x&&this.y<=e.y}gt(e){return this.x>e.x&&this.y>e.y}gte(e){return this.x>=e.x&&this.y>=e.y}lerp(t,n=.5){return n=Math.max(Math.min(1,n),0),new e(this.x+(t.x-this.x)*n,this.y+(t.y-this.y)*n)}distanceFrom(e){let t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}midPointFrom(e){return this.lerp(e)}min(t){return new e(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new e(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return`${this.x},${this.y}`}setXY(e,t){return this.x=e,this.y=t,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setFromPoint(e){return this.x=e.x,this.y=e.y,this}swap(e){let t=this.x,n=this.y;this.x=e.x,this.y=e.y,e.x=t,e.y=n}clone(){return new e(this.x,this.y)}rotate(t,n=xo){let r=bo(t),i=yo(t),a=this.subtract(n);return new e(a.x*i-a.y*r,a.x*r+a.y*i).add(n)}transform(t,n=!1){return new e(t[0]*this.x+t[2]*this.y+(n?0:t[4]),t[1]*this.x+t[3]*this.y+(n?0:t[5]))}},xo=new Q(0,0),So=e=>!!e&&Array.isArray(e._objects);function Co(e){class t extends e{constructor(...e){super(...e),Y(this,`_objects`,[])}_onObjectAdded(e){}_onObjectRemoved(e){}_onStackOrderChanged(e){}add(...e){let t=this._objects.push(...e);return e.forEach(e=>this._onObjectAdded(e)),t}insertAt(e,...t){return this._objects.splice(e,0,...t),t.forEach(e=>this._onObjectAdded(e)),this._objects.length}remove(...e){let t=this._objects,n=[];return e.forEach(e=>{let r=t.indexOf(e);r!==-1&&(t.splice(r,1),n.push(e),this._onObjectRemoved(e))}),n}forEachObject(e){this.getObjects().forEach((t,n,r)=>e(t,n,r))}getObjects(...e){return e.length===0?[...this._objects]:this._objects.filter(t=>t.isType(...e))}item(e){return this._objects[e]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(e,n){return!!this._objects.includes(e)||!!n&&this._objects.some(n=>n instanceof t&&n.contains(e,!0))}complexity(){return this._objects.reduce((e,t)=>e+=t.complexity?t.complexity():0,0)}sendObjectToBack(e){return!(!e||e===this._objects[0])&&(vo(this._objects,e),this._objects.unshift(e),this._onStackOrderChanged(e),!0)}bringObjectToFront(e){return!(!e||e===this._objects[this._objects.length-1])&&(vo(this._objects,e),this._objects.push(e),this._onStackOrderChanged(e),!0)}sendObjectBackwards(e,t){if(!e)return!1;let n=this._objects.indexOf(e);if(n!==0){let r=this.findNewLowerIndex(e,n,t);return vo(this._objects,e),this._objects.splice(r,0,e),this._onStackOrderChanged(e),!0}return!1}bringObjectForward(e,t){if(!e)return!1;let n=this._objects.indexOf(e);if(n!==this._objects.length-1){let r=this.findNewUpperIndex(e,n,t);return vo(this._objects,e),this._objects.splice(r,0,e),this._onStackOrderChanged(e),!0}return!1}moveObjectTo(e,t){return e!==this._objects[t]&&(vo(this._objects,e),this._objects.splice(t,0,e),this._onStackOrderChanged(e),!0)}findNewLowerIndex(e,t,n){let r;if(n){r=t;for(let n=t-1;n>=0;--n)if(e.isOverlapping(this._objects[n])){r=n;break}}else r=t-1;return r}findNewUpperIndex(e,t,n){let r;if(n){r=t;for(let n=t+1;n<this._objects.length;++n)if(e.isOverlapping(this._objects[n])){r=n;break}}else r=t+1;return r}collectObjects({left:e,top:t,width:n,height:r},{includeIntersecting:i=!0}={}){let a=[],o=new Q(e,t),s=o.add(new Q(n,r));for(let e=this._objects.length-1;e>=0;e--){let t=this._objects[e];t.selectable&&t.visible&&(i&&t.intersectsWithRect(o,s)||t.isContainedWithinRect(o,s)||i&&t.containsPoint(o)||i&&t.containsPoint(s))&&a.push(t)}return a}}return t}var wo=class extends _o{_setOptions(e={}){for(let t in e)this.set(t,e[t])}_setObject(e){for(let t in e)this._set(t,e[t])}set(e,t){return typeof e==`object`?this._setObject(e):this._set(e,t),this}_set(e,t){this[e]=t}toggle(e){let t=this.get(e);return typeof t==`boolean`&&this.set(e,!t),this}get(e){return this[e]}};function To(e){return Fa().requestAnimationFrame(e)}function Eo(e){return Fa().cancelAnimationFrame(e)}var Do=0,Oo=()=>Do++,ko=()=>{let e=Pa().createElement(`canvas`);if(!e||e.getContext===void 0)throw new Da("Failed to create `canvas` element");return e},Ao=()=>Pa().createElement(`img`),jo=e=>{var t;let n=Mo(e);return(t=n.getContext(`2d`))==null||t.drawImage(e,0,0),n},Mo=e=>{let t=ko();return t.width=e.width,t.height=e.height,t},No=(e,t,n)=>e.toDataURL(`image/${t}`,n),Po=(e,t,n)=>new Promise((r,i)=>{e.toBlob(r,`image/${t}`,n)}),Fo=e=>e*Ua,Io=e=>e/Ua,Lo=e=>e.every((e,t)=>e===Wa[t]),Ro=(e,t,n)=>new Q(e).transform(t,n),zo=e=>{let t=1/(e[0]*e[3]-e[1]*e[2]),n=[t*e[3],-t*e[1],-t*e[2],t*e[0],0,0],{x:r,y:i}=new Q(e[4],e[5]).transform(n,!0);return n[4]=-r,n[5]=-i,n},Bo=(e,t,n)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],n?0:e[0]*t[4]+e[2]*t[5]+e[4],n?0:e[1]*t[4]+e[3]*t[5]+e[5]],Vo=(e,t)=>e.reduceRight((e,n)=>n&&e?Bo(n,e,t):n||e,void 0)||Wa.concat(),Ho=([e,t])=>Math.atan2(t,e),Uo=([e,t])=>Math.sqrt(e*e+t*t),Wo=([,,e,t])=>Math.sqrt(e*e+t*t),Go=e=>{let t=Ho(e),n=e[0]**2+e[1]**2,r=Math.sqrt(n),i=(e[0]*e[3]-e[2]*e[1])/r,a=Math.atan2(e[0]*e[2]+e[1]*e[3],n);return{angle:Io(t),scaleX:r,scaleY:i,skewX:Io(a),skewY:0,translateX:e[4]||0,translateY:e[5]||0}},Ko=(e,t=0)=>[1,0,0,1,e,t];function qo({angle:e=0}={},{x:t=0,y:n=0}={}){let r=Fo(e),i=yo(r),a=bo(r);return[i,a,-a,i,t?t-(i*t-a*n):0,n?n-(a*t+i*n):0]}var Jo=(e,t=e)=>[e,0,0,t,0,0],Yo=e=>Math.tan(Fo(e)),Xo=e=>[1,0,Yo(e),1,0,0],Zo=e=>[1,Yo(e),0,1,0,0],Qo=({scaleX:e=1,scaleY:t=1,flipX:n=!1,flipY:r=!1,skewX:i=0,skewY:a=0})=>{let o=Jo(n?-e:e,r?-t:t);return i&&(o=Bo(o,Xo(i),!0)),a&&(o=Bo(o,Zo(a),!0)),o},$o=e=>{let{translateX:t=0,translateY:n=0,angle:r=0}=e,i=Ko(t,n);r&&(i=Bo(i,qo({angle:r})));let a=Qo(e);return Lo(a)||(i=Bo(i,a)),i},es=(e,{signal:t,crossOrigin:n=null}={})=>new Promise(function(r,i){if(t&&t.aborted)return i(new Oa(`loadImage`));let a=Ao(),o;t&&(o=function(e){a.src=``,i(e)},t.addEventListener(`abort`,o,{once:!0}));let s=function(){a.onload=a.onerror=null,o&&t?.removeEventListener(`abort`,o),r(a)};e?(a.onload=s,a.onerror=function(){o&&t?.removeEventListener(`abort`,o),i(new Da(`Error loading ${a.src}`))},n&&(a.crossOrigin=n),a.src=e):s()}),ts=(e,{signal:t,reviver:n=za}={})=>new Promise((r,i)=>{let a=[];t&&t.addEventListener(`abort`,i,{once:!0}),Promise.allSettled(e.map(e=>Z.getClass(e.type).fromObject(e,{signal:t}))).then(async t=>{for(let[r,i]of t.entries())if(i.status===`fulfilled`&&(await n(e[r],i.value),a.push(i.value)),i.status===`rejected`){let t=await n(e[r],void 0,i.reason);t&&a.push(t)}r(a)}).catch(e=>{a.forEach(e=>{e.dispose&&e.dispose()}),i(e)}).finally(()=>{t&&t.removeEventListener(`abort`,i)})}),ns=(e,{signal:t}={})=>new Promise((n,r)=>{let i=[];t&&t.addEventListener(`abort`,r,{once:!0});let a=Object.values(e).map(e=>e&&e.type&&Z.has(e.type)?ts([e],{signal:t}).then(([e])=>(i.push(e),e)):e),o=Object.keys(e);Promise.all(a).then(e=>e.reduce((e,t,n)=>(e[o[n]]=t,e),{})).then(n).catch(e=>{i.forEach(e=>{e.dispose&&e.dispose()}),r(e)}).finally(()=>{t&&t.removeEventListener(`abort`,r)})}),rs=(e,t=[])=>t.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{}),is=(e,t)=>Object.keys(e).reduce((n,r)=>(t(e[r],r,e)&&(n[r]=e[r]),n),{}),as=(e,t)=>parseFloat(Number(e).toFixed(t)),os=e=>`matrix(`+e.map(e=>as(e,X.NUM_FRACTION_DIGITS)).join(` `)+`)`,ss=e=>!!e&&e.toLive!==void 0,cs=e=>!!e&&typeof e.toObject==`function`,ls=e=>!!e&&e.offsetX!==void 0&&`source`in e,us=e=>!!e&&`multiSelectionStacking`in e;function ds(e){let t=e&&fs(e),n=0,r=0;if(!e||!t)return{left:n,top:r};let i=e,a=t.documentElement,o=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(n=o.scrollLeft||a.scrollLeft||0,r=o.scrollTop||a.scrollTop||0):(n+=i.scrollLeft||0,r+=i.scrollTop||0),i.nodeType!==1||i.style.position!==`fixed`););return{left:n,top:r}}var fs=e=>e.ownerDocument||null,ps=e=>e.ownerDocument?.defaultView||null,ms=(e,t,{width:n,height:r},i=1)=>{e.width=n,e.height=r,i>1&&(e.setAttribute(`width`,(n*i).toString()),e.setAttribute(`height`,(r*i).toString()),t.scale(i,i))},hs=(e,{width:t,height:n})=>{t&&(e.style.width=typeof t==`number`?`${t}px`:t),n&&(e.style.height=typeof n==`number`?`${n}px`:n)};function gs(e){return e.onselectstart!==void 0&&(e.onselectstart=()=>!1),e.style.userSelect=Ya,e}var _s=class{constructor(e){Y(this,`_originalCanvasStyle`,void 0),Y(this,`lower`,void 0);let t=this.createLowerCanvas(e);this.lower={el:t,ctx:t.getContext(`2d`)}}createLowerCanvas(e){let t=(n=e)&&n.getContext!==void 0?e:e&&Pa().getElementById(e)||ko();var n;if(t.hasAttribute(`data-fabric`))throw new Da(`Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?`);return this._originalCanvasStyle=t.style.cssText,t.setAttribute(`data-fabric`,`main`),t.classList.add(`lower-canvas`),t}cleanupDOM({width:e,height:t}){let{el:n}=this.lower;n.classList.remove(`lower-canvas`),n.removeAttribute(`data-fabric`),n.setAttribute(`width`,`${e}`),n.setAttribute(`height`,`${t}`),n.style.cssText=this._originalCanvasStyle||``,this._originalCanvasStyle=void 0}setDimensions(e,t){let{el:n,ctx:r}=this.lower;ms(n,r,e,t)}setCSSDimensions(e){hs(this.lower.el,e)}calcOffset(){return function(e){let t=e&&fs(e),n={left:0,top:0};if(!t)return n;let r=ps(e)?.getComputedStyle(e,null)||{};n.left+=parseInt(r.borderLeftWidth,10)||0,n.top+=parseInt(r.borderTopWidth,10)||0,n.left+=parseInt(r.paddingLeft,10)||0,n.top+=parseInt(r.paddingTop,10)||0;let i={left:0,top:0},a=t.documentElement;e.getBoundingClientRect!==void 0&&(i=e.getBoundingClientRect());let o=ds(e);return{left:i.left+o.left-(a.clientLeft||0)+n.left,top:i.top+o.top-(a.clientTop||0)+n.top}}(this.lower.el)}dispose(){Na().dispose(this.lower.el),delete this.lower}},vs={backgroundVpt:!0,backgroundColor:``,overlayVpt:!0,overlayColor:``,includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Wa],patternQuality:`best`},ys=Sa({capitalize:()=>bs,escapeXml:()=>$,graphemeSplit:()=>Ss}),bs=(e,t=!1)=>`${e.charAt(0).toUpperCase()}${t?e.slice(1):e.slice(1).toLowerCase()}`,$=e=>e.toString().replace(/&/g,`&`).replace(/"/g,`"`).replace(/'/g,`'`).replace(/</g,`<`).replace(/>/g,`>`),xs,Ss=e=>{if(xs||xs||(xs=`Intl`in Fa()&&`Segmenter`in Intl&&new Intl.Segmenter(void 0,{granularity:`grapheme`})),xs){let t=xs.segment(e);return Array.from(t).map(({segment:e})=>e)}return Cs(e)},Cs=e=>{let t=[];for(let n,r=0;r<e.length;r++)!1!==(n=ws(e,r))&&t.push(n);return t},ws=(e,t)=>{let n=e.charCodeAt(t);if(isNaN(n))return``;if(n<55296||n>57343)return e.charAt(t);if(55296<=n&&n<=56319){if(e.length<=t+1)throw`High surrogate without following low surrogate`;let n=e.charCodeAt(t+1);if(56320>n||n>57343)throw`High surrogate without following low surrogate`;return e.charAt(t)+e.charAt(t+1)}if(t===0)throw`Low surrogate without preceding high surrogate`;let r=e.charCodeAt(t-1);if(55296>r||r>56319)throw`Low surrogate without preceding high surrogate`;return!1},Ts=class e extends Co(wo){get lowerCanvasEl(){return this.elements.lower?.el}get contextContainer(){return this.elements.lower?.ctx}static getDefaults(){return e.ownDefaults}constructor(e,t={}){super(),Object.assign(this,this.constructor.getDefaults()),this.set(t),this.initElements(e),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(e){this.elements=new _s(e)}add(...e){let t=super.add(...e);return e.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(e,...t){let n=super.insertAt(e,...t);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(...e){let t=super.remove(...e);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(e){e.canvas&&e.canvas!==this&&(Ea(`warn`,`Canvas is trying to add an object that belongs to a different canvas.
|
|
2
|
+
Resulting to default behavior: removing object from previous canvas and adding to new canvas`),e.canvas.remove(e)),e._set(`canvas`,this),e.setCoords(),this.fire(`object:added`,{target:e}),e.fire(`added`,{target:this})}_onObjectRemoved(e){e._set(`canvas`,void 0),this.fire(`object:removed`,{target:e}),e.fire(`removed`,{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?Ia():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}_setDimensionsImpl(e,{cssOnly:t=!1,backstoreOnly:n=!1}={}){if(!t){let t={width:this.width,height:this.height,...e};this.elements.setDimensions(t,this.getRetinaScaling()),this.hasLostContext=!0,this.width=t.width,this.height=t.height}n||this.elements.setCSSDimensions(e),this.calcOffset()}setDimensions(e,t){this._setDimensionsImpl(e,t),t&&t.cssOnly||this.requestRenderAll()}getZoom(){return Uo(this.viewportTransform)}setViewportTransform(e){this.viewportTransform=e,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(e,t){let n=e,r=[...this.viewportTransform],i=Ro(e,zo(r));r[0]=t,r[3]=t;let a=Ro(i,r);r[4]+=n.x-a.x,r[5]+=n.y-a.y,this.setViewportTransform(r)}setZoom(e){this.zoomToPoint(new Q(0,0),e)}absolutePan(e){let t=[...this.viewportTransform];return t[4]=-e.x,t[5]=-e.y,this.setViewportTransform(t)}relativePan(e){return this.absolutePan(new Q(-e.x-this.viewportTransform[4],-e.y-this.viewportTransform[5]))}getElement(){return this.elements.lower.el}clearContext(e){e.clearRect(0,0,this.width,this.height)}getContext(){return this.elements.lower.ctx}clear(){this.remove(...this.getObjects()),this.backgroundImage=void 0,this.overlayImage=void 0,this.backgroundColor=``,this.overlayColor=``,this.clearContext(this.getContext()),this.fire(`canvas:cleared`),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.getContext(),this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=To(()=>this.renderAndReset()))}calcViewportBoundaries(){let e=this.width,t=this.height,n=zo(this.viewportTransform),r=Ro({x:0,y:0},n),i=Ro({x:e,y:t},n),a=r.min(i),o=r.max(i);return this.vptCoords={tl:a,tr:new Q(o.x,a.y),bl:new Q(a.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&=(Eo(this.nextRenderHandle),0)}drawControls(e){}renderCanvas(e,t){if(this.destroyed)return;let n=this.viewportTransform,r=this.clipPath;this.calcViewportBoundaries(),this.clearContext(e),e.imageSmoothingEnabled=this.imageSmoothingEnabled,e.patternQuality=this.patternQuality,this.fire(`before:render`,{ctx:e}),this._renderBackground(e),e.save(),e.transform(n[0],n[1],n[2],n[3],n[4],n[5]),this._renderObjects(e,t),e.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(e),r&&(r._set(`canvas`,this),r.shouldCache(),r._transformDone=!0,r.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(e,r)),this._renderOverlay(e),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(e),this.fire(`after:render`,{ctx:e}),this.__cleanupTask&&=(this.__cleanupTask(),void 0)}drawClipPathOnCanvas(e,t){let n=this.viewportTransform;e.save(),e.transform(...n),e.globalCompositeOperation=`destination-in`,t.transform(e),e.scale(1/t.zoomX,1/t.zoomY),e.drawImage(t._cacheCanvas,-t.cacheTranslationX,-t.cacheTranslationY),e.restore()}_renderObjects(e,t){for(let n=0,r=t.length;n<r;++n)t[n]&&t[n].render(e)}_renderBackgroundOrOverlay(e,t){let n=this[`${t}Color`],r=this[`${t}Image`],i=this.viewportTransform,a=this[`${t}Vpt`];if(!n&&!r)return;let o=ss(n);if(n){if(e.save(),e.beginPath(),e.moveTo(0,0),e.lineTo(this.width,0),e.lineTo(this.width,this.height),e.lineTo(0,this.height),e.closePath(),e.fillStyle=o?n.toLive(e):n,a&&e.transform(...i),o){e.transform(1,0,0,1,n.offsetX||0,n.offsetY||0);let t=n.gradientTransform||n.patternTransform;t&&e.transform(...t)}e.fill(),e.restore()}if(r){e.save();let{skipOffscreen:t}=this;this.skipOffscreen=a,a&&e.transform(...i),r.render(e),this.skipOffscreen=t,e.restore()}}_renderBackground(e){this._renderBackgroundOrOverlay(e,`background`)}_renderOverlay(e){this._renderBackgroundOrOverlay(e,`overlay`)}getCenterPoint(){return new Q(this.width/2,this.height/2)}centerObjectH(e){return this._centerObject(e,new Q(this.getCenterPoint().x,e.getCenterPoint().y))}centerObjectV(e){return this._centerObject(e,new Q(e.getCenterPoint().x,this.getCenterPoint().y))}centerObject(e){return this._centerObject(e,this.getCenterPoint())}viewportCenterObject(e){return this._centerObject(e,this.getVpCenter())}viewportCenterObjectH(e){return this._centerObject(e,new Q(this.getVpCenter().x,e.getCenterPoint().y))}viewportCenterObjectV(e){return this._centerObject(e,new Q(e.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Ro(this.getCenterPoint(),zo(this.viewportTransform))}_centerObject(e,t){e.setXY(t,Ga,Ga),e.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(e){return this.toDatalessObject(e)}toObject(e){return this._toObjectMethod(`toObject`,e)}toJSON(){return this.toObject()}toDatalessObject(e){return this._toObjectMethod(`toDatalessObject`,e)}_toObjectMethod(e,t){let n=this.clipPath,r=n&&!n.excludeFromExport?this._toObject(n,e,t):null;return{version:Ra,...rs(this,t),objects:this._objects.filter(e=>!e.excludeFromExport).map(n=>this._toObject(n,e,t)),...this.__serializeBgOverlay(e,t),...r?{clipPath:r}:null}}_toObject(e,t,n){let r;this.includeDefaultValues||(r=e.includeDefaultValues,e.includeDefaultValues=!1);let i=e[t](n);return this.includeDefaultValues||(e.includeDefaultValues=!!r),i}__serializeBgOverlay(e,t){let n={},r=this.backgroundImage,i=this.overlayImage,a=this.backgroundColor,o=this.overlayColor;return ss(a)?a.excludeFromExport||(n.background=a.toObject(t)):a&&(n.background=a),ss(o)?o.excludeFromExport||(n.overlay=o.toObject(t)):o&&(n.overlay=o),r&&!r.excludeFromExport&&(n.backgroundImage=this._toObject(r,e,t)),i&&!i.excludeFromExport&&(n.overlayImage=this._toObject(i,e,t)),n}toSVG(e={},t){e.reviver=t;let n=[];return(this._setSVGPreamble(n,e),this._setSVGHeader(n,e),this.clipPath)&&n.push(`<g clip-path="url(#${$(this.clipPath.clipPathId??``)})" >\n`),this._setSVGBgOverlayColor(n,`background`),this._setSVGBgOverlayImage(n,`backgroundImage`,t),this._setSVGObjects(n,t),this.clipPath&&n.push(`</g>
|
|
3
|
+
`),this._setSVGBgOverlayColor(n,`overlay`),this._setSVGBgOverlayImage(n,`overlayImage`,t),n.push(`</svg>`),n.join(``)}_setSVGPreamble(e,t){t.suppressPreamble||e.push(`<?xml version="1.0" encoding="`,t.encoding||`UTF-8`,`" standalone="no" ?>
|
|
4
|
+
`,`<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" `,`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
5
|
+
`)}_setSVGHeader(e,t){let n=t.width||`${this.width}`,r=t.height||`${this.height}`,i=X.NUM_FRACTION_DIGITS,a=t.viewBox,o;if(a)o=`viewBox="${a.x} ${a.y} ${a.width} ${a.height}" `;else if(this.svgViewportTransformation){let e=this.viewportTransform;o=`viewBox="${as(-e[4]/e[0],i)} ${as(-e[5]/e[3],i)} ${as(this.width/e[0],i)} ${as(this.height/e[3],i)}" `}else o=`viewBox="0 0 ${this.width} ${this.height}" `;e.push(`<svg `,`xmlns="http://www.w3.org/2000/svg" `,`xmlns:xlink="http://www.w3.org/1999/xlink" `,`version="1.1" `,`width="`,n,`" `,`height="`,r,`" `,o,`xml:space="preserve">
|
|
6
|
+
`,`<desc>Created with Fabric.js `,Ra,`</desc>
|
|
7
|
+
`,`<defs>
|
|
8
|
+
`,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(t),`</defs>
|
|
9
|
+
`)}createSVGClipPathMarkup(e){let t=this.clipPath;return t?(t.clipPathId=`CLIPPATH_${Oo()}`,`<clipPath id="${t.clipPathId}" >\n${t.toClipPathSVG(e.reviver)}</clipPath>\n`):``}createSVGRefElementsMarkup(){return[`background`,`overlay`].map(e=>{let t=this[`${e}Color`];if(ss(t)){let n=this[`${e}Vpt`],r=this.viewportTransform,i={isType:()=>!1,width:this.width/(n?r[0]:1),height:this.height/(n?r[3]:1)};return t.toSVG(i,{additionalTransform:n?os(r):``})}}).join(``)}createSVGFontFacesMarkup(){let e=[],t={},n=X.fontPaths;this._objects.forEach(function t(n){e.push(n),So(n)&&n._objects.forEach(t)}),e.forEach(e=>{if(!(r=e)||typeof r._renderText!=`function`)return;var r;let{styles:i,fontFamily:a}=e;!t[a]&&n[a]&&(t[a]=!0,i&&Object.values(i).forEach(e=>{Object.values(e).forEach(({fontFamily:e=``})=>{!t[e]&&n[e]&&(t[e]=!0)})}))});let r=Object.keys(t).map(e=>`\t\t@font-face {\n\t\t\tfont-family: '${e}';\n\t\t\tsrc: url('${n[e]}');\n\t\t}\n`).join(``);return r?`\t<style type="text/css"><![CDATA[\n${r}]]></style>\n`:``}_setSVGObjects(e,t){this.forEachObject(n=>{n.excludeFromExport||this._setSVGObject(e,n,t)})}_setSVGObject(e,t,n){e.push(t.toSVG(n))}_setSVGBgOverlayImage(e,t,n){let r=this[t];r&&!r.excludeFromExport&&r.toSVG&&e.push(r.toSVG(n))}_setSVGBgOverlayColor(e,t){let n=this[`${t}Color`];if(n)if(ss(n)){let r=n.repeat||``,i=this.width,a=this.height,o=this[`${t}Vpt`]?os(zo(this.viewportTransform)):``;e.push(`<rect transform="${o} translate(${i/2},${a/2})" x="${n.offsetX-i/2}" y="${n.offsetY-a/2}" width="${r!==`repeat-y`&&r!==`no-repeat`||!ls(n)?i:n.source.width}" height="${r!==`repeat-x`&&r!==`no-repeat`||!ls(n)?a:n.source.height}" fill="url(#SVGID_${n.id})"></rect>\n`)}else e.push(`<rect x="0" y="0" width="100%" height="100%" `,`fill="`,n,`"`,`></rect>
|
|
10
|
+
`)}loadFromJSON(e,t,{signal:n}={}){if(!e)return Promise.reject(new Da("`json` is undefined"));let{objects:r=[],...i}=typeof e==`string`?JSON.parse(e):e,{backgroundImage:a,background:o,overlayImage:s,overlay:c,clipPath:l}=i,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([ts(r,{reviver:t,signal:n}),ns({backgroundImage:a,backgroundColor:o,overlayImage:s,overlayColor:c,clipPath:l},{signal:n})]).then(([e,t])=>(this.clear(),this.add(...e),this.set(i),this.set(t),this.renderOnAddRemove=u,this))}clone(e){let t=this.toObject(e);return this.cloneWithoutData().loadFromJSON(t)}cloneWithoutData(){let e=Mo(this);return new this.constructor(e)}toDataURL(e={}){let{format:t=`png`,quality:n=1,multiplier:r=1,enableRetinaScaling:i=!1}=e,a=r*(i?this.getRetinaScaling():1);return No(this.toCanvasElement(a,e),t,n)}toBlob(e={}){let{format:t=`png`,quality:n=1,multiplier:r=1,enableRetinaScaling:i=!1}=e,a=r*(i?this.getRetinaScaling():1);return Po(this.toCanvasElement(a,e),t,n)}toCanvasElement(e=1,{width:t,height:n,left:r,top:i,filter:a}={}){let o=(t||this.width)*e,s=(n||this.height)*e,c=this.getZoom(),l=this.width,u=this.height,d=this.skipControlsDrawing,f=c*e,p=this.viewportTransform,m=[f,0,0,f,(p[4]-(r||0))*e,(p[5]-(i||0))*e],h=this.enableRetinaScaling,g=Mo({width:o,height:s}),_=a?this._objects.filter(e=>a(e)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=o,this.height=s,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(g.getContext(`2d`),_),this.viewportTransform=p,this.width=l,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=h,this.skipControlsDrawing=d,g}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),go.cancelByCanvas(this),this.disposed=!0,new Promise((e,t)=>{let n=()=>{this.destroy(),e(!0)};n.kill=t,this.__cleanupTask&&this.__cleanupTask.kill(`aborted`),this.destroyed?e(!1):this.nextRenderHandle?this.__cleanupTask=n:n()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(e=>e.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return`#<Canvas (${this.complexity()}): { objects: ${this._objects.length} }>`}};Y(Ts,`ownDefaults`,vs);var Es=[`touchstart`,`touchmove`,`touchend`],Ds=e=>{let t=ds(e.target),n=function(e){let t=e.changedTouches;return t&&t[0]?t[0]:e}(e);return new Q(n.clientX+t.left,n.clientY+t.top)},Os=e=>Es.includes(e.type)||e.pointerType===`touch`,ks=e=>{e.preventDefault(),e.stopPropagation()},As=e=>{let t=0,n=0,r=0,i=0;for(let a=0,o=e.length;a<o;a++){let{x:o,y:s}=e[a];(o>r||!a)&&(r=o),(o<t||!a)&&(t=o),(s>i||!a)&&(i=s),(s<n||!a)&&(n=s)}return{left:t,top:n,width:r-t,height:i-n}},js=(e,t)=>{Ns(e,Bo(zo(t),e.calcOwnMatrix()))},Ms=(e,t)=>Ns(e,Bo(t,e.calcOwnMatrix())),Ns=(e,t)=>{let{translateX:n,translateY:r,scaleX:i,scaleY:a,...o}=Go(t),s=new Q(n,r);e.flipX=!1,e.flipY=!1,Object.assign(e,o),e.set({scaleX:i,scaleY:a}),e.setPositionByOrigin(s,Ga,Ga)},Ps=e=>{e.scaleX=1,e.scaleY=1,e.skewX=0,e.skewY=0,e.flipX=!1,e.flipY=!1,e.rotate(0)},Fs=e=>({scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,angle:e.angle,left:e.left,flipX:e.flipX,flipY:e.flipY,top:e.top}),Is=(e,t,n)=>{let r=e/2,i=t/2,a=As([new Q(-r,-i),new Q(r,-i),new Q(-r,i),new Q(r,i)].map(e=>e.transform(n)));return new Q(a.width,a.height)},Ls=(e=Wa,t=Wa)=>Bo(zo(t),e),Rs=(e,t=Wa,n=Wa)=>e.transform(Ls(t,n)),zs=(e,t=Wa,n=Wa)=>e.transform(Ls(t,n),!0),Bs=(e,t,n)=>{let r=Ls(t,n);return Ns(e,Bo(r,e.calcOwnMatrix())),r},Vs={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Hs=e=>typeof e==`string`?Vs[e]:e-.5,Us=new Q(1,0),Ws=new Q,Gs=(e,t)=>e.rotate(t),Ks=(e,t)=>new Q(t).subtract(e),qs=e=>e.distanceFrom(Ws),Js=(e,t)=>Math.atan2(Qs(e,t),$s(e,t)),Ys=e=>Js(Us,e),Xs=e=>e.eq(Ws)?e:e.scalarDivide(qs(e)),Zs=(e,t=!0)=>Xs(new Q(-e.y,e.x).scalarMultiply(t?1:-1)),Qs=(e,t)=>e.x*t.y-e.y*t.x,$s=(e,t)=>e.x*t.x+e.y*t.y,ec=(e,t,n)=>{if(e.eq(t)||e.eq(n))return!0;let r=Qs(t,n),i=Qs(t,e),a=Qs(n,e);return r>=0?i>=0&&a<=0:!(i<=0&&a>=0)},tc=`not-allowed`;function nc(e){return Hs(e.originX)===Hs(`center`)&&Hs(e.originY)===Hs(`center`)}function rc(e){return .5-Hs(e)}var ic=(e,t)=>e[t],ac=(e,t,n,r)=>({e,transform:t,pointer:new Q(n,r)});function oc(e,t,n){let r=n,i=Ys(Ks(Rs(e.getCenterPoint(),e.canvas.viewportTransform,void 0),r))+Ha;return Math.round(i%Ha/Va)}function sc({target:e,corner:t},n,r,i,a){let o=e.controls[t],s=e.canvas?.getZoom()||1,c=e.padding/s,l=function(e,t,n,r){let i=e.getRelativeCenterPoint(),a=n!==void 0&&r!==void 0?e.translateToGivenOrigin(i,Ga,Ga,n,r):new Q(e.left,e.top);return(e.angle?t.rotate(-Fo(e.angle),i):t).subtract(a)}(e,new Q(i,a),n,r);return l.x>=c&&(l.x-=c),l.x<=-c&&(l.x+=c),l.y>=c&&(l.y-=c),l.y<=c&&(l.y+=c),l.x-=o.offsetX,l.y-=o.offsetY,l}var cc=new RegExp(String.raw`[\0-\x1F\x7F;<>\\]|\/\*|\*\/|url\s*\(|expression\s*\(|(?:java|vb)script\s*:|data\s*:|@import\b`,`iu`),lc=e=>typeof e==`string`&&e.trim().length>0&&!cc.test(e),uc=(e,t=``)=>{let n=Number(e);return Number.isFinite(n)?`${n}`:t},dc=(e,t=``)=>typeof e==`string`&&lc(e)?e:t,fc=e=>e.replace(/\s+/g,` `),pc={aliceblue:`#F0F8FF`,antiquewhite:`#FAEBD7`,aqua:`#0FF`,aquamarine:`#7FFFD4`,azure:`#F0FFFF`,beige:`#F5F5DC`,bisque:`#FFE4C4`,black:`#000`,blanchedalmond:`#FFEBCD`,blue:`#00F`,blueviolet:`#8A2BE2`,brown:`#A52A2A`,burlywood:`#DEB887`,cadetblue:`#5F9EA0`,chartreuse:`#7FFF00`,chocolate:`#D2691E`,coral:`#FF7F50`,cornflowerblue:`#6495ED`,cornsilk:`#FFF8DC`,crimson:`#DC143C`,cyan:`#0FF`,darkblue:`#00008B`,darkcyan:`#008B8B`,darkgoldenrod:`#B8860B`,darkgray:`#A9A9A9`,darkgrey:`#A9A9A9`,darkgreen:`#006400`,darkkhaki:`#BDB76B`,darkmagenta:`#8B008B`,darkolivegreen:`#556B2F`,darkorange:`#FF8C00`,darkorchid:`#9932CC`,darkred:`#8B0000`,darksalmon:`#E9967A`,darkseagreen:`#8FBC8F`,darkslateblue:`#483D8B`,darkslategray:`#2F4F4F`,darkslategrey:`#2F4F4F`,darkturquoise:`#00CED1`,darkviolet:`#9400D3`,deeppink:`#FF1493`,deepskyblue:`#00BFFF`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1E90FF`,firebrick:`#B22222`,floralwhite:`#FFFAF0`,forestgreen:`#228B22`,fuchsia:`#F0F`,gainsboro:`#DCDCDC`,ghostwhite:`#F8F8FF`,gold:`#FFD700`,goldenrod:`#DAA520`,gray:`#808080`,grey:`#808080`,green:`#008000`,greenyellow:`#ADFF2F`,honeydew:`#F0FFF0`,hotpink:`#FF69B4`,indianred:`#CD5C5C`,indigo:`#4B0082`,ivory:`#FFFFF0`,khaki:`#F0E68C`,lavender:`#E6E6FA`,lavenderblush:`#FFF0F5`,lawngreen:`#7CFC00`,lemonchiffon:`#FFFACD`,lightblue:`#ADD8E6`,lightcoral:`#F08080`,lightcyan:`#E0FFFF`,lightgoldenrodyellow:`#FAFAD2`,lightgray:`#D3D3D3`,lightgrey:`#D3D3D3`,lightgreen:`#90EE90`,lightpink:`#FFB6C1`,lightsalmon:`#FFA07A`,lightseagreen:`#20B2AA`,lightskyblue:`#87CEFA`,lightslategray:`#789`,lightslategrey:`#789`,lightsteelblue:`#B0C4DE`,lightyellow:`#FFFFE0`,lime:`#0F0`,limegreen:`#32CD32`,linen:`#FAF0E6`,magenta:`#F0F`,maroon:`#800000`,mediumaquamarine:`#66CDAA`,mediumblue:`#0000CD`,mediumorchid:`#BA55D3`,mediumpurple:`#9370DB`,mediumseagreen:`#3CB371`,mediumslateblue:`#7B68EE`,mediumspringgreen:`#00FA9A`,mediumturquoise:`#48D1CC`,mediumvioletred:`#C71585`,midnightblue:`#191970`,mintcream:`#F5FFFA`,mistyrose:`#FFE4E1`,moccasin:`#FFE4B5`,navajowhite:`#FFDEAD`,navy:`#000080`,oldlace:`#FDF5E6`,olive:`#808000`,olivedrab:`#6B8E23`,orange:`#FFA500`,orangered:`#FF4500`,orchid:`#DA70D6`,palegoldenrod:`#EEE8AA`,palegreen:`#98FB98`,paleturquoise:`#AFEEEE`,palevioletred:`#DB7093`,papayawhip:`#FFEFD5`,peachpuff:`#FFDAB9`,peru:`#CD853F`,pink:`#FFC0CB`,plum:`#DDA0DD`,powderblue:`#B0E0E6`,purple:`#800080`,rebeccapurple:`#639`,red:`#F00`,rosybrown:`#BC8F8F`,royalblue:`#4169E1`,saddlebrown:`#8B4513`,salmon:`#FA8072`,sandybrown:`#F4A460`,seagreen:`#2E8B57`,seashell:`#FFF5EE`,sienna:`#A0522D`,silver:`#C0C0C0`,skyblue:`#87CEEB`,slateblue:`#6A5ACD`,slategray:`#708090`,slategrey:`#708090`,snow:`#FFFAFA`,springgreen:`#00FF7F`,steelblue:`#4682B4`,tan:`#D2B48C`,teal:`#008080`,thistle:`#D8BFD8`,tomato:`#FF6347`,turquoise:`#40E0D0`,violet:`#EE82EE`,wheat:`#F5DEB3`,white:`#FFF`,whitesmoke:`#F5F5F5`,yellow:`#FF0`,yellowgreen:`#9ACD32`},mc=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e),hc=(e,t,n,r)=>{e/=255,t/=255,n/=255;let i=Math.max(e,t,n),a=Math.min(e,t,n),o,s,c=(i+a)/2;if(i===a)o=s=0;else{let r=i-a;switch(s=c>.5?r/(2-i-a):r/(i+a),i){case e:o=(t-n)/r+(t<n?6:0);break;case t:o=(n-e)/r+2;break;case n:o=(e-t)/r+4}o/=6}return[Math.round(360*o),Math.round(100*s),Math.round(100*c),r]},gc=(e=`1`)=>parseFloat(e)/(e.endsWith(`%`)?100:1),_c=e=>Math.min(Math.round(e),255).toString(16).toUpperCase().padStart(2,`0`),vc=([e,t,n,r=1])=>{let i=Math.round(.3*e+.59*t+.11*n);return[i,i,i,r]},yc=class e{constructor(t){if(Y(this,`isUnrecognised`,!1),t)if(t instanceof e)this.setSource([...t._source]);else if(Array.isArray(t)){let[e,n,r,i=1]=t;this.setSource([e,n,r,i])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in pc&&(t=pc[t]),t===`transparent`?[255,255,255,0]:e.sourceFromHex(t)||e.sourceFromRgb(t)||e.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(e){this._source=e}toRgb(){let[e,t,n]=this.getSource();return`rgb(${e},${t},${n})`}toRgba(){return`rgba(${this.getSource().join(`,`)})`}toHsl(){let[e,t,n]=hc(...this.getSource());return`hsl(${e},${t}%,${n}%)`}toHsla(){let[e,t,n,r]=hc(...this.getSource());return`hsla(${e},${t}%,${n}%,${r})`}toHex(){return this.toHexa().slice(0,6)}toHexa(){let[e,t,n,r]=this.getSource();return`${_c(e)}${_c(t)}${_c(n)}${_c(Math.round(255*r))}`}getAlpha(){return this.getSource()[3]}setAlpha(e){return this._source[3]=e,this}toGrayscale(){return this.setSource(vc(this.getSource())),this}toBlackWhite(e){let[t,,,n]=vc(this.getSource()),r=t<(e||127)?0:255;return this.setSource([r,r,r,n]),this}overlayWith(t){t instanceof e||(t=new e(t));let n=this.getSource(),r=t.getSource(),[i,a,o]=n.map((e,t)=>Math.round(.5*e+.5*r[t]));return this.setSource([i,a,o,n[3]]),this}static fromRgb(t){return e.fromRgba(t)}static fromRgba(t){return new e(e.sourceFromRgb(t))}static sourceFromRgb(e){let t=fc(e).match(/^rgba?\(\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d{0,3}(?:\.\d+)?%?)\s?)?\)$/i);if(t){let[e,n,r]=t.slice(1,4).map(e=>{let t=parseFloat(e);return e.endsWith(`%`)?Math.round(2.55*t):t});return[e,n,r,gc(t[4])]}}static fromHsl(t){return e.fromHsla(t)}static fromHsla(t){return new e(e.sourceFromHsl(t))}static sourceFromHsl(t){let n=fc(t).match(/^hsla?\(\s?([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d*(?:\.\d+)?%?)\s?)?\)$/i);if(!n)return;let r=(e.parseAngletoDegrees(n[1])%360+360)%360/360,i=parseFloat(n[2])/100,a=parseFloat(n[3])/100,o,s,c;if(i===0)o=s=c=a;else{let e=a<=.5?a*(i+1):a+i-a*i,t=2*a-e;o=mc(t,e,r+1/3),s=mc(t,e,r),c=mc(t,e,r-1/3)}return[Math.round(255*o),Math.round(255*s),Math.round(255*c),gc(n[4])]}static fromHex(t){return new e(e.sourceFromHex(t))}static sourceFromHex(e){if(e.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){let t=e.slice(e.indexOf(`#`)+1),n;n=t.length<=4?t.split(``).map(e=>e+e):t.match(/.{2}/g);let[r,i,a,o=255]=n.map(e=>parseInt(e,16));return[r,i,a,o/255]}}static parseAngletoDegrees(e){let t=e.toLowerCase(),n=parseFloat(t);return t.includes(`rad`)?Io(n):t.includes(`turn`)?360*n:n}},bc=e=>{let t=[`instantiated_by_use`,`style`,`id`,`class`];switch(e){case`linearGradient`:return t.concat([`x1`,`y1`,`x2`,`y2`,`gradientUnits`,`gradientTransform`]);case`radialGradient`:return t.concat([`gradientUnits`,`gradientTransform`,`cx`,`cy`,`r`,`fx`,`fy`,`fr`]);case`stop`:return t.concat([`offset`,`stop-color`,`stop-opacity`])}return t},xc=(e,t=16)=>{let n=/\D{0,2}$/.exec(e),r=parseFloat(e),i=X.DPI;switch(n?.[0]){case`mm`:return r*i/25.4;case`cm`:return r*i/2.54;case`in`:return r*i;case`pt`:return r*i/72;case`pc`:return r*i/72*12;case`em`:return r*t;default:return r}},Sc=e=>{let[t,n]=e.trim().split(` `),[r,i]=(a=t)&&a!==`none`?[a.slice(1,4),a.slice(5,8)]:a===`none`?[a,a]:[`Mid`,`Mid`];var a;return{meetOrSlice:n||`meet`,alignX:r,alignY:i}},Cc=(e,t,n=!0)=>{let r,i;if(t)if(t.toLive)r=`url(#SVGID_${$(t.id)})`;else{let e=String(t);if(lc(e)){let t=new yc(e),n=t.getAlpha();r=t.toRgb(),n!==1&&(i=n.toString())}else r=new yc(`black`).toRgb()}else r=`none`;return n?`${e}: ${r}; ${i?`${e}-opacity: ${i}; `:``}`:`${e}="${r}" ${i?`${e}-opacity="${i}" `:``}`},wc=class{getSvgStyles(e){let t=this.fillRule==null?`nonzero`:dc(this.fillRule),n=this.strokeWidth==null?`0`:uc(this.strokeWidth),r=this.strokeDashArray==null?Ya:this.strokeDashArray.every(e=>Number.isFinite(Number(e)))?this.strokeDashArray.join(` `):``,i=this.strokeDashOffset==null?`0`:uc(this.strokeDashOffset),a=this.strokeLineCap==null?`butt`:dc(this.strokeLineCap),o=this.strokeLineJoin==null?`miter`:dc(this.strokeLineJoin),s=this.strokeMiterLimit==null?`4`:uc(this.strokeMiterLimit),c=this.opacity==null?`1`:uc(this.opacity),l=this.visible?``:` visibility: hidden;`,u=e?``:this.getSvgFilter(),d=Cc(uo,this.fill);return[Cc(fo,this.stroke),n?`stroke-width: ${n}; `:``,r?`stroke-dasharray: ${r}; `:``,a?`stroke-linecap: ${a}; `:``,i?`stroke-dashoffset: ${i}; `:``,o?`stroke-linejoin: ${o}; `:``,s?`stroke-miterlimit: ${s}; `:``,d,t?`fill-rule: ${t}; `:``,c?`opacity: ${c};`:``,u,l].map(e=>$(e)).join(``)}getSvgFilter(){return this.shadow?`filter: url(#SVGID_${$(this.shadow.id)});`:``}getSvgCommons(){return[this.id?`id="${$(String(this.id))}" `:``,this.clipPath?`clip-path="url(#${$(this.clipPath.clipPathId)})" `:``].join(``)}getSvgTransform(e,t=``){return`transform="${os(e?this.calcTransformMatrix():this.calcOwnMatrix())}${t}" `}_toSVG(e){return[``]}toSVG(e){return this._createBaseSVGMarkup(this._toSVG(e),{reviver:e})}toClipPathSVG(e){return` `+this._createBaseClipPathSVGMarkup(this._toSVG(e),{reviver:e})}_createBaseClipPathSVGMarkup(e,{reviver:t,additionalTransform:n=``}={}){let r=[this.getSvgTransform(!0,n),this.getSvgCommons()].join(``),i=e.indexOf(`COMMON_PARTS`);return e[i]=r,t?t(e.join(``)):e.join(``)}_createBaseSVGMarkup(e,{noStyle:t,reviver:n,withShadow:r,additionalTransform:i}={}){let a=t?``:`style="${this.getSvgStyles()}" `,o=r?`style="${this.getSvgFilter()}" `:``,s=this.clipPath,c=this.strokeUniform?`vector-effect="non-scaling-stroke" `:``,l=s&&s.absolutePositioned,u=this.stroke,d=this.fill,f=this.shadow,p=[],m=e.indexOf(`COMMON_PARTS`),h;return s&&(s.clipPathId=`CLIPPATH_${Oo()}`,h=`<clipPath id="${s.clipPathId}" >\n${s.toClipPathSVG(n)}</clipPath>\n`),l&&p.push(`<g `,o,this.getSvgCommons(),` >
|
|
11
|
+
`),p.push(`<g `,this.getSvgTransform(!1),l?``:o+this.getSvgCommons(),` >
|
|
12
|
+
`),e[m]=[a,c,t?``:this.addPaintOrder(),` `,i?`transform="${i}" `:``].join(``),ss(d)&&p.push(d.toSVG(this)),ss(u)&&p.push(u.toSVG(this)),f&&p.push(f.toSVG(this)),s&&p.push(h),p.push(e.join(``)),p.push(`</g>
|
|
13
|
+
`),l&&p.push(`</g>
|
|
14
|
+
`),n?n(p.join(``)):p.join(``)}addPaintOrder(){return this.paintFirst===`fill`?``:` paint-order="${$(this.paintFirst)}" `}};function Tc(e){return RegExp(`^(`+e.join(`|`)+`)\\b`,`i`)}var Ec=`textDecorationThickness`,Dc=`textDecorationColor`,Oc=[`fontSize`,`fontWeight`,`fontFamily`,`fontStyle`],kc=[`underline`,`overline`,`linethrough`],Ac=[...Oc,`lineHeight`,`text`,`charSpacing`,`textAlign`,`styles`,`path`,`pathStartOffset`,`pathSide`,`pathAlign`],jc=[...Ac,...kc,`textBackgroundColor`,`direction`,Ec,Dc],Mc=[...Oc,...kc,fo,`strokeWidth`,uo,`deltaY`,`textBackgroundColor`,Ec,Dc],Nc={_reNewline:Xa,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:mo,fontFamily:`Times New Roman`,underline:!1,overline:!1,linethrough:!1,textAlign:Ka,fontStyle:mo,lineHeight:1.16,textBackgroundColor:``,stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:Ka,pathAlign:`baseline`,charSpacing:0,deltaY:0,direction:`ltr`,CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[Ec]:66.667},Pc=`justify`,Fc=String.raw`[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?`,Ic=String.raw`(?:\s*,?\s+|\s*,\s*)`,Lc=`http://www.w3.org/2000/svg`,Rc=RegExp(`(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*(`+Fc+`(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|`+Fc+`))?\\s+(.*)`),zc={cx:Ka,x:Ka,r:`radius`,cy:`top`,y:`top`,display:`visible`,visibility:`visible`,transform:`transformMatrix`,"fill-opacity":`fillOpacity`,"fill-rule":`fillRule`,"font-family":`fontFamily`,"font-size":`fontSize`,"font-style":`fontStyle`,"font-weight":`fontWeight`,"letter-spacing":`charSpacing`,"paint-order":`paintFirst`,"stroke-dasharray":`strokeDashArray`,"stroke-dashoffset":`strokeDashOffset`,"stroke-linecap":`strokeLineCap`,"stroke-linejoin":`strokeLineJoin`,"stroke-miterlimit":`strokeMiterLimit`,"stroke-opacity":`strokeOpacity`,"stroke-width":`strokeWidth`,"text-decoration":`textDecoration`,"text-anchor":`textAnchor`,opacity:`opacity`,"clip-path":`clipPath`,"clip-rule":`clipRule`,"vector-effect":`strokeUniform`,"image-rendering":`imageSmoothing`,"text-decoration-thickness":Ec,"text-decoration-color":Dc},Bc=`font-size`,Vc=`clip-path`,Hc=Tc([`path`,`circle`,`polygon`,`polyline`,`ellipse`,`rect`,`line`,`image`,`text`]),Uc=Tc([`symbol`,`image`,`marker`,`pattern`,`view`,`svg`]),Wc=Tc([`symbol`,`g`,`a`,`svg`,`clipPath`,`defs`]),Gc=new RegExp(String.raw`^\s*(${Fc})${Ic}(${Fc})${Ic}(${Fc})${Ic}(${Fc})\s*$`),Kc=`(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?`,qc=RegExp(`(?:\\s|^)`+Kc+Kc+`(`+Fc+`?(?:px)?)?(?:\\s?|$)(?:$|\\s)`),Jc=class e{constructor(t={}){let n=typeof t==`string`?e.parseShadow(t):t;Object.assign(this,e.ownDefaults,n),this.id=Oo()}static parseShadow(e){let t=e.trim(),[,n=0,r=0,i=0]=(qc.exec(t)||[]).map(e=>parseFloat(e)||0);return{color:(t.replace(qc,``)||`rgb(0,0,0)`).trim(),offsetX:n,offsetY:r,blur:i}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join(`px `)}toSVG(e){let t=Gs(new Q(this.offsetX,this.offsetY),Fo(-e.angle)),n=X.NUM_FRACTION_DIGITS,r=new yc(this.color),i=40,a=40;return e.width&&e.height&&(i=100*as((Math.abs(t.x)+this.blur)/e.width,n)+20,a=100*as((Math.abs(t.y)+this.blur)/e.height,n)+20),e.flipX&&(t.x*=-1),e.flipY&&(t.y*=-1),`<filter id="SVGID_${$(this.id)}" y="-${a}%" height="${100+2*a}%" x="-${i}%" width="${100+2*i}%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="${as(this.blur?this.blur/2:0,n)}"></feGaussianBlur>\n\t<feOffset dx="${as(t.x,n)}" dy="${as(t.y,n)}" result="oBlur" ></feOffset>\n\t<feFlood flood-color="${r.toRgb()}" flood-opacity="${r.getAlpha()}"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n`}toObject(){let t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},n=e.ownDefaults;return this.includeDefaultValues?t:is(t,(e,t)=>e!==n[t])}static async fromObject(e){return new this(e)}};Y(Jc,`ownDefaults`,{color:`rgb(0,0,0)`,blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),Y(Jc,`type`,`shadow`),Z.setClass(Jc,`shadow`);var Yc=(e,t,n)=>Math.max(e,Math.min(t,n)),Xc=[`top`,Ka,oo,so,`flipX`,`flipY`,`originX`,`originY`,`angle`,`opacity`,`globalCompositeOperation`,`shadow`,`visible`,co,lo],Zc=[uo,fo,`strokeWidth`,`strokeDashArray`,`width`,`height`,`paintFirst`,`strokeUniform`,`strokeLineCap`,`strokeDashOffset`,`strokeLineJoin`,`strokeMiterLimit`,`backgroundColor`,`clipPath`],Qc={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:Ga,originY:Ga,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:uo,fill:`rgb(0,0,0)`,fillRule:`nonzero`,stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:`butt`,strokeLineJoin:`miter`,strokeMiterLimit:4,globalCompositeOperation:`source-over`,backgroundColor:``,shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},$c=Sa({defaultEasing:()=>nl,easeInBack:()=>wl,easeInBounce:()=>Ol,easeInCirc:()=>vl,easeInCubic:()=>rl,easeInElastic:()=>xl,easeInExpo:()=>hl,easeInOutBack:()=>El,easeInOutBounce:()=>kl,easeInOutCirc:()=>bl,easeInOutCubic:()=>al,easeInOutElastic:()=>Cl,easeInOutExpo:()=>_l,easeInOutQuad:()=>Ml,easeInOutQuart:()=>cl,easeInOutQuint:()=>dl,easeInOutSine:()=>ml,easeInQuad:()=>Al,easeInQuart:()=>ol,easeInQuint:()=>ll,easeInSine:()=>fl,easeOutBack:()=>Tl,easeOutBounce:()=>Dl,easeOutCirc:()=>yl,easeOutCubic:()=>il,easeOutElastic:()=>Sl,easeOutExpo:()=>gl,easeOutQuad:()=>jl,easeOutQuart:()=>sl,easeOutQuint:()=>ul,easeOutSine:()=>pl}),el=(e,t,n,r)=>(e<Math.abs(t)?(e=t,r=n/4):r=t===0&&e===0?n/Ha*Math.asin(1):n/Ha*Math.asin(t/e),{a:e,c:t,p:n,s:r}),tl=(e,t,n,r,i)=>e*2**(10*--r)*Math.sin((r*i-t)*Ha/n),nl=(e,t,n,r)=>-n*Math.cos(e/r*Ba)+n+t,rl=(e,t,n,r)=>n*(e/r)**3+t,il=(e,t,n,r)=>n*((e/r-1)**3+1)+t,al=(e,t,n,r)=>(e/=r/2)<1?n/2*e**3+t:n/2*((e-2)**3+2)+t,ol=(e,t,n,r)=>n*(e/=r)*e**3+t,sl=(e,t,n,r)=>-n*((e=e/r-1)*e**3-1)+t,cl=(e,t,n,r)=>(e/=r/2)<1?n/2*e**4+t:-n/2*((e-=2)*e**3-2)+t,ll=(e,t,n,r)=>n*(e/r)**5+t,ul=(e,t,n,r)=>n*((e/r-1)**5+1)+t,dl=(e,t,n,r)=>(e/=r/2)<1?n/2*e**5+t:n/2*((e-2)**5+2)+t,fl=(e,t,n,r)=>-n*Math.cos(e/r*Ba)+n+t,pl=(e,t,n,r)=>n*Math.sin(e/r*Ba)+t,ml=(e,t,n,r)=>-n/2*(Math.cos(Math.PI*e/r)-1)+t,hl=(e,t,n,r)=>e===0?t:n*2**(10*(e/r-1))+t,gl=(e,t,n,r)=>e===r?t+n:n*-(2**(-10*e/r)+1)+t,_l=(e,t,n,r)=>e===0?t:e===r?t+n:(e/=r/2)<1?n/2*2**(10*(e-1))+t:n/2*-(2**(-10*(e-1))+2)+t,vl=(e,t,n,r)=>-n*(Math.sqrt(1-(e/=r)*e)-1)+t,yl=(e,t,n,r)=>n*Math.sqrt(1-(e=e/r-1)*e)+t,bl=(e,t,n,r)=>(e/=r/2)<1?-n/2*(Math.sqrt(1-e**2)-1)+t:n/2*(Math.sqrt(1-(e-=2)*e)+1)+t,xl=(e,t,n,r)=>{let i=n,a=0;if(e===0)return t;if((e/=r)===1)return t+n;a||=.3*r;let{a:o,s,p:c}=el(i,n,a,1.70158);return-tl(o,s,c,e,r)+t},Sl=(e,t,n,r)=>{let i=n,a=0;if(e===0)return t;if((e/=r)===1)return t+n;a||=.3*r;let{a:o,s,p:c,c:l}=el(i,n,a,1.70158);return o*2**(-10*e)*Math.sin((e*r-s)*Ha/c)+l+t},Cl=(e,t,n,r)=>{let i=n,a=0;if(e===0)return t;if((e/=r/2)==2)return t+n;a||=.3*1.5*r;let{a:o,s,p:c,c:l}=el(i,n,a,1.70158);return e<1?-.5*tl(o,s,c,e,r)+t:o*2**(-10*--e)*Math.sin((e*r-s)*Ha/c)*.5+l+t},wl=(e,t,n,r,i=1.70158)=>n*(e/=r)*e*((i+1)*e-i)+t,Tl=(e,t,n,r,i=1.70158)=>n*((e=e/r-1)*e*((i+1)*e+i)+1)+t,El=(e,t,n,r,i=1.70158)=>(e/=r/2)<1?n/2*(e*e*((1+(i*=1.525))*e-i))+t:n/2*((e-=2)*e*((1+(i*=1.525))*e+i)+2)+t,Dl=(e,t,n,r)=>(e/=r)<1/2.75?n*(7.5625*e*e)+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t,Ol=(e,t,n,r)=>n-Dl(r-e,0,n,r)+t,kl=(e,t,n,r)=>e<r/2?.5*Ol(2*e,0,n,r)+t:.5*Dl(2*e-r,0,n,r)+.5*n+t,Al=(e,t,n,r)=>n*(e/=r)*e+t,jl=(e,t,n,r)=>-n*(e/=r)*(e-2)+t,Ml=(e,t,n,r)=>(e/=r/2)<1?n/2*e**2+t:-n/2*(--e*(e-2)-1)+t,Nl=()=>!1,Pl=class{constructor({startValue:e,byValue:t,duration:n=500,delay:r=0,easing:i=nl,onStart:a=za,onChange:o=za,onComplete:s=za,abort:c=Nl,target:l}){Y(this,`_state`,`pending`),Y(this,`durationProgress`,0),Y(this,`valueProgress`,0),this.tick=this.tick.bind(this),this.duration=n,this.delay=r,this.easing=i,this._onStart=a,this._onChange=o,this._onComplete=s,this._abort=c,this.target=l,this.startValue=e,this.byValue=t,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state===`aborted`||this._state===`completed`}start(){let e=e=>{this._state===`pending`&&(this.startTime=e||+new Date,this._state=`running`,this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?this.timeout=Fa().setTimeout(()=>To(e),this.delay):To(e)}tick(e){let t=(e||+new Date)-this.startTime,n=Math.min(t,this.duration);this.durationProgress=n/this.duration;let{value:r,valueProgress:i}=this.calculate(n);this.value=Object.freeze(r),this.valueProgress=i,this._state!==`aborted`&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state=`aborted`,this.unregister()):t>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state=`completed`,this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister(),this.timeout=null):(this._onChange(this.value,this.valueProgress,this.durationProgress),To(this.tick)))}register(){go.push(this)}unregister(){go.remove(this)}abort(){this._state=`aborted`,this.unregister(),this.timeout&&Fa().clearTimeout(this.timeout)}},Fl=class extends Pl{constructor({startValue:e=0,endValue:t=100,...n}){super({...n,startValue:e,byValue:t-e})}calculate(e){let t=this.easing(e,this.startValue,this.byValue,this.duration);return{value:t,valueProgress:Math.abs((t-this.startValue)/this.byValue)}}},Il=class extends Pl{constructor({startValue:e=[0],endValue:t=[100],...n}){super({...n,startValue:e,byValue:t.map((t,n)=>t-e[n])})}calculate(e){let t=this.startValue.map((t,n)=>this.easing(e,t,this.byValue[n],this.duration,n));return{value:t,valueProgress:Math.abs((t[0]-this.startValue[0])/this.byValue[0])}}},Ll=(e,t,n,r)=>t+n*(1-Math.cos(e/r*Ba)),Rl=e=>e&&((t,n,r)=>e(new yc(t).toRgba(),n,r)),zl=class extends Pl{constructor({startValue:e,endValue:t,easing:n=Ll,onChange:r,onComplete:i,abort:a,...o}){let s=new yc(e).getSource(),c=new yc(t).getSource();super({...o,startValue:s,byValue:c.map((e,t)=>e-s[t]),easing:n,onChange:Rl(r),onComplete:Rl(i),abort:Rl(a)})}calculate(e){let[t,n,r,i]=this.startValue.map((t,n)=>this.easing(e,t,this.byValue[n],this.duration,n)),a=[...[t,n,r].map(Math.round),Yc(0,i,1)];return{value:a,valueProgress:a.map((e,t)=>this.byValue[t]===0?0:Math.abs((e-this.startValue[t])/this.byValue[t])).find(e=>e!==0)||0}}};function Bl(e){let t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(e)?new Il(e):new Fl(e);return t.start(),t}function Vl(e){let t=new zl(e);return t.start(),t}var Hl=class e{constructor(e){this.status=e,this.points=[]}includes(e){return this.points.some(t=>t.eq(e))}append(...e){return this.points=this.points.concat(e.filter(e=>!this.includes(e))),this}static isPointContained(e,t,n,r=!1){if(t.eq(n))return e.eq(t);if(t.x===n.x)return e.x===t.x&&(r||e.y>=Math.min(t.y,n.y)&&e.y<=Math.max(t.y,n.y));if(t.y===n.y)return e.y===t.y&&(r||e.x>=Math.min(t.x,n.x)&&e.x<=Math.max(t.x,n.x));{let i=Ks(t,n),a=Ks(t,e).divide(i);return r?Math.abs(a.x)===Math.abs(a.y):a.x===a.y&&a.x>=0&&a.x<=1}}static isPointInPolygon(e,t){let n=new Q(e).setX(Math.min(e.x-1,...t.map(e=>e.x))),r=0;for(let i=0;i<t.length;i++){let a=this.intersectSegmentSegment(t[i],t[(i+1)%t.length],e,n);if(a.includes(e))return!0;r+=Number(a.status===`Intersection`)}return r%2==1}static intersectLineLine(t,n,r,i,a=!0,o=!0){let s=n.x-t.x,c=n.y-t.y,l=i.x-r.x,u=i.y-r.y,d=t.x-r.x,f=t.y-r.y,p=l*f-u*d,m=s*f-c*d,h=u*s-l*c;if(h!==0){let n=p/h,r=m/h;return(a||0<=n&&n<=1)&&(o||0<=r&&r<=1)?new e(`Intersection`).append(new Q(t.x+n*s,t.y+n*c)):new e}return new e(p===0||m===0?a||o||e.isPointContained(t,r,i)||e.isPointContained(n,r,i)||e.isPointContained(r,t,n)||e.isPointContained(i,t,n)?`Coincident`:void 0:`Parallel`)}static intersectSegmentLine(t,n,r,i){return e.intersectLineLine(t,n,r,i,!1,!0)}static intersectSegmentSegment(t,n,r,i){return e.intersectLineLine(t,n,r,i,!1,!1)}static intersectLinePolygon(t,n,r,i=!0){let a=new e,o=r.length;for(let s,c,l,u=0;u<o;u++){if(s=r[u],c=r[(u+1)%o],l=e.intersectLineLine(t,n,s,c,i,!1),l.status===`Coincident`)return l;a.append(...l.points)}return a.points.length>0&&(a.status=`Intersection`),a}static intersectSegmentPolygon(t,n,r){return e.intersectLinePolygon(t,n,r,!1)}static intersectPolygonPolygon(t,n){let r=new e,i=t.length,a=[];for(let o=0;o<i;o++){let s=t[o],c=t[(o+1)%i],l=e.intersectSegmentPolygon(s,c,n);l.status===`Coincident`?(a.push(l),r.append(s,c)):r.append(...l.points)}return a.length>0&&a.length===t.length?new e(`Coincident`):(r.points.length>0&&(r.status=`Intersection`),r)}static intersectPolygonRectangle(t,n,r){let i=n.min(r),a=n.max(r),o=new Q(a.x,i.y),s=new Q(i.x,a.y);return e.intersectPolygonPolygon(t,[i,o,a,s])}},Ul=class extends wo{getX(){return this.getXY().x}setX(e){this.setXY(this.getXY().setX(e))}getY(){return this.getXY().y}setY(e){this.setXY(this.getXY().setY(e))}getRelativeX(){return this.left}setRelativeX(e){this.left=e}getRelativeY(){return this.top}setRelativeY(e){this.top=e}getXY(){let e=this.getRelativeXY();return this.group?Ro(e,this.group.calcTransformMatrix()):e}setXY(e,t,n){this.group&&(e=Ro(e,zo(this.group.calcTransformMatrix()))),this.setRelativeXY(e,t,n)}getRelativeXY(){return new Q(this.left,this.top)}setRelativeXY(e,t=this.originX,n=this.originY){this.setPositionByOrigin(e,t,n)}isStrokeAccountedForInDimensions(){return!1}getCoords(){let{tl:e,tr:t,br:n,bl:r}=this.aCoords||=this.calcACoords(),i=[e,t,n,r];if(this.group){let e=this.group.calcTransformMatrix();return i.map(t=>Ro(t,e))}return i}intersectsWithRect(e,t){return Hl.intersectPolygonRectangle(this.getCoords(),e,t).status===`Intersection`}intersectsWithObject(e){let t=Hl.intersectPolygonPolygon(this.getCoords(),e.getCoords());return t.status===`Intersection`||t.status===`Coincident`||e.isContainedWithinObject(this)||this.isContainedWithinObject(e)}isContainedWithinObject(e){return this.getCoords().every(t=>e.containsPoint(t))}isContainedWithinRect(e,t){let{left:n,top:r,width:i,height:a}=this.getBoundingRect();return n>=e.x&&n+i<=t.x&&r>=e.y&&r+a<=t.y}isOverlapping(e){return this.intersectsWithObject(e)||this.isContainedWithinObject(e)||e.isContainedWithinObject(this)}containsPoint(e){return Hl.isPointInPolygon(e,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;let{tl:e,br:t}=this.canvas.vptCoords;return!!this.getCoords().some(n=>n.x<=t.x&&n.x>=e.x&&n.y<=t.y&&n.y>=e.y)||!!this.intersectsWithRect(e,t)||this.containsPoint(e.midPointFrom(t))}isPartiallyOnScreen(){if(!this.canvas)return!1;let{tl:e,br:t}=this.canvas.vptCoords;return!!this.intersectsWithRect(e,t)||this.getCoords().every(n=>(n.x>=t.x||n.x<=e.x)&&(n.y>=t.y||n.y<=e.y))&&this.containsPoint(e.midPointFrom(t))}getBoundingRect(){return As(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(e){this._set(oo,e),this._set(so,e),this.setCoords()}scaleToWidth(e){let t=this.getBoundingRect().width/this.getScaledWidth();return this.scale(e/this.width/t)}scaleToHeight(e){let t=this.getBoundingRect().height/this.getScaledHeight();return this.scale(e/this.height/t)}getCanvasRetinaScaling(){return this.canvas?.getRetinaScaling()||1}getTotalAngle(){return this.group?Io(Ho(this.calcTransformMatrix())):this.angle}getViewportTransform(){return this.canvas?.viewportTransform||Wa.concat()}calcACoords(){let e=qo({angle:this.angle}),{x:t,y:n}=this.getRelativeCenterPoint(),r=Bo(Ko(t,n),e),i=this._getTransformedDimensions(),a=i.x/2,o=i.y/2;return{tl:Ro({x:-a,y:-o},r),tr:Ro({x:a,y:-o},r),bl:Ro({x:-a,y:o},r),br:Ro({x:a,y:o},r)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(e=!1){let t=[];return!e&&this.group&&(t=this.group.transformMatrixKey(e)),t.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Hs(this.originX),Hs(this.originY)),t}calcTransformMatrix(e=!1){let t=this.calcOwnMatrix();if(e||!this.group)return t;let n=this.transformMatrixKey(e),r=this.matrixCache;return r&&r.key.every((e,t)=>e===n[t])?r.value:(this.group&&(t=Bo(this.group.calcTransformMatrix(!1),t)),this.matrixCache={key:n,value:t},t)}calcOwnMatrix(){let e=this.transformMatrixKey(!0),t=this.ownMatrixCache;if(t&&t.key.every((t,n)=>t===e[n]))return t.value;let n=this.getRelativeCenterPoint(),r=$o({angle:this.angle,translateX:n.x,translateY:n.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY});return this.ownMatrixCache={key:e,value:r},r}_getNonTransformedDimensions(){return new Q(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(e){let t=this.canvas?.viewportTransform,n=this._getTransformedDimensions(e);return t?n.multiply(new Q(Uo(t),Wo(t))).scalarAdd(2*this.padding):n.scalarAdd(2*this.padding)}_getTransformedDimensions(e={}){let t={scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth,...e},n=t.strokeWidth,r=n,i=0;this.strokeUniform&&(r=0,i=n);let a=t.width+r,o=t.height+r,s;return s=t.skewX===0&&t.skewY===0?new Q(a*t.scaleX,o*t.scaleY):Is(a,o,Qo(t)),s.scalarAdd(i)}translateToGivenOrigin(e,t,n,r,i){let a=e.x,o=e.y,s=Hs(r)-Hs(t),c=Hs(i)-Hs(n);if(s||c){let e=this._getTransformedDimensions();a+=s*e.x,o+=c*e.y}return new Q(a,o)}translateToCenterPoint(e,t,n){if(t===`center`&&n===`center`)return e;let r=this.translateToGivenOrigin(e,t,n,Ga,Ga);return this.angle?r.rotate(Fo(this.angle),e):r}translateToOriginPoint(e,t,n){let r=this.translateToGivenOrigin(e,Ga,Ga,t,n);return this.angle?r.rotate(Fo(this.angle),e):r}getCenterPoint(){let e=this.getRelativeCenterPoint();return this.group?Ro(e,this.group.calcTransformMatrix()):e}getRelativeCenterPoint(){return this.translateToCenterPoint(new Q(this.left,this.top),this.originX,this.originY)}getPointByOrigin(e,t){return this.getPositionByOrigin(e,t)}getPositionByOrigin(e,t){return this.translateToOriginPoint(this.getRelativeCenterPoint(),e,t)}setPositionByOrigin(e,t,n){let r=this.translateToCenterPoint(e,t,n),i=this.translateToOriginPoint(r,this.originX,this.originY);this.set({left:i.x,top:i.y})}_getLeftTopCoords(){return this.getPositionByOrigin(Ka,`top`)}positionByLeftTop(e){return this.setPositionByOrigin(e,Ka,`top`)}},Wl=class e extends Ul{static getDefaults(){return e.ownDefaults}get type(){let e=this.constructor.type;return e===`FabricObject`?`object`:e.toLowerCase()}set type(e){Ea(`warn`,`Setting type has no effect`,e)}constructor(t){super(),Y(this,`_cacheContext`,null),Object.assign(this,e.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=ko(),this._cacheContext=this._cacheCanvas.getContext(`2d`),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(e){let t=e.width,n=e.height,r=X.maxCacheSideLimit,i=X.minCacheSideLimit;if(t<=r&&n<=r&&t*n<=X.perfLimitSizeTotal)return t<i&&(e.width=i),n<i&&(e.height=i),e;let a=t/n,[o,s]=La.limitDimsByArea(a),c=Yc(i,o,r),l=Yc(i,s,r);return t>c&&(e.zoomX/=t/c,e.width=c,e.capped=!0),n>l&&(e.zoomY/=n/l,e.height=l,e.capped=!0),e}_getCacheCanvasDimensions(){let e=this.getTotalObjectScaling(),t=this._getTransformedDimensions({skewX:0,skewY:0}),n=t.x*e.x/this.scaleX,r=t.y*e.y/this.scaleY;return{width:Math.ceil(n+2),height:Math.ceil(r+2),zoomX:e.x,zoomY:e.y,x:n,y:r}}_updateCacheCanvas(){let e=this._cacheCanvas,t=this._cacheContext,{width:n,height:r,zoomX:i,zoomY:a,x:o,y:s}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=n!==e.width||r!==e.height,l=this.zoomX!==i||this.zoomY!==a;if(!e||!t)return!1;if(c||l){n!==e.width||r!==e.height?(e.width=n,e.height=r):(t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,e.width,e.height));let c=o/2,l=s/2;return this.cacheTranslationX=Math.round(e.width/2-c)+c,this.cacheTranslationY=Math.round(e.height/2-l)+l,t.translate(this.cacheTranslationX,this.cacheTranslationY),t.scale(i,a),this.zoomX=i,this.zoomY=a,!0}return!1}setOptions(e={}){this._setOptions(e)}transform(e){let t=this.group&&!this.group._transformDone||this.group&&this.canvas&&e===this.canvas.contextTop,n=this.calcTransformMatrix(!t);e.transform(n[0],n[1],n[2],n[3],n[4],n[5])}getObjectScaling(){if(!this.group)return new Q(Math.abs(this.scaleX),Math.abs(this.scaleY));let e=Go(this.calcTransformMatrix());return new Q(Math.abs(e.scaleX),Math.abs(e.scaleY))}getTotalObjectScaling(){let e=this.getObjectScaling();if(this.canvas){let t=this.canvas.getZoom(),n=this.getCanvasRetinaScaling();return e.scalarMultiply(t*n)}return e}getObjectOpacity(){let e=this.opacity;return this.group&&(e*=this.group.getObjectOpacity()),e}_constrainScale(e){return Math.abs(e)<this.minScaleLimit?e<0?-this.minScaleLimit:this.minScaleLimit:e===0?1e-4:e}_set(e,t){e!==`scaleX`&&e!==`scaleY`||(t=this._constrainScale(t)),e===`scaleX`&&t<0?(this.flipX=!this.flipX,t*=-1):e===`scaleY`&&t<0?(this.flipY=!this.flipY,t*=-1):e!==`shadow`||!t||t instanceof Jc||(t=new Jc(t));let n=this[e]!==t;return this[e]=t,n&&this.constructor.cacheProperties.includes(e)&&(this.dirty=!0),this.parent&&(this.dirty||n&&this.constructor.stateProperties.includes(e))&&this.parent._set(`dirty`,!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(e){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(e.save(),this._setupCompositeOperation(e),this.drawSelectionBackground(e),this.transform(e),this._setOpacity(e),this._setShadow(e),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(e)):(this._removeCacheCanvas(),this.drawObject(e,!1,{}),this.dirty=!1),e.restore())}drawSelectionBackground(e){}renderCache(e){if(e||={},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){let{zoomX:t,zoomY:n,cacheTranslationX:r,cacheTranslationY:i}=this,{width:a,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,e.forClipping,{zoomX:t,zoomY:n,cacheTranslationX:r,cacheTranslationY:i,width:a,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return!!this.stroke&&this.stroke!==`transparent`&&this.strokeWidth!==0}hasFill(){return!!this.fill&&this.fill!==`transparent`}needsItsOwnCache(){return!!(this.paintFirst===`stroke`&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(e,t,n){e.save(),t.inverted?e.globalCompositeOperation=`destination-out`:e.globalCompositeOperation=`destination-in`,e.setTransform(1,0,0,1,0,0),e.drawImage(n,0,0),e.restore()}drawObject(e,t,n){let r=this.fill,i=this.stroke;t?(this.fill=`black`,this.stroke=``,this._setClippingProperties(e)):this._renderBackground(e),this.fire(`before:render`,{ctx:e}),this._render(e),this._drawClipPath(e,this.clipPath,n),this.fill=r,this.stroke=i}createClipPathLayer(e,t){let n=Mo(t),r=n.getContext(`2d`);if(r.translate(t.cacheTranslationX,t.cacheTranslationY),r.scale(t.zoomX,t.zoomY),e._cacheCanvas=n,t.parentClipPaths.forEach(e=>{e.transform(r)}),t.parentClipPaths.push(e),e.absolutePositioned){let e=zo(this.calcTransformMatrix());r.transform(e[0],e[1],e[2],e[3],e[4],e[5])}return e.transform(r),e.drawObject(r,!0,t),n}_drawClipPath(e,t,n){if(!t)return;t._transformDone=!0;let r=this.createClipPathLayer(t,n);this.drawClipPathOnCache(e,t,r)}drawCacheOnCanvas(e){e.scale(1/this.zoomX,1/this.zoomY),e.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(e=!1){if(this.isNotVisible())return!1;let t=this._cacheCanvas,n=this._cacheContext;return!(!t||!n||e||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(t&&n&&!e&&(n.save(),n.setTransform(1,0,0,1,0,0),n.clearRect(0,0,t.width,t.height),n.restore()),!0)}_renderBackground(e){if(!this.backgroundColor)return;let t=this._getNonTransformedDimensions();e.fillStyle=this.backgroundColor,e.fillRect(-t.x/2,-t.y/2,t.x,t.y),this._removeShadow(e)}_setOpacity(e){this.group&&!this.group._transformDone?e.globalAlpha=this.getObjectOpacity():e.globalAlpha*=this.opacity}_setStrokeStyles(e,t){let n=t.stroke;n&&(e.lineWidth=t.strokeWidth,e.lineCap=t.strokeLineCap,e.lineDashOffset=t.strokeDashOffset,e.lineJoin=t.strokeLineJoin,e.miterLimit=t.strokeMiterLimit,ss(n)?n.gradientUnits===`percentage`||n.gradientTransform||n.patternTransform?this._applyPatternForTransformedGradient(e,n):(e.strokeStyle=n.toLive(e),this._applyPatternGradientTransform(e,n)):e.strokeStyle=t.stroke)}_setFillStyles(e,{fill:t}){t&&(ss(t)?(e.fillStyle=t.toLive(e),this._applyPatternGradientTransform(e,t)):e.fillStyle=t)}_setClippingProperties(e){e.globalAlpha=1,e.strokeStyle=`transparent`,e.fillStyle=`#000000`}_setLineDash(e,t){t&&t.length!==0&&e.setLineDash(t)}_setShadow(e){if(!this.shadow)return;let t=this.shadow,n=this.canvas,r=this.getCanvasRetinaScaling(),[i,,,a]=n?.viewportTransform||Wa,o=i*r,s=a*r,c=t.nonScaling?new Q(1,1):this.getObjectScaling();e.shadowColor=t.color,e.shadowBlur=t.blur*X.browserShadowBlurConstant*(o+s)*(c.x+c.y)/4,e.shadowOffsetX=t.offsetX*o*c.x,e.shadowOffsetY=t.offsetY*s*c.y}_removeShadow(e){this.shadow&&(e.shadowColor=``,e.shadowBlur=e.shadowOffsetX=e.shadowOffsetY=0)}_applyPatternGradientTransform(e,t){if(!ss(t))return{offsetX:0,offsetY:0};let n=t.gradientTransform||t.patternTransform,r=-this.width/2+t.offsetX||0,i=-this.height/2+t.offsetY||0;return t.gradientUnits===`percentage`?e.transform(this.width,0,0,this.height,r,i):e.transform(1,0,0,1,r,i),n&&e.transform(n[0],n[1],n[2],n[3],n[4],n[5]),{offsetX:r,offsetY:i}}_renderPaintInOrder(e){this.paintFirst===`stroke`?(this._renderStroke(e),this._renderFill(e)):(this._renderFill(e),this._renderStroke(e))}_render(e){}_renderFill(e){this.fill&&(e.save(),this._setFillStyles(e,this),this.fillRule===`evenodd`?e.fill(`evenodd`):e.fill(),e.restore())}_renderStroke(e){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(e),e.save(),this.strokeUniform){let t=this.getObjectScaling();e.scale(1/t.x,1/t.y)}this._setLineDash(e,this.strokeDashArray),this._setStrokeStyles(e,this),e.stroke(),e.restore()}}_applyPatternForTransformedGradient(e,t){let n=this._limitCacheSize(this._getCacheCanvasDimensions()),r=this.getCanvasRetinaScaling(),i=n.x/this.scaleX/r,a=n.y/this.scaleY/r,o=Mo({width:Math.ceil(i),height:Math.ceil(a)}),s=o.getContext(`2d`);s&&(s.beginPath(),s.moveTo(0,0),s.lineTo(i,0),s.lineTo(i,a),s.lineTo(0,a),s.closePath(),s.translate(i/2,a/2),s.scale(n.zoomX/this.scaleX/r,n.zoomY/this.scaleY/r),this._applyPatternGradientTransform(s,t),s.fillStyle=t.toLive(e),s.fill(),e.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),e.scale(r*this.scaleX/n.zoomX,r*this.scaleY/n.zoomY),e.strokeStyle=s.createPattern(o,`no-repeat`)??``)}_findCenterFromElement(){return new Q(this.left+this.width/2,this.top+this.height/2)}clone(e){let t=this.toObject(e);return this.constructor.fromObject(t)}cloneAsImage(e){let t=this.toCanvasElement(e);return new(Z.getClass(`image`))(t)}toCanvasElement(e={}){let t=Fs(this),n=this.group,r=this.shadow,i=Math.abs,a=e.enableRetinaScaling?Ia():1,o=(e.multiplier||1)*a,s=e.canvasProvider||(e=>new Ts(e,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,e.withoutTransform&&Ps(this),e.withoutShadow&&(this.shadow=null),e.viewportTransform&&Bs(this,this.getViewportTransform()),this.setCoords();let c=ko(),l=this.getBoundingRect(),u=this.shadow,d=new Q;if(u){let e=u.blur,t=u.nonScaling?new Q(1,1):this.getObjectScaling();d.x=2*Math.round(i(u.offsetX)+e)*i(t.x),d.y=2*Math.round(i(u.offsetY)+e)*i(t.y)}let f=l.width+d.x,p=l.height+d.y;c.width=Math.ceil(f),c.height=Math.ceil(p);let m=s(c);e.format===`jpeg`&&(m.backgroundColor=`#fff`),this.setPositionByOrigin(new Q(m.width/2,m.height/2),Ga,Ga);let h=this.canvas;m._objects=[this],this.set(`canvas`,m),this.setCoords();let g=m.toCanvasElement(o||1,e);return this.set(`canvas`,h),this.shadow=r,n&&(this.group=n),this.set(t),this.setCoords(),m._objects=[],m.destroy(),g}toDataURL(e={}){return No(this.toCanvasElement(e),e.format||`png`,e.quality||1)}toBlob(e={}){return Po(this.toCanvasElement(e),e.format||`png`,e.quality||1)}isType(...e){return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(e){let{centeredRotation:t,originX:n,originY:r}=this;if(t){let{x:e,y:t}=this.getRelativeCenterPoint();this.originX=Ga,this.originY=Ga,this.left=e,this.top=t}if(this.set(`angle`,e),t){let{x:e,y:t}=this.getPositionByOrigin(n,r);this.left=e,this.top=t,this.originX=n,this.originY=r}}setOnGroup(){}_setupCompositeOperation(e){this.globalCompositeOperation&&(e.globalCompositeOperation=this.globalCompositeOperation)}dispose(){go.cancelByTarget(this),this.off(),this._set(`canvas`,void 0),this._cacheCanvas&&Na().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(e,t){return Object.entries(e).reduce((e,[n,r])=>(e[n]=this._animate(n,r,t),e),{})}_animate(e,t,n={}){let r=e.split(`.`),i=this.constructor.colorProperties.includes(r[r.length-1]),{abort:a,startValue:o,onChange:s,onComplete:c}=n,l={...n,target:this,startValue:o??r.reduce((e,t)=>e[t],this),endValue:t,abort:a?.bind(this),onChange:(e,t,n)=>{r.reduce((t,n,i)=>(i===r.length-1&&(t[n]=e),t[n]),this),s&&s(e,t,n)},onComplete:(e,t,n)=>{this.setCoords(),c&&c(e,t,n)}};return i?Vl(l):Bl(l)}isDescendantOf(e){let{parent:t,group:n}=this;return t===e||n===e||!!t&&t.isDescendantOf(e)||!!n&&n!==t&&n.isDescendantOf(e)}getAncestors(){let e=[],t=this;do t=t.parent,t&&e.push(t);while(t);return e}findCommonAncestors(e){if(this===e)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};let t=this.getAncestors(),n=e.getAncestors();if(t.length===0&&n.length>0&&this===n[n.length-1])return{fork:[],otherFork:[e,...n.slice(0,n.length-1)],common:[this]};for(let r,i=0;i<t.length;i++){if(r=t[i],r===e)return{fork:[this,...t.slice(0,i)],otherFork:[],common:t.slice(i)};for(let a=0;a<n.length;a++){if(this===n[a])return{fork:[],otherFork:[e,...n.slice(0,a)],common:[this,...t]};if(r===n[a])return{fork:[this,...t.slice(0,i)],otherFork:[e,...n.slice(0,a)],common:t.slice(i)}}}return{fork:[this,...t],otherFork:[e,...n],common:[]}}hasCommonAncestors(e){let t=this.findCommonAncestors(e);return t&&!!t.common.length}isInFrontOf(e){if(this===e)return;let t=this.findCommonAncestors(e);if(t.fork.includes(e))return!0;if(t.otherFork.includes(this))return!1;let n=t.common[0]||this.canvas;if(!n)return;let r=t.fork.pop(),i=t.otherFork.pop(),a=n._objects.indexOf(r),o=n._objects.indexOf(i);return a>-1&&a>o}toObject(t=[]){let n=t.concat(e.customProperties,this.constructor.customProperties||[]),r,i=X.NUM_FRACTION_DIGITS,{clipPath:a,fill:o,stroke:s,shadow:c,strokeDashArray:l,left:u,top:d,originX:f,originY:p,width:m,height:h,strokeWidth:g,strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:b,strokeMiterLimit:x,scaleX:S,scaleY:C,angle:w,flipX:T,flipY:E,opacity:D,visible:O,backgroundColor:k,fillRule:A,paintFirst:j,globalCompositeOperation:M,skewX:N,skewY:ee}=this;a&&!a.excludeFromExport&&(r=a.toObject(n.concat(`inverted`,`absolutePositioned`)));let P=e=>as(e,i),F={...rs(this,n),type:this.constructor.type,version:Ra,originX:f,originY:p,left:P(u),top:P(d),width:P(m),height:P(h),fill:cs(o)?o.toObject():o,stroke:cs(s)?s.toObject():s,strokeWidth:P(g),strokeDashArray:l&&l.concat(),strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:b,strokeMiterLimit:P(x),scaleX:P(S),scaleY:P(C),angle:P(w),flipX:T,flipY:E,opacity:P(D),shadow:c&&c.toObject(),visible:O,backgroundColor:k,fillRule:A,paintFirst:j,globalCompositeOperation:M,skewX:P(N),skewY:P(ee),...r?{clipPath:r}:null};return this.includeDefaultValues?F:this._removeDefaultValues(F)}toDatalessObject(e){return this.toObject(e)}_removeDefaultValues(e){let t=this.constructor.getDefaults(),n=Object.keys(t).length>0?t:Object.getPrototypeOf(this);return is(e,(e,t)=>{if(t===`left`||t===`top`||t===`type`)return!0;let r=n[t];return e!==r&&!(Array.isArray(e)&&Array.isArray(r)&&e.length===0&&r.length===0)})}toString(){return`#<${this.constructor.type}>`}static _fromObject({type:e,...t},{extraParam:n,...r}={}){return ns(t,r).then(e=>n?(delete e[n],new this(t[n],e)):new this(e))}static fromObject(e,t){return this._fromObject(e,t)}};Y(Wl,`stateProperties`,Xc),Y(Wl,`cacheProperties`,Zc),Y(Wl,`ownDefaults`,Qc),Y(Wl,`type`,`FabricObject`),Y(Wl,`colorProperties`,[uo,fo,`backgroundColor`]),Y(Wl,`customProperties`,[]),Z.setClass(Wl),Z.setClass(Wl,`object`);var Gl=(e,t)=>{var n;let{transform:{target:r}}=t;(n=r.canvas)==null||n.fire(`object:${e}`,{...t,target:r}),r.fire(e,t)},Kl=(e,t,n)=>(r,i,a,o)=>{let s=t(r,i,a,o);return s&&Gl(e,{...ac(r,i,a,o),...n}),s};function ql(e){return(t,n,r,i)=>{let{target:a,originX:o,originY:s}=n,c=a.getPositionByOrigin(o,s),l=e(t,n,r,i);return a.setPositionByOrigin(c,n.originX,n.originY),l}}var Jl=(e,t,n,r)=>(i,a,o,s)=>{let c=sc(a,a.originX,a.originY,o,s)[n],l=Hs(a[t]);if(l===0||l>0&&c<0||l<0&&c>0){let{target:t}=a,n=t.strokeWidth/(t.strokeUniform?t[r]:1),i=nc(a)?2:1,o=t[e],s=Math.abs(c*i/t[r])-n;return t.set(e,Math.max(s,1)),o!==t[e]}return!1},Yl=Jl(`width`,`originX`,`x`,`scaleX`),Xl=Jl(`height`,`originY`,`y`,`scaleY`),Zl=Kl(no,ql(Yl)),Ql=Kl(no,ql(Xl));function $l(e,t,n,r,i){e.save();let{stroke:a,xSize:o,ySize:s,opName:c}=this.commonRenderProps(e,t,n,i,r),l=o;o>s?e.scale(1,s/o):s>o&&(l=s,e.scale(o/s,1)),e.beginPath(),e.arc(0,0,l/2,0,Ha,!1),e[c](),a&&e.stroke(),e.restore()}function eu(e,t,n,r,i){e.save();let{stroke:a,xSize:o,ySize:s,opName:c}=this.commonRenderProps(e,t,n,i,r),l=o/2,u=s/2;e[`${c}Rect`](-l,-u,o,s),a&&e.strokeRect(-l,-u,o,s),e.restore()}var tu=class{constructor(e){Y(this,`visible`,!0),Y(this,`actionName`,ao),Y(this,`angle`,0),Y(this,`x`,0),Y(this,`y`,0),Y(this,`offsetX`,0),Y(this,`offsetY`,0),Y(this,`sizeX`,0),Y(this,`sizeY`,0),Y(this,`touchSizeX`,0),Y(this,`touchSizeY`,0),Y(this,`cursorStyle`,`crosshair`),Y(this,`withConnection`,!1),Object.assign(this,e)}getTransformAnchorPoint(){return this.transformAnchorPoint??new Q(.5-this.x,.5-this.y)}shouldActivate(e,t,n,{tl:r,tr:i,br:a,bl:o}){return t.canvas?.getActiveObject()===t&&t.isControlVisible(e)&&Hl.isPointInPolygon(n,[r,i,a,o])}getActionHandler(e,t,n){return this.actionHandler}getMouseDownHandler(e,t,n){return this.mouseDownHandler}getMouseUpHandler(e,t,n){return this.mouseUpHandler}cursorStyleHandler(e,t,n,r){return t.cursorStyle}getActionName(e,t,n){return t.actionName}getVisibility(e,t){return e._controlsVisibility?.[t]??this.visible}setVisibility(e,t,n){this.visible=e}positionHandler(e,t,n,r){return new Q(this.x*e.x+this.offsetX,this.y*e.y+this.offsetY).transform(t)}calcCornerCoords(e,t,n,r,i,a){let o=Vo([Ko(n,r),qo({angle:e}),Jo((i?this.touchSizeX:this.sizeX)||t,(i?this.touchSizeY:this.sizeY)||t)]);return{tl:new Q(-.5,-.5).transform(o),tr:new Q(.5,-.5).transform(o),br:new Q(.5,.5).transform(o),bl:new Q(-.5,.5).transform(o)}}commonRenderProps(e,t,n,r,i={}){let{cornerSize:a,cornerColor:o,transparentCorners:s,cornerStrokeColor:c}=i,l=a||r.cornerSize,u=this.sizeX||l,d=this.sizeY||l,f=s===void 0?r.transparentCorners:s,p=f?fo:uo,m=c||r.cornerStrokeColor,h=!f&&!!m;return e.fillStyle=o||r.cornerColor||``,e.strokeStyle=m||``,e.translate(t,n),e.rotate(Fo(r.getTotalAngle())),{stroke:h,xSize:u,ySize:d,transparentCorners:f,opName:p}}render(e,t,n,r,i){((r||={}).cornerStyle||i.cornerStyle)===`circle`?$l.call(this,e,t,n,r,i):eu.call(this,e,t,n,r,i)}},nu=(e,t,n)=>n.lockRotation?tc:t.cursorStyle,ru=Kl($a,ql((e,{target:t,ex:n,ey:r,theta:i,originX:a,originY:o},s,c)=>{let l=t.getPositionByOrigin(a,o);if(ic(t,`lockRotation`))return!1;let u=Math.atan2(r-l.y,n-l.x),d=Io(Math.atan2(c-l.y,s-l.x)-u+i);if(t.snapAngle&&t.snapAngle>0){let e=t.snapAngle,n=t.snapThreshold||e,r=Math.ceil(d/e)*e,i=Math.floor(d/e)*e;Math.abs(d-i)<n?d=i:Math.abs(d-r)<n&&(d=r)}d<0&&(d=360+d),d%=360;let f=t.angle!==d;return t.angle=d,f}));function iu(e,t){let n=t.canvas,r=e[n.uniScaleKey];return n.uniformScaling&&!r||!n.uniformScaling&&r}function au(e,t,n){let r=ic(e,`lockScalingX`),i=ic(e,`lockScalingY`);if(r&&i||!t&&(r||i)&&n||r&&t===`x`||i&&t===`y`)return!0;let{width:a,height:o,strokeWidth:s}=e;return a===0&&s===0&&t!==`y`||o===0&&s===0&&t!==`x`}var ou=[`e`,`se`,`s`,`sw`,`w`,`nw`,`n`,`ne`,`e`],su=(e,t,n,r)=>{let i=iu(e,n);return au(n,t.x!==0&&t.y===0?`x`:t.x===0&&t.y!==0?`y`:``,i)?tc:`${ou[oc(n,0,r)]}-resize`};function cu(e,t,n,r,i={}){let a=t.target,o=i.by,s=iu(e,a),c,l,u,d,f,p;if(au(a,o,s))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(c=sc(t,t.originX,t.originY,n,r),f=o===`y`?1:Math.sign(c.x||t.signX||1),p=o===`x`?1:Math.sign(c.y||t.signY||1),t.signX||=f,t.signY||=p,ic(a,`lockScalingFlip`)&&(t.signX!==f||t.signY!==p))return!1;if(d=a._getTransformedDimensions(),s&&!o){let e=Math.abs(c.x)+Math.abs(c.y),{original:n}=t,r=e/(Math.abs(d.x*n.scaleX/a.scaleX)+Math.abs(d.y*n.scaleY/a.scaleY));l=n.scaleX*r,u=n.scaleY*r}else l=Math.abs(c.x*a.scaleX/d.x),u=Math.abs(c.y*a.scaleY/d.y);nc(t)&&(l*=2,u*=2),t.signX!==f&&o!==`y`&&(t.originX=rc(t.originX),l*=-1,t.signX=f),t.signY!==p&&o!==`x`&&(t.originY=rc(t.originY),u*=-1,t.signY=p)}let m=a.scaleX,h=a.scaleY;return o?(o===`x`&&a.set(`scaleX`,l),o===`y`&&a.set(`scaleY`,u)):(!ic(a,`lockScalingX`)&&a.set(`scaleX`,l),!ic(a,`lockScalingY`)&&a.set(`scaleY`,u)),m!==a.scaleX||h!==a.scaleY}var lu=Kl(Qa,ql((e,t,n,r)=>cu(e,t,n,r))),uu=Kl(Qa,ql((e,t,n,r)=>cu(e,t,n,r,{by:`x`}))),du=Kl(Qa,ql((e,t,n,r)=>cu(e,t,n,r,{by:`y`}))),fu={x:{counterAxis:`y`,scale:oo,skew:co,lockSkewing:`lockSkewingX`,origin:`originX`,flip:`flipX`},y:{counterAxis:`x`,scale:so,skew:lo,lockSkewing:`lockSkewingY`,origin:`originY`,flip:`flipY`}},pu=[`ns`,`nesw`,`ew`,`nwse`],mu=(e,t,n,r)=>t.x!==0&&ic(n,`lockSkewingY`)||t.y!==0&&ic(n,`lockSkewingX`)?tc:`${pu[oc(n,0,r)%4]}-resize`;function hu(e,t,n,r,i){let{target:a}=n,{counterAxis:o,origin:s,lockSkewing:c,skew:l,flip:u}=fu[e];if(ic(a,c))return!1;let{origin:d,flip:f}=fu[o],p=Hs(n[d])*(a[f]?-1:1),m=-Math.sign(p)*(a[u]?-1:1),h=-(a[l]===0&&sc(n,`center`,`center`,r,i)[e]>0||a[l]>0?1:-1)*m*.5+.5;return Kl(to,ql((t,n,r,i)=>function(e,{target:t,ex:n,ey:r,skewingSide:i,...a},o){let{skew:s}=fu[e],c=o.subtract(new Q(n,r)).divide(new Q(t.scaleX,t.scaleY))[e],l=t[s],u=a[s],d=Math.tan(Fo(u)),f=e===`y`?t._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:t._getTransformedDimensions({scaleX:1,scaleY:1}).y,p=2*c*i/Math.max(f,1)+d,m=Io(Math.atan(p));t.set(s,m);let h=l!==t[s];if(h&&e===`y`){let{skewX:e,scaleX:n}=t,r=t._getTransformedDimensions({skewY:l}),i=t._getTransformedDimensions(),a=e===0?1:r.x/i.x;a!==1&&t.set(`scaleX`,a*n)}return h}(e,n,new Q(r,i))))(t,{...n,[s]:h,skewingSide:m},r,i)}var gu=(e,t,n,r)=>hu(`x`,e,t,n,r),_u=(e,t,n,r)=>hu(`y`,e,t,n,r);function vu(e,t){return e[t.canvas.altActionKey]}var yu=(e,t,n)=>{let r=vu(e,n);return t.x===0?r?co:so:t.y===0?r?lo:oo:``},bu=(e,t,n,r)=>vu(e,n)?mu(0,t,n,r):su(e,t,n,r),xu=(e,t,n,r)=>vu(e,t.target)?_u(e,t,n,r):uu(e,t,n,r),Su=(e,t,n,r)=>vu(e,t.target)?gu(e,t,n,r):du(e,t,n,r),Cu=()=>({ml:new tu({x:-.5,y:0,cursorStyleHandler:bu,actionHandler:xu,getActionName:yu}),mr:new tu({x:.5,y:0,cursorStyleHandler:bu,actionHandler:xu,getActionName:yu}),mb:new tu({x:0,y:.5,cursorStyleHandler:bu,actionHandler:Su,getActionName:yu}),mt:new tu({x:0,y:-.5,cursorStyleHandler:bu,actionHandler:Su,getActionName:yu}),tl:new tu({x:-.5,y:-.5,cursorStyleHandler:su,actionHandler:lu}),tr:new tu({x:.5,y:-.5,cursorStyleHandler:su,actionHandler:lu}),bl:new tu({x:-.5,y:.5,cursorStyleHandler:su,actionHandler:lu}),br:new tu({x:.5,y:.5,cursorStyleHandler:su,actionHandler:lu}),mtr:new tu({x:0,y:-.5,actionHandler:ru,cursorStyleHandler:nu,offsetY:-40,withConnection:!0,actionName:eo})}),wu=()=>({mr:new tu({x:.5,y:0,actionHandler:Zl,cursorStyleHandler:bu,actionName:no}),ml:new tu({x:-.5,y:0,actionHandler:Zl,cursorStyleHandler:bu,actionName:no})}),Tu=()=>({...Cu(),...wu()}),Eu=class e extends Wl{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,this.constructor.createControls(),e.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Cu()}}_updateCacheCanvas(){let e=this.canvas;if(this.noScaleCache&&e&&e._currentTransform){let t=e._currentTransform,n=t.target,r=t.action;if(this===n&&r&&r.startsWith(`scale`))return!1}return super._updateCacheCanvas()}getActiveControl(){let e=this.__corner;return e?{key:e,control:this.controls[e],coord:this.oCoords[e]}:void 0}findControl(e,t=!1){if(!this.hasControls||!this.canvas)return;this.__corner=void 0;let n=Object.entries(this.oCoords);for(let r=n.length-1;r>=0;r--){let[i,a]=n[r],o=this.controls[i];if(o.shouldActivate(i,this,e,t?a.touchCorner:a.corner))return this.__corner=i,{key:i,control:o,coord:this.oCoords[i]}}}calcOCoords(){let e=this.getViewportTransform(),t=Uo(e),n=Wo(e),r=this.getCenterPoint(),i=Bo(Bo(e,Bo(Ko(r.x,r.y),qo({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}))),[1/t,0,0,1/n,0,0]),a=this.group?Go(this.calcTransformMatrix()):void 0;a&&(a.scaleX=Math.abs(a.scaleX),a.scaleY=Math.abs(a.scaleY));let o=this._calculateCurrentDimensions(a),s={};return this.forEachControl((e,t)=>{let n=e.positionHandler(o,i,this,e);s[t]=Object.assign(n,this._calcCornerCoords(e,n))}),s}_calcCornerCoords(e,t){let n=this.getTotalAngle();return{corner:e.calcCornerCoords(n,this.cornerSize,t.x,t.y,!1,this),touchCorner:e.calcCornerCoords(n,this.touchCornerSize,t.x,t.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(e){for(let t in this.controls)e(this.controls[t],t,this)}drawSelectionBackground(e){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;e.save();let t=this.getRelativeCenterPoint(),n=this._calculateCurrentDimensions(),r=this.getViewportTransform();e.translate(t.x,t.y),e.scale(1/r[0],1/r[3]),e.rotate(Fo(this.angle)),e.fillStyle=this.selectionBackgroundColor,e.fillRect(-n.x/2,-n.y/2,n.x,n.y),e.restore()}strokeBorders(e,t){e.strokeRect(-t.x/2,-t.y/2,t.x,t.y)}_drawBorders(e,t,n={}){let r={hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray,...n};e.save(),e.strokeStyle=r.borderColor,this._setLineDash(e,r.borderDashArray),this.strokeBorders(e,t),r.hasControls&&this.drawControlsConnectingLines(e,t),e.restore()}_renderControls(e,t={}){let{hasBorders:n,hasControls:r}=this,i={hasBorders:n,hasControls:r,...t},a=this.getViewportTransform(),o=i.hasBorders,s=i.hasControls,c=Go(Bo(a,this.calcTransformMatrix()));e.save(),e.translate(c.translateX,c.translateY),e.lineWidth=this.borderScaleFactor,this.group===this.parent&&(e.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(c.angle-=180);let l=Ho(a);e.rotate(this.group?Fo(c.angle):Fo(this.angle)+l),o&&this.drawBorders(e,c,t),s&&this.drawControls(e,t),e.restore()}drawBorders(e,t,n){let r;if(n&&n.forActiveSelection||this.group){let e=Is(this.width,this.height,Qo(t)),n=this.isStrokeAccountedForInDimensions()?xo:(this.strokeUniform?new Q().scalarAdd(this.canvas?this.canvas.getZoom():1):new Q(t.scaleX,t.scaleY)).scalarMultiply(this.strokeWidth);r=e.add(n).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else r=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(e,r,n)}drawControlsConnectingLines(e,t){let n=!1;e.beginPath(),this.forEachControl((r,i)=>{r.withConnection&&r.getVisibility(this,i)&&(n=!0,e.moveTo(r.x*t.x,r.y*t.y),e.lineTo(r.x*t.x+r.offsetX,r.y*t.y+r.offsetY))}),n&&e.stroke()}drawControls(e,t={}){e.save();let n=this.getCanvasRetinaScaling(),{cornerStrokeColor:r,cornerDashArray:i,cornerColor:a}=this,o={cornerStrokeColor:r,cornerDashArray:i,cornerColor:a,...t};e.setTransform(n,0,0,n,0,0),e.strokeStyle=e.fillStyle=o.cornerColor,this.transparentCorners||(e.strokeStyle=o.cornerStrokeColor),this._setLineDash(e,o.cornerDashArray),this.forEachControl((t,n)=>{if(t.getVisibility(this,n)){let r=this.oCoords[n];t.render(e,r.x,r.y,o,this)}}),e.restore()}isControlVisible(e){return this.controls[e]&&this.controls[e].getVisibility(this,e)}setControlVisible(e,t){this._controlsVisibility||={},this._controlsVisibility[e]=t}setControlsVisibility(e={}){Object.entries(e).forEach(([e,t])=>this.setControlVisible(e,t))}clearContextTop(e){if(!this.canvas)return;let t=this.canvas.contextTop;if(!t)return;let n=this.canvas.viewportTransform;t.save(),t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),this.transform(t);let r=this.width+4,i=this.height+4;return t.clearRect(-r/2,-i/2,r,i),e||t.restore(),t}onDeselect(e){return!1}onSelect(e){return!1}shouldStartDragging(e){return!1}onDragStart(e){return!1}canDrop(e){return!1}renderDragSourceEffect(e){}renderDropTargetEffect(e){}};function Du(e,t){return t.forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(n=>{n!==`constructor`&&Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(t.prototype,n)||Object.create(null))})}),e}Y(Eu,`ownDefaults`,{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:`rgb(178,204,255)`,cornerStrokeColor:``,cornerStyle:`rect`,cornerDashArray:null,hasControls:!0,borderColor:`rgb(178,204,255)`,borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:``,selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:`down`,hoverCursor:null,moveCursor:null});var Ou=class extends Eu{};Du(Ou,[wc]),Z.setClass(Ou),Z.setClass(Ou,`object`);var ku=(e,t,n,r)=>{let i=2*(r=Math.round(r))+1,{data:a}=e.getImageData(t-r,n-r,i,i);for(let e=3;e<a.length;e+=4)if(a[e]>0)return!1;return!0},Au=class{constructor(e){this.options=e,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new Q(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new Q(1/this.options.scaleX,1/this.options.scaleY):new Q(1,1)}createSideVector(e,t){let n=Ks(e,t);return this.options.strokeUniform?n.multiply(this.scale):n}projectOrthogonally(e,t,n){return this.applySkew(e.add(this.calcOrthogonalProjection(e,t,n)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(e){let t=new Q(e);return t.y+=t.x*Math.tan(Fo(this.options.skewY)),t.x+=t.y*Math.tan(Fo(this.options.skewX)),t}scaleUnitVector(e,t){return e.multiply(this.strokeUniformScalar).scalarMultiply(t)}},ju=new Q,Mu=class e extends Au{static getOrthogonalRotationFactor(e,t){let n=t?Js(e,t):Ys(e);return Math.abs(n)<Ba?-1:1}constructor(e,t,n,r){super(r),Y(this,`AB`,void 0),Y(this,`AC`,void 0),Y(this,`alpha`,void 0),Y(this,`bisector`,void 0),this.A=new Q(e),this.B=new Q(t),this.C=new Q(n),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Js(this.AB,this.AC),this.bisector=Xs(Gs(this.AB.eq(ju)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,n,r=this.strokeProjectionMagnitude){let i=Zs(this.createSideVector(t,n)),a=e.getOrthogonalRotationFactor(i,this.bisector);return this.scaleUnitVector(i,r*a)}projectBevel(){let e=[];return(this.alpha%Ha===0?[this.B]:[this.B,this.C]).forEach(t=>{e.push(this.projectOrthogonally(this.A,t)),e.push(this.projectOrthogonally(this.A,t,-this.strokeProjectionMagnitude))}),e}projectMiter(){let e=[],t=Math.abs(this.alpha),n=1/Math.sin(t/2),r=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*n),i=this.options.strokeUniform?qs(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return qs(r)/this.strokeProjectionMagnitude<=i&&e.push(this.applySkew(this.A.add(r))),e.push(...this.projectBevel()),e}projectRoundNoSkew(t,n){let r=[],i=new Q(e.getOrthogonalRotationFactor(this.bisector),e.getOrthogonalRotationFactor(new Q(this.bisector.y,this.bisector.x)));return[new Q(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new Q(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(e=>{ec(e,t,n)&&r.push(this.A.add(e))}),r}projectRoundWithSkew(e,t){let n=[],{skewX:r,skewY:i,scaleX:a,scaleY:o,strokeUniform:s}=this.options,c=new Q(Math.tan(Fo(r)),Math.tan(Fo(i))),l=this.strokeProjectionMagnitude,u=s?l/o/Math.sqrt(1/o**2+1/a**2*c.y**2):l/Math.sqrt(1+c.y**2),d=new Q(Math.sqrt(Math.max(l**2-u**2,0)),u),f=s?l/Math.sqrt(1+c.x**2*(1/o)**2/(1/a+1/a*c.x*c.y)**2):l/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new Q(f,Math.sqrt(Math.max(l**2-f**2,0)));return[p,p.scalarMultiply(-1),d,d.scalarMultiply(-1)].map(e=>this.applySkew(s?e.multiply(this.strokeUniformScalar):e)).forEach(r=>{ec(r,e,t)&&n.push(this.applySkew(this.A).add(r))}),n}projectRound(){let e=[];e.push(...this.projectBevel());let t=this.alpha%Ha===0,n=this.applySkew(this.A),r=e[t?0:2].subtract(n),i=e[+!!t].subtract(n),a=Qs(r,t?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)))>0,o=a?r:i,s=a?i:r;return this.isSkewed()?e.push(...this.projectRoundWithSkew(o,s)):e.push(...this.projectRoundNoSkew(o,s)),e}projectPoints(){switch(this.options.strokeLineJoin){case`miter`:return this.projectMiter();case`round`:return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(e=>({originPoint:this.A,projectedPoint:e,angle:this.alpha,bisector:this.bisector}))}},Nu=class extends Au{constructor(e,t,n){super(n),this.A=new Q(e),this.T=new Q(t)}calcOrthogonalProjection(e,t,n=this.strokeProjectionMagnitude){let r=this.createSideVector(e,t);return this.scaleUnitVector(Zs(r),n)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){let e=[];if(!this.isSkewed()&&this.A.eq(this.T)){let t=new Q(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);e.push(this.applySkew(this.A.add(t)),this.applySkew(this.A.subtract(t)))}else e.push(...new Mu(this.A,this.T,this.T,this.options).projectRound());return e}projectSquare(){let e=[];if(this.A.eq(this.T)){let t=new Q(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);e.push(this.A.add(t),this.A.subtract(t))}else{let t=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),n=this.scaleUnitVector(Xs(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),r=this.A.add(n);e.push(r.add(t),r.subtract(t))}return e.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case`round`:return this.projectRound();case`square`:return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(e=>({originPoint:this.A,projectedPoint:e}))}},Pu=(e,t,n=!1)=>{let r=[];if(e.length===0)return r;let i=e.reduce((e,t)=>(e[e.length-1].eq(t)||e.push(new Q(t)),e),[new Q(e[0])]);if(i.length===1)n=!0;else if(!n){let e=i[0],t=((e,t)=>{for(let n=e.length-1;n>=0;n--)if(t(e[n],n,e))return n;return-1})(i,t=>!t.eq(e));i.splice(t+1)}return i.forEach((e,i,a)=>{let o,s;i===0?(s=a[1],o=n?e:a[a.length-1]):i===a.length-1?(o=a[i-1],s=n?e:a[0]):(o=a[i-1],s=a[i+1]),n&&a.length===1?r.push(...new Nu(e,e,t).project()):!n||i!==0&&i!==a.length-1?r.push(...new Mu(e,o,s,t).project()):r.push(...new Nu(e,i===0?s:o,t).project())}),r},Fu=e=>{let t={};return Object.keys(e).forEach(n=>{t[n]={},Object.keys(e[n]).forEach(r=>{t[n][r]={...e[n][r]}})}),t},Iu=(e,t,n=!1)=>e.fill!==t.fill||e.stroke!==t.stroke||e.strokeWidth!==t.strokeWidth||e.fontSize!==t.fontSize||e.fontFamily!==t.fontFamily||e.fontWeight!==t.fontWeight||e.fontStyle!==t.fontStyle||e.textDecorationThickness!==t.textDecorationThickness||e.textDecorationColor!==t.textDecorationColor||e.textBackgroundColor!==t.textBackgroundColor||e.deltaY!==t.deltaY||n&&(e.overline!==t.overline||e.underline!==t.underline||e.linethrough!==t.linethrough),Lu=(e,t)=>{let n=t.split(`
|
|
15
|
+
`),r=[],i=-1,a={};e=Fu(e);for(let t=0;t<n.length;t++){let o=Ss(n[t]);if(e[t])for(let n=0;n<o.length;n++){i++;let o=e[t][n];o&&Object.keys(o).length>0&&(Iu(a,o,!0)?r.push({start:i,end:i+1,style:o}):r[r.length-1].end++),a=o||{}}else i+=o.length,a={}}return r},Ru=(e,t)=>{if(!Array.isArray(e))return Fu(e);let n=t.split(Xa),r={},i=-1,a=0;for(let t=0;t<n.length;t++){let o=Ss(n[t]);for(let n=0;n<o.length;n++)i++,e[a]&&e[a].start<=i&&i<e[a].end&&(r[t]=r[t]||{},r[t][n]={...e[a].style},i===e[a].end-1&&a++)}return r},zu=[`display`,`transform`,uo,`fill-opacity`,`fill-rule`,`opacity`,fo,`stroke-dasharray`,`stroke-linecap`,`stroke-dashoffset`,`stroke-linejoin`,`stroke-miterlimit`,`stroke-opacity`,`stroke-width`,`id`,`paint-order`,`vector-effect`,`instantiated_by_use`,`clip-path`];function Bu(e,t){let n=e.nodeName,r=e.getAttribute(`class`),i=e.getAttribute(`id`),a=`(?![a-zA-Z\\-]+)`,o;if(o=RegExp(`^`+n,`i`),t=t.replace(o,``),i&&t.length&&(o=RegExp(`#`+i+a,`i`),t=t.replace(o,``)),r&&t.length){let e=r.split(` `);for(let n=e.length;n--;)o=RegExp(`\\.`+e[n]+a,`i`),t=t.replace(o,``)}return t.length===0}function Vu(e,t){let n=!0,r=Bu(e,t.pop());return r&&t.length&&(n=function(e,t){let n,r=!0;for(;e.parentElement&&e.parentElement.nodeType===1&&t.length;)r&&(n=t.pop()),r=Bu(e=e.parentElement,n);return t.length===0}(e,t)),r&&n&&t.length===0}function Hu(e,t={}){let n={};for(let r in t)Vu(e,r.split(` `))&&(n={...n,...t[r]});return n}var Uu=e=>zc[e]??e,Wu=RegExp(`(${Fc})`,`gi`),Gu=`(${Fc})`,Ku=String.raw`(skewX)\(${Gu}\)`,qu=String.raw`(skewY)\(${Gu}\)`,Ju=String.raw`(rotate)\(${Gu}(?: ${Gu} ${Gu})?\)`,Yu=String.raw`(scale)\(${Gu}(?: ${Gu})?\)`,Xu=String.raw`(translate)\(${Gu}(?: ${Gu})?\)`,Zu=`(?:${String.raw`(matrix)\(${Gu} ${Gu} ${Gu} ${Gu} ${Gu} ${Gu}\)`}|${Xu}|${Ju}|${Yu}|${Ku}|${qu})`,Qu=`(?:${Zu}*)`,$u=String.raw`^\s*(?:${Qu}?)\s*$`,ed=new RegExp($u),td=new RegExp(Zu),nd=new RegExp(Zu,`g`);function rd(e){let t=[];if(!(e=(e=>fc(e.replace(Wu,` $1 `).replace(/,/gi,` `)))(e).replace(/\s*([()])\s*/gi,`$1`))||e&&!ed.test(e))return[...Wa];for(let n of e.matchAll(nd)){let e=td.exec(n[0]);if(!e)continue;let r=Wa,[,i,...a]=e.filter(e=>!!e),[o,s,c,l,u,d]=a.map(e=>parseFloat(e));switch(i){case`translate`:r=Ko(o,s);break;case eo:r=qo({angle:o},{x:s,y:c});break;case ao:r=Jo(o,s);break;case co:r=Xo(o);break;case lo:r=Zo(o);break;case`matrix`:r=[o,s,c,l,u,d]}t.push(r)}return Vo(t)}function id(e,t,n,r){let i=Array.isArray(t),a,o=t;if(e!==`fill`&&e!==`stroke`||t!==`none`){if(e===`strokeUniform`)return t===`non-scaling-stroke`;if(e===`strokeDashArray`)o=t===`none`?null:t.replace(/,/g,` `).split(/\s+/).map(parseFloat);else if(e===`transformMatrix`)o=n&&n.transformMatrix?Bo(n.transformMatrix,rd(t)):rd(t);else if(e===`visible`)o=t!==`none`&&t!==`hidden`,n&&!1===n.visible&&(o=!1);else if(e===`opacity`)o=parseFloat(t),n&&n.opacity!==void 0&&(o*=n.opacity);else if(e===`textAnchor`)o=t===`start`?Ka:t===`end`?Ja:Ga;else if(e===`charSpacing`||e===`textDecorationThickness`)a=xc(t,r)/r*1e3;else if(e===`paintFirst`){let e=t.indexOf(uo),n=t.indexOf(fo);o=uo,(e>-1&&n>-1&&n<e||e===-1&&n>-1)&&(o=fo)}else{if(e===`href`||e===`xlink:href`||e===`font`||e===`id`)return t;if(e===`imageSmoothing`)return t===`optimizeQuality`;a=i?t.map(xc):xc(t,r)}}else o=``;return!i&&isNaN(a)?o:a}function ad(e,t){e.replace(/;\s*$/,``).split(`;`).forEach(e=>{if(!e)return;let[n,r]=e.split(`:`);t[n.trim().toLowerCase()]=r.trim()})}function od(e){let t={},n=e.getAttribute(`style`);return n&&(typeof n==`string`?ad(n,t):function(e,t){Object.entries(e).forEach(([e,n])=>{n!==void 0&&(t[e.toLowerCase()]=n)})}(n,t)),t}var sd={stroke:`strokeOpacity`,fill:`fillOpacity`};function cd(e,t,n){if(!e)return{};let r,i={},a=16;e.parentNode&&Wc.test(e.parentNode.nodeName)&&(i=cd(e.parentElement,t,n),i.fontSize&&(r=a=xc(i.fontSize)));let o={...t.reduce((t,n)=>{let r=e.getAttribute(n);return r&&(t[n]=r),t},{}),...Hu(e,n),...od(e)};o[`clip-path`]&&e.setAttribute(Vc,o[Vc]),o[`font-size`]&&(r=xc(o[Bc],a),o[Bc]=`${r}`);let s={};for(let e in o){let t=Uu(e);s[t]=id(t,o[e],i,r)}s&&s.font&&function(e,t){let n=e.match(Rc);if(!n)return;let r=n[1],i=n[3],a=n[4],o=n[5],s=n[6];r&&(t.fontStyle=r),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),a&&(t.fontSize=xc(a)),s&&(t.fontFamily=s),o&&(t.lineHeight=o===`normal`?1:o)}(s.font,s);let c={...i,...s};return Wc.test(e.nodeName)?c:function(e){let t=Ou.getDefaults();return Object.entries(sd).forEach(([n,r])=>{if(e[r]===void 0||e[n]===``)return;if(e[n]===void 0){if(!t[n])return;e[n]=t[n]}if(e[n].indexOf(`url(`)===0)return;let i=new yc(e[n]);e[n]=i.setAlpha(as(i.getAlpha()*e[r],2)).toRgba()}),e}(c)}var ld=[`rx`,`ry`],ud=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,e.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){let{rx:e,ry:t}=this;e&&!t?this.ry=e:t&&!e&&(this.rx=t)}_render(e){let{width:t,height:n}=this,r=-t/2,i=-n/2,a=this.rx?Math.min(this.rx,t/2):0,o=this.ry?Math.min(this.ry,n/2):0,s=a!==0||o!==0;e.beginPath(),e.moveTo(r+a,i),e.lineTo(r+t-a,i),s&&e.bezierCurveTo(r+t-.4477152502*a,i,r+t,i+.4477152502*o,r+t,i+o),e.lineTo(r+t,i+n-o),s&&e.bezierCurveTo(r+t,i+n-.4477152502*o,r+t-.4477152502*a,i+n,r+t-a,i+n),e.lineTo(r+a,i+n),s&&e.bezierCurveTo(r+.4477152502*a,i+n,r,i+n-.4477152502*o,r,i+n-o),e.lineTo(r,i+o),s&&e.bezierCurveTo(r,i+.4477152502*o,r+.4477152502*a,i,r+a,i),e.closePath(),this._renderPaintInOrder(e)}toObject(e=[]){return super.toObject([...ld,...e])}_toSVG(){let{width:e,height:t,rx:n,ry:r}=this;return[`<rect `,`COMMON_PARTS`,`x="${-e/2}" y="${-t/2}" rx="${$(n)}" ry="${$(r)}" width="${$(e)}" height="${$(t)}" />\n`]}static async fromElement(e,t,n){let{left:r=0,top:i=0,width:a=0,height:o=0,visible:s=!0,...c}=cd(e,this.ATTRIBUTE_NAMES,n);return new this({...t,...c,left:r,top:i,width:a,height:o,visible:!!(s&&a&&o)})}};Y(ud,`type`,`Rect`),Y(ud,`cacheProperties`,[...Zc,...ld]),Y(ud,`ownDefaults`,{rx:0,ry:0}),Y(ud,`ATTRIBUTE_NAMES`,[...zu,`x`,`y`,`rx`,`ry`,`width`,`height`]),Z.setClass(ud),Z.setSVGClass(ud);var dd=`initialization`,fd=`added`,pd=(e,t)=>{let{strokeUniform:n,strokeWidth:r,width:i,height:a,group:o}=t,s=o&&o!==e?Ls(o.calcTransformMatrix(),e.calcTransformMatrix()):null,c=s?t.getRelativeCenterPoint().transform(s):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),u=n&&l?zs(new Q(r,r),void 0,e.calcTransformMatrix()):xo,d=!n&&l?r:0,f=Is(i+d,a+d,Vo([s,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[c.subtract(f),c.add(f)]},md=class{calcLayoutResult(e,t){if(this.shouldPerformLayout(e))return this.calcBoundingBox(t,e)}shouldPerformLayout({type:e,prevStrategy:t,strategy:n}){return e===`initialization`||e===`imperative`||!!t&&n!==t}shouldLayoutClipPath({type:e,target:{clipPath:t}}){return e!==`initialization`&&t&&!t.absolutePositioned}getInitialSize(e,t){return t.size}calcBoundingBox(e,t){let{type:n,target:r}=t;if(n===`imperative`&&t.overrides)return t.overrides;if(e.length===0)return;let{left:i,top:a,width:o,height:s}=As(e.map(e=>pd(r,e)).reduce((e,t)=>e.concat(t),[])),c=new Q(o,s),l=new Q(i,a).add(c.scalarDivide(2));if(n===`initialization`){let e=this.getInitialSize(t,{size:c,center:l});return{center:l,relativeCorrection:new Q(0,0),size:e}}return{center:l.transform(r.calcOwnMatrix()),size:c}}};Y(md,`type`,`strategy`);var hd=class extends md{shouldPerformLayout(e){return!0}};Y(hd,`type`,`fit-content`),Z.setClass(hd);var gd=`layoutManager`,_d=class{constructor(e=new hd){Y(this,`strategy`,void 0),this.strategy=e,this._subscriptions=new Map}performLayout(e){let t={bubbles:!0,strategy:this.strategy,...e,prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}};this.onBeforeLayout(t);let n=this.getLayoutResult(t);n&&this.commitLayout(t,n),this.onAfterLayout(t,n),this._prevLayoutStrategy=t.strategy}attachHandlers(e,t){let{target:n}=t;return[po,Za,no,$a,Qa,to,io,ro,`modifyPath`].map(t=>e.on(t,e=>this.performLayout(t===`modified`?{type:`object_modified`,trigger:t,e,target:n}:{type:`object_modifying`,trigger:t,e,target:n})))}subscribe(e,t){this.unsubscribe(e,t);let n=this.attachHandlers(e,t);this._subscriptions.set(e,n)}unsubscribe(e,t){(this._subscriptions.get(e)||[]).forEach(e=>e()),this._subscriptions.delete(e)}unsubscribeTargets(e){e.targets.forEach(t=>this.unsubscribe(t,e))}subscribeTargets(e){e.targets.forEach(t=>this.subscribe(t,e))}onBeforeLayout(e){let{target:t,type:n}=e,{canvas:r}=t;if(n===`initialization`||n===`added`?this.subscribeTargets(e):n===`removed`&&this.unsubscribeTargets(e),t.fire(`layout:before`,{context:e}),r&&r.fire(`object:layout:before`,{target:t,context:e}),n===`imperative`&&e.deep){let{strategy:n,...r}=e;t.forEachObject(e=>e.layoutManager&&e.layoutManager.performLayout({...r,bubbles:!1,target:e}))}}getLayoutResult(e){let{target:t,strategy:n,type:r}=e,i=n.calcLayoutResult(e,t.getObjects());if(!i)return;let a=r===`initialization`?new Q:t.getRelativeCenterPoint(),{center:o,correction:s=new Q,relativeCorrection:c=new Q}=i;return{result:i,prevCenter:a,nextCenter:o,offset:a.subtract(o).add(s).transform(r===`initialization`?Wa:zo(t.calcOwnMatrix()),!0).add(c)}}commitLayout(e,t){let{target:n}=e,{result:{size:r},nextCenter:i}=t;n.set({width:r.x,height:r.y}),this.layoutObjects(e,t),e.type===`initialization`?n.set({left:e.x??i.x+r.x*Hs(n.originX),top:e.y??i.y+r.y*Hs(n.originY)}):(n.setPositionByOrigin(i,Ga,Ga),n.setCoords(),n.set(`dirty`,!0))}layoutObjects(e,t){let{target:n}=e;n.forEachObject(r=>{r.group===n&&this.layoutObject(e,t,r)}),e.strategy.shouldLayoutClipPath(e)&&this.layoutObject(e,t,n.clipPath)}layoutObject(e,{offset:t},n){n.set({left:n.left+t.x,top:n.top+t.y})}onAfterLayout(e,t){let{target:n,strategy:r,bubbles:i,prevStrategy:a,...o}=e,{canvas:s}=n;n.fire(`layout:after`,{context:e,result:t}),s&&s.fire(`object:layout:after`,{context:e,result:t,target:n});let c=n.parent;i&&c!=null&&c.layoutManager&&((o.path||=[]).push(n),c.layoutManager.performLayout({...o,target:c})),n.set(`dirty`,!0)}dispose(){let{_subscriptions:e}=this;e.forEach(e=>e.forEach(e=>e())),e.clear()}toObject(){return{type:gd,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}};Z.setClass(_d,gd);var vd=class extends _d{performLayout(){}},yd=class e extends Co(Ou){static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t=[],n={}){super(),Y(this,`_activeObjects`,[]),Y(this,`__objectSelectionTracker`,void 0),Y(this,`__objectSelectionDisposer`,void 0),Object.assign(this,e.ownDefaults),this.setOptions(n),this.groupInit(t,n)}groupInit(e,t){this._objects=[...e],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(e=>{this.enterGroup(e,!1)}),this.layoutManager=t.layoutManager??new _d,this.layoutManager.performLayout({type:dd,target:this,targets:[...e],x:t.left,y:t.top})}canEnterGroup(e){return e===this||this.isDescendantOf(e)?(Ea(`error`,`Group: circular object trees are not supported, this call has no effect`),!1):this._objects.indexOf(e)===-1||(Ea(`error`,`Group: duplicate objects are not supported inside group, this call has no effect`),!1)}_filterObjectsBeforeEnteringGroup(e){return e.filter((e,t,n)=>this.canEnterGroup(e)&&n.indexOf(e)===t)}add(...e){let t=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...t);return this._onAfterObjectsChange(fd,t),n}insertAt(e,...t){let n=this._filterObjectsBeforeEnteringGroup(t),r=super.insertAt(e,...n);return this._onAfterObjectsChange(fd,n),r}remove(...e){let t=super.remove(...e);return this._onAfterObjectsChange(`removed`,t),t}_onObjectAdded(e){this.enterGroup(e,!0),this.fire(`object:added`,{target:e}),e.fire(`added`,{target:this})}_onObjectRemoved(e,t){this.exitGroup(e,t),this.fire(`object:removed`,{target:e}),e.fire(`removed`,{target:this})}_onAfterObjectsChange(e,t){this.layoutManager.performLayout({type:e,targets:t,target:this})}_onStackOrderChanged(){this._set(`dirty`,!0)}_set(e,t){let n=this[e];return super._set(e,t),e===`canvas`&&n!==t&&(this._objects||[]).forEach(n=>{n._set(e,t)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(e,{target:t}){let n=this._activeObjects;if(e)n.push(t),this._set(`dirty`,!0);else if(n.length>0){let e=n.indexOf(t);e>-1&&(n.splice(e,1),this._set(`dirty`,!0))}}_watchObject(e,t){e&&this._watchObject(!1,t),e?(t.on(`selected`,this.__objectSelectionTracker),t.on(`deselected`,this.__objectSelectionDisposer)):(t.off(`selected`,this.__objectSelectionTracker),t.off(`deselected`,this.__objectSelectionDisposer))}enterGroup(e,t){e.group&&e.group.remove(e),e._set(`parent`,this),this._enterGroup(e,t)}_enterGroup(e,t){t&&Ns(e,Bo(zo(this.calcTransformMatrix()),e.calcTransformMatrix())),this._shouldSetNestedCoords()&&e.setCoords(),e._set(`group`,this),e._set(`canvas`,this.canvas),this._watchObject(!0,e);let n=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();n&&(n===e||e.isDescendantOf(n))&&this._activeObjects.push(e)}exitGroup(e,t){this._exitGroup(e,t),e._set(`parent`,void 0),e._set(`canvas`,void 0)}_exitGroup(e,t){e._set(`group`,void 0),t||(Ns(e,Bo(this.calcTransformMatrix(),e.calcTransformMatrix())),e.setCoords()),this._watchObject(!1,e);let n=this._activeObjects.length>0?this._activeObjects.indexOf(e):-1;n>-1&&this._activeObjects.splice(n,1)}shouldCache(){let e=Ou.prototype.shouldCache.call(this);if(e){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return e}willDrawShadow(){if(super.willDrawShadow())return!0;for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(e,t,n){this._renderBackground(e);for(let t=0;t<this._objects.length;t++){var r;let n=this._objects[t];(r=this.canvas)!=null&&r.preserveObjectStacking&&n.group!==this?(e.save(),e.transform(...zo(this.calcTransformMatrix())),n.render(e),e.restore()):n.group===this&&n.render(e)}this._drawClipPath(e,this.clipPath,n)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(e=>e.setCoords())}triggerLayout(e={}){this.layoutManager.performLayout({target:this,type:`imperative`,...e})}render(e){this._transformDone=!0,super.render(e),this._transformDone=!1}__serializeObjects(e,t){let n=this.includeDefaultValues;return this._objects.filter(function(e){return!e.excludeFromExport}).map(function(r){let i=r.includeDefaultValues;r.includeDefaultValues=n;let a=r[e||`toObject`](t);return r.includeDefaultValues=i,a})}toObject(e=[]){let t=this.layoutManager.toObject();return{...super.toObject([`subTargetCheck`,`interactive`,...e]),...t.strategy!==`fit-content`||this.includeDefaultValues?{layoutManager:t}:{},objects:this.__serializeObjects(`toObject`,e)}}toString(){return`#<Group: (${this.complexity()})>`}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(e=>{this._watchObject(!1,e),e.dispose()}),super.dispose()}_createSVGBgRect(e){if(!this.backgroundColor)return``;let t=ud.prototype._toSVG.call(this),n=t.indexOf(`COMMON_PARTS`);t[n]=`for="group" `;let r=t.join(``);return e?e(r):r}_toSVG(e){let t=[`<g `,`COMMON_PARTS`,` >
|
|
16
|
+
`],n=this._createSVGBgRect(e);n&&t.push(` `,n);for(let n=0;n<this._objects.length;n++)t.push(` `,this._objects[n].toSVG(e));return t.push(`</g>
|
|
17
|
+
`),t}getSvgStyles(){let e=this.opacity!==void 0&&this.opacity!==1?`opacity: ${$(this.opacity)};`:``,t=this.visible?``:` visibility: hidden;`;return[e,this.getSvgFilter(),t].join(``)}toClipPathSVG(e){let t=[],n=this._createSVGBgRect(e);n&&t.push(` `,n);for(let n=0;n<this._objects.length;n++)t.push(` `,this._objects[n].toClipPathSVG(e));return this._createBaseClipPathSVGMarkup(t,{reviver:e})}static fromObject({type:e,objects:t=[],layoutManager:n,...r},i){return Promise.all([ts(t,i),ns(r,i)]).then(([e,t])=>{let i=new this(e,{...r,...t,layoutManager:new vd});return i.layoutManager=n?new(Z.getClass(n.type))(new(Z.getClass(n.strategy))):new _d,i.layoutManager.subscribeTargets({type:dd,target:i,targets:i.getObjects()}),i.setCoords(),i})}};Y(yd,`type`,`Group`),Y(yd,`ownDefaults`,{strokeWidth:0,subTargetCheck:!1,interactive:!1}),Z.setClass(yd);var bd=(e,t)=>e&&e.length===1?e[0]:new yd(e,t),xd=(e,t)=>Math.min(t.width/e.width,t.height/e.height),Sd=(e,t)=>Math.max(t.width/e.width,t.height/e.height),Cd=`\\s*,?\\s*`,wd=`${Cd}(${Fc})`,Td=`${wd}${wd}${wd}${Cd}([01])${Cd}([01])${wd}${wd}`,Ed={m:`l`,M:`L`},Dd=(e,t,n,r,i,a,o,s,c,l,u)=>{let d=yo(e),f=bo(e),p=yo(t),m=bo(t),h=n*i*p-r*a*m+o,g=r*i*p+n*a*m+s;return[`C`,l+c*(-n*i*f-r*a*d),u+c*(-r*i*f+n*a*d),h+c*(n*i*m+r*a*p),g+c*(r*i*m-n*a*p),h,g]},Od=(e,t,n,r)=>{let i=Math.atan2(t,e),a=Math.atan2(r,n);return a>=i?a-i:2*Math.PI-(i-a)};function kd(e,t,n,r,i,a,o,s){let c;if(X.cachesBoundsOfCurve&&(c=[...arguments].join(),La.boundsOfCurveCache[c]))return La.boundsOfCurveCache[c];let l=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]],p=6*e-12*n+6*i,m=-3*e+9*n-9*i+3*o,h=3*n-3*e;for(let e=0;e<2;++e){if(e>0&&(p=6*t-12*r+6*a,m=-3*t+9*r-9*a+3*s,h=3*r-3*t),u(m)<1e-12){if(u(p)<1e-12)continue;let e=-h/p;0<e&&e<1&&d.push(e);continue}let n=p*p-4*h*m;if(n<0)continue;let i=l(n),o=(-p+i)/(2*m);0<o&&o<1&&d.push(o);let c=(-p-i)/(2*m);0<c&&c<1&&d.push(c)}let g=d.length,_=g,v=Nd(e,t,n,r,i,a,o,s);for(;g--;){let{x:e,y:t}=v(d[g]);f[0][g]=e,f[1][g]=t}f[0][_]=e,f[1][_]=t,f[0][_+1]=o,f[1][_+1]=s;let y=[new Q(Math.min(...f[0]),Math.min(...f[1])),new Q(Math.max(...f[0]),Math.max(...f[1]))];return X.cachesBoundsOfCurve&&(La.boundsOfCurveCache[c]=y),y}var Ad=(e,t,[n,r,i,a,o,s,c,l])=>{let u=((e,t,n,r,i,a,o)=>{if(n===0||r===0)return[];let s=0,c=0,l=0,u=Math.PI,d=o*Ua,f=bo(d),p=yo(d),m=.5*(-p*e-f*t),h=.5*(-p*t+f*e),g=n**2,_=r**2,v=h**2,y=m**2,b=g*_-g*v-_*y,x=Math.abs(n),S=Math.abs(r);if(b<0){let e=Math.sqrt(1-b/(g*_));x*=e,S*=e}else l=(i===a?-1:1)*Math.sqrt(b/(g*v+_*y));let C=l*x*h/S,w=-l*S*m/x,T=p*C-f*w+.5*e,E=f*C+p*w+.5*t,D=Od(1,0,(m-C)/x,(h-w)/S),O=Od((m-C)/x,(h-w)/S,(-m-C)/x,(-h-w)/S);a===0&&O>0?O-=2*u:a===1&&O<0&&(O+=2*u);let k=Math.ceil(Math.abs(O/u*2)),A=[],j=O/k,M=8/3*Math.sin(j/4)*Math.sin(j/4)/Math.sin(j/2),N=D+j;for(let e=0;e<k;e++)A[e]=Dd(D,N,p,f,x,S,T,E,M,s,c),s=A[e][5],c=A[e][6],D=N,N+=j;return A})(c-e,l-t,r,i,o,s,a);for(let n=0,r=u.length;n<r;n++)u[n][1]+=e,u[n][2]+=t,u[n][3]+=e,u[n][4]+=t,u[n][5]+=e,u[n][6]+=t;return u},jd=e=>{let t=0,n=0,r=0,i=0,a=[],o,s=0,c=0;for(let l of e){let e=[...l],u;switch(e[0]){case`l`:e[1]+=t,e[2]+=n;case`L`:t=e[1],n=e[2],u=[`L`,t,n];break;case`h`:e[1]+=t;case`H`:t=e[1],u=[`L`,t,n];break;case`v`:e[1]+=n;case`V`:n=e[1],u=[`L`,t,n];break;case`m`:e[1]+=t,e[2]+=n;case`M`:t=e[1],n=e[2],r=e[1],i=e[2],u=[`M`,t,n];break;case`c`:e[1]+=t,e[2]+=n,e[3]+=t,e[4]+=n,e[5]+=t,e[6]+=n;case`C`:s=e[3],c=e[4],t=e[5],n=e[6],u=[`C`,e[1],e[2],s,c,t,n];break;case`s`:e[1]+=t,e[2]+=n,e[3]+=t,e[4]+=n;case`S`:o===`C`?(s=2*t-s,c=2*n-c):(s=t,c=n),t=e[3],n=e[4],u=[`C`,s,c,e[1],e[2],t,n],s=u[3],c=u[4];break;case`q`:e[1]+=t,e[2]+=n,e[3]+=t,e[4]+=n;case`Q`:s=e[1],c=e[2],t=e[3],n=e[4],u=[`Q`,s,c,t,n];break;case`t`:e[1]+=t,e[2]+=n;case`T`:o===`Q`?(s=2*t-s,c=2*n-c):(s=t,c=n),t=e[1],n=e[2],u=[`Q`,s,c,t,n];break;case`a`:e[6]+=t,e[7]+=n;case`A`:Ad(t,n,e).forEach(e=>a.push(e)),t=e[6],n=e[7];break;case`z`:case`Z`:t=r,n=i,u=[`Z`]}u?(a.push(u),o=u[0]):o=``}return a},Md=(e,t,n,r)=>Math.sqrt((n-e)**2+(r-t)**2),Nd=(e,t,n,r,i,a,o,s)=>c=>{let l=c**3,u=(e=>3*e**2*(1-e))(c),d=(e=>3*e*(1-e)**2)(c),f=(e=>(1-e)**3)(c);return new Q(o*l+i*u+n*d+e*f,s*l+a*u+r*d+t*f)},Pd=e=>e**2,Fd=e=>2*e*(1-e),Id=e=>(1-e)**2,Ld=(e,t,n,r,i,a,o,s)=>c=>{let l=Pd(c),u=Fd(c),d=Id(c),f=3*(d*(n-e)+u*(i-n)+l*(o-i)),p=3*(d*(r-t)+u*(a-r)+l*(s-a));return Math.atan2(p,f)},Rd=(e,t,n,r,i,a)=>o=>{let s=Pd(o),c=Fd(o),l=Id(o);return new Q(i*s+n*c+e*l,a*s+r*c+t*l)},zd=(e,t,n,r,i,a)=>o=>{let s=1-o,c=2*(s*(n-e)+o*(i-n)),l=2*(s*(r-t)+o*(a-r));return Math.atan2(l,c)},Bd=(e,t,n)=>{let r=new Q(t,n),i=0;for(let t=1;t<=100;t+=1){let n=e(t/100);i+=Md(r.x,r.y,n.x,n.y),r=n}return i},Vd=(e,t)=>{let n,r=0,i=0,a={x:e.x,y:e.y},o={...a},s=.01,c=0,l=e.iterator,u=e.angleFinder;for(;i<t&&s>1e-4;)o=l(r),c=r,n=Md(a.x,a.y,o.x,o.y),n+i>t?(r-=s,s/=2):(a=o,r+=s,i+=n);return{...o,angle:u(c)}},Hd=e=>{let t,n,r=0,i=0,a=0,o=0,s=0,c=[];for(let l of e){let e={x:i,y:a,command:l[0],length:0};switch(l[0]){case`M`:n=e,n.x=o=i=l[1],n.y=s=a=l[2];break;case`L`:n=e,n.length=Md(i,a,l[1],l[2]),i=l[1],a=l[2];break;case`C`:t=Nd(i,a,l[1],l[2],l[3],l[4],l[5],l[6]),n=e,n.iterator=t,n.angleFinder=Ld(i,a,l[1],l[2],l[3],l[4],l[5],l[6]),n.length=Bd(t,i,a),i=l[5],a=l[6];break;case`Q`:t=Rd(i,a,l[1],l[2],l[3],l[4]),n=e,n.iterator=t,n.angleFinder=zd(i,a,l[1],l[2],l[3],l[4]),n.length=Bd(t,i,a),i=l[3],a=l[4];break;case`Z`:n=e,n.destX=o,n.destY=s,n.length=Md(i,a,o,s),i=o,a=s}r+=n.length,c.push(n)}return c.push({length:r,x:i,y:a}),c},Ud=(e,t,n=Hd(e))=>{let r=0;for(;t-n[r].length>0&&r<n.length-2;)t-=n[r].length,r++;let i=n[r],a=t/i.length,o=e[r];switch(i.command){case`M`:return{x:i.x,y:i.y,angle:0};case`Z`:return{...new Q(i.x,i.y).lerp(new Q(i.destX,i.destY),a),angle:Math.atan2(i.destY-i.y,i.destX-i.x)};case`L`:return{...new Q(i.x,i.y).lerp(new Q(o[1],o[2]),a),angle:Math.atan2(o[2]-i.y,o[1]-i.x)};case`C`:case`Q`:return Vd(i,t)}},Wd=RegExp(`[mzlhvcsqta][^mzlhvcsqta]*`,`gi`),Gd=new RegExp(Td,`g`),Kd=new RegExp(Fc,`gi`),qd={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Jd=e=>{let t=[],n=e.match(Wd)??[];for(let e of n){let n=e[0];if(n===`z`||n===`Z`){t.push([n]);continue}let r=qd[n.toLowerCase()],i=[];if(n===`a`||n===`A`){let t;for(Gd.lastIndex=0;t=Gd.exec(e);)i.push(...t.slice(1))}else i=e.match(Kd)||[];for(let e=0;e<i.length;e+=r){let a=Array(r),o=Ed[n];a[0]=e>0&&o?o:n;for(let t=0;t<r;t++)a[t+1]=parseFloat(i[e+t]);t.push(a)}}return t},Yd=(e,t=0)=>{let n=new Q(e[0]),r=new Q(e[1]),i=1,a=0,o=[],s=e.length,c=s>2,l;for(c&&(i=e[2].x<r.x?-1:e[2].x===r.x?0:1,a=e[2].y<r.y?-1:e[2].y===r.y?0:1),o.push([`M`,n.x-i*t,n.y-a*t]),l=1;l<s;l++){if(!n.eq(r)){let e=n.midPointFrom(r);o.push([`Q`,n.x,n.y,e.x,e.y])}n=e[l],l+1<e.length&&(r=e[l+1])}return c&&(i=n.x>e[l-2].x?1:n.x===e[l-2].x?0:-1,a=n.y>e[l-2].y?1:n.y===e[l-2].y?0:-1),o.push([`L`,n.x+i*t,n.y+a*t]),o},Xd=(e,t,n)=>(n&&(t=Bo(t,[1,0,0,1,-n.x,-n.y])),e.map(e=>{let n=[...e];for(let r=1;r<e.length-1;r+=2){let{x:i,y:a}=Ro({x:e[r],y:e[r+1]},t);n[r]=i,n[r+1]=a}return n})),Zd=(e,t)=>{let n=2*Math.PI/e,r=-Ba;e%2==0&&(r+=n/2);let i=Array(e+1);for(let a=0;a<e;a++){let e=a*n+r,{x:o,y:s}=new Q(yo(e),bo(e)).scalarMultiply(t);i[a]=[a===0?`M`:`L`,o,s]}return i[e]=[`Z`],i},Qd=(e,t)=>e.map(e=>e.map((e,n)=>n===0||t===void 0?e:as(e,t)).join(` `)).join(` `),$d=(e,t)=>{let n=e,r=t;n.inverted&&!r.inverted&&(n=t,r=e),Bs(r,r.group?.calcTransformMatrix(),n.calcTransformMatrix());let i=n.inverted&&r.inverted;return i&&(n.inverted=r.inverted=!1),new yd([n],{clipPath:r,inverted:i})},ef=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,tf=(e,t)=>{let n=e._findCenterFromElement();e.transformMatrix&&((e=>{if(e.transformMatrix){let{scaleX:t,scaleY:n,angle:r,skewX:i}=Go(e.transformMatrix);e.flipX=!1,e.flipY=!1,e.set(oo,t),e.set(so,n),e.angle=r,e.skewX=i,e.skewY=0}})(e),n=n.transform(e.transformMatrix)),delete e.transformMatrix,t&&(e.scaleX*=t.scaleX,e.scaleY*=t.scaleY,e.cropX=t.cropX,e.cropY=t.cropY,n.x+=t.offsetLeft,n.y+=t.offsetTop,e.width=t.width,e.height=t.height),e.setPositionByOrigin(n,Ga,Ga)},nf=Sa({addTransformToObject:()=>Ms,animate:()=>Bl,animateColor:()=>Vl,applyTransformToObject:()=>Ns,calcAngleBetweenVectors:()=>Js,calcDimensionsMatrix:()=>Qo,calcPlaneChangeMatrix:()=>Ls,calcVectorRotation:()=>Ys,cancelAnimFrame:()=>Eo,capValue:()=>Yc,composeMatrix:()=>$o,copyCanvasElement:()=>jo,cos:()=>yo,createCanvasElement:()=>ko,createImage:()=>Ao,createRotateMatrix:()=>qo,createScaleMatrix:()=>Jo,createSkewXMatrix:()=>Xo,createSkewYMatrix:()=>Zo,createTranslateMatrix:()=>Ko,createVector:()=>Ks,crossProduct:()=>Qs,degreesToRadians:()=>Fo,dotProduct:()=>$s,ease:()=>$c,enlivenObjectEnlivables:()=>ns,enlivenObjects:()=>ts,findScaleToCover:()=>Sd,findScaleToFit:()=>xd,getBoundsOfCurve:()=>kd,getOrthonormalVector:()=>Zs,getPathSegmentsInfo:()=>Hd,getPointOnPath:()=>Ud,getPointer:()=>Ds,getRandomInt:()=>ef,getRegularPolygonPath:()=>Zd,getSmoothPathFromPoints:()=>Yd,getSvgAttributes:()=>bc,getUnitVector:()=>Xs,groupSVGElements:()=>bd,hasStyleChanged:()=>Iu,invertTransform:()=>zo,isBetweenVectors:()=>ec,isIdentityMatrix:()=>Lo,isTouchEvent:()=>Os,isTransparent:()=>ku,joinPath:()=>Qd,loadImage:()=>es,magnitude:()=>qs,makeBoundingBoxFromPoints:()=>As,makePathSimpler:()=>jd,matrixToSVG:()=>os,mergeClipPaths:()=>$d,multiplyTransformMatrices:()=>Bo,multiplyTransformMatrixArray:()=>Vo,parsePath:()=>Jd,parsePreserveAspectRatioAttribute:()=>Sc,parseUnit:()=>xc,pick:()=>rs,projectStrokeOnPoints:()=>Pu,qrDecompose:()=>Go,radiansToDegrees:()=>Io,removeFromArray:()=>vo,removeTransformFromObject:()=>js,removeTransformMatrixForSvgParsing:()=>tf,requestAnimFrame:()=>To,resetObjectTransform:()=>Ps,rotateVector:()=>Gs,saveObjectTransform:()=>Fs,sendObjectToPlane:()=>Bs,sendPointToPlane:()=>Rs,sendVectorToPlane:()=>zs,sin:()=>bo,sizeAfterTransform:()=>Is,string:()=>ys,stylesFromArray:()=>Ru,stylesToArray:()=>Lu,toBlob:()=>Po,toDataURL:()=>No,toFixed:()=>as,transformPath:()=>Xd,transformPoint:()=>Ro});function rf(e,t){let n=e.style;n&&Object.entries(t).forEach(([e,t])=>n.setProperty(e,t))}var af=class extends _s{constructor(e,{allowTouchScrolling:t=!1,containerClass:n=``}={}){super(e),Y(this,`upper`,void 0),Y(this,`container`,void 0);let{el:r}=this.lower,i=this.createUpperCanvas();this.upper={el:i,ctx:i.getContext(`2d`)},this.applyCanvasStyle(r,{allowTouchScrolling:t}),this.applyCanvasStyle(i,{allowTouchScrolling:t,styles:{position:`absolute`,left:`0`,top:`0`}});let a=this.createContainerElement();a.classList.add(n),r.parentNode&&r.parentNode.replaceChild(a,r),a.append(r,i),this.container=a}createUpperCanvas(){let{el:e}=this.lower,t=ko();return t.className=e.className,t.classList.remove(`lower-canvas`),t.classList.add(`upper-canvas`),t.setAttribute(`data-fabric`,`top`),t.style.cssText=e.style.cssText,t.setAttribute(`draggable`,`true`),t}createContainerElement(){let e=Pa().createElement(`div`);return e.setAttribute(`data-fabric`,`wrapper`),rf(e,{position:`relative`}),gs(e),e}applyCanvasStyle(e,t){let{styles:n,allowTouchScrolling:r}=t;rf(e,{...n,"touch-action":r?`manipulation`:Ya}),gs(e)}setDimensions(e,t){super.setDimensions(e,t);let{el:n,ctx:r}=this.upper;ms(n,r,e,t)}setCSSDimensions(e){super.setCSSDimensions(e),hs(this.upper.el,e),hs(this.container,e)}cleanupDOM(e){let t=this.container,{el:n}=this.lower,{el:r}=this.upper;super.cleanupDOM(e),t.removeChild(r),t.removeChild(n),t.parentNode&&t.parentNode.replaceChild(n,t)}dispose(){super.dispose(),Na().dispose(this.upper.el),delete this.upper,delete this.container}},of=(e,t,n,r)=>{let{target:i,offsetX:a,offsetY:o}=t,s=n-a,c=r-o,l=!ic(i,`lockMovementX`)&&i.left!==s,u=!ic(i,`lockMovementY`)&&i.top!==c;return l&&i.set(`left`,s),u&&i.set(`top`,c),(l||u)&&Gl(Za,ac(e,t,n,r)),l||u},sf=ro,cf=e=>function(t,n,r){let{points:i,pathOffset:a}=r;return new Q(i[e]).subtract(a).transform(Bo(r.getViewportTransform(),r.calcTransformMatrix()))},lf=(e,t,n,r)=>{let{target:i,pointIndex:a}=t,o=i,s=Rs(new Q(n,r),void 0,o.calcOwnMatrix());return o.points[a]=s.add(o.pathOffset),o.setDimensions(),o.set(`dirty`,!0),!0},uf=(e,t)=>function(n,r,i,a){let o=r.target,s=new Q(o.points[(e>0?e:o.points.length)-1]),c=s.subtract(o.pathOffset).transform(o.calcOwnMatrix()),l=t(n,{...r,pointIndex:e},i,a),u=s.subtract(o.pathOffset).transform(o.calcOwnMatrix()).subtract(c);return o.left-=u.x,o.top-=u.y,l},df=e=>Kl(sf,uf(e,lf));function ff(e,t={}){let n={};for(let r=0;r<(typeof e==`number`?e:e.points.length);r++)n[`p${r}`]=new tu({actionName:sf,positionHandler:cf(r),actionHandler:df(r),...t});return n}var pf=(e,t,n)=>{let{path:r,pathOffset:i}=e,a=r[t];return new Q(a[n]-i.x,a[n+1]-i.y).transform(Bo(e.getViewportTransform(),e.calcTransformMatrix()))};function mf(e,t,n){let{commandIndex:r,pointIndex:i}=this;return pf(n,r,i)}function hf(e,t,n,r){let{target:i}=t,{commandIndex:a,pointIndex:o}=this,s=((e,t,n,r,i)=>{let{path:a,pathOffset:o}=e,s=a[(r>0?r:a.length)-1],c=new Q(s[i],s[i+1]),l=c.subtract(o).transform(e.calcOwnMatrix()),u=Rs(new Q(t,n),void 0,e.calcOwnMatrix());a[r][i]=u.x+o.x,a[r][i+1]=u.y+o.y,e.setDimensions();let d=c.subtract(e.pathOffset).transform(e.calcOwnMatrix()).subtract(l);return e.left-=d.x,e.top-=d.y,e.set(`dirty`,!0),!0})(i,n,r,a,o);return s&&Gl(this.actionName,{...ac(e,t,n,r),commandIndex:a,pointIndex:o}),s}var gf=class extends tu{constructor(e){super(e)}render(e,t,n,r,i){let a={...r,cornerColor:this.controlFill,cornerStrokeColor:this.controlStroke,transparentCorners:!this.controlFill};super.render(e,t,n,a,i)}},_f=class extends gf{constructor(e){super(e)}render(e,t,n,r,i){let{path:a}=i,{commandIndex:o,pointIndex:s,connectToCommandIndex:c,connectToPointIndex:l}=this;e.save(),e.strokeStyle=this.controlStroke,this.connectionDashArray&&e.setLineDash(this.connectionDashArray);let[u]=a[o],d=pf(i,c,l);if(u===`Q`){let r=pf(i,o,s+2);e.moveTo(r.x,r.y),e.lineTo(t,n)}else e.moveTo(t,n);e.lineTo(d.x,d.y),e.stroke(),e.restore(),super.render(e,t,n,r,i)}},vf=(e,t,n,r,i,a)=>new(n?_f:gf)({commandIndex:e,pointIndex:t,actionName:`modifyPath`,positionHandler:mf,actionHandler:hf,connectToCommandIndex:i,connectToPointIndex:a,...r,...n?r.controlPointStyle:r.pointStyle});function yf(e,t={}){let n={},r=`M`;return e.path.forEach((e,i)=>{let a=e[0];switch(a!==`Z`&&(n[`c_${i}_${a}`]=vf(i,e.length-2,!1,t)),a){case`C`:n[`c_${i}_C_CP_1`]=vf(i,1,!0,t,i-1,(e=>e===`C`?5:e===`Q`?3:1)(r)),n[`c_${i}_C_CP_2`]=vf(i,3,!0,t,i,5);break;case`Q`:n[`c_${i}_Q_CP_1`]=vf(i,1,!0,t,i,3)}r=a}),n}Sa({changeHeight:()=>Ql,changeObjectHeight:()=>Xl,changeObjectWidth:()=>Yl,changeWidth:()=>Zl,createObjectDefaultControls:()=>Cu,createPathControls:()=>yf,createPolyActionHandler:()=>df,createPolyControls:()=>ff,createPolyPositionHandler:()=>cf,createResizeControls:()=>wu,createTextboxDefaultControls:()=>Tu,dragHandler:()=>of,factoryPolyActionHandler:()=>uf,getLocalPoint:()=>sc,polyActionHandler:()=>lf,renderCircleControl:()=>$l,renderSquareControl:()=>eu,rotationStyleHandler:()=>nu,rotationWithSnapping:()=>ru,scaleCursorStyleHandler:()=>su,scaleOrSkewActionName:()=>yu,scaleSkewCursorStyleHandler:()=>bu,scalingEqually:()=>lu,scalingX:()=>uu,scalingXOrSkewingY:()=>xu,scalingY:()=>du,scalingYOrSkewingX:()=>Su,skewCursorStyleHandler:()=>mu,skewHandlerX:()=>gu,skewHandlerY:()=>_u,wrapWithFireEvent:()=>Kl,wrapWithFixedAnchor:()=>ql});var bf=class e extends Ts{constructor(...e){super(...e),Y(this,`_hoveredTargets`,[]),Y(this,`_currentTransform`,null),Y(this,`_groupSelector`,null),Y(this,`contextTopDirty`,!1)}static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}get upperCanvasEl(){return this.elements.upper?.el}get contextTop(){return this.elements.upper?.ctx}get wrapperEl(){return this.elements.container}initElements(e){this.elements=new af(e,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(e){this._objectsToRender=void 0,super._onObjectAdded(e)}_onObjectRemoved(e){this._objectsToRender=void 0,e===this._activeObject&&(this.fire(`before:selection:cleared`,{deselected:[e]}),this._discardActiveObject(),this.fire(`selection:cleared`,{deselected:[e]}),e.fire(`deselected`,{target:e})),e===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(e)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){let e=this._activeObject;return!this.preserveObjectStacking&&e?this._objects.filter(t=>!t.group&&t!==e).concat(e):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&=(this.renderTopLayer(this.contextTop),!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(e){e.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(e),this.contextTopDirty=!0),e.restore()}renderTop(){let e=this.contextTop;this.clearContext(e),this.renderTopLayer(e),this.fire(`after:render`,{ctx:e})}setTargetFindTolerance(e){e=Math.round(e),this.targetFindTolerance=e;let t=this.getRetinaScaling(),n=Math.ceil((2*e+1)*t);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=n,this.pixelFindContext.scale(t,t)}isTargetTransparent(e,t,n){let r=this.targetFindTolerance,i=this.pixelFindContext;this.clearContext(i),i.save(),i.translate(-t+r,-n+r),i.transform(...this.viewportTransform);let a=e.selectionBackgroundColor;e.selectionBackgroundColor=``,e.render(i),e.selectionBackgroundColor=a,i.restore();let o=Math.round(r*this.getRetinaScaling());return ku(i,o,o,o)}_isSelectionKeyPressed(e){let t=this.selectionKey;return!!t&&(Array.isArray(t)?!!t.find(t=>!!t&&!0===e[t]):e[t])}_shouldClearSelection(e,t){let n=this.getActiveObjects(),r=this._activeObject;return!!(!t||t&&r&&n.length>1&&n.indexOf(t)===-1&&r!==t&&!this._isSelectionKeyPressed(e)||t&&!t.evented||t&&!t.selectable&&r&&r!==t)}_shouldCenterTransform(e,t,n){if(!e)return;let r;return t===`scale`||t===`scaleX`||t===`scaleY`||t===`resizing`?r=this.centeredScaling||e.centeredScaling:t===`rotate`&&(r=this.centeredRotation||e.centeredRotation),r?!n:n}_getOriginFromCorner(e,t){let n=t?e.controls[t].getTransformAnchorPoint():{x:e.originX,y:e.originY};return t?([`ml`,`tl`,`bl`].includes(t)?n.x=Ja:[`mr`,`tr`,`br`].includes(t)&&(n.x=Ka),[`tl`,`mt`,`tr`].includes(t)?n.y=qa:[`bl`,`mb`,`br`].includes(t)&&(n.y=`top`),n):n}_setupCurrentTransform(e,t,n){let r=t.group?Rs(this.getScenePoint(e),void 0,t.group.calcTransformMatrix()):this.getScenePoint(e),{key:i=``,control:a}=t.getActiveControl()||{},o=n&&a?a.getActionHandler(e,t,a)?.bind(a):of,s=((e,t,n,r)=>{if(!t||!e)return`drag`;let i=r.controls[t];return i.getActionName(n,i,r)})(n,i,e,t),c=e[this.centeredKey],l=this._shouldCenterTransform(t,s,c)?{x:Ga,y:Ga}:this._getOriginFromCorner(t,i),{scaleX:u,scaleY:d,skewX:f,skewY:p,left:m,top:h,angle:g,width:_,height:v,cropX:y,cropY:b}=t,x={target:t,action:s,actionHandler:o,actionPerformed:!1,corner:i,scaleX:u,scaleY:d,skewX:f,skewY:p,offsetX:r.x-m,offsetY:r.y-h,originX:l.x,originY:l.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:Fo(g),width:_,height:v,shiftKey:e.shiftKey,altKey:c,original:{...Fs(t),originX:l.x,originY:l.y,cropX:y,cropY:b}};this._currentTransform=x,this.fire(`before:transform`,{e,transform:x})}setCursor(e){this.upperCanvasEl.style.cursor=e}_drawSelection(e){let{x:t,y:n,deltaX:r,deltaY:i}=this._groupSelector,a=new Q(t,n).transform(this.viewportTransform),o=new Q(t+r,n+i).transform(this.viewportTransform),s=this.selectionLineWidth/2,c=Math.min(a.x,o.x),l=Math.min(a.y,o.y),u=Math.max(a.x,o.x),d=Math.max(a.y,o.y);this.selectionColor&&(e.fillStyle=this.selectionColor,e.fillRect(c,l,u-c,d-l)),this.selectionLineWidth&&this.selectionBorderColor&&(e.lineWidth=this.selectionLineWidth,e.strokeStyle=this.selectionBorderColor,c+=s,l+=s,u-=s,d-=s,Ou.prototype._setLineDash.call(this,e,this.selectionDashArray),e.strokeRect(c,l,u-c,d-l))}findTarget(e){if(this._targetInfo)return this._targetInfo;if(this.skipTargetFind)return{subTargets:[],currentSubTargets:[]};let t=this.getScenePoint(e),n=this._activeObject,r=this.getActiveObjects(),i=this.searchPossibleTargets(this._objects,t),{subTargets:a,container:o,target:s}=i,c={...i,currentSubTargets:a,currentContainer:o,currentTarget:s};if(!n)return c;let l={...this.searchPossibleTargets([n],t),currentSubTargets:a,currentContainer:o,currentTarget:s};return n.findControl(this.getViewportPoint(e),Os(e))?{...l,target:n}:l.target&&(r.length>1||!this.preserveObjectStacking||this.preserveObjectStacking&&e[this.altSelectionKey])?l:c}_pointIsInObjectSelectionArea(e,t){let n=e.getCoords(),r=this.getZoom(),i=e.padding/r;if(i){let[e,t,r,a]=n,o=Math.atan2(t.y-e.y,t.x-e.x),s=yo(o)*i,c=bo(o)*i,l=s+c,u=s-c;n=[new Q(e.x-u,e.y-l),new Q(t.x+l,t.y-u),new Q(r.x+u,r.y+l),new Q(a.x-l,a.y+u)]}return Hl.isPointInPolygon(t,n)}_checkTarget(e,t){if(e&&e.visible&&e.evented&&this._pointIsInObjectSelectionArea(e,t)){if(!this.perPixelTargetFind&&!e.perPixelTargetFind||e.isEditing)return!0;{let n=t.transform(this.viewportTransform);if(!this.isTargetTransparent(e,n.x,n.y))return!0}}return!1}_searchPossibleTargets(e,t,n){let r=e.length;for(;r--;){let i=e[r];if(this._checkTarget(i,t)){if(So(i)&&i.subTargetCheck){let{target:e}=this._searchPossibleTargets(i._objects,t,n);e&&n.push(e)}return{target:i,subTargets:n}}}return{subTargets:[]}}searchPossibleTargets(e,t){let n=this._searchPossibleTargets(e,t,[]);n.container=n.target;let{container:r,subTargets:i}=n;if(r&&So(r)&&r.interactive&&i[0]){for(let e=i.length-1;e>0;e--){let t=i[e];if(!So(t)||!t.interactive)return n.target=t,n}return n.target=i[0],n}return n}getViewportPoint(e){return this._viewportPoint?this._viewportPoint:this._getPointerImpl(e,!0)}getScenePoint(e){return this._scenePoint?this._scenePoint:this._getPointerImpl(e)}_getPointerImpl(e,t=!1){let n=this.upperCanvasEl,r=n.getBoundingClientRect(),i=Ds(e),a=r.width||0,o=r.height||0;a&&o||(`top`in r&&`bottom`in r&&(o=Math.abs(r.top-r.bottom)),`right`in r&&`left`in r&&(a=Math.abs(r.right-r.left))),this.calcOffset(),i.x-=this._offset.left,i.y-=this._offset.top,t||(i=Rs(i,void 0,this.viewportTransform));let s=this.getRetinaScaling();s!==1&&(i.x/=s,i.y/=s);let c=a===0||o===0?new Q(1,1):new Q(n.width/a,n.height/o);return i.multiply(c)}_setDimensionsImpl(e,t){this._resetTransformEventData(),super._setDimensionsImpl(e,t),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ko(),this.pixelFindContext=this.pixelFindCanvasEl.getContext(`2d`,{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){let e=this._activeObject;return us(e)?e.getObjects():e?[e]:[]}_fireSelectionEvents(e,t){let n=!1,r=!1,i=this.getActiveObjects(),a=[],o=[];e.forEach(e=>{i.includes(e)||(n=!0,e.fire(`deselected`,{e:t,target:e}),o.push(e))}),i.forEach(r=>{e.includes(r)||(n=!0,r.fire(`selected`,{e:t,target:r}),a.push(r))}),e.length>0&&i.length>0?(r=!0,n&&this.fire(`selection:updated`,{e:t,selected:a,deselected:o})):i.length>0?(r=!0,this.fire(`selection:created`,{e:t,selected:a})):e.length>0&&(r=!0,this.fire(`selection:cleared`,{e:t,deselected:o})),r&&(this._objectsToRender=void 0)}setActiveObject(e,t){let n=this.getActiveObjects(),r=this._setActiveObject(e,t);return this._fireSelectionEvents(n,t),r}_setActiveObject(e,t){let n=this._activeObject;return n!==e&&!(!this._discardActiveObject(t,e)&&this._activeObject)&&!e.onSelect({e:t})&&(this._activeObject=e,us(e)&&n!==e&&e.set(`canvas`,this),e.setCoords(),!0)}_discardActiveObject(e,t){let n=this._activeObject;return!!n&&!n.onDeselect({e,object:t})&&(this._currentTransform&&this._currentTransform.target===n&&this.endCurrentTransform(e),us(n)&&n===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(e){let t=this.getActiveObjects(),n=this.getActiveObject();t.length&&this.fire(`before:selection:cleared`,{e,deselected:[n]});let r=this._discardActiveObject(e);return this._fireSelectionEvents(t,e),r}endCurrentTransform(e){let t=this._currentTransform;this._finalizeCurrentTransform(e),t&&t.target&&(t.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(e){let t=this._currentTransform,n=t.target,r={e,target:n,transform:t,action:t.action};n._scaling&&=!1,n.setCoords(),t.actionPerformed&&(this.fire(`object:modified`,r),n.fire(po,r))}setViewportTransform(e){super.setViewportTransform(e);let t=this._activeObject;t&&t.setCoords()}destroy(){let e=this._activeObject;us(e)&&(e.removeAll(),e.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(e){let t=this._activeObject;t&&t._renderControls(e)}_toObject(e,t,n){let r=this._realizeGroupTransformOnObject(e),i=super._toObject(e,t,n);return e.set(r),i}_realizeGroupTransformOnObject(e){let{group:t}=e;if(t&&us(t)&&this._activeObject===t){let n=rs(e,[`angle`,`flipX`,`flipY`,Ka,oo,so,co,lo,`top`]);return Ms(e,t.calcOwnMatrix()),n}return{}}_setSVGObject(e,t,n){let r=this._realizeGroupTransformOnObject(t);super._setSVGObject(e,t,n),t.set(r)}};Y(bf,`ownDefaults`,{uniformScaling:!0,uniScaleKey:`shiftKey`,centeredScaling:!1,centeredRotation:!1,centeredKey:`altKey`,altActionKey:`shiftKey`,selection:!0,selectionKey:`shiftKey`,selectionColor:`rgba(100, 100, 255, 0.3)`,selectionDashArray:[],selectionBorderColor:`rgba(255, 255, 255, 0.3)`,selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:`move`,moveCursor:`move`,defaultCursor:`default`,freeDrawingCursor:`crosshair`,notAllowedCursor:`not-allowed`,perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!0,fireRightClick:!0,fireMiddleClick:!0,enablePointerEvents:!1,containerClass:`canvas-container`,preserveObjectStacking:!0});var xf=class{constructor(e){Y(this,`targets`,[]),Y(this,`__disposer`,void 0);let t=()=>{let{hiddenTextarea:t}=e.getActiveObject()||{};t&&t.focus()},n=e.upperCanvasEl;n.addEventListener(`click`,t),this.__disposer=()=>n.removeEventListener(`click`,t)}exitTextEditing(){this.target=void 0,this.targets.forEach(e=>{e.isEditing&&e.exitEditing()})}add(e){this.targets.push(e)}remove(e){this.unregister(e),vo(this.targets,e)}register(e){this.target=e}unregister(e){e===this.target&&(this.target=void 0)}onMouseMove(e){var t;(t=this.target)!=null&&t.isEditing&&this.target.updateSelectionOnMouseMove(e)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}},Sf={passive:!1},Cf=(e,t)=>({viewportPoint:e.getViewportPoint(t),scenePoint:e.getScenePoint(t)}),wf=(e,...t)=>e.addEventListener(...t),Tf=(e,...t)=>e.removeEventListener(...t),Ef={mouse:{in:`over`,out:`out`,targetIn:`mouseover`,targetOut:`mouseout`,canvasIn:`mouse:over`,canvasOut:`mouse:out`},drag:{in:`enter`,out:`leave`,targetIn:`dragenter`,targetOut:`dragleave`,canvasIn:`drag:enter`,canvasOut:`drag:leave`}},Df=class extends bf{constructor(e,t={}){super(e,t),Y(this,`_isClick`,void 0),Y(this,`textEditingManager`,new xf(this)),[`_onMouseDown`,`_onTouchStart`,`_onMouseMove`,`_onMouseUp`,`_onTouchEnd`,`_onResize`,`_onMouseWheel`,`_onMouseOut`,`_onMouseEnter`,`_onContextMenu`,`_onClick`,`_onDragStart`,`_onDragEnd`,`_onDragProgress`,`_onDragOver`,`_onDragEnter`,`_onDragLeave`,`_onDrop`].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(wf)}_getEventPrefix(){return this.enablePointerEvents?`pointer`:`mouse`}addOrRemove(e,t=!1){let n=this.upperCanvasEl,r=this._getEventPrefix();e(ps(n),`resize`,this._onResize),e(n,r+`down`,this._onMouseDown),e(n,`${r}move`,this._onMouseMove,Sf),e(n,`${r}out`,this._onMouseOut),e(n,`${r}enter`,this._onMouseEnter),e(n,`wheel`,this._onMouseWheel,{passive:!1}),e(n,`contextmenu`,this._onContextMenu),t||(e(n,`click`,this._onClick),e(n,`dblclick`,this._onClick)),e(n,`dragstart`,this._onDragStart),e(n,`dragend`,this._onDragEnd),e(n,`dragover`,this._onDragOver),e(n,`dragenter`,this._onDragEnter),e(n,`dragleave`,this._onDragLeave),e(n,`drop`,this._onDrop),this.enablePointerEvents||e(n,`touchstart`,this._onTouchStart,Sf)}removeListeners(){this.addOrRemove(Tf);let e=this._getEventPrefix(),t=fs(this.upperCanvasEl);Tf(t,`${e}up`,this._onMouseUp),Tf(t,`touchend`,this._onTouchEnd,Sf),Tf(t,`${e}move`,this._onMouseMove,Sf),Tf(t,`touchmove`,this._onMouseMove,Sf),clearTimeout(this._willAddMouseDown)}_onMouseWheel(e){this._cacheTransformEventData(e),this._handleEvent(e,`wheel`),this._resetTransformEventData()}_onMouseOut(e){let t=this._hoveredTarget,n={e,...Cf(this,e)};this.fire(`mouse:out`,{...n,target:t}),this._hoveredTarget=void 0,t&&t.fire(`mouseout`,{...n}),this._hoveredTargets.forEach(e=>{this.fire(`mouse:out`,{...n,target:e}),e&&e.fire(`mouseout`,{...n})}),this._hoveredTargets=[]}_onMouseEnter(e){let{target:t}=this.findTarget(e);this._currentTransform||t||(this.fire(`mouse:over`,{e,...Cf(this,e)}),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(e){this._isClick=!1;let t=this.getActiveObject();if(t&&t.onDragStart(e)){this._dragSource=t;let n={e,target:t};this.fire(`dragstart`,n),t.fire(`dragstart`,n),wf(this.upperCanvasEl,`drag`,this._onDragProgress);return}ks(e)}_renderDragEffects(e,t,n){let r=!1,i=this._dropTarget;i&&i!==t&&i!==n&&(i.clearContextTop(),r=!0),t?.clearContextTop(),n!==t&&n?.clearContextTop();let a=this.contextTop;a.save(),a.transform(...this.viewportTransform),t&&(a.save(),t.transform(a),t.renderDragSourceEffect(e),a.restore(),r=!0),n&&(a.save(),n.transform(a),n.renderDropTargetEffect(e),a.restore(),r=!0),a.restore(),r&&(this.contextTopDirty=!0)}_onDragEnd(e){let{currentSubTargets:t}=this.findTarget(e),n=!!e.dataTransfer&&e.dataTransfer.dropEffect!==`none`,r=n?this._activeObject:void 0,i={e,target:this._dragSource,subTargets:t,dragSource:this._dragSource,didDrop:n,dropTarget:r};Tf(this.upperCanvasEl,`drag`,this._onDragProgress),this.fire(`dragend`,i),this._dragSource&&this._dragSource.fire(`dragend`,i),delete this._dragSource,this._onMouseUp(e)}_onDragProgress(e){let t={e,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire(`drag`,t),this._dragSource&&this._dragSource.fire(`drag`,t)}_onDragOver(e){let t=`dragover`,{currentContainer:n,currentSubTargets:r}=this.findTarget(e),i=this._dragSource,a={e,target:n,subTargets:r,dragSource:i,canDrop:!1,dropTarget:void 0},o;this.fire(t,a),this._fireEnterLeaveEvents(e,n,a),n&&(n.canDrop(e)&&(o=n),n.fire(t,a));for(let n=0;n<r.length;n++){let i=r[n];i.canDrop(e)&&(o=i),i.fire(t,a)}this._renderDragEffects(e,i,o),this._dropTarget=o}_onDragEnter(e){let{currentContainer:t,currentSubTargets:n}=this.findTarget(e),r={e,target:t,subTargets:n,dragSource:this._dragSource};this.fire(`dragenter`,r),this._fireEnterLeaveEvents(e,t,r)}_onDragLeave(e){let{currentSubTargets:t}=this.findTarget(e),n={e,target:this._draggedoverTarget,subTargets:t,dragSource:this._dragSource};this.fire(`dragleave`,n),this._fireEnterLeaveEvents(e,void 0,n),this._renderDragEffects(e,this._dragSource),this._dropTarget=void 0,this._hoveredTargets=[]}_onDrop(e){let{currentContainer:t,currentSubTargets:n}=this.findTarget(e),r=this._basicEventHandler(`drop:before`,{e,target:t,subTargets:n,dragSource:this._dragSource,...Cf(this,e)});r.didDrop=!1,r.dropTarget=void 0,this._basicEventHandler(`drop`,r),this.fire(`drop:after`,r)}_onContextMenu(e){let{target:t,subTargets:n}=this.findTarget(e),r=this._basicEventHandler(`contextmenu:before`,{e,target:t,subTargets:n});return this.stopContextMenu&&ks(e),this._basicEventHandler(`contextmenu`,r),!1}_onClick(e){let t=e.detail;t>3||t<2||(this._cacheTransformEventData(e),t==2&&e.type===`dblclick`&&this._handleEvent(e,`dblclick`),t==3&&this._handleEvent(e,`tripleclick`),this._resetTransformEventData())}fireEventFromPointerEvent(e,t,n,r={}){this._cacheTransformEventData(e);let{target:i,subTargets:a}=this.findTarget(e),o={e,target:i,subTargets:a,...Cf(this,e),transform:this._currentTransform,...r};this.fire(t,o),i&&i.fire(n,o);for(let e=0;e<a.length;e++)a[e]!==i&&a[e].fire(n,o);this._resetTransformEventData()}getPointerId(e){let t=e.changedTouches;return t?t[0]&&t[0].identifier:this.enablePointerEvents?e.pointerId:-1}_isMainEvent(e){return!0===e.isPrimary||!1!==e.isPrimary&&(e.type===`touchend`&&e.touches.length===0||!e.changedTouches||e.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(e){this._cacheTransformEventData(e);let t=!this.allowTouchScrolling,n=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(e)),this.__onMouseDown(e);let{target:r}=this.findTarget(e);(this.isDrawingMode||n&&r===n)&&(t=!0),t&&e.preventDefault();let i=this.upperCanvasEl,a=this._getEventPrefix(),o=fs(i);wf(o,`touchend`,this._onTouchEnd,Sf),t&&wf(o,`touchmove`,this._onMouseMove,Sf),Tf(i,`${a}down`,this._onMouseDown),this._resetTransformEventData()}_onMouseDown(e){this._cacheTransformEventData(e),this.__onMouseDown(e);let t=this.upperCanvasEl,n=this._getEventPrefix();Tf(t,`${n}move`,this._onMouseMove,Sf);let r=fs(t);wf(r,`${n}up`,this._onMouseUp),wf(r,`${n}move`,this._onMouseMove,Sf),this._resetTransformEventData()}_onTouchEnd(e){if(e.touches.length>0)return;this._cacheTransformEventData(e),this.__onMouseUp(e),this._resetTransformEventData(),delete this.mainTouchId;let t=this._getEventPrefix(),n=fs(this.upperCanvasEl);Tf(n,`touchend`,this._onTouchEnd,Sf),Tf(n,`touchmove`,this._onMouseMove,Sf),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{wf(this.upperCanvasEl,`${t}down`,this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(e){this._cacheTransformEventData(e),this.__onMouseUp(e);let t=this.upperCanvasEl,n=this._getEventPrefix();if(this._isMainEvent(e)){let e=fs(this.upperCanvasEl);Tf(e,`${n}up`,this._onMouseUp),Tf(e,`${n}move`,this._onMouseMove,Sf),wf(t,`${n}move`,this._onMouseMove,Sf)}this._resetTransformEventData()}_onMouseMove(e){this._cacheTransformEventData(e);let t=this.getActiveObject();!this.allowTouchScrolling&&(!t||!t.shouldStartDragging(e))&&e.preventDefault&&e.preventDefault(),this.__onMouseMove(e),this._resetTransformEventData()}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(e){let t=this.getActiveObject();return!!t!=!!e||t&&e&&t!==e}__onMouseUp(e){var t;this._handleEvent(e,`up:before`);let n=this._currentTransform,r=this._isClick,{target:i}=this.findTarget(e),{button:a}=e;if(a)return void((this.fireMiddleClick&&a===1||this.fireRightClick&&a===2)&&this._handleEvent(e,`up`));if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(e);if(!this._isMainEvent(e))return;let o,s,c=!1;if(n&&(this._finalizeCurrentTransform(e),c=n.actionPerformed),!r){let t=i===this._activeObject;this.handleSelection(e),c||=this._shouldRender(i)||!t&&i===this._activeObject}if(i){let{key:t,control:r}=i.findControl(this.getViewportPoint(e),Os(e))||{};if(s=t,i.selectable&&i!==this._activeObject&&i.activeOn===`up`)this.setActiveObject(i,e),c=!0;else if(r){let t=r.getMouseUpHandler(e,i,r);t&&(o=this.getScenePoint(e),t.call(r,e,n,o.x,o.y))}i.isMoving=!1}if(n&&(n.target!==i||n.corner!==s)){let t=n.target&&n.target.controls[n.corner],r=t&&t.getMouseUpHandler(e,n.target,t);o||=this.getScenePoint(e),r&&r.call(t,e,n,o.x,o.y)}this._setCursorFromEvent(e,i),this._handleEvent(e,`up`),this._groupSelector=null,this._currentTransform=null,i&&(i.__corner=void 0),c?this.requestRenderAll():r||(t=this._activeObject)!=null&&t.isEditing||this.renderTop()}_basicEventHandler(e,t){let{target:n,subTargets:r=[]}=t;this.fire(e,t),n&&n.fire(e,t);for(let i=0;i<r.length;i++)r[i]!==n&&r[i].fire(e,t);return t}_handleEvent(e,t,n){let{target:r,subTargets:i}=this.findTarget(e),a={e,target:r,subTargets:i,...Cf(this,e),transform:this._currentTransform,...t===`down:before`||t===`down`?n:{}};t!==`up:before`&&t!==`up`||(a.isClick=this._isClick),this.fire(`mouse:${t}`,a),r&&r.fire(`mouse${t}`,a);for(let e=0;e<i.length;e++)i[e]!==r&&i[e].fire(`mouse${t}`,a)}_onMouseDownInDrawingMode(e){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(e),this.requestRenderAll());let t=this.getScenePoint(e);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(t,{e,pointer:t}),this._handleEvent(e,`down`,{alreadySelected:!1})}_onMouseMoveInDrawingMode(e){if(this._isCurrentlyDrawing){let t=this.getScenePoint(e);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(t,{e,pointer:t})}this.setCursor(this.freeDrawingCursor),this._handleEvent(e,`move`)}_onMouseUpInDrawingMode(e){let t=this.getScenePoint(e);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e,pointer:t}):this._isCurrentlyDrawing=!1,this._handleEvent(e,`up`)}__onMouseDown(e){this._isClick=!0,this._handleEvent(e,`down:before`);let{target:t}=this.findTarget(e),n=!!t&&t===this._activeObject,{button:r}=e;if(r)return void((this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(e,`down`,{alreadySelected:n}));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(e);if(!this._isMainEvent(e)||this._currentTransform)return;let i=this._shouldRender(t),a=!1;if(this.handleMultiSelection(e,t)?(t=this._activeObject,a=!0,i=!0):this._shouldClearSelection(e,t)&&this.discardActiveObject(e),this.selection&&(!t||!t.selectable&&!t.isEditing&&t!==this._activeObject)){let t=this.getScenePoint(e);this._groupSelector={x:t.x,y:t.y,deltaY:0,deltaX:0}}if(n=!!t&&t===this._activeObject,t){t.selectable&&t.activeOn===`down`&&this.setActiveObject(t,e);let r=t.findControl(this.getViewportPoint(e),Os(e));if(t===this._activeObject&&(r||!a)){this._setupCurrentTransform(e,t,n);let i=r?r.control:void 0,a=this.getScenePoint(e),o=i&&i.getMouseDownHandler(e,t,i);o&&o.call(i,e,this._currentTransform,a.x,a.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(e,`down`,{alreadySelected:n}),i&&this.requestRenderAll()}_resetTransformEventData(){this._targetInfo=this._viewportPoint=this._scenePoint=void 0}_cacheTransformEventData(e){this._resetTransformEventData(),this._viewportPoint=this.getViewportPoint(e),this._scenePoint=Rs(this._viewportPoint,void 0,this.viewportTransform),this._targetInfo=this.findTarget(e),this._currentTransform&&(this._targetInfo.target=this._currentTransform.target)}__onMouseMove(e){if(this._isClick=!1,this._handleEvent(e,`move:before`),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(e);if(!this._isMainEvent(e))return;let t=this._groupSelector;if(t){let n=this.getScenePoint(e);t.deltaX=n.x-t.x,t.deltaY=n.y-t.y,this.renderTop()}else if(this._currentTransform)this._transformObject(e);else{let{target:t}=this.findTarget(e);this._setCursorFromEvent(e,t),this._fireOverOutEvents(e,t)}this.textEditingManager.onMouseMove(e),this._handleEvent(e,`move`)}_fireOverOutEvents(e,t){let{_hoveredTarget:n,_hoveredTargets:r}=this,{subTargets:i,currentTarget:a}=this.findTarget(e),o=Math.max(r.length,i.length);this.fireSyntheticInOutEvents(`mouse`,{e,target:t,oldTarget:n,actualTarget:a,oldActualTarget:this._hoveredActualTarget,fireCanvas:!0});for(let a=0;a<o;a++)i[a]===t||r[a]&&r[a]===n||this.fireSyntheticInOutEvents(`mouse`,{e,target:i[a],oldTarget:r[a]});this._hoveredActualTarget=a,this._hoveredTarget=t,this._hoveredTargets=i}_fireEnterLeaveEvents(e,t,n){let r=this._draggedoverTarget,i=this._hoveredTargets,{subTargets:a}=this.findTarget(e),o=Math.max(i.length,a.length);this.fireSyntheticInOutEvents(`drag`,{...n,target:t,oldTarget:r,fireCanvas:!0});for(let e=0;e<o;e++)this.fireSyntheticInOutEvents(`drag`,{...n,target:a[e],oldTarget:i[e]});this._draggedoverTarget=t}fireSyntheticInOutEvents(e,{target:t,oldTarget:n,actualTarget:r,oldActualTarget:i,fireCanvas:a,e:o,...s}){let{targetIn:c,targetOut:l,canvasIn:u,canvasOut:d}=Ef[e],f=n!==t,p=i!==r,m=t&&f,h=r&&p,g=n&&f,_=i&&p,v={...s,e:o,...Cf(this,o)},y={...v,target:n,nextTarget:t,actualTarget:i,nextActualTarget:r};(g||_)&&a&&this.fire(d,y),g&&n.fire(l,y),_&&n!==i&&i.fire(l,y);let b={...v,target:t,previousTarget:n,actualTarget:r,previousActualTarget:i};(m||h)&&a&&this.fire(u,b),m&&t.fire(c,b),h&&r!==t&&r.fire(c,b)}_transformObject(e){let t=this.getScenePoint(e),n=this._currentTransform,r=n.target,i=r.group?Rs(t,void 0,r.group.calcTransformMatrix()):t;n.shiftKey=e.shiftKey,n.altKey=!!this.centeredKey&&e[this.centeredKey],this._performTransformAction(e,n,i),n.actionPerformed&&this.requestRenderAll()}_performTransformAction(e,t,n){let{action:r,actionHandler:i,target:a}=t,o=!!i&&i(e,t,n.x,n.y);o&&a.setCoords(),r===`drag`&&o&&(t.target.isMoving=!0,this.setCursor(t.target.moveCursor||this.moveCursor)),t.actionPerformed=t.actionPerformed||o}_setCursorFromEvent(e,t){if(!t)return void this.setCursor(this.defaultCursor);let n=t.hoverCursor||this.hoverCursor,r=us(this._activeObject)?this._activeObject:null,i=(!r||t.group!==r)&&t.findControl(this.getViewportPoint(e));if(i){let{control:n,coord:r}=i;this.setCursor(n.cursorStyleHandler(e,n,t,r))}else{if(t.subTargetCheck){let{subTargets:t}=this.findTarget(e);t.concat().reverse().forEach(e=>{n=e.hoverCursor||n})}this.setCursor(n)}}handleMultiSelection(e,t){let n=this._activeObject,r=us(n);if(n&&this._isSelectionKeyPressed(e)&&this.selection&&t&&t.selectable&&(n!==t||r)&&(r||!t.isDescendantOf(n)&&!n.isDescendantOf(t))&&!t.onSelect({e})&&!n.getActiveControl()){if(r){let r=n.getObjects(),i=[];if(t===n){let n=this.getScenePoint(e),a=this.searchPossibleTargets(r,n);if(a.target?(t=a.target,i=a.subTargets):(a=this.searchPossibleTargets(this._objects,n),t=a.target,i=a.subTargets),!t||!t.selectable)return!1}t.group===n?(n.remove(t),this._hoveredTarget=t,this._hoveredTargets=i,n.size()===1&&this._setActiveObject(n.item(0),e)):(n.multiSelectAdd(t),this._hoveredTarget=n,this._hoveredTargets=i),this._fireSelectionEvents(r,e)}else{n.isEditing&&n.exitEditing();let r=new(Z.getClass(`ActiveSelection`))([],{canvas:this});r.multiSelectAdd(n,t),this._hoveredTarget=r,this._setActiveObject(r,e),this._fireSelectionEvents([n],e)}return!0}return!1}handleSelection(e){if(!this.selection||!this._groupSelector)return!1;let{x:t,y:n,deltaX:r,deltaY:i}=this._groupSelector,a=new Q(t,n),o=a.add(new Q(r,i)),s=a.min(o),c=a.max(o).subtract(s),l=this.collectObjects({left:s.x,top:s.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),u=a.eq(o)?l[0]?[l[0]]:[]:l.length>1?l.filter(t=>!t.onSelect({e})).reverse():l;if(u.length===1)this.setActiveObject(u[0],e);else if(u.length>1){let t=Z.getClass(`ActiveSelection`);this.setActiveObject(new t(u,{canvas:this}),e)}return this._groupSelector=null,!0}toCanvasElement(e=1,t){let{upper:n}=this.elements;n.ctx=void 0;let r=super.toCanvasElement(e,t);return n.ctx=n.el.getContext(`2d`),r}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}},Of={x1:0,y1:0,x2:0,y2:0},kf={...Of,r1:0,r2:0},Af=(e,t)=>isNaN(e)&&typeof t==`number`?t:e;function jf(e){return e&&/%$/.test(e)&&Number.isFinite(parseFloat(e))}function Mf(e,t){return Yc(0,Af(typeof e==`number`?e:typeof e==`string`?parseFloat(e)/(jf(e)?100:1):NaN,t),1)}var Nf=/\s*;\s*/,Pf=/\s*:\s*/;function Ff(e,t){let n,r,i=e.getAttribute(`style`);if(i){let e=i.split(Nf);e[e.length-1]===``&&e.pop();for(let t=e.length;t--;){let[i,a]=e[t].split(Pf).map(e=>e.trim());i===`stop-color`?n=a:i===`stop-opacity`&&(r=a)}}n=n||e.getAttribute(`stop-color`)||`rgb(0,0,0)`,r=Af(parseFloat(r||e.getAttribute(`stop-opacity`)||``),1);let a=new yc(n);return a.setAlpha(a.getAlpha()*r*t),{offset:Mf(e.getAttribute(`offset`),0),color:a.toRgba()}}function If(e,t){let n=[],r=e.getElementsByTagName(`stop`),i=Mf(t,1);for(let e=r.length;e--;)n.push(Ff(r[e],i));return n}function Lf(e){return e.nodeName===`linearGradient`||e.nodeName===`LINEARGRADIENT`?`linear`:`radial`}function Rf(e){return e.getAttribute(`gradientUnits`)===`userSpaceOnUse`?`pixels`:`percentage`}function zf(e,t){return e.getAttribute(t)}function Bf(e,t){return function(e,{width:t,height:n,gradientUnits:r}){let i;return Object.entries(e).reduce((e,[a,o])=>{if(o===`Infinity`)i=1;else if(o===`-Infinity`)i=0;else{let e=typeof o==`string`;i=e?parseFloat(o):o,e&&jf(o)&&(i*=.01,r===`pixels`&&(a!==`x1`&&a!==`x2`&&a!==`r2`||(i*=t),a!==`y1`&&a!==`y2`||(i*=n)))}return e[a]=i,e},{})}(Lf(e)===`linear`?function(e){return{x1:zf(e,`x1`)||0,y1:zf(e,`y1`)||0,x2:zf(e,`x2`)||`100%`,y2:zf(e,`y2`)||0}}(e):function(e){return{x1:zf(e,`fx`)||zf(e,`cx`)||`50%`,y1:zf(e,`fy`)||zf(e,`cy`)||`50%`,r1:0,x2:zf(e,`cx`)||`50%`,y2:zf(e,`cy`)||`50%`,r2:zf(e,`r`)||`50%`}}(e),{...t,gradientUnits:Rf(e)})}var Vf=class{constructor(e){let{type:t=`linear`,gradientUnits:n=`pixels`,coords:r={},colorStops:i=[],offsetX:a=0,offsetY:o=0,gradientTransform:s,id:c}=e||{};Object.assign(this,{type:t,gradientUnits:n,coords:{...t===`radial`?kf:Of,...r},colorStops:i,offsetX:a,offsetY:o,gradientTransform:s,id:c?`${c}_${Oo()}`:Oo()})}addColorStop(e){for(let t in e)this.colorStops.push({offset:parseFloat(t),color:e[t]});return this}toObject(e){return{...rs(this,e),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map(e=>({...e})),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(e,{additionalTransform:t}={}){let n=[],r=this.gradientTransform?this.gradientTransform.concat():Wa.concat(),i=this.gradientUnits===`pixels`?`userSpaceOnUse`:`objectBoundingBox`,a=this.colorStops.map(e=>({...e})).sort((e,t)=>e.offset-t.offset),o=-this.offsetX,s=-this.offsetY;var c;i===`objectBoundingBox`?(o/=e.width,s/=e.height):(o+=e.width/2,s+=e.height/2),(c=e)&&typeof c._renderPathCommands==`function`&&this.gradientUnits!==`percentage`&&(o-=e.pathOffset.x,s-=e.pathOffset.y),r[4]-=o,r[5]-=s;let l=[`id="SVGID_${$(String(this.id))}"`,`gradientUnits="${i}"`,`gradientTransform="${t?t+` `:``}${os(r)}"`,``].join(` `),u=e=>parseFloat(String(e));if(this.type===`linear`){let{x1:e,y1:t,x2:r,y2:i}=this.coords,a=u(e),o=u(t),s=u(r),c=u(i);n.push(`<linearGradient `,l,` x1="`,a,`" y1="`,o,`" x2="`,s,`" y2="`,c,`">
|
|
18
|
+
`)}else if(this.type===`radial`){let{x1:e,y1:t,x2:r,y2:i,r1:o,r2:s}=this.coords,c=u(e),d=u(t),f=u(r),p=u(i),m=u(o),h=u(s),g=m>h;n.push(`<radialGradient `,l,` cx="`,g?c:f,`" cy="`,g?d:p,`" r="`,g?m:h,`" fx="`,g?f:c,`" fy="`,g?p:d,`">
|
|
19
|
+
`),g&&(a.reverse(),a.forEach(e=>{e.offset=1-e.offset}));let _=Math.min(m,h);if(_>0){let e=_/Math.max(m,h);a.forEach(t=>{t.offset+=e*(1-t.offset)})}}return a.forEach(({color:e,offset:t})=>{let r=String(e),i=lc(r)?r:new yc(r).toRgba();n.push(`<stop offset="${100*t}%" style="stop-color:${$(i)};"/>\n`)}),n.push(this.type===`linear`?`</linearGradient>`:`</radialGradient>`,`
|
|
20
|
+
`),n.join(``)}toLive(e){let{x1:t,y1:n,x2:r,y2:i,r1:a,r2:o}=this.coords,s=this.type===`linear`?e.createLinearGradient(t,n,r,i):e.createRadialGradient(t,n,a,r,i,o);return this.colorStops.forEach(({color:e,offset:t})=>{s.addColorStop(t,e)}),s}static async fromObject(e){let{colorStops:t,gradientTransform:n}=e;return new this({...e,colorStops:t?t.map(e=>({...e})):void 0,gradientTransform:n?[...n]:void 0})}static fromElement(e,t,n){let r=Rf(e),i=t._findCenterFromElement();return new this({id:e.getAttribute(`id`)||void 0,type:Lf(e),coords:Bf(e,{width:n.viewBoxWidth||n.width,height:n.viewBoxHeight||n.height}),colorStops:If(e,n.opacity),gradientUnits:r,gradientTransform:rd(e.getAttribute(`gradientTransform`)||``),...r===`pixels`?{offsetX:t.width/2-i.x,offsetY:t.height/2-i.y}:{offsetX:0,offsetY:0}})}};Y(Vf,`type`,`Gradient`),Z.setClass(Vf,`gradient`),Z.setClass(Vf,`linear`),Z.setClass(Vf,`radial`);var Hf=class{get type(){return`pattern`}set type(e){Ea(`warn`,`Setting type has no effect`,e)}constructor(e){Y(this,`repeat`,`repeat`),Y(this,`offsetX`,0),Y(this,`offsetY`,0),Y(this,`crossOrigin`,``),this.id=Oo(),Object.assign(this,e)}isImageSource(){return!!this.source&&typeof this.source.src==`string`}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():``}toLive(e){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?e.createPattern(this.source,this.repeat):null}toObject(e=[]){let{repeat:t,crossOrigin:n}=this;return{...rs(this,e),type:`pattern`,source:this.sourceToString(),repeat:t,crossOrigin:n,offsetX:as(this.offsetX,X.NUM_FRACTION_DIGITS),offsetY:as(this.offsetY,X.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null}}toSVG({width:e,height:t}){let{source:n,repeat:r,id:i}=this,a=Af(this.offsetX/e,0),o=Af(this.offsetY/t,0),s=r===`repeat-y`||r===`no-repeat`?1+Math.abs(a||0):Af(n.width/e,0),c=r===`repeat-x`||r===`no-repeat`?1+Math.abs(o||0):Af(n.height/t,0);return[`<pattern id="SVGID_${$(i)}" x="${a}" y="${o}" width="${s}" height="${c}">`,`<image x="0" y="0" width="${n.width}" height="${n.height}" xlink:href="${$(this.sourceToString())}"></image>`,`</pattern>`,``].join(`
|
|
21
|
+
`)}static async fromObject({type:e,source:t,patternTransform:n,...r},i){let a=await es(t,{...i,crossOrigin:r.crossOrigin});return new this({...r,patternTransform:n&&n.slice(0),source:a})}};Y(Hf,`type`,`Pattern`),Z.setClass(Hf),Z.setClass(Hf,`pattern`);var Uf=class e extends Ou{constructor(t,{path:n,left:r,top:i,...a}={}){super(),Object.assign(this,e.ownDefaults),this.setOptions(a),this._setPath(t||[],!0),typeof r==`number`&&this.set(`left`,r),typeof i==`number`&&this.set(`top`,i)}_setPath(e,t){this.path=jd(Array.isArray(e)?e:Jd(e)),this.setBoundingBox(t)}_findCenterFromElement(){let e=this._calcBoundsFromPath();return new Q(e.left+e.width/2,e.top+e.height/2)}_renderPathCommands(e){let t=-this.pathOffset.x,n=-this.pathOffset.y;e.beginPath();for(let r of this.path)switch(r[0]){case`L`:e.lineTo(r[1]+t,r[2]+n);break;case`M`:e.moveTo(r[1]+t,r[2]+n);break;case`C`:e.bezierCurveTo(r[1]+t,r[2]+n,r[3]+t,r[4]+n,r[5]+t,r[6]+n);break;case`Q`:e.quadraticCurveTo(r[1]+t,r[2]+n,r[3]+t,r[4]+n);break;case`Z`:e.closePath()}}_render(e){this._renderPathCommands(e),this._renderPaintInOrder(e)}toString(){return`#<Path (${this.complexity()}): { "top": ${this.top}, "left": ${this.left} }>`}toObject(e=[]){return{...super.toObject(e),path:this.path.map(e=>e.slice())}}toDatalessObject(e=[]){let t=this.toObject(e);return this.sourcePath&&(delete t.path,t.sourcePath=this.sourcePath),t}_toSVG(){return[`<path `,`COMMON_PARTS`,`d="${Qd(this.path,X.NUM_FRACTION_DIGITS)}" stroke-linecap="round" />\n`]}_getOffsetTransform(){let e=X.NUM_FRACTION_DIGITS;return` translate(${as(-this.pathOffset.x,e)}, ${as(-this.pathOffset.y,e)})`}toClipPathSVG(e){let t=this._getOffsetTransform();return` `+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:e,additionalTransform:t})}toSVG(e){let t=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:e,additionalTransform:t})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(e){let{width:t,height:n,pathOffset:r}=this._calcDimensions();this.set({width:t,height:n,pathOffset:r}),e&&this.setPositionByOrigin(r,`center`,`center`)}_calcBoundsFromPath(){let e=[],t=0,n=0,r=0,i=0;for(let a of this.path)switch(a[0]){case`L`:r=a[1],i=a[2],e.push({x:t,y:n},{x:r,y:i});break;case`M`:r=a[1],i=a[2],t=r,n=i;break;case`C`:e.push(...kd(r,i,a[1],a[2],a[3],a[4],a[5],a[6])),r=a[5],i=a[6];break;case`Q`:e.push(...kd(r,i,a[1],a[2],a[1],a[2],a[3],a[4])),r=a[3],i=a[4];break;case`Z`:r=t,i=n}return As(e)}_calcDimensions(){let e=this._calcBoundsFromPath();return{...e,pathOffset:new Q(e.left+e.width/2,e.top+e.height/2)}}static fromObject(e){return this._fromObject(e,{extraParam:`path`})}static async fromElement(e,t,n){let{d:r,...i}=cd(e,this.ATTRIBUTE_NAMES,n);return new this(r,{...i,...t,left:void 0,top:void 0})}};Y(Uf,`type`,`Path`),Y(Uf,`cacheProperties`,[...Zc,`path`,`fillRule`]),Y(Uf,`ATTRIBUTE_NAMES`,[...zu,`d`]),Z.setClass(Uf),Z.setSVGClass(Uf);var Wf=[`radius`,`startAngle`,`endAngle`,`counterClockwise`],Gf=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,e.ownDefaults),this.setOptions(t)}_set(e,t){return super._set(e,t),e===`radius`&&this.setRadius(t),this}_render(e){e.beginPath(),e.arc(0,0,this.radius,Fo(this.startAngle),Fo(this.endAngle),this.counterClockwise),this._renderPaintInOrder(e)}getRadiusX(){return this.get(`radius`)*this.get(oo)}getRadiusY(){return this.get(`radius`)*this.get(so)}setRadius(e){this.radius=e,this.set({width:2*e,height:2*e})}toObject(e=[]){return super.toObject([...Wf,...e])}_toSVG(){let{radius:e,startAngle:t,endAngle:n}=this,r=(n-t)%360;if(r===0)return[`<circle `,`COMMON_PARTS`,`cx="0" cy="0" `,`r="`,`${$(e)}`,`" />
|
|
22
|
+
`];{let i=Fo(t),a=Fo(n),o=yo(i)*e,s=bo(i)*e,c=yo(a)*e,l=bo(a)*e;return[`<path d="M ${o} ${s} A ${e} ${e} 0 ${+(r>180)} ${+!this.counterClockwise} ${c} ${l}" `,`COMMON_PARTS`,` />
|
|
23
|
+
`]}}static async fromElement(e,t,n){let{left:r=0,top:i=0,radius:a=0,...o}=cd(e,this.ATTRIBUTE_NAMES,n);return new this({...o,radius:a,left:r-a,top:i-a})}static fromObject(e){return super._fromObject(e)}};Y(Gf,`type`,`Circle`),Y(Gf,`cacheProperties`,[...Zc,...Wf]),Y(Gf,`ownDefaults`,{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),Y(Gf,`ATTRIBUTE_NAMES`,[`cx`,`cy`,`r`,...zu]),Z.setClass(Gf),Z.setSVGClass(Gf);var Kf=[`x1`,`x2`,`y1`,`y2`],qf=class e extends Ou{constructor([t,n,r,i]=[0,0,0,0],a={}){super(),Object.assign(this,e.ownDefaults),this.setOptions(a),this.x1=t,this.x2=r,this.y1=n,this.y2=i,this._setWidthHeight();let{left:o,top:s}=a;typeof o==`number`&&this.set(`left`,o),typeof s==`number`&&this.set(`top`,s)}_setWidthHeight(){let{x1:e,y1:t,x2:n,y2:r}=this;this.width=Math.abs(n-e),this.height=Math.abs(r-t);let{left:i,top:a,width:o,height:s}=As([{x:e,y:t},{x:n,y:r}]),c=new Q(i+o/2,a+s/2);this.setPositionByOrigin(c,Ga,Ga)}_set(e,t){return super._set(e,t),Kf.includes(e)&&this._setWidthHeight(),this}_render(e){e.beginPath();let t=this.calcLinePoints();e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.lineWidth=this.strokeWidth;let n=e.strokeStyle;ss(this.stroke)?e.strokeStyle=this.stroke.toLive(e):e.strokeStyle=this.stroke??e.fillStyle,this.stroke&&this._renderStroke(e),e.strokeStyle=n}_findCenterFromElement(){return new Q((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(e=[]){return{...super.toObject(e),...this.calcLinePoints()}}_getNonTransformedDimensions(){let e=super._getNonTransformedDimensions();return this.strokeLineCap===`butt`&&(this.width===0&&(e.y-=this.strokeWidth),this.height===0&&(e.x-=this.strokeWidth)),e}calcLinePoints(){let{x1:e,x2:t,y1:n,y2:r,width:i,height:a}=this,o=e<=t?-.5:.5,s=n<=r?-.5:.5;return{x1:o*i,x2:o*-i,y1:s*a,y2:s*-a}}_toSVG(){let{x1:e,x2:t,y1:n,y2:r}=this.calcLinePoints();return[`<line `,`COMMON_PARTS`,`x1="${e}" y1="${n}" x2="${t}" y2="${r}" />\n`]}static async fromElement(e,t,n){let{x1:r=0,y1:i=0,x2:a=0,y2:o=0,...s}=cd(e,this.ATTRIBUTE_NAMES,n);return new this([r,i,a,o],s)}static fromObject({x1:e,y1:t,x2:n,y2:r,...i}){return this._fromObject({...i,points:[e,t,n,r]},{extraParam:`points`})}};Y(qf,`type`,`Line`),Y(qf,`cacheProperties`,[...Zc,...Kf]),Y(qf,`ATTRIBUTE_NAMES`,zu.concat(Kf)),Z.setClass(qf),Z.setSVGClass(qf);var Jf=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,e.ownDefaults),this.setOptions(t)}_render(e){let t=this.width/2,n=this.height/2;e.beginPath(),e.moveTo(-t,n),e.lineTo(0,-n),e.lineTo(t,n),e.closePath(),this._renderPaintInOrder(e)}_toSVG(){let e=this.width/2,t=this.height/2;return[`<polygon `,`COMMON_PARTS`,`points="`,`${-e} ${t},0 ${-t},${e} ${t}`,`" />`]}};Y(Jf,`type`,`Triangle`),Y(Jf,`ownDefaults`,{width:100,height:100}),Z.setClass(Jf),Z.setSVGClass(Jf);var Yf=[`rx`,`ry`],Xf=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,e.ownDefaults),this.setOptions(t)}_set(e,t){switch(super._set(e,t),e){case`rx`:this.rx=t,this.set(`width`,2*t);break;case`ry`:this.ry=t,this.set(`height`,2*t)}return this}getRx(){return this.get(`rx`)*this.get(oo)}getRy(){return this.get(`ry`)*this.get(so)}toObject(e=[]){return super.toObject([...Yf,...e])}_toSVG(){return[`<ellipse `,`COMMON_PARTS`,`cx="0" cy="0" rx="${$(this.rx)}" ry="${$(this.ry)}" />\n`]}_render(e){e.beginPath(),e.save(),e.transform(1,0,0,this.ry/this.rx,0,0),e.arc(0,0,this.rx,0,Ha,!1),e.restore(),this._renderPaintInOrder(e)}static async fromElement(e,t,n){let r=cd(e,this.ATTRIBUTE_NAMES,n);return r.left=(r.left||0)-r.rx,r.top=(r.top||0)-r.ry,new this(r)}};Y(Xf,`type`,`Ellipse`),Y(Xf,`cacheProperties`,[...Zc,...Yf]),Y(Xf,`ownDefaults`,{rx:0,ry:0}),Y(Xf,`ATTRIBUTE_NAMES`,[...zu,`cx`,`cy`,`rx`,`ry`]),Z.setClass(Xf),Z.setSVGClass(Xf);var Zf={exactBoundingBox:!1},Qf=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t=[],n={}){super(),Y(this,`strokeDiff`,void 0),Object.assign(this,e.ownDefaults),this.setOptions(n),this.points=t;let{left:r,top:i}=n;this.initialized=!0,this.setBoundingBox(!0),typeof r==`number`&&this.set(`left`,r),typeof i==`number`&&this.set(`top`,i)}isOpen(){return!0}_projectStrokeOnPoints(e){return Pu(this.points,e,this.isOpen())}_calcDimensions(e){e={scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth,...e||{}};let t=this.exactBoundingBox?this._projectStrokeOnPoints(e).map(e=>e.projectedPoint):this.points;if(t.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new Q,strokeOffset:new Q,strokeDiff:new Q};let n=As(t),r=Qo({...e,scaleX:1,scaleY:1}),i=As(this.points.map(e=>Ro(e,r,!0))),a=new Q(this.scaleX,this.scaleY),o=n.left+n.width/2,s=n.top+n.height/2;return this.exactBoundingBox&&(o-=s*Math.tan(Fo(this.skewX)),s-=o*Math.tan(Fo(this.skewY))),{...n,pathOffset:new Q(o,s),strokeOffset:new Q(i.left,i.top).subtract(new Q(n.left,n.top)).multiply(a),strokeDiff:new Q(n.width,n.height).subtract(new Q(i.width,i.height)).multiply(a)}}_findCenterFromElement(){let e=As(this.points);return new Q(e.left+e.width/2,e.top+e.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(e){let{left:t,top:n,width:r,height:i,pathOffset:a,strokeOffset:o,strokeDiff:s}=this._calcDimensions();this.set({width:r,height:i,pathOffset:a,strokeOffset:o,strokeDiff:s}),e&&this.setPositionByOrigin(new Q(t+r/2,n+i/2),`center`,`center`)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new Q(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(e={}){if(this.exactBoundingBox){let t;if(Object.keys(e).some(e=>this.strokeUniform||this.constructor.layoutProperties.includes(e))){let{width:n,height:r}=this._calcDimensions(e);t=new Q(e.width??n,e.height??r)}else t=new Q(e.width??this.width,e.height??this.height);return t.multiply(new Q(e.scaleX||this.scaleX,e.scaleY||this.scaleY))}return super._getTransformedDimensions(e)}_set(e,t){let n=this.initialized&&this[e]!==t,r=super._set(e,t);return this.exactBoundingBox&&n&&((e===`scaleX`||e===`scaleY`)&&this.strokeUniform&&this.constructor.layoutProperties.includes(`strokeUniform`)||this.constructor.layoutProperties.includes(e))&&this.setDimensions(),r}toObject(e=[]){return{...super.toObject(e),points:this.points.map(({x:e,y:t})=>({x:e,y:t}))}}_toSVG(){let e=this.pathOffset.x,t=this.pathOffset.y,n=X.NUM_FRACTION_DIGITS,r=this.points.map(({x:r,y:i})=>`${as(r-e,n)},${as(i-t,n)}`).join(` `);return[`<${$(this.constructor.type).toLowerCase()} `,`COMMON_PARTS`,`points="${r}" />\n`]}_render(e){let t=this.points.length,n=this.pathOffset.x,r=this.pathOffset.y;if(t&&!isNaN(this.points[t-1].y)){e.beginPath(),e.moveTo(this.points[0].x-n,this.points[0].y-r);for(let i=0;i<t;i++){let t=this.points[i];e.lineTo(t.x-n,t.y-r)}!this.isOpen()&&e.closePath(),this._renderPaintInOrder(e)}}complexity(){return this.points.length}static async fromElement(e,t,n){let r=function(e){if(!e)return[];let t=e.replace(/,/g,` `).trim().split(/\s+/),n=[];for(let e=0;e<t.length;e+=2)n.push({x:parseFloat(t[e]),y:parseFloat(t[e+1])});return n}(e.getAttribute(`points`)),{left:i,top:a,...o}=cd(e,this.ATTRIBUTE_NAMES,n);return new this(r,{...o,...t})}static fromObject(e){return this._fromObject(e,{extraParam:`points`})}};Y(Qf,`ownDefaults`,Zf),Y(Qf,`type`,`Polyline`),Y(Qf,`layoutProperties`,[co,lo,`strokeLineCap`,`strokeLineJoin`,`strokeMiterLimit`,`strokeWidth`,`strokeUniform`,`points`]),Y(Qf,`cacheProperties`,[...Zc,`points`]),Y(Qf,`ATTRIBUTE_NAMES`,[...zu]),Z.setClass(Qf),Z.setSVGClass(Qf);var $f=class extends Qf{isOpen(){return!1}};Y($f,`ownDefaults`,Zf),Y($f,`type`,`Polygon`),Z.setClass($f),Z.setSVGClass($f);var ep=class extends Ou{isEmptyStyles(e){if(!this.styles||e!==void 0&&!this.styles[e])return!0;let t=e===void 0?this.styles:{line:this.styles[e]};for(let e in t)for(let n in t[e])for(let r in t[e][n])return!1;return!0}styleHas(e,t){if(!this.styles||t!==void 0&&!this.styles[t])return!1;let n=t===void 0?this.styles:{0:this.styles[t]};for(let t in n)for(let r in n[t])if(n[t][r][e]!==void 0)return!0;return!1}cleanStyle(e){if(!this.styles)return!1;let t=this.styles,n,r,i=0,a=!0,o=0;for(let o in t){n=0;for(let s in t[o]){let c=t[o][s]||{};i++,c[e]===void 0?a=!1:(r?c[e]!==r&&(a=!1):r=c[e],c[e]===this[e]&&delete c[e]),Object.keys(c).length===0?delete t[o][s]:n++}n===0&&delete t[o]}for(let e=0;e<this._textLines.length;e++)o+=this._textLines[e].length;a&&i===o&&(this[e]=r,this.removeStyle(e))}removeStyle(e){if(!this.styles)return;let t=this.styles,n,r,i;for(r in t){for(i in n=t[r],n)delete n[i][e],Object.keys(n[i]).length===0&&delete n[i];Object.keys(n).length===0&&delete t[r]}}_extendStyles(e,t){let{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e);this._getLineStyle(n)||this._setLineStyle(n);let i=is({...this._getStyleDeclaration(n,r),...t},e=>e!==void 0);this._setStyleDeclaration(n,r,i)}getSelectionStyles(e,t,n){let r=[];for(let i=e;i<(t||e);i++)r.push(this.getStyleAtPosition(i,n));return r}getStyleAtPosition(e,t){let{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e);return t?this.getCompleteStyleDeclaration(n,r):this._getStyleDeclaration(n,r)}setSelectionStyles(e,t,n){for(let r=t;r<(n||t);r++)this._extendStyles(r,e);this._forceClearCache=!0}_getStyleDeclaration(e,t){var n;let r=this.styles&&this.styles[e];return r&&(n=r[t])!=null?n:{}}getCompleteStyleDeclaration(e,t){return{...rs(this,this.constructor._styleProperties),...this._getStyleDeclaration(e,t)}}_setStyleDeclaration(e,t,n){this.styles[e][t]=n}_deleteStyleDeclaration(e,t){delete this.styles[e][t]}_getLineStyle(e){return!!this.styles[e]}_setLineStyle(e){this.styles[e]={}}_deleteLineStyle(e){delete this.styles[e]}};Y(ep,`_styleProperties`,Mc);var tp=/ +/g,np=/"/g;function rp(e,t,n,r,i){return`\t\t${((e,{left:t,top:n,width:r,height:i},a=X.NUM_FRACTION_DIGITS)=>{let o=Cc(uo,e,!1),[s,c,l,u]=[t,n,r,i].map(e=>as(e,a));return`<rect ${o} x="${s}" y="${c}" width="${l}" height="${u}"></rect>`})(e,{left:t,top:n,width:r,height:i})}\n`}var ip,ap=class e extends ep{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t,n){super(),Y(this,`__charBounds`,[]),Object.assign(this,e.ownDefaults),this.setOptions(n),this.styles||={},this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){let e=this.path;e&&(e.segmentsInfo=Hd(e.path))}_splitText(){let e=this._splitTextIntoLines(this.text);return this.textLines=e.lines,this._textLines=e.graphemeLines,this._unwrappedTextLines=e._unwrappedLines,this._text=e.graphemeText,e}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(`justify`)&&this.enlargeSpaces()}enlargeSpaces(){let e,t,n,r,i,a,o;for(let s=0,c=this._textLines.length;s<c;s++)if((this.textAlign===`justify`||s!==c-1&&!this.isEndOfWrapping(s))&&(r=0,i=this._textLines[s],t=this.getLineWidth(s),t<this.width&&(o=this.textLines[s].match(this._reSpacesAndTabs)))){n=o.length,e=(this.width-t)/n;for(let t=0;t<=i.length;t++)a=this.__charBounds[s][t],this._reSpaceAndTab.test(i[t])?(a.width+=e,a.kernedWidth+=e,a.left+=r,r+=e):a.left+=r}}isEndOfWrapping(e){return e===this._textLines.length-1}missingNewlineOffset(e){return 1}get2DCursorLocation(e,t){let n=t?this._unwrappedTextLines:this._textLines,r;for(r=0;r<n.length;r++){if(e<=n[r].length)return{lineIndex:r,charIndex:e};e-=n[r].length+this.missingNewlineOffset(r,t)}return{lineIndex:r-1,charIndex:n[r-1].length<e?n[r-1].length:e}}toString(){return`#<Text (${this.complexity()}): { "text": "${this.text}", "fontFamily": "${this.fontFamily}" }>`}_getCacheCanvasDimensions(){let e=super._getCacheCanvasDimensions(),t=this.fontSize;return e.width+=t*e.zoomX,e.height+=t*e.zoomY,e}_render(e){let t=this.path;t&&!t.isNotVisible()&&t._render(e),this._setTextStyles(e),this._renderTextLinesBackground(e),this._renderTextDecoration(e,`underline`),this._renderText(e),this._renderTextDecoration(e,`overline`),this._renderTextDecoration(e,`linethrough`)}_renderText(e){this.paintFirst===`stroke`?(this._renderTextStroke(e),this._renderTextFill(e)):(this._renderTextFill(e),this._renderTextStroke(e))}_setTextStyles(e,t,n){if(e.textBaseline=`alphabetic`,this.path)switch(this.pathAlign){case Ga:e.textBaseline=`middle`;break;case`ascender`:e.textBaseline=`top`;break;case`descender`:e.textBaseline=qa}e.font=this._getFontDeclaration(t,n)}calcTextWidth(){let e=this.getLineWidth(0);for(let t=1,n=this._textLines.length;t<n;t++){let n=this.getLineWidth(t);n>e&&(e=n)}return e}_renderTextLine(e,t,n,r,i,a){this._renderChars(e,t,n,r,i,a)}_renderTextLinesBackground(e){if(!this.textBackgroundColor&&!this.styleHas(`textBackgroundColor`))return;let t=e.fillStyle,n=this._getLeftOffset(),r=this._getTopOffset();for(let t=0,i=this._textLines.length;t<i;t++){let i=this.getHeightOfLine(t);if(!this.textBackgroundColor&&!this.styleHas(`textBackgroundColor`,t)){r+=i;continue}let a=this._textLines[t].length,o=this._getLineLeftOffset(t),s,c,l=0,u=0,d=this.getValueOfPropertyAt(t,0,`textBackgroundColor`),f=this.getHeightOfLineImpl(t);for(let i=0;i<a;i++){let a=this.__charBounds[t][i];c=this.getValueOfPropertyAt(t,i,`textBackgroundColor`),this.path?(e.save(),e.translate(a.renderLeft,a.renderTop),e.rotate(a.angle),e.fillStyle=c,c&&e.fillRect(-a.width/2,-f*(1-this._fontSizeFraction),a.width,f),e.restore()):c===d?l+=a.kernedWidth:(s=n+o+u,this.direction===`rtl`&&(s=this.width-s-l),e.fillStyle=d,d&&e.fillRect(s,r,l,f),u=a.left,l=a.width,d=c)}c&&!this.path&&(s=n+o+u,this.direction===`rtl`&&(s=this.width-s-l),e.fillStyle=c,e.fillRect(s,r,l,f)),r+=i}e.fillStyle=t,this._removeShadow(e)}_measureChar(e,t,n,r){let i=La.getFontCache(t),a=this._getFontDeclaration(t),o=n?n+e:e,s=n&&a===this._getFontDeclaration(r),c=t.fontSize/this.CACHE_FONT_SIZE,l,u,d,f;if(n&&i.has(n)&&(d=i.get(n)),i.has(e)&&(f=l=i.get(e)),s&&i.has(o)&&(u=i.get(o),f=u-d),l===void 0||d===void 0||u===void 0){let r=(ip||=Mo({width:0,height:0}).getContext(`2d`),ip);this._setTextStyles(r,t,!0),l===void 0&&(f=l=r.measureText(e).width,i.set(e,l)),d===void 0&&s&&n&&(d=r.measureText(n).width,i.set(n,d)),s&&u===void 0&&(u=r.measureText(o).width,i.set(o,u),f=u-d)}return{width:l*c,kernedWidth:f*c}}getHeightOfChar(e,t){return this.getValueOfPropertyAt(e,t,`fontSize`)}measureLine(e){let t=this._measureLine(e);return this.charSpacing!==0&&(t.width-=this._getWidthOfCharSpacing()),t.width<0&&(t.width=0),t}_measureLine(e){let t,n,r=0,i=this.pathSide===Ja,a=this.path,o=this._textLines[e],s=o.length,c=Array(s);this.__charBounds[e]=c;for(let i=0;i<s;i++){let a=o[i];n=this._getGraphemeBox(a,e,i,t),c[i]=n,r+=n.kernedWidth,t=a}if(c[s]={left:n?n.left+n.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},a&&a.segmentsInfo){let e=0,t=a.segmentsInfo[a.segmentsInfo.length-1].length;switch(this.textAlign){case Ka:e=i?t-r:0;break;case Ga:e=(t-r)/2;break;case Ja:e=i?0:t-r}e+=this.pathStartOffset*(i?-1:1);for(let r=i?s-1:0;i?r>=0:r<s;i?r--:r++)n=c[r],e>t?e%=t:e<0&&(e+=t),this._setGraphemeOnPath(e,n),e+=n.kernedWidth}return{width:r,numOfSpaces:0}}_setGraphemeOnPath(e,t){let n=e+t.kernedWidth/2,r=this.path,i=Ud(r.path,n,r.segmentsInfo);t.renderLeft=i.x-r.pathOffset.x,t.renderTop=i.y-r.pathOffset.y,t.angle=i.angle+(this.pathSide===`right`?Math.PI:0)}_getGraphemeBox(e,t,n,r,i){let a=this.getCompleteStyleDeclaration(t,n),o=r?this.getCompleteStyleDeclaration(t,n-1):{},s=this._measureChar(e,a,r,o),c,l=s.kernedWidth,u=s.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),u+=c,l+=c);let d={width:u,left:0,height:a.fontSize,kernedWidth:l,deltaY:a.deltaY};if(n>0&&!i){let e=this.__charBounds[t][n-1];d.left=e.left+e.width+s.kernedWidth-s.width}return d}getHeightOfLineImpl(e){let t=this.__lineHeights;if(t[e])return t[e];let n=this.getHeightOfChar(e,0);for(let t=1,r=this._textLines[e].length;t<r;t++)n=Math.max(this.getHeightOfChar(e,t),n);return t[e]=n*this._fontSizeMult}getHeightOfLine(e){return this.getHeightOfLineImpl(e)*this.lineHeight}calcTextHeight(){let e=0;for(let t=0,n=this._textLines.length;t<n;t++)e+=t===n-1?this.getHeightOfLineImpl(t):this.getHeightOfLine(t);return e}_getLeftOffset(){return this.direction===`ltr`?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(e,t){e.save();let n=0,r=this._getLeftOffset(),i=this._getTopOffset();for(let a=0,o=this._textLines.length;a<o;a++)this._renderTextLine(t,e,this._textLines[a],r+this._getLineLeftOffset(a),i+n+this.getHeightOfLineImpl(a),a),n+=this.getHeightOfLine(a);e.restore()}_renderTextFill(e){(this.fill||this.styleHas(`fill`))&&this._renderTextCommon(e,`fillText`)}_renderTextStroke(e){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(e),e.save(),this._setLineDash(e,this.strokeDashArray),e.beginPath(),this._renderTextCommon(e,`strokeText`),e.closePath(),e.restore())}_renderChars(e,t,n,r,i,a){let o=this.textAlign.includes(Pc),s=this.path,c=!o&&this.charSpacing===0&&this.isEmptyStyles(a)&&!s,l=this.direction===`ltr`,u=this.direction===`ltr`?1:-1,d=t.direction,f,p,m,h,g,_=``,v=0;if(t.save(),d!==this.direction&&(t.canvas.setAttribute(`dir`,l?`ltr`:`rtl`),t.direction=l?`ltr`:`rtl`,t.textAlign=l?Ka:Ja),i-=this.getHeightOfLineImpl(a)*this._fontSizeFraction,c)return this._renderChar(e,t,a,0,n.join(``),r,i),void t.restore();for(let c=0,l=n.length-1;c<=l;c++)h=c===l||this.charSpacing||s,_+=n[c],m=this.__charBounds[a][c],v===0?(r+=u*(m.kernedWidth-m.width),v+=m.width):v+=m.kernedWidth,o&&!h&&this._reSpaceAndTab.test(n[c])&&(h=!0),h||=(f||=this.getCompleteStyleDeclaration(a,c),p=this.getCompleteStyleDeclaration(a,c+1),Iu(f,p,!1)),h&&(s?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),this._renderChar(e,t,a,c,_,-v/2,0),t.restore()):(g=r,this._renderChar(e,t,a,c,_,g,i)),_=``,f=p,r+=u*v,v=0);t.restore()}_applyPatternGradientTransformText(e){let t=this.width+this.strokeWidth,n=this.height+this.strokeWidth,r=Mo({width:t,height:n}),i=r.getContext(`2d`);return r.width=t,r.height=n,i.beginPath(),i.moveTo(0,0),i.lineTo(t,0),i.lineTo(t,n),i.lineTo(0,n),i.closePath(),i.translate(t/2,n/2),i.fillStyle=e.toLive(i),this._applyPatternGradientTransform(i,e),i.fill(),i.createPattern(r,`no-repeat`)}handleFiller(e,t,n){let r,i;return ss(n)?n.gradientUnits===`percentage`||n.gradientTransform||n.patternTransform?(r=-this.width/2,i=-this.height/2,e.translate(r,i),e[t]=this._applyPatternGradientTransformText(n),{offsetX:r,offsetY:i}):(e[t]=n.toLive(e),this._applyPatternGradientTransform(e,n)):(e[t]=n,{offsetX:0,offsetY:0})}_setStrokeStyles(e,{stroke:t,strokeWidth:n}){return e.lineWidth=n,e.lineCap=this.strokeLineCap,e.lineDashOffset=this.strokeDashOffset,e.lineJoin=this.strokeLineJoin,e.miterLimit=this.strokeMiterLimit,this.handleFiller(e,`strokeStyle`,t)}_setFillStyles(e,{fill:t}){return this.handleFiller(e,`fillStyle`,t)}_renderChar(e,t,n,r,i,a,o){let s=this._getStyleDeclaration(n,r),c=this.getCompleteStyleDeclaration(n,r),l=e===`fillText`&&c.fill,u=e===`strokeText`&&c.stroke&&c.strokeWidth;if(u||l){if(t.save(),t.font=this._getFontDeclaration(c),s.textBackgroundColor&&this._removeShadow(t),s.deltaY&&(o+=s.deltaY),l){let e=this._setFillStyles(t,c);t.fillText(i,a-e.offsetX,o-e.offsetY)}if(u){let e=this._setStrokeStyles(t,c);t.strokeText(i,a-e.offsetX,o-e.offsetY)}t.restore()}}setSuperscript(e,t){this._setScript(e,t,this.superscript)}setSubscript(e,t){this._setScript(e,t,this.subscript)}_setScript(e,t,n){let r=this.get2DCursorLocation(e,!0),i=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,`fontSize`),a=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,`deltaY`),o={fontSize:i*n.size,deltaY:a+i*n.baseline};this.setSelectionStyles(o,e,t)}_getLineLeftOffset(e){let t=this.getLineWidth(e),n=this.width-t,r=this.textAlign,i=this.direction,a=this.isEndOfWrapping(e),o=0;return r===`justify`||r===`justify-center`&&!a||r===`justify-right`&&!a||r===`justify-left`&&!a?0:(r===`center`&&(o=n/2),r===`right`&&(o=n),r===`justify-center`&&(o=n/2),r===`justify-right`&&(o=n),i===`rtl`&&(r===`right`||r===`justify-right`?o=0:r===`left`||r===`justify-left`?o=-n:r!==`center`&&r!==`justify-center`||(o=-n/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(e){if(this.__lineWidths[e]!==void 0)return this.__lineWidths[e];let{width:t}=this.measureLine(e);return this.__lineWidths[e]=t,t}_getWidthOfCharSpacing(){return this.charSpacing===0?0:this.fontSize*this.charSpacing/1e3}getValueOfPropertyAt(e,t,n){return this._getStyleDeclaration(e,t)[n]??this[n]}_renderTextDecoration(e,t){if(!this[t]&&!this.styleHas(t))return;let n=this._getTopOffset(),r=this._getLeftOffset(),i=this.path,a=this._getWidthOfCharSpacing(),o=t===`linethrough`?.5:+(t===`overline`),s=this.offsets[t];for(let c=0,l=this._textLines.length;c<l;c++){let l=this.getHeightOfLine(c);if(!this[t]&&!this.styleHas(t,c)){n+=l;continue}let u=this._textLines[c],d=l/this.lineHeight,f=this._getLineLeftOffset(c),p,m=0,h=0,g=this.getValueOfPropertyAt(c,0,t),_=this.getValueOfPropertyAt(c,0,uo),v=this.getValueOfPropertyAt(c,0,`textDecorationColor`)||_,y=this.getValueOfPropertyAt(c,0,Ec),b=g,x=v,S=y,C=n+d*(1-this._fontSizeFraction),w=this.getHeightOfChar(c,0),T=this.getValueOfPropertyAt(c,0,`deltaY`);for(let n=0,a=u.length;n<a;n++){let a=this.__charBounds[c][n];b=this.getValueOfPropertyAt(c,n,t),p=this.getValueOfPropertyAt(c,n,uo),x=this.getValueOfPropertyAt(c,n,`textDecorationColor`)||p,S=this.getValueOfPropertyAt(c,n,Ec);let l=this.getHeightOfChar(c,n),u=this.getValueOfPropertyAt(c,n,`deltaY`);if(i&&b&&p){let t=this.fontSize*S/1e3;e.save(),e.fillStyle=x,e.translate(a.renderLeft,a.renderTop),e.rotate(a.angle),e.fillRect(-a.kernedWidth/2,s*l+u-o*t,a.kernedWidth,t),e.restore()}else if((b!==g||p!==_||x!==v||l!==w||S!==y||u!==T)&&h>0){let t=this.fontSize*y/1e3,n=r+f+m;this.direction===`rtl`&&(n=this.width-n-h),g&&v&&y&&(e.fillStyle=v,e.fillRect(n,C+s*w+T-o*t,h,t)),m=a.left,h=a.width,g=b,v=x,y=S,_=p,w=l,T=u}else h+=a.kernedWidth}let E=r+f+m;this.direction===`rtl`&&(E=this.width-E-h),e.fillStyle=x;let D=this.fontSize*S/1e3;b&&x&&S&&e.fillRect(E,C+s*w+T-o*D,h-a,D),n+=l}this._removeShadow(e)}_getFontDeclaration({fontFamily:t=this.fontFamily,fontStyle:n=this.fontStyle,fontWeight:r=this.fontWeight,fontSize:i=this.fontSize}={},a){let o=t.includes(`'`)||t.includes(`"`)||t.includes(`,`)||e.genericFonts.includes(t.toLowerCase())?t:`"${t}"`;return[n,r,`${a?this.CACHE_FONT_SIZE:i}px`,o].join(` `)}render(e){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(e)))}graphemeSplit(e){return Ss(e)}_splitTextIntoLines(e){let t=e.split(this._reNewline),n=Array(t.length),r=[`
|
|
24
|
+
`],i=[];for(let e=0;e<t.length;e++)n[e]=this.graphemeSplit(t[e]),i=i.concat(n[e],r);return i.pop(),{_unwrappedLines:n,lines:t,graphemeText:i,graphemeLines:n}}toObject(e=[]){return{...super.toObject([...jc,...e]),styles:Lu(this.styles,this.text),...this.path?{path:this.path.toObject()}:{}}}set(e,t){let{textLayoutProperties:n}=this.constructor;super.set(e,t);let r=!1,i=!1;if(typeof e==`object`)for(let t in e)t===`path`&&this.setPathInfo(),r||=n.includes(t),i||=t===`path`;else r=n.includes(e),i=e===`path`;return i&&this.setPathInfo(),r&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,n,r){let i=cd(t,e.ATTRIBUTE_NAMES,r),{textAnchor:a=Ka,textDecoration:o=``,dx:s=0,dy:c=0,top:l=0,left:u=0,fontSize:d=16,strokeWidth:f=1,...p}={...n,...i},m=new this(fc(t.textContent||``).trim(),{left:u+s,top:l+c,underline:o.includes(`underline`),overline:o.includes(`overline`),linethrough:o.includes(`line-through`),strokeWidth:0,fontSize:d,...p}),h=m.getScaledHeight()/m.height,g=((m.height+m.strokeWidth)*m.lineHeight-m.height)*h,_=m.getScaledHeight()+g,v=0;return a===`center`&&(v=m.getScaledWidth()/2),a===`right`&&(v=m.getScaledWidth()),m.set({left:m.left-v,top:m.top-(_-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(e){return this._fromObject({...e,styles:Ru(e.styles||{},e.text)},{extraParam:`text`})}};Y(ap,`textLayoutProperties`,Ac),Y(ap,`cacheProperties`,[...Zc,...jc]),Y(ap,`ownDefaults`,Nc),Y(ap,`type`,`Text`),Y(ap,`genericFonts`,[`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-serif`,`ui-sans-serif`,`ui-monospace`,`ui-rounded`,`math`,`emoji`,`fangsong`]),Y(ap,`ATTRIBUTE_NAMES`,zu.concat(`x`,`y`,`dx`,`dy`,`font-family`,`font-style`,`font-weight`,`font-size`,`letter-spacing`,`text-decoration`,`text-decoration-thickness`,`text-decoration-color`,`text-anchor`)),Du(ap,[class extends wc{_toSVG(){let e=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(e.textTop,e.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(e){let t=this._createBaseSVGMarkup(this._toSVG(),{reviver:e,noStyle:!0,withShadow:!0}),n=this.path;return n?t+n._createBaseSVGMarkup(n._toSVG(),{reviver:e,withShadow:!0,additionalTransform:os(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg({textBgRects:e,textSpans:t}){let n=this.getSvgTextDecoration(this);return[e.join(``),` <text xml:space="preserve" `,`font-family="${$(this.fontFamily.replace(np,`'`))}" `,`font-size="${$(this.fontSize)}" `,this.fontStyle?`font-style="${$(this.fontStyle)}" `:``,this.fontWeight?`font-weight="${$(this.fontWeight)}" `:``,n?`text-decoration="${n}" `:``,this.direction===`rtl`?`direction="rtl" `:``,`style="`,this.getSvgStyles(!0),`"`,this.addPaintOrder(),` >`,t.join(``),`</text>
|
|
25
|
+
`]}_getSVGTextAndBg(e,t){let n=[],r=[],i,a=e;this.backgroundColor&&r.push(rp(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let e=0,o=this._textLines.length;e<o;e++)i=this._getLineLeftOffset(e),this.direction===`rtl`&&(i+=this.width),(this.textBackgroundColor||this.styleHas(`textBackgroundColor`,e))&&this._setSVGTextLineBg(r,e,t+i,a),this._setSVGTextLineText(n,e,t+i,a),a+=this.getHeightOfLine(e);return{textSpans:n,textBgRects:r}}_createTextCharSpan(e,t,n,r,i){let a=X.NUM_FRACTION_DIGITS,o=this.getSvgSpanStyles(t,e!==e.trim()||!!e.match(tp)),s=o?`style="${o}"`:``,c=t.deltaY,l=c?` dy="${as(c,a)}" `:``,{angle:u,renderLeft:d,renderTop:f,width:p}=i,m=``;if(d!==void 0){let e=p/2;u&&(m=` rotate="${as(Io(u),a)}"`);let t=qo({angle:Io(u)});t[4]=d,t[5]=f;let i=new Q(-e,0).transform(t);n=i.x,r=i.y}return`<tspan x="${as(n,a)}" y="${as(r,a)}" ${l}${m}${s}>${$(e)}</tspan>`}_setSVGTextLineText(e,t,n,r){let i=this.getHeightOfLine(t),a=this.textAlign.includes(Pc),o=this._textLines[t],s,c,l,u,d,f=``,p=0;r+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let i=0,m=o.length-1;i<=m;i++)d=i===m||this.charSpacing||this.path,f+=o[i],l=this.__charBounds[t][i],p===0?(n+=l.kernedWidth-l.width,p+=l.width):p+=l.kernedWidth,a&&!d&&this._reSpaceAndTab.test(o[i])&&(d=!0),d||=(s||=this.getCompleteStyleDeclaration(t,i),c=this.getCompleteStyleDeclaration(t,i+1),Iu(s,c,!0)),d&&(u=this._getStyleDeclaration(t,i),e.push(this._createTextCharSpan(f,u,n,r,l)),f=``,s=c,this.direction===`rtl`?n-=p:n+=p,p=0)}_setSVGTextLineBg(e,t,n,r){let i=this._textLines[t],a=this.getHeightOfLine(t)/this.lineHeight,o,s=0,c=0,l=this.getValueOfPropertyAt(t,0,`textBackgroundColor`);for(let u=0;u<i.length;u++){let{left:i,width:d,kernedWidth:f}=this.__charBounds[t][u];o=this.getValueOfPropertyAt(t,u,`textBackgroundColor`),o===l?s+=f:(l&&e.push(rp(l,n+c,r,s,a)),c=i,s=d,l=o)}o&&e.push(rp(l,n+c,r,s,a))}getSvgStyles(e){let t=lc(this.textDecorationColor)?` text-decoration-color: ${$(this[Dc])};`:``;return`${super.getSvgStyles(e)} text-decoration-thickness: ${as(this.textDecorationThickness*this.getObjectScaling().y/10,X.NUM_FRACTION_DIGITS)}%;${t} white-space: pre;`}getSvgSpanStyles(e,t){let{fontFamily:n,strokeWidth:r,stroke:i,fill:a,fontSize:o,fontStyle:s,fontWeight:c,textDecorationThickness:l,textDecorationColor:u,linethrough:d,overline:f,underline:p}=e,m=this.getSvgTextDecoration({underline:p??this.underline,overline:f??this.overline,linethrough:d??this.linethrough}),h=l||this.textDecorationThickness,g=u||this.textDecorationColor,_=uc(r),v=dc(n),y=uc(o),b=dc(s),x=uc(c)||dc(c),S=dc(g);return[i?Cc(fo,i):``,_?`stroke-width: ${$(_)}; `:``,v?`font-family: ${v.includes(`'`)||v.includes(`"`)?$(v):`'${$(v)}'`}; `:``,y?`font-size: ${$(y)}px; `:``,b?`font-style: ${$(b)}; `:``,x?`font-weight: ${$(x)}; `:``,m?`text-decoration: ${m}; text-decoration-thickness: ${as(h*this.getObjectScaling().y/10,X.NUM_FRACTION_DIGITS)}%;${S?` text-decoration-color: ${$(S)};`:``} `:``,a?Cc(uo,a):``,t?`white-space: pre; `:``].join(``)}getSvgTextDecoration(e){return[`overline`,`underline`,`line-through`].filter(t=>e[t.replace(`-`,``)]).join(` `)}}]),Z.setClass(ap),Z.setSVGClass(ap);var op=class{constructor(e){Y(this,`target`,void 0),Y(this,`__mouseDownInPlace`,!1),Y(this,`__dragStartFired`,!1),Y(this,`__isDraggingOver`,!1),Y(this,`__dragStartSelection`,void 0),Y(this,`__dragImageDisposer`,void 0),Y(this,`_dispose`,void 0),this.target=e;let t=[this.target.on(`dragenter`,this.dragEnterHandler.bind(this)),this.target.on(`dragover`,this.dragOverHandler.bind(this)),this.target.on(`dragleave`,this.dragLeaveHandler.bind(this)),this.target.on(`dragend`,this.dragEndHandler.bind(this)),this.target.on(`drop`,this.dropHandler.bind(this))];this._dispose=()=>{t.forEach(e=>e()),this._dispose=void 0}}isPointerOverSelection(e){let t=this.target,n=t.getSelectionStartFromPointer(e);return t.isEditing&&n>=t.selectionStart&&n<=t.selectionEnd&&t.selectionStart<t.selectionEnd}start(e){return this.__mouseDownInPlace=this.isPointerOverSelection(e)}isActive(){return this.__mouseDownInPlace}end(e){let t=this.isActive();return t&&!this.__dragStartFired&&(this.target.setCursorByClick(e),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,t}getDragStartSelection(){return this.__dragStartSelection}setDragImage(e,{selectionStart:t,selectionEnd:n}){var r;let i=this.target,a=i.canvas,o=new Q(i.flipX?-1:1,i.flipY?-1:1),s=i._getCursorBoundaries(t),c=new Q(s.left+s.leftOffset,s.top+s.topOffset).multiply(o).transform(i.calcTransformMatrix()),l=a.getScenePoint(e).subtract(c),u=i.getCanvasRetinaScaling(),d=i.getBoundingRect(),f=c.subtract(new Q(d.left,d.top)),p=a.viewportTransform,m=f.add(l).transform(p,!0),h=i.backgroundColor,g=Fu(i.styles);i.backgroundColor=``;let _={stroke:`transparent`,fill:`transparent`,textBackgroundColor:`transparent`};i.setSelectionStyles(_,0,t),i.setSelectionStyles(_,n,i.text.length),i.dirty=!0;let v=i.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});i.backgroundColor=h,i.styles=g,i.dirty=!0,rf(v,{position:`fixed`,left:-v.width+`px`,border:Ya,width:v.width/u+`px`,height:v.height/u+`px`}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{v.remove()},fs(e.target||this.target.hiddenTextarea).body.appendChild(v),(r=e.dataTransfer)==null||r.setDragImage(v,m.x,m.y)}onDragStart(e){this.__dragStartFired=!0;let t=this.target,n=this.isActive();if(n&&e.dataTransfer){let n=this.__dragStartSelection={selectionStart:t.selectionStart,selectionEnd:t.selectionEnd},r=t._text.slice(n.selectionStart,n.selectionEnd).join(``),i={text:t.text,value:r,...n};e.dataTransfer.setData(`text/plain`,r),e.dataTransfer.setData(`application/fabric`,JSON.stringify({value:r,styles:t.getSelectionStyles(n.selectionStart,n.selectionEnd,!0)})),e.dataTransfer.effectAllowed=`copyMove`,this.setDragImage(e,i)}return t.abortCursorAnimation(),n}canDrop(e){if(this.target.editable&&!this.target.getActiveControl()&&!e.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){let t=this.target.getSelectionStartFromPointer(e),n=this.__dragStartSelection;return t<n.selectionStart||t>n.selectionEnd}return!0}return!1}targetCanDrop(e){return this.target.canDrop(e)}dragEnterHandler({e}){let t=this.targetCanDrop(e);!this.__isDraggingOver&&t&&(this.__isDraggingOver=!0)}dragOverHandler(e){let{e:t}=e,n=this.targetCanDrop(t);!this.__isDraggingOver&&n?this.__isDraggingOver=!0:this.__isDraggingOver&&!n&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(t.preventDefault(),e.canDrop=!0,e.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(e){let{e:t}=e,n=t.defaultPrevented;this.__isDraggingOver=!1,t.preventDefault();let r=t.dataTransfer?.getData(`text/plain`);if(r&&!n){let n=this.target,i=n.canvas,a=n.getSelectionStartFromPointer(t),{styles:o}=t.dataTransfer.types.includes(`application/fabric`)?JSON.parse(t.dataTransfer.getData(`application/fabric`)):{},s=r[Math.max(0,r.length-1)];if(this.__dragStartSelection){let e=this.__dragStartSelection.selectionStart,t=this.__dragStartSelection.selectionEnd;a>e&&a<=t?a=e:a>t&&(a-=t-e),n.removeChars(e,t),delete this.__dragStartSelection}n._reNewline.test(s)&&(n._reNewline.test(n._text[a])||a===n._text.length)&&(r=r.trimEnd()),e.didDrop=!0,e.dropTarget=n,n.insertChars(r,o,a),i.setActiveObject(n),n.enterEditing(t),n.selectionStart=Math.min(a+0,n._text.length),n.selectionEnd=Math.min(n.selectionStart+r.length,n._text.length),n.hiddenTextarea.value=n.text,n._updateTextarea(),n.hiddenTextarea.focus(),n.fire(io,{index:a+0,action:`drop`}),i.fire(`text:changed`,{target:n}),i.contextTopDirty=!0,i.requestRenderAll()}}dragEndHandler({e}){if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){let t=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:i}=this.__dragStartSelection,a=e.dataTransfer?.dropEffect||`none`;a===`none`?(t.selectionStart=r,t.selectionEnd=i,t._updateTextarea(),t.hiddenTextarea.focus()):(t.clearContextTop(),a===`move`&&(t.removeChars(r,i),t.selectionStart=t.selectionEnd=r,t.hiddenTextarea&&(t.hiddenTextarea.value=t.text),t._updateTextarea(),t.fire(io,{index:r,action:`dragend`}),n.fire(`text:changed`,{target:t}),n.requestRenderAll()),t.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}},sp=/[ \n\.,;!\?\-]/,cp=class extends ap{constructor(...e){super(...e),Y(this,`_currentCursorOpacity`,1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(e){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(e)}_animateCursor({toValue:e,duration:t,delay:n,onComplete:r}){return Bl({startValue:this._currentCursorOpacity,endValue:e,duration:t,delay:n,onComplete:r,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:e=>{this._currentCursorOpacity=e,this.renderCursorOrSelection()}})}_tick(e){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(e||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var e;(e=this._currentTickCompleteState)==null||e.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(e){this.abortCursorAnimation(),this._tick(e?0:this.cursorDelay)}abortCursorAnimation(){let e=!1;[this._currentTickState,this._currentTickCompleteState].forEach(t=>{t&&!t.isDone()&&(e=!0,t.abort())}),this._currentCursorOpacity=1,e&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(e=>!e||e.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join(``)}findWordBoundaryLeft(e){let t=0,n=e-1;if(this._reSpace.test(this._text[n]))for(;this._reSpace.test(this._text[n]);)t++,n--;for(;/\S/.test(this._text[n])&&n>-1;)t++,n--;return e-t}findWordBoundaryRight(e){let t=0,n=e;if(this._reSpace.test(this._text[n]))for(;this._reSpace.test(this._text[n]);)t++,n++;for(;/\S/.test(this._text[n])&&n<this._text.length;)t++,n++;return e+t}findLineBoundaryLeft(e){let t=0,n=e-1;for(;!/\n/.test(this._text[n])&&n>-1;)t++,n--;return e-t}findLineBoundaryRight(e){let t=0,n=e;for(;!/\n/.test(this._text[n])&&n<this._text.length;)t++,n++;return e+t}searchWordBoundary(e,t){let n=this._text,r=e>0&&this._reSpace.test(n[e])&&(t===-1||!Xa.test(n[e-1]))?e-1:e,i=n[r];for(;r>0&&r<n.length&&!sp.test(i);)r+=t,i=n[r];return t===-1&&sp.test(i)&&r++,r}selectWord(e){e??=this.selectionStart;let t=this.searchWordBoundary(e,-1),n=Math.max(t,this.searchWordBoundary(e,1));this.selectionStart=t,this.selectionEnd=n,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(e){e??=this.selectionStart;let t=this.findLineBoundaryLeft(e),n=this.findLineBoundaryRight(e);this.selectionStart=t,this.selectionEnd=n,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(e){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire(`editing:entered`,e?{e}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire(`text:editing:entered`,{target:this,e}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(e){if(this.getActiveControl())return;let t=this.hiddenTextarea;fs(t).activeElement!==t&&t.focus();let n=this.getSelectionStartFromPointer(e),r=this.selectionStart,i=this.selectionEnd;(n===this.__selectionStartOnMouseDown&&r!==i||r!==n&&i!==n)&&(n>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=n):(this.selectionStart=n,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===r&&this.selectionEnd===i||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor=`text`,this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor=`text`),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(e,t,n){let r=n.slice(0,e),i=this.graphemeSplit(r).length;if(e===t)return{selectionStart:i,selectionEnd:i};let a=n.slice(e,t);return{selectionStart:i,selectionEnd:i+this.graphemeSplit(a).length}}fromGraphemeToStringSelection(e,t,n){let r=n.slice(0,e).join(``).length;return e===t?{selectionStart:r,selectionEnd:r}:{selectionStart:r,selectionEnd:r+n.slice(e,t).join(``).length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){let e=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=e.selectionStart,this.hiddenTextarea.selectionEnd=e.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){let{hiddenTextarea:e,direction:t,textAlign:n,inCompositionMode:r}=this;if(!e)return;let i=n===`justify`?t===`ltr`?Ka:Ja:n.replace(`justify-`,``),a=this.getPositionByOrigin(i,`top`);this.cursorOffsetCache={},this.text=e.value,this.set(`dirty`,!0),this.initDimensions(),this.setPositionByOrigin(a,i,`top`),this.setCoords();let o=this.fromStringToGraphemeSelection(e.selectionStart,e.selectionEnd,e.value);this.selectionEnd=this.selectionStart=o.selectionEnd,r||(this.selectionStart=o.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){let e=this._calcTextareaPosition();this.hiddenTextarea.style.left=e.left,this.hiddenTextarea.style.top=e.top}}_calcTextareaPosition(){if(!this.canvas)return{left:`1px`,top:`1px`};let e=this.inCompositionMode?this.compositionStart:this.selectionStart,t=this._getCursorBoundaries(e),n=this.get2DCursorLocation(e),r=n.lineIndex,i=n.charIndex,a=this.getValueOfPropertyAt(r,i,`fontSize`)*this.lineHeight,o=t.leftOffset,s=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,l=c.width/s,u=c.height/s,d=l-a,f=u-a,p=new Q(t.left+o,t.top+t.topOffset+a).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new Q(c.clientWidth/l,c.clientHeight/u));return p.x<0&&(p.x=0),p.x>d&&(p.x=d),p.y<0&&(p.y=0),p.y>f&&(p.y=f),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:`${p.x}px`,top:`${p.y}px`,fontSize:`${a}px`,charHeight:a}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}exitEditingImpl(){let e=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,e&&(e.blur&&e.blur(),e.parentNode&&e.parentNode.removeChild(e)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){let e=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire(`editing:exited`),e&&this.fire(`modified`),this.canvas&&(this.canvas.fire(`text:editing:exited`,{target:this}),e&&this.canvas.fire(`object:modified`,{target:this})),this}_removeExtraneousStyles(){for(let e in this.styles)this._textLines[e]||delete this.styles[e]}removeStyleFromTo(e,t){let{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0),{lineIndex:i,charIndex:a}=this.get2DCursorLocation(t,!0);if(n!==i){if(this.styles[n])for(let e=r;e<this._unwrappedTextLines[n].length;e++)delete this.styles[n][e];if(this.styles[i])for(let e=a;e<this._unwrappedTextLines[i].length;e++){let t=this.styles[i][e];t&&(this.styles[n]||(this.styles[n]={}),this.styles[n][r+e-a]=t)}for(let e=n+1;e<=i;e++)delete this.styles[e];this.shiftLineStyles(i,n-i)}else if(this.styles[n]){let e=this.styles[n],t=a-r;for(let t=r;t<a;t++)delete e[t];for(let r in this.styles[n]){let n=parseInt(r,10);n>=a&&(e[n-t]=e[r],delete e[r])}}}shiftLineStyles(e,t){let n=Object.assign({},this.styles);for(let r in this.styles){let i=parseInt(r,10);i>e&&(this.styles[i+t]=n[i],n[i-t]||delete this.styles[i])}}insertNewlineStyleObject(e,t,n,r){let i={},a=this._unwrappedTextLines[e].length,o=a===t,s=!1;n||=1,this.shiftLineStyles(e,n);let c=this.styles[e]?this.styles[e][t===0?t:t-1]:void 0;for(let n in this.styles[e]){let r=parseInt(n,10);r>=t&&(s=!0,i[r-t]=this.styles[e][n],o&&t===0||delete this.styles[e][n])}let l=!1;for(s&&!o&&(this.styles[e+n]=i,l=!0),(l||a>t)&&n--;n>0;)r&&r[n-1]?this.styles[e+n]={0:{...r[n-1]}}:c?this.styles[e+n]={0:{...c}}:delete this.styles[e+n],n--;this._forceClearCache=!0}insertCharStyleObject(e,t,n,r){this.styles||={};let i=this.styles[e],a=i?{...i}:{};n||=1;for(let e in a){let r=parseInt(e,10);r>=t&&(i[r+n]=a[r],a[r-n]||delete i[r])}if(this._forceClearCache=!0,r){for(;n--;)Object.keys(r[n]).length&&(this.styles[e]||(this.styles[e]={}),this.styles[e][t+n]={...r[n]});return}if(!i)return;let o=i[t?t-1:1];for(;o&&n--;)this.styles[e][t+n]={...o}}insertNewStyleBlock(e,t,n){let r=this.get2DCursorLocation(t,!0),i=[0],a,o=0;for(let t=0;t<e.length;t++)e[t]===`
|
|
26
|
+
`?(o++,i[o]=0):i[o]++;for(i[0]>0&&(this.insertCharStyleObject(r.lineIndex,r.charIndex,i[0],n),n&&=n.slice(i[0]+1)),o&&this.insertNewlineStyleObject(r.lineIndex,r.charIndex+i[0],o),a=1;a<o;a++)i[a]>0?this.insertCharStyleObject(r.lineIndex+a,0,i[a],n):n&&this.styles[r.lineIndex+a]&&n[0]&&(this.styles[r.lineIndex+a][0]=n[0]),n&&=n.slice(i[a]+1);i[a]>0&&this.insertCharStyleObject(r.lineIndex+a,0,i[a],n)}removeChars(e,t=e+1){this.removeStyleFromTo(e,t),this._text.splice(e,t-e),this.text=this._text.join(``),this.set(`dirty`,!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(e,t,n,r=n){r>n&&this.removeStyleFromTo(n,r);let i=this.graphemeSplit(e);this.insertNewStyleBlock(i,n,t),this._text=[...this._text.slice(0,n),...i,...this._text.slice(r)],this.text=this._text.join(``),this.set(`dirty`,!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(e,t,n){n<=e?(t===e?this._selectionDirection=Ka:this._selectionDirection===`right`&&(this._selectionDirection=Ka,this.selectionEnd=e),this.selectionStart=n):n>e&&n<t?this._selectionDirection===`right`?this.selectionEnd=n:this.selectionStart=n:(t===e?this._selectionDirection=Ja:this._selectionDirection===`left`&&(this._selectionDirection=Ja,this.selectionStart=t),this.selectionEnd=n)}},lp=class extends cp{initHiddenTextarea(){let e=this.canvas&&fs(this.canvas.getElement())||Pa(),t=e.createElement(`textarea`);Object.entries({autocapitalize:`off`,autocorrect:`off`,autocomplete:`off`,spellcheck:`false`,"data-fabric":`textarea`,wrap:`off`,name:`fabricTextarea`}).map(([e,n])=>t.setAttribute(e,n));let{top:n,left:r,fontSize:i}=this._calcTextareaPosition();t.style.cssText=`position: absolute; top: ${n}; left: ${r}; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ${i};`,(this.hiddenTextareaContainer||e.body).appendChild(t),Object.entries({blur:`blur`,keydown:`onKeyDown`,keyup:`onKeyUp`,input:`onInput`,copy:`copy`,cut:`copy`,paste:`paste`,compositionstart:`onCompositionStart`,compositionupdate:`onCompositionUpdate`,compositionend:`onCompositionEnd`}).map(([e,n])=>t.addEventListener(e,this[n].bind(this))),this.hiddenTextarea=t}blur(){this.abortCursorAnimation()}onKeyDown(e){if(!this.isEditing)return;let t=this.direction===`rtl`?this.keysMapRtl:this.keysMap;if(e.keyCode in t)this[t[e.keyCode]](e);else{if(!(e.keyCode in this.ctrlKeysMapDown)||!e.ctrlKey&&!e.metaKey)return;this[this.ctrlKeysMapDown[e.keyCode]](e)}e.stopImmediatePropagation(),e.preventDefault(),e.keyCode>=33&&e.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(e){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:e.keyCode in this.ctrlKeysMapUp&&(e.ctrlKey||e.metaKey)&&(this[this.ctrlKeysMapUp[e.keyCode]](e),e.stopImmediatePropagation(),e.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(e){let t=this.fromPaste,{value:n,selectionStart:r,selectionEnd:i}=this.hiddenTextarea;if(this.fromPaste=!1,e&&e.stopPropagation(),!this.isEditing)return;let a=()=>{this.updateFromTextArea(),this.fire(io),this.canvas&&(this.canvas.fire(`text:changed`,{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value===``)return this.styles={},void a();let o=this._splitTextIntoLines(n).graphemeText,s=this._text.length,c=o.length,l=this.selectionStart,u=this.selectionEnd,d=l!==u,f,p,m,h,g=c-s,_=this.fromStringToGraphemeSelection(r,i,n),v=l>_.selectionStart;d?(p=this._text.slice(l,u),g+=u-l):c<s&&(p=v?this._text.slice(u+g,u):this._text.slice(l,l-g));let y=o.slice(_.selectionEnd-g,_.selectionEnd);if(p&&p.length&&(y.length&&(f=this.getSelectionStyles(l,l+1,!1),f=y.map(()=>f[0])),d?(m=l,h=u):v?(m=u-p.length,h=u):(m=u,h=u+p.length),this.removeStyleFromTo(m,h)),y.length){let{copyPasteData:e}=Na();t&&y.join(``)===e.copiedText&&!X.disableStyleCopyPaste&&(f=e.copiedTextStyle),this.insertNewStyleBlock(y,l,f)}a()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate({target:e}){let{selectionStart:t,selectionEnd:n}=e;this.compositionStart=t,this.compositionEnd=n,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;let{copyPasteData:e}=Na();e.copiedText=this.getSelectedText(),X.disableStyleCopyPaste?e.copiedTextStyle=void 0:e.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(e,t){let n,r=this._getLineLeftOffset(e);return t>0&&(n=this.__charBounds[e][t-1],r+=n.left+n.width),r}getDownCursorOffset(e,t){let n=this._getSelectionForOffset(e,t),r=this.get2DCursorLocation(n),i=r.lineIndex;if(i===this._textLines.length-1||e.metaKey||e.keyCode===34)return this._text.length-n;let a=r.charIndex,o=this._getWidthBeforeCursor(i,a),s=this._getIndexOnLine(i+1,o);return this._textLines[i].slice(a).length+s+1+this.missingNewlineOffset(i)}_getSelectionForOffset(e,t){return e.shiftKey&&this.selectionStart!==this.selectionEnd&&t?this.selectionEnd:this.selectionStart}getUpCursorOffset(e,t){let n=this._getSelectionForOffset(e,t),r=this.get2DCursorLocation(n),i=r.lineIndex;if(i===0||e.metaKey||e.keyCode===33)return-n;let a=r.charIndex,o=this._getWidthBeforeCursor(i,a),s=this._getIndexOnLine(i-1,o),c=this._textLines[i].slice(0,a),l=this.missingNewlineOffset(i-1);return-this._textLines[i-1].length+s-c.length+(1-l)}_getIndexOnLine(e,t){let n=this._textLines[e],r,i,a=this._getLineLeftOffset(e),o=0;for(let s=0,c=n.length;s<c;s++)if(r=this.__charBounds[e][s].width,a+=r,a>t){i=!0;let e=a-r,n=a,c=Math.abs(e-t);o=Math.abs(n-t)<c?s:s-1;break}return i||(o=n.length-1),o}moveCursorDown(e){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown(`Down`,e)}moveCursorUp(e){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown(`Up`,e)}_moveCursorUpOrDown(e,t){let n=this[`get${e}CursorOffset`](t,this._selectionDirection===Ja);if(t.shiftKey?this.moveCursorWithShift(n):this.moveCursorWithoutShift(n),n!==0){let e=this.text.length;this.selectionStart=Yc(0,this.selectionStart,e),this.selectionEnd=Yc(0,this.selectionEnd,e),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(e){let t=this._selectionDirection===`left`?this.selectionStart+e:this.selectionEnd+e;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,t),e!==0}moveCursorWithoutShift(e){return e<0?(this.selectionStart+=e,this.selectionEnd=this.selectionStart):(this.selectionEnd+=e,this.selectionStart=this.selectionEnd),e!==0}moveCursorLeft(e){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight(`Left`,e)}_move(e,t,n){let r;if(e.altKey)r=this[`findWordBoundary${n}`](this[t]);else{if(!e.metaKey&&e.keyCode!==35&&e.keyCode!==36)return this[t]+=n===`Left`?-1:1,!0;r=this[`findLineBoundary${n}`](this[t])}return r!==void 0&&this[t]!==r&&(this[t]=r,!0)}_moveLeft(e,t){return this._move(e,t,`Left`)}_moveRight(e,t){return this._move(e,t,`Right`)}moveCursorLeftWithoutShift(e){let t=!0;return this._selectionDirection=Ka,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(t=this._moveLeft(e,`selectionStart`)),this.selectionEnd=this.selectionStart,t}moveCursorLeftWithShift(e){return this._selectionDirection===`right`&&this.selectionStart!==this.selectionEnd?this._moveLeft(e,`selectionEnd`):this.selectionStart===0?void 0:(this._selectionDirection=Ka,this._moveLeft(e,`selectionStart`))}moveCursorRight(e){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight(`Right`,e)}_moveCursorLeftOrRight(e,t){let n=`moveCursor${e}${t.shiftKey?`WithShift`:`WithoutShift`}`;this._currentCursorOpacity=1,this[n](t)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(e){return this._selectionDirection===`left`&&this.selectionStart!==this.selectionEnd?this._moveRight(e,`selectionStart`):this.selectionEnd===this._text.length?void 0:(this._selectionDirection=Ja,this._moveRight(e,`selectionEnd`))}moveCursorRightWithoutShift(e){let t=!0;return this._selectionDirection=Ja,this.selectionStart===this.selectionEnd?(t=this._moveRight(e,`selectionStart`),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,t}},up=e=>!!e.button,dp=class extends lp{constructor(...e){super(...e),Y(this,`draggableTextDelegate`,void 0)}initBehavior(){this.on(`mousedown`,this._mouseDownHandler),this.on(`mouseup`,this.mouseUpHandler),this.on(`mousedblclick`,this.doubleClickHandler),this.on(`mousetripleclick`,this.tripleClickHandler),this.draggableTextDelegate=new op(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(e){return this.draggableTextDelegate.onDragStart(e)}canDrop(e){return this.draggableTextDelegate.canDrop(e)}doubleClickHandler(e){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(e.e)),this.renderCursorOrSelection())}tripleClickHandler(e){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(e.e)),this.renderCursorOrSelection())}_mouseDownHandler({e,alreadySelected:t}){this.canvas&&this.editable&&!up(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),t&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||=t||this.isEditing))}mouseUpHandler({e,transform:t}){let n=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);let e=this.canvas._activeObject;if(e&&e!==this)return}!this.editable||this.group&&!this.group.interactive||t&&t.actionPerformed||up(e)||n||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(e){let t=this.getSelectionStartFromPointer(e),n=this.selectionStart,r=this.selectionEnd;e.shiftKey?this.setSelectionStartEndWithShift(n,r,t):(this.selectionStart=t,this.selectionEnd=t),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(e){let t=this.canvas.getScenePoint(e).transform(zo(this.calcTransformMatrix())).add(new Q(-this._getLeftOffset(),-this._getTopOffset())),n=0,r=0,i=0;for(let e=0;e<this._textLines.length&&n<=t.y;e++)n+=this.getHeightOfLine(e),i=e,e>0&&(r+=this._textLines[e-1].length+this.missingNewlineOffset(e-1));let a=Math.abs(this._getLineLeftOffset(i)),o=this._textLines[i].length,s=this.__charBounds[i];for(let e=0;e<o;e++){let n=a+s[e].kernedWidth;if(t.x<=n){Math.abs(t.x-n)<=Math.abs(t.x-a)&&r++;break}a=n,r++}return Math.min(this.flipX?o-r:r,this._text.length)}},fp=`moveCursorUp`,pp=`moveCursorDown`,mp=`moveCursorLeft`,hp=`moveCursorRight`,gp=`exitEditing`,_p=(e,t)=>{let n=t.getRetinaScaling();e.setTransform(n,0,0,n,0,0);let r=t.viewportTransform;e.transform(r[0],r[1],r[2],r[3],r[4],r[5])},vp={selectionStart:0,selectionEnd:0,selectionColor:`rgba(17,119,255,0.3)`,isEditing:!1,editable:!0,editingBorderColor:`rgba(102,153,255,0.25)`,cursorWidth:2,cursorColor:``,cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:gp,27:gp,33:fp,34:pp,35:hp,36:mp,37:mp,38:fp,39:hp,40:pp},keysMapRtl:{9:gp,27:gp,33:fp,34:pp,35:mp,36:hp,37:hp,38:fp,39:mp,40:pp},ctrlKeysMapDown:{65:`cmdAll`},ctrlKeysMapUp:{67:`copy`,88:`cut`},_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1},yp=class e extends dp{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}get type(){let e=super.type;return e===`itext`?`i-text`:e}constructor(t,n){super(t,{...e.ownDefaults,...n}),this.initBehavior()}_set(e,t){return this.isEditing&&this._savedProps&&e in this._savedProps?(this._savedProps[e]=t,this):(e===`canvas`&&(this.canvas instanceof Df&&this.canvas.textEditingManager.remove(this),t instanceof Df&&t.textEditingManager.add(this)),super._set(e,t))}setSelectionStart(e){e=Math.max(e,0),this._updateAndFire(`selectionStart`,e)}setSelectionEnd(e){e=Math.min(e,this.text.length),this._updateAndFire(`selectionEnd`,e)}_updateAndFire(e,t){this[e]!==t&&(this._fireSelectionChanged(),this[e]=t),this._updateTextarea()}_fireSelectionChanged(){this.fire(`selection:changed`),this.canvas&&this.canvas.fire(`text:selection:changed`,{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(e=this.selectionStart||0,t=this.selectionEnd,n){return super.getSelectionStyles(e,t,n)}setSelectionStyles(e,t=this.selectionStart||0,n=this.selectionEnd){return super.setSelectionStyles(e,t,n)}get2DCursorLocation(e=this.selectionStart,t){return super.get2DCursorLocation(e,t)}render(e){super.render(e),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(e){let t=this.isEditing;this.isEditing=!1;let n=super.toCanvasElement(e);return this.isEditing=t,n}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;let e=this.clearContextTop(!0);if(!e)return;let t=this._getCursorBoundaries(),n=this.findAncestorsWithClipPath(),r=n.length>0,i,a=e;if(r){i=Mo(e.canvas),a=i.getContext(`2d`),_p(a,this.canvas);let t=this.calcTransformMatrix();a.transform(t[0],t[1],t[2],t[3],t[4],t[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(a,t):this.renderCursor(a,t),r)for(let t of n){let n=t.clipPath,r=Mo(e.canvas),i=r.getContext(`2d`);if(_p(i,this.canvas),!n.absolutePositioned){let e=t.calcTransformMatrix();i.transform(e[0],e[1],e[2],e[3],e[4],e[5])}n.transform(i),n.drawObject(i,!0,{}),this.drawClipPathOnCache(a,n,r)}r&&(e.setTransform(1,0,0,1,0,0),e.drawImage(i,0,0)),this.canvas.contextTopDirty=!0,e.restore()}findAncestorsWithClipPath(){let e=[],t=this;for(;t;)t.clipPath&&e.push(t),t=t.parent;return e}_getCursorBoundaries(e=this.selectionStart,t){let n=this._getLeftOffset(),r=this._getTopOffset(),i=this._getCursorBoundariesOffsets(e,t);return{left:n,top:r,leftOffset:i.left,topOffset:i.top}}_getCursorBoundariesOffsets(e,t){return t?this.__getCursorBoundariesOffsets(e):this.cursorOffsetCache&&`top`in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(e)}__getCursorBoundariesOffsets(e){let t=0,n=0,{charIndex:r,lineIndex:i}=this.get2DCursorLocation(e),{textAlign:a,direction:o}=this;for(let e=0;e<i;e++)t+=this.getHeightOfLine(e);let s=this._getLineLeftOffset(i),c=this.__charBounds[i][r];c&&(n=c.left),this.charSpacing!==0&&r===this._textLines[i].length&&(n-=this._getWidthOfCharSpacing());let l=s+(n>0?n:0);return o===`rtl`&&(a===`right`||a===`justify`||a===`justify-right`?l*=-1:a===`left`||a===`justify-left`?l=s-(n>0?n:0):a!==`center`&&a!==`justify-center`||(l=s-(n>0?n:0))),{top:t,left:l}}renderCursorAt(e){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(e,!0),e)}renderCursor(e,t){this._renderCursor(e,t,this.selectionStart)}getCursorRenderingData(e=this.selectionStart,t=this._getCursorBoundaries(e)){let n=this.get2DCursorLocation(e),r=n.lineIndex,i=n.charIndex>0?n.charIndex-1:0,a=this.getValueOfPropertyAt(r,i,`fontSize`),o=this.getObjectScaling().x*this.canvas.getZoom(),s=this.cursorWidth/o,c=this.getValueOfPropertyAt(r,i,`deltaY`),l=t.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-a*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(r,i,`fill`),opacity:this._currentCursorOpacity,left:t.left+t.leftOffset-s/2,top:l+t.top+c,width:s,height:a}}_renderCursor(e,t,n){let{color:r,opacity:i,left:a,top:o,width:s,height:c}=this.getCursorRenderingData(n,t);e.fillStyle=r,e.globalAlpha=i,e.fillRect(a,o,s,c)}renderSelection(e,t){let n={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(e,n,t)}renderDragSourceEffect(){let e=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,e,this._getCursorBoundaries(e.selectionStart,!0))}renderDropTargetEffect(e){let t=this.getSelectionStartFromPointer(e);this.renderCursorAt(t)}_renderSelection(e,t,n){let{textAlign:r,direction:i}=this,a=t.selectionStart,o=t.selectionEnd,s=r.includes(Pc),c=this.get2DCursorLocation(a),l=this.get2DCursorLocation(o),u=c.lineIndex,d=l.lineIndex,f=c.charIndex<0?0:c.charIndex,p=l.charIndex<0?0:l.charIndex;for(let t=u;t<=d;t++){let a=this._getLineLeftOffset(t)||0,o=this.getHeightOfLine(t),c=0,l=0;if(t===u&&(c=this.__charBounds[u][f].left),t>=u&&t<d)l=s&&!this.isEndOfWrapping(t)?this.width:this.getLineWidth(t)||5;else if(t===d)if(p===0)l=this.__charBounds[d][p].left;else{let e=this._getWidthOfCharSpacing();l=this.__charBounds[d][p-1].left+this.__charBounds[d][p-1].width-e}let m=o;(this.lineHeight<1||t===d&&this.lineHeight>1)&&(o/=this.lineHeight);let h=n.left+a+c,g=o,_=0,v=l-c;this.inCompositionMode?(e.fillStyle=this.compositionColor||`black`,g=1,_=o):e.fillStyle=this.selectionColor,i===`rtl`&&(r===`right`||r===`justify`||r===`justify-right`?h=this.width-h-v:r===`left`||r===`justify-left`?h=n.left+a-l:r!==`center`&&r!==`justify-center`||(h=n.left+a-l)),e.fillRect(h,n.top+n.topOffset+_,v,g),n.topOffset+=m}}getCurrentCharFontSize(){let e=this._getCurrentCharIndex();return this.getValueOfPropertyAt(e.l,e.c,`fontSize`)}getCurrentCharColor(){let e=this._getCurrentCharIndex();return this.getValueOfPropertyAt(e.l,e.c,uo)}_getCurrentCharIndex(){let e=this.get2DCursorLocation(this.selectionStart,!0),t=e.charIndex>0?e.charIndex-1:0;return{l:e.lineIndex,c:t}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}};Y(yp,`ownDefaults`,vp),Y(yp,`type`,`IText`),Z.setClass(yp),Z.setClass(yp,`i-text`);var bp=class e extends yp{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t,n){super(t,{...e.ownDefaults,...n})}static createControls(){return{controls:Tu()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set(`width`,this.dynamicMinWidth),this.textAlign.includes(`justify`)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(e){let t=0,n=0,r=0,i={};for(let a=0;a<e.graphemeLines.length;a++)e.graphemeText[r]===`
|
|
27
|
+
`&&a>0?(n=0,r++,t++):!this.splitByGrapheme&&this._reSpaceAndTab.test(e.graphemeText[r])&&a>0&&(n++,r++),i[a]={line:t,offset:n},r+=e.graphemeLines[a].length,n+=e.graphemeLines[a].length;return i}styleHas(e,t){if(this._styleMap&&!this.isWrapping){let e=this._styleMap[t];e&&(t=e.line)}return super.styleHas(e,t)}isEmptyStyles(e){if(!this.styles)return!0;let t,n,r=0,i=!1,a=this._styleMap[e],o=this._styleMap[e+1];a&&(e=a.line,r=a.offset),o&&(t=o.line,i=t===e,n=o.offset);let s=e===void 0?this.styles:{line:this.styles[e]};for(let e in s)for(let t in s[e]){let a=parseInt(t,10);if(a>=r&&(!i||a<n))for(let n in s[e][t])return!1}return!0}_getStyleDeclaration(e,t){if(this._styleMap&&!this.isWrapping){let n=this._styleMap[e];if(!n)return{};e=n.line,t=n.offset+t}return super._getStyleDeclaration(e,t)}_setStyleDeclaration(e,t,n){let r=this._styleMap[e];super._setStyleDeclaration(r.line,r.offset+t,n)}_deleteStyleDeclaration(e,t){let n=this._styleMap[e];super._deleteStyleDeclaration(n.line,n.offset+t)}_getLineStyle(e){let t=this._styleMap[e];return!!this.styles[t.line]}_setLineStyle(e){let t=this._styleMap[e];super._setLineStyle(t.line)}_wrapText(e,t){this.isWrapping=!0;let n=this.getGraphemeDataForRender(e),r=[];for(let e=0;e<n.wordsData.length;e++)r.push(...this._wrapLine(e,t,n));return this.isWrapping=!1,r}getGraphemeDataForRender(e){let t=this.splitByGrapheme,n=t?``:` `,r=0;return{wordsData:e.map((e,i)=>{let a=0,o=t?this.graphemeSplit(e):this.wordSplit(e);return o.length===0?[{word:[],width:0}]:o.map(e=>{let o=t?[e]:this.graphemeSplit(e),s=this._measureWord(o,i,a);return r=Math.max(s,r),a+=o.length+n.length,{word:o,width:s}})}),largestWordWidth:r}}_measureWord(e,t,n=0){let r,i=0;for(let a=0,o=e.length;a<o;a++)i+=this._getGraphemeBox(e[a],t,a+n,r,!0).kernedWidth,r=e[a];return i}wordSplit(e){return e.split(this._wordJoiners)}_wrapLine(e,t,{largestWordWidth:n,wordsData:r},i=0){let a=this._getWidthOfCharSpacing(),o=this.splitByGrapheme,s=[],c=o?``:` `,l=0,u=[],d=0,f=0,p=!0;t-=i;let m=Math.max(t,n,this.dynamicMinWidth),h=r[e],g;for(g=0;g<h.length;g++){let{word:t,width:n}=h[g];d+=t.length,l+=f+n-a,l>m&&!p?(s.push(u),u=[],l=n,p=!0):l+=a,p||o||u.push(c),u=u.concat(t),f=o?0:this._measureWord([c],e,d),d++,p=!1}return g&&s.push(u),n+i>this.dynamicMinWidth&&(this.dynamicMinWidth=n-a+i),s}isEndOfWrapping(e){return!this._styleMap[e+1]||this._styleMap[e+1].line!==this._styleMap[e].line}missingNewlineOffset(e,t){return this.splitByGrapheme&&!t?+!!this.isEndOfWrapping(e):1}_splitTextIntoLines(e){let t=super._splitTextIntoLines(e),n=this._wrapText(t.lines,this.width),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=n[e].join(``);return t.lines=r,t.graphemeLines=n,t}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){let e=new Map;for(let t in this._styleMap){let n=parseInt(t,10);if(this._textLines[n]){let n=this._styleMap[t].line;e.set(`${n}`,!0)}}for(let t in this.styles)e.has(t)||delete this.styles[t]}toObject(e=[]){return super.toObject([`minWidth`,`splitByGrapheme`,...e])}};Y(bp,`type`,`Textbox`),Y(bp,`textLayoutProperties`,[...yp.textLayoutProperties,`width`]),Y(bp,`ownDefaults`,{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),Z.setClass(bp);var xp=class extends md{shouldPerformLayout(e){return!!e.target.clipPath&&super.shouldPerformLayout(e)}shouldLayoutClipPath(){return!1}calcLayoutResult(e,t){let{target:n}=e,{clipPath:r,group:i}=n;if(!r||!this.shouldPerformLayout(e))return;let{width:a,height:o}=As(pd(n,r)),s=new Q(a,o);if(r.absolutePositioned)return{center:Rs(r.getRelativeCenterPoint(),void 0,i?i.calcTransformMatrix():void 0),size:s};{let i=r.getRelativeCenterPoint().transform(n.calcOwnMatrix(),!0);if(this.shouldPerformLayout(e)){let{center:n=new Q,correction:r=new Q}=this.calcBoundingBox(t,e)||{};return{center:n.add(i),correction:r.subtract(i),size:s}}return{center:n.getRelativeCenterPoint().add(i),size:s}}}};Y(xp,`type`,`clip-path`),Z.setClass(xp);var Sp=class extends md{getInitialSize({target:e},{size:t}){return new Q(e.width||t.x,e.height||t.y)}};Y(Sp,`type`,`fixed`),Z.setClass(Sp);var Cp=class extends _d{subscribeTargets(e){let t=e.target;e.targets.reduce((e,t)=>(t.parent&&e.add(t.parent),e),new Set).forEach(e=>{e.layoutManager.subscribeTargets({target:e,targets:[t]})})}unsubscribeTargets(e){let t=e.target,n=t.getObjects();e.targets.reduce((e,t)=>(t.parent&&e.add(t.parent),e),new Set).forEach(e=>{!n.some(t=>t.parent===e)&&e.layoutManager.unsubscribeTargets({target:e,targets:[t]})})}},wp=class e extends yd{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t=[],n={}){super(),Object.assign(this,e.ownDefaults),this.setOptions(n);let{left:r,top:i,layoutManager:a}=n;this.groupInit(t,{left:r,top:i,layoutManager:a??new Cp})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(...e){this.multiSelectionStacking===`selection-order`?this.add(...e):e.forEach(e=>{let t=this._objects.findIndex(t=>t.isInFrontOf(e)),n=t===-1?this.size():t;this.insertAt(n,e)})}canEnterGroup(e){return this.getObjects().some(t=>t.isDescendantOf(e)||e.isDescendantOf(t))?(Ea(`error`,`ActiveSelection: circular object trees are not supported, this call has no effect`),!1):super.canEnterGroup(e)}enterGroup(e,t){e.parent&&e.parent===e.group?e.parent._exitGroup(e):e.group&&e.parent!==e.group&&e.group.remove(e),this._enterGroup(e,t)}exitGroup(e,t){this._exitGroup(e,t),e.parent&&e.parent._enterGroup(e,!0)}_onAfterObjectsChange(e,t){super._onAfterObjectsChange(e,t);let n=new Set;t.forEach(e=>{let{parent:t}=e;t&&n.add(t)}),e===`removed`?n.forEach(e=>{e._onAfterObjectsChange(fd,t)}):n.forEach(e=>{e._set(`dirty`,!0)})}onDeselect(){return this.removeAll(),!1}toString(){return`#<ActiveSelection: (${this.complexity()})>`}shouldCache(){return!1}isOnACache(){return!1}_renderControls(e,t,n){e.save(),e.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;let r={hasControls:!1,...n,forActiveSelection:!0};for(let t=0;t<this._objects.length;t++)this._objects[t]._renderControls(e,r);super._renderControls(e,t),e.restore()}};Y(wp,`type`,`ActiveSelection`),Y(wp,`ownDefaults`,{multiSelectionStacking:`canvas-stacking`}),Z.setClass(wp),Z.setClass(wp,`activeSelection`);var Tp=class{constructor(){Y(this,`resources`,{})}applyFilters(e,t,n,r,i){let a=i.getContext(`2d`,{willReadFrequently:!0,desynchronized:!0});if(!a)return;a.drawImage(t,0,0,n,r);let o={sourceWidth:n,sourceHeight:r,imageData:a.getImageData(0,0,n,r),originalEl:t,originalImageData:a.getImageData(0,0,n,r),canvasEl:i,ctx:a,filterBackend:this};e.forEach(e=>{e.applyTo(o)});let{imageData:s}=o;return s.width===n&&s.height===r||(i.width=s.width,i.height=s.height),a.putImageData(s,0,0),o}},Ep=class{constructor({tileSize:e=X.textureSize}={}){Y(this,`aPosition`,new Float32Array([0,0,0,1,1,0,1,1])),Y(this,`resources`,{}),this.tileSize=e,this.setupGLContext(e,e),this.captureGPUInfo()}setupGLContext(e,t){this.dispose(),this.createWebGLCanvas(e,t)}createWebGLCanvas(e,t){let n=Mo({width:e,height:t}),r=n.getContext(`webgl`,{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});r&&(r.clearColor(0,0,0,0),this.canvas=n,this.gl=r)}applyFilters(e,t,n,r,i,a){let o=this.gl,s=i.getContext(`2d`);if(!o||!s)return;let c;a&&(c=this.getCachedTexture(a,t));let l={originalWidth:t.width||t.naturalWidth||0,originalHeight:t.height||t.naturalHeight||0,sourceWidth:n,sourceHeight:r,destinationWidth:n,destinationHeight:r,context:o,sourceTexture:this.createTexture(o,n,r,c?void 0:t),targetTexture:this.createTexture(o,n,r),originalTexture:c||this.createTexture(o,n,r,c?void 0:t),passes:e.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:i},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),e.forEach(e=>{e&&e.applyTo(l)}),function(e){let t=e.targetCanvas,n=t.width,r=t.height,i=e.destinationWidth,a=e.destinationHeight;n===i&&r===a||(t.width=i,t.height=a)}(l),this.copyGLTo2D(o,l),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(l.sourceTexture),o.deleteTexture(l.targetTexture),o.deleteFramebuffer(u),s.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(e,t,n,r,i){let{NEAREST:a,TEXTURE_2D:o,RGBA:s,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=e,m=e.createTexture();return e.bindTexture(o,m),e.texParameteri(o,u,i||a),e.texParameteri(o,d,i||a),e.texParameteri(o,f,l),e.texParameteri(o,p,l),r?e.texImage2D(o,0,s,s,c,r):e.texImage2D(o,0,s,t,n,0,s,c,null),m}getCachedTexture(e,t,n){let{textureCache:r}=this;if(r[e])return r[e];{let i=this.createTexture(this.gl,t.width,t.height,t,n);return i&&(r[e]=i),i}}evictCachesForKey(e){this.textureCache[e]&&(this.gl.deleteTexture(this.textureCache[e]),delete this.textureCache[e])}copyGLTo2D(e,t){let n=e.canvas,r=t.targetCanvas,i=r.getContext(`2d`);if(!i)return;i.translate(0,r.height),i.scale(1,-1);let a=n.height-r.height;i.drawImage(n,0,a,r.width,r.height,0,0,r.width,r.height)}copyGLTo2DPutImageData(e,t){let n=t.targetCanvas.getContext(`2d`),r=t.destinationWidth,i=t.destinationHeight,a=r*i*4;if(!n)return;let o=new Uint8Array(this.imageBuffer,0,a),s=new Uint8ClampedArray(this.imageBuffer,0,a);e.readPixels(0,0,r,i,e.RGBA,e.UNSIGNED_BYTE,o);let c=new ImageData(s,r,i);n.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;let e=this.gl,t={renderer:``,vendor:``};if(!e)return t;let n=e.getExtension(`WEBGL_debug_renderer_info`);if(n){let r=e.getParameter(n.UNMASKED_RENDERER_WEBGL),i=e.getParameter(n.UNMASKED_VENDOR_WEBGL);r&&(t.renderer=r.toLowerCase()),i&&(t.vendor=i.toLowerCase())}return this.gpuInfo=t,t}},Dp;function Op(){let{WebGLProbe:e}=Na();return e.queryWebGL(ko()),X.enableGLFiltering&&e.isSupported(X.textureSize)?new Ep({tileSize:X.textureSize}):new Tp}function kp(e=!0){return!Dp&&e&&(Dp=Op()),Dp}var Ap=[`cropX`,`cropY`],jp=class e extends Ou{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t,n){super(),Y(this,`_lastScaleX`,1),Y(this,`_lastScaleY`,1),Y(this,`_filterScalingX`,1),Y(this,`_filterScalingY`,1),this.filters=[],Object.assign(this,e.ownDefaults),this.setOptions(n),this.cacheKey=`texture${Oo()}`,this.setElement(typeof t==`string`?(this.canvas&&fs(this.canvas.getElement())||Pa()).getElementById(t):t,n)}getElement(){return this._element}setElement(e,t={}){this.removeTexture(this.cacheKey),this.removeTexture(`${this.cacheKey}_filtered`),this._element=e,this._originalElement=e,this._setWidthHeight(t),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(e){let t=kp(!1);t instanceof Ep&&t.evictCachesForKey(e)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture(`${this.cacheKey}_filtered`),this._cacheContext=null,[`_originalElement`,`_element`,`_filteredEl`,`_cacheCanvas`].forEach(e=>{let t=this[e];t&&Na().dispose(t),this[e]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){let e=this.getElement();return e?{width:e.naturalWidth||e.width,height:e.naturalHeight||e.height}:{width:0,height:0}}_stroke(e){if(!this.stroke||this.strokeWidth===0)return;let t=this.width/2,n=this.height/2;e.beginPath(),e.moveTo(-t,-n),e.lineTo(t,-n),e.lineTo(t,n),e.lineTo(-t,n),e.lineTo(-t,-n),e.closePath()}toObject(e=[]){let t=[];return this.filters.forEach(e=>{e&&t.push(e.toObject())}),{...super.toObject([...Ap,...e]),src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:t,...this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{}}}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){let e=[],t=this._element,n=-this.width/2,r=-this.height/2,i=[],a=[],o=``,s=``;if(!t)return[];if(this.hasCrop()){let e=Oo();i.push(`<clipPath id="imageCrop_`+e+`">
|
|
28
|
+
`,` <rect x="`+n+`" y="`+r+`" width="`+$(this.width)+`" height="`+$(this.height)+`" />
|
|
29
|
+
`,`</clipPath>
|
|
30
|
+
`),o=` clip-path="url(#imageCrop_`+e+`)" `}if(this.imageSmoothing||(s=` image-rendering="optimizeSpeed"`),e.push(` <image `,`COMMON_PARTS`,`xlink:href="${$(this.getSrc(!0))}" x="${n-this.cropX}" y="${r-this.cropY}" width="${t.width||t.naturalWidth}" height="${t.height||t.naturalHeight}"${s}${o}></image>\n`),this.stroke||this.strokeDashArray){let e=this.fill;this.fill=null,a=[`\t<rect x="${n}" y="${r}" width="${$(this.width)}" height="${$(this.height)}" style="${this.getSvgStyles()}" />\n`],this.fill=e}return i=this.paintFirst===`fill`?i.concat(e,a):i.concat(a,e),i}getSrc(e){let t=e?this._element:this._originalElement;return t?t.toDataURL?t.toDataURL():this.srcFromAttribute?t.getAttribute(`src`)||``:t.src:this.src||``}getSvgSrc(e){return this.getSrc(e)}setSrc(e,{crossOrigin:t,signal:n}={}){return es(e,{crossOrigin:t,signal:n}).then(e=>{t!==void 0&&this.set({crossOrigin:t}),this.setElement(e)})}toString(){return`#<Image: { src: "${this.getSrc()}" }>`}applyResizeFilters(){let e=this.resizeFilter,t=this.minimumScaleTrigger,n=this.getTotalObjectScaling(),r=n.x,i=n.y,a=this._filteredEl||this._originalElement;if(this.group&&this.set(`dirty`,!0),!e||r>t&&i>t)return this._element=a,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=r,void(this._lastScaleY=i);let o=Mo(a),{width:s,height:c}=a;this._element=o,this._lastScaleX=e.scaleX=r,this._lastScaleY=e.scaleY=i,kp().applyFilters([e],a,s,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(e=this.filters||[]){if(e=e.filter(e=>e&&!e.isNeutralState()),this.set(`dirty`,!0),this.removeTexture(`${this.cacheKey}_filtered`),e.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);let t=this._originalElement,n=t.naturalWidth||t.width,r=t.naturalHeight||t.height;if(this._element===this._originalElement){let e=Mo({width:n,height:r});this._element=e,this._filteredEl=e}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext(`2d`).clearRect(0,0,n,r),this._lastScaleX=1,this._lastScaleY=1);kp().applyFilters(e,this._originalElement,n,r,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(e){e.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(e),this._renderPaintInOrder(e)}drawCacheOnCanvas(e){e.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(e)}shouldCache(){return this.needsItsOwnCache()}_renderFill(e){let t=this._element;if(!t)return;let n=this._filterScalingX,r=this._filterScalingY,i=this.width,a=this.height,o=Math.max(this.cropX,0),s=Math.max(this.cropY,0),c=t.naturalWidth||t.width,l=t.naturalHeight||t.height,u=o*n,d=s*r,f=Math.min(i*n,c-u),p=Math.min(a*r,l-d),m=-i/2,h=-a/2,g=Math.min(i,c/n-o),_=Math.min(a,l/r-s);t&&e.drawImage(t,u,d,f,p,m,h,g,_)}_needsResize(){let e=this.getTotalObjectScaling();return e.x!==this._lastScaleX||e.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight({width:e,height:t}={}){let n=this.getOriginalSize();this.width=e||n.width,this.height=t||n.height}parsePreserveAspectRatioAttribute(){let e=Sc(this.preserveAspectRatio||``),t=this.width,n=this.height,r={width:t,height:n},i,a=this._element.width,o=this._element.height,s=1,c=1,l=0,u=0,d=0,f=0;return!e||e.alignX===`none`&&e.alignY===`none`?(s=t/a,c=n/o):(e.meetOrSlice===`meet`&&(s=c=xd(this._element,r),i=(t-a*s)/2,e.alignX===`Min`&&(l=-i),e.alignX===`Max`&&(l=i),i=(n-o*c)/2,e.alignY===`Min`&&(u=-i),e.alignY===`Max`&&(u=i)),e.meetOrSlice===`slice`&&(s=c=Sd(this._element,r),i=a-t/s,e.alignX===`Mid`&&(d=i/2),e.alignX===`Max`&&(d=i),i=o-n/c,e.alignY===`Mid`&&(f=i/2),e.alignY===`Max`&&(f=i),a=t/s,o=n/c)),{width:a,height:o,scaleX:s,scaleY:c,offsetLeft:l,offsetTop:u,cropX:d,cropY:f}}static fromObject({filters:e,resizeFilter:t,src:n,crossOrigin:r,type:i,...a},o){return Promise.all([es(n,{...o,crossOrigin:r}),e&&ts(e,o),t?ts([t],o):[],ns(a,o)]).then(([e,t=[],[r],i={}])=>new this(e,{...a,src:n,filters:t,resizeFilter:r,...i}))}static fromURL(e,{crossOrigin:t=null,signal:n}={},r){return es(e,{crossOrigin:t,signal:n}).then(e=>new this(e,r))}static async fromElement(e,t={},n){let r=cd(e,this.ATTRIBUTE_NAMES,n);return this.fromURL(r[`xlink:href`]||r.href,t,r).catch(e=>(Ea(`log`,`Unable to parse Image`,e),null))}};function Mp(e){if(!Uc.test(e.nodeName))return{};let t=e.getAttribute(`viewBox`),n,r,i=1,a=1,o=e.getAttribute(`width`),s=e.getAttribute(`height`),c=e.getAttribute(`x`)||0,l=e.getAttribute(`y`)||0,u=!(t&&Gc.test(t)),d=!o||!s||o===`100%`||s===`100%`,f=``,p=0,m=0;if(u&&(c||l)&&e.parentNode&&e.parentNode.nodeName!==`#document`&&(f=` translate(`+xc(c||`0`)+` `+xc(l||`0`)+`) `,n=(e.getAttribute(`transform`)||``)+f,e.setAttribute(`transform`,n),e.removeAttribute(`x`),e.removeAttribute(`y`)),u&&d)return{width:0,height:0};let h={width:0,height:0};if(u)return h.width=xc(o),h.height=xc(s),h;let g=t.match(Gc),_=-parseFloat(g[1]),v=-parseFloat(g[2]),y=parseFloat(g[3]),b=parseFloat(g[4]);h.minX=_,h.minY=v,h.viewBoxWidth=y,h.viewBoxHeight=b,d?(h.width=y,h.height=b):(h.width=xc(o),h.height=xc(s),i=h.width/y,a=h.height/b);let x=Sc(e.getAttribute(`preserveAspectRatio`)||``);if(x.alignX!==`none`&&(x.meetOrSlice===`meet`&&(a=i=i>a?a:i),x.meetOrSlice===`slice`&&(a=i=i>a?i:a),p=h.width-y*i,m=h.height-b*i,x.alignX===`Mid`&&(p/=2),x.alignY===`Mid`&&(m/=2),x.alignX===`Min`&&(p=0),x.alignY===`Min`&&(m=0)),i===1&&a===1&&_===0&&v===0&&c===0&&l===0)return h;if((c||l)&&e.parentNode.nodeName!==`#document`&&(f=` translate(`+xc(c||`0`)+` `+xc(l||`0`)+`) `),n=f+` matrix(`+i+` 0 0 `+a+` `+(_*i+p)+` `+(v*a+m)+`) `,e.nodeName===`svg`){for(r=e.ownerDocument.createElementNS(Lc,`g`);e.firstChild;)r.appendChild(e.firstChild);e.appendChild(r)}else r=e,r.removeAttribute(`x`),r.removeAttribute(`y`),n=r.getAttribute(`transform`)+n;return r.setAttribute(`transform`,n),h}Y(jp,`type`,`Image`),Y(jp,`cacheProperties`,[...Zc,...Ap]),Y(jp,`ownDefaults`,{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),Y(jp,`ATTRIBUTE_NAMES`,[...zu,`x`,`y`,`width`,`height`,`preserveAspectRatio`,`xlink:href`,`href`,`crossOrigin`,`image-rendering`]),Z.setClass(jp),Z.setSVGClass(jp);var Np=e=>e.tagName.replace(`svg:`,``),Pp=Tc([`pattern`,`defs`,`symbol`,`metadata`,`clipPath`,`mask`,`desc`]);function Fp(e,t){let n,r,i,a,o=[];for(i=0,a=t.length;i<a;i++)n=t[i],r=e.getElementsByTagNameNS(`http://www.w3.org/2000/svg`,n),o=o.concat(Array.from(r));return o}var Ip=[`gradientTransform`,`x1`,`x2`,`y1`,`y2`,`gradientUnits`,`cx`,`cy`,`r`,`fx`,`fy`],Lp=`xlink:href`;function Rp(e,t){let n=t.getAttribute(Lp)?.slice(1)||``,r=e.getElementById(n);if(r&&r.getAttribute(Lp)&&Rp(e,r),r&&(Ip.forEach(e=>{let n=r.getAttribute(e);!t.hasAttribute(e)&&n&&t.setAttribute(e,n)}),!t.children.length)){let e=r.cloneNode(!0);for(;e.firstChild;)t.appendChild(e.firstChild)}t.removeAttribute(Lp)}var zp=[`linearGradient`,`radialGradient`,`svg:linearGradient`,`svg:radialGradient`],Bp=e=>Z.getSVGClass(Np(e).toLowerCase()),Vp=class{constructor(e,t,n,r,i){this.elements=e,this.options=t,this.reviver=n,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=r,this.clipPaths=i,this.gradientDefs=function(e){let t=Fp(e,zp),n={},r=t.length;for(;r--;){let i=t[r];i.getAttribute(`xlink:href`)&&Rp(e,i);let a=i.getAttribute(`id`);a&&(n[a]=i)}return n}(r),this.cssRules=function(e){let t=e.getElementsByTagName(`style`),n={};for(let e=0;e<t.length;e++){let r=(t[e].textContent||``).replace(/\/\*[\s\S]*?\*\//g,``);r.trim()!==``&&r.split(`}`).filter((e,t,n)=>n.length>1&&e.trim()).forEach(e=>{if((e.match(/{/g)||[]).length>1&&e.trim().startsWith(`@`))return;let t=e.split(`{`),r={},i=t[1].trim().split(`;`).filter(function(e){return e.trim()});for(let e=0;e<i.length;e++){let t=i[e].split(`:`),n=t[0].trim();r[n]=t[1].trim()}(e=t[0].trim()).split(`,`).forEach(e=>{(e=e.replace(/^svg/i,``).trim())!==``&&(n[e]={...n[e]||{},...r})})})}return n}(r)}parse(){return Promise.all(this.elements.map(e=>this.createObject(e)))}async createObject(e){let t=Bp(e);if(t){let n=await t.fromElement(e,this.options,this.cssRules);return this.resolveGradient(n,e,uo),this.resolveGradient(n,e,fo),n instanceof jp&&n._originalElement?tf(n,n.parsePreserveAspectRatioAttribute()):tf(n),await this.resolveClipPath(n,e),this.reviver&&this.reviver(e,n),n}return null}extractPropertyDefinition(e,t,n){let r=e[t],i=this.regexUrl;if(!i.test(r))return;i.lastIndex=0;let a=i.exec(r)[1];return i.lastIndex=0,n[a]}resolveGradient(e,t,n){let r=this.extractPropertyDefinition(e,n,this.gradientDefs);if(r){let i=t.getAttribute(n+`-opacity`),a=Vf.fromElement(r,e,{...this.options,opacity:i});e.set(n,a)}}async resolveClipPath(e,t,n){let r=this.extractPropertyDefinition(e,`clipPath`,this.clipPaths);if(r){let i=zo(e.calcTransformMatrix()),a=r[0].parentElement,o=t;for(;!n&&o.parentElement&&o.getAttribute(`clip-path`)!==e.clipPath;)o=o.parentElement;o.parentElement.appendChild(a);let s=rd(`${o.getAttribute(`transform`)||``} ${a.getAttribute(`originalTransform`)||``}`);a.setAttribute(`transform`,`matrix(${s.join(`,`)})`);let c=await Promise.all(r.map(e=>Bp(e).fromElement(e,this.options,this.cssRules).then(e=>(tf(e),e.fillRule=e.clipRule,delete e.clipRule,e)))),l=c.length===1?c[0]:new yd(c),u=Bo(i,l.calcTransformMatrix());l.clipPath&&await this.resolveClipPath(l,o,a.getAttribute(`clip-path`)?o:void 0);let{scaleX:d,scaleY:f,angle:p,skewX:m,translateX:h,translateY:g}=Go(u);l.set({flipX:!1,flipY:!1}),l.set({scaleX:d,scaleY:f,angle:p,skewX:m,skewY:0}),l.setPositionByOrigin(new Q(h,g),Ga,Ga),e.clipPath=l}else delete e.clipPath}},Hp=e=>Hc.test(Np(e));async function Up(e,t,{crossOrigin:n,signal:r}={}){if(r&&r.aborted)return Ea(`log`,new Oa(`parseSVGDocument`)),{objects:[],elements:[],options:{},allElements:[]};let i=e.documentElement;(function(e){let t=Fp(e,[`use`,`svg:use`]),n=[`x`,`y`,`xlink:href`,`href`,`transform`];for(let r of t){let t=r.attributes,i={};for(let e of t)e.value&&(i[e.name]=e.value);let a=(i[`xlink:href`]||i.href||``).slice(1);if(a===``)return;let o=e.getElementById(a);if(o===null)return;let s=o.cloneNode(!0),c=s.attributes,l={};for(let e of c)e.value&&(l[e.name]=e.value);let{x:u=0,y:d=0,transform:f=``}=i,p=`${f} ${l.transform||``} translate(${u}, ${d})`;if(Mp(s),/^svg$/i.test(s.nodeName)){let e=s.ownerDocument.createElementNS(Lc,`g`);Object.entries(l).forEach(([t,n])=>e.setAttributeNS(Lc,t,n)),e.append(...s.childNodes),s=e}for(let e of t){if(!e)continue;let{name:t,value:r}=e;if(!n.includes(t))if(t===`style`){let e={};ad(r,e),Object.entries(l).forEach(([t,n])=>{e[t]=n}),ad(l.style||``,e);let n=Object.entries(e).map(e=>e.join(`:`)).join(`;`);s.setAttribute(t,n)}else!l[t]&&s.setAttribute(t,r)}s.setAttribute(`transform`,p),s.setAttribute(`instantiated_by_use`,`1`),s.removeAttribute(`id`),r.parentNode.replaceChild(s,r)}})(e);let a=Array.from(i.getElementsByTagName(`*`)),o={...Mp(i),crossOrigin:n,signal:r},s=a.filter(e=>(Mp(e),Hp(e)&&!function(e){let t=e;for(;t&&=t.parentElement;)if(t&&t.nodeName&&Pp.test(Np(t))&&!t.getAttribute(`instantiated_by_use`))return!0;return!1}(e)));if(!s||s&&!s.length)return{objects:[],elements:[],options:{},allElements:[],options:o,allElements:a};let c={};return a.filter(e=>Np(e)===`clipPath`).forEach(e=>{e.setAttribute(`originalTransform`,e.getAttribute(`transform`)||``);let t=e.getAttribute(`id`);c[t]=Array.from(e.getElementsByTagName(`*`)).filter(e=>Hp(e))}),{objects:await new Vp(s,o,t,e,c).parse(),elements:s,options:o,allElements:a}}function Wp(e,t,n){return Up(new(Fa()).DOMParser().parseFromString(e.trim(),`text/xml`),t,n)}function Gp(e,t,n={}){return fetch(e.replace(/^\n\s*/,``).trim(),{signal:n.signal}).then(e=>{if(!e.ok)throw new Da(`HTTP error! status: ${e.status}`);return e.text()}).then(e=>Wp(e,t,n)).catch(()=>({objects:[],elements:[],options:{},allElements:[]}))}var Kp=e=>e.webgl!==void 0,qp=`precision highp float`,Jp=`\n ${qp};\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }`,Yp=new RegExp(qp,`g`),Xp=class{get type(){return this.constructor.type}constructor({type:e,...t}={}){Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Jp}getVertexSource(){return`
|
|
31
|
+
attribute vec2 aPosition;
|
|
32
|
+
varying vec2 vTexCoord;
|
|
33
|
+
void main() {
|
|
34
|
+
vTexCoord = aPosition;
|
|
35
|
+
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
36
|
+
}`}createProgram(e,t=this.getFragmentSource(),n=this.getVertexSource()){let{WebGLProbe:{GLPrecision:r=`highp`}}=Na();r!==`highp`&&(t=t.replace(Yp,qp.replace(`highp`,r)));let i=e.createShader(e.VERTEX_SHADER),a=e.createShader(e.FRAGMENT_SHADER),o=e.createProgram();if(!i||!a||!o)throw new Da(`Vertex, fragment shader or program creation error`);if(e.shaderSource(i,n),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw new Da(`Vertex shader compile error for ${this.type}: ${e.getShaderInfoLog(i)}`);if(e.shaderSource(a,t),e.compileShader(a),!e.getShaderParameter(a,e.COMPILE_STATUS))throw new Da(`Fragment shader compile error for ${this.type}: ${e.getShaderInfoLog(a)}`);if(e.attachShader(o,i),e.attachShader(o,a),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS))throw new Da(`Shader link error for "${this.type}" ${e.getProgramInfoLog(o)}`);let s=this.getUniformLocations(e,o)||{};return s.uStepW=e.getUniformLocation(o,`uStepW`),s.uStepH=e.getUniformLocation(o,`uStepH`),{program:o,attributeLocations:this.getAttributeLocations(e,o),uniformLocations:s}}getAttributeLocations(e,t){return{aPosition:e.getAttribLocation(t,`aPosition`)}}getUniformLocations(e,t){let n=this.constructor.uniformLocations,r={};for(let i=0;i<n.length;i++)r[n[i]]=e.getUniformLocation(t,n[i]);return r}sendAttributeData(e,t,n){let r=t.aPosition,i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,n,e.STATIC_DRAW)}_setupFrameBuffer(e){let t=e.context;if(e.passes>1){let n=e.destinationWidth,r=e.destinationHeight;e.sourceWidth===n&&e.sourceHeight===r||(t.deleteTexture(e.targetTexture),e.targetTexture=e.filterBackend.createTexture(t,n,r)),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e.targetTexture,0)}else t.bindFramebuffer(t.FRAMEBUFFER,null),t.finish()}_swapTextures(e){e.passes--,e.pass++;let t=e.targetTexture;e.targetTexture=e.sourceTexture,e.sourceTexture=t}isNeutralState(e){return!1}applyTo(e){Kp(e)?(this._setupFrameBuffer(e),this.applyToWebGL(e),this._swapTextures(e)):this.applyTo2d(e)}applyTo2d(e){}getCacheKey(){return this.type}retrieveShader(e){let t=this.getCacheKey();return e.programCache[t]||(e.programCache[t]=this.createProgram(e.context)),e.programCache[t]}applyToWebGL(e){let t=e.context,n=this.retrieveShader(e);e.pass===0&&e.originalTexture?t.bindTexture(t.TEXTURE_2D,e.originalTexture):t.bindTexture(t.TEXTURE_2D,e.sourceTexture),t.useProgram(n.program),this.sendAttributeData(t,n.attributeLocations,e.aPosition),t.uniform1f(n.uniformLocations.uStepW,1/e.sourceWidth),t.uniform1f(n.uniformLocations.uStepH,1/e.sourceHeight),this.sendUniformData(t,n.uniformLocations),t.viewport(0,0,e.destinationWidth,e.destinationHeight),t.drawArrays(t.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(e,t,n){e.activeTexture(n),e.bindTexture(e.TEXTURE_2D,t),e.activeTexture(e.TEXTURE0)}unbindAdditionalTexture(e,t){e.activeTexture(t),e.bindTexture(e.TEXTURE_2D,null),e.activeTexture(e.TEXTURE0)}sendUniformData(e,t){}createHelpLayer(e){if(!e.helpLayer){let{sourceWidth:t,sourceHeight:n}=e;e.helpLayer=Mo({width:t,height:n})}}toObject(){let e=Object.keys(this.constructor.defaults||{});return{type:this.type,...e.reduce((e,t)=>(e[t]=this[t],e),{})}}toJSON(){return this.toObject()}static async fromObject({type:e,...t},n){return new this(t)}};Y(Xp,`type`,`BaseFilter`),Y(Xp,`uniformLocations`,[]);var Zp={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
37
|
+
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
38
|
+
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
39
|
+
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
40
|
+
`,subtract:`gl_FragColor.rgb -= uColor.rgb;
|
|
41
|
+
`,lighten:`gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);
|
|
42
|
+
`,darken:`gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);
|
|
43
|
+
`,exclusion:`gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);
|
|
44
|
+
`,overlay:`
|
|
45
|
+
if (uColor.r < 0.5) {
|
|
46
|
+
gl_FragColor.r *= 2.0 * uColor.r;
|
|
47
|
+
} else {
|
|
48
|
+
gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);
|
|
49
|
+
}
|
|
50
|
+
if (uColor.g < 0.5) {
|
|
51
|
+
gl_FragColor.g *= 2.0 * uColor.g;
|
|
52
|
+
} else {
|
|
53
|
+
gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);
|
|
54
|
+
}
|
|
55
|
+
if (uColor.b < 0.5) {
|
|
56
|
+
gl_FragColor.b *= 2.0 * uColor.b;
|
|
57
|
+
} else {
|
|
58
|
+
gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);
|
|
59
|
+
}
|
|
60
|
+
`,tint:`
|
|
61
|
+
gl_FragColor.rgb *= (1.0 - uColor.a);
|
|
62
|
+
gl_FragColor.rgb += uColor.rgb;
|
|
63
|
+
`},Qp=class extends Xp{getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n gl_FragColor = color;\n if (color.a > 0.0) {\n ${Zp[this.mode]}\n }\n }\n `}applyTo2d({imageData:{data:e}}){let t=new yc(this.color).getSource(),n=this.alpha,r=t[0]*n,i=t[1]*n,a=t[2]*n,o=1-n;for(let t=0;t<e.length;t+=4){let n=e[t],s=e[t+1],c=e[t+2],l,u,d;switch(this.mode){case`multiply`:l=n*r/255,u=s*i/255,d=c*a/255;break;case`screen`:l=255-(255-n)*(255-r)/255,u=255-(255-s)*(255-i)/255,d=255-(255-c)*(255-a)/255;break;case`add`:l=n+r,u=s+i,d=c+a;break;case`difference`:l=Math.abs(n-r),u=Math.abs(s-i),d=Math.abs(c-a);break;case`subtract`:l=n-r,u=s-i,d=c-a;break;case`darken`:l=Math.min(n,r),u=Math.min(s,i),d=Math.min(c,a);break;case`lighten`:l=Math.max(n,r),u=Math.max(s,i),d=Math.max(c,a);break;case`overlay`:l=r<128?2*n*r/255:255-2*(255-n)*(255-r)/255,u=i<128?2*s*i/255:255-2*(255-s)*(255-i)/255,d=a<128?2*c*a/255:255-2*(255-c)*(255-a)/255;break;case`exclusion`:l=r+n-2*r*n/255,u=i+s-2*i*s/255,d=a+c-2*a*c/255;break;case`tint`:l=r+n*o,u=i+s*o,d=a+c*o}e[t]=l,e[t+1]=u,e[t+2]=d}}sendUniformData(e,t){let n=new yc(this.color).getSource();n[0]=this.alpha*n[0]/255,n[1]=this.alpha*n[1]/255,n[2]=this.alpha*n[2]/255,n[3]=this.alpha,e.uniform4fv(t.uColor,n)}};Y(Qp,`defaults`,{color:`#F95C63`,mode:`multiply`,alpha:1}),Y(Qp,`type`,`BlendColor`),Y(Qp,`uniformLocations`,[`uColor`]),Z.setClass(Qp);var $p={multiply:`
|
|
64
|
+
precision highp float;
|
|
65
|
+
uniform sampler2D uTexture;
|
|
66
|
+
uniform sampler2D uImage;
|
|
67
|
+
uniform vec4 uColor;
|
|
68
|
+
varying vec2 vTexCoord;
|
|
69
|
+
varying vec2 vTexCoord2;
|
|
70
|
+
void main() {
|
|
71
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
72
|
+
vec4 color2 = texture2D(uImage, vTexCoord2);
|
|
73
|
+
color.rgba *= color2.rgba;
|
|
74
|
+
gl_FragColor = color;
|
|
75
|
+
}
|
|
76
|
+
`,mask:`
|
|
77
|
+
precision highp float;
|
|
78
|
+
uniform sampler2D uTexture;
|
|
79
|
+
uniform sampler2D uImage;
|
|
80
|
+
uniform vec4 uColor;
|
|
81
|
+
varying vec2 vTexCoord;
|
|
82
|
+
varying vec2 vTexCoord2;
|
|
83
|
+
void main() {
|
|
84
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
85
|
+
vec4 color2 = texture2D(uImage, vTexCoord2);
|
|
86
|
+
color.a = color2.a;
|
|
87
|
+
gl_FragColor = color;
|
|
88
|
+
}
|
|
89
|
+
`},em=class extends Xp{getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return $p[this.mode]}getVertexSource(){return`
|
|
90
|
+
attribute vec2 aPosition;
|
|
91
|
+
varying vec2 vTexCoord;
|
|
92
|
+
varying vec2 vTexCoord2;
|
|
93
|
+
uniform mat3 uTransformMatrix;
|
|
94
|
+
void main() {
|
|
95
|
+
vTexCoord = aPosition;
|
|
96
|
+
vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
|
|
97
|
+
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
98
|
+
}
|
|
99
|
+
`}applyToWebGL(e){let t=e.context,n=this.createTexture(e.filterBackend,this.image);this.bindAdditionalTexture(t,n,t.TEXTURE1),super.applyToWebGL(e),this.unbindAdditionalTexture(t,t.TEXTURE1)}createTexture(e,t){return e.getCachedTexture(t.cacheKey,t.getElement())}calculateMatrix(){let e=this.image,{width:t,height:n}=e.getElement();return[1/e.scaleX,0,0,0,1/e.scaleY,0,-e.left/t,-e.top/n,1]}applyTo2d({imageData:{data:e,width:t,height:n},filterBackend:{resources:r}}){let i=this.image;r.blendImage||=ko();let a=r.blendImage,o=a.getContext(`2d`);a.width!==t||a.height!==n?(a.width=t,a.height=n):o.clearRect(0,0,t,n),o.setTransform(i.scaleX,0,0,i.scaleY,i.left,i.top),o.drawImage(i.getElement(),0,0,t,n);let s=o.getImageData(0,0,t,n).data;for(let t=0;t<e.length;t+=4){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3],o=s[t],c=s[t+1],l=s[t+2],u=s[t+3];switch(this.mode){case`multiply`:e[t]=n*o/255,e[t+1]=r*c/255,e[t+2]=i*l/255,e[t+3]=a*u/255;break;case`mask`:e[t+3]=u}}}sendUniformData(e,t){let n=this.calculateMatrix();e.uniform1i(t.uImage,1),e.uniformMatrix3fv(t.uTransformMatrix,!1,n)}toObject(){return{...super.toObject(),image:this.image&&this.image.toObject()}}static async fromObject({type:e,image:t,...n},r){return jp.fromObject(t,r).then(e=>new this({...n,image:e}))}};Y(em,`type`,`BlendImage`),Y(em,`defaults`,{mode:`multiply`,alpha:1}),Y(em,`uniformLocations`,[`uTransformMatrix`,`uImage`]),Z.setClass(em);var tm=class extends Xp{getFragmentSource(){return`
|
|
100
|
+
precision highp float;
|
|
101
|
+
uniform sampler2D uTexture;
|
|
102
|
+
uniform vec2 uDelta;
|
|
103
|
+
varying vec2 vTexCoord;
|
|
104
|
+
const float nSamples = 15.0;
|
|
105
|
+
vec3 v3offset = vec3(12.9898, 78.233, 151.7182);
|
|
106
|
+
float random(vec3 scale) {
|
|
107
|
+
/* use the fragment position for a different seed per-pixel */
|
|
108
|
+
return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);
|
|
109
|
+
}
|
|
110
|
+
void main() {
|
|
111
|
+
vec4 color = vec4(0.0);
|
|
112
|
+
float totalC = 0.0;
|
|
113
|
+
float totalA = 0.0;
|
|
114
|
+
float offset = random(v3offset);
|
|
115
|
+
for (float t = -nSamples; t <= nSamples; t++) {
|
|
116
|
+
float percent = (t + offset - 0.5) / nSamples;
|
|
117
|
+
vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);
|
|
118
|
+
float weight = 1.0 - abs(percent);
|
|
119
|
+
float alpha = weight * sample.a;
|
|
120
|
+
color.rgb += sample.rgb * alpha;
|
|
121
|
+
color.a += alpha;
|
|
122
|
+
totalA += weight;
|
|
123
|
+
totalC += alpha;
|
|
124
|
+
}
|
|
125
|
+
gl_FragColor.rgb = color.rgb / totalC;
|
|
126
|
+
gl_FragColor.a = color.a / totalA;
|
|
127
|
+
}
|
|
128
|
+
`}applyTo(e){Kp(e)?(this.aspectRatio=e.sourceWidth/e.sourceHeight,e.passes++,this._setupFrameBuffer(e),this.horizontal=!0,this.applyToWebGL(e),this._swapTextures(e),this._setupFrameBuffer(e),this.horizontal=!1,this.applyToWebGL(e),this._swapTextures(e)):this.applyTo2d(e)}applyTo2d({imageData:{data:e,width:t,height:n}}){this.aspectRatio=t/n,this.horizontal=!0;let r=this.getBlurValue()*t,i=new Uint8ClampedArray(e),a=4*t;for(let t=0;t<e.length;t+=4){let n=0,o=0,s=0,c=0,l=0,u=t-t%a,d=u+a;for(let i=-14;i<15;i++){let a=i/15,f=4*Math.floor(r*a),p=1-Math.abs(a),m=t+f;m<u?m=u:m>d&&(m=d);let h=e[m+3]*p;n+=e[m]*h,o+=e[m+1]*h,s+=e[m+2]*h,c+=h,l+=p}i[t]=n/c,i[t+1]=o/c,i[t+2]=s/c,i[t+3]=c/l}this.horizontal=!1,r=this.getBlurValue()*n;for(let t=0;t<i.length;t+=4){let n=0,o=0,s=0,c=0,l=0,u=t%a,d=i.length-a+u;for(let e=-14;e<15;e++){let f=e/15,p=Math.floor(r*f)*a,m=1-Math.abs(f),h=t+p;h<u?h=u:h>d&&(h=d);let g=i[h+3]*m;n+=i[h]*g,o+=i[h+1]*g,s+=i[h+2]*g,c+=g,l+=m}e[t]=n/c,e[t+1]=o/c,e[t+2]=s/c,e[t+3]=c/l}}sendUniformData(e,t){let n=this.chooseRightDelta();e.uniform2fv(t.uDelta,n)}isNeutralState(){return this.blur===0}getBlurValue(){let e=1,{horizontal:t,aspectRatio:n}=this;return t?n>1&&(e=1/n):n<1&&(e=n),e*this.blur*.12}chooseRightDelta(){let e=this.getBlurValue();return this.horizontal?[e,0]:[0,e]}};Y(tm,`type`,`Blur`),Y(tm,`defaults`,{blur:0}),Y(tm,`uniformLocations`,[`uDelta`]),Z.setClass(tm);var nm=class extends Xp{getFragmentSource(){return`
|
|
129
|
+
precision highp float;
|
|
130
|
+
uniform sampler2D uTexture;
|
|
131
|
+
uniform float uBrightness;
|
|
132
|
+
varying vec2 vTexCoord;
|
|
133
|
+
void main() {
|
|
134
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
135
|
+
color.rgb += uBrightness;
|
|
136
|
+
gl_FragColor = color;
|
|
137
|
+
}
|
|
138
|
+
`}applyTo2d({imageData:{data:e}}){let t=Math.round(255*this.brightness);for(let n=0;n<e.length;n+=4)e[n]+=t,e[n+1]+=t,e[n+2]+=t}isNeutralState(){return this.brightness===0}sendUniformData(e,t){e.uniform1f(t.uBrightness,this.brightness)}};Y(nm,`type`,`Brightness`),Y(nm,`defaults`,{brightness:0}),Y(nm,`uniformLocations`,[`uBrightness`]),Z.setClass(nm);var rm={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0},im=class extends Xp{getFragmentSource(){return`
|
|
139
|
+
precision highp float;
|
|
140
|
+
uniform sampler2D uTexture;
|
|
141
|
+
varying vec2 vTexCoord;
|
|
142
|
+
uniform mat4 uColorMatrix;
|
|
143
|
+
uniform vec4 uConstants;
|
|
144
|
+
void main() {
|
|
145
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
146
|
+
color *= uColorMatrix;
|
|
147
|
+
color += uConstants;
|
|
148
|
+
gl_FragColor = color;
|
|
149
|
+
}`}applyTo2d(e){let t=e.imageData.data,n=this.matrix,r=this.colorsOnly;for(let e=0;e<t.length;e+=4){let i=t[e],a=t[e+1],o=t[e+2];if(t[e]=i*n[0]+a*n[1]+o*n[2]+255*n[4],t[e+1]=i*n[5]+a*n[6]+o*n[7]+255*n[9],t[e+2]=i*n[10]+a*n[11]+o*n[12]+255*n[14],!r){let r=t[e+3];t[e]+=r*n[3],t[e+1]+=r*n[8],t[e+2]+=r*n[13],t[e+3]=i*n[15]+a*n[16]+o*n[17]+r*n[18]+255*n[19]}}}sendUniformData(e,t){let n=this.matrix,r=[n[0],n[1],n[2],n[3],n[5],n[6],n[7],n[8],n[10],n[11],n[12],n[13],n[15],n[16],n[17],n[18]],i=[n[4],n[9],n[14],n[19]];e.uniformMatrix4fv(t.uColorMatrix,!1,r),e.uniform4fv(t.uConstants,i)}toObject(){return{...super.toObject(),matrix:[...this.matrix]}}};function am(e,t){var n;let r=(Y(n=class extends im{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},`type`,e),Y(n,`defaults`,{colorsOnly:!1,matrix:t}),n);return Z.setClass(r,e),r}Y(im,`type`,`ColorMatrix`),Y(im,`defaults`,rm),Y(im,`uniformLocations`,[`uColorMatrix`,`uConstants`]),Z.setClass(im);var om=am(`Brownie`,[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),sm=am(`Vintage`,[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),cm=am(`Kodachrome`,[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),lm=am(`Technicolor`,[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),um=am(`Polaroid`,[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),dm=am(`Sepia`,[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),fm=am(`BlackWhite`,[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]),pm=class extends Xp{constructor(e={}){super(e),this.subFilters=e.subFilters||[]}applyTo(e){Kp(e)&&(e.passes+=this.subFilters.length-1),this.subFilters.forEach(t=>{t.applyTo(e)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(e=>e.toObject())}}isNeutralState(){return!this.subFilters.some(e=>!e.isNeutralState())}static fromObject(e,t){return Promise.all((e.subFilters||[]).map(e=>Z.getClass(e.type).fromObject(e,t))).then(e=>new this({subFilters:e}))}};Y(pm,`type`,`Composed`),Z.setClass(pm);var mm=class extends Xp{getFragmentSource(){return`
|
|
150
|
+
precision highp float;
|
|
151
|
+
uniform sampler2D uTexture;
|
|
152
|
+
uniform float uContrast;
|
|
153
|
+
varying vec2 vTexCoord;
|
|
154
|
+
void main() {
|
|
155
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
156
|
+
float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
|
|
157
|
+
color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
|
|
158
|
+
gl_FragColor = color;
|
|
159
|
+
}`}isNeutralState(){return this.contrast===0}applyTo2d({imageData:{data:e}}){let t=Math.floor(255*this.contrast),n=259*(t+255)/(255*(259-t));for(let t=0;t<e.length;t+=4)e[t]=n*(e[t]-128)+128,e[t+1]=n*(e[t+1]-128)+128,e[t+2]=n*(e[t+2]-128)+128}sendUniformData(e,t){e.uniform1f(t.uContrast,this.contrast)}};Y(mm,`type`,`Contrast`),Y(mm,`defaults`,{contrast:0}),Y(mm,`uniformLocations`,[`uContrast`]),Z.setClass(mm);var hm={Convolute_3_1:`
|
|
160
|
+
precision highp float;
|
|
161
|
+
uniform sampler2D uTexture;
|
|
162
|
+
uniform float uMatrix[9];
|
|
163
|
+
uniform float uStepW;
|
|
164
|
+
uniform float uStepH;
|
|
165
|
+
varying vec2 vTexCoord;
|
|
166
|
+
void main() {
|
|
167
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
168
|
+
for (float h = 0.0; h < 3.0; h+=1.0) {
|
|
169
|
+
for (float w = 0.0; w < 3.0; w+=1.0) {
|
|
170
|
+
vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));
|
|
171
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
gl_FragColor = color;
|
|
175
|
+
}
|
|
176
|
+
`,Convolute_3_0:`
|
|
177
|
+
precision highp float;
|
|
178
|
+
uniform sampler2D uTexture;
|
|
179
|
+
uniform float uMatrix[9];
|
|
180
|
+
uniform float uStepW;
|
|
181
|
+
uniform float uStepH;
|
|
182
|
+
varying vec2 vTexCoord;
|
|
183
|
+
void main() {
|
|
184
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
185
|
+
for (float h = 0.0; h < 3.0; h+=1.0) {
|
|
186
|
+
for (float w = 0.0; w < 3.0; w+=1.0) {
|
|
187
|
+
vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));
|
|
188
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
192
|
+
gl_FragColor = color;
|
|
193
|
+
gl_FragColor.a = alpha;
|
|
194
|
+
}
|
|
195
|
+
`,Convolute_5_1:`
|
|
196
|
+
precision highp float;
|
|
197
|
+
uniform sampler2D uTexture;
|
|
198
|
+
uniform float uMatrix[25];
|
|
199
|
+
uniform float uStepW;
|
|
200
|
+
uniform float uStepH;
|
|
201
|
+
varying vec2 vTexCoord;
|
|
202
|
+
void main() {
|
|
203
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
204
|
+
for (float h = 0.0; h < 5.0; h+=1.0) {
|
|
205
|
+
for (float w = 0.0; w < 5.0; w+=1.0) {
|
|
206
|
+
vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
|
|
207
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
gl_FragColor = color;
|
|
211
|
+
}
|
|
212
|
+
`,Convolute_5_0:`
|
|
213
|
+
precision highp float;
|
|
214
|
+
uniform sampler2D uTexture;
|
|
215
|
+
uniform float uMatrix[25];
|
|
216
|
+
uniform float uStepW;
|
|
217
|
+
uniform float uStepH;
|
|
218
|
+
varying vec2 vTexCoord;
|
|
219
|
+
void main() {
|
|
220
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
221
|
+
for (float h = 0.0; h < 5.0; h+=1.0) {
|
|
222
|
+
for (float w = 0.0; w < 5.0; w+=1.0) {
|
|
223
|
+
vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
|
|
224
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
228
|
+
gl_FragColor = color;
|
|
229
|
+
gl_FragColor.a = alpha;
|
|
230
|
+
}
|
|
231
|
+
`,Convolute_7_1:`
|
|
232
|
+
precision highp float;
|
|
233
|
+
uniform sampler2D uTexture;
|
|
234
|
+
uniform float uMatrix[49];
|
|
235
|
+
uniform float uStepW;
|
|
236
|
+
uniform float uStepH;
|
|
237
|
+
varying vec2 vTexCoord;
|
|
238
|
+
void main() {
|
|
239
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
240
|
+
for (float h = 0.0; h < 7.0; h+=1.0) {
|
|
241
|
+
for (float w = 0.0; w < 7.0; w+=1.0) {
|
|
242
|
+
vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
|
|
243
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
gl_FragColor = color;
|
|
247
|
+
}
|
|
248
|
+
`,Convolute_7_0:`
|
|
249
|
+
precision highp float;
|
|
250
|
+
uniform sampler2D uTexture;
|
|
251
|
+
uniform float uMatrix[49];
|
|
252
|
+
uniform float uStepW;
|
|
253
|
+
uniform float uStepH;
|
|
254
|
+
varying vec2 vTexCoord;
|
|
255
|
+
void main() {
|
|
256
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
257
|
+
for (float h = 0.0; h < 7.0; h+=1.0) {
|
|
258
|
+
for (float w = 0.0; w < 7.0; w+=1.0) {
|
|
259
|
+
vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
|
|
260
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
264
|
+
gl_FragColor = color;
|
|
265
|
+
gl_FragColor.a = alpha;
|
|
266
|
+
}
|
|
267
|
+
`,Convolute_9_1:`
|
|
268
|
+
precision highp float;
|
|
269
|
+
uniform sampler2D uTexture;
|
|
270
|
+
uniform float uMatrix[81];
|
|
271
|
+
uniform float uStepW;
|
|
272
|
+
uniform float uStepH;
|
|
273
|
+
varying vec2 vTexCoord;
|
|
274
|
+
void main() {
|
|
275
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
276
|
+
for (float h = 0.0; h < 9.0; h+=1.0) {
|
|
277
|
+
for (float w = 0.0; w < 9.0; w+=1.0) {
|
|
278
|
+
vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
|
|
279
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
gl_FragColor = color;
|
|
283
|
+
}
|
|
284
|
+
`,Convolute_9_0:`
|
|
285
|
+
precision highp float;
|
|
286
|
+
uniform sampler2D uTexture;
|
|
287
|
+
uniform float uMatrix[81];
|
|
288
|
+
uniform float uStepW;
|
|
289
|
+
uniform float uStepH;
|
|
290
|
+
varying vec2 vTexCoord;
|
|
291
|
+
void main() {
|
|
292
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
293
|
+
for (float h = 0.0; h < 9.0; h+=1.0) {
|
|
294
|
+
for (float w = 0.0; w < 9.0; w+=1.0) {
|
|
295
|
+
vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
|
|
296
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
300
|
+
gl_FragColor = color;
|
|
301
|
+
gl_FragColor.a = alpha;
|
|
302
|
+
}
|
|
303
|
+
`},gm=class extends Xp{getCacheKey(){return`${this.type}_${Math.sqrt(this.matrix.length)}_${+!!this.opaque}`}getFragmentSource(){return hm[this.getCacheKey()]}applyTo2d(e){let t=e.imageData,n=t.data,r=this.matrix,i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=t.width,s=t.height,c=e.ctx.createImageData(o,s),l=c.data,u=+!!this.opaque,d,f,p,m,h,g,_,v,y,b,x,S,C;for(x=0;x<s;x++)for(b=0;b<o;b++){for(h=4*(x*o+b),d=0,f=0,p=0,m=0,C=0;C<i;C++)for(S=0;S<i;S++)_=x+C-a,g=b+S-a,_<0||_>=s||g<0||g>=o||(v=4*(_*o+g),y=r[C*i+S],d+=n[v]*y,f+=n[v+1]*y,p+=n[v+2]*y,u||(m+=n[v+3]*y));l[h]=d,l[h+1]=f,l[h+2]=p,l[h+3]=u?n[h+3]:m}e.imageData=c}sendUniformData(e,t){e.uniform1fv(t.uMatrix,this.matrix)}toObject(){return{...super.toObject(),opaque:this.opaque,matrix:[...this.matrix]}}};Y(gm,`type`,`Convolute`),Y(gm,`defaults`,{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),Y(gm,`uniformLocations`,[`uMatrix`,`uOpaque`,`uHalfSize`,`uSize`]),Z.setClass(gm);var _m=`Gamma`,vm=class extends Xp{getFragmentSource(){return`
|
|
304
|
+
precision highp float;
|
|
305
|
+
uniform sampler2D uTexture;
|
|
306
|
+
uniform vec3 uGamma;
|
|
307
|
+
varying vec2 vTexCoord;
|
|
308
|
+
void main() {
|
|
309
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
310
|
+
vec3 correction = (1.0 / uGamma);
|
|
311
|
+
color.r = pow(color.r, correction.r);
|
|
312
|
+
color.g = pow(color.g, correction.g);
|
|
313
|
+
color.b = pow(color.b, correction.b);
|
|
314
|
+
gl_FragColor = color;
|
|
315
|
+
gl_FragColor.rgb *= color.a;
|
|
316
|
+
}
|
|
317
|
+
`}constructor(e={}){super(e),this.gamma=e.gamma||this.constructor.defaults.gamma.concat()}applyTo2d({imageData:{data:e}}){let t=this.gamma,n=1/t[0],r=1/t[1],i=1/t[2];this.rgbValues||={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)};let a=this.rgbValues;for(let e=0;e<256;e++)a.r[e]=255*(e/255)**n,a.g[e]=255*(e/255)**r,a.b[e]=255*(e/255)**i;for(let t=0;t<e.length;t+=4)e[t]=a.r[e[t]],e[t+1]=a.g[e[t+1]],e[t+2]=a.b[e[t+2]]}sendUniformData(e,t){e.uniform3fv(t.uGamma,this.gamma)}isNeutralState(){let{gamma:e}=this;return e[0]===1&&e[1]===1&&e[2]===1}toObject(){return{type:_m,gamma:this.gamma.concat()}}};Y(vm,`type`,_m),Y(vm,`defaults`,{gamma:[1,1,1]}),Y(vm,`uniformLocations`,[`uGamma`]),Z.setClass(vm);var ym={average:`
|
|
318
|
+
precision highp float;
|
|
319
|
+
uniform sampler2D uTexture;
|
|
320
|
+
varying vec2 vTexCoord;
|
|
321
|
+
void main() {
|
|
322
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
323
|
+
float average = (color.r + color.b + color.g) / 3.0;
|
|
324
|
+
gl_FragColor = vec4(average, average, average, color.a);
|
|
325
|
+
}
|
|
326
|
+
`,lightness:`
|
|
327
|
+
precision highp float;
|
|
328
|
+
uniform sampler2D uTexture;
|
|
329
|
+
uniform int uMode;
|
|
330
|
+
varying vec2 vTexCoord;
|
|
331
|
+
void main() {
|
|
332
|
+
vec4 col = texture2D(uTexture, vTexCoord);
|
|
333
|
+
float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;
|
|
334
|
+
gl_FragColor = vec4(average, average, average, col.a);
|
|
335
|
+
}
|
|
336
|
+
`,luminosity:`
|
|
337
|
+
precision highp float;
|
|
338
|
+
uniform sampler2D uTexture;
|
|
339
|
+
uniform int uMode;
|
|
340
|
+
varying vec2 vTexCoord;
|
|
341
|
+
void main() {
|
|
342
|
+
vec4 col = texture2D(uTexture, vTexCoord);
|
|
343
|
+
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
344
|
+
gl_FragColor = vec4(average, average, average, col.a);
|
|
345
|
+
}
|
|
346
|
+
`},bm=class extends Xp{applyTo2d({imageData:{data:e}}){for(let t,n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2];switch(this.mode){case`average`:t=(r+i+a)/3;break;case`lightness`:t=(Math.min(r,i,a)+Math.max(r,i,a))/2;break;case`luminosity`:t=.21*r+.72*i+.07*a}e[n+2]=e[n+1]=e[n]=t}}getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return ym[this.mode]}sendUniformData(e,t){e.uniform1i(t.uMode,1)}isNeutralState(){return!1}};Y(bm,`type`,`Grayscale`),Y(bm,`defaults`,{mode:`average`}),Y(bm,`uniformLocations`,[`uMode`]),Z.setClass(bm);var xm={...rm,rotation:0},Sm=class extends im{calculateMatrix(){let e=this.rotation*Math.PI,t=yo(e),n=bo(e),r=1/3,i=Math.sqrt(r)*n,a=1-t;this.matrix=[t+a/3,r*a-i,r*a+i,0,0,r*a+i,t+r*a,r*a-i,0,0,r*a-i,r*a+i,t+r*a,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(e){this.calculateMatrix(),super.applyTo(e)}toObject(){return{type:this.type,rotation:this.rotation}}};Y(Sm,`type`,`HueRotation`),Y(Sm,`defaults`,xm),Z.setClass(Sm);var Cm=class extends Xp{applyTo2d({imageData:{data:e}}){for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return`
|
|
347
|
+
precision highp float;
|
|
348
|
+
uniform sampler2D uTexture;
|
|
349
|
+
uniform int uInvert;
|
|
350
|
+
uniform int uAlpha;
|
|
351
|
+
varying vec2 vTexCoord;
|
|
352
|
+
void main() {
|
|
353
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
354
|
+
if (uInvert == 1) {
|
|
355
|
+
if (uAlpha == 1) {
|
|
356
|
+
gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);
|
|
357
|
+
} else {
|
|
358
|
+
gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
gl_FragColor = color;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
`}isNeutralState(){return!this.invert}sendUniformData(e,t){e.uniform1i(t.uInvert,Number(this.invert)),e.uniform1i(t.uAlpha,Number(this.alpha))}};Y(Cm,`type`,`Invert`),Y(Cm,`defaults`,{alpha:!1,invert:!0}),Y(Cm,`uniformLocations`,[`uInvert`,`uAlpha`]),Z.setClass(Cm);var wm=class extends Xp{getFragmentSource(){return`
|
|
365
|
+
precision highp float;
|
|
366
|
+
uniform sampler2D uTexture;
|
|
367
|
+
uniform float uStepH;
|
|
368
|
+
uniform float uNoise;
|
|
369
|
+
uniform float uSeed;
|
|
370
|
+
varying vec2 vTexCoord;
|
|
371
|
+
float rand(vec2 co, float seed, float vScale) {
|
|
372
|
+
return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);
|
|
373
|
+
}
|
|
374
|
+
void main() {
|
|
375
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
376
|
+
color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
|
|
377
|
+
gl_FragColor = color;
|
|
378
|
+
}
|
|
379
|
+
`}applyTo2d({imageData:{data:e}}){let t=this.noise;for(let n=0;n<e.length;n+=4){let r=(.5-Math.random())*t;e[n]+=r,e[n+1]+=r,e[n+2]+=r}}sendUniformData(e,t){e.uniform1f(t.uNoise,this.noise/255),e.uniform1f(t.uSeed,Math.random())}isNeutralState(){return this.noise===0}};Y(wm,`type`,`Noise`),Y(wm,`defaults`,{noise:0}),Y(wm,`uniformLocations`,[`uNoise`,`uSeed`]),Z.setClass(wm);var Tm=class extends Xp{applyTo2d({imageData:{data:e,width:t,height:n}}){for(let r=0;r<n;r+=this.blocksize)for(let i=0;i<t;i+=this.blocksize){let a=4*r*t+4*i,o=e[a],s=e[a+1],c=e[a+2],l=e[a+3];for(let a=r;a<Math.min(r+this.blocksize,n);a++)for(let n=i;n<Math.min(i+this.blocksize,t);n++){let r=4*a*t+4*n;e[r]=o,e[r+1]=s,e[r+2]=c,e[r+3]=l}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
|
|
380
|
+
precision highp float;
|
|
381
|
+
uniform sampler2D uTexture;
|
|
382
|
+
uniform float uBlocksize;
|
|
383
|
+
uniform float uStepW;
|
|
384
|
+
uniform float uStepH;
|
|
385
|
+
varying vec2 vTexCoord;
|
|
386
|
+
void main() {
|
|
387
|
+
float blockW = uBlocksize * uStepW;
|
|
388
|
+
float blockH = uBlocksize * uStepH;
|
|
389
|
+
int posX = int(vTexCoord.x / blockW);
|
|
390
|
+
int posY = int(vTexCoord.y / blockH);
|
|
391
|
+
float fposX = float(posX);
|
|
392
|
+
float fposY = float(posY);
|
|
393
|
+
vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);
|
|
394
|
+
vec4 color = texture2D(uTexture, squareCoords);
|
|
395
|
+
gl_FragColor = color;
|
|
396
|
+
}
|
|
397
|
+
`}sendUniformData(e,t){e.uniform1f(t.uBlocksize,this.blocksize)}};Y(Tm,`type`,`Pixelate`),Y(Tm,`defaults`,{blocksize:4}),Y(Tm,`uniformLocations`,[`uBlocksize`]),Z.setClass(Tm);var Em=class extends Xp{getFragmentSource(){return`
|
|
398
|
+
precision highp float;
|
|
399
|
+
uniform sampler2D uTexture;
|
|
400
|
+
uniform vec4 uLow;
|
|
401
|
+
uniform vec4 uHigh;
|
|
402
|
+
varying vec2 vTexCoord;
|
|
403
|
+
void main() {
|
|
404
|
+
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
405
|
+
if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {
|
|
406
|
+
gl_FragColor.a = 0.0;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
`}applyTo2d({imageData:{data:e}}){let t=255*this.distance,n=new yc(this.color).getSource(),r=[n[0]-t,n[1]-t,n[2]-t],i=[n[0]+t,n[1]+t,n[2]+t];for(let t=0;t<e.length;t+=4){let n=e[t],a=e[t+1],o=e[t+2];n>r[0]&&a>r[1]&&o>r[2]&&n<i[0]&&a<i[1]&&o<i[2]&&(e[t+3]=0)}}sendUniformData(e,t){let n=new yc(this.color).getSource(),r=this.distance,i=[0+n[0]/255-r,0+n[1]/255-r,0+n[2]/255-r,1],a=[n[0]/255+r,n[1]/255+r,n[2]/255+r,1];e.uniform4fv(t.uLow,i),e.uniform4fv(t.uHigh,a)}};Y(Em,`type`,`RemoveColor`),Y(Em,`defaults`,{color:`#FFFFFF`,distance:.02,useAlpha:!1}),Y(Em,`uniformLocations`,[`uLow`,`uHigh`]),Z.setClass(Em);var Dm=class extends Xp{sendUniformData(e,t){e.uniform2fv(t.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),e.uniform1fv(t.uTaps,this.taps)}getFilterWindow(){let e=this.tempScale;return Math.ceil(this.lanczosLobes/e)}getCacheKey(){let e=this.getFilterWindow();return`${this.type}_${e}`}getFragmentSource(){let e=this.getFilterWindow();return this.generateShader(e)}getTaps(){let e=this.lanczosCreate(this.lanczosLobes),t=this.tempScale,n=this.getFilterWindow(),r=Array(n);for(let i=1;i<=n;i++)r[i-1]=e(i*t);return r}generateShader(e){let t=Array(e);for(let n=1;n<=e;n++)t[n-1]=`${n}.0 * uDelta`;return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${e}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${t.map((e,t)=>`\n color += texture2D(uTexture, vTexCoord + ${e}) * uTaps[${t}] + texture2D(uTexture, vTexCoord - ${e}) * uTaps[${t}];\n sum += 2.0 * uTaps[${t}];\n `).join(`
|
|
410
|
+
`)}\n gl_FragColor = color / sum;\n }\n `}applyToForWebgl(e){e.passes++,this.width=e.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=e.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),e.destinationWidth=this.dW,super.applyTo(e),e.sourceWidth=e.destinationWidth,this.height=e.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),e.destinationHeight=this.dH,super.applyTo(e),e.sourceHeight=e.destinationHeight}applyTo(e){Kp(e)?this.applyToForWebgl(e):this.applyTo2d(e)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(e){return t=>{if(t>=e||t<=-e)return 0;if(t<1.1920929e-7&&t>-1.1920929e-7)return 1;let n=(t*=Math.PI)/e;return Math.sin(t)/t*Math.sin(n)/n}}applyTo2d(e){let t=e.imageData,n=this.scaleX,r=this.scaleY;this.rcpScaleX=1/n,this.rcpScaleY=1/r;let i=t.width,a=t.height,o=Math.round(i*n),s=Math.round(a*r),c;c=this.resizeType===`sliceHack`?this.sliceByTwo(e,i,a,o,s):this.resizeType===`hermite`?this.hermiteFastResize(e,i,a,o,s):this.resizeType===`bilinear`?this.bilinearFiltering(e,i,a,o,s):this.resizeType===`lanczos`?this.lanczosResize(e,i,a,o,s):new ImageData(o,s),e.imageData=c}sliceByTwo(e,t,n,r,i){let a=e.imageData,o=.5,s=!1,c=!1,l=t*o,u=n*o,d=e.filterBackend.resources,f=0,p=0,m=t,h=0;d.sliceByTwo||=ko();let g=d.sliceByTwo;(g.width<1.5*t||g.height<n)&&(g.width=1.5*t,g.height=n);let _=g.getContext(`2d`);for(_.clearRect(0,0,1.5*t,n),_.putImageData(a,0,0),r=Math.floor(r),i=Math.floor(i);!s||!c;)t=l,n=u,r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,s=!0),i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,c=!0),_.drawImage(g,f,p,t,n,m,h,l,u),f=m,p=h,h+=u;return _.getImageData(f,p,r,i)}lanczosResize(e,t,n,r,i){let a=e.imageData.data,o=e.ctx.createImageData(r,i),s=o.data,c=this.lanczosCreate(this.lanczosLobes),l=this.rcpScaleX,u=this.rcpScaleY,d=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(l*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),h={},g={x:0,y:0},_={x:0,y:0};return function e(v){let y,b,x,S,C,w,T,E,D,O,k;for(g.x=(v+.5)*l,_.x=Math.floor(g.x),y=0;y<i;y++){for(g.y=(y+.5)*u,_.y=Math.floor(g.y),C=0,w=0,T=0,E=0,D=0,b=_.x-p;b<=_.x+p;b++)if(!(b<0||b>=t)){O=Math.floor(1e3*Math.abs(b-g.x)),h[O]||(h[O]={});for(let e=_.y-m;e<=_.y+m;e++)e<0||e>=n||(k=Math.floor(1e3*Math.abs(e-g.y)),h[O][k]||(h[O][k]=c(Math.sqrt((O*d)**2+(k*f)**2)/1e3)),x=h[O][k],x>0&&(S=4*(e*t+b),C+=x,w+=x*a[S],T+=x*a[S+1],E+=x*a[S+2],D+=x*a[S+3]))}S=4*(y*r+v),s[S]=w/C,s[S+1]=T/C,s[S+2]=E/C,s[S+3]=D/C}return++v<r?e(v):o}(0)}bilinearFiltering(e,t,n,r,i){let a,o,s,c,l,u,d,f,p,m,h,g,_,v=0,y=this.rcpScaleX,b=this.rcpScaleY,x=4*(t-1),S=e.imageData.data,C=e.ctx.createImageData(r,i),w=C.data;for(d=0;d<i;d++)for(f=0;f<r;f++)for(l=Math.floor(y*f),u=Math.floor(b*d),p=y*f-l,m=b*d-u,_=4*(u*t+l),h=0;h<4;h++)a=S[_+h],o=S[_+4+h],s=S[_+x+h],c=S[_+x+4+h],g=a*(1-p)*(1-m)+o*p*(1-m)+s*m*(1-p)+c*p*m,w[v++]=g;return C}hermiteFastResize(e,t,n,r,i){let a=this.rcpScaleX,o=this.rcpScaleY,s=Math.ceil(a/2),c=Math.ceil(o/2),l=e.imageData.data,u=e.ctx.createImageData(r,i),d=u.data;for(let e=0;e<i;e++)for(let n=0;n<r;n++){let i=4*(n+e*r),u,f=0,p=0,m=0,h=0,g=0,_=0,v=(e+.5)*o;for(let r=Math.floor(e*o);r<(e+1)*o;r++){let e=Math.abs(v-(r+.5))/c,i=(n+.5)*a,o=e*e;for(let e=Math.floor(n*a);e<(n+1)*a;e++){let n=Math.abs(i-(e+.5))/s,a=Math.sqrt(o+n*n);a>1&&a<-1||(u=2*a*a*a-3*a*a+1,u>0&&(n=4*(e+r*t),_+=u*l[n+3],p+=u,l[n+3]<255&&(u=u*l[n+3]/250),m+=u*l[n],h+=u*l[n+1],g+=u*l[n+2],f+=u))}}d[i]=m/f,d[i+1]=h/f,d[i+2]=g/f,d[i+3]=_/p}return u}};Y(Dm,`type`,`Resize`),Y(Dm,`defaults`,{resizeType:`hermite`,scaleX:1,scaleY:1,lanczosLobes:3}),Y(Dm,`uniformLocations`,[`uDelta`,`uTaps`]),Z.setClass(Dm);var Om=class extends Xp{getFragmentSource(){return`
|
|
411
|
+
precision highp float;
|
|
412
|
+
uniform sampler2D uTexture;
|
|
413
|
+
uniform float uSaturation;
|
|
414
|
+
varying vec2 vTexCoord;
|
|
415
|
+
void main() {
|
|
416
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
417
|
+
float rgMax = max(color.r, color.g);
|
|
418
|
+
float rgbMax = max(rgMax, color.b);
|
|
419
|
+
color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;
|
|
420
|
+
color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;
|
|
421
|
+
color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
|
|
422
|
+
gl_FragColor = color;
|
|
423
|
+
}
|
|
424
|
+
`}applyTo2d({imageData:{data:e}}){let t=-this.saturation;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a);e[n]+=o===r?0:(o-r)*t,e[n+1]+=o===i?0:(o-i)*t,e[n+2]+=o===a?0:(o-a)*t}}sendUniformData(e,t){e.uniform1f(t.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}};Y(Om,`type`,`Saturation`),Y(Om,`defaults`,{saturation:0}),Y(Om,`uniformLocations`,[`uSaturation`]),Z.setClass(Om);var km=class extends Xp{getFragmentSource(){return`
|
|
425
|
+
precision highp float;
|
|
426
|
+
uniform sampler2D uTexture;
|
|
427
|
+
uniform float uVibrance;
|
|
428
|
+
varying vec2 vTexCoord;
|
|
429
|
+
void main() {
|
|
430
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
431
|
+
float max = max(color.r, max(color.g, color.b));
|
|
432
|
+
float avg = (color.r + color.g + color.b) / 3.0;
|
|
433
|
+
float amt = (abs(max - avg) * 2.0) * uVibrance;
|
|
434
|
+
color.r += max != color.r ? (max - color.r) * amt : 0.00;
|
|
435
|
+
color.g += max != color.g ? (max - color.g) * amt : 0.00;
|
|
436
|
+
color.b += max != color.b ? (max - color.b) * amt : 0.00;
|
|
437
|
+
gl_FragColor = color;
|
|
438
|
+
}
|
|
439
|
+
`}applyTo2d({imageData:{data:e}}){let t=-this.vibrance;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a),s=(r+i+a)/3,c=2*Math.abs(o-s)/255*t;e[n]+=o===r?0:(o-r)*c,e[n+1]+=o===i?0:(o-i)*c,e[n+2]+=o===a?0:(o-a)*c}}sendUniformData(e,t){e.uniform1f(t.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}};Y(km,`type`,`Vibrance`),Y(km,`defaults`,{vibrance:0}),Y(km,`uniformLocations`,[`uVibrance`]),Z.setClass(km);var Am=Sa({BaseFilter:()=>Xp,BlackWhite:()=>fm,BlendColor:()=>Qp,BlendImage:()=>em,Blur:()=>tm,Brightness:()=>nm,Brownie:()=>om,ColorMatrix:()=>im,Composed:()=>pm,Contrast:()=>mm,Convolute:()=>gm,Gamma:()=>vm,Grayscale:()=>bm,HueRotation:()=>Sm,Invert:()=>Cm,Kodachrome:()=>cm,Noise:()=>wm,Pixelate:()=>Tm,Polaroid:()=>um,RemoveColor:()=>Em,Resize:()=>Dm,Saturation:()=>Om,Sepia:()=>dm,Technicolor:()=>lm,Vibrance:()=>km,Vintage:()=>sm}),jm=[100,200,300,400,500,600,700,800,900],Mm=`Geist Variable`,Nm=null,Pm=new Map,Fm=new Set,Im=new Map,Lm;function Rm(){return Nm??=fetch(`https://fonts.bunny.net/list`).then(e=>{if(!e.ok)throw Error(`Bunny Fonts returned ${e.status}`);return e.json()}).then(e=>Object.entries(e).flatMap(([e,t])=>{if(typeof t.familyName!=`string`||typeof t.category!=`string`||!Array.isArray(t.weights))return[];let n=t.weights.filter(Hm);return n.length>0?[{id:e,familyName:t.familyName,category:t.category,weights:n}]:[]}).sort((e,t)=>e.familyName.localeCompare(t.familyName))).catch(e=>{throw Nm=null,e}),Nm}async function zm(e,t){if(Um(e))return;let n=Pm.get(e);n||(n=new Promise((t,n)=>{let r=new URL(`https://fonts.bunny.net/css`);r.searchParams.set(`family`,`${e}:${jm.join(`,`)}`),r.searchParams.set(`display`,`swap`);let i=document.createElement(`link`);i.rel=`stylesheet`,i.href=r.toString(),i.dataset.storeshotBunnyFont=e,i.addEventListener(`load`,()=>t(),{once:!0}),i.addEventListener(`error`,()=>n(Error(`Could not load ${e}`)),{once:!0}),document.head.append(i)}).catch(t=>{throw Pm.delete(e),t}),Pm.set(e,n)),await n,await document.fonts.load(`${t} 16px ${JSON.stringify(e)}`),La.clearFontCache(e)}async function Bm(e){let t=e.filter(e=>!Um(e.familyName)&&!Fm.has(e.familyName));if(t.length===0)return;t.forEach(e=>Fm.add(e.familyName));let n=t.map(e=>`${e.familyName}:${Wm(e.weights,400)}`).join(`|`),r=new URL(`https://fonts.bunny.net/css`);r.searchParams.set(`family`,n),r.searchParams.set(`display`,`swap`);try{await new Promise((e,t)=>{let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=r.toString(),n.dataset.storeshotBunnyFontPreview=``,n.addEventListener(`load`,()=>e(),{once:!0}),n.addEventListener(`error`,()=>t(Error(`Could not load font previews`)),{once:!0}),document.head.append(n)}),await Promise.all(t.map(e=>document.fonts.load(`${Wm(e.weights,400)} 18px ${JSON.stringify(e.familyName)}`)))}catch(e){throw t.forEach(e=>Fm.delete(e.familyName)),e}}function Vm(e){Um(e.familyName)||Fm.has(e.familyName)||(Im.set(e.familyName,e),!Lm&&(Lm=setTimeout(()=>{Lm=void 0;let e=[...Im.values()];Im.clear(),Bm(e).catch(()=>void 0)},50)))}function Hm(e){return typeof e==`number`&&Number.isInteger(e)&&e>=100&&e<=900&&e%100==0}function Um(e){return e===`Geist Variable`||e===`Arial`||e===`Georgia`||e===`Times New Roman`}function Wm(e,t){return e.reduce((e,n)=>Math.abs(n-t)<Math.abs(e-t)?n:e,e[0]??400)}function Gm(e,t,n){let r=Math.abs(e.y-t.y)<=n,i=Math.abs(e.x-t.x)<=n;return{horizontal:r,vertical:i,x:i?t.x:e.x,y:r?t.y:e.y}}async function Km(e,t){let[n,r]=await Promise.all([Jm(e.frameUrl),Jm(t)]),i=document.createElement(`canvas`);i.width=e.width,i.height=e.height;let a=i.getContext(`2d`);if(!a)throw Error(`Canvas rendering is unavailable`);if(a.imageSmoothingEnabled=!0,a.imageSmoothingQuality=`high`,e.screen.kind===`rect`){let t=e.screen;a.save(),a.beginPath(),a.roundRect(t.x,t.y,t.width,t.height,t.cornerRadius),a.clip(),a.drawImage(r,t.x,t.y,t.width,t.height),a.restore()}else Ym(a,qm(r,e.screen.sourceCornerRadius),e.screen.transform,e.width,e.height);return a.drawImage(n,0,0,e.width,e.height),i}function qm(e,t){let n=document.createElement(`canvas`);n.width=e.naturalWidth,n.height=e.naturalHeight;let r=n.getContext(`2d`);if(!r)throw Error(`Canvas rendering is unavailable`);return r.imageSmoothingEnabled=!0,r.imageSmoothingQuality=`high`,r.beginPath(),r.roundRect(0,0,n.width,n.height,{x:n.width*t.x,y:n.height*t.y}),r.clip(),r.drawImage(e,0,0,n.width,n.height),n}function Jm(e){return new Promise((t,n)=>{let r=new Image;r.crossOrigin=`anonymous`,r.onload=()=>t(r),r.onerror=()=>n(Error(`Could not load ${e}`)),r.src=e})}function Ym(e,t,n,r,i){let a=Math.max(12,Math.ceil(r/64)),o=Math.max(20,Math.ceil(i/64));for(let s=0;s<o;s+=1)for(let c=0;c<a;c+=1){let l=c/a,u=(c+1)/a,d=s/o,f=(s+1)/o,p=Zm(n,r,i,l,d),m=Zm(n,r,i,u,d),h=Zm(n,r,i,u,f),g=Zm(n,r,i,l,f),_=Qm(t,l,d),v=Qm(t,u,d),y=Qm(t,u,f),b=Qm(t,l,f);Xm(e,t,[_,v,y],[p,m,h]),Xm(e,t,[_,y,b],[p,h,g])}}function Xm(e,t,n,r){let[i,a,o]=n,[s,c,l]=r,u=i.x*(a.y-o.y)+a.x*(o.y-i.y)+o.x*(i.y-a.y);if(Math.abs(u)<2**-52)return;let d=(s.x*(a.y-o.y)+c.x*(o.y-i.y)+l.x*(i.y-a.y))/u,f=(s.y*(a.y-o.y)+c.y*(o.y-i.y)+l.y*(i.y-a.y))/u,p=(s.x*(o.x-a.x)+c.x*(i.x-o.x)+l.x*(a.x-i.x))/u,m=(s.y*(o.x-a.x)+c.y*(i.x-o.x)+l.y*(a.x-i.x))/u,h=(s.x*(a.x*o.y-o.x*a.y)+c.x*(o.x*i.y-i.x*o.y)+l.x*(i.x*a.y-a.x*i.y))/u,g=(s.y*(a.x*o.y-o.x*a.y)+c.y*(o.x*i.y-i.x*o.y)+l.y*(i.x*a.y-a.x*i.y))/u;e.save();let _=$m(r,.75);e.beginPath(),e.moveTo(_[0].x,_[0].y),e.lineTo(_[1].x,_[1].y),e.lineTo(_[2].x,_[2].y),e.closePath(),e.clip(),e.setTransform(d,f,p,m,h,g),e.drawImage(t,0,0),e.restore()}function Zm(e,t,n,r,i){let a=e[2][0]*r+e[2][1]*i+e[2][2];return{x:t*(e[0][0]*r+e[0][1]*i+e[0][2])/a,y:n*(e[1][0]*r+e[1][1]*i+e[1][2])/a}}function Qm(e,t,n){return{x:e.width*t,y:e.height*n}}function $m(e,t){let n={x:(e[0].x+e[1].x+e[2].x)/3,y:(e[0].y+e[1].y+e[2].y)/3};return e.map(e=>{let r=Math.max(1,eh(n,e)),i=(r+t)/r;return{x:n.x+(e.x-n.x)*i,y:n.y+(e.y-n.y)*i}})}function eh(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}async function th(e,t,n){if(e.type===`text`)return new bp(e.text,{editable:!0,lockScalingFlip:!0,minWidth:24,splitByGrapheme:!1});if(e.type===`shape`)return new ud({lockScalingFlip:!0});try{if(e.type===`mockup`){if(!t)return oh(uh(),sh(e));let r=n.get(e.mockupId);return oh(r?new jp(await Km(r,t.url),{imageSmoothing:!0,lockScalingFlip:!0}):uh(),sh(e,t))}if(e.type!==`image`)return oh(uh(),sh(e));let r=e.source.kind===`builtin`?va(e.source.id):void 0,i=r?.url??t?.url;if(!i)return oh(uh(),sh(e,t));if(r||t?.name.toLowerCase().endsWith(`.svg`)){let n=await Gp(i),r=n.objects.filter(e=>e!==null);if(r.length===0)return oh(uh(),sh(e,t));let a=nf.groupSVGElements(r,n.options);return a.set({lockScalingFlip:!0}),e.fill&&ch(a,e.fill),oh(a,sh(e,t))}let a=await jp.fromURL(i,{crossOrigin:`anonymous`},{imageSmoothing:!0,lockScalingFlip:!0});return e.fill&&(a.filters=[new Am.BlendColor({color:e.fill,mode:`tint`,alpha:1})],a.applyFilters()),oh(a,sh(e,t))}catch{return oh(uh(),sh(e,t))}}function nh(e,t,n){return t.type===`text`?e instanceof bp:t.type===`shape`?e instanceof ud&&!(e instanceof jp):(e instanceof jp||e instanceof yd||e instanceof ud)&&rh(e)===sh(t,n)}function rh(e){return e.storeshotSourceKey}function ih(e,t){if(e.type===`mockup`)return t.get(e.assetId);if(e.type===`image`&&e.source.kind===`asset`)return t.get(e.source.assetId)}function ah(e,t,r){e.set({angle:t.rotation,flipX:t.flipX??!1,flipY:t.flipY??!1,left:t.x*r,opacity:t.opacity,originX:`left`,originY:`top`,top:t.y*r}),t.type===`text`&&e instanceof bp?(e.set({fill:t.color,fontFamily:t.fontFamily,fontSize:t.fontSize*r,fontWeight:t.fontWeight,lineHeight:t.lineHeight===void 0?n:t.lineHeight/t.fontSize,scaleX:1,scaleY:1,strokeWidth:0,text:t.text,textAlign:t.textAlign,width:Math.max(24,t.width*r)}),e.initDimensions()):t.type===`shape`&&e instanceof ud?e.set({fill:t.fill,height:t.height*r,rx:t.cornerRadius*r,ry:t.cornerRadius*r,scaleX:1,scaleY:1,strokeWidth:0,width:t.width*r}):e.set({scaleX:t.width*r/Math.max(1,e.width),scaleY:t.height*r/Math.max(1,e.height)}),e.setCoords()}function oh(e,t){return e.storeshotSourceKey=t,e}function sh(e,t){return e.type===`mockup`?`mockup:${e.mockupId}:${t?.url??e.assetId}`:e.type===`image`?e.source.kind===`builtin`?`image:builtin:${e.source.id}:${e.fill??`source`}`:`image:asset:${t?.url??e.source.assetId}:${e.fill??`source`}`:e.type}function ch(e,t){if(e instanceof yd)e.getObjects().forEach(e=>ch(e,t));else{let n=typeof e.fill==`string`&&!lh(e.fill)?t:e.fill,r=typeof e.stroke==`string`&&!lh(e.stroke)?t:e.stroke;e.set({fill:n,stroke:r})}e.dirty=!0}function lh(e){let t=e.trim().toLowerCase().replaceAll(` `,``);return t===`none`||t===`transparent`||t===`rgba(0,0,0,0)`}function uh(){return new ud({fill:`rgba(0, 0, 0, 0.08)`,stroke:`rgba(255, 255, 255, 0.8)`,strokeDashArray:[8,6],lockScalingFlip:!0})}var dh=`#1683ff`,fh=754,ph=6,mh=18,hh=96,gh=.24;function _h({active:e,area:t,assetLookup:n,mockupLookup:r,canvasSize:i,continuousPreview:a,selectedElementId:o,zoom:s,onActivate:c,onChange:l,onContextMenu:u,onSelect:d}){let f=(0,q.useRef)(null),p=(0,q.useRef)(null),m=(0,q.useRef)(null),h=(0,q.useRef)(null),g=(0,q.useRef)(new Map),_=(0,q.useRef)(new WeakMap),v=(0,q.useRef)(t),y=(0,q.useRef)(0),b=(0,q.useRef)({active:e,onActivate:c,onChange:l,onContextMenu:u,onSelect:d}),x=fh/Math.max(i.width,i.height),S=Math.max(1,Math.round(i.width*x*s)),C=S/i.width,w=Math.round(i.height*C),T=e?t.elements.find(e=>e.id===o):void 0,E=wh(T)?`${t.id}:${T.id}:${S}x${w}`:null,D=wh(T)?vh(T,C):null,O=yh(S,w),k=h.current;!E||!D?h.current={key:null,viewport:O}:!k||k.key!==E?h.current={key:E,viewport:xh(O,D)?O:Sh(O,D)}:xh(k.viewport,D)||(h.current={key:E,viewport:Sh(k.viewport,D)});let A=h.current.viewport;return v.current=t,b.current={active:e,onActivate:c,onChange:l,onContextMenu:u,onSelect:d},(0,q.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new Df(e,{width:O.width,height:O.height,centeredRotation:!0,preserveObjectStacking:!0,selection:!0,selectionBorderColor:dh,selectionColor:`rgba(22, 131, 255, 0.08)`,selectionLineWidth:1,stopContextMenu:!1,uniformScaling:!0});bh(t,e,O),p.current=t;let n=null,r=null,i=()=>{n&&t.remove(n),r&&t.remove(r),n=null,r=null,t.requestRenderAll()},a=(e,i)=>{e&&!n?(n=Oh([0,w/2,S,w/2]),t.add(n)):!e&&n&&(t.remove(n),n=null),i&&!r?(r=Oh([S/2,0,S/2,w]),t.add(r)):!i&&r&&(t.remove(r),r=null),n&&t.bringObjectToFront(n),r&&t.bringObjectToFront(r),t.requestRenderAll()},o=e=>{b.current.onActivate(),b.current.onSelect(e?_.current.get(e)??null:null)},s=e=>{let t=_.current.get(e),n=v.current.elements.find(e=>e.id===t);n&&b.current.onChange(Ah(e,n,C))},c=e=>{let t=m.current?.object;t&&Dh(t,e)};return t.on(`mouse:down`,({target:e})=>o(e)),t.on(`selection:cleared`,()=>{i()}),t.on(`contextmenu`,({target:e})=>{let n=e?_.current.get(e)??null:null;e&&n&&(t.setActiveObject(e),o(e),t.requestRenderAll()),b.current.onContextMenu(n)}),t.on(`object:moving`,({target:e})=>{let t=Gm(e.getCenterPoint(),new Q(S/2,w/2),ph);(t.horizontal||t.vertical)&&(e.setPositionByOrigin(new Q(t.x,t.y),`center`,`center`),e.setCoords()),c(e),a(t.horizontal,t.vertical)}),t.on(`object:rotating`,({target:e})=>c(e)),t.on(`object:scaling`,({target:e})=>c(e)),t.on(`object:modified`,({target:e})=>{i(),s(e)}),t.on(`mouse:up`,i),t.on(`text:changed`,({target:e})=>s(e)),t.on(`text:editing:exited`,({target:e})=>s(e)),()=>{y.current+=1,m.current=null,g.current.clear(),p.current=null,t.dispose()}},[w,S,C]),(0,q.useLayoutEffect)(()=>{let e=p.current,t=f.current;if(!e||!t)return;let n=m.current;n&&(!A.expanded||n.elementId!==o)&&(e.remove(n.object),n.object.dispose(),m.current=null);for(let e of g.current.values())Th(e,A.expanded,S,w);bh(e,t,A),e.requestRenderAll()},[w,S,o,A.expanded,A.height,A.left,A.top,A.width]),(0,q.useEffect)(()=>{let i=p.current;if(!i)return;let a=i,s=++y.current;async function c(){let i=new Set(t.elements.map(e=>e.id));for(let[e,t]of g.current)i.has(e)||(a.remove(t),g.current.delete(e));for(let e of t.elements){let t=g.current.get(e.id),i=ih(e,n);if(t&&!nh(t,e,i)&&(a.remove(t),g.current.delete(e.id),t=void 0),!t){if(t=await th(e,i,r),s!==y.current||p.current!==a)return;kh(t,e),g.current.set(e.id,t),_.current.set(t,e.id),a.add(t)}if(t instanceof bp&&t.isEditing||ah(t,e,C),Th(t,A.expanded,S,w),e.type===`text`&&t instanceof bp){let n=t;zm(e.fontFamily,e.fontWeight).then(()=>{if(s!==y.current||p.current!==a)return;let t=v.current.elements.find(t=>t.id===e.id);!t||t.type!==`text`||(ah(n,t,C),a.requestRenderAll())}).catch(()=>void 0)}}if(!(s!==y.current||p.current!==a)){if(t.elements.forEach((e,t)=>{let n=g.current.get(e.id);n&&a.moveObjectTo(n,t)}),e&&o){let e=g.current.get(o),n=t.elements.find(e=>e.id===o);if(e&&(a.setActiveObject(e),A.expanded&&wh(n))){let t=rh(e)??n.type,r=m.current;if(r&&(r.elementId!==n.id||r.sourceKey!==t)&&(a.remove(r.object),r.object.dispose(),m.current=null,r=null),r)Dh(r.object,e);else{let i=await e.clone();if(s!==y.current||p.current!==a){i.dispose();return}i.set({clipPath:Eh(S,w,!0),evented:!1,excludeFromExport:!0,objectCaching:!1,opacity:Math.min(e.opacity??1,gh),selectable:!1}),r={elementId:n.id,object:i,sourceKey:t},m.current=r,a.add(i)}a.moveObjectTo(r.object,0),a.setActiveObject(e)}}if(!A.expanded||!wh(T)){let e=m.current;e&&(a.remove(e.object),e.object.dispose(),m.current=null)}a.requestRenderAll()}}c()},[e,t,n,w,S,r,C,o,A.expanded]),(0,q.useEffect)(()=>{let t=p.current;if(t){if(!e||!o)t.discardActiveObject();else{let e=g.current.get(o);e&&t.getActiveObject()!==e&&t.setActiveObject(e)}t.requestRenderAll()}},[e,o,t.elements]),(0,J.jsx)(`div`,{className:a?`relative bg-white`:`relative bg-white shadow-xl ring-1 ring-black/10`,style:{width:S,height:w,backgroundColor:t.background},children:(0,J.jsx)(`canvas`,{ref:f,"aria-label":`${t.name} editable canvas`})})}function vh(e,t){let n=Ch(e,t);return{bottom:Math.ceil(n.bottom+mh),left:Math.floor(n.left-mh),right:Math.ceil(n.right+mh),top:Math.floor(n.top-mh)}}function yh(e,t){return{expanded:!1,height:t,left:0,top:0,width:e}}function bh(e,t,n){e.setDimensions({height:n.height,width:n.width}),e.setViewportTransform([1,0,0,1,-n.left,-n.top]);let r=t.parentElement;r&&(r.style.left=`${n.left}px`,r.style.position=`absolute`,r.style.top=`${n.top}px`,r.style.zIndex=n.expanded?`30`:`0`)}function xh(e,t){return t.left>=e.left&&t.top>=e.top&&t.right<=e.left+e.width&&t.bottom<=e.top+e.height}function Sh(e,t){let n=Math.min(e.left,t.left-hh),r=Math.min(e.top,t.top-hh),i=Math.max(e.left+e.width,t.right+hh);return{expanded:!0,height:Math.max(e.top+e.height,t.bottom+hh)-r,left:n,top:r,width:i-n}}function Ch(e,t){let n=e.x*t,r=e.y*t,i=e.width*t,a=e.height*t,o=e.rotation*Math.PI/180,s=Math.cos(o),c=Math.sin(o),l=[{x:0,y:0},{x:i,y:0},{x:i,y:a},{x:0,y:a}].map(e=>({x:n+e.x*s-e.y*c,y:r+e.x*c+e.y*s}));return{bottom:Math.max(...l.map(e=>e.y)),left:Math.min(...l.map(e=>e.x)),right:Math.max(...l.map(e=>e.x)),top:Math.min(...l.map(e=>e.y))}}function wh(e){return e?.type===`image`||e?.type===`mockup`}function Th(e,t,n,r){let i=e.clipPath;if(!t){i&&(e.set({clipPath:void 0}),e.dirty=!0);return}i?.storeshotClipWidth===n&&i.storeshotClipHeight===r&&i.storeshotClipInverted===!1||(e.set({clipPath:Eh(n,r)}),e.dirty=!0)}function Eh(e,t,n=!1){let r=new ud({absolutePositioned:!0,evented:!1,fill:`#000000`,height:t,inverted:n,left:0,originX:`left`,originY:`top`,selectable:!1,top:0,width:e}),i=r;return i.storeshotClipHeight=t,i.storeshotClipInverted=n,i.storeshotClipWidth=e,r}function Dh(e,t){e.set({angle:t.angle,flipX:t.flipX,flipY:t.flipY,left:t.left,opacity:Math.min(t.opacity??1,gh),scaleX:t.scaleX,scaleY:t.scaleY,skewX:t.skewX,skewY:t.skewY,top:t.top}),e.setCoords(),e.dirty=!0}function Oh(e){return new qf(e,{evented:!1,excludeFromExport:!0,objectCaching:!1,selectable:!1,stroke:dh,strokeDashArray:[4,4],strokeWidth:1})}function kh(e,t){e.set({borderColor:dh,borderScaleFactor:1.25,cornerColor:`#ffffff`,cornerSize:10,cornerStrokeColor:dh,cornerStyle:`circle`,lockScalingFlip:!0,padding:0,transparentCorners:!1}),t.type===`mockup`&&e.setControlsVisibility({ml:!1,mr:!1,mt:!1,mb:!1})}function Ah(e,t,n){let r={...t,x:Nh((e.left??0)/n),y:Nh((e.top??0)/n),width:Nh(e.width*Math.abs(e.scaleX)/n),height:Nh(e.height*Math.abs(e.scaleY)/n),rotation:Nh(e.angle??0),opacity:Nh(e.opacity??1,3),flipX:e.flipX,flipY:e.flipY};return t.type===`text`&&e instanceof bp?{...r,type:`text`,text:e.text,fontFamily:e.fontFamily,fontSize:Nh(t.fontSize*Math.abs(e.scaleY),2),fontWeight:jh(e.fontWeight),lineHeight:t.lineHeight===void 0?void 0:Nh(t.lineHeight*Math.abs(e.scaleY),2),color:typeof e.fill==`string`?e.fill:t.color,textAlign:Mh(e.textAlign)}:r}function jh(e){let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900&&t%100==0?t:400}function Mh(e){return e===`left`||e===`right`?e:`center`}function Nh(e,t=1){let n=10**t;return Math.round(e*n)/n}var Ph=120,Fh=120,Ih=80,Lh={category:`local`,familyName:Mm,id:`storeshot-geist`,weights:[400,600,700,800]};function Rh({value:e,onCancel:t,onPreview:n,onSelect:r}){let[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(``),[c,l]=(0,q.useState)([]),[u,f]=(0,q.useState)(!0),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(e),[_,v]=(0,q.useState)(Ph),y=(0,q.useRef)(i);y.current=i,(0,q.useEffect)(()=>{let e=!1;return Rm().then(t=>{e||l(t)}).catch(()=>{e||m(!0)}).finally(()=>{e||f(!1)}),()=>{e=!0}},[]),(0,q.useEffect)(()=>{y.current||g(e)},[e]);let b=(0,q.useMemo)(()=>{let e=[Lh,...c];return e.some(e=>e.familyName===h)?e:[{id:`saved-${h}`,familyName:h,category:`saved`,weights:[400]},...e]},[h,c]),x=(0,q.useMemo)(()=>{if(o.trim())return b;let e=b.slice(0,_),t=b.find(e=>e.familyName===h);return t&&!e.includes(t)?[t,...e]:e},[_,h,b,o]),S=b.find(e=>e.familyName===h)??b[0];return(0,J.jsxs)(Ge,{autoHighlight:!0,filter:(e,t)=>Uh(e.familyName).toLocaleLowerCase().includes(t.trim().toLocaleLowerCase()),highlightItemOnHover:!0,isItemEqualToValue:(e,t)=>e.familyName===t.familyName,itemToStringLabel:e=>e.familyName===`Geist Variable`?`Geist`:e.familyName,items:x,limit:o.trim()?Ih:void 0,open:i,inputValue:i?o:Uh(h),value:S,onInputValueChange:e=>s(e),onItemHighlighted:e=>{e&&n(e)},onOpenChange:(n,r)=>{n?(g(e),s(``),v(Ph)):r.reason!==`item-press`&&(t(),s(``)),a(n)},onValueChange:e=>{e&&(g(e.familyName),s(``),r(e))},children:[(0,J.jsx)(d,{"aria-label":`Font family`,className:`w-full`,placeholder:u?`Loading Bunny Fonts…`:`Search fonts…`,showClear:!1}),(0,J.jsxs)(bn,{align:`end`,className:`w-[268px]`,children:[(0,J.jsx)(_e,{children:u?`Loading Bunny Fonts…`:p?`Could not load Bunny Fonts.`:`No matching fonts.`}),(0,J.jsx)(xe,{className:`max-h-80 py-1`,onScroll:e=>{if(o.trim())return;let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight>160||v(e=>Math.min(b.length,e+Fh))},children:e=>(0,J.jsx)(gn,{className:`min-h-11 px-3 py-2 pr-9 text-lg`,style:{fontFamily:e.familyName,fontWeight:Wh(e)},value:e,children:(0,J.jsx)(zh,{font:e})},e.id)})]})]})}function zh({font:e}){let t=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let n=t.current;if(n)return Hh(n,e)},[e]),(0,J.jsx)(`span`,{className:`truncate`,ref:t,children:Uh(e.familyName)})}var Bh=new WeakMap,Vh;function Hh(e,t){return typeof IntersectionObserver>`u`?(Vm(t),()=>void 0):(Bh.set(e,t),Vh??=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=Bh.get(t.target);e&&Vm(e),Vh?.unobserve(t.target),Bh.delete(t.target)}}),Vh.observe(e),()=>{Vh?.unobserve(e),Bh.delete(e)})}function Uh(e){return e===`Geist Variable`?`Geist`:e}function Wh(e){return Gh(e.weights,400)}function Gh(e,t){return e.reduce((e,n)=>Math.abs(n-t)<Math.abs(e-t)?n:e,e[0]??400)}var Kh=[`#ffffff`,`#f4f4f5`,`#d4d4d8`,`#a1a1aa`,`#71717a`,`#3f3f46`,`#18181b`,`#09090b`,`#ef4444`,`#f97316`,`#f59e0b`,`#84cc16`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#0ea5e9`,`#3b82f6`,`#6366f1`,`#8b5cf6`,`#a855f7`,`#d946ef`,`#ec4899`,`#f43f5e`,`#7c3aed`];function qh({value:e,usedColors:t=[],label:n,compact:r=!1,className:i,onValueChange:a,onValueCommit:o}){let s=Xh(e)??`#000000`,[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(s),f=(0,q.useRef)(s),p=(0,q.useMemo)(()=>Zh(t),[t]),m=Xh(u);(0,q.useEffect)(()=>{c||d(s)},[s,c]);function h(e){d(e);let t=Xh(e);t&&a(t)}function g(){let e=Xh(u);if(!e){d(f.current),a(f.current);return}d(e),a(e),v(e)}function _(e){d(e),a(e)}function v(e){e!==f.current&&(f.current=e,o?.(e))}function y(e){if(e)f.current=s,d(s);else if(c){let e=Xh(u);e?(a(e),v(e)):(d(f.current),a(f.current))}l(e)}return(0,J.jsxs)(Dt,{open:c,onOpenChange:y,children:[(0,J.jsxs)(Qe,{render:(0,J.jsx)(K,{"aria-label":`${n}: ${s}`,className:mn(`justify-start font-mono font-normal uppercase`,r?`w-16 px-1.5`:`w-full`,i),size:r?`xs`:`default`,type:`button`,variant:`outline`}),children:[(0,J.jsx)(Yh,{color:s,className:r?`size-3.5`:`size-4`}),!r&&(0,J.jsx)(`span`,{children:s})]}),(0,J.jsxs)(cn,{align:`start`,className:`w-72 gap-3 p-3`,sideOffset:6,onPointerDown:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-xs font-medium`,children:`Document colors`}),(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Colors already used in this set`})]}),p.length>0?(0,J.jsx)(ua,{className:`max-h-24`,children:(0,J.jsx)(`div`,{className:`grid grid-cols-8 gap-1.5 pr-2`,children:p.map(e=>(0,J.jsx)(Jh,{color:e,selected:e===s,onClick:()=>_(e)},e))})}):(0,J.jsx)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-xs text-muted-foreground`,children:`No colors used yet`}),(0,J.jsx)(ct,{}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Palette`}),(0,J.jsx)(`div`,{className:`grid grid-cols-8 gap-1.5`,children:Kh.map(e=>(0,J.jsx)(Jh,{color:e,selected:e===s,onClick:()=>_(e)},e))})]}),(0,J.jsx)(ct,{}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Custom color`}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(`label`,{className:`relative grid size-8 shrink-0 cursor-pointer place-items-center overflow-hidden rounded-lg border border-input bg-background outline-none focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50`,title:`Open system color picker`,children:[(0,J.jsx)(Yh,{color:m??s,className:`absolute inset-0 size-full rounded-none border-0`}),(0,J.jsx)(Un,{className:`relative size-4 text-white drop-shadow-[0_1px_2px_rgb(0_0_0/0.8)]`}),(0,J.jsx)(`input`,{"aria-label":`Open system color picker`,className:`absolute inset-0 cursor-pointer opacity-0`,type:`color`,value:m??s,onBlur:g,onChange:e=>{h(e.target.value),v(e.target.value)},onInput:e=>h(e.currentTarget.value)})]}),(0,J.jsx)(Lt,{"aria-label":`${n} hex value`,"aria-invalid":!m,className:`font-mono uppercase`,maxLength:7,spellCheck:!1,value:u,onBlur:g,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),g(),l(!1)),e.key===`Escape`&&(e.preventDefault(),d(f.current),a(f.current),l(!1))}})]}),!m&&(0,J.jsx)(`p`,{className:`mt-1.5 text-[11px] text-destructive`,children:`Enter a 3 or 6 digit hex color.`})]})]})]})}function Jh({color:e,selected:t,onClick:n}){return(0,J.jsxs)(K,{"aria-label":`Use ${e}`,"aria-pressed":t,className:`relative size-7 rounded-md p-0`,title:e.toUpperCase(),type:`button`,variant:`outline`,onClick:n,children:[(0,J.jsx)(Yh,{color:e,className:`absolute inset-0 size-full rounded-[calc(var(--radius-md)-1px)] border-0`}),t&&(0,J.jsx)(s,{className:mn(`relative size-3.5 drop-shadow-[0_1px_2px_rgb(0_0_0/0.7)]`,Qh(e))})]})}function Yh({color:e,className:t}){return(0,J.jsx)(`span`,{"aria-hidden":`true`,className:mn(`shrink-0 rounded border border-black/15`,t),style:{backgroundColor:e}})}function Xh(e){let t=e.trim().replace(/^#/,``);return/^[0-9a-f]{3}$/i.test(t)?`#${t.split(``).map(e=>e.repeat(2)).join(``)}`.toLowerCase():/^[0-9a-f]{6}$/i.test(t)?`#${t.toLowerCase()}`:null}function Zh(e){let t=new Set;for(let n of e){let e=Xh(n);e&&t.add(e)}return[...t]}function Qh(e){let t=Number.parseInt(e.slice(1,3),16),n=Number.parseInt(e.slice(3,5),16),r=Number.parseInt(e.slice(5,7),16);return(t*299+n*587+r*114)/1e3>150?`text-black`:`text-white`}function $h({onImported:e}){let t=(0,q.useRef)(null),{refresh:n}=rn(),[r,i]=(0,q.useState)(null),[a,o]=(0,q.useState)(new Set),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)({completed:0,total:0}),[f,p]=(0,q.useState)(null),m=(0,q.useMemo)(()=>{let e=new Map;if(!r)return e;for(let t of r.manifest.mockups){let n=r.files.get(t.thumbnail??t.frame);n&&e.set(t.id,URL.createObjectURL(n))}return e},[r]);(0,q.useEffect)(()=>{t.current?.setAttribute(`webkitdirectory`,``)},[]),(0,q.useEffect)(()=>()=>{for(let e of m.values())URL.revokeObjectURL(e)},[m]);async function h(e){if(!(!e||e.length===0)){p(null);try{let t=[...e],n=t.filter(e=>eg(e).endsWith(`/storeshot-mockups.json`)||e.name===`storeshot-mockups.json`).sort((e,t)=>eg(e).length-eg(t).length)[0];if(!n)throw Error(`Choose a folder containing ${Pt}`);let r=eg(n),a=r.slice(0,r.length-Pt.length),s=Ve(JSON.parse(await n.text())),c=new Map(t.flatMap(e=>{let t=eg(e);return t.startsWith(a)?[[t.slice(a.length),e]]:[]}));i({files:c,manifest:s}),o(new Set(s.mockups.map(e=>e.id))),d({completed:0,total:0})}catch(e){p(Sn(e))}finally{t.current&&(t.current.value=``)}}}function g(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}async function _(){if(!r||a.size===0)return;let t=crypto.randomUUID();l(!0),p(null);try{let o={...r.manifest,mockups:r.manifest.mockups.filter(e=>a.has(e.id))},s=Yt(o),c=s.filter(e=>!r.files.has(e));if(c.length>0)throw Error(`Bundle is missing ${c[0]}`);d({completed:0,total:s.length+1});for(let[e,n]of s.entries())await ye(`/api/mockup-bundle-imports/${encodeURIComponent(t)}/${encodeURIComponent(o.id)}/files/${tg(n)}`,{method:`PUT`,body:r.files.get(n)}),d({completed:e+1,total:s.length+1});await ye(`/api/mockup-bundle-imports/${encodeURIComponent(t)}/${encodeURIComponent(o.id)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(o)}),d({completed:s.length+1,total:s.length+1});let l=await n();i(null),e(`${o.id}/${o.mockups[0].id}`,l)}catch(e){await ye(`/api/mockup-bundle-imports/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>void 0),p(Sn(e))}finally{l(!1)}}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`input`,{hidden:!0,multiple:!0,ref:t,type:`file`,onChange:e=>void h(e.target.files)}),(0,J.jsxs)(K,{size:`sm`,type:`button`,variant:`outline`,onClick:()=>t.current?.click(),children:[(0,J.jsx)(Bn,{}),`Import bundle`]}),f&&!r&&(0,J.jsx)(`span`,{className:`max-w-64 text-xs text-destructive`,children:f}),(0,J.jsx)(Nt,{open:r!==null,onOpenChange:e=>!e&&!c&&i(null),children:(0,J.jsxs)(gt,{className:`grid h-[min(760px,calc(100vh-2rem))] max-w-3xl grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden p-0`,children:[(0,J.jsxs)(Be,{className:`border-b px-5 py-4 pr-14`,children:[(0,J.jsxs)(hn,{children:[`Import `,r?.manifest.name??`mockup bundle`]}),(0,J.jsx)(ft,{children:`Choose the frames to copy into this StoreShot project. The bundle license and source information stay with the imported files.`})]}),r&&(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 border-b px-5 py-3`,children:[(0,J.jsx)(`span`,{className:`grid size-9 place-items-center rounded-lg bg-muted`,children:(0,J.jsx)(Hn,{className:`size-4`})}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`p`,{className:`truncate text-sm font-medium`,children:r.manifest.name}),(0,J.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[r.manifest.author,` · `,r.manifest.license.name,` · `,r.manifest.mockups.length,` mockups`]})]}),(0,J.jsx)(K,{size:`sm`,type:`button`,variant:`ghost`,onClick:()=>o(new Set(r.manifest.mockups.map(e=>e.id))),children:`Select all`}),(0,J.jsx)(K,{size:`sm`,type:`button`,variant:`ghost`,onClick:()=>o(new Set),children:`None`})]}),(0,J.jsx)(ua,{className:`min-h-0 flex-1`,children:(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-2 p-4 md:grid-cols-3`,children:r.manifest.mockups.map(e=>{let t=a.has(e.id),n=m.get(e.id);return(0,J.jsxs)(K,{"aria-pressed":t,className:mn(`relative h-auto min-h-36 flex-col items-stretch justify-start gap-0 overflow-hidden p-0 text-left`,t&&`border-foreground ring-1 ring-foreground`),type:`button`,variant:`outline`,onClick:()=>g(e.id),children:[(0,J.jsx)(`span`,{className:`grid h-24 place-items-center overflow-hidden bg-muted/40 p-2`,children:n&&(0,J.jsx)(`img`,{alt:``,className:`max-h-full max-w-full object-contain`,src:n})}),(0,J.jsxs)(`span`,{className:`min-w-0 border-t px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:e.name}),(0,J.jsx)(`span`,{className:`mt-0.5 block truncate text-[10px] text-muted-foreground`,children:e.description})]}),t&&(0,J.jsx)(`span`,{className:`absolute right-2 top-2 grid size-5 place-items-center rounded-full bg-foreground text-background`,children:(0,J.jsx)(s,{className:`size-3`})})]},e.id)})})})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-t px-5 py-4`,children:[(0,J.jsx)(`div`,{className:`mr-auto text-xs text-muted-foreground`,children:f?(0,J.jsx)(`span`,{className:`text-destructive`,children:f}):c?`Copying ${u.completed}/${u.total} files…`:`${a.size} selected`}),(0,J.jsx)(K,{disabled:c,type:`button`,variant:`outline`,onClick:()=>i(null),children:`Cancel`}),(0,J.jsxs)(K,{disabled:c||a.size===0,type:`button`,onClick:()=>void _(),children:[c&&(0,J.jsx)(x,{className:`animate-spin`}),`Import `,a.size,` mockup`,a.size===1?``:`s`]})]})]})})]})}function eg(e){return e.webkitRelativePath||e.name}function tg(e){return e.split(`/`).map(encodeURIComponent).join(`/`)}var ng=[{id:`all`,label:`All`},{id:`iphone`,label:`iPhone`},{id:`ipad`,label:`iPad`},{id:`mac`,label:`Mac`},{id:`watch`,label:`Watch`}];function rg({open:e,value:t,onOpenChange:n,onValueChange:r}){let{catalog:i,error:a,loading:o}=rn(),c=_t(i,t)??i.mockups[0],[l,u]=(0,q.useState)(`all`),[d,f]=(0,q.useState)(c?.groupId??``),[p,m]=(0,q.useState)(``);(0,q.useEffect)(()=>{e&&(f(c?.groupId??i.groups[0]?.id??``),u(c?.platform??`all`),m(``))},[i.groups,e,c?.groupId,c?.platform]);let g=(0,q.useMemo)(()=>i.groups.filter(e=>l===`all`||e.platform===l),[i.groups,l]);(0,q.useEffect)(()=>{g.some(e=>e.id===d)||g[0]&&f(g[0].id)},[d,g]);let _=p.trim().toLowerCase(),v=(0,q.useMemo)(()=>i.mockups.filter(e=>{if(l!==`all`&&e.platform!==l)return!1;if(!_)return e.groupId===d;let t=i.bundles.find(t=>t.id===e.bundleId);return`${e.name} ${e.description} ${e.style} ${t?.name??``} ${t?.author??``}`.toLowerCase().includes(_)}),[i.bundles,i.mockups,d,_,l]),b=i.groups.find(e=>e.id===d),x=i.bundles.find(e=>e.id===b?.bundleId);return(0,J.jsx)(Nt,{open:e,onOpenChange:n,children:(0,J.jsxs)(gt,{className:`h-[min(820px,calc(100vh-2rem))] max-w-6xl grid-rows-[auto_auto_minmax(0,1fr)] gap-0 overflow-hidden p-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-4 border-b px-5 py-4 pr-14`,children:[(0,J.jsxs)(Be,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(hn,{children:`Choose a device frame`}),(0,J.jsxs)(ft,{children:[`Browse `,i.mockups.length,` Apple mockups. Your selected screenshot stays in place when you switch frames.`]})]}),(0,J.jsx)($h,{onImported:(e,t)=>{let n=_t(t,e);r(e),n&&(u(n.platform),f(n.groupId))}})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,J.jsxs)(y,{className:`min-w-56 flex-1`,children:[(0,J.jsx)(h,{children:(0,J.jsx)(Gn,{className:`size-4`})}),(0,J.jsx)(wt,{"aria-label":`Search device frames`,placeholder:`Search devices, styles, or colors`,value:p,onChange:e=>m(e.target.value)})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-muted p-1`,children:ng.map(e=>(0,J.jsx)(K,{"aria-pressed":l===e.id,className:mn(`text-muted-foreground`,l===e.id&&`bg-background text-foreground shadow-sm hover:bg-background`),size:`sm`,variant:`ghost`,onClick:()=>u(e.id),children:e.label},e.id))})]}),(0,J.jsxs)(`div`,{className:`grid min-h-0 overflow-hidden grid-cols-[15rem_minmax(0,1fr)]`,children:[(0,J.jsx)(ua,{className:`h-full min-h-0 overflow-hidden border-r`,children:(0,J.jsx)(`div`,{className:`space-y-1 p-2 pb-5`,children:g.map(e=>(0,J.jsxs)(K,{className:`h-auto w-full justify-start gap-3 px-2 py-2 text-left`,variant:!_&&e.id===d?`secondary`:`ghost`,onClick:()=>{f(e.id),m(``)},children:[(0,J.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center overflow-hidden rounded-md bg-muted/70 p-1`,children:(0,J.jsx)(`img`,{alt:``,className:`size-full min-h-0 min-w-0 object-contain`,src:e.thumbnailUrl})}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block whitespace-normal text-xs font-medium leading-tight`,children:e.name}),(0,J.jsxs)(`span`,{className:`mt-1 block text-[10px] text-muted-foreground`,children:[e.count,` `,e.count===1?`frame`:`frames`]})]})]},e.id))})}),(0,J.jsxs)(`div`,{className:`flex min-h-0 overflow-hidden flex-col`,children:[(0,J.jsx)(`div`,{className:`flex shrink-0 items-center justify-between border-b px-4 py-3`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:_?`Search results`:b?.name}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[v.length,` `,v.length===1?`frame`:`frames`,x&&!_?` · ${x.name} · ${x.license.name}`:``]})]})}),(0,J.jsx)(ua,{className:`h-full min-h-0 flex-1 overflow-hidden`,children:o&&i.mockups.length===0?(0,J.jsx)(`div`,{className:`grid h-48 place-items-center text-sm text-muted-foreground`,children:`Loading device frames…`}):a&&i.mockups.length===0?(0,J.jsx)(`div`,{className:`grid h-48 place-items-center px-8 text-center text-sm text-destructive`,children:a}):v.length===0?(0,J.jsx)(`div`,{className:`grid h-48 place-items-center text-sm text-muted-foreground`,children:`No frames match your search.`}):(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-3 p-4 pb-8 lg:grid-cols-3`,children:v.map(e=>(0,J.jsxs)(K,{"aria-label":`Use ${e.name}, ${e.description}`,"aria-pressed":e.id===t,className:mn(`group relative h-auto flex-col items-stretch justify-start overflow-hidden rounded-xl bg-card p-0 text-left whitespace-normal outline-none transition hover:border-foreground/30 hover:bg-card hover:shadow-sm focus-visible:ring-2 focus-visible:ring-ring active:translate-y-0`,e.id===t&&`border-foreground ring-1 ring-foreground`),type:`button`,variant:`outline`,onClick:()=>{r(e.id),n(!1)},children:[(0,J.jsx)(`div`,{className:`relative h-40 overflow-hidden bg-[linear-gradient(45deg,var(--color-muted)_25%,transparent_25%),linear-gradient(-45deg,var(--color-muted)_25%,transparent_25%),linear-gradient(45deg,transparent_75%,var(--color-muted)_75%),linear-gradient(-45deg,transparent_75%,var(--color-muted)_75%)] bg-[length:14px_14px] bg-[position:0_0,0_7px,7px_-7px,-7px_0px]`,children:(0,J.jsx)(`img`,{alt:``,className:`absolute inset-3 h-[calc(100%-1.5rem)] w-[calc(100%-1.5rem)] object-contain transition-transform group-hover:scale-[1.02]`,loading:`lazy`,src:e.thumbnailUrl})}),(0,J.jsxs)(`div`,{className:`border-t px-3 py-2.5`,children:[(0,J.jsx)(`p`,{className:`truncate text-xs font-medium`,children:e.description}),_&&(0,J.jsx)(`p`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:e.name})]}),e.id===t&&(0,J.jsx)(`span`,{className:`absolute top-2 right-2 grid size-6 place-items-center rounded-full bg-foreground text-background`,children:(0,J.jsx)(s,{className:`size-3.5`})})]},e.id))})})]})]})]})})}async function ig(e,t,n,r){let i=document.createElement(`canvas`),a=new Ts(i,{width:r.width,height:r.height,backgroundColor:e.background,renderOnAddRemove:!1});try{let r=e.elements.filter(e=>e.type===`text`);await Promise.all(r.map(e=>zm(e.fontFamily,e.fontWeight)));for(let r of e.elements){let e=await th(r,ih(r,t),n);ah(e,r,1),e.set({evented:!1,selectable:!1}),a.add(e)}return a.renderAll(),await ag(i)}finally{a.dispose()}}function ag(e){return new Promise((t,n)=>{e.toBlob(e=>{e?t(e):n(Error(`The browser could not render this screenshot`))},`image/png`)})}async function og(e){let t=[],n=[],r=0;for(let i of e){let e=new Uint8Array(await i.data.arrayBuffer()),a=new TextEncoder().encode(i.name),o=fg(e),{date:s,time:c}=ug(new Date),l=cg(30),u=new DataView(l.buffer);u.setUint32(0,67324752,!0),u.setUint16(4,20,!0),u.setUint16(6,2048,!0),u.setUint16(8,0,!0),u.setUint16(10,c,!0),u.setUint16(12,s,!0),u.setUint32(14,o,!0),u.setUint32(18,e.byteLength,!0),u.setUint32(22,e.byteLength,!0),u.setUint16(26,a.byteLength,!0),t.push(l,a,e);let d=cg(46),f=new DataView(d.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(8,2048,!0),f.setUint16(10,0,!0),f.setUint16(12,c,!0),f.setUint16(14,s,!0),f.setUint32(16,o,!0),f.setUint32(20,e.byteLength,!0),f.setUint32(24,e.byteLength,!0),f.setUint16(28,a.byteLength,!0),f.setUint32(42,r,!0),n.push(d,a),r+=l.byteLength+a.byteLength+e.byteLength}let i=n.reduce((e,t)=>e+lg(t),0),a=cg(22),o=new DataView(a.buffer);return o.setUint32(0,101010256,!0),o.setUint16(8,e.length,!0),o.setUint16(10,e.length,!0),o.setUint32(12,i,!0),o.setUint32(16,r,!0),new Blob([...t,...n,a],{type:`application/zip`})}function sg(e,t){return e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-zA-Z0-9._-]+/g,`-`).replace(/^-+|-+$/g,``)||t}function cg(e){return new Uint8Array(e)}function lg(e){return typeof e==`string`?new TextEncoder().encode(e).byteLength:e instanceof Blob?e.size:e.byteLength}function ug(e){return{date:Math.max(1980,e.getFullYear())-1980<<9|e.getMonth()+1<<5|e.getDate(),time:e.getHours()<<11|e.getMinutes()<<5|Math.floor(e.getSeconds()/2)}}var dg=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function fg(e){let t=4294967295;for(let n of e)t=dg[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}async function pg(e,t,n,r){let i=[];for(let[a,o]of e.areas.entries()){let s=await ig(o,t,n,e.canvas);i.push({data:s,name:`${String(a+1).padStart(2,`0`)}-${sg(o.name,`screenshot-${a+1}`)}.png`}),r?.({completed:a+1,total:e.areas.length})}mg(await og(i),`${sg(e.name,`screenshot-set`)}.zip`)}function mg(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),0)}var hg=()=>globalThis.crypto.randomUUID();function gg(e,{idFactory:t=hg,offsetX:n=0,offsetY:r=0}={}){return{...structuredClone(e),id:`element-${t()}`,x:e.x+n,y:e.y+r}}function _g(e,{idFactory:t=hg,name:n=e.name}={}){return{...structuredClone(e),id:`area-${t()}`,name:n,elements:e.elements.map(e=>gg(e,{idFactory:t}))}}var vg=1,yg=10,bg=.25,xg=2,Sg=.25,Cg=`application/x-storeshot`,wg=[{label:`All assets`,value:`all`},{label:`Raw screenshots`,value:`screenshots`},{label:`Brand assets`,value:`brand`},{label:`Other`,value:`other`}],Tg=null;function Eg({assets:n,set:r,onOpenAssets:i,onProjectChange:a,onSetChange:o}){let{catalog:s}=rn(),[c,l]=(0,q.useState)(r),[u,d]=(0,q.useState)(r.areas[0].id),[f,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(!1),[v,y]=(0,q.useState)(`all`),[b,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)(``),[k,A]=(0,q.useState)(n.screenshots[0]?.id??null),[M,N]=(0,q.useState)(null),[ee,P]=(0,q.useState)(`saved`),[F,I]=(0,q.useState)(null),[L,te]=(0,q.useState)(!1),[R,z]=(0,q.useState)(1),[ne,re]=(0,q.useState)(null),[B,ie]=(0,q.useState)(null),[,oe]=(0,q.useState)(0),V=(0,q.useRef)(r),se=(0,q.useRef)(u),ce=(0,q.useRef)(f),H=(0,q.useRef)({past:[],future:[]}),de=(0,q.useRef)(null),U=(0,q.useRef)(null),fe=(0,q.useRef)(0),pe=(0,q.useRef)(Promise.resolve()),me=(0,q.useRef)(null);se.current=u,ce.current=f,(0,q.useEffect)(()=>{V.current=r,l(r),d(r.areas[0].id),m(null),g(!1),S(!1),w(!1),E(!1),te(!1),z(1),H.current={past:[],future:[]},de.current=null,oe(e=>e+1)},[r.id]),(0,q.useEffect)(()=>{if(r.id!==V.current.id||JSON.stringify(r)===JSON.stringify(V.current))return;let e=V.current;if(!(JSON.stringify(r.canvas)!==JSON.stringify(e.canvas)||JSON.stringify(r.areas)!==JSON.stringify(e.areas))){let t={...e,name:r.name,locale:r.locale,device:r.device,createdAt:r.createdAt,updatedAt:r.updatedAt};V.current=t,l(t);return}U.current&&=(clearTimeout(U.current),null),fe.current+=1,V.current=r,l(r),d(e=>r.areas.some(t=>t.id===e)?e:r.areas[0].id),m(e=>r.areas.some(t=>t.elements.some(t=>t.id===e))?e:null),P(`saved`),re(null),H.current={past:[],future:[]},de.current=null,oe(e=>e+1)},[r]),(0,q.useEffect)(()=>()=>{U.current&&clearTimeout(U.current)},[]);let ge=(0,q.useMemo)(()=>Object.values(n).flat(),[n]),_e=v===`all`?ge:n[v],ve=wg.find(e=>e.value===v)??wg[0],be=n.screenshots,xe=(0,q.useMemo)(()=>new Map(ge.map(e=>[e.id,e])),[ge]),Se=(0,q.useMemo)(()=>new Map(s.mockups.map(e=>[e.id,e])),[s.mockups]),we=(0,q.useMemo)(()=>Ug(c),[c]),W=c.areas.find(e=>e.id===u)??c.areas[0],G=W.elements.find(e=>e.id===f)??null,Te=_t(s,D)??s.mockups[0],Ee=Ng(be,Te?.platform),De=G?W.elements.findIndex(e=>e.id===G.id):-1,Oe=M?c.areas.find(e=>e.id===M.areaId):void 0,ke=Oe?.elements.find(e=>e.id===M?.elementId),Ae=ke&&Oe?Oe.elements.findIndex(e=>e.id===ke.id):-1,je=H.current.past.length>0,Me=H.current.future.length>0;(0,q.useEffect)(()=>{be.some(e=>e.id===k)||A(be[0]?.id??null)},[k,be]),(0,q.useEffect)(()=>{!Te&&s.mockups[0]&&O(s.mockups[0].id)},[s.mockups,Te]),(0,q.useEffect)(()=>{if(!h&&!b&&!C||T)return;let e=e=>{let t=e.target;!(t instanceof Element&&t.closest(`[data-slot='select-content']`))&&!me.current?.contains(t)&&(g(!1),S(!1),w(!1))},t=e=>{e.key===`Escape`&&(g(!1),S(!1),w(!1))};return window.addEventListener(`pointerdown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,t)}},[h,b,C,T]),(0,q.useEffect)(()=>{function e(e){let t=e.key.toLowerCase(),n=e.metaKey||e.ctrlKey;if(!e_(e.target)&&n&&!e.altKey&&(t===`+`||t===`=`||t===`-`||t===`0`)){e.preventDefault(),z(e=>t===`0`?1:r_(e+(t===`-`?-.25:Sg)));return}if(!e_(e.target)&&n&&!e.altKey&&t===`z`){e.preventDefault(),e.shiftKey?ze():Re();return}if(!e_(e.target)&&e.ctrlKey&&!e.metaKey&&!e.altKey&&t===`y`){e.preventDefault(),ze();return}if(!(!f||e_(e.target)))if(e.key===`Backspace`||e.key===`Delete`)e.preventDefault(),bt();else if(!n&&!e.altKey&&t_(e.key)){e.preventDefault();let t=e.shiftKey?yg:vg;Xe(e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0)}else(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`d`?(e.preventDefault(),xt()):e.key===`Escape`&&m(null)}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[W.id,f,c]),(0,q.useEffect)(()=>{function e(e){if(e_(e.target))return;let t=Be();e.clipboardData?.setData(Cg,t.token),e.clipboardData?.setData(`text/plain`,i_(t)),e.preventDefault()}async function t(e){if(e_(e.target))return;let t=e.clipboardData;if(!t)return;if(Tg&&t.getData(Cg)===Tg.token){e.preventDefault(),Ve();return}let n=Array.from(t.items).find(e=>e.kind===`file`&&e.type.startsWith(`image/`))?.getAsFile();if(n){e.preventDefault(),await ut(n);return}let r=t.getData(`text/plain`);r.trim()&&(e.preventDefault(),st(se.current,r))}return window.addEventListener(`copy`,e),window.addEventListener(`paste`,t),()=>{window.removeEventListener(`copy`,e),window.removeEventListener(`paste`,t)}},[c]);function Ne(){return{areas:structuredClone(V.current.areas),selectedAreaId:se.current,selectedElementId:ce.current}}function Pe(e){if(e&&de.current===e)return;let t=[...H.current.past,Ne()].slice(-100);H.current={past:t,future:[]},de.current=e??null,oe(e=>e+1)}function Fe(){de.current=null}function Ie(e){let t={...V.current,areas:structuredClone(e.areas)},n=t.areas.find(t=>t.id===e.selectedAreaId)??t.areas[0],r=n.elements.some(t=>t.id===e.selectedElementId)?e.selectedElementId:null;He(t,void 0,!1),d(n.id),m(r),g(!1),S(!1),N(null),We(t)}function Re(){let e=H.current.past.at(-1);if(!e)return;let t=H.current.past.slice(0,-1),n=[...H.current.future,Ne()].slice(-100);H.current={past:t,future:n},Fe(),oe(e=>e+1),Ie(e)}function ze(){let e=H.current.future.at(-1);if(!e)return;let t=[...H.current.past,Ne()].slice(-100),n=H.current.future.slice(0,-1);H.current={past:t,future:n},Fe(),oe(e=>e+1),Ie(e)}function Be(){let e=V.current.areas.find(e=>e.id===se.current)??V.current.areas[0],t=e.elements.find(e=>e.id===ce.current);return Tg=t?{kind:`element`,element:structuredClone(t),pasteCount:0,token:crypto.randomUUID()}:{kind:`area`,area:structuredClone(e),pasteCount:0,token:crypto.randomUUID()},Tg}function Ve(){if(!Tg)return;let e=V.current.areas.find(e=>e.id===se.current)??V.current.areas[0];if(Tg.pasteCount+=1,Tg.kind===`element`){let t=Tg.element,n=Math.round(V.current.canvas.width*.025*Tg.pasteCount),r={...gg(t),x:n_(t.x+n,0,Math.max(0,V.current.canvas.width-t.width)),y:n_(t.y+n,0,Math.max(0,V.current.canvas.height-t.height))};mt(e.id,r);return}let t=Tg.area,n=V.current.areas.findIndex(t=>t.id===e.id),r=_g(t,{name:Tg.pasteCount===1?`${t.name} copy`:`${t.name} copy ${Tg.pasteCount}`}),i=[...V.current.areas];i.splice(n+1,0,r);let a={...V.current,areas:i};He(a),d(r.id),m(null),g(!1),S(!1),N(null),We(a)}function He(e,t,n=!0){n&&t!==void 0?Pe(t):n&&e!==V.current&&Pe(),V.current=e,l(e)}function Ue(){U.current&&clearTimeout(U.current),P(`saving`),U.current=setTimeout(()=>{U.current=null,We()},350)}function We(e=V.current){Fe(),U.current&&=(clearTimeout(U.current),null);let t=++fe.current,n=structuredClone(e);P(`saving`),re(null);let r=pe.current.catch(()=>void 0).then(async()=>{try{let r=await ye(`/api/sets/${n.id}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});V.current===e&&(V.current=r,l(r),o(r)),t===fe.current&&P(`saved`)}catch(e){t===fe.current&&(re(Sn(e)),P(`error`))}});return pe.current=r,r}async function Ge(e){await We(),V.current.areas.find(e=>e.id===se.current)?.elements.some(t=>t.id===e)&&m(e)}function Ke(e,t,n){let r={...V.current,areas:V.current.areas.map(n=>n.id===e?t(n):n)};return He(r,n),r}function qe(e,t,n,r){return Ke(e,e=>({...e,elements:e.elements.map(e=>e.id===t?n(e):e)}),r)}function Ye(e){G&&qe(W.id,G.id,t=>({...t,...e}),`inspector:${W.id}:${G.id}`)}function Xe(e,t){let n=se.current,r=ce.current;r&&(qe(n,r,n=>({...n,x:n.x+e,y:n.y+t}),`keyboard:nudge:${n}:${r}`),Ue())}function Ze(e){if(!G||G.type!==`mockup`)return;let t=G.id;Ye(e),requestAnimationFrame(()=>{V.current.areas.find(e=>e.id===se.current)?.elements.some(e=>e.id===t)&&m(t)})}function Qe(e){if(!G)return;let t=W.id,n=G.id;l(r=>({...r,areas:r.areas.map(r=>r.id===t?{...r,elements:r.elements.map(t=>t.id===n?{...t,...e}:t)}:r)}))}function $e(){if(!f)return;let e=V.current.areas.find(e=>e.id===W.id)?.elements.find(e=>e.id===f);e&&l(t=>({...t,areas:t.areas.map(t=>t.id===W.id?{...t,elements:t.elements.map(t=>t.id===f?e:t)}:t)}))}function et(e,t){qe(e,t.id,()=>t,`canvas:${e}:${t.id}`),d(e),m(t.id),Ue()}function tt(){let e=V.current.areas.findIndex(e=>e.id===u),t=V.current.areas.length+1,n={id:`area-${crypto.randomUUID()}`,name:`Screenshot ${t}`,background:W.background,elements:[]},r=[...V.current.areas];r.splice(e+1,0,n);let i={...V.current,areas:r};He(i),d(n.id),m(null),We(i)}function nt(e){let t=V.current.areas.findIndex(t=>t.id===e),n=V.current.areas[t],r=_g(n,{name:`${n.name} copy`}),i=[...V.current.areas];i.splice(t+1,0,r);let a={...V.current,areas:i};He(a),d(r.id),m(null),We(a)}function rt(e,t){let n=V.current.areas.findIndex(t=>t.id===e),r=n+t;if(r<0||r>=V.current.areas.length)return;let i=[...V.current.areas],[a]=i.splice(n,1);i.splice(r,0,a);let o={...V.current,areas:i};He(o),We(o)}function it(e,t){let n=V.current.areas.find(t=>t.id===e);!n||n.name===t||We(Ke(e,e=>({...e,name:t})))}function ot(e){if(V.current.areas.length===1)return;let t=V.current.areas.findIndex(t=>t.id===e),n=V.current.areas.filter(t=>t.id!==e),r={...V.current,areas:n};He(r),d(n[Math.min(t,n.length-1)].id),m(null),ie(null),We(r)}function st(e=W.id,t=`Double-click to edit`){mt(e,{id:`element-${crypto.randomUUID()}`,type:`text`,text:t,x:Math.round(c.canvas.width*.1),y:Math.round(c.canvas.height*.08),width:Math.round(c.canvas.width*.8),height:Math.round(c.canvas.height*.1),rotation:0,opacity:1,fontFamily:`Geist Variable`,fontSize:Math.max(48,Math.round(c.canvas.width*.08)),fontWeight:700,color:`#ffffff`,textAlign:`center`})}async function ut(e){let t=se.current,n=$g(e.type),r=`pasted-image-${crypto.randomUUID()}${n}`;re(null);try{await ye(`/api/assets?category=other&filename=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":e.type||`application/octet-stream`},body:e});let n=await ye(`/api/project`);a(n);let i=n.assets.other.find(e=>e.name===r);if(!i)throw Error(`The pasted image was not found in the asset catalog`);await vt(i,t)}catch(e){re(Sn(e))}}function ft(e=W.id){mt(e,{id:`element-${crypto.randomUUID()}`,type:`shape`,shape:`rectangle`,x:Math.round(c.canvas.width*.2),y:Math.round(c.canvas.height*.3),width:Math.round(c.canvas.width*.6),height:Math.round(c.canvas.height*.2),rotation:0,opacity:1,fill:`#ffffff`,cornerRadius:Math.round(c.canvas.width*.025)})}function mt(e,t){let n=Ke(e,e=>({...e,elements:[...e.elements,t]}));d(e),m(t.id),g(!1),S(!1),w(!1),We(n)}function gt(e){let t=c.canvas.width*.58,n=c.canvas.height*.28,r=Math.min(t/e.width,n/e.height),i=Math.round(e.width*r),a=Math.round(e.height*r),o={id:`element-${crypto.randomUUID()}`,type:`image`,source:{kind:`builtin`,id:e.id},x:Math.round((c.canvas.width-i)/2),y:Math.round(c.canvas.height*.12),width:i,height:a,rotation:0,opacity:1,fit:`contain`,fill:`#ffffff`};mt(W.id,o)}async function vt(e,t=W.id){let n=c.canvas.width*.82,r=c.canvas.height*.72,i=await Qg(e.url),a=Math.min(n/i.width,r/i.height),o=Math.round(i.width*a),s=Math.round(i.height*a);mt(t,{id:`element-${crypto.randomUUID()}`,type:`image`,source:{kind:`asset`,assetId:e.id},x:Math.round((c.canvas.width-o)/2),y:Math.round((c.canvas.height-s)/2),width:o,height:s,rotation:0,opacity:1,fit:`contain`})}function yt(e,t){if(!xe.get(t)){re(`The selected screenshot is no longer available in the asset catalog.`);return}let n=c.canvas.width*.82,r=c.canvas.height*.76,i=Math.min(n/e.width,r/e.height),a=Math.round(e.width*i),o=Math.round(e.height*i),s={id:`element-${crypto.randomUUID()}`,type:`mockup`,mockupId:e.id,assetId:t,x:Math.round((c.canvas.width-a)/2),y:Math.round((c.canvas.height-o)/2),width:a,height:o,rotation:0,opacity:1};mt(W.id,s)}function bt(){if(!f)return;let e=Ke(W.id,e=>({...e,elements:e.elements.filter(e=>e.id!==f)}));m(null),We(e)}function xt(){if(!G)return;let e=gg(G,{offsetX:Math.round(c.canvas.width*.025),offsetY:Math.round(c.canvas.width*.025)}),t=Ke(W.id,t=>{let n=[...t.elements];return n.splice(De+1,0,e),{...t,elements:n}});m(e.id),We(t)}function St(e){if(!G)return;let t=De+e;t<0||t>=W.elements.length||We(Ke(W.id,e=>{let n=[...e.elements],[r]=n.splice(De,1);return n.splice(t,0,r),{...e,elements:n}}))}function Ct(e){if(!M)return;let t=V.current.areas.find(e=>e.id===M.areaId);if(!t)return;let n=t.elements.findIndex(e=>e.id===M.elementId),r=Math.min(Math.max(e,0),t.elements.length-1);n<0||n===r||We(Ke(t.id,e=>{let t=[...e.elements],[i]=t.splice(n,1);return t.splice(r,0,i),{...e,elements:t}}))}function wt(e){M&&(qe(M.areaId,M.elementId,t=>({...t,...e}),`context:${M.areaId}:${M.elementId}`),Ue())}async function Tt(){if(!F){re(null),I({completed:0,total:c.areas.length});try{await pg(c,xe,Se,I)}catch(e){re(`Export failed: ${Sn(e)}`)}finally{I(null)}}}return(0,J.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,children:[(0,J.jsxs)(`header`,{className:`flex h-[68px] shrink-0 items-center gap-4 border-b px-5`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-5`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(`h1`,{className:`truncate text-lg font-semibold`,children:c.name}),(0,J.jsx)(at,{variant:`secondary`,children:c.locale})]}),(0,J.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[c.device,` · `,c.canvas.width,` × `,c.canvas.height,` px`]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center rounded-lg border bg-background p-0.5`,children:[(0,J.jsx)(K,{"aria-label":`Undo`,disabled:!je,size:`icon-sm`,title:`Undo (Command/Ctrl Z)`,variant:`ghost`,onClick:Re,children:(0,J.jsx)(Qn,{className:`size-4`})}),(0,J.jsx)(K,{"aria-label":`Redo`,disabled:!Me,size:`icon-sm`,title:`Redo (Command/Ctrl Shift Z)`,variant:`ghost`,onClick:ze,children:(0,J.jsx)(Wn,{className:`size-4`})})]}),(0,J.jsx)(Jg,{state:ee})]}),(0,J.jsxs)(K,{className:`ml-auto`,disabled:F!==null,onClick:()=>void Tt(),children:[F?(0,J.jsx)(x,{className:`animate-spin`}):(0,J.jsx)(Ln,{}),F?`Exporting ${F.completed}/${F.total}`:`Export`]})]}),ne&&(0,J.jsx)(ht,{className:`shrink-0 rounded-none border-x-0 border-t-0 px-5 py-2`,variant:`destructive`,children:(0,J.jsx)(dt,{children:ne})}),(0,J.jsxs)(Je,{className:`min-h-0 flex-1`,id:`set-editor-shell`,orientation:`horizontal`,children:[(0,J.jsx)($t,{id:`set-canvas`,minSize:420,children:(0,J.jsxs)(`main`,{className:`relative h-full min-h-0 overflow-hidden bg-[#eeeeef]`,children:[(0,J.jsxs)(`div`,{className:`absolute left-3 top-3 z-20`,ref:me,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur-sm`,children:[(0,J.jsx)(Gg,{label:`Add text to selected screenshot`,onClick:()=>st(),children:(0,J.jsx)(Zn,{className:`size-4`})}),(0,J.jsx)(Gg,{label:`Add rectangle to selected screenshot`,onClick:()=>ft(),children:(0,J.jsx)(qn,{className:`size-4`})}),(0,J.jsx)(Gg,{active:C,label:`Add built-in artwork`,onClick:()=>{g(!1),S(!1),w(e=>!e)},children:(0,J.jsx)(Kn,{className:`size-4`})}),(0,J.jsx)(Gg,{active:h,label:`Add image from assets`,onClick:()=>{S(!1),w(!1),g(e=>!e)},children:(0,J.jsx)(_,{className:`size-4`})}),(0,J.jsx)(Gg,{active:b,label:`Add device mockup`,onClick:()=>{if(g(!1),w(!1),!b&&Te){let e=be.find(e=>e.id===k),t=be.find(e=>e.deviceType===Te.platform);t&&e?.deviceType!==Te.platform&&A(t.id)}S(e=>!e)},children:(0,J.jsx)(t,{className:`size-4`})}),(0,J.jsx)(`span`,{className:`mx-1 my-0.5 h-px bg-border`}),(0,J.jsx)(Gg,{label:`Add screenshot`,onClick:tt,children:(0,J.jsx)(Ce,{className:`size-4`})})]}),(0,J.jsx)(ba,{open:C,onClose:()=>w(!1),onSelect:gt}),h&&(0,J.jsxs)(`div`,{className:`absolute left-12 top-0 flex max-h-[min(520px,calc(100vh-160px))] w-64 flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-xl`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between border-b px-3 py-2.5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-semibold`,children:`Add image`}),(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Place an asset on this screenshot`})]}),(0,J.jsx)(K,{"aria-label":`Close asset picker`,className:`text-muted-foreground`,size:`icon-sm`,type:`button`,variant:`ghost`,onClick:()=>g(!1),children:(0,J.jsx)(p,{className:`size-3.5`})})]}),ge.length>0&&(0,J.jsx)(`div`,{className:`shrink-0 border-b p-2.5`,children:(0,J.jsxs)(ae,{value:v,onValueChange:e=>{e!==null&&y(e)},children:[(0,J.jsx)(he,{"aria-label":`Filter assets by type`,className:`w-full`,size:`sm`,children:(0,J.jsxs)(Dn,{children:[(0,J.jsx)(`span`,{children:ve.label}),(0,J.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:_e.length})]})}),(0,J.jsx)(ue,{align:`start`,children:wg.map(e=>(0,J.jsxs)(j,{value:e.value,children:[(0,J.jsx)(`span`,{children:e.label}),(0,J.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:e.value===`all`?ge.length:n[e.value].length})]},e.value))})]})}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2.5`,children:_e.length===0?(0,J.jsxs)(K,{className:`h-auto w-full flex-col border-dashed p-5 text-center text-xs whitespace-normal text-muted-foreground`,type:`button`,variant:`outline`,onClick:i,children:[(0,J.jsx)(e,{className:`mx-auto mb-2 size-5`}),ge.length===0?`Add assets to the catalog`:`No ${ve.label.toLowerCase()} yet`]}):(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:_e.map(e=>(0,J.jsx)(K,{className:`group aspect-square h-auto overflow-hidden rounded-lg bg-muted/40 p-0 hover:border-foreground/30`,title:`Place ${e.name}`,type:`button`,variant:`outline`,onClick:()=>void vt(e),children:(0,J.jsx)(`img`,{className:`h-full w-full object-contain transition-transform group-hover:scale-[1.03]`,src:e.url,alt:e.name})},e.id))})}),(0,J.jsx)(`div`,{className:`shrink-0 border-t p-2.5`,children:(0,J.jsx)(K,{className:`w-full`,size:`sm`,variant:`ghost`,onClick:i,children:`Open asset catalog`})})]}),b&&(0,J.jsxs)(`div`,{className:`absolute left-12 top-0 flex max-h-[min(620px,calc(100vh-160px))] w-72 flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-xl`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between border-b px-3 py-2.5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-semibold`,children:`Add device mockup`}),(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Choose a frame and its screenshot`})]}),(0,J.jsx)(K,{"aria-label":`Close device picker`,size:`icon-xs`,type:`button`,variant:`ghost`,onClick:()=>S(!1),children:(0,J.jsx)(p,{className:`size-3.5`})})]}),(0,J.jsx)(ua,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,J.jsxs)(`div`,{className:`space-y-4 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Frame`}),Te?(0,J.jsxs)(K,{className:`h-auto w-full justify-start gap-3 overflow-hidden p-2 text-left`,type:`button`,variant:`outline`,onClick:()=>E(!0),children:[(0,J.jsx)(`span`,{className:`grid size-16 shrink-0 place-items-center rounded-md bg-muted/60 p-1.5`,children:(0,J.jsx)(`img`,{alt:``,className:`max-h-full max-w-full object-contain`,src:Te.thumbnailUrl})}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:Te.name}),(0,J.jsx)(`span`,{className:`mt-1 block truncate text-[10px] text-muted-foreground`,children:Te.description}),(0,J.jsxs)(`span`,{className:`mt-2 block text-[10px] font-medium`,children:[`Browse `,s.mockups.length,` frames`]})]})]}):(0,J.jsx)(K,{className:`h-auto w-full justify-start p-4 text-xs`,type:`button`,variant:`outline`,onClick:()=>E(!0),children:`No device frames available. Import a mockup bundle.`})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Screenshot`}),be.length===0?(0,J.jsxs)(K,{className:`h-auto w-full flex-col border-dashed p-5 text-center text-xs whitespace-normal text-muted-foreground`,type:`button`,variant:`outline`,onClick:i,children:[(0,J.jsx)(e,{className:`mx-auto mb-2 size-5`}),`Add raw screenshots first`]}):(0,J.jsxs)(`div`,{className:`space-y-3`,children:[Te&&Ee.recommended.length>0&&(0,J.jsx)(jg,{assets:Ee.recommended,label:`Recommended · ${Pg(Te.platform)}`,selectedId:k,onSelect:A}),Ee.other.length>0&&(0,J.jsx)(jg,{assets:Ee.other,label:Ee.recommended.length>0?`Other screenshots`:`Screenshots`,selectedId:k,onSelect:A})]})]})]})}),(0,J.jsx)(`div`,{className:`relative z-10 shrink-0 border-t bg-popover p-3`,children:(0,J.jsx)(K,{className:`w-full`,disabled:!Te||!k,size:`sm`,type:`button`,onClick:()=>{Te&&k&&yt(Te,k)},children:`Add mockup`})})]}),(0,J.jsx)(rg,{open:T,value:D,onOpenChange:E,onValueChange:e=>{O(e);let t=_t(s,e)?.platform,n=be.find(e=>e.id===k),r=t&&be.find(e=>e.deviceType===t);r&&n?.deviceType!==t&&A(r.id)}})]}),(0,J.jsx)(`div`,{className:`h-full overflow-auto`,style:{backgroundImage:`radial-gradient(#d2d2d5 0.75px, transparent 0.75px)`,backgroundSize:`16px 16px`},onPointerDown:()=>m(null),children:(0,J.jsx)(`div`,{className:`flex min-w-max items-start pb-12 pl-20 pr-7 pt-7`,onPointerDown:e=>{e.target===e.currentTarget&&m(null),e.stopPropagation()},children:c.areas.map((e,t)=>{let n=e.id===W.id;return(0,J.jsxs)(q.Fragment,{children:[t>0&&(0,J.jsx)(`div`,{className:mn(`relative shrink-0 self-stretch transition-[width]`,L?`w-0`:`w-7`),children:(0,J.jsx)(K,{"aria-label":L?`Separate screenshots`:`Preview screenshots side by side`,"aria-pressed":L,className:`group/seam absolute inset-y-0 left-1/2 z-30 h-full w-7 -translate-x-1/2 rounded-none border-0 bg-transparent p-0 shadow-none hover:bg-transparent dark:hover:bg-transparent active:translate-y-0`,size:`icon-xs`,title:L?`Return to spaced screenshots`:`Snap screenshots side by side`,variant:`ghost`,onClick:()=>te(e=>!e),children:(0,J.jsx)(`span`,{className:mn(`absolute top-1 grid size-6 place-items-center rounded-md text-muted-foreground/45 transition-colors group-hover/seam:bg-background/80 group-hover/seam:text-muted-foreground group-focus-visible/seam:bg-background/80 group-focus-visible/seam:text-foreground`,L&&`bg-background/60 text-muted-foreground/70`),children:(0,J.jsx)(In,{className:`size-3.5`})})})}),(0,J.jsxs)(`article`,{className:`shrink-0`,children:[(0,J.jsxs)(`div`,{className:`mb-2 flex h-8 items-center justify-center gap-0.5 text-muted-foreground`,children:[(0,J.jsx)(Wg,{label:`Duplicate screenshot`,onClick:()=>nt(e.id),children:(0,J.jsx)(le,{className:`size-4`})}),(0,J.jsx)(Wg,{label:`Delete screenshot`,disabled:c.areas.length===1,onClick:()=>ie(e.id),children:(0,J.jsx)(vn,{className:`size-4`})}),(0,J.jsx)(Wg,{label:`Move screenshot left`,disabled:t===0,onClick:()=>rt(e.id,-1),children:(0,J.jsx)(An,{className:`size-4`})}),(0,J.jsx)(Wg,{label:`Move screenshot right`,disabled:t===c.areas.length-1,onClick:()=>rt(e.id,1),children:(0,J.jsx)(jn,{className:`size-4`})})]}),(0,J.jsxs)(Zi,{onOpenChange:t=>{!t&&M?.areaId===e.id&&N(null)},children:[(0,J.jsx)(Qi,{render:(0,J.jsx)(`div`,{className:mn(`transition-shadow`,n&&!L&&`ring-2 ring-[#1683ff] ring-offset-2 ring-offset-[#eeeeef]`),onClick:e=>e.stopPropagation()}),children:(0,J.jsx)(_h,{active:n,area:e,assetLookup:xe,mockupLookup:Se,canvasSize:c.canvas,continuousPreview:L,zoom:R,selectedElementId:n?f:null,onActivate:()=>d(e.id),onChange:t=>et(e.id,t),onContextMenu:t=>{if(!t){N(null);return}d(e.id),m(t),N({areaId:e.id,elementId:t})},onSelect:t=>{d(e.id),m(t)}})}),M?.areaId===e.id&&Oe&&ke&&(0,J.jsx)(Dg,{areaLength:Oe.elements.length,element:ke,elementIndex:Ae,usedColors:we,onMove:Ct,onUpdate:wt})]}),(0,J.jsx)(qg,{area:e,canvasSize:c.canvas,index:t,onActivate:()=>d(e.id),onRename:t=>it(e.id,t)})]})]},e.id)})})}),(0,J.jsxs)(`div`,{className:`absolute bottom-3 right-3 z-40 flex items-center rounded-lg border bg-background/95 p-0.5 shadow-md backdrop-blur-sm`,children:[(0,J.jsx)(K,{"aria-label":`Zoom out`,disabled:R<=bg,size:`icon-sm`,title:`Zoom out (Command/Ctrl −)`,variant:`ghost`,onClick:()=>z(e=>r_(e-Sg)),children:(0,J.jsx)(Vn,{className:`size-4`})}),(0,J.jsxs)(K,{"aria-label":`Reset zoom to 100%, currently ${Math.round(R*100)}%`,className:`min-w-14 px-2 tabular-nums`,size:`sm`,title:`Reset zoom (Command/Ctrl 0)`,variant:`ghost`,onClick:()=>z(1),children:[Math.round(R*100),`%`]}),(0,J.jsx)(K,{"aria-label":`Zoom in`,disabled:R>=xg,size:`icon-sm`,title:`Zoom in (Command/Ctrl +)`,variant:`ghost`,onClick:()=>z(e=>r_(e+Sg)),children:(0,J.jsx)(Ce,{className:`size-4`})})]})]})}),(0,J.jsx)(Rt,{"aria-label":`Resize editor sidebar`}),(0,J.jsx)($t,{defaultSize:300,groupResizeBehavior:`preserve-pixel-size`,id:`editor-sidebar`,maxSize:520,minSize:260,children:(0,J.jsx)(`aside`,{className:`h-full min-h-0 bg-background`,children:(0,J.jsxs)(Je,{id:`editor-sidebar-sections`,orientation:`vertical`,children:[(0,J.jsx)($t,{defaultSize:`38`,id:`layers-panel`,maxSize:`70`,minSize:116,children:(0,J.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-4 pb-2 pt-4`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Layers`}),(0,J.jsx)(`span`,{className:`text-[11px] tabular-nums text-muted-foreground`,children:W.elements.length})]}),(0,J.jsx)(ua,{className:`min-h-0 flex-1`,children:(0,J.jsx)(`div`,{className:`px-2 pb-3 pt-1`,children:W.elements.length===0?(0,J.jsx)(`p`,{className:`rounded-lg border border-dashed p-3 text-center text-xs text-muted-foreground`,children:`No layers yet`}):(0,J.jsx)(`div`,{className:`space-y-0.5`,children:[...W.elements].reverse().map(e=>(0,J.jsxs)(K,{"aria-pressed":e.id===f,className:`w-full justify-start px-2 text-xs`,size:`default`,type:`button`,variant:e.id===f?`secondary`:`ghost`,onClick:()=>m(e.id),children:[(0,J.jsx)(Yg,{element:e}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:Xg(e,xe,s)})]},e.id))})})})]})}),(0,J.jsx)(Rt,{"aria-label":`Resize layers panel`}),(0,J.jsx)($t,{id:`inspector-panel`,minSize:180,children:(0,J.jsx)(ua,{className:`h-full min-h-0`,children:(0,J.jsx)(`div`,{children:G?(0,J.jsxs)(Hg,{title:Zg(G),children:[(0,J.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-muted/20 p-1`,children:[(0,J.jsx)(Kg,{label:`Duplicate layer`,onClick:xt,children:(0,J.jsx)(le,{className:`size-4`})}),(0,J.jsx)(Kg,{label:`Send backward`,disabled:De===0,onClick:()=>St(-1),children:(0,J.jsx)(kn,{className:`size-4`})}),(0,J.jsx)(Kg,{label:`Bring forward`,disabled:De===W.elements.length-1,onClick:()=>St(1),children:(0,J.jsx)(Mn,{className:`size-4`})}),(0,J.jsx)(Kg,{label:`Flip horizontally`,onClick:()=>{Ye({flipX:!G.flipX}),We()},children:(0,J.jsx)(Rn,{className:`size-4`})}),(0,J.jsx)(Kg,{label:`Flip vertically`,onClick:()=>{Ye({flipY:!G.flipY}),We()},children:(0,J.jsx)(zn,{className:`size-4`})}),(0,J.jsx)(ct,{className:`mx-1 ml-auto h-5`,orientation:`vertical`}),(0,J.jsx)(Kg,{className:`text-destructive hover:text-destructive`,label:`Delete layer`,onClick:bt,children:(0,J.jsx)(vn,{className:`size-4`})})]}),G.type===`text`&&(0,J.jsx)(Og,{element:G,usedColors:we,preview:Qe,cancelPreview:$e,update:Ye,persist:()=>void We()}),G.type===`image`&&(0,J.jsx)(Fg,{element:G,assetLookup:xe,usedColors:we,update:Ye,persist:()=>void We()}),G.type===`mockup`&&(0,J.jsx)(Ig,{element:G,screenshots:be,update:Ze,persist:()=>void Ge(G.id)}),G.type===`shape`&&(0,J.jsx)(Lg,{element:G,usedColors:we,update:Ye,persist:()=>void We()}),(0,J.jsx)(Rg,{element:G,update:Ye,persist:()=>void We()}),(0,J.jsx)(zg,{element:G,update:Ye,persist:()=>void We()})]},G.id):(0,J.jsxs)(Hg,{action:(0,J.jsx)(K,{"aria-label":`Delete screenshot`,className:`text-destructive hover:text-destructive`,disabled:c.areas.length===1,size:`icon-xs`,title:c.areas.length===1?`A set must contain at least one screenshot`:`Delete this screenshot`,type:`button`,variant:`ghost`,onClick:()=>ie(W.id),children:(0,J.jsx)(vn,{className:`size-3.5`})}),title:`Screenshot ${c.areas.findIndex(e=>e.id===W.id)+1}`,children:[(0,J.jsx)(Vg,{label:`Name`,children:(0,J.jsx)(Lt,{value:W.name,onChange:e=>Ke(W.id,t=>({...t,name:e.target.value}),`area:${W.id}`),onBlur:()=>void We()})}),(0,J.jsx)(Vg,{label:`Background`,children:(0,J.jsx)(qh,{label:`Screenshot background color`,usedColors:we,value:W.background,onValueChange:e=>Ke(W.id,t=>({...t,background:e}),`area:${W.id}`),onValueCommit:()=>void We()})}),(0,J.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`Select an object to edit it. Drag to move, use the handles to resize, or double-click text to edit.`})]},W.id)})})})]})})})]}),(0,J.jsx)(Ht,{open:!!B,onOpenChange:e=>{e||ie(null)},children:(0,J.jsxs)(pt,{children:[(0,J.jsxs)(fn,{children:[(0,J.jsx)(wn,{children:`Delete this screenshot?`}),(0,J.jsx)(lt,{children:`The screenshot and all of its layers will be removed from this set. Catalog assets are kept.`})]}),(0,J.jsxs)(Le,{children:[(0,J.jsx)(jt,{render:(0,J.jsx)(K,{variant:`outline`}),children:`Cancel`}),(0,J.jsx)(K,{disabled:!B,variant:`destructive`,onClick:()=>{B&&ot(B)},children:`Delete screenshot`})]})]})})]})}function Dg({areaLength:e,element:t,elementIndex:n,usedColors:r,onMove:i,onUpdate:a}){let o=Math.round(t.opacity*100);return(0,J.jsxs)($i,{"aria-label":`Object actions`,className:`w-60 p-1.5`,sideOffset:4,children:[(0,J.jsxs)(ea,{children:[(0,J.jsx)(ta,{className:`px-2 py-1.5 text-[11px] uppercase tracking-wider`,children:Zg(t)}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,disabled:n===e-1,onClick:()=>i(e-1),children:[(0,J.jsx)(Fn,{}),`Bring to front`]}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,disabled:n===e-1,onClick:()=>i(n+1),children:[(0,J.jsx)(Mn,{}),`Bring forward`]}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,disabled:n===0,onClick:()=>i(n-1),children:[(0,J.jsx)(kn,{}),`Send backward`]}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,disabled:n===0,onClick:()=>i(0),children:[(0,J.jsx)(Pn,{}),`Send to back`]}),(0,J.jsx)(ca,{}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,onClick:()=>a({flipX:!t.flipX}),children:[(0,J.jsx)(Rn,{}),`Flip horizontally`]}),(0,J.jsxs)(na,{className:`h-8 gap-2 px-2 text-xs`,onClick:()=>a({flipY:!t.flipY}),children:[(0,J.jsx)(zn,{}),`Flip vertically`]})]}),t.type===`text`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(ra,{children:[(0,J.jsxs)(ia,{className:`h-8 gap-2 px-2 text-xs`,children:[t.textAlign===`left`?(0,J.jsx)(Xn,{}):t.textAlign===`right`?(0,J.jsx)(Yn,{}):(0,J.jsx)(Jn,{}),`Text alignment`,(0,J.jsx)(la,{className:`mr-3 normal-case tracking-normal`,children:Ag(t.textAlign)})]}),(0,J.jsx)(aa,{className:`w-40 p-1.5`,children:(0,J.jsxs)(oa,{value:t.textAlign,onValueChange:e=>a({textAlign:e}),children:[(0,J.jsxs)(sa,{className:`h-8 gap-2 px-2 text-xs`,value:`left`,children:[(0,J.jsx)(Xn,{}),`Left`]}),(0,J.jsxs)(sa,{className:`h-8 gap-2 px-2 text-xs`,value:`center`,children:[(0,J.jsx)(Jn,{}),`Center`]}),(0,J.jsxs)(sa,{className:`h-8 gap-2 px-2 text-xs`,value:`right`,children:[(0,J.jsx)(Yn,{}),`Right`]})]})})]}),(0,J.jsx)(ca,{}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 text-xs`,children:[(0,J.jsx)(`span`,{children:`Text color`}),(0,J.jsx)(qh,{compact:!0,label:`Text color`,usedColors:r,value:t.color,onValueChange:e=>a({color:e})})]})]}),t.type===`shape`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ca,{}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 text-xs`,children:[(0,J.jsx)(`span`,{children:`Fill color`}),(0,J.jsx)(qh,{compact:!0,label:`Fill color`,usedColors:r,value:t.fill,onValueChange:e=>a({fill:e})})]}),(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 px-2 py-1 text-xs`,children:[(0,J.jsx)(`span`,{children:`Corner radius`}),(0,J.jsx)(Lt,{className:`h-7 w-20 text-right text-xs`,min:0,type:`number`,value:Math.round(t.cornerRadius),onChange:e=>a({cornerRadius:Math.max(0,Number(e.target.value))})})]})]}),(0,J.jsx)(ca,{}),(0,J.jsxs)(`div`,{className:`space-y-2 px-2 pb-2 pt-1.5 text-xs`,onKeyDown:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`span`,{children:`Opacity`}),(0,J.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[o,`%`]})]}),(0,J.jsx)(fa,{"aria-label":`Opacity`,max:100,min:0,value:[o],onValueChange:e=>a({opacity:(typeof e==`number`?e:e[0])/100})})]})]})}function Og({element:e,usedColors:t,preview:r,cancelPreview:i,update:o,persist:s}){let[c,l]=(0,q.useState)(jm);(0,q.useEffect)(()=>{let t=!1;if(e.fontFamily===`Geist Variable`){l([400,600,700,800]);return}return Rm().then(n=>{let r=n.find(t=>t.familyName===e.fontFamily);t||l(r?.weights??jm)}).catch(()=>{t||l(jm)}),()=>{t=!0}},[e.fontFamily]);let u=c.includes(e.fontWeight)?c:[...c,e.fontWeight].sort((e,t)=>e-t);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Vg,{label:`Text`,children:(0,J.jsx)(xt,{className:`min-h-20 resize-y`,value:e.text,onChange:e=>o({text:e.target.value}),onBlur:s})}),(0,J.jsx)(Vg,{label:`Font`,children:(0,J.jsx)(Rh,{value:e.fontFamily,onCancel:i,onPreview:t=>{let n=Gh(t.weights,e.fontWeight);l(t.weights),r({fontFamily:t.familyName,fontWeight:n}),zm(t.familyName,n).catch(()=>void 0)},onSelect:t=>{let n=Gh(t.weights,e.fontWeight);l(t.weights),o({fontFamily:t.familyName,fontWeight:n}),zm(t.familyName,n).catch(()=>void 0),setTimeout(s)}})}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,J.jsx)(Bg,{label:`Font size`,min:1,value:e.fontSize,onChange:e=>o({fontSize:e}),onBlur:s}),(0,J.jsx)(Vg,{label:`Weight`,children:(0,J.jsxs)(ae,{value:e.fontWeight,onValueChange:e=>{e!==null&&(o({fontWeight:e}),setTimeout(s))},children:[(0,J.jsx)(he,{className:`w-full`,children:(0,J.jsx)(Dn,{children:kg(e.fontWeight)})}),(0,J.jsx)(ue,{children:u.map(e=>(0,J.jsx)(j,{value:e,children:kg(e)},e))})]})})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,J.jsx)(Vg,{label:`Color`,children:(0,J.jsx)(qh,{label:`Text color`,usedColors:t,value:e.color,onValueChange:e=>o({color:e}),onValueCommit:s})}),(0,J.jsx)(Vg,{label:`Align`,children:(0,J.jsxs)(ae,{value:e.textAlign,onValueChange:e=>{e!==null&&(o({textAlign:e}),setTimeout(s))},children:[(0,J.jsx)(he,{className:`w-full`,children:(0,J.jsx)(Dn,{children:Ag(e.textAlign)})}),(0,J.jsxs)(ue,{children:[(0,J.jsx)(j,{value:`left`,children:`Left`}),(0,J.jsx)(j,{value:`center`,children:`Center`}),(0,J.jsx)(j,{value:`right`,children:`Right`})]})]})})]}),(0,J.jsx)(Vg,{label:`Line height`,children:(0,J.jsxs)(y,{children:[(0,J.jsx)(wt,{"aria-label":`Line height in pixels`,min:1,placeholder:String(Math.round(e.fontSize*n)),step:1,type:`number`,value:e.lineHeight??``,onBlur:s,onChange:e=>{o({lineHeight:e.target.value===``?void 0:Math.max(1,Number(e.target.value))})}}),(0,J.jsxs)(h,{align:`inline-end`,children:[(0,J.jsx)(a,{children:`px`}),(0,J.jsx)(se,{"aria-label":`Use automatic line height`,"aria-pressed":e.lineHeight===void 0,variant:e.lineHeight===void 0?`secondary`:`ghost`,onClick:()=>{o({lineHeight:void 0}),setTimeout(s)},children:`Auto`})]})]})})]})}function kg(e){return e===400?`Regular`:e===600?`Semibold`:e===700?`Bold`:e===800?`Extra bold`:e===900?`Black`:String(e)}function Ag(e){return e[0].toUpperCase()+e.slice(1)}function jg({assets:e,label:t,selectedId:n,onSelect:r}){return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-1.5 text-[10px] font-medium text-muted-foreground`,children:t}),(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:e.map(e=>(0,J.jsx)(K,{"aria-label":`Use ${e.name}`,"aria-pressed":n===e.id,className:mn(`relative aspect-square h-auto overflow-hidden rounded-lg bg-muted/40 p-0 hover:border-foreground/30 active:translate-y-0`,n===e.id&&`border-foreground ring-1 ring-foreground`),title:`${e.name} · ${e.deviceType===`unknown`||!e.deviceType?`Unknown device`:Pg(e.deviceType)}`,type:`button`,variant:`outline`,onClick:()=>r(e.id),children:(0,J.jsx)(`img`,{alt:``,className:`h-full w-full object-cover`,src:e.url})},e.id))})]})}function Mg({asset:e}){return(0,J.jsxs)(j,{value:e.id,children:[(0,J.jsx)(`img`,{alt:``,className:`size-7 rounded bg-muted object-cover`,src:e.url}),(0,J.jsx)(`span`,{className:`max-w-48 truncate text-xs`,children:e.name})]})}function Ng(e,t){return t?{recommended:e.filter(e=>e.deviceType===t),other:e.filter(e=>e.deviceType!==t)}:{recommended:[],other:e}}function Pg(e){return{iphone:`iPhone`,ipad:`iPad`,mac:`Mac`,watch:`Watch`}[e]}function Fg({element:e,assetLookup:t,usedColors:n,update:r,persist:i}){let a=e.source.kind===`builtin`?va(e.source.id):void 0,o=e.source.kind===`asset`?t.get(e.source.assetId):void 0,s=a?.name??o?.name??`Missing image`,c=a?.url??o?.url;function l(){r({fill:e.fill?void 0:`#ffffff`}),i()}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border p-2`,children:[(0,J.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded bg-muted/50 p-1.5`,children:c?e.fill?(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`size-full bg-current`,style:{color:e.fill??`#000000`,maskImage:`url(${c})`,maskPosition:`center`,maskRepeat:`no-repeat`,maskSize:`contain`,WebkitMaskImage:`url(${c})`,WebkitMaskPosition:`center`,WebkitMaskRepeat:`no-repeat`,WebkitMaskSize:`contain`}}):(0,J.jsx)(`img`,{alt:``,className:`size-full object-contain`,src:c}):(0,J.jsx)(Kn,{className:`size-4 text-muted-foreground`})}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-xs`,children:s}),a&&(0,J.jsxs)(`span`,{className:`mt-0.5 block truncate text-[10px] text-muted-foreground`,children:[a.attribution,` · `,a.license]})]})]}),(0,J.jsxs)(Vg,{label:`Color`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(K,{"aria-pressed":!!e.fill,size:`sm`,type:`button`,variant:`outline`,onClick:l,children:e.fill?`Use original`:`Colorize`}),e.fill&&(0,J.jsx)(qh,{className:`min-w-0 flex-1`,label:`Image fill color`,usedColors:n,value:e.fill,onValueChange:e=>r({fill:e}),onValueCommit:i})]}),(0,J.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:`Colorizing replaces visible pixels while preserving transparency.`})]})]})}function Ig({element:e,screenshots:n,update:r,persist:i}){let{catalog:a}=rn(),[o,s]=(0,q.useState)(!1),c=_t(a,e.mockupId),l=n.find(t=>t.id===e.assetId),u=Ng(n,c?.platform);function d(t){let n=_t(a,t);if(!n)return;let o=Math.round(e.width*n.height/n.width);r({mockupId:t,height:o,y:Math.round(e.y+(e.height-o)/2)}),setTimeout(i)}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Vg,{label:`Frame`,children:(0,J.jsxs)(K,{className:`h-auto w-full justify-start gap-2 p-2 text-left`,type:`button`,variant:`outline`,onClick:()=>s(!0),children:[c?(0,J.jsx)(`img`,{alt:``,className:`size-12 rounded bg-muted object-contain`,src:c.thumbnailUrl}):(0,J.jsx)(t,{className:`size-4`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:c?.name??`Missing frame`}),c&&(0,J.jsx)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:c.description})]}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Change`})]})}),(0,J.jsx)(rg,{open:o,value:e.mockupId,onOpenChange:s,onValueChange:d}),(0,J.jsx)(Vg,{label:`Screenshot`,children:(0,J.jsxs)(ae,{value:e.assetId,onValueChange:e=>{e!==null&&(r({assetId:e}),setTimeout(i))},children:[(0,J.jsx)(he,{className:`w-full`,children:(0,J.jsx)(Dn,{children:l?.name??`Missing screenshot`})}),(0,J.jsxs)(ue,{children:[u.recommended.length>0&&(0,J.jsxs)(C,{children:[(0,J.jsxs)(R,{children:[`Recommended · `,c?Pg(c.platform):`Device`]}),u.recommended.map(e=>(0,J.jsx)(Mg,{asset:e},e.id))]}),u.other.length>0&&(0,J.jsxs)(C,{children:[(0,J.jsx)(R,{children:u.recommended.length>0?`Other screenshots`:`Screenshots`}),u.other.map(e=>(0,J.jsx)(Mg,{asset:e},e.id))]})]})]})})]})}function Lg({element:e,usedColors:t,update:n,persist:r}){return(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,J.jsx)(Vg,{label:`Fill`,children:(0,J.jsx)(qh,{label:`Shape fill color`,usedColors:t,value:e.fill,onValueChange:e=>n({fill:e}),onValueCommit:r})}),(0,J.jsx)(Bg,{label:`Corner radius`,min:0,value:e.cornerRadius,onChange:e=>n({cornerRadius:e}),onBlur:r})]})}function Rg({element:e,update:t,persist:n}){let{catalog:r}=rn(),i=e.type===`mockup`?_t(r,e.mockupId):void 0;function a(e){t(i?{width:e,height:Math.max(1,Math.round(e*i.height/i.width))}:{width:e})}function o(e){t(i?{width:Math.max(1,Math.round(e*i.width/i.height)),height:e}:{height:e})}return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:`Position and size`}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,J.jsx)(Bg,{label:`X`,value:Math.round(e.x),onChange:e=>t({x:e}),onBlur:n}),(0,J.jsx)(Bg,{label:`Y`,value:Math.round(e.y),onChange:e=>t({y:e}),onBlur:n}),(0,J.jsx)(Bg,{label:`Width`,min:1,value:Math.round(e.width),onChange:a,onBlur:n}),e.type!==`text`&&(0,J.jsx)(Bg,{label:`Height`,min:1,value:Math.round(e.height),onChange:o,onBlur:n}),(0,J.jsx)(Bg,{label:`Rotation`,value:Math.round(e.rotation),onChange:e=>t({rotation:e}),onBlur:n})]})]})}function zg({element:e,update:t,persist:n}){let r=Math.round(e.opacity*100),i=(0,q.useId)();return(0,J.jsxs)(dn,{"aria-labelledby":i,className:`gap-1.5`,children:[(0,J.jsxs)(tt,{className:`text-xs`,id:i,children:[`Opacity · `,r,`%`]}),(0,J.jsx)(fa,{"aria-labelledby":i,max:100,min:0,value:[r],onValueChange:e=>t({opacity:(typeof e==`number`?e:e[0])/100}),onValueCommitted:n})]})}function Bg({label:e,value:t,min:n,onChange:r,onBlur:i}){let a=(0,q.useId)(),[o,s]=(0,q.useState)(String(t));(0,q.useEffect)(()=>s(String(t)),[t]);function c(){if(o.trim()===``)return!1;let e=Number(o);return!Number.isFinite(e)||n!==void 0&&e<n?!1:(r(e),!0)}function l(){c()||s(String(t)),i()}return(0,J.jsxs)(dn,{className:`gap-1.5`,children:[(0,J.jsx)(tt,{className:`text-xs`,htmlFor:a,children:e}),(0,J.jsx)(Lt,{id:a,min:n,type:`number`,value:o,onBlur:l,onChange:e=>{let t=e.target.value;s(t);let i=Number(t);t.trim()!==``&&Number.isFinite(i)&&(n===void 0||i>=n)&&r(i)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&(s(String(t)),e.currentTarget.blur())}})]})}function Vg({label:e,children:t}){let n=(0,q.useId)();return(0,J.jsxs)(dn,{"aria-labelledby":n,className:`gap-1.5`,children:[(0,J.jsx)(tt,{className:`text-xs`,id:n,children:e}),t]})}function Hg({title:e,action:t,children:n}){return(0,J.jsxs)(`section`,{className:`space-y-3 border-b p-4`,children:[(0,J.jsxs)(`div`,{className:`flex min-h-6 items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t]}),n]})}function Ug(e){let t=[];for(let n of e.areas){t.push(n.background);for(let e of n.elements)e.type===`text`&&t.push(e.color),e.type===`shape`&&t.push(e.fill),e.type===`image`&&e.fill&&t.push(e.fill)}return t}function Wg({label:e,disabled:t,children:n,onClick:r}){return(0,J.jsx)(K,{"aria-label":e,className:`hover:bg-black/5`,disabled:t,size:`icon`,title:e,type:`button`,variant:`ghost`,onClick:r,children:n})}function Gg({active:e,label:t,children:n,onClick:r}){return(0,J.jsx)(K,{"aria-label":t,"aria-pressed":e,className:`text-muted-foreground`,size:`icon-lg`,title:t,type:`button`,variant:e?`secondary`:`ghost`,onClick:r,children:n})}function Kg({label:e,className:t,disabled:n,children:r,onClick:i}){return(0,J.jsx)(K,{"aria-label":e,className:t,disabled:n,size:`icon`,title:e,type:`button`,variant:`ghost`,onClick:i,children:r})}function qg({area:e,canvasSize:t,index:n,onActivate:r,onRename:i}){let[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(e.name),l=(0,q.useRef)(!1);(0,q.useEffect)(()=>{a||c(e.name)},[e.name,a]);function u(){l.current=!1,c(e.name),o(!0),r()}function d(){if(l.current){l.current=!1,o(!1),c(e.name);return}let t=s.trim();o(!1),c(t||e.name),t&&i(t)}return a?(0,J.jsxs)(`div`,{className:`mt-2 flex min-h-6 items-center justify-between gap-3 text-xs text-muted-foreground`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`span`,{className:`shrink-0`,children:[`#`,n+1,` ·`]}),(0,J.jsx)(Lt,{autoFocus:!0,"aria-label":`Screenshot ${n+1} name`,className:`h-6 w-40 px-1.5 py-0 text-xs`,value:s,onBlur:d,onChange:e=>c(e.target.value),onFocus:e=>e.currentTarget.select(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),t.currentTarget.blur()):t.key===`Escape`&&(t.preventDefault(),l.current=!0,o(!1),c(e.name))}})]}),(0,J.jsxs)(`span`,{className:`shrink-0`,children:[t.width,` × `,t.height]})]}):(0,J.jsxs)(K,{"aria-label":`Select screenshot ${n+1}`,className:`-mx-1 mt-2 h-auto min-h-6 w-[calc(100%+0.5rem)] cursor-default justify-between gap-3 rounded px-1 py-0.5 text-xs font-normal whitespace-normal text-muted-foreground hover:bg-transparent hover:text-muted-foreground active:translate-y-0`,type:`button`,variant:`ghost`,onClick:r,onKeyDown:e=>{e.key===`F2`&&(e.preventDefault(),u())},children:[(0,J.jsxs)(`span`,{className:`min-w-0 truncate`,title:`Double-click to rename`,onDoubleClick:e=>{e.stopPropagation(),u()},children:[`#`,n+1,` · `,e.name]}),(0,J.jsxs)(`span`,{className:`shrink-0`,children:[t.width,` × `,t.height]})]})}function Jg({state:e}){return(0,J.jsxs)(`span`,{className:mn(`mr-1 flex shrink-0 items-center gap-1.5 text-xs text-muted-foreground`,e===`error`&&`text-destructive`),children:[e===`saving`?(0,J.jsx)(x,{className:`size-3.5 animate-spin`}):(0,J.jsx)(s,{className:`size-3.5`}),e===`saving`?`Saving`:e===`error`?`Not saved`:`Saved`]})}function Yg({element:e}){return e.type===`text`?(0,J.jsx)(Zn,{className:`size-3.5 text-muted-foreground`}):e.type===`image`?(0,J.jsx)(_,{className:`size-3.5 text-muted-foreground`}):e.type===`mockup`?(0,J.jsx)(t,{className:`size-3.5 text-muted-foreground`}):(0,J.jsx)(qn,{className:`size-3.5 text-muted-foreground`})}function Xg(e,t,n){return e.type===`text`?e.text.trim().split(`
|
|
440
|
+
`)[0]||`Text`:e.type===`image`?e.source.kind===`builtin`?va(e.source.id)?.name??`Artwork`:t.get(e.source.assetId)?.name??`Image`:e.type===`mockup`?_t(n,e.mockupId)?.name??`Device mockup`:`Rectangle`}function Zg(e){return e.type===`text`?`Text layer`:e.type===`image`?`Image layer`:e.type===`mockup`?`Device mockup`:`Rectangle layer`}async function Qg(e){let t=new window.Image;t.src=e;try{return await t.decode(),{width:t.naturalWidth||1,height:t.naturalHeight||1}}catch{return{width:1,height:1}}}function $g(e){return e===`image/jpeg`?`.jpg`:e===`image/svg+xml`?`.svg`:e===`image/webp`?`.webp`:`.png`}function e_(e){return e instanceof HTMLElement&&!!e.closest(`input, textarea, select, [contenteditable='true']`)}function t_(e){return e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`||e===`ArrowUp`}function n_(e,t,n){return Math.min(Math.max(e,t),n)}function r_(e){return n_(Math.round(e*100)/100,bg,xg)}function i_(e){return e.kind===`area`?e.area.name:e.element.type===`text`?e.element.text:e.element.type===`image`?`StoreShot image layer`:e.element.type===`mockup`?`StoreShot device mockup layer`:`StoreShot rectangle layer`}export{Eg as SetEditor};
|