@popmelt.com/core 0.23.0 → 0.24.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 (38) hide show
  1. package/README.md +30 -0
  2. package/claude-plugin/.claude-plugin/plugin.json +1 -1
  3. package/claude-plugin/skills/popmelt-core/SKILL.md +1 -0
  4. package/codex-plugin/.codex-plugin/plugin.json +1 -1
  5. package/codex-plugin/skills/popmelt-core/SKILL.md +1 -0
  6. package/dist/ParticipantRuntime-PTBGXKSH.mjs +139 -0
  7. package/dist/PreviewRuntime-2SCFCGWC.mjs +2 -0
  8. package/dist/adapter-react-three-fiber.mjs +1 -1
  9. package/dist/bridge-entry.mjs +85 -83
  10. package/dist/browser-runtime-3Z4U66AP.mjs +2 -0
  11. package/dist/browser.d.mts +2 -1
  12. package/dist/browser.mjs +1 -1
  13. package/dist/chunk-6URDGUIL.mjs +2 -0
  14. package/dist/chunk-BYLH3WFB.mjs +2 -0
  15. package/dist/chunk-C4ONFAGF.mjs +399 -0
  16. package/dist/{chunk-4IUZX7YN.mjs → chunk-DHAOAIKK.mjs} +1 -1
  17. package/dist/{chunk-EXYZQ76K.mjs → chunk-EUDGPGCQ.mjs} +1 -1
  18. package/dist/chunk-EX63NVDN.mjs +2 -0
  19. package/dist/chunk-J3UIBBU2.mjs +1 -1
  20. package/dist/chunk-M3HCNQ4T.mjs +250 -0
  21. package/dist/chunk-N2ZEZCHO.mjs +1 -1
  22. package/dist/cli.mjs +102 -98
  23. package/dist/index.d.mts +3 -3
  24. package/dist/index.mjs +1 -1
  25. package/dist/media.mjs +1 -1
  26. package/dist/{options-5yRxW1AX.d.mts → participantBootstrap-Dqu2h47B.d.mts} +22 -1
  27. package/dist/plugin-astro.d.mts +2 -0
  28. package/dist/plugin-astro.mjs +3 -3
  29. package/dist/plugin-nuxt.d.mts +3 -1
  30. package/dist/plugin-nuxt.mjs +2 -1
  31. package/dist/plugin-vite.mjs +1 -1
  32. package/dist/server-T4EMCHVP.mjs +228 -0
  33. package/dist/server.d.mts +121 -1
  34. package/dist/server.mjs +95 -84
  35. package/package.json +1 -1
  36. package/dist/browser-runtime-FWYFRPVT.mjs +0 -2
  37. package/dist/chunk-VHUJQWVP.mjs +0 -453
  38. package/dist/server-7AUQAYVY.mjs +0 -217
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{b as m,a as e}from"./chunk-M3HCNQ4T.mjs";import"./chunk-EX63NVDN.mjs";import"./chunk-N2ZEZCHO.mjs";import"./chunk-J3UIBBU2.mjs";import"./chunk-C4ONFAGF.mjs";import"./chunk-6URDGUIL.mjs";import{createElement as i}from"react";import{createRoot as n}from"react-dom/client";function p(o,t){let r=n(o);return r.render(i(m,t)),()=>{r.unmount(),e()}}export{p as mountBrowserRuntime};
@@ -1,4 +1,5 @@
1
- import { P as PopmeltOptions } from './options-5yRxW1AX.mjs';
1
+ import { P as PopmeltOptions } from './participantBootstrap-Dqu2h47B.mjs';
2
+ export { i as isPopmeltPreview } from './participantBootstrap-Dqu2h47B.mjs';
2
3
  import './subjects-DzjWdlAk.mjs';
3
4
  import './video-adapter-CCLbp86L.mjs';
4
5
 
package/dist/browser.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var p={unmount(){}},m="[data-popmelt-browser-host]";async function a(e={}){if(!e.enabled||typeof document>"u")return p;if(document.querySelector(`${m}, [data-popmelt-top-layer-host]`))throw new Error("Popmelt is already mounted. Unmount it before mounting again.");let o=document.createElement("div");o.setAttribute("data-popmelt-browser-host",""),o.setAttribute("data-devtools",""),document.documentElement.appendChild(o);let d=[["__POPMELT_PROJECT_ID__",e.projectId],["__POPMELT_BRIDGE_URL__",e.bridgeUrl]].flatMap(([t,n])=>{if(n===void 0)return[];let r=Object.prototype.hasOwnProperty.call(window,t),u=window[t],i=n??void 0;return window[t]=i,[()=>{window[t]===i&&(r?window[t]=u:delete window[t])}]}),s=()=>{o.remove();for(let t of d)t()};try{let{mountBrowserRuntime:t}=await import("./browser-runtime-FWYFRPVT.mjs");if(!o.isConnected)throw new Error("Popmelt mount was removed before startup.");let n=t(o,e),r=!0;return{unmount(){if(r){r=!1;try{n()}finally{s()}}}}}catch(t){throw s(),t}}export{a as mountPopmelt};
2
+ export{a as isPopmeltPreview}from"./chunk-EX63NVDN.mjs";var m={unmount(){}},u="[data-popmelt-browser-host]";async function p(o={}){if(!o.enabled||typeof document>"u")return m;if(document.querySelector(`${u}, [data-popmelt-top-layer-host]`))throw new Error("Popmelt is already mounted. Unmount it before mounting again.");let e=document.createElement("div");e.setAttribute("data-popmelt-browser-host",""),e.setAttribute("data-devtools",""),document.documentElement.appendChild(e);let d=[["__POPMELT_PROJECT_ID__",o.projectId],["__POPMELT_BRIDGE_URL__",o.bridgeUrl]].flatMap(([t,r])=>{if(r===void 0)return[];let n=Object.prototype.hasOwnProperty.call(window,t),l=window[t],i=r??void 0;return window[t]=i,[()=>{window[t]===i&&(n?window[t]=l:delete window[t])}]}),a=()=>{e.remove();for(let t of d)t()};try{let{mountBrowserRuntime:t}=await import("./browser-runtime-3Z4U66AP.mjs");if(!e.isConnected)throw new Error("Popmelt mount was removed before startup.");let r=t(e,o),n=!0;return{unmount(){if(n){n=!1;try{r()}finally{a()}}}}}catch(t){throw a(),t}}export{p as mountPopmelt};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var P=" >>> ";function $(t){return Array.from(t.querySelectorAll("*")).flatMap(e=>e.shadowRoot?[e.shadowRoot]:[])}function x(t=document){let e=[t];for(let r of e)e.push(...$(r));return e}function A(t){let e=t.split(P);if(e.length>1){let a=document,o=null;for(let n=0;n<e.length;n+=1){if(o=a.querySelector(e[n]),!o)return null;if(n<e.length-1){if(!o.shadowRoot)return null;a=o.shadowRoot}}return o}let r=[document];for(let a of r){let o=a.querySelector(t);if(o)return o;r.push(...$(a))}return null}function p(t){if(t.parentElement)return t.parentElement;let e=t.getRootNode();return e instanceof ShadowRoot?e.host:null}function k(t,e){let r=t;for(;r;){if(r.matches(e))return r;r=p(r)}return null}function te(t,e){let r=e;for(;r;){if(r===t)return!0;r=p(r)}return!1}function re(t,e,r){let a=typeof t.elementsFromPoint=="function"?t.elementsFromPoint(e,r):[],o=t.elementFromPoint?.(e,r)??null;return o&&!a.includes(o)?[o,...a]:a}function W(t,e){let r=[],a=new Set;for(let o of x().reverse())for(let n of re(o,t,e))a.has(n)||(a.add(n),r.push(n));return r}function N(){return P}var ae=["data-popmelt-media-id","data-testid","data-test","data-cy"];function oe(t){let e=t.getRootNode();if(!(e instanceof Document||e instanceof ShadowRoot))return null;for(let r of ae){let a=t.getAttribute(r);if(!a)continue;let o=`[${r}="${CSS.escape(a)}"]`;if(e.querySelectorAll(o).length===1)return o}return null}function ne(t){if(t.id)return`#${t.id}`;let e=t.tagName.toLowerCase(),r=Array.from(t.classList).slice(0,3).join(".");return r?`${e}.${r}`:e}function y(t){if(t.getRootNode()instanceof Document&&t.id&&!t.id.startsWith("radix-")&&!t.id.startsWith(":"))return`#${CSS.escape(t.id)}`;let e=[],r=t;for(;r&&r!==document.documentElement;){let a=r.tagName.toLowerCase(),o=oe(r);if(o?a=o:r.id&&!r.id.startsWith("radix-")&&!r.id.startsWith(":")&&(a=`#${CSS.escape(r.id)}`),!o&&!a.startsWith("#")){let l=Array.from(r.classList).filter(c=>!c.startsWith("_")&&c.length<30).slice(0,2);l.length>0&&(a+="."+l.map(c=>CSS.escape(c)).join("."))}let n=r.parentElement;if(n&&!o&&!a.startsWith("#")){let l=Array.from(n.children).filter(c=>c.tagName===r.tagName);if(l.length>1){let c=l.indexOf(r)+1;a+=`:nth-of-type(${c})`}}if(e.unshift(a),o||a.startsWith("#")){let l=r.getRootNode();if(l instanceof Document)break;if(l instanceof ShadowRoot){e.unshift(N().trim()),r=l.host;continue}}if(n){r=n;continue}let i=r.getRootNode();if(!(i instanceof ShadowRoot))break;e.unshift(N().trim()),r=i.host}return e.join(" > ").replace(/ > >>> > /g,N())}function m(t){try{return A(t)}catch{return null}}var I=["id","data-testid","data-test","data-cy","data-popmelt-media-id","aria-label","name","href"],R=t=>t.replace(/\s+/g," ").trim();function M(t){let e={};for(let o of I){let n=t.getAttribute(o);n&&n.length<=200&&!(o==="id"&&/^(radix-|:|_r_)/.test(n))&&(e[o]=n)}let r=R(t.querySelector("h1,h2,h3,h4,h5,h6")?.textContent??""),a=R(Array.from(t.childNodes).filter(o=>o.nodeType===3).map(o=>o.textContent).join(" "));return{tag:t.tagName.toLowerCase(),...Object.keys(e).length?{attributes:e}:{},...r&&r.length<=200?{heading:r}:{},...a&&a.length<=200?{text:a}:{}}}function _(t,e){let r=x(),a=s=>{try{return r.flatMap(f=>Array.from(f.querySelectorAll(s)))}catch{return[]}},o=!!(e&&(e.heading||e.text||Object.keys(e.attributes??{}).length)),n=s=>{if(!e||!o)return!0;let f=M(s);return f.tag===e.tag&&(!e.heading||f.heading===e.heading)&&(!e.text||f.text===e.text)&&Object.entries(e.attributes??{}).every(([d,u])=>s.getAttribute(d)===u)};for(let s of t){if(s.includes(" >>> ")){try{let d=A(s);if(d&&n(d))return{status:"matched",element:d}}catch{}continue}let f=a(s);if(f.length===1&&(/^\[data-pm=/.test(s)||!o))return{status:"matched",element:f[0]}}if(!o||t.some(s=>s.includes(" >>> "))||!/^[a-z][a-z0-9-]*$/.test(e.tag))return{status:"missing"};let i=a(e.tag);if(i.length>500)return{status:"ambiguous"};let l=Object.entries(e.attributes??{}).filter(([s])=>I.slice(0,5).includes(s));if(l.length){let s=i.filter(f=>l.every(([d,u])=>f.getAttribute(d)===u));return s.length===1?{status:"matched",element:s[0]}:{status:s.length?"ambiguous":"missing"}}let c=i.filter(n);return c.length===1?{status:"matched",element:c[0]}:{status:c.length?"ambiguous":"missing"}}function ie(t,e){let r=_([t,e?.selector].filter(a=>!!a),e?.targetFingerprint);return r.status==="matched"?r.element:null}var le=900,w=80;function h(t){if(!t)return null;try{return A(t)}catch{return null}}function S(t){return(t??"").replace(/\s+/g," ").trim()}function D(t){let e=S(t.getAttribute("aria-label"));if(e)return e.slice(0,w);let r=S(t.getAttribute("aria-labelledby"));if(r){let o=r.split(/\s+/).map(n=>S(document.getElementById(n)?.textContent)).filter(Boolean).join(" ");if(o)return o.slice(0,w)}let a=S(t.getAttribute("title"));return a?a.slice(0,w):S(t.textContent).slice(0,w)}function se(t){return t.id?Array.from(document.querySelectorAll("[aria-controls]")).find(e=>e.getAttribute("aria-controls")===t.id)??null:null}function ue(t){if(t instanceof HTMLDetailsElement){let a=Array.from(t.children).find(n=>n.tagName.toLowerCase()==="summary");if(!a)return null;let o=D(a);return o?{triggerSelector:y(a),targetSelector:y(t),label:o}:null}let e=se(t);if(!e)return null;let r=D(e);return r?{triggerSelector:y(e),targetSelector:y(t),label:r}:null}function C(t){let e=[],r=new Set,a=p(t);for(;a&&a!==document.body&&a!==document.documentElement;){let n=ue(a);n&&!r.has(n.triggerSelector)&&(r.add(n.triggerSelector),e.push(n)),a=p(a)}if(e.length===0)return;let o=e.reverse();return{steps:o,location:o.map(n=>n.label)}}function q(t){let e=t?.[0]?.revealRecipe;if(e?.steps.length)return e;let r=h(t?.[0]?.selector);return r?C(r):void 0}function ce(t){let e=q(t)?.location.filter(Boolean);return e?.length?`Inside: ${e.join(" \u203A ")}`:null}function T(t){if(!t?.isConnected)return!1;let e=t.getBoundingClientRect();if(e.width<=0||e.height<=0||t.getClientRects().length===0)return!1;let r=t;for(;r;){let a=window.getComputedStyle(r);if(a.display==="none"||a.visibility==="hidden"||a.visibility==="collapse"||Number.parseFloat(a.opacity||"1")<=0)return!1;r=r.parentElement}return!0}function fe(t,e,r){return e.getAttribute("aria-expanded")==="true"||e.getAttribute("data-state")==="open"?!0:r instanceof HTMLDetailsElement?r.open:T(r)}function B(t,e=le){return t?new Promise(r=>{let a=performance.now(),o=()=>{let n=h(t);if(T(n)){r(n);return}if(performance.now()-a>=e){r(null);return}requestAnimationFrame(o)};o()}):Promise.resolve(null)}function de(t,e){return h(t)??h(e?.[0]?.selector)}async function me(t,e){let r=de(t,e);if(T(r))return r;let a=q(e)??(r?C(r):void 0);if(!a)return null;for(let n of a.steps){let i=h(n.triggerSelector);if(!(i instanceof HTMLElement))return null;let l=h(n.targetSelector);if(!fe(n,i,l)&&(i.click(),!await B(n.targetSelector)))return null}let o=t&&h(t)?t:e?.[0]?.selector;return B(o)}function H(t){let e=Object.keys(t).find(n=>n.startsWith("__reactFiber$")||n.startsWith("__reactInternalInstance$"));if(!e)return null;let r=t[e],a=[],o=r?._debugSource;for(;r;){let n=r.type,i=n?.displayName||n?.name;i&&typeof i=="string"&&/^[A-Z]/.test(i)&&!i.startsWith("_")&&i!=="Fragment"&&a.unshift(i),r=r.return}return a.length>0?{name:a[a.length-1],path:a,...o?.fileName&&Number.isFinite(o.lineNumber)?{source:o}:{}}:null}function pe(t){let e=Object.keys(t).find(o=>o.startsWith("__reactFiber$")||o.startsWith("__reactInternalInstance$"));if(!e)return[];let r=t[e],a=[];for(;r;){let o=r.type,n=typeof o=="function"||typeof o=="object"?o?.displayName||o?.name:null;n&&typeof n=="string"&&/^[A-Z]/.test(n)&&!n.startsWith("_")&&n!=="Fragment"&&a.push({name:n,fiber:r}),r=r.return}return a.reverse(),a}function he(t){let e=t,r=new Set;for(;e&&!r.has(e);){if(r.add(e),e.stateNode instanceof Element)return e.stateNode;e.child?e=e.child:e=null}return null}function z(t){let e={targetFingerprint:M(t),selector:ne(t),tagName:t.tagName.toLowerCase()};t.id&&(e.id=t.id),t.classList.length>0&&(e.className=Array.from(t.classList).join(" "));let r=ge(t)||t.matches('button, a, [role="button"], [role="tab"]')&&(t.getAttribute("aria-label")||t.getAttribute("title")||t.textContent?.trim())||"";r&&r.length>0&&r.length<200&&(e.textContent=r);let a={};for(let l of t.attributes)l.name.startsWith("data-")&&(a[l.name]=l.value);Object.keys(a).length>0&&(e.dataAttributes=a);let o=H(t);o&&(e.reactComponent=o.name,e.reactComponentPath=o.path,o.source&&(e.reactSource=o.source));let n=ke(t);n&&(e.context=n);let i=C(t);return i&&(e.revealRecipe=i),e}function ge(t){let e="";for(let r of t.childNodes)r.nodeType===Node.TEXT_NODE&&(e+=r.textContent||"");return e.trim()}function be(t,e){return G(t,e)[0]??null}var ye="[data-popmelt-canvas-block]";function V(t,e){let r=W(t,e).find(a=>a.id!=="devtools-canvas"&&a.id!=="devtools-scrim");return!!(r&&k(r,ye))}function Se(t){return t instanceof SVGElement?t.closest("svg")??t:t}function G(t,e){if(V(t,e))return[];let r=new Set;return W(t,e).map(Se).filter(a=>r.has(a)||(r.add(a),a.id==="devtools-canvas"||a.id==="devtools-toolbar"||a.id==="devtools-scrim")||k(a,"#devtools-toolbar")||a.hasAttribute("data-devtools")||k(a,"[data-devtools]")?!1:!["html","body"].includes(a.tagName.toLowerCase()))}function je(t,e,r){for(let a of t.childNodes){if(a.nodeType!==Node.TEXT_NODE||!a.textContent?.trim())continue;let o=document.createRange();o.selectNodeContents(a);let n=o.getClientRects?.();if(n&&Array.from(n).some(i=>e>=i.left&&e<=i.right&&r>=i.top&&r<=i.bottom))return!0}return!1}function ve(t,e,r){if(je(t,e,r)||["button","canvas","embed","iframe","img","input","object","select","svg","textarea","video"].includes(t.tagName.toLowerCase()))return!0;let a=getComputedStyle(t);if(a.backgroundImage&&a.backgroundImage!=="none")return!0;let o=a.backgroundColor.trim();if(o&&o!=="transparent"&&!/rgba?\([^)]*,\s*0(?:\.0+)?\s*\)$/.test(o))return!0;let n=t.getBoundingClientRect(),i={top:Number.parseFloat(a.borderTopWidth)||0,right:Number.parseFloat(a.borderRightWidth)||0,bottom:Number.parseFloat(a.borderBottomWidth)||0,left:Number.parseFloat(a.borderLeftWidth)||0};return i.top>0&&r<=n.top+i.top||i.right>0&&e>=n.right-i.right||i.bottom>0&&r>=n.bottom-i.bottom||i.left>0&&e<=n.left+i.left}function Ae(t,e){let r=G(t,e);return r.find(a=>ve(a,t,e))??r.at(-1)??null}function ke(t){let e=p(t),r=["section","article","nav","aside","header","footer","main"];for(;e&&e!==document.body;){let a=e.tagName.toLowerCase();if(r.includes(a)&&e.id)return`${a}#${e.id}`;if(e.id&&!e.id.startsWith("radix-")&&!e.id.startsWith(":"))return`${a}#${e.id}`;e=p(e)}return null}function X(t){return Array.from(t,e=>{if(e==='"'||e==="\\")return`\\${e}`;let r=e.codePointAt(0);return r<32||r===127?`\\${r.toString(16)} `:e}).join("")}function U(t){return`[data-popmelt-subject-adapter="${X(t.adapter)}"][data-popmelt-subject-key="${X(t.key)}"]`}function we(t){let e=t?.getAttribute("data-popmelt-subject-adapter"),r=t?.getAttribute("data-popmelt-subject-key");return e&&r?{adapter:e,key:r}:void 0}function E(t,e){let r=!1;t.dataset.popmeltSubjectLabel!==e.label&&(t.dataset.popmeltSubjectLabel=e.label,r=!0);let{left:a,top:o,width:n,height:i}=e.bounds,l=u=>`${Math.round(u*2)/2}px`,c={left:l(a),top:l(o),width:l(Math.max(0,n)),height:l(Math.max(0,i))};for(let[u,b]of Object.entries(c)){let O=u;t.style[O]!==b&&(t.style[O]=b,r=!0)}let s=e.surfaceBounds,f={popmeltSubjectSurfaceLeft:s?String(s.left):void 0,popmeltSubjectSurfaceTop:s?String(s.top):void 0,popmeltSubjectSurfaceWidth:s?String(s.width):void 0,popmeltSubjectSurfaceHeight:s?String(s.height):void 0};for(let[u,b]of Object.entries(f))b===void 0?u in t.dataset&&(delete t.dataset[u],r=!0):t.dataset[u]!==b&&(t.dataset[u]=b,r=!0);let d=e.outline?.map(u=>`${u.x},${u.y}`).join(" ");return d?t.dataset.popmeltSubjectOutline!==d&&(t.dataset.popmeltSubjectOutline=d,r=!0):t.dataset.popmeltSubjectOutline!==void 0&&(delete t.dataset.popmeltSubjectOutline,r=!0),r}var xe=class{constructor(t){this.adapters=t,this.projections=new Map,this.frameListeners=new Set,this.frame=null,this.lastProjectionFrameTime=0,this.adapterUnsubscribes=t.flatMap(e=>{let r=e.subscribe?.(()=>{for(let a of this.frameListeners)a()});return r?[r]:[]})}async whenReady(){await Promise.all(this.adapters.map(t=>t.whenReady?.()))}hitTest(t){return this.hitTestAll(t)[0]??null}hitTestAll(t){for(let e=this.adapters.length-1;e>=0;e-=1){let r=this.adapters[e];if(!r)continue;let a=(r.hitTestAll?.(t)??[r.hitTest(t)]).filter(o=>!!o).map(o=>this.project(r,o));if(a.length>0)return a}return[]}resolve(t){let e=this.adapters.find(a=>a.id===t.adapter);if(!e)return null;let r=e.resolve(t.key);return r?this.project(e,r):null}restore(t,e){let r=this.adapters.find(o=>o.id===t.adapter),a=r?.restoreSubject?.(t.key,e);return r&&a?this.project(r,a):null}async captureFeedback(t){let e=this.resolve(t);if(!e)return null;let{adapter:r,subject:a}=e,o={...e.elementInfo};if(a.sourceElement&&(o.sourceElement={...z(a.sourceElement),selector:y(a.sourceElement)}),!r.captureSubject)return{elementInfo:o};try{let n=await r.captureSubject(t.key);return n?{elementInfo:o,crop:n}:{elementInfo:o,warning:"Object crop unavailable; use the page screenshot and image coordinates."}}catch{return{elementInfo:o,warning:"Object crop unavailable (the image may block canvas access via CORS); use the page screenshot and image coordinates."}}}beginCreate(t){for(let e=this.adapters.length-1;e>=0;e-=1){let r=this.adapters[e],a=r?.beginCreate?.(t);if(r&&a)return{adapter:r,session:a}}return null}rename(t,e){let r=this.adapters.find(o=>o.id===t.adapter),a=r?.renameSubject?.(t.key,e);return r&&a?this.project(r,a):null}updateBounds(t,e){let r=this.adapters.find(o=>o.id===t.adapter),a=r?.updateSubjectBounds?.(t.key,e);return r&&a?this.project(r,a):null}updateTrackingAnchors(t,e){let r=this.adapters.find(o=>o.id===t.adapter),a=r?.updateSubjectTrackingAnchors?.(t.key,e);return r&&a?this.project(r,a):null}promote(t){let e=this.adapters.find(a=>a.id===t.adapter),r=e?.promoteSubject?.(t.key);return e&&r?this.project(e,r):null}remove(t){this.adapters.find(e=>e.id===t.adapter)?.removeSubject?.(t.key)}async captureSurfaces(){return(await Promise.all(this.adapters.map(async t=>t.captureSurfaces?.()??[]))).flat()}subscribeFrame(t){return this.frameListeners.add(t),()=>this.frameListeners.delete(t)}destroy(){this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=null;for(let t of this.projections.values())t.element.remove();this.projections.clear();for(let t of this.adapterUnsubscribes)t();this.frameListeners.clear()}project(t,e){let r={adapter:t.id,key:e.key},a=`${t.id}\0${e.key}`,o=this.projections.get(a);if(o)return o.subject=e,o.elementInfo=this.elementInfo(t,e,o.selector),E(o.element,e),o;let n=U(r),i=document.createElement("div");i.dataset.popmeltSubjectAdapter=t.id,i.dataset.popmeltSubjectKey=e.key,i.dataset.popmeltSubjectLabel=e.label,i.dataset.popmeltSubjectProjection="true",i.setAttribute("aria-hidden","true"),Object.assign(i.style,{position:"fixed",pointerEvents:"none",opacity:"0",zIndex:"-1"}),E(i,e),document.body.appendChild(i);let l={adapter:t,subject:e,target:r,element:i,selector:n,elementInfo:this.elementInfo(t,e,n)};return this.projections.set(a,l),this.ensureFrame(),l}elementInfo(t,e,r){return{selector:r,tagName:t.id,subjectLabel:e.label,textContent:e.label,context:e.context,...e.imageObject?{imageObject:e.imageObject}:{},...e.videoObject?{videoObject:e.videoObject}:{},dataAttributes:{adapter:t.id,key:e.key,...e.data??{}}}}ensureFrame(){if(this.frame!==null||this.projections.size===0)return;let t=e=>{if(this.frame=null,this.lastProjectionFrameTime>0&&e-this.lastProjectionFrameTime<32){this.ensureFrame();return}this.lastProjectionFrameTime=e;let r=!1;for(let[a,o]of this.projections){let n=o.adapter.resolve(o.target.key);if(!n){o.element.remove(),this.projections.delete(a),r=!0;continue}o.subject=n,r=E(o.element,n)||r}if(r)for(let a of this.frameListeners)a();this.projections.size>0&&this.ensureFrame()};this.frame=requestAnimationFrame(t)}},Ne={isAnnotating:!1,activeTool:"inspector",activeColor:"oklch(0.628 0.258 29)",strokeWidth:3,annotations:[],undoStack:[],redoStack:[],selectedAnnotationIds:[],lastSelectedId:null,styleModifications:[],textModifications:[],domModifications:[],spacingTokenChanges:[],spacingTokenMods:[]};function j(t){return t instanceof HTMLElement||t instanceof SVGElement}var F=new WeakMap,v=new WeakMap;function Ce(t,e){if(j(e))for(let[r,a]of v.get(t)??[])a.value?e.style.setProperty(r,a.value,a.priority):e.style.removeProperty(r)}function Te(t,e){F.set(t,new Set(e))}function Ee(t){F.delete(t)}function Z(t,e){return j(t)&&(F.get(t)?.has(e)??!1)}function J(t){let e=t.sticker;return e?e.family==="padding"||e.family==="margin"?e.subproperty==="all"?10:e.subproperty==="x"||e.subproperty==="y"?20:30:e.family==="radius"||e.family==="border"?e.subproperty==="all"?10:20:10:0}function Fe(t){return t.changes.map((e,r)=>({change:e,index:r})).sort((e,r)=>J(e.change)-J(r.change)||e.index-r.index).map(({change:e})=>e)}function K(t,e,r){if(j(t)){let a=v.get(t);a||(a=new Map,v.set(t,a)),a.has(e)||a.set(e,{value:t.style.getPropertyValue(e),priority:t.style.getPropertyPriority(e)}),t.style.setProperty(e,r,"important")}}function Le(t,e,r,a=!1){if(j(t)){let o=a?v.get(t)?.get(e):void 0;o?.value?t.style.setProperty(e,o.value,o.priority):t.style.removeProperty(e),v.get(t)?.delete(e)}}function Q(t){let e=m(t.selector);if(!e&&t.durableSelector&&(e=m(t.durableSelector),e)){let r=t.selector.match(/\[data-pm="([^"]+)"\]/)?.[1];r&&e.setAttribute("data-pm",r)}return e}function Oe(t){for(let e of t){let r=Q(e);if(r)for(let a of Fe(e))Z(r,a.property)||K(r,a.property,a.modified)}}function Pe(t,e=!1){for(let r of t){let a=m(r.selector);if(a)for(let o of r.changes)Z(a,o.property)||Le(a,o.property,o.original,e)}}function Y(t){let e=m(t.selector);if(!e&&t.durableSelector&&(e=m(t.durableSelector),e)){let r=t.selector.match(/\[data-pm="([^"]+)"\]/)?.[1];r&&e.setAttribute("data-pm",r)}return e}function ee(t,e){let r=t;for(let a of e)r=r?.childNodes[a]??null;return r?.nodeType===Node.TEXT_NODE?r:null}function $e(t){for(let e of t){let r=Y(e);if(!r)continue;let a=ee(r,e.textNodePath);a&&(a.nodeValue=e.modified)}}function We(t){for(let e of t){let r=Y(e);if(!r)continue;let a=ee(r,e.textNodePath);a&&(a.nodeValue=e.original)}}function g(t,e){if(!t)return null;let r=m(t);if(!r&&e&&(r=m(e),r)){let a=t.match(/\[data-pm="([^"]+)"\]/)?.[1];a&&r.setAttribute("data-pm",a)}return r}function Ie(t){t.removeAttribute("data-pm"),t.querySelectorAll("[data-pm]").forEach(e=>e.removeAttribute("data-pm"))}function Re(t,e){let r=e.match(/\[data-pm="([^"]+)"\]/)?.[1];r&&t.setAttribute("data-pm",r)}function L(t,e,r){let a=Array.from(t.children).filter(n=>n!==e),o=Math.max(0,Math.min(r,a.length));t.insertBefore(e,a[o]??null)}function Me(t){for(let e of t){let r=g(e.targetParentSelector,e.targetParentDurableSelector);if(!r)continue;if(e.operation==="move"){let n=g(e.selector,e.durableSelector);if(!n||n===r||n.contains(r))continue;L(r,n,e.targetIndex);continue}if(g(e.selector,e.durableSelector))continue;let a=g(e.sourceSelector,e.sourceDurableSelector);if(!a)continue;let o=a.cloneNode(!0);o instanceof Element&&(Ie(o),Re(o,e.selector),L(r,o,e.targetIndex))}}function _e(t){for(let e of[...t].reverse()){if(e.operation==="copy"){g(e.selector,e.durableSelector)?.remove();continue}let r=g(e.selector,e.durableSelector),a=g(e.originalParentSelector,e.originalParentDurableSelector);!r||!a||r===a||r.contains(a)||L(a,r,e.originalIndex??a.children.length)}}export{K as A,Q as B,Oe as C,Pe as D,$e as E,We as F,Me as G,_e as H,x as a,A as b,p as c,k as d,te as e,y as f,m as g,ce as h,me as i,H as j,pe as k,he as l,_ as m,ie as n,z as o,be as p,V as q,Ae as r,U as s,we as t,xe as u,Ne as v,j as w,Ce as x,Te as y,Ee as z};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{u as v,v as P,G as R,C as x,E as A,n as C,F as g,D as b,H as y}from"./chunk-6URDGUIL.mjs";var O="__popmelt_code_preview";function D(a,r){let t=new URL(a,r);if(t.origin!==new URL(r).origin||!/^https?:$/.test(t.protocol))throw new Error("Code previews must use the same application origin");return t.hash="",t.searchParams.delete("popmelt"),t.searchParams.set(O,"1"),t.href}function T(a,r){if(!new URL(location.href).searchParams.has(O))return!1;if(parent===window)return!0;window.__POPMELT_CODE_PREVIEW__?.dispose();let t=P,w="",s=!1,u=0,d=new Map,_=()=>{for(let[e,i]of d)i===null?e.removeAttribute("data-pm"):e.setAttribute("data-pm",i);d.clear()},n=new v(r?.get()??[]),m=()=>{for(let e of t.annotations)e.target&&n.resolve(e.target)},h=()=>{R(t.domModifications),x(t.styleModifications),A(t.textModifications),m();for(let e of t.annotations){let i=e.linkedSelector?.match(/^\[data-pm="([^"]+)"\]$/)?.[1];if(!i)continue;let o=C(e.linkedSelector,e.elements?.[0]);o&&(d.has(o)||d.set(o,o.getAttribute("data-pm")),o.setAttribute("data-pm",i))}},c=new MutationObserver(e=>{e.some(i=>i.addedNodes.length)&&(cancelAnimationFrame(u),u=requestAnimationFrame(()=>{c.disconnect(),h(),p()}))}),p=()=>c.observe(document.body,{childList:!0,subtree:!0}),E=()=>{let e=n;e.whenReady().then(()=>{!s&&n===e&&(m(),document.dispatchEvent(new Event("popmelt-subjects-ready")))})},L=r?.subscribe(()=>{n.destroy(),n=new v(r.get()),m(),E()});E();let f={dispose(){s||(s=!0,c.disconnect(),L?.(),n.destroy(),cancelAnimationFrame(u),window.removeEventListener("pagehide",f.dispose),window.__POPMELT_CODE_PREVIEW__===f&&delete window.__POPMELT_CODE_PREVIEW__,g(t.textModifications),b(t.styleModifications,!0),y(t.domModifications),_())},source:a,getSubjects:()=>n,update(e){if(s)throw new Error("Preview runtime closed");if(e.draft.source&&e.draft.source.sourceId!==a.sourceId)throw new Error("This draft belongs to a different source");let i=JSON.stringify([e.planeId,e.draft.revision,e.draft.source?.sourceId,e.draft.source?.revision]);if(w===i)return;let o=structuredClone(e.draft.state??P),l=M=>!M.pathname||M.pathname===location.pathname,I={...o,annotations:o.annotations.filter(l),styleModifications:o.styleModifications.filter(l),textModifications:o.textModifications.filter(l),domModifications:o.domModifications.filter(l)};c.disconnect(),g(t.textModifications),b(t.styleModifications,!0),y(t.domModifications),_(),t=I,h(),p(),w=i}};return window.__POPMELT_CODE_PREVIEW__=f,p(),window.addEventListener("pagehide",f.dispose,{once:!0}),!0}export{D as a,T as b};