@wireweave/core 4.0.0-beta.14 → 4.0.0-beta.16

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.
Files changed (39) hide show
  1. package/dist/app.cjs +13 -13
  2. package/dist/app.d.cts +2 -2
  3. package/dist/app.d.ts +2 -2
  4. package/dist/app.js +2 -2
  5. package/dist/{chunk-TQSOLTMZ.js → chunk-6EMG345O.js} +251 -41
  6. package/dist/{chunk-NV6UV5ID.cjs → chunk-7ZRMSFWZ.cjs} +286 -75
  7. package/dist/{chunk-ZPHNXJRY.cjs → chunk-CGTYVLPA.cjs} +4 -4
  8. package/dist/{chunk-IMUVIIJR.cjs → chunk-EWCLLW6P.cjs} +11 -3
  9. package/dist/{chunk-SAN6CJEE.cjs → chunk-J5WEVZIX.cjs} +134 -493
  10. package/dist/chunk-KEQRLZQP.js +3066 -0
  11. package/dist/{chunk-XYACLXXF.js → chunk-LBJTNQXU.js} +1 -1
  12. package/dist/{chunk-4DDV6Z2X.js → chunk-MLCJ6NIB.js} +3 -3
  13. package/dist/{chunk-2Y3GKARZ.js → chunk-NMIPMOEJ.js} +73 -432
  14. package/dist/chunk-WCCYK5WK.cjs +3077 -0
  15. package/dist/{chunk-LA5LKIEL.cjs → chunk-XZL42ZQ2.cjs} +28 -28
  16. package/dist/{chunk-3RWGG5EC.js → chunk-YAANMWP2.js} +11 -4
  17. package/dist/{index-BD_4rXH-.d.cts → index-CIfur9e3.d.cts} +1 -1
  18. package/dist/{index-YSIzfhOd.d.cts → index-DdQv4Bu5.d.cts} +7 -1
  19. package/dist/{index-g9yV20xb.d.ts → index-DwGsnD0n.d.ts} +1 -1
  20. package/dist/{index-BEnsO2kE.d.ts → index-c4FTW7XA.d.ts} +7 -1
  21. package/dist/index.cjs +238 -222
  22. package/dist/index.d.cts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +11 -11
  25. package/dist/interaction.cjs +6 -6
  26. package/dist/interaction.js +1 -1
  27. package/dist/parser.cjs +9 -9
  28. package/dist/parser.js +1 -1
  29. package/dist/renderer.cjs +32 -32
  30. package/dist/renderer.d.cts +2 -2
  31. package/dist/renderer.d.ts +2 -2
  32. package/dist/renderer.js +3 -3
  33. package/dist/spec.cjs +39 -23
  34. package/dist/spec.d.cts +45 -1
  35. package/dist/spec.d.ts +45 -1
  36. package/dist/spec.js +1 -1
  37. package/package.json +19 -13
  38. package/dist/chunk-MD6MNOEQ.cjs +0 -2884
  39. package/dist/chunk-V3HVWC7C.js +0 -2874
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkNV6UV5ID_cjs = require('./chunk-NV6UV5ID.cjs');
4
- var chunkIMUVIIJR_cjs = require('./chunk-IMUVIIJR.cjs');
3
+ var chunk7ZRMSFWZ_cjs = require('./chunk-7ZRMSFWZ.cjs');
4
+ var chunkEWCLLW6P_cjs = require('./chunk-EWCLLW6P.cjs');
5
5
  var chunkETV4XYOV_cjs = require('./chunk-ETV4XYOV.cjs');
6
6
 
7
7
  // src/ast/component-parameters.ts
@@ -64,8 +64,8 @@ function definitionKey(namespace, kind, id) {
64
64
  function nodeSource(module) {
65
65
  return module.source;
66
66
  }
67
- function manifestSource(manifest, location2) {
68
- return { sourceId: manifest.sourceId, location: location2 };
67
+ function manifestSource(manifest, location) {
68
+ return { sourceId: manifest.sourceId, location };
69
69
  }
70
70
  function componentUses(node) {
71
71
  const uses = [];
@@ -405,7 +405,7 @@ function expandNode(node, path, context) {
405
405
  return clone;
406
406
  }
407
407
  function linkApp(input, modules) {
408
- if (modules === void 0) return chunkNV6UV5ID_cjs.linkAppV4(input);
408
+ if (modules === void 0) return chunk7ZRMSFWZ_cjs.linkAppV4(input);
409
409
  return linkLegacyApp(input, modules);
410
410
  }
411
411
  function linkLegacyApp(manifest, modules) {
@@ -580,7 +580,7 @@ function linkLegacyApp(manifest, modules) {
580
580
  source: node.source
581
581
  }))
582
582
  );
583
- const document2 = {
583
+ const document = {
584
584
  type: "AppDocument",
585
585
  id: manifest.id,
586
586
  modules: resolvedModules,
@@ -589,9 +589,12 @@ function linkLegacyApp(manifest, modules) {
589
589
  screens: linkedScreens,
590
590
  sourceMap
591
591
  };
592
- return { ok: true, document: document2, diagnostics: [] };
592
+ return { ok: true, document, diagnostics: [] };
593
593
  }
594
594
 
595
+ // src/app/native-runtime.generated.ts
596
+ var NATIVE_RUNTIME = '(()=>{function runtimeEngine(program2){const nodes=new Map(program2.nodes.map(node=>[node.id,node]));const byIdentity=new Map(program2.nodes.map(node=>[canonical(node.identity),node]));const fixtures=new Map(program2.fixtures.map(fixture=>[fixture.id,fixture]));const clone=value=>JSON.parse(JSON.stringify(value));const record=value=>value!==null&&typeof value==="object"&&!Array.isArray(value)?value:{};const scalar=value=>{if(value==null)return"";if(typeof value==="string")return value;if(typeof value==="number"||typeof value==="boolean")return String(value);if(typeof value==="object")return canonical(value);throw Error("scalar-type")};function canonical(value){if(Array.isArray(value))return"["+value.map(canonical).join(",")+"]";if(value!==null&&typeof value==="object")return"{"+Object.keys(value).sort().map(key=>JSON.stringify(key)+":"+canonical(value[key])).join(",")+"}";return JSON.stringify(value)}function bounded(value){const stack=[{value,depth:0}];let count=0;while(stack.length){const entry=stack.pop();if(++count>25e4||entry.depth>128)throw Error("limit-json");const item=entry.value;if(typeof item==="string"){for(const character of item){const code=character.codePointAt(0);if(code>=55296&&code<=57343)throw Error("invalid-unicode")}}else if(typeof item==="number"){if(!Number.isFinite(item))throw Error("non-finite-number")}else if(Array.isArray(item)){if(item.length>1e4)throw Error("limit-list");for(const child of item)stack.push({value:child,depth:entry.depth+1})}else if(item!==null&&typeof item==="object"){const entries=Object.entries(item);if(entries.length>1e3)throw Error("limit-record");for(const[key,child]of entries){bounded(key);stack.push({value:child,depth:entry.depth+1})}}else if(item!==null&&typeof item!=="boolean")throw Error("invalid-json")}}function hash(source){var _a,_b,_c,_d,_e,_f,_g;const k=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];const bytes=new TextEncoder().encode(source),padded=new Uint8Array(Math.ceil((bytes.length+9)/64)*64);padded.set(bytes);padded[bytes.length]=128;const view2=new DataView(padded.buffer);view2.setUint32(padded.length-8,Math.floor(bytes.length/536870912));view2.setUint32(padded.length-4,bytes.length*8>>>0);const h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],words=new Uint32Array(64);const rotate=(value,shift)=>value>>>shift|value<<32-shift;for(let block=0;block<padded.length;block+=64){for(let index=0;index<16;index++)words[index]=view2.getUint32(block+index*4);for(let index=16;index<64;index++){const x=(_a=words[index-15])!=null?_a:0,y=(_b=words[index-2])!=null?_b:0;words[index]=((_c=words[index-16])!=null?_c:0)+(rotate(x,7)^rotate(x,18)^x>>>3)+((_d=words[index-7])!=null?_d:0)+(rotate(y,17)^rotate(y,19)^y>>>10)>>>0}let[a=0,b=0,c=0,d=0,e=0,f=0,g=0,v=0]=h;for(let index=0;index<64;index++){const first=v+(rotate(e,6)^rotate(e,11)^rotate(e,25))+(e&f^~e&g)+((_e=k[index])!=null?_e:0)+((_f=words[index])!=null?_f:0)>>>0,second=(rotate(a,2)^rotate(a,13)^rotate(a,22))+(a&b^a&c^b&c)>>>0;v=g;g=f;f=e;e=d+first>>>0;d=c;c=b;b=a;a=first+second>>>0}for(const[index,value]of[a,b,c,d,e,f,g,v].entries())h[index]=((_g=h[index])!=null?_g:0)+value>>>0}return"sha256:"+h.map(value=>value.toString(16).padStart(8,"0")).join("")}function range(code,ranges){let low=0,high=ranges.length-1;while(low<=high){const middle=low+high>>>1,pair=ranges[middle];if(code<pair[0])high=middle-1;else if(code>pair[1])low=middle+1;else return true}return false}function convert(value,mode){if(typeof value!=="string")throw Error("value-type");const chars=Array.from(value);if(mode==="trim"){let start=0,end=chars.length;while(start<end&&range(chars[start].codePointAt(0),program2.unicode.whitespace))start++;while(end>start&&range(chars[end-1].codePointAt(0),program2.unicode.whitespace))end--;return chars.slice(start,end).join("")}return chars.map((character,index)=>{var _a;if(mode==="lower"&&character==="\\u03A3"){let before=index-1,after=index+1;while(before>=0&&range(chars[before].codePointAt(0),program2.unicode.ignorable))before--;while(after<chars.length&&range(chars[after].codePointAt(0),program2.unicode.ignorable))after++;if(before>=0&&range(chars[before].codePointAt(0),program2.unicode.cased)&&!(after<chars.length&&range(chars[after].codePointAt(0),program2.unicode.cased)))return"\\u03C2"}return(_a=(mode==="upper"?program2.unicode.upper:program2.unicode.lower)[String(character.codePointAt(0))])!=null?_a:character}).join("")}function expression(raw,node,state,event={},depth=0){var _a;if(depth>128)throw Error("limit-expression");const value=record(raw);if(Object.hasOwn(value,"literal"))return value.literal;if(typeof value.state==="string"){const binding=node.bindings[value.state];if(!binding)throw Error("missing-state");return state.states[binding.key]}if(typeof value.event==="string"){if(!Object.hasOwn(event,value.event))throw Error("event-value-unavailable");return event[value.event]}if(value.read){const read=record(value.read);let result=expression(read.source,node,state,event,depth+1);for(const key of read.path){if(["__proto__","constructor","prototype"].includes(String(key))||result===null||typeof result!=="object"||!Object.hasOwn(result,key))throw Error("missing-read-path");result=result[key]}return result}if(typeof value.call==="string"){const args=value.args.map(arg=>expression(arg,node,state,event,depth+1));if(value.call==="length"&&args.length===1&&(typeof args[0]==="string"||Array.isArray(args[0])))return Array.from(args[0]).length;if(["lower","upper","trim"].includes(value.call)&&args.length===1)return convert(args[0],value.call);if(value.call==="concat"&&args.length>=2&&args.length<=16&&args.every(arg=>typeof arg==="string"))return args.join("");if(value.call==="coalesce"&&args.length>=2&&args.length<=16)return(_a=args.find(arg=>arg!==null))!=null?_a:null;if(["add","subtract","multiply","divide"].includes(value.call)&&args.length===2&&args.every(arg=>typeof arg==="number")){const a=args[0],b=args[1];if(value.call==="divide"&&b===0)throw Error("division-by-zero");const result=value.call==="add"?a+b:value.call==="subtract"?a-b:value.call==="multiply"?a*b:a/b;if(!Number.isFinite(result))throw Error("non-finite-number");return result}}throw Error("expression-type")}function compare(a,b){if(typeof a!==typeof b||!["number","string"].includes(typeof a))throw Error("comparison-type");if(typeof a==="number"&&typeof b==="number")return a===b?0:a<b?-1:1;const left=Array.from(a),right=Array.from(b);for(let index=0;index<Math.min(left.length,right.length);index++)if(left[index]!==right[index])return left[index].codePointAt(0)<right[index].codePointAt(0)?-1:1;return left.length-right.length}function guard(raw,node,state,event={}){if(raw===void 0)return true;const value=record(raw);if(value.op==="all")return value.guards.every(item=>guard(item,node,state,event));if(value.op==="any")return value.guards.some(item=>guard(item,node,state,event));if(value.op==="not")return!guard(value.guard,node,state,event);const left=expression(value.left,node,state,event),right=expression(value.right,node,state,event);if(value.op==="eq")return canonical(left)===canonical(right);if(value.op==="ne")return canonical(left)!==canonical(right);if(value.op==="in"&&Array.isArray(right))return right.some(item=>canonical(item)===canonical(left));if(["contains","startsWith"].includes(scalar(value.op))&&typeof left==="string"&&typeof right==="string")return value.op==="contains"?left.includes(right):left.startsWith(right);const order=compare(left,right);if(value.op==="lt")return order<0;if(value.op==="lte")return order<=0;if(value.op==="gt")return order>0;if(value.op==="gte")return order>=0;throw Error("guard-type")}function routeAddress(route){return"#wf/"+encodeURIComponent(route.namespace)+"/"+encodeURIComponent(route.id)+(route.variant===void 0?"":"?variant="+encodeURIComponent(route.variant))}function parseAddress(fragment){if(fragment==="")return clone(program2.entry);try{const match=/^#wf\\/([^/?]+)\\/([^/?]+)(?:\\?variant=([^&]*))?$/.exec(fragment);if(!match)return null;const result={namespace:decodeURIComponent(match[1]),id:decodeURIComponent(match[2])};if(match[3]!==void 0)result.variant=decodeURIComponent(match[3]);const screen=program2.screens.find(screen2=>screen2.route.namespace===result.namespace&&screen2.route.id===result.id);return screen&&(result.variant===void 0||screen.variants.includes(result.variant))?result:null}catch(error){void error;return null}}function screenOf(state){return program2.screens.find(screen=>{var _a,_b;return screen.route.namespace===((_a=state.route)==null?void 0:_a.namespace)&&screen.route.id===((_b=state.route)==null?void 0:_b.id)})}function roots(state){const screen=screenOf(state);return screen?["app","screen/"+screen.route.namespace+"/"+screen.route.id,...screen.shell?[program2.shells.find(shell=>shell.id===screen.shell).root]:[]]:["app"]}function descendant(id,ancestor){let node=nodes.get(id);while(node){if(node.id===ancestor)return true;node=node.parent?nodes.get(node.parent):void 0}return false}function visible(node,state){var _a,_b,_c;const mounted=roots(state);let current=node;while(current){if(!mounted.includes(current.root)||!guard(current.attributes.visibleWhen,current,state))return false;if((["modal","drawer","popover"].includes(current.kind)||current.kind==="dropdown"&&current.id!==node.id)&&!state.overlays.some(overlay=>overlay.id===current.id))return false;if(current.kind==="tab"&&current.parent&&current.id!==node.id){const owner=nodes.get(current.parent);if((owner==null?void 0:owner.kind)==="tabs"&&owner.children.filter(id=>{var _a2;return((_a2=nodes.get(id))==null?void 0:_a2.kind)==="tab"})[(_a=state.selection[owner.id])!=null?_a:0]!==current.id)return false}const when=current.attributes.when;if(when!==void 0){const screen=screenOf(state);const variant=(_c=(_b=state.route)==null?void 0:_b.variant)!=null?_c:screen==null?void 0:screen.variants[0];if(!(Array.isArray(when)?when.includes(variant!=null?variant:""):when===variant))return false}current=current.parent?nodes.get(current.parent):void 0}return true}function enabled(node,state){let current=node;while(current){if(current.attributes.disabled===true||current.attributes.loading===true||!guard(current.attributes.enabledWhen,current,state))return false;current=current.parent?nodes.get(current.parent):void 0}return true}function active(node,state){if(!visible(node,state)||!enabled(node,state))return false;const modal=state.overlays.filter(overlay=>overlay.modal).at(-1);return!modal||descendant(node.id,modal.id)}function focusable(node,state){return active(node,state)&&(["input","textarea","select","checkbox","radio","switch","slider","button","link","nav-item","dropdown-item","page","modal","drawer","popover","dropdown","tabs","tab","accordion"].includes(node.kind)||node.attributes.scroll===true)}function controlValue(node,state){var _a,_b,_c,_d;const raw=(_a=state.controls[node.id])!=null?_a:{value:"",checked:false},bind=record(node.attributes.bind),binding=node.bindings[scalar(bind.state)];if(!binding||state.invalid[node.id]||raw.pending)return raw;const value=state.states[binding.key];if(node.kind==="radio")return{value:(_b=node.attributes.value)!=null?_b:"",checked:canonical(value)===canonical((_c=node.attributes.value)!=null?_c:"")};return bind.property==="checked"?{value:(_d=node.attributes.value)!=null?_d:"",checked:value===true}:{value,checked:raw.checked}}function view(state){const result={visible:{},enabled:{},controls:{},states:state.states,data:{}};for(const node of program2.nodes){result.visible[node.id]=visible(node,state);result.enabled[node.id]=enabled(node,state);result.controls[node.id]=controlValue(node,state);if(node.attributes.data)result.data[node.id]=expression(node.attributes.data,node,state)}return result}function append(state,node,handler,operation,event,result,diagnostic=null,before=state.states){var _a,_b,_c,_d,_e,_f;const delta={};for(const[key,value]of Object.entries(state.states))if(canonical(before[key])!==canonical(value))delta[key]=((_a=program2.states[key])==null?void 0:_a.sensitive)?"[redacted]":value;const normalized=clone(event),binding=node==null?void 0:node.bindings[scalar(record(node==null?void 0:node.attributes.bind).state)];if((binding==null?void 0:binding.sensitive)||(node==null?void 0:node.attributes.inputType)==="password"){if("value"in normalized)normalized.value="[redacted]";if("checked"in normalized)normalized.checked="[redacted]"}state.trace.push({schemaVersion:"1.0.0",appId:program2.appId,modelDigest:program2.modelDigest,profileDigest:program2.profileDigest,sequence:++state.sequence,resetGeneration:state.resetGeneration,virtualTime:state.virtualTime,route:clone(state.route),source:(_b=node==null?void 0:node.identity)!=null?_b:null,renderedId:(_c=node==null?void 0:node.id)!=null?_c:null,handlerId:(_d=handler==null?void 0:handler.id)!=null?_d:null,operationId:(_e=operation==null?void 0:operation.id)!=null?_e:null,executionClass:(_f=operation==null?void 0:operation.executionClass)!=null?_f:"runtime",event:normalized,stateDeltaDigest:hash(canonical(delta)),result,diagnostic});if(diagnostic)state.diagnostic=diagnostic}function write(state,binding,value,requestId){if(!binding)throw Error("missing-state");const held=state.reservations[binding.key];if(held&&held!==requestId)throw Error("state-busy");bounded(value);const valid=binding.type==="list"?Array.isArray(value):binding.type==="record"?value!==null&&typeof value==="object"&&!Array.isArray(value):typeof value===binding.type;if(!valid)throw Error("state-type");state.states[binding.key]=clone(value)}let microsteps=0;function tick(){if(++microsteps>256)throw Error("limit-microsteps")}function enqueue(state,item){if(state.queue.length>=4096)throw Error("limit-queue");state.queue.push(item)}function fieldError(node,state){var _a,_b;const attrs=node.attributes,control=controlValue(node,state);if(!visible(node,state)||!enabled(node,state)||attrs.readonly===true)return null;const value=control.value,text=scalar(value),type=node.kind==="input"?scalar((_a=attrs.inputType)!=null?_a:"text"):node.kind;if(attrs.required===true&&(["checkbox","switch"].includes(type)&&!control.checked||type==="radio"&&!program2.nodes.some(other=>other.kind==="radio"&&other.form===node.form&&other.attributes.name===attrs.name&&controlValue(other,state).checked)||!["checkbox","switch","radio"].includes(type)&&text===""))return"required";if(text==="")return null;if(typeof attrs.minLength==="number"&&Array.from(text).length<attrs.minLength)return"too-short";if(typeof attrs.maxLength==="number"&&Array.from(text).length>attrs.maxLength)return"too-long";if(type==="email"&&!/^[a-zA-Z0-9.!#$%&\'*+\\-/=?^_`{|}~]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/.test(text))return"email";if(type==="url"){try{const url=new URL(text);if(!url.protocol)return"url"}catch(error){void error;return"url"}}if(type==="date"){const match=/^(\\d{4,})-(\\d\\d)-(\\d\\d)$/.exec(text);if(!match)return"date";const year=Number(match[1]),month=Number(match[2]),day=Number(match[3]),days=[31,year%4===0&&(year%100!==0||year%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];if(year<1||month<1||month>12||day<1||day>((_b=days[month-1])!=null?_b:0))return"date"}if(type==="number"||type==="slider"){const number=typeof value==="number"?value:Number(text);if(!Number.isFinite(number))return"number";const min=typeof attrs.min==="number"?attrs.min:type==="slider"?0:void 0,max=typeof attrs.max==="number"?attrs.max:type==="slider"?100:void 0,step=typeof attrs.step==="number"?attrs.step:1;if(min!==void 0&&number<min)return"range-underflow";if(max!==void 0&&number>max)return"range-overflow";const remainder=(number-(min!=null?min:0))/step;if(Math.abs(remainder-Math.round(remainder))>1e-9)return"step-mismatch"}if(node.kind==="select"&&!attrs.options.some(option=>option.disabled!==true&&canonical(option.value)===canonical(value)))return"option";return null}function validateForm(state,form){let first;for(const control of program2.nodes.filter(node=>node.form===form.id&&["input","textarea","select","checkbox","radio","switch","slider"].includes(node.kind))){const error=fieldError(control,state);if(error){state.invalid[control.id]=error;first!=null?first:first=control}else delete state.invalid[control.id]}if(first){state.invalid[form.id]="form-invalid";state.focus=first.id;return false}delete state.invalid[form.id];return true}function normalizeControl(state,node,event){var _a,_b;const bind=record(node.attributes.bind),target=node.bindings[scalar(bind.state)],previous=(_a=state.controls[node.id])!=null?_a:{value:"",checked:false};const raw={value:Object.hasOwn(event,"value")?event.value:previous.value,checked:typeof event.checked==="boolean"?event.checked:previous.checked,pending:!!target&&bind.update!==event.type};if(node.attributes.readonly===true)throw Error("readonly-control");state.controls[node.id]=raw;if(!target||bind.update!==event.type)return;if(node.kind==="radio"&&!raw.checked)return;let value=bind.property==="checked"?raw.checked:raw.value;if(node.kind==="radio")value=(_b=node.attributes.value)!=null?_b:"";else if(node.kind==="select"){const option=node.attributes.options.find(option2=>option2.disabled!==true&&scalar(option2.value)===scalar(raw.value));if(!option)throw Error("option");value=option.value}else if(target.type==="number"){if(value===""){state.invalid[node.id]="number";throw Error("invalid-edit")}value=typeof value==="number"?value:Number(value);if(!Number.isFinite(value)){state.invalid[node.id]="number";throw Error("invalid-edit")}}else if(target.type==="boolean"&&bind.property!=="checked"){if(![true,false,"true","false"].includes(value))throw Error("state-type");value=value===true||value==="true"}const check=clone(state);delete check.invalid[node.id];check.controls[node.id]={...raw,value};if(target)check.states[target.key]=value;const error=fieldError(node,check);if(error&&["too-short","too-long","range-underflow","range-overflow","step-mismatch","number","option"].includes(error)){state.invalid[node.id]=error;throw Error("invalid-edit")}write(state,target,value);raw.pending=false;delete state.invalid[node.id]}function resolveTarget(node,effect){const target=record(effect.target),id=node.targets[scalar(target.scope)+":"+scalar(target.id)],resolved=nodes.get(id!=null?id:"");if(!resolved)throw Error("missing-target");return resolved}function openOverlay(state,target,opener){var _a,_b;if(state.overlays.some(overlay=>overlay.id===target.id))return;if(!roots(state).includes(target.root)||!guard(target.attributes.visibleWhen,target,state)||target.parent&&!visible(nodes.get(target.parent),state))throw Error("inactive-target");const modal=target.kind==="modal"||target.kind==="drawer"&&target.attributes.modal!==false;state.overlays.push({id:target.id,opener:opener.id,modal});if(target.kind==="tooltip")return;const initial2=nodes.get((_a=target.targets.initialFocus)!=null?_a:"");const first=initial2!=null?initial2:program2.nodes.find(node=>node.id!==target.id&&descendant(node.id,target.id)&&focusable(node,state));if(initial2&&!focusable(initial2,state))throw Error("invalid-focus");state.focus=(_b=first==null?void 0:first.id)!=null?_b:target.id}function closeOverlay(state,target){var _a,_b;const index=state.overlays.findIndex(overlay=>overlay.id===target.id);if(index<0)return;const opener=state.overlays[index].opener;if(target.kind==="tooltip"){state.overlays.splice(index,1);return}state.overlays.splice(index);const candidate=opener?nodes.get(opener):void 0;state.focus=candidate&&focusable(candidate,state)?candidate.id:(_b=(_a=screenOf(state))==null?void 0:_a.id)!=null?_b:null}function schedule(state,node,activation,operation){var _a,_b,_c,_d,_e;const effect=operation.effect,fixture=fixtures.get(scalar(effect.fixtureRef));if(!fixture)throw Error("missing-fixture");if(Object.keys(state.requests).length>=128)throw Error("limit-requests");const output=[scalar(effect.resultState),scalar(effect.statusState),scalar(effect.errorState)].map(ref=>node.bindings[ref]);if(output.some(item=>!item)||new Set(output.map(item=>item.key)).size!==3)throw Error("fixture-output-alias");for(const item of output)if(state.reservations[item.key])throw Error("state-busy");const cursor=(_a=state.fixtureCursors[fixture.id])!=null?_a:0,step=(_b=fixture.steps[cursor])!=null?_b:fixture.exhaustion==="repeat-last"?fixture.steps.at(-1):void 0;state.fixtureCursors[fixture.id]=cursor+1;const sequence=++state.requestSequence,id=state.resetGeneration+":"+sequence,timeout=Number(effect.timeoutMs);const deadline=state.virtualTime+timeout,responseAt=state.virtualTime+((_c=step==null?void 0:step.delayMs)!=null?_c:0);if(!Number.isSafeInteger(deadline)||!Number.isSafeInteger(responseAt))throw Error("limit-clock");const request={id,generation:state.resetGeneration,sequence,activation:activation.id,owner:node.id,operation:clone(operation),resultKey:output[0].key,statusKey:output[1].key,errorKey:output[2].key,deadline,responseAt,outcome:(_d=step==null?void 0:step.outcome)!=null?_d:"exhausted",value:clone((_e=step==null?void 0:step.value)!=null?_e:null)};for(const item of output)state.reservations[item.key]=id;write(state,output[1],"pending",id);write(state,output[2],{},id);state.requests[id]=request;state.scheduled.push({time:deadline,priority:0,sequence,requestId:id,generation:state.resetGeneration,owner:node.id,operationId:operation.id});if(request.outcome!=="timeout")state.scheduled.push({time:responseAt,priority:1,sequence,requestId:id,generation:state.resetGeneration,owner:node.id,operationId:operation.id});if(state.scheduled.length>4096)throw Error("limit-queue");state.activations[String(activation.id)]=clone(activation)}function applyOperation(state,node,activation,operation,segment){var _a;tick();const effect=operation.effect,kind=scalar(effect.kind),event=activation.event;if(kind==="specify")return"specified-unexecuted";if(kind==="simulate"){schedule(state,node,activation,operation);return"pending"}if(kind==="set"){write(state,node.bindings[scalar(effect.state)],expression(effect.value,node,state,event));return"succeeded"}if(kind==="reset"){const binding=node.bindings[scalar(effect.state)];write(state,binding,binding.initial);for(const child of program2.nodes)if(((_a=child.bindings[scalar(record(child.attributes.bind).state)])==null?void 0:_a.key)===binding.key)delete state.invalid[child.id];return"succeeded"}if(kind==="toggle"){const binding=node.bindings[scalar(effect.state)],value=state.states[binding.key];if(typeof value!=="boolean")throw Error("state-type");write(state,binding,!value);return"succeeded"}if(kind==="filter"||kind==="sort"){const source=state.states[node.bindings[scalar(effect.source)].key];if(!Array.isArray(source))throw Error("list-type");const field=scalar(effect.field);let result;if(kind==="filter"){const query=convert(expression(effect.query,node,state,event),"lower");for(const item of source)if(!Object.hasOwn(record(item),field)||typeof record(item)[field]!=="string")throw Error("filter-field-type");result=source.filter(item=>convert(record(item)[field],"lower").includes(query))}else{let type;for(const item of source){const value=record(item)[field];if(!Object.hasOwn(record(item),field)||!["number","string"].includes(typeof value)||type&&type!==typeof value)throw Error("sort-field-type");type=typeof value}result=source.map((value,index)=>({value,index})).sort((a,b)=>compare(record(a.value)[field],record(b.value)[field])*(effect.direction==="descending"?-1:1)||a.index-b.index).map(item=>item.value)}write(state,node.bindings[scalar(effect.target)],result);return"succeeded"}if(["open","close","toggleOverlay","focus","validate"].includes(kind)){const target=resolveTarget(node,effect);if(kind==="validate"){if(!active(target,state))throw Error("inactive-target");if(!validateForm(state,target))throw Error("form-invalid")}else if(kind==="focus"){if(!focusable(target,state))throw Error("invalid-focus");state.focus=target.id}else if(kind==="close"||kind==="toggleOverlay"&&state.overlays.some(item=>item.id===target.id))closeOverlay(state,target);else openOverlay(state,target,node);return"succeeded"}if(kind==="navigate"){const target=record(effect.target);if(target.kind==="url"){state.effects.push({kind:"external",fragment:scalar(target.url),sequence:0,delta:0});return"succeeded"}const route=target.screen;const fragment=routeAddress(route);if(!parseAddress(fragment))throw Error("missing-route");segment.route={fragment,mode:effect.history==="replace"?"replace":"push",index:null,browserSequence:null};return"succeeded"}if(kind==="navigateBack"||kind==="navigateForward"){const index=state.historyIndex+(kind==="navigateBack"?-1:1);if(index<0||index>=state.history.length)return"history-boundary";segment.route={fragment:state.history[index].fragment,mode:"traverse",index,browserSequence:null};return"succeeded"}if(kind==="resetScenario"){segment.reset=true;return"succeeded"}throw Error("unsupported-operation")}function cancelRequest(state,request,surviving,reset2=false){var _a,_b;for(const key of[request.resultKey,request.statusKey,request.errorKey])delete state.reservations[key];if(!reset2){for(const[key,value]of[[request.statusKey,"cancelled"],[request.errorKey,{code:"cancelled",value:null,operationId:request.operation.id}]]){const binding=program2.states[key];if(binding&&(binding.lifetime==="session"||surviving.includes(binding.root)))write(state,binding,value)}}const node=nodes.get(request.owner),activation=state.activations[String(request.activation)],handler=(_a=node.handlers.find(handler2=>handler2.id===(activation==null?void 0:activation.handlerId)))!=null?_a:null;delete state.requests[request.id];state.scheduled=state.scheduled.filter(item=>item.requestId!==request.id||item.priority===1);delete state.activations[String(request.activation)];state.queue=state.queue.filter(item=>item.source!==request.owner);append(state,node,handler,request.operation,(_b=activation==null?void 0:activation.event)!=null?_b:{},"cancelled")}function ensureFocus(state,previous,observed){var _a,_b,_c;for(const overlay of[...state.overlays]){const node=nodes.get(overlay.id);if(node&&!visible(node,state))closeOverlay(state,node)}let target=state.focus?nodes.get(state.focus):void 0;if(target&&!focusable(target,state)){while(target==null?void 0:target.parent){target=nodes.get(target.parent);if(target&&focusable(target,state))break}state.focus=target&&focusable(target,state)?target.id:(_b=(_a=screenOf(state))==null?void 0:_a.id)!=null?_b:null}if(state.focus!==previous.focus){for(const[source,type]of[[previous.focus,"blur"],[state.focus,"focus"]]){if(!source||(observed==null?void 0:observed.source)===source&&observed.type===type||!((_c=nodes.get(source))==null?void 0:_c.handlers.some(handler=>handler.event===type))||state.queue.some(item=>item.source===source&&item.event.type===type&&item.handlerId===null))continue;enqueue(state,{source,event:{type},handlerId:null})}}}function lifecycle(state,ids,event){for(const id of ids){const node=nodes.get(id!=null?id:"");if(!node)continue;const handler=node.handlers.find(handler2=>handler2.event===event);if(!handler)continue;tick();if(!guard(handler.guard,node,state))continue;const activation={id:++state.activationSequence,owner:node.id,handlerId:handler.id,event:{type:event},index:0,statuses:{}},segment={route:null,reset:false};for(const operation of handler.operations){const before=clone(state.states);if(operation.after.some(id2=>activation.statuses[id2]!=="succeeded")){activation.statuses[operation.id]="skipped-dependency";append(state,node,handler,operation,activation.event,"skipped-dependency");continue}try{const result=applyOperation(state,node,activation,operation,segment);activation.statuses[operation.id]=result;append(state,node,handler,operation,activation.event,result,null,before)}catch(error){activation.statuses[operation.id]="failed";append(state,node,handler,operation,activation.event,"failed",error.message);if(operation.onFailure==="stop")throw error}}if(segment.route||segment.reset)throw Error("exit-effect")}}function changeRoute(state,request){var _a;const route=parseAddress(request.fragment),current=screenOf(state),next=program2.screens.find(screen=>screen.route.namespace===(route==null?void 0:route.namespace)&&screen.route.id===(route==null?void 0:route.id));const identical=canonical(state.route)===canonical(route)&&state.address===(request.fragment||routeAddress(program2.entry));if(identical&&request.mode==="push")return;const departed=(current==null?void 0:current.id)!==(next==null?void 0:next.id),oldRoots=roots(state),nextRoots=next?["app","screen/"+next.route.namespace+"/"+next.route.id,...next.shell?[program2.shells.find(shell=>shell.id===next.shell).root]:[]]:["app"];if(departed){for(const pending of Object.values(state.requests))if(!nextRoots.includes(nodes.get(pending.owner).root))cancelRequest(state,pending,nextRoots);lifecycle(state,[current==null?void 0:current.id,(current==null?void 0:current.shell)!==(next==null?void 0:next.shell)?current==null?void 0:current.shell:null],"exit");state.overlays=state.overlays.filter(overlay=>nextRoots.includes(nodes.get(overlay.id).root));for(const binding of Object.values(program2.states))if(binding.lifetime==="mount"&&oldRoots.includes(binding.root)&&!nextRoots.includes(binding.root))state.states[binding.key]=clone(binding.initial);for(const node of program2.nodes)if(oldRoots.includes(node.root)&&!nextRoots.includes(node.root)){delete state.invalid[node.id];state.controls[node.id]=initialControl(node)}state.queue=state.queue.filter(item=>{var _a2,_b;return nextRoots.includes((_b=(_a2=nodes.get(item.source))==null?void 0:_a2.root)!=null?_b:"")})}state.route=route;state.address=request.fragment||routeAddress(program2.entry);if(request.mode==="push"){state.history=state.history.slice(0,state.historyIndex+1);const sequence=state.nextHistorySequence++;state.history.push({fragment:state.address,sequence});state.historyIndex=state.history.length-1;state.effects.push({kind:"push",fragment:state.address,sequence,delta:0})}else if(request.mode==="replace"){const sequence=state.history[state.historyIndex].sequence;state.history[state.historyIndex]={fragment:state.address,sequence};state.effects.push({kind:"replace",fragment:state.address,sequence,delta:0})}else if(request.index!==null){const delta=request.index-state.historyIndex;state.historyIndex=request.index;if(request.mode==="traverse")state.effects.push({kind:"traverse",fragment:state.address,sequence:state.history[request.index].sequence,delta})}else{const sequence=state.nextHistorySequence++;state.history=[{fragment:state.address,sequence}];state.historyIndex=0;state.effects.push({kind:"replace",fragment:state.address,sequence,delta:0})}if(departed&&next){if((current==null?void 0:current.shell)!==next.shell&&next.shell)enqueue(state,{source:next.shell,event:{type:"enter"},handlerId:null});enqueue(state,{source:next.id,event:{type:"enter"},handlerId:null})}if(departed)state.focus=(_a=next==null?void 0:next.id)!=null?_a:null}function initialControl(node){var _a,_b,_c,_d;return{value:(_d=node.attributes.value)!=null?_d:node.kind==="select"?Array.isArray(node.attributes.options)?(_b=(_a=node.attributes.options.map(record).find(option=>option.disabled!==true))==null?void 0:_a.value)!=null?_b:"":"":["slider","progress"].includes(node.kind)?(_c=node.attributes.min)!=null?_c:0:"",checked:node.attributes.checked===true}}function fresh(fragment=routeAddress(program2.entry)){var _a,_b;const route=parseAddress(fragment),state={modelDigest:program2.modelDigest,profileDigest:program2.profileDigest,resetGeneration:0,virtualTime:Number(program2.profile.clockStartMs),sequence:0,requestSequence:0,activationSequence:0,states:{},controls:{},invalid:{},route,address:fragment||routeAddress(program2.entry),history:[{fragment:fragment||routeAddress(program2.entry),sequence:0}],historyIndex:0,nextHistorySequence:1,overlays:[],focus:null,selection:{},expanded:{},viewMode:"fixed",fixtureCursors:{},requests:{},reservations:{},activations:{},queue:[],scheduled:[],trace:[],effects:[],diagnostic:null,suspended:false};for(const[key,binding]of Object.entries(program2.states))state.states[key]=clone(binding.initial);for(const node of program2.nodes){state.controls[node.id]=initialControl(node);if(node.kind==="tabs")state.selection[node.id]=Number((_a=node.attributes.active)!=null?_a:0);state.expanded[node.id]=node.attributes.expanded===true||node.attributes.dismissible===true}const screen=screenOf(state);state.focus=(_b=screen==null?void 0:screen.id)!=null?_b:null;if(screen==null?void 0:screen.shell)enqueue(state,{source:screen.shell,event:{type:"enter"},handlerId:null});if(screen)enqueue(state,{source:screen.id,event:{type:"enter"},handlerId:null});return state}function reset(state){const next=fresh(),previousTrace=state.trace;next.resetGeneration=state.resetGeneration+1;next.sequence=state.sequence;next.trace=previousTrace;next.nextHistorySequence=state.nextHistorySequence+1;next.history[0].sequence=state.nextHistorySequence;next.effects=[{kind:"replace",fragment:next.address,sequence:next.history[0].sequence,delta:0}];Object.assign(state,next);append(state,null,null,null,{type:"reset"},"succeeded")}function runHandler(state,node,handler,event,resumed){var _a;tick();if(!resumed&&!["input","change"].includes(scalar(event.type))&&Object.values(state.requests).some(request=>{var _a2;return request.owner===node.id&&((_a2=state.activations[String(request.activation)])==null?void 0:_a2.handlerId)===handler.id})){if(handler.concurrency==="queue")enqueue(state,{source:node.id,event:clone(event),handlerId:handler.id});else append(state,node,handler,null,event,"busy","busy");return}const before=clone(state),draft=clone(state),segment={route:null,reset:false},records=[];const activation=resumed?clone(resumed):{id:++draft.activationSequence,owner:node.id,handlerId:handler.id,event:clone(event),index:0,statuses:{}};let pending=false;try{if(!resumed&&["input","change"].includes(scalar(event.type)))normalizeControl(draft,node,event);const busy=Object.values(draft.requests).some(request=>{var _a2;return request.owner===node.id&&((_a2=draft.activations[String(request.activation)])==null?void 0:_a2.handlerId)===handler.id});if(!resumed&&busy){if(handler.concurrency==="queue"){enqueue(draft,{source:node.id,event:clone(event),handlerId:handler.id});Object.assign(state,draft);return}Object.assign(state,draft);append(state,node,handler,null,event,"busy","busy",before.states);return}if(!resumed&&!guard(handler.guard,node,draft,event)){Object.assign(state,draft);for(const operation of handler.operations)append(state,node,handler,operation,event,"guard-false",null,before.states);return}for(let index=activation.index;index<handler.operations.length;index++){const operation=handler.operations[index];activation.index=index+1;if(operation.after.some(id=>activation.statuses[id]!=="succeeded")){activation.statuses[operation.id]="skipped-dependency";records.push({operation,result:"skipped-dependency",code:null});continue}const prior=clone(draft),priorSegment=clone(segment);try{const result=applyOperation(draft,node,activation,operation,segment);activation.statuses[operation.id]=result;records.push({operation,result,code:result==="history-boundary"?"history-boundary":null});if(result==="pending"){pending=true;draft.activations[String(activation.id)]=clone(activation);break}if(segment.reset||(result==="specified-unexecuted"||result==="history-boundary")&&operation.onFailure==="stop")break}catch(error){const validation=clone(draft.invalid),focus=draft.focus;Object.assign(draft,prior);Object.assign(segment,priorSegment);if(error.message==="form-invalid"){draft.invalid=validation;draft.focus=focus}activation.statuses[operation.id]="failed";records.push({operation,result:"failed",code:error.message});if(operation.onFailure==="stop")throw error}}if(segment.route)changeRoute(draft,segment.route);view(draft);ensureFocus(draft,before,{source:node.id,type:scalar(event.type)});if(!pending)delete draft.activations[String(activation.id)];Object.assign(state,draft);for(const item of records)append(state,node,handler,item.operation,event,item.result,item.code,before.states);if(segment.reset)reset(state)}catch(error){const code=error.message;if(code==="invalid-edit"){state.controls[node.id]=draft.controls[node.id];state.invalid[node.id]=draft.invalid[node.id];append(state,node,handler,null,event,"failed","invalid-edit");return}if(code==="form-invalid"){state.invalid=clone(draft.invalid);state.focus=draft.focus}if(resumed)delete state.activations[String(activation.id)];if(!records.length)append(state,node,handler,null,event,"failed",code);for(const item of records)append(state,node,handler,item.operation,event,item.result==="succeeded"||item.result==="pending"?"cancelled":item.result,(_a=item.code)!=null?_a:item.result==="succeeded"?null:code);if(!records.some(item=>item.code===code))append(state,node,handler,null,event,"failed",code);if(code.startsWith("limit-"))throw error}}function composite(state,node,event){const type=event.type,key=event.key;if(node.kind==="accordion"&&type==="click")state.expanded[node.id]=!state.expanded[node.id];if(["alert","toast"].includes(node.kind)&&node.attributes.dismissible===true&&type==="click")state.expanded[node.id]=false;const tabs=node.kind==="tab"&&node.parent?nodes.get(node.parent):node.kind==="tabs"?node:void 0;if((tabs==null?void 0:tabs.kind)==="tabs"){const list=tabs.children.map(id=>nodes.get(id)).filter(child=>child.kind==="tab"&&enabled(child,state));const selected=list.findIndex(child=>child.id===node.id),current=selected<0?0:selected;const backwards=tabs.attributes.vertical===true?"ArrowUp":"ArrowLeft",forwards=tabs.attributes.vertical===true?"ArrowDown":"ArrowRight";let next=current;if(type==="keydown"&&key===backwards)next=(current-1+list.length)%list.length;else if(type==="keydown"&&key===forwards)next=(current+1)%list.length;else if(type==="keydown"&&key==="Home")next=0;else if(type==="keydown"&&key==="End")next=list.length-1;if(type==="click"||type==="keydown"&&["Enter"," "].includes(scalar(key)))state.selection[tabs.id]=tabs.children.filter(id=>{var _a;return((_a=nodes.get(id))==null?void 0:_a.kind)==="tab"}).indexOf(node.id);if(list[next])state.focus=list[next].id}if(node.kind==="dropdown"&&(type==="click"||type==="keydown"&&["Enter"," ","ArrowDown","ArrowUp"].includes(scalar(key)))){if(state.overlays.some(overlay=>overlay.id===node.id)&&type==="click")closeOverlay(state,node);else openOverlay(state,node,node)}let menu=node;while(menu&&menu.kind!=="dropdown")menu=menu.parent?nodes.get(menu.parent):void 0;if(menu&&node.kind==="dropdown-item"&&type==="click")closeOverlay(state,menu);if(menu&&state.overlays.some(overlay=>overlay.id===menu.id)&&type==="keydown"){const list=program2.nodes.filter(candidate=>candidate.kind==="dropdown-item"&&descendant(candidate.id,menu.id)&&enabled(candidate,state));let index=list.findIndex(candidate=>candidate.id===node.id);if(key==="ArrowDown")index=(index+1)%list.length;else if(key==="ArrowUp")index=(index-1+list.length)%list.length;else if(key==="Home")index=0;else if(key==="End")index=list.length-1;else index=-1;if(list[index])state.focus=list[index].id}if(type==="keydown"&&key==="Escape"){const top=state.overlays.at(-1),target=top?nodes.get(top.id):void 0;if(target&&target.attributes.dismissible!==false)closeOverlay(state,target)}const tooltip=node.parent?nodes.get(node.parent):void 0;if((tooltip==null?void 0:tooltip.kind)==="tooltip"){if(type==="focus")openOverlay(state,tooltip,node);else if(type==="blur")closeOverlay(state,tooltip)}if(type==="focus")state.focus=node.id;else if(type==="blur"&&state.focus===node.id)state.focus=null}function dispatch(state,node,event,handlerId=null){var _a;tick();const internal=["enter","exit"].includes(scalar(event.type));if(!internal&&!active(node,state)){append(state,node,null,null,event,"failed","inactive-owner");return}if(internal&&!roots(state).includes(node.root))return;const handlers=node.handlers.filter(handler=>handlerId?handler.id===handlerId:handler.event===event.type&&(handler.event!=="keydown"||handler.key===event.key));if(event.type==="submit"){const validated=clone(state);if(!validateForm(validated,node)){state.invalid=validated.invalid;state.focus=validated.focus;append(state,node,null,null,event,"failed","form-invalid");return}state.invalid=validated.invalid;if(state.diagnostic==="form-invalid")state.diagnostic=null}const previous={...state,states:{...state.states}};composite(state,node,event);if(!handlers.length&&["input","change"].includes(scalar(event.type))){const draft=clone(state);try{normalizeControl(draft,node,event);view(draft);Object.assign(state,draft);append(state,node,null,null,event,"succeeded",null,previous.states)}catch(error){const code=error.message;if(code==="invalid-edit"){state.controls[node.id]=draft.controls[node.id];state.invalid[node.id]=draft.invalid[node.id]}append(state,node,null,null,event,"failed",code)}}for(const handler of handlers)runHandler(state,node,handler,event);if(event.type==="keydown"&&node.kind==="dropdown-item"&&["Enter"," "].includes(scalar(event.key)))enqueue(state,{source:node.id,event:{type:"click"},handlerId:null});if(event.type==="click"&&node.kind==="button"&&(node.attributes.buttonType==="submit"||node.attributes.action==="submit")&&!handlers.some(handler=>handler.event==="click")){const form=nodes.get((_a=node.form)!=null?_a:"");if(form)enqueue(state,{source:form.id,event:{type:"submit"},handlerId:null})}if(event.type==="click"&&node.kind==="button"&&node.attributes.buttonType==="reset"){for(const child of program2.nodes.filter(child2=>child2.form===node.form)){const target=child.bindings[scalar(record(child.attributes.bind).state)];if(target)write(state,target,target.initial);state.controls[child.id]=initialControl(child);delete state.invalid[child.id]}}ensureFocus(state,previous,{source:node.id,type:scalar(event.type)})}function drain(state){let blocked=0;while(state.queue.length){if(blocked>=state.queue.length)break;const next=state.queue.shift(),node=nodes.get(next.source);if(!node)continue;if(next.handlerId&&Object.values(state.requests).some(request=>{var _a;return request.owner===node.id&&((_a=state.activations[String(request.activation)])==null?void 0:_a.handlerId)===next.handlerId})){state.queue.push(next);blocked++;continue}blocked=0;dispatch(state,node,next.event,next.handlerId)}}function completion(state,due){var _a,_b,_c;const request=state.requests[due.requestId],node=(_a=nodes.get(due.owner))!=null?_a:null;if(!request||request.generation!==state.resetGeneration){const handler2=(_b=node==null?void 0:node.handlers.find(handler3=>handler3.operations.some(operation=>operation.id===due.operationId)))!=null?_b:null;if(due.priority===1)append(state,node,handler2,(_c=handler2==null?void 0:handler2.operations.find(operation=>operation.id===due.operationId))!=null?_c:null,{type:"fixture-response",requestId:due.requestId},"stale-response","stale-response");return}const activation=state.activations[String(request.activation)],owner=nodes.get(request.owner),handler=owner.handlers.find(handler2=>handler2.id===(activation==null?void 0:activation.handlerId));if(!activation||!handler||!roots(state).includes(owner.root)){cancelRequest(state,request,roots(state));append(state,owner,handler!=null?handler:null,request.operation,{type:"fixture-response"},"stale-response","stale-response");return}const before=clone(state.states),timedOut=due.priority===0,success=!timedOut&&request.outcome==="success";for(const key of[request.resultKey,request.statusKey,request.errorKey])delete state.reservations[key];delete state.requests[request.id];state.scheduled=state.scheduled.filter(item=>item.requestId!==request.id||timedOut&&item.priority===1);const code=success?null:timedOut?"timeout":request.outcome==="exhausted"?"fixture-exhausted":"fixture-error";if(success)write(state,program2.states[request.resultKey],request.value);write(state,program2.states[request.statusKey],success?"succeeded":"failed");write(state,program2.states[request.errorKey],success?{}:{code,value:timedOut||request.outcome==="exhausted"?null:request.value,operationId:request.operation.id});activation.statuses[request.operation.id]=success?"succeeded":"failed";append(state,owner,handler,request.operation,activation.event,success?"succeeded":"failed",code,before);if(!success&&request.operation.onFailure==="stop")delete state.activations[String(activation.id)];else runHandler(state,owner,handler,activation.event,activation);drain(state)}function initial(fragment){microsteps=0;const state=fresh(fragment);try{drain(state)}catch(error){state.queue=[];append(state,null,null,null,{type:"initial"},"failed",error.message)}state.effects=[];return state}function reduce(previous,input,browserSequence=null){const state=clone(previous);state.effects=[];microsteps=0;try{if(!input||typeof input!=="object"||Array.isArray(input))throw Error("input-shape");const keys=input.kind==="reset"?["kind"]:input.kind==="advanceClock"?["kind","deltaMs"]:input.kind==="address"?["kind","fragment"]:input.kind==="event"?["kind","source","event","key","value","checked"]:[];if(!keys.length||Object.keys(input).some(key=>!keys.includes(key)))throw Error("input-shape");if(state.suspended&&input.kind!=="address"&&input.kind!=="reset"){append(state,null,null,null,{type:input.kind},"busy","history-compensation");return state}state.diagnostic=null;if(input.kind==="reset"){reset(state);drain(state);return state}if(input.kind==="advanceClock"){if(!Number.isInteger(input.deltaMs)||input.deltaMs<0||input.deltaMs>6e5||!Number.isSafeInteger(state.virtualTime+input.deltaMs))throw Error("limit-clock");const target=state.virtualTime+input.deltaMs;for(;;){state.scheduled.sort((a,b)=>a.time-b.time||a.priority-b.priority||a.sequence-b.sequence);const due=state.scheduled[0];if(!due||due.time>target)break;state.scheduled.shift();state.virtualTime=due.time;microsteps=0;completion(state,due)}state.virtualTime=target;return state}if(input.kind==="address"){if(typeof input.fragment!=="string")throw Error("input-shape");bounded(input.fragment);const fragment=input.fragment||routeAddress(program2.entry);if(state.suspended&&fragment===state.address&&browserSequence===state.history[state.historyIndex].sequence){state.suspended=false;return state}const index=browserSequence===null?-1:state.history.findIndex(entry=>entry.sequence===browserSequence&&entry.fragment===fragment);try{changeRoute(state,{fragment:input.fragment,mode:"address",index:index<0?null:index,browserSequence});ensureFocus(state,previous);drain(state);return state}catch(error){const restored=clone(previous);restored.effects=[];const code=error.message;append(restored,null,null,null,{type:"address",fragment:input.fragment},"failed",code);if(index>=0){restored.suspended=true;restored.effects.push({kind:"compensate",fragment:restored.address,sequence:restored.history[restored.historyIndex].sequence,delta:restored.historyIndex-index})}else{const sequence=restored.nextHistorySequence++;restored.history=[{fragment:restored.address,sequence}];restored.historyIndex=0;restored.effects.push({kind:"replace",fragment:restored.address,sequence,delta:0})}return restored}}const node=byIdentity.get(canonical(input.source));if(!node)throw Error("unknown-source");if(!["click","input","change","submit","keydown","focus","blur"].includes(input.event))throw Error("event-type");if("value"in input){if(input.value===void 0)throw Error("event-payload");bounded(input.value)}if("checked"in input&&typeof input.checked!=="boolean")throw Error("event-payload");if("key"in input&&typeof input.key!=="string")throw Error("event-payload");if(input.event==="keydown"&&(typeof input.key!=="string"||"value"in input||"checked"in input))throw Error("event-payload");if(!["input","change","keydown"].includes(input.event)&&("value"in input||"checked"in input||"key"in input))throw Error("event-payload");if(["input","change"].includes(input.event)&&!["input","textarea","select","checkbox","radio","switch","slider"].includes(node.kind))throw Error("event-owner");if(["input","change"].includes(input.event)){const booleanControl=["checkbox","radio","switch"].includes(node.kind);if("key"in input)throw Error("event-payload");if(booleanControl&&"value"in input)throw Error("event-payload");if(!booleanControl&&"checked"in input)throw Error("event-payload")}if(input.event==="submit"&&node.kind!=="form")throw Error("event-owner");const event={type:input.event};if(input.value!==void 0){event.value=input.value}if(input.checked!==void 0)event.checked=input.checked;if(input.key!==void 0)event.key=input.key;dispatch(state,node,event);drain(state);view(state);return state}catch(error){const restored=clone(previous);restored.effects=[];append(restored,null,null,null,{type:scalar(record(input).kind)||"invalid"},"failed",error.message);return restored}}function hover(previous,id,open){const state=clone(previous),node=nodes.get(id);state.effects=[];if((node==null?void 0:node.kind)==="tooltip"&&active(node,state)){if(open)openOverlay(state,node,node);else closeOverlay(state,node)}return state}return{initial,reduce,view,parseAddress,routeAddress,hover}}function browserAdapter(engine,program2){const root=document.getElementById("wireweave-app"),storage=root.querySelector("[data-wf-screen-storage]");const nodes=new Map(program2.nodes.map(node=>[node.id,node]));let state=engine.initial(location.hash),projecting=false,processing=false,paused=false,last=performance.now(),timer;let projectedFocus;let projectionTimer;const queue=[];let composition=null;const present=value=>value==null?"":typeof value==="object"?JSON.stringify(value):String(value);function element(id){return document.getElementById(id)}function focusElement(id){const node=nodes.get(id);if((node==null?void 0:node.kind)==="tab")return document.getElementById(id+"-tab");if((node==null?void 0:node.kind)==="dropdown")return document.getElementById(id+"-trigger");return element(id)}function pendingFor(id){for(const request of Object.values(state.requests)){let owner2=nodes.get(request.owner);while(owner2){if(owner2.id===id)return true;owner2=owner2.parent?nodes.get(owner2.parent):void 0}}return false}function metadata(sequence){return{wireweave:{modelDigest:program2.modelDigest,sequence}}}function browserSequence(){const outer=history.state;const value=outer&&typeof outer==="object"?outer.wireweave:void 0;if(!value||typeof value!=="object")return null;const entry=value;return entry.modelDigest===program2.modelDigest&&typeof entry.sequence==="number"&&Number.isInteger(entry.sequence)?entry.sequence:null}function effectCommands(){for(const effect of state.effects){if(effect.kind==="push")history.pushState(metadata(effect.sequence),"",effect.fragment);else if(effect.kind==="replace")history.replaceState(metadata(effect.sequence),"",effect.fragment);else if(effect.kind==="traverse"||effect.kind==="compensate"){if(effect.delta!==0)history.go(effect.delta);else history.replaceState(metadata(effect.sequence),"",effect.fragment)}else location.assign(effect.fragment)}}function render(){var _a,_b,_c,_d,_e,_f,_g,_h;if(projectionTimer!==void 0){clearTimeout(projectionTimer);projectionTimer=void 0}projecting=true;try{const view=engine.view(state),active=program2.screens.find(screen=>{var _a2,_b2;return screen.route.namespace===((_a2=state.route)==null?void 0:_a2.namespace)&&screen.route.id===((_b2=state.route)==null?void 0:_b2.id)});for(const wrapper of root.querySelectorAll("[data-wf-screen]")){const visible=wrapper.contains(element((_a=active==null?void 0:active.id)!=null?_a:""));wrapper.hidden=!visible;wrapper.inert=!visible;if(!visible&&wrapper.parentElement!==storage)storage.append(wrapper)}for(const wrapper of root.querySelectorAll("[data-wf-shell]")){const visible=!!(active==null?void 0:active.shell)&&wrapper.contains(element(active.shell));wrapper.hidden=!visible;wrapper.inert=!visible}if(active){const screen=element(active.id).closest("[data-wf-screen]");if(active.shell){const shell=program2.shells.find(shell2=>shell2.id===active.shell);const slot=element(shell.slot);if(screen.parentElement!==slot)slot.append(screen)}else if(screen.parentElement!==storage)storage.append(screen);screen.hidden=false;screen.inert=false}const routeError=root.querySelector("[data-wf-route-error]");routeError.hidden=state.route!==null;root.querySelector("[data-wf-invalid-address]").textContent=state.address;root.setAttribute("data-wf-route",state.route?state.address:"error");root.setAttribute("data-wf-view",state.viewMode);root.setAttribute("aria-busy",String(state.suspended||Object.keys(state.requests).length>0));for(const node of program2.nodes){const el=element(node.id);if(!el)continue;el.hidden=view.visible[node.id]!==true;const pending=pendingFor(node.id);if(pending||node.attributes.loading===true){el.setAttribute("aria-busy","true");if(pending)el.setAttribute("data-wf-pending","true");else el.removeAttribute("data-wf-pending")}else{el.removeAttribute("aria-busy");el.removeAttribute("data-wf-pending")}const field=el.closest("[data-wf-field]");if(field)field.hidden=el.hidden;if(node.kind==="tab"){const owner2=nodes.get((_b=node.parent)!=null?_b:""),tabs=(_c=owner2==null?void 0:owner2.children.filter(id=>{var _a2;return((_a2=nodes.get(id))==null?void 0:_a2.kind)==="tab"}))!=null?_c:[],selected=tabs[(_e=state.selection[(_d=owner2==null?void 0:owner2.id)!=null?_d:""])!=null?_e:0]===node.id;el.hidden=!view.visible[node.id]||!selected;const button=document.getElementById(node.id+"-tab");if(button){button.setAttribute("aria-selected",String(selected));button.tabIndex=state.focus===node.id?0:tabs.includes((_f=state.focus)!=null?_f:"")?-1:selected?0:-1;button.disabled=!view.enabled[node.id]}}if("disabled"in el)el.disabled=view.enabled[node.id]!==true;const control=view.controls[node.id];if(["input","textarea","select","checkbox","radio","switch","slider"].includes(node.kind)){const input=el;if(["checkbox","radio","switch"].includes(node.kind))input.checked=control.checked;else if(!composition||composition.id!==node.id)input.value=present(control.value)}if(state.invalid[node.id]){el.setAttribute("aria-invalid","true");const message=element(node.id+"-error");if(message){message.textContent=state.invalid[node.id];message.hidden=false;el.setAttribute("aria-describedby",message.id)}}else{el.removeAttribute("aria-invalid");const message=element(node.id+"-error");if(message)message.hidden=true;el.removeAttribute("aria-describedby")}if(node.kind==="form"){const error=el.querySelector("[data-wf-form-error]");if(error){error.textContent=state.invalid[node.id]?"Check the required input values.":"";error.hidden=!state.invalid[node.id]}el.setAttribute("aria-busy",String(pending||node.attributes.loading===true))}if(node.kind==="accordion")el.open=state.expanded[node.id]===true;if(["modal","drawer","popover"].includes(node.kind)){const overlay=state.overlays.find(overlay2=>overlay2.id===node.id),dialog=el;if(overlay){dialog.hidden=false;if(!dialog.open){if(overlay.modal)dialog.showModal();else dialog.show()}dialog.setAttribute("aria-modal",String(overlay.modal))}else if(dialog.open)dialog.close()}if(node.kind==="dropdown"){const open=state.overlays.some(overlay=>overlay.id===node.id);const body=el.querySelector("[data-wf-overlay-body]");if(body)body.hidden=!open;const button=document.getElementById(node.id+"-trigger");button==null?void 0:button.setAttribute("aria-expanded",String(open))}if(node.kind==="tooltip"){const tooltip=el.querySelector("[role=tooltip]");if(tooltip)tooltip.hidden=!state.overlays.some(overlay=>overlay.id===node.id);const trigger=node.children[0]?element(node.children[0]):null;if(trigger&&tooltip)trigger.setAttribute("aria-describedby",tooltip.id)}if(node.attributes.dismissible===true&&["toast","alert"].includes(node.kind))el.hidden=el.hidden||state.expanded[node.id]===false;if(el instanceof HTMLAnchorElement){if(el.getAttribute("href")===state.address)el.setAttribute("aria-current","page");else el.removeAttribute("aria-current")}if(node.attributes.data){const value=view.data[node.id];if(node.kind==="table"&&Array.isArray(value)){const body=el.querySelector("tbody"),fragment=document.createDocumentFragment();for(const row of value){const tr=document.createElement("tr");for(const key of node.attributes.columns){const td=document.createElement("td");td.textContent=present(row[key]);tr.append(td)}fragment.append(tr)}body.replaceChildren(fragment)}else if(node.kind==="list"&&Array.isArray(value)){const fragment=document.createDocumentFragment();for(const item of value){const li=document.createElement("li");li.textContent=present(item);fragment.append(li)}el.replaceChildren(fragment)}else if(node.kind==="text"&&value!==void 0)el.textContent=present(value)}}for(const screen of program2.screens)(_g=element(screen.id))==null?void 0:_g.removeAttribute("role");if(active&&![...root.querySelectorAll("main")].some(main=>!main.closest("[hidden]")))(_h=element(active.id))==null?void 0:_h.setAttribute("role","main");const status=root.querySelector("[data-wf-runtime-status]");status.textContent=state.diagnostic?"The action could not complete: "+state.diagnostic:"";if(state.diagnostic)root.setAttribute("data-wf-runtime-diagnostic",state.diagnostic);else root.removeAttribute("data-wf-runtime-diagnostic");const lastTrace=state.trace.at(-1);if(lastTrace)root.setAttribute("data-wf-operation-result",lastTrace.result);document.getElementById("wf-runtime-trace").textContent=JSON.stringify(state.trace);if(state.focus&&state.focus!==projectedFocus){const focus=focusElement(state.focus);if(focus&&focus!==document.activeElement&&!focus.closest("[hidden],[inert]"))focus.focus()}else if(!state.route&&projectedFocus!==null){const heading=routeError.querySelector("h1");heading==null?void 0:heading.focus()}projectedFocus=state.focus}finally{projecting=false}}function apply(input,sequence=null,deferProjection=false){if(queue.length>=4096)throw Error("limit-queue");queue.push({input,sequence,deferProjection});if(processing)return;processing=true;try{while(queue.length){const item=queue.shift();state=engine.reduce(state,item.input,item.sequence);effectCommands();if(item.deferProjection){if(projectionTimer===void 0)projectionTimer=setTimeout(render,0)}else render()}}finally{processing=false}}function owner(target){var _a,_b;if(!(target instanceof Element))return void 0;const el=target.closest("[data-wf-event-owner], [data-wf-kind]");return nodes.get((_b=(_a=el==null?void 0:el.getAttribute("data-wf-event-owner"))!=null?_a:el==null?void 0:el.id)!=null?_b:"")}function nativeEvent(event){if(projecting)return;const node=owner(event.target);if(!node)return;const kind=event.type;const input={kind:"event",source:node.identity,event:kind};if(kind==="input"||kind==="change"){const control=event.target;if(event.isComposing)return;if((composition==null?void 0:composition.id)===node.id){if(composition.value===control.value){composition=null;return}composition=null}if(["checkbox","radio","switch"].includes(node.kind))input.checked=control.checked;else input.value=control.value}apply(input)}root.addEventListener("input",nativeEvent);root.addEventListener("change",nativeEvent);root.addEventListener("focus",nativeEvent,true);root.addEventListener("blur",nativeEvent,true);root.addEventListener("compositionstart",event=>{const node=owner(event.target);if(node)composition={id:node.id,value:event.target.value}});root.addEventListener("compositionend",event=>{const node=owner(event.target);if(!node)return;const value=event.target.value;composition=null;apply({kind:"event",source:node.identity,event:"input",value});composition={id:node.id,value}});root.addEventListener("submit",event=>{event.preventDefault();if(projecting)return;const node=owner(event.target);if(node)apply({kind:"event",source:node.identity,event:"submit"})});root.addEventListener("click",event=>{if(projecting)return;const target=event.target,tool=target.closest("[data-wf-tooling]");if(tool){event.preventDefault();projectedFocus=void 0;if(tool.getAttribute("data-wf-tooling")==="view"){state={...state,viewMode:state.viewMode==="fixed"?"accessible":"fixed"};render()}else if(tool.getAttribute("data-wf-tooling")==="reset")apply({kind:"reset"});return}const node=owner(event.target);if(!node)return;if(event.button!==0||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)return;const anchor=target.closest("a");if(["input","textarea","select","checkbox","radio","switch","slider"].includes(node.kind)){if(node.handlers.some(handler=>handler.event==="click"))apply({kind:"event",source:node.identity,event:"click"},null,true);return}if(anchor&&node.attributes.href!==void 0&&!node.handlers.some(handler=>handler.event==="click"))return;event.preventDefault();apply({kind:"event",source:node.identity,event:"click"})});root.addEventListener("keydown",event=>{if(projecting)return;const node=owner(event.target);if(!node)return;const explicit=node.handlers.some(handler=>handler.event==="keydown"&&handler.key===event.key),widget=["tab","tabs","dropdown","dropdown-item"].includes(node.kind)&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","Enter"," "].includes(event.key);if(explicit||widget||event.key==="Escape"){event.preventDefault();apply({kind:"event",source:node.identity,event:"keydown",key:event.key})}else if(event.key==="Enter"&&["input","select"].includes(node.kind)&&node.form){event.preventDefault();const form=nodes.get(node.form);apply({kind:"event",source:form.identity,event:"submit"})}});root.addEventListener("cancel",event=>{event.preventDefault();const node=owner(event.target);if(node)apply({kind:"event",source:node.identity,event:"keydown",key:"Escape"})},true);function addressChanged(){const sequence=browserSequence(),fragment=location.hash,canonical=fragment||engine.routeAddress(program2.entry);if(!state.suspended&&canonical===state.address&&sequence===state.history[state.historyIndex].sequence)return;apply({kind:"address",fragment},sequence)}addEventListener("hashchange",addressChanged);addEventListener("popstate",addressChanged);for(const type of["pointerover","pointerout"])root.addEventListener(type,event=>{const target=event.target instanceof Element?event.target.closest("[data-wf-kind=tooltip]"):null;if(!target||target.contains(event.relatedTarget))return;if(type==="pointerout"&&target.contains(document.activeElement))return;state=engine.hover(state,target.id,type==="pointerover");render()});function schedule(){timer=setTimeout(()=>{const now=performance.now();if(!paused&&!state.suspended){let delta=Math.max(0,Math.floor(now-last));while(delta>0){const part=Math.min(delta,6e5);const next=engine.reduce(state,{kind:"advanceClock",deltaMs:part});const changed=next.sequence!==state.sequence;state=next;if(changed){effectCommands();render()}delta-=part}}last=now;schedule()},16)}history.replaceState(metadata(state.history[state.historyIndex].sequence),"",location.href);render();schedule();Object.defineProperty(window,"wireweaveRuntime",{value:Object.freeze({pause(){paused=true;last=performance.now()},resume(){paused=false;last=performance.now()},dispatch(input){apply(input)},advanceClock(deltaMs){paused=true;apply({kind:"advanceClock",deltaMs})},reset(){apply({kind:"reset"})},snapshot(){return JSON.parse(JSON.stringify(state))}}),enumerable:false,writable:false,configurable:false});addEventListener("pagehide",()=>{if(timer!==void 0)clearTimeout(timer)})}const program=JSON.parse(document.getElementById("wf-runtime-data").textContent);browserAdapter(runtimeEngine(program),program)})();';
597
+
595
598
  // src/app/compiler.ts
596
599
  function layoutName(layout) {
597
600
  return layout.nodeId;
@@ -611,13 +614,13 @@ function projectScreen(screen) {
611
614
  uses: target === void 0 ? screen.node.uses : target.targetId
612
615
  };
613
616
  }
614
- function compileApp(document2, options = {}) {
615
- if (!("screens" in document2)) return compileAppV4(document2);
617
+ function compileApp(document, options = {}) {
618
+ if (!("screens" in document)) return compileAppV4(document);
616
619
  const projected = {
617
620
  type: "Document",
618
- children: [...document2.layouts.map(projectLayout), ...document2.screens.map(projectScreen)]
621
+ children: [...document.layouts.map(projectLayout), ...document.screens.map(projectScreen)]
619
622
  };
620
- return chunkNV6UV5ID_cjs.renderSite(projected, { ...options, annotationStyle: "neutral" });
623
+ return chunk7ZRMSFWZ_cjs.renderSite(projected, { ...options, annotationStyle: "neutral" });
621
624
  }
622
625
  function linkAndCompileApp(input, modules, options = {}) {
623
626
  if (modules === void 0) {
@@ -629,20 +632,20 @@ function linkAndCompileApp(input, modules, options = {}) {
629
632
  return { ...linked, html: compileApp(linked.document, options) };
630
633
  }
631
634
  function escape(value) {
632
- return chunkNV6UV5ID_cjs.textValue(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
635
+ return chunk7ZRMSFWZ_cjs.textValue(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
633
636
  }
634
637
  function attribute(name, value) {
635
638
  return value === void 0 || value === false ? "" : ` ${name}="${escape(value === true ? "" : value)}"`;
636
639
  }
637
640
  function jsonBlock(value) {
638
- return chunkNV6UV5ID_cjs.jcs(value).replace(/</g, "\\u003c");
641
+ return chunk7ZRMSFWZ_cjs.jcs(value).replace(/</g, "\\u003c");
639
642
  }
640
643
  function address(route) {
641
644
  return `#wf/${encodeURIComponent(route.namespace)}/${encodeURIComponent(route.id)}${route.variant === void 0 ? "" : `?variant=${encodeURIComponent(route.variant)}`}`;
642
645
  }
643
646
  function hashBase64(value) {
644
647
  var _a, _b;
645
- const hex = chunkIMUVIIJR_cjs.digestV4(value).slice(7), alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
648
+ const hex = chunkEWCLLW6P_cjs.digestV4(value).slice(7), alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
646
649
  const bytes = Array.from(
647
650
  { length: 32 },
648
651
  (_, index) => Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16)
@@ -654,51 +657,60 @@ function hashBase64(value) {
654
657
  }
655
658
  return output;
656
659
  }
660
+ function isPrimaryAction(entry) {
661
+ const { kind, attributes } = entry.node;
662
+ return attributes.primary === true && (kind === "button" || kind === "link" && (entry.route !== void 0 || attributes.href !== void 0));
663
+ }
657
664
  var HtmlArtifact = class {
658
665
  constructor(data, program) {
659
666
  chunkETV4XYOV_cjs.__publicField(this, "data", data);
660
667
  chunkETV4XYOV_cjs.__publicField(this, "program", program);
661
668
  chunkETV4XYOV_cjs.__publicField(this, "unsupported", []);
662
669
  chunkETV4XYOV_cjs.__publicField(this, "rules", []);
670
+ chunkETV4XYOV_cjs.__publicField(this, "assets");
671
+ this.assets = chunk7ZRMSFWZ_cjs.validateAppAssets(data.bundle.profile).assets;
663
672
  }
664
673
  node(entry) {
665
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
674
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
666
675
  const { node, renderedId } = entry;
667
676
  const attrs = node.attributes;
668
- const label = (_b = node.label) != null ? _b : chunkNV6UV5ID_cjs.textValue((_a = attrs.label) != null ? _a : "");
677
+ const label = (_b = node.label) != null ? _b : chunk7ZRMSFWZ_cjs.textValue((_a = attrs.label) != null ? _a : "");
669
678
  const children = () => entry.children.map((child) => this.node(child)).join("");
670
- let common = attribute("id", renderedId) + attribute("class", `wf-node wf-${node.kind} ${renderedId}`) + attribute("data-wf-kind", node.kind) + attribute("data-wf-source", entry.owner.module.id) + attribute("data-wf-identity", chunkNV6UV5ID_cjs.jcs(entry.identity)) + attribute(
679
+ let common = attribute("id", renderedId) + attribute(
680
+ "class",
681
+ `wf-node wf-${node.kind} ${renderedId}${isPrimaryAction(entry) ? " wf-primary-action" : ""}`
682
+ ) + attribute("data-wf-kind", node.kind) + attribute("data-wf-source", entry.owner.module.id) + attribute("data-wf-identity", chunk7ZRMSFWZ_cjs.jcs(entry.identity)) + attribute(
671
683
  "data-wf-requirements",
672
- attrs.requirementRefs === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.requirementRefs)
684
+ attrs.requirementRefs === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.requirementRefs)
673
685
  ) + attribute(
674
686
  "data-wf-obligations",
675
- attrs.obligationRefs === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.obligationRefs)
676
- ) + attribute("data-wf-on", attrs.on === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.on)) + attribute("data-wf-bind", attrs.bind === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.bind)) + attribute("data-wf-data", attrs.data === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.data)) + attribute("data-wf-columns", attrs.columns === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.columns)) + attribute(
687
+ attrs.obligationRefs === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.obligationRefs)
688
+ ) + attribute("data-wf-on", attrs.on === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.on)) + attribute("data-wf-bind", attrs.bind === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.bind)) + attribute("data-wf-data", attrs.data === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.data)) + attribute("data-wf-columns", attrs.columns === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.columns)) + attribute(
677
689
  "data-wf-targets",
678
- entry.effectTargets === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(entry.effectTargets)
690
+ entry.effectTargets === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(entry.effectTargets)
679
691
  ) + attribute(
680
692
  "data-wf-visible-when",
681
- attrs.visibleWhen === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.visibleWhen)
693
+ attrs.visibleWhen === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.visibleWhen)
682
694
  ) + attribute(
683
695
  "data-wf-enabled-when",
684
- attrs.enabledWhen === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.enabledWhen)
685
- ) + attribute("data-wf-when", attrs.when === void 0 ? void 0 : chunkNV6UV5ID_cjs.jcs(attrs.when)) + attribute("data-wf-state-bindings", chunkNV6UV5ID_cjs.jcs(entry.stateBindings)) + attribute("data-wf-navigate", entry.route === void 0 ? void 0 : address(entry.route)) + attribute("aria-label", (_c = attrs["aria-label"]) != null ? _c : attrs.aria) + attribute("aria-busy", attrs.loading === true ? "true" : void 0) + attribute(
696
+ attrs.enabledWhen === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.enabledWhen)
697
+ ) + attribute("data-wf-when", attrs.when === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.when)) + attribute("data-wf-state-bindings", chunk7ZRMSFWZ_cjs.jcs(entry.stateBindings)) + attribute("data-wf-navigate", entry.route === void 0 ? void 0 : address(entry.route)) + attribute("aria-label", (_c = attrs["aria-label"]) != null ? _c : attrs.aria) + attribute("aria-busy", attrs.loading === true ? "true" : void 0) + attribute(
686
698
  "data-wf-disabled",
687
699
  attrs.disabled === true || attrs.loading === true ? true : void 0
688
700
  ) + attribute("data-wf-action", attrs.action);
689
- for (const handler of chunkNV6UV5ID_cjs.asObjects(attrs.on))
690
- for (const operation of chunkNV6UV5ID_cjs.asObjects(handler.operations)) {
701
+ for (const handler of chunk7ZRMSFWZ_cjs.asObjects(attrs.on))
702
+ for (const operation of chunk7ZRMSFWZ_cjs.asObjects(handler.operations)) {
691
703
  if (operation.executionClass === "specified") {
692
704
  this.unsupported.push({
693
705
  renderedId,
694
- handlerId: chunkNV6UV5ID_cjs.textValue(handler.id),
695
- operationId: chunkNV6UV5ID_cjs.textValue(operation.id)
706
+ handlerId: chunk7ZRMSFWZ_cjs.textValue(handler.id),
707
+ operationId: chunk7ZRMSFWZ_cjs.textValue(operation.id)
696
708
  });
697
709
  }
698
710
  }
699
711
  if (entry.slot) return `<div${common} data-wf-slot="${escape(entry.owner.key)}"></div>`;
700
712
  this.layout(entry);
701
- const bound = chunkNV6UV5ID_cjs.object(attrs.bind) ? entry.stateBindings[chunkNV6UV5ID_cjs.textValue(attrs.bind.state)] : void 0;
713
+ const bound = chunk7ZRMSFWZ_cjs.object(attrs.bind) ? entry.stateBindings[chunk7ZRMSFWZ_cjs.textValue(attrs.bind.state)] : void 0;
702
714
  const value = (_d = bound == null ? void 0 : bound.initial) != null ? _d : attrs.value;
703
715
  const disabled = attrs.disabled === true || attrs.loading === true;
704
716
  const labelled = (control) => `<div class="wf-field" data-wf-field="${renderedId}">${label ? `<label for="${renderedId}">${escape(label)}</label>` : ""}${control}<span id="${renderedId}-error" role="alert" hidden></span></div>`;
@@ -715,7 +727,7 @@ var HtmlArtifact = class {
715
727
  );
716
728
  if (node.kind === "select")
717
729
  return labelled(
718
- `<select${common}${scalarAttrs}>${chunkNV6UV5ID_cjs.asObjects(attrs.options).map(
730
+ `<select${common}${scalarAttrs}>${chunk7ZRMSFWZ_cjs.asObjects(attrs.options).map(
719
731
  (option) => `<option${attribute("value", option.value)}${attribute("selected", value === option.value)}${attribute("disabled", option.disabled)}>${escape(option.label)}</option>`
720
732
  ).join("")}</select>`
721
733
  );
@@ -736,12 +748,19 @@ var HtmlArtifact = class {
736
748
  return `<h${rank}${common}>${escape(label)}</h${rank}>`;
737
749
  }
738
750
  if (node.kind === "divider") return `<hr${common}>`;
739
- if (node.kind === "image")
740
- return attrs.src === void 0 ? `<div${common} role="img"${attribute("aria-label", (_g = attrs.alt) != null ? _g : "Image placeholder")}></div>` : `<img${common}${attribute("src", attrs.src)}${attribute("alt", (_h = attrs.alt) != null ? _h : "")}>`;
741
- if (node.kind === "avatar" || node.kind === "icon" || node.kind === "badge" || node.kind === "marker")
742
- return `<span${common}>${escape((_i = node.number) != null ? _i : label || attrs.name || "")}</span>`;
751
+ if (node.kind === "image") {
752
+ const asset = typeof attrs.src === "string" ? this.assets.get(attrs.src) : void 0;
753
+ return asset === void 0 ? `<div${common} role="img"${attribute("aria-label", (_g = attrs.alt) != null ? _g : "Image placeholder")}></div>` : `<img${common}${attribute("src", `data:${asset.mediaType};base64,${asset.base64}`)}${attribute("alt", (_h = attrs.alt) != null ? _h : "")}>`;
754
+ }
755
+ if (node.kind === "avatar") {
756
+ const accessibleLabel = ((_j = (_i = attrs["aria-label"]) != null ? _i : attrs.aria) != null ? _j : label) || attrs.name || "Avatar";
757
+ const asset = typeof attrs.src === "string" ? this.assets.get(attrs.src) : void 0;
758
+ return asset === void 0 ? `<span${common}${attribute("role", "img")}${attrs["aria-label"] === void 0 && attrs.aria === void 0 ? attribute("aria-label", accessibleLabel) : ""}>${escape((_k = node.number) != null ? _k : label || attrs.name || "")}</span>` : `<span${common}${attribute("role", "img")}${attrs["aria-label"] === void 0 && attrs.aria === void 0 ? attribute("aria-label", accessibleLabel) : ""}><img${attribute("src", `data:${asset.mediaType};base64,${asset.base64}`)}${attribute("alt", accessibleLabel)}></span>`;
759
+ }
760
+ if (node.kind === "icon" || node.kind === "badge" || node.kind === "marker")
761
+ return `<span${common}>${escape((_l = node.number) != null ? _l : label || attrs.name || "")}</span>`;
743
762
  if (node.kind === "progress")
744
- return `<progress${common}${attribute("value", attrs.indeterminate === true ? void 0 : value != null ? value : 0)}${attribute("max", (_j = attrs.max) != null ? _j : 100)}>${escape(label)}</progress>`;
763
+ return `<progress${common}${attribute("value", attrs.indeterminate === true ? void 0 : value != null ? value : 0)}${attribute("max", (_m = attrs.max) != null ? _m : 100)}>${escape(label)}</progress>`;
745
764
  if (node.kind === "alert" || node.kind === "toast" || node.kind === "spinner")
746
765
  return `<p${common}${attribute("role", node.kind === "alert" ? "alert" : "status")}>${escape(label)}${attrs.dismissible === true ? `<button type="button" data-wf-event-owner="${renderedId}" aria-label="Dismiss ${escape(label)}">Dismiss</button>` : ""}</p>`;
747
766
  if (node.kind === "accordion")
@@ -754,12 +773,12 @@ var HtmlArtifact = class {
754
773
  return `<div${common}>${children()}<span id="${renderedId}-tooltip" role="tooltip" hidden>${escape(label)}</span></div>`;
755
774
  if (node.kind === "table") {
756
775
  const columns = Array.isArray(attrs.columns) ? attrs.columns : [];
757
- let rows = (_k = node.items) != null ? _k : [];
758
- if (chunkNV6UV5ID_cjs.object(attrs.data)) {
759
- const initial = (_l = entry.stateBindings[chunkNV6UV5ID_cjs.textValue(attrs.data.state)]) == null ? void 0 : _l.initial;
776
+ let rows = (_n = node.items) != null ? _n : [];
777
+ if (chunk7ZRMSFWZ_cjs.object(attrs.data)) {
778
+ const initial = (_o = entry.stateBindings[chunk7ZRMSFWZ_cjs.textValue(attrs.data.state)]) == null ? void 0 : _o.initial;
760
779
  if (Array.isArray(initial))
761
780
  rows = initial.map(
762
- (record) => columns.map((column) => chunkNV6UV5ID_cjs.object(record) ? record[chunkNV6UV5ID_cjs.textValue(column)] : null)
781
+ (record) => columns.map((column) => chunk7ZRMSFWZ_cjs.object(record) ? record[chunk7ZRMSFWZ_cjs.textValue(column)] : null)
763
782
  );
764
783
  }
765
784
  return `<table${common}><thead><tr>${columns.map((column) => `<th scope="col">${escape(column)}</th>`).join("")}</tr></thead><tbody>${rows.map((row) => `<tr>${(Array.isArray(row) ? row : []).map((cell) => `<td>${escape(cell != null ? cell : "")}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
@@ -777,7 +796,7 @@ var HtmlArtifact = class {
777
796
  }
778
797
  if (node.kind === "tab")
779
798
  return `<section${common} role="tabpanel" aria-labelledby="${renderedId}-tab" tabindex="0">${children()}</section>`;
780
- const tag = (_m = {
799
+ const tag = (_p = {
781
800
  header: "header",
782
801
  main: "main",
783
802
  footer: "footer",
@@ -787,7 +806,7 @@ var HtmlArtifact = class {
787
806
  section: "section",
788
807
  page: "section",
789
808
  "annotation-item": "section"
790
- }[node.kind]) != null ? _m : "div";
809
+ }[node.kind]) != null ? _p : "div";
791
810
  if (node.kind === "page") common += ' tabindex="-1"';
792
811
  return `<${tag}${common}>${label ? `<span class="wf-label">${escape(label)}</span>` : ""}${children()}</${tag}>`;
793
812
  }
@@ -797,9 +816,9 @@ var HtmlArtifact = class {
797
816
  const length = (value, axis, spacing = false) => {
798
817
  if (typeof value === "number")
799
818
  return `${spacing && [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20].includes(value) ? value * 4 : value}px`;
800
- if (chunkNV6UV5ID_cjs.object(value)) {
819
+ if (chunk7ZRMSFWZ_cjs.object(value)) {
801
820
  const amount = Number(value.value);
802
- return value.unit === "vh" ? `${amount * Number(profile.height) / 100}px` : value.unit === "vw" ? `${amount * Number(profile.width) / 100}px` : value.unit === "rem" ? `${amount * 16}px` : `${amount}${chunkNV6UV5ID_cjs.textValue(value.unit)}`;
821
+ return value.unit === "vh" ? `${amount * Number(profile.height) / 100}px` : value.unit === "vw" ? `${amount * Number(profile.width) / 100}px` : value.unit === "rem" ? `${amount * 16}px` : `${amount}${chunk7ZRMSFWZ_cjs.textValue(value.unit)}`;
803
822
  }
804
823
  return value === "full" ? "100%" : value === "screen" ? `${Number(profile[axis])}px` : value === "fit" ? "fit-content" : "auto";
805
824
  };
@@ -836,10 +855,10 @@ var HtmlArtifact = class {
836
855
  if (["row", "col", "stack"].includes(kind)) {
837
856
  styles.push(
838
857
  "display:flex",
839
- `flex-direction:${chunkNV6UV5ID_cjs.textValue((_a = a.direction) != null ? _a : kind === "row" ? "row" : "column")}`,
858
+ `flex-direction:${chunk7ZRMSFWZ_cjs.textValue((_a = a.direction) != null ? _a : kind === "row" ? "row" : "column")}`,
840
859
  `flex-wrap:${a.wrap === true ? "wrap" : "nowrap"}`,
841
- `justify-content:${(_c = { start: "flex-start", end: "flex-end", between: "space-between", around: "space-around", evenly: "space-evenly" }[chunkNV6UV5ID_cjs.textValue(a.justify)]) != null ? _c : chunkNV6UV5ID_cjs.textValue((_b = a.justify) != null ? _b : "flex-start")}`,
842
- `align-items:${(_e = { start: "flex-start", end: "flex-end" }[chunkNV6UV5ID_cjs.textValue(a.align)]) != null ? _e : chunkNV6UV5ID_cjs.textValue((_d = a.align) != null ? _d : "stretch")}`
860
+ `justify-content:${(_c = { start: "flex-start", end: "flex-end", between: "space-between", around: "space-around", evenly: "space-evenly" }[chunk7ZRMSFWZ_cjs.textValue(a.justify)]) != null ? _c : chunk7ZRMSFWZ_cjs.textValue((_b = a.justify) != null ? _b : "flex-start")}`,
861
+ `align-items:${(_e = { start: "flex-start", end: "flex-end" }[chunk7ZRMSFWZ_cjs.textValue(a.align)]) != null ? _e : chunk7ZRMSFWZ_cjs.textValue((_d = a.align) != null ? _d : "stretch")}`
843
862
  );
844
863
  }
845
864
  if (a.flex !== void 0)
@@ -857,7 +876,7 @@ var HtmlArtifact = class {
857
876
  if (a.order !== void 0) styles.push(`order:${Number(a.order)}`);
858
877
  if (a.scroll === true) styles.push("overflow:auto");
859
878
  if (kind !== "page" && (a.x !== void 0 || a.y !== void 0 || a.anchor !== void 0)) {
860
- const anchor = chunkNV6UV5ID_cjs.textValue((_i = a.anchor) != null ? _i : "top-left"), vertical = anchor === "center" ? "center" : anchor.split("-")[0], horizontal = anchor === "center" ? "center" : anchor.split("-")[1];
879
+ const anchor = chunk7ZRMSFWZ_cjs.textValue((_i = a.anchor) != null ? _i : "top-left"), vertical = anchor === "center" ? "center" : anchor.split("-")[0], horizontal = anchor === "center" ? "center" : anchor.split("-")[1];
861
880
  styles.push(
862
881
  "position:absolute",
863
882
  `left:calc(${horizontal === "center" ? "50%" : horizontal === "right" ? "100%" : "0%"} + ${Number((_j = a.x) != null ? _j : 0)}px)`,
@@ -867,19 +886,21 @@ var HtmlArtifact = class {
867
886
  }
868
887
  if (a.border === true || a.outline === true || a.bordered === true)
869
888
  styles.push("border:1px solid #71717a");
870
- if (a.ghost === true) styles.push("background:transparent", "border-color:transparent");
889
+ const primaryAction = isPrimaryAction(entry);
890
+ if (a.ghost === true && !primaryAction)
891
+ styles.push("background:transparent", "border-color:transparent");
871
892
  if (a.rounded === true || a.pill === true)
872
893
  styles.push(`border-radius:${a.pill === true ? "999px" : "4px"}`);
873
894
  if (a.muted === true) styles.push("color:#52525b");
874
- if (a.bg !== void 0 || a.primary === true || a.secondary === true)
895
+ if (!primaryAction && (a.bg !== void 0 || a.primary === true || a.secondary === true))
875
896
  styles.push("background:#f4f4f5");
876
897
  if (a.shadow !== void 0 && a.shadow !== "none")
877
898
  styles.push(
878
- `box-shadow:0 ${{ sm: 1, md: 2, lg: 4, xl: 8 }[chunkNV6UV5ID_cjs.textValue(a.shadow)]}px ${{ sm: 1, md: 2, lg: 4, xl: 8 }[chunkNV6UV5ID_cjs.textValue(a.shadow)]}px #71717a`
899
+ `box-shadow:0 ${{ sm: 1, md: 2, lg: 4, xl: 8 }[chunk7ZRMSFWZ_cjs.textValue(a.shadow)]}px ${{ sm: 1, md: 2, lg: 4, xl: 8 }[chunk7ZRMSFWZ_cjs.textValue(a.shadow)]}px #71717a`
879
900
  );
880
901
  if (a.bold === true || a.weight !== void 0)
881
902
  styles.push(
882
- `font-weight:${a.bold === true ? 700 : { normal: 400, medium: 500, semibold: 600, bold: 700 }[chunkNV6UV5ID_cjs.textValue(a.weight)]}`
903
+ `font-weight:${a.bold === true ? 700 : { normal: 400, medium: 500, semibold: 600, bold: 700 }[chunk7ZRMSFWZ_cjs.textValue(a.weight)]}`
883
904
  );
884
905
  if (typeof a.size === "string") {
885
906
  const font = { xs: 12, sm: 14, base: 16, md: 16, lg: 18, xl: 20, "2xl": 24, "3xl": 30 }[a.size];
@@ -892,7 +913,7 @@ var HtmlArtifact = class {
892
913
  );
893
914
  } else if (typeof a.size === "number") styles.push(`width:${a.size}px`, `height:${a.size}px`);
894
915
  if (["text", "title", "link"].includes(kind) && a.align !== void 0)
895
- styles.push(`text-align:${chunkNV6UV5ID_cjs.textValue(a.align)}`);
916
+ styles.push(`text-align:${chunk7ZRMSFWZ_cjs.textValue(a.align)}`);
896
917
  if (styles.length) this.rules.push(`#wireweave-app .${entry.renderedId}{${styles.join(";")}}`);
897
918
  }
898
919
  html() {
@@ -909,7 +930,11 @@ var HtmlArtifact = class {
909
930
  return `<section data-wf-requirement="${escape(entry.id)}"><h3>${escape(entry.title)}</h3><p>${escape((_b = (_a = entry.behavior) != null ? _a : entry.trigger) != null ? _b : "")}</p></section>`;
910
931
  }
911
932
  ).join("");
912
- const css = `#wireweave-app{font:16px/1.5 system-ui,sans-serif;color:#18181b;background:white}#wireweave-app [hidden]{display:none!important}#wireweave-app *{box-sizing:border-box}#wireweave-app :focus-visible{outline:2px solid #18181b;outline-offset:2px}#wireweave-app button,#wireweave-app input,#wireweave-app select{min-height:24px;font:inherit}#wireweave-app .wf-row{display:flex;gap:0}#wireweave-app .wf-col{flex:1}#wireweave-app .wf-stack,#wireweave-app .wf-field{display:flex;flex-direction:column;gap:8px}#wireweave-app .wf-page,#wireweave-app [data-wf-shell]{width:${chunkNV6UV5ID_cjs.textValue(bundle.profile.width)}px;height:${chunkNV6UV5ID_cjs.textValue(bundle.profile.height)}px;overflow:auto}#wireweave-app .wf-card,#wireweave-app th,#wireweave-app td{border:1px solid #71717a;padding:8px}#wireweave-app .wf-relative{position:relative}#wireweave-app [data-wf-slot]{display:contents}${this.rules.join("")}#wireweave-app[data-wf-view=accessible] .wf-node,#wireweave-app[data-wf-view=accessible] [data-wf-shell]{position:static!important;transform:none!important;width:auto!important;height:auto!important;min-width:0!important;max-width:100%!important;min-height:0!important;overflow-wrap:anywhere;order:0!important}#wireweave-app[data-wf-view=accessible] .wf-row{flex-direction:column!important;flex-wrap:wrap!important}#wireweave-app[data-wf-view=accessible] .wf-col{flex-basis:auto!important}#wireweave-app .wf-field{min-width:0}#wireweave-app .wf-field input,#wireweave-app .wf-field textarea,#wireweave-app .wf-field select{max-width:100%}#wireweave-app [data-wf-field][hidden]{display:none!important}#wireweave-app [role=tablist]{display:flex;flex-wrap:wrap}#wireweave-app [role=tooltip]{background:#f4f4f5;border:1px solid #71717a}#wireweave-app dialog{color:#18181b;background:white;max-width:100%;max-height:100%;overflow:auto}`;
933
+ const font = typeof bundle.profile.fontAssetId === "string" ? this.assets.get(bundle.profile.fontAssetId) : void 0;
934
+ const fontFace = font === void 0 ? "" : `@font-face{font-family:WireweaveProfile;src:url(data:${font.mediaType};base64,${font.base64}) format("woff2");font-display:swap}`;
935
+ const fontFamily = font === void 0 ? "system-ui,sans-serif" : "WireweaveProfile,system-ui,sans-serif";
936
+ const primaryActionCss = "#wireweave-app .wf-primary-action{display:inline-flex;align-items:center;width:fit-content;max-width:100%;min-height:40px;padding:8px 14px;border:1px solid #18181b;border-radius:4px;background:#18181b;color:white;font-weight:600;text-decoration:none}#wireweave-app .wf-primary-action:not(:disabled,[aria-disabled=true]):hover{background:#3f3f46;cursor:pointer}#wireweave-app .wf-primary-action:is(:disabled,[aria-disabled=true]){background:#f4f4f5;border-color:#71717a;color:#52525b}";
937
+ const css = `${fontFace}body:has(> #wireweave-app){margin:0}#wireweave-app{font:16px/1.5 ${fontFamily};color:#18181b;background:white}#wireweave-app [hidden]{display:none!important}#wireweave-app *{box-sizing:border-box}#wireweave-app :focus-visible{outline:2px solid #18181b;outline-offset:2px}#wireweave-app button,#wireweave-app input,#wireweave-app select{min-height:24px;font:inherit}#wireweave-app .wf-row{display:flex;gap:0}${primaryActionCss}#wireweave-app .wf-col{flex:1}#wireweave-app .wf-field{display:flex;flex-direction:column;gap:8px}#wireweave-app .wf-page,#wireweave-app [data-wf-shell]{width:${chunk7ZRMSFWZ_cjs.textValue(bundle.profile.width)}px;height:${chunk7ZRMSFWZ_cjs.textValue(bundle.profile.height)}px;overflow:auto}#wireweave-app .wf-card,#wireweave-app th,#wireweave-app td{border:1px solid #71717a;padding:8px}#wireweave-app .wf-relative{position:relative}#wireweave-app [data-wf-slot]{display:contents}${this.rules.join("")}#wireweave-app[data-wf-view=accessible] .wf-node,#wireweave-app[data-wf-view=accessible] [data-wf-shell]{position:static!important;transform:none!important;width:auto!important;height:auto!important;min-width:0!important;max-width:100%!important;min-height:0!important;overflow-wrap:anywhere;order:0!important}#wireweave-app[data-wf-view=accessible] .wf-row{flex-direction:column!important;flex-wrap:wrap!important}#wireweave-app[data-wf-view=accessible] .wf-col{flex-basis:auto!important}#wireweave-app .wf-field{min-width:0}#wireweave-app .wf-field input,#wireweave-app .wf-field textarea,#wireweave-app .wf-field select{max-width:100%}#wireweave-app [data-wf-field][hidden]{display:none!important}#wireweave-app [role=tablist]{display:flex;flex-wrap:wrap}#wireweave-app [role=tooltip]{background:#f4f4f5;border:1px solid #71717a}#wireweave-app dialog{color:#18181b;background:white;max-width:100%;max-height:100%;overflow:auto}`;
913
938
  const runtimeData = this.program;
914
939
  const csp = `default-src 'none'; script-src 'sha256-${hashBase64(NATIVE_RUNTIME)}'; style-src 'sha256-${hashBase64(css)}'; img-src data:; font-src data:; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-src 'none'`;
915
940
  return `<!DOCTYPE html>
@@ -2293,6 +2318,7 @@ function runtimeEngine(program) {
2293
2318
  append(state, null, null, null, { type: input.kind }, "busy", "history-compensation");
2294
2319
  return state;
2295
2320
  }
2321
+ state.diagnostic = null;
2296
2322
  if (input.kind === "reset") {
2297
2323
  reset(state);
2298
2324
  drain(state);
@@ -2376,6 +2402,12 @@ function runtimeEngine(program) {
2376
2402
  if (!node) throw Error("unknown-source");
2377
2403
  if (!["click", "input", "change", "submit", "keydown", "focus", "blur"].includes(input.event))
2378
2404
  throw Error("event-type");
2405
+ if ("value" in input) {
2406
+ if (input.value === void 0) throw Error("event-payload");
2407
+ bounded(input.value);
2408
+ }
2409
+ if ("checked" in input && typeof input.checked !== "boolean") throw Error("event-payload");
2410
+ if ("key" in input && typeof input.key !== "string") throw Error("event-payload");
2379
2411
  if (input.event === "keydown" && (typeof input.key !== "string" || "value" in input || "checked" in input))
2380
2412
  throw Error("event-payload");
2381
2413
  if (!["input", "change", "keydown"].includes(input.event) && ("value" in input || "checked" in input || "key" in input))
@@ -2384,10 +2416,15 @@ function runtimeEngine(program) {
2384
2416
  node.kind
2385
2417
  ))
2386
2418
  throw Error("event-owner");
2419
+ if (["input", "change"].includes(input.event)) {
2420
+ const booleanControl = ["checkbox", "radio", "switch"].includes(node.kind);
2421
+ if ("key" in input) throw Error("event-payload");
2422
+ if (booleanControl && "value" in input) throw Error("event-payload");
2423
+ if (!booleanControl && "checked" in input) throw Error("event-payload");
2424
+ }
2387
2425
  if (input.event === "submit" && node.kind !== "form") throw Error("event-owner");
2388
2426
  const event = { type: input.event };
2389
2427
  if (input.value !== void 0) {
2390
- bounded(input.value);
2391
2428
  event.value = input.value;
2392
2429
  }
2393
2430
  if (input.checked !== void 0) event.checked = input.checked;
@@ -2452,15 +2489,15 @@ var snapshotPrograms = /* @__PURE__ */ new WeakMap();
2452
2489
  function runtimeProgram(linked) {
2453
2490
  const cached = programCache.get(linked);
2454
2491
  if (cached) return cached;
2455
- const data = chunkNV6UV5ID_cjs.getLinkedAppData(linked);
2492
+ const data = chunk7ZRMSFWZ_cjs.getLinkedAppData(linked);
2456
2493
  if (!data) throw new TypeError("Untrusted LinkedApp");
2457
2494
  const states = {};
2458
2495
  for (const state of data.bundle.states) {
2459
- const key = `app:${chunkNV6UV5ID_cjs.textValue(state.id)}`;
2496
+ const key = `app:${chunk7ZRMSFWZ_cjs.textValue(state.id)}`;
2460
2497
  states[key] = {
2461
2498
  key,
2462
2499
  initial: state.initial,
2463
- type: chunkNV6UV5ID_cjs.textValue(state.type),
2500
+ type: chunk7ZRMSFWZ_cjs.textValue(state.type),
2464
2501
  lifetime: "session",
2465
2502
  sensitive: state.sensitive === true,
2466
2503
  root: "app"
@@ -2472,14 +2509,14 @@ function runtimeProgram(linked) {
2472
2509
  let form = entry.parent;
2473
2510
  while (form && form.node.kind !== "form") form = form.parent;
2474
2511
  const root = entry.identity.instanceRoot;
2475
- const handlers = chunkNV6UV5ID_cjs.asObjects(entry.node.attributes.on).map((handler) => ({
2476
- id: chunkNV6UV5ID_cjs.textValue(handler.id),
2477
- event: chunkNV6UV5ID_cjs.textValue(handler.event),
2478
- ...handler.key === void 0 ? {} : { key: chunkNV6UV5ID_cjs.textValue(handler.key) },
2512
+ const handlers = chunk7ZRMSFWZ_cjs.asObjects(entry.node.attributes.on).map((handler) => ({
2513
+ id: chunk7ZRMSFWZ_cjs.textValue(handler.id),
2514
+ event: chunk7ZRMSFWZ_cjs.textValue(handler.event),
2515
+ ...handler.key === void 0 ? {} : { key: chunk7ZRMSFWZ_cjs.textValue(handler.key) },
2479
2516
  ...handler.guard === void 0 ? {} : { guard: handler.guard },
2480
2517
  concurrency: handler.concurrency === "queue" ? "queue" : "drop",
2481
- operations: chunkNV6UV5ID_cjs.asObjects(handler.operations).map((operation) => ({
2482
- id: chunkNV6UV5ID_cjs.textValue(operation.id),
2518
+ operations: chunk7ZRMSFWZ_cjs.asObjects(handler.operations).map((operation) => ({
2519
+ id: chunk7ZRMSFWZ_cjs.textValue(operation.id),
2483
2520
  executionClass: operation.executionClass,
2484
2521
  effect: operation.effect,
2485
2522
  after: operation.after,
@@ -2514,11 +2551,16 @@ function runtimeProgram(linked) {
2514
2551
  form: (_e = (_d = entry.formTarget) != null ? _d : form == null ? void 0 : form.renderedId) != null ? _e : null
2515
2552
  };
2516
2553
  });
2517
- const program = chunkNV6UV5ID_cjs.freeze({
2554
+ const runtimeProfile = Object.fromEntries(
2555
+ Object.entries(data.bundle.profile).filter(
2556
+ ([key]) => key !== "assets" && key !== "fontAssetId"
2557
+ )
2558
+ );
2559
+ const program = chunk7ZRMSFWZ_cjs.freeze({
2518
2560
  appId: data.bundle.id,
2519
2561
  modelDigest: linked.digest,
2520
- profileDigest: chunkIMUVIIJR_cjs.digestV4(chunkNV6UV5ID_cjs.jcs(data.bundle.profile)),
2521
- profile: data.bundle.profile,
2562
+ profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
2563
+ profile: runtimeProfile,
2522
2564
  entry: data.bundle.entry,
2523
2565
  nodes: runtimeNodes,
2524
2566
  states,
@@ -2537,11 +2579,11 @@ function runtimeProgram(linked) {
2537
2579
  slot: shell.slotId
2538
2580
  })),
2539
2581
  fixtures: data.bundle.fixtures.map((fixture) => ({
2540
- id: chunkNV6UV5ID_cjs.textValue(fixture.id),
2541
- exhaustion: chunkNV6UV5ID_cjs.textValue(fixture.exhaustion),
2542
- steps: chunkNV6UV5ID_cjs.asObjects(fixture.steps).map((step) => ({
2582
+ id: chunk7ZRMSFWZ_cjs.textValue(fixture.id),
2583
+ exhaustion: chunk7ZRMSFWZ_cjs.textValue(fixture.exhaustion),
2584
+ steps: chunk7ZRMSFWZ_cjs.asObjects(fixture.steps).map((step) => ({
2543
2585
  delayMs: Number(step.delayMs),
2544
- outcome: chunkNV6UV5ID_cjs.textValue(step.outcome),
2586
+ outcome: chunk7ZRMSFWZ_cjs.textValue(step.outcome),
2545
2587
  value: step.value
2546
2588
  }))
2547
2589
  })),
@@ -2551,7 +2593,7 @@ function runtimeProgram(linked) {
2551
2593
  return program;
2552
2594
  }
2553
2595
  function ownSnapshot(snapshot, program) {
2554
- chunkNV6UV5ID_cjs.freeze(snapshot);
2596
+ chunk7ZRMSFWZ_cjs.freeze(snapshot);
2555
2597
  snapshotPrograms.set(snapshot, program);
2556
2598
  return snapshot;
2557
2599
  }
@@ -2570,423 +2612,16 @@ function advanceClock(snapshot, deltaMs) {
2570
2612
  function resetRuntime(snapshot) {
2571
2613
  return reduceEvent(snapshot, { kind: "reset" });
2572
2614
  }
2573
- function browserAdapter(engine, program) {
2574
- const root = document.getElementById("wireweave-app"), storage = root.querySelector("[data-wf-screen-storage]");
2575
- const nodes = new Map(program.nodes.map((node) => [node.id, node]));
2576
- let state = engine.initial(location.hash), projecting = false, processing = false, paused = false, last = performance.now(), timer;
2577
- let projectedFocus;
2578
- let projectionTimer;
2579
- const queue = [];
2580
- let composition = null;
2581
- const present = (value) => value == null ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
2582
- function element(id) {
2583
- return document.getElementById(id);
2584
- }
2585
- function focusElement(id) {
2586
- const node = nodes.get(id);
2587
- if ((node == null ? void 0 : node.kind) === "tab") return document.getElementById(id + "-tab");
2588
- if ((node == null ? void 0 : node.kind) === "dropdown") return document.getElementById(id + "-trigger");
2589
- return element(id);
2590
- }
2591
- function metadata(sequence) {
2592
- return { wireweave: { modelDigest: program.modelDigest, sequence } };
2593
- }
2594
- function browserSequence() {
2595
- const outer = history.state;
2596
- const value = outer && typeof outer === "object" ? outer.wireweave : void 0;
2597
- if (!value || typeof value !== "object") return null;
2598
- const entry = value;
2599
- return entry.modelDigest === program.modelDigest && typeof entry.sequence === "number" && Number.isInteger(entry.sequence) ? entry.sequence : null;
2600
- }
2601
- function effectCommands() {
2602
- for (const effect of state.effects) {
2603
- if (effect.kind === "push") history.pushState(metadata(effect.sequence), "", effect.fragment);
2604
- else if (effect.kind === "replace")
2605
- history.replaceState(metadata(effect.sequence), "", effect.fragment);
2606
- else if (effect.kind === "traverse" || effect.kind === "compensate") {
2607
- if (effect.delta !== 0) history.go(effect.delta);
2608
- else history.replaceState(metadata(effect.sequence), "", effect.fragment);
2609
- } else location.assign(effect.fragment);
2610
- }
2611
- }
2612
- function render() {
2613
- var _a, _b, _c, _d, _e, _f, _g, _h;
2614
- if (projectionTimer !== void 0) {
2615
- clearTimeout(projectionTimer);
2616
- projectionTimer = void 0;
2617
- }
2618
- projecting = true;
2619
- try {
2620
- const view = engine.view(state), active = program.screens.find(
2621
- (screen) => {
2622
- var _a2, _b2;
2623
- return screen.route.namespace === ((_a2 = state.route) == null ? void 0 : _a2.namespace) && screen.route.id === ((_b2 = state.route) == null ? void 0 : _b2.id);
2624
- }
2625
- );
2626
- for (const wrapper of root.querySelectorAll("[data-wf-screen]")) {
2627
- const visible = wrapper.contains(element((_a = active == null ? void 0 : active.id) != null ? _a : ""));
2628
- wrapper.hidden = !visible;
2629
- wrapper.inert = !visible;
2630
- if (!visible && wrapper.parentElement !== storage) storage.append(wrapper);
2631
- }
2632
- for (const wrapper of root.querySelectorAll("[data-wf-shell]")) {
2633
- const visible = !!(active == null ? void 0 : active.shell) && wrapper.contains(element(active.shell));
2634
- wrapper.hidden = !visible;
2635
- wrapper.inert = !visible;
2636
- }
2637
- if (active) {
2638
- const screen = element(active.id).closest("[data-wf-screen]");
2639
- if (active.shell) {
2640
- const shell = program.shells.find((shell2) => shell2.id === active.shell);
2641
- const slot = element(shell.slot);
2642
- if (screen.parentElement !== slot) slot.append(screen);
2643
- } else if (screen.parentElement !== storage) storage.append(screen);
2644
- screen.hidden = false;
2645
- screen.inert = false;
2646
- }
2647
- const routeError = root.querySelector("[data-wf-route-error]");
2648
- routeError.hidden = state.route !== null;
2649
- root.querySelector("[data-wf-invalid-address]").textContent = state.address;
2650
- root.setAttribute("data-wf-route", state.route ? state.address : "error");
2651
- root.setAttribute("data-wf-view", state.viewMode);
2652
- root.setAttribute("aria-busy", String(state.suspended));
2653
- for (const node of program.nodes) {
2654
- const el = element(node.id);
2655
- if (!el) continue;
2656
- el.hidden = view.visible[node.id] !== true;
2657
- const field = el.closest("[data-wf-field]");
2658
- if (field) field.hidden = el.hidden;
2659
- if (node.kind === "tab") {
2660
- const owner2 = nodes.get((_b = node.parent) != null ? _b : ""), tabs = (_c = owner2 == null ? void 0 : owner2.children.filter((id) => {
2661
- var _a2;
2662
- return ((_a2 = nodes.get(id)) == null ? void 0 : _a2.kind) === "tab";
2663
- })) != null ? _c : [], selected = tabs[(_e = state.selection[(_d = owner2 == null ? void 0 : owner2.id) != null ? _d : ""]) != null ? _e : 0] === node.id;
2664
- el.hidden = !view.visible[node.id] || !selected;
2665
- const button = document.getElementById(node.id + "-tab");
2666
- if (button) {
2667
- button.setAttribute("aria-selected", String(selected));
2668
- button.tabIndex = state.focus === node.id ? 0 : tabs.includes((_f = state.focus) != null ? _f : "") ? -1 : selected ? 0 : -1;
2669
- button.disabled = !view.enabled[node.id];
2670
- }
2671
- }
2672
- if ("disabled" in el) el.disabled = view.enabled[node.id] !== true;
2673
- const control = view.controls[node.id];
2674
- if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(
2675
- node.kind
2676
- )) {
2677
- const input = el;
2678
- if (["checkbox", "radio", "switch"].includes(node.kind)) input.checked = control.checked;
2679
- else if (!composition || composition.id !== node.id) input.value = present(control.value);
2680
- }
2681
- if (state.invalid[node.id]) {
2682
- el.setAttribute("aria-invalid", "true");
2683
- const message = element(node.id + "-error");
2684
- if (message) {
2685
- message.textContent = state.invalid[node.id];
2686
- message.hidden = false;
2687
- el.setAttribute("aria-describedby", message.id);
2688
- }
2689
- } else {
2690
- el.removeAttribute("aria-invalid");
2691
- const message = element(node.id + "-error");
2692
- if (message) message.hidden = true;
2693
- el.removeAttribute("aria-describedby");
2694
- }
2695
- if (node.kind === "form") {
2696
- const error = el.querySelector("[data-wf-form-error]");
2697
- if (error) {
2698
- error.textContent = state.invalid[node.id] ? "Check the required input values." : "";
2699
- error.hidden = !state.invalid[node.id];
2700
- }
2701
- el.setAttribute(
2702
- "aria-busy",
2703
- String(Object.values(state.requests).some((request) => request.owner === node.id))
2704
- );
2705
- }
2706
- if (node.kind === "accordion")
2707
- el.open = state.expanded[node.id] === true;
2708
- if (["modal", "drawer", "popover"].includes(node.kind)) {
2709
- const overlay = state.overlays.find((overlay2) => overlay2.id === node.id), dialog = el;
2710
- if (overlay) {
2711
- dialog.hidden = false;
2712
- if (!dialog.open) {
2713
- if (overlay.modal) dialog.showModal();
2714
- else dialog.show();
2715
- }
2716
- dialog.setAttribute("aria-modal", String(overlay.modal));
2717
- } else if (dialog.open) dialog.close();
2718
- }
2719
- if (node.kind === "dropdown") {
2720
- const open = state.overlays.some((overlay) => overlay.id === node.id);
2721
- const body = el.querySelector("[data-wf-overlay-body]");
2722
- if (body) body.hidden = !open;
2723
- const button = document.getElementById(node.id + "-trigger");
2724
- button == null ? void 0 : button.setAttribute("aria-expanded", String(open));
2725
- }
2726
- if (node.kind === "tooltip") {
2727
- const tooltip = el.querySelector("[role=tooltip]");
2728
- if (tooltip) tooltip.hidden = !state.overlays.some((overlay) => overlay.id === node.id);
2729
- const trigger = node.children[0] ? element(node.children[0]) : null;
2730
- if (trigger && tooltip) trigger.setAttribute("aria-describedby", tooltip.id);
2731
- }
2732
- if (node.attributes.dismissible === true && ["toast", "alert"].includes(node.kind))
2733
- el.hidden = el.hidden || state.expanded[node.id] === false;
2734
- if (el instanceof HTMLAnchorElement) {
2735
- if (el.getAttribute("href") === state.address) el.setAttribute("aria-current", "page");
2736
- else el.removeAttribute("aria-current");
2737
- }
2738
- if (node.attributes.data) {
2739
- const value = view.data[node.id];
2740
- if (node.kind === "table" && Array.isArray(value)) {
2741
- const body = el.querySelector("tbody"), fragment = document.createDocumentFragment();
2742
- for (const row of value) {
2743
- const tr = document.createElement("tr");
2744
- for (const key of node.attributes.columns) {
2745
- const td = document.createElement("td");
2746
- td.textContent = present(row[key]);
2747
- tr.append(td);
2748
- }
2749
- fragment.append(tr);
2750
- }
2751
- body.replaceChildren(fragment);
2752
- } else if (node.kind === "list" && Array.isArray(value)) {
2753
- const fragment = document.createDocumentFragment();
2754
- for (const item of value) {
2755
- const li = document.createElement("li");
2756
- li.textContent = present(item);
2757
- fragment.append(li);
2758
- }
2759
- el.replaceChildren(fragment);
2760
- } else if (node.kind === "text" && value !== void 0) el.textContent = present(value);
2761
- }
2762
- }
2763
- for (const screen of program.screens) (_g = element(screen.id)) == null ? void 0 : _g.removeAttribute("role");
2764
- if (active && ![...root.querySelectorAll("main")].some((main) => !main.closest("[hidden]")))
2765
- (_h = element(active.id)) == null ? void 0 : _h.setAttribute("role", "main");
2766
- const status = root.querySelector("[data-wf-runtime-status]");
2767
- status.textContent = state.diagnostic ? "The action could not complete: " + state.diagnostic : "";
2768
- if (state.diagnostic) root.setAttribute("data-wf-runtime-diagnostic", state.diagnostic);
2769
- else root.removeAttribute("data-wf-runtime-diagnostic");
2770
- const lastTrace = state.trace.at(-1);
2771
- if (lastTrace) root.setAttribute("data-wf-operation-result", lastTrace.result);
2772
- document.getElementById("wf-runtime-trace").textContent = JSON.stringify(state.trace);
2773
- if (state.focus && state.focus !== projectedFocus) {
2774
- const focus = focusElement(state.focus);
2775
- if (focus && focus !== document.activeElement && !focus.closest("[hidden],[inert]"))
2776
- focus.focus();
2777
- } else if (!state.route && projectedFocus !== null) {
2778
- const heading = routeError.querySelector("h1");
2779
- heading == null ? void 0 : heading.focus();
2780
- }
2781
- projectedFocus = state.focus;
2782
- } finally {
2783
- projecting = false;
2784
- }
2785
- }
2786
- function apply(input, sequence = null, deferProjection = false) {
2787
- if (queue.length >= 4096) throw Error("limit-queue");
2788
- queue.push({ input, sequence, deferProjection });
2789
- if (processing) return;
2790
- processing = true;
2791
- try {
2792
- while (queue.length) {
2793
- const item = queue.shift();
2794
- state = engine.reduce(state, item.input, item.sequence);
2795
- effectCommands();
2796
- if (item.deferProjection) {
2797
- if (projectionTimer === void 0) projectionTimer = setTimeout(render, 0);
2798
- } else render();
2799
- }
2800
- } finally {
2801
- processing = false;
2802
- }
2803
- }
2804
- function owner(target) {
2805
- var _a, _b;
2806
- if (!(target instanceof Element)) return void 0;
2807
- const el = target.closest("[data-wf-event-owner], [data-wf-kind]");
2808
- return nodes.get((_b = (_a = el == null ? void 0 : el.getAttribute("data-wf-event-owner")) != null ? _a : el == null ? void 0 : el.id) != null ? _b : "");
2809
- }
2810
- function nativeEvent(event) {
2811
- if (projecting) return;
2812
- const node = owner(event.target);
2813
- if (!node) return;
2814
- const kind = event.type;
2815
- const input = { kind: "event", source: node.identity, event: kind };
2816
- if (kind === "input" || kind === "change") {
2817
- const control = event.target;
2818
- if (event.isComposing) return;
2819
- if ((composition == null ? void 0 : composition.id) === node.id) {
2820
- if (composition.value === control.value) {
2821
- composition = null;
2822
- return;
2823
- }
2824
- composition = null;
2825
- }
2826
- if (["checkbox", "radio", "switch"].includes(node.kind)) input.checked = control.checked;
2827
- else input.value = control.value;
2828
- }
2829
- apply(input);
2830
- }
2831
- root.addEventListener("input", nativeEvent);
2832
- root.addEventListener("change", nativeEvent);
2833
- root.addEventListener("focus", nativeEvent, true);
2834
- root.addEventListener("blur", nativeEvent, true);
2835
- root.addEventListener("compositionstart", (event) => {
2836
- const node = owner(event.target);
2837
- if (node) composition = { id: node.id, value: event.target.value };
2838
- });
2839
- root.addEventListener("compositionend", (event) => {
2840
- const node = owner(event.target);
2841
- if (!node) return;
2842
- const value = event.target.value;
2843
- composition = null;
2844
- apply({ kind: "event", source: node.identity, event: "input", value });
2845
- composition = { id: node.id, value };
2846
- });
2847
- root.addEventListener("submit", (event) => {
2848
- event.preventDefault();
2849
- if (projecting) return;
2850
- const node = owner(event.target);
2851
- if (node) apply({ kind: "event", source: node.identity, event: "submit" });
2852
- });
2853
- root.addEventListener("click", (event) => {
2854
- if (projecting) return;
2855
- const target = event.target, tool = target.closest("[data-wf-tooling]");
2856
- if (tool) {
2857
- event.preventDefault();
2858
- projectedFocus = void 0;
2859
- if (tool.getAttribute("data-wf-tooling") === "view") {
2860
- state = { ...state, viewMode: state.viewMode === "fixed" ? "accessible" : "fixed" };
2861
- render();
2862
- } else if (tool.getAttribute("data-wf-tooling") === "reset") apply({ kind: "reset" });
2863
- return;
2864
- }
2865
- const node = owner(event.target);
2866
- if (!node) return;
2867
- if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
2868
- return;
2869
- const anchor = target.closest("a");
2870
- if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(node.kind)) {
2871
- if (node.handlers.some((handler) => handler.event === "click"))
2872
- apply({ kind: "event", source: node.identity, event: "click" }, null, true);
2873
- return;
2874
- }
2875
- if (anchor && node.attributes.href !== void 0 && !node.handlers.some((handler) => handler.event === "click"))
2876
- return;
2877
- event.preventDefault();
2878
- apply({ kind: "event", source: node.identity, event: "click" });
2879
- });
2880
- root.addEventListener("keydown", (event) => {
2881
- if (projecting) return;
2882
- const node = owner(event.target);
2883
- if (!node) return;
2884
- const explicit = node.handlers.some(
2885
- (handler) => handler.event === "keydown" && handler.key === event.key
2886
- ), widget = ["tab", "tabs", "dropdown", "dropdown-item"].includes(node.kind) && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Enter", " "].includes(
2887
- event.key
2888
- );
2889
- if (explicit || widget || event.key === "Escape") {
2890
- event.preventDefault();
2891
- apply({ kind: "event", source: node.identity, event: "keydown", key: event.key });
2892
- } else if (event.key === "Enter" && ["input", "select"].includes(node.kind) && node.form) {
2893
- event.preventDefault();
2894
- const form = nodes.get(node.form);
2895
- apply({ kind: "event", source: form.identity, event: "submit" });
2896
- }
2897
- });
2898
- root.addEventListener(
2899
- "cancel",
2900
- (event) => {
2901
- event.preventDefault();
2902
- const node = owner(event.target);
2903
- if (node) apply({ kind: "event", source: node.identity, event: "keydown", key: "Escape" });
2904
- },
2905
- true
2906
- );
2907
- function addressChanged() {
2908
- const sequence = browserSequence(), fragment = location.hash, canonical = fragment || engine.routeAddress(program.entry);
2909
- if (!state.suspended && canonical === state.address && sequence === state.history[state.historyIndex].sequence)
2910
- return;
2911
- apply({ kind: "address", fragment }, sequence);
2912
- }
2913
- addEventListener("hashchange", addressChanged);
2914
- addEventListener("popstate", addressChanged);
2915
- for (const type of ["pointerover", "pointerout"])
2916
- root.addEventListener(type, (event) => {
2917
- const target = event.target instanceof Element ? event.target.closest("[data-wf-kind=tooltip]") : null;
2918
- if (!target || target.contains(event.relatedTarget)) return;
2919
- if (type === "pointerout" && target.contains(document.activeElement)) return;
2920
- state = engine.hover(state, target.id, type === "pointerover");
2921
- render();
2922
- });
2923
- function schedule() {
2924
- timer = setTimeout(() => {
2925
- const now = performance.now();
2926
- if (!paused && !state.suspended) {
2927
- let delta = Math.max(0, Math.floor(now - last));
2928
- while (delta > 0) {
2929
- const part = Math.min(delta, 6e5);
2930
- const next = engine.reduce(state, { kind: "advanceClock", deltaMs: part });
2931
- const changed = next.sequence !== state.sequence;
2932
- state = next;
2933
- if (changed) {
2934
- effectCommands();
2935
- render();
2936
- }
2937
- delta -= part;
2938
- }
2939
- }
2940
- last = now;
2941
- schedule();
2942
- }, 16);
2943
- }
2944
- history.replaceState(metadata(state.history[state.historyIndex].sequence), "", location.href);
2945
- render();
2946
- schedule();
2947
- Object.defineProperty(window, "wireweaveRuntime", {
2948
- value: Object.freeze({
2949
- pause() {
2950
- paused = true;
2951
- last = performance.now();
2952
- },
2953
- resume() {
2954
- paused = false;
2955
- last = performance.now();
2956
- },
2957
- dispatch(input) {
2958
- apply(input);
2959
- },
2960
- advanceClock(deltaMs) {
2961
- paused = true;
2962
- apply({ kind: "advanceClock", deltaMs });
2963
- },
2964
- reset() {
2965
- apply({ kind: "reset" });
2966
- },
2967
- snapshot() {
2968
- return JSON.parse(JSON.stringify(state));
2969
- }
2970
- }),
2971
- enumerable: false,
2972
- writable: false,
2973
- configurable: false
2974
- });
2975
- addEventListener("pagehide", () => {
2976
- if (timer !== void 0) clearTimeout(timer);
2977
- });
2978
- }
2979
- var NATIVE_RUNTIME = `(()=>{const program=JSON.parse(document.getElementById("wf-runtime-data").textContent);(${browserAdapter.toString()})((${runtimeEngine.toString()})(program),program);})();`;
2980
2615
  function compileAppV4(linked) {
2981
- const data = chunkNV6UV5ID_cjs.getLinkedAppData(linked);
2616
+ const data = chunk7ZRMSFWZ_cjs.getLinkedAppData(linked);
2982
2617
  if (data === void 0)
2983
- return chunkNV6UV5ID_cjs.failed([chunkNV6UV5ID_cjs.diagnostic("WW_SCHEMA", "app.untrusted-linked-model", void 0, {}, "compile")]);
2618
+ return chunk7ZRMSFWZ_cjs.failed([chunk7ZRMSFWZ_cjs.diagnostic("WW_SCHEMA", "app.untrusted-linked-model", void 0, {}, "compile")]);
2984
2619
  if (data.artifact !== void 0) return { ok: true, value: data.artifact, diagnostics: [] };
2985
2620
  const renderer = new HtmlArtifact(data, runtimeProgram(linked));
2986
2621
  const html = renderer.html();
2987
2622
  if (new TextEncoder().encode(html).byteLength > 64 * 1024 * 1024)
2988
- return chunkNV6UV5ID_cjs.failed([chunkNV6UV5ID_cjs.diagnostic("WW_LIMIT", "app.html-byte-limit", void 0, {}, "compile")]);
2989
- const artifact = chunkNV6UV5ID_cjs.freeze({
2623
+ return chunk7ZRMSFWZ_cjs.failed([chunk7ZRMSFWZ_cjs.diagnostic("WW_LIMIT", "app.html-byte-limit", void 0, {}, "compile")]);
2624
+ const artifact = chunk7ZRMSFWZ_cjs.freeze({
2990
2625
  kind: "AppArtifact",
2991
2626
  schemaVersion: "1.0.0",
2992
2627
  languageVersion: "4.0.0",
@@ -2994,10 +2629,10 @@ function compileAppV4(linked) {
2994
2629
  sourceMap: data.sourceMap,
2995
2630
  mediaType: "text/html",
2996
2631
  byteLength: new TextEncoder().encode(html).byteLength,
2997
- digest: chunkIMUVIIJR_cjs.digestV4(html),
2632
+ digest: chunkEWCLLW6P_cjs.digestV4(html),
2998
2633
  modelDigest: linked.digest,
2999
- profileDigest: chunkIMUVIIJR_cjs.digestV4(chunkNV6UV5ID_cjs.jcs(data.bundle.profile)),
3000
- runtimeDigest: chunkIMUVIIJR_cjs.digestV4(NATIVE_RUNTIME),
2634
+ profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
2635
+ runtimeDigest: chunkEWCLLW6P_cjs.digestV4(NATIVE_RUNTIME),
3001
2636
  registryDigest: data.bundle.registry.digest,
3002
2637
  entry: data.bundle.entry,
3003
2638
  screenIndex: data.screens.map((screen) => ({
@@ -3005,12 +2640,12 @@ function compileAppV4(linked) {
3005
2640
  renderedId: screen.children[0].renderedId
3006
2641
  })),
3007
2642
  operationIndex: data.nodes.flatMap(
3008
- (node) => chunkNV6UV5ID_cjs.asObjects(node.node.attributes.on).flatMap(
3009
- (handler) => chunkNV6UV5ID_cjs.asObjects(handler.operations).map((operation) => ({
2643
+ (node) => chunk7ZRMSFWZ_cjs.asObjects(node.node.attributes.on).flatMap(
2644
+ (handler) => chunk7ZRMSFWZ_cjs.asObjects(handler.operations).map((operation) => ({
3010
2645
  renderedId: node.renderedId,
3011
- handlerId: chunkNV6UV5ID_cjs.textValue(handler.id),
3012
- operationId: chunkNV6UV5ID_cjs.textValue(operation.id),
3013
- executionClass: chunkNV6UV5ID_cjs.textValue(operation.executionClass),
2646
+ handlerId: chunk7ZRMSFWZ_cjs.textValue(handler.id),
2647
+ operationId: chunk7ZRMSFWZ_cjs.textValue(operation.id),
2648
+ executionClass: chunk7ZRMSFWZ_cjs.textValue(operation.executionClass),
3014
2649
  operation
3015
2650
  }))
3016
2651
  )
@@ -3019,11 +2654,17 @@ function compileAppV4(linked) {
3019
2654
  manifest: {
3020
2655
  appId: data.bundle.id,
3021
2656
  modelDigest: linked.digest,
3022
- profileDigest: chunkIMUVIIJR_cjs.digestV4(chunkNV6UV5ID_cjs.jcs(data.bundle.profile)),
2657
+ profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
3023
2658
  registryDigest: data.bundle.registry.digest,
3024
- htmlDigest: chunkIMUVIIJR_cjs.digestV4(html),
3025
- runtimeDigest: chunkIMUVIIJR_cjs.digestV4(NATIVE_RUNTIME),
2659
+ htmlDigest: chunkEWCLLW6P_cjs.digestV4(html),
2660
+ runtimeDigest: chunkEWCLLW6P_cjs.digestV4(NATIVE_RUNTIME),
3026
2661
  executionScope: "standard-1",
2662
+ assets: [...renderer.assets.values()].map(({ id, mediaType, digest, byteLength }) => ({
2663
+ id,
2664
+ mediaType,
2665
+ digest,
2666
+ byteLength
2667
+ })),
3027
2668
  unsupportedOperations: renderer.unsupported
3028
2669
  }
3029
2670
  });