@myop/sdk 0.4.0-beta.3 → 0.4.0-beta.4

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 (35) hide show
  1. package/dist/bundled-declarations.d.ts +43 -2
  2. package/dist/cjs/{_IframeSDK.c2e3efb9.js → _IframeSDK.3a412cd4.js} +87 -7
  3. package/dist/cjs/_IframeSDK.3a412cd4.js.map +7 -0
  4. package/dist/cjs/_IframeSDK.9338575d.min.js +1 -0
  5. package/dist/cjs/{_WebComponentSDK.3728ca8b.js → _WebComponentSDK.4b6ac803.js} +87 -7
  6. package/dist/cjs/_WebComponentSDK.4b6ac803.js.map +7 -0
  7. package/dist/cjs/_WebComponentSDK.4e78d94a.min.js +1 -0
  8. package/dist/cjs/_hostSDK.34f770f6.min.js +1 -0
  9. package/dist/cjs/{_hostSDK.94744d97.js → _hostSDK.e9b70e44.js} +87 -7
  10. package/dist/cjs/_hostSDK.e9b70e44.js.map +7 -0
  11. package/dist/cjs/myop_sdk.js +11 -11
  12. package/dist/cjs/myop_sdk.js.map +1 -1
  13. package/dist/cjs/myop_sdk.min.js +1 -1
  14. package/dist/cjs-bundled/myop_sdk.bundled.js +88 -8
  15. package/dist/cjs-bundled/myop_sdk.bundled.js.map +2 -2
  16. package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -1
  17. package/dist/module/Iframe/index.js +88 -8
  18. package/dist/module/Iframe/index.js.map +2 -2
  19. package/dist/module/SDK.js +88 -8
  20. package/dist/module/SDK.js.map +2 -2
  21. package/dist/module/embeddedSDK.js +1 -1
  22. package/dist/module/host/components/myopExtractedWebComponent.d.ts +24 -1
  23. package/dist/module/host/embeddedSDK.js +1 -1
  24. package/dist/module/host/index.js +88 -8
  25. package/dist/module/host/index.js.map +2 -2
  26. package/dist/module/host/loaders/HTMLComponentLoader.d.ts +19 -1
  27. package/dist/module/webcomponent/index.js +88 -8
  28. package/dist/module/webcomponent/index.js.map +2 -2
  29. package/package.json +1 -1
  30. package/dist/cjs/_IframeSDK.3faa31eb.min.js +0 -1
  31. package/dist/cjs/_IframeSDK.c2e3efb9.js.map +0 -7
  32. package/dist/cjs/_WebComponentSDK.3728ca8b.js.map +0 -7
  33. package/dist/cjs/_WebComponentSDK.e517f1a4.min.js +0 -1
  34. package/dist/cjs/_hostSDK.48b3ff7a.min.js +0 -1
  35. package/dist/cjs/_hostSDK.94744d97.js.map +0 -7
@@ -683,7 +683,7 @@ declare module "@myop/sdk/host/componentCore" {
683
683
  };
684
684
  }
685
685
  declare module "@myop/sdk/host/components/myopExtractedWebComponent" {
686
- import { BaseMyopComponent } from "@myop/sdk/host/components/IMyopComponent";
686
+ import { AutoSizeOptions, BaseMyopComponent } from "@myop/sdk/host/components/IMyopComponent";
687
687
  import { BaseMyopMessage } from "@myop/sdk/messages";
688
688
  import { CleanupHandler, IComponentDefinitionConfig, ISkinConfig } from "@myop/sdk/common";
689
689
  import { loaderOptions } from "@myop/sdk/host/hostSDK";
@@ -703,6 +703,29 @@ declare module "@myop/sdk/host/components/myopExtractedWebComponent" {
703
703
  private _ctaQueue;
704
704
  private _ctaListener;
705
705
  constructor(componentDefinition: IComponentDefinitionConfig, skin: ISkinConfig, container: HTMLElement, customElement: HTMLElement, tagName: string, options?: loaderOptions);
706
+ private _autoSizeOptions?;
707
+ /**
708
+ * Data-out for size — the extracted counterpart of the iframe implementation.
709
+ *
710
+ * THIS EXISTED ONLY ON MyopIframeComponent, and that was invisible for as long as
711
+ * minification was sending every v2 component down the iframe path. Restoring v2
712
+ * detection moves them to this class, and `@myop/react` drives both through one
713
+ * wrapper: in content mode it hides its loader from the FIRST onSizeChange, so a
714
+ * component whose class has no observeAutoSize leaves a React host on a loader
715
+ * forever. Pic-Time's sizeMeta is width:100% with no height, which is exactly content
716
+ * mode. Caught by v2-data-contract D8 (API parity).
717
+ *
718
+ * It REPORTS rather than imposes. An iframe has no intrinsic size and must be
719
+ * measured inside and then set from outside; a custom element sizes itself from its
720
+ * own content, so the honest thing is to measure it and tell the host, and let the
721
+ * host decide. React then uses width:100% and the measured height.
722
+ *
723
+ * The one thing it does impose is `display: block` when the element computes to
724
+ * `inline`, which is the default for a custom element and measures as zero height no
725
+ * matter what it contains. The iframe path forces width:100% for the same reason —
726
+ * without it the first measurement is 0 and the host sizes the component to nothing.
727
+ */
728
+ observeAutoSize: (options?: AutoSizeOptions) => CleanupHandler;
706
729
  cleanupInspect: CleanupHandler;
707
730
  inspect(): CleanupHandler;
708
731
  hide(): void;
@@ -2108,7 +2131,25 @@ declare module "@myop/sdk/host/loaders/HTMLComponentLoader" {
2108
2131
  export class HTMLComponentLoader extends BaseMyopLoader {
2109
2132
  type: "HTMLLoader";
2110
2133
  /**
2111
- * Detect if HTML is a Myop Web Component (starts with marker comment)
2134
+ * Detect if HTML is a Myop Web Component.
2135
+ *
2136
+ * THE MARKER COMMENT ALONE IS NOT A SAFE SIGNAL, BECAUSE MINIFIERS DELETE COMMENTS.
2137
+ *
2138
+ * This used to be `startsWith(MYOP_WEB_COMPONENT_MARKER)` and nothing else. The
2139
+ * delivery lane minifies with `removeComments: true` (myop-server derive.ts MIN_CFG),
2140
+ * so the stored `min` artifact of every v2 web component loses its leading
2141
+ * `<!-- myop-web-component -->`. Detection then returned false, the component fell
2142
+ * back to plain iframe rendering, and the whole authored document was shown --
2143
+ * including the v2 authoring wrapper, so Pic-Time's production dashboard displayed the
2144
+ * preview chrome ("Web Component v2", a tag-name badge reading `loading...`, SIZE /
2145
+ * OVERFLOW / BG controls) instead of their component. Reported 2026-10-18; the served
2146
+ * HTML measured 328,071 bytes against 951,130 at origin, with zero `<!--` left in it.
2147
+ *
2148
+ * The script id is the signal that survives, and it is the one `extractWebComponentScript`
2149
+ * already depends on: if that element is present, extraction works, so detection
2150
+ * should agree. Checked with a regex rather than DOMParser -- this runs for every
2151
+ * HTML component, and parsing a 300 KB document to answer a yes/no question is not
2152
+ * worth it.
2112
2153
  */
2113
2154
  private isMyopWebComponent;
2114
2155
  /**
@@ -1188,6 +1188,67 @@ var MyopExtractedWebComponent = class extends BaseMyopComponent {
1188
1188
  this._ctaQueue.push({ action: detail.action, payload: detail.payload });
1189
1189
  }
1190
1190
  });
1191
+ __publicField(this, "_autoSizeOptions");
1192
+ /**
1193
+ * Data-out for size — the extracted counterpart of the iframe implementation.
1194
+ *
1195
+ * THIS EXISTED ONLY ON MyopIframeComponent, and that was invisible for as long as
1196
+ * minification was sending every v2 component down the iframe path. Restoring v2
1197
+ * detection moves them to this class, and `@myop/react` drives both through one
1198
+ * wrapper: in content mode it hides its loader from the FIRST onSizeChange, so a
1199
+ * component whose class has no observeAutoSize leaves a React host on a loader
1200
+ * forever. Pic-Time's sizeMeta is width:100% with no height, which is exactly content
1201
+ * mode. Caught by v2-data-contract D8 (API parity).
1202
+ *
1203
+ * It REPORTS rather than imposes. An iframe has no intrinsic size and must be
1204
+ * measured inside and then set from outside; a custom element sizes itself from its
1205
+ * own content, so the honest thing is to measure it and tell the host, and let the
1206
+ * host decide. React then uses width:100% and the measured height.
1207
+ *
1208
+ * The one thing it does impose is `display: block` when the element computes to
1209
+ * `inline`, which is the default for a custom element and measures as zero height no
1210
+ * matter what it contains. The iframe path forces width:100% for the same reason —
1211
+ * without it the first measurement is 0 and the host sizes the component to nothing.
1212
+ */
1213
+ __publicField(this, "observeAutoSize", (options) => {
1214
+ this._autoSizeOptions = options;
1215
+ const el = this.customElement;
1216
+ try {
1217
+ if (getComputedStyle(el).display === "inline") el.style.display = "block";
1218
+ } catch (e) {
1219
+ }
1220
+ const parse = (v) => {
1221
+ if (v === void 0) return void 0;
1222
+ if (typeof v === "number") return v;
1223
+ const n = parseFloat(v);
1224
+ return isNaN(n) ? void 0 : n;
1225
+ };
1226
+ const clamp = (v, min, max) => min !== void 0 && v < min ? min : max !== void 0 && v > max ? max : v;
1227
+ const report = () => {
1228
+ var _a;
1229
+ const opts = this._autoSizeOptions;
1230
+ const rect = el.getBoundingClientRect();
1231
+ const autoHeight = (opts == null ? void 0 : opts.explicitHeight) === void 0;
1232
+ (_a = opts == null ? void 0 : opts.onSizeChange) == null ? void 0 : _a.call(opts, {
1233
+ width: rect.width,
1234
+ height: autoHeight ? clamp(rect.height, parse(opts == null ? void 0 : opts.minHeight), parse(opts == null ? void 0 : opts.maxHeight)) : rect.height,
1235
+ autoSizingWidth: false,
1236
+ // a web component fills its container's width
1237
+ autoSizingHeight: autoHeight
1238
+ });
1239
+ };
1240
+ let ro;
1241
+ try {
1242
+ ro = new ResizeObserver(() => report());
1243
+ ro.observe(el);
1244
+ } catch (e) {
1245
+ }
1246
+ report();
1247
+ return () => {
1248
+ ro == null ? void 0 : ro.disconnect();
1249
+ this._autoSizeOptions = void 0;
1250
+ };
1251
+ });
1191
1252
  __publicField(this, "cleanupInspect", () => {
1192
1253
  });
1193
1254
  /**
@@ -2189,7 +2250,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
2189
2250
  };
2190
2251
 
2191
2252
  // version:myop-sdk-version
2192
- var myop_sdk_version_default = "0.4.0-beta.3";
2253
+ var myop_sdk_version_default = "0.4.0-beta.4";
2193
2254
 
2194
2255
  // src/helpers/deliveryStore.ts
2195
2256
  var DB_NAME = "myop-delivery";
@@ -3351,14 +3412,14 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
3351
3412
  if (!isolate) {
3352
3413
  doc.writeln("".concat(sdkScript).concat(initScript));
3353
3414
  }
3354
- if (!isolate && (options == null ? void 0 : options.data) !== void 0) {
3415
+ if (!isolate && (options == null ? void 0 : options.data) !== void 0 && (options == null ? void 0 : options.data) !== null) {
3355
3416
  const ctaQueueScript = "<script>\n window.__myop_cta_queue = [];\n window.myop_cta_handler = function(action, payload) {\n window.__myop_cta_queue.push({action: action, payload: payload});\n };\n <\/script>";
3356
3417
  const escapedData = JSON.stringify(options.data).replace(/<\/script/gi, "\\u003c/script");
3357
3418
  const dataScript = '<script id="__myop_init_data_script">\n (function() {\n var data = '.concat(escapedData, ";\n var scriptEl = document.getElementById('__myop_init_data_script');\n\n var callInitInterface = function(fn) {\n var startTime = performance.now();\n // Mark as pre-injected data call for extension tracking\n window.__myop_init_preinjected = true;\n try {\n fn(data);\n } finally {\n window.__myop_init_preinjected = false;\n }\n var duration = performance.now() - startTime;\n\n // Notify extension via postMessage (init* = pre-injected)\n try {\n window.parent.postMessage({\n type: 'MYOP_PREINJECTED_INIT',\n payload: {\n data: data,\n duration: duration,\n timestamp: Date.now()\n }\n }, '*');\n } catch (e) {}\n\n // Cleanup: remove script tag and stored data\n if (scriptEl && scriptEl.parentNode) {\n scriptEl.parentNode.removeChild(scriptEl);\n }\n delete window.__myop_init_data;\n };\n\n if (typeof window.myop_init_interface === 'function') {\n // Function already exists - call immediately\n callInitInterface(window.myop_init_interface);\n } else {\n // Function not yet defined - store data and watch for definition\n window.__myop_init_data = data;\n\n var _original;\n Object.defineProperty(window, 'myop_init_interface', {\n configurable: true,\n enumerable: true,\n set: function(fn) {\n _original = fn;\n if (window.__myop_init_data !== undefined) {\n var storedData = window.__myop_init_data;\n delete window.__myop_init_data;\n callInitInterface(fn);\n }\n },\n get: function() {\n return _original;\n }\n });\n }\n })();\n <\/script>");
3358
3419
  doc.writeln(ctaQueueScript + dataScript);
3359
3420
  }
3360
3421
  if (isolate) {
3361
- const escapedData = (options == null ? void 0 : options.data) !== void 0 ? JSON.stringify(options.data).replace(/<\/script/gi, "\\u003c/script") : "undefined";
3422
+ const escapedData = (options == null ? void 0 : options.data) !== void 0 && (options == null ? void 0 : options.data) !== null ? JSON.stringify(options.data).replace(/<\/script/gi, "\\u003c/script") : "undefined";
3362
3423
  doc.writeln(this.buildIsolationBridge(escapedData));
3363
3424
  }
3364
3425
  doc.close();
@@ -3413,10 +3474,29 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
3413
3474
  });
3414
3475
  }
3415
3476
  /**
3416
- * Detect if HTML is a Myop Web Component (starts with marker comment)
3477
+ * Detect if HTML is a Myop Web Component.
3478
+ *
3479
+ * THE MARKER COMMENT ALONE IS NOT A SAFE SIGNAL, BECAUSE MINIFIERS DELETE COMMENTS.
3480
+ *
3481
+ * This used to be `startsWith(MYOP_WEB_COMPONENT_MARKER)` and nothing else. The
3482
+ * delivery lane minifies with `removeComments: true` (myop-server derive.ts MIN_CFG),
3483
+ * so the stored `min` artifact of every v2 web component loses its leading
3484
+ * `<!-- myop-web-component -->`. Detection then returned false, the component fell
3485
+ * back to plain iframe rendering, and the whole authored document was shown --
3486
+ * including the v2 authoring wrapper, so Pic-Time's production dashboard displayed the
3487
+ * preview chrome ("Web Component v2", a tag-name badge reading `loading...`, SIZE /
3488
+ * OVERFLOW / BG controls) instead of their component. Reported 2026-10-18; the served
3489
+ * HTML measured 328,071 bytes against 951,130 at origin, with zero `<!--` left in it.
3490
+ *
3491
+ * The script id is the signal that survives, and it is the one `extractWebComponentScript`
3492
+ * already depends on: if that element is present, extraction works, so detection
3493
+ * should agree. Checked with a regex rather than DOMParser -- this runs for every
3494
+ * HTML component, and parsing a 300 KB document to answer a yes/no question is not
3495
+ * worth it.
3417
3496
  */
3418
3497
  isMyopWebComponent(html) {
3419
- return html.trimStart().startsWith(MYOP_WEB_COMPONENT_MARKER);
3498
+ if (html.trimStart().startsWith(MYOP_WEB_COMPONENT_MARKER)) return true;
3499
+ return new RegExp("<script[^>]*\\sid=[\"']?".concat(MYOP_WEB_COMPONENT_SCRIPT_ID, "[\"'\\s>]"), "i").test(html);
3420
3500
  }
3421
3501
  /**
3422
3502
  * Resolve how this component should render, applying the host render policy.
@@ -3511,7 +3591,6 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
3511
3591
  if (!container.querySelector('[id^="myop-comp-"]')) {
3512
3592
  container.innerHTML = "";
3513
3593
  }
3514
- this.appendChild(container, element, options);
3515
3594
  const component = new MyopExtractedWebComponent(
3516
3595
  componentDefinition,
3517
3596
  skin,
@@ -3520,7 +3599,8 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
3520
3599
  tagName,
3521
3600
  options
3522
3601
  );
3523
- if ((options == null ? void 0 : options.data) !== void 0) {
3602
+ this.appendChild(container, element, options);
3603
+ if ((options == null ? void 0 : options.data) !== void 0 && (options == null ? void 0 : options.data) !== null) {
3524
3604
  component.initWithData(options.data);
3525
3605
  }
3526
3606
  console.log("[MyopWebComponent] Loaded <".concat(tagName, "> into container"));