@wireweave/core 4.0.0-beta.15 → 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.
- package/dist/app.cjs +13 -13
- package/dist/app.js +2 -2
- package/dist/{chunk-24W2GEKO.js → chunk-6EMG345O.js} +2 -2
- package/dist/{chunk-VCHXMPZL.cjs → chunk-7ZRMSFWZ.cjs} +37 -37
- package/dist/{chunk-ZPHNXJRY.cjs → chunk-CGTYVLPA.cjs} +4 -4
- package/dist/{chunk-H2SWIUMU.cjs → chunk-EWCLLW6P.cjs} +2 -0
- package/dist/{chunk-XODYFTKU.cjs → chunk-J5WEVZIX.cjs} +89 -502
- package/dist/chunk-KEQRLZQP.js +3066 -0
- package/dist/{chunk-XYACLXXF.js → chunk-LBJTNQXU.js} +1 -1
- package/dist/{chunk-NPDSIAWT.js → chunk-MLCJ6NIB.js} +3 -3
- package/dist/{chunk-NZGEUVB4.js → chunk-NMIPMOEJ.js} +26 -439
- package/dist/chunk-WCCYK5WK.cjs +3077 -0
- package/dist/{chunk-KMZXXIM2.cjs → chunk-XZL42ZQ2.cjs} +28 -28
- package/dist/{chunk-UGMDBW46.js → chunk-YAANMWP2.js} +2 -0
- package/dist/index.cjs +238 -222
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -11
- package/dist/interaction.cjs +6 -6
- package/dist/interaction.js +1 -1
- package/dist/parser.cjs +9 -9
- package/dist/parser.js +1 -1
- package/dist/renderer.cjs +32 -32
- package/dist/renderer.js +3 -3
- package/dist/spec.cjs +39 -23
- package/dist/spec.d.cts +45 -1
- package/dist/spec.d.ts +45 -1
- package/dist/spec.js +1 -1
- package/package.json +19 -13
- package/dist/chunk-MD6MNOEQ.cjs +0 -2884
- package/dist/chunk-V3HVWC7C.js +0 -2874
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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,
|
|
68
|
-
return { sourceId: manifest.sourceId, location
|
|
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
|
|
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
|
|
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
|
|
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"&¤t.id!==node.id)&&!state.overlays.some(overlay=>overlay.id===current.id))return false;if(current.kind==="tab"&¤t.parent&¤t.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(
|
|
615
|
-
if (!("screens" in
|
|
617
|
+
function compileApp(document, options = {}) {
|
|
618
|
+
if (!("screens" in document)) return compileAppV4(document);
|
|
616
619
|
const projected = {
|
|
617
620
|
type: "Document",
|
|
618
|
-
children: [...
|
|
621
|
+
children: [...document.layouts.map(projectLayout), ...document.screens.map(projectScreen)]
|
|
619
622
|
};
|
|
620
|
-
return
|
|
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
|
|
635
|
+
return chunk7ZRMSFWZ_cjs.textValue(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
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
|
|
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 =
|
|
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,6 +657,10 @@ 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);
|
|
@@ -661,46 +668,49 @@ var HtmlArtifact = class {
|
|
|
661
668
|
chunkETV4XYOV_cjs.__publicField(this, "unsupported", []);
|
|
662
669
|
chunkETV4XYOV_cjs.__publicField(this, "rules", []);
|
|
663
670
|
chunkETV4XYOV_cjs.__publicField(this, "assets");
|
|
664
|
-
this.assets =
|
|
671
|
+
this.assets = chunk7ZRMSFWZ_cjs.validateAppAssets(data.bundle.profile).assets;
|
|
665
672
|
}
|
|
666
673
|
node(entry) {
|
|
667
674
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
668
675
|
const { node, renderedId } = entry;
|
|
669
676
|
const attrs = node.attributes;
|
|
670
|
-
const label = (_b = node.label) != null ? _b :
|
|
677
|
+
const label = (_b = node.label) != null ? _b : chunk7ZRMSFWZ_cjs.textValue((_a = attrs.label) != null ? _a : "");
|
|
671
678
|
const children = () => entry.children.map((child) => this.node(child)).join("");
|
|
672
|
-
let common = attribute("id", renderedId) + 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(
|
|
673
683
|
"data-wf-requirements",
|
|
674
|
-
attrs.requirementRefs === void 0 ? void 0 :
|
|
684
|
+
attrs.requirementRefs === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.requirementRefs)
|
|
675
685
|
) + attribute(
|
|
676
686
|
"data-wf-obligations",
|
|
677
|
-
attrs.obligationRefs === void 0 ? void 0 :
|
|
678
|
-
) + attribute("data-wf-on", attrs.on === void 0 ? void 0 :
|
|
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(
|
|
679
689
|
"data-wf-targets",
|
|
680
|
-
entry.effectTargets === void 0 ? void 0 :
|
|
690
|
+
entry.effectTargets === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(entry.effectTargets)
|
|
681
691
|
) + attribute(
|
|
682
692
|
"data-wf-visible-when",
|
|
683
|
-
attrs.visibleWhen === void 0 ? void 0 :
|
|
693
|
+
attrs.visibleWhen === void 0 ? void 0 : chunk7ZRMSFWZ_cjs.jcs(attrs.visibleWhen)
|
|
684
694
|
) + attribute(
|
|
685
695
|
"data-wf-enabled-when",
|
|
686
|
-
attrs.enabledWhen === void 0 ? void 0 :
|
|
687
|
-
) + attribute("data-wf-when", attrs.when === void 0 ? void 0 :
|
|
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(
|
|
688
698
|
"data-wf-disabled",
|
|
689
699
|
attrs.disabled === true || attrs.loading === true ? true : void 0
|
|
690
700
|
) + attribute("data-wf-action", attrs.action);
|
|
691
|
-
for (const handler of
|
|
692
|
-
for (const operation of
|
|
701
|
+
for (const handler of chunk7ZRMSFWZ_cjs.asObjects(attrs.on))
|
|
702
|
+
for (const operation of chunk7ZRMSFWZ_cjs.asObjects(handler.operations)) {
|
|
693
703
|
if (operation.executionClass === "specified") {
|
|
694
704
|
this.unsupported.push({
|
|
695
705
|
renderedId,
|
|
696
|
-
handlerId:
|
|
697
|
-
operationId:
|
|
706
|
+
handlerId: chunk7ZRMSFWZ_cjs.textValue(handler.id),
|
|
707
|
+
operationId: chunk7ZRMSFWZ_cjs.textValue(operation.id)
|
|
698
708
|
});
|
|
699
709
|
}
|
|
700
710
|
}
|
|
701
711
|
if (entry.slot) return `<div${common} data-wf-slot="${escape(entry.owner.key)}"></div>`;
|
|
702
712
|
this.layout(entry);
|
|
703
|
-
const bound =
|
|
713
|
+
const bound = chunk7ZRMSFWZ_cjs.object(attrs.bind) ? entry.stateBindings[chunk7ZRMSFWZ_cjs.textValue(attrs.bind.state)] : void 0;
|
|
704
714
|
const value = (_d = bound == null ? void 0 : bound.initial) != null ? _d : attrs.value;
|
|
705
715
|
const disabled = attrs.disabled === true || attrs.loading === true;
|
|
706
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>`;
|
|
@@ -717,7 +727,7 @@ var HtmlArtifact = class {
|
|
|
717
727
|
);
|
|
718
728
|
if (node.kind === "select")
|
|
719
729
|
return labelled(
|
|
720
|
-
`<select${common}${scalarAttrs}>${
|
|
730
|
+
`<select${common}${scalarAttrs}>${chunk7ZRMSFWZ_cjs.asObjects(attrs.options).map(
|
|
721
731
|
(option) => `<option${attribute("value", option.value)}${attribute("selected", value === option.value)}${attribute("disabled", option.disabled)}>${escape(option.label)}</option>`
|
|
722
732
|
).join("")}</select>`
|
|
723
733
|
);
|
|
@@ -764,11 +774,11 @@ var HtmlArtifact = class {
|
|
|
764
774
|
if (node.kind === "table") {
|
|
765
775
|
const columns = Array.isArray(attrs.columns) ? attrs.columns : [];
|
|
766
776
|
let rows = (_n = node.items) != null ? _n : [];
|
|
767
|
-
if (
|
|
768
|
-
const initial = (_o = entry.stateBindings[
|
|
777
|
+
if (chunk7ZRMSFWZ_cjs.object(attrs.data)) {
|
|
778
|
+
const initial = (_o = entry.stateBindings[chunk7ZRMSFWZ_cjs.textValue(attrs.data.state)]) == null ? void 0 : _o.initial;
|
|
769
779
|
if (Array.isArray(initial))
|
|
770
780
|
rows = initial.map(
|
|
771
|
-
(record) => columns.map((column) =>
|
|
781
|
+
(record) => columns.map((column) => chunk7ZRMSFWZ_cjs.object(record) ? record[chunk7ZRMSFWZ_cjs.textValue(column)] : null)
|
|
772
782
|
);
|
|
773
783
|
}
|
|
774
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>`;
|
|
@@ -806,9 +816,9 @@ var HtmlArtifact = class {
|
|
|
806
816
|
const length = (value, axis, spacing = false) => {
|
|
807
817
|
if (typeof value === "number")
|
|
808
818
|
return `${spacing && [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20].includes(value) ? value * 4 : value}px`;
|
|
809
|
-
if (
|
|
819
|
+
if (chunk7ZRMSFWZ_cjs.object(value)) {
|
|
810
820
|
const amount = Number(value.value);
|
|
811
|
-
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}${
|
|
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)}`;
|
|
812
822
|
}
|
|
813
823
|
return value === "full" ? "100%" : value === "screen" ? `${Number(profile[axis])}px` : value === "fit" ? "fit-content" : "auto";
|
|
814
824
|
};
|
|
@@ -845,10 +855,10 @@ var HtmlArtifact = class {
|
|
|
845
855
|
if (["row", "col", "stack"].includes(kind)) {
|
|
846
856
|
styles.push(
|
|
847
857
|
"display:flex",
|
|
848
|
-
`flex-direction:${
|
|
858
|
+
`flex-direction:${chunk7ZRMSFWZ_cjs.textValue((_a = a.direction) != null ? _a : kind === "row" ? "row" : "column")}`,
|
|
849
859
|
`flex-wrap:${a.wrap === true ? "wrap" : "nowrap"}`,
|
|
850
|
-
`justify-content:${(_c = { start: "flex-start", end: "flex-end", between: "space-between", around: "space-around", evenly: "space-evenly" }[
|
|
851
|
-
`align-items:${(_e = { start: "flex-start", end: "flex-end" }[
|
|
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")}`
|
|
852
862
|
);
|
|
853
863
|
}
|
|
854
864
|
if (a.flex !== void 0)
|
|
@@ -866,7 +876,7 @@ var HtmlArtifact = class {
|
|
|
866
876
|
if (a.order !== void 0) styles.push(`order:${Number(a.order)}`);
|
|
867
877
|
if (a.scroll === true) styles.push("overflow:auto");
|
|
868
878
|
if (kind !== "page" && (a.x !== void 0 || a.y !== void 0 || a.anchor !== void 0)) {
|
|
869
|
-
const anchor =
|
|
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];
|
|
870
880
|
styles.push(
|
|
871
881
|
"position:absolute",
|
|
872
882
|
`left:calc(${horizontal === "center" ? "50%" : horizontal === "right" ? "100%" : "0%"} + ${Number((_j = a.x) != null ? _j : 0)}px)`,
|
|
@@ -876,19 +886,21 @@ var HtmlArtifact = class {
|
|
|
876
886
|
}
|
|
877
887
|
if (a.border === true || a.outline === true || a.bordered === true)
|
|
878
888
|
styles.push("border:1px solid #71717a");
|
|
879
|
-
|
|
889
|
+
const primaryAction = isPrimaryAction(entry);
|
|
890
|
+
if (a.ghost === true && !primaryAction)
|
|
891
|
+
styles.push("background:transparent", "border-color:transparent");
|
|
880
892
|
if (a.rounded === true || a.pill === true)
|
|
881
893
|
styles.push(`border-radius:${a.pill === true ? "999px" : "4px"}`);
|
|
882
894
|
if (a.muted === true) styles.push("color:#52525b");
|
|
883
|
-
if (a.bg !== void 0 || a.primary === true || a.secondary === true)
|
|
895
|
+
if (!primaryAction && (a.bg !== void 0 || a.primary === true || a.secondary === true))
|
|
884
896
|
styles.push("background:#f4f4f5");
|
|
885
897
|
if (a.shadow !== void 0 && a.shadow !== "none")
|
|
886
898
|
styles.push(
|
|
887
|
-
`box-shadow:0 ${{ sm: 1, md: 2, lg: 4, xl: 8 }[
|
|
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`
|
|
888
900
|
);
|
|
889
901
|
if (a.bold === true || a.weight !== void 0)
|
|
890
902
|
styles.push(
|
|
891
|
-
`font-weight:${a.bold === true ? 700 : { normal: 400, medium: 500, semibold: 600, bold: 700 }[
|
|
903
|
+
`font-weight:${a.bold === true ? 700 : { normal: 400, medium: 500, semibold: 600, bold: 700 }[chunk7ZRMSFWZ_cjs.textValue(a.weight)]}`
|
|
892
904
|
);
|
|
893
905
|
if (typeof a.size === "string") {
|
|
894
906
|
const font = { xs: 12, sm: 14, base: 16, md: 16, lg: 18, xl: 20, "2xl": 24, "3xl": 30 }[a.size];
|
|
@@ -901,7 +913,7 @@ var HtmlArtifact = class {
|
|
|
901
913
|
);
|
|
902
914
|
} else if (typeof a.size === "number") styles.push(`width:${a.size}px`, `height:${a.size}px`);
|
|
903
915
|
if (["text", "title", "link"].includes(kind) && a.align !== void 0)
|
|
904
|
-
styles.push(`text-align:${
|
|
916
|
+
styles.push(`text-align:${chunk7ZRMSFWZ_cjs.textValue(a.align)}`);
|
|
905
917
|
if (styles.length) this.rules.push(`#wireweave-app .${entry.renderedId}{${styles.join(";")}}`);
|
|
906
918
|
}
|
|
907
919
|
html() {
|
|
@@ -921,7 +933,8 @@ var HtmlArtifact = class {
|
|
|
921
933
|
const font = typeof bundle.profile.fontAssetId === "string" ? this.assets.get(bundle.profile.fontAssetId) : void 0;
|
|
922
934
|
const fontFace = font === void 0 ? "" : `@font-face{font-family:WireweaveProfile;src:url(data:${font.mediaType};base64,${font.base64}) format("woff2");font-display:swap}`;
|
|
923
935
|
const fontFamily = font === void 0 ? "system-ui,sans-serif" : "WireweaveProfile,system-ui,sans-serif";
|
|
924
|
-
const
|
|
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}`;
|
|
925
938
|
const runtimeData = this.program;
|
|
926
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'`;
|
|
927
940
|
return `<!DOCTYPE html>
|
|
@@ -2476,15 +2489,15 @@ var snapshotPrograms = /* @__PURE__ */ new WeakMap();
|
|
|
2476
2489
|
function runtimeProgram(linked) {
|
|
2477
2490
|
const cached = programCache.get(linked);
|
|
2478
2491
|
if (cached) return cached;
|
|
2479
|
-
const data =
|
|
2492
|
+
const data = chunk7ZRMSFWZ_cjs.getLinkedAppData(linked);
|
|
2480
2493
|
if (!data) throw new TypeError("Untrusted LinkedApp");
|
|
2481
2494
|
const states = {};
|
|
2482
2495
|
for (const state of data.bundle.states) {
|
|
2483
|
-
const key = `app:${
|
|
2496
|
+
const key = `app:${chunk7ZRMSFWZ_cjs.textValue(state.id)}`;
|
|
2484
2497
|
states[key] = {
|
|
2485
2498
|
key,
|
|
2486
2499
|
initial: state.initial,
|
|
2487
|
-
type:
|
|
2500
|
+
type: chunk7ZRMSFWZ_cjs.textValue(state.type),
|
|
2488
2501
|
lifetime: "session",
|
|
2489
2502
|
sensitive: state.sensitive === true,
|
|
2490
2503
|
root: "app"
|
|
@@ -2496,14 +2509,14 @@ function runtimeProgram(linked) {
|
|
|
2496
2509
|
let form = entry.parent;
|
|
2497
2510
|
while (form && form.node.kind !== "form") form = form.parent;
|
|
2498
2511
|
const root = entry.identity.instanceRoot;
|
|
2499
|
-
const handlers =
|
|
2500
|
-
id:
|
|
2501
|
-
event:
|
|
2502
|
-
...handler.key === void 0 ? {} : { 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) },
|
|
2503
2516
|
...handler.guard === void 0 ? {} : { guard: handler.guard },
|
|
2504
2517
|
concurrency: handler.concurrency === "queue" ? "queue" : "drop",
|
|
2505
|
-
operations:
|
|
2506
|
-
id:
|
|
2518
|
+
operations: chunk7ZRMSFWZ_cjs.asObjects(handler.operations).map((operation) => ({
|
|
2519
|
+
id: chunk7ZRMSFWZ_cjs.textValue(operation.id),
|
|
2507
2520
|
executionClass: operation.executionClass,
|
|
2508
2521
|
effect: operation.effect,
|
|
2509
2522
|
after: operation.after,
|
|
@@ -2543,10 +2556,10 @@ function runtimeProgram(linked) {
|
|
|
2543
2556
|
([key]) => key !== "assets" && key !== "fontAssetId"
|
|
2544
2557
|
)
|
|
2545
2558
|
);
|
|
2546
|
-
const program =
|
|
2559
|
+
const program = chunk7ZRMSFWZ_cjs.freeze({
|
|
2547
2560
|
appId: data.bundle.id,
|
|
2548
2561
|
modelDigest: linked.digest,
|
|
2549
|
-
profileDigest:
|
|
2562
|
+
profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
|
|
2550
2563
|
profile: runtimeProfile,
|
|
2551
2564
|
entry: data.bundle.entry,
|
|
2552
2565
|
nodes: runtimeNodes,
|
|
@@ -2566,11 +2579,11 @@ function runtimeProgram(linked) {
|
|
|
2566
2579
|
slot: shell.slotId
|
|
2567
2580
|
})),
|
|
2568
2581
|
fixtures: data.bundle.fixtures.map((fixture) => ({
|
|
2569
|
-
id:
|
|
2570
|
-
exhaustion:
|
|
2571
|
-
steps:
|
|
2582
|
+
id: chunk7ZRMSFWZ_cjs.textValue(fixture.id),
|
|
2583
|
+
exhaustion: chunk7ZRMSFWZ_cjs.textValue(fixture.exhaustion),
|
|
2584
|
+
steps: chunk7ZRMSFWZ_cjs.asObjects(fixture.steps).map((step) => ({
|
|
2572
2585
|
delayMs: Number(step.delayMs),
|
|
2573
|
-
outcome:
|
|
2586
|
+
outcome: chunk7ZRMSFWZ_cjs.textValue(step.outcome),
|
|
2574
2587
|
value: step.value
|
|
2575
2588
|
}))
|
|
2576
2589
|
})),
|
|
@@ -2580,7 +2593,7 @@ function runtimeProgram(linked) {
|
|
|
2580
2593
|
return program;
|
|
2581
2594
|
}
|
|
2582
2595
|
function ownSnapshot(snapshot, program) {
|
|
2583
|
-
|
|
2596
|
+
chunk7ZRMSFWZ_cjs.freeze(snapshot);
|
|
2584
2597
|
snapshotPrograms.set(snapshot, program);
|
|
2585
2598
|
return snapshot;
|
|
2586
2599
|
}
|
|
@@ -2599,442 +2612,16 @@ function advanceClock(snapshot, deltaMs) {
|
|
|
2599
2612
|
function resetRuntime(snapshot) {
|
|
2600
2613
|
return reduceEvent(snapshot, { kind: "reset" });
|
|
2601
2614
|
}
|
|
2602
|
-
function browserAdapter(engine, program) {
|
|
2603
|
-
const root = document.getElementById("wireweave-app"), storage = root.querySelector("[data-wf-screen-storage]");
|
|
2604
|
-
const nodes = new Map(program.nodes.map((node) => [node.id, node]));
|
|
2605
|
-
let state = engine.initial(location.hash), projecting = false, processing = false, paused = false, last = performance.now(), timer;
|
|
2606
|
-
let projectedFocus;
|
|
2607
|
-
let projectionTimer;
|
|
2608
|
-
const queue = [];
|
|
2609
|
-
let composition = null;
|
|
2610
|
-
const present = (value) => value == null ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
2611
|
-
function element(id) {
|
|
2612
|
-
return document.getElementById(id);
|
|
2613
|
-
}
|
|
2614
|
-
function focusElement(id) {
|
|
2615
|
-
const node = nodes.get(id);
|
|
2616
|
-
if ((node == null ? void 0 : node.kind) === "tab") return document.getElementById(id + "-tab");
|
|
2617
|
-
if ((node == null ? void 0 : node.kind) === "dropdown") return document.getElementById(id + "-trigger");
|
|
2618
|
-
return element(id);
|
|
2619
|
-
}
|
|
2620
|
-
function pendingFor(id) {
|
|
2621
|
-
for (const request of Object.values(state.requests)) {
|
|
2622
|
-
let owner2 = nodes.get(request.owner);
|
|
2623
|
-
while (owner2) {
|
|
2624
|
-
if (owner2.id === id) return true;
|
|
2625
|
-
owner2 = owner2.parent ? nodes.get(owner2.parent) : void 0;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
return false;
|
|
2629
|
-
}
|
|
2630
|
-
function metadata(sequence) {
|
|
2631
|
-
return { wireweave: { modelDigest: program.modelDigest, sequence } };
|
|
2632
|
-
}
|
|
2633
|
-
function browserSequence() {
|
|
2634
|
-
const outer = history.state;
|
|
2635
|
-
const value = outer && typeof outer === "object" ? outer.wireweave : void 0;
|
|
2636
|
-
if (!value || typeof value !== "object") return null;
|
|
2637
|
-
const entry = value;
|
|
2638
|
-
return entry.modelDigest === program.modelDigest && typeof entry.sequence === "number" && Number.isInteger(entry.sequence) ? entry.sequence : null;
|
|
2639
|
-
}
|
|
2640
|
-
function effectCommands() {
|
|
2641
|
-
for (const effect of state.effects) {
|
|
2642
|
-
if (effect.kind === "push") history.pushState(metadata(effect.sequence), "", effect.fragment);
|
|
2643
|
-
else if (effect.kind === "replace")
|
|
2644
|
-
history.replaceState(metadata(effect.sequence), "", effect.fragment);
|
|
2645
|
-
else if (effect.kind === "traverse" || effect.kind === "compensate") {
|
|
2646
|
-
if (effect.delta !== 0) history.go(effect.delta);
|
|
2647
|
-
else history.replaceState(metadata(effect.sequence), "", effect.fragment);
|
|
2648
|
-
} else location.assign(effect.fragment);
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
function render() {
|
|
2652
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2653
|
-
if (projectionTimer !== void 0) {
|
|
2654
|
-
clearTimeout(projectionTimer);
|
|
2655
|
-
projectionTimer = void 0;
|
|
2656
|
-
}
|
|
2657
|
-
projecting = true;
|
|
2658
|
-
try {
|
|
2659
|
-
const view = engine.view(state), active = program.screens.find(
|
|
2660
|
-
(screen) => {
|
|
2661
|
-
var _a2, _b2;
|
|
2662
|
-
return screen.route.namespace === ((_a2 = state.route) == null ? void 0 : _a2.namespace) && screen.route.id === ((_b2 = state.route) == null ? void 0 : _b2.id);
|
|
2663
|
-
}
|
|
2664
|
-
);
|
|
2665
|
-
for (const wrapper of root.querySelectorAll("[data-wf-screen]")) {
|
|
2666
|
-
const visible = wrapper.contains(element((_a = active == null ? void 0 : active.id) != null ? _a : ""));
|
|
2667
|
-
wrapper.hidden = !visible;
|
|
2668
|
-
wrapper.inert = !visible;
|
|
2669
|
-
if (!visible && wrapper.parentElement !== storage) storage.append(wrapper);
|
|
2670
|
-
}
|
|
2671
|
-
for (const wrapper of root.querySelectorAll("[data-wf-shell]")) {
|
|
2672
|
-
const visible = !!(active == null ? void 0 : active.shell) && wrapper.contains(element(active.shell));
|
|
2673
|
-
wrapper.hidden = !visible;
|
|
2674
|
-
wrapper.inert = !visible;
|
|
2675
|
-
}
|
|
2676
|
-
if (active) {
|
|
2677
|
-
const screen = element(active.id).closest("[data-wf-screen]");
|
|
2678
|
-
if (active.shell) {
|
|
2679
|
-
const shell = program.shells.find((shell2) => shell2.id === active.shell);
|
|
2680
|
-
const slot = element(shell.slot);
|
|
2681
|
-
if (screen.parentElement !== slot) slot.append(screen);
|
|
2682
|
-
} else if (screen.parentElement !== storage) storage.append(screen);
|
|
2683
|
-
screen.hidden = false;
|
|
2684
|
-
screen.inert = false;
|
|
2685
|
-
}
|
|
2686
|
-
const routeError = root.querySelector("[data-wf-route-error]");
|
|
2687
|
-
routeError.hidden = state.route !== null;
|
|
2688
|
-
root.querySelector("[data-wf-invalid-address]").textContent = state.address;
|
|
2689
|
-
root.setAttribute("data-wf-route", state.route ? state.address : "error");
|
|
2690
|
-
root.setAttribute("data-wf-view", state.viewMode);
|
|
2691
|
-
root.setAttribute(
|
|
2692
|
-
"aria-busy",
|
|
2693
|
-
String(state.suspended || Object.keys(state.requests).length > 0)
|
|
2694
|
-
);
|
|
2695
|
-
for (const node of program.nodes) {
|
|
2696
|
-
const el = element(node.id);
|
|
2697
|
-
if (!el) continue;
|
|
2698
|
-
el.hidden = view.visible[node.id] !== true;
|
|
2699
|
-
const pending = pendingFor(node.id);
|
|
2700
|
-
if (pending || node.attributes.loading === true) {
|
|
2701
|
-
el.setAttribute("aria-busy", "true");
|
|
2702
|
-
if (pending) el.setAttribute("data-wf-pending", "true");
|
|
2703
|
-
else el.removeAttribute("data-wf-pending");
|
|
2704
|
-
} else {
|
|
2705
|
-
el.removeAttribute("aria-busy");
|
|
2706
|
-
el.removeAttribute("data-wf-pending");
|
|
2707
|
-
}
|
|
2708
|
-
const field = el.closest("[data-wf-field]");
|
|
2709
|
-
if (field) field.hidden = el.hidden;
|
|
2710
|
-
if (node.kind === "tab") {
|
|
2711
|
-
const owner2 = nodes.get((_b = node.parent) != null ? _b : ""), tabs = (_c = owner2 == null ? void 0 : owner2.children.filter((id) => {
|
|
2712
|
-
var _a2;
|
|
2713
|
-
return ((_a2 = nodes.get(id)) == null ? void 0 : _a2.kind) === "tab";
|
|
2714
|
-
})) != null ? _c : [], selected = tabs[(_e = state.selection[(_d = owner2 == null ? void 0 : owner2.id) != null ? _d : ""]) != null ? _e : 0] === node.id;
|
|
2715
|
-
el.hidden = !view.visible[node.id] || !selected;
|
|
2716
|
-
const button = document.getElementById(node.id + "-tab");
|
|
2717
|
-
if (button) {
|
|
2718
|
-
button.setAttribute("aria-selected", String(selected));
|
|
2719
|
-
button.tabIndex = state.focus === node.id ? 0 : tabs.includes((_f = state.focus) != null ? _f : "") ? -1 : selected ? 0 : -1;
|
|
2720
|
-
button.disabled = !view.enabled[node.id];
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
if ("disabled" in el) el.disabled = view.enabled[node.id] !== true;
|
|
2724
|
-
const control = view.controls[node.id];
|
|
2725
|
-
if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(
|
|
2726
|
-
node.kind
|
|
2727
|
-
)) {
|
|
2728
|
-
const input = el;
|
|
2729
|
-
if (["checkbox", "radio", "switch"].includes(node.kind)) input.checked = control.checked;
|
|
2730
|
-
else if (!composition || composition.id !== node.id) input.value = present(control.value);
|
|
2731
|
-
}
|
|
2732
|
-
if (state.invalid[node.id]) {
|
|
2733
|
-
el.setAttribute("aria-invalid", "true");
|
|
2734
|
-
const message = element(node.id + "-error");
|
|
2735
|
-
if (message) {
|
|
2736
|
-
message.textContent = state.invalid[node.id];
|
|
2737
|
-
message.hidden = false;
|
|
2738
|
-
el.setAttribute("aria-describedby", message.id);
|
|
2739
|
-
}
|
|
2740
|
-
} else {
|
|
2741
|
-
el.removeAttribute("aria-invalid");
|
|
2742
|
-
const message = element(node.id + "-error");
|
|
2743
|
-
if (message) message.hidden = true;
|
|
2744
|
-
el.removeAttribute("aria-describedby");
|
|
2745
|
-
}
|
|
2746
|
-
if (node.kind === "form") {
|
|
2747
|
-
const error = el.querySelector("[data-wf-form-error]");
|
|
2748
|
-
if (error) {
|
|
2749
|
-
error.textContent = state.invalid[node.id] ? "Check the required input values." : "";
|
|
2750
|
-
error.hidden = !state.invalid[node.id];
|
|
2751
|
-
}
|
|
2752
|
-
el.setAttribute("aria-busy", String(pending || node.attributes.loading === true));
|
|
2753
|
-
}
|
|
2754
|
-
if (node.kind === "accordion")
|
|
2755
|
-
el.open = state.expanded[node.id] === true;
|
|
2756
|
-
if (["modal", "drawer", "popover"].includes(node.kind)) {
|
|
2757
|
-
const overlay = state.overlays.find((overlay2) => overlay2.id === node.id), dialog = el;
|
|
2758
|
-
if (overlay) {
|
|
2759
|
-
dialog.hidden = false;
|
|
2760
|
-
if (!dialog.open) {
|
|
2761
|
-
if (overlay.modal) dialog.showModal();
|
|
2762
|
-
else dialog.show();
|
|
2763
|
-
}
|
|
2764
|
-
dialog.setAttribute("aria-modal", String(overlay.modal));
|
|
2765
|
-
} else if (dialog.open) dialog.close();
|
|
2766
|
-
}
|
|
2767
|
-
if (node.kind === "dropdown") {
|
|
2768
|
-
const open = state.overlays.some((overlay) => overlay.id === node.id);
|
|
2769
|
-
const body = el.querySelector("[data-wf-overlay-body]");
|
|
2770
|
-
if (body) body.hidden = !open;
|
|
2771
|
-
const button = document.getElementById(node.id + "-trigger");
|
|
2772
|
-
button == null ? void 0 : button.setAttribute("aria-expanded", String(open));
|
|
2773
|
-
}
|
|
2774
|
-
if (node.kind === "tooltip") {
|
|
2775
|
-
const tooltip = el.querySelector("[role=tooltip]");
|
|
2776
|
-
if (tooltip) tooltip.hidden = !state.overlays.some((overlay) => overlay.id === node.id);
|
|
2777
|
-
const trigger = node.children[0] ? element(node.children[0]) : null;
|
|
2778
|
-
if (trigger && tooltip) trigger.setAttribute("aria-describedby", tooltip.id);
|
|
2779
|
-
}
|
|
2780
|
-
if (node.attributes.dismissible === true && ["toast", "alert"].includes(node.kind))
|
|
2781
|
-
el.hidden = el.hidden || state.expanded[node.id] === false;
|
|
2782
|
-
if (el instanceof HTMLAnchorElement) {
|
|
2783
|
-
if (el.getAttribute("href") === state.address) el.setAttribute("aria-current", "page");
|
|
2784
|
-
else el.removeAttribute("aria-current");
|
|
2785
|
-
}
|
|
2786
|
-
if (node.attributes.data) {
|
|
2787
|
-
const value = view.data[node.id];
|
|
2788
|
-
if (node.kind === "table" && Array.isArray(value)) {
|
|
2789
|
-
const body = el.querySelector("tbody"), fragment = document.createDocumentFragment();
|
|
2790
|
-
for (const row of value) {
|
|
2791
|
-
const tr = document.createElement("tr");
|
|
2792
|
-
for (const key of node.attributes.columns) {
|
|
2793
|
-
const td = document.createElement("td");
|
|
2794
|
-
td.textContent = present(row[key]);
|
|
2795
|
-
tr.append(td);
|
|
2796
|
-
}
|
|
2797
|
-
fragment.append(tr);
|
|
2798
|
-
}
|
|
2799
|
-
body.replaceChildren(fragment);
|
|
2800
|
-
} else if (node.kind === "list" && Array.isArray(value)) {
|
|
2801
|
-
const fragment = document.createDocumentFragment();
|
|
2802
|
-
for (const item of value) {
|
|
2803
|
-
const li = document.createElement("li");
|
|
2804
|
-
li.textContent = present(item);
|
|
2805
|
-
fragment.append(li);
|
|
2806
|
-
}
|
|
2807
|
-
el.replaceChildren(fragment);
|
|
2808
|
-
} else if (node.kind === "text" && value !== void 0) el.textContent = present(value);
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
for (const screen of program.screens) (_g = element(screen.id)) == null ? void 0 : _g.removeAttribute("role");
|
|
2812
|
-
if (active && ![...root.querySelectorAll("main")].some((main) => !main.closest("[hidden]")))
|
|
2813
|
-
(_h = element(active.id)) == null ? void 0 : _h.setAttribute("role", "main");
|
|
2814
|
-
const status = root.querySelector("[data-wf-runtime-status]");
|
|
2815
|
-
status.textContent = state.diagnostic ? "The action could not complete: " + state.diagnostic : "";
|
|
2816
|
-
if (state.diagnostic) root.setAttribute("data-wf-runtime-diagnostic", state.diagnostic);
|
|
2817
|
-
else root.removeAttribute("data-wf-runtime-diagnostic");
|
|
2818
|
-
const lastTrace = state.trace.at(-1);
|
|
2819
|
-
if (lastTrace) root.setAttribute("data-wf-operation-result", lastTrace.result);
|
|
2820
|
-
document.getElementById("wf-runtime-trace").textContent = JSON.stringify(state.trace);
|
|
2821
|
-
if (state.focus && state.focus !== projectedFocus) {
|
|
2822
|
-
const focus = focusElement(state.focus);
|
|
2823
|
-
if (focus && focus !== document.activeElement && !focus.closest("[hidden],[inert]"))
|
|
2824
|
-
focus.focus();
|
|
2825
|
-
} else if (!state.route && projectedFocus !== null) {
|
|
2826
|
-
const heading = routeError.querySelector("h1");
|
|
2827
|
-
heading == null ? void 0 : heading.focus();
|
|
2828
|
-
}
|
|
2829
|
-
projectedFocus = state.focus;
|
|
2830
|
-
} finally {
|
|
2831
|
-
projecting = false;
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
function apply(input, sequence = null, deferProjection = false) {
|
|
2835
|
-
if (queue.length >= 4096) throw Error("limit-queue");
|
|
2836
|
-
queue.push({ input, sequence, deferProjection });
|
|
2837
|
-
if (processing) return;
|
|
2838
|
-
processing = true;
|
|
2839
|
-
try {
|
|
2840
|
-
while (queue.length) {
|
|
2841
|
-
const item = queue.shift();
|
|
2842
|
-
state = engine.reduce(state, item.input, item.sequence);
|
|
2843
|
-
effectCommands();
|
|
2844
|
-
if (item.deferProjection) {
|
|
2845
|
-
if (projectionTimer === void 0) projectionTimer = setTimeout(render, 0);
|
|
2846
|
-
} else render();
|
|
2847
|
-
}
|
|
2848
|
-
} finally {
|
|
2849
|
-
processing = false;
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
function owner(target) {
|
|
2853
|
-
var _a, _b;
|
|
2854
|
-
if (!(target instanceof Element)) return void 0;
|
|
2855
|
-
const el = target.closest("[data-wf-event-owner], [data-wf-kind]");
|
|
2856
|
-
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 : "");
|
|
2857
|
-
}
|
|
2858
|
-
function nativeEvent(event) {
|
|
2859
|
-
if (projecting) return;
|
|
2860
|
-
const node = owner(event.target);
|
|
2861
|
-
if (!node) return;
|
|
2862
|
-
const kind = event.type;
|
|
2863
|
-
const input = { kind: "event", source: node.identity, event: kind };
|
|
2864
|
-
if (kind === "input" || kind === "change") {
|
|
2865
|
-
const control = event.target;
|
|
2866
|
-
if (event.isComposing) return;
|
|
2867
|
-
if ((composition == null ? void 0 : composition.id) === node.id) {
|
|
2868
|
-
if (composition.value === control.value) {
|
|
2869
|
-
composition = null;
|
|
2870
|
-
return;
|
|
2871
|
-
}
|
|
2872
|
-
composition = null;
|
|
2873
|
-
}
|
|
2874
|
-
if (["checkbox", "radio", "switch"].includes(node.kind)) input.checked = control.checked;
|
|
2875
|
-
else input.value = control.value;
|
|
2876
|
-
}
|
|
2877
|
-
apply(input);
|
|
2878
|
-
}
|
|
2879
|
-
root.addEventListener("input", nativeEvent);
|
|
2880
|
-
root.addEventListener("change", nativeEvent);
|
|
2881
|
-
root.addEventListener("focus", nativeEvent, true);
|
|
2882
|
-
root.addEventListener("blur", nativeEvent, true);
|
|
2883
|
-
root.addEventListener("compositionstart", (event) => {
|
|
2884
|
-
const node = owner(event.target);
|
|
2885
|
-
if (node) composition = { id: node.id, value: event.target.value };
|
|
2886
|
-
});
|
|
2887
|
-
root.addEventListener("compositionend", (event) => {
|
|
2888
|
-
const node = owner(event.target);
|
|
2889
|
-
if (!node) return;
|
|
2890
|
-
const value = event.target.value;
|
|
2891
|
-
composition = null;
|
|
2892
|
-
apply({ kind: "event", source: node.identity, event: "input", value });
|
|
2893
|
-
composition = { id: node.id, value };
|
|
2894
|
-
});
|
|
2895
|
-
root.addEventListener("submit", (event) => {
|
|
2896
|
-
event.preventDefault();
|
|
2897
|
-
if (projecting) return;
|
|
2898
|
-
const node = owner(event.target);
|
|
2899
|
-
if (node) apply({ kind: "event", source: node.identity, event: "submit" });
|
|
2900
|
-
});
|
|
2901
|
-
root.addEventListener("click", (event) => {
|
|
2902
|
-
if (projecting) return;
|
|
2903
|
-
const target = event.target, tool = target.closest("[data-wf-tooling]");
|
|
2904
|
-
if (tool) {
|
|
2905
|
-
event.preventDefault();
|
|
2906
|
-
projectedFocus = void 0;
|
|
2907
|
-
if (tool.getAttribute("data-wf-tooling") === "view") {
|
|
2908
|
-
state = { ...state, viewMode: state.viewMode === "fixed" ? "accessible" : "fixed" };
|
|
2909
|
-
render();
|
|
2910
|
-
} else if (tool.getAttribute("data-wf-tooling") === "reset") apply({ kind: "reset" });
|
|
2911
|
-
return;
|
|
2912
|
-
}
|
|
2913
|
-
const node = owner(event.target);
|
|
2914
|
-
if (!node) return;
|
|
2915
|
-
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
2916
|
-
return;
|
|
2917
|
-
const anchor = target.closest("a");
|
|
2918
|
-
if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(node.kind)) {
|
|
2919
|
-
if (node.handlers.some((handler) => handler.event === "click"))
|
|
2920
|
-
apply({ kind: "event", source: node.identity, event: "click" }, null, true);
|
|
2921
|
-
return;
|
|
2922
|
-
}
|
|
2923
|
-
if (anchor && node.attributes.href !== void 0 && !node.handlers.some((handler) => handler.event === "click"))
|
|
2924
|
-
return;
|
|
2925
|
-
event.preventDefault();
|
|
2926
|
-
apply({ kind: "event", source: node.identity, event: "click" });
|
|
2927
|
-
});
|
|
2928
|
-
root.addEventListener("keydown", (event) => {
|
|
2929
|
-
if (projecting) return;
|
|
2930
|
-
const node = owner(event.target);
|
|
2931
|
-
if (!node) return;
|
|
2932
|
-
const explicit = node.handlers.some(
|
|
2933
|
-
(handler) => handler.event === "keydown" && handler.key === event.key
|
|
2934
|
-
), widget = ["tab", "tabs", "dropdown", "dropdown-item"].includes(node.kind) && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Enter", " "].includes(
|
|
2935
|
-
event.key
|
|
2936
|
-
);
|
|
2937
|
-
if (explicit || widget || event.key === "Escape") {
|
|
2938
|
-
event.preventDefault();
|
|
2939
|
-
apply({ kind: "event", source: node.identity, event: "keydown", key: event.key });
|
|
2940
|
-
} else if (event.key === "Enter" && ["input", "select"].includes(node.kind) && node.form) {
|
|
2941
|
-
event.preventDefault();
|
|
2942
|
-
const form = nodes.get(node.form);
|
|
2943
|
-
apply({ kind: "event", source: form.identity, event: "submit" });
|
|
2944
|
-
}
|
|
2945
|
-
});
|
|
2946
|
-
root.addEventListener(
|
|
2947
|
-
"cancel",
|
|
2948
|
-
(event) => {
|
|
2949
|
-
event.preventDefault();
|
|
2950
|
-
const node = owner(event.target);
|
|
2951
|
-
if (node) apply({ kind: "event", source: node.identity, event: "keydown", key: "Escape" });
|
|
2952
|
-
},
|
|
2953
|
-
true
|
|
2954
|
-
);
|
|
2955
|
-
function addressChanged() {
|
|
2956
|
-
const sequence = browserSequence(), fragment = location.hash, canonical = fragment || engine.routeAddress(program.entry);
|
|
2957
|
-
if (!state.suspended && canonical === state.address && sequence === state.history[state.historyIndex].sequence)
|
|
2958
|
-
return;
|
|
2959
|
-
apply({ kind: "address", fragment }, sequence);
|
|
2960
|
-
}
|
|
2961
|
-
addEventListener("hashchange", addressChanged);
|
|
2962
|
-
addEventListener("popstate", addressChanged);
|
|
2963
|
-
for (const type of ["pointerover", "pointerout"])
|
|
2964
|
-
root.addEventListener(type, (event) => {
|
|
2965
|
-
const target = event.target instanceof Element ? event.target.closest("[data-wf-kind=tooltip]") : null;
|
|
2966
|
-
if (!target || target.contains(event.relatedTarget)) return;
|
|
2967
|
-
if (type === "pointerout" && target.contains(document.activeElement)) return;
|
|
2968
|
-
state = engine.hover(state, target.id, type === "pointerover");
|
|
2969
|
-
render();
|
|
2970
|
-
});
|
|
2971
|
-
function schedule() {
|
|
2972
|
-
timer = setTimeout(() => {
|
|
2973
|
-
const now = performance.now();
|
|
2974
|
-
if (!paused && !state.suspended) {
|
|
2975
|
-
let delta = Math.max(0, Math.floor(now - last));
|
|
2976
|
-
while (delta > 0) {
|
|
2977
|
-
const part = Math.min(delta, 6e5);
|
|
2978
|
-
const next = engine.reduce(state, { kind: "advanceClock", deltaMs: part });
|
|
2979
|
-
const changed = next.sequence !== state.sequence;
|
|
2980
|
-
state = next;
|
|
2981
|
-
if (changed) {
|
|
2982
|
-
effectCommands();
|
|
2983
|
-
render();
|
|
2984
|
-
}
|
|
2985
|
-
delta -= part;
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
last = now;
|
|
2989
|
-
schedule();
|
|
2990
|
-
}, 16);
|
|
2991
|
-
}
|
|
2992
|
-
history.replaceState(metadata(state.history[state.historyIndex].sequence), "", location.href);
|
|
2993
|
-
render();
|
|
2994
|
-
schedule();
|
|
2995
|
-
Object.defineProperty(window, "wireweaveRuntime", {
|
|
2996
|
-
value: Object.freeze({
|
|
2997
|
-
pause() {
|
|
2998
|
-
paused = true;
|
|
2999
|
-
last = performance.now();
|
|
3000
|
-
},
|
|
3001
|
-
resume() {
|
|
3002
|
-
paused = false;
|
|
3003
|
-
last = performance.now();
|
|
3004
|
-
},
|
|
3005
|
-
dispatch(input) {
|
|
3006
|
-
apply(input);
|
|
3007
|
-
},
|
|
3008
|
-
advanceClock(deltaMs) {
|
|
3009
|
-
paused = true;
|
|
3010
|
-
apply({ kind: "advanceClock", deltaMs });
|
|
3011
|
-
},
|
|
3012
|
-
reset() {
|
|
3013
|
-
apply({ kind: "reset" });
|
|
3014
|
-
},
|
|
3015
|
-
snapshot() {
|
|
3016
|
-
return JSON.parse(JSON.stringify(state));
|
|
3017
|
-
}
|
|
3018
|
-
}),
|
|
3019
|
-
enumerable: false,
|
|
3020
|
-
writable: false,
|
|
3021
|
-
configurable: false
|
|
3022
|
-
});
|
|
3023
|
-
addEventListener("pagehide", () => {
|
|
3024
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
var NATIVE_RUNTIME = `(()=>{const program=JSON.parse(document.getElementById("wf-runtime-data").textContent);(${browserAdapter.toString()})((${runtimeEngine.toString()})(program),program);})();`;
|
|
3028
2615
|
function compileAppV4(linked) {
|
|
3029
|
-
const data =
|
|
2616
|
+
const data = chunk7ZRMSFWZ_cjs.getLinkedAppData(linked);
|
|
3030
2617
|
if (data === void 0)
|
|
3031
|
-
return
|
|
2618
|
+
return chunk7ZRMSFWZ_cjs.failed([chunk7ZRMSFWZ_cjs.diagnostic("WW_SCHEMA", "app.untrusted-linked-model", void 0, {}, "compile")]);
|
|
3032
2619
|
if (data.artifact !== void 0) return { ok: true, value: data.artifact, diagnostics: [] };
|
|
3033
2620
|
const renderer = new HtmlArtifact(data, runtimeProgram(linked));
|
|
3034
2621
|
const html = renderer.html();
|
|
3035
2622
|
if (new TextEncoder().encode(html).byteLength > 64 * 1024 * 1024)
|
|
3036
|
-
return
|
|
3037
|
-
const artifact =
|
|
2623
|
+
return chunk7ZRMSFWZ_cjs.failed([chunk7ZRMSFWZ_cjs.diagnostic("WW_LIMIT", "app.html-byte-limit", void 0, {}, "compile")]);
|
|
2624
|
+
const artifact = chunk7ZRMSFWZ_cjs.freeze({
|
|
3038
2625
|
kind: "AppArtifact",
|
|
3039
2626
|
schemaVersion: "1.0.0",
|
|
3040
2627
|
languageVersion: "4.0.0",
|
|
@@ -3042,10 +2629,10 @@ function compileAppV4(linked) {
|
|
|
3042
2629
|
sourceMap: data.sourceMap,
|
|
3043
2630
|
mediaType: "text/html",
|
|
3044
2631
|
byteLength: new TextEncoder().encode(html).byteLength,
|
|
3045
|
-
digest:
|
|
2632
|
+
digest: chunkEWCLLW6P_cjs.digestV4(html),
|
|
3046
2633
|
modelDigest: linked.digest,
|
|
3047
|
-
profileDigest:
|
|
3048
|
-
runtimeDigest:
|
|
2634
|
+
profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
|
|
2635
|
+
runtimeDigest: chunkEWCLLW6P_cjs.digestV4(NATIVE_RUNTIME),
|
|
3049
2636
|
registryDigest: data.bundle.registry.digest,
|
|
3050
2637
|
entry: data.bundle.entry,
|
|
3051
2638
|
screenIndex: data.screens.map((screen) => ({
|
|
@@ -3053,12 +2640,12 @@ function compileAppV4(linked) {
|
|
|
3053
2640
|
renderedId: screen.children[0].renderedId
|
|
3054
2641
|
})),
|
|
3055
2642
|
operationIndex: data.nodes.flatMap(
|
|
3056
|
-
(node) =>
|
|
3057
|
-
(handler) =>
|
|
2643
|
+
(node) => chunk7ZRMSFWZ_cjs.asObjects(node.node.attributes.on).flatMap(
|
|
2644
|
+
(handler) => chunk7ZRMSFWZ_cjs.asObjects(handler.operations).map((operation) => ({
|
|
3058
2645
|
renderedId: node.renderedId,
|
|
3059
|
-
handlerId:
|
|
3060
|
-
operationId:
|
|
3061
|
-
executionClass:
|
|
2646
|
+
handlerId: chunk7ZRMSFWZ_cjs.textValue(handler.id),
|
|
2647
|
+
operationId: chunk7ZRMSFWZ_cjs.textValue(operation.id),
|
|
2648
|
+
executionClass: chunk7ZRMSFWZ_cjs.textValue(operation.executionClass),
|
|
3062
2649
|
operation
|
|
3063
2650
|
}))
|
|
3064
2651
|
)
|
|
@@ -3067,10 +2654,10 @@ function compileAppV4(linked) {
|
|
|
3067
2654
|
manifest: {
|
|
3068
2655
|
appId: data.bundle.id,
|
|
3069
2656
|
modelDigest: linked.digest,
|
|
3070
|
-
profileDigest:
|
|
2657
|
+
profileDigest: chunkEWCLLW6P_cjs.digestV4(chunk7ZRMSFWZ_cjs.jcs(data.bundle.profile)),
|
|
3071
2658
|
registryDigest: data.bundle.registry.digest,
|
|
3072
|
-
htmlDigest:
|
|
3073
|
-
runtimeDigest:
|
|
2659
|
+
htmlDigest: chunkEWCLLW6P_cjs.digestV4(html),
|
|
2660
|
+
runtimeDigest: chunkEWCLLW6P_cjs.digestV4(NATIVE_RUNTIME),
|
|
3074
2661
|
executionScope: "standard-1",
|
|
3075
2662
|
assets: [...renderer.assets.values()].map(({ id, mediaType, digest, byteLength }) => ({
|
|
3076
2663
|
id,
|