@lark-apaas/coding-registry-buildless 0.1.24 → 0.1.25-alpha.20260922075718
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/components/design-canvas.jsx +56 -2
- package/package.json +1 -1
- package/scripts/design-canvas.js +65 -2
|
@@ -63,6 +63,39 @@ 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
|
+
|
|
66
99
|
// ── Mirror sync singleton ──────────────────────────────────────────────────
|
|
67
100
|
// Shared by every buildless script on the page (first one to load defines
|
|
68
101
|
// it). Inlined per script rather than shipped as its own registry file:
|
|
@@ -644,6 +677,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
644
677
|
// guard so a replayed viewport doesn't schedule its own re-broadcast.
|
|
645
678
|
const mirrorEmitT = React.useRef(0);
|
|
646
679
|
const applyingRemoteView = React.useRef(false);
|
|
680
|
+
const remoteBounds = React.useRef(null);
|
|
647
681
|
// True while tf holds a REMOTE framing (last write came from a replay,
|
|
648
682
|
// no local gesture since). Gates every localStorage persist path — the
|
|
649
683
|
// 200ms saveT and the pagehide/unmount flush both read tf at fire time,
|
|
@@ -694,6 +728,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
694
728
|
if (applyingRemoteView.current) {
|
|
695
729
|
viewIsRemote.current = true;
|
|
696
730
|
} else {
|
|
731
|
+
remoteBounds.current = null;
|
|
697
732
|
viewIsRemote.current = false;
|
|
698
733
|
clearTimeout(saveT.current);
|
|
699
734
|
saveT.current = setTimeout(() => {
|
|
@@ -708,8 +743,10 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
708
743
|
if (!dcCaptureMode && !applyingRemoteView.current && !mirrorEmitT.current) {
|
|
709
744
|
mirrorEmitT.current = setTimeout(() => {
|
|
710
745
|
mirrorEmitT.current = 0;
|
|
746
|
+
const bounds = dcBoundsFromTransform(tf.current, vpRef.current);
|
|
747
|
+
if (!bounds) return;
|
|
711
748
|
window.__miaodaMirror.emit(
|
|
712
|
-
{ type: 'miaoda:canvas:viewport-changed', x: tf.current.x, y: tf.current.y, scale: tf.current.scale },
|
|
749
|
+
{ type: 'miaoda:canvas:viewport-changed', v: 2, bounds, x: tf.current.x, y: tf.current.y, scale: tf.current.scale },
|
|
713
750
|
{ key: 'canvas:viewport', throttle: 60 },
|
|
714
751
|
);
|
|
715
752
|
}, 120);
|
|
@@ -1078,8 +1115,19 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
1078
1115
|
// pipeline (DOM transform, --dc-inv-zoom, host % readout); the
|
|
1079
1116
|
// applyingRemoteView guard keeps the replay from re-broadcasting or
|
|
1080
1117
|
// persisting the presenter's framing.
|
|
1118
|
+
const applyRemoteBounds = (bounds) => {
|
|
1119
|
+
const next = dcFitTransformToBounds(bounds, vp, minScale, maxScale);
|
|
1120
|
+
if (!next) return false;
|
|
1121
|
+
remoteBounds.current = bounds;
|
|
1122
|
+
applyingRemoteView.current = true;
|
|
1123
|
+
tf.current = next;
|
|
1124
|
+
apply();
|
|
1125
|
+
applyingRemoteView.current = false;
|
|
1126
|
+
return true;
|
|
1127
|
+
};
|
|
1128
|
+
const onViewportResize = () => { if (remoteBounds.current) applyRemoteBounds(remoteBounds.current); };
|
|
1129
|
+
window.addEventListener('resize', onViewportResize);
|
|
1081
1130
|
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
1131
|
// Kill any pending local-emit timer: it was armed before this replay
|
|
1084
1132
|
// and would otherwise fire 120ms later with tf already holding the
|
|
1085
1133
|
// REMOTE state — echoing the presenter's viewport back as our own.
|
|
@@ -1093,6 +1141,11 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
1093
1141
|
// has no saved viewport) would re-measure and override the presenter's
|
|
1094
1142
|
// viewport as soon as content mounts.
|
|
1095
1143
|
didFit.current = true;
|
|
1144
|
+
if (m.v === 2) {
|
|
1145
|
+
return applyRemoteBounds(m.bounds) ? { type: 'applied' } : { type: 'ignored', reason: 'bad bounds snapshot' };
|
|
1146
|
+
}
|
|
1147
|
+
if (![m.x, m.y, m.scale].every(Number.isFinite)) return { type: 'ignored', reason: 'bad snapshot' };
|
|
1148
|
+
remoteBounds.current = null;
|
|
1096
1149
|
applyingRemoteView.current = true;
|
|
1097
1150
|
tf.current = { x: m.x, y: m.y, scale: Math.min(maxScale, Math.max(minScale, m.scale)) };
|
|
1098
1151
|
apply();
|
|
@@ -1132,6 +1185,7 @@ function DCViewport({ children, minScale = 0.1, maxScale = 8, style = {} }) {
|
|
|
1132
1185
|
vp.addEventListener('pointercancel', pu);
|
|
1133
1186
|
return () => {
|
|
1134
1187
|
window.removeEventListener('message', onHostMsg);
|
|
1188
|
+
window.removeEventListener('resize', onViewportResize);
|
|
1135
1189
|
offViewportApply();
|
|
1136
1190
|
clearTimeout(mirrorEmitT.current);
|
|
1137
1191
|
mirrorEmitT.current = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-registry-buildless",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25-alpha.20260922075718",
|
|
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": [
|
package/scripts/design-canvas.js
CHANGED
|
@@ -1226,6 +1226,7 @@
|
|
|
1226
1226
|
this._skipNextFocusEmit = false;
|
|
1227
1227
|
this._applyingRemoteView = false;
|
|
1228
1228
|
this._viewIsRemote = false;
|
|
1229
|
+
this._remoteBounds = null;
|
|
1229
1230
|
this._mirrorSeeded = false;
|
|
1230
1231
|
this._mirrorEmitT = 0;
|
|
1231
1232
|
this._mirrorOffs = [];
|
|
@@ -1245,6 +1246,10 @@
|
|
|
1245
1246
|
this._readSidecar();
|
|
1246
1247
|
this._bindHost();
|
|
1247
1248
|
this._bindGestures();
|
|
1249
|
+
this._onViewportResize = () => {
|
|
1250
|
+
if (this._remoteBounds) this._applyRemoteBounds(this._remoteBounds);
|
|
1251
|
+
};
|
|
1252
|
+
window.addEventListener('resize', this._onViewportResize);
|
|
1248
1253
|
this._bindChildEvents();
|
|
1249
1254
|
this.addEventListener('dc:edit-start', (ev) => {
|
|
1250
1255
|
this._editing = pathOf(ev)[0];
|
|
@@ -1351,8 +1356,6 @@
|
|
|
1351
1356
|
return { type: 'applied' };
|
|
1352
1357
|
}),
|
|
1353
1358
|
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
1359
|
// Kill the pending local-emit timer: it was armed before this replay and
|
|
1357
1360
|
// would fire 120ms later with tf already holding the remote state — echoing
|
|
1358
1361
|
// the presenter's framing back as our own.
|
|
@@ -1367,6 +1370,16 @@
|
|
|
1367
1370
|
// as satisfied, or it re-solves as soon as content mounts and overrides the
|
|
1368
1371
|
// presenter's viewport.
|
|
1369
1372
|
this._didFit = true;
|
|
1373
|
+
if (m.v === 2) {
|
|
1374
|
+
return this._applyRemoteBounds(m.bounds)
|
|
1375
|
+
? { type: 'applied' }
|
|
1376
|
+
: { type: 'ignored', reason: 'bad bounds snapshot' };
|
|
1377
|
+
}
|
|
1378
|
+
// Compatibility for already-published SDKs. New versions emit only
|
|
1379
|
+
// v2 world bounds, while still accepting legacy pixel transforms.
|
|
1380
|
+
if (![m.x, m.y, m.scale].every(Number.isFinite))
|
|
1381
|
+
return { type: 'ignored', reason: 'bad snapshot' };
|
|
1382
|
+
this._remoteBounds = null;
|
|
1370
1383
|
this._applyingRemoteView = true;
|
|
1371
1384
|
this.tf = {
|
|
1372
1385
|
x: m.x,
|
|
@@ -1391,6 +1404,7 @@
|
|
|
1391
1404
|
this.removeEventListener('pointerdown', this._onDocDown);
|
|
1392
1405
|
window.removeEventListener('message', this._onHostMsg);
|
|
1393
1406
|
window.removeEventListener('pagehide', this._flushView);
|
|
1407
|
+
window.removeEventListener('resize', this._onViewportResize);
|
|
1394
1408
|
this._flushView?.();
|
|
1395
1409
|
this.overlay.close();
|
|
1396
1410
|
for (const off of this._offs || []) off();
|
|
@@ -1524,6 +1538,50 @@
|
|
|
1524
1538
|
}
|
|
1525
1539
|
|
|
1526
1540
|
// ── Transform ───────────────────────────────────────────
|
|
1541
|
+
_viewportRect() {
|
|
1542
|
+
const r = this.vp.getBoundingClientRect();
|
|
1543
|
+
return {
|
|
1544
|
+
width: r.width || this.vp.clientWidth || window.innerWidth,
|
|
1545
|
+
height: r.height || this.vp.clientHeight || window.innerHeight,
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
_boundsFromTransform() {
|
|
1549
|
+
const { width, height } = this._viewportRect();
|
|
1550
|
+
if (!(width > 0) || !(height > 0) || !(this.tf.scale > 0)) return null;
|
|
1551
|
+
return {
|
|
1552
|
+
x: -this.tf.x / this.tf.scale,
|
|
1553
|
+
y: -this.tf.y / this.tf.scale,
|
|
1554
|
+
width: width / this.tf.scale,
|
|
1555
|
+
height: height / this.tf.scale,
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
_applyRemoteBounds(bounds) {
|
|
1559
|
+
if (
|
|
1560
|
+
!bounds ||
|
|
1561
|
+
![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite) ||
|
|
1562
|
+
!(bounds.width > 0) ||
|
|
1563
|
+
!(bounds.height > 0)
|
|
1564
|
+
)
|
|
1565
|
+
return false;
|
|
1566
|
+
const { width, height } = this._viewportRect();
|
|
1567
|
+
if (!(width > 0) || !(height > 0)) return false;
|
|
1568
|
+
const scale = Math.min(
|
|
1569
|
+
this.maxScale,
|
|
1570
|
+
Math.max(this.minScale, Math.min(width / bounds.width, height / bounds.height)),
|
|
1571
|
+
);
|
|
1572
|
+
this._remoteBounds = bounds;
|
|
1573
|
+
this._applyingRemoteView = true;
|
|
1574
|
+
this.tf = {
|
|
1575
|
+
scale,
|
|
1576
|
+
// Keep horizontal centring, but top-anchor the shared world: unused
|
|
1577
|
+
// portrait height must not shift the presenter's vertical origin.
|
|
1578
|
+
x: width / 2 - (bounds.x + bounds.width / 2) * scale,
|
|
1579
|
+
y: -bounds.y * scale,
|
|
1580
|
+
};
|
|
1581
|
+
this.apply();
|
|
1582
|
+
this._applyingRemoteView = false;
|
|
1583
|
+
return true;
|
|
1584
|
+
}
|
|
1527
1585
|
apply() {
|
|
1528
1586
|
const { x, y, scale } = this.tf;
|
|
1529
1587
|
if (!this.world) return;
|
|
@@ -1551,6 +1609,7 @@
|
|
|
1551
1609
|
if (this._applyingRemoteView) {
|
|
1552
1610
|
this._viewIsRemote = true;
|
|
1553
1611
|
} else {
|
|
1612
|
+
this._remoteBounds = null;
|
|
1554
1613
|
this._viewIsRemote = false;
|
|
1555
1614
|
clearTimeout(this._saveT);
|
|
1556
1615
|
this._saveT = setTimeout(() => {
|
|
@@ -1566,9 +1625,13 @@
|
|
|
1566
1625
|
if (!dcCaptureMode && !this._applyingRemoteView && !this._mirrorEmitT) {
|
|
1567
1626
|
this._mirrorEmitT = setTimeout(() => {
|
|
1568
1627
|
this._mirrorEmitT = 0;
|
|
1628
|
+
const bounds = this._boundsFromTransform();
|
|
1629
|
+
if (!bounds) return;
|
|
1569
1630
|
window.__miaodaMirror.emit(
|
|
1570
1631
|
{
|
|
1571
1632
|
type: 'miaoda:canvas:viewport-changed',
|
|
1633
|
+
v: 2,
|
|
1634
|
+
bounds,
|
|
1572
1635
|
x: this.tf.x,
|
|
1573
1636
|
y: this.tf.y,
|
|
1574
1637
|
scale: this.tf.scale,
|