@plitzi/sdk-shared 0.39.11 → 0.39.13

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 (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/audiences/audiences.d.ts +78 -0
  3. package/dist/audiences/audiences.mjs +75 -0
  4. package/dist/audiences/index.d.ts +1 -0
  5. package/dist/audiences/index.mjs +1 -0
  6. package/dist/authoring/elementCallbacks.d.ts +22 -0
  7. package/dist/authoring/elementCallbacks.mjs +20 -5
  8. package/dist/authoring/index.mjs +4 -4
  9. package/dist/authoring/spaceCallbacks.mjs +46 -33
  10. package/dist/dataSource/globalSources.d.ts +8 -4
  11. package/dist/dataSource/globalSources.mjs +6 -0
  12. package/dist/experimentEvents/experimentEvents.d.ts +24 -0
  13. package/dist/experimentEvents/experimentEvents.mjs +28 -0
  14. package/dist/experimentEvents/index.d.ts +1 -0
  15. package/dist/experimentEvents/index.mjs +1 -0
  16. package/dist/experiments/experiments.d.ts +73 -0
  17. package/dist/experiments/experiments.mjs +74 -0
  18. package/dist/experiments/experimentsCookie.d.ts +26 -0
  19. package/dist/experiments/experimentsCookie.mjs +25 -0
  20. package/dist/experiments/forcedExperiments.d.ts +31 -0
  21. package/dist/experiments/forcedExperiments.mjs +41 -0
  22. package/dist/experiments/index.d.ts +3 -0
  23. package/dist/experiments/index.mjs +4 -0
  24. package/dist/flags/index.d.ts +1 -0
  25. package/dist/flags/index.mjs +6 -5
  26. package/dist/flags/react/index.d.ts +1 -0
  27. package/dist/flags/react/index.mjs +3 -1
  28. package/dist/flags/react/useFlagResolution.mjs +22 -19
  29. package/dist/flags/react/useRolloutBuckets.d.ts +9 -0
  30. package/dist/flags/react/useRolloutBuckets.mjs +19 -0
  31. package/dist/flags/resolveFlags.d.ts +10 -3
  32. package/dist/flags/resolveFlags.mjs +19 -9
  33. package/dist/flags/rollout.d.ts +41 -0
  34. package/dist/flags/rollout.mjs +53 -0
  35. package/dist/flags/schemaFlag.d.ts +3 -1
  36. package/dist/flags/schemaFlag.mjs +2 -2
  37. package/dist/helpers/index.mjs +31 -30
  38. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +28 -27
  39. package/dist/helpers/twigWrapper/filters/catalog/index.mjs +1 -1
  40. package/dist/helpers/twigWrapper/filters/dates.mjs +6 -6
  41. package/dist/helpers/twigWrapper/filters/filters.mjs +3 -3
  42. package/dist/helpers/twigWrapper/filters/index.mjs +4 -4
  43. package/dist/helpers/twigWrapper/filters/types.d.ts +16 -1
  44. package/dist/helpers/twigWrapper/filters/types.mjs +11 -2
  45. package/dist/helpers/twigWrapper/index.d.ts +2 -1
  46. package/dist/helpers/twigWrapper/index.mjs +4 -3
  47. package/dist/helpers/twigWrapper/templateRoots.mjs +19 -18
  48. package/dist/schema/serverElements.mjs +18 -18
  49. package/dist/schema/serverInput.mjs +6 -6
  50. package/dist/store/renderSettings.d.ts +1 -0
  51. package/dist/store/renderSettings.mjs +16 -12
  52. package/dist/store/storeHooks.d.ts +45 -45
  53. package/dist/style/styleStates.d.ts +7 -2
  54. package/dist/style/styleStates.mjs +2 -2
  55. package/dist/timeWindows/clock.d.ts +11 -0
  56. package/dist/timeWindows/clock.mjs +6 -0
  57. package/dist/timeWindows/countdown.d.ts +31 -0
  58. package/dist/timeWindows/countdown.mjs +57 -0
  59. package/dist/timeWindows/index.d.ts +3 -0
  60. package/dist/timeWindows/index.mjs +4 -0
  61. package/dist/timeWindows/timeWindows.d.ts +13 -0
  62. package/dist/timeWindows/timeWindows.mjs +10 -0
  63. package/dist/types/CommonTypes.d.ts +5 -0
  64. package/dist/types/DataSourceTypes.d.ts +1 -1
  65. package/dist/types/ElementTypes.d.ts +1 -1
  66. package/dist/types/PluginTypes.d.ts +5 -0
  67. package/dist/types/SchemaTypes.d.ts +11 -1
  68. package/dist/types/StoreTypes.d.ts +63 -0
  69. package/dist/variants/index.d.ts +1 -0
  70. package/dist/variants/index.mjs +1 -0
  71. package/dist/variants/variants.d.ts +23 -0
  72. package/dist/variants/variants.mjs +9 -0
  73. package/package.json +1 -1
@@ -46,8 +46,13 @@ export declare const inCascadeOrder: <T>(states: Record<string, T>) => [string,
46
46
  * they are written: a new alternative must weigh no more than that, or every `current` rule gets heavier with it.
47
47
  */
48
48
  export declare const CURRENT_SELECTOR = ":is([aria-current]:not([aria-current=\"false\"]),[aria-pressed=\"true\"],[aria-selected=\"true\"],[role=\"tabpanel\"]:not([hidden]))";
49
- /** What the `expanded` state selects: the control whose panel is open. */
50
- export declare const EXPANDED_SELECTOR = "[aria-expanded=\"true\"]";
49
+ /**
50
+ * What the `expanded` state selects: the control whose panel is open — one that says so (`aria-expanded`), or the
51
+ * `<summary>` of an open `<details>` (a `disclosure`), which says it through its `<details>`: ARIA has no
52
+ * `aria-expanded` for a summary. The summary's alternative weighs nothing (`:where`), so the state weighs the one
53
+ * attribute it always has and keeps its place against `hover` and the rest: weighing more, it would beat them all.
54
+ */
55
+ export declare const EXPANDED_SELECTOR = ":is([aria-expanded=\"true\"],:where([open]>summary))";
51
56
  /**
52
57
  * How a state is written after the selector it modifies: its pseudo-class — or, for `hidden`, the class that hides; for
53
58
  * `current` and `expanded`, the attributes the element carries; for where it sits, the structural pseudo-class.
@@ -41,7 +41,7 @@ var e = [
41
41
  checked: "while a box or a radio is ticked",
42
42
  visited: "a link to a page the visitor has been to",
43
43
  current: "the chosen one of a set, as the element says it — the selected tab (aria-selected), the link to the page shown (aria-current), the pressed toggle (aria-pressed)",
44
- expanded: "the control of a panel while the panel is open — a dropdown trigger, an accordion header (aria-expanded)",
44
+ expanded: "the control of a panel while the panel is open — a dropdown trigger, a disclosure’s summary, a menu button (aria-expanded)",
45
45
  hidden: "how it looks while its `visible` says no — where it goes as it hides, with a transition on the class",
46
46
  first: "the first of its siblings",
47
47
  last: "the last of its siblings",
@@ -63,7 +63,7 @@ var e = [
63
63
  active: 12,
64
64
  disabled: 13,
65
65
  hidden: 14
66
- }, a = (e) => Object.hasOwn(i, e), o = (t) => a(t) ? i[t] : e.length, s = (e) => Object.entries(e).sort(([e], [t]) => o(e) - o(t)), c = ":is([aria-current]:not([aria-current=\"false\"]),[aria-pressed=\"true\"],[aria-selected=\"true\"],[role=\"tabpanel\"]:not([hidden]))", l = "[aria-expanded=\"true\"]", u = {
66
+ }, a = (e) => Object.hasOwn(i, e), o = (t) => a(t) ? i[t] : e.length, s = (e) => Object.entries(e).sort(([e], [t]) => o(e) - o(t)), c = ":is([aria-current]:not([aria-current=\"false\"]),[aria-pressed=\"true\"],[aria-selected=\"true\"],[role=\"tabpanel\"]:not([hidden]))", l = ":is([aria-expanded=\"true\"],:where([open]>summary))", u = {
67
67
  current: c,
68
68
  expanded: l,
69
69
  hidden: `.${t}`,
@@ -0,0 +1,11 @@
1
+ import { Schema } from '../types';
2
+ type SpaceTrees = Pick<Schema, 'flat'> & Partial<Pick<Schema, 'components'>> & {
3
+ settings?: Partial<Pick<Schema['settings'], 'computed'>>;
4
+ };
5
+ /**
6
+ * Whether a space shows or says anything by the time — a time window, a countdown, a template that reads the page's
7
+ * clock (`time.*`, `ago`), on its pages, in its components or its computed values: its pages are then drawn at an
8
+ * instant the browser hydrates at, and say on the server what they say in the browser.
9
+ */
10
+ export declare const readsTheClock: (schema: SpaceTrees) => boolean;
11
+ export {};
@@ -0,0 +1,6 @@
1
+ import { templatePaths as e } from "../helpers/twigWrapper/templateRoots.mjs";
2
+ import { COUNTDOWN_TYPE as t } from "./countdown.mjs";
3
+ import { TIME_WINDOW_TYPE as n } from "./timeWindows.mjs";
4
+ // src/timeWindows/clock.ts
5
+ var r = /* @__PURE__ */ new Set([n, t]), i = (e) => e === "time" || e.startsWith("time."), a = (t) => typeof t == "string" ? i(t) ? !0 : (t.includes("{{") || t.includes("{%")) && e(t).some(i) : Array.isArray(t) ? t.some(a) : typeof t == "object" && !!t && Object.values(t).some(a), o = (e) => [e.flat, ...Object.values(e.components ?? {}).map((e) => e.flat)].some((e) => Object.values(e).some((e) => r.has(e.definition.type) || a(e.attributes) || a(e.definition))) || a(e.settings?.computed);
6
+ export { o as readsTheClock };
@@ -0,0 +1,31 @@
1
+ /** The element that says how long is left until an instant. */
2
+ export declare const COUNTDOWN_TYPE = "countdown";
3
+ /** The units a countdown says what is left in, largest first. */
4
+ export declare const COUNTDOWN_UNITS: readonly ["days", "hours", "minutes", "seconds"];
5
+ export type CountdownUnit = (typeof COUNTDOWN_UNITS)[number];
6
+ /** How a countdown names its units: in words (`days`), short (`d`, `hr`), or not at all. */
7
+ export declare const COUNTDOWN_LABELS: readonly ["long", "short", "none"];
8
+ export type CountdownLabels = (typeof COUNTDOWN_LABELS)[number];
9
+ export type CountdownPart = {
10
+ unit: CountdownUnit;
11
+ amount: number;
12
+ };
13
+ /** The units from `largest` down to `smallest`, in order; one unit alone when they are written the other way round. */
14
+ export declare const countdownUnits: (largest: CountdownUnit, smallest: CountdownUnit) => CountdownUnit[];
15
+ /**
16
+ * What is left from `now` until `to`, in each unit from `largest` down to `smallest` — the largest holding whatever does
17
+ * not fit below it (49 hours with `largest: 'hours'`). Counted up to the smallest unit, so the last second reads 1, not
18
+ * 0, until it is over; every part 0 from then on.
19
+ */
20
+ export declare const countdownParts: (now: number, to: number, largest?: CountdownUnit, smallest?: CountdownUnit) => CountdownPart[];
21
+ /** The next instant after `now` what a countdown shows changes at — a second, or a minute, less — or none once over. */
22
+ export declare const nextCountdownTick: (now: number, to: number, smallest?: CountdownUnit) => number | undefined;
23
+ /** What is left as an ISO 8601 duration — `P2DT3H4M` — what a `<time datetime>` says it in. */
24
+ export declare const countdownDuration: (parts: readonly CountdownPart[]) => string;
25
+ /**
26
+ * A unit's name for an amount of it, in `locale` and its plural — `days`, `día`, `hr` — or `''` with no labels. A
27
+ * locale the runtime does not know is read as English.
28
+ */
29
+ export declare const countdownLabel: (unit: CountdownUnit, amount: number, labels: CountdownLabels, locale: string) => string;
30
+ /** The instant a countdown counts to: its own `to`, or the end of the time window around it. */
31
+ export declare const countdownTarget: (to: unknown, windowEnd: unknown) => number | undefined;
@@ -0,0 +1,57 @@
1
+ import { instantOf as e } from "./timeWindows.mjs";
2
+ // src/timeWindows/countdown.ts
3
+ var t = "countdown", n = [
4
+ "days",
5
+ "hours",
6
+ "minutes",
7
+ "seconds"
8
+ ], r = [
9
+ "long",
10
+ "short",
11
+ "none"
12
+ ], i = {
13
+ days: 864e5,
14
+ hours: 36e5,
15
+ minutes: 6e4,
16
+ seconds: 1e3
17
+ }, a = {
18
+ days: "day",
19
+ hours: "hour",
20
+ minutes: "minute",
21
+ seconds: "second"
22
+ }, o = (e, t) => {
23
+ let r = n.indexOf(e), i = n.indexOf(t);
24
+ return n.slice(r, Math.max(r, i) + 1);
25
+ }, s = (e, t, n = "days", r = "seconds") => {
26
+ let a = o(n, r), s = i[a[a.length - 1]], c = Math.max(0, Math.ceil((t - e) / s) * s);
27
+ return a.map((e) => {
28
+ let t = Math.floor(c / i[e]);
29
+ return c -= t * i[e], {
30
+ unit: e,
31
+ amount: t
32
+ };
33
+ });
34
+ }, c = (e, t, n = "seconds") => {
35
+ let r = i[n], a = t - e;
36
+ if (!(a <= 0)) return t - (Math.ceil(a / r) - 1) * r;
37
+ }, l = (e) => {
38
+ let t = (t) => e.find((e) => e.unit === t)?.amount ?? 0, n = [
39
+ [t("hours"), "H"],
40
+ [t("minutes"), "M"],
41
+ [t("seconds"), "S"]
42
+ ].filter(([e]) => e !== 0).map(([e, t]) => `${String(e)}${String(t)}`).join(""), r = t("days") > 0 ? `${String(t("days"))}D` : "";
43
+ return r || n ? `P${r}${n ? `T${n}` : ""}` : "PT0S";
44
+ }, u = (e, t, n, r) => {
45
+ if (n === "none") return "";
46
+ for (let i of [r || "en", "en"]) try {
47
+ return new Intl.NumberFormat(i, {
48
+ style: "unit",
49
+ unit: a[e],
50
+ unitDisplay: n
51
+ }).formatToParts(t).filter((e) => e.type === "unit").map((e) => e.value).join("").trim();
52
+ } catch {
53
+ continue;
54
+ }
55
+ return "";
56
+ }, d = (t, n) => e(t) ?? (t === void 0 || t === "" ? e(n) : void 0);
57
+ export { r as COUNTDOWN_LABELS, t as COUNTDOWN_TYPE, n as COUNTDOWN_UNITS, l as countdownDuration, u as countdownLabel, s as countdownParts, d as countdownTarget, o as countdownUnits, c as nextCountdownTick };
@@ -0,0 +1,3 @@
1
+ export * from './clock';
2
+ export * from './countdown';
3
+ export * from './timeWindows';
@@ -0,0 +1,4 @@
1
+ import { readsTheClock as e } from "./clock.mjs";
2
+ import { COUNTDOWN_LABELS as t, COUNTDOWN_TYPE as n, COUNTDOWN_UNITS as r, countdownDuration as i, countdownLabel as a, countdownParts as o, countdownTarget as s, countdownUnits as c, nextCountdownTick as l } from "./countdown.mjs";
3
+ import { TIME_WINDOW_TYPE as u, instantOf as d, isWindowBound as f, isWindowOpen as p, nextWindowChange as m } from "./timeWindows.mjs";
4
+ export { t as COUNTDOWN_LABELS, n as COUNTDOWN_TYPE, r as COUNTDOWN_UNITS, u as TIME_WINDOW_TYPE, i as countdownDuration, a as countdownLabel, o as countdownParts, s as countdownTarget, c as countdownUnits, d as instantOf, f as isWindowBound, p as isWindowOpen, l as nextCountdownTick, m as nextWindowChange, e as readsTheClock };
@@ -0,0 +1,13 @@
1
+ /** The element that shows what it holds only between two instants. */
2
+ export declare const TIME_WINDOW_TYPE = "timeWindow";
3
+ /**
4
+ * The instant a window's bound names, in ms since the epoch — or `undefined` for one left empty or written without its
5
+ * offset: a time with no zone is a different instant for every visitor, so it is never read as one.
6
+ */
7
+ export declare const instantOf: (value: unknown) => number | undefined;
8
+ /** Whether a bound is written as an instant the window can read: empty (no bound) or ISO 8601 with its offset. */
9
+ export declare const isWindowBound: (value: unknown) => boolean;
10
+ /** Whether a window is open at `now`: from its start (none, always started) up to its end (none, never ended). */
11
+ export declare const isWindowOpen: (now: number, from: unknown, until: unknown) => boolean;
12
+ /** The next instant after `now` a window opens or closes at — what a page waits for to show or hide it — or none. */
13
+ export declare const nextWindowChange: (now: number, from: unknown, until: unknown) => number | undefined;
@@ -0,0 +1,10 @@
1
+ // src/timeWindows/timeWindows.ts
2
+ var e = "timeWindow", t = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/, n = (e) => {
3
+ if (typeof e != "string" || !t.test(e)) return;
4
+ let n = Date.parse(e);
5
+ return Number.isNaN(n) ? void 0 : n;
6
+ }, r = (e) => e === void 0 || e === "" || n(e) !== void 0, i = (e, t, r) => {
7
+ let i = n(t), a = n(r);
8
+ return (i === void 0 || e >= i) && (a === void 0 || e < a);
9
+ }, a = (e, t, r) => [n(t), n(r)].filter((t) => t !== void 0 && t > e).sort((e, t) => e - t)[0];
10
+ export { e as TIME_WINDOW_TYPE, n as instantOf, r as isWindowBound, i as isWindowOpen, a as nextWindowChange };
@@ -33,6 +33,11 @@ export type Server<T extends Record<string, unknown> = Record<string, unknown>>
33
33
  scriptPolicy?: 'report-only' | 'enforce';
34
34
  websocketServer: string;
35
35
  subscriptionServer: string;
36
+ /**
37
+ * Where this deployment's MCP server answers, `/mcp` included: what an agent is added with to work on a space as a
38
+ * collaborator (the builder's Claude panel). Absent where the host runs none.
39
+ */
40
+ mcpServer?: string;
36
41
  location?: Location;
37
42
  authenticated?: boolean;
38
43
  skipAuth?: boolean;
@@ -39,7 +39,7 @@ export type SourceField = {
39
39
  inputType?: Field['inputType'];
40
40
  values?: {
41
41
  value: RuleValue;
42
- label: 'string';
42
+ label: string;
43
43
  }[];
44
44
  };
45
45
  export type SourceMeta = {
@@ -22,7 +22,7 @@ export type InternalPropsSTG1<T extends InternalPropsExtension = InternalPropsEx
22
22
  plitziElementLayout?: ElementLayout;
23
23
  attributes?: Element['attributes'];
24
24
  };
25
- export type ComponentDefinition = Pick<PluginSchema, 'attributes' | 'builder' | 'definition' | 'defaultStyle' | 'initialItems' | 'contentAttributes'> & {
25
+ export type ComponentDefinition = Pick<PluginSchema, 'attributes' | 'builder' | 'definition' | 'defaultStyle' | 'initialItems' | 'contentAttributes' | 'ancestorType'> & {
26
26
  assets: Asset[];
27
27
  assetsSettings: Omit<Asset, 'isMain'>[];
28
28
  manifest: PluginManifest;
@@ -8,6 +8,11 @@ export type PluginSchema = {
8
8
  definition: Element['definition'];
9
9
  /** The attributes a role that edits the content and not the design may change; none, it may change none. */
10
10
  contentAttributes?: string[];
11
+ /**
12
+ * The element this one only works somewhere inside — a carousel's track, an A/B test's variant: the builder's
13
+ * catalogue lists it after that one, as a part of it.
14
+ */
15
+ ancestorType?: string;
11
16
  defaultStyle: {
12
17
  name: string;
13
18
  displayMode: DisplayMode;
@@ -176,9 +176,19 @@ export type SchemaFlagRule = {
176
176
  */
177
177
  export type SchemaFlag = {
178
178
  description?: string;
179
- /** The answer when no rule matches. */
179
+ /** The answer when no rule matches — and no rollout takes the visitor in. */
180
180
  value: boolean;
181
181
  rules: SchemaFlagRule[];
182
+ /**
183
+ * A gradual rollout, read when no rule matches: `percent` of the visitors (0–100) get `value`, the rest the flag's own
184
+ * `value`. Each visitor is kept in their place by a cookie, so raising the percent keeps everyone who was in.
185
+ */
186
+ rollout?: SchemaFlagRollout;
187
+ };
188
+ /** A share of the visitors a flag answers `value` for, when none of its rules matched. */
189
+ export type SchemaFlagRollout = {
190
+ percent: number;
191
+ value: boolean;
182
192
  };
183
193
  export type PageFolder = {
184
194
  id: string;
@@ -9,7 +9,10 @@ import { SpaceConnector } from './SpaceTypes';
9
9
  import { DisplayMode, Style, StylePseudo, StyleState } from './StyleTypes';
10
10
  import { SignedInTestAccount } from './TestTypes';
11
11
  import { ColorScheme, Theme } from './ThemeTypes';
12
+ import { VisitorFacts } from '../audiences/audiences';
13
+ import { ExperimentAssignments } from '../experiments/experiments';
12
14
  import { FlagOverrides, FlagResolution } from '../flags/resolveFlags';
15
+ import { RolloutBuckets } from '../flags/rollout';
13
16
  /** Where a site's badge leads: who made it, and where to report one that abuses its address — the deployment's own. */
14
17
  export type BadgeLinks = {
15
18
  madeWith: string;
@@ -28,7 +31,12 @@ export type RuntimeSourceValues = {
28
31
  mode: Theme;
29
32
  resolved: ColorScheme;
30
33
  };
34
+ time?: {
35
+ now: number;
36
+ today: string;
37
+ };
31
38
  flags?: Record<string, boolean>;
39
+ experiments?: ExperimentAssignments;
32
40
  };
33
41
  /**
34
42
  * The feature flags of this render: what each layer above the space says, and how every flag resolved.
@@ -46,10 +54,32 @@ export type NavigateHow = {
46
54
  };
47
55
  export type FlagsState = {
48
56
  overrides?: FlagOverrides;
57
+ /** Where the visitor stands in the space's gradual rollouts, as the server that drew the page answered them. */
58
+ rollout?: RolloutBuckets;
49
59
  /** Each declared flag's answer and the layer that gave it — what the dev tools show. The values alone are the
50
60
  * `flags` source. */
51
61
  resolved?: Record<string, FlagResolution>;
52
62
  };
63
+ /**
64
+ * The A/B tests of this render. Top-level for the reason `flags` is: the server's answer is written at the root by
65
+ * whoever mounts the SDK, and an element scope owning `runtime` would keep a write from any depth to itself.
66
+ */
67
+ export type ExperimentsState = {
68
+ /** The variants the server drew the page with — the browser hydrates with these, never a draw of its own. */
69
+ server?: ExperimentAssignments;
70
+ /**
71
+ * The variants a tester forced (the dev tools' Experiments tab, an address's `?ab=`), only where debugging is
72
+ * authorized: shown over the visitor's, never kept as theirs.
73
+ */
74
+ qa?: ExperimentAssignments;
75
+ /** Every experiment's variant on this page: the forced ones, the server's, the visitor's kept and any drawn here. */
76
+ assigned?: ExperimentAssignments;
77
+ /**
78
+ * The experiments drawn for this visitor on this page — by the server that drew it, or here: each reported once to
79
+ * the space's analytics as one visitor of the variant drawn.
80
+ */
81
+ drawn?: string[];
82
+ };
53
83
  export type CommonState = {
54
84
  schema: Schema;
55
85
  pageDefinitions: Record<string, Element>;
@@ -76,6 +106,20 @@ export type CommonState = {
76
106
  sources?: Record<string, Source>;
77
107
  rsc?: RscState;
78
108
  flags?: FlagsState;
109
+ experiments?: ExperimentsState;
110
+ /**
111
+ * What the space's audiences know of the visitor — returning, language, device — as the server that drew the page read
112
+ * them from the request. Absent where no server drew it: the browser reads them itself (`browserVisitorFacts`).
113
+ */
114
+ visitor?: VisitorFacts;
115
+ /**
116
+ * The instant this page is drawn at, for what shows or says things by the time (`timeWindow`, `countdown`): the server's, when it drew the page —
117
+ * the page hydrates at it, then follows its own clock — or the one the builder simulates (`simulated`), which it keeps.
118
+ */
119
+ clock?: {
120
+ at: number;
121
+ simulated?: boolean;
122
+ };
79
123
  actions?: ActionsState;
80
124
  /** Where this origin's realtime channels answer — absent in a render with no server, where no channel opens. */
81
125
  realtime?: {
@@ -140,6 +184,11 @@ export type CommonState = {
140
184
  export type RenderSettings = {
141
185
  previewMode?: boolean;
142
186
  debugMode?: boolean;
187
+ /**
188
+ * The space is drawn in the builder's canvas: what a visitor is assigned there is the author's to choose instead —
189
+ * an A/B test shows the variant its settings name (`builderVariant`), and nothing is drawn or kept for a visitor.
190
+ */
191
+ builder?: boolean;
143
192
  renderMode?: RenderMode;
144
193
  environment?: Environment;
145
194
  isHydrating?: boolean;
@@ -313,6 +362,20 @@ export type BuilderState = CommonState & {
313
362
  * Editor-only and never published; a journey on the canvas decides its own visitor.
314
363
  */
315
364
  canvasGuest?: boolean;
365
+ /**
366
+ * What the canvas's visitor is, for the space's audiences, as chosen in the State Manager's Visitor tab — over what
367
+ * the builder says by itself: the device the canvas is sized as, the editor's language, a first visit. Editor-only and
368
+ * never published; the canvas's preview shows the variants this visitor matches.
369
+ */
370
+ visitorSimulation?: Partial<VisitorFacts>;
371
+ /** The instant the canvas's preview is shown at, chosen in the Visitor tab — the editor's clock until then. */
372
+ simulatedAt?: number;
373
+ /**
374
+ * The A/B tests whose variant the canvas's preview shows was picked by hand, its shares set aside. Every other is drawn
375
+ * by them, as a visitor's page draws it — the variant laid in `experiments.qa` — kept across a reload as a visitor's
376
+ * cookie keeps it, drawn again for a new visitor. Editor-only and never published.
377
+ */
378
+ previewPicked?: string[];
316
379
  displayMode: DisplayMode;
317
380
  selector?: string;
318
381
  styleSelector?: string;
@@ -0,0 +1 @@
1
+ export * from './variants';
@@ -0,0 +1 @@
1
+ export { CHOOSE_BY, VARIANTS_TYPE, VARIANT_ITEM_TYPE, builderVariantOf, chooseByOf, isChooseBy, variantItemsOf, variantsElementsOf } from "./variants.mjs";
@@ -0,0 +1,23 @@
1
+ import { Element, Schema } from '../types';
2
+ /**
3
+ * The element that shows each visitor one of its variants — chosen by chance (an A/B test: each variant a share of the
4
+ * visitors, a visitor kept on theirs) or by rules (who the visitor is: the first variant whose rule they match).
5
+ */
6
+ export declare const VARIANTS_TYPE = "variants";
7
+ /** Its parts, in order: each with its share (`weight`) for the chance and its rule (`when`) for the rules. */
8
+ export declare const VARIANT_ITEM_TYPE = "variantItem";
9
+ /** How a `variants` element chooses: at random by the variants' shares, or by the visitor's facts. */
10
+ export declare const CHOOSE_BY: readonly ["chance", "rules"];
11
+ export type ChooseBy = (typeof CHOOSE_BY)[number];
12
+ export declare const isChooseBy: (value: unknown) => value is ChooseBy;
13
+ /** What a `variants` element chooses by: chance, unless it says rules. */
14
+ export declare const chooseByOf: (attributes: Element["attributes"]) => ChooseBy;
15
+ /** A `variants` element's variants, in order: its items of the variant type. */
16
+ export declare const variantItemsOf: (element: Element, flat: Schema["flat"]) => Element[];
17
+ /** The place (from 0) of the variant the builder's canvas shows while editing: one it has, the first otherwise. */
18
+ export declare const builderVariantOf: (attributes: Element["attributes"], count: number) => number;
19
+ /** Every `variants` element of a space — its pages' tree and each component's — with the tree it is in. */
20
+ export declare const variantsElementsOf: (schema: Pick<Schema, "flat"> & Partial<Pick<Schema, "components">>) => {
21
+ element: Element;
22
+ flat: Schema["flat"];
23
+ }[];
@@ -0,0 +1,9 @@
1
+ // src/variants/variants.ts
2
+ var e = "variants", t = "variantItem", n = ["chance", "rules"], r = (e) => n.some((t) => t === e), i = (e) => r(e.chooseBy) ? e.chooseBy : "chance", a = (e, t) => (e.definition.items ?? []).filter((e) => Object.hasOwn(t, e) && t[e].definition.type === "variantItem").map((e) => t[e]), o = (e, t) => {
3
+ let { builderVariant: n } = e;
4
+ return typeof n == "number" && Number.isInteger(n) && n >= 0 && n < t ? n : 0;
5
+ }, s = (t) => [t.flat, ...Object.values(t.components ?? {}).map((e) => e.flat)].flatMap((t) => Object.values(t).filter((t) => t.definition.type === e).map((e) => ({
6
+ element: e,
7
+ flat: t
8
+ })));
9
+ export { n as CHOOSE_BY, e as VARIANTS_TYPE, t as VARIANT_ITEM_TYPE, o as builderVariantOf, i as chooseByOf, r as isChooseBy, a as variantItemsOf, s as variantsElementsOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-shared",
3
- "version": "0.39.11",
3
+ "version": "0.39.13",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",