@preprio/toolkit 0.4.2 → 0.5.0-rc.1

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/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-Wsfvw9G2.cjs';
2
- export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-Wsfvw9G2.cjs';
1
+ import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-e1fUWl2Y.cjs';
2
+ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-e1fUWl2Y.cjs';
3
3
 
4
4
  /**
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.4.2";
8
+ declare const VERSION = "0.5.0-rc.1";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
@@ -137,12 +137,23 @@ declare class PreprToolbarElement extends HTMLElementBase {
137
137
  /** Idempotent, including across bundles that each try to define the element. */
138
138
  declare function definePreprToolbar(): void;
139
139
 
140
+ /** Which field the editor asked the preview to bring on screen. */
141
+ interface ScrollToFieldMessage {
142
+ field: string;
143
+ id?: string;
144
+ }
140
145
  interface IframeBridgeOptions {
141
146
  /**
142
147
  * Replace the `*.prepr.io` wildcard with an exact origin list. Intended for
143
148
  * self-hosted editors; when set, the wildcard no longer applies.
144
149
  */
145
150
  allowedEditorOrigins?: string[];
151
+ /**
152
+ * Called when the editor selects a field and wants the preview to scroll to
153
+ * it. Only fires for messages from the handshaked editor origin. The bridge
154
+ * stays free of DOM lookups: the preview runtime supplies `scrollToField`.
155
+ */
156
+ onScrollToField?: (message: ScrollToFieldMessage) => void;
146
157
  }
147
158
 
148
159
  /** Error thrown by the token helpers and the segments fetch. */
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-Wsfvw9G2.js';
2
- export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-Wsfvw9G2.js';
1
+ import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-e1fUWl2Y.js';
2
+ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-e1fUWl2Y.js';
3
3
 
4
4
  /**
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.4.2";
8
+ declare const VERSION = "0.5.0-rc.1";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
@@ -137,12 +137,23 @@ declare class PreprToolbarElement extends HTMLElementBase {
137
137
  /** Idempotent, including across bundles that each try to define the element. */
138
138
  declare function definePreprToolbar(): void;
139
139
 
140
+ /** Which field the editor asked the preview to bring on screen. */
141
+ interface ScrollToFieldMessage {
142
+ field: string;
143
+ id?: string;
144
+ }
140
145
  interface IframeBridgeOptions {
141
146
  /**
142
147
  * Replace the `*.prepr.io` wildcard with an exact origin list. Intended for
143
148
  * self-hosted editors; when set, the wildcard no longer applies.
144
149
  */
145
150
  allowedEditorOrigins?: string[];
151
+ /**
152
+ * Called when the editor selects a field and wants the preview to scroll to
153
+ * it. Only fires for messages from the handshaked editor origin. The bridge
154
+ * stays free of DOM lookups: the preview runtime supplies `scrollToField`.
155
+ */
156
+ onScrollToField?: (message: ScrollToFieldMessage) => void;
146
157
  }
147
158
 
148
159
  /** Error thrown by the token helpers and the segments fetch. */
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  setTrackingParam,
19
19
  stegaClean,
20
20
  trackEvent
21
- } from "./chunk-72BQJDDK.js";
21
+ } from "./chunk-4JNKYIEV.js";
22
22
 
23
23
  // src/core/server.ts
24
24
  var PreprError = class extends Error {
@@ -53,7 +53,7 @@ var PREPR_HEADER_KEYS = [
53
53
  "Prepr-Visitor-IP",
54
54
  "Prepr-Hubspot-Id",
55
55
  "Prepr-Customer-Id-Created",
56
- "Prepr-User-Agent",
56
+ "User-Agent",
57
57
  "Prepr-Package"
58
58
  ];
59
59
  function getPreprHeadersFromHeaders(headers) {
@@ -250,7 +250,7 @@ function processFrameworkRequest(request, opts, framework) {
250
250
  }
251
251
  const userAgent = request.headers.get("user-agent");
252
252
  if (userAgent) {
253
- requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
253
+ requestHeaders.set("User-Agent", sanitizeHeaderValue(userAgent));
254
254
  }
255
255
  const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
256
256
  if (framework) packageParts.push(`framework=${framework}`);
@@ -292,6 +292,7 @@ function createElementCache(query, ttl = 1e3) {
292
292
  }
293
293
 
294
294
  // src/core/iframe-bridge.ts
295
+ var debug = createScopedLogger("iframe-bridge");
295
296
  var EDITOR_BASE_DOMAIN = "prepr.io";
296
297
  function isAllowedEditorOrigin(origin, allowed) {
297
298
  if (allowed) return allowed.includes(origin);
@@ -309,6 +310,7 @@ function isAllowedEditorOrigin(origin, allowed) {
309
310
  }
310
311
  function createIframeBridge(store, options = {}) {
311
312
  const allowedOrigins = options.allowedEditorOrigins;
313
+ const onScrollToField = options.onScrollToField;
312
314
  let parentOrigin = null;
313
315
  const onKeyDown = (event) => {
314
316
  const key = event.key.toLowerCase();
@@ -332,6 +334,15 @@ function createIframeBridge(store, options = {}) {
332
334
  const currentScrollY = window.scrollY || document.documentElement.scrollTop;
333
335
  sendPreprEvent("getScrollPosition", { value: currentScrollY });
334
336
  }
337
+ if (data?.event === "prepr:scrollToField") {
338
+ if (typeof data.field !== "string" || !data.field) return;
339
+ if (data.id !== void 0 && typeof data.id !== "string") return;
340
+ try {
341
+ onScrollToField?.({ field: data.field, id: data.id });
342
+ } catch (error) {
343
+ debug.warn("scrollToField handler failed", error);
344
+ }
345
+ }
335
346
  };
336
347
  return {
337
348
  start() {
@@ -356,7 +367,7 @@ var import_stega2 = require("@vercel/stega");
356
367
 
357
368
  // src/core/stega/clean.ts
358
369
  var import_stega = require("@vercel/stega");
359
- var debug = createScopedLogger("stega:clean");
370
+ var debug2 = createScopedLogger("stega:clean");
360
371
  function decodeStega(str) {
361
372
  if (!str) return null;
362
373
  try {
@@ -365,7 +376,7 @@ function decodeStega(str) {
365
376
  return decoded;
366
377
  }
367
378
  } catch (error) {
368
- debug.log("error decoding stega data", error);
379
+ debug2.log("error decoding stega data", error);
369
380
  const match = str.match(/{"origin.*?}/);
370
381
  if (match) {
371
382
  try {
@@ -374,7 +385,7 @@ function decodeStega(str) {
374
385
  return decodedMatch;
375
386
  }
376
387
  } catch (innerError) {
377
- debug.log("error decoding stega regex match", innerError);
388
+ debug2.log("error decoding stega regex match", innerError);
378
389
  }
379
390
  }
380
391
  }
@@ -410,14 +421,37 @@ function isRenderedElement(element) {
410
421
  if (!style) return true;
411
422
  return style.visibility !== "hidden" && style.display !== "none";
412
423
  }
424
+ function parseEditHref(href) {
425
+ try {
426
+ const url = new URL(href, window.location.origin);
427
+ return {
428
+ id: url.pathname.split("/").pop() || void 0,
429
+ field: url.searchParams.get("field") || void 0,
430
+ locale: url.searchParams.get("locale") || void 0
431
+ };
432
+ } catch {
433
+ return {};
434
+ }
435
+ }
436
+ function setOrRemove(element, name, value) {
437
+ if (value) {
438
+ element.setAttribute(name, value);
439
+ } else {
440
+ element.removeAttribute(name);
441
+ }
442
+ }
413
443
  function tagEncodedElement(element, decoded) {
414
444
  element.setAttribute("data-prepr-encoded", "");
415
445
  element.setAttribute("data-prepr-href", decoded.href);
416
446
  element.setAttribute("data-prepr-origin", decoded.origin);
447
+ const { id, field, locale } = parseEditHref(decoded.href);
448
+ setOrRemove(element, "data-prepr-id", id);
449
+ setOrRemove(element, "data-prepr-field", field);
450
+ setOrRemove(element, "data-prepr-locale", locale);
417
451
  }
418
452
 
419
453
  // src/core/stega/auto-clean.ts
420
- var debug2 = createScopedLogger("stega:auto-clean");
454
+ var debug3 = createScopedLogger("stega:auto-clean");
421
455
  function createStegaAutoClean(options) {
422
456
  const stripText = options?.enabled ?? true;
423
457
  let observer = null;
@@ -460,7 +494,7 @@ function createStegaAutoClean(options) {
460
494
  }
461
495
  pendingHidden.add(textNode);
462
496
  } catch (error) {
463
- debug2.log("error cleaning text node", error);
497
+ debug3.log("error cleaning text node", error);
464
498
  }
465
499
  return false;
466
500
  }
@@ -546,7 +580,7 @@ function createStegaAutoClean(options) {
546
580
  if (observer || typeof window === "undefined") return;
547
581
  scanAndClean();
548
582
  setupObserver();
549
- debug2.log("stega auto-clean started");
583
+ debug3.log("stega auto-clean started");
550
584
  }
551
585
  function stop() {
552
586
  if (debounceTimeout) {
@@ -560,13 +594,13 @@ function createStegaAutoClean(options) {
560
594
  cleaned = /* @__PURE__ */ new WeakMap();
561
595
  pendingHidden = /* @__PURE__ */ new Set();
562
596
  pendingDirty = /* @__PURE__ */ new Set();
563
- debug2.log("stega auto-clean stopped");
597
+ debug3.log("stega auto-clean stopped");
564
598
  }
565
599
  return { start, stop };
566
600
  }
567
601
 
568
602
  // src/core/stega/elements.ts
569
- var debug3 = createScopedLogger("stega:elements");
603
+ var debug4 = createScopedLogger("stega:elements");
570
604
  var StegaElements = class {
571
605
  constructor(decode = decodeStega) {
572
606
  this.observer = null;
@@ -611,7 +645,7 @@ var StegaElements = class {
611
645
  walkTextNodes(document.body, (textNode) => {
612
646
  if (this.tagFromTextNode(textNode)) encodedCount++;
613
647
  });
614
- debug3.log("document scan complete, encoded", encodedCount, "elements");
648
+ debug4.log("document scan complete, encoded", encodedCount, "elements");
615
649
  this.elements = document.querySelectorAll("[data-prepr-encoded]");
616
650
  }
617
651
  /** `onUpdate` fires after each debounced batch, for refreshing derived state. */
@@ -667,6 +701,9 @@ var StegaElements = class {
667
701
  element.removeAttribute("data-prepr-encoded");
668
702
  element.removeAttribute("data-prepr-href");
669
703
  element.removeAttribute("data-prepr-origin");
704
+ element.removeAttribute("data-prepr-id");
705
+ element.removeAttribute("data-prepr-field");
706
+ element.removeAttribute("data-prepr-locale");
670
707
  element.classList.remove("prepr-overlay-active");
671
708
  });
672
709
  this.elements = void 0;
@@ -674,7 +711,7 @@ var StegaElements = class {
674
711
  };
675
712
 
676
713
  // src/core/stega/overlay.ts
677
- var debug4 = createScopedLogger("stega:overlay");
714
+ var debug5 = createScopedLogger("stega:overlay");
678
715
  var StegaOverlay = class {
679
716
  constructor(onEdit) {
680
717
  this.overlay = null;
@@ -719,7 +756,8 @@ var StegaOverlay = class {
719
756
  const origin = element.getAttribute("data-prepr-origin");
720
757
  const id = element.getAttribute("data-prepr-id") ?? void 0;
721
758
  const field = element.getAttribute("data-prepr-field") ?? void 0;
722
- debug4.log("showing overlay", { href, origin });
759
+ const locale = element.getAttribute("data-prepr-locale") ?? void 0;
760
+ debug5.log("showing overlay", { href, origin });
723
761
  const overlay = this.overlay;
724
762
  overlay.style.display = "block";
725
763
  overlay.style.top = `${rect.top + window.scrollY - 2}px`;
@@ -751,7 +789,7 @@ var StegaOverlay = class {
751
789
  tooltip.style.left = `${left}px`;
752
790
  });
753
791
  tooltip.onclick = () => {
754
- this.onEdit({ href, origin, id, field });
792
+ this.onEdit({ href, origin, id, field, locale });
755
793
  };
756
794
  }
757
795
  this.currentElement = element;
@@ -791,7 +829,7 @@ var StegaOverlay = class {
791
829
  };
792
830
 
793
831
  // src/core/stega/proximity.ts
794
- var debug5 = createScopedLogger("stega:proximity");
832
+ var debug6 = createScopedLogger("stega:proximity");
795
833
  var StegaProximity = class {
796
834
  constructor() {
797
835
  this.highlighted = /* @__PURE__ */ new Set();
@@ -826,9 +864,9 @@ var StegaProximity = class {
826
864
  );
827
865
  const nodes = this.getEncodedElements();
828
866
  nodes.forEach((el) => this.observer.observe(el));
829
- debug5.log("observing", nodes.length, "encoded elements");
867
+ debug6.log("observing", nodes.length, "encoded elements");
830
868
  } catch (error) {
831
- debug5.log("error setting up IntersectionObserver", error);
869
+ debug6.log("error setting up IntersectionObserver", error);
832
870
  }
833
871
  }
834
872
  stopObserving() {
@@ -898,7 +936,7 @@ function removeStegaStyles() {
898
936
  }
899
937
 
900
938
  // src/core/stega/scan.ts
901
- var debug6 = createScopedLogger("stega:scan");
939
+ var debug7 = createScopedLogger("stega:scan");
902
940
  var EDITOR_MODE_STYLES = "[data-prepr-encoded]{cursor:pointer}";
903
941
  function createStegaController(opts) {
904
942
  const tooltipEnabled = opts.tooltip ?? true;
@@ -931,12 +969,13 @@ function createStegaController(opts) {
931
969
  href: encoded.getAttribute("data-prepr-href") ?? "",
932
970
  origin: encoded.getAttribute("data-prepr-origin") ?? "",
933
971
  id: encoded.getAttribute("data-prepr-id") ?? void 0,
934
- field: encoded.getAttribute("data-prepr-field") ?? void 0
972
+ field: encoded.getAttribute("data-prepr-field") ?? void 0,
973
+ locale: encoded.getAttribute("data-prepr-locale") ?? void 0
935
974
  });
936
975
  };
937
976
  const start = () => {
938
977
  if (initialized) {
939
- debug6.log("already initialized, skipping setup");
978
+ debug7.log("already initialized, skipping setup");
940
979
  return;
941
980
  }
942
981
  if (!tooltipEnabled) {
@@ -946,7 +985,7 @@ function createStegaController(opts) {
946
985
  });
947
986
  document.addEventListener("click", handleClick, { capture: true });
948
987
  initialized = true;
949
- debug6.log("stega controller started (editor mode)");
988
+ debug7.log("stega controller started (editor mode)");
950
989
  return;
951
990
  }
952
991
  injectStegaStyles();
@@ -977,7 +1016,7 @@ function createStegaController(opts) {
977
1016
  passive: true
978
1017
  });
979
1018
  initialized = true;
980
- debug6.log("stega controller started");
1019
+ debug7.log("stega controller started");
981
1020
  };
982
1021
  const stop = () => {
983
1022
  if (!initialized) return;
@@ -986,7 +1025,7 @@ function createStegaController(opts) {
986
1025
  elements.cleanup();
987
1026
  removeStegaStyles();
988
1027
  initialized = false;
989
- debug6.log("stega controller stopped (editor mode)");
1028
+ debug7.log("stega controller stopped (editor mode)");
990
1029
  return;
991
1030
  }
992
1031
  if (throttledMouseMove) {
@@ -1006,11 +1045,43 @@ function createStegaController(opts) {
1006
1045
  elements.cleanup();
1007
1046
  removeStegaStyles();
1008
1047
  initialized = false;
1009
- debug6.log("stega controller stopped");
1048
+ debug7.log("stega controller stopped");
1010
1049
  };
1011
1050
  return { start, stop };
1012
1051
  }
1013
1052
 
1053
+ // src/core/stega/scroll-to-field.ts
1054
+ var debug8 = createScopedLogger("stega:scroll");
1055
+ var FLASH_DURATION_MS = 1200;
1056
+ var flashTimeout = null;
1057
+ function scrollToField(request) {
1058
+ const { field, id } = request;
1059
+ if (!field) return false;
1060
+ const candidates = document.querySelectorAll(
1061
+ "[data-prepr-encoded]"
1062
+ );
1063
+ let target = null;
1064
+ for (const candidate of candidates) {
1065
+ if (candidate.getAttribute("data-prepr-field") !== field) continue;
1066
+ if (id && candidate.getAttribute("data-prepr-id") !== id) continue;
1067
+ target = candidate;
1068
+ break;
1069
+ }
1070
+ if (!target) {
1071
+ debug8.log("no element found for field", field);
1072
+ return false;
1073
+ }
1074
+ target.scrollIntoView({ behavior: "smooth", block: "center" });
1075
+ if (flashTimeout) clearTimeout(flashTimeout);
1076
+ document.querySelectorAll(".prepr-overlay-active").forEach((el) => el.classList.remove("prepr-overlay-active"));
1077
+ target.classList.add("prepr-overlay-active");
1078
+ flashTimeout = setTimeout(() => {
1079
+ target.classList.remove("prepr-overlay-active");
1080
+ flashTimeout = null;
1081
+ }, FLASH_DURATION_MS);
1082
+ return true;
1083
+ }
1084
+
1014
1085
  // src/core/store.ts
1015
1086
  var DEFAULT_STATE = {
1016
1087
  locale: "en",
@@ -2123,7 +2194,7 @@ function definePreprToolbar() {
2123
2194
  }
2124
2195
 
2125
2196
  // src/core/create-preview.ts
2126
- var debug7 = createScopedLogger("create-preview");
2197
+ var debug9 = createScopedLogger("create-preview");
2127
2198
  var controllerStores = /* @__PURE__ */ new WeakMap();
2128
2199
  function defaultNavigation() {
2129
2200
  return {
@@ -2165,7 +2236,7 @@ function createPreprPreview(opts = {}) {
2165
2236
  const search = new URLSearchParams(window.location.search);
2166
2237
  const hideBar = search.get(PARAM_HIDE_BAR) === "true";
2167
2238
  if (hideBar) {
2168
- debug7.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
2239
+ debug9.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
2169
2240
  }
2170
2241
  const mountUi = (options?.ui ?? true) && !isIframe && !hideBar;
2171
2242
  const locale = resolveLocale(options);
@@ -2201,18 +2272,17 @@ function createPreprPreview(opts = {}) {
2201
2272
  tooltip: mountUi,
2202
2273
  // In the editor, ask the parent to focus the field instead of opening a new
2203
2274
  // tab. Standalone previews keep the window.open behaviour.
2204
- onEdit: ({ href, origin, id, field }) => {
2275
+ onEdit: ({ href, id, field, locale: contentLocale }) => {
2205
2276
  const safeHref = href ? safeEditUrl(href) : null;
2206
2277
  if (href && !safeHref) {
2207
- debug7.warn("ignored edit request with unsupported href scheme");
2278
+ debug9.warn("ignored edit request with unsupported href scheme");
2208
2279
  return;
2209
2280
  }
2210
2281
  if (isIframe) {
2211
2282
  sendPreprEvent("field_edit_requested", {
2212
- href: safeHref ?? void 0,
2213
- origin,
2214
2283
  id,
2215
- field
2284
+ field,
2285
+ locale: contentLocale
2216
2286
  });
2217
2287
  } else if (safeHref) {
2218
2288
  window.open(safeHref, "_blank", "noopener,noreferrer");
@@ -2239,7 +2309,15 @@ function createPreprPreview(opts = {}) {
2239
2309
  handleChange(before, state);
2240
2310
  });
2241
2311
  const bridge = createIframeBridge(store, {
2242
- allowedEditorOrigins: options?.allowedEditorOrigins
2312
+ allowedEditorOrigins: options?.allowedEditorOrigins,
2313
+ // The editor selecting a field scrolls the matching element into view. The
2314
+ // lookup relies on the attributes the stega scan writes, so it finds
2315
+ // nothing until encoded content has been tagged.
2316
+ onScrollToField: ({ field, id }) => {
2317
+ if (!scrollToField({ field, id })) {
2318
+ debug9.log("no element on this page renders field", field);
2319
+ }
2320
+ }
2243
2321
  });
2244
2322
  sendPreprEvent(
2245
2323
  "getScrollPosition",
@@ -2259,7 +2337,7 @@ function createPreprPreview(opts = {}) {
2259
2337
  bridge.stop();
2260
2338
  }
2261
2339
  el?.remove();
2262
- debug7.log("preview destroyed");
2340
+ debug9.log("preview destroyed");
2263
2341
  }
2264
2342
  const controller = { destroy };
2265
2343
  controllerStores.set(controller, store);
@@ -2270,7 +2348,7 @@ function createPreprPreview(opts = {}) {
2270
2348
  var import_react = require("react");
2271
2349
 
2272
2350
  // src/version.ts
2273
- var VERSION = "0.4.2";
2351
+ var VERSION = "0.5.0-rc.1";
2274
2352
 
2275
2353
  // src/core/pixel.ts
2276
2354
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -1,4 +1,4 @@
1
- import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-Wsfvw9G2.cjs';
1
+ import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-e1fUWl2Y.cjs';
2
2
 
3
3
  interface PreprTrackingPixelProps {
4
4
  /** Prepr tracking/access token. */
@@ -1,4 +1,4 @@
1
- import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-Wsfvw9G2.js';
1
+ import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-e1fUWl2Y.js';
2
2
 
3
3
  interface PreprTrackingPixelProps {
4
4
  /** Prepr tracking/access token. */
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  createPreprPreview,
4
4
  loadTrackingPixel
5
- } from "../chunk-72BQJDDK.js";
5
+ } from "../chunk-4JNKYIEV.js";
6
6
 
7
7
  // src/nextjs/components.ts
8
8
  import { usePathname, useRouter } from "next/navigation";
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(nextjs_exports);
38
38
  var import_server = require("next/server");
39
39
 
40
40
  // src/version.ts
41
- var VERSION = "0.4.2";
41
+ var VERSION = "0.5.0-rc.1";
42
42
 
43
43
  // src/core/constants.ts
44
44
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -133,7 +133,7 @@ function processFrameworkRequest(request, opts, framework) {
133
133
  }
134
134
  const userAgent = request.headers.get("user-agent");
135
135
  if (userAgent) {
136
- requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
136
+ requestHeaders.set("User-Agent", sanitizeHeaderValue(userAgent));
137
137
  }
138
138
  const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
139
139
  if (framework) packageParts.push(`framework=${framework}`);
@@ -298,7 +298,7 @@ var PREPR_HEADER_KEYS = [
298
298
  "Prepr-Visitor-IP",
299
299
  "Prepr-Hubspot-Id",
300
300
  "Prepr-Customer-Id-Created",
301
- "Prepr-User-Agent",
301
+ "User-Agent",
302
302
  "Prepr-Package"
303
303
  ];
304
304
  function getPreprHeadersFromHeaders(headers2) {
@@ -119,6 +119,9 @@ interface PreprHeaders {
119
119
  readonly 'Prepr-Visitor-IP'?: string;
120
120
  readonly 'Prepr-Hubspot-Id'?: string;
121
121
  readonly 'Prepr-Customer-Id-Created'?: 'true';
122
+ /** The visitor's browser User-Agent, used by the API for device detection. */
123
+ readonly 'User-Agent'?: string;
124
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
122
125
  readonly 'Prepr-User-Agent'?: string;
123
126
  readonly 'Prepr-Package'?: string;
124
127
  }
@@ -119,6 +119,9 @@ interface PreprHeaders {
119
119
  readonly 'Prepr-Visitor-IP'?: string;
120
120
  readonly 'Prepr-Hubspot-Id'?: string;
121
121
  readonly 'Prepr-Customer-Id-Created'?: 'true';
122
+ /** The visitor's browser User-Agent, used by the API for device detection. */
123
+ readonly 'User-Agent'?: string;
124
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
122
125
  readonly 'Prepr-User-Agent'?: string;
123
126
  readonly 'Prepr-Package'?: string;
124
127
  }
@@ -2,7 +2,7 @@
2
2
  import { NextResponse } from "next/server";
3
3
 
4
4
  // src/version.ts
5
- var VERSION = "0.4.2";
5
+ var VERSION = "0.5.0-rc.1";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -97,7 +97,7 @@ function processFrameworkRequest(request, opts, framework) {
97
97
  }
98
98
  const userAgent = request.headers.get("user-agent");
99
99
  if (userAgent) {
100
- requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
100
+ requestHeaders.set("User-Agent", sanitizeHeaderValue(userAgent));
101
101
  }
102
102
  const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
103
103
  if (framework) packageParts.push(`framework=${framework}`);
@@ -262,7 +262,7 @@ var PREPR_HEADER_KEYS = [
262
262
  "Prepr-Visitor-IP",
263
263
  "Prepr-Hubspot-Id",
264
264
  "Prepr-Customer-Id-Created",
265
- "Prepr-User-Agent",
265
+ "User-Agent",
266
266
  "Prepr-Package"
267
267
  ];
268
268
  function getPreprHeadersFromHeaders(headers2) {
@@ -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.4.2";
38
+ var VERSION = "0.5.0-rc.1";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -144,7 +144,7 @@ function processFrameworkRequest(request, opts, framework) {
144
144
  }
145
145
  const userAgent = request.headers.get("user-agent");
146
146
  if (userAgent) {
147
- requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
147
+ requestHeaders.set("User-Agent", sanitizeHeaderValue(userAgent));
148
148
  }
149
149
  const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
150
150
  if (framework) packageParts.push(`framework=${framework}`);
@@ -296,7 +296,7 @@ var PREPR_HEADER_KEYS = [
296
296
  "Prepr-Visitor-IP",
297
297
  "Prepr-Hubspot-Id",
298
298
  "Prepr-Customer-Id-Created",
299
- "Prepr-User-Agent",
299
+ "User-Agent",
300
300
  "Prepr-Package"
301
301
  ];
302
302
  function getPreprHeadersFromHeaders(headers) {
@@ -59,6 +59,9 @@ interface PreprHeaders {
59
59
  readonly 'Prepr-Visitor-IP'?: string;
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
+ /** The visitor's browser User-Agent, used by the API for device detection. */
63
+ readonly 'User-Agent'?: string;
64
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
62
65
  readonly 'Prepr-User-Agent'?: string;
63
66
  readonly 'Prepr-Package'?: string;
64
67
  }
@@ -59,6 +59,9 @@ interface PreprHeaders {
59
59
  readonly 'Prepr-Visitor-IP'?: string;
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
+ /** The visitor's browser User-Agent, used by the API for device detection. */
63
+ readonly 'User-Agent'?: string;
64
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
62
65
  readonly 'Prepr-User-Agent'?: string;
63
66
  readonly 'Prepr-Package'?: string;
64
67
  }
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.4.2";
2
+ var VERSION = "0.5.0-rc.1";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -108,7 +108,7 @@ function processFrameworkRequest(request, opts, framework) {
108
108
  }
109
109
  const userAgent = request.headers.get("user-agent");
110
110
  if (userAgent) {
111
- requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
111
+ requestHeaders.set("User-Agent", sanitizeHeaderValue(userAgent));
112
112
  }
113
113
  const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
114
114
  if (framework) packageParts.push(`framework=${framework}`);
@@ -260,7 +260,7 @@ var PREPR_HEADER_KEYS = [
260
260
  "Prepr-Visitor-IP",
261
261
  "Prepr-Hubspot-Id",
262
262
  "Prepr-Customer-Id-Created",
263
- "Prepr-User-Agent",
263
+ "User-Agent",
264
264
  "Prepr-Package"
265
265
  ];
266
266
  function getPreprHeadersFromHeaders(headers) {
@@ -108,7 +108,7 @@ interface PreprToolbarProps {
108
108
  interface PreprToolbarComponentProps extends PreprToolbarProps {
109
109
  options?: PreprPreviewOptions;
110
110
  }
111
- type PreprHeaderName = 'prepr-customer-id' | 'Prepr-Segments' | 'Prepr-ABtesting' | 'Prepr-User-Agent';
111
+ type PreprHeaderName = 'prepr-customer-id' | 'Prepr-Segments' | 'Prepr-ABtesting' | 'User-Agent' | 'Prepr-User-Agent';
112
112
  type PreprVariant = 'A' | 'B';
113
113
  type PreprEnvironment = 'preview' | 'production';
114
114
  type PreprEventType = 'segment_changed' | 'variant_changed' | 'edit_mode_toggled' | 'preview_mode_toggled' | 'getScrollPosition' | 'loaded' | 'field_edit_requested';
@@ -126,6 +126,9 @@ interface PreprHeaders {
126
126
  readonly 'Prepr-Visitor-IP'?: string;
127
127
  readonly 'Prepr-Hubspot-Id'?: string;
128
128
  readonly 'Prepr-Customer-Id-Created'?: 'true';
129
+ /** The visitor's browser User-Agent, used by the API for device detection. */
130
+ readonly 'User-Agent'?: string;
131
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
129
132
  readonly 'Prepr-User-Agent'?: string;
130
133
  readonly 'Prepr-Package'?: string;
131
134
  }