@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.
- package/README.md +111 -1363
- package/dist/astro/index.cjs +1555 -182
- package/dist/astro/index.d.cts +201 -1
- package/dist/astro/index.d.ts +201 -1
- package/dist/astro/index.js +1557 -29
- package/dist/{chunk-5QIWVDP2.js → chunk-33GWVTRJ.js} +1 -1
- package/dist/chunk-A2J7R4LR.js +256 -0
- package/dist/{chunk-WQBKQG4R.js → chunk-DSJ22P6J.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- package/dist/{chunk-J66UOCK6.js → chunk-WBMN4L7G.js} +1680 -579
- package/dist/chunk-Y7JWV7WV.js +374 -0
- package/dist/codegen/index.cjs +82 -0
- package/dist/codegen/index.d.cts +70 -0
- package/dist/codegen/index.d.ts +70 -0
- package/dist/codegen/index.js +64 -0
- package/dist/index.cjs +3729 -553
- package/dist/index.d.cts +403 -19
- package/dist/index.d.ts +403 -19
- package/dist/index.js +345 -24
- package/dist/live-preview-HCBNBC6C.js +19 -0
- package/dist/nextjs/components.cjs +1872 -754
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -299
- package/dist/nextjs/index.cjs +1228 -181
- package/dist/nextjs/index.d.cts +247 -92
- package/dist/nextjs/index.d.ts +247 -92
- package/dist/nextjs/index.js +1629 -111
- package/dist/nextjs/live-action.cjs +298 -0
- package/dist/nextjs/live-action.d.cts +12 -0
- package/dist/nextjs/live-action.d.ts +12 -0
- package/dist/nextjs/live-action.js +68 -0
- package/dist/nextjs/live.cjs +2010 -0
- package/dist/nextjs/live.d.cts +54 -0
- package/dist/nextjs/live.d.ts +54 -0
- package/dist/nextjs/live.js +287 -0
- package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
- package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
- package/dist/nuxt/index.cjs +15 -16
- package/dist/nuxt/index.d.cts +167 -6
- package/dist/nuxt/index.d.ts +167 -6
- package/dist/nuxt/index.js +402 -15
- package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
- package/dist/nuxt/live.cjs +1928 -0
- package/dist/nuxt/live.d.cts +45 -0
- package/dist/nuxt/live.d.ts +45 -0
- package/dist/nuxt/live.js +216 -0
- package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
- package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
- package/dist/react/components.cjs +1865 -480
- package/dist/react/components.d.cts +43 -8
- package/dist/react/components.d.ts +43 -8
- package/dist/react/components.js +1865 -480
- package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
- package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
- package/dist/sveltekit/index.cjs +15 -16
- package/dist/sveltekit/index.d.cts +111 -10
- package/dist/sveltekit/index.d.ts +111 -10
- package/dist/sveltekit/index.js +398 -15
- package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
- package/dist/sveltekit/live.cjs +1940 -0
- package/dist/sveltekit/live.d.cts +61 -0
- package/dist/sveltekit/live.d.ts +61 -0
- package/dist/sveltekit/live.js +220 -0
- package/package.json +132 -71
- package/src/astro/PreprToolbar.astro +7 -1
- package/src/astro/PreprTrackingPixel.astro +2 -4
- package/src/nuxt/PreprToolbar.vue +12 -1
- package/src/nuxt/PreprTrackingPixel.vue +2 -4
- package/src/sveltekit/PreprToolbar.svelte +17 -2
- package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
- package/dist/astro/chunk-UN4JADNU.js +0 -173
- package/dist/astro/graphql.cjs +0 -1078
- package/dist/astro/graphql.d.cts +0 -300
- package/dist/astro/graphql.d.ts +0 -300
- package/dist/astro/graphql.js +0 -984
- package/dist/astro/index-XT_z-RYT.d.cts +0 -130
- package/dist/astro/index-XT_z-RYT.d.ts +0 -130
- package/dist/chunk-3NCEVJJ3.js +0 -10
- package/dist/chunk-S5RWVMDJ.js +0 -148
- package/dist/chunk-XL4Y7FGW.js +0 -499
- package/dist/graphql/codegen.cjs +0 -557
- package/dist/graphql/codegen.d.cts +0 -23
- package/dist/graphql/codegen.d.ts +0 -23
- package/dist/graphql/codegen.js +0 -99
- package/dist/graphql.cjs +0 -1020
- package/dist/graphql.d.cts +0 -335
- package/dist/graphql.d.ts +0 -335
- package/dist/graphql.js +0 -448
- package/dist/nextjs/chunk-CMV6ZP6E.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1836
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1422
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-XWOABVMW.js +0 -417
- package/dist/nuxt/graphql.cjs +0 -1085
- package/dist/nuxt/graphql.d.cts +0 -297
- package/dist/nuxt/graphql.d.ts +0 -297
- package/dist/nuxt/graphql.js +0 -985
- package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
- package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
- package/dist/pixel-DwW7cXJm.d.cts +0 -49
- package/dist/pixel-DwW7cXJm.d.ts +0 -49
- package/dist/server-Brr1UgtW.d.ts +0 -59
- package/dist/server-DJuS3YU0.d.cts +0 -59
- package/dist/sveltekit/chunk-3S5RA6G5.js +0 -413
- package/dist/sveltekit/graphql.cjs +0 -1091
- package/dist/sveltekit/graphql.d.cts +0 -302
- package/dist/sveltekit/graphql.d.ts +0 -302
- package/dist/sveltekit/graphql.js +0 -991
- package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
- package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { k as PreprToolbarComponentProps } from '../types-BYH9XqmN.cjs';
|
|
3
|
-
import { P as PreprPixelConfig } from '../pixel-DwW7cXJm.cjs';
|
|
1
|
+
import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-DqU7NvgW.cjs';
|
|
4
2
|
|
|
5
3
|
interface PreprTrackingPixelProps {
|
|
6
4
|
/** Prepr tracking/access token. */
|
|
@@ -10,9 +8,9 @@ interface PreprTrackingPixelProps {
|
|
|
10
8
|
/**
|
|
11
9
|
* Loads Prepr's CDN tracking pixel on mount. Renders nothing.
|
|
12
10
|
*
|
|
13
|
-
* The pixel
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* The pixel counts a view for the content item named by the page's
|
|
12
|
+
* `<meta property="prepr:id">` tag, and a new one when a client-side route
|
|
13
|
+
* change points that tag at another item.
|
|
16
14
|
*/
|
|
17
15
|
declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): null;
|
|
18
16
|
|
|
@@ -22,49 +20,5 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
|
|
|
22
20
|
* `createPreprPreview` mounts imperatively.
|
|
23
21
|
*/
|
|
24
22
|
declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
|
|
25
|
-
/**
|
|
26
|
-
* Gets each client-side navigation's decision in before the click: when the
|
|
27
|
-
* visitor hovers over a same-site link (or presses it, on touch devices), it
|
|
28
|
-
* asks `createPreprProxy` which variants they get on that page. Clicks are
|
|
29
|
-
* never held: the new page paints with those variants when the answer is in,
|
|
30
|
-
* and keeps its personalized sections hidden until then otherwise. Pages
|
|
31
|
-
* without personalization answer with no groups and are not asked again for
|
|
32
|
-
* an hour.
|
|
33
|
-
*
|
|
34
|
-
* Mount it once in the root layout, so links on pages without a
|
|
35
|
-
* `PreprStack` are covered too. Links to other sites and links that open a
|
|
36
|
-
* new tab or download are left alone.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* <PreprPersonalizationSwitch />
|
|
40
|
-
*/
|
|
41
|
-
declare function PreprPersonalizationSwitch(): null;
|
|
42
|
-
/**
|
|
43
|
-
* Applies this page view's decision to the variant wrappers of the
|
|
44
|
-
* `PreprStack` it is rendered by, before the page paints when the decision is
|
|
45
|
-
* already in: asked for on hover, or kept from an earlier view of the page.
|
|
46
|
-
* Back and Forward show the page as this tab last showed it. Any other view
|
|
47
|
-
* keeps its personalized sections hidden until the decision request answers.
|
|
48
|
-
* Rendered by `PreprStack`; you do not need it yourself.
|
|
49
|
-
*/
|
|
50
|
-
declare function PreprDecisionApplier(): null;
|
|
51
|
-
/**
|
|
52
|
-
* Wraps one rendered variant and, once hydrated, puts the variant keys on the
|
|
53
|
-
* elements inside, where Prepr's tracking pixel counts impressions and the
|
|
54
|
-
* clicks of any `data-prepr-variant-event` element in them. The wrapper itself
|
|
55
|
-
* takes no box (`display: contents`), and the pixel only counts an element it
|
|
56
|
-
* can see scroll into view, so the keys belong on the sections. The pixel
|
|
57
|
-
* watches for attributes added after load.
|
|
58
|
-
*
|
|
59
|
-
* A variant can hold several items, each with its own key. When the wrapper
|
|
60
|
-
* holds one element per key they are paired in order; otherwise only the
|
|
61
|
-
* first element is tagged, with the first key. An element that already
|
|
62
|
-
* carries a variant key is left alone. Rendered by `PreprStack` with
|
|
63
|
-
* `trackVariants`; you do not need it yourself.
|
|
64
|
-
*/
|
|
65
|
-
declare function PreprVariantTracking({ variantKeys, children, }: {
|
|
66
|
-
variantKeys: string[];
|
|
67
|
-
children?: ReactNode;
|
|
68
|
-
}): ReactElement;
|
|
69
23
|
|
|
70
|
-
export {
|
|
24
|
+
export { PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { k as PreprToolbarComponentProps } from '../types-BYH9XqmN.js';
|
|
3
|
-
import { P as PreprPixelConfig } from '../pixel-DwW7cXJm.js';
|
|
1
|
+
import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-DqU7NvgW.js';
|
|
4
2
|
|
|
5
3
|
interface PreprTrackingPixelProps {
|
|
6
4
|
/** Prepr tracking/access token. */
|
|
@@ -10,9 +8,9 @@ interface PreprTrackingPixelProps {
|
|
|
10
8
|
/**
|
|
11
9
|
* Loads Prepr's CDN tracking pixel on mount. Renders nothing.
|
|
12
10
|
*
|
|
13
|
-
* The pixel
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* The pixel counts a view for the content item named by the page's
|
|
12
|
+
* `<meta property="prepr:id">` tag, and a new one when a client-side route
|
|
13
|
+
* change points that tag at another item.
|
|
16
14
|
*/
|
|
17
15
|
declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): null;
|
|
18
16
|
|
|
@@ -22,49 +20,5 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
|
|
|
22
20
|
* `createPreprPreview` mounts imperatively.
|
|
23
21
|
*/
|
|
24
22
|
declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
|
|
25
|
-
/**
|
|
26
|
-
* Gets each client-side navigation's decision in before the click: when the
|
|
27
|
-
* visitor hovers over a same-site link (or presses it, on touch devices), it
|
|
28
|
-
* asks `createPreprProxy` which variants they get on that page. Clicks are
|
|
29
|
-
* never held: the new page paints with those variants when the answer is in,
|
|
30
|
-
* and keeps its personalized sections hidden until then otherwise. Pages
|
|
31
|
-
* without personalization answer with no groups and are not asked again for
|
|
32
|
-
* an hour.
|
|
33
|
-
*
|
|
34
|
-
* Mount it once in the root layout, so links on pages without a
|
|
35
|
-
* `PreprStack` are covered too. Links to other sites and links that open a
|
|
36
|
-
* new tab or download are left alone.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* <PreprPersonalizationSwitch />
|
|
40
|
-
*/
|
|
41
|
-
declare function PreprPersonalizationSwitch(): null;
|
|
42
|
-
/**
|
|
43
|
-
* Applies this page view's decision to the variant wrappers of the
|
|
44
|
-
* `PreprStack` it is rendered by, before the page paints when the decision is
|
|
45
|
-
* already in: asked for on hover, or kept from an earlier view of the page.
|
|
46
|
-
* Back and Forward show the page as this tab last showed it. Any other view
|
|
47
|
-
* keeps its personalized sections hidden until the decision request answers.
|
|
48
|
-
* Rendered by `PreprStack`; you do not need it yourself.
|
|
49
|
-
*/
|
|
50
|
-
declare function PreprDecisionApplier(): null;
|
|
51
|
-
/**
|
|
52
|
-
* Wraps one rendered variant and, once hydrated, puts the variant keys on the
|
|
53
|
-
* elements inside, where Prepr's tracking pixel counts impressions and the
|
|
54
|
-
* clicks of any `data-prepr-variant-event` element in them. The wrapper itself
|
|
55
|
-
* takes no box (`display: contents`), and the pixel only counts an element it
|
|
56
|
-
* can see scroll into view, so the keys belong on the sections. The pixel
|
|
57
|
-
* watches for attributes added after load.
|
|
58
|
-
*
|
|
59
|
-
* A variant can hold several items, each with its own key. When the wrapper
|
|
60
|
-
* holds one element per key they are paired in order; otherwise only the
|
|
61
|
-
* first element is tagged, with the first key. An element that already
|
|
62
|
-
* carries a variant key is left alone. Rendered by `PreprStack` with
|
|
63
|
-
* `trackVariants`; you do not need it yourself.
|
|
64
|
-
*/
|
|
65
|
-
declare function PreprVariantTracking({ variantKeys, children, }: {
|
|
66
|
-
variantKeys: string[];
|
|
67
|
-
children?: ReactNode;
|
|
68
|
-
}): ReactElement;
|
|
69
23
|
|
|
70
|
-
export {
|
|
24
|
+
export { PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps };
|
|
@@ -2,156 +2,15 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createPreprPreview,
|
|
4
4
|
loadTrackingPixel
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-WBMN4L7G.js";
|
|
6
|
+
import "../chunk-33GWVTRJ.js";
|
|
7
|
+
import "../chunk-Y7JWV7WV.js";
|
|
8
|
+
import "../chunk-UTKH7DOI.js";
|
|
9
|
+
import "../chunk-V7MCHPE7.js";
|
|
8
10
|
|
|
9
11
|
// src/nextjs/components.ts
|
|
10
12
|
import { usePathname, useRouter } from "next/navigation";
|
|
11
|
-
import {
|
|
12
|
-
createElement,
|
|
13
|
-
useEffect as useEffect2,
|
|
14
|
-
useLayoutEffect,
|
|
15
|
-
useRef
|
|
16
|
-
} from "react";
|
|
17
|
-
|
|
18
|
-
// src/react/hydration.ts
|
|
19
|
-
var PROPS_KEY_PREFIX = "__reactProps$";
|
|
20
|
-
function reactProps(element) {
|
|
21
|
-
for (const key of Object.keys(element)) {
|
|
22
|
-
if (key.startsWith(PROPS_KEY_PREFIX)) {
|
|
23
|
-
return element[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
function isReactHydrated(text) {
|
|
29
|
-
for (let el = text.parentElement; el; el = el.parentElement) {
|
|
30
|
-
const props = reactProps(el);
|
|
31
|
-
if (!props) continue;
|
|
32
|
-
return el === text.parentElement || props.dangerouslySetInnerHTML != null;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/nextjs/decision-switch.ts
|
|
38
|
-
function applyPreprDecisions(decision, options = {}) {
|
|
39
|
-
const state = window;
|
|
40
|
-
const key = location.pathname + location.search;
|
|
41
|
-
const previous = state.__preprDecision;
|
|
42
|
-
let value = decision;
|
|
43
|
-
if (value !== void 0 && value !== "*" && options.refresh && previous && previous.key === key && previous.value !== "*") {
|
|
44
|
-
const pairs = (from) => {
|
|
45
|
-
const out = {};
|
|
46
|
-
from.split("~").forEach((pair) => {
|
|
47
|
-
const colon = pair.indexOf(":");
|
|
48
|
-
if (colon > 0) out[pair.slice(0, colon)] = pair;
|
|
49
|
-
});
|
|
50
|
-
return out;
|
|
51
|
-
};
|
|
52
|
-
const before = pairs(previous.value);
|
|
53
|
-
const after = pairs(value);
|
|
54
|
-
document.querySelectorAll("[data-prepr-v][data-prepr-show]").forEach((element) => {
|
|
55
|
-
const range = document.createRange();
|
|
56
|
-
range.selectNodeContents(element);
|
|
57
|
-
if (range.getBoundingClientRect().top >= window.innerHeight) return;
|
|
58
|
-
(element.getAttribute("data-prepr-v") || "").split(" ").forEach((token) => {
|
|
59
|
-
const group = token.slice(0, token.indexOf(":"));
|
|
60
|
-
if (before[group]) after[group] = before[group];
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
value = Object.keys(after).map((group) => after[group]).join("~");
|
|
64
|
-
}
|
|
65
|
-
if (value !== void 0) state.__preprDecision = { key, value };
|
|
66
|
-
const current = state.__preprDecision;
|
|
67
|
-
if (!current || current.key !== key) return false;
|
|
68
|
-
document.querySelectorAll("[data-prepr-decision]").forEach((marker) => {
|
|
69
|
-
marker.setAttribute("data-prepr-decided", "");
|
|
70
|
-
});
|
|
71
|
-
const defaults = current.value === "*";
|
|
72
|
-
const chosen = {};
|
|
73
|
-
current.value.split("~").forEach((pair) => {
|
|
74
|
-
const colon = pair.indexOf(":");
|
|
75
|
-
if (colon > 0)
|
|
76
|
-
chosen[pair.slice(0, colon)] = pair.slice(colon + 1).split("|");
|
|
77
|
-
});
|
|
78
|
-
document.querySelectorAll("[data-prepr-v]").forEach((element) => {
|
|
79
|
-
const nested = element.hasAttribute("data-prepr-nested");
|
|
80
|
-
const show = defaults ? element.hasAttribute("data-prepr-default") : (element.getAttribute("data-prepr-v") || "").split(" ").every((token) => {
|
|
81
|
-
const colon = token.indexOf(":");
|
|
82
|
-
const variant = token.slice(colon + 1);
|
|
83
|
-
const variants = chosen[token.slice(0, colon)];
|
|
84
|
-
return !!variants && (nested ? variants[0] === variant : variants.indexOf(variant) >= 0);
|
|
85
|
-
});
|
|
86
|
-
if (show) element.setAttribute("data-prepr-show", "");
|
|
87
|
-
else element.removeAttribute("data-prepr-show");
|
|
88
|
-
});
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
function requestPreprDecision(key, options = {}) {
|
|
92
|
-
const fresh = 1e4;
|
|
93
|
-
const keep = 18e5;
|
|
94
|
-
const keepStatic = 36e5;
|
|
95
|
-
const state = window;
|
|
96
|
-
const asking = state.__preprAsking = state.__preprAsking || {};
|
|
97
|
-
const read = () => {
|
|
98
|
-
try {
|
|
99
|
-
const all = JSON.parse(sessionStorage.getItem("prepr_decisions") || "{}");
|
|
100
|
-
return all && typeof all === "object" ? all : {};
|
|
101
|
-
} catch {
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const ask = () => {
|
|
106
|
-
if (!asking[key]) {
|
|
107
|
-
asking[key] = fetch(key, {
|
|
108
|
-
headers: { "Prepr-Decide": "1" },
|
|
109
|
-
cache: "no-store",
|
|
110
|
-
credentials: "same-origin",
|
|
111
|
-
// The proxy gives up on Prepr after its own `timeoutMs`; this only
|
|
112
|
-
// covers a proxy that never answers.
|
|
113
|
-
signal: AbortSignal.timeout ? AbortSignal.timeout(6e3) : void 0
|
|
114
|
-
}).then((response) => response.ok ? response.text() : "*").catch(() => "*").then((answer) => {
|
|
115
|
-
delete asking[key];
|
|
116
|
-
try {
|
|
117
|
-
const all = read();
|
|
118
|
-
const at = Date.now();
|
|
119
|
-
Object.keys(all).forEach((stored) => {
|
|
120
|
-
const entry = all[stored];
|
|
121
|
-
if (!(entry && typeof entry.at === "number" && at - entry.at < keepStatic))
|
|
122
|
-
delete all[stored];
|
|
123
|
-
});
|
|
124
|
-
const kept = all[key];
|
|
125
|
-
if (answer !== "*" || !kept || kept.value === "*")
|
|
126
|
-
all[key] = { value: answer, at };
|
|
127
|
-
sessionStorage.setItem("prepr_decisions", JSON.stringify(all));
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
return answer;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return asking[key];
|
|
134
|
-
};
|
|
135
|
-
const last = read()[key];
|
|
136
|
-
const age = last && typeof last.at === "number" ? Date.now() - last.at : -1;
|
|
137
|
-
const value = last && typeof last.value === "string" ? last.value : null;
|
|
138
|
-
if (value !== null && !(value === "" && options.personalized) && age >= 0 && age < (value === "*" ? fresh : value === "" ? keepStatic : keep)) {
|
|
139
|
-
if (value !== "" && age >= fresh) {
|
|
140
|
-
ask().then((answer) => {
|
|
141
|
-
if (answer !== "*" && answer !== value && options.onChange)
|
|
142
|
-
options.onChange(answer);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return { result: value, value: Promise.resolve(value) };
|
|
146
|
-
}
|
|
147
|
-
const pending = {
|
|
148
|
-
value: ask()
|
|
149
|
-
};
|
|
150
|
-
pending.value.then((answer) => {
|
|
151
|
-
pending.result = answer;
|
|
152
|
-
});
|
|
153
|
-
return pending;
|
|
154
|
-
}
|
|
13
|
+
import { useEffect as useEffect2, useRef } from "react";
|
|
155
14
|
|
|
156
15
|
// src/react/components.ts
|
|
157
16
|
import { useEffect } from "react";
|
|
@@ -181,163 +40,13 @@ function PreprToolbar({
|
|
|
181
40
|
navigation: {
|
|
182
41
|
navigate: (url) => router.push(url),
|
|
183
42
|
currentPath: () => pathnameRef.current + window.location.search
|
|
184
|
-
}
|
|
185
|
-
isHydrated: isReactHydrated
|
|
43
|
+
}
|
|
186
44
|
});
|
|
187
45
|
return () => toolbar.destroy();
|
|
188
46
|
}, []);
|
|
189
47
|
return null;
|
|
190
48
|
}
|
|
191
|
-
var shown = /* @__PURE__ */ new Map();
|
|
192
|
-
var historyStep = false;
|
|
193
|
-
var onPopState = () => {
|
|
194
|
-
historyStep = true;
|
|
195
|
-
};
|
|
196
|
-
function requestDecision(key, personalized = false) {
|
|
197
|
-
return requestPreprDecision(key, {
|
|
198
|
-
personalized,
|
|
199
|
-
onChange: (value) => {
|
|
200
|
-
if (location.pathname + location.search !== key) return;
|
|
201
|
-
applyPreprDecisions(value, { refresh: true });
|
|
202
|
-
const state = window.__preprDecision;
|
|
203
|
-
if (state) shown.set(key, state.value);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function linkTarget(event) {
|
|
208
|
-
const anchor = event.target?.closest?.("a[href]");
|
|
209
|
-
if (!(anchor instanceof HTMLAnchorElement)) return null;
|
|
210
|
-
if (anchor.target && anchor.target !== "_self" || anchor.hasAttribute("download")) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
const url = new URL(anchor.href, location.href);
|
|
214
|
-
const key = url.pathname + url.search;
|
|
215
|
-
if (url.origin !== location.origin || key === location.pathname + location.search) {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
return key;
|
|
219
|
-
}
|
|
220
|
-
var HOVER_DELAY_MS = 65;
|
|
221
|
-
var hovering = null;
|
|
222
|
-
function onPointerOver(event) {
|
|
223
|
-
if (event.pointerType !== "mouse") return;
|
|
224
|
-
const key = linkTarget(event);
|
|
225
|
-
if (hovering?.key === key) return;
|
|
226
|
-
if (hovering) clearTimeout(hovering.timer);
|
|
227
|
-
hovering = key ? { key, timer: setTimeout(() => requestDecision(key), HOVER_DELAY_MS) } : null;
|
|
228
|
-
}
|
|
229
|
-
function onPointerDown(event) {
|
|
230
|
-
if (event.button !== 0) return;
|
|
231
|
-
const key = linkTarget(event);
|
|
232
|
-
if (key) requestDecision(key);
|
|
233
|
-
}
|
|
234
|
-
var listeners = 0;
|
|
235
|
-
function useDecisionRequests() {
|
|
236
|
-
useEffect2(() => {
|
|
237
|
-
if (listeners++ === 0) {
|
|
238
|
-
window.addEventListener("pointerover", onPointerOver, { passive: true });
|
|
239
|
-
window.addEventListener("pointerdown", onPointerDown, {
|
|
240
|
-
capture: true,
|
|
241
|
-
passive: true
|
|
242
|
-
});
|
|
243
|
-
window.addEventListener("popstate", onPopState);
|
|
244
|
-
}
|
|
245
|
-
return () => {
|
|
246
|
-
if (--listeners === 0) {
|
|
247
|
-
window.removeEventListener("pointerover", onPointerOver);
|
|
248
|
-
window.removeEventListener("pointerdown", onPointerDown, true);
|
|
249
|
-
window.removeEventListener("popstate", onPopState);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}, []);
|
|
253
|
-
}
|
|
254
|
-
function PreprPersonalizationSwitch() {
|
|
255
|
-
useDecisionRequests();
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
function PreprDecisionApplier() {
|
|
259
|
-
useDecisionRequests();
|
|
260
|
-
useLayoutEffect(() => {
|
|
261
|
-
const key = location.pathname + location.search;
|
|
262
|
-
const remember = () => {
|
|
263
|
-
const state = window.__preprDecision;
|
|
264
|
-
if (state) shown.set(key, state.value);
|
|
265
|
-
};
|
|
266
|
-
const previous = historyStep ? shown.get(key) : void 0;
|
|
267
|
-
historyStep = false;
|
|
268
|
-
if (applyPreprDecisions(previous)) {
|
|
269
|
-
remember();
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const pending = requestDecision(key, true);
|
|
273
|
-
if (pending.result !== void 0) {
|
|
274
|
-
applyPreprDecisions(pending.result);
|
|
275
|
-
remember();
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
let live = true;
|
|
279
|
-
void pending.value.then((value) => {
|
|
280
|
-
if (live && location.pathname + location.search === key) {
|
|
281
|
-
applyPreprDecisions(value);
|
|
282
|
-
remember();
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
return () => {
|
|
286
|
-
live = false;
|
|
287
|
-
};
|
|
288
|
-
});
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
var VARIANT_KEY_ATTRIBUTE = "data-prepr-variant-key";
|
|
292
|
-
function PreprVariantTracking({
|
|
293
|
-
variantKeys,
|
|
294
|
-
children
|
|
295
|
-
}) {
|
|
296
|
-
const ref = useRef(null);
|
|
297
|
-
const keys = variantKeys.join(" ");
|
|
298
|
-
useLayoutEffect(() => {
|
|
299
|
-
let tagged = [];
|
|
300
|
-
const wrapper = ref.current?.closest("[data-prepr-v]");
|
|
301
|
-
const shown2 = () => !wrapper || wrapper.hasAttribute("data-prepr-show");
|
|
302
|
-
const untag = () => {
|
|
303
|
-
for (const [element] of tagged)
|
|
304
|
-
element.removeAttribute(VARIANT_KEY_ATTRIBUTE);
|
|
305
|
-
tagged = [];
|
|
306
|
-
};
|
|
307
|
-
const tag = () => {
|
|
308
|
-
if (!shown2()) return untag();
|
|
309
|
-
if (tagged.length > 0) return;
|
|
310
|
-
const elements = [...ref.current?.children ?? []];
|
|
311
|
-
const list = keys.split(" ");
|
|
312
|
-
const pairs = elements.length === list.length ? elements.map((element, i) => [element, list[i]]) : elements.slice(0, 1).map((element) => [element, list[0]]);
|
|
313
|
-
tagged = pairs.filter(([element, key]) => {
|
|
314
|
-
if (element.hasAttribute(VARIANT_KEY_ATTRIBUTE)) return false;
|
|
315
|
-
element.setAttribute(VARIANT_KEY_ATTRIBUTE, key);
|
|
316
|
-
return true;
|
|
317
|
-
});
|
|
318
|
-
};
|
|
319
|
-
const timer = setTimeout(tag);
|
|
320
|
-
const observer = wrapper && new MutationObserver(tag);
|
|
321
|
-
observer?.observe(wrapper, {
|
|
322
|
-
attributes: true,
|
|
323
|
-
attributeFilter: ["data-prepr-show"]
|
|
324
|
-
});
|
|
325
|
-
return () => {
|
|
326
|
-
clearTimeout(timer);
|
|
327
|
-
observer?.disconnect();
|
|
328
|
-
untag();
|
|
329
|
-
};
|
|
330
|
-
}, [keys]);
|
|
331
|
-
return createElement(
|
|
332
|
-
"div",
|
|
333
|
-
{ ref, style: { display: "contents" } },
|
|
334
|
-
children
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
49
|
export {
|
|
338
|
-
PreprDecisionApplier,
|
|
339
|
-
PreprPersonalizationSwitch,
|
|
340
50
|
PreprToolbar,
|
|
341
|
-
PreprTrackingPixel
|
|
342
|
-
PreprVariantTracking
|
|
51
|
+
PreprTrackingPixel
|
|
343
52
|
};
|