stillmade-sdk 0.1.41 → 0.1.42

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 (48) hide show
  1. package/.stillmade/sdk-baseline.json +19 -19
  2. package/AGENTS.md +2 -2
  3. package/INTERFACE_DESIGN.md +5 -0
  4. package/PASTE_TO_LLM.md +12 -12
  5. package/SDK.md +44 -23
  6. package/UI_AESTHETIC.md +8 -1
  7. package/examples/check-clip.stillmade.json +4 -0
  8. package/examples/clean-text.stillmade.json +4 -0
  9. package/examples/custom-interface.stillmade.json +4 -0
  10. package/examples/describe-image.stillmade.json +4 -0
  11. package/examples/foley-cue.stillmade.json +4 -0
  12. package/examples/generate-image.stillmade.json +4 -0
  13. package/examples/generate-video.stillmade.json +4 -0
  14. package/examples/module-word-stats/stillmade.block.json +4 -0
  15. package/examples/narrate-script.stillmade.json +4 -0
  16. package/examples/numbered-takes.stillmade.json +4 -0
  17. package/examples/research-topic.stillmade.json +4 -0
  18. package/examples/score-a-scene.stillmade.json +4 -0
  19. package/examples/script-draft.stillmade.json +4 -0
  20. package/examples/summarize-page.stillmade.json +4 -0
  21. package/examples/text-workflow.stillmade.json +4 -0
  22. package/examples/thicken-lines.stillmade.json +4 -0
  23. package/examples/timeline-polish.stillmade.json +4 -0
  24. package/examples/transcribe-audio.stillmade.json +4 -0
  25. package/examples/word-count.stillmade.json +4 -0
  26. package/package.json +1 -1
  27. package/packages/block-cli/dev-host/assets/host.js +6 -1
  28. package/packages/block-cli/dev-host/assets/index.css +1 -1
  29. package/packages/block-cli/ready-gate.js +4 -0
  30. package/packages/block-cli/templates.js +7 -7
  31. package/packages/block-platform/block-readiness.js +3 -1
  32. package/packages/block-sdk/audio-generation-example.js +2 -2
  33. package/packages/block-sdk/builder-contract.js +3 -3
  34. package/packages/block-sdk/capability-example.js +1 -1
  35. package/packages/block-sdk/examples.js +3 -3
  36. package/packages/block-sdk/image-description-example.js +1 -1
  37. package/packages/block-sdk/image-generation-example.js +1 -1
  38. package/packages/block-sdk/media-analysis-example.js +1 -1
  39. package/packages/block-sdk/module-example.js +1 -1
  40. package/packages/block-sdk/speech-example.js +1 -1
  41. package/packages/block-sdk/state-example.js +1 -1
  42. package/packages/block-sdk/timeline-proposal-example.js +1 -1
  43. package/packages/block-sdk/transcription-example.js +1 -1
  44. package/packages/block-sdk/trigger-examples.js +2 -2
  45. package/packages/block-sdk/video-generation-example.js +1 -1
  46. package/packages/block-sdk/view-design.js +27 -1
  47. package/packages/block-sdk/web-example.js +2 -2
  48. package/packages/design-system/block-kit.css +5 -0
@@ -1486,6 +1486,7 @@ label:has(> textarea) {
1486
1486
 
1487
1487
  The shape of a Block page, top to bottom:
1488
1488
  .sm-block one workspace, no cards inside cards
1489
+ .sm-fields what the person sets, as one group on its own surface
1489
1490
  .sm-stage the thing being made (preview, media, result); biggest area
1490
1491
  .sm-settings settings side by side; .sm-choices[data-segmented] for short ones
1491
1492
  .sm-list many items, one line each; an item opens in place
@@ -1568,6 +1569,10 @@ label:has(> textarea) {
1568
1569
  :where(.sm-field) :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),select,textarea){width:100%;min-height:var(--touch-target,44px);padding:10px 12px;border:1px solid var(--border-tok);border-radius:var(--r-3,8px);background:var(--bg-elev-1);color:var(--fg);font:inherit}
1569
1570
  :where(.sm-field) :where(textarea){min-height:96px;resize:vertical}
1570
1571
  :where(.sm-fields){display:grid;gap:var(--s-4,16px);grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr))}
1572
+ /* Sections stand apart (owner, November 3, 2026: "make sure it's more separated"). The group of settings on a Block's
1573
+ page sits on its own surface, the same card StillMade's Step page gives its settings, so what goes in, the settings
1574
+ and the result read as separate parts. Only a top-level group: never a card inside a card. */
1575
+ :where(.sm-block) > :where(.sm-fields,.sm-settings){padding:var(--s-3,12px) var(--s-4,16px);border:1px solid var(--border);border-radius:var(--r-3,8px);background:var(--bg-secondary)}
1571
1576
  /* Compact (October 19, 2026): a short field is one row at every width. On a phone or in a
1572
1577
  narrow cell the label takes its own width and the control the rest; when the two do not
1573
1578
  fit, the control wraps under its label. */
@@ -1897,4 +1902,4 @@ label:has(> textarea) {
1897
1902
  .sm-player *,.sm-viewer,.sm-viewer *,.sm-expand-btn{transition:none!important;animation:none!important}
1898
1903
  }
1899
1904
  `,Q=u(f(),1),$=qf();function nU(e){switch(e){case`minus`:return(0,$.jsx)(`path`,{d:`M5 12h14`});case`messageCircle`:return(0,$.jsx)(`path`,{d:`M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8z`});case`arrowLeft`:return(0,$.jsx)(`path`,{d:`M20 12H4M11 5l-7 7 7 7`});case`link`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 .5l3-3a5 5 0 0 0-7-7l-2 2`}),(0,$.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7-.5l-3 3a5 5 0 0 0 7 7l2-2`})]});case`unlink`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`m18.8 12.3 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7`}),(0,$.jsx)(`path`,{d:`m5.2 11.7-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7`}),(0,$.jsx)(`path`,{d:`M8 2v3M2 8h3M16 19v3M19 16h3`})]});case`copy`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`9`,y:`9`,width:`12`,height:`12`,rx:`2`}),(0,$.jsx)(`path`,{d:`M15 9V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h4`})]});case`arrowUp`:return(0,$.jsx)(`path`,{d:`M12 20V4M5 11l7-7 7 7`});case`star`:return(0,$.jsx)(`path`,{d:`M12 3.5l2.6 5.3 5.9.9-4.25 4.15 1 5.85L12 16.95 6.75 19.7l1-5.85L3.5 9.7l5.9-.9z`});case`arrowUpRight`:return(0,$.jsx)(`path`,{d:`M7 17 17 7M8 7h9v9`});case`arrowDown`:return(0,$.jsx)(`path`,{d:`M12 4v16M5 13l7 7 7-7`});case`thumbsUp`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M7 10v11H3V10Z`}),(0,$.jsx)(`path`,{d:`M7 18c2 0 3 3 7 3h2.5a2 2 0 0 0 1.9-1.4l2.4-7A2 2 0 0 0 18.9 10H14l.7-3.5A3 3 0 0 0 11.8 3L7 10Z`})]});case`thumbsDown`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M7 14V3H3v11Z`}),(0,$.jsx)(`path`,{d:`M7 6c2 0 3-3 7-3h2.5a2 2 0 0 1 1.9 1.4l2.4 7a2 2 0 0 1-1.9 2.6H14l.7 3.5a3 3 0 0 1-2.9 3.5L7 14Z`})]});case`undo`:return(0,$.jsx)(`path`,{d:`M3 10h11a7 7 0 0 1 0 14M3 10l5-5M3 10l5 5`,transform:`translate(0 -3)`});case`redo`:return(0,$.jsx)(`path`,{d:`M21 7H10a7 7 0 0 0 0 14M21 7l-5-5M21 7l-5 5`});case`remix`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M5 5h5a5 5 0 0 1 5 5v9`}),(0,$.jsx)(`path`,{d:`m11 15 4 4 4-4`}),(0,$.jsx)(`path`,{d:`M5 19h2`}),(0,$.jsx)(`circle`,{cx:`5`,cy:`5`,r:`2`}),(0,$.jsx)(`circle`,{cx:`5`,cy:`19`,r:`2`})]});case`more`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,$.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]});case`palette`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`13.5`,cy:`6.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,$.jsx)(`circle`,{cx:`17`,cy:`11`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,$.jsx)(`circle`,{cx:`8.5`,cy:`7.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,$.jsx)(`circle`,{cx:`6.5`,cy:`12.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,$.jsx)(`path`,{d:`M12 3a9 9 0 0 0 0 18c1 0 1.6-.8 1.6-1.6 0-.5-.2-.8-.4-1.1-.3-.3-.4-.6-.4-1.1A1.6 1.6 0 0 1 14.3 15h1.9A4.8 4.8 0 0 0 21 10.2C21 6 16.9 3 12 3Z`})]});case`lock`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,$.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 8 0v4`})]});case`unlock`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,$.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 7.9-1`})]});case`pushpin`:return(0,$.jsxs)(`g`,{transform:`rotate(35 12 12)`,children:[(0,$.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`}),(0,$.jsx)(`path`,{d:`M12 14v7`})]});case`pushpinFilled`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`,fill:`currentColor`}),(0,$.jsx)(`path`,{d:`M12 14v7`})]});case`pin`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 21s7-5.7 7-11a7 7 0 0 0-14 0c0 5.3 7 11 7 11Z`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`10`,r:`2.5`})]});case`user`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,$.jsx)(`path`,{d:`M5 21a7 7 0 0 1 14 0`})]});case`image`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,$.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,$.jsx)(`path`,{d:`m21 15-5-5L5 21`})]});case`imageOff`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M2 2l20 20`}),(0,$.jsx)(`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`}),(0,$.jsx)(`path`,{d:`M13.5 13.5 6 21`}),(0,$.jsx)(`path`,{d:`m18 12 3 3`}),(0,$.jsx)(`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`}),(0,$.jsx)(`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`})]});case`film`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,$.jsx)(`path`,{d:`M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4`})]});case`folder`:return(0,$.jsx)(`path`,{d:`M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z`});case`list`:return(0,$.jsx)(`path`,{d:`M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01`});case`grid`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,$.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,$.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1.5`}),(0,$.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1.5`})]});case`zap`:return(0,$.jsx)(`path`,{d:`M13 2 4 14h7l-1 8 9-12h-7Z`});case`plug`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 22v-5M9 8V2M15 8V2`}),(0,$.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});case`book`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,$.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2Z`})]});case`bookOpen`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 7v14`}),(0,$.jsx)(`path`,{d:`M3 5v14h6a3 3 0 0 1 3 3 3 3 0 0 1 3-3h6V5h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3Z`})]});case`input`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`}),(0,$.jsx)(`path`,{d:`m10 17 5-5-5-5`}),(0,$.jsx)(`path`,{d:`M15 12H3`})]});case`upload`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 16V4M7 9l5-5 5 5`}),(0,$.jsx)(`path`,{d:`M5 20h14`})]});case`download`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 4v12M7 11l5 5 5-5`}),(0,$.jsx)(`path`,{d:`M5 20h14`})]});case`save`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M5 3h11l3 3v15H5Z`}),(0,$.jsx)(`path`,{d:`M8 3v5h7M8 21v-7h8v7`})]});case`search`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,$.jsx)(`path`,{d:`m20 20-3.5-3.5`})]});case`magnet`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M6 4h4v8a2 2 0 0 0 4 0V4h4v8a6 6 0 0 1-12 0Z`}),(0,$.jsx)(`path`,{d:`M6 8h4M14 8h4`})]});case`bot`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`4`,y:`8`,width:`16`,height:`11`,rx:`2`}),(0,$.jsx)(`path`,{d:`M12 8V4M9 13h.01M15 13h.01M9 16h6`})]});case`note`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`4`,y:`3`,width:`16`,height:`18`,rx:`2`}),(0,$.jsx)(`path`,{d:`M8 8h8M8 12h8M8 16h5`})]});case`clock`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,$.jsx)(`path`,{d:`M12 7v5l3 2`})]});case`calendar`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`5`,width:`18`,height:`16`,rx:`2`}),(0,$.jsx)(`path`,{d:`M16 3v4M8 3v4M3 10h18`})]});case`hourglass`:return(0,$.jsx)(`path`,{d:`M6 3h12M6 21h12M7 3c0 5 5 6 5 9s-5 4-5 9M17 3c0 5-5 6-5 9s5 4 5 9`});case`edit`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 20h9`}),(0,$.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`music`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M9 18V5l12-2v13`}),(0,$.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,$.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]});case`mic`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`}),(0,$.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,$.jsx)(`path`,{d:`M12 19v3`})]});case`target`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]});case`pointer`:return(0,$.jsx)(`path`,{d:`M4.5 3.5 20 10.4l-6.5 1.9a1.9 1.9 0 0 0-1.3 1.3L10.3 20z`,strokeLinejoin:`round`});case`sprout`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 21V9`}),(0,$.jsx)(`path`,{d:`M12 9C9 9 6 7 6 4c3 0 6 2 6 5ZM12 12c3 0 6-2 6-5-3 0-6 2-6 5Z`})]});case`hand`:return(0,$.jsx)(`path`,{d:`M8 13V5a1.5 1.5 0 0 1 3 0v6M11 11V4a1.5 1.5 0 0 1 3 0v7M14 11V6a1.5 1.5 0 0 1 3 0v8a6 6 0 0 1-6 6h-1a6 6 0 0 1-5.2-3l-2-3.5a1.5 1.5 0 0 1 2.6-1.5L8 14`});case`scissors`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,$.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.5`}),(0,$.jsx)(`path`,{d:`M8 8l12 8M8 16 20 8`})]});case`maximize`:return(0,$.jsx)(`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3M16 3h3a2 2 0 0 1 2 2v3M21 16v3a2 2 0 0 1-2 2h-3M3 16v3a2 2 0 0 0 2 2h3`});case`settings`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,$.jsx)(`path`,{d:`M19.4 15a1.6 1.6 0 0 0 .3 1.8 2 2 0 1 1-2.8 2.8 1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5 2 2 0 1 1-4 0 1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3 2 2 0 1 1-2.8-2.8 1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1 2 2 0 1 1 0-4 1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8 2 2 0 1 1 2.8-2.8 1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5 2 2 0 1 1 4 0 1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3 2 2 0 1 1 2.8 2.8 1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1 2 2 0 1 1 0 4 1.6 1.6 0 0 0-1.5 1Z`})]});case`scale`:return(0,$.jsx)(`path`,{d:`M12 3v18M7 21h10M6 7h12M6 7 3 14h6ZM18 7l-3 7h6ZM3 14a3 3 0 0 0 6 0M15 14a3 3 0 0 0 6 0`});case`checkbox`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,$.jsx)(`path`,{d:`m8 12 3 3 5-6`})]});case`warning`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M10.3 4 2.6 17a2 2 0 0 0 1.7 3h15.4a2 2 0 0 0 1.7-3L13.7 4a2 2 0 0 0-3.4 0Z`}),(0,$.jsx)(`path`,{d:`M12 9v4M12 17h.01`})]});case`sparkle`:return(0,$.jsx)(`path`,{d:`M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z`});case`check`:return(0,$.jsx)(`path`,{d:`m5 12 5 5 9-10`});case`x`:return(0,$.jsx)(`path`,{d:`M6 6 18 18M18 6 6 18`});case`plus`:return(0,$.jsx)(`path`,{d:`M12 5v14M5 12h14`});case`refresh`:return(0,$.jsx)(`path`,{d:`M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M3 21v-5h5`});case`play`:return(0,$.jsx)(`path`,{d:`M7 4v16l13-8Z`});case`pause`:return(0,$.jsx)(`path`,{d:`M9 5v14M15 5v14`});case`playFilled`:return(0,$.jsx)(`path`,{d:`M7 4.6v14.8c0 .8.9 1.2 1.5.8l11.4-7.4a1 1 0 0 0 0-1.6L8.5 3.8C7.9 3.4 7 3.8 7 4.6Z`,fill:`currentColor`,stroke:`none`});case`pauseFilled`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`}),(0,$.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`})]});case`volume2`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,$.jsx)(`path`,{d:`M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14`})]});case`volumeX`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,$.jsx)(`path`,{d:`m22 9-6 6M16 9l6 6`})]});case`minimize`:return(0,$.jsx)(`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3M21 8h-3a2 2 0 0 1-2-2V3M3 16h3a2 2 0 0 1 2 2v3M16 21v-3a2 2 0 0 1 2-2h3`});case`stop`:return(0,$.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`});case`chevronRight`:return(0,$.jsx)(`path`,{d:`m9 6 6 6-6 6`});case`chevronLeft`:return(0,$.jsx)(`path`,{d:`m15 6-6 6 6 6`});case`chevronDown`:return(0,$.jsx)(`path`,{d:`m6 9 6 6 6-6`});case`trash`:return(0,$.jsx)(`path`,{d:`M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-13`});case`layers`:return(0,$.jsx)(`path`,{d:`m12 3 9 5-9 5-9-5Zm9 9-9 5-9-5m18 4-9 5-9-5`});case`type`:return(0,$.jsx)(`path`,{d:`M4 6V4h16v2M12 4v16M9 20h6`});case`home`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M3 10.5 12 3l9 7.5`}),(0,$.jsx)(`path`,{d:`M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5`}),(0,$.jsx)(`path`,{d:`M9 21v-6h6v6`})]});case`menu`:return(0,$.jsx)(`path`,{d:`M4 6h16M4 12h16M4 18h16`});case`logout`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,$.jsx)(`path`,{d:`M16 17l5-5-5-5`}),(0,$.jsx)(`path`,{d:`M21 12H9`})]});case`help`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,$.jsx)(`path`,{d:`M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3`}),(0,$.jsx)(`path`,{d:`M12 17h.01`})]});default:return null}}function rU({name:e,size:t=`1em`,style:n,className:r,strokeWidth:i=1.5}){let a=nU(e);return a?(0,$.jsx)(`svg`,{viewBox:`0 0 24 24`,width:t,height:t,fill:`none`,stroke:`currentColor`,strokeWidth:i,strokeLinecap:`round`,strokeLinejoin:`round`,className:r,style:{display:`inline-block`,verticalAlign:`-0.14em`,flexShrink:0,...n||{}},"aria-hidden":`true`,children:a}):null}var iU=`sm.blockZoom.`;function aU(e){try{let t=e?localStorage.getItem(iU+e):null,n=Number(t);return t&&t!==`auto`&&Number.isFinite(n)?n:`auto`}catch{return`auto`}}function oU(e,t){try{if(!e)return;t===`auto`?localStorage.removeItem(iU+e):localStorage.setItem(iU+e,String(t))}catch{}}function sU(e){if(!e)return 0;let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`)&&t.clientHeight>0)break;t=t.parentElement}let n=t&&t!==document.body?t.getBoundingClientRect():{top:0},r=t&&t!==document.body?t.clientHeight:innerHeight,i=e.getBoundingClientRect().top-n.top+(t&&t!==document.body?t.scrollTop:scrollY);return Math.max(280,Math.round(r-Math.min(i,r*.5)-24))}var cU=(e,t)=>Math.round(Math.min(BH,Math.max(zH,e+t))*100)/100;function lU({zoom:e=1,mode:t=`auto`,onChange:n}){let r=t===`auto`?e:t,i=e=>n(cU(r,e));return(0,$.jsxs)(`div`,{className:`block-zoom-control`,role:`group`,"aria-label":`Block size`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(-VH),disabled:r<=zH,"aria-label":`Smaller`,title:`Smaller`,"data-icon-action":`true`,children:(0,$.jsx)(rU,{name:`minus`,size:14})}),(0,$.jsx)(`button`,{type:`button`,className:`block-zoom-mode`,onClick:()=>n(`auto`),"aria-pressed":t===`auto`,title:t===`auto`?`Sized to fit automatically`:`Size automatically`,children:t===`auto`?`Auto · ${Math.round(e*100)}%`:`${Math.round(r*100)}%`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(VH),disabled:r>=BH,"aria-label":`Bigger`,title:`Bigger`,"data-icon-action":`true`,children:(0,$.jsx)(rU,{name:`plus`,size:14})})]})}var uU=(0,Q.createContext)(null),dU=null,fU=new Set,pU=()=>dU;function mU(e){return fU.add(e),()=>fU.delete(e)}function hU(e,t,n){let r=globalThis.modernScreenshot;if(delete globalThis.modernScreenshot,!r)return;let i=!1,a=[],o=new WeakSet,s=e=>{if(e?.nodeType!==1||o.has(e))return;let t=e.getBoundingClientRect();t.width*t.height<400||t.height>900||(a.push({x:t.left,y:t.top,width:t.width,height:t.height}),a.length>40&&a.shift())},c=()=>{i||(i=!0,setTimeout(()=>{i=!1,n({channel:e,session:t,op:`view-changed`,rects:a.splice(0)},`*`)},100))},l=e=>e.type===`childList`&&[...e.addedNodes,...e.removedNodes].every(e=>o.has(e))||o.has(e.target);new MutationObserver(e=>{let t=e.filter(e=>!l(e));if(t.length){for(let e of t)if(e.type===`childList`)for(let t of e.addedNodes)s(t.nodeType===1?t:t.parentElement);else e.type===`characterData`&&s(e.target.parentElement);c()}}).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,characterData:!0});for(let e of[`input`,`change`,`scroll`])addEventListener(e,c,!0);addEventListener(`message`,async i=>{let a=i.data;if(i.source!==parent||!a||a.channel!==e||a.session!==t||a.op!==`capture-view`||typeof a.id!=`string`)return;let s=Math.max(0,Number(a.top)||0),c=Math.min(4e3,Math.max(1,Number(a.height)||innerHeight)),l=document.createElement(`div`);o.add(l);try{l.style.cssText=`all:initial;position:fixed;left:-99999px;top:0;visibility:hidden`;let i=l.attachShadow({mode:`closed`}),o=document.createElement(`div`);i.append(o),document.documentElement.append(l);let u=await r.createContext(document.body,{scale:2,width:innerWidth,height:c,timeout:4e3,features:{restoreScrollPosition:!0},filter:e=>e!==l&&!(/^(VIDEO|AUDIO)$/.test(e.tagName)&&(e.readyState<2||!e.getClientRects().length)),style:{margin:getComputedStyle(document.body).margin,overflow:`visible`,transform:`translateY(${-s}px)`}});u.sandbox={contentWindow:{document:{createElement:e=>document.createElement(e),createElementNS:(e,t)=>document.createElementNS(e,t),body:o},getComputedStyle:(e,t)=>getComputedStyle(e,t)},remove(){}};let d=await createImageBitmap(await r.domToCanvas(u));n({channel:e,session:t,op:`capture-view-result`,id:a.id,bitmap:d},`*`,[d])}catch(r){n({channel:e,session:t,op:`capture-view-result`,id:a.id,error:String(r?.message||r).slice(0,300)},`*`)}finally{l.remove()}})}Ct();function gU(e){return V(Array.isArray(e)&&e.length>0&&e.length<=128&&e.every(e=>typeof e==`string`&&/^[a-f0-9]{64}$/.test(e)),`SCHEMA`,`Provide 1–128 exact source digests`),[...new Set(e)]}async function _U(e){ft(e);let t=e?.stages&&e.packages||[];return V(Array.isArray(t)&&t.length<128,`LIMIT`,`Too many packaged Blocks for execution review`),gU(await Promise.all([e,...t].map(e=>mt(e))))}async function vU(e){let t=await _U(e),n=new Set(t),r=e?.stages?e.packages||[]:[e],i=e=>{V(e&&typeof e.digest==`string`&&/^[a-f0-9]{64}$/.test(e.digest),`SCHEMA`,`Block lineage needs exact source digests`),n.add(e.digest),V(n.size<=128,`LIMIT`,`Block source and ancestry exceed the security review limit`)};for(let e of r){let t=e.manifest?.provenance;t?.remixedFrom!==void 0&&i(t.remixedFrom);let n=t?.remixAncestors??[];V(Array.isArray(n)&&n.length<=64,`SCHEMA`,`Block ancestry must contain at most 64 exact source references`),n.forEach(i);let r=e.portable?.lineage?.parents??[];V(Array.isArray(r)&&r.length<=16,`SCHEMA`,`Portable lineage must contain at most 16 exact source references`),r.forEach(i)}return gU([...n])}var yU=`stillmade.block-security.v1`,bU=new Map;function xU(e,t){let n=e?.revision||0,r=t.revision||0;return{revision:Math.max(n,r),published:t.published||e?.published===!0,revoked:n>r?e.revoked:n===r?t.revoked||e?.revoked===!0:t.revoked}}function SU(){try{let e=JSON.parse(globalThis.localStorage?.getItem(yU)||`{}`);for(let[t,n]of Object.entries(e))/^[a-f0-9]{64}$/.test(t)&&n&&typeof n.revoked==`boolean`&&typeof n.published==`boolean`&&Number.isInteger(n.revision)&&n.revision>=0&&bU.set(t,xU(bU.get(t),n))}catch{}return bU}function CU(e){let t=SU();for(let n of e){let e=t.get(n.digest);(n.revoked||n.published||e)&&t.set(n.digest,xU(e,n))}try{globalThis.localStorage?.setItem(yU,JSON.stringify(Object.fromEntries(t)))}catch{}}var wU=()=>Object.assign(Error(`This exact Block version has been quarantined by StillMade. Use a reviewed replacement.`),{code:`BLOCK_REVOKED`});async function TU(e,{signal:t}={}){let n=await vU(e),r=SU();if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});let i=new AbortController,a=()=>i.abort();t?.addEventListener(`abort`,a,{once:!0});let o=setTimeout(a,3e3),s;try{let e=await fetch(`/api/blocks/runtime-policy`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:{"Content-Type":`application/json`},body:JSON.stringify({digests:n}),signal:i.signal});if(!e.ok)throw Error(`Block security check unavailable`);if(s=await e.json(),!Array.isArray(s.digests)||s.digests.length!==n.length||new Set(s.digests.map(e=>e.digest)).size!==n.length||s.digests.some(e=>!n.includes(e.digest)||typeof e.revoked!=`boolean`||typeof e.published!=`boolean`||!Number.isInteger(e.revision)||e.revision<0))throw Error(`Invalid security response`);CU(s.digests)}catch{if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});if(n.some(e=>r.get(e)?.revoked))throw wU();if(n.some(e=>r.get(e)?.published))throw Object.assign(Error(`Reconnect to check the safety of this published Block before running it.`),{code:`REVOCATION_UNAVAILABLE`});return{checked:!1}}finally{clearTimeout(o),t?.removeEventListener(`abort`,a)}if(n.some(e=>SU().get(e)?.revoked))throw wU();return{checked:!0}}var EU=c({loadViewAssets:()=>DU});async function DU(e,{signal:t}={}){let n={};for(let[r,i]of Object.entries(e?.files||{})){let a=await fetch(`/__dev/files/`+i.sha256,{signal:t});if(!a.ok)throw Error(r+` is missing from the Block folder.`);let o=await qV(e,r,new Uint8Array(await a.arrayBuffer()));n[r]={mediaType:i.mediaType,base64:OU(o)}}return n}var OU,kU=o((()=>{JV(),OU=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}}));O(),Ct(),di();var AU=`stillmade.block.view.v1`,jU=5e3,MU=()=>globalThis.crypto.randomUUID(),NU=`*{box-sizing:border-box}html{container:stillmade-view/inline-size;overflow-wrap:anywhere}body{min-width:0;margin:0;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}h1,h2{font:200 italic clamp(26px,8cqi,32px)/1.1 var(--font-display);letter-spacing:var(--tr-display)}button,input,textarea,select,summary{font:inherit;color:inherit;max-width:100%}button,input,textarea,select{min-height:44px;border:1px solid var(--border-tok);border-radius:var(--r-3);padding:10px 14px;background:transparent}:where(details:not(.sm-hint))>summary{display:flex;align-items:center;min-height:44px;cursor:pointer}.sm-hint>summary{max-width:none}button{min-width:44px;cursor:pointer;border-radius:var(--r-pill);background:var(--fg);color:var(--bg)}button:disabled{opacity:.5;cursor:default}textarea{display:block;width:100%;min-height:120px}input[type=checkbox],input[type=radio]{width:20px;height:20px;min-height:0;padding:0;margin:0 8px 0 0;vertical-align:middle;accent-color:var(--fg)}input[type=range]{width:100%;min-height:32px;padding:0;border:0;accent-color:var(--fg)}img,video,canvas{max-width:100%}:focus-visible{outline:2px solid var(--signal);outline-offset:3px}@container stillmade-view (max-width:360px){body{padding:12px}button,input,textarea,select{font-size:16px}}`,PU=`*{box-sizing:border-box}html{overflow-wrap:anywhere}body{min-width:0;margin:0;padding:16px;overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}`,FU=`:where(html[data-stillmade-center="1"])>:where(body)>:where(:not([data-stillmade-host])),:where(html[data-stillmade-center="2"])>:where(body)>:where(:not([data-stillmade-host]))>:where(*){margin-inline:auto}`,IU=`html[data-stillmade-pick],html[data-stillmade-pick] *{cursor:crosshair!important}html[data-stillmade-pick] [data-stillmade-media]{display:none!important}`,LU=e=>JSON.stringify(e).replace(/</g,`\\u003c`).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`);function RU(e){if(ft(e),new TextEncoder().encode(JSON.stringify(e)).length>YV.messageBytes)throw Error(`Preview data exceeds 4 MiB`);return structuredClone(e)}var zU=e=>gt(e)&&[`image`,`video`,`audio`].includes(e.kind)&&[`assetId`,`versionId`,`url`].every(t=>typeof e[t]==`string`&&e[t])?pt([e.kind,e.assetId,e.versionId,e.url]):``;function BU(e){let t=(0,Q.useRef)({has:!1,original:null,signature:null,value:null});if(t.current.has&&Object.is(t.current.original,e))return t.current.value;let n=e===void 0?`undefined`:pt(e);return t.current.signature===n?t.current.original=e:t.current={has:!0,original:e,signature:n,value:e},t.current.value}function VU(e,t=[]){return Array.isArray(e)?(e.forEach(e=>VU(e,t)),t):gt(e)?zU(e)?(t.push(e),t):(Object.values(e).forEach(e=>VU(e,t)),t):t}var HU=e=>Array.isArray(e)?e.length>0&&e.every(HU):!!zU(e);function UU(e,t,n){if(!gt(e)||!Object.values(e).length||!Object.values(e).every(HU))throw Error(`Only complete saved media references can be chosen as outputs.`);let r=new Set(VU(t).map(zU));for(let t of VU(e))if(!r.has(zU(t))&&!n?.authorizesMedia(t))throw Error(`Choose media supplied by this workspace or recorded in this session.`);return RU(e)}function WU(e){let t=RU(e);if(!gt(t)||!ht(t,`image`))throw Error(`Choose a valid image supplied by this workspace.`);if(t.role!==void 0&&(typeof t.role!=`string`||!/^[a-z][a-z0-9_]{0,79}$/.test(t.role)))throw Error(`This image has an invalid semantic role.`);if(!Array.isArray(t.data)&&!([`assetId`,`versionId`,`url`].every(e=>typeof t[e]==`string`&&t[e].length>0)&&t.assetId.length<=512&&t.versionId.length<=512&&t.url.length<=32768))throw Error(`Keep the complete image reference supplied by this workspace.`);return t}function GU(e){let t=RU(e);if(!(gt(t)&&Object.keys(t).length===3&&[`url`,`width`,`height`].every(e=>Object.hasOwn(t,e))&&[`width`,`height`].every(e=>Number.isInteger(t[e])&&t[e]>0&&t[e]<=YV.imagePreviewEdge))||typeof t.url!=`string`||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(t.url))throw Error(`The host returned an invalid image preview.`);let n=t.url.slice(22);if(n.length%4!=0)throw Error(`The host returned an invalid image preview.`);let r=atob(n.slice(0,44)),i=e=>r.charCodeAt(e),a=e=>i(e)*16777216+i(e+1)*65536+i(e+2)*256+i(e+3);if(r.length<33||![137,80,78,71,13,10,26,10].every((e,t)=>i(t)===e)||a(8)!==13||r.slice(12,16)!==`IHDR`||a(16)!==t.width||a(20)!==t.height)throw Error(`The host returned an invalid image preview.`);return t}function KU(e,t,n=`light`,r=`package`,i=!1,a=[],o=null,s=!1,c=!1,{assets:l={},filming:u=null}={}){aH(e);let d=fH(e),f=r===`package`?e.appearance??`host`:r;f!==`original`&&!d&&SH(e,{appearance:`host`});let p=(f===`original`?e.css??``:e.themedCss??e.css??``)+`
1900
- `+(d?``:wH),m=globalThis.crypto.randomUUID().replaceAll(`-`,``),h=`__sm_view_${m}`,g=`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,_=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,v=`(()=>{"use strict";document.currentScript.remove();const session=${LU(t)},channel=${LU(AU)},send=parent.postMessage.bind(parent);let input={},ready=false,inputRevision=0,editRevision=0,sequence=0,pending=null,pendingAdopt=null,adoptSequence=0,pendingImage=null,imageSequence=0,pendingDesktop=null,desktopSequence=0;const mediaURLs=new Set();const mintedImages=new Set();Object.defineProperty(globalThis,${LU(_)},{configurable:true,value:url=>mintedImages.has(url)});const clearMedia=()=>{for(const url of mediaURLs)URL.revokeObjectURL(url);mediaURLs.clear()};const listeners=new Set();let calls=0,started=0;const now=performance.now.bind(performance),resetTask=setTimeout.bind(globalThis);let gestureId=0,gestureAt=-Infinity;for(const type of ["pointerdown","keydown"])addEventListener(type,event=>{if(event.isTrusted){gestureId++;gestureAt=now();}},true);${d?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${gH.toString()})(channel,session,send,${LU({guardName:g,taskMs:sH.taskMs,assets:l})});`:`Object.defineProperty(globalThis,${LU(h)},{configurable:true,value:()=>{if(calls===0){started=now();resetTask(()=>{calls=0},0)}if(++calls>10000||now()-started>50)throw Error("Interface is doing too much work. Move processing into the Block runtime.")}});addEventListener("message",event=>{if(event.isTrusted&&event.source===parent)calls=0},true);`}let controlEffects=0;let assisted=false,trackedCalls=new Set(),trackedFailure=null,controlOffset=0;const track=promise=>{if(assisted){trackedCalls.add(promise);promise.then(()=>trackedCalls.delete(promise),error=>{trackedFailure=error;trackedCalls.delete(promise)})}return promise};const controlSnapshot=(offset=controlOffset,automatic=true)=>{try{let snapshot;try{snapshot=dynamicUI.inspectControls({offset})}catch(error){if(!automatic||error.message!=="Choose a current control page"||!Number.isSafeInteger(offset)||offset<0)throw error;snapshot=dynamicUI.inspectControls({offset:0});}controlOffset=snapshot.offset;send({channel,session,op:"view-controls",snapshot},"*")}catch(error){send({channel,session,op:"view-controls-error",error:String(error.message).slice(0,1000)},"*")}};const dynamicUI=(${or.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${ar.toString()})(channel,session,${LU(rr)},sharedLifecycle);const textControls=${i?`(()=>{${Yn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${LU(o)},send});})()`:`null`};const sharedControls=(${Jn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${LU(a)});const {documentTools,sharedDocuments}=(${Xn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${Ot.toString()})((kind,value)=>{if(kind==="media"){if(mediaURLs.size>=2)throw Error("Release a previous media preview before opening another");if(!["video","audio"].includes(value.kind))throw Error("Choose an audio or video reference");}return new Promise((resolve,reject)=>{const id=String(++imageSequence);pendingImage={id,resolve,reject,media:kind==="media"};send({channel,session,op:kind==="media"?"preview-media":"preview-image",id,value},"*")})});const connectionAPI=(${Et.toString()})(${LU(AU)},${LU(t)},${c},send),workAPI=(${E.toString()})(${LU(AU)},${LU(t)},${s},send);const liveBridge=(${Dt.toString()})(${LU(AU)},${LU(t)},send,(operation,args)=>api.desktop(operation,args));const api=Object.freeze({...connectionAPI,...workAPI,live:liveBridge.live,${d?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,`:``}connectedApp(...args){controlEffects++;return track(connectionAPI.connectedApp(...args))},sharedWork(...args){controlEffects++;return track(workAPI.sharedWork(...args))},previewSharedWorkMedia(...args){controlEffects++;return track(workAPI.previewSharedWorkMedia(...args))},schemaFields:(${sr.toString()})(${JSON.stringify(a)}),...sharedAPI,...documentTools,connectDocument:sharedDocuments.connectDocument,bindShared:sharedControls.bindShared,setSharedDefaults:sharedControls.setSharedDefaults,scheduleSharedEdit:sharedControls.scheduleSharedEdit,render:dynamicUI.render,onAction:dynamicUI.onAction,releaseMedia(url){if(mediaURLs.delete(url))URL.revokeObjectURL(url)},previewMedia(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("media",value))},desktop(operation,args={}){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingDesktop)return Promise.reject(Error("A desktop request is already pending"));if(typeof operation!=="string"||JSON.stringify(args).length>131072)return Promise.reject(Error("Invalid desktop request"));return track(new Promise((resolve,reject)=>{const id=String(++desktopSequence);pendingDesktop={id,resolve,reject};send({channel,session,op:"desktop",id,operation,args},"*")}))},get input(){return structuredClone(input)},onInput(fn){if(typeof fn!=="function")throw Error("Expected a function");listeners.add(fn);if(ready)fn(structuredClone(input));return()=>listeners.delete(fn)},useOutput(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingAdopt)return Promise.reject(Error("An output choice is already pending"));let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded output values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++adoptSequence);pendingAdopt={id,resolve,reject};send({channel,session,op:"use-output",id,outputs:values},"*")}))},previewImage(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value))},run(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pending)return Promise.reject(Error("A run is already in progress"));try{dynamicUI.assertCommitted();sharedControls.assertNoComposition();}catch(error){return Promise.reject(error);}let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded input values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++sequence),requested=JSON.parse(serialized),sourceRevision=inputRevision,localRevision=editRevision,call={id,resolve,reject,sent:false};pending=call;Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>{dynamicUI.assertCommitted();sharedControls.assertNoComposition();if(pending!==call||!ready)throw Error("Preview was closed before its edits were saved.");if(inputRevision!==sourceRevision||editRevision!==localRevision)throw Error("The input changed while edits were saving. Review it before running again.");const savedText=textControls?.getValues?.()||{};for(const [key,value] of Object.entries(savedText)){const captured=typeof requested[key]==="string"?requested[key]:typeof requested[key]?.text==="string"?requested[key].text:null;if(captured!==null&&captured!==value)throw Error("The input changed while shared text was saving. Review it before running again.");}if(!sharedAPI.getShared().canEdit)throw Error("Shared editing is unavailable or read only.");call.sent=true;send({channel,session,op:"run",id,input:requested,...(gestureId?{gesture:{id:gestureId,age:now()-gestureAt}}:{})},"*");}).catch(error=>{if(pending===call){pending=null;call.reject(error);}});}))}});Object.defineProperty(globalThis,"StillMade",{value:api,writable:false,configurable:false});addEventListener("message",event=>{if(event.source!==parent||!event.data||event.data.channel!==channel||event.data.session!==session)return;const data=event.data;if(liveBridge.receive(data))return;if(data.op==="inspect-view-controls"){controlSnapshot(data.offset,false);return;}if(data.op==="locate-view-control"&&typeof data.id==="string"){let rect=null;try{rect=dynamicUI.locateControl(data.control)}catch{}send({channel,session,op:"view-control-rect",id:data.id,rect},"*");return;}if(data.op==="dispatch-named-text"&&typeof data.id==="string"){Promise.resolve().then(()=>textControls.dispatchNative(data.control,data.id)).then(()=>send({channel,session,op:"named-text-result",token:${LU(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${LU(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${LU(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${LU(o)},snapshot:textControls.inspectNative()},"*");return;}if(data.op==="dispatch-view-control"&&typeof data.id==="string"){if(assisted){send({channel,session,op:"view-control-result",id:data.id,error:"A declared control is already running"},"*");return;}assisted=true;trackedFailure=null;const controlDocumentSeal=sharedDocuments.captureControlSettlement(),controlSharedSeal=sharedLifecycle.captureControlState(),controlInputRevision=inputRevision,controlEffectRevision=controlEffects;const personalControlUnchanged=()=>controlDocumentSeal&&inputRevision===controlInputRevision&&controlEffects===controlEffectRevision&&JSON.stringify(sharedLifecycle.captureControlState())===JSON.stringify(controlSharedSeal)&&!controlSharedSeal.closed&&controlSharedSeal.ready&&!controlSharedSeal.pending&&!controlSharedSeal.queued&&!controlSharedSeal.failed&&sharedDocuments.unchangedControlSettlement(controlDocumentSeal);dynamicUI.dispatchControl(data.control,async()=>{for(let round=0;round<16;round++){await Promise.allSettled(Array.from(trackedCalls));await dynamicUI.flushAll();await sharedControls.flushAll();if(personalControlUnchanged())await sharedDocuments.settleControl(controlDocumentSeal);else await sharedDocuments.flushAll();await sharedLifecycle.flushSharedWrites();await new Promise(resolve=>setTimeout(resolve,0));if(trackedFailure)throw trackedFailure;if(!trackedCalls.size){if(controlDocumentSeal&&!personalControlUnchanged())await sharedDocuments.flushAll();dynamicUI.assertCommitted();sharedControls.assertNoComposition();return;}}throw Error("Declared action did not settle");}).then(()=>send({channel,session,op:"view-control-result",id:data.id},"*"),error=>send({channel,session,op:"view-control-result",id:data.id,error:String(error?.message||"Declared action failed").slice(0,1000)},"*")).finally(()=>{assisted=false;controlSnapshot()});return;}if(data.op==="flush-shared"&&typeof data.id==="string"){Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>dynamicUI.flushAll()).then(()=>sharedControls.assertNoComposition()).then(()=>send({channel,session,op:"flush-shared-result",id:data.id},"*"),error=>send({channel,session,op:"flush-shared-result",id:data.id,error:String(error?.message||"Pending edits could not be confirmed").slice(0,1000)},"*"));return;}if(data.op==="desktop-result"&&pendingDesktop&&data.id===pendingDesktop.id){const call=pendingDesktop;pendingDesktop=null;data.error?call.reject(Error(data.error)):call.resolve(data.result)}else if(data.op==="use-output-result"&&pendingAdopt&&data.id===pendingAdopt.id){const call=pendingAdopt;pendingAdopt=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="input"){inputRevision+=1;if(pending&&!pending.sent){pending.reject(Error("Preview input changed before its edits were saved."));pending=null;}clearMedia();previews.reset();if(pendingImage)pendingImage.reject(Error("Preview input changed"));pendingImage=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview input changed"));pendingAdopt=null;input=data.input;ready=true;try{sharedControls.useInputDefaults(input)}catch{}for(const fn of listeners)try{fn(structuredClone(input))}catch(error){send({channel,session,op:"interface-error",error:String(error?.message||"The Block interface could not display its input").slice(0,1000)},"*")}}else if(data.op==="result"&&pending?.sent&&data.id===pending.id){const call=pending;pending=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="preview-media-result"&&pendingImage?.media&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error)call.reject(Error(data.error));else{try{const url=URL.createObjectURL(data.preview.blob);mediaURLs.add(url);call.resolve({kind:data.preview.kind,url,mimeType:data.preview.blob.type,bytes:data.preview.blob.size})}catch(error){call.reject(error)}}}else if(data.op==="preview-image-result"&&pendingImage&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error){call.reject(Error(data.error));}else{const url=data.preview?.url;if(typeof url==="string"){mintedImages.delete(url);mintedImages.add(url);if(mintedImages.size>64)mintedImages.delete(mintedImages.values().next().value)}call.resolve(data.preview)}}else if(data.op==="dispose"){liveBridge.dispose();clearMedia();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview was reset"));pendingAdopt=null;if(pendingImage)pendingImage.reject(Error("Preview was reset"));pendingImage=null;if(pending)pending.reject(Error("Preview was reset"));pending=null;listeners.clear();ready=false}});addEventListener("input",()=>{editRevision+=1;},true);addEventListener("change",()=>{editRevision+=1;},true);addEventListener("compositionstart",()=>{editRevision+=1;},true);addEventListener("keydown",event=>{if(event.key==="Escape"&&!document.documentElement.hasAttribute("data-stillmade-stage"))send({channel,session,op:"escape"},"*")},true);addEventListener("click",event=>{if(event.target.closest?.("a,area"))event.preventDefault()},true);send({channel,session,op:"ready"},"*");})();`,y=d?`document.currentScript.remove();for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${hH(e.javascript||``,g)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${h})=>{"use strict";delete globalThis[${LU(h)}];for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${oH(e.javascript||``,h)}\n})(globalThis[${LU(h)}]);`.replace(/<\/script/gi,`<\\/script`);return`<!doctype html><html data-mode="${[`dark`,`white`].includes(n)?n:`light`}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${m}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${d?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${d?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${CH.replace(/@font-face\s*\{[^}]*\}/g,``)}${d?PU:NU}${TH}${d?``:FU}${(p||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${IU}</style></head><body>${e.html}${u?`<script nonce="${m}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${m}">${v.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${m}">document.currentScript.remove();${u?`(${hU.toString()})(${LU(AU)},${LU(t)},parent.postMessage.bind(parent));`:``}(${LH.toString()})(${LU(AU)},${LU(t)});(${RH.toString()})(${LU(AU)},${LU(t)});(${WH.toString()})(${LU(AU)},${LU(t)},(${HH.toString()}),"auto",(${UH.toString()}),${!d});(${GH.toString()})(${LU(AU)},${LU(t)},(${KH.toString().replace(/<\/script/gi,`<\\/script`)})(),${LU(tU)},{minted:(()=>{const read=globalThis[${LU(_)}];delete globalThis[${LU(_)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${OH.toString()})(${LU(AU)},${LU(t)},((validateCursorAnchor)=>(${DH.toString()}))(${EH.toString()}));(${kH.toString()})(${LU(AU)},${LU(t)},(${jH.toString()}));<\/script><script nonce="${m}">${y}<\/script></body></html>`}function qU({activity:e,declaresFolders:t,session:n}){let[r,i]=(0,Q.useState)(!1),a=e?.folders||[],o=e?.entries||[];if(!t&&!o.length)return null;let s=r=>{r.currentTarget.open&&t&&!e&&n.current?.call(`folder.shared`).catch(()=>{})},c=async e=>{i(!0);try{await n.current?.call(`folder.forget`,{folder:e.id})}catch{}finally{i(!1)}};return(0,$.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,$.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,$.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,$.jsx)(`ul`,{children:o.map(e=>(0,$.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,$.jsx)(`p`,{children:`Nothing yet.`})]})}function JU({view:e,input:t={},sharedView:n=null,presenceKey:r=null,peers:i=[],actorId:a=null,onSharedChange:o,sharedText:s=null,sharedWork:c=null,connectedApp:l=null,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m,policyContent:h,policyParent:g,currentAppViewPolicy:_=null,title:v=`Block preview`,height:y=480,fitContent:x=!1,resetKey:E=0,theme:D,appearance:O=`package`,lockedInputKeys:k=[],agentContext:A=null}){let j=BU(e),M=BU(h),N=BU(g),P=[`comfyui`,`capability`].includes(M?.manifest?.runtime)||!!M?.manifest?.desktopTools?.length||M?.manifest?.runtime===`module`&&!!M?.manifest?.permissions?.capabilities?.length,F=M?.capability?.operation===`image.generate`?9e5:36e4,I=(0,Q.useRef)(null),ee=(0,Q.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m}),te=(0,Q.useRef)(t),[L,R]=(0,Q.useState)(``),[ne,z]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(0),ae=(0,Q.useRef)(null),oe=(0,Q.useRef)(null),[B,se]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)(null),[ue,de]=(0,Q.useState)(null),fe=M?.manifest?.id||null,[pe,me]=(0,Q.useState)(()=>aU(fe)),[he,ge]=(0,Q.useState)(null),_e=(0,Q.useRef)(pe);_e.current=pe;let ve=e=>{me(e),oU(fe,e)},ye=(0,Q.useRef)(1);ye.current=pe===`auto`?he?.zoom||1:pe;let be=(0,Q.useRef)(ve);be.current=ve;let xe=(0,Q.useContext)(uU),Se=(0,Q.useRef)(xe);Se.current=xe;let[Ce,we]=(0,Q.useState)(null),[Te,Ee]=(0,Q.useState)(null),[De,Oe]=(0,Q.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),ke=(0,Q.useRef)(`light`);ke.current=[`dark`,`white`].includes(D||De)?D||De:`light`;let Ae=(0,Q.useRef)(l);Ae.current=l;let je=(0,Q.useRef)(c);je.current=c;let Me=(0,Q.useRef)(s);Me.current=s;let Ne=(0,Q.useRef)(!1),[Pe,Fe]=(0,Q.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),Ie=()=>{let e={enabled:!!Me.current,projectId:Me.current?.projectId??null,placementId:Me.current?.placementId??null};Fe(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,Q.useEffect)(()=>{Ne.current||Ie()},[!!s,s?.projectId,s?.placementId]);let Le=Pe.enabled,Re=Pe.projectId,ze=Pe.placementId,Be=!!Te?.count&&!!(Te.dirty||Te.pending||Te.error);(0,Q.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Oe(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Ve=(0,Q.useMemo)(()=>{try{let e=RU(t);return{value:e,signature:pt(e)}}catch(e){return{error:e.message}}},[t]);ee.current={onSharedChange:o,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m},te.current=Ve;let[He,Ue]=(0,Q.useState)(null),We=_?He?.handle===_&&He.allowed:!M||He?.content===M&&He.parent===N&&He.allowed;(0,Q.useEffect)(()=>{if(!M&&!_)return;let e=!0,t=new AbortController;return Ue(null),(_?w(_,{signal:t.signal}):Promise.all([M,...N?[N]:[]].map(e=>TU(e,{signal:t.signal})))).then(()=>{e&&Ue({handle:_,content:M,parent:N,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&M&&oi(M,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(Ue({handle:_,content:M,parent:N,allowed:!1,error:t.message}),ee.current.onError?.(t))}),()=>{e=!1,t.abort()}},[M,N,_,re]);let Ge=fH(j)&&j.files?j.files:null,[Ke,qe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!Ge||!We){qe(null);return}let e=!0,t=new AbortController;return qe(null),Promise.resolve().then(()=>(aH(j),ui(()=>Promise.resolve().then(()=>(kU(),EU)),void 0))).then(({loadViewAssets:e})=>e(Ge,{signal:t.signal})).then(t=>{e&&qe({files:Ge,assets:t})},t=>{e&&qe({files:Ge,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[j,Ge,We]);let Je=Ge?Ke?.files===Ge?Ke:{loading:!0}:null,Ye=JSON.stringify([...new Set(k.filter(e=>typeof e==`string`))].sort()),Xe=[j,Je,E,O,re,a,r,P,F,x,Le,Re,ze,Ye,!!M?.manifest?.sharedWork,M?.capability?.operation],Ze=(0,Q.useRef)(null);if(!Ze.current||Xe.some((e,t)=>!Object.is(e,Ze.current.inputs[t]))){let e;try{if(Je?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if(Je?.error)throw Error(Je.error);let t=MU(),n=MU(),r=pU();e={session:t,nativeTextToken:n,filming:!!r,html:KU(j,t,ke.current,O,Le,JSON.parse(Ye),n,!!M?.manifest?.sharedWork,M?.capability?.operation===`connection.execute`,{assets:Je?.assets||{},filming:r})}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}Ze.current={inputs:Xe,document:e}}let Qe=Ze.current.document,$e=Qe?.session;(0,Q.useEffect)(()=>{let e=I.current?.contentWindow;e&&$e&&e.postMessage({channel:AU,session:$e,op:`zoom-mode`,mode:pe},`*`)},[pe,$e]),(0,Q.useEffect)(()=>{if(!x||!$e)return;let e=null,t=()=>{e=null;let t=I.current?.contentWindow;t&&t.postMessage({channel:AU,session:$e,op:`zoom-space`,height:sU(I.current)},`*`)},n=()=>{clearTimeout(e),e=setTimeout(t,200)};return addEventListener(`resize`,n),()=>{clearTimeout(e),removeEventListener(`resize`,n)}},[x,$e]);let et=(0,Q.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[Qe.session]),tt=(0,Q.useRef)(n);tt.current=n??et;let nt=(0,Q.useRef)(n==null);nt.current=n==null;let rt=(0,Q.useRef)({session:null,count:0}),it=(0,Q.useRef)(null),at=(0,Q.useRef)(null),ot=(0,Q.useRef)(null),st=(0,Q.useRef)(null),ct=(0,Q.useRef)(null),lt=(0,Q.useRef)(null),ut=(0,Q.useRef)(null);lt.current={key:r,peers:i,actorId:a};let dt=(0,Q.useRef)(null),ft=(0,Q.useRef)(null);ft.current={input:Ve.signature,error:Ve.error,view:j,policyContent:M,policyParent:N,resetKey:E,appearance:O,policyReady:We};let ht=(0,Q.useRef)(null);ht.current=pt([A?.projectId,A?.placementId,A?.sourceDigest,a].map(e=>e??null));let[V,_t]=(0,Q.useState)(null),vt=pt([kt(),a,ht.current,Qe.session,Ve.signature,We].map(e=>e??null));(0,Q.useEffect)(()=>{let e=!0;if(_t(null),!A?.projectId||!A?.placementId||!A?.sourceDigest||Ve.error||!We||a!==kt())return()=>{e=!1};let t=vt;return mt(Ve.value).then(n=>{e&&_t({basis:t,value:{version:1,actorId:a,projectId:A.projectId,placementId:A.placementId,sourceDigest:A.sourceDigest,inputDigest:n}})},()=>{e&&_t(null)}),()=>{e=!1}},[vt]),V?.basis===vt&&V.value;let[yt,bt]=(0,Q.useState)(null),xt=(0,Q.useRef)(null),St=(0,Q.useRef)(null),[Ct,wt]=(0,Q.useState)(null),[Et,Dt]=(0,Q.useState)(!1),[Ot,At]=(0,Q.useState)(!1),[jt,Mt]=(0,Q.useState)(null);jt&&jt.actor===a&&jt.runtimeActor===kt()&&jt.identity===ht.current&&jt.session===Qe.session&&Object.keys(jt.authority).every(e=>jt.authority[e]===ft.current[e])&&jt.evidence,{...A},M?.manifest?.id,M?.manifest?.version,Qe.session,Ve.signature,tt.current?.canEdit,{...A},Qe.session,Ve.signature,tt.current?.canEdit,(0,Q.useEffect)(()=>{if(bt(null),wt(null),At(!1),Dt(!1),Mt(null),R(``),de(null),we(null),Ee(null),Qe.error||Qe.loading||!We)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=0,p=0,m=new Set,h=-1/0,g=-1/0,_=e=>{e.isTrusted&&(h=Date.now())};globalThis.document.addEventListener(`pointerdown`,_,!0),globalThis.document.addEventListener(`keydown`,_,!0);let v,y=0,b=null,w=[],E=0,D=null,O=0,k=0,N=null,L=fH(j),ne=null,re=()=>{ne&&globalThis.document.fullscreenElement!==ne&&(ne=null,ce({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,re);let ie=()=>{let t;return t=gz(M,{onStatus:n=>{e&&v===t&&se(n)},onLive:(n,r)=>{e&&v===t?I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&v===t&&le(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};v=ie(),ae.current=v,se(null),le(null);let B=()=>{if(!e||!tt.current?.canEdit)return;let t=v;v=ie(),ae.current=v,b=null,se(null),Promise.resolve(t.close()).catch(()=>{})};oe.current=B;let ce=t=>{e&&I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,...t},`*`)},ue=null,fe=0,pe=(e,t)=>{let n=at.current,r=I.current,i=n?.parentElement;if(!n||!r||!i)return;let a=Math.max(0,t?.x??0),o=Math.max(0,t?.y??0),s=Math.min(r.clientWidth,(t?.x??0)+(t?.width??0)),c=Math.min(r.clientHeight,(t?.y??0)+(t?.height??0));if(!t||s<=a||c<=o){n.hidden=!0,delete n.dataset.control;return}let l=r.getBoundingClientRect(),u=i.getBoundingClientRect();n.style.transform=`translate(${l.left+r.clientLeft-u.left-i.clientLeft+a}px,${l.top+r.clientTop-u.top-i.clientTop+o}px)`,n.style.width=`${s-a}px`,n.style.height=`${c-o}px`,n.dataset.control=e,n.hidden=!1};pe(null,null),ot.current=n=>{!e||!t||typeof n!=`string`||ue&&Date.now()-ue.at<1e3||(ue={id:`locate-`+ ++fe,control:n,at:Date.now()},ce({op:`locate-view-control`,id:ue.id,control:n}))};let me=new Map,he=new Set,ve=0,xe=!1,Ce=(e,t)=>new Promise(n=>{let r=`film-`+ ++ve,i=setTimeout(()=>{me.delete(r),n(null)},6e3);me.set(r,e=>{clearTimeout(i),me.delete(r),n(e)}),ce({op:e,id:r,...t})}),Te=Qe.filming&&I.current?mU({element:I.current,placementId:A?.placementId||null,capture:e=>Ce(`capture-view`,e),locate:e=>Ce(`locate-view-control`,{control:e}),get drawn(){return xe},onChange:e=>(he.add(e),()=>he.delete(e))}):null,De=null,Oe=null,Pe=0,Fe=!1,Be=a,Ve=ft.current,He=ht.current,Ue=(t,n)=>{if(!e||Fe||t?.signal?.aborted||kt()!==Be||ht.current!==He||Oe&&te.current.signature!==Oe.inputIdentity||De&&te.current.signature!==De.inputIdentity&&te.current.signature!==n||Object.keys(Ve).filter(e=>e!==`input`).some(e=>Ve[e]!==ft.current[e]))throw Fe=!0,At(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Ge=e=>{if(!De)return;let t=De;De=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Dt(!1),t.reject(e)};St.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Ue(r),!t||De)throw Error(`The declared interface is loading or busy.`);if(e===`dispatch-view-control`&&!r.taskFence)throw Error(`The declared interface requires its active project task.`);let s=String(++Pe),c=()=>{Fe=!0,At(!1),i?.abort(),Ge(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,F);De={id:s,op:e,inputIdentity:te.current.signature,offset:n.offset,context:r,resolve:a,reject:o,timer:l,abort:c},r.signal?.addEventListener(`abort`,c,{once:!0}),e===`dispatch-view-control`&&Dt(!0),ce({op:e,id:s,...n})}catch(e){o(e)}})},xt.current={request:(e,n)=>new Promise((r,i)=>{try{if(Ue(n),!t||De||Oe||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++Pe),o=()=>{Fe=!0,At(!1),Oe?.id===a&&(Oe=null,Dt(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,F);Oe={id:a,field:e.field,inputIdentity:te.current.signature,context:n,resolve:r,reject:i,timer:s,abort:o},n.signal?.addEventListener(`abort`,o,{once:!0}),Dt(!0),ce({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let Ke=()=>{if(Fe)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return De?.op===`dispatch-view-control`?(Ue(De.context),De.context):null},qe=!1,Je=0,Ye=[],Xe=0,Ze=!1,$e=0,et=[],rt=0,mt=0,V=[],_t=null,vt=!1,yt={projectId:Re,placementId:ze,actorId:a},Ct=()=>e&&Me.current?.projectId===yt.projectId&&Me.current?.placementId===yt.placementId,Et=e=>({message:String(e?.message||`Shared text failed.`).slice(0,1e3),...typeof e?.code==`string`&&/^[A-Z][A-Z0-9_]{0,79}$/.test(e.code)?{code:e.code}:{}}),Ot=Me.current?.projectId&&a?Zn({projectId:Me.current.projectId,actorId:a,headers:Qn,onChange:e=>{if(Ct()){if(e.kind===`revoked`){vt=!0,ce({op:`shared-view`,value:{...tt.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||_t===null&&(_t=setTimeout(()=>{_t=null,t&&Ct()&&!vt&&ce({op:`text-refresh`})},100)))}}}):null,jt=je.current?.projectId&&a?Zn({projectId:je.current.projectId,actorId:a,headers:Qn,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(Xe++,ce({op:`shared-work-refresh`}))}}):null,Nt=()=>{t&&ce({op:`theme`,mode:ke.current})};ut.current=Nt;let Pt=`[]`,Ft=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=lt.current,i=!nt.current&&e&&localStorage.getItem(`stillmade:show-shared-cursors`)!==`false`?n.filter(t=>t.user_id!==r&&t.selection?.cursor?.visible&&t.selection.cursor.surface===e).slice(0,50).flatMap(e=>{let t=EH(e.selection.cursor.anchor);return t?[{id:String(e.session_id).slice(0,200),label:String(e.label||`Teammate`).slice(0,120),anchor:t}]:[]}):[],a=JSON.stringify(i);a!==Pt&&(Pt=a,ce({op:`peer-cursors`,peers:i}))};ct.current=Ft,window.addEventListener(`stillmade:cursor-preferences`,Ft),window.addEventListener(`storage`,Ft);let It=null,Lt=()=>{let e=I.current;if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+e.clientLeft,y:t.top+e.clientTop,right:t.right,bottom:t.bottom}},Rt=()=>{It&&(It.bounds=Lt())},zt=()=>{It&&(It=null,window.removeEventListener(`scroll`,Rt,{capture:!0}),window.removeEventListener(`resize`,Rt))},Bt=n=>{let r=n.detail;e&&r?.root?.contains?.(I.current)&&(r.action===`start`&&t&&!It?(It={bounds:Lt()},window.addEventListener(`scroll`,Rt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Rt),ce({op:`pick-start`})):r.action===`stop`&&It&&(zt(),ce({op:`pick-stop`})))};window.addEventListener(AH.control,Bt);let Vt=e=>{R(e),ee.current.onError?.(Object.assign(Error(e),{shown:!0}))},Ht=()=>{e&&(clearInterval(D),N?.disconnect(),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),Vt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))};it.current=L?()=>{e&&(clearInterval(D),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),Vt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))}:null;let Ut=()=>{if(typeof PerformanceObserver!=`function`||!PerformanceObserver.supportedEntryTypes?.includes(`longtask`))return;let e=[],t=e=>Array.from(e.attribution||[]).some(e=>e.containerType===`iframe`&&typeof e.containerSrc==`string`&&e.containerSrc.endsWith(`#${Qe.session}`));N=new PerformanceObserver(n=>{for(let r of n.getEntries()){if(!t(r))continue;let n=r.startTime+r.duration;if(e=e.filter(e=>e.end>n-5e3),e.push({end:n,duration:r.duration}),r.duration>=sH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Ht()}});try{N.observe({type:`longtask`})}catch{N=null}},Wt=()=>{O=Date.now(),D=setInterval(()=>{if(!e)return clearInterval(D);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-O>8e3)return Ht();ce({op:`ping`,id:String(++k)})},2e3)};z(!0);let Gt=setTimeout(()=>{e&&!t&&(z(!1),Vt(S()?C():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))},S()?5e3:15e3),Kt=e=>{let t=o;t&&(Mt(null),o=null,t.controller.abort(),e&&ce({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},qt=()=>{if(!t)return;let e=te.current;if(e.error){Kt(`Preview input is unavailable.`),Vt(e.error);return}s!==e.signature&&(Kt(`Preview input changed. Use its current image.`),s=e.signature,ce({op:`input`,input:e.value}))};dt.current=qt;let Jt=null,Yt=!1,Xt=0,Zt=[],Qt=null,$t=0,en=null,tn=qn(()=>{if(nt.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(Qt)return Qt.promise;let n=String(++$t),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{Qt?.id===n&&(Qt=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return Qt={id:n,promise:a,resolve:r,reject:i,timer:o},ce({op:`flush-shared`,id:n}),a}),nn=()=>{if(t&&tt.current)try{let e=RU(tt.current),t=pt(e);if(t===Jt)return;Jt=t,ce({op:`shared-view`,value:e})}catch(e){Vt(e.message)}};st.current=nn;let rn=t=>{e&&nt.current&&(tt.current.outputs=t,nn())},an=r=>{let s=r.data;if(L&&e&&gt(s)&&s.op===`navigated`&&s.channel===AU&&s.session===Qe.session&&(r.source===null||r.source===I.current?.contentWindow)){it.current?.();return}if(!e||r.source!==I.current?.contentWindow||!gt(s)||s.channel!==AU||s.session!==Qe.session)return;if(s.op===`document-ready`){n||(n=!0,ce({op:`document`,html:Qe.html}));return}if(s.op===`view-changed`){xe=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>gt(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of he)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&me.has(s.id)){let e=me.get(s.id),t=s.rect;if(!e){s.bitmap?.close?.();return}e(s.op===`capture-view-result`?s.bitmap instanceof ImageBitmap?s.bitmap:null:gt(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`zoom-key`){be.current(s.step===`auto`?`auto`:cU(ye.current,s.step===`bigger`?VH:-VH));return}if(s.op===`media-stage`){let e=I.current,t=globalThis.document;if(!e)return;if(s.on===!0){if(!t.fullscreenElement&&globalThis.navigator?.userActivation?.isActive&&t.activeElement===e&&typeof e.requestFullscreen==`function`){ne=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{ne=null})}catch{ne=null}}}else if(t.fullscreenElement===e){ne=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){ge(e=>{let t={supported:s.supported===!0,zoom:Number.isFinite(s.zoom)?s.zoom:1};return e&&e.supported===t.supported&&e.zoom===t.zoom?e:t});return}if(s.op===`ready`){t||(t=!0,z(!1),clearTimeout(Gt),ce({op:`zoom-mode`,mode:_e.current}),x&&ce({op:`zoom-space`,height:sU(I.current)}),L&&(Wt(),Ut()),Nt(),qt(),nn(),Ft(),ce({op:`inspect-view-controls`,offset:0}),ce({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!Qt||s.id!==Qt.id)return;let e=Qt;Qt=null,clearTimeout(e.timer);let t=s.error||en;t?e.reject(Error(String(t).slice(0,1e3))):e.resolve({queued:!0});return}if(s.op===`escape`){let e=Date.now();globalThis.document.activeElement===I.current&&e-E>=300&&(E=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){L&&typeof s.id==`string`&&(O=Date.now());return}if(s.op===`unresponsive`){L&&Ht();return}if(s.op===`interface-error`){Vt(String(s.error||`The Block interface could not display its input`).slice(0,1e3));return}if(s.op===`document-store-status`){let e=s.status;gt(e)&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=8)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&we(e);return}if(s.op===`text-recovery-status`){let e=s.status;Le&&gt(e)&&Object.keys(e).every(e=>[`count`,`dirty`,`pending`,`readonly`,`error`,`retryable`].includes(e))&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=100)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&typeof e.retryable==`boolean`&&Ee(e);return}if(!t)return;if(s.op===`pick-hover`){if(!It)return;let e=FH(s.hover),t=It.bounds,n=null;if(e&&t){let r=Math.max(t.x,e.rect.x+t.x),i=Math.max(t.y,e.rect.y+t.y),a=Math.min(t.right,e.rect.x+t.x+e.rect.width),o=Math.min(t.bottom,e.rect.y+t.y+e.rect.height);a>r&&o>i&&(n={...e,rect:{x:r,y:i,width:a-r,height:o-i},cursor:{x:e.cursor.x+t.x,y:e.cursor.y+t.y}})}window.dispatchEvent(new CustomEvent(AH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!It)return;zt();let e=s.op===`pick-result`?IH(s.target):null;e?window.dispatchEvent(new CustomEvent(AH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(AH.cancel));return}if(s.op===`named-text-controls`){if(s.token===Qe.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=RU(s.snapshot);e.every(e=>gt(e)&&typeof e.field==`string`&&typeof e.identity==`string`&&typeof e.value==`string`&&e.value.length<=1e4&&typeof e.partial==`boolean`&&typeof e.ready==`boolean`&&typeof e.disabled==`boolean`)&&bt(e)}return}if(s.op===`named-text-result`){let e=Oe;if(!e||s.id!==e.id||s.token!==Qe.nativeTextToken)return;try{if(Ue(e.context),s.error)throw Error(String(s.error).slice(0,1e3));e.resolve()}catch(t){e.reject(t)}finally{Oe=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Dt(!1)}return}if(s.op===`view-controls`){try{let e=RU(s.snapshot);if(!gt(e)||!Number.isSafeInteger(e.revision)||!Number.isSafeInteger(e.total)||e.total<0||e.total>1e4||!Number.isSafeInteger(e.offset)||!Array.isArray(e.controls)||e.controls.length>20||e.controls.some(e=>!gt(e)||typeof e.id!=`string`||typeof e.identity!=`string`||typeof e.action!=`string`||typeof e.disabled!=`boolean`||typeof e.hidden!=`boolean`))throw Error(`Invalid declared interface controls.`);if(wt(e),At(!Fe),De?.op===`inspect-view-controls`&&e.offset===De.offset){let e=De;Ue(e.context),De=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Ge(e)}return}if(s.op===`view-control-rect`){if(!ue||s.id!==ue.id)return;let{control:e}=ue,t=s.rect;ue=null,pe(e,gt(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`view-controls-error`){Ge(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(De?.op!==`dispatch-view-control`||s.id!==De.id)return;let e=De;try{if(Ue(e.context),s.error)throw Error(String(s.error).slice(0,1e3));De=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Dt(!1),e.resolve()}catch(e){Ge(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=Je)return;Je=Number(s.id);let t=e=>ce({op:`connected-app-result`,id:s.id,...e}),n=Ae.current,r=ft.current;Ye=Ye.filter(e=>Date.now()-e<6e4);try{if(M?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Tt(s.operation,RU(s.args));if(i.operation!==`tasks`&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);if(qe||Ye.length>=30)throw Error(`Wait for the current task request.`);qe=!0,Ye.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Ae.current?.projectId||n.placementId!==Ae.current?.placementId||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:RU(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{qe=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-media-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=$e)return;$e=Number(s.id);let t=je.current,n=ft.current,r=Xe,i=e=>ce({op:`shared-work-result`,id:s.id,...e});try{if(!M?.manifest?.sharedWork||!M.manifest.permissions?.project?.includes(`work.shared`)||!t?.previewMedia||typeof s.contributionId!=`string`||!/^[0-9a-f-]{36}$/i.test(s.contributionId))throw Error(`Choose a permitted saved creative in this workspace.`);if(et=et.filter(e=>Date.now()-e<6e4),Ze||et.length>=60)throw Error(`Wait for the current media preview.`);Ze=!0,et.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==Xe||Object.keys(n).some(e=>n[e]!==ft.current[e]))throw Error(`This workspace changed before the creative preview.`);if(!(t.media instanceof Blob)||!t.media.size||t.media.size>67108864||![`image`,`video`,`audio`].includes(t.kind)||!t.media.type.startsWith(t.kind+`/`))throw Error(`This preview exceeds the media limit.`);i(t)},e=>i({error:String(e.message||`Media preview failed.`).slice(0,1e3)})).catch(e=>i({error:String(e.message).slice(0,1e3)})).finally(()=>{Ze=!1})}catch(e){i({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=$e)return;$e=Number(s.id);let t=e=>ce({op:`shared-work-result`,id:s.id,...e}),n=je.current,r=ft.current,i=Xe;et=et.filter(e=>Date.now()-e<6e4);try{if(!M?.manifest?.permissions?.project?.includes(`work.shared`)||!M.manifest.sharedWork||!n?.request)throw Error(`Shared work is unavailable in this preview. Open the saved Block in its project.`);let a=T(s.operation,RU(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);if(Ze||et.length>=60)throw Error(`Wait for the current shared-work request.`);Ze=!0,et.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==je.current?.projectId||n.placementId!==je.current?.placementId||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==Xe){if([`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation))throw Error(`Saved-work access changed. Read its current version.`);t({result:{saved:!0,refreshRequired:!0}});return}t({result:RU(o)})},e=>t({error:String(e.message||`Shared work failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{Ze=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`text-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=mt)return;mt=Number(s.id);let e=e=>ce({op:`text-result`,id:s.id,...e}),t=Me.current,n=te.current.signature,r=ft.current;if(V=V.filter(e=>Date.now()-e<6e4),!Le||!Ct()||!t||typeof t.request!=`function`||![`read`,`initialize`,`update`,`reset`].includes(s.action)||typeof s.key!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(s.key)||[`constructor`,`prototype`,`__proto__`].includes(s.key)){e({error:{message:`Shared text is unavailable for this field.`}});return}if(rt>=16||V.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!Ct()||te.current.error||te.current.signature!==n||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(vt||s.action!==`read`&&!tt.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=RU(s.body),!gt(a)||new TextEncoder().encode(JSON.stringify(a)).length>5e4||Object.keys(a).some(e=>![`protocol`,`requestId`,`sourceIdentity`,`epoch`,`textRevision`,`value`,`update`].includes(e)))throw Error(`Invalid shared text request.`)}catch(t){e({error:Et(t)});return}rt++,V.push(Date.now()),Promise.resolve().then(async()=>{if(i(),Ke()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=Oe,n;if(e&&s.action!==`read`){if(Ue(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==Qe.nativeTextToken||s.nativeText?.callId!==e.id)throw Error(`Unrelated text events cannot use this native task.`);n=e.context}else if(s.nativeText)throw Error(`The original text invocation is no longer current; do not replay.`);return await t.request(s.action,{...a,placementId:t.placementId,fieldKey:s.key},n)}catch(e){if(s.action===`read`&&e.code===`SHARED_TEXT_FIELD_UNSUPPORTED`&&typeof tt.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:RU(t)})}).catch(t=>e({error:Et(t)})).finally(()=>{rt--});return}if(s.op===`cursor`){let e=s.cursor;if(gt(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=I.current?.getBoundingClientRect(),n=EH(e.anchor),r=lt.current.key;t&&window.dispatchEvent(new CustomEvent(`stillmade:sandbox-cursor`,{detail:{x:(t.left+e.x*t.width)/Math.max(1,window.innerWidth),y:(t.top+e.y*t.height)/Math.max(1,window.innerHeight),visible:e.visible!==!1,...n&&typeof r==`string`&&r.length>0&&r.length<=200&&!nt.current?{anchor:n,surface:r}:{}}}))}return}if(s.op===`shared-view-update`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=Xt)return;Xt=Number(s.id);let t=e=>{en=e.error?String(e.error):null,ce({op:`shared-view-result`,id:s.id,...e})};if(Zt=Zt.filter(e=>Date.now()-e<6e4),Yt||Zt.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!tt.current?.canEdit||!nt.current&&typeof ee.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=RU(s.request),new TextEncoder().encode(JSON.stringify(n)).length>rr.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}Yt=!0,Zt.push(Date.now()),Promise.resolve().then(()=>{if(!e||!tt.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if(Ke(),nt.current){tt.current.state=ir(tt.current.state,n),nn();return}let t=Ke();return ee.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{Yt=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&Se.current?.(s.height),x&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&de(Math.max(280,Math.min(3e4,s.height)));return}if(s.op===`live-ack`){v?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=y)return;y=Number(s.id);let t=e=>ce({op:`desktop-result`,id:s.id,...e});if(w=w.filter(e=>Date.now()-e<6e4),b||w.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=RU(s.args||{}),JSON.stringify(n).length>131072||!gt(n))throw Error(`Desktop arguments exceed the limit`)}catch(e){t({error:e.message});return}let r=![`tool.status`,`storage.info`,`storage.list`,`storage.read`,`record.status`,`device.info`,`record.cancel`,`session.close`,`live.status`,`live.stop`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`].includes(s.operation)&&(s.operation!==`folder.pick`||s.args?.write===!0);if(r&&!tt.current?.canEdit){t({error:`Desktop changes are unavailable while this workspace is read only.`});return}if(s.operation===`record.cut`){let e=n?.source,r=zU(e),i=[];try{i=VU(te.current?.value).map(zU)}catch{}if(!r||!(v.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:v};w.push(Date.now()),b=i,Promise.resolve().then(()=>{if(!e||i.native!==v||r&&!tt.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if(Ke()&&r)throw Error(`Assisted desktop mutations require a task-safe native interface; this control is unavailable.`);return i.native.call(s.operation,n,[`record.cut`,`folder.write`].includes(s.operation)?{received:(()=>{try{return VU(te.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==v||r&&!tt.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:RU(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{b===i&&(b=null)});return}if(s.op===`use-output`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let e=e=>ce({op:`use-output-result`,id:s.id,...e});try{if(Ke())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(L&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);let t=RU(s.outputs),n=ee.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);UU(t,te.current.value,v),Promise.resolve(n(t)).then(t=>{let n=RU(t);rn(n),e({outputs:n})},t=>e({error:String(t?.message||`The media output could not be saved`).slice(0,1e3)}))}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`preview-image`||s.op===`preview-media`){let t=s.op===`preview-media`;if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=l)return;Mt(null),l=Number(s.id);let n=e=>ce({op:t?`preview-media-result`:`preview-image-result`,id:s.id,...e}),r=Date.now();if(d=d.filter(e=>r-e<6e4),o||d.length>=YV.imagePreviewsPerMinute){++p<=3&&n({error:o?`An image preview is already loading`:`Image preview limit reached. Wait a minute before trying again.`}),p===4&&(Vt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,Kt(),i?.abort(),I.current&&(I.current.src=`about:blank`));return}d.push(r);let c;try{if(c=t?RU(s.value):WU(s.value),t&&(!gt(c)||![`video`,`audio`].includes(c.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof c[e]==`string`&&c[e].length>0&&c[e].length<=32768)))throw Error(`Keep the complete audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let u=t&&v?.authorizesMedia?.(c)?(e,t)=>Gn(e,t):t?ee.current.onPreviewMedia:ee.current.onPreviewImage;if(typeof u!=`function`){n({error:t?`Audio/video preview is unavailable in this workspace.`:`Image preview is unavailable in this workspace. Choose an image with the host controls.`});return}let f=new AbortController,m=ft.current,h={controller:f,id:s.id,media:t};o=h;let g=ht.current,_=a,y=kt(),b=()=>{if(f.signal.aborted||y!==kt()||g!==ht.current||Object.keys(m).some(e=>m[e]!==ft.current[e]))throw Error(`Image preview input or workspace changed.`)},x=setTimeout(()=>{e&&o===h&&Kt(`Image preview timed out. Try a smaller image.`)},YV.imagePreviewMs);f.signal.addEventListener(`abort`,()=>clearTimeout(x),{once:!0}),Promise.resolve().then(()=>(b(),u(c,{signal:f.signal}))).then(r=>{if(e&&!f.signal.aborted&&o===h){if(b(),t&&r?.kind!==c.kind)throw Error(`The host returned a different media kind.`);let e=t?Un(r):GU(r);b(),typeof c.assetId==`string`&&c.assetId.length<=512&&typeof c.versionId==`string`&&c.versionId.length<=512&&Mt({actor:_,runtimeActor:y,identity:g,session:Qe.session,authority:m,evidence:{assetId:c.assetId,versionId:c.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(x),o===h&&(o=null)});return}if(s.op!==`run`||typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=c)return;c=Number(s.id);let _=e=>ce({op:`result`,id:s.id,...e});if(L&&!tt.current?.canEdit){_({error:`Shared editing is unavailable or read only.`});return}let S=Date.now();if(u=u.filter(e=>S-e<6e4),i||u.length>=YV.runsPerMinute){++f<=3&&_({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),f===4&&(Vt(`Preview paused after too many requests. Reset it to continue.`),e=!1,Kt(),i?.abort(),I.current&&(I.current.src=`about:blank`));return}let C;try{if(!gt(s.input))throw Error(`Expected input values`);C=RU(s.input)}catch(e){_({error:e.message});return}u.push(S),R(``);let D=new AbortController;i=D,Ne.current=!0,De?.context.signal?.addEventListener(`abort`,()=>D.abort(),{once:!0});let k=setTimeout(()=>{e&&i===D&&(D.abort(),i=null,_({error:P?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},P?F:15e3);D.signal.addEventListener(`abort`,()=>clearTimeout(k),{once:!0});let A=De?.op===`dispatch-view-control`?De:null,j=A?async e=>{if(De!==A||i!==D||D.signal.aborted||!gt(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||pt(e.taskFence)!==pt(A.context.taskFence)||pt([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==He||pt(RU(e.beforeInput))!==A.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=pt(RU(e.input));for(let e=0;e<25&&te.current.signature!==t;e++)if(Ue(A.context,t),await new Promise(e=>setTimeout(e,10)),De!==A||i!==D||D.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Ue(A.context,t),te.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);A.inputIdentity=t}:void 0,N=gt(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=jU&&!m.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===I.current&&Date.now()-h>jU&&Date.now()-g>jU;N&&(m.add(s.gesture.id),g=Date.now()),Promise.resolve().then(()=>ee.current.onRun(C,{...Ke(),signal:D.signal,userActivated:N,...j?{onInputCommitted:j}:{},...M?.manifest?.desktopTools?.length?{nativeDesktopSession:v}:{}})).then(t=>{if(e&&!D.signal.aborted){if(!gt(t))throw Error(`Block execution must return named outputs`);let e=RU(t);rn(e),_({outputs:e})}},t=>{e&&!D.signal.aborted&&_({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!D.signal.aborted&&_({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(k),i===D&&(i=null),Ne.current=!1,setTimeout(()=>{e&&!Ne.current&&Ie()},250)})};return window.addEventListener(`message`,an),()=>{globalThis.document.removeEventListener(`fullscreenchange`,re),ne&&globalThis.document.fullscreenElement===ne&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),ne=null,ot.current=null,pe(null,null),Te?.();for(let e of[...me.values()])e(null);Oe&&=(clearTimeout(Oe.timer),Oe.context.signal?.removeEventListener(`abort`,Oe.abort),Oe.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,_,!0),globalThis.document.removeEventListener(`keydown`,_,!0),xt.current=null,Ge(Error(`The declared interface was closed.`)),St.current=null,Ot?.(),jt?.(),clearTimeout(_t),tn(),Qt&&=(clearTimeout(Qt.timer),Qt.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout(Gt),clearInterval(D),N?.disconnect(),ce({op:`dispose`}),e=!1,v.close(),ae.current===v&&(ae.current=null),oe.current===B&&(oe.current=null),Kt(),i?.abort(),Ne.current=!1,window.removeEventListener(`message`,an),window.removeEventListener(`stillmade:cursor-preferences`,Ft),window.removeEventListener(`storage`,Ft),window.removeEventListener(AH.control,Bt),zt(),ct.current=null,dt.current=null,st.current=null}},[Qe,We,P,F,x,r,a,Re,ze]),(0,Q.useEffect)(()=>{dt.current?.()},[t]),(0,Q.useEffect)(()=>{st.current?.(),n?.canEdit===!1&&Promise.resolve(ae.current?.close()).catch(()=>{})},[n,We]),(0,Q.useEffect)(()=>{ct.current?.()},[i,r,a,n]),(0,Q.useEffect)(()=>{ut.current?.()},[D,De]);let Nt=!!globalThis.stillmadeDesktop?.blockDesktop,Pt=B?.camera&&B?.microphone?`camera and microphone`:B?.camera?`camera`:`microphone`;return(0,$.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[B?.kind===`live`&&B.awaitingStart&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:`Ready to share your ${Pt} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:`Start ${Pt}`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Cancel`})]}),B?.kind===`live`&&B.active&&(0,$.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,$.jsx)(`strong`,{children:`${Pt[0].toUpperCase()}${Pt.slice(1)} on`}),(0,$.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.stop,children:`Turn off ${Pt}`})]}),B?.awaitingStart&&(B.kind===`folder`||B.kind===`folder-access`)&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:B.kind===`folder`?`This Block asks for a folder to ${B.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${B.folder} again for this Block.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:B.kind===`folder`?`Choose folder`:`Allow`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>B.cancel?B.cancel():ae.current?.close(),children:`Cancel`})]}),B?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(B.kind)&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:B.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:B.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:B.microphone?`Ready to record your screen with your microphone. Choose your screen or window after pressing Start.`:`Ready to record. Choose your screen or window after pressing Start.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:B.kind===`camera`?`Start camera recording`:B.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Cancel`})]}),B?.active&&B.kind!==`live`&&(0,$.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,$.jsxs)(`strong`,{children:[B.ended?`Recording stopped`:`Recording`,` `,B.kind||`media`]}),(0,$.jsxs)(`span`,{children:[` · `,B.ended?B.message:Nt?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:Nt?`Cancel recording and revoke access`:`Discard recording`})]}),Nt&&B?.closed&&M?.manifest?.permissions?.desktop?.length>0&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:!We||!tt.current?.canEdit,onClick:()=>oe.current?.(),children:`Reopen desktop access`}),Nt&&!B?.closed&&!B?.active&&M?.manifest?.permissions?.desktop?.length>0&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Revoke this Block’s desktop access`}),Qe.loading?(0,$.jsx)(`p`,{role:`status`,children:`Loading the interface…`}):Qe.error?(0,$.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,Qe.error]}):We?(0,$.jsxs)($.Fragment,{children:[ne&&!L&&(0,$.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,$.jsx)(`iframe`,{ref:I,onLoad:()=>{rt.current.session!==Qe.session&&(rt.current={session:Qe.session,count:0}),++rt.current.count>2&&it.current?.()},title:v,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${b(`/block-ui-sandbox.html`)}#${Qe.session}`,style:{width:`100%`,height:x&&ue||y,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...L?{display:`none`}:{}}},Qe.session),(0,$.jsx)(`span`,{ref:at,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}}),he?.supported&&!L&&(0,$.jsx)(lU,{zoom:he.zoom,mode:pe,onChange:ve})]}):(0,$.jsx)(`p`,{role:He?.error?`alert`:`status`,children:He?.error||`Checking Block safety…`}),Ce?.count>0&&(Ce.error?(0,$.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:Ce.error}):Ce.dirty||Ce.pending?(0,$.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),Te?.count>0&&(Te.error||Te.dirty||Te.pending)?(0,$.jsxs)(`div`,{className:`bs-notice`,role:Te.error?`alert`:`status`,children:[(0,$.jsx)(`p`,{children:Te.error||`Saving shared text…`}),Te.error&&(0,$.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),Te.retryable&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:Te.pending>0||!tt.current?.canEdit,onClick:()=>I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(L||He?.error)&&(0,$.jsxs)($.Fragment,{children:[L&&(0,$.jsx)(`p`,{role:`alert`,children:L}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:Be,onClick:()=>{Be||ie(e=>e+1)},children:`Reload`})]}),(0,$.jsx)(qU,{activity:ce,declaresFolders:(M?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:ae})]})}ct();var YU=50,XU=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var ZU=e=>e==null?``:typeof e==`number`?XU.format(e):String(e);function QU(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}function $U({value:e,label:t=`Table`}){let[n,r]=(0,Q.useState)(0);if(!qe(e))return(0,$.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/YU)),a=Math.min(n,i-1),o=e.rows.slice(a*YU,a*YU+YU),s=e.columns.map(t=>e.rows.length>0&&e.rows.every(e=>e[t]===void 0||e[t]===null||typeof e[t]==`number`));return(0,$.jsxs)(`div`,{className:`bd-table`,children:[(0,$.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:e.columns.map(e=>(0,$.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,$.jsx)(`tbody`,{children:o.map((t,n)=>(0,$.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,$.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:ZU(t[e])},e))},a*YU+n))})]})}),(0,$.jsxs)(`div`,{className:`bd-bar`,children:[(0,$.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>QU(new Blob([Ze(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}Ct(),ct();var eW=new Set([`image`,`audio`,`video`]),tW=e=>eW.has(e?.kind)&&typeof e.url==`string`,nW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,rW=e=>{let t=String(e).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},iW=50,aW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),oW=e=>{if(!gt(e))return e;let t=aW(e);return t.length===1&&(Array.isArray(e[t[0]])||gt(e[t[0]]))?oW(e[t[0]]):e},sW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),cW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``);function lW(e){if(e.length<2||!e.every(e=>gt(e)&&aW(e).every(t=>sW(e[t]))))return null;let t=[...new Set(e.flatMap(aW))];if(!t.length||t.length>6)return null;let n={columns:t.map(rW),rows:e.map(e=>Object.fromEntries(aW(e).map(t=>[rW(t),typeof e[t]==`boolean`?cW(e[t]):e[t]])))};return qe(n)?n:null}function uW({value:e,renderMedia:t,depth:n=0}){let r=oW(e);if(sW(r))return(0,$.jsx)(`span`,{children:cW(r)});if(tW(r))return t?.(r)??null;if(qe(r))return(0,$.jsx)($U,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,$.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(tW)&&lW(r);return e?(0,$.jsx)($U,{value:e,label:`Results`}):n>=3?(0,$.jsx)(`span`,{children:nW(r.length,`item`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,iW).map((e,r)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(uW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>iW&&(0,$.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-iW,` more.`]})]})}if(!gt(r))return null;let i=aW(r);return i.length?n>=3?(0,$.jsx)(`span`,{children:nW(i.length,`detail`)}):(0,$.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(`dt`,{children:rW(e)}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(uW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,$.jsx)(`span`,{className:`sm-data-none`,children:`None`})}function dW(e,t){let n=(0,Q.useRef)(t),r=YH(e),[i,a]=(0,Q.useState)(null);return n.current=t,(0,Q.useEffect)(()=>{if(!r)return;let t=!0;return Promise.resolve().then(()=>n.current?.(e)).then(n=>{t&&a({src:e,url:n||null})},()=>{t&&a({src:e,url:null})}),()=>{t=!1}},[e,r]),r?i?.src===e?{url:i.url,missing:!i.url}:{url:null,missing:!1}:{url:e||null,missing:!1}}function fW({src:e,resolveUrl:t,label:n,"aria-label":r,fill:i=!1,className:a,style:o,onMissing:s,controls:c,playsInline:l,preload:u=`metadata`,...d}){let{url:f,missing:p}=dW(e,t),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(s);return _.current=s,(0,Q.useEffect)(()=>{if(p){_.current?.(e);return}let t=ZH(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,$.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,$.jsx)(rU,{name:`imageOff`,size:24})}):(0,$.jsxs)(`div`,{ref:m,className:a?`sm-player ${a}`:`sm-player`,style:o,"data-mode":`dark`,"data-fill":i?``:void 0,tabIndex:0,role:`group`,"aria-label":n||r||`Video`,children:[(0,$.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,$.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var pW=e=>String(e).padStart(2,`0`),mW=/^(\d{4})-(\d{2})-(\d{2})$/,hW=/^([01]\d|2[0-3]):([0-5]\d)$/,gW=e=>{let t=mW.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},_W=e=>{let t=gW(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},vW=e=>{let{year:t,month:n,day:r}=gW(e);return new Date(Date.UTC(t,n-1,r))},yW=(e,t)=>{let n=vW(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},bW=(e,t)=>{let{year:n,month:r,day:i}=gW(e),a=new Date(Date.UTC(n,r-1+t,1)),o=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth()+1,0)).getUTCDate();return`${a.getUTCFullYear()}-${pW(a.getUTCMonth()+1)}-${pW(Math.min(i,o))}`},xW=/(?:time|when|start|schedule|post|send|publish|remind)/i,SW=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||xW.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),CW=e=>`${TW(e.slice(0,10))}${e[10]===`T`?` · ${EW(e.slice(11,16))}`:``}`;function wW({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${pW(t.getMonth()+1)}-${pW(t.getDate())}`}function TW(e,t=wW()){return vW(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function EW(e){let[t,n]=e.split(`:`).map(Number);return new Date(Date.UTC(2e3,0,1,t,n)).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,timeZone:`UTC`})}function DW(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${pW(Math.floor(n*e/60))}:${pW(n*e%60)}`)}function OW(e,t,n,r){return(0,Q.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)};return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e]),n=>{n.key===`Escape`&&e&&(n.stopPropagation(),n.preventDefault(),t(!1),r.current?.focus())}}function kW({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Day`,placeholder:s=`Pick a day`,clearable:c=!1}){let[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null),g=OW(l,u,p,m),_=wW({utc:i}),v=_W(e)?e:null,y=e=>(!n||e>=n)&&(!r||e<=r),b=e=>n&&e<n?n:r&&e>r?r:e;(0,Q.useEffect)(()=>{l&&d&&h.current?.querySelector(`[data-day="${d}"]`)?.focus()},[l,d]);let x=()=>{if(l){u(!1);return}f(b(v||_)),u(!0)},S=e=>{y(e)&&(t?.(e),u(!1),m.current?.focus())},C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7},w=e=>{let t=null;if(C[e.key])t=yW(d,C[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=bW(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=vW(d).getUTCDay();t=yW(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(b(t)))},T=d||v||_,{year:E,month:D}=gW(T),O=`${E}-${pW(D)}-01`,k=new Date(Date.UTC(E,D,0)).getUTCDate(),A=vW(O).getUTCDay(),j=vW(O).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),M=yW(O,-1),N=bW(O,1),P=Array.from({length:k},(e,t)=>`${E}-${pW(D)}-${pW(t+1)}`);return(0,$.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,$.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${v?TW(v,_):`not chosen`}`,disabled:a,onClick:x,children:[(0,$.jsx)(rU,{name:`calendar`,size:16}),(0,$.jsx)(`span`,{children:v?TW(v,_):s}),(0,$.jsx)(rU,{name:`chevronDown`,size:13})]}),l&&(0,$.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,$.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,$.jsx)(`b`,{children:j}),(0,$.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&M<n,onClick:()=>f(b(bW(T,-1))),children:(0,$.jsx)(rU,{name:`chevronLeft`,size:16})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&N>r,onClick:()=>f(b(bW(T,1))),children:(0,$.jsx)(rU,{name:`chevronRight`,size:16})})]})]}),(0,$.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:w,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,$.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),A>0&&(0,$.jsx)(`span`,{style:{gridColumn:`span ${A}`},"aria-hidden":`true`}),P.map(e=>(0,$.jsx)(`button`,{type:`button`,"data-day":e,tabIndex:e===d?0:-1,disabled:!y(e),"aria-pressed":e===v,"aria-current":e===_?`date`:void 0,"aria-label":vW(e).toLocaleDateString(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`,timeZone:`UTC`}),onClick:()=>S(e),children:Number(e.slice(8))},e))]}),c&&v&&(0,$.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function AW({value:e,onChange:t,min:n,step:r=30,disabled:i=!1,label:a=`Time`,placeholder:o=`Pick a time`}){let[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(-1),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(null),m=(0,Q.useId)(),h=OW(s,c,d,f),g=hW.test(e||``)?e:null,_=g&&!DW(r).includes(g)?[...DW(r),g].sort():DW(r),v=e=>!n||e>=n;(0,Q.useEffect)(()=>{s&&(p.current?.focus(),p.current?.querySelector(`[data-active="true"]`)?.scrollIntoView?.({block:`nearest`}))},[s,l]);let y=()=>{if(s){c(!1);return}let e=_.indexOf(g);u(e>=0?e:Math.max(0,_.findIndex(v))),c(!0)},b=e=>{v(e)&&(t?.(e),c(!1),f.current?.focus())};return(0,$.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,$.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?EW(g):`not chosen`}`,disabled:i,onClick:y,children:[(0,$.jsx)(rU,{name:`clock`,size:16}),(0,$.jsx)(`span`,{children:g?EW(g):o}),(0,$.jsx)(rU,{name:`chevronDown`,size:13})]}),s&&(0,$.jsx)(`ul`,{className:`sm-when-pop sm-when-times`,role:`listbox`,ref:p,tabIndex:-1,"aria-label":`Pick a ${a.toLowerCase()}`,"aria-activedescendant":l>=0?`${m}-${l}`:void 0,onKeyDown:e=>{let t=t=>{let n=t,r=e.key===`ArrowUp`||e.key===`End`?-1:1;for(;n>=0&&n<_.length&&!v(_[n]);)n+=r;return n>=0&&n<_.length?n:l};if(e.key===`ArrowDown`)u(t(l+1));else if(e.key===`ArrowUp`)u(t(l-1));else if(e.key===`Home`)u(t(0));else if(e.key===`End`)u(t(_.length-1));else if(e.key===`Enter`||e.key===` `)_[l]&&b(_[l]);else return;e.preventDefault()},children:_.map((e,t)=>(0,$.jsx)(`li`,{id:`${m}-${t}`,role:`option`,"aria-selected":e===g,"aria-disabled":!v(e)||void 0,"data-active":t===l||void 0,onPointerDown:e=>e.preventDefault(),onClick:()=>b(e),children:EW(e)},e))})]})}function jW({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Date`,clearable:s=!1,defaultTime:c=`09:00`,step:l=30}){let u=_W(e?.slice(0,10))?e.slice(0,10):``,d=hW.test(e?.slice(11,16)||``)?e.slice(11,16):``,f=n?.slice(0,10)||void 0,p=f?n.slice(11,16):``,m=e=>e===f&&p?DW(l).find(e=>e>=p)||p:null;return(0,$.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,$.jsx)(kW,{value:u,onChange:e=>{if(!e){t?.(``);return}let n=m(e),r=d||c;n&&r<n&&(r=n),t?.(`${e}T${r}`)},min:f,max:r?.slice(0,10),utc:i,disabled:a,label:`${o} day`,clearable:s}),(0,$.jsx)(AW,{value:d,onChange:e=>t?.(`${u||f||wW({utc:i})}T${e}`),min:(u||f||wW({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}Ct();var MW=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),NW=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),PW=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),FW=(e,{aspectRatios:t,resolutions:n=[],qualities:r=[],references:i=0,seed:a=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),qualities:Object.freeze(r),references:i,seed:a}),IW=(e,{aspectRatios:t=[],resolutions:n=[],durations:r,firstFrame:i=!0,lastFrame:a=!1,requiresFirstFrame:o=!1,seed:s=!1,nativeAudio:c=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),durations:Object.freeze(r),firstFrame:i,lastFrame:a,requiresFirstFrame:o,seed:s,nativeAudio:c});Object.freeze({"nano-banana-2":FW(`Nano Banana 2`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":FW(`Nano Banana 2 Lite`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":FW(`Nano Banana Pro`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":FW(`GPT Image 2`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-1.5":FW(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":FW(`Kling Image V3`,{aspectRatios:[`21:9`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],resolutions:[`1K`,`2K`]}),"seedream-v4.5":FW(`Seedream 4.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`2K`,`4K`],seed:!0})}),Object.freeze({"seedance-2.0":IW(`Seedance 2.0`,{aspectRatios:NW,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":IW(`Seedance 2.0 Fast`,{aspectRatios:NW,resolutions:[`480p`,`720p`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":IW(`Seedance 2.0 Mini`,{aspectRatios:NW,resolutions:[`480p`,`720p`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"kling-v3-turbo":IW(`Kling 3.0 Turbo`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[5,10]}),"wan-2.6-flash":IW(`Wan 2.6 Flash`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[3,4,5],requiresFirstFrame:!0}),"veo-3.1-lite":IW(`Veo 3.1 Lite`,{aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[4,6,8],lastFrame:!0,nativeAudio:!0}),"vidu-q3-turbo":IW(`Vidu Q3 Turbo`,{durations:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],lastFrame:!0,nativeAudio:!0}),"wan-2.7":IW(`Wan 2.7`,{resolutions:[`720p`,`1080p`],durations:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],lastFrame:!0,requiresFirstFrame:!0,seed:!0})}),Object.freeze([`model`,`aspectRatio`,`resolution`,`quality`]),Object.freeze([`model`,`duration`,`resolution`,`aspectRatio`,`generateAudio`]),Object.freeze({references:8,negativePrompt:2e3,seed:2147483647}),Object.freeze({speech:Object.freeze({text:3800,defaultVoice:`asteria`,speed:Object.freeze({min:.25,max:4,default:1})}),music:Object.freeze({min:5,max:240,default:30}),sfx:Object.freeze({min:.5,max:22,default:4})}),Ct();var LW=Object.freeze({googlesheets:`Google Sheets`,googledrive:`Google Drive`,googledocs:`Google Docs`,googlecalendar:`Google Calendar`,gmail:`Gmail`,youtube:`YouTube`,tiktok:`TikTok`,linkedin:`LinkedIn`,hubspot:`HubSpot`,github:`GitHub`,whatsapp:`WhatsApp`,"meta-ads":`Meta Ads`}),RW=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,zW=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),BW=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),VW=[[`send`,new Set([`send`,`reply`,`message`,`notify`,`email`,`forward`,`dm`,`invite`])],[`add`,new Set([`add`,`append`,`insert`,`create`,`new`,`log`,`save`,`record`,`upsert`,`write`,`import`,`book`,`schedule`])],[`update`,new Set([`update`,`edit`,`change`,`modify`,`patch`,`set`,`rename`,`move`,`replace`,`mark`])],[`remove`,new Set([`delete`,`remove`,`archive`,`trash`,`cancel`,`unsubscribe`])],[`upload`,new Set([`upload`])]],HW={post:[`Post to`,`Posting to`],send:[`Send to`,`Sending to`],add:[`Add to`,`Adding to`],update:[`Update in`,`Updating in`],remove:[`Remove from`,`Removing from`],upload:[`Upload to`,`Uploading to`],read:[`Get from`,`Getting from`]},UW=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),WW=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function GW(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=UW(e);return LW[n]||(n?WW(n):`the app`)}function KW(e){let t=String(e?.manifest?.name||``).split(` · `).slice(1).join(` `),n=String(e?.capability?.capabilityId||``).split(`:`).at(-1),r=UW(e).replace(/[-_.]/g,``).toLowerCase(),i=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,` `).trim().split(` `).filter(Boolean);return t.length>1&&t[0].replace(/[-_.]/g,``)===r&&t.shift(),t};for(let e of[i(t),i(n)]){let t=e.slice(0,3),n=t.find(e=>RW.test(e)||zW.has(e)||VW.some(([,t])=>t.has(e)));if(n&&RW.test(n))return`read`;if(e.some(e=>zW.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>BW.has(e)))return`post`;let r=n&&VW.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function qW(e){let t=GW(e),n=KW(e),[r,i]=HW[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var JW=e=>qW(e).verbs,YW=Object.freeze({"text.generate":[`Write`,`Writing…`],"image.generate":[`Generate image`,`Generating image…`],"video.generate":[`Generate video`,`Generating video…`],"video.render":[`Make video`,`Making video…`],"audio.speech":[`Generate voiceover`,`Generating voiceover…`],"audio.transcribe":[`Transcribe`,`Transcribing…`],"image.describe":[`Describe`,`Describing…`],"audio.music":[`Generate music`,`Generating music…`],"audio.sfx":[`Generate sound`,`Generating sound…`],"web.fetch":[`Read page`,`Reading…`],"web.research":[`Research`,`Researching…`],"media.analyze":[`Analyze`,`Analyzing…`],"photos.pick":[`Pick photos`,`Picking photos…`],"timeline.propose":[`Suggest edit`,`Suggesting…`],"workspace.propose":[`Suggest changes`,`Suggesting…`],"connection.execute":[`Send`,`Sending…`]}),XW=(e,t)=>e===`connection.execute`&&t?JW(t):YW[e]||[`Make it`,`Working…`];function ZW(e){let t=[...new Set(e.map(e=>XW(e)[0]))].map((e,t)=>t?e.charAt(0).toLowerCase()+e.slice(1):e);return t.length>1?`${t.slice(0,-1).join(`, `)} and ${t.at(-1)}`:t[0]||XW()[0]}var QW=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function $W(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||XW(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${QW(t.credits)}`:r||t?.credits===0?`${s} · ${QW(0)}`:s}ct();var eG=(e,t)=>Object.freeze({kind:e,mimeType:t}),tG=Object.freeze({png:eG(`image`,`image/png`),jpg:eG(`image`,`image/jpeg`),jpeg:eG(`image`,`image/jpeg`),webp:eG(`image`,`image/webp`),gif:eG(`image`,`image/gif`),mp4:eG(`video`,`video/mp4`),mov:eG(`video`,`video/quicktime`),webm:eG(`video`,`video/webm`),mp3:eG(`audio`,`audio/mpeg`),wav:eG(`audio`,`audio/wav`),m4a:eG(`audio`,`audio/mp4`),aac:eG(`audio`,`audio/aac`),ogg:eG(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(nt).map(([e,t])=>[e,eG(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(tG).filter(([,e])=>e.kind!==`file`))),Object.freeze({"text/csv":[`application/vnd.ms-excel`,`text/x-csv`,`application/csv`],"text/markdown":[`text/x-markdown`,`text/plain`],"application/zip":[`application/x-zip-compressed`],"application/json":[`text/json`]}),Object.freeze([`image`,`video`,`audio`]);var nG=Object.freeze({png:`PNG`,jpg:`JPEG`,webp:`WebP`,gif:`GIF`,mp4:`MP4`,mov:`MOV`,webm:`WebM`,mp3:`MP3`,wav:`WAV`,m4a:`M4A`,aac:`AAC`,ogg:`OGG`,pdf:`PDF`,txt:`TXT`,csv:`CSV`,md:`Markdown`,json:`JSON`,zip:`ZIP`}),rG=e=>Object.entries(tG).filter(([t,n])=>e.includes(n.kind)&&nG[t]).map(([e])=>nG[e]),iG=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],aG=e=>iG([...new Set(rG(e))]),oG=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),sG=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),cG=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),lG=e=>/^[aeiou]/i.test(e)?`an`:`a`;function uG(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=oG[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||sG.has(a)||a===i,s=aG(cG[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${lG(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${lG(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var dG=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],fG=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],pG=new Set([`image`,`video`,`audio`,`file`]),mG={image:`image`,video:`film`,audio:`music`,file:`image`},hG=e=>{let t;try{t=JSON.parse(e)}catch{return String(e)}return Array.isArray(t)?t.map(e=>e?.message===`Unknown manifest field`?`This SDK does not know the Block’s “${e.path}” setting. Update the SDK, then restart the preview.`:`${e?.path?`${e.path}: `:``}${e?.message||`Something is wrong with the Block.`}`).join(` `):String(e)},gG={pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`},_G={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(gG).map(e=>`.${e}`).join(`,`)};async function vG(e,t){if(t===`image`){let t=await createImageBitmap(e),n={width:t.width,height:t.height};return t.close?.(),n}if(t!==`video`&&t!==`audio`)return{};let n=URL.createObjectURL(e),r=document.createElement(t);try{r.preload=`metadata`,r.src=n,await new Promise((e,t)=>{r.onloadedmetadata=e,r.onerror=()=>t(Error(`This file does not play in the browser.`)),setTimeout(e,8e3)});let e=Number.isFinite(r.duration)&&r.duration>0?Math.round(r.duration*1e3)/1e3:void 0;return t===`video`?{...r.videoWidth?{width:r.videoWidth,height:r.videoHeight}:{},...e?{duration:e}:{}}:e?{duration:e}:{}}finally{URL.revokeObjectURL(n)}}async function yG(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?gG[n]||e.type:e.type||`application/octet-stream`,i=await vG(e,t).catch(()=>({})),a=await fetch(`/__dev/files`,{method:`POST`,headers:{"Content-Type":r,"X-File-Name":encodeURIComponent(e.name)},body:e}),o=await a.json().catch(()=>({}));if(!a.ok||!o.url)throw Error(o.error||`The preview could not keep this file.`);return{kind:t,assetId:`picked-${o.url.split(`/`)[4]}`,versionId:`v1`,url:o.url,mimeType:r,bytes:e.size,name:e.name,...i}}function bG({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=rW(e)}){let s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),m=async e=>{if(e){l(!0),d(``);try{a(await yG(e,t.type))}catch(e){d(e.message)}finally{l(!1)}}},h=e=>{let t=e.target.files?.[0];e.target.value=``,m(t)},g=uG(e,t),_=(0,$.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:_G[t.type],onChange:h});return r&&!n?(0,$.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,$.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,$.jsxs)(`div`,{className:`dh-media-drop`,"data-over":f||void 0,onDragOver:e=>{e.preventDefault(),f||p(!0)},onDragLeave:()=>p(!1),onDrop:e=>{e.preventDefault(),p(!1),!i&&!c&&m(e.dataTransfer.files?.[0])},children:[(0,$.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,$.jsx)(`span`,{children:t.description}),(0,$.jsx)(`small`,{children:g.formats}),(0,$.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,$.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,$.jsxs)(`div`,{className:`dh-media`,children:[(0,$.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,$.jsx)(rU,{name:n?mG[t.type]:`plus`,size:16}),(0,$.jsx)(`span`,{children:c?`Adding…`:xG(n)||g.choose})]}),_,u&&(0,$.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):(0,$.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,$.jsx)(rU,{name:mG[t.type],size:16}),(0,$.jsx)(`span`,{children:xG(n)||`Add one in the example`}),(0,$.jsx)(`small`,{children:`Example`})]})]})}var xG=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},SG=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},CG=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function wG(e){return(await fetch(`/__dev/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function TG(e,{signal:t}={}){if(typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`))throw Error(`The local preview shows stand-in media and files mapped in tests/mocks.json.`);let n=await fetch(e.url,{signal:t});if(!n.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let r=await createImageBitmap(await n.blob()),i=Math.min(1,512/Math.max(r.width,r.height)),a=document.createElement(`canvas`);return a.width=Math.max(1,Math.round(r.width*i)),a.height=Math.max(1,Math.round(r.height*i)),a.getContext(`2d`).drawImage(r,0,0,a.width,a.height),r.close?.(),{url:a.toDataURL(`image/png`),width:a.width,height:a.height}}function EG(e,{signal:t}={}){return typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`)?Promise.reject(Error(`The local preview plays stand-in media and files mapped in tests/mocks.json.`)):Gn(e,{signal:t})}function DG({value:e}){let t=xG(e);if(!e.url.startsWith(`/api/media/`))return(0,$.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,$.jsx)(rU,{name:mG[e.kind],size:16}),(0,$.jsx)(`span`,{children:t||`Result`})]});let n=e.width>0&&e.height>0?`${e.width}/${e.height}`:null,r=n?{aspectRatio:n}:void 0;return(0,$.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,$.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,$.jsx)(fW,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,$.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,$.jsx)(`figcaption`,{children:t})]})}var OG=e=>(0,$.jsx)(DG,{value:e}),kG=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function AG({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||rW(e),[c,l]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{l(o)},[o]);let u=`dh-input-${e}`,d=t.description||void 0,f=n?.control===`select`&&Array.isArray(n.options)?n.options:null,p=f?(0,$.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,$.jsxs)(`span`,{className:`dh-slider`,children:[(0,$.jsx)(`input`,{id:u,type:`range`,min:t.min,max:t.max,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(Number(e.target.value)),onPointerUp:()=>i(Number(c)),onKeyUp:()=>i(Number(c)),onBlur:()=>i(Number(c))}),(0,$.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,$.jsx)(`input`,{id:u,type:`checkbox`,checked:!!c,disabled:a,onChange:e=>{l(e.target.checked),i(e.target.checked)}}):[`number`,`integer`].includes(t.type)?(0,$.jsx)(`input`,{id:u,type:`number`,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{if(c===``)return i(void 0);let e=Number(c);Number.isFinite(e)&&i(e)}}):[`text`,`string`].includes(t.type)?(0,$.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,$.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:SW(e,s,typeof o==`string`?o:``)?(0,$.jsx)(jW,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,$.jsx)(kW,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):kG.has(t.type)?(0,$.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,$.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,$.jsx)(rU,{name:mG[e.kind]||`image`,size:16}),(0,$.jsx)(`span`,{children:xG(e)||`${s} ${t+1}`})]},t)),!(Array.isArray(o)?o.length:o)&&(0,$.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,$.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,$.jsxs)(`div`,{className:`dh-row`,children:[(0,$.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function jG({value:e,onCommit:t,disabled:n}){let r=(0,Q.useMemo)(()=>JSON.stringify(e,null,2),[e]),[i,a]=(0,Q.useState)(r),[o,s]=(0,Q.useState)(``);return(0,Q.useEffect)(()=>{a(r),s(``)},[r]),(0,$.jsxs)(`div`,{className:`dh-input`,children:[(0,$.jsx)(`textarea`,{"aria-label":`Input JSON`,spellCheck:!1,rows:8,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:()=>{if(i!==r)try{let e=JSON.parse(i||`{}`);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`The input is one JSON object, keyed by input port.`);s(``),t(e)}catch(e){s(e.message)}}}),o&&(0,$.jsx)(`p`,{role:`alert`,children:o})]})}var MG=(0,Q.memo)(function({entries:e,onClear:t}){let n=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[e]),(0,$.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,$.jsx)(`ol`,{ref:n,children:e.map(e=>(0,$.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,$.jsx)(`time`,{children:e.time}),(0,$.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,$.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,$.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),NG={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},PG={full:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,$.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,$.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,$.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,$.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}),dark:(0,$.jsx)(`path`,{d:`M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z`}),white:(0,$.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,$.jsx)(`path`,{d:`M9 3h6M10 3v6l-5 9a2 2 0 0 0 1.7 3h10.6a2 2 0 0 0 1.7-3l-5-9V3`})},FG=({name:e})=>(0,$.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:PG[e]});function IG(e,t){(0,Q.useLayoutEffect)(()=>{let t=e.current,n=t?.closest(`.dh-main`);if(!t||!n)return;let r=0,i=()=>{r=0;let e=parseFloat(getComputedStyle(n).paddingTop)+parseFloat(getComputedStyle(n).paddingBottom),i=HH({width:t.parentElement.clientWidth,available:n.clientHeight-e,heightAt:e=>{t.style.zoom=e===1?``:String(e),t.style.flex=`none`,t.style.minHeight=`0`;let n=Math.ceil(t.getBoundingClientRect().height);return t.style.flex=``,t.style.minHeight=``,n},mode:`auto`});t.style.zoom=i===1?``:String(i)},a=()=>{r||=requestAnimationFrame(i)};i(),addEventListener(`resize`,a);let o=e=>{[`IMG`,`VIDEO`,`AUDIO`].includes(e.target?.tagName)&&a()};return t.addEventListener(`load`,o,!0),t.addEventListener(`loadedmetadata`,o,!0),()=>{cancelAnimationFrame(r),removeEventListener(`resize`,a),t.removeEventListener(`load`,o,!0),t.removeEventListener(`loadedmetadata`,o,!0),t.style.zoom=``}},t)}function LG({label:e,value:t,options:n,onChange:r}){return(0,$.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,$.jsx)(FG,{name:e})},e))})}var RG=140,zG=260,BG={"text.generate":`Write`,"image.generate":`Generate a picture`,"video.generate":`Generate a video`,"audio.speech":`Speak`,"audio.music":`Make music`,"audio.sfx":`Make a sound effect`,"audio.transcribe":`Transcribe`,"image.describe":`Describe a picture`,"media.analyze":`Look at the media`,"web.fetch":`Read a web page`,"web.research":`Research the web`,"timeline.render":`Render`,"audio.decode":`Decode audio`,"audio.extract":`Take out the audio`,"audio.normalize":`Even out the loudness`,"video.cut":`Cut the video`,"video.concat":`Join videos`,"video.resize":`Resize the video`,"image.thumbnail":`Take a still`,"image.compose":`Join pictures`,"document.text":`Read a document`,"files.read":`Read a file`,"files.write":`Save a file`,"net.fetch":`Call a web service`,"connections.call":`Use a connected app`,"actions.run":`Run an action`,"assets.create":`Add to the project`},VG=e=>BG[e.name]||BG[e.api]||e.name;function HG({on:e,label:t,onChange:n}){return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,$.jsx)(`span`,{className:`dh-switch-track`,children:(0,$.jsx)(`span`,{className:`dh-switch-knob`})}),(0,$.jsx)(`span`,{children:t})]})}function UG({tabs:e,status:t,control:n,children:r}){let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(()=>Number(SG(`stillmade.dev.dock`,``))||zG),c=(0,Q.useRef)(null),l=e=>a(t=>t===e?null:e),u=e=>{i&&(c.current={y:e.clientY,height:o},e.currentTarget.setPointerCapture(e.pointerId))},d=e=>{let t=c.current;t&&s(Math.round(Math.max(RG,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},f=()=>{c.current&&(c.current=null,CG(`stillmade.dev.dock`,String(o)))},p=e.find(e=>e.key===i);return(0,$.jsxs)(`section`,{className:`dh-dock`,"data-open":p?`true`:`false`,style:p?{height:o}:void 0,"aria-label":`Run details`,children:[p&&(0,$.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f}),(0,$.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":i===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>l(e.key),children:[e.label,e.alert&&(0,$.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,$.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,$.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":p?`Fold the panel`:`Open the panel`,title:p?`Fold the panel`:`Open the panel`,"aria-expanded":!!p,onClick:()=>a(t=>t?null:e[0].key),children:(0,$.jsx)(rU,{name:`chevronRight`,size:16})})]}),p&&(0,$.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${p.key}`,"aria-labelledby":`dh-tab-${p.key}`,children:r(p.key)})]})}function WG(){let[e,t]=(0,Q.useState)({revision:0,content:null,problem:null,folder:``}),[n,r]=(0,Q.useState)(0),[i,a]=(0,Q.useState)(()=>SG(`stillmade.dev.theme`,`light`)),[o,s]=(0,Q.useState)(()=>SG(`stillmade.dev.width`,`full`)),[c,l]=(0,Q.useState)(0),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)({}),[w,T]=(0,Q.useState)([]),[E,D]=(0,Q.useState)({}),O=(0,Q.useRef)({}),k=(0,Q.useRef)(0),A=(0,Q.useCallback)((e,t)=>T(n=>[...n.slice(-299),{id:++k.current,kind:e,label:NG[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),j=(0,Q.useCallback)(async()=>{let e=await(await fetch(`/__dev/package`,{cache:`no-store`})).json();return t(e),e},[]);(0,Q.useEffect)(()=>{let e=!0;j().then(t=>{e&&(d(e=>e??(t.content?.tests?.[0]?.input||{})),A(`reload`,`Previewing ${t.folder}`),t.problem&&A(`error`,hG(t.problem)))}).catch(e=>A(`error`,e.message));let t=new EventSource(`/__dev/events`);return t.addEventListener(`package`,async t=>{let n=JSON.parse(t.data);try{if(await j(),!e)return;r(e=>e+1),A(n.problem?`error`:`reload`,n.problem?`Reloaded with a problem: ${hG(n.problem)}`:`Reloaded after a change`)}catch(e){A(`error`,e.message)}}),t.addEventListener(`build`,e=>{let t=JSON.parse(e.data);t.state===`running`?A(`build`,`Building: ${t.command}`):t.state===`done`?A(`build`,`Build finished`):A(`error`,`Build failed${t.output?`\n${t.output}`:``}`)}),()=>{e=!1,t.close()}},[]),(0,Q.useEffect)(()=>{document.documentElement.dataset.mode=i,CG(`stillmade.dev.theme`,i)},[i]),(0,Q.useEffect)(()=>{CG(`stillmade.dev.width`,o)},[o]);let M=e.content,N=M?.manifest,P=M?.tests||[],F=e=>{l(e),d(P[e]?.input||{})},I=(0,Q.useCallback)(async(e,{signal:t}={})=>{A(`run`,`Run started`),h(!0),_(``);try{let n=await wG(e);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])A(`log`,e);for(let e of n.standIns||[])A(`stand-in`,`${e.api} ${e.name} (${e.source===`picked`?`your file`:e.source===`example`?`example file`:/mocks/.test(e.source)?`the Block's tests`:`recorded stand-in`})`);if(y({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw A(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return p(n.outputs),A(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(p(null),_(e?.message||`The run did not finish.`)),e}finally{h(!1)}},[A]),ee=(0,Q.useCallback)(async e=>{let t=ir(O.current,e);O.current=t,D(t)},[]),te=()=>{O.current={},D({}),r(e=>e+1),A(`view`,`Shared state cleared`)},L=(0,Q.useMemo)(()=>({state:E,outputs:{},memory:null,canEdit:!0}),[E]),R=(0,Q.useCallback)(async e=>{p(e),A(`view`,`The view chose its outputs`)},[A]),ne=(0,Q.useCallback)(e=>A(`error`,String(e?.message||e)),[A]),z=(0,Q.useMemo)(()=>{let t={...u||{}};if(b)for(let[n,r]of Object.entries(e.content?.manifest?.inputs||{}))pG.has(r.type)&&(S[n]?t[n]=S[n]:delete t[n]);return t},[u,b,S,e.content]),re=(0,Q.useCallback)(t=>d(n=>{if(!b)return t;let r={...t};for(let[t,i]of Object.entries(e.content?.manifest?.inputs||{}))pG.has(i.type)&&(n&&Object.hasOwn(n,t)?r[t]=n[t]:delete r[t]);return r}),[b,e.content]),ie=fG.find(([e])=>e===o)?.[2],ae=M?.capability?.operation?[M.capability.operation]:(N?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),oe=m?N?.action?.running||XW(ae.length===1?ae[0]:void 0)[1]:$W(void 0,{credits:0},{verb:N?.action?.label||ZW(ae)}),B=(0,Q.useRef)(null);IG(B,[M,o,f,g,m]);let se=f?Object.entries(N?.outputs||{}).filter(([e])=>f[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof f[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(f[e])?(0,$.jsx)(`p`,{className:`dh-date`,children:(0,$.jsx)(`time`,{dateTime:f[e],children:CW(f[e])})},e):(0,$.jsx)(uW,{value:f[e],renderMedia:OG},e)):null,ce=m?`Running…`:v?v.failed?`Last run failed`:`Ran in ${v.ms} ms${v.calls.length?` · ${v.calls.length} ${v.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,le=[{key:`activity`,label:`Activity`,alert:w.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${v?.calls.length?` · ${v.calls.length}`:``}`},...M?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,$.jsxs)(`div`,{className:`dh-page`,children:[(0,$.jsxs)(`header`,{className:`dh-bar`,children:[(0,$.jsxs)(`div`,{className:`dh-title`,children:[(0,$.jsx)(`h1`,{children:N?.name||`Block preview`}),N&&(0,$.jsx)(`span`,{className:`dh-meta`,children:N.version})]}),(0,$.jsx)(`span`,{className:`dh-spacer`}),P.length>1&&(0,$.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,$.jsx)(FG,{name:`example`}),(0,$.jsx)(`select`,{"aria-label":`Example`,value:c,onChange:e=>F(Number(e.target.value)),children:P.map((e,t)=>(0,$.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,$.jsx)(LG,{label:`Width`,value:o,options:fG,onChange:s}),(0,$.jsx)(LG,{label:`Appearance`,value:i,options:dG,onChange:a}),(0,$.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>r(e=>e+1),children:(0,$.jsx)(rU,{name:`refresh`,size:16})})]}),e.problem&&(0,$.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:hG(e.problem)}),(0,$.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,$.jsx)(`div`,{className:`dh-frame`,style:ie?{maxWidth:ie}:void 0,children:M?M.view?(0,$.jsx)(JU,{view:M.view,policyContent:M,input:z,sharedView:L,onSharedChange:ee,onRun:I,onUseOutput:R,onPreviewImage:TG,onPreviewMedia:EG,onError:ne,actorId:`dev-preview`,title:`${N.name} preview`,height:560,fitContent:!0},n):(0,$.jsxs)(`div`,{className:`dh-noview`,ref:B,children:[(0,$.jsx)(`div`,{className:`dh-form`,children:Object.entries(N.inputs||{}).map(([e,t])=>pG.has(t.type)?(0,$.jsx)(bG,{name:e,port:t,title:(N.ui||[]).find(t=>t?.port===e)?.label||rW(e),value:z[e],own:b,disabled:m,onPick:t=>C(n=>({...n,[e]:t}))},e):(0,$.jsx)(AG,{name:e,port:t,control:(N.ui||[]).find(t=>t?.port===e),value:z[e],disabled:m,onCommit:t=>d(n=>({...n,[e]:t}))},e))}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:m,onClick:()=>I(z).catch(()=>{}),children:oe}),g&&(0,$.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),se?(0,$.jsxs)(`div`,{className:`dh-results`,children:[(0,$.jsx)(`h2`,{children:`Result`}),se]}):!g&&(0,$.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,$.jsx)(`p`,{children:`The result appears here after a run.`})})]}):(0,$.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,$.jsx)(UG,{tabs:le,status:ce,control:(0,$.jsx)(HG,{on:!b,label:`Example media`,onChange:e=>x(!e)}),children:e=>e===`activity`?(0,$.jsx)(MG,{entries:w,onClear:()=>T([])}):e===`calls`?v?.calls.length?(0,$.jsx)(`ol`,{className:`dh-calls`,children:v.calls.map((e,t)=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`strong`,{children:VG(e)}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`small`,{children:e.source===`picked`?`read from your file`:e.source===`example`?`read from a StillMade example file`:/mocks/.test(e.source)?`answered from the Block's tests`:`answered by a recorded stand-in`})]},t))}):(0,$.jsx)(`p`,{className:`dh-muted`,children:v?`The last run made no hosted or media calls.`:`Run the Block to see the calls it makes and what answered each one.`}):e===`result`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:te,children:`Clear shared state`})]}),g&&(0,$.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),se||!g&&(0,$.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:m||!M,onClick:()=>I(z).catch(()=>{}),children:oe})]}),u&&(0,$.jsx)(jG,{value:z,onCommit:re,disabled:!M}),f&&(0,$.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(f,null,2)})]})})]})}(0,v.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(WG,{}));
1905
+ `+(d?``:wH),m=globalThis.crypto.randomUUID().replaceAll(`-`,``),h=`__sm_view_${m}`,g=`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,_=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,v=`(()=>{"use strict";document.currentScript.remove();const session=${LU(t)},channel=${LU(AU)},send=parent.postMessage.bind(parent);let input={},ready=false,inputRevision=0,editRevision=0,sequence=0,pending=null,pendingAdopt=null,adoptSequence=0,pendingImage=null,imageSequence=0,pendingDesktop=null,desktopSequence=0;const mediaURLs=new Set();const mintedImages=new Set();Object.defineProperty(globalThis,${LU(_)},{configurable:true,value:url=>mintedImages.has(url)});const clearMedia=()=>{for(const url of mediaURLs)URL.revokeObjectURL(url);mediaURLs.clear()};const listeners=new Set();let calls=0,started=0;const now=performance.now.bind(performance),resetTask=setTimeout.bind(globalThis);let gestureId=0,gestureAt=-Infinity;for(const type of ["pointerdown","keydown"])addEventListener(type,event=>{if(event.isTrusted){gestureId++;gestureAt=now();}},true);${d?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${gH.toString()})(channel,session,send,${LU({guardName:g,taskMs:sH.taskMs,assets:l})});`:`Object.defineProperty(globalThis,${LU(h)},{configurable:true,value:()=>{if(calls===0){started=now();resetTask(()=>{calls=0},0)}if(++calls>10000||now()-started>50)throw Error("Interface is doing too much work. Move processing into the Block runtime.")}});addEventListener("message",event=>{if(event.isTrusted&&event.source===parent)calls=0},true);`}let controlEffects=0;let assisted=false,trackedCalls=new Set(),trackedFailure=null,controlOffset=0;const track=promise=>{if(assisted){trackedCalls.add(promise);promise.then(()=>trackedCalls.delete(promise),error=>{trackedFailure=error;trackedCalls.delete(promise)})}return promise};const controlSnapshot=(offset=controlOffset,automatic=true)=>{try{let snapshot;try{snapshot=dynamicUI.inspectControls({offset})}catch(error){if(!automatic||error.message!=="Choose a current control page"||!Number.isSafeInteger(offset)||offset<0)throw error;snapshot=dynamicUI.inspectControls({offset:0});}controlOffset=snapshot.offset;send({channel,session,op:"view-controls",snapshot},"*")}catch(error){send({channel,session,op:"view-controls-error",error:String(error.message).slice(0,1000)},"*")}};const dynamicUI=(${or.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${ar.toString()})(channel,session,${LU(rr)},sharedLifecycle);const textControls=${i?`(()=>{${Yn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${LU(o)},send});})()`:`null`};const sharedControls=(${Jn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${LU(a)});const {documentTools,sharedDocuments}=(${Xn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${Ot.toString()})((kind,value)=>{if(kind==="media"){if(mediaURLs.size>=2)throw Error("Release a previous media preview before opening another");if(!["video","audio"].includes(value.kind))throw Error("Choose an audio or video reference");}return new Promise((resolve,reject)=>{const id=String(++imageSequence);pendingImage={id,resolve,reject,media:kind==="media"};send({channel,session,op:kind==="media"?"preview-media":"preview-image",id,value},"*")})});const connectionAPI=(${Et.toString()})(${LU(AU)},${LU(t)},${c},send),workAPI=(${E.toString()})(${LU(AU)},${LU(t)},${s},send);const liveBridge=(${Dt.toString()})(${LU(AU)},${LU(t)},send,(operation,args)=>api.desktop(operation,args));const api=Object.freeze({...connectionAPI,...workAPI,live:liveBridge.live,${d?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,`:``}connectedApp(...args){controlEffects++;return track(connectionAPI.connectedApp(...args))},sharedWork(...args){controlEffects++;return track(workAPI.sharedWork(...args))},previewSharedWorkMedia(...args){controlEffects++;return track(workAPI.previewSharedWorkMedia(...args))},schemaFields:(${sr.toString()})(${JSON.stringify(a)}),...sharedAPI,...documentTools,connectDocument:sharedDocuments.connectDocument,bindShared:sharedControls.bindShared,setSharedDefaults:sharedControls.setSharedDefaults,scheduleSharedEdit:sharedControls.scheduleSharedEdit,render:dynamicUI.render,onAction:dynamicUI.onAction,releaseMedia(url){if(mediaURLs.delete(url))URL.revokeObjectURL(url)},previewMedia(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("media",value))},desktop(operation,args={}){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingDesktop)return Promise.reject(Error("A desktop request is already pending"));if(typeof operation!=="string"||JSON.stringify(args).length>131072)return Promise.reject(Error("Invalid desktop request"));return track(new Promise((resolve,reject)=>{const id=String(++desktopSequence);pendingDesktop={id,resolve,reject};send({channel,session,op:"desktop",id,operation,args},"*")}))},get input(){return structuredClone(input)},onInput(fn){if(typeof fn!=="function")throw Error("Expected a function");listeners.add(fn);if(ready)fn(structuredClone(input));return()=>listeners.delete(fn)},useOutput(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingAdopt)return Promise.reject(Error("An output choice is already pending"));let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded output values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++adoptSequence);pendingAdopt={id,resolve,reject};send({channel,session,op:"use-output",id,outputs:values},"*")}))},previewImage(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value))},run(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pending)return Promise.reject(Error("A run is already in progress"));try{dynamicUI.assertCommitted();sharedControls.assertNoComposition();}catch(error){return Promise.reject(error);}let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded input values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++sequence),requested=JSON.parse(serialized),sourceRevision=inputRevision,localRevision=editRevision,call={id,resolve,reject,sent:false};pending=call;Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>{dynamicUI.assertCommitted();sharedControls.assertNoComposition();if(pending!==call||!ready)throw Error("Preview was closed before its edits were saved.");if(inputRevision!==sourceRevision||editRevision!==localRevision)throw Error("The input changed while edits were saving. Review it before running again.");const savedText=textControls?.getValues?.()||{};for(const [key,value] of Object.entries(savedText)){const captured=typeof requested[key]==="string"?requested[key]:typeof requested[key]?.text==="string"?requested[key].text:null;if(captured!==null&&captured!==value)throw Error("The input changed while shared text was saving. Review it before running again.");}if(!sharedAPI.getShared().canEdit)throw Error("Shared editing is unavailable or read only.");call.sent=true;send({channel,session,op:"run",id,input:requested,...(gestureId?{gesture:{id:gestureId,age:now()-gestureAt}}:{})},"*");}).catch(error=>{if(pending===call){pending=null;call.reject(error);}});}))}});Object.defineProperty(globalThis,"StillMade",{value:api,writable:false,configurable:false});addEventListener("message",event=>{if(event.source!==parent||!event.data||event.data.channel!==channel||event.data.session!==session)return;const data=event.data;if(liveBridge.receive(data))return;if(data.op==="inspect-view-controls"){controlSnapshot(data.offset,false);return;}if(data.op==="locate-view-control"&&typeof data.id==="string"){let rect=null;try{rect=dynamicUI.locateControl(data.control)}catch{}send({channel,session,op:"view-control-rect",id:data.id,rect},"*");return;}if(data.op==="dispatch-named-text"&&typeof data.id==="string"){Promise.resolve().then(()=>textControls.dispatchNative(data.control,data.id)).then(()=>send({channel,session,op:"named-text-result",token:${LU(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${LU(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${LU(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${LU(o)},snapshot:textControls.inspectNative()},"*");return;}if(data.op==="dispatch-view-control"&&typeof data.id==="string"){if(assisted){send({channel,session,op:"view-control-result",id:data.id,error:"A declared control is already running"},"*");return;}assisted=true;trackedFailure=null;const controlDocumentSeal=sharedDocuments.captureControlSettlement(),controlSharedSeal=sharedLifecycle.captureControlState(),controlInputRevision=inputRevision,controlEffectRevision=controlEffects;const personalControlUnchanged=()=>controlDocumentSeal&&inputRevision===controlInputRevision&&controlEffects===controlEffectRevision&&JSON.stringify(sharedLifecycle.captureControlState())===JSON.stringify(controlSharedSeal)&&!controlSharedSeal.closed&&controlSharedSeal.ready&&!controlSharedSeal.pending&&!controlSharedSeal.queued&&!controlSharedSeal.failed&&sharedDocuments.unchangedControlSettlement(controlDocumentSeal);dynamicUI.dispatchControl(data.control,async()=>{for(let round=0;round<16;round++){await Promise.allSettled(Array.from(trackedCalls));await dynamicUI.flushAll();await sharedControls.flushAll();if(personalControlUnchanged())await sharedDocuments.settleControl(controlDocumentSeal);else await sharedDocuments.flushAll();await sharedLifecycle.flushSharedWrites();await new Promise(resolve=>setTimeout(resolve,0));if(trackedFailure)throw trackedFailure;if(!trackedCalls.size){if(controlDocumentSeal&&!personalControlUnchanged())await sharedDocuments.flushAll();dynamicUI.assertCommitted();sharedControls.assertNoComposition();return;}}throw Error("Declared action did not settle");}).then(()=>send({channel,session,op:"view-control-result",id:data.id},"*"),error=>send({channel,session,op:"view-control-result",id:data.id,error:String(error?.message||"Declared action failed").slice(0,1000)},"*")).finally(()=>{assisted=false;controlSnapshot()});return;}if(data.op==="flush-shared"&&typeof data.id==="string"){Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>dynamicUI.flushAll()).then(()=>sharedControls.assertNoComposition()).then(()=>send({channel,session,op:"flush-shared-result",id:data.id},"*"),error=>send({channel,session,op:"flush-shared-result",id:data.id,error:String(error?.message||"Pending edits could not be confirmed").slice(0,1000)},"*"));return;}if(data.op==="desktop-result"&&pendingDesktop&&data.id===pendingDesktop.id){const call=pendingDesktop;pendingDesktop=null;data.error?call.reject(Error(data.error)):call.resolve(data.result)}else if(data.op==="use-output-result"&&pendingAdopt&&data.id===pendingAdopt.id){const call=pendingAdopt;pendingAdopt=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="input"){inputRevision+=1;if(pending&&!pending.sent){pending.reject(Error("Preview input changed before its edits were saved."));pending=null;}clearMedia();previews.reset();if(pendingImage)pendingImage.reject(Error("Preview input changed"));pendingImage=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview input changed"));pendingAdopt=null;input=data.input;ready=true;try{sharedControls.useInputDefaults(input)}catch{}for(const fn of listeners)try{fn(structuredClone(input))}catch(error){send({channel,session,op:"interface-error",error:String(error?.message||"The Block interface could not display its input").slice(0,1000)},"*")}}else if(data.op==="result"&&pending?.sent&&data.id===pending.id){const call=pending;pending=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="preview-media-result"&&pendingImage?.media&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error)call.reject(Error(data.error));else{try{const url=URL.createObjectURL(data.preview.blob);mediaURLs.add(url);call.resolve({kind:data.preview.kind,url,mimeType:data.preview.blob.type,bytes:data.preview.blob.size})}catch(error){call.reject(error)}}}else if(data.op==="preview-image-result"&&pendingImage&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error){call.reject(Error(data.error));}else{const url=data.preview?.url;if(typeof url==="string"){mintedImages.delete(url);mintedImages.add(url);if(mintedImages.size>64)mintedImages.delete(mintedImages.values().next().value)}call.resolve(data.preview)}}else if(data.op==="dispose"){liveBridge.dispose();clearMedia();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview was reset"));pendingAdopt=null;if(pendingImage)pendingImage.reject(Error("Preview was reset"));pendingImage=null;if(pending)pending.reject(Error("Preview was reset"));pending=null;listeners.clear();ready=false}});addEventListener("input",()=>{editRevision+=1;},true);addEventListener("change",()=>{editRevision+=1;},true);addEventListener("compositionstart",()=>{editRevision+=1;},true);addEventListener("keydown",event=>{if(event.key==="Escape"&&!document.documentElement.hasAttribute("data-stillmade-stage"))send({channel,session,op:"escape"},"*")},true);addEventListener("click",event=>{if(event.target.closest?.("a,area"))event.preventDefault()},true);send({channel,session,op:"ready"},"*");})();`,y=d?`document.currentScript.remove();for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${hH(e.javascript||``,g)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${h})=>{"use strict";delete globalThis[${LU(h)}];for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${oH(e.javascript||``,h)}\n})(globalThis[${LU(h)}]);`.replace(/<\/script/gi,`<\\/script`);return`<!doctype html><html data-mode="${[`dark`,`white`].includes(n)?n:`light`}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${m}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${d?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${d?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${CH.replace(/@font-face\s*\{[^}]*\}/g,``)}${d?PU:NU}${TH}${d?``:FU}${(p||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${IU}</style></head><body>${e.html}${u?`<script nonce="${m}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${m}">${v.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${m}">document.currentScript.remove();${u?`(${hU.toString()})(${LU(AU)},${LU(t)},parent.postMessage.bind(parent));`:``}(${LH.toString()})(${LU(AU)},${LU(t)});(${RH.toString()})(${LU(AU)},${LU(t)});(${WH.toString()})(${LU(AU)},${LU(t)},(${HH.toString()}),"auto",(${UH.toString()}),${!d});(${GH.toString()})(${LU(AU)},${LU(t)},(${KH.toString().replace(/<\/script/gi,`<\\/script`)})(),${LU(tU)},{minted:(()=>{const read=globalThis[${LU(_)}];delete globalThis[${LU(_)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${OH.toString()})(${LU(AU)},${LU(t)},((validateCursorAnchor)=>(${DH.toString()}))(${EH.toString()}));(${kH.toString()})(${LU(AU)},${LU(t)},(${jH.toString()}));<\/script><script nonce="${m}">${y}<\/script></body></html>`}function qU({activity:e,declaresFolders:t,session:n}){let[r,i]=(0,Q.useState)(!1),a=e?.folders||[],o=e?.entries||[];if(!t&&!o.length)return null;let s=r=>{r.currentTarget.open&&t&&!e&&n.current?.call(`folder.shared`).catch(()=>{})},c=async e=>{i(!0);try{await n.current?.call(`folder.forget`,{folder:e.id})}catch{}finally{i(!1)}};return(0,$.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,$.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,$.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,$.jsx)(`ul`,{children:o.map(e=>(0,$.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,$.jsx)(`p`,{children:`Nothing yet.`})]})}function JU({view:e,input:t={},sharedView:n=null,presenceKey:r=null,peers:i=[],actorId:a=null,onSharedChange:o,sharedText:s=null,sharedWork:c=null,connectedApp:l=null,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m,policyContent:h,policyParent:g,currentAppViewPolicy:_=null,title:v=`Block preview`,height:y=480,fitContent:x=!1,resetKey:E=0,theme:D,appearance:O=`package`,lockedInputKeys:k=[],agentContext:A=null}){let j=BU(e),M=BU(h),N=BU(g),P=[`comfyui`,`capability`].includes(M?.manifest?.runtime)||!!M?.manifest?.desktopTools?.length||M?.manifest?.runtime===`module`&&!!M?.manifest?.permissions?.capabilities?.length,F=M?.capability?.operation===`image.generate`?9e5:36e4,I=(0,Q.useRef)(null),ee=(0,Q.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m}),te=(0,Q.useRef)(t),[L,R]=(0,Q.useState)(``),[ne,z]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(0),ae=(0,Q.useRef)(null),oe=(0,Q.useRef)(null),[B,se]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)(null),[ue,de]=(0,Q.useState)(null),fe=M?.manifest?.id||null,[pe,me]=(0,Q.useState)(()=>aU(fe)),[he,ge]=(0,Q.useState)(null),_e=(0,Q.useRef)(pe);_e.current=pe;let ve=e=>{me(e),oU(fe,e)},ye=(0,Q.useRef)(1);ye.current=pe===`auto`?he?.zoom||1:pe;let be=(0,Q.useRef)(ve);be.current=ve;let xe=(0,Q.useContext)(uU),Se=(0,Q.useRef)(xe);Se.current=xe;let[Ce,we]=(0,Q.useState)(null),[Te,Ee]=(0,Q.useState)(null),[De,Oe]=(0,Q.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),ke=(0,Q.useRef)(`light`);ke.current=[`dark`,`white`].includes(D||De)?D||De:`light`;let Ae=(0,Q.useRef)(l);Ae.current=l;let je=(0,Q.useRef)(c);je.current=c;let Me=(0,Q.useRef)(s);Me.current=s;let Ne=(0,Q.useRef)(!1),[Pe,Fe]=(0,Q.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),Ie=()=>{let e={enabled:!!Me.current,projectId:Me.current?.projectId??null,placementId:Me.current?.placementId??null};Fe(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,Q.useEffect)(()=>{Ne.current||Ie()},[!!s,s?.projectId,s?.placementId]);let Le=Pe.enabled,Re=Pe.projectId,ze=Pe.placementId,Be=!!Te?.count&&!!(Te.dirty||Te.pending||Te.error);(0,Q.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Oe(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Ve=(0,Q.useMemo)(()=>{try{let e=RU(t);return{value:e,signature:pt(e)}}catch(e){return{error:e.message}}},[t]);ee.current={onSharedChange:o,onRun:u,onUseOutput:d,onPreviewImage:f,onPreviewMedia:p,onError:m},te.current=Ve;let[He,Ue]=(0,Q.useState)(null),We=_?He?.handle===_&&He.allowed:!M||He?.content===M&&He.parent===N&&He.allowed;(0,Q.useEffect)(()=>{if(!M&&!_)return;let e=!0,t=new AbortController;return Ue(null),(_?w(_,{signal:t.signal}):Promise.all([M,...N?[N]:[]].map(e=>TU(e,{signal:t.signal})))).then(()=>{e&&Ue({handle:_,content:M,parent:N,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&M&&oi(M,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(Ue({handle:_,content:M,parent:N,allowed:!1,error:t.message}),ee.current.onError?.(t))}),()=>{e=!1,t.abort()}},[M,N,_,re]);let Ge=fH(j)&&j.files?j.files:null,[Ke,qe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!Ge||!We){qe(null);return}let e=!0,t=new AbortController;return qe(null),Promise.resolve().then(()=>(aH(j),ui(()=>Promise.resolve().then(()=>(kU(),EU)),void 0))).then(({loadViewAssets:e})=>e(Ge,{signal:t.signal})).then(t=>{e&&qe({files:Ge,assets:t})},t=>{e&&qe({files:Ge,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[j,Ge,We]);let Je=Ge?Ke?.files===Ge?Ke:{loading:!0}:null,Ye=JSON.stringify([...new Set(k.filter(e=>typeof e==`string`))].sort()),Xe=[j,Je,E,O,re,a,r,P,F,x,Le,Re,ze,Ye,!!M?.manifest?.sharedWork,M?.capability?.operation],Ze=(0,Q.useRef)(null);if(!Ze.current||Xe.some((e,t)=>!Object.is(e,Ze.current.inputs[t]))){let e;try{if(Je?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if(Je?.error)throw Error(Je.error);let t=MU(),n=MU(),r=pU();e={session:t,nativeTextToken:n,filming:!!r,html:KU(j,t,ke.current,O,Le,JSON.parse(Ye),n,!!M?.manifest?.sharedWork,M?.capability?.operation===`connection.execute`,{assets:Je?.assets||{},filming:r})}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}Ze.current={inputs:Xe,document:e}}let Qe=Ze.current.document,$e=Qe?.session;(0,Q.useEffect)(()=>{let e=I.current?.contentWindow;e&&$e&&e.postMessage({channel:AU,session:$e,op:`zoom-mode`,mode:pe},`*`)},[pe,$e]),(0,Q.useEffect)(()=>{if(!x||!$e)return;let e=null,t=()=>{e=null;let t=I.current?.contentWindow;t&&t.postMessage({channel:AU,session:$e,op:`zoom-space`,height:sU(I.current)},`*`)},n=()=>{clearTimeout(e),e=setTimeout(t,200)};return addEventListener(`resize`,n),()=>{clearTimeout(e),removeEventListener(`resize`,n)}},[x,$e]);let et=(0,Q.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[Qe.session]),tt=(0,Q.useRef)(n);tt.current=n??et;let nt=(0,Q.useRef)(n==null);nt.current=n==null;let rt=(0,Q.useRef)({session:null,count:0}),it=(0,Q.useRef)(null),at=(0,Q.useRef)(null),ot=(0,Q.useRef)(null),st=(0,Q.useRef)(null),ct=(0,Q.useRef)(null),lt=(0,Q.useRef)(null),ut=(0,Q.useRef)(null);lt.current={key:r,peers:i,actorId:a};let dt=(0,Q.useRef)(null),ft=(0,Q.useRef)(null);ft.current={input:Ve.signature,error:Ve.error,view:j,policyContent:M,policyParent:N,resetKey:E,appearance:O,policyReady:We};let ht=(0,Q.useRef)(null);ht.current=pt([A?.projectId,A?.placementId,A?.sourceDigest,a].map(e=>e??null));let[V,_t]=(0,Q.useState)(null),vt=pt([kt(),a,ht.current,Qe.session,Ve.signature,We].map(e=>e??null));(0,Q.useEffect)(()=>{let e=!0;if(_t(null),!A?.projectId||!A?.placementId||!A?.sourceDigest||Ve.error||!We||a!==kt())return()=>{e=!1};let t=vt;return mt(Ve.value).then(n=>{e&&_t({basis:t,value:{version:1,actorId:a,projectId:A.projectId,placementId:A.placementId,sourceDigest:A.sourceDigest,inputDigest:n}})},()=>{e&&_t(null)}),()=>{e=!1}},[vt]),V?.basis===vt&&V.value;let[yt,bt]=(0,Q.useState)(null),xt=(0,Q.useRef)(null),St=(0,Q.useRef)(null),[Ct,wt]=(0,Q.useState)(null),[Et,Dt]=(0,Q.useState)(!1),[Ot,At]=(0,Q.useState)(!1),[jt,Mt]=(0,Q.useState)(null);jt&&jt.actor===a&&jt.runtimeActor===kt()&&jt.identity===ht.current&&jt.session===Qe.session&&Object.keys(jt.authority).every(e=>jt.authority[e]===ft.current[e])&&jt.evidence,{...A},M?.manifest?.id,M?.manifest?.version,Qe.session,Ve.signature,tt.current?.canEdit,{...A},Qe.session,Ve.signature,tt.current?.canEdit,(0,Q.useEffect)(()=>{if(bt(null),wt(null),At(!1),Dt(!1),Mt(null),R(``),de(null),we(null),Ee(null),Qe.error||Qe.loading||!We)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=0,p=0,m=new Set,h=-1/0,g=-1/0,_=e=>{e.isTrusted&&(h=Date.now())};globalThis.document.addEventListener(`pointerdown`,_,!0),globalThis.document.addEventListener(`keydown`,_,!0);let v,y=0,b=null,w=[],E=0,D=null,O=0,k=0,N=null,L=fH(j),ne=null,re=()=>{ne&&globalThis.document.fullscreenElement!==ne&&(ne=null,ce({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,re);let ie=()=>{let t;return t=gz(M,{onStatus:n=>{e&&v===t&&se(n)},onLive:(n,r)=>{e&&v===t?I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&v===t&&le(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};v=ie(),ae.current=v,se(null),le(null);let B=()=>{if(!e||!tt.current?.canEdit)return;let t=v;v=ie(),ae.current=v,b=null,se(null),Promise.resolve(t.close()).catch(()=>{})};oe.current=B;let ce=t=>{e&&I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,...t},`*`)},ue=null,fe=0,pe=(e,t)=>{let n=at.current,r=I.current,i=n?.parentElement;if(!n||!r||!i)return;let a=Math.max(0,t?.x??0),o=Math.max(0,t?.y??0),s=Math.min(r.clientWidth,(t?.x??0)+(t?.width??0)),c=Math.min(r.clientHeight,(t?.y??0)+(t?.height??0));if(!t||s<=a||c<=o){n.hidden=!0,delete n.dataset.control;return}let l=r.getBoundingClientRect(),u=i.getBoundingClientRect();n.style.transform=`translate(${l.left+r.clientLeft-u.left-i.clientLeft+a}px,${l.top+r.clientTop-u.top-i.clientTop+o}px)`,n.style.width=`${s-a}px`,n.style.height=`${c-o}px`,n.dataset.control=e,n.hidden=!1};pe(null,null),ot.current=n=>{!e||!t||typeof n!=`string`||ue&&Date.now()-ue.at<1e3||(ue={id:`locate-`+ ++fe,control:n,at:Date.now()},ce({op:`locate-view-control`,id:ue.id,control:n}))};let me=new Map,he=new Set,ve=0,xe=!1,Ce=(e,t)=>new Promise(n=>{let r=`film-`+ ++ve,i=setTimeout(()=>{me.delete(r),n(null)},6e3);me.set(r,e=>{clearTimeout(i),me.delete(r),n(e)}),ce({op:e,id:r,...t})}),Te=Qe.filming&&I.current?mU({element:I.current,placementId:A?.placementId||null,capture:e=>Ce(`capture-view`,e),locate:e=>Ce(`locate-view-control`,{control:e}),get drawn(){return xe},onChange:e=>(he.add(e),()=>he.delete(e))}):null,De=null,Oe=null,Pe=0,Fe=!1,Be=a,Ve=ft.current,He=ht.current,Ue=(t,n)=>{if(!e||Fe||t?.signal?.aborted||kt()!==Be||ht.current!==He||Oe&&te.current.signature!==Oe.inputIdentity||De&&te.current.signature!==De.inputIdentity&&te.current.signature!==n||Object.keys(Ve).filter(e=>e!==`input`).some(e=>Ve[e]!==ft.current[e]))throw Fe=!0,At(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Ge=e=>{if(!De)return;let t=De;De=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Dt(!1),t.reject(e)};St.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Ue(r),!t||De)throw Error(`The declared interface is loading or busy.`);if(e===`dispatch-view-control`&&!r.taskFence)throw Error(`The declared interface requires its active project task.`);let s=String(++Pe),c=()=>{Fe=!0,At(!1),i?.abort(),Ge(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,F);De={id:s,op:e,inputIdentity:te.current.signature,offset:n.offset,context:r,resolve:a,reject:o,timer:l,abort:c},r.signal?.addEventListener(`abort`,c,{once:!0}),e===`dispatch-view-control`&&Dt(!0),ce({op:e,id:s,...n})}catch(e){o(e)}})},xt.current={request:(e,n)=>new Promise((r,i)=>{try{if(Ue(n),!t||De||Oe||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++Pe),o=()=>{Fe=!0,At(!1),Oe?.id===a&&(Oe=null,Dt(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,F);Oe={id:a,field:e.field,inputIdentity:te.current.signature,context:n,resolve:r,reject:i,timer:s,abort:o},n.signal?.addEventListener(`abort`,o,{once:!0}),Dt(!0),ce({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let Ke=()=>{if(Fe)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return De?.op===`dispatch-view-control`?(Ue(De.context),De.context):null},qe=!1,Je=0,Ye=[],Xe=0,Ze=!1,$e=0,et=[],rt=0,mt=0,V=[],_t=null,vt=!1,yt={projectId:Re,placementId:ze,actorId:a},Ct=()=>e&&Me.current?.projectId===yt.projectId&&Me.current?.placementId===yt.placementId,Et=e=>({message:String(e?.message||`Shared text failed.`).slice(0,1e3),...typeof e?.code==`string`&&/^[A-Z][A-Z0-9_]{0,79}$/.test(e.code)?{code:e.code}:{}}),Ot=Me.current?.projectId&&a?Zn({projectId:Me.current.projectId,actorId:a,headers:Qn,onChange:e=>{if(Ct()){if(e.kind===`revoked`){vt=!0,ce({op:`shared-view`,value:{...tt.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||_t===null&&(_t=setTimeout(()=>{_t=null,t&&Ct()&&!vt&&ce({op:`text-refresh`})},100)))}}}):null,jt=je.current?.projectId&&a?Zn({projectId:je.current.projectId,actorId:a,headers:Qn,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(Xe++,ce({op:`shared-work-refresh`}))}}):null,Nt=()=>{t&&ce({op:`theme`,mode:ke.current})};ut.current=Nt;let Pt=`[]`,Ft=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=lt.current,i=!nt.current&&e&&localStorage.getItem(`stillmade:show-shared-cursors`)!==`false`?n.filter(t=>t.user_id!==r&&t.selection?.cursor?.visible&&t.selection.cursor.surface===e).slice(0,50).flatMap(e=>{let t=EH(e.selection.cursor.anchor);return t?[{id:String(e.session_id).slice(0,200),label:String(e.label||`Teammate`).slice(0,120),anchor:t}]:[]}):[],a=JSON.stringify(i);a!==Pt&&(Pt=a,ce({op:`peer-cursors`,peers:i}))};ct.current=Ft,window.addEventListener(`stillmade:cursor-preferences`,Ft),window.addEventListener(`storage`,Ft);let It=null,Lt=()=>{let e=I.current;if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+e.clientLeft,y:t.top+e.clientTop,right:t.right,bottom:t.bottom}},Rt=()=>{It&&(It.bounds=Lt())},zt=()=>{It&&(It=null,window.removeEventListener(`scroll`,Rt,{capture:!0}),window.removeEventListener(`resize`,Rt))},Bt=n=>{let r=n.detail;e&&r?.root?.contains?.(I.current)&&(r.action===`start`&&t&&!It?(It={bounds:Lt()},window.addEventListener(`scroll`,Rt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Rt),ce({op:`pick-start`})):r.action===`stop`&&It&&(zt(),ce({op:`pick-stop`})))};window.addEventListener(AH.control,Bt);let Vt=e=>{R(e),ee.current.onError?.(Object.assign(Error(e),{shown:!0}))},Ht=()=>{e&&(clearInterval(D),N?.disconnect(),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),Vt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))};it.current=L?()=>{e&&(clearInterval(D),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),Vt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))}:null;let Ut=()=>{if(typeof PerformanceObserver!=`function`||!PerformanceObserver.supportedEntryTypes?.includes(`longtask`))return;let e=[],t=e=>Array.from(e.attribution||[]).some(e=>e.containerType===`iframe`&&typeof e.containerSrc==`string`&&e.containerSrc.endsWith(`#${Qe.session}`));N=new PerformanceObserver(n=>{for(let r of n.getEntries()){if(!t(r))continue;let n=r.startTime+r.duration;if(e=e.filter(e=>e.end>n-5e3),e.push({end:n,duration:r.duration}),r.duration>=sH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Ht()}});try{N.observe({type:`longtask`})}catch{N=null}},Wt=()=>{O=Date.now(),D=setInterval(()=>{if(!e)return clearInterval(D);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-O>8e3)return Ht();ce({op:`ping`,id:String(++k)})},2e3)};z(!0);let Gt=setTimeout(()=>{e&&!t&&(z(!1),Vt(S()?C():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),I.current&&(I.current.src=`about:blank`))},S()?5e3:15e3),Kt=e=>{let t=o;t&&(Mt(null),o=null,t.controller.abort(),e&&ce({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},qt=()=>{if(!t)return;let e=te.current;if(e.error){Kt(`Preview input is unavailable.`),Vt(e.error);return}s!==e.signature&&(Kt(`Preview input changed. Use its current image.`),s=e.signature,ce({op:`input`,input:e.value}))};dt.current=qt;let Jt=null,Yt=!1,Xt=0,Zt=[],Qt=null,$t=0,en=null,tn=qn(()=>{if(nt.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(Qt)return Qt.promise;let n=String(++$t),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{Qt?.id===n&&(Qt=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return Qt={id:n,promise:a,resolve:r,reject:i,timer:o},ce({op:`flush-shared`,id:n}),a}),nn=()=>{if(t&&tt.current)try{let e=RU(tt.current),t=pt(e);if(t===Jt)return;Jt=t,ce({op:`shared-view`,value:e})}catch(e){Vt(e.message)}};st.current=nn;let rn=t=>{e&&nt.current&&(tt.current.outputs=t,nn())},an=r=>{let s=r.data;if(L&&e&&gt(s)&&s.op===`navigated`&&s.channel===AU&&s.session===Qe.session&&(r.source===null||r.source===I.current?.contentWindow)){it.current?.();return}if(!e||r.source!==I.current?.contentWindow||!gt(s)||s.channel!==AU||s.session!==Qe.session)return;if(s.op===`document-ready`){n||(n=!0,ce({op:`document`,html:Qe.html}));return}if(s.op===`view-changed`){xe=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>gt(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of he)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&me.has(s.id)){let e=me.get(s.id),t=s.rect;if(!e){s.bitmap?.close?.();return}e(s.op===`capture-view-result`?s.bitmap instanceof ImageBitmap?s.bitmap:null:gt(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`zoom-key`){be.current(s.step===`auto`?`auto`:cU(ye.current,s.step===`bigger`?VH:-VH));return}if(s.op===`media-stage`){let e=I.current,t=globalThis.document;if(!e)return;if(s.on===!0){if(!t.fullscreenElement&&globalThis.navigator?.userActivation?.isActive&&t.activeElement===e&&typeof e.requestFullscreen==`function`){ne=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{ne=null})}catch{ne=null}}}else if(t.fullscreenElement===e){ne=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){ge(e=>{let t={supported:s.supported===!0,zoom:Number.isFinite(s.zoom)?s.zoom:1};return e&&e.supported===t.supported&&e.zoom===t.zoom?e:t});return}if(s.op===`ready`){t||(t=!0,z(!1),clearTimeout(Gt),ce({op:`zoom-mode`,mode:_e.current}),x&&ce({op:`zoom-space`,height:sU(I.current)}),L&&(Wt(),Ut()),Nt(),qt(),nn(),Ft(),ce({op:`inspect-view-controls`,offset:0}),ce({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!Qt||s.id!==Qt.id)return;let e=Qt;Qt=null,clearTimeout(e.timer);let t=s.error||en;t?e.reject(Error(String(t).slice(0,1e3))):e.resolve({queued:!0});return}if(s.op===`escape`){let e=Date.now();globalThis.document.activeElement===I.current&&e-E>=300&&(E=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){L&&typeof s.id==`string`&&(O=Date.now());return}if(s.op===`unresponsive`){L&&Ht();return}if(s.op===`interface-error`){Vt(String(s.error||`The Block interface could not display its input`).slice(0,1e3));return}if(s.op===`document-store-status`){let e=s.status;gt(e)&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=8)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&we(e);return}if(s.op===`text-recovery-status`){let e=s.status;Le&&gt(e)&&Object.keys(e).every(e=>[`count`,`dirty`,`pending`,`readonly`,`error`,`retryable`].includes(e))&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=100)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&typeof e.retryable==`boolean`&&Ee(e);return}if(!t)return;if(s.op===`pick-hover`){if(!It)return;let e=FH(s.hover),t=It.bounds,n=null;if(e&&t){let r=Math.max(t.x,e.rect.x+t.x),i=Math.max(t.y,e.rect.y+t.y),a=Math.min(t.right,e.rect.x+t.x+e.rect.width),o=Math.min(t.bottom,e.rect.y+t.y+e.rect.height);a>r&&o>i&&(n={...e,rect:{x:r,y:i,width:a-r,height:o-i},cursor:{x:e.cursor.x+t.x,y:e.cursor.y+t.y}})}window.dispatchEvent(new CustomEvent(AH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!It)return;zt();let e=s.op===`pick-result`?IH(s.target):null;e?window.dispatchEvent(new CustomEvent(AH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(AH.cancel));return}if(s.op===`named-text-controls`){if(s.token===Qe.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=RU(s.snapshot);e.every(e=>gt(e)&&typeof e.field==`string`&&typeof e.identity==`string`&&typeof e.value==`string`&&e.value.length<=1e4&&typeof e.partial==`boolean`&&typeof e.ready==`boolean`&&typeof e.disabled==`boolean`)&&bt(e)}return}if(s.op===`named-text-result`){let e=Oe;if(!e||s.id!==e.id||s.token!==Qe.nativeTextToken)return;try{if(Ue(e.context),s.error)throw Error(String(s.error).slice(0,1e3));e.resolve()}catch(t){e.reject(t)}finally{Oe=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Dt(!1)}return}if(s.op===`view-controls`){try{let e=RU(s.snapshot);if(!gt(e)||!Number.isSafeInteger(e.revision)||!Number.isSafeInteger(e.total)||e.total<0||e.total>1e4||!Number.isSafeInteger(e.offset)||!Array.isArray(e.controls)||e.controls.length>20||e.controls.some(e=>!gt(e)||typeof e.id!=`string`||typeof e.identity!=`string`||typeof e.action!=`string`||typeof e.disabled!=`boolean`||typeof e.hidden!=`boolean`))throw Error(`Invalid declared interface controls.`);if(wt(e),At(!Fe),De?.op===`inspect-view-controls`&&e.offset===De.offset){let e=De;Ue(e.context),De=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Ge(e)}return}if(s.op===`view-control-rect`){if(!ue||s.id!==ue.id)return;let{control:e}=ue,t=s.rect;ue=null,pe(e,gt(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`view-controls-error`){Ge(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(De?.op!==`dispatch-view-control`||s.id!==De.id)return;let e=De;try{if(Ue(e.context),s.error)throw Error(String(s.error).slice(0,1e3));De=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Dt(!1),e.resolve()}catch(e){Ge(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=Je)return;Je=Number(s.id);let t=e=>ce({op:`connected-app-result`,id:s.id,...e}),n=Ae.current,r=ft.current;Ye=Ye.filter(e=>Date.now()-e<6e4);try{if(M?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Tt(s.operation,RU(s.args));if(i.operation!==`tasks`&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);if(qe||Ye.length>=30)throw Error(`Wait for the current task request.`);qe=!0,Ye.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Ae.current?.projectId||n.placementId!==Ae.current?.placementId||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:RU(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{qe=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-media-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=$e)return;$e=Number(s.id);let t=je.current,n=ft.current,r=Xe,i=e=>ce({op:`shared-work-result`,id:s.id,...e});try{if(!M?.manifest?.sharedWork||!M.manifest.permissions?.project?.includes(`work.shared`)||!t?.previewMedia||typeof s.contributionId!=`string`||!/^[0-9a-f-]{36}$/i.test(s.contributionId))throw Error(`Choose a permitted saved creative in this workspace.`);if(et=et.filter(e=>Date.now()-e<6e4),Ze||et.length>=60)throw Error(`Wait for the current media preview.`);Ze=!0,et.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==Xe||Object.keys(n).some(e=>n[e]!==ft.current[e]))throw Error(`This workspace changed before the creative preview.`);if(!(t.media instanceof Blob)||!t.media.size||t.media.size>67108864||![`image`,`video`,`audio`].includes(t.kind)||!t.media.type.startsWith(t.kind+`/`))throw Error(`This preview exceeds the media limit.`);i(t)},e=>i({error:String(e.message||`Media preview failed.`).slice(0,1e3)})).catch(e=>i({error:String(e.message).slice(0,1e3)})).finally(()=>{Ze=!1})}catch(e){i({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=$e)return;$e=Number(s.id);let t=e=>ce({op:`shared-work-result`,id:s.id,...e}),n=je.current,r=ft.current,i=Xe;et=et.filter(e=>Date.now()-e<6e4);try{if(!M?.manifest?.permissions?.project?.includes(`work.shared`)||!M.manifest.sharedWork||!n?.request)throw Error(`Shared work is unavailable in this preview. Open the saved Block in its project.`);let a=T(s.operation,RU(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);if(Ze||et.length>=60)throw Error(`Wait for the current shared-work request.`);Ze=!0,et.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==je.current?.projectId||n.placementId!==je.current?.placementId||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==Xe){if([`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation))throw Error(`Saved-work access changed. Read its current version.`);t({result:{saved:!0,refreshRequired:!0}});return}t({result:RU(o)})},e=>t({error:String(e.message||`Shared work failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{Ze=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`text-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=mt)return;mt=Number(s.id);let e=e=>ce({op:`text-result`,id:s.id,...e}),t=Me.current,n=te.current.signature,r=ft.current;if(V=V.filter(e=>Date.now()-e<6e4),!Le||!Ct()||!t||typeof t.request!=`function`||![`read`,`initialize`,`update`,`reset`].includes(s.action)||typeof s.key!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(s.key)||[`constructor`,`prototype`,`__proto__`].includes(s.key)){e({error:{message:`Shared text is unavailable for this field.`}});return}if(rt>=16||V.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!Ct()||te.current.error||te.current.signature!==n||Object.keys(r).some(e=>r[e]!==ft.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(vt||s.action!==`read`&&!tt.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=RU(s.body),!gt(a)||new TextEncoder().encode(JSON.stringify(a)).length>5e4||Object.keys(a).some(e=>![`protocol`,`requestId`,`sourceIdentity`,`epoch`,`textRevision`,`value`,`update`].includes(e)))throw Error(`Invalid shared text request.`)}catch(t){e({error:Et(t)});return}rt++,V.push(Date.now()),Promise.resolve().then(async()=>{if(i(),Ke()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=Oe,n;if(e&&s.action!==`read`){if(Ue(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==Qe.nativeTextToken||s.nativeText?.callId!==e.id)throw Error(`Unrelated text events cannot use this native task.`);n=e.context}else if(s.nativeText)throw Error(`The original text invocation is no longer current; do not replay.`);return await t.request(s.action,{...a,placementId:t.placementId,fieldKey:s.key},n)}catch(e){if(s.action===`read`&&e.code===`SHARED_TEXT_FIELD_UNSUPPORTED`&&typeof tt.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:RU(t)})}).catch(t=>e({error:Et(t)})).finally(()=>{rt--});return}if(s.op===`cursor`){let e=s.cursor;if(gt(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=I.current?.getBoundingClientRect(),n=EH(e.anchor),r=lt.current.key;t&&window.dispatchEvent(new CustomEvent(`stillmade:sandbox-cursor`,{detail:{x:(t.left+e.x*t.width)/Math.max(1,window.innerWidth),y:(t.top+e.y*t.height)/Math.max(1,window.innerHeight),visible:e.visible!==!1,...n&&typeof r==`string`&&r.length>0&&r.length<=200&&!nt.current?{anchor:n,surface:r}:{}}}))}return}if(s.op===`shared-view-update`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=Xt)return;Xt=Number(s.id);let t=e=>{en=e.error?String(e.error):null,ce({op:`shared-view-result`,id:s.id,...e})};if(Zt=Zt.filter(e=>Date.now()-e<6e4),Yt||Zt.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!tt.current?.canEdit||!nt.current&&typeof ee.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=RU(s.request),new TextEncoder().encode(JSON.stringify(n)).length>rr.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}Yt=!0,Zt.push(Date.now()),Promise.resolve().then(()=>{if(!e||!tt.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if(Ke(),nt.current){tt.current.state=ir(tt.current.state,n),nn();return}let t=Ke();return ee.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{Yt=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&Se.current?.(s.height),x&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&de(Math.max(280,Math.min(3e4,s.height)));return}if(s.op===`live-ack`){v?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=y)return;y=Number(s.id);let t=e=>ce({op:`desktop-result`,id:s.id,...e});if(w=w.filter(e=>Date.now()-e<6e4),b||w.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=RU(s.args||{}),JSON.stringify(n).length>131072||!gt(n))throw Error(`Desktop arguments exceed the limit`)}catch(e){t({error:e.message});return}let r=![`tool.status`,`storage.info`,`storage.list`,`storage.read`,`record.status`,`device.info`,`record.cancel`,`session.close`,`live.status`,`live.stop`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`].includes(s.operation)&&(s.operation!==`folder.pick`||s.args?.write===!0);if(r&&!tt.current?.canEdit){t({error:`Desktop changes are unavailable while this workspace is read only.`});return}if(s.operation===`record.cut`){let e=n?.source,r=zU(e),i=[];try{i=VU(te.current?.value).map(zU)}catch{}if(!r||!(v.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:v};w.push(Date.now()),b=i,Promise.resolve().then(()=>{if(!e||i.native!==v||r&&!tt.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if(Ke()&&r)throw Error(`Assisted desktop mutations require a task-safe native interface; this control is unavailable.`);return i.native.call(s.operation,n,[`record.cut`,`folder.write`].includes(s.operation)?{received:(()=>{try{return VU(te.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==v||r&&!tt.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:RU(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{b===i&&(b=null)});return}if(s.op===`use-output`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let e=e=>ce({op:`use-output-result`,id:s.id,...e});try{if(Ke())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(L&&!tt.current?.canEdit)throw Error(`This workspace is read only.`);let t=RU(s.outputs),n=ee.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);UU(t,te.current.value,v),Promise.resolve(n(t)).then(t=>{let n=RU(t);rn(n),e({outputs:n})},t=>e({error:String(t?.message||`The media output could not be saved`).slice(0,1e3)}))}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`preview-image`||s.op===`preview-media`){let t=s.op===`preview-media`;if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=l)return;Mt(null),l=Number(s.id);let n=e=>ce({op:t?`preview-media-result`:`preview-image-result`,id:s.id,...e}),r=Date.now();if(d=d.filter(e=>r-e<6e4),o||d.length>=YV.imagePreviewsPerMinute){++p<=3&&n({error:o?`An image preview is already loading`:`Image preview limit reached. Wait a minute before trying again.`}),p===4&&(Vt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,Kt(),i?.abort(),I.current&&(I.current.src=`about:blank`));return}d.push(r);let c;try{if(c=t?RU(s.value):WU(s.value),t&&(!gt(c)||![`video`,`audio`].includes(c.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof c[e]==`string`&&c[e].length>0&&c[e].length<=32768)))throw Error(`Keep the complete audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let u=t&&v?.authorizesMedia?.(c)?(e,t)=>Gn(e,t):t?ee.current.onPreviewMedia:ee.current.onPreviewImage;if(typeof u!=`function`){n({error:t?`Audio/video preview is unavailable in this workspace.`:`Image preview is unavailable in this workspace. Choose an image with the host controls.`});return}let f=new AbortController,m=ft.current,h={controller:f,id:s.id,media:t};o=h;let g=ht.current,_=a,y=kt(),b=()=>{if(f.signal.aborted||y!==kt()||g!==ht.current||Object.keys(m).some(e=>m[e]!==ft.current[e]))throw Error(`Image preview input or workspace changed.`)},x=setTimeout(()=>{e&&o===h&&Kt(`Image preview timed out. Try a smaller image.`)},YV.imagePreviewMs);f.signal.addEventListener(`abort`,()=>clearTimeout(x),{once:!0}),Promise.resolve().then(()=>(b(),u(c,{signal:f.signal}))).then(r=>{if(e&&!f.signal.aborted&&o===h){if(b(),t&&r?.kind!==c.kind)throw Error(`The host returned a different media kind.`);let e=t?Un(r):GU(r);b(),typeof c.assetId==`string`&&c.assetId.length<=512&&typeof c.versionId==`string`&&c.versionId.length<=512&&Mt({actor:_,runtimeActor:y,identity:g,session:Qe.session,authority:m,evidence:{assetId:c.assetId,versionId:c.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(x),o===h&&(o=null)});return}if(s.op!==`run`||typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=c)return;c=Number(s.id);let _=e=>ce({op:`result`,id:s.id,...e});if(L&&!tt.current?.canEdit){_({error:`Shared editing is unavailable or read only.`});return}let S=Date.now();if(u=u.filter(e=>S-e<6e4),i||u.length>=YV.runsPerMinute){++f<=3&&_({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),f===4&&(Vt(`Preview paused after too many requests. Reset it to continue.`),e=!1,Kt(),i?.abort(),I.current&&(I.current.src=`about:blank`));return}let C;try{if(!gt(s.input))throw Error(`Expected input values`);C=RU(s.input)}catch(e){_({error:e.message});return}u.push(S),R(``);let D=new AbortController;i=D,Ne.current=!0,De?.context.signal?.addEventListener(`abort`,()=>D.abort(),{once:!0});let k=setTimeout(()=>{e&&i===D&&(D.abort(),i=null,_({error:P?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},P?F:15e3);D.signal.addEventListener(`abort`,()=>clearTimeout(k),{once:!0});let A=De?.op===`dispatch-view-control`?De:null,j=A?async e=>{if(De!==A||i!==D||D.signal.aborted||!gt(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||pt(e.taskFence)!==pt(A.context.taskFence)||pt([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==He||pt(RU(e.beforeInput))!==A.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=pt(RU(e.input));for(let e=0;e<25&&te.current.signature!==t;e++)if(Ue(A.context,t),await new Promise(e=>setTimeout(e,10)),De!==A||i!==D||D.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Ue(A.context,t),te.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);A.inputIdentity=t}:void 0,N=gt(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=jU&&!m.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===I.current&&Date.now()-h>jU&&Date.now()-g>jU;N&&(m.add(s.gesture.id),g=Date.now()),Promise.resolve().then(()=>ee.current.onRun(C,{...Ke(),signal:D.signal,userActivated:N,...j?{onInputCommitted:j}:{},...M?.manifest?.desktopTools?.length?{nativeDesktopSession:v}:{}})).then(t=>{if(e&&!D.signal.aborted){if(!gt(t))throw Error(`Block execution must return named outputs`);let e=RU(t);rn(e),_({outputs:e})}},t=>{e&&!D.signal.aborted&&_({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!D.signal.aborted&&_({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(k),i===D&&(i=null),Ne.current=!1,setTimeout(()=>{e&&!Ne.current&&Ie()},250)})};return window.addEventListener(`message`,an),()=>{globalThis.document.removeEventListener(`fullscreenchange`,re),ne&&globalThis.document.fullscreenElement===ne&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),ne=null,ot.current=null,pe(null,null),Te?.();for(let e of[...me.values()])e(null);Oe&&=(clearTimeout(Oe.timer),Oe.context.signal?.removeEventListener(`abort`,Oe.abort),Oe.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,_,!0),globalThis.document.removeEventListener(`keydown`,_,!0),xt.current=null,Ge(Error(`The declared interface was closed.`)),St.current=null,Ot?.(),jt?.(),clearTimeout(_t),tn(),Qt&&=(clearTimeout(Qt.timer),Qt.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout(Gt),clearInterval(D),N?.disconnect(),ce({op:`dispose`}),e=!1,v.close(),ae.current===v&&(ae.current=null),oe.current===B&&(oe.current=null),Kt(),i?.abort(),Ne.current=!1,window.removeEventListener(`message`,an),window.removeEventListener(`stillmade:cursor-preferences`,Ft),window.removeEventListener(`storage`,Ft),window.removeEventListener(AH.control,Bt),zt(),ct.current=null,dt.current=null,st.current=null}},[Qe,We,P,F,x,r,a,Re,ze]),(0,Q.useEffect)(()=>{dt.current?.()},[t]),(0,Q.useEffect)(()=>{st.current?.(),n?.canEdit===!1&&Promise.resolve(ae.current?.close()).catch(()=>{})},[n,We]),(0,Q.useEffect)(()=>{ct.current?.()},[i,r,a,n]),(0,Q.useEffect)(()=>{ut.current?.()},[D,De]);let Nt=!!globalThis.stillmadeDesktop?.blockDesktop,Pt=B?.camera&&B?.microphone?`camera and microphone`:B?.camera?`camera`:`microphone`;return(0,$.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[B?.kind===`live`&&B.awaitingStart&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:`Ready to share your ${Pt} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:`Start ${Pt}`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Cancel`})]}),B?.kind===`live`&&B.active&&(0,$.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,$.jsx)(`strong`,{children:`${Pt[0].toUpperCase()}${Pt.slice(1)} on`}),(0,$.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.stop,children:`Turn off ${Pt}`})]}),B?.awaitingStart&&(B.kind===`folder`||B.kind===`folder-access`)&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:B.kind===`folder`?`This Block asks for a folder to ${B.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${B.folder} again for this Block.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:B.kind===`folder`?`Choose folder`:`Allow`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>B.cancel?B.cancel():ae.current?.close(),children:`Cancel`})]}),B?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(B.kind)&&(0,$.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,$.jsx)(`p`,{children:B.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:B.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:B.microphone?`Ready to record your screen with your microphone. Choose your screen or window after pressing Start.`:`Ready to record. Choose your screen or window after pressing Start.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:B.start,children:B.kind===`camera`?`Start camera recording`:B.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Cancel`})]}),B?.active&&B.kind!==`live`&&(0,$.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,$.jsxs)(`strong`,{children:[B.ended?`Recording stopped`:`Recording`,` `,B.kind||`media`]}),(0,$.jsxs)(`span`,{children:[` · `,B.ended?B.message:Nt?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:Nt?`Cancel recording and revoke access`:`Discard recording`})]}),Nt&&B?.closed&&M?.manifest?.permissions?.desktop?.length>0&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:!We||!tt.current?.canEdit,onClick:()=>oe.current?.(),children:`Reopen desktop access`}),Nt&&!B?.closed&&!B?.active&&M?.manifest?.permissions?.desktop?.length>0&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ae.current?.close(),children:`Revoke this Block’s desktop access`}),Qe.loading?(0,$.jsx)(`p`,{role:`status`,children:`Loading the interface…`}):Qe.error?(0,$.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,Qe.error]}):We?(0,$.jsxs)($.Fragment,{children:[ne&&!L&&(0,$.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,$.jsx)(`iframe`,{ref:I,onLoad:()=>{rt.current.session!==Qe.session&&(rt.current={session:Qe.session,count:0}),++rt.current.count>2&&it.current?.()},title:v,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${b(`/block-ui-sandbox.html`)}#${Qe.session}`,style:{width:`100%`,height:x&&ue||y,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...L?{display:`none`}:{}}},Qe.session),(0,$.jsx)(`span`,{ref:at,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}}),he?.supported&&!L&&(0,$.jsx)(lU,{zoom:he.zoom,mode:pe,onChange:ve})]}):(0,$.jsx)(`p`,{role:He?.error?`alert`:`status`,children:He?.error||`Checking Block safety…`}),Ce?.count>0&&(Ce.error?(0,$.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:Ce.error}):Ce.dirty||Ce.pending?(0,$.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),Te?.count>0&&(Te.error||Te.dirty||Te.pending)?(0,$.jsxs)(`div`,{className:`bs-notice`,role:Te.error?`alert`:`status`,children:[(0,$.jsx)(`p`,{children:Te.error||`Saving shared text…`}),Te.error&&(0,$.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),Te.retryable&&(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:Te.pending>0||!tt.current?.canEdit,onClick:()=>I.current?.contentWindow?.postMessage({channel:AU,session:Qe.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(L||He?.error)&&(0,$.jsxs)($.Fragment,{children:[L&&(0,$.jsx)(`p`,{role:`alert`,children:L}),(0,$.jsx)(`button`,{type:`button`,className:`btn`,disabled:Be,onClick:()=>{Be||ie(e=>e+1)},children:`Reload`})]}),(0,$.jsx)(qU,{activity:ce,declaresFolders:(M?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:ae})]})}ct();var YU=50,XU=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var ZU=e=>e==null?``:typeof e==`number`?XU.format(e):String(e);function QU(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}function $U({value:e,label:t=`Table`}){let[n,r]=(0,Q.useState)(0);if(!qe(e))return(0,$.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/YU)),a=Math.min(n,i-1),o=e.rows.slice(a*YU,a*YU+YU),s=e.columns.map(t=>e.rows.length>0&&e.rows.every(e=>e[t]===void 0||e[t]===null||typeof e[t]==`number`));return(0,$.jsxs)(`div`,{className:`bd-table`,children:[(0,$.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:e.columns.map(e=>(0,$.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,$.jsx)(`tbody`,{children:o.map((t,n)=>(0,$.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,$.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:ZU(t[e])},e))},a*YU+n))})]})}),(0,$.jsxs)(`div`,{className:`bd-bar`,children:[(0,$.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>QU(new Blob([Ze(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}Ct(),ct();var eW=new Set([`image`,`audio`,`video`]),tW=e=>eW.has(e?.kind)&&typeof e.url==`string`,nW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,rW=e=>{let t=String(e).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},iW=50,aW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),oW=e=>{if(!gt(e))return e;let t=aW(e);return t.length===1&&(Array.isArray(e[t[0]])||gt(e[t[0]]))?oW(e[t[0]]):e},sW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),cW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``);function lW(e){if(e.length<2||!e.every(e=>gt(e)&&aW(e).every(t=>sW(e[t]))))return null;let t=[...new Set(e.flatMap(aW))];if(!t.length||t.length>6)return null;let n={columns:t.map(rW),rows:e.map(e=>Object.fromEntries(aW(e).map(t=>[rW(t),typeof e[t]==`boolean`?cW(e[t]):e[t]])))};return qe(n)?n:null}function uW({value:e,renderMedia:t,depth:n=0}){let r=oW(e);if(sW(r))return(0,$.jsx)(`span`,{children:cW(r)});if(tW(r))return t?.(r)??null;if(qe(r))return(0,$.jsx)($U,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,$.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(tW)&&lW(r);return e?(0,$.jsx)($U,{value:e,label:`Results`}):n>=3?(0,$.jsx)(`span`,{children:nW(r.length,`item`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,iW).map((e,r)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(uW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>iW&&(0,$.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-iW,` more.`]})]})}if(!gt(r))return null;let i=aW(r);return i.length?n>=3?(0,$.jsx)(`span`,{children:nW(i.length,`detail`)}):(0,$.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(`dt`,{children:rW(e)}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(uW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,$.jsx)(`span`,{className:`sm-data-none`,children:`None`})}function dW(e,t){let n=(0,Q.useRef)(t),r=YH(e),[i,a]=(0,Q.useState)(null);return n.current=t,(0,Q.useEffect)(()=>{if(!r)return;let t=!0;return Promise.resolve().then(()=>n.current?.(e)).then(n=>{t&&a({src:e,url:n||null})},()=>{t&&a({src:e,url:null})}),()=>{t=!1}},[e,r]),r?i?.src===e?{url:i.url,missing:!i.url}:{url:null,missing:!1}:{url:e||null,missing:!1}}function fW({src:e,resolveUrl:t,label:n,"aria-label":r,fill:i=!1,className:a,style:o,onMissing:s,controls:c,playsInline:l,preload:u=`metadata`,...d}){let{url:f,missing:p}=dW(e,t),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(s);return _.current=s,(0,Q.useEffect)(()=>{if(p){_.current?.(e);return}let t=ZH(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,$.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,$.jsx)(rU,{name:`imageOff`,size:24})}):(0,$.jsxs)(`div`,{ref:m,className:a?`sm-player ${a}`:`sm-player`,style:o,"data-mode":`dark`,"data-fill":i?``:void 0,tabIndex:0,role:`group`,"aria-label":n||r||`Video`,children:[(0,$.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,$.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var pW=e=>String(e).padStart(2,`0`),mW=/^(\d{4})-(\d{2})-(\d{2})$/,hW=/^([01]\d|2[0-3]):([0-5]\d)$/,gW=e=>{let t=mW.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},_W=e=>{let t=gW(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},vW=e=>{let{year:t,month:n,day:r}=gW(e);return new Date(Date.UTC(t,n-1,r))},yW=(e,t)=>{let n=vW(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},bW=(e,t)=>{let{year:n,month:r,day:i}=gW(e),a=new Date(Date.UTC(n,r-1+t,1)),o=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth()+1,0)).getUTCDate();return`${a.getUTCFullYear()}-${pW(a.getUTCMonth()+1)}-${pW(Math.min(i,o))}`},xW=/(?:time|when|start|schedule|post|send|publish|remind)/i,SW=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||xW.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),CW=e=>`${TW(e.slice(0,10))}${e[10]===`T`?` · ${EW(e.slice(11,16))}`:``}`;function wW({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${pW(t.getMonth()+1)}-${pW(t.getDate())}`}function TW(e,t=wW()){return vW(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function EW(e){let[t,n]=e.split(`:`).map(Number);return new Date(Date.UTC(2e3,0,1,t,n)).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,timeZone:`UTC`})}function DW(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${pW(Math.floor(n*e/60))}:${pW(n*e%60)}`)}function OW(e,t,n,r){return(0,Q.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)};return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e]),n=>{n.key===`Escape`&&e&&(n.stopPropagation(),n.preventDefault(),t(!1),r.current?.focus())}}function kW({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Day`,placeholder:s=`Pick a day`,clearable:c=!1}){let[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null),g=OW(l,u,p,m),_=wW({utc:i}),v=_W(e)?e:null,y=e=>(!n||e>=n)&&(!r||e<=r),b=e=>n&&e<n?n:r&&e>r?r:e;(0,Q.useEffect)(()=>{l&&d&&h.current?.querySelector(`[data-day="${d}"]`)?.focus()},[l,d]);let x=()=>{if(l){u(!1);return}f(b(v||_)),u(!0)},S=e=>{y(e)&&(t?.(e),u(!1),m.current?.focus())},C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7},w=e=>{let t=null;if(C[e.key])t=yW(d,C[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=bW(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=vW(d).getUTCDay();t=yW(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(b(t)))},T=d||v||_,{year:E,month:D}=gW(T),O=`${E}-${pW(D)}-01`,k=new Date(Date.UTC(E,D,0)).getUTCDate(),A=vW(O).getUTCDay(),j=vW(O).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),M=yW(O,-1),N=bW(O,1),P=Array.from({length:k},(e,t)=>`${E}-${pW(D)}-${pW(t+1)}`);return(0,$.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,$.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${v?TW(v,_):`not chosen`}`,disabled:a,onClick:x,children:[(0,$.jsx)(rU,{name:`calendar`,size:16}),(0,$.jsx)(`span`,{children:v?TW(v,_):s}),(0,$.jsx)(rU,{name:`chevronDown`,size:13})]}),l&&(0,$.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,$.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,$.jsx)(`b`,{children:j}),(0,$.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&M<n,onClick:()=>f(b(bW(T,-1))),children:(0,$.jsx)(rU,{name:`chevronLeft`,size:16})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&N>r,onClick:()=>f(b(bW(T,1))),children:(0,$.jsx)(rU,{name:`chevronRight`,size:16})})]})]}),(0,$.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:w,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,$.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),A>0&&(0,$.jsx)(`span`,{style:{gridColumn:`span ${A}`},"aria-hidden":`true`}),P.map(e=>(0,$.jsx)(`button`,{type:`button`,"data-day":e,tabIndex:e===d?0:-1,disabled:!y(e),"aria-pressed":e===v,"aria-current":e===_?`date`:void 0,"aria-label":vW(e).toLocaleDateString(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`,timeZone:`UTC`}),onClick:()=>S(e),children:Number(e.slice(8))},e))]}),c&&v&&(0,$.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function AW({value:e,onChange:t,min:n,step:r=30,disabled:i=!1,label:a=`Time`,placeholder:o=`Pick a time`}){let[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(-1),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(null),m=(0,Q.useId)(),h=OW(s,c,d,f),g=hW.test(e||``)?e:null,_=g&&!DW(r).includes(g)?[...DW(r),g].sort():DW(r),v=e=>!n||e>=n;(0,Q.useEffect)(()=>{s&&(p.current?.focus(),p.current?.querySelector(`[data-active="true"]`)?.scrollIntoView?.({block:`nearest`}))},[s,l]);let y=()=>{if(s){c(!1);return}let e=_.indexOf(g);u(e>=0?e:Math.max(0,_.findIndex(v))),c(!0)},b=e=>{v(e)&&(t?.(e),c(!1),f.current?.focus())};return(0,$.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,$.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?EW(g):`not chosen`}`,disabled:i,onClick:y,children:[(0,$.jsx)(rU,{name:`clock`,size:16}),(0,$.jsx)(`span`,{children:g?EW(g):o}),(0,$.jsx)(rU,{name:`chevronDown`,size:13})]}),s&&(0,$.jsx)(`ul`,{className:`sm-when-pop sm-when-times`,role:`listbox`,ref:p,tabIndex:-1,"aria-label":`Pick a ${a.toLowerCase()}`,"aria-activedescendant":l>=0?`${m}-${l}`:void 0,onKeyDown:e=>{let t=t=>{let n=t,r=e.key===`ArrowUp`||e.key===`End`?-1:1;for(;n>=0&&n<_.length&&!v(_[n]);)n+=r;return n>=0&&n<_.length?n:l};if(e.key===`ArrowDown`)u(t(l+1));else if(e.key===`ArrowUp`)u(t(l-1));else if(e.key===`Home`)u(t(0));else if(e.key===`End`)u(t(_.length-1));else if(e.key===`Enter`||e.key===` `)_[l]&&b(_[l]);else return;e.preventDefault()},children:_.map((e,t)=>(0,$.jsx)(`li`,{id:`${m}-${t}`,role:`option`,"aria-selected":e===g,"aria-disabled":!v(e)||void 0,"data-active":t===l||void 0,onPointerDown:e=>e.preventDefault(),onClick:()=>b(e),children:EW(e)},e))})]})}function jW({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Date`,clearable:s=!1,defaultTime:c=`09:00`,step:l=30}){let u=_W(e?.slice(0,10))?e.slice(0,10):``,d=hW.test(e?.slice(11,16)||``)?e.slice(11,16):``,f=n?.slice(0,10)||void 0,p=f?n.slice(11,16):``,m=e=>e===f&&p?DW(l).find(e=>e>=p)||p:null;return(0,$.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,$.jsx)(kW,{value:u,onChange:e=>{if(!e){t?.(``);return}let n=m(e),r=d||c;n&&r<n&&(r=n),t?.(`${e}T${r}`)},min:f,max:r?.slice(0,10),utc:i,disabled:a,label:`${o} day`,clearable:s}),(0,$.jsx)(AW,{value:d,onChange:e=>t?.(`${u||f||wW({utc:i})}T${e}`),min:(u||f||wW({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}Ct();var MW=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),NW=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),PW=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),FW=(e,{aspectRatios:t,resolutions:n=[],qualities:r=[],references:i=0,seed:a=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),qualities:Object.freeze(r),references:i,seed:a}),IW=(e,{aspectRatios:t=[],resolutions:n=[],durations:r,firstFrame:i=!0,lastFrame:a=!1,requiresFirstFrame:o=!1,seed:s=!1,nativeAudio:c=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),durations:Object.freeze(r),firstFrame:i,lastFrame:a,requiresFirstFrame:o,seed:s,nativeAudio:c});Object.freeze({"nano-banana-2":FW(`Nano Banana 2`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":FW(`Nano Banana 2 Lite`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":FW(`Nano Banana Pro`,{aspectRatios:MW,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":FW(`GPT Image 2`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-1.5":FW(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":FW(`Kling Image V3`,{aspectRatios:[`21:9`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],resolutions:[`1K`,`2K`]}),"seedream-v4.5":FW(`Seedream 4.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`2K`,`4K`],seed:!0})}),Object.freeze({"seedance-2.0":IW(`Seedance 2.0`,{aspectRatios:NW,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":IW(`Seedance 2.0 Fast`,{aspectRatios:NW,resolutions:[`480p`,`720p`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":IW(`Seedance 2.0 Mini`,{aspectRatios:NW,resolutions:[`480p`,`720p`],durations:PW,lastFrame:!0,seed:!0,nativeAudio:!0}),"kling-v3-turbo":IW(`Kling 3.0 Turbo`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[5,10]}),"wan-2.6-flash":IW(`Wan 2.6 Flash`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[3,4,5],requiresFirstFrame:!0}),"veo-3.1-lite":IW(`Veo 3.1 Lite`,{aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[4,6,8],lastFrame:!0,nativeAudio:!0}),"vidu-q3-turbo":IW(`Vidu Q3 Turbo`,{durations:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],lastFrame:!0,nativeAudio:!0}),"wan-2.7":IW(`Wan 2.7`,{resolutions:[`720p`,`1080p`],durations:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],lastFrame:!0,requiresFirstFrame:!0,seed:!0})}),Object.freeze([`model`,`aspectRatio`,`resolution`,`quality`]),Object.freeze([`model`,`duration`,`resolution`,`aspectRatio`,`generateAudio`]),Object.freeze({references:8,negativePrompt:2e3,seed:2147483647}),Object.freeze({speech:Object.freeze({text:3800,defaultVoice:`asteria`,speed:Object.freeze({min:.25,max:4,default:1})}),music:Object.freeze({min:5,max:240,default:30}),sfx:Object.freeze({min:.5,max:22,default:4})}),Ct();var LW=Object.freeze({googlesheets:`Google Sheets`,googledrive:`Google Drive`,googledocs:`Google Docs`,googlecalendar:`Google Calendar`,gmail:`Gmail`,youtube:`YouTube`,tiktok:`TikTok`,linkedin:`LinkedIn`,hubspot:`HubSpot`,github:`GitHub`,whatsapp:`WhatsApp`,"meta-ads":`Meta Ads`}),RW=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,zW=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),BW=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),VW=[[`send`,new Set([`send`,`reply`,`message`,`notify`,`email`,`forward`,`dm`,`invite`])],[`add`,new Set([`add`,`append`,`insert`,`create`,`new`,`log`,`save`,`record`,`upsert`,`write`,`import`,`book`,`schedule`])],[`update`,new Set([`update`,`edit`,`change`,`modify`,`patch`,`set`,`rename`,`move`,`replace`,`mark`])],[`remove`,new Set([`delete`,`remove`,`archive`,`trash`,`cancel`,`unsubscribe`])],[`upload`,new Set([`upload`])]],HW={post:[`Post to`,`Posting to`],send:[`Send to`,`Sending to`],add:[`Add to`,`Adding to`],update:[`Update in`,`Updating in`],remove:[`Remove from`,`Removing from`],upload:[`Upload to`,`Uploading to`],read:[`Get from`,`Getting from`]},UW=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),WW=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function GW(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=UW(e);return LW[n]||(n?WW(n):`the app`)}function KW(e){let t=String(e?.manifest?.name||``).split(` · `).slice(1).join(` `),n=String(e?.capability?.capabilityId||``).split(`:`).at(-1),r=UW(e).replace(/[-_.]/g,``).toLowerCase(),i=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,` `).trim().split(` `).filter(Boolean);return t.length>1&&t[0].replace(/[-_.]/g,``)===r&&t.shift(),t};for(let e of[i(t),i(n)]){let t=e.slice(0,3),n=t.find(e=>RW.test(e)||zW.has(e)||VW.some(([,t])=>t.has(e)));if(n&&RW.test(n))return`read`;if(e.some(e=>zW.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>BW.has(e)))return`post`;let r=n&&VW.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function qW(e){let t=GW(e),n=KW(e),[r,i]=HW[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var JW=e=>qW(e).verbs,YW=Object.freeze({"text.generate":[`Write`,`Writing…`],"image.generate":[`Generate image`,`Generating image…`],"video.generate":[`Generate video`,`Generating video…`],"video.render":[`Make video`,`Making video…`],"audio.speech":[`Generate voiceover`,`Generating voiceover…`],"audio.transcribe":[`Transcribe`,`Transcribing…`],"image.describe":[`Describe`,`Describing…`],"audio.music":[`Generate music`,`Generating music…`],"audio.sfx":[`Generate sound`,`Generating sound…`],"web.fetch":[`Read page`,`Reading…`],"web.research":[`Research`,`Researching…`],"media.analyze":[`Analyze`,`Analyzing…`],"photos.pick":[`Pick photos`,`Picking photos…`],"timeline.propose":[`Suggest edit`,`Suggesting…`],"workspace.propose":[`Suggest changes`,`Suggesting…`],"connection.execute":[`Send`,`Sending…`]}),XW=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase(),ZW=new Set([`output`,`outputs`,`result`,`results`,`value`,`data`,`out`]),QW=new Set(`add.analyze.animate.build.check.clean.compose.convert.count.create.cut.describe.design.edit.export.extract.find.generate.get.import.make.merge.mix.narrate.pick.plan.post.publish.read.record.remove.render.research.resize.review.schedule.send.split.summarize.transcribe.translate.trim.write`.split(`.`));function $W(e){let t=e?.manifest;if(!t)return null;let n=String(t.name||``).trim(),r=n.split(/\s+/)[0].toLowerCase();if(QW.has(r)&&n.includes(` `))return[n,`Working…`];let i=Object.entries(t.outputs||{}).filter(([,e])=>!e?.context),[a,o]=i.find(([,e])=>e?.primary)||i[0]||[],s=a&&!ZW.has(XW(a))&&!/action/i.test(String(o?.type||``)),c=o?.label?XW(o.label):XW(s?a:n);return c?[`Make ${c}`,`Making ${c}…`]:null}function eG(e,t){let n=t?.manifest?.action,r=typeof n?.label==`string`?n.label.trim():``;return r?[r,n.running||YW[e]?.[1]||`Working…`]:e===`connection.execute`&&t?JW(t):YW[e]||$W(t)||[`Make the result`,`Making the result…`]}var tG=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function nG(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||eG(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${tG(t.credits)}`:r||t?.credits===0?`${s} · ${tG(0)}`:s}ct();var rG=(e,t)=>Object.freeze({kind:e,mimeType:t}),iG=Object.freeze({png:rG(`image`,`image/png`),jpg:rG(`image`,`image/jpeg`),jpeg:rG(`image`,`image/jpeg`),webp:rG(`image`,`image/webp`),gif:rG(`image`,`image/gif`),mp4:rG(`video`,`video/mp4`),mov:rG(`video`,`video/quicktime`),webm:rG(`video`,`video/webm`),mp3:rG(`audio`,`audio/mpeg`),wav:rG(`audio`,`audio/wav`),m4a:rG(`audio`,`audio/mp4`),aac:rG(`audio`,`audio/aac`),ogg:rG(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(nt).map(([e,t])=>[e,rG(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(iG).filter(([,e])=>e.kind!==`file`))),Object.freeze({"text/csv":[`application/vnd.ms-excel`,`text/x-csv`,`application/csv`],"text/markdown":[`text/x-markdown`,`text/plain`],"application/zip":[`application/x-zip-compressed`],"application/json":[`text/json`]}),Object.freeze([`image`,`video`,`audio`]);var aG=Object.freeze({png:`PNG`,jpg:`JPEG`,webp:`WebP`,gif:`GIF`,mp4:`MP4`,mov:`MOV`,webm:`WebM`,mp3:`MP3`,wav:`WAV`,m4a:`M4A`,aac:`AAC`,ogg:`OGG`,pdf:`PDF`,txt:`TXT`,csv:`CSV`,md:`Markdown`,json:`JSON`,zip:`ZIP`}),oG=e=>Object.entries(iG).filter(([t,n])=>e.includes(n.kind)&&aG[t]).map(([e])=>aG[e]),sG=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],cG=e=>sG([...new Set(oG(e))]),lG=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),uG=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),dG=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),fG=e=>/^[aeiou]/i.test(e)?`an`:`a`;function pG(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=lG[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||uG.has(a)||a===i,s=cG(dG[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${fG(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${fG(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var mG=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],hG=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],gG=new Set([`image`,`video`,`audio`,`file`]),_G={image:`image`,video:`film`,audio:`music`,file:`image`},vG=e=>{let t;try{t=JSON.parse(e)}catch{return String(e)}return Array.isArray(t)?t.map(e=>e?.message===`Unknown manifest field`?`This SDK does not know the Block’s “${e.path}” setting. Update the SDK, then restart the preview.`:`${e?.path?`${e.path}: `:``}${e?.message||`Something is wrong with the Block.`}`).join(` `):String(e)},yG={pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`},bG={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(yG).map(e=>`.${e}`).join(`,`)};async function xG(e,t){if(t===`image`){let t=await createImageBitmap(e),n={width:t.width,height:t.height};return t.close?.(),n}if(t!==`video`&&t!==`audio`)return{};let n=URL.createObjectURL(e),r=document.createElement(t);try{r.preload=`metadata`,r.src=n,await new Promise((e,t)=>{r.onloadedmetadata=e,r.onerror=()=>t(Error(`This file does not play in the browser.`)),setTimeout(e,8e3)});let e=Number.isFinite(r.duration)&&r.duration>0?Math.round(r.duration*1e3)/1e3:void 0;return t===`video`?{...r.videoWidth?{width:r.videoWidth,height:r.videoHeight}:{},...e?{duration:e}:{}}:e?{duration:e}:{}}finally{URL.revokeObjectURL(n)}}async function SG(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?yG[n]||e.type:e.type||`application/octet-stream`,i=await xG(e,t).catch(()=>({})),a=await fetch(`/__dev/files`,{method:`POST`,headers:{"Content-Type":r,"X-File-Name":encodeURIComponent(e.name)},body:e}),o=await a.json().catch(()=>({}));if(!a.ok||!o.url)throw Error(o.error||`The preview could not keep this file.`);return{kind:t,assetId:`picked-${o.url.split(`/`)[4]}`,versionId:`v1`,url:o.url,mimeType:r,bytes:e.size,name:e.name,...i}}function CG({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=rW(e)}){let s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),m=async e=>{if(e){l(!0),d(``);try{a(await SG(e,t.type))}catch(e){d(e.message)}finally{l(!1)}}},h=e=>{let t=e.target.files?.[0];e.target.value=``,m(t)},g=pG(e,t),_=(0,$.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:bG[t.type],onChange:h});return r&&!n?(0,$.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,$.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,$.jsxs)(`div`,{className:`dh-media-drop`,"data-over":f||void 0,onDragOver:e=>{e.preventDefault(),f||p(!0)},onDragLeave:()=>p(!1),onDrop:e=>{e.preventDefault(),p(!1),!i&&!c&&m(e.dataTransfer.files?.[0])},children:[(0,$.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,$.jsx)(`span`,{children:t.description}),(0,$.jsx)(`small`,{children:g.formats}),(0,$.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,$.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,$.jsxs)(`div`,{className:`dh-media`,children:[(0,$.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,$.jsx)(rU,{name:n?_G[t.type]:`plus`,size:16}),(0,$.jsx)(`span`,{children:c?`Adding…`:wG(n)||g.choose})]}),_,u&&(0,$.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):(0,$.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,$.jsx)(rU,{name:_G[t.type],size:16}),(0,$.jsx)(`span`,{children:wG(n)||`Add one in the example`}),(0,$.jsx)(`small`,{children:`Example`})]})]})}var wG=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},TG=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},EG=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function DG(e){return(await fetch(`/__dev/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function OG(e,{signal:t}={}){if(typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`))throw Error(`The local preview shows stand-in media and files mapped in tests/mocks.json.`);let n=await fetch(e.url,{signal:t});if(!n.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let r=await createImageBitmap(await n.blob()),i=Math.min(1,512/Math.max(r.width,r.height)),a=document.createElement(`canvas`);return a.width=Math.max(1,Math.round(r.width*i)),a.height=Math.max(1,Math.round(r.height*i)),a.getContext(`2d`).drawImage(r,0,0,a.width,a.height),r.close?.(),{url:a.toDataURL(`image/png`),width:a.width,height:a.height}}function kG(e,{signal:t}={}){return typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`)?Promise.reject(Error(`The local preview plays stand-in media and files mapped in tests/mocks.json.`)):Gn(e,{signal:t})}function AG({value:e}){let t=wG(e);if(!e.url.startsWith(`/api/media/`))return(0,$.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,$.jsx)(rU,{name:_G[e.kind],size:16}),(0,$.jsx)(`span`,{children:t||`Result`})]});let n=e.width>0&&e.height>0?`${e.width}/${e.height}`:null,r=n?{aspectRatio:n}:void 0;return(0,$.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,$.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,$.jsx)(fW,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,$.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,$.jsx)(`figcaption`,{children:t})]})}var jG=e=>(0,$.jsx)(AG,{value:e}),MG=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function NG({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||rW(e),[c,l]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{l(o)},[o]);let u=`dh-input-${e}`,d=t.description||void 0,f=n?.control===`select`&&Array.isArray(n.options)?n.options:null,p=f?(0,$.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,$.jsxs)(`span`,{className:`dh-slider`,children:[(0,$.jsx)(`input`,{id:u,type:`range`,min:t.min,max:t.max,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(Number(e.target.value)),onPointerUp:()=>i(Number(c)),onKeyUp:()=>i(Number(c)),onBlur:()=>i(Number(c))}),(0,$.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,$.jsx)(`input`,{id:u,type:`checkbox`,checked:!!c,disabled:a,onChange:e=>{l(e.target.checked),i(e.target.checked)}}):[`number`,`integer`].includes(t.type)?(0,$.jsx)(`input`,{id:u,type:`number`,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{if(c===``)return i(void 0);let e=Number(c);Number.isFinite(e)&&i(e)}}):[`text`,`string`].includes(t.type)?(0,$.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,$.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:SW(e,s,typeof o==`string`?o:``)?(0,$.jsx)(jW,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,$.jsx)(kW,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):MG.has(t.type)?(0,$.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,$.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,$.jsx)(rU,{name:_G[e.kind]||`image`,size:16}),(0,$.jsx)(`span`,{children:wG(e)||`${s} ${t+1}`})]},t)),!(Array.isArray(o)?o.length:o)&&(0,$.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,$.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,$.jsxs)(`div`,{className:`dh-row`,children:[(0,$.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function PG({value:e,onCommit:t,disabled:n}){let r=(0,Q.useMemo)(()=>JSON.stringify(e,null,2),[e]),[i,a]=(0,Q.useState)(r),[o,s]=(0,Q.useState)(``);return(0,Q.useEffect)(()=>{a(r),s(``)},[r]),(0,$.jsxs)(`div`,{className:`dh-input`,children:[(0,$.jsx)(`textarea`,{"aria-label":`Input JSON`,spellCheck:!1,rows:8,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:()=>{if(i!==r)try{let e=JSON.parse(i||`{}`);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`The input is one JSON object, keyed by input port.`);s(``),t(e)}catch(e){s(e.message)}}}),o&&(0,$.jsx)(`p`,{role:`alert`,children:o})]})}var FG=(0,Q.memo)(function({entries:e,onClear:t}){let n=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[e]),(0,$.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,$.jsx)(`ol`,{ref:n,children:e.map(e=>(0,$.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,$.jsx)(`time`,{children:e.time}),(0,$.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,$.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,$.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),IG={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},LG={full:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,$.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,$.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,$.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,$.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}),dark:(0,$.jsx)(`path`,{d:`M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z`}),white:(0,$.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,$.jsx)(`path`,{d:`M9 3h6M10 3v6l-5 9a2 2 0 0 0 1.7 3h10.6a2 2 0 0 0 1.7-3l-5-9V3`})},RG=({name:e})=>(0,$.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:LG[e]});function zG(e,t){(0,Q.useLayoutEffect)(()=>{let t=e.current,n=t?.closest(`.dh-main`);if(!t||!n)return;let r=0,i=()=>{r=0;let e=parseFloat(getComputedStyle(n).paddingTop)+parseFloat(getComputedStyle(n).paddingBottom),i=HH({width:t.parentElement.clientWidth,available:n.clientHeight-e,heightAt:e=>{t.style.zoom=e===1?``:String(e),t.style.flex=`none`,t.style.minHeight=`0`;let n=Math.ceil(t.getBoundingClientRect().height);return t.style.flex=``,t.style.minHeight=``,n},mode:`auto`});t.style.zoom=i===1?``:String(i)},a=()=>{r||=requestAnimationFrame(i)};i(),addEventListener(`resize`,a);let o=e=>{[`IMG`,`VIDEO`,`AUDIO`].includes(e.target?.tagName)&&a()};return t.addEventListener(`load`,o,!0),t.addEventListener(`loadedmetadata`,o,!0),()=>{cancelAnimationFrame(r),removeEventListener(`resize`,a),t.removeEventListener(`load`,o,!0),t.removeEventListener(`loadedmetadata`,o,!0),t.style.zoom=``}},t)}function BG({label:e,value:t,options:n,onChange:r}){return(0,$.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,$.jsx)(RG,{name:e})},e))})}var VG=140,HG=260,UG={"text.generate":`Write`,"image.generate":`Generate a picture`,"video.generate":`Generate a video`,"audio.speech":`Speak`,"audio.music":`Make music`,"audio.sfx":`Make a sound effect`,"audio.transcribe":`Transcribe`,"image.describe":`Describe a picture`,"media.analyze":`Look at the media`,"web.fetch":`Read a web page`,"web.research":`Research the web`,"timeline.render":`Render`,"audio.decode":`Decode audio`,"audio.extract":`Take out the audio`,"audio.normalize":`Even out the loudness`,"video.cut":`Cut the video`,"video.concat":`Join videos`,"video.resize":`Resize the video`,"image.thumbnail":`Take a still`,"image.compose":`Join pictures`,"document.text":`Read a document`,"files.read":`Read a file`,"files.write":`Save a file`,"net.fetch":`Call a web service`,"connections.call":`Use a connected app`,"actions.run":`Run an action`,"assets.create":`Add to the project`},WG=e=>UG[e.name]||UG[e.api]||e.name;function GG({on:e,label:t,onChange:n}){return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,$.jsx)(`span`,{className:`dh-switch-track`,children:(0,$.jsx)(`span`,{className:`dh-switch-knob`})}),(0,$.jsx)(`span`,{children:t})]})}function KG({tabs:e,status:t,control:n,children:r}){let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(()=>Number(TG(`stillmade.dev.dock`,``))||HG),c=(0,Q.useRef)(null),l=e=>a(t=>t===e?null:e),u=e=>{i&&(c.current={y:e.clientY,height:o},e.currentTarget.setPointerCapture(e.pointerId))},d=e=>{let t=c.current;t&&s(Math.round(Math.max(VG,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},f=()=>{c.current&&(c.current=null,EG(`stillmade.dev.dock`,String(o)))},p=e.find(e=>e.key===i);return(0,$.jsxs)(`section`,{className:`dh-dock`,"data-open":p?`true`:`false`,style:p?{height:o}:void 0,"aria-label":`Run details`,children:[p&&(0,$.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f}),(0,$.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":i===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>l(e.key),children:[e.label,e.alert&&(0,$.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,$.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,$.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":p?`Fold the panel`:`Open the panel`,title:p?`Fold the panel`:`Open the panel`,"aria-expanded":!!p,onClick:()=>a(t=>t?null:e[0].key),children:(0,$.jsx)(rU,{name:`chevronRight`,size:16})})]}),p&&(0,$.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${p.key}`,"aria-labelledby":`dh-tab-${p.key}`,children:r(p.key)})]})}function qG(){let[e,t]=(0,Q.useState)({revision:0,content:null,problem:null,folder:``}),[n,r]=(0,Q.useState)(0),[i,a]=(0,Q.useState)(()=>TG(`stillmade.dev.theme`,`light`)),[o,s]=(0,Q.useState)(()=>TG(`stillmade.dev.width`,`full`)),[c,l]=(0,Q.useState)(0),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)({}),[w,T]=(0,Q.useState)([]),[E,D]=(0,Q.useState)({}),O=(0,Q.useRef)({}),k=(0,Q.useRef)(0),A=(0,Q.useCallback)((e,t)=>T(n=>[...n.slice(-299),{id:++k.current,kind:e,label:IG[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),j=(0,Q.useCallback)(async()=>{let e=await(await fetch(`/__dev/package`,{cache:`no-store`})).json();return t(e),e},[]);(0,Q.useEffect)(()=>{let e=!0;j().then(t=>{e&&(d(e=>e??(t.content?.tests?.[0]?.input||{})),A(`reload`,`Previewing ${t.folder}`),t.problem&&A(`error`,vG(t.problem)))}).catch(e=>A(`error`,e.message));let t=new EventSource(`/__dev/events`);return t.addEventListener(`package`,async t=>{let n=JSON.parse(t.data);try{if(await j(),!e)return;r(e=>e+1),A(n.problem?`error`:`reload`,n.problem?`Reloaded with a problem: ${vG(n.problem)}`:`Reloaded after a change`)}catch(e){A(`error`,e.message)}}),t.addEventListener(`build`,e=>{let t=JSON.parse(e.data);t.state===`running`?A(`build`,`Building: ${t.command}`):t.state===`done`?A(`build`,`Build finished`):A(`error`,`Build failed${t.output?`\n${t.output}`:``}`)}),()=>{e=!1,t.close()}},[]),(0,Q.useEffect)(()=>{document.documentElement.dataset.mode=i,EG(`stillmade.dev.theme`,i)},[i]),(0,Q.useEffect)(()=>{EG(`stillmade.dev.width`,o)},[o]);let M=e.content,N=M?.manifest,P=M?.tests||[],F=e=>{l(e),d(P[e]?.input||{})},I=(0,Q.useCallback)(async(e,{signal:t}={})=>{A(`run`,`Run started`),h(!0),_(``);try{let n=await DG(e);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])A(`log`,e);for(let e of n.standIns||[])A(`stand-in`,`${e.api} ${e.name} (${e.source===`picked`?`your file`:e.source===`example`?`example file`:/mocks/.test(e.source)?`the Block's tests`:`recorded stand-in`})`);if(y({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw A(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return p(n.outputs),A(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(p(null),_(e?.message||`The run did not finish.`)),e}finally{h(!1)}},[A]),ee=(0,Q.useCallback)(async e=>{let t=ir(O.current,e);O.current=t,D(t)},[]),te=()=>{O.current={},D({}),r(e=>e+1),A(`view`,`Shared state cleared`)},L=(0,Q.useMemo)(()=>({state:E,outputs:{},memory:null,canEdit:!0}),[E]),R=(0,Q.useCallback)(async e=>{p(e),A(`view`,`The view chose its outputs`)},[A]),ne=(0,Q.useCallback)(e=>A(`error`,String(e?.message||e)),[A]),z=(0,Q.useMemo)(()=>{let t={...u||{}};if(b)for(let[n,r]of Object.entries(e.content?.manifest?.inputs||{}))gG.has(r.type)&&(S[n]?t[n]=S[n]:delete t[n]);return t},[u,b,S,e.content]),re=(0,Q.useCallback)(t=>d(n=>{if(!b)return t;let r={...t};for(let[t,i]of Object.entries(e.content?.manifest?.inputs||{}))gG.has(i.type)&&(n&&Object.hasOwn(n,t)?r[t]=n[t]:delete r[t]);return r}),[b,e.content]),ie=hG.find(([e])=>e===o)?.[2],ae=M?.capability?.operation?[M.capability.operation]:(N?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),oe=m?eG(ae.length===1?ae[0]:void 0,M)[1]:nG(ae.length===1?ae[0]:void 0,{credits:0},{connector:M}),B=(0,Q.useRef)(null);zG(B,[M,o,f,g,m]);let se=f?Object.entries(N?.outputs||{}).filter(([e])=>f[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof f[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(f[e])?(0,$.jsx)(`p`,{className:`dh-date`,children:(0,$.jsx)(`time`,{dateTime:f[e],children:CW(f[e])})},e):(0,$.jsx)(uW,{value:f[e],renderMedia:jG},e)):null,ce=m?`Running…`:v?v.failed?`Last run failed`:`Ran in ${v.ms} ms${v.calls.length?` · ${v.calls.length} ${v.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,le=[{key:`activity`,label:`Activity`,alert:w.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${v?.calls.length?` · ${v.calls.length}`:``}`},...M?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,$.jsxs)(`div`,{className:`dh-page`,children:[(0,$.jsxs)(`header`,{className:`dh-bar`,children:[(0,$.jsxs)(`div`,{className:`dh-title`,children:[(0,$.jsx)(`h1`,{children:N?.name||`Block preview`}),N&&(0,$.jsx)(`span`,{className:`dh-meta`,children:N.version})]}),(0,$.jsx)(`span`,{className:`dh-spacer`}),P.length>1&&(0,$.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,$.jsx)(RG,{name:`example`}),(0,$.jsx)(`select`,{"aria-label":`Example`,value:c,onChange:e=>F(Number(e.target.value)),children:P.map((e,t)=>(0,$.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,$.jsx)(BG,{label:`Width`,value:o,options:hG,onChange:s}),(0,$.jsx)(BG,{label:`Appearance`,value:i,options:mG,onChange:a}),(0,$.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>r(e=>e+1),children:(0,$.jsx)(rU,{name:`refresh`,size:16})})]}),e.problem&&(0,$.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:vG(e.problem)}),(0,$.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,$.jsx)(`div`,{className:`dh-frame`,style:ie?{maxWidth:ie}:void 0,children:M?M.view?(0,$.jsx)(JU,{view:M.view,policyContent:M,input:z,sharedView:L,onSharedChange:ee,onRun:I,onUseOutput:R,onPreviewImage:OG,onPreviewMedia:kG,onError:ne,actorId:`dev-preview`,title:`${N.name} preview`,height:560,fitContent:!0},n):(0,$.jsxs)(`div`,{className:`dh-noview`,ref:B,children:[(0,$.jsx)(`div`,{className:`dh-form`,children:Object.entries(N.inputs||{}).map(([e,t])=>gG.has(t.type)?(0,$.jsx)(CG,{name:e,port:t,title:(N.ui||[]).find(t=>t?.port===e)?.label||rW(e),value:z[e],own:b,disabled:m,onPick:t=>C(n=>({...n,[e]:t}))},e):(0,$.jsx)(NG,{name:e,port:t,control:(N.ui||[]).find(t=>t?.port===e),value:z[e],disabled:m,onCommit:t=>d(n=>({...n,[e]:t}))},e))}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:m,onClick:()=>I(z).catch(()=>{}),children:oe}),g&&(0,$.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),se?(0,$.jsxs)(`div`,{className:`dh-results`,children:[(0,$.jsx)(`h2`,{children:`Result`}),se]}):!g&&(0,$.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,$.jsx)(`p`,{children:`The result appears here after a run.`})})]}):(0,$.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,$.jsx)(KG,{tabs:le,status:ce,control:(0,$.jsx)(GG,{on:!b,label:`Example media`,onChange:e=>x(!e)}),children:e=>e===`activity`?(0,$.jsx)(FG,{entries:w,onClear:()=>T([])}):e===`calls`?v?.calls.length?(0,$.jsx)(`ol`,{className:`dh-calls`,children:v.calls.map((e,t)=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`strong`,{children:WG(e)}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`small`,{children:e.source===`picked`?`read from your file`:e.source===`example`?`read from a StillMade example file`:/mocks/.test(e.source)?`answered from the Block's tests`:`answered by a recorded stand-in`})]},t))}):(0,$.jsx)(`p`,{className:`dh-muted`,children:v?`The last run made no hosted or media calls.`:`Run the Block to see the calls it makes and what answered each one.`}):e===`result`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:te,children:`Clear shared state`})]}),g&&(0,$.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),se||!g&&(0,$.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`dh-section-head`,children:[(0,$.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,$.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:m||!M,onClick:()=>I(z).catch(()=>{}),children:oe})]}),u&&(0,$.jsx)(PG,{value:z,onCommit:re,disabled:!M}),f&&(0,$.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(f,null,2)})]})})]})}(0,v.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(qG,{}));