@preprio/toolkit 0.2.0-beta.6 → 0.2.0-beta.9

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.
@@ -2,7 +2,7 @@
2
2
  import { NextResponse } from "next/server";
3
3
 
4
4
  // src/version.ts
5
- var VERSION = "0.2.0-beta.6";
5
+ var VERSION = "0.2.0-beta.9";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -56,7 +56,11 @@ function parseCookies(request) {
56
56
  const name = part.slice(0, eq).trim();
57
57
  const value = part.slice(eq + 1).trim();
58
58
  if (!name) continue;
59
- cookies.set(name, decodeURIComponent(value));
59
+ try {
60
+ cookies.set(name, decodeURIComponent(value));
61
+ } catch {
62
+ cookies.set(name, value);
63
+ }
60
64
  }
61
65
  return cookies;
62
66
  }
@@ -95,7 +99,10 @@ function processPreprRequest(request, opts) {
95
99
  if (userAgent) {
96
100
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
97
101
  }
98
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
102
+ requestHeaders.set(
103
+ "Prepr-Package",
104
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
105
+ );
99
106
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
100
107
  if (ip) {
101
108
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -104,7 +111,7 @@ function processPreprRequest(request, opts) {
104
111
  if (hutkCookie) {
105
112
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
106
113
  }
107
- let uid = requestCookies.get(COOKIE_UID);
114
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
108
115
  if (!uid) {
109
116
  uid = crypto.randomUUID();
110
117
  responseCookies.push({
@@ -188,19 +195,30 @@ function createPreprMiddleware(request, responseOrOptions, maybeOptions) {
188
195
  } else {
189
196
  options = responseOrOptions;
190
197
  }
191
- const { requestHeaders, responseCookies } = processPreprRequest(request, options);
198
+ const { requestHeaders, responseCookies } = processPreprRequest(
199
+ request,
200
+ options
201
+ );
192
202
  const response = chainedResponse ?? NextResponse.next({ request: { headers: requestHeaders } });
193
203
  if (chainedResponse) {
204
+ const existing = response.headers.get("x-middleware-override-headers");
205
+ const names = new Set(
206
+ existing ? existing.split(",").map((name) => name.trim()).filter(Boolean) : []
207
+ );
194
208
  requestHeaders.forEach((value, key) => {
195
- response.headers.set(key, value);
209
+ names.add(key);
210
+ response.headers.set(`x-middleware-request-${key}`, value);
196
211
  });
212
+ response.headers.set("x-middleware-override-headers", [...names].join(","));
197
213
  }
198
214
  for (const cookie of responseCookies) {
199
215
  response.cookies.set(cookie.name, cookie.value, {
200
216
  maxAge: cookie.maxAge,
201
217
  path: cookie.path,
202
218
  // Lower-cased: Next's cookie API expects 'none' | 'lax' | 'strict'.
203
- ...cookie.sameSite ? { sameSite: cookie.sameSite.toLowerCase() } : {},
219
+ ...cookie.sameSite ? {
220
+ sameSite: cookie.sameSite.toLowerCase()
221
+ } : {},
204
222
  ...cookie.secure ? { secure: true } : {}
205
223
  });
206
224
  }
@@ -260,7 +278,11 @@ function getPreprHeadersFromHeaders(headers2) {
260
278
  }
261
279
  function validatePreprToken(token) {
262
280
  if (!token) {
263
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
281
+ throw new PreprError(
282
+ "Token is required",
283
+ "MISSING_TOKEN",
284
+ "validatePreprToken"
285
+ );
264
286
  }
265
287
  if (!token.startsWith("https://")) {
266
288
  throw new PreprError(
@@ -393,7 +415,7 @@ async function getToolbarProps(token, features) {
393
415
  import {
394
416
  PreprToolbar,
395
417
  PreprTrackingPixel
396
- } from "./components";
418
+ } from "./components.js";
397
419
  export {
398
420
  PreprError,
399
421
  PreprToolbar,
@@ -35,7 +35,7 @@ __export(nuxt_exports, {
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "0.2.0-beta.6";
38
+ var VERSION = "0.2.0-beta.9";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -103,7 +103,11 @@ function parseCookies(request) {
103
103
  const name = part.slice(0, eq).trim();
104
104
  const value = part.slice(eq + 1).trim();
105
105
  if (!name) continue;
106
- cookies.set(name, decodeURIComponent(value));
106
+ try {
107
+ cookies.set(name, decodeURIComponent(value));
108
+ } catch {
109
+ cookies.set(name, value);
110
+ }
107
111
  }
108
112
  return cookies;
109
113
  }
@@ -142,7 +146,10 @@ function processPreprRequest(request, opts) {
142
146
  if (userAgent) {
143
147
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
144
148
  }
145
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
149
+ requestHeaders.set(
150
+ "Prepr-Package",
151
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
152
+ );
146
153
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
147
154
  if (ip) {
148
155
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -151,7 +158,7 @@ function processPreprRequest(request, opts) {
151
158
  if (hutkCookie) {
152
159
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
153
160
  }
154
- let uid = requestCookies.get(COOKIE_UID);
161
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
155
162
  if (!uid) {
156
163
  uid = crypto.randomUUID();
157
164
  responseCookies.push({
@@ -238,7 +245,10 @@ function handlePreprRequest(event, options) {
238
245
  request.headers.set(key, value.join(", "));
239
246
  }
240
247
  }
241
- const { requestHeaders, responseCookies } = processPreprRequest(request, options);
248
+ const { requestHeaders, responseCookies } = processPreprRequest(
249
+ request,
250
+ options
251
+ );
242
252
  requestHeaders.forEach((value, key) => {
243
253
  req.headers[key.toLowerCase()] = value;
244
254
  });
@@ -302,7 +312,11 @@ function getPreprHeadersFromHeaders(headers) {
302
312
  }
303
313
  function validatePreprToken(token) {
304
314
  if (!token) {
305
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
315
+ throw new PreprError(
316
+ "Token is required",
317
+ "MISSING_TOKEN",
318
+ "validatePreprToken"
319
+ );
306
320
  }
307
321
  if (!token.startsWith("https://")) {
308
322
  throw new PreprError(
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.2.0-beta.6";
2
+ var VERSION = "0.2.0-beta.9";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -67,7 +67,11 @@ function parseCookies(request) {
67
67
  const name = part.slice(0, eq).trim();
68
68
  const value = part.slice(eq + 1).trim();
69
69
  if (!name) continue;
70
- cookies.set(name, decodeURIComponent(value));
70
+ try {
71
+ cookies.set(name, decodeURIComponent(value));
72
+ } catch {
73
+ cookies.set(name, value);
74
+ }
71
75
  }
72
76
  return cookies;
73
77
  }
@@ -106,7 +110,10 @@ function processPreprRequest(request, opts) {
106
110
  if (userAgent) {
107
111
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
108
112
  }
109
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
113
+ requestHeaders.set(
114
+ "Prepr-Package",
115
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
116
+ );
110
117
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
111
118
  if (ip) {
112
119
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -115,7 +122,7 @@ function processPreprRequest(request, opts) {
115
122
  if (hutkCookie) {
116
123
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
117
124
  }
118
- let uid = requestCookies.get(COOKIE_UID);
125
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
119
126
  if (!uid) {
120
127
  uid = crypto.randomUUID();
121
128
  responseCookies.push({
@@ -202,7 +209,10 @@ function handlePreprRequest(event, options) {
202
209
  request.headers.set(key, value.join(", "));
203
210
  }
204
211
  }
205
- const { requestHeaders, responseCookies } = processPreprRequest(request, options);
212
+ const { requestHeaders, responseCookies } = processPreprRequest(
213
+ request,
214
+ options
215
+ );
206
216
  requestHeaders.forEach((value, key) => {
207
217
  req.headers[key.toLowerCase()] = value;
208
218
  });
@@ -266,7 +276,11 @@ function getPreprHeadersFromHeaders(headers) {
266
276
  }
267
277
  function validatePreprToken(token) {
268
278
  if (!token) {
269
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
279
+ throw new PreprError(
280
+ "Token is required",
281
+ "MISSING_TOKEN",
282
+ "validatePreprToken"
283
+ );
270
284
  }
271
285
  if (!token.startsWith("https://")) {
272
286
  throw new PreprError(
@@ -368,9 +368,7 @@ function decodeStega(str) {
368
368
  const match = str.match(/{"origin.*?}/);
369
369
  if (match) {
370
370
  try {
371
- const decodedMatch = (0, import_stega.vercelStegaDecode)(
372
- match[0]
373
- );
371
+ const decodedMatch = (0, import_stega.vercelStegaDecode)(match[0]);
374
372
  if (decodedMatch?.href) {
375
373
  return decodedMatch;
376
374
  }
@@ -439,6 +437,8 @@ function createStegaAutoClean() {
439
437
  function scanAndClean() {
440
438
  processing = true;
441
439
  walkTextNodes(document.body, cleanTextNode);
440
+ const title = (0, import_stega2.vercelStegaSplit)(document.title);
441
+ if (title.encoded) document.title = title.cleaned;
442
442
  processing = false;
443
443
  }
444
444
  function collectAffected(mutations) {
@@ -484,15 +484,8 @@ function createStegaAutoClean() {
484
484
  }
485
485
  function start() {
486
486
  if (observer || typeof window === "undefined") return;
487
- const run = () => {
488
- scanAndClean();
489
- setupObserver();
490
- };
491
- if ("requestIdleCallback" in window) {
492
- window.requestIdleCallback(run);
493
- } else {
494
- setTimeout(run, 0);
495
- }
487
+ scanAndClean();
488
+ setupObserver();
496
489
  debug2.log("stega auto-clean started");
497
490
  }
498
491
  function stop() {
@@ -903,8 +896,13 @@ function createStegaController(opts) {
903
896
  overlay.hide();
904
897
  }
905
898
  }, 16);
906
- document.addEventListener("mousemove", throttledMouseMove);
907
- window.addEventListener("scroll", handleScroll, { capture: true });
899
+ document.addEventListener("mousemove", throttledMouseMove, {
900
+ passive: true
901
+ });
902
+ window.addEventListener("scroll", handleScroll, {
903
+ capture: true,
904
+ passive: true
905
+ });
908
906
  initialized = true;
909
907
  debug6.log("stega controller started");
910
908
  };
@@ -985,7 +983,7 @@ function cookieOpts() {
985
983
  };
986
984
  }
987
985
  function createChangeHandler(deps) {
988
- const { store, stega, syncAutoClean, features, editingEnabled } = deps;
986
+ const { store, stega, features, editingEnabled } = deps;
989
987
  function updateParams(patch) {
990
988
  const [path, existing] = splitPath(deps.currentPath());
991
989
  const params = new URLSearchParams(existing);
@@ -1047,17 +1045,20 @@ function createChangeHandler(deps) {
1047
1045
  }
1048
1046
  setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1049
1047
  setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1050
- sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1051
- syncAutoClean(after.previewMode);
1052
- const [path, existing] = splitPath(deps.currentPath());
1053
- const params = new URLSearchParams(existing);
1054
- if (params.has(PARAM_SEGMENT) || params.has(PARAM_VARIANT)) {
1055
- params.delete(PARAM_SEGMENT);
1056
- params.delete(PARAM_VARIANT);
1057
- const query = params.toString();
1058
- deps.navigate(query ? `${path}?${query}` : path);
1059
- } else {
1060
- deps.reload();
1048
+ sendPreprEvent("preview_mode_toggled", {
1049
+ previewMode: after.previewMode
1050
+ });
1051
+ if (!after.isIframe) {
1052
+ const [path, existing] = splitPath(deps.currentPath());
1053
+ const params = new URLSearchParams(existing);
1054
+ if (params.has(PARAM_SEGMENT) || params.has(PARAM_VARIANT)) {
1055
+ params.delete(PARAM_SEGMENT);
1056
+ params.delete(PARAM_VARIANT);
1057
+ const query = params.toString();
1058
+ deps.navigate(query ? `${path}?${query}` : path);
1059
+ } else {
1060
+ deps.reload();
1061
+ }
1061
1062
  }
1062
1063
  }
1063
1064
  if (before.toolbarOpen !== after.toolbarOpen) {
@@ -1367,7 +1368,10 @@ function u2(e2, t3, n2, o2, i2, u3) {
1367
1368
  }
1368
1369
 
1369
1370
  // src/core/ui/panel.tsx
1370
- function RawSvg({ svg, className }) {
1371
+ function RawSvg({
1372
+ svg,
1373
+ className
1374
+ }) {
1371
1375
  return /* @__PURE__ */ u2(
1372
1376
  "span",
1373
1377
  {
@@ -1938,9 +1942,7 @@ var PreprToolbarElement = class extends HTMLElementBase {
1938
1942
  ) ?? null;
1939
1943
  }
1940
1944
  optionsList() {
1941
- return this.shadowRoot?.querySelector(
1942
- '[data-prepr="options"]'
1943
- ) ?? null;
1945
+ return this.shadowRoot?.querySelector('[data-prepr="options"]') ?? null;
1944
1946
  }
1945
1947
  onListboxKeydown(event) {
1946
1948
  const e2 = event;
@@ -2141,16 +2143,7 @@ function createPreprPreview(opts = {}) {
2141
2143
  }
2142
2144
  });
2143
2145
  const autoClean = createStegaAutoClean();
2144
- let autoCleanActive = false;
2145
- function syncAutoClean(active) {
2146
- if (active && !autoCleanActive) {
2147
- autoClean.start();
2148
- autoCleanActive = true;
2149
- } else if (!active && autoCleanActive) {
2150
- autoClean.stop();
2151
- autoCleanActive = false;
2152
- }
2153
- }
2146
+ autoClean.start();
2154
2147
  const handleChange = createChangeHandler({
2155
2148
  store,
2156
2149
  features,
@@ -2158,8 +2151,7 @@ function createPreprPreview(opts = {}) {
2158
2151
  navigate: (url) => navigation.navigate(url),
2159
2152
  currentPath: () => navigation.currentPath(),
2160
2153
  reload: navigation.reload ?? (() => window.location.reload()),
2161
- stega,
2162
- syncAutoClean
2154
+ stega
2163
2155
  });
2164
2156
  let prev = store.get();
2165
2157
  const unsubscribe = store.subscribe((state) => {
@@ -2167,20 +2159,23 @@ function createPreprPreview(opts = {}) {
2167
2159
  prev = state;
2168
2160
  handleChange(before, state);
2169
2161
  });
2170
- syncAutoClean(store.get().previewMode);
2171
2162
  const bridge = createIframeBridge(store, {
2172
2163
  allowedEditorOrigins: options?.allowedEditorOrigins
2173
2164
  });
2174
- sendPreprEvent("getScrollPosition", { value: 0 }, {
2175
- allowUntrustedTarget: true
2176
- });
2165
+ sendPreprEvent(
2166
+ "getScrollPosition",
2167
+ { value: 0 },
2168
+ {
2169
+ allowUntrustedTarget: true
2170
+ }
2171
+ );
2177
2172
  if (isIframe) {
2178
2173
  bridge.start();
2179
2174
  }
2180
2175
  function destroy() {
2181
2176
  unsubscribe();
2182
2177
  stega.stop();
2183
- syncAutoClean(false);
2178
+ autoClean.stop();
2184
2179
  if (isIframe) {
2185
2180
  bridge.stop();
2186
2181
  }
@@ -344,9 +344,7 @@ function decodeStega(str) {
344
344
  const match = str.match(/{"origin.*?}/);
345
345
  if (match) {
346
346
  try {
347
- const decodedMatch = vercelStegaDecode(
348
- match[0]
349
- );
347
+ const decodedMatch = vercelStegaDecode(match[0]);
350
348
  if (decodedMatch?.href) {
351
349
  return decodedMatch;
352
350
  }
@@ -415,6 +413,8 @@ function createStegaAutoClean() {
415
413
  function scanAndClean() {
416
414
  processing = true;
417
415
  walkTextNodes(document.body, cleanTextNode);
416
+ const title = vercelStegaSplit(document.title);
417
+ if (title.encoded) document.title = title.cleaned;
418
418
  processing = false;
419
419
  }
420
420
  function collectAffected(mutations) {
@@ -460,15 +460,8 @@ function createStegaAutoClean() {
460
460
  }
461
461
  function start() {
462
462
  if (observer || typeof window === "undefined") return;
463
- const run = () => {
464
- scanAndClean();
465
- setupObserver();
466
- };
467
- if ("requestIdleCallback" in window) {
468
- window.requestIdleCallback(run);
469
- } else {
470
- setTimeout(run, 0);
471
- }
463
+ scanAndClean();
464
+ setupObserver();
472
465
  debug2.log("stega auto-clean started");
473
466
  }
474
467
  function stop() {
@@ -879,8 +872,13 @@ function createStegaController(opts) {
879
872
  overlay.hide();
880
873
  }
881
874
  }, 16);
882
- document.addEventListener("mousemove", throttledMouseMove);
883
- window.addEventListener("scroll", handleScroll, { capture: true });
875
+ document.addEventListener("mousemove", throttledMouseMove, {
876
+ passive: true
877
+ });
878
+ window.addEventListener("scroll", handleScroll, {
879
+ capture: true,
880
+ passive: true
881
+ });
884
882
  initialized = true;
885
883
  debug6.log("stega controller started");
886
884
  };
@@ -961,7 +959,7 @@ function cookieOpts() {
961
959
  };
962
960
  }
963
961
  function createChangeHandler(deps) {
964
- const { store, stega, syncAutoClean, features, editingEnabled } = deps;
962
+ const { store, stega, features, editingEnabled } = deps;
965
963
  function updateParams(patch) {
966
964
  const [path, existing] = splitPath(deps.currentPath());
967
965
  const params = new URLSearchParams(existing);
@@ -1023,17 +1021,20 @@ function createChangeHandler(deps) {
1023
1021
  }
1024
1022
  setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1025
1023
  setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1026
- sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1027
- syncAutoClean(after.previewMode);
1028
- const [path, existing] = splitPath(deps.currentPath());
1029
- const params = new URLSearchParams(existing);
1030
- if (params.has(PARAM_SEGMENT) || params.has(PARAM_VARIANT)) {
1031
- params.delete(PARAM_SEGMENT);
1032
- params.delete(PARAM_VARIANT);
1033
- const query = params.toString();
1034
- deps.navigate(query ? `${path}?${query}` : path);
1035
- } else {
1036
- deps.reload();
1024
+ sendPreprEvent("preview_mode_toggled", {
1025
+ previewMode: after.previewMode
1026
+ });
1027
+ if (!after.isIframe) {
1028
+ const [path, existing] = splitPath(deps.currentPath());
1029
+ const params = new URLSearchParams(existing);
1030
+ if (params.has(PARAM_SEGMENT) || params.has(PARAM_VARIANT)) {
1031
+ params.delete(PARAM_SEGMENT);
1032
+ params.delete(PARAM_VARIANT);
1033
+ const query = params.toString();
1034
+ deps.navigate(query ? `${path}?${query}` : path);
1035
+ } else {
1036
+ deps.reload();
1037
+ }
1037
1038
  }
1038
1039
  }
1039
1040
  if (before.toolbarOpen !== after.toolbarOpen) {
@@ -1343,7 +1344,10 @@ function u2(e2, t3, n2, o2, i2, u3) {
1343
1344
  }
1344
1345
 
1345
1346
  // src/core/ui/panel.tsx
1346
- function RawSvg({ svg, className }) {
1347
+ function RawSvg({
1348
+ svg,
1349
+ className
1350
+ }) {
1347
1351
  return /* @__PURE__ */ u2(
1348
1352
  "span",
1349
1353
  {
@@ -1914,9 +1918,7 @@ var PreprToolbarElement = class extends HTMLElementBase {
1914
1918
  ) ?? null;
1915
1919
  }
1916
1920
  optionsList() {
1917
- return this.shadowRoot?.querySelector(
1918
- '[data-prepr="options"]'
1919
- ) ?? null;
1921
+ return this.shadowRoot?.querySelector('[data-prepr="options"]') ?? null;
1920
1922
  }
1921
1923
  onListboxKeydown(event) {
1922
1924
  const e2 = event;
@@ -2117,16 +2119,7 @@ function createPreprPreview(opts = {}) {
2117
2119
  }
2118
2120
  });
2119
2121
  const autoClean = createStegaAutoClean();
2120
- let autoCleanActive = false;
2121
- function syncAutoClean(active) {
2122
- if (active && !autoCleanActive) {
2123
- autoClean.start();
2124
- autoCleanActive = true;
2125
- } else if (!active && autoCleanActive) {
2126
- autoClean.stop();
2127
- autoCleanActive = false;
2128
- }
2129
- }
2122
+ autoClean.start();
2130
2123
  const handleChange = createChangeHandler({
2131
2124
  store,
2132
2125
  features,
@@ -2134,8 +2127,7 @@ function createPreprPreview(opts = {}) {
2134
2127
  navigate: (url) => navigation.navigate(url),
2135
2128
  currentPath: () => navigation.currentPath(),
2136
2129
  reload: navigation.reload ?? (() => window.location.reload()),
2137
- stega,
2138
- syncAutoClean
2130
+ stega
2139
2131
  });
2140
2132
  let prev = store.get();
2141
2133
  const unsubscribe = store.subscribe((state) => {
@@ -2143,20 +2135,23 @@ function createPreprPreview(opts = {}) {
2143
2135
  prev = state;
2144
2136
  handleChange(before, state);
2145
2137
  });
2146
- syncAutoClean(store.get().previewMode);
2147
2138
  const bridge = createIframeBridge(store, {
2148
2139
  allowedEditorOrigins: options?.allowedEditorOrigins
2149
2140
  });
2150
- sendPreprEvent("getScrollPosition", { value: 0 }, {
2151
- allowUntrustedTarget: true
2152
- });
2141
+ sendPreprEvent(
2142
+ "getScrollPosition",
2143
+ { value: 0 },
2144
+ {
2145
+ allowUntrustedTarget: true
2146
+ }
2147
+ );
2153
2148
  if (isIframe) {
2154
2149
  bridge.start();
2155
2150
  }
2156
2151
  function destroy() {
2157
2152
  unsubscribe();
2158
2153
  stega.stop();
2159
- syncAutoClean(false);
2154
+ autoClean.stop();
2160
2155
  if (isIframe) {
2161
2156
  bridge.stop();
2162
2157
  }
@@ -24,7 +24,7 @@ __export(react_exports, {
24
24
  PreprTrackingPixel: () => import_components.PreprTrackingPixel
25
25
  });
26
26
  module.exports = __toCommonJS(react_exports);
27
- var import_components = require("./components.js");
27
+ var import_components = require("./components.cjs");
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
30
30
  PreprPreview,
@@ -1 +1 @@
1
- export { PreprPreview, PreprPreviewProps, PreprTrackingPixel, PreprTrackingPixelProps } from './components.js';
1
+ export { PreprPreview, PreprPreviewProps, PreprTrackingPixel, PreprTrackingPixelProps } from './components.cjs';
@@ -35,7 +35,7 @@ __export(sveltekit_exports, {
35
35
  module.exports = __toCommonJS(sveltekit_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "0.2.0-beta.6";
38
+ var VERSION = "0.2.0-beta.9";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -103,7 +103,11 @@ function parseCookies(request) {
103
103
  const name = part.slice(0, eq).trim();
104
104
  const value = part.slice(eq + 1).trim();
105
105
  if (!name) continue;
106
- cookies.set(name, decodeURIComponent(value));
106
+ try {
107
+ cookies.set(name, decodeURIComponent(value));
108
+ } catch {
109
+ cookies.set(name, value);
110
+ }
107
111
  }
108
112
  return cookies;
109
113
  }
@@ -142,7 +146,10 @@ function processPreprRequest(request, opts) {
142
146
  if (userAgent) {
143
147
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
144
148
  }
145
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
149
+ requestHeaders.set(
150
+ "Prepr-Package",
151
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
152
+ );
146
153
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
147
154
  if (ip) {
148
155
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -151,7 +158,7 @@ function processPreprRequest(request, opts) {
151
158
  if (hutkCookie) {
152
159
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
153
160
  }
154
- let uid = requestCookies.get(COOKIE_UID);
161
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
155
162
  if (!uid) {
156
163
  uid = crypto.randomUUID();
157
164
  responseCookies.push({
@@ -229,7 +236,10 @@ function processPreprRequest(request, opts) {
229
236
  var PREPR_LOCALS_KEY = "prepr";
230
237
  function preprHandle(options) {
231
238
  return async ({ event, resolve }) => {
232
- const { requestHeaders, responseCookies } = processPreprRequest(event.request, options);
239
+ const { requestHeaders, responseCookies } = processPreprRequest(
240
+ event.request,
241
+ options
242
+ );
233
243
  requestHeaders.forEach((value, key) => {
234
244
  event.request.headers.set(key, value);
235
245
  });
@@ -298,7 +308,11 @@ function getPreprHeadersFromHeaders(headers) {
298
308
  }
299
309
  function validatePreprToken(token) {
300
310
  if (!token) {
301
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
311
+ throw new PreprError(
312
+ "Token is required",
313
+ "MISSING_TOKEN",
314
+ "validatePreprToken"
315
+ );
302
316
  }
303
317
  if (!token.startsWith("https://")) {
304
318
  throw new PreprError(