payload-live-preview 2.0.4 → 2.0.5

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/dist/plugins.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function t(t){return(...n)=>{try{e(t(...n))}catch{}}}var n=t((...e)=>console.error(...e)),i=()=>{},r=class{#e;#t;#n=/* @__PURE__ */new Set;#i="staging";constructor(e,t){this.#e=e,this.#t=t}assertOpen(){if("closed"===this.#i)throw new Error(`Plugin context for "${this.#e}" is no longer active`)}get active(){return"active"===this.#i}eligible(){return"closed"!==this.#i}own(e){return this.assertOpen(),this.#r({kind:"cleanup",acquire:void 0,finalize:void 0,cleanup:e,disposed:!1})}stage(e,t,n){this.assertOpen();const i={kind:e,acquire:t,finalize:n,cleanup:void 0,disposed:!1},r=this.#r(i);if("active"===this.#i)try{this.#o(i)}catch(e){throw this.#s(i),e}return r}counts(){const e={transform:0,renderer:0,subscription:0,cleanup:0};for(const t of this.#n)e[t.kind]+=1;return e}commit(){if("staging"!==this.#i)throw new Error(`Plugin context for "${this.#e}" cannot be committed`);this.#i="committing";try{for(const e of this.#n)this.#o(e);this.#i="active"}catch(e){throw this.close(),e}}close(){if("closed"!==this.#i){this.#i="closed";for(const e of[...this.#n].reverse())this.#s(e);this.#n.clear()}}#r(e){return this.#n.add(e),()=>{this.#s(e)}}#o(e){if(e.disposed||void 0!==e.cleanup||void 0===e.acquire)return;const t=e.acquire();e.cleanup=t??i}#s(t){if(t.disposed)return;t.disposed=!0,this.#n.delete(t);const n=t.cleanup;if(t.cleanup=void 0,void 0!==n)try{e(n())&&this.#t(`plugin "${this.#e}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(e){this.#t(`plugin "${this.#e}" cleanup failed:`,e)}try{t.finalize?.()}catch(e){this.#t(`plugin "${this.#e}" cleanup failed:`,e)}}},o=class{#a;#l;#u=/* @__PURE__ */new Set;constructor(e,t){this.#a=e,this.#l=t}on(e,t){return this.#c("on",e,t)}once(e,t){return this.#c("once",e,t)}off(e,t){const n=t;for(const t of[...this.#u])t.event===e&&t.handler===n&&t.dispose()}emit(e,t){return this.#l.assertOpen(),this.#a.emit(e,t)}emitWhile(e,t,n){return this.#l.assertOpen(),this.#a.emitWhile(e,t,()=>{if(!this.#l.eligible())return!1;const e=n();return!!this.#l.eligible()&&e})}listenerCount(e){let t=0;for(const n of this.#u)n.event===e&&(t+=1);return t}removeAllListeners(e){for(const t of[...this.#u])void 0!==e&&t.event!==e||t.dispose()}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#u)e.add(t.event);return[...e]}#c(e,t,n){this.#l.assertOpen();const r=n,o=[...this.#u].find(n=>n.kind===e&&n.event===t&&n.handler===r);if(void 0!==o)return o.dispose;let s=i,a=!0;const l=async t=>{this.#l.active&&a&&("once"===e&&s(),await n(t))},u={kind:e,event:t,handler:r,dispose:i};return s=this.#l.stage("subscription",()=>this.#a[e](t,l),()=>{a=!1,this.#u.delete(u)}),u.dispose=s,this.#u.add(u),s}},s="payload-live-preview-highlight",a=/* @__PURE__ */new WeakMap,l=/* @__PURE__ */new WeakMap,u={name:"highlight",version:"1.0.0",init:e=>{if("undefined"==typeof document||"undefined"==typeof window)return;const t="function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=function(e,t){let n=a.get(e);void 0===n||n.connected()||(a.delete(e),n=void 0),void 0===n&&(n=function(e,t){const n=e.getElementById(s);if(n instanceof HTMLStyleElement)return{pluginOwned:!1,connected:()=>n.isConnected,remove:()=>{},owners:0};const i=function(e,t){try{if(!Array.isArray(e.adoptedStyleSheets)||"function"!=typeof CSSStyleSheet)return;const n=new CSSStyleSheet;if("function"!=typeof n.replaceSync)return;return n.replaceSync(t),e.adoptedStyleSheets=[...e.adoptedStyleSheets,n],n}catch{return}}(e,t);if(void 0!==i)return{pluginOwned:!0,connected:()=>e.adoptedStyleSheets.includes(i),remove:()=>{e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==i)},owners:0};const r=e.createElement("style");return r.id=s,r.textContent=t,e.head.appendChild(r),{pluginOwned:!0,connected:()=>r.isConnected,remove:()=>{r.remove()},owners:0}}(e,t?".lp-highlight{outline:2px solid rgba(0,102,204,0.85);outline-offset:2px;}":"@keyframes lp-highlight{0%{outline:2px solid rgba(0,102,204,0.85);outline-offset:2px}100%{outline:2px solid transparent;outline-offset:2px}}.lp-highlight{animation:lp-highlight 0.6s ease-out;}"),a.set(e,n));const i=n;i.owners+=1;let r=!0;return()=>{r&&(r=!1,i.owners-=1,i.owners>0||(a.get(e)===i&&a.delete(e),i.pluginOwned&&i.remove()))}}(document,t),i=t?1e3:600,r=/* @__PURE__ */new WeakMap,o=/* @__PURE__ */new Set;e.registerCleanup?.(()=>{for(const e of[...o])e();n()}),e.events.on("elementUpdate",e=>{const t=e.element;r.get(t)?.();const n=function(e){let t=l.get(e);void 0===t&&(t={owners:0,pluginAdded:!e.classList.contains("lp-highlight")},l.set(e,t));const n=t;n.owners+=1,e.classList.add("lp-highlight");let i=!0;return()=>{i&&(i=!1,n.owners-=1,n.owners>0||(l.delete(e),n.pluginAdded&&e.classList.remove("lp-highlight")))}}(t);let s=!1;const a=()=>{s||(s=!0,window.clearTimeout(u),r.get(t)===a&&r.delete(t),o.delete(a),n())},u=window.setTimeout(a,i);o.add(a),r.set(t,a)})}},c={name:"debug",version:"1.0.0",init:e=>{e.events.on("init",()=>{e.log("init")}),e.events.on("connect",t=>{e.log("connect ←",t.origin)}),e.events.on("disconnect",t=>{e.log("disconnect (",t.reason,")")}),e.events.on("cacheRefresh",t=>{e.log("cacheRefresh",t.elementCount,"elements,",t.fieldCount,"fields")}),e.events.on("beforeUpdate",t=>{e.log("beforeUpdate",Object.keys(t.data.fields).length,"fields")}),e.events.on("afterUpdate",t=>{e.log("afterUpdate",t.updatedCount,"in",t.durationMs.toFixed(2),"ms")}),e.events.on("error",t=>{e.log("error in",t.context,":",t.error.message)})}},d="payload-live-preview:scroll";function h(){"undefined"!=typeof window&&(function(){if("undefined"!=typeof window)try{sessionStorage.setItem(d,JSON.stringify({href:window.location.href,x:window.scrollX,y:window.scrollY}))}catch{}}(),window.location.reload())}var f="data-payload-field",p="data-payload-guessed",g=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]),m="payload-live-preview-unbound",v={"bottom-right":"bottom:12px;right:12px;","bottom-left":"bottom:12px;left:12px;","top-right":"top:12px;right:12px;","top-left":"top:12px;left:12px;"};function y(e,t,n){const i=function(e,t){const n=new Set(e),i=e=>{if(n.has(e))return!0;const t=`${e}.`;for(const e of n)if(e.startsWith(t))return!0;return!1};return e=>{if(i(e))return!0;const n=function(e,t){if(void 0===t||0===t.length)return e;const n=`_${t}`;return e.endsWith(n)?e.slice(0,-n.length):e}(e,t);return n!==e&&i(n)}}(t,n);return Object.keys(e).filter(e=>!g.has(e)&&!i(e)).sort((e,t)=>e.localeCompare(t))}function w(e,t){const n=e.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.setAttribute("style","position:fixed;opacity:0;pointer-events:none;"),e.body.append(n),n.select(),n.remove()}function b(e,t,n){const i=e.createElement("button");return i.type="button",i.textContent=n,i.setAttribute("style","display:block;width:100%;text-align:left;margin:2px 0;padding:2px 4px;border:0;border-radius:3px;background:#222;color:#7fd1ff;font:inherit;cursor:pointer;"),i.title=`Copy ${f}="${t}"`,i.addEventListener("click",()=>{!function(e,t){const n=e.defaultView?.navigator.clipboard;null==n?w(e,t):n.writeText(t).catch(()=>{w(e,t)})}(e,`${f}="${t}"`),i.textContent=`${n} ✓`}),i}var P=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"});exports.DIAGNOSTIC_CODES=P,exports.EventEmitter=class{#d=/* @__PURE__ */new Map;#h=/* @__PURE__ */new Map;on(e,t){return this.#f(this.#d,e,t)}once(e,t){return this.#f(this.#h,e,t)}off(e,t){this.#p(this.#d,e,t),this.#p(this.#h,e,t)}async emit(e,t){await this.#g(e,t)}async emitWhile(e,t,n){return this.#g(e,t,n)}async#g(e,t,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#d.get(e);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#m(n,t,e),!i())return!1}if(!i())return!1;const o=this.#h.get(e);if(o&&o.size>0){const n=[...o];this.#h.delete(e);for(const r of n){if(!i())return!1;if(await this.#m(r,t,e),!i())return!1}}return i()}listenerCount(e){return(this.#d.get(e)?.size??0)+(this.#h.get(e)?.size??0)}removeAllListeners(e){if(void 0===e)return this.#d.clear(),void this.#h.clear();this.#d.delete(e),this.#h.delete(e)}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#d.keys())e.add(t);for(const t of this.#h.keys())e.add(t);return[...e]}#f(e,t,n){let i=e.get(t);return i||(i=/* @__PURE__ */new Set,e.set(t,i)),i.add(n),()=>{this.#p(e,t,n)}}#p(e,t,n){const i=e.get(t);void 0!==i&&(i.delete(n),0===i.size&&e.delete(t))}async#m(e,t,i){try{await e(t)}catch(e){const t="string"==typeof i||"number"==typeof i?String(i):"<event>";n(`[live-preview] LP0601: handler for "${t}" threw:`,e)}}},exports.PluginManager=class{#a;#v;#y;#w;#t;#b=/* @__PURE__ */new Map;#P=/* @__PURE__ */new Map;#S=/* @__PURE__ */new Map;#x=/* @__PURE__ */new Set;#L=/* @__PURE__ */new Map;#k=Promise.resolve();#A=0;constructor(e){this.#a=e.events,this.#v=e.config,this.#y=e.registerFieldRenderer,this.#t=t(e.log);const n=e.onTransformError;this.#w=void 0===n?void 0:t((...e)=>{const t=e[0];try{return n(t)}catch(e){return void this.#t("transform error reporter failed:",e)}})}register(e){return this.#A>0?this.#N(e,!1):this.#C(()=>this.#N(e,!0))}unregister(e){return this.#A>0?this.#$(e,!1):this.#C(async()=>{await this.#$(e,!0)})}destroyAll(){return this.#A>0?this.#T(!1):this.#C(async()=>{await this.#T(!0)})}applyTransforms(t,n,i,r){const o=this.#L.get(t);if(void 0===o||0===o.length)return n;let s=n;for(const a of[...o]){if(!a.active)continue;const{transform:o}=a;if(!1===r?.())return n;try{s=o(s,{fieldName:t,element:i.element,allFields:i.allFields});const a=e(s);if(!1===r?.())return n;if(a)throw new TypeError(`Transform for "${t}" returned a Promise/thenable; transforms must be synchronous`)}catch(e){if(!1===r?.())return n;const i=e instanceof Error?e:new Error(String(e));return this.#t(`transform for "${t}" failed:`,i),this.#w?.(i),n}}return s}list(){return[...this.#b.keys()]}snapshot(){const e=[],t=(e,t,n,i)=>{const r=i.counts();return{name:e,version:t,state:n,registrations:{transforms:r.transform,renderers:r.renderer,subscriptions:r.subscription,cleanups:r.cleanup}}};for(const[n,i]of this.#P)e.push(t(n,void 0,"initializing",i.scope));for(const[n,i]of this.#b)e.push(t(n,i.plugin.version,"active",i.scope));for(const t of this.#S.keys())e.push({name:t,version:void 0,state:"tearing-down",registrations:{transforms:0,renderers:0,subscriptions:0,cleanups:0}});return e}get size(){return this.#b.size}async#N(e,t){if(this.#b.has(e.name)||this.#P.has(e.name)||this.#S.has(e.name))return void this.#t(`plugin "${e.name}" already registered`);const n=function(e,t){if(void 0!==e){if(void 0!==e.runtime&&!function(e,t){const n=function(e){const t=/^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());if(null!==t)return[Number(t[1]),Number(t[2]),Number(t[3])]}(e);return void 0!==n&&t.split("||").some(e=>{const i=e.trim().split(/\s+/).filter(e=>e.length>0);return 0===i.length?""===e.trim()&&""===t.trim():i.every(e=>function(e,t){const n=t.trim();if(""===n||"*"===n)return!0;const i=/^(\^|~|>=|<=|>|<|=)?\s*v?(\d+)\.(\d+)\.(\d+)/.exec(n);if(null===i)return!1;const r=i[1]??"=",o=[Number(i[2]),Number(i[3]),Number(i[4])],s=function(e,t){for(let n=0;n<3;n+=1){const i=(e[n]??0)-(t[n]??0);if(0!==i)return i}return 0}(e,o);switch(r){case"=":return 0===s;case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"~":return s>=0&&e[0]===o[0]&&e[1]===o[1];case"^":return!(s<0)&&(o[0]>0?e[0]===o[0]:o[1]>0?0===e[0]&&e[1]===o[1]:0===e[0]&&0===e[1]&&e[2]===o[2]);default:return!1}}(n,e))})}(t,e.runtime))return`declares runtime ${e.runtime}, this runtime is ${t}`;if(void 0!==e.protocol){if(!Number.isInteger(e.protocol)||e.protocol<1)return`declares an invalid protocol version ${String(e.protocol)}`;if(e.protocol<4)return`declares protocol ${String(e.protocol)}, this runtime speaks ${String(4)}`}}}(e.compat,"2.0.4");if(void 0!==n)return void this.#O(e.name,n);const i=new r(e.name,this.#t),o=this.#E(e.name,i),s={scope:i,cancelled:!1};this.#P.set(e.name,s);try{if(await this.#U(()=>e.init(o),t),s.cancelled)return;i.commit()}catch(t){return i.close(),void(s.cancelled||this.#t(`plugin "${e.name}" init failed:`,t))}finally{this.#P.get(e.name)===s&&this.#P.delete(e.name)}this.#b.set(e.name,{plugin:e,scope:i}),this.#t(`plugin "${e.name}" registered`)}#O(e,t){const n=`plugin "${e}" refused: ${t}`;this.#t(n),this.#a.emit("error",{error:new Error(n),context:"plugin",code:"LP0103"})}#E(e,t){return{events:new o(this.#a,t),registerFieldRenderer:e=>{t.stage("renderer",()=>{const t=this.#y(e);return"function"==typeof t?t:void 0})},registerTransform:(e,n)=>{const i={transform:n,active:!1};t.stage("transform",()=>{i.active=!0;const t=this.#L.get(e);return void 0===t?this.#L.set(e,[i]):t.push(i),()=>{i.active=!1;const t=this.#L.get(e);if(void 0===t)return;const n=t.indexOf(i);n>=0&&t.splice(n,1),0===t.length&&this.#L.delete(e)}})},registerCleanup:e=>{t.own(e)},getConfig:()=>this.#v,log:(...t)=>{this.#t(`[${e}]`,...t)}}}#$(e,t){const n=this.#P.get(e);if(void 0!==n)return n.cancelled=!0,n.scope.close(),Promise.resolve();const i=this.#S.get(e);if(void 0!==i)return this.#x.has(e)?Promise.resolve():t?this.#F(i):i;const r=this.#b.get(e);if(void 0===r)return Promise.resolve();this.#b.delete(e),r.scope.close();const o=Promise.resolve().then(()=>this.#z(e,r.plugin,t));return this.#S.set(e,o),o.then(()=>{this.#S.get(e)===o&&this.#S.delete(e)}),o}async#z(e,t,n){if(void 0!==t.destroy){this.#x.add(e);try{await this.#U(()=>t.destroy?.(),n)}catch(t){this.#t(`plugin "${e}" destroy failed:`,t)}finally{this.#x.delete(e)}}}async#T(e){for(const e of this.#P.values())e.cancelled=!0,e.scope.close();const t=[...this.#b.keys()];for(const n of t)await this.#$(n,e)}async#U(e,t){t?await this.#F(Promise.resolve().then(e)):await e()}async#F(e){this.#A+=1;try{await e}finally{this.#A-=1}}#C(e){const t=this.#k.then(e);return this.#k=t.catch(e=>{this.#t("plugin manager mutation failed:",e)}),t}},exports.createAnalyticsPlugin=function(){let e=0,t=0,n=0;return{name:"analytics",version:"1.0.0",init:i=>{i.events.on("afterUpdate",i=>{e+=1,t+=i.updatedCount,n+=i.durationMs})},getStats:()=>({updateCount:e,totalElements:t,totalDurationMs:n,averageDurationMs:0===e?0:n/e})}},exports.createUnboundFieldsOverlayPlugin=function(e={}){return{name:"unbound-fields",version:"1.0.0",init:t=>{const n=e.root??("undefined"==typeof document?void 0:document);if(void 0===n)return;if((e.onlyWithDebug??1)&&!0!==t.getConfig().debug)return void t.log("not mounted: the client runs without `debug: true`");const i=function(e,t){const n=function(e){return 9===e.nodeType?e:e.ownerDocument}(e);if(null==n?.body)return null;const i=n.createElement("aside");i.id=m,i.setAttribute("style","position:fixed;z-index:2147483646;max-width:280px;max-height:40vh;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;background:#111;color:#eee;border:1px solid #333;border-radius:6px;padding:8px 10px;box-shadow:0 4px 16px rgba(0,0,0,0.4);"+t),i.setAttribute("aria-hidden","true"),i.hidden=!0;const r=e=>{const t=n.createElement("div");return t.textContent=e,t.setAttribute("style","font-weight:600;margin-bottom:4px;"),t},o=r("Unbound fields"),s=n.createElement("div"),a=r("Guessed bindings");a.setAttribute("data-testid","guessed-bindings");const l=n.createElement("div");return i.append(o,s,a,l),n.body.append(i),{update:(e,t)=>{i.isConnected||(n.getElementById(m)?.remove(),n.body.append(i)),i.hidden=0===e.length&&0===t.length,o.hidden=0===e.length,s.replaceChildren(...e.map(e=>b(n,e,e))),a.hidden=0===t.length,l.replaceChildren(...t.map(({field:e,matched:t})=>b(n,e,`${e} ← ${JSON.stringify(t)}`)))},destroy:()=>{i.remove()}}}(n,v[e.position??"bottom-right"]);null!==i&&(t.registerCleanup?.(i.destroy),t.events.on("afterUpdate",e=>{const r=y(e.data.fields,function(e){const t=[];for(const n of e.querySelectorAll(`[${f}]`)){const e=n.getAttribute(f);null!==e&&e.length>0&&t.push(e)}return t}(n),e.data.locale),o=function(e){const t=[];for(const n of e.querySelectorAll(`[${p}]`)){const e=n.getAttribute(f);null!==e&&0!==e.length&&t.push({field:e,matched:n.getAttribute(p)??""})}return t}(n);i.update(r,o),r.length>0&&t.log("unbound:",r.join(", ")),o.length>0&&t.log("guessed:",o.map(e=>e.field).join(", "))}))}}},exports.debugPlugin=c,exports.documentSavePlugin=function(e={}){const t=e.strategy??"silent";return{name:"document-save",version:"1.1.0",init:n=>{let i=!0;const r=/* @__PURE__ */new Set;n.registerCleanup?.(()=>{i=!1;for(const e of r)e.abort();r.clear()}),function(){if("undefined"!=typeof window)try{const e=sessionStorage.getItem(d);if(null===e)return;sessionStorage.removeItem(d);const t=JSON.parse(e);if(t.href!==window.location.href)return;window.scrollTo(t.x??0,t.y??0)}catch{}}(),n.events.on("documentSave",()=>{if(!i)return;if("silent"===t)return;if("reload"===t)return void h();const o=new AbortController;r.add(o);const s="fetch"===t?async function(e,t,n){if(e.handler)try{await e.handler(n)}catch(e){if(!i||n.aborted)return;t("document-save handler threw:",e)}else t("document-save: fetch strategy selected but no handler supplied")}(e,n.log,o.signal):async function(e,t,n,i){if("undefined"==typeof fetch)return void t("document-save: revalidate strategy needs fetch — not available");const r=e.revalidateUrl??"/api/revalidate";let o=!1;try{const s=await fetch(r,{method:"POST",signal:n,headers:{"Content-Type":"application/json",...e.revalidateHeaders??{}},body:JSON.stringify({source:"payload-live-preview"})});if(!i()||n.aborted)return;o=s.ok,o||t("document-save revalidate non-2xx:",s.status)}catch(e){if(!i()||n.aborted)return;t("document-save revalidate failed:",e)}o||"reload"!==e.onRevalidateFailure||h()}(e,n.log,o.signal,()=>i);s.finally(()=>{r.delete(o)})})}}},exports.highlightPlugin=u,exports.unboundFieldNames=y;
1
+ "use strict";function e(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function t(t){return(...n)=>{try{e(t(...n))}catch{}}}var n=t((...e)=>console.error(...e)),i=()=>{},r=class{#e;#t;#n=/* @__PURE__ */new Set;#i="staging";constructor(e,t){this.#e=e,this.#t=t}assertOpen(){if("closed"===this.#i)throw new Error(`Plugin context for "${this.#e}" is no longer active`)}get active(){return"active"===this.#i}eligible(){return"closed"!==this.#i}own(e){return this.assertOpen(),this.#r({kind:"cleanup",acquire:void 0,finalize:void 0,cleanup:e,disposed:!1})}stage(e,t,n){this.assertOpen();const i={kind:e,acquire:t,finalize:n,cleanup:void 0,disposed:!1},r=this.#r(i);if("active"===this.#i)try{this.#o(i)}catch(e){throw this.#s(i),e}return r}counts(){const e={transform:0,renderer:0,subscription:0,cleanup:0};for(const t of this.#n)e[t.kind]+=1;return e}commit(){if("staging"!==this.#i)throw new Error(`Plugin context for "${this.#e}" cannot be committed`);this.#i="committing";try{for(const e of this.#n)this.#o(e);this.#i="active"}catch(e){throw this.close(),e}}close(){if("closed"!==this.#i){this.#i="closed";for(const e of[...this.#n].reverse())this.#s(e);this.#n.clear()}}#r(e){return this.#n.add(e),()=>{this.#s(e)}}#o(e){if(e.disposed||void 0!==e.cleanup||void 0===e.acquire)return;const t=e.acquire();e.cleanup=t??i}#s(t){if(t.disposed)return;t.disposed=!0,this.#n.delete(t);const n=t.cleanup;if(t.cleanup=void 0,void 0!==n)try{e(n())&&this.#t(`plugin "${this.#e}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(e){this.#t(`plugin "${this.#e}" cleanup failed:`,e)}try{t.finalize?.()}catch(e){this.#t(`plugin "${this.#e}" cleanup failed:`,e)}}},o=class{#a;#l;#u=/* @__PURE__ */new Set;constructor(e,t){this.#a=e,this.#l=t}on(e,t){return this.#c("on",e,t)}once(e,t){return this.#c("once",e,t)}off(e,t){const n=t;for(const t of[...this.#u])t.event===e&&t.handler===n&&t.dispose()}emit(e,t){return this.#l.assertOpen(),this.#a.emit(e,t)}emitWhile(e,t,n){return this.#l.assertOpen(),this.#a.emitWhile(e,t,()=>{if(!this.#l.eligible())return!1;const e=n();return!!this.#l.eligible()&&e})}listenerCount(e){let t=0;for(const n of this.#u)n.event===e&&(t+=1);return t}removeAllListeners(e){for(const t of[...this.#u])void 0!==e&&t.event!==e||t.dispose()}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#u)e.add(t.event);return[...e]}#c(e,t,n){this.#l.assertOpen();const r=n,o=[...this.#u].find(n=>n.kind===e&&n.event===t&&n.handler===r);if(void 0!==o)return o.dispose;let s=i,a=!0;const l=async t=>{this.#l.active&&a&&("once"===e&&s(),await n(t))},u={kind:e,event:t,handler:r,dispose:i};return s=this.#l.stage("subscription",()=>this.#a[e](t,l),()=>{a=!1,this.#u.delete(u)}),u.dispose=s,this.#u.add(u),s}},s="payload-live-preview-highlight",a=/* @__PURE__ */new WeakMap,l=/* @__PURE__ */new WeakMap,u={name:"highlight",version:"1.0.0",init:e=>{if("undefined"==typeof document||"undefined"==typeof window)return;const t="function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=function(e,t){let n=a.get(e);void 0===n||n.connected()||(a.delete(e),n=void 0),void 0===n&&(n=function(e,t){const n=e.getElementById(s);if(n instanceof HTMLStyleElement)return{pluginOwned:!1,connected:()=>n.isConnected,remove:()=>{},owners:0};const i=function(e,t){try{if(!Array.isArray(e.adoptedStyleSheets)||"function"!=typeof CSSStyleSheet)return;const n=new CSSStyleSheet;if("function"!=typeof n.replaceSync)return;return n.replaceSync(t),e.adoptedStyleSheets=[...e.adoptedStyleSheets,n],n}catch{return}}(e,t);if(void 0!==i)return{pluginOwned:!0,connected:()=>e.adoptedStyleSheets.includes(i),remove:()=>{e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==i)},owners:0};const r=e.createElement("style");return r.id=s,r.textContent=t,e.head.appendChild(r),{pluginOwned:!0,connected:()=>r.isConnected,remove:()=>{r.remove()},owners:0}}(e,t?".lp-highlight{outline:2px solid rgba(0,102,204,0.85);outline-offset:2px;}":"@keyframes lp-highlight{0%{outline:2px solid rgba(0,102,204,0.85);outline-offset:2px}100%{outline:2px solid transparent;outline-offset:2px}}.lp-highlight{animation:lp-highlight 0.6s ease-out;}"),a.set(e,n));const i=n;i.owners+=1;let r=!0;return()=>{r&&(r=!1,i.owners-=1,i.owners>0||(a.get(e)===i&&a.delete(e),i.pluginOwned&&i.remove()))}}(document,t),i=t?1e3:600,r=/* @__PURE__ */new WeakMap,o=/* @__PURE__ */new Set;e.registerCleanup?.(()=>{for(const e of[...o])e();n()}),e.events.on("elementUpdate",e=>{const t=e.element;r.get(t)?.();const n=function(e){let t=l.get(e);void 0===t&&(t={owners:0,pluginAdded:!e.classList.contains("lp-highlight")},l.set(e,t));const n=t;n.owners+=1,e.classList.add("lp-highlight");let i=!0;return()=>{i&&(i=!1,n.owners-=1,n.owners>0||(l.delete(e),n.pluginAdded&&e.classList.remove("lp-highlight")))}}(t);let s=!1;const a=()=>{s||(s=!0,window.clearTimeout(u),r.get(t)===a&&r.delete(t),o.delete(a),n())},u=window.setTimeout(a,i);o.add(a),r.set(t,a)})}},c={name:"debug",version:"1.0.0",init:e=>{e.events.on("init",()=>{e.log("init")}),e.events.on("connect",t=>{e.log("connect ←",t.origin)}),e.events.on("disconnect",t=>{e.log("disconnect (",t.reason,")")}),e.events.on("cacheRefresh",t=>{e.log("cacheRefresh",t.elementCount,"elements,",t.fieldCount,"fields")}),e.events.on("beforeUpdate",t=>{e.log("beforeUpdate",Object.keys(t.data.fields).length,"fields")}),e.events.on("afterUpdate",t=>{e.log("afterUpdate",t.updatedCount,"in",t.durationMs.toFixed(2),"ms")}),e.events.on("error",t=>{e.log("error in",t.context,":",t.error.message)})}},d="payload-live-preview:scroll";function h(){"undefined"!=typeof window&&(function(){if("undefined"!=typeof window)try{sessionStorage.setItem(d,JSON.stringify({href:window.location.href,x:window.scrollX,y:window.scrollY}))}catch{}}(),window.location.reload())}var f="data-payload-field",p="data-payload-guessed",g=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]),m="payload-live-preview-unbound",v={"bottom-right":"bottom:12px;right:12px;","bottom-left":"bottom:12px;left:12px;","top-right":"top:12px;right:12px;","top-left":"top:12px;left:12px;"};function y(e,t,n){const i=function(e,t){const n=new Set(e),i=e=>{if(n.has(e))return!0;const t=`${e}.`;for(const e of n)if(e.startsWith(t))return!0;return!1};return e=>{if(i(e))return!0;const n=function(e,t){if(void 0===t||0===t.length)return e;const n=`_${t}`;return e.endsWith(n)?e.slice(0,-n.length):e}(e,t);return n!==e&&i(n)}}(t,n);return Object.keys(e).filter(e=>!g.has(e)&&!i(e)).sort((e,t)=>e.localeCompare(t))}function w(e,t){const n=e.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.setAttribute("style","position:fixed;opacity:0;pointer-events:none;"),e.body.append(n),n.select(),n.remove()}function b(e,t,n){const i=e.createElement("button");return i.type="button",i.textContent=n,i.setAttribute("style","display:block;width:100%;text-align:left;margin:2px 0;padding:2px 4px;border:0;border-radius:3px;background:#222;color:#7fd1ff;font:inherit;cursor:pointer;"),i.title=`Copy ${f}="${t}"`,i.addEventListener("click",()=>{!function(e,t){const n=e.defaultView?.navigator.clipboard;null==n?w(e,t):n.writeText(t).catch(()=>{w(e,t)})}(e,`${f}="${t}"`),i.textContent=`${n} ✓`}),i}var P=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"});exports.DIAGNOSTIC_CODES=P,exports.EventEmitter=class{#d=/* @__PURE__ */new Map;#h=/* @__PURE__ */new Map;on(e,t){return this.#f(this.#d,e,t)}once(e,t){return this.#f(this.#h,e,t)}off(e,t){this.#p(this.#d,e,t),this.#p(this.#h,e,t)}async emit(e,t){await this.#g(e,t)}async emitWhile(e,t,n){return this.#g(e,t,n)}async#g(e,t,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#d.get(e);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#m(n,t,e),!i())return!1}if(!i())return!1;const o=this.#h.get(e);if(o&&o.size>0){const n=[...o];this.#h.delete(e);for(const r of n){if(!i())return!1;if(await this.#m(r,t,e),!i())return!1}}return i()}listenerCount(e){return(this.#d.get(e)?.size??0)+(this.#h.get(e)?.size??0)}removeAllListeners(e){if(void 0===e)return this.#d.clear(),void this.#h.clear();this.#d.delete(e),this.#h.delete(e)}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#d.keys())e.add(t);for(const t of this.#h.keys())e.add(t);return[...e]}#f(e,t,n){let i=e.get(t);return i||(i=/* @__PURE__ */new Set,e.set(t,i)),i.add(n),()=>{this.#p(e,t,n)}}#p(e,t,n){const i=e.get(t);void 0!==i&&(i.delete(n),0===i.size&&e.delete(t))}async#m(e,t,i){try{await e(t)}catch(e){const t="string"==typeof i||"number"==typeof i?String(i):"<event>";n(`[live-preview] LP0601: handler for "${t}" threw:`,e)}}},exports.PluginManager=class{#a;#v;#y;#w;#t;#b=/* @__PURE__ */new Map;#P=/* @__PURE__ */new Map;#S=/* @__PURE__ */new Map;#x=/* @__PURE__ */new Set;#L=/* @__PURE__ */new Map;#k=Promise.resolve();#A=0;constructor(e){this.#a=e.events,this.#v=e.config,this.#y=e.registerFieldRenderer,this.#t=t(e.log);const n=e.onTransformError;this.#w=void 0===n?void 0:t((...e)=>{const t=e[0];try{return n(t)}catch(e){return void this.#t("transform error reporter failed:",e)}})}register(e){return this.#A>0?this.#N(e,!1):this.#C(()=>this.#N(e,!0))}unregister(e){return this.#A>0?this.#$(e,!1):this.#C(async()=>{await this.#$(e,!0)})}destroyAll(){return this.#A>0?this.#T(!1):this.#C(async()=>{await this.#T(!0)})}applyTransforms(t,n,i,r){const o=this.#L.get(t);if(void 0===o||0===o.length)return n;let s=n;for(const a of[...o]){if(!a.active)continue;const{transform:o}=a;if(!1===r?.())return n;try{s=o(s,{fieldName:t,element:i.element,allFields:i.allFields});const a=e(s);if(!1===r?.())return n;if(a)throw new TypeError(`Transform for "${t}" returned a Promise/thenable; transforms must be synchronous`)}catch(e){if(!1===r?.())return n;const i=e instanceof Error?e:new Error(String(e));return this.#t(`transform for "${t}" failed:`,i),this.#w?.(i),n}}return s}list(){return[...this.#b.keys()]}snapshot(){const e=[],t=(e,t,n,i)=>{const r=i.counts();return{name:e,version:t,state:n,registrations:{transforms:r.transform,renderers:r.renderer,subscriptions:r.subscription,cleanups:r.cleanup}}};for(const[n,i]of this.#P)e.push(t(n,void 0,"initializing",i.scope));for(const[n,i]of this.#b)e.push(t(n,i.plugin.version,"active",i.scope));for(const t of this.#S.keys())e.push({name:t,version:void 0,state:"tearing-down",registrations:{transforms:0,renderers:0,subscriptions:0,cleanups:0}});return e}get size(){return this.#b.size}async#N(e,t){if(this.#b.has(e.name)||this.#P.has(e.name)||this.#S.has(e.name))return void this.#t(`plugin "${e.name}" already registered`);const n=function(e,t){if(void 0!==e){if(void 0!==e.runtime&&!function(e,t){const n=function(e){const t=/^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());if(null!==t)return[Number(t[1]),Number(t[2]),Number(t[3])]}(e);return void 0!==n&&t.split("||").some(e=>{const i=e.trim().split(/\s+/).filter(e=>e.length>0);return 0===i.length?""===e.trim()&&""===t.trim():i.every(e=>function(e,t){const n=t.trim();if(""===n||"*"===n)return!0;const i=/^(\^|~|>=|<=|>|<|=)?\s*v?(\d+)\.(\d+)\.(\d+)/.exec(n);if(null===i)return!1;const r=i[1]??"=",o=[Number(i[2]),Number(i[3]),Number(i[4])],s=function(e,t){for(let n=0;n<3;n+=1){const i=(e[n]??0)-(t[n]??0);if(0!==i)return i}return 0}(e,o);switch(r){case"=":return 0===s;case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"~":return s>=0&&e[0]===o[0]&&e[1]===o[1];case"^":return!(s<0)&&(o[0]>0?e[0]===o[0]:o[1]>0?0===e[0]&&e[1]===o[1]:0===e[0]&&0===e[1]&&e[2]===o[2]);default:return!1}}(n,e))})}(t,e.runtime))return`declares runtime ${e.runtime}, this runtime is ${t}`;if(void 0!==e.protocol){if(!Number.isInteger(e.protocol)||e.protocol<1)return`declares an invalid protocol version ${String(e.protocol)}`;if(e.protocol<4)return`declares protocol ${String(e.protocol)}, this runtime speaks ${String(4)}`}}}(e.compat,"2.0.5");if(void 0!==n)return void this.#O(e.name,n);const i=new r(e.name,this.#t),o=this.#E(e.name,i),s={scope:i,cancelled:!1};this.#P.set(e.name,s);try{if(await this.#U(()=>e.init(o),t),s.cancelled)return;i.commit()}catch(t){return i.close(),void(s.cancelled||this.#t(`plugin "${e.name}" init failed:`,t))}finally{this.#P.get(e.name)===s&&this.#P.delete(e.name)}this.#b.set(e.name,{plugin:e,scope:i}),this.#t(`plugin "${e.name}" registered`)}#O(e,t){const n=`plugin "${e}" refused: ${t}`;this.#t(n),this.#a.emit("error",{error:new Error(n),context:"plugin",code:"LP0103"})}#E(e,t){return{events:new o(this.#a,t),registerFieldRenderer:e=>{t.stage("renderer",()=>{const t=this.#y(e);return"function"==typeof t?t:void 0})},registerTransform:(e,n)=>{const i={transform:n,active:!1};t.stage("transform",()=>{i.active=!0;const t=this.#L.get(e);return void 0===t?this.#L.set(e,[i]):t.push(i),()=>{i.active=!1;const t=this.#L.get(e);if(void 0===t)return;const n=t.indexOf(i);n>=0&&t.splice(n,1),0===t.length&&this.#L.delete(e)}})},registerCleanup:e=>{t.own(e)},getConfig:()=>this.#v,log:(...t)=>{this.#t(`[${e}]`,...t)}}}#$(e,t){const n=this.#P.get(e);if(void 0!==n)return n.cancelled=!0,n.scope.close(),Promise.resolve();const i=this.#S.get(e);if(void 0!==i)return this.#x.has(e)?Promise.resolve():t?this.#F(i):i;const r=this.#b.get(e);if(void 0===r)return Promise.resolve();this.#b.delete(e),r.scope.close();const o=Promise.resolve().then(()=>this.#z(e,r.plugin,t));return this.#S.set(e,o),o.then(()=>{this.#S.get(e)===o&&this.#S.delete(e)}),o}async#z(e,t,n){if(void 0!==t.destroy){this.#x.add(e);try{await this.#U(()=>t.destroy?.(),n)}catch(t){this.#t(`plugin "${e}" destroy failed:`,t)}finally{this.#x.delete(e)}}}async#T(e){for(const e of this.#P.values())e.cancelled=!0,e.scope.close();const t=[...this.#b.keys()];for(const n of t)await this.#$(n,e)}async#U(e,t){t?await this.#F(Promise.resolve().then(e)):await e()}async#F(e){this.#A+=1;try{await e}finally{this.#A-=1}}#C(e){const t=this.#k.then(e);return this.#k=t.catch(e=>{this.#t("plugin manager mutation failed:",e)}),t}},exports.createAnalyticsPlugin=function(){let e=0,t=0,n=0;return{name:"analytics",version:"1.0.0",init:i=>{i.events.on("afterUpdate",i=>{e+=1,t+=i.updatedCount,n+=i.durationMs})},getStats:()=>({updateCount:e,totalElements:t,totalDurationMs:n,averageDurationMs:0===e?0:n/e})}},exports.createUnboundFieldsOverlayPlugin=function(e={}){return{name:"unbound-fields",version:"1.0.0",init:t=>{const n=e.root??("undefined"==typeof document?void 0:document);if(void 0===n)return;if((e.onlyWithDebug??1)&&!0!==t.getConfig().debug)return void t.log("not mounted: the client runs without `debug: true`");const i=function(e,t){const n=function(e){return 9===e.nodeType?e:e.ownerDocument}(e);if(null==n?.body)return null;const i=n.createElement("aside");i.id=m,i.setAttribute("style","position:fixed;z-index:2147483646;max-width:280px;max-height:40vh;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;background:#111;color:#eee;border:1px solid #333;border-radius:6px;padding:8px 10px;box-shadow:0 4px 16px rgba(0,0,0,0.4);"+t),i.setAttribute("aria-hidden","true"),i.hidden=!0;const r=e=>{const t=n.createElement("div");return t.textContent=e,t.setAttribute("style","font-weight:600;margin-bottom:4px;"),t},o=r("Unbound fields"),s=n.createElement("div"),a=r("Guessed bindings");a.setAttribute("data-testid","guessed-bindings");const l=n.createElement("div");return i.append(o,s,a,l),n.body.append(i),{update:(e,t)=>{i.isConnected||(n.getElementById(m)?.remove(),n.body.append(i)),i.hidden=0===e.length&&0===t.length,o.hidden=0===e.length,s.replaceChildren(...e.map(e=>b(n,e,e))),a.hidden=0===t.length,l.replaceChildren(...t.map(({field:e,matched:t})=>b(n,e,`${e} ← ${JSON.stringify(t)}`)))},destroy:()=>{i.remove()}}}(n,v[e.position??"bottom-right"]);null!==i&&(t.registerCleanup?.(i.destroy),t.events.on("afterUpdate",e=>{const r=y(e.data.fields,function(e){const t=[];for(const n of e.querySelectorAll(`[${f}]`)){const e=n.getAttribute(f);null!==e&&e.length>0&&t.push(e)}return t}(n),e.data.locale),o=function(e){const t=[];for(const n of e.querySelectorAll(`[${p}]`)){const e=n.getAttribute(f);null!==e&&0!==e.length&&t.push({field:e,matched:n.getAttribute(p)??""})}return t}(n);i.update(r,o),r.length>0&&t.log("unbound:",r.join(", ")),o.length>0&&t.log("guessed:",o.map(e=>e.field).join(", "))}))}}},exports.debugPlugin=c,exports.documentSavePlugin=function(e={}){const t=e.strategy??"silent";return{name:"document-save",version:"1.1.0",init:n=>{let i=!0;const r=/* @__PURE__ */new Set;n.registerCleanup?.(()=>{i=!1;for(const e of r)e.abort();r.clear()}),function(){if("undefined"!=typeof window)try{const e=sessionStorage.getItem(d);if(null===e)return;sessionStorage.removeItem(d);const t=JSON.parse(e);if(t.href!==window.location.href)return;window.scrollTo(t.x??0,t.y??0)}catch{}}(),n.events.on("documentSave",()=>{if(!i)return;if("silent"===t)return;if("reload"===t)return void h();const o=new AbortController;r.add(o);const s="fetch"===t?async function(e,t,n){if(e.handler)try{await e.handler(n)}catch(e){if(!i||n.aborted)return;t("document-save handler threw:",e)}else t("document-save: fetch strategy selected but no handler supplied")}(e,n.log,o.signal):async function(e,t,n,i){if("undefined"==typeof fetch)return void t("document-save: revalidate strategy needs fetch — not available");const r=e.revalidateUrl??"/api/revalidate";let o=!1;try{const s=await fetch(r,{method:"POST",signal:n,headers:{"Content-Type":"application/json",...e.revalidateHeaders??{}},body:JSON.stringify({source:"payload-live-preview"})});if(!i()||n.aborted)return;o=s.ok,o||t("document-save revalidate non-2xx:",s.status)}catch(e){if(!i()||n.aborted)return;t("document-save revalidate failed:",e)}o||"reload"!==e.onRevalidateFailure||h()}(e,n.log,o.signal,()=>i);s.finally(()=>{r.delete(o)})})}}},exports.highlightPlugin=u,exports.unboundFieldNames=y;
2
2
  //# sourceMappingURL=plugins.cjs.map