@pwfabric/embed 1.0.0-rc.1 → 1.0.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/dist/index.js CHANGED
@@ -295,6 +295,7 @@ __export(dist_exports, {
295
295
  getHttpStatus: () => getHttpStatus,
296
296
  getRating: () => getRating,
297
297
  injectTraceId: () => injectTraceId,
298
+ isExportableName: () => isExportableName,
298
299
  isRetryable: () => isRetryable,
299
300
  isScopeToken: () => isScopeToken,
300
301
  objectSchema: () => objectSchema,
@@ -312,6 +313,7 @@ __export(dist_exports, {
312
313
  responsiveBooleanSchema: () => responsiveBooleanSchema,
313
314
  responsiveNumberSchema: () => responsiveNumberSchema,
314
315
  retry: () => retry,
316
+ shimSource: () => shimSource,
315
317
  sleep: () => sleep,
316
318
  specifiersForShim: () => specifiersForShim,
317
319
  subscribeToSlice: () => subscribeToSlice,
@@ -1709,7 +1711,7 @@ var BLOCK_HOST_IMPORTS = [
1709
1711
  specifier: "@pwfabric/authoring",
1710
1712
  kind: "global",
1711
1713
  global: "__pwfabric_sdk",
1712
- seeding: "app-host",
1714
+ seeding: "every-host",
1713
1715
  shim: "sdk@v1.mjs",
1714
1716
  reason: "What the scaffolding emits and a third-party author reads first. A host that does not map it breaks every block that follows the documented path."
1715
1717
  },
@@ -1747,6 +1749,34 @@ function unseededHostGlobals() {
1747
1749
  function specifiersForShim(shim) {
1748
1750
  return BLOCK_HOST_IMPORTS.filter((i) => i.shim === shim).map((i) => i.specifier);
1749
1751
  }
1752
+ var NON_BINDABLE_NAMES = new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval undefined NaN Infinity".split(" "));
1753
+ function isExportableName(name) {
1754
+ return /^[A-Za-z_$][\w$]*$/.test(name) && !NON_BINDABLE_NAMES.has(name);
1755
+ }
1756
+ function shimSource(shim, global, names) {
1757
+ const exported = [...new Set(names)].filter(isExportableName).sort();
1758
+ const specifiers = specifiersForShim(shim);
1759
+ const required = BLOCK_HOST_IMPORTS.some((i) => i.shim === shim && i.seeding === "every-host");
1760
+ const served = specifiers.map((s) => `'${s}'`).join(", ");
1761
+ const lines = [
1762
+ `// Generated by pwf. Serves ${served} to compiled blocks:`,
1763
+ `// re-exports the instance the page seeded on globalThis.${global}.`
1764
+ ];
1765
+ if (required) {
1766
+ const message = `[pwfabric] globalThis.${global} is not seeded, so ${specifiers.join(", ") || shim} cannot be imported by a block. The host page must seed it before loading block bundles (@pwfabric/embed's embed.js does).`;
1767
+ lines.push(`const m = globalThis.${global}`, `if (m == null) throw new Error(${JSON.stringify(message)})`);
1768
+ } else {
1769
+ lines.push(`const m = globalThis.${global} ?? {}`);
1770
+ }
1771
+ lines.push("export default m");
1772
+ if (exported.length > 0) {
1773
+ lines.push(`export const {
1774
+ ${exported.map((n) => ` ${n},`).join("\n")}
1775
+ } = m`);
1776
+ }
1777
+ return `${lines.join("\n")}
1778
+ `;
1779
+ }
1750
1780
  function toRuntimeBlock(node) {
1751
1781
  const storedLayout = node.layout;
1752
1782
  const mergedLayout = storedLayout ? {