@preprio/toolkit 0.2.0-beta.7 → 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.
@@ -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.2.0-beta.7";
33
+ var VERSION = "0.2.0-beta.9";
34
34
 
35
35
  // src/core/features.ts
36
36
  function isEnabled(config) {
@@ -100,7 +100,11 @@ function getPreprHeadersFromHeaders(headers) {
100
100
  }
101
101
  function validatePreprToken(token) {
102
102
  if (!token) {
103
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
103
+ throw new PreprError(
104
+ "Token is required",
105
+ "MISSING_TOKEN",
106
+ "validatePreprToken"
107
+ );
104
108
  }
105
109
  if (!token.startsWith("https://")) {
106
110
  throw new PreprError(
@@ -222,7 +226,11 @@ function parseCookies(request) {
222
226
  const name = part.slice(0, eq).trim();
223
227
  const value = part.slice(eq + 1).trim();
224
228
  if (!name) continue;
225
- cookies.set(name, decodeURIComponent(value));
229
+ try {
230
+ cookies.set(name, decodeURIComponent(value));
231
+ } catch {
232
+ cookies.set(name, value);
233
+ }
226
234
  }
227
235
  return cookies;
228
236
  }
@@ -261,7 +269,10 @@ function processPreprRequest(request, opts) {
261
269
  if (userAgent) {
262
270
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
263
271
  }
264
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
272
+ requestHeaders.set(
273
+ "Prepr-Package",
274
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
275
+ );
265
276
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
266
277
  if (ip) {
267
278
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -270,7 +281,7 @@ function processPreprRequest(request, opts) {
270
281
  if (hutkCookie) {
271
282
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
272
283
  }
273
- let uid = requestCookies.get(COOKIE_UID);
284
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
274
285
  if (!uid) {
275
286
  uid = crypto.randomUUID();
276
287
  responseCookies.push({
@@ -346,7 +357,10 @@ function processPreprRequest(request, opts) {
346
357
 
347
358
  // src/astro/index.ts
348
359
  async function onPreprRequest(context, next, options) {
349
- const { requestHeaders, responseCookies } = processPreprRequest(context.request, options);
360
+ const { requestHeaders, responseCookies } = processPreprRequest(
361
+ context.request,
362
+ options
363
+ );
350
364
  requestHeaders.forEach((value, key) => {
351
365
  context.request.headers.set(key, value);
352
366
  });
@@ -90,7 +90,7 @@ type AstroNext = () => Promise<Response>;
90
90
  * Astro middleware entry point: computes the Prepr headers/cookies for this
91
91
  * request, forwards the headers downstream and sets the cookies on the response.
92
92
  *
93
- * Astro hands downstream code the same `Request` instance we get here, so the
93
+ * Astro hands downstream code the same `Request` instance this middleware receives, so the
94
94
  * headers are mutated in place — building a new `Request` would go nowhere,
95
95
  * there's no way to hand a replacement back out of middleware.
96
96
  */
@@ -90,7 +90,7 @@ type AstroNext = () => Promise<Response>;
90
90
  * Astro middleware entry point: computes the Prepr headers/cookies for this
91
91
  * request, forwards the headers downstream and sets the cookies on the response.
92
92
  *
93
- * Astro hands downstream code the same `Request` instance we get here, so the
93
+ * Astro hands downstream code the same `Request` instance this middleware receives, so the
94
94
  * headers are mutated in place — building a new `Request` would go nowhere,
95
95
  * there's no way to hand a replacement back out of middleware.
96
96
  */
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.2.0-beta.7";
2
+ var VERSION = "0.2.0-beta.9";
3
3
 
4
4
  // src/core/features.ts
5
5
  function isEnabled(config) {
@@ -69,7 +69,11 @@ function getPreprHeadersFromHeaders(headers) {
69
69
  }
70
70
  function validatePreprToken(token) {
71
71
  if (!token) {
72
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
72
+ throw new PreprError(
73
+ "Token is required",
74
+ "MISSING_TOKEN",
75
+ "validatePreprToken"
76
+ );
73
77
  }
74
78
  if (!token.startsWith("https://")) {
75
79
  throw new PreprError(
@@ -191,7 +195,11 @@ function parseCookies(request) {
191
195
  const name = part.slice(0, eq).trim();
192
196
  const value = part.slice(eq + 1).trim();
193
197
  if (!name) continue;
194
- cookies.set(name, decodeURIComponent(value));
198
+ try {
199
+ cookies.set(name, decodeURIComponent(value));
200
+ } catch {
201
+ cookies.set(name, value);
202
+ }
195
203
  }
196
204
  return cookies;
197
205
  }
@@ -230,7 +238,10 @@ function processPreprRequest(request, opts) {
230
238
  if (userAgent) {
231
239
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
232
240
  }
233
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
241
+ requestHeaders.set(
242
+ "Prepr-Package",
243
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
244
+ );
234
245
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
235
246
  if (ip) {
236
247
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -239,7 +250,7 @@ function processPreprRequest(request, opts) {
239
250
  if (hutkCookie) {
240
251
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
241
252
  }
242
- let uid = requestCookies.get(COOKIE_UID);
253
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
243
254
  if (!uid) {
244
255
  uid = crypto.randomUUID();
245
256
  responseCookies.push({
@@ -315,7 +326,10 @@ function processPreprRequest(request, opts) {
315
326
 
316
327
  // src/astro/index.ts
317
328
  async function onPreprRequest(context, next, options) {
318
- const { requestHeaders, responseCookies } = processPreprRequest(context.request, options);
329
+ const { requestHeaders, responseCookies } = processPreprRequest(
330
+ context.request,
331
+ options
332
+ );
319
333
  requestHeaders.forEach((value, key) => {
320
334
  context.request.headers.set(key, value);
321
335
  });
@@ -142,9 +142,7 @@ function decodeStega(str) {
142
142
  const match = str.match(/{"origin.*?}/);
143
143
  if (match) {
144
144
  try {
145
- const decodedMatch = vercelStegaDecode(
146
- match[0]
147
- );
145
+ const decodedMatch = vercelStegaDecode(match[0]);
148
146
  if (decodedMatch?.href) {
149
147
  return decodedMatch;
150
148
  }
@@ -570,8 +568,13 @@ function createStegaController(opts) {
570
568
  overlay.hide();
571
569
  }
572
570
  }, 16);
573
- document.addEventListener("mousemove", throttledMouseMove);
574
- window.addEventListener("scroll", handleScroll, { capture: true });
571
+ document.addEventListener("mousemove", throttledMouseMove, {
572
+ passive: true
573
+ });
574
+ window.addEventListener("scroll", handleScroll, {
575
+ capture: true,
576
+ passive: true
577
+ });
575
578
  initialized = true;
576
579
  debug5.log("stega controller started");
577
580
  };
@@ -1042,7 +1045,10 @@ function u2(e2, t3, n2, o2, i2, u3) {
1042
1045
  }
1043
1046
 
1044
1047
  // src/core/ui/panel.tsx
1045
- function RawSvg({ svg, className }) {
1048
+ function RawSvg({
1049
+ svg,
1050
+ className
1051
+ }) {
1046
1052
  return /* @__PURE__ */ u2(
1047
1053
  "span",
1048
1054
  {
@@ -1613,9 +1619,7 @@ var PreprToolbarElement = class extends HTMLElementBase {
1613
1619
  ) ?? null;
1614
1620
  }
1615
1621
  optionsList() {
1616
- return this.shadowRoot?.querySelector(
1617
- '[data-prepr="options"]'
1618
- ) ?? null;
1622
+ return this.shadowRoot?.querySelector('[data-prepr="options"]') ?? null;
1619
1623
  }
1620
1624
  onListboxKeydown(event) {
1621
1625
  const e2 = event;
@@ -1991,7 +1995,9 @@ function createChangeHandler(deps) {
1991
1995
  }
1992
1996
  setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1993
1997
  setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1994
- sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1998
+ sendPreprEvent("preview_mode_toggled", {
1999
+ previewMode: after.previewMode
2000
+ });
1995
2001
  if (!after.isIframe) {
1996
2002
  const [path, existing] = splitPath(deps.currentPath());
1997
2003
  const params = new URLSearchParams(existing);
@@ -2133,9 +2139,13 @@ function createPreprPreview(opts = {}) {
2133
2139
  const bridge = createIframeBridge(store, {
2134
2140
  allowedEditorOrigins: options?.allowedEditorOrigins
2135
2141
  });
2136
- sendPreprEvent("getScrollPosition", { value: 0 }, {
2137
- allowUntrustedTarget: true
2138
- });
2142
+ sendPreprEvent(
2143
+ "getScrollPosition",
2144
+ { value: 0 },
2145
+ {
2146
+ allowUntrustedTarget: true
2147
+ }
2148
+ );
2139
2149
  if (isIframe) {
2140
2150
  bridge.start();
2141
2151
  }
package/dist/index.cjs CHANGED
@@ -44,7 +44,7 @@ __export(src_exports, {
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
46
  // src/version.ts
47
- var VERSION = "0.2.0-beta.7";
47
+ var VERSION = "0.2.0-beta.9";
48
48
 
49
49
  // src/core/features.ts
50
50
  function isEnabled(config) {
@@ -393,9 +393,7 @@ function decodeStega(str) {
393
393
  const match = str.match(/{"origin.*?}/);
394
394
  if (match) {
395
395
  try {
396
- const decodedMatch = (0, import_stega.vercelStegaDecode)(
397
- match[0]
398
- );
396
+ const decodedMatch = (0, import_stega.vercelStegaDecode)(match[0]);
399
397
  if (decodedMatch?.href) {
400
398
  return decodedMatch;
401
399
  }
@@ -923,8 +921,13 @@ function createStegaController(opts) {
923
921
  overlay.hide();
924
922
  }
925
923
  }, 16);
926
- document.addEventListener("mousemove", throttledMouseMove);
927
- window.addEventListener("scroll", handleScroll, { capture: true });
924
+ document.addEventListener("mousemove", throttledMouseMove, {
925
+ passive: true
926
+ });
927
+ window.addEventListener("scroll", handleScroll, {
928
+ capture: true,
929
+ passive: true
930
+ });
928
931
  initialized = true;
929
932
  debug6.log("stega controller started");
930
933
  };
@@ -1067,7 +1070,9 @@ function createChangeHandler(deps) {
1067
1070
  }
1068
1071
  setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1069
1072
  setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1070
- sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1073
+ sendPreprEvent("preview_mode_toggled", {
1074
+ previewMode: after.previewMode
1075
+ });
1071
1076
  if (!after.isIframe) {
1072
1077
  const [path, existing] = splitPath(deps.currentPath());
1073
1078
  const params = new URLSearchParams(existing);
@@ -1388,7 +1393,10 @@ function u2(e2, t3, n2, o2, i2, u3) {
1388
1393
  }
1389
1394
 
1390
1395
  // src/core/ui/panel.tsx
1391
- function RawSvg({ svg, className }) {
1396
+ function RawSvg({
1397
+ svg,
1398
+ className
1399
+ }) {
1392
1400
  return /* @__PURE__ */ u2(
1393
1401
  "span",
1394
1402
  {
@@ -1959,9 +1967,7 @@ var PreprToolbarElement = class extends HTMLElementBase {
1959
1967
  ) ?? null;
1960
1968
  }
1961
1969
  optionsList() {
1962
- return this.shadowRoot?.querySelector(
1963
- '[data-prepr="options"]'
1964
- ) ?? null;
1970
+ return this.shadowRoot?.querySelector('[data-prepr="options"]') ?? null;
1965
1971
  }
1966
1972
  onListboxKeydown(event) {
1967
1973
  const e2 = event;
@@ -2181,9 +2187,13 @@ function createPreprPreview(opts = {}) {
2181
2187
  const bridge = createIframeBridge(store, {
2182
2188
  allowedEditorOrigins: options?.allowedEditorOrigins
2183
2189
  });
2184
- sendPreprEvent("getScrollPosition", { value: 0 }, {
2185
- allowUntrustedTarget: true
2186
- });
2190
+ sendPreprEvent(
2191
+ "getScrollPosition",
2192
+ { value: 0 },
2193
+ {
2194
+ allowUntrustedTarget: true
2195
+ }
2196
+ );
2187
2197
  if (isIframe) {
2188
2198
  bridge.start();
2189
2199
  }
@@ -2252,7 +2262,11 @@ function getPreprHeadersFromHeaders(headers) {
2252
2262
  }
2253
2263
  function validatePreprToken(token) {
2254
2264
  if (!token) {
2255
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
2265
+ throw new PreprError(
2266
+ "Token is required",
2267
+ "MISSING_TOKEN",
2268
+ "validatePreprToken"
2269
+ );
2256
2270
  }
2257
2271
  if (!token.startsWith("https://")) {
2258
2272
  throw new PreprError(
@@ -2379,7 +2393,11 @@ function parseCookies(request) {
2379
2393
  const name = part.slice(0, eq).trim();
2380
2394
  const value = part.slice(eq + 1).trim();
2381
2395
  if (!name) continue;
2382
- cookies.set(name, decodeURIComponent(value));
2396
+ try {
2397
+ cookies.set(name, decodeURIComponent(value));
2398
+ } catch {
2399
+ cookies.set(name, value);
2400
+ }
2383
2401
  }
2384
2402
  return cookies;
2385
2403
  }
@@ -2418,7 +2436,10 @@ function processPreprRequest(request, opts) {
2418
2436
  if (userAgent) {
2419
2437
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
2420
2438
  }
2421
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
2439
+ requestHeaders.set(
2440
+ "Prepr-Package",
2441
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
2442
+ );
2422
2443
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
2423
2444
  if (ip) {
2424
2445
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -2427,7 +2448,7 @@ function processPreprRequest(request, opts) {
2427
2448
  if (hutkCookie) {
2428
2449
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
2429
2450
  }
2430
- let uid = requestCookies.get(COOKIE_UID);
2451
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
2431
2452
  if (!uid) {
2432
2453
  uid = crypto.randomUUID();
2433
2454
  responseCookies.push({
package/dist/index.d.cts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "0.2.0-beta.7";
8
+ declare const VERSION = "0.2.0-beta.9";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "0.2.0-beta.7";
8
+ declare const VERSION = "0.2.0-beta.9";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.js CHANGED
@@ -17,10 +17,10 @@ import {
17
17
  setTrackingParam,
18
18
  stegaClean,
19
19
  trackEvent
20
- } from "./chunk-P6VTLWM4.js";
20
+ } from "./chunk-JVUG6S4O.js";
21
21
 
22
22
  // src/version.ts
23
- var VERSION = "0.2.0-beta.7";
23
+ var VERSION = "0.2.0-beta.9";
24
24
 
25
25
  // src/core/server.ts
26
26
  var PreprError = class extends Error {
@@ -72,7 +72,11 @@ function getPreprHeadersFromHeaders(headers) {
72
72
  }
73
73
  function validatePreprToken(token) {
74
74
  if (!token) {
75
- throw new PreprError("Token is required", "MISSING_TOKEN", "validatePreprToken");
75
+ throw new PreprError(
76
+ "Token is required",
77
+ "MISSING_TOKEN",
78
+ "validatePreprToken"
79
+ );
76
80
  }
77
81
  if (!token.startsWith("https://")) {
78
82
  throw new PreprError(
@@ -199,7 +203,11 @@ function parseCookies(request) {
199
203
  const name = part.slice(0, eq).trim();
200
204
  const value = part.slice(eq + 1).trim();
201
205
  if (!name) continue;
202
- cookies.set(name, decodeURIComponent(value));
206
+ try {
207
+ cookies.set(name, decodeURIComponent(value));
208
+ } catch {
209
+ cookies.set(name, value);
210
+ }
203
211
  }
204
212
  return cookies;
205
213
  }
@@ -238,7 +246,10 @@ function processPreprRequest(request, opts) {
238
246
  if (userAgent) {
239
247
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
240
248
  }
241
- requestHeaders.set("Prepr-Package", `@preprio/toolkit@${opts?.version ?? VERSION}`);
249
+ requestHeaders.set(
250
+ "Prepr-Package",
251
+ `@preprio/toolkit@${opts?.version ?? VERSION}`
252
+ );
242
253
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
243
254
  if (ip) {
244
255
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -247,7 +258,7 @@ function processPreprRequest(request, opts) {
247
258
  if (hutkCookie) {
248
259
  requestHeaders.set("Prepr-Hubspot-Id", sanitizeHeaderValue(hutkCookie));
249
260
  }
250
- let uid = requestCookies.get(COOKIE_UID);
261
+ let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
251
262
  if (!uid) {
252
263
  uid = crypto.randomUUID();
253
264
  responseCookies.push({
@@ -369,9 +369,7 @@ function decodeStega(str) {
369
369
  const match = str.match(/{"origin.*?}/);
370
370
  if (match) {
371
371
  try {
372
- const decodedMatch = (0, import_stega.vercelStegaDecode)(
373
- match[0]
374
- );
372
+ const decodedMatch = (0, import_stega.vercelStegaDecode)(match[0]);
375
373
  if (decodedMatch?.href) {
376
374
  return decodedMatch;
377
375
  }
@@ -899,8 +897,13 @@ function createStegaController(opts) {
899
897
  overlay.hide();
900
898
  }
901
899
  }, 16);
902
- document.addEventListener("mousemove", throttledMouseMove);
903
- window.addEventListener("scroll", handleScroll, { capture: true });
900
+ document.addEventListener("mousemove", throttledMouseMove, {
901
+ passive: true
902
+ });
903
+ window.addEventListener("scroll", handleScroll, {
904
+ capture: true,
905
+ passive: true
906
+ });
904
907
  initialized = true;
905
908
  debug6.log("stega controller started");
906
909
  };
@@ -1043,7 +1046,9 @@ function createChangeHandler(deps) {
1043
1046
  }
1044
1047
  setCookie(COOKIE_PREVIEW_MODE, String(after.previewMode), cookieOpts());
1045
1048
  setCookie(COOKIE_TOOLBAR_OPEN, "false", cookieOpts());
1046
- sendPreprEvent("preview_mode_toggled", { previewMode: after.previewMode });
1049
+ sendPreprEvent("preview_mode_toggled", {
1050
+ previewMode: after.previewMode
1051
+ });
1047
1052
  if (!after.isIframe) {
1048
1053
  const [path, existing] = splitPath(deps.currentPath());
1049
1054
  const params = new URLSearchParams(existing);
@@ -1364,7 +1369,10 @@ function u2(e2, t3, n2, o2, i2, u3) {
1364
1369
  }
1365
1370
 
1366
1371
  // src/core/ui/panel.tsx
1367
- function RawSvg({ svg, className }) {
1372
+ function RawSvg({
1373
+ svg,
1374
+ className
1375
+ }) {
1368
1376
  return /* @__PURE__ */ u2(
1369
1377
  "span",
1370
1378
  {
@@ -1935,9 +1943,7 @@ var PreprToolbarElement = class extends HTMLElementBase {
1935
1943
  ) ?? null;
1936
1944
  }
1937
1945
  optionsList() {
1938
- return this.shadowRoot?.querySelector(
1939
- '[data-prepr="options"]'
1940
- ) ?? null;
1946
+ return this.shadowRoot?.querySelector('[data-prepr="options"]') ?? null;
1941
1947
  }
1942
1948
  onListboxKeydown(event) {
1943
1949
  const e2 = event;
@@ -2157,9 +2163,13 @@ function createPreprPreview(opts = {}) {
2157
2163
  const bridge = createIframeBridge(store, {
2158
2164
  allowedEditorOrigins: options?.allowedEditorOrigins
2159
2165
  });
2160
- sendPreprEvent("getScrollPosition", { value: 0 }, {
2161
- allowUntrustedTarget: true
2162
- });
2166
+ sendPreprEvent(
2167
+ "getScrollPosition",
2168
+ { value: 0 },
2169
+ {
2170
+ allowUntrustedTarget: true
2171
+ }
2172
+ );
2163
2173
  if (isIframe) {
2164
2174
  bridge.start();
2165
2175
  }
@@ -2237,13 +2247,15 @@ function PreprToolbar({
2237
2247
  }) {
2238
2248
  const router = (0, import_navigation.useRouter)();
2239
2249
  const pathname = (0, import_navigation.usePathname)();
2250
+ const pathnameRef = (0, import_react2.useRef)(pathname);
2251
+ pathnameRef.current = pathname;
2240
2252
  (0, import_react2.useEffect)(() => {
2241
2253
  const toolbar = createPreprPreview({
2242
2254
  props,
2243
2255
  options,
2244
2256
  navigation: {
2245
2257
  navigate: (url) => router.push(url),
2246
- currentPath: () => pathname + window.location.search
2258
+ currentPath: () => pathnameRef.current + window.location.search
2247
2259
  }
2248
2260
  });
2249
2261
  return () => toolbar.destroy();
@@ -2,11 +2,11 @@
2
2
  import {
3
3
  createPreprPreview,
4
4
  loadTrackingPixel
5
- } from "../chunk-P6VTLWM4.js";
5
+ } from "../chunk-JVUG6S4O.js";
6
6
 
7
7
  // src/nextjs/components.ts
8
8
  import { usePathname, useRouter } from "next/navigation";
9
- import { useEffect as useEffect2 } from "react";
9
+ import { useEffect as useEffect2, useRef } from "react";
10
10
 
11
11
  // src/react/components.ts
12
12
  import { useEffect } from "react";
@@ -27,13 +27,15 @@ function PreprToolbar({
27
27
  }) {
28
28
  const router = useRouter();
29
29
  const pathname = usePathname();
30
+ const pathnameRef = useRef(pathname);
31
+ pathnameRef.current = pathname;
30
32
  useEffect2(() => {
31
33
  const toolbar = createPreprPreview({
32
34
  props,
33
35
  options,
34
36
  navigation: {
35
37
  navigate: (url) => router.push(url),
36
- currentPath: () => pathname + window.location.search
38
+ currentPath: () => pathnameRef.current + window.location.search
37
39
  }
38
40
  });
39
41
  return () => toolbar.destroy();
@@ -25,7 +25,10 @@ __export(image_loader_exports, {
25
25
  module.exports = __toCommonJS(image_loader_exports);
26
26
  var TRANSFORM_SEGMENT = /\/([^/]*\bw_\d+[^/]*)\//;
27
27
  var isPositiveInteger = (value) => /^\d+$/.test(value);
28
- function preprImageLoader({ src, width }) {
28
+ function preprImageLoader({
29
+ src,
30
+ width
31
+ }) {
29
32
  return src.replace(TRANSFORM_SEGMENT, (match, segment) => {
30
33
  const options = segment.split(",").map((pair) => {
31
34
  const underscore = pair.indexOf("_");
@@ -36,7 +39,9 @@ function preprImageLoader({ src, width }) {
36
39
  const emittedHeight = options.find(([key]) => key === "h");
37
40
  if (emittedHeight && isPositiveInteger(emittedHeight[1])) {
38
41
  emittedHeight[1] = String(
39
- Math.round(width * Number(emittedHeight[1]) / Number(emittedWidth[1]))
42
+ Math.round(
43
+ width * Number(emittedHeight[1]) / Number(emittedWidth[1])
44
+ )
40
45
  );
41
46
  }
42
47
  emittedWidth[1] = String(width);
@@ -9,6 +9,6 @@ import { ImageLoaderProps } from 'next/image';
9
9
  * neither of which is a ceiling on what the CDN can serve, so capping there
10
10
  * would rule out retina.
11
11
  */
12
- declare function preprImageLoader({ src, width }: ImageLoaderProps): string;
12
+ declare function preprImageLoader({ src, width, }: ImageLoaderProps): string;
13
13
 
14
14
  export { preprImageLoader as default };
@@ -9,6 +9,6 @@ import { ImageLoaderProps } from 'next/image';
9
9
  * neither of which is a ceiling on what the CDN can serve, so capping there
10
10
  * would rule out retina.
11
11
  */
12
- declare function preprImageLoader({ src, width }: ImageLoaderProps): string;
12
+ declare function preprImageLoader({ src, width, }: ImageLoaderProps): string;
13
13
 
14
14
  export { preprImageLoader as default };
@@ -1,7 +1,10 @@
1
1
  // src/nextjs/image-loader.ts
2
2
  var TRANSFORM_SEGMENT = /\/([^/]*\bw_\d+[^/]*)\//;
3
3
  var isPositiveInteger = (value) => /^\d+$/.test(value);
4
- function preprImageLoader({ src, width }) {
4
+ function preprImageLoader({
5
+ src,
6
+ width
7
+ }) {
5
8
  return src.replace(TRANSFORM_SEGMENT, (match, segment) => {
6
9
  const options = segment.split(",").map((pair) => {
7
10
  const underscore = pair.indexOf("_");
@@ -12,7 +15,9 @@ function preprImageLoader({ src, width }) {
12
15
  const emittedHeight = options.find(([key]) => key === "h");
13
16
  if (emittedHeight && isPositiveInteger(emittedHeight[1])) {
14
17
  emittedHeight[1] = String(
15
- Math.round(width * Number(emittedHeight[1]) / Number(emittedWidth[1]))
18
+ Math.round(
19
+ width * Number(emittedHeight[1]) / Number(emittedWidth[1])
20
+ )
16
21
  );
17
22
  }
18
23
  emittedWidth[1] = String(width);