@hy-bricks/canvas 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- !function(){"use strict";try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode(".hc-canvas-stage[data-v-825e0ee8]{position:relative;width:100%;height:100%;overflow:hidden;background:#f1f5f9;isolation:isolate}.hc-canvas-stage__world[data-v-825e0ee8]{position:absolute;top:0;left:0;will-change:transform}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}}();
2
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@hy-bricks/core"),t=new Map,o=new Set;function i(e,n){const t=[...o];for(const o of t)try{o(e,n)}catch{}}function a(e,n){t.has(e)&&console.warn(`[hc-rendererDiagnostics] canvasId "${e}" already registered, overwriting`),t.set(e,n),i("register",e)}function r(e){t.has(e)&&(t.delete(e),i("unregister",e))}function s(e){return JSON.parse(JSON.stringify(e))}const c="[hc-canvas/normalizeBindings]";function d(e){if(!Array.isArray(e))return[];const n=[];for(let t=0;t<e.length;t++){const o=e[t];if(!o||"object"!=typeof o){console.warn(`${c} dropped non-object binding at index ${t}`);continue}if(l(o)){n.push(o);continue}const i=u(o);null!==i&&n.push(i)}return n}function l(e){if(!e||"object"!=typeof e)return!1;const n=e;if("string"!=typeof n.id||0===n.id.length)return!1;if("event"!==n.type&&"init"!==n.type&&"data"!==n.type)return!1;const t=n.source;if(!t||"object"!=typeof t)return!1;if("string"!=typeof t.kind)return!1;const o=n.target;return!(!o||"object"!=typeof o)&&"string"==typeof o.kind}function u(e){if("string"!=typeof e.id||0===e.id.length)return console.warn(`${c} dropped binding with missing/invalid id`),null;const n=e.target;if(!n||"object"!=typeof n||"string"!=typeof n.instanceId||""===n.instanceId||"string"!=typeof n.method)return console.warn(`${c} dropped binding "${e.id}" missing/invalid target`),null;const t=e.type;let o;if("event"===t){const n=e.source;if(!n||"object"!=typeof n||"string"!=typeof n.instanceId||""===n.instanceId||"string"!=typeof n.event)return console.warn(`${c} dropped event binding "${e.id}" missing/invalid source`),null;o={kind:"instanceEvent",instanceId:n.instanceId,event:n.event}}else{if("init"!==t)return console.warn(`${c} dropped binding "${e.id}" with unknown legacy type "${String(e.type)}"`),null;{const n=e.source;n&&"string"==typeof n.instanceId&&""!==n.instanceId&&console.warn(`${c} init binding "${e.id}" had source.instanceId, discarded`),o={kind:"page",hook:"pageInit"}}}const i={kind:"instanceMethod",instanceId:n.instanceId,method:n.method};let a;a=void 0===n.args?{kind:"passthrough"}:Array.isArray(n.args)&&0===n.args.length?{kind:"static",args:[]}:Array.isArray(n.args)?{kind:"static",args:s(n.args)}:{kind:"passthrough"};const r={},d=e.options;d&&"object"==typeof d&&(!0===d.once&&(r.once=!0),"number"==typeof d.throttleMs&&(r.throttle={windowMs:d.throttleMs}),"number"==typeof d.debounceMs&&(r.debounce={windowMs:d.debounceMs}));const l=void 0!==r.once||void 0!==r.throttle||void 0!==r.debounce,u={id:e.id,source:o,target:i,mapping:a,...void 0!==e.disabled?{disabled:e.disabled}:{},...l?{schedule:r}:{}};return"event"===t?{...u,type:"event"}:{...u,type:"init"}}function p(e){const n=e.instances.map(v),t=m(e.componentOverrides,n),o=d(e.bindings);if("1"===e.schemaVersion){const i=F(B(e.layout)?e.layout:S(e.layout));return{...e,layout:i,instances:n,bindings:o,componentOverrides:t}}return{schemaVersion:"1",layout:F(S(e.layout)),instances:n,bindings:o,componentOverrides:t}}function f(e){const n=function(e){var n;const t=new Map;for(const o of e){if(!o.parentId)continue;if(void 0!==o.slot)continue;const e=t.get(o.parentId),i=null==(n=o.layoutItem)?void 0:n.ratio;e?e.push(i):t.set(o.parentId,[i])}let o=!1;const i=e.map(e=>{if(!e.containerLayout||"split"!==e.containerLayout.mode)return e;const n=t.get(e.instanceId)??[],i=e.containerLayout.ratios,a=k(i,n);return i.length===a.length&&i.every((e,n)=>e===a[n])?e:(o=!0,{...e,containerLayout:{...e.containerLayout,ratios:a}})});return o?i:e}(e.instances),t=e.layout.rootLayout?function(e,n){const t=e.rootLayout;if(!t||"split"!==t.mode)return e;const o=n.filter(e=>void 0===e.parentId).map(e=>{var n;return null==(n=e.layoutItem)?void 0:n.ratio}),i=t.ratios,a=k(i,o);return i.length===a.length&&i.every((e,n)=>e===a[n])?e:{...e,rootLayout:{...t,ratios:a}}}(e.layout,n):e.layout;return n===e.instances&&t===e.layout?e:{...e,layout:t,instances:n}}function h(e){const n=new Map,t=new Set;for(const o of e.instances){const e=o.containerLayout;if("grid"!==(null==e?void 0:e.mode))continue;t.add(o.instanceId);const i=e.cells;i&&"object"==typeof i&&Object.keys(i).length>0&&n.set(o.instanceId,g(i))}if(0===t.size)return e;let o=!1;const i=e.instances.map(e=>{if(!e.parentId)return e;if(void 0!==e.slot)return e;if(!t.has(e.parentId))return e;const i=e.layoutItem;if(i&&("number"==typeof i.row||"number"==typeof i.column)){const n=function(e){const n="number"==typeof e.row&&Number.isFinite(e.row)&&e.row<1,t="number"==typeof e.column&&Number.isFinite(e.column)&&e.column<1;if(!n&&!t)return e;const o={...e};return n&&(o.row=1),t&&(o.column=1),o}(i);return n===i?e:(o=!0,{...e,layoutItem:n})}const a=n.get(e.parentId),r=null==a?void 0:a[e.instanceId];if(!r)return e;const s=function(e){const n={};return"number"==typeof e.row&&Number.isFinite(e.row)&&(n.row=e.row<1?1:e.row),"number"==typeof e.column&&Number.isFinite(e.column)&&(n.column=e.column<1?1:e.column),void 0===n.row&&void 0===n.column?null:("number"==typeof e.rowSpan&&Number.isFinite(e.rowSpan)&&e.rowSpan>0&&e.rowSpan<=32&&(n.rowSpan=e.rowSpan),"number"==typeof e.columnSpan&&Number.isFinite(e.columnSpan)&&e.columnSpan>0&&e.columnSpan<=32&&(n.columnSpan=e.columnSpan),n)}(r);return s?(o=!0,{...e,layoutItem:{...i??{},...s}}):e});return o?{...e,instances:i}:e}function g(e){let n=!1;for(const t of Object.values(e))if(t&&(0===t.row||0===t.column)){n=!0;break}if(!n)return e;const t={};for(const[n,o]of Object.entries(e)){if(!o)continue;const e={...o};"number"==typeof e.row&&Number.isFinite(e.row)&&(e.row=e.row+1),"number"==typeof e.column&&Number.isFinite(e.column)&&(e.column=e.column+1),t[n]=e}return t}function m(e,n){if(!e||"object"!=typeof e||Array.isArray(e))return{};const t=new Set(n.map(e=>e.instanceId)),o={};for(const[n,i]of Object.entries(e)){if(!i||"object"!=typeof i||Array.isArray(i))continue;const e=i;e.instanceId===n&&t.has(e.instanceId)&&"string"==typeof e.baseVersionKey&&e.baseVersionKey&&D(e.source)&&P(e.contract)&&(o[n]={instanceId:e.instanceId,baseVersionKey:e.baseVersionKey,source:e.source,contract:e.contract,...R(e.contractParseError)?{contractParseError:R(e.contractParseError)}:{},..."string"==typeof e.createdAt?{createdAt:e.createdAt}:{},..."string"==typeof e.updatedAt?{updatedAt:e.updatedAt}:{}})}return o}function v(e){let n=e;void 0===n.parentId&&n.slotPlacement&&(n={...n,parentId:n.slotPlacement.parentInstanceId,slot:n.slotPlacement.slotName}),""!==n.slot&&"default"!==n.slot||(n={...n,slot:void 0}),void 0===n.placement&&(n={...n,placement:void 0===n.parentId?"absolute":"slot"});const t=I(n.sizing,n.size);if(t!==n.size&&(n={...n,size:t}),void 0!==n.containerLayout){const e=b(n.containerLayout);if(e!==n.containerLayout)if(null===e){const{containerLayout:e,...t}=n;n=t}else n={...n,containerLayout:e}}if(n=A(n),n=N(n),void 0!==n.layoutItem){const e=_(n.layoutItem);if(null===e){const{layoutItem:e,...t}=n;n=t}else e!==n.layoutItem&&(n={...n,layoutItem:e})}if(!0===n.locked){const e={};void 0===n.lockPosition&&(e.lockPosition=!0),void 0===n.lockSize&&(e.lockSize=!0),Object.keys(e).length>0&&(n={...n,...e})}return n}const y=new Set(["px","percent","fill","hug","auto"]);function I(e,n){var t,o,i,a;const r=n?function(e){const n={},t=x(e.width),o=x(e.height);return t&&(n.width=t),o&&(n.height=o),n.width||n.height?n:void 0}(n):void 0;if(!e)return r;const s={};if(e.width){const n=w(e.width,null==(t=e.min)?void 0:t.w,null==(o=e.max)?void 0:o.w);n&&(s.width=n)}if(e.height){const n=w(e.height,null==(i=e.min)?void 0:i.h,null==(a=e.max)?void 0:a.h);n&&(s.height=n)}return r?{width:r.width??s.width,height:r.height??s.height}:Object.keys(s).length>0?s:void 0}function w(e,n,t){if(!e||"object"!=typeof e)return null;let o;switch(e.mode){case"fixed":o="px";break;case"percent":o="percent";break;case"fill":o="fill";break;case"hug":o="hug";break;default:return null}const i={mode:o};return"px"!==o&&"percent"!==o||"number"!=typeof e.value||(i.value=e.value),"number"==typeof n&&(i.min=n),"number"==typeof t&&(i.max=t),i}function x(e){if(!e||"object"!=typeof e)return null;if("string"!=typeof e.mode)return null;if(!y.has(e.mode))return null;const n={mode:e.mode};return"px"!==e.mode&&"percent"!==e.mode||"number"!=typeof e.value||(n.value=e.value),"number"==typeof e.min&&(n.min=e.min),"number"==typeof e.max&&(n.max=e.max),n}function b(e){if(!e||"object"!=typeof e)return null;if("none"===e.mode)return{mode:"none"};if("free"===e.mode)return{mode:"free"};if("flex"===e.mode){const n=e,t={mode:"flex",direction:"row"===n.direction||"column"===n.direction?n.direction:"row"};return!0===n.wrap&&(t.wrap=!0),"number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0&&(t.gap=n.gap),"start"!==n.justify&&"center"!==n.justify&&"end"!==n.justify&&"space-between"!==n.justify&&"space-around"!==n.justify||(t.justify=n.justify),"start"!==n.align&&"center"!==n.align&&"end"!==n.align&&"stretch"!==n.align||(t.align=n.align),t}if("split"===e.mode){const n=e;if("horizontal"!==n.direction&&"vertical"!==n.direction)return null;if(!Array.isArray(n.ratios))return null;const t=n.ratios.filter(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0),o={mode:"split",direction:n.direction,ratios:t};return"number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0&&(o.gap=n.gap),o}if("grid"===e.mode){const n=e;if(!Array.isArray(n.columns)||!Array.isArray(n.rows))return null;const t={mode:"grid",columns:n.columns.filter(e=>!!e&&("fr"===e.mode||"px"===e.mode||"percent"===e.mode)&&"number"==typeof e.value&&Number.isFinite(e.value)&&e.value>=0).slice(0,32),rows:n.rows.filter(e=>!!e&&("fr"===e.mode||"px"===e.mode||"percent"===e.mode||"auto"===e.mode)&&("auto"===e.mode&&void 0===e.value||"number"==typeof e.value&&Number.isFinite(e.value)&&e.value>=0)).slice(0,32)};if("number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0)t.gap=n.gap;else if(n.gap&&"object"==typeof n.gap){const e={};"number"==typeof n.gap.row&&Number.isFinite(n.gap.row)&&n.gap.row>=0&&(e.row=n.gap.row),"number"==typeof n.gap.column&&Number.isFinite(n.gap.column)&&n.gap.column>=0&&(e.column=n.gap.column),Object.keys(e).length>0&&(t.gap=e)}if(n.cells&&"object"==typeof n.cells&&!Array.isArray(n.cells)){const e={};for(const[t,o]of Object.entries(n.cells)){if(!o||"object"!=typeof o)continue;if(!Number.isFinite(o.row)||!Number.isFinite(o.column))continue;const n={row:o.row,column:o.column};"number"==typeof o.rowSpan&&Number.isFinite(o.rowSpan)&&o.rowSpan>0&&o.rowSpan<=32&&(n.rowSpan=o.rowSpan),"number"==typeof o.columnSpan&&Number.isFinite(o.columnSpan)&&o.columnSpan>0&&o.columnSpan<=32&&(n.columnSpan=o.columnSpan),e[t]=n}Object.keys(e).length>0&&(t.cells=e)}return t}return null}function k(e,n){const t=(e??[]).map(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0),o=[];for(let e=0;e<n.length;e++){const i=n[e];if("number"==typeof i&&Number.isFinite(i)&&i>0){o.push(i);continue}const a=t[e];"number"==typeof a&&a>0?o.push(a):o.push(1)}return o}function S(e){if(!e)return{type:"free",canvas:{width:{mode:"px",value:1920},height:{mode:"px",value:1080}}};if(B(e))return e;const n=e,t={width:{mode:"px",value:n.canvas.w},height:{mode:"px",value:n.canvas.h}},o=function(e){if(!e)return;const n={};if(void 0!==e.color&&(n.color=e.color),void 0!==e.imageAssetId){const t={id:e.imageAssetId,type:"image"};n.image=t}return void 0!==e.fit&&(n.imageFit="original"===e.fit?"center":e.fit),Object.keys(n).length>0?n:void 0}(n.canvas.background),i={type:n.type,canvas:t};return o&&(i.background=o),void 0!==n.canvas.gridSize&&(i.guides={grid:{size:n.canvas.gridSize}}),i}function B(e){if(!e)return!1;const n=e.canvas;if(!n)return!1;const t=n.width;return"object"==typeof t&&null!==t&&"mode"in t&&"string"==typeof t.mode}function M(e,n,t=1920){switch(e.mode){case"px":return e.value;case"percent":return n>0?n*e.value/100:t;case"vw":return"undefined"!=typeof window?window.innerWidth*e.value/100:t;case"vh":return"undefined"!=typeof window?window.innerHeight*e.value/100:t;case"auto":case"fill":return n>0?n:t}}function T(e,n,t,o,i){const a=C(e.widthMode,e.width),r=C(e.heightMode,e.height),s="free"===o,c={boxSizing:"border-box",minWidth:0,minHeight:0,overflow:e.overflow??"hidden",zIndex:n};return null!==a&&(c.width=a),null!==r&&(c.height=r),"split"===o&&("vertical"===i?c.height="100%":c.width="100%"),"number"==typeof t&&Number.isFinite(t)&&0!==t&&(c.transform=`rotate(${t}deg)`),s?(c.position="absolute",c.left=`${e.x}px`,c.top=`${e.y}px`):c.position="relative",c}function C(e,n){switch(e){case"px":return`${n}px`;case"percent":return`${n}%`;case"fill":return"100%";case"auto":return"auto"}}function z(e){if(!e||"none"===e.mode||"free"===e.mode)return null;if("flex"===e.mode){const n={display:"flex"};if(n.flexDirection=e.direction??"row",e.wrap&&(n.flexWrap="wrap"),"number"==typeof e.gap&&(n.gap=`${e.gap}px`),e.justify){const t={start:"flex-start",end:"flex-end",center:"center","space-between":"space-between","space-around":"space-around"};n.justifyContent=t[e.justify]??e.justify}if(e.align){const t={start:"flex-start",end:"flex-end",center:"center",stretch:"stretch"};n.alignItems=t[e.align]??e.align}return n}if("grid"===e.mode){const n={display:"grid"},t=(e.columns??[]).map(e=>"fr"===e.mode?`${e.value}fr`:"px"===e.mode?`${e.value}px`:`${e.value}%`).join(" "),o=(e.rows??[]).map(e=>"auto"===e.mode?"auto":"fr"===e.mode?`${e.value??1}fr`:"px"===e.mode?`${e.value??0}px`:`${e.value??0}%`).join(" ");if(t&&(n.gridTemplateColumns=t),o&&(n.gridTemplateRows=o),"number"==typeof e.gap)n.gap=`${e.gap}px`;else if(e.gap&&"object"==typeof e.gap){const t=e.gap.row??0,o=e.gap.column??0;n.gap=`${t}px ${o}px`}return n}if("split"===e.mode){const n=(Array.isArray(e.ratios)?e.ratios:[]).map(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0).filter(e=>e>0),t=n.length>0?n.map(e=>`${e}fr`).join(" "):"1fr",o={display:"grid"};return"vertical"===e.direction?o.gridTemplateRows=t:o.gridTemplateColumns=t,"number"==typeof e.gap&&(o.gap=`${e.gap}px`),o}return null}function L(e,n){if(!e)return null;if("flex"===n){const n={};return"number"==typeof e.order&&(n.order=e.order),"number"==typeof e.grow&&(n.flexGrow=e.grow),"number"==typeof e.shrink&&(n.flexShrink=e.shrink),Object.keys(n).length>0?n:null}if("grid"===n){const n={};if("number"==typeof e.row){const t="number"==typeof e.rowSpan&&e.rowSpan>0?e.rowSpan:1;n.gridRow=t>1?`${e.row} / span ${t}`:`${e.row}`}if("number"==typeof e.column){const t="number"==typeof e.columnSpan&&e.columnSpan>0?e.columnSpan:1;n.gridColumn=t>1?`${e.column} / span ${t}`:`${e.column}`}return Object.keys(n).length>0?n:null}return null}function E(e){switch(e.mode){case"px":return`${e.value}px`;case"percent":return`${e.value}%`;case"vw":return`${e.value}vw`;case"vh":return`${e.value}vh`;case"auto":return"auto";case"fill":return"100%"}}function D(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.html&&"string"==typeof e.js&&"string"==typeof e.css}function P(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;const n=e;return["propsDecl","emitsDecl","methodsDecl","slotsDecl","modelDecl","dataInputsDecl","dataOutputsDecl"].every(e=>Array.isArray(n[e]))}function R(e){if(!e||"object"!=typeof e||Array.isArray(e))return;const n=e;return"string"==typeof n.message?{message:n.message,..."number"==typeof n.line?{line:n.line}:{},..."number"==typeof n.column?{column:n.column}:{}}:void 0}const O=new Set(["px","percent","fill","auto"]),$=new Set(["hidden","visible","auto"]);function A(e){const n=e.placement;return"canvas"===n||"container"===n?e:"absolute"===n?{...e,placement:"canvas"}:"slot"===n?{...e,placement:"container"}:{...e,placement:e.parentId?"container":"canvas"}}function N(e){var n,t;const o=e.rect??{x:0,y:0,w:0,h:0},i=null==(n=e.size)?void 0:n.width,a=null==(t=e.size)?void 0:t.height,r=e=>{if(e)return"hug"===e.mode?"auto":"percent"===e.mode?"percent":"fill"===e.mode?"fill":"auto"===e.mode?"auto":"px"===e.mode?"px":void 0},s=e.layoutBox,c=s&&O.has(s.widthMode)?s.widthMode:r(i)??"px",d=s&&O.has(s.heightMode)?s.heightMode:r(a)??"px",l=(e,n)=>"number"==typeof e&&Number.isFinite(e)?e:n,u={x:l(null==s?void 0:s.x,o.x),y:l(null==s?void 0:s.y,o.y),width:l(null==s?void 0:s.width,(null==i?void 0:i.value)??o.w),height:l(null==s?void 0:s.height,(null==a?void 0:a.value)??o.h),widthMode:c,heightMode:d,overflow:(null==s?void 0:s.overflow)&&$.has(s.overflow)?s.overflow:"hidden"};return s&&s.x===u.x&&s.y===u.y&&s.width===u.width&&s.height===u.height&&s.widthMode===u.widthMode&&s.heightMode===u.heightMode&&s.overflow===u.overflow?e:{...e,layoutBox:u}}function F(e){if(e.rootLayout){const o=b(e.rootLayout);return null===o?{...e,rootLayout:{mode:"free"}}:(t=o,(n=e.rootLayout).mode===t.mode&&JSON.stringify(n)===JSON.stringify(t)?e:{...e,rootLayout:o})}var n,t;return{...e,rootLayout:{mode:"free"}}}function j(e){return"container"===e||"slot"===e}function V(e,n,t){var o,i;const a=n.find(e=>e.instanceId===t);if(!a)return;if(void 0===a.parentId)return(null==(o=null==e?void 0:e.rootLayout)?void 0:o.mode)??"free";const r=n.find(e=>e.instanceId===a.parentId);return(null==(i=null==r?void 0:r.containerLayout)?void 0:i.mode)??"none"}function _(e){if(!e||"object"!=typeof e)return null;const n={},t=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"];for(const o of t){const t=e[o];"number"==typeof t&&Number.isFinite(t)&&(n[o]=t)}return Object.keys(n).length>0?n:null}function q(n={}){const{rootMargin:t="500px",disposeDelayMs:o=1500,mountConcurrency:i=2,root:a=null}=n,r={state:e.reactive({}),elById:new Map,idByEl:new WeakMap,mountQueue:[],disposeTimers:new Map,idleScheduled:!1,io:null,counts:{pending:0,mounting:0,mounted:0,disposing:0}};function s(e,n){const t=r.state[e];t!==n&&(void 0!==t&&"idle"!==t&&r.counts[t]--,r.state[e]=n,"idle"!==n&&r.counts[n]++)}function c(e){for(const n of e){const e=r.idByEl.get(n.target);e&&(n.isIntersecting?d(e):l(e))}}function d(e){const n=r.disposeTimers.get(e);n&&(clearTimeout(n),r.disposeTimers.delete(e));const t=r.state[e];"mounted"!==t&&"disposing"!==t?(s(e,"mounting"),r.mountQueue.includes(e)||r.mountQueue.push(e),u()):s(e,"mounted")}function l(e){const n=r.state[e];if("pending"===n||"idle"===n)return;if("mounting"===n){const n=r.mountQueue.indexOf(e);return n>=0&&r.mountQueue.splice(n,1),void s(e,"pending")}s(e,"disposing");const t=r.disposeTimers.get(e);t&&clearTimeout(t);const i=setTimeout(()=>{"disposing"===r.state[e]&&(s(e,"pending"),r.disposeTimers.delete(e))},o);r.disposeTimers.set(e,i)}function u(){r.idleScheduled||0===r.mountQueue.length||(r.idleScheduled=!0,function(e,n=50){const t=globalThis;"function"==typeof t.requestIdleCallback?t.requestIdleCallback(()=>e(),{timeout:n}):setTimeout(e,16)}(()=>{r.idleScheduled=!1;let e=0;for(;e<i&&r.mountQueue.length>0;){const n=r.mountQueue.shift();"mounting"===r.state[n]&&(s(n,"mounted"),e++)}r.mountQueue.length>0&&u()}))}return{register(e,n){const o=r.elById.get(e);if(o&&o!==n){const e=r.io;e&&e.unobserve(o),r.idByEl.delete(o)}r.elById.set(e,n),r.idByEl.set(n,e),s(e,"pending");const i=r.io?r.io:"undefined"==typeof IntersectionObserver?null:(r.io=new IntersectionObserver(c,{root:a,rootMargin:t}),r.io);i?i.observe(n):s(e,"mounted")},unregister(e){const n=r.elById.get(e);if(n){const t=r.io;t&&t.unobserve(n),r.idByEl.delete(n),r.elById.delete(e)}const t=r.disposeTimers.get(e);t&&(clearTimeout(t),r.disposeTimers.delete(e));const o=r.mountQueue.indexOf(e);o>=0&&r.mountQueue.splice(o,1),function(e){const n=r.state[e];void 0!==n&&"idle"!==n&&r.counts[n]--,delete r.state[e]}(e)},isMounted(e){const n=r.state[e];return"mounted"===n||"disposing"===n},getState:e=>r.state[e]??"idle",get state(){return r.state},getStats:()=>({...r.counts}),dispose(){r.io&&(r.io.disconnect(),r.io=null);for(const e of r.disposeTimers.values())clearTimeout(e);r.disposeTimers.clear(),r.elById.clear(),r.mountQueue.length=0;for(const e of Object.keys(r.state))delete r.state[e];r.counts.pending=0,r.counts.mounting=0,r.counts.mounted=0,r.counts.disposing=0}}}function K(e){const n=[];switch(e.source.kind){case"instanceEvent":case"lifecycle":n.push({canvasId:e.source.canvasId,instanceId:e.source.instanceId});break;case"page":case"dataSource":break;default:U(e.source)}switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":n.push({canvasId:e.target.canvasId,instanceId:e.target.instanceId});break;default:H(e.target)}return n}function J(e,n,t){for(const o of K(e))if(o.instanceId===n&&o.canvasId===t)return!0;return!1}function U(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingSource.kind: ${e.kind}`)}function H(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingTarget.kind: ${e.kind}`)}function X(e){const n={type:e.type,canvas:{...e.canvas,width:{...e.canvas.width},height:{...e.canvas.height}}};return e.background&&(n.background={...e.background,...e.background.image?{image:{...e.background.image}}:{}}),e.behavior&&(n.behavior={...e.behavior}),e.guides&&(n.guides={...e.guides,...e.guides.items?{items:[...e.guides.items]}:{}}),e.rootLayout&&(n.rootLayout="grid"===(t=e.rootLayout).mode?{...t,columns:t.columns?t.columns.map(e=>({...e})):[],rows:t.rows?t.rows.map(e=>({...e})):[],...t.cells?{cells:{...t.cells}}:{},..."object"==typeof t.gap&&null!==t.gap?{gap:{...t.gap}}:{}}:"split"===t.mode?{...t,ratios:Array.isArray(t.ratios)?[...t.ratios]:[]}:{...t}),n;var t}function Y(e={}){return JSON.parse(JSON.stringify(e))}function G(n={schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}){const t=h(p(n)),o=e.reactive({schemaVersion:"1",layout:X(t.layout),instances:t.instances.map(e=>({...e,rect:{...e.rect}})),bindings:t.bindings.map(e=>s(e)),componentOverrides:Y(t.componentOverrides)});function i(e){return o.instances.findIndex(n=>n.instanceId===e)}function a(e){return o.bindings.findIndex(n=>n.id===e)}return{get document(){return o},instanceCount:e.computed(()=>o.instances.length),bindingCount:e.computed(()=>o.bindings.length),addInstance(e){if(i(e.instanceId)>=0)return void console.warn(`[hc-canvas/doc-store] instanceId "${e.instanceId}" 已存在,addInstance 忽略`);const n=e.rect?{...e.rect}:function(e){if(!e)return{x:0,y:0,w:0,h:0};const n=(e,n)=>"number"==typeof e&&Number.isFinite(e)?e:n;return{x:n(e.x,0),y:n(e.y,0),w:n(e.width,0),h:n(e.height,0)}}(e.layoutBox),t={...e,rect:n};!0===t.locked&&(void 0===t.lockPosition&&(t.lockPosition=!0),void 0===t.lockSize&&(t.lockSize=!0)),o.instances.push(t)},removeInstance(e){var n;const t=i(e);t<0||(o.instances.splice(t,1),null==(n=o.componentOverrides)||delete n[e],o.bindings=o.bindings.filter(n=>!J(n,e)))},updateInstance(e,n){const t=o.instances.find(n=>n.instanceId===e);if(t&&(Object.assign(t,n),n.rect&&t.layoutBox&&(t.layoutBox={...t.layoutBox,x:t.rect.x,y:t.rect.y,..."px"===t.layoutBox.widthMode?{width:t.rect.w}:{},..."px"===t.layoutBox.heightMode?{height:t.rect.h}:{}}),n.layoutBox)){const e=t.layoutBox??n.layoutBox,o=e=>"number"==typeof e&&Number.isFinite(e);t.rect={x:o(e.x)?e.x:t.rect.x,y:o(e.y)?e.y:t.rect.y,w:"px"===e.widthMode&&o(e.width)?e.width:t.rect.w,h:"px"===e.heightMode&&o(e.height)?e.height:t.rect.h}}},moveInstance(e,n,t){const i=o.instances.find(n=>n.instanceId===e);i&&(i.rect.x=n,i.rect.y=t,i.layoutBox&&(i.layoutBox={...i.layoutBox,x:n,y:t}))},resizeInstance(e,n,t){const i=o.instances.find(n=>n.instanceId===e);if(!i)return;const a=Math.max(1,n),r=Math.max(1,t);i.rect.w=a,i.rect.h=r,i.layoutBox&&(i.layoutBox={...i.layoutBox,width:a,height:r,widthMode:"px",heightMode:"px"})},setInstanceProp(e,n,t){const i=o.instances.find(n=>n.instanceId===e);i&&(i.props={...i.props,[n]:t})},setInstanceLocked(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&(t.locked=n,n?(t.lockPosition=!0,t.lockSize=!0):(delete t.lockPosition,delete t.lockSize))},setInstanceSize(e,n){const t=o.instances.find(n=>n.instanceId===e);if(t)if(null===n)delete t.size,t.layoutBox&&(t.layoutBox={...t.layoutBox,width:t.rect.w,height:t.rect.h,widthMode:"px",heightMode:"px"});else if(t.size=n,t.layoutBox){const e=n.width,o=n.height,i={...t.layoutBox};e&&("px"===e.mode?(i.widthMode="px","number"==typeof e.value&&Number.isFinite(e.value)&&(i.width=e.value)):"percent"===e.mode?(i.widthMode="percent","number"==typeof e.value&&Number.isFinite(e.value)&&(i.width=e.value)):"fill"===e.mode?(i.widthMode="fill",Number.isFinite(i.width)||(i.width=t.rect.w)):"auto"!==e.mode&&"hug"!==e.mode||(i.widthMode="auto",Number.isFinite(i.width)||(i.width=t.rect.w))),o&&("px"===o.mode?(i.heightMode="px","number"==typeof o.value&&Number.isFinite(o.value)&&(i.height=o.value)):"percent"===o.mode?(i.heightMode="percent","number"==typeof o.value&&Number.isFinite(o.value)&&(i.height=o.value)):"fill"===o.mode?(i.heightMode="fill",Number.isFinite(i.height)||(i.height=t.rect.h)):"auto"!==o.mode&&"hug"!==o.mode||(i.heightMode="auto",Number.isFinite(i.height)||(i.height=t.rect.h))),t.layoutBox=i}},setInstanceContainerLayout(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&(null===n?delete t.containerLayout:t.containerLayout=n)},updateInstanceLayoutBox(e,n){const t=o.instances.find(n=>n.instanceId===e);if(!t)return;const i=t.layoutBox??{x:t.rect.x,y:t.rect.y,width:t.rect.w,height:t.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},a={},r=["x","y","width","height"];for(const e of r){const t=n[e];"number"==typeof t&&Number.isFinite(t)&&(a[e]=t)}if("px"!==n.widthMode&&"percent"!==n.widthMode&&"fill"!==n.widthMode&&"auto"!==n.widthMode||(a.widthMode=n.widthMode),"px"!==n.heightMode&&"percent"!==n.heightMode&&"fill"!==n.heightMode&&"auto"!==n.heightMode||(a.heightMode=n.heightMode),"hidden"!==n.overflow&&"visible"!==n.overflow&&"auto"!==n.overflow||(a.overflow=n.overflow),0===Object.keys(a).length)return;const s={...i,...a};t.layoutBox=s;const c=a.widthMode??i.widthMode,d=a.heightMode??i.heightMode;t.rect={x:s.x,y:s.y,w:"px"===c?s.width:t.rect.w,h:"px"===d?s.height:t.rect.h}},updateInstanceLayoutItem(e,n){const t=o.instances.find(n=>n.instanceId===e);if(!t)return;if(null===n)return void delete t.layoutItem;const i=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"],a={};for(const e of i){const t=n[e];"number"==typeof t&&Number.isFinite(t)&&(a[e]=t)}if(0===Object.keys(a).length)return;const r=t.layoutItem??{};t.layoutItem={...r,...a}},setInstanceRotation(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&Number.isFinite(n)&&(0===n?delete t.rotation:t.rotation=n)},duplicateInstance(e,n,t){var i;const a=o.instances.find(n=>n.instanceId===e);if(!a)return;const r=JSON.parse(JSON.stringify(a));if(r.instanceId=n,r.rect={...r.rect,x:a.rect.x+t.x,y:a.rect.y+t.y},r.layoutBox&&(r.layoutBox={...r.layoutBox,x:r.layoutBox.x+t.x,y:r.layoutBox.y+t.y}),delete r.locked,delete r.lockPosition,delete r.lockSize,o.instances.some(e=>e.instanceId===n))return void console.warn(`[hc-canvas/doc-store] duplicateInstance: newInstanceId "${n}" 已存在,忽略`);o.instances.push(r);const s=null==(i=o.componentOverrides)?void 0:i[e];s&&(o.componentOverrides={...o.componentOverrides??{},[n]:{...JSON.parse(JSON.stringify(s)),instanceId:n}})},addBinding(e){if(a(e.id)>=0)return void console.warn(`[hc-canvas/doc-store] binding id "${e.id}" 已存在,addBinding 忽略`);const[n]=d([e]);n?o.bindings.push(s(n)):console.warn(`[hc-canvas/doc-store] addBinding "${null==e?void 0:e.id}" dropped by normalize`)},removeBinding(e){const n=a(e);n<0||o.bindings.splice(n,1)},updateBinding(e,n){const t=o.bindings.find(n=>n.id===e);if(!t)return;const i=s(n);Object.assign(t,i)},updateLayout(e){for(const n of Object.keys(e)){const t=e[n];void 0===t?delete o.layout[n]:o.layout[n]=t}},setComponentOverride(e,n){null!==n?(o.componentOverrides||(o.componentOverrides={}),o.componentOverrides[e]=n):o.componentOverrides&&e in o.componentOverrides&&delete o.componentOverrides[e]},replaceDocument(e){const n=h(p(e));o.schemaVersion="1",o.layout=X(n.layout),o.instances=n.instances.map(e=>({...e,rect:{...e.rect}})),o.bindings=n.bindings.map(e=>s(e)),o.componentOverrides=Y(n.componentOverrides)},getInstance:e=>o.instances.find(n=>n.instanceId===e),listInstancesByComponentVersionKey:e=>o.instances.filter(n=>n.componentVersionKey===e)}}function W(){const n=e.reactive({ids:[]});return{selectedIds:e.computed(()=>n.ids),size:e.computed(()=>n.ids.length),primaryId:e.computed(()=>n.ids[0]),select(e){n.ids=[e]},toggleSelect(e){const t=n.ids.indexOf(e);t>=0?n.ids.splice(t,1):n.ids.push(e)},addToSelection(e){n.ids.includes(e)||n.ids.push(e)},removeFromSelection(e){const t=n.ids.indexOf(e);t>=0&&n.ids.splice(t,1)},clearSelection(){n.ids=[]},selectAll(e){n.ids=Array.from(new Set(e))},purgeOrphans(e){const t=new Set(e);n.ids=n.ids.filter(e=>t.has(e))},isSelected:e=>n.ids.includes(e)}}function Q(n={}){const{minScale:t=.25,maxScale:o=4,initialScale:i=1}=n,a=e.reactive({scale:i,panX:0,panY:0});function r(e){return Math.max(t,Math.min(o,e))}return{state:a,scale:e.computed(()=>a.scale),panX:e.computed(()=>a.panX),panY:e.computed(()=>a.panY),setScale(e){a.scale=r(e)},zoomAt(e,n){const t=a.scale,o=r(t+n);if(o===t)return;const i=o/t;a.panX=e.x-(e.x-a.panX)*i,a.panY=e.y-(e.y-a.panY)*i,a.scale=o},setPan(e,n){a.panX=e,a.panY=n},panBy(e,n){a.panX+=e,a.panY+=n},resetView(){a.scale=i,a.panX=0,a.panY=0},fitToScreen(e,n,t=40){const o=Math.max(1,n.w-2*t),i=Math.max(1,n.h-2*t),s=o/e.w,c=i/e.h,d=r(Math.min(s,c)),l=e.w*d,u=e.h*d;a.scale=d,a.panX=(n.w-l)/2,a.panY=(n.h-u)/2},toCanvasPoint:e=>({x:(e.x-a.panX)/a.scale,y:(e.y-a.panY)/a.scale}),toViewportPoint:e=>({x:e.x*a.scale+a.panX,y:e.y*a.scale+a.panY})}}function Z(e){const n=new Map;return{resolve(t){const o=function(e){return e.id||e.url||""}(t);if(o&&n.has(o))return n.get(o);if(!e){const e=t.url??"";return o&&n.set(o,e),e}const i=e.resolve(t);return"string"==typeof i?(o&&n.set(o,i),i):(o&&n.set(o,i),i.then(e=>{o&&n.set(o,e)},e=>{console.warn(`[hc-canvas/assets] resolve("${o}") 失败,缓存里删条目允许重试:`,e),o&&n.delete(o)}),i)},__clearCache(){n.clear()}}}function ee(e,n,t){if(!n||0===Object.keys(n).length)return`${e}::{}`;const o=ne(n,t);return null===o?`${e}::__fresh_${Date.now()}_${Math.random().toString(36).slice(2,8)}__`:`${e}::${o}`}function ne(e,n,t=new WeakSet){if(null==e)return JSON.stringify(e);const o=typeof e;if("string"===o||"number"===o||"boolean"===o)return JSON.stringify(e);if("function"===o||"symbol"===o||"bigint"===o)return null==n||n(),null;if(Array.isArray(e)){if(t.has(e))return null==n||n(),null;t.add(e);const o=[];for(const i of e){const e=ne(i,n,t);if(null===e)return null;o.push(e)}return`[${o.join(",")}]`}if("object"===o){const o=Object.getPrototypeOf(e);if(o!==Object.prototype&&null!==o)return null==n||n(),null;const i=e;if(t.has(i))return null==n||n(),null;t.add(i);const a=Object.keys(i).sort(),r=[];for(const e of a){const o=ne(i[e],n,t);if(null===o)return null;r.push(`${JSON.stringify(e)}:${o}`)}return`{${r.join(",")}}`}return null==n||n(),null}function te(e){const n=new Map,t=new Map,o=new Map,i=new Map,a=new Map,r=new Map;let s=!1,c=!1,d=0,l=null;function u(e){if(!c&&null!==l)try{l(e)}catch(e){console.error("[hc-canvas/dataStore] trace bridge listener threw",e)}}function p(e,n){var t;const a=o.get(e);if(a)for(const e of a)null==(t=i.get(e))||t.onUpdate(n)}function f(e,t){let o=n.get(e);return o||(o={cacheKey:e,sourceId:t,status:"idle"},n.set(e,o)),o}function h(t,r,s){if(!e)return;const l=a.get(t);l&&l.abort();const h=new AbortController;a.set(t,h);const g=f(t,r);g.status="loading";const m=g.writeSeq??0;Promise.resolve().then(()=>async function(e,n){return{value:await Promise.resolve(e.query(n))}}(e,{sourceId:r,params:s,signal:h.signal})).then(e=>{if(c)return;if(a.get(t)!==h)return;a.delete(t);const o=n.get(t);o&&((o.writeSeq??0)>m?u({kind:"data-query-skipped",cacheKey:t,sourceId:r,writeSeq:o.writeSeq,reason:"race-stale"}):(o.status="success",o.value=e.value,o.error=void 0,o.lastFetchedAt=Date.now(),o.writeSeq=++d,u({kind:"data-source-update",cacheKey:t,sourceId:r,writeSeq:o.writeSeq,value:e.value}),p(t,e.value)))}).catch(e=>{if(c)return;if(function(e){return null!==e&&"object"==typeof e&&"AbortError"===e.name}(e))return;if(a.get(t)!==h)return;a.delete(t);const s=n.get(t);s&&((s.writeSeq??0)>m?u({kind:"data-query-skipped",cacheKey:t,sourceId:r,writeSeq:s.writeSeq,reason:"race-stale-reject"}):(s.status="error",s.error=e,s.lastFetchedAt=Date.now(),function(e,n){var t,a;const r=o.get(e);if(r)for(const e of r)null==(a=null==(t=i.get(e))?void 0:t.onError)||a.call(t,n)}(t,e)))})}function g(e){if(c)return;const{bindingId:d,sourceId:l,params:u,onUpdate:p,onError:f}=e,g=ee(l,u,()=>{s||(console.warn(`[hc-canvas/dataStore] params for "${l}" contains non-plain values; fresh query every call (no cache)`),s=!0)});!function(e,i){const s=t.get(e);if(s===i)return;if(s){const t=o.get(s);if(t&&(t.delete(e),0===t.size)){o.delete(s);const e=a.get(s);e&&(e.abort(),a.delete(s)),n.delete(s)}const i=r.get(e);if(i){try{i()}catch{}r.delete(e)}}t.set(e,i);let c=o.get(i);c||(c=new Set,o.set(i,c)),c.add(e)}(d,g),i.set(d,{onUpdate:p,onError:f});const m=n.get(g);if(m){if("success"===m.status)return void p(m.value);if("error"===m.status)return void(null==f||f(m.error));if("loading"===m.status)return}h(g,l,u)}return{request:g,subscribe:function(n){if(c)return;const{bindingId:o,sourceId:i,params:a,onUpdate:s,onError:l}=n;if(g({bindingId:o,sourceId:i,params:a,onUpdate:s,onError:l}),!e)return;const h=t.get(o);if(!h)return;let m=!0;try{const n=function(e,n){if(e.subscribe)return e.subscribe(n,e=>{if(c)return;if(!m)return;if(t.get(o)!==h)return;const n=f(h,i);n.status="success",n.value=e,n.lastFetchedAt=Date.now(),n.writeSeq=++d,u({kind:"data-source-update",cacheKey:h,sourceId:i,writeSeq:n.writeSeq,value:e}),p(h,e)})}(e,{sourceId:i,params:a});n?r.set(o,()=>{m=!1;try{n()}catch{}}):r.set(o,()=>{m=!1})}catch(e){m=!1,c||null==l||l(e)}},removeBinding:function(e,s){if(c)return;const d=!0===(null==s?void 0:s.preserveCache),l=r.get(e);if(l){try{l()}catch{}r.delete(e)}i.delete(e);const u=function(e){const n=t.get(e);if(!n)return;t.delete(e);const i=o.get(n);return i&&(i.delete(e),0===i.size&&o.delete(n)),n}(e);if(u&&!o.has(u)){const e=n.get(u);if(!d||"success"!==(null==e?void 0:e.status)){const e=a.get(u);e&&(e.abort(),a.delete(u)),n.delete(u)}}},invalidate:function(e){if(c)return;const t=[];for(const[o,i]of n)void 0!==e&&i.sourceId!==e||t.push(o);for(const e of t){const t=n.get(e);if(!t)continue;const i=o.get(e);if(!i||0===i.size){n.delete(e);const t=a.get(e);t&&(t.abort(),a.delete(e));continue}t.status="stale",h(e,t.sourceId,void 0)}},getSnapshot:function(){return{entries:Array.from(n.values()).map(e=>({cacheKey:e.cacheKey,sourceId:e.sourceId,status:e.status,value:e.value,error:e.error,lastFetchedAt:e.lastFetchedAt}))}},getCachedBySourceId:function(e,t){if(c)return;const o=ee(e,t,()=>{s||(console.warn(`[hc-canvas/dataStore] params for "${e}" contains non-plain values; cannot compute stable cache key, cache lookup will miss`),s=!0)}),i=n.get(o);return i?{value:i.value,status:i.status}:void 0},disposeAll:function(){if(!c){c=!0;for(const e of a.values())try{e.abort()}catch{}a.clear();for(const e of r.values())try{e()}catch{}r.clear(),n.clear(),t.clear(),o.clear(),i.clear(),l=null}},attachTraceBridge:function(e){return c?()=>{}:(l=e,()=>{l===e&&(l=null)})},getBindingsForCacheKey:function(e){const n=o.get(e);return n?Array.from(n):[]},get isDisposed(){return c}}}const oe=Symbol("hc:canvas:context");function ie(t={}){var o,i;const a=t.canvasId??n.DEFAULT_CANVAS_ID,r=G(t.initialDocument),s=W(),c=Q(t.viewport),d=q(t.scheduler),l=te(null==(o=t.adapters)?void 0:o.data);let u=!1;const p=[];t.hooks&&p.push(t.hooks);const f=e.ref(!1),h=e.computed(()=>f.value),g=e.ref({}),m=e.computed(()=>g.value),v=e.computed(()=>{var e;const n=(null==(e=t.getMode)?void 0:e.call(t))??"design",o=function(e){switch(e){case"design":return{selectable:!0,draggable:!0,resizable:!0,keyboardMove:!0,snap:!0,grid:!1,allowOverflow:!0,locked:!1};case"preview":case"runtime":return{selectable:!1,draggable:!1,resizable:!1,keyboardMove:!1,snap:!0,grid:!1,allowOverflow:!0,locked:!1};case"inspect":return{selectable:!0,draggable:!1,resizable:!1,keyboardMove:!1,snap:!0,grid:!1,allowOverflow:!0,locked:!1}}}(n),i=r.document.layout.behavior??{};if("design"!==n){const{selectable:e,draggable:n,resizable:t,keyboardMove:a,...r}=i;return{...o,...r,...g.value}}return{...o,...i,...g.value}}),y=Z(null==(i=t.adapters)?void 0:i.assets),w=e.ref("select"),x=e.ref(null),k=e.computed(()=>x.value??w.value),S=e.ref(null),B=e.computed(()=>S.value),T=e.ref(null),C=e.ref({w:0,h:0}),z=e.computed(()=>C.value),L=e.computed(()=>{const e=r.document.layout,n=C.value;return{w:M(e.canvas.width,n.w,1920),h:M(e.canvas.height,n.h,1080)}}),E=e.ref([]),D=e.computed(()=>E.value),P=e.ref(0),R=e.computed(()=>P.value>0);return{canvasId:a,document:r,selection:s,viewport:c,scheduler:d,adapters:t.adapters??{},dataStore:l,dispatch:function(e){var n,t;if(u)console.warn("[hc-canvas/context] dispatch called after dispose()");else{for(const t of p)if(!1===(null==(n=t.onBeforeAction)?void 0:n.call(t,e)))return;switch(e.type){case"addInstance":r.addInstance(e.payload.instance);break;case"removeInstance":r.removeInstance(e.payload.instanceId),s.removeFromSelection(e.payload.instanceId);break;case"updateInstance":r.updateInstance(e.payload.instanceId,e.payload.patch);break;case"moveInstance":r.moveInstance(e.payload.instanceId,e.payload.x,e.payload.y);break;case"resizeInstance":r.resizeInstance(e.payload.instanceId,e.payload.w,e.payload.h);break;case"setInstanceProp":r.setInstanceProp(e.payload.instanceId,e.payload.key,e.payload.value);break;case"addBinding":r.addBinding(e.payload.binding);break;case"removeBinding":r.removeBinding(e.payload.bindingId);break;case"updateBinding":r.updateBinding(e.payload.bindingId,e.payload.patch);break;case"updateLayout":r.updateLayout(e.payload.patch);break;case"setRootLayout":{const{rootLayout:n}=e.payload;r.updateLayout({rootLayout:null===n?void 0:n});break}case"replaceDocument":r.replaceDocument(e.payload.document),s.purgeOrphans(r.document.instances.map(e=>e.instanceId));break;case"setComponentOverride":{const{instanceId:n,override:t}=e.payload;if(void 0===r.getInstance(n)){console.warn(`[hc-canvas/context] setComponentOverride: instance "${n}" 不存在,no-op`);break}r.setComponentOverride(n,t);break}case"setInstanceLocked":r.setInstanceLocked(e.payload.instanceId,e.payload.locked);break;case"duplicateInstance":r.duplicateInstance(e.payload.instanceId,e.payload.newInstanceId,e.payload.offset??{x:20,y:20});break;case"setInstanceSize":{const{instanceId:n,size:t}=e.payload;if(null===t)r.setInstanceSize(n,null);else{const e=I(void 0,t);r.setInstanceSize(n,e??null)}break}case"setContainerLayout":{const{instanceId:n,containerLayout:t}=e.payload;if(null===t)r.setInstanceContainerLayout(n,null);else{const e=b(t);null!==e&&r.setInstanceContainerLayout(n,e)}break}case"updateLayoutBox":r.updateInstanceLayoutBox(e.payload.instanceId,e.payload.patch);break;case"updateLayoutItem":r.updateInstanceLayoutItem(e.payload.instanceId,e.payload.patch);break;case"updateRotation":r.setInstanceRotation(e.payload.instanceId,e.payload.value);break;case"select":s.select(e.payload.instanceId);break;case"toggleSelect":s.toggleSelect(e.payload.instanceId);break;case"addToSelection":s.addToSelection(e.payload.instanceId);break;case"removeFromSelection":s.removeFromSelection(e.payload.instanceId);break;case"clearSelection":s.clearSelection();break;case"selectAll":s.selectAll(e.payload.instanceIds);break;default:{const n=e;console.warn("[hc-canvas/context] unknown action",n)}}for(const n of p)null==(t=n.onAfterAction)||t.call(n,e)}},dispose:function(){u||(u=!0,f.value=!1,d.dispose(),l.disposeAll())},isBatching:h,beginBatch:function(){u||f.value||(f.value=!0)},endBatch:function(e){var n;if(!u&&f.value){for(const t of p)null==(n=t.onAfterBatch)||n.call(t,e);f.value=!1}},registerHooks:function(e){return p.push(e),()=>{const n=p.indexOf(e);n>=0&&p.splice(n,1)}},isRecordingSuppressed:R,suppressRecording:function(e){P.value++;try{return e()}finally{P.value--}},effectiveBehavior:v,interactionOptions:m,setInteractionOptions:function(e){const n={...g.value};for(const t of Object.keys(e)){const o=e[t];void 0===o?delete n[t]:n[t]=o}g.value=n},resolveAsset:function(e){return y.resolve(e)},toolMode:k,setToolMode:function(e){w.value=e},setTemporaryToolMode:function(e){x.value=e},mouseCanvasPoint:B,setMouseCanvasPoint:function(e){S.value=e},measuredStageSize:z,measuredCanvasSize:L,setMeasuredStageSize:function(e){const n=Math.max(0,Math.round(e.w)),t=Math.max(0,Math.round(e.h));C.value.w===n&&C.value.h===t||(C.value={w:n,h:t})},layoutIssues:D,setLayoutIssues:function(e){E.value=e},cannotDragLayoutManagedChildEvent:e.readonly(T),setCannotDragLayoutManagedChildEvent:function(e){T.value=e}}}function ae(n){e.provide(oe,n)}function re(){const n=e.inject(oe);if(!n)throw new Error("[hc-canvas] useCanvasContext() called outside <CanvasProvider> / <HyperCardCanvasDesigner>. Make sure the component tree is wrapped by a provider.");return n}const se="default";function ce(e){return e.slot??se}function de(e,n){const t=[],o=n.resolveContract,i=n.maxDepth??8,a=new Map;for(const n of e.instances)a.set(n.instanceId,n);for(const n of e.instances){if(void 0===n.parentId&&void 0!==n.slot&&n.slot!==se){le(t,"orphan-slot",n.instanceId,`slot "${n.slot}" 没有 parentId,数据不完整`);continue}if(void 0===n.parentId)continue;if(!a.has(n.parentId)){le(t,"missing-parent",n.instanceId,`parentId "${n.parentId}" 指向不存在的实例`);continue}"absolute"!==n.placement&&"canvas"!==n.placement||le(t,"absolute-child-rejected",n.instanceId,"parentId + placement='absolute'|'canvas' 在 D4.5f MVP 不支持,只允许 root absolute/canvas 或 child slot/container");const e=a.get(n.parentId),i=o(e.componentVersionKey);if(!i)continue;const r=i.slotsDecl??[];if(0===r.length){le(t,"parent-not-layout",n.instanceId,`父组件 "${e.componentId}" 不是布局组件(slotsDecl 为空)`);continue}const s=ce(n),c=ue(r,s);c?c.accepts&&c.accepts.length>0&&(c.accepts.includes(n.componentId)||le(t,"slot-not-allowed-component",n.instanceId,`slot "${s}" 不允许 componentId "${n.componentId}"(accepts: ${c.accepts.join(", ")})`)):le(t,"invalid-slot",n.instanceId,`slot "${s}" 不在父 "${e.componentId}" 的 slotsDecl 中(可能组件升级删除了该 slot)`)}const r=new Map;for(const n of e.instances){if(void 0===n.parentId)continue;const e=ce(n),t=`${n.parentId}::${e}`;let o=r.get(t);o||(o=[],r.set(t,o)),o.push(n)}for(const[e,n]of r){if(n.length<=1)continue;const[i,r]=pe(e),s=a.get(i);if(!s)continue;const c=o(s.componentVersionKey);if(!c)continue;const d=ue(c.slotsDecl??[],r);if(d&&!0!==d.multiple)for(let e=1;e<n.length;e++)le(t,"slot-multiple-violated",n[e].instanceId,`slot "${r}" 不允许多个子实例(SlotDecl.multiple !== true)`)}const s=new Map;for(const n of e.instances)s.set(n.instanceId,0);for(const n of e.instances)0===s.get(n.instanceId)&&c(n.instanceId,[],0);function c(e,n,o){s.set(e,1);const r=a.get(e);if(o>i)return le(t,"depth-exceeded",e,`嵌套深度 ${o} 超过上限 ${i}`),void s.set(e,2);const d=r.parentId;if(void 0===d)return void s.set(e,2);if(!a.has(d))return void s.set(e,2);const l=s.get(d);if(1===l)return le(t,"cycle",e,`parentId 链成环:${[...n,e,d].join(" → ")}`),void s.set(e,2);2!==l?(c(d,[...n,e],o+1),s.set(e,2)):s.set(e,2)}return t}function le(e,n,t,o){e.push({kind:n,instanceId:t,detail:o})}function ue(e,n){return e.find(e=>e.name===n)}function pe(e){const n=e.indexOf("::");return[e.slice(0,n),e.slice(n+2)]}function fe(e,n,t){const o=(null==e?void 0:e.onError)??"log";switch(o){case"stop":return"stop";case"log":return console.error(`[hc-canvas/wirePageBindings] binding "${t}" threw:`,n),"continue";case"continue":return"continue";default:return console.error(`[hc-canvas/wirePageBindings] binding "${t}" threw (unknown onError="${String(o)}"):`,n),"continue"}}function he(e,n){return e&&"passthrough"!==e.kind?"static"===e.kind?function(e){if("function"==typeof structuredClone)try{return structuredClone(e)}catch{}try{return JSON.parse(JSON.stringify(e))}catch{return[...e]}}(e.args):"pickPath"===e.kind?function(e,n){const t=[];let o;for(const i of e){const e=ge(n,i.from);void 0===i.to?t.push(e):"number"==typeof i.to?(me(t,i.to+1),t[i.to]=e):(o||(t.length>0&&"object"==typeof t[0]&&null!==t[0]&&!Array.isArray(t[0])?o=t[0]:(o={},0===t.length?t.push(o):t[0]=o)),o[i.to]=e)}return t}(e.paths,n):[n]:[n]}function ge(e,n){if(""===n)return e;const t=n.split(".");let o=e;for(const e of t){if(null==o)return;if("object"!=typeof o)return;o=o[e]}return o}function me(e,n){for(;e.length<n;)e.push(void 0)}function ve(e,n,t,o){e.debouncePendingTimer=null;const i=e.debounceDirty,a=e.debouncePendingChainId,r=e.debouncePendingPayload;e.debouncePendingChainId=null,e.debouncePendingPayload=void 0,e.debounceDirty=!1,t&&i&&null!==a&&Ie(n,e).pass&&o(r,a)}function ye(e,n,t){e.throttleTrailingTimer=null;const o=e.throttleTrailingPendingChainId,i=e.throttleTrailingPendingPayload;e.throttleTrailingPendingChainId=null,e.throttleTrailingPendingPayload=void 0,e.throttleWindowStartTs=null,null!==o&&(n.once&&e.onceConsumed||(n.once&&(e.onceConsumed=!0),e.throttleLastFireTs=be(),t(i,o)))}function Ie(e,n){const t=e.throttle;if(t){t.leading;const e=t.windowMs,o=be(),i=n.throttleLastFireTs;if(null!==i&&o-i<e)return{pass:!1,reason:"throttle-window"};n.throttleLastFireTs=o}if(e.once){if(n.onceConsumed)return{pass:!1,reason:"once-consumed"};n.onceConsumed=!0}return{pass:!0}}function we(e){return!(!e||!(e.throttle&&!1===e.throttle.leading&&!1===e.throttle.trailing||e.debounce&&!1===e.debounce.leading&&!1===e.debounce.trailing))}let xe=()=>Date.now();function be(){return xe()}let ke=0;function Se(t){var o,i;const a=t.canvasId,{source:r}=t,s=t.dataStore,c=new Set;let d="off",l=0,u=!1;const p="w"+ ++ke;let f=0;function h(){return`${p}-${++f}`}let g=0;function m(e){L.hasListeners("binding:trace")&&L.emit("binding:trace",{canvasId:a,ts:Date.now(),seq:++g,...e})}let v=!1,y=null;function I(){v&&(y&&y(),y=null,v=!1)}const w=new Map,x=new Map,b=new Set,k=new Set,S=new Set,B=new Set,M=new Map;let T=new Set;const C=[],z=[],L=function(e){const n=new Set,t=new Set,o=new Set;return{on(i,a){var r;if("binding:fire"===i){const e=a;return n.add(e),()=>n.delete(e)}if("binding:error"===i){const e=a;return t.add(e),()=>t.delete(e)}const s=a;return o.add(s),null==(r=null==e?void 0:e.onTraceListenerCountChange)||r.call(e,o.size),()=>{var n;o.delete(s),null==(n=null==e?void 0:e.onTraceListenerCountChange)||n.call(e,o.size)}},emit(e,i){if("binding:fire"===e)for(const e of n)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else if("binding:error"===e)for(const e of t)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else for(const e of o)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] trace listener threw",e)}},hasListeners:e=>"binding:fire"===e?n.size>0:"binding:error"===e?t.size>0:o.size>0,clear(){n.clear(),t.clear(),o.clear()}}}({onTraceListenerCountChange:function(e){e>0?!v&&s&&(y=s.attachTraceBridge(e=>{if(u)return;const n=s.getBindingsForCacheKey(e.cacheKey);for(const t of n)m({kind:e.kind,bindingId:t,cacheKey:e.cacheKey,sourceId:e.sourceId,writeSeq:e.writeSeq,reason:e.reason,payload:e.value})}),v=!0):I()}}),E=function(e){let n=[],t=200,o=null,i=null;return{start:function(a){i&&(i(),i=null,n=[]),t=(null==a?void 0:a.capacity)??200,o=(null==a?void 0:a.filterKinds)&&a.filterKinds.length>0?new Set(a.filterKinds):null,i=e.on("binding:trace",e=>{o&&!o.has(e.kind)||(n.push(e),n.length>t&&n.shift())})},stop:function(){i&&(i(),i=null);const e=n.slice();return n=[],e},snapshot:function(){return n.slice()},get isRunning(){return null!==i}}}({on:(e,n)=>L.on(e,n)});function D(e){return void 0===e.canvasId||e.canvasId===a}function P(e){for(const n of K(e))if(void 0!==n.canvasId&&n.canvasId!==a)return!0;return!1}function R(e){return JSON.stringify({id:e.id,type:e.type,disabled:e.disabled??!1,source:e.source,target:e.target,mapping:e.mapping??null,schedule:e.schedule??null,errorPolicy:e.errorPolicy??null})}function O(e,n){return void 0===n||R(e)!==n}function $(){var e;return(null==(e=r.getDocument())?void 0:e.bindings)??[]}function A(e){return $().find(n=>n.id===e)}function N(e){try{e()}catch(e){console.error("[hc-canvas/wirePageBindings] cleanup threw",e)}}function F(e,n){L.emit("binding:fire",e),m({kind:"fire",bindingId:e.bindingId,chainId:n,payload:e.payload,args:e.args})}function j(e,n){L.emit("binding:error",e),m({kind:(null==n?void 0:n.traceKind)??"error",bindingId:e.bindingId,chainId:null==n?void 0:n.chainId,code:e.code,message:e.message,detail:e.detail})}function V(e,n=!1){const t=w.get(e);if(t)for(const e of t)N(e);w.delete(e);const o=x.get(e);if(o){const n=function(e){const n={};return null!==e.debouncePendingTimer&&(clearTimeout(e.debouncePendingTimer),e.debouncePendingTimer=null,null!==e.debouncePendingChainId&&(n.droppedDebounce={chainId:e.debouncePendingChainId,payload:e.debouncePendingPayload})),null!==e.debouncePendingTimer||null===e.debouncePendingChainId||n.droppedDebounce||(n.droppedDebounce={chainId:e.debouncePendingChainId,payload:e.debouncePendingPayload}),e.debouncePendingChainId=null,e.debouncePendingPayload=void 0,e.debounceDirty=!1,null!==e.throttleTrailingTimer&&(clearTimeout(e.throttleTrailingTimer),e.throttleTrailingTimer=null),null!==e.throttleTrailingPendingChainId&&(n.droppedThrottleTrailing={chainId:e.throttleTrailingPendingChainId,payload:e.throttleTrailingPendingPayload}),e.throttleTrailingPendingChainId=null,e.throttleTrailingPendingPayload=void 0,e.throttleWindowStartTs=null,n}(o);n.droppedDebounce&&m({kind:"scheduled-dropped",bindingId:e,chainId:n.droppedDebounce.chainId,payload:n.droppedDebounce.payload}),n.droppedThrottleTrailing&&m({kind:"scheduled-dropped",bindingId:e,chainId:n.droppedThrottleTrailing.chainId,payload:n.droppedThrottleTrailing.payload}),x.delete(e)}k.delete(e),M.delete(e),S.delete(e),B.delete(e),c.delete(e),s&&s.removeBinding(e,{preserveCache:n})}function _(e=!1){for(const n of[...w.keys()])V(n,e)}function q(e){if(u)return;if(w.has(e.id))return;if(P(e))return void(S.has(e.id)||(j({bindingId:e.id,code:"unsupported-cross-canvas"}),S.add(e.id),m({kind:"wire-skipped",bindingId:e.id,reason:"unsupported-cross-canvas"})));const t=function(e){return e.disabled?"disabled":b.has(e.id)?"stopped":null}(e);if(t)return void m({kind:"wire-skipped",bindingId:e.id,reason:t});if("data-preview"===d&&"dataSource"!==e.source.kind)return void m({kind:"wire-skipped",bindingId:e.id,reason:"mode-matrix-data-preview"});we(e.schedule)&&!B.has(e.id)&&(console.warn(`[hc-canvas/wirePageBindings] schedule.{throttle|debounce}.{leading=false,trailing=false} 永远不会 fire (binding "${e.id}")`),B.add(e.id));const o=[];switch(e.source.kind){case"instanceEvent":{const t=n.getInstance(e.source.instanceId,a);if(!t)return void k.add(e.id);const i=e.source.event,r=t.on(i,n=>U(e,n));o.push(r);break}case"lifecycle":case"page":break;case"dataSource":{if(!s)return void(c.has(e.id)||(j({bindingId:e.id,code:"no-data-adapter"}),m({kind:"wire-skipped",bindingId:e.id,reason:"no-data-adapter"}),c.add(e.id)));const n=e.source,t="change"===n.watch,o=n=>U(e,n),i=n=>{j({bindingId:e.id,code:"data-query-failed",message:n instanceof Error?n.message:String(n),detail:n}),"stop"===fe(e.errorPolicy,n,e.id)&&b.add(e.id)};m({kind:"data-query-started",bindingId:e.id,sourceId:n.sourceId}),t?s.subscribe({bindingId:e.id,sourceId:n.sourceId,onUpdate:o,onError:i}):s.request({bindingId:e.id,sourceId:n.sourceId,onUpdate:o,onError:i});break}default:return}w.set(e.id,o),M.set(e.id,R(e))}function J(){for(const e of $())q(e)}function U(e,n){if(u)return;if("off"===d)return;if(b.has(e.id))return void m({kind:"stopped-skipped",bindingId:e.id});if(P(e))return;if(l>=8){const n=h();return void j({bindingId:e.id,code:"cycle-detected"},{chainId:n,traceKind:"cycle-detected"})}const t=h(),o=function(e,n,t,o){return we(e)?{fire:!1,deferred:!1,reason:"schedule-no-fire"}:(null==e?void 0:e.debounce)?function(e,n,t,o){const i=e.debounce,a=i.leading??!1,r=i.trailing??!0,s=i.windowMs;if(null===n.debouncePendingTimer){if(a){const t=Ie(e,n);return t.pass?(n.debounceLeadingFireTs=be(),n.debounceDirty=!1,n.debouncePendingPayload=void 0,n.debouncePendingChainId=null,{fire:!0,deferred:!1,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{ve(n,e,r,t)},s)}}):{fire:!1,deferred:!1,reason:t.reason}}return n.debouncePendingPayload=t,n.debouncePendingChainId=o,n.debounceDirty=!0,{fire:!1,deferred:!0,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{ve(n,e,r,t)},s)}}}const c=null!==n.debouncePendingChainId?{chainId:n.debouncePendingChainId,payload:n.debouncePendingPayload}:void 0;return n.debounceDirty=!0,r&&(n.debouncePendingPayload=t,n.debouncePendingChainId=o),clearTimeout(n.debouncePendingTimer),n.debouncePendingTimer=null,r?{fire:!1,deferred:!0,droppedByReschedule:c,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{ve(n,e,r,t)},s)}}:{fire:!1,deferred:!1,reason:"debounce-window",scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{ve(n,e,r,t)},s)}}}(e,n,t,o):function(e,n,t,o){const i=null==e?void 0:e.throttle;if(!i)return function(e,n){if(null==e?void 0:e.once){if(n.onceConsumed)return{fire:!1,deferred:!1,reason:"once-consumed"};n.onceConsumed=!0}return{fire:!0,deferred:!1}}(e,n);const a=i.leading??!0,r=i.trailing??!1,s=i.windowMs,c=be();if(a){const i=n.throttleLastFireTs;if(!(null!==i&&c-i<s))return(null==e?void 0:e.once)&&n.onceConsumed?{fire:!1,deferred:!1,reason:"once-consumed"}:((null==e?void 0:e.once)&&(n.onceConsumed=!0),n.throttleLastFireTs=c,{fire:!0,deferred:!1});if(!r)return{fire:!1,deferred:!1,reason:"throttle-window"};const a=null!==n.throttleTrailingPendingChainId?{chainId:n.throttleTrailingPendingChainId,payload:n.throttleTrailingPendingPayload}:void 0;if(n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,null===n.throttleTrailingTimer){const t=s-(c-i);return{fire:!1,deferred:!0,scheduleDeferred:o=>{n.throttleTrailingTimer=setTimeout(()=>{ye(n,e,o)},t)}}}return{fire:!1,deferred:!1,reason:"throttle-window",droppedByReschedule:a}}if(null===n.throttleWindowStartTs)return n.throttleWindowStartTs=c,n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,{fire:!1,deferred:!0,reason:"leading-disabled",scheduleDeferred:t=>{n.throttleTrailingTimer=setTimeout(()=>{ye(n,e,t)},s)}};const d=null!==n.throttleTrailingPendingChainId?{chainId:n.throttleTrailingPendingChainId,payload:n.throttleTrailingPendingPayload}:void 0;return n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,{fire:!1,deferred:!1,reason:"throttle-window",droppedByReschedule:d}}(e,n,t,o)}(e.schedule,function(e){let n=x.get(e);return n||(n={onceConsumed:!1,throttleLastFireTs:null,throttleWindowStartTs:null,throttleTrailingPendingPayload:void 0,throttleTrailingPendingChainId:null,throttleTrailingTimer:null,debouncePendingTimer:null,debouncePendingPayload:void 0,debouncePendingChainId:null,debounceDirty:!1,debounceLeadingFireTs:null},x.set(e,n)),n}(e.id),n,t),i=function(e){if(e)return e.throttle?{kind:"throttle",windowMs:e.throttle.windowMs,leading:e.throttle.leading,trailing:e.throttle.trailing}:e.debounce?{kind:"debounce",windowMs:e.debounce.windowMs,leading:e.debounce.leading,trailing:e.debounce.trailing}:void 0}(e.schedule);o.droppedByReschedule&&m({kind:"scheduled-dropped",bindingId:e.id,chainId:o.droppedByReschedule.chainId,payload:o.droppedByReschedule.payload,schedule:i}),o.scheduleDeferred&&o.scheduleDeferred((n,t)=>{u||(m({kind:"scheduled-flushed",bindingId:e.id,chainId:t,payload:n,schedule:i}),H(e,n,t))}),o.reason?m({kind:"scheduled-skipped",bindingId:e.id,chainId:t,reason:o.reason,payload:n,schedule:i}):!o.deferred||o.fire?o.fire&&H(e,n,t):m({kind:"scheduled-deferred",bindingId:e.id,chainId:t,payload:n,schedule:i})}function H(e,t,o){if(u)return;const i=n.getInstance(e.target.instanceId,a);if(!i)return void j({bindingId:e.id,code:"target-not-mounted"},{chainId:o});let r,s;try{r=he(e.mapping,t)}catch(n){return m({kind:"mapping-failed",bindingId:e.id,chainId:o,message:n instanceof Error?n.message:String(n),detail:n}),void("stop"===fe(e.errorPolicy,n,e.id)&&b.add(e.id))}if("instanceDataInput"===e.target.kind){const n=i.vm.custom,a=null==n?void 0:n[e.target.key];if(!a||"object"!=typeof a||!0!==a.dataInput)return void j({bindingId:e.id,code:"unknown-target-data-input",message:n&&e.target.key in n?`target.key "${e.target.key}" on instance "${e.target.instanceId}" is not declared with dataInput:true`:`target.key "${e.target.key}" not declared on instance "${e.target.instanceId}"`},{chainId:o});try{i.setDataInput(e.target.key,r[0])}catch(n){return"stop"===fe(e.errorPolicy,n,e.id)&&b.add(e.id),void j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o})}return void F({bindingId:e.id,source:e.source,target:e.target,payload:t,args:r},o)}l++;try{s=function(e,n,t){switch(n.kind){case"instanceMethod":return e.call(n.method,...t);case"instanceEmit":return void e.emit(n.event,t[0]);default:return}}(i,e.target,r),F({bindingId:e.id,source:e.source,target:e.target,payload:t,args:r},o)}catch(n){return"stop"===fe(e.errorPolicy,n,e.id)&&b.add(e.id),void j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o})}finally{l--}var c;"object"==typeof(c=s)&&null!==c&&"function"==typeof c.then&&Promise.resolve(s).catch(n=>{u||("stop"===fe(e.errorPolicy,n,e.id)&&b.add(e.id),j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o}))})}const X=null==(o=r.onAction)?void 0:o.call(r,e=>{var n,t,o,i;if(u)return;if("off"===d)return;const a=e;if(a&&"object"==typeof a)switch(a.type){case"addBinding":{const e=null==(t=null==(n=a.payload)?void 0:n.binding)?void 0:t.id;if(!e)return;const o=A(e);o&&q(o);break}case"updateBinding":{const e=null==(o=a.payload)?void 0:o.bindingId;if(!e)return;V(e);const n=A(e);n&&q(n);break}case"removeBinding":{const e=null==(i=a.payload)?void 0:i.bindingId;if(!e)return;V(e),b.delete(e);break}case"replaceDocument":_(),b.clear(),k.clear(),J();break;case"removeInstance":!function(){const e=new Set($().map(e=>e.id));for(const n of[...w.keys()])e.has(n)||(V(n),b.delete(n));for(const e of $())q(e)}()}});X&&C.push(X);const Y=null==(i=r.onDocumentChange)?void 0:i.call(r,()=>{if(u)return;if("off"===d)return;const e=$(),n=new Set(e.map(e=>e.id)),t=new Set(w.keys());for(const e of t)n.has(e)||V(e);for(const n of e)w.has(n.id)?O(n,M.get(n.id))&&(V(n.id),q(n)):q(n)});function G(){return new Set(n.listInstances({canvasId:a}).map(e=>e.instanceId))}Y&&C.push(Y),T=G();const W=e.watch(n.registryVersion,()=>{if(u)return;if("off"===d)return;const e=G(),n=Be(e,T),t=Be(T,e);T=e;for(const n of[...k]){const t=A(n);t?Q(t,e)&&(k.delete(n),q(t)):k.delete(n)}if(t.size>0)for(const e of[...w.keys()]){const n=A(e);n&&K(n).some(e=>D(e)&&t.has(e.instanceId))&&(V(e),k.add(e))}!function(e){if(0!==e.size)for(const n of $())"lifecycle"===n.source.kind&&"mounted"===n.source.hook&&D({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&U(n,{instanceId:n.source.instanceId,hook:"mounted"})}(n),function(e){if(0!==e.size)for(const n of $())"lifecycle"===n.source.kind&&"unmounted"===n.source.hook&&D({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&U(n,{instanceId:n.source.instanceId,hook:"unmounted"})}(t)},{flush:"post"});function Q(e,n){for(const t of K(e)){if(!D(t))return!1;if(!n.has(t.instanceId))return!1}return!0}return z.push(W),{setMode:function(e){u||e!==d&&(_(!0),b.clear(),k.clear(),d=e,"off"!==e&&J(),"runtime"===e&&function(){for(const e of $())"page"===e.source.kind&&"pageInit"===e.source.hook&&U(e,{hook:"pageInit"})}())},getMode:()=>d,testBinding(e,t){const o=[],i=A(e);if(!i)return o.push({bindingId:e,phase:"skipped",details:{reason:"binding-not-found"}}),o;if(i.disabled)return o.push({bindingId:e,phase:"skipped",details:{reason:"disabled"}}),o;if(P(i))return o.push({bindingId:e,phase:"skipped",details:{reason:"unsupported-cross-canvas"}}),o;let r;try{r=he(i.mapping,t),o.push({bindingId:e,phase:"mapping",details:{payload:t,args:r}})}catch(n){return o.push({bindingId:e,phase:"error",details:{stage:"mapping",message:n instanceof Error?n.message:String(n)}}),o}const s=n.getInstance(i.target.instanceId,a);if(!s)return o.push({bindingId:e,phase:"skipped",details:{reason:"target-not-mounted"}}),o;if("instanceDataInput"===i.target.kind){const n=s.vm.custom,t=null==n?void 0:n[i.target.key];if(!t||"object"!=typeof t||!0!==t.dataInput)return o.push({bindingId:e,phase:"skipped",details:{reason:"unknown-target-data-input",key:i.target.key}}),o}return o.push({bindingId:e,phase:"calling-target",details:{target:i.target,dryRun:!0}}),o.push({bindingId:e,phase:"done",details:{args:r}}),o},on:(e,n)=>L.on(e,n),startTracing(e){E.start(e)},stopTracing:()=>E.stop(),getTraceBuffer:()=>E.snapshot(),dispose:function(){if(!u){"runtime"===d&&function(){for(const e of $())"page"===e.source.kind&&"pageBeforeUnmount"===e.source.hook&&U(e,{hook:"pageBeforeUnmount"})}(),u=!0,_();for(const e of C)N(e);for(const e of z)N(e);C.length=0,z.length=0,b.clear(),k.clear(),S.clear(),B.clear(),M.clear(),T.clear(),x.clear(),E.stop(),L.clear(),I(),d="off"}}}}function Be(e,n){const t=new Set;for(const o of e)n.has(o)||t.add(o);return t}const Me=["display","gridTemplateColumns","gridTemplateRows","gridAutoFlow","flexDirection","flexWrap","gap","rowGap","columnGap","justifyContent","alignItems","position"];function Te(e,t){const o="string"==typeof(null==e?void 0:e.js)?e.js:"",i="string"==typeof(null==e?void 0:e.html)?e.html:"",a=n.parseComponentSource(o,i);return!a.ok&&(null==t?void 0:t.fallback)?t.fallback:{propsDecl:a.propsDecl.map(ze),emitsDecl:a.emitsDecl.map(Ee),methodsDecl:a.methodsDecl.map(Le),slotsDecl:a.slotsDecl.map(De),modelDecl:a.modelDecl.map(Pe),dataInputsDecl:a.dataInputsDecl.map(Re),dataOutputsDecl:a.dataOutputsDecl.map(Re)}}function Ce(e){if("string"===e||"number"===e||"boolean"===e||"object"===e||"array"===e||"any"===e)return e}function ze(e){const n=e.key,t="string"==typeof e.name?e.name:void 0;return{key:n,type:Ce(e.type)??"string",...void 0!==e.value?{value:e.value}:{},...t&&t!==n?{label:t}:{},...e.enum?{enum:e.enum}:{}}}function Le(e){return{key:e.name,...e.params?{params:e.params}:{}}}function Ee(e){return{event:e.event}}function De(e){return{name:e.name,...void 0!==e.multiple?{multiple:e.multiple}:{},...void 0!==e.accepts?{accepts:e.accepts}:{},...void 0!==e.maxChildren?{maxChildren:e.maxChildren}:{},...void 0!==e.label?{label:e.label}:{}}}function Pe(e){const n=Ce(e.type);return{key:e.key,...void 0!==e.prop?{prop:e.prop}:{},...void 0!==e.event?{event:e.event}:{},...n?{type:n}:{},...void 0!==e.defaultValue?{defaultValue:e.defaultValue}:{}}}function Re(e){const n=Ce(e.type);return{key:e.key,...n?{type:n}:{},...void 0!==e.label?{label:e.label}:{}}}const Oe=["data-hc-canvas-id"],$e=["data-instance-id","data-hc-hidden"],Ae={key:0,class:"hc-page-instance-fallback",style:{width:"100%",height:"100%",border:"2px dashed #f59e0b",background:"#fef3c7",color:"#92400e",padding:"8px",fontSize:"11px",fontFamily:"monospace",overflow:"hidden",borderRadius:"4px",boxSizing:"border-box"}},Ne={style:{opacity:"0.8"}},Fe={style:{opacity:"0.6","margin-top":"4px","word-break":"break-all"}},je={key:2,class:"hc-page-instance-skeleton",style:{width:"100%",height:"100%",background:"linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%)",backgroundSize:"200% 100%",animation:"hc-skeleton-shimmer 1.5s infinite ease-in-out",borderRadius:"4px",boxSizing:"border-box"}},Ve=["data-instance-id","data-hc-placement","data-hc-hidden"],_e={key:0,class:"hc-page-instance-fallback",style:{width:"100%",height:"100%",border:"2px dashed #f59e0b",background:"#fef3c7",color:"#92400e",padding:"8px","font-size":"11px","font-family":"monospace",overflow:"hidden","border-radius":"4px","box-sizing":"border-box"}},qe={style:{opacity:"0.6"}},Ke=["title"],Je={key:1,class:"hc-page-renderer-empty",style:{padding:"24px",color:"#64748b","font-size":"13px"}},Ue=e.defineComponent({__name:"HyperCardPageRenderer",props:{payload:{},document:{},componentSourceMap:{},schedulerOptions:{},canvasId:{},adapters:{}},setup(t,{expose:o}){var i,s;const c=t,d=c.canvasId??function(){var e;const n="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`auto-${(null==(e=null==n?void 0:n.randomUUID)?void 0:e.call(n).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}();e.provide(n.HC_CANVAS_ID_KEY,d);const l=q(c.schedulerOptions),u=e.ref(null);let g=!1;e.onMounted(()=>{X||e.nextTick(()=>{var e;if(g)return;if(!u.value)return;if("fill"!==(null==(e=U.value)?void 0:e.canvas.height.mode))return;const n=u.value.parentElement;n&&(n.getBoundingClientRect().height>0||(g=!0,console.warn("[hypercard] HyperCardPageRenderer 父容器高度为 0,fill 模式画布不可见。请给父容器设置明确 height 或改用 px 模式。")))})}),e.onBeforeUnmount(()=>{r(d),G.value&&(G.value.dispose(),G.value=null),l.dispose(),W&&W.disposeAll(),d!==n.DEFAULT_CANVAS_ID&&n.disposeCanvas(d)});const m=e.ref(new Map),v=e.ref(new Map),y=new Map,I=e.ref(!1);let w=null;function x(){I.value=!1,w&&clearTimeout(w),w=setTimeout(()=>{I.value=!0},300)}function b(e,n){const t=new Map;if(n.querySelectorAll("[data-hc-slot]").forEach(e=>{if(e.closest("[data-instance-id]")!==n)return;const o=e.getAttribute("data-hc-slot")||se;t.has(o)||t.set(o,e)}),function(e,n){if(!e||e.size!==n.size)return!1;for(const[t,o]of n)if(e.get(t)!==o)return!1;return!0}(v.value.get(e),t))return;const o=new Map(v.value);o.set(e,t),v.value=o,k(e,t)}function k(e,n){const t=n.get(se);if(!t)return;const o=B.value,i=null==o?void 0:o.instances.find(n=>n.instanceId===e);!function(e,n){!function(e){const n=e.style;for(const e of Me)n[e]=""}(e);const t=null==n?void 0:n.mode;if(!n||"none"===t||void 0===t)return;if("free"===t)return void(e.style.position="relative");const o=z(n);o&&Object.assign(e.style,o)}(t,null==i?void 0:i.containerLayout)}function S(e,n){const t=m.value.get(e);n&&n!==t?(m.value.set(e,n),l.register(e,n),function(e,n){const t=y.get(e);t&&t.disconnect(),b(e,n);const o=new MutationObserver(()=>b(e,n));o.observe(n,{childList:!0,subtree:!0}),y.set(e,o)}(e,n)):!n&&t&&(l.unregister(e),m.value.delete(e),function(e){const n=y.get(e);if(n&&(n.disconnect(),y.delete(e)),v.value.has(e)){const n=new Map(v.value);n.delete(e),v.value=n}}(e))}e.onMounted(x),e.watch(v,x),e.onBeforeUnmount(()=>{for(const e of y.values())e.disconnect();y.clear(),v.value=new Map,w&&clearTimeout(w)});const B=e.computed(()=>{var e;const n=(null==(e=c.payload)?void 0:e.document)??c.document??null;return n?h(f(p(n))):null});e.watch(B,()=>{e.nextTick(()=>function(){for(const[e,n]of v.value)k(e,n)}())},{flush:"post"});const M=e.computed(()=>function(e){const n={};for(const t of Object.keys(e)){const o=e[t],i=o.source;o&&"ok"===o.status&&i&&("string"==typeof i.html||"string"==typeof i.js)?n[t]={...o,contract:Te({html:i.html??"",js:i.js??"",css:i.css??""},{fallback:o.contract})}:n[t]=o}return n}(c.payload?c.payload.componentVersions:c.componentSourceMap??{})),C=e.computed(()=>{const e=B.value,n=M.value;return e?e.instances.map(t=>{var o;const i=n[t.componentVersionKey]??null,a=(null==(o=e.componentOverrides)?void 0:o[t.instanceId])??null,r=a&&a.baseVersionKey===t.componentVersionKey?a:null,s=r?`${r.baseVersionKey}#override:${t.instanceId}`:t.componentVersionKey;if(r)return{instance:t,asset:i,override:r,renderSource:r.source,scopeId:s,status:"ok"};if(!i)return{instance:t,asset:null,override:null,renderSource:null,scopeId:s,status:"missing-source",invalidReason:`componentVersionKey "${t.componentVersionKey}" not in sourceMap`};if("ok"!==i.status)return{instance:t,asset:i,override:null,renderSource:null,scopeId:s,status:"unavailable",invalidReason:i.invalidReason??`component version unavailable (${i.status})`};let c=null;return c=function(e){return!!e&&!0===e.isDraft}(i)?i.lastGoodSource:i.source??null,c?{instance:t,asset:i,override:null,renderSource:c,scopeId:s,status:"ok"}:{instance:t,asset:i,override:null,renderSource:null,scopeId:s,status:"missing-source",invalidReason:"asset.status=ok but source missing"}}):[]});function D(e){const n=M.value[e];return null==n?void 0:n.contract}const P=e.computed(()=>{const e=B.value;return e?de(e,{resolveContract:D}):[]}),R=e.inject(oe,null);e.watch(P,e=>{R&&"function"==typeof R.setLayoutIssues&&R.setLayoutIssues(e)},{immediate:!0});const O=e.computed(()=>{const e=new Set;for(const n of P.value)"missing-parent"!==n.kind&&"invalid-slot"!==n.kind&&"parent-not-layout"!==n.kind&&"orphan-slot"!==n.kind&&"cycle"!==n.kind&&"absolute-child-rejected"!==n.kind||e.add(n.instanceId);return e}),$=e.computed(()=>C.value.filter(e=>void 0===e.instance.parentId)),A=e.computed(()=>C.value.filter(e=>void 0!==e.instance.parentId&&j(e.instance.placement)));function N(e){const n=e.layoutBox??{x:e.rect.x,y:e.rect.y,width:e.rect.w,height:e.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},t=function(e){const n=B.value;if(n)return V(U.value??void 0,n.instances,e.instanceId)}(e),o=T(n,e.zIndex,e.rotation,t,function(e){var n,t;const o=B.value;if(!o)return;if(void 0===e.parentId){const e=null==(n=U.value)?void 0:n.rootLayout;return"split"===(null==e?void 0:e.mode)?e.direction:void 0}const i=null==(t=o.instances.find(n=>n.instanceId===e.parentId))?void 0:t.containerLayout;return"split"===(null==i?void 0:i.mode)?i.direction:void 0}(e)),i=L(e.layoutItem,t);return i&&Object.assign(o,i),o}const F=e.computed(()=>{var e;return z(null==(e=U.value)?void 0:e.rootLayout)});function _(e){if(!e.parentId)return null;const n=v.value.get(e.parentId);return n?n.get(ce(e))??null:null}function K(e){return{position:"absolute",left:"8px",top:8+28*A.value.indexOf(e)+"px",padding:"4px 8px",background:"hsla(40, 90%, 50%, 0.95)",color:"#5b3a00",fontSize:"11px",fontFamily:"ui-monospace, monospace",borderRadius:"4px",zIndex:9999,maxWidth:"60%",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap"}}function J(e){return"实例 "+e.instance.instanceId+':slot "'+ce(e.instance)+'" 不可用'}const U=e.computed(()=>{var e;return(null==(e=B.value)?void 0:e.layout)??null}),H=e.computed(()=>{if(!U.value)return null;if(X){const e=X.measuredCanvasSize.value;return{width:`${e.w}px`,height:`${e.h}px`,overflow:U.value.canvas.overflow??"hidden"}}return{width:E(U.value.canvas.width),height:E(U.value.canvas.height),overflow:U.value.canvas.overflow??"hidden"}}),X=e.inject(oe,void 0),Y=X?null:Z(null==(i=c.adapters)?void 0:i.assets),G=e.shallowRef(null),W=X||!(null==(s=c.adapters)?void 0:s.data)?null:te(c.adapters.data);if(!X){const n=Se({canvasId:d,source:{getDocument:()=>B.value,onDocumentChange:n=>e.watch(B,n,{flush:"post"})},dataStore:W??void 0});G.value=n,e.nextTick(()=>{n.setMode("runtime")})}const Q=X?{invalidateDataSource(e){X.dataStore.invalidate(e)},getDataSourceSnapshot:()=>X.dataStore.getSnapshot(),getCachedBySourceId:(e,n)=>X.dataStore.getCachedBySourceId(e,n)}:W?{invalidateDataSource(e){W.invalidate(e)},getDataSourceSnapshot:()=>W.getSnapshot(),getCachedBySourceId:(e,n)=>W.getCachedBySourceId(e,n)}:null,ee={canvasId:d,getSchedulerStats:()=>l.getStats(),listRuntimeInstances:()=>function(){const e=B.value;if(!e)return[];const t=new Map;for(const e of P.value)t.set(e.instanceId,!0);const o=l.state;return e.instances.map(e=>{const i=o[e.instanceId];let a,r;switch(i){case"mounting":case"mounted":case"disposing":a=i;break;default:a="pending"}if(t.has(e.instanceId))r="layout-error";else if(e.componentId){const n=e.source;r=!n||n.template||n.script||n.style?"ok":"missing-source"}else r="missing-componentId";return{instanceId:e.instanceId,componentId:e.componentId,mountState:a,timings:n.getInstanceTimings(d,e.instanceId),protocolStatus:r}})}(),getInstanceTimings:e=>n.getInstanceTimings(d,e),getLayoutIssues:()=>P.value,getPageDocument:()=>B.value};e.onMounted(()=>{a(d,ee)}),o({binding:G,data:Q});const ne=e.ref(null);let ie=0;e.watch(()=>{var e,n;return null==(n=null==(e=U.value)?void 0:e.background)?void 0:n.image},e=>{ie++;const n=ie;if(!e)return void(ne.value=null);const t=(o=e,X?X.resolveAsset(o):Y.resolve(o));var o;"string"!=typeof t?(ne.value=null,t.then(t=>{var o,i;n===ie&&(null==(i=null==(o=U.value)?void 0:o.background)?void 0:i.image)===e&&(ne.value=t||null)},()=>{n===ie&&(ne.value=null)})):ne.value=t||null},{immediate:!0,deep:!0});const ae=e.computed(()=>{var e;const n=null==(e=U.value)?void 0:e.background;if(!n)return null;const t={position:"absolute",inset:"0",pointerEvents:"none",zIndex:-1};return n.color&&(t.background=n.color),n.image&&ne.value&&(t.backgroundImage=`url("${ne.value}")`,t.backgroundRepeat="repeat"===n.imageFit?"repeat":"no-repeat",t.backgroundPosition=n.imagePosition??"center","stretch"===n.imageFit?t.backgroundSize="100% 100%":n.imageFit&&"repeat"!==n.imageFit&&"center"!==n.imageFit&&(t.backgroundSize=n.imageFit)),void 0!==n.opacity&&(t.opacity=n.opacity),t});return(t,o)=>U.value&&H.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"rootEl",ref:u,class:"hc-page-renderer","data-hc-canvas-id":e.unref(d),style:e.normalizeStyle({position:"relative",...H.value,...F.value??{}})},[ae.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-canvas-bg","data-hc-canvas-bg":"",style:e.normalizeStyle(ae.value)},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList($.value,t=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:t.instance.instanceId,ref_for:!0,ref:e=>S(t.instance.instanceId,e),"data-instance-id":t.instance.instanceId,"data-hc-hidden":t.instance.hidden?"true":void 0,style:e.normalizeStyle(N(t.instance))},["ok"===t.status&&t.renderSource?e.unref(l).isMounted(t.instance.instanceId)?(e.openBlock(),e.createBlock(e.unref(n.RuntimeBox),{key:1,"canvas-id":e.unref(d),"instance-id":t.instance.instanceId,"component-id":t.instance.componentId,"scope-id":t.scopeId,"html-source":t.renderSource.html,"js-source":t.renderSource.js,"css-source":t.renderSource.css,"custom-values":{...t.instance.props,__containerLayout:t.instance.containerLayout}},null,8,["canvas-id","instance-id","component-id","scope-id","html-source","js-source","css-source","custom-values"])):(e.openBlock(),e.createElementBlock("div",je)):(e.openBlock(),e.createElementBlock("div",Ae,[o[0]||(o[0]=e.createElementVNode("div",{style:{"font-weight":"600","margin-bottom":"4px"}}," ⚠️ 组件不可渲染 ",-1)),e.createElementVNode("div",Ne,e.toDisplayString(t.instance.alias??t.instance.instanceId),1),e.createElementVNode("div",Fe,e.toDisplayString(t.invalidReason),1)]))],12,$e)),[[e.vShow,!t.instance.hidden]])),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(A.value,t=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`child-${t.instance.instanceId}`},[_(t.instance)&&!O.value.has(t.instance.instanceId)?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:_(t.instance)},[e.withDirectives(e.createElementVNode("div",{ref_for:!0,ref:e=>S(t.instance.instanceId,e),"data-instance-id":t.instance.instanceId,"data-hc-placement":t.instance.placement,"data-hc-hidden":t.instance.hidden?"true":void 0,style:e.normalizeStyle(N(t.instance))},["ok"===t.status&&t.renderSource?(e.openBlock(),e.createBlock(e.unref(n.RuntimeBox),{key:1,"canvas-id":e.unref(d),"instance-id":t.instance.instanceId,"component-id":t.instance.componentId,"scope-id":t.scopeId,"html-source":t.renderSource.html,"js-source":t.renderSource.js,"css-source":t.renderSource.css,"custom-values":{...t.instance.props,__containerLayout:t.instance.containerLayout}},null,8,["canvas-id","instance-id","component-id","scope-id","html-source","js-source","css-source","custom-values"])):(e.openBlock(),e.createElementBlock("div",_e,[o[1]||(o[1]=e.createElementVNode("div",{style:{"font-weight":"600"}},"⚠️ 组件不可渲染",-1)),e.createElementVNode("div",qe,e.toDisplayString(t.invalidReason),1)]))],12,Ve),[[e.vShow,!t.instance.hidden]])],8,["to"])):O.value.has(t.instance.instanceId)||I.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-layout-issue-warning",title:J(t),style:e.normalizeStyle(K(t))}," ⚠ 布局问题:"+e.toDisplayString(t.instance.instanceId)+'(slot "'+e.toDisplayString(e.unref(ce)(t.instance))+'") ',13,Ke)):e.createCommentVNode("",!0)],64))),128))],12,Oe)):(e.openBlock(),e.createElementBlock("div",Je," No page to render(payload / document 都未提供) "))}}),He=new Map,Xe=new Set;function Ye(){const e=Object.freeze(Array.from(He.keys()));for(const n of Xe)try{n(e)}catch{}}function Ge(e,n){He.set(e,n),Ye()}function We(e){He.delete(e)&&Ye()}function Qe(e,n){var t;const o=n.document;switch(e.type){case"addInstance":{const{instance:n}=e.payload;return o.getInstance(n.instanceId)?null:[{type:"removeInstance",payload:{instanceId:n.instanceId}}]}case"removeInstance":{const{instanceId:n}=e.payload,t=o.getInstance(n);if(!t)return null;const i=o.document.bindings.filter(e=>J(e,n)),a=[{type:"addInstance",payload:{instance:en(t)}}];for(const e of i)a.push({type:"addBinding",payload:{binding:s(e)}});return a}case"updateInstance":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a={};for(const e of Object.keys(t)){const n=i[e];a[e]=Ze(n)?s(n):n}return[{type:"updateInstance",payload:{instanceId:n,patch:a}}]}case"moveInstance":{const{instanceId:n,x:t,y:i}=e.payload,a=o.getInstance(n);return a?a.rect.x===t&&a.rect.y===i?null:a.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...a.layoutBox}}}]:[{type:"moveInstance",payload:{instanceId:n,x:a.rect.x,y:a.rect.y}}]:null}case"resizeInstance":{const{instanceId:n,w:t,h:i}=e.payload,a=o.getInstance(n);return a?a.rect.w===t&&a.rect.h===i?null:a.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...a.layoutBox}}}]:[{type:"resizeInstance",payload:{instanceId:n,w:a.rect.w,h:a.rect.h}}]:null}case"setInstanceProp":{const{instanceId:n,key:t,value:i}=e.payload,a=o.getInstance(n);return a?a.props[t]===i?null:[{type:"updateInstance",payload:{instanceId:n,patch:{props:{...a.props}}}}]:null}case"addBinding":{const{binding:n}=e.payload;return o.document.bindings.some(e=>e.id===n.id)?null:[{type:"removeBinding",payload:{bindingId:n.id}}]}case"removeBinding":{const{bindingId:n}=e.payload,t=o.document.bindings.find(e=>e.id===n);return t?[{type:"addBinding",payload:{binding:s(t)}}]:null}case"updateBinding":{const{bindingId:n,patch:t}=e.payload,i=o.document.bindings.find(e=>e.id===n);if(!i)return null;const a={};for(const e of Object.keys(t)){const n=i[e];a[e]=Ze(n)?s(n):n}return[{type:"updateBinding",payload:{bindingId:n,patch:a}}]}case"updateLayout":{const{patch:n}=e.payload,t={};for(const e of Object.keys(n)){const n=o.document.layout[e];t[e]=Ze(n)?s(n):n}return[{type:"updateLayout",payload:{patch:t}}]}case"setRootLayout":{const{rootLayout:n}=e.payload,t=o.document.layout.rootLayout,i=void 0!==t;return i||null!==n?[{type:"setRootLayout",payload:{rootLayout:i?s(t):null}}]:null}case"setComponentOverride":{const{instanceId:n,override:i}=e.payload;if(void 0===o.getInstance(n))return null;const a=null==(t=o.document.componentOverrides)?void 0:t[n],r=void 0!==a;return r||null!==i?[{type:"setComponentOverride",payload:{instanceId:n,override:r?s(a):null}}]:null}case"replaceDocument":return[{type:"replaceDocument",payload:{document:s(o.document)}}];case"setInstanceLocked":{const{instanceId:n,locked:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.locked??!1,r=i.lockPosition,s=i.lockSize;return a===t&&r===(!!t||void 0)&&s===(!!t||void 0)?null:[{type:"updateInstance",payload:{instanceId:n,patch:{locked:a,lockPosition:r,lockSize:s}}}]}case"duplicateInstance":{const{instanceId:n,newInstanceId:t}=e.payload;return o.getInstance(n)?o.getInstance(t)?null:[{type:"removeInstance",payload:{instanceId:t}}]:null}case"setInstanceSize":{const{instanceId:n,size:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.size,r="size"in i&&void 0!==a;return r||null!==t?[{type:"setInstanceSize",payload:{instanceId:n,size:(r?s(a):null)??null}}]:null}case"setContainerLayout":{const{instanceId:n,containerLayout:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.containerLayout,r="containerLayout"in i&&void 0!==a;return r||null!==t?[{type:"setContainerLayout",payload:{instanceId:n,containerLayout:(r?s(a):null)??null}}]:null}case"updateLayoutBox":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.layoutBox??{x:i.rect.x,y:i.rect.y,width:i.rect.w,height:i.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},r={};let s=!1;const c=["x","y","width","height"];for(const e of c){const n=t[e];"number"==typeof n&&Number.isFinite(n)&&(r[e]=a[e],s=!0)}return"px"!==t.widthMode&&"percent"!==t.widthMode&&"fill"!==t.widthMode&&"auto"!==t.widthMode||(r.widthMode=a.widthMode,s=!0),"px"!==t.heightMode&&"percent"!==t.heightMode&&"fill"!==t.heightMode&&"auto"!==t.heightMode||(r.heightMode=a.heightMode,s=!0),"hidden"!==t.overflow&&"visible"!==t.overflow&&"auto"!==t.overflow||(r.overflow=a.overflow,s=!0),s?[{type:"updateLayoutBox",payload:{instanceId:n,patch:r}}]:null}case"updateLayoutItem":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.layoutItem,r="layoutItem"in i&&void 0!==a,c=null===t;if(!r&&c)return null;if(!c){const e=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"];let n=!1;for(const o of e){const e=t[o];if("number"==typeof e&&Number.isFinite(e)){n=!0;break}}if(!n)return null}return[{type:"updateLayoutItem",payload:{instanceId:n,patch:(r?s(a):null)??null}}]}case"updateRotation":{const{instanceId:n,value:t}=e.payload,i=o.getInstance(n);if(!i)return null;if(!Number.isFinite(t))return null;const a=i.rotation,r="number"==typeof a&&Number.isFinite(a)?a:0;return r===t?null:[{type:"updateRotation",payload:{instanceId:n,value:r}}]}case"select":case"toggleSelect":case"addToSelection":case"removeFromSelection":case"clearSelection":case"selectAll":return null;default:{const n=e;return console.warn("[hc-canvas/computeInverse] unknown action",n),null}}}function Ze(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function en(e){return s(e)}function nn(n,t={}){const o=t.maxSize??100,i=e.ref([]),a=e.ref([]);let r={redo:[],undo:[]},s=null;function c(e){var n;0===r.redo.length&&0===r.undo.length||(n={type:e,redo:r.redo,undo:r.undo,timestamp:Date.now()},i.value.push(n),i.value.length>o&&i.value.shift(),a.value.length>0&&(a.value=[]),r={redo:[],undo:[]},s=null)}const d={onBeforeAction(e){if(n.isRecordingSuppressed.value)return;const t=Qe(e,n);if(null!==t){r.redo.push(e);for(let e=t.length-1;e>=0;e--)r.undo.unshift(t[e]);s=e.type}},onAfterAction(e){n.isRecordingSuppressed.value||n.isBatching.value||c(s??"action")},onAfterBatch(e){n.isRecordingSuppressed.value||c(e??"batch")}},l=n.registerHooks(d);function u(){i.value=[],a.value=[],r={redo:[],undo:[]},s=null}return{undo:function(){if(0===i.value.length)return;const e=i.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.undo)n.dispatch(t);n.endBatch("undo")}),a.value.push(e)},redo:function(){if(0===a.value.length)return;const e=a.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.redo)n.dispatch(t);n.endBatch("redo")}),i.value.push(e)},clear:u,canUndo:e.computed(()=>i.value.length>0),canRedo:e.computed(()=>a.value.length>0),undoStackSize:e.computed(()=>i.value.length),redoStackSize:e.computed(()=>a.value.length),dispose:function(){l(),u()}}}function tn(e,n,t){let o=null;for(const i of e)for(const e of n){const n=e.pos-i,a=Math.abs(n);a<=t&&(!o||a<Math.abs(o.delta))&&(o={delta:n,candidate:e,targetPos:i})}return o}function on(e){var n,t,o,i;const a=e.threshold??5,r=function(e){if(0===e.length)return null;let n=1/0,t=-1/0,o=1/0,i=-1/0;for(const a of e)a.x<n&&(n=a.x),a.x+a.w>t&&(t=a.x+a.w),a.y<o&&(o=a.y),a.y+a.h>i&&(i=a.y+a.h);return{left:n,right:t,top:o,bottom:i,centerX:(n+t)/2,centerY:(o+i)/2,width:t-n,height:i-o}}(e.draggedRects);if(!r)return{dx:0,dy:0,lines:[]};const s=function(e,n,t){const o=[];for(const n of e)o.push({pos:n.x,kind:"edge-left",source:n}),o.push({pos:n.x+n.w,kind:"edge-right",source:n}),o.push({pos:n.x+n.w/2,kind:"center-x",source:n});if(o.push({pos:0,kind:"canvas-edge"}),o.push({pos:n.w,kind:"canvas-edge"}),o.push({pos:n.w/2,kind:"canvas-edge"}),t)for(const e of t)o.push({pos:e,kind:"guide"});return o}(e.otherRects,e.canvasSize,null==(n=e.manualGuides)?void 0:n.x),c=function(e,n,t){const o=[];for(const n of e)o.push({pos:n.y,kind:"edge-top",source:n}),o.push({pos:n.y+n.h,kind:"edge-bottom",source:n}),o.push({pos:n.y+n.h/2,kind:"center-y",source:n});if(o.push({pos:0,kind:"canvas-edge"}),o.push({pos:n.h,kind:"canvas-edge"}),o.push({pos:n.h/2,kind:"canvas-edge"}),t)for(const e of t)o.push({pos:e,kind:"guide"});return o}(e.otherRects,e.canvasSize,null==(t=e.manualGuides)?void 0:t.y),d=[r.left,r.right,r.centerX],l=[r.top,r.bottom,r.centerY],u=tn(d,s,a),p=tn(l,c,a),f=(null==u?void 0:u.delta)??0,h=(null==p?void 0:p.delta)??0,g=[];if(u){const n=(null==(o=u.candidate.source)?void 0:o.y)??0,t=u.candidate.source?u.candidate.source.y+u.candidate.source.h:e.canvasSize.h,i=Math.min(r.top+h,n),a=Math.max(r.bottom+h,t);g.push({axis:"x",pos:u.candidate.pos,from:i,to:a,kind:u.candidate.kind})}if(p){const n=(null==(i=p.candidate.source)?void 0:i.x)??0,t=p.candidate.source?p.candidate.source.x+p.candidate.source.w:e.canvasSize.w,o=Math.min(r.left+f,n),a=Math.max(r.right+f,t);g.push({axis:"y",pos:p.candidate.pos,from:o,to:a,kind:p.candidate.kind})}return{dx:f,dy:h,lines:g}}function an(e,n,t){const o=new Map;for(let e=0;e<n.length;e++)o.set(n[e].instanceId,e);const i=new Map;function a(e){const t=i.get(e);if(t)return t;const o=[];let a=e;const r=new Set;for(;a&&!r.has(a);){r.add(a),o.push(a);const e=n.find(e=>e.instanceId===a);if(!(null==e?void 0:e.parentId))break;a=e.parentId}const s=o.reverse();return i.set(e,s),s}function r(e,t){const i=a(e),r=a(t);let s=0;for(;s<i.length&&s<r.length&&i[s]===r[s];)s++;if(s===i.length&&s===r.length)return 0;if(s===i.length)return-1;if(s===r.length)return 1;const c=i[s],d=r[s],l=n.find(e=>e.instanceId===c),u=n.find(e=>e.instanceId===d),p=(null==l?void 0:l.zIndex)??0,f=(null==u?void 0:u.zIndex)??0;return p!==f?p-f:(o.get(c)??-1)-(o.get(d)??-1)}let s=null,c=-1;for(let o=0;o<n.length;o++){const i=n[o];if(i.hidden)continue;const a=(null==t?void 0:t(i.instanceId))??i.rect;if(!(e.x>=a.x&&e.x<=a.x+a.w&&e.y>=a.y&&e.y<=a.y+a.h))continue;if(null===s){s=i.instanceId,c=o;continue}const d=r(i.instanceId,s);let l;l=d>0||!(d<0)&&o>c,l&&(s=i.instanceId,c=o)}return s}function rn(e,n){return{x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),w:Math.abs(e.x-n.x),h:Math.abs(e.y-n.y)}}function sn(e,n,t){const o=[];for(const i of n){if(i.hidden)continue;const n=(null==t?void 0:t(i.instanceId))??i.rect;n.x>=e.x&&n.y>=e.y&&n.x+n.w<=e.x+e.w&&n.y+n.h<=e.y+e.h&&o.push(i.instanceId)}return o}function cn(e,n){if(!e||"function"!=typeof e.querySelector)return null;const t=e.querySelector(n);if(t)return t;if(e instanceof Element&&"function"==typeof e.closest){const t=e.closest("[data-hc-canvas-designer]");if(t&&t!==e){const e=t.querySelector(n);if(e)return e}}return null}function dn(e,n,t){var o;const i=t??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!i)return null;const a=n??"default",r=""===a?"default":a,s="undefined"!=typeof globalThis&&(null==(o=globalThis.CSS)?void 0:o.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),c=cn(i,`[data-instance-id="${s(e)}"] [data-hc-slot="${s(r)}"]`);return c&&c instanceof HTMLElement?c.getBoundingClientRect():null}function ln(e,n,t){var o;const i=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!i)return null;if("function"!=typeof i.querySelector)return null;const a=`[data-instance-id="${("undefined"!=typeof globalThis&&(null==(o=globalThis.CSS)?void 0:o.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`))(e)}"]`,r=t?cn(i,a):i.querySelector(a);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null}function un(e,n){return V(e.document.document.layout,e.document.document.instances,n)}function pn(e){return"free"===e||"none"===e||void 0===e}const fn=new Set(["e","w","ne","nw","se","sw"]),hn=new Set(["n","s","ne","nw","se","sw"]);function gn(e,n,t,o){if(pn(e))return!0;const i=fn.has(n),a=hn.has(n);return!(i&&"fill"===t||a&&"fill"===o)}function mn(e,n,t){if(!n)return null;const o=ln(e,n,!0);if(!o)return null;const i=n.getBoundingClientRect(),a=t.toCanvasPoint({x:o.left-i.left,y:o.top-i.top}),r=t.toCanvasPoint({x:o.right-i.left,y:o.bottom-i.top});return{x:a.x,y:a.y,w:Math.max(0,r.x-a.x),h:Math.max(0,r.y-a.y)}}function vn(e,n,t){const o=Math.max(8,n);if(!e)return{mode:"px",value:o};switch(e.mode){case"px":return{...e,mode:"px",value:o};case"percent":{if(!t||t<=0)return{...e,mode:"px",value:o};const n=o/t*100,i=Math.max(0,Math.min(1e3,n));return{...e,mode:"percent",value:i}}case"fill":case"hug":case"auto":return{mode:"px",value:o,min:e.min,max:e.max}}}function yn(e,n,t){const o=Math.max(8,n);switch(e){case"px":case"fill":case"auto":default:return{mode:"px",value:o};case"percent":{if(!t||t<=0)return{mode:"px",value:o};const e=o/t*100;return{mode:"percent",value:Math.max(0,Math.min(1e3,e))}}}}function In(e){return e.shift||e.ctrl||e.meta}function wn(e,n,t){const o=n.getBoundingClientRect(),i={x:e.x-o.left,y:e.y-o.top};return t.toCanvasPoint(i)}function xn(e,n){const t=new Set(n.map(e=>e.instanceId));return e.filter(e=>t.has(e))}function bn(n,t={}){const o=e.reactive({active:!1,start:null,end:null,additive:!1,priorSelection:[]}),i=e.reactive({status:"idle",startPt:null,startRects:new Map,deferredClickSelect:null}),a=e.reactive({status:"idle",handle:null,startPt:null,startRect:null,instanceId:null,placement:null,parentLayoutMode:void 0,startSize:null,startLayoutBox:null,startOutletCanvasSize:null}),r=e.ref([]),s=e.ref(null);let c=0;const d=e.ref(null);let l=0;const u=e.computed(()=>o.active&&o.start&&o.end?rn(o.start,o.end):null),p=e.computed(()=>"active"===i.status),f=e.computed(()=>"active"===a.status);function h(){o.active=!1,o.start=null,o.end=null,o.additive=!1,o.priorSelection=[]}function g(){i.status="idle",i.startPt=null,i.startRects=new Map,i.deferredClickSelect=null,r.value=[]}function m(){a.status="idle",a.handle=null,a.startPt=null,a.startRect=null,a.instanceId=null,a.placement=null,a.startSize=null,a.startOutletCanvasSize=null,a.parentLayoutMode=void 0,a.startLayoutBox=null}return{marquee:o,marqueeRect:u,drag:i,isDragging:p,resize:a,isResizing:f,snapLines:r,cannotDragSlotChildEvent:s,cannotDragLayoutManagedChildEvent:d,handlePointerDown(e,a){var r;const u=n.effectiveBehavior.value;if(!u.selectable)return{startTracking:!1};const p=n.toolMode.value;if("hand"===p)return{startTracking:!1};const f=In(a),h="marquee"===p?null:an(e,n.document.document.instances,t.getDomBox);if(h){const t=n.document.getInstance(h),o=!0===((null==t?void 0:t.lockPosition)??(null==t?void 0:t.locked)),a=n.selection.selectedIds.value.includes(h),g=n.selection.size.value>1;f?n.dispatch({type:"toggleSelect",payload:{instanceId:h}}):o?n.dispatch({type:"select",payload:{instanceId:h}}):a&&g&&u.draggable&&"inspect"!==p?i.deferredClickSelect=h:n.dispatch({type:"select",payload:{instanceId:h}});const m="slot"===(null==t?void 0:t.placement)||"container"===(null==t?void 0:t.placement),v=un(n,h),y="inspect"===p;if(o||!u.draggable||y||(null==t?void 0:t.hidden))return{startTracking:!1};if(!pn(v)){if(!f){l++;const e={instanceId:h,parentId:null==t?void 0:t.parentId,parentLayoutMode:v,token:l};d.value=e,null==(r=n.setCannotDragLayoutManagedChildEvent)||r.call(n,e),m&&(c++,s.value={instanceId:h,parentId:null==t?void 0:t.parentId,token:c})}return{startTracking:!1}}return i.status="pending",i.startPt={...e},i.startRects=function(){const e=n.selection.selectedIds.value,t=new Map;for(const o of e){const e=n.document.getInstance(o);e&&!0!==(e.lockPosition??e.locked)&&t.set(o,{x:e.rect.x,y:e.rect.y})}return t}(),{startTracking:!0}}return f||n.dispatch({type:"clearSelection"}),o.active=!0,o.start={...e},o.end={...e},o.additive=f,o.priorSelection=f?[...n.selection.selectedIds.value]:[],{startTracking:!0}},handlePointerMove(e){var s,c;if("active"===a.status&&a.startPt&&a.startRect&&a.instanceId){const t=e.x-a.startPt.x,o=e.y-a.startPt.y,i=a.startRect,r=a.handle,s=n.document.getInstance(a.instanceId);if(!s)return;const c=a.parentLayoutMode,d=void 0!==c&&!pn(c);let l=i.x,u=i.y,p=i.w,f=i.h;const h="w"===r||"nw"===r||"sw"===r,g="e"===r||"ne"===r||"se"===r,m="n"===r||"ne"===r||"nw"===r,v="s"===r||"se"===r||"sw"===r;g?p=i.w+t:h&&(p=i.w-t,d||(l=i.x+t)),v?f=i.h+o:m&&(f=i.h-o,d||(u=i.y+o)),p<8&&(!d&&h&&(l=i.x+i.w-8),p=8),f<8&&(!d&&m&&(u=i.y+i.h-8),f=8);const y=a.startLayoutBox,I=a.startOutletCanvasSize,w=g||h,x=v||m,b=!d&&h,k=!d&&m,S=w?yn(y.widthMode,p,I?I.w:null):null,B=x?yn(y.heightMode,f,I?I.h:null):null,M="canvas"===a.placement||"absolute"===a.placement,T=!(S&&"px"!==S.mode||B&&"px"!==B.mode||w&&"px"!==y.widthMode||x&&"px"!==y.heightMode);if(M&&T)(w&&s.rect.w!==p||x&&s.rect.h!==f)&&n.dispatch({type:"resizeInstance",payload:{instanceId:a.instanceId,w:w?p:s.rect.w,h:x?f:s.rect.h}}),(b&&s.rect.x!==l||k&&s.rect.y!==u)&&n.dispatch({type:"moveInstance",payload:{instanceId:a.instanceId,x:b?l:s.rect.x,y:k?u:s.rect.y}});else{const e={};S&&(e.widthMode=S.mode,e.width=S.value),B&&(e.heightMode=B.mode,e.height=B.value),b&&(e.x=l),k&&(e.y=u);const t=s.layoutBox;let o=!1;t?(void 0!==e.x&&e.x!==t.x&&(o=!0),void 0!==e.y&&e.y!==t.y&&(o=!0),void 0!==e.width&&e.width!==t.width&&(o=!0),void 0!==e.height&&e.height!==t.height&&(o=!0),void 0!==e.widthMode&&e.widthMode!==t.widthMode&&(o=!0),void 0!==e.heightMode&&e.heightMode!==t.heightMode&&(o=!0)):o=Object.keys(e).length>0,o&&n.dispatch({type:"updateLayoutBox",payload:{instanceId:a.instanceId,patch:e}})}if(("container"===a.placement||"slot"===a.placement)&&(null!==a.startSize||T)){const e=a.startSize,t={};w?t.width=vn(null==e?void 0:e.width,p,I?I.w:null):(null==e?void 0:e.width)&&(t.width=JSON.parse(JSON.stringify(e.width))),x?t.height=vn(null==e?void 0:e.height,f,I?I.h:null):(null==e?void 0:e.height)&&(t.height=JSON.parse(JSON.stringify(e.height)));const o=s.size;JSON.stringify(o)!==JSON.stringify(t)&&n.dispatch({type:"setInstanceSize",payload:{instanceId:a.instanceId,size:t}})}return}if("pending"===i.status&&i.startPt){const t=e.x-i.startPt.x,o=e.y-i.startPt.y;t*t+o*o>=9&&(i.status="active",n.beginBatch())}if("active"===i.status&&i.startPt){const o=e.x-i.startPt.x,a=e.y-i.startPt.y,d=(null==(s=t.getRoot)?void 0:s.call(t))??null,l=d instanceof HTMLElement?d:null,u=n.document.document.instances,p=null!==l&&u.length<=50,f=(e,t)=>p?mn(e,l,n.viewport)??t:t,h=[];for(const[e,t]of i.startRects){const i=n.document.getInstance(e);if(!i)continue;const r=f(e,i.rect);h.push({x:t.x+o,y:t.y+a,w:r.w,h:r.h})}const g=[],m=new Set(i.startRects.keys());for(const e of u)m.has(e.instanceId)||g.push(f(e.instanceId,e.rect));const v=n.document.document.layout,y=!1!==n.effectiveBehavior.value.snap,I=(null==(c=v.guides)?void 0:c.items)??[],w=[],x=[];for(const e of I)"x"===e.axis?w.push(e.position):x.push(e.position);const b=y?on({draggedRects:h,otherRects:g,canvasSize:{w:n.measuredCanvasSize.value.w,h:n.measuredCanvasSize.value.h},manualGuides:w.length||x.length?{x:w,y:x}:void 0}):{dx:0,dy:0,lines:[]};r.value=b.lines;const k=o+b.dx,S=a+b.dy;for(const[e,t]of i.startRects)n.document.getInstance(e)&&n.dispatch({type:"moveInstance",payload:{instanceId:e,x:t.x+k,y:t.y+S}});return}o.active&&(o.end={...e})},handlePointerUp(){if("active"===a.status){const e="slot"===a.placement||"container"===a.placement?"resize-slot-child":"resize";return n.endBatch(e),void m()}if("active"===i.status)return n.endBatch("drag"),void g();if("pending"===i.status)return i.deferredClickSelect&&n.dispatch({type:"select",payload:{instanceId:i.deferredClickSelect}}),void g();if(!o.active)return;const e=u.value,t=n.document.document.instances;if(e&&(e.w>0||e.h>0)){const i=xn(sn(e,t),t);if(o.additive){const e=xn(o.priorSelection,t),a=Array.from(new Set([...e,...i]));n.dispatch({type:"selectAll",payload:{instanceIds:a}})}else i.length>0&&n.dispatch({type:"selectAll",payload:{instanceIds:i}})}h()},cancelMarquee(){h()},cancelDrag(){"active"===i.status&&n.endBatch("drag-cancel"),g()},handleResizeStart(e,o,i){var r,s,c,d,l,u;const p=n.document.getInstance(e);if(!p)return{startTracking:!1};if(!0===(p.lockSize??p.locked))return{startTracking:!1};if(p.hidden)return{startTracking:!1};if(!n.effectiveBehavior.value.resizable)return{startTracking:!1};const f="slot"===p.placement||"container"===p.placement,h=un(n,e);if(!gn(h,o,null==(r=p.layoutBox)?void 0:r.widthMode,null==(s=p.layoutBox)?void 0:s.heightMode))return{startTracking:!1};a.status="active",a.handle=o,a.startPt={...i};const g=mn(e,(null==(c=t.getRoot)?void 0:c.call(t))??null,n.viewport);a.startRect=g??{...p.rect},a.instanceId=e,a.placement=f?"container":"canvas",a.parentLayoutMode=h,a.startLayoutBox=p.layoutBox?JSON.parse(JSON.stringify(p.layoutBox)):{x:p.rect.x,y:p.rect.y,width:p.rect.w,height:p.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},a.startSize=f&&p.size?JSON.parse(JSON.stringify(p.size)):null;const m=p.parentId,v=p.slot,y=(null==(d=t.getRoot)?void 0:d.call(t))??null;let I=m?dn(m,v,y):null;if(m&&(!I||0===I.width&&0===I.height)){const n=cn(y,`[data-instance-id="${e.replace(/["\\]/g,e=>`\\${e}`)}"]`),t=n instanceof HTMLElement?n.parentElement:null;if(t){const e=t.getBoundingClientRect();(e.width>0||e.height>0)&&(I=e)}}if(I){const e=n.viewport.scale.value||1;a.startOutletCanvasSize={w:I.width/e,h:I.height/e}}else if(void 0===m)a.startOutletCanvasSize={w:n.measuredCanvasSize.value.w,h:n.measuredCanvasSize.value.h};else{const n=a.startLayoutBox.widthMode,t=a.startLayoutBox.heightMode,o="percent"===n||"percent"===t;o&&console.debug("[hc-canvas/interaction] resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:m,slot:v});const i=a.startSize,r="percent"===(null==(l=null==i?void 0:i.width)?void 0:l.mode)||"percent"===(null==(u=null==i?void 0:i.height)?void 0:u.mode);!o&&r&&console.debug("[hc-canvas/interaction] slot child resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:m,slot:v}),a.startOutletCanvasSize=null}return n.beginBatch(),{startTracking:!0}},cancelResize(){if("active"===a.status){const e="slot"===a.placement||"container"===a.placement?"resize-slot-child-cancel":"resize-cancel";n.endBatch(e)}m()}}}function kn(e,n){return{ok:!1,reason:e,message:n}}function Sn(e,n,t,o={}){const i=new Map;for(const n of e)i.set(n.instanceId,n);const a=i.get(n);if(!a)return kn("instance-not-exists",`实例 "${n}" 不存在,无法 reparent`);const r=null===t.parentId||void 0===t.parentId?void 0:t.parentId;if(r===n)return kn("self-parent",`parentId 不能等于自身 "${n}"`);if(void 0!==r){const e=i.get(r);if(!e)return kn("parent-not-exists",`目标 parentId "${r}" 不存在`);const t=new Set;let o=e.parentId;for(;void 0!==o&&!t.has(o);){if(t.add(o),o===n)return kn("cycle",`目标 parent "${r}" 是 "${n}" 的后代,会循环`);const e=i.get(o);o=null==e?void 0:e.parentId}}if(void 0===r)return{ok:!0};const s=o.resolveContract;if(!s)return{ok:!0};const c=i.get(r),d=s(c.componentVersionKey);if(!d)return{ok:!0};const l=d.slotsDecl??[];if(0===l.length)return kn("parent-not-layout",`父组件 "${c.componentId}" 不是布局组件(slotsDecl 空)`);const u=void 0===t.slot||""===t.slot||"default"===t.slot?se:t.slot,p=(f=u,l.find(e=>e.name===f));var f;if(!p)return kn("slot-not-exists",`slot "${u}" 不在父 "${c.componentId}" 的 slotsDecl`);if(p.accepts&&p.accepts.length>0&&!p.accepts.includes(a.componentId))return kn("accepts-violation",`slot "${u}" 不允许 componentId "${a.componentId}"(accepts: ${p.accepts.join(", ")})`);if(!0!==p.multiple){const t=e.filter(e=>e.instanceId!==n&&e.parentId===r&&ce(e)===u);if(t.length>0)return kn("slot-multiple-violated",`slot "${u}" 不允许多个子实例(已有 "${t[0].instanceId}")`)}if("number"==typeof p.maxChildren&&Number.isFinite(p.maxChildren)&&p.maxChildren>=1){const t=e.filter(e=>e.instanceId!==n&&e.parentId===r&&ce(e)===u);if(t.length+1>p.maxChildren)return kn("max-children-exceeded",`slot "${u}" 最多接受 ${p.maxChildren} 个子(已有 ${t.length} 个)`)}return{ok:!0}}function Bn(e){const n=new Set(e.map(e=>e.instanceId)),t=new Map;for(const n of e)t.set(n.instanceId,Tn(n));const o=[],i=new Map;e.forEach((e,a)=>{const r={inst:e,node:t.get(e.instanceId),originalIndex:a},s=e.parentId;if(s){if(!n.has(s))return console.warn(`[hc-canvas/instance-tree] instance "${e.instanceId}" parentId="${s}" 不存在,降级当顶层`),void o.push(r);i.has(s)||i.set(s,[]),i.get(s).push(r)}else o.push(r)});for(const[e,n]of i){const o=t.get(e);o&&(o.children=Mn(n).map(e=>e.node))}return o.slice().sort((e,n)=>{const t=(n.inst.zIndex??0)-(e.inst.zIndex??0);return 0!==t?t:e.originalIndex-n.originalIndex}).map(e=>e.node)}function Mn(e){const n=new Map;for(const t of e){const e=t.inst.slot??"default";let o=n.get(e);o||(o={firstIndex:t.originalIndex,entries:[]},n.set(e,o)),o.entries.push(t)}return Array.from(n.values()).sort((e,n)=>e.firstIndex-n.firstIndex).flatMap(e=>e.entries.slice().sort((e,n)=>e.originalIndex-n.originalIndex))}function Tn(e){const n={instanceId:e.instanceId,componentId:e.componentId,componentVersionKey:e.componentVersionKey,kind:"visual",label:e.alias??e.instanceId};return void 0!==e.locked&&(n.locked=e.locked),void 0!==e.lockPosition&&(n.lockPosition=e.lockPosition),void 0!==e.lockSize&&(n.lockSize=e.lockSize),void 0!==e.hidden&&(n.hidden=e.hidden),n}function Cn(e,n){for(const t of e){if(t.instanceId===n)return[t];if(t.children&&t.children.length>0){const e=Cn(t.children,n);if(e.length>0)return[t,...e]}}return[]}function zn(e,n){const t=new Map;for(const n of e)t.set(n.instanceId,n);const o=t.get(n);if(!o)return[];const i=[o];let a=o;const r=e.length;for(;a&&a.parentId;){if(i.length>r){console.warn(`[hc-canvas/instance-tree] breadcrumb for "${n}" exceeds depth ${r},疑似环,截断`);break}const e=t.get(a.parentId);if(!e)break;i.unshift(e),a=e}return i}function Ln(e,n,t){const o=n||void 0;return e.filter(e=>(e.parentId||void 0)===o&&e.slot===t).map((e,n)=>({inst:e,originalIndex:n})).sort((e,n)=>{const t=(n.inst.zIndex??0)-(e.inst.zIndex??0);return 0!==t?t:e.originalIndex-n.originalIndex}).map(e=>e.inst)}function En(e){if(0===e.length)return null;let n=1/0,t=1/0,o=-1/0,i=-1/0;for(const a of e)a.x<n&&(n=a.x),a.y<t&&(t=a.y),a.x+a.w>o&&(o=a.x+a.w),a.y+a.h>i&&(i=a.y+a.h);return{x:n,y:t,w:o-n,h:i-t}}function Dn(e){return En(e.map(e=>e.rect))}function Pn(e,n){if(0===n.length)return null;const t=new Set(n),o=[];for(const n of e)t.has(n.instanceId)&&o.push(n.rect);return En(o)}function Rn(e,n,t){const o=(null==t?void 0:t.padding)??40,i=Math.max(1,n.w-2*o),a=Math.max(1,n.h-2*o),r=Math.max(1,e.w),s=Math.max(1,e.h);let c=Math.min(i/r,a/s);void 0!==(null==t?void 0:t.maxScale)&&(c=Math.min(c,t.maxScale)),void 0!==(null==t?void 0:t.minScale)&&(c=Math.max(c,t.minScale));const d=e.x+e.w/2,l=e.y+e.h/2;return{scale:c,panX:n.w/2-d*c,panY:n.h/2-l*c}}function On(e,n){const t=e.scale||1;return{x:-e.panX/t+0,y:-e.panY/t+0,w:n.w/t,h:n.h/t}}function $n(e){const n=[];(e.metaKey||e.ctrlKey)&&n.push("mod"),e.shiftKey&&n.push("shift"),e.altKey&&n.push("alt");let t=e.key;return t="Meta"===t||"Control"===t?"mod":" "===t||"Space"===e.code?"space":(t.length,t.toLowerCase()),n[n.length-1]===t||n.push(t),n.join("+")}function An(e){if(!(e&&e instanceof HTMLElement))return!1;const n=e.tagName;return"INPUT"===n||"TEXTAREA"===n||"SELECT"===n||!!e.isContentEditable}function Nn(e,n){const t=$n(n);for(const n of e.keys)if(Fn(n)===t)return!0;return!1}function Fn(e){return e.split("+").map(e=>e.trim().toLowerCase()).join("+")}class jn extends Error{constructor(e="CanvasHandle has been disposed"){super(e),this.name="HandleDisposedError"}}function Vn(t,o){const i=nn(t,o.recorder);function a(e){const n=o.getStageEl();if(!n)return console.warn("[hc-canvas/handle] clientToCanvasPoint called before stage mounted; falling back to viewport.toCanvasPoint(raw clientPt). 结果可能偏移。"),t.viewport.toCanvasPoint(e);const i=n.getBoundingClientRect();return t.viewport.toCanvasPoint({x:e.x-i.left,y:e.y-i.top})}function r(e,n){const o=t.document.getInstance(e);if(!o)return null;const i=(null==n?void 0:n.newInstanceId)??function(e){var n;const t="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`${e}_${(null==(n=null==t?void 0:t.randomUUID)?void 0:n.call(t).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}(o.componentId);return t.dispatch({type:"duplicateInstance",payload:{instanceId:e,newInstanceId:i,...void 0!==(null==n?void 0:n.offset)?{offset:n.offset}:{}}}),t.document.getInstance(i)?i:null}function s(){return JSON.parse(JSON.stringify(t.document.document.layout))}function c(){return Bn(t.document.document.instances)}function d(e,n){const i=t.document.getInstance(e);if(!i)return console.warn(`[hc-canvas/handle] ${n}: instance "${e}" 不存在`),!1;const a=o.getStageEl();if(!a)return console.warn(`[hc-canvas/handle] ${n}: stage 未挂载,跳过滚动(${e})`),!1;const r=mn(e,a,t.viewport),s=r&&(r.w>0||r.h>0)?r:{x:i.rect.x,y:i.rect.y,w:i.rect.w,h:i.rect.h},c=a.getBoundingClientRect(),d=t.viewport.scale.value,l=c.width/2-(s.x+s.w/2)*d,u=c.height/2-(s.y+s.h/2)*d;return t.viewport.setPan(l,u),!0}const l=e.ref(null);let u=0;function p(e){var n;return"undefined"!=typeof globalThis&&(null==(n=globalThis.CSS)?void 0:n.escape)?globalThis.CSS.escape(e):e.replace(/["\\]/g,e=>`\\${e}`)}function f(){const e=o.getStageEl();if(!e)return null;const n=e.getBoundingClientRect();return{w:n.width,h:n.height}}function h(){return{scale:t.viewport.scale.value,panX:t.viewport.panX.value,panY:t.viewport.panY.value}}function g(){return Dn(t.document.document.instances)}function m(){return Pn(t.document.document.instances,t.selection.selectedIds.value)}function v(e,n){const o=f();if(!o)return void t.viewport.setScale(e);const i=h();let a;if(null==n?void 0:n.center)a=n.center;else{const e=On(i,o);a={x:e.x+e.w/2,y:e.y+e.h/2}}const r=a.x*i.scale+i.panX,s=a.y*i.scale+i.panY,c=r-a.x*e,d=s-a.y*e;t.viewport.setScale(e),t.viewport.setPan(c,d)}function y(e,n){v(t.viewport.scale.value+e,n)}function I(){t.viewport.resetView()}function w(e,n){const o=f();if(!o)return void console.warn("[hc-canvas/handle] scrollToRect: stage 未挂载,跳过");const i=Rn(e,o,n);t.viewport.setScale(i.scale),t.viewport.setPan(i.panX,i.panY)}function x(e){const n=g();n&&w(n,e)}function b(e){const n=m();n&&w(n,e)}const k=Object.freeze([{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]);function S(){const e=t.selection.selectedIds.value;if(0===e.length)return!1;for(const n of e){const e=t.document.getInstance(n);if(e&&!0!==(e.lockPosition??e.locked))return!0}return!1}function B(e,n,o){const i=o?10:1,a=t.selection.selectedIds.value;if(0===a.length)return;const r=!t.isBatching.value;r&&t.beginBatch();try{for(const o of a){const a=t.document.getInstance(o);if(!a||!0===(a.lockPosition??a.locked))continue;const r=un(t,o);pn(r)?t.dispatch({type:"moveInstance",payload:{instanceId:o,x:a.rect.x+e*i,y:a.rect.y+n*i}}):"undefined"!=typeof console&&"function"==typeof console.debug&&console.debug("[hc-canvas/handle] executeNudge: 拒绝 layout-managed 子 nudge",{instanceId:o,parentLayoutMode:r})}}finally{r&&t.endBatch(o?"arrow-move-large":"arrow-move")}}function M(e){const n=[...t.selection.selectedIds.value];if(0===n.length)return;const o=!t.isBatching.value;o&&t.beginBatch();try{for(const o of n)t.dispatch({type:"setInstanceLocked",payload:{instanceId:o,locked:e}})}finally{o&&t.endBatch(e?"lock-selection":"unlock-selection")}}function T(e){const n=t.selection.selectedIds.value;if(0===n.length)return;const o=t.document.document.instances;if(0===o.length)return;const i=o.map((e,n)=>({inst:e,origIdx:n})).sort((e,n)=>{const t=e.inst.zIndex??0,o=n.inst.zIndex??0;return t!==o?t-o:e.origIdx-n.origIdx}).map(e=>e.inst),a=new Set(n),r=[];for(let e=0;e<i.length;e++)a.has(i[e].instanceId)&&r.push(e);if(0===r.length)return;if(r.length===i.length)return;const s=r.map(e=>i[e]),c=i.filter(e=>!a.has(e.instanceId));let d;if("toFront"===e)d=[...c,...s];else if("toBack"===e)d=[...s,...c];else if("forward"===e){let e=r[r.length-1]+1;for(;e<i.length&&a.has(i[e].instanceId);)e++;if(e>=i.length)return;const n=i[e],t=c.indexOf(n);d=[...c.slice(0,t+1),...s,...c.slice(t+1)]}else{let e=r[0]-1;for(;e>=0&&a.has(i[e].instanceId);)e--;if(e<0)return;const n=i[e],t=c.indexOf(n);d=[...c.slice(0,t),...s,...c.slice(t)]}const l=[];for(let e=0;e<d.length;e++){const n=d[e];(n.zIndex??0)!==e&&l.push({id:n.instanceId,zIndex:e})}if(0===l.length)return;const u=!t.isBatching.value;u&&t.beginBatch();try{for(const e of l)t.dispatch({type:"updateInstance",payload:{instanceId:e.id,patch:{zIndex:e.zIndex}}})}finally{u&&t.endBatch(`z-order-${e}`)}}const C={undo:{execute:()=>i.undo(),canExecute:()=>i.canUndo.value},redo:{execute:()=>i.redo(),canExecute:()=>i.canRedo.value},deleteSelection:{execute:function(){const e=[...t.selection.selectedIds.value];if(0===e.length)return;const n=!t.isBatching.value;n&&t.beginBatch();try{for(const n of e)t.dispatch({type:"removeInstance",payload:{instanceId:n}})}finally{n&&t.endBatch("delete-selection")}},canExecute:()=>t.selection.selectedIds.value.length>0},duplicateSelection:{execute:function(){const e=[...t.selection.selectedIds.value];if(0===e.length)return;const n=[],o=!t.isBatching.value;o&&t.beginBatch();try{for(const t of e){const e=r(t);e&&n.push(e)}n.length>0&&t.dispatch({type:"selectAll",payload:{instanceIds:n}})}finally{o&&t.endBatch("duplicate-selection")}},canExecute:()=>t.selection.selectedIds.value.length>0},clearSelection:{execute:()=>t.dispatch({type:"clearSelection"}),canExecute:()=>t.selection.selectedIds.value.length>0},cancelInteraction:{execute:()=>t.dispatch({type:"clearSelection"}),canExecute:()=>!0},zoomIn:{execute:()=>y(.1),canExecute:()=>!0},zoomOut:{execute:()=>y(-.1),canExecute:()=>!0},zoom100:{execute:()=>v(1),canExecute:()=>!0},resetViewport:{execute:()=>I(),canExecute:()=>!0},fitToContent:{execute:()=>x(),canExecute:()=>null!==g()},fitToSelection:{execute:()=>b(),canExecute:()=>null!==m()},fitToSelectionOrContent:{execute:()=>{m()?b():x()},canExecute:()=>null!==m()||null!==g()},nudgeSelection:{execute:e=>{const n=e??{dx:0,dy:0};B(n.dx,n.dy,!1)},canExecute:S},nudgeSelectionLarge:{execute:e=>{const n=e??{dx:0,dy:0};B(n.dx,n.dy,!0)},canExecute:S},lockSelection:{execute:()=>M(!0),canExecute:()=>t.selection.selectedIds.value.length>0},unlockSelection:{execute:()=>M(!1),canExecute:()=>t.selection.selectedIds.value.length>0},bringForward:{execute:()=>T("forward"),canExecute:()=>t.selection.selectedIds.value.length>0},sendBackward:{execute:()=>T("backward"),canExecute:()=>t.selection.selectedIds.value.length>0},bringToFront:{execute:()=>T("toFront"),canExecute:()=>t.selection.selectedIds.value.length>0},sendToBack:{execute:()=>T("toBack"),canExecute:()=>t.selection.selectedIds.value.length>0},toggleGrid:{execute:function(){var e;const n=null==(e=t.document.document.layout.guides)?void 0:e.grid;R(!(null==n?void 0:n.visible))},canExecute:()=>!0},toggleRuler:{execute:function(){var e;const n=null==(e=t.document.document.layout.guides)?void 0:e.ruler;P(!(null==n?void 0:n.visible))},canExecute:()=>!0}};function z(e,n){const o=null===n?null:JSON.parse(JSON.stringify(n));t.dispatch({type:"setComponentOverride",payload:{instanceId:e,override:o}})}function L(e,n){const o=e??"notEditingText";return"always"===o||("notEditingText"===o?!An(n.target):"design"===o?!An(n.target)&&!1!==t.effectiveBehavior.value.draggable:"hasSelection"===o&&!An(n.target)&&t.selection.selectedIds.value.length>0)}function E(){return t.document.document.layout.guides??{}}function D(e){t.dispatch({type:"updateLayout",payload:{patch:{guides:e}}})}function P(e){const n=E();D({...n,ruler:{...n.ruler??{},visible:e}})}function R(e){const n=E();D({...n,grid:{...n.grid??{},visible:e}})}const O=e.computed(()=>{const e=t.selection.selectedIds.value;if(0===e.length)return[];const n=new Set(e);return t.document.document.instances.filter(e=>n.has(e.instanceId))}),$=t.selection.selectedIds,A=e.readonly($),N=e.readonly(t.isBatching);let F=null,j=null;const V=t.canvasId,_=new Set,q=new Set;let K=!1;function J(e){var n,i,a,r,s,c,d,l,u;const p=e.parentId||void 0;if(void 0===p)return e;const f=(null==(i=null==(n=t.document.getInstance(p))?void 0:n.containerLayout)?void 0:i.mode)??"none";if("flex"!==f&&"split"!==f&&"grid"!==f)return e;const h=e.layoutBox,g=void 0!==h,m=void 0!==h,v=null==(a=o.resolveContract)?void 0:a.call(o,e.componentVersionKey),y=null==(s=null==(r=null==v?void 0:v.layoutDecl)?void 0:r.sizing)?void 0:s.defaultChildSize,I=e.rect??{w:240,h:60},w=h??{x:0,y:0,width:I.w,height:I.h,widthMode:"px",heightMode:"px"},x=e=>{if(void 0!==e)return"hug"===e?"auto":e},b=g?w.widthMode:x(null==(c=null==y?void 0:y.width)?void 0:c.mode)??"fill",k=m?w.heightMode:x(null==(d=null==y?void 0:y.height)?void 0:d.mode)??"fill",S=g||void 0===(null==(l=null==y?void 0:y.width)?void 0:l.value)?w.width:y.width.value,B=m||void 0===(null==(u=null==y?void 0:y.height)?void 0:u.value)?w.height:y.height.value;return{...e,layoutBox:{...w,x:0,y:0,width:S,height:B,widthMode:b,heightMode:k}}}return{dispatch:e=>function(e){if("addInstance"===e.type){const n=function(e){var n,t,i,a;if(void 0!==e.containerLayout)return e;const r=null==(n=o.resolveContract)?void 0:n.call(o,e.componentVersionKey);if(!r)return e;if(!("container"===(null==(t=r.layoutDecl)?void 0:t.role)||((null==(i=r.slotsDecl)?void 0:i.length)??0)>0))return e;const s=null==(a=r.layoutDecl)?void 0:a.defaultLayout;return void 0===s?e:{...e,containerLayout:JSON.parse(JSON.stringify(s))}}(e.payload.instance);return void t.dispatch({type:"addInstance",payload:{instance:J(n)}})}t.dispatch(e)}(e),beginBatch:()=>t.beginBatch(),endBatch:e=>t.endBatch(e),isBatching:N,getSnapshot:()=>JSON.parse(JSON.stringify(t.document.document)),selectedIds:A,selectedInstances:O,viewport:t.viewport,clientToCanvasPoint:a,getInstanceAtClientPoint:function(e){const n=o.getStageEl();if(!n)return null;const i=an(a(e),t.document.document.instances,e=>mn(e,n,t.viewport));return i?t.document.getInstance(i)??null:null},getDropTarget:function(e,n,i){var a;const r=n??(null==(a=o.getStageEl)?void 0:a.call(o))??("undefined"!=typeof document&&"function"==typeof document.querySelectorAll?document:null);if(!r)return null;const s=void 0!==(null==i?void 0:i.excludeInstanceId),c=s?`[data-instance-id="${p(i.excludeInstanceId)}"]`:null;let d=c?r.querySelector(c):null;if(!d&&s&&r instanceof Element){const e=r.closest("[data-hc-canvas-designer]");e&&e!==r&&(d=e.querySelector(c))}let l=r.querySelectorAll("[data-hc-slot]");if(0===l.length&&s&&r instanceof Element){const e=r.closest("[data-hc-canvas-designer]");e&&e!==r&&(l=e.querySelectorAll("[data-hc-slot]"))}let u=null;for(const n of l){if(!(n instanceof HTMLElement))continue;if(d&&d.contains(n))continue;const t=n.getBoundingClientRect();if(0===t.width&&0===t.height)continue;if(e.x<t.left||e.x>t.right)continue;if(e.y<t.top||e.y>t.bottom)continue;let o=0,i=n;for(;i;)o++,i=i.parentElement;(!u||o>u.depth)&&(u={el:n,depth:o})}if(!u)return null;const f=u.el,h=f.closest("[data-instance-id]");if(!h)return null;const g=h.getAttribute("data-instance-id");return g&&t.document.getInstance(g)?{parentId:g,slot:f.getAttribute("data-hc-slot")||"default",outletEl:f}:null},duplicateInstance:r,undo:i.undo,redo:i.redo,canUndo:i.canUndo,canRedo:i.canRedo,undoStackSize:i.undoStackSize,redoStackSize:i.redoStackSize,clearHistory:i.clear,getLayoutConfig:s,updateCanvasSize:function(e){const n={...s().canvas,...e};t.dispatch({type:"updateLayout",payload:{patch:{canvas:n}}})},updateCanvasBackground:function(e){if(null===e)return void t.dispatch({type:"updateLayout",payload:{patch:{background:void 0}}});const n={...s().background??{},...e};t.dispatch({type:"updateLayout",payload:{patch:{background:n}}})},updateBehavior:function(e){const n={...s().behavior??{},...e};t.dispatch({type:"updateLayout",payload:{patch:{behavior:n}}})},setInteractionOptions:function(e){t.setInteractionOptions(e)},getEffectiveBehavior:function(){return{...t.effectiveBehavior.value}},setRootLayout:function(e){let n;if(null===e)n=null;else if("string"==typeof e)switch(e){case"free":n={mode:"free"};break;case"none":n={mode:"none"};break;case"split":n={mode:"split",direction:"horizontal",ratios:[.5,.5]};break;case"grid":n={mode:"grid",columns:[{mode:"fr",value:1},{mode:"fr",value:1}],rows:[{mode:"fr",value:1},{mode:"fr",value:1}]};break;case"flex":n={mode:"flex",direction:"row"};break;default:return void console.warn(`[hc-canvas/handle] setRootLayout: 未知 mode "${e}",忽略`)}else n=e;t.dispatch({type:"setRootLayout",payload:{rootLayout:n}})},getInstanceTree:c,getInstanceList:function(){return t.document.document.instances.map(e=>JSON.parse(JSON.stringify(e)))},getInstance:function(e){const n=t.document.getInstance(e);return n?JSON.parse(JSON.stringify(n)):null},getSelectedPath:function(){const e=t.selection.primaryId.value;return e?Cn(c(),e):[]},getBreadcrumb:function(e){return zn(t.document.document.instances,e).map(e=>JSON.parse(JSON.stringify(e)))},focusInstance:function(e){t.document.getInstance(e)?(t.dispatch({type:"select",payload:{instanceId:e}}),d(e,"focusInstance")):console.warn(`[hc-canvas/handle] focusInstance: instance "${e}" 不存在`)},scrollToInstance:function(e){d(e,"scrollToInstance")},moveInstanceInTree:function(e,n){var i,a,r;const s=Sn(t.document.document.instances,e,n,{resolveContract:o.resolveContract});if(!s.ok)return console.warn(`[hc-canvas/handle] moveInstanceInTree 守门拒绝(${s.reason}): ${s.message}`),void function(e,n,t,o){u++,l.value={instanceId:e,target:{...n},reason:t,message:o,token:u}}(e,n,s.reason,s.message??`reparent rejected: ${s.reason}`);const c=t.document.getInstance(e),d=null===n.parentId?void 0:n.parentId,p=(c.parentId||void 0)!==(d||void 0),f=c.slot!==n.slot,h={};if(p&&(h.parentId=d),f&&(h.slot=n.slot),p){const e=void 0===d?"canvas":"container";c.placement!==e&&(h.placement=e);const n=t.document.document.layout,o=void 0===d?(null==(i=null==n?void 0:n.rootLayout)?void 0:i.mode)??"free":(null==(r=null==(a=t.document.getInstance(d))?void 0:a.containerLayout)?void 0:r.mode)??"none";if(c.layoutBox)if("container"!==e||"flex"!==o&&"split"!==o&&"grid"!==o){if("canvas"===e){const e="fill"===c.layoutBox.widthMode?"px":c.layoutBox.widthMode,n="fill"===c.layoutBox.heightMode?"px":c.layoutBox.heightMode;e===c.layoutBox.widthMode&&n===c.layoutBox.heightMode||(h.layoutBox={...c.layoutBox,widthMode:e,heightMode:n})}}else h.layoutBox={...c.layoutBox,x:0,y:0,widthMode:"fill",heightMode:"fill"},h.rect={x:0,y:0,w:c.rect.w,h:c.rect.h};if("container"===e&&"grid"===o){const e=c.layoutItem??{};void 0!==e.row&&void 0!==e.column||(h.layoutItem={...e,row:e.row??1,column:e.column??1})}}const g=[];if(void 0!==n.index){const o=Ln(t.document.document.instances,d,n.slot).filter(n=>n.instanceId!==e),i=Math.max(0,Math.min(n.index,o.length));o.splice(i,0,c),o.forEach((e,n)=>{const t=o.length-1-n;(e.zIndex??0)!==t&&g.push({id:e.instanceId,zIndex:t})})}if(0===Object.keys(h).length&&0===g.length)return;const m=!t.isBatching.value;m&&t.beginBatch();try{Object.keys(h).length>0&&t.dispatch({type:"updateInstance",payload:{instanceId:e,patch:h}});for(const e of g)t.dispatch({type:"updateInstance",payload:{instanceId:e.id,patch:{zIndex:e.zIndex}}})}finally{m&&t.endBatch("moveInstanceInTree")}},canReparent:function(e,n){return Sn(t.document.document.instances,e,n,{resolveContract:o.resolveContract})},cannotReparentEvent:e.readonly(l),cannotDragLayoutManagedChildEvent:t.cannotDragLayoutManagedChildEvent,resolveAsset:function(e){return t.resolveAsset(e)},getViewportState:h,getVisibleBounds:function(){const e=f();return e?On(h(),e):{x:0,y:0,w:0,h:0}},getCanvasBounds:function(){const e=t.measuredCanvasSize.value;return{x:0,y:0,w:e.w,h:e.h}},getContentBounds:g,getSelectionBounds:m,getInstanceBounds:function(e){const n=t.document.getInstance(e);return n?{...n.rect}:null},panBy:function(e,n){t.viewport.setPan(t.viewport.panX.value+e,t.viewport.panY.value+n)},panTo:function(e,n){t.viewport.setPan(e,n)},zoomTo:v,zoomBy:y,zoomToPoint:function(e,n){const i=o.getStageEl();if(!i)return void console.warn("[hc-canvas/handle] zoomToPoint: stage 未挂载,跳过");const a=i.getBoundingClientRect(),r=n.x-a.left,s=n.y-a.top,c=h(),d=r-(r-c.panX)/c.scale*e,l=s-(s-c.panY)/c.scale*e;t.viewport.setScale(e),t.viewport.setPan(d,l)},resetViewport:I,fitToContent:x,fitToSelection:b,scrollToRect:w,toolMode:t.toolMode,getToolMode:function(){return t.toolMode.value},setToolMode:function(e){t.setToolMode(e)},setTemporaryToolMode:function(e){t.setTemporaryToolMode(e)},getDefaultShortcuts:function(){return[{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]},executeShortcut:function(e){for(const n of k){if(!Nn(n,e))continue;if(!L(n.when,e))continue;const t=C[n.command];return!!t&&!!t.canExecute()&&(t.execute(n.payload),!1!==n.preventDefault&&e.preventDefault(),!0)}return!1},executeCommand:function(e,n){const t=C[e];t?t.canExecute()&&t.execute(n):console.warn(`[hc-canvas/handle] executeCommand: 未知命令 "${e}"`)},canExecuteCommand:function(e){const n=C[e];return!!n&&n.canExecute()},getStaleComponentOverrides:function(){const e=t.document.document.componentOverrides??{},n=[];for(const o of t.document.document.instances){const t=e[o.instanceId];t&&t.baseVersionKey!==o.componentVersionKey&&n.push({instanceId:o.instanceId,baseVersionKey:t.baseVersionKey,currentVersionKey:o.componentVersionKey})}return n},setComponentOverride:z,discardComponentOverride:function(e){z(e,null)},getLayoutIssues:function(){return t.layoutIssues.value},setRulerVisible:P,setGridVisible:R,updateRulerConfig:function(e){const n=E();D({...n,ruler:{...n.ruler??{},...e}})},updateGridConfig:function(e){const n=E();D({...n,grid:{...n.grid??{},...e}})},addGuide:function(e){const n=E(),t=n.items??[],o=e.id??function(){var e;const n="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`g_${(null==(e=null==n?void 0:n.randomUUID)?void 0:e.call(n).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}();if(t.some(e=>e.id===o))return console.warn(`[hc-canvas/handle] addGuide: id "${o}" 已存在,忽略`),o;const i={id:o,axis:e.axis,position:e.position};return void 0!==e.locked&&(i.locked=e.locked),void 0!==e.label&&(i.label=e.label),D({...n,items:[...t,i]}),o},removeGuide:function(e){const n=E(),t=n.items??[];t.some(n=>n.id===e)&&D({...n,items:t.filter(n=>n.id!==e)})},updateGuide:function(e,n){const t=E(),o=t.items??[],i=o.findIndex(n=>n.id===e);if(i<0)return void console.warn(`[hc-canvas/handle] updateGuide: id "${e}" 不存在,忽略`);const{id:a,...r}=n,s={...o[i],...r},c=[...o];c[i]=s,D({...t,items:c})},getGuides:function(){return(E().items??[]).map(e=>({...e}))},clearGuides:function(){const e=E();e.items&&0!==e.items.length&&D({...e,items:[]})},getMouseCanvasPoint:function(){const e=t.mouseCanvasPoint.value;return e?{x:e.x,y:e.y}:null},getInstanceSize:function(e){const n=t.document.getInstance(e);if(n&&void 0!==n.size)return JSON.parse(JSON.stringify(n.size))},updateInstanceSize:function(e,n){t.dispatch({type:"setInstanceSize",payload:{instanceId:e,size:n}})},getContainerLayout:function(e){const n=t.document.getInstance(e);return n&&void 0!==n.containerLayout?JSON.parse(JSON.stringify(n.containerLayout)):null},updateContainerLayout:function(e,n){t.dispatch({type:"setContainerLayout",payload:{instanceId:e,containerLayout:n}})},getInstanceOutletRect:function(e,n){if("undefined"==typeof document||"function"!=typeof document.querySelector)return null;const t=n??"default",o=""===t?"default":t,i=`[data-instance-id="${p(e)}"]`,a=`[data-hc-slot="${p(o)}"]`,r=document.querySelector(`${i} ${a}`);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null},getLayoutBox:function(e){const n=t.document.getInstance(e);if(n&&void 0!==n.layoutBox)return JSON.parse(JSON.stringify(n.layoutBox))},updateLayoutBox:function(e,n){t.dispatch({type:"updateLayoutBox",payload:{instanceId:e,patch:n}})},getLayoutItem:function(e){const n=t.document.getInstance(e);if(n&&void 0!==n.layoutItem)return JSON.parse(JSON.stringify(n.layoutItem))},updateLayoutItem:function(e,n){t.dispatch({type:"updateLayoutItem",payload:{instanceId:e,patch:n}})},getRotation:function(e){const n=t.document.getInstance(e);if(!n)return 0;const o=n.rotation;return"number"==typeof o&&Number.isFinite(o)?o:0},updateRotation:function(e,n){t.dispatch({type:"updateRotation",payload:{instanceId:e,value:n}})},setBindingMode:function(e){null==F||F.setMode(e)},getBindingMode:function(){return(null==F?void 0:F.getMode())??"off"},testBinding:function(e,n){return(null==F?void 0:F.testBinding(e,n))??[]},on:function(e,t){if(K)return()=>{};if("instance:ready"===e||"instance:unmounted"===e){const o=e,i=t,a=n.onInstanceLifecycle(o,e=>{e.canvasId===V&&i(e.instanceId)});let r=!1;const s=()=>{r||(r=!0,q.delete(s),a())};return q.add(s),s}return F?F.on(e,t):()=>{}},attachBindingDelegate:function(e,n){K||(F=e,null===e?j=null:arguments.length>=2&&(j=n??null))},invalidateDataSource:function(e){null==j||j.invalidate(e)},getDataSourceSnapshot:function(){return(null==j?void 0:j.getSnapshot())??{entries:[]}},getCachedBySourceId:function(e,n){return null==j?void 0:j.getCachedBySourceId(e,n)},getInstanceReady:function(e){return K?Promise.reject(new jn):"string"!=typeof e||0===e.length?Promise.reject(new TypeError("getInstanceReady: instanceId must be a non-empty string")):n.getInstance(e,V)?Promise.resolve():new Promise((t,o)=>{let i,a,r=!1;const s=()=>{r=!0;try{null==i||i()}catch{}a&&_.delete(a)};i=n.onInstanceLifecycle("instance:ready",n=>{r||n.canvasId===V&&n.instanceId===e&&(s(),t())}),a={off:i,reject:e=>{r||(s(),o(e))}},_.add(a),!r&&n.getInstance(e,V)&&(s(),t())})},getInstanceRuntime:function(e){return K?null:n.getInstance(e,V)},startTracing:function(e){null==F||F.startTracing(e)},stopTracing:function(){return(null==F?void 0:F.stopTracing())??[]},getTraceBuffer:function(){return(null==F?void 0:F.getTraceBuffer())??[]},dispose:function(){if(K)return;K=!0;const e=[..._];_.clear();for(const n of e)try{n.reject(new jn)}catch(e){console.error("[hc-canvas/handle] pending ready rejection threw on dispose",e)}const n=[...q];q.clear();for(const e of n)try{e()}catch(e){console.error("[hc-canvas/handle] instance listener off threw on dispose",e)}F=null,j=null,i.dispose()}}}const _n=Symbol("hc:canvas:reparent-bridge");function qn(e){return"preview"===e||"runtime"===e?"runtime":"off"}const Kn=(e=>{const n=e.__vccOpts||e;for(const[e,t]of[["__scopeId","data-v-825e0ee8"]])n[e]=t;return n})(e.defineComponent({__name:"CanvasStage",setup(n){const t=re(),o=e.ref(null);let i=null;const a=e.computed(()=>{const{scale:e,panX:n,panY:o}=t.viewport.state;return`translate(${n}px, ${o}px) scale(${e})`});function r(){const e=o.value;if(!e)return;const n=e.getBoundingClientRect();t.setMeasuredStageSize({w:n.width,h:n.height})}return e.onMounted(()=>{e.nextTick(r),"undefined"!=typeof ResizeObserver&&o.value&&(i=new ResizeObserver(r),i.observe(o.value)),window.addEventListener("resize",r)}),e.onBeforeUnmount(()=>{null==i||i.disconnect(),i=null,window.removeEventListener("resize",r)}),(n,t)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"stageEl",ref:o,class:"hc-canvas-stage","data-hc-stage":""},[e.createElementVNode("div",{class:"hc-canvas-stage__world","data-hc-stage-world":"",style:e.normalizeStyle({transform:a.value,transformOrigin:"0 0"})},[e.renderSlot(n.$slots,"default",{},void 0,!0)],4)],512))}})),Jn=["data-mode"],Un=e.defineComponent({__name:"RuntimeLayer",props:{componentSourceMap:{},mode:{default:"design"},schedulerOptions:{},canvasId:{}},setup(n){const t=re(),o=e.computed(()=>t.document.document);return(i,a)=>(e.openBlock(),e.createElementBlock("div",{class:"hc-runtime-layer","data-hc-runtime-layer":"","data-mode":n.mode,style:e.normalizeStyle({position:"absolute",top:0,left:0,pointerEvents:e.unref(t).effectiveBehavior.value.selectable?"none":"auto"})},[e.createVNode(Ue,{document:o.value,"component-source-map":n.componentSourceMap,"scheduler-options":n.schedulerOptions,"canvas-id":n.canvasId},null,8,["document","component-source-map","scheduler-options","canvas-id"])],12,Jn))}});function Hn(e,n,t,o=0){if(!n||n.length<2)return[];if(e.w<=0||e.h<=0)return[];const i=n.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),a=i.reduce((e,n)=>e+n,0);if(a<=0)return[];const r=i.length-1,s=Math.max(0,o)*r,c="horizontal"===t?e.w:e.h,d=Math.max(0,c-s);if(d<=0)return[];const l=o>0?o:8,u=[];let p=0;for(let n=0;n<r;n++){p+=i[n]/a*d;const r=p+n*o+o/2;let s;s="horizontal"===t?{x:e.x+r-l/2,y:e.y,w:l,h:e.h}:{x:e.x,y:e.y+r-l/2,w:e.w,h:l},u.push({index:n,rect:s,direction:t})}return u}function Xn(e,n,t,o,i=0){if(!e||n<0||n>=e.length-1)return e.slice();const a=e.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),r=a[n],s=a[n+1],c=r+s;if(c<=0)return a;const d=a.length-1,l=Math.max(0,i)*d,u=Math.max(0,o-l);if(u<=0)return a;const p=a.reduce((e,n)=>e+n,0);if(p<=0)return a;const f=t/u*p,h=.05*p;let g=r+f,m=s-f;g<h&&(g=h,m=c-h),m<h&&(m=h,g=c-h);const v=a.slice();return v[n]=g,v[n+1]=m,v}function Yn(n){const t=e.reactive({status:"idle",parentId:null,dividerIndex:null,startRatios:null,childIds:null,parentAxisPx:0,startPt:null,direction:null,gap:0}),o=e.computed(()=>"active"===t.status);function i(){t.status="idle",t.parentId=null,t.dividerIndex=null,t.startRatios=null,t.childIds=null,t.parentAxisPx=0,t.startPt=null,t.direction=null,t.gap=0}return{drag:t,isDragging:o,handleSplitDividerStart:function(e){if(!e.parentId)return{startTracking:!1};if(e.dividerIndex<0)return{startTracking:!1};if(!e.startRatios||e.startRatios.length<2)return{startTracking:!1};if(!e.childIds||e.childIds.length<=e.dividerIndex+1||!e.childIds[e.dividerIndex]||!e.childIds[e.dividerIndex+1])return{startTracking:!1};const o=n.document.getInstance(e.parentId);return o&&o.containerLayout&&"split"===o.containerLayout.mode?(t.status="active",t.parentId=e.parentId,t.dividerIndex=e.dividerIndex,t.startRatios=e.startRatios.slice(),t.childIds=e.childIds.slice(),t.parentAxisPx=e.parentAxisPx,t.startPt={...e.canvasPt},t.direction=e.direction,t.gap=e.gap,n.beginBatch(),{startTracking:!0}):{startTracking:!1}},handleSplitDividerMove:function(e){var o,i;if("active"!==t.status)return;if(!(t.startPt&&t.startRatios&&t.childIds&&t.direction&&null!==t.dividerIndex))return;const a=n.document.getInstance(t.parentId);if(!a||!a.containerLayout||"split"!==a.containerLayout.mode)return;const r="horizontal"===t.direction?e.x-t.startPt.x:e.y-t.startPt.y,s=Xn(t.startRatios,t.dividerIndex,r,t.parentAxisPx,t.gap),c=t.dividerIndex,d=t.childIds[c],l=t.childIds[c+1];if(!d||!l)return;const u=s[c],p=s[c+1],f=n.document.getInstance(d),h=n.document.getInstance(l),g=null==(o=null==f?void 0:f.layoutItem)?void 0:o.ratio,m=null==(i=null==h?void 0:h.layoutItem)?void 0:i.ratio;g===u&&m===p||(n.dispatch({type:"updateLayoutItem",payload:{instanceId:d,patch:{ratio:u}}}),n.dispatch({type:"updateLayoutItem",payload:{instanceId:l,patch:{ratio:p}}}))},handleSplitDividerEnd:function(){"active"===t.status&&(n.endBatch("split-divider-drag"),i())},cancelSplitDividerDrag:function(){"active"===t.status&&n.endBatch("split-divider-cancel"),i()}}}function Gn(e){return!0===(e.lockPosition??e.locked)}function Wn(e){return!0===(e.lockSize??e.locked)}function Qn(e){return Gn(e)||Wn(e)}const Zn=["data-mode"],et=["data-selection-box","data-locked","data-placement"],nt=["data-lock-badge"],tt=["data-resize-handle","data-resize-instance","onPointerdown"],ot=["data-hc-divider-direction","data-hc-divider-index","data-hc-parent-id","data-hc-divider-dragging","onPointerdown"],it=["data-axis","data-kind"],at=["data-hc-reparent-state"],rt=["data-hc-reparent-ghost-reason"],st={key:0,"data-hc-reparent-ghost-reason-chip":"",style:{flex:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"10px",lineHeight:"14px",padding:"0 4px",borderRadius:"2px",background:"rgba(0, 0, 0, 0.25)",color:"#fff",whiteSpace:"nowrap"}},ct=e.defineComponent({__name:"InteractionLayer",props:{mode:{default:"design"}},emits:["cannot-drag-slot-child","cannot-drag-layout-managed-child"],setup(n,{emit:t}){const o=t,i=re(),a=bn(i,{getRoot:()=>$(),getDomBox:e=>{const n=mn(e,$(),i.viewport);return n?0===n.w&&0===n.h?null:n:null}}),r=Yn(i),s=e.inject(_n,null);e.watch(()=>a.cannotDragSlotChildEvent.value,e=>{e&&o("cannot-drag-slot-child",{instanceId:e.instanceId,parentId:e.parentId})},{flush:"sync"}),e.watch(()=>a.cannotDragLayoutManagedChildEvent.value,e=>{e&&o("cannot-drag-layout-managed-child",{instanceId:e.instanceId,parentId:e.parentId,parentLayoutMode:e.parentLayoutMode})},{flush:"sync"});const c=e.ref(null);let d=null;const l=e.computed(()=>{const e=new Set(i.selection.selectedIds.value);return i.document.document.instances.filter(n=>e.has(n.instanceId)&&!n.hidden)}),u=e.computed(()=>i.measuredCanvasSize.value),p=e.shallowRef({});function f(){const e=$(),n={};for(const t of l.value)n[t.instanceId]=mn(t.instanceId,e,i.viewport);p.value=n}let h=null;function g(){"undefined"!=typeof requestAnimationFrame?null===h&&(h=requestAnimationFrame(()=>{h=null,f()})):f()}let m=null;function v(){m=null,f(),(a.isResizing.value||a.isDragging.value||r.isDragging.value)&&(m=requestAnimationFrame(v))}function y(e){const n=p.value[e.instanceId];if(n)return n;const t=mn(e.instanceId,$(),i.viewport);if(t&&(t.w>0||t.h>0))return t;const o=e.layoutBox;return o?{x:o.x,y:o.y,w:o.width,h:o.height}:{x:e.rect.x,y:e.rect.y,w:e.rect.w,h:e.rect.h}}e.watch(()=>i.selection.selectedIds.value,()=>{g()},{flush:"post",deep:!0}),e.watch(()=>i.viewport.scale.value,()=>g()),e.watch(()=>[i.viewport.panX.value,i.viewport.panY.value],()=>g()),e.watch(()=>l.value.map(e=>{const n=e.layoutBox;return n?`${n.x}|${n.y}|${n.width}|${n.height}|${n.widthMode}|${n.heightMode}`:""}),()=>g(),{flush:"post",deep:!0}),e.watch(()=>a.isResizing.value,e=>{e&&null===m&&(m=requestAnimationFrame(v))}),e.watch(()=>a.isDragging.value,e=>{e&&null===m&&(m=requestAnimationFrame(v))}),e.watch(()=>r.isDragging.value,e=>{e&&null===m&&(m=requestAnimationFrame(v))}),e.onMounted(()=>{g()});const I=e.computed(()=>l.value.map(e=>({instance:e,box:y(e)}))),w=e.computed(()=>{var e,n;if(!i.effectiveBehavior.value.resizable)return[];const t=[];for(const o of I.value){const a=o.instance;if(!0===(a.lockSize??a.locked))continue;if(!o.box)continue;const r=un(i,a.instanceId),{x:s,y:c,w:d,h:l}=o.box,u=[{handle:"nw",cx:s,cy:c,cursor:"nwse-resize"},{handle:"n",cx:s+d/2,cy:c,cursor:"ns-resize"},{handle:"ne",cx:s+d,cy:c,cursor:"nesw-resize"},{handle:"e",cx:s+d,cy:c+l/2,cursor:"ew-resize"},{handle:"se",cx:s+d,cy:c+l,cursor:"nwse-resize"},{handle:"s",cx:s+d/2,cy:c+l,cursor:"ns-resize"},{handle:"sw",cx:s,cy:c+l,cursor:"nesw-resize"},{handle:"w",cx:s,cy:c+l/2,cursor:"ew-resize"}],p=null==(e=a.layoutBox)?void 0:e.widthMode,f=null==(n=a.layoutBox)?void 0:n.heightMode,h=u.filter(e=>gn(r,e.handle,p,f));for(const e of h)t.push({instanceId:a.instanceId,handle:e.handle,left:e.cx-4,top:e.cy-4,cursor:e.cursor})}return t});function x(e,n,t){return"percent"===n?`${Math.round(t)}%`:"fill"===n?"fill":"auto"===n?"auto":String(Math.round(e))}const b=e.computed(()=>{if(!a.isResizing.value)return null;const e=a.resize.instanceId;if(!e)return null;const n=i.document.getInstance(e);if(!n)return null;const t=y(n);if(!t)return null;const o=n.layoutBox,r=x(t.w,null==o?void 0:o.widthMode,(null==o?void 0:o.width)??t.w),s=x(t.h,null==o?void 0:o.heightMode,(null==o?void 0:o.height)??t.h);return{x:t.x,y:t.y,w:t.w,h:t.h,wText:r,hText:s}}),S={nw:"nwse-resize",se:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",n:"ns-resize",s:"ns-resize",w:"ew-resize",e:"ew-resize"};function B(e){var n;const t=[],o=[];for(const a of i.document.document.instances)a.parentId===e&&void 0===a.slot&&(t.push(a.instanceId),o.push(null==(n=a.layoutItem)?void 0:n.ratio));return{ids:t,ratios:o}}const M=e.computed(()=>{var e,n;const t=new Set;for(const o of l.value)if("split"===(null==(e=o.containerLayout)?void 0:e.mode)&&t.add(o.instanceId),o.parentId){const e=i.document.getInstance(o.parentId);"split"===(null==(n=null==e?void 0:e.containerLayout)?void 0:n.mode)&&t.add(e.instanceId)}if(0===t.size)return[];const o=[];for(const e of t){const n=i.document.getInstance(e);if(!n)continue;const t=n.containerLayout;if(!t||"split"!==t.mode)continue;const a=E(e)??y(n);if(!a)continue;const r=t,s=r.direction,c=r.gap??0,{ids:d,ratios:l}=B(e),u=k(r.ratios??[],l),p=Hn(a,u,s,c);0!==p.length&&o.push({parentId:e,direction:s,gap:c,effectiveRatios:u,childIds:d,parentBox:a,dividers:p})}return o}),T=e.computed(()=>a.isResizing.value&&a.resize.handle?S[a.resize.handle]:r.isDragging.value?"horizontal"===r.drag.direction?"ew-resize":"ns-resize":a.isDragging.value?"grabbing":"hand"===i.toolMode.value?F?"grabbing":"grab":"marquee"===i.toolMode.value?"crosshair":"default"),C=e.shallowRef(null);function z(){if(!s)return!1;if(!a.isDragging.value)return!1;if(1!==a.drag.startRects.size)return!1;const e=Array.from(a.drag.startRects.keys())[0],n=i.document.getInstance(e);return!(!n||void 0!==n.placement&&"canvas"!==n.placement&&"absolute"!==n.placement||!0===(n.lockPosition??n.locked)||n.hidden)}function L(e){const n=$();if(!n)return null;const t=e.getBoundingClientRect(),o=n.getBoundingClientRect(),a=i.viewport.toCanvasPoint({x:t.left-o.left,y:t.top-o.top}),r=i.viewport.toCanvasPoint({x:t.right-o.left,y:t.bottom-o.top});return{x:a.x,y:a.y,w:Math.max(0,r.x-a.x),h:Math.max(0,r.y-a.y)}}function E(e){var n;const t=$();if(!t)return null;const o=cn(t,`[data-instance-id="${("undefined"!=typeof globalThis&&(null==(n=globalThis.CSS)?void 0:n.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`))(e)}"] [data-hc-slot="default"]`);return o&&o instanceof HTMLElement?L(o):null}let D=null,P=null;function R(e){if(!z()||!s)return void(null!==C.value&&(C.value=null));const n=Array.from(a.drag.startRects.keys())[0],t=s.getDropTarget(e,{excludeInstanceId:n});if(!t)return void(null!==C.value&&(C.value=null));const o=i.document.getInstance(n);if(o&&o.parentId===t.parentId&&(o.slot??"default")===(t.slot||"default"))return void(null!==C.value&&(C.value=null));const r=L(t.outletEl);if(!r)return void(null!==C.value&&(C.value=null));const c={parentId:t.parentId,slot:t.slot},d=s.canReparent(n,c);C.value={rect:r,target:t,result:d}}const O=e.computed(()=>C.value);function $(){return d||(c.value?(d=c.value.closest("[data-hc-stage]"),d):null)}function A(e){const n=$();if(!n)return;const t=wn({x:e.clientX,y:e.clientY},n,i.viewport);i.setMouseCanvasPoint(t)}function N(){i.setMouseCanvasPoint(null)}let F=null;function j(e){if(0!==e.button)return;const n=$();if(!n)return;if("hand"===i.toolMode.value)return F={clientX:e.clientX,clientY:e.clientY,panX:i.viewport.panX.value,panY:i.viewport.panY.value},window.addEventListener("pointermove",V),window.addEventListener("pointerup",_),void e.preventDefault();const t=wn({x:e.clientX,y:e.clientY},n,i.viewport),{startTracking:o}=a.handlePointerDown(t,{shift:e.shiftKey,ctrl:e.ctrlKey,meta:e.metaKey});o&&(q(),e.preventDefault())}function V(e){if(!F)return;const n=e.clientX-F.clientX,t=e.clientY-F.clientY;i.viewport.setPan(F.panX+n,F.panY+t)}function _(){F=null,window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",_)}function q(){window.addEventListener("pointermove",K),window.addEventListener("pointerup",J),window.addEventListener("keydown",U)}function K(e){const n=$();if(!n)return;const t=wn({x:e.clientX,y:e.clientY},n,i.viewport);var o;a.handlePointerMove(t),r.handleSplitDividerMove(t),r.isDragging.value&&g(),o={x:e.clientX,y:e.clientY},D=o,"undefined"!=typeof requestAnimationFrame?null===P&&(P=requestAnimationFrame(()=>{P=null,D&&R(D)})):R(o)}function J(e){if(r.isDragging.value)return r.handleSplitDividerEnd(),void H();e&&s&&z()&&R({x:e.clientX,y:e.clientY}),null!==P&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(P),P=null);const n=C.value;if(n&&s){const e=Array.from(a.drag.startRects.keys())[0];return n.result.ok&&e?(a.cancelDrag(),s.moveInstanceInTree(e,{parentId:n.target.parentId,slot:n.target.slot})):a.cancelDrag(),C.value=null,void H()}a.handlePointerUp(),H()}function U(e){"Escape"===e.key&&(a.cancelResize(),a.cancelDrag(),a.cancelMarquee(),r.cancelSplitDividerDrag(),C.value=null,null!==P&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(P),P=null),_(),H())}function H(){window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",J),window.removeEventListener("keydown",U)}return e.onBeforeUnmount(()=>{a.cancelResize(),a.cancelDrag(),a.cancelMarquee(),r.cancelSplitDividerDrag(),C.value=null,H(),_(),null!==h&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(h),h=null),null!==m&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(m),m=null),null!==P&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(P),P=null),D=null}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"layerEl",ref:c,class:"hc-interaction-layer","data-hc-interaction-layer":"","data-mode":n.mode,style:e.normalizeStyle({position:"absolute",top:0,left:0,width:u.value.w+"px",height:u.value.h+"px",pointerEvents:e.unref(i).effectiveBehavior.value.selectable?"auto":"none",cursor:T.value,zIndex:9999}),onPointerdown:j,onPointermove:A,onPointerleave:N},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(I.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sel-"+n.instance.instanceId},[n.box?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-selection-box","data-selection-box":n.instance.instanceId,"data-locked":e.unref(Qn)(n.instance)?"true":"false","data-placement":n.instance.placement??"absolute",style:e.normalizeStyle({position:"absolute",left:n.box.x+"px",top:n.box.y+"px",width:n.box.w+"px",height:n.box.h+"px",border:"2px solid "+(e.unref(Qn)(n.instance)?"#9ca3af":"#3b82f6"),boxSizing:"border-box",pointerEvents:"none",boxShadow:"0 0 0 1px rgba(59, 130, 246, 0.2)"})},null,12,et)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(I.value.filter(n=>e.unref(Qn)(n.instance)),n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"lock-"+n.instance.instanceId},[n.box?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-lock-badge","data-lock-badge":n.instance.instanceId,style:e.normalizeStyle({position:"absolute",left:n.box.x+n.box.w-18+"px",top:n.box.y+2+"px",width:"16px",height:"16px",background:"#9ca3af",color:"#fff",fontSize:"11px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",pointerEvents:"none",userSelect:"none"})},"🔒",12,nt)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(w.value,n=>(e.openBlock(),e.createElementBlock("div",{key:"rh-"+n.instanceId+"-"+n.handle,class:"hc-resize-handle","data-resize-handle":n.handle,"data-resize-instance":n.instanceId,style:e.normalizeStyle({position:"absolute",left:n.left+"px",top:n.top+"px",width:"8px",height:"8px",background:"#fff",border:"1px solid #3b82f6",boxSizing:"border-box",cursor:n.cursor,pointerEvents:"auto",zIndex:2}),onPointerdown:e=>function(e,n,t){if(0!==e.button)return;e.stopPropagation();const o=$();if(!o)return;const r=wn({x:e.clientX,y:e.clientY},o,i.viewport),{startTracking:s}=a.handleResizeStart(n,t,r);s&&(q(),e.preventDefault())}(e,n.instanceId,n.handle)},null,44,tt))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sd-parent-"+n.parentId},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.dividers,o=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sd-"+n.parentId+"-"+o.index},[t.$slots["split-divider"]?e.renderSlot(t.$slots,"split-divider",{key:0,state:{parentId:n.parentId,dividerIndex:o.index,direction:o.direction,rect:o.rect,isDragging:e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index}}):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-split-divider","data-hc-divider-direction":o.direction,"data-hc-divider-index":o.index,"data-hc-parent-id":n.parentId,"data-hc-divider-dragging":e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index?"true":"false",style:e.normalizeStyle({position:"absolute",left:o.rect.x+"px",top:o.rect.y+"px",width:o.rect.w+"px",height:o.rect.h+"px",background:e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index?"rgba(59, 130, 246, 0.6)":"rgba(59, 130, 246, 0.18)",cursor:"horizontal"===o.direction?"ew-resize":"ns-resize",pointerEvents:"auto",boxSizing:"border-box",zIndex:3}),onPointerdown:e=>function(e,n,t){if(0!==e.button)return;e.stopPropagation();const o=$();if(!o)return;const a=i.document.getInstance(n);if(!a)return;const s=a.containerLayout;if(!s||"split"!==s.mode)return;const c=s,d=E(n)??y(a);if(!d)return;const l="horizontal"===c.direction?d.w:d.h,{ids:u,ratios:p}=B(n),f=k(c.ratios??[],p),h=wn({x:e.clientX,y:e.clientY},o,i.viewport),{startTracking:g}=r.handleSplitDividerStart({parentId:n,dividerIndex:t,startRatios:f,childIds:u,parentAxisPx:l,direction:c.direction,gap:c.gap??0,canvasPt:h});g&&(q(),e.preventDefault())}(e,n.parentId,o.index)},null,44,ot))],64))),128))],64))),128)),b.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-resize-badge","data-resize-badge":"",style:e.normalizeStyle({position:"absolute",left:b.value.x+"px",top:b.value.y-22+"px",padding:"2px 6px",background:"#3b82f6",color:"#fff",fontSize:"11px",lineHeight:"14px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, monospace"})},e.toDisplayString(b.value.wText)+" × "+e.toDisplayString(b.value.hText),5)):e.createCommentVNode("",!0),e.unref(a).marqueeRect.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-marquee-box","data-marquee-box":"",style:e.normalizeStyle({position:"absolute",left:e.unref(a).marqueeRect.value.x+"px",top:e.unref(a).marqueeRect.value.y+"px",width:e.unref(a).marqueeRect.value.w+"px",height:e.unref(a).marqueeRect.value.h+"px",border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",boxSizing:"border-box"})},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(a).snapLines.value,(n,t)=>(e.openBlock(),e.createElementBlock("div",{key:"snap-"+t,class:"hc-snap-line","data-snap-line":"","data-axis":n.axis,"data-kind":n.kind,style:e.normalizeStyle("x"===n.axis?{position:"absolute",left:n.pos+"px",top:n.from+"px",width:"0px",height:n.to-n.from+"px",borderLeft:"1px dashed #ec4899",pointerEvents:"none"}:{position:"absolute",left:n.from+"px",top:n.pos+"px",width:n.to-n.from+"px",height:"0px",borderTop:"1px dashed #ec4899",pointerEvents:"none"})},null,12,it))),128)),O.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[t.$slots["reparent-ghost"]?e.renderSlot(t.$slots,"reparent-ghost",{key:0,state:O.value}):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-reparent-ghost","data-hc-reparent-ghost":"","data-hc-reparent-state":O.value.result.ok?"legal":"illegal",style:e.normalizeStyle({position:"absolute",left:O.value.rect.x+"px",top:O.value.rect.y+"px",width:O.value.rect.w+"px",height:O.value.rect.h+"px",pointerEvents:"none",boxSizing:"border-box",border:"2px solid "+(O.value.result.ok?"#22c55e":"#ef4444"),background:O.value.result.ok?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)"})},[!O.value.result.ok&&O.value.result.message?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-reparent-ghost__message","data-hc-reparent-ghost-message":"","data-hc-reparent-ghost-reason":O.value.result.reason||"",style:{position:"absolute",left:"0",top:"100%",marginTop:"4px",maxWidth:"280px",padding:"3px 6px",background:"#ef4444",color:"#fff",fontSize:"11px",lineHeight:"16px",borderRadius:"3px",whiteSpace:"normal",wordBreak:"break-all",pointerEvents:"none",display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px"}},[O.value.result.reason?(e.openBlock(),e.createElementBlock("span",st,"["+e.toDisplayString(O.value.result.reason)+"]",1)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(O.value.result.message),1)],8,rt)):e.createCommentVNode("",!0)],12,at))],64)):e.createCommentVNode("",!0)],44,Zn))}}),dt=e.defineComponent({__name:"HyperCardCanvasDesigner",props:{modelValue:{},componentSourceMap:{},mode:{default:"design"},schedulerOptions:{},adapters:{},canvasId:{}},emits:["update:modelValue","context-ready","handle-ready","cannot-drag-slot-child","cannot-drag-layout-managed-child"],setup(n,{expose:t,emit:o}){const i=n,a=o;let r=!1;const s=i.canvasId??function(){const e=globalThis.crypto;return e&&"function"==typeof e.randomUUID?`hc-designer-${e.randomUUID()}`:`hc-designer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}(),c=ie({canvasId:s,initialDocument:i.modelValue,getMode:()=>i.mode,adapters:i.adapters});ae(c);const d=e.ref(null),l=Vn(c,{getStageEl:()=>{var e;return(null==(e=d.value)?void 0:e.querySelector("[data-hc-stage]"))??null},resolveContract:function(e){var n;const t=null==(n=i.componentSourceMap)?void 0:n[e];if(t)return"contract"in t&&t.contract?t.contract:void 0}}),u=!!c.adapters.data,p=Se({canvasId:s,source:{getDocument:()=>c.document.document,onAction:e=>c.registerHooks({onAfterAction:n=>e(n)})},initialMode:qn(i.mode),dataStore:u?c.dataStore:void 0});l.attachBindingDelegate(p,u?c.dataStore:null),a("context-ready",c),a("handle-ready",l);const f={getDropTarget:(e,n)=>l.getDropTarget(e,d.value,n),canReparent:(e,n)=>l.canReparent(e,n),moveInstanceInTree:(e,n)=>l.moveInstanceInTree(e,n),cannotReparentEvent:l.cannotReparentEvent};function h(){a("update:modelValue",JSON.parse(JSON.stringify(c.document.document)))}return e.provide(_n,f),e.watch(()=>i.modelValue,(e,n)=>{if(e&&e!==n){r=!0;try{c.suppressRecording(()=>{c.dispatch({type:"replaceDocument",payload:{document:e}})})}finally{r=!1}}}),e.watch(()=>c.document.document,()=>{r||c.isBatching.value||h()},{deep:!0,flush:"sync"}),e.watch(()=>c.isBatching.value,(e,n)=>{!n||e||r||h()},{flush:"sync"}),e.onMounted(()=>{Ge(s,l),e.nextTick(()=>{p.setMode(qn(i.mode))})}),e.watch(()=>i.mode,e=>{p.setMode(qn(e))}),e.onBeforeUnmount(()=>{p.dispose(),l.attachBindingDelegate(null,null),We(s),l.dispose(),c.dispose()}),t({context:c,handle:l,canvasId:s}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"stageContainerEl",ref:d,class:"hc-canvas-designer",style:{width:"100%",height:"100%",position:"relative"},"data-hc-canvas-designer":""},[e.createVNode(Kn,null,{default:e.withCtx(()=>[e.createVNode(Un,{"component-source-map":n.componentSourceMap,mode:n.mode,"scheduler-options":n.schedulerOptions,"canvas-id":e.unref(s)},null,8,["component-source-map","mode","scheduler-options","canvas-id"]),"runtime"!==n.mode?(e.openBlock(),e.createBlock(ct,{key:0,mode:n.mode,onCannotDragSlotChild:o[0]||(o[0]=e=>a("cannot-drag-slot-child",e)),onCannotDragLayoutManagedChild:o[1]||(o[1]=e=>a("cannot-drag-layout-managed-child",e))},e.createSlots({_:2},[t.$slots["reparent-ghost"]?{name:"reparent-ghost",fn:e.withCtx(n=>[e.renderSlot(t.$slots,"reparent-ghost",e.normalizeProps(e.guardReactiveProps(n)))]),key:"0"}:void 0,t.$slots["split-divider"]?{name:"split-divider",fn:e.withCtx(n=>[e.renderSlot(t.$slots,"split-divider",e.normalizeProps(e.guardReactiveProps(n)))]),key:"1"}:void 0]),1032,["mode"])):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"canvas-overlay",{viewport:e.unref(l).viewport,handle:e.unref(l)}),e.renderSlot(t.$slots,"default")]),_:3})],512))}});function lt(e={}){const{canvasWidth:n=1280,canvasHeight:t=720,rootLayout:o="free",instances:i=[],bindings:a=[]}=e;return{schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"px",value:n},height:{mode:"px",value:t}},rootLayout:"string"==typeof o?{mode:o}:o},instances:i,bindings:a}}const ut={event:["instanceEvent"],init:["lifecycle","page"],data:["dataSource"]};function pt(e){return ut[e.type].includes(e.source.kind)}function ft(e,n,t,o){const i={level:n,code:e,bindingId:t.id,message:`${e} on binding "${t.id}"`};return o.instanceId&&(i.instanceId=o.instanceId),o.canvasId&&(i.canvasId=o.canvasId),i}function ht(e){return"instanceEvent"===e.source.kind||"lifecycle"===e.source.kind?{instanceId:e.source.instanceId}:"instanceMethod"===e.target.kind||"instanceDataInput"===e.target.kind||"instanceEmit"===e.target.kind?{instanceId:e.target.instanceId}:{}}function gt(e){switch(e.source.kind){case"instanceEvent":case"lifecycle":return e.source.canvasId;case"page":case"dataSource":return}}function mt(e){switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":return e.target.canvasId}}exports.CANVAS_CONTEXT_KEY=oe,exports.CANVAS_REPARENT_BRIDGE_KEY=_n,exports.CanvasStage=Kn,exports.DEFAULT_FIT_PADDING=40,exports.DIVIDER_HIT_THICKNESS=8,exports.DRAG_THRESHOLD_CANVAS_PX=3,exports.EFFECTIVE_DEFAULT_SLOT=se,exports.HandleDisposedError=jn,exports.HyperCardCanvasDesigner=dt,exports.HyperCardPageRenderer=Ue,exports.InteractionLayer=ct,exports.MAX_INSTANCE_TREE_DEPTH=8,exports.MIN_INSTANCE_SIZE=8,exports.MIN_RATIO_FRACTION=.05,exports.RuntimeLayer=Un,exports.SLOT_CHILD_RESIZE_HANDLES=["e","s","se"],exports.VERSION="0.0.0-d3.6c-stage",exports.__resetRendererDiagnosticsRegistry=function(){const e=[...t.keys()];t.clear();for(const n of e)i("unregister",n)},exports.applyEffectiveSplitRatiosToDocument=f,exports.applySplitDividerDrag=Xn,exports.assertNeverBindingSource=U,exports.assertNeverBindingTarget=H,exports.bindingModeForCanvasMode=qn,exports.bindingReferencesInstance=J,exports.buildInstanceTree=Bn,exports.canReparent=Sn,exports.canvasSizeToCss=E,exports.cleanLayoutItem=_,exports.clientToCanvas=wn,exports.computeContentBounds=Dn,exports.computeEffectiveSplitRatios=k,exports.computeFit=Rn,exports.computeInverse=Qe,exports.computeNextAxisSize=vn,exports.computeNextLayoutBoxAxis=yn,exports.computeParentLayoutMode=V,exports.computeSelectionBounds=Pn,exports.computeSlotChildCanvasRect=mn,exports.computeSnap=on,exports.computeSplitDividers=Hn,exports.computeVisibleBounds=On,exports.containerLayoutToCss=z,exports.createAssetResolver=Z,exports.createCanvasContext=ie,exports.createCanvasHandle=Vn,exports.createCanvasInteraction=bn,exports.createCommandRecorder=nn,exports.createDocumentStore=G,exports.createFreePageDocument=function(e={}){return lt({...e,rootLayout:"free"})},exports.createMinimalPageDocument=lt,exports.createRenderScheduler=q,exports.createSelectionStore=W,exports.createSplitDividerInteraction=Yn,exports.createViewportStore=Q,exports.deriveComponentContract=Te,exports.deriveComponentKind=function(e,t){const o="string"==typeof(null==e?void 0:e.js)?e.js:"",i="string"==typeof(null==e?void 0:e.html)?e.html:"",a=n.parseComponentSource(o,i);return!a.ok&&(null==t?void 0:t.fallback)?t.fallback:a.kind},exports.effectiveSlot=ce,exports.emptyComponentContract=function(){return{propsDecl:[],emitsDecl:[],methodsDecl:[],slotsDecl:[],modelDecl:[],dataInputsDecl:[],dataOutputsDecl:[]}},exports.emptyPageDocument=function(){return{schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}},exports.filterExistingIds=xn,exports.filterInstancesInRect=sn,exports.findInstanceBreadcrumb=zn,exports.findInstancePath=Cn,exports.getBindingInstanceRefs=K,exports.getDefaultShortcuts=function(){return[{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]},exports.getDesignerHandle=function(e){return He.get(e)??null},exports.getInstanceWrapperRectFromDom=ln,exports.getOutletRectFromDom=dn,exports.getParentLayoutMode=un,exports.getRendererDiagnostics=function(e){return t.get(e)??null},exports.getSiblings=Ln,exports.getSlotChildRectFromDom=function(e,n){var t;const o=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!o)return null;const i="undefined"!=typeof globalThis&&(null==(t=globalThis.CSS)?void 0:t.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),a=o.querySelector(`[data-instance-id="${i(e)}"][data-hc-placement="slot"]`);return a&&a instanceof HTMLElement?a.getBoundingClientRect():null},exports.hitTestInstance=an,exports.isAdditive=In,exports.isCanvasRootPlacement=function(e){return"canvas"===e||"absolute"===e||void 0===e},exports.isContainerChildPlacement=j,exports.isDraftKey=function(e){return"string"==typeof e&&e.includes("@draft:")},exports.isEditingText=An,exports.isFreePositionLayoutMode=pn,exports.isInstanceEffectivelyLocked=Qn,exports.isInstancePositionLocked=Gn,exports.isInstanceSizeLocked=Wn,exports.isResizeHandleAllowed=gn,exports.isV1Layout=B,exports.layoutItemToCss=L,exports.listRegisteredCanvasIds=function(){return Object.freeze(Array.from(He.keys()))},exports.listRendererDiagnostics=function(){return[...t.values()]},exports.matchBinding=Nn,exports.migrateGridCellsToLayoutItem=h,exports.migrateInstanceToLayoutBox=N,exports.migrateLayoutV0ToV1=S,exports.migratePlacementToCanvasContainer=A,exports.migrateRootLayout=F,exports.normalizeComponentOverrides=m,exports.normalizeGridCells0Based=g,exports.normalizeInstanceSlotFields=v,exports.normalizeKeyString=Fn,exports.normalizeMarqueeRect=rn,exports.normalizePageBindings=d,exports.normalizePageDocument=p,exports.parseComponentVersionKey=function(e){if("string"!=typeof e||!e.includes("@"))return null;const n=e.indexOf("@"),t=e.slice(0,n),o=e.slice(n+1);if(!t)return null;if(o.startsWith("draft:")){const e=o.slice(6),n=e.indexOf(":");if(n<=0)return null;const i=e.slice(0,n),a=e.slice(n+1);return i&&a?{kind:"draft",componentId:t,pageId:i,baseVersion:a,baseVersionKey:`${t}@${a}`}:null}return o?{kind:"published",componentId:t,version:o}:null},exports.parseKeyEvent=$n,exports.provideCanvasContext=ae,exports.registerDesignerHandle=Ge,exports.registerRendererDiagnostics=a,exports.renderLayoutBoxStyle=T,exports.resolveCanvasSizePx=function(e,n=1920){return"px"===e.mode?e.value:n},exports.resolveMeasuredCanvasSizePx=M,exports.subscribeDesignerRegistry=function(e){return Xe.add(e),()=>{Xe.delete(e)}},exports.subscribeRendererDiagnostics=function(e){return o.add(e),()=>o.delete(e)},exports.unionRects=En,exports.unregisterDesignerHandle=We,exports.unregisterRendererDiagnostics=r,exports.useCanvasContext=re,exports.validateBindings=function(e,n){var t,o,i;const a=[],r=new Map;for(const n of e.instances)r.set(n.instanceId,n);const s=null==n?void 0:n.currentCanvasId,c=null==n?void 0:n.resolveContract;let d=null,l=null;if(c){d=new Map,l=new Map;for(const n of e.instances){const e=c(n.componentVersionKey);if(d.set(n.instanceId,e),e)for(const t of e.dataInputsDecl)if(t.required){let e=l.get(n.instanceId);e||(e=new Set,l.set(n.instanceId,e)),e.add(t.key)}}}for(const n of e.bindings)if(pt(n)){if(void 0!==s){const e=gt(n),t=mt(n);void 0!==e&&e!==s&&a.push(ft("unsupported-cross-canvas","error",n,{canvasId:e})),void 0!==t&&t!==s&&a.push(ft("unsupported-cross-canvas","error",n,{canvasId:t}))}switch(n.source.kind){case"instanceEvent":{const e=n.source.event,t=r.get(n.source.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.emitsDecl.some(n=>n.event===e)&&a.push(ft("unknown-source-event","error",n,{instanceId:t.instanceId}))}}else a.push(ft("orphan-binding","warn",n,{instanceId:n.source.instanceId}));break}case"lifecycle":r.get(n.source.instanceId)||a.push(ft("orphan-binding","warn",n,{instanceId:n.source.instanceId}))}switch(n.target.kind){case"instanceMethod":{const e=n.target.method,t=r.get(n.target.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.methodsDecl.some(n=>n.key===e)&&a.push(ft("unknown-target-method","error",n,{instanceId:t.instanceId}))}}else a.push(ft("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}case"instanceEmit":{const e=n.target.event,t=r.get(n.target.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.emitsDecl.some(n=>n.event===e)&&a.push(ft("unknown-target-event","error",n,{instanceId:t.instanceId}))}}else a.push(ft("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}case"instanceDataInput":{const e=n.target.key,o=r.get(n.target.instanceId);if(o){if(d){const i=d.get(o.instanceId);i&&!i.dataInputsDecl.some(n=>n.key===e)?a.push(ft("unknown-target-data-input","error",n,{instanceId:o.instanceId})):l&&(null==(t=l.get(o.instanceId))||t.delete(e))}}else a.push(ft("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}}(null==(o=n.schedule)?void 0:o.throttle)&&n.schedule.throttle.windowMs<16&&a.push(ft("schedule-window-too-small","info",n,ht(n))),(null==(i=n.schedule)?void 0:i.debounce)&&n.schedule.debounce.windowMs<16&&a.push(ft("schedule-window-too-small","info",n,ht(n)))}else a.push(ft("invalid-type-source-kind","error",n,ht(n)));if(l)for(const[e,n]of l)for(const t of n){const n={level:"warn",code:"required-data-input-missing",instanceId:e,key:t,message:`Required dataInput "${t}" on instance "${e}" is not fed by any binding`};a.push(n)}return a},exports.validateInstanceTree=de,exports.wirePageBindings=Se;
1
+ !function(){"use strict";try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode(".hc-canvas-stage[data-v-825e0ee8]{position:relative;width:100%;height:100%;overflow:hidden;background:#f1f5f9;isolation:isolate}.hc-canvas-stage__world[data-v-825e0ee8]{position:absolute;top:0;left:0;will-change:transform}.hc-fs-leaf-empty[data-v-ccd54f15]{position:absolute;top:3px;right:3px;bottom:3px;left:3px;border:1px dashed rgba(100,116,139,.5);border-radius:4px;display:flex;align-items:center;justify-content:center;pointer-events:none}.hc-fs-leaf-hint[data-v-ccd54f15]{font-size:12px;color:#64748bd9;pointer-events:none;-webkit-user-select:none;user-select:none}.hc-fs-leaf-edge[data-v-ccd54f15]:hover{box-shadow:inset 0 0 0 1px #3b82f64d}.hc-fs-leaf-toolbar[data-v-ccd54f15]{position:absolute;top:4px;right:4px;display:inline-flex;gap:4px;pointer-events:none;opacity:0;transition:opacity .12s ease}.hc-fs-leaf-edge:hover .hc-fs-leaf-toolbar[data-v-ccd54f15],.hc-fs-leaf-edge.is-empty .hc-fs-leaf-toolbar[data-v-ccd54f15]{opacity:1}.hc-fs-leaf-btn[data-v-ccd54f15]{pointer-events:auto;width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center;border:1px solid rgba(59,130,246,.5);background:#fffffff2;color:#2563eb;border-radius:6px;cursor:pointer;font-size:13px;line-height:1;box-shadow:0 1px 2px #0000001f}.hc-fs-leaf-btn[data-v-ccd54f15]:hover{background:#eff6ff;border-color:#3b82f6}.hc-fs-leaf-btn--danger[data-v-ccd54f15]{color:#dc2626;border-color:#dc262680}.hc-fs-leaf-btn--danger[data-v-ccd54f15]:hover{background:#fef2f2;border-color:#dc2626}.hc-fs-leaf-move[data-v-ccd54f15]{cursor:grab;color:#475569;border-color:#47556973}.hc-fs-leaf-move[data-v-ccd54f15]:active{cursor:grabbing}.hc-fs-leaf-edge.is-drop-target[data-v-ccd54f15]{box-shadow:inset 0 0 0 2px #3b82f6e6}.hc-fs-divider[data-v-ccd54f15]:hover{box-shadow:inset 0 0 0 1px #3b82f680}.hc-fs-divider-grip[data-v-ccd54f15]{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);background:#3b82f6bf;border-radius:999px;pointer-events:none}.hc-fs-divider[data-hc-fs-divider-direction=horizontal] .hc-fs-divider-grip[data-v-ccd54f15]{width:4px;height:26px}.hc-fs-divider[data-hc-fs-divider-direction=vertical] .hc-fs-divider-grip[data-v-ccd54f15]{width:26px;height:4px}.hc-fs-merge-btn[data-v-ccd54f15]{position:absolute;pointer-events:none;opacity:0;transition:opacity .12s ease;width:22px;height:22px;display:inline-flex;align-items:center;justify-content:center;border:1px solid rgba(59,130,246,.6);background:#fffffff7;color:#2563eb;border-radius:999px;cursor:pointer;font-size:12px;line-height:1;box-shadow:0 1px 3px #0000002e}.hc-fs-divider[data-hc-fs-divider-direction=horizontal] .hc-fs-merge-btn[data-v-ccd54f15]{top:10px;left:50%;transform:translate(-50%)}.hc-fs-divider[data-hc-fs-divider-direction=vertical] .hc-fs-merge-btn[data-v-ccd54f15]{left:10px;top:50%;transform:translateY(-50%)}.hc-fs-divider:hover .hc-fs-merge-btn[data-v-ccd54f15]{pointer-events:auto;opacity:1}.hc-fs-merge-btn[data-v-ccd54f15]:hover{background:#eff6ff;border-color:#3b82f6}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}}();
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@hy-bricks/core"),t=new Map,o=new Set;function i(e,n){const t=[...o];for(const o of t)try{o(e,n)}catch{}}function a(e,n){t.has(e)&&console.warn(`[hc-rendererDiagnostics] canvasId "${e}" already registered, overwriting`),t.set(e,n),i("register",e)}function r(e){t.has(e)&&(t.delete(e),i("unregister",e))}function c(e){return JSON.parse(JSON.stringify(e))}const s="[hc-canvas/normalizeBindings]";function d(e){if(!Array.isArray(e))return[];const n=[];for(let t=0;t<e.length;t++){const o=e[t];if(!o||"object"!=typeof o){console.warn(`${s} dropped non-object binding at index ${t}`);continue}if(l(o)){n.push(o);continue}const i=u(o);null!==i&&n.push(i)}return n}function l(e){if(!e||"object"!=typeof e)return!1;const n=e;if("string"!=typeof n.id||0===n.id.length)return!1;if("event"!==n.type&&"init"!==n.type&&"data"!==n.type)return!1;const t=n.source;if(!t||"object"!=typeof t)return!1;if("string"!=typeof t.kind)return!1;const o=n.target;return!(!o||"object"!=typeof o)&&"string"==typeof o.kind}function u(e){if("string"!=typeof e.id||0===e.id.length)return console.warn(`${s} dropped binding with missing/invalid id`),null;const n=e.target;if(!n||"object"!=typeof n||"string"!=typeof n.instanceId||""===n.instanceId||"string"!=typeof n.method)return console.warn(`${s} dropped binding "${e.id}" missing/invalid target`),null;const t=e.type;let o;if("event"===t){const n=e.source;if(!n||"object"!=typeof n||"string"!=typeof n.instanceId||""===n.instanceId||"string"!=typeof n.event)return console.warn(`${s} dropped event binding "${e.id}" missing/invalid source`),null;o={kind:"instanceEvent",instanceId:n.instanceId,event:n.event}}else{if("init"!==t)return console.warn(`${s} dropped binding "${e.id}" with unknown legacy type "${String(e.type)}"`),null;{const n=e.source;n&&"string"==typeof n.instanceId&&""!==n.instanceId&&console.warn(`${s} init binding "${e.id}" had source.instanceId, discarded`),o={kind:"page",hook:"pageInit"}}}const i={kind:"instanceMethod",instanceId:n.instanceId,method:n.method};let a;a=void 0===n.args?{kind:"passthrough"}:Array.isArray(n.args)&&0===n.args.length?{kind:"static",args:[]}:Array.isArray(n.args)?{kind:"static",args:c(n.args)}:{kind:"passthrough"};const r={},d=e.options;d&&"object"==typeof d&&(!0===d.once&&(r.once=!0),"number"==typeof d.throttleMs&&(r.throttle={windowMs:d.throttleMs}),"number"==typeof d.debounceMs&&(r.debounce={windowMs:d.debounceMs}));const l=void 0!==r.once||void 0!==r.throttle||void 0!==r.debounce,u={id:e.id,source:o,target:i,mapping:a,...void 0!==e.disabled?{disabled:e.disabled}:{},...l?{schedule:r}:{}};return"event"===t?{...u,type:"event"}:{...u,type:"init"}}function p(){const e=globalThis.crypto;return(null==e?void 0:e.randomUUID)?e.randomUUID().replace(/-/g,"").slice(0,10):Math.floor(0xffffffffff*Math.random()).toString(36)}function f(){return`lf_${p()}`}function g(){return{type:"leaf",leafId:f(),instanceId:null}}function h(e){const n=e.instances.map(x),t=I(e.componentOverrides,n),o=d(e.bindings);if("1"===e.schemaVersion){const i=_(T(e.layout)?e.layout:M(e.layout));return{...e,layout:i,instances:n,bindings:o,componentOverrides:t}}return{schemaVersion:"1",layout:_(M(e.layout)),instances:n,bindings:o,componentOverrides:t}}function m(e){const n=function(e){var n;const t=new Map;for(const o of e){if(!o.parentId)continue;if(void 0!==o.slot)continue;const e=t.get(o.parentId),i=null==(n=o.layoutItem)?void 0:n.ratio;e?e.push(i):t.set(o.parentId,[i])}let o=!1;const i=e.map(e=>{if(!e.containerLayout||"split"!==e.containerLayout.mode)return e;const n=t.get(e.instanceId)??[],i=e.containerLayout.ratios,a=z(i,n);return i.length===a.length&&i.every((e,n)=>e===a[n])?e:(o=!0,{...e,containerLayout:{...e.containerLayout,ratios:a}})});return o?i:e}(e.instances),t=e.layout.rootLayout?function(e,n){const t=e.rootLayout;if(!t||"split"!==t.mode)return e;const o=n.filter(e=>void 0===e.parentId).map(e=>{var n;return null==(n=e.layoutItem)?void 0:n.ratio}),i=t.ratios,a=z(i,o);return i.length===a.length&&i.every((e,n)=>e===a[n])?e:{...e,rootLayout:{...t,ratios:a}}}(e.layout,n):e.layout;return n===e.instances&&t===e.layout?e:{...e,layout:t,instances:n}}function v(e){const n=new Map,t=new Set;for(const o of e.instances){const e=o.containerLayout;if("grid"!==(null==e?void 0:e.mode))continue;t.add(o.instanceId);const i=e.cells;i&&"object"==typeof i&&Object.keys(i).length>0&&n.set(o.instanceId,y(i))}if(0===t.size)return e;let o=!1;const i=e.instances.map(e=>{if(!e.parentId)return e;if(void 0!==e.slot)return e;if(!t.has(e.parentId))return e;const i=e.layoutItem;if(i&&("number"==typeof i.row||"number"==typeof i.column)){const n=function(e){const n="number"==typeof e.row&&Number.isFinite(e.row)&&e.row<1,t="number"==typeof e.column&&Number.isFinite(e.column)&&e.column<1;if(!n&&!t)return e;const o={...e};return n&&(o.row=1),t&&(o.column=1),o}(i);return n===i?e:(o=!0,{...e,layoutItem:n})}const a=n.get(e.parentId),r=null==a?void 0:a[e.instanceId];if(!r)return e;const c=function(e){const n={};return"number"==typeof e.row&&Number.isFinite(e.row)&&(n.row=e.row<1?1:e.row),"number"==typeof e.column&&Number.isFinite(e.column)&&(n.column=e.column<1?1:e.column),void 0===n.row&&void 0===n.column?null:("number"==typeof e.rowSpan&&Number.isFinite(e.rowSpan)&&e.rowSpan>0&&e.rowSpan<=32&&(n.rowSpan=e.rowSpan),"number"==typeof e.columnSpan&&Number.isFinite(e.columnSpan)&&e.columnSpan>0&&e.columnSpan<=32&&(n.columnSpan=e.columnSpan),n)}(r);return c?(o=!0,{...e,layoutItem:{...i??{},...c}}):e});return o?{...e,instances:i}:e}function y(e){let n=!1;for(const t of Object.values(e))if(t&&(0===t.row||0===t.column)){n=!0;break}if(!n)return e;const t={};for(const[n,o]of Object.entries(e)){if(!o)continue;const e={...o};"number"==typeof e.row&&Number.isFinite(e.row)&&(e.row=e.row+1),"number"==typeof e.column&&Number.isFinite(e.column)&&(e.column=e.column+1),t[n]=e}return t}function I(e,n){if(!e||"object"!=typeof e||Array.isArray(e))return{};const t=new Set(n.map(e=>e.instanceId)),o={};for(const[n,i]of Object.entries(e)){if(!i||"object"!=typeof i||Array.isArray(i))continue;const e=i;e.instanceId===n&&t.has(e.instanceId)&&"string"==typeof e.baseVersionKey&&e.baseVersionKey&&$(e.source)&&O(e.contract)&&(o[n]={instanceId:e.instanceId,baseVersionKey:e.baseVersionKey,source:e.source,contract:e.contract,...F(e.contractParseError)?{contractParseError:F(e.contractParseError)}:{},..."string"==typeof e.createdAt?{createdAt:e.createdAt}:{},..."string"==typeof e.updatedAt?{updatedAt:e.updatedAt}:{}})}return o}function x(e){let n=e;void 0===n.parentId&&n.slotPlacement&&(n={...n,parentId:n.slotPlacement.parentInstanceId,slot:n.slotPlacement.slotName}),""!==n.slot&&"default"!==n.slot||(n={...n,slot:void 0}),void 0===n.placement&&(n={...n,placement:void 0===n.parentId?"absolute":"slot"});const t=b(n.sizing,n.size);if(t!==n.size&&(n={...n,size:t}),void 0!==n.containerLayout){const e=B(n.containerLayout);if(e!==n.containerLayout)if(null===e){const{containerLayout:e,...t}=n;n=t}else n={...n,containerLayout:e}}if(n=j(n),n=V(n),void 0!==n.layoutItem){const e=U(n.layoutItem);if(null===e){const{layoutItem:e,...t}=n;n=t}else e!==n.layoutItem&&(n={...n,layoutItem:e})}if(!0===n.locked){const e={};void 0===n.lockPosition&&(e.lockPosition=!0),void 0===n.lockSize&&(e.lockSize=!0),Object.keys(e).length>0&&(n={...n,...e})}return n}const w=new Set(["px","percent","fill","hug","auto"]);function b(e,n){var t,o,i,a;const r=n?function(e){const n={},t=k(e.width),o=k(e.height);return t&&(n.width=t),o&&(n.height=o),n.width||n.height?n:void 0}(n):void 0;if(!e)return r;const c={};if(e.width){const n=S(e.width,null==(t=e.min)?void 0:t.w,null==(o=e.max)?void 0:o.w);n&&(c.width=n)}if(e.height){const n=S(e.height,null==(i=e.min)?void 0:i.h,null==(a=e.max)?void 0:a.h);n&&(c.height=n)}return r?{width:r.width??c.width,height:r.height??c.height}:Object.keys(c).length>0?c:void 0}function S(e,n,t){if(!e||"object"!=typeof e)return null;let o;switch(e.mode){case"fixed":o="px";break;case"percent":o="percent";break;case"fill":o="fill";break;case"hug":o="hug";break;default:return null}const i={mode:o};return"px"!==o&&"percent"!==o||"number"!=typeof e.value||(i.value=e.value),"number"==typeof n&&(i.min=n),"number"==typeof t&&(i.max=t),i}function k(e){if(!e||"object"!=typeof e)return null;if("string"!=typeof e.mode)return null;if(!w.has(e.mode))return null;const n={mode:e.mode};return"px"!==e.mode&&"percent"!==e.mode||"number"!=typeof e.value||(n.value=e.value),"number"==typeof e.min&&(n.min=e.min),"number"==typeof e.max&&(n.max=e.max),n}function B(e){if(!e||"object"!=typeof e)return null;if("none"===e.mode)return{mode:"none"};if("free"===e.mode)return{mode:"free"};if("flex"===e.mode){const n=e,t={mode:"flex",direction:"row"===n.direction||"column"===n.direction?n.direction:"row"};return!0===n.wrap&&(t.wrap=!0),"number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0&&(t.gap=n.gap),"start"!==n.justify&&"center"!==n.justify&&"end"!==n.justify&&"space-between"!==n.justify&&"space-around"!==n.justify||(t.justify=n.justify),"start"!==n.align&&"center"!==n.align&&"end"!==n.align&&"stretch"!==n.align||(t.align=n.align),t}if("split"===e.mode){const n=e;if("horizontal"!==n.direction&&"vertical"!==n.direction)return null;if(!Array.isArray(n.ratios))return null;const t=n.ratios.filter(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0),o={mode:"split",direction:n.direction,ratios:t};return"number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0&&(o.gap=n.gap),o}if("grid"===e.mode){const n=e;if(!Array.isArray(n.columns)||!Array.isArray(n.rows))return null;const t={mode:"grid",columns:n.columns.filter(e=>!!e&&("fr"===e.mode||"px"===e.mode||"percent"===e.mode)&&"number"==typeof e.value&&Number.isFinite(e.value)&&e.value>=0).slice(0,32),rows:n.rows.filter(e=>!!e&&("fr"===e.mode||"px"===e.mode||"percent"===e.mode||"auto"===e.mode)&&("auto"===e.mode&&void 0===e.value||"number"==typeof e.value&&Number.isFinite(e.value)&&e.value>=0)).slice(0,32)};if("number"==typeof n.gap&&Number.isFinite(n.gap)&&n.gap>=0)t.gap=n.gap;else if(n.gap&&"object"==typeof n.gap){const e={};"number"==typeof n.gap.row&&Number.isFinite(n.gap.row)&&n.gap.row>=0&&(e.row=n.gap.row),"number"==typeof n.gap.column&&Number.isFinite(n.gap.column)&&n.gap.column>=0&&(e.column=n.gap.column),Object.keys(e).length>0&&(t.gap=e)}if(n.cells&&"object"==typeof n.cells&&!Array.isArray(n.cells)){const e={};for(const[t,o]of Object.entries(n.cells)){if(!o||"object"!=typeof o)continue;if(!Number.isFinite(o.row)||!Number.isFinite(o.column))continue;const n={row:o.row,column:o.column};"number"==typeof o.rowSpan&&Number.isFinite(o.rowSpan)&&o.rowSpan>0&&o.rowSpan<=32&&(n.rowSpan=o.rowSpan),"number"==typeof o.columnSpan&&Number.isFinite(o.columnSpan)&&o.columnSpan>0&&o.columnSpan<=32&&(n.columnSpan=o.columnSpan),e[t]=n}Object.keys(e).length>0&&(t.cells=e)}return t}return"free-split"===e.mode?e:null}function z(e,n){const t=(e??[]).map(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0),o=[];for(let e=0;e<n.length;e++){const i=n[e];if("number"==typeof i&&Number.isFinite(i)&&i>0){o.push(i);continue}const a=t[e];"number"==typeof a&&a>0?o.push(a):o.push(1)}return o}function M(e){if(!e)return{type:"free",canvas:{width:{mode:"px",value:1920},height:{mode:"px",value:1080}}};if(T(e))return e;const n=e,t={width:{mode:"px",value:n.canvas.w},height:{mode:"px",value:n.canvas.h}},o=function(e){if(!e)return;const n={};if(void 0!==e.color&&(n.color=e.color),void 0!==e.imageAssetId){const t={id:e.imageAssetId,type:"image"};n.image=t}return void 0!==e.fit&&(n.imageFit="original"===e.fit?"center":e.fit),Object.keys(n).length>0?n:void 0}(n.canvas.background),i={type:n.type,canvas:t};return o&&(i.background=o),void 0!==n.canvas.gridSize&&(i.guides={grid:{size:n.canvas.gridSize}}),i}function T(e){if(!e)return!1;const n=e.canvas;if(!n)return!1;const t=n.width;return"object"==typeof t&&null!==t&&"mode"in t&&"string"==typeof t.mode}function C(e,n,t=1920){switch(e.mode){case"px":return e.value;case"percent":return n>0?n*e.value/100:t;case"vw":return"undefined"!=typeof window?window.innerWidth*e.value/100:t;case"vh":return"undefined"!=typeof window?window.innerHeight*e.value/100:t;case"auto":case"fill":return n>0?n:t}}function L(e,n,t,o,i){const a=E(e.widthMode,e.width),r=E(e.heightMode,e.height),c="free"===o,s={boxSizing:"border-box",minWidth:0,minHeight:0,overflow:e.overflow??"hidden",zIndex:n};return null!==a&&(s.width=a),null!==r&&(s.height=r),"split"===o&&("vertical"===i?s.height="100%":s.width="100%"),"number"==typeof t&&Number.isFinite(t)&&0!==t&&(s.transform=`rotate(${t}deg)`),c?(s.position="absolute",s.left=`${e.x}px`,s.top=`${e.y}px`):s.position="relative",s}function E(e,n){switch(e){case"px":return`${n}px`;case"percent":return`${n}%`;case"fill":return"100%";case"auto":return"auto"}}function D(e){if(!e||"none"===e.mode||"free"===e.mode)return null;if("flex"===e.mode){const n={display:"flex"};if(n.flexDirection=e.direction??"row",e.wrap&&(n.flexWrap="wrap"),"number"==typeof e.gap&&(n.gap=`${e.gap}px`),e.justify){const t={start:"flex-start",end:"flex-end",center:"center","space-between":"space-between","space-around":"space-around"};n.justifyContent=t[e.justify]??e.justify}if(e.align){const t={start:"flex-start",end:"flex-end",center:"center",stretch:"stretch"};n.alignItems=t[e.align]??e.align}return n}if("grid"===e.mode){const n={display:"grid"},t=(e.columns??[]).map(e=>"fr"===e.mode?`${e.value}fr`:"px"===e.mode?`${e.value}px`:`${e.value}%`).join(" "),o=(e.rows??[]).map(e=>"auto"===e.mode?"auto":"fr"===e.mode?`${e.value??1}fr`:"px"===e.mode?`${e.value??0}px`:`${e.value??0}%`).join(" ");if(t&&(n.gridTemplateColumns=t),o&&(n.gridTemplateRows=o),"number"==typeof e.gap)n.gap=`${e.gap}px`;else if(e.gap&&"object"==typeof e.gap){const t=e.gap.row??0,o=e.gap.column??0;n.gap=`${t}px ${o}px`}return n}if("split"===e.mode){const n=(Array.isArray(e.ratios)?e.ratios:[]).map(e=>"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0).filter(e=>e>0),t=n.length>0?n.map(e=>`${e}fr`).join(" "):"1fr",o={display:"grid"};return"vertical"===e.direction?o.gridTemplateRows=t:o.gridTemplateColumns=t,"number"==typeof e.gap&&(o.gap=`${e.gap}px`),o}return e.mode,null}function P(e,n){if(!e)return null;if("flex"===n){const n={};return"number"==typeof e.order&&(n.order=e.order),"number"==typeof e.grow&&(n.flexGrow=e.grow),"number"==typeof e.shrink&&(n.flexShrink=e.shrink),Object.keys(n).length>0?n:null}if("grid"===n){const n={};if("number"==typeof e.row){const t="number"==typeof e.rowSpan&&e.rowSpan>0?e.rowSpan:1;n.gridRow=t>1?`${e.row} / span ${t}`:`${e.row}`}if("number"==typeof e.column){const t="number"==typeof e.columnSpan&&e.columnSpan>0?e.columnSpan:1;n.gridColumn=t>1?`${e.column} / span ${t}`:`${e.column}`}return Object.keys(n).length>0?n:null}return null}function R(e){switch(e.mode){case"px":return`${e.value}px`;case"percent":return`${e.value}%`;case"vw":return`${e.value}vw`;case"vh":return`${e.value}vh`;case"auto":return"auto";case"fill":return"100%"}}function $(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.html&&"string"==typeof e.js&&"string"==typeof e.css}function O(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;const n=e;return["propsDecl","emitsDecl","methodsDecl","slotsDecl","modelDecl","dataInputsDecl","dataOutputsDecl"].every(e=>Array.isArray(n[e]))}function F(e){if(!e||"object"!=typeof e||Array.isArray(e))return;const n=e;return"string"==typeof n.message?{message:n.message,..."number"==typeof n.line?{line:n.line}:{},..."number"==typeof n.column?{column:n.column}:{}}:void 0}const A=new Set(["px","percent","fill","auto"]),N=new Set(["hidden","visible","auto"]);function j(e){const n=e.placement;return"canvas"===n||"container"===n?e:"absolute"===n?{...e,placement:"canvas"}:"slot"===n?{...e,placement:"container"}:{...e,placement:e.parentId?"container":"canvas"}}function V(e){var n,t;const o=e.rect??{x:0,y:0,w:0,h:0},i=null==(n=e.size)?void 0:n.width,a=null==(t=e.size)?void 0:t.height,r=e=>{if(e)return"hug"===e.mode?"auto":"percent"===e.mode?"percent":"fill"===e.mode?"fill":"auto"===e.mode?"auto":"px"===e.mode?"px":void 0},c=e.layoutBox,s=c&&A.has(c.widthMode)?c.widthMode:r(i)??"px",d=c&&A.has(c.heightMode)?c.heightMode:r(a)??"px",l=(e,n)=>"number"==typeof e&&Number.isFinite(e)?e:n,u={x:l(null==c?void 0:c.x,o.x),y:l(null==c?void 0:c.y,o.y),width:l(null==c?void 0:c.width,(null==i?void 0:i.value)??o.w),height:l(null==c?void 0:c.height,(null==a?void 0:a.value)??o.h),widthMode:s,heightMode:d,overflow:(null==c?void 0:c.overflow)&&N.has(c.overflow)?c.overflow:"hidden"};return c&&c.x===u.x&&c.y===u.y&&c.width===u.width&&c.height===u.height&&c.widthMode===u.widthMode&&c.heightMode===u.heightMode&&c.overflow===u.overflow?e:{...e,layoutBox:u}}let q=!1;function _(e){if(e.rootLayout){const o=B(e.rootLayout);return null===o?{...e,rootLayout:{mode:"free"}}:"free-split"===o.mode?(q||(q=!0,console.warn("[hypercard] rootLayout.mode='free-split' 不支持(free-split 仅用于容器实例,根画布无 outlet/containerId 锚),已降级为 'free'。")),{...e,rootLayout:{mode:"free"}}):(t=o,(n=e.rootLayout).mode===t.mode&&JSON.stringify(n)===JSON.stringify(t)?e:{...e,rootLayout:o})}var n,t;return{...e,rootLayout:{mode:"free"}}}function K(e){return"container"===e||"slot"===e}function J(e,n,t){var o,i;const a=n.find(e=>e.instanceId===t);if(!a)return;if(void 0===a.parentId)return(null==(o=null==e?void 0:e.rootLayout)?void 0:o.mode)??"free";const r=n.find(e=>e.instanceId===a.parentId);return(null==(i=null==r?void 0:r.containerLayout)?void 0:i.mode)??"none"}function U(e){if(!e||"object"!=typeof e)return null;const n={},t=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"];for(const o of t){const t=e[o];"number"==typeof t&&Number.isFinite(t)&&(n[o]=t)}return Object.keys(n).length>0?n:null}function H(n={}){const{rootMargin:t="500px",disposeDelayMs:o=1500,mountConcurrency:i=2,root:a=null}=n,r={state:e.reactive({}),elById:new Map,idByEl:new WeakMap,mountQueue:[],disposeTimers:new Map,idleScheduled:!1,io:null,counts:{pending:0,mounting:0,mounted:0,disposing:0}};function c(e,n){const t=r.state[e];t!==n&&(void 0!==t&&"idle"!==t&&r.counts[t]--,r.state[e]=n,"idle"!==n&&r.counts[n]++)}function s(e){for(const n of e){const e=r.idByEl.get(n.target);e&&(n.isIntersecting?d(e):l(e))}}function d(e){const n=r.disposeTimers.get(e);n&&(clearTimeout(n),r.disposeTimers.delete(e));const t=r.state[e];"mounted"!==t&&"disposing"!==t?(c(e,"mounting"),r.mountQueue.includes(e)||r.mountQueue.push(e),u()):c(e,"mounted")}function l(e){const n=r.state[e];if("pending"===n||"idle"===n)return;if("mounting"===n){const n=r.mountQueue.indexOf(e);return n>=0&&r.mountQueue.splice(n,1),void c(e,"pending")}c(e,"disposing");const t=r.disposeTimers.get(e);t&&clearTimeout(t);const i=setTimeout(()=>{"disposing"===r.state[e]&&(c(e,"pending"),r.disposeTimers.delete(e))},o);r.disposeTimers.set(e,i)}function u(){r.idleScheduled||0===r.mountQueue.length||(r.idleScheduled=!0,function(e,n=50){const t=globalThis;"function"==typeof t.requestIdleCallback?t.requestIdleCallback(()=>e(),{timeout:n}):setTimeout(e,16)}(()=>{r.idleScheduled=!1;let e=0;for(;e<i&&r.mountQueue.length>0;){const n=r.mountQueue.shift();"mounting"===r.state[n]&&(c(n,"mounted"),e++)}r.mountQueue.length>0&&u()}))}return{register(e,n){const o=r.elById.get(e);if(o&&o!==n){const e=r.io;e&&e.unobserve(o),r.idByEl.delete(o)}r.elById.set(e,n),r.idByEl.set(n,e),c(e,"pending");const i=r.io?r.io:"undefined"==typeof IntersectionObserver?null:(r.io=new IntersectionObserver(s,{root:a,rootMargin:t}),r.io);i?i.observe(n):c(e,"mounted")},unregister(e){const n=r.elById.get(e);if(n){const t=r.io;t&&t.unobserve(n),r.idByEl.delete(n),r.elById.delete(e)}const t=r.disposeTimers.get(e);t&&(clearTimeout(t),r.disposeTimers.delete(e));const o=r.mountQueue.indexOf(e);o>=0&&r.mountQueue.splice(o,1),function(e){const n=r.state[e];void 0!==n&&"idle"!==n&&r.counts[n]--,delete r.state[e]}(e)},isMounted(e){const n=r.state[e];return"mounted"===n||"disposing"===n},getState:e=>r.state[e]??"idle",get state(){return r.state},getStats:()=>({...r.counts}),dispose(){r.io&&(r.io.disconnect(),r.io=null);for(const e of r.disposeTimers.values())clearTimeout(e);r.disposeTimers.clear(),r.elById.clear(),r.mountQueue.length=0;for(const e of Object.keys(r.state))delete r.state[e];r.counts.pending=0,r.counts.mounting=0,r.counts.mounted=0,r.counts.disposing=0}}}function X(e){const n=[];switch(e.source.kind){case"instanceEvent":case"lifecycle":n.push({canvasId:e.source.canvasId,instanceId:e.source.instanceId});break;case"page":case"dataSource":break;default:G(e.source)}switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":n.push({canvasId:e.target.canvasId,instanceId:e.target.instanceId});break;default:W(e.target)}return n}function Y(e,n,t){for(const o of X(e))if(o.instanceId===n&&o.canvasId===t)return!0;return!1}function G(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingSource.kind: ${e.kind}`)}function W(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingTarget.kind: ${e.kind}`)}function Q(e){const n={type:e.type,canvas:{...e.canvas,width:{...e.canvas.width},height:{...e.canvas.height}}};return e.background&&(n.background={...e.background,...e.background.image?{image:{...e.background.image}}:{}}),e.behavior&&(n.behavior={...e.behavior}),e.guides&&(n.guides={...e.guides,...e.guides.items?{items:[...e.guides.items]}:{}}),e.rootLayout&&(n.rootLayout="grid"===(t=e.rootLayout).mode?{...t,columns:t.columns?t.columns.map(e=>({...e})):[],rows:t.rows?t.rows.map(e=>({...e})):[],...t.cells?{cells:{...t.cells}}:{},..."object"==typeof t.gap&&null!==t.gap?{gap:{...t.gap}}:{}}:"split"===t.mode?{...t,ratios:Array.isArray(t.ratios)?[...t.ratios]:[]}:{...t}),n;var t}function Z(e={}){return JSON.parse(JSON.stringify(e))}function ee(n={schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}){const t=v(h(n)),o=e.reactive({schemaVersion:"1",layout:Q(t.layout),instances:t.instances.map(e=>({...e,rect:{...e.rect}})),bindings:t.bindings.map(e=>c(e)),componentOverrides:Z(t.componentOverrides)});function i(e){return o.instances.findIndex(n=>n.instanceId===e)}function a(e){return o.bindings.findIndex(n=>n.id===e)}return{get document(){return o},instanceCount:e.computed(()=>o.instances.length),bindingCount:e.computed(()=>o.bindings.length),addInstance(e){if(i(e.instanceId)>=0)return void console.warn(`[hc-canvas/doc-store] instanceId "${e.instanceId}" 已存在,addInstance 忽略`);const n=e.rect?{...e.rect}:function(e){if(!e)return{x:0,y:0,w:0,h:0};const n=(e,n)=>"number"==typeof e&&Number.isFinite(e)?e:n;return{x:n(e.x,0),y:n(e.y,0),w:n(e.width,0),h:n(e.height,0)}}(e.layoutBox),t={...e,rect:n};!0===t.locked&&(void 0===t.lockPosition&&(t.lockPosition=!0),void 0===t.lockSize&&(t.lockSize=!0)),o.instances.push(t)},removeInstance(e){var n;const t=i(e);t<0||(o.instances.splice(t,1),null==(n=o.componentOverrides)||delete n[e],o.bindings=o.bindings.filter(n=>!Y(n,e)))},updateInstance(e,n){const t=o.instances.find(n=>n.instanceId===e);if(t&&(Object.assign(t,n),n.rect&&t.layoutBox&&(t.layoutBox={...t.layoutBox,x:t.rect.x,y:t.rect.y,..."px"===t.layoutBox.widthMode?{width:t.rect.w}:{},..."px"===t.layoutBox.heightMode?{height:t.rect.h}:{}}),n.layoutBox)){const e=t.layoutBox??n.layoutBox,o=e=>"number"==typeof e&&Number.isFinite(e);t.rect={x:o(e.x)?e.x:t.rect.x,y:o(e.y)?e.y:t.rect.y,w:"px"===e.widthMode&&o(e.width)?e.width:t.rect.w,h:"px"===e.heightMode&&o(e.height)?e.height:t.rect.h}}},moveInstance(e,n,t){const i=o.instances.find(n=>n.instanceId===e);i&&(i.rect.x=n,i.rect.y=t,i.layoutBox&&(i.layoutBox={...i.layoutBox,x:n,y:t}))},resizeInstance(e,n,t){const i=o.instances.find(n=>n.instanceId===e);if(!i)return;const a=Math.max(1,n),r=Math.max(1,t);i.rect.w=a,i.rect.h=r,i.layoutBox&&(i.layoutBox={...i.layoutBox,width:a,height:r,widthMode:"px",heightMode:"px"})},setInstanceProp(e,n,t){const i=o.instances.find(n=>n.instanceId===e);i&&(i.props={...i.props,[n]:t})},setInstanceLocked(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&(t.locked=n,n?(t.lockPosition=!0,t.lockSize=!0):(delete t.lockPosition,delete t.lockSize))},setInstanceSize(e,n){const t=o.instances.find(n=>n.instanceId===e);if(t)if(null===n)delete t.size,t.layoutBox&&(t.layoutBox={...t.layoutBox,width:t.rect.w,height:t.rect.h,widthMode:"px",heightMode:"px"});else if(t.size=n,t.layoutBox){const e=n.width,o=n.height,i={...t.layoutBox};e&&("px"===e.mode?(i.widthMode="px","number"==typeof e.value&&Number.isFinite(e.value)&&(i.width=e.value)):"percent"===e.mode?(i.widthMode="percent","number"==typeof e.value&&Number.isFinite(e.value)&&(i.width=e.value)):"fill"===e.mode?(i.widthMode="fill",Number.isFinite(i.width)||(i.width=t.rect.w)):"auto"!==e.mode&&"hug"!==e.mode||(i.widthMode="auto",Number.isFinite(i.width)||(i.width=t.rect.w))),o&&("px"===o.mode?(i.heightMode="px","number"==typeof o.value&&Number.isFinite(o.value)&&(i.height=o.value)):"percent"===o.mode?(i.heightMode="percent","number"==typeof o.value&&Number.isFinite(o.value)&&(i.height=o.value)):"fill"===o.mode?(i.heightMode="fill",Number.isFinite(i.height)||(i.height=t.rect.h)):"auto"!==o.mode&&"hug"!==o.mode||(i.heightMode="auto",Number.isFinite(i.height)||(i.height=t.rect.h))),t.layoutBox=i}},setInstanceContainerLayout(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&(null===n?delete t.containerLayout:t.containerLayout=n)},updateInstanceLayoutBox(e,n){const t=o.instances.find(n=>n.instanceId===e);if(!t)return;const i=t.layoutBox??{x:t.rect.x,y:t.rect.y,width:t.rect.w,height:t.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},a={},r=["x","y","width","height"];for(const e of r){const t=n[e];"number"==typeof t&&Number.isFinite(t)&&(a[e]=t)}if("px"!==n.widthMode&&"percent"!==n.widthMode&&"fill"!==n.widthMode&&"auto"!==n.widthMode||(a.widthMode=n.widthMode),"px"!==n.heightMode&&"percent"!==n.heightMode&&"fill"!==n.heightMode&&"auto"!==n.heightMode||(a.heightMode=n.heightMode),"hidden"!==n.overflow&&"visible"!==n.overflow&&"auto"!==n.overflow||(a.overflow=n.overflow),0===Object.keys(a).length)return;const c={...i,...a};t.layoutBox=c;const s=a.widthMode??i.widthMode,d=a.heightMode??i.heightMode;t.rect={x:c.x,y:c.y,w:"px"===s?c.width:t.rect.w,h:"px"===d?c.height:t.rect.h}},updateInstanceLayoutItem(e,n){const t=o.instances.find(n=>n.instanceId===e);if(!t)return;if(null===n)return void delete t.layoutItem;const i=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"],a={};for(const e of i){const t=n[e];"number"==typeof t&&Number.isFinite(t)&&(a[e]=t)}if(0===Object.keys(a).length)return;const r=t.layoutItem??{};t.layoutItem={...r,...a}},setInstanceRotation(e,n){const t=o.instances.find(n=>n.instanceId===e);t&&Number.isFinite(n)&&(0===n?delete t.rotation:t.rotation=n)},duplicateInstance(e,n,t){var i;const a=o.instances.find(n=>n.instanceId===e);if(!a)return;const r=JSON.parse(JSON.stringify(a));if(r.instanceId=n,r.rect={...r.rect,x:a.rect.x+t.x,y:a.rect.y+t.y},r.layoutBox&&(r.layoutBox={...r.layoutBox,x:r.layoutBox.x+t.x,y:r.layoutBox.y+t.y}),delete r.locked,delete r.lockPosition,delete r.lockSize,o.instances.some(e=>e.instanceId===n))return void console.warn(`[hc-canvas/doc-store] duplicateInstance: newInstanceId "${n}" 已存在,忽略`);o.instances.push(r);const c=null==(i=o.componentOverrides)?void 0:i[e];c&&(o.componentOverrides={...o.componentOverrides??{},[n]:{...JSON.parse(JSON.stringify(c)),instanceId:n}})},addBinding(e){if(a(e.id)>=0)return void console.warn(`[hc-canvas/doc-store] binding id "${e.id}" 已存在,addBinding 忽略`);const[n]=d([e]);n?o.bindings.push(c(n)):console.warn(`[hc-canvas/doc-store] addBinding "${null==e?void 0:e.id}" dropped by normalize`)},removeBinding(e){const n=a(e);n<0||o.bindings.splice(n,1)},updateBinding(e,n){const t=o.bindings.find(n=>n.id===e);if(!t)return;const i=c(n);Object.assign(t,i)},updateLayout(e){for(const n of Object.keys(e)){const t=e[n];void 0===t?delete o.layout[n]:o.layout[n]=t}},setComponentOverride(e,n){null!==n?(o.componentOverrides||(o.componentOverrides={}),o.componentOverrides[e]=n):o.componentOverrides&&e in o.componentOverrides&&delete o.componentOverrides[e]},replaceDocument(e){const n=v(h(e));o.schemaVersion="1",o.layout=Q(n.layout),o.instances=n.instances.map(e=>({...e,rect:{...e.rect}})),o.bindings=n.bindings.map(e=>c(e)),o.componentOverrides=Z(n.componentOverrides)},getInstance:e=>o.instances.find(n=>n.instanceId===e),listInstancesByComponentVersionKey:e=>o.instances.filter(n=>n.componentVersionKey===e)}}function ne(){const n=e.reactive({ids:[],freeSplit:null});return{selectedIds:e.computed(()=>n.ids),size:e.computed(()=>n.ids.length),primaryId:e.computed(()=>n.ids[0]),freeSplitSelection:e.computed(()=>n.freeSplit),select(e){n.ids=[e],n.freeSplit=null},toggleSelect(e){const t=n.ids.indexOf(e);t>=0?n.ids.splice(t,1):n.ids.push(e),n.freeSplit=null},addToSelection(e){n.freeSplit=null,n.ids.includes(e)||n.ids.push(e)},removeFromSelection(e){const t=n.ids.indexOf(e);t>=0&&n.ids.splice(t,1)},clearSelection(){n.ids=[],n.freeSplit=null},selectAll(e){n.ids=Array.from(new Set(e)),n.freeSplit=null},purgeOrphans(e){const t=new Set(e);n.ids=n.ids.filter(e=>t.has(e))},isSelected:e=>n.ids.includes(e),selectFreeSplitLeaf(e,t){n.freeSplit={kind:"freeSplitLeaf",containerId:e,leafId:t},n.ids=[]},selectFreeSplitDivider(e,t,o){n.freeSplit={kind:"freeSplitDivider",containerId:e,nodeId:t,dividerIndex:o},n.ids=[]},clearFreeSplitSelection(){n.freeSplit=null}}}function te(n={}){const{minScale:t=.25,maxScale:o=4,initialScale:i=1}=n,a=e.reactive({scale:i,panX:0,panY:0});function r(e){return Math.max(t,Math.min(o,e))}return{state:a,scale:e.computed(()=>a.scale),panX:e.computed(()=>a.panX),panY:e.computed(()=>a.panY),setScale(e){a.scale=r(e)},zoomAt(e,n){const t=a.scale,o=r(t+n);if(o===t)return;const i=o/t;a.panX=e.x-(e.x-a.panX)*i,a.panY=e.y-(e.y-a.panY)*i,a.scale=o},setPan(e,n){a.panX=e,a.panY=n},panBy(e,n){a.panX+=e,a.panY+=n},resetView(){a.scale=i,a.panX=0,a.panY=0},fitToScreen(e,n,t=40){const o=Math.max(1,n.w-2*t),i=Math.max(1,n.h-2*t),c=o/e.w,s=i/e.h,d=r(Math.min(c,s)),l=e.w*d,u=e.h*d;a.scale=d,a.panX=(n.w-l)/2,a.panY=(n.h-u)/2},toCanvasPoint:e=>({x:(e.x-a.panX)/a.scale,y:(e.y-a.panY)/a.scale}),toViewportPoint:e=>({x:e.x*a.scale+a.panX,y:e.y*a.scale+a.panY})}}function oe(e,n){if("leaf"===e.type)return e.leafId===n?e:null;for(const t of e.children){const e=oe(t,n);if(e)return e}return null}function ie(e,n){if("leaf"===e.type)return null;if(e.nodeId===n)return e;for(const t of e.children){const e=ie(t,n);if(e)return e}return null}function ae(e){return"leaf"===e.type?!0===e.locked:e.children.some(e=>ae(e))}function re(e){return"leaf"===e.type?[e]:e.children.flatMap(e=>re(e))}const ce=e=>({ok:!1,reason:e}),se=e=>({ok:!0,root:e});function de(e,n){return"leaf"===e.type?n(e):{...e,children:e.children.map(e=>de(e,n))}}function le(e,n){if("leaf"===e.type)return e.leafId===n?e:null;for(const t of e.children){const e=le(t,n);if(e)return e}return null}function ue(e,n){if("leaf"===e.type)return null;if(e.nodeId===n)return e;for(const t of e.children){const e=ue(t,n);if(e)return e}return null}function pe(e,n,t){const o=ue(e,n);if(!o)return ce(`resize: branch "${n}" not found`);if(t.length!==o.children.length)return ce(`resize: sizes arity ${t.length} !== children ${o.children.length}`);const i=t.findIndex(e=>function(e){if("object"!=typeof e||null===e)return!0;const{mode:n,value:t,min:o,max:i}=e,a=void 0!==o&&("number"!=typeof o||!Number.isFinite(o)||o<0)||void 0!==i&&("number"!=typeof i||!Number.isFinite(i)||i<0)||"number"==typeof o&&"number"==typeof i&&o>i;return"ratio"!==n&&"px"!==n||"number"!=typeof t||!Number.isFinite(t)||"ratio"===n&&t<=0||"px"===n&&t<0||a}(e));if(i>=0)return ce(`resize: sizes[${i}] invalid NodeSize`);const a=e=>"leaf"===e.type?e:e.nodeId===n?{...e,sizes:t.map(e=>({...e}))}:{...e,children:e.children.map(a)};return se(a(e))}function fe(e,n){return n?[{mode:"ratio",value:e},{mode:"ratio",value:1-e}]:[{mode:"ratio",value:1-e},{mode:"ratio",value:e}]}const ge=["freeSplitFill","freeSplitClear","freeSplitSwap","freeSplitResize","freeSplitSplit","freeSplitMerge"];function he(e){return ge.includes(e.type)}function me(e,n,t){const o=n.root,{containerId:i}=e.payload;switch(e.type){case"freeSplitFill":{const{leafId:n,instance:a}=e.payload,r=oe(o,n);if(!r||null!==r.instanceId)return null;if(t.some(e=>e.instanceId===a.instanceId))return null;const c=function(e,n,t){return le(e,n)?se(de(e,e=>e.leafId===n?{...e,instanceId:t}:e)):ce(`fill: leaf "${n}" not found`)}(o,n,a.instanceId);if(!c.ok)return null;const s={...a,parentId:i,slot:"default",placement:"container"};return{containerId:i,nextRoot:c.root,addInstance:s}}case"freeSplitClear":{const{leafId:n}=e.payload,a=oe(o,n);if(!a||null===a.instanceId)return null;if(!t.some(e=>e.instanceId===a.instanceId))return null;const r=function(e,n){return le(e,n)?se(de(e,e=>e.leafId===n?{...e,instanceId:null}:e)):ce(`clear: leaf "${n}" not found`)}(o,n);if(!r.ok)return null;const c=function(e,n){const t=[n],o=[n];for(;o.length>0;){const n=o.shift();for(const i of e)i.parentId===n&&(t.push(i.instanceId),o.push(i.instanceId))}return t}(t,a.instanceId);return{containerId:i,nextRoot:r.root,removeInstanceIds:c}}case"freeSplitSwap":{const n=function(e,n,t){if(n===t)return ce("swap: same leaf");const o=le(e,n),i=le(e,t);if(!o)return ce(`swap: leaf "${n}" not found`);if(!i)return ce(`swap: leaf "${t}" not found`);const a=o.instanceId,r=i.instanceId;return se(de(e,e=>e.leafId===n?{...e,instanceId:r}:e.leafId===t?{...e,instanceId:a}:e))}(o,e.payload.leafIdA,e.payload.leafIdB);return n.ok?{containerId:i,nextRoot:n.root}:null}case"freeSplitResize":{const n=pe(o,e.payload.nodeId,e.payload.sizes);return n.ok?{containerId:i,nextRoot:n.root}:null}case"freeSplitSplit":{const{leafId:n,edge:t,newLeafShare:a,newLeafId:r,newNodeId:c}=e.payload,s=function(e,n,t,o,i,a){if(!(o>0&&o<1))return ce(`split: newLeafShare ${o} not in (0,1)`);if(i===a)return ce("split: newLeafId === newNodeId");const r=function(e){const n=new Set,t=e=>{"leaf"===e.type?n.add(e.leafId):(n.add(e.nodeId),e.children.forEach(t))};return t(e),n}(e);if(r.has(i))return ce(`split: newLeafId "${i}" already exists`);if(r.has(a))return ce(`split: newNodeId "${a}" already exists`);if(!le(e,n))return ce(`split: leaf "${n}" not found`);const c=function(e){return"left"===e||"right"===e?"row":"col"}(t),s=function(e){return"left"===e||"top"===e}(t),d={type:"leaf",leafId:i,instanceId:null},l=e=>s?[d,e]:[e,d];if("leaf"===e.type)return se({type:"split",nodeId:a,dir:c,children:l(e),sizes:fe(o,s)});const u=e=>{if("leaf"===e.type)return e;const t=e.children.findIndex(e=>"leaf"===e.type&&e.leafId===n);if(t>=0){const n=e.children[t];if(e.dir===c){const[i,a]=function(e,n,t){const o=e.value*n,i=e.value*(1-n),a=n=>({mode:e.mode,value:n}),r=n=>({mode:e.mode,value:n,...void 0!==e.min?{min:e.min}:{},...void 0!==e.max?{max:e.max}:{}});return t?[a(o),r(i)]:[r(i),a(o)]}(e.sizes[t],o,s),r=[...e.children.slice(0,t),...l(n),...e.children.slice(t+1)],c=[...e.sizes.slice(0,t),i,a,...e.sizes.slice(t+1)];return{...e,children:r,sizes:c}}const i={type:"split",nodeId:a,dir:c,children:l(n),sizes:fe(o,s)},r=[...e.children];return r[t]=i,{...e,children:r}}return{...e,children:e.children.map(u)}};return se(u(e))}(o,n,t,a,r,c);return s.ok?{containerId:i,nextRoot:s.root}:null}case"freeSplitMerge":{const{leafId:n}=e.payload,t=oe(o,n);if(!t||null!==t.instanceId)return null;const a=function(e,n){if("leaf"===e.type)return ce("merge: root leaf has no parent");let t=!1;const o=e=>{if("leaf"===e.type)return e;const i=e.children.findIndex(e=>"leaf"===e.type&&e.leafId===n);if(i>=0){t=!0;const n=i-1>=0?i-1:i+1,o=e.sizes[i],c=e.children.filter((e,n)=>n!==i),s=e.sizes.filter((e,n)=>n!==i),d=n<i?n:n-1;return s[d]=(r=o,(a=s[d]).mode===r.mode?{...a,value:a.value+r.value}:a),1===c.length?c[0]:{...e,children:c,sizes:s}}var a,r;return{...e,children:e.children.map(o)}},i=o(e);return t?se(i):ce(`merge: leaf "${n}" not found as a branch child`)}(o,n);return a.ok?{containerId:i,nextRoot:a.root}:null}}}function ve(e,n){if(!0===e.structureLocked)return!1;if("split"===n.op||"merge"===n.op){const t=oe(e.root,n.leafId);if(!t)return!1;if(!0===t.locked)return!1}return!0}function ye(e){return!0!==e.structureLocked&&!ae(e.root)}const Ie=new WeakMap;function xe(e){const n=new Map;return{resolve(t){const o=function(e){return e.id||e.url||""}(t);if(o&&n.has(o))return n.get(o);if(!e){const e=t.url??"";return o&&n.set(o,e),e}const i=e.resolve(t);return"string"==typeof i?(o&&n.set(o,i),i):(o&&n.set(o,i),i.then(e=>{o&&n.set(o,e)},e=>{console.warn(`[hc-canvas/assets] resolve("${o}") 失败,缓存里删条目允许重试:`,e),o&&n.delete(o)}),i)},__clearCache(){n.clear()}}}function we(e,n,t){if(!n||0===Object.keys(n).length)return`${e}::{}`;const o=be(n,t);return null===o?`${e}::__fresh_${Date.now()}_${Math.random().toString(36).slice(2,8)}__`:`${e}::${o}`}function be(e,n,t=new WeakSet){if(null==e)return JSON.stringify(e);const o=typeof e;if("string"===o||"number"===o||"boolean"===o)return JSON.stringify(e);if("function"===o||"symbol"===o||"bigint"===o)return null==n||n(),null;if(Array.isArray(e)){if(t.has(e))return null==n||n(),null;t.add(e);const o=[];for(const i of e){const e=be(i,n,t);if(null===e)return null;o.push(e)}return`[${o.join(",")}]`}if("object"===o){const o=Object.getPrototypeOf(e);if(o!==Object.prototype&&null!==o)return null==n||n(),null;const i=e;if(t.has(i))return null==n||n(),null;t.add(i);const a=Object.keys(i).sort(),r=[];for(const e of a){const o=be(i[e],n,t);if(null===o)return null;r.push(`${JSON.stringify(e)}:${o}`)}return`{${r.join(",")}}`}return null==n||n(),null}function Se(e){const n=new Map,t=new Map,o=new Map,i=new Map,a=new Map,r=new Map;let c=!1,s=!1,d=0,l=null;function u(e){if(!s&&null!==l)try{l(e)}catch(e){console.error("[hc-canvas/dataStore] trace bridge listener threw",e)}}function p(e,n){var t;const a=o.get(e);if(a)for(const e of a)null==(t=i.get(e))||t.onUpdate(n)}function f(e,t){let o=n.get(e);return o||(o={cacheKey:e,sourceId:t,status:"idle"},n.set(e,o)),o}function g(t,r,c){if(!e)return;const l=a.get(t);l&&l.abort();const g=new AbortController;a.set(t,g);const h=f(t,r);h.status="loading";const m=h.writeSeq??0;Promise.resolve().then(()=>async function(e,n){return{value:await Promise.resolve(e.query(n))}}(e,{sourceId:r,params:c,signal:g.signal})).then(e=>{if(s)return;if(a.get(t)!==g)return;a.delete(t);const o=n.get(t);o&&((o.writeSeq??0)>m?u({kind:"data-query-skipped",cacheKey:t,sourceId:r,writeSeq:o.writeSeq,reason:"race-stale"}):(o.status="success",o.value=e.value,o.error=void 0,o.lastFetchedAt=Date.now(),o.writeSeq=++d,u({kind:"data-source-update",cacheKey:t,sourceId:r,writeSeq:o.writeSeq,value:e.value}),p(t,e.value)))}).catch(e=>{if(s)return;if(function(e){return null!==e&&"object"==typeof e&&"AbortError"===e.name}(e))return;if(a.get(t)!==g)return;a.delete(t);const c=n.get(t);c&&((c.writeSeq??0)>m?u({kind:"data-query-skipped",cacheKey:t,sourceId:r,writeSeq:c.writeSeq,reason:"race-stale-reject"}):(c.status="error",c.error=e,c.lastFetchedAt=Date.now(),function(e,n){var t,a;const r=o.get(e);if(r)for(const e of r)null==(a=null==(t=i.get(e))?void 0:t.onError)||a.call(t,n)}(t,e)))})}function h(e){if(s)return;const{bindingId:d,sourceId:l,params:u,onUpdate:p,onError:f}=e,h=we(l,u,()=>{c||(console.warn(`[hc-canvas/dataStore] params for "${l}" contains non-plain values; fresh query every call (no cache)`),c=!0)});!function(e,i){const c=t.get(e);if(c===i)return;if(c){const t=o.get(c);if(t&&(t.delete(e),0===t.size)){o.delete(c);const e=a.get(c);e&&(e.abort(),a.delete(c)),n.delete(c)}const i=r.get(e);if(i){try{i()}catch{}r.delete(e)}}t.set(e,i);let s=o.get(i);s||(s=new Set,o.set(i,s)),s.add(e)}(d,h),i.set(d,{onUpdate:p,onError:f});const m=n.get(h);if(m){if("success"===m.status)return void p(m.value);if("error"===m.status)return void(null==f||f(m.error));if("loading"===m.status)return}g(h,l,u)}return{request:h,subscribe:function(n){if(s)return;const{bindingId:o,sourceId:i,params:a,onUpdate:c,onError:l}=n;if(h({bindingId:o,sourceId:i,params:a,onUpdate:c,onError:l}),!e)return;const g=t.get(o);if(!g)return;let m=!0;try{const n=function(e,n){if(e.subscribe)return e.subscribe(n,e=>{if(s)return;if(!m)return;if(t.get(o)!==g)return;const n=f(g,i);n.status="success",n.value=e,n.lastFetchedAt=Date.now(),n.writeSeq=++d,u({kind:"data-source-update",cacheKey:g,sourceId:i,writeSeq:n.writeSeq,value:e}),p(g,e)})}(e,{sourceId:i,params:a});n?r.set(o,()=>{m=!1;try{n()}catch{}}):r.set(o,()=>{m=!1})}catch(e){m=!1,s||null==l||l(e)}},removeBinding:function(e,c){if(s)return;const d=!0===(null==c?void 0:c.preserveCache),l=r.get(e);if(l){try{l()}catch{}r.delete(e)}i.delete(e);const u=function(e){const n=t.get(e);if(!n)return;t.delete(e);const i=o.get(n);return i&&(i.delete(e),0===i.size&&o.delete(n)),n}(e);if(u&&!o.has(u)){const e=n.get(u);if(!d||"success"!==(null==e?void 0:e.status)){const e=a.get(u);e&&(e.abort(),a.delete(u)),n.delete(u)}}},invalidate:function(e){if(s)return;const t=[];for(const[o,i]of n)void 0!==e&&i.sourceId!==e||t.push(o);for(const e of t){const t=n.get(e);if(!t)continue;const i=o.get(e);if(!i||0===i.size){n.delete(e);const t=a.get(e);t&&(t.abort(),a.delete(e));continue}t.status="stale",g(e,t.sourceId,void 0)}},getSnapshot:function(){return{entries:Array.from(n.values()).map(e=>({cacheKey:e.cacheKey,sourceId:e.sourceId,status:e.status,value:e.value,error:e.error,lastFetchedAt:e.lastFetchedAt}))}},getCachedBySourceId:function(e,t){if(s)return;const o=we(e,t,()=>{c||(console.warn(`[hc-canvas/dataStore] params for "${e}" contains non-plain values; cannot compute stable cache key, cache lookup will miss`),c=!0)}),i=n.get(o);return i?{value:i.value,status:i.status}:void 0},disposeAll:function(){if(!s){s=!0;for(const e of a.values())try{e.abort()}catch{}a.clear();for(const e of r.values())try{e()}catch{}r.clear(),n.clear(),t.clear(),o.clear(),i.clear(),l=null}},attachTraceBridge:function(e){return s?()=>{}:(l=e,()=>{l===e&&(l=null)})},getBindingsForCacheKey:function(e){const n=o.get(e);return n?Array.from(n):[]},get isDisposed(){return s}}}const ke=Symbol("hc:canvas:context");function Be(t={}){var o,i;const a=t.canvasId??n.DEFAULT_CANVAS_ID,r=ee(t.initialDocument),s=ne(),d=te(t.viewport),l=H(t.scheduler),u=Se(null==(o=t.adapters)?void 0:o.data);let p=!1;const f=function(){const n=new WeakSet;return{mint(t){const o=e.markRaw({type:"freeSplitRestore",payload:t});return n.add(o),o},isMarked:e=>"object"==typeof e&&null!==e&&n.has(e)&&"freeSplitRestore"===e.type}}(),g=e.computed(()=>{const e=t.freeSplitEnabled;return("function"==typeof e?e():e)??!1}),h=[];t.hooks&&h.push(t.hooks);const m=e.ref(!1),v=e.computed(()=>m.value),y=e.ref({}),I=e.computed(()=>y.value),x=e.computed(()=>{var e;const n=(null==(e=t.getMode)?void 0:e.call(t))??"design",o=function(e){switch(e){case"design":return{selectable:!0,draggable:!0,resizable:!0,keyboardMove:!0,snap:!0,grid:!1,allowOverflow:!0,locked:!1};case"preview":case"runtime":return{selectable:!1,draggable:!1,resizable:!1,keyboardMove:!1,snap:!0,grid:!1,allowOverflow:!0,locked:!1};case"inspect":return{selectable:!0,draggable:!1,resizable:!1,keyboardMove:!1,snap:!0,grid:!1,allowOverflow:!0,locked:!1}}}(n),i=r.document.layout.behavior??{};if("design"!==n){const{selectable:e,draggable:n,resizable:t,keyboardMove:a,...r}=i;return{...o,...r,...y.value}}return{...o,...i,...y.value}}),w=xe(null==(i=t.adapters)?void 0:i.assets),S=e.ref("select"),k=e.ref(null),z=e.computed(()=>k.value??S.value),M=e.ref(null),T=e.computed(()=>M.value),L=e.ref(null),E=e.ref({w:0,h:0}),D=e.computed(()=>E.value),P=e.computed(()=>{const e=r.document.layout,n=E.value;return{w:C(e.canvas.width,n.w,1920),h:C(e.canvas.height,n.h,1080)}}),R=e.ref([]),$=e.computed(()=>R.value),O=e.ref(0),F=e.computed(()=>O.value>0);function A(e){if(!e)return null;const n=r.getInstance(e),t=null==n?void 0:n.containerLayout;return t&&"free-split"===t.mode?t:null}function N(){const e=s.freeSplitSelection.value;if(!e)return;const n=A(e.containerId);if(!n)return void s.clearFreeSplitSelection();if("freeSplitLeaf"===e.kind)return void(oe(n.root,e.leafId)||s.clearFreeSplitSelection());const t=ie(n.root,e.nodeId);(!t||e.dividerIndex<0||e.dividerIndex>=t.children.length-1)&&s.clearFreeSplitSelection()}const j={canvasId:a,document:r,selection:s,viewport:d,scheduler:l,adapters:t.adapters??{},dataStore:u,dispatch:function(e){var n,t;if(p)return void console.warn("[hc-canvas/context] dispatch called after dispose()");if("freeSplitRestore"===e.type)return void(f.isMarked(e)?function(e){const{containerId:n,containerLayout:t,addInstances:o,addBindings:i,removeInstanceIds:a}=e.payload;if(r.setInstanceContainerLayout(n,c(t)),o)for(const e of o)r.addInstance(c(e));if(i)for(const e of i)r.addBinding(c(e));if(a)for(const e of a)r.removeInstance(e),s.removeFromSelection(e)}(e):console.warn("[hypercard] freeSplitRestore 未经内部铸造(疑似伪造),已拒绝。"));const o=function(e){var n;if(he(e)){if(!g.value)return console.warn("[hypercard] free-split 布局未启用(本 canvas gate 关),free-split action 已忽略。"),null;const n=A(e.payload.containerId);if(!n)return null;if("freeSplitSplit"===e.type){if(!ve(n,{op:"split",leafId:e.payload.leafId}))return console.warn("[hypercard] free-split split 被锁(structureLocked / leaf.locked),已忽略。"),null}else if("freeSplitMerge"===e.type){if(!ve(n,{op:"merge",leafId:e.payload.leafId}))return console.warn("[hypercard] free-split merge 被锁(structureLocked / leaf.locked),已忽略。"),null;const t=oe(n.root,e.payload.leafId);if(t&&null!==t.instanceId)return console.warn("[hypercard] free-split merge 仅支持空叶(先 clear 内容),已忽略。"),null}else if("freeSplitResize"===e.type&&!ve(n,{op:"resize"}))return console.warn("[hypercard] free-split resize 被锁(structureLocked),已忽略。"),null;return e}if("removeInstance"===e.type){const n=r.getInstance(e.payload.instanceId),t=A(null==n?void 0:n.parentId);if(n&&t){const e=re(t.root).find(e=>e.instanceId===n.instanceId);if(e)return{type:"freeSplitClear",payload:{containerId:n.parentId,leafId:e.leafId}}}}if("addInstance"===e.type){const t=e.payload.instance;if(A(t.parentId??(null==(n=t.slotPlacement)?void 0:n.parentInstanceId)))return console.warn("[hypercard] free-split 容器子实例必须通过 freeSplitFill 创建(含 slotPlacement 入口),addInstance 已拒绝。"),null}if("duplicateInstance"===e.type){const n=r.getInstance(e.payload.instanceId);if(n){if(A(n.instanceId))return console.warn("[hypercard] free-split 容器不支持浅复制(树/flat 会不一致),已拒绝。"),null;if(A(n.parentId))return console.warn("[hypercard] free-split 容器子实例不支持复制(首版),已拒绝。"),null}}if("updateInstance"===e.type&&e.payload.patch){const n=e.payload.patch;if("parentId"in n){const e=n.parentId;if(e&&A(e))return console.warn("[hypercard] 不能 reparent 进 free-split 容器(请用 freeSplitFill),已拒绝。"),null}const t=n.slotPlacement;if((null==t?void 0:t.parentInstanceId)&&A(t.parentInstanceId))return console.warn("[hypercard] 不能用 slotPlacement 把实例挂进 free-split 容器(请用 freeSplitFill),已拒绝。"),null;if(["parentId","slot","placement","slotPlacement"].some(e=>e in n)){const n=r.getInstance(e.payload.instanceId);if(n&&A(n.parentId))return console.warn("[hypercard] 不能用 updateInstance 改 free-split 子实例的归属(parentId/slot/placement/slotPlacement);请用 freeSplitClear/freeSplitFill,已拒绝。"),null}}if("setRootLayout"===e.type&&null!==e.payload.rootLayout&&"free-split"===e.payload.rootLayout.mode)return console.warn("[hypercard] setRootLayout: rootLayout 不支持 free-split(仅容器实例),已忽略。"),null;if("setContainerLayout"===e.type){const n=A(e.payload.instanceId);if(n&&!ye(n))return console.warn("[hypercard] free-split 容器被锁(structureLocked / leaf.locked),不能整树替换 containerLayout,已忽略。"),null;if(null!==e.payload.containerLayout&&"free-split"===e.payload.containerLayout.mode&&!g.value)return console.warn("[hypercard] free-split 布局未启用(本 canvas gate 关),setContainerLayout 已忽略。"),null}if("updateLayout"===e.type&&e.payload.patch.rootLayout&&"free-split"===e.payload.patch.rootLayout.mode){console.warn("[hypercard] updateLayout: rootLayout 不支持 free-split(仅容器实例),已剥除该字段。");const{rootLayout:n,...t}=e.payload.patch;return 0===Object.keys(t).length?null:{type:"updateLayout",payload:{patch:t}}}return e}(e);if(null!==o){for(const e of h)if(!1===(null==(n=e.onBeforeAction)?void 0:n.call(e,o)))return;switch(o.type){case"addInstance":r.addInstance(o.payload.instance);break;case"removeInstance":r.removeInstance(o.payload.instanceId),s.removeFromSelection(o.payload.instanceId),N();break;case"updateInstance":r.updateInstance(o.payload.instanceId,o.payload.patch);break;case"moveInstance":r.moveInstance(o.payload.instanceId,o.payload.x,o.payload.y);break;case"resizeInstance":r.resizeInstance(o.payload.instanceId,o.payload.w,o.payload.h);break;case"setInstanceProp":r.setInstanceProp(o.payload.instanceId,o.payload.key,o.payload.value);break;case"addBinding":r.addBinding(o.payload.binding);break;case"removeBinding":r.removeBinding(o.payload.bindingId);break;case"updateBinding":r.updateBinding(o.payload.bindingId,o.payload.patch);break;case"updateLayout":r.updateLayout(o.payload.patch);break;case"setRootLayout":{const{rootLayout:e}=o.payload;r.updateLayout({rootLayout:null===e?void 0:e});break}case"replaceDocument":r.replaceDocument(o.payload.document),s.purgeOrphans(r.document.instances.map(e=>e.instanceId)),N();break;case"setComponentOverride":{const{instanceId:e,override:n}=o.payload;if(void 0===r.getInstance(e)){console.warn(`[hc-canvas/context] setComponentOverride: instance "${e}" 不存在,no-op`);break}r.setComponentOverride(e,n);break}case"setInstanceLocked":r.setInstanceLocked(o.payload.instanceId,o.payload.locked);break;case"duplicateInstance":r.duplicateInstance(o.payload.instanceId,o.payload.newInstanceId,o.payload.offset??{x:20,y:20});break;case"setInstanceSize":{const{instanceId:e,size:n}=o.payload;if(null===n)r.setInstanceSize(e,null);else{const t=b(void 0,n);r.setInstanceSize(e,t??null)}break}case"setContainerLayout":{const{instanceId:e,containerLayout:n}=o.payload;if(null===n)r.setInstanceContainerLayout(e,null);else{const t=B(n);null!==t&&r.setInstanceContainerLayout(e,t)}N();break}case"updateLayoutBox":r.updateInstanceLayoutBox(o.payload.instanceId,o.payload.patch);break;case"updateLayoutItem":r.updateInstanceLayoutItem(o.payload.instanceId,o.payload.patch);break;case"updateRotation":r.setInstanceRotation(o.payload.instanceId,o.payload.value);break;case"select":s.select(o.payload.instanceId);break;case"toggleSelect":s.toggleSelect(o.payload.instanceId);break;case"addToSelection":s.addToSelection(o.payload.instanceId);break;case"removeFromSelection":s.removeFromSelection(o.payload.instanceId);break;case"clearSelection":s.clearSelection();break;case"selectAll":s.selectAll(o.payload.instanceIds);break;case"freeSplitFill":case"freeSplitClear":case"freeSplitSwap":case"freeSplitResize":case"freeSplitSplit":case"freeSplitMerge":!function(e){const n=A(e.payload.containerId);if(!n)return;const t=me(e,n,r.document.instances);if(!t)return;const o=c({...n,root:t.nextRoot});if(r.setInstanceContainerLayout(e.payload.containerId,o),t.addInstance&&r.addInstance(c(t.addInstance)),t.removeInstanceIds)for(const e of t.removeInstanceIds)r.removeInstance(e),s.removeFromSelection(e)}(o);break;default:{const e=o;console.warn("[hc-canvas/context] unknown action",e)}}for(const e of h)null==(t=e.onAfterAction)||t.call(e,o)}},dispose:function(){p||(p=!0,m.value=!1,l.dispose(),u.disposeAll())},isBatching:v,beginBatch:function(){p||m.value||(m.value=!0)},endBatch:function(e){var n;if(!p&&m.value){for(const t of h)null==(n=t.onAfterBatch)||n.call(t,e);m.value=!1}},registerHooks:function(e){return h.push(e),()=>{const n=h.indexOf(e);n>=0&&h.splice(n,1)}},isRecordingSuppressed:F,suppressRecording:function(e){O.value++;try{return e()}finally{O.value--}},freeSplitEnabled:g,effectiveBehavior:x,interactionOptions:I,setInteractionOptions:function(e){const n={...y.value};for(const t of Object.keys(e)){const o=e[t];void 0===o?delete n[t]:n[t]=o}y.value=n},resolveAsset:function(e){return w.resolve(e)},toolMode:z,setToolMode:function(e){S.value=e},setTemporaryToolMode:function(e){k.value=e},mouseCanvasPoint:T,setMouseCanvasPoint:function(e){M.value=e},measuredStageSize:D,measuredCanvasSize:P,setMeasuredStageSize:function(e){const n=Math.max(0,Math.round(e.w)),t=Math.max(0,Math.round(e.h));E.value.w===n&&E.value.h===t||(E.value={w:n,h:t})},layoutIssues:$,setLayoutIssues:function(e){R.value=e},cannotDragLayoutManagedChildEvent:e.readonly(L),setCannotDragLayoutManagedChildEvent:function(e){L.value=e}};return function(e,n){Ie.set(e,n)}(j,{computeInverse:e=>function(e,n,t){const o=n.document,{containerId:i}=e.payload,a=o.getInstance(i),r=null==a?void 0:a.containerLayout;if(!r||"free-split"!==r.mode)return null;const s=r,d=me(e,s,o.document.instances);if(!d)return null;const l={containerId:i,containerLayout:c(s)};if(d.removeInstanceIds&&d.removeInstanceIds.length>0){const e=d.removeInstanceIds;l.addInstances=e.map(e=>o.getInstance(e)).filter(e=>void 0!==e).map(e=>c(e));const n=o.document.bindings.filter(n=>e.some(e=>Y(n,e))).map(e=>c(e));n.length>0&&(l.addBindings=n)}return d.addInstance&&(l.removeInstanceIds=[d.addInstance.instanceId]),t.mint(l)}(e,j,f)}),j}function ze(n){e.provide(ke,n)}function Me(){const n=e.inject(ke);if(!n)throw new Error("[hc-canvas] useCanvasContext() called outside <CanvasProvider> / <HyperCardCanvasDesigner>. Make sure the component tree is wrapped by a provider.");return n}const Te="default";function Ce(e){return e.slot??Te}function Le(e,n){const t=[],o=n.resolveContract,i=n.maxDepth??8,a=new Map;for(const n of e.instances)a.set(n.instanceId,n);for(const n of e.instances){if(void 0===n.parentId&&void 0!==n.slot&&n.slot!==Te){Ee(t,"orphan-slot",n.instanceId,`slot "${n.slot}" 没有 parentId,数据不完整`);continue}if(void 0===n.parentId)continue;if(!a.has(n.parentId)){Ee(t,"missing-parent",n.instanceId,`parentId "${n.parentId}" 指向不存在的实例`);continue}"absolute"!==n.placement&&"canvas"!==n.placement||Ee(t,"absolute-child-rejected",n.instanceId,"parentId + placement='absolute'|'canvas' 在 D4.5f MVP 不支持,只允许 root absolute/canvas 或 child slot/container");const e=a.get(n.parentId),i=o(e.componentVersionKey);if(!i)continue;const r=i.slotsDecl??[];if(0===r.length){Ee(t,"parent-not-layout",n.instanceId,`父组件 "${e.componentId}" 不是布局组件(slotsDecl 为空)`);continue}const c=Ce(n),s=De(r,c);s?s.accepts&&s.accepts.length>0&&(s.accepts.includes(n.componentId)||Ee(t,"slot-not-allowed-component",n.instanceId,`slot "${c}" 不允许 componentId "${n.componentId}"(accepts: ${s.accepts.join(", ")})`)):Ee(t,"invalid-slot",n.instanceId,`slot "${c}" 不在父 "${e.componentId}" 的 slotsDecl 中(可能组件升级删除了该 slot)`)}const r=new Map;for(const n of e.instances){if(void 0===n.parentId)continue;const e=Ce(n),t=`${n.parentId}::${e}`;let o=r.get(t);o||(o=[],r.set(t,o)),o.push(n)}for(const[e,n]of r){if(n.length<=1)continue;const[i,r]=Pe(e),c=a.get(i);if(!c)continue;const s=o(c.componentVersionKey);if(!s)continue;const d=De(s.slotsDecl??[],r);if(d&&!0!==d.multiple)for(let e=1;e<n.length;e++)Ee(t,"slot-multiple-violated",n[e].instanceId,`slot "${r}" 不允许多个子实例(SlotDecl.multiple !== true)`)}const c=new Map;for(const n of e.instances)c.set(n.instanceId,0);for(const n of e.instances)0===c.get(n.instanceId)&&s(n.instanceId,[],0);function s(e,n,o){c.set(e,1);const r=a.get(e);if(o>i)return Ee(t,"depth-exceeded",e,`嵌套深度 ${o} 超过上限 ${i}`),void c.set(e,2);const d=r.parentId;if(void 0===d)return void c.set(e,2);if(!a.has(d))return void c.set(e,2);const l=c.get(d);if(1===l)return Ee(t,"cycle",e,`parentId 链成环:${[...n,e,d].join(" → ")}`),void c.set(e,2);2!==l?(s(d,[...n,e],o+1),c.set(e,2)):c.set(e,2)}return t}function Ee(e,n,t,o){e.push({kind:n,instanceId:t,detail:o})}function De(e,n){return e.find(e=>e.name===n)}function Pe(e){const n=e.indexOf("::");return[e.slice(0,n),e.slice(n+2)]}const Re=["data-hc-leaf","data-hc-leaf-container"],$e=e.defineComponent({name:"SplitTreeRenderer",__name:"SplitTreeRenderer",props:{containerId:{},node:{},register:{type:Function},unregister:{type:Function},gap:{}},setup(n){const t=n,o=e.computed(()=>"leaf"===t.node.type?t.node:null),i=e.computed(()=>"split"===t.node.type?t.node:null);function a(e){const n=o.value;n&&(e instanceof HTMLElement?t.register(t.containerId,n.leafId,e):t.unregister(t.containerId,n.leafId))}function r(e){return e?"px"===e.mode?`${e.value}px`:`minmax(0, ${e.value}fr)`:"minmax(0, 1fr)"}function c(e){return"leaf"===e.type?e.leafId:e.nodeId}const s=e.computed(()=>{const e=i.value;if(!e)return{};const n=[];for(let t=0;t<e.children.length;t++)n.push(r(e.sizes[t]));const o=n.join(" ")||"minmax(0, 1fr)",a={display:"grid",width:"100%",height:"100%",boxSizing:"border-box"};return"row"===e.dir?(a.gridTemplateColumns=o,a.gridTemplateRows="100%"):(a.gridTemplateRows=o,a.gridTemplateColumns="100%"),t.gap&&t.gap>0&&(a.gap=`${t.gap}px`),a});return(t,r)=>{const d=e.resolveComponent("SplitTreeRenderer",!0);return o.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref:a,"data-hc-leaf":o.value.leafId,"data-hc-leaf-container":n.containerId,class:"hc-fs-leaf",style:{width:"100%",height:"100%","box-sizing":"border-box"}},null,8,Re)):i.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-fs-branch",style:e.normalizeStyle(s.value)},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value.children,t=>(e.openBlock(),e.createBlock(d,{key:c(t),"container-id":n.containerId,node:t,register:n.register,unregister:n.unregister,gap:n.gap},null,8,["container-id","node","register","unregister","gap"]))),128))],4)):e.createCommentVNode("",!0)}}}),Oe={containers:new Map};function Fe(e){return"object"==typeof e&&null!==e}function Ae(e){if(!Fe(e))return!0;const{mode:n,value:t,min:o,max:i}=e,a=void 0!==o&&("number"!=typeof o||!Number.isFinite(o)||o<0)||void 0!==i&&("number"!=typeof i||!Number.isFinite(i)||i<0)||"number"==typeof o&&"number"==typeof i&&o>i;return"ratio"!==n&&"px"!==n||"number"!=typeof t||!Number.isFinite(t)||"ratio"===n&&t<=0||"px"===n&&t<0||a}function Ne(e){if(!Fe(e))return{ok:!1,reason:"empty-root"};const n=new Set,t=new Set,o=new Map;let i=null;const a=(e,r)=>{if(i)return;if(r>8)return void(i="depth-exceeded");if(!Fe(e))return void(i="empty-root");const c=e.type;if("leaf"===c){const{leafId:a,instanceId:r}=e;if("string"!=typeof a)return void(i="empty-root");if(null!=r&&"string"!=typeof r)return void(i="empty-root");if(n.has(a))return void(i="duplicate-id");if(n.add(a),"string"==typeof r){if(t.has(r))return void(i="duplicate-instance");t.add(r),o.set(r,a)}return}if("split"===c){const{nodeId:t,dir:o,children:c,sizes:s}=e;if("string"!=typeof t)return void(i="empty-root");if("row"!==o&&"col"!==o)return void(i="empty-root");if(!Array.isArray(c)||!Array.isArray(s))return void(i="empty-root");if(n.has(t))return void(i="duplicate-id");n.add(t);for(const e of s)if(Ae(e))return void(i="bad-size");for(const e of c)a(e,r+1);return}i="empty-root"};return a(e,1),i?{ok:!1,reason:i}:{ok:!0,instanceToLeaf:o}}function je(e,n,t){const o=(null==e?void 0:e.onError)??"log";switch(o){case"stop":return"stop";case"log":return console.error(`[hc-canvas/wirePageBindings] binding "${t}" threw:`,n),"continue";case"continue":return"continue";default:return console.error(`[hc-canvas/wirePageBindings] binding "${t}" threw (unknown onError="${String(o)}"):`,n),"continue"}}function Ve(e,n){return e&&"passthrough"!==e.kind?"static"===e.kind?function(e){if("function"==typeof structuredClone)try{return structuredClone(e)}catch{}try{return JSON.parse(JSON.stringify(e))}catch{return[...e]}}(e.args):"pickPath"===e.kind?function(e,n){const t=[];let o;for(const i of e){const e=qe(n,i.from);void 0===i.to?t.push(e):"number"==typeof i.to?(_e(t,i.to+1),t[i.to]=e):(o||(t.length>0&&"object"==typeof t[0]&&null!==t[0]&&!Array.isArray(t[0])?o=t[0]:(o={},0===t.length?t.push(o):t[0]=o)),o[i.to]=e)}return t}(e.paths,n):[n]:[n]}function qe(e,n){if(""===n)return e;const t=n.split(".");let o=e;for(const e of t){if(null==o)return;if("object"!=typeof o)return;o=o[e]}return o}function _e(e,n){for(;e.length<n;)e.push(void 0)}function Ke(e,n,t,o){e.debouncePendingTimer=null;const i=e.debounceDirty,a=e.debouncePendingChainId,r=e.debouncePendingPayload;e.debouncePendingChainId=null,e.debouncePendingPayload=void 0,e.debounceDirty=!1,t&&i&&null!==a&&Ue(n,e).pass&&o(r,a)}function Je(e,n,t){e.throttleTrailingTimer=null;const o=e.throttleTrailingPendingChainId,i=e.throttleTrailingPendingPayload;e.throttleTrailingPendingChainId=null,e.throttleTrailingPendingPayload=void 0,e.throttleWindowStartTs=null,null!==o&&(n.once&&e.onceConsumed||(n.once&&(e.onceConsumed=!0),e.throttleLastFireTs=Ye(),t(i,o)))}function Ue(e,n){const t=e.throttle;if(t){t.leading;const e=t.windowMs,o=Ye(),i=n.throttleLastFireTs;if(null!==i&&o-i<e)return{pass:!1,reason:"throttle-window"};n.throttleLastFireTs=o}if(e.once){if(n.onceConsumed)return{pass:!1,reason:"once-consumed"};n.onceConsumed=!0}return{pass:!0}}function He(e){return!(!e||!(e.throttle&&!1===e.throttle.leading&&!1===e.throttle.trailing||e.debounce&&!1===e.debounce.leading&&!1===e.debounce.trailing))}let Xe=()=>Date.now();function Ye(){return Xe()}let Ge=0;function We(t){var o,i;const a=t.canvasId,{source:r}=t,c=t.dataStore,s=new Set;let d="off",l=0,u=!1;const p="w"+ ++Ge;let f=0;function g(){return`${p}-${++f}`}let h=0;function m(e){L.hasListeners("binding:trace")&&L.emit("binding:trace",{canvasId:a,ts:Date.now(),seq:++h,...e})}let v=!1,y=null;function I(){v&&(y&&y(),y=null,v=!1)}const x=new Map,w=new Map,b=new Set,S=new Set,k=new Set,B=new Set,z=new Map;let M=new Set;const T=[],C=[],L=function(e){const n=new Set,t=new Set,o=new Set;return{on(i,a){var r;if("binding:fire"===i){const e=a;return n.add(e),()=>n.delete(e)}if("binding:error"===i){const e=a;return t.add(e),()=>t.delete(e)}const c=a;return o.add(c),null==(r=null==e?void 0:e.onTraceListenerCountChange)||r.call(e,o.size),()=>{var n;o.delete(c),null==(n=null==e?void 0:e.onTraceListenerCountChange)||n.call(e,o.size)}},emit(e,i){if("binding:fire"===e)for(const e of n)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else if("binding:error"===e)for(const e of t)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else for(const e of o)try{e(i)}catch(e){console.error("[hc-canvas/wirePageBindings] trace listener threw",e)}},hasListeners:e=>"binding:fire"===e?n.size>0:"binding:error"===e?t.size>0:o.size>0,clear(){n.clear(),t.clear(),o.clear()}}}({onTraceListenerCountChange:function(e){e>0?!v&&c&&(y=c.attachTraceBridge(e=>{if(u)return;const n=c.getBindingsForCacheKey(e.cacheKey);for(const t of n)m({kind:e.kind,bindingId:t,cacheKey:e.cacheKey,sourceId:e.sourceId,writeSeq:e.writeSeq,reason:e.reason,payload:e.value})}),v=!0):I()}}),E=function(e){let n=[],t=200,o=null,i=null;return{start:function(a){i&&(i(),i=null,n=[]),t=(null==a?void 0:a.capacity)??200,o=(null==a?void 0:a.filterKinds)&&a.filterKinds.length>0?new Set(a.filterKinds):null,i=e.on("binding:trace",e=>{o&&!o.has(e.kind)||(n.push(e),n.length>t&&n.shift())})},stop:function(){i&&(i(),i=null);const e=n.slice();return n=[],e},snapshot:function(){return n.slice()},get isRunning(){return null!==i}}}({on:(e,n)=>L.on(e,n)});function D(e){return void 0===e.canvasId||e.canvasId===a}function P(e){for(const n of X(e))if(void 0!==n.canvasId&&n.canvasId!==a)return!0;return!1}function R(e){return JSON.stringify({id:e.id,type:e.type,disabled:e.disabled??!1,source:e.source,target:e.target,mapping:e.mapping??null,schedule:e.schedule??null,errorPolicy:e.errorPolicy??null})}function $(e,n){return void 0===n||R(e)!==n}function O(){var e;return(null==(e=r.getDocument())?void 0:e.bindings)??[]}function F(e){return O().find(n=>n.id===e)}function A(e){try{e()}catch(e){console.error("[hc-canvas/wirePageBindings] cleanup threw",e)}}function N(e,n){L.emit("binding:fire",e),m({kind:"fire",bindingId:e.bindingId,chainId:n,payload:e.payload,args:e.args})}function j(e,n){L.emit("binding:error",e),m({kind:(null==n?void 0:n.traceKind)??"error",bindingId:e.bindingId,chainId:null==n?void 0:n.chainId,code:e.code,message:e.message,detail:e.detail})}function V(e,n=!1){const t=x.get(e);if(t)for(const e of t)A(e);x.delete(e);const o=w.get(e);if(o){const n=function(e){const n={};return null!==e.debouncePendingTimer&&(clearTimeout(e.debouncePendingTimer),e.debouncePendingTimer=null,null!==e.debouncePendingChainId&&(n.droppedDebounce={chainId:e.debouncePendingChainId,payload:e.debouncePendingPayload})),null!==e.debouncePendingTimer||null===e.debouncePendingChainId||n.droppedDebounce||(n.droppedDebounce={chainId:e.debouncePendingChainId,payload:e.debouncePendingPayload}),e.debouncePendingChainId=null,e.debouncePendingPayload=void 0,e.debounceDirty=!1,null!==e.throttleTrailingTimer&&(clearTimeout(e.throttleTrailingTimer),e.throttleTrailingTimer=null),null!==e.throttleTrailingPendingChainId&&(n.droppedThrottleTrailing={chainId:e.throttleTrailingPendingChainId,payload:e.throttleTrailingPendingPayload}),e.throttleTrailingPendingChainId=null,e.throttleTrailingPendingPayload=void 0,e.throttleWindowStartTs=null,n}(o);n.droppedDebounce&&m({kind:"scheduled-dropped",bindingId:e,chainId:n.droppedDebounce.chainId,payload:n.droppedDebounce.payload}),n.droppedThrottleTrailing&&m({kind:"scheduled-dropped",bindingId:e,chainId:n.droppedThrottleTrailing.chainId,payload:n.droppedThrottleTrailing.payload}),w.delete(e)}S.delete(e),z.delete(e),k.delete(e),B.delete(e),s.delete(e),c&&c.removeBinding(e,{preserveCache:n})}function q(e=!1){for(const n of[...x.keys()])V(n,e)}function _(e){if(u)return;if(x.has(e.id))return;if(P(e))return void(k.has(e.id)||(j({bindingId:e.id,code:"unsupported-cross-canvas"}),k.add(e.id),m({kind:"wire-skipped",bindingId:e.id,reason:"unsupported-cross-canvas"})));const t=function(e){return e.disabled?"disabled":b.has(e.id)?"stopped":null}(e);if(t)return void m({kind:"wire-skipped",bindingId:e.id,reason:t});if("data-preview"===d&&"dataSource"!==e.source.kind)return void m({kind:"wire-skipped",bindingId:e.id,reason:"mode-matrix-data-preview"});He(e.schedule)&&!B.has(e.id)&&(console.warn(`[hc-canvas/wirePageBindings] schedule.{throttle|debounce}.{leading=false,trailing=false} 永远不会 fire (binding "${e.id}")`),B.add(e.id));const o=[];switch(e.source.kind){case"instanceEvent":{const t=n.getInstance(e.source.instanceId,a);if(!t)return void S.add(e.id);const i=e.source.event,r=t.on(i,n=>J(e,n));o.push(r);break}case"lifecycle":case"page":break;case"dataSource":{if(!c)return void(s.has(e.id)||(j({bindingId:e.id,code:"no-data-adapter"}),m({kind:"wire-skipped",bindingId:e.id,reason:"no-data-adapter"}),s.add(e.id)));const n=e.source,t="change"===n.watch,o=n=>J(e,n),i=n=>{j({bindingId:e.id,code:"data-query-failed",message:n instanceof Error?n.message:String(n),detail:n}),"stop"===je(e.errorPolicy,n,e.id)&&b.add(e.id)};m({kind:"data-query-started",bindingId:e.id,sourceId:n.sourceId}),t?c.subscribe({bindingId:e.id,sourceId:n.sourceId,onUpdate:o,onError:i}):c.request({bindingId:e.id,sourceId:n.sourceId,onUpdate:o,onError:i});break}default:return}x.set(e.id,o),z.set(e.id,R(e))}function K(){for(const e of O())_(e)}function J(e,n){if(u)return;if("off"===d)return;if(b.has(e.id))return void m({kind:"stopped-skipped",bindingId:e.id});if(P(e))return;if(l>=8){const n=g();return void j({bindingId:e.id,code:"cycle-detected"},{chainId:n,traceKind:"cycle-detected"})}const t=g(),o=function(e,n,t,o){return He(e)?{fire:!1,deferred:!1,reason:"schedule-no-fire"}:(null==e?void 0:e.debounce)?function(e,n,t,o){const i=e.debounce,a=i.leading??!1,r=i.trailing??!0,c=i.windowMs;if(null===n.debouncePendingTimer){if(a){const t=Ue(e,n);return t.pass?(n.debounceLeadingFireTs=Ye(),n.debounceDirty=!1,n.debouncePendingPayload=void 0,n.debouncePendingChainId=null,{fire:!0,deferred:!1,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{Ke(n,e,r,t)},c)}}):{fire:!1,deferred:!1,reason:t.reason}}return n.debouncePendingPayload=t,n.debouncePendingChainId=o,n.debounceDirty=!0,{fire:!1,deferred:!0,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{Ke(n,e,r,t)},c)}}}const s=null!==n.debouncePendingChainId?{chainId:n.debouncePendingChainId,payload:n.debouncePendingPayload}:void 0;return n.debounceDirty=!0,r&&(n.debouncePendingPayload=t,n.debouncePendingChainId=o),clearTimeout(n.debouncePendingTimer),n.debouncePendingTimer=null,r?{fire:!1,deferred:!0,droppedByReschedule:s,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{Ke(n,e,r,t)},c)}}:{fire:!1,deferred:!1,reason:"debounce-window",scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{Ke(n,e,r,t)},c)}}}(e,n,t,o):function(e,n,t,o){const i=null==e?void 0:e.throttle;if(!i)return function(e,n){if(null==e?void 0:e.once){if(n.onceConsumed)return{fire:!1,deferred:!1,reason:"once-consumed"};n.onceConsumed=!0}return{fire:!0,deferred:!1}}(e,n);const a=i.leading??!0,r=i.trailing??!1,c=i.windowMs,s=Ye();if(a){const i=n.throttleLastFireTs;if(!(null!==i&&s-i<c))return(null==e?void 0:e.once)&&n.onceConsumed?{fire:!1,deferred:!1,reason:"once-consumed"}:((null==e?void 0:e.once)&&(n.onceConsumed=!0),n.throttleLastFireTs=s,{fire:!0,deferred:!1});if(!r)return{fire:!1,deferred:!1,reason:"throttle-window"};const a=null!==n.throttleTrailingPendingChainId?{chainId:n.throttleTrailingPendingChainId,payload:n.throttleTrailingPendingPayload}:void 0;if(n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,null===n.throttleTrailingTimer){const t=c-(s-i);return{fire:!1,deferred:!0,scheduleDeferred:o=>{n.throttleTrailingTimer=setTimeout(()=>{Je(n,e,o)},t)}}}return{fire:!1,deferred:!1,reason:"throttle-window",droppedByReschedule:a}}if(null===n.throttleWindowStartTs)return n.throttleWindowStartTs=s,n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,{fire:!1,deferred:!0,reason:"leading-disabled",scheduleDeferred:t=>{n.throttleTrailingTimer=setTimeout(()=>{Je(n,e,t)},c)}};const d=null!==n.throttleTrailingPendingChainId?{chainId:n.throttleTrailingPendingChainId,payload:n.throttleTrailingPendingPayload}:void 0;return n.throttleTrailingPendingPayload=t,n.throttleTrailingPendingChainId=o,{fire:!1,deferred:!1,reason:"throttle-window",droppedByReschedule:d}}(e,n,t,o)}(e.schedule,function(e){let n=w.get(e);return n||(n={onceConsumed:!1,throttleLastFireTs:null,throttleWindowStartTs:null,throttleTrailingPendingPayload:void 0,throttleTrailingPendingChainId:null,throttleTrailingTimer:null,debouncePendingTimer:null,debouncePendingPayload:void 0,debouncePendingChainId:null,debounceDirty:!1,debounceLeadingFireTs:null},w.set(e,n)),n}(e.id),n,t),i=function(e){if(e)return e.throttle?{kind:"throttle",windowMs:e.throttle.windowMs,leading:e.throttle.leading,trailing:e.throttle.trailing}:e.debounce?{kind:"debounce",windowMs:e.debounce.windowMs,leading:e.debounce.leading,trailing:e.debounce.trailing}:void 0}(e.schedule);o.droppedByReschedule&&m({kind:"scheduled-dropped",bindingId:e.id,chainId:o.droppedByReschedule.chainId,payload:o.droppedByReschedule.payload,schedule:i}),o.scheduleDeferred&&o.scheduleDeferred((n,t)=>{u||(m({kind:"scheduled-flushed",bindingId:e.id,chainId:t,payload:n,schedule:i}),U(e,n,t))}),o.reason?m({kind:"scheduled-skipped",bindingId:e.id,chainId:t,reason:o.reason,payload:n,schedule:i}):!o.deferred||o.fire?o.fire&&U(e,n,t):m({kind:"scheduled-deferred",bindingId:e.id,chainId:t,payload:n,schedule:i})}function U(e,t,o){if(u)return;const i=n.getInstance(e.target.instanceId,a);if(!i)return void j({bindingId:e.id,code:"target-not-mounted"},{chainId:o});let r,c;try{r=Ve(e.mapping,t)}catch(n){return m({kind:"mapping-failed",bindingId:e.id,chainId:o,message:n instanceof Error?n.message:String(n),detail:n}),void("stop"===je(e.errorPolicy,n,e.id)&&b.add(e.id))}if("instanceDataInput"===e.target.kind){const n=i.vm.custom,a=null==n?void 0:n[e.target.key];if(!a||"object"!=typeof a||!0!==a.dataInput)return void j({bindingId:e.id,code:"unknown-target-data-input",message:n&&e.target.key in n?`target.key "${e.target.key}" on instance "${e.target.instanceId}" is not declared with dataInput:true`:`target.key "${e.target.key}" not declared on instance "${e.target.instanceId}"`},{chainId:o});try{i.setDataInput(e.target.key,r[0])}catch(n){return"stop"===je(e.errorPolicy,n,e.id)&&b.add(e.id),void j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o})}return void N({bindingId:e.id,source:e.source,target:e.target,payload:t,args:r},o)}l++;try{c=function(e,n,t){switch(n.kind){case"instanceMethod":return e.call(n.method,...t);case"instanceEmit":return void e.emit(n.event,t[0]);default:return}}(i,e.target,r),N({bindingId:e.id,source:e.source,target:e.target,payload:t,args:r},o)}catch(n){return"stop"===je(e.errorPolicy,n,e.id)&&b.add(e.id),void j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o})}finally{l--}var s;"object"==typeof(s=c)&&null!==s&&"function"==typeof s.then&&Promise.resolve(c).catch(n=>{u||("stop"===je(e.errorPolicy,n,e.id)&&b.add(e.id),j({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o}))})}const H=null==(o=r.onAction)?void 0:o.call(r,e=>{var n,t,o,i;if(u)return;if("off"===d)return;const a=e;if(a&&"object"==typeof a)switch(a.type){case"addBinding":{const e=null==(t=null==(n=a.payload)?void 0:n.binding)?void 0:t.id;if(!e)return;const o=F(e);o&&_(o);break}case"updateBinding":{const e=null==(o=a.payload)?void 0:o.bindingId;if(!e)return;V(e);const n=F(e);n&&_(n);break}case"removeBinding":{const e=null==(i=a.payload)?void 0:i.bindingId;if(!e)return;V(e),b.delete(e);break}case"replaceDocument":q(),b.clear(),S.clear(),K();break;case"removeInstance":!function(){const e=new Set(O().map(e=>e.id));for(const n of[...x.keys()])e.has(n)||(V(n),b.delete(n));for(const e of O())_(e)}()}});H&&T.push(H);const Y=null==(i=r.onDocumentChange)?void 0:i.call(r,()=>{if(u)return;if("off"===d)return;const e=O(),n=new Set(e.map(e=>e.id)),t=new Set(x.keys());for(const e of t)n.has(e)||V(e);for(const n of e)x.has(n.id)?$(n,z.get(n.id))&&(V(n.id),_(n)):_(n)});function G(){return new Set(n.listInstances({canvasId:a}).map(e=>e.instanceId))}Y&&T.push(Y),M=G();const W=e.watch(n.registryVersion,()=>{if(u)return;if("off"===d)return;const e=G(),n=Qe(e,M),t=Qe(M,e);M=e;for(const n of[...S]){const t=F(n);t?Q(t,e)&&(S.delete(n),_(t)):S.delete(n)}if(t.size>0)for(const e of[...x.keys()]){const n=F(e);n&&X(n).some(e=>D(e)&&t.has(e.instanceId))&&(V(e),S.add(e))}!function(e){if(0!==e.size)for(const n of O())"lifecycle"===n.source.kind&&"mounted"===n.source.hook&&D({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&J(n,{instanceId:n.source.instanceId,hook:"mounted"})}(n),function(e){if(0!==e.size)for(const n of O())"lifecycle"===n.source.kind&&"unmounted"===n.source.hook&&D({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&J(n,{instanceId:n.source.instanceId,hook:"unmounted"})}(t)},{flush:"post"});function Q(e,n){for(const t of X(e)){if(!D(t))return!1;if(!n.has(t.instanceId))return!1}return!0}return C.push(W),{setMode:function(e){u||e!==d&&(q(!0),b.clear(),S.clear(),d=e,"off"!==e&&K(),"runtime"===e&&function(){for(const e of O())"page"===e.source.kind&&"pageInit"===e.source.hook&&J(e,{hook:"pageInit"})}())},getMode:()=>d,testBinding(e,t){const o=[],i=F(e);if(!i)return o.push({bindingId:e,phase:"skipped",details:{reason:"binding-not-found"}}),o;if(i.disabled)return o.push({bindingId:e,phase:"skipped",details:{reason:"disabled"}}),o;if(P(i))return o.push({bindingId:e,phase:"skipped",details:{reason:"unsupported-cross-canvas"}}),o;let r;try{r=Ve(i.mapping,t),o.push({bindingId:e,phase:"mapping",details:{payload:t,args:r}})}catch(n){return o.push({bindingId:e,phase:"error",details:{stage:"mapping",message:n instanceof Error?n.message:String(n)}}),o}const c=n.getInstance(i.target.instanceId,a);if(!c)return o.push({bindingId:e,phase:"skipped",details:{reason:"target-not-mounted"}}),o;if("instanceDataInput"===i.target.kind){const n=c.vm.custom,t=null==n?void 0:n[i.target.key];if(!t||"object"!=typeof t||!0!==t.dataInput)return o.push({bindingId:e,phase:"skipped",details:{reason:"unknown-target-data-input",key:i.target.key}}),o}return o.push({bindingId:e,phase:"calling-target",details:{target:i.target,dryRun:!0}}),o.push({bindingId:e,phase:"done",details:{args:r}}),o},on:(e,n)=>L.on(e,n),startTracing(e){E.start(e)},stopTracing:()=>E.stop(),getTraceBuffer:()=>E.snapshot(),dispose:function(){if(!u){"runtime"===d&&function(){for(const e of O())"page"===e.source.kind&&"pageBeforeUnmount"===e.source.hook&&J(e,{hook:"pageBeforeUnmount"})}(),u=!0,q();for(const e of T)A(e);for(const e of C)A(e);T.length=0,C.length=0,b.clear(),S.clear(),k.clear(),B.clear(),z.clear(),M.clear(),w.clear(),E.stop(),L.clear(),I(),d="off"}}}}function Qe(e,n){const t=new Set;for(const o of e)n.has(o)||t.add(o);return t}const Ze=["display","gridTemplateColumns","gridTemplateRows","gridAutoFlow","flexDirection","flexWrap","gap","rowGap","columnGap","justifyContent","alignItems","position"];let en=!1;function nn(e,t){const o="string"==typeof(null==e?void 0:e.js)?e.js:"",i="string"==typeof(null==e?void 0:e.html)?e.html:"",a=n.parseComponentSource(o,i);return!a.ok&&(null==t?void 0:t.fallback)?t.fallback:{propsDecl:a.propsDecl.map(on),emitsDecl:a.emitsDecl.map(rn),methodsDecl:a.methodsDecl.map(an),slotsDecl:a.slotsDecl.map(cn),modelDecl:a.modelDecl.map(sn),dataInputsDecl:a.dataInputsDecl.map(dn),dataOutputsDecl:a.dataOutputsDecl.map(dn)}}function tn(e){if("string"===e||"number"===e||"boolean"===e||"object"===e||"array"===e||"any"===e)return e}function on(e){const n=e.key,t="string"==typeof e.name?e.name:void 0;return{key:n,type:tn(e.type)??"string",...void 0!==e.value?{value:e.value}:{},...t&&t!==n?{label:t}:{},...e.enum?{enum:e.enum}:{}}}function an(e){return{key:e.name,...e.params?{params:e.params}:{}}}function rn(e){return{event:e.event}}function cn(e){return{name:e.name,...void 0!==e.multiple?{multiple:e.multiple}:{},...void 0!==e.accepts?{accepts:e.accepts}:{},...void 0!==e.maxChildren?{maxChildren:e.maxChildren}:{},...void 0!==e.label?{label:e.label}:{}}}function sn(e){const n=tn(e.type);return{key:e.key,...void 0!==e.prop?{prop:e.prop}:{},...void 0!==e.event?{event:e.event}:{},...n?{type:n}:{},...void 0!==e.defaultValue?{defaultValue:e.defaultValue}:{}}}function dn(e){const n=tn(e.type);return{key:e.key,...n?{type:n}:{},...void 0!==e.label?{label:e.label}:{}}}const ln=["data-hc-canvas-id"],un=["data-instance-id","data-hc-hidden"],pn={key:0,class:"hc-page-instance-fallback",style:{width:"100%",height:"100%",border:"2px dashed #f59e0b",background:"#fef3c7",color:"#92400e",padding:"8px",fontSize:"11px",fontFamily:"monospace",overflow:"hidden",borderRadius:"4px",boxSizing:"border-box"}},fn={style:{opacity:"0.8"}},gn={style:{opacity:"0.6","margin-top":"4px","word-break":"break-all"}},hn={key:2,class:"hc-page-instance-skeleton",style:{width:"100%",height:"100%",background:"linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%)",backgroundSize:"200% 100%",animation:"hc-skeleton-shimmer 1.5s infinite ease-in-out",borderRadius:"4px",boxSizing:"border-box"}},mn=["data-instance-id","data-hc-placement","data-hc-hidden"],vn={key:0,class:"hc-page-instance-fallback",style:{width:"100%",height:"100%",border:"2px dashed #f59e0b",background:"#fef3c7",color:"#92400e",padding:"8px","font-size":"11px","font-family":"monospace",overflow:"hidden","border-radius":"4px","box-sizing":"border-box"}},yn={style:{opacity:"0.6"}},In=["title"],xn={key:1,class:"hc-page-renderer-empty",style:{padding:"24px",color:"#64748b","font-size":"13px"}},wn=e.defineComponent({__name:"HyperCardPageRenderer",props:{payload:{},document:{},componentSourceMap:{},schedulerOptions:{},canvasId:{},adapters:{}},setup(t,{expose:o}){var i,c;const s=t,d=s.canvasId??function(){var e;const n="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`auto-${(null==(e=null==n?void 0:n.randomUUID)?void 0:e.call(n).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}();e.provide(n.HC_CANVAS_ID_KEY,d);const l=H(s.schedulerOptions),u=e.ref(null);let p=!1;e.onMounted(()=>{ne||e.nextTick(()=>{var e;if(p)return;if(!u.value)return;if("fill"!==(null==(e=Z.value)?void 0:e.canvas.height.mode))return;const n=u.value.parentElement;n&&(n.getBoundingClientRect().height>0||(p=!0,console.warn("[hypercard] HyperCardPageRenderer 父容器高度为 0,fill 模式画布不可见。请给父容器设置明确 height 或改用 px 模式。")))})}),e.onBeforeUnmount(()=>{r(d),oe.value&&(oe.value.dispose(),oe.value=null),l.dispose(),ie&&ie.disposeAll(),d!==n.DEFAULT_CANVAS_ID&&n.disposeCanvas(d)});const f=e.ref(new Map),g=e.ref(new Map),y=new Map,I=e.ref(!1);let x=null;function w(){I.value=!1,x&&clearTimeout(x),x=setTimeout(()=>{I.value=!0},300)}function b(e,n){const t=new Map;if(n.querySelectorAll("[data-hc-slot]").forEach(e=>{if(e.closest("[data-instance-id]")!==n)return;const o=e.getAttribute("data-hc-slot")||Te;t.has(o)||t.set(o,e)}),function(e,n){if(!e||e.size!==n.size)return!1;for(const[t,o]of n)if(e.get(t)!==o)return!1;return!0}(g.value.get(e),t))return;const o=new Map(g.value);o.set(e,t),g.value=o,S(e,t)}function S(e,n){var t;const o=n.get(Te);if(!o)return;const i=B.value,a=null==i?void 0:i.instances.find(n=>n.instanceId===e),r="active"===(null==(t=V.value.containers.get(e))?void 0:t.status);!function(e,n,t=!1){!function(e){const n=e.style;for(const e of Ze)n[e]=""}(e);const o=null==n?void 0:n.mode;if(!n||"none"===o||void 0===o)return;if("free"===o)return void(e.style.position="relative");if("free-split"===o)return void(t||en||(en=!0,console.warn("[hypercard] free-split 容器降级平铺(分割树非法 / plan fallback),子实例已平铺显示。")));const i=D(n);i&&Object.assign(e.style,i)}(o,null==a?void 0:a.containerLayout,r)}function k(e,n){const t=f.value.get(e);n&&n!==t?(f.value.set(e,n),l.register(e,n),function(e,n){const t=y.get(e);t&&t.disconnect(),b(e,n);const o=new MutationObserver(()=>b(e,n));o.observe(n,{childList:!0,subtree:!0}),y.set(e,o)}(e,n)):!n&&t&&(l.unregister(e),f.value.delete(e),function(e){const n=y.get(e);if(n&&(n.disconnect(),y.delete(e)),g.value.has(e)){const n=new Map(g.value);n.delete(e),g.value=n}}(e))}e.onMounted(w),e.watch(g,w),e.onBeforeUnmount(()=>{for(const e of y.values())e.disconnect();y.clear(),g.value=new Map,j.clearAll(),x&&clearTimeout(x)});const B=e.computed(()=>{var e;const n=(null==(e=s.payload)?void 0:e.document)??s.document??null;return n?v(m(h(n))):null});e.watch(B,()=>{e.nextTick(()=>function(){for(const[e,n]of g.value)S(e,n)}())},{flush:"post"});const z=e.computed(()=>function(e){const n={};for(const t of Object.keys(e)){const o=e[t],i=o.source;o&&"ok"===o.status&&i&&("string"==typeof i.html||"string"==typeof i.js)?n[t]={...o,contract:nn({html:i.html??"",js:i.js??"",css:i.css??""},{fallback:o.contract})}:n[t]=o}return n}(s.payload?s.payload.componentVersions:s.componentSourceMap??{})),M=e.computed(()=>{const e=B.value,n=z.value;return e?e.instances.map(t=>{var o;const i=n[t.componentVersionKey]??null,a=(null==(o=e.componentOverrides)?void 0:o[t.instanceId])??null,r=a&&a.baseVersionKey===t.componentVersionKey?a:null,c=r?`${r.baseVersionKey}#override:${t.instanceId}`:t.componentVersionKey;if(r)return{instance:t,asset:i,override:r,renderSource:r.source,scopeId:c,status:"ok"};if(!i)return{instance:t,asset:null,override:null,renderSource:null,scopeId:c,status:"missing-source",invalidReason:`componentVersionKey "${t.componentVersionKey}" not in sourceMap`};if("ok"!==i.status)return{instance:t,asset:i,override:null,renderSource:null,scopeId:c,status:"unavailable",invalidReason:i.invalidReason??`component version unavailable (${i.status})`};let s=null;return s=function(e){return!!e&&!0===e.isDraft}(i)?i.lastGoodSource:i.source??null,s?{instance:t,asset:i,override:null,renderSource:s,scopeId:c,status:"ok"}:{instance:t,asset:i,override:null,renderSource:null,scopeId:c,status:"missing-source",invalidReason:"asset.status=ok but source missing"}}):[]});function T(e){const n=z.value[e];return null==n?void 0:n.contract}const C=e.computed(()=>{const e=B.value;return e?Le(e,{resolveContract:T}):[]}),E=e.inject(ke,null);e.watch(C,e=>{E&&"function"==typeof E.setLayoutIssues&&E.setLayoutIssues(e)},{immediate:!0});const $=e.computed(()=>{const e=new Set;for(const n of C.value)"missing-parent"!==n.kind&&"invalid-slot"!==n.kind&&"parent-not-layout"!==n.kind&&"orphan-slot"!==n.kind&&"cycle"!==n.kind&&"absolute-child-rejected"!==n.kind||e.add(n.instanceId);return e}),O=e.computed(()=>M.value.filter(e=>void 0===e.instance.parentId)),F=e.computed(()=>M.value.filter(e=>void 0!==e.instance.parentId&&K(e.instance.placement)));function A(e){const n=e.layoutBox??{x:e.rect.x,y:e.rect.y,width:e.rect.w,height:e.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},t=function(e){const n=B.value;if(n)return J(Z.value??void 0,n.instances,e.instanceId)}(e),o=L(n,e.zIndex,e.rotation,t,function(e){var n,t;const o=B.value;if(!o)return;if(void 0===e.parentId){const e=null==(n=Z.value)?void 0:n.rootLayout;return"split"===(null==e?void 0:e.mode)?e.direction:void 0}const i=null==(t=o.instances.find(n=>n.instanceId===e.parentId))?void 0:t.containerLayout;return"split"===(null==i?void 0:i.mode)?i.direction:void 0}(e)),i=P(e.layoutItem,t);return i&&Object.assign(o,i),Y(e)&&function(e){e.width="100%",e.height="100%",e.position="relative",delete e.left,delete e.top}(o),o}const N=e.computed(()=>{var e;return D(null==(e=Z.value)?void 0:e.rootLayout)}),j=function(){const n=e.ref(new Map);return{map:n,register:function(e,t,o){const i=n.value.get(e);if(i&&i.get(t)===o)return;const a=new Map(n.value),r=new Map(i??[]);r.set(t,o),a.set(e,r),n.value=a},unregister:function(e,t){const o=n.value.get(e);if(!o||!o.has(t))return;const i=new Map(n.value),a=new Map(o);a.delete(t),0===a.size?i.delete(e):i.set(e,a),n.value=i},get:function(e,t){var o;return null==(o=n.value.get(e))?void 0:o.get(t)},clearContainer:function(e){if(!n.value.has(e))return;const t=new Map(n.value);t.delete(e),n.value=t},clearAll:function(){0!==n.value.size&&(n.value=new Map)}}}(),V=e.computed(()=>function(e){if(!e)return Oe;const n=new Map;for(const t of e.instances){const e=t.containerLayout;if(!e||"free-split"!==e.mode)continue;const o=t.instanceId,i=e,a=Ne(i.root);a.ok?n.set(o,{status:"active",containerId:o,root:i.root,instanceToLeaf:a.instanceToLeaf}):n.set(o,{status:"fallback",containerId:o,reason:a.reason})}return{containers:n}}(B.value)),q=e.computed(()=>{const e=[];for(const n of V.value.containers.values())"active"===n.status&&e.push(n);return e});function _(e){var n;return(null==(n=g.value.get(e))?void 0:n.get(Te))??null}function U(e){const n=e.root;return e.containerId+":"+("leaf"===n.type?n.leafId:n.nodeId)}function X(e){var n,t;const o=null==(t=null==(n=B.value)?void 0:n.instances.find(n=>n.instanceId===e))?void 0:t.containerLayout;return"free-split"===(null==o?void 0:o.mode)?o.gap??0:0}function Y(e){return function(e){const{parentId:n,instanceId:t,effectiveSlot:o,plan:i}=e;if(!n)return null;if(o!==Te)return null;const a=i.containers.get(n);if(!a||"active"!==a.status)return null;const r=a.instanceToLeaf.get(t);return r?{containerId:n,leafId:r}:null}({parentId:e.parentId,instanceId:e.instanceId,effectiveSlot:Ce(e),plan:V.value})}function G(e){if(!e.parentId)return null;const n=Y(e);if(n)return j.get(n.containerId,n.leafId)??null;const t=g.value.get(e.parentId);return t?t.get(Ce(e))??null:null}function W(e){return{position:"absolute",left:"8px",top:8+28*F.value.indexOf(e)+"px",padding:"4px 8px",background:"hsla(40, 90%, 50%, 0.95)",color:"#5b3a00",fontSize:"11px",fontFamily:"ui-monospace, monospace",borderRadius:"4px",zIndex:9999,maxWidth:"60%",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap"}}function Q(e){return"实例 "+e.instance.instanceId+':slot "'+Ce(e.instance)+'" 不可用'}const Z=e.computed(()=>{var e;return(null==(e=B.value)?void 0:e.layout)??null}),ee=e.computed(()=>{if(!Z.value)return null;if(ne){const e=ne.measuredCanvasSize.value;return{width:`${e.w}px`,height:`${e.h}px`,overflow:Z.value.canvas.overflow??"hidden"}}return{width:R(Z.value.canvas.width),height:R(Z.value.canvas.height),overflow:Z.value.canvas.overflow??"hidden"}}),ne=e.inject(ke,void 0),te=ne?null:xe(null==(i=s.adapters)?void 0:i.assets),oe=e.shallowRef(null),ie=ne||!(null==(c=s.adapters)?void 0:c.data)?null:Se(s.adapters.data);if(!ne){const n=We({canvasId:d,source:{getDocument:()=>B.value,onDocumentChange:n=>e.watch(B,n,{flush:"post"})},dataStore:ie??void 0});oe.value=n,e.nextTick(()=>{n.setMode("runtime")})}const ae=ne?{invalidateDataSource(e){ne.dataStore.invalidate(e)},getDataSourceSnapshot:()=>ne.dataStore.getSnapshot(),getCachedBySourceId:(e,n)=>ne.dataStore.getCachedBySourceId(e,n)}:ie?{invalidateDataSource(e){ie.invalidate(e)},getDataSourceSnapshot:()=>ie.getSnapshot(),getCachedBySourceId:(e,n)=>ie.getCachedBySourceId(e,n)}:null,re={canvasId:d,getSchedulerStats:()=>l.getStats(),listRuntimeInstances:()=>function(){const e=B.value;if(!e)return[];const t=new Map;for(const e of C.value)t.set(e.instanceId,!0);const o=l.state;return e.instances.map(e=>{const i=o[e.instanceId];let a,r;switch(i){case"mounting":case"mounted":case"disposing":a=i;break;default:a="pending"}if(t.has(e.instanceId))r="layout-error";else if(e.componentId){const n=e.source;r=!n||n.template||n.script||n.style?"ok":"missing-source"}else r="missing-componentId";return{instanceId:e.instanceId,componentId:e.componentId,mountState:a,timings:n.getInstanceTimings(d,e.instanceId),protocolStatus:r}})}(),getInstanceTimings:e=>n.getInstanceTimings(d,e),getLayoutIssues:()=>C.value,getPageDocument:()=>B.value};e.onMounted(()=>{a(d,re)}),o({binding:oe,data:ae});const ce=e.ref(null);let se=0;e.watch(()=>{var e,n;return null==(n=null==(e=Z.value)?void 0:e.background)?void 0:n.image},e=>{se++;const n=se;if(!e)return void(ce.value=null);const t=(o=e,ne?ne.resolveAsset(o):te.resolve(o));var o;"string"!=typeof t?(ce.value=null,t.then(t=>{var o,i;n===se&&(null==(i=null==(o=Z.value)?void 0:o.background)?void 0:i.image)===e&&(ce.value=t||null)},()=>{n===se&&(ce.value=null)})):ce.value=t||null},{immediate:!0,deep:!0});const de=e.computed(()=>{var e;const n=null==(e=Z.value)?void 0:e.background;if(!n)return null;const t={position:"absolute",inset:"0",pointerEvents:"none",zIndex:-1};return n.color&&(t.background=n.color),n.image&&ce.value&&(t.backgroundImage=`url("${ce.value}")`,t.backgroundRepeat="repeat"===n.imageFit?"repeat":"no-repeat",t.backgroundPosition=n.imagePosition??"center","stretch"===n.imageFit?t.backgroundSize="100% 100%":n.imageFit&&"repeat"!==n.imageFit&&"center"!==n.imageFit&&(t.backgroundSize=n.imageFit)),void 0!==n.opacity&&(t.opacity=n.opacity),t});return(t,o)=>Z.value&&ee.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"rootEl",ref:u,class:"hc-page-renderer","data-hc-canvas-id":e.unref(d),style:e.normalizeStyle({position:"relative",...ee.value,...N.value??{}})},[de.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-canvas-bg","data-hc-canvas-bg":"",style:e.normalizeStyle(de.value)},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(O.value,t=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:t.instance.instanceId,ref_for:!0,ref:e=>k(t.instance.instanceId,e),"data-instance-id":t.instance.instanceId,"data-hc-hidden":t.instance.hidden?"true":void 0,style:e.normalizeStyle(A(t.instance))},["ok"===t.status&&t.renderSource?e.unref(l).isMounted(t.instance.instanceId)?(e.openBlock(),e.createBlock(e.unref(n.RuntimeBox),{key:1,"canvas-id":e.unref(d),"instance-id":t.instance.instanceId,"component-id":t.instance.componentId,"scope-id":t.scopeId,"html-source":t.renderSource.html,"js-source":t.renderSource.js,"css-source":t.renderSource.css,"custom-values":{...t.instance.props,__containerLayout:t.instance.containerLayout}},null,8,["canvas-id","instance-id","component-id","scope-id","html-source","js-source","css-source","custom-values"])):(e.openBlock(),e.createElementBlock("div",hn)):(e.openBlock(),e.createElementBlock("div",pn,[o[0]||(o[0]=e.createElementVNode("div",{style:{"font-weight":"600","margin-bottom":"4px"}}," ⚠️ 组件不可渲染 ",-1)),e.createElementVNode("div",fn,e.toDisplayString(t.instance.alias??t.instance.instanceId),1),e.createElementVNode("div",gn,e.toDisplayString(t.invalidReason),1)]))],12,un)),[[e.vShow,!t.instance.hidden]])),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.value,t=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`child-${t.instance.instanceId}`},[G(t.instance)&&!$.value.has(t.instance.instanceId)?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:G(t.instance)},[e.withDirectives(e.createElementVNode("div",{ref_for:!0,ref:e=>k(t.instance.instanceId,e),"data-instance-id":t.instance.instanceId,"data-hc-placement":t.instance.placement,"data-hc-hidden":t.instance.hidden?"true":void 0,style:e.normalizeStyle(A(t.instance))},["ok"===t.status&&t.renderSource?(e.openBlock(),e.createBlock(e.unref(n.RuntimeBox),{key:1,"canvas-id":e.unref(d),"instance-id":t.instance.instanceId,"component-id":t.instance.componentId,"scope-id":t.scopeId,"html-source":t.renderSource.html,"js-source":t.renderSource.js,"css-source":t.renderSource.css,"custom-values":{...t.instance.props,__containerLayout:t.instance.containerLayout}},null,8,["canvas-id","instance-id","component-id","scope-id","html-source","js-source","css-source","custom-values"])):(e.openBlock(),e.createElementBlock("div",vn,[o[1]||(o[1]=e.createElementVNode("div",{style:{"font-weight":"600"}},"⚠️ 组件不可渲染",-1)),e.createElementVNode("div",yn,e.toDisplayString(t.invalidReason),1)]))],12,mn),[[e.vShow,!t.instance.hidden]])],8,["to"])):$.value.has(t.instance.instanceId)||I.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-layout-issue-warning",title:Q(t),style:e.normalizeStyle(W(t))}," ⚠ 布局问题:"+e.toDisplayString(t.instance.instanceId)+'(slot "'+e.toDisplayString(e.unref(Ce)(t.instance))+'") ',13,In)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(q.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`fs-${n.containerId}`},[_(n.containerId)?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:_(n.containerId)},[(e.openBlock(),e.createBlock($e,{key:U(n),"container-id":n.containerId,node:n.root,register:e.unref(j).register,unregister:e.unref(j).unregister,gap:X(n.containerId)},null,8,["container-id","node","register","unregister","gap"]))],8,["to"])):e.createCommentVNode("",!0)],64))),128))],12,ln)):(e.openBlock(),e.createElementBlock("div",xn," No page to render(payload / document 都未提供) "))}}),bn=new Map,Sn=new Set;function kn(){const e=Object.freeze(Array.from(bn.keys()));for(const n of Sn)try{n(e)}catch{}}function Bn(e,n){bn.set(e,n),kn()}function zn(e){bn.delete(e)&&kn()}function Mn(e,n){var t;const o=n.document;switch(e.type){case"addInstance":{const{instance:n}=e.payload;return o.getInstance(n.instanceId)?null:[{type:"removeInstance",payload:{instanceId:n.instanceId}}]}case"removeInstance":{const{instanceId:n}=e.payload,t=o.getInstance(n);if(!t)return null;const i=o.document.bindings.filter(e=>Y(e,n)),a=[{type:"addInstance",payload:{instance:Cn(t)}}];for(const e of i)a.push({type:"addBinding",payload:{binding:c(e)}});return a}case"updateInstance":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a={};for(const e of Object.keys(t)){const n=i[e];a[e]=Tn(n)?c(n):n}return[{type:"updateInstance",payload:{instanceId:n,patch:a}}]}case"moveInstance":{const{instanceId:n,x:t,y:i}=e.payload,a=o.getInstance(n);return a?a.rect.x===t&&a.rect.y===i?null:a.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...a.layoutBox}}}]:[{type:"moveInstance",payload:{instanceId:n,x:a.rect.x,y:a.rect.y}}]:null}case"resizeInstance":{const{instanceId:n,w:t,h:i}=e.payload,a=o.getInstance(n);return a?a.rect.w===t&&a.rect.h===i?null:a.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...a.layoutBox}}}]:[{type:"resizeInstance",payload:{instanceId:n,w:a.rect.w,h:a.rect.h}}]:null}case"setInstanceProp":{const{instanceId:n,key:t,value:i}=e.payload,a=o.getInstance(n);return a?a.props[t]===i?null:[{type:"updateInstance",payload:{instanceId:n,patch:{props:{...a.props}}}}]:null}case"addBinding":{const{binding:n}=e.payload;return o.document.bindings.some(e=>e.id===n.id)?null:[{type:"removeBinding",payload:{bindingId:n.id}}]}case"removeBinding":{const{bindingId:n}=e.payload,t=o.document.bindings.find(e=>e.id===n);return t?[{type:"addBinding",payload:{binding:c(t)}}]:null}case"updateBinding":{const{bindingId:n,patch:t}=e.payload,i=o.document.bindings.find(e=>e.id===n);if(!i)return null;const a={};for(const e of Object.keys(t)){const n=i[e];a[e]=Tn(n)?c(n):n}return[{type:"updateBinding",payload:{bindingId:n,patch:a}}]}case"updateLayout":{const{patch:n}=e.payload,t={};for(const e of Object.keys(n)){const n=o.document.layout[e];t[e]=Tn(n)?c(n):n}return[{type:"updateLayout",payload:{patch:t}}]}case"setRootLayout":{const{rootLayout:n}=e.payload,t=o.document.layout.rootLayout,i=void 0!==t;return i||null!==n?[{type:"setRootLayout",payload:{rootLayout:i?c(t):null}}]:null}case"setComponentOverride":{const{instanceId:n,override:i}=e.payload;if(void 0===o.getInstance(n))return null;const a=null==(t=o.document.componentOverrides)?void 0:t[n],r=void 0!==a;return r||null!==i?[{type:"setComponentOverride",payload:{instanceId:n,override:r?c(a):null}}]:null}case"replaceDocument":return[{type:"replaceDocument",payload:{document:c(o.document)}}];case"setInstanceLocked":{const{instanceId:n,locked:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.locked??!1,r=i.lockPosition,c=i.lockSize;return a===t&&r===(!!t||void 0)&&c===(!!t||void 0)?null:[{type:"updateInstance",payload:{instanceId:n,patch:{locked:a,lockPosition:r,lockSize:c}}}]}case"duplicateInstance":{const{instanceId:n,newInstanceId:t}=e.payload;return o.getInstance(n)?o.getInstance(t)?null:[{type:"removeInstance",payload:{instanceId:t}}]:null}case"setInstanceSize":{const{instanceId:n,size:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.size,r="size"in i&&void 0!==a;return r||null!==t?[{type:"setInstanceSize",payload:{instanceId:n,size:(r?c(a):null)??null}}]:null}case"setContainerLayout":{const{instanceId:n,containerLayout:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.containerLayout,r="containerLayout"in i&&void 0!==a;return r||null!==t?[{type:"setContainerLayout",payload:{instanceId:n,containerLayout:(r?c(a):null)??null}}]:null}case"updateLayoutBox":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.layoutBox??{x:i.rect.x,y:i.rect.y,width:i.rect.w,height:i.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},r={};let c=!1;const s=["x","y","width","height"];for(const e of s){const n=t[e];"number"==typeof n&&Number.isFinite(n)&&(r[e]=a[e],c=!0)}return"px"!==t.widthMode&&"percent"!==t.widthMode&&"fill"!==t.widthMode&&"auto"!==t.widthMode||(r.widthMode=a.widthMode,c=!0),"px"!==t.heightMode&&"percent"!==t.heightMode&&"fill"!==t.heightMode&&"auto"!==t.heightMode||(r.heightMode=a.heightMode,c=!0),"hidden"!==t.overflow&&"visible"!==t.overflow&&"auto"!==t.overflow||(r.overflow=a.overflow,c=!0),c?[{type:"updateLayoutBox",payload:{instanceId:n,patch:r}}]:null}case"updateLayoutItem":{const{instanceId:n,patch:t}=e.payload,i=o.getInstance(n);if(!i)return null;const a=i.layoutItem,r="layoutItem"in i&&void 0!==a,s=null===t;if(!r&&s)return null;if(!s){const e=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"];let n=!1;for(const o of e){const e=t[o];if("number"==typeof e&&Number.isFinite(e)){n=!0;break}}if(!n)return null}return[{type:"updateLayoutItem",payload:{instanceId:n,patch:(r?c(a):null)??null}}]}case"updateRotation":{const{instanceId:n,value:t}=e.payload,i=o.getInstance(n);if(!i)return null;if(!Number.isFinite(t))return null;const a=i.rotation,r="number"==typeof a&&Number.isFinite(a)?a:0;return r===t?null:[{type:"updateRotation",payload:{instanceId:n,value:r}}]}case"select":case"toggleSelect":case"addToSelection":case"removeFromSelection":case"clearSelection":case"selectAll":case"freeSplitFill":case"freeSplitClear":case"freeSplitSwap":case"freeSplitResize":case"freeSplitSplit":case"freeSplitMerge":return null;default:{const n=e;return console.warn("[hc-canvas/computeInverse] unknown action",n),null}}}function Tn(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function Cn(e){return c(e)}function Ln(n,t={}){const o=t.maxSize??100,i=e.ref([]),a=e.ref([]),r=function(e){return Ie.get(e)}(n);let c={redo:[],undo:[]},s=null;function d(e){var n;0===c.redo.length&&0===c.undo.length||(n={type:e,redo:c.redo,undo:c.undo,timestamp:Date.now()},i.value.push(n),i.value.length>o&&i.value.shift(),a.value.length>0&&(a.value=[]),c={redo:[],undo:[]},s=null)}const l={onBeforeAction(e){if(n.isRecordingSuppressed.value)return;if(he(e)){const n=(null==r?void 0:r.computeInverse(e))??null;if(!n)return;return c.redo.push(e),c.undo.unshift(n),void(s=e.type)}const t=Mn(e,n);if(null!==t){c.redo.push(e);for(let e=t.length-1;e>=0;e--)c.undo.unshift(t[e]);s=e.type}},onAfterAction(e){n.isRecordingSuppressed.value||n.isBatching.value||d(s??"action")},onAfterBatch(e){n.isRecordingSuppressed.value||d(e??"batch")}},u=n.registerHooks(l);function p(){i.value=[],a.value=[],c={redo:[],undo:[]},s=null}return{undo:function(){if(0===i.value.length)return;const e=i.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.undo)n.dispatch(t);n.endBatch("undo")}),a.value.push(e)},redo:function(){if(0===a.value.length)return;const e=a.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.redo)n.dispatch(t);n.endBatch("redo")}),i.value.push(e)},clear:p,canUndo:e.computed(()=>i.value.length>0),canRedo:e.computed(()=>a.value.length>0),undoStackSize:e.computed(()=>i.value.length),redoStackSize:e.computed(()=>a.value.length),dispose:function(){u(),p()}}}class En extends Error{constructor(e="CanvasHandle has been disposed"){super(e),this.name="HandleDisposedError"}}function Dn(e,n,t){let o=null;for(const i of e)for(const e of n){const n=e.pos-i,a=Math.abs(n);a<=t&&(!o||a<Math.abs(o.delta))&&(o={delta:n,candidate:e,targetPos:i})}return o}function Pn(e){var n,t,o,i;const a=e.threshold??5,r=function(e){if(0===e.length)return null;let n=1/0,t=-1/0,o=1/0,i=-1/0;for(const a of e)a.x<n&&(n=a.x),a.x+a.w>t&&(t=a.x+a.w),a.y<o&&(o=a.y),a.y+a.h>i&&(i=a.y+a.h);return{left:n,right:t,top:o,bottom:i,centerX:(n+t)/2,centerY:(o+i)/2,width:t-n,height:i-o}}(e.draggedRects);if(!r)return{dx:0,dy:0,lines:[]};const c=function(e,n,t){const o=[];for(const n of e)o.push({pos:n.x,kind:"edge-left",source:n}),o.push({pos:n.x+n.w,kind:"edge-right",source:n}),o.push({pos:n.x+n.w/2,kind:"center-x",source:n});if(o.push({pos:0,kind:"canvas-edge"}),o.push({pos:n.w,kind:"canvas-edge"}),o.push({pos:n.w/2,kind:"canvas-edge"}),t)for(const e of t)o.push({pos:e,kind:"guide"});return o}(e.otherRects,e.canvasSize,null==(n=e.manualGuides)?void 0:n.x),s=function(e,n,t){const o=[];for(const n of e)o.push({pos:n.y,kind:"edge-top",source:n}),o.push({pos:n.y+n.h,kind:"edge-bottom",source:n}),o.push({pos:n.y+n.h/2,kind:"center-y",source:n});if(o.push({pos:0,kind:"canvas-edge"}),o.push({pos:n.h,kind:"canvas-edge"}),o.push({pos:n.h/2,kind:"canvas-edge"}),t)for(const e of t)o.push({pos:e,kind:"guide"});return o}(e.otherRects,e.canvasSize,null==(t=e.manualGuides)?void 0:t.y),d=[r.left,r.right,r.centerX],l=[r.top,r.bottom,r.centerY],u=Dn(d,c,a),p=Dn(l,s,a),f=(null==u?void 0:u.delta)??0,g=(null==p?void 0:p.delta)??0,h=[];if(u){const n=(null==(o=u.candidate.source)?void 0:o.y)??0,t=u.candidate.source?u.candidate.source.y+u.candidate.source.h:e.canvasSize.h,i=Math.min(r.top+g,n),a=Math.max(r.bottom+g,t);h.push({axis:"x",pos:u.candidate.pos,from:i,to:a,kind:u.candidate.kind})}if(p){const n=(null==(i=p.candidate.source)?void 0:i.x)??0,t=p.candidate.source?p.candidate.source.x+p.candidate.source.w:e.canvasSize.w,o=Math.min(r.left+f,n),a=Math.max(r.right+f,t);h.push({axis:"y",pos:p.candidate.pos,from:o,to:a,kind:p.candidate.kind})}return{dx:f,dy:g,lines:h}}function Rn(e,n,t){const o=new Map;for(let e=0;e<n.length;e++)o.set(n[e].instanceId,e);const i=new Map;function a(e){const t=i.get(e);if(t)return t;const o=[];let a=e;const r=new Set;for(;a&&!r.has(a);){r.add(a),o.push(a);const e=n.find(e=>e.instanceId===a);if(!(null==e?void 0:e.parentId))break;a=e.parentId}const c=o.reverse();return i.set(e,c),c}function r(e,t){const i=a(e),r=a(t);let c=0;for(;c<i.length&&c<r.length&&i[c]===r[c];)c++;if(c===i.length&&c===r.length)return 0;if(c===i.length)return-1;if(c===r.length)return 1;const s=i[c],d=r[c],l=n.find(e=>e.instanceId===s),u=n.find(e=>e.instanceId===d),p=(null==l?void 0:l.zIndex)??0,f=(null==u?void 0:u.zIndex)??0;return p!==f?p-f:(o.get(s)??-1)-(o.get(d)??-1)}let c=null,s=-1;for(let o=0;o<n.length;o++){const i=n[o];if(i.hidden)continue;const a=(null==t?void 0:t(i.instanceId))??i.rect;if(!(e.x>=a.x&&e.x<=a.x+a.w&&e.y>=a.y&&e.y<=a.y+a.h))continue;if(null===c){c=i.instanceId,s=o;continue}const d=r(i.instanceId,c);let l;l=d>0||!(d<0)&&o>s,l&&(c=i.instanceId,s=o)}return c}function $n(e,n){return{x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),w:Math.abs(e.x-n.x),h:Math.abs(e.y-n.y)}}function On(e,n,t){const o=[];for(const i of n){if(i.hidden)continue;const n=(null==t?void 0:t(i.instanceId))??i.rect;n.x>=e.x&&n.y>=e.y&&n.x+n.w<=e.x+e.w&&n.y+n.h<=e.y+e.h&&o.push(i.instanceId)}return o}function Fn(e,n){if(!e||"function"!=typeof e.querySelector)return null;const t=e.querySelector(n);if(t)return t;if(e instanceof Element&&"function"==typeof e.closest){const t=e.closest("[data-hc-canvas-designer]");if(t&&t!==e){const e=t.querySelector(n);if(e)return e}}return null}function An(e,n,t){var o;const i=t??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!i)return null;const a=n??"default",r=""===a?"default":a,c="undefined"!=typeof globalThis&&(null==(o=globalThis.CSS)?void 0:o.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),s=Fn(i,`[data-instance-id="${c(e)}"] [data-hc-slot="${c(r)}"]`);return s&&s instanceof HTMLElement?s.getBoundingClientRect():null}function Nn(e,n,t){var o;const i=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!i)return null;if("function"!=typeof i.querySelector)return null;const a=`[data-instance-id="${("undefined"!=typeof globalThis&&(null==(o=globalThis.CSS)?void 0:o.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`))(e)}"]`,r=t?Fn(i,a):i.querySelector(a);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null}function jn(e,n){return J(e.document.document.layout,e.document.document.instances,n)}function Vn(e){return"free"===e||"none"===e||void 0===e}const qn=new Set(["e","w","ne","nw","se","sw"]),_n=new Set(["n","s","ne","nw","se","sw"]);function Kn(e,n,t,o){if(Vn(e))return!0;const i=qn.has(n),a=_n.has(n);return!(i&&"fill"===t||a&&"fill"===o)}function Jn(e,n,t){if(!n)return null;const o=Nn(e,n,!0);if(!o)return null;const i=n.getBoundingClientRect(),a=t.toCanvasPoint({x:o.left-i.left,y:o.top-i.top}),r=t.toCanvasPoint({x:o.right-i.left,y:o.bottom-i.top});return{x:a.x,y:a.y,w:Math.max(0,r.x-a.x),h:Math.max(0,r.y-a.y)}}function Un(e,n,t){const o=Math.max(8,n);if(!e)return{mode:"px",value:o};switch(e.mode){case"px":return{...e,mode:"px",value:o};case"percent":{if(!t||t<=0)return{...e,mode:"px",value:o};const n=o/t*100,i=Math.max(0,Math.min(1e3,n));return{...e,mode:"percent",value:i}}case"fill":case"hug":case"auto":return{mode:"px",value:o,min:e.min,max:e.max}}}function Hn(e,n,t){const o=Math.max(8,n);switch(e){case"px":case"fill":case"auto":default:return{mode:"px",value:o};case"percent":{if(!t||t<=0)return{mode:"px",value:o};const e=o/t*100;return{mode:"percent",value:Math.max(0,Math.min(1e3,e))}}}}function Xn(e){return e.shift||e.ctrl||e.meta}function Yn(e,n,t){const o=n.getBoundingClientRect(),i={x:e.x-o.left,y:e.y-o.top};return t.toCanvasPoint(i)}function Gn(e,n){const t=new Set(n.map(e=>e.instanceId));return e.filter(e=>t.has(e))}function Wn(n,t={}){const o=e.reactive({active:!1,start:null,end:null,additive:!1,priorSelection:[]}),i=e.reactive({status:"idle",startPt:null,startRects:new Map,deferredClickSelect:null}),a=e.reactive({status:"idle",handle:null,startPt:null,startRect:null,instanceId:null,placement:null,parentLayoutMode:void 0,startSize:null,startLayoutBox:null,startOutletCanvasSize:null}),r=e.ref([]),c=e.ref(null);let s=0;const d=e.ref(null);let l=0;const u=e.computed(()=>o.active&&o.start&&o.end?$n(o.start,o.end):null),p=e.computed(()=>"active"===i.status),f=e.computed(()=>"active"===a.status);function g(){o.active=!1,o.start=null,o.end=null,o.additive=!1,o.priorSelection=[]}function h(){i.status="idle",i.startPt=null,i.startRects=new Map,i.deferredClickSelect=null,r.value=[]}function m(){a.status="idle",a.handle=null,a.startPt=null,a.startRect=null,a.instanceId=null,a.placement=null,a.startSize=null,a.startOutletCanvasSize=null,a.parentLayoutMode=void 0,a.startLayoutBox=null}return{marquee:o,marqueeRect:u,drag:i,isDragging:p,resize:a,isResizing:f,snapLines:r,cannotDragSlotChildEvent:c,cannotDragLayoutManagedChildEvent:d,handlePointerDown(e,a){var r;const u=n.effectiveBehavior.value;if(!u.selectable)return{startTracking:!1};const p=n.toolMode.value;if("hand"===p)return{startTracking:!1};const f=Xn(a),g="marquee"===p?null:Rn(e,n.document.document.instances,t.getDomBox);if(g){const t=n.document.getInstance(g),o=!0===((null==t?void 0:t.lockPosition)??(null==t?void 0:t.locked)),a=n.selection.selectedIds.value.includes(g),h=n.selection.size.value>1;f?n.dispatch({type:"toggleSelect",payload:{instanceId:g}}):o?n.dispatch({type:"select",payload:{instanceId:g}}):a&&h&&u.draggable&&"inspect"!==p?i.deferredClickSelect=g:n.dispatch({type:"select",payload:{instanceId:g}});const m="slot"===(null==t?void 0:t.placement)||"container"===(null==t?void 0:t.placement),v=jn(n,g),y="inspect"===p;if(o||!u.draggable||y||(null==t?void 0:t.hidden))return{startTracking:!1};if(!Vn(v)){if(!f){l++;const e={instanceId:g,parentId:null==t?void 0:t.parentId,parentLayoutMode:v,token:l};d.value=e,null==(r=n.setCannotDragLayoutManagedChildEvent)||r.call(n,e),m&&(s++,c.value={instanceId:g,parentId:null==t?void 0:t.parentId,token:s})}return{startTracking:!1}}return i.status="pending",i.startPt={...e},i.startRects=function(){const e=n.selection.selectedIds.value,t=new Map;for(const o of e){const e=n.document.getInstance(o);e&&!0!==(e.lockPosition??e.locked)&&t.set(o,{x:e.rect.x,y:e.rect.y})}return t}(),{startTracking:!0}}return f||n.dispatch({type:"clearSelection"}),o.active=!0,o.start={...e},o.end={...e},o.additive=f,o.priorSelection=f?[...n.selection.selectedIds.value]:[],{startTracking:!0}},handlePointerMove(e){var c,s;if("active"===a.status&&a.startPt&&a.startRect&&a.instanceId){const t=e.x-a.startPt.x,o=e.y-a.startPt.y,i=a.startRect,r=a.handle,c=n.document.getInstance(a.instanceId);if(!c)return;const s=a.parentLayoutMode,d=void 0!==s&&!Vn(s);let l=i.x,u=i.y,p=i.w,f=i.h;const g="w"===r||"nw"===r||"sw"===r,h="e"===r||"ne"===r||"se"===r,m="n"===r||"ne"===r||"nw"===r,v="s"===r||"se"===r||"sw"===r;h?p=i.w+t:g&&(p=i.w-t,d||(l=i.x+t)),v?f=i.h+o:m&&(f=i.h-o,d||(u=i.y+o)),p<8&&(!d&&g&&(l=i.x+i.w-8),p=8),f<8&&(!d&&m&&(u=i.y+i.h-8),f=8);const y=a.startLayoutBox,I=a.startOutletCanvasSize,x=h||g,w=v||m,b=!d&&g,S=!d&&m,k=x?Hn(y.widthMode,p,I?I.w:null):null,B=w?Hn(y.heightMode,f,I?I.h:null):null,z="canvas"===a.placement||"absolute"===a.placement,M=!(k&&"px"!==k.mode||B&&"px"!==B.mode||x&&"px"!==y.widthMode||w&&"px"!==y.heightMode);if(z&&M)(x&&c.rect.w!==p||w&&c.rect.h!==f)&&n.dispatch({type:"resizeInstance",payload:{instanceId:a.instanceId,w:x?p:c.rect.w,h:w?f:c.rect.h}}),(b&&c.rect.x!==l||S&&c.rect.y!==u)&&n.dispatch({type:"moveInstance",payload:{instanceId:a.instanceId,x:b?l:c.rect.x,y:S?u:c.rect.y}});else{const e={};k&&(e.widthMode=k.mode,e.width=k.value),B&&(e.heightMode=B.mode,e.height=B.value),b&&(e.x=l),S&&(e.y=u);const t=c.layoutBox;let o=!1;t?(void 0!==e.x&&e.x!==t.x&&(o=!0),void 0!==e.y&&e.y!==t.y&&(o=!0),void 0!==e.width&&e.width!==t.width&&(o=!0),void 0!==e.height&&e.height!==t.height&&(o=!0),void 0!==e.widthMode&&e.widthMode!==t.widthMode&&(o=!0),void 0!==e.heightMode&&e.heightMode!==t.heightMode&&(o=!0)):o=Object.keys(e).length>0,o&&n.dispatch({type:"updateLayoutBox",payload:{instanceId:a.instanceId,patch:e}})}if(("container"===a.placement||"slot"===a.placement)&&(null!==a.startSize||M)){const e=a.startSize,t={};x?t.width=Un(null==e?void 0:e.width,p,I?I.w:null):(null==e?void 0:e.width)&&(t.width=JSON.parse(JSON.stringify(e.width))),w?t.height=Un(null==e?void 0:e.height,f,I?I.h:null):(null==e?void 0:e.height)&&(t.height=JSON.parse(JSON.stringify(e.height)));const o=c.size;JSON.stringify(o)!==JSON.stringify(t)&&n.dispatch({type:"setInstanceSize",payload:{instanceId:a.instanceId,size:t}})}return}if("pending"===i.status&&i.startPt){const t=e.x-i.startPt.x,o=e.y-i.startPt.y;t*t+o*o>=9&&(i.status="active",n.beginBatch())}if("active"===i.status&&i.startPt){const o=e.x-i.startPt.x,a=e.y-i.startPt.y,d=(null==(c=t.getRoot)?void 0:c.call(t))??null,l=d instanceof HTMLElement?d:null,u=n.document.document.instances,p=null!==l&&u.length<=50,f=(e,t)=>p?Jn(e,l,n.viewport)??t:t,g=[];for(const[e,t]of i.startRects){const i=n.document.getInstance(e);if(!i)continue;const r=f(e,i.rect);g.push({x:t.x+o,y:t.y+a,w:r.w,h:r.h})}const h=[],m=new Set(i.startRects.keys());for(const e of u)m.has(e.instanceId)||h.push(f(e.instanceId,e.rect));const v=n.document.document.layout,y=!1!==n.effectiveBehavior.value.snap,I=(null==(s=v.guides)?void 0:s.items)??[],x=[],w=[];for(const e of I)"x"===e.axis?x.push(e.position):w.push(e.position);const b=y?Pn({draggedRects:g,otherRects:h,canvasSize:{w:n.measuredCanvasSize.value.w,h:n.measuredCanvasSize.value.h},manualGuides:x.length||w.length?{x:x,y:w}:void 0}):{dx:0,dy:0,lines:[]};r.value=b.lines;const S=o+b.dx,k=a+b.dy;for(const[e,t]of i.startRects)n.document.getInstance(e)&&n.dispatch({type:"moveInstance",payload:{instanceId:e,x:t.x+S,y:t.y+k}});return}o.active&&(o.end={...e})},handlePointerUp(){if("active"===a.status){const e="slot"===a.placement||"container"===a.placement?"resize-slot-child":"resize";return n.endBatch(e),void m()}if("active"===i.status)return n.endBatch("drag"),void h();if("pending"===i.status)return i.deferredClickSelect&&n.dispatch({type:"select",payload:{instanceId:i.deferredClickSelect}}),void h();if(!o.active)return;const e=u.value,t=n.document.document.instances;if(e&&(e.w>0||e.h>0)){const i=Gn(On(e,t),t);if(o.additive){const e=Gn(o.priorSelection,t),a=Array.from(new Set([...e,...i]));n.dispatch({type:"selectAll",payload:{instanceIds:a}})}else i.length>0&&n.dispatch({type:"selectAll",payload:{instanceIds:i}})}g()},cancelMarquee(){g()},cancelDrag(){"active"===i.status&&n.endBatch("drag-cancel"),h()},handleResizeStart(e,o,i){var r,c,s,d,l,u;const p=n.document.getInstance(e);if(!p)return{startTracking:!1};if(!0===(p.lockSize??p.locked))return{startTracking:!1};if(p.hidden)return{startTracking:!1};if(!n.effectiveBehavior.value.resizable)return{startTracking:!1};const f="slot"===p.placement||"container"===p.placement,g=jn(n,e);if(!Kn(g,o,null==(r=p.layoutBox)?void 0:r.widthMode,null==(c=p.layoutBox)?void 0:c.heightMode))return{startTracking:!1};a.status="active",a.handle=o,a.startPt={...i};const h=Jn(e,(null==(s=t.getRoot)?void 0:s.call(t))??null,n.viewport);a.startRect=h??{...p.rect},a.instanceId=e,a.placement=f?"container":"canvas",a.parentLayoutMode=g,a.startLayoutBox=p.layoutBox?JSON.parse(JSON.stringify(p.layoutBox)):{x:p.rect.x,y:p.rect.y,width:p.rect.w,height:p.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},a.startSize=f&&p.size?JSON.parse(JSON.stringify(p.size)):null;const m=p.parentId,v=p.slot,y=(null==(d=t.getRoot)?void 0:d.call(t))??null;let I=m?An(m,v,y):null;if(m&&(!I||0===I.width&&0===I.height)){const n=Fn(y,`[data-instance-id="${e.replace(/["\\]/g,e=>`\\${e}`)}"]`),t=n instanceof HTMLElement?n.parentElement:null;if(t){const e=t.getBoundingClientRect();(e.width>0||e.height>0)&&(I=e)}}if(I){const e=n.viewport.scale.value||1;a.startOutletCanvasSize={w:I.width/e,h:I.height/e}}else if(void 0===m)a.startOutletCanvasSize={w:n.measuredCanvasSize.value.w,h:n.measuredCanvasSize.value.h};else{const n=a.startLayoutBox.widthMode,t=a.startLayoutBox.heightMode,o="percent"===n||"percent"===t;o&&console.debug("[hc-canvas/interaction] resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:m,slot:v});const i=a.startSize,r="percent"===(null==(l=null==i?void 0:i.width)?void 0:l.mode)||"percent"===(null==(u=null==i?void 0:i.height)?void 0:u.mode);!o&&r&&console.debug("[hc-canvas/interaction] slot child resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:m,slot:v}),a.startOutletCanvasSize=null}return n.beginBatch(),{startTracking:!0}},cancelResize(){if("active"===a.status){const e="slot"===a.placement||"container"===a.placement?"resize-slot-child-cancel":"resize-cancel";n.endBatch(e)}m()}}}function Qn(e){var n;return"undefined"!=typeof globalThis&&(null==(n=globalThis.CSS)?void 0:n.escape)?globalThis.CSS.escape(e):e.replace(/["\\]/g,e=>`\\${e}`)}function Zn(e,n){return{ok:!1,reason:e,message:n}}function et(e,n,t,o={}){const i=new Map;for(const n of e)i.set(n.instanceId,n);const a=i.get(n);if(!a)return Zn("instance-not-exists",`实例 "${n}" 不存在,无法 reparent`);const r=null===t.parentId||void 0===t.parentId?void 0:t.parentId;if(r===n)return Zn("self-parent",`parentId 不能等于自身 "${n}"`);if(void 0!==r){const e=i.get(r);if(!e)return Zn("parent-not-exists",`目标 parentId "${r}" 不存在`);const t=new Set;let o=e.parentId;for(;void 0!==o&&!t.has(o);){if(t.add(o),o===n)return Zn("cycle",`目标 parent "${r}" 是 "${n}" 的后代,会循环`);const e=i.get(o);o=null==e?void 0:e.parentId}}if(void 0===r)return{ok:!0};const c=o.resolveContract;if(!c)return{ok:!0};const s=i.get(r),d=c(s.componentVersionKey);if(!d)return{ok:!0};const l=d.slotsDecl??[];if(0===l.length)return Zn("parent-not-layout",`父组件 "${s.componentId}" 不是布局组件(slotsDecl 空)`);const u=void 0===t.slot||""===t.slot||"default"===t.slot?Te:t.slot,p=(f=u,l.find(e=>e.name===f));var f;if(!p)return Zn("slot-not-exists",`slot "${u}" 不在父 "${s.componentId}" 的 slotsDecl`);if(p.accepts&&p.accepts.length>0&&!p.accepts.includes(a.componentId))return Zn("accepts-violation",`slot "${u}" 不允许 componentId "${a.componentId}"(accepts: ${p.accepts.join(", ")})`);if(!0!==p.multiple){const t=e.filter(e=>e.instanceId!==n&&e.parentId===r&&Ce(e)===u);if(t.length>0)return Zn("slot-multiple-violated",`slot "${u}" 不允许多个子实例(已有 "${t[0].instanceId}")`)}if("number"==typeof p.maxChildren&&Number.isFinite(p.maxChildren)&&p.maxChildren>=1){const t=e.filter(e=>e.instanceId!==n&&e.parentId===r&&Ce(e)===u);if(t.length+1>p.maxChildren)return Zn("max-children-exceeded",`slot "${u}" 最多接受 ${p.maxChildren} 个子(已有 ${t.length} 个)`)}return{ok:!0}}function nt(e){const n=new Set(e.map(e=>e.instanceId)),t=new Map;for(const n of e)t.set(n.instanceId,ot(n));const o=[],i=new Map;e.forEach((e,a)=>{const r={inst:e,node:t.get(e.instanceId),originalIndex:a},c=e.parentId;if(c){if(!n.has(c))return console.warn(`[hc-canvas/instance-tree] instance "${e.instanceId}" parentId="${c}" 不存在,降级当顶层`),void o.push(r);i.has(c)||i.set(c,[]),i.get(c).push(r)}else o.push(r)});for(const[e,n]of i){const o=t.get(e);o&&(o.children=tt(n).map(e=>e.node))}return o.slice().sort((e,n)=>{const t=(n.inst.zIndex??0)-(e.inst.zIndex??0);return 0!==t?t:e.originalIndex-n.originalIndex}).map(e=>e.node)}function tt(e){const n=new Map;for(const t of e){const e=t.inst.slot??"default";let o=n.get(e);o||(o={firstIndex:t.originalIndex,entries:[]},n.set(e,o)),o.entries.push(t)}return Array.from(n.values()).sort((e,n)=>e.firstIndex-n.firstIndex).flatMap(e=>e.entries.slice().sort((e,n)=>e.originalIndex-n.originalIndex))}function ot(e){const n={instanceId:e.instanceId,componentId:e.componentId,componentVersionKey:e.componentVersionKey,kind:"visual",label:e.alias??e.instanceId};return void 0!==e.locked&&(n.locked=e.locked),void 0!==e.lockPosition&&(n.lockPosition=e.lockPosition),void 0!==e.lockSize&&(n.lockSize=e.lockSize),void 0!==e.hidden&&(n.hidden=e.hidden),n}function it(e,n){for(const t of e){if(t.instanceId===n)return[t];if(t.children&&t.children.length>0){const e=it(t.children,n);if(e.length>0)return[t,...e]}}return[]}function at(e,n){const t=new Map;for(const n of e)t.set(n.instanceId,n);const o=t.get(n);if(!o)return[];const i=[o];let a=o;const r=e.length;for(;a&&a.parentId;){if(i.length>r){console.warn(`[hc-canvas/instance-tree] breadcrumb for "${n}" exceeds depth ${r},疑似环,截断`);break}const e=t.get(a.parentId);if(!e)break;i.unshift(e),a=e}return i}function rt(e,n,t){const o=n||void 0;return e.filter(e=>(e.parentId||void 0)===o&&e.slot===t).map((e,n)=>({inst:e,originalIndex:n})).sort((e,n)=>{const t=(n.inst.zIndex??0)-(e.inst.zIndex??0);return 0!==t?t:e.originalIndex-n.originalIndex}).map(e=>e.inst)}function ct(e){if(0===e.length)return null;let n=1/0,t=1/0,o=-1/0,i=-1/0;for(const a of e)a.x<n&&(n=a.x),a.y<t&&(t=a.y),a.x+a.w>o&&(o=a.x+a.w),a.y+a.h>i&&(i=a.y+a.h);return{x:n,y:t,w:o-n,h:i-t}}function st(e){return ct(e.map(e=>e.rect))}function dt(e,n){if(0===n.length)return null;const t=new Set(n),o=[];for(const n of e)t.has(n.instanceId)&&o.push(n.rect);return ct(o)}function lt(e,n,t){const o=(null==t?void 0:t.padding)??40,i=Math.max(1,n.w-2*o),a=Math.max(1,n.h-2*o),r=Math.max(1,e.w),c=Math.max(1,e.h);let s=Math.min(i/r,a/c);void 0!==(null==t?void 0:t.maxScale)&&(s=Math.min(s,t.maxScale)),void 0!==(null==t?void 0:t.minScale)&&(s=Math.max(s,t.minScale));const d=e.x+e.w/2,l=e.y+e.h/2;return{scale:s,panX:n.w/2-d*s,panY:n.h/2-l*s}}function ut(e,n){const t=e.scale||1;return{x:-e.panX/t+0,y:-e.panY/t+0,w:n.w/t,h:n.h/t}}function pt(e){const n=[];(e.metaKey||e.ctrlKey)&&n.push("mod"),e.shiftKey&&n.push("shift"),e.altKey&&n.push("alt");let t=e.key;return t="Meta"===t||"Control"===t?"mod":" "===t||"Space"===e.code?"space":(t.length,t.toLowerCase()),n[n.length-1]===t||n.push(t),n.join("+")}function ft(e){if(!(e&&e instanceof HTMLElement))return!1;const n=e.tagName;return"INPUT"===n||"TEXTAREA"===n||"SELECT"===n||!!e.isContentEditable}function gt(e,n){const t=pt(n);for(const n of e.keys)if(ht(n)===t)return!0;return!1}function ht(e){return e.split("+").map(e=>e.trim().toLowerCase()).join("+")}function mt(e){const{ctx:n}=e;function t(e){var n;const t="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`${e}_${(null==(n=null==t?void 0:t.randomUUID)?void 0:n.call(t).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}return{fill(e,t,o){n.dispatch({type:"freeSplitFill",payload:{containerId:e,leafId:t,instance:o}})},clear(e,t){n.dispatch({type:"freeSplitClear",payload:{containerId:e,leafId:t}})},swap(e,t,o){n.dispatch({type:"freeSplitSwap",payload:{containerId:e,leafIdA:t,leafIdB:o}})},resize(e,t,o){n.dispatch({type:"freeSplitResize",payload:{containerId:e,nodeId:t,sizes:o}})},split(e,o,i,a){const r=t("lf"),c=t("nd");return n.dispatch({type:"freeSplitSplit",payload:{containerId:e,leafId:o,edge:i,newLeafShare:a,newLeafId:r,newNodeId:c}}),{leafId:r,nodeId:c}},merge(e,t){n.dispatch({type:"freeSplitMerge",payload:{containerId:e,leafId:t}})}}}function vt(t,o){const i=Ln(t,o.recorder),a=function(e){const{ctx:n,options:t}=e;function o(e){const o=t.getStageEl();if(!o)return console.warn("[hc-canvas/handle] clientToCanvasPoint called before stage mounted; falling back to viewport.toCanvasPoint(raw clientPt). 结果可能偏移。"),n.viewport.toCanvasPoint(e);const i=o.getBoundingClientRect();return n.viewport.toCanvasPoint({x:e.x-i.left,y:e.y-i.top})}return{clientToCanvasPoint:o,getInstanceAtClientPoint:function(e){const i=t.getStageEl();if(!i)return null;const a=Rn(o(e),n.document.document.instances,e=>Jn(e,i,n.viewport));return a?n.document.getInstance(a)??null:null},getDropTarget:function(e,o,i){var a;const r=o??(null==(a=t.getStageEl)?void 0:a.call(t))??("undefined"!=typeof document&&"function"==typeof document.querySelectorAll?document:null);if(!r)return null;const c=void 0!==(null==i?void 0:i.excludeInstanceId),s=c?`[data-instance-id="${Qn(i.excludeInstanceId)}"]`:null;let d=s?r.querySelector(s):null;if(!d&&c&&r instanceof Element){const e=r.closest("[data-hc-canvas-designer]");e&&e!==r&&(d=e.querySelector(s))}let l=r.querySelectorAll("[data-hc-slot]");if(0===l.length&&c&&r instanceof Element){const e=r.closest("[data-hc-canvas-designer]");e&&e!==r&&(l=e.querySelectorAll("[data-hc-slot]"))}let u=null;for(const n of l){if(!(n instanceof HTMLElement))continue;if(d&&d.contains(n))continue;const t=n.getBoundingClientRect();if(0===t.width&&0===t.height)continue;if(e.x<t.left||e.x>t.right)continue;if(e.y<t.top||e.y>t.bottom)continue;let o=0,i=n;for(;i;)o++,i=i.parentElement;(!u||o>u.depth)&&(u={el:n,depth:o})}if(!u)return null;const p=u.el,f=p.closest("[data-instance-id]");if(!f)return null;const g=f.getAttribute("data-instance-id");return g&&n.document.getInstance(g)?{parentId:g,slot:p.getAttribute("data-hc-slot")||"default",outletEl:p}:null},getFreeSplitDropTarget:function(e,o){var i;const a=o??(null==(i=t.getStageEl)?void 0:i.call(t))??("undefined"!=typeof document&&"function"==typeof document.querySelectorAll?document:null);if(!a)return null;const r=a.querySelectorAll("[data-hc-leaf]");let c=null;for(const n of r){if(!(n instanceof HTMLElement))continue;const t=n.getBoundingClientRect();if(0===t.width&&0===t.height)continue;if(e.x<t.left||e.x>t.right)continue;if(e.y<t.top||e.y>t.bottom)continue;let o=0,i=n;for(;i;)o++,i=i.parentElement;(!c||o>c.depth)&&(c={el:n,depth:o})}if(!c)return null;const s=c.el,d=s.getAttribute("data-hc-leaf"),l=s.getAttribute("data-hc-leaf-container");if(!d||!l)return null;const u=n.document.getInstance(l),p=null==u?void 0:u.containerLayout;return p&&"free-split"===p.mode&&oe(p.root,d)?{containerId:l,leafId:d,leafEl:s}:null}}}({ctx:t,options:o}),r=function(n){const{ctx:t,options:o}=n;function i(){return nt(t.document.document.instances)}function a(e,n){const i=t.document.getInstance(e);if(!i)return console.warn(`[hc-canvas/handle] ${n}: instance "${e}" 不存在`),!1;const a=o.getStageEl();if(!a)return console.warn(`[hc-canvas/handle] ${n}: stage 未挂载,跳过滚动(${e})`),!1;const r=Jn(e,a,t.viewport),c=r&&(r.w>0||r.h>0)?r:{x:i.rect.x,y:i.rect.y,w:i.rect.w,h:i.rect.h},s=a.getBoundingClientRect(),d=t.viewport.scale.value,l=s.width/2-(c.x+c.w/2)*d,u=s.height/2-(c.y+c.h/2)*d;return t.viewport.setPan(l,u),!0}const r=e.ref(null);let c=0;return{getInstanceTree:i,getInstanceList:function(){return t.document.document.instances.map(e=>JSON.parse(JSON.stringify(e)))},getInstanceById:function(e){const n=t.document.getInstance(e);return n?JSON.parse(JSON.stringify(n)):null},getSelectedPath:function(){const e=t.selection.primaryId.value;return e?it(i(),e):[]},getBreadcrumb:function(e){return at(t.document.document.instances,e).map(e=>JSON.parse(JSON.stringify(e)))},focusInstance:function(e){t.document.getInstance(e)?(t.dispatch({type:"select",payload:{instanceId:e}}),a(e,"focusInstance")):console.warn(`[hc-canvas/handle] focusInstance: instance "${e}" 不存在`)},scrollToInstance:function(e){a(e,"scrollToInstance")},canReparent:function(e,n){return et(t.document.document.instances,e,n,{resolveContract:o.resolveContract})},moveInstanceInTree:function(e,n){var i,a,s;const d=et(t.document.document.instances,e,n,{resolveContract:o.resolveContract});if(!d.ok)return console.warn(`[hc-canvas/handle] moveInstanceInTree 守门拒绝(${d.reason}): ${d.message}`),void function(e,n,t,o){c++,r.value={instanceId:e,target:{...n},reason:t,message:o,token:c}}(e,n,d.reason,d.message??`reparent rejected: ${d.reason}`);const l=t.document.getInstance(e),u=null===n.parentId?void 0:n.parentId,p=(l.parentId||void 0)!==(u||void 0),f=l.slot!==n.slot,g={};if(p&&(g.parentId=u),f&&(g.slot=n.slot),p){const e=void 0===u?"canvas":"container";l.placement!==e&&(g.placement=e);const n=t.document.document.layout,o=void 0===u?(null==(i=null==n?void 0:n.rootLayout)?void 0:i.mode)??"free":(null==(s=null==(a=t.document.getInstance(u))?void 0:a.containerLayout)?void 0:s.mode)??"none";if(l.layoutBox)if("container"!==e||"flex"!==o&&"split"!==o&&"grid"!==o){if("canvas"===e){const e="fill"===l.layoutBox.widthMode?"px":l.layoutBox.widthMode,n="fill"===l.layoutBox.heightMode?"px":l.layoutBox.heightMode;e===l.layoutBox.widthMode&&n===l.layoutBox.heightMode||(g.layoutBox={...l.layoutBox,widthMode:e,heightMode:n})}}else g.layoutBox={...l.layoutBox,x:0,y:0,widthMode:"fill",heightMode:"fill"},g.rect={x:0,y:0,w:l.rect.w,h:l.rect.h};if("container"===e&&"grid"===o){const e=l.layoutItem??{};void 0!==e.row&&void 0!==e.column||(g.layoutItem={...e,row:e.row??1,column:e.column??1})}}const h=[];if(void 0!==n.index){const o=rt(t.document.document.instances,u,n.slot).filter(n=>n.instanceId!==e),i=Math.max(0,Math.min(n.index,o.length));o.splice(i,0,l),o.forEach((e,n)=>{const t=o.length-1-n;(e.zIndex??0)!==t&&h.push({id:e.instanceId,zIndex:t})})}if(0===Object.keys(g).length&&0===h.length)return;const m=!t.isBatching.value;m&&t.beginBatch();try{Object.keys(g).length>0&&t.dispatch({type:"updateInstance",payload:{instanceId:e,patch:g}});for(const e of h)t.dispatch({type:"updateInstance",payload:{instanceId:e.id,patch:{zIndex:e.zIndex}}})}finally{m&&t.endBatch("moveInstanceInTree")}},cannotReparentEvent:e.readonly(r)}}({ctx:t,options:o}),c=function(e){const{ctx:n,options:t}=e;function o(){const e=t.getStageEl();if(!e)return null;const n=e.getBoundingClientRect();return{w:n.width,h:n.height}}function i(){return{scale:n.viewport.scale.value,panX:n.viewport.panX.value,panY:n.viewport.panY.value}}function a(){return st(n.document.document.instances)}function r(){return dt(n.document.document.instances,n.selection.selectedIds.value)}function c(e,t){const a=o();if(!a)return void n.viewport.setScale(e);const r=i();let c;if(null==t?void 0:t.center)c=t.center;else{const e=ut(r,a);c={x:e.x+e.w/2,y:e.y+e.h/2}}const s=c.x*r.scale+r.panX,d=c.y*r.scale+r.panY,l=s-c.x*e,u=d-c.y*e;n.viewport.setScale(e),n.viewport.setPan(l,u)}function s(e,t){const i=o();if(!i)return void console.warn("[hc-canvas/handle] scrollToRect: stage 未挂载,跳过");const a=lt(e,i,t);n.viewport.setScale(a.scale),n.viewport.setPan(a.panX,a.panY)}return{getViewportState:i,getVisibleBounds:function(){const e=o();return e?ut(i(),e):{x:0,y:0,w:0,h:0}},getCanvasBounds:function(){const e=n.measuredCanvasSize.value;return{x:0,y:0,w:e.w,h:e.h}},getContentBounds:a,getSelectionBounds:r,getInstanceBounds:function(e){const t=n.document.getInstance(e);return t?{...t.rect}:null},panBy:function(e,t){n.viewport.setPan(n.viewport.panX.value+e,n.viewport.panY.value+t)},panTo:function(e,t){n.viewport.setPan(e,t)},zoomTo:c,zoomBy:function(e,t){c(n.viewport.scale.value+e,t)},zoomToPoint:function(e,o){const a=t.getStageEl();if(!a)return void console.warn("[hc-canvas/handle] zoomToPoint: stage 未挂载,跳过");const r=a.getBoundingClientRect(),c=o.x-r.left,s=o.y-r.top,d=i(),l=c-(c-d.panX)/d.scale*e,u=s-(s-d.panY)/d.scale*e;n.viewport.setScale(e),n.viewport.setPan(l,u)},resetViewport:function(){n.viewport.resetView()},scrollToRect:s,fitToContent:function(e){const n=a();n&&s(n,e)},fitToSelection:function(e){const n=r();n&&s(n,e)}}}({ctx:t,options:o}),s=function(e){const{ctx:n}=e;return{getInstanceSize:function(e){const t=n.document.getInstance(e);if(t&&void 0!==t.size)return JSON.parse(JSON.stringify(t.size))},updateInstanceSize:function(e,t){n.dispatch({type:"setInstanceSize",payload:{instanceId:e,size:t}})},getContainerLayout:function(e){const t=n.document.getInstance(e);return t&&void 0!==t.containerLayout?JSON.parse(JSON.stringify(t.containerLayout)):null},updateContainerLayout:function(e,t){n.dispatch({type:"setContainerLayout",payload:{instanceId:e,containerLayout:t}})},getLayoutBox:function(e){const t=n.document.getInstance(e);if(t&&void 0!==t.layoutBox)return JSON.parse(JSON.stringify(t.layoutBox))},updateLayoutBox:function(e,t){n.dispatch({type:"updateLayoutBox",payload:{instanceId:e,patch:t}})},getLayoutItem:function(e){const t=n.document.getInstance(e);if(t&&void 0!==t.layoutItem)return JSON.parse(JSON.stringify(t.layoutItem))},updateLayoutItem:function(e,t){n.dispatch({type:"updateLayoutItem",payload:{instanceId:e,patch:t}})},getRotation:function(e){const t=n.document.getInstance(e);if(!t)return 0;const o=t.rotation;return"number"==typeof o&&Number.isFinite(o)?o:0},updateRotation:function(e,t){n.dispatch({type:"updateRotation",payload:{instanceId:e,value:t}})},getInstanceOutletRect:function(e,n){if("undefined"==typeof document||"function"!=typeof document.querySelector)return null;const t=n??"default",o=""===t?"default":t,i=`[data-instance-id="${Qn(e)}"]`,a=`[data-hc-slot="${Qn(o)}"]`,r=document.querySelector(`${i} ${a}`);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null}}}({ctx:t}),d=function(e){const{ctx:n}=e;function t(){return JSON.parse(JSON.stringify(n.document.document.layout))}return{getLayoutConfig:t,updateCanvasSize:function(e){const o={...t().canvas,...e};n.dispatch({type:"updateLayout",payload:{patch:{canvas:o}}})},updateCanvasBackground:function(e){if(null===e)return void n.dispatch({type:"updateLayout",payload:{patch:{background:void 0}}});const o={...t().background??{},...e};n.dispatch({type:"updateLayout",payload:{patch:{background:o}}})},updateBehavior:function(e){const o={...t().behavior??{},...e};n.dispatch({type:"updateLayout",payload:{patch:{behavior:o}}})},setRootLayout:function(e){let t;if(null===e)t=null;else if("string"==typeof e)switch(e){case"free":t={mode:"free"};break;case"none":t={mode:"none"};break;case"split":t={mode:"split",direction:"horizontal",ratios:[.5,.5]};break;case"grid":t={mode:"grid",columns:[{mode:"fr",value:1},{mode:"fr",value:1}],rows:[{mode:"fr",value:1},{mode:"fr",value:1}]};break;case"flex":t={mode:"flex",direction:"row"};break;default:return void console.warn(`[hc-canvas/handle] setRootLayout: 未知 mode "${e}",忽略`)}else t=e;n.dispatch({type:"setRootLayout",payload:{rootLayout:t}})},setInteractionOptions:function(e){n.setInteractionOptions(e)},getEffectiveBehavior:function(){return{...n.effectiveBehavior.value}},resolveAsset:function(e){return n.resolveAsset(e)}}}({ctx:t}),l=function(e){const{ctx:n}=e;function t(){return n.document.document.layout.guides??{}}function o(e){n.dispatch({type:"updateLayout",payload:{patch:{guides:e}}})}return{setRulerVisible:function(e){const n=t();o({...n,ruler:{...n.ruler??{},visible:e}})},setGridVisible:function(e){const n=t();o({...n,grid:{...n.grid??{},visible:e}})},updateRulerConfig:function(e){const n=t();o({...n,ruler:{...n.ruler??{},...e}})},updateGridConfig:function(e){const n=t();o({...n,grid:{...n.grid??{},...e}})},addGuide:function(e){const n=t(),i=n.items??[],a=e.id??function(){var e;const n="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`g_${(null==(e=null==n?void 0:n.randomUUID)?void 0:e.call(n).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}();if(i.some(e=>e.id===a))return console.warn(`[hc-canvas/handle] addGuide: id "${a}" 已存在,忽略`),a;const r={id:a,axis:e.axis,position:e.position};return void 0!==e.locked&&(r.locked=e.locked),void 0!==e.label&&(r.label=e.label),o({...n,items:[...i,r]}),a},removeGuide:function(e){const n=t(),i=n.items??[];i.some(n=>n.id===e)&&o({...n,items:i.filter(n=>n.id!==e)})},updateGuide:function(e,n){const i=t(),a=i.items??[],r=a.findIndex(n=>n.id===e);if(r<0)return void console.warn(`[hc-canvas/handle] updateGuide: id "${e}" 不存在,忽略`);const{id:c,...s}=n,d={...a[r],...s},l=[...a];l[r]=d,o({...i,items:l})},getGuides:function(){return(t().items??[]).map(e=>({...e}))},clearGuides:function(){const e=t();e.items&&0!==e.items.length&&o({...e,items:[]})},getMouseCanvasPoint:function(){const e=n.mouseCanvasPoint.value;return e?{x:e.x,y:e.y}:null}}}({ctx:t}),u=function(e){const{ctx:n,recorder:t,viewportApi:o,guides:i}=e;function a(e,t){const o=n.document.getInstance(e);if(!o)return null;const i=(null==t?void 0:t.newInstanceId)??function(e){var n;const t="undefined"!=typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;return`${e}_${(null==(n=null==t?void 0:t.randomUUID)?void 0:n.call(t).replace(/-/g,"").slice(0,8))??Math.random().toString(36).slice(2,10)}`}(o.componentId);return n.dispatch({type:"duplicateInstance",payload:{instanceId:e,newInstanceId:i,...void 0!==(null==t?void 0:t.offset)?{offset:t.offset}:{}}}),n.document.getInstance(i)?i:null}const r=Object.freeze([{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]);function c(){const e=n.selection.selectedIds.value;if(0===e.length)return!1;for(const t of e){const e=n.document.getInstance(t);if(e&&!0!==(e.lockPosition??e.locked))return!0}return!1}function s(e,t,o){const i=o?10:1,a=n.selection.selectedIds.value;if(0===a.length)return;const r=!n.isBatching.value;r&&n.beginBatch();try{for(const o of a){const a=n.document.getInstance(o);if(!a||!0===(a.lockPosition??a.locked))continue;const r=jn(n,o);Vn(r)?n.dispatch({type:"moveInstance",payload:{instanceId:o,x:a.rect.x+e*i,y:a.rect.y+t*i}}):"undefined"!=typeof console&&"function"==typeof console.debug&&console.debug("[hc-canvas/handle] executeNudge: 拒绝 layout-managed 子 nudge",{instanceId:o,parentLayoutMode:r})}}finally{r&&n.endBatch(o?"arrow-move-large":"arrow-move")}}function d(e){const t=[...n.selection.selectedIds.value];if(0===t.length)return;const o=!n.isBatching.value;o&&n.beginBatch();try{for(const o of t)n.dispatch({type:"setInstanceLocked",payload:{instanceId:o,locked:e}})}finally{o&&n.endBatch(e?"lock-selection":"unlock-selection")}}function l(e){const t=n.selection.selectedIds.value;if(0===t.length)return;const o=n.document.document.instances;if(0===o.length)return;const i=o.map((e,n)=>({inst:e,origIdx:n})).sort((e,n)=>{const t=e.inst.zIndex??0,o=n.inst.zIndex??0;return t!==o?t-o:e.origIdx-n.origIdx}).map(e=>e.inst),a=new Set(t),r=[];for(let e=0;e<i.length;e++)a.has(i[e].instanceId)&&r.push(e);if(0===r.length)return;if(r.length===i.length)return;const c=r.map(e=>i[e]),s=i.filter(e=>!a.has(e.instanceId));let d;if("toFront"===e)d=[...s,...c];else if("toBack"===e)d=[...c,...s];else if("forward"===e){let e=r[r.length-1]+1;for(;e<i.length&&a.has(i[e].instanceId);)e++;if(e>=i.length)return;const n=i[e],t=s.indexOf(n);d=[...s.slice(0,t+1),...c,...s.slice(t+1)]}else{let e=r[0]-1;for(;e>=0&&a.has(i[e].instanceId);)e--;if(e<0)return;const n=i[e],t=s.indexOf(n);d=[...s.slice(0,t),...c,...s.slice(t)]}const l=[];for(let e=0;e<d.length;e++){const n=d[e];(n.zIndex??0)!==e&&l.push({id:n.instanceId,zIndex:e})}if(0===l.length)return;const u=!n.isBatching.value;u&&n.beginBatch();try{for(const e of l)n.dispatch({type:"updateInstance",payload:{instanceId:e.id,patch:{zIndex:e.zIndex}}})}finally{u&&n.endBatch(`z-order-${e}`)}}const u={undo:{execute:()=>t.undo(),canExecute:()=>t.canUndo.value},redo:{execute:()=>t.redo(),canExecute:()=>t.canRedo.value},deleteSelection:{execute:function(){const e=[...n.selection.selectedIds.value];if(0===e.length)return;const t=!n.isBatching.value;t&&n.beginBatch();try{for(const t of e)n.dispatch({type:"removeInstance",payload:{instanceId:t}})}finally{t&&n.endBatch("delete-selection")}},canExecute:()=>n.selection.selectedIds.value.length>0},duplicateSelection:{execute:function(){const e=[...n.selection.selectedIds.value];if(0===e.length)return;const t=[],o=!n.isBatching.value;o&&n.beginBatch();try{for(const n of e){const e=a(n);e&&t.push(e)}t.length>0&&n.dispatch({type:"selectAll",payload:{instanceIds:t}})}finally{o&&n.endBatch("duplicate-selection")}},canExecute:()=>n.selection.selectedIds.value.length>0},clearSelection:{execute:()=>n.dispatch({type:"clearSelection"}),canExecute:()=>n.selection.selectedIds.value.length>0},cancelInteraction:{execute:()=>n.dispatch({type:"clearSelection"}),canExecute:()=>!0},zoomIn:{execute:()=>o.zoomBy(.1),canExecute:()=>!0},zoomOut:{execute:()=>o.zoomBy(-.1),canExecute:()=>!0},zoom100:{execute:()=>o.zoomTo(1),canExecute:()=>!0},resetViewport:{execute:()=>o.resetViewport(),canExecute:()=>!0},fitToContent:{execute:()=>o.fitToContent(),canExecute:()=>null!==o.getContentBounds()},fitToSelection:{execute:()=>o.fitToSelection(),canExecute:()=>null!==o.getSelectionBounds()},fitToSelectionOrContent:{execute:()=>{o.getSelectionBounds()?o.fitToSelection():o.fitToContent()},canExecute:()=>null!==o.getSelectionBounds()||null!==o.getContentBounds()},nudgeSelection:{execute:e=>{const n=e??{dx:0,dy:0};s(n.dx,n.dy,!1)},canExecute:c},nudgeSelectionLarge:{execute:e=>{const n=e??{dx:0,dy:0};s(n.dx,n.dy,!0)},canExecute:c},lockSelection:{execute:()=>d(!0),canExecute:()=>n.selection.selectedIds.value.length>0},unlockSelection:{execute:()=>d(!1),canExecute:()=>n.selection.selectedIds.value.length>0},bringForward:{execute:()=>l("forward"),canExecute:()=>n.selection.selectedIds.value.length>0},sendBackward:{execute:()=>l("backward"),canExecute:()=>n.selection.selectedIds.value.length>0},bringToFront:{execute:()=>l("toFront"),canExecute:()=>n.selection.selectedIds.value.length>0},sendToBack:{execute:()=>l("toBack"),canExecute:()=>n.selection.selectedIds.value.length>0},toggleGrid:{execute:function(){var e;const t=null==(e=n.document.document.layout.guides)?void 0:e.grid;i.setGridVisible(!(null==t?void 0:t.visible))},canExecute:()=>!0},toggleRuler:{execute:function(){var e;const t=null==(e=n.document.document.layout.guides)?void 0:e.ruler;i.setRulerVisible(!(null==t?void 0:t.visible))},canExecute:()=>!0}};function p(e,t){const o=null===t?null:JSON.parse(JSON.stringify(t));n.dispatch({type:"setComponentOverride",payload:{instanceId:e,override:o}})}function f(e,t){const o=e??"notEditingText";return"always"===o||("notEditingText"===o?!ft(t.target):"design"===o?!ft(t.target)&&!1!==n.effectiveBehavior.value.draggable:"hasSelection"===o&&!ft(t.target)&&n.selection.selectedIds.value.length>0)}return{duplicateInstance:a,getToolMode:function(){return n.toolMode.value},setToolMode:function(e){n.setToolMode(e)},setTemporaryToolMode:function(e){n.setTemporaryToolMode(e)},handleGetDefaultShortcuts:function(){return[{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]},executeShortcut:function(e){for(const n of r){if(!gt(n,e))continue;if(!f(n.when,e))continue;const t=u[n.command];return!!t&&!!t.canExecute()&&(t.execute(n.payload),!1!==n.preventDefault&&e.preventDefault(),!0)}return!1},executeCommand:function(e,n){const t=u[e];t?t.canExecute()&&t.execute(n):console.warn(`[hc-canvas/handle] executeCommand: 未知命令 "${e}"`)},canExecuteCommand:function(e){const n=u[e];return!!n&&n.canExecute()},getStaleComponentOverrides:function(){const e=n.document.document.componentOverrides??{},t=[];for(const o of n.document.document.instances){const n=e[o.instanceId];n&&n.baseVersionKey!==o.componentVersionKey&&t.push({instanceId:o.instanceId,baseVersionKey:n.baseVersionKey,currentVersionKey:o.componentVersionKey})}return t},setComponentOverride:p,discardComponentOverride:function(e){p(e,null)},getLayoutIssues:function(){return n.layoutIssues.value}}}({ctx:t,recorder:i,viewportApi:c,guides:l}),p=function(e){const{ctx:n,options:t}=e;function o(e){var o,i,a,r,c,s,d,l,u;const p=e.parentId||void 0;if(void 0===p)return e;const f=(null==(i=null==(o=n.document.getInstance(p))?void 0:o.containerLayout)?void 0:i.mode)??"none";if("flex"!==f&&"split"!==f&&"grid"!==f)return e;const g=e.layoutBox,h=void 0!==g,m=void 0!==g,v=null==(a=t.resolveContract)?void 0:a.call(t,e.componentVersionKey),y=null==(c=null==(r=null==v?void 0:v.layoutDecl)?void 0:r.sizing)?void 0:c.defaultChildSize,I=e.rect??{w:240,h:60},x=g??{x:0,y:0,width:I.w,height:I.h,widthMode:"px",heightMode:"px"},w=e=>{if(void 0!==e)return"hug"===e?"auto":e},b=h?x.widthMode:w(null==(s=null==y?void 0:y.width)?void 0:s.mode)??"fill",S=m?x.heightMode:w(null==(d=null==y?void 0:y.height)?void 0:d.mode)??"fill",k=h||void 0===(null==(l=null==y?void 0:y.width)?void 0:l.value)?x.width:y.width.value,B=m||void 0===(null==(u=null==y?void 0:y.height)?void 0:u.value)?x.height:y.height.value;return{...e,layoutBox:{...x,x:0,y:0,width:k,height:B,widthMode:b,heightMode:S}}}return{dispatchWithDefaults:function(e){if("addInstance"===e.type){const i=function(e){var n,o,i,a;if(void 0!==e.containerLayout)return e;const r=null==(n=t.resolveContract)?void 0:n.call(t,e.componentVersionKey);if(!r)return e;if(!("container"===(null==(o=r.layoutDecl)?void 0:o.role)||((null==(i=r.slotsDecl)?void 0:i.length)??0)>0))return e;const c=null==(a=r.layoutDecl)?void 0:a.defaultLayout;return void 0===c?e:{...e,containerLayout:JSON.parse(JSON.stringify(c))}}(e.payload.instance);return void n.dispatch({type:"addInstance",payload:{instance:o(i)}})}n.dispatch(e)}}}({ctx:t,options:o}),f=mt({ctx:t}),g=e.computed(()=>{const e=t.selection.selectedIds.value;if(0===e.length)return[];const n=new Set(e);return t.document.document.instances.filter(e=>n.has(e.instanceId))}),h=t.selection.selectedIds,m=e.readonly(h),v=e.readonly(t.isBatching),y=function(){let e=!1;const n=new Set,t=new Set,o=[];return{isDisposed:()=>e,addPendingReady(e){n.add(e)},removePendingReady(e){n.delete(e)},registerListenerOff(e){let n=!1;const o=()=>{n||(n=!0,t.delete(o),e())};return t.add(o),o},addDisposeCleanup(e){o.push(e)},markDisposed(){if(e)return;e=!0;const i=[...n];n.clear();for(const e of i)try{e.reject(new En)}catch(e){console.error("[hc-canvas/handle] pending ready rejection threw on dispose",e)}const a=[...t];t.clear();for(const e of a)try{e()}catch(e){console.error("[hc-canvas/handle] instance listener off threw on dispose",e)}for(const e of o)e()}}}(),{attachBindingDelegate:I,setBindingMode:x,getBindingMode:w,testBinding:b,invalidateDataSource:S,getDataSourceSnapshot:k,on:B,getInstanceReady:z,getInstanceRuntime:M,getCachedBySourceId:T,startTracing:C,stopTracing:L,getTraceBuffer:E}=function(e){const{lifecycle:t,currentCanvasId:o}=e;let i=null,a=null;return t.addDisposeCleanup(()=>{i=null,a=null}),{attachBindingDelegate:function(e,n){t.isDisposed()||(i=e,null===e?a=null:arguments.length>=2&&(a=n??null))},setBindingMode:function(e){null==i||i.setMode(e)},getBindingMode:function(){return(null==i?void 0:i.getMode())??"off"},testBinding:function(e,n){return(null==i?void 0:i.testBinding(e,n))??[]},invalidateDataSource:function(e){null==a||a.invalidate(e)},getDataSourceSnapshot:function(){return(null==a?void 0:a.getSnapshot())??{entries:[]}},on:function(e,a){if(t.isDisposed())return()=>{};if("instance:ready"===e||"instance:unmounted"===e){const i=e,r=a,c=n.onInstanceLifecycle(i,e=>{e.canvasId===o&&r(e.instanceId)});return t.registerListenerOff(c)}return i?i.on(e,a):()=>{}},getInstanceReady:function(e){return t.isDisposed()?Promise.reject(new En):"string"!=typeof e||0===e.length?Promise.reject(new TypeError("getInstanceReady: instanceId must be a non-empty string")):n.getInstance(e,o)?Promise.resolve():new Promise((i,a)=>{let r,c,s=!1;const d=()=>{s=!0;try{null==r||r()}catch{}c&&t.removePendingReady(c)};r=n.onInstanceLifecycle("instance:ready",n=>{s||n.canvasId===o&&n.instanceId===e&&(d(),i())}),c={off:r,reject:e=>{s||(d(),a(e))}},t.addPendingReady(c),!s&&n.getInstance(e,o)&&(d(),i())})},getInstanceRuntime:function(e){return t.isDisposed()?null:n.getInstance(e,o)},getCachedBySourceId:function(e,n){return null==a?void 0:a.getCachedBySourceId(e,n)},startTracing:function(e){null==i||i.startTracing(e)},stopTracing:function(){return(null==i?void 0:i.stopTracing())??[]},getTraceBuffer:function(){return(null==i?void 0:i.getTraceBuffer())??[]}}}({lifecycle:y,currentCanvasId:t.canvasId});return y.addDisposeCleanup(()=>i.dispose()),{dispatch:e=>p.dispatchWithDefaults(e),beginBatch:()=>t.beginBatch(),endBatch:e=>t.endBatch(e),isBatching:v,getSnapshot:()=>JSON.parse(JSON.stringify(t.document.document)),selectedIds:m,selectedInstances:g,freeSplitSelection:e.readonly(t.selection.freeSplitSelection),selectFreeSplitLeaf:(e,n)=>t.selection.selectFreeSplitLeaf(e,n),selectFreeSplitDivider:(e,n,o)=>t.selection.selectFreeSplitDivider(e,n,o),clearFreeSplitSelection:()=>t.selection.clearFreeSplitSelection(),viewport:t.viewport,clientToCanvasPoint:a.clientToCanvasPoint,getInstanceAtClientPoint:a.getInstanceAtClientPoint,getDropTarget:a.getDropTarget,getFreeSplitDropTarget:a.getFreeSplitDropTarget,duplicateInstance:u.duplicateInstance,undo:i.undo,redo:i.redo,canUndo:i.canUndo,canRedo:i.canRedo,undoStackSize:i.undoStackSize,redoStackSize:i.redoStackSize,clearHistory:i.clear,getLayoutConfig:d.getLayoutConfig,updateCanvasSize:d.updateCanvasSize,updateCanvasBackground:d.updateCanvasBackground,updateBehavior:d.updateBehavior,setInteractionOptions:d.setInteractionOptions,getEffectiveBehavior:d.getEffectiveBehavior,setRootLayout:d.setRootLayout,getInstanceTree:r.getInstanceTree,getInstanceList:r.getInstanceList,getInstance:r.getInstanceById,getSelectedPath:r.getSelectedPath,getBreadcrumb:r.getBreadcrumb,focusInstance:r.focusInstance,scrollToInstance:r.scrollToInstance,moveInstanceInTree:r.moveInstanceInTree,canReparent:r.canReparent,cannotReparentEvent:r.cannotReparentEvent,cannotDragLayoutManagedChildEvent:t.cannotDragLayoutManagedChildEvent,resolveAsset:d.resolveAsset,getViewportState:c.getViewportState,getVisibleBounds:c.getVisibleBounds,getCanvasBounds:c.getCanvasBounds,getContentBounds:c.getContentBounds,getSelectionBounds:c.getSelectionBounds,getInstanceBounds:c.getInstanceBounds,panBy:c.panBy,panTo:c.panTo,zoomTo:c.zoomTo,zoomBy:c.zoomBy,zoomToPoint:c.zoomToPoint,resetViewport:c.resetViewport,fitToContent:c.fitToContent,fitToSelection:c.fitToSelection,scrollToRect:c.scrollToRect,toolMode:t.toolMode,getToolMode:u.getToolMode,setToolMode:u.setToolMode,setTemporaryToolMode:u.setTemporaryToolMode,getDefaultShortcuts:u.handleGetDefaultShortcuts,executeShortcut:u.executeShortcut,executeCommand:u.executeCommand,canExecuteCommand:u.canExecuteCommand,getStaleComponentOverrides:u.getStaleComponentOverrides,setComponentOverride:u.setComponentOverride,discardComponentOverride:u.discardComponentOverride,getLayoutIssues:u.getLayoutIssues,setRulerVisible:l.setRulerVisible,setGridVisible:l.setGridVisible,updateRulerConfig:l.updateRulerConfig,updateGridConfig:l.updateGridConfig,addGuide:l.addGuide,removeGuide:l.removeGuide,updateGuide:l.updateGuide,getGuides:l.getGuides,clearGuides:l.clearGuides,getMouseCanvasPoint:l.getMouseCanvasPoint,getInstanceSize:s.getInstanceSize,updateInstanceSize:s.updateInstanceSize,getContainerLayout:s.getContainerLayout,updateContainerLayout:s.updateContainerLayout,getInstanceOutletRect:s.getInstanceOutletRect,getLayoutBox:s.getLayoutBox,updateLayoutBox:s.updateLayoutBox,getLayoutItem:s.getLayoutItem,updateLayoutItem:s.updateLayoutItem,getRotation:s.getRotation,updateRotation:s.updateRotation,setBindingMode:x,getBindingMode:w,testBinding:b,on:B,attachBindingDelegate:I,invalidateDataSource:S,getDataSourceSnapshot:k,getCachedBySourceId:T,getInstanceReady:z,getInstanceRuntime:M,startTracing:C,stopTracing:L,getTraceBuffer:E,freeSplit:f,dispose:function(){y.markDisposed()}}}const yt=Symbol("hc:canvas:reparent-bridge");function It(e){return"preview"===e||"runtime"===e?"runtime":"off"}const xt=(e,n)=>{const t=e.__vccOpts||e;for(const[e,o]of n)t[e]=o;return t},wt=xt(e.defineComponent({__name:"CanvasStage",setup(n){const t=Me(),o=e.ref(null);let i=null;const a=e.computed(()=>{const{scale:e,panX:n,panY:o}=t.viewport.state;return`translate(${n}px, ${o}px) scale(${e})`});function r(){const e=o.value;if(!e)return;const n=e.getBoundingClientRect();t.setMeasuredStageSize({w:n.width,h:n.height})}return e.onMounted(()=>{e.nextTick(r),"undefined"!=typeof ResizeObserver&&o.value&&(i=new ResizeObserver(r),i.observe(o.value)),window.addEventListener("resize",r)}),e.onBeforeUnmount(()=>{null==i||i.disconnect(),i=null,window.removeEventListener("resize",r)}),(n,t)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"stageEl",ref:o,class:"hc-canvas-stage","data-hc-stage":""},[e.createElementVNode("div",{class:"hc-canvas-stage__world","data-hc-stage-world":"",style:e.normalizeStyle({transform:a.value,transformOrigin:"0 0"})},[e.renderSlot(n.$slots,"default",{},void 0,!0)],4)],512))}}),[["__scopeId","data-v-825e0ee8"]]),bt=["data-mode"],St=e.defineComponent({__name:"RuntimeLayer",props:{componentSourceMap:{},mode:{default:"design"},schedulerOptions:{},canvasId:{}},setup(n){const t=Me(),o=e.computed(()=>t.document.document);return(i,a)=>(e.openBlock(),e.createElementBlock("div",{class:"hc-runtime-layer","data-hc-runtime-layer":"","data-mode":n.mode,style:e.normalizeStyle({position:"absolute",top:0,left:0,pointerEvents:e.unref(t).effectiveBehavior.value.selectable?"none":"auto"})},[e.createVNode(wn,{document:o.value,"component-source-map":n.componentSourceMap,"scheduler-options":n.schedulerOptions,"canvas-id":n.canvasId},null,8,["document","component-source-map","scheduler-options","canvas-id"])],12,bt))}}),kt=.05;function Bt(e,n,t,o=0){if(!n||n.length<2)return[];if(e.w<=0||e.h<=0)return[];const i=n.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),a=i.reduce((e,n)=>e+n,0);if(a<=0)return[];const r=i.length-1,c=Math.max(0,o)*r,s="horizontal"===t?e.w:e.h,d=Math.max(0,s-c);if(d<=0)return[];const l=o>0?o:8,u=[];let p=0;for(let n=0;n<r;n++){p+=i[n]/a*d;const r=p+n*o+o/2;let c;c="horizontal"===t?{x:e.x+r-l/2,y:e.y,w:l,h:e.h}:{x:e.x,y:e.y+r-l/2,w:e.w,h:l},u.push({index:n,rect:c,direction:t})}return u}function zt(e,n,t,o,i=0){if(!e||n<0||n>=e.length-1)return e.slice();const a=e.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),r=a[n],c=a[n+1],s=r+c;if(s<=0)return a;const d=a.length-1,l=Math.max(0,i)*d,u=Math.max(0,o-l);if(u<=0)return a;const p=a.reduce((e,n)=>e+n,0);if(p<=0)return a;const f=t/u*p,g=kt*p;let h=r+f,m=c-f;h<g&&(h=g,m=s-g),m<g&&(m=g,h=s-g);const v=a.slice();return v[n]=h,v[n+1]=m,v}function Mt(n){const t=e.reactive({status:"idle",parentId:null,dividerIndex:null,startRatios:null,childIds:null,parentAxisPx:0,startPt:null,direction:null,gap:0}),o=e.computed(()=>"active"===t.status);function i(){t.status="idle",t.parentId=null,t.dividerIndex=null,t.startRatios=null,t.childIds=null,t.parentAxisPx=0,t.startPt=null,t.direction=null,t.gap=0}return{drag:t,isDragging:o,handleSplitDividerStart:function(e){if(!e.parentId)return{startTracking:!1};if(e.dividerIndex<0)return{startTracking:!1};if(!e.startRatios||e.startRatios.length<2)return{startTracking:!1};if(!e.childIds||e.childIds.length<=e.dividerIndex+1||!e.childIds[e.dividerIndex]||!e.childIds[e.dividerIndex+1])return{startTracking:!1};const o=n.document.getInstance(e.parentId);return o&&o.containerLayout&&"split"===o.containerLayout.mode?(t.status="active",t.parentId=e.parentId,t.dividerIndex=e.dividerIndex,t.startRatios=e.startRatios.slice(),t.childIds=e.childIds.slice(),t.parentAxisPx=e.parentAxisPx,t.startPt={...e.canvasPt},t.direction=e.direction,t.gap=e.gap,n.beginBatch(),{startTracking:!0}):{startTracking:!1}},handleSplitDividerMove:function(e){var o,i;if("active"!==t.status)return;if(!(t.startPt&&t.startRatios&&t.childIds&&t.direction&&null!==t.dividerIndex))return;const a=n.document.getInstance(t.parentId);if(!a||!a.containerLayout||"split"!==a.containerLayout.mode)return;const r="horizontal"===t.direction?e.x-t.startPt.x:e.y-t.startPt.y,c=zt(t.startRatios,t.dividerIndex,r,t.parentAxisPx,t.gap),s=t.dividerIndex,d=t.childIds[s],l=t.childIds[s+1];if(!d||!l)return;const u=c[s],p=c[s+1],f=n.document.getInstance(d),g=n.document.getInstance(l),h=null==(o=null==f?void 0:f.layoutItem)?void 0:o.ratio,m=null==(i=null==g?void 0:g.layoutItem)?void 0:i.ratio;h===u&&m===p||(n.dispatch({type:"updateLayoutItem",payload:{instanceId:d,patch:{ratio:u}}}),n.dispatch({type:"updateLayoutItem",payload:{instanceId:l,patch:{ratio:p}}}))},handleSplitDividerEnd:function(){"active"===t.status&&(n.endBatch("split-divider-drag"),i())},cancelSplitDividerDrag:function(){"active"===t.status&&n.endBatch("split-divider-cancel"),i()}}}function Tt(e,n){const t=Math.min(e.x,n.x),o=Math.min(e.y,n.y);return{x:t,y:o,w:Math.max(e.x+e.w,n.x+n.w)-t,h:Math.max(e.y+e.h,n.y+n.h)-o}}function Ct(e,n){if("leaf"===e.type)return n(e.leafId);let t=null;for(const o of e.children){const e=Ct(o,n);e&&(t=t?Tt(t,e):e)}return t}function Lt(e,n){return Ct(e,n)}function Et(e,n,t={}){const o=t.thickness??8,i=[],a=e=>{if("leaf"===e.type)return;const t=e.children.map(e=>Ct(e,n));for(let n=0;n<e.children.length-1;n++){const a=t[n],r=t[n+1];if(a&&r)if("row"===e.dir){const t=(a.x+a.w+r.x)/2,c=Math.min(a.y,r.y),s=Math.max(a.y+a.h,r.y+r.h);i.push({nodeId:e.nodeId,dividerIndex:n,direction:"horizontal",rect:{x:t-o/2,y:c,w:o,h:s-c}})}else{const t=(a.y+a.h+r.y)/2,c=Math.min(a.x,r.x),s=Math.max(a.x+a.w,r.x+r.w);i.push({nodeId:e.nodeId,dividerIndex:n,direction:"vertical",rect:{x:c,y:t-o/2,w:s-c,h:o}})}}e.children.forEach(a)};return a(e),i}function Dt(e,n,t,o,i={}){const{snap:a=!1,snapFractions:r=[.5],snapThreshold:c=.04,minRatioFraction:s=kt,minPx:d=0}=i,l=e.map(e=>({...e}));if(n<0||n>=e.length-1)return l;const u=e[n],p=e[n+1];if("px"===u.mode&&"px"===p.mode){const e=u.value+p.value,o=Math.max(d,u.min??0),i=Math.max(d,p.min??0),a=Math.min(u.max??1/0,e-i);let r=u.value+t;return r=Math.max(o,Math.min(a,r)),l[n]={...u,value:r},l[n+1]={...p,value:e-r},l}if("ratio"===u.mode&&"ratio"===p.mode){const i=u.value+p.value;if(i<=0||o<=0)return l;const d=e.reduce((e,n)=>e+("ratio"===n.mode?n.value:0),0);if(d<=0)return l;const f=t/o*d;let g=u.value+f,h=p.value-f;const m=s*i;if(g<m&&(g=m,h=i-m),h<m&&(h=m,g=i-m),a){const e=g/i;for(const n of r)if(Math.abs(e-n)<=c){g=n*i,h=(1-n)*i;break}}return l[n]={...u,value:g},l[n+1]={...p,value:h},l}if("px"===u.mode){let e=u.value+t;e=Math.max(Math.max(d,u.min??0),Math.min(u.max??1/0,e)),l[n]={...u,value:e}}else{let e=p.value-t;e=Math.max(Math.max(d,p.min??0),Math.min(p.max??1/0,e)),l[n+1]={...p,value:e}}return l}function Pt(e,n,t={}){const o=t.edgeZonePx??12,{x:i,y:a,w:r,h:c}=e;if(n.x<i||n.x>i+r||n.y<a||n.y>a+c)return null;const s=n.x-i,d=i+r-n.x,l=n.y-a,u=a+c-n.y,p=Math.min(s,d,l,u);return p>o?null:p===s?{edge:"left"}:p===d?{edge:"right"}:p===l?{edge:"top"}:{edge:"bottom"}}function Rt(e,n,t){const{x:o,y:i,w:a,h:r}=e;let c;return c="left"===n?(t.x-o)/a:"right"===n?(o+a-t.x)/a:"top"===n?(t.y-i)/r:(i+r-t.y)/r,Math.max(.05,Math.min(.95,c))}function $t(e,n,t){const o=ie(e,n);if(!o)return null;const i=o.children[t],a=o.children[t+1];return i&&a?"leaf"===i.type&&null===i.instanceId?i.leafId:"leaf"===a.type&&null===a.instanceId?a.leafId:null:null}function Ot(e,n){const t=e.document.getInstance(n),o=null==t?void 0:t.containerLayout;return o&&"free-split"===o.mode?o:null}function Ft(n){const t=mt({ctx:n}),o=e.reactive({status:"idle",containerId:null,nodeId:null,dividerIndex:null,startSizes:null,branchAxisPx:0,startPt:null,direction:null,snap:!1}),i=e.computed(()=>"active"===o.status);function a(){o.status="idle",o.containerId=null,o.nodeId=null,o.dividerIndex=null,o.startSizes=null,o.branchAxisPx=0,o.startPt=null,o.direction=null,o.snap=!1}return{resizeDrag:o,isResizing:i,handleResizeStart:function(e){if(!e.containerId||e.dividerIndex<0)return{startTracking:!1};if(!e.startSizes||e.startSizes.length<2)return{startTracking:!1};if(e.dividerIndex>=e.startSizes.length-1)return{startTracking:!1};const t=Ot(n,e.containerId);if(!t)return{startTracking:!1};const i=ie(t.root,e.nodeId);return i&&i.sizes.length===e.startSizes.length?(o.status="active",o.containerId=e.containerId,o.nodeId=e.nodeId,o.dividerIndex=e.dividerIndex,o.startSizes=e.startSizes.map(e=>({...e})),o.branchAxisPx=e.branchAxisPx,o.startPt={...e.canvasPt},o.direction=e.direction,o.snap=e.snap??!1,n.beginBatch(),{startTracking:!0}):{startTracking:!1}},handleResizeMove:function(e){if("active"!==o.status)return;if(!(o.startPt&&o.startSizes&&o.direction&&null!==o.dividerIndex&&o.containerId&&o.nodeId))return;const i=Ot(n,o.containerId);if(!i)return;const a="horizontal"===o.direction?e.x-o.startPt.x:e.y-o.startPt.y,r=Dt(o.startSizes,o.dividerIndex,a,o.branchAxisPx,{snap:o.snap}),c=ie(i.root,o.nodeId);c&&function(e,n){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t].mode!==n[t].mode||e[t].value!==n[t].value)return!1;return!0}(c.sizes,r)||t.resize(o.containerId,o.nodeId,r)},handleResizeEnd:function(){"active"===o.status&&(n.endBatch("free-split-resize"),a())},cancelResize:function(){"active"===o.status&&n.endBatch("free-split-resize-cancel"),a()},requestSplit:function(e,o,i,a){if(!Ot(n,e))return null;const r=t.split(e,o,i,a),c=Ot(n,e);return c&&oe(c.root,r.leafId)?r:null},requestMerge:function(e,o){Ot(n,e)&&t.merge(e,o)},requestDelete:function(e,o){const i=Ot(n,e);if(!i)return;const a=oe(i.root,o);if(a){n.beginBatch();try{null!==a.instanceId&&t.clear(e,o),t.merge(e,o)}finally{n.endBatch("free-split-delete-region")}}},requestSwap:function(e,o,i){o!==i&&Ot(n,e)&&t.swap(e,o,i)}}}function At(e){return!0===(e.lockPosition??e.locked)}function Nt(e){return!0===(e.lockSize??e.locked)}function jt(e){return At(e)||Nt(e)}const Vt=["data-mode"],qt=["data-selection-box","data-locked","data-placement"],_t=["data-lock-badge"],Kt=["data-resize-handle","data-resize-instance","onPointerdown"],Jt=["data-hc-divider-direction","data-hc-divider-index","data-hc-parent-id","data-hc-divider-dragging","onPointerdown"],Ut=["data-hc-fs-leaf","data-hc-fs-leaf-container","onPointerdown"],Ht={key:0,class:"hc-fs-leaf-empty"},Xt=["onPointerdown"],Yt=["onClick"],Gt=["onClick"],Wt=["onClick"],Qt=["data-hc-fs-divider-direction","data-hc-fs-divider-node","data-hc-fs-divider-index","data-hc-fs-container-id","data-hc-fs-divider-dragging","onPointerdown","onDblclick"],Zt=["onClick"],eo=["data-axis","data-kind"],no=["data-hc-reparent-state"],to=["data-hc-reparent-ghost-reason"],oo={key:0,"data-hc-reparent-ghost-reason-chip":"",style:{flex:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"10px",lineHeight:"14px",padding:"0 4px",borderRadius:"2px",background:"rgba(0, 0, 0, 0.25)",color:"#fff",whiteSpace:"nowrap"}},io=xt(e.defineComponent({__name:"InteractionLayer",props:{mode:{default:"design"}},emits:["cannot-drag-slot-child","cannot-drag-layout-managed-child"],setup(n,{emit:t}){const o=t,i=Me(),a=Wn(i,{getRoot:()=>Q(),getDomBox:e=>{const n=Jn(e,Q(),i.viewport);return n?0===n.w&&0===n.h?null:n:null}}),r=Mt(i),c=Ft(i),s=e.inject(yt,null);e.watch(()=>a.cannotDragSlotChildEvent.value,e=>{e&&o("cannot-drag-slot-child",{instanceId:e.instanceId,parentId:e.parentId})},{flush:"sync"}),e.watch(()=>a.cannotDragLayoutManagedChildEvent.value,e=>{e&&o("cannot-drag-layout-managed-child",{instanceId:e.instanceId,parentId:e.parentId,parentLayoutMode:e.parentLayoutMode})},{flush:"sync"});const d=e.ref(null);let l=null;const u=e.computed(()=>{const e=new Set(i.selection.selectedIds.value);return i.document.document.instances.filter(n=>e.has(n.instanceId)&&!n.hidden)}),p=e.computed(()=>i.measuredCanvasSize.value),f=e.shallowRef({}),g=e.ref(0);function h(){const e=Q(),n={};for(const t of u.value)n[t.instanceId]=Jn(t.instanceId,e,i.viewport);f.value=n,g.value++}let m=null;function v(){"undefined"!=typeof requestAnimationFrame?null===m&&(m=requestAnimationFrame(()=>{m=null,h()})):h()}let y=null;function I(){y=null,h(),(a.isResizing.value||a.isDragging.value||r.isDragging.value||c.isResizing.value)&&(y=requestAnimationFrame(I))}function x(e){const n=f.value[e.instanceId];if(n)return n;const t=Jn(e.instanceId,Q(),i.viewport);if(t&&(t.w>0||t.h>0))return t;const o=e.layoutBox;return o?{x:o.x,y:o.y,w:o.width,h:o.height}:{x:e.rect.x,y:e.rect.y,w:e.rect.w,h:e.rect.h}}e.watch(()=>i.selection.selectedIds.value,()=>{v()},{flush:"post",deep:!0}),e.watch(()=>i.viewport.scale.value,()=>v()),e.watch(()=>[i.viewport.panX.value,i.viewport.panY.value],()=>v()),e.watch(()=>u.value.map(e=>{const n=e.layoutBox;return n?`${n.x}|${n.y}|${n.width}|${n.height}|${n.widthMode}|${n.heightMode}`:""}),()=>v(),{flush:"post",deep:!0}),e.watch(()=>u.value.map(e=>{const n=e.containerLayout;return n&&"free-split"===n.mode?JSON.stringify(n):""}),()=>v(),{flush:"post",deep:!0}),e.watch(()=>a.isResizing.value,e=>{e&&null===y&&(y=requestAnimationFrame(I))}),e.watch(()=>a.isDragging.value,e=>{e&&null===y&&(y=requestAnimationFrame(I))}),e.watch(()=>r.isDragging.value,e=>{e&&null===y&&(y=requestAnimationFrame(I))}),e.watch(()=>c.isResizing.value,e=>{e&&null===y&&(y=requestAnimationFrame(I))}),e.onMounted(()=>{v()});const w=e.computed(()=>u.value.map(e=>({instance:e,box:x(e)}))),b=e.computed(()=>{var e,n;if(!i.effectiveBehavior.value.resizable)return[];const t=[];for(const o of w.value){const a=o.instance;if(!0===(a.lockSize??a.locked))continue;if(!o.box)continue;const r=jn(i,a.instanceId),{x:c,y:s,w:d,h:l}=o.box,u=[{handle:"nw",cx:c,cy:s,cursor:"nwse-resize"},{handle:"n",cx:c+d/2,cy:s,cursor:"ns-resize"},{handle:"ne",cx:c+d,cy:s,cursor:"nesw-resize"},{handle:"e",cx:c+d,cy:s+l/2,cursor:"ew-resize"},{handle:"se",cx:c+d,cy:s+l,cursor:"nwse-resize"},{handle:"s",cx:c+d/2,cy:s+l,cursor:"ns-resize"},{handle:"sw",cx:c,cy:s+l,cursor:"nesw-resize"},{handle:"w",cx:c,cy:s+l/2,cursor:"ew-resize"}],p=null==(e=a.layoutBox)?void 0:e.widthMode,f=null==(n=a.layoutBox)?void 0:n.heightMode,g=u.filter(e=>Kn(r,e.handle,p,f));for(const e of g)t.push({instanceId:a.instanceId,handle:e.handle,left:e.cx-4,top:e.cy-4,cursor:e.cursor})}return t});function S(e,n,t){return"percent"===n?`${Math.round(t)}%`:"fill"===n?"fill":"auto"===n?"auto":String(Math.round(e))}const k=e.computed(()=>{if(!a.isResizing.value)return null;const e=a.resize.instanceId;if(!e)return null;const n=i.document.getInstance(e);if(!n)return null;const t=x(n);if(!t)return null;const o=n.layoutBox,r=S(t.w,null==o?void 0:o.widthMode,(null==o?void 0:o.width)??t.w),c=S(t.h,null==o?void 0:o.heightMode,(null==o?void 0:o.height)??t.h);return{x:t.x,y:t.y,w:t.w,h:t.h,wText:r,hText:c}}),B={nw:"nwse-resize",se:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",n:"ns-resize",s:"ns-resize",w:"ew-resize",e:"ew-resize"};function M(e){var n;const t=[],o=[];for(const a of i.document.document.instances)a.parentId===e&&void 0===a.slot&&(t.push(a.instanceId),o.push(null==(n=a.layoutItem)?void 0:n.ratio));return{ids:t,ratios:o}}const T=e.computed(()=>{var e,n;const t=new Set;for(const o of u.value)if("split"===(null==(e=o.containerLayout)?void 0:e.mode)&&t.add(o.instanceId),o.parentId){const e=i.document.getInstance(o.parentId);"split"===(null==(n=null==e?void 0:e.containerLayout)?void 0:n.mode)&&t.add(e.instanceId)}if(0===t.size)return[];const o=[];for(const e of t){const n=i.document.getInstance(e);if(!n)continue;const t=n.containerLayout;if(!t||"split"!==t.mode)continue;const a=H(e)??x(n);if(!a)continue;const r=t,c=r.direction,s=r.gap??0,{ids:d,ratios:l}=M(e),u=z(r.ratios??[],l),p=Bt(a,u,c,s);0!==p.length&&o.push({parentId:e,direction:c,gap:s,effectiveRatios:u,childIds:d,parentBox:a,dividers:p})}return o});function C(e){var n;return"undefined"!=typeof globalThis&&(null==(n=globalThis.CSS)?void 0:n.escape)?globalThis.CSS.escape(e):e.replace(/["\\]/g,e=>`\\${e}`)}function L(e){const n=i.document.getInstance(e),t=null==n?void 0:n.containerLayout;return t&&"free-split"===t.mode?t:null}function E(e,n){const t=Q();if(!t)return null;const o=Fn(t,`[data-hc-leaf-container="${C(e)}"][data-hc-leaf="${C(n)}"]`);if(!(o&&o instanceof HTMLElement))return null;const i=U(o);return i&&0===i.w&&0===i.h?null:i}const D=e.computed(()=>{if(!i.freeSplitEnabled.value)return[];g.value;const e=[];for(const n of u.value){const t=L(n.instanceId);if(!t)continue;const o=n.instanceId,i=Et(t.root,e=>E(o,e));if(0===i.length)continue;const a=i.map(e=>({...e,mergeTargetLeafId:$t(t.root,e.nodeId,e.dividerIndex)}));e.push({containerId:o,dividers:a})}return e}),P=e.computed(()=>{if(!i.freeSplitEnabled.value)return[];g.value;const e=[];for(const n of u.value){const t=L(n.instanceId);if(!t)continue;const o=n.instanceId,i=!0===t.structureLocked,a=re(t.root);for(const n of a){const t=E(o,n.leafId);if(!t)continue;const r=!i&&!0!==n.locked;e.push({containerId:o,leafId:n.leafId,rect:t,isEmpty:null===n.instanceId,canSplit:r,canDelete:r&&a.length>1,canMove:null!==n.instanceId&&a.length>1})}}return e}),R=e.reactive({active:!1,containerId:null,sourceLeafId:null,targetLeafId:null});function $(e){const n=R.containerId,t=Q();if(!n||!t)return null;const o=Yn({x:e.clientX,y:e.clientY},t,i.viewport);for(const e of P.value){if(e.containerId!==n||e.leafId===R.sourceLeafId)continue;const t=e.rect;if(o.x>=t.x&&o.x<=t.x+t.w&&o.y>=t.y&&o.y<=t.y+t.h)return e.leafId}return null}function O(e){R.active&&(R.targetLeafId=$(e))}function F(){window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",N),window.removeEventListener("keydown",le)}function A(){R.active=!1,R.containerId=null,R.sourceLeafId=null,R.targetLeafId=null}function N(e){F();const n=R.containerId,t=R.sourceLeafId,o=R.active?$(e):null;A(),n&&t&&o&&o!==t&&c.requestSwap(n,t,o)}function j(e,n,t){c.requestSplit(e,n,t,.5)}const V=e.reactive({active:!1,containerId:null,leafId:null,edge:null,leafRect:null,startPt:null});function q(){V.active=!1,V.containerId=null,V.leafId=null,V.edge=null,V.leafRect=null,V.startPt=null}const _=e.computed(()=>a.isResizing.value&&a.resize.handle?B[a.resize.handle]:r.isDragging.value?"horizontal"===r.drag.direction?"ew-resize":"ns-resize":c.isResizing.value?"horizontal"===c.resizeDrag.direction?"ew-resize":"ns-resize":a.isDragging.value?"grabbing":"hand"===i.toolMode.value?ne?"grabbing":"grab":"marquee"===i.toolMode.value?"crosshair":"default"),K=e.shallowRef(null);function J(){if(!s)return!1;if(!a.isDragging.value)return!1;if(1!==a.drag.startRects.size)return!1;const e=Array.from(a.drag.startRects.keys())[0],n=i.document.getInstance(e);return!(!n||void 0!==n.placement&&"canvas"!==n.placement&&"absolute"!==n.placement||!0===(n.lockPosition??n.locked)||n.hidden)}function U(e){const n=Q();if(!n)return null;const t=e.getBoundingClientRect(),o=n.getBoundingClientRect(),a=i.viewport.toCanvasPoint({x:t.left-o.left,y:t.top-o.top}),r=i.viewport.toCanvasPoint({x:t.right-o.left,y:t.bottom-o.top});return{x:a.x,y:a.y,w:Math.max(0,r.x-a.x),h:Math.max(0,r.y-a.y)}}function H(e){var n;const t=Q();if(!t)return null;const o=Fn(t,`[data-instance-id="${("undefined"!=typeof globalThis&&(null==(n=globalThis.CSS)?void 0:n.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`))(e)}"] [data-hc-slot="default"]`);return o&&o instanceof HTMLElement?U(o):null}let X=null,Y=null;function G(e){if(!J()||!s)return void(null!==K.value&&(K.value=null));const n=Array.from(a.drag.startRects.keys())[0],t=s.getDropTarget(e,{excludeInstanceId:n});if(!t)return void(null!==K.value&&(K.value=null));const o=i.document.getInstance(n);if(o&&o.parentId===t.parentId&&(o.slot??"default")===(t.slot||"default"))return void(null!==K.value&&(K.value=null));const r=U(t.outletEl);if(!r)return void(null!==K.value&&(K.value=null));const c={parentId:t.parentId,slot:t.slot},d=s.canReparent(n,c);K.value={rect:r,target:t,result:d}}const W=e.computed(()=>K.value);function Q(){return l||(d.value?(l=d.value.closest("[data-hc-stage]"),l):null)}function Z(e){const n=Q();if(!n)return;const t=Yn({x:e.clientX,y:e.clientY},n,i.viewport);i.setMouseCanvasPoint(t)}function ee(){i.setMouseCanvasPoint(null)}let ne=null;function te(e){if(0!==e.button)return;const n=Q();if(!n)return;if("hand"===i.toolMode.value)return ne={clientX:e.clientX,clientY:e.clientY,panX:i.viewport.panX.value,panY:i.viewport.panY.value},window.addEventListener("pointermove",oe),window.addEventListener("pointerup",ae),void e.preventDefault();const t=Yn({x:e.clientX,y:e.clientY},n,i.viewport),{startTracking:o}=a.handlePointerDown(t,{shift:e.shiftKey,ctrl:e.ctrlKey,meta:e.metaKey});o&&(ce(),e.preventDefault())}function oe(e){if(!ne)return;const n=e.clientX-ne.clientX,t=e.clientY-ne.clientY;i.viewport.setPan(ne.panX+n,ne.panY+t)}function ae(){ne=null,window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",ae)}function ce(){window.addEventListener("pointermove",se),window.addEventListener("pointerup",de),window.addEventListener("keydown",le)}function se(e){const n=Q();if(!n)return;const t=Yn({x:e.clientX,y:e.clientY},n,i.viewport);var o;a.handlePointerMove(t),r.handleSplitDividerMove(t),r.isDragging.value&&v(),c.handleResizeMove(t),c.isResizing.value&&v(),o={x:e.clientX,y:e.clientY},X=o,"undefined"!=typeof requestAnimationFrame?null===Y&&(Y=requestAnimationFrame(()=>{Y=null,X&&G(X)})):G(o)}function de(e){if(r.isDragging.value)return r.handleSplitDividerEnd(),void ue();if(c.isResizing.value)return c.handleResizeEnd(),void ue();if(V.active){const{containerId:n,leafId:t,edge:o,leafRect:a,startPt:r}=V;if(q(),ue(),!(n&&t&&o&&a&&r))return;const s=Q(),d=e&&s?Yn({x:e.clientX,y:e.clientY},s,i.viewport):r;if(("left"===o?d.x-r.x:"right"===o?r.x-d.x:"top"===o?d.y-r.y:r.y-d.y)<3)return;const l=Rt(a,o,d);return void c.requestSplit(n,t,o,l)}e&&s&&J()&&G({x:e.clientX,y:e.clientY}),null!==Y&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(Y),Y=null);const n=K.value;if(n&&s){const e=Array.from(a.drag.startRects.keys())[0];return n.result.ok&&e?(a.cancelDrag(),s.moveInstanceInTree(e,{parentId:n.target.parentId,slot:n.target.slot})):a.cancelDrag(),K.value=null,void ue()}a.handlePointerUp(),ue()}function le(e){"Escape"===e.key&&(a.cancelResize(),a.cancelDrag(),a.cancelMarquee(),r.cancelSplitDividerDrag(),c.cancelResize(),q(),F(),A(),K.value=null,null!==Y&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(Y),Y=null),ae(),ue())}function ue(){window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",de),window.removeEventListener("keydown",le)}return e.onBeforeUnmount(()=>{a.cancelResize(),a.cancelDrag(),a.cancelMarquee(),r.cancelSplitDividerDrag(),c.cancelResize(),q(),F(),A(),K.value=null,ue(),ae(),null!==m&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(m),m=null),null!==y&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(y),y=null),null!==Y&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(Y),Y=null),X=null}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"layerEl",ref:d,class:"hc-interaction-layer","data-hc-interaction-layer":"","data-mode":n.mode,style:e.normalizeStyle({position:"absolute",top:0,left:0,width:p.value.w+"px",height:p.value.h+"px",pointerEvents:e.unref(i).effectiveBehavior.value.selectable?"auto":"none",cursor:_.value,zIndex:9999}),onPointerdown:te,onPointermove:Z,onPointerleave:ee},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(w.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sel-"+n.instance.instanceId},[n.box?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-selection-box","data-selection-box":n.instance.instanceId,"data-locked":e.unref(jt)(n.instance)?"true":"false","data-placement":n.instance.placement??"absolute",style:e.normalizeStyle({position:"absolute",left:n.box.x+"px",top:n.box.y+"px",width:n.box.w+"px",height:n.box.h+"px",border:"2px solid "+(e.unref(jt)(n.instance)?"#9ca3af":"#3b82f6"),boxSizing:"border-box",pointerEvents:"none",boxShadow:"0 0 0 1px rgba(59, 130, 246, 0.2)"})},null,12,qt)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(w.value.filter(n=>e.unref(jt)(n.instance)),n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"lock-"+n.instance.instanceId},[n.box?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-lock-badge","data-lock-badge":n.instance.instanceId,style:e.normalizeStyle({position:"absolute",left:n.box.x+n.box.w-18+"px",top:n.box.y+2+"px",width:"16px",height:"16px",background:"#9ca3af",color:"#fff",fontSize:"11px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",pointerEvents:"none",userSelect:"none"})},"🔒",12,_t)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.value,n=>(e.openBlock(),e.createElementBlock("div",{key:"rh-"+n.instanceId+"-"+n.handle,class:"hc-resize-handle","data-resize-handle":n.handle,"data-resize-instance":n.instanceId,style:e.normalizeStyle({position:"absolute",left:n.left+"px",top:n.top+"px",width:"8px",height:"8px",background:"#fff",border:"1px solid #3b82f6",boxSizing:"border-box",cursor:n.cursor,pointerEvents:"auto",zIndex:2}),onPointerdown:e=>function(e,n,t){if(0!==e.button)return;e.stopPropagation();const o=Q();if(!o)return;const r=Yn({x:e.clientX,y:e.clientY},o,i.viewport),{startTracking:c}=a.handleResizeStart(n,t,r);c&&(ce(),e.preventDefault())}(e,n.instanceId,n.handle)},null,44,Kt))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(T.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sd-parent-"+n.parentId},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.dividers,o=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"sd-"+n.parentId+"-"+o.index},[t.$slots["split-divider"]?e.renderSlot(t.$slots,"split-divider",{key:0,state:{parentId:n.parentId,dividerIndex:o.index,direction:o.direction,rect:o.rect,isDragging:e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index}},void 0,!0):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-split-divider","data-hc-divider-direction":o.direction,"data-hc-divider-index":o.index,"data-hc-parent-id":n.parentId,"data-hc-divider-dragging":e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index?"true":"false",style:e.normalizeStyle({position:"absolute",left:o.rect.x+"px",top:o.rect.y+"px",width:o.rect.w+"px",height:o.rect.h+"px",background:e.unref(r).isDragging.value&&e.unref(r).drag.parentId===n.parentId&&e.unref(r).drag.dividerIndex===o.index?"rgba(59, 130, 246, 0.6)":"rgba(59, 130, 246, 0.18)",cursor:"horizontal"===o.direction?"ew-resize":"ns-resize",pointerEvents:"auto",boxSizing:"border-box",zIndex:3}),onPointerdown:e=>function(e,n,t){if(0!==e.button)return;e.stopPropagation();const o=Q();if(!o)return;const a=i.document.getInstance(n);if(!a)return;const c=a.containerLayout;if(!c||"split"!==c.mode)return;const s=c,d=H(n)??x(a);if(!d)return;const l="horizontal"===s.direction?d.w:d.h,{ids:u,ratios:p}=M(n),f=z(s.ratios??[],p),g=Yn({x:e.clientX,y:e.clientY},o,i.viewport),{startTracking:h}=r.handleSplitDividerStart({parentId:n,dividerIndex:t,startRatios:f,childIds:u,parentAxisPx:l,direction:s.direction,gap:s.gap??0,canvasPt:g});h&&(ce(),e.preventDefault())}(e,n.parentId,o.index)},null,44,Jt))],64))),128))],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,n=>(e.openBlock(),e.createElementBlock("div",{key:"fsl-"+n.containerId+"-"+n.leafId,class:e.normalizeClass(["hc-fs-leaf-edge",{"is-empty":n.isEmpty,"is-drop-target":R.active&&R.containerId===n.containerId&&R.targetLeafId===n.leafId}]),"data-hc-fs-leaf":n.leafId,"data-hc-fs-leaf-container":n.containerId,style:e.normalizeStyle({position:"absolute",left:n.rect.x+"px",top:n.rect.y+"px",width:n.rect.w+"px",height:n.rect.h+"px",background:"transparent",pointerEvents:"auto",boxSizing:"border-box",zIndex:1}),onPointerdown:e=>function(e,n,t,o){if(0!==e.button)return;const a=Q();if(!a)return;const r=Yn({x:e.clientX,y:e.clientY},a,i.viewport),c=Pt(o,r);c&&(e.stopPropagation(),e.preventDefault(),V.active=!0,V.containerId=n,V.leafId=t,V.edge=c.edge,V.leafRect={...o},V.startPt=r,ce())}(e,n.containerId,n.leafId,n.rect)},[n.isEmpty?(e.openBlock(),e.createElementBlock("div",Ht,[...o[3]||(o[3]=[e.createElementVNode("span",{class:"hc-fs-leaf-hint"},"拖组件进来",-1)])])):e.createCommentVNode("",!0),n.canSplit||n.canDelete||n.canMove?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-fs-leaf-toolbar",onPointerdown:o[0]||(o[0]=e.withModifiers(()=>{},["stop"]))},[n.canMove?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"hc-fs-leaf-btn hc-fs-leaf-move",title:"拖动:移动 / 交换到另一格",onPointerdown:e.withModifiers(e=>{return t=e,o=n.containerId,i=n.leafId,void(0===t.button&&(t.stopPropagation(),t.preventDefault(),R.active=!0,R.containerId=o,R.sourceLeafId=i,R.targetLeafId=null,window.addEventListener("pointermove",O),window.addEventListener("pointerup",N),window.addEventListener("keydown",le)));var t,o,i},["stop"])},"⠿",40,Xt)):e.createCommentVNode("",!0),n.canSplit?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"hc-fs-leaf-btn",title:"竖切(分左右)",onClick:e.withModifiers(e=>j(n.containerId,n.leafId,"right"),["stop"])},"⬌",8,Yt)):e.createCommentVNode("",!0),n.canSplit?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",class:"hc-fs-leaf-btn",title:"横切(分上下)",onClick:e.withModifiers(e=>j(n.containerId,n.leafId,"bottom"),["stop"])},"⬍",8,Gt)):e.createCommentVNode("",!0),n.canDelete?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",class:"hc-fs-leaf-btn hc-fs-leaf-btn--danger",title:"删除此区(并入相邻)",onClick:e.withModifiers(e=>{return t=n.containerId,o=n.leafId,void c.requestDelete(t,o);var t,o},["stop"])},"✕",8,Wt)):e.createCommentVNode("",!0)],32)):e.createCommentVNode("",!0)],46,Ut))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(D.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"fsd-cnt-"+n.containerId},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.dividers,a=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:"fsd-"+n.containerId+"-"+a.nodeId+"-"+a.dividerIndex},[t.$slots["free-split-divider"]?e.renderSlot(t.$slots,"free-split-divider",{key:0,state:{containerId:n.containerId,nodeId:a.nodeId,dividerIndex:a.dividerIndex,direction:a.direction,rect:a.rect,isDragging:e.unref(c).isResizing.value&&e.unref(c).resizeDrag.containerId===n.containerId&&e.unref(c).resizeDrag.nodeId===a.nodeId&&e.unref(c).resizeDrag.dividerIndex===a.dividerIndex}},void 0,!0):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-fs-divider","data-hc-fs-divider-direction":a.direction,"data-hc-fs-divider-node":a.nodeId,"data-hc-fs-divider-index":a.dividerIndex,"data-hc-fs-container-id":n.containerId,"data-hc-fs-divider-dragging":e.unref(c).isResizing.value&&e.unref(c).resizeDrag.containerId===n.containerId&&e.unref(c).resizeDrag.nodeId===a.nodeId&&e.unref(c).resizeDrag.dividerIndex===a.dividerIndex?"true":"false",style:e.normalizeStyle({position:"absolute",left:a.rect.x+"px",top:a.rect.y+"px",width:a.rect.w+"px",height:a.rect.h+"px",background:e.unref(c).isResizing.value&&e.unref(c).resizeDrag.containerId===n.containerId&&e.unref(c).resizeDrag.nodeId===a.nodeId&&e.unref(c).resizeDrag.dividerIndex===a.dividerIndex?"rgba(59, 130, 246, 0.6)":"rgba(59, 130, 246, 0.18)",cursor:"horizontal"===a.direction?"ew-resize":"ns-resize",pointerEvents:"auto",boxSizing:"border-box",zIndex:3}),onPointerdown:e=>function(e,n,t,o){if(0!==e.button)return;e.stopPropagation();const a=Q();if(!a)return;const r=L(n);if(!r)return;const s=ie(r.root,t);if(!s)return;const d=Lt(s,e=>E(n,e));if(!d)return;const l="row"===s.dir?"horizontal":"vertical",u="horizontal"===l?d.w:d.h,p=Yn({x:e.clientX,y:e.clientY},a,i.viewport),{startTracking:f}=c.handleResizeStart({containerId:n,nodeId:t,dividerIndex:o,startSizes:s.sizes.map(e=>({...e})),branchAxisPx:u,direction:l,canvasPt:p});f&&(ce(),e.preventDefault())}(e,n.containerId,a.nodeId,a.dividerIndex),onDblclick:e=>function(e,n,t,o){e.stopPropagation();const i=L(n);if(!i)return;const a=$t(i.root,t,o);a&&c.requestMerge(n,a)}(e,n.containerId,a.nodeId,a.dividerIndex)},[o[4]||(o[4]=e.createElementVNode("span",{class:"hc-fs-divider-grip","aria-hidden":"true"},null,-1)),a.mergeTargetLeafId?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"hc-fs-merge-btn",title:"合并(并入相邻空格)",onPointerdown:o[1]||(o[1]=e.withModifiers(()=>{},["stop"])),onDblclick:o[2]||(o[2]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(e=>function(e,n,t){const o=L(e);if(!o)return;const i=$t(o.root,n,t);i&&c.requestMerge(e,i)}(n.containerId,a.nodeId,a.dividerIndex),["stop"])},"⤧",40,Zt)):e.createCommentVNode("",!0)],44,Qt))],64))),128))],64))),128)),k.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-resize-badge","data-resize-badge":"",style:e.normalizeStyle({position:"absolute",left:k.value.x+"px",top:k.value.y-22+"px",padding:"2px 6px",background:"#3b82f6",color:"#fff",fontSize:"11px",lineHeight:"14px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, monospace"})},e.toDisplayString(k.value.wText)+" × "+e.toDisplayString(k.value.hText),5)):e.createCommentVNode("",!0),e.unref(a).marqueeRect.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-marquee-box","data-marquee-box":"",style:e.normalizeStyle({position:"absolute",left:e.unref(a).marqueeRect.value.x+"px",top:e.unref(a).marqueeRect.value.y+"px",width:e.unref(a).marqueeRect.value.w+"px",height:e.unref(a).marqueeRect.value.h+"px",border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",boxSizing:"border-box"})},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(a).snapLines.value,(n,t)=>(e.openBlock(),e.createElementBlock("div",{key:"snap-"+t,class:"hc-snap-line","data-snap-line":"","data-axis":n.axis,"data-kind":n.kind,style:e.normalizeStyle("x"===n.axis?{position:"absolute",left:n.pos+"px",top:n.from+"px",width:"0px",height:n.to-n.from+"px",borderLeft:"1px dashed #ec4899",pointerEvents:"none"}:{position:"absolute",left:n.from+"px",top:n.pos+"px",width:n.to-n.from+"px",height:"0px",borderTop:"1px dashed #ec4899",pointerEvents:"none"})},null,12,eo))),128)),W.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[t.$slots["reparent-ghost"]?e.renderSlot(t.$slots,"reparent-ghost",{key:0,state:W.value},void 0,!0):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-reparent-ghost","data-hc-reparent-ghost":"","data-hc-reparent-state":W.value.result.ok?"legal":"illegal",style:e.normalizeStyle({position:"absolute",left:W.value.rect.x+"px",top:W.value.rect.y+"px",width:W.value.rect.w+"px",height:W.value.rect.h+"px",pointerEvents:"none",boxSizing:"border-box",border:"2px solid "+(W.value.result.ok?"#22c55e":"#ef4444"),background:W.value.result.ok?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)"})},[!W.value.result.ok&&W.value.result.message?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-reparent-ghost__message","data-hc-reparent-ghost-message":"","data-hc-reparent-ghost-reason":W.value.result.reason||"",style:{position:"absolute",left:"0",top:"100%",marginTop:"4px",maxWidth:"280px",padding:"3px 6px",background:"#ef4444",color:"#fff",fontSize:"11px",lineHeight:"16px",borderRadius:"3px",whiteSpace:"normal",wordBreak:"break-all",pointerEvents:"none",display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px"}},[W.value.result.reason?(e.openBlock(),e.createElementBlock("span",oo,"["+e.toDisplayString(W.value.result.reason)+"]",1)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(W.value.result.message),1)],8,to)):e.createCommentVNode("",!0)],12,no))],64)):e.createCommentVNode("",!0)],44,Vt))}}),[["__scopeId","data-v-ccd54f15"]]),ao=e.defineComponent({__name:"HyperCardCanvasDesigner",props:{modelValue:{},componentSourceMap:{},mode:{default:"design"},schedulerOptions:{},adapters:{},canvasId:{},freeSplitEnabled:{type:[Boolean,Function],default:void 0}},emits:["update:modelValue","context-ready","handle-ready","cannot-drag-slot-child","cannot-drag-layout-managed-child"],setup(n,{expose:t,emit:o}){const i=n,a=o;let r=!1;const c=i.canvasId??function(){const e=globalThis.crypto;return e&&"function"==typeof e.randomUUID?`hc-designer-${e.randomUUID()}`:`hc-designer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}(),s=Be({canvasId:c,initialDocument:i.modelValue,getMode:()=>i.mode,adapters:i.adapters,freeSplitEnabled:()=>"function"==typeof i.freeSplitEnabled?i.freeSplitEnabled():i.freeSplitEnabled});ze(s);const d=e.ref(null),l=vt(s,{getStageEl:()=>{var e;return(null==(e=d.value)?void 0:e.querySelector("[data-hc-stage]"))??null},resolveContract:function(e){var n;const t=null==(n=i.componentSourceMap)?void 0:n[e];if(t)return"contract"in t&&t.contract?t.contract:void 0}}),u=!!s.adapters.data,p=We({canvasId:c,source:{getDocument:()=>s.document.document,onAction:e=>s.registerHooks({onAfterAction:n=>e(n)})},initialMode:It(i.mode),dataStore:u?s.dataStore:void 0});l.attachBindingDelegate(p,u?s.dataStore:null),a("context-ready",s),a("handle-ready",l);const f={getDropTarget:(e,n)=>l.getDropTarget(e,d.value,n),canReparent:(e,n)=>l.canReparent(e,n),moveInstanceInTree:(e,n)=>l.moveInstanceInTree(e,n),cannotReparentEvent:l.cannotReparentEvent};function g(){a("update:modelValue",JSON.parse(JSON.stringify(s.document.document)))}return e.provide(yt,f),e.watch(()=>i.modelValue,(e,n)=>{if(e&&e!==n){r=!0;try{s.suppressRecording(()=>{s.dispatch({type:"replaceDocument",payload:{document:e}})})}finally{r=!1}}}),e.watch(()=>s.document.document,()=>{r||s.isBatching.value||g()},{deep:!0,flush:"sync"}),e.watch(()=>s.isBatching.value,(e,n)=>{!n||e||r||g()},{flush:"sync"}),e.onMounted(()=>{Bn(c,l),e.nextTick(()=>{p.setMode(It(i.mode))})}),e.watch(()=>i.mode,e=>{p.setMode(It(e))}),e.onBeforeUnmount(()=>{p.dispose(),l.attachBindingDelegate(null,null),zn(c),l.dispose(),s.dispose()}),t({context:s,handle:l,canvasId:c}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"stageContainerEl",ref:d,class:"hc-canvas-designer",style:{width:"100%",height:"100%",position:"relative"},"data-hc-canvas-designer":""},[e.createVNode(wt,null,{default:e.withCtx(()=>[e.createVNode(St,{"component-source-map":n.componentSourceMap,mode:n.mode,"scheduler-options":n.schedulerOptions,"canvas-id":e.unref(c)},null,8,["component-source-map","mode","scheduler-options","canvas-id"]),"runtime"!==n.mode?(e.openBlock(),e.createBlock(io,{key:0,mode:n.mode,onCannotDragSlotChild:o[0]||(o[0]=e=>a("cannot-drag-slot-child",e)),onCannotDragLayoutManagedChild:o[1]||(o[1]=e=>a("cannot-drag-layout-managed-child",e))},e.createSlots({_:2},[t.$slots["reparent-ghost"]?{name:"reparent-ghost",fn:e.withCtx(n=>[e.renderSlot(t.$slots,"reparent-ghost",e.normalizeProps(e.guardReactiveProps(n)))]),key:"0"}:void 0,t.$slots["split-divider"]?{name:"split-divider",fn:e.withCtx(n=>[e.renderSlot(t.$slots,"split-divider",e.normalizeProps(e.guardReactiveProps(n)))]),key:"1"}:void 0,t.$slots["free-split-divider"]?{name:"free-split-divider",fn:e.withCtx(n=>[e.renderSlot(t.$slots,"free-split-divider",e.normalizeProps(e.guardReactiveProps(n)))]),key:"2"}:void 0]),1032,["mode"])):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"canvas-overlay",{viewport:e.unref(l).viewport,handle:e.unref(l)}),e.renderSlot(t.$slots,"default")]),_:3})],512))}});function ro(e={}){const{canvasWidth:n=1280,canvasHeight:t=720,rootLayout:o="free",instances:i=[],bindings:a=[]}=e;return{schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"px",value:n},height:{mode:"px",value:t}},rootLayout:"string"==typeof o?{mode:o}:o},instances:i,bindings:a}}const co={event:["instanceEvent"],init:["lifecycle","page"],data:["dataSource"]};function so(e){return co[e.type].includes(e.source.kind)}function lo(e,n,t,o){const i={level:n,code:e,bindingId:t.id,message:`${e} on binding "${t.id}"`};return o.instanceId&&(i.instanceId=o.instanceId),o.canvasId&&(i.canvasId=o.canvasId),i}function uo(e){return"instanceEvent"===e.source.kind||"lifecycle"===e.source.kind?{instanceId:e.source.instanceId}:"instanceMethod"===e.target.kind||"instanceDataInput"===e.target.kind||"instanceEmit"===e.target.kind?{instanceId:e.target.instanceId}:{}}function po(e){switch(e.source.kind){case"instanceEvent":case"lifecycle":return e.source.canvasId;case"page":case"dataSource":return}}function fo(e){switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":return e.target.canvasId}}exports.CANVAS_CONTEXT_KEY=ke,exports.CANVAS_REPARENT_BRIDGE_KEY=yt,exports.CanvasStage=wt,exports.DEFAULT_FIT_PADDING=40,exports.DIVIDER_HIT_THICKNESS=8,exports.DRAG_THRESHOLD_CANVAS_PX=3,exports.EFFECTIVE_DEFAULT_SLOT=Te,exports.HandleDisposedError=En,exports.HyperCardCanvasDesigner=ao,exports.HyperCardPageRenderer=wn,exports.InteractionLayer=io,exports.MAX_INSTANCE_TREE_DEPTH=8,exports.MAX_SPLIT_TREE_DEPTH=8,exports.MIN_INSTANCE_SIZE=8,exports.MIN_RATIO_FRACTION=kt,exports.RuntimeLayer=St,exports.SLOT_CHILD_RESIZE_HANDLES=["e","s","se"],exports.VERSION="0.0.0-d3.6c-stage",exports.__resetRendererDiagnosticsRegistry=function(){const e=[...t.keys()];t.clear();for(const n of e)i("unregister",n)},exports.applyEffectiveSplitRatiosToDocument=m,exports.applyFreeSplitResizeDrag=Dt,exports.applySplitDividerDrag=zt,exports.assertNeverBindingSource=G,exports.assertNeverBindingTarget=W,exports.bindingModeForCanvasMode=It,exports.bindingReferencesInstance=Y,exports.buildInstanceTree=nt,exports.canReparent=et,exports.canvasSizeToCss=R,exports.cleanLayoutItem=U,exports.clientToCanvas=Yn,exports.computeContentBounds=st,exports.computeEffectiveSplitRatios=z,exports.computeFit=lt,exports.computeFreeSplitDividers=Et,exports.computeFreeSplitNodeRect=Lt,exports.computeInverse=Mn,exports.computeNextAxisSize=Un,exports.computeNextLayoutBoxAxis=Hn,exports.computeParentLayoutMode=J,exports.computeSelectionBounds=dt,exports.computeSlotChildCanvasRect=Jn,exports.computeSnap=Pn,exports.computeSplitDividers=Bt,exports.computeSplitShare=Rt,exports.computeVisibleBounds=ut,exports.containerLayoutToCss=D,exports.createAssetResolver=xe,exports.createCanvasContext=Be,exports.createCanvasHandle=vt,exports.createCanvasInteraction=Wn,exports.createCommandRecorder=Ln,exports.createDocumentStore=ee,exports.createFreePageDocument=function(e={}){return ro({...e,rootLayout:"free"})},exports.createFreeSplitInteraction=Ft,exports.createMinimalPageDocument=ro,exports.createRenderScheduler=H,exports.createSelectionStore=ne,exports.createSplitDividerInteraction=Mt,exports.createViewportStore=te,exports.deriveComponentContract=nn,exports.deriveComponentKind=function(e,t){const o="string"==typeof(null==e?void 0:e.js)?e.js:"",i="string"==typeof(null==e?void 0:e.html)?e.html:"",a=n.parseComponentSource(o,i);return!a.ok&&(null==t?void 0:t.fallback)?t.fallback:a.kind},exports.effectiveSlot=Ce,exports.emptyComponentContract=function(){return{propsDecl:[],emitsDecl:[],methodsDecl:[],slotsDecl:[],modelDecl:[],dataInputsDecl:[],dataOutputsDecl:[]}},exports.emptyPageDocument=function(){return{schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}},exports.filterExistingIds=Gn,exports.filterInstancesInRect=On,exports.findInstanceBreadcrumb=at,exports.findInstancePath=it,exports.getBindingInstanceRefs=X,exports.getDefaultShortcuts=function(){return[{id:"undo",keys:["mod+z"],command:"undo",when:"notEditingText"},{id:"redo",keys:["mod+shift+z","mod+y"],command:"redo",when:"notEditingText"},{id:"deleteSelection",keys:["delete","backspace"],command:"deleteSelection",when:"hasSelection"},{id:"duplicateSelection",keys:["mod+d"],command:"duplicateSelection",when:"hasSelection"},{id:"fitToSelectionOrContent",keys:["f"],command:"fitToSelectionOrContent",when:"notEditingText"},{id:"zoom100",keys:["1"],command:"zoom100",when:"notEditingText"},{id:"resetViewport",keys:["0"],command:"resetViewport",when:"notEditingText"},{id:"zoomIn",keys:["+","="],command:"zoomIn",when:"notEditingText"},{id:"zoomOut",keys:["-"],command:"zoomOut",when:"notEditingText"},{id:"nudgeLeft",keys:["arrowleft"],command:"nudgeSelection",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRight",keys:["arrowright"],command:"nudgeSelection",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUp",keys:["arrowup"],command:"nudgeSelection",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDown",keys:["arrowdown"],command:"nudgeSelection",payload:{dx:0,dy:1},when:"hasSelection"},{id:"nudgeLeftLarge",keys:["shift+arrowleft"],command:"nudgeSelectionLarge",payload:{dx:-1,dy:0},when:"hasSelection"},{id:"nudgeRightLarge",keys:["shift+arrowright"],command:"nudgeSelectionLarge",payload:{dx:1,dy:0},when:"hasSelection"},{id:"nudgeUpLarge",keys:["shift+arrowup"],command:"nudgeSelectionLarge",payload:{dx:0,dy:-1},when:"hasSelection"},{id:"nudgeDownLarge",keys:["shift+arrowdown"],command:"nudgeSelectionLarge",payload:{dx:0,dy:1},when:"hasSelection"},{id:"cancelInteraction",keys:["escape"],command:"cancelInteraction",when:"notEditingText"}]},exports.getDesignerHandle=function(e){return bn.get(e)??null},exports.getInstanceWrapperRectFromDom=Nn,exports.getOutletRectFromDom=An,exports.getParentLayoutMode=jn,exports.getRendererDiagnostics=function(e){return t.get(e)??null},exports.getSiblings=rt,exports.getSlotChildRectFromDom=function(e,n){var t;const o=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!o)return null;const i="undefined"!=typeof globalThis&&(null==(t=globalThis.CSS)?void 0:t.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),a=o.querySelector(`[data-instance-id="${i(e)}"][data-hc-placement="slot"]`);return a&&a instanceof HTMLElement?a.getBoundingClientRect():null},exports.hitTestInstance=Rn,exports.isAdditive=Xn,exports.isCanvasRootPlacement=function(e){return"canvas"===e||"absolute"===e||void 0===e},exports.isContainerChildPlacement=K,exports.isDraftKey=function(e){return"string"==typeof e&&e.includes("@draft:")},exports.isEditingText=ft,exports.isFreePositionLayoutMode=Vn,exports.isFreeSplitEnabled=function(){return!1},exports.isInstanceEffectivelyLocked=jt,exports.isInstancePositionLocked=At,exports.isInstanceSizeLocked=Nt,exports.isResizeHandleAllowed=Kn,exports.isV1Layout=T,exports.layoutItemToCss=P,exports.listRegisteredCanvasIds=function(){return Object.freeze(Array.from(bn.keys()))},exports.listRendererDiagnostics=function(){return[...t.values()]},exports.matchBinding=gt,exports.migrateGridCellsToLayoutItem=v,exports.migrateInstanceToLayoutBox=V,exports.migrateLayoutV0ToV1=M,exports.migratePlacementToCanvasContainer=j,exports.migrateRootLayout=_,exports.normalizeComponentOverrides=I,exports.normalizeFreeSplitContainersInDocument=function(e){return e},exports.normalizeFreeSplitTreeShape=function e(n){if(!n||"object"!=typeof n)return g();const t=n;if("leaf"===t.type){const e={type:"leaf",leafId:"string"==typeof t.leafId&&t.leafId?t.leafId:f(),instanceId:"string"==typeof t.instanceId?t.instanceId:null};return!0===t.locked&&(e.locked=!0),e}if("split"===t.type){const n=(Array.isArray(t.children)?t.children:[]).map(n=>e(n));if(0===n.length)return g();if(1===n.length)return n[0];const o=Array.isArray(t.sizes)?t.sizes:[],i=n.map((e,n)=>function(e){if(e&&"object"==typeof e){const n=e;if("px"===n.mode){const e={mode:"px",value:"number"==typeof n.value&&Number.isFinite(n.value)&&n.value>=0?n.value:0};let t="number"==typeof n.min&&Number.isFinite(n.min)&&n.min>=0?n.min:void 0,o="number"==typeof n.max&&Number.isFinite(n.max)&&n.max>=0?n.max:void 0;return void 0!==t&&void 0!==o&&t>o&&(t=void 0,o=void 0),void 0!==t&&(e.min=t),void 0!==o&&(e.max=o),e}return{mode:"ratio",value:"number"==typeof n.value&&Number.isFinite(n.value)&&n.value>0?n.value:1}}return{mode:"ratio",value:1}}(o[n]));return{type:"split",nodeId:"string"==typeof t.nodeId&&t.nodeId?t.nodeId:`nd_${p()}`,dir:"col"===t.dir?"col":"row",children:n,sizes:i}}return g()},exports.normalizeGridCells0Based=y,exports.normalizeInstanceSlotFields=x,exports.normalizeKeyString=ht,exports.normalizeMarqueeRect=$n,exports.normalizePageBindings=d,exports.normalizePageDocument=h,exports.parseComponentVersionKey=function(e){if("string"!=typeof e||!e.includes("@"))return null;const n=e.indexOf("@"),t=e.slice(0,n),o=e.slice(n+1);if(!t)return null;if(o.startsWith("draft:")){const e=o.slice(6),n=e.indexOf(":");if(n<=0)return null;const i=e.slice(0,n),a=e.slice(n+1);return i&&a?{kind:"draft",componentId:t,pageId:i,baseVersion:a,baseVersionKey:`${t}@${a}`}:null}return o?{kind:"published",componentId:t,version:o}:null},exports.parseKeyEvent=pt,exports.provideCanvasContext=ze,exports.registerDesignerHandle=Bn,exports.registerRendererDiagnostics=a,exports.renderLayoutBoxStyle=L,exports.resolveCanvasSizePx=function(e,n=1920){return"px"===e.mode?e.value:n},exports.resolveFreeSplitMergeTarget=$t,exports.resolveMeasuredCanvasSizePx=C,exports.resolveSplitEdge=Pt,exports.subscribeDesignerRegistry=function(e){return Sn.add(e),()=>{Sn.delete(e)}},exports.subscribeRendererDiagnostics=function(e){return o.add(e),()=>o.delete(e)},exports.unionRects=ct,exports.unregisterDesignerHandle=zn,exports.unregisterRendererDiagnostics=r,exports.useCanvasContext=Me,exports.validateBindings=function(e,n){var t,o,i;const a=[],r=new Map;for(const n of e.instances)r.set(n.instanceId,n);const c=null==n?void 0:n.currentCanvasId,s=null==n?void 0:n.resolveContract;let d=null,l=null;if(s){d=new Map,l=new Map;for(const n of e.instances){const e=s(n.componentVersionKey);if(d.set(n.instanceId,e),e)for(const t of e.dataInputsDecl)if(t.required){let e=l.get(n.instanceId);e||(e=new Set,l.set(n.instanceId,e)),e.add(t.key)}}}for(const n of e.bindings)if(so(n)){if(void 0!==c){const e=po(n),t=fo(n);void 0!==e&&e!==c&&a.push(lo("unsupported-cross-canvas","error",n,{canvasId:e})),void 0!==t&&t!==c&&a.push(lo("unsupported-cross-canvas","error",n,{canvasId:t}))}switch(n.source.kind){case"instanceEvent":{const e=n.source.event,t=r.get(n.source.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.emitsDecl.some(n=>n.event===e)&&a.push(lo("unknown-source-event","error",n,{instanceId:t.instanceId}))}}else a.push(lo("orphan-binding","warn",n,{instanceId:n.source.instanceId}));break}case"lifecycle":r.get(n.source.instanceId)||a.push(lo("orphan-binding","warn",n,{instanceId:n.source.instanceId}))}switch(n.target.kind){case"instanceMethod":{const e=n.target.method,t=r.get(n.target.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.methodsDecl.some(n=>n.key===e)&&a.push(lo("unknown-target-method","error",n,{instanceId:t.instanceId}))}}else a.push(lo("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}case"instanceEmit":{const e=n.target.event,t=r.get(n.target.instanceId);if(t){if(d){const o=d.get(t.instanceId);o&&!o.emitsDecl.some(n=>n.event===e)&&a.push(lo("unknown-target-event","error",n,{instanceId:t.instanceId}))}}else a.push(lo("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}case"instanceDataInput":{const e=n.target.key,o=r.get(n.target.instanceId);if(o){if(d){const i=d.get(o.instanceId);i&&!i.dataInputsDecl.some(n=>n.key===e)?a.push(lo("unknown-target-data-input","error",n,{instanceId:o.instanceId})):l&&(null==(t=l.get(o.instanceId))||t.delete(e))}}else a.push(lo("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}}(null==(o=n.schedule)?void 0:o.throttle)&&n.schedule.throttle.windowMs<16&&a.push(lo("schedule-window-too-small","info",n,uo(n))),(null==(i=n.schedule)?void 0:i.debounce)&&n.schedule.debounce.windowMs<16&&a.push(lo("schedule-window-too-small","info",n,uo(n)))}else a.push(lo("invalid-type-source-kind","error",n,uo(n)));if(l)for(const[e,n]of l)for(const t of n){const n={level:"warn",code:"required-data-input-missing",instanceId:e,key:t,message:`Required dataInput "${t}" on instance "${e}" is not fed by any binding`};a.push(n)}return a},exports.validateInstanceTree=Le,exports.wirePageBindings=We;