@plitzi/sdk-shared 0.39.12 → 0.39.14
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/CHANGELOG.md +14 -0
- package/dist/audiences/audiences.d.ts +18 -4
- package/dist/audiences/audiences.mjs +30 -21
- package/dist/audiences/index.mjs +1 -1
- package/dist/authoring/elementCallbacks.d.ts +22 -0
- package/dist/authoring/elementCallbacks.mjs +20 -5
- package/dist/authoring/index.mjs +4 -4
- package/dist/dataSource/globalSources.d.ts +6 -2
- package/dist/dataSource/globalSources.mjs +5 -0
- package/dist/helpers/index.mjs +24 -23
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +28 -27
- package/dist/helpers/twigWrapper/filters/catalog/index.mjs +1 -1
- package/dist/helpers/twigWrapper/filters/dates.mjs +6 -6
- package/dist/helpers/twigWrapper/filters/filters.mjs +3 -3
- package/dist/helpers/twigWrapper/filters/index.mjs +4 -4
- package/dist/helpers/twigWrapper/filters/types.d.ts +16 -1
- package/dist/helpers/twigWrapper/filters/types.mjs +11 -2
- package/dist/helpers/twigWrapper/index.d.ts +2 -1
- package/dist/helpers/twigWrapper/index.mjs +4 -3
- package/dist/helpers/twigWrapper/templateRoots.mjs +19 -18
- package/dist/store/storeHooks.d.ts +33 -33
- package/dist/style/styleStates.d.ts +7 -2
- package/dist/style/styleStates.mjs +2 -2
- package/dist/timeWindows/clock.d.ts +11 -0
- package/dist/timeWindows/clock.mjs +6 -0
- package/dist/timeWindows/countdown.d.ts +31 -0
- package/dist/timeWindows/countdown.mjs +57 -0
- package/dist/timeWindows/index.d.ts +2 -0
- package/dist/timeWindows/index.mjs +4 -1
- package/dist/timeWindows/timeWindows.d.ts +0 -3
- package/dist/timeWindows/timeWindows.mjs +2 -2
- package/dist/types/CommonTypes.d.ts +5 -0
- package/dist/types/StoreTypes.d.ts +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @plitzi/sdk-shared
|
|
2
2
|
|
|
3
|
+
## 0.39.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f1922cf: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
|
|
10
|
+
## 0.39.13
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 919736b: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
15
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
16
|
+
|
|
3
17
|
## 0.39.12
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -3,14 +3,16 @@ import { Schema } from '../types';
|
|
|
3
3
|
export type VisitorDevice = 'mobile' | 'tablet' | 'desktop';
|
|
4
4
|
/**
|
|
5
5
|
* What an audience's rules know of the visitor beyond what a flag's do, read as `visitor.<fact>`: whether they came
|
|
6
|
-
* before, the language their browser asks for first (its primary subtag: `es`, `en`)
|
|
6
|
+
* before, the language their browser asks for first (its primary subtag: `es`, `en`), the kind of device, and the
|
|
7
|
+
* country they are in (ISO 3166-1 alpha-2: `ES`, `MX`) — empty where nothing in front of the server says it.
|
|
7
8
|
*/
|
|
8
9
|
export type VisitorFacts = {
|
|
9
10
|
returning: boolean;
|
|
10
11
|
language: string;
|
|
11
12
|
device: VisitorDevice;
|
|
13
|
+
country: string;
|
|
12
14
|
};
|
|
13
|
-
export declare const VISITOR_FACTS: readonly ["returning", "language", "device"];
|
|
15
|
+
export declare const VISITOR_FACTS: readonly ["returning", "language", "device", "country"];
|
|
14
16
|
export type VisitorFact = (typeof VISITOR_FACTS)[number];
|
|
15
17
|
/** What an audience's rules are matched against: what a flag's are, and the visitor's facts. */
|
|
16
18
|
export type AudienceScope = FlagScope & {
|
|
@@ -23,6 +25,17 @@ export type AudienceScope = FlagScope & {
|
|
|
23
25
|
export declare const deviceFromUserAgent: (userAgent: string | undefined, mobileHint?: string) => VisitorDevice;
|
|
24
26
|
/** The language a browser asks for first, by its primary subtag — `es` for `es-AR,es;q=0.9,en;q=0.8` — or none. */
|
|
25
27
|
export declare const languageFrom: (preferred: string | undefined) => string;
|
|
28
|
+
/**
|
|
29
|
+
* The headers a CDN in front of the server says the visitor's country in, the first one present winning: Cloudflare's,
|
|
30
|
+
* CloudFront's, Vercel's. A server with none in front gets none — and any visitor could send one, so a country is for
|
|
31
|
+
* what a page shows, never for who may see it.
|
|
32
|
+
*/
|
|
33
|
+
export declare const COUNTRY_HEADERS: readonly ["cf-ipcountry", "cloudfront-viewer-country", "x-vercel-ip-country"];
|
|
34
|
+
/**
|
|
35
|
+
* A country as an edge says it, as rules compare it: two letters, upper case — `ES` for `es` — or none for what is no
|
|
36
|
+
* country (`XX`, unknown, and `T1`, Tor, as Cloudflare says them).
|
|
37
|
+
*/
|
|
38
|
+
export declare const countryFrom: (value: string | undefined) => string;
|
|
26
39
|
/**
|
|
27
40
|
* The cookie that says when a visitor was first seen, in seconds since the epoch (UTC): what makes them returning. Named
|
|
28
41
|
* with the port, as the others a page keeps for its visitor are.
|
|
@@ -38,13 +51,14 @@ export declare const isReturning: (firstSeen: number | undefined, now: number) =
|
|
|
38
51
|
export declare const seenCookie: (host: string | undefined, now: number, { secure }: {
|
|
39
52
|
secure: boolean;
|
|
40
53
|
}) => string;
|
|
41
|
-
/** A visitor's facts, as a request says them: its cookies, its agent and its
|
|
42
|
-
export declare const visitorFactsOf: ({ cookies, host, userAgent, mobileHint, acceptLanguage, now }: {
|
|
54
|
+
/** A visitor's facts, as a request says them: its cookies, its agent, its languages and the country its edge said. */
|
|
55
|
+
export declare const visitorFactsOf: ({ cookies, host, userAgent, mobileHint, acceptLanguage, country, now }: {
|
|
43
56
|
cookies: string | undefined;
|
|
44
57
|
host: string | undefined;
|
|
45
58
|
userAgent: string | undefined;
|
|
46
59
|
mobileHint?: string;
|
|
47
60
|
acceptLanguage: string | undefined;
|
|
61
|
+
country?: string;
|
|
48
62
|
now: number;
|
|
49
63
|
}) => VisitorFacts;
|
|
50
64
|
/**
|
|
@@ -7,48 +7,57 @@ import { chooseByOf as i, variantItemsOf as a, variantsElementsOf as o } from ".
|
|
|
7
7
|
var s = [
|
|
8
8
|
"returning",
|
|
9
9
|
"language",
|
|
10
|
-
"device"
|
|
10
|
+
"device",
|
|
11
|
+
"country"
|
|
11
12
|
], c = (e, t) => {
|
|
12
13
|
if (t === "?1") return "mobile";
|
|
13
14
|
let n = e ?? "";
|
|
14
15
|
return /iPad|Tablet|PlayBook|Silk|Android(?!.*Mobile)/i.test(n) ? "tablet" : /Mobi|iPhone|iPod|Android|Windows Phone/i.test(n) ? "mobile" : "desktop";
|
|
15
|
-
}, l = (e) => (e ?? "").split(",")[0]?.split(";")[0]?.split("-")[0]?.trim().toLowerCase() ?? "", u =
|
|
16
|
+
}, l = (e) => (e ?? "").split(",")[0]?.split(";")[0]?.split("-")[0]?.trim().toLowerCase() ?? "", u = [
|
|
17
|
+
"cf-ipcountry",
|
|
18
|
+
"cloudfront-viewer-country",
|
|
19
|
+
"x-vercel-ip-country"
|
|
20
|
+
], d = (e) => {
|
|
21
|
+
let t = (e ?? "").trim().toUpperCase();
|
|
22
|
+
return /^[A-Z]{2}$/.test(t) && t !== "XX" ? t : "";
|
|
23
|
+
}, f = (e) => {
|
|
16
24
|
let t = e?.split(":")[1];
|
|
17
25
|
return t ? `plitzi_seen_${t}` : "plitzi_seen";
|
|
18
|
-
},
|
|
19
|
-
let r = Number(n(e,
|
|
26
|
+
}, p = 1800, m = 31536e3, h = (e, t) => {
|
|
27
|
+
let r = Number(n(e, f(t)));
|
|
20
28
|
return Number.isInteger(r) && r > 0 ? r : void 0;
|
|
21
|
-
},
|
|
22
|
-
`${
|
|
29
|
+
}, g = (e, t) => e !== void 0 && t / 1e3 - e > 1800, _ = (e, t, { secure: n }) => [
|
|
30
|
+
`${f(e)}=${String(Math.floor(t / 1e3))}`,
|
|
23
31
|
"Path=/",
|
|
24
|
-
`Max-Age=${String(
|
|
32
|
+
`Max-Age=${String(m)}`,
|
|
25
33
|
"SameSite=Lax",
|
|
26
34
|
...n ? ["Secure"] : []
|
|
27
|
-
].join("; "),
|
|
28
|
-
returning:
|
|
35
|
+
].join("; "), v = ({ cookies: e, host: t, userAgent: n, mobileHint: r, acceptLanguage: i, country: a, now: o }) => ({
|
|
36
|
+
returning: g(h(e, t), o),
|
|
29
37
|
language: l(i),
|
|
30
|
-
device: c(n, r)
|
|
31
|
-
|
|
38
|
+
device: c(n, r),
|
|
39
|
+
country: d(a)
|
|
40
|
+
}), y = (e, t) => {
|
|
32
41
|
if (!r(e)) return;
|
|
33
42
|
let { field: n, rules: i } = e;
|
|
34
43
|
if (typeof n == "string" && n.startsWith("visitor.")) {
|
|
35
44
|
let e = s.find((e) => `visitor.${e}` === n);
|
|
36
45
|
e && t.add(e);
|
|
37
46
|
}
|
|
38
|
-
Array.isArray(i) && i.forEach((e) =>
|
|
39
|
-
},
|
|
47
|
+
Array.isArray(i) && i.forEach((e) => y(e, t));
|
|
48
|
+
}, b = (e) => o(e).filter(({ element: e }) => i(e.attributes) === "rules").flatMap(({ element: e, flat: t }) => a(e, t)), x = (e) => {
|
|
40
49
|
let t = /* @__PURE__ */ new Set();
|
|
41
|
-
for (let n of
|
|
50
|
+
for (let n of b(e)) y(n.attributes.when, t);
|
|
42
51
|
return s.filter((e) => t.has(e));
|
|
43
|
-
},
|
|
44
|
-
if (!
|
|
52
|
+
}, S = (e, t) => t.map((t) => `${t}=${String(e[t])}`).join(";"), C = (n, r) => n.findIndex((n) => !e(n) || t(n, r)), w, T = () => {
|
|
53
|
+
if (!w) {
|
|
45
54
|
let e;
|
|
46
55
|
try {
|
|
47
56
|
e = document.cookie;
|
|
48
57
|
} catch {
|
|
49
58
|
e = void 0;
|
|
50
59
|
}
|
|
51
|
-
|
|
60
|
+
w = v({
|
|
52
61
|
cookies: e,
|
|
53
62
|
host: window.location.host,
|
|
54
63
|
userAgent: navigator.userAgent,
|
|
@@ -56,11 +65,11 @@ var s = [
|
|
|
56
65
|
now: Date.now()
|
|
57
66
|
});
|
|
58
67
|
}
|
|
59
|
-
return
|
|
60
|
-
},
|
|
68
|
+
return w;
|
|
69
|
+
}, E = () => {
|
|
61
70
|
try {
|
|
62
71
|
let e = window.location.host;
|
|
63
|
-
|
|
72
|
+
h(document.cookie, e) === void 0 && (document.cookie = _(e, Date.now(), { secure: window.location.protocol === "https:" }));
|
|
64
73
|
} catch {}
|
|
65
74
|
};
|
|
66
|
-
export { s as VISITOR_FACTS,
|
|
75
|
+
export { u as COUNTRY_HEADERS, s as VISITOR_FACTS, p as VISIT_LENGTH_S, x as audienceFactsUsed, S as audienceKeyOf, T as browserVisitorFacts, C as chooseAudienceVariant, d as countryFrom, c as deviceFromUserAgent, h as firstSeenOf, g as isReturning, E as keepFirstSeen, l as languageFrom, _ as seenCookie, f as seenCookieName, v as visitorFactsOf };
|
package/dist/audiences/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { VISITOR_FACTS, VISIT_LENGTH_S, audienceFactsUsed, audienceKeyOf, browserVisitorFacts, chooseAudienceVariant, deviceFromUserAgent, firstSeenOf, isReturning, keepFirstSeen, languageFrom, seenCookie, seenCookieName, visitorFactsOf } from "./audiences.mjs";
|
|
1
|
+
export { COUNTRY_HEADERS, VISITOR_FACTS, VISIT_LENGTH_S, audienceFactsUsed, audienceKeyOf, browserVisitorFacts, chooseAudienceVariant, countryFrom, deviceFromUserAgent, firstSeenOf, isReturning, keepFirstSeen, languageFrom, seenCookie, seenCookieName, visitorFactsOf } from "./audiences.mjs";
|
|
@@ -77,6 +77,28 @@ export declare const FOCUS_CALLBACKS: {
|
|
|
77
77
|
params: {};
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
+
/** How a `fullscreen` step moves: in or out as it is (`toggle`), or one way. */
|
|
81
|
+
export declare const FULLSCREEN_MODES: readonly ["toggle", "enter", "exit"];
|
|
82
|
+
export type FullscreenMode = (typeof FULLSCREEN_MODES)[number];
|
|
83
|
+
/**
|
|
84
|
+
* An element shown on the whole screen — a map, a board, a gallery, a video — and back. Its node names the element; a
|
|
85
|
+
* browser that cannot (an iPhone shows only a video so) fails the step, and the flow's `onFailure` says so.
|
|
86
|
+
*/
|
|
87
|
+
export declare const FULLSCREEN_CALLBACKS: {
|
|
88
|
+
fullscreen: {
|
|
89
|
+
title: string;
|
|
90
|
+
type: "callback";
|
|
91
|
+
strictParams: true;
|
|
92
|
+
params: {
|
|
93
|
+
mode: {
|
|
94
|
+
type: "select";
|
|
95
|
+
description: string;
|
|
96
|
+
default: string;
|
|
97
|
+
options: ("enter" | "toggle" | "exit")[];
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
80
102
|
/** The callbacks every element answers — `setState`, `scrollTo`, `scrollIntoView`, `focus`… — each with its params, as a flow's step calls them. */
|
|
81
103
|
export declare const BUILTIN_ELEMENT_CALLBACKS: Record<string, BuiltinElementCallback>;
|
|
82
104
|
/** The built-in element callback for an action, or undefined when the action is not a known built-in (an
|
|
@@ -68,7 +68,21 @@ var r = {
|
|
|
68
68
|
type: "callback",
|
|
69
69
|
strictParams: !0,
|
|
70
70
|
params: {}
|
|
71
|
-
} }, o =
|
|
71
|
+
} }, o = [
|
|
72
|
+
"toggle",
|
|
73
|
+
"enter",
|
|
74
|
+
"exit"
|
|
75
|
+
], s = { fullscreen: {
|
|
76
|
+
title: "Fullscreen",
|
|
77
|
+
type: "callback",
|
|
78
|
+
strictParams: !0,
|
|
79
|
+
params: { mode: {
|
|
80
|
+
type: "select",
|
|
81
|
+
description: "\"toggle\" shows it on the whole screen or, when it is already, back; \"enter\" and \"exit\" one way.",
|
|
82
|
+
default: "toggle",
|
|
83
|
+
options: [...o]
|
|
84
|
+
} }
|
|
85
|
+
} }, c = {
|
|
72
86
|
setState: {
|
|
73
87
|
title: "Update Element (set attribute / state)",
|
|
74
88
|
type: "callback",
|
|
@@ -126,9 +140,10 @@ var r = {
|
|
|
126
140
|
}
|
|
127
141
|
},
|
|
128
142
|
...i,
|
|
129
|
-
...a
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
...a,
|
|
144
|
+
...s
|
|
145
|
+
}, l = (e) => Object.hasOwn(c, e) ? c[e] : void 0, u = (t, n) => {
|
|
146
|
+
let r = l(t);
|
|
132
147
|
return r ? {
|
|
133
148
|
known: !0,
|
|
134
149
|
params: e(n, r.params, r.strictParams)
|
|
@@ -137,4 +152,4 @@ var r = {
|
|
|
137
152
|
params: n
|
|
138
153
|
};
|
|
139
154
|
};
|
|
140
|
-
export {
|
|
155
|
+
export { c as BUILTIN_ELEMENT_CALLBACKS, a as FOCUS_CALLBACKS, s as FULLSCREEN_CALLBACKS, o as FULLSCREEN_MODES, i as SCROLL_CALLBACKS, u as applyElementCallback, l as getElementCallback };
|
package/dist/authoring/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBuilderParams as e, toInteractionCallback as t, toInteractionCallbacks as n } from "./builder.mjs";
|
|
2
2
|
import { definePlugin as r, elementDeclaration as i, valuesOf as a } from "./declare.mjs";
|
|
3
|
-
import { BUILTIN_ELEMENT_CALLBACKS as o, FOCUS_CALLBACKS as s,
|
|
4
|
-
import { BUILTIN_PARAM_TYPES as
|
|
5
|
-
import { NOTIFICATION_APPEARANCES as
|
|
6
|
-
export { o as BUILTIN_ELEMENT_CALLBACKS,
|
|
3
|
+
import { BUILTIN_ELEMENT_CALLBACKS as o, FOCUS_CALLBACKS as s, FULLSCREEN_CALLBACKS as c, FULLSCREEN_MODES as l, SCROLL_CALLBACKS as u, applyElementCallback as d, getElementCallback as f } from "./elementCallbacks.mjs";
|
|
4
|
+
import { BUILTIN_PARAM_TYPES as p, hiddenParams as m, invalidParams as h, missingRequiredParams as g, reconcileParams as _ } from "./paramSpec.mjs";
|
|
5
|
+
import { NOTIFICATION_APPEARANCES as v, NOTIFICATION_DEFAULTS as y, NOTIFICATION_PLACEMENTS as b, readNotificationOptions as x, spaceCallbacks as S } from "./spaceCallbacks.mjs";
|
|
6
|
+
export { o as BUILTIN_ELEMENT_CALLBACKS, p as BUILTIN_PARAM_TYPES, s as FOCUS_CALLBACKS, c as FULLSCREEN_CALLBACKS, l as FULLSCREEN_MODES, v as NOTIFICATION_APPEARANCES, y as NOTIFICATION_DEFAULTS, b as NOTIFICATION_PLACEMENTS, u as SCROLL_CALLBACKS, d as applyElementCallback, r as definePlugin, i as elementDeclaration, f as getElementCallback, m as hiddenParams, h as invalidParams, g as missingRequiredParams, x as readNotificationOptions, _ as reconcileParams, S as spaceCallbacks, e as toBuilderParams, t as toInteractionCallback, n as toInteractionCallbacks, a as valuesOf };
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* refusing a binding to a name nothing answers to, an element that may not take one of these names as its id — so a
|
|
7
7
|
* new global is a global everywhere at once.
|
|
8
8
|
*/
|
|
9
|
-
export declare const GLOBAL_SOURCES: readonly ["variables", "navigation", "auth", "state", "host", "theme", "flags", "experiments", "computed"];
|
|
9
|
+
export declare const GLOBAL_SOURCES: readonly ["variables", "navigation", "auth", "state", "host", "theme", "flags", "experiments", "time", "computed"];
|
|
10
10
|
export type GlobalSource = (typeof GLOBAL_SOURCES)[number];
|
|
11
11
|
/**
|
|
12
12
|
* What a computed value is evaluated over: every global but `state`, which a flow hands it live, and `computed`, which
|
|
13
13
|
* is what is being evaluated.
|
|
14
14
|
*/
|
|
15
|
-
export declare const COMPUTED_GLOBALS: ("auth" | "host" | "navigation" | "flags" | "variables" | "theme" | "experiments")[];
|
|
15
|
+
export declare const COMPUTED_GLOBALS: ("auth" | "time" | "host" | "navigation" | "flags" | "variables" | "theme" | "experiments")[];
|
|
16
16
|
/**
|
|
17
17
|
* The fields of the globals whose shape the platform decides, as `GlobalSources` publishes them: a read of any other
|
|
18
18
|
* — `auth.authenticated` for `auth.isAuthenticated` — resolves to nothing, and the authoring linter says so. An `open`
|
|
@@ -40,6 +40,10 @@ export declare const GLOBAL_SOURCE_FIELDS: {
|
|
|
40
40
|
readonly mode: "value";
|
|
41
41
|
readonly resolved: "value";
|
|
42
42
|
};
|
|
43
|
+
readonly time: {
|
|
44
|
+
readonly now: "value";
|
|
45
|
+
readonly today: "value";
|
|
46
|
+
};
|
|
43
47
|
};
|
|
44
48
|
export type ShapedGlobalSource = keyof typeof GLOBAL_SOURCE_FIELDS;
|
|
45
49
|
/** What one of those globals publishes: its declared fields and no others, each one a page may leave out. */
|
|
@@ -8,6 +8,7 @@ var e = [
|
|
|
8
8
|
"theme",
|
|
9
9
|
"flags",
|
|
10
10
|
"experiments",
|
|
11
|
+
"time",
|
|
11
12
|
"computed"
|
|
12
13
|
], t = e.filter((e) => e !== "state" && e !== "computed"), n = {
|
|
13
14
|
navigation: {
|
|
@@ -28,6 +29,10 @@ var e = [
|
|
|
28
29
|
theme: {
|
|
29
30
|
mode: "value",
|
|
30
31
|
resolved: "value"
|
|
32
|
+
},
|
|
33
|
+
time: {
|
|
34
|
+
now: "value",
|
|
35
|
+
today: "value"
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
38
|
export { t as COMPUTED_GLOBALS, e as GLOBAL_SOURCES, n as GLOBAL_SOURCE_FIELDS };
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -6,26 +6,27 @@ import { omit as i } from "./lodash/omit.mjs";
|
|
|
6
6
|
import { capitalize as a } from "./lodash/capitalize.mjs";
|
|
7
7
|
import { camelCase as o } from "./lodash/camelCase.mjs";
|
|
8
8
|
import s from "./syntaxHighlight.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
|
|
9
|
+
import { TIME_GRAIN_MS as c, TIME_NOW as l } from "./twigWrapper/filters/types.mjs";
|
|
10
|
+
import { filters as u } from "./twigWrapper/filters/filters.mjs";
|
|
11
|
+
import { processTwig as d, processTwigParam as f, processTwigValue as p } from "./twigWrapper/processTwig/processTwig.mjs";
|
|
12
|
+
import { hasTemplateSyntax as m } from "./twigWrapper/tokens/hasTemplateSyntax.mjs";
|
|
13
|
+
import { hasValidToken as h } from "./twigWrapper/tokens/hasValidToken.mjs";
|
|
14
|
+
import { MAX_PARAM_PASSES as g, resolveStepParam as _ } from "./twigWrapper/processTwig/resolveStepParam.mjs";
|
|
15
|
+
import { inspectTemplate as v } from "./twigWrapper/inspectTemplate.mjs";
|
|
16
|
+
import { templatePaths as y, templateRootNames as b } from "./twigWrapper/templateRoots.mjs";
|
|
17
|
+
import { cookieFromHeader as x, documentCookies as S } from "./cookies.mjs";
|
|
18
|
+
import { deepEqual as C } from "./deepEqual/deepEqual.mjs";
|
|
19
|
+
import { elementOf as w, isElementTarget as T, isNodeTarget as E, nodeOf as D } from "./eventTarget.mjs";
|
|
20
|
+
import { INTERVAL_TRIGGER as O, MIN_INTERVAL_MS as k, intervalOf as A } from "./interval.mjs";
|
|
21
|
+
import { isRecord as j } from "./isRecord.mjs";
|
|
22
|
+
import { isUserEdit as M } from "./reducerOrigin.mjs";
|
|
23
|
+
import { ParamsFromURL as N, delay as P, emptyObject as F, getDisplayName as I, getKeyDecoded as L, getPathsFromObject as R, hexToRGB as z, isInViewport as B, makeId as V } from "./utils.mjs";
|
|
24
|
+
import { TRUSTED_TYPES_POLICIES as H, disableReactDevTools as U } from "./security.mjs";
|
|
25
|
+
import { canonicalJson as W } from "./canonicalJson.mjs";
|
|
26
|
+
import { SPACE_ROOT_CLASS as G, spaceRootOf as K } from "./spaceRoot.mjs";
|
|
27
|
+
import { IMAGE_PATH as q, IMAGE_WIDTHS as J, imageSrcSet as Y, imageUrl as X, isImageWidth as Z, isRemoteImage as Q, isResizableImage as $ } from "./images.mjs";
|
|
28
|
+
import { KEY_TRIGGER as ee, isFieldEditing as te, keyPressCombo as ne, parseKeys as re } from "./keys.mjs";
|
|
29
|
+
import { SCROLL_BEHAVIORS as ie, SCROLL_POSITIONS as ae, SCROLL_TRIGGER as oe, VIEW_TRIGGER as se, scrollDistance as ce, scrollPosition as le, scrollState as ue } from "./scroll.mjs";
|
|
30
|
+
import { NOT_COPIED_REASON as de, clipboardWriter as fe, copyText as pe } from "./clipboard.mjs";
|
|
31
|
+
import { MEMORY_STEPS as me, VCPU_STEPS as he, memoryWords as ge, mibOf as _e, millicoresOf as ve, quantityWords as ye, sizeWords as be, vcpuWords as xe } from "./resources.mjs";
|
|
32
|
+
export { q as IMAGE_PATH, J as IMAGE_WIDTHS, O as INTERVAL_TRIGGER, ee as KEY_TRIGGER, g as MAX_PARAM_PASSES, me as MEMORY_STEPS, k as MIN_INTERVAL_MS, de as NOT_COPIED_REASON, N as ParamsFromURL, ie as SCROLL_BEHAVIORS, ae as SCROLL_POSITIONS, oe as SCROLL_TRIGGER, G as SPACE_ROOT_CLASS, c as TIME_GRAIN_MS, l as TIME_NOW, H as TRUSTED_TYPES_POLICIES, he as VCPU_STEPS, se as VIEW_TRIGGER, o as camelCase, W as canonicalJson, a as capitalize, fe as clipboardWriter, x as cookieFromHeader, pe as copyText, C as deepEqual, P as delay, U as disableReactDevTools, S as documentCookies, w as elementOf, F as emptyObject, e as fetchManifest, u as filters, t as get, I as getDisplayName, L as getKeyDecoded, R as getPathsFromObject, r as has, m as hasTemplateSyntax, h as hasValidToken, z as hexToRGB, Y as imageSrcSet, X as imageUrl, v as inspectTemplate, A as intervalOf, T as isElementTarget, te as isFieldEditing, Z as isImageWidth, B as isInViewport, E as isNodeTarget, j as isRecord, Q as isRemoteImage, $ as isResizableImage, M as isUserEdit, ne as keyPressCombo, V as makeId, ge as memoryWords, _e as mibOf, ve as millicoresOf, D as nodeOf, i as omit, re as parseKeys, d as processTwig, f as processTwigParam, p as processTwigValue, ye as quantityWords, _ as resolveStepParam, ce as scrollDistance, le as scrollPosition, ue as scrollState, n as set, be as sizeWords, K as spaceRootOf, s as syntaxHighlight, y as templatePaths, b as templateRootNames, xe as vcpuWords };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isTruthy as e, order as t, resolveCollection as n, resolveObjectEntries as r, valueIn as i } from "./helpers.mjs";
|
|
2
2
|
import { filters as a } from "../filters/filters.mjs";
|
|
3
|
-
import { ARROW_PARAMS as o } from "../filters/types.mjs";
|
|
4
|
-
import { isRawMarker as
|
|
5
|
-
import { serializeValue as
|
|
3
|
+
import { ARROW_PARAMS as o, filterEnvOf as s } from "../filters/types.mjs";
|
|
4
|
+
import { isRawMarker as c, unwrapRaw as l } from "../filters/raw.mjs";
|
|
5
|
+
import { serializeValue as u } from "../processTwig/helpers.mjs";
|
|
6
6
|
// src/helpers/twigWrapper/Evaluator/Evaluator.ts
|
|
7
|
-
var
|
|
7
|
+
var d = {
|
|
8
8
|
defined: (e) => e !== void 0,
|
|
9
9
|
null: (e) => e == null,
|
|
10
10
|
none: (e) => e == null,
|
|
@@ -12,14 +12,14 @@ var u = {
|
|
|
12
12
|
iterable: (e) => Array.isArray(e) || typeof e == "object" && !!e,
|
|
13
13
|
even: (e) => typeof e == "number" && e % 2 == 0,
|
|
14
14
|
odd: (e) => typeof e == "number" && Math.abs(e % 2) === 1
|
|
15
|
-
},
|
|
16
|
-
let i = new
|
|
15
|
+
}, f = (e) => e.type === "path" || e.type === "filter" && f(e.subject), p = (e, t) => t == null || t === "" && f(e), m = (e) => e.type === "path" ? e.segments[0] : e.type === "filter" ? m(e.subject) : void 0, h = (e) => e.type === "path" && e.segments.length === 1 ? e.segments[0] : e.type === "literal" && e.value === null ? "null" : void 0, g = [], _ = (e, t, n = !1, r = !1) => {
|
|
16
|
+
let i = new y(t, n, r);
|
|
17
17
|
return {
|
|
18
18
|
output: i.evalNodes(e),
|
|
19
19
|
variables: i.variables,
|
|
20
20
|
hasSet: i.hasSet
|
|
21
21
|
};
|
|
22
|
-
},
|
|
22
|
+
}, v = (e, t) => new y(t).evalExpression(e), y = class f {
|
|
23
23
|
variables;
|
|
24
24
|
keepEmptyTokens;
|
|
25
25
|
jsonStrings;
|
|
@@ -27,13 +27,14 @@ var u = {
|
|
|
27
27
|
escaping = !1;
|
|
28
28
|
breakFlag = !1;
|
|
29
29
|
continueFlag = !1;
|
|
30
|
+
env;
|
|
30
31
|
hasSet = !1;
|
|
31
32
|
constructor(e, t = !1, n = !1) {
|
|
32
33
|
this.variables = { ...e }, this.keepEmptyTokens = t, this.jsonStrings = n;
|
|
33
34
|
}
|
|
34
35
|
keeps(e) {
|
|
35
36
|
if (typeof this.keepEmptyTokens == "boolean") return this.keepEmptyTokens;
|
|
36
|
-
let t =
|
|
37
|
+
let t = m(e);
|
|
37
38
|
return t === void 0 || !this.keepEmptyTokens.settled.has(t);
|
|
38
39
|
}
|
|
39
40
|
evalNodes(e) {
|
|
@@ -58,7 +59,7 @@ var u = {
|
|
|
58
59
|
}
|
|
59
60
|
evalVariable(e) {
|
|
60
61
|
let t = this.evalExpression(e.expression);
|
|
61
|
-
return this.keeps(e.expression) &&
|
|
62
|
+
return this.keeps(e.expression) && p(e.expression, t) ? e.source : c(t) ? String(l(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
|
|
62
63
|
}
|
|
63
64
|
followQuotes(e) {
|
|
64
65
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -113,13 +114,13 @@ var u = {
|
|
|
113
114
|
}
|
|
114
115
|
evalApply(e) {
|
|
115
116
|
let t = this.applyFilters(this.evalNodes(e.body), e.filters);
|
|
116
|
-
return
|
|
117
|
+
return c(t) ? String(l(t)) : typeof t == "object" && t ? JSON.stringify(t) : t == null ? "" : String(t);
|
|
117
118
|
}
|
|
118
119
|
applyFilters(e, t) {
|
|
119
120
|
let n = e;
|
|
120
121
|
for (let e of t) {
|
|
121
122
|
let t = a[e.name];
|
|
122
|
-
t !== void 0 && (n = t(n, e.args.length === 0 ?
|
|
123
|
+
t !== void 0 && (this.env ??= s(this.variables), n = t(n, e.args.length === 0 ? g : this.evalArgs(e.args), this.env));
|
|
123
124
|
}
|
|
124
125
|
return n;
|
|
125
126
|
}
|
|
@@ -169,7 +170,7 @@ var u = {
|
|
|
169
170
|
}
|
|
170
171
|
createArrowFunction(e, t) {
|
|
171
172
|
let n = { ...this.variables }, r = this.keepEmptyTokens, i = (...i) => {
|
|
172
|
-
let a = new
|
|
173
|
+
let a = new f(n, r);
|
|
173
174
|
for (let t = 0; t < e.length; t++) a.variables[e[t]] = i[t];
|
|
174
175
|
return a.evalExpression(t);
|
|
175
176
|
};
|
|
@@ -228,9 +229,9 @@ var u = {
|
|
|
228
229
|
return a;
|
|
229
230
|
}
|
|
230
231
|
evalBinary(n, r, a) {
|
|
231
|
-
let o =
|
|
232
|
+
let o = h(a);
|
|
232
233
|
if ((n === "is" || n === "is not") && o !== void 0) {
|
|
233
|
-
let e =
|
|
234
|
+
let e = d[o];
|
|
234
235
|
if (e) {
|
|
235
236
|
let t = e(this.evalExpression(r));
|
|
236
237
|
return n === "is" ? t : !t;
|
|
@@ -238,23 +239,23 @@ var u = {
|
|
|
238
239
|
}
|
|
239
240
|
if (n === "or") return e(this.evalExpression(r)) || e(this.evalExpression(a));
|
|
240
241
|
if (n === "and") return e(this.evalExpression(r)) && e(this.evalExpression(a));
|
|
241
|
-
let s = this.evalExpression(r), c = this.evalExpression(a),
|
|
242
|
+
let s = this.evalExpression(r), c = this.evalExpression(a), l = typeof s == "number" && typeof c == "number";
|
|
242
243
|
switch (n) {
|
|
243
|
-
case "+": return
|
|
244
|
-
case "-": return
|
|
245
|
-
case "*": return
|
|
246
|
-
case "/": return
|
|
244
|
+
case "+": return l ? s + c : Number(s) + Number(c);
|
|
245
|
+
case "-": return l ? s - c : Number(s) - Number(c);
|
|
246
|
+
case "*": return l ? s * c : Number(s) * Number(c);
|
|
247
|
+
case "/": return l ? s / c : Number(s) / Number(c);
|
|
247
248
|
case "//": return Math.floor(Number(s) / Number(c));
|
|
248
249
|
case "**": return Number(s) ** Number(c);
|
|
249
|
-
case "starts with": return typeof s == "string" && s.startsWith(
|
|
250
|
-
case "ends with": return typeof s == "string" && s.endsWith(
|
|
251
|
-
case "%": return
|
|
250
|
+
case "starts with": return typeof s == "string" && s.startsWith(u(c));
|
|
251
|
+
case "ends with": return typeof s == "string" && s.endsWith(u(c));
|
|
252
|
+
case "%": return l ? s % c : Number(s) % Number(c);
|
|
252
253
|
case "==": return s === c || String(s) === String(c);
|
|
253
254
|
case "!=": return s !== c && String(s) !== String(c);
|
|
254
|
-
case ">": return
|
|
255
|
-
case "<": return
|
|
256
|
-
case ">=": return
|
|
257
|
-
case "<=": return
|
|
255
|
+
case ">": return l ? s > c : t(s, c) > 0;
|
|
256
|
+
case "<": return l ? s < c : t(s, c) < 0;
|
|
257
|
+
case ">=": return l ? s >= c : t(s, c) >= 0;
|
|
258
|
+
case "<=": return l ? s <= c : t(s, c) <= 0;
|
|
258
259
|
case "in": return i(s, c);
|
|
259
260
|
case "not in": return !i(s, c);
|
|
260
261
|
case "same as": return s === c;
|
|
@@ -268,4 +269,4 @@ var u = {
|
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
};
|
|
271
|
-
export {
|
|
272
|
+
export { _ as evaluate, v as evaluateExpression };
|
|
@@ -252,7 +252,7 @@ var e = {
|
|
|
252
252
|
},
|
|
253
253
|
ago: {
|
|
254
254
|
signature: "ago(locale?)",
|
|
255
|
-
summary: "Relative time: how long ago a moment was, or how far ahead, in words — \"4 minutes ago\", \"in 3 hours\", \"now\" — at the
|
|
255
|
+
summary: "Relative time: how long ago a moment was, or how far ahead, in words — \"4 minutes ago\", \"in 3 hours\", \"now\" — at the page’s clock (time.now), moving on each minute while the page is open",
|
|
256
256
|
example: "{{ played.endedAt|ago }} · {{ post.at|ago(\"es\") }}"
|
|
257
257
|
},
|
|
258
258
|
duration: {
|
|
@@ -68,19 +68,19 @@ var i = {
|
|
|
68
68
|
for (let e of a) m ? (p += e, m = !1) : e === "\\" ? m = !0 : p += Object.prototype.hasOwnProperty.call(f, e) ? f[e] : e;
|
|
69
69
|
return p;
|
|
70
70
|
},
|
|
71
|
-
ago: (e, n) => {
|
|
72
|
-
let
|
|
73
|
-
if (Number.isNaN(
|
|
74
|
-
let
|
|
71
|
+
ago: (e, n, i) => {
|
|
72
|
+
let a = t(e);
|
|
73
|
+
if (Number.isNaN(a.getTime())) return "";
|
|
74
|
+
let o = (a.getTime() - i.now) / 1e3, s = Math.abs(o) * 1e3 < i.grain ? 0 : Math.round(o), [c, l] = [
|
|
75
75
|
["year", 31536e3],
|
|
76
76
|
["month", 2592e3],
|
|
77
77
|
["week", 604800],
|
|
78
78
|
["day", 86400],
|
|
79
79
|
["hour", 3600],
|
|
80
80
|
["minute", 60]
|
|
81
|
-
].find(([, e]) => Math.abs(
|
|
81
|
+
].find(([, e]) => Math.abs(s) >= e) ?? ["second", 1], u = c === "second" ? Math.abs(s) < 10 ? 0 : s : Math.trunc(s / l);
|
|
82
82
|
for (let e of [n.length > 0 ? r(n[0]) : "en", "en"]) try {
|
|
83
|
-
return new Intl.RelativeTimeFormat(e, { numeric: "auto" }).format(
|
|
83
|
+
return new Intl.RelativeTimeFormat(e, { numeric: "auto" }).format(u, c);
|
|
84
84
|
} catch {
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
@@ -5,9 +5,9 @@ import { numberFilters as o } from "./numbers.mjs";
|
|
|
5
5
|
import { objectFilters as s, queryFilters as c } from "./objects.mjs";
|
|
6
6
|
import { defaultFilters as l, identityFilters as u, serialisationFilters as d, stringOperationFilters as f, stringQueryFilters as p, stringTransformFilters as m } from "./strings.mjs";
|
|
7
7
|
import { RAW_MARKER as h, isRawMarker as g, unwrapRaw as _, wrapRaw as v } from "./raw.mjs";
|
|
8
|
-
import { ARROW_PARAMS as y,
|
|
8
|
+
import { ARROW_PARAMS as y, TIME_GRAIN_MS as b, TIME_NOW as x, filterEnvOf as S, isCallback as C, isList as w } from "./types.mjs";
|
|
9
9
|
// src/helpers/twigWrapper/filters/filters.ts
|
|
10
|
-
var
|
|
10
|
+
var T = {
|
|
11
11
|
...u,
|
|
12
12
|
...d,
|
|
13
13
|
...l,
|
|
@@ -24,4 +24,4 @@ var S = {
|
|
|
24
24
|
...s,
|
|
25
25
|
...c
|
|
26
26
|
};
|
|
27
|
-
export { y as ARROW_PARAMS, h as RAW_MARKER, S as filters,
|
|
27
|
+
export { y as ARROW_PARAMS, h as RAW_MARKER, b as TIME_GRAIN_MS, x as TIME_NOW, S as filterEnvOf, T as filters, C as isCallback, w as isList, g as isRawMarker, _ as unwrapRaw, v as wrapRaw };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARROW_PARAMS as e,
|
|
2
|
-
import { RAW_MARKER as
|
|
3
|
-
import { filters as
|
|
4
|
-
export { e as ARROW_PARAMS,
|
|
1
|
+
import { ARROW_PARAMS as e, TIME_GRAIN_MS as t, TIME_NOW as n, filterEnvOf as r, isCallback as i, isList as a } from "./types.mjs";
|
|
2
|
+
import { RAW_MARKER as o, isRawMarker as s, unwrapRaw as c, wrapRaw as l } from "./raw.mjs";
|
|
3
|
+
import { filters as u } from "./filters.mjs";
|
|
4
|
+
export { e as ARROW_PARAMS, o as RAW_MARKER, t as TIME_GRAIN_MS, n as TIME_NOW, r as filterEnvOf, u as filters, i as isCallback, a as isList, s as isRawMarker, c as unwrapRaw, l as wrapRaw };
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export type TwigFilter = (value: unknown, args: readonly unknown[]) => unknown;
|
|
1
|
+
export type TwigFilter = (value: unknown, args: readonly unknown[], env: FilterEnv) => unknown;
|
|
2
|
+
/**
|
|
3
|
+
* What a filter may read of the render besides its value: the instant it happens at. The page's clock (`time.now`)
|
|
4
|
+
* where the template reads it — minute by minute, so `grain` is a minute and what is within one is "now" — and the
|
|
5
|
+
* moment it runs otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export type FilterEnv = {
|
|
8
|
+
now: number;
|
|
9
|
+
grain: number;
|
|
10
|
+
};
|
|
11
|
+
/** The page's clock in a template's scope, `time.now`: what makes a relative time move on while the page is open. */
|
|
12
|
+
export declare const TIME_NOW = "time.now";
|
|
13
|
+
/** What the page's clock steps by: `time.now` is the start of the minute it is. */
|
|
14
|
+
export declare const TIME_GRAIN_MS = 60000;
|
|
15
|
+
/** The instant a render happens at: the page's clock when the template's scope holds it, the moment it runs if not. */
|
|
16
|
+
export declare const filterEnvOf: (variables: Record<string, unknown>) => FilterEnv;
|
|
2
17
|
export declare const ARROW_PARAMS: unique symbol;
|
|
3
18
|
export type ArrowCallback = ((...args: unknown[]) => unknown) & {
|
|
4
19
|
[ARROW_PARAMS]?: number;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
// src/helpers/twigWrapper/filters/types.ts
|
|
2
|
-
var e =
|
|
3
|
-
|
|
2
|
+
var e = "time.now", t = 6e4, n = (e) => {
|
|
3
|
+
let n = e.time, r = typeof n == "object" && n && "now" in n ? n.now : void 0;
|
|
4
|
+
return typeof r == "number" ? {
|
|
5
|
+
now: r,
|
|
6
|
+
grain: t
|
|
7
|
+
} : {
|
|
8
|
+
now: Date.now(),
|
|
9
|
+
grain: 1
|
|
10
|
+
};
|
|
11
|
+
}, r = Symbol("twigArrowParams"), i = (e) => Array.isArray(e), a = (e) => typeof e == "function";
|
|
12
|
+
export { r as ARROW_PARAMS, t as TIME_GRAIN_MS, e as TIME_NOW, n as filterEnvOf, a as isCallback, i as isList };
|
|
@@ -5,7 +5,8 @@ export { hasValidToken } from './tokens/hasValidToken';
|
|
|
5
5
|
export { inspectTemplate } from './inspectTemplate';
|
|
6
6
|
export { templatePaths, templateRootNames } from './templateRoots';
|
|
7
7
|
export { filters } from './filters/filters';
|
|
8
|
+
export { TIME_GRAIN_MS, TIME_NOW } from './filters/types';
|
|
8
9
|
export type { ASTNode, Expression } from './AST';
|
|
9
10
|
export type { KeepEmptyTokens } from './Evaluator';
|
|
10
11
|
export type { TemplateInspection } from './inspectTemplate';
|
|
11
|
-
export type { TwigFilter } from './filters/filters';
|
|
12
|
+
export type { FilterEnv, TwigFilter } from './filters/filters';
|