@preprio/toolkit 0.1.0-beta.3 → 0.1.0-beta.5

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Prepr B.V.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -647,9 +647,13 @@ validatePreprToken(process.env.PREPR_GRAPHQL_URL!); // throws PreprError if inva
647
647
 
648
648
  Extracts the access token from a Prepr GraphQL URL — the value `PreprTrackingPixel` needs as its `id`.
649
649
 
650
+ Returns the token as a `string`. It never returns `null` — a URL that is malformed, not on `graphql.prepr.io`, or missing a token segment throws a `PreprError` with code `INVALID_TOKEN`.
651
+
650
652
  ```typescript
651
653
  const token = extractAccessToken('https://graphql.prepr.io/abc123');
652
- // 'abc123' or null
654
+ // 'abc123'
655
+
656
+ extractAccessToken('not-a-url'); // throws PreprError(INVALID_TOKEN)
653
657
  ```
654
658
 
655
659
  ### Components
@@ -30,7 +30,7 @@ __export(astro_exports, {
30
30
  module.exports = __toCommonJS(astro_exports);
31
31
 
32
32
  // src/version.ts
33
- var VERSION = "0.1.0-beta.3";
33
+ var VERSION = "0.1.0-beta.5";
34
34
 
35
35
  // src/core/server.ts
36
36
  var PreprError = class extends Error {
@@ -172,6 +172,20 @@ var UTM_PARAMS = [
172
172
  "utm_content",
173
173
  "utm_campaign"
174
174
  ];
175
+ function serializeCookie(cookie) {
176
+ const parts = [
177
+ `${cookie.name}=${encodeURIComponent(cookie.value)}`,
178
+ `Max-Age=${cookie.maxAge}`,
179
+ `Path=${cookie.path}`
180
+ ];
181
+ if (cookie.sameSite) {
182
+ parts.push(`SameSite=${cookie.sameSite}`);
183
+ }
184
+ if (cookie.secure) {
185
+ parts.push("Secure");
186
+ }
187
+ return parts.join("; ");
188
+ }
175
189
  function parseCookies(request) {
176
190
  const cookies = /* @__PURE__ */ new Map();
177
191
  const header = request.headers.get("cookie");
@@ -190,7 +204,11 @@ function processPreprRequest(request, opts) {
190
204
  const requestHeaders = new Headers(request.headers);
191
205
  const responseCookies = [];
192
206
  const requestCookies = parseCookies(request);
193
- const searchParams = new URL(request.url).searchParams;
207
+ const url = new URL(request.url);
208
+ const searchParams = url.searchParams;
209
+ const forwardedProto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
210
+ const isSecure = forwardedProto ? forwardedProto === "https" : url.protocol === "https:";
211
+ const crossSite = isSecure ? { sameSite: "None", secure: true } : {};
194
212
  for (const key of UTM_PARAMS) {
195
213
  const value = searchParams.get(key);
196
214
  if (value !== null) {
@@ -239,6 +257,15 @@ function processPreprRequest(request, opts) {
239
257
  }
240
258
  requestHeaders.set("Prepr-Preview-Bar", "true");
241
259
  const isLivePreview = searchParams.get(PARAM_HIDE_BAR) === "true";
260
+ if (!isLivePreview && !requestCookies.has(COOKIE_PREVIEW_MODE)) {
261
+ responseCookies.push({
262
+ name: COOKIE_PREVIEW_MODE,
263
+ value: "true",
264
+ maxAge: ONE_YEAR_SECONDS,
265
+ path: "/",
266
+ ...crossSite
267
+ });
268
+ }
242
269
  if (!isLivePreview) {
243
270
  const segmentCookie = requestCookies.get(COOKIE_SEGMENT);
244
271
  if (segmentCookie) {
@@ -257,7 +284,8 @@ function processPreprRequest(request, opts) {
257
284
  name: COOKIE_VARIANT,
258
285
  value: previewAb,
259
286
  maxAge: ONE_YEAR_SECONDS,
260
- path: "/"
287
+ path: "/",
288
+ ...crossSite
261
289
  });
262
290
  }
263
291
  }
@@ -269,7 +297,8 @@ function processPreprRequest(request, opts) {
269
297
  name: COOKIE_SEGMENT,
270
298
  value: previewSegment,
271
299
  maxAge: ONE_YEAR_SECONDS,
272
- path: "/"
300
+ path: "/",
301
+ ...crossSite
273
302
  });
274
303
  }
275
304
  }
@@ -284,12 +313,7 @@ async function onPreprRequest(context, next, options) {
284
313
  });
285
314
  const response = await next();
286
315
  for (const cookie of responseCookies) {
287
- const parts = [
288
- `${cookie.name}=${encodeURIComponent(cookie.value)}`,
289
- `Max-Age=${cookie.maxAge}`,
290
- `Path=${cookie.path}`
291
- ];
292
- response.headers.append("Set-Cookie", parts.join("; "));
316
+ response.headers.append("Set-Cookie", serializeCookie(cookie));
293
317
  }
294
318
  return response;
295
319
  }
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.1.0-beta.3";
2
+ var VERSION = "0.1.0-beta.5";
3
3
 
4
4
  // src/core/server.ts
5
5
  var PreprError = class extends Error {
@@ -141,6 +141,20 @@ var UTM_PARAMS = [
141
141
  "utm_content",
142
142
  "utm_campaign"
143
143
  ];
144
+ function serializeCookie(cookie) {
145
+ const parts = [
146
+ `${cookie.name}=${encodeURIComponent(cookie.value)}`,
147
+ `Max-Age=${cookie.maxAge}`,
148
+ `Path=${cookie.path}`
149
+ ];
150
+ if (cookie.sameSite) {
151
+ parts.push(`SameSite=${cookie.sameSite}`);
152
+ }
153
+ if (cookie.secure) {
154
+ parts.push("Secure");
155
+ }
156
+ return parts.join("; ");
157
+ }
144
158
  function parseCookies(request) {
145
159
  const cookies = /* @__PURE__ */ new Map();
146
160
  const header = request.headers.get("cookie");
@@ -159,7 +173,11 @@ function processPreprRequest(request, opts) {
159
173
  const requestHeaders = new Headers(request.headers);
160
174
  const responseCookies = [];
161
175
  const requestCookies = parseCookies(request);
162
- const searchParams = new URL(request.url).searchParams;
176
+ const url = new URL(request.url);
177
+ const searchParams = url.searchParams;
178
+ const forwardedProto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
179
+ const isSecure = forwardedProto ? forwardedProto === "https" : url.protocol === "https:";
180
+ const crossSite = isSecure ? { sameSite: "None", secure: true } : {};
163
181
  for (const key of UTM_PARAMS) {
164
182
  const value = searchParams.get(key);
165
183
  if (value !== null) {
@@ -208,6 +226,15 @@ function processPreprRequest(request, opts) {
208
226
  }
209
227
  requestHeaders.set("Prepr-Preview-Bar", "true");
210
228
  const isLivePreview = searchParams.get(PARAM_HIDE_BAR) === "true";
229
+ if (!isLivePreview && !requestCookies.has(COOKIE_PREVIEW_MODE)) {
230
+ responseCookies.push({
231
+ name: COOKIE_PREVIEW_MODE,
232
+ value: "true",
233
+ maxAge: ONE_YEAR_SECONDS,
234
+ path: "/",
235
+ ...crossSite
236
+ });
237
+ }
211
238
  if (!isLivePreview) {
212
239
  const segmentCookie = requestCookies.get(COOKIE_SEGMENT);
213
240
  if (segmentCookie) {
@@ -226,7 +253,8 @@ function processPreprRequest(request, opts) {
226
253
  name: COOKIE_VARIANT,
227
254
  value: previewAb,
228
255
  maxAge: ONE_YEAR_SECONDS,
229
- path: "/"
256
+ path: "/",
257
+ ...crossSite
230
258
  });
231
259
  }
232
260
  }
@@ -238,7 +266,8 @@ function processPreprRequest(request, opts) {
238
266
  name: COOKIE_SEGMENT,
239
267
  value: previewSegment,
240
268
  maxAge: ONE_YEAR_SECONDS,
241
- path: "/"
269
+ path: "/",
270
+ ...crossSite
242
271
  });
243
272
  }
244
273
  }
@@ -253,12 +282,7 @@ async function onPreprRequest(context, next, options) {
253
282
  });
254
283
  const response = await next();
255
284
  for (const cookie of responseCookies) {
256
- const parts = [
257
- `${cookie.name}=${encodeURIComponent(cookie.value)}`,
258
- `Max-Age=${cookie.maxAge}`,
259
- `Path=${cookie.path}`
260
- ];
261
- response.headers.append("Set-Cookie", parts.join("; "));
285
+ response.headers.append("Set-Cookie", serializeCookie(cookie));
262
286
  }
263
287
  return response;
264
288
  }
@@ -2,7 +2,11 @@
2
2
  import { vercelStegaClean, vercelStegaDecode } from "@vercel/stega";
3
3
 
4
4
  // src/core/utils.ts
5
- function sendPreprEvent(event, data) {
5
+ var trustedParentOrigin = null;
6
+ function setTrustedParentOrigin(origin) {
7
+ trustedParentOrigin = origin;
8
+ }
9
+ function sendPreprEvent(event, data, options) {
6
10
  if (typeof window !== "undefined") {
7
11
  const message = {
8
12
  name: "prepr_preview_bar",
@@ -13,7 +17,11 @@ function sendPreprEvent(event, data) {
13
17
  new CustomEvent("prepr_preview_bar", { detail: message })
14
18
  );
15
19
  if (window.parent && window.parent !== window) {
16
- window.parent.postMessage(message, "*");
20
+ if (trustedParentOrigin) {
21
+ window.parent.postMessage(message, trustedParentOrigin);
22
+ } else if (options?.allowUntrustedTarget) {
23
+ window.parent.postMessage(message, "*");
24
+ }
17
25
  }
18
26
  }
19
27
  }
@@ -1704,16 +1712,34 @@ function getCookie(name) {
1704
1712
  }
1705
1713
  function setCookie(name, value, options = {}) {
1706
1714
  if (typeof document === "undefined") return;
1707
- const { maxAge, path = "/" } = options;
1715
+ const { maxAge, path = "/", sameSite, secure } = options;
1708
1716
  let cookie = `${name}=${encodeURIComponent(value)};path=${path}`;
1709
1717
  if (typeof maxAge === "number") {
1710
1718
  cookie += `;max-age=${maxAge}`;
1711
1719
  }
1720
+ if (sameSite) {
1721
+ cookie += `;samesite=${sameSite}`;
1722
+ }
1723
+ if (secure) {
1724
+ cookie += ";secure";
1725
+ }
1712
1726
  document.cookie = cookie;
1713
1727
  }
1714
- function removeCookie(name, path = "/") {
1728
+ function removeCookie(name, path = "/", options = {}) {
1715
1729
  if (typeof document === "undefined") return;
1716
- document.cookie = `${name}=;path=${path};expires=Thu, 01 Jan 1970 00:00:00 GMT`;
1730
+ const { sameSite, secure } = options;
1731
+ let cookie = `${name}=;path=${path};expires=Thu, 01 Jan 1970 00:00:00 GMT`;
1732
+ if (sameSite) {
1733
+ cookie += `;samesite=${sameSite}`;
1734
+ }
1735
+ if (secure) {
1736
+ cookie += ";secure";
1737
+ }
1738
+ document.cookie = cookie;
1739
+ }
1740
+ function crossSiteCookieOptions() {
1741
+ if (typeof window === "undefined" || !window.isSecureContext) return {};
1742
+ return { sameSite: "None", secure: true };
1717
1743
  }
1718
1744
 
1719
1745
  // src/core/locales/en.json
@@ -1807,7 +1833,23 @@ function t2(key, locale, vars) {
1807
1833
  }
1808
1834
 
1809
1835
  // src/core/iframe-bridge.ts
1810
- function createIframeBridge(store) {
1836
+ var EDITOR_BASE_DOMAIN = "prepr.io";
1837
+ function isAllowedEditorOrigin(origin, allowed) {
1838
+ if (allowed) return allowed.includes(origin);
1839
+ let url;
1840
+ try {
1841
+ url = new URL(origin);
1842
+ } catch {
1843
+ return false;
1844
+ }
1845
+ if (url.protocol !== "https:" || url.port !== "") return false;
1846
+ const suffix = `.${EDITOR_BASE_DOMAIN}`;
1847
+ if (!url.hostname.endsWith(suffix)) return false;
1848
+ const label = url.hostname.slice(0, -suffix.length);
1849
+ return label.length > 0 && !label.includes(".");
1850
+ }
1851
+ function createIframeBridge(store, options = {}) {
1852
+ const allowedOrigins = options.allowedEditorOrigins;
1811
1853
  let parentOrigin = null;
1812
1854
  const onKeyDown = (event) => {
1813
1855
  const key = event.key.toLowerCase();
@@ -1817,14 +1859,16 @@ function createIframeBridge(store) {
1817
1859
  const onMessage = (evt) => {
1818
1860
  const data = evt?.data;
1819
1861
  if (data?.event === "prepr:initVE" && !parentOrigin) {
1862
+ if (!isAllowedEditorOrigin(evt.origin, allowedOrigins)) return;
1820
1863
  parentOrigin = evt.origin;
1864
+ setTrustedParentOrigin(parentOrigin);
1821
1865
  if (data.scrollPosition != null) {
1822
1866
  const top = data.scrollPosition;
1823
1867
  setTimeout(() => window.scrollTo(0, top), 1);
1824
1868
  }
1825
1869
  store.set({ previewMode: true, editMode: data.editMode ?? true });
1826
1870
  }
1827
- if (evt.origin !== parentOrigin) return;
1871
+ if (!parentOrigin || evt.origin !== parentOrigin) return;
1828
1872
  if (data?.event === "prepr:getScrollPosition") {
1829
1873
  const currentScrollY = window.scrollY || document.documentElement.scrollTop;
1830
1874
  sendPreprEvent("getScrollPosition", { value: currentScrollY });
@@ -1832,55 +1876,69 @@ function createIframeBridge(store) {
1832
1876
  };
1833
1877
  return {
1834
1878
  start() {
1835
- sendPreprEvent("loaded");
1879
+ sendPreprEvent("loaded", void 0, { allowUntrustedTarget: true });
1836
1880
  window.addEventListener("keydown", onKeyDown);
1837
1881
  window.addEventListener("message", onMessage);
1838
1882
  },
1839
1883
  stop() {
1840
1884
  window.removeEventListener("keydown", onKeyDown);
1841
1885
  window.removeEventListener("message", onMessage);
1886
+ parentOrigin = null;
1887
+ setTrustedParentOrigin(null);
1842
1888
  }
1843
1889
  };
1844
1890
  }
1845
1891
 
1846
1892
  // src/core/toolbar-change-handler.ts
1847
- var COOKIE_OPTS = { maxAge: ONE_YEAR_SECONDS, path: "/" };
1893
+ function cookieOpts() {
1894
+ return {
1895
+ maxAge: ONE_YEAR_SECONDS,
1896
+ path: "/",
1897
+ ...crossSiteCookieOptions()
1898
+ };
1899
+ }
1848
1900
  function createChangeHandler(deps) {
1849
1901
  const { store, stega, syncAutoClean } = deps;
1850
- function updateParam(name, value) {
1902
+ function updateParams(patch) {
1851
1903
  const [path, existing] = splitPath(deps.currentPath());
1852
1904
  const params = new URLSearchParams(existing);
1853
- if (value === null) {
1854
- params.delete(name);
1855
- } else {
1856
- params.set(name, value);
1905
+ for (const [name, value] of Object.entries(patch)) {
1906
+ if (value === null) {
1907
+ params.delete(name);
1908
+ } else {
1909
+ params.set(name, value);
1910
+ }
1857
1911
  }
1858
1912
  const query = params.toString();
1859
1913
  deps.navigate(query ? `${path}?${query}` : path);
1860
1914
  }
1861
1915
  return function handleChange(before, after) {
1916
+ const paramPatch = {};
1862
1917
  if (before.selectedSegment !== after.selectedSegment) {
1863
1918
  if (after.selectedSegment === null) {
1864
- removeCookie(COOKIE_SEGMENT);
1919
+ removeCookie(COOKIE_SEGMENT, "/", crossSiteCookieOptions());
1865
1920
  } else {
1866
- setCookie(COOKIE_SEGMENT, after.selectedSegment, COOKIE_OPTS);
1921
+ setCookie(COOKIE_SEGMENT, after.selectedSegment, cookieOpts());
1867
1922
  }
1868
- updateParam(PARAM_SEGMENT, after.selectedSegment);
1923
+ paramPatch[PARAM_SEGMENT] = after.selectedSegment;
1869
1924
  sendPreprEvent("segment_changed", {
1870
1925
  segment: after.selectedSegment ?? void 0
1871
1926
  });
1872
1927
  }
1873
1928
  if (before.selectedVariant !== after.selectedVariant) {
1874
1929
  if (after.selectedVariant === null) {
1875
- removeCookie(COOKIE_VARIANT);
1930
+ removeCookie(COOKIE_VARIANT, "/", crossSiteCookieOptions());
1876
1931
  } else {
1877
- setCookie(COOKIE_VARIANT, after.selectedVariant, COOKIE_OPTS);
1932
+ setCookie(COOKIE_VARIANT, after.selectedVariant, cookieOpts());
1878
1933
  }
1879
- updateParam(PARAM_VARIANT, after.selectedVariant);
1934
+ paramPatch[PARAM_VARIANT] = after.selectedVariant;
1880
1935
  sendPreprEvent("variant_changed", {
1881
1936
  variant: after.selectedVariant ?? void 0
1882
1937
  });
1883
1938
  }
1939
+ if (Object.keys(paramPatch).length > 0) {
1940
+ updateParams(paramPatch);
1941
+ }
1884
1942
  if (before.editMode !== after.editMode) {
1885
1943
  if (after.editMode) {
1886
1944
  stega.start();
@@ -1900,8 +1958,8 @@ function createChangeHandler(deps) {
1900
1958
  if (Object.keys(coupled).length > 0) {
1901
1959
  store.set(coupled);
1902
1960
  }
1903
- setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), COOKIE_OPTS);
1904
- setCookie(COOKIE_TOOLBAR_OPEN, "false", COOKIE_OPTS);
1961
+ setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1962
+ setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1905
1963
  sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1906
1964
  syncAutoClean(after.previewMode);
1907
1965
  const [path, existing] = splitPath(deps.currentPath());
@@ -1916,7 +1974,7 @@ function createChangeHandler(deps) {
1916
1974
  }
1917
1975
  }
1918
1976
  if (before.toolbarOpen !== after.toolbarOpen) {
1919
- setCookie(COOKIE_TOOLBAR_OPEN, String(after.toolbarOpen), COOKIE_OPTS);
1977
+ setCookie(COOKIE_TOOLBAR_OPEN, String(after.toolbarOpen), cookieOpts());
1920
1978
  }
1921
1979
  };
1922
1980
  }
@@ -2028,7 +2086,9 @@ function createPreprToolbar(opts) {
2028
2086
  });
2029
2087
  syncAutoClean(store.get().previewMode);
2030
2088
  const bridge = createIframeBridge(store);
2031
- sendPreprEvent("getScrollPosition", { value: 0 });
2089
+ sendPreprEvent("getScrollPosition", { value: 0 }, {
2090
+ allowUntrustedTarget: true
2091
+ });
2032
2092
  if (isIframe) {
2033
2093
  bridge.start();
2034
2094
  }