@popmelt.com/core 0.41.1 → 0.42.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.
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/codex-plugin/.codex-plugin/plugin.json +1 -1
- package/codex-plugin/assets/popmelt-logo.svg +1 -1
- package/dist/{ExploreAttachment-PTK4YHVE.mjs → ExploreAttachment-TRA62BMX.mjs} +1 -1
- package/dist/PagePreviewLayer-TX74TJBY.mjs +1 -0
- package/dist/ParticipantRuntime-Y7MKLWBC.mjs +1 -0
- package/dist/PhoneHostGate-XRYFSUJA.mjs +1 -0
- package/dist/{PopmeltProvider-5g-1VH5a.d.mts → PopmeltProvider-NwqjKtGG.d.mts} +1 -1
- package/dist/PopmeltTasteConnectedPane-NMKIRMDM.mjs +1 -0
- package/dist/{PreviewRuntime-7EQNIOF5.mjs → PreviewRuntime-VJXFECBF.mjs} +1 -1
- package/dist/{QueuedReplies-ESF5UL3J.mjs → QueuedReplies-X2N4JRS6.mjs} +1 -1
- package/dist/SamplePlacementOverlay-VWCULP2R.mjs +1 -0
- package/dist/ShareProjectPane-L6AO57IN.mjs +1 -0
- package/dist/SuppliedContext-UGQSL4IG.mjs +1 -0
- package/dist/{ThreadErrorCard-QGTWIV7B.mjs → ThreadErrorCard-WSNEGY7J.mjs} +1 -1
- package/dist/ThreadPanel-QNDCQOA4.mjs +1 -0
- package/dist/adapter-react-three-fiber.d.mts +1 -1
- package/dist/adapter-three.d.mts +1 -1
- package/dist/bridge-entry.mjs +1 -1
- package/dist/{bridgeSSEStream-2KKFO64A.mjs → bridgeSSEStream-BHUFYHTT.mjs} +1 -1
- package/dist/{bridgeWebSocketStream-XTHQPBPI.mjs → bridgeWebSocketStream-L277I5ZX.mjs} +1 -1
- package/dist/browser-runtime-3PAM2ZUE.mjs +1 -0
- package/dist/browser.d.mts +4 -4
- package/dist/browser.mjs +1 -1
- package/dist/{canvas-chat-note-XMVKWL2J.mjs → canvas-chat-note-HTK23RYE.mjs} +1 -1
- package/dist/canvas-text.d.mts +1 -1
- package/dist/{checkFixture-VWHN4ZNH.mjs → checkFixture-C26VSTGP.mjs} +1 -1
- package/dist/chunk-23YWKAQM.mjs +1 -0
- package/dist/chunk-2OWGUAUI.mjs +1 -0
- package/dist/{chunk-YTIDSDPP.mjs → chunk-2PARHFWP.mjs} +1 -1
- package/dist/chunk-2YT4X5VC.mjs +1 -0
- package/dist/{chunk-DMKBAI2Z.mjs → chunk-47SWWW5Y.mjs} +1 -1
- package/dist/chunk-56AALMHI.mjs +1 -0
- package/dist/chunk-5JAZXI47.mjs +1 -0
- package/dist/chunk-5SXPTNUM.mjs +1 -0
- package/dist/chunk-5YNIYMKX.mjs +1 -0
- package/dist/{chunk-EWNSX5BF.mjs → chunk-7PZN2RNE.mjs} +1 -1
- package/dist/chunk-ALW6WNDJ.mjs +1 -0
- package/dist/{chunk-ADRWR5GI.mjs → chunk-BH5BNULT.mjs} +1 -1
- package/dist/chunk-BZPWT44Z.mjs +1 -0
- package/dist/chunk-DAMF6ZWZ.mjs +1 -0
- package/dist/chunk-E7VH7WB5.mjs +1 -0
- package/dist/chunk-EBESPLST.mjs +1 -0
- package/dist/{chunk-7D4BUDKG.mjs → chunk-ECGXE2Z6.mjs} +1 -1
- package/dist/chunk-EEU5J3CD.mjs +1 -0
- package/dist/chunk-FGJX74DI.mjs +1 -0
- package/dist/chunk-I3LFTKJP.mjs +1 -0
- package/dist/chunk-K4CIGHJI.mjs +1 -0
- package/dist/chunk-KYS76O3N.mjs +1 -0
- package/dist/{chunk-77DD4HQE.mjs → chunk-LB66O2BP.mjs} +1 -1
- package/dist/chunk-LEMLTB2X.mjs +1 -0
- package/dist/chunk-M2BCEQDP.mjs +1 -0
- package/dist/{chunk-44NLL6X3.mjs → chunk-MYEG7OXO.mjs} +1 -1
- package/dist/chunk-NMMTIZ6K.mjs +1 -0
- package/dist/chunk-NWQGXYER.mjs +1 -0
- package/dist/{chunk-3UE2DLFY.mjs → chunk-OBYCW4I3.mjs} +1 -1
- package/dist/chunk-ODZOYCTC.mjs +1 -0
- package/dist/{chunk-HFKGW34E.mjs → chunk-OOFTFGZL.mjs} +1 -1
- package/dist/chunk-OSUJWNS2.mjs +1 -0
- package/dist/chunk-PACB6IBR.mjs +1 -0
- package/dist/{chunk-ENXCO63D.mjs → chunk-PGIWJ37M.mjs} +1 -1
- package/dist/{chunk-VSWRWS2H.mjs → chunk-PLRJ4GAR.mjs} +1 -1
- package/dist/{chunk-KF35YUNZ.mjs → chunk-QF5B6AYF.mjs} +1 -1
- package/dist/chunk-QKJPWA2I.mjs +1 -0
- package/dist/{chunk-4O6YFMWF.mjs → chunk-RBX7ANQX.mjs} +1 -1
- package/dist/chunk-RQHZNEA2.mjs +1 -0
- package/dist/{chunk-SZQTGYPS.mjs → chunk-SDXFJ7JW.mjs} +1 -1
- package/dist/{chunk-EHM2ZBQU.mjs → chunk-SKQA53J2.mjs} +1 -1
- package/dist/chunk-TJ25JLBL.mjs +1 -0
- package/dist/chunk-U522GPBG.mjs +1 -0
- package/dist/{chunk-5J4BZL6N.mjs → chunk-V5K4F2XQ.mjs} +1 -1
- package/dist/chunk-VGX6J2OP.mjs +1 -0
- package/dist/{chunk-EO3SHOXX.mjs → chunk-VPF4NHAP.mjs} +1 -1
- package/dist/{chunk-VJKC2RJB.mjs → chunk-WNCZCPTX.mjs} +1 -1
- package/dist/chunk-XMCHOGMG.mjs +1 -0
- package/dist/chunk-XNCN6DGG.mjs +30 -0
- package/dist/{chunk-P6XIVHP5.mjs → chunk-XRM2KI4C.mjs} +1 -1
- package/dist/{chunk-YU5PF45T.mjs → chunk-YFXYRNER.mjs} +1 -1
- package/dist/{chunk-YHCZYT4T.mjs → chunk-YZIDCW7A.mjs} +1 -1
- package/dist/chunk-Z32CLWW2.mjs +1 -0
- package/dist/{chunk-KCDHP4N3.mjs → chunk-ZCJCM3DT.mjs} +1 -1
- package/dist/{chunk-WIJSWSNF.mjs → chunk-ZE3LG7MR.mjs} +1 -1
- package/dist/chunk-ZEIVO4X7.mjs +1 -0
- package/dist/{chunk-SIGOY5GG.mjs → chunk-ZQLNGMVV.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/codex-note-context-327LH622.mjs +1 -0
- package/dist/codex-project-25QJDNJN.mjs +1 -0
- package/dist/{codex-store-mount-VHUHC2ZA.mjs → codex-store-mount-BRHVGYZU.mjs} +1 -1
- package/dist/{dev-server-D8Qxrp1A.d.mts → dev-server-C-mvGeOM.d.mts} +2 -2
- package/dist/dev-server-ZLIPCFFT.mjs +1 -0
- package/dist/{focus-inspection-FVQ6TVGA.mjs → focus-inspection-TPTEFBH3.mjs} +1 -1
- package/dist/guest-admission.mjs +1 -1
- package/dist/guest-live-canvas.mjs +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +1 -1
- package/dist/{invitationLink-LUIIOAEZ.mjs → invitationLink-RX53O6RI.mjs} +1 -1
- package/dist/media.d.mts +3 -3
- package/dist/memory-store.d.mts +6 -6
- package/dist/{page-interaction-74JGNCZ5.mjs → page-interaction-6SR32FFS.mjs} +1 -1
- package/dist/{page-planes-BeFZ3Wso.d.mts → page-planes-C5J6qgMj.d.mts} +99 -50
- package/dist/{participantBootstrap-BcfNTEe9.d.mts → participantBootstrap-BjHfrdwL.d.mts} +3 -2
- package/dist/peer-client-2LEZ7SW4.mjs +1 -0
- package/dist/phone-recovery.mjs +1 -0
- package/dist/plugin-astro.d.mts +7 -7
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-next.mjs +1 -1
- package/dist/plugin-nuxt.d.mts +5 -5
- package/dist/plugin-nuxt.mjs +1 -1
- package/dist/plugin-vite.d.mts +8 -7
- package/dist/plugin-vite.mjs +1 -1
- package/dist/project-id.mjs +1 -0
- package/dist/{protocol-BIUE4rB6.d.mts → protocol-aJ3S127Q.d.mts} +5 -1
- package/dist/server.d.mts +15 -7
- package/dist/server.mjs +1 -1
- package/dist/shared-page-KQSG3DM3.mjs +1 -0
- package/dist/{subjects-qHIrZrlt.d.mts → subjects-CGN4QTSS.d.mts} +1 -1
- package/dist/{video-adapter-B5eap10v.d.mts → video-adapter-DtIw_QVy.d.mts} +1 -1
- package/dist/{workspace-snapshot-RUGPDEYJ.mjs → workspace-snapshot-DX62ZFVF.mjs} +1 -1
- package/infra/phone-pairing/machine-config.mjs +15 -2
- package/infra/phone-pairing/machine-service.mjs +39 -13
- package/infra/phone-pairing/managed-install.mjs +8 -2
- package/package.json +1 -1
- package/dist/PagePreviewLayer-HMKZL5VB.mjs +0 -1
- package/dist/ParticipantRuntime-ELXK42P7.mjs +0 -1
- package/dist/PhoneHostGate-5S2WCM3W.mjs +0 -1
- package/dist/PopmeltTasteConnectedPane-BILMI6L2.mjs +0 -1
- package/dist/SamplePlacementOverlay-K3Z5C67A.mjs +0 -1
- package/dist/ShareProjectPane-P5HAKBKX.mjs +0 -1
- package/dist/SuppliedContext-ADMN2D2I.mjs +0 -1
- package/dist/ThreadPanel-Z76WNKPP.mjs +0 -1
- package/dist/browser-runtime-OWU4CMJB.mjs +0 -1
- package/dist/chunk-2F2BVGFH.mjs +0 -1
- package/dist/chunk-5TCWBNV4.mjs +0 -1
- package/dist/chunk-72CUIZA2.mjs +0 -1
- package/dist/chunk-C2ZSNUXQ.mjs +0 -1
- package/dist/chunk-EILBHZDX.mjs +0 -1
- package/dist/chunk-FAEFYWCY.mjs +0 -1
- package/dist/chunk-FQH24XFS.mjs +0 -1
- package/dist/chunk-G7UU6M76.mjs +0 -1
- package/dist/chunk-GYKRKAEF.mjs +0 -1
- package/dist/chunk-HAZXZ5TU.mjs +0 -1
- package/dist/chunk-HM6EBJVO.mjs +0 -1
- package/dist/chunk-IC4G3NXR.mjs +0 -1
- package/dist/chunk-ITLRSHNZ.mjs +0 -1
- package/dist/chunk-J3IPAD7E.mjs +0 -1
- package/dist/chunk-LZV3IYTM.mjs +0 -1
- package/dist/chunk-OEJXPUAR.mjs +0 -1
- package/dist/chunk-PRZ6C5X3.mjs +0 -1
- package/dist/chunk-RWZ7SVMO.mjs +0 -1
- package/dist/chunk-SHIN4R4V.mjs +0 -1
- package/dist/chunk-SMIEQSM5.mjs +0 -1
- package/dist/chunk-SOGN7S54.mjs +0 -1
- package/dist/chunk-SUAHDXJZ.mjs +0 -1
- package/dist/chunk-TMW3SI7F.mjs +0 -1
- package/dist/chunk-TRRNHBEH.mjs +0 -1
- package/dist/chunk-UFU5IA3G.mjs +0 -1
- package/dist/chunk-UNUYNWTJ.mjs +0 -1
- package/dist/chunk-VI3DNZM4.mjs +0 -1
- package/dist/chunk-VLTK7KWK.mjs +0 -1
- package/dist/chunk-WP44H6DL.mjs +0 -30
- package/dist/chunk-YG3RSK5J.mjs +0 -1
- package/dist/chunk-YTMUAK4P.mjs +0 -1
- package/dist/codex-note-context-PM4TA6WR.mjs +0 -1
- package/dist/codex-project-YSALZU44.mjs +0 -1
- package/dist/dev-server-KE4NM4WM.mjs +0 -1
- package/dist/peer-client-TSTD27DV.mjs +0 -1
- package/dist/shared-page-6AUYAPJ3.mjs +0 -1
- /package/dist/{chunk-CIKFUS7J.mjs → chunk-R565ZNSP.mjs} +0 -0
- /package/dist/{chunk-DPLSL33X.mjs → chunk-XBA5ROC5.mjs} +0 -0
- /package/dist/{toolbarFonts-33BI56VQ.mjs → toolbarFonts-RR24L4CJ.mjs} +0 -0
- /package/dist/{webpEncoder-JVMGDKHV.mjs → webpEncoder-XTISHUBA.mjs} +0 -0
package/dist/chunk-UNUYNWTJ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,b as t}from"./chunk-HKHZBKAN.mjs";import{a as r,c as o}from"./chunk-CIKFUS7J.mjs";import{H as i,b as a,n,s,u as p,w as l,z as c}from"./chunk-72CUIZA2.mjs";import{a as d,c as h,e as f,f as m,g as u}from"./chunk-GLF7Z5IR.mjs";import{createHash as w,randomBytes as g,X509Certificate as y}from"crypto";import{createServer as v}from"https";import{createServer as b}from"http";import{pipeline as I}from"stream/promises";import{Readable as j}from"stream";import{Resolver as S}from"dns/promises";import{setTimeout as P}from"timers/promises";import{spawn as A}from"child_process";import{devNull as H}from"os";import{createInterface as T}from"readline";import{networkInterfaces as k}from"os";import{lstat as E,readFile as O,realpath as x}from"fs/promises";import{extname as C,isAbsolute as N,relative as L,resolve as D,sep as R}from"path";var _={".js":"text/javascript",".mjs":"text/javascript",".css":"text/css",".html":"text/html",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif",".ico":"image/x-icon",".json":"application/json",".webmanifest":"application/manifest+json",".woff":"font/woff",".woff2":"font/woff2",".wasm":"application/wasm",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".glb":"model/gltf-binary"};function X(e,t){return{body:e,type:_[C(t)]??"application/octet-stream"}}async function $(t,r,o){let i="",a=await t({root:r,base:o,logLevel:"error",plugins:[{name:"popmelt-lan-assets",configResolved(e){if(i=e.publicDir,e.root!==r||e.base!==o||e.build.write||e.build.sourcemap)throw new Error("Expected an in-memory plane build without source maps.")}}],build:{write:!1,emptyOutDir:!1,copyPublicDir:!1,sourcemap:!1,watch:null}}),n=new Map;for(let e of Array.isArray(a)?a:[a]){if(!("output"in e))throw new Error("Expected a browser application build.");for(let t of e.output)t.fileName.endsWith(".map")||n.set(t.fileName,X("chunk"===t.type?t.code:t.source,t.fileName))}if(!n.has("index.html"))throw new Error("Expected a Vite HTML entry for the shared app.");return async(t,o,a)=>{let s=n.get(t);if(!s&&i&&t){let e=D(i,t);try{let o=await x(e),a=L(r,o);if(o!==e||".."===a||a.startsWith(".."+R)||N(a)||!e.startsWith(i+R)||!(await E(e)).isFile())return;s=X(await O(e),t)}catch(e){if(!["ENOENT","ENOTDIR"].includes(e.code??""))throw e}}if(s??=o&&!C(t)?n.get("index.html"):void 0,!s||"text/html"!==s.type)return s;let p="<script>window.__POPMELT_PARTICIPANTS__="+JSON.stringify(a).replace(/</g,"\\u003c")+';<\/script><script defer src="'+e+'"><\/script>',l=Buffer.from(s.body).toString("utf8");return X(l.replace(/<head(?:\s[^>]*)?>/i.test(l)?/<head(?:\s[^>]*)?>/i:/^(?:\s*<!doctype[^>]*>)?(?:\s*<html[^>]*>)?/i,e=>e+p),"index.html")}}var U="/__popmelt/join",J=288e5,G=new Set(["source","pending","snapshot","read","connect","renew","disconnect","merge","publish","attention","attention-read","preview-read","preview-demand","preview-publish","rename"]),M="/__popmelt/guest-admission.js",B=`<!doctype html><html lang="en"><head>\n<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1,viewport-fit=cover">\n<meta name="color-scheme" content="light dark"><title>Join Popmelt</title>\n<style>html{color-scheme:light dark;background:light-dark(#eaeaea,#111);font-family:system-ui,sans-serif}body{margin:0}</style>\n<script defer src="${M}"><\/script></head>\n<body><main id="guest-entry"></main><noscript>Enable JavaScript to join this project.</noscript></body></html>`;function W(e){return("GET"===e.method||"HEAD"===e.method)&&("document"===e.headers["sec-fetch-dest"]||"iframe"===e.headers["sec-fetch-dest"]||String(e.headers.accept).includes("text/html"))}function F(e,t,r){if(t.headersSent)return void t.destroy();if(t.statusCode=r,!W(e))return void t.end();let o=401===r||403===r,i=o?"Guest access required":"Preview unavailable",a=o&&"same-origin"!==e.headers["sec-fetch-site"],n=a?"If you’ve already joined in this browser, open the project again below. Otherwise, ask the host for a fresh invite.":o?"Ask the host for a fresh invite to open this project.":"Ask the host for the current preview link.";t.setHeader("Content-Type","text/html; charset=utf-8"),t.end("HEAD"===e.method?void 0:p(i,'<p class="view-note">'+n+"</p>"+(a?'<a class="primary-action" href="">Open project</a>':"")))}async function q(e,t){let r=[],o=0;for await(let i of e){if(o+=i.length,o>t)throw new d(413,"Request too large");r.push(i)}return Buffer.concat(r).toString("utf8")}function V(e,t){e.setHeader("Content-Type","application/json"),e.end(JSON.stringify(t))}function z(e,t,r){let o=new Map;return{async guestOrigin(i){let a=o.get(i);a||(a=K(e(),{readApp:t,planes:r},{quickTunnel:"tunnel"===i}).then(e=>(e.onClose(()=>{o.get(i)===a&&o.delete(i)}),e)),o.set(i,a));try{let e=await a;if(o.get(i)!==a)throw new Error("Sharing stopped.");return e.inviteOrigin()}catch(e){throw o.get(i)===a&&o.delete(i),e}},async stopGuestSharing(){let e=[...o.values()];o.clear(),await Promise.all(e.map(e=>e.then(e=>e.close(),()=>{})))}}}function Z(e,t,r){return K(e,{planes:t,build:r.build},r)}async function K(a,n,s){let p=s.quickTunnel?"127.0.0.1":s.address??l();if(!(s.quickTunnel||/^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.)/.test(p)&&Object.values(k()).flat().some(e=>"IPv4"===e?.family&&e.address===p&&!e.internal)))throw new Error("Select a private IPv4 address on this computer.");let E,O=s.quickTunnel?void 0:await c(p),x="http://127.0.0.1:"+a.port,C=new Map,N=new Map,L="",D=!1,R=(o,s)=>{(async function(o,s){let p=e=>F(o,s,e);if(s.setHeader("Cache-Control","private, no-store"),s.setHeader("Referrer-Policy","same-origin"),s.setHeader("Cross-Origin-Resource-Policy","same-origin"),s.setHeader("X-Content-Type-Options","nosniff"),s.setHeader("X-Frame-Options","SAMEORIGIN"),D||!L||o.headers.host!==new URL(L).host||o.headers.origin&&o.headers.origin!==L||"cross-site"===o.headers["sec-fetch-site"]&&"GET"!==o.method)return p(403);let l=o.url??"";if(!l.startsWith("/")||l.startsWith("//")||/[\\#]/.test(l))return p(400);let c=new URL(l,L).pathname,y=c===r+"/send",v=o.headers["content-type"]??"";if("POST"===o.method&&(o.headers.origin!==L||(y?!/^multipart\/form-data;\s*boundary=/i.test(v):"application/json"!==v)))return p(403);if(c===M)return"GET"!==o.method&&"HEAD"!==o.method?p(405):(s.setHeader("Content-Type","application/javascript; charset=utf-8"),void s.end("HEAD"===o.method?void 0:await t("admission")));let b=o.headers.cookie?.split(";").map(e=>e.trim()).find(e=>e.startsWith(E+"="))?.slice(E.length+1),S=b&&/^[A-Za-z0-9_-]{43}$/.test(b)?b:void 0;if(c===U||c===U+"/appearance"){if(c===U&&("GET"===o.method||"HEAD"===o.method))return s.setHeader("Content-Type","text/html; charset=utf-8"),s.setHeader("X-Popmelt-Guest-Landing","1"),void s.end("HEAD"===o.method?void 0:B);if("POST"!==o.method)return p(405);let{invitation:e,name:t}=JSON.parse(await q(o,2048))??{},r=c===U;if("string"!=typeof e||!/^[\w-]{43}$/.test(e)||r&&("string"!=typeof t||!t.trim()||t.length>48))return p(400);let n=S??g(32).toString("base64url"),l=w("sha256").update(JSON.stringify([a.projectId,L,n])).digest("hex"),d=await a.visitGuestInvite(e,l,r?t.trim():void 0);if(D)return p(503);if(s.setHeader("Set-Cookie",E+"="+n+"; Path=/; Secure; HttpOnly; SameSite=Strict; Max-Age="+i/1e3),d.appearance)return V(s,{projectId:a.projectId,...d.appearance});let{credential:h,sharedPath:f}=d;for(let[e,t]of C)t.expires<=Date.now()&&C.delete(e);let m=C.get(n);return m&&m.proof.participantId===h.participantId&&m.sharedPath===f?m.expires=Date.now()+J:(m={proof:h,browserToken:g(32).toString("base64url"),sharedPath:f,expires:Date.now()+J,mounts:new Map,assets:new Map},C.set(n,m)),V(s,{sharedPath:f,projectId:a.projectId,credential:{participantId:h.participantId,token:m.browserToken}})}let P=S&&C.get(S);if(!P||P.expires<=Date.now())return p(403);let{proof:A}=P,H=a.planeAppBasis;await H(A,A.participantId);let T=o.headers["x-popmelt-participant-id"],k=c.startsWith(r+"/thread/")?/^([a-zA-Z0-9_-]{1,128})$/.exec(c.slice((r+"/thread/").length))?.[1]:void 0;if(y||k||c===f+"open"||c.startsWith(r+"/participants/")){if(o.method!==(k?"GET":"POST")||T!==A.participantId||o.headers["x-popmelt-participant-token"]!==P.browserToken)return p(403);if(y){let e=o.headers["x-popmelt-draft-revision"],t=o.headers["x-popmelt-source-revision"];if(o.headers["x-popmelt-project-id"]!==a.projectId)return p(403);if("string"!=typeof e||!/^\d+$/.test(e)||"string"!=typeof t||!t||t.length>512)return p(400);let r=await h(o,33554432),i=await fetch(x+"/send",{method:"POST",redirect:"error",headers:{"Content-Type":v,"X-Popmelt-Project-Id":a.projectId,"X-Popmelt-Participant-Id":A.participantId,"X-Popmelt-Participant-Token":A.token,"X-Popmelt-Draft-Revision":e,"X-Popmelt-Source-Revision":t},body:new Uint8Array(r)});return s.statusCode=i.status,s.setHeader("Content-Type","application/json"),void s.end(await i.text())}if(c===f+"open"){if(!n.planes)return p(404);let{target:e,pathname:t,active:r}=JSON.parse(await q(o,8192))??{};if("string"!=typeof e)return p(400);if("readApp"in n&&void 0!==t&&("string"!=typeof t||u(t)!==P.sharedPath))return p(403);let i=await n.planes.open(a,A,e,t,r);"readApp"in n&&(i.application.path=P.sharedPath);let l=i.application.basePath,c=P.mounts.get(l)??new Set;return c.add(e),P.mounts.set(l,c),V(s,i)}let e=k?"shared-thread":c.slice((r+"/participants/").length);if(!k&&!G.has(e)||o.headers["x-popmelt-project-id"]!==a.projectId)return p(403);let t=await fetch(x+"/participants/"+e,{method:"POST",redirect:"error",signal:AbortSignal.timeout(15e3),headers:{"Content-Type":"application/json","X-Popmelt-Project-Id":a.projectId,"X-Popmelt-Participant-Id":A.participantId,"X-Popmelt-Participant-Token":A.token},body:k?JSON.stringify({threadId:k}):await q(o,2097152)});return s.statusCode=t.status,s.setHeader("Content-Type","application/json"),void s.end(await t.text())}if("GET"!==o.method&&"HEAD"!==o.method)return p(403);if(c===e)return s.setHeader("Content-Type","text/javascript"),void s.end("HEAD"===o.method?void 0:await t("toolbar"));if(c===r+"/status")return V(s,{projectId:a.projectId,running:!0});let O=m(c);if("/"===O&&/^\/(?:__popmelt|@|popmelt\/)/.test(c))return p(404);let R,_=W(o),X=P.mounts.get(O);if("/"!==O&&!X)return p(403);if(X)for(let e of X)try{await H(A,e),R=e;break}catch(e){if(!(e instanceof d)||404!==e.statusCode)throw e}if(X&&!R)return p(404);if("readApp"in n){if("/"!==O&&!n.planes)return p(404);let e=P.assets.get(O);e||P.assets.set(O,e=new Set);let t=await(n.planes?.servedAt(c)),i=await n.readApp({url:new URL(l,L),document:_,projectId:a.projectId,sharedPath:P.sharedPath,assets:e,basePath:O,...t&&{bootstrap:{version:1,planeApps:!0,...t,projectId:a.projectId,url:L+r}},range:o.headers.range});if(!i)return p(404);try{await H(A,R??A.participantId)}catch(e){throw await(i.body?.cancel()),e}for(let e of["content-type","content-length","content-range","content-security-policy","accept-ranges"]){let t=i.headers.get(e);t&&s.setHeader(e,t)}return s.statusCode=i.status,void("HEAD"!==o.method&&i.body?await I(j.fromWeb(i.body),s):(await(i.body?.cancel()),s.end()))}let{planes:z,build:Z}=n;if("/"===O&&!_&&o.headers.referer){let e=new URL(o.headers.referer),t=m(e.pathname);if(e.origin===L&&"/"!==t&&P.mounts.has(t))return s.writeHead(307,{Location:t.slice(0,-1)+l}),void s.end()}let K=decodeURIComponent(c.slice(O.length));if(K.split("/").some(e=>e.startsWith(".")||"node_modules"===e)||/[\\%\0]/.test(K)||/\.(?:map|pem|crt|key)$/i.test(K))return p(404);let{revision:Y,appVersion:Q}=await z.servedAt(c),ee=N.get(O);if(ee?.version!==Q){let e=$(Z,z.checkout(O),O);ee={version:Q,built:e},N.set(O,ee),e.catch(()=>{N.get(O)?.built===e&&N.delete(O)})}let te=await(await ee.built)(K,_,{version:1,planeApps:!0,appVersion:Q,projectId:a.projectId,revision:Y,url:L+r});if(!te)return p(404);await H(A,R??A.participantId),s.setHeader("Content-Type",te.type),s.end("HEAD"===o.method?void 0:te.body)})(o,s).catch(e=>{let t=e instanceof d?e.statusCode:e instanceof SyntaxError||e instanceof URIError?400:503;F(o,s,t)})},_=O?v({...O,minVersion:"TLSv1.2"},R):b(R);await new Promise((e,t)=>{_.once("error",t),_.listen(0,p,e)});let X,z=_.address();if(!z||"string"==typeof z)throw new Error("LAN listener unavailable");try{s.quickTunnel&&(X=await async function(e){let t={...process.env};for(let e of Object.keys(t))/^(TUNNEL_|CLOUDFLARE_|CF_)/i.test(e)&&delete t[e];let r,i=A("cloudflared",["tunnel","--config",H,"--no-autoupdate","--metrics","127.0.0.1:0","--grace-period","1s","--url","http://127.0.0.1:"+e],{env:t,stdio:["ignore","ignore","pipe"],windowsHide:!0}),a=T({input:i.stderr}),n=new Promise((e,t)=>{r=t,a.on("line",t=>{let r=/https:\/\/[a-z0-9-]+\.trycloudflare\.com\b/.exec(t);r&&o(r[0])&&e(r[0])}),i.once("error",t)}),s=new Promise(e=>i.once("close",t=>{r(new Error("Cloudflare connector closed (exit "+t+").")),e()})),p=()=>{i.kill("SIGTERM")};process.once("exit",p),s.then(()=>process.off("exit",p));let l=setTimeout(()=>r(new Error("Timed out starting the Cloudflare Quick Tunnel.")),45e3),c=async()=>{p();let e=setTimeout(()=>i.kill("SIGKILL"),4e3);try{await s}finally{clearTimeout(e)}};try{return{origin:await n,exited:s,close:c}}catch(e){throw await c(),e}finally{clearTimeout(l)}}(z.port)),L=X?.origin??"https://"+p+":"+z.port,E="__Host-popmelt-guest-"+w("sha256").update(JSON.stringify([a.projectId,L])).digest("hex").slice(0,24)}catch(e){throw _.closeAllConnections(),await new Promise(e=>_.close(()=>e())),e}let Z,K,Y=new AbortController;function Q(){if(K)return K;D=!0,Y.abort(),C.clear(),N.clear();let e=new Promise(e=>_.close(()=>e()));return _.closeAllConnections(),K=Promise.all([e,X?.close()]).then(()=>{}),K}return X?.exited.then(Q),{server:_,origin:L,onClose(e){D?e():Y.signal.addEventListener("abort",e,{once:!0})},inviteOrigin:async()=>(X&&(Z??=async function(e,t){let r=new S({timeout:2e3,tries:1}),o=Date.now()+12e4;for(await P(8e3,void 0,{signal:t});Date.now()<o;){t.throwIfAborted();try{await r.resolve4(new URL(e).hostname);let o=await fetch(e+"/__popmelt/join",{method:"HEAD",redirect:"error",signal:AbortSignal.any([t,AbortSignal.timeout(4e3)])});if(o.ok&&"1"===o.headers.get("X-Popmelt-Guest-Landing"))return}catch{}await P(1500,void 0,{signal:t})}throw new Error("The guest tunnel did not become reachable.")}(L,Y.signal).catch(e=>{throw Z=void 0,e}),await Z),Y.signal.throwIfAborted(),L),fingerprint:O?new y(O.cert).fingerprint256:void 0,close:Q}}import{randomBytes as Y,timingSafeEqual as Q}from"crypto";import{readFile as ee,writeFile as te,mkdir as re,rename as oe,unlink as ie}from"fs/promises";import{join as ae}from"path";import{randomBytes as ne}from"crypto";import{createServer as se}from"http";var pe=(e,t)=>"string"==typeof e&&Buffer.byteLength(e)===Buffer.byteLength(t)&&Q(Buffer.from(e),Buffer.from(t));async function le(e){let t=ae(e.projectRoot,".popmelt");await re(t,{recursive:!0});let r,o=ae(t,"participant-host-recovery.json");try{if(r=JSON.parse(await ee(o,"utf8")).token,"string"!=typeof r||!/^[\w-]{43}$/.test(r))throw new Error("Invalid host recovery capability")}catch(e){if("ENOENT"!==e.code)throw e;r=Y(32).toString("base64url"),await te(o,JSON.stringify({token:r}),{mode:384,flag:"wx"})}let i=Y(16).toString("hex"),n=ae(t,"participant-host-browser.json"),p=await ee(n,"utf8").catch(()=>"")===e.origin,l=new AbortController;p&&l.abort();let c=Y(32).toString("base64url"),d=ae(t,"participant-host-link.json"),h=t=>`${e.origin}/#popmelt-host=${t}`;async function f(){let e=Y(32).toString("base64url"),t=d+"."+Y(12).toString("hex");try{await te(t,JSON.stringify({url:h(e)}),{flag:"wx",mode:384}),await oe(t,d)}finally{await ie(t).catch(()=>{})}return e}let m=await f(),u=await async function(e,t){let r=new URL(e);if(r.origin!==e||!["http:","https:"].includes(r.protocol)||!["localhost","127.0.0.1","[::1]"].includes(r.hostname))return;let o=new Map,i=0,n=se(async(r,n)=>{if(n.setHeader("Cache-Control","no-store"),n.setHeader("Vary","Origin"),"/"!==r.url||"127.0.0.1"!==r.socket.remoteAddress||r.headers.host!=="127.0.0.1:"+r.socket.localPort||r.headers.origin!==e||Object.keys(r.headers).some(e=>/^(forwarded$|x-forwarded-|via$|x-real-ip$)/.test(e)))return void n.writeHead(403).end();if(n.setHeader("Access-Control-Allow-Origin",e),"OPTIONS"===r.method)return void n.writeHead(204,{"Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":"X-Popmelt-Session"}).end();if("POST"!==r.method||r.headers["x-popmelt-session"]!==t)return void n.writeHead(403).end();let s=Date.now();for(let[e,t]of o)t<=s&&o.delete(e);if(i>=8||o.size>=64)return void n.writeHead(429).end();i++;try{if(!r.socket.remotePort||!r.socket.localPort||!await a(r.socket.remotePort,r.socket.localPort))return void n.writeHead(403).end()}finally{i--}if(n.destroyed)return;let p=ne(32).toString("base64url");o.set(p,Date.now()+3e4),n.writeHead(200,{"Content-Type":"application/json"}).end(JSON.stringify({proof:p}))});return await new Promise((e,t)=>{n.once("error",t),n.listen(0,"127.0.0.1",()=>{n.off("error",t),e()})}),n.unref(),{port:n.address().port,consume(e){if("string"!=typeof e)return!1;let t=o.get(e);return o.delete(e)&&void 0!==t&&t>Date.now()},close(){o.clear(),n.close(),n.closeAllConnections()}}}(e.origin,i).catch(e=>{console.warn("[popmelt] Local browser discovery unavailable (%s). Use the private host link.",e.code??"listener unavailable")}),w=`popmelt-host-${e.projectId}`;return{handler:async(t,o)=>{o.setHeader("Cache-Control","no-store");let a=t.headers.origin,d=a&&s(a,e.origin);if("HEAD"===t.method)return d&&(o.setHeader("Access-Control-Allow-Origin",a),o.setHeader("Access-Control-Expose-Headers","X-Popmelt-Session"),o.setHeader("Vary","Origin")),void o.writeHead(204,{"X-Popmelt-Session":i}).end();if("POST"!==t.method||t.headers.origin!==e.origin||"application/json"!==t.headers["content-type"])return d&&"POST"===t.method&&(o.setHeader("X-Popmelt-Host-Origin",e.origin),o.setHeader("X-Popmelt-Session",i)),o.statusCode=403,void o.end();try{let a="";for await(let e of t)if(a+=e,a.length>2048)throw new Error("Invalid host proof");let s,d=JSON.parse(a),h=t.headers.cookie?.split(";").map(e=>e.trim()).find(e=>e.startsWith(`${w}=`))?.slice(w.length+1);if(m&&pe(d.token,m)){let t=m;m="";try{s=await e.host(),m=await f()}catch(e){throw m=t,e}}else if(c&&pe(d.token,c))c="";else if(!pe(h,r))if(d.localProof&&u?.consume(d.localProof)){if(s=await e.host(),void 0!==d.previousId&&d.previousId!==s.participantId)throw new Error("Previous participant was not this host")}else{if(!d.credential)throw u&&0===Object.keys(d).length&&(o.setHeader("X-Popmelt-Local-Port",String(u.port)),o.setHeader("X-Popmelt-Session",i)),new Error("Host proof required");if(s=await e.host(),d.credential.participantId!==s.participantId||!pe(d.credential.token,s.token))throw new Error("Invalid host proof")}s??=await e.host(),l.abort(),p||(p=!0,await te(n,e.origin,{mode:384}).catch(()=>{p=!1})),o.setHeader("Set-Cookie",`${w}=${r}; Path=/__popmelt/host; HttpOnly; SameSite=Strict; Max-Age=31536000`),o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(s))}catch{o.statusCode=403,o.end()}},dispose(){l.abort(),u?.close()},instanceId:i,browserLaunch:l,launchUrl:`${e.origin}/#popmelt-host=${c}`,get claimUrl(){return h(m)}}}import{mkdir as ce,writeFile as de}from"fs/promises";import{join as he}from"path";import{spawn as fe}from"child_process";import{setTimeout as me}from"timers/promises";function ue(e){let[t,...r]="darwin"===process.platform?["open",e]:"win32"===process.platform?["rundll32.exe","url.dll,FileProtocolHandler",e]:["xdg-open",e],o=fe(t,r,{stdio:"ignore",detached:!0});o.on("error",()=>{}),o.unref()}async function we(e,t,r,o=(function(){let{BROWSER:e,CI:t,DISPLAY:r,WAYLAND_DISPLAY:o,SSH_CONNECTION:i,NODE_ENV:a}=process.env;return!("none"===e||t||"test"===a||i||"darwin"!==process.platform&&"win32"!==process.platform&&!r&&!o)}()?ue:void 0)){let{origin:i,hostname:a,protocol:n}=new URL(e);if(!o||!["localhost","127.0.0.1","[::1]"].includes(a)||!["http:","https:"].includes(n))return;let{signal:s}=r;if(s.aborted)return;let p=setTimeout(()=>r.abort(),9e4).unref();try{for(;!s.aborted;){try{let r=await fetch(i+"/__popmelt/host",{method:"HEAD",redirect:"error",signal:s});if(204===r.status&&r.headers.get("x-popmelt-session")===t)return void(s.aborted||o(e))}catch{}await me(500,void 0,{signal:s,ref:!1}).catch(()=>{})}}finally{clearTimeout(p)}}async function ge(e){let{bridge:t}=e,r=e.guestInvites&&{guestInvites:e.guestInvites,tunnelAvailable:!!await n("cloudflared",e.projectRoot)};if(!t.participantHost)throw new Error("The bridge does not support participant sessions");let o=he(e.projectRoot,".popmelt");await ce(o,{recursive:!0}),await de(he(o,"participant-bridge.json"),JSON.stringify({port:t.port,projectId:t.projectId}),{mode:384});let i=await le({projectRoot:e.projectRoot,projectId:t.projectId,origin:e.origin,host:t.participantHost});async function a(o="/"){let i=await(e.planeApps?.servedAt(o));return{version:1,...r,url:`http://127.0.0.1:${t.port}`,projectId:t.projectId,revision:i?.revision??await(e.sourceRevision?.())??"unversioned",...i&&{planeApps:!0,appVersion:i.appVersion}}}return we(i.launchUrl,i.instanceId,i.browserLaunch),{dispose:i.dispose,cancelBrowserLaunch:()=>i.browserLaunch.abort(),hostEntry:i.handler,read:a,planeMiddleware:e.planeApps?.middleware(t,e.origin,a)}}export{$ as a,z as b,Z as c,le as d,ge as e};
|
package/dist/chunk-VI3DNZM4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as t,f as e}from"./chunk-SMIEQSM5.mjs";import{h as a,q as r,w as i}from"./chunk-WP44H6DL.mjs";import{readFile as o,realpath as n,mkdir as s,writeFile as c}from"fs/promises";import{createHash as p}from"crypto";import{join as d,resolve as l}from"path";function u(t,e){let a=p("sha256").update(e).digest("hex");return d(t,".popmelt","participant-agents",a+".json")}async function f(t,a){if(a.storeId!==t.storeId)return{ok:!1,body:{status:"writable_store_required"}};if("string"!=typeof a.threadId||!a.threadId||"string"!=typeof a.text||!a.text.trim()||a.text.length>8e3)return{ok:!1,body:{status:"invalid_note"}};let r;try{r=await h(t,t.sessionId,!0)}catch(t){if("ENOENT"!==t.code)throw t;return{ok:!1,body:{status:"participant_invitation_required"}}}if(!r)return{ok:!1,body:{status:"enrolled_bridge_required"}};let i=await e(r.endpoint,"/participants/thread-note",{...r.request,method:"POST",signal:AbortSignal.timeout(3e4),body:JSON.stringify({storeId:t.storeId,threadId:a.threadId,reply:a.text,sessionId:t.sessionId,requestId:a.requestId})});return{ok:i.response.ok,body:i.body}}async function h(t,i,s=!1){let c=await o(d(t.projectRoot,".popmelt","participant-bridge.json"),"utf8").then(JSON.parse).catch(e=>{if("ENOENT"!==e.code||!t.bridgePort)throw e;return{projectId:t.projectId,port:t.bridgePort}});if(c.projectId!==t.projectId||!Number.isInteger(c.port)||c.port<1||c.port>65535)return null;let p={redirect:"error",signal:AbortSignal.timeout(3e3)},l=await e(c,"/status",p);if(!l.response.ok||l.body?.projectId!==t.projectId)return null;let f,h=u(t.projectRoot,i);try{f=JSON.parse(await o(h,"utf8"))}catch(l){if("ENOENT"!==l.code||!s)throw l;let u=await n(t.projectRoot),m=r(i);if(a(u)!==t.projectId||!m)return null;let g=JSON.parse(await o(d(u,".popmelt","participant-host.json"),"utf8"));if(!(await e(c,"/participants/agent-join",{...p,method:"POST",headers:{"X-Popmelt-Participant-Id":g.participantId,"X-Popmelt-Participant-Token":g.token},body:JSON.stringify({sessionId:i,name:m,headless:!0})})).response.ok)return null;f=JSON.parse(await o(h,"utf8"))}return{endpoint:c,request:{...p,headers:{"X-Popmelt-Participant-Id":f.participantId,"X-Popmelt-Participant-Token":f.token}}}}async function m(t,a,r){let i=[t,...t.mountedStores].find(t=>t.storeId===a.storeId);if(!i||r&&i!==t)return{ok:!1,body:{status:"store_unavailable"}};if(r&&("string"!=typeof a.threadId||!a.threadId))return{ok:!1,body:{status:"thread_required"}};let o=await h(i,t.sessionId,r).catch(t=>{if("ENOENT"===t.code)return null;throw t});if(!o)return{ok:!1,body:{status:"enrolled_bridge_required",message:"Join this project as a Popmelt peer and check that its bridge is running."}};let{endpoint:n,request:s}=o,c=await e(n,r?t.sessionId.startsWith("claude:")?"/participants/link-claude-chat":"/participants/link-codex-chat":"/participants/check-claude-notes",{...s,method:"POST",body:JSON.stringify({sessionId:t.sessionId,...r?{threadId:a.threadId}:{}})});return{ok:c.response.ok,body:c.body}}async function g(r,l,f={}){if(t())return{status:"already_managed_by_bridge"};if((await e(r,"/status",{redirect:"error",signal:AbortSignal.timeout(3e3)})).body?.participantSessions)return async function(t,r,l){if(!l.projectRoot)throw new Error("Participant connections require the active project root");let f=await n(l.projectRoot);if(a(f)!==t.projectId)throw new Error("Participant project does not match");let h,m,g=d(f,".popmelt"),w=p("sha256").update(r).digest("hex"),I=async(a,r,i)=>{let o=await e(t,"/participants/"+a,{method:"POST",redirect:"error",headers:{"X-Popmelt-Participant-Id":r.participantId,"X-Popmelt-Participant-Token":r.token},body:JSON.stringify(i),signal:AbortSignal.timeout(9e4)}),n=o.body;if(!o.response.ok||n.error)throw new Error(n.error??"Participant connection unavailable");return n};try{h=JSON.parse(await o(u(f,r),"utf8"))}catch(t){if("ENOENT"!==t.code)throw t;if(!l.name)return{status:"participant_invitation_required"};let e=JSON.parse(await o(d(g,"participant-host.json"),"utf8")),a=await I("agent-join",e,{sessionId:r,name:l.name});h=a.credential,m=a.participant}if(!l.action){let t=await I("agent-connect",h,{});return{status:"participant_connected",participantId:h.participantId,participant:t.participant??m}}let y=await I("agent-act",h,{action:i(l.action)}),b=y.evidence;if(b?.frame?.image){let t=b.frame.image;if(!/^data:image\/jpeg;base64,[A-Za-z0-9+/=]+$/.test(t)||t.length>7e5)throw new Error("Invalid participant preview");let e=d(g,"artifacts","participant-previews");await s(e,{recursive:!0,mode:448});let a=d(e,w+".jpg");return await c(a,Buffer.from(t.slice(t.indexOf(",")+1),"base64"),{mode:384}),{status:"participant_connected",participant:y.participant,evidence:{...b,frame:{imagePath:a,targets:b.frame.targets}}}}return{status:"participant_connected",participant:y.participant,evidence:y.evidence}}(r,l,f);let h=async(t,a)=>{let i=await e(r,`/peers/${t}`,{method:"POST",body:JSON.stringify(a),signal:AbortSignal.timeout(5e4)}),o=i.body;if(!i.response.ok||o?.error)throw new Error(o?.error??"Peer connection unavailable");return o},m=await h("join",{sessionId:l,name:f.name}),g=f.action?await h("act",{token:m.token,clientId:f.clientId,action:i(f.action)}):m,w=g.peer;return{...g.status?{status:g.status}:{},...w?{peer:{...w,state:w.state?{annotations:w.state.annotations,styleModifications:w.state.styleModifications,textModifications:w.state.textModifications,undoDepth:w.state.undoStack.length,redoDepth:w.state.redoStack.length}:null}}:{},...g.evidence?{evidence:g.evidence}:{},clients:m.clients}}async function w(t){let r=e=>{let a=t.indexOf(e);return a>=0?t[a+1]:void 0},i=r("--session");if(!i)throw new Error("Usage: popmelt peer --session <stable-agent-session> [--project-root <active-project>] [--name <your-name>] [--client <canvas-id>] [--action <JSON>]");let s=await n(l(r("--project-root")??process.cwd())),c=JSON.parse(await o(d(s,".popmelt","bridge.lock"),"utf8")),p=a(s),u=await e({port:c.port,projectId:p},"/status",{signal:AbortSignal.timeout(3e3)});if(!u.response.ok||u.body.projectRoot!==s&&(!u.body.participantSessions||u.body.projectId!==p))throw new Error("No matching running project bridge");let f=r("--action");console.log(JSON.stringify(await g({port:c.port,projectId:p},i,{name:r("--name"),projectRoot:s,clientId:r("--client"),action:f?JSON.parse(f):void 0}),null,2))}export{u as a,f as b,h as c,m as d,g as e,w as f};
|
package/dist/chunk-VLTK7KWK.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{f as e,e as t,c as r}from"./chunk-RWZ7SVMO.mjs";import{w as n,C as a}from"./chunk-KF35YUNZ.mjs";import{a as l,b as o}from"./chunk-VBH2YQLG.mjs";import{c as i,h as s}from"./chunk-VXRRHXUP.mjs";import{c}from"./chunk-WP2SHSCG.mjs";import{f as m}from"./chunk-AAMUU2QA.mjs";import{d as f}from"./chunk-LH7HKUCK.mjs";function p(e){return/^(inline-)?(flex|grid)$/.test(e.display)}function u(e,t,r,n){return e?{left:t-1,top:r,width:2,height:n-r}:{left:r,top:t-1,width:n-r,height:2}}function d(e,t,r){if(!c(e))return null;let l=n(a(e),e.ownerDocument);return t?r?[l.topLeft,l.bottomLeft]:[l.topRight,l.bottomRight]:r?[l.topLeft,l.topRight]:[l.bottomLeft,l.bottomRight]}function h(e,t,r){let n=getComputedStyle(e),a=p(n),{horizontal:l,reverse:o}=a?function(e){let t=e.display.endsWith("grid"),r=t?!e.gridAutoFlow.includes("column"):!e.flexDirection.startsWith("column");if(t){let t=(r?e.gridTemplateColumns:e.gridTemplateRows).replace(/\[[^\]]*\]/g,"").trim();/^[\d.]+px$/.test(t)&&(r=!r)}return{horizontal:r!==/^(vertical|sideways)/.test(e.writingMode),reverse:(r?"rtl"===e.direction:e.writingMode.endsWith("-rl"))!==(!t&&e.flexDirection.endsWith("-reverse"))}}(n):{horizontal:!1,reverse:!1},i=l?"left":"top",s=l?"right":"bottom",m=l?"top":"left",h=l?"bottom":"right",b=l?r.x:r.y,g=l?r.y:r.x,y=[];if(!t||a)for(let t of e.children){if(t.matches("script,style,link,[data-devtools],[data-popmelt-shadow-host]"))continue;let e=f(t);!e.width||!e.height||a&&["absolute","fixed"].includes(getComputedStyle(t).position)||y.push({child:t,rect:e})}let j=y.find(e=>e.child===t);if(!t){if(a&&(n.display.endsWith("grid")||n.flexWrap.startsWith("wrap"))&&!y.some(({rect:e})=>g>e[m]&&g<e[h])){let t=-1/0,r=1/0;for(let{rect:e}of y)e[h]<=g&&(t=Math.max(t,e[h])),e[m]>=g&&(r=Math.min(r,e[m]));if(t<r&&Number.isFinite(t)&&Number.isFinite(r)){let n=y[0].rect[h]<=t,a=y.find(({rect:e})=>n?e[m]>=r:e[h]<=t);if(a){let n=f(e);return{reference:a.child,before:!0,inGap:!0,marker:u(!l,(t+r)/2,n[i],n[s])}}}}let o=1/0;for(let e of y){let t=e.rect,n=a?Math.hypot(Math.max(t.left-r.x,r.x-t.right,0),Math.max(t.top-r.y,r.y-t.bottom,0)):Math.min(Math.abs(r.y-t.top),Math.abs(r.y-t.bottom));n<o&&(o=n,j=e)}t=j?.child??null}let x=j?.rect??f(t??e),v=t?b<(x[i]+x[s])/2:!o,w=!!t&&v!==o,S=v?x[i]:x[s],k=S,E=x[m],M=x[h],T=!1;if(a&&t&&c(t)&&getComputedStyle(t).transform?.startsWith("matrix")){let e,r=d(t,l,v),n=(x[i]+x[s])/2,a=1/0;for(let t of y){let r=t.rect;if(Math.min(x[h],r[h])<=Math.max(x[m],r[m]))continue;let l=((r[i]+r[s])/2-n)*(v?-1:1);l>0&&l<a&&(e=t.child,a=l)}let o=e&&d(e,l,!v);if(r){let e=e=>({x:(r[e].x+(o?.[e].x??r[e].x))/2,y:(r[e].y+(o?.[e].y??r[e].y))/2}),n=e(0),a=e(1);return{reference:t,before:w,inGap:b<x[i]||b>x[s],marker:{left:n.x-1,top:n.y,width:2,height:Math.hypot(a.x-n.x,a.y-n.y),transformOrigin:"1px 0",transform:`rotate(${Math.atan2(n.x-a.x,a.y-n.y)}rad)`}}}}if(a&&t){let e=1/0;for(let r of y){if(r.child===t)continue;let n=r.rect,a=Math.max(x[m],n[m]),l=Math.min(x[h],n[h]);if(l<=a)continue;let o=v?n[s]:n[i],c=v?S-o:o-S;c<0||c>=e||(e=c,k=(S+o)/2,E=a,M=l,T=b>=Math.min(S,o)&&b<=Math.max(S,o)&&g>=E&&g<=M)}}return{reference:t,before:w,inGap:T,marker:u(l,k,E,M)}}function b(e){if(!e||"object"!=typeof e)return!1;let t=e;return(void 0===t.subject||null!==t.subject&&(void 0===t.subject.inserted||!0===t.subject.inserted)&&(void 0===t.subject.label||"string"==typeof t.subject.label&&t.subject.label.length<=256)&&[t.subject.adapter,t.subject.key,t.subject.canvasSelector].every(e=>"string"==typeof e&&e.length>0&&e.length<=2048))&&"string"==typeof t.pathname&&t.pathname.startsWith("/")&&t.pathname.length<=2048&&"string"==typeof t.selector&&t.selector.length>0&&t.selector.length<=2048&&"string"==typeof t.format&&t.format.length>0&&t.format.length<=128&&"string"==typeof t.value&&t.value.length<=65536}var g=class extends Error{constructor(e){super("This sample needs a matching target or a place on your plane."),this.sample=e}};function y(e,t,n,a){try{let l=function(e,t,n,a){let l=m(t.location.pathname);if(!e.isConnected||m(e.ownerDocument.location.pathname)!==l)throw new Error("The preview changed. Select the element again.");let i=n?.sampleableObject(e);if(i){let{projection:e,surface:r,objects:n}=i,l=n.read(r.read(),e.target.key);if(null===l)throw new Error("This object cannot be sampled by its renderer.");if(l.length>65536)throw new Error("This object is too large to place.");if(!a?.sampleableCanvases(t.documentElement,!0).some(e=>e.format===r.format&&e.objects?.placement&&(e.objects.placement.canPlace?.(l)??!0)))throw new Error("This object needs a matching scene object on your plane.");return{kind:"object",label:e.subject.label,format:r.format,value:l}}if(o(e))throw new Error("This scene object needs a unique identity before it can be sampled.");return{kind:"element",label:e.localName,tree:r(e)}}(e,t,n,a),s={pathname:m(t.location.pathname),id:crypto.randomUUID()};return{sample:"object"===l.kind?{...l,...s}:{...l,...s,sourceSelector:i(e)},reason:null}}catch(e){return{sample:null,reason:e instanceof Error?e.message:"This element cannot be sampled."}}}function j(e,t,r,n,a){let l=y(t,r,n,a);if(!l.sample)throw new Error(l.reason);return{...l.sample,from:e}}function x(e){for(let t=e;t?.parentElement;t=t.parentElement){let e=t.parentElement;if(p(getComputedStyle(e)))return t;if(!["div","a","li","span"].includes(e.localName)||Array.from(e.childNodes).some(e=>e!==t&&(3===e.nodeType?!!e.textContent?.trim():1===e.nodeType&&!e.matches("[inert],script,style,[data-devtools]"))))break}return e}function v(r,n,a,o){if(!n||m(n.ownerDocument.location.pathname)!==r.pathname)return null;if("object"===r.kind){let e=o?.placementSurface(n,r.format),t=e?.surface.objects?.placement;if(!e||!t)return null;let{surface:s,adapter:c}=e,m="placed-"+r.id,f=t.at(r.value,a);if(null===f)return null;let p={adapter:c,key:m,canvasSelector:i(s.element),inserted:!0,label:r.label.slice(0,256)},u={subject:p,pathname:r.pathname,selector:l(p),format:r.format,value:f};if(!b(u))return null;let d=t.insert(s.read(),m,f);return null!==d&&s.accepts(d)?{target:s.element,pointer:a,objectPlacement:t,payload:{from:r.from,styles:[],texts:[],canvases:[u]}}:null}if(n.closest("[data-devtools],[data-popmelt-shadow-host]"))return null;let c,f=function(e,t,r){let n=e.closest('svg[aria-hidden="true"]');if(!n||"absolute"!==getComputedStyle(n).position)return null;let a=(e,r)=>x(s(e,r)?.closest(t)??null);for(let e of[8,16,32])for(let[t,n]of[[e,0],[0,e]]){let e=a(r.x-t,r.y-n);if(!e?.parentElement||!p(getComputedStyle(e.parentElement)))continue;let l=a(r.x+t,r.y+n);if(l&&(e.nextElementSibling===l||e.previousElementSibling===l))return e}return null}(n,r.tree.tag,a)??x(n.closest(r.tree.tag)),u=f?.parentElement??null;if(e(n,r.tree.tag)&&p(getComputedStyle(n))){let e=h(n,null,a);(e.inGap||!f)&&(u=n,c=e)}if(!c&&!f&&("body"!==n.localName&&e(n,r.tree.tag)?u=n:n.parentElement&&p(getComputedStyle(n.parentElement))?(f=n,u=n.parentElement):(f=n.closest("section,article,li,header,footer,aside,nav,p,div"),u=f?.parentElement??null)),!u||!e(u,r.tree.tag))return null;c??(c=h(u,f,a)),f=c.reference;let{before:d,marker:g}=c,y=e=>{let r=e.getAttribute("data-popmelt-placement-item");if(r&&/^[0-9a-f-]{36}$/.test(r))return`[data-popmelt-placement-item="${r}"]`;let n=e.getAttribute("data-popmelt-placement");return n&&e.getAttribute("data-pm")==="placed-"+n&&/^[0-9a-f-]{36}$/.test(n)?t(n):i(e)},j=t(r.id);return{target:u,pointer:a,marker:g,payload:{from:r.from,styles:[],texts:[],placedElement:{id:r.id,operation:"copy",selector:j,element:{selector:j,tagName:r.tree.tag},sampledTree:r.tree,pathname:r.pathname,sourceSelector:r.sourceSelector,targetParentSelector:y(u),referenceSelector:f?y(f):void 0,targetIndex:f?Array.from(u.children).indexOf(f)+(d?0:1):u.children.length,placement:d?"before":"after"}}}}function w(e,t,r,n){let a=e.domModifications.find(e=>e.sampledTree&&e.pathname===n&&!t.domModifications.some(t=>t.id===e.id));if(a?.sampledTree&&a.sourceSelector)return{kind:"element",tree:a.sampledTree,sourceSelector:a.sourceSelector,label:a.sampledTree.tag,id:a.id,from:r,pathname:n};let l=e.canvasSamples?.find(e=>e.subject?.inserted&&e.pathname===n&&!t.canvasSamples?.some(t=>t.pathname===n&&t.selector===e.selector));return l?.subject?.key.startsWith("placed-")?{kind:"object",format:l.format,value:l.value,label:l.subject.label??"object",id:l.subject.key.slice(7),from:r,pathname:n}:null}export{b as a,g as b,y as c,j as d,v as e,w as f};
|