@hypertools/sdk 0.1.0 → 0.2.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 +1 -1
- package/README.md +19 -19
- package/dist/capture/index.d.ts +1 -1
- package/dist/capture/index.js +13 -1
- package/dist/capture/index.js.map +2 -2
- package/dist/controls/index.js +13 -1
- package/dist/controls/index.js.map +2 -2
- package/dist/core/index.js +13 -1
- package/dist/core/index.js.map +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +14 -1
- package/dist/index.js.map +3 -3
- package/dist/react/index.js +13 -1
- package/dist/react/index.js.map +2 -2
- package/dist/recording/index.js +13 -1
- package/dist/recording/index.js.map +2 -2
- package/package.json +34 -13
- package/dist/codegen/index.d.ts +0 -6
- package/dist/codegen/index.d.ts.map +0 -1
- package/dist/codegen/index.js +0 -800
- package/dist/codegen/index.js.map +0 -13
- package/dist/export/bundler.d.ts +0 -55
- package/dist/export/bundler.d.ts.map +0 -1
- package/dist/export/generators/index.d.ts +0 -6
- package/dist/export/generators/index.d.ts.map +0 -1
- package/dist/export/generators/webComponent.d.ts +0 -29
- package/dist/export/generators/webComponent.d.ts.map +0 -1
- package/dist/export/index.d.ts +0 -19
- package/dist/export/index.d.ts.map +0 -1
- package/dist/export/index.js +0 -800
- package/dist/export/index.js.map +0 -13
- package/dist/export/runtime.d.ts +0 -46
- package/dist/export/runtime.d.ts.map +0 -1
- package/dist/frame/cssBridge.d.ts +0 -34
- package/dist/frame/cssBridge.d.ts.map +0 -1
- package/dist/frame/index.d.ts +0 -9
- package/dist/frame/index.d.ts.map +0 -1
- package/dist/frame/index.js +0 -3
- package/dist/frame/index.js.map +0 -24
- package/dist/frame/runtime.d.ts +0 -39
- package/dist/frame/runtime.d.ts.map +0 -1
- package/dist/frame/types.d.ts +0 -119
- package/dist/frame/types.d.ts.map +0 -1
- package/dist/frame/utils/dom.d.ts +0 -11
- package/dist/frame/utils/dom.d.ts.map +0 -1
- package/dist/frame/wrapper-app/WrapperApp.d.ts +0 -16
- package/dist/frame/wrapper-app/WrapperApp.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/CanvasSizeWidget.d.ts +0 -17
- package/dist/frame/wrapper-app/components/CanvasSizeWidget.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/ControlsPanel.d.ts +0 -11
- package/dist/frame/wrapper-app/components/ControlsPanel.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/ExportWidget.d.ts +0 -16
- package/dist/frame/wrapper-app/components/ExportWidget.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/ResizeHandles.d.ts +0 -19
- package/dist/frame/wrapper-app/components/ResizeHandles.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/SandboxContainer.d.ts +0 -16
- package/dist/frame/wrapper-app/components/SandboxContainer.d.ts.map +0 -1
- package/dist/frame/wrapper-app/components/index.d.ts +0 -5
- package/dist/frame/wrapper-app/components/index.d.ts.map +0 -1
- package/dist/frame/wrapper-app/context/CanvasContext.d.ts +0 -37
- package/dist/frame/wrapper-app/context/CanvasContext.d.ts.map +0 -1
- package/dist/frame/wrapper-app/context/index.d.ts +0 -2
- package/dist/frame/wrapper-app/context/index.d.ts.map +0 -1
- package/dist/frame/wrapper-app/index.d.ts +0 -9
- package/dist/frame/wrapper-app/index.d.ts.map +0 -1
- package/dist/frame/wrapper-app/types.d.ts +0 -38
- package/dist/frame/wrapper-app/types.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hypertools/sdk
|
|
3
|
+
* Copyright (c) 2025 HyperTools Team
|
|
4
|
+
*
|
|
5
|
+
* Vanilla-first SDK for embedding interactive creative coding experiences.
|
|
6
|
+
* Supports p5.js, Three.js, WebGL, and more.
|
|
7
|
+
*
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @see https://github.com/hypertools/sdk
|
|
10
|
+
*/
|
|
1
11
|
var sR=Object.create;var{getPrototypeOf:lR,defineProperty:IW,getOwnPropertyNames:iR}=Object;var nR=Object.prototype.hasOwnProperty;var zQ=(Z,Y,K)=>{K=Z!=null?sR(lR(Z)):{};let z=Y||!Z||!Z.__esModule?IW(K,"default",{value:Z,enumerable:!0}):K;for(let $ of iR(Z))if(!nR.call(z,$))IW(z,$,{get:()=>Z[$],enumerable:!0});return z};var m1=(Z,Y)=>()=>(Y||Z((Y={exports:{}}).exports,Y),Y.exports);var G8=m1((rT,UG)=>{(function(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart==="function")__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var Z="18.3.1",Y=Symbol.for("react.element"),K=Symbol.for("react.portal"),z=Symbol.for("react.fragment"),$=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),B=Symbol.for("react.provider"),j=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),b=Symbol.for("react.suspense_list"),k=Symbol.for("react.memo"),a=Symbol.for("react.lazy"),DJ=Symbol.for("react.offscreen"),_J=Symbol.iterator,yJ="@@iterator";function CJ(D){if(D===null||typeof D!=="object")return null;var A=_J&&D[_J]||D[yJ];if(typeof A==="function")return A;return null}var g={current:null},KJ={transition:null},c={current:null,isBatchingLegacy:!1,didScheduleLegacyUpdate:!1},qJ={current:null},d={},UJ=null;function SJ(D){UJ=D}d.setExtraStackFrame=function(D){UJ=D},d.getCurrentStack=null,d.getStackAddendum=function(){var D="";if(UJ)D+=UJ;var A=d.getCurrentStack;if(A)D+=A()||"";return D};var zJ=!1,i=!1,$J=!1,LJ=!1,JJ=!1,YJ={ReactCurrentDispatcher:g,ReactCurrentBatchConfig:KJ,ReactCurrentOwner:qJ};YJ.ReactDebugCurrentFrame=d,YJ.ReactCurrentActQueue=c;function TJ(D){{for(var A=arguments.length,V=Array(A>1?A-1:0),C=1;C<A;C++)V[C-1]=arguments[C];AJ("warn",D,V)}}function QJ(D){{for(var A=arguments.length,V=Array(A>1?A-1:0),C=1;C<A;C++)V[C-1]=arguments[C];AJ("error",D,V)}}function AJ(D,A,V){{var C=YJ.ReactDebugCurrentFrame,m=C.getStackAddendum();if(m!=="")A+="%s",V=V.concat([m]);var IJ=V.map(function(XJ){return String(XJ)});IJ.unshift("Warning: "+A),Function.prototype.apply.call(console[D],console,IJ)}}var BQ={};function vQ(D,A){{var V=D.constructor,C=V&&(V.displayName||V.name)||"ReactClass",m=C+"."+A;if(BQ[m])return;QJ("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",A,C),BQ[m]=!0}}var mZ={isMounted:function(D){return!1},enqueueForceUpdate:function(D,A,V){vQ(D,"forceUpdate")},enqueueReplaceState:function(D,A,V,C){vQ(D,"replaceState")},enqueueSetState:function(D,A,V,C){vQ(D,"setState")}},cQ=Object.assign,$Q={};Object.freeze($Q);function uQ(D,A,V){this.props=D,this.context=A,this.refs=$Q,this.updater=V||mZ}uQ.prototype.isReactComponent={},uQ.prototype.setState=function(D,A){if(typeof D!=="object"&&typeof D!=="function"&&D!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,D,A,"setState")},uQ.prototype.forceUpdate=function(D){this.updater.enqueueForceUpdate(this,D,"forceUpdate")};{var cZ={isMounted:["isMounted","Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."],replaceState:["replaceState","Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."]},Z7=function(D,A){Object.defineProperty(uQ.prototype,D,{get:function(){TJ("%s(...) is deprecated in plain JavaScript React classes. %s",A[0],A[1]);return}})};for(var f7 in cZ)if(cZ.hasOwnProperty(f7))Z7(f7,cZ[f7])}function v7(){}v7.prototype=uQ.prototype;function ZZ(D,A,V){this.props=D,this.context=A,this.refs=$Q,this.updater=V||mZ}var X7=ZZ.prototype=new v7;X7.constructor=ZZ,cQ(X7,uQ.prototype),X7.isPureReactComponent=!0;function PZ(){var D={current:null};return Object.seal(D),D}var I7=Array.isArray;function yQ(D){return I7(D)}function Y7(D){{var A=typeof Symbol==="function"&&Symbol.toStringTag,V=A&&D[Symbol.toStringTag]||D.constructor.name||"Object";return V}}function j7(D){try{return pQ(D),!1}catch(A){return!0}}function pQ(D){return""+D}function SQ(D){if(j7(D))return QJ("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Y7(D)),pQ(D)}function pZ(D,A,V){var C=D.displayName;if(C)return C;var m=A.displayName||A.name||"";return m!==""?V+"("+m+")":V}function u7(D){return D.displayName||"Context"}function XZ(D){if(D==null)return null;if(typeof D.tag==="number")QJ("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.");if(typeof D==="function")return D.displayName||D.name||null;if(typeof D==="string")return D;switch(D){case z:return"Fragment";case K:return"Portal";case F:return"Profiler";case $:return"StrictMode";case _:return"Suspense";case b:return"SuspenseList"}if(typeof D==="object")switch(D.$$typeof){case j:var A=D;return u7(A)+".Consumer";case B:var V=D;return u7(V._context)+".Provider";case y:return pZ(D,D.render,"ForwardRef");case k:var C=D.displayName||null;if(C!==null)return C;return XZ(D.type)||"Memo";case a:{var m=D,IJ=m._payload,XJ=m._init;try{return XZ(XJ(IJ))}catch(PJ){return null}}}return null}var P7=Object.prototype.hasOwnProperty,qX={key:!0,ref:!0,__self:!0,__source:!0},G7,K7,sQ;sQ={};function N7(D){if(P7.call(D,"ref")){var A=Object.getOwnPropertyDescriptor(D,"ref").get;if(A&&A.isReactWarning)return!1}return D.ref!==void 0}function NZ(D){if(P7.call(D,"key")){var A=Object.getOwnPropertyDescriptor(D,"key").get;if(A&&A.isReactWarning)return!1}return D.key!==void 0}function $Z(D,A){var V=function(){if(!G7)G7=!0,QJ("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",A)};V.isReactWarning=!0,Object.defineProperty(D,"key",{get:V,configurable:!0})}function K8(D,A){var V=function(){if(!K7)K7=!0,QJ("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",A)};V.isReactWarning=!0,Object.defineProperty(D,"ref",{get:V,configurable:!0})}function U8(D){if(typeof D.ref==="string"&&qJ.current&&D.__self&&qJ.current.stateNode!==D.__self){var A=XZ(qJ.current.type);if(!sQ[A])QJ('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',A,D.ref),sQ[A]=!0}}var g7=function(D,A,V,C,m,IJ,XJ){var PJ={$$typeof:Y,type:D,key:A,ref:V,props:XJ,_owner:IJ};if(PJ._store={},Object.defineProperty(PJ._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(PJ,"_self",{configurable:!1,enumerable:!1,writable:!1,value:C}),Object.defineProperty(PJ,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze)Object.freeze(PJ.props),Object.freeze(PJ);return PJ};function U7(D,A,V){var C,m={},IJ=null,XJ=null,PJ=null,gJ=null;if(A!=null){if(N7(A))XJ=A.ref,U8(A);if(NZ(A))SQ(A.key),IJ=""+A.key;PJ=A.__self===void 0?null:A.__self,gJ=A.__source===void 0?null:A.__source;for(C in A)if(P7.call(A,C)&&!qX.hasOwnProperty(C))m[C]=A[C]}var XQ=arguments.length-2;if(XQ===1)m.children=V;else if(XQ>1){var LQ=Array(XQ);for(var WQ=0;WQ<XQ;WQ++)LQ[WQ]=arguments[WQ+2];if(Object.freeze)Object.freeze(LQ);m.children=LQ}if(D&&D.defaultProps){var jQ=D.defaultProps;for(C in jQ)if(m[C]===void 0)m[C]=jQ[C]}if(IJ||XJ){var EQ=typeof D==="function"?D.displayName||D.name||"Unknown":D;if(IJ)$Z(m,EQ);if(XJ)K8(m,EQ)}return g7(D,IJ,XJ,PJ,gJ,qJ.current,m)}function r(D,A){var V=g7(D.type,A,D.ref,D._self,D._source,D._owner,D.props);return V}function WJ(D,A,V){if(D===null||D===void 0)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+D+".");var C,m=cQ({},D.props),IJ=D.key,XJ=D.ref,PJ=D._self,gJ=D._source,XQ=D._owner;if(A!=null){if(N7(A))XJ=A.ref,XQ=qJ.current;if(NZ(A))SQ(A.key),IJ=""+A.key;var LQ;if(D.type&&D.type.defaultProps)LQ=D.type.defaultProps;for(C in A)if(P7.call(A,C)&&!qX.hasOwnProperty(C))if(A[C]===void 0&&LQ!==void 0)m[C]=LQ[C];else m[C]=A[C]}var WQ=arguments.length-2;if(WQ===1)m.children=V;else if(WQ>1){var jQ=Array(WQ);for(var EQ=0;EQ<WQ;EQ++)jQ[EQ]=arguments[EQ+2];m.children=jQ}return g7(D.type,IJ,XJ,PJ,gJ,XQ,m)}function VJ(D){return typeof D==="object"&&D!==null&&D.$$typeof===Y}var JQ=".",OQ=":";function lQ(D){var A=/[=:]/g,V={"=":"=0",":":"=2"},C=D.replace(A,function(m){return V[m]});return"$"+C}var AQ=!1,wZ=/\/+/g;function cJ(D){return D.replace(wZ,"$&/")}function rJ(D,A){if(typeof D==="object"&&D!==null&&D.key!=null)return SQ(D.key),lQ(""+D.key);return A.toString(36)}function T8(D,A,V,C,m){var IJ=typeof D;if(IJ==="undefined"||IJ==="boolean")D=null;var XJ=!1;if(D===null)XJ=!0;else switch(IJ){case"string":case"number":XJ=!0;break;case"object":switch(D.$$typeof){case Y:case K:XJ=!0}}if(XJ){var PJ=D,gJ=m(PJ),XQ=C===""?JQ+rJ(PJ,0):C;if(yQ(gJ)){var LQ="";if(XQ!=null)LQ=cJ(XQ)+"/";T8(gJ,A,LQ,"",function(FG){return FG})}else if(gJ!=null){if(VJ(gJ)){if(gJ.key&&(!PJ||PJ.key!==gJ.key))SQ(gJ.key);gJ=r(gJ,V+(gJ.key&&(!PJ||PJ.key!==gJ.key)?cJ(""+gJ.key)+"/":"")+XQ)}A.push(gJ)}return 1}var WQ,jQ,EQ=0,tJ=C===""?JQ:C+OQ;if(yQ(D))for(var Z9=0;Z9<D.length;Z9++)WQ=D[Z9],jQ=tJ+rJ(WQ,Z9),EQ+=T8(WQ,A,V,jQ,m);else{var r9=CJ(D);if(typeof r9==="function"){var I6=D;if(r9===I6.entries){if(!AQ)TJ("Using Maps as children is not supported. Use an array of keyed ReactElements instead.");AQ=!0}var MG=r9.call(I6),k8,j6=0;while(!(k8=MG.next()).done)WQ=k8.value,jQ=tJ+rJ(WQ,j6++),EQ+=T8(WQ,A,V,jQ,m)}else if(IJ==="object"){var P6=String(D);throw Error("Objects are not valid as a React child (found: "+(P6==="[object Object]"?"object with keys {"+Object.keys(D).join(", ")+"}":P6)+"). If you meant to render a collection of children, use an array instead.")}}return EQ}function w7(D,A,V){if(D==null)return D;var C=[],m=0;return T8(D,C,"","",function(IJ){return A.call(V,IJ,m++)}),C}function zX(D){var A=0;return w7(D,function(){A++}),A}function K6(D,A,V){w7(D,function(){A.apply(this,arguments)},V)}function m9(D){return w7(D,function(A){return A})||[]}function c9(D){if(!VJ(D))throw Error("React.Children.only expected to receive a single React element child.");return D}function tX(D){var A={$$typeof:j,_currentValue:D,_currentValue2:D,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};A.Provider={$$typeof:B,_context:A};var V=!1,C=!1,m=!1;{var IJ={$$typeof:j,_context:A};Object.defineProperties(IJ,{Provider:{get:function(){if(!C)C=!0,QJ("Rendering <Context.Consumer.Provider> is not supported and will be removed in a future major release. Did you mean to render <Context.Provider> instead?");return A.Provider},set:function(XJ){A.Provider=XJ}},_currentValue:{get:function(){return A._currentValue},set:function(XJ){A._currentValue=XJ}},_currentValue2:{get:function(){return A._currentValue2},set:function(XJ){A._currentValue2=XJ}},_threadCount:{get:function(){return A._threadCount},set:function(XJ){A._threadCount=XJ}},Consumer:{get:function(){if(!V)V=!0,QJ("Rendering <Context.Consumer.Consumer> is not supported and will be removed in a future major release. Did you mean to render <Context.Consumer> instead?");return A.Consumer}},displayName:{get:function(){return A.displayName},set:function(XJ){if(!m)TJ("Setting `displayName` on Context.Consumer has no effect. You should set it directly on the context with Context.displayName = '%s'.",XJ),m=!0}}}),A.Consumer=IJ}return A._currentRenderer=null,A._currentRenderer2=null,A}var q8=-1,$X=0,OX=1,d7=2;function m7(D){if(D._status===q8){var A=D._result,V=A();if(V.then(function(IJ){if(D._status===$X||D._status===q8){var XJ=D;XJ._status=OX,XJ._result=IJ}},function(IJ){if(D._status===$X||D._status===q8){var XJ=D;XJ._status=d7,XJ._result=IJ}}),D._status===q8){var C=D;C._status=$X,C._result=V}}if(D._status===OX){var m=D._result;if(m===void 0)QJ(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
2
12
|
|
|
3
13
|
Your code should look like:
|
|
@@ -186,4 +196,7 @@ ${Y}
|
|
|
186
196
|
}
|
|
187
197
|
`,document.head.appendChild(Z)}class u9{constructor(Z,Y={}){this.pane=null,this.definitions=Z,this.options={title:Y.title||"Controls",position:Y.position||"top-right",expanded:Y.expanded!==void 0?Y.expanded:!0,container:Y.container!==void 0?Y.container:null,onChange:Y.onChange||(()=>{}),onReady:Y.onReady||(()=>{})},this.params=this.extractInitialValues(Z),this.init()}isFolder(Z){return Z&&typeof Z==="object"&&(Z.type==="folder"||Z.type==="group")}isButton(Z){return Z&&typeof Z==="object"&&Z.type==="button"}isTab(Z){return Z&&typeof Z==="object"&&Z.type==="tab"}isFile(Z){return Z&&typeof Z==="object"&&Z.type==="file"}extractInitialValues(Z){let Y={};for(let[K,z]of Object.entries(Z)){let $=z;if(this.isFolder($))Y[K]=this.extractInitialValues($.controls);else if(this.isTab($))Y[K]=$.pages.map((F)=>this.extractInitialValues(F.controls));else if(this.isButton($))continue;else Y[K]=$.value}return Y}async init(){try{H4(),await new Promise((Z)=>setTimeout(Z,50)),this.createPane(),this.addControls(),this.options.onReady()}catch(Z){console.error("[HypertoolControls] Initialization error:",Z)}}createPane(){let Z=this.resolveContainer(),Y={title:this.options.title,expanded:this.options.expanded};if(Z)Y.container=Z;this.pane=new G$(Y),this.pane.element.parentElement?.classList.add("controls-container")}resolveContainer(){if(typeof document>"u")return null;let Z=this.options.container;if(!Z)return null;if(Z instanceof HTMLElement)return Z;let Y=document.querySelector(Z);if(!Y)return console.warn(`[HypertoolControls] Container selector "${Z}" did not match any elements`),null;return Y}addControls(){if(!this.pane)return;this.addControlsToTarget(this.pane,this.definitions,this.params)}addControlsToTarget(Z,Y,K){for(let[z,$]of Object.entries(Y))try{if(this.isFolder($)){let F={title:$.label||z};if($.expanded!==void 0)F.expanded=$.expanded;let B=Z.addFolder(F);this.addControlsToTarget(B,$.controls,K[z])}else if(this.isButton($)){let F={title:$.title};if($.label)F.label=$.label;let B=Z.addButton(F);if($.onClick)B.on("click",$.onClick)}else if(this.isTab($)){let F={pages:$.pages.map((j)=>({title:j.title}))},B=Z.addTab(F);$.pages.forEach((j,y)=>{this.addControlsToTarget(B.pages[y],j.controls,K[z][y])})}else if(this.isFile($))this.addFileControl(Z,z,$,K);else this.addControlToTarget(Z,z,$,K)}catch(F){console.error(`[HypertoolControls] Error adding control/folder/button/tab "${z}":`,F)}}addControlToTarget(Z,Y,K,z){if(this.isFolder(K))return;let $={label:K.label||Y};if(K.readonly!==void 0)$.readonly=K.readonly;if(K.interval!==void 0)$.interval=K.interval;if(K.bufferSize!==void 0)$.bufferSize=K.bufferSize;if(K.multiline!==void 0)$.multiline=K.multiline;if(K.rows!==void 0)$.rows=K.rows;if(K.view!==void 0)$.view=K.view;switch(K.type){case"number":if(K.min!==void 0)$.min=K.min;if(K.max!==void 0)$.max=K.max;if(K.step!==void 0)$.step=K.step;break;case"point":case"point2d":case"point3d":case"point4d":if(K.min!==void 0)$.min=K.min;if(K.max!==void 0)$.max=K.max;if(K.step!==void 0)$.step=K.step;let B=["x","y","z","w"];for(let j of B)if(K[j]&&typeof K[j]==="object")$[j]=K[j];break;case"select":case"selector":if(Array.isArray(K.options))$.options=K.options.map((j)=>{if(typeof j==="object"&&j!==null)return{text:j.label||j.text||String(j.value),value:j.value};return{text:String(j),value:j}});else $.options=Object.entries(K.options).map(([j,y])=>({text:j,value:y}));break;case"color":case"boolean":case"string":case"text":break;case"folder":case"group":console.warn("[HypertoolControls] Folder/Group encountered in addControlToTarget (should be handled earlier)");return;case"button":console.warn("[HypertoolControls] Button encountered in addControlToTarget (should be handled earlier)");return;case"tab":console.warn("[HypertoolControls] Tab encountered in addControlToTarget (should be handled earlier)");return;default:console.warn(`[HypertoolControls] Unknown control type: ${K.type}`);return}Z.addBinding(z,Y,$).on("change",(B)=>{z[Y]=B.value;let j={key:Y,value:B.value,event:B};this.options.onChange(this.values,j)})}addFileControl(Z,Y,K,z){let $=K.label||Y,F=K.accept||"*/*",B=K.placeholder||"Choose file...",j=K.preview!==!1,y=document.createElement("div");y.className="tp-lblv ht-file-control-row";let _=document.createElement("div");_.className="tp-lblv_l ht-file-control-label",_.textContent=$;let b=document.createElement("div");b.className="tp-lblv_v ht-file-control-value";let k=document.createElement("input");k.type="file",k.accept=F,k.style.display="none";let a=document.createElement("div");a.className="ht-file-control-buttons";let DJ=document.createElement("button");DJ.className="tp-btnv_b ht-file-control-button",DJ.textContent=z[Y]?"Change":"Upload",DJ.style.display=z[Y]?"none":"inline-flex";let _J=document.createElement("button");_J.className="tp-btnv_b ht-file-control-button ht-file-control-button--muted",_J.textContent="✕",_J.style.display="none";let yJ=document.createElement("div");yJ.className="ht-file-control-preview",yJ.style.display=z[Y]&&j?"block":"none";let CJ=document.createElement("div");CJ.className="ht-file-control-preview-bar";let g=document.createElement("span");g.className="ht-file-control-preview-name",g.textContent=z[Y]?"File":"No file selected";let KJ=document.createElement("div");KJ.className="ht-file-control-preview-actions";let c=document.createElement("button");c.type="button",c.className="ht-file-control-preview-action",c.title="Replace file",c.textContent="↻",c.onclick=(i)=>{i.preventDefault(),k.click()};let qJ=document.createElement("button");qJ.type="button",qJ.className="ht-file-control-preview-action",qJ.title="Remove file",qJ.textContent="✕",qJ.onclick=(i)=>{i.preventDefault(),_J.click()},KJ.appendChild(c),KJ.appendChild(qJ),CJ.appendChild(g),CJ.appendChild(KJ);let d=document.createElement("img");d.className="ht-file-control-preview-img";let UJ=document.createElement("div");UJ.className="ht-file-control-placeholder",UJ.style.display="none",k.onchange=async()=>{let i=k.files?.[0];if(!i)return;if(K.maxSize&&i.size>K.maxSize){console.warn(`[HypertoolControls] File size exceeds limit: ${i.size} > ${K.maxSize}`);return}DJ.textContent="Uploading...",DJ.disabled=!0;let $J=`file-upload-${Date.now()}-${Math.random().toString(36).slice(2)}`,LJ=new Promise((TJ)=>{let QJ=(AJ)=>{if(AJ.data?.type!=="UPLOAD_CONTROL_FILE_RESULT")return;if(AJ.data?.requestId!==$J)return;if(window.removeEventListener("message",QJ),AJ.data.error)console.error("[HypertoolControls] File upload failed:",AJ.data.error),TJ(null);else TJ({url:AJ.data.url,originalUrl:AJ.data.originalUrl||AJ.data.url})};window.addEventListener("message",QJ),setTimeout(()=>{window.removeEventListener("message",QJ),console.warn("[HypertoolControls] File upload timed out"),TJ(null)},30000)}),JJ=null;if(j&&i.type.startsWith("image/")){let TJ=new FileReader;TJ.onload=(QJ)=>{JJ=QJ.target?.result},TJ.readAsDataURL(i)}let YJ=new FileReader;YJ.onload=async(TJ)=>{let QJ=TJ.target?.result;window.parent.postMessage({type:"UPLOAD_CONTROL_FILE",source:"hypertool-iframe",requestId:$J,data:{fileName:i.name,fileType:i.type,fileSize:i.size,fileData:QJ,controlKey:Y}},"*",[QJ]);let AJ=await LJ;if(DJ.disabled=!1,AJ){if(z[Y]=AJ.url,DJ.textContent="Change",DJ.style.display="none",g.textContent=i.name||"File",j&&i.type.startsWith("image/")&&JJ)UJ.style.display="none",d.src=JJ,yJ.style.display="flex";let BQ={key:Y,value:AJ.originalUrl,event:{value:AJ.originalUrl,proxyUrl:AJ.url,file:i}};this.options.onChange(this.values,BQ)}else DJ.textContent=z[Y]?"Change":"Upload",console.error("[HypertoolControls] Failed to upload file to storage")},YJ.readAsArrayBuffer(i)},DJ.onclick=()=>{k.click()},_J.onclick=()=>{z[Y]=null,k.value="",DJ.textContent="Upload",DJ.style.display="inline-flex",_J.style.display="none",yJ.style.display="none",UJ.style.display="none",g.textContent="No file selected";let i={key:Y,value:null,event:{value:null}};this.options.onChange(this.values,i)},a.appendChild(DJ),a.appendChild(_J),yJ.appendChild(d),yJ.appendChild(CJ),b.appendChild(k),b.appendChild(a),b.appendChild(UJ),b.appendChild(yJ),y.appendChild(_),y.appendChild(b);let SJ=Z.element;(SJ.querySelector(".tp-rotv_c")||SJ).appendChild(y)}addFolder(Z){if(!this.pane)return null;return this.pane.addFolder({title:Z})}set(Z,Y){if(Z in this.params){if(this.params[Z]=Y,this.pane)this.pane.refresh()}}get values(){return{...this.params}}destroy(){if(this.pane)this.pane.dispose(),this.pane=null;let Z=document.getElementById("hypertool-theme");if(Z)Z.remove()}setVisible(Z){if(!this.pane)return;this.pane.element.style.display=Z?"block":"none"}refresh(){if(this.pane)this.pane.refresh()}}function K$(Z,Y){return new u9(Z,Y).params}function U$(Z,Y){return new u9(Z,Y)}var jM=zQ(G8(),1),PM=zQ(zM(),1);var q$=new Set(["STYLE","LINK"]);class z${source;target;observer=null;nodeMap=new WeakMap;active=!1;messageListener=null;usePostMessage=!1;cssNodesById=new Map;constructor(Z={}){let Y=null;if(Z.sourceDocument)Y=Z.sourceDocument;else if(typeof window<"u")try{Y=window.parent?.document??null}catch(K){console.debug("[hyper-frame] Using postMessage for CSS sync (cross-origin)"),this.usePostMessage=!0,Y=null}this.source=Y,this.target=Z.targetDocument??(typeof document<"u"?document:null),this.active=Boolean(Z.mirror??!0)}start(){if(!this.active)return;if(this.usePostMessage)this.startPostMessageMode();else if(this.source&&this.target)this.cleanupPreviousClones(),this.syncAll(),this.attachObserver();else console.warn("[hyper-frame] Unable to mirror CSS – missing source or target document.")}stop(){if(this.observer?.disconnect(),this.observer=null,this.nodeMap=new WeakMap,this.cleanupPreviousClones(),this.messageListener&&typeof window<"u")window.removeEventListener("message",this.messageListener),this.messageListener=null;this.cssNodesById.clear()}startPostMessageMode(){if(!this.target||typeof window>"u")return;this.cleanupPreviousClones(),this.messageListener=(Z)=>{if(!Z.data||Z.data.type!=="hyper-frame:css-sync")return;this.handleCssMessage(Z.data)},window.addEventListener("message",this.messageListener),console.debug("[hyper-frame] CSS postMessage receiver ready")}handleCssMessage(Z){if(!this.target)return;switch(Z.action){case"init":this.cleanupPreviousClones(),this.cssNodesById.clear();break;case"add":if(Z.id&&Z.tagName)this.addCssNode(Z.id,Z.tagName,Z.attributes,Z.textContent);break;case"remove":if(Z.id)this.removeCssNode(Z.id);break;case"update":if(Z.id)this.updateCssNode(Z.id,Z.attributes,Z.textContent);break}}addCssNode(Z,Y,K,z){if(!this.target)return;if(this.cssNodesById.has(Z))return;let $=document.createElement(Y);if($.setAttribute("data-hyper-frame-clone","true"),$.setAttribute("data-css-id",Z),K)for(let[F,B]of Object.entries(K))$.setAttribute(F,B);if(z)$.textContent=z;this.target.head.appendChild($),this.cssNodesById.set(Z,$)}removeCssNode(Z){let Y=this.cssNodesById.get(Z);if(Y&&Y.parentNode)Y.parentNode.removeChild(Y),this.cssNodesById.delete(Z)}updateCssNode(Z,Y,K){let z=this.cssNodesById.get(Z);if(!z)return;if(Y){for(let $ of Array.from(z.attributes))if(!$.name.startsWith("data-"))z.removeAttribute($.name);for(let[$,F]of Object.entries(Y))z.setAttribute($,F)}if(K!==void 0)z.textContent=K}cleanupPreviousClones(){if(!this.target)return;this.target.querySelectorAll('[data-hyper-frame-clone="true"]').forEach((Z)=>Z.parentNode?.removeChild(Z))}async syncAll(){if(!this.source||!this.target)return;let Z=this.source.head,Y=Array.from(Z.children).filter((K)=>q$.has(K.nodeName));for(let K of Y){let z=await this.cloneNode(K);if(!z)continue;this.target?.head.appendChild(z),this.nodeMap.set(K,z)}}attachObserver(){if(!this.source||!this.target)return;if(this.observer)return;this.observer=new MutationObserver((Z)=>{Z.forEach((Y)=>{switch(Y.type){case"childList":this.handleChildListMutation(Y);break;case"characterData":this.handleCharacterDataMutation(Y);break;case"attributes":this.handleAttributeMutation(Y);break}})}),this.observer.observe(this.source.head,{childList:!0,subtree:!0,characterData:!0,attributes:!0})}handleChildListMutation(Z){if(!this.target)return;Z.removedNodes.forEach((Y)=>{let K=this.nodeMap.get(Y);if(K&&K.parentNode)K.parentNode.removeChild(K),this.nodeMap.delete(Y)}),Z.addedNodes.forEach(async(Y)=>{if(!(Y instanceof HTMLElement))return;if(!q$.has(Y.nodeName))return;try{let K=await this.cloneNode(Y);if(!K)return;let z=Z.nextSibling?this.nodeMap.get(Z.nextSibling):null;if(z&&z.parentNode)z.parentNode.insertBefore(K,z);else this.target?.head.appendChild(K);this.nodeMap.set(Y,K)}catch(K){console.error("[CssBridge] Failed to clone node:",K)}})}handleCharacterDataMutation(Z){let K=Z.target.parentNode;if(!K)return;let z=this.nodeMap.get(K);if(!z)return;z.textContent=K.textContent}handleAttributeMutation(Z){let Y=Z.target,K=this.nodeMap.get(Y);if(!K||!(K instanceof Element))return;if(Z.attributeName){let z=Y.getAttribute(Z.attributeName);if(z===null)K.removeAttribute(Z.attributeName);else K.setAttribute(Z.attributeName,z)}}async cloneNode(Z){if(!(Z instanceof HTMLElement))return null;if(!q$.has(Z.nodeName))return null;if(Z.nodeName==="LINK"&&Z instanceof HTMLLinkElement){let K=Z.getAttribute("href"),z=Z.getAttribute("rel");if(K){if(z==="stylesheet")try{let F=await this.fetchCssContent(K),B=document.createElement("STYLE");return B.textContent=F,B.setAttribute("data-hyper-frame-clone","true"),B}catch(F){console.error(`[CssBridge] Failed to fetch CSS from ${K}:`,F)}let $=Z.cloneNode(!0);try{let F=this.source?new URL(this.source.location.href):new URL(window.location.href),B=new URL(K,F).href;$.setAttribute("href",B)}catch(F){console.error(`[CssBridge] Failed to convert URL to absolute: ${K}`,F)}return $.setAttribute("data-hyper-frame-clone","true"),$}}let Y=Z.cloneNode(!0);return Y.setAttribute("data-hyper-frame-clone","true"),Y}async fetchCssContent(Z){let Y=this.source?new URL(this.source.location.href):new URL(window.location.href),K=new URL(Z,Y).href,z=await fetch(K);if(!z.ok)throw Error(`HTTP ${z.status}: ${z.statusText}`);return await z.text()}}function $M(Z={}){let Y=Z.documentRef??document;if(!Y)throw Error("[hyper-frame] document is not available");let K=Z.containerClassName||"hyper-frame",z=Z.target;if(z instanceof HTMLElement)return z.classList.add(K),{element:z,createdInternally:!1};if(typeof z==="string"&&z.trim().length>0){let F=Y.querySelector(z);if(F)return F.classList.add(K),{element:F,createdInternally:!1};console.warn(`[hyper-frame] Could not find container for selector "${z}", creating one instead.`)}let $=Y.createElement("div");return $.classList.add(K),$.classList.add("hyper-frame-container"),Y.body.appendChild($),{element:$,createdInternally:!0}}var zG=zQ(G8(),1);var NQ=zQ(G8(),1),y7=zQ(gZ(),1),OM=({definitions:Z,options:Y,onChange:K,onReady:z})=>{let $=NQ.useRef(null),F=NQ.useRef(null),B=NQ.useRef(null),j=NQ.useRef(null),y=NQ.useRef(z),[_,b]=NQ.useState(!1),[k,a]=NQ.useState(!1),[DJ,_J]=NQ.useState(!1),yJ=NQ.useMemo(()=>{let d=[{type:"number",label:"Number",description:"Slider with min/max/step"},{type:"color",label:"Color",description:"Color picker"},{type:"boolean",label:"Toggle",description:"On/off switch"},{type:"string",label:"Text",description:"Single-line string"},{type:"text",label:"Textarea",description:"Multiline string"},{type:"select",label:"Select",description:"Dropdown options"},{type:"point2d",label:"Point 2D",description:"Vector {x,y}"},{type:"point3d",label:"Point 3D",description:"Vector {x,y,z}"},{type:"file",label:"File",description:"Upload image/audio/etc"}],UJ=Y?.controlTypes;if(!UJ||UJ.length===0)return d;return d.filter((SJ)=>UJ.includes(SJ.type))},[Y?.controlTypes]),CJ=NQ.useCallback(()=>b(!1),[]),g=NQ.useCallback(()=>{let d=$.current,UJ=F.current;if(!d||!UJ)return;let SJ=d.getBoundingClientRect(),zJ=window.innerHeight-SJ.top-12,i=UJ.scrollHeight;_J(i>zJ)},[]);NQ.useEffect(()=>{let d=(UJ)=>{if(!(UJ.target instanceof HTMLElement))return;if(!UJ.target.closest(".hyper-frame-controls-panel"))CJ()};if(_)document.addEventListener("click",d);return()=>{document.removeEventListener("click",d)}},[_,CJ]),NQ.useEffect(()=>{g()},[_,g,yJ.length]),NQ.useEffect(()=>{let d=()=>g();return window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[g]);let KJ=NQ.useCallback((d)=>{let UJ=Math.random().toString(36).slice(2,6);return`${d}-control-${UJ}`},[]),c=NQ.useCallback((d,UJ)=>{return[`Add a new ${d} control named "${UJ}" to the existing controls definitions.`,"Do NOT regenerate files; only patch the controls definitions object.",`Use sensible defaults for ${d} (e.g., 0/1 for numbers, "#00ff88" for colors).`,"Return a search-replace JSON patch that only touches the controls definitions section.","Keep all other code intact."].join(" ")},[]),qJ=NQ.useCallback((d)=>{let UJ=KJ(d),SJ=c(d,UJ),zJ={source:"hypertool-controls",type:"ADD_CONTROL_REQUEST",controlType:d,name:UJ,prompt:SJ,timestamp:Date.now()};if(Y?.onAddControlRequest);if(Y?.onAddControlRequest?.({type:d,name:UJ,prompt:SJ}),window.dispatchEvent(new CustomEvent("hypertool:add-control-request",{detail:zJ})),window.parent&&window.parent!==window)window.parent.postMessage(zJ,"*")},[c,KJ,Y]);return NQ.useEffect(()=>{y.current=z},[z]),NQ.useEffect(()=>{let d=(UJ)=>{let SJ=UJ;if(!SJ.detail||typeof SJ.detail.loading!=="boolean")return;a(Boolean(SJ.detail.loading))};return window.addEventListener("hypertool:add-control-status",d),()=>{window.removeEventListener("hypertool:add-control-status",d)}},[]),NQ.useEffect(()=>{if(!B.current)return;let d=()=>g(),UJ=()=>g(),SJ=null,zJ=window;if(!zJ.hypertoolControls){console.warn("[ControlsPanel] hypertoolControls not available on window");return}try{let i=zJ.hypertoolControls.createControlPanel(Z,{title:Y?.title,position:Y?.position,expanded:Y?.expanded,container:B.current,onChange:($J,LJ)=>{if(K)K({key:LJ.key,value:LJ.value,event:LJ.event})}});if(j.current=i,SJ=document.querySelector(".hyper-frame-controls-panel__add-btn"),SJ?.addEventListener("click",d),window.addEventListener("resize",UJ),g(),y.current)y.current(i)}catch(i){console.error("[ControlsPanel] Failed to create controls:",i)}return()=>{if(j.current){if(typeof j.current.dispose==="function")j.current.dispose();else if(typeof j.current.destroy==="function")j.current.destroy();j.current=null}SJ?.removeEventListener("click",d),window.removeEventListener("resize",UJ)}},[Z,Y,K]),y7.jsxDEV("div",{className:"hyper-frame-controls-panel",ref:$,children:y7.jsxDEV("div",{ref:F,className:DJ?"hyper-frame-controls-panel__scroll hyper-frame-controls-panel__scroll--overflow":"hyper-frame-controls-panel__scroll",children:[y7.jsxDEV("div",{ref:B,className:"hyper-frame-controls-panel__pane"},void 0,!1,void 0,this),Y?.showAddControlActions!==!1&&yJ.length>0&&y7.jsxDEV("div",{className:"hyper-frame-controls-panel__actions",children:[y7.jsxDEV("button",{type:"button",className:"hyper-frame-controls-panel__add-btn",onClick:()=>b((d)=>!d),"aria-expanded":_,"aria-haspopup":"true",disabled:k,children:[k?y7.jsxDEV("span",{className:"hyper-frame-controls-panel__spinner"},void 0,!1,void 0,this):"+",y7.jsxDEV("span",{children:k?"Adding…":"Add control"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&y7.jsxDEV("div",{className:"hyper-frame-controls-panel__menu",role:"menu",children:yJ.map((d)=>y7.jsxDEV("button",{className:"hyper-frame-controls-panel__menu-item",onClick:()=>{a(!0),qJ(d.type),CJ()},role:"menuitem",children:[y7.jsxDEV("div",{className:"hyper-frame-controls-panel__menu-title",children:[d.label,": "]},void 0,!0,void 0,this),y7.jsxDEV("div",{className:"hyper-frame-controls-panel__menu-desc",children:d.description},void 0,!1,void 0,this)]},d.type,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var dZ=zQ(G8(),1);var wQ=zQ(G8(),1),DM=zQ(gZ(),1),LM=wQ.createContext(null),qG=()=>{let{innerWidth:Z,innerHeight:Y}=window;return{width:Math.max(100,Math.round(Z)),height:Math.max(100,Math.round(Y))}},WM=({children:Z})=>{let Y=wQ.useMemo(()=>{let $J=qG(),LJ=window.devicePixelRatio||1,JJ=Math.round($J.width*LJ),YJ=Math.round($J.height*LJ);return{canvasWidth:Math.max(100,Math.round(JJ*0.9)),canvasHeight:Math.max(100,Math.round(YJ*0.9)),maxWidth:JJ,maxHeight:YJ}},[]),[K,z]=wQ.useState(Y.canvasWidth),[$,F]=wQ.useState(Y.canvasHeight),[B,j]=wQ.useState(Y.maxWidth),[y,_]=wQ.useState(Y.maxHeight),[b,k]=wQ.useState(!1),[a,DJ]=wQ.useState(!1),[_J,yJ]=wQ.useState(null),[CJ,g]=wQ.useState(null),KJ=wQ.useMemo(()=>{let $J=window.devicePixelRatio||1,LJ=K/$J,JJ=$/$J;if(LJ===0||JJ===0)return 1;let YJ=B/$J,TJ=y/$J,QJ=YJ/LJ,AJ=TJ/JJ;return Math.min(QJ,AJ,1)},[K,$,B,y]);wQ.useEffect(()=>{let $J=()=>{let LJ=qG(),JJ=window.devicePixelRatio||1,YJ=Math.round(LJ.width*JJ),TJ=Math.round(LJ.height*JJ);if(j(YJ),_(TJ),b)z(YJ),F(TJ);else if(_J!==null){let QJ,AJ;if(YJ/TJ>_J)AJ=TJ,QJ=Math.round(AJ*_J);else QJ=YJ,AJ=Math.round(QJ/_J);z(QJ),F(AJ)}};return window.addEventListener("resize",$J),()=>window.removeEventListener("resize",$J)},[b,_J]);let c=wQ.useCallback(($J)=>{let LJ=Math.max(100,Math.round($J));z(LJ),k(!1),yJ(null)},[]),qJ=wQ.useCallback(($J)=>{let LJ=Math.max(100,Math.round($J));F(LJ),k(!1),yJ(null)},[]),d=wQ.useCallback(($J,LJ)=>{let JJ=Math.max(100,Math.round($J)),YJ=Math.max(100,Math.round(LJ));z(JJ),F(YJ),k(!1),yJ(null)},[]),UJ=wQ.useCallback(($J,LJ)=>{let JJ=qG(),YJ=window.devicePixelRatio||1,TJ=$J/LJ,QJ=Math.round(JJ.width*YJ),AJ=Math.round(JJ.height*YJ),BQ,vQ;if(QJ/AJ>TJ)vQ=AJ,BQ=Math.round(vQ*TJ);else BQ=QJ,vQ=Math.round(BQ/TJ);z(BQ),F(vQ),yJ(TJ),k(!1)},[]),SJ=wQ.useCallback(($J)=>{let{width:LJ,height:JJ}=$J;if(LJ>0&&JJ>0)console.log("[CanvasContext] Syncing with actual canvas:",{actual:{width:LJ,height:JJ},current:{width:K,height:$}}),z(LJ),F(JJ),k(!1),yJ(null)},[K,$]),zJ=wQ.useCallback(()=>{if(b&&CJ)z(CJ.width),F(CJ.height),k(!1),g(null);else{g({width:K,height:$});let $J=qG(),LJ=window.devicePixelRatio||1,JJ=Math.round($J.width*LJ),YJ=Math.round($J.height*LJ);z(JJ),F(YJ),yJ(null),k(!0)}},[b,CJ,K,$]),i={canvasWidth:K,canvasHeight:$,maxCanvasWidth:B,maxCanvasHeight:y,scale:KJ,isFittedToScreen:b,isRecording:a,setIsRecording:DJ,setCanvasWidth:c,setCanvasHeight:qJ,setCanvasSize:d,setAspectRatio:UJ,syncWithCanvas:SJ,fitToScreen:zJ};return DM.jsxDEV(LM.Provider,{value:i,children:Z},void 0,!1,void 0,this)},oX=()=>{let Z=wQ.useContext(LM);if(!Z)throw Error("useCanvas must be used within a CanvasProvider");return Z};var A7=zQ(gZ(),1),HM=({getContainer:Z,filename:Y="hyperframe-export",useCanvasCapture:K=!0})=>{let{setIsRecording:z}=oX(),[$,F]=dZ.useState(!1),[B,j]=dZ.useState(!1),[y,_]=dZ.useState(!1),b=dZ.useRef(null),k=dZ.useRef([]);dZ.useEffect(()=>{let g=()=>{let c=Z();if(c&&K){if(c.querySelector("canvas"))return F(!0),j(!0),!0}return!1};if(g())return;let KJ=setInterval(()=>{if(g())clearInterval(KJ)},100);return()=>clearInterval(KJ)},[Z,K]);let a=dZ.useCallback((g,KJ)=>{let c=URL.createObjectURL(g),qJ=document.createElement("a");qJ.href=c,qJ.download=KJ,qJ.rel="noopener",qJ.style.display="none",document.body.appendChild(qJ),qJ.click(),document.body.removeChild(qJ),URL.revokeObjectURL(c)},[]),DJ=dZ.useCallback(async()=>{try{let g=Z();if(!g)throw Error("Container not available.");let KJ=g.querySelector("canvas");if(!KJ||!(KJ instanceof HTMLCanvasElement))throw Error("No canvas element available for capture.");let c=await new Promise((qJ,d)=>{KJ.toBlob((UJ)=>{if(UJ)qJ(UJ);else d(Error("Canvas capture returned an empty blob."))})});if(c)a(c,`${Y}.png`),console.log("PNG captured")}catch(g){console.error("[ExportWidget] Failed to capture image:",g)}},[Z,Y,a]),_J=dZ.useCallback(()=>{if(!b.current){console.warn("[ExportWidget] No active recorder to stop");return}console.log("Stopping recording"),b.current.stop()},[]),yJ=dZ.useCallback(async()=>{try{let g=Z();if(!g)throw Error("Container not available.");let KJ=g.querySelector("canvas");if(!KJ||!(KJ instanceof HTMLCanvasElement))throw Error("No canvas element available for recording.");if(typeof KJ.captureStream!=="function")throw Error("Canvas captureStream API is not supported in this browser.");let c=KJ.captureStream(60),d=[{mimeType:"video/mp4;codecs=avc1",extension:"mp4"},{mimeType:"video/mp4;codecs=h264",extension:"mp4"},{mimeType:"video/mp4;codecs=avc1.42E01E",extension:"mp4"},{mimeType:"video/mp4",extension:"mp4"},{mimeType:"video/webm;codecs=h264",extension:"webm"},{mimeType:"video/webm;codecs=vp9",extension:"webm"},{mimeType:"video/webm;codecs=vp8",extension:"webm"},{mimeType:"video/webm",extension:"webm"}].find((i)=>MediaRecorder.isTypeSupported(i.mimeType));if(!d)d={mimeType:"",extension:"webm"};console.log("[ExportWidget] Using video format:",d.mimeType||"browser default");let UJ={videoBitsPerSecond:5000000};if(d.mimeType)UJ.mimeType=d.mimeType;let SJ=new MediaRecorder(c,UJ),zJ=[];k.current=zJ,SJ.addEventListener("dataavailable",(i)=>{if(i.data?.size)zJ.push(i.data)}),SJ.addEventListener("stop",()=>{let i=d.mimeType||SJ.mimeType||"video/webm",$J=new Blob(zJ,{type:i});console.log("[ExportWidget] Recording complete:",{size:$J.size,type:$J.type,chunks:zJ.length}),a($J,`${Y}.${d.extension}`),c.getTracks().forEach((LJ)=>LJ.stop()),_(!1),z(!1),b.current=null,k.current=[]}),SJ.start(),b.current=SJ,_(!0),z(!0),console.log("Recording started")}catch(g){console.error("[ExportWidget] Failed to start recording:",g),_(!1),z(!1),b.current=null}},[Z,Y,a,z]),CJ=dZ.useCallback(async()=>{if(y)_J();else await yJ()},[y,_J,yJ]);return A7.jsxDEV("div",{className:"export-widget-container absolute top-0 left-0 py-2 px-2 z-[9999]",children:A7.jsxDEV("div",{className:"flex items-center gap-2",children:[A7.jsxDEV("button",{type:"button",className:`inline-flex items-center gap-2 rounded-lg border border-border bg-background px-2 py-1 text-sm text-text transition hover:bg-muted/80 whitespace-nowrap ${!$?"opacity-60 cursor-not-allowed":""}`,onClick:DJ,disabled:!$,title:"Screenshot",children:[A7.jsxDEV("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A7.jsxDEV("path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"},void 0,!1,void 0,this),A7.jsxDEV("circle",{cx:"12",cy:"13",r:"3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A7.jsxDEV("span",{children:"Screenshot"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A7.jsxDEV("button",{type:"button",className:`inline-flex items-center gap-2 rounded-lg border transition hover:bg-muted/80 whitespace-nowrap px-2 py-1 text-sm ${y?"bg-red-500/20 text-red-400 border-red-500/30":"bg-background text-text border-border"} ${!B?"opacity-60 cursor-not-allowed":""}`,onClick:CJ,disabled:!B,title:y?"Stop Recording":"Record Video",children:[A7.jsxDEV("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A7.jsxDEV("path",{d:"m22 8-6 4 6 4V8Z"},void 0,!1,void 0,this),A7.jsxDEV("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",ry:"2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A7.jsxDEV("span",{children:y?"Stop":"Rec"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var UX=zQ(G8(),1);var b7=zQ(G8(),1);var Q7=zQ(gZ(),1),MM=({canvasWidth:Z,canvasHeight:Y,scale:K,onResize:z})=>{let{isRecording:$}=oX(),[F,B]=b7.useState(!1),[j,y]=b7.useState(null),[_,b]=b7.useState({x:0,y:0}),[k,a]=b7.useState({width:0,height:0}),DJ=window.devicePixelRatio||1,_J=b7.useRef(K),yJ=1;b7.useEffect(()=>{_J.current=K},[K]);let CJ=b7.useCallback((KJ,c)=>{if($)return;c.preventDefault(),c.stopPropagation(),B(!0),y(KJ),b({x:c.clientX,y:c.clientY}),a({width:Z,height:Y})},[Z,Y,$]);b7.useEffect(()=>{if(!F||!j)return;let KJ=(d)=>{let UJ=d.clientX-_.x,SJ=d.clientY-_.y,zJ=_J.current||1,i=j.length===2,$J=j==="e"||j==="w",LJ=j==="n"||j==="s",JJ=k.width,YJ=k.height,TJ=j.includes("e")?UJ*DJ/zJ:j.includes("w")?-UJ*DJ/zJ:0,QJ=j.includes("s")?SJ*DJ/zJ:j.includes("n")?-SJ*DJ/zJ:0;if(JJ=k.width+TJ,YJ=k.height+QJ,d.shiftKey){let AJ=Math.max(1,k.width),BQ=Math.max(1,k.height),vQ=TJ/AJ,mZ=QJ/BQ,cQ=($Q,uQ)=>{if(!Number.isFinite($Q)||$Q<=0)return 1/uQ;return $Q};if($J&&!LJ){let $Q=cQ(1+vQ,AJ);JJ=AJ*$Q,YJ=BQ*$Q}else if(LJ&&!$J){let $Q=cQ(1+mZ,BQ);JJ=AJ*$Q,YJ=BQ*$Q}else if(i){let $Q=Math.abs(vQ)>=Math.abs(mZ),uQ=$Q?vQ:mZ,cZ=$Q?AJ:BQ,Z7=cQ(1+uQ,cZ);JJ=AJ*Z7,YJ=BQ*Z7}}JJ=Math.max(1,JJ),YJ=Math.max(1,YJ),z(JJ,YJ)},c=()=>{B(!1),y(null)},qJ=()=>{B(!1),y(null)};return document.addEventListener("mousemove",KJ),document.addEventListener("mouseup",c),document.addEventListener("mouseleave",qJ),()=>{document.removeEventListener("mousemove",KJ),document.removeEventListener("mouseup",c),document.removeEventListener("mouseleave",qJ)}},[F,j,_,k,DJ,z]);let g=({handle:KJ,className:c})=>Q7.jsxDEV("div",{className:`absolute ${c} group ${$?"cursor-not-allowed opacity-0":""}`,onMouseDown:(qJ)=>CJ(KJ,qJ),style:{zIndex:10},title:$?"Canvas resizing is locked during recording":void 0,children:Q7.jsxDEV("div",{className:`w-full h-full transition-opacity bg-accent/20 ${$?"opacity-0":"opacity-0 group-hover:opacity-100"}`},void 0,!1,void 0,this)},void 0,!1,void 0,this);return Q7.jsxDEV(Q7.Fragment,{children:[Q7.jsxDEV(g,{handle:"nw",className:"top-0 left-0 w-3 h-3 cursor-nw-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"ne",className:"top-0 right-0 w-3 h-3 cursor-ne-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"sw",className:"bottom-0 left-0 w-3 h-3 cursor-sw-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"se",className:"bottom-0 right-0 w-3 h-3 cursor-se-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"n",className:"top-0 left-3 right-3 h-1 cursor-n-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"s",className:"bottom-0 left-3 right-3 h-1 cursor-s-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"w",className:"left-0 top-3 bottom-3 w-1 cursor-w-resize"},void 0,!1,void 0,this),Q7.jsxDEV(g,{handle:"e",className:"right-0 top-3 bottom-3 w-1 cursor-e-resize"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var F4=zQ(gZ(),1),FM=({onReady:Z})=>{let Y=UX.useRef(null),K=UX.useRef(null),{canvasWidth:z,canvasHeight:$,scale:F,setCanvasSize:B,syncWithCanvas:j}=oX(),[y,_]=UX.useState(!1),b=window.devicePixelRatio||1,k=Math.max(1,Math.round(z/b)),a=Math.max(1,Math.round($/b)),DJ=Math.max(1,Math.round(k*F)),_J=Math.max(1,Math.round(a*F));return UX.useEffect(()=>{if(Y.current)Z(Y.current)},[Z]),UX.useEffect(()=>{if(!Y.current||y)return;let yJ=()=>{let KJ=Y.current?.querySelector("canvas");if(KJ&&KJ instanceof HTMLCanvasElement){let{width:c,height:qJ}=KJ;if(c>100&&qJ>100){let d=Math.abs(c-z),UJ=Math.abs(qJ-$);if(d>z*0.1||UJ>$*0.1)console.log("[SandboxContainer] Canvas detected, syncing dimensions"),j(KJ),_(!0)}}};yJ();let CJ=setInterval(yJ,100),g=setTimeout(()=>{clearInterval(CJ),_(!0)},3000);return()=>{clearInterval(CJ),clearTimeout(g)}},[Y,z,$,y,j]),UX.useEffect(()=>{let yJ=new Event("resize");window.dispatchEvent(yJ),console.log("[SandboxContainer] Dispatched resize event:",{canvas:{width:z,height:$},container:{width:k,height:a},display:{width:DJ,height:_J},scale:F})},[z,$,k,a,DJ,_J,F]),F4.jsxDEV("div",{className:"hyper-frame-sandbox-wrapper absolute inset-0 flex items-center justify-center pointer-events-none",children:F4.jsxDEV("div",{ref:K,className:"hyper-frame-sandbox-display-container relative pointer-events-auto",style:{width:`${DJ}px`,height:`${_J}px`,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)"},children:[F4.jsxDEV(MM,{canvasWidth:z,canvasHeight:$,scale:F,onResize:B},void 0,!1,void 0,this),F4.jsxDEV("div",{ref:Y,className:"hyper-frame-sandbox-container absolute top-0 left-0 flex items-center justify-center",style:{width:`${k}px`,height:`${a}px`,overflow:"hidden",transform:`scale(${F})`,transformOrigin:"top left"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var G6=zQ(G8(),1);var FQ=zQ(gZ(),1),BM=[{label:"16:9 Landscape",width:1920,height:1080},{label:"9:16 Portrait",width:1080,height:1920},{label:"4:3 Standard",width:1024,height:768},{label:"1:1 Square",width:1080,height:1080},{label:"21:9 Ultrawide",width:2560,height:1080},{label:"3:2 Classic",width:1440,height:960},{label:"---",width:0,height:0},{label:"iPhone 15 Pro",width:1179,height:2556},{label:"iPhone 15 Pro Max",width:1290,height:2796},{label:"iPhone SE",width:750,height:1334},{label:"iPhone 15",width:1170,height:2532},{label:"---",width:0,height:0},{label:'MacBook Air 13"',width:2560,height:1664},{label:'MacBook Pro 14"',width:3024,height:1964},{label:'MacBook Pro 16"',width:3456,height:2234},{label:'iMac 24"',width:4480,height:2520},{label:"Studio Display",width:5120,height:2880}],AM=()=>{let{canvasWidth:Z,canvasHeight:Y,scale:K,isRecording:z,setCanvasWidth:$,setCanvasHeight:F,setAspectRatio:B,fitToScreen:j}=oX(),[y,_]=G6.useState(Z.toString()),[b,k]=G6.useState(Y.toString());G6.useEffect(()=>{_(Z.toString())},[Z]),G6.useEffect(()=>{k(Y.toString())},[Y]);let a=()=>{if(z)return;let zJ=Math.round(parseFloat(y));if(!isNaN(zJ)&&zJ>=100)$(zJ),_(zJ.toString());else _(Z.toString())},DJ=()=>{if(z)return;let zJ=Math.round(parseFloat(b));if(!isNaN(zJ)&&zJ>=100)F(zJ),k(zJ.toString());else k(Y.toString())},_J=(zJ)=>{if(zJ.key==="Enter")a(),zJ.currentTarget.blur()},yJ=(zJ)=>{if(zJ.key==="Enter")DJ(),zJ.currentTarget.blur()},CJ=(zJ)=>{if(z)return;let i=BM.find(($J)=>$J.label===zJ.target.value);if(i&&i.width>0&&i.height>0)B(i.width,i.height)},g=window.devicePixelRatio||1,KJ=Math.round(Z/g*K),c=Math.round(Y/g*K),qJ=`${Z}×${Y}`,d=`${KJ}×${c}`,UJ=K<1,SJ=Math.round(K*100);return FQ.jsxDEV("div",{className:"canvas-size-widget-container absolute top-0 center px-2 py-2 z-[9999] flex items-center gap-2",children:[FQ.jsxDEV("select",{onChange:CJ,className:`rounded border border-border w-[90px] bg-background px-2 py-1 text-sm text-text focus:border-accent focus:outline-none ${z?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,defaultValue:"",disabled:z,title:z?"Canvas resizing is locked during recording":"Choose a preset size",children:[FQ.jsxDEV("option",{value:"",disabled:!0,children:"Presets"},void 0,!1,void 0,this),BM.map((zJ,i)=>zJ.label==="---"?FQ.jsxDEV("option",{disabled:!0,children:"────────"},i,!1,void 0,this):FQ.jsxDEV("option",{value:zJ.label,children:zJ.label},i,!1,void 0,this))]},void 0,!0,void 0,this),FQ.jsxDEV("div",{className:"flex items-center gap-1",children:[FQ.jsxDEV("label",{className:"text-sm text-accent",children:"W:"},void 0,!1,void 0,this),FQ.jsxDEV("input",{value:y,onChange:(zJ)=>_(zJ.target.value),onBlur:a,onKeyDown:_J,className:`rounded border border-border bg-background px-2 py-1 text-sm text-text focus:border-accent focus:outline-none ${z?"opacity-50 cursor-not-allowed":""}`,style:{width:`${Math.max(y.length*8+16,55)}px`},min:"60",step:"1",disabled:z,title:z?"Canvas resizing is locked during recording":"Canvas width"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV("div",{className:"flex items-center gap-1",children:[FQ.jsxDEV("label",{className:"text-sm text-accent",children:"H:"},void 0,!1,void 0,this),FQ.jsxDEV("input",{value:b,onChange:(zJ)=>k(zJ.target.value),onBlur:DJ,onKeyDown:yJ,className:`rounded border border-border bg-background px-2 py-1 text-sm text-text focus:border-accent focus:outline-none ${z?"opacity-50 cursor-not-allowed":""}`,style:{width:`${Math.max(b.length*8+16,55)}px`},min:"60",step:"1",disabled:z,title:z?"Canvas resizing is locked during recording":"Canvas height"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded border border-border bg-background/50",title:UJ?`Canvas: ${qJ} → Display: ${d} (scaled to ${SJ}%)`:`Canvas: ${qJ} = Display: ${d} (no scaling)`,style:{display:UJ?"flex":"none"},children:[FQ.jsxDEV("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:UJ?"text-accent":"text-muted",children:[FQ.jsxDEV("circle",{cx:"11",cy:"11",r:"8"},void 0,!1,void 0,this),FQ.jsxDEV("path",{d:"m21 21-4.3-4.3"},void 0,!1,void 0,this),FQ.jsxDEV("line",{x1:"11",y1:"8",x2:"11",y2:"14"},void 0,!1,void 0,this),FQ.jsxDEV("line",{x1:"8",y1:"11",x2:"14",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV("div",{className:"flex items-center gap-1",children:FQ.jsxDEV("span",{className:`text-xs ${UJ?"text-accent":"text-muted"}`,children:[SJ,"%"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV("button",{type:"button",className:`inline-flex items-center gap-1 h-[30px] rounded-lg border border-border bg-background px-3 py-2 text-sm text-text transition whitespace-nowrap ${z?"opacity-50 cursor-not-allowed":"hover:bg-muted/80"}`,onClick:j,disabled:z,title:z?"Canvas resizing is locked during recording":"Fit to screen",children:FQ.jsxDEV("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[FQ.jsxDEV("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"},void 0,!1,void 0,this),FQ.jsxDEV("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"},void 0,!1,void 0,this),FQ.jsxDEV("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"},void 0,!1,void 0,this),FQ.jsxDEV("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var d9=zQ(gZ(),1),IM=({onContainerReady:Z,controls:Y,exportWidget:K})=>{let[z,$]=zG.useState(null),F=zG.useCallback((B)=>{$(B),Z(B)},[Z]);return d9.jsxDEV(WM,{children:d9.jsxDEV("div",{className:"hyper-container flex flex-col items-center justify-center",children:[K&&K.enabled&&d9.jsxDEV(HM,{getContainer:()=>z,filename:K.filename,useCanvasCapture:K.useCanvasCapture},void 0,!1,void 0,this),d9.jsxDEV(AM,{},void 0,!1,void 0,this),d9.jsxDEV(FM,{onReady:F},void 0,!1,void 0,this),Y&&d9.jsxDEV(OM,{definitions:Y.definitions,options:Y.options,onChange:Y.onChange,onReady:Y.onReady},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};class $G{cssBridge=null;config;currentExperience=null;constructor(Z={}){this.config=Z,this.setupMessageHandlers()}setupMessageHandlers(){if(typeof window>"u")return;window.addEventListener("message",(Z)=>{let{type:Y,data:K}=Z.data||{};switch(Y){case"CAPTURE_SCREENSHOT":this.handleCaptureScreenshot(Z.data?.requestId);break;case"HYPERTOOL_SET_PARAMS":this.handleSetParams(K?.params);break;case"HYPERTOOL_GET_PARAMS":this.handleGetParams();break}})}handleCaptureScreenshot(Z){let Y=null;if(this.currentExperience)Y=this.currentExperience.mount.querySelector("canvas");if(!Y){let K=document.querySelectorAll("canvas");if(K.length>0){let z=K[0],$=z.width*z.height;K.forEach((F)=>{let B=F,j=B.width*B.height;if(j>$)z=B,$=j}),Y=z}}if(!Y){this.sendToParent("SCREENSHOT_RESULT",{requestId:Z,noCanvas:!0,error:"No canvas found"});return}try{let K=this.createOptimizedThumbnail(Y,400,0.8);this.sendToParent("SCREENSHOT_RESULT",{requestId:Z,dataUrl:K})}catch(K){this.sendToParent("SCREENSHOT_RESULT",{requestId:Z,error:K instanceof Error?K.message:"Unknown error"})}}handleSetParams(Z){if(!Z||!this.currentExperience)return;this.currentExperience.setParams(Z)}handleGetParams(){let Z=this.currentExperience?.getParams()??{};this.sendToParent("HYPERTOOL_PARAMS_RESPONSE",{params:Z})}sendToParent(Z,Y){window.parent.postMessage({type:Z,...Y},"*")}notifyParamChange(Z){let Y={};for(let[K,z]of Object.entries(Z))if(z===null||typeof z==="string"||typeof z==="number"||typeof z==="boolean")Y[K]=z;else if(typeof z==="object")try{Y[K]=JSON.parse(JSON.stringify(z))}catch{}window.parent.postMessage({type:"HYPERTOOL_PARAMS_CHANGED",source:"hypertool-iframe",data:{params:Y}},"*")}createOptimizedThumbnail(Z,Y,K){let{width:z,height:$}=Z,F=z,B=$;if(z>Y){let _=Y/z;F=Y,B=Math.round($*_)}let j=document.createElement("canvas");j.width=F,j.height=B;let y=j.getContext("2d");if(!y)return Z.toDataURL("image/jpeg",K);return y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(Z,0,0,F,B),j.toDataURL("image/jpeg",K)}mirrorCss(){if(this.cssBridge)return;this.cssBridge=new z$({mirror:this.config.mirrorCss!==!1}),this.cssBridge.start()}async createSandbox(Z){if(this.config.mirrorCss!==!1&&Z.mirrorCss!==!1)this.mirrorCss();let Y=await this.createReactMount(Z),K=new u5({mount:Y.sandboxContainer,paramDefs:Z.controls?.definitions,autoplay:!0,setup:($)=>this.wrapUserSetup(Z.setup,$,Z)});if(this.currentExperience=K,K.on("paramChange",()=>{this.notifyParamChange(K.getParams())}),Z.controls?.definitions)this.wireControlsToExperience(K,Y);if(typeof globalThis.__hypertool_registerParams==="function")globalThis.__hypertool_registerParams(K.params);return this.notifyParamChange(K.getParams()),{container:Y.sandboxContainer,controls:null,params:K.params,destroy:()=>{K.destroy(),Y.destroy()}}}wrapUserSetup(Z,Y,K){let z={mount:Y.mount,params:Y.params,controls:null,exports:{registerImageCapture:()=>{},registerVideoCapture:()=>{},setFilename:Y.exports.setFilename,setVisible:()=>{},useDefaultCanvasCapture:()=>{},destroy:()=>{}},runtime:this,environment:{window:Y.environment.window,document:Y.environment.document,addCleanup:Y.environment.addCleanup,onResize:($,F)=>{Y.environment.window.addEventListener("resize",$,F);let B=()=>Y.environment.window.removeEventListener("resize",$,F);return Y.environment.addCleanup(B),B}}};return Z(z)}wireControlsToExperience(Z,Y){}async createReactMount(Z){let Y=Z.mount,K=$M({target:Y?.target,containerClassName:Y?.containerClassName}),z=PM.createRoot(K.element),$=Z.controls?.definitions?{definitions:Z.controls.definitions,options:Z.controls.options,onChange:(j)=>{if(this.currentExperience&&j?.key!==void 0)this.currentExperience.setParam(j.key,j.value);Z.controls?.onChange?.(j,{})},onReady:(j)=>{if(this.currentExperience){let y=j.params;this.currentExperience.setParams(y)}if(typeof globalThis.__hypertool_registerControls==="function")globalThis.__hypertool_registerControls(j)}}:null,B=await new Promise((j)=>{z.render(jM.default.createElement(IM,{onContainerReady:j,controls:$,exportWidget:{enabled:Z.exportWidget?.enabled!==!1,filename:Z.exportWidget?.filename,position:Z.exportWidget?.position,useCanvasCapture:Z.exportWidget?.useCanvasCapture!==!1}}))});if(typeof Y?.onReady==="function")Y.onReady({container:B});return{sandboxContainer:B,destroy:()=>{if(z.unmount(),K.createdInternally)K.element.remove()}}}}var Q_={mirrorCss:!0},OG=new $G(Q_);function Z_(Z){return new $G(Z)}function NM(Z){return OG.createSandbox(Z)}function wM(){OG.mirrorCss()}if(typeof window<"u"){window.hypertoolControls={createControls:K$,createControlPanel:U$,HypertoolControls:u9,injectThemeVariables:H4,studioTheme:D4};let Z=window.hyperFrame||{};window.hyperFrame={...Z,version:"universal",runtime:OG,createSandbox:NM,mirrorCss:wM},G_()}var B4=null,LG=null;function X_(Z){B4=Z}function Y_(Z){LG=Z}if(typeof globalThis<"u")globalThis.__hypertool_registerParams=X_,globalThis.__hypertool_registerControls=Y_;function G_(){if(typeof window>"u")return;let Z={isRecording:!1,recorder:null,recordedChunks:[]};window.addEventListener("message",(B)=>{if(B.data?.source!=="hypertool-main")return;let{type:j}=B.data;switch(j){case"HYPERTOOL_CAPTURE_PNG":z();break;case"HYPERTOOL_START_RECORDING":$();break;case"HYPERTOOL_STOP_RECORDING":F();break;case"HYPERTOOL_GET_PARAMS":Y();break;case"HYPERTOOL_SET_PARAMS":K(B.data.data?.params);break}});function Y(){window.parent.postMessage({type:"HYPERTOOL_PARAMS_RESPONSE",data:{params:B4?{...B4}:{}}},"*")}function K(B){if(!B||typeof B!=="object"){console.warn("[Runtime] Invalid params received in SET_PARAMS");return}if(console.log("[Runtime] Received SET_PARAMS from parent:",Object.keys(B).length,"values"),B4){for(let[j,y]of Object.entries(B))if(y!==void 0)B4[j]=y}if(LG){for(let[j,y]of Object.entries(B))if(y!==void 0)try{LG.set(j,y)}catch(_){}LG.refresh(),console.log("[Runtime] Controls updated with saved values")}}function z(){let B=document.querySelector("canvas");if(B)B.toBlob((j)=>{if(j)window.parent.postMessage({type:"HYPERTOOL_CAPTURE_RESPONSE",data:{blob:j,filename:"hypertool-capture.png"}},"*")},"image/png");else console.warn("No canvas found for capture")}function $(){console.log("Starting recording...");let B=document.querySelector("canvas");if(B&&typeof B.captureStream==="function"){let j=B.captureStream(60),y=new MediaRecorder(j,{mimeType:"video/webm;codecs=vp9"});Z.recordedChunks=[],y.ondataavailable=(_)=>{if(_.data.size>0)Z.recordedChunks.push(_.data),console.log("Recording data available:",_.data.size,"bytes")},y.onstop=()=>{console.log("Recording stopped, processing...");let _=new Blob(Z.recordedChunks,{type:"video/webm"});console.log("Recording blob size:",_.size,"bytes"),window.parent.postMessage({type:"HYPERTOOL_RECORDING_RESPONSE",data:{blob:_,filename:"hypertool-recording.webm"}},"*"),Z.isRecording=!1,Z.recorder=null},y.start(),Z.recorder=y,Z.isRecording=!0,console.log("Recording started successfully")}else console.warn("Canvas not found or captureStream not supported")}function F(){if(console.log("Stopping recording..."),Z.recorder)Z.recorder.stop(),window.parent.postMessage({type:"HYPERTOOL_RECORDING_STOPPED",data:{}},"*"),console.log("Stop recording message sent");else console.warn("No active recorder to stop")}}export{D4 as studioTheme,OG as runtime,X_ as registerSandboxParams,Y_ as registerControlsInstance,wM as mirrorCss,H4 as injectThemeVariables,NM as createSandbox,K$ as createControls,U$ as createControlPanel,Z_ as configureRuntime,f5 as ParamStore,v5 as ObjectRegistry,u9 as HypertoolControls,u5 as Experience,b5 as EventEmitter};
|
|
188
198
|
|
|
189
|
-
|
|
199
|
+
|
|
200
|
+
/* @hypertools/sdk - MIT License - https://hypertools.dev */
|
|
201
|
+
|
|
202
|
+
//# debugId=A9F726608F6E0D0B64756E2164756E21
|