@jeevandev/flow-canvas 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +235 -79
- package/dist/flow-canvas.css +1 -1
- package/dist/flow-canvas.es.js +4570 -2273
- package/dist/flow-canvas.umd.js +8 -13
- package/dist/index.d.ts +877 -93
- package/package.json +36 -11
package/dist/flow-canvas.umd.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
(function(G,I){typeof exports=="object"&&typeof module<"u"?I(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],I):(G=typeof globalThis<"u"?globalThis:G||self,I(G.FlowCanvas={},G.React))})(this,(function(G,I){"use strict";var vt=document.createElement("style");vt.textContent=`.ce-editor{position:relative;width:100%;height:100%;overflow:hidden;background-color:#f3f4f6}.ce-editor__canvas{position:absolute;top:0;left:0;width:100%;height:100%;touch-action:none;transform-origin:0 0}.ce-editor__viewport{width:100%;height:100%;overflow:hidden}.ce-editor__viewport--panning{cursor:grab!important}.ce-editor__viewport--panning *{pointer-events:none!important}.ce-editor__grid-layer{position:absolute;top:-50000px;left:-50000px;width:100000px;height:100000px;opacity:.5;pointer-events:none;z-index:0}.ce-editor__content-area{position:absolute;left:0;top:0;background-color:#fff;overflow:hidden;z-index:1;box-shadow:0 0 20px #0000001a}.ce-editor__infinite-area{position:relative;z-index:1}.ce-element{position:absolute;touch-action:none;-webkit-user-select:none;user-select:none;box-sizing:border-box;transition:box-shadow .1s}.ce-element--selected{outline:2px solid #3b82f6;outline-width:calc(2px * var(--ce-inverse-zoom, 1));box-shadow:0 0 0 calc(4px * var(--ce-inverse-zoom, 1)) #3b82f633;z-index:100!important}.ce-element img{pointer-events:none;-webkit-user-drag:none;-webkit-user-select:none;user-select:none}.ce-editor--connecting{cursor:crosshair!important}.ce-editor--connecting .ce-element:hover{outline:2px dashed #3b82f6;outline-width:calc(2px * var(--ce-inverse-zoom, 1));background-color:#3b82f60d;cursor:copy}.ce-editor--connecting .ce-handle:hover{transform:scale(1.5);background-color:#3b82f6!important;border-color:#fff!important;transition:transform .1s}.ce-resize-handle{width:calc(10px * var(--ce-inverse-zoom, 1));height:calc(10px * var(--ce-inverse-zoom, 1));background:#fff;border:calc(1px * var(--ce-inverse-zoom, 1)) solid #3b82f6;position:absolute;z-index:101}.ce-resize-handle--nw{top:calc(-6px * var(--ce-inverse-zoom, 1));left:calc(-6px * var(--ce-inverse-zoom, 1));cursor:nw-resize}.ce-resize-handle--ne{top:calc(-6px * var(--ce-inverse-zoom, 1));right:calc(-6px * var(--ce-inverse-zoom, 1));cursor:ne-resize}.ce-resize-handle--sw{bottom:calc(-6px * var(--ce-inverse-zoom, 1));left:calc(-6px * var(--ce-inverse-zoom, 1));cursor:sw-resize}.ce-resize-handle--se{bottom:calc(-6px * var(--ce-inverse-zoom, 1));right:calc(-6px * var(--ce-inverse-zoom, 1));cursor:se-resize}.ce-resize-handle--n{top:calc(-6px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);cursor:n-resize}.ce-resize-handle--s{bottom:calc(-6px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);cursor:s-resize}.ce-resize-handle--e{right:calc(-6px * var(--ce-inverse-zoom, 1));top:50%;transform:translateY(-50%);cursor:e-resize}.ce-resize-handle--w{left:calc(-6px * var(--ce-inverse-zoom, 1));top:50%;transform:translateY(-50%);cursor:w-resize}.ce-rotate-handle{width:calc(24px * var(--ce-inverse-zoom, 1));height:calc(24px * var(--ce-inverse-zoom, 1));background:#fff;border:none;box-shadow:0 2px 4px #0003;border-radius:50%;position:absolute;top:auto;bottom:calc(-35px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);cursor:grab;z-index:101;display:flex;align-items:center;justify-content:center;color:#555}.ce-rotate-handle:after{display:none}.ce-rotate-handle:active{cursor:grabbing;background:#f3f4f6;color:#000}.ce-drag-handle-minimal{width:calc(24px * var(--ce-inverse-zoom, 1));height:calc(24px * var(--ce-inverse-zoom, 1));position:absolute;top:auto;bottom:calc(-35px * var(--ce-inverse-zoom, 1));left:calc(50% + calc(30px * var(--ce-inverse-zoom, 1)));transform:translate(-50%);background-color:#fff;border-radius:50%;box-shadow:0 2px 4px #0003;cursor:grab;z-index:102;display:flex;align-items:center;justify-content:center;color:#555;background-image:none}.ce-drag-handle-minimal:active{cursor:grabbing;background-color:#f3f4f6;color:#000}.ce-snap-guide{position:absolute;background-color:#f0f;pointer-events:none;z-index:200}.ce-snap-guide--vertical{width:1px;height:100vh}.ce-snap-guide--horizontal{height:1px;width:100vw}.ce-node-default,.ce-node-input,.ce-node-output{background:#fff;border:1px solid #777;border-radius:4px;padding:10px;min-width:180px;text-align:center;font-size:14px;color:#222;box-shadow:0 1px 4px #0000001a;position:relative}.ce-node-input{border-color:#3b82f6}.ce-node-output{border-color:#10b981}.ce-node-content{pointer-events:none}.ce-handle{width:10px;height:10px;background:#fff;border-radius:50%;position:absolute;border:3px solid #777;z-index:10;cursor:crosshair;transition:border-color .2s}.ce-handle--left{left:0;transform:translate(-50%)}.ce-handle--right{right:0;transform:translate(50%)}.ce-handle--top{top:0;transform:translateY(-50%)}.ce-handle--bottom{bottom:0;transform:translateY(50%)}.ce-workflow-node:hover .ce-delete-node-btn{opacity:1;pointer-events:auto}.ce-delete-node-btn{position:absolute;top:-8px;right:-8px;width:18px;height:18px;background:#ff4d4f;color:#fff;border:none;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;line-height:1;padding:0;z-index:20;opacity:0;pointer-events:none;transition:opacity .2s,transform .1s;box-shadow:0 2px 4px #0000001a}.ce-delete-node-btn:hover{transform:scale(1.1);background:#ff7875}.ce-edge-group .ce-edge-delete-fo{opacity:0;pointer-events:none;transition:opacity .2s}.ce-edge-group:hover .ce-edge-delete-fo{opacity:1;pointer-events:auto}.ce-connection-line{animation:dashdraw .5s linear infinite}@keyframes dashdraw{0%{stroke-dashoffset:10}to{stroke-dashoffset:0}}
|
|
2
|
-
/*$vite$:1*/`,document.head.appendChild(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<%s key={someKey} {...props} />`,W,M,K,M),se[M+W]=!0)}if(M=null,H!==void 0&&(n(H),M=""+H),i(A)&&(n(A.key),M=""+A.key),"key"in A){H={};for(var L in A)L!=="key"&&(H[L]=A[L])}else H=A;return M&&a(H,typeof u=="function"?u.displayName||u.name||"Unknown":u),d(u,M,H,s(),be,E)}function _(u){m(u)?u._store&&(u._store.validated=1):typeof u=="object"&&u!==null&&u.$$typeof===k&&(u._payload.status==="fulfilled"?m(u._payload.value)&&u._payload.value._store&&(u._payload.value._store.validated=1):u._store&&(u._store.validated=1))}function m(u){return typeof u=="object"&&u!==null&&u.$$typeof===N}var w=I,N=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),v=Symbol.for("react.context"),D=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),O=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),S=Symbol.for("react.activity"),j=Symbol.for("react.client.reference"),R=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,x=Object.prototype.hasOwnProperty,B=Array.isArray,Z=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(u){return u()}};var q,Y={},U=w.react_stack_bottom_frame.bind(w,o)(),de=Z(r(o)),se={};xe.Fragment=c,xe.jsx=function(u,A,H){var W=1e4>R.recentlyCreatedOwnerStacks++;return f(u,A,H,!1,W?Error("react-stack-top-frame"):U,W?Z(r(u)):de)},xe.jsxs=function(u,A,H){var W=1e4>R.recentlyCreatedOwnerStacks++;return f(u,A,H,!0,W?Error("react-stack-top-frame"):U,W?Z(r(u)):de)}})()),xe}var wt;function bn(){return wt||(wt=1,process.env.NODE_ENV==="production"?Ce.exports=vn():Ce.exports=_n()),Ce.exports}var y=bn();const xt=t=>{let e;const n=new Set,r=(d,f)=>{const _=typeof d=="function"?d(e):d;if(!Object.is(_,e)){const m=e;e=f??(typeof _!="object"||_===null)?_:Object.assign({},e,_),n.forEach(w=>w(e,m))}},s=()=>e,a={setState:r,getState:s,getInitialState:()=>l,subscribe:d=>(n.add(d),()=>n.delete(d))},l=e=t(r,s,a);return a},wn=(t=>t?xt(t):xt),xn=t=>t;function En(t,e=xn){const n=I.useSyncExternalStore(t.subscribe,I.useCallback(()=>e(t.getState()),[t,e]),I.useCallback(()=>e(t.getInitialState()),[t,e]));return I.useDebugValue(n),n}var Et=Symbol.for("immer-nothing"),St=Symbol.for("immer-draftable"),J=Symbol.for("immer-state"),Sn=process.env.NODE_ENV!=="production"?[function(t){return`The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`},function(t){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`},"This object has been frozen and should not be mutated",function(t){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+t},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(t){return`'current' expects a draft, got: ${t}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(t){return`'original' expects a draft, got: ${t}`}]:[];function ee(t,...e){if(process.env.NODE_ENV!=="production"){const n=Sn[t],r=he(n)?n.apply(null,e):n;throw new Error(`[Immer] ${r}`)}throw new Error(`[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`)}var te=Object,me=te.getPrototypeOf,Ae="constructor",ze="prototype",Je="configurable",Me="enumerable",je="writable",Ee="value",ue=t=>!!t&&!!t[J];function ae(t){return t?kt(t)||Le(t)||!!t[St]||!!t[Ae]?.[St]||$e(t)||Ye(t):!1}var Tn=te[ze][Ae].toString(),Tt=new WeakMap;function kt(t){if(!t||!Qe(t))return!1;const e=me(t);if(e===null||e===te[ze])return!0;const n=te.hasOwnProperty.call(e,Ae)&&e[Ae];if(n===Object)return!0;if(!he(n))return!1;let r=Tt.get(n);return r===void 0&&(r=Function.toString.call(n),Tt.set(n,r)),r===Tn}function Se(t,e,n=!0){Te(t)===0?(n?Reflect.ownKeys(t):te.keys(t)).forEach(s=>{e(s,t[s],t)}):t.forEach((r,s)=>e(s,r,t))}function Te(t){const e=t[J];return e?e.type_:Le(t)?1:$e(t)?2:Ye(t)?3:0}var It=(t,e,n=Te(t))=>n===2?t.has(e):te[ze].hasOwnProperty.call(t,e),Ze=(t,e,n=Te(t))=>n===2?t.get(e):t[e],Re=(t,e,n,r=Te(t))=>{r===2?t.set(e,n):r===3?t.add(n):t[e]=n};function kn(t,e){return t===e?t!==0||1/t===1/e:t!==t&&e!==e}var Le=Array.isArray,$e=t=>t instanceof Map,Ye=t=>t instanceof Set,Qe=t=>typeof t=="object",he=t=>typeof t=="function",et=t=>typeof t=="boolean",ce=t=>t.copy_||t.base_,tt=t=>t.modified_?t.copy_:t.base_;function nt(t,e){if($e(t))return new Map(t);if(Ye(t))return new Set(t);if(Le(t))return Array[ze].slice.call(t);const n=kt(t);if(e===!0||e==="class_only"&&!n){const r=te.getOwnPropertyDescriptors(t);delete r[J];let s=Reflect.ownKeys(r);for(let o=0;o<s.length;o++){const i=s[o],a=r[i];a[je]===!1&&(a[je]=!0,a[Je]=!0),(a.get||a.set)&&(r[i]={[Je]:!0,[je]:!0,[Me]:a[Me],[Ee]:t[i]})}return te.create(me(t),r)}else{const r=me(t);if(r!==null&&n)return{...t};const s=te.create(r);return te.assign(s,t)}}function rt(t,e=!1){return Ve(t)||ue(t)||!ae(t)||(Te(t)>1&&te.defineProperties(t,{set:He,add:He,clear:He,delete:He}),te.freeze(t),e&&Se(t,(n,r)=>{rt(r,!0)},!1)),t}function In(){ee(2)}var He={[Ee]:In};function Ve(t){return t===null||!Qe(t)?!0:te.isFrozen(t)}var Fe="MapSet",st="Patches",Pt={};function ge(t){const e=Pt[t];return e||ee(0,t),e}var Pn=t=>!!Pt[t],ke,Dt=()=>ke,Dn=(t,e)=>({drafts_:[],parent_:t,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:Pn(Fe)?ge(Fe):void 0});function Ot(t,e){e&&(t.patchPlugin_=ge(st),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function ot(t){it(t),t.drafts_.forEach(On),t.drafts_=null}function it(t){t===ke&&(ke=t.parent_)}var Nt=t=>ke=Dn(ke,t);function On(t){const e=t[J];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function Ct(t,e){e.unfinalizedDrafts_=e.drafts_.length;const n=e.drafts_[0];if(t!==void 0&&t!==n){n[J].modified_&&(ot(e),ee(4)),ae(t)&&(t=At(e,t));const{patchPlugin_:s}=e;s&&s.generateReplacementPatches_(n[J].base_,t,e)}else t=At(e,n);return Nn(e,t,!0),ot(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==Et?t:void 0}function At(t,e){if(Ve(e))return e;const n=e[J];if(!n)return at(e,t.handledSet_,t);if(!Ue(n,t))return e;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(t);jt(n,t)}return n.copy_}function Nn(t,e,n=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&rt(e,n)}function zt(t){t.finalized_=!0,t.scope_.unfinalizedDrafts_--}var Ue=(t,e)=>t.scope_===e,Cn=[];function Mt(t,e,n,r){const s=ce(t),o=t.type_;if(r!==void 0&&Ze(s,r,o)===e){Re(s,r,n,o);return}if(!t.draftLocations_){const a=t.draftLocations_=new Map;Se(s,(l,d)=>{if(ue(d)){const f=a.get(d)||[];f.push(l),a.set(d,f)}})}const i=t.draftLocations_.get(e)??Cn;for(const a of i)Re(s,a,n,o)}function An(t,e,n){t.callbacks_.push(function(s){const o=e;if(!o||!Ue(o,s))return;s.mapSetPlugin_?.fixSetContents(o);const i=tt(o);Mt(t,o.draft_??o,i,n),jt(o,s)})}function jt(t,e){if(t.modified_&&!t.finalized_&&(t.type_===3||(t.assigned_?.size??0)>0)){const{patchPlugin_:r}=e;if(r){const s=r.getPath(t);s&&r.generatePatches_(t,s,e)}zt(t)}}function zn(t,e,n){const{scope_:r}=t;if(ue(n)){const s=n[J];Ue(s,r)&&s.callbacks_.push(function(){Be(t);const i=tt(s);Mt(t,n,i,e)})}else ae(n)&&t.callbacks_.push(function(){const o=ce(t);Ze(o,e,t.type_)===n&&r.drafts_.length>1&&(t.assigned_.get(e)??!1)===!0&&t.copy_&&at(Ze(t.copy_,e,t.type_),r.handledSet_,r)})}function at(t,e,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||ue(t)||e.has(t)||!ae(t)||Ve(t)||(e.add(t),Se(t,(r,s)=>{if(ue(s)){const o=s[J];if(Ue(o,n)){const i=tt(o);Re(t,r,i,t.type_),zt(o)}}else ae(s)&&at(s,e,n)})),t}function Mn(t,e){const n=Le(t),r={type_:n?1:0,scope_:e?e.scope_:Dt(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=r,o=ct;n&&(s=[r],o=Ie);const{revoke:i,proxy:a}=Proxy.revocable(s,o);return r.draft_=a,r.revoke_=i,[a,r]}var ct={get(t,e){if(e===J)return t;const n=ce(t);if(!It(n,e,t.type_))return jn(t,n,e);const r=n[e];if(t.finalized_||!ae(r))return r;if(r===lt(t.base_,e)){Be(t);const s=t.type_===1?+e:e,o=dt(t.scope_,r,t,s);return t.copy_[s]=o}return r},has(t,e){return e in ce(t)},ownKeys(t){return Reflect.ownKeys(ce(t))},set(t,e,n){const r=Rt(ce(t),e);if(r?.set)return r.set.call(t.draft_,n),!0;if(!t.modified_){const s=lt(ce(t),e),o=s?.[J];if(o&&o.base_===n)return t.copy_[e]=n,t.assigned_.set(e,!1),!0;if(kn(n,s)&&(n!==void 0||It(t.base_,e,t.type_)))return!0;Be(t),ut(t)}return t.copy_[e]===n&&(n!==void 0||e in t.copy_)||Number.isNaN(n)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=n,t.assigned_.set(e,!0),zn(t,e,n)),!0},deleteProperty(t,e){return Be(t),lt(t.base_,e)!==void 0||e in t.base_?(t.assigned_.set(e,!1),ut(t)):t.assigned_.delete(e),t.copy_&&delete t.copy_[e],!0},getOwnPropertyDescriptor(t,e){const n=ce(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r&&{[je]:!0,[Je]:t.type_!==1||e!=="length",[Me]:r[Me],[Ee]:n[e]}},defineProperty(){ee(11)},getPrototypeOf(t){return me(t.base_)},setPrototypeOf(){ee(12)}},Ie={};Se(ct,(t,e)=>{Ie[t]=function(){const n=arguments;return n[0]=n[0][0],e.apply(this,n)}}),Ie.deleteProperty=function(t,e){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(e))&&ee(13),Ie.set.call(this,t,e,void 0)},Ie.set=function(t,e,n){return process.env.NODE_ENV!=="production"&&e!=="length"&&isNaN(parseInt(e))&&ee(14),ct.set.call(this,t[0],e,n,t[0])};function lt(t,e){const n=t[J];return(n?ce(n):t)[e]}function jn(t,e,n){const r=Rt(e,n);return r?Ee in r?r[Ee]:r.get?.call(t.draft_):void 0}function Rt(t,e){if(!(e in t))return;let n=me(t);for(;n;){const r=Object.getOwnPropertyDescriptor(n,e);if(r)return r;n=me(n)}}function ut(t){t.modified_||(t.modified_=!0,t.parent_&&ut(t.parent_))}function Be(t){t.copy_||(t.assigned_=new Map,t.copy_=nt(t.base_,t.scope_.immer_.useStrictShallowCopy_))}var Rn=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,n,r)=>{if(he(e)&&!he(n)){const o=n;n=e;const i=this;return function(l=o,...d){return i.produce(l,f=>n.call(this,f,...d))}}he(n)||ee(6),r!==void 0&&!he(r)&&ee(7);let s;if(ae(e)){const o=Nt(this),i=dt(o,e,void 0);let a=!0;try{s=n(i),a=!1}finally{a?ot(o):it(o)}return Ot(o,r),Ct(s,o)}else if(!e||!Qe(e)){if(s=n(e),s===void 0&&(s=e),s===Et&&(s=void 0),this.autoFreeze_&&rt(s,!0),r){const o=[],i=[];ge(st).generateReplacementPatches_(e,s,{patches_:o,inversePatches_:i}),r(o,i)}return s}else ee(1,e)},this.produceWithPatches=(e,n)=>{if(he(e))return(i,...a)=>this.produceWithPatches(i,l=>e(l,...a));let r,s;return[this.produce(e,n,(i,a)=>{r=i,s=a}),r,s]},et(t?.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),et(t?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),et(t?.useStrictIteration)&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){ae(t)||ee(8),ue(t)&&(t=Ln(t));const e=Nt(this),n=dt(e,t,void 0);return n[J].isManual_=!0,it(e),n}finishDraft(t,e){const n=t&&t[J];(!n||!n.isManual_)&&ee(9);const{scope_:r}=n;return Ot(r,e),Ct(void 0,r)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,e){let n;for(n=e.length-1;n>=0;n--){const s=e[n];if(s.path.length===0&&s.op==="replace"){t=s.value;break}}n>-1&&(e=e.slice(n+1));const r=ge(st).applyPatches_;return ue(t)?r(t,e):this.produce(t,s=>r(s,e))}};function dt(t,e,n,r){const[s,o]=$e(e)?ge(Fe).proxyMap_(e,n):Ye(e)?ge(Fe).proxySet_(e,n):Mn(e,n);return(n?.scope_??Dt()).drafts_.push(s),o.callbacks_=n?.callbacks_??[],o.key_=r,n&&r!==void 0?An(n,o,r):o.callbacks_.push(function(l){l.mapSetPlugin_?.fixSetContents(o);const{patchPlugin_:d}=l;o.modified_&&d&&d.generatePatches_(o,[],l)}),s}function Ln(t){return ue(t)||ee(10,t),Lt(t)}function Lt(t){if(!ae(t)||Ve(t))return t;const e=t[J];let n,r=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,n=nt(t,e.scope_.immer_.useStrictShallowCopy_),r=e.scope_.immer_.shouldUseStrictIteration()}else n=nt(t,!0);return Se(n,(s,o)=>{Re(n,s,Lt(o))},r),e&&(e.finalized_=!1),n}var $n=new Rn,Yn=$n.produce;const Hn=t=>(e,n,r)=>(r.setState=(s,o,...i)=>{const a=typeof s=="function"?Yn(s):s;return e(a,o,...i)},t(r.setState,n,r)),Vn={snapping:!0,snapGuide:!0,rotation:!0,rotationSpeed:2,rotationSnap:5,zoom:!0,pan:!0,viewOnly:!1,minZoom:.1,maxZoom:5,showGrid:!0,gridSize:20,gridColor:"#ddd"},Fn=(t=[],e=[],n={})=>wn(Hn(r=>({nodes:t.reduce((s,o)=>({...s,[o.id]:o}),{}),edges:e.reduce((s,o)=>({...s,[o.id]:o}),{}),selectedIds:[],camera:{x:0,y:0,zoom:1},dimensions:{width:0,height:0},config:{...Vn,...n},connectionState:{nodeId:null,handleId:null,handleType:null,position:null,isValid:!1},startConnection:(s,o,i,a)=>r(l=>{l.connectionState={nodeId:s,handleId:o,handleType:i,position:a,isValid:!0}}),updateConnection:s=>r(o=>{o.connectionState.nodeId&&(o.connectionState.position=s)}),endConnection:()=>r(s=>{s.connectionState={nodeId:null,handleId:null,handleType:null,position:null,isValid:!1}}),setCamera:s=>r(o=>{Object.assign(o.camera,s)}),panCamera:(s,o)=>r(i=>{i.camera.x+=s,i.camera.y+=o}),zoomCamera:(s,o,i)=>r(a=>{const{minZoom:l=.1,maxZoom:d=5}=a.config,f=Math.min(Math.max(a.camera.zoom*s,l),d),_=(o-a.camera.x)/a.camera.zoom,m=(i-a.camera.y)/a.camera.zoom;a.camera.x=o-_*f,a.camera.y=i-m*f,a.camera.zoom=f}),setDimensions:(s,o)=>r(i=>{i.dimensions={width:s,height:o}}),setNodes:s=>r(o=>{o.nodes=s.reduce((i,a)=>({...i,[a.id]:a}),{})}),addNode:s=>r(o=>{o.nodes[s.id]=s}),updateNode:(s,o)=>r(i=>{i.nodes[s]&&Object.assign(i.nodes[s],o)}),registerHandle:(s,o,i)=>r(a=>{const l=a.nodes[s];l&&(l.handles||(l.handles={}),l.handles[o]={id:o,...i})}),removeNode:s=>r(o=>{delete o.nodes[s],Object.keys(o.edges).forEach(i=>{const a=o.edges[i];(a.source===s||a.target===s)&&delete o.edges[i]}),o.selectedIds=o.selectedIds.filter(i=>i!==s)}),setEdges:s=>r(o=>{o.edges=s.reduce((i,a)=>({...i,[a.id]:a}),{})}),addEdge:s=>r(o=>{Object.values(o.edges).some(a=>a.source===s.source&&a.target===s.target&&a.sourceHandle===s.sourceHandle&&a.targetHandle===s.targetHandle)||(o.edges[s.id]=s)}),removeEdge:s=>r(o=>{delete o.edges[s]}),selectNode:s=>r(o=>{o.selectedIds=s?[s]:[]}),resizeNode:(s,o,i,a,l)=>r(d=>{d.nodes[s]&&(d.nodes[s].x=o,d.nodes[s].y=i,d.nodes[s].width=a,d.nodes[s].height=l)}),rotateNode:(s,o)=>r(i=>{i.nodes[s]&&(i.nodes[s].rotation=o)}),deleteSelected:()=>r(s=>{s.selectedIds.forEach(o=>{s.nodes[o]?(delete s.nodes[o],Object.keys(s.edges).forEach(i=>{const a=s.edges[i];(a.source===o||a.target===o)&&delete s.edges[i]})):s.edges[o]&&delete s.edges[o]}),s.selectedIds=[]}),selectAll:()=>r(s=>{s.selectedIds=Object.keys(s.nodes)}),deselectAll:()=>r(s=>{s.selectedIds=[]}),duplicateSelected:()=>r(s=>{const o=[];s.selectedIds.forEach(i=>{const a=s.nodes[i];if(a){const l=`node-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,d={...a,id:l,x:a.x+20,y:a.y+20};s.nodes[l]=d,o.push(d)}}),s.selectedIds=o.map(i=>i.id)}),nudgeSelected:(s,o)=>r(i=>{i.selectedIds.forEach(a=>{const l=i.nodes[a];l&&(l.x+=s,l.y+=o)})}),setConfig:s=>r(o=>{o.config={...o.config,...s}})}))),ft=I.createContext(null),Un=({children:t,initialNodes:e=[],initialEdges:n=[],nodes:r,config:s={},className:o="",style:i,onChange:a})=>{const l=I.useRef(null);return l.current||(l.current=Fn(e,n,s)),I.useEffect(()=>{r&&l.current&&l.current.getState().setNodes(r)},[r]),I.useEffect(()=>{if(!a||!l.current)return;const d=l.current.subscribe(f=>{a(f)});return()=>d()},[a]),I.useEffect(()=>{l.current&&l.current.getState().setConfig(s)},[s]),y.jsx(ft.Provider,{value:l.current,children:y.jsx("div",{className:`ce-editor ${o}`,style:i,children:t})})},z=t=>{const e=I.useContext(ft);if(!e)throw new Error("useEditor must be used within Editor");return En(e,t)},We=()=>{const t=I.useContext(ft);if(!t)throw new Error("useEditor must be used within Editor");return t},$t=I.createContext(null),Bn=({id:t,children:e})=>y.jsx($t.Provider,{value:t,children:e}),Wn=()=>{const t=I.useContext($t);return t||null},Pe=({type:t,id:e="default",position:n="top",className:r="",style:s,...o})=>{const i=Wn(),a=z(w=>w.startConnection),l=z(w=>w.camera),d=z(w=>w.registerHandle),f=We(),_=I.useRef(null);I.useEffect(()=>{if(!i||!_.current)return;const w=()=>{const c=document.getElementById(i);if(!c||!_.current)return;const g=c.getBoundingClientRect(),p=_.current.getBoundingClientRect(),b=f.getState().camera.zoom,v=(p.left+p.width/2-g.left)/b,D=(p.top+p.height/2-g.top)/b;d(i,e,{type:t,position:n,x:v,y:D,width:p.width/b,height:p.height/b})};w();const N=document.getElementById(i);if(!N)return;const C=new ResizeObserver(()=>{requestAnimationFrame(w)});return C.observe(N),()=>C.disconnect()},[i,e,t,n,d]);const m=w=>{if(!i)return;w.stopPropagation();const N=document.querySelector(".ce-editor__viewport")?.getBoundingClientRect();if(!N)return;const C=(w.clientX-N.left-l.x)/l.zoom,c=(w.clientY-N.top-l.y)/l.zoom;a(i,e,t,{x:C,y:c})};return y.jsx("div",{ref:_,"data-handle-type":t,"data-handle-id":e,onPointerDown:m,className:`ce-handle ce-handle--${n} ${r}`,style:s,...o})},Xe=({data:t,...e})=>y.jsxs("div",{className:"ce-node-default",...e,style:e.style,children:[y.jsx(Pe,{type:"target",position:"left",id:"input"}),y.jsx("div",{className:"ce-node-content",children:t.label||"Default Node"}),y.jsx(Pe,{type:"source",position:"right",id:"output"})]}),Yt=({data:t,...e})=>y.jsxs("div",{className:"ce-node-input",...e,style:e.style,children:[y.jsx("div",{className:"ce-node-content",children:t.label||"Input Node"}),y.jsx(Pe,{type:"source",position:"right",id:"output"})]}),Ht=({data:t,...e})=>y.jsxs("div",{className:"ce-node-output",...e,style:e.style,children:[y.jsx(Pe,{type:"target",position:"left",id:"input"}),y.jsx("div",{className:"ce-node-content",children:t.label||"Output Node"})]});function Xn(t,e,n){return Math.max(e,Math.min(t,n))}const $={toVector(t,e){return t===void 0&&(t=e),Array.isArray(t)?t:[t,t]},add(t,e){return[t[0]+e[0],t[1]+e[1]]},sub(t,e){return[t[0]-e[0],t[1]-e[1]]},addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function Vt(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function Ft(t,e,n,r=.15){return r===0?Xn(t,e,n):t<e?-Vt(e-t,n-e,r)+e:t>n?+Vt(t-n,n-e,r)+n:t}function Kn(t,[e,n],[r,s]){const[[o,i],[a,l]]=t;return[Ft(e,o,i,r),Ft(n,a,l,s)]}function Gn(t,e){if(typeof t!="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function qn(t){var e=Gn(t,"string");return typeof e=="symbol"?e:String(e)}function X(t,e,n){return e=qn(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ut(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function V(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ut(Object(n),!0).forEach(function(r){X(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ut(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const Bt={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function Wt(t){return t?t[0].toUpperCase()+t.slice(1):""}const Jn=["enter","leave"];function Zn(t=!1,e){return t&&!Jn.includes(e)}function Qn(t,e="",n=!1){const r=Bt[t],s=r&&r[e]||e;return"on"+Wt(t)+Wt(s)+(Zn(n,s)?"Capture":"")}const er=["gotpointercapture","lostpointercapture"];function tr(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=er.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:n}}function nr(t,e=""){const n=Bt[t],r=n&&n[e]||e;return t+r}function Ke(t){return"touches"in t}function Xt(t){return Ke(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function rr(t){return Array.from(t.touches).filter(e=>{var n,r;return e.target===t.currentTarget||((n=t.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,e.target))})}function sr(t){return t.type==="touchend"||t.type==="touchcancel"?t.changedTouches:t.targetTouches}function Kt(t){return Ke(t)?sr(t)[0]:t}function ht(t,e){try{const n=e.clientX-t.clientX,r=e.clientY-t.clientY,s=(e.clientX+t.clientX)/2,o=(e.clientY+t.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function or(t){return rr(t).map(e=>e.identifier)}function Gt(t,e){const[n,r]=Array.from(t.touches).filter(s=>e.includes(s.identifier));return ht(n,r)}function pt(t){const e=Kt(t);return Ke(t)?e.identifier:e.pointerId}function ye(t){const e=Kt(t);return[e.clientX,e.clientY]}const qt=40,Jt=800;function Zt(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=qt,n*=qt):r===2&&(e*=Jt,n*=Jt),[e,n]}function ir(t){var e,n;const{scrollX:r,scrollY:s,scrollLeft:o,scrollTop:i}=t.currentTarget;return[(e=r??o)!==null&&e!==void 0?e:0,(n=s??i)!==null&&n!==void 0?n:0]}function ar(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o}=t;Object.assign(e,{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o})}return e}function Ge(t,...e){return typeof t=="function"?t(...e):t}function cr(){}function lr(...t){return t.length===0?cr:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function Qt(t,e){return Object.assign({},e,t||{})}const ur=32;class en{constructor(e,n,r){this.ctrl=e,this.args=n,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:n,ingKey:r,args:s}=this;n[r]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=e.target,n.currentTarget=e.currentTarget,n.lastOffset=r.from?Ge(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=e.timeStamp)}computeValues(e){const n=this.state;n._values=e,n.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:n,config:r,shared:s}=this;n.args=this.args;let o=0;if(e&&(n.event=e,r.preventDefault&&e.cancelable&&n.event.preventDefault(),n.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,ar(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const h=n._delta.map(Math.abs);$.addTo(n._distance,h)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,d]=r.threshold,{_step:f,values:_}=n;if(r.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(i)>=l&&_[0]),f[1]===!1&&(f[1]=Math.abs(a)>=d&&_[1])):(f[0]===!1&&(f[0]=Math.abs(i)>=l&&Math.sign(i)*l),f[1]===!1&&(f[1]=Math.abs(a)>=d&&Math.sign(a)*d)),n.intentional=f[0]!==!1||f[1]!==!1,!n.intentional)return;const m=[0,0];if(r.hasCustomTransform){const[h,O]=_;m[0]=f[0]!==!1?h-f[0]:0,m[1]=f[1]!==!1?O-f[1]:0}else m[0]=f[0]!==!1?i-f[0]:0,m[1]=f[1]!==!1?a-f[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(m);const w=n.offset,N=n._active&&!n._blocked||n.active;N&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=s[this.ingKey]=n._active,e&&(n.first&&("bounds"in r&&(n._bounds=Ge(r.bounds,n)),this.setup&&this.setup()),n.movement=m,this.computeOffset()));const[C,c]=n.offset,[[g,p],[b,v]]=n._bounds;n.overflow=[C<g?-1:C>p?1:0,c<b?-1:c>v?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const D=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=Kn(n._bounds,n.offset,D),n.delta=$.sub(n.offset,w),this.computeMovement(),N&&(!n.last||o>ur)){n.delta=$.sub(n.offset,w);const h=n.delta.map(Math.abs);$.addTo(n.distance,h),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&o>0&&(n.velocity=[h[0]/o,h[1]/o],n.timeDelta=o)}}emit(){const e=this.state,n=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const s=this.handler(V(V(V({},n),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function dr([t,e],n){const r=Math.abs(t),s=Math.abs(e);if(r>s&&r>n)return"x";if(s>r&&s>n)return"y"}class De extends en{constructor(...e){super(...e),X(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=$.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=$.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const n=this.state,r=this.config;if(!n.axis&&e){const s=typeof r.axisThreshold=="object"?r.axisThreshold[Xt(e)]:r.axisThreshold;n.axis=dr(n._movement,s)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const tn=t=>t,nn=.15,mt={enabled(t=!0){return t},eventOptions(t,e,n){return V(V({},n.shared.eventOptions),t)},preventDefault(t=!1){return t},triggerAllEvents(t=!1){return t},rubberband(t=0){switch(t){case!0:return[nn,nn];case!1:return[0,0];default:return $.toVector(t)}},from(t){if(typeof t=="function")return t;if(t!=null)return $.toVector(t)},transform(t,e,n){const r=t||n.shared.transform;if(this.hasCustomTransform=!!r,process.env.NODE_ENV==="development"){const s=r||tn;return o=>{const i=s(o);return(!isFinite(i[0])||!isFinite(i[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${i[0]},${[1]}]`),i}}return r||tn},threshold(t){return $.toVector(t,0)}};process.env.NODE_ENV==="development"&&Object.assign(mt,{domTarget(t){if(t!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(t){if(t!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(t){if(t!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const fr=0,pe=V(V({},mt),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=fr){return t},bounds(t={}){if(typeof t=="function")return o=>pe.bounds(t(o));if("current"in t)return()=>t.current;if(typeof HTMLElement=="function"&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:n=1/0,top:r=-1/0,bottom:s=1/0}=t;return[[e,n],[r,s]]}}),rn={ArrowRight:(t,e=1)=>[t*e,0],ArrowLeft:(t,e=1)=>[-1*t*e,0],ArrowUp:(t,e=1)=>[0,-1*t*e],ArrowDown:(t,e=1)=>[0,t*e]};class hr extends De{constructor(...e){super(...e),X(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const n=e._bounds.getBoundingClientRect(),r=e.currentTarget.getBoundingClientRect(),s={left:n.left-r.left+e.offset[0],right:n.right-r.right+e.offset[0],top:n.top-r.top+e.offset[1],bottom:n.bottom-r.bottom+e.offset[1]};e._bounds=pe.bounds(s)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const n=this.config,r=this.state;if(e.buttons!=null&&(Array.isArray(n.pointerButtons)?!n.pointerButtons.includes(e.buttons):n.pointerButtons!==-1&&n.pointerButtons!==e.buttons))return;const s=this.ctrl.setEventIds(e);n.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(s&&s.size>1&&r._pointerActive)&&(this.start(e),this.setupPointer(e),r._pointerId=pt(e),r._pointerActive=!0,this.computeValues(ye(e)),this.computeInitial(),n.preventScrollAxis&&Xt(e)!=="mouse"?(r._active=!1,this.setupScrollPrevention(e)):n.delay>0?(this.setupDelayTrigger(e),n.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const n=this.state;n._active=!0,n._preventScroll=!0,n._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const n=this.state,r=this.config;if(!n._pointerActive)return;const s=pt(e);if(n._pointerId!==void 0&&s!==n._pointerId)return;const o=ye(e);if(document.pointerLockElement===e.target?n._delta=[e.movementX,e.movementY]:(n._delta=$.sub(o,n._values),this.computeValues(o)),$.addTo(n._movement,n._delta),this.compute(e),n._delayed&&n.intentional){this.timeoutStore.remove("dragDelay"),n.active=!1,this.startPointerDrag(e);return}if(r.preventScrollAxis&&!n._preventScroll)if(n.axis)if(n.axis===r.preventScrollAxis||r.preventScrollAxis==="xy"){n._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{process.env.NODE_ENV==="development"&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const n=this.state,r=this.config;if(!n._active||!n._pointerActive)return;const s=pt(e);if(n._pointerId!==void 0&&s!==n._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[o,i]=n._distance;if(n.tap=o<=r.tapsThreshold&&i<=r.tapsThreshold,n.tap&&r.filterTaps)n._force=!0;else{const[a,l]=n._delta,[d,f]=n._movement,[_,m]=r.swipe.velocity,[w,N]=r.swipe.distance,C=r.swipe.duration;if(n.elapsedTime<C){const c=Math.abs(a/n.timeDelta),g=Math.abs(l/n.timeDelta);c>_&&Math.abs(d)>w&&(n.swipe[0]=Math.sign(a)),g>m&&Math.abs(f)>N&&(n.swipe[1]=Math.sign(l))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const n=this.config,r=n.device;if(process.env.NODE_ENV==="development")try{if(r==="pointer"&&n.preventScrollDelay===void 0){const s="uv"in e?e.sourceEvent.currentTarget:e.currentTarget;window.getComputedStyle(s).touchAction==="auto"&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",s)}}catch{}n.pointerLock&&e.currentTarget.requestPointerLock(),n.pointerCapture||(this.eventStore.add(this.sharedConfig.window,r,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,r,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,r,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,pr(e);const n=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",n),this.eventStore.add(this.sharedConfig.window,"touch","cancel",n),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const n=rn[e.key];if(n){const r=this.state,s=e.shiftKey?10:e.altKey?.1:1;this.start(e),r._delta=n(this.config.keyboardDisplacement,s),r._keyboardActive=!0,$.addTo(r._movement,r._delta),this.compute(e),this.emit()}}keyUp(e){e.key in rn&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const n=this.config.device;e(n,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(n,"change",this.pointerMove.bind(this)),e(n,"end",this.pointerUp.bind(this)),e(n,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function pr(t){"persist"in t&&typeof t.persist=="function"&&t.persist()}const Oe=typeof window<"u"&&window.document&&window.document.createElement;function sn(){return Oe&&"ontouchstart"in window}function mr(){return sn()||Oe&&window.navigator.maxTouchPoints>1}function gr(){return Oe&&"onpointerdown"in window}function yr(){return Oe&&"exitPointerLock"in window.document}function vr(){try{return"constructor"in GestureEvent}catch{return!1}}const re={isBrowser:Oe,gesture:vr(),touch:sn(),touchscreen:mr(),pointer:gr(),pointerLock:yr()},_r=250,br=180,wr=.5,xr=50,Er=250,Sr=10,on={mouse:0,touch:0,pen:8},an=V(V({},pe),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&re.pointerLock,re.touch&&n?"touch":this.pointerLock?"mouse":re.pointer&&!s?"pointer":re.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?_r:void 0,!(!re.touchscreen||n===!1))return t||(n!==void 0?"y":void 0)},pointerCapture(t,e,{pointer:{capture:n=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:s=void 0}){const o=$.toVector(t,n?r:s?1:0);return this.filterTaps=n,this.tapsThreshold=r,o},swipe({velocity:t=wr,distance:e=xr,duration:n=Er}={}){return{velocity:this.transform($.toVector(t)),distance:this.transform($.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return br;case!1:return 0;default:return t}},axisThreshold(t){return t?V(V({},on),t):on},keyboardDisplacement(t=Sr){return t}});process.env.NODE_ENV==="development"&&Object.assign(an,{useTouch(t){if(t!==void 0)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(t){if(t!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(t){if(t!==void 0)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(t){if(t!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(t){if(t!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}});function cn(t){const[e,n]=t.overflow,[r,s]=t._delta,[o,i]=t._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(t._movement[0]=t._movementBound[0]),(n<0&&s>0&&i<0||n>0&&s<0&&i>0)&&(t._movement[1]=t._movementBound[1])}const Tr=30,kr=100;class Ir extends en{constructor(...e){super(...e),X(this,"ingKey","pinching"),X(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:n,lastOffset:r}=this.state;e==="wheel"?this.state.offset=$.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:n}=this.state;this.state.movement=[e[0]/n[0],e[1]-n[1]]}axisIntent(){const e=this.state,[n,r]=e._movement;if(!e.axis){const s=Math.abs(n)*Tr-Math.abs(r);s<0?e.axis="angle":s>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(e),n._touchIds=Array.from(r).slice(0,2);const s=Gt(e,n._touchIds);s&&this.pinchStart(e,s)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const n=this.state,r=n._pointerEvents,s=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),n._pointerEvents.size<2))return;this.start(e);const o=ht(...Array.from(r.values()));o&&this.pinchStart(e,o)}pinchStart(e,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const n=Gt(e,this.state._touchIds);n&&this.pinchMove(e,n)}pointerMove(e){const n=this.state._pointerEvents;if(n.has(e.pointerId)&&n.set(e.pointerId,e),!this.state._active)return;const r=ht(...Array.from(n.values()));r&&this.pinchMove(e,r)}pinchMove(e,n){const r=this.state,s=r._values[1],o=n.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),this.computeValues([n.distance,n.angle-360*i]),r.origin=n.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const n=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}n._pointerEvents.has(e.pointerId)&&n._pointerEvents.delete(e.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const n=this.state;n._active||(this.start(e),this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY];const r=n._movement;n._movement=[e.scale-1,e.rotation],n._delta=$.sub(n._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>e[r]):!e[n])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||(e.cancelable&&e.preventDefault(),process.env.NODE_ENV==="development"&&!e.defaultPrevented&&console.warn("[@use-gesture]: To properly support zoom on trackpads, try using the `target` option.\n\nThis message will only appear in development mode."));const r=this.state;r._delta=[-Zt(e)[1]/kr*r.offset[0],0],$.addTo(r._movement,r._delta),cn(r),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const n=this.config.device;n&&(e(n,"start",this[n+"Start"].bind(this)),e(n,"change",this[n+"Move"].bind(this)),e(n,"end",this[n+"End"].bind(this)),e(n,"cancel",this[n+"End"].bind(this)),e("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const Pr=V(V({},mt),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!re.touch&&re.gesture)return"gesture";if(re.touch&&r)return"touch";if(re.touchscreen){if(re.pointer)return"pointer";if(re.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const s=i=>{const a=Qt(Ge(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=Qt(Ge(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(t,e,n){return this.lockDirection=n.axis==="lock",$.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey(t){return t===void 0?"ctrlKey":t},pinchOnWheel(t=!0){return t}});class Dr extends De{constructor(...e){super(...e),X(this,"ingKey","moving")}move(e){this.config.mouseOnly&&e.pointerType!=="mouse"||(this.state._active?this.moveChange(e):this.moveStart(e),this.timeoutStore.add("moveEnd",this.moveEnd.bind(this)))}moveStart(e){this.start(e),this.computeValues(ye(e)),this.compute(e),this.computeInitial(),this.emit()}moveChange(e){if(!this.state._active)return;const n=ye(e),r=this.state;r._delta=$.sub(n,r._values),$.addTo(r._movement,r._delta),this.computeValues(n),this.compute(e),this.emit()}moveEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}bind(e){e("pointer","change",this.move.bind(this)),e("pointer","leave",this.moveEnd.bind(this))}}const Or=V(V({},pe),{},{mouseOnly:(t=!0)=>t});class Nr extends De{constructor(...e){super(...e),X(this,"ingKey","scrolling")}scroll(e){this.state._active||this.start(e),this.scrollChange(e),this.timeoutStore.add("scrollEnd",this.scrollEnd.bind(this))}scrollChange(e){e.cancelable&&e.preventDefault();const n=this.state,r=ir(e);n._delta=$.sub(r,n._values),$.addTo(n._movement,n._delta),this.computeValues(r),this.compute(e),this.emit()}scrollEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("scroll","",this.scroll.bind(this))}}const Cr=pe;class Ar extends De{constructor(...e){super(...e),X(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const n=this.state;n._delta=Zt(e),$.addTo(n._movement,n._delta),cn(n),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const zr=pe;class Mr extends De{constructor(...e){super(...e),X(this,"ingKey","hovering")}enter(e){this.config.mouseOnly&&e.pointerType!=="mouse"||(this.start(e),this.computeValues(ye(e)),this.compute(e),this.emit())}leave(e){if(this.config.mouseOnly&&e.pointerType!=="mouse")return;const n=this.state;if(!n._active)return;n._active=!1;const r=ye(e);n._movement=n._delta=$.sub(r,n._values),this.computeValues(r),this.compute(e),n.delta=n.movement,this.emit()}bind(e){e("pointer","enter",this.enter.bind(this)),e("pointer","leave",this.leave.bind(this))}}const jr=V(V({},pe),{},{mouseOnly:(t=!0)=>t}),gt=new Map,yt=new Map;function Rr(t){gt.set(t.key,t.engine),yt.set(t.key,t.resolver)}const Lr={key:"drag",engine:hr,resolver:an},$r={key:"hover",engine:Mr,resolver:jr},Yr={key:"move",engine:Dr,resolver:Or},Hr={key:"pinch",engine:Ir,resolver:Pr},Vr={key:"scroll",engine:Nr,resolver:Cr},Fr={key:"wheel",engine:Ar,resolver:zr};function Ur(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function Br(t,e){if(t==null)return{};var n=Ur(t,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}const Wr={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=re.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},Xr=["target","eventOptions","window","enabled","transform"];function qe(t={},e){const n={};for(const[r,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const o=s.call(n,t[r],r,t);Number.isNaN(o)||(n[r]=o)}else n[r]=s.call(n,t[r],r,t);break;case"object":n[r]=qe(t[r],s);break;case"boolean":s&&(n[r]=t[r]);break}return n}function Kr(t,e,n={}){const r=t,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,d=Br(r,Xr);if(n.shared=qe({target:s,eventOptions:o,window:i,enabled:a,transform:l},Wr),e){const f=yt.get(e);n[e]=qe(V({shared:n.shared},d),f)}else for(const f in d){const _=yt.get(f);if(_)n[f]=qe(V({shared:n.shared},d[f]),_);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(f)){if(f==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${f}\` was used. Please read the documentation for further information.`)}}return n}class ln{constructor(e,n){X(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,s,o){const i=this._listeners,a=nr(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},d=V(V({},l),o);e.addEventListener(a,s,d);const f=()=>{e.removeEventListener(a,s,d),i.delete(f)};return i.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Gr{constructor(){X(this,"_timeouts",new Map)}add(e,n,r=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(n,r,...s))}remove(e){const n=this._timeouts.get(e);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class qr{constructor(e){X(this,"gestures",new Set),X(this,"_targetEventStore",new ln(this)),X(this,"gestureEventStores",{}),X(this,"gestureTimeoutStores",{}),X(this,"handlers",{}),X(this,"config",{}),X(this,"pointerIds",new Set),X(this,"touchIds",new Set),X(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Jr(this,e)}setEventIds(e){if(Ke(e))return this.touchIds=new Set(or(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,n){this.handlers=e,this.nativeHandlers=n}applyConfig(e,n){this.config=Kr(e,n,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const n=this.config.shared,r={};let s;if(!(n.target&&(s=n.target(),!s))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=un(r,a.eventOptions,!!s);if(a.enabled){const d=gt.get(i);new d(this,e,i).bind(l)}}const o=un(r,n.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](V(V({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=lr(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=tr(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function ve(t,e){t.gestures.add(e),t.gestureEventStores[e]=new ln(t,e),t.gestureTimeoutStores[e]=new Gr}function Jr(t,e){e.drag&&ve(t,"drag"),e.wheel&&ve(t,"wheel"),e.scroll&&ve(t,"scroll"),e.move&&ve(t,"move"),e.pinch&&ve(t,"pinch"),e.hover&&ve(t,"hover")}const un=(t,e,n)=>(r,s,o,i={},a=!1)=>{var l,d;const f=(l=i.capture)!==null&&l!==void 0?l:e.capture,_=(d=i.passive)!==null&&d!==void 0?d:e.passive;let m=a?r:Qn(r,s,f);n&&_&&(m+="Passive"),t[m]=t[m]||[],t[m].push(o)},Zr=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Qr(t){const e={},n={},r=new Set;for(let s in t)Zr.test(s)?(r.add(RegExp.lastMatch),n[s]=t[s]):e[s]=t[s];return[n,e,r]}function _e(t,e,n,r,s,o){if(!t.has(n))return;if(!gt.has(r)){process.env.NODE_ENV==="development"&&console.warn(`[@use-gesture]: You've created a custom handler that that uses the \`${r}\` gesture but isn't properly configured.
|
|
8
|
-
|
|
9
|
-
Please add \`${r}Action\` when creating your handler.`);return}const i=n+"Start",a=n+"End",l=d=>{let f;return d.first&&i in e&&e[i](d),n in e&&(f=e[n](d)),d.last&&a in e&&e[a](d),f};s[r]=l,o[r]=o[r]||{}}function es(t,e){const[n,r,s]=Qr(t),o={};return _e(s,n,"onDrag","drag",o,e),_e(s,n,"onWheel","wheel",o,e),_e(s,n,"onScroll","scroll",o,e),_e(s,n,"onPinch","pinch",o,e),_e(s,n,"onMove","move",o,e),_e(s,n,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function ts(t,e={},n,r){const s=I.useMemo(()=>new qr(t),[]);if(s.applyHandlers(t,r),s.applyConfig(e,n),I.useEffect(s.effect.bind(s)),I.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function ns(t){return t.forEach(Rr),function(n,r){const{handlers:s,nativeHandlers:o,config:i}=es(n,r||{});return ts(s,i,void 0,o)}}function Ne(t,e){return ns([Lr,Hr,Vr,Fr,Yr,$r])(t,e||{})}const rs=({pos:t,onDragStart:e,onDragMove:n,onDragEnd:r,className:s="",style:o})=>{const i=Ne({onDrag:({first:a,movement:[l,d],memo:f,event:_})=>(_.stopPropagation(),a?e():(f&&n(t,l,d,f),f)),onDragEnd:({movement:[a,l],memo:d,event:f})=>{f.stopPropagation(),d&&r(t,a,l,d)}},{drag:{filterTaps:!0,threshold:0}});return y.jsx("div",{className:`ce-resize-handle ce-resize-handle--${t} ${s}`,style:{touchAction:"none",...o},...i()})},ss=({onDragStart:t,onDragMove:e,onDragEnd:n,className:r="",style:s})=>{const o=Ne({onDrag:({first:i,movement:[a,l],memo:d,event:f})=>(f.stopPropagation(),i?t(a,l):(d&&e(a,l,d),d)),onDragEnd:({movement:[i,a],memo:l,event:d})=>{d.stopPropagation(),l&&n(i,a,l)}},{drag:{filterTaps:!0,threshold:0}});return y.jsx("div",{className:`ce-rotate-handle ${r}`,style:{touchAction:"none",...s},...o(),children:y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})})},dn=({lines:t,className:e="",style:n})=>t.length?y.jsx(y.Fragment,{children:t.map((r,s)=>y.jsx("div",{className:`ce-snap-guide ce-snap-guide--${r.type} ${e}`,style:{left:r.type==="vertical"?r.pos:0,top:r.type==="horizontal"?r.pos:0,...n}},s))}):null,fn=5,hn=(t,e,n,r,s,o)=>{let i=e,a=n;const l=[],d=[e,e+r/2,e+r],f=[n,n+s/2,n+s];return Object.values(o).forEach(_=>{if(_.id===t)return;const m=[_.x,_.x+_.width/2,_.x+_.width];d.forEach((N,C)=>{m.forEach(c=>{Math.abs(N-c)<fn&&(C===0&&(i=c),C===1&&(i=c-r/2),C===2&&(i=c-r),l.push({type:"vertical",pos:c}))})});const w=[_.y,_.y+_.height/2,_.y+_.height];f.forEach((N,C)=>{w.forEach(c=>{Math.abs(N-c)<fn&&(C===0&&(a=c),C===1&&(a=c-s/2),C===2&&(a=c-s),l.push({type:"horizontal",pos:c}))})})}),{x:i,y:a,lines:l}},pn=(t,e,n,r,s,o,i)=>{let l=r,d=s,f=e,_=n;const m=[],w=e,N=e+r,C=e+r/2,c=n,g=n+s,p=n+s/2,b=o.includes("w"),v=o.includes("e"),D=o.includes("n"),h=o.includes("s"),O=o==="n"||o==="s",T=o==="e"||o==="w";Object.values(i).forEach(S=>{if(S.id===t)return;const j=S.x,R=S.x+S.width,x=S.x+S.width/2,B=S.y,Z=S.y+S.height,q=S.y+S.height/2;if(v&&[j,R,x].forEach(Y=>{Math.abs(N-Y)<5&&(l=Y-e,m.push({type:"vertical",pos:Y}))}),b){const Y=e+r;[j,R,x].forEach(U=>{Math.abs(w-U)<5&&(f=U,l=Y-U,m.push({type:"vertical",pos:U}))})}if(O&&Math.abs(C-x)<5&&(f=x-r/2,m.push({type:"vertical",pos:x})),h&&[B,Z,q].forEach(Y=>{Math.abs(g-Y)<5&&(d=Y-n,m.push({type:"horizontal",pos:Y}))}),D){const Y=n+s;[B,Z,q].forEach(U=>{Math.abs(c-U)<5&&(_=U,d=Y-U,m.push({type:"horizontal",pos:U}))})}T&&Math.abs(p-q)<5&&(_=q-s/2,m.push({type:"horizontal",pos:q}))});const k=10;return l<k&&(b&&(f=e+r-k),l=k),d<k&&(D&&(_=n+s-k),d=k),{x:f,y:_,width:l,height:d,lines:m}},mn=(t,e,n,r,s,o,i,a)=>{let l=.5,d=.5;o.includes("n")&&(d=1),o.includes("s")&&(d=0),o.includes("e")&&(l=0),o.includes("w")&&(l=1);const f=s*Math.PI/180,_=Math.cos(f),m=Math.sin(f),w=t+n/2,N=e+r/2,C=n*l-n/2,c=r*d-r/2,g=w+(C*_-c*m),p=N+(C*m+c*_),b=Math.cos(-f),v=Math.sin(-f),D=i*b-a*v,h=i*v+a*b;let O=0,T=0;o.includes("e")&&(O=D),o.includes("w")&&(O=-D),o.includes("s")&&(T=h),o.includes("n")&&(T=-h);const k=Math.max(10,n+O),S=Math.max(10,r+T),j=k*l-k/2,R=S*d-S/2,x=j*_-R*m,B=j*m+R*_,Z=g-x,q=p-B,Y=Z-k/2,U=q-S/2;return{x:Y,y:U,width:k,height:S}},os=({id:t,children:e,className:n="",style:r,draggable:s,resizable:o,rotatable:i,selectable:a,rotationSnap:l,showDragHandle:d,doubleClickToEdit:f,..._})=>{const m=z(E=>E.nodes[t]),w=z(E=>E.config),N=z(E=>E.config.viewOnly||a===!1?!1:E.selectedIds?.includes(t)),C=z(E=>E.camera.zoom),c=We(),g=z(E=>E.selectNode),p=z(E=>E.updateNode),b=I.useRef(null),[v,D]=I.useState([]),[h,O]=I.useState(!1),T=I.useRef(!1);I.useEffect(()=>{N||(D([]),O(!1))},[N]);const k=I.useRef(m);I.useEffect(()=>{k.current=m},[m]);const S=!w.viewOnly,j=(E,M)=>E!==void 0?E:M!==void 0?M:!0,R=S&&j(s,m?.draggable),x=S&&j(o,m?.resizable),B=S&&j(i,m?.rotatable),Z=S&&a!==!1,q=S&&R&&d!==!1,Y=f!==void 0?f:m?.doubleClickToEdit??m?.data?.doubleClickToEdit??!1,U=()=>typeof l=="number"?l:l===!1?0:l===!0?w.rotationSnap||15:w.rotationSnap||0,de=Ne({onDragStart:({event:E})=>{if(!S)return;const M=E.target;M.closest(".ce-resize-handle")||M.closest(".ce-rotate-handle")||h&&!M.closest(".ce-drag-handle-minimal")||Z&&!N&&g(t)},onDrag:({movement:[E,M],first:K,memo:L,event:ne})=>{if(!S||!R)return;const F=ne.target;if(F.closest(".ce-resize-handle")||F.closest(".ce-rotate-handle")||h&&!F.closest(".ce-drag-handle-minimal")||T.current||(ne&&ne.stopPropagation(),!m))return;if(K)return{x:m.x,y:m.y};const P=c.getState().nodes,Q=L?.x??m.x,ie=L?.y??m.y;let fe=Q+E/C,oe=ie+M/C;if(w.snapping){const le=hn(t,fe,oe,m.width,m.height,P);fe=le.x,oe=le.y,w.snapGuide&&D(le.lines)}if(w.isLimited){const le=(w.width||1920)-m.width,ds=(w.height||1080)-m.height;fe=Math.max(0,Math.min(fe,le)),oe=Math.max(0,Math.min(oe,ds))}return b.current&&(b.current.style.transform=`translate(${fe}px, ${oe}px) rotate(${m.rotation}deg)`),{x:Q,y:ie,finalX:fe,finalY:oe}},onDragEnd:({memo:E,event:M})=>{M&&M.stopPropagation(),D([]),E&&typeof E.finalX=="number"&&p(t,{x:E.finalX,y:E.finalY})}},{drag:{filterTaps:!0,threshold:3,enabled:S}}),se=I.useCallback(()=>{T.current=!0;const E=k.current;return E?{x:E.x,y:E.y,w:E.width,h:E.height,r:E.rotation||0}:{x:0,y:0,w:0,h:0,r:0}},[]),u=I.useCallback((E,M,K,L)=>{if(!b.current)return;const ne=c.getState().nodes,F=mn(L.x,L.y,L.w,L.h,L.r,E,M/C,K/C);let P={x:F.x,y:F.y,width:F.width,height:F.height,lines:[]};if(w.snapping?P=pn(t,F.x,F.y,F.width,F.height,E,ne):P={...F,lines:[]},w.isLimited){const Q=w.width||1920,ie=w.height||1080;P.x<0&&(P.width+=P.x,P.x=0),P.y<0&&(P.height+=P.y,P.y=0),P.x+P.width>Q&&(P.width=Q-P.x),P.y+P.height>ie&&(P.height=ie-P.y)}w.snapGuide&&D(P.lines),b.current.style.width=`${P.width}px`,b.current.style.height=`${P.height}px`,b.current.style.transform=`translate(${P.x}px, ${P.y}px) rotate(${L.r}deg)`},[t,C,w,c]),A=I.useCallback((E,M,K,L)=>{const ne=c.getState().nodes,F=mn(L.x,L.y,L.w,L.h,L.r,E,M/C,K/C);let P={...F};if(w.snapping&&(P=pn(t,F.x,F.y,F.width,F.height,E,ne)),w.isLimited){const Q=w.width||1920,ie=w.height||1080;P.x<0&&(P.width+=P.x,P.x=0),P.y<0&&(P.height+=P.y,P.y=0),P.x+P.width>Q&&(P.width=Q-P.x),P.y+P.height>ie&&(P.height=ie-P.y)}p(t,{x:P.x,y:P.y,width:P.width,height:P.height}),D([]),setTimeout(()=>{T.current=!1},100)},[t,C,p,w,c]),H=I.useCallback((E,M)=>{T.current=!0;const K=k.current;if(!K||!b.current)return{startRotation:0,startAngle:0};const L=b.current.getBoundingClientRect(),ne=L.left+L.width/2,F=L.top+L.height/2;let Q=Math.atan2(M-F,E-ne)*(180/Math.PI);return Q+=90,{startRotation:K.rotation,startAngle:Q}},[]),W=I.useCallback((E,M,K)=>{if(!b.current||!k.current)return;const L=b.current.getBoundingClientRect(),ne=L.left+L.width/2,F=L.top+L.height/2;let Q=Math.atan2(M-F,E-ne)*(180/Math.PI);Q+=90;const ie=Q-K.startAngle,fe=w.rotationSpeed||1;let oe=K.startRotation+ie*fe;const le=U();le>0&&(oe=Math.round(oe/le)*le),b.current.style.transform=`translate(${k.current.x}px, ${k.current.y}px) rotate(${oe}deg)`,b.current.__tempRotation=oe},[w.rotationSpeed,U]),be=I.useCallback(()=>{const E=b.current.__tempRotation;typeof E=="number"&&(p(t,{rotation:E}),delete b.current.__tempRotation),setTimeout(()=>{T.current=!1},100)},[t,p]);return m?y.jsxs(y.Fragment,{children:[y.jsx(dn,{lines:v}),y.jsxs("div",{ref:b,"data-node-id":t,className:`ce-element ${N?"ce-element--selected":""} ${n}`,style:{transform:`translate(${m.x}px, ${m.y}px) rotate(${m.rotation}deg)`,width:m.width,height:m.height,zIndex:N?100:1,"--ce-inverse-zoom":1/C,...r},...de(),..._,onClick:E=>{E.stopPropagation(),S&&Z&&g(t)},onDoubleClick:E=>{S&&Y&&(E.stopPropagation(),O(!0))},children:[y.jsx("div",{style:{width:"100%",height:"100%",pointerEvents:Y&&!h?"none":"auto"},children:e}),N&&S&&y.jsxs(y.Fragment,{children:[q&&y.jsx("div",{className:"ce-drag-handle-minimal",children:y.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("polyline",{points:"5 9 2 12 5 15"}),y.jsx("polyline",{points:"9 5 12 2 15 5"}),y.jsx("polyline",{points:"19 9 22 12 19 15"}),y.jsx("polyline",{points:"9 19 12 22 15 19"}),y.jsx("path",{d:"M2 12h20"}),y.jsx("path",{d:"M12 2v20"})]})}),x&&["nw","ne","sw","se","n","s","e","w"].map(E=>y.jsx(rs,{pos:E,onDragStart:se,onDragMove:u,onDragEnd:A},E)),w.rotation&&B&&y.jsx(ss,{onDragStart:H,onDragMove:W,onDragEnd:be})]})]})]}):null},gn=I.memo(os),is=({id:t,children:e,className:n="",style:r,draggable:s=!0,selectable:o=!0})=>{const i=z(v=>v.nodes[t]),a=z(v=>v.config),l=We(),d=z(v=>v.removeNode),f=z(v=>v.config.viewOnly||!o?!1:v.selectedIds?.includes(t)),_=z(v=>v.camera.zoom),m=z(v=>v.selectNode),w=z(v=>v.updateNode),N=I.useRef(null),[C,c]=I.useState([]);if(I.useEffect(()=>{f||c([])},[f]),I.useEffect(()=>{if(!N.current)return;const v=new ResizeObserver(D=>{for(const h of D){const{width:O,height:T}=h.contentRect;i&&(Math.abs(i.width-O)>1||Math.abs(i.height-T)>1)&&w(t,{width:O,height:T})}});return v.observe(N.current),()=>v.disconnect()},[t,i?.width,i?.height,w]),!i)return null;const g=!a.viewOnly,p=g&&s&&i.draggable!==!1,b=Ne({onDragStart:({event:v})=>{if(!g)return;const D=v.target;D.tagName==="INPUT"||D.tagName==="TEXTAREA"||o&&!f&&m(t)},onDrag:({movement:[v,D],first:h,memo:O,event:T})=>{if(!p)return;if(T&&T.stopPropagation(),h)return{x:i.x,y:i.y};const k=l.getState().nodes,S=O?.x??i.x,j=O?.y??i.y;let R=S+v/_,x=j+D/_;if(a.snapping){const B=hn(t,R,x,i.width,i.height,k);R=B.x,x=B.y,a.snapGuide&&c(B.lines)}return w(t,{x:R,y:x}),N.current&&(N.current.style.transform=`translate(${R}px, ${x}px)`),{x:S,y:j,finalX:R,finalY:x}},onDragEnd:({event:v})=>{v&&v.stopPropagation(),c([])}},{drag:{filterTaps:!0,threshold:3,enabled:p}});return y.jsxs(y.Fragment,{children:[a.snapGuide&&y.jsx(dn,{lines:C}),y.jsxs("div",{ref:N,"data-node-id":t,className:`ce-element ce-workflow-node ${f?"ce-element--selected":""} ${n}`,style:{position:"absolute",left:0,top:0,width:"max-content",transform:`translate(${i.x}px, ${i.y}px)`,zIndex:f?10:1,cursor:p?"grab":"default",touchAction:"none",...r},...b(),onClick:v=>{v.stopPropagation(),g&&o&&m(t)},children:[i.customCss&&y.jsx("style",{children:`
|
|
10
|
-
[data-node-id="${t}"] {
|
|
11
|
-
${i.customCss}
|
|
12
|
-
}
|
|
13
|
-
`}),y.jsx(Bn,{id:t,children:e}),g&&!a.viewOnly&&y.jsx("button",{className:"ce-delete-node-btn",onPointerDown:v=>v.stopPropagation(),onClick:v=>{v.stopPropagation(),d(t)},title:"Remove Node",children:"×"})]})]})},yn=I.memo(is),as=()=>{const t=z(c=>c.edges),e=z(c=>c.nodes),n=z(c=>c.connectionState),r=z(c=>c.selectNode),s=z(c=>c.selectedIds),o=z(c=>c.removeEdge),i=(c,g,p,b,v)=>{const D=1-c;return Math.pow(D,3)*g+3*Math.pow(D,2)*c*p+3*D*Math.pow(c,2)*b+Math.pow(c,3)*v},a=(c,g,p,b)=>{const v=Math.abs(p-c)/2,D=c+v,h=g,O=p-v;return`M ${c} ${g} C ${D} ${h}, ${O} ${b}, ${p} ${b}`},l=(c,g,p,b)=>`M ${c} ${g} L ${p} ${b}`,d=(c,g,p,b)=>{const v=(c+p)/2;return`M ${c} ${g} L ${v} ${g} L ${v} ${b} L ${p} ${b}`},f=(c,g,p,b,v)=>{switch(c){case"straight":return l(g,p,b,v);case"step":return d(g,p,b,v);default:return a(g,p,b,v)}},_=z(c=>c.camera),m=z(c=>c.dimensions),N=I.useMemo(()=>m.width===0||m.height===0?Object.values(t):Object.values(t).filter(c=>{const g=e[c.source],p=e[c.target];if(!g||!p)return!1;const b=Math.min(g.x,p.x),v=Math.max(g.x+g.width,p.x+p.width),D=Math.min(g.y,p.y),h=Math.max(g.y+g.height,p.y+p.height),O=_.zoom,T=b*O+_.x,k=v*O+_.x,S=D*O+_.y,j=h*O+_.y,R=100;return!(k<-R||T>m.width+R||j<-R||S>m.height+R)}),[t,e,_,m]).map(c=>{const g=e[c.source],p=e[c.target];if(!g||!p)return null;let b=g.x+g.width/2,v=g.y+g.height/2,D=p.x+p.width/2,h=p.y+p.height/2;if(g.handles&&c.sourceHandle&&g.handles[c.sourceHandle]){const x=g.handles[c.sourceHandle];typeof x.x=="number"&&typeof x.y=="number"&&x.x!==0?(b=g.x+x.x,v=g.y+x.y):x.position==="top"?(b=g.x+g.width/2,v=g.y):x.position==="bottom"?(b=g.x+g.width/2,v=g.y+g.height):x.position==="left"?(b=g.x,v=g.y+g.height/2):x.position==="right"&&(b=g.x+g.width,v=g.y+g.height/2)}if(p.handles&&c.targetHandle&&p.handles[c.targetHandle]){const x=p.handles[c.targetHandle];typeof x.x=="number"&&typeof x.y=="number"&&x.x!==0?(D=p.x+x.x,h=p.y+x.y):x.position==="top"?(D=p.x+p.width/2,h=p.y):x.position==="bottom"?(D=p.x+p.width/2,h=p.y+p.height):x.position==="left"?(D=p.x,h=p.y+p.height/2):x.position==="right"&&(D=p.x+p.width,h=p.y+p.height/2)}const O=f(c.type,b,v,D,h),T=s.includes(c.id),k=(b+D)/2,S=(v+h)/2;let j=k,R=S;if(!c.type||c.type==="default"){const x=Math.abs(D-b)/2;j=i(.5,b,b+x,D-x,D),R=i(.5,v,v,h,h)}return y.jsxs("g",{className:"ce-edge-group",style:{pointerEvents:"all"},children:[y.jsx("path",{d:O,stroke:"transparent",strokeWidth:"20",fill:"none",style:{cursor:"pointer"},onClick:x=>{x.stopPropagation(),r(c.id)}}),y.jsx("path",{d:O,stroke:T?"#3b82f6":"#b1b1b7",strokeWidth:T?"3":"2",fill:"none",markerEnd:"url(#arrow-closed)",style:{pointerEvents:"none"}}),y.jsx("foreignObject",{x:j-10,y:R-10,width:20,height:20,className:"ce-edge-delete-fo",style:{overflow:"visible"},children:y.jsx("button",{className:"ce-edge-delete-btn",onClick:x=>{x.stopPropagation(),o(c.id)},title:"Disconnect",style:{width:"20px",height:"20px",borderRadius:"50%",background:"#ff4d4f",color:"white",border:"1px solid white",padding:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"14px",lineHeight:1,cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.2)"},children:"×"})})]},c.id)});let C=null;if(n.isValid&&n.nodeId&&n.position&&e[n.nodeId]){const c=e[n.nodeId];let g=c.x+c.width/2,p=c.y+c.height/2;if(n.handleId&&c.handles&&c.handles[n.handleId]){const h=c.handles[n.handleId];typeof h.x=="number"&&typeof h.y=="number"&&h.x!==0?(g=c.x+h.x,p=c.y+h.y):h.position==="top"?(g=c.x+c.width/2,p=c.y):h.position==="bottom"?(g=c.x+c.width/2,p=c.y+c.height):h.position==="left"?(g=c.x,p=c.y+c.height/2):h.position==="right"&&(g=c.x+c.width,p=c.y+c.height/2)}const b=n.position.x,v=n.position.y,D=a(g,p,b,v);C=y.jsx("path",{d:D,stroke:"#3b82f6",strokeWidth:"2",strokeDasharray:"5,5",fill:"none",markerEnd:"url(#arrow-closed)",className:"ce-connection-line"})}return y.jsxs("svg",{className:"ce-edge-layer",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none",zIndex:0},children:[y.jsx("defs",{children:y.jsx("marker",{id:"arrow-closed",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:y.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"#b1b1b7"})})}),N,N,C]})},cs=({children:t,grid:e,background:n,className:r="",style:s,canvasStyle:o})=>{const i=I.useRef(null),a=z(h=>h.camera),l=z(h=>h.config),d=z(h=>h.panCamera),f=z(h=>h.zoomCamera),_=z(h=>h.deselectAll),m=z(h=>h.deleteSelected),w=z(h=>h.setDimensions);I.useEffect(()=>{const h=k=>{k.ctrlKey&&k.preventDefault()},O=i.current;O&&O.addEventListener("wheel",h,{passive:!1});let T=null;return O&&(T=new ResizeObserver(k=>{for(const S of k){const{width:j,height:R}=S.contentRect;w(j,R)}}),T.observe(O)),()=>{O&&O.removeEventListener("wheel",h),T&&T.disconnect()}},[w]);const[N,C]=I.useState(!1);I.useEffect(()=>{const h=T=>{if(T.code==="Space"&&!T.repeat&&C(!0),(T.code==="Delete"||T.code==="Backspace")&&!l.viewOnly){const k=T.target;k.tagName!=="INPUT"&&k.tagName!=="TEXTAREA"&&m()}},O=T=>{T.code==="Space"&&C(!1)};return window.addEventListener("keydown",h),window.addEventListener("keyup",O),()=>{window.removeEventListener("keydown",h),window.removeEventListener("keyup",O)}},[m,l.viewOnly]),Ne({onDrag:({delta:[h,O],event:T})=>{const k=T.target,S=k.closest(".ce-element")||k.closest(".ce-resize-handle");(N||l.pan&&!S)&&d(h,O)},onWheel:({event:h,delta:[,O],ctrlKey:T})=>{if(T||h.metaKey){if(l.zoom){const k=i.current?.getBoundingClientRect();if(k){let S,j;!l.pan&&!N?(S=(k.width||window.innerWidth)/2,j=(k.height||window.innerHeight)/2):(S=h.clientX-k.left,j=h.clientY-k.top),f(1-O/500,S,j)}}}else d(-h.deltaX,-h.deltaY)}},{target:i,drag:{filterTaps:!0}});const c=z(h=>h.connectionState),g=z(h=>h.updateConnection),p=z(h=>h.endConnection),b=z(h=>h.addEdge);I.useEffect(()=>{if(!c.isValid)return;const h=T=>{if(!i.current)return;const k=i.current.getBoundingClientRect();let S=(T.clientX-k.left-a.x)/a.zoom,j=(T.clientY-k.top-a.y)/a.zoom;const x=document.elementFromPoint(T.clientX,T.clientY)?.closest(".ce-handle");if(document.querySelectorAll(".ce-handle--valid").forEach(B=>B.classList.remove("ce-handle--valid")),x&&c.nodeId){const B=x.closest("[data-node-id]")?.getAttribute("data-node-id"),Z=x.dataset.handleId,q=x.dataset.handleType,Y=c.handleType,U=B===c.nodeId;if(B&&Z&&!U&&(Y==="source"&&q==="target"||Y==="target"&&q==="source")){x.classList.add("ce-handle--valid");const se=x.getBoundingClientRect();S=(se.left+se.width/2-k.left-a.x)/a.zoom,j=(se.top+se.height/2-k.top-a.y)/a.zoom}}g({x:S,y:j})},O=T=>{const S=document.elementFromPoint(T.clientX,T.clientY)?.closest(".ce-handle");if(S&&c.nodeId){const j=S.closest("[data-node-id]")?.getAttribute("data-node-id"),R=S.dataset.handleId,x=S.dataset.handleType,B=c.handleType,Z=j===c.nodeId;if(j&&R&&!Z&&(B==="source"&&x==="target"||B==="target"&&x==="source")){let Y=c.nodeId,U=c.handleId||void 0,de=j,se=R;B==="target"&&x==="source"&&(Y=j,U=R,de=c.nodeId,se=c.handleId||void 0),b({id:`e-${Date.now()}`,source:Y,sourceHandle:U||void 0,target:de,targetHandle:se})}}document.querySelectorAll(".ce-handle--valid").forEach(j=>j.classList.remove("ce-handle--valid")),p()};return window.addEventListener("pointermove",h),window.addEventListener("pointerup",O),()=>{window.removeEventListener("pointermove",h),window.removeEventListener("pointerup",O),document.querySelectorAll(".ce-handle--valid").forEach(T=>T.classList.remove("ce-handle--valid"))}},[c.isValid,a,g,p,b,c.nodeId,c.handleType,c.handleId]);const v=()=>{l.viewOnly||_()},D=l.isLimited?{touchAction:"none",cursor:N?"grab":"default"}:{...s,touchAction:"none",cursor:N?"grab":"default"};return y.jsxs("div",{ref:i,className:`ce-editor__viewport ${N?"ce-editor__viewport--panning":""} ${r} ${l.viewOnly?"ce-editor--view-only":""} ${c.isValid?"ce-editor--connecting":""}`,style:D,onClick:v,children:[n,y.jsxs("div",{className:"ce-editor__canvas",style:{transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`,...o},children:[l.showGrid&&y.jsx("div",{className:"ce-editor__grid-layer",children:e||y.jsxs("svg",{width:"100%",height:"100%",children:[y.jsx("defs",{children:y.jsx("pattern",{id:"default-grid",width:l.gridSize,height:l.gridSize,patternUnits:"userSpaceOnUse",children:y.jsx("circle",{cx:"1",cy:"1",r:"1",fill:l.gridColor||"#ccc"})})}),y.jsx("rect",{width:"100%",height:"100%",fill:"url(#default-grid)"})]})}),y.jsx(as,{}),l.isLimited?y.jsx("div",{className:"ce-editor__content-area",style:{width:l.width||1920,height:l.height||1080,...s},children:t}):y.jsx("div",{className:"ce-editor__infinite-area",children:t})]})]})},ls={default:Xe,input:Yt,output:Ht,workflow:Xe},us=({nodeTypes:t={}})=>{const e=z(i=>i.nodes),n=z(i=>i.camera),r=z(i=>i.dimensions),s=I.useMemo(()=>({...ls,...t}),[t]),o=I.useMemo(()=>{if(r.width<=0||r.height<=0)return Object.values(e);const i=100;return Object.values(e).filter(a=>{const l=n.zoom,d=a.x*l+n.x,f=a.y*l+n.y,_=a.width*l,m=a.height*l;return!(d+_<-i||d>r.width+i||f+m<-i||f>r.height+i)})},[e,n,r]);return y.jsx(y.Fragment,{children:o.map(i=>{const a=s[i.type||"default"]||Xe;return i.type==="custom"||i.type==="design"||i.resizable||i.rotatable?y.jsx(gn,{id:i.id,draggable:i.draggable,resizable:i.resizable,rotatable:i.rotatable,children:y.jsx(a,{style:i.style,className:i.className,data:i.data,id:i.id})},i.id):y.jsx(yn,{id:i.id,draggable:i.draggable,className:i.className,style:i.style,children:y.jsx(a,{data:i.data,id:i.id})},i.id)})})};G.Canvas=cs,G.DefaultNode=Xe,G.Editor=Un,G.ElementWrapper=gn,G.Handle=Pe,G.InputNode=Yt,G.NodeLayer=us,G.OutputNode=Ht,G.WorkflowNodeWrapper=yn,G.useEditor=z,G.useEditorStoreApi=We,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(O,z){typeof exports=="object"&&typeof module<"u"?z(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],z):(O=typeof globalThis<"u"?globalThis:O||self,z(O.FlowCanvas={},O.React,O.ReactDOM))})(this,(function(O,z,$n){"use strict";var Dt=document.createElement("style");Dt.textContent=`.ce-editor{position:relative;width:100%;height:100%;overflow:hidden;background-color:#f3f4f6}.ce-editor__viewport{position:relative;width:100%;height:100%;overflow:auto;cursor:default}.ce-editor__viewport--panning{cursor:grab!important}.ce-editor__viewport--panning *{pointer-events:none!important}.ce-editor__scale-wrapper{width:100%;height:100%;display:flex;justify-content:center;align-items:flex-start;padding-top:40px}.ce-editor__canvas{transform-origin:top center;display:flex;flex-direction:column;align-items:center;padding:40px}.ce-editor__grid-layer{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:0}.ce-editor__content-area{position:absolute;left:0;top:0;background-color:#fff;overflow:hidden;z-index:1;box-shadow:0 0 20px #0000001a}.ce-editor__infinite-area{position:relative;z-index:1}.ce-page{position:relative;flex-shrink:0;background-color:#fff;box-shadow:0 2px 8px #00000014,0 0 0 1px #0000000a;border-radius:4px;overflow:hidden;transition:box-shadow .2s ease,transform .2s ease}.ce-page--drag-target{box-shadow:0 4px 16px #06f3,0 0 0 2px #0066ff4d;transform:scale(1.002)}.ce-page--active{box-shadow:0 4px 12px #0000001f,0 0 0 1px #0000000f}.ce-page__ghost-preview{position:absolute;inset:0;pointer-events:none;z-index:999;background-color:#0066ff08;border:2px dashed rgba(0,102,255,.4);border-radius:4px}.ce-element{position:absolute;touch-action:none;-webkit-user-select:none;user-select:none;box-sizing:border-box;transition:box-shadow .15s ease,outline .15s ease}.ce-element--selected{outline:2px solid #0066FF;outline-width:calc(2px * var(--ce-inverse-zoom, 1));outline-offset:calc(-1px * var(--ce-inverse-zoom, 1));box-shadow:0 0 0 calc(1px * var(--ce-inverse-zoom, 1)) #ffffffe6,0 2px 8px #0066ff26;z-index:100!important}.ce-element img{pointer-events:none;-webkit-user-drag:none;-webkit-user-select:none;user-select:none}.ce-editor--editing-group .ce-element{opacity:.15;pointer-events:none!important;transition:opacity .2s ease,filter .2s ease}.ce-editor--editing-group .ce-element--editing-active{opacity:1;filter:none;pointer-events:auto;z-index:50!important;outline:2px dashed #0066FF;outline-offset:4px}.ce-editor--editing-group .ce-element--editing-active .ce-element{opacity:1;filter:none;pointer-events:auto!important}.ce-editor--connecting{cursor:crosshair!important}.ce-editor--connecting .ce-element:hover{outline:2px dashed #3b82f6;outline-width:calc(2px * var(--ce-inverse-zoom, 1));background-color:#3b82f60d;cursor:copy}.ce-editor--connecting .ce-handle:hover{transform:scale(1.5);background-color:#3b82f6!important;border-color:#fff!important;transition:transform .1s}.ce-resize-handle{width:calc(8px * var(--ce-inverse-zoom, 1));height:calc(8px * var(--ce-inverse-zoom, 1));background:#fff;border:calc(1.5px * var(--ce-inverse-zoom, 1)) solid #0066FF;border-radius:2px;position:absolute;z-index:101;box-shadow:0 1px 3px #00000026;transition:transform .1s ease,box-shadow .1s ease}.ce-resize-handle:hover{transform:scale(1.2);box-shadow:0 2px 6px #0003}.ce-resize-handle--nw{top:calc(-4px * var(--ce-inverse-zoom, 1));left:calc(-4px * var(--ce-inverse-zoom, 1));cursor:nw-resize}.ce-resize-handle--ne{top:calc(-4px * var(--ce-inverse-zoom, 1));right:calc(-4px * var(--ce-inverse-zoom, 1));cursor:ne-resize}.ce-resize-handle--sw{bottom:calc(-4px * var(--ce-inverse-zoom, 1));left:calc(-4px * var(--ce-inverse-zoom, 1));cursor:sw-resize}.ce-resize-handle--se{bottom:calc(-4px * var(--ce-inverse-zoom, 1));right:calc(-4px * var(--ce-inverse-zoom, 1));cursor:se-resize}.ce-resize-handle--n{top:calc(-4px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);cursor:n-resize}.ce-resize-handle--s{bottom:calc(-4px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);cursor:s-resize}.ce-resize-handle--e{right:calc(-4px * var(--ce-inverse-zoom, 1));top:50%;transform:translateY(-50%);cursor:e-resize}.ce-resize-handle--w{left:calc(-4px * var(--ce-inverse-zoom, 1));top:50%;transform:translateY(-50%);cursor:w-resize}.ce-rotate-handle{width:calc(20px * var(--ce-inverse-zoom, 1));height:calc(20px * var(--ce-inverse-zoom, 1));background:#fff;border:none;box-shadow:0 2px 6px #00000026;border-radius:50%;position:absolute;bottom:auto;top:calc(-32px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);margin-left:0;cursor:grab;z-index:101;display:flex;align-items:center;justify-content:center;color:#06f;pointer-events:auto;transition:transform .1s ease,box-shadow .1s ease}.ce-rotate-handle svg{width:calc(12px * var(--ce-inverse-zoom, 1));height:calc(12px * var(--ce-inverse-zoom, 1))}.ce-rotate-handle:hover{transform:translate(-50%) scale(1.1);box-shadow:0 3px 8px #0003}.ce-rotate-handle:active{cursor:grabbing;background:#f3f4f6}.ce-drag-handle-minimal{width:calc(20px * var(--ce-inverse-zoom, 1));height:calc(20px * var(--ce-inverse-zoom, 1));position:absolute;top:auto;bottom:calc(-32px * var(--ce-inverse-zoom, 1));left:50%;transform:translate(-50%);margin-left:0;background-color:#fff;border-radius:50%;box-shadow:0 2px 6px #00000026;cursor:grab;z-index:102;display:flex;align-items:center;justify-content:center;color:#06f;transition:transform .1s ease,box-shadow .1s ease}.ce-drag-handle-minimal svg{width:calc(14px * var(--ce-inverse-zoom, 1));height:calc(14px * var(--ce-inverse-zoom, 1))}.ce-drag-handle-minimal:hover{transform:translate(-50%) scale(1.1);box-shadow:0 3px 8px #0003}.ce-drag-handle-minimal:active{cursor:grabbing;background-color:#f3f4f6}.ce-selection-overlay{position:absolute;top:0;left:0;width:0;height:0;pointer-events:none;z-index:1000}.ce-selection-overlay__box{position:absolute;border:2px solid #0066FF;background-color:#0066ff0a;pointer-events:none;box-shadow:0 0 0 1px #ffffffe6,0 2px 8px #0066ff26;transition:opacity .1s ease}.ce-resize-handle{position:absolute;width:10px;height:10px;background-color:#fff;border:calc(1.5px * var(--ce-inverse-zoom, 1)) solid #3b82f6;border-radius:calc(2px * var(--ce-inverse-zoom, 1));z-index:101;pointer-events:auto;box-shadow:0 1px 4px #0000001f,0 0 0 calc(.5px * var(--ce-inverse-zoom, 1)) #ffffffe6;transition:all .15s cubic-bezier(.4,0,.2,1)}.ce-resize-handle:hover{background-color:#3b82f6;box-shadow:0 2px 8px #3b82f659,0 0 0 calc(1px * var(--ce-inverse-zoom, 1)) #fff;transform:scale(1.2)}.ce-resize-handle--nw{top:-5px;left:-5px;cursor:nw-resize}.ce-resize-handle--ne{top:-5px;right:-5px;cursor:ne-resize}.ce-resize-handle--sw{bottom:-5px;left:-5px;cursor:sw-resize}.ce-resize-handle--se{bottom:-5px;right:-5px;cursor:se-resize}.ce-resize-handle--n{top:-5px;left:50%;transform:translate(-50%);cursor:n-resize}.ce-resize-handle--s{bottom:-5px;left:50%;transform:translate(-50%);cursor:s-resize}.ce-resize-handle--e{top:50%;right:-5px;transform:translateY(-50%);cursor:e-resize}.ce-resize-handle--w{top:50%;left:-5px;transform:translateY(-50%);cursor:w-resize}.ce-drag-handle-minimal{position:absolute;top:auto;left:50%;transform:translate(-50%);cursor:grab;background-color:#fff;border-radius:50%;border:calc(1.5px * var(--ce-inverse-zoom, 1)) solid #3b82f6;box-shadow:0 2px 8px #00000026,0 0 0 calc(.5px * var(--ce-inverse-zoom, 1)) #ffffffe6;display:flex;align-items:center;justify-content:center;color:#3b82f6;-webkit-user-select:none;user-select:none;pointer-events:auto;z-index:102;transition:all .15s cubic-bezier(.4,0,.2,1)}.ce-drag-handle-minimal:hover{background-color:#3b82f6;color:#fff;box-shadow:0 4px 12px #3b82f64d,0 0 0 calc(1px * var(--ce-inverse-zoom, 1)) #fff;transform:translate(-50%) scale(1.1)}.ce-drag-handle-minimal:active{cursor:grabbing}.ce-drag-handle-minimal svg{width:calc(16px * var(--ce-inverse-zoom, 1));height:calc(16px * var(--ce-inverse-zoom, 1));fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.ce-element-content{width:100%;height:100%}.ce-snap-guide{position:absolute;background-color:#06f;pointer-events:none;z-index:200;opacity:.85;transition:opacity .15s ease;box-shadow:0 0 0 .5px #fff9;animation:snapGuideFadeIn .15s ease-out}.ce-snap-guide--vertical{width:1px;height:100%;left:0;top:0}.ce-snap-guide--horizontal{height:1px;width:100%;left:0;top:0}.ce-snap-guide:after{content:"";position:absolute;inset:-.5px;background:#0066ff26;border-radius:1px;z-index:-1}@keyframes snapGuideFadeIn{0%{opacity:0}to{opacity:.85}}.ce-node-default,.ce-node-input,.ce-node-output{background:#fff;border:1px solid #777;border-radius:4px;padding:10px;min-width:180px;text-align:center;font-size:14px;color:#222;box-shadow:0 1px 4px #0000001a;position:relative}.ce-node-input{border-color:#3b82f6}.ce-node-output{border-color:#10b981}.ce-node-content{pointer-events:none}.ce-handle{width:10px;height:10px;background:#fff;border-radius:50%;position:absolute;border:3px solid #777;z-index:10;cursor:crosshair;transition:border-color .2s}.ce-handle--left{left:0;transform:translate(-50%)}.ce-handle--right{right:0;transform:translate(50%)}.ce-handle--top{top:0;transform:translateY(-50%)}.ce-handle--bottom{bottom:0;transform:translateY(50%)}.ce-workflow-node:hover .ce-delete-node-btn{opacity:1;pointer-events:auto}.ce-delete-node-btn{position:absolute;top:-8px;right:-8px;width:18px;height:18px;background:#ff4d4f;color:#fff;border:none;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;line-height:1;padding:0;z-index:20;opacity:0;pointer-events:none;transition:opacity .2s,transform .1s;box-shadow:0 2px 4px #0000001a}.ce-delete-node-btn:hover{transform:scale(1.1);background:#ff7875}.demo-node{width:100%;height:100%;background:#fff;border:1px solid #e5e7eb;border-radius:8px;overflow:hidden;-webkit-user-select:none;user-select:none;box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f;display:flex;flex-direction:column}.demo-node__header{height:32px;background:#f9fafb;border-bottom:1px solid #e5e7eb;display:flex;align-items:center;padding:0 12px;font-size:12px;font-weight:500;color:#6b7280}.demo-node__body{flex:1;padding:12px;font-size:14px;color:#1f2937;display:flex;align-items:center;justify-content:center;background:#fff}.ce-edge-group .ce-edge-delete-fo{opacity:0;pointer-events:none;transition:opacity .2s}.ce-edge-group:hover .ce-edge-delete-fo{opacity:1;pointer-events:auto}.ce-connection-line{animation:dashdraw .5s linear infinite}@keyframes dashdraw{0%{stroke-dashoffset:10}to{stroke-dashoffset:0}}.ce-group-node{position:relative;pointer-events:none;width:100%;height:100%}.ce-group-node--editing{outline:2px dashed #0066FF;outline-offset:4px;border-radius:4px}.ce-editor--editing-group .ce-element{opacity:.5;pointer-events:none!important;transition:opacity .25s ease,filter .25s ease;filter:grayscale(.15)}.ce-editor--editing-group .ce-group-node--editing{opacity:1;filter:none;pointer-events:auto;z-index:50!important;outline:2px dashed #0066FF;outline-offset:4px;border-radius:4px;background:#0066ff05;box-shadow:0 0 0 1px #0066ff1a}.ce-editor--editing-group .ce-group-node--editing .ce-element{opacity:1;filter:none;pointer-events:auto!important}.ce-editor--editing-group .ce-group-node--editing .ce-element--selected{opacity:1;filter:none;z-index:100!important}.ce-editor--editing-group .ce-group-node--editing>.ce-element{opacity:1!important;filter:none!important}.ce-element[data-node-type=group].ce-element--selected{outline:2px solid #0066FF;outline-offset:2px;box-shadow:0 0 0 1px #ffffffe6,0 2px 8px #06f3}.ce-error-boundary{padding:20px;background-color:#fee;border:1px solid #fcc;border-radius:4px;color:#c00}.ce-error-boundary__title{margin:0 0 10px;font-size:18px}.ce-error-boundary__message{margin:0 0 10px}.ce-error-boundary__details{font-size:14px}.ce-error-boundary__details summary{cursor:pointer;margin-bottom:10px}.ce-error-boundary__details pre{padding:10px;background-color:#fff;border:1px solid #ddd;border-radius:4px;overflow:auto;font-size:12px}.ce-accessibility-instructions{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.ce-group-editor{position:fixed;top:16px;left:50%;transform:translate(-50%);z-index:10000;display:flex;align-items:center;gap:8px;background-color:#fffffff2;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);padding:8px 16px;border-radius:8px;box-shadow:0 4px 12px #00000026,0 0 0 1px #0000000d;pointer-events:auto}.ce-group-editor__breadcrumbs{display:flex;align-items:center;gap:4px;font-size:13px;color:#666}.ce-group-editor__separator{color:#999;margin:0 4px}.ce-group-editor__breadcrumb{background:none;border:none;padding:4px 8px;border-radius:4px;cursor:pointer;color:#666;font-weight:400;transition:background-color .15s ease}.ce-group-editor__breadcrumb--active{color:#06f;font-weight:600}.ce-group-editor__breadcrumb:hover:not(.ce-group-editor__breadcrumb--active){background-color:#0066ff1a}.ce-group-editor__exit-button{background:none;border:1px solid #ddd;border-radius:6px;padding:6px 12px;cursor:pointer;color:#666;font-size:12px;font-weight:500;display:flex;align-items:center;gap:6px;transition:all .15s ease;margin-left:8px}.ce-group-editor__exit-button:hover{background-color:#f5f5f5;border-color:#bbb}.ce-default-node{padding:20px;background-color:#f0f0f0}.ce-virtualization-debug{position:fixed;bottom:10px;right:10px;padding:8px;background-color:#000000b3;color:#fff;font-size:12px;border-radius:4px;z-index:10000}.ce-virtualized-container{position:relative;width:100%;height:100%}.ce-global-snap-guide{position:absolute;inset:0;pointer-events:none;z-index:200}
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(Dt);var J=typeof document<"u"?document.currentScript:null,Qe={exports:{}},_e={};var Tt;function Yn(){if(Tt)return _e;Tt=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(i,o,r){var s=null;if(r!==void 0&&(s=""+r),o.key!==void 0&&(s=""+o.key),"key"in o){r={};for(var c in o)c!=="key"&&(r[c]=o[c])}else r=o;return o=r.ref,{$$typeof:n,type:i,key:s,ref:o!==void 0?o:null,props:r}}return _e.Fragment=e,_e.jsx=t,_e.jsxs=t,_e}var zt;function Hn(){return zt||(zt=1,Qe.exports=Yn()),Qe.exports}var _=Hn();const kt=n=>{let e;const t=new Set,i=(a,d)=>{const u=typeof a=="function"?a(e):a;if(!Object.is(u,e)){const f=e;e=d??(typeof u!="object"||u===null)?u:Object.assign({},e,u),t.forEach(h=>h(e,f))}},o=()=>e,c={setState:i,getState:o,getInitialState:()=>l,subscribe:a=>(t.add(a),()=>t.delete(a))},l=e=n(i,o,c);return c},Ct=(n=>n?kt(n):kt),Bn=n=>n;function At(n,e=Bn){const t=z.useSyncExternalStore(n.subscribe,z.useCallback(()=>e(n.getState()),[n,e]),z.useCallback(()=>e(n.getInitialState()),[n,e]));return z.useDebugValue(t),t}const Ot=n=>{const e=Ct(n),t=i=>At(e,i);return Object.assign(t,e),t},Xn=(n=>n?Ot(n):Ot),Nt={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Se=new Map,Ce=n=>{const e=Se.get(n);return e?Object.fromEntries(Object.entries(e.stores).map(([t,i])=>[t,i.getState()])):{}},Un=(n,e,t)=>{if(n===void 0)return{type:"untracked",connection:e.connect(t)};const i=Se.get(t.name);if(i)return{type:"tracked",store:n,...i};const o={connection:e.connect(t),stores:{}};return Se.set(t.name,o),{type:"tracked",store:n,...o}},Fn=(n,e)=>{if(e===void 0)return;const t=Se.get(n);t&&(delete t.stores[e],Object.keys(t.stores).length===0&&Se.delete(n))},Vn=n=>{var e,t;if(!n)return;const i=n.split(`
|
|
3
|
+
`),o=i.findIndex(s=>s.includes("api.setState"));if(o<0)return;const r=((e=i[o+1])==null?void 0:e.trim())||"";return(t=/.+ (.+) .+/.exec(r))==null?void 0:t[1]},Wn=(n,e={})=>(t,i,o)=>{const{enabled:r,anonymousActionType:s,store:c,...l}=e;let a;try{a=(r??(Nt?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!a)return n(t,i,o);const{connection:d,...u}=Un(c,a,l);let f=!0;o.setState=((y,p,x)=>{const m=t(y,p);if(!f)return m;const w=x===void 0?{type:s||Vn(new Error().stack)||"anonymous"}:typeof x=="string"?{type:x}:x;return c===void 0?(d?.send(w,i()),m):(d?.send({...w,type:`${c}/${w.type}`},{...Ce(l.name),[c]:o.getState()}),m)}),o.devtools={cleanup:()=>{d&&typeof d.unsubscribe=="function"&&d.unsubscribe(),Fn(l.name,c)}};const h=(...y)=>{const p=f;f=!1,t(...y),f=p},g=n(o.setState,i,o);if(u.type==="untracked"?d?.init(g):(u.stores[u.store]=o,d?.init(Object.fromEntries(Object.entries(u.stores).map(([y,p])=>[y,y===u.store?g:p.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let y=!1;const p=o.dispatch;o.dispatch=(...x)=>{(Nt?"production":void 0)!=="production"&&x[0].type==="__setState"&&!y&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),y=!0),p(...x)}}return d.subscribe(y=>{var p;switch(y.type){case"ACTION":if(typeof y.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return et(y.payload,x=>{if(x.type==="__setState"){if(c===void 0){h(x.state);return}Object.keys(x.state).length!==1&&console.error(`
|
|
4
|
+
[zustand devtools middleware] Unsupported __setState action format.
|
|
5
|
+
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
6
|
+
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
7
|
+
`);const m=x.state[c];if(m==null)return;JSON.stringify(o.getState())!==JSON.stringify(m)&&h(m);return}o.dispatchFromDevtools&&typeof o.dispatch=="function"&&o.dispatch(x)});case"DISPATCH":switch(y.payload.type){case"RESET":return h(g),c===void 0?d?.init(o.getState()):d?.init(Ce(l.name));case"COMMIT":if(c===void 0){d?.init(o.getState());return}return d?.init(Ce(l.name));case"ROLLBACK":return et(y.state,x=>{if(c===void 0){h(x),d?.init(o.getState());return}h(x[c]),d?.init(Ce(l.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return et(y.state,x=>{if(c===void 0){h(x);return}JSON.stringify(o.getState())!==JSON.stringify(x[c])&&h(x[c])});case"IMPORT_STATE":{const{nextLiftedState:x}=y.payload,m=(p=x.computedStates.slice(-1)[0])==null?void 0:p.state;if(!m)return;h(c===void 0?m:m[c]),d?.send(null,x);return}case"PAUSE_RECORDING":return f=!f}return}}),g},et=(n,e)=>{let t;try{t=JSON.parse(n)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}t!==void 0&&e(t)};var Lt=Symbol.for("immer-nothing"),jt=Symbol.for("immer-draftable"),Q=Symbol.for("immer-state");function oe(n,...e){throw new Error(`[Immer] minified error nr: ${n}. Full error at: https://bit.ly/3cXEKWf`)}var ne=Object,pe=ne.getPrototypeOf,Ae="constructor",Oe="prototype",tt="configurable",Ne="enumerable",Le="writable",Ie="value",de=n=>!!n&&!!n[Q];function re(n){return n?Gt(n)||Re(n)||!!n[jt]||!!n[Ae]?.[jt]||Ge(n)||$e(n):!1}var Kn=ne[Oe][Ae].toString(),Rt=new WeakMap;function Gt(n){if(!n||!it(n))return!1;const e=pe(n);if(e===null||e===ne[Oe])return!0;const t=ne.hasOwnProperty.call(e,Ae)&&e[Ae];if(t===Object)return!0;if(!ge(t))return!1;let i=Rt.get(t);return i===void 0&&(i=Function.toString.call(t),Rt.set(t,i)),i===Kn}function Ee(n,e,t=!0){Pe(n)===0?(t?Reflect.ownKeys(n):ne.keys(n)).forEach(o=>{e(o,n[o],n)}):n.forEach((i,o)=>e(o,i,n))}function Pe(n){const e=n[Q];return e?e.type_:Re(n)?1:Ge(n)?2:$e(n)?3:0}var $t=(n,e,t=Pe(n))=>t===2?n.has(e):ne[Oe].hasOwnProperty.call(n,e),nt=(n,e,t=Pe(n))=>t===2?n.get(e):n[e],je=(n,e,t,i=Pe(n))=>{i===2?n.set(e,t):i===3?n.add(t):n[e]=t};function Jn(n,e){return n===e?n!==0||1/n===1/e:n!==n&&e!==e}var Re=Array.isArray,Ge=n=>n instanceof Map,$e=n=>n instanceof Set,it=n=>typeof n=="object",ge=n=>typeof n=="function",ot=n=>typeof n=="boolean",ae=n=>n.copy_||n.base_,st=n=>n.modified_?n.copy_:n.base_;function rt(n,e){if(Ge(n))return new Map(n);if($e(n))return new Set(n);if(Re(n))return Array[Oe].slice.call(n);const t=Gt(n);if(e===!0||e==="class_only"&&!t){const i=ne.getOwnPropertyDescriptors(n);delete i[Q];let o=Reflect.ownKeys(i);for(let r=0;r<o.length;r++){const s=o[r],c=i[s];c[Le]===!1&&(c[Le]=!0,c[tt]=!0),(c.get||c.set)&&(i[s]={[tt]:!0,[Le]:!0,[Ne]:c[Ne],[Ie]:n[s]})}return ne.create(pe(n),i)}else{const i=pe(n);if(i!==null&&t)return{...n};const o=ne.create(i);return ne.assign(o,n)}}function at(n,e=!1){return He(n)||de(n)||!re(n)||(Pe(n)>1&&ne.defineProperties(n,{set:Ye,add:Ye,clear:Ye,delete:Ye}),ne.freeze(n),e&&Ee(n,(t,i)=>{at(i,!0)},!1)),n}function qn(){oe(2)}var Ye={[Ie]:qn};function He(n){return n===null||!it(n)?!0:ne.isFrozen(n)}var Be="MapSet",ct="Patches",Yt={};function me(n){const e=Yt[n];return e||oe(0,n),e}var Zn=n=>!!Yt[n],Me,Ht=()=>Me,Qn=(n,e)=>({drafts_:[],parent_:n,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:Zn(Be)?me(Be):void 0});function Bt(n,e){e&&(n.patchPlugin_=me(ct),n.patches_=[],n.inversePatches_=[],n.patchListener_=e)}function lt(n){dt(n),n.drafts_.forEach(ei),n.drafts_=null}function dt(n){n===Me&&(Me=n.parent_)}var Xt=n=>Me=Qn(Me,n);function ei(n){const e=n[Q];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function Ut(n,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];if(n!==void 0&&n!==t){t[Q].modified_&&(lt(e),oe(4)),re(n)&&(n=Ft(e,n));const{patchPlugin_:o}=e;o&&o.generateReplacementPatches_(t[Q].base_,n,e)}else n=Ft(e,t);return ti(e,n,!0),lt(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),n!==Lt?n:void 0}function Ft(n,e){if(He(e))return e;const t=e[Q];if(!t)return ut(e,n.handledSet_,n);if(!Xe(t,n))return e;if(!t.modified_)return t.base_;if(!t.finalized_){const{callbacks_:i}=t;if(i)for(;i.length>0;)i.pop()(n);Kt(t,n)}return t.copy_}function ti(n,e,t=!1){!n.parent_&&n.immer_.autoFreeze_&&n.canAutoFreeze_&&at(e,t)}function Vt(n){n.finalized_=!0,n.scope_.unfinalizedDrafts_--}var Xe=(n,e)=>n.scope_===e,ni=[];function Wt(n,e,t,i){const o=ae(n),r=n.type_;if(i!==void 0&&nt(o,i,r)===e){je(o,i,t,r);return}if(!n.draftLocations_){const c=n.draftLocations_=new Map;Ee(o,(l,a)=>{if(de(a)){const d=c.get(a)||[];d.push(l),c.set(a,d)}})}const s=n.draftLocations_.get(e)??ni;for(const c of s)je(o,c,t,r)}function ii(n,e,t){n.callbacks_.push(function(o){const r=e;if(!r||!Xe(r,o))return;o.mapSetPlugin_?.fixSetContents(r);const s=st(r);Wt(n,r.draft_??r,s,t),Kt(r,o)})}function Kt(n,e){if(n.modified_&&!n.finalized_&&(n.type_===3||(n.assigned_?.size??0)>0)){const{patchPlugin_:i}=e;if(i){const o=i.getPath(n);o&&i.generatePatches_(n,o,e)}Vt(n)}}function oi(n,e,t){const{scope_:i}=n;if(de(t)){const o=t[Q];Xe(o,i)&&o.callbacks_.push(function(){Ue(n);const s=st(o);Wt(n,t,s,e)})}else re(t)&&n.callbacks_.push(function(){const r=ae(n);nt(r,e,n.type_)===t&&i.drafts_.length>1&&(n.assigned_.get(e)??!1)===!0&&n.copy_&&ut(nt(n.copy_,e,n.type_),i.handledSet_,i)})}function ut(n,e,t){return!t.immer_.autoFreeze_&&t.unfinalizedDrafts_<1||de(n)||e.has(n)||!re(n)||He(n)||(e.add(n),Ee(n,(i,o)=>{if(de(o)){const r=o[Q];if(Xe(r,t)){const s=st(r);je(n,i,s,n.type_),Vt(r)}}else re(o)&&ut(o,e,t)})),n}function si(n,e){const t=Re(n),i={type_:t?1:0,scope_:e?e.scope_:Ht(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:e,base_:n,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let o=i,r=ft;t&&(o=[i],r=De);const{revoke:s,proxy:c}=Proxy.revocable(o,r);return i.draft_=c,i.revoke_=s,[c,i]}var ft={get(n,e){if(e===Q)return n;const t=ae(n);if(!$t(t,e,n.type_))return ri(n,t,e);const i=t[e];if(n.finalized_||!re(i))return i;if(i===ht(n.base_,e)){Ue(n);const o=n.type_===1?+e:e,r=gt(n.scope_,i,n,o);return n.copy_[o]=r}return i},has(n,e){return e in ae(n)},ownKeys(n){return Reflect.ownKeys(ae(n))},set(n,e,t){const i=Jt(ae(n),e);if(i?.set)return i.set.call(n.draft_,t),!0;if(!n.modified_){const o=ht(ae(n),e),r=o?.[Q];if(r&&r.base_===t)return n.copy_[e]=t,n.assigned_.set(e,!1),!0;if(Jn(t,o)&&(t!==void 0||$t(n.base_,e,n.type_)))return!0;Ue(n),pt(n)}return n.copy_[e]===t&&(t!==void 0||e in n.copy_)||Number.isNaN(t)&&Number.isNaN(n.copy_[e])||(n.copy_[e]=t,n.assigned_.set(e,!0),oi(n,e,t)),!0},deleteProperty(n,e){return Ue(n),ht(n.base_,e)!==void 0||e in n.base_?(n.assigned_.set(e,!1),pt(n)):n.assigned_.delete(e),n.copy_&&delete n.copy_[e],!0},getOwnPropertyDescriptor(n,e){const t=ae(n),i=Reflect.getOwnPropertyDescriptor(t,e);return i&&{[Le]:!0,[tt]:n.type_!==1||e!=="length",[Ne]:i[Ne],[Ie]:t[e]}},defineProperty(){oe(11)},getPrototypeOf(n){return pe(n.base_)},setPrototypeOf(){oe(12)}},De={};Ee(ft,(n,e)=>{De[n]=function(){const t=arguments;return t[0]=t[0][0],e.apply(this,t)}}),De.deleteProperty=function(n,e){return De.set.call(this,n,e,void 0)},De.set=function(n,e,t){return ft.set.call(this,n[0],e,t,n[0])};function ht(n,e){const t=n[Q];return(t?ae(t):n)[e]}function ri(n,e,t){const i=Jt(e,t);return i?Ie in i?i[Ie]:i.get?.call(n.draft_):void 0}function Jt(n,e){if(!(e in n))return;let t=pe(n);for(;t;){const i=Object.getOwnPropertyDescriptor(t,e);if(i)return i;t=pe(t)}}function pt(n){n.modified_||(n.modified_=!0,n.parent_&&pt(n.parent_))}function Ue(n){n.copy_||(n.assigned_=new Map,n.copy_=rt(n.base_,n.scope_.immer_.useStrictShallowCopy_))}var ai=class{constructor(n){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,i)=>{if(ge(e)&&!ge(t)){const r=t;t=e;const s=this;return function(l=r,...a){return s.produce(l,d=>t.call(this,d,...a))}}ge(t)||oe(6),i!==void 0&&!ge(i)&&oe(7);let o;if(re(e)){const r=Xt(this),s=gt(r,e,void 0);let c=!0;try{o=t(s),c=!1}finally{c?lt(r):dt(r)}return Bt(r,i),Ut(o,r)}else if(!e||!it(e)){if(o=t(e),o===void 0&&(o=e),o===Lt&&(o=void 0),this.autoFreeze_&&at(o,!0),i){const r=[],s=[];me(ct).generateReplacementPatches_(e,o,{patches_:r,inversePatches_:s}),i(r,s)}return o}else oe(1,e)},this.produceWithPatches=(e,t)=>{if(ge(e))return(s,...c)=>this.produceWithPatches(s,l=>e(l,...c));let i,o;return[this.produce(e,t,(s,c)=>{i=s,o=c}),i,o]},ot(n?.autoFreeze)&&this.setAutoFreeze(n.autoFreeze),ot(n?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(n.useStrictShallowCopy),ot(n?.useStrictIteration)&&this.setUseStrictIteration(n.useStrictIteration)}createDraft(n){re(n)||oe(8),de(n)&&(n=ci(n));const e=Xt(this),t=gt(e,n,void 0);return t[Q].isManual_=!0,dt(e),t}finishDraft(n,e){const t=n&&n[Q];(!t||!t.isManual_)&&oe(9);const{scope_:i}=t;return Bt(i,e),Ut(void 0,i)}setAutoFreeze(n){this.autoFreeze_=n}setUseStrictShallowCopy(n){this.useStrictShallowCopy_=n}setUseStrictIteration(n){this.useStrictIteration_=n}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(n,e){let t;for(t=e.length-1;t>=0;t--){const o=e[t];if(o.path.length===0&&o.op==="replace"){n=o.value;break}}t>-1&&(e=e.slice(t+1));const i=me(ct).applyPatches_;return de(n)?i(n,e):this.produce(n,o=>i(o,e))}};function gt(n,e,t,i){const[o,r]=Ge(e)?me(Be).proxyMap_(e,t):$e(e)?me(Be).proxySet_(e,t):si(e,t);return(t?.scope_??Ht()).drafts_.push(o),r.callbacks_=t?.callbacks_??[],r.key_=i,t&&i!==void 0?ii(t,r,i):r.callbacks_.push(function(l){l.mapSetPlugin_?.fixSetContents(r);const{patchPlugin_:a}=l;r.modified_&&a&&a.generatePatches_(r,[],l)}),o}function ci(n){return de(n)||oe(10,n),qt(n)}function qt(n){if(!re(n)||He(n))return n;const e=n[Q];let t,i=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,t=rt(n,e.scope_.immer_.useStrictShallowCopy_),i=e.scope_.immer_.shouldUseStrictIteration()}else t=rt(n,!0);return Ee(t,(o,r)=>{je(t,o,qt(r))},i),e&&(e.finalized_=!1),t}var li=new ai,di=li.produce;const ui=n=>(e,t,i)=>(i.setState=(o,r,...s)=>{const c=typeof o=="function"?di(o):o;return e(c,r,...s)},n(i.setState,t,i));var Zt=(n,e,t)=>(o,r)=>({pastStates:t?.pastStates||[],futureStates:t?.futureStates||[],undo:(s=1)=>{if(r().pastStates.length){const c=t?.partialize?.(e())||e(),l=r().pastStates.splice(-s,s),a=l.shift();n(a),o({pastStates:r().pastStates,futureStates:r().futureStates.concat(t?.diff?.(c,a)||c,l.reverse())})}},redo:(s=1)=>{if(r().futureStates.length){const c=t?.partialize?.(e())||e(),l=r().futureStates.splice(-s,s),a=l.shift();n(a),o({pastStates:r().pastStates.concat(t?.diff?.(c,a)||c,l.reverse()),futureStates:r().futureStates})}},clear:()=>o({pastStates:[],futureStates:[]}),isTracking:!0,pause:()=>o({isTracking:!1}),resume:()=>o({isTracking:!0}),setOnSave:s=>o({_onSave:s}),_onSave:t?.onSave,_handleSet:(s,c,l,a)=>{t?.limit&&r().pastStates.length>=t?.limit&&r().pastStates.shift(),r()._onSave?.(s,l),o({pastStates:r().pastStates.concat(a||s),futureStates:[]})}}),fi=(n,e)=>(i,o,r)=>{r.temporal=Ct(e?.wrapTemporal?.(Zt(i,o,e))||Zt(i,o,e));const s=e?.handleSet?.(r.temporal.getState()._handleSet)||r.temporal.getState()._handleSet,c=a=>{if(!r.temporal.getState().isTracking)return;const d=e?.partialize?.(o())||o(),u=e?.diff?.(a,d);u===null||e?.equality?.(a,d)||s(a,void 0,d,u)},l=r.setState;return r.setState=(...a)=>{const d=e?.partialize?.(o())||o();l(...a),c(d)},n((...a)=>{const d=e?.partialize?.(o())||o();i(...a),c(d)},o,r)};function hi(n){const e=[];return n.id||e.push("Node must have an id"),(typeof n.x!="number"||isNaN(n.x))&&e.push("Node x must be a valid number"),(typeof n.y!="number"||isNaN(n.y))&&e.push("Node y must be a valid number"),(typeof n.width!="number"||n.width<0)&&e.push("Node width must be a positive number"),(typeof n.height!="number"||n.height<0)&&e.push("Node height must be a positive number"),n.rotation!==void 0&&(typeof n.rotation!="number"||isNaN(n.rotation))&&e.push("Node rotation must be a valid number"),n.pageId!==void 0&&typeof n.pageId!="string"&&e.push("Node pageId must be a string"),{valid:e.length===0,errors:e}}const ye=(n,e)=>Object.values(e).filter(t=>t.parentId===n),Qt=n=>{if(n.length===0)return{x:0,y:0,width:100,height:100};let e=1/0,t=1/0,i=-1/0,o=-1/0;return n.forEach(r=>{e=Math.min(e,r.x),t=Math.min(t,r.y),i=Math.max(i,r.x+r.width),o=Math.max(o,r.y+r.height)}),{x:e,y:t,width:i-e,height:o-t}},pi=(n,e,t)=>{const i=t[n];if(!i)return null;if(!e)return i.type==="group"?i.id:null;let o=i;for(;o.parentId&&o.parentId!==e;){const r=t[o.parentId];if(!r)break;o=r}return o.parentId===e&&o.type==="group"?o.id:null},gi=(n,e,t)=>{const i=t[n];if(!i)return null;if(i.parentId===e)return n;let o=i;for(;o.parentId&&o.parentId!==e;){const r=t[o.parentId];if(!r)return null;o=r}return o.parentId===e?o.id:null};class mi{isDevelopment;logHistory=[];maxHistorySize=100;constructor(){try{this.isDevelopment=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"&&!1}catch{this.isDevelopment=!1}}log(e,t,...i){const o={level:e,message:t,timestamp:Date.now(),data:i.length>0?i:void 0};if(this.logHistory.push(o),this.logHistory.length>this.maxHistorySize&&this.logHistory.shift(),!this.isDevelopment&&e==="debug")return;const r=`[Editor ${e.toUpperCase()}]`,s=new Date().toISOString();switch(e){case"error":console.error(`${s} ${r}`,t,...i),this.isDevelopment||this.reportError(t,i);break;case"warn":console.warn(`${s} ${r}`,t,...i);break;case"info":this.isDevelopment&&console.info(`${s} ${r}`,t,...i);break;case"debug":this.isDevelopment&&console.debug(`${s} ${r}`,t,...i);break}}reportError(e,t){}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,t,...i){t?this.log("error",e,t,...i):this.log("error",e,...i)}getHistory(){return[...this.logHistory]}clearHistory(){this.logHistory=[]}}let mt=null;function yi(){return mt||(mt=new mi),mt}const B=yi(),vi={snapping:!0,snapGuide:!0,rotation:!0,rotationSpeed:2,rotationSnap:5,zoom:!0,pan:!1,viewOnly:!1,minZoom:.1,maxZoom:5,showGrid:!0,gridSize:20,gridColor:"#ddd",pageWidth:1920,pageHeight:1080,pageGap:40},xi=(n=[],e={})=>{const t={...vi,...e},i={id:"page-1",width:t.pageWidth,height:t.pageHeight,backgroundColor:"#ffffff",name:"Page 1"},o=n.map(r=>({...r,pageId:r.pageId||i.id}));return Xn()(fi(Wn(ui(r=>({pages:{[i.id]:i},pageOrder:[i.id],dragTargetPageId:null,activePageId:i.id,nodes:o.reduce((s,c)=>({...s,[c.id]:c}),{}),selectedIds:[],editingGroupId:null,clipboard:{nodes:[],copyCount:0},camera:{x:(1200-i.width)/2,y:(800-i.height)/2+100,zoom:.5},dimensions:{width:0,height:0},config:t,setActivePage:s=>r(c=>{c.activePageId=s}),setCamera:(s,c,l)=>r(a=>{a.camera.x=s,a.camera.y=c,a.camera.zoom=l}),panCamera:(s,c)=>r(l=>{l.camera.x+=s,l.camera.y+=c}),zoomCamera:(s,c,l)=>r(a=>{const{zoom:d,x:u,y:f}=a.camera,{minZoom:h=.1,maxZoom:g=5}=a.config;let y=d*s;y<h&&(y=h),y>g&&(y=g);const p=c-(c-u)*(y/d),x=l-(l-f)*(y/d);a.camera={x:p,y:x,zoom:y}}),setDimensions:(s,c)=>r(l=>{l.dimensions={width:s,height:c}}),setNodes:s=>r(c=>{c.nodes=s.reduce((l,a)=>({...l,[a.id]:a}),{})}),addNode:s=>{hi(s).valid&&r(l=>{l.nodes[s.id]=s})},updateNode:(s,c)=>r(l=>{const a=l.nodes[s];if(a&&(Object.assign(a,c),a.parentId&&l.nodes[a.parentId])){const d=l.nodes[a.parentId];if(d.type==="group"){const u=ye(d.id,l.nodes),f=Qt(u);d.x+=f.x,d.y+=f.y,d.width=f.width,d.height=f.height,u.forEach(h=>{h.x-=f.x,h.y-=f.y})}}}),removeNode:s=>r(c=>{delete c.nodes[s],c.selectedIds=c.selectedIds.filter(l=>l!==s)}),selectNode:(s,c)=>r(l=>{c?l.selectedIds.includes(s)?l.selectedIds=l.selectedIds.filter(a=>a!==s):l.selectedIds.push(s):l.selectedIds=s?[s]:[]}),duplicateSelected:()=>{r(s=>{const c=[],l=(a,d=20,u=20,f)=>{const h=s.nodes[a];if(!h)return null;const g=`node-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,y={...h,id:g,x:h.x+d,y:h.y+u,parentId:f};return s.nodes[g]=y,h.type==="group"&&ye(a,s.nodes).forEach(x=>{l(x.id,0,0,g)}),g};s.selectedIds.forEach(a=>{const d=l(a);d&&c.push(d)}),s.selectedIds=c})},copy:()=>r(s=>{if(s.selectedIds.length===0)return;const c=[];s.selectedIds.forEach(l=>{const a=s.nodes[l];if(a){const d=JSON.parse(JSON.stringify(a));c.push(d),a.type==="group"&&ye(l,s.nodes).forEach(f=>{const h=JSON.parse(JSON.stringify(f));c.push(h)})}}),s.clipboard.nodes=c,s.clipboard.copyCount=0}),paste:()=>r(s=>{if(s.clipboard.nodes.length===0)return;const c=20+s.clipboard.copyCount*20,l=[],a={},d=s.activePageId||void 0;s.clipboard.nodes.forEach(u=>{const f=`node-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;a[u.id]=f;const h={...u,id:f,x:u.x+c,y:u.y+c,pageId:d};u.parentId&&a[u.parentId]?h.parentId=a[u.parentId]:h.parentId=void 0,s.nodes[f]=h,h.parentId||l.push(f)}),s.selectedIds=l,s.clipboard.copyCount+=1}),cut:()=>r(s=>{if(s.selectedIds.length===0)return;const c=[];s.selectedIds.forEach(a=>{const d=s.nodes[a];if(d){const u=JSON.parse(JSON.stringify(d));c.push(u),d.type==="group"&&ye(a,s.nodes).forEach(h=>{const g=JSON.parse(JSON.stringify(h));c.push(g)})}}),s.clipboard.nodes=c,s.clipboard.copyCount=0;const l={...s.nodes};s.selectedIds.forEach(a=>{delete l[a]}),s.nodes=l,s.selectedIds=[]}),nudgeSelected:(s,c)=>r(l=>{l.selectedIds.forEach(a=>{const d=l.nodes[a];d&&(d.x+=s,d.y+=c)})}),rotateSelected:s=>r(c=>{c.selectedIds.forEach(l=>{c.nodes[l]&&(c.nodes[l].rotation=s)})}),resizeNode:(s,c,l,a,d)=>r(u=>{const f=u.nodes[s];if(f){if(f.type==="group"){const h=f.width,g=f.height,y=h>0?a/h:1,p=g>0?d/g:1,x=(m,w,S)=>{Object.values(u.nodes).forEach(I=>{I.parentId===m&&(I.x*=w,I.y*=S,I.width*=w,I.height*=S,I.type==="group"&&x(I.id,w,S))})};x(s,y,p)}if(f.x=c,f.y=l,f.width=a,f.height=d,f.parentId&&u.nodes[f.parentId]){const h=u.nodes[f.parentId];if(h.type==="group"){const g=ye(h.id,u.nodes),y=Qt(g);h.x+=y.x,h.y+=y.y,h.width=y.width,h.height=y.height,g.forEach(p=>{p.x-=y.x,p.y-=y.y})}}}}),rotateNode:(s,c)=>r(l=>{l.nodes[s]&&(l.nodes[s].rotation=c)}),deleteSelected:()=>r(s=>{const c={...s.nodes};return s.selectedIds.forEach(l=>{delete c[l]}),{nodes:c,selectedIds:[]}}),selectAll:()=>r(s=>{s.selectedIds=Object.keys(s.nodes)}),deselectAll:()=>r(s=>{s.selectedIds=[]}),setEditingGroup:s=>r(c=>{if(s===null)c.editingGroupId=null,c.selectedIds=[];else{if(!c.nodes[s]||c.nodes[s].type!=="group"){c.editingGroupId=null;return}c.editingGroupId=s,c.selectedIds.includes(s)&&(c.selectedIds=c.selectedIds.filter(l=>l!==s))}}),resizeSelected:(s,c,l,a,d)=>{B.warn("resizeSelected called but likely deprecated by resizeSelectedLocal")},resizeSelectedLocal:(s,c,l,a,d,u)=>r(f=>{const h=-(a*Math.PI)/180,g=Math.cos(h),y=Math.sin(h),p=a*Math.PI/180,x=Math.cos(p),m=Math.sin(p),w={};let S=0;const I=f.config.pageGap||40;f.pageOrder.forEach(k=>{w[k]=S;const C=f.pages[k];C&&(S+=C.height+I)}),Object.keys(d).forEach(k=>{const C=d[k],v=f.nodes[k];if(!v)return;const E=C.cx-l.x,P=C.cy-l.y,b=E*g-P*y,A=E*y+P*g,M=b*s,R=A*c,K=M*x-R*m,G=M*m+R*x,N=l.x+K,L=l.y+G,j=C.w*s,$=C.h*c,X=w[v.pageId||""]||0,V=N-u.x,se=L-u.y-X;v.width=j,v.height=$,v.x=V-j/2,v.y=se-$/2})}),rotateSelectedBy:s=>r(c=>{const{selectedIds:l,nodes:a,config:d,pageOrder:u,pages:f}=c;if(l.length===0)return;let h=1/0,g=1/0,y=-1/0,p=-1/0;const x=d.pageGap||40,m={};let w=0;u.forEach(P=>{m[P]=w,w+=(f[P]?.height||0)+x});const S=[];if(l.forEach(P=>{const b=a[P];if(b){const A=m[b.pageId||u[0]]||0,M=b.x,R=b.y+A;h=Math.min(h,M),g=Math.min(g,R),y=Math.max(y,M+b.width),p=Math.max(p,R+b.height),S.push({id:P,startX:M,startY:R})}}),S.length===0)return;const I=(h+y)/2,k=(g+p)/2,C=s*Math.PI/180,v=Math.cos(C),E=Math.sin(C);S.forEach(P=>{const b=a[P.id],A=b.x+b.width/2,M=m[b.pageId||u[0]]||0,R=b.y+M+b.height/2,K=A-I,G=R-k,N=K*v-G*E,L=K*E+G*v,j=I+N,$=k+L,X=j-b.width/2,V=$-b.height/2;b.x=X,b.y=V-M,b.rotation=(b.rotation||0)+s})}),setConfig:s=>r(c=>{c.config={...c.config,...s}}),addPage:s=>{let c="";return r(l=>{const a=l.pageOrder.length+1;c=`page-${Date.now()}`;const d={id:c,width:s?.width||l.config.pageWidth||1920,height:s?.height||l.config.pageHeight||1080,backgroundColor:s?.backgroundColor||"#ffffff",name:s?.name||`Page ${a}`};l.pages[c]=d,l.pageOrder.push(c)}),c},removePage:s=>r(c=>{if(c.pageOrder.length<=1)return;delete c.pages[s],c.pageOrder=c.pageOrder.filter(a=>a!==s);const l=c.pageOrder[0];Object.values(c.nodes).forEach(a=>{a.pageId===s&&(l?a.pageId=l:delete c.nodes[a.id])})}),updatePage:(s,c)=>r(l=>{l.pages[s]&&Object.assign(l.pages[s],c)}),setDragTargetPage:s=>r(c=>{c.dragTargetPageId=s}),moveSelectedToPage:s=>r(c=>{}),checkAutoReparent:()=>r(s=>{const{selectedIds:c,nodes:l,pages:a,pageOrder:d,config:u}=s;if(c.length===0)return;let f=1/0,h=1/0,g=-1/0,y=-1/0;const p=u.pageGap||40,x={};let m=0;d.forEach(C=>{x[C]=m;const v=a[C];m+=(v?.height||0)+p});let w=!1;if(c.forEach(C=>{const v=l[C];if(v){w=!0;const E=x[v.pageId||d[0]]||0,P=v.y+E;f=Math.min(f,v.x),h=Math.min(h,P),g=Math.max(g,v.x+v.width),y=Math.max(y,P+v.height)}}),!w)return;const S=(h+y)/2;let I=null,k=0;for(const C of d){const v=a[C];if(!v)continue;const E=v.height||0,P=k,b=k+E;if(S>=P-p/2&&S<=b+p/2){I=C;break}k+=E+p}!I&&S>k&&(I=d[d.length-1]),I&&c.forEach(C=>{const v=l[C];if(v&&v.pageId!==I){const E=x[v.pageId||""]||0,P=v.y+E;v.pageId=I,v.y=P-(x[I]||0)}})}),groupSelected:()=>{r(s=>{const{selectedIds:c,nodes:l}=s;if(c.length<2)return;const a=c.filter(x=>{const m=l[x];return m&&!m.parentId});if(a.length<2)return;const d=l[a[0]]?.pageId;let u=1/0,f=1/0,h=-1/0,g=-1/0;a.forEach(x=>{const m=l[x];m&&m.pageId===d&&(u=Math.min(u,m.x),f=Math.min(f,m.y),h=Math.max(h,m.x+m.width),g=Math.max(g,m.y+m.height))});const y=4;u-=y,f-=y,h+=y,g+=y;const p={id:`group-${Date.now()}`,type:"group",x:u,y:f,width:h-u,height:g-f,pageId:d,rotation:0,data:{name:`Group ${a.length} items`,createdAt:Date.now()}};s.nodes[p.id]=p,a.forEach(x=>{const m=l[x];m&&(m.parentId=p.id,m.x-=u,m.y-=f)}),s.selectedIds=[p.id]})},ungroupSelected:()=>{r(s=>{const{selectedIds:c,nodes:l}=s;if(c.length!==1)return;const a=c[0],d=l[a];if(!d||d.type!=="group")return;const u=[];if(Object.values(l).forEach(f=>{f.parentId===a&&u.push(f.id)}),u.length===0){delete s.nodes[a],s.selectedIds=[];return}u.forEach(f=>{const h=l[f];h&&(h.parentId=void 0,h.x+=d.x,h.y+=d.y,h.pageId=d.pageId||h.pageId)}),delete s.nodes[a],s.editingGroupId===a&&(s.editingGroupId=null),s.selectedIds=u})},bringForward:()=>r(s=>{s.selectedIds.forEach(c=>{const l=s.nodes[c];l&&(l.zIndex=(l.zIndex||0)+1)})}),sendBackward:()=>r(s=>{s.selectedIds.forEach(c=>{const l=s.nodes[c];l&&(l.zIndex=(l.zIndex||0)-1)})}),bringToFront:()=>r(s=>{const c=Math.max(...Object.values(s.nodes).map(l=>l.zIndex||0),0);s.selectedIds.forEach(l=>{const a=s.nodes[l];a&&(a.zIndex=c+1)})}),sendToBack:()=>r(s=>{const c=Math.min(...Object.values(s.nodes).map(l=>l.zIndex||0),0);s.selectedIds.forEach(l=>{const a=s.nodes[l];a&&(a.zIndex=c-1)})}),toggleLock:()=>r(s=>{s.selectedIds.forEach(c=>{const l=s.nodes[c];l&&(l.locked=!l.locked)})}),lockSelected:()=>r(s=>{s.selectedIds.forEach(c=>{const l=s.nodes[c];l&&(l.locked=!0)})}),unlockSelected:()=>r(s=>{s.selectedIds.forEach(c=>{const l=s.nodes[c];l&&(l.locked=!1)})}),alignLeft:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(a=>s.nodes[a]),l=Math.min(...c.map(a=>a.x));s.selectedIds.forEach(a=>{s.nodes[a].x=l})}),alignRight:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(a=>s.nodes[a]),l=Math.max(...c.map(a=>a.x+a.width));s.selectedIds.forEach(a=>{const d=s.nodes[a];d.x=l-d.width})}),alignTop:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(a=>s.nodes[a]),l=Math.min(...c.map(a=>a.y));s.selectedIds.forEach(a=>{s.nodes[a].y=l})}),alignBottom:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(a=>s.nodes[a]),l=Math.max(...c.map(a=>a.y+a.height));s.selectedIds.forEach(a=>{const d=s.nodes[a];d.y=l-d.height})}),alignCenterH:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(u=>s.nodes[u]),l=Math.min(...c.map(u=>u.x)),a=Math.max(...c.map(u=>u.x+u.width)),d=(l+a)/2;s.selectedIds.forEach(u=>{const f=s.nodes[u];f.x=d-f.width/2})}),alignCenterV:()=>r(s=>{if(s.selectedIds.length<2)return;const c=s.selectedIds.map(u=>s.nodes[u]),l=Math.min(...c.map(u=>u.y)),a=Math.max(...c.map(u=>u.y+u.height)),d=(l+a)/2;s.selectedIds.forEach(u=>{const f=s.nodes[u];f.y=d-f.height/2})}),distributeH:()=>r(s=>{if(s.selectedIds.length<3)return;const c=s.selectedIds.map(g=>s.nodes[g]).sort((g,y)=>g.x-y.x),l=c[0].x,a=c[c.length-1].x+c[c.length-1].width,d=c.reduce((g,y)=>g+y.width,0),f=(a-l-d)/(c.length-1);let h=l;c.forEach((g,y)=>{y>0&&(h+=c[y-1].width+f),y>0&&y<c.length-1&&(s.nodes[g.id].x=h)})}),distributeV:()=>r(s=>{if(s.selectedIds.length<3)return;const c=s.selectedIds.map(g=>s.nodes[g]).sort((g,y)=>g.y-y.y),l=c[0].y,a=c[c.length-1].y+c[c.length-1].height,d=c.reduce((g,y)=>g+y.height,0),f=(a-l-d)/(c.length-1);let h=l;c.forEach((g,y)=>{y>0&&(h+=c[y-1].height+f),y>0&&y<c.length-1&&(s.nodes[g.id].y=h)})})}))),{limit:50,equality:(r,s)=>r===s}))},bi=()=>{const n=fe();z.useEffect(()=>{const e=t=>{if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"||document.activeElement?.isContentEditable)return;const i=t.metaKey||t.ctrlKey,o=t.shiftKey;if(i&&!o&&t.key.toLowerCase()==="z"){t.preventDefault(),n.temporal?.getState().undo();return}if(i&&o&&t.key.toLowerCase()==="z"||i&&t.key.toLowerCase()==="y"){t.preventDefault(),n.temporal?.getState().redo();return}if(i&&t.key.toLowerCase()==="c"){t.preventDefault(),n.getState().copy();return}if(i&&t.key.toLowerCase()==="v"){t.preventDefault(),n.getState().paste();return}if(i&&t.key.toLowerCase()==="x"){t.preventDefault(),n.getState().cut();return}if(i&&!o&&t.key.toLowerCase()==="g"&&(t.preventDefault(),n.getState().groupSelected()),i&&o&&t.key.toLowerCase()==="g"){t.preventDefault(),n.getState().ungroupSelected();return}if(t.key==="Escape"&&n.getState().editingGroupId){t.preventDefault(),n.getState().setEditingGroup(null);return}if((t.key==="Backspace"||t.key==="Delete")&&n.getState().deleteSelected(),i&&t.key.toLowerCase()==="a"&&(t.preventDefault(),n.getState().selectAll()),i&&t.key.toLowerCase()==="d"&&(t.preventDefault(),n.getState().duplicateSelected()),["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t.key)){t.preventDefault();let r=5;t.shiftKey&&(r=10),t.altKey&&(r=1);let s=0,c=0;t.key==="ArrowUp"&&(c=-r),t.key==="ArrowDown"&&(c=r),t.key==="ArrowLeft"&&(s=-r),t.key==="ArrowRight"&&(s=r),n.getState().nudgeSelected(s,c);return}if(i&&!o&&t.key==="]"){t.preventDefault(),n.getState().bringForward();return}if(i&&!o&&t.key==="["){t.preventDefault(),n.getState().sendBackward();return}if(i&&o&&t.key==="}"){t.preventDefault(),n.getState().bringToFront();return}if(i&&o&&t.key==="{"){t.preventDefault(),n.getState().sendToBack();return}if(i&&t.key.toLowerCase()==="l"){t.preventDefault(),n.getState().toggleLock();return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n])},yt=z.createContext(null),wi=({children:n,initialNodes:e=[],nodes:t,config:i={},className:o="",style:r,onChange:s})=>{const c=z.useRef(null);return c.current||(c.current=xi(e,i)),z.useEffect(()=>{t&&c.current&&c.current.getState().setNodes(t)},[t]),z.useEffect(()=>{if(!s||!c.current)return;const l=c.current.subscribe(a=>{s(a)});return()=>l()},[s]),z.useEffect(()=>{c.current&&c.current.getState().setConfig(i)},[i]),_.jsx(yt.Provider,{value:c.current,children:_.jsx(_i,{className:o,style:r,children:n})})},_i=({className:n,style:e,children:t})=>(bi(),_.jsx("div",{className:`ce-editor ${n}`,style:e,children:t})),D=n=>{const e=z.useContext(yt);if(!e)throw new Error("useEditor must be used within Editor");return At(e,n)},fe=()=>{const n=z.useContext(yt);if(!n)throw new Error("useEditor must be used within Editor");return n};function Si(n,e,t){return Math.max(e,Math.min(n,t))}const Y={toVector(n,e){return n===void 0&&(n=e),Array.isArray(n)?n:[n,n]},add(n,e){return[n[0]+e[0],n[1]+e[1]]},sub(n,e){return[n[0]-e[0],n[1]-e[1]]},addTo(n,e){n[0]+=e[0],n[1]+=e[1]},subTo(n,e){n[0]-=e[0],n[1]-=e[1]}};function en(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function tn(n,e,t,i=.15){return i===0?Si(n,e,t):n<e?-en(e-n,t-e,i)+e:n>t?+en(n-t,t-e,i)+t:n}function Ii(n,[e,t],[i,o]){const[[r,s],[c,l]]=n;return[tn(e,r,s,i),tn(t,c,l,o)]}function Ei(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var i=t.call(n,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(n)}function Pi(n){var e=Ei(n,"string");return typeof e=="symbol"?e:String(e)}function W(n,e,t){return e=Pi(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function nn(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);e&&(i=i.filter(function(o){return Object.getOwnPropertyDescriptor(n,o).enumerable})),t.push.apply(t,i)}return t}function U(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?nn(Object(t),!0).forEach(function(i){W(n,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):nn(Object(t)).forEach(function(i){Object.defineProperty(n,i,Object.getOwnPropertyDescriptor(t,i))})}return n}const on={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function sn(n){return n?n[0].toUpperCase()+n.slice(1):""}const Mi=["enter","leave"];function Di(n=!1,e){return n&&!Mi.includes(e)}function Ti(n,e="",t=!1){const i=on[n],o=i&&i[e]||e;return"on"+sn(n)+sn(o)+(Di(t,o)?"Capture":"")}const zi=["gotpointercapture","lostpointercapture"];function ki(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const i=zi.includes(e)?"capturecapture":"capture",o=!!~e.indexOf(i);return o&&(e=e.replace("capture","")),{device:e,capture:o,passive:t}}function Ci(n,e=""){const t=on[n],i=t&&t[e]||e;return n+i}function Fe(n){return"touches"in n}function rn(n){return Fe(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function Ai(n){return Array.from(n.touches).filter(e=>{var t,i;return e.target===n.currentTarget||((t=n.currentTarget)===null||t===void 0||(i=t.contains)===null||i===void 0?void 0:i.call(t,e.target))})}function Oi(n){return n.type==="touchend"||n.type==="touchcancel"?n.changedTouches:n.targetTouches}function an(n){return Fe(n)?Oi(n)[0]:n}function vt(n,e){try{const t=e.clientX-n.clientX,i=e.clientY-n.clientY,o=(e.clientX+n.clientX)/2,r=(e.clientY+n.clientY)/2,s=Math.hypot(t,i);return{angle:-(Math.atan2(t,i)*180)/Math.PI,distance:s,origin:[o,r]}}catch{}return null}function Ni(n){return Ai(n).map(e=>e.identifier)}function cn(n,e){const[t,i]=Array.from(n.touches).filter(o=>e.includes(o.identifier));return vt(t,i)}function xt(n){const e=an(n);return Fe(n)?e.identifier:e.pointerId}function ve(n){const e=an(n);return[e.clientX,e.clientY]}const ln=40,dn=800;function un(n){let{deltaX:e,deltaY:t,deltaMode:i}=n;return i===1?(e*=ln,t*=ln):i===2&&(e*=dn,t*=dn),[e,t]}function Li(n){var e,t;const{scrollX:i,scrollY:o,scrollLeft:r,scrollTop:s}=n.currentTarget;return[(e=i??r)!==null&&e!==void 0?e:0,(t=o??s)!==null&&t!==void 0?t:0]}function ji(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:i,metaKey:o,ctrlKey:r}=n;Object.assign(e,{shiftKey:t,altKey:i,metaKey:o,ctrlKey:r})}return e}function Ve(n,...e){return typeof n=="function"?n(...e):n}function Ri(){}function Gi(...n){return n.length===0?Ri:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function fn(n,e){return Object.assign({},e,n||{})}const $i=32;class hn{constructor(e,t,i){this.ctrl=e,this.args=t,this.key=i,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:t,ingKey:i,args:o}=this;t[i]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=o,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,i=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=i.from?Ve(i.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:i,shared:o}=this;t.args=this.args;let r=0;if(e&&(t.event=e,i.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,ji(e)),o.down=o.pressed=o.buttons%2===1||o.touches>0,r=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const k=t._delta.map(Math.abs);Y.addTo(t._distance,k)}this.axisIntent&&this.axisIntent(e);const[s,c]=t._movement,[l,a]=i.threshold,{_step:d,values:u}=t;if(i.hasCustomTransform?(d[0]===!1&&(d[0]=Math.abs(s)>=l&&u[0]),d[1]===!1&&(d[1]=Math.abs(c)>=a&&u[1])):(d[0]===!1&&(d[0]=Math.abs(s)>=l&&Math.sign(s)*l),d[1]===!1&&(d[1]=Math.abs(c)>=a&&Math.sign(c)*a)),t.intentional=d[0]!==!1||d[1]!==!1,!t.intentional)return;const f=[0,0];if(i.hasCustomTransform){const[k,C]=u;f[0]=d[0]!==!1?k-d[0]:0,f[1]=d[1]!==!1?C-d[1]:0}else f[0]=d[0]!==!1?s-d[0]:0,f[1]=d[1]!==!1?c-d[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(f);const h=t.offset,g=t._active&&!t._blocked||t.active;g&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=o[this.ingKey]=t._active,e&&(t.first&&("bounds"in i&&(t._bounds=Ve(i.bounds,t)),this.setup&&this.setup()),t.movement=f,this.computeOffset()));const[y,p]=t.offset,[[x,m],[w,S]]=t._bounds;t.overflow=[y<x?-1:y>m?1:0,p<w?-1:p>S?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const I=t._active?i.rubberband||[0,0]:[0,0];if(t.offset=Ii(t._bounds,t.offset,I),t.delta=Y.sub(t.offset,h),this.computeMovement(),g&&(!t.last||r>$i)){t.delta=Y.sub(t.offset,h);const k=t.delta.map(Math.abs);Y.addTo(t.distance,k),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&r>0&&(t.velocity=[k[0]/r,k[1]/r],t.timeDelta=r)}}emit(){const e=this.state,t=this.shared,i=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!i.triggerAllEvents)return;const o=this.handler(U(U(U({},t),e),{},{[this.aliasKey]:e.values}));o!==void 0&&(e.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function Yi([n,e],t){const i=Math.abs(n),o=Math.abs(e);if(i>o&&i>t)return"x";if(o>i&&o>t)return"y"}class Te extends hn{constructor(...e){super(...e),W(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=Y.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Y.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,i=this.config;if(!t.axis&&e){const o=typeof i.axisThreshold=="object"?i.axisThreshold[rn(e)]:i.axisThreshold;t.axis=Yi(t._movement,o)}t._blocked=(i.lockDirection||!!i.axis)&&!t.axis||!!i.axis&&i.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const Hi=n=>n,pn=.15,gn={enabled(n=!0){return n},eventOptions(n,e,t){return U(U({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[pn,pn];case!1:return[0,0];default:return Y.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return Y.toVector(n)},transform(n,e,t){const i=n||t.shared.transform;return this.hasCustomTransform=!!i,i||Hi},threshold(n){return Y.toVector(n,0)}},Bi=0,he=U(U({},gn),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=Bi){return n},bounds(n={}){if(typeof n=="function")return r=>he.bounds(n(r));if("current"in n)return()=>n.current;if(typeof HTMLElement=="function"&&n instanceof HTMLElement)return n;const{left:e=-1/0,right:t=1/0,top:i=-1/0,bottom:o=1/0}=n;return[[e,t],[i,o]]}}),mn={ArrowRight:(n,e=1)=>[n*e,0],ArrowLeft:(n,e=1)=>[-1*n*e,0],ArrowUp:(n,e=1)=>[0,-1*n*e],ArrowDown:(n,e=1)=>[0,n*e]};class Xi extends Te{constructor(...e){super(...e),W(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const t=e._bounds.getBoundingClientRect(),i=e.currentTarget.getBoundingClientRect(),o={left:t.left-i.left+e.offset[0],right:t.right-i.right+e.offset[0],top:t.top-i.top+e.offset[1],bottom:t.bottom-i.bottom+e.offset[1]};e._bounds=he.bounds(o)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const t=this.config,i=this.state;if(e.buttons!=null&&(Array.isArray(t.pointerButtons)?!t.pointerButtons.includes(e.buttons):t.pointerButtons!==-1&&t.pointerButtons!==e.buttons))return;const o=this.ctrl.setEventIds(e);t.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(o&&o.size>1&&i._pointerActive)&&(this.start(e),this.setupPointer(e),i._pointerId=xt(e),i._pointerActive=!0,this.computeValues(ve(e)),this.computeInitial(),t.preventScrollAxis&&rn(e)!=="mouse"?(i._active=!1,this.setupScrollPrevention(e)):t.delay>0?(this.setupDelayTrigger(e),t.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const t=this.state;t._active=!0,t._preventScroll=!0,t._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const t=this.state,i=this.config;if(!t._pointerActive)return;const o=xt(e);if(t._pointerId!==void 0&&o!==t._pointerId)return;const r=ve(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=Y.sub(r,t._values),this.computeValues(r)),Y.addTo(t._movement,t._delta),this.compute(e),t._delayed&&t.intentional){this.timeoutStore.remove("dragDelay"),t.active=!1,this.startPointerDrag(e);return}if(i.preventScrollAxis&&!t._preventScroll)if(t.axis)if(t.axis===i.preventScrollAxis||i.preventScrollAxis==="xy"){t._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{}const t=this.state,i=this.config;if(!t._active||!t._pointerActive)return;const o=xt(e);if(t._pointerId!==void 0&&o!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[r,s]=t._distance;if(t.tap=r<=i.tapsThreshold&&s<=i.tapsThreshold,t.tap&&i.filterTaps)t._force=!0;else{const[c,l]=t._delta,[a,d]=t._movement,[u,f]=i.swipe.velocity,[h,g]=i.swipe.distance,y=i.swipe.duration;if(t.elapsedTime<y){const p=Math.abs(c/t.timeDelta),x=Math.abs(l/t.timeDelta);p>u&&Math.abs(a)>h&&(t.swipe[0]=Math.sign(c)),x>f&&Math.abs(d)>g&&(t.swipe[1]=Math.sign(l))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const t=this.config,i=t.device;t.pointerLock&&e.currentTarget.requestPointerLock(),t.pointerCapture||(this.eventStore.add(this.sharedConfig.window,i,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,Ui(e);const t=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",t),this.eventStore.add(this.sharedConfig.window,"touch","cancel",t),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const t=mn[e.key];if(t){const i=this.state,o=e.shiftKey?10:e.altKey?.1:1;this.start(e),i._delta=t(this.config.keyboardDisplacement,o),i._keyboardActive=!0,Y.addTo(i._movement,i._delta),this.compute(e),this.emit()}}keyUp(e){e.key in mn&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const t=this.config.device;e(t,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(t,"change",this.pointerMove.bind(this)),e(t,"end",this.pointerUp.bind(this)),e(t,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function Ui(n){"persist"in n&&typeof n.persist=="function"&&n.persist()}const ze=typeof window<"u"&&window.document&&window.document.createElement;function yn(){return ze&&"ontouchstart"in window}function Fi(){return yn()||ze&&window.navigator.maxTouchPoints>1}function Vi(){return ze&&"onpointerdown"in window}function Wi(){return ze&&"exitPointerLock"in window.document}function Ki(){try{return"constructor"in GestureEvent}catch{return!1}}const ie={isBrowser:ze,gesture:Ki(),touch:yn(),touchscreen:Fi(),pointer:Vi(),pointerLock:Wi()},Ji=250,qi=180,Zi=.5,Qi=50,eo=250,to=10,vn={mouse:0,touch:0,pen:8},no=U(U({},he),{},{device(n,e,{pointer:{touch:t=!1,lock:i=!1,mouse:o=!1}={}}){return this.pointerLock=i&&ie.pointerLock,ie.touch&&t?"touch":this.pointerLock?"mouse":ie.pointer&&!o?"pointer":ie.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?Ji:void 0,!(!ie.touchscreen||t===!1))return n||(t!==void 0?"y":void 0)},pointerCapture(n,e,{pointer:{capture:t=!0,buttons:i=1,keys:o=!0}={}}){return this.pointerButtons=i,this.keys=o,!this.pointerLock&&this.device==="pointer"&&t},threshold(n,e,{filterTaps:t=!1,tapsThreshold:i=3,axis:o=void 0}){const r=Y.toVector(n,t?i:o?1:0);return this.filterTaps=t,this.tapsThreshold=i,r},swipe({velocity:n=Zi,distance:e=Qi,duration:t=eo}={}){return{velocity:this.transform(Y.toVector(n)),distance:this.transform(Y.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return qi;case!1:return 0;default:return n}},axisThreshold(n){return n?U(U({},vn),n):vn},keyboardDisplacement(n=to){return n}});function xn(n){const[e,t]=n.overflow,[i,o]=n._delta,[r,s]=n._direction;(e<0&&i>0&&r<0||e>0&&i<0&&r>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&o>0&&s<0||t>0&&o<0&&s>0)&&(n._movement[1]=n._movementBound[1])}const io=30,oo=100;class so extends hn{constructor(...e){super(...e),W(this,"ingKey","pinching"),W(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:t,lastOffset:i}=this.state;e==="wheel"?this.state.offset=Y.add(t,i):this.state.offset=[(1+t[0])*i[0],t[1]+i[1]]}computeMovement(){const{offset:e,lastOffset:t}=this.state;this.state.movement=[e[0]/t[0],e[1]-t[1]]}axisIntent(){const e=this.state,[t,i]=e._movement;if(!e.axis){const o=Math.abs(t)*io-Math.abs(i);o<0?e.axis="angle":o>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const t=this.state,i=this.ctrl.touchIds;if(t._active&&t._touchIds.every(r=>i.has(r))||i.size<2)return;this.start(e),t._touchIds=Array.from(i).slice(0,2);const o=cn(e,t._touchIds);o&&this.pinchStart(e,o)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const t=this.state,i=t._pointerEvents,o=this.ctrl.pointerIds;if(t._active&&Array.from(i.keys()).every(s=>o.has(s))||(i.size<2&&i.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const r=vt(...Array.from(i.values()));r&&this.pinchStart(e,r)}pinchStart(e,t){const i=this.state;i.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const t=cn(e,this.state._touchIds);t&&this.pinchMove(e,t)}pointerMove(e){const t=this.state._pointerEvents;if(t.has(e.pointerId)&&t.set(e.pointerId,e),!this.state._active)return;const i=vt(...Array.from(t.values()));i&&this.pinchMove(e,i)}pinchMove(e,t){const i=this.state,o=i._values[1],r=t.angle-o;let s=0;Math.abs(r)>270&&(s+=Math.sign(r)),this.computeValues([t.distance,t.angle-360*s]),i.origin=t.origin,i.turns=s,i._movement=[i._values[0]/i._initial[0]-1,i._values[1]-i._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const t=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}t._pointerEvents.has(e.pointerId)&&t._pointerEvents.delete(e.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const t=this.state;t._active||(this.start(e),this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY];const i=t._movement;t._movement=[e.scale-1,e.rotation],t._delta=Y.sub(t._movement,i),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(i=>e[i]):!e[t])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||e.cancelable&&e.preventDefault();const i=this.state;i._delta=[-un(e)[1]/oo*i.offset[0],0],Y.addTo(i._movement,i._delta),xn(i),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const t=this.config.device;t&&(e(t,"start",this[t+"Start"].bind(this)),e(t,"change",this[t+"Move"].bind(this)),e(t,"end",this[t+"End"].bind(this)),e(t,"cancel",this[t+"End"].bind(this)),e("lostPointerCapture","",this[t+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const ro=U(U({},gn),{},{device(n,e,{shared:t,pointer:{touch:i=!1}={}}){if(t.target&&!ie.touch&&ie.gesture)return"gesture";if(ie.touch&&i)return"touch";if(ie.touchscreen){if(ie.pointer)return"pointer";if(ie.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:i={}}){const o=s=>{const c=fn(Ve(t,s),{min:-1/0,max:1/0});return[c.min,c.max]},r=s=>{const c=fn(Ve(i,s),{min:-1/0,max:1/0});return[c.min,c.max]};return typeof t!="function"&&typeof i!="function"?[o(),r()]:s=>[o(s),r(s)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",Y.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});class ao extends Te{constructor(...e){super(...e),W(this,"ingKey","moving")}move(e){this.config.mouseOnly&&e.pointerType!=="mouse"||(this.state._active?this.moveChange(e):this.moveStart(e),this.timeoutStore.add("moveEnd",this.moveEnd.bind(this)))}moveStart(e){this.start(e),this.computeValues(ve(e)),this.compute(e),this.computeInitial(),this.emit()}moveChange(e){if(!this.state._active)return;const t=ve(e),i=this.state;i._delta=Y.sub(t,i._values),Y.addTo(i._movement,i._delta),this.computeValues(t),this.compute(e),this.emit()}moveEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}bind(e){e("pointer","change",this.move.bind(this)),e("pointer","leave",this.moveEnd.bind(this))}}const co=U(U({},he),{},{mouseOnly:(n=!0)=>n});class lo extends Te{constructor(...e){super(...e),W(this,"ingKey","scrolling")}scroll(e){this.state._active||this.start(e),this.scrollChange(e),this.timeoutStore.add("scrollEnd",this.scrollEnd.bind(this))}scrollChange(e){e.cancelable&&e.preventDefault();const t=this.state,i=Li(e);t._delta=Y.sub(i,t._values),Y.addTo(t._movement,t._delta),this.computeValues(i),this.compute(e),this.emit()}scrollEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("scroll","",this.scroll.bind(this))}}const uo=he;class fo extends Te{constructor(...e){super(...e),W(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const t=this.state;t._delta=un(e),Y.addTo(t._movement,t._delta),xn(t),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const ho=he;class po extends Te{constructor(...e){super(...e),W(this,"ingKey","hovering")}enter(e){this.config.mouseOnly&&e.pointerType!=="mouse"||(this.start(e),this.computeValues(ve(e)),this.compute(e),this.emit())}leave(e){if(this.config.mouseOnly&&e.pointerType!=="mouse")return;const t=this.state;if(!t._active)return;t._active=!1;const i=ve(e);t._movement=t._delta=Y.sub(i,t._values),this.computeValues(i),this.compute(e),t.delta=t.movement,this.emit()}bind(e){e("pointer","enter",this.enter.bind(this)),e("pointer","leave",this.leave.bind(this))}}const go=U(U({},he),{},{mouseOnly:(n=!0)=>n}),bt=new Map,wt=new Map;function mo(n){bt.set(n.key,n.engine),wt.set(n.key,n.resolver)}const yo={key:"drag",engine:Xi,resolver:no},vo={key:"hover",engine:po,resolver:go},xo={key:"move",engine:ao,resolver:co},bo={key:"pinch",engine:so,resolver:ro},wo={key:"scroll",engine:lo,resolver:uo},_o={key:"wheel",engine:fo,resolver:ho};function So(n,e){if(n==null)return{};var t={},i=Object.keys(n),o,r;for(r=0;r<i.length;r++)o=i[r],!(e.indexOf(o)>=0)&&(t[o]=n[o]);return t}function Io(n,e){if(n==null)return{};var t=So(n,e),i,o;if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);for(o=0;o<r.length;o++)i=r[o],!(e.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(n,i)&&(t[i]=n[i])}return t}const Eo={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=ie.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},Po=["target","eventOptions","window","enabled","transform"];function We(n={},e){const t={};for(const[i,o]of Object.entries(e))switch(typeof o){case"function":t[i]=o.call(t,n[i],i,n);break;case"object":t[i]=We(n[i],o);break;case"boolean":o&&(t[i]=n[i]);break}return t}function Mo(n,e,t={}){const i=n,{target:o,eventOptions:r,window:s,enabled:c,transform:l}=i,a=Io(i,Po);if(t.shared=We({target:o,eventOptions:r,window:s,enabled:c,transform:l},Eo),e){const d=wt.get(e);t[e]=We(U({shared:t.shared},a),d)}else for(const d in a){const u=wt.get(d);u&&(t[d]=We(U({shared:t.shared},a[d]),u))}return t}class bn{constructor(e,t){W(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,i,o,r){const s=this._listeners,c=Ci(t,i),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},a=U(U({},l),r);e.addEventListener(c,o,a);const d=()=>{e.removeEventListener(c,o,a),s.delete(d)};return s.add(d),d}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Do{constructor(){W(this,"_timeouts",new Map)}add(e,t,i=140,...o){this.remove(e),this._timeouts.set(e,window.setTimeout(t,i,...o))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>{window.clearTimeout(e)}),this._timeouts.clear()}}class To{constructor(e){W(this,"gestures",new Set),W(this,"_targetEventStore",new bn(this)),W(this,"gestureEventStores",{}),W(this,"gestureTimeoutStores",{}),W(this,"handlers",{}),W(this,"config",{}),W(this,"pointerIds",new Set),W(this,"touchIds",new Set),W(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),zo(this,e)}setEventIds(e){if(Fe(e))return this.touchIds=new Set(Ni(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=Mo(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,i={};let o;if(!(t.target&&(o=t.target(),!o))){if(t.enabled){for(const s of this.gestures){const c=this.config[s],l=wn(i,c.eventOptions,!!o);if(c.enabled){const a=bt.get(s);new a(this,e,s).bind(l)}}const r=wn(i,t.eventOptions,!!o);for(const s in this.nativeHandlers)r(s,"",c=>this.nativeHandlers[s](U(U({},this.state.shared),{},{event:c,args:e})),void 0,!0)}for(const r in i)i[r]=Gi(...i[r]);if(!o)return i;for(const r in i){const{device:s,capture:c,passive:l}=ki(r);this._targetEventStore.add(o,s,"",i[r],{capture:c,passive:l})}}}}function xe(n,e){n.gestures.add(e),n.gestureEventStores[e]=new bn(n,e),n.gestureTimeoutStores[e]=new Do}function zo(n,e){e.drag&&xe(n,"drag"),e.wheel&&xe(n,"wheel"),e.scroll&&xe(n,"scroll"),e.move&&xe(n,"move"),e.pinch&&xe(n,"pinch"),e.hover&&xe(n,"hover")}const wn=(n,e,t)=>(i,o,r,s={},c=!1)=>{var l,a;const d=(l=s.capture)!==null&&l!==void 0?l:e.capture,u=(a=s.passive)!==null&&a!==void 0?a:e.passive;let f=c?i:Ti(i,o,d);t&&u&&(f+="Passive"),n[f]=n[f]||[],n[f].push(r)},ko=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Co(n){const e={},t={},i=new Set;for(let o in n)ko.test(o)?(i.add(RegExp.lastMatch),t[o]=n[o]):e[o]=n[o];return[t,e,i]}function be(n,e,t,i,o,r){if(!n.has(t)||!bt.has(i))return;const s=t+"Start",c=t+"End",l=a=>{let d;return a.first&&s in e&&e[s](a),t in e&&(d=e[t](a)),a.last&&c in e&&e[c](a),d};o[i]=l,r[i]=r[i]||{}}function Ao(n,e){const[t,i,o]=Co(n),r={};return be(o,t,"onDrag","drag",r,e),be(o,t,"onWheel","wheel",r,e),be(o,t,"onScroll","scroll",r,e),be(o,t,"onPinch","pinch",r,e),be(o,t,"onMove","move",r,e),be(o,t,"onHover","hover",r,e),{handlers:r,config:e,nativeHandlers:i}}function Oo(n,e={},t,i){const o=z.useMemo(()=>new To(n),[]);if(o.applyHandlers(n,i),o.applyConfig(e,t),z.useEffect(o.effect.bind(o)),z.useEffect(()=>o.clean.bind(o),[]),e.target===void 0)return o.bind.bind(o)}function No(n){return n.forEach(mo),function(t,i){const{handlers:o,nativeHandlers:r,config:s}=Ao(t,i||{});return Oo(o,s,void 0,r)}}function ke(n,e){return No([yo,bo,wo,_o,xo,vo])(n,e||{})}const _n=({pos:n,onDragStart:e,onDragMove:t,onDragEnd:i,className:o="",style:r})=>{const s=ke({onDrag:({first:l,movement:[a,d],memo:u,event:f})=>(f.stopPropagation(),l?e():(u&&t(n,a,d,u),u)),onDragEnd:({movement:[l,a],memo:d,event:u})=>{u.stopPropagation(),d&&i(n,l,a,d)}},{drag:{filterTaps:!0,threshold:0}}),c=`Resize handle ${n.toUpperCase()}`;return _.jsx("div",{className:`ce-resize-handle ce-resize-handle--${n} ${o}`,role:"button","aria-label":c,"aria-describedby":"resize-handle-instructions",tabIndex:0,style:{touchAction:"none",...r},...s()})},Sn=({onDragStart:n,onDragMove:e,onDragEnd:t,className:i="",style:o})=>{const r=ke({onDrag:({first:s,xy:[c,l],memo:a,event:d})=>(d.stopPropagation(),s?n(c,l):(a&&e(c,l,a),a)),onDragEnd:({xy:[s,c],memo:l,event:a})=>{a.stopPropagation(),l&&t(s,c,l)}},{drag:{filterTaps:!0,threshold:0}});return _.jsx("div",{className:`ce-rotate-handle ${i}`,role:"button","aria-label":"Rotate handle","aria-describedby":"rotate-handle-instructions",tabIndex:0,style:{touchAction:"none",...o},...r(),children:_.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:_.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})})},In=({lines:n,className:e="",style:t,pageOffset:i={x:0,y:0}})=>n.length?_.jsx(_.Fragment,{children:n.map((o,r)=>{const s=o.type==="vertical",c=o.pos+(s?i.x:i.y);return _.jsx("div",{className:`ce-snap-guide ce-snap-guide--${o.type} ${e}`,style:{left:s?`${c}px`:0,top:s?0:`${c}px`,...t}},`${o.type}-${o.pos}-${r}`)})}):null;function Lo({elementId:n,canSelect:e=!0}){const t=fe(),i=D(u=>u.selectedIds),o=D(u=>u.nodes),r=D(u=>u.editingGroupId),s=i.includes(n),c=z.useMemo(()=>{if(!o[n])return n;const u=o[n];if(!u.parentId)return n;if(!r){let h=u;for(;h.parentId;){const g=o[h.parentId];if(!g)break;h=g}return h.id}return gi(n,r,o)||n},[n,o,r]),l=u=>{e&&t.getState().selectNode(c,u)},a=()=>{e&&t.getState().deselectAll()};return{isSelected:s,select:l,deselect:a,toggleSelection:()=>{e&&(s?a():l())},targetId:c}}const En=8,Pn=(n,e,t,i,o,r,s,c=[])=>{let l=e,a=t;const d=[],u=[e,e+i/2,e+i],f=[t,t+o/2,t+o];return Object.values(r).forEach(h=>{if(h.id===n||c.includes(h.id)||h.parentId!==s)return;const g=[h.x,h.x+h.width/2,h.x+h.width];u.forEach((p,x)=>{g.forEach(m=>{Math.abs(p-m)<En&&(x===0&&(l=m),x===1&&(l=m-i/2),x===2&&(l=m-i),d.push({type:"vertical",pos:m}))})});const y=[h.y,h.y+h.height/2,h.y+h.height];f.forEach((p,x)=>{y.forEach(m=>{Math.abs(p-m)<En&&(x===0&&(a=m),x===1&&(a=m-o/2),x===2&&(a=m-o),d.push({type:"horizontal",pos:m}))})})}),{x:l,y:a,lines:d}},Mn=(n,e,t,i,o,r,s)=>{let l=i,a=o,d=e,u=t;const f=[],h=e,g=e+i,y=e+i/2,p=t,x=t+o,m=t+o/2,w=r.includes("w"),S=r.includes("e"),I=r.includes("n"),k=r.includes("s"),C=r==="n"||r==="s",v=r==="e"||r==="w";Object.values(s).forEach(P=>{if(P.id===n)return;const b=P.x,A=P.x+P.width,M=P.x+P.width/2,R=P.y,K=P.y+P.height,G=P.y+P.height/2;if(S&&[b,A,M].forEach(N=>{Math.abs(g-N)<8&&(l=N-e,f.push({type:"vertical",pos:N}))}),w){const N=e+i;[b,A,M].forEach(L=>{Math.abs(h-L)<8&&(d=L,l=N-L,f.push({type:"vertical",pos:L}))})}if(C&&Math.abs(y-M)<8&&(d=M-i/2,f.push({type:"vertical",pos:M})),k&&[R,K,G].forEach(N=>{Math.abs(x-N)<8&&(a=N-t,f.push({type:"horizontal",pos:N}))}),I){const N=t+o;[R,K,G].forEach(L=>{Math.abs(p-L)<8&&(u=L,a=N-L,f.push({type:"horizontal",pos:L}))})}v&&Math.abs(m-G)<8&&(u=G-o/2,f.push({type:"horizontal",pos:G}))});const E=10;return l<E&&(w&&(d=e+i-E),l=E),a<E&&(I&&(u=t+o-E),a=E),{x:d,y:u,width:l,height:a,lines:f}},F={PAGE_WIDTH:1920,PAGE_HEIGHT:1080,PAGE_GAP:40,MIN_DRAG_DISTANCE:3,SNAP_THRESHOLD:5};class Ke{static getPageAtPosition(e,t,i,o=F.PAGE_GAP){let r=0;for(const s of i){const c=t[s];if(!c)continue;const l=r,a=r+c.height;if(e>=l&&e<=a)return s;r+=c.height+o}return null}static calculatePageOffset(e,t,i,o=F.PAGE_GAP){let r=0;for(const s of i){if(s===e)return r;const c=t[s];c&&(r+=c.height+o)}return r}static isWithinPageBounds(e,t){const{x:i,y:o,width:r,height:s}=e;return i>=0&&o>=0&&i+r<=t.width&&o+s<=t.height}static isPartiallyWithinPageBounds(e,t){const{x:i,y:o,width:r,height:s}=e;return!(i+r<0||o+s<0||i>t.width||o>t.height)}static constrainToPageBounds(e,t,i){return{x:Math.max(0,Math.min(e.x,i.width-t.width)),y:Math.max(0,Math.min(e.y,i.height-t.height))}}static convertPositionBetweenPages(e,t,i,o,r,s=F.PAGE_GAP){const c=this.calculatePageOffset(t,o,r,s),l=this.calculatePageOffset(i,o,r,s),a=e.y+c;return{x:e.x,y:a-l}}static getTotalHeight(e,t,i=F.PAGE_GAP){if(t.length===0)return 0;let o=0;return t.forEach((r,s)=>{const c=e[r];c&&(o+=c.height,s<t.length-1&&(o+=i))}),o}static getMaxWidth(e){return Math.max(...Object.values(e).map(t=>t.width),0)}static getPageByElementCenter(e,t,i,o=F.PAGE_GAP){if(!e.pageId)return null;const s=this.calculatePageOffset(e.pageId,t,i,o)+e.y+e.height/2;return this.getPageAtPosition(s,t,i,o)}}function jo({elementId:n,elementRef:e,enabled:t=!0,canInteract:i=!0,isEditing:o=!1,onDragStart:r,onDragEnd:s,visualElementGetter:c}){const l=fe(),a=D(v=>v.nodes[n]),d=D(v=>v.config),u=D(v=>v.camera.zoom),f=D(v=>v.pages),h=D(v=>v.pageOrder),g=D(v=>v.setDragTargetPage),[y,p]=z.useState(!1),[x,m]=z.useState([]),[w,S]=z.useState(null),[I,k]=z.useState(null),C=ke({onDragStart:({event:v})=>{if(!i||!t)return;const E=v.target;E.closest(".ce-resize-handle")||E.closest(".ce-rotate-handle")||o&&!E.closest(".ce-drag-handle-minimal")||a?.type==="group"&&!E.closest(".ce-drag-handle-minimal")||(p(!0),r?.())},onDrag:({movement:[v,E],first:P,memo:b,event:A})=>{if(!i||!t)return;const M=l.getState().nodes[n];if(M?.locked)return b;const R=A.target;if(R.closest(".ce-resize-handle")||R.closest(".ce-rotate-handle")||o&&!R.closest(".ce-drag-handle-minimal")||M?.type==="group"&&!R.closest(".ce-drag-handle-minimal")||(A&&A.stopPropagation(),!M))return;if(P)return{x:M.x,y:M.y,currentPageId:M.pageId};const K=l.getState().nodes,G=b?.x??M.x,N=b?.y??M.y,L=b?.currentPageId||M.pageId;let j=G+v/u,$=N+E/u;if(d.snapping&&!d.isLimited){const V=Pn(n,j,$,M.width,M.height,K,M.parentId);j=V.x,$=V.y,d.snapGuide&&m(V.lines)}if(M.pageId&&!M.parentId&&d.snapping){const V=f[L||M.pageId];if(V){j>=-10&&j<=10&&(j=0);const ee=V.width-M.width;j>=ee-10&&j<=ee+10&&(j=ee),$>=-10&&$<=10&&($=0);const T=V.height-M.height;$>=T-10&&$<=T+10&&($=T)}}const X=c?c():e.current;if(X&&(X.style.transform=`translate(${j}px, ${$}px) rotate(${M.rotation}deg)`),M.pageId){if(!f[M.pageId])return;const ee=Ke.calculatePageOffset(L,f,h,d.pageGap||F.PAGE_GAP)+$+M.height/2,T=Ke.getPageAtPosition(ee,f,h,d.pageGap||F.PAGE_GAP)||M.pageId;if(T!==L){k(T),g(T);const H=f[T];if(H){const Z=Ke.calculatePageOffset(T,f,h,d.pageGap||F.PAGE_GAP),q=ee-Z-M.height/2,te=Ke.constrainToPageBounds({x:j,y:q},{width:M.width,height:M.height},H);S({visible:!0,x:te.x,y:te.y,targetPageId:T})}}else k(null),g(null),S(null)}return{x:G,y:N,finalX:j,finalY:$,currentPageId:L}},onDragEnd:({memo:v,event:E})=>{if(E&&E.stopPropagation(),k(null),g(null),S(null),m([]),p(!1),v&&typeof v.finalX=="number"&&a){let P=a.pageId,b=v.finalX,A=v.finalY;if(a.pageId&&!a.parentId){let R=0;const K=v.currentPageId||a.pageId;for(const L of h){if(L===K)break;const j=f[L];j&&(R+=j.height+(d.pageGap||F.PAGE_GAP))}const G=v.finalY+a.height/2+R;let N=0;for(const L of h){const j=f[L];if(!j)continue;const $=N,X=N+j.height;if(G>=$&&G<X){P=L,A=G-$-a.height/2,b=Math.max(0,Math.min(v.finalX,j.width-a.width)),A=Math.max(0,Math.min(A,j.height-a.height));break}N+=j.height+(d.pageGap||F.PAGE_GAP)}}l.getState().updateNode(n,{x:b,y:A,...P!==a.pageId?{pageId:P}:{}});const M=c?c():e.current;M&&(M.style.transform="")}s?.()}},{drag:{filterTaps:!0,threshold:F.MIN_DRAG_DISTANCE,enabled:i&&t}});return{isDragging:y,snapLines:x,ghostPreview:w,dragTargetPageId:I,bindDrag:C}}const Dn=(n,e,t,i,o,r,s,c)=>{let l=.5,a=.5;r.includes("n")&&(a=1),r.includes("s")&&(a=0),r.includes("e")&&(l=0),r.includes("w")&&(l=1);const d=o*Math.PI/180,u=Math.cos(d),f=Math.sin(d),h=n+t/2,g=e+i/2,y=t*l-t/2,p=i*a-i/2,x=h+(y*u-p*f),m=g+(y*f+p*u),w=Math.cos(-d),S=Math.sin(-d),I=s*w-c*S,k=s*S+c*w;let C=0,v=0;r.includes("e")&&(C=I),r.includes("w")&&(C=-I),r.includes("s")&&(v=k),r.includes("n")&&(v=-k);const E=Math.max(10,t+C),P=Math.max(10,i+v),b=E*l-E/2,A=P*a-P/2,M=b*u-A*f,R=b*f+A*u,K=x-M,G=m-R,N=K-E/2,L=G-P/2;return{x:N,y:L,width:E,height:P}};function Ro({elementId:n,elementRef:e,enabled:t=!0,canInteract:i=!0,onResizeStart:o,onResizeEnd:r}){const s=fe(),c=D(I=>I.nodes[n]),l=D(I=>I.config),a=D(I=>I.camera.zoom),[d,u]=z.useState(!1),[f,h]=z.useState(null),[g,y]=z.useState([]),p=z.useRef(c);p.current=c;const x=z.useCallback(()=>{if(!p.current)return null;const I=p.current;return{x:I.x,y:I.y,w:I.width,h:I.height,r:I.rotation||0}},[]),m=z.useCallback((I,k,C,v)=>{if(!e.current)return;const E=s.getState().nodes,P=Dn(v.x,v.y,v.w,v.h,v.r,I,k/a,C/a);let b={x:P.x,y:P.y,width:P.width,height:P.height,lines:[]};if(l.snapping&&(b=Mn(n,P.x,P.y,P.width,P.height,I,E)),l.isLimited){const A=l.width||F.PAGE_WIDTH,M=l.height||F.PAGE_HEIGHT;b.x<0&&(b.width+=b.x,b.x=0),b.y<0&&(b.height+=b.y,b.y=0),b.x+b.width>A&&(b.width=A-b.x),b.y+b.height>M&&(b.height=M-b.y)}l.snapGuide&&y(b.lines),e.current.style.width=`${b.width}px`,e.current.style.height=`${b.height}px`,e.current.style.transform=`translate(${b.x}px, ${b.y}px) rotate(${v.r}deg)`},[n,a,l,s]),w=z.useCallback((I,k,C,v)=>{const E=s.getState().nodes,P=Dn(v.x,v.y,v.w,v.h,v.r,I,k/a,C/a);let b={...P};if(l.snapping&&(b=Mn(n,P.x,P.y,P.width,P.height,I,E)),l.isLimited){const A=l.width||F.PAGE_WIDTH,M=l.height||F.PAGE_HEIGHT;b.x<0&&(b.width+=b.x,b.x=0),b.y<0&&(b.height+=b.y,b.y=0),b.x+b.width>A&&(b.width=A-b.x),b.y+b.height>M&&(b.height=M-b.y)}s.getState().resizeNode(n,b.x,b.y,b.width,b.height),y([]),u(!1),h(null),r?.()},[n,a,l,s,r]),S=z.useCallback(I=>({onDragStart:()=>{if(!(!i||!t||s.getState().nodes[n]?.locked))return u(!0),h(I),o?.(),x()},onDrag:({movement:[k,C],memo:v})=>{!i||!t||!v||m(I,k,C,v)},onDragEnd:({movement:[k,C],memo:v})=>{!i||!t||!v||w(I,k,C,v)}}),[i,t,x,m,w,o]);return{isResizing:d,activeHandle:f,snapLines:g,createHandleGestures:S}}const Go=({id:n,children:e,className:t="",style:i,draggable:o,resizable:r,rotatable:s,selectable:c,rotationSnap:l,showDragHandle:a=!0,doubleClickToEdit:d,...u})=>{const f=D(T=>T.nodes[n]),h=D(T=>T.nodes),g=D(T=>T.config),y=D(T=>T.camera.zoom),p=D(T=>T.updateNode),x=D(T=>T.setEditingGroup),m=D(T=>T.editingGroupId),w=D(T=>T.selectedIds),S=z.useRef(null),[I,k]=z.useState(!1),C=(T,H)=>T!==void 0?T:H!==void 0?H:!0,v=w.length>1,E=!g.viewOnly,P=C(c,f?.selectable)&&E,b=Lo({elementId:n,canSelect:P}),M=b.isSelected&&!v,R=C(r,f?.resizable)&&E&&!v,K=C(s,f?.rotatable)&&E&&!v,G=d??f?.doubleClickToEdit??!1,N=b.targetId,L=h[N],j=n===m,$=C(L?.draggable,L?.draggable)&&E&&!v&&!j,X=jo({elementId:N,elementRef:S,enabled:$,canInteract:E,isEditing:I,visualElementGetter:()=>N===n?S.current:document.querySelector(`[data-node-id="${N}"]`)}),V=Ro({elementId:n,elementRef:S,enabled:R,canInteract:E});if(z.useEffect(()=>{b.isSelected||k(!1)},[b.isSelected]),z.useEffect(()=>{if(S.current&&f){const T=`translate(${f.x}px, ${f.y}px) rotate(${f.rotation}deg)`;S.current.style.transform!==T&&(S.current.style.transform=T)}},[f?.x,f?.y,f?.rotation,f?.pageId]),!f)return null;const se=[...X.snapLines,...V.snapLines],ee=g.snapGuide&&g.snapping&&(X.isDragging||V.isResizing)&&se.length>0;return _.jsxs(_.Fragment,{children:[ee&&_.jsx(In,{lines:se}),_.jsxs("div",{ref:S,"data-node-id":n,"data-node-type":f?.type||"default",role:"application","aria-label":`${f?.type||"Element"} ${n}`,"aria-selected":b.isSelected,"aria-disabled":!E,tabIndex:b.isSelected&&E?0:-1,className:`ce-element ${b.isSelected?"ce-element--selected":""} ${m===n?"ce-element--editing-active":""} ${f?.type==="group"?"ce-element--group":""} ${t}`,style:{transform:`translate(${f.x}px, ${f.y}px) rotate(${f.rotation}deg)`,width:f.width,height:f.height,zIndex:b.isSelected?100:1,"--ce-inverse-zoom":1/y,...i},...X.bindDrag(),...u,onClick:T=>{T.stopPropagation();const H=T.shiftKey||T.metaKey;if(E){const q=h[N];C(q?.selectable,q?.selectable)&&E&&P&&b.select(H)}},onDoubleClick:T=>{if(E){T.stopPropagation();const H=pi(n,m,h);if(H){x(H);return}G&&k(!0)}},children:[_.jsx("div",{className:"ce-element-content",style:{pointerEvents:G&&!I?"none":"auto"},children:e}),M&&a&&!g.viewOnly&&_.jsx("div",{className:"ce-drag-handle-minimal",role:"button","aria-label":"Drag handle","aria-describedby":"drag-handle-instructions",tabIndex:0,style:{bottom:"calc(-35px * var(--ce-inverse-zoom, 1))",width:"calc(24px * var(--ce-inverse-zoom, 1))",height:"calc(24px * var(--ce-inverse-zoom, 1))"},children:_.jsxs("svg",{viewBox:"0 0 24 24",children:[_.jsx("path",{d:"M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3"}),_.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),_.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"})]})}),M&&R&&!g.viewOnly&&_.jsx(_.Fragment,{children:["nw","ne","sw","se","n","s","e","w"].map(T=>{const H=V.createHandleGestures(T);return _.jsx(_n,{pos:T,onDragStart:()=>(H.onDragStart?.({}),{x:f.x,y:f.y,w:f.width,h:f.height,r:f.rotation||0}),onDragMove:(Z,q,te,ce)=>{H.onDrag?.({movement:[q,te],memo:ce})},onDragEnd:(Z,q,te,ce)=>{H.onDragEnd?.({movement:[q,te],memo:ce})}},T)})}),M&&K&&!g.viewOnly&&_.jsx(Sn,{onDragStart:(T,H)=>{if(!S.current||!f)return{initialAngle:0,initialRotation:0,centerX:0,centerY:0};const Z=S.current.getBoundingClientRect(),q=Z.left+Z.width/2,te=Z.top+Z.height/2;let we=Math.atan2(H-te,T-q)*(180/Math.PI);return we+=90,{initialAngle:we,initialRotation:f.rotation||0,centerX:q,centerY:te}},onDragMove:(T,H,Z)=>{if(!S.current||!f||!Z)return;const q=S.current.getBoundingClientRect(),te=q.left+q.width/2,ce=q.top+q.height/2;let qe=Math.atan2(H-ce,T-te)*(180/Math.PI);qe+=90;const Mt=qe-Z.initialAngle;let le=Z.initialRotation+Mt;const ue=typeof l=="number"?l:g.rotationSnap||0;ue>0&&(le=Math.round(le/ue)*ue),S.current.style.transform=`translate(${f.x}px, ${f.y}px) rotate(${le}deg)`,S.current.__tempRotation=le},onDragEnd:()=>{const T=S.current.__tempRotation;typeof T=="number"&&f&&(p(n,{rotation:T}),delete S.current.__tempRotation)}})]}),X.ghostPreview?.visible&&X.dragTargetPageId&&(()=>{const T=document.querySelector(`[data-page-id="${X.dragTargetPageId}"]`);return T?$n.createPortal(_.jsx("div",{className:"ce-ghost-preview","data-target-page":X.dragTargetPageId,style:{left:X.ghostPreview.x,top:X.ghostPreview.y,width:f.width,height:f.height,transform:`rotate(${f.rotation}deg)`}}),T):null})()]})},Je=z.memo(Go),$o=({page:n,children:e})=>{const t=D(l=>l.dragTargetPageId),i=D(l=>l.activePageId),o=D(l=>l.setEditingGroup),r=D(l=>l.config),s=t===n.id,c=i===n.id;return _.jsxs("div",{className:`ce-page ${s?"ce-page--drag-target":""} ${c?"ce-page--active":""}`,"data-page-id":n.id,style:{width:n.width,height:n.height,backgroundColor:n.backgroundColor||"#ffffff"},onDoubleClick:l=>{r.viewOnly||(l.stopPropagation(),o(null))},children:[e,s&&_.jsx("div",{className:"ce-page__ghost-preview","data-ghost-preview":"true"})]})};function Yo(n,e,t=100){const i={x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2},o=n.x+n.width,r=n.y+n.height,s=i.x+i.width,c=i.y+i.height;return o>=i.x&&n.x<=s&&r>=i.y&&n.y<=c}function _t(n,e){return{x:-n.x/n.zoom,y:-n.y/n.zoom,width:e.width/n.zoom,height:e.height/n.zoom}}function Ho(n,e,t=50){return n.length<t?n:n.filter(i=>{const o={x:i.x,y:i.y,width:i.width,height:i.height};return Yo(o,e)})}function St(n,e,t={enabled:!0,threshold:100,overscan:5}){if(!t.enabled||n.length<t.threshold)return n.map((c,l)=>({node:c,index:l,isVisible:!0}));const i=t.overscan*100,o=t.overscan*100,r={minX:e.x-i,maxX:e.x+e.width+i,minY:e.y-o,maxY:e.y+e.height+o},s=[];return n.forEach((c,l)=>{const a={minX:c.x,maxX:c.x+c.width,minY:c.y,maxY:c.y+c.height},d=a.maxX>=r.minX&&a.minX<=r.maxX&&a.maxY>=r.minY&&a.minY<=r.maxY;s.push({node:c,index:l,isVisible:d})}),s}function It(n){return n.filter(e=>e.isVisible).map(e=>e.node)}function Bo(n){if(n.length===0)return{minX:0,minY:0,maxX:0,maxY:0,width:0,height:0};let e=1/0,t=1/0,i=-1/0,o=-1/0;return n.forEach(r=>{e=Math.min(e,r.x),t=Math.min(t,r.y),i=Math.max(i,r.x+r.width),o=Math.max(o,r.y+r.height)}),{minX:e,minY:t,maxX:i,maxY:o,width:i-e,height:o-t}}function Et(n,e=200){const t=new Map;return n.forEach(i=>{const o=Math.floor(i.x/e),r=Math.floor(i.y/e),s=`${o},${r}`;t.has(s)||t.set(s,[]),t.get(s).push(i)}),t}function Pt(n,e,t=200){const i=[],o=Math.floor(e.x/t),r=Math.floor((e.x+e.width)/t),s=Math.floor(e.y/t),c=Math.floor((e.y+e.height)/t);for(let l=o;l<=r;l++)for(let a=s;a<=c;a++){const d=`${l},${a}`,u=n.get(d);u&&i.push(...u)}return i}const Tn=({id:n,style:e,className:t,nodeTypes:i={}})=>{const o=D(a=>a.nodes),s=D(a=>a.editingGroupId)===n,c=z.useMemo(()=>ye(n,o),[o,n]),l=({data:a,style:d,className:u})=>_.jsx("div",{style:d,className:`ce-default-node ${u||""}`,children:a?.label||"Element"});return _.jsx("div",{style:e,className:`ce-group-node ${s?"ce-group-node--editing":""} ${t||""}`,children:c.map(a=>{const d=i[a.type||"default"]||l;return _.jsx(Je,{id:a.id,draggable:a.draggable,resizable:a.resizable,rotatable:a.rotatable,selectable:a.selectable,showDragHandle:a.showDragHandle,doubleClickToEdit:a.doubleClickToEdit,rotationSnap:a.rotationSnap,children:_.jsx(d,{style:a.style,className:a.className,data:a.data,id:a.id})},a.id)})})},zn=({nodeTypes:n={},pageId:e})=>{const t=D(a=>a.nodes),i=D(a=>a.camera),o=D(a=>a.dimensions),r=D(a=>a.config),s=z.useMemo(()=>{const a=Object.values(t),u=(e?a.filter(y=>y.pageId===e):a).filter(y=>!y.parentId),f=r.virtualization||{},h=f.enabled!==!1,g=f.threshold||100;if(h&&u.length>=g){const y=_t(i,o);if(u.length>1e3){const x=Et(u,200);return Pt(x,y,200)}const p=St(u,y,{enabled:!0,threshold:g,overscan:f.overscan||5});return It(p)}if(r.viewportCulling!==!1&&u.length>50){const y=_t(i,o);return Ho(u,y,50)}return u},[t,e,i,o,r.viewportCulling,r.virtualization]),c=z.useMemo(()=>({...n,group:Tn}),[n]),l=({data:a,style:d,className:u})=>_.jsx("div",{style:d,className:`ce-default-node ${u||""}`,children:a?.label||"Element"});return _.jsx(_.Fragment,{children:s.map(a=>{const d=c[a.type||"default"]||l,u=a.type==="group"?{nodeTypes:c}:{};return _.jsx(Je,{id:a.id,draggable:a.draggable,resizable:a.resizable,rotatable:a.rotatable,selectable:a.selectable,showDragHandle:a.showDragHandle,doubleClickToEdit:a.doubleClickToEdit,rotationSnap:a.rotationSnap,children:_.jsx(d,{style:a.style,className:a.className,data:a.data,id:a.id,...u})},`${a.id}-${a.pageId||"no-page"}`)})})},Xo=(n,e,t)=>{const i={};let o=0;return n.forEach(r=>{i[r]=o;const s=e[r];s&&(o+=s.height+t)}),i},kn=(n,e,t,i)=>{let o=n.x,r=n.y,s=n;for(;s.parentId&&e[s.parentId];){const l=e[s.parentId];o+=l.x,r+=l.y,s=l}const c=t[s.pageId||""]||0;return{x:o+i.x,y:r+c+i.y}},Uo=({bounds:n,pageOffsets:e,canvasOffsets:t})=>{const i=D(p=>p.camera.zoom),o=D(p=>p.config),r=D(p=>p.selectedIds),s=D(p=>p.nodes),c=D(p=>p.pages),l=D(p=>p.pageOrder),a=D(p=>p.nudgeSelected),d=D(p=>p.checkAutoReparent),[u,f]=z.useState([]),[h,g]=z.useState(!1);return{bindDrag:ke({onDragStart:()=>{g(!0)},onDrag:({delta:[p,x]})=>{let m=p/i,w=x/i;if(o.snapping&&!o.isLimited&&n){const S=n.x+m,I=n.y+w,k={};Object.values(s).forEach(v=>{if(!v||r.includes(v.id))return;const E=kn(v,s,e,t);k[v.id]={...v,x:E.x,y:E.y}}),l.forEach(v=>{const E=c[v];if(!E)return;const P=(e[v]||0)+t.y;k[`page-${v}-left`]={id:`page-${v}-left`,x:t.x,y:P,width:0,height:E.height},k[`page-${v}-right`]={id:`page-${v}-right`,x:t.x+E.width,y:P,width:0,height:E.height},k[`page-${v}-center`]={id:`page-${v}-center`,x:t.x+E.width/2,y:P,width:0,height:E.height}});const C=Pn("multi-selection",S,I,n.width,n.height,k,void 0,r);o.snapGuide&&f(C.lines),m=C.x-n.x,w=C.y-n.y}else f([]);a(m,w)},onDragEnd:()=>{g(!1),f([]),d()}}),snapLines:u,isDragging:h}},Fo=({bounds:n})=>{const e=D(c=>c.rotateSelectedBy),t=z.useRef(null),i=z.useCallback((c,l)=>{if(!n)return 0;t.current||(t.current=document.querySelector(".ce-editor__canvas"));const a=t.current;if(!a)return 0;const d=a.getBoundingClientRect(),u=d.width/a.offsetWidth||1,f=n.x+n.width/2,h=n.y+n.height/2,g=d.left+f*u,y=d.top+h*u;return Math.atan2(l-y,c-g)*(180/Math.PI)},[n]),o=z.useRef(0);return{onDragStart:(c,l)=>{if(!n)return o.current=0,{initialAngle:0,initialRotation:0,centerX:0,centerY:0};const a=i(c,l),d=n.x+n.width/2,u=n.y+n.height/2;return o.current=a,{initialAngle:a,initialRotation:n.rotation||0,centerX:d,centerY:u}},onDragMove:(c,l,a)=>{if(!n||!a)return;let d=i(c,l);const u=45,f=5,h=Math.round(d/u)*u;Math.abs(d-h)<f&&(d=h);let g=d-o.current;g>180&&(g-=360),g<-180&&(g+=360),g!==0&&(e(g),o.current=d)}}},Vo=({bounds:n,zoom:e,offsets:t,pageOffsets:i})=>{const o=D(a=>a.selectedIds),r=D(a=>a.nodes),s=D(a=>a.resizeSelectedLocal);return{onDragStart:()=>{const a={};return o.forEach(d=>{const u=r[d];if(u){const f=i[u.pageId||""]||0,h=u.x+t.x,g=u.y+t.y+f;a[d]={x:u.x,y:u.y,w:u.width,h:u.height,r:u.rotation||0,cx:h+u.width/2,cy:g+u.height/2}}}),{initialBounds:{...n},initialNodes:a}},onDragMove:(a,d,u,f)=>{const h=-((n?.rotation||0)*Math.PI)/180,g=Math.cos(h),y=Math.sin(h),p=d/e,x=u/e,m=p*g-x*y,w=p*y+x*g,S=f.initialBounds.width,I=f.initialBounds.height,k=f.initialBounds.x,C=f.initialBounds.y;let v=S,E=I;a.includes("e")&&(v=S+m),a.includes("w")&&(v=S-m),a.includes("s")&&(E=I+w),a.includes("n")&&(E=I-w),v<10&&(v=10),E<10&&(E=10);const P=v/S,b=E/I;let A=0,M=0;a.includes("e")&&(A=0),a.includes("w")&&(A=1),a.includes("s")&&(M=0),a.includes("n")&&(M=1),!a.includes("e")&&!a.includes("w")&&(A=.5),!a.includes("n")&&!a.includes("s")&&(M=.5);const R=S*A,K=I*M,G=k+R,N=C+K,L=k+S/2,j=C+I/2,$=G-L,X=N-j,V=(f.initialBounds.rotation||0)*Math.PI/180,se=Math.cos(V),ee=Math.sin(V),T=$*se-X*ee,H=$*ee+X*se,Z={x:L+T,y:j+H};s(P,b,Z,f.initialBounds.rotation||0,f.initialNodes,t)}}},Wo=()=>{const n=D(w=>w.selectedIds),e=D(w=>w.nodes),t=D(w=>w.pageOrder),i=D(w=>w.pages),o=D(w=>w.camera.zoom),r=D(w=>w.config),s=D(w=>w.dimensions),[c,l]=z.useState({x:0,y:0});z.useEffect(()=>{const w=t[0];if(!w)return;const S=document.querySelector(`.ce-page[data-page-id="${w}"]`);S&&l({x:S.offsetLeft,y:S.offsetTop})},[t,s,o]);const a=z.useMemo(()=>Xo(t,i,r.pageGap||40),[i,t,r.pageGap]),d=z.useMemo(()=>{if(n.length===0)return null;let w=!1,S=null,I=null;for(const ee of n){const T=e[ee];if(T)if(I===null)I=T.rotation||0,S=I;else{const H=T.rotation||0;if(Math.abs(H-I)>.1){S=null;break}}}const k=S||0,C=k*Math.PI/180,v=Math.cos(-C),E=Math.sin(-C);let P=1/0,b=1/0,A=-1/0,M=-1/0;if(n.forEach(ee=>{const T=e[ee];if(!T)return;w=!0;const H=kn(T,e,a,c),Z=H.x,q=H.y,te=(T.rotation||0)*Math.PI/180,ce=Math.cos(te),we=Math.sin(te),qe=Z+T.width/2,Mt=q+T.height/2,le=T.width/2,ue=T.height/2;[{x:-le,y:-ue},{x:le,y:-ue},{x:le,y:ue},{x:-le,y:ue}].forEach(Ze=>{const gs=Ze.x*ce-Ze.y*we,ms=Ze.x*we+Ze.y*ce,Ln=qe+gs,jn=Mt+ms,Rn=Ln*v-jn*E,Gn=Ln*E+jn*v;P=Math.min(P,Rn),b=Math.min(b,Gn),A=Math.max(A,Rn),M=Math.max(M,Gn)})}),!w)return null;const R=2;P-=R,b-=R,A+=R,M+=R;const K=(P+A)/2,G=(b+M)/2,N=A-P,L=M-b,j=k*Math.PI/180,$=Math.cos(j),X=Math.sin(j),V=K*$-G*X,se=K*X+G*$;return{x:V-N/2,y:se-L/2,width:N,height:L,rotation:k}},[n,e,t,r.pageGap,c,a]),{bindDrag:u,snapLines:f,isDragging:h}=Uo({bounds:d,pageOffsets:a,canvasOffsets:c}),{onDragStart:g,onDragMove:y}=Fo({bounds:d}),{onDragStart:p,onDragMove:x}=Vo({bounds:d,zoom:o,offsets:c,pageOffsets:a});if(n.length<2||!d)return null;const m=r.snapGuide&&r.snapping&&h&&f.length>0;return _.jsxs(_.Fragment,{children:[m&&_.jsx(In,{lines:f}),_.jsx("div",{className:"ce-selection-overlay",children:_.jsxs("div",{className:"ce-selection-overlay__box",style:{left:d.x,top:d.y,width:d.width,height:d.height,transform:`rotate(${d.rotation}deg)`,borderWidth:"calc(2px * var(--ce-inverse-zoom, 1))",borderRadius:"calc(4px * var(--ce-inverse-zoom, 1))","--ce-inverse-zoom":1/o},children:[r.rotation&&!r.viewOnly&&_.jsx(Sn,{style:{"--ce-inverse-zoom":1/o,pointerEvents:"auto"},onDragStart:g,onDragMove:y,onDragEnd:()=>{}}),!r.viewOnly&&_.jsx(_.Fragment,{children:["nw","n","ne","e","se","s","sw","w"].map(w=>_.jsx(_n,{pos:w,style:{"--ce-inverse-zoom":1/o,position:"absolute",zIndex:10,pointerEvents:"auto"},onDragStart:p,onDragMove:x,onDragEnd:()=>{}},w))}),_.jsx("div",{...u(),className:"ce-drag-handle-minimal",style:{"--ce-inverse-zoom":1/o,pointerEvents:"auto"},onClick:w=>{w.stopPropagation()},children:_.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[_.jsx("path",{d:"M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3"}),_.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),_.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"})]})})]})})]})},Ko=()=>{const n=D(a=>a.editingGroupId),e=D(a=>a.nodes),t=D(a=>a.setEditingGroup),i=D(a=>a.config);if(!n||i.viewOnly)return null;const o=e[n];if(!o||o.type!=="group")return null;const r=[];let s=o;for(;s;)r.unshift({id:s.id,name:s.data?.name||`Group ${s.id.slice(-4)}`}),s.parentId?s=e[s.parentId]:s=void 0;const c=a=>{a.stopPropagation(),t(null)},l=(a,d)=>{d.stopPropagation(),a!==n&&t(a)};return _.jsxs("div",{className:"ce-group-editor",onClick:a=>a.stopPropagation(),children:[_.jsx("div",{className:"ce-group-editor__breadcrumbs",children:r.map((a,d)=>_.jsxs(z.Fragment,{children:[d>0&&_.jsx("span",{className:"ce-group-editor__separator",children:"/"}),_.jsx("button",{onClick:u=>l(a.id,u),className:`ce-group-editor__breadcrumb ${d===r.length-1?"ce-group-editor__breadcrumb--active":""}`,children:a.name})]},a.id))}),_.jsxs("button",{onClick:c,className:"ce-group-editor__exit-button",children:[_.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:_.jsx("path",{d:"M18 6L6 18M6 6l12 12"})}),"Exit Group"]})]})},Cn=()=>_.jsxs("div",{className:"ce-accessibility-instructions",children:[_.jsx("div",{id:"canvas-instructions",children:"Design canvas editor. Use arrow keys to move selected elements. Press Tab to navigate between elements. Press Enter to edit groups."}),_.jsx("div",{id:"resize-handle-instructions",children:"Drag to resize element. Use Shift to maintain aspect ratio."}),_.jsx("div",{id:"rotate-handle-instructions",children:"Drag to rotate element. Use Shift to snap to 15 degree increments."}),_.jsx("div",{id:"drag-handle-instructions",children:"Drag to move element. Use arrow keys for precise movement."})]}),Jo=({children:n,grid:e,background:t,className:i="",style:o,canvasStyle:r,nodeTypes:s})=>{const c=z.useRef(null),l=D(m=>m.camera),a=D(m=>m.config),d=D(m=>m.pages),u=D(m=>m.pageOrder),f=D(m=>m.setDimensions),h=D(m=>m.dimensions),g=D(m=>m.editingGroupId),y=fe();z.useEffect(()=>{const m=()=>{if(c.current){const w=c.current.getBoundingClientRect();f(w.width,w.height)}};return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[f]),z.useEffect(()=>{const m=S=>{(S.ctrlKey||S.metaKey)&&S.preventDefault()},w=c.current;return w&&w.addEventListener("wheel",m,{passive:!1}),()=>{w&&w.removeEventListener("wheel",m)}},[]);const p=m=>{if(!a.zoom)return;const w=1-m/500;let S=l.zoom*w;if(h.width>0&&h.height>0){const I=u.reduce((v,E)=>{const P=d[E];return v+(P?.height||0)},0)+(u.length-1)*(a.pageGap||40)+80,k=h.height/I,C=Math.max(a.minZoom||.1,k);S=Math.max(C,Math.min(a.maxZoom||5,S))}else S=Math.max(a.minZoom||.1,Math.min(a.maxZoom||5,S));y.getState().setCamera(0,0,S)};ke({onWheel:({event:m,delta:[,w],ctrlKey:S})=>{(S||m.metaKey)&&(m.preventDefault(),p(w))}},{target:c,wheel:{eventOptions:{passive:!1}}});const x=()=>{a.viewOnly||(y.getState().deselectAll(),y.getState().setEditingGroup(null))};return _.jsxs("div",{ref:c,className:`ce-editor__viewport ${i} ${a.viewOnly?"ce-editor--view-only":""} ${g?"ce-editor--editing-group":""}`,role:"application","aria-label":"Design canvas editor","aria-describedby":"canvas-instructions",style:o,onClick:x,onDoubleClick:()=>{a.viewOnly||y.getState().setEditingGroup(null)},children:[t,_.jsx("div",{className:"ce-editor__scale-wrapper",children:_.jsxs("div",{className:"ce-editor__canvas",style:{transform:`scale(${l.zoom})`,gap:`${a.pageGap||40}px`,...r},children:[a.showGrid&&_.jsx("div",{className:"ce-editor__grid-layer",children:e||_.jsxs("svg",{width:"100%",height:"100%",children:[_.jsx("defs",{children:_.jsx("pattern",{id:"page-grid",width:a.gridSize||20,height:a.gridSize||20,patternUnits:"userSpaceOnUse",children:_.jsx("circle",{cx:"1",cy:"1",r:"1",fill:a.gridColor||"#ddd"})})}),_.jsx("rect",{width:"100%",height:"100%",fill:"url(#page-grid)"})]})}),u.map(m=>{const w=d[m];return w?_.jsx($o,{page:w,children:_.jsx(zn,{pageId:m,nodeTypes:s})},m):null}),_.jsx(Wo,{})]})}),_.jsx(Cn,{}),n,_.jsx(Ko,{})]})},qo=()=>{const n=D(i=>i.nodes),e=z.useMemo(()=>Object.values(n).map(i=>i.customCss),[n]),t=z.useMemo(()=>e.filter(Boolean).join(`
|
|
8
|
+
`),[e]);return t?_.jsx("style",{children:t}):null},Zo=({data:n})=>_.jsxs("div",{className:"demo-node",children:[_.jsx("div",{className:"demo-node__header",children:n.title||"Untitled"}),_.jsx("div",{className:"demo-node__body",children:"Design Node"})]});function Qo(n,e={width:200,height:150},t){const i=n.getState(),o=t||i.pageOrder[0],r=i.pages[o];if(!r)return{x:100,y:100,pageId:o};const s=r.width/2,c=r.height/2,l=s-e.width/2,a=c-e.height/2;return{x:l,y:a,pageId:o}}const es={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};class ts{config;initialized=!1;constructor(){let e=!1,t="unknown";try{typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"&&es&&(e=!0,t="unknown")}catch{e=!0}this.config={enabled:e,environment:e?"production":"development",release:t}}init(e){this.initialized||(this.config={...this.config,...e},this.config.enabled&&(this.config.dsn&&typeof window<"u"&&this.initSentry(),this.initialized=!0))}initSentry(){if(typeof window>"u")return;const e=window.Sentry;if(!e||!this.config.dsn){try{typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"}catch{}return}try{e.init({dsn:this.config.dsn,environment:this.config.environment,release:this.config.release,tracesSampleRate:.1,replaysSessionSampleRate:.1,replaysOnErrorSampleRate:1})}catch{try{typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"}catch{}}}captureException(e,t){if(this.config.enabled)if(typeof window<"u"&&window.Sentry)window.Sentry.captureException(e,{extra:t});else try{typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"}catch{}}captureMessage(e,t="info",i){if(this.config.enabled)if(typeof window<"u"&&window.Sentry)window.Sentry.captureMessage(e,t,{extra:i});else try{typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("flow-canvas.umd.js",document.baseURI).href}<"u"}catch{}}setUser(e){typeof window<"u"&&window.Sentry&&window.Sentry.setUser(e)}clearUser(){typeof window<"u"&&window.Sentry&&window.Sentry.setUser(null)}}const An=new ts;typeof window<"u"&&An.init({dsn:void 0,enabled:!0});class ns{metrics=[];maxMetrics=100;enabled=!1;measure(e,t,i){if(!this.enabled)return t();const o=performance.now(),r=t(),c=performance.now()-o;return this.recordMetric(e,c,i),r}async measureAsync(e,t,i){if(!this.enabled)return t();const o=performance.now(),r=await t(),c=performance.now()-o;return this.recordMetric(e,c,i),r}recordMetric(e,t,i){const o={name:e,duration:t,timestamp:Date.now(),metadata:i};this.metrics.push(o),this.metrics.length>this.maxMetrics&&this.metrics.shift(),t>16&&console.warn(`[Performance] Slow operation: ${e} took ${t.toFixed(2)}ms`,i)}getMetrics(){return[...this.metrics]}getAverageDuration(e){const t=this.metrics.filter(o=>o.name===e);return t.length===0?0:t.reduce((o,r)=>o+r.duration,0)/t.length}clearMetrics(){this.metrics=[]}enable(){this.enabled=!0}disable(){this.enabled=!1}}const is=new ns;class os{templates=new Map;storageKey="flow-canvas-templates";loadTemplates(){if(!(typeof window>"u"))try{const e=localStorage.getItem(this.storageKey);if(e){const t=JSON.parse(e);t.forEach(i=>{this.templates.set(i.id,i)}),B.debug(`Loaded ${t.length} templates from storage`)}}catch(e){B.error("Failed to load templates",e)}}saveTemplates(){if(!(typeof window>"u"))try{const e=Array.from(this.templates.values());localStorage.setItem(this.storageKey,JSON.stringify(e)),B.debug(`Saved ${e.length} templates to storage`)}catch(e){B.error("Failed to save templates",e)}}saveTemplate(e){this.templates.set(e.id,{...e,metadata:{...e.metadata,updatedAt:Date.now(),createdAt:e.metadata?.createdAt||Date.now()}}),this.saveTemplates(),B.info(`Template saved: ${e.name}`)}getTemplate(e){return this.templates.get(e)}getAllTemplates(){return Array.from(this.templates.values())}getTemplatesByCategory(e){return this.getAllTemplates().filter(t=>t.category===e)}deleteTemplate(e){const t=this.templates.delete(e);return t&&(this.saveTemplates(),B.info(`Template deleted: ${e}`)),t}createTemplateFromState(e,t,i){const o={id:`template-${Date.now()}`,name:e,description:i?.description,category:i?.category,thumbnail:i?.thumbnail,nodes:Object.values(t.nodes),pages:Object.values(t.pages),pageOrder:t.pageOrder,metadata:{createdAt:Date.now(),updatedAt:Date.now()}};return this.saveTemplate(o),o}applyTemplate(e){const t=this.getTemplate(e);return t?(B.info(`Applying template: ${t.name}`),t):(B.warn(`Template not found: ${e}`),null)}}const On=new os;typeof window<"u"&&On.loadTemplates();class ss{assets=new Map;categories=new Map;storageKey="flow-canvas-assets";loadAssets(){if(!(typeof window>"u"))try{const e=localStorage.getItem(this.storageKey);if(e){const t=JSON.parse(e);t.assets?.forEach(i=>{this.assets.set(i.id,i)}),t.categories?.forEach(i=>{this.categories.set(i.id,i)}),B.debug(`Loaded ${t.assets?.length||0} assets from storage`)}}catch(e){B.error("Failed to load assets",e)}}saveAssets(){if(!(typeof window>"u"))try{const e={assets:Array.from(this.assets.values()),categories:Array.from(this.categories.values())};localStorage.setItem(this.storageKey,JSON.stringify(e)),B.debug(`Saved ${e.assets.length} assets to storage`)}catch(e){B.error("Failed to save assets",e)}}addAsset(e){this.assets.set(e.id,{...e,metadata:{...e.metadata,createdAt:e.metadata?.createdAt||Date.now()}}),this.saveAssets(),B.info(`Asset added: ${e.name}`)}getAsset(e){return this.assets.get(e)}getAllAssets(){return Array.from(this.assets.values())}getAssetsByType(e){return this.getAllAssets().filter(t=>t.type===e)}getAssetsByCategory(e){return this.getAllAssets().filter(t=>t.category===e)}searchAssets(e){const t=e.toLowerCase();return this.getAllAssets().filter(i=>i.name.toLowerCase().includes(t)||i.tags?.some(o=>o.toLowerCase().includes(t))||i.category?.toLowerCase().includes(t))}deleteAsset(e){const t=this.assets.delete(e);return t&&(this.saveAssets(),B.info(`Asset deleted: ${e}`)),t}addCategory(e){this.categories.set(e.id,e),this.saveAssets()}getAllCategories(){return Array.from(this.categories.values())}deleteCategory(e){const t=this.categories.delete(e);return t&&(this.saveAssets(),B.info(`Category deleted: ${e}`)),t}async createAssetFromUrl(e,t){const i={id:`asset-${Date.now()}`,name:t.name,type:t.type,url:e,category:t.category,tags:t.tags,metadata:{createdAt:Date.now()}};if(t.type==="image")try{const o=new Image;await new Promise((r,s)=>{o.onload=r,o.onerror=s,o.src=e}),i.metadata={...i.metadata,width:o.width,height:o.height}}catch(o){B.warn("Failed to load image dimensions",o)}return this.addAsset(i),i}}const Nn=new ss;typeof window<"u"&&Nn.loadAssets();function rs(n={}){const{enabled:e=!0,interval:t=3e4,storageKey:i="flow-canvas-autosave",onSave:o,onError:r}=n,s=fe(),c=z.useRef(0),l=z.useRef(null),a=async()=>{try{const h=s.getState(),g={nodes:Object.values(h.nodes),pages:Object.values(h.pages),pageOrder:h.pageOrder,camera:h.camera,config:h.config,timestamp:Date.now()};typeof window<"u"&&i&&(localStorage.setItem(i,JSON.stringify(g)),B.debug("Auto-save: State saved to localStorage")),o&&(await o(h),B.debug("Auto-save: Custom save handler executed")),c.current=Date.now()}catch(h){const g=h instanceof Error?h:new Error(String(h));B.error("Auto-save failed",g),r?.(g)}};return z.useEffect(()=>{if(!e){l.current&&(clearTimeout(l.current),l.current=null);return}const h=()=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{a(),h()},t)};return h(),()=>{l.current&&clearTimeout(l.current),a()}},[e,t,i,o,r]),{manualSave:()=>{a()},loadSavedState:()=>{if(typeof window>"u"||!i)return null;try{const h=localStorage.getItem(i);if(!h)return null;const g=JSON.parse(h);return B.debug("Auto-save: Loaded state from localStorage",{timestamp:g.timestamp,nodeCount:g.nodes?.length||0}),g}catch(h){return B.error("Auto-save: Failed to load saved state",h),null}},clearSavedState:()=>{typeof window<"u"&&i&&(localStorage.removeItem(i),B.debug("Auto-save: Cleared saved state"))},lastSaveTime:c.current}}const as=({nodeTypes:n={},pageId:e})=>{const t=D(p=>p.nodes),i=D(p=>p.camera),o=D(p=>p.dimensions),r=D(p=>p.config),s=z.useRef(null),[c,l]=z.useState([]),a=z.useMemo(()=>{const p=Object.values(t);return(e?p.filter(m=>m.pageId===e):p).filter(m=>!m.parentId)},[t,e]),d=z.useMemo(()=>_t(i,o),[i,o]),u=r.virtualization||{},f=u.enabled!==!1,h=u.threshold||100;z.useEffect(()=>{if(!f||a.length<h){l(a);return}if(a.length>1e3){const x=Et(a,200),m=Pt(x,d,200);l(m);return}const p=St(a,d,{enabled:!0,threshold:h,overscan:u.overscan||5});l(It(p))},[a,d,f,h,u.overscan]);const g=z.useMemo(()=>({...n,group:Tn}),[n]),y=({data:p,style:x,className:m})=>_.jsx("div",{style:x,className:`ce-default-node ${m||""}`,children:p?.label||"Element"});return _.jsxs("div",{ref:s,className:"ce-virtualized-container",children:[c.map(p=>{const x=g[p.type||"default"]||y,m=p.type==="group"?{nodeTypes:g}:{};return _.jsx(Je,{id:p.id,draggable:p.draggable,resizable:p.resizable,rotatable:p.rotatable,selectable:p.selectable,showDragHandle:p.showDragHandle,doubleClickToEdit:p.doubleClickToEdit,rotationSnap:p.rotationSnap,children:_.jsx(x,{style:p.style,className:p.className,data:p.data,id:p.id,...m})},`${p.id}-${p.pageId||"no-page"}`)}),!1]})};class cs{static calculateDragPosition(e,t,i,o){const[r,s]=t;let c=e.x+r/i,l=e.y+s/i;return o&&(o.minX!==void 0&&(c=Math.max(o.minX,c)),o.minY!==void 0&&(l=Math.max(o.minY,l)),o.maxX!==void 0&&(c=Math.min(o.maxX,c)),o.maxY!==void 0&&(l=Math.min(o.maxY,l))),{x:c,y:l}}static calculateResize(e,t,i,o,r,s=0,c){const[l,a]=i,d=l/r,u=a/r;if(s!==0){const f=s*Math.PI/180,h=Math.cos(f),g=Math.sin(f),y=d*h+u*g,p=-d*g+u*h;return this.applyHandleResize(e,t,[y,p],o,c)}return this.applyHandleResize(e,t,[d,u],o,c)}static applyHandleResize(e,t,i,o,r){const[s,c]=i;let l=e.x,a=e.y,d=t.width,u=t.height;o.includes("e")&&(d+=s),o.includes("w")&&(d-=s,l+=s),o.includes("s")&&(u+=c),o.includes("n")&&(u-=c,a+=c);const f=r?.minWidth??10,h=r?.minHeight??10,g=r?.maxWidth??1/0,y=r?.maxHeight??1/0;if(d=Math.max(f,Math.min(g,d)),u=Math.max(h,Math.min(y,u)),r?.aspectRatio){const p=r.aspectRatio;o.includes("e")||o.includes("w")?u=d/p:(o.includes("n")||o.includes("s"))&&(d=u*p)}return{position:{x:l,y:a},size:{width:d,height:u}}}static calculateRotation(e,t,i=0){const o=t.x-e.x,r=t.y-e.y;let c=Math.atan2(r,o)*180/Math.PI+90;return c=(c%360+360)%360,i>0&&(c=Math.round(c/i)*i),c}static getElementCenter(e,t){return{x:e.x+t.width/2,y:e.y+t.height/2}}static getRotatedBounds(e,t,i){if(i===0)return{...e,...t};const o=i*Math.PI/180,r=Math.abs(Math.cos(o)),s=Math.abs(Math.sin(o)),c=t.width*r+t.height*s,l=t.width*s+t.height*r,a=this.getElementCenter(e,t);return{x:a.x-c/2,y:a.y-l/2,width:c,height:l}}}class ls{static findSnapLines(e,t,i=F.SNAP_THRESHOLD){const o=[],{x:r,y:s,width:c,height:l,pageId:a}=e,d=r,u=r+c,f=r+c/2,h=s,g=s+l,y=s+l/2;return Object.values(t).forEach(p=>{if(p.id===e.id||p.pageId!==a)return;const{x,y:m,width:w,height:S}=p,I=x,k=x+w,C=x+w/2,v=m,E=m+S,P=m+S/2;Math.abs(d-I)<i&&o.push({id:`v-${p.id}-left`,type:"vertical",position:I,pageId:a||""}),Math.abs(u-k)<i&&o.push({id:`v-${p.id}-right`,type:"vertical",position:k,pageId:a||""}),Math.abs(f-C)<i&&o.push({id:`v-${p.id}-center`,type:"vertical",position:C,pageId:a||""}),Math.abs(d-k)<i&&o.push({id:`v-${p.id}-edge-r`,type:"vertical",position:k,pageId:a||""}),Math.abs(u-I)<i&&o.push({id:`v-${p.id}-edge-l`,type:"vertical",position:I,pageId:a||""}),Math.abs(h-v)<i&&o.push({id:`h-${p.id}-top`,type:"horizontal",position:v,pageId:a||""}),Math.abs(g-E)<i&&o.push({id:`h-${p.id}-bottom`,type:"horizontal",position:E,pageId:a||""}),Math.abs(y-P)<i&&o.push({id:`h-${p.id}-center`,type:"horizontal",position:P,pageId:a||""}),Math.abs(h-E)<i&&o.push({id:`h-${p.id}-edge-b`,type:"horizontal",position:E,pageId:a||""}),Math.abs(g-v)<i&&o.push({id:`h-${p.id}-edge-t`,type:"horizontal",position:v,pageId:a||""})}),o}static applySnap(e,t,i,o=F.SNAP_THRESHOLD){let{x:r,y:s}=e;const c=r,l=r+t.width,a=r+t.width/2,d=s,u=s+t.height,f=s+t.height/2,h=i.filter(x=>x.type==="vertical");let g=o;h.forEach(x=>{const m=Math.abs(c-x.position),w=Math.abs(l-x.position),S=Math.abs(a-x.position);m<g?(g=m,r=x.position):w<g?(g=w,r=x.position-t.width):S<g&&(g=S,r=x.position-t.width/2)});const y=i.filter(x=>x.type==="horizontal");let p=o;return y.forEach(x=>{const m=Math.abs(d-x.position),w=Math.abs(u-x.position),S=Math.abs(f-x.position);m<p?(p=m,s=x.position):w<p?(p=w,s=x.position-t.height):S<p&&(p=S,s=x.position-t.height/2)}),{x:r,y:s}}static getActiveSnapLines(e,t,i=F.SNAP_THRESHOLD){const o=this.findSnapLines(e,t,i),r=o.filter(l=>l.type==="vertical"),s=o.filter(l=>l.type==="horizontal"),c=[];if(r.length>0){const l=r.reduce((a,d)=>{const u=Math.abs(e.x-a.position);return Math.abs(e.x-d.position)<u?d:a});c.push(l)}if(s.length>0){const l=s.reduce((a,d)=>{const u=Math.abs(e.y-a.position);return Math.abs(e.y-d.position)<u?d:a});c.push(l)}return c}}class ds{static getPageAtPosition(e,t,i,o=F.PAGE_GAP){let r=0;for(const s of i){const c=t[s];if(!c)continue;const l=r,a=r+c.height;if(e>=l&&e<=a)return s;r+=c.height+o}return null}static calculatePageOffset(e,t,i,o=F.PAGE_GAP){let r=0;for(const s of i){if(s===e)return r;const c=t[s];c&&(r+=c.height+o)}return r}static isWithinPageBounds(e,t){const{x:i,y:o,width:r,height:s}=e;return i>=0&&o>=0&&i+r<=t.width&&o+s<=t.height}static isPartiallyWithinPageBounds(e,t){const{x:i,y:o,width:r,height:s}=e;return!(i+r<0||o+s<0||i>t.width||o>t.height)}static constrainToPageBounds(e,t,i){return{x:Math.max(0,Math.min(e.x,i.width-t.width)),y:Math.max(0,Math.min(e.y,i.height-t.height))}}static convertPositionBetweenPages(e,t,i,o,r,s=F.PAGE_GAP){const c=this.calculatePageOffset(t,o,r,s),l=this.calculatePageOffset(i,o,r,s),a=e.y+c;return{x:e.x,y:a-l}}static getTotalHeight(e,t,i=F.PAGE_GAP){if(t.length===0)return 0;let o=0;return t.forEach((r,s)=>{const c=e[r];c&&(o+=c.height,s<t.length-1&&(o+=i))}),o}static getMaxWidth(e){return Math.max(...Object.values(e).map(t=>t.width),0)}static getPageByElementCenter(e,t,i,o=F.PAGE_GAP){if(!e.pageId)return null;const s=this.calculatePageOffset(e.pageId,t,i,o)+e.y+e.height/2;return this.getPageAtPosition(s,t,i,o)}}class us{static getChildren(e,t){return Object.values(t).filter(i=>i.parentId===e)}static getDescendants(e,t){const i=[];return this.getChildren(e,t).forEach(r=>{i.push(r),r.type==="group"&&i.push(...this.getDescendants(r.id,t))}),i}static calculateBounds(e){if(e.length===0)return{x:0,y:0,width:100,height:100};let t=1/0,i=1/0,o=-1/0,r=-1/0;return e.forEach(s=>{t=Math.min(t,s.x),i=Math.min(i,s.y),o=Math.max(o,s.x+s.width),r=Math.max(r,s.y+s.height)}),{x:t,y:i,width:o-t,height:r-i}}static findTargetGroupToEnter(e,t,i){const o=i[e];if(!o)return null;if(!t)return o.type==="group"?o.id:null;let r=o;for(;r.parentId&&r.parentId!==t;){const s=i[r.parentId];if(!s)break;r=s}return r.parentId===t&&r.type==="group"?r.id:null}static findAncestorInEditScope(e,t,i){const o=i[e];if(!o)return null;if(o.parentId===t)return e;let r=o;for(;r.parentId&&r.parentId!==t;){const s=i[r.parentId];if(!s)return null;r=s}return r.parentId===t?r.id:null}}class fs{id;bounds;rotation;pageId;parentId;type;data;constructor(e,t,i=0,o,r,s,c){this.id=e,this.bounds=t,this.rotation=i,this.pageId=o,this.parentId=r,this.type=s,this.data=c}getCenter(){return{x:this.bounds.x+this.bounds.width/2,y:this.bounds.y+this.bounds.height/2}}getRotatedBounds(){if(this.rotation===0)return{...this.bounds};const e=this.rotation*Math.PI/180,t=Math.abs(Math.cos(e)),i=Math.abs(Math.sin(e)),o=this.bounds.width*t+this.bounds.height*i,r=this.bounds.width*i+this.bounds.height*t,s=this.getCenter();return{x:s.x-o/2,y:s.y-r/2,width:o,height:r}}containsPoint(e,t){return e>=this.bounds.x&&e<=this.bounds.x+this.bounds.width&&t>=this.bounds.y&&t<=this.bounds.y+this.bounds.height}getTransform(){return{position:{x:this.bounds.x,y:this.bounds.y},size:{width:this.bounds.width,height:this.bounds.height},rotation:this.rotation}}applyTransform(e){e.position&&(this.bounds.x=e.position.x,this.bounds.y=e.position.y),e.size&&(this.bounds.width=e.size.width,this.bounds.height=e.size.height),e.rotation!==void 0&&(this.rotation=e.rotation)}}class hs{id;dimensions;backgroundColor;name;constructor(e,t,i="#ffffff",o){this.id=e,this.dimensions=t,this.backgroundColor=i,this.name=o}getArea(){return this.dimensions.width*this.dimensions.height}containsPoint(e,t){return e>=0&&e<=this.dimensions.width&&t>=0&&t<=this.dimensions.height}containsBounds(e,t,i,o){return e>=0&&t>=0&&e+i<=this.dimensions.width&&t+o<=this.dimensions.height}constrainPosition(e,t,i,o){return{x:Math.max(0,Math.min(e,this.dimensions.width-i)),y:Math.max(0,Math.min(t,this.dimensions.height-o))}}}class ps{x;y;zoom;constructor(e=0,t=0,i=1){this.x=e,this.y=t,this.zoom=i}pan(e,t){this.x+=e,this.y+=t}zoomAt(e,t,i){const o=this.zoom*e,r=t-(t-this.x)*(o/this.zoom),s=i-(i-this.y)*(o/this.zoom);this.zoom=o,this.x=r,this.y=s}screenToWorld(e,t){return{x:(e-this.x)/this.zoom,y:(t-this.y)/this.zoom}}worldToScreen(e,t){return{x:e*this.zoom+this.x,y:t*this.zoom+this.y}}getState(){return{x:this.x,y:this.y,zoom:this.zoom}}setState(e){e.x!==void 0&&(this.x=e.x),e.y!==void 0&&(this.y=e.y),e.zoom!==void 0&&(this.zoom=e.zoom)}}O.AccessibilityInstructions=Cn,O.Camera=ps,O.Canvas=Jo,O.DemoNodeContent=Zo,O.Editor=wi,O.Element=fs,O.ElementWrapper=Je,O.GroupService=us,O.NodeLayer=zn,O.Page=hs,O.PageService=ds,O.SnapService=ls,O.StyleInjector=qo,O.TransformService=cs,O.VirtualizedNodeLayer=as,O.assetLibrary=Nn,O.calculateTotalBounds=Bo,O.errorReporter=An,O.getSpawnPosition=Qo,O.getVisibleCells=Pt,O.getVisibleNodes=It,O.logger=B,O.optimizeForVirtualization=Et,O.performanceMonitor=is,O.templateManager=On,O.useAutoSave=rs,O.useEditor=D,O.useEditorStoreApi=fe,O.virtualizeNodes=St,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})}));
|