@popmelt.com/core 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +78 -23
  2. package/claude-plugin/.claude-plugin/plugin.json +1 -1
  3. package/claude-plugin/skills/popmelt-core/SKILL.md +1 -0
  4. package/codex-plugin/.codex-plugin/plugin.json +1 -1
  5. package/codex-plugin/skills/popmelt-core/SKILL.md +1 -0
  6. package/dist/ExploreAttachment-IO3CNUWH.mjs +1 -0
  7. package/dist/PagePreviewLayer-KQ2FLIGX.mjs +1 -0
  8. package/dist/ParticipantRuntime-Y2BQVJSL.mjs +1 -0
  9. package/dist/PhoneHostGate-2G4BA5FP.mjs +1 -0
  10. package/dist/PopmeltTasteConnectedPane-H5QWBFD7.mjs +1 -0
  11. package/dist/PreviewRuntime-V2PZF462.mjs +1 -0
  12. package/dist/{QueuedReplies-ESIFFRKS.mjs → QueuedReplies-4APDDNQX.mjs} +1 -1
  13. package/dist/SamplePlacementOverlay-ELSP5AHM.mjs +1 -0
  14. package/dist/ShareProjectPane-OR2LS2A3.mjs +1 -0
  15. package/dist/SuppliedContext-SAQKEDWW.mjs +1 -0
  16. package/dist/ThreadErrorCard-OSHIWSHR.mjs +1 -0
  17. package/dist/ThreadPanel-YPL2HDUC.mjs +1 -0
  18. package/dist/adapter-react-three-fiber.d.mts +6 -2
  19. package/dist/adapter-react-three-fiber.mjs +1 -1
  20. package/dist/adapter-three.d.mts +34 -0
  21. package/dist/adapter-three.mjs +45 -1
  22. package/dist/bridge-entry.mjs +1 -1
  23. package/dist/bridgeSSEStream-6OMAFDFW.mjs +1 -0
  24. package/dist/bridgeWebSocketStream-WIOGOPJW.mjs +1 -0
  25. package/dist/browser-runtime-O3EKN3FI.mjs +1 -0
  26. package/dist/browser.d.mts +4 -4
  27. package/dist/browser.mjs +1 -1
  28. package/dist/canvas-chat-note-O3USBECW.mjs +1 -0
  29. package/dist/checkFixture-SOSI7AT4.mjs +1 -0
  30. package/dist/chunk-3VOEPWRL.mjs +1 -0
  31. package/dist/chunk-4OEHQ6M7.mjs +24 -0
  32. package/dist/chunk-4YQWU5YB.mjs +1 -0
  33. package/dist/chunk-5IZHN3A7.mjs +1 -0
  34. package/dist/chunk-6EO73WJN.mjs +1 -0
  35. package/dist/chunk-6O5QLRSA.mjs +1 -0
  36. package/dist/chunk-76WRZ2NH.mjs +1 -0
  37. package/dist/chunk-A4GARXVQ.mjs +1 -0
  38. package/dist/chunk-AAMUU2QA.mjs +1 -0
  39. package/dist/chunk-AGCS65LT.mjs +1 -0
  40. package/dist/chunk-AGYBVMHX.mjs +1 -0
  41. package/dist/{chunk-RR4SHK7O.mjs → chunk-AOTDTBQO.mjs} +1 -1
  42. package/dist/chunk-ATLUO4G7.mjs +1 -0
  43. package/dist/chunk-AYZUOBFI.mjs +1 -0
  44. package/dist/chunk-B22WBEQC.mjs +1 -0
  45. package/dist/chunk-B2ISA6V6.mjs +1 -0
  46. package/dist/chunk-B4DYUYX4.mjs +1 -0
  47. package/dist/chunk-BVGHHT3Y.mjs +1 -0
  48. package/dist/{chunk-NDGM4DAP.mjs → chunk-BYASSHKJ.mjs} +1 -1
  49. package/dist/chunk-C2ZSNUXQ.mjs +1 -0
  50. package/dist/chunk-CIA6WVXQ.mjs +1 -0
  51. package/dist/chunk-CIKFUS7J.mjs +1 -0
  52. package/dist/chunk-CK3CDA3L.mjs +1 -0
  53. package/dist/{chunk-AH6LZOQC.mjs → chunk-DO46YJCX.mjs} +1 -1
  54. package/dist/chunk-DRPRASD6.mjs +1 -0
  55. package/dist/chunk-EBJ23A7F.mjs +1 -0
  56. package/dist/chunk-ECMLCGAM.mjs +1 -0
  57. package/dist/chunk-EILBHZDX.mjs +1 -0
  58. package/dist/{chunk-DOCRI237.mjs → chunk-ELKVFX2O.mjs} +1 -1
  59. package/dist/{chunk-EXIUW3JX.mjs → chunk-EUFR7R5Q.mjs} +1 -1
  60. package/dist/chunk-EZVFCJEG.mjs +1 -0
  61. package/dist/chunk-FHCKFQBY.mjs +1 -0
  62. package/dist/chunk-FJWWBKCQ.mjs +1 -0
  63. package/dist/chunk-FON4QY7P.mjs +1 -0
  64. package/dist/chunk-GLF7Z5IR.mjs +1 -0
  65. package/dist/chunk-HAZXZ5TU.mjs +1 -0
  66. package/dist/chunk-HKHZBKAN.mjs +1 -0
  67. package/dist/chunk-I6FJ533W.mjs +1 -0
  68. package/dist/chunk-I7AI52RX.mjs +1 -0
  69. package/dist/{chunk-YHYFWNN6.mjs → chunk-IAXSC2ZN.mjs} +1 -1
  70. package/dist/chunk-IGKU4YIV.mjs +1 -0
  71. package/dist/chunk-IW7V7WNL.mjs +1 -0
  72. package/dist/chunk-JCW2WY7X.mjs +1 -0
  73. package/dist/chunk-JEGBAHYK.mjs +1 -0
  74. package/dist/chunk-JLK3VRBT.mjs +1 -0
  75. package/dist/chunk-KCDHP4N3.mjs +1 -0
  76. package/dist/chunk-KF73S7MG.mjs +1 -0
  77. package/dist/chunk-L6S66APQ.mjs +1 -0
  78. package/dist/chunk-LH7HKUCK.mjs +1 -0
  79. package/dist/chunk-LOUWY55X.mjs +1 -0
  80. package/dist/chunk-LXFKOYLK.mjs +1 -0
  81. package/dist/chunk-MDPZUECK.mjs +1 -0
  82. package/dist/chunk-MHWIFSXJ.mjs +1 -0
  83. package/dist/chunk-MPEVFQ43.mjs +1 -0
  84. package/dist/{chunk-57FM7XQV.mjs → chunk-NI77Y3WC.mjs} +1 -1
  85. package/dist/chunk-NXTWB3A7.mjs +1 -0
  86. package/dist/chunk-OA63PYHZ.mjs +1 -0
  87. package/dist/chunk-OFJUTWJU.mjs +1 -0
  88. package/dist/chunk-OREALBUO.mjs +1 -0
  89. package/dist/chunk-OVZ4CQGM.mjs +1 -0
  90. package/dist/chunk-PILMDBAX.mjs +1 -0
  91. package/dist/chunk-PLE6FFKY.mjs +1 -0
  92. package/dist/chunk-PRPXMDZ7.mjs +1 -0
  93. package/dist/chunk-PWQB3FIW.mjs +1 -0
  94. package/dist/chunk-ROKRMYFR.mjs +1 -0
  95. package/dist/chunk-SNAJBV7T.mjs +30 -0
  96. package/dist/chunk-SOGN7S54.mjs +1 -0
  97. package/dist/chunk-SOT33EQ4.mjs +1 -0
  98. package/dist/chunk-SQA27YGA.mjs +1 -0
  99. package/dist/chunk-SUAHDXJZ.mjs +1 -0
  100. package/dist/chunk-TCGXG7UA.mjs +1 -0
  101. package/dist/chunk-TMSGNHXH.mjs +1 -0
  102. package/dist/chunk-TQ3SP5TE.mjs +1 -0
  103. package/dist/chunk-UTP56NCY.mjs +1 -0
  104. package/dist/chunk-W2QQVB2H.mjs +1 -0
  105. package/dist/chunk-WC4ZNVFM.mjs +1 -0
  106. package/dist/chunk-WDSFOF2E.mjs +1 -0
  107. package/dist/chunk-WP2SHSCG.mjs +1 -0
  108. package/dist/chunk-X6I6KQDG.mjs +1 -0
  109. package/dist/chunk-XJJDBMZI.mjs +1 -0
  110. package/dist/chunk-XY7YW7SH.mjs +1 -0
  111. package/dist/chunk-YMWXWXPV.mjs +1 -0
  112. package/dist/chunk-YU3ZY76H.mjs +1 -0
  113. package/dist/chunk-YVT3J6JB.mjs +1 -0
  114. package/dist/chunk-YYFF2X3L.mjs +1 -0
  115. package/dist/cli.mjs +1 -1
  116. package/dist/codex-note-context-UI55CWRI.mjs +1 -0
  117. package/dist/codex-project-LIU27RXA.mjs +1 -0
  118. package/dist/codex-session-registry-YNU6LEVH.mjs +1 -0
  119. package/dist/codex-store-mount-EPETPOBA.mjs +1 -0
  120. package/dist/{dev-server-DtX2_HCa.d.mts → dev-server-BRrhkH5t.d.mts} +11 -1
  121. package/dist/dev-server-WYB2CRC5.mjs +1 -0
  122. package/dist/focus-inspection-42IEM45O.mjs +1 -0
  123. package/dist/guest-admission.d.mts +2 -0
  124. package/dist/guest-admission.mjs +1 -0
  125. package/dist/guest-live-canvas.d.mts +2 -0
  126. package/dist/guest-live-canvas.mjs +1 -0
  127. package/dist/index.d.mts +6 -6
  128. package/dist/index.mjs +1 -1
  129. package/dist/invitationLink-LUIIOAEZ.mjs +1 -0
  130. package/dist/inviteQr-HVHH45SN.mjs +1 -0
  131. package/dist/inviteQr-U77MLSEQ.mjs +1 -0
  132. package/dist/media.d.mts +3 -3
  133. package/dist/memory-store.d.mts +5 -1
  134. package/dist/page-interaction-TV3P6B3X.mjs +1 -0
  135. package/dist/page-planes-2ZepTpen.d.mts +817 -0
  136. package/dist/participantBootstrap-BuTrTQbo.d.mts +22 -0
  137. package/dist/{participantBootstrap-DFJlcKRI.d.mts → participantBootstrap-DuosDN9G.d.mts} +9 -3
  138. package/dist/peer-client-RSC6EGAF.mjs +1 -0
  139. package/dist/plain-html-EF7MUNRZ.mjs +1 -0
  140. package/dist/plugin-astro.d.mts +5 -2
  141. package/dist/plugin-astro.mjs +1 -1
  142. package/dist/plugin-next.mjs +1 -1
  143. package/dist/plugin-nuxt.d.mts +4 -2
  144. package/dist/plugin-nuxt.mjs +1 -1
  145. package/dist/plugin-vite.d.mts +69 -9
  146. package/dist/plugin-vite.mjs +1 -1
  147. package/dist/qr-encoder.mjs +3 -0
  148. package/dist/server.d.mts +42 -19
  149. package/dist/server.mjs +1 -1
  150. package/dist/shared-page-GO76UP7I.mjs +1 -0
  151. package/dist/{subjects-DdavjSTL.d.mts → subjects-BhO1x5tz.d.mts} +80 -1
  152. package/dist/taste-proposal-session-DBOUA54V.mjs +1 -0
  153. package/dist/toolbarFonts-GVPRHJGB.mjs +1 -0
  154. package/dist/{types-g9YCBx4Z.d.mts → types-CggBG-H6.d.mts} +1 -137
  155. package/dist/{video-adapter-DB6Hex1f.d.mts → video-adapter-B8J5awc_.d.mts} +2 -2
  156. package/dist/workspace-snapshot-6LN7U2NJ.mjs +1 -0
  157. package/package.json +45 -22
  158. package/samples/README.md +32 -0
  159. package/samples/build.d.mts +16 -0
  160. package/samples/build.mjs +138 -0
  161. package/dist/ExploreAttachment-H5WPEAZB.mjs +0 -1
  162. package/dist/PagePreviewLayer-WCYOBKAS.mjs +0 -1
  163. package/dist/ParticipantRuntime-HEC26AER.mjs +0 -1
  164. package/dist/PhoneHostGate-Q2AXVOSH.mjs +0 -1
  165. package/dist/PopmeltTasteConnectedPane-B7DHQKRQ.mjs +0 -1
  166. package/dist/PreviewRuntime-H2UOLP6T.mjs +0 -1
  167. package/dist/SuppliedContext-7ASO6GAW.mjs +0 -1
  168. package/dist/ThreadErrorCard-6R7W3RGZ.mjs +0 -1
  169. package/dist/ThreadPanel-3IS7GUYS.mjs +0 -1
  170. package/dist/bridgeSSEStream-K3UIMBTC.mjs +0 -1
  171. package/dist/bridgeWebSocketStream-2SUZUBE3.mjs +0 -1
  172. package/dist/browser-runtime-ILNTJLZ5.mjs +0 -1
  173. package/dist/canvas-chat-note-MGAEUYJO.mjs +0 -1
  174. package/dist/checkFixture-YE2ROOLL.mjs +0 -1
  175. package/dist/chunk-26P7UUHT.mjs +0 -1
  176. package/dist/chunk-2P2NUZW7.mjs +0 -1
  177. package/dist/chunk-3SEXH3AZ.mjs +0 -1
  178. package/dist/chunk-3XJEC6LS.mjs +0 -1
  179. package/dist/chunk-4LHTPRFY.mjs +0 -1
  180. package/dist/chunk-5D2ADU7H.mjs +0 -1
  181. package/dist/chunk-5K7SACPW.mjs +0 -1
  182. package/dist/chunk-67QNAAUC.mjs +0 -1
  183. package/dist/chunk-7CGKO4IU.mjs +0 -30
  184. package/dist/chunk-BACXPVHP.mjs +0 -1
  185. package/dist/chunk-DC47WNPG.mjs +0 -1
  186. package/dist/chunk-DJTGR3RO.mjs +0 -1
  187. package/dist/chunk-DLUNNAZC.mjs +0 -1
  188. package/dist/chunk-EX63NVDN.mjs +0 -1
  189. package/dist/chunk-FLTHWLRC.mjs +0 -1
  190. package/dist/chunk-G6RYESYI.mjs +0 -1
  191. package/dist/chunk-G7JR5Z3P.mjs +0 -1
  192. package/dist/chunk-GBVPRXA3.mjs +0 -1
  193. package/dist/chunk-HAE5LUJX.mjs +0 -1
  194. package/dist/chunk-HU2XWUJC.mjs +0 -1
  195. package/dist/chunk-HV7HRQ2S.mjs +0 -1
  196. package/dist/chunk-J4WDYITA.mjs +0 -1
  197. package/dist/chunk-L7QONR4K.mjs +0 -1
  198. package/dist/chunk-LVEMYZOA.mjs +0 -1
  199. package/dist/chunk-MSWXKP77.mjs +0 -1
  200. package/dist/chunk-NSCO633B.mjs +0 -1
  201. package/dist/chunk-NWE5PYKM.mjs +0 -1
  202. package/dist/chunk-O4HZP3RP.mjs +0 -1
  203. package/dist/chunk-OAHYSDJ4.mjs +0 -1
  204. package/dist/chunk-PNTM77NT.mjs +0 -1
  205. package/dist/chunk-RUTWU5W2.mjs +0 -1
  206. package/dist/chunk-TLREGQQB.mjs +0 -1
  207. package/dist/chunk-TUXBMJQZ.mjs +0 -1
  208. package/dist/chunk-V2I7PSJW.mjs +0 -1
  209. package/dist/chunk-WDAXARLI.mjs +0 -1
  210. package/dist/chunk-WHJEKDNP.mjs +0 -1
  211. package/dist/chunk-X2Q3H6X7.mjs +0 -1
  212. package/dist/chunk-XJQJQ5V5.mjs +0 -1
  213. package/dist/chunk-XT6PHPPG.mjs +0 -1
  214. package/dist/chunk-YD3PDEFX.mjs +0 -1
  215. package/dist/chunk-ZDXQ7WNW.mjs +0 -1
  216. package/dist/codex-note-context-YFURG7VL.mjs +0 -1
  217. package/dist/codex-project-3NSU5OWL.mjs +0 -1
  218. package/dist/codex-session-registry-ONODFWFD.mjs +0 -1
  219. package/dist/focus-inspection-SZJ5KP23.mjs +0 -1
  220. package/dist/peer-client-56EAHIGF.mjs +0 -1
  221. package/dist/taste-proposal-session-XU4N7RUV.mjs +0 -1
  222. package/dist/workspace-snapshot-RTTXNNUX.mjs +0 -1
@@ -0,0 +1 @@
1
+ "use client";var a="\n 0%, 100% { translate: 0 0; }\n 20% { translate: -4px 0; }\n 45% { translate: 4px 0; }\n 70% { translate: -2px 0; }\n 88% { translate: 1px 0; }\n";export{a};
@@ -0,0 +1 @@
1
+ "use client";import{useId as e,useState as t,useLayoutEffect as n}from"react";function i(i,r){let o=e(),[s,a]=t(-1),[c,l]=t(!1),u=r.some(({suffix:e})=>e);n(()=>{let e=i.current;if(!e||!u)return;let t=()=>a(e.matches(":focus")&&e.selectionStart===e.selectionEnd?e.selectionEnd:-1),n=()=>a(-1);return t(),e.addEventListener("selectionchange",t),e.addEventListener("select",t),e.addEventListener("input",t),e.addEventListener("focus",t),e.addEventListener("blur",n),()=>{e.removeEventListener("selectionchange",t),e.removeEventListener("select",t),e.removeEventListener("input",t),e.removeEventListener("focus",t),e.removeEventListener("blur",n)}},[u,i]);let d=c?void 0:r.find(({start:e,token:t,suffix:n})=>n&&e+t.length===s);return{active:d,complete:function(e,t){let n=e.currentTarget;if(!d||"Tab"!==e.key||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.nativeEvent.isComposing||n.selectionStart!==s||n.selectionEnd!==s)return!1;e.preventDefault(),e.stopPropagation();let i=/\s/.test(n.value.charAt(s)),r=d.suffix+(i?"":" ");return n.ownerDocument.execCommand?.("insertText",!1,r)||(n.setRangeText(r,s,s,"end"),t()),i&&n.setSelectionRange(s+r.length+1,s+r.length+1),!0},hintId:o,inputProps:{"aria-autocomplete":d?"inline":void 0,"aria-describedby":d?o:void 0,onCompositionStart:()=>l(!0),onCompositionEnd:()=>l(!1)}}}export{i as a};
@@ -0,0 +1 @@
1
+ "use client";import{b as e}from"./chunk-L6S66APQ.mjs";import{K as t,D as o,H as i,I as n,E as a,L as s,M as r}from"./chunk-FJWWBKCQ.mjs";import{c as d}from"./chunk-I6FJ533W.mjs";import{f as c}from"./chunk-AAMUU2QA.mjs";import{v as l}from"./chunk-LH7HKUCK.mjs";import{a as m}from"./chunk-B4DYUYX4.mjs";var f="__popmelt_code_preview";function p(e,t){let o=new URL(e,t);if(o.origin!==new URL(t).origin||!/^https?:$/.test(o.protocol))throw new Error("Code previews must use the same application origin");return o.hash="",o.searchParams.delete("popmelt"),o.searchParams.set(f,"1"),o.href}function u(e,t){return!!new URL(location.href).searchParams.has(f)&&(parent===window||(window.__POPMELT_CODE_PREVIEW__?.dispose(),window.__POPMELT_CODE_PREVIEW__=h(e,t)),!0)}function h(f,p){let u,h,w=new Set,_=m,M="",E=!1,v=0,P=new Map,b=()=>{for(let[e,t]of P)null===t?e.removeAttribute("data-pm"):e.setAttribute("data-pm",t);P.clear()},g=new d(p?.get()??[]),y=()=>{for(let e of _.annotations)e.target&&g.resolve(e.target)},L=(e=_.domModifications)=>{g.applyCanvasSamples(_.canvasSamples),t(e.filter(e=>!w.has(e.id))),o(_.styleModifications),i(_.textModifications),y();for(let e of _.annotations){let t=e.linkedSelector?.match(/^\[data-pm="([^"]+)"\]$/)?.[1];if(!t)continue;let o=l(e.linkedSelector,e.elements?.[0]);o&&(P.has(o)||P.set(o,o.getAttribute("data-pm")),o.setAttribute("data-pm",t))}},A=new MutationObserver(e=>{e.some(e=>e.addedNodes.length)&&(cancelAnimationFrame(v),v=requestAnimationFrame(()=>{A.disconnect(),L(),I()}))}),I=()=>A.observe(document.body,{childList:!0,subtree:!0}),C=()=>{let e=g;e.whenReady().then(()=>{!E&&g===e&&(y(),document.dispatchEvent(new Event("popmelt-subjects-ready")))})},O=p?.subscribe(()=>{g.destroy(),g=new d(p.get()),g.applyCanvasSamples(_.canvasSamples),y(),C()});C();let S={dispose(){E||(E=!0,u?.(),A.disconnect(),O?.(),g.destroy(),cancelAnimationFrame(v),window.removeEventListener("pagehide",S.dispose),window.__POPMELT_CODE_PREVIEW__===S&&delete window.__POPMELT_CODE_PREVIEW__,n(_.textModifications),a(_.styleModifications,!0),r(_.domModifications),b())},source:f,getSubjects:()=>g,update(t){if(E)throw new Error("Preview runtime closed");if(t.draft.source&&t.draft.source.sourceId!==f.sourceId)throw new Error("This draft belongs to a different source");let o=JSON.stringify([t.planeId,t.draft.revision,t.draft.source?.sourceId,t.draft.source?.revision]);if(M===o)return;let i=structuredClone(t.draft.state??m),r=e=>!e.pathname||c(e.pathname)===c(location.pathname),d={...i,annotations:i.annotations.filter(r),styleModifications:i.styleModifications.filter(r),textModifications:i.textModifications.filter(r),domModifications:i.domModifications.filter(r)};A.disconnect(),n(_.textModifications),a(_.styleModifications,!0);let l=s(_.domModifications,d.domModifications);b(),u?.(),h!==t.planeId&&w.clear(),h=t.planeId,_=d,u=e(d.domModifications.filter(e=>!w.has(e.id)),c(location.pathname),!1,e=>{for(let t of e)w.add(t)}),L(l),I(),M=o}};return I(),window.addEventListener("pagehide",S.dispose,{once:!0}),S}export{p as a,u as b,h as c};
@@ -0,0 +1 @@
1
+ import{a as e,b as r}from"./chunk-WDSFOF2E.mjs";import{c as t,e as o}from"./chunk-NXTWB3A7.mjs";import{d as a,e as n,f as i}from"./chunk-IW7V7WNL.mjs";import{b as s,c as l,e as p,f as c}from"./chunk-SQA27YGA.mjs";import{existsSync as d}from"fs";import{dirname as h,join as g,resolve as f}from"path";import{createHash as m}from"crypto";import{homedir as u}from"os";import{mkdir as w,realpath as v,symlink as y}from"fs/promises";import{basename as b,join as S,relative as E,isAbsolute as P,sep as T}from"path";var j="popmelt-plane-renderer",I=[".env",".env.*","*.{crt,pem}","**/.git","**/.git/**"];function x(e){let r=e?`**/${b(e)}/**`:"**";return[r+"/.popmelt",r+"/.popmelt/**"]}function _(e,r,t){let{publicDir:o,base:a}=e.config;o&&e.middlewares.use(a,async(e,a,n)=>{try{let n=decodeURIComponent(new URL(e.url??"/","http://localhost").pathname),i=await v(S(o,n)),s=E(r,i);if(s.split(T).includes(".popmelt")||t&&(".."===s||s.startsWith(".."+T)||P(s)))return a.statusCode=403,void a.end()}catch(e){let r=e.code;if("ENOENT"!==r&&"ENOTDIR"!==r)return n(e)}n()})}function O(e){return[{tag:"script",injectTo:"head-prepend",children:"window.__POPMELT_PARTICIPANTS__="+JSON.stringify(e).replace(/</g,"\\u003c")}]}function R(r){let s,l,p,c,d=new Map,h=async()=>{let e=[...d.values()];d.clear();let r=[s?.lan,s?.tunnel];s&&(delete s.lan,delete s.tunnel),await Promise.all([...r.map(e=>e?.close()),...e.map(e=>e.catch(()=>{}))])},g=()=>p??=(async()=>{if(l?.cancelBrowserLaunch(),s)try{await h(),await s.planeApps.close()}finally{await s.bridge.close()}})(),f=async()=>{if(await c,!l)throw new Error("Plane session has no bootstrap.");return{...await l.read(),lanInviteOrigin:s?.tunnel?.origin??s?.lan?.origin}};return{room:()=>{if(!s)throw new Error("Start the local Vite session first.");return s},close:g,read:f,async configureServer(b){let R=b.config.server.host||"localhost",A=r.origin??`http://${"::1"===R?"[::1]":R}:${b.config.server.port}`,N=new URL(A);if(!["127.0.0.1","localhost","[::1]"].includes(N.hostname)||"http:"!==N.protocol||N.origin!==A||"/"!==b.config.base)throw new Error("Local plane sessions need a loopback HTTP origin and a root-mounted host app.");if(!b.httpServer)throw new Error("Local plane sessions require a listening Vite dev server.");if(!0===b.config.server.host||"string"==typeof b.config.server.host&&!["127.0.0.1","localhost","::1"].includes(b.config.server.host)||b.config.server.https||b.config.server.port!==Number(N.port||80))throw new Error("Match the session origin to the local Vite host and port.");r.origin&&(b.config.server.strictPort=!0);let k=await v(b.config.root),D=S(k,".popmelt","planes"),L=r.directory??D;await w(L,{recursive:!0,mode:448});let $=E(k,await v(L));if($!==S(".popmelt","planes")&&".."!==$&&!$.startsWith(".."+T)&&!P($))throw new Error("Use .popmelt/planes or a directory outside the served project.");if(!r.prepare){let e=await v(S(k,"node_modules")).catch(e=>{if("ENOENT"!==e.code)throw e});if(e){let r=S(L,"node_modules");try{await y(e,r,"junction")}catch(t){if("EEXIST"!==t.code||await v(r)!==e)throw t}}}let M=new Map,W=await a({projectRoot:k,directory:L,previousDirectory:void 0===r.directory?S(u(),".popmelt-planes",m("sha256").update(k).digest("hex")):void 0,async startApp({directory:e,basePath:t,checkoutRoot:o}){let a,p,c,d=1,h=1,g=0,f=!1,u=(r,t)=>{n(t)&&(h++,M.delete(e))},w=()=>{if(r.prepare||g===h)return;if(a)return a;let t=M.get(e);if(t&&Date.now()<t.until)throw t.error;return a=(async()=>{for(;g!==h;){let r=h,t=await i(e,o,k,e=>{b.watcher.add(e)});if(c&&(t.installed||t.graph!==p)&&(f=!0),f&&c){let e=c.watcher;if(await c.restart(!0),e===c.watcher)throw new Error("Could not restart the plane after its dependency install.");d++,f=!1}p=t.graph,M.delete(e),g=r}})().catch(r=>{throw M.set(e,{until:Date.now()+15e3,error:r}),b.config.logger.error("Plane dependency setup failed: "+(r instanceof Error?r.message:String(r))),r}).finally(()=>{a=void 0}),a};r.prepare?await r.prepare(e):await w();let v=x(o),y={name:j,enforce:"post",config(e){e.server?.fs&&(e.server.fs.allow=[o])},configureServer(r){_(r,o,!0),o!==e&&r.watcher.add(o),r.watcher.on("all",(e,r)=>{d++,u(0,r)})},transformIndexHtml:async()=>O({...await l.read(t),lanInviteOrigin:s?.tunnel?.origin??s?.lan?.origin})},E=await r.createServer({root:e,base:t,mode:b.config.mode,plugins:[y],cacheDir:S(L,"cache",m("sha256").update(e).digest("hex")),server:{fs:{strict:!0,allow:[o],deny:[...I,...v]},host:"127.0.0.1",port:0,strictPort:!1,open:!1,https:void 0,hmr:!1,watch:{ignored:[...v,"**/.git/**"]}}});try{if(E.config.root!==e||E.config.base!==t||E.config.server.https||E.config.server.proxy)throw new Error("Plane Vite servers require their assigned root and base, HTTP and local assets. Use a custom app runner for backend proxies.");await E.listen();let r=E.httpServer?.address();if(!r||"string"==typeof r||"127.0.0.1"!==r.address)throw new Error("Expected an isolated loopback Vite server.");return c=E,b.watcher.on("all",u),h++,{origin:"http://127.0.0.1:"+r.port,version:()=>String(d),ready:w,async close(){b.watcher.off("all",u),await(a?.catch(()=>{})),await E.close()}}}catch(e){throw await E.close(),e}}});try{let a=async o=>{if(!s||p)throw new Error("The session has closed.");let a=s;if(a[o])return a[o].inviteOrigin();let n=d.get(o);return n||(n=(async()=>{let i=r.lan?.build??r.tunnel?.build??(await e(k)).build,s=await t(a.bridge,W,{build:i,address:"lan"===o?r.lan?.address:void 0,quickTunnel:"tunnel"===o});if(d.get(o)!==n)throw await s.close(),new Error("Sharing stopped.");return a[o]=s,s})().finally(()=>{d.get(o)===n&&d.delete(o)}),d.set(o,n)),(await n).inviteOrigin()},{startPopmelt:n}=await(import("./server.mjs")),i=await n({projectRoot:k,port:r.bridgePort,devOrigin:A,experimentalEventTransport:r.experimentalEventTransport,manageLease:!1,participantSessions:{planeApps:W,guestOrigin:a,stopGuestSharing:h}});s={planeApps:W,bridge:i};let m=async e=>{l?.cancelBrowserLaunch(),l=await o({bridge:i,projectRoot:k,origin:e,guestInvites:r.tunnel&&!r.lan?"tunnel":"lan",planeApps:W})};await m(A),r.origin||b.httpServer.once("listening",()=>{let e=b.httpServer?.address();e&&"string"!=typeof e&&e.port!==Number(N.port)&&(N.port=String(e.port),c=m(N.origin),c.catch(e=>b.config.logger.error(String(e))))}),r.lan&&await a("lan"),r.tunnel&&(await f()).tunnelAvailable&&await a("tunnel"),b.middlewares.use("/__popmelt/host",(e,r,t)=>{Promise.resolve(c).then(()=>l.hostEntry(e,r)).catch(t)}),b.middlewares.use((e,r,t)=>{Promise.resolve(c).then(()=>l.planeMiddleware(e,r,t)).catch(t)}),_(b,k,!1),b.watcher.on("all",(e,r)=>{/(^|[\\/])(?:\.popmelt|\.git|node_modules)([\\/]|$)/.test(r)||W.sourceChanged()}),b.httpServer.once("close",()=>{g().catch(e=>b.config.logger.error(String(e)))})}catch(e){throw s?await g():await W.close(),e}}}}function A(e){let r=R(e);return{name:"popmelt-local-participant-planes",apply:(e,r)=>"serve"===r.command&&!e.plugins?.some(e=>e&&"name"in e&&e.name===j),config:()=>({server:{fs:{strict:!0,deny:[...I,...x()]},watch:{ignored:x()}}}),api:{room:r.room},configureServer:r.configureServer,transformIndexHtml:async()=>O(await r.read()),closeBundle:r.close}}var N="@popmelt.com/core/browser";function k(t,o){let a,n=t?.basePath??"/popmelt",i={port:null,projectId:null},m=!1,u="virtual:popmelt/bridge",w=`\0${u}`;return{name:"popmelt",api:{ownsDevBridge:!1!==t?.bridge,room(){if(!a)throw new Error("Independent planes are unavailable for this server.");return a.room()}},config(e,{command:r,isPreview:t}){m="serve"===r&&!t;let o=e?.plugins?.flat(1/0).some(e=>"popmelt-plane-renderer"===e?.name||"popmelt-local-participant-planes"===e?.name);if(m&&!o)return{server:{fs:{strict:!0,deny:[".env",".env.*","*.{crt,pem}","**/.git","**/.git/**","**/.popmelt","**/.popmelt/**"]},watch:{ignored:["**/.popmelt/**"]}}}},async configResolved(e){if(!m||!(await e.createResolver({asSrc:!1,scan:!0})(N).catch(()=>{}))?.replaceAll("\\","/").includes("/node_modules/"))return;let{include:r,exclude:t,noDiscovery:o,disabled:a}=e.optimizeDeps;o||!0===a||"dev"===a||r?.includes(N)||t?.some(e=>e===N||N.startsWith(e.endsWith("/")?e:`${e}/`))||(e.optimizeDeps.include=[...r??[],N])},resolveId(e){if(e===u)return w},load:e=>e!==w?void 0:`${i.bootstrap?`if(typeof window !== 'undefined')window.__POPMELT_PARTICIPANTS__??=${JSON.stringify(i.bootstrap)};`:""}export const bridgeUrl = ${JSON.stringify(null===i.port?null:`http://localhost:${i.port}`)}; export const projectId = ${JSON.stringify(i.projectId)};`,async closeBundle(){await(i.close?.())},async configureServer(c){if(c.config?.plugins?.some(e=>"popmelt-plane-renderer"===e.name||"popmelt-local-participant-planes"===e.name))return;let m=c,u=t?.projectRoot??c.config?.root;if(!1!==t?.bridge&&!process.env.POPMELT_BRIDGE_URL&&!o&&function(e,r){let t=e.config;if(!t||!e.httpServer||!t.root||"/"!==t.base||"custom"===t.appType||t.server.middlewareMode||t.server.https||t.server.proxy||t.server.host&&!["127.0.0.1","localhost","::1"].includes(String(t.server.host))||r?.projectRoot&&f(r.projectRoot)!==t.root||!d(g(t.root,"index.html")))return!1;let o=t.root;for(;!d(g(o,".git"));){let e=h(o);if(o===e)return!1;o=e}return!0}(m,t))try{let r=R({createServer:(await e(m.config.root)).createServer,bridgePort:t?.port,experimentalEventTransport:t?.experimentalEventTransport});await r.configureServer(m),a=r;let o=a.room();i={port:o.bridge.port,projectId:o.bridge.projectId,close:a.close},console.info("[popmelt] Pair and Share: private host link for another browser or a headless session in .popmelt/participant-host-link.json.")}catch(e){m.config.logger.warn("[popmelt] Starting a shared preview because independent planes could not start: "+String(e))}a||(c.config?.publicDir&&c.config.root&&_(m,c.config.root,!1),i=await s(t,c,5173,u&&!o?r(u,m):void 0,o)),await l(i,c),c.middlewares.use(p(n,()=>i))},transformIndexHtml(){if(null===i.port)return;let e=e=>[{tag:"script",attrs:{type:"text/javascript"},children:c(e),injectTo:"head-prepend"}];return a?a.read().then(r=>e({...i,bootstrap:r})):e(i)}}}export{A as a,k as b};
@@ -0,0 +1 @@
1
+ "use client";function t(t){if(0===t.length)return{x:0,y:0,width:0,height:0};let h=t.map(t=>t.x),a=t.map(t=>t.y),i=Math.min(...h),e=Math.max(...h),n=Math.min(...a);return{x:i,y:n,width:e-i,height:Math.max(...a)-n}}export{t as a};
@@ -0,0 +1 @@
1
+ "use client";import{a as e}from"./chunk-FHCKFQBY.mjs";import{a as t}from"./chunk-APP5IYTE.mjs";import{i as r,J as n,p as l,a as o,n as i,z as a,G as s,H as f,D as c,q as u}from"./chunk-5IZHN3A7.mjs";import{a as p,b as d}from"./chunk-WP2SHSCG.mjs";import{v as m,l as h,k as g}from"./chunk-LH7HKUCK.mjs";var y='[role="img"], [role="group"][aria-label], [role="group"][aria-labelledby]';function b(e){let t=e?.closest(y);return t&&"canvas"!==t.localName&&t.querySelector("canvas")?t:null}function w(e,t){let r=t?.querySelector("canvas")?t:b(e);if(!r||r===e)return null;let n=r.querySelectorAll("canvas");if(1!==n.length)return null;let l=n[0].getBoundingClientRect(),o=e.getBoundingClientRect();return l.width<=0||l.height<=0?null:o.left<=l.left+1&&o.top<=l.top+1&&o.right>=l.right-1&&o.bottom>=l.bottom-1?r:null}function S(e){let t=m(e.selector,e.element),r=function(e,t=m(e.selector,e.element)){let r=e.element;if("canvas"!==r?.tagName&&"svg"!==r?.tagName&&!t?.closest("svg,canvas"))return t;let n=b(t);if(n)return n;if(t)return t;let l=r?.selector,o=l?.lastIndexOf(" > ")??-1;if(l&&o>=0)try{let e=b(h(l.slice(0,o)));if(e&&(!r?.reactComponent||p(e)?.name===r.reactComponent))return e}catch{}if(!r?.reactComponent||r.frameContext?.length||l?.includes(" >>> "))return null;let i=g().flatMap(e=>Array.from(e.querySelectorAll(y)).filter(e=>e.querySelector("canvas")&&p(e)?.name===r.reactComponent));return 1===i.length?i[0]:null}(e,t),n=e.element?.reactComponent,l=t&&(n?function(e,t){let r=d(e).findLast(e=>e.name===t)?.fiber;if(!r?.child)return null;let n=[r.child],l=null;for(;n.length;){let e=n.pop();if(4===e.tag)return null;e.sibling&&n.push(e.sibling);let t=e.stateNode;if((1===t?.nodeType||3===t?.nodeType)&&(!l&&1===t.nodeType&&(l=t),!l?.contains(t)))return null;e.child&&n.push(e.child)}return l?.contains(e)?l:null}(t,n):b(t));return{element:t,component:l,legacy:r,legacyScene:t&&w(t,l)}}function E(e,t,r){let n="component"===t?e.component:"element"===t?e.element:r&&e.legacyScene||e.legacy;return n?.isConnected&&n.parentElement&&!n.matches("body,html")&&!n.closest("[data-devtools]")?n:null}var v=["font-family","font-size","font-weight","font-style","font-stretch","font-variation-settings","font-feature-settings","line-height","letter-spacing","white-space","overflow-wrap","word-break","flex-wrap","color"];function x(e){return e.trim().replace(/^(['"])(.*)\1$/,"$2").toLowerCase()}function*N(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT,{acceptNode(e){if(e.nodeType===Node.TEXT_NODE)return e.textContent?.trim()?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;let t=e;return t.matches("script,style,noscript,template,[hidden],[data-devtools],[data-popmelt-root]")?NodeFilter.FILTER_REJECT:t.matches("input,textarea,select")?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),r=new Set;for(let e=t.nextNode();e;e=t.nextNode()){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;!t||r.has(t)||(r.add(t),yield[t,e.nodeType===Node.TEXT_NODE?e.textContent.trim():""])}}function C(e){let t=[],r=new Set;for(let[n,l]of N(e)){let o=getComputedStyle(n),i=n.closest("button,a,label"),a=(i&&e.contains(i)?i:n).localName,{fontFamily:s,fontWeight:f,fontSize:c}=o,u=JSON.stringify([a,s,f,c]);if(s&&!r.has(u)&&(r.add(u),t.push({tag:a,text:l.slice(0,64),family:s,weight:f,size:c}),12===t.length))break}return t}function T(e,t){let r=e.ownerDocument,n=[];function l(e){if(!e||e.disabled)return;let t;try{t=e.cssRules}catch{return}o(t,e.href??r.baseURI)}function o(e,r){for(let i of e)if(i.type===CSSRule.FONT_FACE_RULE){let{style:e}=i;if(!t.has(x(e.getPropertyValue("font-family"))))continue;let l=i.cssText.replace(/url\("([^"]*)"\)|url\('([^']*)'\)|url\(([^)]*)\)/gi,(e,t,n,l)=>{try{return"url("+JSON.stringify(new URL(t??n??l.trim(),r).href)+")"}catch{return e}});n.push(l)}else i.type===CSSRule.IMPORT_RULE?l(i.styleSheet):"cssRules"in i&&o(i.cssRules,r)}let i=[r];for(let t=e.getRootNode();"host"in t;t=t.host.getRootNode())i.push(t);for(let e of i)for(let t of[...e.styleSheets,...e.adoptedStyleSheets??[]])l(t);return n}async function I(e,t){let r=function(e,t){let r=new Set([t]);for(let[t]of N(e))t!==e&&r.add(getComputedStyle(t).fontFamily);let n=new Set;for(let e of r)for(let t of e.matchAll(/\s*("[^"]*"|'[^']*'|[^,]+)\s*(?:,|$)/g))n.add(x(t[1]));return n}(e,getComputedStyle(e).fontFamily),n=T(e,r).join("\n"),l=new Set(Array.from(n.matchAll(/url\("([^"]+)"\)/g),e=>e[1])),o=n;return await Promise.all([...l].map(async e=>{if(!e.startsWith("data:"))try{let r=await fetch(e,{signal:t,credentials:"same-origin"});if(!r.ok)return;let n=await r.blob(),l=await new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=t,r.readAsDataURL(n)});o=o.replaceAll(JSON.stringify(e),JSON.stringify(l))}catch{}})),o}var k=/^(?:@[a-zA-Z][\w-]{0,63}|~?(?:0|[1-9]\d{0,3})(?:\.(?:0|[1-9]\d{0,3})){0,31}|)$/;function R(e,t){let r="text"===t?e.replace(/\/text\/(?:0|[1-9]\d{0,3})$/,""):e;return k.test(r)}function A(e){if(e.matches('svg, img, [role="img"]'))return!0;if(e.childElementCount||"http://www.w3.org/1999/xhtml"!==e.namespaceURI)return!1;let t=e.ownerDocument.defaultView?.getComputedStyle(e).maskImage;return!!t&&"none"!==t}function O(e){let t=e.getAttribute("data-popmelt-subject-label")||e.getAttribute("data-explore-part");if(t)return t.slice(0,80);let r=e.closest('button, a[href], [role="button"], [role="link"]');if(r===e)return e.matches('a[href], [role="link"]')?"link":"button";let n=e.getAttribute("aria-label");if(A(e)){let t=n||e.getAttribute("alt")||e.querySelector(":scope > title")?.textContent;if(t)return t.slice(0,80);if(r){let t=Array.from(r.querySelectorAll("*")).filter(A);if(t.length>1)return"icon "+(t.indexOf(e)+1)}return"icon"}let l=Array.from(e.childNodes).filter(e=>e.nodeType===Node.TEXT_NODE).map(e=>e.textContent).join(" ").trim();return r&&l?"label":(n||l||e.localName).slice(0,80)}function j(e,t){let r=new Map;for(let n of[...e,...t]){let e=n.part+":"+n.property,t=r.get(e)?.from??n.from;t===n.to?r.delete(e):(r.delete(e),r.set(e,{...n,from:t}))}return[...r.values()]}function F(e){let t=Object.create(null);for(let{batchId:r,option:n,part:l,property:o,to:i}of e){let e=t[r]??(t[r]=Object.create(null)),a=e[n]??(e[n]=Object.create(null));(a[l]??(a[l]=Object.create(null)))[o]=i}return t}function _(e){if(!e||"object"!=typeof e)throw new Error("Invalid Steer edit.");let{batchId:n,option:l,part:o,property:a,from:s,to:f,sticker:c}=e;if("string"!=typeof n||"number"!=typeof l||!Number.isInteger(l)||"string"!=typeof o||"string"!=typeof a||"string"!=typeof s||"string"!=typeof f||("text"===a||"paragraphs"===a)&&void 0!==c)throw new Error("Invalid Steer edit.");"paragraphs"===a?(t(s),t(f)):"text"!==a&&$({[a]:f});let p={batchId:n,option:l,part:o,property:a,from:s,to:f};if(void 0===c)return p;let{family:d,subproperty:m,step:h,axisSteps:g}=c;if(!r.includes(d)||u(d,m)!==m||!i(d,m).includes(h))throw new Error("Invalid Steer dimension.");let y={family:d,subproperty:m,step:h};if(void 0===g)return{...p,sticker:y};let b=i("transform","translate");if("transform"!==d||"translate"!==m||!b.includes(g.x)||!b.includes(g.y))throw new Error("Invalid Steer translation.");return{...p,sticker:{...y,axisSteps:{x:g.x,y:g.y}}}}var L=new Map;function P(e,t){L.has(e)||L.set(e,new Set),L.get(e).add(t)}for(let e of r){let t=n(e);t&&P("display",t);for(let t of l(e))for(let r of"color"===t?o:[t]){let t=i(e,r);for(let n of t){let l=a(e,r);P(l,s(e,n,r));for(let t of f(e,r,n))P(t.property,t.value);if("border"===e&&l.endsWith("width")&&P(c(r),"solid"),"translate"===l)for(let e of t)P(l,4*Number(n)+"px "+4*Number(e)+"px")}}}function U(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Invalid Steer draft.");return Object.entries(e)}function $(e){return Object.fromEntries(U(e).map(([e,t])=>{if("string"!=typeof t||!L.get(e)?.has(t))throw new Error("Unsupported Steer declaration: "+e);return[e,t]}))}function q(e,r){if(void 0===r)return e;let n=structuredClone(e);for(let[e,l]of U(r)){let r=n.messages.find(t=>t.batch?.id===e)?.batch;if(!r)throw new Error("Steer draft refers to an unknown batch.");for(let[e,n]of U(l)){let l=/^[0-5]$/.test(e)&&r.options[Number(e)];if(!l)throw new Error("Steer draft refers to an unknown option.");for(let[e,r]of U(n)){if("fixture"in l){if(!U(r).every(([t])=>R(e,t)))throw new Error("Invalid fixture part.");let{text:n,paragraphs:l,...o}=Object.fromEntries(U(r));if(void 0!==n&&"string"!=typeof n)throw new Error("Invalid fixture text.");if(void 0!==l){if("string"!=typeof l)throw Error("Invalid paragraph draft.");t(l)}$(o);continue}if(!/^(?:[0-7](?:\.[0-7]){0,3})?(?:\/label)?$/.test(e))throw new Error("Invalid specimen path.");let[n,o]=e.split("/"),i=l.root;for(let e of n?n.split("."):[])i=i?.children?.[Number(e)];if(!i||o&&(!i.label||"text"===i.kind))throw new Error("Steered element no longer exists.");let{text:a,...s}=Object.fromEntries(U(r));if(void 0!==a){if("string"!=typeof a||!o&&"text"!==i.kind)throw new Error("Invalid specimen text.");i.label=a}if(Object.keys(s).length){let e=o?"labelStyle":"style";i[e]={...i[e],...$(s)}}}}}return n}function D(e){return[...e.original?.runnable?[e.original.runnable]:[],...e.options]}function H(e,t){if(!e||e.target)return;let r=e.elements?.find(t=>t.selector===e.linkedSelector)??e.elements?.[0],n=e.linkedSelector??r?.selector;return n?{selector:n,element:r,pathname:e.pathname??t}:void 0}var W=new RegExp(`^${e.explore}(?=\\s|$)`,"i");function z(e){let t=W.exec(e.trimStart());return!!t&&!!e.trimStart().slice(t[0].length).trim()}function J(e,t){let r=e.label?.trim().replace(/\s*[→↓]$/,"").slice(0,52),n=r?r[0].toUpperCase()+r.slice(1)+" "+e.kind:e.kind[0].toUpperCase()+e.kind.slice(1),l=e.name||n;return"label"===t?l+" label":l}export{b as a,S as b,E as c,v as d,C as e,I as f,k as g,R as h,O as i,j,F as k,_ as l,q as m,D as n,H as o,z as p,J as q};
@@ -0,0 +1 @@
1
+ "use client";import{a as e}from"./chunk-XTOCFTVW.mjs";function t(){return{schemaVersion:1,name:"",constraints:[{id:"basis",name:"basis",kind:"layout",value:"16",parentId:null,derivative:1,scale:.75},{id:"padding",name:"padding",kind:"layout",value:"",parentId:"basis",derivative:2,scale:1},{id:"gap",name:"gap",kind:"layout",value:"16",parentId:null,derivative:1,scale:.75},{id:"radii",name:"radii",kind:"layout",value:"",parentId:null,derivative:1,scale:.75},...r(),{id:"primary",name:"primary",kind:"color",value:"oklch(65% 0.16 265)",parentId:null,derivative:0,scale:.125},{id:"secondary",name:"secondary",kind:"color",value:"",parentId:"primary",derivative:30,scale:.125},{id:"tertiary",name:"tertiary",kind:"color",value:"",parentId:"primary",derivative:60,scale:.125}],tokens:[{id:"semantic-color",name:"semantic_color",value:"@primary: 1"},{id:"ad-hoc-spacer",name:"ad-hoc-spacer",value:"@basis: 2"},{id:"ad-hoc-color",name:"ad-hoc-color",value:"#123ccc"},{id:"shadow-lg",name:"shadow-lg",value:"0 10px 15px rgba(0, 0, 0, 0.5)"}]}}function r(){return["body","heading"].flatMap(e=>[{id:`${e}-family`,name:`${e}-family`,kind:"font",group:"typography",typographyRole:e,value:"body"===e?"system-ui, sans-serif":"",parentId:"heading"===e?"body-family":null,derivative:1,scale:1},...["size","height","weight"].map(t=>({id:`${e}-${t}`,name:`${e}-${t}`,kind:"layout",group:"typography",typographyRole:e,value:"weight"===t&&"body"===e?"400":"",parentId:"size"===t?"body"===e?"basis":"body-size":"height"===t?`${e}-size`:"body"===e?null:"body-weight",derivative:"height"===t?1.5:"size"===t?2:1,scale:"weight"===t?100:.125,..."weight"===t?{scaleMode:"increment"}:{}}))])}function n(e){let t={text:"body-size",height:"body-height",weight:"body-weight"},n=e.constraints.filter(e=>t[e.id]);if(!n.length)return e;let i=[...e.constraints];for(let e of r()){if(i.some(t=>t.id===e.id))continue;let r=n.find(r=>t[r.id]===e.id);i.push(r?{...r,id:e.id,name:e.name,group:e.group,typographyRole:e.typographyRole}:e)}let o=i.filter(e=>!t[e.id]).map(e=>({...e})),a=e=>{let r=new Set([e.id]);for(;e.parentId&&t[e.parentId];){let t=i.find(t=>t.id===e.parentId);if(!t||r.has(e.parentId)){e.parentId=null,e.value="";break}if(r.add(e.parentId),e.derivative*=t.derivative,e.parentId=t.parentId,!t.parentId){try{e.value=f(p(i,e.id))}catch{e.value=t.value}e.derivative=1}}};o.filter(e=>"body"===e.typographyRole).forEach(a);for(let e of o){if(!e.parentId||!t[e.parentId])continue;let r=t[e.parentId];try{let t=p(i,e.parentId),n=p(o,r);if("layout"!==t.kind||"layout"!==n.kind||t.unit!==n.unit||!n.value||c(o,e.id,r))throw Error("Keep the original root");e.derivative*=t.value/n.value,e.parentId=r}catch{a(e)}}let s=new Map(n.map(e=>[e.name.toLowerCase(),t[e.id]]));return n.some(e=>"text"===e.id)&&(s.set("text","body-size"),s.set("size","body-size")),{...e,constraints:o,tokens:e.tokens.map(e=>({...e,value:e.value.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|url\([^)]*\)|@([\w-]+)(?::\s*[+-]?(?:\d+\.?\d*|\.\d+))?/gi,(e,t)=>{if(!t)return e;let r=s.get(t.toLowerCase());if(!r)return e;let n=e.replace(`@${t}`,`@${r}`),a=g(i,e),l=g(o,n);return!a||l&&f(a)===f(l)?n:f(a)})}))}}var i="[+-]?(?:\\d+\\.?\\d*|\\.\\d+)",o=new RegExp(`^(${i})(px|rem|em|%|vw|vh|vmin|vmax|ch)?$`,"i"),a=new RegExp(`^oklch\\(\\s*(${i})(%)?\\s+(${i})\\s+(${i})(?:deg)?\\s*\\)$`,"i"),s=e=>(e%360+360)%360,l=e=>Math.max(0,Math.min(1,e)),d=e=>Number(e.toFixed(4));function u(e,t){if("font"===e){let r=t.trim();if(!r||!/[a-z\u0080-\uffff]/i.test(r)||r.length>160||/[;{}()@]|[<>]/.test(r)||[...r].some(e=>e.charCodeAt(0)<32))throw Error("Use a font family or comma-separated font stack");return{kind:e,value:r}}if("layout"===e){let r=t.trim().match(o);if(!r||!Number.isFinite(Number(r[1]))||Number(r[1])<0)throw Error("Use a positive length, like 24px or 1.5rem");return{kind:e,value:Number(r[1]),unit:r[2]?.toLowerCase()??""}}let r=t.trim().match(a);if(!r)throw Error("Use OKLCH, like oklch(65% 0.16 265)");let n=Number(r[1])/(r[2]?100:1),i=Number(r[3]),l=Number(r[4]);if(![n,i,l].every(Number.isFinite)||n<0||n>1||i<0)throw Error("Lightness must be 0–100% and chroma cannot be negative");return{kind:e,l:n,c:i,h:s(l)}}function c(e,t,r){let n=e.find(e=>e.id===t),i=e.find(e=>e.id===r);if(!n||!i)return"Choose an existing constraint";if(n.kind!==i.kind)return"Connect constraints of the same type";if("increment"===n.scaleMode!=("increment"===i.scaleMode))return"Connect weights to weights, and lengths to lengths";let o=new Set([t]);for(;i;){if(o.has(i.id))return"That connection would create a cycle";if(o.add(i.id),!i.parentId)break;if(i=e.find(e=>e.id===i.parentId),!i)return"The parent reference is missing"}return null}function p(e,t,r=0){let n=new Set,i=t=>{if(n.has(t))throw Error("Circular reference");n.add(t);let r=e.find(e=>e.id===t);if(!r)throw Error("The parent reference is missing");if(!Number.isFinite(r.derivative))throw Error("Use a finite derivative");if(!r.parentId)return u(r.kind,r.value);let o=e.find(e=>e.id===r.parentId);if(o&&"increment"===r.scaleMode!=("increment"===o.scaleMode))throw Error("Connect weights to weights, and lengths to lengths");let a=i(r.parentId);if(a.kind!==r.kind)throw Error("Connect constraints of the same type");if("font"===a.kind)return a;if("layout"===a.kind){if(r.derivative<0)throw Error("The derivative cannot be negative");return{...a,value:a.value*r.derivative}}return{...a,h:s(a.h+r.derivative)}},o=i(t),a=e.find(e=>e.id===t);if("font"===o.kind){if(0!==r)throw Error("Font families do not have numeric steps");return o}if(!Number.isFinite(r)||!Number.isFinite(a.scale))throw Error("Use a finite step");if("layout"===o.kind){if("increment"===a.scaleMode?a.scale<=0:a.scale<0)throw Error("Use a nonnegative growth rate or a positive weight increment");let e="increment"===a.scaleMode?Math.max(0,o.value+a.scale*r):o.value*(1+a.scale)**r;if(!Number.isFinite(e))throw Error("The scaled value is too large");return{...o,value:0===r?e:Math.round(e)}}return{...o,l:l(o.l+a.scale*r)}}function f(e){return"font"===e.kind?e.value:"layout"===e.kind?`${d(e.value)}${e.unit}`:`oklch(${d(100*e.l)}% ${d(e.c)} ${d(e.h)}${void 0===e.alpha?"":` / ${d(e.alpha)}`})`}function m(e){let t=e.trim().match(new RegExp(`^@([^:@/(),]+?)(?::\\s*(${i}))?(?:\\s*/\\s*(${i}%?))?$`));return!t||!t[1].trim()||void 0===t[2]&&/\s/.test(t[1].trim())||void 0!==t[2]&&!Number.isFinite(Number(t[2]))||void 0!==t[3]&&null===h(t[3])?null:{name:t[1].trim(),step:void 0===t[2]?null:Number(t[2]),...void 0===t[3]?{}:{opacity:t[3]}}}function h(e){if(!new RegExp(`^${i}%?$`).test(e))return null;let t=parseFloat(e)/(e.endsWith("%")?100:1);return Number.isFinite(t)&&t>=0&&t<=1?t:null}function g(e,t){let r=m(t);if(!r)return null;let n=e.find(e=>e.name.toLowerCase()===r.name.toLowerCase());if(!n)return null;try{let t=p(e,n.id,r.step??0);return void 0===r.opacity?t:"color"===t.kind?{...t,alpha:h(r.opacity)}:null}catch{return null}}function v(e,t,r){let n=e.find(e=>e.id===t);if("layout"!==n?.kind)return n?.derivative??0;try{let n=p(e,t),i=p(e,r);if("layout"===n.kind&&"layout"===i.kind&&n.unit===i.unit&&0!==i.value){let e=n.value/i.value;if(Number.isFinite(e))return e}}catch{}return 1}function y(e,t){let r=f(p(e,t));return e.map(e=>e.id===t?{...e,parentId:null,value:r}:e)}function k(e,t){let r=new Set;for(let n=0;n<32;n+=1){if(r.has(e))return;if(r.add(e),e&&"object"==typeof e){let t=e;e=t.$value??t.ref;continue}if("string"!=typeof e)return;let n=e.trim(),i=n.replace(/^\{(.+)\}$/,"$1").replace(/^var\(--([^,)]+)\)$/,"$1").replace(/^var\(principles\.([^,)]+)\)$/,"$1").replace(/^principles\./,"");if(!Object.hasOwn(t,i)){if(/\b(currentcolor|inherit|initial|unset|revert|var|env|light-dark)\b/i.test(n))return;if(typeof CSS<"u"&&CSS.supports)return CSS.supports("color",n)?n:void 0;if(typeof document<"u"){let e=document.createElement("span").style;return e.color=n,e.color?n:void 0}return}e=t[i]}}var b=/^@([\w-]+)(?::\s*[+-]?(?:\d+\.?\d*|\.\d+)(?![\w.]))?(?![\w-]|\s*:)/,w=/^(?:px|rem|em|ex|ch|cap|ic|lh|rlh|vw|vh|vi|vb|vmin|vmax|[sld]v[whib]|cm|mm|q|in|pt|pc|%)$/i,I=e=>String(Number(e.toPrecision(12)));function $(e,t){if(e.length>4096||!/^calc\(/i.test(e))return null;let r=5,n=0,i=()=>{throw Error("Invalid calc expression")},o=()=>{for(;/\s/.test(e[r]??"")&&r<e.length;)r++},a=(e,t="")=>!Number.isFinite(e)||t&&!w.test(t)?i():{kind:t?"length":"number",terms:new Map([[t.toLowerCase(),e]])},s=(e,t)=>({...e,terms:new Map([...e.terms].map(([e,r])=>{let n=r*t;return Number.isFinite(n)||i(),[e,n]}))}),l=()=>{o(),++n>32&&i();try{let n=e[r];if("+"===n||"-"===n)return r++,s(l(),"-"===n?-1:1);if("("===e[r]||/^calc\(/i.test(e.slice(r))){r+="("===e[r]?1:5;let t=u();return o(),")"!==e[r++]&&i(),t}let d=e.slice(r).match(b)?.[0];if(d){r+=d.length;let e=g(t,d);if("layout"!==e?.kind)return i();let n=t.find(e=>e.name.toLowerCase()===d.slice(1).split(":")[0].trim().toLowerCase());return a(e.value,e.unit||("increment"===n?.scaleMode?"":"px"))}let c=e.slice(r).match(/^(\d+\.?\d*|\.\d+)(e[+-]?\d+)?([a-z]+|%)?/i);return c?(r+=c[0].length,a(Number(c[1]+(c[2]??"")),c[3])):i()}finally{n--}},d=()=>{let t=l();for(;;){o();let n=e[r];if("*"!==n&&"/"!==n)return t;r++;let a=l();if("/"===n){let e=a.terms.get("");if("number"!==a.kind||!e)return i();t=s(t,1/e)}else if("number"===a.kind)t=s(t,a.terms.get(""));else{if("number"!==t.kind)return i();t=s(a,t.terms.get(""))}}},u=()=>{let t=d();for(;;){o();let n=e[r];if("+"!==n&&"-"!==n)return t;r++;let a=d();if(t.kind!==a.kind)return i();for(let[e,r]of a.terms){let o=(t.terms.get(e)??0)+r*("-"===n?-1:1);Number.isFinite(o)||i(),t.terms.set(e,o)}}};try{let t=u();if(o(),")"!==e[r++]||e.slice(r).trim())return null;let n=[...t.terms].filter(([,e])=>0!==e);n.length||n.push([t.terms.keys().next().value??"",0]);let[i,a]=n[0];return{css:1===n.length?`${I(a)}${i}`:`calc(${n.map(([e,t],r)=>`${r?t<0?" - ":" + ":t<0?"-":""}${I(Math.abs(t))}${e}`).join("")})`,kind:t.kind,...1===n.length?{value:a,unit:i}:{}}}catch{return null}}function x(e,t){let r=e;for(let n of function(e){let t=[],r=/url\((?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^)'"])*\)|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\*[\s\S]*?\*\/|\bcalc\(/gi;for(let n;n=r.exec(e);){if(!/^calc\(/i.test(n[0]))continue;let i=1,o=r.lastIndex;for(;o<e.length&&i;)"("===e[o]?i++:")"===e[o]&&i--,o++;t.push({start:n.index,end:o,text:e.slice(n.index,o)}),r.lastIndex=o}return t}(e).reverse()){let e=$(n.text,t);if(!e)return null;r=r.slice(0,n.start)+e.css+r.slice(n.end)}return r}function E(e,t){let r=[],n=(e,t,n)=>{let i=k(e,{});i&&r.push({start:t,end:n,color:i})},i=(e,o=0,a=!1)=>{let s=0;for(;s<e.length;){let l=e[s];if('"'===l||"'"===l){let t=l;for(s++;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t){s++;break}continue}if(e.startsWith("/*",s)){let t=e.indexOf("*/",s+2);s=t<0?e.length:t+2;continue}if("@"===l){let n=e.slice(s).match(/^@([^:@(),/]+):\s*([+-]?(?:\d+\.?\d*|\.\d+))(?![\w.])(?:\s*\/\s*[+-]?(?:\d+\.?\d*|\.\d+)%?(?![\w.%]))?(?!\s*\/)/),i=e.slice(s).match(/^@([\w-]+)(?![\w-]|\s*:)(?:\s*\/\s*([+-]?(?:\d+\.?\d*|\.\d+)%?)(?![\w.%]))?(?!\s*\/)/),l=a?e.slice(s).match(b):n??i;if(l){let e=g(t,l[0]),n=m(l[0]);n&&r.push({start:o+s,end:o+s+l[0].length,color:"color"===e?.kind?f(e):null,reference:n,...a?{math:!0}:{}}),s+=l[0].length}else s+=e.slice(s).match(/^@[^\s,()]*(?:\s*:\s*[^\s,()]*)?/)?.[0].length??1;continue}let d=e.slice(s).match(/^(?:#[\w-]+|[\w-]+)/)?.[0];if(!d){s++;continue}let u=s;if(s+=d.length,"("!==e[s]){a||n(d,o+u,o+s);continue}let c=++s,p=1,h="";for(;s<e.length&&p;){let t=e[s++];"\\"!==t?h?t===h&&(h=""):'"'===t||"'"===t?h=t:"("===t?p++:")"===t&&p--:s++}if(p)continue;let v=k(e.slice(u,s),{});v?r.push({start:o+u,end:o+s,color:v}):/^(?:(?:repeating-)?(?:linear|radial|conic)-gradient|drop-shadow|calc)$/i.test(d)&&i(e.slice(c,s-1),o+c,a||"calc"===d.toLowerCase())}};return i(e),r}function C(e,t){return E(e,t).flatMap(e=>e.color?[{...e,color:e.color}]:[])}function S(e,t){return E(e,t).flatMap(({reference:e,start:t,end:r,math:n})=>e?[{...e,start:t,end:r,...n?{math:!0}:{}}]:[])}function N(e,t){return C(e,t).map(({color:e})=>e)}function A(e,t){let r=S(e,t);return null!==x(e,t)&&r.length===(e.match(/@/g)?.length??0)&&r.every(({start:r,end:n})=>null!==g(t,e.slice(r,n)))}function R(e,t,r=!1){let n=x(e,t);if(null===n)return null;let i=n;for(let e of S(n,t).reverse()){let o=g(t,n.slice(e.start,e.end));if(!o)return null;i=i.slice(0,e.start)+f(o)+(r&&"layout"===o.kind&&!o.unit?"px":"")+i.slice(e.end)}return i}function j(e,t,r,n){if(void 0!==n){let i=S(e,r)[n];return!i||void 0!==i.opacity&&"color"!==t.kind||i.math&&"layout"!==t.kind?null:e.slice(0,i.start)+`@${t.name}${null===i.step?"":`: ${i.step}`}${void 0===i.opacity?"":` / ${i.opacity}`}`+e.slice(i.end)}let i=m(e);if(i||!e.trim())return void 0!==i?.opacity&&"color"!==t.kind?null:`@${t.name}${null===i?.step?"":`: ${i?.step??0}`}${void 0===i?.opacity?"":` / ${i.opacity}`}`;let o=C(e,r);if("color"===t.kind&&1===o.length){let{start:r,end:n}=o[0],i=m(e.slice(r,n));return`${e.slice(0,r)}@${t.name}${null===i?.step?"":`: ${i?.step??0}`}${void 0===i?.opacity?"":` / ${i.opacity}`}${e.slice(n)}`}return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[a-z%]+)?$/i.test(e.trim())?`@${t.name}: 0`:null}var T=["page","body","heading","muted","card","button","input"],F=["color","backgroundColor","border","borderColor","borderWidth","borderRadius","boxShadow","padding","paddingInline","paddingBlock","gap","fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","opacity"];function L(e){var t;let r={};for(let n of e.usage??[]){if(!T.includes(n.target)||!F.includes(n.property))continue;let i=null;try{if("token"===n.source.kind){let t=e.tokens.find(e=>e.id===n.source.id);t&&(i=R(t.value,e.constraints,!["fontWeight","opacity"].includes(n.property)))}else if("dimension"===n.source.kind){let t=p(e.constraints,n.source.id,n.source.step??0);i=f(t),"layout"===t.kind&&!t.unit&&!["fontWeight","opacity"].includes(n.property)&&(i+="px")}}catch{continue}(i&&/^-?\d+(?:\.\d+)?$/.test(i)&&["fontSize","letterSpacing","padding","paddingInline","paddingBlock","gap","borderRadius","borderWidth"].includes(n.property)&&(i+="px"),!i||/[;{}]|\b(?:url|expression|var)\s*\(/i.test(i)||i.includes("\\")||[...i].some(e=>e.charCodeAt(0)<32)||typeof CSS<"u"&&CSS.supports&&!CSS.supports(n.property.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),i))||((r[t=n.target]??(r[t]={}))[n.property]=["fontWeight","opacity"].includes(n.property)&&Number.isFinite(Number(i))?Number(i):i)}return r}var U=["display","boxSizing","width","height","flexDirection","flexWrap","alignItems","justifyContent","alignSelf","flexGrow","flexShrink","gridTemplateColumns","rowGap","columnGap","gap","padding","paddingInline","paddingBlock","border","borderRadius","paddingTop","paddingRight","paddingBottom","paddingLeft","marginTop","marginRight","marginBottom","marginLeft","borderTop","borderRight","borderBottom","borderLeft","borderColor","borderWidth","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","color","backgroundColor","backgroundImage","boxShadow","opacity","fontFamily","fontSize","fontWeight","fontStyle","lineHeight","letterSpacing","textAlign","textTransform","textDecoration","whiteSpace","overflow","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","objectFit"],M=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;function z(e,t){return!!D(t)&&("flexGrow"===e||"flexShrink"===e?M.test(t)&&Number.isFinite(Number(t))&&Number(t)>=0:["display","boxSizing","flexDirection","flexWrap","alignItems","justifyContent","alignSelf","textAlign","whiteSpace","overflow","strokeLinecap","strokeLinejoin","objectFit"].includes(e)?!M.test(t):!!/^(none|normal|auto|transparent|currentcolor)$/i.test(t)||(/^(?:width|height|gridTemplateColumns)$/.test(e)?/^(?:min-content|max-content|fit-content|subgrid)$/.test(t):/^(?:padding|margin|border.*Radius|gap|rowGap|columnGap|letterSpacing|strokeWidth)/.test(e)?/^0(?:px|em|rem|%)?$/.test(t):/^border(Top|Right|Bottom|Left)$/.test(e)?/^(?:0px\b|.*\bnone\b)/.test(t):"opacity"===e?"1"===t:/^(?:backgroundColor|fill|stroke)$/.test(e)&&/^rgba\([^)]*,\s*0\)$/.test(t)))}function O(e,t){return{...e,tokens:[...e.tokens,...t.tokens??[]]}}function W(e){return/^(width|height|marginTop|marginRight|marginBottom|marginLeft|gridTemplateColumns)$/.test(e)}var B=e=>{throw new J(e)},D=e=>"string"==typeof e&&e.length>0&&e.length<=512&&!/[;{}\\]|\b(?:url|expression|var)\s*\(/i.test(e)&&![...e].some(e=>e.charCodeAt(0)<32),G=e=>"string"==typeof e&&/^[a-zA-Z0-9_-]{1,80}$/.test(e),q=new Set(["div","span","img","svg","path","circle","rect","line","polyline","polygon","ellipse","g"]),_=e=>"string"==typeof e&&e.length<=2e4&&/^(https?:\/\/|blob:https?:\/\/|data:image\/(png|jpeg|webp|gif);base64,)/i.test(e),Z=new Set(["viewBox","d","cx","cy","r","rx","ry","x","y","x1","x2","y1","y2","width","height","points","transform","fillRule","clipRule"]);function H(e){(!e||"object"!=typeof e||JSON.stringify(e).length>24e4)&&B("Invalid fragment capture.");let t=e,{evidence:r,draft:n}=t;(!r||!G(r.id)||![r.width,r.height].every(e=>Number.isFinite(e)&&e>0&&e<=1e4)||!Array.isArray(r.values)||r.values.length>180||!n||!Array.isArray(n.constraints)||n.constraints.length>32||!Array.isArray(n.tokens)||n.tokens.length>128)&&B("This component is too large to capture. Try a smaller element.");let i=new Set;for(let e of r.values)(!e||!G(e.id)||i.has(e.id)||!U.includes(e.property)||void 0!==e.local&&(!0!==e.local||!W(e.property))||!D(e.value))&&B("Unsupported captured style."),i.add(e.id);let o=0,a=new Set,s=(e,t)=>{(!e||!G(e.id)||a.has(e.id)||!q.has(e.tag)||++o>64||t>12||!Array.isArray(e.children)||e.children.length>128||!e.styles||"object"!=typeof e.styles)&&B("This component is too complex. Try a smaller element."),a.add(e.id);for(let[t,n]of Object.entries(e.styles))r.values.some(e=>e.id===n&&e.property===t)||B("Invalid captured style reference.");for(let[t,r]of Object.entries(e.attributes??{}))"img"===e.tag&&"src"===t&&_(r)||(!Z.has(t)||"string"!=typeof r||r.length>12e3||!/^[\d\w\s.,+()-]*$/.test(r))&&B("Unsupported vector geometry.");for(let r of e.children)"string"==typeof r?r.length>2e3&&B("Too much captured text."):s(r,t+1)};return s(r.root,0),t}function K(e,t,r){try{let n,i=["fontWeight","opacity","flexGrow","flexShrink","strokeWidth"].includes(r);if("token"===t.kind){let r=e.tokens.find(e=>e.id===t.id);n=r?R(r.value,e.constraints,!i):null}else{let r=p(e.constraints,t.id,t.step??0);n=f(r),"layout"===r.kind&&!r.unit&&!i&&(n+="px")}return D(n)?n:null}catch{return null}}function V(e,t){let r=["div","span","img"].includes(t.tag)?{all:"initial"}:{};for(let[e,n]of Object.entries(t.localStyles??{}))U.includes(e)&&(z(e,n)||W(e)&&D(n))&&(r[e]=["flexGrow","flexShrink","opacity","strokeWidth"].includes(e)&&Number.isFinite(Number(n))?Number(n):n);for(let[n,i]of Object.entries(t.styles)){if(!U.includes(n))continue;let t=K(e,i,n);null!==t&&(r[n]=["fontWeight","opacity","flexGrow","flexShrink","strokeWidth"].includes(n)&&Number.isFinite(Number(t))?Number(t):t)}return r}var J=class extends Error{};function P(){let e=t();return{...e,tokens:[],constraints:e.constraints.map(e=>({...e,value:"",parentId:null}))}}function X(e,t){t=O(t,e);let r=new Map,n=e=>{let r=t.constraints.find(t=>t.id===e);return r?r.parentId?`@${t.constraints.find(e=>e.id===r.parentId)?.name??r.parentId}${"font"===r.kind?"":"color"===r.kind?` · hue ${r.derivative}°`:` × ${r.derivative}`}`:r.value:"Missing dimension"},i=e=>{let o=e.children.filter(e=>"string"==typeof e).join(" ").trim();for(let[i,a]of Object.entries(e.styles)){let s=`${a.kind}:${a.id}:${a.step??0}`,l=r.get(s);if(!l){let e="token"===a.kind?t.tokens.find(e=>e.id===a.id):void 0,i="dimension"===a.kind?t.constraints.find(e=>e.id===a.id):void 0,o=[],d=new Set("dimension"===a.kind?[a.id]:[]),u=e=>{if(d.has(e))return;d.add(e);let r=t.constraints.find(t=>t.id===e);if(!r)return;let i="Unresolved";try{i=f(p(t.constraints,e))}catch{}o.push({id:e,name:r.name,expression:n(e),value:i}),r.parentId&&u(r.parentId)};e&&S(e.value,t.constraints).forEach(e=>{let r=t.constraints.find(t=>t.name===e.name);r&&u(r.id)}),i?.parentId&&u(i.parentId),l={key:s,source:a,name:e?.name??i?.name??a.id,expression:e?.value??n(a.id),derived:o.length>0,dependencies:o,values:[],targets:[]},r.set(s,l)}let d=K(t,a,i)??"Unresolved";l.values.includes(d)||l.values.push(d),l.targets.push({nodeId:e.id,label:o.slice(0,64)||`${e.tag} · ${e.id}`,property:i})}e.children.forEach(e=>{"string"!=typeof e&&i(e)})};return i(e.root),[...r.values()]}function Q(e){let t=new Map(e.constraints.map(e=>[e.id,[]]));for(let r of e.constraints)r.parentId&&t.get(r.parentId)?.push({kind:"dimension",id:r.id});function r(r,n){return Object.fromEntries(r.map(r=>{let i=S(r.value,e.constraints).map((i,o)=>{let a=e.constraints.find(e=>e.name.toLowerCase()===i.name.toLowerCase()),s=i.step??0;return a&&t.get(a.id)?.push({kind:"token",id:r.id,...n?{fragmentId:n}:{},referenceIndex:o,step:s,...void 0!==i.opacity?{opacity:i.opacity}:{}}),{dimensionId:a?.id??null,expression:r.value.slice(i.start,i.end),step:s}});return[r.id,{...r,references:i,bindings:o("token",r.id,n),resolved:R(r.value,e.constraints)}]}))}let n=e.usage??[],i=(e.fragments??[]).map(t=>({fragment:t,uses:X(t,e)}));function o(e,t,r){return{usage:r?[]:n.filter(r=>r.source.kind===e&&r.source.id===t),components:i.flatMap(({fragment:n,uses:i})=>r&&n.id!==r?[]:i.filter(i=>i.source.kind===e&&i.source.id===t&&("token"!==e||r||!n.tokens?.some(e=>e.id===t))).map(e=>({fragmentId:n.id,step:e.source.step??0,targets:e.targets})))}}let a=r(e.tokens),s=Object.fromEntries(i.map(({fragment:e,uses:t})=>[e.id,{name:e.name,tokens:r(e.tokens??[],e.id),uses:t}]));return{dimensions:Object.fromEntries(e.constraints.map(r=>{let n=Object.fromEntries(("font"===r.kind?[0]:[-2,-1,0,1,2]).map(t=>{try{return[t,f(p(e.constraints,r.id,t))]}catch{return[t,null]}})),i=r.parentId?"font"===r.kind?"inherit":"color"===r.kind?"rotate-hue":"multiply":"literal";return[r.id,{...r,derivation:i,resolvedBase:n[0],steps:n,dependents:t.get(r.id),bindings:o("dimension",r.id)}]})),tokens:a,usage:e.usage??[],resolvedUsage:L(e),components:s,featuredComponentId:e.featuredComponentId??null}}var Y=(e,t=512)=>"string"==typeof e&&e.length<=t&&![...e].some(e=>e.charCodeAt(0)<32)&&!/[;{}]|\b(?:url|expression)\s*\(/i.test(e);function ee(e,t){if(!t||"object"!=typeof t||Array.isArray(t)||Object.keys(t).some(e=>!["name","constraints","tokens","usage","featuredComponentId"].includes(e)))throw Error("Invalid proposal patch.");let r=structuredClone(e);if(void 0!==t.featuredComponentId){if(null!==t.featuredComponentId&&!r.fragments?.some(e=>e.id===t.featuredComponentId))throw Error("The featured component must belong to this Taste.");r.featuredComponentId=t.featuredComponentId}if(void 0!==t.name){if("string"!=typeof t.name||t.name.length>80)throw Error("Invalid name.");r.name=t.name}if(void 0!==t.constraints){if(!Array.isArray(t.constraints)||t.constraints.length>32)throw Error("Invalid dimensions.");let e=new Set;for(let n of t.constraints){if(!n||"object"!=typeof n||Object.keys(n).some(e=>!["id","value","parentId","derivative","scale"].includes(e)))throw Error("Invalid dimension patch.");let t=r.constraints.find(e=>e.id===n.id);if(!t||e.has(n.id))throw Error("Unknown or duplicate dimension ID.");if(e.add(n.id),Object.assign(t,n),!Y(t.value)||!Number.isFinite(t.derivative)||!Number.isFinite(t.scale)||t.scale<0||"increment"===t.scaleMode&&t.scale<=0||"color"===t.kind&&t.scale>1||"font"===t.kind&&(1!==t.scale||1!==t.derivative)||"layout"===t.kind&&t.derivative<0||null!==t.parentId&&!r.constraints.some(e=>e.id===t.parentId&&e.kind===t.kind))throw Error(`Invalid ${t.id} dimension.`)}for(let e of r.constraints)(e.value||e.parentId)&&p(r.constraints,e.id)}if(void 0!==t.tokens){if(!Array.isArray(t.tokens)||t.tokens.length>128)throw Error("Invalid tokens.");let e=new Set,n=new Set;for(let r of t.tokens){if(!r||"string"!=typeof r.id||!/^[a-zA-Z0-9_-]{1,80}$/.test(r.id)||"string"!=typeof r.name||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.name)||!Y(r.value)||e.has(r.id)||n.has(r.name))throw Error("Invalid or duplicate token.");e.add(r.id),n.add(r.name)}r.tokens=structuredClone(t.tokens)}void 0!==t.usage&&(r.usage=structuredClone(t.usage));for(let e of r.tokens)if(!A(e.value,r.constraints))throw Error(`Invalid reference or calc expression in ${e.name}.`);if(!Array.isArray(r.usage??[])||(r.usage?.length??0)>128)throw Error("Invalid usage mappings.");for(let e of r.usage??[])if(!e||Object.keys(e).some(e=>!["target","property","source"].includes(e))||!T.includes(e.target)||!F.includes(e.property)||!e.source||Object.keys(e.source).some(e=>!["kind","id","step"].includes(e))||!["token","dimension"].includes(e.source.kind)||!("token"===e.source.kind?r.tokens:r.constraints).some(t=>t.id===e.source.id)||void 0!==e.source.step&&(!Number.isInteger(e.source.step)||Math.abs(e.source.step)>100))throw Error("Usage must reference an existing token or dimension.");return r}function te(e,r=!0,n=!0){let i=t(),o={past:[],future:[]},a={current:{past:[],future:[]}},s={available:r,revision:crypto.randomUUID(),runId:"",openRequest:"",open:!1,mode:"empty",state:e?"complete":"idle",message:"",draft:e??null},l=new Set,d=null,u=new Set,c=e=>{d={id:crypto.randomUUID(),target:e,expiresAt:Date.now()+2e3},u.forEach(e=>e())},m=()=>{d=null,u.forEach(e=>e())},h=e=>{s={...s,...e,revision:crypto.randomUUID()},l.forEach(e=>e())},g={setCreationAllowed(e){n=e},history:a,getLookSnapshot:()=>d,subscribeLook:e=>(u.add(e),()=>{u.delete(e)}),setAvailable(e){s.available!==e&&h({available:e})},getSnapshot:()=>s,subscribe:e=>(l.add(e),()=>{l.delete(e)}),create(e="template",r=!1){if(!n)throw Error("An active subscription is required to create a Taste.");m(),"template"===e&&!r&&(i=t()),"template"===e?(r||(o.past=[],o.future=[]),a.current=o):a.current={past:[],future:[]},h({open:!0,openRequest:crypto.randomUUID(),runId:crypto.randomUUID(),mode:e,state:"extract"===e?"running":"complete",message:"",draft:"template"===e?i:P()})},edit(e){"running"!==s.state&&("template"===s.mode&&(i=e),h({draft:e}))},addFragment(e,t){if(s.runId!==e||!s.open||"running"===s.state||!s.draft)throw Error("This proposal has changed. Capture the component again.");let r=s.draft;if((r.fragments?.length??0)>=16)throw Error("A proposal can contain up to 16 components.");if(r.fragments?.some(e=>e.id===t.fragment.id))throw Error("This component was already captured.");if(t.tokens.some(e=>r.tokens.some(t=>t.id===e.id||t.name===e.name)))throw Error("A component token conflicts with a shared token. Retry capture.");let n=ee({...r,usage:[]},{tokens:t.tokens}),i=e=>{for(let t of Object.values(e.styles))if(!("token"===t.kind?[...r.tokens,...n.tokens]:n.constraints).some(e=>e.id===t.id))throw Error("A referenced Taste value was removed. Retry capture.");e.children.forEach(e=>{"string"!=typeof e&&i(e)})};i(t.fragment.root);let o={...r,fragments:[...r.fragments??[],{...t.fragment,tokens:t.tokens}]};return a.current.past.push(r),a.current.past.length>100&&a.current.past.shift(),a.current.future=[],g.edit(o),o},stream(e,t){s.runId===e&&"running"===s.state&&h(t)},close(){m(),h({open:!1,..."running"===s.state?{state:"error",message:"Extraction stopped. Retry or continue editing the partial draft."}:{}})},command(e){let t=(e,t={})=>({status:e,...s,...t,saved:!1,applied:!1});if(void 0!==e.target&&"inspect"!==e.action)return t("invalid",{error:"target is only supported for inspection."});if("inspect"===e.action){let r=e.target;if(void 0!==r){let{draft:t,...n}=s,i=(e,t={})=>({status:e,...n,saved:!1,applied:!1,...t});if(!r||!["dimension","token"].includes(r.kind)||"string"!=typeof r.id||!r.id||r.id.length>200)return i("invalid");let o=("dimension"===r.kind?t?.constraints:t?.tokens)?.find(e=>e.id===r.id);if(!o||!t)return i("not_found",{target:r});let a,l=null;try{l="dimension"===r.kind?f(p(t.constraints,r.id)):R(o.value,t.constraints)}catch(e){a=e instanceof Error?e.message:"Not resolved yet"}return c({kind:r.kind,id:r.id}),i("ok",{target:r,row:o,resolved:l,...!0===e.includeRelationships?{relationships:Q(t)["dimension"===r.kind?"dimensions":"tokens"][r.id]}:{},...a?{resolutionError:a}:{}})}return s.draft&&c(null),t("ok")}if(!s.available)return t("unavailable",{error:"The host Taste panel is not available in this browser."});if(!["create","modify"].includes(e.action))return t("invalid",{error:"Unknown proposal action."});if(!e.expectedRevision||e.expectedRevision!==s.revision)return t("conflict");if("running"===s.state)return t("busy");try{if("create"===e.action){let t=e.mode??"template";if(!["template","empty","extract"].includes(t)||e.patch)throw Error("Create accepts a mode; modify the returned draft separately.");g.create(t)}else{if(!s.draft)return t("not_found");let r=ee(s.draft,e.patch);a.current.past=[...a.current.past.slice(-99),s.draft],a.current.future=[],"template"===s.mode&&(i=r),h({draft:r,open:!0,openRequest:crypto.randomUUID()})}return t("ok")}catch(e){return t("invalid",{error:e instanceof Error?e.message:"Invalid patch."})}}};return g}var re=te(null,!1,!1);e.connect(re);export{K as A,V as B,P as C,X as D,te as E,re as F,t as a,n as b,u as c,c as d,p as e,f,m as g,h,g as i,v as j,y as k,k as l,$ as m,x as n,C as o,S as p,N as q,R as r,j as s,L as t,U as u,O as v,W as w,D as x,_ as y,H as z};