@lark-apaas/coding-registry-buildless 0.1.24 → 0.1.25-alpha.20260922061823

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.
@@ -63,6 +63,50 @@ const dcIsMobile = typeof navigator !== 'undefined' &&
63
63
  // (mis)forwarded replay could reframe the canvas mid-shot.
64
64
  const dcCaptureMode = typeof location !== 'undefined' && /[?&](_snthumb|thumbnail)=/.test(location.search || '');
65
65
 
66
+ // A canvas transform is local screen geometry, so it cannot be replayed on a
67
+ // device with another viewport size. Mirror the world-space rectangle instead
68
+ // and let each receiver fit that rectangle into its own viewport.
69
+ function dcViewportRect(vp) {
70
+ const r = vp.getBoundingClientRect();
71
+ return {
72
+ width: r.width || vp.clientWidth || window.innerWidth,
73
+ height: r.height || vp.clientHeight || window.innerHeight,
74
+ };
75
+ }
76
+
77
+ function dcBoundsFromTransform(tf, vp) {
78
+ const { width, height } = dcViewportRect(vp);
79
+ if (!(width > 0) || !(height > 0) || !(tf.scale > 0)) return null;
80
+ return { x: -tf.x / tf.scale, y: -tf.y / tf.scale, width: width / tf.scale, height: height / tf.scale };
81
+ }
82
+
83
+ function dcFitTransformToBounds(bounds, vp, minScale, maxScale) {
84
+ if (!bounds || ![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite) ||
85
+ !(bounds.width > 0) || !(bounds.height > 0)) return null;
86
+ const { width, height } = dcViewportRect(vp);
87
+ if (!(width > 0) || !(height > 0)) return null;
88
+ const scale = Math.min(maxScale, Math.max(minScale, Math.min(width / bounds.width, height / bounds.height)));
89
+ return {
90
+ scale,
91
+ // Keep the existing horizontal centring, but anchor the shared world at
92
+ // the top of each viewport. A contain fit's spare vertical room otherwise
93
+ // becomes a device-specific Y baseline across landscape and portrait.
94
+ x: width / 2 - (bounds.x + bounds.width / 2) * scale,
95
+ y: -bounds.y * scale,
96
+ };
97
+ }
98
+
99
+ function dcPresentationSectionAtViewport(vp) {
100
+ if (!vp) return null;
101
+ const top = vp.getBoundingClientRect().top;
102
+ let current = null, distance = Infinity;
103
+ vp.querySelectorAll('[data-dc-section]').forEach((el) => {
104
+ const delta = Math.abs(el.getBoundingClientRect().top - top);
105
+ if (delta < distance) { current = el.dataset.dcSection || null; distance = delta; }
106
+ });
107
+ return current;
108
+ }
109
+
66
110
  // ── Mirror sync singleton ──────────────────────────────────────────────────
67
111
  // Shared by every buildless script on the page (first one to load defines
68
112
  // it). Inlined per script rather than shipped as its own registry file:
@@ -483,15 +527,22 @@ function DesignCanvas({ children, minScale, maxScale, style }) {
483
527
  };
484
528
  });
485
529
 
530
+ const [presentationMode, setPresentationMode] = React.useState(false);
531
+ const [presentationSectionId, setPresentationSectionId] = React.useState(null);
532
+
486
533
  const api = React.useMemo(() => ({
487
534
  state,
535
+ presentationMode,
536
+ setPresentationMode,
537
+ presentationSectionId,
538
+ setPresentationSectionId,
488
539
  section: (id) => state.sections[id] || {},
489
540
  patchSection: (id, p) => setState((s) => ({
490
541
  ...s,
491
542
  sections: { ...s.sections, [id]: { ...s.sections[id], ...(typeof p === 'function' ? p(s.sections[id] || {}) : p) } },
492
543
  })),
493
544
  setFocus: (slotId) => setState((s) => ({ ...s, focus: slotId })),
494
- }), [state]);
545
+ }), [state, presentationMode, presentationSectionId]);
495
546
 
496
547
  // Esc exits focus; any outside pointerdown commits an in-progress rename.
497
548
  React.useEffect(() => {
@@ -517,6 +568,12 @@ function DesignCanvas({ children, minScale, maxScale, style }) {
517
568
  return (
518
569
  <DCCtx.Provider value={api}>
519
570
  <DCViewport minScale={minScale} maxScale={maxScale} style={style}>{ready && worldChildren}</DCViewport>
571
+ {presentationMode && sectionMeta[presentationSectionId || sectionOrder[0]] && (
572
+ <div data-dc-presentation-title style={{ position: 'fixed', top: 16, left: 20, zIndex: 60, pointerEvents: 'none', fontFamily: DC.font }}>
573
+ <div style={{ fontSize: 16, fontWeight: 600, color: DC.title }}>{sectionMeta[presentationSectionId || sectionOrder[0]].title}</div>
574
+ {sectionMeta[presentationSectionId || sectionOrder[0]].subtitle && <div style={{ marginTop: 2, fontSize: 12, color: DC.subtitle }}>{sectionMeta[presentationSectionId || sectionOrder[0]].subtitle}</div>}
575
+ </div>
576
+ )}
520
577
  {ready && overlayChildren}
521
578
  {state.focus && registry[state.focus] && (
522
579
  <DCFocusOverlay entry={registry[state.focus]} sectionMeta={sectionMeta} sectionOrder={sectionOrder} />
@@ -627,6 +684,8 @@ function DCZoomControl({ scalePct, minScale, maxScale, onZoomTo }) {
627
684
  // keeps pans at 60fps on dense canvases.
628
685
  // ─────────────────────────────────────────────────────────────
629
686
  function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
687
+ const ctx = React.useContext(DCCtx);
688
+ const { presentationMode, setPresentationMode, setPresentationSectionId } = ctx;
630
689
  const vpRef = React.useRef(null);
631
690
  const worldRef = React.useRef(null);
632
691
  // Pre-fit fallback scale. A fresh canvas is reframed by the first-visit fit
@@ -644,6 +703,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
644
703
  // guard so a replayed viewport doesn't schedule its own re-broadcast.
645
704
  const mirrorEmitT = React.useRef(0);
646
705
  const applyingRemoteView = React.useRef(false);
706
+ const remoteBounds = React.useRef(null);
647
707
  // True while tf holds a REMOTE framing (last write came from a replay,
648
708
  // no local gesture since). Gates every localStorage persist path — the
649
709
  // 200ms saveT and the pagehide/unmount flush both read tf at fire time,
@@ -694,6 +754,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
694
754
  if (applyingRemoteView.current) {
695
755
  viewIsRemote.current = true;
696
756
  } else {
757
+ remoteBounds.current = null;
697
758
  viewIsRemote.current = false;
698
759
  clearTimeout(saveT.current);
699
760
  saveT.current = setTimeout(() => {
@@ -708,13 +769,23 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
708
769
  if (!dcCaptureMode && !applyingRemoteView.current && !mirrorEmitT.current) {
709
770
  mirrorEmitT.current = setTimeout(() => {
710
771
  mirrorEmitT.current = 0;
772
+ const bounds = dcBoundsFromTransform(tf.current, vpRef.current);
773
+ if (!bounds) return;
774
+ const sectionId = presentationMode ? dcPresentationSectionAtViewport(vpRef.current) : null;
775
+ if (sectionId) setPresentationSectionId((current) => current === sectionId ? current : sectionId);
711
776
  window.__miaodaMirror.emit(
712
- { type: 'miaoda:canvas:viewport-changed', x: tf.current.x, y: tf.current.y, scale: tf.current.scale },
777
+ { type: 'miaoda:canvas:viewport-changed', v: 2, bounds, sectionId, x: tf.current.x, y: tf.current.y, scale: tf.current.scale },
713
778
  { key: 'canvas:viewport', throttle: 60 },
714
779
  );
715
780
  }, 120);
716
781
  }
717
- }, [tfKey]);
782
+ }, [tfKey, presentationMode, setPresentationSectionId]);
783
+
784
+ React.useLayoutEffect(() => {
785
+ if (!presentationMode) return;
786
+ const sectionId = dcPresentationSectionAtViewport(vpRef.current);
787
+ if (sectionId) setPresentationSectionId((current) => current === sectionId ? current : sectionId);
788
+ }, [presentationMode, setPresentationSectionId]);
718
789
 
719
790
  // Whether the mount-time restore found a saved viewport — when it did, the
720
791
  // first-visit fit below is skipped so revisits keep the user's own view.
@@ -1071,6 +1142,9 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
1071
1142
  applyingRemoteView.current = viewIsRemote.current;
1072
1143
  apply();
1073
1144
  applyingRemoteView.current = false;
1145
+ } else if (d && d.type === 'miaoda:canvas:presentation-mode') {
1146
+ setPresentationMode(!!d.enabled);
1147
+ if (!d.enabled) setPresentationSectionId(null);
1074
1148
  }
1075
1149
  };
1076
1150
  window.addEventListener('message', onHostMsg);
@@ -1078,8 +1152,19 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
1078
1152
  // pipeline (DOM transform, --dc-inv-zoom, host % readout); the
1079
1153
  // applyingRemoteView guard keeps the replay from re-broadcasting or
1080
1154
  // persisting the presenter's framing.
1155
+ const applyRemoteBounds = (bounds) => {
1156
+ const next = dcFitTransformToBounds(bounds, vp, minScale, maxScale);
1157
+ if (!next) return false;
1158
+ remoteBounds.current = bounds;
1159
+ applyingRemoteView.current = true;
1160
+ tf.current = next;
1161
+ apply();
1162
+ applyingRemoteView.current = false;
1163
+ return true;
1164
+ };
1165
+ const onViewportResize = () => { if (remoteBounds.current) applyRemoteBounds(remoteBounds.current); };
1166
+ window.addEventListener('resize', onViewportResize);
1081
1167
  const offViewportApply = dcCaptureMode ? () => {} : window.__miaodaMirror.onApply('miaoda:canvas:viewport-changed', (m) => {
1082
- if (![m.x, m.y, m.scale].every(Number.isFinite)) return { type: 'ignored', reason: 'bad snapshot' };
1083
1168
  // Kill any pending local-emit timer: it was armed before this replay
1084
1169
  // and would otherwise fire 120ms later with tf already holding the
1085
1170
  // REMOTE state — echoing the presenter's viewport back as our own.
@@ -1093,6 +1178,12 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
1093
1178
  // has no saved viewport) would re-measure and override the presenter's
1094
1179
  // viewport as soon as content mounts.
1095
1180
  didFit.current = true;
1181
+ if (m.v === 2) {
1182
+ if (m.sectionId) setPresentationSectionId(m.sectionId);
1183
+ return applyRemoteBounds(m.bounds) ? { type: 'applied' } : { type: 'ignored', reason: 'bad bounds snapshot' };
1184
+ }
1185
+ if (![m.x, m.y, m.scale].every(Number.isFinite)) return { type: 'ignored', reason: 'bad snapshot' };
1186
+ remoteBounds.current = null;
1096
1187
  applyingRemoteView.current = true;
1097
1188
  tf.current = { x: m.x, y: m.y, scale: Math.min(maxScale, Math.max(minScale, m.scale)) };
1098
1189
  apply();
@@ -1132,6 +1223,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
1132
1223
  vp.addEventListener('pointercancel', pu);
1133
1224
  return () => {
1134
1225
  window.removeEventListener('message', onHostMsg);
1226
+ window.removeEventListener('resize', onViewportResize);
1135
1227
  offViewportApply();
1136
1228
  clearTimeout(mirrorEmitT.current);
1137
1229
  mirrorEmitT.current = 0;
@@ -1145,12 +1237,13 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
1145
1237
  vp.removeEventListener('pointercancel', pu);
1146
1238
  if (mobRaf) cancelAnimationFrame(mobRaf);
1147
1239
  };
1148
- }, [apply, minScale, maxScale]);
1240
+ }, [apply, minScale, maxScale, setPresentationMode, setPresentationSectionId]);
1149
1241
 
1150
1242
  return (
1151
1243
  <div
1152
1244
  ref={vpRef}
1153
- className={dcIsMobile ? 'design-canvas dc-mobile' : 'design-canvas'}
1245
+ className={(dcIsMobile ? 'design-canvas dc-mobile' : 'design-canvas') + (presentationMode ? ' dc-presentation-mode' : '')}
1246
+ data-dc-presentation-mode={presentationMode ? '' : undefined}
1154
1247
  style={{
1155
1248
  height: '100vh', width: '100vw',
1156
1249
  background: DC.bg,
@@ -1222,8 +1315,8 @@ function DCSection({ id, title, subtitle, children, gap = 48 }) {
1222
1315
  // the title sits tight against its own row at every zoom.
1223
1316
  return (
1224
1317
  <div data-dc-section={sid}
1225
- style={{ marginBottom: 'calc(80px * var(--dc-inv-zoom, 1))', position: 'relative' }}>
1226
- <div style={{ padding: '0 60px' }}>
1318
+ style={{ marginBottom: ctx?.presentationMode ? 80 : 'calc(80px * var(--dc-inv-zoom, 1))', position: 'relative' }}>
1319
+ {!ctx?.presentationMode && <div style={{ padding: '0 60px' }}>
1227
1320
  <div className="dc-sectionhead" style={{ paddingBottom: 'calc(36px * var(--dc-inv-zoom, 1))' }}>
1228
1321
  <DCEditable tag="div" value={sec.title ?? title}
1229
1322
  onChange={(v) => ctx && sid && ctx.patchSection(sid, { title: v })}
@@ -1235,7 +1328,7 @@ function DCSection({ id, title, subtitle, children, gap = 48 }) {
1235
1328
  }} />
1236
1329
  {subtitle && <div style={{ fontSize: 'calc(14px * var(--dc-inv-zoom, 1))', color: DC.subtitle, lineHeight: 'calc(22px * var(--dc-inv-zoom, 1))' }}>{subtitle}</div>}
1237
1330
  </div>
1238
- </div>
1331
+ </div>}
1239
1332
  <div style={{ display: 'flex', gap, padding: '0 60px', alignItems: 'flex-start', width: 'max-content' }}>
1240
1333
  {order.map((k) => (
1241
1334
  <DCArtboardFrame key={k} sectionId={sid} artboard={byId[k]} order={order}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-registry-buildless",
3
- "version": "0.1.24",
3
+ "version": "0.1.25-alpha.20260922061823",
4
4
  "description": "Miaoda registry (buildless runtime) — shadcn-style copy-in SDKs (globals + CDN-pinned, browser Babel) for buildless static HTML stacks",
5
5
  "type": "module",
6
6
  "files": [
@@ -630,9 +630,23 @@
630
630
  this.style.marginBottom = 'calc(80px * var(--dc-inv-zoom, 1))';
631
631
  this._render();
632
632
  }
633
+ /**
634
+ * Presentation mode keeps section headings outside the transformed world.
635
+ * The remaining section/card layout is then purely world-space, which is the
636
+ * coordinate model mirrored by the v2 bounds snapshot.
637
+ */
638
+ setPresentationMode(active) {
639
+ this._presentationMode = !!active;
640
+ this.style.marginBottom = active ? '80px' : 'calc(80px * var(--dc-inv-zoom, 1))';
641
+ // Rebuild instead of merely hiding the existing heading: in a shadow tree
642
+ // hidden descendants can still participate in measurement in some engines.
643
+ // Omitting it makes the presentation world genuinely title-free.
644
+ this._render();
645
+ }
633
646
  /** Pushed down by <design-canvas>: renamed title, order, deleted artboards. */
634
647
  applyState(meta) {
635
648
  this._order = meta.slotIds;
649
+ this._stateTitle = meta.title;
636
650
  const t = this.shadowRoot?.querySelector('.dc-sectionhead .dc-editable');
637
651
  if (t && meta.title != null && t.textContent !== meta.title) t.textContent = meta.title;
638
652
  const boards = [...this.querySelectorAll(':scope > dc-artboard')];
@@ -688,11 +702,14 @@
688
702
  .dc-sectionhead{padding-bottom:calc(36px * var(--dc-inv-zoom,1))}
689
703
  </style>
690
704
  <div part="frame">
691
- <div style="padding:0 60px">
705
+ ${
706
+ this._presentationMode
707
+ ? ''
708
+ : `<div class="dc-sectionhead-wrap" style="padding:0 60px">
692
709
  <div class="dc-sectionhead" part="sectionhead">
693
710
  ${editable(
694
711
  '',
695
- this.attr('title', ''),
712
+ this._stateTitle ?? this.attr('title', ''),
696
713
  `font-size:calc(20px * var(--dc-inv-zoom,1));font-weight:600;color:${DC.title};` +
697
714
  'letter-spacing:calc(-0.4px * var(--dc-inv-zoom,1));margin-bottom:calc(2px * var(--dc-inv-zoom,1));' +
698
715
  'display:inline-block;line-height:calc(28px * var(--dc-inv-zoom,1))',
@@ -703,7 +720,8 @@
703
720
  : ''
704
721
  }
705
722
  </div>
706
- </div>
723
+ </div>`
724
+ }
707
725
  <div style="display:flex;gap:${px(gap)};padding:0 60px;align-items:flex-start;width:max-content">
708
726
  <slot></slot>
709
727
  </div>
@@ -1226,6 +1244,10 @@
1226
1244
  this._skipNextFocusEmit = false;
1227
1245
  this._applyingRemoteView = false;
1228
1246
  this._viewIsRemote = false;
1247
+ this._remoteBounds = null;
1248
+ this._presentationMode = false;
1249
+ this._presentationSectionId = null;
1250
+ this._presentationTitle = null;
1229
1251
  this._mirrorSeeded = false;
1230
1252
  this._mirrorEmitT = 0;
1231
1253
  this._mirrorOffs = [];
@@ -1245,6 +1267,10 @@
1245
1267
  this._readSidecar();
1246
1268
  this._bindHost();
1247
1269
  this._bindGestures();
1270
+ this._onViewportResize = () => {
1271
+ if (this._remoteBounds) this._applyRemoteBounds(this._remoteBounds);
1272
+ };
1273
+ window.addEventListener('resize', this._onViewportResize);
1248
1274
  this._bindChildEvents();
1249
1275
  this.addEventListener('dc:edit-start', (ev) => {
1250
1276
  this._editing = pathOf(ev)[0];
@@ -1351,8 +1377,6 @@
1351
1377
  return { type: 'applied' };
1352
1378
  }),
1353
1379
  window.__miaodaMirror.onApply('miaoda:canvas:viewport-changed', (m) => {
1354
- if (![m.x, m.y, m.scale].every(Number.isFinite))
1355
- return { type: 'ignored', reason: 'bad snapshot' };
1356
1380
  // Kill the pending local-emit timer: it was armed before this replay and
1357
1381
  // would fire 120ms later with tf already holding the remote state — echoing
1358
1382
  // the presenter's framing back as our own.
@@ -1367,6 +1391,17 @@
1367
1391
  // as satisfied, or it re-solves as soon as content mounts and overrides the
1368
1392
  // presenter's viewport.
1369
1393
  this._didFit = true;
1394
+ if (m.v === 2) {
1395
+ if (m.sectionId) this._syncPresentationTitle(m.sectionId);
1396
+ return this._applyRemoteBounds(m.bounds)
1397
+ ? { type: 'applied' }
1398
+ : { type: 'ignored', reason: 'bad bounds snapshot' };
1399
+ }
1400
+ // Compatibility for already-published SDKs. New versions emit only
1401
+ // v2 world bounds, while still accepting legacy pixel transforms.
1402
+ if (![m.x, m.y, m.scale].every(Number.isFinite))
1403
+ return { type: 'ignored', reason: 'bad snapshot' };
1404
+ this._remoteBounds = null;
1370
1405
  this._applyingRemoteView = true;
1371
1406
  this.tf = {
1372
1407
  x: m.x,
@@ -1391,7 +1426,10 @@
1391
1426
  this.removeEventListener('pointerdown', this._onDocDown);
1392
1427
  window.removeEventListener('message', this._onHostMsg);
1393
1428
  window.removeEventListener('pagehide', this._flushView);
1429
+ window.removeEventListener('resize', this._onViewportResize);
1394
1430
  this._flushView?.();
1431
+ this._presentationTitle?.remove();
1432
+ this._presentationTitle = null;
1395
1433
  this.overlay.close();
1396
1434
  for (const off of this._offs || []) off();
1397
1435
  this._offs = [];
@@ -1434,6 +1472,77 @@
1434
1472
  if (!dcIsMobile) this._renderZoom();
1435
1473
  }
1436
1474
 
1475
+ _setPresentationMode(active) {
1476
+ this._presentationMode = !!active;
1477
+ this.vp?.classList.toggle('dc-presentation-mode', this._presentationMode);
1478
+ this.vp?.toggleAttribute('data-dc-presentation-mode', this._presentationMode);
1479
+ for (const sec of this.querySelectorAll(':scope > dc-section'))
1480
+ sec.setPresentationMode?.(this._presentationMode);
1481
+ if (!this._presentationMode) {
1482
+ this._presentationSectionId = null;
1483
+ this._presentationTitle?.remove();
1484
+ this._presentationTitle = null;
1485
+ this.apply();
1486
+ return;
1487
+ }
1488
+ this._syncPresentationTitle();
1489
+ // The world layout just changed (counter-scaled headings moved to fixed
1490
+ // chrome). Re-run the normal transform pipeline so an already-presenting
1491
+ // peer receives the presentation-layout bounds on the next snapshot.
1492
+ this.apply();
1493
+ }
1494
+
1495
+ _presentationSectionAtViewport() {
1496
+ if (!this.vp) return null;
1497
+ const top = this.vp.getBoundingClientRect().top;
1498
+ let current = null;
1499
+ let distance = Infinity;
1500
+ for (const sec of this.querySelectorAll(':scope > dc-section')) {
1501
+ const delta = Math.abs(sec.getBoundingClientRect().top - top);
1502
+ if (delta < distance) {
1503
+ current = sec.sectionId;
1504
+ distance = delta;
1505
+ }
1506
+ }
1507
+ return current;
1508
+ }
1509
+
1510
+ _syncPresentationTitle(sectionId = this._presentationSectionAtViewport()) {
1511
+ if (!this._presentationMode) return;
1512
+ const sid = sectionId || this.sectionOrder[0];
1513
+ const meta = sid && this.sectionMeta[sid];
1514
+ if (!meta) return;
1515
+ this._presentationSectionId = sid;
1516
+ if (!this._presentationTitle) {
1517
+ const title = document.createElement('div');
1518
+ title.setAttribute('data-dc-presentation-title', '');
1519
+ Object.assign(title.style, {
1520
+ position: 'fixed',
1521
+ top: '16px',
1522
+ left: '20px',
1523
+ zIndex: '60',
1524
+ pointerEvents: 'none',
1525
+ fontFamily: DC.font,
1526
+ });
1527
+ this.shadowRoot.appendChild(title);
1528
+ this._presentationTitle = title;
1529
+ }
1530
+ this._presentationTitle.textContent = '';
1531
+ const main = document.createElement('div');
1532
+ main.textContent = meta.title || '';
1533
+ Object.assign(main.style, { fontSize: '16px', fontWeight: '600', color: DC.title });
1534
+ this._presentationTitle.appendChild(main);
1535
+ const subtitle = [...this.querySelectorAll(':scope > dc-section')]
1536
+ .find((sec) => sec.sectionId === sid)
1537
+ ?.getAttribute('subtitle');
1538
+ if (subtitle) {
1539
+ const sub = document.createElement('div');
1540
+ sub.textContent = subtitle;
1541
+ Object.assign(sub.style, { marginTop: '2px', fontSize: '12px', color: DC.subtitle });
1542
+ this._presentationTitle.appendChild(sub);
1543
+ }
1544
+ }
1545
+
1437
1546
  // ── Zoom control (bottom right) ─────────────────────────
1438
1547
  _renderZoom() {
1439
1548
  const wrap = document.createElement('div');
@@ -1524,6 +1633,50 @@
1524
1633
  }
1525
1634
 
1526
1635
  // ── Transform ───────────────────────────────────────────
1636
+ _viewportRect() {
1637
+ const r = this.vp.getBoundingClientRect();
1638
+ return {
1639
+ width: r.width || this.vp.clientWidth || window.innerWidth,
1640
+ height: r.height || this.vp.clientHeight || window.innerHeight,
1641
+ };
1642
+ }
1643
+ _boundsFromTransform() {
1644
+ const { width, height } = this._viewportRect();
1645
+ if (!(width > 0) || !(height > 0) || !(this.tf.scale > 0)) return null;
1646
+ return {
1647
+ x: -this.tf.x / this.tf.scale,
1648
+ y: -this.tf.y / this.tf.scale,
1649
+ width: width / this.tf.scale,
1650
+ height: height / this.tf.scale,
1651
+ };
1652
+ }
1653
+ _applyRemoteBounds(bounds) {
1654
+ if (
1655
+ !bounds ||
1656
+ ![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite) ||
1657
+ !(bounds.width > 0) ||
1658
+ !(bounds.height > 0)
1659
+ )
1660
+ return false;
1661
+ const { width, height } = this._viewportRect();
1662
+ if (!(width > 0) || !(height > 0)) return false;
1663
+ const scale = Math.min(
1664
+ this.maxScale,
1665
+ Math.max(this.minScale, Math.min(width / bounds.width, height / bounds.height)),
1666
+ );
1667
+ this._remoteBounds = bounds;
1668
+ this._applyingRemoteView = true;
1669
+ this.tf = {
1670
+ scale,
1671
+ // Keep horizontal centring, but top-anchor the shared world: unused
1672
+ // portrait height must not shift the presenter's vertical origin.
1673
+ x: width / 2 - (bounds.x + bounds.width / 2) * scale,
1674
+ y: -bounds.y * scale,
1675
+ };
1676
+ this.apply();
1677
+ this._applyingRemoteView = false;
1678
+ return true;
1679
+ }
1527
1680
  apply() {
1528
1681
  const { x, y, scale } = this.tf;
1529
1682
  if (!this.world) return;
@@ -1551,6 +1704,7 @@
1551
1704
  if (this._applyingRemoteView) {
1552
1705
  this._viewIsRemote = true;
1553
1706
  } else {
1707
+ this._remoteBounds = null;
1554
1708
  this._viewIsRemote = false;
1555
1709
  clearTimeout(this._saveT);
1556
1710
  this._saveT = setTimeout(() => {
@@ -1566,9 +1720,16 @@
1566
1720
  if (!dcCaptureMode && !this._applyingRemoteView && !this._mirrorEmitT) {
1567
1721
  this._mirrorEmitT = setTimeout(() => {
1568
1722
  this._mirrorEmitT = 0;
1723
+ const bounds = this._boundsFromTransform();
1724
+ if (!bounds) return;
1725
+ const sectionId = this._presentationMode ? this._presentationSectionAtViewport() : null;
1726
+ if (sectionId) this._syncPresentationTitle(sectionId);
1569
1727
  window.__miaodaMirror.emit(
1570
1728
  {
1571
1729
  type: 'miaoda:canvas:viewport-changed',
1730
+ v: 2,
1731
+ bounds,
1732
+ sectionId,
1572
1733
  x: this.tf.x,
1573
1734
  y: this.tf.y,
1574
1735
  scale: this.tf.scale,
@@ -1979,6 +2140,8 @@
1979
2140
  } catch {}
1980
2141
  this._lastPostedScale = undefined;
1981
2142
  this.apply();
2143
+ } else if (d && d.type === 'miaoda:canvas:presentation-mode') {
2144
+ this._setPresentationMode(!!d.enabled);
1982
2145
  }
1983
2146
  };
1984
2147
  window.addEventListener('message', this._onHostMsg);
@@ -2155,6 +2318,7 @@
2155
2318
  };
2156
2319
  this.sectionMeta[sid] = meta;
2157
2320
  sec.applyState(meta);
2321
+ sec.setPresentationMode?.(this._presentationMode);
2158
2322
  }
2159
2323
  // If the focused artboard is gone (deleted, or content regenerated), leave focus.
2160
2324
  // This is a LOCAL correction, not a user action, so it must not broadcast: in a
@@ -2173,6 +2337,7 @@
2173
2337
  // useLayoutEffect. Deferring to rAF is one tick late and flashes an unfitted
2174
2338
  // first frame.
2175
2339
  this.fitToContent();
2340
+ this._syncPresentationTitle();
2176
2341
  }
2177
2342
  }
2178
2343