faustwave 0.0.1 → 0.94.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 (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -5
  3. package/dist/npm/faustwave.mjs +31372 -0
  4. package/dist/npm/page/assets/index-BPO9trAg.css +1 -0
  5. package/dist/npm/page/assets/index-DyOBLoeh.js +2 -0
  6. package/dist/npm/page/files.json +1 -0
  7. package/dist/npm/page/index.html +17 -0
  8. package/dist/npm/pagekit/pagekit.js +2347 -0
  9. package/dist/npm/pagekit/parts/device-button.glb +0 -0
  10. package/dist/npm/pagekit/parts/device-fader.glb +0 -0
  11. package/dist/npm/pagekit/parts/device-knob.glb +0 -0
  12. package/dist/npm/pagekit/parts/device-meter.glb +0 -0
  13. package/dist/npm/pagekit/parts/device-panel.glb +0 -0
  14. package/dist/npm/pagekit/parts/models-provenance.json +46 -0
  15. package/dist/npm/pagekit/player/THIRD-PARTY-NOTICES.md +12358 -0
  16. package/dist/npm/pagekit/player/assets/AppView-BV9Obknn.js +1 -0
  17. package/dist/npm/pagekit/player/assets/AppView-CdET0bgZ.css +1 -0
  18. package/dist/npm/pagekit/player/assets/FontLoader-C8xh6Irz.js +64 -0
  19. package/dist/npm/pagekit/player/assets/StageView-CSu--ASd.css +1 -0
  20. package/dist/npm/pagekit/player/assets/StageView-_SwGWnwx.js +1 -0
  21. package/dist/npm/pagekit/player/assets/actionRegistry-DrQhww6a.js +1 -0
  22. package/dist/npm/pagekit/player/assets/actionRegistry-hOkUYNvI.js +1 -0
  23. package/dist/npm/pagekit/player/assets/ahead-BNQHG1e8.js +1 -0
  24. package/dist/npm/pagekit/player/assets/api-BrGhAVvb.js +1 -0
  25. package/dist/npm/pagekit/player/assets/autoLayout-C5ue2K3x.js +1 -0
  26. package/dist/npm/pagekit/player/assets/bundledSources-2GoXdU5z.js +1 -0
  27. package/dist/npm/pagekit/player/assets/clapModule-CB6_36hc.js +1 -0
  28. package/dist/npm/pagekit/player/assets/client-DksDHYQL.js +1 -0
  29. package/dist/npm/pagekit/player/assets/codeEditorBridge-Bl202hrO.js +1 -0
  30. package/dist/npm/pagekit/player/assets/disclose-version-BvIhFN19.js +1 -0
  31. package/dist/npm/pagekit/player/assets/dist-BvRk9kiK.js +0 -0
  32. package/dist/npm/pagekit/player/assets/dist-DfaMbR-1.js +1 -0
  33. package/dist/npm/pagekit/player/assets/engine.worklet-BTB8yjdk.js +1865 -0
  34. package/dist/npm/pagekit/player/assets/engineCost.worker-Cv0PY3S-.js +2167 -0
  35. package/dist/npm/pagekit/player/assets/errors-BdUU2zPt.js +1 -0
  36. package/dist/npm/pagekit/player/assets/faust-analysis.nodepack-Bg1ixSAB.js +1 -0
  37. package/dist/npm/pagekit/player/assets/faust-physical-models.nodepack-DxbqTZII.js +1 -0
  38. package/dist/npm/pagekit/player/assets/faust-reverbs.nodepack-c-ZIKLrJ.js +1 -0
  39. package/dist/npm/pagekit/player/assets/faust-spatial.nodepack-C6GwVzOM.js +1 -0
  40. package/dist/npm/pagekit/player/assets/faust-vintage.nodepack-D8g5LX-U.js +1 -0
  41. package/dist/npm/pagekit/player/assets/faust.nodepack-Do7P1z0H.js +1 -0
  42. package/dist/npm/pagekit/player/assets/faustSource-Blr9zzKL.js +1 -0
  43. package/dist/npm/pagekit/player/assets/faustwasm-webclap-double-BX3OrOpF.js +1 -0
  44. package/dist/npm/pagekit/player/assets/faustwasm-webclap-double-Drn3DiHA.wasm +0 -0
  45. package/dist/npm/pagekit/player/assets/faustwasm.js +1 -0
  46. package/dist/npm/pagekit/player/assets/faustwave-conventions.nodepack-D2jA38Q6.js +1 -0
  47. package/dist/npm/pagekit/player/assets/fileMirror-CkgB9zNS.js +1 -0
  48. package/dist/npm/pagekit/player/assets/fileRef-BmnWhXuY.js +1 -0
  49. package/dist/npm/pagekit/player/assets/host-DPIuYxlL.js +1 -0
  50. package/dist/npm/pagekit/player/assets/instantiate-Dh0T46aH.js +1 -0
  51. package/dist/npm/pagekit/player/assets/inter-500.typeface-B6jxeZL_.js +21 -0
  52. package/dist/npm/pagekit/player/assets/inter-700.typeface-COCE0d_R.js +21 -0
  53. package/dist/npm/pagekit/player/assets/kernel-BErAMnKr.js +1 -0
  54. package/dist/npm/pagekit/player/assets/kernel-D6spGIFh.js +1 -0
  55. package/dist/npm/pagekit/player/assets/kernel-DKiI3Wqx.js +2 -0
  56. package/dist/npm/pagekit/player/assets/kit--nsV_OZy.js +1 -0
  57. package/dist/npm/pagekit/player/assets/kit-vVQ5cDnW.css +1 -0
  58. package/dist/npm/pagekit/player/assets/lazy-BkjipY-3.css +1 -0
  59. package/dist/npm/pagekit/player/assets/lazy-ClEpU-Ev.js +1 -0
  60. package/dist/npm/pagekit/player/assets/libraryFacts-B_z-Kv6i.js +1 -0
  61. package/dist/npm/pagekit/player/assets/mono-500.typeface-CuX9Pbhu.js +21 -0
  62. package/dist/npm/pagekit/player/assets/mono-700.typeface-BpIQdJao.js +21 -0
  63. package/dist/npm/pagekit/player/assets/newId-DuoSrkVn.js +1 -0
  64. package/dist/npm/pagekit/player/assets/notes-D-zF5qJ1.js +1 -0
  65. package/dist/npm/pagekit/player/assets/opfsStore-CXd1Yz_2.js +1 -0
  66. package/dist/npm/pagekit/player/assets/panic-ckha9YOX.js +1 -0
  67. package/dist/npm/pagekit/player/assets/patchSnippets-Dsccmpj6.js +1 -0
  68. package/dist/npm/pagekit/player/assets/paths-DFjX1bFA.js +1 -0
  69. package/dist/npm/pagekit/player/assets/player-CgcvekqS.js +2 -0
  70. package/dist/npm/pagekit/player/assets/playerApp-BmyTSXxw.js +2 -0
  71. package/dist/npm/pagekit/player/assets/playerApp-DO80EIpx.css +1 -0
  72. package/dist/npm/pagekit/player/assets/preArm-ifXM2Buj.js +1 -0
  73. package/dist/npm/pagekit/player/assets/preload-helper-9MKZsTCd.js +1 -0
  74. package/dist/npm/pagekit/player/assets/projectFiles-BEdLy3nE.js +1 -0
  75. package/dist/npm/pagekit/player/assets/projectPicker-mteZ2tiI.js +1 -0
  76. package/dist/npm/pagekit/player/assets/rocket-CgRnlVoE.js +1 -0
  77. package/dist/npm/pagekit/player/assets/runtime-36oA_YiG.js +1 -0
  78. package/dist/npm/pagekit/player/assets/runtime-7lvdeERt.js +1 -0
  79. package/dist/npm/pagekit/player/assets/runtime-BNLxaYPi.js +2 -0
  80. package/dist/npm/pagekit/player/assets/runtime-CL1M0Epi.js +1 -0
  81. package/dist/npm/pagekit/player/assets/runtime-bQsuRbRM.js +2 -0
  82. package/dist/npm/pagekit/player/assets/runtime-vj8wKnnG.js +1 -0
  83. package/dist/npm/pagekit/player/assets/runtime-wuc1seO8.js +1 -0
  84. package/dist/npm/pagekit/player/assets/scale-D2nqiPek.js +1 -0
  85. package/dist/npm/pagekit/player/assets/sha256-B9lHpAF4.js +1 -0
  86. package/dist/npm/pagekit/player/assets/soundfiles-DMZ8HKDZ.js +1 -0
  87. package/dist/npm/pagekit/player/assets/src-BvHr5YSH.js +2 -0
  88. package/dist/npm/pagekit/player/assets/src-Co7ihhBK.js +1 -0
  89. package/dist/npm/pagekit/player/assets/src-DyDfRe65.js +1 -0
  90. package/dist/npm/pagekit/player/assets/src-LMfGAjlj.js +1 -0
  91. package/dist/npm/pagekit/player/assets/stageWorker-ggqqFf5m.js +20869 -0
  92. package/dist/npm/pagekit/player/assets/store-CJdayqZa.js +1 -0
  93. package/dist/npm/pagekit/player/assets/sun-Bi-OgPry.js +1 -0
  94. package/dist/npm/pagekit/player/assets/time-aboh42pX.js +1 -0
  95. package/dist/npm/pagekit/player/assets/toasts-BCcM1yGS.js +1 -0
  96. package/dist/npm/pagekit/player/assets/toasts-ChPacqdd.js +1 -0
  97. package/dist/npm/pagekit/player/assets/transportFollow-Ox91SKLF.js +1 -0
  98. package/dist/npm/pagekit/player/favicon.svg +77 -0
  99. package/dist/npm/pagekit/player/files.json +1 -0
  100. package/dist/npm/pagekit/player/player.html +35 -0
  101. package/package.json +58 -17
  102. package/faustwave.mjs +0 -2
@@ -0,0 +1 @@
1
+ import"./disclose-version-BvIhFN19.js";import{A as e,C as t,D as s,M as a,S as o,j as l,w as i,x as n,y as r}from"./client-DksDHYQL.js";import{t as d}from"./fileMirror-CkgB9zNS.js";import{a as c,i as p,n as u,r as m,s as v,t as g}from"./kit--nsV_OZy.js";import{n as b,t as h}from"./rocket-CgRnlVoE.js";import{$ as f,D as $,Ft as j,K as k,L as w,M as y,Pt as x,S as _,dt as z,lt as M,pt as C,rt as L,x as T,yt as E,z as W}from"./src-DyDfRe65.js";import{t as A}from"./codeEditorBridge-Bl202hrO.js";import{h as F,l as I,m as P,n as S,p as B,r as D}from"./runtime-vj8wKnnG.js";var K=a('<span class="fw-footer-spacer"></span> <!>',1),N=a("<li> </li>"),O=a('<section class="gv-problems svelte-ot5c55" aria-label="Not an app"><ul class="svelte-ot5c55"></ul></section>'),R=a('<p class="gv-error svelte-ot5c55">The code editor is not loaded — the editors extension provides it.</p>'),V=a('<!> <div class="gv-body svelte-ot5c55"><!></div>',1),q=a('<div class="gv-body gv-play svelte-ot5c55" data-testid="app.view"><!></div>');function G(a,G){j(G,!0);const H='{\n "format": "app",\n "title": "My App",\n "levels": [\n { "name": "first", "title": "The First Level", "stage": "asset:assets/<name>.stage" }\n ]\n}\n',J=F(),Q=y(()=>G.moduleId),U=A();let X=W(""),Y=W(""),Z=W(null);const ee=k(()=>!!$(Z)?.editing);let te=null,se=W(!1);_(()=>{$(Y),y(()=>{te?.changed(),w(se,!!te?.dirty())})});let ae=!1;_(()=>{const e=$(ee);y(()=>{ae&&!e&&te?.save().then(()=>D(Q,$(Y))).catch(e=>F().log.create("App").error(`the app could not be saved: ${e instanceof Error?e.message:String(e)}`)),ae=e})});const oe=[];i(()=>{te=d({api:J,moduleId:Q,ext:".faustwave",get:()=>$(Y),set:e=>w(Y,e,!0),onFile:e=>w(X,e.title,!0),scaffold:H,onText:(e,t)=>{w(se,!!te?.dirty()),"load"!==t||te?.ref()||e!==H?"reload"!==t&&"save"!==t||D(Q,e):I(Q,!0)}}),w(X,te.title(),!0),oe.push(S(Q)?.subscribe(e=>w(Z,e))??(()=>{})),te.load()}),t(()=>{te?.dispose();for(const e of oe)e()});const le=(e,t)=>F().actions.run(e,t);let ie=W(C(F().audio.getMasterVolumeL()));i(()=>F().audio.subscribeMaster(e=>w(ie,e.volumeL,!0)));const ne=k(()=>({level:$(ie),set:e=>{F().actions.run("master.volume.set",{volume:e})}})),re=k(()=>{const e=$(Z);if(!e?.doc)return[];const t=e.doc,s=e.last?t.levels.find(t=>t.name===e.last):void 0,a=s&&!B(t,s,e.won)?s:void 0;return[...a?[{label:"Continue",testid:"app.menu.continue",note:a.title,action:"app.level.load",input:{module_id:Q,level:a.name}}]:[],...t.levels.filter(e=>e.menu).map(s=>{const a=B(t,s,e.won),o=((e,t)=>{const s=Object.entries(e.best).filter(([e])=>e.startsWith(`${t}:`));return s.length?1===s.length?`best ${P(s[0][1])}`:s.map(([e,s])=>`${e.slice(t.length+1)} ${P(s)}`).join(" · "):null})(e,s.name);return{label:s.title,testid:`app.menu.level.${s.name}`,...a?{note:`locked — ${a}`,hint:`Locked: ${a}`}:{action:"app.level.load",input:{module_id:Q,level:s.name},...o?{note:o}:{}}}}),{label:"Credits",testid:"app.menu.credits",action:"app.credits",input:{module_id:Q,show:!0}}]});{const t=e=>{h(e,{size:14,strokeWidth:2})},i=t=>{var s=l(),a=L(s),i=e=>{{let t=k(()=>$(Z).problems.join(" · "));u(e,{label:"not an app",tone:"err",dot:!0,get title(){return $(t)}})}},n=e=>{{let t=k(()=>$(se)?"edit · saving":"edit");u(e,{get label(){return $(t)},title:"The source — Play reads it and shows the menu"})}};o(a,e=>{$(Z)?.problems.length?e(i):$(ee)&&e(n,1)}),e(t,s)},d=t=>{var s=K(),a=z(L(s),2),l=e=>{{const t=e=>{b(e,{size:14,strokeWidth:2})};p(e,{testid:"app.play",size:"lg",label:"Play",onclick:()=>{J.actions.run("app.document.edit",{module_id:Q,on:!1})},title:"Read the source and show the app's menu",icon:t,$$slots:{icon:!0}})}},i=e=>{{const t=e=>{v(e,{size:14,strokeWidth:2})};p(e,{testid:"app.edit",size:"lg",label:"Edit",onclick:()=>{J.actions.run("app.document.edit",{module_id:Q,on:!0})},title:"Edit the source: its title and its levels",icon:t,$$slots:{icon:!0}})}};o(a,e=>{$(ee)?e(l):e(i,-1)}),e(t,s)};c(a,{get title(){return $(X)},onClose:()=>{J.actions.run("view.document.remove",{module_id:Q})},icon:t,actions:i,footer:d,children:(t,a)=>{var i=l(),d=L(i),c=t=>{var a=V(),l=L(a),i=t=>{var a=O(),o=f(a);r(o,20,()=>$(Z).problems,e=>e,(t,a)=>{var o=N(),l=M(o,!0);T(()=>s(l,a)),e(t,o)}),E(o),E(a),e(t,a)};o(l,e=>{$(Z)?.problems.length&&e(i)});var n=z(l,2),d=f(n),c=e=>{U(e,{language:"json",get ownerId(){return Q},get value(){return $(Y)},set value(e){w(Y,e,!0)}})},p=t=>{var s=R();e(t,s)};o(d,e=>{U?e(c):e(p,-1)}),E(n),e(t,a)},p=t=>{var s=q(),a=f(s),i=t=>{var s=l(),a=L(s);n(a,()=>$(Z).save.read,t=>{var s=l(),a=L(s),i=e=>{{let t=k(()=>[{label:"Back",testid:"app.credits.back",action:"app.credits",input:{module_id:Q,show:!1}}]);m(e,{title:"Credits",get lines(){return $(Z).credits},get entries(){return $(t)},testid:"app.credits",run:le})}},n=e=>{{let t=k(()=>$(Z).save.problem?[`The save: ${$(Z).save.problem}`]:[]);m(e,{get title(){return $(Z).doc.title},get entries(){return $(re)},get lines(){return $(t)},get volume(){return $(ne)},testid:"app.menu",run:le})}};o(a,e=>{$(Z).credits?e(i):e(n,-1)}),e(t,s)}),e(t,s)},r=e=>{{let t=k(()=>$(Z).problems.join(" · "));g(e,{block:!0,get text(){return $(t)}})}};o(a,e=>{$(Z)?.doc?e(i):$(Z)?.problems.length&&e(r,1)}),E(s),e(t,s)};o(d,e=>{$(ee)?e(c):e(p,-1)}),e(t,i)},$$slots:{icon:!0,actions:!0,footer:!0,default:!0}})}x()}export{G as default};
@@ -0,0 +1 @@
1
+ .gv-body.svelte-ot5c55{flex-direction:column;flex:1;min-height:0;display:flex;position:relative}.gv-play.svelte-ot5c55{background:radial-gradient(ellipse at 50% 35%, var(--hud-shade-2), var(--bg) 75%)}.gv-problems.svelte-ot5c55{border-bottom:1px solid var(--border-2);color:var(--status-error);font-family:var(--font-mono);font-size:var(--fs-meta-mono);padding:8px 12px}.gv-problems.svelte-ot5c55 ul:where(.svelte-ot5c55){margin:0;padding-left:16px}.gv-error.svelte-ot5c55{color:var(--text-3);padding:12px}
@@ -0,0 +1,64 @@
1
+ import { a as e, i as t, o as s } from "./stageWorker-ggqqFf5m.js";
2
+ var r = class extends e {
3
+ constructor(e) {
4
+ super(e);
5
+ }
6
+ load(e, s, r, o) {
7
+ const n = this, a = new t(this.manager);
8
+ a.setPriority(this.priority), a.setCache(this.cache), a.setPath(this.path), a.setRequestHeader(this.requestHeader), a.setWithCredentials(this.withCredentials), a.load(e, function(e) {
9
+ const t = n.parse(JSON.parse(e));
10
+ s && s(t);
11
+ }, r, o);
12
+ }
13
+ parse(e) {
14
+ return new o(e);
15
+ }
16
+ }, o = class {
17
+ constructor(e) {
18
+ this.isFont = !0, this.type = "Font", this.data = e;
19
+ }
20
+ generateShapes(e, t = 100, s = "ltr") {
21
+ const r = [], o = function(e, t, s, r) {
22
+ const o = Array.from(e), a = t / s.resolution, i = (s.boundingBox.yMax - s.boundingBox.yMin + s.underlineThickness) * a, c = [];
23
+ let h = 0, l = 0;
24
+ "rtl" != r && "tb" != r || o.reverse();
25
+ for (let u = 0; u < o.length; u++) {
26
+ const e = o[u];
27
+ if ("\n" === e) h = 0, l -= i;
28
+ else {
29
+ const t = n(e, a, h, l, s);
30
+ "tb" == r ? (h = 0, l += s.ascender * a) : h += t.offsetX, c.push(t.path);
31
+ }
32
+ }
33
+ return c;
34
+ }(e, t, this.data, s);
35
+ for (let n = 0, a = o.length; n < a; n++) r.push(...o[n].toShapes());
36
+ return r;
37
+ }
38
+ };
39
+ function n(e, t, r, o, n) {
40
+ const a = n.glyphs[e] || n.glyphs["?"];
41
+ if (!a) return void console.error("THREE.Font: character \"" + e + "\" does not exists in font family " + n.familyName + ".");
42
+ const i = new s();
43
+ let c, h, l, u, d, f, p, g;
44
+ if (a.o) {
45
+ const e = a._cachedOutline || (a._cachedOutline = a.o.split(" "));
46
+ for (let s = 0, n = e.length; s < n;) switch (e[s++]) {
47
+ case "m":
48
+ c = e[s++] * t + r, h = e[s++] * t + o, i.moveTo(c, h);
49
+ break;
50
+ case "l":
51
+ c = e[s++] * t + r, h = e[s++] * t + o, i.lineTo(c, h);
52
+ break;
53
+ case "q":
54
+ l = e[s++] * t + r, u = e[s++] * t + o, d = e[s++] * t + r, f = e[s++] * t + o, i.quadraticCurveTo(d, f, l, u);
55
+ break;
56
+ case "b": l = e[s++] * t + r, u = e[s++] * t + o, d = e[s++] * t + r, f = e[s++] * t + o, p = e[s++] * t + r, g = e[s++] * t + o, i.bezierCurveTo(d, f, p, g, l, u);
57
+ }
58
+ }
59
+ return {
60
+ offsetX: a.ha * t,
61
+ path: i
62
+ };
63
+ }
64
+ export { o as Font, r as FontLoader };
@@ -0,0 +1 @@
1
+ .stage-document.svelte-1lxvsu{flex-direction:column;width:100%;height:100%;min-height:0;display:flex;position:relative}.picture.svelte-1lxvsu{flex:1;min-height:0;position:relative}canvas.editing.svelte-1lxvsu{cursor:crosshair;-webkit-mask-image:none;mask-image:none}canvas.world.svelte-1lxvsu{-webkit-mask-image:none;mask-image:none}canvas.svelte-1lxvsu{width:100%;height:100%;position:absolute;inset:0;-webkit-mask-image:linear-gradient(#000 70%,#0000);mask-image:linear-gradient(#000 70%,#0000)}.sv-stage.svelte-wtfu26,.sv-editor.svelte-wtfu26{flex-direction:column;flex:1;min-height:0;display:flex;position:relative}.sv-problems.svelte-wtfu26{border-bottom:1px solid var(--border-2);color:var(--status-error);font-family:var(--font-mono);font-size:var(--fs-meta-mono);padding:8px 12px}.sv-problems.svelte-wtfu26 ul:where(.svelte-wtfu26){margin:4px 0 0;padding-left:16px}.sv-error.svelte-wtfu26{color:var(--text-3);padding:12px}
@@ -0,0 +1 @@
1
+ import"./disclose-version-BvIhFN19.js";import{t as e}from"./fileMirror-CkgB9zNS.js";import{A as t,C as n,D as s,F as i,I as o,L as l,M as a,S as r,a as d,c,d as u,h as m,i as p,j as h,m as g,o as f,t as v,v as w,w as k,y}from"./client-DksDHYQL.js";import{a as b,c as $,i as x,n as M,s as j,t as E}from"./kit--nsV_OZy.js";import{t as I}from"./sun-Bi-OgPry.js";import{$ as P,D as L,Ft as z,K as _,L as A,M as C,Mn as T,Pt as R,S as Y,dt as F,lt as O,n as W,pt as S,rt as X,x as B,yt as D,z as N,zt as q}from"./src-DyDfRe65.js";import{t as K}from"./codeEditorBridge-Bl202hrO.js";import{C as V,G as H,K as U,M as G,S as J,T as Z,V as Q,a as ee,b as te,c as ne,f as se,g as ie,i as oe,j as le,p as ae,r as re,t as de,v as ce,w as ue,y as me}from"./runtime-7lvdeERt.js";function pe(e){if("undefined"==typeof document)return()=>"";const t=getComputedStyle(e??document.documentElement);return e=>t.getPropertyValue(`--${e}`).trim()}var he=()=>"undefined"==typeof document?null:document.documentElement.getAttribute("data-theme");function ge(e){return new Worker(new URL("stageWorker-ggqqFf5m.js",import.meta.url).href,{type:"module",name:e?.name})}var fe=a('<div class="stage-document svelte-1lxvsu"><!> <div class="picture svelte-1lxvsu" role="presentation"><canvas aria-label="The stage" data-testid="stage.picture"></canvas></div></div>');function ve(e,s){z(s,!0);const[i,a]=d(),u=e=>!e?.world.edit&&Object.values(e?.doc?.controls??{}).some(e=>"look"===e.kind||("hit"===e.kind||"hold"===e.kind)&&!!e.mouse),p=e=>{const t=e.target;if(!L(y)||!u(L(b))||L(b)?.paused||L(Xe))return;const n=L(y).getBoundingClientRect();e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom&&n.width>0&&document.pointerLockElement!==L(y)&&!t.closest('button, input, select, textarea, [role="slider"]')&&h(L(y))};function h(e){Promise.resolve(e.requestPointerLock({unadjustedMovement:!0})).catch(()=>e.requestPointerLock()).catch(()=>{})}const v=H(),w=W();let y=N(void 0),b=N(null);const $=C(()=>s.moduleId),x=new ge,M=(e,t=[])=>x.postMessage(e,t),j=[],I=new Map;let T=0;const O=new Map,X=new Map,K=new Map,ee=new Map,le=(e,t)=>new Promise((n,s)=>{const i=++T;ee.set(i,{resolve:n,reject:s}),M({kind:"film",id:i,...e?{start:e}:{},...void 0===t?{}:{end:t}})});j.push(ae($,{snap:e=>new Promise((t,n)=>{const s=++T;I.set(s,{resolve:t,reject:n}),M({kind:"snap",id:s,width:e}),setTimeout(()=>{I.has(s)&&(I.delete(s),n(new Error("the stage worker did not answer within 15 s — close the stage and open it again")))},15e3)}),draw:(e,t)=>M({kind:"drive",at:e,...t}),ready:()=>new Promise(e=>{const t=++T;O.set(t,e),M({kind:"ready",id:t})}),hit:(e,t,n,s)=>M({kind:"hit",element:e,input:t,at:performance.now(),...void 0===n?{}:{value:n},...void 0===s?{}:{by:s}}),play:(e,t,n)=>M({kind:"play",element:e,drive:t,cars:n}),orbit:(e,t)=>M({kind:"orbit",element:e,move:t}),pick:(e,t,n)=>new Promise(s=>{const i=++T;X.set(i,s),M({kind:"pick",id:i,element:e,x:t,y:n})}),mission:(e,t)=>new Promise(n=>{const s=++T;K.set(s,n),M({kind:"mission",id:s,element:e,...t})}),film:{begin:async e=>{await le(e)},end:async e=>{const t=await le(void 0,e);if(!t)throw new Error("the stage worker handed no film over");return t}}}));let de=null;const ve=(e=!1)=>{const t=v.net.status().connected&&we===$;(t!==de||e)&&M({kind:"net",on:t,...!t||!e&&de?{}:{now:!0}}),de=t};let we=null;j.push(re.subscribe(e=>(we=e,ve())));const ke=()=>M({kind:"peers",peers:we===$?v.net.status().peers.flatMap(e=>e.state&&e.channels.includes(v.net.status().channels[0]??"")?[{id:e.id,x:e.state.x??0,y:e.state.y??0,z:e.state.z??0,heading:e.state.heading??0}]:[]):[]});j.push(v.net.subscribe(e=>(ve("joined"===e?.type),ke()))),j.push(re.subscribe(()=>ke()));let ye,be=!1;x.onerror=e=>{const t=`the stage worker failed: ${e.message||"it could not load"}${e.filename?` (${e.filename}:${e.lineno})`:""}`;U("stage").error(t),be||mt(t)},x.onmessage=e=>{be=!0;const t=e.data;if("readText"===t.kind&&t.binary)v.files.readBinary(t.ref).then(e=>M({kind:"file",id:t.id,bytes:e},[e]),e=>M({kind:"file",id:t.id,error:e.message}));else if("readText"===t.kind)v.files.readText(t.ref).then(e=>M({kind:"file",id:t.id,text:e}),e=>M({kind:"file",id:t.id,error:e.message}));else if("role"===t.kind)M({kind:"role",name:t.name,value:pe()(t.name)});else if("sound"===t.kind)V($,t.element,t.events,t.values);else if("world-events"===t.kind)Z($,t.element,t.events);else if("hud"===t.kind)A(Oe,t.hud);else if("spots"===t.kind)A(st,{w:t.w,h:t.h,spots:t.spots}),ie($,{w:t.w,h:t.h,said:t.said});else if("made"===t.kind)me($,t.failed);else if("cost"===t.kind)ce.update(e=>new Map(e).set($,t.cost));else if("pick"===t.kind)X.get(t.id)?.(t.picked),X.delete(t.id);else if("mission"===t.kind)K.get(t.id)?.(t.answer),K.delete(t.id);else if("standing"===t.kind){const e=v.net.status().channels[0];e&&v.net.send(e,{x:t.x,y:t.y,z:t.z,heading:t.heading})}else if("film"===t.kind){const e=ee.get(t.id);ee.delete(t.id),void 0!==t.error?e?.reject(new Error(t.error)):e?.resolve(t.take)}else if("ready"===t.kind)O.get(t.id)?.(),O.delete(t.id);else if("snap"===t.kind){const e=I.get(t.id);I.delete(t.id),void 0===t.error&&t.bytes?e?.resolve({bytes:new Uint8Array(t.bytes),samples:t.samples??[],...t.player?{player:t.player}:{},...t.mission?{mission:t.mission}:{},...t.others?{others:t.others}:{}}):e?.reject(new Error(t.error??"no picture"))}else U(t.source)[t.level](t.message)};let $e=null,xe=!1,Me=!1,je=!1;j.push(ue($)?.subscribe(e=>{A(b,e);const{doc:t}=e;t!==ye&&M({kind:"doc",doc:ye=t}),xe=!!t?.follow,null!==$e&&e.fresh!==$e&&(je=!0),$e=e.fresh,Me||(Me=!0,queueMicrotask(()=>{Me=!1;const{doc:e,...t}=L(b);M({kind:"state",state:t}),je&&M({kind:"fresh"}),je=!1}))})??(()=>{}));let Ee=null;j.push(v.transport.subscribe(e=>{e.playing!==Ee&&M({kind:"transport",playing:Ee=e.playing})}));let Ie="";j.push(v.transport.subscribePlayers(e=>{const t=oe($),n={plays:se(e,t),part:ne(e,t,xe)},s=JSON.stringify(n);s!==Ie&&(Ie=s,M({kind:"players",...n}))}));let Pe="";const Le=setInterval(()=>{const e={step:v.transport.clock.audibleAbsStep(),bpm:v.transport.getBpm()},t=`${e.step}|${e.bpm}`;t!==Pe&&(Pe=t,M({kind:"clock",...e}))},10),ze=new MutationObserver(()=>M({kind:"theme",theme:he()}));ze.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const _e=_(()=>!!L(b)?.world.edit);let Ae=null,Ce=null;const Te=async e=>{const t=await v.actions.run("stage.world.grab",(e=>{const t=L(y).getBoundingClientRect();return{module_id:$,x:(e.clientX-t.left)/t.width,y:(e.clientY-t.top)/t.height}})(e));return"object"==typeof t&&t?.thing?{thing:t.thing,at:t.at??0}:null},Re=()=>!(!L(y)||L(_e)||u(L(b))||!L(b)?.doc?.elements.some(e=>"world"===e.type)),Ye=()=>{Ce?.thing&&v.actions.run("stage.world.release",{module_id:$,thing:Ce.thing})},Fe=()=>{Ye(),Ae=Ce=null,it=null,ot=null};Y(()=>{const e=L(y);if(!e)return;const t=e=>{L(_e)&&(e.preventDefault(),v.actions.run("stage.world.orbit",{module_id:$,zoom:Math.sign(e.deltaY)}))};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)}),Y(()=>(window.addEventListener("pointerdown",p,!0),()=>window.removeEventListener("pointerdown",p,!0)));let Oe=N(null);const We=_(()=>G(L(b)?.doc?.hud)),Se=_(()=>f(te,"$stageOverlays",i).get($)??null),Xe=_(()=>L(Se)?.panel??null),Be=_(()=>!!L(Se)||Object.values(L(b)?.doc?.controls??{}).some(e=>"menu"===e.kind));let De=N(S(v.audio.getMasterVolumeL()));k(()=>v.audio.subscribeMaster(e=>A(De,e.volumeL,!0)));const Ne=_(()=>({level:L(De),set:e=>{v.actions.run("master.volume.set",{volume:e})}})),qe=(e,t)=>v.actions.run(e,t),Ke=_(()=>!!L(b)?.paused&&!L(_e));let Ve=!1;Y(()=>{const e=()=>{const e=!!L(y)&&document.pointerLockElement===L(y);!Ve||e||!L(Be)||L(b)?.paused||L(_e)||v.actions.run("stage.pause",{module_id:$,on:!0}),Ve=e};return document.addEventListener("pointerlockchange",e),()=>document.removeEventListener("pointerlockchange",e)}),Y(()=>{L(Ke)&&L(y)&&document.pointerLockElement===L(y)&&document.exitPointerLock()});const He=_(()=>[{label:"Resume",testid:"stage.menu.resume",action:"stage.pause",input:{module_id:$,on:!1}},...L(b)?.doc?.missions?.length?[{label:L(Oe)?.played?"Restart mission":"Start mission",testid:"stage.menu.restart",action:"stage.mission.start",input:{module_id:$,...L(Oe)?.played?{mission:L(Oe).played}:{}}}]:[],{label:"Fullscreen",testid:"stage.menu.fullscreen",action:"view.fullscreen",input:{}},...L(Se)?.menu??[]]),Ue=_(()=>L(Xe)?[...L(Xe).lines,...L(Oe)?.targets?[`Targets ${L(Oe).targets.hits} / ${L(Oe).targets.of}`]:[]]:[]),Ge=e=>{"stage.mission.start"===e.action&&v.actions.run("stage.pause",{module_id:$,on:!1}),("stage.pause"===e.action||"stage.mission.start"===e.action||e.playsOn)&&L(y)&&u(L(b))&&h(L(y))},Je=_(()=>L(Xe)?L(Xe).testid??"stage.panel":null),Ze=_(()=>!!L(Xe)||L(Ke)),Qe=_(()=>L(Xe)?L(Xe).entries:L(Ke)?L(He):[]),et=_(()=>L(Je)??"stage.menu"),tt=_(()=>!L(Xe)&&L(Ke));let nt=N(null),st=N({w:0,h:0,spots:[]}),it=null,ot=null;const lt=_(()=>[...L(Qe).filter(e=>!!e.action).map(e=>e.testid),...L(tt)?[`${L(et)}.volume`]:[]]);Y(()=>{const e=L(lt)[0]??null;C(()=>{L(nt)&&L(lt).includes(L(nt))||A(nt,e,!0)})});const at=(e,t,n,s,i)=>({title:e,lines:t,entries:n.map(e=>({label:e.label,testid:e.testid,...e.note?{note:e.note}:{},open:!!e.action})),volume:s,testid:i,focus:L(nt)}),rt=_(()=>({editing:L(_e),parts:[...L(We)],paused:L(Ke)&&!L(Xe)?at("Paused",[],L(He),L(De),"stage.menu"):null,panel:L(Xe)?at(L(Xe).title,L(Ue),L(Xe).entries,null,L(Je)):null,notice:L(Se)?.notice?{id:L(Se).notice.id,text:L(Se).notice.text}:null,...L(Se)?{cover:L(Se).cover||null}:{}}));Y(()=>M({kind:"screen",screen:q(L(rt))}));const dt=e=>{if(!L(y)||!L(st).w)return null;const t=L(y).getBoundingClientRect(),n=(e.clientX-t.left)/t.width*L(st).w,s=(e.clientY-t.top)/t.height*L(st).h;return L(st).spots.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h)??null},ct=e=>{if(!L(y)||!it)return;const t=L(y).getBoundingClientRect(),n=(e.clientX-t.left)/t.width*L(st).w;A(nt,it.testid,!0),L(Ne).set(Math.round(100*Math.min(1,Math.max(0,(n-it.x)/it.w)))/100)};async function ut(e){const t=L(Qe).find(t=>t.testid===e);t?.action&&(await qe(t.action,t.input??{}),Ge(t))}function mt(e){for(const t of I.values())t.reject(new Error(e));I.clear();for(const t of ee.values())t.reject(new Error(e));ee.clear();for(const t of O.values())t();O.clear();for(const t of X.values())t(null);X.clear();for(const t of K.values())t(null);K.clear()}Y(()=>{if(!L(Ze))return;const e=e=>{const t=L(nt)?L(lt).indexOf(L(nt)):-1,n=e=>A(nt,L(lt)[(t+e+L(lt).length)%L(lt).length]??null,!0);if("ArrowDown"===e.key||"Tab"===e.key&&!e.shiftKey)n(1);else if("ArrowUp"===e.key||"Tab"===e.key&&e.shiftKey)n(-1);else if("ArrowLeft"!==e.key&&"ArrowRight"!==e.key||!L(nt)?.endsWith(".volume")){if("Enter"!==e.key&&" "!==e.key||!L(nt)||L(nt).endsWith(".volume"))return;ut(L(nt))}else L(Ne).set(Math.round(100*Math.min(1,Math.max(0,L(De)+("ArrowRight"===e.key?.05:-.05))))/100);e.preventDefault(),e.stopPropagation()};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)}),k(()=>{if(!L(y))return;const e=v.documents.listModules().find(e=>e.id===$)?.title??$,t=L(y).transferControlToOffscreen();M({kind:"init",canvas:t,moduleId:$,title:e,origin:performance.timeOrigin,theme:he()},[t]);const n=new ResizeObserver(([e])=>{M({kind:"size",w:e.contentRect.width,h:e.contentRect.height,dpr:Math.min(1,window.devicePixelRatio||1)})}),s={},i=w.subscribe(e=>{M({kind:"seen",seen:e}),J($,s,e)});return n.observe(L(y)),()=>{n.disconnect(),i(),J($,s,null)}}),n(()=>{Fe(),mt("the stage view closed");for(const e of j)e();clearInterval(Le),ze.disconnect(),ie($,null),x.terminate()});var pt=fe(),ht=P(pt),gt=e=>{{let t=_(()=>L(b).problems.join(" · "));E(e,{block:!0,get text(){return L(t)}})}};r(ht,e=>{L(b)?.problems.length&&e(gt)});var ft=F(ht,2),vt=P(ft);let wt;c(vt,e=>A(y,e),()=>L(y)),m(vt,()=>w.observe),D(ft),D(pt),B(e=>wt=g(vt,1,"svelte-1lxvsu",null,wt,{editing:L(_e),world:e}),[()=>!!L(b)?.doc?.elements.some(e=>"world"===e.type)]),o("pointerdown",vt,e=>{if(L(Ze)){const t=dt(e);if(0!==e.button||!t||t.disabled)return;return void("volume"===t.kind?(it=t,L(y)?.setPointerCapture(e.pointerId),ct(e)):(ot=t.testid,L(y)?.setPointerCapture(e.pointerId)))}if(Re()&&0===e.button){const t={y:e.clientY,thing:null,at:0};return Ce=t,L(y)?.setPointerCapture(e.pointerId),void Te(e).then(e=>{Ce===t?e?[t.thing,t.at]=[e.thing,e.at]:Ce=null:e&&v.actions.run("stage.world.release",{module_id:$,thing:e.thing})})}L(_e)&&(Ae={x:e.clientX,y:e.clientY,button:e.button,moved:!1},L(y)?.setPointerCapture(e.pointerId))}),o("pointermove",vt,e=>{if(it)return ct(e);if(L(Ze)){const t=dt(e);return void(t&&!t.disabled&&A(nt,t.testid,!0))}if(Ce?.thing&&e.clientY!==Ce.y&&(Ce.at=Q(Ce.at,e.clientY-Ce.y,e.shiftKey),Ce.y=e.clientY,v.actions.run("stage.world.drag",{module_id:$,thing:Ce.thing,to:Ce.at})),!Ae)return;const[t,n]=[e.clientX-Ae.x,e.clientY-Ae.y];!Ae.moved&&Math.hypot(t,n)<4||([Ae.moved,Ae.x,Ae.y]=[!0,e.clientX,e.clientY],v.actions.run("stage.world.orbit",{module_id:$,dx:t,dy:n,pan:0!==Ae.button}))}),o("pointerup",vt,e=>{it=null;const t=ot;if(ot=null,t&&L(Ze))return void(dt(e)?.testid===t&&ut(t));Ye(),Ce=null;const n=Ae;if(Ae=null,!n||n.moved||0!==n.button||!L(y))return;const s=L(y).getBoundingClientRect();v.actions.run("stage.world.click",{module_id:$,x:(e.clientX-s.left)/s.width,y:(e.clientY-s.top)/s.height})}),l("pointercancel",vt,Fe),o("dblclick",vt,async e=>{if(!Re())return;const t=await Te(e);t&&v.actions.run("stage.world.drag",{module_id:$,thing:t.thing,reset:!0})}),l("lostpointercapture",vt,Fe),o("contextmenu",vt,e=>L(_e)&&e.preventDefault()),t(e,pt),R(),a()}i(["pointerdown","pointermove","pointerup","dblclick","contextmenu"]);var we=new Map;var ke=a('<span class="sv-cost" data-testid="stage.cost"><!></span>'),ye=a("<!> <!>",1),be=a("<!> <!> <!> <!>",1),$e=a('<span class="fw-footer-spacer"></span> <!>',1),xe=a("<li> </li>"),Me=a('<section class="sv-problems svelte-wtfu26" aria-label="Not a stage"><p> </p> <ul class="svelte-wtfu26"></ul></section>'),je=a('<p class="sv-error svelte-wtfu26">The code editor is not loaded — the editors extension provides it.</p>'),Ee=a('<!> <div class="sv-editor svelte-wtfu26"><!></div>',1),Ie=a('<div class="sv-stage svelte-wtfu26"><!></div>');function Pe(i,o){z(o,!0);const l=()=>f(ee,"$filming",a),[a,c]=d(),m=H(),g=e=>{m.actions.run(e,{module_id:o.moduleId})},E=K();let W=N(null),q=N(""),V=N(""),U=N(!1),G=N(S([])),J=N("play"),Z=N(!1),Q=N(!1),te=N(!1),ne=null;Y(()=>{L(V),C(()=>{ne?.changed(),A(U,!!ne?.dirty())})});let se=N(!1);async function ie(){A(se,!0);try{await(async()=>{await(ne?.save())})(),A(G,L(W)?de(o.moduleId,L(V),L(W)):["This stage has no file."],!0),L(G).length||A(J,"play")}finally{A(se,!1)}}let oe=[];k(()=>{var t,n,s,i;ne=e({api:m,moduleId:o.moduleId,ext:".stage",get:()=>L(V),set:e=>A(V,e,!0),onFile:e=>{return t=[e.title,e.ref],n=T(t,2),A(q,n[0],!0),A(W,n[1],!0),t;var t,n},onText:()=>A(U,!!ne?.dirty())}),t=[ne.title(),ne.ref()],n=T(t,2),A(q,n[0],!0),A(W,n[1],!0),oe=[(s=o.moduleId,i={edit:()=>(A(J,"edit"),`${L(q)} is in edit: its source in the code editor.`),follow:async e=>(A(V,le(L(V),e),!0),await ie(),L(G).length?`${L(q)}: ${L(G).join("; ")}.`:e?`${L(q)} follows Master Play — the floor dances with the clock.`:`${L(q)} is detached — it moves while a Performer plays it.`),compile:async()=>(await ie(),L(G).length?`${L(q)} is not a stage as written: ${L(G).join("; ")}.`:`${L(q)} compiled — it stands on the stage, live.`),apply:async(e,t)=>{const n=e(L(V));return"problem"in n?`${L(q)}: ${n.problem}.`:(A(V,n.text,!0),await ie(),L(G).length?`${L(q)}: ${L(G).join("; ")}.`:`${t} — on ${L(q)}, live.`)}},we.set(s,i),()=>{we.get(s)===i&&we.delete(s)})],ne.load()});let ae=N(null),re=N(30);const me=_(()=>1e3/L(re));k(()=>ce.subscribe(e=>A(ae,e.get(o.moduleId)??null,!0))),Y(()=>ue(o.moduleId)?.subscribe(e=>{A(Z,!!e.doc?.follow),A(re,e.doc?.fps??30,!0),A(Q,!!e.doc?.elements.some(e=>"world"===e.type)),A(te,e.world.edit,!0),!e.doc&&e.problems.length&&(A(G,e.problems,!0),A(J,"edit"))})),n(()=>{ne?.dispose();for(const e of oe)e()});{const e=e=>{I(e,{size:14,strokeWidth:2})},n=e=>{var n=ye(),s=X(n),i=e=>{var n=ke(),s=P(n);{let e=_(()=>`${L(ae).ms.toFixed(1)} ms`),t=_(()=>L(ae).ms>L(me)?"err":L(ae).ms>L(me)/2?"warn":"neutral"),n=_(()=>`A picture costs ${L(ae).ms} ms — computing ${L(ae).compute}, drawing ${L(ae).draw}, the longest ${L(ae).most} — of ${L(me).toFixed(1)} ms a picture at ${L(re)} pictures a second (${L(ae).frames} in the last second)`);M(s,{get label(){return L(e)},get tone(){return L(t)},get title(){return L(n)}})}D(n),B(e=>u(n,"data-value",e),[()=>String(L(ae).ms)]),t(e,n)};r(s,e=>{L(ae)&&"edit"!==L(J)&&!L(G).length&&e(i)});var o=F(s,2),l=e=>{{let t=_(()=>L(G).join(" · "));M(e,{label:"not a stage",tone:"err",dot:!0,get title(){return L(t)}})}},a=e=>{{let t=_(()=>L(U)?"edit · saving":"edit");M(e,{get label(){return L(t)},title:"The source — Compile puts it on the stage"})}};r(o,e=>{L(G).length?e(l):"edit"===L(J)&&e(a,1)}),t(e,n)},a=e=>{var n=$e(),s=F(X(n),2),i=e=>{{const n=e=>{!function(e,n){const s=v(n,["children","$$slots","$$events","$$legacy"]),i=[["path",{d:"m15 12-9.373 9.373a1 1 0 0 1-3.001-3L12 9"}],["path",{d:"m18 15 4-4"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172v-.344a2 2 0 0 0-.586-1.414l-1.657-1.657A6 6 0 0 0 12.516 3H9l1.243 1.243A6 6 0 0 1 12 8.485V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5"}]];$(e,p({name:"hammer"},()=>s,{get iconNode(){return i},children:(e,s)=>{var i=h(),o=X(i);w(o,n,"default",{},null),t(e,i)},$$slots:{default:!0}}))}(e,{size:14,strokeWidth:2})};x(e,{testid:"stage.compile",size:"lg",label:"Compile",get disabled(){return L(se)},onclick:()=>g("stage.document.compile"),title:"Save and check the source — it goes on the stage live",icon:n,$$slots:{icon:!0}})}},a=e=>{var n=be(),s=X(n);{const e=e=>{j(e,{size:14,strokeWidth:2})};x(s,{testid:"stage.edit",size:"lg",label:"Edit",onclick:()=>g("stage.document.edit"),title:"Edit the source",icon:e,$$slots:{icon:!0}})}var i=F(s,2);{const e=e=>{!function(e,n){const s=v(n,["children","$$slots","$$events","$$legacy"]),i=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12"}]];$(e,p({name:"link-2"},()=>s,{get iconNode(){return i},children:(e,s)=>{var i=h(),o=X(i);w(o,n,"default",{},null),t(e,i)},$$slots:{default:!0}}))}(e,{size:14,strokeWidth:2})};let n=_(()=>!L(W)),s=_(()=>L(Z)?"Follows Master Play — the floor dances with the clock; click to detach":"Detached — it moves while a Performer plays it; click to follow Master Play");x(i,{testid:"stage.follow",size:"lg",get active(){return L(Z)},get disabled(){return L(n)},onclick:()=>{m.actions.run("stage.follow.set",{module_id:o.moduleId,enabled:!L(Z)})},get title(){return L(s)},ariaLabel:"Follow Master Play",icon:e,$$slots:{icon:!0}})}var a=F(i,2);{const e=e=>{!function(e,n){const s=v(n,["children","$$slots","$$events","$$legacy"]),i=[["path",{d:"m12.296 3.464 3.02 3.956"}],["path",{d:"M20.2 6 3 11l-.9-2.4c-.3-1.1.3-2.2 1.3-2.5l13.5-4c1.1-.3 2.2.3 2.5 1.3z"}],["path",{d:"M3 11h18v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}],["path",{d:"m6.18 5.276 3.1 3.899"}]];$(e,p({name:"clapperboard"},()=>s,{get iconNode(){return i},children:(e,s)=>{var i=h(),o=X(i);w(o,n,"default",{},null),t(e,i)},$$slots:{default:!0}}))}(e,{size:14,strokeWidth:2})};let n=_(()=>l().has(o.moduleId)),s=_(()=>l().has(o.moduleId)?"End the film — it goes beside its take in the Recorder (Export… → MP4)":"Film the stage with the sound, 1080p — until clicked again"),i=_(()=>l().has(o.moduleId)?"End the film":"Film the stage");x(a,{testid:"stage.film",size:"lg",get active(){return L(n)},onclick:()=>{m.actions.run("stage.film.record",{module_id:o.moduleId,on:!l().has(o.moduleId)})},get title(){return L(s)},get ariaLabel(){return L(i)},icon:e,$$slots:{icon:!0}})}var d=F(a,2),c=e=>{{const n=e=>{!function(e,n){const s=v(n,["children","$$slots","$$events","$$legacy"]),i=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"}],["path",{d:"m3.3 7 8.7 5 8.7-5"}],["path",{d:"M12 22V12"}]];$(e,p({name:"box"},()=>s,{get iconNode(){return i},children:(e,s)=>{var i=h(),o=X(i);w(o,n,"default",{},null),t(e,i)},$$slots:{default:!0}}))}(e,{size:14,strokeWidth:2})};let s=_(()=>L(te)?"Play the world again — made anew as written":"Edit the world on the stage: place models on the grid, turn them, set their fields");x(e,{size:"lg",get active(){return L(te)},onclick:()=>{m.actions.run("stage.world.edit",{module_id:o.moduleId,on:!L(te)})},get title(){return L(s)},ariaLabel:"Edit the world",testid:"stage.world.edit",icon:n,$$slots:{icon:!0}})}};r(d,e=>{L(Q)&&e(c)}),t(e,n)};r(s,e=>{"edit"===L(J)?e(i):e(a,-1)}),t(e,n)};b(i,{get title(){return L(q)},onClose:()=>{m.actions.run("view.document.remove",{module_id:o.moduleId})},icon:e,actions:n,footer:a,children:(e,n)=>{var i=h(),l=X(i),a=e=>{var n=Ee(),i=X(n),l=e=>{var n=Me(),i=P(n),o=O(i,!0),l=F(i,2);y(l,20,()=>L(G),e=>e,(e,n)=>{var i=xe(),o=O(i,!0);B(()=>s(o,n)),t(e,i)}),D(l),D(n),B(()=>s(o,1===L(G).length?"This is not a stage as written:":`This is not a stage as written — ${L(G).length} problems:`)),t(e,n)};r(i,e=>{L(G).length&&e(l)});var a=F(i,2),d=P(a),c=e=>{E(e,{language:"json",get ownerId(){return o.moduleId},get value(){return L(V)},set value(e){A(V,e,!0)}})},u=e=>{var n=je();t(e,n)};r(d,e=>{E?e(c):e(u,-1)}),D(a),t(e,n)},d=e=>{var n=Ie();ve(P(n),{get moduleId(){return o.moduleId}}),D(n),t(e,n)};r(l,e=>{"edit"===L(J)?e(a):e(d,-1)}),t(e,i)},$$slots:{icon:!0,actions:!0,footer:!0,default:!0}})}R(),c()}export{Pe as default};
@@ -0,0 +1 @@
1
+ import{a as s,c as a,i as o,n as r,o as t,r as i,s as c,t as e}from"./actionRegistry-hOkUYNvI.js";export{a as runAction};
@@ -0,0 +1 @@
1
+ import"./src-DyDfRe65.js";import{n as e}from"./toasts-BCcM1yGS.js";function t(e){const t=e;return"object"==typeof t&&null!==t&&"string"==typeof t.text&&"string"==typeof t.image?.data&&("image/png"===t.image.mimeType||"image/jpeg"===t.image.mimeType)}var n=e=>`${e.text}\n[picture: ${"image/jpeg"===e.image.mimeType?"JPEG":"PNG"}, ${Math.round(3*e.image.data.length/4/1024)} kB — shown to callers that can look]`;function r(e,t){const n=typeof e;if(n!==typeof t)return!1;const o=Array.isArray(e);if(o!==Array.isArray(t))return!1;if(o){const n=e.length;if(n!==t.length)return!1;for(let o=0;o<n;o++)if(!r(e[o],t[o]))return!1;return!0}if("object"===n){if(!e||!t)return e===t;const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(const i of n){if(!Object.prototype.hasOwnProperty.call(t,i))return!1;if(!r(e[i],t[i]))return!1}return!0}return e===t}function o(e){return encodeURI(function(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}(e)).replace(/#/g,"%23")}var i=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,a=/^%[0-9A-Fa-f]{2}$/,s=/^[A-Za-z0-9._~-]$/;function c(e,t){const n=new URL(e,t.href);return n.hash=n.hash?function(e){let t="";for(let n=0;n<e.length;){const r=e[n],o=e.slice(n,n+3);if("%"===r&&a.test(o)){const e=String.fromCharCode(parseInt(o.slice(1),16));t+=s.test(e)?e:o.toUpperCase(),n+=3;continue}const c=String.fromCodePoint(e.codePointAt(n));t+=i.test(c)?c:encodeURIComponent(c),n+=c.length}return t}(n.hash.slice(1)):"",n}var d={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},u={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},f={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},l="undefined"!=typeof self&&self.location&&"null"!==self.location.origin?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function m(e,t=Object.create(null),n=l,r=""){if(e&&"object"==typeof e&&!Array.isArray(e)){const o=e.$id||e.id;if(o){const i=c(o,n);i.hash.length>1?t[i.href]=e:(i.hash="",""===r?n=i:m(e,t,n))}}else if(!0!==e&&!1!==e)return t;const i=n.href+(r?"#"+r:"");if(void 0!==t[i]&&t[i]!==e)throw new Error(`Duplicate schema URI "${i}".`);if(t[i]=e,!0===e||!1===e)return t;if(void 0===e.__absolute_uri__&&Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i}),e.$ref&&void 0===e.__absolute_ref__){const t=c(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:t.href})}if(e.$recursiveRef&&void 0===e.__absolute_recursive_ref__){const t=c(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:t.href})}if(e.$anchor){t[c("#"+e.$anchor,n).href]=e}for(let a in e){if(f[a])continue;const i=`${r}/${o(a)}`,s=e[a];if(Array.isArray(s)){if(d[a]){const e=s.length;for(let r=0;r<e;r++)m(s[r],t,n,`${i}/${r}`)}}else if(u[a])for(let e in s)m(s[e],t,n,`${i}/${o(e)}`);else m(s,t,n,i)}return t}var h=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,p=[0,31,28,31,30,31,30,31,31,30,31,30,31],$=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,y=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i,w=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,v=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,g=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;function k(e){return e.test.bind(e)}var L={date:b,time:_.bind(void 0,!0),"date-time":function(e){const[t,n,r]=e.split(x);return void 0!==t&&void 0!==n&&void 0===r&&b(t)&&_(!0,n)},duration:e=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e),uri:function(e){return I.test(e)&&A.test(e)},"uri-reference":k(/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i),"uri-template":k(/^(?:(?:[^\x00-\x20\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i),url:k(/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu),email:e=>{const t=e.match(w);if(!t)return!1;const n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if('"'!==n[0]&&("."===n[0]||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){const e=r.slice(1,-1);return/^ipv6:/i.test(e)?g.test(e.slice(5)):v.test(e)}return y.test(r)},hostname:k(y),ipv4:k(v),ipv6:k(g),regex:function(e){if(O.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}},uuid:k(/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i),"json-pointer":k(/^(?:\/(?:[^~/]|~0|~1)*)*$/),"json-pointer-uri-fragment":k(/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i),"relative-json-pointer":k(/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/)};function b(e){const t=e.match(h);if(!t)return!1;const n=t[1],r=t[2],o=t[3];if(!n||!r||!o)return!1;const i=+r,a=+o,s=2==i&&function(e){return e%4==0&&(e%100!=0||e%400==0)}(+n)?29:p[i];return i>=1&&i<=12&&a>=1&&void 0!==s&&a<=s}function _(e,t){const n=t.match($);if(!n)return!1;const r=n[1],o=n[2],i=n[3];if(!r||!o||!i)return!1;const a=+r,s=+o,c=+i,d=n[5],u=n[6],f=+(n[7]??0),l=+(n[8]??0);if(a>23||s>59||c>60||f>23||l>59||e&&void 0===d)return!1;if(c<60)return!0;return(60*a+s-("+"===u?1:"-"===u?-1:0)*(60*f+l)+1440)%1440==1439}var x=/t|\s/i;var I=/\/|:/,A=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;var O=/[^\\]\\Z/;function z(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function j(e){const t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",o=n.indexOf("."),i=-1===o?0:n.length-o-1;return[BigInt(n.replace(".","")),Number(r)-i]}function R(e,t,n="2019-09",i=m(t),a=!0,s=null,c="#",d="#",u=Object.create(null)){if(!0===t)return{valid:!0,errors:[]};if(!1===t)return{valid:!1,errors:[{instanceLocation:c,keyword:"false",keywordLocation:c,error:"False boolean schema."}]};const f=typeof e;let l;switch(f){case"boolean":case"number":case"string":l=f;break;case"object":l=null===e?"null":Array.isArray(e)?"array":"object";break;default:throw new Error(`Instances of "${f}" type are not supported.`)}const{$ref:h,$recursiveRef:p,$recursiveAnchor:$,type:y,const:w,enum:v,required:g,not:k,anyOf:b,allOf:_,oneOf:x,if:I,then:A,else:O,format:P,properties:S,patternProperties:E,additionalProperties:q,unevaluatedProperties:M,minProperties:C,maxProperties:N,propertyNames:D,dependentRequired:U,dependentSchemas:T,dependencies:J,prefixItems:F,items:W,additionalItems:B,unevaluatedItems:G,contains:Z,minContains:H,maxContains:V,minItems:X,maxItems:K,uniqueItems:Y,minimum:Q,maximum:ee,exclusiveMinimum:te,exclusiveMaximum:ne,multipleOf:re,minLength:oe,maxLength:ie,pattern:ae,__absolute_ref__:se,__absolute_recursive_ref__:ce}=t,de=[];if(!0===$&&null===s&&(s=t),"#"===p){const r=null===s?i[ce]:s,o=`${d}/$recursiveRef`,f=R(e,null===s?t:s,n,i,a,r,c,o,u);f.valid||de.push({instanceLocation:c,keyword:"$recursiveRef",keywordLocation:o,error:"A subschema had errors."},...f.errors)}if(void 0!==h){const t=i[se||h];if(void 0===t){let e=`Unresolved $ref "${h}".`;throw se&&se!==h&&(e+=` Absolute URI "${se}".`),e+=`\nKnown schemas:\n- ${Object.keys(i).join("\n- ")}`,new Error(e)}const r=`${d}/$ref`,o=R(e,t,n,i,a,s,c,r,u);if(o.valid||de.push({instanceLocation:c,keyword:"$ref",keywordLocation:r,error:"A subschema had errors."},...o.errors),"4"===n||"7"===n)return{valid:0===de.length,errors:de}}if(Array.isArray(y)){let t=y.length,n=!1;for(let r=0;r<t;r++)if(l===y[r]||"integer"===y[r]&&"number"===l&&e%1==0&&e==e){n=!0;break}n||de.push({instanceLocation:c,keyword:"type",keywordLocation:`${d}/type`,error:`Instance type "${l}" is invalid. Expected "${y.join('", "')}".`})}else"integer"===y?("number"!==l||e%1||e!=e)&&de.push({instanceLocation:c,keyword:"type",keywordLocation:`${d}/type`,error:`Instance type "${l}" is invalid. Expected "${y}".`}):void 0!==y&&l!==y&&de.push({instanceLocation:c,keyword:"type",keywordLocation:`${d}/type`,error:`Instance type "${l}" is invalid. Expected "${y}".`});if(void 0!==w&&("object"===l||"array"===l?r(e,w)||de.push({instanceLocation:c,keyword:"const",keywordLocation:`${d}/const`,error:`Instance does not match ${JSON.stringify(w)}.`}):e!==w&&de.push({instanceLocation:c,keyword:"const",keywordLocation:`${d}/const`,error:`Instance does not match ${JSON.stringify(w)}.`})),void 0!==v&&("object"===l||"array"===l?v.some(t=>r(e,t))||de.push({instanceLocation:c,keyword:"enum",keywordLocation:`${d}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`}):v.some(t=>e===t)||de.push({instanceLocation:c,keyword:"enum",keywordLocation:`${d}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`})),void 0!==k){const t=`${d}/not`;R(e,k,n,i,a,s,c,t).valid&&de.push({instanceLocation:c,keyword:"not",keywordLocation:t,error:'Instance matched "not" schema.'})}let ue=[];if(void 0!==b){const t=`${d}/anyOf`,r=de.length;let o=!1;for(const[d,f]of b.entries()){const r=Object.create(u),l=R(e,f,n,i,a,!0===$?s:null,c,`${t}/${d}`,r);de.push(...l.errors),o=o||l.valid,l.valid&&ue.push(r)}o?de.length=r:de.splice(r,0,{instanceLocation:c,keyword:"anyOf",keywordLocation:t,error:"Instance does not match any subschemas."})}if(void 0!==_){const t=`${d}/allOf`,r=de.length;let o=!0;for(const[d,f]of _.entries()){const r=Object.create(u),l=R(e,f,n,i,a,!0===$?s:null,c,`${t}/${d}`,r);de.push(...l.errors),o=o&&l.valid,l.valid&&ue.push(r)}o?de.length=r:de.splice(r,0,{instanceLocation:c,keyword:"allOf",keywordLocation:t,error:"Instance does not match every subschema."})}if(void 0!==x){const t=`${d}/oneOf`,r=de.length,o=x.filter((r,o)=>{const d=Object.create(u),f=R(e,r,n,i,a,!0===$?s:null,c,`${t}/${o}`,d);return de.push(...f.errors),f.valid&&ue.push(d),f.valid}).length;1===o?de.length=r:de.splice(r,0,{instanceLocation:c,keyword:"oneOf",keywordLocation:t,error:`Instance does not match exactly one subschema (${o} matches).`})}if("object"!==l&&"array"!==l||Object.assign(u,...ue),void 0!==I){const t=`${d}/if`,r=Object.create(null);if(R(e,I,n,i,a,s,c,t,r).valid){if(Object.assign(u,r),void 0!==A){const r=R(e,A,n,i,a,s,c,`${d}/then`,u);r.valid||de.push({instanceLocation:c,keyword:"if",keywordLocation:t,error:'Instance does not match "then" schema.'},...r.errors)}}else if(void 0!==O){const r=R(e,O,n,i,a,s,c,`${d}/else`,u);r.valid||de.push({instanceLocation:c,keyword:"if",keywordLocation:t,error:'Instance does not match "else" schema.'},...r.errors)}}if("object"===l){if(void 0!==g)for(const n of g)z(e,n)||de.push({instanceLocation:c,keyword:"required",keywordLocation:`${d}/required`,error:`Instance does not have required property "${n}".`});const t=Object.keys(e);if(void 0!==C&&t.length<C&&de.push({instanceLocation:c,keyword:"minProperties",keywordLocation:`${d}/minProperties`,error:`Instance does not have at least ${C} properties.`}),void 0!==N&&t.length>N&&de.push({instanceLocation:c,keyword:"maxProperties",keywordLocation:`${d}/maxProperties`,error:`Instance does not have at least ${N} properties.`}),void 0!==D){const t=`${d}/propertyNames`;for(const r in e){const e=`${c}/${o(r)}`,d=R(r,D,n,i,a,s,e,t);d.valid||de.push({instanceLocation:c,keyword:"propertyNames",keywordLocation:t,error:`Property name "${r}" does not match schema.`},...d.errors)}}if(void 0!==U){const t=`${d}/dependantRequired`;for(const n in U)if(z(e,n)){const r=U[n];for(const o of r)z(e,o)||de.push({instanceLocation:c,keyword:"dependentRequired",keywordLocation:t,error:`Instance has "${n}" but does not have "${o}".`})}}if(void 0!==T)for(const[l,m]of Object.entries(T)){const t=`${d}/dependentSchemas`;if(z(e,l)){const r=R(e,m,n,i,a,s,c,`${t}/${o(l)}`,u);r.valid||de.push({instanceLocation:c,keyword:"dependentSchemas",keywordLocation:t,error:`Instance has "${l}" but does not match dependant schema.`},...r.errors)}}if(void 0!==J){const t=`${d}/dependencies`;for(const r in J)if(z(e,r)){const d=J[r];if(Array.isArray(d))for(const n of d)z(e,n)||de.push({instanceLocation:c,keyword:"dependencies",keywordLocation:t,error:`Instance has "${r}" but does not have "${n}".`});else{const u=R(e,d,n,i,a,s,c,`${t}/${o(r)}`);u.valid||de.push({instanceLocation:c,keyword:"dependencies",keywordLocation:t,error:`Instance has "${r}" but does not match dependant schema.`},...u.errors)}}}const r=Object.create(null);let f=!1;if(void 0!==S){const t=`${d}/properties`;for(const[d,l]of Object.entries(S)){if(!z(e,d))continue;const m=`${c}/${o(d)}`,h=R(e[d],l,n,i,a,s,m,`${t}/${o(d)}`);if(r[d]=!0,h.valid)u[d]=!0;else if(f=a,de.push({instanceLocation:c,keyword:"properties",keywordLocation:t,error:`Property "${d}" does not match schema.`},...h.errors),f)break}}if(!f&&void 0!==E){const t=`${d}/patternProperties`;for(const[d,l]of Object.entries(E)){const m=new RegExp(d,"u");for(const h in e){if(!m.test(h))continue;const p=`${c}/${o(h)}`,$=R(e[h],l,n,i,a,s,p,`${t}/${o(d)}`);r[h]=!0,$.valid?u[h]=!0:(f=a,de.push({instanceLocation:c,keyword:"patternProperties",keywordLocation:t,error:`Property "${h}" matches pattern "${d}" but does not match associated schema.`},...$.errors))}}}if(f||void 0===q){if(!f&&void 0!==M){const t=`${d}/unevaluatedProperties`;for(const r in e)if(!u[r]){const d=`${c}/${o(r)}`,f=R(e[r],M,n,i,a,s,d,t);f.valid?u[r]=!0:de.push({instanceLocation:c,keyword:"unevaluatedProperties",keywordLocation:t,error:`Property "${r}" does not match unevaluated properties schema.`},...f.errors)}}}else{const t=`${d}/additionalProperties`;for(const d in e){if(r[d])continue;const l=`${c}/${o(d)}`,m=R(e[d],q,n,i,a,s,l,t);m.valid?u[d]=!0:(f=a,de.push({instanceLocation:c,keyword:"additionalProperties",keywordLocation:t,error:`Property "${d}" does not match additional properties schema.`},...m.errors))}}}else if("array"===l){void 0!==K&&e.length>K&&de.push({instanceLocation:c,keyword:"maxItems",keywordLocation:`${d}/maxItems`,error:`Array has too many items (${e.length} > ${K}).`}),void 0!==X&&e.length<X&&de.push({instanceLocation:c,keyword:"minItems",keywordLocation:`${d}/minItems`,error:`Array has too few items (${e.length} < ${X}).`});const t=e.length;let o=0,f=!1;if(void 0!==F){const r=`${d}/prefixItems`,l=Math.min(F.length,t);for(;o<l;o++){const t=R(e[o],F[o],n,i,a,s,`${c}/${o}`,`${r}/${o}`);if(u[o]=!0,!t.valid&&(f=a,de.push({instanceLocation:c,keyword:"prefixItems",keywordLocation:r,error:"Items did not match schema."},...t.errors),f))break}}if(void 0!==W){const r=`${d}/items`;if(Array.isArray(W)){const d=Math.min(W.length,t);for(;o<d;o++){const t=R(e[o],W[o],n,i,a,s,`${c}/${o}`,`${r}/${o}`);if(u[o]=!0,!t.valid&&(f=a,de.push({instanceLocation:c,keyword:"items",keywordLocation:r,error:"Items did not match schema."},...t.errors),f))break}}else for(;o<t;o++){const t=R(e[o],W,n,i,a,s,`${c}/${o}`,r);if(u[o]=!0,!t.valid&&(f=a,de.push({instanceLocation:c,keyword:"items",keywordLocation:r,error:"Items did not match schema."},...t.errors),f))break}if(!f&&void 0!==B){const r=`${d}/additionalItems`;for(;o<t;o++){const t=R(e[o],B,n,i,a,s,`${c}/${o}`,r);u[o]=!0,t.valid||(f=a,de.push({instanceLocation:c,keyword:"additionalItems",keywordLocation:r,error:"Items did not match additional items schema."},...t.errors))}}}if(void 0!==Z)if(0===t&&void 0===H)de.push({instanceLocation:c,keyword:"contains",keywordLocation:`${d}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(void 0!==H&&t<H)de.push({instanceLocation:c,keyword:"minContains",keywordLocation:`${d}/minContains`,error:`Array has less items (${t}) than minContains (${H}).`});else{const r=`${d}/contains`,o=de.length;let f=0;for(let d=0;d<t;d++){const t=R(e[d],Z,n,i,a,s,`${c}/${d}`,r);t.valid?(u[d]=!0,f++):de.push(...t.errors)}f>=(H||0)&&(de.length=o),void 0===H&&0===f?de.splice(o,0,{instanceLocation:c,keyword:"contains",keywordLocation:r,error:"Array does not contain item matching schema."}):void 0!==H&&f<H?de.push({instanceLocation:c,keyword:"minContains",keywordLocation:`${d}/minContains`,error:`Array must contain at least ${H} items matching schema. Only ${f} items were found.`}):void 0!==V&&f>V&&de.push({instanceLocation:c,keyword:"maxContains",keywordLocation:`${d}/maxContains`,error:`Array may contain at most ${V} items matching schema. ${f} items were found.`})}if(!f&&void 0!==G){const r=`${d}/unevaluatedItems`;for(;o<t;o++){if(u[o])continue;const t=R(e[o],G,n,i,a,s,`${c}/${o}`,r);u[o]=!0,t.valid||de.push({instanceLocation:c,keyword:"unevaluatedItems",keywordLocation:r,error:"Items did not match unevaluated items schema."},...t.errors)}}if(Y)for(let n=0;n<t;n++){const o=e[n],i="object"==typeof o&&null!==o;for(let a=0;a<t;a++){if(n===a)continue;const t=e[a];(o===t||i&&"object"==typeof t&&null!==t&&r(o,t))&&(de.push({instanceLocation:c,keyword:"uniqueItems",keywordLocation:`${d}/uniqueItems`,error:`Duplicate items at indexes ${n} and ${a}.`}),n=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER)}}}else if("number"===l)"4"===n?(void 0!==Q&&(!0===te&&e<=Q||e<Q)&&de.push({instanceLocation:c,keyword:"minimum",keywordLocation:`${d}/minimum`,error:`${e} is less than ${te?"or equal to ":""} ${Q}.`}),void 0!==ee&&(!0===ne&&e>=ee||e>ee)&&de.push({instanceLocation:c,keyword:"maximum",keywordLocation:`${d}/maximum`,error:`${e} is greater than ${ne?"or equal to ":""} ${ee}.`})):(void 0!==Q&&e<Q&&de.push({instanceLocation:c,keyword:"minimum",keywordLocation:`${d}/minimum`,error:`${e} is less than ${Q}.`}),void 0!==ee&&e>ee&&de.push({instanceLocation:c,keyword:"maximum",keywordLocation:`${d}/maximum`,error:`${e} is greater than ${ee}.`}),void 0!==te&&e<=te&&de.push({instanceLocation:c,keyword:"exclusiveMinimum",keywordLocation:`${d}/exclusiveMinimum`,error:`${e} is less than ${te}.`}),void 0!==ne&&e>=ne&&de.push({instanceLocation:c,keyword:"exclusiveMaximum",keywordLocation:`${d}/exclusiveMaximum`,error:`${e} is greater than or equal to ${ne}.`})),void 0!==re&&(function(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;const[n,r]=j(e),[o,i]=j(t),a=r-i;return a>=0?n*10n**BigInt(a)%o===0n:n%(o*10n**BigInt(-a))===0n}(e,re)||de.push({instanceLocation:c,keyword:"multipleOf",keywordLocation:`${d}/multipleOf`,error:`${e} is not a multiple of ${re}.`}));else if("string"===l){const t=void 0===oe&&void 0===ie?0:function(e){let t,n=0,r=e.length,o=0;for(;o<r;)n++,t=e.charCodeAt(o++),t>=55296&&t<=56319&&o<r&&(t=e.charCodeAt(o),56320==(64512&t)&&o++);return n}(e);void 0!==oe&&t<oe&&de.push({instanceLocation:c,keyword:"minLength",keywordLocation:`${d}/minLength`,error:`String is too short (${t} < ${oe}).`}),void 0!==ie&&t>ie&&de.push({instanceLocation:c,keyword:"maxLength",keywordLocation:`${d}/maxLength`,error:`String is too long (${t} > ${ie}).`}),void 0===ae||new RegExp(ae,"u").test(e)||de.push({instanceLocation:c,keyword:"pattern",keywordLocation:`${d}/pattern`,error:"String does not match pattern."}),void 0!==P&&L[P]&&!L[P](e)&&de.push({instanceLocation:c,keyword:"format",keywordLocation:`${d}/format`,error:`String does not match format "${P}".`})}return{valid:0===de.length,errors:de}}var P=class{schema;draft;shortCircuit;lookup;constructor(e,t="2019-09",n=!0){this.schema=e,this.draft=t,this.shortCircuit=n,this.lookup=m(e)}validate(e){return R(e,this.schema,this.draft,this.lookup,this.shortCircuit)}addSchema(e,t){t&&(e={...e,$id:t}),m(e,this.lookup)}},S=0,E=[],q=new Set,M=8192;function C(e){if(null==e||"number"==typeof e||"boolean"==typeof e)return e;if("string"==typeof e)return e.length<=M?e:`${e.slice(0,M)}… [truncated, ${e.length} chars total]`;let t;try{t=JSON.stringify(e)??String(e)}catch{return"[unserializable]"}return t.length<=M?e:`${t.slice(0,M)}… [truncated, ${t.length} chars total]`}function N(e){const t={id:++S,...e,input:C(e.input),result:C(e.result)};E.push(t),E.length>500&&E.splice(0,E.length-500);for(const r of q)try{r(t)}catch(n){console.error("[commandLog] a subscriber failed:",n)}}function D(e){if(null==e)return"";if("string"==typeof e)return e;try{return JSON.stringify(e)}catch{return String(e)}}function U(e={}){let t=E.slice();if(e.surface&&(t=t.filter(t=>t.surface===e.surface)),e.outcome&&(t=t.filter(t=>t.outcome===e.outcome)),e.text){const n=e.text.toLowerCase();t=t.filter(e=>function(e){return`${e.name} ${e.error??""} ${D(e.input)} ${D(e.result)}`.toLowerCase()}(e).includes(n))}return e.limit&&t.length>e.limit&&(t=t.slice(t.length-e.limit)),t}function T(){E.length=0}var J=new Map,F=new Map;function W(e,t,n){const r=function(e){const t=e,n=t?.properties;if(!n)return null;const r=Object.keys(n);if(0===r.length)return"none — this action takes no input";const o=new Set(t?.required??[]);return[...r].sort((e,t)=>{const n=o.has(e)?0:1,r=o.has(t)?0:1;return n!==r?n-r:e.localeCompare(t)}).map(e=>o.has(e)?`${e} (required)`:e).join(", ")}(n),o=r?` Accepted: ${r}.`:"";if(!t||0===t.length)return`Invalid input for ${e}.${o}`;const i=function(e){const t=e.find(e=>"additionalProperties"===e.keyword)??e.find(e=>"required"===e.keyword);return t||e.reduce((e,t)=>(t.instanceLocation?.length??0)>(e.instanceLocation?.length??0)?t:e)}(t),a=function(e){const t=/Property "([^"]+)" does not match additional properties schema/.exec(e);if(t)return`unknown property "${t[1]}"`;const n=/does not have required property "([^"]+)"/.exec(e);return n?`missing required property "${n[1]}"`:e.replace(/\.$/,"")}(i.error??"failed validation"),s=i.instanceLocation;return`Invalid input for ${e}: ${a}${s&&"#"!==s?` at ${s.replace(/^#/,"")}`:""}.${o}`}function B(e,t){const n=function(e){if(!e.input_schema)return null;const t=F.get(e.id);if(t)return t;try{const t=new P(e.input_schema,"2020-12");return F.set(e.id,t),t}catch{return null}}(e);if(!n)return;const r=n.validate(t??{});if(!r.valid)throw new Error(W(e.id,r.errors,e.input_schema))}function G(e){if(!e.id)throw new Error("[actionRegistry] ActionDef.id is required");if(J.has(e.id))throw new Error(`[actionRegistry] Duplicate id "${e.id}" — actions must be globally unique`);if(!e.title)throw new Error(`[actionRegistry] ActionDef "${e.id}": title is required (string or () => string)`);if(!e.category)throw new Error(`[actionRegistry] ActionDef "${e.id}": category is required`);if(!e.run&&!e.mcpRun)throw new Error(`[actionRegistry] ActionDef "${e.id}": at least one of \`run\` or \`mcpRun\` must be set`);if(e.mcpRun&&!e.input_schema)throw new Error(`[actionRegistry] ActionDef "${e.id}": \`mcpRun\` requires \`input_schema\``);J.set(e.id,e)}function Z(e){return J.get(e)}function H(){return Array.from(J.values())}async function V(e,r,o,i,a){const s=Date.now(),c=performance.now();try{const d=await i();return N({ts:s,surface:r,name:e.id,input:o,origin:a,outcome:"completed",durationMs:Math.round(performance.now()-c),result:e.forwards?"→ result is in the forwarded action's own entry (the one just before this)":t(d)?n(d):d}),d}catch(d){throw N({ts:s,surface:r,name:e.id,input:o,origin:a,outcome:"failed",durationMs:Math.round(performance.now()-c),error:d instanceof Error?d.message:String(d)}),d}}function X(){return Array.from(J.values()).filter(e=>!!e.run||!!e.mcpRun).map(e=>{const t=function(e){const t=e.input_schema,n=t?.properties;if(!n)return[];const r=new Set(t?.required??[]);return Object.entries(n).map(([e,t])=>{const n=Array.isArray(t.type)?t.type.find(e=>"null"!==e):t.type,o="string"===n||"number"===n||"integer"===n||"boolean"===n?n:"other",i=Array.isArray(t.enum)?t.enum.filter(e=>"string"==typeof e||"number"==typeof e):void 0;return{name:e,type:o,required:r.has(e),description:"string"==typeof t.description?t.description:void 0,options:i,default:t.default}})}(e),n=t.some(e=>e.required);return{id:e.id,title:"function"==typeof e.title?e.title():e.title,description:e.description,category:e.category,shortcut:e.shortcut,when:e.when,run:n?void 0:e.run?()=>Q(e.id,V(e,"palette",void 0,()=>e.run())):()=>Q(e.id,V(e,"palette",void 0,()=>e.mcpRun(void 0))),params:t,runWith:t=>Q(e.id,V(e,"palette",t,()=>(B(e,t),e.mcpRun?e.mcpRun(t):e.run())))}})}async function K(e,t,n){const r=J.get(e);if(!r)throw new Error(`Unknown action: ${e}`);if(!r.mcpRun)throw new Error(`Action "${e}" is not MCP-callable`);return V(r,n?.surface??"mcp",t,()=>(B(r,t),r.mcpRun(t)))}async function Y(e,t,n){const r=n?.origin,o=n?.surface??"palette";try{const n=J.get(e);if(!n)throw new Error(`Unknown action: ${e}`);if(void 0!==t&&n.mcpRun)return await V(n,o,t,()=>n.mcpRun(t),r);if(n.run)return await V(n,o,void 0,()=>n.run(),r);if(n.mcpRun)return await V(n,o,void 0,()=>n.mcpRun(void 0),r);throw new Error(`Action "${e}" has neither run nor mcpRun`)}catch(i){throw te(e,i),i}}function Q(e,t){return t.catch(t=>{throw te(e,t),t})}var ee=new Map;function te(t,n){const r=Date.now();if(r-(ee.get(t)??0)<2e3)return;ee.set(t,r);const o=n instanceof Error&&"ActionRefusal"===n.name;e({kind:o?"warning":"error",title:o?`Not done: ${t}`:`Action failed: ${t}`,description:n instanceof Error?n.message:String(n),durationMs:6e3})}function ne(){return J.size}function re(){J.clear(),F.clear()}export{G as a,Y as c,N as d,t as f,X as i,T as l,Z as n,ne as o,n as p,H as r,re as s,K as t,U as u};
@@ -0,0 +1 @@
1
+ var t=(t,e)=>null===t.stepTime(0)?e:e+1;function e(t,e,n,s){const r=t.stepTime(e),u=t.stepDuration()??15/n;return{t0:r,dur:u,stale:null!==r&&r<s-u}}export{e as n,t};
@@ -0,0 +1 @@
1
+ import"./src-DyDfRe65.js";import{o as t}from"./faustSource-Blr9zzKL.js";import{n as s}from"./preArm-ifXM2Buj.js";import{C as n,S as e,_ as o,a as u,b as i,d as r,g as p,h as a,i as c,m as d,o as l,r as f,t as m,v as h,x as g,y as b}from"./instantiate-Dh0T46aH.js";var w={"":{select2:{inputs:3,outputs:1},select3:{inputs:4,outputs:1},attach:{inputs:2,outputs:1},max:{inputs:2,outputs:1},min:{inputs:2,outputs:1},pow:{inputs:2,outputs:1},abs:{inputs:1,outputs:1},floor:{inputs:1,outputs:1},ceil:{inputs:1,outputs:1},round:{inputs:1,outputs:1},sqrt:{inputs:1,outputs:1},exp:{inputs:1,outputs:1},log:{inputs:1,outputs:1},sin:{inputs:1,outputs:1},cos:{inputs:1,outputs:1},tan:{inputs:1,outputs:1},int:{inputs:1,outputs:1},float:{inputs:1,outputs:1},hslider:{inputs:0,outputs:1},vslider:{inputs:0,outputs:1},button:{inputs:0,outputs:1},checkbox:{inputs:0,outputs:1},nentry:{inputs:0,outputs:1},hbargraph:{inputs:1,outputs:1},vbargraph:{inputs:1,outputs:1}},os:{osc:{inputs:1,outputs:1},sawtooth:{inputs:1,outputs:1},triangle:{inputs:1,outputs:1},square:{inputs:1,outputs:1},phasor:{inputs:2,outputs:1}},no:{noise:{inputs:0,outputs:1},pink_noise:{inputs:0,outputs:1},colored_noise:{inputs:1,outputs:1}},re:{mono_freeverb:{inputs:1,outputs:1},stereo_freeverb:{inputs:2,outputs:2},zita_rev1_stereo:{inputs:2,outputs:2},jcrev:{inputs:1,outputs:4},satrev:{inputs:1,outputs:2},dattorro_rev_default:{inputs:2,outputs:2},springreverb:{inputs:1,outputs:1},greyhole:{inputs:2,outputs:2},jpverb:{inputs:2,outputs:2}},fi:{lowpass:{inputs:1,outputs:1},highpass:{inputs:1,outputs:1},bandpass:{inputs:1,outputs:1},resonbp:{inputs:1,outputs:1},peak_eq:{inputs:1,outputs:1},low_shelf:{inputs:1,outputs:1},high_shelf:{inputs:1,outputs:1},dcblocker:{inputs:1,outputs:1},fb_fcomb:{inputs:1,outputs:1},nlf2:{inputs:1,outputs:1},peakholder:{inputs:1,outputs:1}},an:{amp_follower:{inputs:1,outputs:1},amp_follower_ar:{inputs:1,outputs:1},rms_envelope_t60:{inputs:1,outputs:1},pitchTracker:{inputs:1,outputs:1},spectralCentroid:{inputs:1,outputs:1},zcr:{inputs:1,outputs:1}},ba:{tau2pole:{inputs:0,outputs:1},linear2db:{inputs:1,outputs:1},db2linear:{inputs:1,outputs:1},hz2midikey:{inputs:1,outputs:1},midikey2hz:{inputs:1,outputs:1},selectn:{inputs:1,outputs:1},bitcrusher:{inputs:1,outputs:1},downSample:{inputs:1,outputs:1},if:{inputs:3,outputs:1},peakholder:{inputs:1,outputs:1}},si:{smooth:{inputs:1,outputs:1}},de:{delay:{inputs:1,outputs:1},fdelay4:{inputs:1,outputs:1}},ef:{cubicnl:{inputs:1,outputs:1},gate_mono:{inputs:1,outputs:1},transpose:{inputs:1,outputs:1},wavefold:{inputs:1,outputs:1}},en:{adsr:{inputs:1,outputs:1},ar:{inputs:1,outputs:1}},co:{compressor_mono:{inputs:1,outputs:1},compression_gain_mono:{inputs:1,outputs:1}},pf:{flanger_mono:{inputs:1,outputs:1},phaser2_mono:{inputs:1,outputs:1}},pm:{ks:{inputs:1,outputs:1},f2l:{inputs:1,outputs:1},impulseExcitation:{inputs:1,outputs:1},standardBell:{inputs:1,outputs:1}},qu:{quantize:{inputs:1,outputs:1},ionian:{inputs:1,outputs:1},dorian:{inputs:1,outputs:1},phrygian:{inputs:1,outputs:1},lydian:{inputs:1,outputs:1},locrian:{inputs:1,outputs:1}},ve:{moog_vcf_2bn:{inputs:1,outputs:1},diodeLadder:{inputs:1,outputs:1},korg35LPF:{inputs:1,outputs:1},oberheimLPF:{inputs:1,outputs:1}},ma:{SR:{inputs:0,outputs:1},tanh:{inputs:1,outputs:1},log2:{inputs:1,outputs:1}}};function $(t,s){return w[t]?.[s]}function y(t){switch(t.tag){case"wire":case"hbargraph":case"vbargraph":return{inputs:1,outputs:1};case"cut":return{inputs:1,outputs:0};case"real":case"int":case"hslider":case"vslider":case"numEntry":case"button":case"checkbox":return{inputs:0,outputs:1};case"add":case"sub":case"mul":case"div":return{inputs:2,outputs:1};case"plus":case"minus":case"times":case"over":case"mod":case"lt":case"gt":case"le":case"ge":case"eq":case"ne":{const s=y(t.a);return{inputs:s.inputs,outputs:s.outputs}}case"neg":case"intCast":case"floatCast":case"mem":{const s=y(t.a);return{inputs:s.inputs,outputs:s.outputs}}case"select2":return y(t.then);case"prim":{const s=$("",t.name);if(s)return s;throw new Error(`unknown bare-name primitive "${t.name}"; add it to packages/faust-box/src/stdfaust-arity.ts under namespace ''`)}case"attach":return y(t.a);case"seq":{const s=y(t.a),n=y(t.b);return{inputs:s.inputs,outputs:n.outputs}}case"par":{const s=y(t.a),n=y(t.b);return{inputs:s.inputs+n.inputs,outputs:s.outputs+n.outputs}}case"split":{const s=y(t.a),n=y(t.b);return{inputs:s.inputs,outputs:n.outputs}}case"merge":{const s=y(t.a),n=y(t.b);return{inputs:s.inputs,outputs:n.outputs}}case"rec":{const s=y(t.a),n=y(t.b);return{inputs:s.inputs-n.outputs,outputs:s.outputs}}case"libCall":{const s=$(t.ns,t.name);if(s)return s;throw new Error(`unknown stdfaust arity for ${t.ns}.${t.name}; add it to packages/faust-box/src/stdfaust-arity.ts`)}case"raw":return t.arity;case"parLoop":{const s=y(t.body);return{inputs:s.inputs*t.count,outputs:s.outputs*t.count}}case"withDefs":return y(t.main)}}var v=t=>t.data?.kind,k=t=>{const s=l(v(t)??"")?.midi;return"notes"===s?.listens?s:null};function _(t,s){return s||t.some(t=>null!==k(t))}function x(t){return t.some(t=>"input"===v(t))}function M(t){for(const s of t){const t=k(s);if(!t?.channelParam)continue;const n=s.data;return Math.round(n?.paramValues?.[t.channelParam]??0)}return 0}function S(t,n){return s(M(t),n)}function I(t){return"n_"+t.replace(/[^a-zA-Z0-9_]/g,"_")}var E=new Set(["hslider","vslider","nentry","checkbox"]);function j(t){return E.has(t.type)&&!t.recompileOnChange&&!t.controlPlane}function V(t,s,n){return C(t.map(t=>{const s=t.data,n=s?.kind?l(s.kind):void 0;if(!n||!s?.paramValues)return t;const e={};for(const[o,u]of Object.entries(s.paramValues)){const t=n.params.find(t=>t.id===o);t&&j(t)||(e[o]=u)}return{...t,data:{...s,paramValues:e}}}),s,n).source}function q(t,s){return s||(t.some(t=>!0===l(t.data?.kind??"")?.midi?.voice)?{voices:1}:void 0)}function C(t,s,u){u=q(t,u);const r=[];if(u){const s=t.filter(t=>{const s=t.data?.kind;return!!s&&!0===l(s)?.midi?.voice}).length;s>1&&r.push(`Polyphonic patch has ${s} midi_note nodes — must have at most 1. In poly mode the runtime per-voice-replicates the magic-name sliders, so multiple midi_note nodes collapse to a single shared MIDI source. Remove the extras or switch back to mono mode.`)}const c=new Map;for(const n of s)n.targetHandle&&n.sourceHandle&&(c.has(n.target)||c.set(n.target,new Map),c.get(n.target).set(n.targetHandle,{src:n.source,srcHandle:n.sourceHandle}));const f=new Map(t.map(t=>[t.id,t])),m=function(t){const s=new Set;for(const n of t){const t=n.data;if(!t?.kind)continue;const e=l(t.kind);if(e?.imports)for(const n of e.imports)"stdfaust.lib"!==n&&s.add(n)}return[...s].sort()}(t),w=M(t),$=new Map;for(const n of t){const t=n.parentId;if(!t)continue;const s=f.get(t);if(!s)continue;const e=s.data?.label;e&&e.trim().length>0&&$.set(n.id,e)}const v=new Map,k=new Map;for(const n of t){const t=n.parentId;t&&$.has(n.id)&&k.set(n.id,t)}const _=new Map,x=new Set;for(const n of s)n.sourceHandle&&x.add(`${n.source}.${n.sourceHandle}`);for(const n of s)_.has(n.source)||_.set(n.source,[]),_.get(n.source).push(n.target);for(const n of t){if(!$.has(n.id))continue;const t=k.get(n.id),s=_.get(n.id)??[];if(0===s.length){v.set(n.id,!0);continue}let e=!1;for(const n of s)if(k.get(n)!==t){e=!0;break}e&&v.set(n.id,!0)}const S=t.filter(t=>{const s=t.data;if(!s?.kind)return!1;const n=l(s.kind);return!!n&&0===n.outputs.length});if(0===S.length)return{source:H(u,m,w)+"\nprocess = 0, 0; // no sink node placed yet\n",errors:['No sink node in graph (need an "output" node)']};S.length>1&&r.push("Multiple sink nodes — only the first is used.");const E=S[0],j={...N(l(E.data?.kind??"")),...E.data?.paramValues??{}},V={voices:Math.max(1,Math.round(j.unison_voices??1)),detune_cents:j.unison_detune_cents??0,stereo_spread:j.unison_stereo_spread??0},C=t.some(t=>"input"===t.data?.kind),z=u?.voices??1,A=z*V.voices;A>16&&r.push(`warning: total voice count ${z} (poly) × ${V.voices} (unison) = ${A} exceeds the 16-voice soft-cap. Audio may glitch under load.`);const P=new Set,F=new Set,D=[];let L=null;const J=new Map,R=I;!function t(s){if(F.has(s))return R(s);if(P.has(s))return r.push(`Cycle detected at node "${s}" — graph must be acyclic`),null;P.add(s);const n=f.get(s);if(!n)return r.push(`Edge references unknown node "${s}"`),P.delete(s),null;const e=n.data;if(!e?.kind)return r.push(`Node "${s}" has no kind`),P.delete(s),null;const o=l(e.kind);if(!o)return r.push(`Unknown node kind "${e.kind}" on node "${s}"`),P.delete(s),null;const i={},p=c.get(s);for(const u of o.inputs){const s=p?.get(u.id);if(s){const n=t(s.src);i[u.id]=n?`${n}_${s.srcHandle}`:""}else i[u.id]=""}const a=R(s);let m,h=null;if(o.bypass&&e.bypassed){const t=i[o.bypass.input]||"0";m={[o.bypass.output]:t};for(const s of o.outputs)s.id in m||(m[s.id]="0")}else{const t={params:{...N(o),...e.paramValues},refs:e.refValues??{},inputs:i,faustId:a,polyMode:!!u,unisonConfig:V,isFxShape:C};try{h=o.toBox(t),m={};for(const[t,s]of Object.entries(h))m[t]=d(s)}catch(y){const t=y instanceof Error?y.message:String(y);r.push(`Node "${e.kind}" (id: ${s}) failed to compile: ${t}`),h=null,m={};for(const s of o.outputs)m[s.id]="0"}}const b=$.get(s),w=t=>{return b&&v.get(s)&&O.test(t)?`vgroup("${n=b,n.replace(/[\x00-\x1f]/g," ").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}", ${t})`:t;var n};for(const[u,c]of Object.entries(m)){if("__process"===u){null!==L&&r.push("Multiple sink expressions encountered");const t=w(c);L=t;const n=h?.__process??g(c,{inputs:C?1:0,outputs:1});J.set(s,{expr:t,box:n});continue}x.has(`${s}.${u}`)&&D.push({name:`${a}_${u}`,expr:w(c)})}return P.delete(s),F.add(s),a}(E.id);const B=C,G=J.get(E.id)?.box,T=G?y(G).outputs:1;let U;U=null!==L?T>=2?L:`${L} <: _, _`:"0, 0";let W;if(V.voices>1&&!B&&null!==L)W=function(t){const{sinkExpr:s,sinkOutputs:u,defs:r,unisonConfig:c,polyConfig:l,extraImports:f,channel:m}=t,w=c.voices,$=c.stereo_spread,y=r.map(t=>({name:t.name,body:g(t.expr,{inputs:0,outputs:1})}));let v,k;if(u>=2)k=[{name:"scale",body:g(`1.0 / sqrt(${w})`,{inputs:0,outputs:1})},...y,{name:"sinkStereo",body:g(s,{inputs:0,outputs:2})}],v=o(g("sinkStereo",{inputs:0,outputs:2}),p(g("*(scale)",{inputs:1,outputs:1}),g("*(scale)",{inputs:1,outputs:1})));else{k=[{name:"panV",body:g(`((i / ${1===w?1:w-1}.0) - 0.5) * 2 * ${$}`,{inputs:0,outputs:1})},{name:"L",body:g(`sqrt((1 - panV) / 2) / sqrt(${w})`,{inputs:0,outputs:1})},{name:"R",body:g(`sqrt((1 + panV) / 2) / sqrt(${w})`,{inputs:0,outputs:1})},...y,{name:"sinkMono",body:g(s,{inputs:0,outputs:1})}],v=h(g("sinkMono",{inputs:0,outputs:1}),p(g("*(L)",{inputs:1,outputs:1}),g("*(R)",{inputs:1,outputs:1})))}const _=n(k,v),x=g("i",{inputs:0,outputs:1}),M=b("i",w,i("voice",x)),S=a(M,p(e(),e())),I=n([{name:"voice",params:["i"],body:_}],S);return`${H(l,f,m)}\nprocess = ${d(I)};\n`}({sinkExpr:L,sinkOutputs:T,defs:D,unisonConfig:V,polyConfig:u,extraImports:m,channel:w});else if(B){const t=g(U,{inputs:2,outputs:2}),s=n(D.map(t=>({name:t.name,body:g(t.expr,{inputs:0,outputs:1})})),t);W=`${H(u,m,w)}\nprocess(in_l, in_r) = ${d(s)};\n`}else{const t=D.map(t=>`${t.name} = ${t.expr};`).join("\n");W=`${H(u,m,w)}\n${t}\n\nprocess = ${U};\n`}return{source:W,errors:r}}function H(t,s=[],n=0){const e=(t?`[nvoices:${t.voices}]`:"")+(n>=1&&n<=16?`[midichannel:${n}]`:"");return`// Generated from graph — do not edit by hand for now.\n${e?`declare options "${e}";\n`:""}import("stdfaust.lib");\n${s.length>0?s.map(t=>`import("${t}");`).join("\n")+"\n":""}`}var O=/\b(?:hslider|vslider|nentry|button|checkbox|hbargraph|vbargraph)\b/;function N(t){if(!t)return{};const s={};for(const n of t.params)s[n.id]=n.init;return s}var z="builder";function A(s,n,e,o,u,i){const r=s.filter(t=>t.type!==m),p=s.filter(t=>t.type===m).map(t=>{const s=t.data,n=t.width,e=t.height,o=P(t.style,"width"),u=P(t.style,"height"),i=t.measured;return{id:t.id,position:{x:t.position.x,y:t.position.y},size:{width:n??i?.width??o??320,height:e??i?.height??u??200},label:s?.label??"Group"}});return{format:z,version:2,...e?{meta:e}:{},nodes:r.map(t=>{const s=t.data,n={id:t.id,kind:D(t),position:{x:t.position.x,y:t.position.y},params:s?.paramValues??{}};if(!0===s?.bypassed&&(n.bypassed=!0),s?.refValues){const t={};let e=!1;for(const[n,o]of Object.entries(s.refValues))o&&o.length>0&&(t[n]=o,e=!0);e&&(n.refs=t)}const e=t.parentId;return e&&(n.parentId=e),n}),edges:n.map(t=>({id:t.id,source:{node:t.source,port:L(t,"source")},target:{node:t.target,port:L(t,"target")}})),...p.length>0?{groups:p}:{},...void 0!==o?{compiledSource:o,isFx:t(o)}:{},...u&&u.length>0?{samples:u}:{},...i?{polyphonic:i}:{}}}function P(t,s){if(!t)return;const n=t.match(new RegExp(`${s}\\s*:\\s*([0-9.]+)`));if(!n)return;const e=parseFloat(n[1]);return Number.isFinite(e)?e:void 0}function F(t){return JSON.stringify(t,null,2)}function D(t){const s=t.data?.kind;if(!s)throw new Error(`Node "${t.id}" has no kind — it cannot be written.`);return s}function L(t,s){const n="source"===s?t.sourceHandle:t.targetHandle;if(!n)throw new Error(`Edge "${t.id}" has no ${s} port — it cannot be written.`);return n}var J=class extends Error{constructor(t){super(t),this.name="BuilderParseError"}};function R(t){let s;try{s=JSON.parse(t)}catch(n){throw new J(`Invalid JSON: ${n.message}`)}return function(t){if(!t||"object"!=typeof t)throw new J("Document is not an object");const s=t;if("builder"!==s.format)throw new J(`Wrong format: expected "${z}", got "${s.format}"`);if("number"!=typeof s.version)throw new J("Missing version");if(s.version<1||s.version>2)throw new J(`Document version ${s.version} is newer than supported (2). Upgrade the app.`);if(!Array.isArray(s.nodes))throw new J("nodes is not an array");if(!Array.isArray(s.edges))throw new J("edges is not an array");for(const n of s.nodes)if(!n.id||!n.kind||!n.position)throw new J(`Malformed node entry: ${JSON.stringify(n)}`);for(const n of s.edges)if(!n.id||!n.source?.node||!n.target?.node)throw new J(`Malformed edge entry: ${JSON.stringify(n)}`);return s}(s)}function B(t){const{doc:s,notes:n}=function(t){if(t.version>=2)return{doc:t,notes:[]};const s=[],n=new Map(t.nodes.map(t=>[t.id,t.kind])),e=t.edges.map(t=>{let{source:e,target:o}=t;return"in"===o.port&&"output"===n.get(o.node)&&(o={...o,port:"in_l"},s.push(`cable ${t.id} into ${o.node}.in now goes to in_l`)),"out"===e.port&&"input"===n.get(e.node)&&(e={...e,port:"out_l"},s.push(`cable ${t.id} from ${e.node}.out now comes from out_l`)),{...t,source:e,target:o}}),o=new Map;for(const i of e)o.set(`${i.target.node}.${i.target.port}`,i.id);const u=e.filter(t=>{const n=`${t.target.node}.${t.target.port}`;return o.get(n)===t.id||(s.push(`cable ${t.id} into ${n} removed — ${o.get(n)} was the one playing there`),!1)});return{doc:{...t,version:2,edges:u},notes:s}}(t),e=[],o=[],i=[],r=new Set;for(const u of s.groups??[])r.add(u.id),i.push(f({id:u.id,position:u.position,size:u.size,label:u.label}));const p=new Map;for(const u of s.nodes){const t=I(u.id),s=p.get(t);void 0!==s?e.push(`Nodes ${s} and ${u.id} share one Faust name (${t}) — rename one`):p.set(t,u.id)}for(const l of s.nodes){const t=c(l.kind,{id:l.id,position:l.position,params:l.params,refs:l.refs,bypassed:l.bypassed});if(!t){const t={inputs:[...new Set(s.edges.filter(t=>t.target.node===l.id).map(t=>t.target.port))],outputs:[...new Set(s.edges.filter(t=>t.source.node===l.id).map(t=>t.source.port))]};o.push(`${l.id} (${l.kind})`);const n=u(l.kind,{id:l.id,position:l.position,params:l.params,refs:l.refs,bypassed:l.bypassed},t);l.parentId&&r.has(l.parentId)&&(n.parentId=l.parentId,n.extent="parent"),i.push(n);continue}l.parentId&&r.has(l.parentId)&&(t.parentId=l.parentId,t.extent="parent"),i.push(t)}const a=new Map,d=[];for(const u of s.edges){const t=`${u.target.node}.${u.target.port}`,s=a.get(t);s?e.push(`Two cables into ${t} (${s}, ${u.id}) — an input takes one cable`):(a.set(t,u.id),d.push({id:u.id,source:u.source.node,sourceHandle:u.source.port,target:u.target.node,targetHandle:u.target.port}))}return{nodes:i,edges:d,warnings:e,notes:n,missing:o}}var G=null;function T(t){G=t}function U(){if(!G)throw new Error("[extension-dsp-builder] IDEAPI not initialized. Did the factory run?");return G}var W=new Map;function Z(t){const s=W.get(t);if(s)return s;const n=U().log.create(t);return W.set(t,n),n}export{R as a,F as c,I as d,q as f,M as g,S as h,J as i,V as l,_ as m,Z as n,B as o,x as p,T as r,A as s,U as t,C as u};
@@ -0,0 +1 @@
1
+ import{t as e}from"./instantiate-Dh0T46aH.js";var t=Object.defineProperty,n=(e,n,r)=>((e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r)(e,"symbol"!=typeof n?n+"":n,r),r={};((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(r,{Graph:()=>D,alg:()=>p});var i=Object.defineProperty,o=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},s=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=!("directed"in e)||e.directed,this._isMultigraph="multigraph"in e&&e.multigraph,this._isCompound="compound"in e&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn="function"!=typeof e?()=>e:e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>0===Object.keys(this._in[e]).length)}sinks(){return this.nodes().filter(e=>0===Object.keys(this._out[e]).length)}setNodes(e,t){return e.forEach(e=>{void 0!==t?this.setNode(e,t):this.setNode(e)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t="\0";else{for(let n=t+="";void 0!==n;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if("\0"!==t)return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if("\0"===e)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t),r=this.successors(e);if(r)for(let e of r)n.add(e);return Array.from(n.values())}}isLeaf(e){var t;let n;return n=this.isDirected()?this.successors(e):this.neighbors(e),0===(null!=(t=null==n?void 0:n.length)?t:0)}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i,i):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn="function"!=typeof e?()=>e:e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(void 0!==t?this.setEdge(e,n,t):this.setEdge(e,n),n)),this}setEdge(e,t,n,r){let i,o,s,l,h=!1;"object"==typeof e&&null!==e&&"v"in e?(i=e.v,o=e.w,s=e.name,2===arguments.length&&(l=t,h=!0)):(i=e,o=t,s=r,arguments.length>2&&(l=n,h=!0)),i=""+i,o=""+o,void 0!==s&&(s=""+s);let u=a(this._isDirected,i,o,s);if(u in this._edgeLabels)return h&&(this._edgeLabels[u]=l),this;if(void 0!==s&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(i),this.setNode(o),this._edgeLabels[u]=h?l:this._defaultEdgeLabelFn(i,o,s);let c=function(e,t,n,r){let i=""+t,o=""+n;if(!e&&i>o){let e=i;i=o,o=e}let s={v:i,w:o};return r&&(s.name=r),s}(this._isDirected,i,o,s);return i=c.v,o=c.w,Object.freeze(c),this._edgeObjs[u]=c,d(this._preds[o],i),d(this._sucs[i],o),this._in[o][u]=c,this._out[i][u]=c,this._edgeCount++,this}edge(e,t,n){let r=1===arguments.length?h(this._isDirected,e):a(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=1===arguments.length?this.edge(e):this.edge(e,t,n);return"object"!=typeof r||null===r?{label:r}:r}hasEdge(e,t,n){return(1===arguments.length?h(this._isDirected,e):a(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=1===arguments.length?h(this._isDirected,e):a(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],l(this._preds[t],e),l(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function d(e,t){e[t]?e[t]++:e[t]=1}function l(e,t){void 0!==e[t]&&! --e[t]&&delete e[t]}function a(e,t,n,r){let i=""+t,o=""+n;if(!e&&i>o){let e=i;i=o,o=e}return i+""+o+""+(void 0===r?"\0":r)}function h(e,t){return a(e,t.v,t.w,t.name)}function u(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:c(e),edges:f(e)},n=e.graph();return void 0!==n&&(t.value=structuredClone(n)),t}function c(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return void 0!==n&&(i.value=n),void 0!==r&&(i.parent=r),i})}function f(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==n&&(r.value=n),r})}function g(e){let t=new s(e.options);return void 0!==e.value&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}o({},{read:()=>g,write:()=>u});var p={};o(p,{CycleException:()=>j,bellmanFord:()=>w,components:()=>b,dijkstra:()=>y,dijkstraAll:()=>_,findCycles:()=>O,floydWarshall:()=>N,isAcyclic:()=>C,postorder:()=>S,preorder:()=>P,prim:()=>F,shortestPaths:()=>R,tarjan:()=>k,topsort:()=>I});var v=()=>1;function w(e,t,n,r){return function(e,t,n,r){let i,o={},s=0,d=e.nodes(),l=function(e){let t=o[e.v],r=o[e.w];if(!t||!r)return;let s=n(e);t.distance+s<r.distance&&(o[e.w]={distance:t.distance+s,predecessor:e.v},i=!0)},a=function(){d.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;l({v:n,w:r})})})};d.forEach(function(e){o[e]={distance:e===t?0:Number.POSITIVE_INFINITY,predecessor:""}});let h=d.length;for(let u=1;u<h&&(i=!1,s++,a(),i);u++);if(s===h-1&&(i=!1,a(),i))throw new Error("The graph contains a negative weight cycle");return o}(e,String(t),n||v,r||function(t){var n;return null!=(n=e.outEdges(t))?n:[]})}function b(e){let t,n={},r=[];function i(r){var o,s;r in n||(n[r]=!0,t.push(r),null==(o=e.successors(r))||o.forEach(i),null==(s=e.predecessors(r))||s.forEach(i))}return e.nodes().forEach(function(e){t=[],i(e),t.length&&r.push(t)}),r}var m=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){if(0===this.size())throw new Error("Queue underflow");this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(void 0===n)throw new Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t,n=this._arr,r=n[e].priority;for(;0!==e&&(t=e>>1,!(n[t].priority<r));)this._swap(e,t),e=t}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],o=n[t];n[e]=o,n[t]=i,r[o.key]=e,r[i.key]=t}},E=()=>1;function y(e,t,n,r){return function(e,t,n,r){let i,o,s={},d=new m,l=function(e){let t=e.v!==i?e.v:e.w,r=s[t];if(!r)return;let l=n(e),a=o.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+l);a<r.distance&&(r.distance=a,r.predecessor=i,d.decrease(t,a))};for(e.nodes().forEach(function(e){let n=e===t?0:Number.POSITIVE_INFINITY;s[e]={distance:n,predecessor:""},d.add(e,n)});d.size()>0;){i=d.removeMin();let e=s[i];if(!e||e.distance===Number.POSITIVE_INFINITY)break;o=e,r(i).forEach(l)}return s}(e,String(t),n||E,r||function(t){var n;return null!=(n=e.outEdges(t))?n:[]})}function _(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=y(e,i,t,n),r},{})}function k(e){let t=0,n=[],r={},i=[];function o(s){var d;let l=r[s]={onStack:!0,lowlink:t,index:t++};if(n.push(s),null==(d=e.successors(s))||d.forEach(function(e){if(e in r){let t=r[e];null!=t&&t.onStack&&(l.lowlink=Math.min(l.lowlink,t.index))}else{o(e);let t=r[e];t&&(l.lowlink=Math.min(l.lowlink,t.lowlink))}}),l.lowlink===l.index){let e,t=[];do{e=n.pop();let i=r[e];i&&(i.onStack=!1),t.push(e)}while(s!==e);i.push(t)}}return e.nodes().forEach(function(e){e in r||o(e)}),i}function O(e){return k(e).filter(function(t){var n;let r=t[0];return!!r&&(t.length>1||1===t.length&&(null!=(n=e.outEdges(r,r))?n:[]).length>0)})}var x=()=>1;function N(e,t,n){return function(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){let o={};r[e]=o,o[e]={distance:0,predecessor:""},i.forEach(function(t){e!==t&&(o[t]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(e).forEach(function(n){let r=n.v===e?n.w:n.v,i=t(n);o[r]={distance:i,predecessor:e}})}),i.forEach(function(e){let t=r[e];t&&i.forEach(function(n){let o=r[n];o&&i.forEach(function(n){let r=o[e],i=t[n],s=o[n];if(r&&i&&s){let e=r.distance+i.distance;e<s.distance&&(s.distance=e,s.predecessor=i.predecessor)}})})}),r}(e,t||x,n||function(t){var n;return null!=(n=e.outEdges(t))?n:[]})}var j=class extends Error{constructor(e){super(e),this.name="CycleException"}};function I(e){let t={},n={},r=[];if(e.sinks().forEach(function i(o){var s;if(o in n)throw new j;o in t||(n[o]=!0,t[o]=!0,null==(s=e.predecessors(o))||s.forEach(i),delete n[o],r.push(o))}),Object.keys(t).length!==e.nodeCount())throw new j;return r}function C(e){try{I(e)}catch(t){if(t instanceof j)return!1;throw t}return!0}function M(e,t,n,r,i){Array.isArray(t)||(t=[t]);let o=t=>{var n;return null!=(n=e.isDirected()?e.successors(t):e.neighbors(t))?n:[]},s={};return t.forEach(function(t){if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);i=L(e,t,"post"===n,s,o,r,i)}),i}function L(e,t,n,r,i,o,s){return t in r||(r[t]=!0,n||(s=o(s,t)),i(t).forEach(function(t){s=L(e,t,n,r,i,o,s)}),n&&(s=o(s,t))),s}function T(e,t,n){return M(e,t,n,function(e,t){return e.push(t),e},[])}function S(e,t){return T(e,t,"post")}function P(e,t){return T(e,t,"pre")}function F(e,t){var n;let r,i=new s,o={},d=new m;function l(e){let n=e.v===r?e.w:e.v,i=d.priority(n);if(void 0!==i){let s=t(e);s<i&&(o[n]=r,d.decrease(n,s))}}if(0===e.nodeCount())return i;e.nodes().forEach(function(e){d.add(e,Number.POSITIVE_INFINITY),i.setNode(e)});let a=e.nodes()[0];void 0!==a&&d.decrease(a,0);let h=!1;for(;d.size()>0;){if(r=d.removeMin(),r in o)i.setEdge(r,o[r]);else{if(h)throw new Error("Input graph is not connected: "+e);h=!0}null==(n=e.nodeEdges(r))||n.forEach(l)}return i}function R(e,t,n,r){return function(e,t,n,r){if(void 0===n)return y(e,t,n,r);let i=!1,o=e.nodes();for(let s=0;s<o.length;s++){let d=o[s];if(void 0===d)continue;let l=r(d);for(let e=0;e<l.length;e++){let t=l[e];if(!t)continue;let r=t.v===d?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return w(e,t,n,r)}return y(e,t,n,r)}(e,t,n,null!=r?r:t=>{var n;return null!=(n=e.outEdges(t))?n:[]})}var D=s;function Y(e,t,n,r){let i=r;for(;e.hasNode(i);)i=W(r);return n.dummy=t,e.setNode(i,n),i}function V(e){let t=new D({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function A(e,t){let n,r,i=e.x,o=e.y,s=t.x-i,d=t.y-o,l=e.width/2,a=e.height/2;if(!s&&!d)throw new Error("Not possible to find intersection inside of the rectangle");return 0===s||Math.abs(d)*l>Math.abs(s)*a?(d<0&&(a=-a),n=a*s/d,r=a):(s<0&&(l=-l),n=l,r=l*d/s),{x:i+n,y:o+r}}function G(e){let t=K(X(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;void 0!==i&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function B(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),Y(e,"border",i,t)}var z=65535;function q(e,t){return t.length>z?e(...function(e,t=z){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}(t).map(t=>e(...t))):e(...t)}function X(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return void 0===n?Number.MIN_VALUE:n});return q(Math.max,t)}function $(e,t){return t()}var J=0;function W(e){return e+""+ ++J}function K(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let o=e;r(o);o+=n)i.push(o);return i}function Q(e,t){let n={};for(let r of t)void 0!==e[r]&&(n[r]=e[r]);return n}function U(e,t){let n;return n="string"==typeof t?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}var H="\0";function Z(e,t,n){var r,i,o,s,d,l;if(!(e&&t&&n&&"edge"===t.dummy&&"edge"===n.dummy&&t.edgeObj&&n.edgeObj&&e[t.edgeObj.v]&&e[n.edgeObj.v]&&e[t.edgeObj.w]&&e[n.edgeObj.w]))return 0;let a=!0;t.edgeObj.w===n.edgeObj.w&&(a=!1);let h=a?null!=(i=null==(r=e[t.edgeObj.v])?void 0:r.rank)?i:NaN:null!=(s=null==(o=e[t.edgeObj.w])?void 0:o.rank)?s:NaN,u=Object.entries(e).find(e=>{var n,r;return(null==(n=e[1].edgeObj)?void 0:n.v)===t.edgeObj.v&&(null==(r=e[1].edgeObj)?void 0:r.w)===t.edgeObj.w&&e[1].rank===h}),c=Object.entries(e).find(e=>{var t,r;return(null==(t=e[1].edgeObj)?void 0:t.v)===n.edgeObj.v&&(null==(r=e[1].edgeObj)?void 0:r.w)===n.edgeObj.w&&e[1].rank===h});if(!u||!c)return 0;let f=null!=(d=u[1].order)?d:NaN,g=null!=(l=c[1].order)?l:NaN;return isNaN(f-g)?0:f-g}function ee(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function te(e,t){if("_next"!==e&&"_prev"!==e)return t}var ne=class{constructor(){n(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return ee(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&ee(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,te)),n=n._prev;return"["+e.join(", ")+"]"}},re=()=>1;function ie(e,t){if(e.nodeCount()<=1)return[];let n=function(e,t){let n=new D,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let o=n.edge(e.v,e.w)||0,s=t(e),d=o+s;n.setEdge(e.v,e.w,d);let l=n.node(e.v),a=n.node(e.w);i=Math.max(i,l.out+=s),r=Math.max(r,a.in+=s)});let o=function(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}(i+r+3).map(()=>new ne),s=r+1;return n.nodes().forEach(e=>{se(o,s,n.node(e))}),{graph:n,buckets:o,zeroIdx:s}}(e,t||re);return function(e,t,n){var r;let i,o=[],s=t[t.length-1],d=t[0];for(;e.nodeCount();){for(;i=d.dequeue();)oe(e,t,n,i);for(;i=s.dequeue();)oe(e,t,n,i);if(e.nodeCount())for(let s=t.length-2;s>0;--s)if(i=null==(r=t[s])?void 0:r.dequeue(),i){o=o.concat(oe(e,t,n,i,!0)||[]);break}}return o}(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function oe(e,t,n,r,i){let o=[],s=i?o:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let s=e.edge(r),d=e.node(r.v);i&&o.push({v:r.v,w:r.w}),d.out-=s,se(t,n,d)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),o=r.w,s=e.node(o);s.in-=i,se(t,n,s)}),e.removeNode(r.v),s}function se(e,t,n){var r,i,o;n.out?n.in?null==(o=e[n.out-n.in+t])||o.enqueue(n):null==(i=e[e.length-1])||i.enqueue(n):null==(r=e[0])||r.enqueue(n)}function de(e,t){var n;("greedy"===e.graph().acyclicer?ie(e,(n=e,e=>n.edge(e).weight)):function(e,t){let n=[],r={},i={};function o(t){Object.hasOwn(i,t)||(i[t]=!0,r[t]=!0,e.outEdges(t).forEach(e=>{Object.hasOwn(r,e.w)?n.push(e):o(e.w)}),delete r[t])}function s(o){var d;Object.hasOwn(i,o)||(i[o]=!0,r[o]=!0,null==(d=e.outEdges(o))||d.forEach(i=>{var d,l;Object.hasOwn(r,i.w)||(null==(d=t.node(o))?void 0:d.rank)>(null==(l=t.node(i.w))?void 0:l.rank)&&function(e,t,n){let r=new Set;function i(t){var o;if(e.sources().includes(t))return!0;r.add(t);for(let s of null!=(o=e.inEdges(t))?o:[])if((s.v!==n.v||s.w!==n.w)&&!r.has(s.v)&&i(s.v))return!0;return!1}return i(t)}(e,i.w,i)?n.push(i):s(i.w)}),delete r[o])}let d=o;return t&&"function"==typeof t.node&&(d=s),e.sources().forEach(d),e.nodes().forEach(d),n}(e,null!=t?t:null)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,W("rev"))})}function le(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let n=t.v,r=e.node(n).rank,i=t.w,o=e.node(i).rank,s=t.name,d=e.edge(t),l=d.labelRank;if(o===r+1)return;e.removeEdge(t);let a,h,u=0;for(++r;r<o;++u,++r)d.points=[],h={width:0,height:0,edgeLabel:d,edgeObj:t,rank:r},a=Y(e,"edge",h,"_d"),r===l&&(h.width=d.width,h.height=d.height,h.dummy="edge-label",h.labelpos=d.labelpos),e.setEdge(n,a,{weight:d.weight},s),0===u&&e.graph().dummyChains.push(a),n=a;e.setEdge(n,i,{weight:d.weight},s)}(e,t))}function ae(e){let t={};e.sources().forEach(function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let o=e.outEdges(r),s=o?o.map(t=>null==t?Number.POSITIVE_INFINITY:n(t.w)-e.edge(t).minlen):[],d=q(Math.min,s);return d===Number.POSITIVE_INFINITY&&(d=0),i.rank=d})}function he(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var ue=function(e){let t=new D({directed:!1}),n=e.nodes();if(0===n.length)throw new Error("Graph must have at least one node");let r,i,o=n[0],s=e.nodeCount();for(t.setNode(o,{});ce(t,e)<s&&(r=fe(t,e),r);)i=t.hasNode(r.v)?he(e,r):-he(e,r),ge(t,e,i);return t};function ce(e,t){return e.nodes().forEach(function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let o=i.v,s=r===o?i.w:o;!e.hasNode(s)&&!he(t,i)&&(e.setNode(s,{}),e.setEdge(r,s,{}),n(s))})}),e.nodeCount()}function fe(e,t){return t.edges().reduce((n,r)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=he(t,r)),i<n[0]?[i,r]:n},[Number.POSITIVE_INFINITY,null])[1]}function ge(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:pe,postorder:ve}=p,we=be;function be(e){e=function(e){let t=(new D).setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}(e),ae(e);let t,n,r=ue(e);for(ye(r),me(r,e);t=ke(r);)n=Oe(r,e,t),xe(r,e,t,n)}function me(e,t){let n=ve(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>function(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=Ee(e,t,n)}(e,t,n))}function Ee(e,t,n){let r=e.node(n).parent,i=!0,o=t.edge(n,r),s=0;o||(i=!1,o=t.edge(r,n)),s=o.weight;let d=t.nodeEdges(n);return d&&d.forEach(o=>{let d=o.v===n,l=d?o.w:o.v;if(l!==r){let r=d===i,a=t.edge(o).weight;if(s+=r?a:-a,function(e,t,n){return e.hasEdge(t,n)}(e,n,l)){let t=e.edge(n,l).cutvalue;s+=r?-t:t}}}),s}function ye(e,t){arguments.length<2&&(t=e.nodes()[0]),_e(e,{},1,t)}function _e(e,t,n,r,i){let o=n,s=e.node(r);t[r]=!0;let d=e.neighbors(r);return d&&d.forEach(i=>{Object.hasOwn(t,i)||(n=_e(e,t,n,i,r))}),s.low=o,s.lim=n++,i?s.parent=i:delete s.parent,n}function ke(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Oe(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let o=e.node(r),s=e.node(i),d=o,l=!1;return o.lim>s.lim&&(d=s,l=!0),t.edges().filter(t=>l===Ne(e,e.node(t.v),d)&&l!==Ne(e,e.node(t.w),d)).reduce((e,n)=>he(t,n)<he(t,e)?n:e)}function xe(e,t,n,r){let i=n.v,o=n.w;e.removeEdge(i,o),e.setEdge(r.v,r.w,{}),ye(e),me(e,t),function(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=pe(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),o=!1;i||(i=t.edge(r,n),o=!0),t.node(n).rank=t.node(r).rank+(o?i.minlen:-i.minlen)})}(e,t)}function Ne(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}be.initLowLimValues=ye,be.initCutValues=me,be.calcCutValue=Ee,be.leaveEdge=ke,be.enterEdge=Oe,be.exchangeEdges=xe;var je=function(e){let t=e.graph().ranker;if("function"==typeof t)return t(e);switch(t){case"network-simplex":default:Ce(e);break;case"tight-tree":!function(e){ae(e),ue(e)}(e);break;case"longest-path":Ie(e);case"none":}};var Ie=ae;function Ce(e){we(e)}var Me=function(e){let t=function(e){let t={},n=0;function r(i){let o=n;e.children(i).forEach(r),t[i]={low:o,lim:n++}}return e.children(H).forEach(r),t}(e),n=e.graph();if(!Array.isArray(n.dummyChains))return;n.dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,o=function(e,t,n,r){let i,o=[],s=[],d=Math.min(t[n].low,t[r].low),l=Math.max(t[n].lim,t[r].lim);i=n;do{i=e.parent(i),o.push(i)}while(i&&(t[i].low>d||l>t[i].lim));let a=i,h=r;for(;(h=e.parent(h))!==a;)s.push(h);return{path:o.concat(s.reverse()),lca:a}}(e,t,i.v,i.w),s=o.path,d=o.lca,l=0,a=s[l],h=!0;for(;n!==i.w;){if(r=e.node(n),h){for(;(a=s[l])!==d&&e.node(a).maxRank<r.rank;)l++;a===d&&(h=!1)}if(!h){for(;l<s.length-1&&e.node(s[l+1]).minRank<=r.rank;)l++;a=s[l]}void 0!==a&&e.setParent(n,a),n=e.successors(n)[0]}})};function Le(e){let t=Y(e,"root",{},"_root"),n=function(e){let t={};function n(r,i){let o=e.children(r);o&&o.length&&o.forEach(e=>n(e,i+1)),t[r]=i}return e.children(H).forEach(e=>n(e,1)),t}(e),r=Object.values(n),i=q(Math.max,r)-1,o=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=o);let s=function(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}(e)+1;e.children(H).forEach(r=>{Te(e,t,o,s,i,n,r)}),e.graph().nodeRankFactor=o}function Te(e,t,n,r,i,o,s){var d;let l=e.children(s);if(!l.length)return void(s!==t&&e.setEdge(t,s,{weight:0,minlen:n}));let a=B(e,"_bt"),h=B(e,"_bb"),u=e.node(s);e.setParent(a,s),u.borderTop=a,e.setParent(h,s),u.borderBottom=h,l.forEach(d=>{var l;Te(e,t,n,r,i,o,d);let u=e.node(d),c=u.borderTop?u.borderTop:d,f=u.borderBottom?u.borderBottom:d,g=u.borderTop?r:2*r,p=c!==f?1:i-(null!=(l=o[s])?l:0)+1;e.setEdge(a,c,{weight:g,minlen:p,nestingEdge:!0}),e.setEdge(f,h,{weight:g,minlen:p,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,a,{weight:0,minlen:i+(null!=(d=o[s])?d:0)})}var Se=function(e){e.children(H).forEach(function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),i&&Object.hasOwn(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Pe(e,"borderLeft","_bl",n,i,t),Pe(e,"borderRight","_br",n,i,t)}})};function Pe(e,t,n,r,i,o){let s={width:0,height:0,rank:o,borderType:t},d=i[t][o-1],l=Y(e,"border",s,n);i[t][o]=l,e.setParent(l,r),d&&e.setEdge(d,l,{weight:1})}function Fe(e){var t;let n=null==(t=e.graph().rankdir)?void 0:t.toLowerCase();("bt"===n||"rl"===n)&&function(e){e.nodes().forEach(t=>Ye(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);null==(n=r.points)||n.forEach(Ye),Object.hasOwn(r,"y")&&Ye(r)})}(e),("lr"===n||"rl"===n)&&(function(e){e.nodes().forEach(t=>Ve(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);null==(n=r.points)||n.forEach(Ve),Object.hasOwn(r,"x")&&Ve(r)})}(e),Re(e))}function Re(e){e.nodes().forEach(t=>De(e.node(t))),e.edges().forEach(t=>De(e.edge(t)))}function De(e){let t=e.width;e.width=e.height,e.height=t}function Ye(e){e.y=-e.y}function Ve(e){let t=e.x;e.x=e.y,e.y=t}function Ae(e,t=null){let n={},r=e.nodes().filter(t=>!e.children(t).length),i=r.map(t=>e.node(t).rank),o=K(q(Math.max,i)+1).map(()=>[]);return r.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(function r(i){if(n[i])return;n[i]=!0;let s=e.node(i);o[s.rank].push(i);let d=e.successors(i);d&&[...d].sort((n,r)=>function(n,r){return Z(t,e.node(n),e.node(r))}(n,r)).forEach(r)}),o}function Ge(e,t){let n=0;for(let r=1;r<t.length;++r)n+=Be(e,t[r-1],t[r]);return n}function Be(e,t,n){let r=function(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),o=1;for(;o<n.length;)o<<=1;let s=2*o-1;o-=1;let d=new Array(s).fill(0),l=0;return i.forEach(e=>{let t=e.pos+o;d[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=d[t+1]),t=t-1>>1,d[t]+=e.weight;l+=e.weight*n}),l}function ze(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(r))}),function(e){let t=[];function n(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return n=>{n.in.push(t),0===--n.indegree&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>Q(e,["vs","i","barycenter","weight"]))}(Object.values(n).filter(e=>!e.indegree))}function qe(e,t,n,r,i){let o={},s=null,d=null,l=i;"boolean"==typeof t?(l=t,o={}):t&&(o=t,s=null!=n?n:null,d=null!=r?r:null);let a=function(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}(e,e=>Object.hasOwn(e,"barycenter")),h=a.lhs,u=a.rhs.sort((e,t)=>t.i-e.i),c=[],f=0,g=0,p=0;h.sort(function(e,t,n){return(r,i)=>{if(r.barycenter<i.barycenter)return-1;if(r.barycenter>i.barycenter)return 1;if(e&&("string"==typeof r.vs[0]||"string"==typeof i.vs[0])){let n=Z(t,e.node(r.vs[0]),e.node(i.vs[0]));if(0!==n)return n}return n?i.i-r.i:r.i-i.i}}(d,s,!!l));for(let[w,b]of Object.entries(o)){let e=h.findIndex(e=>e.vs[0]===w);h.splice(e+1,0,b)}p=Xe(c,u,p),h.forEach(e=>{p+=e.vs.length,c.push(e.vs),f+=e.barycenter*e.weight,g+=e.weight,p=Xe(c,u,p)});let v={vs:c.flat(1)};return g&&(v.barycenter=f/g,v.weight=g),v}function Xe(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function $e(e,t,n,r,i){var o,s,d,l,a,h,u,c,f,g,p;let v=null,w=i;"boolean"==typeof r?(w=r,v=null):void 0!==r&&(v=r);let b=e.children(t),m=e.node(t),E=m?m.borderLeft:void 0,y=m?m.borderRight:void 0,_={};E&&(b=b.filter(e=>e!==E&&e!==y));let k=function(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}(e,b);k.forEach(t=>{if(e.children(t.v).length){let{result:r}=$e(e,t.v,n,v,w);_[t.v]=r,Object.hasOwn(r,"barycenter")&&function(e,t){void 0!==e.barycenter?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}(t,r)}});let O=ze(k,n);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(O,_);let x={},N=!1;for(let I=0;I<O.length;I++)for(let t=I+1;t<O.length;t++)if(O[I]&&O[t]&&null!=(o=O[I])&&o.barycenter&&null!=(s=O[t])&&s.barycenter&&(null==(d=O[I])?void 0:d.barycenter)===O[t].barycenter){let n=null!=(a=null==(l=O[I])?void 0:l.vs[0])?a:"",r=null!=(u=null==(h=O[t])?void 0:h.vs[0])?u:"",i=e.node(n),o=e.node(r);if("edge"===i.dummy&&"edge"===o.dummy&&(null==(c=i.edgeObj)?void 0:c.v)===(null==(f=o.edgeObj)?void 0:f.v)&&(null==(g=i.edgeObj)?void 0:g.w)===(null==(p=o.edgeObj)?void 0:p.w)){if(i.edgeLabel.reversed){x[r]=O[I],O.splice(I,1),I--;break}x[n]||(x[n]=O[t],O.splice(t,1),t--)}else N=!0}let j=qe(O,x,v,e,w);if(E&&y){j.vs=[E,j.vs,y].flat(1);let t=e.predecessors(E);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(y),i=e.node(r[0]);Object.hasOwn(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+n.order+i.order)/(j.weight+2),j.weight+=2}}return Object.defineProperty(j,"result",{value:j,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(j,"usedBias",{value:N,enumerable:!1,configurable:!0,writable:!0}),j}function Je(e,t,n,r){r||(r=e.nodes());let i=function(e){let t;for(;e.hasNode(t=W("_root")););return t}(e),o=new D({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let s=e.node(r),d=e.parent(r);if(s.rank===t||s.minRank<=t&&t<=s.maxRank){o.setNode(r),o.setParent(r,d||i);let l=e[n](r);l&&l.forEach(t=>{let n=t.v===r?t.w:t.v,i=o.edge(n,r),s=void 0!==i?i.weight:0;o.setEdge(n,r,{weight:e.edge(t).weight+s})}),Object.hasOwn(s,"minRank")&&o.setNode(r,{borderLeft:s.borderLeft[t],borderRight:s.borderRight[t]})}}),o}function We(e,t={},n=null){if("function"==typeof t.customOrder)return void t.customOrder(e,We);let r=X(e),i=Ke(e,K(1,r+1),"inEdges"),o=Ke(e,K(r-1,-1,-1),"outEdges"),s=Ae(e,n);if(Ue(e,s),t.disableOptimalOrderHeuristic)return;let d,l=Number.POSITIVE_INFINITY,a=t.constraints||[];for(let h=0,u=0;u<4;++h,++u){Qe(h%2?i:o,h%4>=2,a,n),s=G(e);let t=Ge(e,s);t<l?(u=0,d=Object.assign({},s),l=t):t===l&&(d=structuredClone(s))}Ue(e,d)}function Ke(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let o of e.nodes()){let t=e.node(o);if("number"==typeof t.rank&&i(t.rank,o),"number"==typeof t.minRank&&"number"==typeof t.maxRank)for(let e=t.minRank;e<=t.maxRank;e++)e!==t.rank&&i(e,o)}return t.map(function(t){return Je(e,t,n,r.get(t)||[])})}function Qe(e,t,n,r){let i=!0,o=new D;e.forEach(function(e){n.forEach(e=>o.setEdge(e.left,e.right));let s=e.graph().root,{result:d,usedBias:l}=$e(e,s,o,r,i);t&&l&&(i=!i),d.vs.forEach((t,n)=>e.node(t).order=n),function(e,t,n){let r,i={};n.forEach(n=>{let o,s,d=e.parent(n);for(;d;){if(o=e.parent(d),o?(s=i[o],i[o]=d):(s=r,r=d),s&&s!==d)return void t.setEdge(s,d);d=o}})}(e,o,d.vs)})}function Ue(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function He(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Ze(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return void 0!==r&&Object.hasOwn(r,n)}function et(e,t,n,r,i=!1){let o={},s=function(e,t,n,r){let i=new D,o=e.graph(),s=function(e,t,n){return(r,i,o)=>{let s,d=r.node(i),l=r.node(o),a=0;if(a+=d.width/2,Object.hasOwn(d,"labelpos"))switch(d.labelpos.toLowerCase()){case"l":s=-d.width/2;break;case"r":s=d.width/2}if(s&&(a+=n?s:-s),s=void 0,a+=(d.dummy?t:e)/2,a+=(l.dummy?t:e)/2,a+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":s=l.width/2;break;case"r":s=-l.width/2}return s&&(a+=n?s:-s),a}}(o.nodesep,o.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let o=n[t];if(void 0!==o){if(i.setNode(o),void 0!==r){let d=n[r];if(void 0!==d){let n=i.edge(d,o);i.setEdge(d,o,Math.max(s(e,t,r),n||0))}}r=t}})}),i}(e,t,n,i),d=i?"borderLeft":"borderRight";function l(e,t){let n=s.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}return l(function(e){let t=s.inEdges(e);o[e]=t?t.reduce((e,t)=>{var n;let r=null!=(n=o[t.v])?n:0,i=s.edge(t);return Math.max(e,r+(void 0!==i?i:0))},0):0},function(e){return s.predecessors(e)||[]}),l(function(t){let n=s.outEdges(t),r=Number.POSITIVE_INFINITY;n&&(r=n.reduce((e,t)=>{let n=o[t.w],r=s.edge(t);return Math.min(e,(void 0!==n?n:0)-(void 0!==r?r:0))},Number.POSITIVE_INFINITY));let i=e.node(t);r!==Number.POSITIVE_INFINITY&&i.borderType!==d&&(o[t]=Math.max(void 0!==o[t]?o[t]:0,r))},function(e){return s.successors(e)||[]}),Object.keys(r).forEach(e=>{var t;let r=n[e];void 0!==r&&(o[e]=null!=(t=o[r])?t:0)}),o}function tt(e,t){let n,r=G(e),i=Object.assign(function(e,t){let n={};return t.length&&t.reduce(function(t,r){let i=0,o=0,s=t.length,d=r[r.length-1];return r.forEach((t,l)=>{let a=function(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}(e,t),h=a?e.node(a).order:s;(a||t===d)&&(r.slice(o,l+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let o=e.node(r),s=o.order;(s<i||h<s)&&(!o.dummy||!e.node(t).dummy)&&He(n,r,t)})}),o=l+1,i=h)}),r}),n}(e,r),function(e,t){let n={};function r(t){var n;return"border"===(null==(n=e.node(t))?void 0:n.dummy)}if(!e.nodes().some(r))return n;function i(t,r,i,o,s){K(r,i).forEach(r=>{let i=t[r];if(void 0!==i&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(void 0===t)return;let r=e.node(t);r.dummy&&(r.order<o||r.order>s)&&He(n,t,i)})}})}return t.length&&t.reduce(function(t,n){let o=-1,s=-1,d=0;return n.forEach((l,a)=>{if(r(l)){let t=e.predecessors(l);if(t&&t.length){let r=t[0];if(void 0===r)return;s=e.node(r).order,i(n,d,a,o,s),d=a,o=s}}i(n,d,n.length,s,t.length)}),n}),n}(e,r)),o={};return["u","d"].forEach(s=>{n="u"===s?r:Object.values(r).reverse(),["l","r"].forEach(r=>{"r"===r&&(n=n.map(e=>Object.values(e).reverse()));let d=function(e,t,n,r,i){let o={},s={},d={};return t.forEach(e=>{e.forEach((e,t)=>{o[e]=e,s[e]=e,d[e]=t})}),t.forEach(t=>{let l=-1,a=-1,h=!1,u=t,c=t.findIndex(t=>(null==i?void 0:i.includes(t))||nt(t,e,i));c>0&&(u=[t[c],...t.slice(0,c),...t.slice(c+1)],h=!0),u.forEach(t=>{var u;let c=r(t);if(c&&c.length){null!=i&&i.includes(t)&&(c=c.filter(t=>nt(t,e,i)));let r=c.sort((e,t)=>{let n=d[e],r=d[t];return(void 0!==n?n:0)-(void 0!==r?r:0)}),f=(r.length-1)/2;for(let e=Math.floor(f),i=Math.ceil(f);e<=i;++e){let i=r[e];if(void 0===i)continue;let c=d[i];if(void 0!==c&&s[t]===t&&l<c&&d[i]!==a&&!Ze(n,t,i)){let e=o[i];void 0!==e&&(s[i]=t,s[t]=o[t]=e,l=c,h&&(l=-1,a=null!=(u=d[i])?u:-1,h=!1))}}}})}),{root:o,align:s}}(e,n,i,t=>("u"===s?e.predecessors(t):e.successors(t))||[],t),l=et(e,n,d.root,d.align,"r"===r);"r"===r&&(l=U(l,e=>-e)),o[s+r]=l})}),function(e,t){let n=Object.values(t),r=q(Math.min,n),i=q(Math.max,n);["u","d"].forEach(n=>{["l","r"].forEach(o=>{let s=n+o,d=e[s];if(!d||d===t)return;let l=Object.values(d),a=r-q(Math.min,l);"l"!==o&&(a=i-q(Math.max,l)),a&&(e[s]=U(d,e=>e+a))})})}(o,function(e,t){return Object.values(t).reduce((t,n)=>{let r=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(n).forEach(([t,n])=>{let o=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(n+o,r),i=Math.min(n-o,i)});let o=r-i;return o<t[0]&&(t=[o,n]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,o)),function(e,t){let n=e.ul;return n?U(n,(n,r)=>{var i,o;if(t){let n=e[t.toLowerCase()];if(n&&void 0!==n[r])return n[r]}let s=Object.values(e).map(e=>{let t=e[r];return void 0!==t?t:0}).sort((e,t)=>e-t);return((null!=(i=s[1])?i:0)+(null!=(o=s[2])?o:0))/2}):{}}(o,e.graph().align)}function nt(e,t,n){var r;if(!n)return!1;let i=null==(r=t.node(e))?void 0:r.edgeObj;if(!i||t.node(e).edgeLabel.reversed)return!1;let o=n.indexOf(null==i?void 0:i.v),s=n.indexOf(null==i?void 0:i.w);return-1!==o&&-1!==s&&o===(s+1)%n.length||o===(s-1)%n.length}function rt(e,t){(function(e){let t=G(e),n=e.graph(),r=n.ranksep,i=n.rankalign,o=0;t.forEach(t=>{let n=t.reduce((t,n)=>{var r;let i=null!=(r=e.node(n).height)?r:0;return t>i?t:i},0);t.forEach(t=>{let r=e.node(t);r.y="top"===i?o+r.height/2:"bottom"===i?o+n-r.height/2:o+n/2}),o+=n+r})})(e=V(e)),Object.entries(tt(e,t)).forEach(([t,n])=>e.node(t).x=n)}var it=new WeakMap;function ot(e,t,n){let r=t;for(;void 0!==r;){let t=e.parent(r);if(t===n)return r;r=t}}function st(e,t,n){var r;let i=e.nodes().filter(t=>e.children(t).length),o={};i.forEach(r=>{let i=e.node(r);if(i&&i.rankdir){let s=new D({multigraph:!0,compound:!0});s.setGraph({rankdir:i.rankdir});let d=e.children(r);d.forEach(t=>{let n={...e.node(t)};s.setNode(t,n);let i=e.parent(t);i&&i!==r&&d.includes(i)&&s.setParent(t,i)});let l=new Set;e.edges().forEach(t=>{let n=ot(e,t.v,r),i=ot(e,t.w,r);if(n===t.v&&i===t.w)s.setEdge(t,{...e.edge(t)});else if(n&&i&&n!==i){let r=`${n}\0${i}`;l.has(r)||(l.add(r),s.setEdge(n,i,{...e.edge(t)}))}}),st(s,t,n);let a=bt(s);lt(a,t,n,null),at(s,a);let h=1/0,u=1/0,c=-1/0,f=-1/0;s.nodes().forEach(e=>{if(e===r)return;let t=s.node(e);t&&"number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.width&&"number"==typeof t.height&&(h=Math.min(h,t.x-t.width/2),c=Math.max(c,t.x+t.width/2),u=Math.min(u,t.y-t.height/2),f=Math.max(f,t.y+t.height/2))}),(!isFinite(h)||!isFinite(u)||!isFinite(c)||!isFinite(f))&&(h=u=0,c=f=0);let g=c-h,p=f-u;o[r]={minX:h,minY:u,maxX:c,maxY:f,width:g,height:p,offsetX:h,offsetY:u},i._dagreClusterSubgraph=s}});let s=[],d=new Map;i.forEach(t=>{let n=e.node(t);n&&n.rankdir&&o[t]&&d.set(t,(e.children(t)||[]).filter(e=>e!==t))});let l=new Set([...d.values()].flat()),a=new Map;d.forEach((t,n)=>{l.has(n)||a.set(n,(t=>{let n=[],r=(e.children(t)||[]).filter(e=>e!==t);for(;r.length>0;){let t=r.shift();n.push(t),(e.children(t)||[]).filter(e=>e!==t).forEach(e=>r.push(e))}return n})(n))});let h=new Set([...a.values()].flat()),u=e=>{for(let[t,n]of a)if(n.includes(e))return t;return e},c=[];e.edges().forEach(t=>{(h.has(t.v)||h.has(t.w))&&c.push({edge:t,label:e.edge(t)})});let f=new Map;h.forEach(t=>{let n=e.parent(t);f.set(t,"string"==typeof n?n:void 0)}),a.forEach((t,n)=>{let r=e.node(n),i=[];t.forEach(t=>{let n=e.node(t);n&&(i.push({id:t,node:n,parent:f.get(t)}),e.removeNode(t))});let d=c.filter(({edge:e})=>t.includes(e.v)||t.includes(e.w)),l=o[n];r&&(s.push({clusterId:n,subgraph:r._dagreClusterSubgraph,bounds:l,children:t,removedNodes:i,removedEdges:d}),r.width=l.width,r.height=l.height)});let g=new Set;c.forEach(({edge:t,label:n})=>{let r=u(t.v),i=u(t.w);if(r!==i&&e.hasNode(r)&&e.hasNode(i)){let t=`${r}\0${i}`;g.has(t)||(g.add(t),e.setEdge(r,i,{...n,width:0,height:0}))}});let p=bt(e),v=lt(p,t,n,null!=(r=it.get(e))?r:null);it.set(e,v),at(e,p),g.forEach(t=>{let n=t.indexOf("\0"),r=t.slice(0,n),i=t.slice(n+1);e.hasEdge(r,i)&&e.removeEdge(r,i)}),s.forEach(({clusterId:t,subgraph:n,bounds:r,removedNodes:i,removedEdges:o})=>{var s,d;let l=e.node(t),a=null!=(s=null==l?void 0:l.x)?s:0,h=null!=(d=null==l?void 0:l.y)?d:0,u=(r.minX+r.maxX)/2,c=(r.minY+r.maxY)/2;i.forEach(({id:t,node:n,parent:r})=>{e.setNode(t,n),void 0!==r&&e.setParent(t,r)}),o.forEach(({edge:t,label:n})=>{e.setEdge(t,n)}),n.nodes().forEach(r=>{if(r===t)return;let i=n.node(r),o=e.node(r);o&&i&&"number"==typeof i.x&&"number"==typeof i.y&&(o.x=a+(i.x-u),o.y=h+(i.y-c))}),dt(e,n,a-u,h-c),delete l._dagreClusterSubgraph}),i.forEach(t=>{var n,r;let i=e.node(t),s=o[t];if(i&&i.rankdir&&i._dagreClusterSubgraph&&s){let o=i._dagreClusterSubgraph,d=null!=(n=i.x)?n:0,l=null!=(r=i.y)?r:0,a=(s.minX+s.maxX)/2,h=(s.minY+s.maxY)/2;o.nodes().forEach(n=>{if(n===t)return;let r=o.node(n),i=e.node(n);if(i&&r&&"number"==typeof r.x&&"number"==typeof r.y){let e=r.x-a,t=r.y-h;i.x=d+e,i.y=l+t}}),dt(e,o,d-a,l-h),delete i._dagreClusterSubgraph}})}function dt(e,t,n,r){t.edges().forEach(i=>{if(!e.hasEdge(i))return;let o=t.edge(i),s=e.edge(i);s.points=o.points.map(e=>({x:e.x+n,y:e.y+r})),Object.hasOwn(o,"x")&&(s.x=o.x+n,s.y=o.y+r)})}function lt(e,t,n,r=null){var i,o;let s=!1!==(null==n?void 0:n.useDynamic),d=s&&null!=(i=null==r?void 0:r.graph)?i:null,l=s&&null!=(o=null==r?void 0:r.rawNodes)?o:null;t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{var r;let i=e.edge(n);i.minlen*=2,"c"!==(null!=(r=i.labelpos)?r:"r").toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?i.width+=i.labeloffset:i.height+=i.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>de(e,d)),t(" nestingGraph.run",()=>Le(e)),t(" rank",()=>je(V(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);Y(e,"edge-proxy",{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},"_ep")}})}(e)),t(" removeEmptyRanks",()=>function(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>void 0!==e),n=q(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{void 0===t&&n%o!==0?--i:void 0!==t&&i&&t.forEach(t=>e.node(t).rank+=i)})}(e)),t(" nestingGraph.cleanup",()=>function(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}(e)),t(" normalizeRanks",()=>function(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return void 0===n?Number.MAX_VALUE:n}),n=q(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=n)})}(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let n=e.node(t);if("edge-proxy"===n.dummy){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}(e)),t(" normalize.run",()=>le(e)),t(" parentDummyChains",()=>Me(e)),t(" addBorderSegments",()=>Se(e)),t(" order",()=>We(e,n,l)),t(" insertSelfEdges",()=>function(e){G(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);"number"!=typeof i.rank&&(i.rank=0),i.order=r+n,(i.selfEdges||[]).forEach(t=>{Y(e,"selfedge",{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,edgeLabel:t.label},"_se"),(!Array.isArray(t.label.points)||7!==t.label.points.length)&&(t.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete i.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>function(e){var t;let n=null==(t=e.graph().rankdir)?void 0:t.toLowerCase();("lr"===n||"rl"===n)&&Re(e)}(e)),t(" position",()=>rt(e,n.corePath)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{let n=e.node(t),r=e=>"number"==typeof e&&isFinite(e);if("selfedge"===n.dummy){let i=n,o=e.node(i.e.v),s=r(null==o?void 0:o.x)?o.x:0,d=r(null==o?void 0:o.y)?o.y:0,l=r(null==o?void 0:o.width)?o.width:0,a=r(null==o?void 0:o.height)?o.height:0,h=r(n.x)?n.x:s,u=r(n.y)?n.y:d,c=l/2,f=a/2;i.edgeLabel.points=[{x:h+c,y:u-f},{x:h+c,y:u-f},{x:h,y:u},{x:h-c,y:u+f},{x:h-c,y:u+f},{x:h,y:u},{x:h,y:u}],i.edgeLabel.x=h,i.edgeLabel.y=u,e.setEdge(i.e,i.edgeLabel),e.removeNode(t)}else n&&Array.isArray(n.selfEdges)&&n.selfEdges.forEach(e=>{if(!Array.isArray(e.label.points)||7!==e.label.points.length){let t=r(n.x)?n.x:0,i=r(n.y)?n.y:0,o=(r(n.width)?n.width:0)/2,s=(r(n.height)?n.height:0)/2;e.label.points=[{x:t+o,y:i-s},{x:t+o,y:i-s},{x:t,y:i},{x:t-o,y:i+s},{x:t-o,y:i+s},{x:t,y:i},{x:t,y:i}]}})})}(e));let a=JSON.parse(JSON.stringify(e._nodes));return t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),s=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(s.x-o.x),n.height=Math.abs(i.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>function(e){e.graph().dummyChains.forEach(t=>{let n,r=e.node(t),i=r.edgeLabel;for(e.setEdge(r.edgeObj,i);r.dummy;)n=e.successors(t)[0],e.removeNode(t),i.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(i.x=r.x,i.y=r.y,i.width=r.width,i.height=r.height),t=n,r=e.node(t)})}(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch(("l"===n.labelpos||"r"===n.labelpos)&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>Fe(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,i=0,o=e.graph(),s=o.marginx||0,d=o.marginy||0;function l(e){let o=e.x,s=e.y,d=e.width,l=e.height;t=Math.min(t,o-d/2),n=Math.max(n,o+d/2),r=Math.min(r,s-l/2),i=Math.max(i,s+l/2)}e.nodes().forEach(t=>l(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,"x")&&l(n)}),t-=s,r-=d,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,"x")&&(i.x-=t),Object.hasOwn(i,"y")&&(i.y-=r)}),o.width=n-t+s,o.height=i-r+d}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w)return;let n,r,i=e.edge(t),o=e.node(t.v),s=e.node(t.w);i.points?(n=i.points[0],r=i.points[i.points.length-1]):(i.points=[],n=s,r=o),i.points.unshift(A(o,n)),i.points.push(A(s,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}(e)),t(" acyclic.undo",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}(e)),{graph:e,rawNodes:a}}function at(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,"x")&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var ht=["nodesep","edgesep","ranksep","marginx","marginy"],ut={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},ct=["acyclicer","ranker","rankdir","align","rankalign"],ft=["width","height","rank"],gt={width:0,height:0},pt=["minlen","weight","width","height","labeloffset"],vt={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},wt=["labelpos"];function bt(e){let t=new D({multigraph:!0,compound:!0}),n=Et(e.graph());return t.setGraph(Object.assign({},ut,mt(n,ht),Q(n,ct))),e.nodes().forEach(n=>{let r=mt(Et(e.node(n)),ft);Object.keys(gt).forEach(e=>{void 0===r[e]&&(r[e]=gt[e])}),t.setNode(n,r);let i=e.parent(n);void 0!==i&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=Et(e.edge(n));t.setEdge(n,Object.assign({},vt,mt(r,pt),Q(r,wt)))}),t}function mt(e,t){return U(Q(e,t),Number)}function Et(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=n}),t}var yt={graphlib:r,version:"3.1.3",layout:function(e,t={}){return st(e,$,t),e},debug:function(e){let t=G(e),n=new D({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{n.setNode(t,{label:t}),n.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;n.setNode(r,{rank:"same"}),e.reduce((e,t)=>(n.setEdge(e,t,{style:"invis"}),t))}),n},util:{time:function(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}},notime:$}};function _t(e,t,n="LR"){if(e.length<=1)return e;const r=new yt.graphlib.Graph({compound:!0});r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:n,ranksep:96,nodesep:56});for(const i of e)if("builderGroup"===i.type)r.setNode(i.id,{});else{const e=i.measured;r.setNode(i.id,{width:e?.width??190,height:e?.height??150})}for(const i of t)r.setEdge(i.source,i.target);for(const i of e){const e=i.parentId;e&&r.setParent(i.id,e)}return yt.layout(r),e.map(e=>{const t=r.node(e.id);if(!t)return e;const n=t.width??190,i=t.height??150;let o=t.x-n/2,s=t.y-i/2;const d=e.parentId;if(d){const e=r.node(d);if(e){const t=e.width??0,n=e.height??0;o-=e.x-t/2,s-=e.y-n/2}}if("builderGroup"===e.type&&t.width&&t.height){const n={...e,position:{x:o,y:s},width:t.width,height:t.height};return delete n.style,n}return{...e,position:{x:o,y:s}}})}export{_t as autoLayout};
@@ -0,0 +1 @@
1
+ import{t as e}from"./libraryFacts-B_z-Kv6i.js";var n={"fwlib.lib":'declare name "FaustWave Examples";\ndeclare author "FaustWave";\ndeclare version "0.1";\ndeclare description "Tiny example library bundled with FaustWave to prove out the library-mount pipeline. Functions live in the global namespace once you import this file. Treat as a starting point for your own custom .lib files.";\n\nimport("stdfaust.lib");\n\n// Tanh-based soft saturation with gain compensation. `drive` controls\n// curve shape (1 = nearly linear, 5+ pushes toward hard limiting); the\n// output is normalized so unity-amplitude input maps to unity-amplitude\n// output regardless of drive.\nfwSaturate(drive, x) = ma.tanh(x * drive) / ma.tanh(drive);\n\n// Single-tap feedback delay convenience. `time_ms` is delay length,\n// `fb` is the feedback coefficient (0..0.95). Internally caps the\n// buffer at 192k samples (~4s at 48kHz).\nfwEcho(time_ms, fb, x) = x : (+ : de.fdelay(192000, time_ms * ma.SR / 1000.0)) ~ *(fb);\n',"pinktrombone-tract.lib":'//################################ pinktrombone-tract.lib ##################################\n// FaustWave: Faust\'s pinktrombone.lib (v1.0.1, faustlibraries, MIT, David Braun 2026, port of Neil Thapen\'s Pink\n// Trombone 1.1, 2017) with the TRACT LENGTH FREE — substitute _n, _bladeStart, _tipStart, _lipStart, _noseLength:\n// ptf = library("pinktrombone-tract.lib")[_n=38; _bladeStart=9; _tipStart=28; _lipStart=34; _noseLength=24;];\n// Changed (2026-11-08): the nose junction follows _noseStart (it was wired at section 17 by pattern, right only for\n// the 44-section tract) and the constriction-width ramp scales with _n (a fixed 25). Nothing else. Same MIT licence as\n// the original, whose header and notice follow unchanged.\n//##########################################################################################\n\n//################################ pinktrombone.lib ##########################################\n// A Faust port of Neil Thapen\'s **Pink Trombone** (2017), the bare-handed procedural\n// speech synthesiser <https://dood.al/pinktrombone/>.\n//\n// The original is a ~1000-line JavaScript program running in a ScriptProcessorNode.\n// This library reproduces its DSP core:\n//\n// * **Glottis** — a per-period-resampled Liljencrants–Fant (LF) glottal-flow\n// waveform driven by a single "tenseness" parameter (Rd = 3(1-tenseness)),\n// plus aspiration noise modulated by the glottal cycle, vibrato / pitch wobble\n// and slow tenseness drift.\n// * **Tract** — a 44-section Kelly–Lochbaum digital waveguide of the vocal\n// tract, run at *twice* the audio rate (two waveguide ticks per sample),\n// with a 28-section nasal branch coupled at section 17 by a three-port\n// scattering junction, glottal reflection 0.75, lip/nostril reflection -0.85,\n// fricative turbulence injected at a movable constriction, and a decaying\n// "transient" pulse released when a full closure opens (plosives).\n// * **Tract shape** — the "tongue" (index / diameter) that bends the rest\n// diameters between the blade and the lips, one or two constrictions\n// (index / diameter, e.g. for fricatives and stops), and the velum.\n//\n// Everything that was block-rate (512 samples) in the JavaScript is computed\n// at sample rate here, with the block-rate constants converted to rates using\n// the original\'s block length.\n//\n// **Sample rate.** Each waveguide section is one tick long, so the tract\'s\n// acoustic length, and with it every formant, scales with the tick rate; the\n// original has the same property. With the default `ticksPerSample = 2` the\n// model is tuned for 44.1 and 48 kHz (at 48 kHz the formants of a given shape\n// are about 9 % higher than at 44.1 kHz). At 88.2 or 96 kHz, override it to 1,\n// e.g. `pt[ticksPerSample=1;].pinkTrombone(...)`: the whole model then behaves\n// as it does at 44.1 or 48 kHz. Other rates shift the formants in proportion.\n// The 1-D simplex drift noises are the real thing (`no.simplex1_lf`, a port of\n// the same noisejs code, with a fixed seed instead of `Date.now()`); the browser\'s\n// uniform `Math.random()` white noise is replaced by scaled `no.noise`.\n//\n// Its official prefix is `pt`.\n//\n// #### Deviations from the original\n//\n// * The block-rate updates (512-sample blocks) run at sample rate, and the reflection\n// coefficients follow the section diameters every sample instead of being\n// interpolated across each block (which also removes the original\'s swapped\n// old/new interpolation at the nose junction). The release of a closure is still\n// detected one block late, as in the original.\n// * `voiced` behaves like a finger on the original\'s pitch keyboard: voicing ramps\n// in and out, without the pressed onset of the original\'s untouched "always\n// voice" start-up.\n// * UI-only behaviour is not modelled: the keyboard is replaced by `freq` in Hz;\n// the tongue control\'s reachable-range kludge, and its side effect of acting as a\n// wide constriction while held, are left out; at most two constrictions\n// (`tract2`, `pinkTrombone2`); the velum is the separate `nasal` gate instead of a\n// touch below the tract.\n// * Up to two release transients sound at once (the original keeps a list).\n// * The simplex drift uses the fixed seed `noiseSeed` instead of `Date.now()`, and\n// the uniform white noise is scaled `no.noise`.\n// * Waveguide state below 1e-20 is flushed to zero, so the (lossless) nose does not\n// decay into denormals.\n//\n// Against a line-by-line reference port of the JavaScript, settled tract output\n// matches to about 1e-6 (relative) and the LF waveform to 2e-3 (absolute, float32).\n//\n// #### Usage\n//\n// ```\n// pt = library("pinktrombone.lib");\n// process = pt.pinkTrombone(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter,\n// constrictionIndex, constrictionDiameter, constrictionOn, nasal);\n// ```\n//\n// Use `process = dm.pink_trombone_demo;` with `import("stdfaust.lib");` for the demo.\n//\n// Note: pass *signals* (or use partial application / sequential composition) for the\n// audio-rate arguments `glottalOutput`, `noiseModulator`, `fricNoise` — an explicit\n// `_` argument gets duplicated wherever the parameter is used inside the function.\n//\n// #### References\n//\n// * Neil Thapen, *Pink Trombone — bare-handed procedural speech synthesis*,\n// version 1.1 (March 2017), MIT licence. <https://dood.al/pinktrombone/>\n// * The original\'s bibliography: J. O. Smith III, *Physical Audio Signal Processing*\n// <https://ccrma.stanford.edu/~jos/pasp/>; B. H. Story, "A parametric model of the\n// vocal tract area function for vowel and consonant simulation", JASA 117(5), 2005;\n// H.-L. Lu & J. O. Smith, "Glottal source modeling for singing voice synthesis",\n// ICMC 2000; J. Mullen, *Physical modelling of the vocal tract with the 2D digital\n// waveguide mesh*, PhD thesis, York, 2006.\n// * G. Fant, "The LF-model revisited. Transformations and frequency domain analysis",\n// STL-QPSR 36(2-3), 1995 (the Rd parametrisation used by `setupWaveform`).\n//\n// #### License\n//\n// The Faust port is MIT-licensed, Copyright 2026 David Braun. It is a derivative\n// work of *Pink Trombone* version 1.1 (March 2017) by Neil Thapen\n// <https://venuspatrol.nfshost.com>; the original copyright and permission notice\n// follows, reproduced verbatim as it requires:\n//\n// Copyright 2017 Neil Thapen\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the "Software"),\n// to deal in the Software without restriction, including without limitation\n// the rights to use, copy, modify, merge, publish, distribute, sublicense,\n// and/or sell copies of the Software, and to permit persons to whom the\n// Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n// IN THE SOFTWARE.\n//########################################################################################\n\ndeclare name "pinktrombone.lib";\ndeclare version "1.0.1";\ndeclare author "David Braun (Faust port), Neil Thapen (original algorithm)";\ndeclare license "MIT";\n\naa = library("aanl.lib");\nba = library("basics.lib");\nfi = library("filters.lib");\nma = library("maths.lib");\nno = library("noises.lib");\nos = library("oscillators.lib");\nsi = library("signals.lib");\n\n//=========================== Constants ================================================\n//======================================================================================\n\n_n = 44; // number of tract sections\n_bladeStart = 10;\n_tipStart = 32;\n_lipStart = 39;\n_noseLength = 28;\n_noseStart = _n - _noseLength + 1; // 17\n_glottalReflection = 0.75;\n_lipReflection = -0.85;\n_movementSpeed = 15; // "cm per second"\n_tractDamping = 0.999; // per-tick loss in the mouth\n_noseDamping = 1.0; // `fade` in the original (nose has no loss)\n\n//------------------------`(pt.)ticksPerSample`----------------------------------------\n// Waveguide ticks per sample (2). The tract\'s length, and so its formants, follow\n// the tick rate: keep 2 at 44.1/48 kHz, override it to 1 at 88.2/96 kHz with\n// explicit substitution (`pt[ticksPerSample=1;]`).\n//\n// #### Usage\n//\n// ```\n// ticksPerSample : _\n// ```\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// pt_ticksPerSample_test = pt[ticksPerSample=1;].pinkTrombone(140, 0.6, 1, 0, 12.9, 2.43, 30, 3, 0, 0);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare ticksPerSample license "MIT";\nticksPerSample = 2;\n\n// The sample rate at which the original would run the same tract: all its\n// block-rate constants refer to 512-sample blocks at that rate.\n_equivSR = ma.SR*ticksPerSample/2;\n_blockTime = 512.0/_equivSR;\n\n//=========================== Utilities =================================================\n//======================================================================================\n\n// Asymmetric slew limiter (rates in units/second). y(0) = x(0): the state is\n// the deviation from the target so the smoother starts *on* its target\n// instead of at 0 (avoids a spurious "opening" of the tract at start-up).\n// A constant input therefore gives a constant output, with no ramp at any\n// point — which is what makes a frozen articulation exactly LTI (see `tractExt`).\n_moveTowards(up, dn, x) = x - e\nwith {\n dx = (x - x\') * (1\'); // 0 on the first sample only\n e = (\\(ep).(ep + dx - aa.clip(0 - dn/ma.SR, up/ma.SR, ep + dx))) ~ _;\n};\n\n// Latch `x` when `w` is nonzero (also on the very first sample so the _latch\n// never sits at an unrelated 0).\n_latch(w, x) = x : ba.sAndH(w | (1 - 1\'));\n\n// The original\'s 1-D simplex noise `noise.simplex1(t*rate)`: one seeded permutation\n// table shared by all the drift streams (as in the JavaScript, where a single\n// `noise` object is evaluated at different rates). Real simplex noise lives in\n// `no.simplex1_lf` (noises.lib); `noiseSeed` selects the table (the original\n// seeds it from `Date.now()`, i.e. randomly per page load).\n//------------------------`(pt.)noiseSeed`----------------------------------------\n// Constant integer seed (12345) shared by the simplex drift streams. Override with explicit library substitution to choose another seed.\n//\n// #### Usage\n//\n// ```\n// noiseSeed : _\n// ```\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// pt_noiseSeed_test = pt[noiseSeed=7;].glottis(140, 0.6, 1, 1) : _, !, !, !;\n// ```\n//-------------------------------------------------------------------------------------\ndeclare noiseSeed license "MIT";\nnoiseSeed = 12345;\n\n// Seeded slow simplex drift shared by the modulators.\n_simplexNoise(rate) = no.simplex1_lf(noiseSeed, rate);\n_simplexNoise(rate) = no.simplex1_lf(noiseSeed, rate);\n\n// The browser fed one uniform [0,1) white noise into two bandpass filters\n// (BiquadFilterNode "bandpass", unity peak). Faust `no.noise` is [-1,1], so\n// halve it; the DC offset is removed by the bandpass anyway.\n_whiteNoise = 0.5*no.noise;\n_bandpassUnity(fc, Q) = fi.resonbp(fc, Q, 1/Q);\n_aspirationNoise = _whiteNoise : _bandpassUnity(500, 0.5);\n_fricativeNoise = _whiteNoise : _bandpassUnity(1000, 0.5);\n\n//=========================== Glottis ===================================================\n//======================================================================================\n\n//------------------------`(pt.)lfWaveform`----------------------------------------\n// The original\'s `setupWaveform` + `normalizedLFWaveform`: a Liljencrants–Fant\n// glottal flow derivative pulse parametrised by Rd (0.5..2.7), normalised to a\n// period of 1 and Ee = 1, evaluated at phase `t` in [0,1).\n//\n// #### Usage\n//\n// ```\n// lfWaveform(Rd0, t) : _\n// ```\n//\n// Where:\n//\n// * `Rd0`: LF shape parameter, clamped to 0.5..2.7.\n// * `t`: Phase in the half-open interval [0, 1).\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// lfWaveform_test = par(i, 3, pt.lfWaveform(0.5 + i, os.lf_sawpos(100)));\n// lfWaveform_modulated_test = pt.lfWaveform(0.5 + 2.2*tri, os.lf_sawpos(200)) with { P = int(ma.SR/10); tri = 1 - abs(2*ba.period(P)/P - 1); };\n// ```\n//-------------------------------------------------------------------------------------\ndeclare lfWaveform license "MIT";\nlfWaveform(Rd0, t) = (Rd0 : _lfCoefficients), t : _lfEvaluate;\n\n// Separate shape-dependent setup from phase-dependent evaluation so the\n// glottis can hold coefficients for a whole period. The public lfWaveform\n// still accepts an audio-rate Rd. Outputs: epsilon, shift, Delta, Te, omega,\n// alpha, E0. Keep shared intermediates on wires to bound the block diagram.\n_lfCoefficients = shapeRatios : phaseTiming : returnCoefficients : openingCoefficients\nwith {\n // Rd -> Ra (return duration ratio), Rk (opening ratio), Rg (frequency ratio).\n shapeRatios = aa.clip(0.5, 2.7)\n : \\(Rd).(-0.01 + 0.048*Rd, 0.224 + 0.118*Rd, Rd)\n : \\(Ra, Rk, Rd).(Ra, Rk, (Rk/4)*(0.5 + 1.2*Rk)/(0.11*Rd - Ra*(0.5 + 1.2*Rk)));\n\n // Ratios -> Ta (return time), Tp (peak time), Te (end of opening phase).\n phaseTiming = \\(Ra, Rk, Rg).(Ra, 1/(2*Rg), Rk)\n : \\(Ta, Tp, Rk).(Ta, Tp, Tp + Tp*Rk);\n\n // Return-phase decay and normalization; carry Tp and Te into the next stage.\n returnCoefficients = \\(Ta, Tp, Te).(1/Ta, Tp, Te)\n : \\(epsilon, Tp, Te).(epsilon, exp(0 - epsilon*(1 - Te)), Tp, Te)\n : \\(epsilon, shift, Tp, Te).(epsilon, shift, 1 - shift, Tp, Te);\n\n // Balance the opening and return phases for a zero waveform integral.\n openingCoefficients = \\(epsilon, shift, Delta, Tp, Te).\n (epsilon, shift, Delta, Tp, Te, ma.PI/Tp,\n ((1/epsilon)*(shift - 1) + (1 - Te)*shift)/Delta)\n : \\(epsilon, shift, Delta, Tp, Te, omega, RHSIntegral).\n (epsilon, shift, Delta, Te, omega, sin(omega*Te), Tp,\n 0 - (RHSIntegral - (Te - Tp)/2))\n : \\(epsilon, shift, Delta, Te, omega, s, Tp, totalUpperIntegral).\n (epsilon, shift, Delta, Te, omega, s,\n log(0 - ma.PI*s*totalUpperIntegral/(Tp*2))/(Tp/2 - Te))\n : \\(epsilon, shift, Delta, Te, omega, s, alpha).\n (epsilon, shift, Delta, Te, omega, alpha, -1.0/(s*exp(alpha*Te)));\n};\n\n// Evaluate one phase using the seven shape coefficients above.\n_lfEvaluate = \\(epsilon, shift, Delta, Te, omega, alpha, E0, t).\n (select2(t > Te,\n E0*exp(alpha*t)*sin(omega*t),\n (shift - exp(0 - epsilon*(t - Te)))/Delta));\n\n//------------------------`(pt.)glottis`----------------------------------------\n// The Pink Trombone glottal source. Returns the glottal flow (LF pulse plus\n// aspiration noise) that feeds the tract, together with the signals the tract\n// needs from the glottis (noise modulator, and glottal-phase & intensity for\n// convenience).\n// Outputs are glottal excitation, noise modulator, intensity and phase, in that order.\n//\n// #### Usage\n//\n// ```\n// glottis(freq, tenseness, voiced, wobble) : _, _, _, _\n// ```\n//\n// Where:\n//\n// * `freq`: Positive fundamental frequency in Hz; the demo spans about 87..277 Hz.\n// * `tenseness`: Voice tenseness in 0..1; the default is 0.6.\n// * `voiced`: Voice gate: positive is on, zero is off. It acts like a finger on the\n// original\'s pitch keyboard: voicing ramps in and out, with no pressed onset.\n// * `wobble`: Pitch wobble amount in 0..1.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// glottis_test = pt.glottis(140, 0.6, (ba.time < 24000), 0);\n// glottis_modulated_test = pt.glottis(100 + 100*tri, 0.05 + 0.9*tri, (ba.time % 48000) > 12000, 1) with { P = int(ma.SR/10); tri = 1 - abs(2*ba.period(P)/P - 1); };\n// ```\n//-------------------------------------------------------------------------------------\ndeclare glottis license "MIT";\nglottis(freq, tenseness, voiced, wobble) = voiceIntensity : modulateControls : advancePhase : renderExcitation\nwith {\n // The stages pass shared signals along as *wires* (sequential composition)\n // instead of referencing `with`-definitions from several places: Faust\n // substitutes definitions textually, so a twice-referenced definition\n // becomes two full subgraphs in the block diagram (the signal compiler\n // CSEs them, the SVG drawer does not).\n\n // ---- voiceIntensity: intensity (block-rate state of the original, at sample rate)\n // intensity += 0.13 per block when voiced, -= 0.05 per block otherwise, clamped 0..1\n voiceIntensity = _moveTowards(0.13/_blockTime, 0.05/_blockTime, (voiced > 0)) : aa.clip(0, 1);\n\n // ---- modulateControls: (intensity) -> (intensity, newFrequency, newTenseness) ----\n modulateControls = \\(intensity).(intensity, newFrequency(intensity), newTenseness(intensity));\n\n // smoothFrequency moves by a factor 1.1 per block towards the UI frequency,\n // and snaps to it when intensity == 0.\n newFrequency(intensity) = smoothFrequency*(1 + vibrato)\n with {\n logRate = log(1.1)/_blockTime;\n smoothFrequency = exp(smoothLogFrequency)\n with {\n targetLogFrequency = log(max(1, freq));\n smoothLogFrequency = (\\(previous).(select2((intensity == 0) | (1 - 1\'),\n previous + aa.clip(0 - logRate/ma.SR, logRate/ma.SR, targetLogFrequency - previous),\n targetLogFrequency))) ~ _ ;\n };\n vibrato = 0.005*os.osc(6)\n + 0.02*_simplexNoise(4.07)\n + 0.04*_simplexNoise(2.15)\n + wobble*(0.2*_simplexNoise(0.98) + 0.4*_simplexNoise(0.5));\n };\n\n // newTenseness: UI tenseness + slow drift. The gate acts like a finger on\n // the original\'s keyboard, so its untouched "always voice" pressed onset\n // term (3-tenseness)*(1-intensity) does not apply.\n newTenseness(intensity) = tenseness + 0.1*_simplexNoise(0.46) + 0.05*_simplexNoise(0.36);\n\n // ---- advancePhase: (intensity, newFrequency, newTenseness) -> (intensity, newTenseness, phase, wrap)\n // per-period phasor: the frequency is sampled at the start of each glottal\n // cycle (setupWaveform); wrap is 1 on the sample where a new period starts\n advancePhase = \\(intensity, frequency, tenseness).(intensity, tenseness, phaseAndWrap(frequency));\n phaseAndWrap(newFrequency) = (tick ~ (_,_)) : (_,!,_)\n with {\n tick(phase, latchedFrequency) = nextPhase - wrap, select2(wrap, frequency, newFrequency), wrap\n with {\n frequency = select2(latchedFrequency > 0, newFrequency, latchedFrequency); // first sample: no latched value yet\n nextPhase = phase + frequency/ma.SR;\n wrap = nextPhase >= 1;\n };\n };\n\n // ---- renderExcitation: (intensity, newTenseness, phase, wrap) -> the four outputs ----\n renderExcitation(intensity, newTenseness, phase, wrap) = glottalOutput, noiseModulator, intensity, phase\n with {\n loudness = pow(tenseness, 0.25);\n // tenseness is sampled at the start of each glottal cycle too\n Rd = 3*(1 - _latch(wrap, newTenseness));\n // Hold the derived coefficients on the same samples as Rd, including\n // sample zero. This reuses them between wraps without control/enable,\n // preserving compatibility with the vector compiler.\n coefficients = Rd : _lfCoefficients : par(i, 7, _latch(wrap));\n voice = (coefficients, phase : _lfEvaluate)*intensity*loudness;\n\n voicedMod = 0.1 + 0.2*max(0, sin(2*ma.PI*phase));\n noiseModulator = tenseness*intensity*voicedMod + (1 - tenseness*intensity)*0.3;\n aspiration = intensity*(1 - sqrt(tenseness))*noiseModulator*_aspirationNoise\n * (0.2 + 0.02*_simplexNoise(1.99));\n\n glottalOutput = voice + aspiration;\n };\n};\n\n//=========================== Tract shape ==============================================\n//======================================================================================\n\n// Rest diameter of section i given the tongue position (TractUI.setRestDiameter\n// plus Tract.init for the sections outside the tongue range).\n_restDiameter(tongueIndex, tongueDiameter, i) = ba.if(i < _bladeStart, initial(i),\n ba.if(i < _lipStart, tongue, 1.5))\nwith {\n initial(j) = ba.if(j < 7*_n/44 - 0.5, 0.6, ba.if(j < 12*_n/44, 1.1, 1.5));\n t = 1.1*ma.PI*(tongueIndex - i)/(_tipStart - _bladeStart);\n fixedTongueDiameter = 2 + (tongueDiameter - 2)/1.5;\n edge = ba.if((i == _bladeStart-2) | (i == _lipStart-1), 0.8,\n ba.if((i == _bladeStart) | (i == _lipStart-2), 0.94, 1.0));\n curve = (1.5 - fixedTongueDiameter + 1.7)*cos(t)*edge; // 1.7 = gridOffset\n tongue = 1.5 - curve;\n};\n\n// Target diameter of section i after applying a constriction at fractional\n// `index` with (touch-space) `diameter` (TractUI.handleTouches).\n_constrictedDiameter(index, diameter, active, i, rest) =\n select2(active & (index >= 2) & (index < _n) & (diameter < 3) & (d < rest),\n rest,\n d + (rest - d)*shrink)\nwith {\n d = max(0, diameter - 0.3);\n // the width ramp starts at 25 of 44 sections — scaled with the tract (FaustWave: was the literal 25)\n w0 = 25*_n/44;\n width = ba.if(index < w0, 10,\n ba.if(index >= _tipStart, 5, 10 - 5*(index - w0)/(_tipStart - w0)));\n relpos = abs(i - index) - 0.5;\n shrink = ba.if(relpos <= 0, 0, ba.if(relpos > width, 1, 0.5*(1 - cos(ma.PI*relpos/width))));\n};\n\n// Slew rate ("_slowReturn") for section i: the tract re-opens more slowly\n// towards the back.\n_slowReturn(i) = ba.if(i < _noseStart, 0.6,\n ba.if(i >= _tipStart, 1.0, 0.6 + 0.4*(i - _noseStart)/(_tipStart - _noseStart)));\n\n//------------------------`(pt.)tractDiameters`----------------------------------------\n// The 44 time-varying section diameters (after the original\'s movement\n// smoothing), as parallel signals.\n//\n// #### Usage\n//\n// ```\n// tractDiameters(tongueIndex, tongueDiameter, cIndex, cDiameter, cActive) : si.bus(44)\n// ```\n//\n// Where:\n//\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `cIndex`: Constriction position in sections, 2..44; position 44 lies beyond the mouth cells.\n// * `cDiameter`: Touch diameter in model units, 0..3; at most 0.3 closes the tract, 3 leaves it open.\n// * `cActive`: Constriction gate, 0 or 1.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// tractDiameters_test = pt.tractDiameters(12.9, 2.43, 30, 3, 0);\n// tractDiameters_constricted_test = pt.tractDiameters(20, 3.0, 30.4, 0.55, 1);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tractDiameters license "MIT";\ntractDiameters(tongueIndex, tongueDiameter, cIndex, cDiameter, cActive) =\n tractDiameters2(tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, 30, 3, 0);\n\n//------------------------`(pt.)tractDiameters2`----------------------------------------\n// Same with two independent constrictions, applied in order like the original\'s\n// touch loop (each can only narrow what the previous ones left).\n//\n// #### Usage\n//\n// ```\n// tractDiameters2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a) : si.bus(44)\n// ```\n//\n// Where:\n//\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `c1i`: First constriction position in sections, 2..44.\n// * `c1d`: First touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c1a`: First constriction gate, 0 or 1.\n// * `c2i`: Second constriction position in sections, 2..44.\n// * `c2d`: Second touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c2a`: Second constriction gate, 0 or 1.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// tractDiameters2_test = pt.tractDiameters2(20, 3.0, 36.3, 0.5, 1, 20.6, 0.8, 1);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tractDiameters2 license "MIT";\ntractDiameters2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a) =\n par(i, _n, _moveTowards(_slowReturn(i)*_movementSpeed, 2*_movementSpeed, target(i)))\nwith {\n target(i) = _constrictedDiameter(c2i, c2d, c2a, i,\n _constrictedDiameter(c1i, c1d, c1a, i,\n _restDiameter(tongueIndex, tongueDiameter, i)));\n};\n\n// Fixed nose diameters (Tract.init); section 0 is the velum, replaced dynamically.\n_noseDiameterInit(i) = min(1.9, ba.if(d < 1, 0.4 + 1.6*d, 0.5 + 1.5*(2 - d)))\nwith { d = 2*(i/_noseLength); };\n\n// Nose reflections are computed once at init in the original with noseA[0]=0.16.\n_noseArea(i) = _noseDiameterInit(i)*_noseDiameterInit(i);\n_noseReflection(i) = (_noseArea(i-1) - _noseArea(i))/(_noseArea(i-1) + _noseArea(i));\n\n//=========================== Tract waveguide ==========================================\n//======================================================================================\n\n_NSTATE = 2*_n + 2*_noseLength; // 144 state signals: R[0..43], L[0..43], NR[0..27], NL[0..27]\n_NREFL = _n - 1 + 3; // reflection coefficients: refl[1..43], reflLeft, reflRight, reflNose\n\n\n// Compile-time conditional for route() positions (c must be a constant 0/1).\n_cif(c, a, b) = c*a + (1-c)*b;\n\n// One waveguide tick (the original\'s Tract.runStep): state, glottal, inj[0..43],\n// reflections -> state.\n_tractTick = addInjections : junctionRoute : junctions : reorder : damping\nwith {\n // ---- stage A: R[k] += inj[k], L[k] += inj[k]; pass the rest through ----\n NIN = _NSTATE + 1 + _n + _NREFL;\n NA = 4*_n + 2*_noseLength + 1 + _NREFL;\n addInjections = route(NIN, NA,\n par(k, _n, (k+1, 2*k+1), (_NSTATE+2+k, 2*k+2)), // R[k], inj[k]\n par(k, _n, (_n+k+1, 2*_n+2*k+1), (_NSTATE+2+k, 2*_n+2*k+2)), // L[k], inj[k]\n par(k, 2*_noseLength, (2*_n+k+1, 4*_n+k+1)), // NR, NL\n (_NSTATE+1, 4*_n+2*_noseLength+1), // glottal\n par(k, _NREFL, (_NSTATE+1+_n+k+1, 4*_n+2*_noseLength+1+k+1))) // reflections\n : par(k, _n, +), par(k, _n, +), si.bus(2*_noseLength), _, si.bus(_NREFL);\n\n // ---- stage B: scattering junctions ----\n // Input order after stage A (1-based): R\'[k]=k+1, L\'[k]=n+k+1, NR[k]=2n+k+1,\n // NL[k]=2n+_noseLength+k+1, glottal, refl[1..43], reflLeft, reflRight, reflNose.\n inR(k) = k+1;\n inL(k) = _n+k+1;\n inNR(k) = 2*_n+k+1;\n inNL(k) = 2*_n+_noseLength+k+1;\n inG = _NSTATE+1;\n inRefl(i) = _NSTATE+1+i; // i = 1..43\n inReflLeft = _NSTATE+1+_n;\n inReflRight = _NSTATE+2+_n;\n inReflNose = _NSTATE+3+_n;\n // Block input offsets (number of inputs consumed before each block):\n // glottalEnd(2), junction(1..16)(3 each), noseJunction(6), junction(18..43)(3 each),\n // lipEnd(1), noseJunction(1..27)(2 each), noseEnd(1).\n offR(i) = _cif(i <= _noseStart, 3*i-1, 3*i+2); // i >= 1\n offLipL = 3*_n+2; // 134\n offNJ(i) = offLipL+1 + 2*(i-1); // i >= 1\n offNoseL = offLipL+1 + 2*(_noseLength-1); // 189\n NB = offNoseL+1; // 190 = inputs consumed by stage B\n junctionRoute = route(_NSTATE+1+_NREFL, NB,\n (inL(0), 1), (inG, 2), // glottal end\n par(j, _n-1, jr(j+1)), // interior junctions\n (inR(_n-1), offLipL+1), // lip end\n par(j, _noseLength-1, (inNR(j), offNJ(j+1)+1), (inNL(j+1), offNJ(j+1)+2)),\n (inNR(_noseLength-1), offNoseL+1))\n with {\n // the nose junction at _noseStart, whatever the tract length (FaustWave: was the literal 17)\n jr(i) = jrAt(i - _noseStart, i);\n jrAt(0, i) = (inReflLeft, offR(i)+1), (inReflRight, offR(i)+2), (inReflNose, offR(i)+3),\n (inR(i-1), offR(i)+4), (inL(i), offR(i)+5), (inNL(0), offR(i)+6);\n jrAt(d, i) = (inRefl(i), offR(i)+1), (inR(i-1), offR(i)+2), (inL(i), offR(i)+3);\n };\n // scattering blocks\n glottalEnd(l0, g) = l0*_glottalReflection + g; // -> jR[0]\n junction(r, a, b) = a - w, b + w with { w = r*(a + b); }; // (r, R[i-1], L[i]) -> (jR[i], jL[i])\n noseJunction(rl, rr, rn, a, b, c) = // (.., R[i-1], L[i], NL[0])\n rr*b + (1+rr)*(a + c), // jR[i]\n rl*a + (1+rl)*(c + b), // jL[i]\n rn*c + (1+rn)*(b + a); // nJR[0]\n lipEnd = *(_lipReflection);\n blockR(0) = glottalEnd;\n // the nose junction at _noseStart (FaustWave: was the literal 17)\n blockR(i) = blockAt(i - _noseStart);\n blockAt(0) = noseJunction;\n blockAt(d) = junction;\n junctions = par(i, _n, blockR(i)), lipEnd,\n par(j, _noseLength-1, junction(_noseReflection(j+1))), lipEnd;\n\n // ---- stage C: back to state order (R = 0.999*jR[k], L = 0.999*jL[k+1], ...) ----\n // Output positions (1-based) of stage B: glottalEnd(1), junction i (2 each),\n // noseJunction(3), lipEnd(1), nose junction i (2 each), noseEnd(1).\n posJR(0) = 1;\n posJR(k) = _cif(k <= _noseStart, 2*k, 2*k+1);\n posJL(k) = _cif(k <= _noseStart, 2*k+1, _cif(k == _n, 2*_n+1, 2*k+2));\n posNJR(0) = 2*_noseStart+2; // 36\n posNJR(k) = 2*_n+2 + 2*(k-1);\n posNJL(k) = _cif(k == _noseLength, 2*_n + 2*_noseLength, 2*_n+2 + 2*(k-1) + 1);\n reorder = route(_NSTATE, _NSTATE,\n par(k, _n, (posJR(k), k+1)),\n par(k, _n, (posJL(k+1), _n+k+1)),\n par(k, _noseLength, (posNJR(k), 2*_n+k+1)),\n par(k, _noseLength, (posNJL(k+1), 2*_n+_noseLength+k+1)));\n damping = par(k, 2*_n, *(_tractDamping)), par(k, 2*_noseLength, *(_noseDamping));\n};\n\n// Scattering coefficients from the 44 section diameters and the velum diameter\n// (outputs ordered like _NREFL).\n_tractReflections = route(_n+1, 2*(_n-1) + 3,\n par(i, _n-1, (i+1, 2*i+1), (i+2, 2*i+2)), // (d[i-1], d[i]) pairs\n (_noseStart+1, 2*(_n-1)+1), (_noseStart+2, 2*(_n-1)+2), (_n+1, 2*(_n-1)+3))\n : par(i, _n-1, refl), noseJunctionRefl\nwith {\n refl(d0, d1) = select2(a1 == 0, (a0 - a1)/max(ma.EPSILON, a0 + a1), 0.999)\n with { a0 = d0*d0; a1 = d1*d1; };\n noseJunctionRefl(d0, d1, dv) = (2*a0 - sA)/sA, (2*a1 - sA)/sA, (2*av - sA)/sA\n with { a0 = d0*d0; a1 = d1*d1; av = dv*dv; sA = a0 + a1 + av; };\n};\n\n//------------------------`(pt.)tract`----------------------------------------\n// The Pink Trombone vocal tract: 44-section Kelly–Lochbaum waveguide with a\n// 28-section nasal branch, ticked twice per sample. Diameters, constriction and\n// velum drive the reflection coefficients; fricative noise and closure-release\n// transients are injected into the waveguide.\n//\n// #### Usage\n//\n// ```\n// tract(tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal, glottalOutput, noiseModulator) : _\n// ```\n//\n// Where:\n//\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `cIndex`: Constriction position in sections, 2..44; position 44 lies beyond the mouth cells.\n// * `cDiameter`: Touch diameter in model units, 0..3; at most 0.3 closes the tract, 3 leaves it open.\n// * `cActive`: Constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n// * `glottalOutput`: Audio excitation from glottis or an external source.\n// * `noiseModulator`: Turbulence amplitude modulator, normally the second output of glottis.\n//\n// #### Test\n// ```\n// pt = library("pinktrombone.lib");\n// ba = library("basics.lib");\n// ma = library("maths.lib");\n// os = library("oscillators.lib");\n// import("stdfaust.lib");\n// tract_test = (os.lf_imptrain(140), 0.3) : pt.tract(12.9, 2.43, 30, 3, 0, 0);\n// tract_nasal_test = (os.lf_imptrain(140), 0.3) : pt.tract(27, 2.2, 30, 3, 0, 1);\n// tract_closure_test = (os.lf_imptrain(140), 0.3) : pt.tract(12.9, 2.43, 40, 0, 1, 0);\n// tract_release_test = (os.lf_imptrain(140), 0.3) : pt.tract(12.9, 2.43, 30, 0, ba.time < 12000, 0);\n// tract_modulated_test = (os.lf_imptrain(140), 0.3) : pt.tract(12 + 17*tri, 2.43, 30, 3, 0, 0) with { P = int(ma.SR/10); tri = 1 - abs(2*ba.period(P)/P - 1); };\n// tract_diameter_modulated_test = (os.lf_imptrain(140), 0.3) : pt.tract(12.9, 2.05 + 1.45*tri, 30, 3, 0, 0) with { P = int(ma.SR/10); tri = 1 - abs(2*ba.period(P)/P - 1); };\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tract license "MIT";\ntract(tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal, glottalOutput, noiseModulator) =\n tractExt(_fricativeNoise, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal, glottalOutput, noiseModulator);\n\n//------------------------`(pt.)tract2`----------------------------------------\n// `tract` with two independent constrictions (the original is multi-touch: each\n// touch narrows the tract and injects its own turbulence). Useful for consonant\n// clusters and double articulations.\n//\n// #### Usage\n//\n// ```\n// tract2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal, glottalOutput, noiseModulator) : _\n// ```\n//\n// Where:\n//\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `c1i`: First constriction position in sections, 2..44.\n// * `c1d`: First touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c1a`: First constriction gate, 0 or 1.\n// * `c2i`: Second constriction position in sections, 2..44.\n// * `c2d`: Second touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c2a`: Second constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n// * `glottalOutput`: Audio excitation from glottis or an external source.\n// * `noiseModulator`: Turbulence amplitude modulator, normally the second output of glottis.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// tract2_test = (os.lf_imptrain(140), 0.3) : pt.tract2(12.9, 2.43, 36.3, 0.5, 1, 20.6, 0.8, 1, 0);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tract2 license "MIT";\ntract2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal, glottalOutput, noiseModulator) =\n tract2Ext(_fricativeNoise, tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal, glottalOutput, noiseModulator);\n\n//------------------------`(pt.)tractExt`----------------------------------------\n// Same as `tract` / `tract2` but with an explicit turbulence noise source (the\n// original\'s 1 kHz, Q 0.5 bandpassed white noise) as first argument, for testing.\n//\n// With `fricNoise = 0` and *constant* articulation arguments, `tractExt`/`tract2Ext`\n// reduce to the bare linear waveguide, which is exactly LTI from `glottalOutput`\n// to the output: `_moveTowards` starts on its target, so constant articulation\n// never ramps, the reflection coefficients are constants, and no release\n// transient can fire. Its impulse response then characterises it completely\n// (useful for FIR/formant analysis of a fixed vocal-tract shape).\n//\n// #### Usage\n//\n// ```\n// tractExt(fricNoise, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal, glottalOutput, noiseModulator) : _\n// ```\n//\n// Where:\n//\n// * `fricNoise`: External turbulence signal, typically white noise bandpassed at 1 kHz with Q 0.5; zero disables turbulence.\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `cIndex`: Constriction position in sections, 2..44; position 44 lies beyond the mouth cells.\n// * `cDiameter`: Touch diameter in model units, 0..3; at most 0.3 closes the tract, 3 leaves it open.\n// * `cActive`: Constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n// * `glottalOutput`: Audio excitation from glottis or an external source.\n// * `noiseModulator`: Turbulence amplitude modulator, normally the second output of glottis.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// tractExt_test = pt.tractExt(no.noise, 12.9, 2.43, 30.4, 0.55, 1, 0, os.lf_imptrain(140), 0.3);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tractExt license "MIT";\ntractExt(fricNoise, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal, glottalOutput, noiseModulator) =\n tract2Ext(fricNoise, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, 30, 3, 0, nasal, glottalOutput, noiseModulator);\n\n//------------------------`(pt.)tract2Ext`----------------------------------------\n// Vocal tract with two independent constrictions and an explicit turbulence source.\n// With zero turbulence and constant articulation, this is a linear time-invariant\n// filter of the glottal excitation. Constant articulation starts on its target.\n//\n// #### Usage\n//\n// ```\n// tract2Ext(fricNoise, tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal, glottalOutput, noiseModulator) : _\n// ```\n//\n// Where:\n//\n// * `fricNoise`: External turbulence signal, typically white noise bandpassed at 1 kHz with Q 0.5; zero disables turbulence.\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `c1i`: First constriction position in sections, 2..44.\n// * `c1d`: First touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c1a`: First constriction gate, 0 or 1.\n// * `c2i`: Second constriction position in sections, 2..44.\n// * `c2d`: Second touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c2a`: Second constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n// * `glottalOutput`: Audio excitation from glottis or an external source.\n// * `noiseModulator`: Turbulence amplitude modulator, normally the second output of glottis.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// tract2Ext_test = pt.tract2Ext(no.noise, 12.9, 2.43, 36.3, 0.5, 1, 20.6, 0.8, 1, 0, os.lf_imptrain(140), 0.3);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare tract2Ext license "MIT";\ntract2Ext(fricNoise, tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal, glottalOutput, noiseModulator) =\n excBus : (body(ticksPerSample) ~ par(k, _NSTATE, _flush)) : (par(k, _NSTATE, !), _) : *(0.25/ticksPerSample)\nwith {\n NTRB = 2*2 + 3*2; // (transEnv, transPos) per transient slot, then (turb, idx, delta) per constriction\n NEXC = 1 + _n + _NREFL; // glottal, inj[0..43], reflections\n\n // ---- geometry (each signal generator instantiated ONCE; multiply-used buses\n // are distributed with explicit fan-out `<:` so the *box* graph stays small —\n // Faust substitutes `with`-definitions textually, and letting each of the 44\n // injection taps close over the diameter graph made the block diagram\n // explode: the WASM compiler of the online IDE ran out of memory\n // generating the SVG) ----\n velumTarget = select2(nasal > 0, 0.01, 0.4);\n velum = _moveTowards(0.25*_movementSpeed, 0.1*_movementSpeed, velumTarget);\n diameters = tractDiameters2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a);\n\n // ---- turbulence noise level at each constriction ----\n // The original also skips a touch with `diameter <= 0`, but that guard is\n // subsumed by `openness` (already 0 for cd <= 0.3), so only the index\n // bounds are kept here.\n turbOf(ci, cd, ca) = 0.66*fricNoise*fricIntensity*noiseModulator*thinness*openness\n * (ci >= 2) * (ci <= _n)\n with {\n fricIntensity = _moveTowards(10, 10, ca > 0) : aa.clip(0, 1); // 0.1 s attack/release\n thinness = 8*(0.7 - cd) : aa.clip(0, 1);\n openness = 30*(cd - 0.3) : aa.clip(0, 1);\n };\n turbBus = turbOf(c1i, c1d, c1a), floor(c1i), c1i - floor(c1i),\n turbOf(c2i, c2d, c2a), floor(c2i), c2i - floor(c2i);\n\n // ---- transients: (lastObstruction, velum) -> (transEnv, transPos) ----\n // The original detects the release in `reshapeTract`, one block after the\n // diameter first became positive, so the pulse is delayed by one block here too.\n obstructedIdx(i, d) = ba.if(d <= 0, i, -1);\n lastObsAndVelum = (par(i, _n, obstructedIdx(i)) : ba.parallelMax(_n)), _; // d[0..43], velum -> lastObs, velum\n transientPair(lo, vel) = env(1), pos(1), env(0), pos(0)\n with {\n blockSamples = int(512*2/ticksPerSample); // one original block\n releaseTrig = (((lo\' > -1) & (lo == -1) & (1\')) @ blockSamples) & (vel*vel < 0.05);\n // two slots, used alternately, so an earlier transient keeps sounding at\n // its own position when a new one is released\n slot = ((+(releaseTrig)) ~ _) % 2;\n env(j) = (\\(e).(e*pow(2, -200.0/ma.SR) + 0.3*releaseTrig*(slot == j))) ~ _; // strength 0.3, exponent 200\n pos(j) = _latch(releaseTrig*(slot == j), lo\' @ blockSamples);\n };\n\n // one injection tap: (transEnv, transPos, (turb, idx, delta)x2) -> inj[k]\n injTap(k) = \\(e, p, eb, pb, t1, ix1, dl1, t2, ix2, dl2).(\n 0.5*e*(k == p) + 0.5*eb*(k == pb)\n + 0.5*t1*((k == ix1+1)*(1 - dl1) + (k == ix1+2)*dl1)\n + 0.5*t2*((k == ix2+1)*(1 - dl2) + (k == ix2+2)*dl2));\n\n // ---- the excitation bus: glottal, inj[0..43], reflections (built once) ----\n excBus = glottalOutput,\n (((diameters, velum) <: (_tractReflections, lastObsAndVelum)) // refl(_NREFL), lastObs, velum\n : (si.bus(_NREFL), transientPair), turbBus // refl(_NREFL), e, p, eb, pb, turbBus(6)\n : route(_NREFL+NTRB, _NREFL+NTRB,\n par(i, _NREFL, (i+1, i+NTRB+1)),\n par(i, NTRB, (_NREFL+1+i, i+1))) // e, p, turbBus(6), refl(_NREFL)\n : (si.bus(NTRB) <: par(k, _n, injTap(k))), si.bus(_NREFL)); // inj(n), refl(_NREFL)\n\n // ---- ticksPerSample waveguide ticks per sample, summing lip+nose output of each ----\n tapOut = si.bus(_NSTATE) <: si.bus(_NSTATE), (route(_NSTATE, 2, (_n, 1), (2*_n + _noseLength, 2)) : +); // lipOutput + noseOutput\n tickTap = _tractTick : tapOut; // state, exc -> state, out\n // body: state, exc -> state, summed output of each tick (exc duplicated as\n // wires, not as subgraphs). Two ticks per sample (the original) or one.\n body(1) = tickTap;\n body(2) = (si.bus(_NSTATE), (si.bus(NEXC) <: si.bus(2*NEXC)))\n : (tickTap, si.bus(NEXC))\n : route(_NSTATE+1+NEXC, _NSTATE+NEXC+1,\n par(i, _NSTATE, (i+1, i+1)),\n (_NSTATE+1, _NSTATE+NEXC+1),\n par(i, NEXC, (_NSTATE+2+i, _NSTATE+1+i)))\n : (tickTap, _)\n : (si.bus(_NSTATE), +);\n // state below 1e-20 is flushed to zero (the lossless nose would otherwise\n // decay into denormals)\n _flush(x) = select2(abs(x) < 1e-20, x, 0.0);\n};\n\n//=========================== Full instrument ==========================================\n//======================================================================================\n\n//------------------------`(pt.)pinkTrombone`----------------------------------------\n// Glottis + tract. Mono output.\n//\n// #### Usage\n//\n// ```\n// pinkTrombone(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal) : _\n// ```\n//\n// Where:\n//\n// * `freq`: Positive fundamental frequency in Hz; the demo spans about 87..277 Hz.\n// * `tenseness`: Voice tenseness in 0..1; the default is 0.6.\n// * `voiced`: Voice gate: positive is on, zero is off. It acts like a finger on the\n// original\'s pitch keyboard: voicing ramps in and out, with no pressed onset.\n// * `wobble`: Pitch wobble amount in 0..1.\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `cIndex`: Constriction position in sections, 2..44; position 44 lies beyond the mouth cells.\n// * `cDiameter`: Touch diameter in model units, 0..3; at most 0.3 closes the tract, 3 leaves it open.\n// * `cActive`: Constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// pinkTrombone_test = pt.pinkTrombone(140, 0.6, 1, 0, 12.9, 2.43, 30, 3, 0, 0);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare pinkTrombone license "MIT";\npinkTrombone(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, nasal) =\n pinkTrombone2(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter, cIndex, cDiameter, cActive, 30, 3, 0, nasal);\n\n//------------------------`(pt.)pinkTrombone2`----------------------------------------\n// Glottis + tract with two constrictions. Mono output.\n//\n// #### Usage\n//\n// ```\n// pinkTrombone2(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal) : _\n// ```\n//\n// Where:\n//\n// * `freq`: Positive fundamental frequency in Hz; the demo spans about 87..277 Hz.\n// * `tenseness`: Voice tenseness in 0..1; the default is 0.6.\n// * `voiced`: Voice gate: positive is on, zero is off. It acts like a finger on the\n// original\'s pitch keyboard: voicing ramps in and out, with no pressed onset.\n// * `wobble`: Pitch wobble amount in 0..1.\n// * `tongueIndex`: Tongue position in sections, 12..29 (default 12.9).\n// * `tongueDiameter`: Tongue diameter in model units, 2.05..3.5 (default 2.43).\n// * `c1i`: First constriction position in sections, 2..44.\n// * `c1d`: First touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c1a`: First constriction gate, 0 or 1.\n// * `c2i`: Second constriction position in sections, 2..44.\n// * `c2d`: Second touch diameter in model units, 0..3; at most 0.3 closes the tract.\n// * `c2a`: Second constriction gate, 0 or 1.\n// * `nasal`: Velum gate: positive selects diameter 0.4; zero selects 0.01.\n//\n// #### Test\n// ```\n// import("stdfaust.lib");\n// pinkTrombone2_test = pt.pinkTrombone2(140, 0.6, 1, 0, 12.9, 2.43, 40, 0.2, 1, 20, 1.0, 1, 1);\n// ```\n//-------------------------------------------------------------------------------------\ndeclare pinkTrombone2 license "MIT";\npinkTrombone2(freq, tenseness, voiced, wobble, tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal) =\n glottis(freq, tenseness, voiced, wobble) : (_,_,!,!)\n : tract2(tongueIndex, tongueDiameter, c1i, c1d, c1a, c2i, c2d, c2a, nasal);\n',"fwvoice.lib":"//################################ fwvoice.lib ##############################################\n// FaustWave's singing voice — syllables from a model of the human vocal tract (Pink Trombone), a man and a woman.\n// For any patch: import(\"fwvoice.lib\"); then\n//\n// process = sayVoice(freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap) <: _, _;\n// effect = sayRoom(cutoff, lowcut, throw, feedback, bpm); // in a poly patch: its own filter and echo\n//\n// syllable (0..23, latched when a note starts): the man 0 aa, 1 ooh, 2 la, 3 na, 4 ma, 5 da, 6 ba, 7 oh, 8 no,\n// 9 hey, 10 yeah, 11 mmm — the woman the same + 12 (aa-f … mmm-f). Paste this menu into the slider for names\n// (the Performer's `each` sends them over MIDI CC 20 — [midi:ctrl 20]):\n// [style:menu{'aa':0;'ooh':1;'la':2;'na':3;'ma':4;'da':5;'ba':6;'oh':7;'no':8;'hey':9;'yeah':10;'mmm':11;\n// 'aa-f':12;'ooh-f':13;'la-f':14;'na-f':15;'ma-f':16;'da-f':17;'ba-f':18;'oh-f':19;'no-f':20;'hey-f':21;'yeah-f':22;'mmm-f':23}]\n//\n// The vowels are MEASURED, not guessed: the model rendered over a grid of tongue and lip shapes, F1/F2 read off, each\n// vowel the shape closest to German vowels — the man within 0.22 Bark, the woman (a 38-section tract instead of 44,\n// formants ~16 % higher) within 0.34 Bark. The consonants close the lips (m, b), the tongue tip at the ridge (n, d, l,\n// s), open the nose (m, n) or go unvoiced (s, h). Vibrato and glide after Paul Batchelor's \"Trio\". Both tracts run\n// all the time (Faust computes both branches): ~20 % of the audio budget offline — one voice per instrument (nvoices:1).\n// sayHim / sayHer run ONE tract (~9 %, measured 2026-11-10): the man's syllables (0..11) or the woman's (12..23), the\n// other's silent — two instruments, one for each, cost half of one that has both.\n//\n// SPDX-License-Identifier: CC0-1.0 — this library is free: use, change and share it without asking.\n// Built on pinktrombone-tract.lib (MIT, see its header): Faust's pinktrombone.lib with the tract length free.\n//##########################################################################################\n\ndeclare name \"FaustWave Voice\";\ndeclare author \"FaustWave\";\ndeclare version \"1.0\";\ndeclare license \"CC0-1.0\";\n\nimport(\"stdfaust.lib\");\n\n// the man's tract (Faust's own, 44 sections) and the woman's (38: formants ~16 % higher)\nsayMan = library(\"pinktrombone.lib\");\nsayWoman = library(\"pinktrombone-tract.lib\")[_n=38; _bladeStart=9; _tipStart=28; _lipStart=34; _noseLength=24;];\n\n// --- the sounds: 0 a, 1 e, 2 i, 3 o, 4 u, 5 m, 6 n, 7 l, 8 d, 9 b, 10 s, 11 h\n// tongue index / diameter, lips (diameter; 3 = open), tongue tip (diameter; 3 = away), nose, voiced\nsayTI = waveform{16, 27, 26, 19, 14, 20, 24, 24, 24, 20, 24, 16};\nsayTD = waveform{2.75, 2.35, 2.05, 2.25, 2.05, 2.6, 2.4, 2.4, 2.4, 2.6, 2.4, 2.75};\nsayLIP = waveform{1.4, 1.4, 3, 0.7, 0.7, 0, 3, 3, 3, 0, 3, 3};\nsayTIF = waveform{15, 24, 23, 17, 12, 17, 21, 21, 21, 17, 21, 15};\nsayTDF = waveform{2.45, 2.55, 2.15, 2.15, 2.05, 2.6, 2.4, 2.4, 2.4, 2.6, 2.4, 2.45};\nsayLIPF = waveform{3, 1.4, 3, 0.7, 0.7, 0, 3, 3, 3, 0, 3, 3};\nsayTIP = waveform{3, 3, 3, 3, 3, 3, 0, 0.7, 0, 3, 0.25, 3};\nsayNOS = waveform{0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};\nsayVOI = waveform{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0};\n\n// --- the syllables: sound 1 for d1 ms, sound 2 for d2 ms, then sound 3 held\n// aa ooh la na ma da ba oh no hey yeah mmm\nsayP1 = waveform{ 0, 4, 7, 6, 5, 8, 9, 3, 6, 11, 2, 5};\nsayD1 = waveform{ 1, 1, 60, 70, 80, 50, 50, 250, 70, 60, 80, 1};\nsayP2 = waveform{ 0, 4, 0, 0, 0, 0, 0, 3, 3, 1, 1, 5};\nsayD2 = waveform{ 1, 1, 1, 1, 1, 1, 1, 1, 250, 200, 120, 1};\nsayP3 = waveform{ 0, 4, 0, 0, 0, 0, 0, 4, 4, 2, 0, 5};\n\nsayField(w, i) = w, int(i) : rdtable;\n\n//------------------------------- sayVoice ----------------------------------\n// One sung note: `freq` (Hz) and `gain` (0..1) from the note, `gate` (> 0 while held), `syllable` (0..23, latched\n// when the note starts), `tense` (0 breathy .. 1 pressed), `wobble` (0/1, pitch drift), `vibrato` (0..1, comes in late,\n// deeper with the pitch), `glide` (s, pitch and loudness), `blur` (s, how soft one sound turns into the next), `snap`\n// (0..1, the autotune effect: notes jump, no vibrato). Mono out, before any level — the model speaks quietly\n// (a note peaks near -29 dBFS): lift it (×8 sits it with other instruments).\n//------------------------------------------------------------------------------\nsayVoice(freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap) = sayWho(1, 1, freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap);\n// one tract only: the man (his syllables sound, hers are silent) or the woman\nsayHim(freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap) = sayWho(1, 0, freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap);\nsayHer(freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap) = sayWho(0, 1, freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap);\n\n// `hasHim`, `hasHer`: constants 0/1 — a tract multiplied by a constant 0 is left out when the patch compiles\nsayWho(hasHim, hasHer, freq, gain, gate, syllable, tense, wobble, vibrato, glide, blur, snap) = hasHim * him + hasHer * her\nwith {\n rise = (gate > 0) > (gate' > 0);\n chosen = syllable : ba.sAndH(rise);\n woman = chosen >= 12;\n syl = chosen - 12 * woman;\n ms = ba.countup(ma.SR * 10, rise) / ma.SR * 1000;\n d1 = sayField(sayD1, syl);\n d2 = sayField(sayD2, syl);\n now = ba.if(ms < d1, sayField(sayP1, syl), ba.if(ms < d1 + d2, sayField(sayP2, syl), sayField(sayP3, syl)));\n\n soft(x) = x : si.smooth(ba.tau2pole(blur));\n tip = sayField(sayTIP, now) : soft;\n nose = sayField(sayNOS, now) : soft;\n sings = (gate > 0) * sayField(sayVOI, now);\n\n pitch = freq : si.smooth(ba.tau2pole(glide * (1 - snap) + 0.003 * snap));\n rate = 6.2 + 0.25 * no.lfnoise(0.7);\n onset = (gate > 0) : si.smooth(ba.tau2pole(0.4));\n cents = 35 * vibrato * (1 - snap) * onset * sqrt(pitch / 220);\n sung = pitch * pow(2, cents * os.osc(rate) / 1200);\n\n env = en.adsr(0.03, 0.1, 0.9, 0.25, gate);\n loud = gain : si.smooth(ba.tau2pole(glide));\n\n him = sayMan.pinkTrombone2(sung, tense, sings * (1 - woman), wobble,\n sayField(sayTI, now) : soft, sayField(sayTD, now) : soft,\n 41, lip, lip < 2.9, 36, tip, tip < 2.9, nose > 0.5) * env * loud\n with { lip = sayField(sayLIP, now) : soft; };\n her = sayWoman.pinkTrombone2(sung, max(0, tense - 0.15), sings * woman, wobble,\n sayField(sayTIF, now) : soft, sayField(sayTDF, now) : soft,\n 36, lip, lip < 2.9, 31, tip, tip < 2.9, nose > 0.5) * env * loud\n with { lip = sayField(sayLIPF, now) : soft; };\n};\n\n//------------------------------- sayRoom -----------------------------------\n// The voice's own room — stereo in, stereo out: a low cut (Hz: clears the bass range, the voice stops shadowing kick\n// and bass) and a low-pass `cutoff` (Hz), then an echo in the song's tempo (`bpm`; a dotted eighth left, a quarter\n// right) that `throw` (0..1) feeds and `feedback` (0..0.85) keeps. In a poly patch put it in `effect`, so the echo\n// rings past the note.\n//------------------------------------------------------------------------------\nsayRoom(cutoff, lowcut, throw, feedback, bpm) = filt, filt : side(0.75 * beat : si.smoo), side(beat : si.smoo)\nwith {\n filt = fi.highpass(2, lowcut) : fi.resonlp(cutoff, 0.8, 1);\n beat = 60 / bpm * ma.SR;\n side(d) = _ <: _, (*(throw) : (+ : de.fdelay(131072, d)) ~ *(feedback)) :> _;\n};\n","fwsync.lib":'declare name "FaustWave Sync";\ndeclare author "FaustWave";\ndeclare version "1.2";\ndeclare license "CC0-1.0";\ndeclare description "The host\'s transport through Faust\'s standard MIDI sync controls - [midi:start]/[midi:stop] and [midi:clock], 24 ticks a quarter note - as a patch needs it: the tempo (fwBpm) and a pulse as the play begins (fwReset). A host that plays them (FaustWave, a CLAP host through faustwasm-webclap, Faust\'s own MidiUI) keeps the patch in time.";\n\nimport("stdfaust.lib");\n\n// The two controls the host plays. One checkbox carries the play: 1 as it begins, 0 as it ends.\nfwSyncPlay = checkbox("fwsync play[midi:start][midi:stop]");\n// Toggles on every tick of the clock, on its sample.\nfwSyncClock = checkbox("fwsync clock[midi:clock]");\n// The song position, in sixteenths: the place of the clock\'s last tick — set by the host as the play begins and at each\n// jump (a loop, a click in the timeline), moved on by a sixth with each tick (MIDI\'s Song Position Pointer and its\n// clock; [midi:songpos] is proposed to Faust — the FaustWave IDE\'s docs/FAUST-UPSTREAM-PATCHES.md P1).\nfwSongPos = hslider("fwsync songpos[midi:songpos]", 0, 0, 1e9, 0.0001);\n\n// 1 on the sample of a tick (while playing).\nfwTick = (fwSyncClock != fwSyncClock\') * fwSyncPlay;\n\n// 1 on the first sample played, 0 after: where a phasor begins again (os.lf_sawpos_reset).\nfwReset = fwSyncPlay * (1 - fwSyncPlay\');\n\n// Samples since the play began — counted as an integer: in a float (Faust\'s single precision) the count stood still at\n// 2^24 samples, 5:49 at 48 kHz (measured, 2026-11-27; the tempo then read it and went to infinity — it reads only\n// spacings now, fwSyncStep below); an int counts 2^31, 12 h.\nfwSyncNow = (+(1) : *(1 - int(fwReset))) ~ _;\n\n// One step of the tick bookkeeping: the samples since the last tick D, the spacings of the ticks the average spans\n// summed Total, how many K, the ticks seen S. A spacing more than 0.3 % off the average starts it anew (a new tempo — a\n// tick\'s spacing strays by at most a sample, 0.11 % at 130 BPM); the average spans at most the last 240 ticks (ten\n// beats: a smaller change arrives within them) — past them each new spacing takes an average one\'s place; a new play\n// forgets it all. Only spacings are kept, never a sample\'s place in the song: small numbers, exact in a float however\n// long the song (it kept the places once, and they lost their last samples past 2^24 in single precision).\nfwSyncStep(D0, Total0, K0, S0) = D, Total, K, S with {\n keep = 1 - fwReset;\n d = D0 * keep;\n total = Total0 * keep;\n k = K0 * keep;\n s = S0 * keep;\n // the samples from the last tick to this one\n spacing = d + 1;\n avg = total / max(k, 1);\n jump = (k > 0) * (abs(spacing - avg) > 0.003 * avg);\n full = k >= 240;\n first = s < 1;\n D = select2(fwTick, spacing, 0);\n Total = select2(fwTick, total, select2(first, select2(jump, select2(full, total + spacing, total + spacing - avg), spacing), 0));\n K = select2(fwTick, k, select2(first, select2(jump, select2(full, k + 1, k), 1), 0));\n S = s + fwTick;\n};\n\n// The tempo from the ticks: their spacing averaged over every tick since the tempo last changed, rounded to 0.1 BPM -\n// a steady tempo is exact after a few ticks and stays put, so a delay time taken of it does not jump with each tick.\n// Before the first spacing: the last tempo known, else 120.\nfwBpm = fwSyncStep ~ (_, _, _, _) : tempo with {\n tempo(D, Total, K, S) = (select2(K > 0, _, rounded) ~ _) : \\(x).(select2(x > 0, 120, x)) with {\n rounded = floor(ma.SR * 60 / (24 * Total / max(K, 1)) * 10 + 0.5) / 10;\n };\n};\n\n// Where in a bar of n sixteenths the song is (16: 4/4, 12: 3/4, 14: 7/8), 0..1 — 0 on its one, by the ticks (96 a 4/4 bar).\nfwBarPhase(n) = fwSongPos / n : ma.frac;\n\n// 1 on the tick a bar of n sixteenths begins (its one), 0 elsewhere.\nfwBarStart(n) = fwTick * (fwBarPhase(n) == 0);\n'};function t(){return e.map(e=>`${e}${n[e]}`).join("\0")}export{t as bundledLibrariesMaterial};
@@ -0,0 +1 @@
1
+ import{n as s,r as t,t as o}from"./host-DPIuYxlL.js";import"./dist-BvRk9kiK.js";export{o as ClapHost,s as bundleOf,t as memoryImportOf};