@wyndlass/app-sdk 1.2.0 → 1.3.0
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 +28 -2
- package/cli/preview.mjs +7 -3
- package/dist/contract/app-contract.d.ts +9 -1
- package/dist/frames.d.ts +4 -0
- package/dist/frames.js +18 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/preview/frame/frame.js +1 -1
- package/dist/preview/page.js +4 -4
- package/dist/react.d.ts +6 -1
- package/dist/react.js +17 -3
- package/dist/signals.d.ts +17 -0
- package/dist/signals.js +30 -0
- package/package.json +6 -1
- package/skill/wyndlass-app/SKILL.md +2 -0
- package/skill/wyndlass-app/references/contract.md +10 -2
- package/skill/wyndlass-app/references/templates.md +6 -5
- package/templates/react/AGENTS.md +1 -0
- package/templates/vanilla/AGENTS.md +1 -0
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Its controls:
|
|
|
61
61
|
- **The clock:** play, pause, seek, and speeds from 0.25× to 4×.
|
|
62
62
|
- **Enter and exit,** with each preset and how long it lasts, and the app's pages.
|
|
63
63
|
- **Data:** each data source's answer, from samples you can edit in the page. `--data <dir>` reads `<source>.json` there instead (the answer's `data`, or a whole answer). The preview reaches no data service. A source the definition doesn't declare gets no answer, as on a screen.
|
|
64
|
-
- **Tables:** each file in `<dir>/tables/`, or one you add in the page. A file may be CSV, a JSON array of rows, or a snapshot. A CSV's header gives its columns' labels, and their keys are made as Wyndlass makes a table's (`Now serving` is `now_serving`), so a `column` param holds the key it will on screens. A `datatable` param chooses among the tables, a `column` param among the chosen table's columns, and an app with `slots` is bound to the first table.
|
|
64
|
+
- **Tables:** each file in `<dir>/tables/`, or one you add in the page. A file may be CSV, a JSON array of rows, or a snapshot. A CSV's header gives its columns' labels, and their keys are made as Wyndlass makes a table's (`Now serving` is `now_serving`), so a `column` param holds the key it will on screens. A `datatable` param chooses among the tables, a `column` param among the chosen table's columns, and an app with `slots` is bound to the first table. Edit a table's rows in the page, or change its file, and the app gets them as it plays, as a screen gives a table's new version: frozen, and without making the app again. The report says how many times the app was made.
|
|
65
65
|
- **The people at the screen,** for an app that declares the `impressions` sensor: someone arrives, looks, or leaves.
|
|
66
66
|
- **The player's controller,** for what `capabilities.player` allows. The page sends the app the player's events, each one editable. A command the app may give is answered "not applied", and one it may not is refused, as on a screen.
|
|
67
67
|
|
|
@@ -149,6 +149,7 @@ export default class QueueBoard extends WyndlassApp {
|
|
|
149
149
|
- `kept(this, source, params)`, the answer the screen last kept, at once;
|
|
150
150
|
- `image(this, path)`, `snapshot(this, table)`, `controllerOf(this)` and `impressionsOf(this)`;
|
|
151
151
|
- `contextOf(this)`, for the rest.
|
|
152
|
+
- **A table's rows change while the app plays.** A screen gives the app a table's new rows within about a second of the save, without making it again. Read them where you draw: `snapshot()` in `draw()`, `useSnapshot`, or `tableSignal`. Never read them once in `mount()` and keep them. On a screen they are the same object until they change, and frozen: copy rows before you sort or change them.
|
|
152
153
|
- **Helpers:** `fit`, `typographyCss`, `color` and `escape`, and the presets' curves `easingOf`, `cubicBezier` and `staggerTimes`.
|
|
153
154
|
- **Types:**
|
|
154
155
|
- the contract's (`AppContext`, `DataAnswer`, `HookOptions` and the rest);
|
|
@@ -182,10 +183,35 @@ export default reactApp(Board, { css });
|
|
|
182
183
|
- **`useNow(everyMs?)`:** the layout's clock. Without `everyMs`, the component renders again at each of the layout's frames, many times a second. With it, the time is a multiple of `everyMs` (`useNow(1000)`: whole seconds), and the component renders only when that changes. Take the coarsest the app shows. Either way, make formatters (`Intl.DateTimeFormat`, `Intl.NumberFormat`) and other objects with `useMemo`, never in the render. One made in each draw holds memory a screen does not free in time: an app that did so ran a 4 GB screen out of memory within an hour.
|
|
183
184
|
- **`usePaging(count, ms)`:** the page showing now, rendering when it turns. It also tells the host the pages.
|
|
184
185
|
- **`useData(source, params)`:** at once the answer the screen kept, then the service's, asked again every 10 minutes. `error` is set once an ask fails with nothing to show.
|
|
185
|
-
- **`useSnapshot(table)`:** a data table's snapshot,
|
|
186
|
+
- **`useSnapshot(table)`:** a data table's snapshot, as `snapshot` gives it. The component renders when the rows change: when the screen gets a table's new version, or when a binding's rows, chosen on the layout's clock, change. On players before Wyndlass's live rows (WP-0149), which make the app again when a table changes, it renders at every frame, as before.
|
|
186
187
|
|
|
187
188
|
The hooks reach the app's context through the SDK's own module, never through React's tree, so nothing another app could use hangs off the shadow root.
|
|
188
189
|
|
|
190
|
+
## Signals (`@wyndlass/app-sdk/signals`)
|
|
191
|
+
|
|
192
|
+
For an app that updates its DOM when its rows change, rather than at every frame:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { WyndlassApp } from "@wyndlass/app-sdk";
|
|
196
|
+
import { effect, tableSignal } from "@wyndlass/app-sdk/signals";
|
|
197
|
+
|
|
198
|
+
export default class Queue extends WyndlassApp {
|
|
199
|
+
protected mount() {
|
|
200
|
+
const rows = tableSignal(this, String(this.prop("table", "")));
|
|
201
|
+
const number = document.createElement("p");
|
|
202
|
+
this.root.append(number);
|
|
203
|
+
effect(() => { number.textContent = String((rows.value as { rows?: { number?: string }[] } | null)?.rows?.[0]?.number ?? ""); });
|
|
204
|
+
this.ready();
|
|
205
|
+
}
|
|
206
|
+
protected draw() { /* the effect draws */ }
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- **`tableSignal(this, table)`:** a read-only [Preact signal](https://github.com/preactjs/signals) of the table's snapshot. Its value changes when the rows do, and is the same object until then. Make it in `mount()`.
|
|
211
|
+
- **`effect`, `computed`, `batch`, `signal`, `untracked`:** Preact's, from the same copy. Import them from here, not from `@preact/signals-core`: an effect from another copy does not see these signals.
|
|
212
|
+
- **Its own entry,** so an app that doesn't import it doesn't bundle it (about 2 KB gzipped when it does).
|
|
213
|
+
- On players before WP-0149, the signal keeps the rows the app was made with: such a player makes the app again when a table changes.
|
|
214
|
+
|
|
189
215
|
## Limits
|
|
190
216
|
|
|
191
217
|
- The zip: at most 6 MiB, holding only `app.json` (at most 256 KiB) and `app.js` (at most 5 MiB).
|
package/cli/preview.mjs
CHANGED
|
@@ -84,6 +84,10 @@ export async function preview(dir = ".", { port = 5199, data: dataDir, frame = f
|
|
|
84
84
|
await firstBuilt;
|
|
85
85
|
// The definition is not a source esbuild follows.
|
|
86
86
|
const definitionWatch = watch(join(root, "app.json"), () => { version++; tell(); });
|
|
87
|
+
// The data folder's tables (WP-0149): a change is given to the app as it plays, not by drawing it again.
|
|
88
|
+
const tablesDir = dataDir && join(resolve(dataDir), "tables");
|
|
89
|
+
const tablesWatch = tablesDir && existsSync(tablesDir) ? watch(tablesDir, () => { for (const c of clients) c.write("event: tables\ndata: {}\n\n"); }) : null;
|
|
90
|
+
const unwatch = () => { definitionWatch.close(); tablesWatch?.close(); };
|
|
87
91
|
|
|
88
92
|
const server = createServer((req, res) => {
|
|
89
93
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
@@ -113,7 +117,7 @@ export async function preview(dir = ".", { port = 5199, data: dataDir, frame = f
|
|
|
113
117
|
}
|
|
114
118
|
});
|
|
115
119
|
await new Promise((ok, fail) => { server.once("error", fail); server.listen(port, "127.0.0.1", ok); })
|
|
116
|
-
.catch(e => { void builder.dispose();
|
|
120
|
+
.catch(e => { void builder.dispose(); unwatch(); throw new CliError(e.code === "EADDRINUSE" ? `port ${port} is taken: give another with --port` : e.message); });
|
|
117
121
|
const { address, port: bound } = server.address();
|
|
118
122
|
pageOrigin = `http://${address}:${bound}`;
|
|
119
123
|
if (frame) {
|
|
@@ -126,13 +130,13 @@ export async function preview(dir = ".", { port = 5199, data: dataDir, frame = f
|
|
|
126
130
|
.end(readFileSync(join(page, "frame", file)));
|
|
127
131
|
});
|
|
128
132
|
await new Promise((ok, fail) => { frames.once("error", fail); frames.listen(port === 0 ? 0 : port + 1, "127.0.0.1", ok); })
|
|
129
|
-
.catch(async e => { await builder.dispose();
|
|
133
|
+
.catch(async e => { await builder.dispose(); unwatch(); server.close(); throw new CliError(e.code === "EADDRINUSE" ? `port ${port + 1}, for the frames, is taken: give another with --port` : e.message); });
|
|
130
134
|
framesOrigin = `http://127.0.0.1:${frames.address().port}`;
|
|
131
135
|
}
|
|
132
136
|
return {
|
|
133
137
|
url: `http://${address}:${bound}/`, address, port: bound, frames: framesOrigin || null,
|
|
134
138
|
async close() {
|
|
135
|
-
|
|
139
|
+
unwatch();
|
|
136
140
|
if (frames) await new Promise(r => frames.close(r));
|
|
137
141
|
for (const c of clients) c.end();
|
|
138
142
|
await builder.dispose();
|
|
@@ -178,9 +178,17 @@ export interface AppContext {
|
|
|
178
178
|
binding?: TableBinding;
|
|
179
179
|
/**
|
|
180
180
|
* A data table's snapshot, as the manifest carries it; null without one. The bound table's comes with only the rows the
|
|
181
|
-
* binding chooses, chosen at each read on the layout's clock with the screen's facts (WP-0137).
|
|
181
|
+
* binding chooses, chosen at each read on the layout's clock with the screen's facts (WP-0137). On a screen it is the same
|
|
182
|
+
* object until the table's next version, and frozen (WP-0149): copy rows before changing them.
|
|
182
183
|
*/
|
|
183
184
|
snapshot(table: string): unknown | null;
|
|
185
|
+
/**
|
|
186
|
+
* Tells the app that a table's snapshot changed while it plays (WP-0149): the listener gets the table's id once
|
|
187
|
+
* snapshot() gives the new rows, before the next frame. Props with tokens are filled again by then. Returns what stops
|
|
188
|
+
* it; the host stops them all when the app goes. Absent where rows never change while an app runs, and on players
|
|
189
|
+
* older than WP-0149 part a, so apps check for it.
|
|
190
|
+
*/
|
|
191
|
+
onSnapshot?(listener: (table: string) => void): () => void;
|
|
184
192
|
/** The app's view of the player's controller, on screens (WP-0100); absent in the designer and previews. */
|
|
185
193
|
controller?: AppController;
|
|
186
194
|
/**
|
package/dist/frames.d.ts
ADDED
package/dist/frames.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// What the SDK's own modules run at each of an app's frames, just before it draws (WP-0149): the signals' reads. Not one of
|
|
2
|
+
// the package's exports, so it is no part of what an app may call.
|
|
3
|
+
const work = new WeakMap();
|
|
4
|
+
/** Runs `f` at each frame the app draws, before its draw; returns what stops it. */
|
|
5
|
+
export function eachFrame(app, f) {
|
|
6
|
+
let set = work.get(app);
|
|
7
|
+
if (!set)
|
|
8
|
+
work.set(app, set = new Set());
|
|
9
|
+
set.add(f);
|
|
10
|
+
return () => { set.delete(f); };
|
|
11
|
+
}
|
|
12
|
+
/** The app's frame: what runs at it, in turn. */
|
|
13
|
+
export function atFrame(app) {
|
|
14
|
+
const set = work.get(app);
|
|
15
|
+
if (set)
|
|
16
|
+
for (const f of [...set])
|
|
17
|
+
f();
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,9 @@ export declare function image(app: WyndlassApp, path: string): Promise<string>;
|
|
|
36
36
|
/**
|
|
37
37
|
* A data table's snapshot as the manifest carries it: a table the layout names, in a datatable param or in the element's
|
|
38
38
|
* binding, which needs no binding of its own; the bound table's with only the rows the binding chooses. Null when the
|
|
39
|
-
* screen has no snapshot of that table.
|
|
39
|
+
* screen has no snapshot of that table. On a screen it is the same object until the table's rows change, and frozen: copy
|
|
40
|
+
* rows before changing them. Read it where it is drawn (draw(), useSnapshot or tableSignal), never once at mount: a
|
|
41
|
+
* screen gives the app a table's new rows while it plays (WP-0149).
|
|
40
42
|
*/
|
|
41
43
|
export declare function snapshot(app: WyndlassApp, table: string): unknown | null;
|
|
42
44
|
/** The app's view of the player's controller (ADR 0050), on screens, as its definition's `capabilities.player` allows. */
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var _WyndlassApp_instances, _WyndlassApp_said, _WyndlassApp_hooks, _WyndlassApp_
|
|
|
24
24
|
*/
|
|
25
25
|
import { ATTACH } from "./contract/app-contract.js";
|
|
26
26
|
import { cubicBezier, easingOf, staggerTimes } from "./easing.js";
|
|
27
|
+
import { atFrame } from "./frames.js";
|
|
27
28
|
export { ATTACH };
|
|
28
29
|
export { cubicBezier, easingOf, staggerTimes } from "./easing.js";
|
|
29
30
|
/** The contexts handed over through ATTACH, where no other script on the page can reach them. */
|
|
@@ -50,7 +51,9 @@ export function image(app, path) {
|
|
|
50
51
|
/**
|
|
51
52
|
* A data table's snapshot as the manifest carries it: a table the layout names, in a datatable param or in the element's
|
|
52
53
|
* binding, which needs no binding of its own; the bound table's with only the rows the binding chooses. Null when the
|
|
53
|
-
* screen has no snapshot of that table.
|
|
54
|
+
* screen has no snapshot of that table. On a screen it is the same object until the table's rows change, and frozen: copy
|
|
55
|
+
* rows before changing them. Read it where it is drawn (draw(), useSnapshot or tableSignal), never once at mount: a
|
|
56
|
+
* screen gives the app a table's new rows while it plays (WP-0149).
|
|
54
57
|
*/
|
|
55
58
|
export function snapshot(app, table) {
|
|
56
59
|
return contextOf(app)?.snapshot(table) ?? null;
|
|
@@ -125,6 +128,7 @@ export class WyndlassApp extends HTMLElement {
|
|
|
125
128
|
update(epochMs) {
|
|
126
129
|
if (!__classPrivateFieldGet(this, _WyndlassApp_mounted, "f"))
|
|
127
130
|
return;
|
|
131
|
+
atFrame(this);
|
|
128
132
|
this.draw(epochMs);
|
|
129
133
|
__classPrivateFieldGet(this, _WyndlassApp_instances, "m", _WyndlassApp_present).call(this, epochMs);
|
|
130
134
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @wyndlass/app-sdk's preview: player-core's app frame, compiled. MIT, (c) Northwynd Labs LLC. */
|
|
2
|
-
"use strict";(()=>{var pt=Object.defineProperty;var lt=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>lt(e,typeof t!="symbol"?t+"":t,n);var ve={apiVersion:2,properties:[{name:"device",description:"What the device is: id, type, shell and versions, model, resolution and orientation. Fixed while the player runs."},{name:"mode",description:"Where player-core runs: player, preview (in the CMS) or designer. In preview and the designer, commands change nothing."},{name:"timeZone",description:"The player's time zone (IANA), from the host.",event:"time.changed"},{name:"locale",description:"The player's locale (BCP 47), from the host."},{name:"connection",description:"Whether the player is connected to Wyndlass.",event:"connection.changed"},{name:"state",description:"starting, playing, paused, stopped (the standby screen), idle (nothing to play) or error.",event:"state.changed"},{name:"held",description:"A remote pause or stop in effect, by whom and since when; absent when none.",event:"state.changed"},{name:"content",description:"The manifest playing, when it was issued and switched to; absent when there is none.",event:"content.updated"},{name:"now",description:"What each zone shows: the item, its blob and content type, when it started, and its duration and position when known.",event:"item.start"},{name:"audio",description:"The player's volume (0 to 100) and whether it is muted; only when the host can set them.",event:"audio.changed"},{name:"display",description:"The display's power and brightness; only when the host can report them.",event:"display.changed"},{name:"capabilities",description:"What the host can do: audio, display power, display brightness."}],events:[{name:"state.changed",description:"The player's state changed (playing, paused, stopped, idle, error), and who changed it."},{name:"content.updated",description:"A new manifest was switched to."},{name:"item.start",description:"An item started in a zone (source start)."},{name:"item.end",description:"An item ended in a zone (source end): completed, skipped, stopped, error, replaced by new content, or finished by its app."},{name:"item.error",description:"An item could not be shown."},{name:"connection.changed",description:"The player connected to Wyndlass or lost its connection."},{name:"audio.changed",description:"The volume or mute changed, and who changed it."},{name:"display.changed",description:"The display's power or brightness changed, and who changed it."},{name:"time.changed",description:"The clock was adjusted or the time zone changed."},{name:"app.command",description:"A command for apps on the screen (apps.sendCommand); an app reacts if it knows the name."},{name:"app.failed",description:"An app on the screen could not run, or misbehaved (WP-0100): its bundle did not load, it was not an app, it needs a newer player, it kept throwing and was stopped, or it was late or overran a clip."},{name:"app.held",description:"An app version was held back on this screen until the next manifest, after the page stopped answering twice in an hour while it was on screen (WP-0100)."}],commands:[{name:"player.status",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/status",description:"Everything about the player now: device, mode, time zone, locale, connection, state (and any hold), the content playing, what each zone shows, audio, display and what the host can do. Changes nothing.",idempotent:!0},{name:"player.events",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/events",result:"player-api-results.schema.json#/$defs/events",description:"The player's recent events (the last 200), oldest first, after a sequence number: state changes, content updates, item starts and ends, errors, connection, audio, display and time. Pass next as after to poll for more. Changes nothing.",idempotent:!0},{name:"time.now",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/timeNow",description:"The player's current time, its time zone and UTC offset, and whether its clock is synchronized. Changes nothing.",idempotent:!0},{name:"player.play",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Resumes or starts playback on the screen. From a remote caller it also ends a remote pause or stop.",idempotent:!0},{name:"player.pause",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Freezes the screen on what it shows now: the loop's timer and any media stop where they are. From a remote caller it holds until a remote player.play or a restart; apps cannot resume it, and new content arrives paused.",idempotent:!0},{name:"player.stop",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Stops playback and shows the standby screen (black, display on). From a remote caller it holds until a remote player.play or a restart; apps cannot restart it, and new content arrives stopped.",idempotent:!0},{name:"player.next",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Skips to the next item in a zone (main by default); the current item ends as skipped."},{name:"player.previous",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Goes back to the previous item in a zone (main by default); the current item ends as skipped."},{name:"player.playItem",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/playItem",result:"player-api-results.schema.json#/$defs/now",description:"Shows a given item of the content playing now in a zone (main by default), then continues the loop from it. Refused for an item the playing manifest does not have."},{name:"audio.setVolume",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setVolume",result:"player-api-results.schema.json#/$defs/audio",description:"Sets the player's volume, 0 to 100. Only on players whose host can set it to a level.",needs:"audio.volume",idempotent:!0},{name:"audio.setMuted",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setMuted",result:"player-api-results.schema.json#/$defs/audio",description:"Mutes or unmutes the player. Only on players whose host can.",needs:"audio",idempotent:!0},{name:"display.setPower",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setPower",result:"player-api-results.schema.json#/$defs/display",description:"Turns the display on or to standby. Only on players whose host can. Standby blanks the screen until it is turned on.",needs:"display.power",idempotent:!0},{name:"display.setBrightness",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setBrightness",result:"player-api-results.schema.json#/$defs/display",description:"Sets the display's brightness, 0 to 100. Only on players whose host can.",needs:"display.brightness",idempotent:!0},{name:"apps.sendCommand",access:"control",apps:"none",remote:!0,params:"player-api-params.schema.json#/$defs/sendCommand",result:"player-api-results.schema.json#/$defs/delivered",description:"Sends a named command, with an optional argument, to the apps on the screen; an app that knows the name reacts. Returns how many apps listen."},{name:"app.finish",access:"control",apps:"read",remote:!1,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/none",description:"An app ends its own slot now: its item ends as finished and the loop moves on. Apps only; not a tool."}],host:[{name:"host.describe",kind:"request",description:"What the device is, its time zone, locale, connection and capabilities.",result:"player-api-host.schema.json#/$defs/describeResult"},{name:"host.time",kind:"request",description:"The host's time and time zone.",result:"player-api-common.schema.json#/$defs/timeNow"},{name:"host.getAudio",kind:"request",description:"The player's volume and mute.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.setAudio",kind:"request",description:"Sets the volume, the mute or both; answers the audio after.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.getDisplay",kind:"request",description:"The display's power and brightness.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.setDisplay",kind:"request",description:"Sets the display's power, brightness or both; answers the display after.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.adRequest",kind:"request",description:"Asks Wyndlass's ad broker for one slot of a break over the host's NATS connection (WP-0075); the result is the broker's ad-decision (ad-decision.schema.json). Only a host whose describe says ads is asked."},{name:"host.mediaPrepare",kind:"request",description:"Lays a video out behind the page and prepares it to its first frame; host.mediaState says when (ADR 0055)."},{name:"host.mediaShow",kind:"request",description:"Shows and hides prepared videos; replies once its layer has changed."},{name:"host.mediaControl",kind:"request",description:"Plays, pauses or seeks a video, or asks for its position."},{name:"host.mediaRelease",kind:"request",description:"Removes a video and frees its decoder."},{name:"host.reply",kind:"reply",description:"The host's answer to a request: result or error (unsupported, failed)."},{name:"host.connection",kind:"event",description:"The connection to Wyndlass changed."},{name:"host.timeChanged",kind:"event",description:"The clock was adjusted or the time zone changed."},{name:"host.audioChanged",kind:"event",description:"The volume or mute changed outside the player."},{name:"host.displayChanged",kind:"event",description:"The display changed outside the player."},{name:"host.mediaState",kind:"event",description:"A video was prepared, started, ended or failed, or its position was asked for."},{name:"host.presence",kind:"event",description:"What one of the host's sensors sees now: the presences in view, with random ids that never leave the page (WP-0105)."},{name:"host.sensing",kind:"event",description:"The site's sensing mode as the host applies it, and its sensors (WP-0105)."},{name:"host.serialPorts",kind:"event",description:"The host's sensor controller ports, and which are open (WP-0043)."},{name:"host.serialLine",kind:"event",description:"One line from a sensor controller, as it arrived (WP-0043)."},{name:"host.serialWrite",kind:"request",description:"Writes lines to a sensor controller, a gap apart; replies once written (WP-0043)."},{name:"host.bleWatch",kind:"request",description:"What the page listens for: beacons' iBeacon UUIDs, Eddystone namespaces and addresses; replies once the scan follows it. Sent only to a host that has sent host.bleState (WP-0044)."},{name:"host.bleAdverts",kind:"event",description:"Beacon frames that match the watch, at most four a second of each kind from each beacon (WP-0044)."},{name:"host.bleState",kind:"event",description:"The host's Bluetooth scanner: scanning, idle, off, refused, missing or failed; sent only by a host that has one (WP-0044)."},{name:"host.gpioPins",kind:"event",description:"The GPIO pins the host reads, with their values (WP-0044)."},{name:"host.gpioEdge",kind:"event",description:"A GPIO pin changed (WP-0044)."},{name:"host.mcp",kind:"relay",description:"An MCP message from ctl.dev.{deviceId}, for player-core to answer."},{name:"core.ready",kind:"core",description:"player-core is ready to answer host.mcp; until then the shell answers -32002 itself."},{name:"core.mcpReply",kind:"core",description:"player-core's answer to a host.mcp, for the shell to send back."},{name:"core.sensors",kind:"core",description:"The page's sensor controllers, channels and inputs, and the beacons it hears, whenever they change, for the heartbeat and sensors.recent (WP-0043, WP-0044)."}]};var ke=Symbol.for("wyndlass.app.attach");var Re=Reflect.apply,re=Object.getOwnPropertyDescriptor,V=Object.getPrototypeOf,y=globalThis,a=(e,t,n)=>Re(e,t,n),v=(e,t)=>e?re(e,t)?.get:void 0,oe=(e,t)=>e?re(e,t)?.set:void 0,f=e=>y[e]?.prototype,Ce=(e,t,n)=>Re(e,t,n);var Cn=Date.now,Ln=new TextEncoder,On=new TextDecoder,jn=TextEncoder.prototype.encode,In=TextDecoder.prototype.decode;var Dn=v(V(Uint8Array.prototype),"length");var ut=Uint8Array,mt=e=>new ut(e),ft=[];for(let e=0;e<256;e++)ft[e]=(e<16?"0":"")+e.toString(16);var ht=Object.create(null);for(let e=0;e<64;e++)ht["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[e]]=e;var Ae=y.crypto?.subtle,se=Ae?V(Ae):void 0,ne=y.crypto,gt=ne?V(ne).getRandomValues:void 0,Hn=se?.digest,Bn=se?.importKey,Wn=se?.sign;var Le=e=>a(gt,ne,[mt(e)]),Un={setTimeout:y.setTimeout,clearTimeout:y.clearTimeout,setInterval:y.setInterval,clearInterval:y.clearInterval};var qn=y.fetch;var B=f("MessagePort"),zn=B&&B.postMessage,Zn=oe(B,"onmessage"),_n=B&&B.start,ie=f("MessageEvent"),Kn=v(ie,"data"),Vn=v(ie,"ports"),Gn=v(ie,"source");var Oe=f("EventTarget"),Jn=Oe?.addEventListener,Yn=Oe?.removeEventListener;var Qn=y.Worker,Z=f("Worker"),Xn=Z&&Z.postMessage,er=oe(Z,"onmessage"),tr=oe(Z,"onerror");var xe=y.Blob,_=y.URL,Se=_?.createObjectURL,yt=_?.revokeObjectURL,ae=xe&&Se?{make:(e,t)=>a(Se,_,[new xe(e,{type:t})]),revoke:e=>a(yt,_,[e])}:void 0,H=y.customElements,de=H?V(H):void 0,bt=de?.define,wt=de?.get,pe=H&&de?{define:(e,t)=>a(bt,H,[e,t]),get:e=>a(wt,H,[e])}:void 0,vt=y.document,K=f("Document"),kt=K?.createElement,nr=K?.createElementNS,At=WeakSet.prototype.add,rr=WeakSet.prototype.has,xt=new WeakSet;var St=(e,t)=>(a(At,e,[t]),t);function je(e){return St(xt,a(kt,vt,[e]))}var W=f("Node"),le=f("Element"),G=f("HTMLElement"),j=e=>v(W,e),Ee=j("parentNode"),Et=j("firstChild"),Tt=j("lastChild"),Mt=j("nextSibling"),Ft=j("nodeType"),Pt=j("childNodes"),$t=v(le,"localName"),Nt=W?.appendChild,Rt=W?.insertBefore,Ct=W?.removeChild,C=le,Lt=C?.getAttribute,Ot=C?.getAttributeNames,jt=C?.setAttribute,It=C?.removeAttribute,Dt=C?.matches,Ht=C?.attachShadow,Bt=C?.querySelectorAll,Wt=f("HTMLDialogElement")?.close,Ut=v(f("NodeList"),"length"),qt=f("NodeList")?.item,J=f("MutationRecord"),zt=v(J,"type"),Zt=v(J,"target"),_t=v(J,"addedNodes"),Kt=v(J,"removedNodes"),Te=y.MutationObserver,Vt=f("MutationObserver")?.observe,Ie=K?re(K,"adoptedStyleSheets"):void 0,Me=Ie?.get,Fe=Ie?.set,Gt=y.requestAnimationFrame,Pe=v(G,"style"),Y=f("CSSStyleDeclaration"),Jt=Y?.getPropertyValue,Yt=Y?.getPropertyPriority,Qt=Y?.setProperty,$e=G?.showPopover,Ne=G?.hidePopover,Xt=v(f("Event"),"target"),en=f("Event")?.stopImmediatePropagation,z=e=>{let t=[];for(let n=0,r=a(Ut,e,[]);n<r;n++)t[n]=a(qt,e,[n]);return t},De=Te&&W&&le&&G&&Y?{parent:e=>a(Ee,e,[]),first:e=>a(Et,e,[]),last:e=>a(Tt,e,[]),next:e=>a(Mt,e,[]),isElement:e=>a(Ft,e,[])===1,name:e=>a($t,e,[]),children:e=>z(a(Pt,e,[])),append:(e,t)=>a(Nt,e,[t]),insert:(e,t,n)=>a(Rt,e,[t,n]),remove:e=>{let t=a(Ee,e,[]);t&&a(Ct,t,[e])},attribute:(e,t)=>a(Lt,e,[t]),attributes:e=>a(Ot,e,[]),setAttribute:(e,t,n)=>a(jt,e,[t,n]),removeAttribute:(e,t)=>a(It,e,[t]),matches:(e,t)=>a(Dt,e,[t]),all:(e,t)=>z(a(Bt,e,[t])),closeDialog:e=>a(Wt,e,[]),shadow:e=>a(Ht,e,[{mode:"closed"}]),style:(e,t)=>{let n=a(Pe,e,[]);return[a(Jt,n,[t]),a(Yt,n,[t])]},setStyle:(e,t,n,r="")=>a(Qt,a(Pe,e,[]),[t,n,r]),observer:e=>new Te(e),observe:(e,t,n)=>a(Vt,e,[t,n]),record:e=>({type:a(zt,e,[]),target:a(Zt,e,[]),added:z(a(_t,e,[])),removed:z(a(Kt,e,[]))}),adopted:Me&&Fe?{count:e=>a(Me,e,[]).length,clear:e=>a(Fe,e,[[]])}:void 0,frame:e=>a(Gt,globalThis,[e]),popover:$e&&Ne?{show:e=>a($e,e,[]),hide:e=>a(Ne,e,[])}:void 0,target:e=>a(Xt,e,[]),stop:e=>a(en,e,[])}:void 0;var M=class extends Error{constructor(n,r){super(`the app could not run (${n})`);m(this,"reason",n);m(this,"error",r)}};function L(e){try{let t=e instanceof Error?e.name:void 0;return typeof t=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(t)?t:void 0}catch{return}}function U(e){let t=e?.id;if(typeof t!="string"||t==="")return!0;for(let n=0;n<He.length;n++)if(t[n]!==He[n])return!1;return!0}var He="com.wyndlass.";function tn(e=typeof navigator>"u"?"":navigator.userAgent){let t=/Chrom(?:e|ium)\/(\d+)/.exec(e);return t?Number(t[1]):void 0}function Be(e,t=ve.apiVersion,n=tn()){return!(e?.playerApi!==void 0&&e.playerApi>t||e?.webView!==void 0&&n!==void 0&&e.webView>n)}function nn(e){let t;try{t=e.paging?.()}catch{return null}let n=t;return n&&Number.isInteger(n.count)&&n.count>1&&typeof n.ms=="number"&&n.ms>0?{count:n.count,ms:n.ms}:null}var ce=new Map;function rn(){let e=Le(8),t="";for(let n=0;n<8;n++)t+=on[e[n]%26];return t}var on="abcdefghijklmnopqrstuvwxyz",sn=0;function We(e,t,n){let r=ce.get(e);if(!r){let o=ae.make([t],"text/javascript");r=import(o).then(s=>an(s,n),s=>{throw s instanceof M?s:new M("load",L(s))}).finally(()=>ae.revoke(o)),ce.set(e,r),r.catch(()=>ce.delete(e))}return r}function an(e,t){let n=e.default;if(typeof n=="function"&&n.prototype instanceof HTMLElement){let r=n.prototype[ke];if(typeof r!="function")throw new M("shape");let o=class extends n{},s=`${t?.element??"wl-app"}-${rn()}${++sn}`;try{pe.define(s,o)}catch(c){throw new M("shape",L(c))}return{tag:s,shape:"class",attach:(c,k)=>{Ce(r,c,[k])}}}if(U(t)&&typeof e.element=="string"&&pe.get(e.element))return{tag:e.element,shape:"legacy"};throw new M("shape")}var dn=3,pn=6e4,Q=class{constructor(t,n){m(this,"element",t);m(this,"o",n);m(this,"faults",[]);m(this,"halted",!1)}get stopped(){return this.halted}has(t){try{return!this.halted&&typeof this.element[t]=="function"}catch{return!1}}update(t){this.halted||this.run(()=>this.element.update?.(t))}reset(){this.halted||this.run(()=>this.element.reset?.())}paging(){return this.halted?null:nn(this.element)}hook(t,n){if(this.halted)return Promise.resolve();let r;try{r=this.element[t]?.(n)}catch(o){return this.fault(o),Promise.resolve()}return Promise.resolve(r).then(()=>{},o=>this.fault(o))}stop(t){if(!this.halted){this.halted=!0;try{this.element.remove()}catch{}this.o.dispose?.(),this.o.onStop(t)}}dispose(){this.o.dispose?.()}run(t){try{t()}catch(n){this.fault(n)}}fault(t){let n=(this.o.now??Date.now)();this.faults=this.faults.filter(r=>n-r<pn),this.faults.push(n),this.faults.length>=dn&&this.stop(L(t))}},dr=24*3600*1e3;var X="wyndlass.frame";function ze(e,t){return!!e&&(e.apps?e.apps(t):!U(t))}var ln=new Set(["load","shape","unsupported","error","late","overran"]),Ue=50,qe=250,ue=class{constructor(t,n,r,o){m(this,"frame",t);m(this,"port",n);m(this,"o",o);m(this,"halted",!1);m(this,"pages");m(this,"hooks");m(this,"pending",new Map);m(this,"next",0);m(this,"told");m(this,"last");m(this,"quiet");this.hooks=new Set(r.hooks),this.pages=r.paging}get stopped(){return this.halted}has(t){return!this.halted&&this.hooks.has(t)}paging(){return this.halted?null:this.pages}update(t){if(this.halted)return;let n=performance.now(),r=this.last;this.last={t,at:n};let o=this.told;if(o&&(o.running?Math.abs(t-(o.t+(n-o.at)))<=Ue:t===o.t)){o.running&&this.watch();return}let s=!!r&&n-r.at<qe&&t>r.t&&Math.abs(t-r.t-(n-r.at))<=Ue;this.told={t,at:n,running:s},this.post({type:"clock",t,running:s}),s&&this.watch()}reset(){this.halted||this.post({type:"reset"})}hook(t,n){if(this.halted)return Promise.resolve();let r=++this.next;return new Promise(o=>{this.pending.set(r,o),this.post({type:"hook",id:r,kind:t,options:n})})}stop(t){this.halted||(this.halted=!0,this.frame.remove(),this.dispose(),this.o.onStop(t))}dispose(){clearTimeout(this.quiet),this.port.close();for(let t of this.pending.values())t();this.pending.clear()}heard(t){t.type==="paging"?this.pages=_e(t.paging):t.type==="hooked"&&typeof t.id=="number"?(this.pending.get(t.id)?.(),this.pending.delete(t.id)):t.type==="stopped"&&this.stop(Ke(t.error))}post(t){try{this.port.postMessage(t)}catch{}}watch(){clearTimeout(this.quiet),this.quiet=setTimeout(()=>{!this.told?.running||!this.last||this.halted||(this.told={...this.last,running:!1},this.post({type:"clock",t:this.last.t,running:!1}))},qe)}};async function Ze(e,t,n,r,o,s,c,k,h,i){let l=e.appInfo??n.info,u;try{u=new URL(h.frames).origin}catch{return i("unsupported")}let p=document.createElement("iframe");p.setAttribute("sandbox","allow-scripts"),p.setAttribute("referrerpolicy","no-referrer"),p.title=l?.id??"app",p.tabIndex=-1,p.dataset.frame=l?.id??"",p.style.cssText="display:block;width:100%;height:100%;border:0;pointer-events:none;background:transparent;color-scheme:normal";let b=new Promise(S=>{p.addEventListener("load",()=>S(!0),{once:!0}),setTimeout(()=>S(!1),s)});p.src=`${u}/`,t.append(p);let x=(S,w)=>(p.remove(),i(S,w));if(!await b||!p.contentWindow)return x("load");let{port1:A,port2:q}=new MessageChannel,N={type:"init",element:{id:e.id,type:"app",app:e.app,props:e.props??{},...e.binding?{binding:e.binding}:{},...e.appInfo?{appInfo:e.appInfo}:{}},bundle:{hash:n.hash,bytes:n.bytes.slice(),...n.info?{info:n.info}:{}},...r.place?{place:r.place}:{},screen:r.screen??null,timeZone:r.timeZone,locale:r.locale,preview:!!r.preview,clock:{t:o.now(),running:!1,startedAt:o.startedAt()},fonts:mn(e.props??{},h),snapshots:fn(e,r),deadlineMs:s};return new Promise(S=>{let w,P=!1,E=I=>{P||(P=!0,clearTimeout(T),S(I))},T=setTimeout(()=>{w?(E({app:w,late:!0}),w.update(o.now())):(A.close(),E(x("load")))},s+1e3),R=!1;A.onmessage=I=>{let d=I.data;if(!(!d||typeof d!="object")){if(d.type==="ask"){R&&cn(d,r,A);return}if(w){d.type==="ready"?(E({app:w,late:d.late===!0}),w.update(o.now())):w.heard(d);return}d.type==="hello"&&!R?(R=!0,A.postMessage(N,[N.bundle.bytes.buffer])):d.type==="made"&&Array.isArray(d.hooks)?(w=new ue(p,A,{type:"made",hooks:d.hooks.filter(g=>g==="enter"||g==="exit"),paging:_e(d.paging)},{onStop:k}),c(w)):d.type==="failed"&&(A.close(),E(x(ln.has(d.reason)?d.reason:"error",Ke(d.error))))}},p.contentWindow.postMessage({type:X},"*",[q])})}async function cn(e,t,n){if(typeof e.id!="number")return;let r=(o,s=[])=>{try{n.postMessage(o,s)}catch{}};try{if(!t.data)throw new Error("no data service");if(e.what==="data"&&typeof e.source=="string")r({type:"answer",id:e.id,value:await t.data.get(e.source,un(e.params))});else if(e.what==="image"&&typeof e.path=="string"){let o=await t.data.imageBlob(e.path),s=new Uint8Array(await o.arrayBuffer());r({type:"answer",id:e.id,value:{bytes:s,type:o.type}},[s.buffer])}else throw new TypeError("not a question")}catch(o){r({type:"answer",id:e.id,error:L(o)??"Error"})}}function un(e){let t={};if(e&&typeof e=="object")for(let[n,r]of Object.entries(e))(typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&(t[n]=r);return t}function _e(e){let t=e;return t&&Number.isInteger(t.count)&&t.count>1&&typeof t.ms=="number"&&t.ms>0?{count:t.count,ms:t.ms}:null}function Ke(e){return typeof e=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(e)?e:void 0}function mn(e,t){let n=new Set;for(let o of Object.values(e)){let s=o?.family;o&&typeof o=="object"&&typeof s=="string"&&n.add(s)}let r=[];for(let o of t.fonts??[]){let s=n.has(o.family)?t.font?.(o.blob):void 0;s&&r.push({family:o.family,weight:o.weight,style:o.style,blob:o.blob,bytes:s.slice()})}return r}function fn(e,t){let n=new Set;e.binding?.table&&n.add(e.binding.table);for(let o of Object.values(e.props??{}))typeof o=="string"&&/^tbl_[0-9a-z]{26}$/.test(o)&&n.add(o);let r={};for(let o of n){let s=t.snapshot?.(o);s&&(r[o]=s)}return r}function Ve(e){let t=De?.setStyle??((n,r,o,s)=>n.style.setProperty(r,o,s));t(e,"contain","strict","important"),t(e,"overflow","clip","important")}var hn=["name","type","tags","location","site","district","region","organization","path","timeZone"],gn=["text","date","currency","truncate"],Ge={site:"SITE",district:"DISTRICT",region:"REGION",organization:"ORGANIZATION"};function ee(e,t,n,r){if(!e)return n==="timeZone"&&t?t:void 0;if(n==="fields")return r&&e.fields?.[r]||void 0;let o=e.path??[];switch(n){case"name":return e.name||void 0;case"type":return e.type||void 0;case"tags":return e.tags?.length?e.tags.join(", "):void 0;case"location":return o.at(-1)?.name;case"path":return o.length?o.map(s=>s.name).join(" \u203A "):void 0;case"timeZone":return t||void 0;default:return Ge[n]?[...o].reverse().find(s=>s.kind===Ge[n])?.name:void 0}}function yn(e,t){if(e==null||e==="")return;let n=String(e);if(t==="currency"){let r=Number(e);return Number.isFinite(r)?r.toFixed(2):n}if(t==="date"){let r=Date.parse(n);return Number.isNaN(r)?n:new Date(r).toISOString().slice(0,10)}return t==="truncate"&&n.length>40?n.slice(0,39)+"\u2026":n}function Je(e,t){return(e.source==="screen"?ee(t.screen,t.timeZone,e.field,e.key):yn(t.tables?.[e.table]?.rows?.[e.row??0]?.[e.column],e.format))??e.fallback??""}function bn(e){let t=/^\s*(?:screen\.(fields\.[a-z][A-Za-z0-9]{0,31}|[A-Za-z]+)|table\.([A-Za-z0-9_-]+)\[(\d+)\](?:\.([A-Za-z0-9_]+)|\["((?:[^"\\]|\\.)*)"\]))\s*((?:\|\s*(?:[a-z]+|"(?:[^"\\]|\\.)*")\s*)*)$/.exec(e);if(!t)return null;let n=[...t[6].matchAll(/\|\s*([a-z]+|"((?:[^"\\]|\\.)*)")/g)],r=n.find(s=>s[1].startsWith('"'))?.[2]?.replace(/\\(.)/g,"$1"),o=n.find(s=>!s[1].startsWith('"'))?.[1];return t[1]!==void 0?o?null:t[1].startsWith("fields.")?{source:"screen",field:"fields",key:t[1].slice(7),...r!==void 0?{fallback:r}:{}}:hn.includes(t[1])?{source:"screen",field:t[1],...r!==void 0?{fallback:r}:{}}:null:o&&!gn.includes(o)?null:{source:"table",table:t[2],row:Number(t[3]),column:t[4]??t[5].replace(/\\(.)/g,"$1"),...o?{format:o}:{},...r!==void 0?{fallback:r}:{}}}function Ye(e,t){return e.replace(/\{{2}([^{}]*)\}{2}/g,(n,r)=>{let o=bn(r);return o?Je(o,t):n})}function Qe(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,typeof r=="string"?Ye(r,t):r]))}var me=e=>e==null||e==="";function et(e,t,n,r,o,s){return wn(e,t,n,r,{now:o,timeZone:s})}function wn(e,t,n,r,o){if(n===null&&(t==="eq"||t==="ne"))return t==="eq"?me(e):!me(e);if(me(e)||n===null||n===void 0)return!1;switch(r){case"number":case"currency":{let s=Number(e),c=Number(n);return typeof n!="boolean"&&n!==""&&Number.isFinite(s)&&Number.isFinite(c)&&fe(t,s-c)}case"boolean":{let s=n===!0||n==="true"?!0:n===!1||n==="false"?!1:void 0;return s!==void 0&&(t==="eq"?e===s:t==="ne"?e!==s:!1)}case"date":{let s=n==="today"?vn(o.now,o.timeZone).date:String(n),c=String(e).slice(0,10);return/^\d{4}-\d{2}-\d{2}$/.test(s)&&fe(t,c<s?-1:c>s?1:0)}case"datetime":{let s=Date.parse(String(e)),c=n==="now"?o.now:Date.parse(String(n));return!Number.isNaN(s)&&!Number.isNaN(c)&&fe(t,s-c)}default:{let s=String(e).toLowerCase(),c=String(n).toLowerCase();return t==="eq"?s===c:t==="ne"?s!==c:t==="contains"?s.includes(c):!1}}}function fe(e,t){switch(e){case"eq":return t===0;case"ne":return t!==0;case"lt":return t<0;case"lte":return t<=0;case"gt":return t>0;case"gte":return t>=0;default:return!1}}var Xe=new Map;function vn(e,t){let n=Xe.get(t);n||(n=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",weekday:"short"}),Xe.set(t,n));let r=Object.fromEntries(n.formatToParts(new Date(e)).map(o=>[o.type,o.value]));return{date:`${r.year}-${r.month}-${r.day}`,minute:Number(r.hour)%24*60+Number(r.minute),day:String(r.weekday).slice(0,3).toLowerCase()}}var tt=e=>!!(e?.filter?.length||e?.sort||e?.limit),kn=e=>e==null||e==="";function An(e,t){if(!kn(e))switch(t){case"number":case"currency":{let n=Number(e);return Number.isFinite(n)?n:void 0}case"datetime":{let n=Date.parse(String(e));return Number.isNaN(n)?void 0:n}case"boolean":return e===!0||String(e).toLowerCase()==="true"?1:0;case"date":return String(e).slice(0,10);default:return String(e).toLowerCase()}}function xn(e,t){let n=Array.from(e),r=Array.from(t);for(let o=0;o<n.length&&o<r.length;o++){let s=n[o].codePointAt(0)-r[o].codePointAt(0);if(s!==0)return s}return n.length-r.length}function Sn(e,t,n,r,o){let s=e,c=Array.isArray(s?.rows)?s.rows:[],k=Array.isArray(s?.columns)?s.columns:void 0,h=i=>k?.find(l=>l.key===i)?.type??"text";for(let i of t.filter??[]){if(k&&!k.some(p=>p.key===i.column))return[];let l=i.value;if(l!==null&&typeof l=="object"){let p=l;if(l=ee(n,r,p.screen,p.key),l===void 0)return[]}let u=h(i.column);c=c.filter(p=>et(p[i.column],i.op,l,u,o,r))}if(t.sort){let{column:i}=t.sort,l=h(i),u=t.sort.order==="desc"?-1:1;c=c.map((p,b)=>({row:p,i:b,key:An(p[i],l)})).sort((p,b)=>{if(p.key===void 0||b.key===void 0)return p.key===void 0&&b.key===void 0?p.i-b.i:p.key===void 0?1:-1;let x=typeof p.key=="number"&&typeof b.key=="number"?p.key-b.key:xn(String(p.key),String(b.key));return x===0?p.i-b.i:x<0?-u:u}).map(p=>p.row)}return t.limit?c.slice(0,t.limit):c}function nt(e,t,n,r,o){return!e||typeof e!="object"?e:{...e,rows:Sn(e,t,n,r,o)}}function En(e){return{screen:e?.screen??null,timeZone:e?.timeZone,tables:new Proxy({},{get:(t,n)=>typeof n=="string"?e?.snapshot?.(n):void 0})}}async function ot(e,t,n,r,o,s,c,k=()=>{},h){let i=e.appInfo??n.info;Ve(t),i?.id&&(t.dataset.app=i.id);let l=(d,g)=>(t.dataset.appFailed=d,{failed:d,...g?{error:g}:{}});if(!Be(i?.requires))return l("unsupported");let u=r.appHost;if(u&&!u.custom&&!U(i))return l("unsupported");if(ze(h,i))return Ze(e,t,n,r,o,s,c,k,h,l);let p=e.app;if(u?.held?.(p))return t.dataset.appHeld="",{held:!0};await u?.mounting?.(p,i?.id);let b=!1,x=()=>{b||(b=!0,u?.unmounted?.(p))},A;try{A=await We(n.hash,n.bytes,i)}catch(d){return x(),d instanceof M?l(d.reason,d.error):l("load")}let q=A.tag,N=i?.id?r.controllerFor?.({id:i.id,instance:e.id,capability:i.player??"read"}):void 0,S,w=new Promise(d=>{S=d}),P,E={app:i?.id??e.app.id,element:q,props:Qe(e.props??{},En(r)),place:r.place,screen:r.screen??null,timeZone:r.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,locale:r.locale??navigator.language,preview:!!r.preview,now:o.now,startedAt:o.startedAt,ready:()=>S(),data:(d,g)=>r.data?r.data.get(d,g):Promise.reject(new Error("no data service")),kept:(d,g)=>r.data?.kept?.(d,g),image:d=>r.data?r.data.image(d):Promise.reject(new Error("no data service")),snapshot:d=>{let g=r.snapshot?.(d)??null;if(!g||e.binding?.table!==d||!tt(e.binding))return g;let D=nt(g,e.binding,r.screen,E.timeZone,o.now());return P?.from===g&&P.rows.length===D.rows.length&&P.rows.every((at,dt)=>at===D.rows[dt])?P.snapshot:(P={from:g,rows:D.rows,snapshot:D},D)},...e.binding?{binding:e.binding}:{},...e.sensors?.includes("impressions")&&r.impressions?.measuring?{impressions:{now:()=>r.impressions.now(),on:d=>r.impressions.on(d)}}:{},...N?{controller:N}:{}},T;try{T=je(q),A.shape==="class"?A.attach(T,E):T.wyndlass=E}catch(d){return N?.dispose(),x(),l("error",L(d))}T.style.cssText="display:block;width:100%;height:100%",u?.contained?.(t,T);let R=new Q(T,{onStop:k,dispose:()=>{N?.dispose(),x()}});t.append(T),c(R);let I=await Promise.race([w.then(()=>!1),new Promise(d=>setTimeout(()=>d(!0),s))]);return R.update(E.now()),{app:R,late:I}}var rt=new Set;async function st(e,t){for(let n of e){let r=`${n.family}/${n.weight??400}/${n.style??"normal"}/${n.blob}`,o=t(n.blob);if(!(rt.has(r)||!o||typeof FontFace>"u"))try{let s=new FontFace(n.family,o,{weight:String(n.weight??400),style:n.style??"normal"});document.fonts.add(await s.load()),rt.add(r)}catch{}}}var te,F,O={t:0,at:0,running:!1},he={},ge="null",ye=new Map,Tn=0,$=e=>te.postMessage(e),be=()=>O.running?O.t+(performance.now()-O.at):O.t;addEventListener("message",e=>{te||e.source!==parent||e.data?.type!==X||!e.ports[0]||(te=e.ports[0],te.onmessage=t=>Mn(t.data),$({type:"hello"}))});function Mn(e){switch(e.type){case"init":Fn(e);break;case"clock":O={t:e.t,at:performance.now(),running:e.running},F?.update(be()),we();break;case"hook":{let t=e.id;(F?F.hook(e.kind,e.options):Promise.resolve()).then(()=>$({type:"hooked",id:t}));break}case"reset":F?.reset();break;case"snapshots":he=e.snapshots;break;case"answer":{let t=ye.get(e.id);ye.delete(e.id),e.error!==void 0?t?.reject(Object.assign(new Error("the host could not answer"),{name:e.error})):t?.resolve(e.value);break}}}function it(e){let t=++Tn;return new Promise((n,r)=>{ye.set(t,{resolve:n,reject:r}),$({type:"ask",id:t,...e})})}function we(){let e=F?.paging()??null,t=JSON.stringify(e);t!==ge&&(ge=t,$({type:"paging",paging:e}))}async function Fn(e){if(F)return;O={t:e.clock.t,at:performance.now(),running:e.clock.running},he=e.snapshots;let t=new Map,n=(i,l)=>`${i}?${JSON.stringify(Object.keys(l).sort().map(u=>[u,l[u]]))}`,o={data:{get:async(i,l)=>{let u=await it({what:"data",source:i,params:l});return t.set(n(i,l),u),u},kept:(i,l)=>t.get(n(i,l)),image:async i=>{let{bytes:l,type:u}=await it({what:"image",path:i});return URL.createObjectURL(new Blob([l],{type:u}))}},place:e.place,screen:e.screen,timeZone:e.timeZone,locale:e.locale,preview:e.preview,snapshot:i=>he[i]??null},s={now:be,startedAt:()=>e.clock.startedAt},c=new Map(e.fonts.map(i=>[i.blob,i.bytes]));await st(e.fonts,i=>c.get(i));let k=document.getElementById("app"),h=await ot(e.element,k,e.bundle,o,s,e.deadlineMs,i=>{F=i,ge=JSON.stringify(i.paging()),$({type:"made",hooks:["enter","exit"].filter(l=>i.has(l)),paging:i.paging()})},i=>$({type:"stopped",...i?{error:i}:{}}));"failed"in h?$({type:"failed",reason:h.failed,...h.error?{error:h.error}:{}}):"app"in h&&($({type:"ready",late:h.late}),we(),Pn())}function Pn(){let e=0,t=n=>{F?.stopped||(O.running&&F?.update(be()),n-e>1e3&&(e=n,we()),requestAnimationFrame(t))};requestAnimationFrame(t)}})();
|
|
2
|
+
"use strict";(()=>{var vt=Object.defineProperty;var kt=(e,t,n)=>t in e?vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>kt(e,typeof t!="symbol"?t+"":t,n);var Te={apiVersion:2,properties:[{name:"device",description:"What the device is: id, type, shell and versions, model, resolution and orientation. Fixed while the player runs."},{name:"mode",description:"Where player-core runs: player, preview (in the CMS) or designer. In preview and the designer, commands change nothing."},{name:"timeZone",description:"The player's time zone (IANA), from the host.",event:"time.changed"},{name:"locale",description:"The player's locale (BCP 47), from the host."},{name:"connection",description:"Whether the player is connected to Wyndlass.",event:"connection.changed"},{name:"state",description:"starting, playing, paused, stopped (the standby screen), idle (nothing to play) or error.",event:"state.changed"},{name:"held",description:"A remote pause or stop in effect, by whom and since when; absent when none.",event:"state.changed"},{name:"content",description:"The manifest playing, when it was issued and switched to; absent when there is none.",event:"content.updated"},{name:"now",description:"What each zone shows: the item, its blob and content type, when it started, and its duration and position when known.",event:"item.start"},{name:"audio",description:"The player's volume (0 to 100) and whether it is muted; only when the host can set them.",event:"audio.changed"},{name:"display",description:"The display's power and brightness; only when the host can report them.",event:"display.changed"},{name:"capabilities",description:"What the host can do: audio, display power, display brightness."}],events:[{name:"state.changed",description:"The player's state changed (playing, paused, stopped, idle, error), and who changed it."},{name:"content.updated",description:"A new manifest was switched to."},{name:"item.start",description:"An item started in a zone (source start)."},{name:"item.end",description:"An item ended in a zone (source end): completed, skipped, stopped, error, replaced by new content, or finished by its app."},{name:"item.error",description:"An item could not be shown."},{name:"connection.changed",description:"The player connected to Wyndlass or lost its connection."},{name:"audio.changed",description:"The volume or mute changed, and who changed it."},{name:"display.changed",description:"The display's power or brightness changed, and who changed it."},{name:"time.changed",description:"The clock was adjusted or the time zone changed."},{name:"app.command",description:"A command for apps on the screen (apps.sendCommand); an app reacts if it knows the name."},{name:"app.failed",description:"An app on the screen could not run, or misbehaved (WP-0100): its bundle did not load, it was not an app, it needs a newer player, it kept throwing and was stopped, or it was late or overran a clip."},{name:"app.held",description:"An app version was held back on this screen until the next manifest, after the page stopped answering twice in an hour while it was on screen (WP-0100)."}],commands:[{name:"player.status",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/status",description:"Everything about the player now: device, mode, time zone, locale, connection, state (and any hold), the content playing, what each zone shows, audio, display and what the host can do. Changes nothing.",idempotent:!0},{name:"player.events",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/events",result:"player-api-results.schema.json#/$defs/events",description:"The player's recent events (the last 200), oldest first, after a sequence number: state changes, content updates, item starts and ends, errors, connection, audio, display and time. Pass next as after to poll for more. Changes nothing.",idempotent:!0},{name:"time.now",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/timeNow",description:"The player's current time, its time zone and UTC offset, and whether its clock is synchronized. Changes nothing.",idempotent:!0},{name:"player.play",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Resumes or starts playback on the screen. From a remote caller it also ends a remote pause or stop.",idempotent:!0},{name:"player.pause",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Freezes the screen on what it shows now: the loop's timer and any media stop where they are. From a remote caller it holds until a remote player.play or a restart; apps cannot resume it, and new content arrives paused.",idempotent:!0},{name:"player.stop",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Stops playback and shows the standby screen (black, display on). From a remote caller it holds until a remote player.play or a restart; apps cannot restart it, and new content arrives stopped.",idempotent:!0},{name:"player.next",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Skips to the next item in a zone (main by default); the current item ends as skipped."},{name:"player.previous",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Goes back to the previous item in a zone (main by default); the current item ends as skipped."},{name:"player.playItem",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/playItem",result:"player-api-results.schema.json#/$defs/now",description:"Shows a given item of the content playing now in a zone (main by default), then continues the loop from it. Refused for an item the playing manifest does not have."},{name:"audio.setVolume",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setVolume",result:"player-api-results.schema.json#/$defs/audio",description:"Sets the player's volume, 0 to 100. Only on players whose host can set it to a level.",needs:"audio.volume",idempotent:!0},{name:"audio.setMuted",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setMuted",result:"player-api-results.schema.json#/$defs/audio",description:"Mutes or unmutes the player. Only on players whose host can.",needs:"audio",idempotent:!0},{name:"display.setPower",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setPower",result:"player-api-results.schema.json#/$defs/display",description:"Turns the display on or to standby. Only on players whose host can. Standby blanks the screen until it is turned on.",needs:"display.power",idempotent:!0},{name:"display.setBrightness",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setBrightness",result:"player-api-results.schema.json#/$defs/display",description:"Sets the display's brightness, 0 to 100. Only on players whose host can.",needs:"display.brightness",idempotent:!0},{name:"apps.sendCommand",access:"control",apps:"none",remote:!0,params:"player-api-params.schema.json#/$defs/sendCommand",result:"player-api-results.schema.json#/$defs/delivered",description:"Sends a named command, with an optional argument, to the apps on the screen; an app that knows the name reacts. Returns how many apps listen."},{name:"app.finish",access:"control",apps:"read",remote:!1,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/none",description:"An app ends its own slot now: its item ends as finished and the loop moves on. Apps only; not a tool."}],host:[{name:"host.describe",kind:"request",description:"What the device is, its time zone, locale, connection and capabilities.",result:"player-api-host.schema.json#/$defs/describeResult"},{name:"host.time",kind:"request",description:"The host's time and time zone.",result:"player-api-common.schema.json#/$defs/timeNow"},{name:"host.getAudio",kind:"request",description:"The player's volume and mute.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.setAudio",kind:"request",description:"Sets the volume, the mute or both; answers the audio after.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.getDisplay",kind:"request",description:"The display's power and brightness.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.setDisplay",kind:"request",description:"Sets the display's power, brightness or both; answers the display after.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.adRequest",kind:"request",description:"Asks Wyndlass's ad broker for one slot of a break over the host's NATS connection (WP-0075); the result is the broker's ad-decision (ad-decision.schema.json). Only a host whose describe says ads is asked."},{name:"host.mediaPrepare",kind:"request",description:"Lays a video out behind the page and prepares it to its first frame; host.mediaState says when (ADR 0055)."},{name:"host.mediaShow",kind:"request",description:"Shows and hides prepared videos; replies once its layer has changed."},{name:"host.mediaControl",kind:"request",description:"Plays, pauses or seeks a video, or asks for its position."},{name:"host.mediaRelease",kind:"request",description:"Removes a video and frees its decoder."},{name:"host.reply",kind:"reply",description:"The host's answer to a request: result or error (unsupported, failed)."},{name:"host.connection",kind:"event",description:"The connection to Wyndlass changed."},{name:"host.timeChanged",kind:"event",description:"The clock was adjusted or the time zone changed."},{name:"host.audioChanged",kind:"event",description:"The volume or mute changed outside the player."},{name:"host.displayChanged",kind:"event",description:"The display changed outside the player."},{name:"host.mediaState",kind:"event",description:"A video was prepared, started, ended or failed, or its position was asked for."},{name:"host.presence",kind:"event",description:"What one of the host's sensors sees now: the presences in view, with random ids that never leave the page (WP-0105)."},{name:"host.sensing",kind:"event",description:"The site's sensing mode as the host applies it, and its sensors (WP-0105)."},{name:"host.serialPorts",kind:"event",description:"The host's sensor controller ports, and which are open (WP-0043)."},{name:"host.serialLine",kind:"event",description:"One line from a sensor controller, as it arrived (WP-0043)."},{name:"host.serialWrite",kind:"request",description:"Writes lines to a sensor controller, a gap apart; replies once written (WP-0043)."},{name:"host.bleWatch",kind:"request",description:"What the page listens for: beacons' iBeacon UUIDs, Eddystone namespaces and addresses; replies once the scan follows it. Sent only to a host that has sent host.bleState (WP-0044)."},{name:"host.bleAdverts",kind:"event",description:"Beacon frames that match the watch, at most four a second of each kind from each beacon (WP-0044)."},{name:"host.bleState",kind:"event",description:"The host's Bluetooth scanner: scanning, idle, off, refused, missing or failed; sent only by a host that has one (WP-0044)."},{name:"host.gpioPins",kind:"event",description:"The GPIO pins the host reads, with their values (WP-0044)."},{name:"host.gpioEdge",kind:"event",description:"A GPIO pin changed (WP-0044)."},{name:"host.mcp",kind:"relay",description:"An MCP message from ctl.dev.{deviceId}, for player-core to answer."},{name:"core.ready",kind:"core",description:"player-core is ready to answer host.mcp; until then the shell answers -32002 itself."},{name:"core.mcpReply",kind:"core",description:"player-core's answer to a host.mcp, for the shell to send back."},{name:"core.sensors",kind:"core",description:"The page's sensor controllers, channels and inputs, and the beacons it hears, whenever they change, for the heartbeat and sensors.recent (WP-0043, WP-0044)."}]};var Me=Symbol.for("wyndlass.app.attach");var De=Reflect.apply,de=Object.getOwnPropertyDescriptor,Q=Object.getPrototypeOf,b=globalThis,a=(e,t,n)=>De(e,t,n),k=(e,t)=>e?de(e,t)?.get:void 0,pe=(e,t)=>e?de(e,t)?.set:void 0,g=e=>b[e]?.prototype,He=(e,t,n)=>De(e,t,n);var qn=Date.now,zn=new TextEncoder,_n=new TextDecoder,Zn=TextEncoder.prototype.encode,Kn=TextDecoder.prototype.decode;var Vn=k(Q(Uint8Array.prototype),"length");var xt=Uint8Array,St=e=>new xt(e),Et=[];for(let e=0;e<256;e++)Et[e]=(e<16?"0":"")+e.toString(16);var Tt=Object.create(null);for(let e=0;e<64;e++)Tt["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[e]]=e;var Fe=b.crypto?.subtle,le=Fe?Q(Fe):void 0,ae=b.crypto,Mt=ae?Q(ae).getRandomValues:void 0,Gn=le?.digest,Jn=le?.importKey,Yn=le?.sign;var Be=e=>a(Mt,ae,[St(e)]),Qn={setTimeout:b.setTimeout,clearTimeout:b.clearTimeout,setInterval:b.setInterval,clearInterval:b.clearInterval};var Xn=b.fetch;var q=g("MessagePort"),er=q&&q.postMessage,tr=pe(q,"onmessage"),nr=q&&q.start,ce=g("MessageEvent"),rr=k(ce,"data"),or=k(ce,"ports"),sr=k(ce,"source");var We=g("EventTarget"),ir=We?.addEventListener,ar=We?.removeEventListener;var dr=b.Worker,G=g("Worker"),pr=G&&G.postMessage,lr=pe(G,"onmessage"),cr=pe(G,"onerror");var Pe=b.Blob,J=b.URL,Re=J?.createObjectURL,Ft=J?.revokeObjectURL,ue=Pe&&Re?{make:(e,t)=>a(Re,J,[new Pe(e,{type:t})]),revoke:e=>a(Ft,J,[e])}:void 0,U=b.customElements,me=U?Q(U):void 0,Pt=me?.define,Rt=me?.get,fe=U&&me?{define:(e,t)=>a(Pt,U,[e,t]),get:e=>a(Rt,U,[e])}:void 0,$t=b.document,Y=g("Document"),Nt=Y?.createElement,ur=Y?.createElementNS,Ot=WeakSet.prototype.add,mr=WeakSet.prototype.has,Ct=new WeakSet;var Lt=(e,t)=>(a(Ot,e,[t]),t);function Ue(e){return Lt(Ct,a(Nt,$t,[e]))}var z=g("Node"),he=g("Element"),X=g("HTMLElement"),D=e=>k(z,e),$e=D("parentNode"),jt=D("firstChild"),It=D("lastChild"),Dt=D("nextSibling"),Ht=D("nodeType"),Bt=D("childNodes"),Wt=k(he,"localName"),Ut=z?.appendChild,qt=z?.insertBefore,zt=z?.removeChild,L=he,_t=L?.getAttribute,Zt=L?.getAttributeNames,Kt=L?.setAttribute,Vt=L?.removeAttribute,Gt=L?.matches,Jt=L?.attachShadow,Yt=L?.querySelectorAll,Qt=g("HTMLDialogElement")?.close,Xt=k(g("NodeList"),"length"),en=g("NodeList")?.item,ee=g("MutationRecord"),tn=k(ee,"type"),nn=k(ee,"target"),rn=k(ee,"addedNodes"),on=k(ee,"removedNodes"),Ne=b.MutationObserver,sn=g("MutationObserver")?.observe,qe=Y?de(Y,"adoptedStyleSheets"):void 0,Oe=qe?.get,Ce=qe?.set,an=b.requestAnimationFrame,Le=k(X,"style"),te=g("CSSStyleDeclaration"),dn=te?.getPropertyValue,pn=te?.getPropertyPriority,ln=te?.setProperty,je=X?.showPopover,Ie=X?.hidePopover,cn=k(g("Event"),"target"),un=g("Event")?.stopImmediatePropagation,V=e=>{let t=[];for(let n=0,r=a(Xt,e,[]);n<r;n++)t[n]=a(en,e,[n]);return t},ze=Ne&&z&&he&&X&&te?{parent:e=>a($e,e,[]),first:e=>a(jt,e,[]),last:e=>a(It,e,[]),next:e=>a(Dt,e,[]),isElement:e=>a(Ht,e,[])===1,name:e=>a(Wt,e,[]),children:e=>V(a(Bt,e,[])),append:(e,t)=>a(Ut,e,[t]),insert:(e,t,n)=>a(qt,e,[t,n]),remove:e=>{let t=a($e,e,[]);t&&a(zt,t,[e])},attribute:(e,t)=>a(_t,e,[t]),attributes:e=>a(Zt,e,[]),setAttribute:(e,t,n)=>a(Kt,e,[t,n]),removeAttribute:(e,t)=>a(Vt,e,[t]),matches:(e,t)=>a(Gt,e,[t]),all:(e,t)=>V(a(Yt,e,[t])),closeDialog:e=>a(Qt,e,[]),shadow:e=>a(Jt,e,[{mode:"closed"}]),style:(e,t)=>{let n=a(Le,e,[]);return[a(dn,n,[t]),a(pn,n,[t])]},setStyle:(e,t,n,r="")=>a(ln,a(Le,e,[]),[t,n,r]),observer:e=>new Ne(e),observe:(e,t,n)=>a(sn,e,[t,n]),record:e=>({type:a(tn,e,[]),target:a(nn,e,[]),added:V(a(rn,e,[])),removed:V(a(on,e,[]))}),adopted:Oe&&Ce?{count:e=>a(Oe,e,[]).length,clear:e=>a(Ce,e,[[]])}:void 0,frame:e=>a(an,globalThis,[e]),popover:je&&Ie?{show:e=>a(je,e,[]),hide:e=>a(Ie,e,[])}:void 0,target:e=>a(cn,e,[]),stop:e=>a(un,e,[])}:void 0;var P=class extends Error{constructor(n,r){super(`the app could not run (${n})`);m(this,"reason",n);m(this,"error",r)}};function j(e){try{let t=e instanceof Error?e.name:void 0;return typeof t=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(t)?t:void 0}catch{return}}function _(e){let t=e?.id;if(typeof t!="string"||t==="")return!0;for(let n=0;n<_e.length;n++)if(t[n]!==_e[n])return!1;return!0}var _e="com.wyndlass.";function mn(e=typeof navigator>"u"?"":navigator.userAgent){let t=/Chrom(?:e|ium)\/(\d+)/.exec(e);return t?Number(t[1]):void 0}function Ze(e,t=Te.apiVersion,n=mn()){return!(e?.playerApi!==void 0&&e.playerApi>t||e?.webView!==void 0&&n!==void 0&&e.webView>n)}function fn(e){let t;try{t=e.paging?.()}catch{return null}let n=t;return n&&Number.isInteger(n.count)&&n.count>1&&typeof n.ms=="number"&&n.ms>0?{count:n.count,ms:n.ms}:null}var ge=new Map;function hn(){let e=Be(8),t="";for(let n=0;n<8;n++)t+=gn[e[n]%26];return t}var gn="abcdefghijklmnopqrstuvwxyz",yn=0;function Ke(e,t,n){let r=ge.get(e);if(!r){let o=ue.make([t],"text/javascript");r=import(o).then(s=>bn(s,n),s=>{throw s instanceof P?s:new P("load",j(s))}).finally(()=>ue.revoke(o)),ge.set(e,r),r.catch(()=>ge.delete(e))}return r}function bn(e,t){let n=e.default;if(typeof n=="function"&&n.prototype instanceof HTMLElement){let r=n.prototype[Me];if(typeof r!="function")throw new P("shape");let o=class extends n{},s=`${t?.element??"wl-app"}-${hn()}${++yn}`;try{fe.define(s,o)}catch(c){throw new P("shape",j(c))}return{tag:s,shape:"class",attach:(c,A)=>{He(r,c,[A])}}}if(_(t)&&typeof e.element=="string"&&fe.get(e.element))return{tag:e.element,shape:"legacy"};throw new P("shape")}var wn=3,vn=6e4,ne=class{constructor(t,n){m(this,"element",t);m(this,"o",n);m(this,"faults",[]);m(this,"halted",!1)}get stopped(){return this.halted}has(t){try{return!this.halted&&typeof this.element[t]=="function"}catch{return!1}}update(t){this.halted||this.run(()=>this.element.update?.(t))}reset(){this.halted||this.run(()=>this.element.reset?.())}paging(){return this.halted?null:fn(this.element)}hook(t,n){if(this.halted)return Promise.resolve();let r;try{r=this.element[t]?.(n)}catch(o){return this.fault(o),Promise.resolve()}return Promise.resolve(r).then(()=>{},o=>this.fault(o))}stop(t){if(!this.halted){this.halted=!0;try{this.element.remove()}catch{}this.o.dispose?.(),this.o.onStop(t)}}dispose(){this.o.dispose?.()}run(t){try{t()}catch(n){this.fault(n)}}fault(t){let n=(this.o.now??Date.now)();this.faults=this.faults.filter(r=>n-r<vn),this.faults.push(n),this.faults.length>=wn&&this.stop(j(t))}},br=24*3600*1e3;var re="wyndlass.frame";function Ye(e,t){return!!e&&(e.apps?e.apps(t):!_(t))}var kn=new Set(["load","shape","unsupported","error","late","overran"]),Ve=50,Ge=250,ye=class{constructor(t,n,r,o){m(this,"frame",t);m(this,"port",n);m(this,"o",o);m(this,"halted",!1);m(this,"pages");m(this,"hooks");m(this,"pending",new Map);m(this,"next",0);m(this,"told");m(this,"last");m(this,"quiet");this.hooks=new Set(r.hooks),this.pages=r.paging}get stopped(){return this.halted}has(t){return!this.halted&&this.hooks.has(t)}paging(){return this.halted?null:this.pages}update(t){if(this.halted)return;let n=performance.now(),r=this.last;this.last={t,at:n};let o=this.told;if(o&&(o.running?Math.abs(t-(o.t+(n-o.at)))<=Ve:t===o.t)){o.running&&this.watch();return}let s=!!r&&n-r.at<Ge&&t>r.t&&Math.abs(t-r.t-(n-r.at))<=Ve;this.told={t,at:n,running:s},this.post({type:"clock",t,running:s}),s&&this.watch()}reset(){this.halted||this.post({type:"reset"})}snapshots(t){this.halted||this.post({type:"snapshots",snapshots:t})}hook(t,n){if(this.halted)return Promise.resolve();let r=++this.next;return new Promise(o=>{this.pending.set(r,o),this.post({type:"hook",id:r,kind:t,options:n})})}stop(t){this.halted||(this.halted=!0,this.frame.remove(),this.dispose(),this.o.onStop(t))}dispose(){this.o.dispose?.(),clearTimeout(this.quiet),this.port.close();for(let t of this.pending.values())t();this.pending.clear()}heard(t){t.type==="paging"?this.pages=Xe(t.paging):t.type==="hooked"&&typeof t.id=="number"?(this.pending.get(t.id)?.(),this.pending.delete(t.id)):t.type==="stopped"&&this.stop(et(t.error))}post(t){try{this.port.postMessage(t)}catch{}}watch(){clearTimeout(this.quiet),this.quiet=setTimeout(()=>{!this.told?.running||!this.last||this.halted||(this.told={...this.last,running:!1},this.post({type:"clock",t:this.last.t,running:!1}))},Ge)}};async function Qe(e,t,n,r,o,s,c,A,y,i){let l=e.appInfo??n.info,u;try{u=new URL(y.frames).origin}catch{return i("unsupported")}let d=document.createElement("iframe");d.setAttribute("sandbox","allow-scripts"),d.setAttribute("referrerpolicy","no-referrer"),d.title=l?.id??"app",d.tabIndex=-1,d.dataset.frame=l?.id??"",d.style.cssText="display:block;width:100%;height:100%;border:0;pointer-events:none;background:transparent;color-scheme:normal";let w=new Promise(T=>{d.addEventListener("load",()=>T(!0),{once:!0}),setTimeout(()=>T(!1),s)});d.src=`${u}/`,t.append(d);let E=(T,v)=>(d.remove(),i(T,v));if(!await w||!d.contentWindow)return E("load");let{port1:x,port2:Z}=new MessageChannel,O={type:"init",element:{id:e.id,type:"app",app:e.app,props:e.props??{},...e.binding?{binding:e.binding}:{},...e.appInfo?{appInfo:e.appInfo}:{}},bundle:{hash:n.hash,bytes:n.bytes.slice(),...n.info?{info:n.info}:{}},...r.place?{place:r.place}:{},screen:r.screen??null,timeZone:r.timeZone,locale:r.locale,preview:!!r.preview,clock:{t:o.now(),running:!1,startedAt:o.startedAt()},fonts:Sn(e.props??{},y),snapshots:Je(e,r),deadlineMs:s};return new Promise(T=>{let v,$=!1,M=B=>{$||($=!0,clearTimeout(C),T(B))},C=setTimeout(()=>{v?(M({app:v,late:!0}),v.update(o.now())):(x.close(),M(E("load")))},s+1e3),S=!1;x.onmessage=B=>{let h=B.data;if(!(!h||typeof h!="object")){if(h.type==="ask"){S&&An(h,r,x);return}if(v){h.type==="ready"?(M({app:v,late:h.late===!0}),v.update(o.now())):v.heard(h);return}if(h.type==="hello"&&!S)S=!0,x.postMessage(O,[O.bundle.bytes.buffer]);else if(h.type==="made"&&Array.isArray(h.hooks)){let W=tt(e),K,p=new ye(d,x,{type:"made",hooks:h.hooks.filter(f=>f==="enter"||f==="exit"),paging:Xe(h.paging)},{onStop:A,dispose:()=>K?.()});K=r.onSnapshots?.(f=>{f.some(F=>W.has(F))&&p.snapshots(Je(e,r))}),v=p,c(v)}else h.type==="failed"&&(x.close(),M(E(kn.has(h.reason)?h.reason:"error",et(h.error))))}},d.contentWindow.postMessage({type:re},"*",[Z])})}async function An(e,t,n){if(typeof e.id!="number")return;let r=(o,s=[])=>{try{n.postMessage(o,s)}catch{}};try{if(!t.data)throw new Error("no data service");if(e.what==="data"&&typeof e.source=="string")r({type:"answer",id:e.id,value:await t.data.get(e.source,xn(e.params))});else if(e.what==="image"&&typeof e.path=="string"){let o=await t.data.imageBlob(e.path),s=new Uint8Array(await o.arrayBuffer());r({type:"answer",id:e.id,value:{bytes:s,type:o.type}},[s.buffer])}else throw new TypeError("not a question")}catch(o){r({type:"answer",id:e.id,error:j(o)??"Error"})}}function xn(e){let t={};if(e&&typeof e=="object")for(let[n,r]of Object.entries(e))(typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&(t[n]=r);return t}function Xe(e){let t=e;return t&&Number.isInteger(t.count)&&t.count>1&&typeof t.ms=="number"&&t.ms>0?{count:t.count,ms:t.ms}:null}function et(e){return typeof e=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(e)?e:void 0}function Sn(e,t){let n=new Set;for(let o of Object.values(e)){let s=o?.family;o&&typeof o=="object"&&typeof s=="string"&&n.add(s)}let r=[];for(let o of t.fonts??[]){let s=n.has(o.family)?t.font?.(o.blob):void 0;s&&r.push({family:o.family,weight:o.weight,style:o.style,blob:o.blob,bytes:s.slice()})}return r}function tt(e){let t=new Set;e.binding?.table&&t.add(e.binding.table);for(let n of Object.values(e.props??{}))typeof n=="string"&&/^tbl_[0-9a-z]{26}$/.test(n)&&t.add(n);return t}function Je(e,t){let n={};for(let r of tt(e)){let o=t.snapshot?.(r);o&&(n[r]=o)}return n}function nt(e){let t=ze?.setStyle??((n,r,o,s)=>n.style.setProperty(r,o,s));t(e,"contain","strict","important"),t(e,"overflow","clip","important")}var En=["name","type","tags","location","site","district","region","organization","path","timeZone"],Tn=["text","date","currency","truncate"],rt={site:"SITE",district:"DISTRICT",region:"REGION",organization:"ORGANIZATION"};function oe(e,t,n,r){if(!e)return n==="timeZone"&&t?t:void 0;if(n==="fields")return r&&e.fields?.[r]||void 0;let o=e.path??[];switch(n){case"name":return e.name||void 0;case"type":return e.type||void 0;case"tags":return e.tags?.length?e.tags.join(", "):void 0;case"location":return o.at(-1)?.name;case"path":return o.length?o.map(s=>s.name).join(" \u203A "):void 0;case"timeZone":return t||void 0;default:return rt[n]?[...o].reverse().find(s=>s.kind===rt[n])?.name:void 0}}function Mn(e,t){if(e==null||e==="")return;let n=String(e);if(t==="currency"){let r=Number(e);return Number.isFinite(r)?r.toFixed(2):n}if(t==="date"){let r=Date.parse(n);return Number.isNaN(r)?n:new Date(r).toISOString().slice(0,10)}return t==="truncate"&&n.length>40?n.slice(0,39)+"\u2026":n}function ot(e,t){return(e.source==="screen"?oe(t.screen,t.timeZone,e.field,e.key):Mn(t.tables?.[e.table]?.rows?.[e.row??0]?.[e.column],e.format))??e.fallback??""}function st(e){let t=/^\s*(?:screen\.(fields\.[a-z][A-Za-z0-9]{0,31}|[A-Za-z]+)|table\.([A-Za-z0-9_-]+)\[(\d+)\](?:\.([A-Za-z0-9_]+)|\["((?:[^"\\]|\\.)*)"\]))\s*((?:\|\s*(?:[a-z]+|"(?:[^"\\]|\\.)*")\s*)*)$/.exec(e);if(!t)return null;let n=[...t[6].matchAll(/\|\s*([a-z]+|"((?:[^"\\]|\\.)*)")/g)],r=n.find(s=>s[1].startsWith('"'))?.[2]?.replace(/\\(.)/g,"$1"),o=n.find(s=>!s[1].startsWith('"'))?.[1];return t[1]!==void 0?o?null:t[1].startsWith("fields.")?{source:"screen",field:"fields",key:t[1].slice(7),...r!==void 0?{fallback:r}:{}}:En.includes(t[1])?{source:"screen",field:t[1],...r!==void 0?{fallback:r}:{}}:null:o&&!Tn.includes(o)?null:{source:"table",table:t[2],row:Number(t[3]),column:t[4]??t[5].replace(/\\(.)/g,"$1"),...o?{format:o}:{},...r!==void 0?{fallback:r}:{}}}function it(e,t){return e.replace(/\{{2}([^{}]*)\}{2}/g,(n,r)=>{let o=st(r);return o?ot(o,t):n})}function at(e){return[...e.matchAll(/\{{2}([^{}]*)\}{2}/g)].some(t=>st(t[1])!==null)}function be(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,typeof r=="string"?it(r,t):r]))}var we=e=>e==null||e==="";function pt(e,t,n,r,o,s){return Fn(e,t,n,r,{now:o,timeZone:s})}function Fn(e,t,n,r,o){if(n===null&&(t==="eq"||t==="ne"))return t==="eq"?we(e):!we(e);if(we(e)||n===null||n===void 0)return!1;switch(r){case"number":case"currency":{let s=Number(e),c=Number(n);return typeof n!="boolean"&&n!==""&&Number.isFinite(s)&&Number.isFinite(c)&&ve(t,s-c)}case"boolean":{let s=n===!0||n==="true"?!0:n===!1||n==="false"?!1:void 0;return s!==void 0&&(t==="eq"?e===s:t==="ne"?e!==s:!1)}case"date":{let s=n==="today"?Pn(o.now,o.timeZone).date:String(n),c=String(e).slice(0,10);return/^\d{4}-\d{2}-\d{2}$/.test(s)&&ve(t,c<s?-1:c>s?1:0)}case"datetime":{let s=Date.parse(String(e)),c=n==="now"?o.now:Date.parse(String(n));return!Number.isNaN(s)&&!Number.isNaN(c)&&ve(t,s-c)}default:{let s=String(e).toLowerCase(),c=String(n).toLowerCase();return t==="eq"?s===c:t==="ne"?s!==c:t==="contains"?s.includes(c):!1}}}function ve(e,t){switch(e){case"eq":return t===0;case"ne":return t!==0;case"lt":return t<0;case"lte":return t<=0;case"gt":return t>0;case"gte":return t>=0;default:return!1}}var dt=new Map;function Pn(e,t){let n=dt.get(t);n||(n=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",weekday:"short"}),dt.set(t,n));let r=Object.fromEntries(n.formatToParts(new Date(e)).map(o=>[o.type,o.value]));return{date:`${r.year}-${r.month}-${r.day}`,minute:Number(r.hour)%24*60+Number(r.minute),day:String(r.weekday).slice(0,3).toLowerCase()}}var lt=e=>!!(e?.filter?.length||e?.sort||e?.limit),Rn=e=>e==null||e==="";function $n(e,t){if(!Rn(e))switch(t){case"number":case"currency":{let n=Number(e);return Number.isFinite(n)?n:void 0}case"datetime":{let n=Date.parse(String(e));return Number.isNaN(n)?void 0:n}case"boolean":return e===!0||String(e).toLowerCase()==="true"?1:0;case"date":return String(e).slice(0,10);default:return String(e).toLowerCase()}}function Nn(e,t){let n=Array.from(e),r=Array.from(t);for(let o=0;o<n.length&&o<r.length;o++){let s=n[o].codePointAt(0)-r[o].codePointAt(0);if(s!==0)return s}return n.length-r.length}function On(e,t,n,r,o){let s=e,c=Array.isArray(s?.rows)?s.rows:[],A=Array.isArray(s?.columns)?s.columns:void 0,y=i=>A?.find(l=>l.key===i)?.type??"text";for(let i of t.filter??[]){if(A&&!A.some(d=>d.key===i.column))return[];let l=i.value;if(l!==null&&typeof l=="object"){let d=l;if(l=oe(n,r,d.screen,d.key),l===void 0)return[]}let u=y(i.column);c=c.filter(d=>pt(d[i.column],i.op,l,u,o,r))}if(t.sort){let{column:i}=t.sort,l=y(i),u=t.sort.order==="desc"?-1:1;c=c.map((d,w)=>({row:d,i:w,key:$n(d[i],l)})).sort((d,w)=>{if(d.key===void 0||w.key===void 0)return d.key===void 0&&w.key===void 0?d.i-w.i:d.key===void 0?1:-1;let E=typeof d.key=="number"&&typeof w.key=="number"?d.key-w.key:Nn(String(d.key),String(w.key));return E===0?d.i-w.i:E<0?-u:u}).map(d=>d.row)}return t.limit?c.slice(0,t.limit):c}function ct(e,t,n,r,o){return!e||typeof e!="object"?e:{...e,rows:On(e,t,n,r,o)}}function ut(e){return{screen:e?.screen??null,timeZone:e?.timeZone,tables:new Proxy({},{get:(t,n)=>typeof n=="string"?e?.snapshot?.(n):void 0})}}async function ft(e,t,n,r,o,s,c,A=()=>{},y){let i=e.appInfo??n.info;nt(t),i?.id&&(t.dataset.app=i.id);let l=(p,f)=>(t.dataset.appFailed=p,{failed:p,...f?{error:f}:{}});if(!Ze(i?.requires))return l("unsupported");let u=r.appHost;if(u&&!u.custom&&!_(i))return l("unsupported");if(Ye(y,i))return Qe(e,t,n,r,o,s,c,A,y,l);let d=e.app;if(u?.held?.(d))return t.dataset.appHeld="",{held:!0};await u?.mounting?.(d,i?.id);let w=!1,E=()=>{w||(w=!0,u?.unmounted?.(d))},x;try{x=await Ke(n.hash,n.bytes,i)}catch(p){return E(),p instanceof P?l(p.reason,p.error):l("load")}let Z=x.tag,O=i?.id?r.controllerFor?.({id:i.id,instance:e.id,capability:i.player??"read"}):void 0,T,v=new Promise(p=>{T=p}),$,M=new Set,C={app:i?.id??e.app.id,element:Z,props:be(e.props??{},ut(r)),place:r.place,screen:r.screen??null,timeZone:r.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,locale:r.locale??navigator.language,preview:!!r.preview,now:o.now,startedAt:o.startedAt,ready:()=>T(),data:(p,f)=>r.data?r.data.get(p,f):Promise.reject(new Error("no data service")),kept:(p,f)=>r.data?.kept?.(p,f),image:p=>r.data?r.data.image(p):Promise.reject(new Error("no data service")),snapshot:p=>{let f=r.snapshot?.(p)??null;if(!f||e.binding?.table!==p||!lt(e.binding))return f;let F=ct(f,e.binding,r.screen,C.timeZone,o.now());return $?.from===f&&$.rows.length===F.rows.length&&$.rows.every((bt,wt)=>bt===F.rows[wt])?$.snapshot:($={from:f,rows:F.rows,snapshot:F},F)},...e.binding?{binding:e.binding}:{},...r.onSnapshots?{onSnapshot:p=>(M.add(p),()=>{M.delete(p)})}:{},...e.sensors?.includes("impressions")&&r.impressions?.measuring?{impressions:{now:()=>r.impressions.now(),on:p=>r.impressions.on(p)}}:{},...O?{controller:O}:{}},S;try{S=Ue(Z),x.shape==="class"?x.attach(S,C):S.wyndlass=C}catch(p){return O?.dispose(),E(),l("error",j(p))}S.style.cssText="display:block;width:100%;height:100%",u?.contained?.(t,S);let B=Object.values(e.props??{}).some(p=>typeof p=="string"&&at(p)),h=r.onSnapshots?.(p=>{B&&(C.props=be(e.props??{},ut(r)));for(let f of p)for(let F of[...M])try{F(f)}catch{}}),W=new ne(S,{onStop:A,dispose:()=>{h?.(),M.clear(),O?.dispose(),E()}});t.append(S),c(W);let K=await Promise.race([v.then(()=>!1),new Promise(p=>setTimeout(()=>p(!0),s))]);return W.update(C.now()),{app:W,late:K}}var mt=new Set;async function ht(e,t){for(let n of e){let r=`${n.family}/${n.weight??400}/${n.style??"normal"}/${n.blob}`,o=t(n.blob);if(!(mt.has(r)||!o||typeof FontFace>"u"))try{let s=new FontFace(n.family,o,{weight:String(n.weight??400),style:n.style??"normal"});document.fonts.add(await s.load()),mt.add(r)}catch{}}}var Cn=Object.freeze,Ln=Object.values,gt=Reflect.apply;function se(e){if(e===null||typeof e!="object")return e;for(let t of gt(Ln,Object,[e]))se(t);return gt(Cn,Object,[e])}var ie,R,I={t:0,at:0,running:!1},H={},ke=new Set,Ae="null",xe=new Map,jn=0,N=e=>ie.postMessage(e),Se=()=>I.running?I.t+(performance.now()-I.at):I.t;addEventListener("message",e=>{ie||e.source!==parent||e.data?.type!==re||!e.ports[0]||(ie=e.ports[0],ie.onmessage=t=>In(t.data),N({type:"hello"}))});function In(e){switch(e.type){case"init":Dn(e);break;case"clock":I={t:e.t,at:performance.now(),running:e.running},R?.update(Se()),Ee();break;case"hook":{let t=e.id;(R?R.hook(e.kind,e.options):Promise.resolve()).then(()=>N({type:"hooked",id:t}));break}case"reset":R?.reset();break;case"snapshots":{let t=H;H=se(e.snapshots);let n=[...new Set([...Object.keys(t),...Object.keys(H)])].filter(r=>JSON.stringify(t[r])!==JSON.stringify(H[r]));if(n.length)for(let r of[...ke])r(n);break}case"answer":{let t=xe.get(e.id);xe.delete(e.id),e.error!==void 0?t?.reject(Object.assign(new Error("the host could not answer"),{name:e.error})):t?.resolve(e.value);break}}}function yt(e){let t=++jn;return new Promise((n,r)=>{xe.set(t,{resolve:n,reject:r}),N({type:"ask",id:t,...e})})}function Ee(){let e=R?.paging()??null,t=JSON.stringify(e);t!==Ae&&(Ae=t,N({type:"paging",paging:e}))}async function Dn(e){if(R)return;I={t:e.clock.t,at:performance.now(),running:e.clock.running},H=se(e.snapshots);let t=new Map,n=(i,l)=>`${i}?${JSON.stringify(Object.keys(l).sort().map(u=>[u,l[u]]))}`,o={data:{get:async(i,l)=>{let u=await yt({what:"data",source:i,params:l});return t.set(n(i,l),u),u},kept:(i,l)=>t.get(n(i,l)),image:async i=>{let{bytes:l,type:u}=await yt({what:"image",path:i});return URL.createObjectURL(new Blob([l],{type:u}))}},place:e.place,screen:e.screen,timeZone:e.timeZone,locale:e.locale,preview:e.preview,snapshot:i=>H[i]??null,onSnapshots:i=>(ke.add(i),()=>{ke.delete(i)})},s={now:Se,startedAt:()=>e.clock.startedAt},c=new Map(e.fonts.map(i=>[i.blob,i.bytes]));await ht(e.fonts,i=>c.get(i));let A=document.getElementById("app"),y=await ft(e.element,A,e.bundle,o,s,e.deadlineMs,i=>{R=i,Ae=JSON.stringify(i.paging()),N({type:"made",hooks:["enter","exit"].filter(l=>i.has(l)),paging:i.paging()})},i=>N({type:"stopped",...i?{error:i}:{}}));"failed"in y?N({type:"failed",reason:y.failed,...y.error?{error:y.error}:{}}):"app"in y&&(N({type:"ready",late:y.late}),Ee(),Hn())}function Hn(){let e=0,t=n=>{R?.stopped||(I.running&&R?.update(Se()),n-e>1e3&&(e=n,Ee()),requestAnimationFrame(t))};requestAnimationFrame(t)}})();
|
package/dist/preview/page.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @wyndlass/app-sdk's preview: player-core's host, compiled. MIT, (c) Northwynd Labs LLC. */
|
|
2
|
-
"use strict";(()=>{var qn=Object.defineProperty;var _n=(t,e,n)=>e in t?qn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var h=(t,e,n)=>_n(t,typeof e!="symbol"?e+"":e,n);var At=Reflect.apply,Oe=Object.getOwnPropertyDescriptor,ge=Object.getPrototypeOf,R=globalThis,x=(t,e,n)=>At(t,e,n),O=(t,e)=>t?Oe(t,e)?.get:void 0,$e=(t,e)=>t?Oe(t,e)?.set:void 0,L=t=>R[t]?.prototype,Et=(t,e,n)=>At(t,e,n);var Kr=Date.now,Zr=new TextEncoder,Jr=new TextDecoder,Yr=TextEncoder.prototype.encode,Xr=TextDecoder.prototype.decode;var Gr=O(ge(Uint8Array.prototype),"length");var Wn=Uint8Array,zn=t=>new Wn(t),Vn=[];for(let t=0;t<256;t++)Vn[t]=(t<16?"0":"")+t.toString(16);var Kn=Object.create(null);for(let t=0;t<64;t++)Kn["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[t]]=t;var ht=R.crypto?.subtle,De=ht?ge(ht):void 0,Ne=R.crypto,Zn=Ne?ge(Ne).getRandomValues:void 0,Qr=De?.digest,ei=De?.importKey,ti=De?.sign;var St=t=>x(Zn,Ne,[zn(t)]),ni={setTimeout:R.setTimeout,clearTimeout:R.clearTimeout,setInterval:R.setInterval,clearInterval:R.clearInterval};var si=R.fetch;var se=L("MessagePort"),ri=se&&se.postMessage,ii=$e(se,"onmessage"),oi=se&&se.start,je=L("MessageEvent"),ai=O(je,"data"),di=O(je,"ports"),li=O(je,"source");var Tt=L("EventTarget"),pi=Tt?.addEventListener,ci=Tt?.removeEventListener;var ui=R.Worker,me=L("Worker"),mi=me&&me.postMessage,hi=$e(me,"onmessage"),fi=$e(me,"onerror");var ft=R.Blob,he=R.URL,gt=he?.createObjectURL,Jn=he?.revokeObjectURL,Fe=ft&>?{make:(t,e)=>x(gt,he,[new ft(t,{type:e})]),revoke:t=>x(Jn,he,[t])}:void 0,te=R.customElements,He=te?ge(te):void 0,Yn=He?.define,Xn=He?.get,Be=te&&He?{define:(t,e)=>x(Yn,te,[t,e]),get:t=>x(Xn,te,[t])}:void 0,Pt=R.document,fe=L("Document"),Gn=fe?.createElement,Qn=fe?.createElementNS,es=WeakSet.prototype.add,gi=WeakSet.prototype.has,Ue=new WeakSet,ts=new WeakSet,ye=(t,e)=>(x(es,t,[e]),e);function j(t){return ye(Ue,x(Gn,Pt,[t]))}var be=t=>ye(Ue,x(Qn,Pt,["http://www.w3.org/2000/svg",t]));var Z=t=>ye(ts,t);var re=L("Node"),qe=L("Element"),we=L("HTMLElement"),J=t=>O(re,t),yt=J("parentNode"),ns=J("firstChild"),ss=J("lastChild"),rs=J("nextSibling"),is=J("nodeType"),os=J("childNodes"),as=O(qe,"localName"),ds=re?.appendChild,ls=re?.insertBefore,ps=re?.removeChild,z=qe,cs=z?.getAttribute,us=z?.getAttributeNames,ms=z?.setAttribute,hs=z?.removeAttribute,fs=z?.matches,gs=z?.attachShadow,ys=z?.querySelectorAll,bs=L("HTMLDialogElement")?.close,ws=O(L("NodeList"),"length"),vs=L("NodeList")?.item,ve=L("MutationRecord"),ks=O(ve,"type"),xs=O(ve,"target"),Ms=O(ve,"addedNodes"),As=O(ve,"removedNodes"),bt=R.MutationObserver,Es=L("MutationObserver")?.observe,Lt=fe?Oe(fe,"adoptedStyleSheets"):void 0,wt=Lt?.get,vt=Lt?.set,Ss=R.requestAnimationFrame,kt=O(we,"style"),ke=L("CSSStyleDeclaration"),Ts=ke?.getPropertyValue,Ps=ke?.getPropertyPriority,Ls=ke?.setProperty,xt=we?.showPopover,Mt=we?.hidePopover,Is=O(L("Event"),"target"),Cs=L("Event")?.stopImmediatePropagation,ue=t=>{let e=[];for(let n=0,s=x(ws,t,[]);n<s;n++)e[n]=x(vs,t,[n]);return e},ne=bt&&re&&qe&&we&&ke?{parent:t=>x(yt,t,[]),first:t=>x(ns,t,[]),last:t=>x(ss,t,[]),next:t=>x(rs,t,[]),isElement:t=>x(is,t,[])===1,name:t=>x(as,t,[]),children:t=>ue(x(os,t,[])),append:(t,e)=>x(ds,t,[e]),insert:(t,e,n)=>x(ls,t,[e,n]),remove:t=>{let e=x(yt,t,[]);e&&x(ps,e,[t])},attribute:(t,e)=>x(cs,t,[e]),attributes:t=>x(us,t,[]),setAttribute:(t,e,n)=>x(ms,t,[e,n]),removeAttribute:(t,e)=>x(hs,t,[e]),matches:(t,e)=>x(fs,t,[e]),all:(t,e)=>ue(x(ys,t,[e])),closeDialog:t=>x(bs,t,[]),shadow:t=>x(gs,t,[{mode:"closed"}]),style:(t,e)=>{let n=x(kt,t,[]);return[x(Ts,n,[e]),x(Ps,n,[e])]},setStyle:(t,e,n,s="")=>x(Ls,x(kt,t,[]),[e,n,s]),observer:t=>new bt(t),observe:(t,e,n)=>x(Es,t,[e,n]),record:t=>({type:x(ks,t,[]),target:x(xs,t,[]),added:ue(x(Ms,t,[])),removed:ue(x(As,t,[]))}),adopted:wt&&vt?{count:t=>x(wt,t,[]).length,clear:t=>x(vt,t,[[]])}:void 0,frame:t=>x(Ss,globalThis,[t]),popover:xt&&Mt?{show:t=>x(xt,t,[]),hide:t=>x(Mt,t,[])}:void 0,target:t=>x(Is,t,[]),stop:t=>x(Cs,t,[])}:void 0;function _e(t){if(ye(Ue,t),ne)for(let e of ne.children(t))ne.isElement(e)&&_e(e);return t}var We=t=>new TextEncoder().encode(t);function Rs(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n="";for(let s of e)n+=s.toString(16).padStart(2,"0");return n}async function ze(t){return Rs(await crypto.subtle.digest("SHA-256",t))}var Ns=["name","type","tags","location","site","district","region","organization","path","timeZone"],Os=["text","date","currency","truncate"],It={site:"SITE",district:"DISTRICT",region:"REGION",organization:"ORGANIZATION"};function xe(t,e,n,s){if(!t)return n==="timeZone"&&e?e:void 0;if(n==="fields")return s&&t.fields?.[s]||void 0;let r=t.path??[];switch(n){case"name":return t.name||void 0;case"type":return t.type||void 0;case"tags":return t.tags?.length?t.tags.join(", "):void 0;case"location":return r.at(-1)?.name;case"path":return r.length?r.map(o=>o.name).join(" \u203A "):void 0;case"timeZone":return e||void 0;default:return It[n]?[...r].reverse().find(o=>o.kind===It[n])?.name:void 0}}function $s(t,e){if(t==null||t==="")return;let n=String(t);if(e==="currency"){let s=Number(t);return Number.isFinite(s)?s.toFixed(2):n}if(e==="date"){let s=Date.parse(n);return Number.isNaN(s)?n:new Date(s).toISOString().slice(0,10)}return e==="truncate"&&n.length>40?n.slice(0,39)+"\u2026":n}function Ve(t,e){return(t.source==="screen"?xe(e.screen,e.timeZone,t.field,t.key):$s(e.tables?.[t.table]?.rows?.[t.row??0]?.[t.column],t.format))??t.fallback??""}function Ds(t){let e=/^\s*(?:screen\.(fields\.[a-z][A-Za-z0-9]{0,31}|[A-Za-z]+)|table\.([A-Za-z0-9_-]+)\[(\d+)\](?:\.([A-Za-z0-9_]+)|\["((?:[^"\\]|\\.)*)"\]))\s*((?:\|\s*(?:[a-z]+|"(?:[^"\\]|\\.)*")\s*)*)$/.exec(t);if(!e)return null;let n=[...e[6].matchAll(/\|\s*([a-z]+|"((?:[^"\\]|\\.)*)")/g)],s=n.find(o=>o[1].startsWith('"'))?.[2]?.replace(/\\(.)/g,"$1"),r=n.find(o=>!o[1].startsWith('"'))?.[1];return e[1]!==void 0?r?null:e[1].startsWith("fields.")?{source:"screen",field:"fields",key:e[1].slice(7),...s!==void 0?{fallback:s}:{}}:Ns.includes(e[1])?{source:"screen",field:e[1],...s!==void 0?{fallback:s}:{}}:null:r&&!Os.includes(r)?null:{source:"table",table:e[2],row:Number(e[3]),column:e[4]??e[5].replace(/\\(.)/g,"$1"),...r?{format:r}:{},...s!==void 0?{fallback:s}:{}}}function Ke(t,e){return t.replace(/\{{2}([^{}]*)\}{2}/g,(n,s)=>{let r=Ds(s);return r?Ve(r,e):n})}function Ct(t,e){return Object.fromEntries(Object.entries(t).map(([n,s])=>[n,typeof s=="string"?Ke(s,e):s]))}var Ze=t=>t==null||t==="";function Nt(t,e,n,s,r,o){return js(t,e,n,s,{now:r,timeZone:o})}function js(t,e,n,s,r){if(n===null&&(e==="eq"||e==="ne"))return e==="eq"?Ze(t):!Ze(t);if(Ze(t)||n===null||n===void 0)return!1;switch(s){case"number":case"currency":{let o=Number(t),i=Number(n);return typeof n!="boolean"&&n!==""&&Number.isFinite(o)&&Number.isFinite(i)&&Je(e,o-i)}case"boolean":{let o=n===!0||n==="true"?!0:n===!1||n==="false"?!1:void 0;return o!==void 0&&(e==="eq"?t===o:e==="ne"?t!==o:!1)}case"date":{let o=n==="today"?Fs(r.now,r.timeZone).date:String(n),i=String(t).slice(0,10);return/^\d{4}-\d{2}-\d{2}$/.test(o)&&Je(e,i<o?-1:i>o?1:0)}case"datetime":{let o=Date.parse(String(t)),i=n==="now"?r.now:Date.parse(String(n));return!Number.isNaN(o)&&!Number.isNaN(i)&&Je(e,o-i)}default:{let o=String(t).toLowerCase(),i=String(n).toLowerCase();return e==="eq"?o===i:e==="ne"?o!==i:e==="contains"?o.includes(i):!1}}}function Je(t,e){switch(t){case"eq":return e===0;case"ne":return e!==0;case"lt":return e<0;case"lte":return e<=0;case"gt":return e>0;case"gte":return e>=0;default:return!1}}var Rt=new Map;function Fs(t,e){let n=Rt.get(e);n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",weekday:"short"}),Rt.set(e,n));let s=Object.fromEntries(n.formatToParts(new Date(t)).map(r=>[r.type,r.value]));return{date:`${s.year}-${s.month}-${s.day}`,minute:Number(s.hour)%24*60+Number(s.minute),day:String(s.weekday).slice(0,3).toLowerCase()}}var Ot=(t,e)=>!t||(t.from===void 0||t.from<=e)&&(t.until===void 0||e<t.until);var ie=class{constructor(e,n,s,r,o){h(this,"renderer",e);h(this,"wrap",r);h(this,"onShown",o);h(this,"timer");h(this,"turns",0);h(this,"turnAt");h(this,"left");h(this,"stopped",!1);h(this,"share");h(this,"pages");this.pages=n.pages??[],this.share=n.durationMs/Math.max(1,this.pages.length),this.turnAt=s+this.share,this.arm()}arm(){clearTimeout(this.timer);let e=this.pages.length;if(this.stopped||this.left!==void 0||e<2||!this.wrap&&this.turns+1>=e)return;let n=this.pages[(this.turns+1)%e];this.renderer.prepare?.(n).catch(()=>{}),this.timer=setTimeout(()=>{this.turn(n)},Math.min(Math.max(0,this.turnAt-Date.now()),2**31-1))}async turn(e){try{await this.renderer.show(e)}catch{}this.stopped||(this.turns++,this.turnAt+=this.share,this.onShown?.(e),this.arm())}pause(){this.stopped||this.left!==void 0||(clearTimeout(this.timer),this.left=Math.max(0,this.turnAt-Date.now()))}resume(){this.stopped||this.left===void 0||(this.turnAt=Date.now()+this.left,this.left=void 0,this.arm())}stop(){if(!this.stopped){this.stopped=!0,clearTimeout(this.timer);for(let e of this.pages)this.renderer.release?.(e)}}};var Ye=class extends Error{constructor(n,s){super(s);h(this,"code",n);this.name="MediaError"}};function Xe(t){return t instanceof Ye?{code:t.code.slice(0,64),message:t.message.slice(0,1e3)}:{code:"not-shown",message:String(t instanceof Error?t.message:t??"").slice(0,1e3)}}var $t=t=>t.blob.contentType.startsWith("video/");var Ge="position:absolute;inset:0;width:100%;height:100%;object-fit:contain",Bs=1,Me=class{constructor(e,n={}){h(this,"container",e);h(this,"options",n);h(this,"prepared",new Map);h(this,"shown",null);h(this,"endListeners",new Set);h(this,"itemListeners",new Set);h(this,"appListeners",new Set);h(this,"held",null);h(this,"drawn",0);h(this,"shownHash",null);let s=n.media;s&&(document.documentElement.style.background="transparent",document.body.style.background="transparent",e.style.background="#000",s.onEnd((r,o)=>{let i=this.shown;if(i?.mediaId===r)for(let a of this.endListeners)a(i.slide,o)}))}onMediaEnd(e){this.endListeners.add(e)}onElementItem(e){this.itemListeners.add(e)}onApp(e){this.appListeners.add(e)}app(e){for(let n of this.appListeners)n(e);this.options.onApp?.(e)}prepare(e){let n=this.prepared.get(e);if(n)return n.ready;let s;try{s=this.make(e)}catch(r){return Promise.reject(r)}return this.prepared.set(e,s),s.ready.catch(()=>{this.prepared.get(e)===s&&(this.prepared.delete(e),this.dispose(s))}),s.ready}release(e){let n=this.prepared.get(e);n&&(this.prepared.delete(e),this.dispose(n))}async show(e){await this.prepare(e);let n=this.prepared.get(e);if(!n)throw new Error("the slide was released before it was shown");this.prepared.delete(e);let s=this.shown,r=this.options.media,o=s?jt(e):void 0;if(n.kind==="layout"&&o===void 0){await B(()=>{s?this.container.insertBefore(n.el,s.el):this.container.append(n.el),this.shown=n,this.shownHash=e.blob.hash}),this.held=[],await n.view.start().catch(()=>{});let i=Promise.resolve();return await B(()=>{this.shown===n&&(n.el.style.visibility="",s?.el.remove(),r&&this.paint("transparent"),r&&s?.mediaId&&(i=r.show([],[s.mediaId],Date.now())))}),await i.catch(()=>{}),s&&this.dispose(s),this.releaseHeld(),"cut"}if(o!==void 0&&r&&n.kind==="native"&&s.kind==="native"){if(n.fadesIn&&!n.queued){let i=Promise.resolve();return await B(()=>{n.el.style.visibility="",this.container.insertBefore(n.el,s.el),i=r.show([n.mediaId],[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),Us(o).then(async()=>{await r.show([],[s.mediaId],Date.now()).catch(()=>{}),s.el.remove(),this.dispose(s)}),"crossfade"}}else if(o!==void 0&&r&&n.kind==="native"){let i=Promise.resolve();return await B(()=>{n.el.style.visibility="",this.container.insertBefore(n.el,s.el),i=r.show([n.mediaId],[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),this.paint("transparent"),Ft(s.el,1,0,o).then(()=>{s.el.remove(),this.dispose(s)}),"crossfade"}else if(o!==void 0)return await B(()=>{n.el.style.visibility="",n.el.style.opacity="0",this.container.append(n.el),n.kind==="video"&&Qe(n.el),this.shown=n,this.shownHash=e.blob.hash}),n.view&&(this.held=[],n.view.start().then(()=>this.releaseHeld())),Ft(n.el,0,1,o).then(async()=>{s.el.remove(),this.shown===n&&this.paint(r?"#000":""),r&&s.mediaId&&await r.show([],[s.mediaId],Date.now()).catch(()=>{}),this.dispose(s)}),"crossfade";if(r&&n.kind==="native"){let i=Promise.resolve();await B(()=>{n.el.style.visibility="",s?this.container.insertBefore(n.el,s.el):this.container.prepend(n.el),i=r.show([n.mediaId],s?.mediaId?[s.mediaId]:[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),await B(()=>{this.shown===n&&(s?.el.remove(),this.paint("transparent"))})}else{let i=Promise.resolve();await B(()=>{n.el.style.visibility="",n.el.parentNode!==this.container&&this.container.append(n.el),s?.el.remove(),this.paint(r?"#000":""),r&&s?.mediaId&&(i=r.show([],[s.mediaId],Date.now())),n.kind==="video"&&Qe(n.el),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{})}return s&&this.dispose(s),"cut"}paint(e){this.options.background?this.options.background(e):this.container.style.background=e}standby(){let e=this.shown;this.shown=null,this.shownHash=null,this.paint(this.options.media?"#000":""),e&&(e.mediaId&&this.options.media?.show([],[e.mediaId],Date.now()).catch(()=>{}),this.dispose(e))}pause(){let e=this.shown;e?.view?.pause(),e?.kind==="video"?e.el.pause():e?.mediaId&&this.options.media?.control(e.mediaId,"pause").catch(()=>{})}resume(){let e=this.shown;e?.view?.resume(),e?.kind==="video"?Qe(e.el):e?.mediaId&&this.options.media?.control(e.mediaId,"play").catch(()=>{})}make(e){if(e.layout){let{doc:i,source:a,untilPass:p}=e.layout,l=Z(j("div"));l.dataset.blob=e.blob.hash,l.style.cssText=`${Ge};visibility:hidden`,this.container.append(l);let c={slide:e,kind:"layout",el:l,ready:Promise.resolve()},d=g=>this.options.path?`${this.options.path}/${g}`:g,m=String(++this.drawn);return c.view=new Y(i,a,l,{media:this.options.media,path:this.options.path,endsWith:p?d(p):void 0,onItem:g=>{let w={...g,slide:g.slide?`${m}.${g.slide}`:m};this.held?this.held.push(w):this.item(w)},onPassEnd:g=>{if(p&&g===d(p)&&this.shown===c){for(let w of this.endListeners)w(e);return"hold"}return this.options.onPassEnd?.(g)},onApp:g=>this.app(g)}),c.ready=c.view.ready,c}if(!$t(e)){if(!e.bytes&&!e.url)throw new Error(`no bytes for ${e.blob.hash}`);let i=e.bytes?URL.createObjectURL(new Blob([e.bytes],{type:e.blob.contentType})):void 0,a=Z(j("img"));return a.src=i??e.url,a.alt="",a.dataset.blob=e.blob.hash,a.style.cssText=this.fill(),{slide:e,kind:"image",el:a,objectUrl:i,ready:a.decode()}}let n=this.options.media;if(n){let i=`m-${Bs++}`,a=Z(j("div"));a.dataset.blob=e.blob.hash,a.dataset.media=i,a.style.cssText=`${Ge};visibility:hidden`;let p=this.container.getBoundingClientRect(),l={x:p.left,y:p.top,w:p.width||window.innerWidth,h:p.height||window.innerHeight},c=jt(e),d=c!==void 0&&this.shown?.kind==="native"&&n.capability.animates&&n.capability.layers>=2,m=d?[{property:"opacity",keyframes:[{t:0,v:0},{t:c,v:1}]}]:[],g={slide:e,kind:"native",el:a,mediaId:i,fadesIn:d,ready:Promise.resolve()},w=this.options.fit??"contain";return g.ready=n.prepare({mediaId:i,blob:e.blob.hash,contentType:e.blob.contentType,box:l,z:d?1:0,loop:e.loop,muted:!1,fit:w,...d?{tracks:m}:{}}).then(f=>{f.queued&&(g.queued=!0)}),g}let s=e.url?void 0:URL.createObjectURL(new Blob([e.bytes],{type:e.blob.contentType})),r=Z(j("video"));r.dataset.blob=e.blob.hash,r.style.cssText=`${this.fill()};visibility:hidden`,r.muted=!1,r.playsInline=!0,r.preload="auto",r.loop=e.loop,r.src=e.url??s,r.addEventListener("ended",()=>{if(this.shown?.el===r)for(let i of this.endListeners)i(e)}),r.addEventListener("error",()=>{if(this.shown?.el===r)for(let i of this.endListeners)i(e,`video: ${r.error?.message??"error"}`)});let o=new Promise((i,a)=>{if(r.readyState>=2)return i();r.addEventListener("loadeddata",()=>i(),{once:!0}),r.addEventListener("error",()=>a(new Error(`video: ${r.error?.message??"cannot load"}`)),{once:!0})});return this.container.append(r),{slide:e,kind:"video",el:r,objectUrl:s,ready:o}}item(e){this.options.onItem?.(e);for(let n of this.itemListeners)n(e)}releaseHeld(){let e=this.held;this.held=null,e?.length&&setTimeout(()=>{for(let n of e)this.item(n)},0)}fill(){let e=this.options.fit==="stretch"?"fill":this.options.fit??"contain";return Ge.replace("object-fit:contain",`object-fit:${e}`)}dispose(e){if(this.shown!==e){if(e.view?.dispose(),e.el.remove(),e.kind==="video"){let n=e.el;n.pause(),n.removeAttribute("src"),n.load()}e.mediaId&&this.options.media?.release(e.mediaId).catch(()=>{}),e.objectUrl&&URL.revokeObjectURL(e.objectUrl)}}};function jt(t){if(t.transition?.type==="crossfade")return Math.max(0,Math.min(t.transition.durationMs??1e3,t.durationMs/2))}var Us=t=>new Promise(e=>setTimeout(e,t));function Ft(t,e,n,s){return new Promise(r=>{let o=Date.now(),i=!1,a=()=>{i||(i=!0,t.style.opacity=n===1?"":String(n),r())};t.style.opacity=String(e);let p=()=>{if(i)return;let l=Math.min(1,(Date.now()-o)/s);if(l>=1)return a();t.style.opacity=String(e+(n-e)*l),requestAnimationFrame(p)};requestAnimationFrame(p),setTimeout(a,s+250)})}function Qe(t){t.play().catch(()=>(t.muted=!0,t.play())).catch(()=>{})}function B(t){return new Promise((e,n)=>{let s=!1,r=()=>{if(!s){s=!0;try{t(),e()}catch(o){n(o)}}};requestAnimationFrame(r),setTimeout(r,250)})}var oe={apiVersion:2,properties:[{name:"device",description:"What the device is: id, type, shell and versions, model, resolution and orientation. Fixed while the player runs."},{name:"mode",description:"Where player-core runs: player, preview (in the CMS) or designer. In preview and the designer, commands change nothing."},{name:"timeZone",description:"The player's time zone (IANA), from the host.",event:"time.changed"},{name:"locale",description:"The player's locale (BCP 47), from the host."},{name:"connection",description:"Whether the player is connected to Wyndlass.",event:"connection.changed"},{name:"state",description:"starting, playing, paused, stopped (the standby screen), idle (nothing to play) or error.",event:"state.changed"},{name:"held",description:"A remote pause or stop in effect, by whom and since when; absent when none.",event:"state.changed"},{name:"content",description:"The manifest playing, when it was issued and switched to; absent when there is none.",event:"content.updated"},{name:"now",description:"What each zone shows: the item, its blob and content type, when it started, and its duration and position when known.",event:"item.start"},{name:"audio",description:"The player's volume (0 to 100) and whether it is muted; only when the host can set them.",event:"audio.changed"},{name:"display",description:"The display's power and brightness; only when the host can report them.",event:"display.changed"},{name:"capabilities",description:"What the host can do: audio, display power, display brightness."}],events:[{name:"state.changed",description:"The player's state changed (playing, paused, stopped, idle, error), and who changed it."},{name:"content.updated",description:"A new manifest was switched to."},{name:"item.start",description:"An item started in a zone (source start)."},{name:"item.end",description:"An item ended in a zone (source end): completed, skipped, stopped, error, replaced by new content, or finished by its app."},{name:"item.error",description:"An item could not be shown."},{name:"connection.changed",description:"The player connected to Wyndlass or lost its connection."},{name:"audio.changed",description:"The volume or mute changed, and who changed it."},{name:"display.changed",description:"The display's power or brightness changed, and who changed it."},{name:"time.changed",description:"The clock was adjusted or the time zone changed."},{name:"app.command",description:"A command for apps on the screen (apps.sendCommand); an app reacts if it knows the name."},{name:"app.failed",description:"An app on the screen could not run, or misbehaved (WP-0100): its bundle did not load, it was not an app, it needs a newer player, it kept throwing and was stopped, or it was late or overran a clip."},{name:"app.held",description:"An app version was held back on this screen until the next manifest, after the page stopped answering twice in an hour while it was on screen (WP-0100)."}],commands:[{name:"player.status",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/status",description:"Everything about the player now: device, mode, time zone, locale, connection, state (and any hold), the content playing, what each zone shows, audio, display and what the host can do. Changes nothing.",idempotent:!0},{name:"player.events",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/events",result:"player-api-results.schema.json#/$defs/events",description:"The player's recent events (the last 200), oldest first, after a sequence number: state changes, content updates, item starts and ends, errors, connection, audio, display and time. Pass next as after to poll for more. Changes nothing.",idempotent:!0},{name:"time.now",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/timeNow",description:"The player's current time, its time zone and UTC offset, and whether its clock is synchronized. Changes nothing.",idempotent:!0},{name:"player.play",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Resumes or starts playback on the screen. From a remote caller it also ends a remote pause or stop.",idempotent:!0},{name:"player.pause",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Freezes the screen on what it shows now: the loop's timer and any media stop where they are. From a remote caller it holds until a remote player.play or a restart; apps cannot resume it, and new content arrives paused.",idempotent:!0},{name:"player.stop",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Stops playback and shows the standby screen (black, display on). From a remote caller it holds until a remote player.play or a restart; apps cannot restart it, and new content arrives stopped.",idempotent:!0},{name:"player.next",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Skips to the next item in a zone (main by default); the current item ends as skipped."},{name:"player.previous",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Goes back to the previous item in a zone (main by default); the current item ends as skipped."},{name:"player.playItem",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/playItem",result:"player-api-results.schema.json#/$defs/now",description:"Shows a given item of the content playing now in a zone (main by default), then continues the loop from it. Refused for an item the playing manifest does not have."},{name:"audio.setVolume",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setVolume",result:"player-api-results.schema.json#/$defs/audio",description:"Sets the player's volume, 0 to 100. Only on players whose host can set it to a level.",needs:"audio.volume",idempotent:!0},{name:"audio.setMuted",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setMuted",result:"player-api-results.schema.json#/$defs/audio",description:"Mutes or unmutes the player. Only on players whose host can.",needs:"audio",idempotent:!0},{name:"display.setPower",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setPower",result:"player-api-results.schema.json#/$defs/display",description:"Turns the display on or to standby. Only on players whose host can. Standby blanks the screen until it is turned on.",needs:"display.power",idempotent:!0},{name:"display.setBrightness",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setBrightness",result:"player-api-results.schema.json#/$defs/display",description:"Sets the display's brightness, 0 to 100. Only on players whose host can.",needs:"display.brightness",idempotent:!0},{name:"apps.sendCommand",access:"control",apps:"none",remote:!0,params:"player-api-params.schema.json#/$defs/sendCommand",result:"player-api-results.schema.json#/$defs/delivered",description:"Sends a named command, with an optional argument, to the apps on the screen; an app that knows the name reacts. Returns how many apps listen."},{name:"app.finish",access:"control",apps:"read",remote:!1,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/none",description:"An app ends its own slot now: its item ends as finished and the loop moves on. Apps only; not a tool."}],host:[{name:"host.describe",kind:"request",description:"What the device is, its time zone, locale, connection and capabilities.",result:"player-api-host.schema.json#/$defs/describeResult"},{name:"host.time",kind:"request",description:"The host's time and time zone.",result:"player-api-common.schema.json#/$defs/timeNow"},{name:"host.getAudio",kind:"request",description:"The player's volume and mute.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.setAudio",kind:"request",description:"Sets the volume, the mute or both; answers the audio after.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.getDisplay",kind:"request",description:"The display's power and brightness.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.setDisplay",kind:"request",description:"Sets the display's power, brightness or both; answers the display after.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.adRequest",kind:"request",description:"Asks Wyndlass's ad broker for one slot of a break over the host's NATS connection (WP-0075); the result is the broker's ad-decision (ad-decision.schema.json). Only a host whose describe says ads is asked."},{name:"host.mediaPrepare",kind:"request",description:"Lays a video out behind the page and prepares it to its first frame; host.mediaState says when (ADR 0055)."},{name:"host.mediaShow",kind:"request",description:"Shows and hides prepared videos; replies once its layer has changed."},{name:"host.mediaControl",kind:"request",description:"Plays, pauses or seeks a video, or asks for its position."},{name:"host.mediaRelease",kind:"request",description:"Removes a video and frees its decoder."},{name:"host.reply",kind:"reply",description:"The host's answer to a request: result or error (unsupported, failed)."},{name:"host.connection",kind:"event",description:"The connection to Wyndlass changed."},{name:"host.timeChanged",kind:"event",description:"The clock was adjusted or the time zone changed."},{name:"host.audioChanged",kind:"event",description:"The volume or mute changed outside the player."},{name:"host.displayChanged",kind:"event",description:"The display changed outside the player."},{name:"host.mediaState",kind:"event",description:"A video was prepared, started, ended or failed, or its position was asked for."},{name:"host.presence",kind:"event",description:"What one of the host's sensors sees now: the presences in view, with random ids that never leave the page (WP-0105)."},{name:"host.sensing",kind:"event",description:"The site's sensing mode as the host applies it, and its sensors (WP-0105)."},{name:"host.serialPorts",kind:"event",description:"The host's sensor controller ports, and which are open (WP-0043)."},{name:"host.serialLine",kind:"event",description:"One line from a sensor controller, as it arrived (WP-0043)."},{name:"host.serialWrite",kind:"request",description:"Writes lines to a sensor controller, a gap apart; replies once written (WP-0043)."},{name:"host.bleWatch",kind:"request",description:"What the page listens for: beacons' iBeacon UUIDs, Eddystone namespaces and addresses; replies once the scan follows it. Sent only to a host that has sent host.bleState (WP-0044)."},{name:"host.bleAdverts",kind:"event",description:"Beacon frames that match the watch, at most four a second of each kind from each beacon (WP-0044)."},{name:"host.bleState",kind:"event",description:"The host's Bluetooth scanner: scanning, idle, off, refused, missing or failed; sent only by a host that has one (WP-0044)."},{name:"host.gpioPins",kind:"event",description:"The GPIO pins the host reads, with their values (WP-0044)."},{name:"host.gpioEdge",kind:"event",description:"A GPIO pin changed (WP-0044)."},{name:"host.mcp",kind:"relay",description:"An MCP message from ctl.dev.{deviceId}, for player-core to answer."},{name:"core.ready",kind:"core",description:"player-core is ready to answer host.mcp; until then the shell answers -32002 itself."},{name:"core.mcpReply",kind:"core",description:"player-core's answer to a host.mcp, for the shell to send back."},{name:"core.sensors",kind:"core",description:"The page's sensor controllers, channels and inputs, and the beacons it hears, whenever they change, for the heartbeat and sensors.recent (WP-0043, WP-0044)."}]};var Ht=Symbol.for("wyndlass.app.attach");var H=class extends Error{constructor(n,s){super(`the app could not run (${n})`);h(this,"reason",n);h(this,"error",s)}};function V(t){try{let e=t instanceof Error?t.name:void 0;return typeof e=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(e)?e:void 0}catch{return}}function ae(t){let e=t?.id;if(typeof e!="string"||e==="")return!0;for(let n=0;n<Bt.length;n++)if(e[n]!==Bt[n])return!1;return!0}var Bt="com.wyndlass.";function _s(t=typeof navigator>"u"?"":navigator.userAgent){let e=/Chrom(?:e|ium)\/(\d+)/.exec(t);return e?Number(e[1]):void 0}function Ut(t,e=oe.apiVersion,n=_s()){return!(t?.playerApi!==void 0&&t.playerApi>e||t?.webView!==void 0&&n!==void 0&&t.webView>n)}function Ws(t){let e;try{e=t.paging?.()}catch{return null}let n=e;return n&&Number.isInteger(n.count)&&n.count>1&&typeof n.ms=="number"&&n.ms>0?{count:n.count,ms:n.ms}:null}var et=new Map;function zs(){let t=St(8),e="";for(let n=0;n<8;n++)e+=Vs[t[n]%26];return e}var Vs="abcdefghijklmnopqrstuvwxyz",Ks=0;function qt(t,e,n){let s=et.get(t);if(!s){let r=Fe.make([e],"text/javascript");s=import(r).then(o=>Zs(o,n),o=>{throw o instanceof H?o:new H("load",V(o))}).finally(()=>Fe.revoke(r)),et.set(t,s),s.catch(()=>et.delete(t))}return s}function Zs(t,e){let n=t.default;if(typeof n=="function"&&n.prototype instanceof HTMLElement){let s=n.prototype[Ht];if(typeof s!="function")throw new H("shape");let r=class extends n{},o=`${e?.element??"wl-app"}-${zs()}${++Ks}`;try{Be.define(o,r)}catch(i){throw new H("shape",V(i))}return{tag:o,shape:"class",attach:(i,a)=>{Et(s,i,[a])}}}if(ae(e)&&typeof t.element=="string"&&Be.get(t.element))return{tag:t.element,shape:"legacy"};throw new H("shape")}var Js=3,Ys=6e4,Ae=class{constructor(e,n){h(this,"element",e);h(this,"o",n);h(this,"faults",[]);h(this,"halted",!1)}get stopped(){return this.halted}has(e){try{return!this.halted&&typeof this.element[e]=="function"}catch{return!1}}update(e){this.halted||this.run(()=>this.element.update?.(e))}reset(){this.halted||this.run(()=>this.element.reset?.())}paging(){return this.halted?null:Ws(this.element)}hook(e,n){if(this.halted)return Promise.resolve();let s;try{s=this.element[e]?.(n)}catch(r){return this.fault(r),Promise.resolve()}return Promise.resolve(s).then(()=>{},r=>this.fault(r))}stop(e){if(!this.halted){this.halted=!0;try{this.element.remove()}catch{}this.o.dispose?.(),this.o.onStop(e)}}dispose(){this.o.dispose?.()}run(e){try{e()}catch(n){this.fault(n)}}fault(e){let n=(this.o.now??Date.now)();this.faults=this.faults.filter(s=>n-s<Ys),this.faults.push(n),this.faults.length>=Js&&this.stop(V(e))}},Xs=24*3600*1e3,Ee=class t{constructor(e){h(this,"o",e);h(this,"memory",new Map);h(this,"inflight",new Map);h(this,"images",new Map);h(this,"pictures",new Map)}now(){return this.o.now?.()??Date.now()}url(e){let n=this.o.base();if(!n)return;let s=this.o.token(),r=`${n.replace(/\/$/,"")}${e}`;return s?`${r}${r.includes("?")?"&":"?"}${s}`:r}stored(e){return this.memory.get(e)??this.o.store?.getItem(e)??void 0}static keyOf(e,n){let s=Object.keys(n).sort().map(r=>`${encodeURIComponent(r)}=${encodeURIComponent(String(n[r]))}`).join("&");return{query:s,key:`wyndlass:data:${e}?${s}`}}kept(e,n){let s=this.stored(t.keyOf(e,n).key);if(s)try{let r=JSON.parse(s);return this.dress(r,Date.parse(r.expiresAt)<=this.now())}catch{return}}keep(e,n){this.memory.set(e,n);try{this.o.store?.setItem(e,n)}catch{}}get(e,n){let{query:s,key:r}=t.keyOf(e,n),o=this.inflight.get(r);if(o)return o;let i=this.o.fetch??fetch,a=(async()=>{let p=this.stored(r),l=p?JSON.parse(p):void 0;if(l&&Date.parse(l.expiresAt)>this.now())return this.dress(l,!1);let c=this.url(`/v0/${encodeURIComponent(e)}?${s}`);try{if(!c)throw new Error("no data service");let d=await i(c);if(!d.ok)throw new Error(`the data service answered ${d.status}`);let m=await d.text();return this.keep(r,m),this.dress(JSON.parse(m),!1)}catch(d){if(l&&Date.parse(l.expiresAt)+Xs>this.now())return this.dress(l,!0);throw d}})().finally(()=>this.inflight.delete(r));return this.inflight.set(r,a),a}dress(e,n){return{...e,offline:n,ageMs:Math.max(0,this.now()-Date.parse(e.fetchedAt))}}image(e){let n=this.images.get(e);return n||(n=this.imageBlob(e).then(s=>URL.createObjectURL(s)),this.images.set(e,n),n.catch(()=>this.images.delete(e))),n}imageBlob(e){let n=this.pictures.get(e);if(!n){let s=this.url(e);n=s?(this.o.fetch??fetch)(s).then(r=>{if(!r.ok)throw new Error(`the image answered ${r.status}`);return r.blob()}):Promise.reject(new Error("no data service")),this.pictures.set(e,n),n.catch(()=>this.pictures.delete(e))}return n}};var _t="wyndlass.frame";function Vt(t,e){return!!t&&(t.apps?t.apps(e):!ae(e))}var Gs=new Set(["load","shape","unsupported","error","late","overran"]),Wt=50,zt=250,tt=class{constructor(e,n,s,r){h(this,"frame",e);h(this,"port",n);h(this,"o",r);h(this,"halted",!1);h(this,"pages");h(this,"hooks");h(this,"pending",new Map);h(this,"next",0);h(this,"told");h(this,"last");h(this,"quiet");this.hooks=new Set(s.hooks),this.pages=s.paging}get stopped(){return this.halted}has(e){return!this.halted&&this.hooks.has(e)}paging(){return this.halted?null:this.pages}update(e){if(this.halted)return;let n=performance.now(),s=this.last;this.last={t:e,at:n};let r=this.told;if(r&&(r.running?Math.abs(e-(r.t+(n-r.at)))<=Wt:e===r.t)){r.running&&this.watch();return}let o=!!s&&n-s.at<zt&&e>s.t&&Math.abs(e-s.t-(n-s.at))<=Wt;this.told={t:e,at:n,running:o},this.post({type:"clock",t:e,running:o}),o&&this.watch()}reset(){this.halted||this.post({type:"reset"})}hook(e,n){if(this.halted)return Promise.resolve();let s=++this.next;return new Promise(r=>{this.pending.set(s,r),this.post({type:"hook",id:s,kind:e,options:n})})}stop(e){this.halted||(this.halted=!0,this.frame.remove(),this.dispose(),this.o.onStop(e))}dispose(){clearTimeout(this.quiet),this.port.close();for(let e of this.pending.values())e();this.pending.clear()}heard(e){e.type==="paging"?this.pages=Zt(e.paging):e.type==="hooked"&&typeof e.id=="number"?(this.pending.get(e.id)?.(),this.pending.delete(e.id)):e.type==="stopped"&&this.stop(Jt(e.error))}post(e){try{this.port.postMessage(e)}catch{}}watch(){clearTimeout(this.quiet),this.quiet=setTimeout(()=>{!this.told?.running||!this.last||this.halted||(this.told={...this.last,running:!1},this.post({type:"clock",t:this.last.t,running:!1}))},zt)}};async function Kt(t,e,n,s,r,o,i,a,p,l){let c=t.appInfo??n.info,d;try{d=new URL(p.frames).origin}catch{return l("unsupported")}let m=document.createElement("iframe");m.setAttribute("sandbox","allow-scripts"),m.setAttribute("referrerpolicy","no-referrer"),m.title=c?.id??"app",m.tabIndex=-1,m.dataset.frame=c?.id??"",m.style.cssText="display:block;width:100%;height:100%;border:0;pointer-events:none;background:transparent;color-scheme:normal";let g=new Promise(A=>{m.addEventListener("load",()=>A(!0),{once:!0}),setTimeout(()=>A(!1),o)});m.src=`${d}/`,e.append(m);let w=(A,k)=>(m.remove(),l(A,k));if(!await g||!m.contentWindow)return w("load");let{port1:f,port2:b}=new MessageChannel,v={type:"init",element:{id:t.id,type:"app",app:t.app,props:t.props??{},...t.binding?{binding:t.binding}:{},...t.appInfo?{appInfo:t.appInfo}:{}},bundle:{hash:n.hash,bytes:n.bytes.slice(),...n.info?{info:n.info}:{}},...s.place?{place:s.place}:{},screen:s.screen??null,timeZone:s.timeZone,locale:s.locale,preview:!!s.preview,clock:{t:r.now(),running:!1,startedAt:r.startedAt()},fonts:tr(t.props??{},p),snapshots:nr(t,s),deadlineMs:o};return new Promise(A=>{let k,P=!1,N=Q=>{P||(P=!0,clearTimeout(F),A(Q))},F=setTimeout(()=>{k?(N({app:k,late:!0}),k.update(r.now())):(f.close(),N(w("load")))},o+1e3),W=!1;f.onmessage=Q=>{let M=Q.data;if(!(!M||typeof M!="object")){if(M.type==="ask"){W&&Qs(M,s,f);return}if(k){M.type==="ready"?(N({app:k,late:M.late===!0}),k.update(r.now())):k.heard(M);return}M.type==="hello"&&!W?(W=!0,f.postMessage(v,[v.bundle.bytes.buffer])):M.type==="made"&&Array.isArray(M.hooks)?(k=new tt(m,f,{type:"made",hooks:M.hooks.filter(C=>C==="enter"||C==="exit"),paging:Zt(M.paging)},{onStop:a}),i(k)):M.type==="failed"&&(f.close(),N(w(Gs.has(M.reason)?M.reason:"error",Jt(M.error))))}},m.contentWindow.postMessage({type:_t},"*",[b])})}async function Qs(t,e,n){if(typeof t.id!="number")return;let s=(r,o=[])=>{try{n.postMessage(r,o)}catch{}};try{if(!e.data)throw new Error("no data service");if(t.what==="data"&&typeof t.source=="string")s({type:"answer",id:t.id,value:await e.data.get(t.source,er(t.params))});else if(t.what==="image"&&typeof t.path=="string"){let r=await e.data.imageBlob(t.path),o=new Uint8Array(await r.arrayBuffer());s({type:"answer",id:t.id,value:{bytes:o,type:r.type}},[o.buffer])}else throw new TypeError("not a question")}catch(r){s({type:"answer",id:t.id,error:V(r)??"Error"})}}function er(t){let e={};if(t&&typeof t=="object")for(let[n,s]of Object.entries(t))(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(e[n]=s);return e}function Zt(t){let e=t;return e&&Number.isInteger(e.count)&&e.count>1&&typeof e.ms=="number"&&e.ms>0?{count:e.count,ms:e.ms}:null}function Jt(t){return typeof t=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(t)?t:void 0}function tr(t,e){let n=new Set;for(let r of Object.values(t)){let o=r?.family;r&&typeof r=="object"&&typeof o=="string"&&n.add(o)}let s=[];for(let r of e.fonts??[]){let o=n.has(r.family)?e.font?.(r.blob):void 0;o&&s.push({family:r.family,weight:r.weight,style:r.style,blob:r.blob,bytes:o.slice()})}return s}function nr(t,e){let n=new Set;t.binding?.table&&n.add(t.binding.table);for(let r of Object.values(t.props??{}))typeof r=="string"&&/^tbl_[0-9a-z]{26}$/.test(r)&&n.add(r);let s={};for(let r of n){let o=e.snapshot?.(r);o&&(s[r]=o)}return s}function Yt(t){let e=ne?.setStyle??((n,s,r,o)=>n.style.setProperty(s,r,o));e(t,"contain","strict","important"),e(t,"overflow","clip","important")}var Xt=t=>!!(t?.filter?.length||t?.sort||t?.limit),sr=t=>t==null||t==="";function rr(t,e){if(!sr(t))switch(e){case"number":case"currency":{let n=Number(t);return Number.isFinite(n)?n:void 0}case"datetime":{let n=Date.parse(String(t));return Number.isNaN(n)?void 0:n}case"boolean":return t===!0||String(t).toLowerCase()==="true"?1:0;case"date":return String(t).slice(0,10);default:return String(t).toLowerCase()}}function ir(t,e){let n=Array.from(t),s=Array.from(e);for(let r=0;r<n.length&&r<s.length;r++){let o=n[r].codePointAt(0)-s[r].codePointAt(0);if(o!==0)return o}return n.length-s.length}function or(t,e,n,s,r){let o=t,i=Array.isArray(o?.rows)?o.rows:[],a=Array.isArray(o?.columns)?o.columns:void 0,p=l=>a?.find(c=>c.key===l)?.type??"text";for(let l of e.filter??[]){if(a&&!a.some(m=>m.key===l.column))return[];let c=l.value;if(c!==null&&typeof c=="object"){let m=c;if(c=xe(n,s,m.screen,m.key),c===void 0)return[]}let d=p(l.column);i=i.filter(m=>Nt(m[l.column],l.op,c,d,r,s))}if(e.sort){let{column:l}=e.sort,c=p(l),d=e.sort.order==="desc"?-1:1;i=i.map((m,g)=>({row:m,i:g,key:rr(m[l],c)})).sort((m,g)=>{if(m.key===void 0||g.key===void 0)return m.key===void 0&&g.key===void 0?m.i-g.i:m.key===void 0?1:-1;let w=typeof m.key=="number"&&typeof g.key=="number"?m.key-g.key:ir(String(m.key),String(g.key));return w===0?m.i-g.i:w<0?-d:d}).map(m=>m.row)}return e.limit?i.slice(0,e.limit):i}function Gt(t,e,n,s,r){return!t||typeof t!="object"?t:{...t,rows:or(t,e,n,s,r)}}function ar(t){if(!t)return"#000000";if("value"in t)return t.value;let e=t.gradient,n=[...e.stops].sort((s,r)=>s.at-r.at).map(s=>`${s.color.value} ${Math.round(s.at*1e4)/100}%`).join(", ");return e.kind==="radial"?`radial-gradient(circle, ${n})`:`linear-gradient(${e.angle??180}deg, ${n})`}function en(t,e,n,s=[]){let r=j("div");if(r.dataset.background="",r.style.cssText="position:absolute;inset:0;pointer-events:none",r.style.background=ar(e),s.length){let o=[`M0 0H${n.width}V${n.height}H0Z`,...s.map(p=>`M${p.x} ${p.y}H${p.x+p.w}V${p.y+p.h}H${p.x}Z`)].join(""),i=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${n.width} ${n.height}" preserveAspectRatio="none"><path fill-rule="evenodd" d="${o}"/></svg>`,a=`url("data:image/svg+xml,${encodeURIComponent(i)}")`;r.dataset.holes=String(s.length);for(let[p,l]of[["maskImage",a],["maskSize","100% 100%"],["maskRepeat","no-repeat"]])r.style[p]=l,r.style[`webkit${p[0].toUpperCase()}${p.slice(1)}`]=l}return t.prepend(r),r}function tn(t,e=t.frame){let n=j("div");return n.dataset.element=t.id,n.style.cssText="position:absolute;box-sizing:border-box",dr(n,e),n}function dr(t,e){Object.assign(t.style,{left:`${e.x}px`,top:`${e.y}px`,width:`${e.w}px`,height:`${e.h}px`,transform:e.rotation?`rotate(${e.rotation}deg)`:""})}function nn(t,e,n){if(e.type==="text"){let s=e.style??{},r=sn(n);t.textContent=e.bind?Ve(e.bind,r):Ke(e.text??"",r),Object.assign(t.style,{fontFamily:s.font?.family?`"${s.font.family}", sans-serif`:"",fontWeight:String(s.font?.weight??400),fontStyle:s.font?.style??"normal",fontSize:`${s.size??48}px`,color:s.color?.value??"#ffffff",background:s.background?.value??"",whiteSpace:"pre-wrap",textAlign:{start:"left",end:"right"}[s.align??"start"]??s.align??"left",display:"flex",flexDirection:"column",justifyContent:{top:"flex-start",middle:"center",bottom:"flex-end"}[s.verticalAlign??"top"],lineHeight:s.lineHeight?String(s.lineHeight):"",opacity:s.opacity!==void 0?String(s.opacity):"",textDecorationLine:s.decoration?.length?s.decoration.join(" "):"",textTransform:s.transform&&s.transform!=="none"?s.transform:"",letterSpacing:s.letterSpacing?`${s.letterSpacing}em`:"",textShadow:s.shadow?`${s.shadow.x??0}px ${s.shadow.y??2}px ${s.shadow.blur??4}px ${s.shadow.color?.value??"#000000"}`:""})}else e.type==="shape"&&lr(e)?(t.style.opacity=e.opacity!==void 0?String(e.opacity):"",t.append(pr(e))):e.type==="shape"?Object.assign(t.style,{background:e.fill?.value??"",opacity:e.opacity!==void 0?String(e.opacity):"",border:e.stroke?.width?`${e.stroke.width}px ${e.stroke.dash??"solid"} ${e.stroke.color?.value??"#000"}`:"",borderRadius:e.shape==="ellipse"?"50%":e.radius?`${e.radius}px`:"",overflow:e.clip!==!1?"hidden":""}):e.type==="library"&&(t.style.overflow="hidden",t.style.background=e.playback?.background?.value??"")}function sn(t){return{screen:t?.screen??null,timeZone:t?.timeZone,tables:new Proxy({},{get:(e,n)=>typeof n=="string"?t?.snapshot?.(n):void 0})}}var lr=t=>t.shape==="line"||t.shape==="arrow"||t.shape==="polygon";function pr(t){let e=be("svg");e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.style.cssText="position:absolute;inset:0;overflow:visible";let n=t.frame.w,s=t.frame.h,r=t.stroke?.width??(t.shape==="polygon"?0:4),i=(t.points?.length?t.points:t.shape==="polygon"?[[.5,0],[1,1],[0,1]]:[[0,.5],[1,.5]]).map(([c,d])=>[c*n,d*s]),a=t.stroke?.color?.value??"#000000",p=t.stroke?.dash==="dashed"?`${r*3} ${r*2}`:t.stroke?.dash==="dotted"?`0 ${r*2}`:"",l=be(t.shape==="polygon"?"polygon":"polyline");if(l.setAttribute("points",i.map(c=>`${c[0]},${c[1]}`).join(" ")),l.setAttribute("fill",t.shape==="polygon"?t.fill?.value??"none":"none"),r&&(l.setAttribute("stroke",a),l.setAttribute("stroke-width",String(r)),l.setAttribute("stroke-linecap",t.stroke?.dash==="dotted"?"round":"butt"),l.setAttribute("stroke-linejoin","round"),p&&l.setAttribute("stroke-dasharray",p)),e.append(l),t.shape==="arrow"&&i.length>=2){let[c,d]=[i[i.length-2],i[i.length-1]],m=Math.atan2(d[1]-c[1],d[0]-c[0]),g=Math.max(10,r*3.5),w=b=>`${d[0]-g*Math.cos(m)+b*g*.5*Math.sin(m)},${d[1]-g*Math.sin(m)-b*g*.5*Math.cos(m)}`;l.setAttribute("points",[...i.slice(0,-1),[d[0]-g*.8*Math.cos(m),d[1]-g*.8*Math.sin(m)]].map(b=>`${b[0]},${b[1]}`).join(" "));let f=be("polygon");f.setAttribute("points",`${d[0]},${d[1]} ${w(1)} ${w(-1)}`),f.setAttribute("fill",a),e.append(f)}return e}async function rn(t,e,n,s,r,o,i,a=()=>{},p){let l=t.appInfo??n.info;Yt(e),l?.id&&(e.dataset.app=l.id);let c=(M,C)=>(e.dataset.appFailed=M,{failed:M,...C?{error:C}:{}});if(!Ut(l?.requires))return c("unsupported");let d=s.appHost;if(d&&!d.custom&&!ae(l))return c("unsupported");if(Vt(p,l))return Kt(t,e,n,s,r,o,i,a,p,c);let m=t.app;if(d?.held?.(m))return e.dataset.appHeld="",{held:!0};await d?.mounting?.(m,l?.id);let g=!1,w=()=>{g||(g=!0,d?.unmounted?.(m))},f;try{f=await qt(n.hash,n.bytes,l)}catch(M){return w(),M instanceof H?c(M.reason,M.error):c("load")}let b=f.tag,v=l?.id?s.controllerFor?.({id:l.id,instance:t.id,capability:l.player??"read"}):void 0,A,k=new Promise(M=>{A=M}),P,N={app:l?.id??t.app.id,element:b,props:Ct(t.props??{},sn(s)),place:s.place,screen:s.screen??null,timeZone:s.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,locale:s.locale??navigator.language,preview:!!s.preview,now:r.now,startedAt:r.startedAt,ready:()=>A(),data:(M,C)=>s.data?s.data.get(M,C):Promise.reject(new Error("no data service")),kept:(M,C)=>s.data?.kept?.(M,C),image:M=>s.data?s.data.image(M):Promise.reject(new Error("no data service")),snapshot:M=>{let C=s.snapshot?.(M)??null;if(!C||t.binding?.table!==M||!Xt(t.binding))return C;let ee=Gt(C,t.binding,s.screen,N.timeZone,r.now());return P?.from===C&&P.rows.length===ee.rows.length&&P.rows.every((Bn,Un)=>Bn===ee.rows[Un])?P.snapshot:(P={from:C,rows:ee.rows,snapshot:ee},ee)},...t.binding?{binding:t.binding}:{},...t.sensors?.includes("impressions")&&s.impressions?.measuring?{impressions:{now:()=>s.impressions.now(),on:M=>s.impressions.on(M)}}:{},...v?{controller:v}:{}},F;try{F=j(b),f.shape==="class"?f.attach(F,N):F.wyndlass=N}catch(M){return v?.dispose(),w(),c("error",V(M))}F.style.cssText="display:block;width:100%;height:100%",d?.contained?.(e,F);let W=new Ae(F,{onStop:a,dispose:()=>{v?.dispose(),w()}});e.append(F),i(W);let Q=await Promise.race([k.then(()=>!1),new Promise(M=>setTimeout(()=>M(!0),o))]);return W.update(N.now()),{app:W,late:Q}}var Qt=new Set;async function on(t,e){for(let n of t){let s=`${n.family}/${n.weight??400}/${n.style??"normal"}/${n.blob}`,r=e(n.blob);if(!(Qt.has(s)||!r||typeof FontFace>"u"))try{let o=new FontFace(n.family,r,{weight:String(n.weight??400),style:n.style??"normal"});document.fonts.add(await o.load()),Qt.add(s)}catch{}}}function de(t){let e=[],n=null;for(let s of t){let r=s.start,o=Math.max(0,r.kind==="at"?r.ms:r.kind==="withPrevious"?(n?.startMs??0)+(r.offsetMs??0):(n?.endMs??0)+(r.offsetMs??0));n={startMs:o,endMs:o+s.durationMs},e.push(n)}return{clips:e,autoDurationMs:e.reduce((s,r)=>Math.max(s,r.endMs),0)}}var cr=new Set(["x","y","scaleX","scaleY","rotation","opacity","reveal"]);function ur(t,{pageBelow:e=!1}={},n=null){let s=o=>({path:"page",reason:o});if(!n)return s("no-media-layer");if(e)return s("page-element-beneath");let r=t.slice(0,-1).filter(o=>o.type==="shape"&&o.clip!==!1);if(r.some(o=>o.shape!=="rectangle"||(o.radius??0)>0))return s("clipped-to-shape");if(r.some(o=>(o.rotation??0)%360!==0))return s("clipped-by-rotated-shape");if(!n.animates){if(t.some(o=>(o.rotation??0)%360!==0))return s("rotated");if(t.some(o=>(o.opacity??1)<1))return s("translucent");if(t.some(o=>(o.animated??[]).some(i=>cr.has(i))))return s("animated")}return{path:"native"}}var mr={fade:["opacity"],slide:["x","opacity"],scale:["scaleX","scaleY","opacity"],pulse:["scaleX","scaleY"],loop:["scaleX","scaleY"],wipe:["reveal"]};function an(t,e,n,s){let r=e&&t.overrides?.[e]||{},o=new Map;for(let d of t.animation?.clips??[]){let m=[...d.preset?mr[d.preset]??[]:[],...(d.lanes??[]).map(g=>g.property)];o.set(d.element,[...o.get(d.element)??[],...m])}let i=d=>d.type==="library"&&!!d.source&&!!n[d.source.item.id]?.video,a=d=>!i(d)&&!(d.type==="shape"&&!d.fill&&!(d.stroke?.width??0)),p=[],l=(d,m,g,w)=>{for(let f of d){let b=r[f.id];if(b?.hidden??f.hidden??!1)continue;let v=b?.frame??f.frame,A={x:m.x+v.x,y:m.y+v.y,w:v.w,h:v.h},k={type:f.type==="shape"?"shape":"library",rotation:v.rotation??0,opacity:f.opacity??f.style?.opacity??1,animated:o.get(f.id)??[],...f.type==="shape"?{shape:f.shape,radius:f.radius,clip:f.clip}:{}};p.push({e:f,box:A,chain:[...g,k],ancestors:w}),f.type==="shape"&&l(f.children??[],A,[...g,k],[...w,f])}};l(t.elements,{x:0,y:0},[],[]);let c=(d,m)=>d.x<m.x+m.w&&m.x<d.x+d.w&&d.y<m.y+m.h&&m.y<d.y+d.h;return p.flatMap((d,m)=>{if(!i(d.e))return[];let g=p.slice(0,m).some(w=>a(w.e)&&c(w.box,d.box));return[{element:d.e.id,path:ur(d.chain,{pageBelow:g},s),box:d.box}]})}var hr=[0,0,1,1];function nt(t,e){if(e<=0)return 0;if(e>=1)return 1;let[n,s,r,o]=t;if(n===s&&r===o)return e;let i=3*n,a=3*(r-n)-i,p=1-i-a,l=3*s,c=3*(o-s)-l,d=1-l-c,m=k=>((p*k+a)*k+i)*k,g=k=>((d*k+c)*k+l)*k,w=k=>(3*p*k+2*a)*k+i,f=1e-7,b=e;for(let k=0;k<8;k++){let P=m(b)-e;if(Math.abs(P)<f)return g(b);let N=w(b);if(Math.abs(N)<1e-6)break;b-=P/N}let v=0,A=1;for(b=e;v<A;){let k=m(b);if(Math.abs(k-e)<f||(e>k?v=b:A=b,b=(A-v)/2+v,A-v<f))break}return g(b)}function Se(t,e){let n=t.keyframes;if(e<=n[0].t)return n[0].v;let s=n[n.length-1];if(e>=s.t)return s.v;let r=0;for(;e>=n[r+1].t;)r++;let o=n[r],i=n[r+1];return o.v+(i.v-o.v)*nt(o.easing??hr,(e-o.t)/(i.t-o.t))}function dn(t,e,n){let s={x:t.x,y:t.y,scaleX:1,scaleY:1,rotation:0,opacity:1};for(let r of e??[])s[r.property]=Se(r,n);return s}var le={linear:[0,0,1,1],ease:[.25,.1,.25,1],"ease-in":[.42,0,1,1],"ease-out":[0,0,.58,1],"ease-in-out":[.42,0,.58,1]};function ln(t){if(!t)return le.ease;if(le[t])return le[t];let n=/^cubic-bezier\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^)]+)\)$/.exec(t)?.slice(1).map(Number);return n&&n.every(Number.isFinite)?n:le.ease}function fr(t){let e=typeof t=="string"?/^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/.exec(t):null;if(!e)return null;let n=parseInt(e[1],16);return[n>>16&255,n>>8&255,n&255,e[2]?parseInt(e[2],16)/255:1]}var un={fade:()=>({opacity:0}),slide:t=>({x:t.x-t.w*.1,opacity:0}),scale:()=>({scaleX:.8,scaleY:.8,opacity:0}),wipe:()=>({reveal:0}),typewriter:()=>({chars:0}),"count-up":()=>({count:0})},ra=Object.keys(un);var gr={x:t=>t.x,y:t=>t.y,scaleX:()=>1,scaleY:()=>1,rotation:()=>0,opacity:()=>1,reveal:()=>1,chars:()=>1,count:()=>1},pn=1e3,yr=le["ease-in-out"];function mn(t,e){let n=de(t).clips,s=new Map,r=new Set,o=a=>{let p=s.get(a);return p||s.set(a,p={keys:new Map,colour:null,loops:[],tickers:[]}),p},i=(a,p,l)=>{let c=o(a).keys,d=c.get(p)??[];c.set(p,d),d.push(l)};t.forEach((a,p)=>{let l=e.get(a.element);if(!l)return;let{startMs:c,endMs:d}=n[p],m=ln(a.easing);if(a.lanes?.length){for(let f of a.lanes)for(let b of f.keyframes){let v={t:c+b.at,easing:ln(b.easing??a.easing)};if(f.property==="color"){let A=fr(b.value);if(!A)continue;let k=o(a.element);k.colour??(k.colour=[[],[],[],[]]),A.forEach((P,N)=>k.colour[N].push({...v,v:P}))}else i(a.element,f.property,{...v,v:Number(b.value)})}return}let g=a.preset??"fade";if(a.kind==="emphasis"){g==="pulse"?(i(a.element,"pulse",{t:c,v:1,easing:m}),i(a.element,"pulse",{t:(c+d)/2,v:1.05,easing:m}),i(a.element,"pulse",{t:d,v:1})):g==="loop"?o(a.element).loops.push({startMs:c,endMs:d}):g==="ticker"?o(a.element).tickers.push({startMs:c,endMs:d}):r.add(g);return}let w=un[g];if(!w){r.add(g);return}for(let[f,b]of Object.entries(w(l))){let v=gr[f](l),[A,k]=a.kind==="enter"?[b,v]:[v,b];i(a.element,f,{t:c,v:A,easing:m}),i(a.element,f,{t:d,v:k})}});for(let a of s.values()){for(let p of a.keys.values())p.sort((l,c)=>l.t-c.t);for(let p of a.colour??[])p.sort((l,c)=>l.t-c.t)}return{motions:s,unplayed:[...r].sort()}}var br=["x","y","scaleX","scaleY","rotation","opacity"];function hn(t,e,n,s=!1){if(s)return wr(t,e,n);let r=(p,l)=>{let c=t?.keys.get(p);return c?Se({property:"x",keyframes:c},n):l},o=dn(e,br.flatMap(p=>t?.keys.get(p)?[{property:p,keyframes:t.keys.get(p)}]:[]),n),i=r("pulse",1);for(let p of t?.loops??[])if(n>=p.startMs&&n<p.endMs){let l=(n-p.startMs)%pn/pn;i*=1+.05*nt(yr,l<.5?l*2:2-l*2)}let a=t?.tickers.find(p=>n>=p.startMs&&n<p.endMs);return{...o,reveal:r("reveal",1),chars:r("chars",1),count:r("count",1),pulse:i,scroll:a?(n-a.startMs)/(a.endMs-a.startMs):null,color:t?.colour?t.colour.map(p=>Se({property:"x",keyframes:p},n)):null}}function cn(t,e){if(e<t[0].t)return t[0].v;let n=0;for(;n+1<t.length&&t[n+1].t<=e;)n++;return n+1<t.length?t[n+1].v:t[n].v}function wr(t,e,n){let s=(r,o)=>{let i=t?.keys.get(r);return i?cn(i,n):o};return{x:s("x",e.x),y:s("y",e.y),scaleX:s("scaleX",1),scaleY:s("scaleY",1),rotation:s("rotation",0),opacity:s("opacity",1),reveal:s("reveal",1),chars:s("chars",1),count:s("count",1),pulse:1,scroll:null,color:t?.colour?t.colour.map(r=>cn(r,n)):null}}function vr(t,e){let n=Array.from(t);return e>=1?t:n.slice(0,Math.max(0,Math.round(e*n.length))).join("")}function kr(t,e){return e>=1?t:t.replace(/\d+(?:\.\d+)?/g,n=>(Number(n)*Math.max(0,e)).toFixed((n.split(".")[1]??"").length))}function fn(t,e,n){if(t<=1||e<=0)return[{page:0,startMs:0,endMs:n}];let s=[];for(let r=0;r*e<n&&r<1e3;r++)s.push({page:r%t,startMs:r*e,endMs:Math.min((r+1)*e,n)});return s}function gn(t,e,n,s){t.style.left=`${n.x}px`,t.style.top=`${n.y}px`,t.style.transform=`rotate(${(e.frame.rotation??0)+n.rotation}deg) scale(${n.scaleX*n.pulse}, ${n.scaleY*n.pulse})`,t.style.opacity=String((e.opacity??e.style?.opacity??1)*n.opacity),t.style.clipPath=n.reveal>=1?"":`inset(0 ${(1-Math.max(0,n.reveal))*100}% 0 0)`;let r=n.color?`rgba(${n.color.slice(0,3).map(o=>Math.round(o)).join(",")},${n.color[3]})`:null;if(e.type==="text"&&s!==void 0){let o=kr(vr(s,n.chars),n.count);if(n.scroll!==null){let i=t.querySelector("[data-ticker]");i||(i=document.createElement("span"),i.dataset.ticker="",i.style.cssText="display:inline-block;white-space:nowrap;will-change:transform",t.replaceChildren(i),t.style.overflow="hidden"),i.textContent!==o&&(i.textContent=o);let a=e.frame.w,p=i.scrollWidth;i.style.transform=`translateX(${a-n.scroll*(a+p)}px)`}else(t.textContent!==o||t.querySelector("[data-ticker]"))&&(t.textContent=o,t.style.overflow="");r&&(t.style.color=r)}else if(e.type==="shape"&&r){let o=t.querySelector("polygon, polyline");o&&e.shape==="polygon"?o.setAttribute("fill",r):o||(t.style.background=r)}}function xr(t){let e=t>>>0;return()=>{e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}async function yn(t,e,n,s){let r=parseInt((await ze(We(`${t}
|
|
2
|
+
"use strict";(()=>{var rs=Object.defineProperty;var is=(t,e,n)=>e in t?rs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var h=(t,e,n)=>is(t,typeof e!="symbol"?e+"":e,n);var jt=Reflect.apply,qe=Object.getOwnPropertyDescriptor,Me=Object.getPrototypeOf,N=globalThis,x=(t,e,n)=>jt(t,e,n),$=(t,e)=>t?qe(t,e)?.get:void 0,We=(t,e)=>t?qe(t,e)?.set:void 0,C=t=>N[t]?.prototype,Ft=(t,e,n)=>jt(t,e,n);var ci=Date.now,ui=new TextEncoder,hi=new TextDecoder,mi=TextEncoder.prototype.encode,fi=TextDecoder.prototype.decode;var gi=$(Me(Uint8Array.prototype),"length");var os=Uint8Array,as=t=>new os(t),ls=[];for(let t=0;t<256;t++)ls[t]=(t<16?"0":"")+t.toString(16);var ds=Object.create(null);for(let t=0;t<64;t++)ds["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[t]]=t;var Tt=N.crypto?.subtle,ze=Tt?Me(Tt):void 0,_e=N.crypto,ps=_e?Me(_e).getRandomValues:void 0,yi=ze?.digest,bi=ze?.importKey,wi=ze?.sign;var Ht=t=>x(ps,_e,[as(t)]),vi={setTimeout:N.setTimeout,clearTimeout:N.clearTimeout,setInterval:N.setInterval,clearInterval:N.clearInterval};var ki=N.fetch;var oe=C("MessagePort"),xi=oe&&oe.postMessage,Mi=We(oe,"onmessage"),Ai=oe&&oe.start,Ve=C("MessageEvent"),Si=$(Ve,"data"),Ei=$(Ve,"ports"),Ti=$(Ve,"source");var Bt=C("EventTarget"),Pi=Bt?.addEventListener,Li=Bt?.removeEventListener;var Ii=N.Worker,ve=C("Worker"),Ci=ve&&ve.postMessage,Ri=We(ve,"onmessage"),Ni=We(ve,"onerror");var Pt=N.Blob,ke=N.URL,Lt=ke?.createObjectURL,cs=ke?.revokeObjectURL,Ke=Pt&&Lt?{make:(t,e)=>x(Lt,ke,[new Pt(t,{type:e})]),revoke:t=>x(cs,ke,[t])}:void 0,re=N.customElements,Ze=re?Me(re):void 0,us=Ze?.define,hs=Ze?.get,Je=re&&Ze?{define:(t,e)=>x(us,re,[t,e]),get:t=>x(hs,re,[t])}:void 0,Ut=N.document,xe=C("Document"),ms=xe?.createElement,fs=xe?.createElementNS,gs=WeakSet.prototype.add,Oi=WeakSet.prototype.has,Ye=new WeakSet,ys=new WeakSet,Ae=(t,e)=>(x(gs,t,[e]),e);function H(t){return Ae(Ye,x(ms,Ut,[t]))}var Se=t=>Ae(Ye,x(fs,Ut,["http://www.w3.org/2000/svg",t]));var Y=t=>Ae(ys,t);var ae=C("Node"),Xe=C("Element"),Ee=C("HTMLElement"),X=t=>$(ae,t),It=X("parentNode"),bs=X("firstChild"),ws=X("lastChild"),vs=X("nextSibling"),ks=X("nodeType"),xs=X("childNodes"),Ms=$(Xe,"localName"),As=ae?.appendChild,Ss=ae?.insertBefore,Es=ae?.removeChild,K=Xe,Ts=K?.getAttribute,Ps=K?.getAttributeNames,Ls=K?.setAttribute,Is=K?.removeAttribute,Cs=K?.matches,Rs=K?.attachShadow,Ns=K?.querySelectorAll,Os=C("HTMLDialogElement")?.close,$s=$(C("NodeList"),"length"),Ds=C("NodeList")?.item,Te=C("MutationRecord"),js=$(Te,"type"),Fs=$(Te,"target"),Hs=$(Te,"addedNodes"),Bs=$(Te,"removedNodes"),Ct=N.MutationObserver,Us=C("MutationObserver")?.observe,_t=xe?qe(xe,"adoptedStyleSheets"):void 0,Rt=_t?.get,Nt=_t?.set,_s=N.requestAnimationFrame,Ot=$(Ee,"style"),Pe=C("CSSStyleDeclaration"),qs=Pe?.getPropertyValue,Ws=Pe?.getPropertyPriority,zs=Pe?.setProperty,$t=Ee?.showPopover,Dt=Ee?.hidePopover,Vs=$(C("Event"),"target"),Ks=C("Event")?.stopImmediatePropagation,we=t=>{let e=[];for(let n=0,s=x($s,t,[]);n<s;n++)e[n]=x(Ds,t,[n]);return e},ie=Ct&&ae&&Xe&&Ee&&Pe?{parent:t=>x(It,t,[]),first:t=>x(bs,t,[]),last:t=>x(ws,t,[]),next:t=>x(vs,t,[]),isElement:t=>x(ks,t,[])===1,name:t=>x(Ms,t,[]),children:t=>we(x(xs,t,[])),append:(t,e)=>x(As,t,[e]),insert:(t,e,n)=>x(Ss,t,[e,n]),remove:t=>{let e=x(It,t,[]);e&&x(Es,e,[t])},attribute:(t,e)=>x(Ts,t,[e]),attributes:t=>x(Ps,t,[]),setAttribute:(t,e,n)=>x(Ls,t,[e,n]),removeAttribute:(t,e)=>x(Is,t,[e]),matches:(t,e)=>x(Cs,t,[e]),all:(t,e)=>we(x(Ns,t,[e])),closeDialog:t=>x(Os,t,[]),shadow:t=>x(Rs,t,[{mode:"closed"}]),style:(t,e)=>{let n=x(Ot,t,[]);return[x(qs,n,[e]),x(Ws,n,[e])]},setStyle:(t,e,n,s="")=>x(zs,x(Ot,t,[]),[e,n,s]),observer:t=>new Ct(t),observe:(t,e,n)=>x(Us,t,[e,n]),record:t=>({type:x(js,t,[]),target:x(Fs,t,[]),added:we(x(Hs,t,[])),removed:we(x(Bs,t,[]))}),adopted:Rt&&Nt?{count:t=>x(Rt,t,[]).length,clear:t=>x(Nt,t,[[]])}:void 0,frame:t=>x(_s,globalThis,[t]),popover:$t&&Dt?{show:t=>x($t,t,[]),hide:t=>x(Dt,t,[])}:void 0,target:t=>x(Vs,t,[]),stop:t=>x(Ks,t,[])}:void 0;function Ge(t){if(Ae(Ye,t),ie)for(let e of ie.children(t))ie.isElement(e)&&Ge(e);return t}var Qe=t=>new TextEncoder().encode(t);function Zs(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n="";for(let s of e)n+=s.toString(16).padStart(2,"0");return n}async function et(t){return Zs(await crypto.subtle.digest("SHA-256",t))}var Js=["name","type","tags","location","site","district","region","organization","path","timeZone"],Ys=["text","date","currency","truncate"],qt={site:"SITE",district:"DISTRICT",region:"REGION",organization:"ORGANIZATION"};function Le(t,e,n,s){if(!t)return n==="timeZone"&&e?e:void 0;if(n==="fields")return s&&t.fields?.[s]||void 0;let r=t.path??[];switch(n){case"name":return t.name||void 0;case"type":return t.type||void 0;case"tags":return t.tags?.length?t.tags.join(", "):void 0;case"location":return r.at(-1)?.name;case"path":return r.length?r.map(o=>o.name).join(" \u203A "):void 0;case"timeZone":return e||void 0;default:return qt[n]?[...r].reverse().find(o=>o.kind===qt[n])?.name:void 0}}function Xs(t,e){if(t==null||t==="")return;let n=String(t);if(e==="currency"){let s=Number(t);return Number.isFinite(s)?s.toFixed(2):n}if(e==="date"){let s=Date.parse(n);return Number.isNaN(s)?n:new Date(s).toISOString().slice(0,10)}return e==="truncate"&&n.length>40?n.slice(0,39)+"\u2026":n}function tt(t,e){return(t.source==="screen"?Le(e.screen,e.timeZone,t.field,t.key):Xs(e.tables?.[t.table]?.rows?.[t.row??0]?.[t.column],t.format))??t.fallback??""}function Wt(t){let e=/^\s*(?:screen\.(fields\.[a-z][A-Za-z0-9]{0,31}|[A-Za-z]+)|table\.([A-Za-z0-9_-]+)\[(\d+)\](?:\.([A-Za-z0-9_]+)|\["((?:[^"\\]|\\.)*)"\]))\s*((?:\|\s*(?:[a-z]+|"(?:[^"\\]|\\.)*")\s*)*)$/.exec(t);if(!e)return null;let n=[...e[6].matchAll(/\|\s*([a-z]+|"((?:[^"\\]|\\.)*)")/g)],s=n.find(o=>o[1].startsWith('"'))?.[2]?.replace(/\\(.)/g,"$1"),r=n.find(o=>!o[1].startsWith('"'))?.[1];return e[1]!==void 0?r?null:e[1].startsWith("fields.")?{source:"screen",field:"fields",key:e[1].slice(7),...s!==void 0?{fallback:s}:{}}:Js.includes(e[1])?{source:"screen",field:e[1],...s!==void 0?{fallback:s}:{}}:null:r&&!Ys.includes(r)?null:{source:"table",table:e[2],row:Number(e[3]),column:e[4]??e[5].replace(/\\(.)/g,"$1"),...r?{format:r}:{},...s!==void 0?{fallback:s}:{}}}function nt(t,e){return t.replace(/\{{2}([^{}]*)\}{2}/g,(n,s)=>{let r=Wt(s);return r?tt(r,e):n})}function Ie(t){return[...t.matchAll(/\{{2}([^{}]*)\}{2}/g)].some(e=>Wt(e[1])!==null)}function st(t,e){return Object.fromEntries(Object.entries(t).map(([n,s])=>[n,typeof s=="string"?nt(s,e):s]))}var rt=t=>t==null||t==="";function Vt(t,e,n,s,r,o){return Gs(t,e,n,s,{now:r,timeZone:o})}function Gs(t,e,n,s,r){if(n===null&&(e==="eq"||e==="ne"))return e==="eq"?rt(t):!rt(t);if(rt(t)||n===null||n===void 0)return!1;switch(s){case"number":case"currency":{let o=Number(t),i=Number(n);return typeof n!="boolean"&&n!==""&&Number.isFinite(o)&&Number.isFinite(i)&&it(e,o-i)}case"boolean":{let o=n===!0||n==="true"?!0:n===!1||n==="false"?!1:void 0;return o!==void 0&&(e==="eq"?t===o:e==="ne"?t!==o:!1)}case"date":{let o=n==="today"?Qs(r.now,r.timeZone).date:String(n),i=String(t).slice(0,10);return/^\d{4}-\d{2}-\d{2}$/.test(o)&&it(e,i<o?-1:i>o?1:0)}case"datetime":{let o=Date.parse(String(t)),i=n==="now"?r.now:Date.parse(String(n));return!Number.isNaN(o)&&!Number.isNaN(i)&&it(e,o-i)}default:{let o=String(t).toLowerCase(),i=String(n).toLowerCase();return e==="eq"?o===i:e==="ne"?o!==i:e==="contains"?o.includes(i):!1}}}function it(t,e){switch(t){case"eq":return e===0;case"ne":return e!==0;case"lt":return e<0;case"lte":return e<=0;case"gt":return e>0;case"gte":return e>=0;default:return!1}}var zt=new Map;function Qs(t,e){let n=zt.get(e);n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",weekday:"short"}),zt.set(e,n));let s=Object.fromEntries(n.formatToParts(new Date(t)).map(r=>[r.type,r.value]));return{date:`${s.year}-${s.month}-${s.day}`,minute:Number(s.hour)%24*60+Number(s.minute),day:String(s.weekday).slice(0,3).toLowerCase()}}var Kt=(t,e)=>!t||(t.from===void 0||t.from<=e)&&(t.until===void 0||e<t.until);var le=class{constructor(e,n,s,r,o){h(this,"renderer",e);h(this,"wrap",r);h(this,"onShown",o);h(this,"timer");h(this,"turns",0);h(this,"turnAt");h(this,"left");h(this,"stopped",!1);h(this,"share");h(this,"pages");this.pages=n.pages??[],this.share=n.durationMs/Math.max(1,this.pages.length),this.turnAt=s+this.share,this.arm()}arm(){clearTimeout(this.timer);let e=this.pages.length;if(this.stopped||this.left!==void 0||e<2||!this.wrap&&this.turns+1>=e)return;let n=this.pages[(this.turns+1)%e];this.renderer.prepare?.(n).catch(()=>{}),this.timer=setTimeout(()=>{this.turn(n)},Math.min(Math.max(0,this.turnAt-Date.now()),2**31-1))}async turn(e){try{await this.renderer.show(e)}catch{}this.stopped||(this.turns++,this.turnAt+=this.share,this.onShown?.(e),this.arm())}pause(){this.stopped||this.left!==void 0||(clearTimeout(this.timer),this.left=Math.max(0,this.turnAt-Date.now()))}resume(){this.stopped||this.left===void 0||(this.turnAt=Date.now()+this.left,this.left=void 0,this.arm())}stop(){if(!this.stopped){this.stopped=!0,clearTimeout(this.timer);for(let e of this.pages)this.renderer.release?.(e)}}};var sr=Object.freeze,rr=Object.values,Zt=Reflect.apply;function Ce(t){if(t===null||typeof t!="object")return t;for(let e of Zt(rr,Object,[t]))Ce(e);return Zt(sr,Object,[t])}var ot=class extends Error{constructor(n,s){super(s);h(this,"code",n);this.name="MediaError"}};function at(t){return t instanceof ot?{code:t.code.slice(0,64),message:t.message.slice(0,1e3)}:{code:"not-shown",message:String(t instanceof Error?t.message:t??"").slice(0,1e3)}}var Jt=t=>t.blob.contentType.startsWith("video/");var lt="position:absolute;inset:0;width:100%;height:100%;object-fit:contain",ir=1,Re=class{constructor(e,n={}){h(this,"container",e);h(this,"options",n);h(this,"prepared",new Map);h(this,"shown",null);h(this,"endListeners",new Set);h(this,"itemListeners",new Set);h(this,"appListeners",new Set);h(this,"held",null);h(this,"drawn",0);h(this,"shownHash",null);let s=n.media;s&&(document.documentElement.style.background="transparent",document.body.style.background="transparent",e.style.background="#000",s.onEnd((r,o)=>{let i=this.shown;if(i?.mediaId===r)for(let a of this.endListeners)a(i.slide,o)}))}onMediaEnd(e){this.endListeners.add(e)}onElementItem(e){this.itemListeners.add(e)}onApp(e){this.appListeners.add(e)}app(e){for(let n of this.appListeners)n(e);this.options.onApp?.(e)}prepare(e){let n=this.prepared.get(e);if(n)return n.ready;let s;try{s=this.make(e)}catch(r){return Promise.reject(r)}return this.prepared.set(e,s),s.ready.catch(()=>{this.prepared.get(e)===s&&(this.prepared.delete(e),this.dispose(s))}),s.ready}release(e){let n=this.prepared.get(e);n&&(this.prepared.delete(e),this.dispose(n))}async show(e){await this.prepare(e);let n=this.prepared.get(e);if(!n)throw new Error("the slide was released before it was shown");this.prepared.delete(e);let s=this.shown,r=this.options.media,o=s?Xt(e):void 0;if(n.kind==="layout"&&o===void 0){await _(()=>{s?this.container.insertBefore(n.el,s.el):this.container.append(n.el),this.shown=n,this.shownHash=e.blob.hash}),this.held=[],await n.view.start().catch(()=>{});let i=Promise.resolve();return await _(()=>{this.shown===n&&(n.el.style.visibility="",s?.el.remove(),r&&this.paint("transparent"),r&&s?.mediaId&&(i=r.show([],[s.mediaId],Date.now())))}),await i.catch(()=>{}),s&&this.dispose(s),this.releaseHeld(),"cut"}if(o!==void 0&&r&&n.kind==="native"&&s.kind==="native"){if(n.fadesIn&&!n.queued){let i=Promise.resolve();return await _(()=>{n.el.style.visibility="",this.container.insertBefore(n.el,s.el),i=r.show([n.mediaId],[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),or(o).then(async()=>{await r.show([],[s.mediaId],Date.now()).catch(()=>{}),s.el.remove(),this.dispose(s)}),"crossfade"}}else if(o!==void 0&&r&&n.kind==="native"){let i=Promise.resolve();return await _(()=>{n.el.style.visibility="",this.container.insertBefore(n.el,s.el),i=r.show([n.mediaId],[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),this.paint("transparent"),Gt(s.el,1,0,o).then(()=>{s.el.remove(),this.dispose(s)}),"crossfade"}else if(o!==void 0)return await _(()=>{n.el.style.visibility="",n.el.style.opacity="0",this.container.append(n.el),n.kind==="video"&&dt(n.el),this.shown=n,this.shownHash=e.blob.hash}),n.view&&(this.held=[],n.view.start().then(()=>this.releaseHeld())),Gt(n.el,0,1,o).then(async()=>{s.el.remove(),this.shown===n&&this.paint(r?"#000":""),r&&s.mediaId&&await r.show([],[s.mediaId],Date.now()).catch(()=>{}),this.dispose(s)}),"crossfade";if(r&&n.kind==="native"){let i=Promise.resolve();await _(()=>{n.el.style.visibility="",s?this.container.insertBefore(n.el,s.el):this.container.prepend(n.el),i=r.show([n.mediaId],s?.mediaId?[s.mediaId]:[],Date.now()),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{}),await _(()=>{this.shown===n&&(s?.el.remove(),this.paint("transparent"))})}else{let i=Promise.resolve();await _(()=>{n.el.style.visibility="",n.el.parentNode!==this.container&&this.container.append(n.el),s?.el.remove(),this.paint(r?"#000":""),r&&s?.mediaId&&(i=r.show([],[s.mediaId],Date.now())),n.kind==="video"&&dt(n.el),this.shown=n,this.shownHash=e.blob.hash}),await i.catch(()=>{})}return s&&this.dispose(s),"cut"}paint(e){this.options.background?this.options.background(e):this.container.style.background=e}standby(){let e=this.shown;this.shown=null,this.shownHash=null,this.paint(this.options.media?"#000":""),e&&(e.mediaId&&this.options.media?.show([],[e.mediaId],Date.now()).catch(()=>{}),this.dispose(e))}pause(){let e=this.shown;e?.view?.pause(),e?.kind==="video"?e.el.pause():e?.mediaId&&this.options.media?.control(e.mediaId,"pause").catch(()=>{})}resume(){let e=this.shown;e?.view?.resume(),e?.kind==="video"?dt(e.el):e?.mediaId&&this.options.media?.control(e.mediaId,"play").catch(()=>{})}make(e){if(e.layout){let{doc:i,source:a,untilPass:d}=e.layout,p=Y(H("div"));p.dataset.blob=e.blob.hash,p.style.cssText=`${lt};visibility:hidden`,this.container.append(p);let c={slide:e,kind:"layout",el:p,ready:Promise.resolve()},l=g=>this.options.path?`${this.options.path}/${g}`:g,m=String(++this.drawn);return c.view=new G(i,a,p,{media:this.options.media,path:this.options.path,endsWith:d?l(d):void 0,onItem:g=>{let w={...g,slide:g.slide?`${m}.${g.slide}`:m};this.held?this.held.push(w):this.item(w)},onPassEnd:g=>{if(d&&g===l(d)&&this.shown===c){for(let w of this.endListeners)w(e);return"hold"}return this.options.onPassEnd?.(g)},onApp:g=>this.app(g)}),c.ready=c.view.ready,c}if(!Jt(e)){if(!e.bytes&&!e.url)throw new Error(`no bytes for ${e.blob.hash}`);let i=e.bytes?URL.createObjectURL(new Blob([e.bytes],{type:e.blob.contentType})):void 0,a=Y(H("img"));return a.src=i??e.url,a.alt="",a.dataset.blob=e.blob.hash,a.style.cssText=this.fill(),{slide:e,kind:"image",el:a,objectUrl:i,ready:a.decode()}}let n=this.options.media;if(n){let i=`m-${ir++}`,a=Y(H("div"));a.dataset.blob=e.blob.hash,a.dataset.media=i,a.style.cssText=`${lt};visibility:hidden`;let d=this.container.getBoundingClientRect(),p={x:d.left,y:d.top,w:d.width||window.innerWidth,h:d.height||window.innerHeight},c=Xt(e),l=c!==void 0&&this.shown?.kind==="native"&&n.capability.animates&&n.capability.layers>=2,m=l?[{property:"opacity",keyframes:[{t:0,v:0},{t:c,v:1}]}]:[],g={slide:e,kind:"native",el:a,mediaId:i,fadesIn:l,ready:Promise.resolve()},w=this.options.fit??"contain";return g.ready=n.prepare({mediaId:i,blob:e.blob.hash,contentType:e.blob.contentType,box:p,z:l?1:0,loop:e.loop,muted:!1,fit:w,...l?{tracks:m}:{}}).then(f=>{f.queued&&(g.queued=!0)}),g}let s=e.url?void 0:URL.createObjectURL(new Blob([e.bytes],{type:e.blob.contentType})),r=Y(H("video"));r.dataset.blob=e.blob.hash,r.style.cssText=`${this.fill()};visibility:hidden`,r.muted=!1,r.playsInline=!0,r.preload="auto",r.loop=e.loop,r.src=e.url??s,r.addEventListener("ended",()=>{if(this.shown?.el===r)for(let i of this.endListeners)i(e)}),r.addEventListener("error",()=>{if(this.shown?.el===r)for(let i of this.endListeners)i(e,`video: ${r.error?.message??"error"}`)});let o=new Promise((i,a)=>{if(r.readyState>=2)return i();r.addEventListener("loadeddata",()=>i(),{once:!0}),r.addEventListener("error",()=>a(new Error(`video: ${r.error?.message??"cannot load"}`)),{once:!0})});return this.container.append(r),{slide:e,kind:"video",el:r,objectUrl:s,ready:o}}item(e){this.options.onItem?.(e);for(let n of this.itemListeners)n(e)}releaseHeld(){let e=this.held;this.held=null,e?.length&&setTimeout(()=>{for(let n of e)this.item(n)},0)}fill(){let e=this.options.fit==="stretch"?"fill":this.options.fit??"contain";return lt.replace("object-fit:contain",`object-fit:${e}`)}dispose(e){if(this.shown!==e){if(e.view?.dispose(),e.el.remove(),e.kind==="video"){let n=e.el;n.pause(),n.removeAttribute("src"),n.load()}e.mediaId&&this.options.media?.release(e.mediaId).catch(()=>{}),e.objectUrl&&URL.revokeObjectURL(e.objectUrl)}}};function Xt(t){if(t.transition?.type==="crossfade")return Math.max(0,Math.min(t.transition.durationMs??1e3,t.durationMs/2))}var or=t=>new Promise(e=>setTimeout(e,t));function Gt(t,e,n,s){return new Promise(r=>{let o=Date.now(),i=!1,a=()=>{i||(i=!0,t.style.opacity=n===1?"":String(n),r())};t.style.opacity=String(e);let d=()=>{if(i)return;let p=Math.min(1,(Date.now()-o)/s);if(p>=1)return a();t.style.opacity=String(e+(n-e)*p),requestAnimationFrame(d)};requestAnimationFrame(d),setTimeout(a,s+250)})}function dt(t){t.play().catch(()=>(t.muted=!0,t.play())).catch(()=>{})}function _(t){return new Promise((e,n)=>{let s=!1,r=()=>{if(!s){s=!0;try{t(),e()}catch(o){n(o)}}};requestAnimationFrame(r),setTimeout(r,250)})}var de={apiVersion:2,properties:[{name:"device",description:"What the device is: id, type, shell and versions, model, resolution and orientation. Fixed while the player runs."},{name:"mode",description:"Where player-core runs: player, preview (in the CMS) or designer. In preview and the designer, commands change nothing."},{name:"timeZone",description:"The player's time zone (IANA), from the host.",event:"time.changed"},{name:"locale",description:"The player's locale (BCP 47), from the host."},{name:"connection",description:"Whether the player is connected to Wyndlass.",event:"connection.changed"},{name:"state",description:"starting, playing, paused, stopped (the standby screen), idle (nothing to play) or error.",event:"state.changed"},{name:"held",description:"A remote pause or stop in effect, by whom and since when; absent when none.",event:"state.changed"},{name:"content",description:"The manifest playing, when it was issued and switched to; absent when there is none.",event:"content.updated"},{name:"now",description:"What each zone shows: the item, its blob and content type, when it started, and its duration and position when known.",event:"item.start"},{name:"audio",description:"The player's volume (0 to 100) and whether it is muted; only when the host can set them.",event:"audio.changed"},{name:"display",description:"The display's power and brightness; only when the host can report them.",event:"display.changed"},{name:"capabilities",description:"What the host can do: audio, display power, display brightness."}],events:[{name:"state.changed",description:"The player's state changed (playing, paused, stopped, idle, error), and who changed it."},{name:"content.updated",description:"A new manifest was switched to."},{name:"item.start",description:"An item started in a zone (source start)."},{name:"item.end",description:"An item ended in a zone (source end): completed, skipped, stopped, error, replaced by new content, or finished by its app."},{name:"item.error",description:"An item could not be shown."},{name:"connection.changed",description:"The player connected to Wyndlass or lost its connection."},{name:"audio.changed",description:"The volume or mute changed, and who changed it."},{name:"display.changed",description:"The display's power or brightness changed, and who changed it."},{name:"time.changed",description:"The clock was adjusted or the time zone changed."},{name:"app.command",description:"A command for apps on the screen (apps.sendCommand); an app reacts if it knows the name."},{name:"app.failed",description:"An app on the screen could not run, or misbehaved (WP-0100): its bundle did not load, it was not an app, it needs a newer player, it kept throwing and was stopped, or it was late or overran a clip."},{name:"app.held",description:"An app version was held back on this screen until the next manifest, after the page stopped answering twice in an hour while it was on screen (WP-0100)."}],commands:[{name:"player.status",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/status",description:"Everything about the player now: device, mode, time zone, locale, connection, state (and any hold), the content playing, what each zone shows, audio, display and what the host can do. Changes nothing.",idempotent:!0},{name:"player.events",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/events",result:"player-api-results.schema.json#/$defs/events",description:"The player's recent events (the last 200), oldest first, after a sequence number: state changes, content updates, item starts and ends, errors, connection, audio, display and time. Pass next as after to poll for more. Changes nothing.",idempotent:!0},{name:"time.now",access:"read",apps:"read",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/timeNow",description:"The player's current time, its time zone and UTC offset, and whether its clock is synchronized. Changes nothing.",idempotent:!0},{name:"player.play",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Resumes or starts playback on the screen. From a remote caller it also ends a remote pause or stop.",idempotent:!0},{name:"player.pause",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Freezes the screen on what it shows now: the loop's timer and any media stop where they are. From a remote caller it holds until a remote player.play or a restart; apps cannot resume it, and new content arrives paused.",idempotent:!0},{name:"player.stop",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/state",description:"Stops playback and shows the standby screen (black, display on). From a remote caller it holds until a remote player.play or a restart; apps cannot restart it, and new content arrives stopped.",idempotent:!0},{name:"player.next",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Skips to the next item in a zone (main by default); the current item ends as skipped."},{name:"player.previous",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/zone",result:"player-api-results.schema.json#/$defs/now",description:"Goes back to the previous item in a zone (main by default); the current item ends as skipped."},{name:"player.playItem",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/playItem",result:"player-api-results.schema.json#/$defs/now",description:"Shows a given item of the content playing now in a zone (main by default), then continues the loop from it. Refused for an item the playing manifest does not have."},{name:"audio.setVolume",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setVolume",result:"player-api-results.schema.json#/$defs/audio",description:"Sets the player's volume, 0 to 100. Only on players whose host can set it to a level.",needs:"audio.volume",idempotent:!0},{name:"audio.setMuted",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setMuted",result:"player-api-results.schema.json#/$defs/audio",description:"Mutes or unmutes the player. Only on players whose host can.",needs:"audio",idempotent:!0},{name:"display.setPower",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setPower",result:"player-api-results.schema.json#/$defs/display",description:"Turns the display on or to standby. Only on players whose host can. Standby blanks the screen until it is turned on.",needs:"display.power",idempotent:!0},{name:"display.setBrightness",access:"control",apps:"control",remote:!0,params:"player-api-params.schema.json#/$defs/setBrightness",result:"player-api-results.schema.json#/$defs/display",description:"Sets the display's brightness, 0 to 100. Only on players whose host can.",needs:"display.brightness",idempotent:!0},{name:"apps.sendCommand",access:"control",apps:"none",remote:!0,params:"player-api-params.schema.json#/$defs/sendCommand",result:"player-api-results.schema.json#/$defs/delivered",description:"Sends a named command, with an optional argument, to the apps on the screen; an app that knows the name reacts. Returns how many apps listen."},{name:"app.finish",access:"control",apps:"read",remote:!1,params:"player-api-params.schema.json#/$defs/empty",result:"player-api-results.schema.json#/$defs/none",description:"An app ends its own slot now: its item ends as finished and the loop moves on. Apps only; not a tool."}],host:[{name:"host.describe",kind:"request",description:"What the device is, its time zone, locale, connection and capabilities.",result:"player-api-host.schema.json#/$defs/describeResult"},{name:"host.time",kind:"request",description:"The host's time and time zone.",result:"player-api-common.schema.json#/$defs/timeNow"},{name:"host.getAudio",kind:"request",description:"The player's volume and mute.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.setAudio",kind:"request",description:"Sets the volume, the mute or both; answers the audio after.",result:"player-api-common.schema.json#/$defs/audio"},{name:"host.getDisplay",kind:"request",description:"The display's power and brightness.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.setDisplay",kind:"request",description:"Sets the display's power, brightness or both; answers the display after.",result:"player-api-common.schema.json#/$defs/display"},{name:"host.adRequest",kind:"request",description:"Asks Wyndlass's ad broker for one slot of a break over the host's NATS connection (WP-0075); the result is the broker's ad-decision (ad-decision.schema.json). Only a host whose describe says ads is asked."},{name:"host.mediaPrepare",kind:"request",description:"Lays a video out behind the page and prepares it to its first frame; host.mediaState says when (ADR 0055)."},{name:"host.mediaShow",kind:"request",description:"Shows and hides prepared videos; replies once its layer has changed."},{name:"host.mediaControl",kind:"request",description:"Plays, pauses or seeks a video, or asks for its position."},{name:"host.mediaRelease",kind:"request",description:"Removes a video and frees its decoder."},{name:"host.reply",kind:"reply",description:"The host's answer to a request: result or error (unsupported, failed)."},{name:"host.connection",kind:"event",description:"The connection to Wyndlass changed."},{name:"host.timeChanged",kind:"event",description:"The clock was adjusted or the time zone changed."},{name:"host.audioChanged",kind:"event",description:"The volume or mute changed outside the player."},{name:"host.displayChanged",kind:"event",description:"The display changed outside the player."},{name:"host.mediaState",kind:"event",description:"A video was prepared, started, ended or failed, or its position was asked for."},{name:"host.presence",kind:"event",description:"What one of the host's sensors sees now: the presences in view, with random ids that never leave the page (WP-0105)."},{name:"host.sensing",kind:"event",description:"The site's sensing mode as the host applies it, and its sensors (WP-0105)."},{name:"host.serialPorts",kind:"event",description:"The host's sensor controller ports, and which are open (WP-0043)."},{name:"host.serialLine",kind:"event",description:"One line from a sensor controller, as it arrived (WP-0043)."},{name:"host.serialWrite",kind:"request",description:"Writes lines to a sensor controller, a gap apart; replies once written (WP-0043)."},{name:"host.bleWatch",kind:"request",description:"What the page listens for: beacons' iBeacon UUIDs, Eddystone namespaces and addresses; replies once the scan follows it. Sent only to a host that has sent host.bleState (WP-0044)."},{name:"host.bleAdverts",kind:"event",description:"Beacon frames that match the watch, at most four a second of each kind from each beacon (WP-0044)."},{name:"host.bleState",kind:"event",description:"The host's Bluetooth scanner: scanning, idle, off, refused, missing or failed; sent only by a host that has one (WP-0044)."},{name:"host.gpioPins",kind:"event",description:"The GPIO pins the host reads, with their values (WP-0044)."},{name:"host.gpioEdge",kind:"event",description:"A GPIO pin changed (WP-0044)."},{name:"host.mcp",kind:"relay",description:"An MCP message from ctl.dev.{deviceId}, for player-core to answer."},{name:"core.ready",kind:"core",description:"player-core is ready to answer host.mcp; until then the shell answers -32002 itself."},{name:"core.mcpReply",kind:"core",description:"player-core's answer to a host.mcp, for the shell to send back."},{name:"core.sensors",kind:"core",description:"The page's sensor controllers, channels and inputs, and the beacons it hears, whenever they change, for the heartbeat and sensors.recent (WP-0043, WP-0044)."}]};var Qt=Symbol.for("wyndlass.app.attach");var U=class extends Error{constructor(n,s){super(`the app could not run (${n})`);h(this,"reason",n);h(this,"error",s)}};function Z(t){try{let e=t instanceof Error?t.name:void 0;return typeof e=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(e)?e:void 0}catch{return}}function pe(t){let e=t?.id;if(typeof e!="string"||e==="")return!0;for(let n=0;n<en.length;n++)if(e[n]!==en[n])return!1;return!0}var en="com.wyndlass.";function lr(t=typeof navigator>"u"?"":navigator.userAgent){let e=/Chrom(?:e|ium)\/(\d+)/.exec(t);return e?Number(e[1]):void 0}function tn(t,e=de.apiVersion,n=lr()){return!(t?.playerApi!==void 0&&t.playerApi>e||t?.webView!==void 0&&n!==void 0&&t.webView>n)}function dr(t){let e;try{e=t.paging?.()}catch{return null}let n=e;return n&&Number.isInteger(n.count)&&n.count>1&&typeof n.ms=="number"&&n.ms>0?{count:n.count,ms:n.ms}:null}var pt=new Map;function pr(){let t=Ht(8),e="";for(let n=0;n<8;n++)e+=cr[t[n]%26];return e}var cr="abcdefghijklmnopqrstuvwxyz",ur=0;function nn(t,e,n){let s=pt.get(t);if(!s){let r=Ke.make([e],"text/javascript");s=import(r).then(o=>hr(o,n),o=>{throw o instanceof U?o:new U("load",Z(o))}).finally(()=>Ke.revoke(r)),pt.set(t,s),s.catch(()=>pt.delete(t))}return s}function hr(t,e){let n=t.default;if(typeof n=="function"&&n.prototype instanceof HTMLElement){let s=n.prototype[Qt];if(typeof s!="function")throw new U("shape");let r=class extends n{},o=`${e?.element??"wl-app"}-${pr()}${++ur}`;try{Je.define(o,r)}catch(i){throw new U("shape",Z(i))}return{tag:o,shape:"class",attach:(i,a)=>{Ft(s,i,[a])}}}if(pe(e)&&typeof t.element=="string"&&Je.get(t.element))return{tag:t.element,shape:"legacy"};throw new U("shape")}var mr=3,fr=6e4,Ne=class{constructor(e,n){h(this,"element",e);h(this,"o",n);h(this,"faults",[]);h(this,"halted",!1)}get stopped(){return this.halted}has(e){try{return!this.halted&&typeof this.element[e]=="function"}catch{return!1}}update(e){this.halted||this.run(()=>this.element.update?.(e))}reset(){this.halted||this.run(()=>this.element.reset?.())}paging(){return this.halted?null:dr(this.element)}hook(e,n){if(this.halted)return Promise.resolve();let s;try{s=this.element[e]?.(n)}catch(r){return this.fault(r),Promise.resolve()}return Promise.resolve(s).then(()=>{},r=>this.fault(r))}stop(e){if(!this.halted){this.halted=!0;try{this.element.remove()}catch{}this.o.dispose?.(),this.o.onStop(e)}}dispose(){this.o.dispose?.()}run(e){try{e()}catch(n){this.fault(n)}}fault(e){let n=(this.o.now??Date.now)();this.faults=this.faults.filter(s=>n-s<fr),this.faults.push(n),this.faults.length>=mr&&this.stop(Z(e))}},gr=24*3600*1e3,Oe=class t{constructor(e){h(this,"o",e);h(this,"memory",new Map);h(this,"inflight",new Map);h(this,"images",new Map);h(this,"pictures",new Map)}now(){return this.o.now?.()??Date.now()}url(e){let n=this.o.base();if(!n)return;let s=this.o.token(),r=`${n.replace(/\/$/,"")}${e}`;return s?`${r}${r.includes("?")?"&":"?"}${s}`:r}stored(e){return this.memory.get(e)??this.o.store?.getItem(e)??void 0}static keyOf(e,n){let s=Object.keys(n).sort().map(r=>`${encodeURIComponent(r)}=${encodeURIComponent(String(n[r]))}`).join("&");return{query:s,key:`wyndlass:data:${e}?${s}`}}kept(e,n){let s=this.stored(t.keyOf(e,n).key);if(s)try{let r=JSON.parse(s);return this.dress(r,Date.parse(r.expiresAt)<=this.now())}catch{return}}keep(e,n){this.memory.set(e,n);try{this.o.store?.setItem(e,n)}catch{}}get(e,n){let{query:s,key:r}=t.keyOf(e,n),o=this.inflight.get(r);if(o)return o;let i=this.o.fetch??fetch,a=(async()=>{let d=this.stored(r),p=d?JSON.parse(d):void 0;if(p&&Date.parse(p.expiresAt)>this.now())return this.dress(p,!1);let c=this.url(`/v0/${encodeURIComponent(e)}?${s}`);try{if(!c)throw new Error("no data service");let l=await i(c);if(!l.ok)throw new Error(`the data service answered ${l.status}`);let m=await l.text();return this.keep(r,m),this.dress(JSON.parse(m),!1)}catch(l){if(p&&Date.parse(p.expiresAt)+gr>this.now())return this.dress(p,!0);throw l}})().finally(()=>this.inflight.delete(r));return this.inflight.set(r,a),a}dress(e,n){return{...e,offline:n,ageMs:Math.max(0,this.now()-Date.parse(e.fetchedAt))}}image(e){let n=this.images.get(e);return n||(n=this.imageBlob(e).then(s=>URL.createObjectURL(s)),this.images.set(e,n),n.catch(()=>this.images.delete(e))),n}imageBlob(e){let n=this.pictures.get(e);if(!n){let s=this.url(e);n=s?(this.o.fetch??fetch)(s).then(r=>{if(!r.ok)throw new Error(`the image answered ${r.status}`);return r.blob()}):Promise.reject(new Error("no data service")),this.pictures.set(e,n),n.catch(()=>this.pictures.delete(e))}return n}};var sn="wyndlass.frame";function ln(t,e){return!!t&&(t.apps?t.apps(e):!pe(e))}var yr=new Set(["load","shape","unsupported","error","late","overran"]),rn=50,on=250,ct=class{constructor(e,n,s,r){h(this,"frame",e);h(this,"port",n);h(this,"o",r);h(this,"halted",!1);h(this,"pages");h(this,"hooks");h(this,"pending",new Map);h(this,"next",0);h(this,"told");h(this,"last");h(this,"quiet");this.hooks=new Set(s.hooks),this.pages=s.paging}get stopped(){return this.halted}has(e){return!this.halted&&this.hooks.has(e)}paging(){return this.halted?null:this.pages}update(e){if(this.halted)return;let n=performance.now(),s=this.last;this.last={t:e,at:n};let r=this.told;if(r&&(r.running?Math.abs(e-(r.t+(n-r.at)))<=rn:e===r.t)){r.running&&this.watch();return}let o=!!s&&n-s.at<on&&e>s.t&&Math.abs(e-s.t-(n-s.at))<=rn;this.told={t:e,at:n,running:o},this.post({type:"clock",t:e,running:o}),o&&this.watch()}reset(){this.halted||this.post({type:"reset"})}snapshots(e){this.halted||this.post({type:"snapshots",snapshots:e})}hook(e,n){if(this.halted)return Promise.resolve();let s=++this.next;return new Promise(r=>{this.pending.set(s,r),this.post({type:"hook",id:s,kind:e,options:n})})}stop(e){this.halted||(this.halted=!0,this.frame.remove(),this.dispose(),this.o.onStop(e))}dispose(){this.o.dispose?.(),clearTimeout(this.quiet),this.port.close();for(let e of this.pending.values())e();this.pending.clear()}heard(e){e.type==="paging"?this.pages=pn(e.paging):e.type==="hooked"&&typeof e.id=="number"?(this.pending.get(e.id)?.(),this.pending.delete(e.id)):e.type==="stopped"&&this.stop(cn(e.error))}post(e){try{this.port.postMessage(e)}catch{}}watch(){clearTimeout(this.quiet),this.quiet=setTimeout(()=>{!this.told?.running||!this.last||this.halted||(this.told={...this.last,running:!1},this.post({type:"clock",t:this.last.t,running:!1}))},on)}};async function dn(t,e,n,s,r,o,i,a,d,p){let c=t.appInfo??n.info,l;try{l=new URL(d.frames).origin}catch{return p("unsupported")}let m=document.createElement("iframe");m.setAttribute("sandbox","allow-scripts"),m.setAttribute("referrerpolicy","no-referrer"),m.title=c?.id??"app",m.tabIndex=-1,m.dataset.frame=c?.id??"",m.style.cssText="display:block;width:100%;height:100%;border:0;pointer-events:none;background:transparent;color-scheme:normal";let g=new Promise(A=>{m.addEventListener("load",()=>A(!0),{once:!0}),setTimeout(()=>A(!1),o)});m.src=`${l}/`,e.append(m);let w=(A,k)=>(m.remove(),p(A,k));if(!await g||!m.contentWindow)return w("load");let{port1:f,port2:b}=new MessageChannel,v={type:"init",element:{id:t.id,type:"app",app:t.app,props:t.props??{},...t.binding?{binding:t.binding}:{},...t.appInfo?{appInfo:t.appInfo}:{}},bundle:{hash:n.hash,bytes:n.bytes.slice(),...n.info?{info:n.info}:{}},...s.place?{place:s.place}:{},screen:s.screen??null,timeZone:s.timeZone,locale:s.locale,preview:!!s.preview,clock:{t:r.now(),running:!1,startedAt:r.startedAt()},fonts:vr(t.props??{},d),snapshots:an(t,s),deadlineMs:o};return new Promise(A=>{let k,I=!1,O=ne=>{I||(I=!0,clearTimeout(V),A(ne))},V=setTimeout(()=>{k?(O({app:k,late:!0}),k.update(r.now())):(f.close(),O(w("load")))},o+1e3),F=!1;f.onmessage=ne=>{let P=ne.data;if(!(!P||typeof P!="object")){if(P.type==="ask"){F&&br(P,s,f);return}if(k){P.type==="ready"?(O({app:k,late:P.late===!0}),k.update(r.now())):k.heard(P);return}if(P.type==="hello"&&!F)F=!0,f.postMessage(v,[v.bundle.bytes.buffer]);else if(P.type==="made"&&Array.isArray(P.hooks)){let se=un(t),be,M=new ct(m,f,{type:"made",hooks:P.hooks.filter(T=>T==="enter"||T==="exit"),paging:pn(P.paging)},{onStop:a,dispose:()=>be?.()});be=s.onSnapshots?.(T=>{T.some(B=>se.has(B))&&M.snapshots(an(t,s))}),k=M,i(k)}else P.type==="failed"&&(f.close(),O(w(yr.has(P.reason)?P.reason:"error",cn(P.error))))}},m.contentWindow.postMessage({type:sn},"*",[b])})}async function br(t,e,n){if(typeof t.id!="number")return;let s=(r,o=[])=>{try{n.postMessage(r,o)}catch{}};try{if(!e.data)throw new Error("no data service");if(t.what==="data"&&typeof t.source=="string")s({type:"answer",id:t.id,value:await e.data.get(t.source,wr(t.params))});else if(t.what==="image"&&typeof t.path=="string"){let r=await e.data.imageBlob(t.path),o=new Uint8Array(await r.arrayBuffer());s({type:"answer",id:t.id,value:{bytes:o,type:r.type}},[o.buffer])}else throw new TypeError("not a question")}catch(r){s({type:"answer",id:t.id,error:Z(r)??"Error"})}}function wr(t){let e={};if(t&&typeof t=="object")for(let[n,s]of Object.entries(t))(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(e[n]=s);return e}function pn(t){let e=t;return e&&Number.isInteger(e.count)&&e.count>1&&typeof e.ms=="number"&&e.ms>0?{count:e.count,ms:e.ms}:null}function cn(t){return typeof t=="string"&&/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(t)?t:void 0}function vr(t,e){let n=new Set;for(let r of Object.values(t)){let o=r?.family;r&&typeof r=="object"&&typeof o=="string"&&n.add(o)}let s=[];for(let r of e.fonts??[]){let o=n.has(r.family)?e.font?.(r.blob):void 0;o&&s.push({family:r.family,weight:r.weight,style:r.style,blob:r.blob,bytes:o.slice()})}return s}function un(t){let e=new Set;t.binding?.table&&e.add(t.binding.table);for(let n of Object.values(t.props??{}))typeof n=="string"&&/^tbl_[0-9a-z]{26}$/.test(n)&&e.add(n);return e}function an(t,e){let n={};for(let s of un(t)){let r=e.snapshot?.(s);r&&(n[s]=r)}return n}function hn(t){let e=ie?.setStyle??((n,s,r,o)=>n.style.setProperty(s,r,o));e(t,"contain","strict","important"),e(t,"overflow","clip","important")}var mn=t=>!!(t?.filter?.length||t?.sort||t?.limit),kr=t=>t==null||t==="";function xr(t,e){if(!kr(t))switch(e){case"number":case"currency":{let n=Number(t);return Number.isFinite(n)?n:void 0}case"datetime":{let n=Date.parse(String(t));return Number.isNaN(n)?void 0:n}case"boolean":return t===!0||String(t).toLowerCase()==="true"?1:0;case"date":return String(t).slice(0,10);default:return String(t).toLowerCase()}}function Mr(t,e){let n=Array.from(t),s=Array.from(e);for(let r=0;r<n.length&&r<s.length;r++){let o=n[r].codePointAt(0)-s[r].codePointAt(0);if(o!==0)return o}return n.length-s.length}function Ar(t,e,n,s,r){let o=t,i=Array.isArray(o?.rows)?o.rows:[],a=Array.isArray(o?.columns)?o.columns:void 0,d=p=>a?.find(c=>c.key===p)?.type??"text";for(let p of e.filter??[]){if(a&&!a.some(m=>m.key===p.column))return[];let c=p.value;if(c!==null&&typeof c=="object"){let m=c;if(c=Le(n,s,m.screen,m.key),c===void 0)return[]}let l=d(p.column);i=i.filter(m=>Vt(m[p.column],p.op,c,l,r,s))}if(e.sort){let{column:p}=e.sort,c=d(p),l=e.sort.order==="desc"?-1:1;i=i.map((m,g)=>({row:m,i:g,key:xr(m[p],c)})).sort((m,g)=>{if(m.key===void 0||g.key===void 0)return m.key===void 0&&g.key===void 0?m.i-g.i:m.key===void 0?1:-1;let w=typeof m.key=="number"&&typeof g.key=="number"?m.key-g.key:Mr(String(m.key),String(g.key));return w===0?m.i-g.i:w<0?-l:l}).map(m=>m.row)}return e.limit?i.slice(0,e.limit):i}function fn(t,e,n,s,r){return!t||typeof t!="object"?t:{...t,rows:Ar(t,e,n,s,r)}}function Sr(t){if(!t)return"#000000";if("value"in t)return t.value;let e=t.gradient,n=[...e.stops].sort((s,r)=>s.at-r.at).map(s=>`${s.color.value} ${Math.round(s.at*1e4)/100}%`).join(", ");return e.kind==="radial"?`radial-gradient(circle, ${n})`:`linear-gradient(${e.angle??180}deg, ${n})`}function yn(t,e,n,s=[]){let r=H("div");if(r.dataset.background="",r.style.cssText="position:absolute;inset:0;pointer-events:none",r.style.background=Sr(e),s.length){let o=[`M0 0H${n.width}V${n.height}H0Z`,...s.map(d=>`M${d.x} ${d.y}H${d.x+d.w}V${d.y+d.h}H${d.x}Z`)].join(""),i=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${n.width} ${n.height}" preserveAspectRatio="none"><path fill-rule="evenodd" d="${o}"/></svg>`,a=`url("data:image/svg+xml,${encodeURIComponent(i)}")`;r.dataset.holes=String(s.length);for(let[d,p]of[["maskImage",a],["maskSize","100% 100%"],["maskRepeat","no-repeat"]])r.style[d]=p,r.style[`webkit${d[0].toUpperCase()}${d.slice(1)}`]=p}return t.prepend(r),r}function bn(t,e=t.frame){let n=H("div");return n.dataset.element=t.id,n.style.cssText="position:absolute;box-sizing:border-box",Er(n,e),n}function Er(t,e){Object.assign(t.style,{left:`${e.x}px`,top:`${e.y}px`,width:`${e.w}px`,height:`${e.h}px`,transform:e.rotation?`rotate(${e.rotation}deg)`:""})}function wn(t,e,n){if(e.type==="text"){let s=e.style??{};t.textContent=ut(e,ce(n)),Object.assign(t.style,{fontFamily:s.font?.family?`"${s.font.family}", sans-serif`:"",fontWeight:String(s.font?.weight??400),fontStyle:s.font?.style??"normal",fontSize:`${s.size??48}px`,color:s.color?.value??"#ffffff",background:s.background?.value??"",whiteSpace:"pre-wrap",textAlign:{start:"left",end:"right"}[s.align??"start"]??s.align??"left",display:"flex",flexDirection:"column",justifyContent:{top:"flex-start",middle:"center",bottom:"flex-end"}[s.verticalAlign??"top"],lineHeight:s.lineHeight?String(s.lineHeight):"",opacity:s.opacity!==void 0?String(s.opacity):"",textDecorationLine:s.decoration?.length?s.decoration.join(" "):"",textTransform:s.transform&&s.transform!=="none"?s.transform:"",letterSpacing:s.letterSpacing?`${s.letterSpacing}em`:"",textShadow:s.shadow?`${s.shadow.x??0}px ${s.shadow.y??2}px ${s.shadow.blur??4}px ${s.shadow.color?.value??"#000000"}`:""})}else e.type==="shape"&&Tr(e)?(t.style.opacity=e.opacity!==void 0?String(e.opacity):"",t.append(Pr(e))):e.type==="shape"?Object.assign(t.style,{background:e.fill?.value??"",opacity:e.opacity!==void 0?String(e.opacity):"",border:e.stroke?.width?`${e.stroke.width}px ${e.stroke.dash??"solid"} ${e.stroke.color?.value??"#000"}`:"",borderRadius:e.shape==="ellipse"?"50%":e.radius?`${e.radius}px`:"",overflow:e.clip!==!1?"hidden":""}):e.type==="library"&&(t.style.overflow="hidden",t.style.background=e.playback?.background?.value??"")}function ut(t,e){return t.bind?tt(t.bind,e):nt(t.text??"",e)}function ce(t){return{screen:t?.screen??null,timeZone:t?.timeZone,tables:new Proxy({},{get:(e,n)=>typeof n=="string"?t?.snapshot?.(n):void 0})}}var Tr=t=>t.shape==="line"||t.shape==="arrow"||t.shape==="polygon";function Pr(t){let e=Se("svg");e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.style.cssText="position:absolute;inset:0;overflow:visible";let n=t.frame.w,s=t.frame.h,r=t.stroke?.width??(t.shape==="polygon"?0:4),i=(t.points?.length?t.points:t.shape==="polygon"?[[.5,0],[1,1],[0,1]]:[[0,.5],[1,.5]]).map(([c,l])=>[c*n,l*s]),a=t.stroke?.color?.value??"#000000",d=t.stroke?.dash==="dashed"?`${r*3} ${r*2}`:t.stroke?.dash==="dotted"?`0 ${r*2}`:"",p=Se(t.shape==="polygon"?"polygon":"polyline");if(p.setAttribute("points",i.map(c=>`${c[0]},${c[1]}`).join(" ")),p.setAttribute("fill",t.shape==="polygon"?t.fill?.value??"none":"none"),r&&(p.setAttribute("stroke",a),p.setAttribute("stroke-width",String(r)),p.setAttribute("stroke-linecap",t.stroke?.dash==="dotted"?"round":"butt"),p.setAttribute("stroke-linejoin","round"),d&&p.setAttribute("stroke-dasharray",d)),e.append(p),t.shape==="arrow"&&i.length>=2){let[c,l]=[i[i.length-2],i[i.length-1]],m=Math.atan2(l[1]-c[1],l[0]-c[0]),g=Math.max(10,r*3.5),w=b=>`${l[0]-g*Math.cos(m)+b*g*.5*Math.sin(m)},${l[1]-g*Math.sin(m)-b*g*.5*Math.cos(m)}`;p.setAttribute("points",[...i.slice(0,-1),[l[0]-g*.8*Math.cos(m),l[1]-g*.8*Math.sin(m)]].map(b=>`${b[0]},${b[1]}`).join(" "));let f=Se("polygon");f.setAttribute("points",`${l[0]},${l[1]} ${w(1)} ${w(-1)}`),f.setAttribute("fill",a),e.append(f)}return e}async function vn(t,e,n,s,r,o,i,a=()=>{},d){let p=t.appInfo??n.info;hn(e),p?.id&&(e.dataset.app=p.id);let c=(M,T)=>(e.dataset.appFailed=M,{failed:M,...T?{error:T}:{}});if(!tn(p?.requires))return c("unsupported");let l=s.appHost;if(l&&!l.custom&&!pe(p))return c("unsupported");if(ln(d,p))return dn(t,e,n,s,r,o,i,a,d,c);let m=t.app;if(l?.held?.(m))return e.dataset.appHeld="",{held:!0};await l?.mounting?.(m,p?.id);let g=!1,w=()=>{g||(g=!0,l?.unmounted?.(m))},f;try{f=await nn(n.hash,n.bytes,p)}catch(M){return w(),M instanceof U?c(M.reason,M.error):c("load")}let b=f.tag,v=p?.id?s.controllerFor?.({id:p.id,instance:t.id,capability:p.player??"read"}):void 0,A,k=new Promise(M=>{A=M}),I,O=new Set,V={app:p?.id??t.app.id,element:b,props:st(t.props??{},ce(s)),place:s.place,screen:s.screen??null,timeZone:s.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,locale:s.locale??navigator.language,preview:!!s.preview,now:r.now,startedAt:r.startedAt,ready:()=>A(),data:(M,T)=>s.data?s.data.get(M,T):Promise.reject(new Error("no data service")),kept:(M,T)=>s.data?.kept?.(M,T),image:M=>s.data?s.data.image(M):Promise.reject(new Error("no data service")),snapshot:M=>{let T=s.snapshot?.(M)??null;if(!T||t.binding?.table!==M||!mn(t.binding))return T;let B=fn(T,t.binding,s.screen,V.timeZone,r.now());return I?.from===T&&I.rows.length===B.rows.length&&I.rows.every((ns,ss)=>ns===B.rows[ss])?I.snapshot:(I={from:T,rows:B.rows,snapshot:B},B)},...t.binding?{binding:t.binding}:{},...s.onSnapshots?{onSnapshot:M=>(O.add(M),()=>{O.delete(M)})}:{},...t.sensors?.includes("impressions")&&s.impressions?.measuring?{impressions:{now:()=>s.impressions.now(),on:M=>s.impressions.on(M)}}:{},...v?{controller:v}:{}},F;try{F=H(b),f.shape==="class"?f.attach(F,V):F.wyndlass=V}catch(M){return v?.dispose(),w(),c("error",Z(M))}F.style.cssText="display:block;width:100%;height:100%",l?.contained?.(e,F);let ne=Object.values(t.props??{}).some(M=>typeof M=="string"&&Ie(M)),P=s.onSnapshots?.(M=>{ne&&(V.props=st(t.props??{},ce(s)));for(let T of M)for(let B of[...O])try{B(T)}catch{}}),se=new Ne(F,{onStop:a,dispose:()=>{P?.(),O.clear(),v?.dispose(),w()}});e.append(F),i(se);let be=await Promise.race([k.then(()=>!1),new Promise(M=>setTimeout(()=>M(!0),o))]);return se.update(V.now()),{app:se,late:be}}var gn=new Set;async function kn(t,e){for(let n of t){let s=`${n.family}/${n.weight??400}/${n.style??"normal"}/${n.blob}`,r=e(n.blob);if(!(gn.has(s)||!r||typeof FontFace>"u"))try{let o=new FontFace(n.family,r,{weight:String(n.weight??400),style:n.style??"normal"});document.fonts.add(await o.load()),gn.add(s)}catch{}}}function ue(t){let e=[],n=null;for(let s of t){let r=s.start,o=Math.max(0,r.kind==="at"?r.ms:r.kind==="withPrevious"?(n?.startMs??0)+(r.offsetMs??0):(n?.endMs??0)+(r.offsetMs??0));n={startMs:o,endMs:o+s.durationMs},e.push(n)}return{clips:e,autoDurationMs:e.reduce((s,r)=>Math.max(s,r.endMs),0)}}var Lr=new Set(["x","y","scaleX","scaleY","rotation","opacity","reveal"]);function Ir(t,{pageBelow:e=!1}={},n=null){let s=o=>({path:"page",reason:o});if(!n)return s("no-media-layer");if(e)return s("page-element-beneath");let r=t.slice(0,-1).filter(o=>o.type==="shape"&&o.clip!==!1);if(r.some(o=>o.shape!=="rectangle"||(o.radius??0)>0))return s("clipped-to-shape");if(r.some(o=>(o.rotation??0)%360!==0))return s("clipped-by-rotated-shape");if(!n.animates){if(t.some(o=>(o.rotation??0)%360!==0))return s("rotated");if(t.some(o=>(o.opacity??1)<1))return s("translucent");if(t.some(o=>(o.animated??[]).some(i=>Lr.has(i))))return s("animated")}return{path:"native"}}var Cr={fade:["opacity"],slide:["x","opacity"],scale:["scaleX","scaleY","opacity"],pulse:["scaleX","scaleY"],loop:["scaleX","scaleY"],wipe:["reveal"]};function xn(t,e,n,s){let r=e&&t.overrides?.[e]||{},o=new Map;for(let l of t.animation?.clips??[]){let m=[...l.preset?Cr[l.preset]??[]:[],...(l.lanes??[]).map(g=>g.property)];o.set(l.element,[...o.get(l.element)??[],...m])}let i=l=>l.type==="library"&&!!l.source&&!!n[l.source.item.id]?.video,a=l=>!i(l)&&!(l.type==="shape"&&!l.fill&&!(l.stroke?.width??0)),d=[],p=(l,m,g,w)=>{for(let f of l){let b=r[f.id];if(b?.hidden??f.hidden??!1)continue;let v=b?.frame??f.frame,A={x:m.x+v.x,y:m.y+v.y,w:v.w,h:v.h},k={type:f.type==="shape"?"shape":"library",rotation:v.rotation??0,opacity:f.opacity??f.style?.opacity??1,animated:o.get(f.id)??[],...f.type==="shape"?{shape:f.shape,radius:f.radius,clip:f.clip}:{}};d.push({e:f,box:A,chain:[...g,k],ancestors:w}),f.type==="shape"&&p(f.children??[],A,[...g,k],[...w,f])}};p(t.elements,{x:0,y:0},[],[]);let c=(l,m)=>l.x<m.x+m.w&&m.x<l.x+l.w&&l.y<m.y+m.h&&m.y<l.y+l.h;return d.flatMap((l,m)=>{if(!i(l.e))return[];let g=d.slice(0,m).some(w=>a(w.e)&&c(w.box,l.box));return[{element:l.e.id,path:Ir(l.chain,{pageBelow:g},s),box:l.box}]})}var Rr=[0,0,1,1];function ht(t,e){if(e<=0)return 0;if(e>=1)return 1;let[n,s,r,o]=t;if(n===s&&r===o)return e;let i=3*n,a=3*(r-n)-i,d=1-i-a,p=3*s,c=3*(o-s)-p,l=1-p-c,m=k=>((d*k+a)*k+i)*k,g=k=>((l*k+c)*k+p)*k,w=k=>(3*d*k+2*a)*k+i,f=1e-7,b=e;for(let k=0;k<8;k++){let I=m(b)-e;if(Math.abs(I)<f)return g(b);let O=w(b);if(Math.abs(O)<1e-6)break;b-=I/O}let v=0,A=1;for(b=e;v<A;){let k=m(b);if(Math.abs(k-e)<f||(e>k?v=b:A=b,b=(A-v)/2+v,A-v<f))break}return g(b)}function $e(t,e){let n=t.keyframes;if(e<=n[0].t)return n[0].v;let s=n[n.length-1];if(e>=s.t)return s.v;let r=0;for(;e>=n[r+1].t;)r++;let o=n[r],i=n[r+1];return o.v+(i.v-o.v)*ht(o.easing??Rr,(e-o.t)/(i.t-o.t))}function Mn(t,e,n){let s={x:t.x,y:t.y,scaleX:1,scaleY:1,rotation:0,opacity:1};for(let r of e??[])s[r.property]=$e(r,n);return s}var he={linear:[0,0,1,1],ease:[.25,.1,.25,1],"ease-in":[.42,0,1,1],"ease-out":[0,0,.58,1],"ease-in-out":[.42,0,.58,1]};function An(t){if(!t)return he.ease;if(he[t])return he[t];let n=/^cubic-bezier\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^)]+)\)$/.exec(t)?.slice(1).map(Number);return n&&n.every(Number.isFinite)?n:he.ease}function Nr(t){let e=typeof t=="string"?/^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/.exec(t):null;if(!e)return null;let n=parseInt(e[1],16);return[n>>16&255,n>>8&255,n&255,e[2]?parseInt(e[2],16)/255:1]}var Tn={fade:()=>({opacity:0}),slide:t=>({x:t.x-t.w*.1,opacity:0}),scale:()=>({scaleX:.8,scaleY:.8,opacity:0}),wipe:()=>({reveal:0}),typewriter:()=>({chars:0}),"count-up":()=>({count:0})},Ta=Object.keys(Tn);var Or={x:t=>t.x,y:t=>t.y,scaleX:()=>1,scaleY:()=>1,rotation:()=>0,opacity:()=>1,reveal:()=>1,chars:()=>1,count:()=>1},Sn=1e3,$r=he["ease-in-out"];function Pn(t,e){let n=ue(t).clips,s=new Map,r=new Set,o=a=>{let d=s.get(a);return d||s.set(a,d={keys:new Map,colour:null,loops:[],tickers:[]}),d},i=(a,d,p)=>{let c=o(a).keys,l=c.get(d)??[];c.set(d,l),l.push(p)};t.forEach((a,d)=>{let p=e.get(a.element);if(!p)return;let{startMs:c,endMs:l}=n[d],m=An(a.easing);if(a.lanes?.length){for(let f of a.lanes)for(let b of f.keyframes){let v={t:c+b.at,easing:An(b.easing??a.easing)};if(f.property==="color"){let A=Nr(b.value);if(!A)continue;let k=o(a.element);k.colour??(k.colour=[[],[],[],[]]),A.forEach((I,O)=>k.colour[O].push({...v,v:I}))}else i(a.element,f.property,{...v,v:Number(b.value)})}return}let g=a.preset??"fade";if(a.kind==="emphasis"){g==="pulse"?(i(a.element,"pulse",{t:c,v:1,easing:m}),i(a.element,"pulse",{t:(c+l)/2,v:1.05,easing:m}),i(a.element,"pulse",{t:l,v:1})):g==="loop"?o(a.element).loops.push({startMs:c,endMs:l}):g==="ticker"?o(a.element).tickers.push({startMs:c,endMs:l}):r.add(g);return}let w=Tn[g];if(!w){r.add(g);return}for(let[f,b]of Object.entries(w(p))){let v=Or[f](p),[A,k]=a.kind==="enter"?[b,v]:[v,b];i(a.element,f,{t:c,v:A,easing:m}),i(a.element,f,{t:l,v:k})}});for(let a of s.values()){for(let d of a.keys.values())d.sort((p,c)=>p.t-c.t);for(let d of a.colour??[])d.sort((p,c)=>p.t-c.t)}return{motions:s,unplayed:[...r].sort()}}var Dr=["x","y","scaleX","scaleY","rotation","opacity"];function Ln(t,e,n,s=!1){if(s)return jr(t,e,n);let r=(d,p)=>{let c=t?.keys.get(d);return c?$e({property:"x",keyframes:c},n):p},o=Mn(e,Dr.flatMap(d=>t?.keys.get(d)?[{property:d,keyframes:t.keys.get(d)}]:[]),n),i=r("pulse",1);for(let d of t?.loops??[])if(n>=d.startMs&&n<d.endMs){let p=(n-d.startMs)%Sn/Sn;i*=1+.05*ht($r,p<.5?p*2:2-p*2)}let a=t?.tickers.find(d=>n>=d.startMs&&n<d.endMs);return{...o,reveal:r("reveal",1),chars:r("chars",1),count:r("count",1),pulse:i,scroll:a?(n-a.startMs)/(a.endMs-a.startMs):null,color:t?.colour?t.colour.map(d=>$e({property:"x",keyframes:d},n)):null}}function En(t,e){if(e<t[0].t)return t[0].v;let n=0;for(;n+1<t.length&&t[n+1].t<=e;)n++;return n+1<t.length?t[n+1].v:t[n].v}function jr(t,e,n){let s=(r,o)=>{let i=t?.keys.get(r);return i?En(i,n):o};return{x:s("x",e.x),y:s("y",e.y),scaleX:s("scaleX",1),scaleY:s("scaleY",1),rotation:s("rotation",0),opacity:s("opacity",1),reveal:s("reveal",1),chars:s("chars",1),count:s("count",1),pulse:1,scroll:null,color:t?.colour?t.colour.map(r=>En(r,n)):null}}function Fr(t,e){let n=Array.from(t);return e>=1?t:n.slice(0,Math.max(0,Math.round(e*n.length))).join("")}function Hr(t,e){return e>=1?t:t.replace(/\d+(?:\.\d+)?/g,n=>(Number(n)*Math.max(0,e)).toFixed((n.split(".")[1]??"").length))}function In(t,e,n){if(t<=1||e<=0)return[{page:0,startMs:0,endMs:n}];let s=[];for(let r=0;r*e<n&&r<1e3;r++)s.push({page:r%t,startMs:r*e,endMs:Math.min((r+1)*e,n)});return s}function Cn(t,e,n,s){t.style.left=`${n.x}px`,t.style.top=`${n.y}px`,t.style.transform=`rotate(${(e.frame.rotation??0)+n.rotation}deg) scale(${n.scaleX*n.pulse}, ${n.scaleY*n.pulse})`,t.style.opacity=String((e.opacity??e.style?.opacity??1)*n.opacity),t.style.clipPath=n.reveal>=1?"":`inset(0 ${(1-Math.max(0,n.reveal))*100}% 0 0)`;let r=n.color?`rgba(${n.color.slice(0,3).map(o=>Math.round(o)).join(",")},${n.color[3]})`:null;if(e.type==="text"&&s!==void 0){let o=Hr(Fr(s,n.chars),n.count);if(n.scroll!==null){let i=t.querySelector("[data-ticker]");i||(i=document.createElement("span"),i.dataset.ticker="",i.style.cssText="display:inline-block;white-space:nowrap;will-change:transform",t.replaceChildren(i),t.style.overflow="hidden"),i.textContent!==o&&(i.textContent=o);let a=e.frame.w,d=i.scrollWidth;i.style.transform=`translateX(${a-n.scroll*(a+d)}px)`}else(t.textContent!==o||t.querySelector("[data-ticker]"))&&(t.textContent=o,t.style.overflow="");r&&(t.style.color=r)}else if(e.type==="shape"&&r){let o=t.querySelector("polygon, polyline");o&&e.shape==="polygon"?o.setAttribute("fill",r):o||(t.style.background=r)}}function Br(t){let e=t>>>0;return()=>{e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}async function Rn(t,e,n,s){let r=parseInt((await et(Qe(`${t}
|
|
3
3
|
${e}
|
|
4
|
-
${n}`))).slice(0,8),16),o=xr(r),i=Array.from({length:s},(a,p)=>p);for(let a=s-1;a>0;a--){let p=Math.floor(o()*(a+1));[i[a],i[p]]=[i[p],i[a]]}return i}var Mr=250,Ar=1e3;function Dt(t,e){let n=t.animation?.duration;if(n?.kind==="fixed")return{durationMs:n.ms};if(n?.kind==="untilPlaylistEnds"){let s=vn(t.elements,n.element);return{durationMs:(s?.source?.kind==="playlist"?e.playlist(s.source.item)??[]:s?.source?[{item:s.source.item}]:[]).reduce((i,a)=>i+(e.slide(a,{imageDurationMs:s?.playback?.imageDurationMs})?.durationMs??0),0)||1e4,untilPass:n.element}}return{durationMs:de(t.animation?.clips??[]).autoDurationMs}}function wn(t,e,n=0){let s={},r=o=>{for(let i of o){if(i.type==="library"&&i.source){let a=i.source.kind==="playlist"?e.playlist(i.source.item)??[]:[{item:i.source.item}];s[i.source.item.id]={video:a.some(p=>{let l=e.slide(p);if(!l)return!1;if(l.blob.contentType.startsWith("video/"))return!0;let c=l.layout;return!!c&&n<4&&Object.values(wn(c.doc,c.source,n+1)).some(d=>d.video)})}}i.children&&r(i.children)}};return r(t.elements),s}function vn(t,e){for(let n of t){if(n.id===e)return n;let s=n.children&&vn(n.children,e);if(s)return s}}var Y=class{constructor(e,n,s,r={}){h(this,"source",n);h(this,"o",r);h(this,"el");h(this,"ready");h(this,"unplayed");h(this,"doc");h(this,"motions");h(this,"native");h(this,"animated",[]);h(this,"loops",[]);h(this,"startedAt",0);h(this,"frame",0);h(this,"running",!1);h(this,"disposed",!1);h(this,"apps",[]);h(this,"heldAt");h(this,"late",[]);h(this,"overran",[]);h(this,"timers",[]);h(this,"reduced",typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches);let o=s.clientWidth||window.innerWidth,i=s.clientHeight||window.innerHeight,a=!e.profiles[0].width,p=a?{...e.profiles[0],width:o,height:i}:e.profiles[0];a&&(e={...e,elements:e.elements.map(v=>v.frame.w?v:{...v,frame:{x:0,y:0,w:o,h:i}})});let l=Math.min(o/p.width,i/p.height);this.el=j("div"),this.el.dataset.layout=p.id,this.el.style.cssText=`position:absolute;left:${(o-p.width*l)/2}px;top:${(i-p.height*l)/2}px;width:${p.width}px;height:${p.height}px;transform:scale(${l});transform-origin:0 0;overflow:hidden`,s.append(this.el),this.doc=e;let c=new Map,d=v=>{for(let A of v)c.set(A.id,A.frame),A.children&&d(A.children)};d(e.elements);let m=mn(e.animation?.clips??[],c);this.motions=m.motions;let g=new Set(m.unplayed.map(v=>`preset ${v}`)),w=[this.loadFonts()],f=r.media?an(e,void 0,wn(e,n),r.media.capability):[];this.native=new Set(f.filter(v=>v.path.path==="native").map(v=>v.element));let b=(v,A)=>{for(let k of v){if(k.hidden)continue;let P=this.element(k,g,w);A.append(P),k.children?.length&&k.type==="shape"&&b(k.children,P)}};b(e.elements,this.el),e.background&&en(this.el,e.background,p,f.filter(v=>this.native.has(v.element)).map(v=>v.box)),this.unplayed=[...g].sort(),this.ready=Promise.all(w).then(()=>{})}path(e){return this.o.path?`${this.o.path}/${e}`:e}element(e,n,s){let r=tn(e);nn(r,e,this.source);let o=this.motions.get(e.id);if(o){let i={el:r,e,motion:o,text:e.type==="text"?r.textContent??"":void 0};this.animated.push(i),this.place(i,0)}if(e.type==="library"&&e.source){let i=e.source.kind==="playlist"?this.source.playlist(e.source.item)??[]:[{item:e.source.item}],a=new st(r,i,e.playback??{},this.source,this.path(e.id),{...this.o,media:this.native.has(e.id)?this.o.media:void 0},e.source.kind==="playlist"?e.source.item:void 0);this.loops.push(a),s.push(a.ready);for(let p of a.unplayed)n.add(p)}else if(e.type==="app"){let i=e.app?this.source.app?.(e.app):null;i?s.push(this.mountApp(e,r,i)):n.add(`app ${e.app?.id??e.id}`)}return r}place(e,n){gn(e.el,e.e,hn(e.motion,e.e.frame,n,this.reduced),e.text);let s=e.e.type==="text"?e.el.firstElementChild:null;s&&_e(s)}loadFonts(){return on(this.doc.fonts??[],e=>this.source.font(e))}async mountApp(e,n,s){let r=this.path(e.id),o=e.app,i=(e.appInfo??s.info)?.id,a={now:()=>this.heldAt??Date.now(),startedAt:()=>this.startedAt||Date.now()},p=(d,m)=>this.o.onApp?.({type:"app.failed",element:r,item:o,...i?{app:i}:{},reason:d,...m?{error:m}:{}}),l=this.o.isolate?{...this.o.isolate,fonts:this.doc.fonts,font:d=>this.source.font(d)}:void 0,c=await rn(e,n,s,this.source,a,this.o.appDeadlineMs??5e3,d=>{this.disposed?d.dispose():this.apps.push({app:d,box:n,path:r,id:e.id,item:o})},d=>p("error",d),l);if(!("held"in c)){if("failed"in c){p(c.failed,c.error);return}c.late&&(this.late.push(r),this.o.onAppLate?.(r,o.id),p("late"))}}async start(e=Date.now()){this.startedAt=e,this.heldAt=void 0,this.running=!0,this.hooks(e);let n=()=>{if(!this.running)return;let s=Date.now(),r=s-this.startedAt;for(let o of this.animated)this.place(o,r);for(let o of this.apps)o.app.update(s);this.frame=requestAnimationFrame(n)};(this.animated.length||this.apps.length)&&(this.frame=requestAnimationFrame(n)),await Promise.all(this.loops.map(s=>s.start()))}hooks(e){let n=this.doc.animation?.clips??[],s=de(n).clips,r=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches;for(let o of this.apps){let a=n.map((f,b)=>({c:f,t:s[b]})).filter(f=>f.c.element===o.id&&(f.c.kind==="enter"||f.c.kind==="exit")).filter(f=>o.app.has(f.c.kind));if(!a.length)continue;let p=o.box,l=this.animated.findIndex(f=>f.el===p);l>=0&&(this.animated.splice(l,1),Object.assign(p.style,{opacity:"",transform:"",clipPath:""}));let c=(f,b,v)=>this.hook(o,f.kind,{startAt:b,preset:f.preset??"fade",durationMs:f.durationMs,easing:f.easing,delayMs:0,...f.staggerMs?{staggerMs:f.staggerMs}:{},...v!==void 0?{page:v}:{},reducedMotion:r},p);for(let{c:f,t:b}of a)c(f,e+b.startMs);let d=o.app.paging();if(!d)continue;let m=a.find(f=>f.c.kind==="enter")?.c,g=a.find(f=>f.c.kind==="exit")?.c,w=fn(d.count,d.ms,Dt(this.doc,this.source).durationMs);for(let f=1;f<w.length;f++){let b=e+w[f].startMs;g&&c(g,b-g.durationMs,w[f-1].page),m&&c(m,b,w[f].page)}}}hook(e,n,s,r){let o=!1;e.app.hook(n,s).finally(()=>{o=!0});let i=s.startAt+s.durationMs;this.timers.push(setTimeout(()=>{o||!this.running||(this.overran.includes(e.path)||(this.overran.push(e.path),this.o.onAppOverran?.(e.path,e.item.id),this.o.onApp?.({type:"app.failed",element:e.path,item:e.item,reason:"overran"})),n==="exit"&&(r.style.visibility="hidden"))},Math.max(0,i+Mr-Date.now())))}pause(){this.heldAt=Date.now();for(let e of this.loops)e.pause();for(let e of this.apps)e.app.update(this.heldAt)}seek(e){this.running=!1,cancelAnimationFrame(this.frame);for(let n of this.loops)n.pause();for(let n of this.animated)this.place(n,e);this.heldAt=this.startedAt+e;for(let n of this.apps)n.app.update(this.heldAt)}resume(){this.heldAt=void 0;for(let e of this.loops)e.resume()}paging(e){return this.apps.find(n=>n.id===e)?.app.paging()??null}dispose(){this.running=!1,this.disposed=!0,cancelAnimationFrame(this.frame);for(let e of this.timers)clearTimeout(e);for(let e of this.loops)e.stop();for(let e of this.apps)e.app.dispose();this.el.remove()}},bn=t=>Math.min(Math.max(0,t),2**31-1),st=class{constructor(e,n,s,r,o,i,a){h(this,"region",e);h(this,"playback",s);h(this,"source",r);h(this,"path",o);h(this,"o",i);h(this,"list",a);h(this,"ready");h(this,"unplayed",[]);h(this,"renderer");h(this,"slides");h(this,"order",[]);h(this,"pass",0);h(this,"at",0);h(this,"timer");h(this,"current");h(this,"shownAt",0);h(this,"remaining");h(this,"stopped",!1);h(this,"ended",!1);h(this,"empty",!1);h(this,"open");h(this,"pages");this.renderer=new Me(e,{media:i.media,fit:s.fit,path:o,onItem:i.onItem,onPassEnd:i.onPassEnd,onApp:i.onApp}),s.transition==="slide"&&this.unplayed.push("transition slide");let p=s.transition==="fade"?{type:"crossfade"}:void 0,l=n.map(c=>r.slide(c,{imageDurationMs:s.imageDurationMs,transition:p,region:!0})).filter(c=>!!c);this.slides=l.length===1&&l[0].untilEnd&&(s.onEnd??"loop")==="loop"?[{...l[0],untilEnd:!1,loop:!0}]:l,this.renderer.onMediaEnd(c=>{c===this.current&&!this.stopped&&(clearTimeout(this.timer),this.next("completed"))}),this.ready=this.newPass().then(()=>this.slides.length?this.renderer.prepare(this.slides[this.order[0]]):void 0).catch(()=>{})}async newPass(){let e=this.slides.length;this.order=this.playback.order==="shuffle"?await yn(this.source.deviceId,this.path,this.pass,e):[...Array(e).keys()],this.at=0}async start(){this.slides.length&&await this.first()}bounds(e){return[this.source.bounds?.(e.item),this.list&&this.source.bounds?.(this.list)]}seek(e){let n=Date.now(),s=e;for(;s<this.order.length&&!this.bounds(this.slides[this.order[s]]).every(r=>Ot(r,n));)s++;return s}async first(){if(this.at=this.seek(0),this.at<this.order.length){this.empty=!1,await this.show();return}this.empty=!0,this.current=void 0,this.renderer.standby();let e=Date.now(),n=this.slides.flatMap(s=>this.bounds(s).map(r=>r?.from??0)).filter(s=>s>e);clearTimeout(this.timer),n.length&&(this.timer=setTimeout(()=>{!this.stopped&&!this.ended&&this.first()},bn(Math.min(...n)-e)))}async show(){let e=this.slides[this.order[this.at]];this.current=e;try{await this.renderer.show(e)}catch(s){if(this.stopped)return;this.o.onItem?.({type:"item.error",element:this.path,item:e.item,blob:e.blob.hash,...Xe(s)}),this.o.onItem?.({type:"item.end",element:this.path,item:e.item,blob:e.blob.hash,endedAt:Date.now(),reason:"error"}),this.schedule(Ar);return}if(this.stopped)return;if(this.shownAt=Date.now(),this.open=e,this.o.onItem?.({type:"item.start",element:this.path,item:e.item,blob:e.blob.hash,contentType:e.blob.contentType,startedAt:this.shownAt,durationMs:e.durationMs}),e.pages&&(this.pages=new ie(this.renderer,e,this.shownAt,!1)),!(this.slides.length===1&&e.loop))this.schedule(e.durationMs+(e.untilEnd?5e3:0));else{let s=this.bounds(e).flatMap(r=>r?.until??[]);s.length&&this.schedule(Math.min(...s)-this.shownAt)}let n=this.peek();n&&n!==e&&this.renderer.prepare(n).catch(()=>{})}peek(){let e=this.seek(this.at+1);if(e<this.order.length)return this.slides[this.order[e]];if(this.o.endsWith!==this.path)return this.playback.onEnd==="hold"||this.playback.onEnd==="hide"||this.playback.order==="shuffle"?void 0:this.slides[this.order[0]]}schedule(e){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.next("completed")},bn(e))}async next(e){if(this.stopped||this.ended||!this.current)return;let n=()=>this.endOpen(e),s=this.seek(this.at+1);if(s<this.order.length){this.at=s,n(),await this.show();return}let o=this.o.onPassEnd?.(this.path)==="hold"?"hold":this.playback.onEnd??"loop";if(o==="hold"){this.ended=!0;return}if(o==="hide"){this.ended=!0,n(),this.renderer.standby(),this.region.style.visibility="hidden";return}this.pass++,await this.newPass(),n(),await this.first()}pause(){clearTimeout(this.timer),this.current&&this.remaining===void 0&&(this.remaining=Math.max(0,this.current.durationMs-(Date.now()-this.shownAt))),this.pages?.pause(),this.renderer.pause()}resume(){if(this.empty&&!this.ended&&!this.stopped){this.first();return}this.remaining===void 0||this.ended||(this.renderer.resume(),this.pages?.resume(),this.shownAt=Date.now()-(this.current.durationMs-this.remaining),this.schedule(this.remaining),this.remaining=void 0)}endOpen(e){this.pages?.stop(),this.pages=void 0;let n=this.open;n&&(this.open=void 0,this.o.onItem?.({type:"item.end",element:this.path,item:n.item,blob:n.blob.hash,endedAt:Date.now(),reason:e}))}stop(){this.endOpen("stopped"),this.stopped=!0,clearTimeout(this.timer),this.renderer.standby();for(let e of this.slides)this.renderer.release(e)}};var rt=t=>t!=null&&t!==""&&!(Array.isArray(t)&&t.length===0);function kn(t,e,n,s=[]){let r=t[n];if(!r)return!1;if(!r.when)return!0;if(s.includes(n))return!1;let o=i=>String(i);for(let[i,a]of Object.entries(r.when)){if(!t[i]||i===n)return!1;let l=kn(t,e,i,[...s,n])?e[i]!==void 0?e[i]:t[i].default:void 0,c=Array.isArray(l)?l.map(o):rt(l)?[o(l)]:[];if(a.set!==void 0&&a.set!==rt(l)||a.anyOf&&!(rt(l)&&!Array.isArray(l)?a.anyOf.map(o).includes(o(l)):c.some(d=>a.anyOf.map(o).includes(d)))||a.allOf&&!a.allOf.map(o).every(d=>c.includes(d))||a.noneOf&&c.some(d=>a.noneOf.map(o).includes(d)))return!1}return!0}function xn(t,e){return Object.keys(t).filter(n=>kn(t,e,n))}var ka=oe.apiVersion,Mn=new Map(oe.commands.map(t=>[t.name,t]));var K=class extends Error{constructor(n,s){super(s);h(this,"code",n)}};function An(t,e){let n=e.capability??"read",s={kind:"app",app:e.id,instance:e.instance},r=new Set,o=!1,i=async(a,p={})=>{if(o)throw new K("NOT_ALLOWED","This app has been removed from the screen.");let l=Mn.get(a);if(!l)throw new K("UNKNOWN",`There is no command ${a}.`);if(l.apps==="none")throw new K("NOT_ALLOWED",`Apps cannot call ${a}.`);if(l.apps==="control"&&n!=="control")throw new K("NOT_ALLOWED",`${a} needs capabilities.player: control in ${e.id}'s definition.`);let c=await t.call(a,p,s);if(c.ok)return c.result;if(c.code==="PREVIEW")return{applied:!1,reason:"preview"};throw new K(c.code,c.message)};return{app:e.id,instance:e.instance,capability:n,status:()=>t.status(),get:a=>t.status()[a],on(a,p){if(o)return()=>{};let l=t.on(a,p),c=()=>{l(),r.delete(c)};return r.add(c),c},time:()=>i("time.now"),call:i,play:()=>i("player.play"),pause:()=>i("player.pause"),stop:()=>i("player.stop"),next:()=>i("player.next"),previous:()=>i("player.previous"),finish:()=>i("app.finish"),dispose(){o=!0;for(let a of[...r])a()}}}var it={"Intl.DateTimeFormat":"date formatters (Intl.DateTimeFormat)","Intl.NumberFormat":"number formatters (Intl.NumberFormat)","Intl.Collator":"collators (Intl.Collator)","Intl.PluralRules":"plural rules (Intl.PluralRules)","Intl.RelativeTimeFormat":"relative time formatters (Intl.RelativeTimeFormat)","Intl.ListFormat":"list formatters (Intl.ListFormat)","Intl.DisplayNames":"display names (Intl.DisplayNames)","Intl.Segmenter":"segmenters (Intl.Segmenter)",toLocale:"formatters, through toLocaleString, toLocaleDateString or toLocaleTimeString with options",canvas:"canvases",context:"canvas contexts",bitmap:"image bitmaps (createImageBitmap)",objectUrl:"object URLs (URL.createObjectURL)",worker:"workers",listener:"listeners on window or document"};function En(t){let e=0,n=s=>{for(let r=s.firstChild;r;r=r.nextSibling){if(r.nodeType===1){e++;let o=r.shadowRoot;o&&n(o)}n(r)}};return n(t),e}function Sn(t,e){let n={},s=c=>{n[c]=(n[c]??0)+1},r=(c,d)=>new Proxy(c,{construct:(m,g,w)=>(s(d),Reflect.construct(m,g,w)),apply:(m,g,w)=>(s(d),Reflect.apply(m,g,w))}),o=t.Intl;for(let c of["DateTimeFormat","NumberFormat","Collator","PluralRules","RelativeTimeFormat","ListFormat","DisplayNames","Segmenter"]){let d=o[c];d&&(o[c]=r(d,`Intl.${c}`))}let i=(c,d,m)=>{let g=c&&c[d];typeof g=="function"&&(c[d]=function(...w){let f=Reflect.apply(g,this,w),b=m(w,this,f);return b&&s(b),f})},a=c=>c[1]!==void 0?"toLocale":null;for(let c of["toLocaleString","toLocaleDateString","toLocaleTimeString"])i(t.Date?.prototype,c,a);i(t.Number?.prototype,"toLocaleString",a),i(t.Document?.prototype,"createElement",c=>String(c[0]).toLowerCase()==="canvas"?"canvas":null),t.OffscreenCanvas&&(t.OffscreenCanvas=r(t.OffscreenCanvas,"canvas"));let p=new WeakSet,l=(c,d,m)=>!m||typeof m!="object"||p.has(m)?null:(p.add(m),"context");return i(t.HTMLCanvasElement?.prototype,"getContext",l),i(t.OffscreenCanvas?.prototype,"getContext",l),i(t,"createImageBitmap",()=>"bitmap"),i(t.URL,"createObjectURL",()=>"objectUrl"),t.Worker&&(t.Worker=r(t.Worker,"worker")),i(t.EventTarget?.prototype,"addEventListener",(c,d)=>d===void 0||d===t||d===t.document?"listener":null),()=>({kinds:{...n},nodes:e()})}var Tn=["none","fade","scale","slide-up","slide-left"],Te=[["1920 \xD7 1080",1920,1080],["1080 \xD7 1920",1080,1920],["3840 \xD7 2160",3840,2160]],Er=[.25,.5,1,2,4],ce=3e4,Rn=5e3,Sr={id:"med_preview",version:1},u={width:1920,height:1080,props:{},touched:new Set,playing:!0,speed:1,t:0,enter:"none",exit:"none",clipMs:800,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:navigator.language||"en-US",screen:{name:"Preview screen",lat:49.9,lon:-97.14,fields:"{}"},samples:{},tables:new Map,people:[]},T={frames:"",tables:{},controller:{status:{},events:{}}},_={people:new Set,player:new Map},Re=[],dt=new Map,S=null,lt=null,pt=null,Nn=-1,q=null,pe=0,G={wall:0,t:0},Pe=0,Le=[],D=t=>document.getElementById(t),ct=D("stage"),Tr=D("controls"),Pn=D("report"),ot=D("made"),Pr=Sn(window,()=>En(ct)),ut={kinds:{},nodes:0};addEventListener("message",t=>{let e=t.data;T.frames&&t.origin==="null"&&e?.wyndlassPreview==="made"&&e.made&&typeof e.made=="object"&&(ut=e.made)});var On=500,Ln=3,$={last:null,reads:[],said:""};function y(t,e={},...n){let s=document.createElement(t);for(let[r,o]of Object.entries(e))o==null||o===!1||(r.startsWith("on")&&typeof o=="function"?s.addEventListener(r.slice(2),o):r==="value"||r in s&&typeof o!="string"?s[r]=o:s.setAttribute(r,o===!0?"":String(o)));for(let r of n)r!=null&&s.append(r);return s}var Lr=0;function E(t,e,n=!1){return e.id||(e.id=`c${++Lr}`),n?y("div",{class:"field inline"},e,y("label",{for:e.id},t)):y("div",{class:"field"},y("label",{for:e.id},t),e)}function U(t,e,n){let s=y("select",{onchange:()=>n(s.value)},...t.map(r=>{let[o,i]=Array.isArray(r)?r:[r,r];return y("option",{value:o,selected:o===e},i)}));return s}async function In(){let[t,e,n,s]=await Promise.all([fetch("/app.json").then(i=>i.json()),fetch("/app.js"),fetch("/samples.json").then(i=>i.json()),fetch("/config.json").then(i=>i.json())]);T=s;for(let[i,a]of Object.entries(T.tables))u.tables.has(mt(i))||$n(i,a);S=t,Nn=Number(e.headers.get("x-preview-version")??-1),pt=e.ok?null:await e.text(),lt=e.ok?new Uint8Array(await e.arrayBuffer()):null;let r=S.params??{},o={};for(let[i,a]of Object.entries(r))o[i]=u.touched.has(i)?u.props[i]:a.default;u.props=o;for(let[i,a]of Object.entries(n))i in u.samples||(u.samples[i]=a);Dn(),document.title=`${S.name}: Wyndlass app preview`,D("title").textContent=S.name,D("subtitle").textContent=`${S.id} ${S.version}`}var mt=t=>`tbl_${(t.replace(/\.(json|csv)$/i,"").toLowerCase().replace(/[^a-z0-9]+/g,"")||"table").slice(0,26).padEnd(26,"0")}`;function Ir(t){let e=[],n=[],s="",r=!1;for(let o=0;o<t.length;o++){let i=t[o];if(r){i==='"'&&t[o+1]==='"'?(s+='"',o++):i==='"'?r=!1:s+=i;continue}i==='"'?r=!0:i===","?(n.push(s),s=""):i===`
|
|
4
|
+
${n}`))).slice(0,8),16),o=Br(r),i=Array.from({length:s},(a,d)=>d);for(let a=s-1;a>0;a--){let d=Math.floor(o()*(a+1));[i[a],i[d]]=[i[d],i[a]]}return i}var Ur=250,_r=1e3;function Yt(t,e){let n=t.animation?.duration;if(n?.kind==="fixed")return{durationMs:n.ms};if(n?.kind==="untilPlaylistEnds"){let s=$n(t.elements,n.element);return{durationMs:(s?.source?.kind==="playlist"?e.playlist(s.source.item)??[]:s?.source?[{item:s.source.item}]:[]).reduce((i,a)=>i+(e.slide(a,{imageDurationMs:s?.playback?.imageDurationMs})?.durationMs??0),0)||1e4,untilPass:n.element}}return{durationMs:ue(t.animation?.clips??[]).autoDurationMs}}function On(t,e,n=0){let s={},r=o=>{for(let i of o){if(i.type==="library"&&i.source){let a=i.source.kind==="playlist"?e.playlist(i.source.item)??[]:[{item:i.source.item}];s[i.source.item.id]={video:a.some(d=>{let p=e.slide(d);if(!p)return!1;if(p.blob.contentType.startsWith("video/"))return!0;let c=p.layout;return!!c&&n<4&&Object.values(On(c.doc,c.source,n+1)).some(l=>l.video)})}}i.children&&r(i.children)}};return r(t.elements),s}function $n(t,e){for(let n of t){if(n.id===e)return n;let s=n.children&&$n(n.children,e);if(s)return s}}var G=class{constructor(e,n,s,r={}){h(this,"source",n);h(this,"o",r);h(this,"el");h(this,"ready");h(this,"unplayed");h(this,"doc");h(this,"motions");h(this,"native");h(this,"animated",[]);h(this,"loops",[]);h(this,"startedAt",0);h(this,"frame",0);h(this,"running",!1);h(this,"disposed",!1);h(this,"apps",[]);h(this,"heldAt");h(this,"late",[]);h(this,"overran",[]);h(this,"timers",[]);h(this,"bound",[]);h(this,"unheard");h(this,"reduced",typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches);let o=s.clientWidth||window.innerWidth,i=s.clientHeight||window.innerHeight,a=!e.profiles[0].width,d=a?{...e.profiles[0],width:o,height:i}:e.profiles[0];a&&(e={...e,elements:e.elements.map(v=>v.frame.w?v:{...v,frame:{x:0,y:0,w:o,h:i}})});let p=Math.min(o/d.width,i/d.height);this.el=H("div"),this.el.dataset.layout=d.id,this.el.style.cssText=`position:absolute;left:${(o-d.width*p)/2}px;top:${(i-d.height*p)/2}px;width:${d.width}px;height:${d.height}px;transform:scale(${p});transform-origin:0 0;overflow:hidden`,s.append(this.el),this.doc=e;let c=new Map,l=v=>{for(let A of v)c.set(A.id,A.frame),A.children&&l(A.children)};l(e.elements);let m=Pn(e.animation?.clips??[],c);this.motions=m.motions;let g=new Set(m.unplayed.map(v=>`preset ${v}`)),w=[this.loadFonts()],f=r.media?xn(e,void 0,On(e,n),r.media.capability):[];this.native=new Set(f.filter(v=>v.path.path==="native").map(v=>v.element));let b=(v,A)=>{for(let k of v){if(k.hidden)continue;let I=this.element(k,g,w);A.append(I),k.children?.length&&k.type==="shape"&&b(k.children,I)}};b(e.elements,this.el),e.background&&yn(this.el,e.background,d,f.filter(v=>this.native.has(v.element)).map(v=>v.box)),this.unplayed=[...g].sort(),this.ready=Promise.all(w).then(()=>{}),this.bound.length&&(this.unheard=n.onSnapshots?.(()=>this.refill()))}refill(){let e=ce(this.source),n=(this.heldAt??Date.now())-this.startedAt;for(let{el:s,e:r}of this.bound){let o=ut(r,e),i=this.animated.find(a=>a.el===s);i?(i.text=o,this.running||this.place(i,n)):s.textContent!==o&&(s.textContent=o)}}path(e){return this.o.path?`${this.o.path}/${e}`:e}element(e,n,s){let r=bn(e);wn(r,e,this.source),e.type==="text"&&(e.bind||Ie(e.text??""))&&this.bound.push({el:r,e});let o=this.motions.get(e.id);if(o){let i={el:r,e,motion:o,text:e.type==="text"?r.textContent??"":void 0};this.animated.push(i),this.place(i,0)}if(e.type==="library"&&e.source){let i=e.source.kind==="playlist"?this.source.playlist(e.source.item)??[]:[{item:e.source.item}],a=new mt(r,i,e.playback??{},this.source,this.path(e.id),{...this.o,media:this.native.has(e.id)?this.o.media:void 0},e.source.kind==="playlist"?e.source.item:void 0);this.loops.push(a),s.push(a.ready);for(let d of a.unplayed)n.add(d)}else if(e.type==="app"){let i=e.app?this.source.app?.(e.app):null;i?s.push(this.mountApp(e,r,i)):n.add(`app ${e.app?.id??e.id}`)}return r}place(e,n){Cn(e.el,e.e,Ln(e.motion,e.e.frame,n,this.reduced),e.text);let s=e.e.type==="text"?e.el.firstElementChild:null;s&&Ge(s)}loadFonts(){return kn(this.doc.fonts??[],e=>this.source.font(e))}async mountApp(e,n,s){let r=this.path(e.id),o=e.app,i=(e.appInfo??s.info)?.id,a={now:()=>this.heldAt??Date.now(),startedAt:()=>this.startedAt||Date.now()},d=(l,m)=>this.o.onApp?.({type:"app.failed",element:r,item:o,...i?{app:i}:{},reason:l,...m?{error:m}:{}}),p=this.o.isolate?{...this.o.isolate,fonts:this.doc.fonts,font:l=>this.source.font(l)}:void 0,c=await vn(e,n,s,this.source,a,this.o.appDeadlineMs??5e3,l=>{this.disposed?l.dispose():this.apps.push({app:l,box:n,path:r,id:e.id,item:o})},l=>d("error",l),p);if(!("held"in c)){if("failed"in c){d(c.failed,c.error);return}c.late&&(this.late.push(r),this.o.onAppLate?.(r,o.id),d("late"))}}async start(e=Date.now()){this.startedAt=e,this.heldAt=void 0,this.running=!0,this.hooks(e);let n=()=>{if(!this.running)return;let s=Date.now(),r=s-this.startedAt;for(let o of this.animated)this.place(o,r);for(let o of this.apps)o.app.update(s);this.frame=requestAnimationFrame(n)};(this.animated.length||this.apps.length)&&(this.frame=requestAnimationFrame(n)),await Promise.all(this.loops.map(s=>s.start()))}hooks(e){let n=this.doc.animation?.clips??[],s=ue(n).clips,r=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches;for(let o of this.apps){let a=n.map((f,b)=>({c:f,t:s[b]})).filter(f=>f.c.element===o.id&&(f.c.kind==="enter"||f.c.kind==="exit")).filter(f=>o.app.has(f.c.kind));if(!a.length)continue;let d=o.box,p=this.animated.findIndex(f=>f.el===d);p>=0&&(this.animated.splice(p,1),Object.assign(d.style,{opacity:"",transform:"",clipPath:""}));let c=(f,b,v)=>this.hook(o,f.kind,{startAt:b,preset:f.preset??"fade",durationMs:f.durationMs,easing:f.easing,delayMs:0,...f.staggerMs?{staggerMs:f.staggerMs}:{},...v!==void 0?{page:v}:{},reducedMotion:r},d);for(let{c:f,t:b}of a)c(f,e+b.startMs);let l=o.app.paging();if(!l)continue;let m=a.find(f=>f.c.kind==="enter")?.c,g=a.find(f=>f.c.kind==="exit")?.c,w=In(l.count,l.ms,Yt(this.doc,this.source).durationMs);for(let f=1;f<w.length;f++){let b=e+w[f].startMs;g&&c(g,b-g.durationMs,w[f-1].page),m&&c(m,b,w[f].page)}}}hook(e,n,s,r){let o=!1;e.app.hook(n,s).finally(()=>{o=!0});let i=s.startAt+s.durationMs;this.timers.push(setTimeout(()=>{o||!this.running||(this.overran.includes(e.path)||(this.overran.push(e.path),this.o.onAppOverran?.(e.path,e.item.id),this.o.onApp?.({type:"app.failed",element:e.path,item:e.item,reason:"overran"})),n==="exit"&&(r.style.visibility="hidden"))},Math.max(0,i+Ur-Date.now())))}pause(){this.heldAt=Date.now();for(let e of this.loops)e.pause();for(let e of this.apps)e.app.update(this.heldAt)}seek(e){this.running=!1,cancelAnimationFrame(this.frame);for(let n of this.loops)n.pause();for(let n of this.animated)this.place(n,e);this.heldAt=this.startedAt+e;for(let n of this.apps)n.app.update(this.heldAt)}resume(){this.heldAt=void 0;for(let e of this.loops)e.resume()}paging(e){return this.apps.find(n=>n.id===e)?.app.paging()??null}dispose(){this.running=!1,this.disposed=!0,cancelAnimationFrame(this.frame);for(let e of this.timers)clearTimeout(e);for(let e of this.loops)e.stop();for(let e of this.apps)e.app.dispose();this.unheard?.(),this.el.remove()}},Nn=t=>Math.min(Math.max(0,t),2**31-1),mt=class{constructor(e,n,s,r,o,i,a){h(this,"region",e);h(this,"playback",s);h(this,"source",r);h(this,"path",o);h(this,"o",i);h(this,"list",a);h(this,"ready");h(this,"unplayed",[]);h(this,"renderer");h(this,"slides");h(this,"order",[]);h(this,"pass",0);h(this,"at",0);h(this,"timer");h(this,"current");h(this,"shownAt",0);h(this,"remaining");h(this,"stopped",!1);h(this,"ended",!1);h(this,"empty",!1);h(this,"open");h(this,"pages");this.renderer=new Re(e,{media:i.media,fit:s.fit,path:o,onItem:i.onItem,onPassEnd:i.onPassEnd,onApp:i.onApp}),s.transition==="slide"&&this.unplayed.push("transition slide");let d=s.transition==="fade"?{type:"crossfade"}:void 0,p=n.map(c=>r.slide(c,{imageDurationMs:s.imageDurationMs,transition:d,region:!0})).filter(c=>!!c);this.slides=p.length===1&&p[0].untilEnd&&(s.onEnd??"loop")==="loop"?[{...p[0],untilEnd:!1,loop:!0}]:p,this.renderer.onMediaEnd(c=>{c===this.current&&!this.stopped&&(clearTimeout(this.timer),this.next("completed"))}),this.ready=this.newPass().then(()=>this.slides.length?this.renderer.prepare(this.slides[this.order[0]]):void 0).catch(()=>{})}async newPass(){let e=this.slides.length;this.order=this.playback.order==="shuffle"?await Rn(this.source.deviceId,this.path,this.pass,e):[...Array(e).keys()],this.at=0}async start(){this.slides.length&&await this.first()}bounds(e){return[this.source.bounds?.(e.item),this.list&&this.source.bounds?.(this.list)]}seek(e){let n=Date.now(),s=e;for(;s<this.order.length&&!this.bounds(this.slides[this.order[s]]).every(r=>Kt(r,n));)s++;return s}async first(){if(this.at=this.seek(0),this.at<this.order.length){this.empty=!1,await this.show();return}this.empty=!0,this.current=void 0,this.renderer.standby();let e=Date.now(),n=this.slides.flatMap(s=>this.bounds(s).map(r=>r?.from??0)).filter(s=>s>e);clearTimeout(this.timer),n.length&&(this.timer=setTimeout(()=>{!this.stopped&&!this.ended&&this.first()},Nn(Math.min(...n)-e)))}async show(){let e=this.slides[this.order[this.at]];this.current=e;try{await this.renderer.show(e)}catch(s){if(this.stopped)return;this.o.onItem?.({type:"item.error",element:this.path,item:e.item,blob:e.blob.hash,...at(s)}),this.o.onItem?.({type:"item.end",element:this.path,item:e.item,blob:e.blob.hash,endedAt:Date.now(),reason:"error"}),this.schedule(_r);return}if(this.stopped)return;if(this.shownAt=Date.now(),this.open=e,this.o.onItem?.({type:"item.start",element:this.path,item:e.item,blob:e.blob.hash,contentType:e.blob.contentType,startedAt:this.shownAt,durationMs:e.durationMs}),e.pages&&(this.pages=new le(this.renderer,e,this.shownAt,!1)),!(this.slides.length===1&&e.loop))this.schedule(e.durationMs+(e.untilEnd?5e3:0));else{let s=this.bounds(e).flatMap(r=>r?.until??[]);s.length&&this.schedule(Math.min(...s)-this.shownAt)}let n=this.peek();n&&n!==e&&this.renderer.prepare(n).catch(()=>{})}peek(){let e=this.seek(this.at+1);if(e<this.order.length)return this.slides[this.order[e]];if(this.o.endsWith!==this.path)return this.playback.onEnd==="hold"||this.playback.onEnd==="hide"||this.playback.order==="shuffle"?void 0:this.slides[this.order[0]]}schedule(e){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.next("completed")},Nn(e))}async next(e){if(this.stopped||this.ended||!this.current)return;let n=()=>this.endOpen(e),s=this.seek(this.at+1);if(s<this.order.length){this.at=s,n(),await this.show();return}let o=this.o.onPassEnd?.(this.path)==="hold"?"hold":this.playback.onEnd??"loop";if(o==="hold"){this.ended=!0;return}if(o==="hide"){this.ended=!0,n(),this.renderer.standby(),this.region.style.visibility="hidden";return}this.pass++,await this.newPass(),n(),await this.first()}pause(){clearTimeout(this.timer),this.current&&this.remaining===void 0&&(this.remaining=Math.max(0,this.current.durationMs-(Date.now()-this.shownAt))),this.pages?.pause(),this.renderer.pause()}resume(){if(this.empty&&!this.ended&&!this.stopped){this.first();return}this.remaining===void 0||this.ended||(this.renderer.resume(),this.pages?.resume(),this.shownAt=Date.now()-(this.current.durationMs-this.remaining),this.schedule(this.remaining),this.remaining=void 0)}endOpen(e){this.pages?.stop(),this.pages=void 0;let n=this.open;n&&(this.open=void 0,this.o.onItem?.({type:"item.end",element:this.path,item:n.item,blob:n.blob.hash,endedAt:Date.now(),reason:e}))}stop(){this.endOpen("stopped"),this.stopped=!0,clearTimeout(this.timer),this.renderer.standby();for(let e of this.slides)this.renderer.release(e)}};var ft=t=>t!=null&&t!==""&&!(Array.isArray(t)&&t.length===0);function Dn(t,e,n,s=[]){let r=t[n];if(!r)return!1;if(!r.when)return!0;if(s.includes(n))return!1;let o=i=>String(i);for(let[i,a]of Object.entries(r.when)){if(!t[i]||i===n)return!1;let p=Dn(t,e,i,[...s,n])?e[i]!==void 0?e[i]:t[i].default:void 0,c=Array.isArray(p)?p.map(o):ft(p)?[o(p)]:[];if(a.set!==void 0&&a.set!==ft(p)||a.anyOf&&!(ft(p)&&!Array.isArray(p)?a.anyOf.map(o).includes(o(p)):c.some(l=>a.anyOf.map(o).includes(l)))||a.allOf&&!a.allOf.map(o).every(l=>c.includes(l))||a.noneOf&&c.some(l=>a.noneOf.map(o).includes(l)))return!1}return!0}function jn(t,e){return Object.keys(t).filter(n=>Dn(t,e,n))}var za=de.apiVersion,Fn=new Map(de.commands.map(t=>[t.name,t]));var J=class extends Error{constructor(n,s){super(s);h(this,"code",n)}};function Hn(t,e){let n=e.capability??"read",s={kind:"app",app:e.id,instance:e.instance},r=new Set,o=!1,i=async(a,d={})=>{if(o)throw new J("NOT_ALLOWED","This app has been removed from the screen.");let p=Fn.get(a);if(!p)throw new J("UNKNOWN",`There is no command ${a}.`);if(p.apps==="none")throw new J("NOT_ALLOWED",`Apps cannot call ${a}.`);if(p.apps==="control"&&n!=="control")throw new J("NOT_ALLOWED",`${a} needs capabilities.player: control in ${e.id}'s definition.`);let c=await t.call(a,d,s);if(c.ok)return c.result;if(c.code==="PREVIEW")return{applied:!1,reason:"preview"};throw new J(c.code,c.message)};return{app:e.id,instance:e.instance,capability:n,status:()=>t.status(),get:a=>t.status()[a],on(a,d){if(o)return()=>{};let p=t.on(a,d),c=()=>{p(),r.delete(c)};return r.add(c),c},time:()=>i("time.now"),call:i,play:()=>i("player.play"),pause:()=>i("player.pause"),stop:()=>i("player.stop"),next:()=>i("player.next"),previous:()=>i("player.previous"),finish:()=>i("app.finish"),dispose(){o=!0;for(let a of[...r])a()}}}var gt={"Intl.DateTimeFormat":"date formatters (Intl.DateTimeFormat)","Intl.NumberFormat":"number formatters (Intl.NumberFormat)","Intl.Collator":"collators (Intl.Collator)","Intl.PluralRules":"plural rules (Intl.PluralRules)","Intl.RelativeTimeFormat":"relative time formatters (Intl.RelativeTimeFormat)","Intl.ListFormat":"list formatters (Intl.ListFormat)","Intl.DisplayNames":"display names (Intl.DisplayNames)","Intl.Segmenter":"segmenters (Intl.Segmenter)",toLocale:"formatters, through toLocaleString, toLocaleDateString or toLocaleTimeString with options",canvas:"canvases",context:"canvas contexts",bitmap:"image bitmaps (createImageBitmap)",objectUrl:"object URLs (URL.createObjectURL)",worker:"workers",listener:"listeners on window or document"};function Bn(t){let e=0,n=s=>{for(let r=s.firstChild;r;r=r.nextSibling){if(r.nodeType===1){e++;let o=r.shadowRoot;o&&n(o)}n(r)}};return n(t),e}function Un(t,e){let n={},s=c=>{n[c]=(n[c]??0)+1},r=(c,l)=>new Proxy(c,{construct:(m,g,w)=>(s(l),Reflect.construct(m,g,w)),apply:(m,g,w)=>(s(l),Reflect.apply(m,g,w))}),o=t.Intl;for(let c of["DateTimeFormat","NumberFormat","Collator","PluralRules","RelativeTimeFormat","ListFormat","DisplayNames","Segmenter"]){let l=o[c];l&&(o[c]=r(l,`Intl.${c}`))}let i=(c,l,m)=>{let g=c&&c[l];typeof g=="function"&&(c[l]=function(...w){let f=Reflect.apply(g,this,w),b=m(w,this,f);return b&&s(b),f})},a=c=>c[1]!==void 0?"toLocale":null;for(let c of["toLocaleString","toLocaleDateString","toLocaleTimeString"])i(t.Date?.prototype,c,a);i(t.Number?.prototype,"toLocaleString",a),i(t.Document?.prototype,"createElement",c=>String(c[0]).toLowerCase()==="canvas"?"canvas":null),t.OffscreenCanvas&&(t.OffscreenCanvas=r(t.OffscreenCanvas,"canvas"));let d=new WeakSet,p=(c,l,m)=>!m||typeof m!="object"||d.has(m)?null:(d.add(m),"context");return i(t.HTMLCanvasElement?.prototype,"getContext",p),i(t.OffscreenCanvas?.prototype,"getContext",p),i(t,"createImageBitmap",()=>"bitmap"),i(t.URL,"createObjectURL",()=>"objectUrl"),t.Worker&&(t.Worker=r(t.Worker,"worker")),i(t.EventTarget?.prototype,"addEventListener",(c,l)=>l===void 0||l===t||l===t.document?"listener":null),()=>({kinds:{...n},nodes:e()})}var _n=["none","fade","scale","slide-up","slide-left"],De=[["1920 \xD7 1080",1920,1080],["1080 \xD7 1920",1080,1920],["3840 \xD7 2160",3840,2160]],qr=[.25,.5,1,2,4],fe=3e4,Kn=5e3,Wr={id:"med_preview",version:1},u={width:1920,height:1080,props:{},touched:new Set,playing:!0,speed:1,t:0,enter:"none",exit:"none",clipMs:800,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:navigator.language||"en-US",screen:{name:"Preview screen",lat:49.9,lon:-97.14,fields:"{}"},samples:{},tables:new Map,people:[]},L={frames:"",tables:{},controller:{status:{},events:{}}},z={people:new Set,player:new Map},Be=[],ge=new Map,wt=new Map,vt=new Set,je=0,E=null,kt=null,xt=null,Zn=-1,W=null,me=0,ee={wall:0,t:0},Fe=0,He=[],j=t=>document.getElementById(t),Mt=j("stage"),zr=j("controls"),qn=j("report"),yt=j("made"),Vr=Un(window,()=>Bn(Mt)),At={kinds:{},nodes:0};addEventListener("message",t=>{let e=t.data;L.frames&&t.origin==="null"&&e?.wyndlassPreview==="made"&&e.made&&typeof e.made=="object"&&(At=e.made)});var Jn=500,Wn=3,D={last:null,reads:[],said:""};function y(t,e={},...n){let s=document.createElement(t);for(let[r,o]of Object.entries(e))o==null||o===!1||(r.startsWith("on")&&typeof o=="function"?s.addEventListener(r.slice(2),o):r==="value"||r in s&&typeof o!="string"?s[r]=o:s.setAttribute(r,o===!0?"":String(o)));for(let r of n)r!=null&&s.append(r);return s}var Kr=0;function S(t,e,n=!1){return e.id||(e.id=`c${++Kr}`),n?y("div",{class:"field inline"},e,y("label",{for:e.id},t)):y("div",{class:"field"},y("label",{for:e.id},t),e)}function q(t,e,n){let s=y("select",{onchange:()=>n(s.value)},...t.map(r=>{let[o,i]=Array.isArray(r)?r:[r,r];return y("option",{value:o,selected:o===e},i)}));return s}async function zn(){let[t,e,n,s]=await Promise.all([fetch("/app.json").then(i=>i.json()),fetch("/app.js"),fetch("/samples.json").then(i=>i.json()),fetch("/config.json").then(i=>i.json())]);L=s;for(let[i,a]of Object.entries(L.tables))u.tables.has(Ue(i))||St(i,a);E=t,Zn=Number(e.headers.get("x-preview-version")??-1),xt=e.ok?null:await e.text(),kt=e.ok?new Uint8Array(await e.arrayBuffer()):null;let r=E.params??{},o={};for(let[i,a]of Object.entries(r))o[i]=u.touched.has(i)?u.props[i]:a.default;u.props=o;for(let[i,a]of Object.entries(n))i in u.samples||(u.samples[i]=a);Et(),document.title=`${E.name}: Wyndlass app preview`,j("title").textContent=E.name,j("subtitle").textContent=`${E.id} ${E.version}`}var Ue=t=>`tbl_${(t.replace(/\.(json|csv)$/i,"").toLowerCase().replace(/[^a-z0-9]+/g,"")||"table").slice(0,26).padEnd(26,"0")}`;function Zr(t){let e=[],n=[],s="",r=!1;for(let o=0;o<t.length;o++){let i=t[o];if(r){i==='"'&&t[o+1]==='"'?(s+='"',o++):i==='"'?r=!1:s+=i;continue}i==='"'?r=!0:i===","?(n.push(s),s=""):i===`
|
|
5
5
|
`||i==="\r"?(i==="\r"&&t[o+1]===`
|
|
6
|
-
`&&o++,n.push(s),e.push(n),n=[],s=""):s+=i}return(s||n.length)&&(n.push(s),e.push(n)),e.filter(o=>o.some(i=>i!==""))}function
|
|
7
|
-
${
|
|
6
|
+
`&&o++,n.push(s),e.push(n),n=[],s=""):s+=i}return(s||n.length)&&(n.push(s),e.push(n)),e.filter(o=>o.some(i=>i!==""))}function Jr(t,e){let n="";for(let r of t.normalize("NFD").replace(/\p{Mn}/gu,""))/[A-Za-z0-9]/.test(r)?n+=r.toLowerCase():n&&!n.endsWith("_")&&(n+="_");n=n.replace(/^_+|_+$/g,""),/^[a-z]/.test(n)||(n=`c_${n}`),n=n.length>60?n.slice(0,60).replace(/_+$/,""):n;let s=n;for(let r=2;[...e].some(o=>o.toLowerCase()===s);r++)s=`${n}_${r}`;return e.add(s),s}function Yn(t,e){let n=Ue(t),s=(o,i)=>({table:n,version:1,rows:i,columns:o.map(({key:a,label:d})=>({key:a,label:d,type:i.length&&i.every(p=>p[a]===""||p[a]===void 0||Number.isFinite(Number(p[a])))?"number":"text"}))});if(/\.csv$/i.test(t)){let[o=[],...i]=Zr(e),a=new Set,d=o.map(l=>({label:l.trim(),key:Jr(l.trim()||"column",a)})),p=i.map(l=>Object.fromEntries(d.map((m,g)=>[m.key,l[g]??""]))),c=s(d,p);for(let l of c.columns)if(l.type==="number")for(let m of p)m[l.key]!==""&&(m[l.key]=Number(m[l.key]));return c}let r=JSON.parse(e);if(r&&typeof r=="object"&&"columns"in r&&"rows"in r)return{...r,table:n};if(Array.isArray(r))return s([...new Set(r.flatMap(o=>Object.keys(o)))].map(o=>({key:o,label:o})),r);throw new Error(`${t} is not a table: a snapshot, an array of rows, or CSV`)}function St(t,e){wt.set(t,e);try{u.tables.set(Ue(t),Ce(Yn(t,e))),ge.delete(t)}catch(n){ge.set(t,String(n.message))}}function Xn(t,e,n){let s=u.tables.get(t);if(!s)return;u.tables.set(t,Ce({...s,version:s.version+1,rows:e,...n?{columns:n}:{}}));for(let i of[...vt])i([t]);let r=document.querySelector(`[data-testid="table"][data-table="${t}"]`);r&&(r.textContent=es(u.tables.get(t)));let o=document.querySelector(`textarea[data-rows="${t}"]`);o&&document.activeElement!==o&&(o.value=JSON.stringify(e,null,2))}async function Yr(){let t=await fetch("/config.json").then(n=>n.json()),e=!1;for(let[n,s]of Object.entries(t.tables)){if(wt.get(n)===s)continue;let r=Ue(n);if(!u.tables.has(r)){St(n,s),e=!0;continue}wt.set(n,s);try{let o=Yn(n,s);ge.delete(n),Xn(r,o.rows,o.columns)}catch(o){ge.set(n,String(o.message)),te()}}e&&(Et(),te(),await ye())}function Et(){let t=[...u.tables.keys()][0];if(!(!t||!E))for(let[e,n]of Object.entries(E.params??{}))n.type==="datatable"&&!u.props[e]&&(u.props[e]=t,u.touched.add(e))}function Xr(){return{measuring:!0,now:()=>[{source:"preview",present:u.people.length,longestDwellS:u.people.length?Math.round((Date.now()-Math.min(...u.people))/1e3):0}],on(t){return z.people.add(t),()=>{z.people.delete(t)}}}}function bt(t){if(t==="enter"&&u.people.push(Date.now()),t==="leave"&&!u.people.length)return;let e=t==="leave"?u.people.shift():0,n=t==="leave"?{type:"leave",source:"preview",dwellS:Math.round((Date.now()-e)/1e3)}:{type:t,source:"preview"};for(let s of z.people)s([n]);j("people-count").textContent=`${u.people.length} in view`}var Gr={status:()=>L.controller.status,on(t,e){let n=z.player.get(t)??new Set;return n.add(e),z.player.set(t,n),()=>{n.delete(e)}},async call(t,e,n){return Be.push(`controller: ${n.app??"the app"} called ${t}, not applied (a preview)`),Q({}),{ok:!1,code:"PREVIEW",message:"a preview"}}},Qr={time:"time.now",play:"player.play",pause:"player.pause",stop:"player.stop",next:"player.next",previous:"player.previous",finish:"app.finish"};function ei(t){let e=s=>r=>{throw Be.push(`controller: ${s} refused, ${r.code??"error"}: ${r.message}`),Q({}),r},n={...t,call:(s,r)=>t.call(s,r).catch(e(s))};for(let[s,r]of Object.entries(Qr))n[s]=()=>t[s]().catch(e(r));return n}function ti(t){for(let e of[t.type,"*"])for(let n of z.player.get(e)??[])n(t)}function ni(){return new Oe({base:()=>location.origin,token:()=>{},fetch:(async t=>{let e=new URL(String(t),location.origin);if(e.pathname.endsWith("/v0/image"))return fetch("/picture.svg");let n=decodeURIComponent(e.pathname.split("/").pop()??"");if(!(n in u.samples))return new Response(`the preview has no answer for ${n}: declare it in app.json's data`,{status:404});let s=Date.now();return new Response(JSON.stringify({source:n,params:Object.fromEntries(e.searchParams),fetchedAt:new Date(s).toISOString(),expiresAt:new Date(s+36e5).toISOString(),stale:!1,data:u.samples[n]}))})})}function si(){let t=[...u.enter!=="none"?[{element:"app",kind:"enter",preset:u.enter,start:{kind:"at",ms:0},durationMs:u.clipMs,easing:"ease-out"}]:[],...u.exit!=="none"?[{element:"app",kind:"exit",preset:u.exit,start:{kind:"at",ms:fe-u.clipMs},durationMs:u.clipMs,easing:"ease-in"}]:[]];return{profiles:[{id:"preview",width:u.width,height:u.height}],elements:[{type:"app",id:"app",frame:{x:0,y:0,w:u.width,h:u.height},app:Wr,props:u.props,...E.slots&&u.tables.size?{binding:{table:[...u.tables.keys()][0]}}:{},...E.capabilities?.sensors?{sensors:E.capabilities.sensors}:{},appInfo:{id:E.id,element:E.element,player:E.capabilities?.player==="control"?"control":"read"}}],animation:{duration:{kind:"fixed",ms:fe},clips:t}}}async function ye(){let t=++me;if(cancelAnimationFrame(Fe),W?.dispose(),W=null,Mt.replaceChildren(),He.length=0,Be.length=0,D.last=null,D.reads=[],At={kinds:{},nodes:0},!E||!kt){Q({building:!0});return}let e={};try{e=JSON.parse(u.screen.fields||"{}")}catch{}let n=kt,s={deviceId:"preview",slide:()=>null,playlist:()=>null,font:()=>{},app:()=>({hash:`preview-${me}`,bytes:n}),data:ni(),place:{lat:u.screen.lat,lon:u.screen.lon},screen:{name:u.screen.name,type:"preview",tags:[],path:[{name:"Preview",kind:"organization"}],fields:e},timeZone:u.timeZone,locale:u.locale,preview:!1,snapshot:a=>u.tables.get(a)??null,onSnapshots:a=>(vt.add(a),()=>{vt.delete(a)}),...L.frames?{}:{...E.capabilities?.sensors?.includes("impressions")?{impressions:Xr()}:{},controllerFor:a=>ei(Hn(Gr,a))}};z.people.clear(),z.player.clear();let r=performance.now(),o=!1;je++;let i=new G(si(),s,Mt,{appDeadlineMs:Kn,...L.frames?{isolate:{frames:L.frames,apps:()=>!0}}:{},onAppLate:()=>{o=!0},onApp:a=>{t===me&&(He.push(`app.failed: ${a.reason}${a.error?` (${a.error})`:""}`),Q({}))}});W=i,Q({waiting:!0}),await i.ready,t===me&&(Q({readyMs:o?void 0:Math.round(performance.now()-r),late:o}),await i.start(Date.now()-u.t),t===me&&(i.seek(u.t),ee={wall:Date.now(),t:u.t},ri(),ii()))}function ri(){cancelAnimationFrame(Fe);let t=()=>{if(W){if(u.playing){if(u.t=ee.t+(Date.now()-ee.wall)*u.speed,u.t>=fe){u.t=0,ye();return}W.seek(u.t)}j("clock-seek").value=String(Math.round(u.t)),j("clock-time").textContent=`${(u.t/1e3).toFixed(1)} s`,Fe=requestAnimationFrame(t)}};Fe=requestAnimationFrame(t)}function ii(){let t=j("pages"),e=W?.paging("app")??null;t.replaceChildren(e&&e.count>1?y("div",{},y("p",{"data-testid":"pages"},`${e.count} pages of ${(e.ms/1e3).toFixed(1)} s`),y("div",{class:"row"},...Array.from({length:e.count},(n,s)=>y("button",{onclick:()=>Gn(s*e.ms)},`Page ${s+1}`)))):y("p",{"data-testid":"pages"},"One page"))}function Gn(t){u.t=Math.max(0,Math.min(fe-1,t)),ee={wall:Date.now(),t:u.t},W?.seek(u.t)}function Q(t){let e=[];if(xt?e.push(y("pre",{"data-testid":"build-error"},`The module does not build:
|
|
7
|
+
${xt}`)):t.building&&e.push(y("span",{},"Building\u2026")),t.waiting&&e.push(y("span",{"data-testid":"ready"},"Waiting for ready()\u2026")),t.late)e.push(y("span",{class:"late","data-testid":"ready"},`Late: not ready within ${Kn/1e3} s. A screen reports app.failed (late) and shows the app as it is.`));else if(t.readyMs!==void 0)e.push(y("span",{class:"ok","data-testid":"ready"},`Ready in ${t.readyMs} ms`));else if(!t.waiting&&!t.building){let n=qn.querySelector('[data-testid="ready"]');n&&e.push(n)}for(let n of He)e.push(y("span",{class:"failed","data-testid":"failure"},n));L.frames&&He.some(n=>/SecurityError/.test(n))&&e.push(y("span",{class:"warn","data-testid":"frame-why"},"In its frame, as in the CMS, an app has no storage, cookies or parent page: localStorage, sessionStorage, document.cookie and parent's document throw SecurityError. Keep nothing there that matters; a screen may lose it too."));for(let n of Be.slice(-5))e.push(y("span",{"data-testid":"command"},n));je&&e.push(y("span",{"data-testid":"made-times"},`Made ${je===1?"once":`${je} times`}: at each start of its layout, and when its code, params or screen change. A table's change reaches it as it plays.`)),qn.replaceChildren(...e)}function oi(){let t=L.frames?At:Vr();if(D.last&&u.playing&&W){let i={};for(let[a,d]of Object.entries(t.kinds)){let p=d-(D.last.kinds[a]??0);p>0&&(i[a]=p)}D.reads=[...D.reads,i].slice(-Wn)}D.last=t;let e=D.reads.length===Wn?Object.keys(gt).filter(i=>D.reads.every(a=>a[i])):[],n=i=>Math.round(D.reads.reduce((a,d)=>a+(d[i]??0),0)*1e3/(Jn*D.reads.length)),s=e.map(i=>[i,`Makes ${n(i)} ${gt[i]} a second while it plays. ${i==="listener"?"Add a listener once, in mount(), and take it off when the app goes":"Make it once, in mount() or with useMemo, never in draw() or a render"}: one made at every frame holds memory a screen frees late, and can run it out.`]),r=`${e.length?"":"Nothing made at every frame. "}${t.nodes} DOM nodes in the app.`,o=JSON.stringify(s);if(o===D.said&&yt.firstChild){yt.querySelector('[data-testid="made-counts"]').textContent=r;return}D.said=o,yt.replaceChildren(...s.map(([i,a])=>y("span",{class:"warn","data-testid":"made","data-kind":i},a)),y("span",{"data-testid":"made-counts"},r))}function ai(){let t=Object.entries(E?.params??{}).find(([,n])=>n.type==="datatable")?.[0],e=E?.slots?[...u.tables.keys()][0]:t?u.props[t]:void 0;return typeof e=="string"?u.tables.get(e):void 0}var Qn=t=>t.label&&t.label!==t.key?`${t.label} (${t.key})`:t.key,es=t=>`${t.table}: ${t.rows.length} rows, ${t.columns.map(Qn).join(", ")}`;function li(t,e){let n=u.props[t],s=o=>{u.props[t]=o,u.touched.add(t),ts(),R()},r=e.label??t;if(e.type==="boolean")return S(r,y("input",{type:"checkbox",checked:n===!0,onchange:o=>s(o.target.checked)}),!0);if(e.type==="enum"){let o=(e.values??[]).map(i=>i&&typeof i=="object"?[String(i.value),String(i.label??i.value)]:String(i));return S(r,q(o,String(n??""),s))}if(e.type==="number")return S(r,y("input",{type:"number",value:n===void 0?"":String(n),min:e.min,max:e.max,step:e.step??"any",onchange:o=>{let i=o.target.value;s(i===""?void 0:Number(i))}}));if(["string","text","color","url","datetime","duration","secret"].includes(e.type)){let o=e.type==="text"?y("textarea",{value:String(n??""),onchange:i=>s(i.target.value)}):y("input",{type:"text",value:String(n??""),placeholder:e.type==="color"?"#rrggbb or #rrggbbaa":void 0,onchange:i=>s(i.target.value)});return S(r,o)}return e.type==="datatable"?S(r,q(["",...u.tables.keys()],String(n??""),s)):e.type==="column"?S(r,q(["",...(ai()?.columns??[]).map(o=>[o.key,Qn(o)])],String(n??""),s)):S(`${r} (JSON)`,y("textarea",{value:n===void 0?"":JSON.stringify(n,null,2),onchange:o=>{let i=o.target.value.trim();try{s(i?JSON.parse(i):void 0)}catch{s(i)}}}))}function ts(){let t=j("params"),e=E?.params??{},n=new Set(jn(e,u.props));t.replaceChildren(...Object.entries(e).filter(([s])=>n.has(s)).map(([s,r])=>li(s,r))),t.children.length||t.append(y("p",{},"No params."))}var Vn;function R(){clearTimeout(Vn),Vn=setTimeout(()=>{ye()},150)}function te(){let t=!De.some(([,i,a])=>i===u.width&&a===u.height),e=y("input",{type:"number",value:String(u.width),min:64,max:7680,onchange:i=>{u.width=Number(i.target.value)||1920,R()}}),n=y("input",{type:"number",value:String(u.height),min:64,max:7680,onchange:i=>{u.height=Number(i.target.value)||1080,R()}}),s=y("button",{type:"button","aria-pressed":String(!u.playing),onclick:()=>{u.playing=!u.playing,s.textContent=u.playing?"Pause":"Play",s.setAttribute("aria-pressed",String(!u.playing)),ee={wall:Date.now(),t:u.t}}},u.playing?"Pause":"Play"),r=y("input",{id:"clock-seek",type:"range",min:0,max:fe,step:100,value:String(u.t),oninput:i=>Gn(Number(i.target.value))}),o=[y("h2",{},"Screen"),S("Size",q([...De.map(([i])=>i),"Custom"],t?"Custom":De.find(([,i,a])=>i===u.width&&a===u.height)[0],i=>{let a=De.find(([d])=>d===i);a&&(u.width=a[1],u.height=a[2]),te(),R()})),t?y("div",{class:"row"},S("Width",e),S("Height",n)):null,y("div",{class:"row"},S("Time zone",y("input",{type:"text",value:u.timeZone,onchange:i=>{u.timeZone=i.target.value||"UTC",R()}})),S("Locale",y("input",{type:"text",value:u.locale,onchange:i=>{u.locale=i.target.value||"en-US",R()}}))),S("Screen's name",y("input",{type:"text",value:u.screen.name,onchange:i=>{u.screen.name=i.target.value,R()}})),y("div",{class:"row"},S("Latitude",y("input",{type:"number",step:"any",value:String(u.screen.lat),onchange:i=>{u.screen.lat=Number(i.target.value),R()}})),S("Longitude",y("input",{type:"number",step:"any",value:String(u.screen.lon),onchange:i=>{u.screen.lon=Number(i.target.value),R()}}))),S("Screen's fields (JSON)",y("textarea",{value:u.screen.fields,onchange:i=>{u.screen.fields=i.target.value,R()}})),y("h2",{},"Clock"),y("div",{class:"row"},s,S("Speed",q(qr.map(i=>[String(i),`${i}\xD7`]),String(u.speed),i=>{ee={wall:Date.now(),t:u.t},u.speed=Number(i)})),y("span",{id:"clock-time"},"0.0 s")),S("Time in the layout",r),y("h2",{},"Enter and exit"),y("div",{class:"row"},S("Enter",q(_n,u.enter,i=>{u.enter=i,R()})),S("Exit",q(_n,u.exit,i=>{u.exit=i,R()}))),S("Each lasts (ms)",y("input",{type:"number",min:0,max:5e3,step:100,value:String(u.clipMs),onchange:i=>{u.clipMs=Number(i.target.value)||0,R()}})),y("div",{id:"pages"}),y("h2",{},"Params"),y("div",{id:"params"}),L.frames?y("p",{"data-testid":"framed"},`In a frame on ${L.frames}, as in the CMS: no storage, cookies, parent page, controller or impressions.`):null,y("h2",{},"Tables"),...[...u.tables.values()].flatMap(i=>[y("p",{"data-testid":"table","data-table":i.table},es(i)),S(`${i.table}'s rows (JSON)`,y("textarea",{"data-rows":i.table,value:JSON.stringify(i.rows,null,2),rows:6,onchange:a=>{try{let d=JSON.parse(a.target.value);Array.isArray(d)&&Xn(i.table,d)}catch{}}}))]),...[...ge].map(([i,a])=>y("p",{class:"failed","data-testid":"table-error"},`${i}: ${a}`)),S("Add a table (JSON or CSV)",y("input",{type:"file",accept:".json,.csv",onchange:async i=>{let a=i.target.files?.[0];a&&(St(a.name,await a.text()),Et(),te(),R())}})),...E?.capabilities?.sensors?.includes("impressions")&&!L.frames?[y("h2",{},"People at the screen"),y("div",{class:"row"},y("button",{type:"button",onclick:()=>bt("enter")},"Someone arrives"),y("button",{type:"button",onclick:()=>bt("look")},"Someone looks"),y("button",{type:"button",onclick:()=>bt("leave")},"Someone leaves")),y("p",{id:"people-count"},`${u.people.length} in view`)]:[],...L.frames?[]:[y("h2",{},"The player's controller"),y("p",{},`The app may ${E?.capabilities?.player==="control"?"read it and call its commands":"read it (capabilities.player: read)"}. Commands are not applied here.`),...Object.keys(L.controller.events).length?[S("Event",q(Object.keys(L.controller.events),Object.keys(L.controller.events)[0],i=>{j("event-json").value=JSON.stringify(L.controller.events[i],null,2)})),S("Its JSON",y("textarea",{id:"event-json",rows:6,value:JSON.stringify(Object.values(L.controller.events)[0],null,2)})),y("button",{type:"button",onclick:()=>{try{ti(JSON.parse(j("event-json").value))}catch{}}},"Send to the app")]:[]],y("h2",{},"Data"),...Object.keys(u.samples).map(i=>S(`${i} answer's data (JSON)`,y("textarea",{"data-source":i,value:JSON.stringify(u.samples[i],null,2),rows:8,onchange:a=>{try{u.samples[i]=JSON.parse(a.target.value),R()}catch{}}}))),Object.keys(u.samples).length?null:y("p",{},"The app declares no data source with a sample (weather, news or calendar).")];zr.replaceChildren(...o.filter(i=>i!==null)),ts()}async function di(){await zn(),te(),setInterval(oi,Jn),await ye();let t=new EventSource("/events"),e=()=>{zn().then(()=>(te(),ye()))};t.addEventListener("hello",n=>{JSON.parse(n.data).version!==Zn&&e()}),t.addEventListener("reload",e),t.addEventListener("tables",()=>{Yr()}),window.addEventListener("resize",()=>R())}di();})();
|
package/dist/react.d.ts
CHANGED
|
@@ -53,6 +53,11 @@ export declare function useData<T = unknown>(source: string, params: Params, eve
|
|
|
53
53
|
answer?: DataAnswer<T>;
|
|
54
54
|
error?: Error;
|
|
55
55
|
};
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* A data table's snapshot, as snapshot() gives it (null when the screen has none). On a player that says when a table
|
|
58
|
+
* changes (onSnapshot, WP-0149), it renders when the rows do: when the screen says so, or when a binding's rows, chosen
|
|
59
|
+
* on the layout's clock, change. On an older player, which makes the app again when a table changes, it reads them at
|
|
60
|
+
* every frame, as before.
|
|
61
|
+
*/
|
|
57
62
|
export declare function useSnapshot(table: string): unknown | null;
|
|
58
63
|
export {};
|
package/dist/react.js
CHANGED
|
@@ -149,9 +149,23 @@ export function useData(source, params, everyMs = 10 * 60000) {
|
|
|
149
149
|
}, [app, key, everyMs]);
|
|
150
150
|
return state.key === key ? { answer: state.answer, error: state.error } : { answer: kept(app, source, params) };
|
|
151
151
|
}
|
|
152
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* A data table's snapshot, as snapshot() gives it (null when the screen has none). On a player that says when a table
|
|
154
|
+
* changes (onSnapshot, WP-0149), it renders when the rows do: when the screen says so, or when a binding's rows, chosen
|
|
155
|
+
* on the layout's clock, change. On an older player, which makes the app again when a table changes, it reads them at
|
|
156
|
+
* every frame, as before.
|
|
157
|
+
*/
|
|
153
158
|
export function useSnapshot(table) {
|
|
154
|
-
const [app] = useBridge();
|
|
155
|
-
|
|
159
|
+
const [app, bridge] = useBridge();
|
|
160
|
+
const live = typeof contextOf(app)?.onSnapshot === "function";
|
|
161
|
+
// Each frame, and each change the screen says (it may come while the layout is held).
|
|
162
|
+
const subscribe = useCallback((listener) => {
|
|
163
|
+
const off = bridge.subscribe(listener);
|
|
164
|
+
const unheard = contextOf(app)?.onSnapshot?.(() => listener());
|
|
165
|
+
return () => { off(); unheard?.(); };
|
|
166
|
+
}, [app, bridge]);
|
|
167
|
+
// Live, the rows are the same object until they change; an older player's are a new object at each read, so its frames decide.
|
|
168
|
+
const read = useCallback(() => live ? snapshot(app, table) : bridge.time(), [app, bridge, live, table]);
|
|
169
|
+
useSyncExternalStore(subscribe, read, read);
|
|
156
170
|
return snapshot(app, table);
|
|
157
171
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table rows as Preact signals (WP-0149 decision 5, `@wyndlass/app-sdk/signals`): for an app that updates its DOM when its
|
|
3
|
+
* rows change, in an effect, rather than at every frame. An entry of its own, so an app that does not import it does not
|
|
4
|
+
* bundle it. Its signals are this copy of `@preact/signals-core`'s: take effect, computed and the rest from here too, as
|
|
5
|
+
* an effect from another copy does not see them.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReadonlySignal } from "@preact/signals-core";
|
|
8
|
+
import { type WyndlassApp } from "./index.js";
|
|
9
|
+
export { batch, computed, effect, signal, untracked, type ReadonlySignal, type Signal } from "@preact/signals-core";
|
|
10
|
+
/**
|
|
11
|
+
* A data table's snapshot, as snapshot() gives it, as a read-only signal: its value changes when the rows do, and is the
|
|
12
|
+
* same object until then. Read again when the screen says the table changed, and at each frame, since a binding's rows
|
|
13
|
+
* are chosen on the layout's clock (WP-0137). Make it in mount(), where the app has its context.
|
|
14
|
+
*
|
|
15
|
+
* On a player before WP-0149, which makes the app again when a table changes, it keeps the rows the app was made with.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tableSignal(app: WyndlassApp, table: string): ReadonlySignal<unknown | null>;
|
package/dist/signals.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table rows as Preact signals (WP-0149 decision 5, `@wyndlass/app-sdk/signals`): for an app that updates its DOM when its
|
|
3
|
+
* rows change, in an effect, rather than at every frame. An entry of its own, so an app that does not import it does not
|
|
4
|
+
* bundle it. Its signals are this copy of `@preact/signals-core`'s: take effect, computed and the rest from here too, as
|
|
5
|
+
* an effect from another copy does not see them.
|
|
6
|
+
*/
|
|
7
|
+
import { computed, signal } from "@preact/signals-core";
|
|
8
|
+
import { eachFrame } from "./frames.js";
|
|
9
|
+
import { contextOf, snapshot } from "./index.js";
|
|
10
|
+
export { batch, computed, effect, signal, untracked } from "@preact/signals-core";
|
|
11
|
+
/**
|
|
12
|
+
* A data table's snapshot, as snapshot() gives it, as a read-only signal: its value changes when the rows do, and is the
|
|
13
|
+
* same object until then. Read again when the screen says the table changed, and at each frame, since a binding's rows
|
|
14
|
+
* are chosen on the layout's clock (WP-0137). Make it in mount(), where the app has its context.
|
|
15
|
+
*
|
|
16
|
+
* On a player before WP-0149, which makes the app again when a table changes, it keeps the rows the app was made with.
|
|
17
|
+
*/
|
|
18
|
+
export function tableSignal(app, table) {
|
|
19
|
+
const rows = signal(snapshot(app, table));
|
|
20
|
+
const context = contextOf(app);
|
|
21
|
+
if (context?.onSnapshot) {
|
|
22
|
+
// The same object while the rows are the same: set only when another comes.
|
|
23
|
+
const read = () => { const next = snapshot(app, table); if (next !== rows.peek())
|
|
24
|
+
rows.value = next; };
|
|
25
|
+
context.onSnapshot(changed => { if (changed === table)
|
|
26
|
+
read(); });
|
|
27
|
+
eachFrame(app, read);
|
|
28
|
+
}
|
|
29
|
+
return computed(() => rows.value);
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyndlass/app-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Build apps for Wyndlass's screens: web components on the app contract (Player API 2), with the runtime Wyndlass's own apps use.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wyndlass",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/react.d.ts",
|
|
34
34
|
"import": "./dist/react.js"
|
|
35
35
|
},
|
|
36
|
+
"./signals": {
|
|
37
|
+
"types": "./dist/signals.d.ts",
|
|
38
|
+
"import": "./dist/signals.js"
|
|
39
|
+
},
|
|
36
40
|
"./app-definition.schema.json": "./protocol/app-definition.schema.json",
|
|
37
41
|
"./common.schema.json": "./protocol/common.schema.json"
|
|
38
42
|
},
|
|
@@ -49,6 +53,7 @@
|
|
|
49
53
|
"node": ">=20"
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
56
|
+
"@preact/signals-core": "1.14.5",
|
|
52
57
|
"acorn": "8.19.0",
|
|
53
58
|
"ajv": "8.17.1",
|
|
54
59
|
"ajv-formats": "3.0.1",
|
|
@@ -91,6 +91,8 @@ Screens or the CMS enforce each of these:
|
|
|
91
91
|
|
|
92
92
|
One more, which nothing enforces: **make nothing in a draw.** `draw(epochMs)` and a React component run again at every frame, many times a second. Make formatters (`Intl.DateTimeFormat`, `Intl.NumberFormat`) and other objects once: in `mount()`, or with `useMemo` on what they depend on. One made in each draw holds memory a screen does not free in time: an app that did so ran a 4 GB screen out of memory within an hour.
|
|
93
93
|
|
|
94
|
+
And **read a table's rows where you draw,** never once in `mount()`: a screen gives the app a table's new rows while it plays, within about a second of the save. Use `snapshot(this, table)` in `draw()`, `useSnapshot(table)` in a component, or `tableSignal(this, table)` with an `effect` (`@wyndlass/app-sdk/signals`). The rows are frozen: copy them before you sort or change them.
|
|
95
|
+
|
|
94
96
|
## When something goes wrong
|
|
95
97
|
|
|
96
98
|
- **A tool you need is missing:** call `whoami`. The import tools are listed only while the organization has imported apps turned on at its top place. An Owner or Admin turns them on in the CMS, under **Settings**, **Imported apps**.
|
|
@@ -27,7 +27,7 @@ A paged app also defines `paging()`, returning `{count, ms}`, so the layout can
|
|
|
27
27
|
- `data(this, source, params)`: the data service's answer, a promise. Only for sources `app.json`'s `data` lists;
|
|
28
28
|
- `kept(this, source, params)`: the answer the screen last kept for the same request, at once, or `undefined`. Draw it while `data` asks again, so the app is ready without the network;
|
|
29
29
|
- `image(this, path)`: a picture a data answer names, as a URL the app can draw;
|
|
30
|
-
- `snapshot(this, table)`: the rows of a table the layout names, in a `datatable` param or in the element's `binding`. Where a binding chooses rows (a filter, a sort, a limit), only those. `null` when the screen has no snapshot of that table. A `datatable` param needs no binding;
|
|
30
|
+
- `snapshot(this, table)`: the rows of a table the layout names, in a `datatable` param or in the element's `binding`. Where a binding chooses rows (a filter, a sort, a limit), only those. `null` when the screen has no snapshot of that table. A `datatable` param needs no binding. A screen gives the app a table's new rows while it plays: read them where you draw (in `draw()`, `useSnapshot` or `tableSignal`), never once in `mount()`. They are the same object until they change, and frozen: copy rows before you sort or change them;
|
|
31
31
|
- `controllerOf(this)`: the player's controller, as `capabilities.player` allows; absent in the designer and previews;
|
|
32
32
|
- `impressionsOf(this)`: the people at the screen, for an app whose definition declares the `impressions` sensor;
|
|
33
33
|
- `contextOf(this)`: the rest of the context (the screen's `place` and facts, `preview`).
|
|
@@ -43,7 +43,15 @@ A paged app also defines `paging()`, returning `{count, ms}`, so the layout can
|
|
|
43
43
|
- `useNow(everyMs?)`: the layout's clock. Without `everyMs`, drawn again at each of its frames, so the component renders many times a second. With it, the time is a multiple of `everyMs` (`useNow(1000)`: whole seconds), and the component renders only when that changes: take the coarsest the app shows. Either way, make formatters and other objects with `useMemo`, never in the render;
|
|
44
44
|
- `usePaging(count, ms)`: the page showing now, rendering when it turns. It also tells the host the pages;
|
|
45
45
|
- `useData(source, params)`: `{answer, error}`. The kept answer at once, then the service's, asked again every 10 minutes;
|
|
46
|
-
- `useSnapshot(table)`: a data table's rows, as `snapshot` gives them
|
|
46
|
+
- `useSnapshot(table)`: a data table's rows, as `snapshot` gives them. The component renders when they change.
|
|
47
|
+
|
|
48
|
+
## Signals (`@wyndlass/app-sdk/signals`)
|
|
49
|
+
|
|
50
|
+
For a vanilla app that updates its DOM when its rows change, rather than at every frame:
|
|
51
|
+
- `tableSignal(this, table)`: a read-only Preact signal of the table's snapshot, made in `mount()`. Its value changes when the rows do;
|
|
52
|
+
- `effect`, `computed`, `batch`, `signal`, `untracked`: Preact's, from the same copy. Import them from here, never from `@preact/signals-core`, whose effects would not see these signals.
|
|
53
|
+
|
|
54
|
+
Draw in an `effect(() => { … rows.value … })` made in `mount()`, and leave `draw()` empty.
|
|
47
55
|
|
|
48
56
|
## The definition, `app.json`
|
|
49
57
|
|
|
@@ -29,10 +29,11 @@ Two pages, eight seconds each: a heading and the time, then the weather for the
|
|
|
29
29
|
1. **Change `app.json` first:** the `params` people set in the designer (each with a `label` and a `default`), the `data` sources it reads, and `capabilities` if it asks for more.
|
|
30
30
|
2. **Read each param** with `prop(name, default)` (vanilla) or `useApp().prop(name, default)` (react), with the same default as `app.json`.
|
|
31
31
|
3. **Draw from the layout's clock:** vanilla's `draw(epochMs)` gets the moment; react's `useNow()` gives it, and `useNow(1000)` gives whole seconds, rendering once a second. Work out what changes with time (a page, a countdown, a clock) from that number, never from a timer of your own. Both run at every frame: make a formatter once, as the templates do (`#format` in `mount()`, `useMemo` in react), never in the draw.
|
|
32
|
-
4. **
|
|
33
|
-
5. **
|
|
34
|
-
6. **
|
|
35
|
-
7. **
|
|
36
|
-
8. **
|
|
32
|
+
4. **Read a table's rows where you draw,** for an app with a `datatable` param: `snapshot(this, table)` in `draw()`, `tableSignal(this, table)` with an `effect` (vanilla, `@wyndlass/app-sdk/signals`), or `useSnapshot(table)` (react). A screen gives the app a table's new rows while it plays, so a copy kept from `mount()` goes stale. The rows are frozen: copy before you sort them. In the preview, edit a table's rows and check the app follows without being made again.
|
|
33
|
+
5. **Say `ready()`** as soon as the app has something to show, within 5 s: the kept answer, a default, or the failure.
|
|
34
|
+
6. **Styles** go in `src/app.css`. Size text to the box with `fit()` or the `--w` and `--h` properties ([contract.md](contract.md)), since screens run from 1080p to 4K.
|
|
35
|
+
7. **Images:** import them from `src/` (`import logo from "./logo.png"`: PNG, JPEG, GIF, WebP or SVG), and `pack` inlines each as a data URL, for an `<img>`'s `src` or a style set from code. A `url()` inside `src/app.css` is not bundled.
|
|
36
|
+
8. **Fonts:** give the app a param named `font`, of the kind `font`, so the person picks a font in the designer. Apply it as CSS with `font()` (vanilla), or `typographyCss(app.prop("font", null))` (react) ([contract.md](contract.md)).
|
|
37
|
+
9. **Delete what the template drew** that the person did not ask for, its weather included, and its `data` entry with it.
|
|
37
38
|
|
|
38
39
|
Each source change redraws the preview. `npm run typecheck` and `npm run check` find mistakes before the person sees them.
|
|
@@ -5,6 +5,7 @@ An app for Wyndlass's screens, on `@wyndlass/app-sdk` and React. Its README says
|
|
|
5
5
|
- **The module is `src/app.tsx`;** its default export is `reactApp(Component, { css })`, the element's class. The component renders in the app's shadow root.
|
|
6
6
|
- **Time:** `useNow()` gives the layout's clock, drawn again at each of its frames, and `useNow(1000)` whole seconds, rendering once a second: take the coarsest the app shows; never `Date.now()`, so a seek or a pause shows the right moment.
|
|
7
7
|
- **Nothing made in a render:** the component renders at every frame, many times a second. Make formatters (`Intl.DateTimeFormat`, `Intl.NumberFormat`) and other objects with `useMemo` on what they depend on, never in the render. One made in each draw holds memory a screen does not free in time: an app that did so ran a 4 GB screen out of memory within an hour.
|
|
8
|
+
- **A table's rows from `useSnapshot(table)`:** a screen gives the app a table's new rows while it plays, and the component renders when they change. Never keep a copy made once. They are frozen: copy before you sort or change them.
|
|
8
9
|
- **Ready:** call `useApp().ready()` once drawn, within 5 s, or the screen reports the app late. `useData()` gives the answer the screen kept at once, then the service's.
|
|
9
10
|
- **Data:** only through `useData(source, params)`, and only the sources `app.json`'s `data` lists. Pages: `usePaging(count, ms)`.
|
|
10
11
|
- **Styles:** `src/app.css`, passed as `css`, never a `<style>`.
|
|
@@ -5,6 +5,7 @@ An app for Wyndlass's screens, on `@wyndlass/app-sdk`. Its README says what it i
|
|
|
5
5
|
- **The module is `src/app.ts`;** its default export is the element's class, extending `WyndlassApp`. `mount()` builds the shadow DOM once; `draw(epochMs)` draws that moment of the layout's clock.
|
|
6
6
|
- **Time:** from `now()` or `draw`'s `epochMs`, never `Date.now()`, so a seek or a pause shows the right moment.
|
|
7
7
|
- **Nothing made in `draw`:** it runs at every frame, many times a second. Make formatters (`Intl.DateTimeFormat`, `Intl.NumberFormat`) and other objects in `mount()`, never in `draw`. One made in each draw holds memory a screen does not free in time: an app that did so ran a 4 GB screen out of memory within an hour.
|
|
8
|
+
- **A table's rows where you draw:** a screen gives the app a table's new rows while it plays. Read them with `snapshot(this, table)` in `draw`, or with `tableSignal(this, table)` and an `effect` from `@wyndlass/app-sdk/signals`, made in `mount()`. Never read them once in `mount()` and keep them. They are frozen: copy before you sort or change them.
|
|
8
9
|
- **Ready:** call `ready()` once drawn, within 5 s, or the screen reports the app late. Draw the answer `kept()` gives at once, then ask `data()`.
|
|
9
10
|
- **Data:** only through `data(this, source, params)`, and only the sources `app.json`'s `data` lists. Images a data answer names through `image(this, path)`.
|
|
10
11
|
- **Styles:** `this.css(text)`, never a `<style>`. A CSS file the source imports is its text.
|