@duffcloudservices/cms 0.14.0 → 0.16.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/README.md CHANGED
@@ -646,6 +646,16 @@ For DCS-managed sites, `src/editor/editorBridge.ts` is the shared
646
646
  discovery/runtime layer that turns site DOM markers into portal editing
647
647
  entry points.
648
648
 
649
+ ### Which portal the bridge talks to
650
+
651
+ The bridge posts to, and accepts commands from, one portal origin (`src/editor/bridgeTrust.ts`), chosen in this order:
652
+
653
+ 1. `VITE_DCS_PORTAL_ORIGIN`, when the site's dev build sets it. `dcsEditorPlugin` reads it from Vite's resolved env and passes it to `initEditorBridge({ portalOrigin })`. It must be exactly one origin: `https://host[:port]`, or `http://` on `localhost`, `127.0.0.1` or `[::1]` for dev and e2e. A value that is set but empty or malformed (a path, a trailing slash, upper case, a wildcard) makes the bridge refuse every message. It does not fall back. `create-dcs-site doctor` reports such a value.
654
+ 2. Otherwise, on a host under `dcs-preview.dev` (the preview sandbox), the built-in `https://portal.duffcloudservices.com`.
655
+ 3. Otherwise the legacy inference for a preview served on the portal's own origin. This arm is removed when the legacy preview surface is.
656
+
657
+ In cases 1 and 2 the bridge speaks protocol 2 as well as protocol 1: it posts `dcs:hello { protocol: 2 }` before its `dcs:ready`, takes the nonce from the portal's `dcs:init`, and from then on sends and requires that nonce on every message. A portal that does not know `dcs:hello` drops it and connects on `dcs:ready` as before.
658
+
649
659
  ### Managed background images
650
660
 
651
661
  For customer-site hero, CTA, footer, card, staff, and gallery images that need editor image replacement, prefer the exported `ManagedImage` component over CSS-only `background-image` or hardcoded image arrays.
@@ -0,0 +1,10 @@
1
+ // package.json
2
+ var config = {
3
+ agentApiBaseUrl: "https://portal.duffcloudservices.com",
4
+ previewPortalOrigin: "https://portal.duffcloudservices.com",
5
+ agentWidgetScriptUrl: "https://files.duffcloudservices.com/agent-widget/v1/dcs-agent-widget.js"
6
+ };
7
+
8
+ export { config };
9
+ //# sourceMappingURL=chunk-KD2HFSIZ.js.map
10
+ //# sourceMappingURL=chunk-KD2HFSIZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../package.json"],"names":[],"mappings":";AAKE,IAAA,MAAA,GAAU;AAAA,EACR,eAAA,EAAmB,sCAAA;AAAA,EACnB,mBAAA,EAAuB,sCAAA;AAAA,EACvB,oBAAA,EAAwB;AAC1B","file":"chunk-KD2HFSIZ.js","sourcesContent":["{\n \"name\": \"@duffcloudservices/cms\",\n \"version\": \"0.16.0\",\n \"description\": \"Vue 3 composables and Vite plugins for DCS CMS integration\",\n \"type\": \"module\",\n \"config\": {\n \"agentApiBaseUrl\": \"https://portal.duffcloudservices.com\",\n \"previewPortalOrigin\": \"https://portal.duffcloudservices.com\",\n \"agentWidgetScriptUrl\": \"https://files.duffcloudservices.com/agent-widget/v1/dcs-agent-widget.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./plugins\": {\n \"types\": \"./dist/plugins/index.d.ts\",\n \"import\": \"./dist/plugins/index.js\"\n },\n \"./editor\": {\n \"types\": \"./dist/editor/editorBridge.d.ts\",\n \"import\": \"./dist/editor/editorBridge.js\"\n },\n \"./seo\": {\n \"types\": \"./dist/seo/index.d.ts\",\n \"import\": \"./dist/seo/index.js\"\n },\n \"./components\": {\n \"import\": \"./src/components/PreviewRibbon.vue\"\n },\n \"./responsive-image\": {\n \"import\": \"./src/components/ResponsiveImage.vue\"\n },\n \"./managed-image\": {\n \"import\": \"./src/components/ManagedImage.vue\"\n },\n \"./review-showcase\": {\n \"import\": \"./src/components/DcsReviewShowcase.vue\"\n },\n \"./call-button\": {\n \"import\": \"./src/components/DcsCallButton.vue\"\n },\n \"./lite-media-embed\": {\n \"import\": \"./src/components/LiteMediaEmbed.vue\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"src/components\",\n \"src/composables\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"verify:honesty-rails\": \"node scripts/verify-honesty-rails.mjs\",\n \"probe:live-urls\": \"node scripts/probe-live-emitted-urls.mjs\",\n \"verify:served-honesty\": \"node scripts/probe-live-emitted-urls.mjs\",\n \"type-check\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"lint:fix\": \"eslint . --fix\",\n \"prepublishOnly\": \"pnpm run build\"\n },\n \"peerDependencies\": {\n \"@unhead/vue\": \"^1.9.0\",\n \"playwright\": \"^1.40.0\",\n \"vue\": \"^3.4.0\"\n },\n \"peerDependenciesMeta\": {\n \"playwright\": {\n \"optional\": true\n }\n },\n \"dependencies\": {\n \"@duffcloudservices/cms-core\": \"workspace:*\",\n \"js-yaml\": \"^4.1.0\"\n },\n \"devDependencies\": {\n \"@dcs/eslint-rules\": \"workspace:*\",\n \"@dcs/test-utils\": \"workspace:*\",\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/markdown-it\": \"^14.1.0\",\n \"@types/node\": \"^20.11.0\",\n \"@unhead/vue\": \"^2.0.5\",\n \"@unhead/vue-v1\": \"npm:@unhead/vue@1.11.20\",\n \"@vitejs/plugin-vue\": \"^6.0.1\",\n \"@vitest/eslint-plugin\": \"^1.3.4\",\n \"@vue/eslint-config-typescript\": \"^14.6.0\",\n \"@vue/test-utils\": \"^2.4.0\",\n \"eslint\": \"^9.31.0\",\n \"eslint-plugin-vue\": \"~10.3.0\",\n \"jiti\": \"^2.4.2\",\n \"markdown-it\": \"^14.3.3\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"~5.6.3\",\n \"vite\": \"^6.4.6\",\n \"vitepress\": \"1.6.4\",\n \"vitest\": \"^3.2.3\",\n \"vue\": \"^3.5.44\",\n \"vue-router\": \"^4.5.1\"\n },\n \"keywords\": [\n \"vue\",\n \"vitepress\",\n \"cms\",\n \"dcs\",\n \"composables\",\n \"duff-cloud-services\"\n ],\n \"author\": \"Duff Cloud Services\",\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/NateDuff/dcs\"\n },\n \"homepage\": \"https://portal.duffcloudservices.com\",\n \"bugs\": {\n \"url\": \"https://github.com/NateDuff/dcs/issues\"\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n"]}
@@ -1,3 +1,12 @@
1
+ interface ViewportPinReport {
2
+ /** The pinned viewport height in CSS px. */
3
+ height: number;
4
+ /** Declarations (or whole declaration blocks) rewritten since the bridge started. */
5
+ declarations: number;
6
+ /** Stylesheets the bridge could not read (cross-origin without CORS) at the last scan. */
7
+ unreadableSheets: number;
8
+ }
9
+
1
10
  /**
2
11
  * Editor Bridge — injected into customer site iframes by the DCS visual editor.
3
12
  *
@@ -20,6 +29,7 @@
20
29
  * This script runs inside the iframe (customer site). The parent portal
21
30
  * communicates via postMessage using the `dcs:*` message protocol.
22
31
  */
32
+
23
33
  interface SectionInfo {
24
34
  id: string;
25
35
  label: string | null;
@@ -55,6 +65,12 @@ interface EditorReadyPayload {
55
65
  hasReviews: boolean;
56
66
  /** Keys of all [data-dcs-reviews] elements found on the page */
57
67
  reviewKeys: string[];
68
+ /**
69
+ * C-2064 D4: the viewport-height pin (height, rewritten declarations,
70
+ * unreadable stylesheets). For judges, support and telemetry; the portal
71
+ * does not branch on it.
72
+ */
73
+ viewportPin?: ViewportPinReport | null;
58
74
  }
59
75
  /**
60
76
  * Swap the live `<img>`(s) carrying a managed image key to a new source.
@@ -108,6 +124,15 @@ declare function revertImageOverrideIfImageKey(key: string, value: string): bool
108
124
  declare function revertImageAltOverrideIfAltKey(key: string, value: string): boolean;
109
125
  /** Clear all pending image overrides (test isolation). */
110
126
  declare function clearPendingImageOverrides(): void;
111
- declare function initEditorBridge(): void;
127
+ interface EditorBridgeOptions {
128
+ /**
129
+ * The site build's `VITE_DCS_PORTAL_ORIGIN`, passed through as it is (the
130
+ * editor plugin does this). `undefined` means the variable is not set. Any
131
+ * other value makes that origin the only one the bridge talks to; an empty
132
+ * or malformed value makes the bridge refuse every message.
133
+ */
134
+ portalOrigin?: unknown;
135
+ }
136
+ declare function initEditorBridge(options?: EditorBridgeOptions): void;
112
137
 
113
- export { type EditorReadyPayload, type SectionInfo, applyImageOverride, applyPendingImageOverrides, clearPendingImageOverrides, initEditorBridge, recordPendingImageOverride, revertImageAltOverrideIfAltKey, revertImageOverrideIfImageKey };
138
+ export { type EditorBridgeOptions, type EditorReadyPayload, type SectionInfo, applyImageOverride, applyPendingImageOverrides, clearPendingImageOverrides, initEditorBridge, recordPendingImageOverride, revertImageAltOverrideIfAltKey, revertImageOverrideIfImageKey };
@@ -1,10 +1,74 @@
1
+ import { config } from '../chunk-KD2HFSIZ.js';
2
+
1
3
  // src/editor/bridgeTrust.ts
4
+ var PREVIEW_SANDBOX_DOMAIN = "dcs-preview.dev";
5
+ var BUILT_IN_PORTAL_ORIGIN = config.previewPortalOrigin;
6
+ var LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
7
+ var DNS_HOST = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/;
8
+ function parseConfiguredPortalOrigin(value) {
9
+ if (typeof value !== "string" || value.length === 0 || value.length > 2048) return null;
10
+ let url;
11
+ try {
12
+ url = new URL(value);
13
+ } catch {
14
+ return null;
15
+ }
16
+ if (url.origin !== value) return null;
17
+ if (url.protocol === "https:" && DNS_HOST.test(url.hostname)) return value;
18
+ if (url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname)) return value;
19
+ return null;
20
+ }
21
+ function isPreviewSandboxHost(hostname) {
22
+ if (typeof hostname !== "string") return false;
23
+ let host = hostname.toLowerCase();
24
+ if (host.endsWith(".")) host = host.slice(0, -1);
25
+ return host === PREVIEW_SANDBOX_DOMAIN || host.endsWith("." + PREVIEW_SANDBOX_DOMAIN);
26
+ }
27
+ var configuredPortalOrigin = { set: false };
28
+ var sessionNonce = null;
29
+ function configurePortalOrigin(value) {
30
+ configuredPortalOrigin = value === void 0 ? { set: false } : { set: true, origin: parseConfiguredPortalOrigin(value) };
31
+ sessionNonce = null;
32
+ }
33
+ function portalTrustMode(win = globalThis.window) {
34
+ if (configuredPortalOrigin.set) return configuredPortalOrigin.origin ? "configured" : "refused";
35
+ return isPreviewSandboxHost(win.location.hostname) ? "sandbox" : "legacy";
36
+ }
37
+ var NONCE = /^[A-Za-z0-9-]{16,128}$/;
38
+ function speaksProtocol2(win = globalThis.window) {
39
+ const mode = portalTrustMode(win);
40
+ return mode === "configured" || mode === "sandbox";
41
+ }
42
+ function resetProtocolSession() {
43
+ sessionNonce = null;
44
+ }
45
+ function acceptProtocolInit(raw, win = globalThis.window) {
46
+ if (!speaksProtocol2(win)) return false;
47
+ if (!isRecord(raw) || raw.type !== "dcs:init" || !isRecord(raw.data)) return false;
48
+ const { protocol, nonce } = raw.data;
49
+ if (protocol !== 2 || typeof nonce !== "string" || !NONCE.test(nonce)) return false;
50
+ sessionNonce = nonce;
51
+ return true;
52
+ }
53
+ function withSessionNonce(data) {
54
+ if (sessionNonce === null) return data;
55
+ return isRecord(data) ? { ...data, nonce: sessionNonce } : { nonce: sessionNonce };
56
+ }
57
+ function carriesSessionNonce(raw) {
58
+ if (sessionNonce === null) return true;
59
+ return isRecord(raw) && isRecord(raw.data) && raw.data.nonce === sessionNonce;
60
+ }
2
61
  var trustedPortalOrigins = [];
3
62
  function isTrustedParentOrigin(origin, selfOrigin) {
4
63
  if (!origin || origin === "null") return false;
5
64
  return origin === selfOrigin || trustedPortalOrigins.includes(origin);
6
65
  }
7
66
  function resolveParentOrigin(win = globalThis.window) {
67
+ if (configuredPortalOrigin.set) return configuredPortalOrigin.origin;
68
+ if (isPreviewSandboxHost(win.location.hostname)) return BUILT_IN_PORTAL_ORIGIN;
69
+ return inferParentOrigin(win);
70
+ }
71
+ function inferParentOrigin(win) {
8
72
  const selfOrigin = win.location.origin;
9
73
  let candidate = null;
10
74
  try {
@@ -31,7 +95,10 @@ var INBOUND_LIMITS = {
31
95
  html: 2e6,
32
96
  src: 2e6,
33
97
  alt: 1e4,
34
- reviews: 500
98
+ reviews: 500,
99
+ /** dcs:set-viewport height, CSS px (C-2064 D4): an integer in [1, 10000]. */
100
+ viewportHeightMin: 1,
101
+ viewportHeightMax: 1e4
35
102
  };
36
103
  function isRecord(v) {
37
104
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -92,11 +159,169 @@ function parseInboundCommand(raw) {
92
159
  if (d.reviews === void 0 || d.reviews === null) return { type: raw.type, key: k, reviews: null };
93
160
  return Array.isArray(d.reviews) && d.reviews.length <= INBOUND_LIMITS.reviews ? { type: raw.type, key: k, reviews: d.reviews } : null;
94
161
  }
162
+ case "dcs:set-viewport": {
163
+ const h = d.height;
164
+ return typeof h === "number" && Number.isInteger(h) && h >= INBOUND_LIMITS.viewportHeightMin && h <= INBOUND_LIMITS.viewportHeightMax ? { type: raw.type, height: h } : null;
165
+ }
95
166
  default:
96
167
  return null;
97
168
  }
98
169
  }
99
170
 
171
+ // src/editor/viewportPin.ts
172
+ var VIEWPORT_PIN_STYLE_ID = "dcs-viewport-pin";
173
+ var VIEWPORT_PIN_PROPERTY = "--dcs-vh";
174
+ var UNIT_TOKEN = /(^|[^\w.#-])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)([sld]?)(vh|vb|vmax|vmin)(?![\w-])/gi;
175
+ var PROTECTED = /url\((?:[^()"'\\]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')*\)|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/gi;
176
+ var QUICK_CHECK = /\d[sld]?v(?:h|b|max|min)/i;
177
+ function rewriteSegment(text) {
178
+ return text.replace(UNIT_TOKEN, (_m, prefix, num, variant, unit) => {
179
+ const pinned = `calc(${num} * var(${VIEWPORT_PIN_PROPERTY}))`;
180
+ const u = unit.toLowerCase();
181
+ if (u === "vmax") return `${prefix}calc(${num} * max(1${variant}vw, var(${VIEWPORT_PIN_PROPERTY})))`;
182
+ if (u === "vmin") return `${prefix}calc(${num} * min(1${variant}vw, var(${VIEWPORT_PIN_PROPERTY})))`;
183
+ return `${prefix}${pinned}`;
184
+ });
185
+ }
186
+ function rewriteViewportUnits(value) {
187
+ if (!QUICK_CHECK.test(value)) return value;
188
+ let out = "";
189
+ let last = 0;
190
+ PROTECTED.lastIndex = 0;
191
+ for (let m = PROTECTED.exec(value); m; m = PROTECTED.exec(value)) {
192
+ out += rewriteSegment(value.slice(last, m.index)) + m[0];
193
+ last = m.index + m[0].length;
194
+ }
195
+ return out + rewriteSegment(value.slice(last));
196
+ }
197
+ var pinnedHeight = null;
198
+ var declarations = 0;
199
+ var unreadableSheets = 0;
200
+ var watching = false;
201
+ var scannedSheets = /* @__PURE__ */ new WeakMap();
202
+ function pinStyleElement() {
203
+ const el = document.getElementById(VIEWPORT_PIN_STYLE_ID);
204
+ return el instanceof HTMLStyleElement ? el : null;
205
+ }
206
+ function writePin(height) {
207
+ let el = pinStyleElement();
208
+ if (!el) {
209
+ el = document.createElement("style");
210
+ el.id = VIEWPORT_PIN_STYLE_ID;
211
+ (document.head ?? document.documentElement).appendChild(el);
212
+ }
213
+ const text = `:root{${VIEWPORT_PIN_PROPERTY}:${height / 100}px !important}`;
214
+ if (el.textContent !== text) el.textContent = text;
215
+ el.dataset.height = String(height);
216
+ }
217
+ function rewriteDeclarations(style) {
218
+ if (!QUICK_CHECK.test(style.cssText)) return 0;
219
+ let n = 0;
220
+ const props = [];
221
+ for (let i = 0; i < style.length; i++) props.push(style.item(i));
222
+ for (const prop of props) {
223
+ const value = style.getPropertyValue(prop);
224
+ const next2 = rewriteViewportUnits(value);
225
+ if (next2 !== value) {
226
+ style.setProperty(prop, next2, style.getPropertyPriority(prop));
227
+ n++;
228
+ }
229
+ }
230
+ const whole = style.cssText;
231
+ const next = rewriteViewportUnits(whole);
232
+ if (next !== whole) {
233
+ style.cssText = next;
234
+ n++;
235
+ }
236
+ return n;
237
+ }
238
+ function walkRules(rules, depth) {
239
+ let unreadable = 0;
240
+ for (let i = 0; i < rules.length; i++) {
241
+ const rule = rules[i];
242
+ if (rule.styleSheet) unreadable += scanSheet(rule.styleSheet, depth + 1, true);
243
+ if (rule.style) declarations += rewriteDeclarations(rule.style);
244
+ if (rule.cssRules) unreadable += walkRules(rule.cssRules, depth + 1);
245
+ }
246
+ return unreadable;
247
+ }
248
+ function scanSheet(sheet, depth, force = false) {
249
+ if (depth > 32) return 0;
250
+ const owner = sheet.ownerNode;
251
+ if (owner?.id === VIEWPORT_PIN_STYLE_ID) return 0;
252
+ let rules;
253
+ try {
254
+ rules = sheet.cssRules;
255
+ } catch {
256
+ return 1;
257
+ }
258
+ if (!rules) return 0;
259
+ const seen = scannedSheets.get(sheet);
260
+ if (!force && seen && seen.rules === rules.length) return seen.unreadable;
261
+ const unreadable = walkRules(rules, depth);
262
+ scannedSheets.set(sheet, { rules: rules.length, unreadable });
263
+ return unreadable;
264
+ }
265
+ function rescanViewportUnits(options = {}) {
266
+ if (pinnedHeight === null) return;
267
+ if (!pinStyleElement()) writePin(pinnedHeight);
268
+ let unreadable = 0;
269
+ const sheets = Array.from(document.styleSheets ?? []);
270
+ const adopted = document.adoptedStyleSheets;
271
+ if (adopted) sheets.push(...adopted);
272
+ for (const sheet of sheets) {
273
+ try {
274
+ void sheet.cssRules;
275
+ } catch {
276
+ unreadable++;
277
+ continue;
278
+ }
279
+ unreadable += scanSheet(sheet, 0);
280
+ }
281
+ unreadableSheets = unreadable;
282
+ if (options.inline) {
283
+ document.querySelectorAll("[style]").forEach((el) => {
284
+ if (el.style && QUICK_CHECK.test(el.getAttribute("style") ?? "")) declarations += rewriteDeclarations(el.style);
285
+ });
286
+ }
287
+ }
288
+ function startWatching() {
289
+ if (watching) return;
290
+ watching = true;
291
+ if (typeof MutationObserver !== "undefined") {
292
+ const observer = new MutationObserver((records) => {
293
+ const own = pinStyleElement();
294
+ if (records.every((r) => own && (r.target === own || r.target.parentNode === own))) return;
295
+ rescanViewportUnits();
296
+ });
297
+ observer.observe(document.head ?? document.documentElement, { childList: true, subtree: true, characterData: true });
298
+ }
299
+ document.addEventListener("load", (event) => {
300
+ const target = event.target;
301
+ if (target instanceof HTMLLinkElement || target instanceof HTMLStyleElement) rescanViewportUnits();
302
+ }, true);
303
+ }
304
+ function pinViewportUnits(height) {
305
+ const h = Math.round(height);
306
+ if (!Number.isFinite(h) || h < 0) return false;
307
+ const changed = pinnedHeight !== h;
308
+ const first = pinnedHeight === null;
309
+ pinnedHeight = h;
310
+ writePin(h);
311
+ if (first) {
312
+ rescanViewportUnits({ inline: true });
313
+ startWatching();
314
+ }
315
+ return changed;
316
+ }
317
+ function startViewportPin() {
318
+ const carried = Number(pinStyleElement()?.dataset.height);
319
+ pinViewportUnits(Number.isFinite(carried) && carried > 0 ? carried : globalThis.innerHeight);
320
+ }
321
+ function viewportPinReport() {
322
+ return pinnedHeight === null ? null : { height: pinnedHeight, declarations, unreadableSheets };
323
+ }
324
+
100
325
  // src/editor/editorBridge.ts
101
326
  function isInIframe() {
102
327
  try {
@@ -109,7 +334,7 @@ function postToParent(type, data) {
109
334
  if (!isInIframe()) return;
110
335
  const targetOrigin = resolveParentOrigin();
111
336
  if (!targetOrigin) return;
112
- globalThis.self.parent.postMessage({ type, data }, targetOrigin);
337
+ globalThis.self.parent.postMessage({ type, data: withSessionNonce(data) }, targetOrigin);
113
338
  }
114
339
  var TEXT_KEY_SELECTOR = "[data-text-key], [data-dcs-text]";
115
340
  var REVIEW_SELECTOR = "[data-dcs-reviews]";
@@ -264,6 +489,7 @@ function setMode(mode) {
264
489
  }
265
490
  function rediscoverAndNotify() {
266
491
  activeEditElement = null;
492
+ rescanViewportUnits({ inline: true });
267
493
  const sections = discoverSections();
268
494
  const textKeys = discoverTextKeys();
269
495
  const reviewKeys = discoverReviewKeys();
@@ -292,7 +518,8 @@ function rediscoverAndNotify() {
292
518
  hasManagedForms: managedFormIds.length > 0,
293
519
  managedFormIds,
294
520
  hasReviews: reviewKeys.length > 0,
295
- reviewKeys
521
+ reviewKeys,
522
+ viewportPin: viewportPinReport()
296
523
  });
297
524
  applyPendingImageOverrides();
298
525
  if (editorActive) {
@@ -1232,6 +1459,11 @@ function handleMessage(event) {
1232
1459
  if (event.source !== globalThis.self.parent) return;
1233
1460
  const parentOrigin = resolveParentOrigin();
1234
1461
  if (!parentOrigin || event.origin !== parentOrigin) return;
1462
+ if (acceptProtocolInit(event.data)) {
1463
+ rediscoverAndNotify();
1464
+ return;
1465
+ }
1466
+ if (!carriesSessionNonce(event.data)) return;
1235
1467
  const cmd = parseInboundCommand(event.data);
1236
1468
  if (!cmd) return;
1237
1469
  switch (cmd.type) {
@@ -1291,9 +1523,13 @@ function handleMessage(event) {
1291
1523
  }));
1292
1524
  scheduleRediscovery();
1293
1525
  break;
1526
+ case "dcs:set-viewport":
1527
+ if (pinViewportUnits(cmd.height)) scheduleRediscovery();
1528
+ break;
1294
1529
  }
1295
1530
  }
1296
1531
  function injectEditorHeightFix() {
1532
+ startViewportPin();
1297
1533
  if (document.getElementById("dcs-editor-height-fix")) return;
1298
1534
  const style = document.createElement("style");
1299
1535
  style.id = "dcs-editor-height-fix";
@@ -1316,7 +1552,8 @@ function measureContentHeight(sections) {
1316
1552
  const bodyHeight = document.body.scrollHeight;
1317
1553
  return Math.max(sectionHeight, bodyHeight);
1318
1554
  }
1319
- function initEditorBridge() {
1555
+ function initEditorBridge(options) {
1556
+ if (options) configurePortalOrigin(options.portalOrigin);
1320
1557
  if (!isInIframe()) return;
1321
1558
  injectEditorHeightFix();
1322
1559
  if (!bridgeInitialized) {
@@ -1379,6 +1616,10 @@ function initEditorBridge() {
1379
1616
  const eventEl = document.querySelector(EVENT_CONTENT_SELECTOR);
1380
1617
  const blogTitleEl = document.querySelector("[data-blog-title]");
1381
1618
  const blogSummaryEl = document.querySelector("[data-blog-summary]");
1619
+ if (speaksProtocol2()) {
1620
+ resetProtocolSession();
1621
+ postToParent("dcs:hello", { protocol: 2 });
1622
+ }
1382
1623
  postToParent("dcs:ready", {
1383
1624
  sections,
1384
1625
  textKeys,
@@ -1392,7 +1633,8 @@ function initEditorBridge() {
1392
1633
  hasManagedForms: managedFormIds.length > 0,
1393
1634
  managedFormIds,
1394
1635
  hasReviews: reviewKeys.length > 0,
1395
- reviewKeys
1636
+ reviewKeys,
1637
+ viewportPin: viewportPinReport()
1396
1638
  });
1397
1639
  observeSectionLayout();
1398
1640
  }