@popmelt.com/core 0.35.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 (225) hide show
  1. package/README.md +80 -29
  2. package/THIRD_PARTY_NOTICES.md +26 -0
  3. package/claude-plugin/.claude-plugin/plugin.json +1 -1
  4. package/claude-plugin/skills/popmelt-core/SKILL.md +1 -0
  5. package/codex-plugin/.codex-plugin/plugin.json +1 -1
  6. package/codex-plugin/skills/popmelt-core/SKILL.md +1 -0
  7. package/dist/ExploreAttachment-IO3CNUWH.mjs +1 -0
  8. package/dist/PagePreviewLayer-KQ2FLIGX.mjs +1 -0
  9. package/dist/ParticipantRuntime-Y2BQVJSL.mjs +1 -0
  10. package/dist/PhoneHostGate-2G4BA5FP.mjs +1 -0
  11. package/dist/PopmeltTasteConnectedPane-H5QWBFD7.mjs +1 -0
  12. package/dist/PreviewRuntime-V2PZF462.mjs +1 -0
  13. package/dist/QueuedReplies-4APDDNQX.mjs +1 -0
  14. package/dist/SamplePlacementOverlay-ELSP5AHM.mjs +1 -0
  15. package/dist/ShareProjectPane-OR2LS2A3.mjs +1 -0
  16. package/dist/SuppliedContext-SAQKEDWW.mjs +1 -0
  17. package/dist/ThreadErrorCard-OSHIWSHR.mjs +1 -0
  18. package/dist/ThreadPanel-YPL2HDUC.mjs +1 -0
  19. package/dist/adapter-react-three-fiber.d.mts +6 -2
  20. package/dist/adapter-react-three-fiber.mjs +1 -1
  21. package/dist/adapter-three.d.mts +34 -0
  22. package/dist/adapter-three.mjs +45 -1
  23. package/dist/bridge-entry.mjs +1 -1
  24. package/dist/bridgeSSEStream-6OMAFDFW.mjs +1 -0
  25. package/dist/bridgeWebSocketStream-WIOGOPJW.mjs +1 -0
  26. package/dist/browser-runtime-O3EKN3FI.mjs +1 -0
  27. package/dist/browser.d.mts +4 -4
  28. package/dist/browser.mjs +1 -1
  29. package/dist/canvas-chat-note-O3USBECW.mjs +1 -0
  30. package/dist/checkFixture-SOSI7AT4.mjs +1 -0
  31. package/dist/chunk-3VOEPWRL.mjs +1 -0
  32. package/dist/chunk-4OEHQ6M7.mjs +24 -0
  33. package/dist/chunk-4YQWU5YB.mjs +1 -0
  34. package/dist/chunk-5IZHN3A7.mjs +1 -0
  35. package/dist/chunk-6EO73WJN.mjs +1 -0
  36. package/dist/{chunk-66VOM5NA.mjs → chunk-6O5QLRSA.mjs} +1 -1
  37. package/dist/chunk-76WRZ2NH.mjs +1 -0
  38. package/dist/chunk-A4GARXVQ.mjs +1 -0
  39. package/dist/chunk-AAMUU2QA.mjs +1 -0
  40. package/dist/chunk-AGCS65LT.mjs +1 -0
  41. package/dist/chunk-AGYBVMHX.mjs +1 -0
  42. package/dist/{chunk-RR4SHK7O.mjs → chunk-AOTDTBQO.mjs} +1 -1
  43. package/dist/chunk-ATLUO4G7.mjs +1 -0
  44. package/dist/chunk-AYZUOBFI.mjs +1 -0
  45. package/dist/chunk-B22WBEQC.mjs +1 -0
  46. package/dist/chunk-B2ISA6V6.mjs +1 -0
  47. package/dist/chunk-B4DYUYX4.mjs +1 -0
  48. package/dist/chunk-BVGHHT3Y.mjs +1 -0
  49. package/dist/{chunk-NDGM4DAP.mjs → chunk-BYASSHKJ.mjs} +1 -1
  50. package/dist/chunk-C2ZSNUXQ.mjs +1 -0
  51. package/dist/chunk-CIA6WVXQ.mjs +1 -0
  52. package/dist/chunk-CIKFUS7J.mjs +1 -0
  53. package/dist/chunk-CK3CDA3L.mjs +1 -0
  54. package/dist/{chunk-M5P6VHZY.mjs → chunk-DO46YJCX.mjs} +1 -1
  55. package/dist/chunk-DRPRASD6.mjs +1 -0
  56. package/dist/chunk-EBJ23A7F.mjs +1 -0
  57. package/dist/chunk-ECMLCGAM.mjs +1 -0
  58. package/dist/chunk-EILBHZDX.mjs +1 -0
  59. package/dist/{chunk-DOCRI237.mjs → chunk-ELKVFX2O.mjs} +1 -1
  60. package/dist/chunk-EUFR7R5Q.mjs +1 -0
  61. package/dist/chunk-EZVFCJEG.mjs +1 -0
  62. package/dist/chunk-FHCKFQBY.mjs +1 -0
  63. package/dist/chunk-FJWWBKCQ.mjs +1 -0
  64. package/dist/chunk-FON4QY7P.mjs +1 -0
  65. package/dist/chunk-GLF7Z5IR.mjs +1 -0
  66. package/dist/chunk-HAZXZ5TU.mjs +1 -0
  67. package/dist/chunk-HKHZBKAN.mjs +1 -0
  68. package/dist/chunk-I6FJ533W.mjs +1 -0
  69. package/dist/chunk-I7AI52RX.mjs +1 -0
  70. package/dist/chunk-IAXSC2ZN.mjs +1 -0
  71. package/dist/chunk-IGKU4YIV.mjs +1 -0
  72. package/dist/chunk-IW7V7WNL.mjs +1 -0
  73. package/dist/chunk-JCW2WY7X.mjs +1 -0
  74. package/dist/chunk-JEGBAHYK.mjs +1 -0
  75. package/dist/chunk-JLK3VRBT.mjs +1 -0
  76. package/dist/chunk-KCDHP4N3.mjs +1 -0
  77. package/dist/chunk-KF73S7MG.mjs +1 -0
  78. package/dist/chunk-L6S66APQ.mjs +1 -0
  79. package/dist/chunk-LH7HKUCK.mjs +1 -0
  80. package/dist/chunk-LOUWY55X.mjs +1 -0
  81. package/dist/chunk-LXFKOYLK.mjs +1 -0
  82. package/dist/chunk-MDPZUECK.mjs +1 -0
  83. package/dist/chunk-MHWIFSXJ.mjs +1 -0
  84. package/dist/chunk-MPEVFQ43.mjs +1 -0
  85. package/dist/{chunk-57FM7XQV.mjs → chunk-NI77Y3WC.mjs} +1 -1
  86. package/dist/chunk-NXTWB3A7.mjs +1 -0
  87. package/dist/chunk-OA63PYHZ.mjs +1 -0
  88. package/dist/chunk-OFJUTWJU.mjs +1 -0
  89. package/dist/chunk-OREALBUO.mjs +1 -0
  90. package/dist/chunk-OVZ4CQGM.mjs +1 -0
  91. package/dist/{chunk-XG2YIAJS.mjs → chunk-OZBMHEOD.mjs} +1 -1
  92. package/dist/chunk-PILMDBAX.mjs +1 -0
  93. package/dist/chunk-PLE6FFKY.mjs +1 -0
  94. package/dist/chunk-PRPXMDZ7.mjs +1 -0
  95. package/dist/chunk-PWQB3FIW.mjs +1 -0
  96. package/dist/chunk-ROKRMYFR.mjs +1 -0
  97. package/dist/chunk-SNAJBV7T.mjs +30 -0
  98. package/dist/chunk-SOGN7S54.mjs +1 -0
  99. package/dist/chunk-SOT33EQ4.mjs +1 -0
  100. package/dist/chunk-SQA27YGA.mjs +1 -0
  101. package/dist/chunk-SUAHDXJZ.mjs +1 -0
  102. package/dist/chunk-TCGXG7UA.mjs +1 -0
  103. package/dist/chunk-TMSGNHXH.mjs +1 -0
  104. package/dist/chunk-TQ3SP5TE.mjs +1 -0
  105. package/dist/chunk-UTP56NCY.mjs +1 -0
  106. package/dist/chunk-W2QQVB2H.mjs +1 -0
  107. package/dist/chunk-WC4ZNVFM.mjs +1 -0
  108. package/dist/chunk-WDSFOF2E.mjs +1 -0
  109. package/dist/chunk-WP2SHSCG.mjs +1 -0
  110. package/dist/chunk-X6I6KQDG.mjs +1 -0
  111. package/dist/chunk-XJJDBMZI.mjs +1 -0
  112. package/dist/chunk-XY7YW7SH.mjs +1 -0
  113. package/dist/chunk-YMWXWXPV.mjs +1 -0
  114. package/dist/chunk-YU3ZY76H.mjs +1 -0
  115. package/dist/chunk-YVT3J6JB.mjs +1 -0
  116. package/dist/chunk-YYFF2X3L.mjs +1 -0
  117. package/dist/cli.mjs +1 -1
  118. package/dist/codex-note-context-UI55CWRI.mjs +1 -0
  119. package/dist/codex-project-LIU27RXA.mjs +1 -0
  120. package/dist/codex-session-registry-YNU6LEVH.mjs +1 -0
  121. package/dist/codex-store-mount-EPETPOBA.mjs +1 -0
  122. package/dist/{dev-server-DtX2_HCa.d.mts → dev-server-BRrhkH5t.d.mts} +11 -1
  123. package/dist/dev-server-WYB2CRC5.mjs +1 -0
  124. package/dist/focus-inspection-42IEM45O.mjs +1 -0
  125. package/dist/guest-admission.d.mts +2 -0
  126. package/dist/guest-admission.mjs +1 -0
  127. package/dist/guest-live-canvas.d.mts +2 -0
  128. package/dist/guest-live-canvas.mjs +1 -0
  129. package/dist/index.d.mts +6 -6
  130. package/dist/index.mjs +1 -1
  131. package/dist/invitationLink-LUIIOAEZ.mjs +1 -0
  132. package/dist/inviteQr-HVHH45SN.mjs +1 -0
  133. package/dist/inviteQr-U77MLSEQ.mjs +1 -0
  134. package/dist/media.d.mts +3 -3
  135. package/dist/memory-store.d.mts +5 -1
  136. package/dist/page-interaction-TV3P6B3X.mjs +1 -0
  137. package/dist/page-planes-2ZepTpen.d.mts +817 -0
  138. package/dist/participantBootstrap-BuTrTQbo.d.mts +22 -0
  139. package/dist/{participantBootstrap-DFJlcKRI.d.mts → participantBootstrap-DuosDN9G.d.mts} +9 -3
  140. package/dist/peer-client-RSC6EGAF.mjs +1 -0
  141. package/dist/plain-html-EF7MUNRZ.mjs +1 -0
  142. package/dist/plugin-astro.d.mts +5 -2
  143. package/dist/plugin-astro.mjs +1 -1
  144. package/dist/plugin-next.mjs +1 -1
  145. package/dist/plugin-nuxt.d.mts +4 -2
  146. package/dist/plugin-nuxt.mjs +1 -1
  147. package/dist/plugin-vite.d.mts +86 -9
  148. package/dist/plugin-vite.mjs +1 -1
  149. package/dist/qr-encoder.mjs +3 -0
  150. package/dist/server.d.mts +43 -20
  151. package/dist/server.mjs +1 -1
  152. package/dist/shared-page-GO76UP7I.mjs +1 -0
  153. package/dist/{subjects-DdavjSTL.d.mts → subjects-BhO1x5tz.d.mts} +80 -1
  154. package/dist/taste-proposal-session-DBOUA54V.mjs +1 -0
  155. package/dist/toolbarFonts-GVPRHJGB.mjs +1 -0
  156. package/dist/{types-C8tjyhiF.d.mts → types-CggBG-H6.d.mts} +1 -136
  157. package/dist/{video-adapter-DB6Hex1f.d.mts → video-adapter-B8J5awc_.d.mts} +2 -2
  158. package/dist/workspace-snapshot-6LN7U2NJ.mjs +1 -0
  159. package/package.json +46 -22
  160. package/samples/README.md +32 -0
  161. package/samples/build.d.mts +16 -0
  162. package/samples/build.mjs +138 -0
  163. package/dist/ExploreAttachment-TTEKD4AU.mjs +0 -1
  164. package/dist/PagePreviewLayer-TJZOJBSD.mjs +0 -1
  165. package/dist/ParticipantRuntime-BQAOTSQZ.mjs +0 -1
  166. package/dist/PhoneHostGate-LNSDZOG2.mjs +0 -1
  167. package/dist/PopmeltTasteConnectedPane-NCCF7YUX.mjs +0 -1
  168. package/dist/PreviewRuntime-H2UOLP6T.mjs +0 -1
  169. package/dist/QueuedReplies-LQUBEZ6K.mjs +0 -1
  170. package/dist/SuppliedContext-YKQSMF3J.mjs +0 -1
  171. package/dist/ThreadErrorCard-4MOA34C4.mjs +0 -1
  172. package/dist/ThreadPanel-T6IXWFLA.mjs +0 -1
  173. package/dist/bridgeSSEStream-K3UIMBTC.mjs +0 -1
  174. package/dist/bridgeWebSocketStream-2SUZUBE3.mjs +0 -1
  175. package/dist/browser-runtime-HQM2Y6EL.mjs +0 -1
  176. package/dist/canvas-chat-note-MGAEUYJO.mjs +0 -1
  177. package/dist/checkFixture-BXILOUP5.mjs +0 -1
  178. package/dist/chunk-2P2NUZW7.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-6LBPTCGC.mjs +0 -1
  184. package/dist/chunk-AYDREFWN.mjs +0 -1
  185. package/dist/chunk-CRJPE33X.mjs +0 -1
  186. package/dist/chunk-DC47WNPG.mjs +0 -1
  187. package/dist/chunk-DJTGR3RO.mjs +0 -1
  188. package/dist/chunk-DOJBWTT5.mjs +0 -1
  189. package/dist/chunk-EX63NVDN.mjs +0 -1
  190. package/dist/chunk-F45IVFS3.mjs +0 -1
  191. package/dist/chunk-F5XSNRGT.mjs +0 -1
  192. package/dist/chunk-G7JR5Z3P.mjs +0 -1
  193. package/dist/chunk-GKOMTSWV.mjs +0 -1
  194. package/dist/chunk-HAE5LUJX.mjs +0 -1
  195. package/dist/chunk-HU2XWUJC.mjs +0 -1
  196. package/dist/chunk-HV7HRQ2S.mjs +0 -1
  197. package/dist/chunk-J4WDYITA.mjs +0 -1
  198. package/dist/chunk-KTRMNVPZ.mjs +0 -1
  199. package/dist/chunk-LVEMYZOA.mjs +0 -1
  200. package/dist/chunk-N4737FRL.mjs +0 -1
  201. package/dist/chunk-NSCO633B.mjs +0 -1
  202. package/dist/chunk-O4HZP3RP.mjs +0 -1
  203. package/dist/chunk-OAHYSDJ4.mjs +0 -1
  204. package/dist/chunk-PQT5FYN5.mjs +0 -1
  205. package/dist/chunk-R34FOW4D.mjs +0 -1
  206. package/dist/chunk-RUTWU5W2.mjs +0 -1
  207. package/dist/chunk-S7BCEQKP.mjs +0 -1
  208. package/dist/chunk-T4CCY2EL.mjs +0 -1
  209. package/dist/chunk-TH7DML4A.mjs +0 -1
  210. package/dist/chunk-UEGDSECJ.mjs +0 -1
  211. package/dist/chunk-V2I7PSJW.mjs +0 -1
  212. package/dist/chunk-WDAXARLI.mjs +0 -1
  213. package/dist/chunk-WHJEKDNP.mjs +0 -1
  214. package/dist/chunk-XM6RE6HT.mjs +0 -1
  215. package/dist/chunk-XT6PHPPG.mjs +0 -1
  216. package/dist/chunk-Y3SF5YCR.mjs +0 -1
  217. package/dist/chunk-ZG6XHKYO.mjs +0 -1
  218. package/dist/chunk-ZG7MAEEV.mjs +0 -30
  219. package/dist/codex-note-context-OUG4S6XE.mjs +0 -1
  220. package/dist/codex-project-B5466BL6.mjs +0 -1
  221. package/dist/codex-session-registry-ONODFWFD.mjs +0 -1
  222. package/dist/focus-inspection-SZJ5KP23.mjs +0 -1
  223. package/dist/peer-client-SCSWLRCX.mjs +0 -1
  224. package/dist/taste-proposal-session-XU4N7RUV.mjs +0 -1
  225. package/dist/workspace-snapshot-RTTXNNUX.mjs +0 -1
package/README.md CHANGED
@@ -4,43 +4,94 @@
4
4
 
5
5
  # Popmelt
6
6
 
7
- Popmelt is a design layer for humans and AI. Point to an element in your local web app, describe a change, and work through it with Codex or Claude Code in a thread on the page.
7
+ Popmelt is a design layer for humans and AI. Click an element in your running app, show your coding agent what you want to change, and review the result on the page.
8
8
 
9
- ## Install and leave your first annotation
9
+ [Get started](#get-started) · [Features](#features) · [Keyboard and mouse shortcuts](#keyboard-and-mouse-shortcuts) · [Framework setup](https://popmelt.com/docs/core/getting-started)
10
10
 
11
- You'll need a local web project, Node.js 18 or newer (or the version your framework requires), and a signed-in Codex or Claude Code CLI.
11
+ ## Get started
12
12
 
13
- 1. Open your project in your coding agent and ask it to install Popmelt using the [setup guide for your framework](https://popmelt.com/docs/core/getting-started).
13
+ You'll need a local web project, a coding agent, and Node.js 18 or newer (or the version your framework requires).
14
14
 
15
- ```text
16
- Let's install @popmelt.com/core in this project
17
- ```
15
+ 1. Ask your coding agent to set up `@popmelt.com/core` using the [guide for your framework](https://popmelt.com/docs/core/getting-started). Standard setups include Vite, Next.js, Astro, and Nuxt. For a plain HTML project, install the package and run `npx popmelt serve` in the site directory.
16
+ 2. Start your dev server. On first use, Popmelt opens your local browser and links it as the host. For a headless session or a different browser, open the private URL from `.popmelt/participant-host-link.json`. Guest access starts off.
17
+ 3. Double-tap **Command** on macOS or **Control** on Windows or Linux. Choose **Chat** (`C`), click a card, and type “Give this card more breathing room.”
18
+ 4. Click the **Send** arrow or press **Cmd/Ctrl + Enter**. Open the numbered badge to read your agent’s reply or ask for another adjustment.
18
19
 
19
- 2. Start or restart your app with its usual development command and open its local URL.
20
- 3. Double-tap **Command** on macOS or **Control** on Windows or Linux to open the toolbar. Choose **Chat** (`C`), click a card, and type “Give this card more breathing room.”
21
- 4. Press **Cmd+Enter** or **Ctrl+Enter** to send the annotation. Review the change on the page and reply in the same thread.
20
+ <details>
21
+ <summary>Copy a setup prompt for your agent</summary>
22
22
 
23
- Threads and screenshots are saved in your project under `.popmelt/`. When you send an annotation, the relevant context goes to your selected AI provider.
24
-
25
- ## Telemetry and opt-out
26
-
27
- During local development, Popmelt reports daily active projects by default. Reports include a random project ID, Core version, framework, Node.js major version, and operating system. They exclude source code, annotations, and thread content. In Git projects, reporting begins after `popmelt.project.json` is committed. In a public repository, that ID can be linked back to the project.
28
-
29
- **Turn telemetry off for all projects on this machine**
30
-
31
- ```sh
32
- npx @popmelt.com/core telemetry disable
23
+ ```text
24
+ Install @popmelt.com/core in this project. For Git projects without existing ignore rules for .popmelt, add .popmelt/ to the project’s .gitignore. Set up a CLI that Popmelt supports in the environment that runs my dev server. Use my current agent’s CLI if supported. If it's missing, install it using the vendor's setup instructions. If it needs sign-in, guide me through login and verify it afterward. Verify the Popmelt bridge and tell me which local URL to open.
33
25
  ```
34
26
 
35
- Popmelt also honors `DO_NOT_TRACK=1`.
36
-
37
- ## Docs
38
-
39
- - [Annotate elements and work in threads](https://popmelt.com/docs/core/comments-and-threads)
40
- - [Preview style changes with Steer](https://popmelt.com/docs/core/steer)
41
- - [Review project memory with Imprint](https://popmelt.com/docs/core/imprint)
42
- - [Attach application context to annotations](https://popmelt.com/docs/core/application-context)
43
- - [Annotate Three.js scenes](https://popmelt.com/docs/core/media-and-3d)
27
+ | Desktop agent | CLI setup | Check sign-in | Sign in |
28
+ | --- | --- | --- | --- |
29
+ | Codex | [Codex CLI installation](https://github.com/openai/codex#installing-and-running-codex-cli) | `codex login status` | `codex login` |
30
+ | Claude Code | [Claude Code installation](https://code.claude.com/docs/en/setup#installation) | `claude auth status` | `claude auth login` |
31
+ | Grok Code (Cursor) | [Cursor CLI installation](https://cursor.com/docs/cli/installation) | `cursor-agent status` | `cursor-agent login` |
32
+ | OpenCode 2 | [OpenCode CLI installation](https://opencode.ai/docs/) | `opencode models` | `opencode auth login` |
33
+
34
+ For Grok Code (Cursor), choose a model in Popmelt’s model picker. The list comes from your installed Cursor CLI. Choose **Cursor default** to use the CLI’s configured model.
35
+
36
+ </details>
37
+
38
+ ## Features
39
+
40
+ | Feature | What you can do |
41
+ | --- | --- |
42
+ | [Annotations and threads](https://popmelt.com/docs/core/comments-and-threads) | Pin a question to an element, paste a reference image, or double-click text to draft a replacement. Follow up on the same badge or find the conversation in History. |
43
+ | [Steer](https://popmelt.com/docs/core/steer) | Try padding, gap, color, type, and other CSS values on the live element. Send the changes together when the preview looks right. |
44
+ | [Explore](https://popmelt.com/docs/core/explore) | Type `/explore` in a single-element annotation or thread to ask for alternatives. Compare them with the original on the page, refine one, and send it for implementation. |
45
+ | [Pair and Share](https://popmelt.com/docs/core/multiplayer) | Pair your own phone for host access, or turn on **Allow collaborators?** to invite a guest by QR code or link. Choose **Local** for the same network or **Remote** for a Cloudflare Tunnel. Projects start private. |
46
+ | [Multiplayer](https://popmelt.com/docs/core/multiplayer) | In a shared Git project, everyone gets their own version of the app, called a plane. Select anyone’s avatar to see their latest code and drafts update live. |
47
+ | [Sampling](#sampling) | Shift-click an element to copy it with its children. On your plane, click where to place the copy. From a teammate’s plane, the sample goes to the matching target on yours if there is one, or you choose where to place it. |
48
+ | [Media and 3D](https://popmelt.com/docs/core/media-and-3d) | Mark a region on an image or paused video. Connect a Three.js scene adapter to attach feedback to a moving object. |
49
+ | [Imprint](https://popmelt.com/docs/core/imprint) | Review what your agent has learned about the project, inspect its evidence, and confirm or correct its understanding. |
50
+ | [Custom context](https://popmelt.com/docs/core/application-context) | Attach app-specific state to an annotation so your agent knows what you were looking at when you left it. |
51
+
52
+ ## Keyboard and mouse shortcuts
53
+
54
+ **Mod** means **Command** on macOS and **Control** on Windows or Linux. Tool keys work with the toolbar open and focus outside a text field.
55
+
56
+ ### Toolbar and annotations
57
+
58
+ | Gesture | Action |
59
+ | --- | --- |
60
+ | Double-tap `Mod` | Open or collapse the toolbar. |
61
+ | `C` / `S` / `I` | Switch to Chat, Steer, or Imprint. |
62
+ | Click an element in Chat | Start an annotation. Double-click its text to edit the wording directly. |
63
+ | `Enter` / `Shift + Enter` | In a new annotation, finish the draft or add a line. In an existing thread, Enter sends a reply. |
64
+ | `Mod + Enter` | Send the annotation or staged changes to your agent. |
65
+ | `Mod + Z` / `Mod + Shift + Z` | Undo or redo a draft change. |
66
+ | Right-click a draft badge | Remove that draft item. |
67
+ | `Option` / `Alt` + drag | In Chat, mark a named region on an image or paused video. |
68
+
69
+ ### Steer
70
+
71
+ | Gesture | Action |
72
+ | --- | --- |
73
+ | `Space` | Search the dial for a property or value. |
74
+ | `Q` / `E` | Move between properties in the dial. |
75
+ | `←` / `→` or `A` / `D` | Preview the previous or next value. |
76
+ | `Enter` / `Esc` | Go deeper or stage the selected value with Enter. Go back one level with Esc. |
77
+
78
+ ### Multiplayer
79
+
80
+ | Gesture | Action |
81
+ | --- | --- |
82
+ | `Mod + ←` / `Mod + →` | Cycle through participants’ planes. |
83
+
84
+ ### Sampling
85
+
86
+ | Gesture | Action |
87
+ | --- | --- |
88
+ | Hold `Shift` over an element | Isolate the target and see whether it can be sampled. |
89
+ | `Shift` + click on your plane | Sample the element, then click where you want the copy. |
90
+ | `Shift` + click on a peer’s plane | Bring the element and its children to the matching target on your plane. If there’s no clear match, click where to place it. |
91
+ | `Mod + Shift` + click on a peer’s plane | Choose the destination yourself, even when a match exists. |
92
+ | `Esc` during placement | Cancel placement. |
93
+
94
+ Threads and screenshots are stored locally under `.popmelt/`. The bridge creates `.popmelt/.gitignore` on first startup. When you send an annotation, the relevant context goes to your selected AI provider. [Data and privacy](https://popmelt.com/docs/core/data-and-privacy)
44
95
 
45
96
  ## License
46
97
 
@@ -95,3 +95,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95
95
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96
96
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
97
97
  SOFTWARE.
98
+
99
+ ---
100
+
101
+ ## QR Code Generator
102
+
103
+ The bundled QR code encoder is licensed under the MIT License.
104
+
105
+ Copyright (c) 2009 Kazuhiko Arase
106
+
107
+ Permission is hereby granted, free of charge, to any person obtaining a copy
108
+ of this software and associated documentation files (the "Software"), to deal
109
+ in the Software without restriction, including without limitation the rights
110
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111
+ copies of the Software, and to permit persons to whom the Software is
112
+ furnished to do so, subject to the following conditions:
113
+
114
+ The above copyright notice and this permission notice shall be included in all
115
+ copies or substantial portions of the Software.
116
+
117
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
121
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
122
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
123
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "popmelt-core",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Local Popmelt context, canvas tools, and ambient turn capture for Claude Code.",
5
5
  "author": {
6
6
  "name": "Popmelt",
@@ -12,6 +12,7 @@ Use the tools deliberately:
12
12
  - Pass the exact `tool session` ID supplied by the Ambient Popmelt Core context as `sessionId` on every tool call. This routes the call to the correct project even when the MCP process has a different working directory.
13
13
 
14
14
  - Use `popmelt_orient_stores` only after the human explicitly chooses the writable primary store and any mounted read stores from an ambient orientation packet. Save that choice as the workspace default unless the human explicitly requests a session-only override. Store proximity, nesting, size, or recency never implies that choice.
15
+ - In a Codex chat, use `popmelt codex mount-store <directory>` when the human asks to attach another workspace store. The mount is read-only and applies to that chat.
15
16
  - Use `popmelt_expand_context` when the automatically supplied packet is truncated or the user explicitly asks for broader history.
16
17
  - Pass the current ambient `threadId` and `jobId` when expanding context. Only a `registered` assessmentContext receipt makes fetched Imprint references available to that turn’s assessment.
17
18
  - Use `popmelt_inspect_thread` when the user asks to inspect the paired thread or its evidence.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "popmelt-core",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Point out what you mean, talk through changes, and keep your AI on the same page.",
5
5
  "author": {
6
6
  "name": "Popmelt",
@@ -12,6 +12,7 @@ Use the tools deliberately:
12
12
  - Pass the exact `tool session` ID supplied by the Ambient Popmelt Core context as `sessionId` on every tool call. This routes the call to the correct project even when the MCP process has a different working directory.
13
13
 
14
14
  - Use `popmelt_orient_stores` only after the human explicitly chooses the writable primary store and any mounted read stores from an ambient orientation packet. Save that choice as the workspace default unless the human explicitly requests a session-only override. Store proximity, nesting, size, or recency never implies that choice.
15
+ - In a Codex chat, use `popmelt codex mount-store <directory>` when the human asks to attach another workspace store. The mount is read-only and applies to that chat.
15
16
  - Use `popmelt_expand_context` when the automatically supplied packet is truncated or the user explicitly asks for broader history.
16
17
  - Pass the current ambient `threadId` and `jobId` when expanding context. Only a `registered` assessmentContext receipt makes fetched Imprint references available to that turn’s assessment.
17
18
  - Use `popmelt_inspect_thread` when the user asks to inspect the paired thread or its evidence.
@@ -0,0 +1 @@
1
+ "use client";import{d as e}from"./chunk-OZBMHEOD.mjs";import{g as t,f as n,b as r}from"./chunk-ZSL57PQ7.mjs";import{a as o,b as a,c as i}from"./chunk-EUFR7R5Q.mjs";import{c as s,f as l,d as p,e as d,a as c,b as u}from"./chunk-MDPZUECK.mjs";import{a as h}from"./chunk-OFJUTWJU.mjs";import{c as m,a as g,b as f}from"./chunk-ELKVFX2O.mjs";import{n as v,m as b,k as x,b as y,c as w,l as k,j as C,i as S}from"./chunk-PWQB3FIW.mjs";import"./chunk-Q6N77LIS.mjs";import{c as E}from"./chunk-ZVDKW7TO.mjs";import"./chunk-FHCKFQBY.mjs";import"./chunk-APP5IYTE.mjs";import{a as I}from"./chunk-G2ZHJXHZ.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-RK6UROPO.mjs";import{l as P}from"./chunk-5IZHN3A7.mjs";import"./chunk-AOTDTBQO.mjs";import{h as T}from"./chunk-W2QQVB2H.mjs";import"./chunk-WP2SHSCG.mjs";import{v as O}from"./chunk-LH7HKUCK.mjs";import{a as N}from"./chunk-Q6C7ZA3H.mjs";import{b as j}from"./chunk-CK3CDA3L.mjs";import"./chunk-NI77Y3WC.mjs";import{b as M}from"./chunk-FON4QY7P.mjs";import{D as A,N as R,aa as z,Z as B,s as L,_ as H,F as J,G as D}from"./chunk-OA63PYHZ.mjs";import{a as W,c as V}from"./chunk-ECMLCGAM.mjs";import"./chunk-AGCS65LT.mjs";import"./chunk-SUAHDXJZ.mjs";import{useContext as K,useState as U,useRef as q,useLayoutEffect as F,useMemo as Y,useEffect as X,useCallback as Q}from"react";import{createPortal as Z}from"react-dom";import{jsxs as $,Fragment as G,jsx as _}from"react/jsx-runtime";import{createContext as ee,domToCanvas as te,destroyContext as ne}from"modern-screenshot";function re(e,t,n,r=!1){let[o,a]=U({}),i=n?.backdrop,s=n?.style.color;return F(()=>{if(location.pathname!==e.pathname||r&&i)return void a({background:i,ink:s});let n="component"===t?y(e):void 0,o=n?.component??n?.element??O(e.selector,e.element);if(!o)return void a({background:i,ink:s});let l=o.ownerDocument.defaultView,p=()=>{let e=f(o)??i,t=l.getComputedStyle(o).color;a(n=>n.background===e&&n.ink===t?n:{background:e,ink:t})};p();let d=new MutationObserver(p),c=[o,...g(o)],u=e=>{["color","background-color"].includes(e.propertyName)&&e.target===e.currentTarget&&p()};for(let e of c)d.observe(e,{attributes:!0}),e.addEventListener("transitionend",u);let h=l.matchMedia("(prefers-color-scheme: dark)");return h.addEventListener("change",p),l.addEventListener("resize",p),()=>{d.disconnect();for(let e of c)e.removeEventListener("transitionend",u);h.removeEventListener("change",p),l.removeEventListener("resize",p)}},[e,t,i,s,r]),o}var oe=`\n.sp-card button { border: 0; cursor: pointer; font: inherit; }\n.sp-card {\n --sp-control-bg: light-dark(var(--popmelt-thread-soft, #f2f2f2), #363636);\n position: relative;\n align-self: stretch;\n min-width: 0;\n width: 100%;\n margin-top: 6px;\n border-radius: 12px;\n overflow: hidden;\n color: var(--popmelt-thread-primary, #222);\n font:\n 13px/1.38 'Popmelt Geist',\n system-ui,\n sans-serif;\n}\n.sp-card, .sp-workspace {\n color-scheme: light dark;\n background-color: var(--sp-page-background, var(--popmelt-thread-raised, light-dark(#fff, #181818)));\n background-image: radial-gradient(circle, var(--sp-page-dot, light-dark(#f2f2f2, #222222)) 1px, transparent 1.25px);\n background-size: 11px 11px;\n}\n:is(.sp-workspace[data-popmelt-theme='dark'], [data-popmelt-theme='dark'] .sp-card) {\n color-scheme: dark;\n}\n:is(.sp-workspace[data-popmelt-theme='light'], [data-popmelt-theme='light'] .sp-card) {\n color-scheme: light;\n}\n.sp-stage {\n position: relative;\n min-height: 185px;\n display: grid;\n /* The zoom viewport measures this track. Keep captured images and previous\n zoom measurements from increasing its intrinsic minimum width. */\n grid-template-columns: minmax(0, 1fr);\n place-items: center;\n padding: 0;\n}\n.sp-actions,\n.sp-zoom-actions {\n position: absolute;\n z-index: 2;\n top: 6px;\n display: flex;\n gap: 3px;\n opacity: 0;\n pointer-events: none;\n transition: opacity 120ms ease-out;\n}\n.sp-actions {\n right: 6px;\n}\n.sp-zoom-actions {\n left: 6px;\n}\n.sp-card:is(:hover, :has(:focus-visible)) :is(.sp-actions, .sp-zoom-actions),\n.sp-actions[data-preview-active='true'] {\n opacity: 1;\n pointer-events: auto;\n}\n.sp-zoom-actions [role='group'] {\n display: flex;\n gap: 2px;\n}\n.sp-card :is(.sp-actions, .sp-zoom-actions) button {\n color: var(--popmelt-thread-primary, #383838);\n background: var(--sp-control-bg);\n border-radius: 8px;\n width: 28px;\n height: 26px;\n display: grid;\n place-items: center;\n}\n.sp-card .sp-zoom-actions button {\n width: 26px;\n}\n.sp-card .sp-zoom-actions button:disabled {\n color: #aaa;\n cursor: default;\n}\n.sp-card .sp-actions button[aria-pressed='true'] {\n background: var(--sp-accent, #ed1014);\n color: white;\n}\n.sp-card button:focus-visible {\n outline: 2px solid var(--sp-accent, #ed1014);\n outline-offset: 2px;\n}\n.sp-card svg {\n width: 14px;\n height: 14px;\n}\n/* Thread text is selectable by default, including individual spans. */\n.sp-card footer, .sp-card footer * {\n -webkit-user-select: none !important;\n user-select: none !important;\n}\n.sp-card footer {\n font: 14px/1.5 ${W};\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 3px;\n position: absolute;\n inset: auto 0 0;\n z-index: 2;\n padding: 6px;\n pointer-events: none;\n}\n.sp-card .tag-option,\n.sp-card .pager button {\n padding: 3px;\n background: none;\n color: inherit;\n}\n.sp-card .tag-option {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n min-width: 0;\n text-align: left;\n}\n.sp-card .tag-option > span {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.sp-card .tag-option > svg {\n flex: none;\n opacity: 0;\n transition: opacity 120ms ease-out;\n}\n.sp-card .tag-option:is(:hover, :focus-visible) > svg {\n opacity: 1;\n}\n@media (hover: none), (max-width: 480px) {\n .sp-card .tag-option > svg {\n opacity: 1;\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .sp-card .tag-option > svg {\n transition: none;\n }\n}\n.sp-card .pager {\n display: flex;\n align-items: center;\n gap: 3px;\n color: var(--popmelt-thread-primary, #383838);\n white-space: nowrap;\n}\n.sp-card .pager-number {\n font-variant-numeric: tabular-nums;\n}\n.sp-card .pager button {\n width: 22px;\n height: 22px;\n display: grid;\n place-items: center;\n}\n.sp-card footer :is(.tag-option, .pager) {\n pointer-events: auto;\n touch-action: manipulation;\n}\n.sp-card footer .tag-option {\n padding: 0;\n}\n.sp-card .tag-option > span,\n.sp-card .pager {\n box-sizing: border-box;\n min-height: 26px;\n padding: 2px 8px;\n border-radius: 8px;\n background: var(--sp-control-bg);\n}\n.sp-card .tag-option > span {\n align-content: center;\n}\n.sp-card footer .pager {\n padding-inline: 2px;\n touch-action: pan-y pinch-zoom;\n}\n@media (prefers-reduced-motion: reduce) {\n .sp-actions,\n .sp-zoom-actions {\n transition: none;\n }\n}\n@media (hover: none), (max-width: 480px) {\n .sp-actions,\n .sp-zoom-actions {\n pointer-events: auto;\n opacity: 1;\n transition: none;\n }\n}\n\n.sp-expanded-placeholder, .sp-steer-frame { height: 260px; }\n.sp-steer-frame {\n position: relative;\n border: 0;\n display: block;\n width: 100%;\n border-radius: inherit;\n}\n\n/* An expanded card covers the annotation canvas. Its editor takes the free side of the thread. */\n/* Group the toolbar and its popovers above the editor, alongside the thread. */\n:is(body, [data-popmelt-root]):has(> .sp-workspace:not([hidden])) [data-popmelt-toolbar-layer] {\n position: relative;\n z-index: 10004;\n}\n/* Preserve the toolbar's geometry while the active preview covers its controls. */\n[data-popmelt-toolbar-layer][inert] { opacity: 0; }\n.sp-workspace {\n position: fixed;\n inset: 8px;\n overflow: clip;\n box-shadow: 0 0 0 100vmax light-dark(rgb(255 255 255 / 50%), rgb(0 0 0 / 50%));\n}\n.sp-workspace .sp-card {\n position: absolute;\n inset: 0 var(--sp-work-right, 0px) 0 var(--sp-work-left, 0px);\n width: auto;\n display: flex;\n flex-direction: column;\n margin: 0;\n border-radius: 0;\n background: transparent;\n}\n.sp-workspace .sp-stage {\n flex: 1;\n min-height: 0;\n}\n.sp-workspace .sp-steer-frame {\n position: absolute;\n inset: 0;\n height: 100%;\n}\n.sp-workspace :is(.sp-actions, .sp-zoom-actions) {\n top: 12px;\n opacity: 1;\n pointer-events: auto;\n}\n.sp-workspace .sp-actions { right: 12px; }\n.sp-workspace .sp-zoom-actions { left: 12px; }\n.sp-workspace .sp-card footer { padding: 12px; }\n.sp-card .sp-expanded-badge {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n border-radius: 8px;\n min-height: 26px;\n padding: 2px 8px;\n background: var(--sp-control-bg);\n color: inherit;\n}\n[data-popmelt-explore-canvas="right"] .sp-expanded-badge > svg { rotate: 180deg; }\n@media (max-width: 480px) {\n /* Keep the same mounted composer and card; the portal uses the space above them. */\n [data-devtools="thread-panel"][data-popmelt-explore-canvas] {\n top: auto !important;\n height: auto !important;\n padding: 0 !important;\n border: 0 !important;\n background: transparent !important;\n backdrop-filter: none !important;\n }\n [data-popmelt-explore-canvas] [data-popmelt-thread-shell] {\n overflow: visible !important;\n background: transparent !important;\n }\n [data-popmelt-explore-canvas] :is([data-popmelt-thread-header], [data-devtools="thread-panel-messages"], [data-queued-replies-area], [data-scroll-to-bottom]) {\n display: none !important;\n }\n .sp-workspace {\n inset: max(var(--popmelt-thread-visible-top, 8px), env(safe-area-inset-top))\n max(8px, env(safe-area-inset-right))\n calc(max(var(--popmelt-thread-visible-bottom, 8px), env(safe-area-inset-bottom)) + var(--sp-thread-height, 0px) + 6px)\n max(8px, env(safe-area-inset-left));\n }\n .sp-workspace .sp-card { inset: 0; }\n [data-popmelt-explore-canvas] .sp-expanded-badge > svg { rotate: 90deg; }\n}\n`;function ae({anchor:e,surfaceStyle:t,children:n}){let{visible:r}=K(c),o=q(null),[a,i]=U(null);return F(()=>{i(e.current?.closest("[data-popmelt-root]")??document.body)},[e]),F(()=>{if(r&&a)return function(e){let t=e.createElement("style");return t.textContent=":root, body { overflow: hidden !important; overscroll-behavior: none !important; }",e.head.append(t),()=>t.remove()}(a.ownerDocument)},[a,r]),F(()=>{let t=o.current,n=e.current?.closest('[data-devtools="thread-panel"]');if(!t||!n||!r)return;n.dataset.popmeltExploreCanvas="left";let i=a?.querySelector("[data-popmelt-toolbar-layer]"),s=i?.querySelector("#devtools-toolbar"),l=()=>{let e=n.getBoundingClientRect();if(i&&s){let t=s.getBoundingClientRect(),n=e.left<t.right+1&&e.right>t.left-1&&e.top<t.bottom+1&&e.bottom>t.top-1;i.inert=N(window.innerWidth)||n}let r=t.getBoundingClientRect(),o=e.left-r.left>=r.right-e.right;n.dataset.popmeltExploreCanvas=o?"left":"right",t.style.setProperty("--sp-thread-height",`${e.height}px`),t.style.setProperty("--sp-work-left",o?"0px":`${Math.max(0,e.right-r.left)}px`),t.style.setProperty("--sp-work-right",o?`${Math.max(0,r.right-e.left)}px`:"0px"),t.style.borderRadius=getComputedStyle(n).borderRadius,t.dataset.popmeltTheme=n.dataset.popmeltTheme;for(let e of Array.from(n.style))e.startsWith("--popmelt-thread-")&&t.style.setProperty(e,n.style.getPropertyValue(e))};l();let p=new ResizeObserver(l);p.observe(n),s&&p.observe(s);let d=new MutationObserver(l);return d.observe(n,{attributes:!0,attributeFilter:["style","data-popmelt-theme"]}),s&&d.observe(s,{attributeFilter:["style"]}),window.addEventListener("resize",l),()=>{i&&(i.inert=!1),delete n.dataset.popmeltExploreCanvas,p.disconnect(),d.disconnect(),window.removeEventListener("resize",l)}},[e,a,r]),a?Z(_("div",{hidden:!r,ref:o,className:"sp-workspace","data-popmelt-font":"sans",style:{...t,zIndex:10003},children:n}),a):null}function ie({tag:e,framing:t}){let n=q(null);return _("div",{"data-devtools":"preview-feedback-picker",style:{position:"absolute",inset:0,cursor:e?"crosshair":"default",userSelect:"none"},onPointerDown:e=>{n.current=e.isPrimary&&0===e.button?{id:e.pointerId,x:e.clientX,y:e.clientY,dragged:!1}:null},onPointerMove:e=>{let r=n.current;if(r?.id!==e.pointerId)return;let o=e.clientX-r.x,a=e.clientY-r.y;if(!r.dragged&&Math.hypot(o,a)<=8||(r.dragged=!0,r.x=e.clientX,r.y=e.clientY,"touch"!==e.pointerType||t.getScale()<=1))return;let{width:i,height:s}=e.currentTarget.getBoundingClientRect();if(!i||!s)return;let l=t.getView(i,s);t.setView(l.scale,l.x+o/i,l.y+a/s,i,s)},onPointerLeave:()=>{n.current=null},onPointerCancel:()=>{n.current=null},onPointerUp:t=>{let r=n.current;if(n.current=null,r?.id!==t.pointerId||r.dragged||Math.hypot(t.clientX-r.x,t.clientY-r.y)>8||!e)return;let o=t.currentTarget.parentElement?.querySelector(".sp-fit");if(!o)return;let a=T(t.clientX,t.clientY,{within:o})?.closest("[data-scratch-part]");a&&e(a.getAttribute("data-scratch-part"),S(a))}})}function se({capture:e,framing:t}){let n=q(null),[r,o]=U(1);return F(()=>{let r=n.current,a=()=>{let n=Math.max(.01,Math.min(1,(r.clientWidth-36)/e.width,(r.clientHeight-36)/e.height));o(n),t.setFitScale(n)};a();let i=new ResizeObserver(a);return i.observe(r),()=>i.disconnect()},[e,t]),_("div",{className:"sp-steer-frame",ref:n,children:_(i,{interactive:!0,framing:t,overlay:_(ie,{framing:t}),children:_("div",{style:{display:"grid",placeItems:"center",width:"100%",height:"100%"},children:_("img",{alt:"Original at exploration time",src:e.still,draggable:!1,style:{width:e.width*r,height:e.height*r,maxWidth:"none"}})})})})}function le({original:e,bundles:t,target:n,theme:r,accent:o,framing:a,onEscape:i}){let[s,l]=U(!1),{capture:p,runnable:c}=e,u=c&&t?.[c.fixture.bundle];return c&&!s&&"string"!=typeof u?u?_(d,{bundle:u,target:n,readOnly:!0,capture:p,theme:r,accent:o,framing:a,initial:[],onError:()=>l(!0),onEscape:i}):_("div",{className:"sp-steer-frame",role:"status",children:"Loading original…"}):p?.still?_(se,{capture:p,framing:a}):_("div",{className:"sp-steer-frame",role:"status",children:"Original unavailable for this round."})}function pe({frameUrl:e,theme:t,...n}){let[r,o]=U(null);return F(()=>{r&&t&&(r.documentElement.style.colorScheme=t)},[r,t]),F(()=>{if(!r||!n.captureRef)return;let e=()=>{let e=r.querySelector(".sp-fit");return e?async function(e,t){let n=e.ownerDocument;await n.fonts.ready;let r=e.getBoundingClientRect(),o=e.offsetWidth,a=e.offsetHeight;if(!o||!a||!r.width)throw Error("The option is not ready to capture.");let i=r.width/o,s=Array.from(e.children,e=>e.getBoundingClientRect()).filter(e=>e.width&&e.height);s.length||s.push(r);let l,p=Math.max(0,(Math.min(r.right,...s.map(e=>e.left))-r.left)/i-12),d=Math.max(0,(Math.min(r.bottom,...s.map(e=>e.top))-r.top)/i-12),c=Math.min(o,(Math.max(r.left,...s.map(e=>e.right))-r.left)/i+12),u=Math.min(a,(Math.max(r.top,...s.map(e=>e.bottom))-r.top)/i+12),h=await ee(e,{width:o,height:a,scale:Math.min(2,1600/Math.max(o,a)),backgroundColor:t,timeout:2500,style:{transform:"none",position:"static",margin:"0"},onCloneEachNode:e=>{if(1!==e.nodeType)return;let t=e;(t.hasAttribute("data-tagged")||t.hasAttribute("data-badge-hover")||t.hasAttribute("data-scratch-part"))&&(t.style.outline="none"),t.removeAttribute("data-tagged"),t.removeAttribute("data-badge-hover")}});h.sandbox=n.createElement("iframe");try{l=await te(h)}finally{ne(h)}let m=n.createElement("canvas"),g=l.width/o;return m.width=Math.max(1,Math.ceil((c-p)*g)),m.height=Math.max(1,Math.ceil((u-d)*g)),m.getContext("2d").drawImage(l,-p*g,-d*g),new Promise((e,t)=>m.toBlob(n=>n?e(n):t(Error("Could not capture the reviewed option.")),"image/png"))}(e,n.captureBackground??"transparent"):Promise.reject(Error("The option is still loading."))},t=n.captureRef;return t.current=e,()=>{t.current===e&&(t.current=null)}},[r,n.captureRef,n.captureBackground]),$(G,{children:[_("iframe",{className:"sp-steer-frame",style:{colorScheme:t},"aria-label":"Edit or comment on this option",src:e,srcDoc:e?void 0:h,onLoad:e=>{let t=e.currentTarget.contentDocument;t&&V(t),o(t)}}),r&&_(de,{doc:r,...n},n.editorKey)]})}function de({doc:e,...t}){let{toggle:n}=K(c),r=q(t),o=q(t);o.current=t;let a=q(void 0);F(()=>{let t=e.defaultView;if(!t)return;let{node:i,initial:s,target:l,accentColor:p,framing:d}=r.current,c=!0,u=s;a.current=t.startScratchSteer?.(i,l,p,d,e=>{if(!c)return;let t=C(s,e);JSON.stringify(t)!==JSON.stringify(u)&&(u=t,o.current.onChange(t))},e=>{c&&o.current.onTag(e)},e=>{c&&o.current.onPreview(e)},n);let h=e=>{"Escape"!==e.key||!o.current.onEscapeWorkspace||e.target?.closest?.('input, textarea, [contenteditable="true"]')||(e.preventDefault(),e.stopImmediatePropagation(),o.current.onEscapeWorkspace())};return t.addEventListener("keydown",h,!0),()=>{c=!1,a.current=void 0,o.current.onPreview(null),t.removeEventListener("keydown",h,!0)}},[e,n]);let i=E(),[s,l]=U();F(()=>{let t=e.defaultView?.frameElement;if(t instanceof HTMLIFrameElement)return u(t,l,()=>{e.documentElement.setAttribute("data-preview-control-hovered","")})},[e]);let{selectedPart:p,hoveredPart:d,focusRequest:h}=t;return F(()=>{a.current?.({feedbackOnly:i,selectedPart:p,hoveredPart:d,focusRequest:h,controlBounds:s})},[e,n,p,d,h,s,i]),null}function ce(e){!e||e.getRootNode().activeElement?.closest("[data-popmelt-thread-composer]")||e.querySelector("[data-expand-option]")?.focus({preventScroll:!0})}function ue({batch:t,frameUrl:n,bundles:r,canApply:i=!0,frozenVersion:s,framing:l,theme:d,accentColor:c,selection:u,preview:h,setTag:g,onTogglePreview:f,onBrowse:v,edits:b,revisions:x,index:y,hoveredTarget:w,focusRequest:k,onPreviewStyle:C,onFixtureCanvas:S,onSteer:E,onApply:I,busy:T,expanded:O,onExpand:N}){let M=q(null),[H,J]=U(""),[D,W]=U(!1),V=q(null),K=q(null),Y=Q(e=>{K.current=e,ce(e)},[]),X=q(O);F(()=>{X.current&&!O&&ce(V.current),X.current=O},[O]),F(()=>{if(k?.batchId!==t.id||k.option!==y)return;let e=O?K.current:V.current,n=e?.closest('[data-devtools="thread-panel-messages"]');if(!e||!n)return;let r=e.getBoundingClientRect(),o=n.getBoundingClientRect();r.top>=o.top&&r.bottom<=o.bottom||n.scrollBy({top:r.top-o.top-Math.max(0,(n.clientHeight-r.height)/2),behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":"smooth"})},[t.id,y,k,O]);let Z=JSON.stringify([t.id,y,s??x?.[y]??0]),[ee]=U(()=>l??o(null)),te=t.options.length,ne=-1===y?t.original:void 0,ie=t.options[Math.max(0,y)],{background:se,ink:de}=re(t.target,ne?.capture?.scope??("fixture"in ie?ie.previewScope:void 0),t.original?.capture,!!ne),ue=se?m(se):void 0,me=ue?.theme??d,ge={"--sp-page-background":se,"--sp-accent":c,"--sp-page-dot":ue?.dot,backgroundImage:ne?"none":void 0},fe={batchId:t.id,option:y,path:[]},ve=h?.showVariant&&h.target.batchId===t.id&&h.target.option===y;let be="fixture"in ie?r?.[ie.fixture.bundle]:void 0,xe=_(he,{title:ne?"Original":ie.title,index:ne?-1:y,hasOriginal:!!t.original,optionCount:te,accentColor:c,canTag:i,onTag:()=>g(fe),browseBy:function(e){let n=t.original?-1:0,r=te-n,o=n+(y-n+e+r)%r;J(""),v({...fe,option:o})}}),ye=$("div",{className:"sp-stage",style:{cursor:P(c)},children:[_("div",{className:"sp-zoom-actions",children:_(a,{framing:ee})}),$("div",{className:"sp-actions","data-preview-active":!!h,children:[!ne&&ve&&i&&_(j,{type:"button","aria-label":"Apply this option in code",disabled:T||D,onClick:async()=>{J(""),W(!0);try{if(!M.current)throw Error("The option is still loading. Try again in a moment.");let e=await M.current();await I(fe,e)}catch(e){J(e instanceof Error?e.message:"Could not apply this option.")}finally{W(!1)}},children:_(A,{})}),!s&&(!ne||!!h)&&_(j,{type:"button","aria-pressed":!!h,hint:!O&&h?"Turn off page preview":"Preview on page","aria-label":"Preview on page",disabled:"fixture"in ie&&(!be||"string"==typeof be),onClick:()=>f(fe),children:_(R,{})}),_(j,{type:"button","data-expand-option":"","aria-label":O?"Collapse preview":"Expand preview","aria-expanded":O,onClick:()=>N(!O),children:_(O?z:B,{})})]}),ne?_(le,{original:ne,target:t.target,bundles:r,framing:ee,theme:me,accent:c,onEscape:O?()=>N(!1):void 0}):"fixture"in ie?_(p,{captureRef:M,captureBackground:se??void 0,frameKey:Z,frozenParent:!!s,readOnly:!!s,capture:s?t.original?.capture:void 0,bundle:be,previewScope:ie.previewScope,target:t.target,pageInk:se?de:void 0,framing:ee,theme:me,accent:c,initial:b.filter(e=>e.batchId===t.id&&e.option===y),onCanvas:e=>S?.(ie.fixture.bundle,e),onEscape:O?()=>N(!1):void 0,selected:u?.batchId===t.id&&u.option===y?u.fixturePart:void 0,onTag:(e,t)=>g({...fe,fixturePart:e,fixturePartLabel:t}),onChange:e=>E(y,e),onPreview:e=>C(y,e)}):_(pe,{captureRef:M,captureBackground:se??void 0,editorKey:Z,readOnly:!!s,framing:ee,onEscapeWorkspace:O?()=>N(!1):void 0,frameUrl:n,target:t.target,node:ie.root,theme:me,accentColor:c,initial:b.filter(e=>e.batchId===t.id&&e.option===y),onPreview:e=>C(y,e),hoveredPart:w?.batchId===t.id&&w.option===y?w.part:void 0,focusRequest:k?.batchId===t.id&&k.option===y?k:void 0,selectedPart:u?.batchId===t.id&&u.option===y?u.path.join(".")+(u.field?"/label":""):void 0,onChange:e=>E(y,e),onTag:e=>{let[t,n]=e.split("/");g({...fe,path:t?t.split(".").map(Number):[],field:"label"===n?"label":void 0})}}),H&&_("span",{role:"alert",children:H}),xe]});return $(G,{children:[$("section",{ref:V,"data-explore-batch":t.id,"aria-label":"Explore options",className:"sp-card",style:ge,"data-popmelt-tooltip-group":"",children:[_("style",{children:oe}),O?$("div",{className:"sp-stage sp-expanded-placeholder",children:[$(j,{type:"button",className:"sp-expanded-badge",hint:"Collapse preview","aria-label":"Preview expanded. Collapse preview","aria-expanded":!0,onClick:()=>N(!1),children:[_(L,{"aria-hidden":"true"}),"Preview expanded"]}),xe]}):ye]}),!ne&&"fixture"in ie&&ie.rationale&&_(e,{text:ie.rationale}),O&&_(ae,{anchor:V,surfaceStyle:ge,children:_("section",{ref:Y,"aria-label":"Expanded explore options",className:"sp-card","data-popmelt-tooltip-group":"","data-popmelt-tooltip-boundary":!0,children:ye})})]})}function he({title:e,index:t,optionCount:n,hasOriginal:r,accentColor:o,onTag:a,canTag:i,browseBy:s}){let l=q(null),p=q(null);return $("footer",{children:[t<0?_("span",{className:"tag-option",children:_("span",{children:e})}):$(j,{above:!0,className:"tag-option",disabled:!i,hint:"Add to chat",anchorRef:l,"aria-label":`Add ${e} to chat`,onClick:a,children:[_("span",{children:e}),_(H,{ref:l,"aria-hidden":"true",color:o})]}),(r||n>1)&&$("div",{className:"pager",onTouchStart:e=>{let t=e.touches[0];p.current=1===e.touches.length?{id:t.identifier,x:t.clientX,y:t.clientY}:null},onTouchCancel:()=>{p.current=null},onTouchEnd:e=>{let t=p.current;p.current=null;let n=e.changedTouches[0];if(!t||!n||n.identifier!==t.id||e.touches.length)return;let r=n.clientX-t.x,o=n.clientY-t.y;Math.abs(r)<24||Math.abs(r)<1.3*Math.abs(o)||(e.preventDefault(),s(r>0?1:-1))},children:[_("button",{type:"button","aria-label":"Previous option",onClick:()=>s(-1),children:_(J,{})}),$("span",{"aria-live":"polite",children:[_("span",{className:"pager-number",children:t+1})," of"," ",_("span",{className:"pager-number",children:n})]}),_("button",{type:"button","aria-label":"Next option",onClick:()=>s(1),children:_(D,{})})]})]})}function me(e,t,n){return`popmelt-explore-draft:${e}:${t}:${n}`}function ge(e,t,n,r,o){try{let a=me(e,t,n);void 0!==o?window.localStorage.setItem(a,JSON.stringify({revision:o,edits:r})):r.length?window.localStorage.setItem(a,JSON.stringify(r)):window.localStorage.removeItem(a)}catch{}}function fe(e,t,n,r){try{let o=me(e,t,n),a=window.localStorage.getItem(o);if(!a)return;let i=JSON.parse(a),s=Array.isArray(i)?{revision:0,edits:i}:i;s.revision===r.revision&&JSON.stringify(s.edits.map(k))===JSON.stringify(r.edits)&&window.localStorage.removeItem(o)}catch{}}var ve={edits:[]};function be(e,t,n,r,o){let[a]=U(()=>function(e,t){let n={};return t.options.forEach((r,o)=>{try{let r=window.localStorage.getItem(me(e,t.id,o));if(!r)return;let a=JSON.parse(r),{revision:i,edits:s}=Array.isArray(a)?{revision:0,edits:a}:a;if(!Number.isSafeInteger(i)||i<0||!Array.isArray(s))return;let l=s.map(k);if(l.some(e=>e.batchId!==t.id||e.option!==o))return;b({messages:[{batch:t}]},x(l)),n[o]={revision:i,edits:l}}catch{}}),n}(e,t)),[i,s]=U(()=>({...n,...a})),l=q(i),p=q({...n}),d=q({...a}),c=q(new Set),u=q(new Map),[h,m]=U({}),[g,f]=U(""),v=o&&void 0!==n;function y(e,t,n){let r=l.current[e]??ve;l.current={...l.current,[e]:t},JSON.stringify(r.edits)!==JSON.stringify(t.edits)&&(s(l.current),n&&m(t=>({...t,[e]:(t[e]??0)+1})))}async function w(n){if(v&&!c.current.has(n)){c.current.add(n);try{for(;d.current[n];){let o=d.current[n],a=await M(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({batchId:t.id,option:n,...o})});if(!a.ok&&409!==a.status)throw Error();let{draft:i}=await a.json();if(!i||!Number.isSafeInteger(i.revision)||!Array.isArray(i.edits))throw Error();i.revision>=(p.current[n]?.revision??0)&&(p.current[n]=i);let s=d.current[n];409===a.status||s===o?(delete d.current[n],fe(e,t.id,n,s),y(n,p.current[n],!0),f(409===a.status?"This option changed on another device. Its latest saved edits are shown.":"")):(s.revision=i.revision,ge(e,t.id,n,s.edits,s.revision))}}catch{f("Couldn’t sync option edits to this project.")}finally{c.current.delete(n)}}}let C=()=>Object.keys(d.current).forEach(e=>{w(Number(e))}),S=q(C);return F(()=>{S.current=C}),F(()=>{if(n)for(let[e,t]of Object.entries(n)){let n=Number(e);t.revision<(p.current[n]?.revision??0)||(p.current[n]=t,d.current[n]||y(n,t,!0))}},[n]),X(()=>{if(!v)return;let e=()=>S.current();e(),window.addEventListener("online",e);let t=u.current;return()=>{window.removeEventListener("online",e);for(let e of t.values())clearTimeout(e);t.clear(),e()}},[v]),{edits:Y(()=>Object.values(i).flatMap(e=>e.edits),[i]),save:function(n,r){let o=d.current[n]?.revision??p.current[n]?.revision??0,a={revision:o,edits:r.map(k)};JSON.stringify(l.current[n]?.edits??[])!==JSON.stringify(a.edits)&&(d.current[n]=a,ge(e,t.id,n,a.edits,o),y(n,a,!1),v&&(clearTimeout(u.current.get(n)),u.current.set(n,setTimeout(()=>{u.current.delete(n),w(n)},220))))},revisions:h,failure:g,retry:C,unsynced:!!Object.keys(d.current).length}}function xe({batch:e,draftScope:a,threadId:i,sharedDrafts:p,bridgeUrl:d,theme:c,accentColor:u,active:h,hidden:m,revealOnPage:g,activate:f,expanded:k,onExpand:C,canReply:S,submit:E,selection:P,onAttach:T,focusRequest:O,workspaceRef:N,followSource:j}){let M=s(d,v(e)),A=K(I),R=A?.preview?.batchId===e.id&&A.preview.threadId===i?A.preview:null,z=A?!!R?.enabled:h,[B,L]=U(()=>R?.index??0),H=q(null);F(()=>{H.current!==O&&(H.current=O,O&&O.batchId===e.id&&e.options[O.option]&&L(O.option))},[O,e.id,e.options]);let J=Y(()=>O?{...O,part:""}:null,[O]),D=be(a,e,p,d+"/thread/"+encodeURIComponent(i)+"/explore-draft",S),[W,V]=U(),X=O!==W&&O?.option===B?O.snapshot:void 0,Q=X?.edits??D.edits,[Z]=U(()=>o(null)),ee=Y(()=>k&&!m&&!X&&B>=0?{batchId:e.id,option:B}:null,[k,m,X,e.id,B]),[te,ne]=U(R?.targets??null),[re,oe]=U(()=>R&&"fixture"in R.option?{[R.option.fixture.bundle]:R.hasCanvas}:{}),[ae,ie]=U(""),[se,le]=U(null),pe=Y(()=>b({messages:[{batch:e}]},x(Q)).messages[0].batch,[e,Q]);F(()=>{if(!ee)return;let e={source:ee,framing:Z,reference:()=>n(pe,{...ee,path:[]},Q)};return N.current=e,()=>{N.current===e&&(N.current=null)}},[N,ee,Z,pe,Q]),F(()=>{let t=N.current;if(!t||t.source!==j)return;let n=e.options.findIndex((n,r)=>{let o=e.parents?.[r];return o?.batchId===t.source.batchId&&o.option===t.source.option&&(!("fixture"in n)||"object"==typeof M[n.fixture.bundle])});n<0||(Z.restore(t.framing.snapshot()),L(n),C(!0))},[e,M,j,Z,C,N]);let de=pe.options[Math.max(0,B)],ce=e=>"fixture"in de?w(e,de.previewScope,!!re[de.fixture.bundle]):e.element,he=B>=0&&te&&ce(te),me="fixture"in de&&"component"===de.previewScope?"Core could not locate a single root for this component on the page. You can still review the option here.":"Open the annotated page with its target visible to preview this option.",ge="fixture"in de?M[de.fixture.bundle]??(R&&"fixture"in R.option&&R.option.fixture.bundle===de.fixture.bundle?R.bundle:void 0):void 0,fe=Y(()=>{let t=x(Q)[e.id]?.[B]??{},n={...t};if(se?.option===B)for(let[e,r]of Object.entries(se.parts))n[e]={...t[e],...r};return n},[Q,e.id,B,se]),ve="fixture"in de&&!!re[de.fixture.bundle],xe=Y(()=>te?{threadId:i,batchId:e.id,index:B,enabled:!0,target:e.target,option:de,targets:te,hasCanvas:ve,bundle:"string"==typeof ge?void 0:ge,parts:fe,theme:c,accentColor:u,revealOnPage:g}:null,[i,e.id,e.target,B,de,te,ve,ge,fe,c,u,g]),ye=!!R,we=A?.setPreview;F(()=>{X||!ye||!xe||!we||we(t=>t?.batchId===e.id&&t.threadId===i?{...xe,enabled:t.enabled,suspended:t.suspended}:t)},[X,ye,xe,we,e.id,i]);let ke=()=>{we?.(t=>t?.batchId===e.id&&t.threadId===i?{...t,enabled:!1}:t),f(!1)},Ce=z?{target:{batchId:e.id,option:B,path:[]},showVariant:B>=0}:null,Se=e.parents?.[B];return $(G,{children:[_(ue,{batch:pe,framing:Z,bundles:M,index:B,edits:Q,theme:c,accentColor:u,selection:P,preview:Ce,expanded:k&&!m,onExpand:C,revisions:D.revisions,focusRequest:J,hoveredTarget:null,busy:!1,canApply:S&&!X,frozenVersion:X?O?.returnTo:void 0,onTogglePreview:()=>{if(ie(""),Ce&&!k)return void ke();let t=y(e.target),n=location.pathname===e.target.pathname&&ce(t);n&&n.parentElement&&!n.matches("body,html")&&!n.closest("[data-devtools]")?(ne(t),we?.({threadId:i,batchId:e.id,index:B,enabled:!0,target:e.target,option:de,targets:t,hasCanvas:ve,bundle:"string"==typeof ge?void 0:ge,parts:fe,theme:c,accentColor:u,revealOnPage:g}),C(!1),f(!0)):ie(me)},onBrowse:e=>{V(O),L(e.option),le(null)},onFixtureCanvas:(e,t)=>oe(n=>n[e]===t?n:{...n,[e]:t}),onPreviewStyle:(e,t)=>le(n=>t?{option:e,parts:t}:n?.option===e?null:n),onSteer:(t,n)=>{if(X)return;let r=n.map(n=>({...n,batchId:e.id,option:t}));D.save(t,r)},setTag:e=>{S&&!X&&T(n(pe,e,Q))},onApply:async(e,n)=>{let{text:r,meta:o}=t(pe,e.option,Q);if(!await E(r,n?{...o,exploreOption:{...o.exploreOption,selection:{...o.exploreOption.selection,reviewedImage:{replyImageIndex:0,capturedAt:Date.now(),description:"The attached image shows this reviewed option with its saved edits. Use it as the visual target to apply; the original annotation screenshot is earlier context."}}}}:o,n?[n]:void 0))throw Error("This thread cannot send the apply request.");ke(),C(!1)}}),X&&O?.returnTo?$("span",{children:["Parent version ·"," ",_(r,{reference:O.returnTo,children:"Back to iteration"})]}):Se?$("span",{children:["Based on"," ",_(r,{reference:{...Se,snapshot:Se,returnTo:{batchId:e.id,option:B,title:de.title}},showVersion:!0})]}):null,D.failure&&$("span",{role:"alert",children:[D.failure," ",D.unsynced&&_("button",{type:"button",onClick:D.retry,children:"Retry"})]}),(ae||z&&B>=0&&!m&&te&&!he)&&_("span",{role:"alert",children:ae||me}),!A&&!X&&z&&!m&&xe&&_(l,{preview:xe})]})}export{xe as ExploreAttachment};
@@ -0,0 +1 @@
1
+ "use client";export{f as PagePreviewLayer}from"./chunk-MDPZUECK.mjs";import"./chunk-OFJUTWJU.mjs";import"./chunk-PWQB3FIW.mjs";import"./chunk-Q6N77LIS.mjs";import"./chunk-ZVDKW7TO.mjs";import"./chunk-FHCKFQBY.mjs";import"./chunk-APP5IYTE.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-WP2SHSCG.mjs";import"./chunk-LH7HKUCK.mjs";import"./chunk-Q6C7ZA3H.mjs";import"./chunk-NI77Y3WC.mjs";import"./chunk-FON4QY7P.mjs";import"./chunk-AGCS65LT.mjs";import"./chunk-SUAHDXJZ.mjs";
@@ -0,0 +1 @@
1
+ "use client";import{d as t,b as e,c as o,a as r}from"./chunk-TQ3SP5TE.mjs";import"./chunk-JLK3VRBT.mjs";import"./chunk-JCW2WY7X.mjs";import{e as i}from"./chunk-4OEHQ6M7.mjs";import"./chunk-LOUWY55X.mjs";import"./chunk-PH2MLB3T.mjs";import"./chunk-ZVDKW7TO.mjs";import"./chunk-XTOCFTVW.mjs";import"./chunk-XY7YW7SH.mjs";import"./chunk-SOGN7S54.mjs";import"./chunk-YVT3J6JB.mjs";import"./chunk-EZVFCJEG.mjs";import"./chunk-IAXSC2ZN.mjs";import"./chunk-PILMDBAX.mjs";import{a as n}from"./chunk-I7AI52RX.mjs";import{i as a,Y as s}from"./chunk-DRPRASD6.mjs";import"./chunk-B22WBEQC.mjs";import"./chunk-CIA6WVXQ.mjs";import"./chunk-G2ZHJXHZ.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-76WRZ2NH.mjs";import"./chunk-AGYBVMHX.mjs";import"./chunk-YYFF2X3L.mjs";import"./chunk-L6S66APQ.mjs";import"./chunk-FJWWBKCQ.mjs";import"./chunk-RK6UROPO.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-HAZXZ5TU.mjs";import"./chunk-JEGBAHYK.mjs";import"./chunk-I6FJ533W.mjs";import"./chunk-W2QQVB2H.mjs";import"./chunk-WP2SHSCG.mjs";import{e as c,g as p,f as m}from"./chunk-AAMUU2QA.mjs";import"./chunk-LH7HKUCK.mjs";import{a as l}from"./chunk-4YQWU5YB.mjs";import{b as h,f as u,c as d,d as f}from"./chunk-3VOEPWRL.mjs";import{o as j}from"./chunk-BVGHHT3Y.mjs";import"./chunk-X6I6KQDG.mjs";import"./chunk-ATLUO4G7.mjs";import"./chunk-Q6C7ZA3H.mjs";import"./chunk-SOT33EQ4.mjs";import"./chunk-C2ZSNUXQ.mjs";import"./chunk-EBJ23A7F.mjs";import"./chunk-EILBHZDX.mjs";import"./chunk-XJJDBMZI.mjs";import"./chunk-OREALBUO.mjs";import"./chunk-B4DYUYX4.mjs";import"./chunk-CK3CDA3L.mjs";import{c as k,a as g}from"./chunk-NI77Y3WC.mjs";import"./chunk-FON4QY7P.mjs";import{U as w}from"./chunk-OA63PYHZ.mjs";import"./chunk-ECMLCGAM.mjs";import"./chunk-PRPXMDZ7.mjs";import"./chunk-A4GARXVQ.mjs";import"./chunk-AGCS65LT.mjs";import{b as v}from"./chunk-SUAHDXJZ.mjs";import{useState as S,useSyncExternalStore as y,useEffect as I}from"react";import{jsx as A,jsxs as O}from"react/jsx-runtime";function H(t,i){let n,a={phase:"starting"},l=0,j=!1,k=!1,g=0,w=new Set,S=`popmelt-participant:${t.projectId}`,y=new h(t.url,t.projectId),I=t=>{if(!k){a=t;for(let t of w)t()}},A=async(e={},o=!1)=>{if(v(t.url))return null;let r=await fetch("/__popmelt/host",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(e),redirect:"error"});if(403===r.status){let e=r.headers.get("X-Popmelt-Host-Origin"),i=r.headers.get("X-Popmelt-Session");if(o&&e&&i&&window.top===window&&function(t,e){try{let o=new URL(t),r=new URL(e),i=["localhost","127.0.0.1","[::1]"];return o.origin===t&&r.origin===e&&t!==e&&["http:","https:"].includes(o.protocol)&&o.protocol===r.protocol&&o.port===r.port&&i.includes(o.hostname)&&i.includes(r.hostname)}catch{return!1}}(location.origin,e)&&!location.hash.includes("popmelt-")&&!localStorage.getItem(`popmelt-admission:${t.projectId}`)){let t=await fetch(e+"/__popmelt/host",{method:"HEAD",credentials:"omit",redirect:"error",referrerPolicy:"no-referrer",signal:AbortSignal.timeout(2e3)}).catch(()=>null);if(!k&&204===t?.status&&t.headers.get("X-Popmelt-Session")===i){let t=new URL(location.href);throw t.host=new URL(e).host,location.replace(t.href),O}}return null}if(!r.ok)throw new Error(`Host entry unavailable (${r.status}).`);let i=`popmelt-before-participants:${t.projectId}`;return null===localStorage.getItem(i)&&localStorage.setItem(i,JSON.stringify(Object.fromEntries(Object.values(s(t.projectId)).map(t=>[t,localStorage.getItem(t)])))),await r.json()},O=Symbol("navigating"),H=async(a,s=g)=>{if(k||s!==g)return;let l=await r({bridgeUrl:t.url,projectId:t.projectId,credential:a,runtimeStorage:sessionStorage,observedSource:{sourceId:t.projectId,revision:t.revision},loadOwnSource:i,prepareApplication:t.planeApps?async r=>{if(k||s!==g)throw O;let i=c(location.pathname);if(r.author.id===a.participantId&&"host"===r.author.relationship&&!v(t.url)){if("/"!==i){let t=new URL(location.href);throw t.pathname=m(t.pathname),location.replace(t.href),O}return("/"===r.ownWorkspace?.basePath?r.ownWorkspace.revision:void 0)??r.draft.source?.revision??t.revision}let n=await e(a,a.participantId,void 0,location.pathname);if(k||s!==g)throw O;let l=o(n.application);if(t.appVersion??(t.appVersion=n.application.version),l!==p(location.pathname)||t.appVersion&&t.appVersion!==n.application.version)throw localStorage.setItem(S,JSON.stringify(a)),location.replace(l+location.search+location.hash),O;return n.application.basis??t.revision}:void 0}).catch(t=>{if(t!==O)throw t});if(l){if(k||s!==g)return void l.dispose();try{localStorage.setItem(S,JSON.stringify(a))}catch(t){throw l.dispose(),t}n?.dispose(),n=l,I({phase:"connected",connection:l}),A({credential:a}).catch(()=>{})}},P=()=>{g++,n?.dispose(),n=void 0,function(t,e){t.removeItem(`popmelt-participant:${e}`);let o,r=`popmelt-admission:${e}`;try{o=JSON.parse(t.getItem(r)??"null")}catch{return void t.removeItem(r)}o&&"object"==typeof o&&t.setItem(r,JSON.stringify({name:o.name,colorIdentity:o.colorIdentity??o.receipt}))}(localStorage,t.projectId),I({phase:"entry",invitation:null})};return{client:y,getSnapshot:()=>a,subscribe:t=>(w.add(t),()=>{w.delete(t)}),retain(){if(k)throw new Error("Participant lifecycle is disposed");l++,j||(j=!0,(async()=>{let t=u(location.href),e=new URL(t.cleanUrl),o=new URLSearchParams(e.hash.slice(1)),r=o.get("popmelt-host");o.delete("popmelt-host"),r&&(e.hash=o.toString()),e.href!==location.href&&history.replaceState(history.state,"",e);let i=null;if(r){if(i=await A({token:r}),!i)throw new Error("Host entry expired. Use the current private host link.")}else if(!t.token){try{i=JSON.parse(localStorage.getItem(S)??"null")}catch{}i??(i=await A({},!0))}if(k)return;if(!i)return void I({phase:"entry",invitation:t.token??null});let n=g;for(let t=1;!k&&n===g;t++)try{return void await H(i,n)}catch(e){if(k||n!==g)return;if(d(e)){I({phase:"error",message:e.message}),await new Promise(e=>setTimeout(e,f(t)));continue}if("access_removed"===e.code)return void P();if(401!==e.status)throw e;let o=await A();return void(o?await H(o):P())}})().catch(t=>{t!==O&&I({phase:"error",message:t.message})}));let t=!1;return()=>{t||(t=!0,l--,queueMicrotask(()=>{l||k||(k=!0,g++,n?.dispose(),n=void 0,w.clear())}))}},removed:P,async join(e,o){if("entry"!==a.phase||!a.invitation||k)throw new Error("No active invitation");if(!o)throw new Error("Peer identity is not ready");let r=g,i=await y.joinOrRequestAdmission(a.invitation,e,o);if(!k&&r===g){if("admission"in i)return localStorage.setItem(`popmelt-admission:${t.projectId}`,JSON.stringify({name:i.admission.name,receipt:o,colorIdentity:o})),void I({phase:"entry",invitation:null});await H(i.joined.credential,r)}},admit:t=>H(t)}}function P({config:r,loadOwnSource:s,children:m}){let[h]=S(()=>H(r,s)),u=a(),d=y(h.subscribe,h.getSnapshot,h.getSnapshot);I(()=>h.retain(),[h]);let[f,P,b]=k(),U="connected"===d.phase?d.connection:null;if(I(()=>{if(!U||!r.planeApps)return;let t,i=new AbortController,n=U.isHost&&!v(r.url)&&"/"===c(location.pathname),a=n?void 0:r.appVersion,s=async()=>{try{let t=await e(U.credential,U.credential.participantId,i.signal,location.pathname);if(n&&"/"!==t.application.basePath)throw new Error("Host checkout unavailable");let s=o(t.application);if(a??(a=t.application.version),!i.signal.aborted&&(s!==p(location.pathname)||t.application.version!==a)){if(U.isHost&&!v(r.url)){let t=await fetch(s+location.search,{method:"HEAD",headers:{Accept:"text/html"},mode:"same-origin",cache:"no-store",signal:i.signal});if(!t.ok||!t.headers.get("content-type")?.includes("text/html")||p(new URL(t.url).pathname)!==s)throw new Error("Host plane document unavailable")}return await U.state.flush(),void(i.signal.aborted||(s===p(location.pathname)?location.reload():location.replace(s+location.search+location.hash)))}}catch{}i.signal.aborted||(t=setTimeout(s,1500))};return s(),()=>{i.abort(),clearTimeout(t)}},[r.planeApps,r.appVersion,r.url,U,u]),U)return A(t,{connection:U,codePreviewUrl:location.href,planeApps:r.planeApps,onAccessRemoved:h.removed,children:m});let X="starting"===d.phase||"error"===d.phase,E="entry"===d.phase?d.invitation:null;return A(n,{children:A("div",{"data-devtools":"participant-entry",style:{display:"contents",pointerEvents:"auto"},children:X?A(i,{entry:{theme:f,themePreference:b,onThemePreferenceChange:P,ariaLabel:"starting"===d.phase?"Popmelt connecting":"Popmelt disconnected",action:null,logoOnly:!0,connected:!1,connection:O("span",{"data-popmelt-entry-content":!0,role:"status",style:{...j(g[f],!1),cursor:"default"},children:[A(w,{size:14,strokeWidth:1.5,"aria-hidden":"true"}),"starting"===d.phase?"Connecting…":"Disconnected"]})}}):A(l,{client:h.client,storage:localStorage,storageKey:`popmelt-admission:${r.projectId}`,theme:f,themePreference:b,onThemePreferenceChange:P,onAdmitted:h.admit,onJoin:E?h.join:void 0},E??"request-access")})})}export{P as default};
@@ -0,0 +1 @@
1
+ "use client";import{a as r,d as t}from"./chunk-TQ3SP5TE.mjs";import"./chunk-JLK3VRBT.mjs";import"./chunk-JCW2WY7X.mjs";import"./chunk-XY7YW7SH.mjs";import"./chunk-SOGN7S54.mjs";import"./chunk-YVT3J6JB.mjs";import"./chunk-PILMDBAX.mjs";import"./chunk-DRPRASD6.mjs";import"./chunk-B22WBEQC.mjs";import"./chunk-CIA6WVXQ.mjs";import"./chunk-G2ZHJXHZ.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-76WRZ2NH.mjs";import"./chunk-AGYBVMHX.mjs";import"./chunk-YYFF2X3L.mjs";import"./chunk-L6S66APQ.mjs";import"./chunk-FJWWBKCQ.mjs";import"./chunk-RK6UROPO.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-HAZXZ5TU.mjs";import"./chunk-JEGBAHYK.mjs";import"./chunk-I6FJ533W.mjs";import"./chunk-W2QQVB2H.mjs";import"./chunk-WP2SHSCG.mjs";import"./chunk-AAMUU2QA.mjs";import"./chunk-LH7HKUCK.mjs";import"./chunk-3VOEPWRL.mjs";import"./chunk-EILBHZDX.mjs";import"./chunk-XJJDBMZI.mjs";import"./chunk-OREALBUO.mjs";import"./chunk-B4DYUYX4.mjs";import"./chunk-CK3CDA3L.mjs";import"./chunk-NI77Y3WC.mjs";import{b as o}from"./chunk-FON4QY7P.mjs";import"./chunk-OA63PYHZ.mjs";import"./chunk-ECMLCGAM.mjs";import"./chunk-PRPXMDZ7.mjs";import{d as n,f as i,c as m,a as e}from"./chunk-AGCS65LT.mjs";import"./chunk-SUAHDXJZ.mjs";import{useState as c,useEffect as s,cloneElement as p}from"react";import{jsxs as h,jsx as u}from"react/jsx-runtime";function j({children:j,projectId:a,participantConfig:k}){let[l,d]=c(null),[I,A]=c("");if(s(()=>{let t,m,c=!1;return d(null),A(""),n(a).then(async n=>{if(c)return;let s=location.origin+e;m=i(s,n);let p=await o(s+"/status",{signal:AbortSignal.timeout(6e3)}),h=p.ok?await p.json():null;if(h?.projectId!==n.projectId)throw new Error("Phone access expired. Create a fresh pairing link in the project terminal.");if(!c){if(h.phoneParticipantId)t=await r({projectId:n.projectId,bridgeUrl:s,credential:{participantId:h.phoneParticipantId,token:""},runtimeStorage:sessionStorage,observedSource:{sourceId:n.projectId,revision:k?.revision??"unversioned"}});else if(k)throw new Error("This phone is not connected to the multiplayer host.");c?t?.dispose():d({bridgeUrl:s,projectId:n.projectId,connection:t})}}).catch(r=>{m?.(),c||A(r instanceof Error?r.message:"Phone pairing failed.")}),()=>{c=!0,t?.dispose(),m?.()}},[a,k]),I)return h("p",{role:"alert","data-devtools":"phone-pairing-error",children:[I," ",u("button",{type:"button",onClick:m,children:"Forget this pairing"})]});if(!l)return null;let H=p(j,{bridgeUrl:l.bridgeUrl,projectId:l.projectId});return l.connection?u(t,{connection:l.connection,onAccessRemoved:m,children:H}):H}export{j as PhoneHostGate};