@myop/sdk 0.3.19 → 0.3.21

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 (33) hide show
  1. package/dist/bundled-declarations.d.ts +8 -0
  2. package/dist/cjs/_IframeSDK.1493b283.min.js +1 -0
  3. package/dist/cjs/{_IframeSDK.b158be2e.js → _IframeSDK.4f5885de.js} +92 -70
  4. package/dist/cjs/_IframeSDK.4f5885de.js.map +7 -0
  5. package/dist/cjs/_WebComponentSDK.0c7d1e66.min.js +1 -0
  6. package/dist/cjs/{_WebComponentSDK.fedea102.js → _WebComponentSDK.2303271b.js} +92 -70
  7. package/dist/cjs/{_WebComponentSDK.fedea102.js.map → _WebComponentSDK.2303271b.js.map} +3 -3
  8. package/dist/cjs/{_hostSDK.898f6183.js → _hostSDK.8b2cafd5.js} +92 -70
  9. package/dist/cjs/_hostSDK.8b2cafd5.js.map +7 -0
  10. package/dist/cjs/_hostSDK.efb2b2e6.min.js +1 -0
  11. package/dist/cjs/myop_sdk.js +16 -16
  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 +93 -71
  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 +93 -71
  18. package/dist/module/Iframe/index.js.map +3 -3
  19. package/dist/module/SDK.js +93 -71
  20. package/dist/module/SDK.js.map +2 -2
  21. package/dist/module/embeddedSDK.js +1 -1
  22. package/dist/module/host/components/myopIframeComponent.d.ts +8 -0
  23. package/dist/module/host/embeddedSDK.js +1 -1
  24. package/dist/module/host/index.js +93 -71
  25. package/dist/module/host/index.js.map +3 -3
  26. package/dist/module/webcomponent/index.js +93 -71
  27. package/dist/module/webcomponent/index.js.map +3 -3
  28. package/package.json +1 -1
  29. package/dist/cjs/_IframeSDK.736cc080.min.js +0 -1
  30. package/dist/cjs/_IframeSDK.b158be2e.js.map +0 -7
  31. package/dist/cjs/_WebComponentSDK.d0ae9e45.min.js +0 -1
  32. package/dist/cjs/_hostSDK.1f707218.min.js +0 -1
  33. package/dist/cjs/_hostSDK.898f6183.js.map +0 -7
@@ -1442,6 +1442,9 @@ var MyopIframeComponent = class extends BaseMyopComponent {
1442
1442
  this.componentConfig = componentConfig;
1443
1443
  this.container = container;
1444
1444
  this.IframeElement = IframeElement;
1445
+ __publicField(this, "_autoSizeCleanup");
1446
+ __publicField(this, "_autoSizeOptions");
1447
+ __publicField(this, "_autoSizeUpdate");
1445
1448
  __publicField(this, "sizeMeta");
1446
1449
  __publicField(this, "cleanupInspect");
1447
1450
  __publicField(this, "setHeightBasedOnDocumentElement", () => {
@@ -1471,11 +1474,20 @@ var MyopIframeComponent = class extends BaseMyopComponent {
1471
1474
  /**
1472
1475
  * Observes the iframe content size and automatically syncs it to the iframe element.
1473
1476
  * Uses direct contentDocument access (same-origin only) for accurate measurements.
1477
+ *
1478
+ * Reentrant: when called again while observers already exist, updates options and
1479
+ * re-evaluates sizing without recreating observers. Cleanup + re-call (e.g. React
1480
+ * re-render) creates fresh observers since cleanup clears the existing ones.
1481
+ *
1474
1482
  * @param options - Configuration options including size change callback and min/max constraints
1475
1483
  * @returns Cleanup function to stop observing
1476
1484
  */
1477
1485
  __publicField(this, "observeAutoSize", (options) => {
1478
- var _a, _b, _c, _d, _e, _f, _g;
1486
+ this._autoSizeOptions = options;
1487
+ if (this._autoSizeCleanup && this._autoSizeUpdate) {
1488
+ this._autoSizeUpdate();
1489
+ return this._autoSizeCleanup;
1490
+ }
1479
1491
  const iframe = this.IframeElement;
1480
1492
  const doc = iframe.contentDocument;
1481
1493
  if (!doc) {
@@ -1494,78 +1506,88 @@ var MyopIframeComponent = class extends BaseMyopComponent {
1494
1506
  const parsed = parseFloat(value);
1495
1507
  return isNaN(parsed) ? void 0 : parsed;
1496
1508
  };
1497
- const minWidth = parseSize(options == null ? void 0 : options.minWidth);
1498
- const maxWidth = parseSize(options == null ? void 0 : options.maxWidth);
1499
- const minHeight = parseSize(options == null ? void 0 : options.minHeight);
1500
- const maxHeight = parseSize(options == null ? void 0 : options.maxHeight);
1501
- const loaderMinHeight = (_a = options == null ? void 0 : options.loaderMinHeight) != null ? _a : 50;
1502
- const sizeMetaFillWidth = ((_b = this.sizeMeta) == null ? void 0 : _b.width) === "100%" ? "100%" : void 0;
1503
- const sizeMetaFillHeight = ((_c = this.sizeMeta) == null ? void 0 : _c.height) === "100%" ? "100%" : void 0;
1504
- const resolvedExplicitWidth = (_e = (_d = options == null ? void 0 : options.explicitWidth) != null ? _d : sizeMetaFillWidth) != null ? _e : "100%";
1505
- const resolvedExplicitHeight = (_f = options == null ? void 0 : options.explicitHeight) != null ? _f : sizeMetaFillHeight;
1506
- const hasExplicitWidth = resolvedExplicitWidth !== void 0;
1507
- const hasExplicitHeight = resolvedExplicitHeight !== void 0;
1508
- const containerRect = this.container.getBoundingClientRect();
1509
- const collapsedWidth = containerRect.width === 0;
1510
- const collapsedHeight = containerRect.height === 0 || containerRect.height === loaderMinHeight;
1511
- const shouldAutoWidth = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitWidth : collapsedWidth && !hasExplicitWidth;
1512
- const shouldAutoHeight = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitHeight : collapsedHeight && !hasExplicitHeight;
1513
- if (!shouldAutoWidth && !shouldAutoHeight) {
1514
- const explicitWidthPx = typeof resolvedExplicitWidth === "number" ? resolvedExplicitWidth : void 0;
1515
- const explicitHeightPx = typeof resolvedExplicitHeight === "number" ? resolvedExplicitHeight : void 0;
1516
- if (explicitWidthPx !== void 0 || explicitHeightPx !== void 0) {
1517
- (_g = options == null ? void 0 : options.onSizeChange) == null ? void 0 : _g.call(options, {
1518
- width: explicitWidthPx,
1519
- height: explicitHeightPx,
1520
- autoSizingWidth: false,
1521
- autoSizingHeight: false
1522
- });
1523
- }
1524
- return () => {
1525
- };
1526
- }
1527
1509
  const updateSize = () => {
1528
- var _a2;
1510
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1529
1511
  const contentDoc = iframe.contentDocument;
1530
- if (contentDoc) {
1531
- if (shouldAutoHeight) {
1532
- iframe.style.height = "0px";
1533
- }
1534
- if (shouldAutoWidth) {
1535
- iframe.style.width = "0px";
1536
- }
1537
- const contentWidth = Math.ceil(contentDoc.documentElement.scrollWidth);
1538
- const contentHeight = Math.ceil(contentDoc.documentElement.scrollHeight);
1539
- const width = clamp(contentWidth, minWidth, maxWidth);
1540
- const height = clamp(contentHeight, minHeight, maxHeight);
1541
- if (shouldAutoWidth) {
1542
- iframe.style.width = "".concat(width, "px");
1543
- }
1544
- if (shouldAutoHeight) {
1545
- iframe.style.height = "".concat(height, "px");
1512
+ if (!contentDoc) return;
1513
+ const opts = this._autoSizeOptions;
1514
+ const minWidth = parseSize(opts == null ? void 0 : opts.minWidth);
1515
+ const maxWidth = parseSize(opts == null ? void 0 : opts.maxWidth);
1516
+ const minHeight = parseSize(opts == null ? void 0 : opts.minHeight);
1517
+ const maxHeight = parseSize(opts == null ? void 0 : opts.maxHeight);
1518
+ const loaderMinHeight = (_a = opts == null ? void 0 : opts.loaderMinHeight) != null ? _a : 50;
1519
+ const sizeMetaFillWidth = ((_b = this.sizeMeta) == null ? void 0 : _b.width) === "100%" ? "100%" : void 0;
1520
+ const sizeMetaFillHeight = ((_c = this.sizeMeta) == null ? void 0 : _c.height) === "100%" ? "100%" : void 0;
1521
+ const resolvedExplicitWidth = (_e = (_d = opts == null ? void 0 : opts.explicitWidth) != null ? _d : sizeMetaFillWidth) != null ? _e : "100%";
1522
+ const resolvedExplicitHeight = (_f = opts == null ? void 0 : opts.explicitHeight) != null ? _f : sizeMetaFillHeight;
1523
+ const hasExplicitWidth = resolvedExplicitWidth !== void 0;
1524
+ const hasExplicitHeight = resolvedExplicitHeight !== void 0;
1525
+ const containerRect = this.container.getBoundingClientRect();
1526
+ const collapsedWidth = containerRect.width === 0;
1527
+ const collapsedHeight = containerRect.height === 0 || containerRect.height === loaderMinHeight;
1528
+ const shouldAutoWidth = (opts == null ? void 0 : opts.forceAutoSize) ? !hasExplicitWidth : collapsedWidth && !hasExplicitWidth;
1529
+ const shouldAutoHeight = (opts == null ? void 0 : opts.forceAutoSize) ? !hasExplicitHeight : collapsedHeight && !hasExplicitHeight;
1530
+ if (!shouldAutoWidth && !shouldAutoHeight) {
1531
+ iframe.style.width = typeof resolvedExplicitWidth === "number" ? "".concat(resolvedExplicitWidth, "px") : "100%";
1532
+ iframe.style.height = typeof resolvedExplicitHeight === "number" ? "".concat(resolvedExplicitHeight, "px") : "100%";
1533
+ const explicitWidthPx = typeof resolvedExplicitWidth === "number" ? resolvedExplicitWidth : void 0;
1534
+ const explicitHeightPx = typeof resolvedExplicitHeight === "number" ? resolvedExplicitHeight : void 0;
1535
+ if (explicitWidthPx !== void 0 || explicitHeightPx !== void 0) {
1536
+ (_g = opts == null ? void 0 : opts.onSizeChange) == null ? void 0 : _g.call(opts, {
1537
+ width: explicitWidthPx,
1538
+ height: explicitHeightPx,
1539
+ autoSizingWidth: false,
1540
+ autoSizingHeight: false
1541
+ });
1546
1542
  }
1547
- const isWidthConstrained = shouldAutoWidth && maxWidth !== void 0 && contentWidth > maxWidth;
1548
- const isHeightConstrained = shouldAutoHeight && maxHeight !== void 0 && contentHeight > maxHeight;
1549
- contentDoc.documentElement.style.overflowX = isWidthConstrained ? "auto" : "";
1550
- contentDoc.documentElement.style.overflowY = isHeightConstrained ? "auto" : "";
1551
- (_a2 = options == null ? void 0 : options.onSizeChange) == null ? void 0 : _a2.call(options, {
1552
- width,
1553
- height,
1554
- autoSizingWidth: shouldAutoWidth,
1555
- autoSizingHeight: shouldAutoHeight
1556
- });
1543
+ return;
1544
+ }
1545
+ if (shouldAutoHeight) {
1546
+ iframe.style.height = "0px";
1547
+ }
1548
+ if (shouldAutoWidth) {
1549
+ iframe.style.width = "0px";
1557
1550
  }
1551
+ const contentWidth = Math.ceil(Math.max(contentDoc.documentElement.scrollWidth, contentDoc.body.scrollWidth));
1552
+ const contentHeight = Math.ceil(Math.max(contentDoc.documentElement.scrollHeight, contentDoc.body.scrollHeight));
1553
+ const width = clamp(contentWidth, minWidth, maxWidth);
1554
+ const height = clamp(contentHeight, minHeight, maxHeight);
1555
+ if (shouldAutoWidth) {
1556
+ iframe.style.width = "".concat(width, "px");
1557
+ } else {
1558
+ iframe.style.width = typeof resolvedExplicitWidth === "number" ? "".concat(resolvedExplicitWidth, "px") : "100%";
1559
+ }
1560
+ if (shouldAutoHeight) {
1561
+ iframe.style.height = "".concat(height, "px");
1562
+ } else {
1563
+ iframe.style.height = typeof resolvedExplicitHeight === "number" ? "".concat(resolvedExplicitHeight, "px") : "100%";
1564
+ }
1565
+ const isWidthConstrained = shouldAutoWidth && maxWidth !== void 0 && contentWidth > maxWidth;
1566
+ const isHeightConstrained = shouldAutoHeight && maxHeight !== void 0 && contentHeight > maxHeight;
1567
+ contentDoc.documentElement.style.overflowX = isWidthConstrained ? "auto" : "";
1568
+ contentDoc.documentElement.style.overflowY = isHeightConstrained ? "auto" : "";
1569
+ (_h = opts == null ? void 0 : opts.onSizeChange) == null ? void 0 : _h.call(opts, {
1570
+ width,
1571
+ height,
1572
+ autoSizingWidth: shouldAutoWidth,
1573
+ autoSizingHeight: shouldAutoHeight
1574
+ });
1558
1575
  };
1559
1576
  updateSize();
1577
+ this._autoSizeUpdate = updateSize;
1560
1578
  const resizeObserver = new ResizeObserver(updateSize);
1561
1579
  resizeObserver.observe(doc.body);
1562
1580
  resizeObserver.observe(doc.documentElement);
1563
1581
  const mutationObserver = new MutationObserver(updateSize);
1564
1582
  mutationObserver.observe(doc.body, { childList: true, subtree: true, characterData: true, attributes: true });
1565
- return () => {
1583
+ const cleanup = () => {
1566
1584
  resizeObserver.disconnect();
1567
1585
  mutationObserver.disconnect();
1586
+ this._autoSizeUpdate = void 0;
1587
+ this._autoSizeCleanup = void 0;
1568
1588
  };
1589
+ this._autoSizeCleanup = cleanup;
1590
+ return cleanup;
1569
1591
  });
1570
1592
  __publicField(this, "setSizeBasedOnDocumentElement", () => {
1571
1593
  const cleanupHandler = this.send(new ExecuteScriptMessage(() => {
@@ -1612,16 +1634,15 @@ var MyopIframeComponent = class extends BaseMyopComponent {
1612
1634
  return cleanupHandler;
1613
1635
  });
1614
1636
  __publicField(this, "dispose", () => {
1637
+ if (this._autoSizeCleanup) {
1638
+ this._autoSizeCleanup();
1639
+ this._autoSizeCleanup = void 0;
1640
+ }
1615
1641
  if (this.cleanupInspect)
1616
1642
  this.cleanupInspect();
1617
1643
  super.dispose();
1618
1644
  this.IframeElement.parentNode.removeChild(this.IframeElement);
1619
1645
  });
1620
- if (skin.loader.autoHeight) {
1621
- this.initiated().then(() => {
1622
- this.setHeightBasedOnScrollHeight();
1623
- });
1624
- }
1625
1646
  this.element = this.IframeElement;
1626
1647
  }
1627
1648
  inspect() {
@@ -1831,7 +1852,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
1831
1852
  };
1832
1853
 
1833
1854
  // version:myop-sdk-version
1834
- var myop_sdk_version_default = "0.3.19";
1855
+ var myop_sdk_version_default = "0.3.21";
1835
1856
 
1836
1857
  // src/webcomponent/messageHandlers/BaseWebComponentMessageHandler.ts
1837
1858
  var BaseWebComponentMessageHandler = class extends BaseContextMessageHandler {
@@ -2287,11 +2308,12 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
2287
2308
  doc.close();
2288
2309
  const comp = new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
2289
2310
  comp.sizeMeta = parsedSizeMeta;
2290
- if (loaderConfig.autoHeight) {
2291
- IframeElement.onload = () => {
2292
- comp.observeSizeBasedOnDocumentElement();
2293
- };
2294
- }
2311
+ comp.initiated().then(() => {
2312
+ comp.observeAutoSize({ forceAutoSize: true });
2313
+ if (!(options == null ? void 0 : options.hidden)) {
2314
+ comp.show();
2315
+ }
2316
+ });
2295
2317
  return comp;
2296
2318
  }
2297
2319
  if (loaderConfig.shadowRootMode === ShadowRootModeType.none) {