@hy-bricks/canvas 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +1982 -0
- package/dist/index.mjs +2 -0
- package/package.json +62 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +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");function t(e){return JSON.parse(JSON.stringify(e))}const o="[hc-canvas/normalizeBindings]";function a(e){if(!Array.isArray(e))return[];const n=[];for(let t=0;t<e.length;t++){const a=e[t];if(!a||"object"!=typeof a){console.warn(`${o} dropped non-object binding at index ${t}`);continue}if(i(a)){n.push(a);continue}const s=r(a);null!==s&&n.push(s)}return n}function i(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 r(e){if("string"!=typeof e.id||0===e.id.length)return console.warn(`${o} 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(`${o} dropped binding "${e.id}" missing/invalid target`),null;const a=e.type;let i;if("event"===a){const n=e.source;if(!n||"object"!=typeof n||"string"!=typeof n.instanceId||""===n.instanceId||"string"!=typeof n.event)return console.warn(`${o} dropped event binding "${e.id}" missing/invalid source`),null;i={kind:"instanceEvent",instanceId:n.instanceId,event:n.event}}else{if("init"!==a)return console.warn(`${o} 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(`${o} init binding "${e.id}" had source.instanceId, discarded`),i={kind:"page",hook:"pageInit"}}}const r={kind:"instanceMethod",instanceId:n.instanceId,method:n.method};let s;s=void 0===n.args?{kind:"passthrough"}:Array.isArray(n.args)&&0===n.args.length?{kind:"static",args:[]}:Array.isArray(n.args)?{kind:"static",args:t(n.args)}:{kind:"passthrough"};const c={},d=e.options;d&&"object"==typeof d&&(!0===d.once&&(c.once=!0),"number"==typeof d.throttleMs&&(c.throttle={windowMs:d.throttleMs}),"number"==typeof d.debounceMs&&(c.debounce={windowMs:d.debounceMs}));const l=void 0!==c.once||void 0!==c.throttle||void 0!==c.debounce,u={id:e.id,source:i,target:r,mapping:s,...void 0!==e.disabled?{disabled:e.disabled}:{},...l?{schedule:c}:{}};return"event"===a?{...u,type:"event"}:{...u,type:"init"}}function s(e){const n=e.instances.map(l),t=d(e.componentOverrides,n),o=a(e.bindings);if("1"===e.schemaVersion){const a=P(y(e.layout)?e.layout:v(e.layout));return{...e,layout:a,instances:n,bindings:o,componentOverrides:t}}return{schemaVersion:"1",layout:P(v(e.layout)),instances:n,bindings:o,componentOverrides:t}}function c(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),a=null==(n=o.layoutItem)?void 0:n.ratio;e?e.push(a):t.set(o.parentId,[a])}let o=!1;const a=e.map(e=>{if(!e.containerLayout||"split"!==e.containerLayout.mode)return e;const n=t.get(e.instanceId)??[],a=e.containerLayout.ratios,i=m(a,n);return a.length===i.length&&a.every((e,n)=>e===i[n])?e:(o=!0,{...e,containerLayout:{...e.containerLayout,ratios:i}})});return o?a: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}),a=t.ratios,i=m(a,o);return a.length===i.length&&a.every((e,n)=>e===i[n])?e:{...e,rootLayout:{...t,ratios:i}}}(e.layout,n):e.layout;return n===e.instances&&t===e.layout?e:{...e,layout:t,instances:n}}function d(e,n){if(!e||"object"!=typeof e||Array.isArray(e))return{};const t=new Set(n.map(e=>e.instanceId)),o={};for(const[n,a]of Object.entries(e)){if(!a||"object"!=typeof a||Array.isArray(a))continue;const e=a;e.instanceId===n&&t.has(e.instanceId)&&"string"==typeof e.baseVersionKey&&e.baseVersionKey&&B(e.source)&&M(e.contract)&&(o[n]={instanceId:e.instanceId,baseVersionKey:e.baseVersionKey,source:e.source,contract:e.contract,...T(e.contractParseError)?{contractParseError:T(e.contractParseError)}:{},..."string"==typeof e.createdAt?{createdAt:e.createdAt}:{},..."string"==typeof e.updatedAt?{updatedAt:e.updatedAt}:{}})}return o}function l(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=p(n.sizing,n.size);if(t!==n.size&&(n={...n,size:t}),void 0!==n.containerLayout){const e=g(n.containerLayout);if(e!==n.containerLayout)if(null===e){const{containerLayout:e,...t}=n;n=t}else n={...n,containerLayout:e}}if(n=E(n),n=L(n),void 0!==n.layoutItem){const e=O(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 u=new Set(["px","percent","fill","hug","auto"]);function p(e,n){var t,o,a,i;const r=n?function(e){const n={},t=h(e.width),o=h(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=f(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=f(e.height,null==(a=e.min)?void 0:a.h,null==(i=e.max)?void 0:i.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 f(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 a={mode:o};return"px"!==o&&"percent"!==o||"number"!=typeof e.value||(a.value=e.value),"number"==typeof n&&(a.min=n),"number"==typeof t&&(a.max=t),a}function h(e){if(!e||"object"!=typeof e)return null;if("string"!=typeof e.mode)return null;if(!u.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 g(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 m(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 a=n[e];if("number"==typeof a&&Number.isFinite(a)&&a>0){o.push(a);continue}const i=t[e];"number"==typeof i&&i>0?o.push(i):o.push(1)}return o}function v(e){if(!e)return{type:"free",canvas:{width:{mode:"px",value:1920},height:{mode:"px",value:1080}}};if(y(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),a={type:n.type,canvas:t};return o&&(a.background=o),void 0!==n.canvas.gridSize&&(a.guides={grid:{size:n.canvas.gridSize}}),a}function y(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 I(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 x(e,n,t,o){const a=w(e.widthMode,e.width),i=w(e.heightMode,e.height),r="free"===o,s={boxSizing:"border-box",minWidth:0,minHeight:0,overflow:e.overflow??"hidden",zIndex:n};return null!==a&&(s.width=a),null!==i&&(s.height=i),"number"==typeof t&&Number.isFinite(t)&&0!==t&&(s.transform=`rotate(${t}deg)`),r?(s.position="absolute",s.left=`${e.x}px`,s.top=`${e.y}px`):s.position="relative",s}function w(e,n){switch(e){case"px":return`${n}px`;case"percent":return`${n}%`;case"fill":return"100%";case"auto":return"auto"}}function b(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 k(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 S(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 B(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.html&&"string"==typeof e.js&&"string"==typeof e.css}function M(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 T(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 z=new Set(["px","percent","fill","auto"]),C=new Set(["hidden","visible","auto"]);function E(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 L(e){var n,t;const o=e.rect??{x:0,y:0,w:0,h:0},a=null==(n=e.size)?void 0:n.width,i=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&&z.has(s.widthMode)?s.widthMode:r(a)??"px",d=s&&z.has(s.heightMode)?s.heightMode:r(i)??"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==a?void 0:a.value)??o.w),height:l(null==s?void 0:s.height,(null==i?void 0:i.value)??o.h),widthMode:c,heightMode:d,overflow:(null==s?void 0:s.overflow)&&C.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 P(e){if(e.rootLayout){const o=g(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 D(e){return"container"===e||"slot"===e}function R(e,n,t){var o,a;const i=n.find(e=>e.instanceId===t);if(!i)return;if(void 0===i.parentId)return(null==(o=null==e?void 0:e.rootLayout)?void 0:o.mode)??"free";const r=n.find(e=>e.instanceId===i.parentId);return(null==(a=null==r?void 0:r.containerLayout)?void 0:a.mode)??"none"}function O(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 $(n={}){const{rootMargin:t="500px",disposeDelayMs:o=1500,mountConcurrency:a=2,root:i=null}=n,r={state:e.reactive({}),elById:new Map,idByEl:new WeakMap,mountQueue:[],disposeTimers:new Map,idleScheduled:!1,io:null};function s(e){for(const n of e){const e=r.idByEl.get(n.target);e&&(n.isIntersecting?c(e):d(e))}}function c(e){const n=r.disposeTimers.get(e);n&&(clearTimeout(n),r.disposeTimers.delete(e));const t=r.state[e];"mounted"!==t&&"disposing"!==t?(r.state[e]="mounting",r.mountQueue.includes(e)||r.mountQueue.push(e),l()):r.state[e]="mounted"}function d(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(r.state[e]="pending")}r.state[e]="disposing";const t=r.disposeTimers.get(e);t&&clearTimeout(t);const a=setTimeout(()=>{"disposing"===r.state[e]&&(r.state[e]="pending",r.disposeTimers.delete(e))},o);r.disposeTimers.set(e,a)}function l(){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<a&&r.mountQueue.length>0;){const n=r.mountQueue.shift();"mounting"===r.state[n]&&(r.state[n]="mounted",e++)}r.mountQueue.length>0&&l()}))}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),r.state[e]="pending";const a=r.io?r.io:"undefined"==typeof IntersectionObserver?null:(r.io=new IntersectionObserver(s,{root:i,rootMargin:t}),r.io);a?a.observe(n):r.state[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),delete r.state[e]},isMounted(e){const n=r.state[e];return"mounted"===n||"disposing"===n},getState:e=>r.state[e]??"idle",get state(){return r.state},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]}}}function A(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:F(e.source)}switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":n.push({canvasId:e.target.canvasId,instanceId:e.target.instanceId});break;default:j(e.target)}return n}function N(e,n,t){for(const o of A(e))if(o.instanceId===n&&o.canvasId===t)return!0;return!1}function F(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingSource.kind: ${e.kind}`)}function j(e){throw new Error(`[hc-canvas/bindingRefs] Unhandled BindingTarget.kind: ${e.kind}`)}function V(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 q(e={}){return JSON.parse(JSON.stringify(e))}function _(n={schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}){const o=s(n),i=e.reactive({schemaVersion:"1",layout:V(o.layout),instances:o.instances.map(e=>({...e,rect:{...e.rect}})),bindings:o.bindings.map(e=>t(e)),componentOverrides:q(o.componentOverrides)});function r(e){return i.instances.findIndex(n=>n.instanceId===e)}function c(e){return i.bindings.findIndex(n=>n.id===e)}return{get document(){return i},instanceCount:e.computed(()=>i.instances.length),bindingCount:e.computed(()=>i.bindings.length),addInstance(e){if(r(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)),i.instances.push(t)},removeInstance(e){var n;const t=r(e);t<0||(i.instances.splice(t,1),null==(n=i.componentOverrides)||delete n[e],i.bindings=i.bindings.filter(n=>!N(n,e)))},updateInstance(e,n){const t=i.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 o=i.instances.find(n=>n.instanceId===e);o&&(o.rect.x=n,o.rect.y=t,o.layoutBox&&(o.layoutBox={...o.layoutBox,x:n,y:t}))},resizeInstance(e,n,t){const o=i.instances.find(n=>n.instanceId===e);if(!o)return;const a=Math.max(1,n),r=Math.max(1,t);o.rect.w=a,o.rect.h=r,o.layoutBox&&(o.layoutBox={...o.layoutBox,width:a,height:r,widthMode:"px",heightMode:"px"})},setInstanceProp(e,n,t){const o=i.instances.find(n=>n.instanceId===e);o&&(o.props={...o.props,[n]:t})},setInstanceLocked(e,n){const t=i.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=i.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,a={...t.layoutBox};e&&("px"===e.mode?(a.widthMode="px","number"==typeof e.value&&Number.isFinite(e.value)&&(a.width=e.value)):"percent"===e.mode?(a.widthMode="percent","number"==typeof e.value&&Number.isFinite(e.value)&&(a.width=e.value)):"fill"===e.mode?(a.widthMode="fill",Number.isFinite(a.width)||(a.width=t.rect.w)):"auto"!==e.mode&&"hug"!==e.mode||(a.widthMode="auto",Number.isFinite(a.width)||(a.width=t.rect.w))),o&&("px"===o.mode?(a.heightMode="px","number"==typeof o.value&&Number.isFinite(o.value)&&(a.height=o.value)):"percent"===o.mode?(a.heightMode="percent","number"==typeof o.value&&Number.isFinite(o.value)&&(a.height=o.value)):"fill"===o.mode?(a.heightMode="fill",Number.isFinite(a.height)||(a.height=t.rect.h)):"auto"!==o.mode&&"hug"!==o.mode||(a.heightMode="auto",Number.isFinite(a.height)||(a.height=t.rect.h))),t.layoutBox=a}},setInstanceContainerLayout(e,n){const t=i.instances.find(n=>n.instanceId===e);t&&(null===n?delete t.containerLayout:t.containerLayout=n)},updateInstanceLayoutBox(e,n){const t=i.instances.find(n=>n.instanceId===e);if(!t)return;const o=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={...o,...a};t.layoutBox=s;const c=a.widthMode??o.widthMode,d=a.heightMode??o.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=i.instances.find(n=>n.instanceId===e);if(!t)return;if(null===n)return void delete t.layoutItem;const o=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"],a={};for(const e of o){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=i.instances.find(n=>n.instanceId===e);t&&Number.isFinite(n)&&(0===n?delete t.rotation:t.rotation=n)},duplicateInstance(e,n,t){var o;const a=i.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,i.instances.some(e=>e.instanceId===n))return void console.warn(`[hc-canvas/doc-store] duplicateInstance: newInstanceId "${n}" 已存在,忽略`);i.instances.push(r);const s=null==(o=i.componentOverrides)?void 0:o[e];s&&(i.componentOverrides={...i.componentOverrides??{},[n]:{...JSON.parse(JSON.stringify(s)),instanceId:n}})},addBinding(e){if(c(e.id)>=0)return void console.warn(`[hc-canvas/doc-store] binding id "${e.id}" 已存在,addBinding 忽略`);const[n]=a([e]);n?i.bindings.push(t(n)):console.warn(`[hc-canvas/doc-store] addBinding "${null==e?void 0:e.id}" dropped by normalize`)},removeBinding(e){const n=c(e);n<0||i.bindings.splice(n,1)},updateBinding(e,n){const o=i.bindings.find(n=>n.id===e);if(!o)return;const a=t(n);Object.assign(o,a)},updateLayout(e){for(const n of Object.keys(e)){const t=e[n];void 0===t?delete i.layout[n]:i.layout[n]=t}},setComponentOverride(e,n){null!==n?(i.componentOverrides||(i.componentOverrides={}),i.componentOverrides[e]=n):i.componentOverrides&&e in i.componentOverrides&&delete i.componentOverrides[e]},replaceDocument(e){const n=s(e);i.schemaVersion="1",i.layout=V(n.layout),i.instances=n.instances.map(e=>({...e,rect:{...e.rect}})),i.bindings=n.bindings.map(e=>t(e)),i.componentOverrides=q(n.componentOverrides)},getInstance:e=>i.instances.find(n=>n.instanceId===e),listInstancesByComponentVersionKey:e=>i.instances.filter(n=>n.componentVersionKey===e)}}function K(){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 J(n={}){const{minScale:t=.25,maxScale:o=4,initialScale:a=1}=n,i=e.reactive({scale:a,panX:0,panY:0});function r(e){return Math.max(t,Math.min(o,e))}return{state:i,scale:e.computed(()=>i.scale),panX:e.computed(()=>i.panX),panY:e.computed(()=>i.panY),setScale(e){i.scale=r(e)},zoomAt(e,n){const t=i.scale,o=r(t+n);if(o===t)return;const a=o/t;i.panX=e.x-(e.x-i.panX)*a,i.panY=e.y-(e.y-i.panY)*a,i.scale=o},setPan(e,n){i.panX=e,i.panY=n},panBy(e,n){i.panX+=e,i.panY+=n},resetView(){i.scale=a,i.panX=0,i.panY=0},fitToScreen(e,n,t=40){const o=Math.max(1,n.w-2*t),a=Math.max(1,n.h-2*t),s=o/e.w,c=a/e.h,d=r(Math.min(s,c)),l=e.w*d,u=e.h*d;i.scale=d,i.panX=(n.w-l)/2,i.panY=(n.h-u)/2},toCanvasPoint:e=>({x:(e.x-i.panX)/i.scale,y:(e.y-i.panY)/i.scale}),toViewportPoint:e=>({x:e.x*i.scale+i.panX,y:e.y*i.scale+i.panY})}}function U(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 a=e.resolve(t);return"string"==typeof a?(o&&n.set(o,a),a):(o&&n.set(o,a),a.then(e=>{o&&n.set(o,e)},e=>{console.warn(`[hc-canvas/assets] resolve("${o}") 失败,缓存里删条目允许重试:`,e),o&&n.delete(o)}),a)},__clearCache(){n.clear()}}}function X(e){const n=new Map,t=new Map,o=new Map,a=new Map,i=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 i=o.get(e);if(i)for(const e of i)null==(t=a.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=i.get(t);l&&l.abort();const h=new AbortController;i.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(i.get(t)!==h)return;i.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(i.get(t)!==h)return;i.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,i;const r=o.get(e);if(r)for(const e of r)null==(i=null==(t=a.get(e))?void 0:t.onError)||i.call(t,n)}(t,e)))})}function g(e){if(c)return;const{bindingId:d,sourceId:l,params:u,onUpdate:p,onError:f}=e,g=function(e,n){if(!n||0===Object.keys(n).length)return`${e}::{}`;const t=Y(n,()=>{s||(console.warn(`[hc-canvas/dataStore] params for "${l}" contains non-plain values; fresh query every call (no cache)`),s=!0)});return null===t?`${e}::__fresh_${Date.now()}_${Math.random().toString(36).slice(2,8)}__`:`${e}::${t}`}(l,u);!function(e,a){const s=t.get(e);if(s===a)return;if(s){const t=o.get(s);if(t&&(t.delete(e),0===t.size)){o.delete(s);const e=i.get(s);e&&(e.abort(),i.delete(s)),n.delete(s)}const a=r.get(e);if(a){try{a()}catch{}r.delete(e)}}t.set(e,a);let c=o.get(a);c||(c=new Set,o.set(a,c)),c.add(e)}(d,g),a.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:a,params:i,onUpdate:s,onError:l}=n;if(g({bindingId:o,sourceId:a,params:i,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,a);n.status="success",n.value=e,n.lastFetchedAt=Date.now(),n.writeSeq=++d,u({kind:"data-source-update",cacheKey:h,sourceId:a,writeSeq:n.writeSeq,value:e}),p(h,e)})}(e,{sourceId:a,params:i});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)}a.delete(e);const u=function(e){const n=t.get(e);if(!n)return;t.delete(e);const a=o.get(n);return a&&(a.delete(e),0===a.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=i.get(u);e&&(e.abort(),i.delete(u)),n.delete(u)}}},invalidate:function(e){if(c)return;const t=[];for(const[o,a]of n)void 0!==e&&a.sourceId!==e||t.push(o);for(const e of t){const t=n.get(e);if(!t)continue;const a=o.get(e);if(!a||0===a.size){n.delete(e);const t=i.get(e);t&&(t.abort(),i.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}))}},disposeAll:function(){if(!c){c=!0;for(const e of i.values())try{e.abort()}catch{}i.clear();for(const e of r.values())try{e()}catch{}r.clear(),n.clear(),t.clear(),o.clear(),a.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}}}function Y(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 a of e){const e=Y(a,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 a=e;if(t.has(a))return null==n||n(),null;t.add(a);const i=Object.keys(a).sort(),r=[];for(const e of i){const o=Y(a[e],n,t);if(null===o)return null;r.push(`${JSON.stringify(e)}:${o}`)}return`{${r.join(",")}}`}return null==n||n(),null}const H=Symbol("hc:canvas:context");function G(n={}){var t,o;const a=_(n.initialDocument),i=K(),r=J(n.viewport),s=$(n.scheduler),c=X(null==(t=n.adapters)?void 0:t.data);let d=!1;const l=[];n.hooks&&l.push(n.hooks);const u=e.ref(!1),f=e.computed(()=>u.value),h=e.ref({}),m=e.computed(()=>h.value),v=e.computed(()=>{var e;const t=(null==(e=n.getMode)?void 0:e.call(n))??"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}}}(t),i=a.document.layout.behavior??{};if("design"!==t){const{selectable:e,draggable:n,resizable:t,keyboardMove:a,...r}=i;return{...o,...r,...h.value}}return{...o,...i,...h.value}}),y=U(null==(o=n.adapters)?void 0:o.assets),x=e.ref("select"),w=e.ref(null),b=e.computed(()=>w.value??x.value),k=e.ref(null),S=e.computed(()=>k.value),B=e.ref(null),M=e.ref({w:0,h:0}),T=e.computed(()=>M.value),z=e.computed(()=>{const e=a.document.layout,n=M.value;return{w:I(e.canvas.width,n.w,1920),h:I(e.canvas.height,n.h,1080)}}),C=e.ref([]),E=e.computed(()=>C.value),L=e.ref(0),P=e.computed(()=>L.value>0);return{document:a,selection:i,viewport:r,scheduler:s,adapters:n.adapters??{},dataStore:c,dispatch:function(e){var n,t;if(d)console.warn("[hc-canvas/context] dispatch called after dispose()");else{for(const t of l)if(!1===(null==(n=t.onBeforeAction)?void 0:n.call(t,e)))return;switch(e.type){case"addInstance":a.addInstance(e.payload.instance);break;case"removeInstance":a.removeInstance(e.payload.instanceId),i.removeFromSelection(e.payload.instanceId);break;case"updateInstance":a.updateInstance(e.payload.instanceId,e.payload.patch);break;case"moveInstance":a.moveInstance(e.payload.instanceId,e.payload.x,e.payload.y);break;case"resizeInstance":a.resizeInstance(e.payload.instanceId,e.payload.w,e.payload.h);break;case"setInstanceProp":a.setInstanceProp(e.payload.instanceId,e.payload.key,e.payload.value);break;case"addBinding":a.addBinding(e.payload.binding);break;case"removeBinding":a.removeBinding(e.payload.bindingId);break;case"updateBinding":a.updateBinding(e.payload.bindingId,e.payload.patch);break;case"updateLayout":a.updateLayout(e.payload.patch);break;case"setRootLayout":{const{rootLayout:n}=e.payload;a.updateLayout({rootLayout:null===n?void 0:n});break}case"replaceDocument":a.replaceDocument(e.payload.document),i.purgeOrphans(a.document.instances.map(e=>e.instanceId));break;case"setComponentOverride":{const{instanceId:n,override:t}=e.payload;if(void 0===a.getInstance(n)){console.warn(`[hc-canvas/context] setComponentOverride: instance "${n}" 不存在,no-op`);break}a.setComponentOverride(n,t);break}case"setInstanceLocked":a.setInstanceLocked(e.payload.instanceId,e.payload.locked);break;case"duplicateInstance":a.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)a.setInstanceSize(n,null);else{const e=p(void 0,t);a.setInstanceSize(n,e??null)}break}case"setContainerLayout":{const{instanceId:n,containerLayout:t}=e.payload;if(null===t)a.setInstanceContainerLayout(n,null);else{const e=g(t);null!==e&&a.setInstanceContainerLayout(n,e)}break}case"updateLayoutBox":a.updateInstanceLayoutBox(e.payload.instanceId,e.payload.patch);break;case"updateLayoutItem":a.updateInstanceLayoutItem(e.payload.instanceId,e.payload.patch);break;case"updateRotation":a.setInstanceRotation(e.payload.instanceId,e.payload.value);break;case"select":i.select(e.payload.instanceId);break;case"toggleSelect":i.toggleSelect(e.payload.instanceId);break;case"addToSelection":i.addToSelection(e.payload.instanceId);break;case"removeFromSelection":i.removeFromSelection(e.payload.instanceId);break;case"clearSelection":i.clearSelection();break;case"selectAll":i.selectAll(e.payload.instanceIds);break;default:{const n=e;console.warn("[hc-canvas/context] unknown action",n)}}for(const n of l)null==(t=n.onAfterAction)||t.call(n,e)}},dispose:function(){d||(d=!0,u.value=!1,s.dispose(),c.disposeAll())},isBatching:f,beginBatch:function(){d||u.value||(u.value=!0)},endBatch:function(e){var n;if(!d&&u.value){for(const t of l)null==(n=t.onAfterBatch)||n.call(t,e);u.value=!1}},registerHooks:function(e){return l.push(e),()=>{const n=l.indexOf(e);n>=0&&l.splice(n,1)}},isRecordingSuppressed:P,suppressRecording:function(e){L.value++;try{return e()}finally{L.value--}},effectiveBehavior:v,interactionOptions:m,setInteractionOptions:function(e){const n={...h.value};for(const t of Object.keys(e)){const o=e[t];void 0===o?delete n[t]:n[t]=o}h.value=n},resolveAsset:function(e){return y.resolve(e)},toolMode:b,setToolMode:function(e){x.value=e},setTemporaryToolMode:function(e){w.value=e},mouseCanvasPoint:S,setMouseCanvasPoint:function(e){k.value=e},measuredStageSize:T,measuredCanvasSize:z,setMeasuredStageSize:function(e){const n=Math.max(0,Math.round(e.w)),t=Math.max(0,Math.round(e.h));M.value.w===n&&M.value.h===t||(M.value={w:n,h:t})},layoutIssues:E,setLayoutIssues:function(e){C.value=e},cannotDragLayoutManagedChildEvent:e.readonly(B),setCannotDragLayoutManagedChildEvent:function(e){B.value=e}}}function W(n){e.provide(H,n)}function Q(){const n=e.inject(H);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 Z="default";function ee(e){return e.slot??Z}function ne(e,n){const t=[],o=n.resolveContract,a=n.maxDepth??8,i=new Map;for(const n of e.instances)i.set(n.instanceId,n);for(const n of e.instances){if(void 0===n.parentId&&void 0!==n.slot&&n.slot!==Z){te(t,"orphan-slot",n.instanceId,`slot "${n.slot}" 没有 parentId,数据不完整`);continue}if(void 0===n.parentId)continue;if(!i.has(n.parentId)){te(t,"missing-parent",n.instanceId,`parentId "${n.parentId}" 指向不存在的实例`);continue}"absolute"!==n.placement&&"canvas"!==n.placement||te(t,"absolute-child-rejected",n.instanceId,"parentId + placement='absolute'|'canvas' 在 D4.5f MVP 不支持,只允许 root absolute/canvas 或 child slot/container");const e=i.get(n.parentId),a=o(e.componentVersionKey);if(!a)continue;const r=a.slotsDecl??[];if(0===r.length){te(t,"parent-not-layout",n.instanceId,`父组件 "${e.componentId}" 不是布局组件(slotsDecl 为空)`);continue}const s=ee(n),c=oe(r,s);c?c.accepts&&c.accepts.length>0&&(c.accepts.includes(n.componentId)||te(t,"slot-not-allowed-component",n.instanceId,`slot "${s}" 不允许 componentId "${n.componentId}"(accepts: ${c.accepts.join(", ")})`)):te(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=ee(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[a,r]=ae(e),s=i.get(a);if(!s)continue;const c=o(s.componentVersionKey);if(!c)continue;const d=oe(c.slotsDecl??[],r);if(d&&!0!==d.multiple)for(let e=1;e<n.length;e++)te(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=i.get(e);if(o>a)return te(t,"depth-exceeded",e,`嵌套深度 ${o} 超过上限 ${a}`),void s.set(e,2);const d=r.parentId;if(void 0===d)return void s.set(e,2);if(!i.has(d))return void s.set(e,2);const l=s.get(d);if(1===l)return te(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 te(e,n,t,o){e.push({kind:n,instanceId:t,detail:o})}function oe(e,n){return e.find(e=>e.name===n)}function ae(e){const n=e.indexOf("::");return[e.slice(0,n),e.slice(n+2)]}function ie(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 re(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 a of e){const e=se(n,a.from);void 0===a.to?t.push(e):"number"==typeof a.to?(ce(t,a.to+1),t[a.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[a.to]=e)}return t}(e.paths,n):[n]:[n]}function se(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 ce(e,n){for(;e.length<n;)e.push(void 0)}function de(e,n,t,o){e.debouncePendingTimer=null;const a=e.debounceDirty,i=e.debouncePendingChainId,r=e.debouncePendingPayload;e.debouncePendingChainId=null,e.debouncePendingPayload=void 0,e.debounceDirty=!1,t&&a&&null!==i&&ue(n,e).pass&&o(r,i)}function le(e,n,t){e.throttleTrailingTimer=null;const o=e.throttleTrailingPendingChainId,a=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=he(),t(a,o)))}function ue(e,n){const t=e.throttle;if(t){t.leading;const e=t.windowMs,o=he(),a=n.throttleLastFireTs;if(null!==a&&o-a<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 pe(e){return!(!e||!(e.throttle&&!1===e.throttle.leading&&!1===e.throttle.trailing||e.debounce&&!1===e.debounce.leading&&!1===e.debounce.trailing))}let fe=()=>Date.now();function he(){return fe()}let ge=0;function me(t){var o,a;const i=t.canvasId,{source:r}=t,s=t.dataStore,c=new Set;let d="off",l=0,u=!1;const p="w"+ ++ge;let f=0;function h(){return`${p}-${++f}`}let g=0;function m(e){z.hasListeners("binding:trace")&&z.emit("binding:trace",{canvasId:i,ts:Date.now(),seq:++g,...e})}let v=null;s&&(v=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})}));const y=new Map,I=new Map,x=new Set,w=new Set,b=new Set,k=new Set,S=new Map;let B=new Set;const M=[],T=[],z=function(){const e=new Set,n=new Set,t=new Set;return{on(o,a){if("binding:fire"===o){const n=a;return e.add(n),()=>e.delete(n)}if("binding:error"===o){const e=a;return n.add(e),()=>n.delete(e)}const i=a;return t.add(i),()=>t.delete(i)},emit(o,a){if("binding:fire"===o)for(const n of e)try{n(a)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else if("binding:error"===o)for(const e of n)try{e(a)}catch(e){console.error("[hc-canvas/wirePageBindings] listener threw",e)}else for(const e of t)try{e(a)}catch(e){console.error("[hc-canvas/wirePageBindings] trace listener threw",e)}},hasListeners:o=>"binding:fire"===o?e.size>0:"binding:error"===o?n.size>0:t.size>0,clear(){e.clear(),n.clear(),t.clear()}}}(),C=function(e){let n=[],t=200,o=null,a=null;return{start:function(i){a&&(a(),a=null,n=[]),t=(null==i?void 0:i.capacity)??200,o=(null==i?void 0:i.filterKinds)&&i.filterKinds.length>0?new Set(i.filterKinds):null,a=e.on("binding:trace",e=>{o&&!o.has(e.kind)||(n.push(e),n.length>t&&n.shift())})},stop:function(){a&&(a(),a=null);const e=n.slice();return n=[],e},snapshot:function(){return n.slice()},get isRunning(){return null!==a}}}({on:(e,n)=>z.on(e,n)});function E(e){return void 0===e.canvasId||e.canvasId===i}function L(e){for(const n of A(e))if(void 0!==n.canvasId&&n.canvasId!==i)return!0;return!1}function P(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 D(e,n){return void 0===n||P(e)!==n}function R(){var e;return(null==(e=r.getDocument())?void 0:e.bindings)??[]}function O(e){return R().find(n=>n.id===e)}function $(e){try{e()}catch(e){console.error("[hc-canvas/wirePageBindings] cleanup threw",e)}}function N(e,n){z.emit("binding:fire",e),m({kind:"fire",bindingId:e.bindingId,chainId:n,payload:e.payload,args:e.args})}function F(e,n){z.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 j(e,n=!1){const t=y.get(e);if(t)for(const e of t)$(e);y.delete(e);const o=I.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}),I.delete(e)}w.delete(e),S.delete(e),b.delete(e),k.delete(e),c.delete(e),s&&s.removeBinding(e,{preserveCache:n})}function V(e=!1){for(const n of[...y.keys()])j(n,e)}function q(e){if(u)return;if(y.has(e.id))return;if(L(e))return void(b.has(e.id)||(F({bindingId:e.id,code:"unsupported-cross-canvas"}),b.add(e.id),m({kind:"wire-skipped",bindingId:e.id,reason:"unsupported-cross-canvas"})));const t=function(e){return e.disabled?"disabled":x.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"});pe(e.schedule)&&!k.has(e.id)&&(console.warn(`[hc-canvas/wirePageBindings] schedule.{throttle|debounce}.{leading=false,trailing=false} 永远不会 fire (binding "${e.id}")`),k.add(e.id));const o=[];switch(e.source.kind){case"instanceEvent":{const t=n.getInstance(e.source.instanceId,i);if(!t)return void w.add(e.id);const a=e.source.event,r=t.on(a,n=>K(e,n));o.push(r);break}case"lifecycle":case"page":break;case"dataSource":{if(!s)return void(c.has(e.id)||(F({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=>K(e,n),a=n=>{F({bindingId:e.id,code:"data-query-failed",message:n instanceof Error?n.message:String(n),detail:n}),"stop"===ie(e.errorPolicy,n,e.id)&&x.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:a}):s.request({bindingId:e.id,sourceId:n.sourceId,onUpdate:o,onError:a});break}default:return}y.set(e.id,o),S.set(e.id,P(e))}function _(){for(const e of R())q(e)}function K(e,n){if(u)return;if("off"===d)return;if(x.has(e.id))return void m({kind:"stopped-skipped",bindingId:e.id});if(L(e))return;if(l>=8){const n=h();return void F({bindingId:e.id,code:"cycle-detected"},{chainId:n,traceKind:"cycle-detected"})}const t=h(),o=function(e,n,t,o){return pe(e)?{fire:!1,deferred:!1,reason:"schedule-no-fire"}:(null==e?void 0:e.debounce)?function(e,n,t,o){const a=e.debounce,i=a.leading??!1,r=a.trailing??!0,s=a.windowMs;if(null===n.debouncePendingTimer){if(i){const t=ue(e,n);return t.pass?(n.debounceLeadingFireTs=he(),n.debounceDirty=!1,n.debouncePendingPayload=void 0,n.debouncePendingChainId=null,{fire:!0,deferred:!1,scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{de(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(()=>{de(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(()=>{de(n,e,r,t)},s)}}:{fire:!1,deferred:!1,reason:"debounce-window",scheduleDeferred:t=>{n.debouncePendingTimer=setTimeout(()=>{de(n,e,r,t)},s)}}}(e,n,t,o):function(e,n,t,o){const a=null==e?void 0:e.throttle;if(!a)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 i=a.leading??!0,r=a.trailing??!1,s=a.windowMs,c=he();if(i){const a=n.throttleLastFireTs;if(!(null!==a&&c-a<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 i=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-a);return{fire:!1,deferred:!0,scheduleDeferred:o=>{n.throttleTrailingTimer=setTimeout(()=>{le(n,e,o)},t)}}}return{fire:!1,deferred:!1,reason:"throttle-window",droppedByReschedule:i}}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(()=>{le(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=I.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},I.set(e,n)),n}(e.id),n,t),a=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:a}),o.scheduleDeferred&&o.scheduleDeferred((n,t)=>{u||(m({kind:"scheduled-flushed",bindingId:e.id,chainId:t,payload:n,schedule:a}),J(e,n,t))}),o.reason?m({kind:"scheduled-skipped",bindingId:e.id,chainId:t,reason:o.reason,payload:n,schedule:a}):!o.deferred||o.fire?o.fire&&J(e,n,t):m({kind:"scheduled-deferred",bindingId:e.id,chainId:t,payload:n,schedule:a})}function J(e,t,o){if(u)return;const a=n.getInstance(e.target.instanceId,i);if(!a)return void F({bindingId:e.id,code:"target-not-mounted"},{chainId:o});let r,s;try{r=re(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"===ie(e.errorPolicy,n,e.id)&&x.add(e.id))}if("instanceDataInput"===e.target.kind){const n=a.vm.custom,i=null==n?void 0:n[e.target.key];if(!i||"object"!=typeof i||!0!==i.dataInput)return void F({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{a.setDataInput(e.target.key,r[0])}catch(n){return"stop"===ie(e.errorPolicy,n,e.id)&&x.add(e.id),void F({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{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}}(a,e.target,r),N({bindingId:e.id,source:e.source,target:e.target,payload:t,args:r},o)}catch(n){return"stop"===ie(e.errorPolicy,n,e.id)&&x.add(e.id),void F({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"===ie(e.errorPolicy,n,e.id)&&x.add(e.id),F({bindingId:e.id,code:"invoke-failed",message:n instanceof Error?n.message:String(n),detail:n},{chainId:o}))})}const U=null==(o=r.onAction)?void 0:o.call(r,e=>{var n,t,o,a;if(u)return;if("off"===d)return;const i=e;if(i&&"object"==typeof i)switch(i.type){case"addBinding":{const e=null==(t=null==(n=i.payload)?void 0:n.binding)?void 0:t.id;if(!e)return;const o=O(e);o&&q(o);break}case"updateBinding":{const e=null==(o=i.payload)?void 0:o.bindingId;if(!e)return;j(e);const n=O(e);n&&q(n);break}case"removeBinding":{const e=null==(a=i.payload)?void 0:a.bindingId;if(!e)return;j(e),x.delete(e);break}case"replaceDocument":V(),x.clear(),w.clear(),_();break;case"removeInstance":!function(){const e=new Set(R().map(e=>e.id));for(const n of[...y.keys()])e.has(n)||(j(n),x.delete(n));for(const e of R())q(e)}()}});U&&M.push(U);const X=null==(a=r.onDocumentChange)?void 0:a.call(r,()=>{if(u)return;if("off"===d)return;const e=R(),n=new Set(e.map(e=>e.id)),t=new Set(y.keys());for(const e of t)n.has(e)||j(e);for(const n of e)y.has(n.id)?D(n,S.get(n.id))&&(j(n.id),q(n)):q(n)});function Y(){return new Set(n.listInstances({canvasId:i}).map(e=>e.instanceId))}X&&M.push(X),B=Y();const H=e.watch(n.registryVersion,()=>{if(u)return;if("off"===d)return;const e=Y(),n=ve(e,B),t=ve(B,e);B=e;for(const n of[...w]){const t=O(n);t?G(t,e)&&(w.delete(n),q(t)):w.delete(n)}if(t.size>0)for(const e of[...y.keys()]){const n=O(e);n&&A(n).some(e=>E(e)&&t.has(e.instanceId))&&(j(e),w.add(e))}!function(e){if(0!==e.size)for(const n of R())"lifecycle"===n.source.kind&&"mounted"===n.source.hook&&E({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&K(n,{instanceId:n.source.instanceId,hook:"mounted"})}(n),function(e){if(0!==e.size)for(const n of R())"lifecycle"===n.source.kind&&"unmounted"===n.source.hook&&E({canvasId:n.source.canvasId,instanceId:n.source.instanceId})&&e.has(n.source.instanceId)&&K(n,{instanceId:n.source.instanceId,hook:"unmounted"})}(t)},{flush:"post"});function G(e,n){for(const t of A(e)){if(!E(t))return!1;if(!n.has(t.instanceId))return!1}return!0}return T.push(H),{setMode:function(e){u||e!==d&&(V(!0),x.clear(),w.clear(),d=e,"off"!==e&&_(),"runtime"===e&&function(){for(const e of R())"page"===e.source.kind&&"pageInit"===e.source.hook&&K(e,{hook:"pageInit"})}())},getMode:()=>d,testBinding(e,t){const o=[],a=O(e);if(!a)return o.push({bindingId:e,phase:"skipped",details:{reason:"binding-not-found"}}),o;if(a.disabled)return o.push({bindingId:e,phase:"skipped",details:{reason:"disabled"}}),o;if(L(a))return o.push({bindingId:e,phase:"skipped",details:{reason:"unsupported-cross-canvas"}}),o;let r;try{r=re(a.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(a.target.instanceId,i);if(!s)return o.push({bindingId:e,phase:"skipped",details:{reason:"target-not-mounted"}}),o;if("instanceDataInput"===a.target.kind){const n=s.vm.custom,t=null==n?void 0:n[a.target.key];if(!t||"object"!=typeof t||!0!==t.dataInput)return o.push({bindingId:e,phase:"skipped",details:{reason:"unknown-target-data-input",key:a.target.key}}),o}return o.push({bindingId:e,phase:"calling-target",details:{target:a.target,dryRun:!0}}),o.push({bindingId:e,phase:"done",details:{args:r}}),o},on:(e,n)=>z.on(e,n),startTracing(e){C.start(e)},stopTracing:()=>C.stop(),getTraceBuffer:()=>C.snapshot(),dispose:function(){if(!u){"runtime"===d&&function(){for(const e of R())"page"===e.source.kind&&"pageBeforeUnmount"===e.source.hook&&K(e,{hook:"pageBeforeUnmount"})}(),u=!0,V();for(const e of M)$(e);for(const e of T)$(e);M.length=0,T.length=0,x.clear(),w.clear(),b.clear(),k.clear(),S.clear(),B.clear(),I.clear(),C.stop(),z.clear(),v&&(v(),v=null),d="off"}}}}function ve(e,n){const t=new Set;for(const o of e)n.has(o)||t.add(o);return t}const ye=["data-hc-canvas-id"],Ie=["data-instance-id","data-hc-hidden"],xe={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"}},we={style:{opacity:"0.8"}},be={style:{opacity:"0.6","margin-top":"4px","word-break":"break-all"}},ke={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"}},Se=["data-instance-id","data-hc-placement","data-hc-hidden"],Be={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"}},Me={style:{opacity:"0.6"}},Te=["title"],ze={key:1,class:"hc-page-renderer-empty",style:{padding:"24px",color:"#64748b","font-size":"13px"}},Ce=e.defineComponent({__name:"HyperCardPageRenderer",props:{payload:{},document:{},componentSourceMap:{},schedulerOptions:{},canvasId:{},adapters:{}},setup(t,{expose:o}){var a,i;const r=t,d=r.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=$(r.schedulerOptions),u=e.ref(null);let p=!1;e.onMounted(()=>{V||e.nextTick(()=>{var e;if(p)return;if(!u.value)return;if("fill"!==(null==(e=F.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(()=>{_.value&&(_.value.dispose(),_.value=null),l.dispose(),K&&K.disposeAll(),d!==n.DEFAULT_CANVAS_ID&&n.disposeCanvas(d)});const f=e.ref(new Map),h=e.ref(new Map),g=new Map;function m(e,n){const t=new Map;n.querySelectorAll("[data-hc-slot]").forEach(e=>{if(e.closest("[data-instance-id]")!==n)return;const o=e.getAttribute("data-hc-slot")||Z;t.has(o)||t.set(o,e)});const o=new Map(h.value);o.set(e,t),h.value=o}function v(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=g.get(e);t&&t.disconnect(),m(e,n);const o=new MutationObserver(()=>m(e,n));o.observe(n,{childList:!0,subtree:!0}),g.set(e,o)}(e,n)):!n&&t&&(l.unregister(e),f.value.delete(e),function(e){const n=g.get(e);if(n&&(n.disconnect(),g.delete(e)),h.value.has(e)){const n=new Map(h.value);n.delete(e),h.value=n}}(e))}e.onBeforeUnmount(()=>{for(const e of g.values())e.disconnect();g.clear(),h.value=new Map});const y=e.computed(()=>{var e;const n=(null==(e=r.payload)?void 0:e.document)??r.document??null;return n?c(s(n)):null}),I=e.computed(()=>r.payload?r.payload.componentVersions:r.componentSourceMap??{}),w=e.computed(()=>{const e=y.value,n=I.value;return e?e.instances.map(t=>{var o;const a=n[t.componentVersionKey]??null,i=(null==(o=e.componentOverrides)?void 0:o[t.instanceId])??null,r=i&&i.baseVersionKey===t.componentVersionKey?i:null,s=r?`${r.baseVersionKey}#override:${t.instanceId}`:t.componentVersionKey;if(r)return{instance:t,asset:a,override:r,renderSource:r.source,scopeId:s,status:"ok"};if(!a)return{instance:t,asset:null,override:null,renderSource:null,scopeId:s,status:"missing-source",invalidReason:`componentVersionKey "${t.componentVersionKey}" not in sourceMap`};if("ok"!==a.status)return{instance:t,asset:a,override:null,renderSource:null,scopeId:s,status:"unavailable",invalidReason:a.invalidReason??`component version unavailable (${a.status})`};let c=null;return c=function(e){return!!e&&!0===e.isDraft}(a)?a.lastGoodSource:a.source??null,c?{instance:t,asset:a,override:null,renderSource:c,scopeId:s,status:"ok"}:{instance:t,asset:a,override:null,renderSource:null,scopeId:s,status:"missing-source",invalidReason:"asset.status=ok but source missing"}}):[]});function B(e){const n=I.value[e];return null==n?void 0:n.contract}const M=e.computed(()=>{const e=y.value;return e?ne(e,{resolveContract:B}):[]}),T=e.inject(H,null);e.watch(M,e=>{T&&"function"==typeof T.setLayoutIssues&&T.setLayoutIssues(e)},{immediate:!0});const z=e.computed(()=>{const e=new Set;for(const n of M.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}),C=e.computed(()=>w.value.filter(e=>void 0===e.instance.parentId)),E=e.computed(()=>w.value.filter(e=>void 0!==e.instance.parentId&&D(e.instance.placement)));function L(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=y.value;if(n)return R(F.value??void 0,n.instances,e.instanceId)}(e),o=x(n,e.zIndex,e.rotation,t),a=k(e.layoutItem,t);return a&&Object.assign(o,a),o}const P=e.computed(()=>{var e;return b(null==(e=F.value)?void 0:e.rootLayout)});function O(e){if(!e.parentId)return null;const n=h.value.get(e.parentId);return n?n.get(ee(e))??null:null}function A(e){return{position:"absolute",left:"8px",top:8+28*E.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 N(e){return"实例 "+e.instance.instanceId+':slot "'+ee(e.instance)+'" 不可用'}const F=e.computed(()=>{var e;return(null==(e=y.value)?void 0:e.layout)??null}),j=e.computed(()=>{if(!F.value)return null;if(V){const e=V.measuredCanvasSize.value;return{width:`${e.w}px`,height:`${e.h}px`,overflow:F.value.canvas.overflow??"hidden"}}return{width:S(F.value.canvas.width),height:S(F.value.canvas.height),overflow:F.value.canvas.overflow??"hidden"}}),V=e.inject(H,void 0),q=V?null:U(null==(a=r.adapters)?void 0:a.assets),_=e.shallowRef(null),K=V||!(null==(i=r.adapters)?void 0:i.data)?null:X(r.adapters.data);if(!V){const n=me({canvasId:d,source:{getDocument:()=>y.value,onDocumentChange:n=>e.watch(y,n,{flush:"post"})},dataStore:K??void 0});_.value=n,e.nextTick(()=>{n.setMode("runtime")})}o({binding:_,data:V?{invalidateDataSource(e){V.dataStore.invalidate(e)},getDataSourceSnapshot:()=>V.dataStore.getSnapshot()}:K?{invalidateDataSource(e){K.invalidate(e)},getDataSourceSnapshot:()=>K.getSnapshot()}:null});const J=e.ref(null);let Y=0;e.watch(()=>{var e,n;return null==(n=null==(e=F.value)?void 0:e.background)?void 0:n.image},e=>{Y++;const n=Y;if(!e)return void(J.value=null);const t=(o=e,V?V.resolveAsset(o):q.resolve(o));var o;"string"!=typeof t?(J.value=null,t.then(t=>{var o,a;n===Y&&(null==(a=null==(o=F.value)?void 0:o.background)?void 0:a.image)===e&&(J.value=t||null)},()=>{n===Y&&(J.value=null)})):J.value=t||null},{immediate:!0,deep:!0});const G=e.computed(()=>{var e;const n=null==(e=F.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&&J.value&&(t.backgroundImage=`url("${J.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)=>F.value&&j.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",...j.value,...P.value??{}})},[G.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"hc-canvas-bg","data-hc-canvas-bg":"",style:e.normalizeStyle(G.value)},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,t=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:t.instance.instanceId,ref_for:!0,ref:e=>v(t.instance.instanceId,e),"data-instance-id":t.instance.instanceId,"data-hc-hidden":t.instance.hidden?"true":void 0,style:e.normalizeStyle(L(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",ke)):(e.openBlock(),e.createElementBlock("div",xe,[o[0]||(o[0]=e.createElementVNode("div",{style:{"font-weight":"600","margin-bottom":"4px"}}," ⚠️ 组件不可渲染 ",-1)),e.createElementVNode("div",we,e.toDisplayString(t.instance.alias??t.instance.instanceId),1),e.createElementVNode("div",be,e.toDisplayString(t.invalidReason),1)]))],12,Ie)),[[e.vShow,!t.instance.hidden]])),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(E.value,t=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`child-${t.instance.instanceId}`},[O(t.instance)&&!z.value.has(t.instance.instanceId)?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:O(t.instance)},[e.withDirectives(e.createElementVNode("div",{ref_for:!0,ref:e=>v(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(L(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",Be,[o[1]||(o[1]=e.createElementVNode("div",{style:{"font-weight":"600"}},"⚠️ 组件不可渲染",-1)),e.createElementVNode("div",Me,e.toDisplayString(t.invalidReason),1)]))],12,Se),[[e.vShow,!t.instance.hidden]])],8,["to"])):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-layout-issue-warning",title:N(t),style:e.normalizeStyle(A(t))}," ⚠ 布局问题:"+e.toDisplayString(t.instance.instanceId)+'(slot "'+e.toDisplayString(e.unref(ee)(t.instance))+'") ',13,Te))],64))),128))],12,ye)):(e.openBlock(),e.createElementBlock("div",ze," No page to render(payload / document 都未提供) "))}}),Ee=new Map,Le=new Set;function Pe(){const e=Object.freeze(Array.from(Ee.keys()));for(const n of Le)try{n(e)}catch{}}function De(e,n){Ee.set(e,n),Pe()}function Re(e){Ee.delete(e)&&Pe()}function Oe(e,n){var o;const a=n.document;switch(e.type){case"addInstance":{const{instance:n}=e.payload;return a.getInstance(n.instanceId)?null:[{type:"removeInstance",payload:{instanceId:n.instanceId}}]}case"removeInstance":{const{instanceId:n}=e.payload,o=a.getInstance(n);if(!o)return null;const i=a.document.bindings.filter(e=>N(e,n)),r=[{type:"addInstance",payload:{instance:Ae(o)}}];for(const e of i)r.push({type:"addBinding",payload:{binding:t(e)}});return r}case"updateInstance":{const{instanceId:n,patch:o}=e.payload,i=a.getInstance(n);if(!i)return null;const r={};for(const e of Object.keys(o)){const n=i[e];r[e]=$e(n)?t(n):n}return[{type:"updateInstance",payload:{instanceId:n,patch:r}}]}case"moveInstance":{const{instanceId:n,x:t,y:o}=e.payload,i=a.getInstance(n);return i?i.rect.x===t&&i.rect.y===o?null:i.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...i.layoutBox}}}]:[{type:"moveInstance",payload:{instanceId:n,x:i.rect.x,y:i.rect.y}}]:null}case"resizeInstance":{const{instanceId:n,w:t,h:o}=e.payload,i=a.getInstance(n);return i?i.rect.w===t&&i.rect.h===o?null:i.layoutBox?[{type:"updateLayoutBox",payload:{instanceId:n,patch:{...i.layoutBox}}}]:[{type:"resizeInstance",payload:{instanceId:n,w:i.rect.w,h:i.rect.h}}]:null}case"setInstanceProp":{const{instanceId:n,key:t,value:o}=e.payload,i=a.getInstance(n);return i?i.props[t]===o?null:[{type:"updateInstance",payload:{instanceId:n,patch:{props:{...i.props}}}}]:null}case"addBinding":{const{binding:n}=e.payload;return a.document.bindings.some(e=>e.id===n.id)?null:[{type:"removeBinding",payload:{bindingId:n.id}}]}case"removeBinding":{const{bindingId:n}=e.payload,o=a.document.bindings.find(e=>e.id===n);return o?[{type:"addBinding",payload:{binding:t(o)}}]:null}case"updateBinding":{const{bindingId:n,patch:o}=e.payload,i=a.document.bindings.find(e=>e.id===n);if(!i)return null;const r={};for(const e of Object.keys(o)){const n=i[e];r[e]=$e(n)?t(n):n}return[{type:"updateBinding",payload:{bindingId:n,patch:r}}]}case"updateLayout":{const{patch:n}=e.payload,o={};for(const e of Object.keys(n)){const n=a.document.layout[e];o[e]=$e(n)?t(n):n}return[{type:"updateLayout",payload:{patch:o}}]}case"setRootLayout":{const{rootLayout:n}=e.payload,o=a.document.layout.rootLayout,i=void 0!==o;return i||null!==n?[{type:"setRootLayout",payload:{rootLayout:i?t(o):null}}]:null}case"setComponentOverride":{const{instanceId:n,override:i}=e.payload;if(void 0===a.getInstance(n))return null;const r=null==(o=a.document.componentOverrides)?void 0:o[n],s=void 0!==r;return s||null!==i?[{type:"setComponentOverride",payload:{instanceId:n,override:s?t(r):null}}]:null}case"replaceDocument":return[{type:"replaceDocument",payload:{document:t(a.document)}}];case"setInstanceLocked":{const{instanceId:n,locked:t}=e.payload,o=a.getInstance(n);if(!o)return null;const i=o.locked??!1,r=o.lockPosition,s=o.lockSize;return i===t&&r===(!!t||void 0)&&s===(!!t||void 0)?null:[{type:"updateInstance",payload:{instanceId:n,patch:{locked:i,lockPosition:r,lockSize:s}}}]}case"duplicateInstance":{const{instanceId:n,newInstanceId:t}=e.payload;return a.getInstance(n)?a.getInstance(t)?null:[{type:"removeInstance",payload:{instanceId:t}}]:null}case"setInstanceSize":{const{instanceId:n,size:o}=e.payload,i=a.getInstance(n);if(!i)return null;const r=i.size,s="size"in i&&void 0!==r;return s||null!==o?[{type:"setInstanceSize",payload:{instanceId:n,size:(s?t(r):null)??null}}]:null}case"setContainerLayout":{const{instanceId:n,containerLayout:o}=e.payload,i=a.getInstance(n);if(!i)return null;const r=i.containerLayout,s="containerLayout"in i&&void 0!==r;return s||null!==o?[{type:"setContainerLayout",payload:{instanceId:n,containerLayout:(s?t(r):null)??null}}]:null}case"updateLayoutBox":{const{instanceId:n,patch:t}=e.payload,o=a.getInstance(n);if(!o)return null;const i=o.layoutBox??{x:o.rect.x,y:o.rect.y,width:o.rect.w,height:o.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]=i[e],s=!0)}return"px"!==t.widthMode&&"percent"!==t.widthMode&&"fill"!==t.widthMode&&"auto"!==t.widthMode||(r.widthMode=i.widthMode,s=!0),"px"!==t.heightMode&&"percent"!==t.heightMode&&"fill"!==t.heightMode&&"auto"!==t.heightMode||(r.heightMode=i.heightMode,s=!0),"hidden"!==t.overflow&&"visible"!==t.overflow&&"auto"!==t.overflow||(r.overflow=i.overflow,s=!0),s?[{type:"updateLayoutBox",payload:{instanceId:n,patch:r}}]:null}case"updateLayoutItem":{const{instanceId:n,patch:o}=e.payload,i=a.getInstance(n);if(!i)return null;const r=i.layoutItem,s="layoutItem"in i&&void 0!==r,c=null===o;if(!s&&c)return null;if(!c){const e=["order","grow","shrink","row","column","rowSpan","columnSpan","ratio"];let n=!1;for(const t of e){const e=o[t];if("number"==typeof e&&Number.isFinite(e)){n=!0;break}}if(!n)return null}return[{type:"updateLayoutItem",payload:{instanceId:n,patch:(s?t(r):null)??null}}]}case"updateRotation":{const{instanceId:n,value:t}=e.payload,o=a.getInstance(n);if(!o)return null;if(!Number.isFinite(t))return null;const i=o.rotation,r="number"==typeof i&&Number.isFinite(i)?i: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 $e(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function Ae(e){return t(e)}function Ne(n,t={}){const o=t.maxSize??100,a=e.ref([]),i=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()},a.value.push(n),a.value.length>o&&a.value.shift(),i.value.length>0&&(i.value=[]),r={redo:[],undo:[]},s=null)}const d={onBeforeAction(e){if(n.isRecordingSuppressed.value)return;const t=Oe(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(){a.value=[],i.value=[],r={redo:[],undo:[]},s=null}return{undo:function(){if(0===a.value.length)return;const e=a.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.undo)n.dispatch(t);n.endBatch("undo")}),i.value.push(e)},redo:function(){if(0===i.value.length)return;const e=i.value.pop();n.suppressRecording(()=>{n.beginBatch();for(const t of e.redo)n.dispatch(t);n.endBatch("redo")}),a.value.push(e)},clear:u,canUndo:e.computed(()=>a.value.length>0),canRedo:e.computed(()=>i.value.length>0),undoStackSize:e.computed(()=>a.value.length),redoStackSize:e.computed(()=>i.value.length),dispose:function(){l(),u()}}}function Fe(e,n,t){let o=null;for(const a of e)for(const e of n){const n=e.pos-a,i=Math.abs(n);i<=t&&(!o||i<Math.abs(o.delta))&&(o={delta:n,candidate:e,targetPos:a})}return o}function je(e){var n,t,o,a;const i=e.threshold??5,r=function(e){if(0===e.length)return null;let n=1/0,t=-1/0,o=1/0,a=-1/0;for(const i of e)i.x<n&&(n=i.x),i.x+i.w>t&&(t=i.x+i.w),i.y<o&&(o=i.y),i.y+i.h>a&&(a=i.y+i.h);return{left:n,right:t,top:o,bottom:a,centerX:(n+t)/2,centerY:(o+a)/2,width:t-n,height:a-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=Fe(d,s,i),p=Fe(l,c,i),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,a=Math.min(r.top+h,n),i=Math.max(r.bottom+h,t);g.push({axis:"x",pos:u.candidate.pos,from:a,to:i,kind:u.candidate.kind})}if(p){const n=(null==(a=p.candidate.source)?void 0:a.x)??0,t=p.candidate.source?p.candidate.source.x+p.candidate.source.w:e.canvasSize.w,o=Math.min(r.left+f,n),i=Math.max(r.right+f,t);g.push({axis:"y",pos:p.candidate.pos,from:o,to:i,kind:p.candidate.kind})}return{dx:f,dy:h,lines:g}}function Ve(e){return e.shift||e.ctrl||e.meta}function qe(e,n,t){const o=n.getBoundingClientRect(),a={x:e.x-o.left,y:e.y-o.top};return t.toCanvasPoint(a)}function _e(e,n,t){const o=new Map;for(let e=0;e<n.length;e++)o.set(n[e].instanceId,e);const a=new Map;function i(e){const t=a.get(e);if(t)return t;const o=[];let i=e;const r=new Set;for(;i&&!r.has(i);){r.add(i),o.push(i);const e=n.find(e=>e.instanceId===i);if(!(null==e?void 0:e.parentId))break;i=e.parentId}const s=o.reverse();return a.set(e,s),s}function r(e,t){const a=i(e),r=i(t);let s=0;for(;s<a.length&&s<r.length&&a[s]===r[s];)s++;if(s===a.length&&s===r.length)return 0;if(s===a.length)return-1;if(s===r.length)return 1;const c=a[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 a=n[o];if(a.hidden)continue;const i=(null==t?void 0:t(a.instanceId))??a.rect;if(!(e.x>=i.x&&e.x<=i.x+i.w&&e.y>=i.y&&e.y<=i.y+i.h))continue;if(null===s){s=a.instanceId,c=o;continue}const d=r(a.instanceId,s);let l;l=d>0||!(d<0)&&o>c,l&&(s=a.instanceId,c=o)}return s}function Ke(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 Je(e,n,t){const o=[];for(const a of n){if(a.hidden)continue;const n=(null==t?void 0:t(a.instanceId))??a.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(a.instanceId)}return o}const Ue=["e","s","se"];function Xe(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 Ye(e,n,t){var o;const a=t??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!a)return null;const i=n??"default",r=""===i?"default":i,s="undefined"!=typeof globalThis&&(null==(o=globalThis.CSS)?void 0:o.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),c=Xe(a,`[data-instance-id="${s(e)}"] [data-hc-slot="${s(r)}"]`);return c&&c instanceof HTMLElement?c.getBoundingClientRect():null}function He(e,n,t){var o;const a=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!a)return null;if("function"!=typeof a.querySelector)return null;const i=`[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?Xe(a,i):a.querySelector(i);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null}function Ge(e,n){return R(e.document.document.layout,e.document.document.instances,n)}function We(e){return"free"===e||"none"===e||void 0===e}function Qe(e,n,t){if(!n)return null;const o=He(e,n,!0);if(!o)return null;const a=n.getBoundingClientRect(),i=t.toCanvasPoint({x:o.left-a.left,y:o.top-a.top}),r=t.toCanvasPoint({x:o.right-a.left,y:o.bottom-a.top});return{x:i.x,y:i.y,w:Math.max(0,r.x-i.x),h:Math.max(0,r.y-i.y)}}function Ze(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,a=Math.max(0,Math.min(1e3,n));return{...e,mode:"percent",value:a}}case"fill":case"hug":case"auto":return{mode:"px",value:o,min:e.min,max:e.max}}}function en(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 nn(e,n){const t=new Set(n.map(e=>e.instanceId));return e.filter(e=>t.has(e))}function tn(n,t={}){const o=e.reactive({active:!1,start:null,end:null,additive:!1,priorSelection:[]}),a=e.reactive({status:"idle",startPt:null,startRects:new Map,deferredClickSelect:null}),i=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?Ke(o.start,o.end):null),p=e.computed(()=>"active"===a.status),f=e.computed(()=>"active"===i.status);function h(){o.active=!1,o.start=null,o.end=null,o.additive=!1,o.priorSelection=[]}function g(){a.status="idle",a.startPt=null,a.startRects=new Map,a.deferredClickSelect=null,r.value=[]}function m(){i.status="idle",i.handle=null,i.startPt=null,i.startRect=null,i.instanceId=null,i.placement=null,i.startSize=null,i.startOutletCanvasSize=null,i.parentLayoutMode=void 0,i.startLayoutBox=null}return{marquee:o,marqueeRect:u,drag:a,isDragging:p,resize:i,isResizing:f,snapLines:r,cannotDragSlotChildEvent:s,cannotDragLayoutManagedChildEvent:d,handlePointerDown(e,i){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=Ve(i),h="marquee"===p?null:_e(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)),i=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}}):i&&g&&u.draggable&&"inspect"!==p?a.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=Ge(n,h),y="inspect"===p;if(o||!u.draggable||y||(null==t?void 0:t.hidden))return{startTracking:!1};if(!We(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 a.status="pending",a.startPt={...e},a.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"===i.status&&i.startPt&&i.startRect&&i.instanceId){const t=e.x-i.startPt.x,o=e.y-i.startPt.y,a=i.startRect,r=i.handle,s=n.document.getInstance(i.instanceId);if(!s)return;const c=i.parentLayoutMode,d="flex"===c||"grid"===c;let l=a.x,u=a.y,p=a.w,f=a.h;"e"===r||"ne"===r||"se"===r?p=a.w+t:d||"w"!==r&&"nw"!==r&&"sw"!==r||(p=a.w-t,l=a.x+t),"s"===r||"se"===r||"sw"===r?f=a.h+o:d||"n"!==r&&"ne"!==r&&"nw"!==r||(f=a.h-o,u=a.y+o),p<8&&(d||"w"!==r&&"nw"!==r&&"sw"!==r||(l=a.x+a.w-8),p=8),f<8&&(d||"n"!==r&&"nw"!==r&&"ne"!==r||(u=a.y+a.h-8),f=8);const h=i.startLayoutBox,g=i.startOutletCanvasSize,m="e"===r||"ne"===r||"se"===r||!d&&("w"===r||"nw"===r||"sw"===r),v="s"===r||"se"===r||"sw"===r||!d&&("n"===r||"ne"===r||"nw"===r),y=!d&&("w"===r||"nw"===r||"sw"===r),I=!d&&("n"===r||"ne"===r||"nw"===r),x=m?en(h.widthMode,p,g?g.w:null):null,w=v?en(h.heightMode,f,g?g.h:null):null,b="canvas"===i.placement||"absolute"===i.placement,k=!(x&&"px"!==x.mode||w&&"px"!==w.mode||m&&"px"!==h.widthMode||v&&"px"!==h.heightMode);if(b&&k)(m&&s.rect.w!==p||v&&s.rect.h!==f)&&n.dispatch({type:"resizeInstance",payload:{instanceId:i.instanceId,w:m?p:s.rect.w,h:v?f:s.rect.h}}),(y&&s.rect.x!==l||I&&s.rect.y!==u)&&n.dispatch({type:"moveInstance",payload:{instanceId:i.instanceId,x:y?l:s.rect.x,y:I?u:s.rect.y}});else{const e={};x&&(e.widthMode=x.mode,e.width=x.value),w&&(e.heightMode=w.mode,e.height=w.value),y&&(e.x=l),I&&(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:i.instanceId,patch:e}})}if(("container"===i.placement||"slot"===i.placement)&&(null!==i.startSize||k)){const e=i.startSize,t={};m?t.width=Ze(null==e?void 0:e.width,p,g?g.w:null):(null==e?void 0:e.width)&&(t.width=JSON.parse(JSON.stringify(e.width))),v?t.height=Ze(null==e?void 0:e.height,f,g?g.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:i.instanceId,size:t}})}return}if("pending"===a.status&&a.startPt){const t=e.x-a.startPt.x,o=e.y-a.startPt.y;t*t+o*o>=9&&(a.status="active",n.beginBatch())}if("active"===a.status&&a.startPt){const o=e.x-a.startPt.x,i=e.y-a.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?Qe(e,l,n.viewport)??t:t,h=[];for(const[e,t]of a.startRects){const a=n.document.getInstance(e);if(!a)continue;const r=f(e,a.rect);h.push({x:t.x+o,y:t.y+i,w:r.w,h:r.h})}const g=[],m=new Set(a.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)??[],x=[],w=[];for(const e of I)"x"===e.axis?x.push(e.position):w.push(e.position);const b=y?je({draggedRects:h,otherRects:g,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 k=o+b.dx,S=i+b.dy;for(const[e,t]of a.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"===i.status){const e="slot"===i.placement||"container"===i.placement?"resize-slot-child":"resize";return n.endBatch(e),void m()}if("active"===a.status)return n.endBatch("drag"),void g();if("pending"===a.status)return a.deferredClickSelect&&n.dispatch({type:"select",payload:{instanceId:a.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 a=nn(Je(e,t),t);if(o.additive){const e=nn(o.priorSelection,t),i=Array.from(new Set([...e,...a]));n.dispatch({type:"selectAll",payload:{instanceIds:i}})}else a.length>0&&n.dispatch({type:"selectAll",payload:{instanceIds:a}})}h()},cancelMarquee(){h()},cancelDrag(){"active"===a.status&&n.endBatch("drag-cancel"),g()},handleResizeStart(e,o,a){var r,s,c,d;const l=n.document.getInstance(e);if(!l)return{startTracking:!1};if(!0===(l.lockSize??l.locked))return{startTracking:!1};if(l.hidden)return{startTracking:!1};if(!n.effectiveBehavior.value.resizable)return{startTracking:!1};const u="slot"===l.placement||"container"===l.placement,p=Ge(n,e);if("split"===p)return{startTracking:!1};if(("flex"===p||"grid"===p)&&!Ue.includes(o))return{startTracking:!1};i.status="active",i.handle=o,i.startPt={...a};const f=Qe(e,(null==(r=t.getRoot)?void 0:r.call(t))??null,n.viewport);i.startRect=f??{...l.rect},i.instanceId=e,i.placement=u?"container":"canvas",i.parentLayoutMode=p,i.startLayoutBox=l.layoutBox?JSON.parse(JSON.stringify(l.layoutBox)):{x:l.rect.x,y:l.rect.y,width:l.rect.w,height:l.rect.h,widthMode:"px",heightMode:"px",overflow:"hidden"},i.startSize=u&&l.size?JSON.parse(JSON.stringify(l.size)):null;const h=l.parentId,g=l.slot,m=(null==(s=t.getRoot)?void 0:s.call(t))??null;let v=h?Ye(h,g,m):null;if(h&&(!v||0===v.width&&0===v.height)){const n=Xe(m,`[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)&&(v=e)}}if(v){const e=n.viewport.scale.value||1;i.startOutletCanvasSize={w:v.width/e,h:v.height/e}}else if(void 0===h)i.startOutletCanvasSize={w:n.measuredCanvasSize.value.w,h:n.measuredCanvasSize.value.h};else{const n=i.startLayoutBox.widthMode,t=i.startLayoutBox.heightMode,o="percent"===n||"percent"===t;o&&console.debug("[hc-canvas/interaction] resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:h,slot:g});const a=i.startSize,r="percent"===(null==(c=null==a?void 0:a.width)?void 0:c.mode)||"percent"===(null==(d=null==a?void 0:a.height)?void 0:d.mode);!o&&r&&console.debug("[hc-canvas/interaction] slot child resize: 父 outlet 找不到,percent 模式将退化到 px。",{instanceId:e,parentId:h,slot:g}),i.startOutletCanvasSize=null}return n.beginBatch(),{startTracking:!0}},cancelResize(){if("active"===i.status){const e="slot"===i.placement||"container"===i.placement?"resize-slot-child-cancel":"resize-cancel";n.endBatch(e)}m()}}}function on(e,n){return{ok:!1,reason:e,message:n}}function an(e,n,t,o={}){const a=new Map;for(const n of e)a.set(n.instanceId,n);const i=a.get(n);if(!i)return on("instance-not-exists",`实例 "${n}" 不存在,无法 reparent`);const r=null===t.parentId||void 0===t.parentId?void 0:t.parentId;if(r===n)return on("self-parent",`parentId 不能等于自身 "${n}"`);if(void 0!==r){const e=a.get(r);if(!e)return on("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 on("cycle",`目标 parent "${r}" 是 "${n}" 的后代,会循环`);const e=a.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=a.get(r),d=s(c.componentVersionKey);if(!d)return{ok:!0};const l=d.slotsDecl??[];if(0===l.length)return on("parent-not-layout",`父组件 "${c.componentId}" 不是布局组件(slotsDecl 空)`);const u=void 0===t.slot||""===t.slot||"default"===t.slot?Z:t.slot,p=(f=u,l.find(e=>e.name===f));var f;if(!p)return on("slot-not-exists",`slot "${u}" 不在父 "${c.componentId}" 的 slotsDecl`);if(p.accepts&&p.accepts.length>0&&!p.accepts.includes(i.componentId))return on("accepts-violation",`slot "${u}" 不允许 componentId "${i.componentId}"(accepts: ${p.accepts.join(", ")})`);if(!0!==p.multiple){const t=e.filter(e=>e.instanceId!==n&&e.parentId===r&&ee(e)===u);if(t.length>0)return on("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&&ee(e)===u);if(t.length+1>p.maxChildren)return on("max-children-exceeded",`slot "${u}" 最多接受 ${p.maxChildren} 个子(已有 ${t.length} 个)`)}return{ok:!0}}function rn(e){const n=new Set(e.map(e=>e.instanceId)),t=new Map;for(const n of e)t.set(n.instanceId,cn(n));const o=[],a=new Map;e.forEach((e,i)=>{const r={inst:e,node:t.get(e.instanceId),originalIndex:i},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);a.has(s)||a.set(s,[]),a.get(s).push(r)}else o.push(r)});for(const[e,n]of a){const o=t.get(e);o&&(o.children=sn(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 sn(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 cn(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 dn(e,n){for(const t of e){if(t.instanceId===n)return[t];if(t.children&&t.children.length>0){const e=dn(t.children,n);if(e.length>0)return[t,...e]}}return[]}function ln(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 a=[o];let i=o;const r=e.length;for(;i&&i.parentId;){if(a.length>r){console.warn(`[hc-canvas/instance-tree] breadcrumb for "${n}" exceeds depth ${r},疑似环,截断`);break}const e=t.get(i.parentId);if(!e)break;a.unshift(e),i=e}return a}function un(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 pn(e){if(0===e.length)return null;let n=1/0,t=1/0,o=-1/0,a=-1/0;for(const i of e)i.x<n&&(n=i.x),i.y<t&&(t=i.y),i.x+i.w>o&&(o=i.x+i.w),i.y+i.h>a&&(a=i.y+i.h);return{x:n,y:t,w:o-n,h:a-t}}function fn(e){return pn(e.map(e=>e.rect))}function hn(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 pn(o)}function gn(e,n,t){const o=(null==t?void 0:t.padding)??40,a=Math.max(1,n.w-2*o),i=Math.max(1,n.h-2*o),r=Math.max(1,e.w),s=Math.max(1,e.h);let c=Math.min(a/r,i/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 mn(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 vn(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 yn(e){if(!(e&&e instanceof HTMLElement))return!1;const n=e.tagName;return"INPUT"===n||"TEXTAREA"===n||"SELECT"===n||!!e.isContentEditable}function In(e,n){const t=vn(n);for(const n of e.keys)if(xn(n)===t)return!0;return!1}function xn(e){return e.split("+").map(e=>e.trim().toLowerCase()).join("+")}function wn(n,t){const o=Ne(n,t.recorder);function a(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 a=o.getBoundingClientRect();return n.viewport.toCanvasPoint({x:e.x-a.left,y:e.y-a.top})}function i(e,t){const o=n.document.getInstance(e);if(!o)return null;const a=(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:a,...void 0!==(null==t?void 0:t.offset)?{offset:t.offset}:{}}}),n.document.getInstance(a)?a:null}function r(){return JSON.parse(JSON.stringify(n.document.document.layout))}function s(){return rn(n.document.document.instances)}function c(e,o){const a=n.document.getInstance(e);if(!a)return console.warn(`[hc-canvas/handle] ${o}: instance "${e}" 不存在`),!1;const i=t.getStageEl();if(!i)return console.warn(`[hc-canvas/handle] ${o}: stage 未挂载,跳过滚动(${e})`),!1;const r=Qe(e,i,n.viewport),s=r&&(r.w>0||r.h>0)?r:{x:a.rect.x,y:a.rect.y,w:a.rect.w,h:a.rect.h},c=i.getBoundingClientRect(),d=n.viewport.scale.value,l=c.width/2-(s.x+s.w/2)*d,u=c.height/2-(s.y+s.h/2)*d;return n.viewport.setPan(l,u),!0}const d=e.ref(null);let l=0;function u(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 p(){const e=t.getStageEl();if(!e)return null;const n=e.getBoundingClientRect();return{w:n.width,h:n.height}}function f(){return{scale:n.viewport.scale.value,panX:n.viewport.panX.value,panY:n.viewport.panY.value}}function h(){return fn(n.document.document.instances)}function g(){return hn(n.document.document.instances,n.selection.selectedIds.value)}function m(e,t){const o=p();if(!o)return void n.viewport.setScale(e);const a=f();let i;if(null==t?void 0:t.center)i=t.center;else{const e=mn(a,o);i={x:e.x+e.w/2,y:e.y+e.h/2}}const r=i.x*a.scale+a.panX,s=i.y*a.scale+a.panY,c=r-i.x*e,d=s-i.y*e;n.viewport.setScale(e),n.viewport.setPan(c,d)}function v(e,t){m(n.viewport.scale.value+e,t)}function y(){n.viewport.resetView()}function I(e,t){const o=p();if(!o)return void console.warn("[hc-canvas/handle] scrollToRect: stage 未挂载,跳过");const a=gn(e,o,t);n.viewport.setScale(a.scale),n.viewport.setPan(a.panX,a.panY)}function x(e){const n=h();n&&I(n,e)}function w(e){const n=g();n&&I(n,e)}const b=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 k(){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 a=o?10:1,i=n.selection.selectedIds.value;if(0===i.length)return;const r=!n.isBatching.value;r&&n.beginBatch();try{for(const o of i){const i=n.document.getInstance(o);if(!i||!0===(i.lockPosition??i.locked))continue;const r=Ge(n,o);We(r)?n.dispatch({type:"moveInstance",payload:{instanceId:o,x:i.rect.x+e*a,y:i.rect.y+t*a}}):"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 B(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 M(e){const t=n.selection.selectedIds.value;if(0===t.length)return;const o=n.document.document.instances;if(0===o.length)return;const a=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),i=new Set(t),r=[];for(let e=0;e<a.length;e++)i.has(a[e].instanceId)&&r.push(e);if(0===r.length)return;if(r.length===a.length)return;const s=r.map(e=>a[e]),c=a.filter(e=>!i.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<a.length&&i.has(a[e].instanceId);)e++;if(e>=a.length)return;const n=a[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&&i.has(a[e].instanceId);)e--;if(e<0)return;const n=a[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=!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 T={undo:{execute:()=>o.undo(),canExecute:()=>o.canUndo.value},redo:{execute:()=>o.redo(),canExecute:()=>o.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=i(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:()=>v(.1),canExecute:()=>!0},zoomOut:{execute:()=>v(-.1),canExecute:()=>!0},zoom100:{execute:()=>m(1),canExecute:()=>!0},resetViewport:{execute:()=>y(),canExecute:()=>!0},fitToContent:{execute:()=>x(),canExecute:()=>null!==h()},fitToSelection:{execute:()=>w(),canExecute:()=>null!==g()},fitToSelectionOrContent:{execute:()=>{g()?w():x()},canExecute:()=>null!==g()||null!==h()},nudgeSelection:{execute:e=>{const n=e??{dx:0,dy:0};S(n.dx,n.dy,!1)},canExecute:k},nudgeSelectionLarge:{execute:e=>{const n=e??{dx:0,dy:0};S(n.dx,n.dy,!0)},canExecute:k},lockSelection:{execute:()=>B(!0),canExecute:()=>n.selection.selectedIds.value.length>0},unlockSelection:{execute:()=>B(!1),canExecute:()=>n.selection.selectedIds.value.length>0},bringForward:{execute:()=>M("forward"),canExecute:()=>n.selection.selectedIds.value.length>0},sendBackward:{execute:()=>M("backward"),canExecute:()=>n.selection.selectedIds.value.length>0},bringToFront:{execute:()=>M("toFront"),canExecute:()=>n.selection.selectedIds.value.length>0},sendToBack:{execute:()=>M("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;D(!(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;P(!(null==t?void 0:t.visible))},canExecute:()=>!0}};function z(e,t){const o=null===t?null:JSON.parse(JSON.stringify(t));n.dispatch({type:"setComponentOverride",payload:{instanceId:e,override:o}})}function C(e,t){const o=e??"notEditingText";return"always"===o||("notEditingText"===o?!yn(t.target):"design"===o?!yn(t.target)&&!1!==n.effectiveBehavior.value.draggable:"hasSelection"===o&&!yn(t.target)&&n.selection.selectedIds.value.length>0)}function E(){return n.document.document.layout.guides??{}}function L(e){n.dispatch({type:"updateLayout",payload:{patch:{guides:e}}})}function P(e){const n=E();L({...n,ruler:{...n.ruler??{},visible:e}})}function D(e){const n=E();L({...n,grid:{...n.grid??{},visible:e}})}const R=e.computed(()=>{const e=n.selection.selectedIds.value;if(0===e.length)return[];const t=new Set(e);return n.document.document.instances.filter(e=>t.has(e.instanceId))}),O=n.selection.selectedIds,$=e.readonly(O),A=e.readonly(n.isBatching);let N=null,F=null;return{dispatch:e=>n.dispatch(e),beginBatch:()=>n.beginBatch(),endBatch:e=>n.endBatch(e),isBatching:A,getSnapshot:()=>JSON.parse(JSON.stringify(n.document.document)),selectedIds:$,selectedInstances:R,viewport:n.viewport,clientToCanvasPoint:a,getInstanceAtClientPoint:function(e){const o=t.getStageEl();if(!o)return null;const i=_e(a(e),n.document.document.instances,e=>Qe(e,o,n.viewport));return i?n.document.getInstance(i)??null:null},getDropTarget:function(e,o,a){var i;const r=o??(null==(i=t.getStageEl)?void 0:i.call(t))??("undefined"!=typeof document&&"function"==typeof document.querySelectorAll?document:null);if(!r)return null;const s=void 0!==(null==a?void 0:a.excludeInstanceId),c=s?`[data-instance-id="${u(a.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 p=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,a=n;for(;a;)o++,a=a.parentElement;(!p||o>p.depth)&&(p={el:n,depth:o})}if(!p)return null;const f=p.el,h=f.closest("[data-instance-id]");if(!h)return null;const g=h.getAttribute("data-instance-id");return g&&n.document.getInstance(g)?{parentId:g,slot:f.getAttribute("data-hc-slot")||"default",outletEl:f}:null},duplicateInstance:i,undo:o.undo,redo:o.redo,canUndo:o.canUndo,canRedo:o.canRedo,undoStackSize:o.undoStackSize,redoStackSize:o.redoStackSize,clearHistory:o.clear,getLayoutConfig:r,updateCanvasSize:function(e){const t={...r().canvas,...e};n.dispatch({type:"updateLayout",payload:{patch:{canvas:t}}})},updateCanvasBackground:function(e){if(null===e)return void n.dispatch({type:"updateLayout",payload:{patch:{background:void 0}}});const t={...r().background??{},...e};n.dispatch({type:"updateLayout",payload:{patch:{background:t}}})},updateBehavior:function(e){const t={...r().behavior??{},...e};n.dispatch({type:"updateLayout",payload:{patch:{behavior:t}}})},setInteractionOptions:function(e){n.setInteractionOptions(e)},getEffectiveBehavior:function(){return{...n.effectiveBehavior.value}},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}})},getInstanceTree:s,getInstanceList:function(){return n.document.document.instances.map(e=>JSON.parse(JSON.stringify(e)))},getInstance:function(e){const t=n.document.getInstance(e);return t?JSON.parse(JSON.stringify(t)):null},getSelectedPath:function(){const e=n.selection.primaryId.value;return e?dn(s(),e):[]},getBreadcrumb:function(e){return ln(n.document.document.instances,e).map(e=>JSON.parse(JSON.stringify(e)))},focusInstance:function(e){n.document.getInstance(e)?(n.dispatch({type:"select",payload:{instanceId:e}}),c(e,"focusInstance")):console.warn(`[hc-canvas/handle] focusInstance: instance "${e}" 不存在`)},scrollToInstance:function(e){c(e,"scrollToInstance")},moveInstanceInTree:function(e,o){var a,i,r;const s=an(n.document.document.instances,e,o,{resolveContract:t.resolveContract});if(!s.ok)return console.warn(`[hc-canvas/handle] moveInstanceInTree 守门拒绝(${s.reason}): ${s.message}`),void function(e,n,t,o){l++,d.value={instanceId:e,target:{...n},reason:t,message:o,token:l}}(e,o,s.reason,s.message??`reparent rejected: ${s.reason}`);const c=n.document.getInstance(e),u=null===o.parentId?void 0:o.parentId,p=(c.parentId||void 0)!==(u||void 0),f=c.slot!==o.slot,h={};if(p&&(h.parentId=u),f&&(h.slot=o.slot),p){const e=void 0===u?"canvas":"container";c.placement!==e&&(h.placement=e);const t=n.document.document.layout,o=void 0===u?(null==(a=null==t?void 0:t.rootLayout)?void 0:a.mode)??"free":(null==(r=null==(i=n.document.getInstance(u))?void 0:i.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??0,column:e.column??0})}}const g=[];if(void 0!==o.index){const t=un(n.document.document.instances,u,o.slot).filter(n=>n.instanceId!==e),a=Math.max(0,Math.min(o.index,t.length));t.splice(a,0,c),t.forEach((e,n)=>{const o=t.length-1-n;(e.zIndex??0)!==o&&g.push({id:e.instanceId,zIndex:o})})}if(0===Object.keys(h).length&&0===g.length)return;const m=!n.isBatching.value;m&&n.beginBatch();try{Object.keys(h).length>0&&n.dispatch({type:"updateInstance",payload:{instanceId:e,patch:h}});for(const e of g)n.dispatch({type:"updateInstance",payload:{instanceId:e.id,patch:{zIndex:e.zIndex}}})}finally{m&&n.endBatch("moveInstanceInTree")}},canReparent:function(e,o){return an(n.document.document.instances,e,o,{resolveContract:t.resolveContract})},cannotReparentEvent:e.readonly(d),cannotDragLayoutManagedChildEvent:n.cannotDragLayoutManagedChildEvent,resolveAsset:function(e){return n.resolveAsset(e)},getViewportState:f,getVisibleBounds:function(){const e=p();return e?mn(f(),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:h,getSelectionBounds:g,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:m,zoomBy:v,zoomToPoint:function(e,o){const a=t.getStageEl();if(!a)return void console.warn("[hc-canvas/handle] zoomToPoint: stage 未挂载,跳过");const i=a.getBoundingClientRect(),r=o.x-i.left,s=o.y-i.top,c=f(),d=r-(r-c.panX)/c.scale*e,l=s-(s-c.panY)/c.scale*e;n.viewport.setScale(e),n.viewport.setPan(d,l)},resetViewport:y,fitToContent:x,fitToSelection:w,scrollToRect:I,toolMode:n.toolMode,getToolMode:function(){return n.toolMode.value},setToolMode:function(e){n.setToolMode(e)},setTemporaryToolMode:function(e){n.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 b){if(!In(n,e))continue;if(!C(n.when,e))continue;const t=T[n.command];return!!t&&!!t.canExecute()&&(t.execute(n.payload),!1!==n.preventDefault&&e.preventDefault(),!0)}return!1},executeCommand:function(e,n){const t=T[e];t?t.canExecute()&&t.execute(n):console.warn(`[hc-canvas/handle] executeCommand: 未知命令 "${e}"`)},canExecuteCommand:function(e){const n=T[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:z,discardComponentOverride:function(e){z(e,null)},getLayoutIssues:function(){return n.layoutIssues.value},setRulerVisible:P,setGridVisible:D,updateRulerConfig:function(e){const n=E();L({...n,ruler:{...n.ruler??{},...e}})},updateGridConfig:function(e){const n=E();L({...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 a={id:o,axis:e.axis,position:e.position};return void 0!==e.locked&&(a.locked=e.locked),void 0!==e.label&&(a.label=e.label),L({...n,items:[...t,a]}),o},removeGuide:function(e){const n=E(),t=n.items??[];t.some(n=>n.id===e)&&L({...n,items:t.filter(n=>n.id!==e)})},updateGuide:function(e,n){const t=E(),o=t.items??[],a=o.findIndex(n=>n.id===e);if(a<0)return void console.warn(`[hc-canvas/handle] updateGuide: id "${e}" 不存在,忽略`);const{id:i,...r}=n,s={...o[a],...r},c=[...o];c[a]=s,L({...t,items:c})},getGuides:function(){return(E().items??[]).map(e=>({...e}))},clearGuides:function(){const e=E();e.items&&0!==e.items.length&&L({...e,items:[]})},getMouseCanvasPoint:function(){const e=n.mouseCanvasPoint.value;return e?{x:e.x,y:e.y}:null},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}})},getInstanceOutletRect:function(e,n){if("undefined"==typeof document||"function"!=typeof document.querySelector)return null;const t=n??"default",o=""===t?"default":t,a=`[data-instance-id="${u(e)}"]`,i=`[data-hc-slot="${u(o)}"]`,r=document.querySelector(`${a} ${i}`);return r&&r instanceof HTMLElement?r.getBoundingClientRect():null},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}})},setBindingMode:function(e){null==N||N.setMode(e)},getBindingMode:function(){return(null==N?void 0:N.getMode())??"off"},testBinding:function(e,n){return(null==N?void 0:N.testBinding(e,n))??[]},on:function(e,n){return N?N.on(e,n):()=>{}},attachBindingDelegate:function(e,n){N=e,null===e?F=null:arguments.length>=2&&(F=n??null)},invalidateDataSource:function(e){null==F||F.invalidate(e)},getDataSourceSnapshot:function(){return(null==F?void 0:F.getSnapshot())??{entries:[]}},startTracing:function(e){null==N||N.startTracing(e)},stopTracing:function(){return(null==N?void 0:N.stopTracing())??[]},getTraceBuffer:function(){return(null==N?void 0:N.getTraceBuffer())??[]},dispose:o.dispose}}const bn=Symbol("hc:canvas:reparent-bridge");function kn(e){return"preview"===e||"runtime"===e?"runtime":"off"}const Sn=(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=Q(),o=e.ref(null);let a=null;const i=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&&(a=new ResizeObserver(r),a.observe(o.value)),window.addEventListener("resize",r)}),e.onBeforeUnmount(()=>{null==a||a.disconnect(),a=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:i.value,transformOrigin:"0 0"})},[e.renderSlot(n.$slots,"default",{},void 0,!0)],4)],512))}})),Bn=["data-mode"],Mn=e.defineComponent({__name:"RuntimeLayer",props:{componentSourceMap:{},mode:{default:"design"},schedulerOptions:{},canvasId:{}},setup(n){const t=Q(),o=e.computed(()=>t.document.document);return(a,i)=>(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(Ce,{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,Bn))}});function Tn(e,n,t,o=0){if(!n||n.length<2)return[];if(e.w<=0||e.h<=0)return[];const a=n.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),i=a.reduce((e,n)=>e+n,0);if(i<=0)return[];const r=a.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+=a[n]/i*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 zn(e,n,t,o,a=0){if(!e||n<0||n>=e.length-1)return e.slice();const i=e.map(e=>"number"==typeof e&&Number.isFinite(e)&&e>0?e:0),r=i[n],s=i[n+1],c=r+s;if(c<=0)return i;const d=i.length-1,l=Math.max(0,a)*d,u=Math.max(0,o-l);if(u<=0)return i;const p=i.reduce((e,n)=>e+n,0);if(p<=0)return i;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=i.slice();return v[n]=g,v[n+1]=m,v}function Cn(n){const t=e.reactive({status:"idle",parentId:null,dividerIndex:null,startRatios:null,parentAxisPx:0,startPt:null,direction:null,gap:0}),o=e.computed(()=>"active"===t.status);function a(){t.status="idle",t.parentId=null,t.dividerIndex=null,t.startRatios=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};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.parentAxisPx=e.parentAxisPx,t.startPt={...e.canvasPt},t.direction=e.direction,t.gap=e.gap,n.beginBatch(),{startTracking:!0}):{startTracking:!1}},handleSplitDividerMove:function(e){if("active"!==t.status)return;if(!t.startPt||!t.startRatios||!t.direction||null===t.dividerIndex)return;const o=n.document.getInstance(t.parentId);if(!o||!o.containerLayout||"split"!==o.containerLayout.mode)return;const a="horizontal"===t.direction?e.x-t.startPt.x:e.y-t.startPt.y,i=zn(t.startRatios,t.dividerIndex,a,t.parentAxisPx,t.gap),r=o.containerLayout;if(r.ratios.length===i.length&&r.ratios.every((e,n)=>e===i[n]))return;const s={...r,ratios:i};n.dispatch({type:"setContainerLayout",payload:{instanceId:t.parentId,containerLayout:s}})},handleSplitDividerEnd:function(){"active"===t.status&&(n.endBatch("split-divider-drag"),a())},cancelSplitDividerDrag:function(){"active"===t.status&&n.endBatch("split-divider-cancel"),a()}}}function En(e){return!0===(e.lockPosition??e.locked)}function Ln(e){return!0===(e.lockSize??e.locked)}function Pn(e){return En(e)||Ln(e)}const Dn=["data-mode"],Rn=["data-selection-box","data-locked","data-placement"],On=["data-lock-badge"],$n=["data-resize-handle","data-resize-instance","onPointerdown"],An=["data-hc-divider-direction","data-hc-divider-index","data-hc-parent-id","data-hc-divider-dragging","onPointerdown"],Nn=["data-axis","data-kind"],Fn=["data-hc-reparent-state"],jn=["data-hc-reparent-ghost-reason"],Vn={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"}},qn=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,a=Q(),i=tn(a,{getRoot:()=>D(),getDomBox:e=>{const n=Qe(e,D(),a.viewport);return n?0===n.w&&0===n.h?null:n:null}}),r=Cn(a),s=e.inject(bn,null);e.watch(()=>i.cannotDragSlotChildEvent.value,e=>{e&&o("cannot-drag-slot-child",{instanceId:e.instanceId,parentId:e.parentId})},{flush:"sync"}),e.watch(()=>i.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(a.selection.selectedIds.value);return a.document.document.instances.filter(n=>e.has(n.instanceId)&&!n.hidden)}),u=e.computed(()=>a.measuredCanvasSize.value),p=e.shallowRef({});function f(){const e=D(),n={};for(const t of l.value)n[t.instanceId]=Qe(t.instanceId,e,a.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(),(i.isResizing.value||i.isDragging.value||r.isDragging.value)&&(m=requestAnimationFrame(v))}function y(e){const n=p.value[e.instanceId];if(n)return n;const t=Qe(e.instanceId,D(),a.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(()=>a.selection.selectedIds.value,()=>{g()},{flush:"post",deep:!0}),e.watch(()=>a.viewport.scale.value,()=>g()),e.watch(()=>[a.viewport.panX.value,a.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(()=>i.isResizing.value,e=>{e&&null===m&&(m=requestAnimationFrame(v))}),e.watch(()=>i.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)}))),x=new Set(Ue),w=e.computed(()=>{if(!a.effectiveBehavior.value.resizable)return[];const e=[];for(const n of I.value){const t=n.instance;if(!0===(t.lockSize??t.locked))continue;if(!n.box)continue;const o=Ge(a,t.instanceId),{x:i,y:r,w:s,h:c}=n.box,d=[{handle:"nw",cx:i,cy:r,cursor:"nwse-resize"},{handle:"n",cx:i+s/2,cy:r,cursor:"ns-resize"},{handle:"ne",cx:i+s,cy:r,cursor:"nesw-resize"},{handle:"e",cx:i+s,cy:r+c/2,cursor:"ew-resize"},{handle:"se",cx:i+s,cy:r+c,cursor:"nwse-resize"},{handle:"s",cx:i+s/2,cy:r+c,cursor:"ns-resize"},{handle:"sw",cx:i,cy:r+c,cursor:"nesw-resize"},{handle:"w",cx:i,cy:r+c/2,cursor:"ew-resize"}];let l=d;"split"===o?l=[]:"flex"!==o&&"grid"!==o||(l=d.filter(e=>x.has(e.handle)));for(const n of l)e.push({instanceId:t.instanceId,handle:n.handle,left:n.cx-4,top:n.cy-4,cursor:n.cursor})}return e});function b(e,n,t){return"percent"===n?`${Math.round(t)}%`:"fill"===n?"fill":"auto"===n?"auto":String(Math.round(e))}const k=e.computed(()=>{if(!i.isResizing.value)return null;const e=i.resize.instanceId;if(!e)return null;const n=a.document.getInstance(e);if(!n)return null;const t=y(n);if(!t)return null;const o=n.layoutBox,r=b(t.w,null==o?void 0:o.widthMode,(null==o?void 0:o.width)??t.w),s=b(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"},B=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=a.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=a.document.getInstance(e);if(!n)continue;const t=n.containerLayout;if(!t||"split"!==t.mode)continue;const i=y(n);if(!i)continue;const r=t,s=r.direction,c=r.gap??0,d=r.ratios??[],l=Tn(i,d,s,c);0!==l.length&&o.push({parentId:e,direction:s,gap:c,ratios:d.slice(),parentBox:i,dividers:l})}return o}),M=e.computed(()=>i.isResizing.value&&i.resize.handle?S[i.resize.handle]:r.isDragging.value?"horizontal"===r.drag.direction?"ew-resize":"ns-resize":i.isDragging.value?"grabbing":"hand"===a.toolMode.value?$?"grabbing":"grab":"marquee"===a.toolMode.value?"crosshair":"default"),T=e.shallowRef(null);function z(){if(!s)return!1;if(!i.isDragging.value)return!1;if(1!==i.drag.startRects.size)return!1;const e=Array.from(i.drag.startRects.keys())[0],n=a.document.getInstance(e);return!(!n||void 0!==n.placement&&"canvas"!==n.placement&&"absolute"!==n.placement||!0===(n.lockPosition??n.locked)||n.hidden)}let C=null,E=null;function L(e){if(!z()||!s)return void(null!==T.value&&(T.value=null));const n=Array.from(i.drag.startRects.keys())[0],t=s.getDropTarget(e,{excludeInstanceId:n});if(!t)return void(null!==T.value&&(T.value=null));const o=a.document.getInstance(n);if(o&&o.parentId===t.parentId&&(o.slot??"default")===(t.slot||"default"))return void(null!==T.value&&(T.value=null));const r=function(e){const n=D();if(!n)return null;const t=e.getBoundingClientRect(),o=n.getBoundingClientRect(),i=a.viewport.toCanvasPoint({x:t.left-o.left,y:t.top-o.top}),r=a.viewport.toCanvasPoint({x:t.right-o.left,y:t.bottom-o.top});return{x:i.x,y:i.y,w:Math.max(0,r.x-i.x),h:Math.max(0,r.y-i.y)}}(t.outletEl);if(!r)return void(null!==T.value&&(T.value=null));const c={parentId:t.parentId,slot:t.slot},d=s.canReparent(n,c);T.value={rect:r,target:t,result:d}}const P=e.computed(()=>T.value);function D(){return d||(c.value?(d=c.value.closest("[data-hc-stage]"),d):null)}function R(e){const n=D();if(!n)return;const t=qe({x:e.clientX,y:e.clientY},n,a.viewport);a.setMouseCanvasPoint(t)}function O(){a.setMouseCanvasPoint(null)}let $=null;function A(e){if(0!==e.button)return;const n=D();if(!n)return;if("hand"===a.toolMode.value)return $={clientX:e.clientX,clientY:e.clientY,panX:a.viewport.panX.value,panY:a.viewport.panY.value},window.addEventListener("pointermove",N),window.addEventListener("pointerup",F),void e.preventDefault();const t=qe({x:e.clientX,y:e.clientY},n,a.viewport),{startTracking:o}=i.handlePointerDown(t,{shift:e.shiftKey,ctrl:e.ctrlKey,meta:e.metaKey});o&&(j(),e.preventDefault())}function N(e){if(!$)return;const n=e.clientX-$.clientX,t=e.clientY-$.clientY;a.viewport.setPan($.panX+n,$.panY+t)}function F(){$=null,window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",F)}function j(){window.addEventListener("pointermove",V),window.addEventListener("pointerup",q),window.addEventListener("keydown",_)}function V(e){const n=D();if(!n)return;const t=qe({x:e.clientX,y:e.clientY},n,a.viewport);var o;i.handlePointerMove(t),r.handleSplitDividerMove(t),r.isDragging.value&&g(),o={x:e.clientX,y:e.clientY},C=o,"undefined"!=typeof requestAnimationFrame?null===E&&(E=requestAnimationFrame(()=>{E=null,C&&L(C)})):L(o)}function q(e){if(r.isDragging.value)return r.handleSplitDividerEnd(),void K();e&&s&&z()&&L({x:e.clientX,y:e.clientY}),null!==E&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(E),E=null);const n=T.value;if(n&&s){const e=Array.from(i.drag.startRects.keys())[0];return n.result.ok&&e?(i.cancelDrag(),s.moveInstanceInTree(e,{parentId:n.target.parentId,slot:n.target.slot})):i.cancelDrag(),T.value=null,void K()}i.handlePointerUp(),K()}function _(e){"Escape"===e.key&&(i.cancelResize(),i.cancelDrag(),i.cancelMarquee(),r.cancelSplitDividerDrag(),T.value=null,null!==E&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(E),E=null),F(),K())}function K(){window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",q),window.removeEventListener("keydown",_)}return e.onBeforeUnmount(()=>{i.cancelResize(),i.cancelDrag(),i.cancelMarquee(),r.cancelSplitDividerDrag(),T.value=null,K(),F(),null!==h&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(h),h=null),null!==m&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(m),m=null),null!==E&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(E),E=null),C=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(a).effectiveBehavior.value.selectable?"auto":"none",cursor:M.value,zIndex:9999}),onPointerdown:A,onPointermove:R,onPointerleave:O},[(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(Pn)(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(Pn)(n.instance)?"#9ca3af":"#3b82f6"),boxSizing:"border-box",pointerEvents:"none",boxShadow:"0 0 0 1px rgba(59, 130, 246, 0.2)"})},null,12,Rn)):e.createCommentVNode("",!0)],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(I.value.filter(n=>e.unref(Pn)(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,On)):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=D();if(!o)return;const r=qe({x:e.clientX,y:e.clientY},o,a.viewport),{startTracking:s}=i.handleResizeStart(n,t,r);s&&(j(),e.preventDefault())}(e,n.instanceId,n.handle)},null,44,$n))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.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=D();if(!o)return;const i=a.document.getInstance(n);if(!i)return;const s=i.containerLayout;if(!s||"split"!==s.mode)return;const c=s,d=y(i);if(!d)return;const l="horizontal"===c.direction?d.w:d.h,u=qe({x:e.clientX,y:e.clientY},o,a.viewport),{startTracking:p}=r.handleSplitDividerStart({parentId:n,dividerIndex:t,startRatios:(c.ratios??[]).slice(),parentAxisPx:l,direction:c.direction,gap:c.gap??0,canvasPt:u});p&&(j(),e.preventDefault())}(e,n.parentId,o.index)},null,44,An))],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(i).marqueeRect.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-marquee-box","data-marquee-box":"",style:e.normalizeStyle({position:"absolute",left:e.unref(i).marqueeRect.value.x+"px",top:e.unref(i).marqueeRect.value.y+"px",width:e.unref(i).marqueeRect.value.w+"px",height:e.unref(i).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(i).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,Nn))),128)),P.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[t.$slots["reparent-ghost"]?e.renderSlot(t.$slots,"reparent-ghost",{key:0,state:P.value}):(e.openBlock(),e.createElementBlock("div",{key:1,class:"hc-reparent-ghost","data-hc-reparent-ghost":"","data-hc-reparent-state":P.value.result.ok?"legal":"illegal",style:e.normalizeStyle({position:"absolute",left:P.value.rect.x+"px",top:P.value.rect.y+"px",width:P.value.rect.w+"px",height:P.value.rect.h+"px",pointerEvents:"none",boxSizing:"border-box",border:"2px solid "+(P.value.result.ok?"#22c55e":"#ef4444"),background:P.value.result.ok?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)"})},[!P.value.result.ok&&P.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":P.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"}},[P.value.result.reason?(e.openBlock(),e.createElementBlock("span",Vn,"["+e.toDisplayString(P.value.result.reason)+"]",1)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(P.value.result.message),1)],8,jn)):e.createCommentVNode("",!0)],12,Fn))],64)):e.createCommentVNode("",!0)],44,Dn))}}),_n=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 a=n,i=o;let r=!1;const s=G({initialDocument:a.modelValue,getMode:()=>a.mode,adapters:a.adapters});W(s);const c=e.ref(null),d=wn(s,{getStageEl:()=>{var e;return(null==(e=c.value)?void 0:e.querySelector("[data-hc-stage]"))??null},resolveContract:function(e){var n;const t=null==(n=a.componentSourceMap)?void 0:n[e];if(t)return"contract"in t&&t.contract?t.contract:void 0}}),l=a.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)}`}(),u=!!s.adapters.data,p=me({canvasId:l,source:{getDocument:()=>s.document.document,onAction:e=>s.registerHooks({onAfterAction:n=>e(n)})},initialMode:kn(a.mode),dataStore:u?s.dataStore:void 0});d.attachBindingDelegate(p,u?s.dataStore:null),i("context-ready",s),i("handle-ready",d);const f={getDropTarget:(e,n)=>d.getDropTarget(e,c.value,n),canReparent:(e,n)=>d.canReparent(e,n),moveInstanceInTree:(e,n)=>d.moveInstanceInTree(e,n),cannotReparentEvent:d.cannotReparentEvent};function h(){i("update:modelValue",JSON.parse(JSON.stringify(s.document.document)))}return e.provide(bn,f),e.watch(()=>a.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||h()},{deep:!0,flush:"sync"}),e.watch(()=>s.isBatching.value,(e,n)=>{!n||e||r||h()},{flush:"sync"}),e.onMounted(()=>{De(l,d),e.nextTick(()=>{p.setMode(kn(a.mode))})}),e.watch(()=>a.mode,e=>{p.setMode(kn(e))}),e.onBeforeUnmount(()=>{p.dispose(),d.attachBindingDelegate(null,null),Re(l),d.dispose(),s.dispose()}),t({context:s,handle:d,canvasId:l}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"stageContainerEl",ref:c,class:"hc-canvas-designer",style:{width:"100%",height:"100%",position:"relative"},"data-hc-canvas-designer":""},[e.createVNode(Sn,null,{default:e.withCtx(()=>[e.createVNode(Mn,{"component-source-map":n.componentSourceMap,mode:n.mode,"scheduler-options":n.schedulerOptions,"canvas-id":e.unref(l)},null,8,["component-source-map","mode","scheduler-options","canvas-id"]),"runtime"!==n.mode?(e.openBlock(),e.createBlock(qn,{key:0,mode:n.mode,onCannotDragSlotChild:o[0]||(o[0]=e=>i("cannot-drag-slot-child",e)),onCannotDragLayoutManagedChild:o[1]||(o[1]=e=>i("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(d).viewport,handle:e.unref(d)}),e.renderSlot(t.$slots,"default")]),_:3})],512))}});function Kn(e={}){const{canvasWidth:n=1280,canvasHeight:t=720,rootLayout:o="free",instances:a=[],bindings:i=[]}=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:a,bindings:i}}const Jn={event:["instanceEvent"],init:["lifecycle","page"],data:["dataSource"]};function Un(e){return Jn[e.type].includes(e.source.kind)}function Xn(e,n,t,o){const a={level:n,code:e,bindingId:t.id,message:`${e} on binding "${t.id}"`};return o.instanceId&&(a.instanceId=o.instanceId),o.canvasId&&(a.canvasId=o.canvasId),a}function Yn(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 Hn(e){switch(e.source.kind){case"instanceEvent":case"lifecycle":return e.source.canvasId;case"page":case"dataSource":return}}function Gn(e){switch(e.target.kind){case"instanceMethod":case"instanceEmit":case"instanceDataInput":return e.target.canvasId}}exports.CANVAS_CONTEXT_KEY=H,exports.CANVAS_REPARENT_BRIDGE_KEY=bn,exports.CanvasStage=Sn,exports.DEFAULT_FIT_PADDING=40,exports.DIVIDER_HIT_THICKNESS=8,exports.DRAG_THRESHOLD_CANVAS_PX=3,exports.EFFECTIVE_DEFAULT_SLOT=Z,exports.HyperCardCanvasDesigner=_n,exports.HyperCardPageRenderer=Ce,exports.InteractionLayer=qn,exports.MAX_INSTANCE_TREE_DEPTH=8,exports.MIN_INSTANCE_SIZE=8,exports.MIN_RATIO_FRACTION=.05,exports.RuntimeLayer=Mn,exports.SLOT_CHILD_RESIZE_HANDLES=Ue,exports.VERSION="0.0.0-d3.6c-stage",exports.applyEffectiveSplitRatiosToDocument=c,exports.applySplitDividerDrag=zn,exports.assertNeverBindingSource=F,exports.assertNeverBindingTarget=j,exports.bindingModeForCanvasMode=kn,exports.bindingReferencesInstance=N,exports.buildInstanceTree=rn,exports.canReparent=an,exports.canvasSizeToCss=S,exports.cleanLayoutItem=O,exports.clientToCanvas=qe,exports.computeContentBounds=fn,exports.computeEffectiveSplitRatios=m,exports.computeFit=gn,exports.computeInverse=Oe,exports.computeNextAxisSize=Ze,exports.computeNextLayoutBoxAxis=en,exports.computeParentLayoutMode=R,exports.computeSelectionBounds=hn,exports.computeSlotChildCanvasRect=Qe,exports.computeSnap=je,exports.computeSplitDividers=Tn,exports.computeVisibleBounds=mn,exports.containerLayoutToCss=b,exports.createAssetResolver=U,exports.createCanvasContext=G,exports.createCanvasHandle=wn,exports.createCanvasInteraction=tn,exports.createCommandRecorder=Ne,exports.createDocumentStore=_,exports.createFreePageDocument=function(e={}){return Kn({...e,rootLayout:"free"})},exports.createMinimalPageDocument=Kn,exports.createRenderScheduler=$,exports.createSelectionStore=K,exports.createSplitDividerInteraction=Cn,exports.createViewportStore=J,exports.effectiveSlot=ee,exports.emptyPageDocument=function(){return{schemaVersion:"1",layout:{type:"free",canvas:{width:{mode:"fill"},height:{mode:"fill"}}},instances:[],bindings:[]}},exports.filterExistingIds=nn,exports.filterInstancesInRect=Je,exports.findInstanceBreadcrumb=ln,exports.findInstancePath=dn,exports.getBindingInstanceRefs=A,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 Ee.get(e)??null},exports.getInstanceWrapperRectFromDom=He,exports.getOutletRectFromDom=Ye,exports.getParentLayoutMode=Ge,exports.getSiblings=un,exports.getSlotChildRectFromDom=function(e,n){var t;const o=n??("undefined"!=typeof document&&"function"==typeof document.querySelector?document:null);if(!o)return null;const a="undefined"!=typeof globalThis&&(null==(t=globalThis.CSS)?void 0:t.escape)?globalThis.CSS.escape:e=>e.replace(/["\\]/g,e=>`\\${e}`),i=o.querySelector(`[data-instance-id="${a(e)}"][data-hc-placement="slot"]`);return i&&i instanceof HTMLElement?i.getBoundingClientRect():null},exports.hitTestInstance=_e,exports.isAdditive=Ve,exports.isCanvasRootPlacement=function(e){return"canvas"===e||"absolute"===e||void 0===e},exports.isContainerChildPlacement=D,exports.isDraftKey=function(e){return"string"==typeof e&&e.includes("@draft:")},exports.isEditingText=yn,exports.isFreePositionLayoutMode=We,exports.isInstanceEffectivelyLocked=Pn,exports.isInstancePositionLocked=En,exports.isInstanceSizeLocked=Ln,exports.isV1Layout=y,exports.layoutItemToCss=k,exports.listRegisteredCanvasIds=function(){return Object.freeze(Array.from(Ee.keys()))},exports.matchBinding=In,exports.migrateInstanceToLayoutBox=L,exports.migrateLayoutV0ToV1=v,exports.migratePlacementToCanvasContainer=E,exports.migrateRootLayout=P,exports.normalizeComponentOverrides=d,exports.normalizeInstanceSlotFields=l,exports.normalizeKeyString=xn,exports.normalizeMarqueeRect=Ke,exports.normalizePageBindings=a,exports.normalizePageDocument=s,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 a=e.slice(0,n),i=e.slice(n+1);return a&&i?{kind:"draft",componentId:t,pageId:a,baseVersion:i,baseVersionKey:`${t}@${i}`}:null}return o?{kind:"published",componentId:t,version:o}:null},exports.parseKeyEvent=vn,exports.provideCanvasContext=W,exports.registerDesignerHandle=De,exports.renderLayoutBoxStyle=x,exports.resolveCanvasSizePx=function(e,n=1920){return"px"===e.mode?e.value:n},exports.resolveMeasuredCanvasSizePx=I,exports.subscribeDesignerRegistry=function(e){return Le.add(e),()=>{Le.delete(e)}},exports.unionRects=pn,exports.unregisterDesignerHandle=Re,exports.useCanvasContext=Q,exports.validateBindings=function(e,n){var t,o,a;const i=[],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(Un(n)){if(void 0!==s){const e=Hn(n),t=Gn(n);void 0!==e&&e!==s&&i.push(Xn("unsupported-cross-canvas","error",n,{canvasId:e})),void 0!==t&&t!==s&&i.push(Xn("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)&&i.push(Xn("unknown-source-event","error",n,{instanceId:t.instanceId}))}}else i.push(Xn("orphan-binding","warn",n,{instanceId:n.source.instanceId}));break}case"lifecycle":r.get(n.source.instanceId)||i.push(Xn("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)&&i.push(Xn("unknown-target-method","error",n,{instanceId:t.instanceId}))}}else i.push(Xn("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)&&i.push(Xn("unknown-target-event","error",n,{instanceId:t.instanceId}))}}else i.push(Xn("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 a=d.get(o.instanceId);a&&!a.dataInputsDecl.some(n=>n.key===e)?i.push(Xn("unknown-target-data-input","error",n,{instanceId:o.instanceId})):l&&(null==(t=l.get(o.instanceId))||t.delete(e))}}else i.push(Xn("orphan-binding","warn",n,{instanceId:n.target.instanceId}));break}}(null==(o=n.schedule)?void 0:o.throttle)&&n.schedule.throttle.windowMs<16&&i.push(Xn("schedule-window-too-small","info",n,Yn(n))),(null==(a=n.schedule)?void 0:a.debounce)&&n.schedule.debounce.windowMs<16&&i.push(Xn("schedule-window-too-small","info",n,Yn(n)))}else i.push(Xn("invalid-type-source-kind","error",n,Yn(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`};i.push(n)}return i},exports.validateInstanceTree=ne,exports.wirePageBindings=me;
|