allyhub 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/cli-version.js +2 -0
  2. package/dist/commands/add.js +5 -5
  3. package/dist/commands/dev.js +2 -2
  4. package/dist/commands/mcp.js +1 -1
  5. package/dist/commands/model.js +1 -1
  6. package/dist/commands/render.js +1 -1
  7. package/dist/commands/skills.js +3 -3
  8. package/dist/main.js +7 -7
  9. package/dist/works.js +1 -1
  10. package/editor-app/view.html +3 -3
  11. package/editor-web/assets/chevron-left-W6sP7nB1.js +1 -0
  12. package/editor-web/assets/{chevron-up-BMNXDEBs.js → chevron-up-566GQpAm.js} +1 -1
  13. package/editor-web/assets/{dist-B4VKfY-H.js → dist-BKDr73BR.js} +4 -4
  14. package/editor-web/assets/dist-CPCNTYVu.js +8 -0
  15. package/editor-web/assets/{dist-Coblfc3T.js → dist-C_NajYp0.js} +1 -1
  16. package/editor-web/assets/{dist-BcInw4os.js → dist-mA6NrAKh.js} +34 -34
  17. package/editor-web/assets/{floating-ui.react-dom-DSyn5TRd.js → floating-ui.react-dom-BUxFRF6t.js} +1 -1
  18. package/editor-web/assets/index-CFZhjTQW.js +56 -0
  19. package/editor-web/assets/index-DgU-lyX6.css +2 -0
  20. package/editor-web/assets/{react-Bo429Bov.js → react-Ff_buMj8.js} +1 -1
  21. package/editor-web/assets/{undo-2-CWgOKQ3L.js → undo-2-BKFItM3X.js} +1 -1
  22. package/editor-web/index.html +4 -4
  23. package/node_modules/@allyhub-next/audio/package.json +1 -1
  24. package/node_modules/@allyhub-next/browser/package.json +1 -1
  25. package/node_modules/@allyhub-next/build/dist/scan.js +1 -1
  26. package/node_modules/@allyhub-next/build/package.json +1 -1
  27. package/node_modules/@allyhub-next/check/dist/check.js +3 -3
  28. package/node_modules/@allyhub-next/check/package.json +1 -1
  29. package/node_modules/@allyhub-next/cloud/dist/index.js +1 -1
  30. package/node_modules/@allyhub-next/cloud/dist/token.js +1 -1
  31. package/node_modules/@allyhub-next/cloud/package.json +1 -1
  32. package/node_modules/@allyhub-next/components/package.json +1 -1
  33. package/node_modules/@allyhub-next/dev-server/dist/live.js +1 -1
  34. package/node_modules/@allyhub-next/dev-server/dist/tools.js +1 -1
  35. package/node_modules/@allyhub-next/dev-server/package.json +1 -1
  36. package/node_modules/@allyhub-next/doc/package.json +1 -1
  37. package/node_modules/@allyhub-next/export/dist/export.d.ts +5 -2
  38. package/node_modules/@allyhub-next/export/dist/export.js +2 -2
  39. package/node_modules/@allyhub-next/export/package.json +1 -1
  40. package/node_modules/@allyhub-next/formats/dist/items.d.ts +5 -0
  41. package/node_modules/@allyhub-next/formats/dist/items.js +1 -1
  42. package/node_modules/@allyhub-next/formats/dist/layout.d.ts +2 -0
  43. package/node_modules/@allyhub-next/formats/dist/layout.js +1 -1
  44. package/node_modules/@allyhub-next/formats/package.json +1 -1
  45. package/node_modules/@allyhub-next/measure/package.json +1 -1
  46. package/node_modules/@allyhub-next/media/package.json +1 -1
  47. package/node_modules/@allyhub-next/model/dist/report.d.ts +1 -1
  48. package/node_modules/@allyhub-next/model/package.json +1 -1
  49. package/node_modules/@allyhub-next/project/package.json +1 -1
  50. package/node_modules/@allyhub-next/protocol/dist/app.d.ts +3 -0
  51. package/node_modules/@allyhub-next/protocol/dist/auth.d.ts +17 -0
  52. package/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  53. package/node_modules/@allyhub-next/protocol/dist/cli.d.ts +1 -1
  54. package/node_modules/@allyhub-next/protocol/dist/cli.js +1 -1
  55. package/node_modules/@allyhub-next/protocol/dist/editor.d.ts +4 -0
  56. package/node_modules/@allyhub-next/protocol/dist/registry.d.ts +3 -1
  57. package/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  58. package/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  59. package/node_modules/@allyhub-next/protocol/dist/tools.d.ts +1 -0
  60. package/node_modules/@allyhub-next/protocol/package.json +1 -1
  61. package/node_modules/@allyhub-next/registry/package.json +1 -1
  62. package/node_modules/@allyhub-next/render/package.json +1 -1
  63. package/node_modules/@allyhub-next/runtime/dist/page.js +1 -1
  64. package/node_modules/@allyhub-next/runtime/package.json +1 -1
  65. package/node_modules/@allyhub-next/runtimes/package.json +1 -1
  66. package/node_modules/@allyhub-next/scaffold/dist/index.js +5 -5
  67. package/node_modules/@allyhub-next/scaffold/package.json +1 -1
  68. package/node_modules/@allyhub-next/scenery/package.json +1 -1
  69. package/node_modules/@allyhub-next/scenery-host/dist/bundle.d.ts +1 -0
  70. package/node_modules/@allyhub-next/scenery-host/dist/bundle.js +3 -3
  71. package/node_modules/@allyhub-next/scenery-host/dist/model-stage.d.ts +32 -0
  72. package/node_modules/@allyhub-next/scenery-host/dist/model-stage.js +3 -0
  73. package/node_modules/@allyhub-next/scenery-host/package.json +1 -1
  74. package/node_modules/@allyhub-next/sheet/package.json +1 -1
  75. package/node_modules/@allyhub-next/site/package.json +1 -1
  76. package/node_modules/@allyhub-next/stage/package.json +1 -1
  77. package/node_modules/@allyhub-next/video-core/dist/problem.d.ts +4 -0
  78. package/node_modules/@allyhub-next/video-core/dist/problem.js +1 -1
  79. package/node_modules/@allyhub-next/video-core/package.json +1 -1
  80. package/package.json +28 -28
  81. package/editor-web/assets/chevron-left-D1vfOP5S.js +0 -1
  82. package/editor-web/assets/dist-BIEloJVS.js +0 -8
  83. package/editor-web/assets/index-BSFR4plz.css +0 -2
  84. package/editor-web/assets/index-Dc8FX_sp.js +0 -56
@@ -63,7 +63,7 @@ ${s}
63
63
  Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const o of e.seen.entries()){const a=o[1];if(t===o[0]){i(o);continue}if(e.external){const c=e.external.registry.get(o[0])?.id;if(t!==o[0]&&c){i(o);continue}}if(e.metadataRegistry.get(o[0])?.id){i(o);continue}if(a.cycle){i(o);continue}a.count>1&&e.reused==="ref"&&i(o)}e.external&&(e.sharedDefsExtractedFor=e.external)}function compactTypeUnion(e){const t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;const n=[];for(const r of t){if(!r||typeof r!="object")return;compactTypeUnion(r);const u=Object.keys(r);if(u.length!==1||u[0]!=="type")return;const i=r.type;for(const o of Array.isArray(i)?i:[i]){if(typeof o!="string")return;n.includes(o)||n.push(o)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var FOLDABLE_KEYS=new Set(["type","properties","required","additionalProperties"]),UNION_KEYS=["oneOf","anyOf"];function undeclaredConstraint(e){const t=e.additionalProperties;return t===void 0||t===!1||typeof t!="object"||t===null?null:Object.keys(t).length?t:null}function foldObjects(e){const t=[];for(const i of e){if(typeof i!="object"||i.type!=="object")return null;for(const o in i)if(!FOLDABLE_KEYS.has(o))return null;t.push(i)}const n={},r=new Set;for(const i of t){for(const o in i.properties){if(Object.prototype.hasOwnProperty.call(n,o))continue;const a=[];for(const c of t){const l=c.properties?.[o]??undeclaredConstraint(c);l!=null&&(a.some(d=>JSON.stringify(d)===JSON.stringify(l))||a.push(l))}const s=a.length===1?a[0]:foldObjects(a)??{allOf:a};assignProp(n,o,s)}for(const o of i.required??[])r.add(o)}const u={type:"object",properties:n};if(r.size&&(u.required=[...r]),t.every(i=>i.additionalProperties===!1))u.additionalProperties=!1;else{const i=[];for(const o of t){const a=undeclaredConstraint(o);a&&!i.some(s=>JSON.stringify(s)===JSON.stringify(a))&&i.push(a)}i.length===1?u.additionalProperties=i[0]:i.length>1&&(u.additionalProperties={allOf:i})}return u}function foldIntersection(e){const t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(const u of FOLDABLE_KEYS)if(u in e)return;const n=t.filter(u=>UNION_KEYS.some(i=>Array.isArray(u[i])));let r=null;if(!n.length)r=foldObjects(t);else{const u=n[0],i=UNION_KEYS.find(s=>Array.isArray(u[s]));if(Object.keys(u).length!==1)return;const o=t.filter(s=>s!==u),a=u[i].map(s=>foldObjects([...o,s]));if(a.some(s=>!s))return;r={[i]:a}}r&&(delete e.allOf,assignProps(e,r))}function finalize(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=a=>{const s=e.seen.get(a);if(s.ref===null)return;const c=s.def??s.schema,l={...c},d=s.ref;if(s.ref=null,d){r(d);const m=e.seen.get(d),h=m.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(c.allOf=c.allOf??[],c.allOf.push(h)):assignProps(c,h),assignProps(c,l),a._zod.parent===d)for(const g in c)g==="$ref"||g==="allOf"||g in l||delete c[g];if(h.$ref&&m.def)for(const g in c)g==="$ref"||g==="allOf"||g in m.def&&JSON.stringify(c[g])===JSON.stringify(m.def[g])&&delete c[g]}const f=a._zod.parent;if(f&&f!==d){r(f);const m=e.seen.get(f);if(m?.schema.$ref&&(c.$ref=m.schema.$ref,m.def))for(const h in c)h==="$ref"||h==="allOf"||h in m.def&&JSON.stringify(c[h])===JSON.stringify(m.def[h])&&delete c[h]}e.override({zodSchema:a,jsonSchema:c,path:s.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(const a of[...e.seen.entries()].reverse())r(a[0]);if(e.target!=="openapi-3.0")for(const a of e.seen.entries())compactTypeUnion(a[1].def??a[1].schema);for(const a of e.deferred)a();if(e.intersections.length){const a=new Map;for(const s of e.seen.values())for(const c of[s.schema,s.def]){const l=c?.allOf;if(!Array.isArray(l))continue;const d=a.get(l);d?d.push(c):a.set(l,[c])}for(const s of e.intersections)for(const c of a.get(s)??[])foldIntersection(c)}}const u={};if(e.target==="draft-2020-12"?u.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?u.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?u.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const a=e.external.registry.get(t)?.id;if(!a)throw new Error("Schema is missing an `id` property");u.$id=e.external.uri(a)}assignProps(u,n.defId?n.schema:n.def??n.schema);const i=e.metadataRegistry.get(t)?.id;i!==void 0&&u.id===i&&delete u.id;const o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(const a of e.seen.entries()){const s=a[1];s.def&&s.defId&&(s.def.id===s.defId&&delete s.def.id,assignProp(o,s.defId,s.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target==="draft-2020-12"?u.$defs=o:u.definitions=o);try{const a=JSON.parse(JSON.stringify(u));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:createStandardJSONSchemaMethod(t,"input",e.processors),output:createStandardJSONSchemaMethod(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function isTransforming(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return isTransforming(r.element,n);if(r.type==="set")return isTransforming(r.valueType,n);if(r.type==="lazy")return isTransforming(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault"||r.type==="catch")return isTransforming(r.innerType,n);if(r.type==="intersection")return isTransforming(r.left,n)||isTransforming(r.right,n);if(r.type==="record"||r.type==="map")return isTransforming(r.keyType,n)||isTransforming(r.valueType,n);if(r.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:isTransforming(r.in,n)||isTransforming(r.out,n);if(r.type==="object"){for(const u in r.shape)if(isTransforming(r.shape[u],n))return!0;return!1}if(r.type==="union"){for(const u of r.options)if(isTransforming(u,n))return!0;return!1}if(r.type==="tuple"){for(const u of r.items)if(isTransforming(u,n))return!0;return!!(r.rest&&isTransforming(r.rest,n))}return!1}var createToJSONSchemaMethod=(e,t={})=>n=>{const r=initializeContext({...n,processors:t});return processSchema(e,r),extractDefs(r,e),finalize(r,e)},createStandardJSONSchemaMethod=(e,t,n={})=>r=>{const{libraryOptions:u,target:i}=r??{},o=initializeContext({...u??{},target:i,io:t,processors:n});return processSchema(e,o),extractDefs(o,e),finalize(o,e)},narrowMin=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},narrowMax=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},narrowBoth=(e,t)=>{narrowMin(e,"minimum",t),narrowMax(e,"maximum",t)},addDivisor=(e,t)=>{e.multipleOf??(e.multipleOf=[]),e.multipleOf.includes(t)||e.multipleOf.push(t)},addPattern=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},intersectMime=(e,t)=>{e.mime=e.mime?e.mime.filter(n=>t.includes(n)):[...t]},setFormat=(e,t)=>{e.format=t,t.includes("int")&&(e.isInt=!0)},minContributor=(e,t)=>narrowMin(e,"minimum",t.minimum),maxContributor=(e,t)=>narrowMax(e,"maximum",t.maximum),formatContributor=e=>(t,n)=>{setFormat(t,n.format);const[r,u]=e[n.format];narrowMin(t,"minimum",r),narrowMax(t,"maximum",u)},contributors={greater_than:(e,t)=>narrowMin(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>narrowMax(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>addDivisor(e,t.value),number_format:formatContributor(NUMBER_FORMAT_RANGES),bigint_format:formatContributor(BIGINT_FORMAT_RANGES),min_length:minContributor,max_length:maxContributor,length_equals:(e,t)=>narrowBoth(e,t.length),min_size:minContributor,max_size:maxContributor,size_equals:(e,t)=>narrowBoth(e,t.size),string_format:(e,t)=>{setFormat(e,t.format),t.pattern&&addPattern(e,t.pattern),(t.format==="base64"||t.format==="base64url")&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>intersectMime(e,t.mime)};function aggregateChecks(e){const t={},n=e._zod.def,r=e._zod.traits.has("$ZodCheck")?[e,...n.checks??[]]:n.checks??[];for(const i of r)contributors[i._zod.def.check]?.(t,i._zod.def);const u=e._zod.bag;u.minimum!==void 0&&narrowMin(t,"minimum",u.minimum),u.exclusiveMinimum!==void 0&&narrowMin(t,"exclusiveMinimum",u.exclusiveMinimum),u.maximum!==void 0&&narrowMax(t,"maximum",u.maximum),u.exclusiveMaximum!==void 0&&narrowMax(t,"exclusiveMaximum",u.exclusiveMaximum),u.multipleOf!==void 0&&addDivisor(t,u.multipleOf),u.format!==void 0&&(t.format??(t.format=u.format),u.format.includes("int")&&(t.isInt=!0)),u.mime&&intersectMime(t,u.mime);for(const i of u.patterns??[])addPattern(t,i);return t}var formatMap={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},exactPatterns=new Map([[base64Charset,base64],[base64urlCharset,base64url]]),exactPattern=e=>exactPatterns.get(e)??e,stringProcessor=(e,t,n,r)=>{const u=n;u.type="string";const{minimum:i,maximum:o,format:a,patterns:s,contentEncoding:c,laxFormat:l}=aggregateChecks(e);if(typeof i=="number"&&(u.minLength=i),typeof o=="number"&&(u.maxLength=o),a&&(u.format=formatMap[a]??a,u.format===""&&delete u.format,(a==="time"||l)&&delete u.format),c&&(u.contentEncoding=c),s&&s.size>0){const d=[...s].map(exactPattern);d.length===1?u.pattern=d[0].source:d.length>1&&(u.allOf=[...d.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},numberProcessor=(e,t,n,r)=>{const u=n,{minimum:i,maximum:o,multipleOf:a,exclusiveMaximum:s,exclusiveMinimum:c,isInt:l}=aggregateChecks(e);u.type=l?"integer":"number";const d=typeof c=="number"&&c>=(i??Number.NEGATIVE_INFINITY),f=typeof s=="number"&&s<=(o??Number.POSITIVE_INFINITY),m=t.target==="draft-04"||t.target==="openapi-3.0";if(d?m?(u.minimum=c,u.exclusiveMinimum=!0):u.exclusiveMinimum=c:typeof i=="number"&&(u.minimum=i),f?m?(u.maximum=s,u.exclusiveMaximum=!0):u.exclusiveMaximum=s:typeof o=="number"&&(u.maximum=o),a){const h=new Set;for(const D of a)Number.isFinite(D)&&D!==0?h.add(Math.abs(D)):handleUnrepresentable(e,t,u,r,`A multipleOf divisor of ${D} cannot be represented in JSON Schema`);const[p,...g]=h;p!==void 0&&(u.multipleOf=p),g.length&&(u.allOf=[...u.allOf??[],...g.map(D=>({multipleOf:D}))])}},booleanProcessor=(e,t,n,r)=>{n.type="boolean"},bigintProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"BigInt cannot be represented in JSON Schema")},symbolProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Symbols cannot be represented in JSON Schema")},nullProcessor=(e,t,n,r)=>{t.target==="openapi-3.0"?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"},undefinedProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Undefined cannot be represented in JSON Schema")},voidProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Void cannot be represented in JSON Schema")},neverProcessor=(e,t,n,r)=>{n.not={}},anyProcessor=(e,t,n,r)=>{},unknownProcessor=(e,t,n,r)=>{},dateProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Date cannot be represented in JSON Schema")},enumProcessor=(e,t,n,r)=>{const u=e._zod.def,i=getEnumValues(u.entries);if(i.length===0){n.not={};return}i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},literalProcessor=(e,t,n,r)=>{const u=e._zod.def;if(u.values.length===0){n.not={};return}const i=[];for(const o of u.values)if(o===void 0){if(handleUnrepresentable(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o=="bigint"){if(handleUnrepresentable(e,t,n,r,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},nanProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"NaN cannot be represented in JSON Schema")},templateLiteralProcessor=(e,t,n,r)=>{const u=n,i=e._zod.pattern;if(!i)throw new Error("Pattern not found in template literal");u.type="string",u.pattern=i.source},fileProcessor=(e,t,n,r)=>{const u=n;u.type="string",u.format="binary",u.contentEncoding="binary";const{minimum:i,maximum:o,mime:a}=aggregateChecks(e);i!==void 0&&(u.minLength=i),o!==void 0&&(u.maxLength=o),a&&(a.length===0?u.not={}:a.length===1?u.contentMediaType=a[0]:u.anyOf=a.map(s=>({contentMediaType:s})))},successProcessor=(e,t,n,r)=>{n.type="boolean"},customProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Custom types cannot be represented in JSON Schema")},functionProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Function types cannot be represented in JSON Schema")},transformProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Transforms cannot be represented in JSON Schema")},mapProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Map cannot be represented in JSON Schema")},setProcessor=(e,t,n,r)=>{handleUnrepresentable(e,t,n,r,"Set cannot be represented in JSON Schema")},arrayProcessor=(e,t,n,r)=>{const u=n,i=e._zod.def,{minimum:o,maximum:a}=aggregateChecks(e);typeof o=="number"&&(u.minItems=o),typeof a=="number"&&(u.maxItems=a),u.type="array",u.items=processSchema(i.element,t,{...r,path:[...r.path,"items"]})};function inputOptin(e){const t=e._zod.def;return t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform")?inputOptin(t.out):t.type==="catch"?inputOptin(t.innerType):e._zod.optin}var objectProcessor=(e,t,n,r)=>{const u=n,i=e._zod.def,o=i.shape;if(Object.getOwnPropertySymbols(o).length&&handleUnrepresentable(e,t,u,r,"Symbol keys cannot be represented in JSON Schema"))return;u.type="object",u.properties={};for(const c in o)assignProp(u.properties,c,processSchema(o[c],t,{...r,path:[...r.path,"properties",c]}));const s=[];for(const c of Object.keys(o)){const l=i.shape[c];(t.io==="input"?inputOptin(l)===void 0:l._zod.optout===void 0)&&s.push(c)}s.length>0&&(u.required=s),i.catchall?._zod.def.type==="never"?u.additionalProperties=!1:i.catchall?i.catchall&&(u.additionalProperties=processSchema(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(u.additionalProperties=!1)},unionProcessor=(e,t,n,r)=>{const u=e._zod.def,i=u.inclusive===!1,o=u.options.map((a,s)=>processSchema(a,t,{...r,path:[...r.path,i?"oneOf":"anyOf",s]}));i?n.oneOf=o:n.anyOf=o},intersectionProcessor=(e,t,n,r)=>{const u=e._zod.def,i=processSchema(u.left,t,{...r,path:[...r.path,"allOf",0]}),o=processSchema(u.right,t,{...r,path:[...r.path,"allOf",1]}),a=c=>"allOf"in c&&Object.keys(c).length===1,s=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=s,t.intersections.push(s)},tupleProcessor=(e,t,n,r)=>{const u=n,i=e._zod.def;u.type="array";const o=t.target==="draft-2020-12"?"prefixItems":"items",a=t.target==="draft-2020-12"||t.target==="openapi-3.0"?"items":"additionalItems",s=i.items.map((p,g)=>processSchema(p,t,{...r,path:[...r.path,o,g]})),c=i.rest?processSchema(i.rest,t,{...r,path:[...r.path,a,...t.target==="openapi-3.0"?[i.items.length]:[]]}):null;let l=i.items.length;for(;l>0;){const p=i.items[l-1];if(!(t.io==="input"?inputOptin(p)!==void 0:p._zod.optout==="optional"))break;l--}const d=i.items.length,f=!i.rest;t.target==="draft-2020-12"?(u.prefixItems=s,f?u.items=!1:c&&(u.items=c),l>0&&(u.minItems=l),f&&(u.maxItems=d)):t.target==="openapi-3.0"?(u.items={anyOf:s},c&&u.items.anyOf.push(c),l>0&&(u.minItems=l),f&&(u.maxItems=d)):(u.items=s,f?u.additionalItems=!1:c&&(u.additionalItems=c),l>0&&(u.minItems=l),f&&(u.maxItems=d));const{minimum:m,maximum:h}=aggregateChecks(e);typeof m=="number"&&(u.minItems=m),typeof h=="number"&&(u.maxItems=h)};function stringifyKeyNames(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);const h=e.get(t)?.def;if(!h)return t;const p=stringifyKeyNames(e,h,n);return p===h?t:p}for(const h of["anyOf","oneOf"]){const p=t[h];if(!Array.isArray(p))continue;const g=p.map(D=>stringifyKeyNames(e,D,n));g.some((D,v)=>D!==p[v])&&(t={...t,[h]:g})}const r=Array.isArray(t.type)?t.type:[t.type],u=!r.includes("string")&&r.some(h=>h==="number"||h==="integer"),i=t.enum??(t.const!==void 0?[t.const]:void 0);if(!u&&!i?.some(h=>typeof h=="number"))return t;const{minimum:o,maximum:a,exclusiveMinimum:s,exclusiveMaximum:c,multipleOf:l,format:d,id:f,...m}=t;return m.enum?m.enum=m.enum.map(h=>typeof h=="number"?String(h):h):typeof m.const=="number"&&(m.const=String(m.const)),u&&(m.type="string",i||(m.pattern=(r.includes("number")?number:integer).source)),m}var pendingRecords=new WeakMap;function rewriteKeyNames(e){const t=new Map;for(const r of e.seen.values())r.def&&!t.has(r.schema)&&t.set(r.schema,r);const n=new Map;for(const r of pendingRecords.get(e)??[]){const u=e.seen.get(r),i=(u?.def??u?.schema)?.propertyNames;if(!i||i===!0||n.has(i))continue;const o=stringifyKeyNames(t,i,new Set);o!==i&&n.set(i,o)}if(n.size)for(const r of e.seen.values())for(const u of[r.schema,r.def]){const i=u&&n.get(u.propertyNames);i&&(u.propertyNames=i)}}var recordProcessor=(e,t,n,r)=>{const u=n,i=e._zod.def;u.type="object";const o=i.keyType,a=aggregateChecks(o).patterns;if(i.mode==="loose"&&a&&a.size>0){const l=processSchema(i.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});u.patternProperties={};for(const d of a)assignProp(u.patternProperties,exactPattern(d).source,l)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){u.propertyNames=processSchema(i.keyType,t,{...r,path:[...r.path,"propertyNames"]});let l=pendingRecords.get(t);l||(l=[],pendingRecords.set(t,l),t.deferred.push(()=>rewriteKeyNames(t))),l.push(e)}u.additionalProperties=processSchema(i.valueType,t,{...r,path:[...r.path,"additionalProperties"]})}const s=o._zod.values,c=t.io==="input"&&inputOptin(i.valueType)!==void 0;if(s&&!i.partial&&!c){const l=[...s].filter(d=>typeof d=="string"||typeof d=="number");l.length>0&&(u.required=l.map(String))}},nullableProcessor=(e,t,n,r)=>{const u=e._zod.def,i=processSchema(u.innerType,t,r),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=u.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},nonoptionalProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType},UNREPRESENTABLE_DEFAULT=Symbol();function serializeDefaultValue(e,t,n,r,u){let i=!1;const o=JSON.stringify(e,(a,s)=>typeof s!="bigint"?s:(i=!0,null));return i?(handleUnrepresentable(t,n,r,u,"BigInt defaults cannot be represented in JSON Schema"),UNREPRESENTABLE_DEFAULT):JSON.parse(o)}var defaultProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType;const o=serializeDefaultValue(u.defaultValue,e,t,n,r);o!==UNREPRESENTABLE_DEFAULT&&(n.default=o)},prefaultProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);if(i.ref=u.innerType,t.io!=="input")return;const o=serializeDefaultValue(u.defaultValue,e,t,n,r);o!==UNREPRESENTABLE_DEFAULT&&(n._prefault=o)},catchProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType;let o;try{o=u.catchValue(void 0)}catch{handleUnrepresentable(e,t,n,r,"Dynamic catch values are not supported in JSON Schema");return}n.default=o},pipeProcessor=(e,t,n,r)=>{const u=e._zod.def,i=u.in._zod.traits.has("$ZodTransform"),o=t.io==="input"?i?u.out:u.in:u.out;processSchema(o,t,r);const a=t.seen.get(e);a.ref=o},readonlyProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType,n.readOnly=!0},promiseProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType},optionalProcessor=(e,t,n,r)=>{const u=e._zod.def;processSchema(u.innerType,t,r);const i=t.seen.get(e);i.ref=u.innerType},lazyProcessor=(e,t,n,r)=>{const u=e._zod.innerType;processSchema(u,t,r);const i=t.seen.get(e);i.ref=u},allProcessors={string:stringProcessor,number:numberProcessor,boolean:booleanProcessor,bigint:bigintProcessor,symbol:symbolProcessor,null:nullProcessor,undefined:undefinedProcessor,void:voidProcessor,never:neverProcessor,any:anyProcessor,unknown:unknownProcessor,date:dateProcessor,enum:enumProcessor,literal:literalProcessor,nan:nanProcessor,template_literal:templateLiteralProcessor,file:fileProcessor,success:successProcessor,custom:customProcessor,function:functionProcessor,transform:transformProcessor,map:mapProcessor,set:setProcessor,array:arrayProcessor,object:objectProcessor,union:unionProcessor,intersection:intersectionProcessor,tuple:tupleProcessor,record:recordProcessor,nullable:nullableProcessor,nonoptional:nonoptionalProcessor,default:defaultProcessor,prefault:prefaultProcessor,catch:catchProcessor,pipe:pipeProcessor,readonly:readonlyProcessor,promise:promiseProcessor,optional:optionalProcessor,lazy:lazyProcessor};function toJSONSchema(e,t){if("_idmap"in e){const r=e,u=initializeContext({...t,processors:allProcessors}),i={};for(const s of r._idmap.entries()){const[c,l]=s;processSchema(l,u)}const o={},a={registry:r,uri:t?.uri,defs:i};u.external=a;for(const s of r._idmap.entries()){const[c,l]=s;extractDefs(u,l),assignProp(o,c,finalize(u,l))}if(Object.keys(i).length>0){const s=u.target==="draft-2020-12"?"$defs":"definitions";o.__shared={[s]:i}}return{schemas:o}}const n=initializeContext({...t,processors:allProcessors});return processSchema(e,n),extractDefs(n,e),finalize(n,e)}var JSONSchemaGenerator=class{get metadataRegistry(){return this.ctx.metadataRegistry}get target(){return this.ctx.target}get unrepresentable(){return this.ctx.unrepresentable}get override(){return this.ctx.override}get io(){return this.ctx.io}get counter(){return this.ctx.counter}set counter(e){this.ctx.counter=e}get seen(){return this.ctx.seen}constructor(e){let t=e?.target??"draft-2020-12";t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),this.ctx=initializeContext({processors:allProcessors,target:t,...e?.metadata&&{metadata:e.metadata},...e?.unrepresentable&&{unrepresentable:e.unrepresentable},...e?.override&&{override:e.override},...e?.io&&{io:e.io}})}process(e,t={path:[],schemaPath:[]}){return processSchema(e,this.ctx,t)}emit(e,t){t&&(t.cycles&&(this.ctx.cycles=t.cycles),t.reused&&(this.ctx.reused=t.reused),t.external&&(this.ctx.external=t.external)),this.ctx.sharedDefsExtractedFor=void 0,this.ctx.sharedEmitDoneFor=void 0,extractDefs(this.ctx,e);const n=finalize(this.ctx,e),{"~standard":r,...u}=n;return u}},json_schema_exports={},schemas_exports2={};__export(schemas_exports2,{ZodAny:()=>ZodAny,ZodArray:()=>ZodArray,ZodBase64:()=>ZodBase64,ZodBase64URL:()=>ZodBase64URL,ZodBigInt:()=>ZodBigInt,ZodBigIntFormat:()=>ZodBigIntFormat,ZodBoolean:()=>ZodBoolean,ZodCIDRv4:()=>ZodCIDRv4,ZodCIDRv6:()=>ZodCIDRv6,ZodCUID:()=>ZodCUID,ZodCUID2:()=>ZodCUID2,ZodCatch:()=>ZodCatch,ZodCodec:()=>ZodCodec,ZodCreditCard:()=>ZodCreditCard,ZodCustom:()=>ZodCustom,ZodCustomStringFormat:()=>ZodCustomStringFormat,ZodDate:()=>ZodDate,ZodDefault:()=>ZodDefault,ZodDiscriminatedUnion:()=>ZodDiscriminatedUnion,ZodE164:()=>ZodE164,ZodEmail:()=>ZodEmail,ZodEmoji:()=>ZodEmoji,ZodEnum:()=>ZodEnum,ZodExactOptional:()=>ZodExactOptional,ZodFile:()=>ZodFile,ZodFunction:()=>ZodFunction,ZodGUID:()=>ZodGUID,ZodIBAN:()=>ZodIBAN,ZodIPv4:()=>ZodIPv4,ZodIPv6:()=>ZodIPv6,ZodISODate:()=>ZodISODate,ZodISODateTime:()=>ZodISODateTime,ZodISODuration:()=>ZodISODuration,ZodISOTime:()=>ZodISOTime,ZodInstanceOf:()=>ZodInstanceOf,ZodIntersection:()=>ZodIntersection,ZodJWT:()=>ZodJWT,ZodKSUID:()=>ZodKSUID,ZodLazy:()=>ZodLazy,ZodLiteral:()=>ZodLiteral,ZodMAC:()=>ZodMAC,ZodMap:()=>ZodMap,ZodNaN:()=>ZodNaN,ZodNanoID:()=>ZodNanoID,ZodNever:()=>ZodNever,ZodNonOptional:()=>ZodNonOptional,ZodNull:()=>ZodNull,ZodNullable:()=>ZodNullable,ZodNumber:()=>ZodNumber,ZodNumberFormat:()=>ZodNumberFormat,ZodObject:()=>ZodObject,ZodOptional:()=>ZodOptional,ZodPipe:()=>ZodPipe,ZodPrefault:()=>ZodPrefault,ZodPreprocess:()=>ZodPreprocess,ZodPromise:()=>ZodPromise,ZodReadonly:()=>ZodReadonly,ZodRecord:()=>ZodRecord,ZodSet:()=>ZodSet,ZodString:()=>ZodString,ZodStringFormat:()=>ZodStringFormat,ZodSuccess:()=>ZodSuccess,ZodSymbol:()=>ZodSymbol,ZodTemplateLiteral:()=>ZodTemplateLiteral,ZodTransform:()=>ZodTransform,ZodTuple:()=>ZodTuple,ZodType:()=>ZodType,ZodULID:()=>ZodULID,ZodURL:()=>ZodURL,ZodUUID:()=>ZodUUID,ZodUndefined:()=>ZodUndefined,ZodUnion:()=>ZodUnion,ZodUnknown:()=>ZodUnknown,ZodVoid:()=>ZodVoid,ZodXID:()=>ZodXID,ZodXor:()=>ZodXor,_ZodString:()=>_ZodString,_default:()=>_default2,_function:()=>_function,any:()=>any,array:()=>array,base64:()=>base642,base64url:()=>base64url2,bigint:()=>bigint2,boolean:()=>boolean2,catch:()=>_catch2,check:()=>check,cidrv4:()=>cidrv42,cidrv6:()=>cidrv62,codec:()=>codec,creditCard:()=>creditCard2,cuid:()=>cuid3,cuid2:()=>cuid22,currencyCode:()=>currencyCode2,custom:()=>custom,date:()=>date2,describe:()=>describe2,discriminatedUnion:()=>discriminatedUnion,e164:()=>e1642,email:()=>email2,emoji:()=>emoji2,enum:()=>_enum2,exactOptional:()=>exactOptional,file:()=>file,float32:()=>float32,float64:()=>float64,function:()=>_function,guid:()=>guid2,hash:()=>hash,hex:()=>hex2,hostname:()=>hostname2,httpUrl:()=>httpUrl,iban:()=>iban2,instanceof:()=>_instanceof,int:()=>int,int32:()=>int32,int64:()=>int64,intersection:()=>intersection,invertCodec:()=>invertCodec,ipv4:()=>ipv42,ipv6:()=>ipv62,json:()=>json,jwt:()=>jwt,keyof:()=>keyof,ksuid:()=>ksuid2,lazy:()=>lazy,literal:()=>literal,looseObject:()=>looseObject,looseRecord:()=>looseRecord,mac:()=>mac2,map:()=>map,meta:()=>meta2,nan:()=>nan,nanoid:()=>nanoid2,nativeEnum:()=>nativeEnum,never:()=>never,nonoptional:()=>nonoptional,null:()=>_null3,nullable:()=>nullable,nullish:()=>nullish2,number:()=>number2,object:()=>object,optional:()=>optional,partialRecord:()=>partialRecord,pipe:()=>pipe,prefault:()=>prefault,preprocess:()=>preprocess,promise:()=>promise,readonly:()=>readonly,record:()=>record,refine:()=>refine,set:()=>set,strictObject:()=>strictObject,string:()=>string2,stringFormat:()=>stringFormat,stringbool:()=>stringbool,success:()=>success,superRefine:()=>superRefine,symbol:()=>symbol,templateLiteral:()=>templateLiteral,transform:()=>transform,tuple:()=>tuple,uint32:()=>uint32,uint64:()=>uint64,ulid:()=>ulid2,undefined:()=>_undefined3,union:()=>union,unknown:()=>unknown,url:()=>url,uuid:()=>uuid2,uuidv4:()=>uuidv4,uuidv6:()=>uuidv6,uuidv7:()=>uuidv7,void:()=>_void2,xid:()=>xid2,xor:()=>xor});var checks_exports2={};__export(checks_exports2,{endsWith:()=>_endsWith,gt:()=>_gt,gte:()=>_gte,includes:()=>_includes,length:()=>_length,lowercase:()=>_lowercase,lt:()=>_lt,lte:()=>_lte,maxLength:()=>_maxLength,maxSize:()=>_maxSize,mime:()=>_mime,minLength:()=>_minLength,minSize:()=>_minSize,multipleOf:()=>_multipleOf,negative:()=>_negative,nonnegative:()=>_nonnegative,nonpositive:()=>_nonpositive,normalize:()=>_normalize,overwrite:()=>_overwrite,positive:()=>_positive,properties:()=>_properties,property:()=>_property,regex:()=>_regex,size:()=>_size,slugify:()=>_slugify,startsWith:()=>_startsWith,toLowerCase:()=>_toLowerCase,toUpperCase:()=>_toUpperCase,trim:()=>_trim,uppercase:()=>_uppercase});var _installedErrorProtos=new WeakSet([Object.prototype,Error.prototype]);function _lazyMethod(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){const r=n(this);return Object.defineProperty(this,t,{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,t,{value:r,configurable:!0,writable:!0})}})}var initializer2=(e,t)=>{$ZodError.init(e,t),e.name="ZodError";const n=Object.getPrototypeOf(e);_installedErrorProtos.has(n)||(_installedErrorProtos.add(n),_lazyMethod(n,"format",r=>u=>formatError(r,u)),_lazyMethod(n,"flatten",r=>u=>flattenError(r,u)),_lazyMethod(n,"addIssue",r=>u=>{r.issues.push(u),r.message=JSON.stringify(r.issues,jsonStringifyReplacer,2)}),_lazyMethod(n,"addIssues",r=>u=>{r.issues.push(...u),r.message=JSON.stringify(r.issues,jsonStringifyReplacer,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},ZodError=$constructor("ZodError",initializer2),ZodRealError=$constructor("ZodError",initializer2,void 0,{Parent:Error}),parse2=_parse(ZodRealError),parseAsync2=_parseAsync(ZodRealError),safeParse2=_safeParse(ZodRealError),safeParseAsync2=_safeParseAsync(ZodRealError),encode2=_encode(ZodRealError),decode2=_decode(ZodRealError),encodeAsync2=_encodeAsync(ZodRealError),decodeAsync2=_decodeAsync(ZodRealError),safeEncode2=_safeEncode(ZodRealError),safeDecode2=_safeDecode(ZodRealError),safeEncodeAsync2=_safeEncodeAsync(ZodRealError),safeDecodeAsync2=_safeDecodeAsync(ZodRealError);function _ensureDefaultLocale(){globalConfig.localeError||config(en_default())}function _ensureDefaultMemoizer(){globalConfig.memoizer||config({memoizer:memoizer()})}var ZodType=$constructor("ZodType",(e,t)=>(_ensureDefaultLocale(),$ZodType.init(e,t),e.def=t,e.type=t.type,e),{check(...e){const t=this.def;return this.clone(util_exports.mergeDefs(t,{checks:[...t.checks??[],...e.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return clone(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(refine(e,t))},superRefine(e,t){return this.check(superRefine(e,t))},overwrite(e){return this.check(_overwrite(e))},optional(){return optional(this)},exactOptional(){return exactOptional(this)},nullable(){return nullable(this)},nullish(){return optional(nullable(this))},nonoptional(e){return nonoptional(this,e)},array(){return array(this)},or(e){return union([this,e])},and(e){return intersection(this,e)},transform(e){return pipe(this,transform(e))},default(e){return _default2(this,e)},prefault(e){return prefault(this,e)},catch(e){return _catch2(this,e)},pipe(e){return pipe(this,e)},readonly(){return readonly(this)},describe(e){const t=this.clone();return globalRegistry.add(t,{description:e}),t},meta(...e){if(e.length===0)return globalRegistry.get(this);const t=this.clone();return globalRegistry.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return util_exports.hide(this,"~standard",{...standardProps(this),jsonSchema:{input:createStandardJSONSchemaMethod(this,"input"),output:createStandardJSONSchemaMethod(this,"output")}})},set"~standard"(e){util_exports.own(this,"~standard",e)},parse:function e(t,n){return parse2(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await parseAsync2(this,t,n,{callee:e})},safeParse(e,t){return safeParse2(this,e,t)},async safeParseAsync(e,t){return safeParseAsync2(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){util_exports.own(this,"spa",e)},validate(e,t){return validate(this,e,t)},validateAsync(e,t){return validateAsync(this,e,t)},encode:function e(t,n){return encode2(this,t,n,{callee:e})},decode:function e(t,n){return decode2(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await encodeAsync2(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await decodeAsync2(this,t,n,{callee:e})},safeEncode(e,t){return safeEncode2(this,e,t)},safeDecode(e,t){return safeDecode2(this,e,t)},async safeEncodeAsync(e,t){return safeEncodeAsync2(this,e,t)},async safeDecodeAsync(e,t){return safeDecodeAsync2(this,e,t)},toJSONSchema(e){return createToJSONSchemaMethod(this,{})(e)},get description(){return globalRegistry.get(this)?.description},get _def(){return this._zod.def}}),_ZodString=$constructor("_ZodString",(e,t)=>{$ZodString.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>stringProcessor(e,n,r,u)},util_exports.derived({format:e=>aggregateChecks(e).format??null,minLength:e=>aggregateChecks(e).minimum??null,maxLength:e=>aggregateChecks(e).maximum??null},{regex(...e){return this.check(_regex(...e))},includes(...e){return this.check(_includes(...e))},startsWith(...e){return this.check(_startsWith(...e))},endsWith(...e){return this.check(_endsWith(...e))},min(...e){return this.check(_minLength(...e))},max(...e){return this.check(_maxLength(...e))},length(...e){return this.check(_length(...e))},nonempty(...e){return this.check(_minLength(1,...e))},lowercase(e){return this.check(_lowercase(e))},uppercase(e){return this.check(_uppercase(e))},trim(){return this.check(_trim())},normalize(...e){return this.check(_normalize(...e))},toLowerCase(){return this.check(_toLowerCase())},toUpperCase(){return this.check(_toUpperCase())},slugify(){return this.check(_slugify())}})),ZodString=$constructor("ZodString",(e,t)=>{$ZodString.init(e,t),_ZodString.init(e,t)},{email(e){return this.check(_email(ZodEmail,e))},url(e){return this.check(_url(ZodURL,e))},jwt(e){return this.check(_jwt(ZodJWT,e))},emoji(e){return this.check(_emoji2(ZodEmoji,e))},guid(e){return this.check(_guid(ZodGUID,e))},uuid(e){return this.check(_uuid(ZodUUID,e))},uuidv4(e){return this.check(_uuidv4(ZodUUID,e))},uuidv6(e){return this.check(_uuidv6(ZodUUID,e))},uuidv7(e){return this.check(_uuidv7(ZodUUID,e))},nanoid(e){return this.check(_nanoid(ZodNanoID,e))},cuid(e){return this.check(_cuid(ZodCUID,e))},cuid2(e){return this.check(_cuid2(ZodCUID2,e))},ulid(e){return this.check(_ulid(ZodULID,e))},base64(e){return this.check(_base64(ZodBase64,e))},base64url(e){return this.check(_base64url(ZodBase64URL,e))},xid(e){return this.check(_xid(ZodXID,e))},ksuid(e){return this.check(_ksuid(ZodKSUID,e))},ipv4(e){return this.check(_ipv4(ZodIPv4,e))},ipv6(e){return this.check(_ipv6(ZodIPv6,e))},cidrv4(e){return this.check(_cidrv4(ZodCIDRv4,e))},cidrv6(e){return this.check(_cidrv6(ZodCIDRv6,e))},e164(e){return this.check(_e164(ZodE164,e))},datetime(e){return this.check(_isoDateTime(ZodISODateTime,e))},date(e){return this.check(_isoDate(ZodISODate,e))},time(e){return this.check(_isoTime(ZodISOTime,e))},duration(e){return this.check(_isoDuration(ZodISODuration,e))}});function string2(e){return _string(ZodString,e)}var ZodStringFormat=$constructor("ZodStringFormat",(e,t)=>{$ZodStringFormat.init(e,t),_ZodString.init(e,t)}),ZodISODateTime=$constructor("ZodISODateTime",(e,t)=>{$ZodISODateTime.init(e,t),ZodStringFormat.init(e,t)}),ZodISODate=$constructor("ZodISODate",(e,t)=>{$ZodISODate.init(e,t),ZodStringFormat.init(e,t)}),ZodISOTime=$constructor("ZodISOTime",(e,t)=>{$ZodISOTime.init(e,t),ZodStringFormat.init(e,t)}),ZodISODuration=$constructor("ZodISODuration",(e,t)=>{$ZodISODuration.init(e,t),ZodStringFormat.init(e,t)}),ZodEmail=$constructor("ZodEmail",(e,t)=>{$ZodEmail.init(e,t),ZodStringFormat.init(e,t)});function email2(e){return _email(ZodEmail,e)}var ZodGUID=$constructor("ZodGUID",(e,t)=>{$ZodGUID.init(e,t),ZodStringFormat.init(e,t)});function guid2(e){return _guid(ZodGUID,e)}var ZodUUID=$constructor("ZodUUID",(e,t)=>{$ZodUUID.init(e,t),ZodStringFormat.init(e,t)});function uuid2(e){return _uuid(ZodUUID,e)}function uuidv4(e){return _uuidv4(ZodUUID,e)}function uuidv6(e){return _uuidv6(ZodUUID,e)}function uuidv7(e){return _uuidv7(ZodUUID,e)}var ZodURL=$constructor("ZodURL",(e,t)=>{$ZodURL.init(e,t),ZodStringFormat.init(e,t)});function url(e){return _url(ZodURL,e)}function httpUrl(e){return _url(ZodURL,{protocol:httpProtocol,hostname:domain,...util_exports.normalizeParams(e)})}var ZodEmoji=$constructor("ZodEmoji",(e,t)=>{$ZodEmoji.init(e,t),ZodStringFormat.init(e,t)});function emoji2(e){return _emoji2(ZodEmoji,e)}var ZodNanoID=$constructor("ZodNanoID",(e,t)=>{$ZodNanoID.init(e,t),ZodStringFormat.init(e,t)});function nanoid2(e){return _nanoid(ZodNanoID,e)}var ZodCUID=$constructor("ZodCUID",(e,t)=>{$ZodCUID.init(e,t),ZodStringFormat.init(e,t)});function cuid3(e){return _cuid(ZodCUID,e)}var ZodCUID2=$constructor("ZodCUID2",(e,t)=>{$ZodCUID2.init(e,t),ZodStringFormat.init(e,t)});function cuid22(e){return _cuid2(ZodCUID2,e)}var ZodULID=$constructor("ZodULID",(e,t)=>{$ZodULID.init(e,t),ZodStringFormat.init(e,t)});function ulid2(e){return _ulid(ZodULID,e)}var ZodXID=$constructor("ZodXID",(e,t)=>{$ZodXID.init(e,t),ZodStringFormat.init(e,t)});function xid2(e){return _xid(ZodXID,e)}var ZodKSUID=$constructor("ZodKSUID",(e,t)=>{$ZodKSUID.init(e,t),ZodStringFormat.init(e,t)});function ksuid2(e){return _ksuid(ZodKSUID,e)}var ZodIPv4=$constructor("ZodIPv4",(e,t)=>{$ZodIPv4.init(e,t),ZodStringFormat.init(e,t)});function ipv42(e){return _ipv4(ZodIPv4,e)}var ZodMAC=$constructor("ZodMAC",(e,t)=>{$ZodMAC.init(e,t),ZodStringFormat.init(e,t)});function mac2(e){return _mac(ZodMAC,e)}var ZodIPv6=$constructor("ZodIPv6",(e,t)=>{$ZodIPv6.init(e,t),ZodStringFormat.init(e,t)});function ipv62(e){return _ipv6(ZodIPv6,e)}var ZodCIDRv4=$constructor("ZodCIDRv4",(e,t)=>{$ZodCIDRv4.init(e,t),ZodStringFormat.init(e,t)});function cidrv42(e){return _cidrv4(ZodCIDRv4,e)}var ZodCIDRv6=$constructor("ZodCIDRv6",(e,t)=>{$ZodCIDRv6.init(e,t),ZodStringFormat.init(e,t)});function cidrv62(e){return _cidrv6(ZodCIDRv6,e)}var ZodBase64=$constructor("ZodBase64",(e,t)=>{$ZodBase64.init(e,t),ZodStringFormat.init(e,t)});function base642(e){return _base64(ZodBase64,e)}var ZodBase64URL=$constructor("ZodBase64URL",(e,t)=>{$ZodBase64URL.init(e,t),ZodStringFormat.init(e,t)});function base64url2(e){return _base64url(ZodBase64URL,e)}var ZodE164=$constructor("ZodE164",(e,t)=>{$ZodE164.init(e,t),ZodStringFormat.init(e,t)});function e1642(e){return _e164(ZodE164,e)}var ZodCreditCard=$constructor("ZodCreditCard",(e,t)=>{$ZodCreditCard.init(e,t),ZodStringFormat.init(e,t)});function creditCard2(e){return _creditCard(ZodCreditCard,e)}var ZodIBAN=$constructor("ZodIBAN",(e,t)=>{$ZodIBAN.init(e,t),ZodStringFormat.init(e,t)});function iban2(e){return _iban(ZodIBAN,e)}var ZodJWT=$constructor("ZodJWT",(e,t)=>{$ZodJWT.init(e,t),ZodStringFormat.init(e,t)});function jwt(e){return _jwt(ZodJWT,e)}var ZodCustomStringFormat=$constructor("ZodCustomStringFormat",(e,t)=>{$ZodCustomStringFormat.init(e,t),ZodStringFormat.init(e,t)});function stringFormat(e,t,n={}){return _stringFormat(ZodCustomStringFormat,e,t,n)}function hostname2(e){return _stringFormat(ZodCustomStringFormat,"hostname",hostname,e)}function hex2(e){return _stringFormat(ZodCustomStringFormat,"hex",hex,e)}function currencyCode2(e){return _stringFormat(ZodCustomStringFormat,"currency_code",currencyCode,e)}function hash(e,t){const n=t?.enc??"hex",r=`${e}_${n}`,u=regexes_exports[r];if(!u)throw new Error(`Unrecognized hash format: ${r}`);return _stringFormat(ZodCustomStringFormat,r,u,t)}var ZodNumber=$constructor("ZodNumber",(e,t)=>{$ZodNumber.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>numberProcessor(e,n,r,u),e.isFinite=!0},util_exports.derived({minValue:e=>{const{minimum:t,exclusiveMinimum:n}=aggregateChecks(e);return Math.max(t??Number.NEGATIVE_INFINITY,n??Number.NEGATIVE_INFINITY)},maxValue:e=>{const{maximum:t,exclusiveMaximum:n}=aggregateChecks(e);return Math.min(t??Number.POSITIVE_INFINITY,n??Number.POSITIVE_INFINITY)},isInt:e=>{const{isInt:t,multipleOf:n}=aggregateChecks(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>aggregateChecks(e).format??null},{gt(e,t){return this.check(_gt(e,t))},gte(e,t){return this.check(_gte(e,t))},min(e,t){return this.check(_gte(e,t))},lt(e,t){return this.check(_lt(e,t))},lte(e,t){return this.check(_lte(e,t))},max(e,t){return this.check(_lte(e,t))},int(e){return this.check(int(e))},safe(e){return this.check(int(e))},positive(e){return this.check(_gt(0,e))},nonnegative(e){return this.check(_gte(0,e))},negative(e){return this.check(_lt(0,e))},nonpositive(e){return this.check(_lte(0,e))},multipleOf(e,t){return this.check(_multipleOf(e,t))},step(e,t){return this.check(_multipleOf(e,t))},finite(){return this}}));function number2(e){return _number(ZodNumber,e)}var ZodNumberFormat=$constructor("ZodNumberFormat",(e,t)=>{$ZodNumberFormat.init(e,t),ZodNumber.init(e,t)});function int(e){return _int(ZodNumberFormat,e)}function float32(e){return _float32(ZodNumberFormat,e)}function float64(e){return _float64(ZodNumberFormat,e)}function int32(e){return _int32(ZodNumberFormat,e)}function uint32(e){return _uint32(ZodNumberFormat,e)}var ZodBoolean=$constructor("ZodBoolean",(e,t)=>{$ZodBoolean.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>booleanProcessor(e,n,r,u)});function boolean2(e){return _boolean(ZodBoolean,e)}var ZodBigInt=$constructor("ZodBigInt",(e,t)=>{$ZodBigInt.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>bigintProcessor(e,n,r,u)},util_exports.derived({minValue:e=>aggregateChecks(e).minimum??null,maxValue:e=>aggregateChecks(e).maximum??null,format:e=>aggregateChecks(e).format??null},{gte(e,t){return this.check(_gte(e,t))},min(e,t){return this.check(_gte(e,t))},gt(e,t){return this.check(_gt(e,t))},lt(e,t){return this.check(_lt(e,t))},lte(e,t){return this.check(_lte(e,t))},max(e,t){return this.check(_lte(e,t))},positive(e){return this.check(_gt(BigInt(0),e))},negative(e){return this.check(_lt(BigInt(0),e))},nonpositive(e){return this.check(_lte(BigInt(0),e))},nonnegative(e){return this.check(_gte(BigInt(0),e))},multipleOf(e,t){return this.check(_multipleOf(e,t))}}));function bigint2(e){return _bigint(ZodBigInt,e)}var ZodBigIntFormat=$constructor("ZodBigIntFormat",(e,t)=>{$ZodBigIntFormat.init(e,t),ZodBigInt.init(e,t)});function int64(e){return _int64(ZodBigIntFormat,e)}function uint64(e){return _uint64(ZodBigIntFormat,e)}var ZodSymbol=$constructor("ZodSymbol",(e,t)=>{$ZodSymbol.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>symbolProcessor(e,n,r,u)});function symbol(e){return _symbol(ZodSymbol,e)}var ZodUndefined=$constructor("ZodUndefined",(e,t)=>{$ZodUndefined.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>undefinedProcessor(e,n,r,u)});function _undefined3(e){return _undefined2(ZodUndefined,e)}var ZodNull=$constructor("ZodNull",(e,t)=>{$ZodNull.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>nullProcessor(e,n,r,u)});function _null3(e){return _null2(ZodNull,e)}var ZodAny=$constructor("ZodAny",(e,t)=>{$ZodAny.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>anyProcessor(e,n,r,u)});function any(){return _any(ZodAny)}var ZodUnknown=$constructor("ZodUnknown",(e,t)=>{$ZodUnknown.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>unknownProcessor(e,n,r,u)});function unknown(){return _unknown(ZodUnknown)}var ZodNever=$constructor("ZodNever",(e,t)=>{$ZodNever.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>neverProcessor(e,n,r,u)});function never(e){return _never(ZodNever,e)}var ZodVoid=$constructor("ZodVoid",(e,t)=>{$ZodVoid.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>voidProcessor(e,n,r,u)});function _void2(e){return _void(ZodVoid,e)}var ZodDate=$constructor("ZodDate",(e,t)=>{$ZodDate.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>dateProcessor(e,n,r,u),e.min=(n,r)=>e.check(_gte(n,r)),e.max=(n,r)=>e.check(_lte(n,r))},util_exports.derived({minDate:e=>{const{minimum:t}=aggregateChecks(e);return t?new Date(t):null},maxDate:e=>{const{maximum:t}=aggregateChecks(e);return t?new Date(t):null}},{}));function date2(e){return _date(ZodDate,e)}var ZodArray=$constructor("ZodArray",(e,t)=>{_ensureDefaultMemoizer(),$ZodArray.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>arrayProcessor(e,n,r,u),e.element=t.element},{min(e,t){return this.check(_minLength(e,t))},nonempty(e){return this.check(_minLength(1,e))},max(e,t){return this.check(_maxLength(e,t))},length(e,t){return this.check(_length(e,t))},unwrap(){return this.element}});function array(e,t){return _array(ZodArray,e,t)}function keyof(e){const t=e._zod.def.shape;return _enum2(Object.keys(t))}var ZodObject=$constructor("ZodObject",(e,t)=>{_ensureDefaultMemoizer(),$ZodObjectJIT.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>objectProcessor(e,n,r,u),util_exports.installLazyProp(e,"shape",n=>n._zod.def.shape,!1)},{keyof(){return _enum2(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(util_exports.mergeDefs(this._zod.def,{catchall:e}))},passthrough(){return this.clone(util_exports.mergeDefs(this._zod.def,{catchall:unknown()}))},loose(){return this.clone(util_exports.mergeDefs(this._zod.def,{catchall:unknown()}))},strict(){return this.clone(util_exports.mergeDefs(this._zod.def,{catchall:never()}))},strip(){return this.clone(util_exports.mergeDefs(this._zod.def,{catchall:void 0}))},extend(e){return util_exports.extend(this,e)},safeExtend(e){return util_exports.safeExtend(this,e)},merge(e){return util_exports.merge(this,e)},pick(e){return util_exports.pick(this,e)},omit(e){return util_exports.omit(this,e)},partial(...e){return util_exports.partial(ZodOptional,this,e[0])},exactPartial(...e){return util_exports.partial(ZodExactOptional,this,e[0],"exactPartial")},required(...e){return util_exports.required(ZodNonOptional,this,e[0])}});function object(e,t){const n={type:"object",shape:e??{},...util_exports.normalizeParams(t)};return new ZodObject(n)}function strictObject(e,t){return new ZodObject({type:"object",shape:e,catchall:never(),...util_exports.normalizeParams(t)})}function looseObject(e,t){return new ZodObject({type:"object",shape:e,catchall:unknown(),...util_exports.normalizeParams(t)})}var ZodUnion=$constructor("ZodUnion",(e,t)=>{$ZodUnion.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>unionProcessor(e,n,r,u),e.options=t.options});function union(e,t){return new ZodUnion({type:"union",options:e,...util_exports.normalizeParams(t)})}var ZodXor=$constructor("ZodXor",(e,t)=>{ZodUnion.init(e,t),$ZodXor.init(e,t),e._zod.processJSONSchema=(n,r,u)=>unionProcessor(e,n,r,u),e.options=t.options});function xor(e,t){return new ZodXor({type:"union",options:e,inclusive:!1,...util_exports.normalizeParams(t)})}var ZodDiscriminatedUnion=$constructor("ZodDiscriminatedUnion",(e,t)=>{ZodUnion.init(e,t),$ZodDiscriminatedUnion.init(e,t)});function discriminatedUnion(e,t,n){return new ZodDiscriminatedUnion({type:"union",options:t,discriminator:e,...util_exports.normalizeParams(n)})}var ZodIntersection=$constructor("ZodIntersection",(e,t)=>{$ZodIntersection.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>intersectionProcessor(e,n,r,u)});function intersection(e,t){return new ZodIntersection({type:"intersection",left:e,right:t})}var ZodTuple=$constructor("ZodTuple",(e,t)=>{_ensureDefaultMemoizer(),$ZodTuple.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>tupleProcessor(e,n,r,u)},{rest(e){return this.clone({...this._zod.def,rest:e})},partial(){const e=this._zod.def;if(e.checks?.length)throw new Error(".partial() cannot be used on tuple schemas containing refinements");return this.clone({...e,items:e.items.map(t=>new ZodOptional({type:"optional",innerType:t}))})}});function tuple(e,t,n){const r=t instanceof $ZodType,u=r?n:t,i=r?t:null;return new ZodTuple({type:"tuple",items:e,rest:i,...util_exports.normalizeParams(u)})}var ZodRecord=$constructor("ZodRecord",(e,t)=>{_ensureDefaultMemoizer(),$ZodRecord.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>recordProcessor(e,n,r,u),e.keyType=t.keyType,e.valueType=t.valueType});function record(e,t,n){return!t||!t._zod?new ZodRecord({type:"record",keyType:string2(),valueType:e,...util_exports.normalizeParams(t)}):new ZodRecord({type:"record",keyType:e,valueType:t,...util_exports.normalizeParams(n)})}function partialRecord(e,t,n){return new ZodRecord({type:"record",keyType:e,valueType:t,...util_exports.normalizeParams(n),partial:!0})}function looseRecord(e,t,n){return new ZodRecord({type:"record",keyType:e,valueType:t,mode:"loose",...util_exports.normalizeParams(n)})}var ZodMap=$constructor("ZodMap",(e,t)=>{_ensureDefaultMemoizer(),$ZodMap.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>mapProcessor(e,n,r,u),e.keyType=t.keyType,e.valueType=t.valueType,e.min=(...n)=>e.check(_minSize(...n)),e.nonempty=n=>e.check(_minSize(1,n)),e.max=(...n)=>e.check(_maxSize(...n)),e.size=(...n)=>e.check(_size(...n))});function map(e,t,n){return new ZodMap({type:"map",keyType:e,valueType:t,...util_exports.normalizeParams(n)})}var ZodSet=$constructor("ZodSet",(e,t)=>{_ensureDefaultMemoizer(),$ZodSet.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>setProcessor(e,n,r,u),e.min=(...n)=>e.check(_minSize(...n)),e.nonempty=n=>e.check(_minSize(1,n)),e.max=(...n)=>e.check(_maxSize(...n)),e.size=(...n)=>e.check(_size(...n))});function set(e,t){return new ZodSet({type:"set",valueType:e,...util_exports.normalizeParams(t)})}var ZodEnum=$constructor("ZodEnum",(e,t)=>{$ZodEnum.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(r,u,i)=>enumProcessor(e,r,u,i),e.enum=t.entries,e.options=[...e._zod.values];const n=new Set(Object.keys(t.entries));e.extract=(r,u)=>{const i={};for(const o of r)if(n.has(o))i[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new ZodEnum({...t,checks:[],...util_exports.normalizeParams(u),entries:i})},e.exclude=(r,u)=>{const i={...t.entries};for(const o of r)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new ZodEnum({...t,checks:[],...util_exports.normalizeParams(u),entries:i})}});function _enum2(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new ZodEnum({type:"enum",entries:n,...util_exports.normalizeParams(t)})}function nativeEnum(e,t){return new ZodEnum({type:"enum",entries:e,...util_exports.normalizeParams(t)})}var ZodLiteral=$constructor("ZodLiteral",(e,t)=>{$ZodLiteral.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>literalProcessor(e,n,r,u),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function literal(e,t){return new ZodLiteral({type:"literal",values:Array.isArray(e)?e:[e],...util_exports.normalizeParams(t)})}var ZodFile=$constructor("ZodFile",(e,t)=>{$ZodFile.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>fileProcessor(e,n,r,u),e.min=(n,r)=>e.check(_minSize(n,r)),e.max=(n,r)=>e.check(_maxSize(n,r)),e.mime=(n,r)=>e.check(_mime(Array.isArray(n)?n:[n],r))});function file(e){return _file(ZodFile,e)}var ZodTransform=$constructor("ZodTransform",(e,t)=>{_ensureDefaultMemoizer(),$ZodTransform.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>transformProcessor(e,n,r,u),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new $ZodEncodeError(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(util_exports.issue(i,n.value,t));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),"input"in o||(o.input=n.value),o.inst??(o.inst=e),n.issues.push(util_exports.issue(o))}};const u=t.transform(n.value,n);return u instanceof Promise?u.then(i=>(n.value=i,n)):(n.value=u,n)}});function transform(e){return new ZodTransform({type:"transform",transform:e})}var ZodOptional=$constructor("ZodOptional",(e,t)=>{$ZodOptional.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>optionalProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function optional(e){return new ZodOptional({type:"optional",innerType:e})}var ZodExactOptional=$constructor("ZodExactOptional",(e,t)=>{$ZodExactOptional.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>optionalProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function exactOptional(e){return new ZodExactOptional({type:"optional",innerType:e})}var ZodNullable=$constructor("ZodNullable",(e,t)=>{$ZodNullable.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>nullableProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function nullable(e){return new ZodNullable({type:"nullable",innerType:e})}function nullish2(e){return optional(nullable(e))}var ZodDefault=$constructor("ZodDefault",(e,t)=>{$ZodDefault.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>defaultProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function _default2(e,t){return new ZodDefault({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():util_exports.shallowClone(t)}})}var ZodPrefault=$constructor("ZodPrefault",(e,t)=>{$ZodPrefault.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>prefaultProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function prefault(e,t){return new ZodPrefault({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():util_exports.shallowClone(t)}})}var ZodNonOptional=$constructor("ZodNonOptional",(e,t)=>{$ZodNonOptional.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>nonoptionalProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function nonoptional(e,t){return new ZodNonOptional({type:"nonoptional",innerType:e,...util_exports.normalizeParams(t)})}var ZodSuccess=$constructor("ZodSuccess",(e,t)=>{$ZodSuccess.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>successProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function success(e){return new ZodSuccess({type:"success",innerType:e})}var ZodCatch=$constructor("ZodCatch",(e,t)=>{$ZodCatch.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>catchProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function _catch2(e,t){return new ZodCatch({type:"catch",innerType:e,catchValue:typeof t=="function"?t:util_exports.constantCatch(t)})}var ZodNaN=$constructor("ZodNaN",(e,t)=>{$ZodNaN.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>nanProcessor(e,n,r,u)});function nan(e){return _nan(ZodNaN,e)}var ZodPipe=$constructor("ZodPipe",(e,t)=>{$ZodPipe.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>pipeProcessor(e,n,r,u),e.in=t.in,e.out=t.out});function pipe(e,t){return new ZodPipe({type:"pipe",in:e,out:t})}var ZodCodec=$constructor("ZodCodec",(e,t)=>{ZodPipe.init(e,t),$ZodCodec.init(e,t)});function codec(e,t,n){return new ZodCodec({type:"pipe",in:e,out:t,transform:n.decode,reverseTransform:n.encode})}function invertCodec(e){const t=e._zod.def;return new ZodCodec({type:"pipe",in:t.out,out:t.in,transform:t.reverseTransform,reverseTransform:t.transform})}var ZodPreprocess=$constructor("ZodPreprocess",(e,t)=>{ZodPipe.init(e,t),$ZodPreprocess.init(e,t)}),ZodReadonly=$constructor("ZodReadonly",(e,t)=>{$ZodReadonly.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>readonlyProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function readonly(e){return new ZodReadonly({type:"readonly",innerType:e})}var ZodTemplateLiteral=$constructor("ZodTemplateLiteral",(e,t)=>{$ZodTemplateLiteral.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>templateLiteralProcessor(e,n,r,u)});function templateLiteral(e,t){return new ZodTemplateLiteral({type:"template_literal",parts:e,...util_exports.normalizeParams(t)})}var ZodLazy=$constructor("ZodLazy",(e,t)=>{$ZodLazy.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>lazyProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.getter()});function lazy(e){return new ZodLazy({type:"lazy",getter:e})}var ZodPromise=$constructor("ZodPromise",(e,t)=>{$ZodPromise.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>promiseProcessor(e,n,r,u),e.unwrap=()=>e._zod.def.innerType});function promise(e){return new ZodPromise({type:"promise",innerType:e})}var ZodFunction=$constructor("ZodFunction",(e,t)=>{$ZodFunction.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>functionProcessor(e,n,r,u)});function _function(e){return new ZodFunction({type:"function",input:Array.isArray(e?.input)?tuple(e?.input):e?.input??array(unknown()),output:e?.output??unknown()})}var ZodCustom=$constructor("ZodCustom",(e,t)=>{$ZodCustom.init(e,t),ZodType.init(e,t),e._zod.processJSONSchema=(n,r,u)=>customProcessor(e,n,r,u)});function check(e){const t=new $ZodCheck({check:"custom"});return t._zod.check=e,t}function custom(e,t){return _custom(ZodCustom,e??(()=>!0),t)}function refine(e,t={}){return _refine(ZodCustom,e,t)}function superRefine(e,t){return _superRefine(e,t)}var describe2=describe,meta2=meta,ZodInstanceOf=$constructor("ZodInstanceOf",(e,t)=>{ZodCustom.init(e,t)},{properties(e,t){return this.check(_properties(e,t))}});function _instanceof(e,t={}){const n=new ZodInstanceOf({type:"custom",check:"custom",fn:r=>r instanceof e,abort:!0,...util_exports.normalizeParams(t)});return n._zod.bag.Class=e,n._zod.check=r=>{r.value instanceof e||r.issues.push({code:"invalid_type",expected:e.name,input:r.value,inst:n,path:[...n._zod.def.path??[]]})},n}var stringbool=(...e)=>_stringbool({Codec:ZodCodec,Boolean:ZodBoolean,String:ZodString},...e);function json(e){const t=lazy(()=>union([string2(e),number2(),boolean2(),_null3(),array(t),record(string2(),t)]));return t}function preprocess(e,t){return new ZodPreprocess({type:"pipe",in:transform(e),out:t})}var ZodIssueCode={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"};function setErrorMap(e){config({customError:e})}function getErrorMap(){return config().customError}var ZodFirstPartyTypeKind;ZodFirstPartyTypeKind||(ZodFirstPartyTypeKind={});var iso_exports={};__export(iso_exports,{ZodISODate:()=>ZodISODate,ZodISODateTime:()=>ZodISODateTime,ZodISODuration:()=>ZodISODuration,ZodISOTime:()=>ZodISOTime,date:()=>date3,datetime:()=>datetime2,duration:()=>duration2,time:()=>time2});function datetime2(e){return _isoDateTime(ZodISODateTime,e)}function date3(e){return _isoDate(ZodISODate,e)}function time2(e){return _isoTime(ZodISOTime,e)}function duration2(e){return _isoDuration(ZodISODuration,e)}var z={...schemas_exports2,...checks_exports2,iso:iso_exports},RECOGNIZED_KEYS=new Set(["$schema","$ref","$defs","definitions","$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor","type","enum","const","anyOf","oneOf","allOf","not","properties","required","additionalProperties","patternProperties","propertyNames","minProperties","maxProperties","items","prefixItems","additionalItems","minItems","maxItems","uniqueItems","contains","minContains","maxContains","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","description","default","contentEncoding","contentMediaType","contentSchema","unevaluatedItems","unevaluatedProperties","if","then","else","dependentSchemas","dependentRequired","nullable","readOnly"]);function detectVersion(e,t){const n=e.$schema;return n==="https://json-schema.org/draft/2020-12/schema"?"draft-2020-12":n==="http://json-schema.org/draft-07/schema#"?"draft-7":n==="http://json-schema.org/draft-04/schema#"?"draft-4":t??"draft-2020-12"}function applyMinItems(e,t){return e.map((n,r)=>r<t?n:n.optional())}function decodeJSONPointerSegment(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function resolveRef(e,t){if(!e.startsWith("#"))throw new Error("External $ref is not supported, only local refs (#/...) are allowed");const n=e.slice(1).split("/").filter(Boolean);if(n.length===0)return t.rootSchema;const r=t.version==="draft-2020-12"?"$defs":"definitions";if(n[0]===r){const u=n[1]===void 0?void 0:decodeJSONPointerSegment(n[1]);if(!u||!t.defs[u])throw new Error(`Reference not found: ${e}`);return t.defs[u]}throw new Error(`Reference not found: ${e}`)}function checkObjectGuards(e,t){return z.transform(r=>r).check(r=>{const u=r.value;if(typeof u!="object"||u===null||Array.isArray(u))return;const i=Object.getOwnPropertyNames(u);if(t.minProperties!==void 0&&i.length<t.minProperties&&r.issues.push({origin:"object",code:"too_small",minimum:t.minProperties,inclusive:!0,message:`Too small: expected object to have >=${t.minProperties} properties`,input:u,inst:e,continue:!0}),t.maxProperties!==void 0&&i.length>t.maxProperties&&r.issues.push({origin:"object",code:"too_big",maximum:t.maxProperties,inclusive:!0,message:`Too big: expected object to have <=${t.maxProperties} properties`,input:u,inst:e,continue:!0}),t.keySchema)for(const o of i){const a=t.keySchema.safeParse(o);a.success||r.issues.push({code:"invalid_key",origin:"record",issues:a.error.issues,input:o,path:[o],continue:!0})}}).pipe(e)}function canonicalKey(e,t){if(e===null)return"z";const n=typeof e;if(n!=="object"){if(n==="number"&&Number.isNaN(e))return null;const r=String(e);return`${n[0]}${r.length}:${r}`}if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){const i=[];for(const o of e){const a=canonicalKey(o,t);if(a===null)return null;i.push(a)}return`a${i.length}:[${i.join(",")}]`}const r=Object.keys(e).sort(),u=[];for(const i of r){const o=canonicalKey(e[i],t);if(o===null)return null;u.push(`${i.length}:${i}=${o}`)}return`o${u.length}:{${u.join(",")}}`}finally{t.delete(e)}}var SCHEMA_KEYWORDS=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),SCHEMA_MAP_KEYWORDS=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function containsRef(e){return typeof e!="object"||e===null?!1:Array.isArray(e)?e.some(containsRef):typeof e.$ref=="string"?!0:Object.entries(e).some(([t,n])=>SCHEMA_KEYWORDS.has(t)?containsRef(n):!SCHEMA_MAP_KEYWORDS.has(t)||typeof n!="object"||n===null?!1:Object.values(n).some(containsRef))}function plural(e){return e===1?"element":"elements"}function checkArrayGuards(e,t){return z.transform(r=>r).check(r=>{const u=r.value;if(Array.isArray(u)){if(t.uniqueItems===!0){const i=new Map;for(let o=0;o<u.length;o++){const a=canonicalKey(u[o],new Set);if(a===null)continue;const s=i.get(a);if(s===void 0){i.set(a,o);continue}r.issues.push({code:"custom",message:`Array items must be unique: element at index ${o} duplicates the one at index ${s}`,input:u,path:[o],continue:!0})}}if(t.containsSchema){const i=t.minContains??1,o=t.maxContains!==void 0?t.maxContains+1:Number.POSITIVE_INFINITY;let a=0;for(const s of u)if(t.containsSchema.safeParse(s).success&&++a>=o)break;a<i&&r.issues.push({code:"custom",message:`Array must contain at least ${i} matching ${plural(i)}; found ${a}`,input:u,continue:!0}),t.maxContains!==void 0&&a>t.maxContains&&r.issues.push({code:"custom",message:`Array must contain at most ${t.maxContains} matching ${plural(t.maxContains)}`,input:u,continue:!0})}}}).pipe(e)}function getTupleRest(e,t){if(e!==!1)return e===void 0||e===!0?z.any():convertSchema(e,t)}var fullTime=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function convertBaseSchema(e,t){if(e.not!==void 0){if(typeof e.not=="object"&&Object.keys(e.not).length===0)return z.never();throw new Error("not is not supported in Zod (except { not: {} } for never)")}if(e.unevaluatedItems!==void 0)throw new Error("unevaluatedItems is not supported");if(e.unevaluatedProperties!==void 0)throw new Error("unevaluatedProperties is not supported");if(e.if!==void 0||e.then!==void 0||e.else!==void 0)throw new Error("Conditional schemas (if/then/else) are not supported");if(e.dependentSchemas!==void 0||e.dependentRequired!==void 0)throw new Error("dependentSchemas and dependentRequired are not supported");if(e.$ref){const u=e.$ref;if(t.refs.has(u))return t.refs.get(u);if(t.processing.has(u))return z.lazy(()=>{if(!t.refs.has(u))throw new Error(`Circular reference not resolved: ${u}`);return t.refs.get(u)});t.processing.add(u);const i=resolveRef(u,t),o=convertSchema(i,t);return t.refs.set(u,o),t.processing.delete(u),o}if(e.enum!==void 0){const u=e.enum;if(t.version==="openapi-3.0"&&e.nullable===!0&&u.length===1&&u[0]===null)return z.null();if(u.length===0)return z.never();if(u.length===1)return z.literal(u[0]);if(u.every(o=>typeof o=="string"))return z.enum(u);const i=u.map(o=>z.literal(o));return i.length<2?i[0]:z.union([i[0],i[1],...i.slice(2)])}if(e.const!==void 0)return z.literal(e.const);const n=e.type;if(Array.isArray(n)){const u=n.map(i=>{const o={...e,type:i};return convertBaseSchema(o,t)});return u.length===0?z.never():u.length===1?u[0]:z.union(u)}if(!n)return z.any();let r;switch(n){case"string":{let u=z.string();if(e.format){const i=e.format;i==="email"?u=u.check(z.email()):i==="uri"||i==="uri-reference"?u=u.check(z.url()):i==="uuid"||i==="guid"?u=u.check(z.uuid()):i==="date-time"?u=u.check(z.iso.datetime({offset:!0})):i==="date"?u=u.check(z.iso.date()):i==="time"?u=u.check(z.regex(fullTime)):i==="duration"?u=u.check(z.iso.duration()):i==="hostname"?u=u.check(z.hostname()):i==="ipv4"?u=u.check(z.ipv4()):i==="ipv6"?u=u.check(z.ipv6()):i==="mac"?u=u.check(z.mac()):i==="cidr"?u=u.check(z.cidrv4()):i==="cidr-v6"?u=u.check(z.cidrv6()):i==="base64"?u=u.check(z.base64()):i==="base64url"?u=u.check(z.base64url()):i==="e164"?u=u.check(z.e164()):i==="credit_card"?u=u.check(z.creditCard()):i==="iban"?u=u.check(z.iban()):i==="jwt"?u=u.check(z.jwt()):i==="emoji"?u=u.check(z.emoji()):i==="nanoid"?u=u.check(z.nanoid()):i==="cuid"?u=u.check(z.cuid()):i==="cuid2"?u=u.check(z.cuid2()):i==="ulid"?u=u.check(z.ulid()):i==="xid"?u=u.check(z.xid()):i==="ksuid"&&(u=u.check(z.ksuid()))}typeof e.minLength=="number"&&(u=u.min(e.minLength)),typeof e.maxLength=="number"&&(u=u.max(e.maxLength)),e.pattern&&(u=u.regex(new RegExp(e.pattern))),r=u;break}case"number":case"integer":{let u=n==="integer"?z.number().int():z.number();typeof e.minimum=="number"&&e.exclusiveMinimum!==!0&&(u=u.min(e.minimum)),typeof e.maximum=="number"&&e.exclusiveMaximum!==!0&&(u=u.max(e.maximum)),typeof e.exclusiveMinimum=="number"?u=u.gt(e.exclusiveMinimum):e.exclusiveMinimum===!0&&typeof e.minimum=="number"&&(u=u.gt(e.minimum)),typeof e.exclusiveMaximum=="number"?u=u.lt(e.exclusiveMaximum):e.exclusiveMaximum===!0&&typeof e.maximum=="number"&&(u=u.lt(e.maximum)),typeof e.multipleOf=="number"&&(u=u.multipleOf(e.multipleOf)),r=u;break}case"boolean":{r=z.boolean();break}case"null":{r=z.null();break}case"object":{const u={},i=e.properties||{},o=new Set(e.required||[]),a=typeof e.additionalProperties=="object"?convertSchema(e.additionalProperties,t):void 0;for(const[d,f]of Object.entries(i)){const m=convertSchema(f,t);assignProp(u,d,o.has(d)?m:m.optional())}if(e.patternProperties){const d=e.patternProperties,f=Object.keys(d),m=[];for(const p of f){const g=convertSchema(d[p],t),D=z.string().regex(new RegExp(p));m.push(z.looseRecord(D,g))}const h=[];if(Object.keys(u).length>0&&h.push(z.object(u).passthrough()),h.push(...m),h.length===0)r=z.object({}).passthrough();else if(h.length===1)r=h[0];else{let p=z.intersection(h[0],h[1]);for(let g=2;g<h.length;g++)p=z.intersection(p,h[g]);r=p}if(e.additionalProperties===!1){const p=Object.keys(u),g=f.map(v=>new RegExp(v)),D=r;r=r.check(v=>{if(!isPlainObject(v.value))return;const E=[];for(const y of Object.keys(v.value))p.includes(y)||g.some(b=>b.test(y))||E.push(y);E.length&&v.issues.push({code:"unrecognized_keys",keys:E,input:v.value,inst:D})})}}else{const d=z.object(u);e.additionalProperties===!1?r=d.strict():a?r=d.catchall(a):r=d.passthrough()}const s=e.propertyNames!==void 0&&e.propertyNames!==!0,c=typeof e.minProperties=="number"?e.minProperties:void 0,l=typeof e.maxProperties=="number"?e.maxProperties:void 0;if(s||c!==void 0||l!==void 0){let d;if(s){const f=typeof e.propertyNames=="object"&&e.propertyNames.type===void 0?{type:"string",...e.propertyNames}:e.propertyNames;d=convertSchema(f,t)}r=checkObjectGuards(r,{keySchema:d,minProperties:c,maxProperties:l})}break}case"array":{const u=e.prefixItems,i=e.items;if(u&&Array.isArray(u)){const o=typeof e.minItems=="number"?e.minItems:0,a=u.map(d=>convertSchema(d,t)),s=applyMinItems(a,o),c=Array.isArray(i)?void 0:getTupleRest(i,t),l=z.tuple(s);r=c?l.rest(c):l,typeof e.minItems=="number"&&(r=r.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(r=r.check(z.maxLength(e.maxItems)))}else if(Array.isArray(i)){const o=typeof e.minItems=="number"?e.minItems:0,a=i.map(d=>convertSchema(d,t)),s=applyMinItems(a,o),c=getTupleRest(e.additionalItems,t),l=z.tuple(s);r=c?l.rest(c):l,typeof e.minItems=="number"&&(r=r.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(r=r.check(z.maxLength(e.maxItems)))}else if(i!==void 0){const o=convertSchema(i,t);let a=z.array(o);typeof e.minItems=="number"&&(a=a.min(e.minItems)),typeof e.maxItems=="number"&&(a=a.max(e.maxItems)),r=a}else r=z.array(z.any());(e.uniqueItems===!0||e.contains!==void 0)&&(r=checkArrayGuards(r,{uniqueItems:e.uniqueItems===!0,containsSchema:e.contains!==void 0?convertSchema(e.contains,t):void 0,minContains:typeof e.minContains=="number"?e.minContains:void 0,maxContains:typeof e.maxContains=="number"?e.maxContains:void 0}));break}default:throw new Error(`Unsupported type: ${n}`)}return r}function convertSchema(e,t){if(typeof e=="boolean")return e?z.any():z.never();let n=convertBaseSchema(e,t);const r=e.type||e.enum!==void 0||e.const!==void 0;if(e.anyOf&&Array.isArray(e.anyOf)){const a=e.anyOf.map(c=>convertSchema(c,t)),s=z.union(a);n=r?z.intersection(n,s):s}if(e.oneOf&&Array.isArray(e.oneOf)){const a=e.oneOf.map(c=>convertSchema(c,t)),s=z.xor(a);n=r?z.intersection(n,s):s}if(e.allOf&&Array.isArray(e.allOf))if(e.allOf.length===0)n=r?n:z.any();else{let a=r?n:convertSchema(e.allOf[0],t);const s=r?0:1;for(let c=s;c<e.allOf.length;c++)a=z.intersection(a,convertSchema(e.allOf[c],t));n=a}e.nullable===!0&&t.version==="openapi-3.0"&&(n=z.nullable(n)),e.readOnly===!0&&(n=z.readonly(n)),e.default!==void 0&&(n=n.default(e.default));const u={},i=["$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor"];for(const a of i)a in e&&(u[a]=e[a]);const o=["contentEncoding","contentMediaType","contentSchema"];for(const a of o)a in e&&(u[a]=e[a]);if(e.type==="object"&&e.$ref===void 0){e.propertyNames!==void 0&&!containsRef(e.propertyNames)&&(u.propertyNames=e.propertyNames);for(const a of["minProperties","maxProperties"])e[a]!==void 0&&(u[a]=e[a])}if(e.type==="array"&&e.$ref===void 0){e.contains!==void 0&&!containsRef(e.contains)&&(u.contains=e.contains);for(const a of["uniqueItems","minContains","maxContains"])e[a]!==void 0&&(u[a]=e[a])}for(const a of Object.keys(e))RECOGNIZED_KEYS.has(a)||assignProp(u,a,e[a]);return Object.keys(u).length>0&&t.registry.add(n,u),e.description&&(n=n.describe(e.description)),n}function fromJSONSchema(e,t){if(typeof e=="boolean")return e?z.any():z.never();let n;try{n=JSON.parse(JSON.stringify(e))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}const r=detectVersion(n,t?.defaultTarget),u=n.$defs||n.definitions||{},i={version:r,defs:u,refs:new Map,processing:new Set,rootSchema:n,registry:t?.registry??globalRegistry};return convertSchema(n,i)}var RESOLVING=Symbol("z.visit/resolving");function visit(e,t){const n=typeof t=="function"?t:(o,a)=>{const s=t[o._zod.def.type];return s?s(o,a):o},r=new Map;function u(o){const a=r.get(o);if(a===RESOLVING)return new $ZodLazy({type:"lazy",getter:()=>r.get(o)});if(a!==void 0)return a;r.set(o,RESOLVING);const s=i(o),c=n(s,s!==o);return r.set(o,c),c}function i(o){const a=o._zod.def,s=a.type;switch(s){case"object":{const c=a.shape,l=Object.keys(c);let d=!1;const f={};for(const h of l){const p=u(c[h]);p!==c[h]&&(d=!0),f[h]=p}let m=a.catchall;return a.catchall&&(m=u(a.catchall),m!==a.catchall&&(d=!0)),d?clone(o,{...a,shape:f,catchall:m}):o}case"array":{const c=u(a.element);return c===a.element?o:clone(o,{...a,element:c})}case"tuple":{const c=a.items;let l=!1;const d=[];for(const m of c){const h=u(m);h!==m&&(l=!0),d.push(h)}let f=a.rest;return a.rest&&(f=u(a.rest),f!==a.rest&&(l=!0)),l?clone(o,{...a,items:d,rest:f}):o}case"record":case"map":{const c=u(a.keyType),l=u(a.valueType);return c===a.keyType&&l===a.valueType?o:clone(o,{...a,keyType:c,valueType:l})}case"set":{const c=u(a.valueType);return c===a.valueType?o:clone(o,{...a,valueType:c})}case"union":{const c=a.options;let l=!1;const d=[];for(const f of c){const m=u(f);m!==f&&(l=!0),d.push(m)}return l?clone(o,{...a,options:d}):o}case"intersection":{const c=u(a.left),l=u(a.right);return c===a.left&&l===a.right?o:clone(o,{...a,left:c,right:l})}case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":{const c=u(a.innerType);return c===a.innerType?o:clone(o,{...a,innerType:c})}case"pipe":{const c=u(a.in),l=u(a.out);return c===a.in&&l===a.out?o:clone(o,{...a,in:c,out:l})}case"function":{const c=u(a.input),l=u(a.output);return c===a.input&&l===a.output?o:clone(o,{...a,input:c,output:l})}case"lazy":{const c=a.getter,{_cachedInner:l,...d}=a;return clone(o,{...d,getter:()=>u(c())})}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":return o;default:return o}}return u(e)}function deepPartial(e){return visit(e,{object:t=>t.partial(),union:t=>{const n=t._zod.def;return n.discriminator===void 0?t:union(n.options)}})}function withChecks(e,t){if(!t?.length)return e;const n=e._zod.def;return clone(e,mergeDefs(n,{checks:[...n.checks??[],...t]}),{parent:!0})}function outSide(e){return withChecks(e.out,e.checks)}function inSide(e){return e.in._zod.traits.has("$ZodTransform")?outSide(e):e.in}function input(e){return visit(e,{pipe:t=>inSide(t._zod.def),default:(t,n)=>n?optional(t._zod.def.innerType):t,catch:(t,n)=>n?t._zod.def.innerType:t})}function output(e){return visit(e,{pipe:t=>outSide(t._zod.def),prefault:(t,n)=>n?t._zod.def.innerType:t})}var coerce_exports={};__export(coerce_exports,{bigint:()=>bigint3,boolean:()=>boolean3,date:()=>date4,number:()=>number3,string:()=>string3});function string3(e){return _coercedString(ZodString,e)}function number3(e){return _coercedNumber(ZodNumber,e)}function boolean3(e){return _coercedBoolean(ZodBoolean,e)}function bigint3(e){return _coercedBigint(ZodBigInt,e)}function date4(e){return _coercedDate(ZodDate,e)}function isSpoken(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.display=="string"&&typeof e.speak=="string"}function isVariants(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.match=="object"}function displayOf(e,t={},n){return isVariants(e)?selectVariant(e,t,n):isSpoken(e)?e.display:e}function speakOf(e,t={},n){return isVariants(e)?selectVariant(e,t,n):isSpoken(e)?e.speak:e}function textsOf(e){if(isVariants(e))return[...new Set(Object.values(e.match))];const t=displayOf(e);return t===void 0?[]:[t]}var INPUT_DECL=/^input\s+([A-Za-z_][A-Za-z0-9_]*)$/,LOCAL_DECL=/^local\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z]+)((?:\s+[A-Za-z]+\s*=\s*[A-Za-z]+)*)$/;function parseDeclaration(e){const t=e.trim(),n=INPUT_DECL.exec(t);if(n?.[1])return{kind:"input",name:n[1]};const r=LOCAL_DECL.exec(t);if(r?.[1]&&r[2]&&r[3]){if(r[3]!=="plural")return`"${t}": only plural is supported, not ${r[3]}`;const i=new Map([...(r[4]??"").matchAll(/([A-Za-z]+)\s*=\s*([A-Za-z]+)/g)].map(o=>[o[1]??"",o[2]??""])).get("type")??"cardinal";return i!=="cardinal"&&i!=="ordinal"?`"${t}": type must be cardinal or ordinal`:{kind:"plural",name:r[1],of:r[2],ordinal:i==="ordinal"}}return`cannot read "${t}": write "input name" or "local name = input: plural"`}function parseMatchKey(e){const t=new Map;for(const n of e.split(",")){const r=/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([^,=\s]+)\s*$/.exec(n);if(!r?.[1]||!r[2])return;t.set(r[1],r[2])}return t}function selectorsOf(e){if(e.selectors.length>0)return e.selectors;const t=Object.keys(e.match)[0];return t===void 0?[]:[...parseMatchKey(t)?.keys()??[]]}function declarations(e){return e.declarations.map(parseDeclaration).filter(t=>typeof t!="string")}var pluralRules=new Map;function pluralCategory(e,t,n){if(!Number.isFinite(e))return;const r=`${t??""}|${String(n)}`;let u=pluralRules.get(r);if(!u){const i=n?"ordinal":"cardinal";try{u=new Intl.PluralRules(t,{type:i})}catch{u=new Intl.PluralRules(void 0,{type:i})}pluralRules.set(r,u)}return u.select(e)}function selectVariant(e,t,n){const r=new Map;for(const s of declarations(e))s.kind==="plural"&&r.set(s.name,{of:s.of,ordinal:s.ordinal});const u=selectorsOf(e),i=u.map(s=>{const c=r.get(s);if(c){const d=t[c.of],f=d===void 0||d===""?NaN:Number(d);return{exact:Number.isFinite(f)?String(f):void 0,category:pluralCategory(f,n,c.ordinal)}}const l=t[s];return{exact:l===void 0?void 0:String(l),category:void 0}});let o,a=-1;for(const[s,c]of Object.entries(e.match)){const l=parseMatchKey(s);if(!l)continue;let d=0;for(const[f,m]of u.entries()){const h=l.get(m),p=i[f];if(h==="*")d+=1;else if(p?.exact!==void 0&&h===p.exact)d+=3;else if(p?.category!==void 0&&h===p.category)d+=2;else{d=-1;break}}d>a&&(o=c,a=d)}if(o!==void 0)return o;if(r.size>0)for(const[s,c]of Object.entries(e.match)){const l=parseMatchKey(s);if(l&&[...r.keys()].every(d=>l.get(d)==="other"))return c}return Object.values(e.match)[0]??""}function fillMessage(e,t){return e.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(n,r)=>{const u=t[r];return u===void 0?n:String(u)})}function messageList(e,t,n,r=[]){const u=`${n}.`,i=[...t].filter(s=>s.startsWith(u)),o=s=>{const c=e(s);if(c!==void 0&&!i.some(m=>m.startsWith(`${s}.`)))return r.push(s),c;const l=new Set;for(const m of i){if(!m.startsWith(`${s}.`))continue;const h=m.slice(s.length+1).split(".")[0];h&&l.add(h)}if(l.size===0)return;if([...l].every(m=>/^\d+$/.test(m))){const m=[];for(let h=0;l.has(String(h));h++){const p=o(`${s}.${String(h)}`);p!==void 0&&m.push(p)}return m}const f={};for(const m of[...l].sort()){const h=o(`${s}.${m}`);h!==void 0&&(f[m]=h)}return f},a=o(n);return Array.isArray(a)?a:[]}function momentOf(e,t){const n=new Set(e.parts.flatMap(i=>(i.anchors??[]).map(o=>o.name))),r=parseAnchorRef(t,n);if(r){for(const i of e.parts){const o=i.anchors?.find(a=>a.name===r.name);if(o){if(r.end&&o.end===void 0)throw new Error(`The anchor "${r.name}" of part ${i.key} is a place, not a stretch: "@/${r.name}" has no end. Use "@${r.name}".`);return(r.end?o.end??o.at:o.at)+r.shift}}throw new Error(`No part of the video has the anchor "${r.name}"; it has ${n.size>0?[...n].map(i=>`@${i}`).join(", "):"no anchors"}.`)}const u=e.parts.find(i=>i.key===t);if(u)return u.start;throw new Error(`"${t}" is not an anchor ("@name") or a part of the video; its parts are ${e.parts.map(i=>i.key).join(", ")}.`)}var BUILTIN_SFX=["whoosh","tick","pop"];function isBuiltinSfx(e){return BUILTIN_SFX.includes(e)}var CLEAN_LOOK={name:"clean",color:{bg:"#ffffff",fg:"#16181d",accent:"#2f5bea",muted:"#5d6470",surface:"#f3f4f6"},font:{display:'"Inter Variable", "Noto Sans SC", "Noto Sans CJK SC", sans-serif',body:'"Inter Variable", "Noto Sans SC", "Noto Sans CJK SC", sans-serif',mono:'ui-monospace, "SF Mono", Menlo, monospace',emoji:'"Noto Color Emoji"'},motion:{beat:.5},sfx:{}};function lookCss(e){const t={};for(const[n,r]of Object.entries(e.color))t[`--ak-color-${n}`]=r;for(const[n,r]of Object.entries(e.font))t[`--ak-font-${n}`]=r;return t["--ak-motion-beat"]=`${String(e.motion.beat)}s`,t}var PRESETS=["16x9","9x16","1x1","4x5"];function isPreset(e){return typeof e=="string"&&PRESETS.includes(e)}var INFO={"16x9":{width:1920,height:1080,orient:"landscape",safe:{top:60,bottom:90,left:80,right:80}},"9x16":{width:1080,height:1920,orient:"portrait",safe:{top:150,bottom:400,left:40,right:140}},"1x1":{width:1080,height:1080,orient:"square",safe:{top:50,bottom:90,left:40,right:40}},"4x5":{width:1080,height:1350,orient:"portrait",safe:{top:60,bottom:120,left:40,right:40}}};function contentEdges(e,t={}){const{width:n,height:r,orient:u,safe:i}=e,o=Math.min(n,r)/1080,a=t.margin??(u==="landscape"?120:84)*o,s=Math.max(a,i.left,i.right),c=Math.max(s,i.top+(t.topGap??30*o)),l=r-Math.max(s,i.bottom+(t.bottomGap??20*o));return{k:o,pad:s,top:c,bottom:l,left:s,right:n-s}}function presetInfo(e){return INFO[e]}var PROFILES=["tiktok","reels","shorts","meta-feed","amazon","linkedin"];function isProfile(e){return typeof e=="string"&&PROFILES.includes(e)}var PROFILE_INFO={tiktok:{name:"tiktok",label:"TikTok",width:1080,height:1920,safe:{top:240,bottom:660,left:120,right:180},maxDuration:600,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1080,height:1920},maxBytes:5e8,encode:{crf:20,maxKbps:6e3}},served:{video:{codec:"h264",profile:"high",kbps:900,width:720,height:1280,fps:30,preset:"slow"},audio:{codec:"he-aac-v2",kbps:32,rate:44100,channels:2}}},reels:{name:"reels",label:"Instagram Reels",width:1080,height:1920,safe:{top:269,bottom:672,left:65,right:65},maxDuration:180,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1080,height:1920},maxBytes:4e9,encode:{crf:20,maxKbps:6e3}}},shorts:{name:"shorts",label:"YouTube Shorts",width:1080,height:1920,safe:{top:288,bottom:672,left:48,right:192},maxDuration:180,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1080,height:1920},maxBytes:256e9,encode:{crf:20,maxKbps:8e3}}},"meta-feed":{name:"meta-feed",label:"Facebook and Instagram feed",width:1080,height:1350,safe:{top:60,bottom:120,left:40,right:40},maxDuration:14460,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1080,height:1350},maxBytes:4e9,encode:{crf:20,maxKbps:6e3}}},amazon:{name:"amazon",label:"Amazon Sponsored Brands video",width:1920,height:1080,safe:{top:60,bottom:90,left:80,right:80},maxDuration:45,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1920,height:1080},maxBytes:5e8,encode:{crf:20,maxKbps:8e3}}},linkedin:{name:"linkedin",label:"LinkedIn",width:1080,height:1080,safe:{top:50,bottom:90,left:40,right:40},maxDuration:1800,loudness:-14,file:{container:"mp4",video:"h264",audio:"aac",cover:{width:1080,height:1080},maxBytes:2e8,encode:{crf:20,maxKbps:6e3}}}},FPS=30,LOAD_LIMIT=10,SEEK_LIMIT=30,LOAD_WAITS=4,MAX_FPS=120,NTSC=[24,30,48,60,120];function parseFps(e){if(typeof e=="number"){if(!Number.isFinite(e))return;if(Number.isInteger(e))return e>=1&&e<=MAX_FPS?e:void 0;for(const r of NTSC){const u=r*1e3/1001;if(Math.abs(e-u)<.005)return u}return}if(typeof e!="string")return;const t=e.trim(),n=/^(\d+)\s*\/\s*(\d+)$/.exec(t);if(n){const r=Number(n[1]),u=Number(n[2]);return u===1?parseFps(r):u===1001&&NTSC.some(i=>i*1e3===r)?r/u:void 0}return t!==""&&Number.isFinite(Number(t))?parseFps(Number(t)):void 0}function toFrame(e,t=FPS){return Math.floor(e*t+1e-9)/t}var PAGE_FORMATS=["a4","letter"],PAGES={a4:{width:1240,height:1754,css:"210mm 297mm"},letter:{width:1275,height:1650,css:"8.5in 11in"}},CUSTOM=/^([1-9]\d{1,3})x([1-9]\d{1,3})$/,NO_SAFE={top:0,bottom:0,left:0,right:0},orientOf=(e,t)=>e>t?"landscape":e<t?"portrait":"square",isPageFormat=e=>PAGE_FORMATS.includes(e);function formatName(e){return typeof e=="string"?e:e.format}function formatEntry(e,t){return e.find(n=>formatName(n)===t)}function withSpec(e,t){const n={...e.safe,...definedOf(t.safe??{})},r=e.profile;return{...e,safe:n,...r?{profile:{...r,safe:n,...t.maxDuration===void 0?{}:{maxDuration:t.maxDuration},...t.loudness===void 0?{}:{loudness:t.loudness}}}:{}}}function definedOf(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function formatInfo(e){if(typeof e!="string"){const u=formatInfo(e.format);return u&&withSpec(u,e)}if(isPreset(e))return INFO[e];if(isProfile(e)){const u=PROFILE_INFO[e];return{width:u.width,height:u.height,orient:orientOf(u.width,u.height),safe:u.safe,profile:u}}if(isPageFormat(e)){const u=PAGES[e];return{width:u.width,height:u.height,orient:orientOf(u.width,u.height),safe:NO_SAFE}}const t=CUSTOM.exec(e);if(!t)return;const n=Number(t[1]),r=Number(t[2]);if(!(n<64||r<64||n>8192||r>8192))return{width:n,height:r,orient:orientOf(n,r),safe:NO_SAFE}}function isFormat(e){return typeof e=="string"&&formatInfo(e)!==void 0}var VIDEO_FORMAT_HELP=`one of ${PRESETS.join(", ")}, a platform profile (${PROFILES.join(", ")}), or WIDTHxHEIGHT in pixels with even sides from 64 to 8192, such as 1280x720`,FORMAT_HELP=`one of ${[...PRESETS,...PAGE_FORMATS].join(", ")}, a platform profile (${PROFILES.join(", ")}), or WIDTHxHEIGHT in pixels (each side 64–8192, such as 1200x630)`,clamp01=e=>Math.min(Math.max(e,0),1);function pixelRect(e,t,n){const r=Math.round(clamp01(e[0])*t),u=Math.round(clamp01(e[1])*n),i=Math.round(clamp01(e[0]+e[2])*t),o=Math.round(clamp01(e[1]+e[3])*n);return[Math.min(r,t-1),Math.min(u,n-1),Math.max(1,i-r),Math.max(1,o-u)]}function placeFootage(e){const{frame:t}=e,n=e.box==="full"?[0,0,t.width,t.height]:pixelRect(e.box,t.width,t.height),r=e.source;if(!r||r.width<=0||r.height<=0)return{box:n,picture:[...n]};const u=e.crop?pixelRect(e.crop,r.width,r.height):[0,0,r.width,r.height],[i,o,a,s]=n,c=a/u[2],l=s/u[3],d=e.fit==="cover"?Math.max(c,l):Math.min(c,l),f=e.fit==="cover"?Math.ceil:Math.round,m=Math.max(1,f(u[2]*d-1e-6)),h=Math.max(1,f(u[3]*d-1e-6)),p=[i+Math.round((a-m)/2),o+Math.round((s-h)/2),m,h];return{box:n,crop:u,picture:p}}function intersect(e,t){const n=Math.max(e[0],t[0]),r=Math.max(e[1],t[1]),u=Math.min(e[0]+e[2],t[0]+t[2]),i=Math.min(e[1]+e[3],t[1]+t[3]);return u>n&&i>r?[n,r,u-n,i-r]:void 0}var MEDIA_DIR="assets/media",TEXT_DIR="assets/text",LOCAL_DIR=".allyhub",CACHE_DIR=".allyhub/cache",GITIGNORE=`node_modules/
64
64
  ${LOCAL_DIR}/
65
65
  .playwright-cli/
66
- `;function baseOf(e){return e.slice(e.lastIndexOf("/")+1)}var CODE_EXTENSIONS=["ts","tsx","mts","js","jsx","mjs"],code=e=>CODE_EXTENSIONS.map(t=>`${e}.${t}`),ITEM_KINDS={video:{entries:code("video"),editor:"video",name:"video"},slides:{entries:code("slides"),editor:"slides",name:"slides"},doc:{entries:["doc.mdx"],editor:"doc",name:"doc"},sheet:{entries:["sheet.csv"],editor:"sheet",name:"sheet"},scenery:{entries:code("scenery"),editor:"scenery",name:"3D scenery"},website:{entries:["astro.config.mjs","astro.config.ts","astro.config.mts","astro.config.js"],editor:"website",name:"website"}},KINDS=Object.keys(ITEM_KINDS),BY_ENTRY=new Map(KINDS.flatMap(e=>ITEM_KINDS[e].entries.map(t=>[t,e])));function entryKind(e){return BY_ENTRY.get(baseOf(e))}var SHA256=external_exports.string().regex(/^[0-9a-f]{64}$/u,"A sha256 is 64 lowercase hexadecimal digits."),SECONDS=external_exports.number().nonnegative(),INSTANT=external_exports.iso.datetime({offset:!0});function dataFile(e){return external_exports.strictObject({$schema:external_exports.string().optional(),...e})}var TargetSchema=external_exports.discriminatedUnion("type",[external_exports.strictObject({type:external_exports.literal("quote"),exact:external_exports.string().min(1),prefix:external_exports.string().optional(),suffix:external_exports.string().optional()}),external_exports.strictObject({type:external_exports.literal("cells"),range:external_exports.string().regex(/^[A-Z]+[1-9]\d*(?::[A-Z]+[1-9]\d*)?$/u)}),external_exports.strictObject({type:external_exports.literal("item")})]),AuthorSchema=external_exports.strictObject({kind:external_exports.enum(["person","agent"]),name:external_exports.string().min(1)}),CommentSchema=external_exports.strictObject({id:external_exports.string().min(1),author:AuthorSchema,text:external_exports.string().min(1),at:INSTANT}),ThreadSchema=external_exports.strictObject({id:external_exports.string().min(1),target:TargetSchema,resolved:external_exports.boolean().default(!1),comments:external_exports.array(CommentSchema).min(1)}),CommentsFileSchema=dataFile({version:external_exports.literal(1),threads:external_exports.array(ThreadSchema).default([])}),ConfigSchema=external_exports.strictObject({fonts:external_exports.array(external_exports.string().min(1)).default([]),text:external_exports.string().optional(),locales:external_exports.array(external_exports.string().min(2)).min(1).optional(),look:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),defaults:external_exports.record(external_exports.string(),external_exports.unknown()).optional()}),Stretch=external_exports.strictObject({from:SECONDS,to:SECONDS}).refine(e=>e.to>e.from,{message:"A stretch ends after its start.",path:["to"]}),PAD_MAX=2,PAD_SIDE=external_exports.number().min(0).max(PAD_MAX),EditsFileSchema=dataFile({version:external_exports.literal(1),take:external_exports.string().optional(),remove:external_exports.array(external_exports.strictObject({from:external_exports.int().nonnegative(),to:external_exports.int().nonnegative(),text:external_exports.string().optional()}).refine(e=>e.to>=e.from,{message:"A range ends at or after its start.",path:["to"]})).optional(),sounds:external_exports.array(Stretch).optional(),inWord:external_exports.array(Stretch).optional(),maxPause:external_exports.number().min(.05).max(10).optional(),pad:external_exports.strictObject({before:PAD_SIDE.optional(),after:PAD_SIDE.optional()}).optional()}),ElementBoxSchema=external_exports.tuple([external_exports.number(),external_exports.number(),external_exports.number().nonnegative(),external_exports.number().nonnegative()]),ElementsFileSchema=external_exports.record(external_exports.string().min(1),ElementBoxSchema),Omitted=external_exports.strictObject({omitted:external_exports.literal(!0),sha256:SHA256,bytes:external_exports.int().nonnegative()}),GenFileSchema=dataFile({version:external_exports.literal(1),ai:external_exports.boolean(),tool:external_exports.string().optional(),model:external_exports.string().optional(),input:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),inputHash:SHA256.optional(),output:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),credits:external_exports.number().nonnegative().optional(),at:INSTANT,sha256:SHA256,bytes:external_exports.int().nonnegative(),source:external_exports.strictObject({library:external_exports.string(),page:external_exports.url(),authors:external_exports.array(external_exports.string()).default([]),license:external_exports.string()}).optional()}),MESSAGE_KEY=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/u,SpokenSchema=external_exports.strictObject({display:external_exports.string(),speak:external_exports.string()}),VariantsSchema=external_exports.strictObject({declarations:external_exports.array(external_exports.string()).default([]),selectors:external_exports.array(external_exports.string()).default([]),match:external_exports.record(external_exports.string(),external_exports.string()).refine(e=>Object.keys(e).length>0,"A match needs at least one case.")}),MessageSchema=external_exports.union([external_exports.string(),SpokenSchema,external_exports.tuple([VariantsSchema])]),MessagesFileSchema=external_exports.record(external_exports.string(),external_exports.unknown()).superRefine((e,t)=>{for(const[n,r]of Object.entries(e)){if(n==="$schema"){typeof r!="string"&&t.addIssue({code:"custom",path:[n],message:"$schema is a string."});continue}MESSAGE_KEY.test(n)||t.addIssue({code:"custom",path:[n],message:`"${n}" is not a message key: letters, digits, _ and -, in segments joined by dots.`});const u=MessageSchema.safeParse(r);u.success||t.addIssue({code:"custom",path:[n],message:Array.isArray(r)?`A message with variants is [{ "declarations": […], "selectors": […], "match": {…} }]: ${u.error.issues.map(i=>i.message).join("; ")}`:"A message is a string, { display, speak }, or [{ declarations, selectors, match }]."})}}).transform(e=>{const t={...e};return delete t.$schema,t}),SHARE_BOX=external_exports.tuple([external_exports.number(),external_exports.number(),external_exports.number(),external_exports.number()]),SCORED=external_exports.object({t:SECONDS,score:external_exports.number()}),MAYBE=external_exports.number().nullable(),COUNT=external_exports.number().int().nonnegative(),ReferenceSentenceSchema=external_exports.object({index:COUNT,start:SECONDS,end:SECONDS,words:external_exports.tuple([external_exports.number().int(),external_exports.number().int()]),text:external_exports.string(),punctuation:external_exports.boolean(),pauseAfter:SECONDS.optional()}),ReferenceGapSchema=external_exports.object({after:COUNT,start:SECONDS,end:SECONDS,dur:SECONDS}),ReferenceBoundarySchema=external_exports.object({t:SECONDS,cut:SCORED.optional(),weak:SCORED.optional(),pause:external_exports.object({start:SECONDS,end:SECONDS,dur:SECONDS}).optional(),sentence:COUNT.optional()}),ReferenceTextSchema=external_exports.object({id:COUNT,text:external_exports.string(),box:SHARE_BOX,height:external_exports.number(),conf:external_exports.number(),words:COUNT,upper:external_exports.number().min(0).max(1),start:SECONDS,end:SECONDS,spans:external_exports.array(external_exports.tuple([SECONDS,SECONDS])),seconds:SECONDS,seen:external_exports.number().int().positive(),frames:external_exports.number().min(0).max(1),spread:external_exports.number().min(0).max(1),said:external_exports.number().min(0).max(1)}),SectionNumbersSchema=external_exports.object({start:SECONDS,end:SECONDS,dur:SECONDS,said:external_exports.string(),words:COUNT,wordsPerMinute:external_exports.number().nonnegative(),cuts:external_exports.array(SECONDS),shots:external_exports.number().int().positive(),cutsPerMinute:external_exports.number().nonnegative(),text:external_exports.array(COUNT),textSeconds:SECONDS}),ReferenceSegmentSchema=SectionNumbersSchema.extend({index:COUNT,name:external_exports.string(),sentences:external_exports.tuple([external_exports.number().int(),external_exports.number().int()]).optional()}),ReferencePacingSchema=external_exports.object({cutsPerMinute:external_exports.number().nonnegative(),meanShot:SECONDS,medianShot:SECONDS,wordsPerMinute:external_exports.number().nonnegative(),speakingRate:external_exports.number().nonnegative(),timeToFirstWord:SECONDS.optional(),timeToFirstCut:SECONDS.optional(),textShare:external_exports.number().min(0).max(1),speechShare:external_exports.number().min(0).max(1),tempo:external_exports.object({bpm:external_exports.number().positive(),confidence:external_exports.number().min(0),candidates:external_exports.array(external_exports.object({bpm:external_exports.number(),r:external_exports.number(),score:external_exports.number()})).optional(),prior:external_exports.number().optional()}).optional(),onsetsPerMinute:external_exports.number().nonnegative()}),LEVELS=external_exports.object({seconds:SECONDS,p10:external_exports.number(),median:external_exports.number(),p90:external_exports.number()}),ReferenceSoundSchema=external_exports.object({gap:SECONDS,edge:SECONDS,voiced:external_exports.number().min(0).max(100),whole:LEVELS,words:LEVELS.optional(),between:LEVELS.extend({voicedShare:external_exports.number().min(0).max(1),onsetsPerMinute:external_exports.number().nonnegative()}).optional(),floor:external_exports.number()}),ReferencePictureSchema=external_exports.object({params:external_exports.record(external_exports.string(),external_exports.unknown()),frames:external_exports.object({tone:COUNT,color:COUNT,motion:COUNT}),luma:external_exports.object({p1:MAYBE,p50:MAYBE,p99:MAYBE}),blackShare:MAYBE,noise:MAYBE,sharpness:MAYBE,saturation:MAYBE,warmth:MAYBE,motion:external_exports.object({speed:external_exports.object({p50:MAYBE,p90:MAYBE}),shake:external_exports.object({p50:MAYBE,p90:MAYBE}),stillShare:MAYBE,runs:COUNT}),sharpnessBySpeed:external_exports.array(external_exports.object({from:external_exports.number(),to:MAYBE,frames:COUNT,sharpness:MAYBE})),noiseByLuma:external_exports.array(external_exports.object({from:external_exports.number(),to:external_exports.number(),blocks:COUNT,noise:MAYBE,median:MAYBE})),shake:external_exports.array(external_exports.object({start:SECONDS,end:SECONDS,rms:external_exports.number(),peaks:external_exports.array(external_exports.object({hz:external_exports.number(),share:external_exports.number()})),flatness:external_exports.number()}))}),BANDWIDTH=external_exports.object({frames:COUNT,reach:external_exports.array(external_exports.object({drop:external_exports.number(),hz:MAYBE})),rolloff95:MAYBE,rolloff99:MAYBE,steps:external_exports.array(external_exports.object({hz:external_exports.number(),db:external_exports.number()}))}),ReferenceAudioSchema=external_exports.object({loudness:external_exports.object({integrated:MAYBE,range:MAYBE,truePeak:MAYBE}),recording:external_exports.object({params:external_exports.record(external_exports.string(),external_exports.unknown()),spectrum:external_exports.array(external_exports.object({hz:external_exports.number(),db:external_exports.number()})),dynamics:external_exports.object({spread:external_exports.number(),crest:external_exports.number()})}).loose(),bandwidth:BANDWIDTH.extend({params:external_exports.record(external_exports.string(),external_exports.unknown())}),voice:BANDWIDTH.optional()}),ReferenceServedSchema=external_exports.object({item:external_exports.string(),combo:external_exports.record(external_exports.string(),external_exports.string()),format:external_exports.string(),platform:external_exports.string().optional(),export:external_exports.object({type:external_exports.string(),crf:external_exports.number().optional(),maxKbps:external_exports.number().optional()}),video:external_exports.object({codec:external_exports.string(),profile:external_exports.string().optional(),kbps:external_exports.number(),width:external_exports.number().int().positive(),height:external_exports.number().int().positive(),fps:external_exports.number().positive(),preset:external_exports.string().optional()}).optional(),audio:external_exports.union([external_exports.object({codec:external_exports.string(),kbps:external_exports.number(),rate:external_exports.number(),channels:external_exports.number()}),external_exports.object({missing:external_exports.string(),instead:external_exports.string()})]),joins:external_exports.array(external_exports.object({t:SECONDS,kind:external_exports.string(),part:external_exports.string().optional(),score:external_exports.number(),margin:external_exports.number(),cut:external_exports.boolean()})),unmeant:external_exports.array(external_exports.object({t:SECONDS,score:external_exports.number(),margin:external_exports.number()}))}),ReferenceSchema=external_exports.object({version:external_exports.literal(1),id:external_exports.string(),source:external_exports.object({file:external_exports.string(),url:external_exports.string().optional(),title:external_exports.string().optional(),sha256:SHA256}),analysedAt:external_exports.string(),duration:SECONDS,width:external_exports.number().int().positive(),height:external_exports.number().int().positive(),fps:external_exports.number().positive(),encoding:external_exports.object({codec:external_exports.string().optional(),bitrate:external_exports.number().positive().optional(),audio:external_exports.object({codec:external_exports.string().optional(),profile:external_exports.string().optional(),bitrate:external_exports.number().positive().optional(),rate:external_exports.number().positive().optional(),channels:external_exports.number().int().positive().optional()}).optional()}).optional(),words:external_exports.string().optional(),wordCount:COUNT,asr:external_exports.string().optional(),wordsMissing:external_exports.object({code:external_exports.string().optional(),message:external_exports.string(),hint:external_exports.string().optional(),instead:external_exports.string()}).optional(),shots:external_exports.object({threshold:external_exports.number().min(0).max(1),minShot:external_exports.number().nonnegative(),weakFloor:external_exports.number().min(0).max(1),prominence:external_exports.number().nonnegative(),cuts:external_exports.array(SCORED),weak:external_exports.array(SCORED),candidates:external_exports.array(external_exports.object({t:SECONDS,score:external_exports.number(),source:external_exports.enum(["jump","change"]),around:external_exports.number(),passes:external_exports.boolean()})).optional()}),speech:external_exports.object({pause:SECONDS,sentences:external_exports.array(ReferenceSentenceSchema),pauses:external_exports.array(ReferenceGapSchema),gaps:external_exports.array(ReferenceGapSchema).optional()}),boundaries:external_exports.object({cutWithin:SECONDS,candidates:external_exports.array(ReferenceBoundarySchema)}),ocr:external_exports.object({engine:external_exports.string(),confidence:external_exports.object({word:external_exports.number().min(0).max(100),short:external_exports.number().min(0).max(100)}),frames:COUNT,samePlace:external_exports.number(),saidWithin:SECONDS,low:external_exports.array(external_exports.object({t:SECONDS,text:external_exports.string(),conf:external_exports.number(),box:SHARE_BOX})).optional()}),text:external_exports.array(ReferenceTextSchema),pacing:ReferencePacingSchema,sound:ReferenceSoundSchema.optional(),segments:external_exports.object({rule:external_exports.string(),pause:SECONDS,cutWithin:SECONDS,minLength:SECONDS,list:external_exports.array(ReferenceSegmentSchema).min(1)}),sheets:external_exports.array(external_exports.string()),picture:ReferencePictureSchema,audio:ReferenceAudioSchema.optional(),served:ReferenceServedSchema.optional()}),InterpretedSectionSchema=external_exports.strictObject({start:SECONDS,end:SECONDS,name:external_exports.string().min(1).optional(),role:external_exports.string().min(1).optional(),picture:external_exports.string().optional(),onScreen:external_exports.array(external_exports.string()).optional(),notes:external_exports.string().optional()}),InterpretationSchema=dataFile({version:external_exports.literal(1).default(1),summary:external_exports.string().optional(),layout:external_exports.string().optional(),hook:external_exports.string().optional(),sections:external_exports.array(InterpretedSectionSchema).min(1),captions:external_exports.strictObject({lines:external_exports.array(COUNT).optional(),style:external_exports.string().optional()}).optional(),watermarks:external_exports.array(COUNT).optional(),notes:external_exports.string().optional(),labels:external_exports.record(external_exports.string(),external_exports.union([external_exports.string(),external_exports.number(),external_exports.boolean(),external_exports.array(external_exports.string())])).optional()}),SCRIPT_NAME=/^[A-Za-z0-9_-]+$/u,NamedSchema=external_exports.string().regex(SCRIPT_NAME,"A name is letters, digits, _ and -."),ScriptTextSchema=external_exports.lazy(()=>external_exports.union([external_exports.string(),SpokenSchema,VariantsSchema,external_exports.array(ScriptTextSchema),external_exports.record(NamedSchema,ScriptTextSchema)])),ScriptPartSchema=external_exports.strictObject({id:NamedSchema,say:external_exports.union([external_exports.string(),VariantsSchema]).optional(),screen:external_exports.record(NamedSchema,ScriptTextSchema).optional()}),ScriptFileSchema=external_exports.strictObject({title:external_exports.string().optional(),text:external_exports.record(NamedSchema,ScriptTextSchema).optional(),parts:external_exports.array(ScriptPartSchema).default([])}).superRefine((e,t)=>{const n=new Set;e.parts.forEach((r,u)=>{n.has(r.id)&&t.addIssue({code:"custom",path:["parts",u,"id"],message:`Two parts are "${r.id}".`}),n.add(r.id)})}),COLUMN_TYPES=["text","number","select","multi-select","date","checkbox","url","email","phone","file"],OPTION_COLORS=["gray","brown","red","orange","yellow","green","blue","purple","pink"],ColumnName=external_exports.string().regex(/\S/u),Option=external_exports.union([external_exports.string().regex(/\S/u),external_exports.number(),external_exports.boolean(),external_exports.strictObject({name:external_exports.union([external_exports.string().regex(/\S/u),external_exports.number()]),color:external_exports.enum(OPTION_COLORS).optional()})]),nameOf=e=>String(typeof e=="object"?e.name:e).trim(),Separator=external_exports.string().regex(/^[^"]*[^"\s][^"]*$/u),NumberStyle=external_exports.enum(["plain","percent","currency"]),NumberFormat=external_exports.union([NumberStyle,external_exports.strictObject({style:NumberStyle.nullable().optional(),decimals:external_exports.int().min(0).max(10).optional(),currency:external_exports.string().regex(/^[A-Za-z]{3}$/u).optional(),thousands:external_exports.boolean().optional()})]),DateStyle=external_exports.enum(["iso","short","long"]),DateFormat=external_exports.union([DateStyle,external_exports.strictObject({style:DateStyle.nullable().optional(),time:external_exports.boolean().optional()})]),common={width:external_exports.number().positive().optional(),wrap:external_exports.boolean().optional()};function checkOptions(e,t){const n=e.separator??";",r=new Set;(e.options??[]).forEach((u,i)=>{const o=nameOf(u);o.includes(n)&&t.addIssue({code:"custom",path:["options",i],message:`"${o}" has the separator ${JSON.stringify(n)} in it`}),r.has(o)&&t.addIssue({code:"custom",path:["options",i],message:`"${o}" is an option twice`}),r.add(o)})}var ColumnFields=external_exports.union([external_exports.strictObject({type:external_exports.enum(["text","checkbox","url","email","phone"]).nullable().optional(),...common}),external_exports.strictObject({type:external_exports.literal("number"),format:NumberFormat.optional(),...common}),external_exports.strictObject({type:external_exports.literal("date"),format:DateFormat.optional(),...common}),external_exports.strictObject({type:external_exports.literal("select"),options:external_exports.array(Option).optional(),...common}).superRefine(checkOptions),external_exports.strictObject({type:external_exports.literal("multi-select"),options:external_exports.array(Option).optional(),separator:Separator.optional(),...common}).superRefine(checkOptions),external_exports.strictObject({type:external_exports.literal("file"),separator:Separator.optional(),height:external_exports.number().positive().optional(),...common})]),ColumnSchema=external_exports.union([external_exports.null(),external_exports.enum(COLUMN_TYPES),ColumnFields]),SheetSpecSchema=external_exports.union([external_exports.null(),external_exports.strictObject({title:external_exports.union([external_exports.string(),external_exports.number()]).optional(),key:ColumnName.optional(),primary:ColumnName.optional(),columns:external_exports.union([external_exports.null(),external_exports.record(external_exports.string(),ColumnSchema)]).optional()})]),WordSchema=external_exports.strictObject({text:external_exports.string().min(1),start:SECONDS,end:SECONDS,confidence:external_exports.number().min(0).max(1).optional()}).refine(e=>e.end>=e.start,{message:"A word ends at or after its start.",path:["end"]}),WordsFileSchema=dataFile({version:external_exports.literal(1),language:external_exports.string().min(2).optional(),duration:SECONDS.optional(),model:external_exports.string().optional(),words:external_exports.array(WordSchema)}).refine(e=>e.words.every((t,n)=>n===0||t.start>=(e.words[n-1]?.start??0)),{message:"Words are in the order they are said.",path:["words"]});function asUrlString(e){return Object.prototype.hasOwnProperty.call(e,"toString")||Object.defineProperty(e,"toString",{value(){return this.url},enumerable:!1,configurable:!0,writable:!0}),e}var INDEX_DIR=`${CACHE_DIR}/index`;function boxAt(e,t,n){const r=e[0],u=e.at(-1);if(!r||!u)return;const i=1/Math.max(1,t);if(n<r.t-i||n>u.t+i)return;if(n<=r.t)return r.box;if(n>=u.t)return u.box;let o=0,a=e.length-1;for(;a-o>1;){const d=o+a>>1;(e[d]?.t??0)<=n?o=d:a=d}const s=e[o]??r,c=e[a]??u,l=c.t===s.t?0:(n-s.t)/(c.t-s.t);return[0,1,2,3].map(d=>(s.box[d]??0)+((c.box[d]??0)-(s.box[d]??0))*l)}function faceAt(e,t,n=e.speaker){if(n===void 0)return;const r=e.faces.find(u=>u.id===n);return r?boxAt(r.samples,e.fps,t):void 0}function facesAt(e,t){return e.faces.flatMap(n=>{const r=boxAt(n.samples,e.fps,t);return r?[{id:n.id,box:r}]:[]})}function hasFace(e,t){return e.faces.some(n=>n.id===t)}var EXT={png:"image",jpg:"image",jpeg:"image",webp:"image",gif:"image",svg:"image",avif:"image",mp3:"audio",wav:"audio",m4a:"audio",ogg:"audio",aac:"audio",flac:"audio",mp4:"video",webm:"video",mov:"video",m4v:"video",qt:"video",woff2:"font",woff:"font",ttf:"font",otf:"font",glb:"model",gltf:"model",bin:"model",ktx2:"model",hdr:"environment",exr:"environment"},MEDIA_EXTENSIONS=Object.keys(EXT);function repoPath(e,t){return pathIn(e.split("/").slice(0,-1).join("/"),t)}function pathIn(e,t){const n=t.startsWith("/")||e===""?[]:e.split("/");for(const r of t.split("/"))if(!(r==="."||r===""))if(r===".."){if(n.length===0)return;n.pop()}else n.push(r);return n.join("/")}var KIND={"**":"strong","*":"em","~~":"strike","`":"code"},TOKEN=/\\([\\*~`])|\*\*|~~|\*|`/g,SPACE=/\s/u;function tokens(e){const t=[];let n=0;for(const r of e.matchAll(TOKEN)){if(r.index>n&&t.push({kind:"text",text:e.slice(n,r.index)}),n=r.index+r[0].length,r[1]!==void 0){t.push({kind:"escape",text:r[1]});continue}const u=e[r.index-1],i=e[n];t.push({kind:"delim",text:r[0],opens:i!==void 0&&!SPACE.test(i),closes:u!==void 0&&!SPACE.test(u)})}return n<e.length&&t.push({kind:"text",text:e.slice(n)}),t}var hasMarks=e=>/[*~`\\]/.test(e);function readMarks(e){if(!hasMarks(e))return{text:e,marks:[]};const t=tokens(e),n=[];for(let o=0;o<t.length;o++){const a=t[o];if(a?.kind!=="delim")continue;if(a.text==="`"){const d=t.findIndex((m,h)=>h>o&&m.kind==="delim"&&m.text==="`");if(d<0)continue;const f=t[d];a.pair=d,f?.kind==="delim"&&(f.pair=o),o=d;continue}let s=-1;if(a.closes)for(let d=n.length-1;d>=0&&s<0;d--)t[n[d]??-1]?.text===a.text&&(s=d);const c=n[s],l=c===void 0?void 0:t[c];c!==void 0&&l?.kind==="delim"&&c<o-1?(l.pair=o,a.pair=c,n.length=s):a.opens&&n.push(o)}let r="";const u=[],i=new Map;for(let o=0;o<t.length;o++){const a=t[o];if(!a)continue;if(a.kind!=="delim"){r+=a.text;continue}if(a.pair===void 0){r+=a.text;continue}const s=KIND[a.text];if(s===void 0)continue;if(a.pair>o){if(i.set(o,r.length),s!=="code")continue;for(let l=o+1;l<a.pair;l++){const d=t[l];d&&(r+=d.kind==="escape"?`\\${d.text}`:d.text)}o=a.pair-1;continue}const c=i.get(a.pair);c!==void 0&&r.length>c&&u.push({at:c,end:r.length,kind:s})}return u.sort((o,a)=>o.at-a.at||a.end-o.end),{text:r,marks:u}}var withoutMarks=e=>readMarks(e).text,RULES={"AK-M001":{level:"error",rule:"The fields of video(), slides() or defineComponent do not match the format"},"AK-M002":{level:"error",rule:"A piece is not the entry file of an item folder"},"AK-M003":{level:"error",rule:"An item's entry file does not match its folder or its kind"},"AK-M004":{level:"error",rule:"The project has no pieces"},"AK-M006":{level:"error",rule:"A messages file does not match the format"},"AK-M007":{level:"error",rule:"A script file does not match the format"},"AK-M008":{level:"error",rule:"A doc's file is not MDX, holds what a doc does not draw, or is not an item of its own"},"AK-M009":{level:"error",rule:"A sheet cannot be read as it says: its file is not CSV a sheet can read, a value is not its column's type, or its spec does not match the format"},"AK-M010":{level:"error",rule:"A video item reaches itself through the videos it shows (a screen, a video take, a footage of a video item)"},"AK-B001":{level:"error",rule:"Two pieces have the same id"},"AK-B003":{level:"error",rule:"The build made a network request"},"AK-B004":{level:"error",rule:"The build timed out, or its result is over the size limit"},"AK-B005":{level:"error",rule:"An import of a file outside the project, or of a package not declared in package.json"},"AK-B006":{level:"error",rule:"An import of an @allyhub/sdk entry point that does not exist"},"AK-B008":{level:"error",rule:"The project's @allyhub/sdk is another version than the allyhub that builds it"},"AK-B009":{level:"error",rule:"The project's package.json declares AllyHub, but its packages are not installed"},"AK-K001":{level:"error",rule:"Two parts have the same key"},"AK-K003":{level:"error",rule:"The output has no parts"},"AK-D002":{level:"error",rule:"The same frame has different pixels when drawn in order and out of order"},"AK-N003":{level:"error",rule:"The sandbox blocked a request at run time"},"AK-S001":{level:"error",rule:"The code reads a key that is missing in the default language too"},"AK-T001":{level:"error",rule:"A take has no word times beside it (<name>.words.json)"},"AK-T002":{level:"error",rule:"A say part has no generated file for its text, voice and tool"},"AK-T003":{level:"error",rule:"A take's range phrase, or the line a part is saying, is not found in the take"},"AK-T004":{level:"error",rule:"A word reference is not in its part's words, or an anchor is not in its line"},"AK-T005":{level:"error",rule:"A take's edits file is missing or does not match the format, or an edit's words are no longer in the take"},"AK-T006":{level:"error",rule:"A take's range phrase, or the line a part is saying, is said in words the take's edits remove"},"AK-T007":{level:"error",rule:"A part says a line its generated voice was not made from"},"AK-F001":{level:"error",rule:"The video is longer than its platform profile takes"},"AK-A001":{level:"error",rule:"A referenced media or data file does not exist"},"AK-A003":{level:"error",rule:"Wrong media type"},"AK-A005":{level:"error",rule:"A layer draws a picture that does not load: its source is not a file the stage serves, or not a picture"},"AK-P002":{level:"error",rule:"Loading took longer than the piece's loadLimit (default 10 seconds)"},"AK-P003":{level:"error",rule:"A moment did not finish drawing within the piece's seekLimit (default 30 seconds): work a layer waits for (ctx.wait) or a picture it shows never settled"},"AK-R001":{level:"error",rule:"An unhandled exception was thrown at run time"},"AK-R003":{level:"error",rule:"The page was changed outside the stage"},"AK-R004":{level:"error",rule:"The code sets a style value the browser does not accept, so the style does not apply"},"AK-G001":{level:"error",rule:"Unknown format: not one of the four presets or WIDTHxHEIGHT (a4 and letter for paged outputs only, and even sides for video)"},"AK-X001":{level:"error",rule:"The matrix's slots, structures, rules or combos name something that does not exist, or a combo lacks a slot of its structure"},"AK-X002":{level:"error",rule:"The matrix's rules leave no combination to make, or rule out a combo matrix.combos names"},"AK-X004":{level:"error",rule:"Two chosen combos are the same, or more alike than the matrix's differ allows"},"AK-X005":{level:"error",rule:"A part reads another slot's pick, so one render of it cannot serve every combo"},"AK-X006":{level:"error",rule:"A combo is longer than its output's maxDuration"},"AK-W001":{level:"error",rule:"A scenery does not build: its module's export is not a scenery, its build throws or does not finish, or its update throws"},"AK-W002":{level:"error",rule:"WebGL cannot be made or is lost, or draws on something other than SwiftShader where the CPU was asked for (--cpu, ALLYHUB_GPU=0, or the default off macOS)"},"AK-W003":{level:"error",rule:"A model, texture, environment or splat file does not load, names a file that is not there, or needs a decoder AllyHub does not lend"},"AK-W004":{level:"error",rule:"A camera cannot be drawn: a number that is not finite, a target at its position, a view along its up, a field of view outside (0°, 180°), or near and far planes out of order"},"AK-W005":{level:"error",rule:"A name a camera, a move or a measurement refers to names no object in the scenery, or names two"},"AK-W006":{level:"error",rule:"A material's shader does not compile or link on this renderer, or needs more texture units than the renderer has, so what uses it draws nothing (warn: more than the 16 a GPU may have)"},"AK-W008":{level:"error",rule:"A screen drawn in the scenery cannot show its element as it is: an element of it is in the browser's top layer (a modal dialog, a popover), planes of a preserve-3d context overlap, its element is larger than the largest texture, or its picture could not be copied"},"AK-S002":{level:"warn",rule:"Missing translation"},"AK-L002":{level:"warn",rule:"Text overflows the frame or is clipped"},"AK-L003":{level:"warn",rule:"Missing glyphs"},"AK-L006":{level:"warn",rule:"Text is drawn in a fallback font, or in a bold or italic the font does not have"},"AK-W007":{level:"warn",rule:"A screen asked to be drawn in the scenery is drawn over it, unlit and untoned: this browser cannot draw an element into a canvas (Chrome's HTML-in-Canvas), or ALLYHUB_HTML_IN_CANVAS=0"}};function problem(e,t,n={}){const{level:r,...u}=n;return{code:e,level:r??RULES[e].level,message:t,...u}}var round3=e=>Math.round(e*1e3)/1e3;function frameStarts(e,t,n){const r=o=>Math.round(o*n)/n,u=e.map(r);for(let o=1;o<u.length;o++){const a=u[o-1]??0;(u[o]??0)<=a&&(u[o]=a+1/n)}const i=u.at(-1)??0;return{starts:u,end:Math.max(r(t),i+1/n)}}var voiced=e=>e.speechDur!==void 0&&e.speechDur>0;function overlapOf(e,t){const n=e[t]??0;if(!voiced(e)||!Number.isFinite(n)||n<=0)return 0;const r=(e.speechDur??0)/2+(t==="before"?e.lead:e.tail);return Math.min(n,r)}function timeParts(e,t={}){const n=e.map((g,D)=>({...g,before:D===0?0:g.before??0,after:D===e.length-1?0:g.after??0})),r=t.fps??FPS,u=t.beat??0,i=[];for(const g of n){const D=new Set((g.placed??[]).map(v=>v.name));for(const v of g.anchors??[])D.has(v.name)&&i.push(problem("AK-T004",`The anchor ${v.name} of part ${g.key} is both in the line it says (@{${v.name}}) and in the part's own anchors; "@${v.name}" is the part's own. Rename one of them.`,{part:g.key}))}const o=[];let a=0;for(const g of n){o.push(a);let D;if(voiced(g))D=g.lead+(g.speechDur??0)+g.tail-overlapOf(g,"before")-overlapOf(g,"after");else{D=g.dur;const v=t.snap?.(a+D,a);if(v!==void 0)D=v-a;else if(u>0&&!t.snap){const E=t.beatPhase??0;let y=E+Math.round((a+D-E)/u)*u;y<=a+1e-9&&(y+=u),D=y-a}}a+=Math.max(D,1/r)}const{starts:s,end:c}=frameStarts(o,a,r),l=n.map((g,D)=>{const v=s[D]??0;return{key:g.key,start:v,end:s[D+1]??c,...voiced(g)?{speechAt:round3(v+g.lead-overlapOf(g,"before"))}:{}}}),d=new Map,f=g=>{if(d.has(g))return d.get(g);const D=n[g],v=D?.script&&D.words?.length?new ScriptAlignment(new WordStream(D.words),[D.script]):void 0;return d.set(g,v),v};function m(g,D){const v=l[g],E=n[g];if(!v||!E)return;const y=E.anchors??[],b=E.placed??[],A=parseAnchorRef(D,new Set([...y,...b].map(j=>j.name)));if(!A)return;const B=v.end-v.start,$=j=>(i.push(problem("AK-T004",j,{part:E.key})),round3(B/2)),x=j=>round3(Math.min(B,Math.max(0,j))),_=b.find(j=>j.name===A.name);if(_)return A.end&&_.end===void 0?$(`"${D}" asks for the end of the anchor ${_.name} of part ${E.key}, which is a point. Give it as a stretch (anchors: { ${_.name}: [from, to] }), or use "@${_.name}".`):x((A.end?_.end??_.at:_.at)+A.shift);const F=y.find(j=>j.name===A.name);if(!F){const j=[...y,...b].map(R=>`@${R.name}`);return $(`The anchor "${D}" is not in the line part ${E.key} says, nor in the part's own anchors${j.length>0?` (its anchors: ${j.join(", ")})`:""}. Write @{${A.name}} before the word it is for, in the part's say in the item's script, in every language (the part must say that line, s("….say")); or give its seconds in the part: anchors: { ${A.name}: 1.2 }.`)}if(A.end&&F.end===void 0)return $(`"${D}" asks for the end of the anchor ${F.name} of part ${E.key}, which is a point. Write @{${F.name}}…@{/${F.name}} around the words in the script, or use "@${F.name}".`);const S=A.end?F.end??F.at:F.at,k=normText(E.script??"");if(E.pending===!0&&v.speechAt===void 0)return k.length===0?round3(B/2):x(S/k.length*B+A.shift);const w=E.words??[],I=f(g);if(v.speechAt===void 0||!I||w.length===0)return $(`The anchor "${D}" is in part ${E.key}, which has no speech. Give its seconds in the part instead: anchors: { ${A.name}: 1.2 }.`);const M=w.at(-1),P=A.end?w[I.wordAtChar(0,Math.max(0,S-1))]?.end:S>=k.length?M?.end:w[I.wordAtChar(0,S)]?.start;return x(v.speechAt+(P??0)+A.shift-v.start)}function h(g,D){const v=numericRef(D);if(v!==void 0)return v;const E=typeof D=="string"?m(g,D):void 0;if(E!==void 0)return E;const y=l[g],b=n[g];if(!y||!b)return 0;const A=y.end-y.start,B=b.words??[],{text:$,nth:x,shift:_}=parseWordRef(String(D));let F=-1;B.length>0&&(F=f(g)?.wordFor(0,$,x)??-1,F<0&&(F=new WordStream(B).find(normText($),0,B.length-1,x)));const S=B[F];if(b.pending===!0&&y.speechAt===void 0){const w=normText(b.script??"");let I=-1;for(let M=0;M<x;M++)I=w.indexOf(normText($),I+1);return I<0||w.length===0?round3(A/2):round3(Math.min(A,Math.max(0,I/w.length*A+_)))}if(F<0||!S||y.speechAt===void 0){const w=b.script??joinWords(B);return i.push(problem("AK-T004",y.speechAt===void 0?`The word reference "${String(D)}" is in part ${b.key}, which has no speech. Give it in seconds from the part's start instead.`:`The word reference "${String(D)}" is not in the words of part ${b.key}${w?` (it says: "${w.length>160?`${w.slice(0,160)}…`:w}")`:""}. Use a word the part says, as "word", "word@2" or "word+0.2".`,{part:b.key})),round3(A/2)}const k=y.speechAt+S.start+_;return round3(Math.min(A,Math.max(0,k-y.start)))}function p(g){const D=l[g],v=n[g];if(!D||!v||D.speechAt===void 0)return[];const E=D.speechAt-D.start;return(v.words??[]).map(y=>({text:y.text,start:round3(y.start+E),end:round3(y.end+E)}))}return{parts:l,duration:c,problems:i,at:h,words:p}}var MUSIC_DEFAULTS={seam:.03,meter:4,loopSeam:.25};function musicGrid(e,t={}){if(!e||!(e.bpm>0))return;const n=e.beat??0;return{beat:60/e.bpm,first:t.downbeat??n,meter:t.meter??MUSIC_DEFAULTS.meter,downbeat:t.downbeat??n}}function musicSeconds(e,t){if(typeof e=="number")return e;if(t)return"beat"in e?t.first+e.beat*t.beat:t.downbeat+e.bar*t.meter*t.beat}var onGrid=e=>typeof e!="number";function placeStretches(e,t,n,r){const u=[];let i=0;const o=a=>{const s=Math.max(0,a.from),c=Math.min(n,a.to);return c-s<.001?!1:(u.push({at:i,from:s,to:c}),i+=c-s,!0)};for(const a of e){if(i>=r)return u;o(a)}if(t)for(;i<r&&o(t););return u}function wholeLoop(e,t,n,r=MUSIC_DEFAULTS.loopSeam){const u=t>1?r:0,i=t-u;if(i<=0)return[];const o=[];let a=0,s=Math.max(0,e)%i;for(;a<n;)o.push({at:a,from:s,to:i}),a+=i-s,s=0;return o}function musicSegments(e,t,n,r="before",u=!0){const i=e.map(o=>({at:o.at,from:o.from,dur:o.to-o.from,fadeIn:0,fadeOut:0}));for(let o=0;o<i.length;o++){const a=i[o],s=e[o];if(!a||!s||t<=0)continue;const c=e[o+1],l=i[o+1],d=m=>Math.min(t,m.dur/2);if(!c||!l){u&&n-s.to>.001&&(a.fadeOut=d(a));continue}if(r==="after"){const m=Math.min(t,n-s.to);a.dur+=m,a.fadeOut=m,l.fadeIn=m;continue}a.fadeOut=d(a);const f=Math.min(t,c.from);l.at-=f,l.from-=f,l.dur+=f,l.fadeIn=f}return i}function filmBeats(e,t,n="beat"){const r=n==="bar"?t.beat*t.meter:t.beat,u=n==="bar"?t.downbeat:t.first,i=[];for(const o of e){let a=Math.ceil((o.from-u)/r-1e-9);for(;;){const s=u+a*r;if(s>=o.to-1e-9)break;s>=o.from-1e-9&&i.push(o.at+(s-o.from)),a++}}return i.sort((o,a)=>o-a)}function beatNear(e,t,n,r){const u=e.at(-1);if(u===void 0||!(t>0))return;let i;const o=a=>{a<=r+1e-9||(i===void 0||Math.abs(a-n)<Math.abs(i-n))&&(i=a)};for(const a of e)o(a);if(n+t>u){const a=Math.max(1,Math.round((n-u)/t));for(const s of[a-1,a,a+1])s>=1&&o(u+s*t)}if(i===void 0){const a=Math.max(1,Math.ceil((r-u)/t+1e-9));i=u+a*t}return i}var SAY_DIR=`${MEDIA_DIR}/gen/say`,DEFAULT_VOICE_TOOL="speech-elevenlabs-multilingual-v2";function hash64(e){let t=0xcbf29ce484222325n;const n=0x100000001b3n;for(const r of new TextEncoder().encode(e))t^=BigInt(r),t=t*n&0xffffffffffffffffn;return t.toString(16).padStart(16,"0")}function canonicalJson(e){if(Array.isArray(e))return`[${e.map(canonicalJson).join(",")}]`;if(typeof e=="object"&&e!==null){const t=e;return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${canonicalJson(t[n])}`).join(",")}}`}return JSON.stringify(e)}function sayStem(e){const t=e.tool??DEFAULT_VOICE_TOOL,n=e.params&&Object.keys(e.params).length>0?`
66
+ `;function baseOf(e){return e.slice(e.lastIndexOf("/")+1)}var CODE_EXTENSIONS=["ts","tsx","mts","js","jsx","mjs"],code=e=>CODE_EXTENSIONS.map(t=>`${e}.${t}`),ITEM_KINDS={video:{entries:code("video"),editor:"video",name:"video"},slides:{entries:code("slides"),editor:"slides",name:"slides"},doc:{entries:["doc.mdx"],editor:"doc",name:"doc"},sheet:{entries:["sheet.csv"],editor:"sheet",name:"sheet"},scenery:{entries:code("scenery"),editor:"scenery",name:"3D scenery"},model:{entries:code("model"),editor:"scenery",name:"3D model"},website:{entries:["astro.config.mjs","astro.config.ts","astro.config.mts","astro.config.js"],editor:"website",name:"website"}},KINDS=Object.keys(ITEM_KINDS),BY_ENTRY=new Map(KINDS.flatMap(e=>ITEM_KINDS[e].entries.map(t=>[t,e])));function entryKind(e){return BY_ENTRY.get(baseOf(e))}var SHA256=external_exports.string().regex(/^[0-9a-f]{64}$/u,"A sha256 is 64 lowercase hexadecimal digits."),SECONDS=external_exports.number().nonnegative(),INSTANT=external_exports.iso.datetime({offset:!0});function dataFile(e){return external_exports.strictObject({$schema:external_exports.string().optional(),...e})}var TargetSchema=external_exports.discriminatedUnion("type",[external_exports.strictObject({type:external_exports.literal("quote"),exact:external_exports.string().min(1),prefix:external_exports.string().optional(),suffix:external_exports.string().optional()}),external_exports.strictObject({type:external_exports.literal("cells"),range:external_exports.string().regex(/^[A-Z]+[1-9]\d*(?::[A-Z]+[1-9]\d*)?$/u)}),external_exports.strictObject({type:external_exports.literal("item")})]),AuthorSchema=external_exports.strictObject({kind:external_exports.enum(["person","agent"]),name:external_exports.string().min(1)}),CommentSchema=external_exports.strictObject({id:external_exports.string().min(1),author:AuthorSchema,text:external_exports.string().min(1),at:INSTANT}),ThreadSchema=external_exports.strictObject({id:external_exports.string().min(1),target:TargetSchema,resolved:external_exports.boolean().default(!1),comments:external_exports.array(CommentSchema).min(1)}),CommentsFileSchema=dataFile({version:external_exports.literal(1),threads:external_exports.array(ThreadSchema).default([])}),ConfigSchema=external_exports.strictObject({fonts:external_exports.array(external_exports.string().min(1)).default([]),text:external_exports.string().optional(),locales:external_exports.array(external_exports.string().min(2)).min(1).optional(),look:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),defaults:external_exports.record(external_exports.string(),external_exports.unknown()).optional()}),Stretch=external_exports.strictObject({from:SECONDS,to:SECONDS}).refine(e=>e.to>e.from,{message:"A stretch ends after its start.",path:["to"]}),PAD_MAX=2,PAD_SIDE=external_exports.number().min(0).max(PAD_MAX),EditsFileSchema=dataFile({version:external_exports.literal(1),take:external_exports.string().optional(),remove:external_exports.array(external_exports.strictObject({from:external_exports.int().nonnegative(),to:external_exports.int().nonnegative(),text:external_exports.string().optional()}).refine(e=>e.to>=e.from,{message:"A range ends at or after its start.",path:["to"]})).optional(),sounds:external_exports.array(Stretch).optional(),inWord:external_exports.array(Stretch).optional(),maxPause:external_exports.number().min(.05).max(10).optional(),pad:external_exports.strictObject({before:PAD_SIDE.optional(),after:PAD_SIDE.optional()}).optional()}),ElementBoxSchema=external_exports.tuple([external_exports.number(),external_exports.number(),external_exports.number().nonnegative(),external_exports.number().nonnegative()]),ElementsFileSchema=external_exports.record(external_exports.string().min(1),ElementBoxSchema),Omitted=external_exports.strictObject({omitted:external_exports.literal(!0),sha256:SHA256,bytes:external_exports.int().nonnegative()}),GenFileSchema=dataFile({version:external_exports.literal(1),ai:external_exports.boolean(),tool:external_exports.string().optional(),model:external_exports.string().optional(),input:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),inputHash:SHA256.optional(),output:external_exports.record(external_exports.string(),external_exports.unknown()).optional(),credits:external_exports.number().nonnegative().optional(),at:INSTANT,sha256:SHA256,bytes:external_exports.int().nonnegative(),source:external_exports.strictObject({library:external_exports.string(),page:external_exports.url(),authors:external_exports.array(external_exports.string()).default([]),license:external_exports.string()}).optional()}),MESSAGE_KEY=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/u,SpokenSchema=external_exports.strictObject({display:external_exports.string(),speak:external_exports.string()}),VariantsSchema=external_exports.strictObject({declarations:external_exports.array(external_exports.string()).default([]),selectors:external_exports.array(external_exports.string()).default([]),match:external_exports.record(external_exports.string(),external_exports.string()).refine(e=>Object.keys(e).length>0,"A match needs at least one case.")}),MessageSchema=external_exports.union([external_exports.string(),SpokenSchema,external_exports.tuple([VariantsSchema])]),MessagesFileSchema=external_exports.record(external_exports.string(),external_exports.unknown()).superRefine((e,t)=>{for(const[n,r]of Object.entries(e)){if(n==="$schema"){typeof r!="string"&&t.addIssue({code:"custom",path:[n],message:"$schema is a string."});continue}MESSAGE_KEY.test(n)||t.addIssue({code:"custom",path:[n],message:`"${n}" is not a message key: letters, digits, _ and -, in segments joined by dots.`});const u=MessageSchema.safeParse(r);u.success||t.addIssue({code:"custom",path:[n],message:Array.isArray(r)?`A message with variants is [{ "declarations": […], "selectors": […], "match": {…} }]: ${u.error.issues.map(i=>i.message).join("; ")}`:"A message is a string, { display, speak }, or [{ declarations, selectors, match }]."})}}).transform(e=>{const t={...e};return delete t.$schema,t}),SHARE_BOX=external_exports.tuple([external_exports.number(),external_exports.number(),external_exports.number(),external_exports.number()]),SCORED=external_exports.object({t:SECONDS,score:external_exports.number()}),MAYBE=external_exports.number().nullable(),COUNT=external_exports.number().int().nonnegative(),ReferenceSentenceSchema=external_exports.object({index:COUNT,start:SECONDS,end:SECONDS,words:external_exports.tuple([external_exports.number().int(),external_exports.number().int()]),text:external_exports.string(),punctuation:external_exports.boolean(),pauseAfter:SECONDS.optional()}),ReferenceGapSchema=external_exports.object({after:COUNT,start:SECONDS,end:SECONDS,dur:SECONDS}),ReferenceBoundarySchema=external_exports.object({t:SECONDS,cut:SCORED.optional(),weak:SCORED.optional(),pause:external_exports.object({start:SECONDS,end:SECONDS,dur:SECONDS}).optional(),sentence:COUNT.optional()}),ReferenceTextSchema=external_exports.object({id:COUNT,text:external_exports.string(),box:SHARE_BOX,height:external_exports.number(),conf:external_exports.number(),words:COUNT,upper:external_exports.number().min(0).max(1),start:SECONDS,end:SECONDS,spans:external_exports.array(external_exports.tuple([SECONDS,SECONDS])),seconds:SECONDS,seen:external_exports.number().int().positive(),frames:external_exports.number().min(0).max(1),spread:external_exports.number().min(0).max(1),said:external_exports.number().min(0).max(1)}),SectionNumbersSchema=external_exports.object({start:SECONDS,end:SECONDS,dur:SECONDS,said:external_exports.string(),words:COUNT,wordsPerMinute:external_exports.number().nonnegative(),cuts:external_exports.array(SECONDS),shots:external_exports.number().int().positive(),cutsPerMinute:external_exports.number().nonnegative(),text:external_exports.array(COUNT),textSeconds:SECONDS}),ReferenceSegmentSchema=SectionNumbersSchema.extend({index:COUNT,name:external_exports.string(),sentences:external_exports.tuple([external_exports.number().int(),external_exports.number().int()]).optional()}),ReferencePacingSchema=external_exports.object({cutsPerMinute:external_exports.number().nonnegative(),meanShot:SECONDS,medianShot:SECONDS,wordsPerMinute:external_exports.number().nonnegative(),speakingRate:external_exports.number().nonnegative(),timeToFirstWord:SECONDS.optional(),timeToFirstCut:SECONDS.optional(),textShare:external_exports.number().min(0).max(1),speechShare:external_exports.number().min(0).max(1),tempo:external_exports.object({bpm:external_exports.number().positive(),confidence:external_exports.number().min(0),candidates:external_exports.array(external_exports.object({bpm:external_exports.number(),r:external_exports.number(),score:external_exports.number()})).optional(),prior:external_exports.number().optional()}).optional(),onsetsPerMinute:external_exports.number().nonnegative()}),LEVELS=external_exports.object({seconds:SECONDS,p10:external_exports.number(),median:external_exports.number(),p90:external_exports.number()}),ReferenceSoundSchema=external_exports.object({gap:SECONDS,edge:SECONDS,voiced:external_exports.number().min(0).max(100),whole:LEVELS,words:LEVELS.optional(),between:LEVELS.extend({voicedShare:external_exports.number().min(0).max(1),onsetsPerMinute:external_exports.number().nonnegative()}).optional(),floor:external_exports.number()}),ReferencePictureSchema=external_exports.object({params:external_exports.record(external_exports.string(),external_exports.unknown()),frames:external_exports.object({tone:COUNT,color:COUNT,motion:COUNT}),luma:external_exports.object({p1:MAYBE,p50:MAYBE,p99:MAYBE}),blackShare:MAYBE,noise:MAYBE,sharpness:MAYBE,saturation:MAYBE,warmth:MAYBE,motion:external_exports.object({speed:external_exports.object({p50:MAYBE,p90:MAYBE}),shake:external_exports.object({p50:MAYBE,p90:MAYBE}),stillShare:MAYBE,runs:COUNT}),sharpnessBySpeed:external_exports.array(external_exports.object({from:external_exports.number(),to:MAYBE,frames:COUNT,sharpness:MAYBE})),noiseByLuma:external_exports.array(external_exports.object({from:external_exports.number(),to:external_exports.number(),blocks:COUNT,noise:MAYBE,median:MAYBE})),shake:external_exports.array(external_exports.object({start:SECONDS,end:SECONDS,rms:external_exports.number(),peaks:external_exports.array(external_exports.object({hz:external_exports.number(),share:external_exports.number()})),flatness:external_exports.number()}))}),BANDWIDTH=external_exports.object({frames:COUNT,reach:external_exports.array(external_exports.object({drop:external_exports.number(),hz:MAYBE})),rolloff95:MAYBE,rolloff99:MAYBE,steps:external_exports.array(external_exports.object({hz:external_exports.number(),db:external_exports.number()}))}),ReferenceAudioSchema=external_exports.object({loudness:external_exports.object({integrated:MAYBE,range:MAYBE,truePeak:MAYBE}),recording:external_exports.object({params:external_exports.record(external_exports.string(),external_exports.unknown()),spectrum:external_exports.array(external_exports.object({hz:external_exports.number(),db:external_exports.number()})),dynamics:external_exports.object({spread:external_exports.number(),crest:external_exports.number()})}).loose(),bandwidth:BANDWIDTH.extend({params:external_exports.record(external_exports.string(),external_exports.unknown())}),voice:BANDWIDTH.optional()}),ReferenceServedSchema=external_exports.object({item:external_exports.string(),combo:external_exports.record(external_exports.string(),external_exports.string()),format:external_exports.string(),platform:external_exports.string().optional(),export:external_exports.object({type:external_exports.string(),crf:external_exports.number().optional(),maxKbps:external_exports.number().optional()}),video:external_exports.object({codec:external_exports.string(),profile:external_exports.string().optional(),kbps:external_exports.number(),width:external_exports.number().int().positive(),height:external_exports.number().int().positive(),fps:external_exports.number().positive(),preset:external_exports.string().optional()}).optional(),audio:external_exports.union([external_exports.object({codec:external_exports.string(),kbps:external_exports.number(),rate:external_exports.number(),channels:external_exports.number()}),external_exports.object({missing:external_exports.string(),instead:external_exports.string()})]),joins:external_exports.array(external_exports.object({t:SECONDS,kind:external_exports.string(),part:external_exports.string().optional(),score:external_exports.number(),margin:external_exports.number(),cut:external_exports.boolean()})),unmeant:external_exports.array(external_exports.object({t:SECONDS,score:external_exports.number(),margin:external_exports.number()}))}),ReferenceSchema=external_exports.object({version:external_exports.literal(1),id:external_exports.string(),source:external_exports.object({file:external_exports.string(),url:external_exports.string().optional(),title:external_exports.string().optional(),sha256:SHA256}),analysedAt:external_exports.string(),duration:SECONDS,width:external_exports.number().int().positive(),height:external_exports.number().int().positive(),fps:external_exports.number().positive(),encoding:external_exports.object({codec:external_exports.string().optional(),bitrate:external_exports.number().positive().optional(),audio:external_exports.object({codec:external_exports.string().optional(),profile:external_exports.string().optional(),bitrate:external_exports.number().positive().optional(),rate:external_exports.number().positive().optional(),channels:external_exports.number().int().positive().optional()}).optional()}).optional(),words:external_exports.string().optional(),wordCount:COUNT,asr:external_exports.string().optional(),wordsMissing:external_exports.object({code:external_exports.string().optional(),message:external_exports.string(),hint:external_exports.string().optional(),instead:external_exports.string()}).optional(),shots:external_exports.object({threshold:external_exports.number().min(0).max(1),minShot:external_exports.number().nonnegative(),weakFloor:external_exports.number().min(0).max(1),prominence:external_exports.number().nonnegative(),cuts:external_exports.array(SCORED),weak:external_exports.array(SCORED),candidates:external_exports.array(external_exports.object({t:SECONDS,score:external_exports.number(),source:external_exports.enum(["jump","change"]),around:external_exports.number(),passes:external_exports.boolean()})).optional()}),speech:external_exports.object({pause:SECONDS,sentences:external_exports.array(ReferenceSentenceSchema),pauses:external_exports.array(ReferenceGapSchema),gaps:external_exports.array(ReferenceGapSchema).optional()}),boundaries:external_exports.object({cutWithin:SECONDS,candidates:external_exports.array(ReferenceBoundarySchema)}),ocr:external_exports.object({engine:external_exports.string(),confidence:external_exports.object({word:external_exports.number().min(0).max(100),short:external_exports.number().min(0).max(100)}),frames:COUNT,samePlace:external_exports.number(),saidWithin:SECONDS,low:external_exports.array(external_exports.object({t:SECONDS,text:external_exports.string(),conf:external_exports.number(),box:SHARE_BOX})).optional()}),text:external_exports.array(ReferenceTextSchema),pacing:ReferencePacingSchema,sound:ReferenceSoundSchema.optional(),segments:external_exports.object({rule:external_exports.string(),pause:SECONDS,cutWithin:SECONDS,minLength:SECONDS,list:external_exports.array(ReferenceSegmentSchema).min(1)}),sheets:external_exports.array(external_exports.string()),picture:ReferencePictureSchema,audio:ReferenceAudioSchema.optional(),served:ReferenceServedSchema.optional()}),InterpretedSectionSchema=external_exports.strictObject({start:SECONDS,end:SECONDS,name:external_exports.string().min(1).optional(),role:external_exports.string().min(1).optional(),picture:external_exports.string().optional(),onScreen:external_exports.array(external_exports.string()).optional(),notes:external_exports.string().optional()}),InterpretationSchema=dataFile({version:external_exports.literal(1).default(1),summary:external_exports.string().optional(),layout:external_exports.string().optional(),hook:external_exports.string().optional(),sections:external_exports.array(InterpretedSectionSchema).min(1),captions:external_exports.strictObject({lines:external_exports.array(COUNT).optional(),style:external_exports.string().optional()}).optional(),watermarks:external_exports.array(COUNT).optional(),notes:external_exports.string().optional(),labels:external_exports.record(external_exports.string(),external_exports.union([external_exports.string(),external_exports.number(),external_exports.boolean(),external_exports.array(external_exports.string())])).optional()}),SCRIPT_NAME=/^[A-Za-z0-9_-]+$/u,NamedSchema=external_exports.string().regex(SCRIPT_NAME,"A name is letters, digits, _ and -."),ScriptTextSchema=external_exports.lazy(()=>external_exports.union([external_exports.string(),SpokenSchema,VariantsSchema,external_exports.array(ScriptTextSchema),external_exports.record(NamedSchema,ScriptTextSchema)])),ScriptPartSchema=external_exports.strictObject({id:NamedSchema,say:external_exports.union([external_exports.string(),VariantsSchema]).optional(),screen:external_exports.record(NamedSchema,ScriptTextSchema).optional()}),ScriptFileSchema=external_exports.strictObject({title:external_exports.string().optional(),text:external_exports.record(NamedSchema,ScriptTextSchema).optional(),parts:external_exports.array(ScriptPartSchema).default([])}).superRefine((e,t)=>{const n=new Set;e.parts.forEach((r,u)=>{n.has(r.id)&&t.addIssue({code:"custom",path:["parts",u,"id"],message:`Two parts are "${r.id}".`}),n.add(r.id)})}),COLUMN_TYPES=["text","number","select","multi-select","date","checkbox","url","email","phone","file"],OPTION_COLORS=["gray","brown","red","orange","yellow","green","blue","purple","pink"],ColumnName=external_exports.string().regex(/\S/u),Option=external_exports.union([external_exports.string().regex(/\S/u),external_exports.number(),external_exports.boolean(),external_exports.strictObject({name:external_exports.union([external_exports.string().regex(/\S/u),external_exports.number()]),color:external_exports.enum(OPTION_COLORS).optional()})]),nameOf=e=>String(typeof e=="object"?e.name:e).trim(),Separator=external_exports.string().regex(/^[^"]*[^"\s][^"]*$/u),NumberStyle=external_exports.enum(["plain","percent","currency"]),NumberFormat=external_exports.union([NumberStyle,external_exports.strictObject({style:NumberStyle.nullable().optional(),decimals:external_exports.int().min(0).max(10).optional(),currency:external_exports.string().regex(/^[A-Za-z]{3}$/u).optional(),thousands:external_exports.boolean().optional()})]),DateStyle=external_exports.enum(["iso","short","long"]),DateFormat=external_exports.union([DateStyle,external_exports.strictObject({style:DateStyle.nullable().optional(),time:external_exports.boolean().optional()})]),common={width:external_exports.number().positive().optional(),wrap:external_exports.boolean().optional()};function checkOptions(e,t){const n=e.separator??";",r=new Set;(e.options??[]).forEach((u,i)=>{const o=nameOf(u);o.includes(n)&&t.addIssue({code:"custom",path:["options",i],message:`"${o}" has the separator ${JSON.stringify(n)} in it`}),r.has(o)&&t.addIssue({code:"custom",path:["options",i],message:`"${o}" is an option twice`}),r.add(o)})}var ColumnFields=external_exports.union([external_exports.strictObject({type:external_exports.enum(["text","checkbox","url","email","phone"]).nullable().optional(),...common}),external_exports.strictObject({type:external_exports.literal("number"),format:NumberFormat.optional(),...common}),external_exports.strictObject({type:external_exports.literal("date"),format:DateFormat.optional(),...common}),external_exports.strictObject({type:external_exports.literal("select"),options:external_exports.array(Option).optional(),...common}).superRefine(checkOptions),external_exports.strictObject({type:external_exports.literal("multi-select"),options:external_exports.array(Option).optional(),separator:Separator.optional(),...common}).superRefine(checkOptions),external_exports.strictObject({type:external_exports.literal("file"),separator:Separator.optional(),height:external_exports.number().positive().optional(),...common})]),ColumnSchema=external_exports.union([external_exports.null(),external_exports.enum(COLUMN_TYPES),ColumnFields]),SheetSpecSchema=external_exports.union([external_exports.null(),external_exports.strictObject({title:external_exports.union([external_exports.string(),external_exports.number()]).optional(),key:ColumnName.optional(),primary:ColumnName.optional(),columns:external_exports.union([external_exports.null(),external_exports.record(external_exports.string(),ColumnSchema)]).optional()})]),WordSchema=external_exports.strictObject({text:external_exports.string().min(1),start:SECONDS,end:SECONDS,confidence:external_exports.number().min(0).max(1).optional()}).refine(e=>e.end>=e.start,{message:"A word ends at or after its start.",path:["end"]}),WordsFileSchema=dataFile({version:external_exports.literal(1),language:external_exports.string().min(2).optional(),duration:SECONDS.optional(),model:external_exports.string().optional(),words:external_exports.array(WordSchema)}).refine(e=>e.words.every((t,n)=>n===0||t.start>=(e.words[n-1]?.start??0)),{message:"Words are in the order they are said.",path:["words"]});function asUrlString(e){return Object.prototype.hasOwnProperty.call(e,"toString")||Object.defineProperty(e,"toString",{value(){return this.url},enumerable:!1,configurable:!0,writable:!0}),e}var INDEX_DIR=`${CACHE_DIR}/index`;function boxAt(e,t,n){const r=e[0],u=e.at(-1);if(!r||!u)return;const i=1/Math.max(1,t);if(n<r.t-i||n>u.t+i)return;if(n<=r.t)return r.box;if(n>=u.t)return u.box;let o=0,a=e.length-1;for(;a-o>1;){const d=o+a>>1;(e[d]?.t??0)<=n?o=d:a=d}const s=e[o]??r,c=e[a]??u,l=c.t===s.t?0:(n-s.t)/(c.t-s.t);return[0,1,2,3].map(d=>(s.box[d]??0)+((c.box[d]??0)-(s.box[d]??0))*l)}function faceAt(e,t,n=e.speaker){if(n===void 0)return;const r=e.faces.find(u=>u.id===n);return r?boxAt(r.samples,e.fps,t):void 0}function facesAt(e,t){return e.faces.flatMap(n=>{const r=boxAt(n.samples,e.fps,t);return r?[{id:n.id,box:r}]:[]})}function hasFace(e,t){return e.faces.some(n=>n.id===t)}var EXT={png:"image",jpg:"image",jpeg:"image",webp:"image",gif:"image",svg:"image",avif:"image",mp3:"audio",wav:"audio",m4a:"audio",ogg:"audio",aac:"audio",flac:"audio",mp4:"video",webm:"video",mov:"video",m4v:"video",qt:"video",woff2:"font",woff:"font",ttf:"font",otf:"font",glb:"model",gltf:"model",bin:"model",ktx2:"model",hdr:"environment",exr:"environment"},MEDIA_EXTENSIONS=Object.keys(EXT);function repoPath(e,t){return pathIn(e.split("/").slice(0,-1).join("/"),t)}function pathIn(e,t){const n=t.startsWith("/")||e===""?[]:e.split("/");for(const r of t.split("/"))if(!(r==="."||r===""))if(r===".."){if(n.length===0)return;n.pop()}else n.push(r);return n.join("/")}var KIND={"**":"strong","*":"em","~~":"strike","`":"code"},TOKEN=/\\([\\*~`])|\*\*|~~|\*|`/g,SPACE=/\s/u;function tokens(e){const t=[];let n=0;for(const r of e.matchAll(TOKEN)){if(r.index>n&&t.push({kind:"text",text:e.slice(n,r.index)}),n=r.index+r[0].length,r[1]!==void 0){t.push({kind:"escape",text:r[1]});continue}const u=e[r.index-1],i=e[n];t.push({kind:"delim",text:r[0],opens:i!==void 0&&!SPACE.test(i),closes:u!==void 0&&!SPACE.test(u)})}return n<e.length&&t.push({kind:"text",text:e.slice(n)}),t}var hasMarks=e=>/[*~`\\]/.test(e);function readMarks(e){if(!hasMarks(e))return{text:e,marks:[]};const t=tokens(e),n=[];for(let o=0;o<t.length;o++){const a=t[o];if(a?.kind!=="delim")continue;if(a.text==="`"){const d=t.findIndex((m,h)=>h>o&&m.kind==="delim"&&m.text==="`");if(d<0)continue;const f=t[d];a.pair=d,f?.kind==="delim"&&(f.pair=o),o=d;continue}let s=-1;if(a.closes)for(let d=n.length-1;d>=0&&s<0;d--)t[n[d]??-1]?.text===a.text&&(s=d);const c=n[s],l=c===void 0?void 0:t[c];c!==void 0&&l?.kind==="delim"&&c<o-1?(l.pair=o,a.pair=c,n.length=s):a.opens&&n.push(o)}let r="";const u=[],i=new Map;for(let o=0;o<t.length;o++){const a=t[o];if(!a)continue;if(a.kind!=="delim"){r+=a.text;continue}if(a.pair===void 0){r+=a.text;continue}const s=KIND[a.text];if(s===void 0)continue;if(a.pair>o){if(i.set(o,r.length),s!=="code")continue;for(let l=o+1;l<a.pair;l++){const d=t[l];d&&(r+=d.kind==="escape"?`\\${d.text}`:d.text)}o=a.pair-1;continue}const c=i.get(a.pair);c!==void 0&&r.length>c&&u.push({at:c,end:r.length,kind:s})}return u.sort((o,a)=>o.at-a.at||a.end-o.end),{text:r,marks:u}}var withoutMarks=e=>readMarks(e).text,RULES={"AK-M001":{level:"error",rule:"The fields of video(), slides() or defineComponent do not match the format"},"AK-M002":{level:"error",rule:"A piece is not the entry file of an item folder"},"AK-M003":{level:"error",rule:"An item's entry file does not match its folder or its kind"},"AK-M004":{level:"error",rule:"The project has no pieces"},"AK-M006":{level:"error",rule:"A messages file does not match the format"},"AK-M007":{level:"error",rule:"A script file does not match the format"},"AK-M008":{level:"error",rule:"A doc's file is not MDX, holds what a doc does not draw, or is not an item of its own"},"AK-M009":{level:"error",rule:"A sheet cannot be read as it says: its file is not CSV a sheet can read, a value is not its column's type, or its spec does not match the format"},"AK-M010":{level:"error",rule:"A video item reaches itself through the videos it shows (a screen, a video take, a footage of a video item)"},"AK-B001":{level:"error",rule:"Two pieces have the same id"},"AK-B003":{level:"error",rule:"The build made a network request"},"AK-B004":{level:"error",rule:"The build timed out, or its result is over the size limit"},"AK-B005":{level:"error",rule:"An import of a file outside the project, or of a package not declared in package.json"},"AK-B006":{level:"error",rule:"An import of an @allyhub/sdk entry point that does not exist"},"AK-B008":{level:"error",rule:"The project's @allyhub/sdk is another version than the allyhub that builds it"},"AK-B009":{level:"error",rule:"The project's package.json declares AllyHub, but its packages are not installed"},"AK-B010":{level:"error",rule:"A 3D model does not build"},"AK-K001":{level:"error",rule:"Two parts have the same key"},"AK-K003":{level:"error",rule:"The output has no parts"},"AK-D002":{level:"error",rule:"The same frame has different pixels when drawn in order and out of order"},"AK-N003":{level:"error",rule:"The sandbox blocked a request at run time"},"AK-S001":{level:"error",rule:"The code reads a key that is missing in the default language too"},"AK-T001":{level:"error",rule:"A take has no word times beside it (<name>.words.json)"},"AK-T002":{level:"error",rule:"A say part has no generated file for its text, voice and tool"},"AK-T003":{level:"error",rule:"A take's range phrase, or the line a part is saying, is not found in the take"},"AK-T004":{level:"error",rule:"A word reference is not in its part's words, or an anchor is not in its line"},"AK-T005":{level:"error",rule:"A take's edits file is missing or does not match the format, or an edit's words are no longer in the take"},"AK-T006":{level:"error",rule:"A take's range phrase, or the line a part is saying, is said in words the take's edits remove"},"AK-T007":{level:"error",rule:"A part says a line its generated voice was not made from"},"AK-F001":{level:"error",rule:"The video is longer than its platform profile takes"},"AK-A001":{level:"error",rule:"A referenced media or data file does not exist"},"AK-A003":{level:"error",rule:"Wrong media type"},"AK-A005":{level:"error",rule:"A layer draws a picture that does not load: its source is not a file the stage serves, or not a picture"},"AK-P002":{level:"error",rule:"Loading took longer than the piece's loadLimit (default 10 seconds)"},"AK-P003":{level:"error",rule:"A moment did not finish drawing within the piece's seekLimit (default 30 seconds): work a layer waits for (ctx.wait) or a picture it shows never settled"},"AK-R001":{level:"error",rule:"An unhandled exception was thrown at run time"},"AK-R003":{level:"error",rule:"The page was changed outside the stage"},"AK-R004":{level:"error",rule:"The code sets a style value the browser does not accept, so the style does not apply"},"AK-G001":{level:"error",rule:"Unknown format: not one of the four presets or WIDTHxHEIGHT (a4 and letter for paged outputs only, and even sides for video)"},"AK-X001":{level:"error",rule:"The matrix's slots, structures, rules or combos name something that does not exist, or a combo lacks a slot of its structure"},"AK-X002":{level:"error",rule:"The matrix's rules leave no combination to make, or rule out a combo matrix.combos names"},"AK-X004":{level:"error",rule:"Two chosen combos are the same, or more alike than the matrix's differ allows"},"AK-X005":{level:"error",rule:"A part reads another slot's pick, so one render of it cannot serve every combo"},"AK-X006":{level:"error",rule:"A combo is longer than its output's maxDuration"},"AK-W001":{level:"error",rule:"A scenery does not build: its module's export is not a scenery, its build throws or does not finish, or its update throws"},"AK-W002":{level:"error",rule:"WebGL cannot be made or is lost, or draws on something other than SwiftShader where the CPU was asked for (--cpu, ALLYHUB_GPU=0, or the default off macOS)"},"AK-W003":{level:"error",rule:"A model, texture, environment or splat file does not load, names a file that is not there, or needs a decoder AllyHub does not lend"},"AK-W004":{level:"error",rule:"A camera cannot be drawn: a number that is not finite, a target at its position, a view along its up, a field of view outside (0°, 180°), or near and far planes out of order"},"AK-W005":{level:"error",rule:"A name a camera, a move or a measurement refers to names no object in the scenery, or names two"},"AK-W006":{level:"error",rule:"A material's shader does not compile or link on this renderer, or needs more texture units than the renderer has, so what uses it draws nothing (warn: more than the 16 a GPU may have)"},"AK-W008":{level:"error",rule:"A screen drawn in the scenery cannot show its element as it is: an element of it is in the browser's top layer (a modal dialog, a popover), planes of a preserve-3d context overlap, its element is larger than the largest texture, or its picture could not be copied"},"AK-S002":{level:"warn",rule:"Missing translation"},"AK-L002":{level:"warn",rule:"Text overflows the frame or is clipped"},"AK-L003":{level:"warn",rule:"Missing glyphs"},"AK-L006":{level:"warn",rule:"Text is drawn in a fallback font, or in a bold or italic the font does not have"},"AK-W007":{level:"warn",rule:"A screen asked to be drawn in the scenery is drawn over it, unlit and untoned: this browser cannot draw an element into a canvas (Chrome's HTML-in-Canvas), or ALLYHUB_HTML_IN_CANVAS=0"}};function problem(e,t,n={}){const{level:r,...u}=n;return{code:e,level:r??RULES[e].level,message:t,...u}}var round3=e=>Math.round(e*1e3)/1e3;function frameStarts(e,t,n){const r=o=>Math.round(o*n)/n,u=e.map(r);for(let o=1;o<u.length;o++){const a=u[o-1]??0;(u[o]??0)<=a&&(u[o]=a+1/n)}const i=u.at(-1)??0;return{starts:u,end:Math.max(r(t),i+1/n)}}var voiced=e=>e.speechDur!==void 0&&e.speechDur>0;function overlapOf(e,t){const n=e[t]??0;if(!voiced(e)||!Number.isFinite(n)||n<=0)return 0;const r=(e.speechDur??0)/2+(t==="before"?e.lead:e.tail);return Math.min(n,r)}function timeParts(e,t={}){const n=e.map((g,D)=>({...g,before:D===0?0:g.before??0,after:D===e.length-1?0:g.after??0})),r=t.fps??FPS,u=t.beat??0,i=[];for(const g of n){const D=new Set((g.placed??[]).map(v=>v.name));for(const v of g.anchors??[])D.has(v.name)&&i.push(problem("AK-T004",`The anchor ${v.name} of part ${g.key} is both in the line it says (@{${v.name}}) and in the part's own anchors; "@${v.name}" is the part's own. Rename one of them.`,{part:g.key}))}const o=[];let a=0;for(const g of n){o.push(a);let D;if(voiced(g))D=g.lead+(g.speechDur??0)+g.tail-overlapOf(g,"before")-overlapOf(g,"after");else{D=g.dur;const v=t.snap?.(a+D,a);if(v!==void 0)D=v-a;else if(u>0&&!t.snap){const E=t.beatPhase??0;let y=E+Math.round((a+D-E)/u)*u;y<=a+1e-9&&(y+=u),D=y-a}}a+=Math.max(D,1/r)}const{starts:s,end:c}=frameStarts(o,a,r),l=n.map((g,D)=>{const v=s[D]??0;return{key:g.key,start:v,end:s[D+1]??c,...voiced(g)?{speechAt:round3(v+g.lead-overlapOf(g,"before"))}:{}}}),d=new Map,f=g=>{if(d.has(g))return d.get(g);const D=n[g],v=D?.script&&D.words?.length?new ScriptAlignment(new WordStream(D.words),[D.script]):void 0;return d.set(g,v),v};function m(g,D){const v=l[g],E=n[g];if(!v||!E)return;const y=E.anchors??[],b=E.placed??[],A=parseAnchorRef(D,new Set([...y,...b].map(j=>j.name)));if(!A)return;const B=v.end-v.start,$=j=>(i.push(problem("AK-T004",j,{part:E.key})),round3(B/2)),x=j=>round3(Math.min(B,Math.max(0,j))),_=b.find(j=>j.name===A.name);if(_)return A.end&&_.end===void 0?$(`"${D}" asks for the end of the anchor ${_.name} of part ${E.key}, which is a point. Give it as a stretch (anchors: { ${_.name}: [from, to] }), or use "@${_.name}".`):x((A.end?_.end??_.at:_.at)+A.shift);const F=y.find(j=>j.name===A.name);if(!F){const j=[...y,...b].map(R=>`@${R.name}`);return $(`The anchor "${D}" is not in the line part ${E.key} says, nor in the part's own anchors${j.length>0?` (its anchors: ${j.join(", ")})`:""}. Write @{${A.name}} before the word it is for, in the part's say in the item's script, in every language (the part must say that line, s("….say")); or give its seconds in the part: anchors: { ${A.name}: 1.2 }.`)}if(A.end&&F.end===void 0)return $(`"${D}" asks for the end of the anchor ${F.name} of part ${E.key}, which is a point. Write @{${F.name}}…@{/${F.name}} around the words in the script, or use "@${F.name}".`);const S=A.end?F.end??F.at:F.at,k=normText(E.script??"");if(E.pending===!0&&v.speechAt===void 0)return k.length===0?round3(B/2):x(S/k.length*B+A.shift);const w=E.words??[],I=f(g);if(v.speechAt===void 0||!I||w.length===0)return $(`The anchor "${D}" is in part ${E.key}, which has no speech. Give its seconds in the part instead: anchors: { ${A.name}: 1.2 }.`);const M=w.at(-1),P=A.end?w[I.wordAtChar(0,Math.max(0,S-1))]?.end:S>=k.length?M?.end:w[I.wordAtChar(0,S)]?.start;return x(v.speechAt+(P??0)+A.shift-v.start)}function h(g,D){const v=numericRef(D);if(v!==void 0)return v;const E=typeof D=="string"?m(g,D):void 0;if(E!==void 0)return E;const y=l[g],b=n[g];if(!y||!b)return 0;const A=y.end-y.start,B=b.words??[],{text:$,nth:x,shift:_}=parseWordRef(String(D));let F=-1;B.length>0&&(F=f(g)?.wordFor(0,$,x)??-1,F<0&&(F=new WordStream(B).find(normText($),0,B.length-1,x)));const S=B[F];if(b.pending===!0&&y.speechAt===void 0){const w=normText(b.script??"");let I=-1;for(let M=0;M<x;M++)I=w.indexOf(normText($),I+1);return I<0||w.length===0?round3(A/2):round3(Math.min(A,Math.max(0,I/w.length*A+_)))}if(F<0||!S||y.speechAt===void 0){const w=b.script??joinWords(B);return i.push(problem("AK-T004",y.speechAt===void 0?`The word reference "${String(D)}" is in part ${b.key}, which has no speech. Give it in seconds from the part's start instead.`:`The word reference "${String(D)}" is not in the words of part ${b.key}${w?` (it says: "${w.length>160?`${w.slice(0,160)}…`:w}")`:""}. Use a word the part says, as "word", "word@2" or "word+0.2".`,{part:b.key})),round3(A/2)}const k=y.speechAt+S.start+_;return round3(Math.min(A,Math.max(0,k-y.start)))}function p(g){const D=l[g],v=n[g];if(!D||!v||D.speechAt===void 0)return[];const E=D.speechAt-D.start;return(v.words??[]).map(y=>({text:y.text,start:round3(y.start+E),end:round3(y.end+E)}))}return{parts:l,duration:c,problems:i,at:h,words:p}}var MUSIC_DEFAULTS={seam:.03,meter:4,loopSeam:.25};function musicGrid(e,t={}){if(!e||!(e.bpm>0))return;const n=e.beat??0;return{beat:60/e.bpm,first:t.downbeat??n,meter:t.meter??MUSIC_DEFAULTS.meter,downbeat:t.downbeat??n}}function musicSeconds(e,t){if(typeof e=="number")return e;if(t)return"beat"in e?t.first+e.beat*t.beat:t.downbeat+e.bar*t.meter*t.beat}var onGrid=e=>typeof e!="number";function placeStretches(e,t,n,r){const u=[];let i=0;const o=a=>{const s=Math.max(0,a.from),c=Math.min(n,a.to);return c-s<.001?!1:(u.push({at:i,from:s,to:c}),i+=c-s,!0)};for(const a of e){if(i>=r)return u;o(a)}if(t)for(;i<r&&o(t););return u}function wholeLoop(e,t,n,r=MUSIC_DEFAULTS.loopSeam){const u=t>1?r:0,i=t-u;if(i<=0)return[];const o=[];let a=0,s=Math.max(0,e)%i;for(;a<n;)o.push({at:a,from:s,to:i}),a+=i-s,s=0;return o}function musicSegments(e,t,n,r="before",u=!0){const i=e.map(o=>({at:o.at,from:o.from,dur:o.to-o.from,fadeIn:0,fadeOut:0}));for(let o=0;o<i.length;o++){const a=i[o],s=e[o];if(!a||!s||t<=0)continue;const c=e[o+1],l=i[o+1],d=m=>Math.min(t,m.dur/2);if(!c||!l){u&&n-s.to>.001&&(a.fadeOut=d(a));continue}if(r==="after"){const m=Math.min(t,n-s.to);a.dur+=m,a.fadeOut=m,l.fadeIn=m;continue}a.fadeOut=d(a);const f=Math.min(t,c.from);l.at-=f,l.from-=f,l.dur+=f,l.fadeIn=f}return i}function filmBeats(e,t,n="beat"){const r=n==="bar"?t.beat*t.meter:t.beat,u=n==="bar"?t.downbeat:t.first,i=[];for(const o of e){let a=Math.ceil((o.from-u)/r-1e-9);for(;;){const s=u+a*r;if(s>=o.to-1e-9)break;s>=o.from-1e-9&&i.push(o.at+(s-o.from)),a++}}return i.sort((o,a)=>o-a)}function beatNear(e,t,n,r){const u=e.at(-1);if(u===void 0||!(t>0))return;let i;const o=a=>{a<=r+1e-9||(i===void 0||Math.abs(a-n)<Math.abs(i-n))&&(i=a)};for(const a of e)o(a);if(n+t>u){const a=Math.max(1,Math.round((n-u)/t));for(const s of[a-1,a,a+1])s>=1&&o(u+s*t)}if(i===void 0){const a=Math.max(1,Math.ceil((r-u)/t+1e-9));i=u+a*t}return i}var SAY_DIR=`${MEDIA_DIR}/gen/say`,DEFAULT_VOICE_TOOL="speech-elevenlabs-multilingual-v2";function hash64(e){let t=0xcbf29ce484222325n;const n=0x100000001b3n;for(const r of new TextEncoder().encode(e))t^=BigInt(r),t=t*n&0xffffffffffffffffn;return t.toString(16).padStart(16,"0")}function canonicalJson(e){if(Array.isArray(e))return`[${e.map(canonicalJson).join(",")}]`;if(typeof e=="object"&&e!==null){const t=e;return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${canonicalJson(t[n])}`).join(",")}}`}return JSON.stringify(e)}function sayStem(e){const t=e.tool??DEFAULT_VOICE_TOOL,n=e.params&&Object.keys(e.params).length>0?`
67
67
  ${canonicalJson(e.params)}`:"";return`${SAY_DIR}/${hash64(`${t}
68
68
  ${e.voice??""}
69
69
  ${e.text}${n}`)}`}function mediaByStem(e,t){for(const[n,r]of Object.entries(e))if(r.kind==="audio"&&n.startsWith(`${t}.`)){const u=n.slice(t.length+1);if(!u.includes("/")&&!u.includes("."))return r}}function wordsIn(e,t,n,r,u=1){const i=c=>Math.round(c*1e3)/1e3,o=t+n*u,a=r-t,s=c=>i(u===1?c+a:r+(c-t)/u);return e.filter(c=>c.start>=t-1e-6&&c.start<o-1e-6).map(c=>({text:c.text,start:s(c.start),end:s(Math.min(c.end,o))}))}var CJK_CHAR=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/gu,SPEECH_RATE_DEFAULTS={word:.38,cjk:.22};function speechUnits(e){const t=e.match(CJK_CHAR)?.length??0;return{words:e.replace(CJK_CHAR," ").split(/\s+/u).filter(r=>/[\p{L}\p{N}]/u.test(r)).length,cjk:t}}var unitSeconds=(e,t)=>{const{words:n,cjk:r}=speechUnits(e);return n*(t.word??SPEECH_RATE_DEFAULTS.word)+r*(t.cjk??SPEECH_RATE_DEFAULTS.cjk)};function estimateSpeech(e,t={}){return Math.max(1,Math.round(unitSeconds(e,t)*10)/10)}var VOICE_HOP=.01;function frameDb(e,t){const n=e.db[t];return n===void 0?-120:-n}function envelopeFrames(e){return{hop:VOICE_HOP,db:Uint8Array.from(atob(e),t=>t.charCodeAt(0))}}function quietest(e,t,n,r){const u=c=>Math.min(Math.max(c,n),r);if(!(r>=n))return t;const i=Math.ceil(n/e.hop-1e-9),o=Math.floor(r/e.hop+1e-9);let a,s=1/0;for(let c=Math.max(0,i);c<=o&&c<e.db.length;c++){const l=frameDb(e,c),d=c*e.hop;(l<s||l===s&&a!==void 0&&Math.abs(d-t)<Math.abs(a-t))&&(a=d,s=l)}return u(a===void 0?t:Math.round(a*1e3)/1e3)}var r3=e=>Math.round(e*1e3)/1e3,r1=e=>Math.round(e*10)/10,FLOOR_SHARE=.25,FLOOR_FRAMES=3;function floorLevel(e,t,n,r=FLOOR_FRAMES){const u=Math.max(0,Math.ceil(t/e.hop-1e-9)),i=Math.min(e.db.length,Math.ceil(n/e.hop-1e-9)),o=[];for(let c=u;c<i;c++)o.push(frameDb(e,c));if(o.length<Math.max(FLOOR_FRAMES,r))return;o.sort((c,l)=>c-l);const a=o.slice(0,Math.max(FLOOR_FRAMES,Math.ceil(o.length*FLOOR_SHARE))),s=a.reduce((c,l)=>c+10**(l/10),0)/a.length;return r1(10*Math.log10(s+1e-12))}var ROOM_MATCH={near:.3,least:.1,fade:.04,limitDb:6};function matchRoom(e,t,n,r=ROOM_MATCH.limitDb){const u=e?floorLevel(e,t.from,t.to):void 0,i=e?floorLevel(e,n.from,n.to,Math.round(ROOM_MATCH.least/e.hop)):void 0;if(u===void 0||i===void 0)return{level:u??null,floor:i??null,gainDb:0,from:"unmeasured"};const o=i-u,a=r1(Math.min(r,Math.max(-r,o)));return{level:u,floor:i,gainDb:a,from:"matched",...a===r1(o)?{}:{limited:!0}}}var ROOM_DB=6;function roomTone(e){const t=e.db.length;if(t===0)return;const r=Array.from(e.db,o=>-o).sort((o,a)=>o-a)[Math.floor(t*.1)]??-120;let u,i=-1;for(let o=0;o<=t;o++){const a=o<t&&frameDb(e,o)<=r+ROOM_DB;a&&i<0&&(i=o),!a&&i>=0&&((!u||o-i>u[1]-u[0])&&(u=[i,o]),i=-1)}if(!(!u||(u[1]-u[0])*e.hop<.2))return{from:r3((u[0]+1)*e.hop),to:r3((u[1]-1)*e.hop)}}var PAD_BEFORE=.12,PAD_AFTER=.08,SNAP=.04,JOIN=.04,round32=e=>Math.round(e*1e3)/1e3,isTime=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0;function parseEditList(e){if(typeof e!="object"||e===null||Array.isArray(e))return"an edits file is a JSON object: { version: 1, remove, sounds, inWord, maxPause, pad }";const t=e;if(t.version!==1)return"version is 1";for(const o of["take","$schema"])if(t[o]!==void 0&&typeof t[o]!="string")return`${o} is a string`;const n=Object.keys(t).filter(o=>!["version","remove","sounds","inWord","maxPause","pad","take","$schema"].includes(o));if(n.length>0)return`unknown field${n.length>1?"s":""} ${n.join(", ")} (an edits file has version, remove, sounds, inWord, maxPause, pad and take)`;const r={};if(t.remove!==void 0){if(!Array.isArray(t.remove))return"remove is a list of { from, to, text }";const o=[];for(const[a,s]of t.remove.entries()){const c=s,l=c?.from,d=c?.to,f=c?.text;if(typeof l!="number"||typeof d!="number"||!Number.isInteger(l)||!Number.isInteger(d)||l<0||d<l||f!==void 0&&typeof f!="string")return`remove[${String(a)}] is not { from, to, text } with word indices from ≤ to`;o.push({from:l,to:d,...f===void 0?{}:{text:f}})}r.remove=o}for(const o of["sounds","inWord"]){if(t[o]===void 0)continue;if(!Array.isArray(t[o]))return`${o} is a list of { from, to } in seconds of the take`;const a=[];for(const[s,c]of t[o].entries()){const l=c,d=l?.from,f=l?.to;if(!isTime(d)||!isTime(f)||f<=d)return`${o}[${String(s)}] is not { from, to } in seconds with from < to`;a.push({from:d,to:f})}r[o]=a}const u=t.maxPause;if(u!==void 0){if(typeof u!="number"||!Number.isFinite(u)||u<.05||u>10)return"maxPause is seconds, from 0.05 to 10";r.maxPause=u}const i=t.pad;if(i!==void 0){const o=i,a=typeof i=="object"&&o!==null&&!Array.isArray(i),s=a?Object.keys(o).filter(f=>f!=="before"&&f!=="after"):[],c=f=>f===void 0||isTime(f)&&f<=PAD_MAX;if(!a||s.length>0||!c(o.before)||!c(o.after))return`pad is { before, after }: seconds of silence kept before and after each cut, each from 0 to ${String(PAD_MAX)}`;const l=o.before,d=o.after;r.pad={...l===void 0?{}:{before:l},...d===void 0?{}:{after:d}}}return r}function rangeText(e,t,n){return joinWords(e.slice(t,n+1))}function locateRange(e,t,n=new WordStream(e)){const r=t.from>=0&&t.to<e.length&&t.to>=t.from;if(t.text===void 0)return r?{from:t.from,to:t.to}:void 0;const u=normText(t.text);if(u==="")return r?{from:t.from,to:t.to}:void 0;if(r&&normText(rangeText(e,t.from,t.to))===u)return{from:t.from,to:t.to};let i;for(let o=1;;o++){const a=n.span(u,0,e.length-1,o);if(!a)break;normText(rangeText(e,a.first,a.last))===u&&(!i||Math.abs(a.first-t.from)<Math.abs(i.from-t.from))&&(i={from:a.first,to:a.last})}return i}function removedWords(e,t,n=new WordStream(e)){const r=new Set,u=[];for(const i of t?.remove??[]){const o=locateRange(e,i,n);if(!o){u.push(i);continue}for(let a=o.from;a<=o.to;a++)r.add(a)}return{cut:r,lost:u}}function snapCut(e,t,n,r){const u=Math.min(Math.max(t,n),r);return e?quietest(e,u,Math.max(n,u-SNAP),Math.min(r,u+SNAP)):u}var ROOM_IN=.5,ROOM_OUT=.6;function speechPads(e,t,n,r,u){const i=e[t],o=e[n]??i;if(!i||!o)return{padIn:0,padOut:0};const a=i.start,s=e[t-1]?.end??0,c=e[n+1]?.start??r??o.end+.4,l=Math.max(0,Math.min((a-s)/2,a)),d=Math.max(0,(c-o.end)/2),f=snapCut(u,a-Math.min(ROOM_IN,l),a-l,a),m=snapCut(u,o.end+Math.min(ROOM_OUT,d),o.end,o.end+d);return{padIn:round32(Math.max(0,a-f)),padOut:round32(Math.max(0,m-o.end))}}function applyEdits(e,t,n=0,r=e.length-1,u={}){const{levels:i,fps:o}=u,{cut:a,lost:s}=removedWords(e,t),c=[];for(let w=n;w<=r;w++)a.has(w)||c.push(w);const l=[...a].filter(w=>w>=n&&w<=r).sort((w,I)=>w-I),d=t?.maxPause,f=[],m=[],h=w=>e[w]??{text:"",start:0,end:0};if(c.length===0)return{ranges:[],words:[],kept:c,removed:l,sounds:[],inWord:[],pauses:f,lost:s};const p=[],g=new Map;for(const w of t?.sounds??[])for(let I=0;I<c.length-1;I++){const M=h(c[I]??0),P=h(c[I+1]??0),j=Math.max(w.from,M.end),R=Math.min(w.to,P.start);if(R-j<.01)continue;const U=g.get(I)??[];U.push({start:j,end:R}),g.set(I,U),p.push({from:round32(j),to:round32(R)})}const D=h(c[0]??0);let v=D.start,E=D.start;const y=t?.pad?.before??PAD_BEFORE,b=t?.pad?.after??PAD_AFTER,A=d===void 0?y:Math.min(y,d/2),B=d===void 0?b:Math.min(b,d/2);for(let w=0;w<c.length-1;w++){const I=c[w]??0,M=c[w+1]??0,P=h(I),j=h(M),R=[];for(let V=I+1;V<M;V++)R.push({start:h(V).start,end:h(V).end});R.push(...g.get(w)??[]),R.sort((V,X)=>V.start-X.start);const U=R[0],O=R.at(-1);if(!U||!O){const V=j.start-P.end;if(d!==void 0&&V>d){const X=snapCut(i,P.end+d/2,P.end,j.start),J=snapCut(i,j.start-d/2,X,j.start);J-X>=JOIN&&(f.push({after:I,was:round32(V),now:d}),m.push({from:v,to:X,lo:E,hi:J}),v=J,E=X)}continue}const Z=Math.max(0,U.start-P.end),L=Math.max(0,j.start-O.end),T=snapCut(i,P.end+Math.min(A,Z/2),P.end,P.end+Z/2),G=snapCut(i,j.start-Math.min(B,L/2),j.start-L/2,j.start);m.push({from:v,to:T,lo:E,hi:U.start}),v=Math.max(G,T),E=Math.min(v,O.end)}const $=h(c.at(-1)??0);m.push({from:v,to:$.end,lo:E,hi:$.end});const x=[];for(const w of t?.inWord??[]){const I=(w.from+w.to)/2,M=snapCut(i,w.from,w.from-SNAP,I),P=snapCut(i,w.to,I,w.to+SNAP);if(P-M<JOIN)continue;let j=!1;for(let R=0;R<m.length;R++){const U=m[R];!U||M>=U.to||P<=U.from||(j=!0,M>U.from&&P<U.to?(m.splice(R,1,{from:U.from,to:M,lo:U.lo,hi:M},{from:P,to:U.to,lo:P,hi:U.hi}),R++):M<=U.from&&P>=U.to?(m.splice(R,1),R--):M<=U.from?(U.from=P,U.lo=P):(U.to=M,U.hi=M))}j&&x.push({from:round32(M),to:round32(P),words:c.filter(R=>h(R).start<P&&h(R).end>M)})}o!==void 0&&o>0&&m.forEach((w,I)=>{if(I>0){const M=Math.floor(w.from*o+1e-6)/o;M>=w.lo-1e-9&&(w.from=M)}if(I<m.length-1){const M=Math.ceil(w.to*o-1e-6)/o;M<=w.hi+1e-9&&(w.to=M)}});const _=[];for(const w of m){const I=_.at(-1);I&&w.from-I.to<JOIN?I.to=Math.max(I.to,w.to):_.push({from:w.from,to:w.to})}const F=_.map(w=>({from:round32(w.from),to:round32(w.to)})),S=editedLength(F),k=w=>round32(Math.min(S,Math.max(0,toEdited(F,w))));return{ranges:F,words:c.map(w=>{const I=h(w);return{text:I.text,start:k(I.start),end:k(I.end)}}),kept:c,removed:l,sounds:p,inWord:x,pauses:f,lost:s}}function editedLength(e){return e.reduce((t,n)=>t+(n.to-n.from),0)}function toEdited(e,t){let n=0;const r=e[0];if(!r)return t;if(t<=r.from)return t-r.from;for(const i of e){if(t<i.from)return n;if(t<=i.to)return n+(t-i.from);n+=i.to-i.from}const u=e.at(-1)??r;return n+(t-u.to)}function fromEdited(e,t){const n=e[0];if(!n)return t;if(t<=0)return n.from+t;let r=0;for(const i of e){const o=i.to-i.from;if(t<r+o)return i.from+(t-r);r+=o}return(e.at(-1)??n).to+(t-r)}var CAPTION_CUE_DEFAULTS={maxChars:42,maxCharsCjk:16,minSeconds:.8,maxSeconds:6,gapFrames:2};function shownToSpoken(e,t){const n=(u,i)=>normText(u.slice(0,i)).length,r=[[0,0]];for(const u of changesOf(e,t))r.push([n(e,u.at),n(t,u.into)]),r.push([n(e,u.at+u.removed),n(t,u.into+u.inserted)]);return r.push([normText(e).length,normText(t).length]),u=>{for(let i=1;i<r.length;i++){const[o,a]=r[i-1]??[0,0],[s,c]=r[i]??[0,0];if(u>s&&i<r.length-1)continue;if(s<=o)return u<=o?a:c;const l=Math.max(0,Math.min(1,(u-o)/(s-o)));return a+(c-a)*l}return 0}}var CJK2=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,SENTENCE=/[。!?!?…]|\.(?=\s|$)/u,CLAUSE=/[,、;:,;:—]/u,TRAILING=/[,、;:。,;:.\s]+$/u;function keptSpans(e,t){const n=[],r=shownWords(e).map(u=>({...u,n:normText(u.w)}));for(const u of t){const i=normText(u);if(!i)continue;if(CJK2.test(u)){const a=[];Array.from(e).reduce((c,l)=>(normText(l)&&a.push(c),c+l.length),0);const s=normText(e);for(let c=s.indexOf(i);c>=0;c=s.indexOf(i,c+1)){const l=a[c],d=a[c+i.length-1];l!==void 0&&d!==void 0&&n.push([l,d+1])}continue}const o=u.split(/\s+/u).map(normText).filter(Boolean);for(let a=0;a+o.length<=r.length;a++)if(o.every((s,c)=>r[a+c]?.n===s)){const s=r[a],c=r[a+o.length-1];s&&c&&n.push([s.from,c.to])}}return n}var inside=(e,t)=>e.some(([n,r])=>t>n&&t<r);function splitLine(e,t=CJK2.test(e)?CAPTION_CUE_DEFAULTS.maxCharsCjk:CAPTION_CUE_DEFAULTS.maxChars,n=[]){const r=[],u=(o,a)=>{const s=e.slice(o,a),c=s.length-s.trimStart().length,l=s.trim();l&&r.push({text:l,from:o+c,to:o+c+l.length})},i=(o,a,s)=>{const c=e.slice(o,a);if(Array.from(c.trim()).length<=t){u(o,a);return}const d=s===0?SENTENCE:s===1?CLAUSE:void 0;if(d){let p=-1;for(let g=1;g<c.length-1;g++)d.test(c[g]??"")&&!inside(n,o+g+1)&&(p<0||Math.abs(g-c.length/2)<Math.abs(p-c.length/2))&&(p=g);if(p<0){i(o,a,s+1);return}i(o,o+p+1,s),i(o+p+1,a,s);return}const f=Math.floor(c.length/2),m=p=>p>0&&p<c.length&&!inside(n,o+p);let h=-1;if(!CJK2.test(c)){for(let p=f;p>0&&h<0;p--)c[p]===" "&&m(p)&&(h=p);for(let p=f;p<c.length&&h<0;p++)c[p]===" "&&m(p)&&(h=p)}for(let p=0;p<=c.length&&h<0;p++)m(f-p)?h=f-p:m(f+p)&&(h=f+p);if(h<0){u(o,a);return}i(o,o+h,s),i(o+h,a,s)};return i(0,e.length,0),r}function captionCues(e,t={}){const{lines:n,fps:r}=e,u={...CAPTION_CUE_DEFAULTS,...t},i=[];for(const c of n){if(c.words.length===0)continue;const l=c.words,d=new ScriptAlignment(new WordStream(l),[c.spoken]),f=(D,v)=>{const E=l[d.wordAtChar(0,D)];return E?v?E.end:E.start:0};if((d.lines[0]?.length??0)===0)continue;const p=normText(c.shown)===normText(c.spoken)?D=>D:shownToSpoken(c.shown,c.spoken),g=CJK2.test(c.shown)?u.maxCharsCjk:u.maxChars;for(const D of splitLine(c.shown,g)){const v=Math.round(p(normText(c.shown.slice(0,D.from)).length)),E=Math.round(p(normText(c.shown.slice(0,D.to)).length)),y=f(v,!1),b=f(Math.max(v,E-1),!0),A=CJK2.test(D.text)?D.text.replace(TRAILING,""):D.text.replace(/[,;:]+$/u,"");A&&i.push({start:y,end:Math.max(b,y),text:A,part:c.part})}}const o=1/r,a=c=>Math.round(c*r)/r,s=i.map(c=>({...c,start:a(c.start),end:a(c.end)}));for(let c=0;c<s.length;c++){const l=s[c];if(!l)continue;const d=s[c+1],f=d?d.start-u.gapFrames*o:1/0;l.end=Math.min(Math.max(l.end,l.start+u.minSeconds),l.start+u.maxSeconds,f),l.end<=l.start&&(l.end=l.start+o)}return s}function subtitleCues(e,t){return t===void 0?captionCues(e):wordCues(e.lines,{...t,fps:e.fps}).map(n=>({start:n.start,end:n.end,text:n.text,part:n.part}))}function shownWords(e){const t=[],n=/\S+/gu;for(let r=n.exec(e);r;r=n.exec(e))t.push({w:r[0],from:r.index,to:r.index+r[0].length});return t}function wordCues(e,t){const{fps:n}=t,r=[];for(const a of e){if(a.words.length===0)continue;const s=a.words,c=new ScriptAlignment(new WordStream(s),[a.spoken]);if((c.lines[0]?.length??0)===0)continue;const d=(v,E)=>{const y=s[c.wordAtChar(0,v)];return y?E?y.end:y.start:0},m=normText(a.shown)===normText(a.spoken)?v=>v:shownToSpoken(a.shown,a.spoken),h=(v,E)=>{const y=Math.round(m(normText(a.shown.slice(0,v)).length)),b=Math.round(m(normText(a.shown.slice(0,E)).length));return[d(y,!1),d(Math.max(y,b-1),!0)]},p=CJK2.test(a.shown),g=t.maxChars??(p?16:32),D=keptSpans(a.shown,t.keep??[]);for(const v of splitLine(a.shown,g,D)){const E=(p?[{w:v.text,from:v.from,to:v.to}]:shownWords(a.shown.slice(v.from,v.to)).map(_=>({w:_.w,from:_.from+v.from,to:_.to+v.from}))).filter(_=>normText(_.w)!=="");if(E.length===0)continue;const y=t.maxWords&&t.maxWords>0?t.maxWords:E.length,b=Math.ceil(E.length/y),A=Math.ceil(E.length/b),B=[];E.forEach((_,F)=>{const S=E[F-1],k=B.at(-1);k&&S&&inside(D,Math.ceil((S.to+_.from)/2))?k.push(_):B.push([_])});const $=[];let x=[];for(const _ of B)x.length>0&&x.length+_.length>A&&($.push(x),x=[]),x.push(..._);x.length>0&&$.push(x);for(const _ of $){const F=_.map(I=>{const[M,P]=h(I.from,I.to);return{text:I.w,start:M,end:Math.max(P,M)}}),S=F[0],k=F.at(-1);if(!S||!k)continue;const w=_.map(I=>I.w).join(p?"":" ").replace(p?TRAILING:/[,;:]+$/u,"");r.push({start:S.start,end:k.end,text:w,part:a.part,words:F})}}}const u=a=>Math.round(a*n)/n,i=1/n,o=r.map(a=>({...a,start:u(a.start),end:u(a.end)}));for(let a=0;a<o.length;a++){const s=o[a];if(!s)continue;const c=o[a+1],l=c?.part===s.part;c&&l&&c.start-s.end<(t.close??.4)&&(s.end=c.start),s.end=Math.max(s.end,s.start+Math.min(.5,6*i)),c&&s.end>c.start&&(s.end=c.start),s.end<=s.start&&(s.end=s.start+i)}return o}function cuesIn(e,t,n){const r=u=>Math.round(u*1e6)/1e6;return e.filter(u=>u.end>t&&u.start<n).map(u=>({start:r(Math.max(u.start,t)-t),end:r(Math.min(u.end,n)-t),text:u.text,words:u.words.map(i=>({text:i.text,start:r(i.start-t),end:r(i.end-t)}))}))}function easeValue(e,t){const n=Math.min(Math.max(t,0),1);switch(e??"linear"){case"linear":return n;case"in":return n*n*n;case"out":return 1-(1-n)**3;case"in-out":return n<.5?4*n*n*n:1-(-2*n+2)**3/2}}function keyAt(e,t){const n=e[0];if(!n)return 0;if(t<=n.t)return n.v;for(let r=1;r<e.length;r++){const u=e[r-1],i=e[r];if(!(!u||!i)&&t<i.t){const o=i.t-u.t;return o<=0?i.v:u.v+(i.v-u.v)*easeValue(i.ease,(t-u.t)/o)}}return e.at(-1)?.v??n.v}function rectChannel(e,t){return e.map(n=>({t:n.t,v:n.rect[t],...n.ease?{ease:n.ease}:{}}))}function rectAt(e,t){return[keyAt(rectChannel(e,0),t),keyAt(rectChannel(e,1),t),keyAt(rectChannel(e,2),t),keyAt(rectChannel(e,3),t)]}function simplifyKeys(e,t){if(e.length<=2)return[...e];const n=new Uint8Array(e.length);n[0]=1,n[e.length-1]=1;const r=[[0,e.length-1]];for(;r.length>0;){const[u,i]=r.pop()??[0,0],o=e[u],a=e[i];if(!o||!a)continue;let s=-1,c=-1;for(let l=u+1;l<i;l++){const d=e[l];if(!d)continue;const f=a.t===o.t?0:(d.t-o.t)/(a.t-o.t);let m=0;d.v.forEach((h,p)=>{const g=(o.v[p]??0)+((a.v[p]??0)-(o.v[p]??0))*f;m=Math.max(m,Math.abs(h-g))}),m>s&&(s=m,c=l)}s>t&&c>0&&(n[c]=1,r.push([u,c],[c,i]))}return e.filter((u,i)=>n[i]===1)}var TRANSITION_TYPES=["fade","dip","slide","push","wipe","zoom","custom"],TRANSITION_DEFAULTS={dur:.4,split:.5,direction:"left",scale:1.2};function transitionEase(e){return e==="fade"||e==="dip"||e==="custom"?"linear":"in-out"}var isNumber=e=>typeof e=="number"&&Number.isFinite(e);function channelKeys(e){if(isNumber(e))return[{t:0,v:e},{t:1,v:e}];if(!Array.isArray(e)||e.length===0)return;const t=e;if(t.length===2&&isNumber(t[0])&&isNumber(t[1]))return[{t:0,v:t[0]},{t:1,v:t[1]}];const n=[];for(const r of t){if(typeof r!="object"||r===null)return;const{p:u,v:i}=r;if(!isNumber(u)||!isNumber(i)||u<0||u>1||n.length>0&&u<(n.at(-1)?.t??0))return;n.push({t:u,v:i})}return n}var CLIP_EDGES=["left","right","top","bottom"],TYPE_LIST=TRANSITION_TYPES.map(e=>`"${e}"`).join(", ");function transitionSpec(e){return typeof e=="string"?{type:e}:e}var line=(e,t)=>[{t:0,v:e},{t:1,v:t}],still=(e,t)=>e.every(n=>Math.abs(n.v-t)<1e-9);function customPicture(e){const t={};if(!e)return t;const n=(r,u,i)=>{const o=u===void 0?void 0:channelKeys(u);o&&!still(o,i)&&(t[r]=o)};n("x",e.x,0),n("y",e.y,0),n("scale",e.scale,1),n("opacity",e.opacity,1);for(const r of CLIP_EDGES)n(r,e.clip?.[r],0);return t}var isClear=e=>e==="transparent"||/^#[0-9a-f]{6}00$/i.test(e);function transitionKeys(e,t){const n=t.transparent?{add:!0}:{};switch(e.type){case"fade":return{out:{},in:{opacity:line(0,1)},...n};case"dip":{const r=t.color??t.background,u=[{t:0,v:0},{t:.5,v:0},{t:1,v:1}];return isClear(r)?{out:{opacity:[{t:0,v:1},{t:.5,v:0},{t:1,v:0}]},in:{opacity:u}}:{out:{},in:{opacity:u},color:{value:r,opacity:[{t:0,v:0},{t:.5,v:1},{t:1,v:1}]}}}case"slide":case"push":{const r=e.direction??TRANSITION_DEFAULTS.direction,u=r==="left"||r==="right",i=r==="left"||r==="up"?1:-1,o=a=>u?{x:a}:{y:a};return{out:e.type==="push"?o(line(0,-i)):{},in:o(line(i,0))}}case"wipe":{const r=e.direction??TRANSITION_DEFAULTS.direction,u=line(1,0);return{out:{},in:r==="left"?{left:u}:r==="right"?{right:u}:r==="up"?{top:u}:{bottom:u}}}case"zoom":{const r=e.scale??TRANSITION_DEFAULTS.scale,u=e.from??r;return{out:{scale:line(1,r)},in:{...Math.abs(u-1)<1e-9?{}:{scale:line(u,1)},opacity:line(0,1)},...n}}case"custom":{const r=e.color===void 0?void 0:channelKeys(e.color.opacity),u=t.color??t.background;return{out:customPicture(e.out),in:customPicture(e.in),...r&&!still(r,0)&&!isClear(u)?{color:{value:u,opacity:r}}:{}}}}}function transitionWindow(e,t,n,r){const u=Math.max(1,Math.round((e.dur??TRANSITION_DEFAULTS.dur)*t)),i=Math.min(Math.max(e.split??TRANSITION_DEFAULTS.split,0),1),o=Math.round(u*i);return{before:Math.max(0,Math.min(o,Math.floor(n/2))),after:Math.max(0,Math.min(u-o,Math.floor(r/2)))}}function windowFrames(e,t){const n=Math.round(e.start*t);return{first:n,frames:Math.round(e.end*t)-n,join:Math.round(e.at*t)}}function transitionAt(e,t,n){if(!e||e.length===0)return;const r=Math.floor(t*n+1e-6);return e.find(u=>r>=Math.round(u.start*n)&&r<Math.round(u.end*n))}var rawProgress=(e,t)=>Math.min(Math.max((e+1)/(t+1),0),1);function progressAt(e,t,n){const r=windowFrames(e,n);return easeValue(e.ease,rawProgress(t-r.first,r.frames))}var at=(e,t,n)=>e?keyAt(e,n):t;function pictureAt(e,t){return{x:at(e.x,0,t),y:at(e.y,0,t),scale:at(e.scale,1,t),opacity:at(e.opacity,1,t),left:at(e.left,0,t),right:at(e.right,0,t),top:at(e.top,0,t),bottom:at(e.bottom,0,t)}}function stateAt(e,t){const n=pictureAt(e.in,t),r=pictureAt(e.out,t),u=e.add===!0;return{out:u?{...r,opacity:1-n.opacity}:r,in:n,...e.color?{color:{value:e.color.value,opacity:at(e.color.opacity,0,t)}}:{},add:u}}function transitionState(e,t,n){return stateAt(e.keys,progressAt(e,t,n))}function pictureOffset(e,t,n){return[Math.floor(e.x*t+.5),Math.floor(e.y*n+.5)]}var fixed=e=>{const t=(Math.round(e*1e4)/1e4).toString();return t==="-0"?"0":t};function pictureCss(e,t,n){const[r,u]=pictureOffset(e,t,n),i=r!==0||u!==0,o=Math.abs(e.scale-1)>1e-9,a=e.left>0||e.right>0||e.top>0||e.bottom>0;return{transform:`${i?`translate(${String(r)}px, ${String(u)}px)`:""}${i&&o?" ":""}${o?`scale(${fixed(e.scale)})`:""}`,opacity:e.opacity>=1?"":fixed(Math.max(0,e.opacity)),clipPath:a?`inset(${fixed(e.top*n)}px ${fixed(e.right*t)}px ${fixed(e.bottom*n)}px ${fixed(e.left*t)}px)`:""}}function heldTime(e,t,n){if(t>=e.start&&t<e.end-.5/n)return t;const r=Math.round(e.start*n),u=Math.max(r,Math.round(e.end*n)-1),i=Math.min(Math.max(Math.round(t*n),r),u);return i===r?e.start:i/n}function extendFootage(e,t,n){const r=e.cuts?.[0],u=r?Math.max(t,e.start-Math.max(0,r.from)):t;if(u===e.start&&n===e.end)return e;const i=e.start-u;return{...e,start:u,end:n,from:r?r.from-i:e.from-i*e.speed,...e.cuts&&r?{cuts:[{at:u,from:r.from-i},...e.cuts.slice(1)]}:{}}}function withHandles(e,t,n,r){if(!n||n.length===0)return[...e];const u=(i,o)=>Math.round(i*r)===Math.round(o*r);return e.map(i=>{const o=t.find(d=>d.key===i.part);if(!o)return i;const a=n.find(d=>d.part===i.part),s=n.find(d=>d.from===i.part),c=a&&u(i.start,o.start)&&a.start<i.start?a.start:i.start,l=s&&u(i.end,o.end)&&s.end>i.end?s.end:i.end;return extendFootage(i,c,l)})}function sourceAt(e,t){const n=e.cuts;if(n&&n.length>0){let r=n[0]??{at:e.start,from:e.from};for(const u of n)u.at<=t+1e-9&&(r=u);return r.from+(t-r.at)}return e.from+(t-e.start)*e.speed}function zoomRect(e,t,n,r){if(t===1)return e;const u=1-1/t;return[e[0]+n*e[2]*u,e[1]+r*e[3]*u,e[2]/t,e[3]/t]}function zoomChannel(e,t){return e.map(n=>({t:n.t,v:n[t],...n.ease?{ease:n.ease}:{}}))}function placementAt(e,t){let n=e.box,r=e.picture;if(e.boxes&&e.boxes.length>0){const i=e.boxes[0]?.box??e.box,o=rectAt(e.boxes.map(h=>({t:h.t,rect:h.box,...h.ease?{ease:h.ease}:{}})),t),a=boxFit(e,i,o),[s,c,l,d]=e.picture,f=o[0]+o[2]/2+(s+l/2-(i[0]+i[2]/2))*a,m=o[1]+o[3]/2+(c+d/2-(i[1]+i[3]/2))*a;r=[f-l*a/2,m-d*a/2,l*a,d*a],n=o}let u=e.crop;if(u&&e.pan&&e.pan.length>0){const i=keyAt(e.pan.map(a=>({t:a.t,v:a.x})),t),o=keyAt(e.pan.map(a=>({t:a.t,v:a.y})),t);u=[i,o,u[2],u[3]]}return u&&e.zoom&&e.zoom.length>0&&(u=zoomRect(u,keyAt(zoomChannel(e.zoom,"z"),t),keyAt(zoomChannel(e.zoom,"cx"),t),keyAt(zoomChannel(e.zoom,"cy"),t))),{box:n,picture:r,...u?{crop:u}:{}}}function boxFit(e,t,n){const[,,r,u]=e.picture;if(r<=0||u<=0||t[2]<=0||t[3]<=0)return 1;const i=e.fit==="cover"?Math.max:Math.min,o=i(t[2]/r,t[3]/u);return i(n[2]/r,n[3]/u)/o}function sourceToFrame(e,t){const n=e.crop;if(!n)return t;const r=e.picture[2]/n[2],u=e.picture[3]/n[3];return[e.picture[0]+(t[0]-n[0])*r,e.picture[1]+(t[1]-n[1])*u,t[2]*r,t[3]*u]}function overlap(e,t){const n=Math.max(e[0],t[0]),r=Math.max(e[1],t[1]),u=Math.min(e[0]+e[2],t[0]+t[2]),i=Math.min(e[1]+e[3],t[1]+t[3]);return u>n&&i>r?[n,r,u-n,i-r]:void 0}function faceOnFrame(e,t,n,r=e.speaker??t.speaker){if(n<e.start||n>=e.end)return;const u=faceAt(t,sourceAt(e,n),r);if(!u)return;const i=placementAt(e,n);return overlap(sourceToFrame(i,u),i.box)}function facesOnFrame(e,t,n){if(n<e.start||n>=e.end)return[];const r=placementAt(e,n);return facesAt(t,sourceAt(e,n)).flatMap(u=>{const i=overlap(sourceToFrame(r,u.box),r.box);return i?[{id:u.id,box:i}]:[]})}function reframeWindow(e,t){const n=t.w/t.h,r=Math.min(e.width,e.height*n);return{w:Math.min(e.width,Math.round(r)),h:Math.min(e.height,Math.round(r/n))}}var REFRAME_FACE_Y=.4,REFRAME_FALLBACK={x:.5,y:.4};function reframePath(e){const{window:t,source:n,layer:r}=e,u=f=>Math.min(Math.max(f,0),n.width-t.w),i=f=>Math.min(Math.max(f,0),n.height-t.h),o=e.faceY??REFRAME_FACE_Y,a=f=>{const m=e.track?faceAt(e.track,sourceAt(r,f),e.speaker??e.track.speaker):void 0,h=m?m[0]+m[2]/2:(e.focus?.x??.5)*n.width,p=m?m[1]+m[3]/2:(e.focus?.y??.4)*n.height;return[u(h-t.w/2),i(p-t.h*o)]},s=(r.cuts??[]).map(f=>f.at).filter(f=>f>r.start&&f<r.end),c=[r.start,...s,r.end],l=[];for(let f=0;f<c.length-1;f++){const m=c[f]??0,h=c[f+1]??m,p=[];for(let D=m;D<h-1e-6;D+=.1)p.push({t:D,v:a(D)});const g=Math.max(m,h-.001);p.push({t:g,v:a(g)});for(const D of simplifyKeys(p,1.5))l.push({t:Math.round(D.t*1e6)/1e6,x:Math.round((D.v[0]??0)*100)/100,y:Math.round((D.v[1]??0)*100)/100})}const d=l[0];return d&&l.every(f=>f.x===d.x&&f.y===d.y)?[d]:l}var PUNCH_IN=.2,PUNCH_OUT=.25,PUNCH_SCALE=1.12,PUNCH_EASE="in-out",PUNCH_CENTER={x:.5,y:.42};function punchKeys(e){const t=[...e].sort((i,o)=>i.start-o.start),n=[],r=i=>Math.round(i*1e6)/1e6;let u=PUNCH_OUT;for(const i of t){const o=i.in??PUNCH_IN,a=i.out??PUNCH_OUT,s=i.ease??PUNCH_EASE,c=i.start-o/2,l=i.start+o/2,d=n.at(-1);d&&d.t>c?(n.pop(),n.push({t:r(Math.max(d.t-u,l)),z:i.scale,cx:i.cx,cy:i.cy,ease:s})):(n.push({t:r(Math.max(0,c)),z:1,cx:i.cx,cy:i.cy}),n.push({t:r(l),z:i.scale,cx:i.cx,cy:i.cy,ease:s}));const f=Math.max(i.end,l);n.push({t:r(f),z:i.scale,cx:i.cx,cy:i.cy}),n.push({t:r(f+a),z:1,cx:i.cx,cy:i.cy,ease:s}),u=a}return n}var PULLBACK_SCALE=1.12,PULLBACK_DUR=.6,PULLBACK_EASE="out";function pullbackKeys(e,t,n=[]){const r=a=>Math.round(a*1e6)/1e6,u=n[0],i=Math.min(e+t.dur,u?.t??1/0);if(i<=e+1e-6)return[...n];const o=u&&u.t<=i+1e-9&&u.z===1?n.slice(1):n;return[{t:r(e),z:t.scale,cx:t.cx,cy:t.cy},{t:r(i),z:1,cx:t.cx,cy:t.cy,ease:t.ease??PULLBACK_EASE},...o]}function parsePunch(e){const t=/^(.*\S)@(\d*\.\d+)$/u.exec(e.trim());return!t?.[1]||t[2]===void 0?{ref:e}:{ref:t[1],scale:Number(t[2])}}var MATTE_FEATHER=2,MATTE_SHRINK=4;function backdropUnit(e,t){return Math.min(e,t)/1080}var MATTE_FIRM=[.25,.75];function firmLevels(){const e=new Uint8ClampedArray(256),[t,n]=MATTE_FIRM;for(let r=0;r<256;r++)e[r]=Math.round((r/255-t)/(n-t)*255);return e}var MATTE_FLOOR=6;function matteEdge(e,t,n){const r=.2*Math.max(0,n),u=Math.max(Math.hypot(e,r),Math.abs(t)/1.5,.001),i=Math.sqrt(Math.max(0,u*u-r*r)),o=a=>Math.round(a*1e4)/1e4;return{sigma:o(i),gain:o(Math.exp(1.702*t/u))}}function edgeLevels(e){const t=new Uint8ClampedArray(256);for(let n=0;n<256;n++){const r=Math.min(Math.max((n-MATTE_FLOOR)/(255-2*MATTE_FLOOR),0),1);t[n]=Math.round(255*r/(r+e.gain*(1-r)))}return t}var READ_DEFAULTS={every:.2,opacity:.9,shown:.9,phone:[390,844]};function phoneScale(e,t){return Math.min(t[0]/e[0],t[1]/e[1])}function countWords(e){let t=0;for(const r of new Intl.Segmenter(void 0,{granularity:"word"}).segment(e))r.isWordLike&&t++;let n=0;for(const r of new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e))r.segment.trim()!==""&&n++;return{words:t,chars:n}}function textTime(e,t,n=READ_DEFAULTS){const r=new Map;for(const E of e)r.set(E.text,(r.get(E.text)??0)+1);let u,i=0;for(const E of e){const y=r.get(E.text)??0;y>=i&&(i=y,u=E.text)}if(u===void 0)return;const o=e.filter(E=>E.text===u),a=E=>E.opacity>=n.opacity-1e-9&&E.shown>=n.shown-1e-9,s=n.every,c=E=>r32(Math.min(E+s,t.end)),l=[];for(const E of o){if(!a(E))continue;const y=l.at(-1);y&&E.t-y[1]<s*.5?y[1]=c(E.t):l.push([r32(E.t),c(E.t)])}const d=o.find(a)??o[0];if(!d)return;const f=(o.some(a)?o.filter(a):o).flatMap(E=>E.size===void 0?[]:[E.size]),m=f.length>0?Math.min(...f):void 0,h=(o.some(a)?o.filter(a):o).flatMap(E=>E.xHeight===void 0?[]:[E.xHeight]),p=h.length>0?Math.min(...h):void 0,g=phoneScale(t.frame,n.phone),D=E=>r32(E.reduce((y,[b,A])=>y+Math.max(0,A-b),0)),v=[];for(const E of o){const y=v.at(-1);y&&E.t-y[1]<s*.5?y[1]=c(E.t):v.push([r32(E.t),c(E.t)])}return{part:t.part,text:{layer:t.layer,z:t.z,text:u,box:d.box},...countWords(u),seconds:D(l),spans:l,onScreen:D(v),first:r32(d.t),...m===void 0?{}:{size:{px:r12(m),phone:r12(m*g),...p===void 0?{}:{lowercase:{px:r12(p),phone:r12(p*g)}}}}}}var area=e=>Math.max(0,e[2])*Math.max(0,e[3]);function overlapArea(e,t){const n=Math.min(e[0]+e[2],t[0]+t[2])-Math.max(e[0],t[0]),r=Math.min(e[1]+e[3],t[1]+t[3])-Math.max(e[1],t[1]);return n>0&&r>0?n*r:0}var r32=e=>Math.round(e*1e3)/1e3,r12=e=>Math.round(e*10)/10;function boxOverlap(e,t){const n=overlapArea(e,t);if(n<=0)return;const r=Math.min(area(e),area(t));return{area:Math.round(n),share:r>0?r32(n/r):0}}function safeEdges(e,t,n,r){const[u,i,o,a]=e;return[["top",t.top>0?t.top-i:0],["bottom",t.bottom>0?i+a-(r-t.bottom):0],["left",t.left>0?t.left-u:0],["right",t.right>0?u+o-(n-t.right):0]].filter(([,c])=>c>=1).map(([c,l])=>({side:c,px:Math.round(l)}))}function outsideEdges(e,t){return[["top",t[1]-e[1]],["bottom",e[1]+e[3]-(t[1]+t[3])],["left",t[0]-e[0]],["right",e[0]+e[2]-(t[0]+t[2])]].filter(([,r])=>r>=1).map(([r,u])=>({side:r,px:Math.round(u)}))}function offFrame(e,t,n){let r=0,u=0;const i={top:0,bottom:0,left:0,right:0};let[o,a,s,c]=[1/0,1/0,-1/0,-1/0];for(const h of e)h[2]<=0||h[3]<=0||(o=Math.min(o,h[0]),a=Math.min(a,h[1]),s=Math.max(s,h[0]+h[2]),c=Math.max(c,h[1]+h[3]),r+=area(h),u+=overlapArea(h,[0,0,t,n]),i.top=Math.max(i.top,-h[1]),i.bottom=Math.max(i.bottom,h[1]+h[3]-n),i.left=Math.max(i.left,-h[0]),i.right=Math.max(i.right,h[0]+h[2]-t));if(r<=0)return;const l=["top","bottom","left","right"].filter(h=>i[h]>=1).map(h=>({side:h,px:Math.round(i[h])}));if(l.length===0)return;const d=Math.max(0,r-u),f=Math.round(o),m=Math.round(a);return{outside:Math.round(d),share:r32(d/r),edges:l,glyphs:[f,m,Math.round(s)-f,Math.round(c)-m]}}function measureMoment(e){const t=[],n=[],r=c=>e.seen?.[c]??e.texts[c]?.box;for(let c=0;c<e.texts.length;c++)for(let l=c+1;l<e.texts.length;l++){const d=e.texts[c],f=e.texts[l];if(!d||!f)continue;if(e.owner[c]===e.owner[l]){const h=r(c),p=r(l),g=h&&p?boxOverlap(h,p):void 0;g&&n.push({a:c,b:l,...g});continue}const m=boxOverlap(d.box,f.box);m&&t.push({a:c,b:l,...m})}const u=[];e.texts.forEach((c,l)=>{const d=r(l);if(!(!d||c.viewport))for(const f of e.containers?.[l]??[]){const m=outsideEdges(d,f.box);if(m.length!==0){u.push({text:l,container:f,edges:m});break}}});const i=[],o=e.face;o&&e.texts.forEach((c,l)=>{const d=overlapArea(c.box,o);d<=0||i.push({text:l,area:Math.round(d),ofText:r32(d/Math.max(1,area(c.box))),ofFace:r32(d/Math.max(1,area(o)))})});const a=[];e.texts.forEach((c,l)=>{if(c.viewport)return;const d=safeEdges(c.box,e.safe,e.width,e.height);d.length>0&&a.push({text:l,edges:d})});const s=[];return e.texts.forEach((c,l)=>{if(c.viewport)return;const d=r(l),f=offFrame(e.glyphs?.[l]??(d?[d]:[]),e.width,e.height);f&&s.push({text:l,...f})}),{t:e.t,part:e.part,texts:e.texts,...o?{face:o}:{},overlaps:t,ownOverlaps:n,outside:u,faceOverlaps:i,safeOverlaps:a,offFrame:s}}function footageScale(e,t=1,n){const r=e.crop;if(!r||!e.source||r[2]<=0||r[3]<=0)return;const u=e.picture,i=e.zoom&&e.zoom.length>0?zoomChannel(e.zoom,"z"):[],o=e.boxes&&e.boxes.length>1?e.boxes:void 0,a=o?.[0]?.box,s=o?.map(h=>({t:h.t,rect:h.box,...h.ease?{ease:h.ease}:{}})),c=Math.max(e.start,n?e.end-1/n:e.end),l=[e.start,...i.map(h=>h.t),...(o??[]).map(h=>h.t),c].map(h=>Math.min(Math.max(h,e.start),c)).sort((h,p)=>h-p),d=h=>{const p=i.length>0?keyAt(i,h):1,g=s&&a?boxFit(e,a,rectAt(s,h)):1,D=Math.max(u[2]*g/r[2],u[3]*g/r[3])*p*t,v=[e.fit];return Math.abs(p-1)>1e-6&&v.push(`zoom ${String(r32(p))}×`),s&&Math.abs(g-1)>1e-6&&v.push(`box key ${String(r32(g))}×`),{scale:r32(D),t:r32(h),from:v}};let f=d(e.start),m=f;for(const h of l){const p=d(h);p.scale>f.scale&&(f=p),p.scale<m.scale&&(m=p)}return{part:e.part,file:e.file,source:[e.source.width,e.source.height],shown:[Math.round(r[2]),Math.round(r[3])],max:f,min:m}}var STRUCTURE="structure";function comboKey(e){const t=Object.keys(e).sort();return t.length===0?"default":t.map(n=>`${n}=${e[n]??""}`).join(",")}function seedKey(e,t){return comboKey({...e,size:t})}var hasSlots=e=>e!==void 0&&Object.keys(e.slots).length>0;function structureOf(e,t){return e.declared?t[STRUCTURE]:Object.keys(e.structures)[0]}function slotsOf(e,t){const n=structureOf(e,t);return n===void 0?[]:e.structures[n]??[]}function dimsCombo(e,t){const n={};for(const r of Object.keys(e)){const u=t[r];u!==void 0&&(n[r]=u)}return n}var listOf=e=>typeof e=="string"?[e]:e;function valueMatches(e,t,n){return listOf(e).some(r=>r.startsWith("#")?n?.tags.includes(r.slice(1))??!1:r===t)}function holds(e,t,n,r,u){if(r===STRUCTURE){const i=structureOf(e,n);return i!==void 0&&valueMatches(u,i,void 0)?"yes":"no"}if(r in e.slots){if(!slotsOf(e,n).includes(r))return"no";const i=n[r];if(i===void 0)return"no";const o=e.slots[r]?.find(a=>a.name===i);return valueMatches(u,i,o)?"yes":"no"}if(r in t){const i=n[r];return i===void 0?"unknown":valueMatches(u,i,void 0)?"yes":"no"}return"no"}var all=e=>e.includes("no")?"no":e.includes("unknown")?"unknown":"yes";function keepsRule(e,t,n,r){const u=all(Object.entries(n.if??{}).map(([s,c])=>holds(e,t,r,s,c)));if(u==="no")return"yes";const i=Object.entries(n.require??{}).map(([s,c])=>holds(e,t,r,s,c)),o=Object.entries(n.exclude??{}).map(([s,c])=>{const l=holds(e,t,r,s,c);return l==="yes"?"no":l==="no"?"yes":"unknown"}),a=all([...i,...o]);return a==="yes"?"yes":u==="unknown"||a==="unknown"?"unknown":"no"}function keepsRules(e,t,n,r){return n.every(u=>keepsRule(e,t,u,r)!=="no")}function validCombo(e,t,n,r){const u=new Set(Object.keys(r));for(const[o,a]of Object.entries(t)){if(!a.includes(r[o]??""))return!1;u.delete(o)}if(!hasSlots(e))return u.size===0;const i=structureOf(e,r);if(i===void 0||!(i in e.structures))return!1;e.declared&&u.delete(STRUCTURE);for(const o of slotsOf(e,r)){if(!e.slots[o]?.some(a=>a.name===r[o]))return!1;u.delete(o)}return u.size===0&&keepsRules(e,t,n,r)}function fact(e,t,n){return{kind:e,...t,data:n}}var CONSOLE_LEVELS=["log","info","warn","error","debug"],PHASE_ORDER={module:0,build:1,mount:2,render:3,cover:4,other:5},CONSOLE_LIMIT=200,CONSOLE_TEXT_MAX=4e3,keyOf=e=>[e.level,e.phase,e.part??"",e.layer??"",e.index??"",e.text].join("\0"),ConsoleCollector=class{limit;kept=new Map;droppedCalls=0;constructor(e=CONSOLE_LIMIT){this.limit=Math.max(0,e)}add(e){const t=e.count??1,n=keyOf(e),r=this.kept.get(n);if(r){r.count+=t;const u=[r.t,e.t].filter(o=>o!==void 0),i=[r.until??r.t,e.until??e.t].filter(o=>o!==void 0);if(u.length>0){const o=Math.min(...u),a=Math.max(...i);r.t=o,a>o&&(r.until=a)}return}if(this.kept.size>=this.limit){this.droppedCalls+=t;return}this.kept.set(n,{level:e.level,text:e.text,phase:e.phase,...e.part===void 0?{}:{part:e.part},...e.layer===void 0?{}:{layer:e.layer},...e.index===void 0?{}:{index:e.index},...e.t===void 0?{}:{t:e.t},...e.until!==void 0&&e.t!==void 0&&e.until>e.t?{until:e.until}:{},count:t})}merge(e){for(const t of e.messages)this.add(t);this.droppedCalls+=e.dropped}log(e=[]){const t=new Map(e.map((r,u)=>[r,u]));return{messages:[...this.kept.values()].map((r,u)=>({m:r,i:u})).sort((r,u)=>PHASE_ORDER[r.m.phase]-PHASE_ORDER[u.m.phase]||(t.get(r.m.part??"")??-1)-(t.get(u.m.part??"")??-1)||(r.m.t??-1)-(u.m.t??-1)||r.i-u.i).map(({m:r})=>({...r})),dropped:this.droppedCalls}}};function nodeText(e){const t=globalThis.Node;if(!t||!(e instanceof t))return;const n=e;if(n.nodeType===1){const r=[...n.classList??[]].map(u=>`.${u}`).join("");return`<${n.nodeName.toLowerCase()}${r}${n.id?`#${n.id}`:""}>`}return JSON.stringify(n.textContent??"")}function shown(e){if(typeof e=="bigint")return`${String(e)}n`;if(typeof e=="function")return`[Function${e.name?` ${e.name}`:""}]`;if(typeof e=="number"&&!Number.isFinite(e))return String(e);if(typeof e!="object"||e===null)return e;if(e instanceof Error)return`${e.name}: ${e.message}`;const t=nodeText(e);return t!==void 0?t:e instanceof Map?{Map:[...e]}:e instanceof Set?{Set:[...e]}:ArrayBuffer.isView(e)&&!(e instanceof DataView)?Array.from(e):e}function jsonOf(e){const t=[];try{return JSON.stringify(e,function(n,r){for(;t.length>0&&t[t.length-1]!==this;)t.pop();if(typeof r!="object"||r===null)return shown(r);if(t.includes(r))return"[Circular]";t.push(r);const u=shown(r);return u!==r&&typeof u=="object"&&u!==null&&t.push(u),u})}catch{return Object.prototype.toString.call(e)}}function consoleValue(e){switch(typeof e){case"string":return e;case"number":case"boolean":case"undefined":return String(e);case"bigint":return`${String(e)}n`;case"symbol":return e.toString();case"function":return`[Function${e.name?` ${e.name}`:""}]`;case"object":{if(e===null)return"null";if(e instanceof Error)return`${e.name}: ${e.message}`;const t=nodeText(e);return t!==void 0?t:jsonOf(e)}}}function consoleText(e){const t=[...e],n=[],r=t[0];typeof r=="string"&&r.includes("%")&&(t.shift(),n.push(r.replace(/%([sdifoOjc%])/g,(i,o)=>{if(o==="%")return"%";if(t.length===0)return i;const a=t.shift();if(o==="c")return"";if(o==="d"||o==="i"||o==="f"){const s=typeof a=="symbol"?NaN:Number(a);return String(o==="f"?s:Math.trunc(s))}return consoleValue(a)}))),n.push(...t.map(consoleValue));const u=n.join(" ");return u.length<=CONSOLE_TEXT_MAX?u:`${u.slice(0,CONSOLE_TEXT_MAX)}… (${String(u.length-CONSOLE_TEXT_MAX)} more characters)`}var where={phase:"other"},collector=new ConsoleCollector,passThrough=!0,parts=[],installed=!1;function installConsole(){if(installed)return;installed=!0;const e=console;for(const t of CONSOLE_LEVELS){const n=e[t]?.bind(console);e[t]=(...r)=>{try{collector.add({level:t,text:consoleText(r),...where})}catch{}passThrough&&n?.(...r)}}}function resetConsole(e){collector=new ConsoleCollector(e.limit??CONSOLE_LIMIT),passThrough=e.passThrough,parts=[],where={phase:"other"}}function consoleParts(e){parts=e}function consoleAt(e,t){const n=where;where=e;try{return t()}finally{where=n}}async function consoleAtAsync(e,t){const n=where;where=e;try{return await t()}finally{where=n}}function consoleLog(){return collector.log(parts)}var round33=e=>Math.round(e*1e3)/1e3,round6=e=>Math.round(e*1e6)/1e6;function noCaptions(){return{lines:[],asked:void 0,cues:()=>[],partCues:()=>[],partWords:()=>[],wordEnd:(e,t)=>t+.4}}function captionTrack(e,t,n){const{specs:r,videoTakes:u,results:i}=e,{timing:o}=t,a=r.flatMap((f,m)=>{const h=o.parts[m],p=u[m];if(p&&h)return p.captionWords.length===0?[]:[{part:f.key,shown:p.line.shown||joinWords(p.captionWords),spoken:p.line.spoken||joinWords(p.captionWords),words:p.captionWords.map(b=>({text:b.text,start:round33(b.start+h.start),end:round33(b.end+h.start)}))}];const g=i[m]?.speech,D=h?.speechAt;if(D===void 0||!g||g.words.length===0)return[];const v=g.words.map(b=>({text:b.text,start:round33(b.start+D),end:round33(b.end+D)})),E=g.ranges?joinWords(g.words):i[m]?.shown??joinWords(g.words),y=g.ranges?E:g.script??E;return[{part:f.key,shown:E,spoken:y,words:v}]}),s=new Map,c=(f={})=>{const m=JSON.stringify([f.maxChars,f.maxWords,f.keep,f.close]);let h=s.get(m);return h||(h=wordCues(a,{fps:n,...f.maxChars===void 0?{}:{maxChars:f.maxChars},...f.maxWords===void 0?{}:{maxWords:f.maxWords},...f.keep===void 0?{}:{keep:f.keep},...f.close===void 0?{}:{close:f.close}}),s.set(m,h)),h},l=new Map(r.map((f,m)=>[f.key,o.words(m)]));let d;return{lines:a,get asked(){return d},cues:c,partCues(f,m,h){d??=h??{};const p=cuesIn(c(h),f,m);return h?.edges!==!0?p:p.map((g,D)=>({...g,...D===0?{start:0}:{},...D===p.length-1?{end:round6(m-f)}:{}}))},partWords:f=>l.get(f)??[],wordEnd(f,m){let h;for(const p of l.get(f)??[])(!h||Math.abs(p.start-m)<Math.abs(h.start-m))&&(h=p);return h&&Math.abs(h.start-m)<.05?h.end:m+.4}}}var LoadFailure=class extends Error{code;text;constructor(e,t){super(`${e}: ${t}`),this.name="LoadFailure",this.code=e,this.text=t}};function codeOf(e){const t=e??{};if(typeof t.code=="string"&&t.code in RULES)return t.code;if(t.code==="video_cycle")return"AK-M010";const n=typeof t.message=="string"?t.message:"",r=/\bAK-[A-Z]\d{3}\b/.exec(n)?.[0];return r!==void 0&&r in RULES?r:"AK-R001"}var messageOf=e=>e instanceof Error?e.message:String(e),round62=e=>Math.round(e*1e6)/1e6;function timeFilm(e,t,n,r){const{source:u,ledger:i}=e,{fps:o,isPaged:a,dims:s,options:c,format:l}=t,{specs:d,inputs:f}=n,m=r?.snapTo(f),h=timeParts([...f],{fps:o,beat:r?.beat??0,beatPhase:r?.beatPhase??0,...m?{snap:m}:{}});n.videoTakes.forEach((E,y)=>{const b=h.parts[y];!E||!b||(E.shown.start=b.start,E.shown.partStart=b.start)});const p=d.map((E,y)=>{const b=h.parts[y],A=f[y]?.placed??[],B=[...A,...(f[y]?.anchors??[]).filter($=>!A.some(x=>x.name===$.name))];return{key:E.key,start:b?.start??0,anchors:b?B.map($=>({name:$.name,at:round62(b.start+h.at(y,`@${$.name}`)),...$.end===void 0?{}:{end:round62(b.start+h.at(y,`@/${$.name}`))}})):[]}}),g=E=>momentOf({parts:p},E),D=(E,y)=>{try{if(typeof E=="number")return E;if(typeof E=="string")return g(E);const b=d.findIndex(B=>B.key===E.part),A=h.parts[b];if(b<0||!A)throw new Error(`The video has no part ${E.part}; its parts are ${d.map(B=>B.key).join(", ")}.`);return A.start+h.at(b,E.at)}catch(b){i.problems.push(problem("AK-T004",`${y}: ${messageOf(b)}`,{where:{file:u.file}}));return}},v=new Map;if(!a){const E=y=>Math.round((y.end-y.start)*o);d.forEach((y,b)=>{const A=h.parts[b-1],B=h.parts[b];if(y.transition===void 0||!A||!B)return;const $=transitionWindow(transitionSpec(y.transition),o,E(A),E(B));$.before+$.after>0&&v.set(b,$)})}return{timing:h,duration:h.duration,parts:p,filmAt:g,momentAt:D,windows:v,checkLimit(){const E=a?void 0:s.profile,y=c.maxDuration;E&&h.duration>E.maxDuration+1e-6&&!(y!==void 0&&y<=E.maxDuration)&&i.problems.push(problem("AK-F001",`This video lasts ${h.duration.toFixed(1)} s, and ${E.label} (${l}) takes at most ${String(E.maxDuration)} s. Cut ${(h.duration-E.maxDuration).toFixed(1)} s: shorter parts, an edits file on the take, or fewer parts.`,{where:{file:u.file}}))}}}var EPOCH_MS=Date.UTC(2026,0,1);function hashString(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function mulberry32(e){let t=e>>>0;return()=>{t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}var realNow=performance.now.bind(performance),realTimeout=setTimeout.bind(globalThis),nativeClearTimeout=clearTimeout.bind(globalThis),realClearTimeout=e=>{nativeClearTimeout(e)};function within2(e,t){const n=e.map(()=>{});return e.length===0?Promise.resolve(n):new Promise(r=>{let u=e.length;const i=realTimeout(()=>{r([...n])},Math.max(0,t));e.forEach((o,a)=>{o.then(s=>{n[a]={status:"fulfilled",value:s}},s=>{n[a]={status:"rejected",reason:s}}).finally(()=>{u--,u===0&&(realClearTimeout(i),r([...n]))})})})}var realRaf=typeof requestAnimationFrame=="function"?requestAnimationFrame.bind(globalThis):e=>Number(setTimeout(()=>{e(realNow())},16)),realTimers={now:realNow,setTimeout:realTimeout,clearTimeout:realClearTimeout},installed2;function installGuards(){if(installed2)return installed2;const e=globalThis,t=Date;let n=0,r=mulberry32(1);class u extends t{constructor(...c){c.length===0?super(EPOCH_MS+n):super(...c)}static now(){return EPOCH_MS+n}}e.Date=u,Math.random=()=>r(),performance.now=()=>n;const i=s=>{if(s){const c=new Uint8Array(s.buffer,s.byteOffset,s.byteLength);for(let l=0;l<c.length;l++)c[l]=Math.floor(r()*256)}return s};crypto.getRandomValues=i;let o=[],a=1;return e.requestAnimationFrame=s=>{const c=a++;return o.push([c,s]),c},e.cancelAnimationFrame=s=>{o=o.filter(([c])=>c!==s)},e.setTimeout=()=>0,e.setInterval=()=>0,installed2={setMoment(s,c){n=s*1e3,r=mulberry32(hashString(c))},flushFrames(){const s=o;o=[];for(const[,c]of s)c(n)}},installed2}var isFootage=e=>e.__allyhubLayer==="footage",zOf=e=>e.z==="behind-person"||e.z==="overlay"?e.z:"front",layerNames=e=>e.map(t=>isFootage(t)?"footage":t.component);function resolveTimes(e,t,n){if(Array.isArray(e))return e.map(u=>resolveTimes(u,t,n));if(t===!0)return typeof e=="string"||typeof e=="number"?n(e):e;if(typeof e!="object"||e===null)return e;const r={...e};for(const[u,i]of Object.entries(t))u in r&&r[u]!==void 0&&(r[u]=resolveTimes(r[u],i,n));return r}function windowOf(e,t,n){const r=o=>Math.min(Math.max(o,0),t),u=r(e.at===void 0?0:n(e.at)),i=e.until!==void 0?r(n(e.until)):e.dur!==void 0?r(u+e.dur):t;return[u,i]}function planStack(e){const t=e.some(l=>!isFootage(l)&&zOf(l)==="behind-person"),n=t?e.findIndex(l=>isFootage(l)&&l.file===void 0):-1,r=l=>n>=0&&!isFootage(l)&&zOf(l)==="behind-person",u=l=>l!==void 0&&!isFootage(l)&&zOf(l)==="overlay",i=[];e.forEach((l,d)=>{isFootage(l)?(i.push(d),d===n&&e.forEach((f,m)=>{r(f)&&i.push(m)})):!r(l)&&!u(l)&&i.push(d)}),e.forEach((l,d)=>{u(l)&&i.push(d)});const o=[],a=new Map,s=new Map;let c;for(const l of i){const d=e[l];if(!d)continue;if(isFootage(d)){c=void 0,s.set(l,o.length);continue}const f=r(d)?"behind":u(d)?"overlay":"front";c!==f&&(o.push({layers:[],...f==="behind"?{behindPerson:!0}:{},...f==="overlay"?{overlay:!0}:{}}),c=f),a.set(l,o.length-1)}return{takeAt:n,hasBehind:t,order:i,planes:o,planeOf:a,overOf:s,overlaid:l=>u(e[l])}}var noReads={captions:()=>[],face:()=>{},faces:()=>[],texts:()=>[]};function layerContexts(e,t,n,r,u){const{log:i,ledger:o,embed:a,combo:s}=e,{look:c,format:l,dims:d}=t,f=[[0,0,d.width,d.safe.top],[0,d.height-d.safe.bottom,d.width,d.safe.bottom],[0,0,d.safe.left,d.height],[d.width-d.safe.right,0,d.safe.right,d.height]].filter(g=>g[2]>0&&g[3]>0),m=contentEdges(d),h=[m.left,m.top,m.right-m.left,m.bottom-m.top],p=g=>{if(!u)throw new Error(`"${g}": a page has no film to find it in.`);return u.filmAt(g)};return g=>{const D=g.reads??noReads,v=g.record??(()=>{}),E=g.place,y=g.answers,b={look:c,format:l,dims:d,combo:g.combo??s,dur:g.dur,asset:A=>i.asset(A),optionalAsset:A=>i.optionalAsset(A),words:g.words,at:g.at,layer:{start:g.start,end:g.end},wait:A=>{o.wait(A)},report:A=>{const B=o.running,$=A.code in RULES?A.code:"AK-R001",x=B?.part??E?.part;o.ran(problem($,A.message,{...A.level?{level:A.level}:{},...x?{part:x}:{},...B?.t===void 0?{}:{t:B.t}}))},captions:A=>D.captions(A),face:(A,B)=>D.face(A,B),faces:A=>D.faces(A),texts:A=>D.texts(A),covered:f,content:h,video:(A,B)=>n.video(A,B,v),cameraFor:A=>a?.cameras?.[A]??a?.cameras?.["*"],...a?.sceneryScale===void 0?{}:{sceneryScale:a.sceneryScale},embedded:a!==void 0,get layoutOnly(){return r.mode==="layout"},realTimers,...y?{answer:(A,B)=>{y.set(A,B)}}:{}};return E&&Object.defineProperty(b,"film",{enumerable:!0,get:()=>(v("film",String(E.start)),{start:E.start,part:E.part,at:p,...a?.shown?{outer:a.shown}:{}})}),b}}var settled=e=>Math.max(0,e-.4),round34=e=>Math.round(e*1e3)/1e3,round63=e=>Math.round(e*1e6)/1e6;function compose(e){const{env:t,piece:n,stage:r,takes:u,film:i,captions:o,footage:a,sound:s}=e,{source:c,options:l,combo:d,picked:f,ledger:m}=t,{fps:h,format:p,dims:g}=n,{specs:D}=u,{timing:v,windows:E}=i,y=[],b=[],A=[],B=l.purpose==="play",$=new Set,x=(_,F)=>{const S={};for(const[k,w]of Object.entries(d)){if(!f.has(k)||k===F){S[k]=w;continue}Object.defineProperty(S,k,{enumerable:!0,get:()=>($.has(`${_}:${k}`)||($.add(`${_}:${k}`),m.problems.push(problem("AK-X005",`A layer of part ${_} reads ctx.combo.${k}, ${k===STRUCTURE?"the combo's structure":`the pick of the slot ${k}`}. A part is rendered once and reused in every combo that has it, so it may read only the dimensions${F===void 0?"":` and its own slot (${F})`}. Choose in the output's function instead, and pass the result as a prop.`,{part:_,where:{file:c.file}}))),w)})}return S};for(const[_,F]of D.entries()){const S=v.parts[_];if(!S)continue;const k=S.end-S.start,w=q=>v.at(_,q),I=o.partWords(F.key),M=u.results[_]?.speech,P=u.inputs[_],j=P?.placed??[],R=[...j,...(P?.anchors??[]).filter(q=>!j.some(Y=>Y.name===q.name))],U=u.speechFor(_,S);let O;if(typeof F.still=="function")O=F.still(k);else if(F.still===void 0){O=settled(k);const q=E.get(_),Y=E.get(_+1);if(q||Y){const ce=(q?.after??0)/h,he=k-((Y?.before??0)+1)/h;O=Math.max(ce,Math.min(O,he))}}else O=w(F.still);let Z=toFrame(S.start+O,h);(Z<S.start||Z>=S.end)&&(Z=S.start);const L=F.slot??(f.has(F.key)&&F.key!==STRUCTURE?F.key:void 0),T=f.size>0?x(F.key,L):d,G={reads:new Map,captioned:!1},V=planStack(F.layers),{takeAt:X,planes:J,planeOf:ie,overOf:oe,order:K}=V,Q=F.layers,H=u.videoTakes[_],ee={key:F.key,...F.title===void 0?{}:{title:F.title},...L===void 0?{}:{slot:L},layers:layerNames(Q),start:S.start,end:S.end,planes:J,still:Z,...U.speech?{speech:U.speech}:{},...R.length>0?{anchors:R.map(q=>({name:q.name,at:round34(S.start+w(`@${q.name}`)),...q.end===void 0?{}:{end:round34(S.start+w(`@/${q.name}`))}}))}:{},...F.tags?.length?{tags:[...F.tags]}:{},...F.post?{post:{filter:F.post.filter}}:{},...F.speechGainDb!==void 0&&F.speechGainDb!==0?{speechGainDb:F.speechGainDb}:{},...H?{plays:{video:H.id,from:H.from,to:H.to}}:{}};y.push(ee),s.addSpeech(U.clips,U.room);const W=document.createElement("section");W.className="ak-part",W.dataset.key=F.key,W.dataset.format=p,Object.assign(W.style,{position:"absolute",inset:"0",overflow:"hidden"}),showLayer(W,!1),r.el.append(W);const ue=new Map;B&&Q.forEach((q,Y)=>{if(!isFootage(q))return;const ce=document.createElement("div");ce.className="ak-footage-plane",Object.assign(ce.style,{position:"absolute",inset:"0",...(oe.get(Y)??0)>0?{pointerEvents:"none"}:{}}),ue.set(Y,ce)});let re;ue.size>0&&X>=0&&(re=document.createElement("div"),re.className="ak-cutout-plane",Object.assign(re.style,{position:"absolute",inset:"0",pointerEvents:"none"}));const ae={captions:q=>(G.captioned=!0,o.partCues(S.start,S.end,q)),face:(q,Y)=>a.faceAt(F.key,S.start+q,Y),faces:q=>a.facesAt(F.key,S.start+q)},de=[],se=new Map,me=Q.some(q=>!isFootage(q));for(const[q,Y]of Q.entries()){const[ce,he]=windowOf(Y,k,w);if(isFootage(Y)){const Ae=q===X,ye=a.plan(Y,ee,M,S.speechAt,ce,he,{at:w,cutout:Ae,over:oe.get(q)??0,graphics:me,person:Ae&&re!==void 0});if(ye&&B){const be=ue.get(q)??W,{matteUrl:xe,personOver:we,...ke}=ye;A.push({...ke,host:be,...xe===void 0?{}:{cutoutIn:{host:we&&re?re:be,matte:xe}}})}continue}const le=zOf(Y),De=ie.get(q)??0;J[De]?.layers.push({component:Y.component,start:round63(ee.start+ce),end:round63(ee.start+Math.max(ce,he))});const ne=document.createElement("div");ne.className="ak-layer",ne.dataset.component=Y.component,Object.assign(ne.style,{position:"absolute",inset:"0"}),showLayer(ne,!1),se.set(q,ne);const ve=Y.times?resolveTimes(Y.props,Y.times,w):Y.props,Ce=de.slice(),Be=new Map,$e=e.contexts({dur:k,words:()=>I,at:w,start:ce,end:he,combo:T,reads:{...ae,texts:Ae=>e.texts({part:ee,el:W},Ce,Ae)},record:(Ae,ye)=>G.reads.set(Ae,ye),place:{start:ee.start,part:F.key},answers:Be});de.push({spec:Y,index:q,props:ve,el:ne,ctx:$e,start:ce,end:he,z:le,plane:De,answers:Be})}let ge=W,pe;if(J.some(q=>q.overlay===!0)){ge=document.createElement("div"),pe=document.createElement("div"),ge.className="ak-picture",pe.className="ak-overlays";for(const q of[ge,pe])Object.assign(q.style,{position:"absolute",inset:"0",overflow:"hidden"}),W.append(q)}K.forEach((q,Y)=>{const ce=ue.get(q)??se.get(q);ce&&(pe&&V.overlaid(q)?pe:ge).append(ce);const he=ie.get(q),le=K[Y+1];re&&he!==void 0&&J[he]?.behindPerson===!0&&(le===void 0||ie.get(le)!==he)&&ge.append(re)}),s.sfx(F,ee,w),H&&s.carry(H.inner,H.from,H.to,ee.start,ee.key,0);for(const q of de){const Y=u.shownBy.get(q.spec);Y&&(Y.shown.start=ee.start+q.start,Y.shown.partStart=ee.start,Y.shown.from=Y.from,Y.shown.to=Y.from+(q.end-q.start)*Y.speed,Y.shown.speed=Y.speed,Y.audio!==void 0&&Y.speed===1&&s.carry(Y.inner,Y.from,Y.shown.to,ee.start+q.start,ee.key,Y.audio))}J.forEach((q,Y)=>{const ce=q.layers.filter(le=>le.end>le.start),he=a.placed.flatMap(le=>{if(le.part!==ee.key||(le.over??0)<=Y)return[];if(!ce.some(ne=>ne.end>le.start&&ne.start<le.end))return[];let De;for(const ne of le.boxes?le.boxes.map(ve=>ve.box):[le.box]){const ve=intersect(ne,[0,0,g.width,g.height]),Ce=ve?round34(ve[2]*ve[3]/(g.width*g.height)):0;(!De||Ce>De.frame)&&(De={box:ne,frame:Ce})}return De?[{file:le.file,start:le.start,end:le.end,...De}]:[]});he.length!==0&&m.facts.push(fact("graphics-under-footage",{piece:c.piece,part:F.key,t:ee.start},{layers:ce,footage:he,covered:Math.max(...he.map(le=>le.frame))}))}),V.hasBehind&&X<0&&m.facts.push(fact("fallback",{piece:c.piece,part:F.key},{missing:"own-footage",for:"behind-person",fallback:"in-front"})),b.push({part:ee,spec:F,n:_,el:W,picture:ge,...pe?{overlays:pe}:{},layers:de,record:G})}return{parts:y,mounted:b,clips:A}}var momentIn=(e,t)=>typeof t=="number"?t:momentOf(e.timeline,t),camerasOf=e=>e?.cameras??(e?.camera===void 0?void 0:{"*":e.camera});function pieceEntry(e,t){const n=t.written?.file;if(!(n===void 0||n===""))return Object.entries(e.pieces??{}).find(([,r])=>r.file===n)}function createEmbedder(e,t,n){const{source:r,options:u,embed:i,combo:o}=e,a=[],s=[...i?.chain??[],r.piece],c={loaded:a,async load(l,d,f={}){const m=isPieceDefinition(l)?pieceEntry(r,l):void 0;if(!isPieceDefinition(l)||!m)throw new LoadFailure("bad_video",'A video item of the project is shown by its piece, imported (import demo from "../demo/video") and passed as it is.');const[h,p]=m;if(s.includes(h))throw new LoadFailure("video_cycle",`${[...s,h].join(" → ")}: a video item that shows itself, through the videos it shows (AK-M010). A source cannot reach itself.`);const g=outputName(l.kind),D=f.frame===!0?r.format:p.format,v=Object.fromEntries(Object.entries(p.dims).map(([$,x])=>{const _=o[$];return[$,_!==void 0&&x.includes(_)?_:x[0]??""]})),E=d.parentNode,y=d.nextSibling,b=document.createElement("div");b.dataset.akHolder="",Object.assign(b.style,{position:"absolute",left:"0px",top:"0px",visibility:"hidden",pointerEvents:"none"}),t.el.append(b),b.append(d);let A;try{A=await n({...r,piece:h,file:p.file,module:"",styles:[],dims:p.dims,format:D,...p.matrix?{matrix:p.matrix}:{}},{combo:v,purpose:u.purpose},d,{def:l,chain:s,...f.cameras?{cameras:f.cameras}:{},...f.shown?{shown:f.shown}:{},...f.sceneryScale===void 0?{}:{sceneryScale:f.sceneryScale}}),await A.ready()}finally{t.takeOutside(),E?E.insertBefore(d,y):d.remove(),t.takeOutside(),b.remove()}const B={id:h,output:g,format:D,inner:A};return a.push(B),B},async video(l,d,f){const{id:m,output:h,format:p,inner:g}=await c.load(l,d);return f(`video:${m}:${h}:${p}`,JSON.stringify(g.signs())),{id:m,duration:g.timeline.duration,width:g.timeline.width,height:g.timeline.height,seek:(D,v)=>g.seek(D,{mode:v===!0?"layout":"picture"}),at:D=>momentOf(g.timeline,D)}}};return c}var isBoxKeys=e=>Array.isArray(e)&&e.length>0&&typeof e[0]=="object";function videoLayer(e,t,n,r,u){const{inner:i,host:o}=n,a=i.timeline.width,s=i.timeline.height,c=forOrient(t.box,e.orient);if(isBoxKeys(c))throw new LoadFailure("bad_footage",'footage() of a video item takes one box (or "full"), not keyframes.');const[l,d,f,m]=c===void 0||c==="full"?[0,0,1,1]:c,h=t.fit??"cover",p=t.cameras??(t.camera===void 0?void 0:t.camera);return{[LAYER_BRAND]:"graphic",component:"video",...t.at===void 0?{}:{at:t.at},...t.until===void 0?{}:{until:t.until},...t.dur===void 0?{}:{dur:t.dur},props:{...u,box:[l,d,f,m],fit:h,...p===void 0?{}:{camera:p},...t.quality?{quality:t.quality}:{},parts:i.signs()},mount(g){const D={x:l*e.width,y:d*e.height,w:f*e.width,h:m*e.height},v=h==="contain"?Math.min(D.w/a,D.h/s):Math.max(D.w/a,D.h/s),E=document.createElement("div");Object.assign(E.style,{position:"absolute",left:`${String(D.x)}px`,top:`${String(D.y)}px`,width:`${String(D.w)}px`,height:`${String(D.h)}px`,overflow:"hidden"}),Object.assign(o.style,{position:"absolute",left:`${String((D.w-a*v)/2)}px`,top:`${String((D.h-s*v)/2)}px`,width:`${String(a)}px`,height:`${String(s)}px`,transformOrigin:"0 0",transform:`scale(${String(v)})`}),E.appendChild(o),g.appendChild(E)},render(g,D,v,E){const y=Math.min(Math.max(r(D,E),0),Math.max(0,i.timeline.duration-.001)),b=E.layoutOnly===!0?"layout":"picture";E.wait(Promise.resolve().then(()=>i.seek(y,{mode:b})))}}}var PLACEHOLDER="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",KEY_PART_MIN=3,ReadLog=class{messages=new Map;media=new Map;data=new Map;keyByText=new Map;missingReads=new Set;missingMedia=new Set;problems=[];texts=new Set;tap;opts;fileOf;constructor(e){this.opts=e,this.fileOf=t=>`${e.text??TEXT_DIR}/${t??"en"}.json`}value(e){const{own:t,fallback:n,lang:r,defaultLang:u}=this.opts;return Object.hasOwn(t,e)?{value:t[e],fellBack:!1}:Object.hasOwn(n,e)?{value:n[e],fellBack:r!==u}:{value:void 0,fellBack:!1}}record(e,t,n){if(this.messages.has(e))return;const{value:r,fellBack:u}=this.value(e);this.messages.set(e,{key:e,kind:t,fallback:u,...n?{hint:n}:{}}),t!=="list"&&r===void 0&&this.problems.push(problem("AK-S001",`The code reads ${e}, but the default language ${this.opts.defaultLang??"(no messages)"} does not have it. Add it to ${this.fileOf(this.opts.defaultLang)}.`,{where:{file:this.fileOf(this.opts.defaultLang)}}))}locale(e){return Object.hasOwn(this.opts.own,e)?this.opts.lang:this.opts.defaultLang}text(e,t,n){this.record(e,"text",t);const{value:r}=this.value(e);this.tap?.(`m:${e}`,JSON.stringify(r??null));for(const u of textsOf(r))this.texts.add(u);return displayOf(r,n,this.locale(e))??""}s(e,t){const n=this.text(e,t,{});return n&&this.keyByText.set(n,{key:e,inputs:{}}),n}with(e,t,n){const r=fillMessage(this.text(e,n,t),t);return this.texts.add(r),r&&this.keyByText.set(r,{key:e,inputs:t}),r}spokenOf(e){const t=this.keyByText.get(e);if(!t)return;const n=speakOf(this.value(t.key).value,t.inputs,this.locale(t.key)),r=(Object.hasOwn(this.opts.own,t.key)?this.opts.anchors?.own:this.opts.anchors?.fallback)?.[t.key];return{key:t.key,speak:n===void 0?e:fillMessage(n,t.inputs),...r&&n!==void 0?{anchors:lineAnchors(n,r,u=>fillMessage(u,t.inputs))}:{}}}list(e,t){const n=[],r=new Set([...Object.keys(this.opts.own),...Object.keys(this.opts.fallback)]),u=messageList(i=>displayOf(this.value(i).value,{},this.locale(i)),r,e,n);this.record(e,"list",t),n.length===0&&this.problems.push(problem("AK-S001",`The code reads the list ${e}, but the default language has no keys like ${e}.0, ${e}.1. Add them to ${this.fileOf(this.opts.defaultLang)}.`,{where:{file:this.fileOf(this.opts.defaultLang)}}));for(const i of n)this.text(i,void 0,{});return u}peek(e){return this.value(e).value}touch(e){const{value:t,fellBack:n}=this.value(e);return this.tap?.(`m:${e}`,JSON.stringify(t??null)),t!==void 0&&!this.messages.has(e)&&this.messages.set(e,{key:e,kind:"text",fallback:n}),t}mediaAt(e){const t=this.opts.media[e];return t&&this.media.set(e,asUrlString(t)),this.tap?.(`f:${e}`,t?.sha256??""),t}missing(e){this.missingReads.add(e)}report(e){this.problems.some(t=>t.code===e.code&&t.message===e.message)||this.problems.push(e)}relativeTo(e){this.base=e}base;get pathBase(){return this.base??this.opts.file}baseOf(e){return e===void 0?this.pathBase:e===""?"the project's root":e}resolve(e,t){return t===void 0?repoPath(this.pathBase,e):pathIn(t,e)}asset(e,t){const n=this.baseOf(t),r=this.resolve(e,t),u=r===void 0?void 0:this.mediaAt(r);if(u)return u;const i=r??e;return this.missingMedia.has(i)||(this.missingMedia.add(i),this.problems.push(problem("AK-A001",r===void 0?`"${e}" points outside the project. Put media in the project, with a path relative to ${n}.`:`"${e}" (named in ${n}) cannot find ${r}: the path is wrong, or the file is not in the project yet.`,{where:{file:n}}))),asUrlString({path:r??e,sha256:"",kind:"image",url:PLACEHOLDER,width:1,height:1})}optionalAsset(e){const t=repoPath(this.pathBase,e);if(t===void 0)return;const n=this.mediaAt(t);return n||this.missing(t),n?asUrlString(n):void 0}optionalData(e,t){const n=this.resolve(e,t);if(n===void 0)return{found:!1};const r=this.opts.data?.[n];return this.data.set(n,r?.sha256??""),r?r.error===void 0?{full:n,found:!0,value:r.value}:{full:n,found:!0,error:r.error}:{full:n,found:!1}}readData(e){const t=repoPath(this.pathBase,e),n=t===void 0?void 0:this.opts.data?.[t];if(t!==void 0&&n){if(this.data.set(t,n.sha256),this.tap?.(`d:${t}`,n.sha256),n.error===void 0)return n.value;this.missingMedia.has(t)||(this.missingMedia.add(t),this.problems.push(problem("AK-R001",`Cannot read the data file ${t}: ${n.error}`,{where:{file:t}})));return}this.missingMedia.has(e)||(this.missingMedia.add(e),this.problems.push(problem("AK-A001",t===void 0?`ctx.data("${e}") points outside the project. Put data files in the project, with a path relative to ${this.pathBase}.`:`ctx.data("${e}") cannot find ${t}: the path is wrong, or the file is not CSV, YAML or JSON.`,{where:{file:this.pathBase}})))}reads(e,t){const n=r=>{if(!r.startsWith(`${e}.`))return;const u=r.slice(e.length+1).split(".")[0]??"";return t.includes(u)?u:void 0};return{messages:[...this.messages.values()].map(r=>{const u=n(r.key);return u===void 0?r:{...r,part:u}}).sort((r,u)=>r.key<u.key?-1:r.key>u.key?1:0),media:[...[...this.media.values()].map(r=>({path:r.path,sha256:r.sha256,kind:r.kind})),...[...this.missingReads].filter(r=>!this.media.has(r)).map(r=>({path:r,sha256:"",kind:"audio"}))].sort((r,u)=>r.path<u.path?-1:1),data:[...this.data.entries()].map(([r,u])=>({path:r,sha256:u})).sort((r,u)=>r.path<u.path?-1:1)}}translationProblems(){const e=[];for(const t of this.messages.values())t.fallback&&t.kind==="text"&&e.push(problem("AK-S002",`${this.opts.lang??""} is missing a translation: ${t.key}. The ${this.opts.defaultLang??""} text was used.`,{where:{file:this.fileOf(this.opts.lang)}}));return e}keysShowing(e){const t=o=>o.replace(/[\s\p{Cf}]+/gu,""),n=t(e);if(n==="")return[];const r=[],u=[];for(const o of this.messages.values()){const a=textsOf(this.peek(o.key)).flatMap(s=>hasMarks(s)?[s,withoutMarks(s)]:[s]).map(t);a.includes(n)?r.push(o.key):a.some(s=>s.includes(n))&&u.push(o.key)}return r.length>0?r:(n.match(/[\p{L}\p{N}]/gu)?.length??0)>=KEY_PART_MIN?u:[]}get file(){return this.fileOf(this.opts.lang)}},RUN_PROBLEMS=200,Ledger=class{problems=[];facts=[];run=[];times=[];running;loading=!0;doing;waiting=[];ran(e){this.run.length>=RUN_PROBLEMS||this.run.some(t=>t.code===e.code&&t.message===e.message&&t.part===e.part)||this.run.push(e)}async timed(e,t){const n=realNow();try{return await t()}finally{this.times.push({what:e,ms:realNow()-n})}}wait(e){const t=this.running;if(!this.loading){this.waiting.push({work:e,who:t});return}const n=this.doing??"a layer",r=realNow();this.waiting.push({work:e.finally(()=>{this.times.push({what:`the work ${n} waited for (ctx.wait)`,ms:realNow()-r})}),who:t})}async settle(e){const t=realNow()+e,n=[];for(;this.waiting.length>0;){const r=this.waiting.splice(0);if((await within2(r.map(i=>i.work),t-realNow())).forEach((i,o)=>{const a=r[o]?.who;if(i===void 0){n.push(`the work ${whoText(a)} waits for (ctx.wait)`);return}if(i.status==="fulfilled")return;const s=i.reason;this.ran(problem(codeOf(i.reason),`${whoText(a)}: the work it waits for (ctx.wait) failed: ${String(s.message??i.reason)}`,{...a?.part===void 0?{}:{part:a.part},...a?.t===void 0?{}:{t:a.t}}))}),n.length>0)break}return n}},whoText=e=>e?.what??"A layer";function checkCombo(e,t){const n=e.dims,r=e.matrix?.space;if(validCombo(r,n,e.matrix?.rules??[],t.combo))return;const u=r?`; slots: ${Object.entries(r.slots).map(([i,o])=>`${i}=${o.map(a=>a.name).join("|")}`).join(", ")}${r.declared?`; structures: ${Object.keys(r.structures).join("|")}`:""}; and the matrix's rules`:"";throw new LoadFailure("bad_combo",`Piece ${e.piece} has no combo ${comboKey(t.combo)} (dimensions: ${Object.entries(n).map(([i,o])=>`${i}=${o.join("|")}`).join(", ")||"none"}${u}).`)}function createEnv(e,t,n){const r=realNow();checkCombo(e,t);const u={...t.combo},i=u.lang,o=e.locales[0],a=(n?n.def.kind==="paged":entryKind(e.file)==="slides")?"slides":"video",s=`${e.piece}:${a}:${seedKey(u,e.format)}`,c=seedKey(dimsCombo(e.dims,u),e.format),l=e.matrix?.space,d=new Set(l?[...Object.keys(l.slots),...l.declared?[STRUCTURE]:[]]:[]),f=installGuards();f.setMoment(0,`${s}:load`),n||(installConsole(),resetConsole({...t.consoleLimit===void 0?{}:{limit:t.consoleLimit},passThrough:t.purpose==="play"}));const m=new ReadLog({lang:i,defaultLang:o,...e.text===void 0?{}:{text:e.text},own:i===void 0?{}:e.messages[i]??{},fallback:o===void 0?{}:e.messages[o]??{},...e.anchors?{anchors:{...i!==void 0&&e.anchors[i]?{own:e.anchors[i]}:{},...o!==void 0&&e.anchors[o]?{fallback:e.anchors[o]}:{}}}:{},media:e.media,file:e.file,...e.data?{data:e.data}:{}});return{source:e,options:t,embed:n,combo:u,lang:i,defaultLang:o,output:a,seedBase:s,partSeed:(h,p)=>`${e.piece}:${a}:${c}:${h}:${String(p)}`,picked:d,space:l,guards:f,log:m,ledger:new Ledger,start:r,mediaOf:(h,p)=>typeof h=="string"?m.asset(h,p):m.mediaAt(h.path)??m.asset(`/${h.path}`)}}var BACKDROP_IMAGE=/\.(png|jpe?g|webp)$/i,treats=e=>(e.blur??0)>0||(e.dim??0)>0||(e.desaturate??0)>0||e.color!==void 0||e.image!==void 0,round35=e=>Math.round(e*1e3)/1e3;function footagePlanner(e,t,n,r){const{source:u,ledger:i,embed:o}=e,{dims:a,fps:s,isPaged:c}=t,l=[],d=new Map,f=new Set,m=new Map,h=(v,E)=>{const y=m.get(v)??{file:v};y[E]=!0,m.set(v,y)},p=(v,E)=>{i.facts.push(fact("fallback",{piece:u.piece,part:v},E))},g=(v,E,y)=>{const b=backdropUnit(a.width,a.height),A=x=>Math.round(x*b*1e3)/1e3;let B;if(v.image!==void 0){if(B=e.mediaOf(v.image,y),B.sha256==="")return;if(B.kind!=="image"||!BACKDROP_IMAGE.test(B.path)){i.problems.push(problem("AK-A003",`The background image ${B.path} of footage() in part ${E} is not a PNG, JPEG or WebP image.`,{part:E,where:{file:u.file}}));return}}let $;if(v.color!==void 0){const x=CSS.supports("color",v.color)?r(v.color):void 0;if(x===void 0)throw new Error(`footage() background color ${JSON.stringify(v.color)} in part ${E} is not a CSS color.`);$=x.length===9&&x.endsWith("00")?"transparent":x}return{backdrop:{...v.blur?{blur:A(v.blur)}:{},...v.dim?{dim:v.dim}:{},...v.desaturate?{desaturate:v.desaturate}:{},...$===void 0?{}:{color:$},...B?{image:B.path}:{},feather:A(v.feather??MATTE_FEATHER),shrink:A(v.shrink??MATTE_SHRINK)},...B?{imageUrl:B.url}:{}}};return{plan:(v,E,y,b,A,B,$)=>{const x=v.file,_=x===void 0;let F;if(_){if(!y){i.problems.push(problem("AK-A001",`footage() in part ${E.key} names no file, so it shows the part's take, and the part has no take${c?" (pages have no speech)":""}. Give footage a file, or give the part speech: take("./clip.mp4").`,{part:E.key,where:{file:u.file}}));return}F=y.media}else F=e.mediaOf(x,v.base);if(F.sha256==="")return;if(F.kind!=="video"){i.problems.push(problem("AK-A003",_?`footage() in part ${E.key} shows the part's take, and ${F.path} is not a video. Give footage a file, or take a video.`:`The footage ${F.path} in part ${E.key} is not a video (mp4, webm or mov).`,{part:E.key,where:{file:u.file}}));return}const S=toFrame(E.start+A,s),k=toFrame(E.start+B,s);if(k<=S)return;F.faces&&d.set(F.path,F.faces),F.matte===!0&&f.add(F.path);let w,I;if(_&&y&&b!==void 0){const ue=y.ranges??[{from:y.from,to:y.from+y.dur}];if(w=round35(fromEdited(ue,S-b)),y.ranges&&y.ranges.length>1){const re=[{at:S,from:w}];let ae=0;for(const de of y.ranges){const se=round35(b+ae);ae>0&&se>S+1e-6&&se<k&&re.push({at:se,from:de.from}),ae+=de.to-de.from}re.length>1&&(I=re)}}else w=Math.max(0,typeof v.from=="number"?v.from:0);const M=F.width!==void 0&&F.height!==void 0?{width:F.width,height:F.height}:void 0,P=v.fit??"cover",j=forOrient(v.box,a.orient),R=forOrient(v.crop,a.orient),U=isBoxKeys(j)?j:void 0,O=U?.map(ue=>({t:toFrame(E.start+Math.min(Math.max($.at(ue.t),A),B),s),box:ue.box==="full"?[0,0,a.width,a.height]:pixelRect(ue.box,a.width,a.height),...ue.ease?{ease:ue.ease}:{}})).sort((ue,re)=>ue.t-re.t),Z=U?"full":j??"full",L=O?.[0],T=placeFootage({box:L?[L.box[0]/a.width,L.box[1]/a.height,L.box[2]/a.width,L.box[3]/a.height]:Z,fit:P,...R?{crop:R}:{},...M?{source:M}:{},frame:a}),G=v.shape==="circle"||!v.radius?0:round35(Math.min(v.radius*backdropUnit(a.width,a.height),T.box[2]/2,T.box[3]/2));let V=T.crop,X=T.picture,J,ie;const oe=v.punchIn??[],K=v.pullback===void 0||v.pullback===!1?void 0:v.pullback===!0?{}:v.pullback;if((v.reframe!==void 0||oe.length>0||K)&&M){const ue=T.box,re=reframeWindow(M,{w:ue[2],h:ue[3]}),ae=typeof v.reframe=="object"&&"face"in v.reframe?v.reframe:void 0,de=v.reframe==="face"||ae!==void 0;de&&!F.faces&&(h(F.path,"faces"),p(E.key,{file:F.path,missing:"face-track",for:"reframe",fallback:"centred"}));const se=F.faces,me=v.speaker??se?.speaker;se&&v.speaker!==void 0&&!hasFace(se,v.speaker)&&p(E.key,{file:F.path,missing:"face",face:v.speaker,for:"speaker",fallback:"centred"});const ge=typeof v.reframe=="object"&&"x"in v.reframe?v.reframe:de?REFRAME_FALLBACK:{x:.5,y:.5},pe={start:S,end:k,from:w,speed:_?1:v.speed??1,...I?{cuts:I}:{}};J=reframePath({track:de?se:void 0,speaker:me,faceY:ae?.faceY,focus:ge,window:re,source:M,layer:pe});const q=J[0]??{x:0,y:0};V=[q.x,q.y,re.w,re.h],X=[...ue],J.length<=1&&(J=void 0);const Y=J,ce=(ne,ve)=>{if(ve)return{cx:ve.x,cy:ve.y};const Ce=se?faceAt(se,sourceAt(pe,ne),me):void 0;if(!Ce)return{cx:PUNCH_CENTER.x,cy:PUNCH_CENTER.y};const Be=Y?keyAt(Y.map(be=>({t:be.t,v:be.x})),ne):q.x,$e=Y?keyAt(Y.map(be=>({t:be.t,v:be.y})),ne):q.y,Ae=(Ce[0]+Ce[2]/2-Be)/re.w,ye=(Ce[1]+Ce[3]/2-$e)/re.h;return{cx:round35(Math.min(Math.max(Ae,0),1)),cy:round35(Math.min(Math.max(ye,0),1))}},he=[];for(const ne of oe){const ve=typeof ne=="object"?{...ne,ref:ne.at}:{...parsePunch(String(ne)),until:void 0},Ce=$.at(ve.ref),Be=ve.until!==void 0?$.at(ve.until):n.wordEnd(E.key,Ce),$e=E.start+Ce;he.push({start:$e,end:E.start+Math.max(Be,Ce),scale:ve.scale??PUNCH_SCALE,...ce($e,typeof ne=="object"?ne.center:void 0),...typeof ne=="object"&&ne.in!==void 0?{in:ne.in}:{},...typeof ne=="object"&&ne.out!==void 0?{out:ne.out}:{},...typeof ne=="object"&&ne.ease!==void 0?{ease:ne.ease}:{}})}const le=he.length>0?punchKeys(he):[],De=K?pullbackKeys(S,{scale:K.scale??PULLBACK_SCALE,dur:K.dur??PULLBACK_DUR,...ce(S,K.center),...K.ease?{ease:K.ease}:{}},le):le;De.length>0&&(ie=De)}_&&$.graphics&&!F.faces&&h(F.path,"faces");let Q=!1;$.cutout&&(F.matte===!0?Q=!0:(h(F.path,"matte"),p(E.key,{file:F.path,missing:"person-matte",for:"behind-person",fallback:"in-front"})));let H;if(v.background&&treats(v.background)){const ue=g(v.background,E.key,v.base);ue&&F.matte===!0?H=ue:ue&&(h(F.path,"matte"),p(E.key,{file:F.path,missing:"person-matte",for:"background",fallback:"unprocessed"}))}if(o)throw new LoadFailure("embedded_footage",`${u.piece}'s part ${E.key} plays ${F.path}: a video shown inside another (a scenery's screen, a part's video take, a footage of a video item) draws its graphic layers only, not footage yet.`);const ee=Q&&$.person,W={part:E.key,file:F.path,start:S,end:k,from:w,speed:_?1:v.speed??1,gainDb:v.gainDb??0,audio:!c&&(v.audio??!1)&&F.audio===!0,..._?{take:!0}:{},fit:P,box:T.box,...V?{crop:V}:{},picture:X,...I?{cuts:I}:{},...J?{pan:J}:{},...ie?{zoom:ie}:{},...O&&O.length>1?{boxes:O}:{},...$.over>0?{over:$.over}:{},...Q?{cutout:!0}:{},...v.sharpen?{sharpen:v.sharpen}:{},...H?{background:H.backdrop}:{},...H?.imageUrl?{imageUrl:H.imageUrl}:{},...(ee||H)&&F.matteUrl?{matteUrl:F.matteUrl}:{},...ee?{personOver:!0}:{},...v.shape==="circle"?{shape:"circle"}:{},...G>0?{radius:G}:{},...v.speaker===void 0?{}:{speaker:v.speaker},url:F.url,...F.duration===void 0?{}:{duration:F.duration},...M?{source:M}:{}};return l.push(W),W},placed:l,needs:()=>[...m.values()],speakerIn:v=>l.some(E=>E.part===v&&(d.has(E.file)||f.has(E.file))),faceAt(v,E,y){for(let b=l.length-1;b>=0;b--){const A=l[b];if(A?.part!==v||E<A.start||E>=A.end)continue;const B=d.get(A.file);if(!B)continue;const $=y===void 0?faceOnFrame(A,B,E):faceOnFrame(A,B,E,y);if($)return $}},facesAt(v,E){for(let y=l.length-1;y>=0;y--){const b=l[y];if(b?.part!==v||E<b.start||E>=b.end)continue;const A=d.get(b.file);if(!A)continue;const B=facesOnFrame(b,A,E);if(B.length>0)return B}return[]}}}function timelineFootage(e){return{part:e.part,file:e.file,start:e.start,end:e.end,from:e.from,speed:e.speed,gainDb:e.gainDb,audio:e.audio,...e.take?{take:!0}:{},fit:e.fit,box:e.box,...e.crop?{crop:e.crop}:{},picture:e.picture,...e.cuts?{cuts:e.cuts}:{},...e.pan?{pan:e.pan}:{},...e.zoom?{zoom:e.zoom}:{},...e.boxes?{boxes:e.boxes}:{},...e.over?{over:e.over}:{},...e.cutout?{cutout:!0}:{},...e.sharpen?{sharpen:e.sharpen}:{},...e.background?{background:e.background}:{},...e.shape?{shape:e.shape}:{},...e.radius?{radius:e.radius}:{},...e.speaker===void 0?{}:{speaker:e.speaker}}}var MIX_DEFAULTS={speech:-16,music:-20,musicAlone:-16,sfx:-22,footage:-16,footageUnderSpeech:-22,duck:{db:-8,attack:.3,release:1,hold:2},musicFade:{in:.3,out:1.5}};function resolveMix(e){const t=MIX_DEFAULTS;return{speech:e?.speech??t.speech,music:e?.music??t.music,musicAlone:e?.musicAlone??t.musicAlone,sfx:e?.sfx??t.sfx,footage:e?.footage??t.footage,footageUnderSpeech:e?.footageUnderSpeech??t.footageUnderSpeech,duck:{...t.duck,...e?.duck},musicFade:{...t.musicFade,...e?.musicFade}}}var MASTER_DEFAULTS={lufs:-14,truePeak:-3},MASTER_MECHANICS={attack:.002,release:.04,oversample:4,rounds:4,tolerance:.1};function resolveMaster(e,t){const n=t??MASTER_DEFAULTS.lufs;return e===!1?{lufs:!1,truePeak:MASTER_DEFAULTS.truePeak}:typeof e=="number"?{lufs:e,truePeak:MASTER_DEFAULTS.truePeak}:{lufs:e?.lufs??n,truePeak:e?.truePeak??MASTER_DEFAULTS.truePeak}}function merge2(e,t){const n=[];for(const r of[...e].sort((u,i)=>u.start-i.start)){const u=n.at(-1);u&&r.start-u.end<t?u.end=Math.max(u.end,r.end):n.push({start:r.start,end:r.end})}return n}function spansEnvelope(e,t,n,r){const u=[];for(const i of e)u.push({t:Math.max(0,i.start-n),db:0},{t:i.start,db:t},{t:i.end,db:t},{t:i.end+r,db:0});return u}function duckEnvelope(e,t=MIX_DEFAULTS.duck){return t.db>=0||e.length===0?[]:spansEnvelope(merge2(e,t.hold+t.attack+t.release),t.db,t.attack,t.release)}function speechSpans(e,t=MIX_DEFAULTS.duck){return merge2(e.filter(n=>n.dur>0).map(n=>({start:n.at,end:n.at+n.dur})),t.attack+t.release)}function speechEnvelope(e,t,n=MIX_DEFAULTS.duck){return t===0||e.length===0?[]:spansEnvelope(e,t,n.attack,n.release)}function addEnvelopes(e,t){return e.length===0?[...t]:t.length===0?[...e]:[...new Set([...e,...t].map(r=>r.t))].sort((r,u)=>r-u).map(r=>({t:r,db:gainAt(e,r)+gainAt(t,r)}))}var equalPower=e=>Math.sin(Math.PI/2*Math.min(1,Math.max(0,e)));function gainAt(e,t){if(e.length===0)return 0;const n=e[0];if(!n||t<=n.t)return n?.db??0;for(let r=1;r<e.length;r++){const u=e[r-1],i=e[r];if(!(!u||!i)&&t<=i.t)return i.t===u.t?i.db:u.db+(i.db-u.db)*(t-u.t)/(i.t-u.t)}return e.at(-1)?.db??0}var decodeKey=(e,t)=>`${e}\0${String(t.denoise??0)}\0${String(t.speed??1)}\0${t.filter??""}`,speechHow=e=>({...e.denoise?{denoise:e.denoise}:{},...e.speed!==void 0&&e.speed!==1?{speed:e.speed}:{}});function decodings(e){const t=new Map,n=(r,u)=>t.set(decodeKey(r,u),{file:r,how:u});for(const r of e.speech)n(r.file,speechHow(r));for(const r of e.footage)n(r.file,{});e.music&&n(e.music.file,e.music.shape?.filter?{filter:e.music.shape.filter}:{});for(const r of e.sfx)r.file!==void 0&&n(r.file,r.shape?.filter?{filter:r.shape.filter}:{});return[...t.values()]}function clipSource(e){return t=>{const n=e(t.file,speechHow(t));if(!n)return;const r=t.speed!==void 0&&t.speed!==1?t.speed:void 0;return r!==void 0&&n.made.speed===r?{src:n.src,stretched:r}:{src:n.src}}}var BUTTERWORTH_Q=Math.SQRT1_2;function biquad(e,t){const n=Math.min(Math.max(e.hz,1),t*.49),r=2*Math.PI*n/t,u=Math.cos(r),i=Math.sin(r);let o,a,s,c,l,d;switch(e.type){case"lowpass":case"highpass":case"bandpass":{const f=e.q??BUTTERWORTH_Q,m=i/(2*f);c=1+m,l=-2*u,d=1-m,e.type==="lowpass"?(o=(1-u)/2,a=1-u,s=(1-u)/2):e.type==="highpass"?(o=(1+u)/2,a=-(1+u),s=(1+u)/2):(o=m,a=0,s=-m);break}case"peak":{const f=10**(e.db/40),m=i/(2*(e.q??1));o=1+m*f,a=-2*u,s=1-m*f,c=1+m/f,l=-2*u,d=1-m/f;break}case"lowshelf":case"highshelf":{const f=10**(e.db/40),m=e.slope??1,h=i/2*Math.sqrt((f+1/f)*(1/m-1)+2),p=2*Math.sqrt(f)*h;e.type==="lowshelf"?(o=f*(f+1-(f-1)*u+p),a=2*f*(f-1-(f+1)*u),s=f*(f+1-(f-1)*u-p),c=f+1+(f-1)*u+p,l=-2*(f-1+(f+1)*u),d=f+1+(f-1)*u-p):(o=f*(f+1+(f-1)*u+p),a=-2*f*(f-1+(f+1)*u),s=f*(f+1+(f-1)*u-p),c=f+1-(f-1)*u+p,l=2*(f-1-(f+1)*u),d=f+1-(f-1)*u-p);break}}return{b0:o/c,b1:a/c,b2:s/c,a1:l/c,a2:d/c}}function biquadGain(e,t,n){const r=2*Math.PI*t/n,u=Math.cos(r),i=Math.sin(r),o=Math.cos(2*r),a=Math.sin(2*r),s=e.b0+e.b1*u+e.b2*o,c=-(e.b1*i+e.b2*a),l=1+e.a1*u+e.a2*o,d=-(e.a1*i+e.a2*a);return Math.hypot(s,c)/Math.hypot(l,d)}function runBiquads(e,t){for(const n of t){let r=0,u=0;for(let i=0;i<e.length;i++){const o=e[i]??0,a=n.b0*o+r;r=n.b1*o-n.a1*a+u,u=n.b2*o-n.a2*a,e[i]=a}}}var fromDb=e=>10**(e/20);function gainComputer(e,t){const n=e-t.threshold,r=t.knee;let u;return 2*n<-r?u=e:r>0&&2*Math.abs(n)<=r?u=e+(1/t.ratio-1)*(n+r/2)**2/(2*r):u=t.threshold+n/t.ratio,u-e}function levels(e,t,n){const r=e[0]?.length??0,u=new Float32Array(r);if(t<=0){for(let a=0;a<r;a++){let s=0;for(const c of e)s=Math.max(s,Math.abs(c[a]??0));u[a]=20*Math.log10(Math.max(s,1e-9))}return u}const i=Math.exp(-1/(t*n));let o=0;for(let a=0;a<r;a++){let s=0;for(const c of e)s=Math.max(s,(c[a]??0)**2);o=i*o+(1-i)*s,u[a]=10*Math.log10(Math.max(o,1e-18))}return u}function smooth(e,t,n,r){const u=t>0?Math.exp(-1/(t*r)):0,i=n>0?Math.exp(-1/(n*r)):0,o=new Float32Array(e.length);let a=0;for(let s=0;s<e.length;s++){const c=e[s]??0,l=c<a?u:i;a=l*a+(1-l)*c,o[s]=a}return o}function compress(e,t,n){const r=levels(e,t.window,n),u=new Float32Array(r.length);for(let o=0;o<r.length;o++)u[o]=gainComputer(r[o]??-180,t);const i=smooth(u,t.attack,t.release,n);for(const o of e)for(let a=0;a<o.length;a++)o[a]=(o[a]??0)*fromDb(i[a]??0)}function deess(e,t,n){const r=biquad({type:"highpass",hz:t.hz},n),u=biquad({type:"lowpass",hz:t.hz},n),i=l=>{const d=Float32Array.from(l);runBiquads(d,[r,r]);const f=Float32Array.from(l);return runBiquads(f,[u,u]),{low:f,high:d}},o=e.map(i),a=levels(o.map(l=>l.high),.005,n),s=new Float32Array(a.length);for(let l=0;l<a.length;l++)s[l]=gainComputer(a[l]??-180,{...t,knee:6});const c=smooth(s,t.attack,t.release,n);e.forEach((l,d)=>{const f=o[d];if(f)for(let m=0;m<l.length;m++)l[m]=(f.low[m]??0)+(f.high[m]??0)*fromDb(c[m]??0)})}function agc(e,t,n){const r=levels(e,.05,n),u=new Float32Array(r.length),i=Math.exp(-1/(Math.max(t.window,.001)*n));let o=-1;for(let s=0;s<r.length;s++){const c=r[s]??-180;if(t.gate===void 0||c>=t.gate){const l=10**(c/10);o=o<0?l:i*o+(1-i)*l}u[s]=o<0?0:Math.min(t.most,t.target-10*Math.log10(Math.max(o,1e-18)))}const a=smooth(u,t.attack,t.release,n);for(const s of e)for(let c=0;c<s.length;c++)s[c]=(s[c]??0)*fromDb(a[c]??0)}function kWeighting(e){const t=1681.974450955533,n=3.999843853973347,r=.7071752369554196,u=Math.tan(Math.PI*t/e),i=10**(n/20),o=i**.4996667741545416,a=1+u/r+u*u,s={b0:(i+o*u/r+u*u)/a,b1:2*(u*u-i)/a,b2:(i-o*u/r+u*u)/a,a1:2*(u*u-1)/a,a2:(1-u/r+u*u)/a},c=biquad({type:"highpass",hz:38.13547087602444,q:.5003270373238773},e),l={b0:1,b1:-2,b2:1,a1:c.a1,a2:c.a2};return[s,l]}function integratedLoudness(e,t){const n=e[0]?.length??0,r=Math.round(.4*t),u=Math.round(.1*t);if(n<r)return;const i=kWeighting(t),o=Math.floor(n/u),a=new Float64Array(o);for(const h of e){const p=Float32Array.from(h);runBiquads(p,i);for(let g=0;g<o;g++){let D=0;for(let v=g*u;v<(g+1)*u;v++)D+=(p[v]??0)**2;a[g]=(a[g]??0)+D}}const s=[],c=Math.round(r/u);for(let h=0;h+c<=o;h++){let p=0;for(let g=0;g<c;g++)p+=a[h+g]??0;s.push(p/(c*u))}const l=h=>-.691+10*Math.log10(Math.max(h,1e-20)),d=s.filter(h=>l(h)>-70);if(d.length===0)return;const f=d.reduce((h,p)=>h+p,0)/d.length,m=d.filter(h=>l(h)>l(f)-10);if(m.length!==0)return l(m.reduce((h,p)=>h+p,0)/m.length)}function steadyLoudness(e,t){const n=kWeighting(t);let r=0,u=0;for(const i of e){const o=Float32Array.from(i);runBiquads(o,n);let a=0;for(const s of o)a+=s*s;r+=a/Math.max(1,o.length),u=Math.max(u,o.length)}if(!(u===0||r<=1e-20))return-.691+10*Math.log10(r)}var COMPRESS_DEFAULTS={ratio:2,knee:6,attack:.01,release:.15,window:.01};function bandAt(e,t){const n=e.keys??[];let r=e.hz,u=e.db??0,i=e.q;if(n.length>0){const o=[...n].sort((f,m)=>f.at-m.at),a=(f,m)=>f[m]??(m==="hz"?e.hz:m==="db"?e.db??0:e.q),s=o[0],c=o.at(-1);let l=s,d=s;if(s&&t<=s.at)l=s,d=s;else if(c&&t>=c.at)l=c,d=c;else for(let f=1;f<o.length;f++){const m=o[f];if(m&&t<m.at){l=o[f-1],d=m;break}}if(l&&d){const f=d.at===l.at?1:(t-l.at)/(d.at-l.at),m=a(l,"hz")??e.hz,h=a(d,"hz")??e.hz;r=m===h||f<=0?m:f>=1?h:Math.exp(Math.log(m)+(Math.log(h)-Math.log(m))*f);const p=a(l,"db")??0,g=a(d,"db")??0;u=p+(g-p)*f;const D=a(l,"q"),v=a(d,"q");i=D===void 0||v===void 0?D??v:D+(v-D)*f}}switch(e.type){case"peak":return{type:"peak",hz:r,db:u,...i===void 0?{}:{q:i}};case"lowshelf":case"highshelf":return{type:e.type,hz:r,db:u,...i===void 0?{}:{slope:i}};default:return{type:e.type,hz:r,...i===void 0?{}:{q:i}}}}var BLOCK=32;function runBand(e,t,n,r){if(!t.keys||t.keys.length===0){runBiquads(e,[biquad(bandAt(t,0),n)]);return}let u=0,i=0,o=biquad(bandAt(t,r),n);for(let a=0;a<e.length;a++){a%BLOCK===0&&(o=biquad(bandAt(t,r+(a+BLOCK/2)/n),n));const s=e[a]??0,c=o.b0*s+u;u=o.b1*s-o.a1*c+i,i=o.b2*s-o.a2*c,e[a]=c}}function shapeSound(e,t,n,r=0){if(!t)return;for(const i of t.eq??[])for(const o of e)runBand(o,i,n,r);const u=t.compress;if(u){const i=soundLevel(e,n)?.lufs;if(i===void 0)return;const o={threshold:i+u.threshold,ratio:u.ratio??COMPRESS_DEFAULTS.ratio,knee:u.knee??COMPRESS_DEFAULTS.knee,attack:u.attack??COMPRESS_DEFAULTS.attack,release:u.release??COMPRESS_DEFAULTS.release,window:u.window??COMPRESS_DEFAULTS.window};compress(e,o,n)}}function soundLevel(e,t){const n=integratedLoudness(e,t);if(n!==void 0&&n>-70)return{lufs:n,by:"integrated"};const r=steadyLoudness(e,t);return r===void 0?void 0:{lufs:r,by:"level"}}var shapes=e=>(e?.eq?.length??0)>0||e?.compress!==void 0;function playMusic(e,t,n,r){const u=Math.round(n*r),i=[new Float32Array(u),new Float32Array(u)],o=t[0].length;if(o===0)return i;for(const d of e.segments){const f=Math.round(d.at*r),m=Math.round(d.from*r),h=Math.round(d.dur*r),p=Math.round(d.fadeIn*r),g=Math.round(d.fadeOut*r);for(let D=0;D<h;D++){const v=f+D,E=m+D;if(v<0||v>=u||E<0||E>=o)continue;let y=1;p>0&&D<p&&(y*=equalPower(D/p)),g>0&&h-1-D<g&&(y*=equalPower((h-1-D)/g)),i[0][v]=(i[0][v]??0)+(t[0][E]??0)*y,i[1][v]=(i[1][v]??0)+(t[1][E]??0)*y}}let a=e.gainDb;if(e.shape&&(shapes(e.shape)||e.shape.filter!==void 0)){shapeSound(i,e.shape,r,0);const d=soundLevel(i,r);d&&(a=e.alone-d.lufs)}const s=Math.round(e.fadeIn*r),c=Math.round(e.fadeOut*r),l=Math.min(u,Math.round((e.until??n)*r));for(let d=0;d<u;d++){if(d>=l){i[0][d]=0,i[1][d]=0;continue}let f=10**((a+gainAt(e.duck,d/r))/20);d<s&&(f*=d/s),l-d<c&&(f*=(l-d)/c),i[0][d]=(i[0][d]??0)*f,i[1][d]=(i[1][d]??0)*f}return i}var SFX_HIT={whoosh:.18,tick:.004,pop:.01};function hashSeed(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t}function rng(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function synthSfx(e,t,n){const r=rng(n),u=()=>r()*2-1,i=.2;if(e==="tick"){const f=Math.round(t*.06),m=new Float32Array(f);for(let h=0;h<f;h++){const p=h/t,g=Math.exp(-p*90);m[h]=(Math.sin(2*Math.PI*3200*p)*.8+u()*.2)*g}return normalize(m,i*.7)}if(e==="pop"){const f=Math.round(t*.12),m=new Float32Array(f);let h=0;for(let p=0;p<f;p++){const g=p/t,D=300+600*Math.exp(-g*40);h+=2*Math.PI*D/t;const v=Math.min(1,g/.002)*Math.exp(-g*35);m[p]=Math.sin(h)*v}return normalize(m,i)}const o=.55,a=Math.round(t*o),s=new Float32Array(a),c=SFX_HIT.whoosh??.18;let l=0,d=0;for(let f=0;f<a;f++){const m=f/t,h=400+2600*Math.exp(-(((m-c)/.12)**2)),p=2*Math.sin(Math.PI*h/t),g=u()-l-.7*d;d+=p*g,l+=p*d;const D=m<c?(m/c)**2:Math.exp(-((m-c)/(o-c))*4);s[f]=d*D}return normalize(s,i)}function normalize(e,t){let n=0;for(const r of e)n=Math.max(n,Math.abs(r));if(n>0)for(let r=0;r<e.length;r++)e[r]=(e[r]??0)/n*t;return e}var twiddles=new Map;function twiddlesOf(e){let t=twiddles.get(e);if(!t){const n=new Float64Array(e/2),r=new Float64Array(e/2);for(let u=0;u<e/2;u++)n[u]=Math.cos(2*Math.PI*u/e),r[u]=-Math.sin(2*Math.PI*u/e);t={cos:n,sin:r},twiddles.set(e,t)}return t}function nextPow2(e){let t=1;for(;t<e;)t*=2;return t}function fft(e,t,n=!1){const r=e.length;if(r<=1)return;for(let a=1,s=0;a<r;a++){let c=r>>1;for(;s&c;c>>=1)s^=c;if(s^=c,a<s){const l=e[a]??0;e[a]=e[s]??0,e[s]=l;const d=t[a]??0;t[a]=t[s]??0,t[s]=d}}const{cos:u,sin:i}=twiddlesOf(r),o=n?-1:1;for(let a=2;a<=r;a<<=1){const s=r/a,c=a/2;for(let l=0;l<r;l+=a)for(let d=0;d<c;d++){const f=u[d*s]??1,m=(i[d*s]??0)*o,h=l+d,p=h+c,g=e[p]??0,D=t[p]??0,v=g*f-D*m,E=g*m+D*f,y=e[h]??0,b=t[h]??0;e[p]=y-v,t[p]=b-E,e[h]=y+v,t[h]=b+E}}if(n)for(let a=0;a<r;a++)e[a]=(e[a]??0)/r,t[a]=(t[a]??0)/r}function convolve(e,t){const n=new Float32Array(e.length);if(t.length===0||e.length===0)return n;if(t.length<=64){for(let c=0;c<e.length;c++){let l=0;const d=Math.min(t.length,c+1);for(let f=0;f<d;f++)l+=(t[f]??0)*(e[c-f]??0);n[c]=l}return n}const r=nextPow2(2*t.length),u=r-t.length+1,i=new Float64Array(r),o=new Float64Array(r);for(let c=0;c<t.length;c++)i[c]=t[c]??0;fft(i,o);const a=new Float64Array(r),s=new Float64Array(r);for(let c=0;c<e.length;c+=2*u){a.fill(0),s.fill(0);const l=c+u;for(let d=0;d<u;d++)a[d]=e[c+d]??0,s[d]=e[l+d]??0;fft(a,s);for(let d=0;d<r;d++){const f=a[d]??0,m=s[d]??0,h=i[d]??0,p=o[d]??0;a[d]=f*h-m*p,s[d]=f*p+m*h}fft(a,s,!0);for(let d=0;d<r;d++){const f=c+d;f<n.length&&(n[f]=(n[f]??0)+(a[d]??0));const m=l+d;m<n.length&&(n[m]=(n[m]??0)+(s[d]??0))}}return n}function minimumPhase(e,t,n=4096){const r=nextPow2(n*4),u=new Float64Array(r),i=new Float64Array(r);for(let s=0;s<=r/2;s++){const c=Math.max(e(s*t/r),1e-6);u[s]=Math.log(c),s>0&&s<r/2&&(u[r-s]=u[s]??0)}fft(u,i,!0);for(let s=1;s<r/2;s++)u[s]=2*(u[s]??0),i[s]=0;i[0]=0,i[r/2]=0;for(let s=r/2+1;s<r;s++)u[s]=0,i[s]=0;fft(u,i);for(let s=0;s<r;s++){const c=Math.exp(u[s]??0),l=i[s]??0;u[s]=c*Math.cos(l),i[s]=c*Math.sin(l)}fft(u,i,!0);const o=new Float64Array(n),a=Math.max(1,Math.floor(n/4));for(let s=0;s<n;s++){const c=s-(n-a),l=c>0?.5*(1+Math.cos(Math.PI*c/a)):1;o[s]=(u[s]??0)*l}return o}var SOUND_SPEED=343,PATTERNS={omni:1,subcardioid:.75,cardioid:.5,supercardioid:.37,hypercardioid:.25,figure8:0};function patternGain(e,t){const n=PATTERNS[e];return n+(1-n)*t}function proximity(e,t,n){const r=PATTERNS[e],u=2*Math.PI*Math.max(n,1)*Math.max(t,.005)/SOUND_SPEED;return Math.hypot(1,(1-r)/u)}var TALKER_BEHIND=[[63,0],[125,-1],[250,-2],[500,-4],[1e3,-6],[2e3,-9],[4e3,-13],[8e3,-18],[16e3,-25]];function curveDb(e,t){const n=e[0],r=e[e.length-1];if(!n||!r)return 0;if(t<=n[0])return n[1];if(t>=r[0])return r[1];for(let u=1;u<e.length;u++){const i=e[u-1],o=e[u];if(!i||!o||t>o[0])continue;const a=Math.log(t/i[0])/Math.log(o[0]/i[0]);return i[1]+(o[1]-i[1])*a}return r[1]}function talkerDb(e,t){return curveDb(TALKER_BEHIND,e)*((1-t)/2)}function cosBetween(e,t){const n=Math.hypot(e[0],e[1],e[2]),r=Math.hypot(t[0],t[1],t[2]);return n===0||r===0?1:(e[0]*t[0]+e[1]*t[1]+e[2]*t[2])/(n*r)}function random(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function gaussian(e){const t=random(e);let n;return()=>{if(n!==void 0){const o=n;return n=void 0,o}const r=Math.max(t(),1e-12),u=t(),i=Math.sqrt(-2*Math.log(r));return n=i*Math.sin(2*Math.PI*u),i*Math.cos(2*Math.PI*u)}}function noiseGain(e,t){const n=Math.max(t,10);let r=e.tilt*Math.log2(n/1e3);return r+=e.rumble/(1+(n/120)**2),n>e.top&&(r-=48*Math.log2(n/e.top)),10**(r/20)}function roomTone2(e,t,n,r){const u=gaussian(r),i=new Float32Array(e+4096);for(let d=0;d<i.length;d++)i[d]=u();const o=minimumPhase(d=>noiseGain(n,d),t,2048),a=convolve(i,o).subarray(4096);let s=0;for(const d of a)s+=d*d;const c=Math.sqrt(s/Math.max(1,a.length)),l=new Float32Array(e);for(let d=0;d<e;d++)l[d]=(a[d]??0)/(c||1);if(n.hum){const d=10**(n.hum.db/20)*Math.SQRT2,f=random(r^2654435769);for(let m=1;m<=6;m++){const h=n.hum.hz*m;if(h>n.top)break;const p=d/2**(m-1),g=f()*2*Math.PI,D=2*Math.PI*h/t;for(let v=0;v<e;v++)l[v]=(l[v]??0)+p*Math.sin(D*v+g)}}return l}var ROOM_PRESETS={bedroom:{size:[3.4,2.6,4],walls:"plasterboard",floor:"carpet",ceiling:"plasterboard-ceiling",rt60:.4,talker:[1.5,1.2,1.5],order:3},"living-room":{size:[5,2.7,6],walls:"plasterboard",floor:"wood",ceiling:"plasterboard-ceiling",rt60:.55,talker:[2.2,1.2,2.5],order:3},office:{size:[4,2.8,5],walls:"plasterboard",floor:"carpet-thin",ceiling:"ceiling-tiles",rt60:.45,talker:[1.8,1.2,2],order:3},kitchen:{size:[3,2.6,4],walls:"tiles",floor:"tiles",ceiling:"plasterboard-ceiling",rt60:.75,talker:[1.4,1.6,1.6],order:3},treated:{size:[3,2.6,3.5],walls:"foam",floor:"carpet",ceiling:"foam",rt60:.2,talker:[1.4,1.2,1.4],order:3},car:{size:[1.4,1.15,1.9],walls:"glass",floor:"upholstery",ceiling:"upholstery",rt60:.08,talker:[.45,.85,.9],order:6},outdoor:{size:[60,30,60],walls:"hard",floor:"hard",ceiling:"hard",rt60:.4,talker:[30,1.6,30],open:!0,order:1}},DEESS={hz:5500,threshold:-12,ratio:3,attack:.002,release:.06},POST_PRESETS={finish:{highpass:70,eq:[],deess:DEESS,compress:{threshold:-3,ratio:4,knee:6,attack:.005,release:.3,window:.01}},"phone-app":{highpass:90,eq:[{type:"peak",hz:300,db:-2,q:1},{type:"peak",hz:4e3,db:3,q:.8},{type:"highshelf",hz:1e4,db:1}],deess:DEESS,compress:{threshold:0,ratio:3,knee:6,attack:.005,release:.12,window:.01}}},ROOM_TONE={tilt:-4,rumble:8,top:16e3},SETUP_PRESETS={studio:{pattern:"cardioid",distance:.2,angle:0,below:0,response:[[125,-3.5],[250,-3],[500,-.5],[1e3,0],[2e3,-2],[4e3,-1.5],[8e3,-4],[12500,-4]],band:[20,2e4],stereo:!1,room:!1,noise:!1,agc:!1,post:"finish"},phone:{pattern:"omni",distance:.35,angle:0,below:25,response:[[125,-8.5],[250,-3.5],[500,-.5],[1e3,0],[2e3,0],[4e3,0],[8e3,-3.5],[12500,-2.5]],band:[100,16e3],stereo:.1,room:{preset:"bedroom",rt60:.2},noise:{...ROOM_TONE,below:42},agc:{target:0,most:10,attack:.3,release:1.5,window:2,gate:-25},post:!1},lav:{pattern:"omni",distance:.22,angle:0,below:70,response:[[125,-2],[250,-3],[500,.5],[1e3,0],[2e3,-1],[4e3,-1],[8e3,-3.5],[12500,-4]],band:[70,18e3],stereo:!1,room:{preset:"bedroom",rt60:.13},noise:{tilt:-4,rumble:4,top:18e3,below:50},agc:!1,post:"finish"}},SOURCE_DEFAULTS={pattern:"cardioid",distance:.2};function bandCentres(e){const t=Math.floor(Math.log2(e/125));return Array.from({length:t},(n,r)=>125*2**r)}var MATERIALS={hard:[.02,.02,.03,.03,.04,.05,.05],plasterboard:[.15,.1,.06,.04,.04,.05,.05],"plasterboard-ceiling":[.2,.15,.1,.08,.04,.02,.02],tiles:[.01,.01,.01,.02,.02,.02,.02],concrete:[.01,.03,.05,.02,.02,.02,.02],wood:[.18,.12,.1,.09,.08,.07,.07],carpet:[.08,.08,.3,.6,.75,.8,.8],"carpet-thin":[.02,.04,.08,.2,.35,.4,.4],glass:[.1,.05,.04,.03,.03,.03,.03],curtains:[.05,.12,.35,.45,.38,.36,.36],"ceiling-tiles":[.49,.53,.53,.75,.92,.99,.99],foam:[.12,.33,.83,.97,.98,.95,.95],upholstery:[.44,.6,.77,.89,.82,.7,.7],grass:[.11,.26,.6,.69,.92,.99,.99]},AIR=[1e-4,3e-4,6e-4,.001,.0019,.0058,.0203];function atBands(e,t){return t.map(n=>{const r=Math.log2(n/125),u=Math.min(Math.max(Math.floor(r),0),e.length-2),i=e[u]??0,o=e[u+1]??i;return Math.min(1,Math.max(0,i+(o-i)*(r-u)))})}var C=343;function areas(e){const[t,n,r]=e;return[n*r,n*r,t*r,t*r,t*n,t*n]}function reverberation(e,t){const n=bandCentres(t),[r,u,i]=e.size,o=r*u*i,a=areas(e.size),s=a.reduce((l,d)=>l+d,0),c=atBands(AIR,n);return n.map((l,d)=>{let f=0;e.surfaces.forEach((h,p)=>{const g=e.open?.[p]===!0;f+=(a[p]??0)*(g?1:atBands(h,n)[d]??0)});const m=Math.min(f/s,.999);return 24*Math.LN10*o/(C*(-s*Math.log(1-m)+4*(c[d]??0)*o))})}function withReverberation(e,t,n){const r=a=>({...e,surfaces:e.surfaces.map(s=>s.map(c=>Math.min(.99,c*a)))}),u=a=>{const s=reverberation(a,n);return((s[2]??0)+(s[3]??0))/2};let i=.001,o=1e3;for(let a=0;a<60;a++){const s=Math.sqrt(i*o);u(r(s))>t?i=s:o=s}return r(Math.sqrt(i*o))}function bandShapes(e,t,n){const r=t/2+1,u=e.map(()=>new Float64Array(r)),i=e.map((s,c)=>c===0?0:Math.round(s/Math.SQRT2/n*t)),o=e.map(s=>Math.round(s/n*t)),a=e.map((s,c)=>c===e.length-1?r:Math.round(s*Math.SQRT2/n*t));e.forEach((s,c)=>{const l=u[c];if(l)for(let d=i[c]??0;d<Math.min(a[c]??r,r);d++)l[d]=1});for(let s=1;s<e.length;s++){const c=Math.max(1,Math.round(.5*((a[s]??0)-(o[s]??0)))),l=u[s-1],d=u[s];if(!(!l||!d))for(let f=-c;f<=c;f++){const m=(i[s]??0)+f;if(m<0||m>=r)continue;const h=(f/c+1)/2;l[m]=Math.cos(Math.PI*h/2),d[m]=Math.sin(Math.PI*h/2)}}return u}function addImpulse(e,t,n){const r=Math.floor(t),u=t-r;for(let i=0;i<81;i++){const o=r-40+i;if(o<0||o>=e.length)continue;const a=i-40-u,s=Math.abs(a)<1e-9?1:Math.sin(Math.PI*a)/(Math.PI*a),c=.5-.5*Math.cos(2*Math.PI*i/80);e[o]=(e[o]??0)+n*c*s}}function roomResponse(e,t,n){const r=bandCentres(t),u=r.length,[i,o,a]=e.size,s=[i,o,a],c=e.talker,l=e.mic,d=e.surfaces.map((R,U)=>e.open?.[U]===!0?r.map(()=>0):atBands(R,r).map(O=>Math.sqrt(1-O))),f=atBands(AIR,r),m=reverberation(e,t),h=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],p=Math.hypot(...h),g=40,D=e.order,v=[];let E=1/0;for(let R=-(D+1);R<=D+1;R++)for(let U=-(D+1);U<=D+1;U++)for(let O=-(D+1);O<=D+1;O++){const Z=Math.abs(R)+Math.abs(U)+Math.abs(O);if(Z===0||Z>D+1)continue;const L=[R,U,O],T=(H,ee)=>{const W=s[ee]??1,ue=c[ee];return H*W+(Math.abs(H)%2===1?W-ue:ue)},G=[T(R,0)-l[0],T(U,1)-l[1],T(O,2)-l[2]],V=Math.hypot(...G),X=(V-p)/C;if(Z===D+1){L.every((ee,W)=>ee===0||!(e.open?.[W*2]===!0&&e.open[W*2+1]===!0))&&(E=Math.min(E,X));continue}let J=!1;const ie=r.map((H,ee)=>{let W=1;return L.forEach((ue,re)=>{const ae=ue>0?Math.floor(ue/2):Math.ceil(-ue/2),de=ue>0?Math.ceil(ue/2):Math.floor(-ue/2),se=d[re*2]?.[ee]??0,me=d[re*2+1]?.[ee]??0;(ae>0&&se===0||de>0&&me===0)&&(J=!0),W*=se**ae*me**de}),W});if(J)continue;const oe=[Math.abs(R)%2===1?G[0]:-G[0],Math.abs(U)%2===1?G[1]:-G[1],Math.abs(O)%2===1?G[2]:-G[2]],K=patternGain(e.pattern,cosBetween(G,e.axis)),Q=cosBetween(oe,e.facing);v.push({t:X,amp:ie.map((H,ee)=>{const W=r[ee]??1e3,ue=proximity(e.pattern,V,W)/proximity(e.source.pattern,e.source.distance,W);return H*K/V*Math.exp(-.5*(f[ee]??0)*V)*10**(talkerDb(W,Q)/20)*ue})})}Number.isFinite(E)||(E=.08);const y=Math.max(...m),b=Math.ceil((Math.min(Math.max(y,E+.05),3)+.01)*t)+2*g,A=nextPow2(2*b),B=bandShapes(r,A,t),$=new Float64Array(A),x=new Float64Array(A),_=new Float64Array(A),F=new Float64Array(A),S=Math.round(E*t),[k,w,I]=e.size,M=k*w*I,P=e.open?.some(Boolean)===!0,j=new Float64Array(b);if(!P){const R=random(n);let U=E;for(;U*t<b-g;){const T=Math.floor(U*t)+g;j[T]=(j[T]??0)+(R()<.5?-1:1);const G=Math.min(4*Math.PI*C**3*(U+p/C)**2/M,1e4);U+=Math.log(1/Math.max(R(),1e-12))/G}const O=Math.max(1,Math.round(.004*t)),Z=new Float64Array(b);let L=0;for(let T=0;T<b;T++)L+=(j[T]??0)**2,T>=O&&(L-=(j[T-O]??0)**2),Z[T]=L/O;for(let T=0;T<b;T++){const G=Z[Math.min(b-1,T+Math.floor(O/2))]??0;G>0&&(j[T]=(j[T]??0)/Math.sqrt(G))}}for(let R=0;R<u;R++){_.fill(0),F.fill(0);for(const O of v)!P&&O.t>E+.002||addImpulse(_,O.t*t+g,O.amp[R]??0);if(!P){const O=m[R]??.4,Z=Math.round(.01*t);for(let L=S+g-Math.round(.002*t);L<b;L++){const T=(L-g)/t,G=Math.sqrt(4*Math.PI*C/M/t*Math.exp(-6*Math.LN10*(T+p/C)/O)),V=L-(S+g-Math.round(.002*t)),X=V<Z?.5-.5*Math.cos(Math.PI*V/Z):1;F[L]=(j[L]??0)*G*X}}fft(_,F);const U=B[R];if(U)for(let O=0;O<A;O++){const Z=O<=A/2?O:A-O,L=(U[Z]??0)**2,T=(A-O)%A,G=_[O]??0,V=F[O]??0,X=_[T]??0,J=F[T]??0,ie=(G+X)/2,oe=(V-J)/2,K=(V+J)/2,Q=(X-G)/2;$[O]=($[O]??0)+L*(ie+K),x[O]=(x[O]??0)+L*(oe+Q)}}return fft($,x,!0),{reflections:$.slice(0,b),direct:{gain:patternGain(e.pattern,cosBetween([-h[0],-h[1],-h[2]],e.axis))/p,cos:cosBetween(h,e.facing),distance:p},lead:g,rt60:m,mixing:E}}var surface=(e,t)=>e===void 0?[...MATERIALS[t]??[]]:typeof e=="string"?[...MATERIALS[e]??[]]:[...e];function resolveRoom(e,t){if(e===!1||e===void 0&&t===!1)return!1;const n=t===!1?{preset:"bedroom"}:typeof t=="string"?{preset:t}:t,r=typeof e=="string"?{preset:e}:e===void 0?n:e.preset===void 0?{...n,...e}:e,u=ROOM_PRESETS[r.preset??"bedroom"];return{size:r.size??u.size,walls:surface(r.walls,u.walls),floor:surface(r.floor,u.floor),ceiling:surface(r.ceiling,u.ceiling),rt60:r.rt60??u.rt60,talker:r.talker??u.talker,...u.open?{open:!0}:{},order:u.order}}function resolvePickup(e,t,n){const r=SETUP_PRESETS[t],u=e.noise===!1?!1:e.noise===void 0?r.noise:{...r.noise||{tilt:-4,rumble:8,top:16e3,below:45},...e.noise},i=e.agc===!1?!1:e.agc===void 0?r.agc:{...r.agc||{target:0,most:10,attack:.3,release:1.5,window:1},...e.agc};return{pattern:e.pattern??r.pattern,distance:e.distance??r.distance,angle:e.angle??r.angle,below:e.below??r.below,response:(e.response??r.response).map(([o,a])=>[o,a]),band:e.band??r.band,stereo:e.stereo??r.stereo,room:resolveRoom(e.room,r.room),noise:u===!1?!1:{tilt:u.tilt,rumble:u.rumble,top:u.top,below:u.below,...u.hum?{hum:u.hum}:{}},agc:i===!1?!1:{target:i.target??0,most:i.most??10,attack:i.attack??.3,release:i.release??1.5,window:i.window??1,...i.gate===void 0?{}:{gate:i.gate}},gain:n,toneAt:r.distance}}function resolvePost(e,t){if(e===!1)return!1;const n=typeof e=="string"?e:e?.preset??(t===!1?void 0:t),r=n===void 0?void 0:POST_PRESETS[n],u=typeof e=="object"?e:{};if(!r&&typeof e!="object")return!1;const i=u.deess===!1?!1:u.deess===void 0?r?.deess??!1:{...r?.deess||POST_PRESETS.finish.deess||{hz:5500,threshold:-12,ratio:3,attack:.002,release:.06},...u.deess},o=u.compress===!1?!1:u.compress===void 0?r?.compress??!1:{...r?.compress||POST_PRESETS.finish.compress||{threshold:2,ratio:2,knee:6,attack:.01,release:.15,window:.01},...u.compress};return{highpass:u.highpass??r?.highpass??!1,eq:[...u.eq??r?.eq??[]],deess:i,compress:o}}function resolveVoice(e){if(e===!1)return!1;const t=typeof e=="string"?{setup:e}:e??{},n=t.setup??"studio",r=SETUP_PRESETS[n],u=resolvePickup(t,n,0);return{setup:n,source:{pattern:t.source?.pattern??SOURCE_DEFAULTS.pattern,distance:t.source?.distance??SOURCE_DEFAULTS.distance},pickups:[u,...(t.also??[]).map(i=>({...resolvePickup(i,i.setup??n,i.gain??-12),...i.room===void 0?{room:u.room}:{}}))],post:resolvePost(t.post,r.post)}}var impulses=new Map;function placement(e,t,n,r){const u=e.angle*Math.PI/180,i=e.below*Math.PI/180,o=[Math.sin(u)*Math.cos(i),-Math.sin(i),Math.cos(u)*Math.cos(i)],a=(c,l)=>Math.min(Math.max(c,.05),l-.05),s=[a(t[0]+o[0]*e.distance+r,n[0]),a(t[1]+o[1]*e.distance,n[1]),a(t[2]+o[2]*e.distance,n[2])];return{mic:s,axis:[t[0]-s[0],t[1]-s[1],t[2]-s[2]]}}function bandGain(e,t,n){let r=1;return e[0]>15&&(r*=biquadGain(biquad({type:"highpass",hz:e[0]},n),t,n)),e[1]<n*.45&&(r*=biquadGain(biquad({type:"lowpass",hz:e[1]},n),t,n)),r}var micFilters=new Map;function micFilter(e,t){const n=JSON.stringify([e.response,e.band,t]);let r=micFilters.get(n);return r||(r=minimumPhase(u=>fromDb(curveDb(e.response,u))*bandGain(e.band,u,t),t,2048),micFilters.set(n,r)),r}function pickupImpulses(e,t,n,r){const u=JSON.stringify([e.pattern,e.distance,e.angle,e.below,e.response,e.band,e.stereo,e.room,t,n,r]),i=impulses.get(u);if(i!==void 0)return i;const o=(h,p)=>proximity(e.pattern,p,h)/proximity(t.pattern,t.distance,h),a=Math.cos(e.angle*Math.PI/180)*Math.cos(e.below*Math.PI/180);if(e.room===!1&&e.response.every(([,h])=>Math.abs(h)<.01)&&e.band[0]<=20&&e.band[1]>=2e4&&Math.abs(o(100,e.distance)-1)<.001&&Math.abs(talkerDb(8e3,a))<.01)return impulses.set(u,null),null;const c=micFilter(e,n),l=[];let d=0;(e.stereo===!1?[0]:[-e.stereo/2,e.stereo/2]).forEach((h,p)=>{let g;if(e.room===!1)g=minimumPhase(E=>o(E,e.distance)*fromDb(talkerDb(E,a)),n,2048);else{const v=e.room,E=placement(e,v.talker,v.size,h);let y={size:v.size,surfaces:[v.walls,v.walls,v.floor,v.ceiling,v.walls,v.walls],...v.open?{open:[!0,!0,!1,!0,!0,!0]}:{},talker:v.talker,facing:[0,0,1],mic:E.mic,axis:E.axis,pattern:e.pattern,source:t,order:v.order};v.open||(y=withReverberation(y,v.rt60,n));const b=roomResponse(y,n,r+p*7919),A=b.direct.distance,B=minimumPhase($=>o($,A)*fromDb(talkerDb($,b.direct.cos)),n,2048);g=Float64Array.from(b.reflections);for(let $=0;$<B.length&&b.lead+$<g.length;$++)g[b.lead+$]=(g[b.lead+$]??0)+b.direct.gain*(B[$]??0);d=b.lead}const D=convolve(Float32Array.from(g),c);l.push(Float64Array.from(D))});const m={channels:l,lead:d};return impulses.set(u,m),m}function distanceDrop(e,t,n,r){if(Math.abs(e.distance-e.toneAt)<1e-6)return 0;const u=a=>{const s=pickupImpulses(a,t,n,r)?.channels[0];if(!s)return;let c=0;for(const l of s)c+=l*l;return c},i=u(e),o=u({...e,distance:e.toneAt});return e.room===!1||i===void 0||o===void 0?20*Math.log10(e.distance/e.toneAt):10*Math.log10(o/i)}function recordVoice(e,t,n,r,u){const[i,o]=e,a=i.length,s=integratedLoudness([i,o],n);if(s===void 0)return;const c=new Float32Array(a);for(let p=0;p<a;p++)c[p]=((i[p]??0)+(o[p]??0))/2;const l=new Float32Array(a),d=new Float32Array(a);t.pickups.forEach((p,g)=>{const D=pickupImpulses(p,t.source,n,r+g*104729);let v,E;if(!D)v=Float32Array.from(i),E=Float32Array.from(o);else{const B=$=>{const x=convolve(c,$);return Float32Array.from({length:a},(_,F)=>x[F+D.lead]??0)};v=B(D.channels[0]??new Float64Array(1)),E=D.channels[1]?B(D.channels[1]):Float32Array.from(v)}const y=integratedLoudness([v,E],n);if(y===void 0)return;const b=fromDb(s-y);for(let B=0;B<a;B++)v[B]=(v[B]??0)*b,E[B]=(E[B]??0)*b;if(p.noise){const B=micFilter(p,n),$=I=>convolve(I,B).subarray(0,a),x=$(roomTone2(a,n,p.noise,r+g*31+1)),_=p.stereo===!1?x:$(roomTone2(a,n,p.noise,r+g*31+2)),F=Math.round(.05*n),S=new Float32Array(a);for(const I of u){const M=Math.max(0,Math.round(I.start*n)),P=Math.min(a,Math.round(I.end*n));for(let j=M;j<P;j++){const R=Math.min(j-M,P-1-j);S[j]=Math.max(S[j]??0,R<F?R/F:1)}}const k=integratedLoudness([x,_],n)??-3,w=fromDb(s-p.noise.below+distanceDrop(p,t.source,n,r+g*104729)-k);for(let I=0;I<a;I++){const M=(S[I]??0)*w;v[I]=(v[I]??0)+(x[I]??0)*M,E[I]=(E[I]??0)+(_[I]??0)*M}}p.agc&&agc([v,E],{...p.agc,target:s+p.agc.target,...p.agc.gate===void 0?{}:{gate:s+p.agc.gate}},n);const A=fromDb(p.gain);for(let B=0;B<a;B++)l[B]=(l[B]??0)+(v[B]??0)*A,d[B]=(d[B]??0)+(E[B]??0)*A});const f=t.post;if(f){const p=[...f.highpass===!1?[]:[biquad({type:"highpass",hz:f.highpass},n)],...f.eq.map(g=>biquad(g,n))];runBiquads(l,p),runBiquads(d,p),f.deess&&deess([l,d],{...f.deess,threshold:s+f.deess.threshold},n),f.compress&&compress([l,d],{...f.compress,threshold:s+f.compress.threshold},n)}const m=integratedLoudness([l,d],n),h=m===void 0?1:fromDb(s-m);for(let p=0;p<a;p++)i[p]=(l[p]??0)*h,o[p]=(d[p]??0)*h}function voiceGroups(e){const t=e.voice;if(!t)return{groups:[],dry:[...e.speech]};const n=o=>(o===void 0?void 0:t.parts?.[o])??t.video,r=new Map,u=[],i=o=>{const a=JSON.stringify(o);let s=r.get(a);return s||(s={voice:o,clips:[],spans:[],parts:[],seed:hashSeed(`${t.seed}:voice:${a}`)},r.set(a,s)),s};for(const o of e.speech){const a=n(o.part);a===!1?u.push(o):i(a).clips.push(o)}for(const o of t.spans){const a=n(o.part);if(a===!1)continue;const s=i(a);s.spans.push({start:o.start,end:o.end}),s.parts.push(o.part)}return{groups:[...r.values()],dry:u}}function addSpeech(e,t,n,r,u){const i=Math.round(n.dur*r),o=Math.round(n.at*r),a=10**(n.gainDb/20),s=Math.min(Math.round(.01*r),Math.floor(i/4)),c=D=>D===void 0||D<=0?0:Math.min(Math.round(D*r),Math.floor(i/2)),l=c(n.fadeIn),d=c(n.fadeOut),f=(D,v)=>v>0?equalPower(D/v):s>0&&D<s?D/s:1,m=e[0].length,h=t[0].length,p=u===void 0?n.speed??1:1,g=u===void 0?n.from*r:n.from/u*r;for(let D=0;D<i;D++){const v=o+D;if(v<0||v>=m)continue;const E=p===1?Math.round(g)+D:g+D*p,y=Math.floor(E);if(y<0||y>=h)continue;const b=E-y,A=Math.min(y+1,h-1),B=a*f(D,l)*f(i-1-D,d);for(let $=0;$<2;$++){const x=t[$]??t[0],_=x[y]??0,F=x[A]??0,S=e[$]??e[0];S[v]=(S[v]??0)+(_+(F-_)*b)*B}}}function sumSpeech(e,t,n,r){const u=Math.round(t*n),i=[new Float32Array(u),new Float32Array(u)];for(const o of e){const a=r(o);a&&addSpeech(i,a.src,o,n,a.stretched)}return i}function playVoice(e,t,n,r){const u=sumSpeech(e.clips,t,n,r);return recordVoice(u,e.voice,n,e.seed,e.spans),u}function applyEnvelope(e,t,n){if(t.length===0)return;const r=e[0].length;for(let u=0;u<r;u++){const i=10**(gainAt(t,u/n)/20);i!==1&&(e[0][u]=(e[0][u]??0)*i,e[1][u]=(e[1][u]??0)*i)}}function addPlayed(e,t,n,r,u,i){const o=Math.round(n.dur*r),a=Math.round(n.at*r),s=10**(n.gainDb/20),c=Math.min(Math.round(.01*r),Math.floor(o/4)),l=E=>E===void 0||E<=0?0:Math.min(Math.round(E*r),Math.floor(o/2)),d=l(n.fadeIn),f=l(n.fadeOut),m=(E,y)=>y>0?equalPower(E/y):c>0&&E<c?E/c:1,h=[...n.envelope??[]],p=e[0].length,g=t[0].length,D=u===void 0?n.speed??1:1,v=u===void 0?n.from*r:n.from/u*r;for(let E=0;E<o;E++){const y=a+E;if(y<0||y>=p)continue;const b=D===1?Math.round(v)+E:v+E*D,A=Math.floor(b);if(A<0||A>=g)continue;const B=b-A,$=Math.min(A+1,g-1),x=y/r,_=h.length>0||i.length>0?10**((gainAt(h,x)+gainAt(i,x))/20):1,F=s*_*m(E,d)*m(o-1-E,f);for(let S=0;S<2;S++){const k=t[S]??t[0],w=k[A]??0,I=k[$]??0,M=e[S]??e[0];M[y]=(M[y]??0)+(w+(I-w)*B)*F}}}function playSfx(e,t,n){if(!e.shape||!(shapes(e.shape)||e.shape.filter!==void 0))return{src:t,gainDb:e.gainDb};const r=soundLevel(t,n)?.lufs,u=[Float32Array.from(t[0]),Float32Array.from(t[1])];shapeSound(u,e.shape,n,0);const i=soundLevel(u,n)?.lufs;return i===void 0?{src:u,gainDb:e.gainDb}:e.level?{src:u,gainDb:e.level.target-i+e.level.gainDb}:{src:u,gainDb:e.gainDb+(r===void 0?0:r-i)}}function synthStereo(e,t,n){const r=synthSfx(e,t,n);return[r,r]}function renderMix(e,t,n,r={}){const u=Math.round(e.duration*n),i=[new Float32Array(u),new Float32Array(u)],o=e.speechGain??[],a=clipSource(t),{groups:s,dry:c}=voiceGroups(e);for(const l of s){const[d,f]=playVoice(l,e.duration,n,a);applyEnvelope([d,f],o,n);for(let m=0;m<u;m++)i[0][m]=(i[0][m]??0)+(d[m]??0),i[1][m]=(i[1][m]??0)+(f[m]??0)}for(const l of c){const d=a(l);d&&addPlayed(i,d.src,l,n,d.stretched,o)}if(r.only==="voice")return i;for(const l of e.footage){const d=t(l.file,{});d&&addPlayed(i,d.src,l,n,void 0,[])}if(e.music){const l=e.music,d=t(l.file,l.shape?.filter?{filter:l.shape.filter}:{});if(d){const[f,m]=playMusic(l,d.src,e.duration,n);for(let h=0;h<u;h++)i[0][h]=(i[0][h]??0)+(f[h]??0),i[1][h]=(i[1][h]??0)+(m[h]??0)}}for(const l of e.sfx){let d;if(l.file!==void 0?d=t(l.file,l.shape?.filter?{filter:l.shape.filter}:{})?.src:d=synthStereo(l.sound,n,l.seed),!d)continue;const f=playSfx(l,d,n),m=10**(f.gainDb/20),h=Math.round(l.at*n),p=f.src[0].length;for(let g=0;g<p;g++){const D=h+g;D<0||D>=u||(i[0][D]=(i[0][D]??0)+(f.src[0][g]??0)*m,i[1][D]=(i[1][D]??0)+(f.src[1][g]??0)*m)}}return i}function limitPeaks(e,t,n,r=MASTER_MECHANICS.attack,u=MASTER_MECHANICS.release){const i=e[0].length,o=Math.max(1,Math.round(r*n)),a=new Float32Array(i);for(let p=0;p<i;p++){const g=Math.max(Math.abs(e[0][p]??0),Math.abs(e[1][p]??0));a[p]=g>t?t/g:1}const s=new Float32Array(i),c=[];let l=0;for(let p=i-1;p>=0;p--){const g=a[p]??1;for(;c.length>l&&(a[c[c.length-1]??0]??1)>=g;)c.pop();for(c.push(p);(c[l]??0)>p+o;)l++;s[p]=a[c[l]??p]??1}const d=Math.exp(-1/(Math.max(u,1e-4)*n));let f=1;for(let p=0;p<i;p++)f=Math.min(s[p]??1,1-(1-f)*d),s[p]=f;let m=0;const h=new Float32Array(i);for(let p=0;p<i;p++)m+=s[p]??1,p>=o&&(m-=s[p-o]??1),h[p]=m/Math.min(o,p+1);for(let p=0;p<i;p++){const g=Math.min(h[p]??1,a[p]??1);e[0][p]=(e[0][p]??0)*g,e[1][p]=(e[1][p]??0)*g}}function masterMix(e,t,n){const r=10**(n.truePeak/20),u=integratedLoudness(e,t),i=c=>{const l=10**(c/20),d=[Float32Array.from(e[0],f=>f*l),Float32Array.from(e[1],f=>f*l)];return limitPeaks(d,r,t),d};let o=n.lufs===!1||u===void 0?0:n.lufs-u,a=i(o),s=integratedLoudness(a,t);if(n.lufs!==!1&&u!==void 0)for(let c=1;c<MASTER_MECHANICS.rounds&&s!==void 0;c++){const l=n.lufs-s;if(Math.abs(l)<=MASTER_MECHANICS.tolerance)break;o+=l,a=i(o),s=integratedLoudness(a,t)}return e[0].set(a[0]),e[1].set(a[1]),{gainDb:o,...s===void 0?{}:{integrated:s}}}function previewMaster(e,t,n){const[r,u]=e;let i=!1;for(let o=0;o<r.length&&!i;o++)i=r[o]!==0||u[o]!==0;if(i)return masterMix(e,t,n),e}var BANDWIDTH_DEFAULTS={ref:1e3,drops:[30,50,70],smooth:1/12,stepsFrom:3e3,stepSpan:1/6,stepMin:3,steps:4,floor:-60};function voicePlan(e,t){const n=u=>resolveVoice(u),r=t.filter(u=>u.mic!==void 0);return{mic:{video:n(e),...r.length>0?{parts:Object.fromEntries(r.map(u=>[u.key,n(u.mic)]))}:{}}}}function wordsOnFilm(e,t){return e.flatMap(n=>wordsIn(t(n.file)??[],n.from,n.dur,n.at,n.speed??1)).map(n=>({start:n.start,end:n.end})).sort((n,r)=>n.start-r.start)}var level=(e,t)=>t===void 0||!Number.isFinite(t)?0:e-t,held=e=>[...e].sort((t,n)=>t.t-n.t);function musicPlayed(e,t,n){return e.play?musicSegments(e.play,e.seam??MUSIC_DEFAULTS.seam,t,"before",!e.loop):e.loop?musicSegments(wholeLoop(e.from,t,n,e.seam),t>1?e.seam??MUSIC_DEFAULTS.loopSeam:0,t,"after",!1):musicSegments(placeStretches([{from:e.from,to:t}],void 0,t,n),0,t)}function mixPlan(e,t,n){const r=e.duration,u=e.audio.mix??MIX_DEFAULTS,i={duration:r,speech:[],footage:[],sfx:[]};for(const f of[...e.audio.speech??[],...e.audio.room??[]]){const m=t[f.file];!m||f.dur<=0||i.speech.push({file:f.file,...f.part===void 0?{}:{part:f.part},at:f.at,from:f.from,dur:f.dur,gainDb:level(u.speech,m.loudness)+(f.gainDb??0),...f.speed!==void 0&&f.speed!==1?{speed:f.speed}:{},...f.denoise?{denoise:f.denoise}:{},...f.fadeIn?{fadeIn:f.fadeIn}:{},...f.fadeOut?{fadeOut:f.fadeOut}:{}})}const o=speechSpans(i.speech,u.duck),a=speechEnvelope(o,u.footageUnderSpeech-u.footage,u.duck);for(const f of e.footage??[]){const m=t[f.file];if(!f.audio||f.take===!0||!m)continue;const h=f.speed>0?f.speed:1,p=Math.max(0,f.from),g=f.start+(p-f.from)/h,D=m.duration===void 0?1/0:m.duration-p,v=Math.min(f.end-g,D/h);v<=0||i.footage.push({file:f.file,at:g,from:p,dur:v,...h===1?{}:{speed:h},gainDb:level(u.footage,m.loudness)+f.gainDb,...a.length>0?{envelope:a}:{}})}const s=e.audio.music,c=s?.file===void 0?void 0:t[s.file];if(s?.file!==void 0&&c){const f=(s.gain??[]).map(p=>({t:p.t,db:p.db})),m=c.duration??s.from+r,h={file:s.file,segments:musicPlayed(s,m,r),gainDb:level(u.musicAlone,c.loudness),alone:u.musicAlone,fadeIn:u.musicFade.in,fadeOut:Math.min(u.musicFade.out,r/4),...s.until===void 0?{}:{until:s.until},duck:addEnvelopes(addEnvelopes(speechEnvelope(o,u.music-u.musicAlone,u.duck),duckEnvelope(wordsOnFilm(i.speech,p=>t[p]?.words),u.duck)),held(f)),...s.shape?{shape:s.shape}:{}};i.music=h}const l=speechGains(e);l.length>0&&(i.speechGain=l);const d=e.audio.mic;return d&&(i.voice={video:d.video,...d.parts?{parts:d.parts}:{},spans:e.parts.map(f=>({part:f.key,start:f.start,end:f.end})),seed:n.seed}),e.cues.forEach((f,m)=>{const h=f.gainDb??0;if(f.file!==void 0){const g=t[f.file];if(!g)return;i.sfx.push({sound:f.sound,file:f.file,at:f.t,gainDb:level(u.sfx,g.loudness)+h,seed:0,...f.shape?{shape:f.shape,level:{target:u.sfx,gainDb:h}}:{}});return}const p=SFX_HIT[f.sound];p!==void 0&&i.sfx.push({sound:f.sound,at:Math.max(0,f.t-p),gainDb:u.sfx-MIX_DEFAULTS.sfx+h,seed:hashSeed(`${n.seed}:${f.sound}:${String(m)}`),...f.shape?{shape:f.shape}:{}})}),i}function speechGains(e){const t=new Map;for(const s of e.parts)s.speechGainDb!==void 0&&s.speechGainDb!==0&&t.set(s.key,s.speechGainDb);if(t.size===0)return[];const n=[];for(const s of e.parts)n.push({start:s.start,end:s.end,db:t.get(s.key)??0,rank:0});const r=[...(e.audio.speech??[]).map(s=>({c:s,rank:2})),...(e.audio.room??[]).map(s=>({c:s,rank:1}))];for(const{c:s,rank:c}of r)s.part===void 0||s.dur<=0||n.push({start:s.at,end:s.at+s.dur,db:t.get(s.part)??0,rank:c});const u=[...new Set(n.flatMap(s=>[s.start,s.end]))].sort((s,c)=>s-c),i=[];for(let s=0;s+1<u.length;s++){const c=u[s]??0,l=u[s+1]??c,d=(c+l)/2;let f;for(const h of n)d<h.start||d>=h.end||(!f||h.rank>f.rank||h.rank===f.rank&&h.start>=f.start)&&(f=h);const m=f?.db??0;i.at(-1)?.db!==m&&i.push({t:c,db:m})}if(i.every(s=>s.db===0))return[];const o=.005,a=[];for(const[s,c]of i.entries()){if(s===0){a.push({t:c.t,db:c.db});continue}const l=i[s-1]?.db??0;a.push({t:Math.max(0,c.t-o),db:l},{t:c.t+o,db:c.db})}return a}function canonical(e){return JSON.stringify(e,(t,n)=>{if(typeof n=="function")return`fn:${String(n)}`;if(typeof n=="object"&&n!==null&&"sha256"in n&&"path"in n&&"url"in n){const r={...n};return delete r.url,delete r.matteUrl,delete r.denoisedUrl,r}return n})}function facade(e){const{env:t,piece:n,stage:r,mounted:u,takes:i,captions:o,footage:a}=e,{drawer:s,measurer:c,embedder:l}=e,{source:d,combo:f,log:m,ledger:h}=t,{fps:p,dims:g,format:D,look:v,isPaged:E,prefix:y}=n;let b=!1,A;const B=()=>{if(A)return A;const x={fps:p,width:g.width,height:g.height,...E||!g.profile?{}:{profile:g.profile},duration:e.duration,background:e.background,parts:u.map(_=>_.part.title===void 0&&_.record.title!==void 0?{..._.part,title:_.record.title}:_.part),cues:[...e.cues],...a.placed.length>0?{footage:a.placed.map(timelineFootage)}:{},...e.transitions.length>0?{transitions:[...e.transitions]}:{},...a.needs().length>0?{index:a.needs()}:{},audio:e.audio};return b&&(A=x),x};return{kind:E?"paged":"video",get timeline(){return B()},async ready(){await s.ready(),b=!0,A=void 0},seek:(x,_)=>s.draw(x,_),words:()=>o.lines.flatMap(x=>[...x.words]),lines:()=>[...o.lines],captionOptions:()=>o.asked??null,measure:x=>c.measure(x),tracks:(x,_)=>c.tracks(x,_),inks:x=>c.inks(x),stuck:()=>s.stuck(),seekLimit:n.seekLimitMs/1e3,setPlaying(x){s.setPlaying(x)},text(){return u.map(x=>{const _=i.results[x.n]??{},F=_.speech,S=_.shown??(F?joinWords(F.words):void 0),k=F?.script??_.say?.text,w=e.notes.get(x.part.key);return{key:x.part.key,onScreen:[...new Set(x.record.onScreen??[])],...w===void 0?{}:{notes:w},...S===void 0?{}:{spoken:S},...k!==void 0&&S!==void 0&&k!==S?{speak:k}:{},..._.speechKey===void 0?{}:{speechKey:_.speechKey}}})},signature:()=>c.signature(),signatureAt:x=>c.signatureAt(x),partSignature:(x,_)=>c.partSignature(x,_),reads(){const x=m.reads(y,u.map(k=>k.part.key)),_=l.loaded.reduce((k,w)=>{const I=w.inner.reads(),M=(P,j)=>[...new Map(P.map(R=>[j(R),R])).values()];return{messages:M([...k.messages,...I.messages],P=>P.key),media:M([...k.media,...I.media],P=>P.path),data:M([...k.data,...I.data],P=>P.path)}},x),F=new Map,S=(k,w)=>{const I=F.get(k)??new Set;I.add(w),F.set(k,I)};for(const k of u)for(const w of k.record.reads.keys())w.startsWith("f:")&&S(w.slice(2),k.part.key);for(const k of u)k.part.speech&&S(k.part.speech.file,k.part.key);for(const k of a.placed)S(k.file,k.part);return{..._,media:_.media.flatMap(k=>{const w=F.get(k.path);return w?.size?[...w].sort().map(I=>({...k,part:I})):[k]})}},says:()=>i.says.map(x=>({...x})),signs(){const x={},_=dimsCombo(d.dims,f),F=e.background;for(const S of u)x[S.part.key]=JSON.stringify({v:1,piece:d.piece,output:t.output,kind:E?"paged":"video",key:S.part.key,slot:S.part.slot??null,pick:S.part.slot===void 0?null:f[S.part.slot]??null,dims:_,format:D,fps:p,size:[g.width,g.height],frames:Math.round((S.part.end-S.part.start)*p),background:F,look:v,layers:S.layers.map(k=>[k.spec.component,k.spec.z??"front",Math.round(k.start*1e6)/1e6,Math.round(k.end*1e6)/1e6,canonical(k.props)]),custom:S.layers.some(k=>k.spec.component==="custom"||k.spec.component==="scenery"),words:e.words(S.n),heard:cuesIn(o.cues(),S.part.start,S.part.end),planes:S.part.planes.map(k=>k.overlay===!0?"overlay":k.behindPerson===!0),stack:S.layers.map(k=>[k.index,k.plane]),reads:[...S.record.reads.entries()].sort((k,w)=>k[0]<w[0]?-1:k[0]>w[0]?1:0)});return x},mixPlan:()=>mixPlan(B(),d.media,{seed:t.seedBase}),problems(){const x=[...h.problems,...l.loaded.flatMap(F=>F.inner.problems().map(S=>({...S,message:`In the video ${F.id}: ${S.message}`}))),...m.problems,...e.timingProblems,...h.run,...r.problems(u),...m.translationProblems()],_=new Set;return x.map(F=>({...F,piece:d.piece,output:t.output,combo:f,format:D})).filter(F=>{const S=`${F.code}|${F.message}|${F.part??""}`;return _.has(S)?!1:(_.add(S),!0)})},facts:()=>h.facts.map(x=>({...x,output:t.output,combo:f,format:D})),covers:()=>s.covers(),drawCover:x=>s.drawCover(x),async ask(x,_){const F=[];for(const S of u)for(const k of S.layers){const w=k.answers.get(x);if(w)try{F.push({part:S.part.key,layer:k.spec.component,index:k.index,answer:await w(_)})}catch(I){h.ran(problem(codeOf(I),`${k.spec.component} (layer ${String(k.index+1)}) in part ${S.part.key} failed to answer ${x}: ${messageOf(I)}`,{part:S.part.key}))}}return F},dispose(){s.dispose(),r.dispose()}}}var GENERIC=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","math","emoji","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","-apple-system","blinkmacsystemfont","inherit","initial"]),isGeneric=e=>GENERIC.has(e.toLowerCase());function families(e){const t=[];let n="",r="";for(const u of e)r?u===r?r="":n+=u:u==='"'||u==="'"?r=u:u===","?(t.push(n.trim()),n=""):n+=u;return t.push(n.trim()),t.filter(Boolean)}function unicodeRanges(e){const t=[];for(const n of e.split(",")){const r=/^\s*u\+([0-9a-f?]+)(?:-([0-9a-f]+))?\s*$/i.exec(n),u=r?.[1];if(u)if(u.includes("?"))t.push([parseInt(u.replace(/\?/g,"0"),16),parseInt(u.replace(/\?/g,"f"),16)]);else{const i=parseInt(u,16);t.push([i,r[2]?parseInt(r[2],16):i])}}return t}function weightRange(e){const t=o=>o==="bold"?700:o==="normal"?400:Number(o),[n="400",r]=e.trim().split(/\s+/),u=t(n),i=r===void 0?u:t(r);return Number.isFinite(u)&&Number.isFinite(i)?[u,i]:[400,400]}function matchWeight(e,t){if(t.length===0)return;if(t.some(([o,a])=>e>=o&&e<=a))return e;const n=t.filter(([o])=>o>e).map(([o])=>o),r=t.filter(([,o])=>o<e).map(([,o])=>o),u=n.length?Math.min(...n):void 0,i=r.length?Math.max(...r):void 0;return e>500?u??i:e<400?i??u:u!==void 0&&u<=500?u:i??u}var BOLD=600,covers=(e,t)=>e.ranges.length===0||t.some(n=>e.ranges.some(([r,u])=>n>=r&&n<=u));function fontIssue(e,t,n,r){const u=e.families[0];if(u===void 0||isGeneric(u))return;let i;for(const o of e.families){if(isGeneric(o))return i&&{kind:"fallback",...i,usedFamily:o};const a=n.filter(f=>f.family.toLowerCase()===o.toLowerCase());if(a.length===0){if(r(o))return i&&{kind:"fallback",...i,usedFamily:o};i??={family:o,failed:!1};continue}const s=a.filter(f=>covers(f,t));if(s.length===0)continue;const c=s.filter(f=>f.status==="loaded");if(c.length===0){if(s.every(f=>f.status==="error")){i??={family:o,failed:!0};continue}return}if(i)return{kind:"fallback",...i,usedFamily:o};const l=matchWeight(e.weight,c.map(f=>f.weight)),d=Math.max(...c.map(f=>f.weight[1]));return e.weight>=BOLD&&d<BOLD?{kind:"bold",family:o,weight:e.weight,drawn:l??d,faked:e.synthBold}:e.italic&&!c.some(f=>f.slanted)?{kind:"italic",family:o,faked:e.synthItalic}:void 0}return i&&{kind:"fallback",...i,usedFamily:"the browser's default font"}}function drawnFamilies(e,t,n,r){const u=[];for(const i of new Set(t)){let o="the browser's default font";for(const a of e.families){if(isGeneric(a)){o=a;break}const s=n.filter(c=>c.family.toLowerCase()===a.toLowerCase());if(s.length===0?r(a):s.some(c=>c.status==="loaded"&&covers(c,[i]))){o=a;break}}u.includes(o)||u.push(o)}return u}function fontIssueText(e){switch(e.kind){case"fallback":return e.failed?`the font "${e.family}" failed to load, so it is drawn in ${quoteFamily(e.usedFamily)}. Check the @font-face url and that the file is in the workspace.`:`the font "${e.family}" is not loaded, so it is drawn in ${quoteFamily(e.usedFamily)}. Import its stylesheet in the piece (import "@fontsource/<id>/400.css" after npm install @fontsource/<id>, or a .css of @font-face rules), or list it in allyhub.config.ts's fonts for every stage, or use a font the look has (var(--ak-font-display), var(--ak-font-body)).`;case"bold":return e.faked?`"${e.family}" has no face for weight ${String(e.weight)} (the loaded faces stop below ${String(BOLD)}), so Chrome fakes the bold by thickening weight ${String(e.drawn)}. Load a bold face of the font, or use a weight it has.`:`"${e.family}" has no face for weight ${String(e.weight)}, so it is drawn at weight ${String(e.drawn)}. Load a bold face of the font, or use a weight it has.`;case"italic":return e.faked?`"${e.family}" has no italic face, so Chrome fakes the italic by slanting the upright letters. Load an italic face of the font, or drop font-style: italic.`:`"${e.family}" has no italic face, so it is drawn upright. Load an italic face of the font, or drop font-style: italic.`}}var quoteFamily=e=>isGeneric(e)?`the browser's ${e} font`:e.startsWith("the ")?e:`"${e}"`;function stringsOf(e,t=2e3){const n=[],r=new Set,u=i=>{if(!(n.length>=t)){if(typeof i=="string")n.push(i);else if(typeof i=="object"&&i!==null&&!r.has(i)){r.add(i);for(const o of Array.isArray(i)?i:Object.values(i))u(o)}}};return u(e),n}function emojiOf(e){const t=/\p{Extended_Pictographic}|\p{Regional_Indicator}|[\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]|\u200d|\ufe0f|\u20e3/gu,n=new Set;for(const r of e)for(const u of r.matchAll(t))n.add(u[0]);return[...n].join("")}var localCache=new Map,measure;function pageFaces(){const e=[];return document.fonts.forEach(t=>{e.push({family:families(t.family)[0]??t.family,weight:weightRange(t.weight),slanted:t.style!=="normal",status:t.status,ranges:unicodeRanges(t.unicodeRange)})}),e}function localFamily(e){const t=localCache.get(e);if(t!==void 0)return t;measure??=document.createElement("canvas").getContext("2d");const n=measure;if(!n)return!0;const r="mmmmmmmmmmlli10WQ@#ÆŒ",u=a=>(n.font=a,n.measureText(r).width),i=JSON.stringify(e),o=["monospace","serif","sans-serif"].some(a=>u(`40px ${i}, ${a}`)!==u(`40px ${a}`));return localCache.set(e,o),o}function fontWant(e){const t=Number(e.fontWeight);return{families:families(e.fontFamily),weight:Number.isFinite(t)?t:400,italic:e.fontStyle!=="normal",synthBold:e.getPropertyValue("font-synthesis-weight")!=="none",synthItalic:e.getPropertyValue("font-synthesis-style")!=="none"}}function codePoints(e){const t=new Set;for(const n of e)for(const r of n)t.add(r.codePointAt(0)??0);return t}function coversAny(e,t){if(e.length===0)return!0;for(const n of t)if(e.some(([r,u])=>n>=r&&n<=u))return!0;return!1}function namedFamilies(e){return families(e).filter(t=>!isGeneric(t)&&!t.startsWith("var(")).map(t=>t.toLowerCase())}function styleSheetFamilies(){const e=new Set,t=n=>{for(const r of Array.from(n))if(r instanceof CSSStyleRule){const u=r.style.getPropertyValue("font-family");if(u)for(const i of namedFamilies(u))e.add(i)}else r instanceof CSSGroupingRule&&t(r.cssRules)};for(const n of Array.from(document.styleSheets))try{t(n.cssRules)}catch{}return e}function propFamilies(e){const t=new Set;document.fonts.forEach(u=>{t.add((families(u.family)[0]??u.family).toLowerCase())});const n=e.map(u=>u.toLowerCase()),r=new Set;for(const u of t)u&&n.some(i=>i.includes(u))&&r.add(u);return r}async function loadFaces(e,t){const n=[];document.fonts.forEach(r=>{if(r.status!=="unloaded")return;const u=(families(r.family)[0]??r.family).toLowerCase();e.has(u)&&coversAny(unicodeRanges(r.unicodeRange),t)&&n.push(r.load().catch(()=>{}))}),await Promise.all(n)}async function loadTextFonts(e){const t=new Map,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let u=r.nextNode();u;u=r.nextNode()){const i=u.nodeValue??"",o=u.parentElement;if(!o||!i.trim())continue;let a=n.get(o);if(a===void 0){const c=getComputedStyle(o);a=`${c.fontStyle==="normal"?"":"italic "}${c.fontWeight} 40px ${c.fontFamily}`,n.set(o,a)}let s=t.get(a);s||(s=new Set,t.set(a,s));for(const c of i)c.trim()&&s.add(c)}await Promise.all([...t].map(([u,i])=>document.fonts.load(u,[...i].join("")).catch(()=>[])))}var fontRows=new Map,measurer;function rowsOf(e,t){const n=`${e}