@preprio/toolkit 0.6.0-alpha.9 → 1.0.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.
Files changed (116) hide show
  1. package/README.md +111 -1363
  2. package/dist/astro/index.cjs +1555 -182
  3. package/dist/astro/index.d.cts +201 -1
  4. package/dist/astro/index.d.ts +201 -1
  5. package/dist/astro/index.js +1557 -29
  6. package/dist/{chunk-5QIWVDP2.js → chunk-33GWVTRJ.js} +1 -1
  7. package/dist/chunk-A2J7R4LR.js +256 -0
  8. package/dist/{chunk-WQBKQG4R.js → chunk-DSJ22P6J.js} +6 -1
  9. package/dist/chunk-KM2GME62.js +1255 -0
  10. package/dist/chunk-UTKH7DOI.js +58 -0
  11. package/dist/chunk-V7MCHPE7.js +85 -0
  12. package/dist/{chunk-J66UOCK6.js → chunk-WBMN4L7G.js} +1680 -579
  13. package/dist/chunk-Y7JWV7WV.js +374 -0
  14. package/dist/codegen/index.cjs +82 -0
  15. package/dist/codegen/index.d.cts +70 -0
  16. package/dist/codegen/index.d.ts +70 -0
  17. package/dist/codegen/index.js +64 -0
  18. package/dist/index.cjs +3729 -553
  19. package/dist/index.d.cts +403 -19
  20. package/dist/index.d.ts +403 -19
  21. package/dist/index.js +345 -24
  22. package/dist/live-preview-HCBNBC6C.js +19 -0
  23. package/dist/nextjs/components.cjs +1872 -754
  24. package/dist/nextjs/components.d.cts +5 -51
  25. package/dist/nextjs/components.d.ts +5 -51
  26. package/dist/nextjs/components.js +8 -299
  27. package/dist/nextjs/index.cjs +1228 -181
  28. package/dist/nextjs/index.d.cts +247 -92
  29. package/dist/nextjs/index.d.ts +247 -92
  30. package/dist/nextjs/index.js +1629 -111
  31. package/dist/nextjs/live-action.cjs +298 -0
  32. package/dist/nextjs/live-action.d.cts +12 -0
  33. package/dist/nextjs/live-action.d.ts +12 -0
  34. package/dist/nextjs/live-action.js +68 -0
  35. package/dist/nextjs/live.cjs +2010 -0
  36. package/dist/nextjs/live.d.cts +54 -0
  37. package/dist/nextjs/live.d.ts +54 -0
  38. package/dist/nextjs/live.js +287 -0
  39. package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
  40. package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
  41. package/dist/nuxt/index.cjs +15 -16
  42. package/dist/nuxt/index.d.cts +167 -6
  43. package/dist/nuxt/index.d.ts +167 -6
  44. package/dist/nuxt/index.js +402 -15
  45. package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
  46. package/dist/nuxt/live.cjs +1928 -0
  47. package/dist/nuxt/live.d.cts +45 -0
  48. package/dist/nuxt/live.d.ts +45 -0
  49. package/dist/nuxt/live.js +216 -0
  50. package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
  51. package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
  52. package/dist/react/components.cjs +1865 -480
  53. package/dist/react/components.d.cts +43 -8
  54. package/dist/react/components.d.ts +43 -8
  55. package/dist/react/components.js +1865 -480
  56. package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
  57. package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
  58. package/dist/sveltekit/index.cjs +15 -16
  59. package/dist/sveltekit/index.d.cts +111 -10
  60. package/dist/sveltekit/index.d.ts +111 -10
  61. package/dist/sveltekit/index.js +398 -15
  62. package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
  63. package/dist/sveltekit/live.cjs +1940 -0
  64. package/dist/sveltekit/live.d.cts +61 -0
  65. package/dist/sveltekit/live.d.ts +61 -0
  66. package/dist/sveltekit/live.js +220 -0
  67. package/package.json +132 -71
  68. package/src/astro/PreprToolbar.astro +7 -1
  69. package/src/astro/PreprTrackingPixel.astro +2 -4
  70. package/src/nuxt/PreprToolbar.vue +12 -1
  71. package/src/nuxt/PreprTrackingPixel.vue +2 -4
  72. package/src/sveltekit/PreprToolbar.svelte +17 -2
  73. package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
  74. package/dist/astro/chunk-UN4JADNU.js +0 -173
  75. package/dist/astro/graphql.cjs +0 -1078
  76. package/dist/astro/graphql.d.cts +0 -300
  77. package/dist/astro/graphql.d.ts +0 -300
  78. package/dist/astro/graphql.js +0 -984
  79. package/dist/astro/index-XT_z-RYT.d.cts +0 -130
  80. package/dist/astro/index-XT_z-RYT.d.ts +0 -130
  81. package/dist/chunk-3NCEVJJ3.js +0 -10
  82. package/dist/chunk-S5RWVMDJ.js +0 -148
  83. package/dist/chunk-XL4Y7FGW.js +0 -499
  84. package/dist/graphql/codegen.cjs +0 -557
  85. package/dist/graphql/codegen.d.cts +0 -23
  86. package/dist/graphql/codegen.d.ts +0 -23
  87. package/dist/graphql/codegen.js +0 -99
  88. package/dist/graphql.cjs +0 -1020
  89. package/dist/graphql.d.cts +0 -335
  90. package/dist/graphql.d.ts +0 -335
  91. package/dist/graphql.js +0 -448
  92. package/dist/nextjs/chunk-CMV6ZP6E.js +0 -549
  93. package/dist/nextjs/graphql.cjs +0 -1836
  94. package/dist/nextjs/graphql.d.cts +0 -498
  95. package/dist/nextjs/graphql.d.ts +0 -498
  96. package/dist/nextjs/graphql.js +0 -1422
  97. package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
  98. package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
  99. package/dist/nuxt/chunk-XWOABVMW.js +0 -417
  100. package/dist/nuxt/graphql.cjs +0 -1085
  101. package/dist/nuxt/graphql.d.cts +0 -297
  102. package/dist/nuxt/graphql.d.ts +0 -297
  103. package/dist/nuxt/graphql.js +0 -985
  104. package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
  105. package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
  106. package/dist/pixel-DwW7cXJm.d.cts +0 -49
  107. package/dist/pixel-DwW7cXJm.d.ts +0 -49
  108. package/dist/server-Brr1UgtW.d.ts +0 -59
  109. package/dist/server-DJuS3YU0.d.cts +0 -59
  110. package/dist/sveltekit/chunk-3S5RA6G5.js +0 -413
  111. package/dist/sveltekit/graphql.cjs +0 -1091
  112. package/dist/sveltekit/graphql.d.cts +0 -302
  113. package/dist/sveltekit/graphql.d.ts +0 -302
  114. package/dist/sveltekit/graphql.js +0 -991
  115. package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
  116. package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
@@ -1,130 +0,0 @@
1
- interface PreprSegment {
2
- readonly _id: string;
3
- readonly name: string;
4
- }
5
- /**
6
- * Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
7
- * form leaves room for per-feature options later without a breaking change.
8
- */
9
- type PreprFeatureConfig = boolean | {
10
- enabled?: boolean;
11
- };
12
- /** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
13
- interface PreprFeatures {
14
- /** Segment picker, `Prepr-Segments` header and its cookie/query param. */
15
- segments?: PreprFeatureConfig;
16
- /** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
17
- abTesting?: PreprFeatureConfig;
18
- /**
19
- * The site's own click-to-edit: the toolbar's Edit mode control, the stega
20
- * tooltip/overlay and the close-edit pill.
21
- *
22
- * NOT a security control, and NOT the Prepr editor's live preview. When the
23
- * site is framed by the editor, `prepr:initVE` still activates edit mode —
24
- * that is the CMS operating inside its own iframe, not an affordance offered
25
- * to visitors. See iframe-bridge.ts.
26
- */
27
- editMode?: PreprFeatureConfig;
28
- }
29
- interface PreprToolbarProps {
30
- /**
31
- * Server-resolved active segment. Optional: omit it with `segments`
32
- * disabled, where there is nothing to resolve. When enabled and omitted,
33
- * the persisted cookie is used.
34
- */
35
- readonly activeSegment?: string | null;
36
- /**
37
- * Server-resolved active A/B variant. Optional: omit it with `abTesting`
38
- * disabled, where there is nothing to resolve. When enabled and omitted,
39
- * the persisted cookie is used.
40
- */
41
- readonly activeVariant?: string | null;
42
- /** Available segments to personalize on. */
43
- readonly segments?: readonly PreprSegment[];
44
- /** @deprecated Alias for `segments`. */
45
- readonly data?: readonly PreprSegment[];
46
- }
47
- type PreprVariant = 'A' | 'B';
48
- interface PreprHeaders {
49
- readonly 'prepr-customer-id'?: string;
50
- readonly 'Prepr-Segments'?: string;
51
- readonly 'Prepr-ABtesting'?: PreprVariant;
52
- readonly 'Prepr-Preview-Bar'?: 'true';
53
- readonly 'Prepr-Context-utm_source'?: string;
54
- readonly 'Prepr-Context-utm_medium'?: string;
55
- readonly 'Prepr-Context-utm_term'?: string;
56
- readonly 'Prepr-Context-utm_content'?: string;
57
- readonly 'Prepr-Context-utm_campaign'?: string;
58
- readonly 'Prepr-Context-initial_referral'?: string;
59
- readonly 'Prepr-Visitor-IP'?: string;
60
- readonly 'Prepr-Hubspot-Id'?: string;
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`. */
65
- readonly 'Prepr-User-Agent'?: string;
66
- readonly 'Prepr-Package'?: string;
67
- }
68
- type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
69
-
70
- interface PreprMiddlewareOptions {
71
- /** Enable preview-mode headers (segment/AB overrides, preview bar). */
72
- preview?: boolean;
73
- /**
74
- * Disable features app-wide. Pass the same object you give the toolbar: a
75
- * disabled feature injects no header and persists no cookie, whatever the
76
- * request carries.
77
- */
78
- features?: PreprFeatures;
79
- /** Override the version reported in Prepr-Package (mainly for tests). */
80
- version?: string;
81
- }
82
-
83
- /**
84
- * Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
85
- * header. Use it when fetching with your own GraphQL client; the toolkit's
86
- * `createPreprClient` already returns it as `personalized`.
87
- *
88
- * Never throws; a response without `Vary` is not personalized.
89
- */
90
- declare function isPersonalizedResponse(source: Response | Headers): boolean;
91
-
92
- /**
93
- * Structural stand-in for Astro's `APIContext`, so this package needs no
94
- * build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
95
- */
96
- interface AstroLikeContext {
97
- request: Request;
98
- /** Unused; typed loosely so passing the real Astro context still checks. */
99
- cookies?: unknown;
100
- }
101
- /** Astro middleware's `next()` — resolves to the `Response` from downstream. */
102
- type AstroNext = () => Promise<Response>;
103
- /**
104
- * Astro middleware entry point: computes the Prepr headers/cookies for this
105
- * request, forwards the headers downstream and sets the cookies on the response.
106
- *
107
- * Astro hands downstream code the same `Request` instance this middleware receives, so the
108
- * headers are mutated in place — building a new `Request` would go nowhere,
109
- * there's no way to hand a replacement back out of middleware.
110
- */
111
- declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
112
- /** Prepr Customer ID for this request, from `Astro.request.headers`. */
113
- declare function getPreprUUID(headers: Headers): string | null;
114
- /** Active segment for this request, from `Astro.request.headers`. */
115
- declare function getActiveSegment(headers: Headers): string | null;
116
- /** Active A/B variant for this request, from `Astro.request.headers`. */
117
- declare function getActiveVariant(headers: Headers): string | null;
118
- /** All Prepr headers for this request, from `Astro.request.headers`. */
119
- declare function getPreprHeaders(headers: Headers): PreprHeaders;
120
- /**
121
- * Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
122
- * plus a Prepr GraphQL token.
123
- *
124
- * Ungated: call it only when your app is in preview mode. Resolve that however
125
- * your deployment already does — the toolkit reads no environment variables of
126
- * its own.
127
- */
128
- declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
129
-
130
- export { type AstroLikeContext as A, type PreprHeaders as P, type PreprErrorCode as a, type AstroNext as b, type PreprMiddlewareOptions as c, getActiveVariant as d, getPreprHeaders as e, getPreprUUID as f, getActiveSegment as g, getToolbarProps as h, isPersonalizedResponse as i, onPreprRequest as o };
@@ -1,130 +0,0 @@
1
- interface PreprSegment {
2
- readonly _id: string;
3
- readonly name: string;
4
- }
5
- /**
6
- * Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
7
- * form leaves room for per-feature options later without a breaking change.
8
- */
9
- type PreprFeatureConfig = boolean | {
10
- enabled?: boolean;
11
- };
12
- /** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
13
- interface PreprFeatures {
14
- /** Segment picker, `Prepr-Segments` header and its cookie/query param. */
15
- segments?: PreprFeatureConfig;
16
- /** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
17
- abTesting?: PreprFeatureConfig;
18
- /**
19
- * The site's own click-to-edit: the toolbar's Edit mode control, the stega
20
- * tooltip/overlay and the close-edit pill.
21
- *
22
- * NOT a security control, and NOT the Prepr editor's live preview. When the
23
- * site is framed by the editor, `prepr:initVE` still activates edit mode —
24
- * that is the CMS operating inside its own iframe, not an affordance offered
25
- * to visitors. See iframe-bridge.ts.
26
- */
27
- editMode?: PreprFeatureConfig;
28
- }
29
- interface PreprToolbarProps {
30
- /**
31
- * Server-resolved active segment. Optional: omit it with `segments`
32
- * disabled, where there is nothing to resolve. When enabled and omitted,
33
- * the persisted cookie is used.
34
- */
35
- readonly activeSegment?: string | null;
36
- /**
37
- * Server-resolved active A/B variant. Optional: omit it with `abTesting`
38
- * disabled, where there is nothing to resolve. When enabled and omitted,
39
- * the persisted cookie is used.
40
- */
41
- readonly activeVariant?: string | null;
42
- /** Available segments to personalize on. */
43
- readonly segments?: readonly PreprSegment[];
44
- /** @deprecated Alias for `segments`. */
45
- readonly data?: readonly PreprSegment[];
46
- }
47
- type PreprVariant = 'A' | 'B';
48
- interface PreprHeaders {
49
- readonly 'prepr-customer-id'?: string;
50
- readonly 'Prepr-Segments'?: string;
51
- readonly 'Prepr-ABtesting'?: PreprVariant;
52
- readonly 'Prepr-Preview-Bar'?: 'true';
53
- readonly 'Prepr-Context-utm_source'?: string;
54
- readonly 'Prepr-Context-utm_medium'?: string;
55
- readonly 'Prepr-Context-utm_term'?: string;
56
- readonly 'Prepr-Context-utm_content'?: string;
57
- readonly 'Prepr-Context-utm_campaign'?: string;
58
- readonly 'Prepr-Context-initial_referral'?: string;
59
- readonly 'Prepr-Visitor-IP'?: string;
60
- readonly 'Prepr-Hubspot-Id'?: string;
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`. */
65
- readonly 'Prepr-User-Agent'?: string;
66
- readonly 'Prepr-Package'?: string;
67
- }
68
- type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
69
-
70
- interface PreprMiddlewareOptions {
71
- /** Enable preview-mode headers (segment/AB overrides, preview bar). */
72
- preview?: boolean;
73
- /**
74
- * Disable features app-wide. Pass the same object you give the toolbar: a
75
- * disabled feature injects no header and persists no cookie, whatever the
76
- * request carries.
77
- */
78
- features?: PreprFeatures;
79
- /** Override the version reported in Prepr-Package (mainly for tests). */
80
- version?: string;
81
- }
82
-
83
- /**
84
- * Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
85
- * header. Use it when fetching with your own GraphQL client; the toolkit's
86
- * `createPreprClient` already returns it as `personalized`.
87
- *
88
- * Never throws; a response without `Vary` is not personalized.
89
- */
90
- declare function isPersonalizedResponse(source: Response | Headers): boolean;
91
-
92
- /**
93
- * Structural stand-in for Astro's `APIContext`, so this package needs no
94
- * build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
95
- */
96
- interface AstroLikeContext {
97
- request: Request;
98
- /** Unused; typed loosely so passing the real Astro context still checks. */
99
- cookies?: unknown;
100
- }
101
- /** Astro middleware's `next()` — resolves to the `Response` from downstream. */
102
- type AstroNext = () => Promise<Response>;
103
- /**
104
- * Astro middleware entry point: computes the Prepr headers/cookies for this
105
- * request, forwards the headers downstream and sets the cookies on the response.
106
- *
107
- * Astro hands downstream code the same `Request` instance this middleware receives, so the
108
- * headers are mutated in place — building a new `Request` would go nowhere,
109
- * there's no way to hand a replacement back out of middleware.
110
- */
111
- declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
112
- /** Prepr Customer ID for this request, from `Astro.request.headers`. */
113
- declare function getPreprUUID(headers: Headers): string | null;
114
- /** Active segment for this request, from `Astro.request.headers`. */
115
- declare function getActiveSegment(headers: Headers): string | null;
116
- /** Active A/B variant for this request, from `Astro.request.headers`. */
117
- declare function getActiveVariant(headers: Headers): string | null;
118
- /** All Prepr headers for this request, from `Astro.request.headers`. */
119
- declare function getPreprHeaders(headers: Headers): PreprHeaders;
120
- /**
121
- * Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
122
- * plus a Prepr GraphQL token.
123
- *
124
- * Ungated: call it only when your app is in preview mode. Resolve that however
125
- * your deployment already does — the toolkit reads no environment variables of
126
- * its own.
127
- */
128
- declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
129
-
130
- export { type AstroLikeContext as A, type PreprHeaders as P, type PreprErrorCode as a, type AstroNext as b, type PreprMiddlewareOptions as c, getActiveVariant as d, getPreprHeaders as e, getPreprUUID as f, getActiveSegment as g, getToolbarProps as h, isPersonalizedResponse as i, onPreprRequest as o };
@@ -1,10 +0,0 @@
1
- // src/core/personalization.ts
2
- var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
3
- function isPersonalizedResponse(source) {
4
- const headers = "headers" in source ? source.headers : source;
5
- return PERSONALIZED_VARY.test(headers.get("vary") ?? "");
6
- }
7
-
8
- export {
9
- isPersonalizedResponse
10
- };
@@ -1,148 +0,0 @@
1
- // src/core/stega/clean.ts
2
- import { vercelStegaClean, vercelStegaDecode } from "@vercel/stega";
3
-
4
- // src/core/utils.ts
5
- var trustedParentOrigin = null;
6
- function setTrustedParentOrigin(origin) {
7
- trustedParentOrigin = origin;
8
- }
9
- function sendPreprEvent(event, data, options) {
10
- if (typeof window !== "undefined") {
11
- const message = {
12
- name: "prepr_preview_bar",
13
- event,
14
- ...data
15
- };
16
- window.dispatchEvent(
17
- new CustomEvent("prepr_preview_bar", { detail: message })
18
- );
19
- if (window.parent && window.parent !== window) {
20
- if (trustedParentOrigin) {
21
- window.parent.postMessage(message, trustedParentOrigin);
22
- } else if (options?.allowUntrustedTarget) {
23
- window.parent.postMessage(message, "*");
24
- }
25
- }
26
- }
27
- }
28
- var DebugLogger = class {
29
- constructor(options) {
30
- this.options = {
31
- prefix: "[Prepr]",
32
- ...options
33
- };
34
- }
35
- // A local `enabled` wins; otherwise defer to the global logger so scoped
36
- // loggers created before initDebugLogger() still pick up the setting.
37
- isEnabled() {
38
- if (this.options.enabled !== void 0) {
39
- return this.options.enabled;
40
- }
41
- return globalDebugLogger?.options?.enabled ?? false;
42
- }
43
- log(message, ...args) {
44
- if (!this.isEnabled()) return;
45
- const prefix = this.options.prefix;
46
- console.log(`${prefix} ${message}`, ...args);
47
- }
48
- warn(message, ...args) {
49
- if (!this.isEnabled()) return;
50
- const prefix = this.options.prefix;
51
- console.warn(`${prefix} ${message}`, ...args);
52
- }
53
- error(message, ...args) {
54
- if (!this.isEnabled()) return;
55
- const prefix = this.options.prefix;
56
- console.error(`${prefix} ${message}`, ...args);
57
- }
58
- };
59
- var globalDebugLogger = null;
60
- function initDebugLogger(enabled = false) {
61
- globalDebugLogger = new DebugLogger({ enabled });
62
- }
63
- function createScopedLogger(scopeName) {
64
- return new DebugLogger({
65
- prefix: `[Prepr][${scopeName}]`
66
- });
67
- }
68
- function throttle(func, delay) {
69
- let timeoutId = null;
70
- let lastExecTime = 0;
71
- const throttledFunc = ((...args) => {
72
- const currentTime = Date.now();
73
- const timeSinceLastExec = currentTime - lastExecTime;
74
- if (timeSinceLastExec >= delay) {
75
- func(...args);
76
- lastExecTime = currentTime;
77
- } else {
78
- if (timeoutId) {
79
- clearTimeout(timeoutId);
80
- }
81
- timeoutId = setTimeout(() => {
82
- func(...args);
83
- lastExecTime = Date.now();
84
- timeoutId = null;
85
- }, delay - timeSinceLastExec);
86
- }
87
- });
88
- throttledFunc.cancel = () => {
89
- if (timeoutId) {
90
- clearTimeout(timeoutId);
91
- timeoutId = null;
92
- }
93
- };
94
- return throttledFunc;
95
- }
96
- function createElementCache(query, ttl = 1e3) {
97
- let cache = null;
98
- let lastCacheTime = 0;
99
- return () => {
100
- const now = Date.now();
101
- if (!cache || now - lastCacheTime > ttl) {
102
- cache = document.querySelectorAll(query);
103
- lastCacheTime = now;
104
- }
105
- return cache;
106
- };
107
- }
108
-
109
- // src/core/stega/clean.ts
110
- var debug = createScopedLogger("stega:clean");
111
- function stegaClean(text) {
112
- if (!text) return text;
113
- return vercelStegaClean(text);
114
- }
115
- function decodeStega(str) {
116
- if (!str) return null;
117
- try {
118
- const decoded = vercelStegaDecode(str);
119
- if (decoded?.href) {
120
- return decoded;
121
- }
122
- } catch (error) {
123
- debug.log("error decoding stega data", error);
124
- const match = str.match(/{"origin.*?}/);
125
- if (match) {
126
- try {
127
- const decodedMatch = vercelStegaDecode(match[0]);
128
- if (decodedMatch?.href) {
129
- return decodedMatch;
130
- }
131
- } catch (innerError) {
132
- debug.log("error decoding stega regex match", innerError);
133
- }
134
- }
135
- }
136
- return null;
137
- }
138
-
139
- export {
140
- setTrustedParentOrigin,
141
- sendPreprEvent,
142
- initDebugLogger,
143
- createScopedLogger,
144
- throttle,
145
- createElementCache,
146
- stegaClean,
147
- decodeStega
148
- };