zcode-app-cli 3.14.5-34 → 3.15.3-36
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 +13 -2
- package/bin/zcode.js +9 -0
- package/docs/CONFIGURATION.md +36 -5
- package/docs/CONFIGURATION.zh-CN.md +29 -3
- package/docs/PROVIDER_CONFIG.md +25 -0
- package/docs/PROVIDER_CONFIG.zh-CN.md +20 -0
- package/package.json +5 -3
- package/vendor/cli-config.cjs +88 -0
- package/vendor/extraction.json +24 -6
- package/vendor/node_modules/@zcode/tui/dist/index.js +533 -98
- package/vendor/packages/browser-use-plugin/README.md +1 -1
- package/vendor/packages/browser-use-plugin/docs/api.json +1 -1
- package/vendor/packages/browser-use-plugin/docs/overview.md +6 -6
- package/vendor/packages/browser-use-plugin/docs/playwright.md +3 -3
- package/vendor/packages/browser-use-plugin/docs/workflow.md +2 -2
- package/vendor/packages/browser-use-plugin/scripts/browser-client.mjs +5 -7
- package/vendor/packages/browser-use-plugin/scripts/build.mjs +0 -1
- package/vendor/packages/browser-use-plugin/skills/control-browser/SKILL.md +9 -9
- package/vendor/packages/bundled-skills/skills/dynamic-workflows/SKILL.md +760 -687
- package/vendor/packages/bundled-skills/skills/dynamic-workflows/examples.md +310 -1
- package/vendor/packages/bundled-skills/skills/dynamic-workflows/patterns.md +336 -4
- package/vendor/packages/documents-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/documents-plugin/package.json +2 -2
- package/vendor/packages/documents-plugin/skills/docx/LICENSE.txt +10 -10
- package/vendor/packages/node-repl-host/.zcode-plugin/plugin.json +1 -1
- package/vendor/packages/node-repl-host/dist/mcp/server.js +116 -48
- package/vendor/packages/node-repl-host/package.json +1 -1
- package/vendor/packages/node-repl-host/scripts/build.mjs +4 -4
- package/vendor/packages/pdf-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/pdf-plugin/package.json +2 -2
- package/vendor/packages/pdf-plugin/skills/pdf/LICENSE.txt +10 -10
- package/vendor/packages/pdf-plugin/skills/pdf/references/resume-altacv.tex +1 -1
- package/vendor/packages/plugin-creator-plugin/skills/plugin-creator/SKILL.md +1 -1
- package/vendor/packages/plugin-creator-plugin/skills/plugin-creator/references/plugin-json-spec.md +1 -1
- package/vendor/packages/presentations-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/presentations-plugin/package.json +2 -2
- package/vendor/packages/presentations-plugin/skills/pptx/LICENSE.txt +10 -10
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +1 -1
- package/vendor/packages/spreadsheets-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/spreadsheets-plugin/package.json +2 -2
- package/vendor/packages/spreadsheets-plugin/skills/xlsx/LICENSE.txt +10 -10
- package/vendor/packages/visualize-plugin/.zcode-plugin/plugin.json +10 -0
- package/vendor/packages/visualize-plugin/package.json +8 -0
- package/vendor/packages/visualize-plugin/skills/visualize/LICENSE.md +5 -0
- package/vendor/packages/visualize-plugin/skills/visualize/SKILL.md +277 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/calendar.js +273 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/runtime-manifest.json +16 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/standalone-host-bridge.js +256 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/standalone-shell.js +183 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/d3-7.9.0.min.js +2 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/d3-7.9.0.min.js.LICENSE +13 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/floating-ui-core-1.7.3.min.js +1 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/floating-ui-core-1.7.3.min.js.LICENSE +20 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/floating-ui-dom-1.7.4.min.js +1 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/floating-ui-dom-1.7.4.min.js.LICENSE +20 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/lucide-1.17.0.js +19521 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/lucide-1.17.0.js.LICENSE +43 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/vendor/manifest.json +57 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/visualize.css +1222 -0
- package/vendor/packages/visualize-plugin/skills/visualize/assets/visualize.html +517 -0
- package/vendor/packages/visualize-plugin/skills/visualize/examples/calendar.html +10 -0
- package/vendor/packages/visualize-plugin/skills/visualize/references/api.md +128 -0
- package/vendor/packages/visualize-plugin/skills/visualize/references/styles.md +3 -0
- package/vendor/packages/visualize-plugin/skills/visualize/scripts/render.py +248 -0
- package/vendor/packages/visualize-plugin/skills/visualize/scripts/vendor.py +56 -0
- package/vendor/packages/visualize-plugin/skills/visualize/tweak.md +62 -0
- package/vendor/packages/visualize-plugin/skills/visualize/widgets/calendar.md +90 -0
- package/vendor/packages/zcode-cua-plugin/.zcode-plugin/plugin.json +1 -1
- package/vendor/packages/zcode-cua-plugin/docs/computer-use.md +1 -1
- package/vendor/packages/zcode-cua-plugin/package.json +1 -1
- package/vendor/packages/zcode-cua-plugin/scripts/computer-use-client.mjs +35 -41
- package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +2 -2
- package/vendor/provider/zcode-builtin.json +96 -1
- package/vendor/zcode.cjs +1622 -1425
- package/zcode-runtime.lock.json +3 -3
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// Bundled into the sandbox only when the fragment references viz-calendar.
|
|
2
|
+
// Register before parsing the fragment: connectedCallback builds the styled
|
|
3
|
+
// shadow tree synchronously, without a network request or hydration frame.
|
|
4
|
+
(() => {
|
|
5
|
+
if (customElements.get("viz-calendar")) return;
|
|
6
|
+
|
|
7
|
+
const style = `
|
|
8
|
+
:host{display:block;min-width:0;padding:12px;font:400 14px/1.5 Inter,system-ui,sans-serif;color:var(--foreground);container-type:inline-size}
|
|
9
|
+
*{box-sizing:border-box}
|
|
10
|
+
.layout{display:grid;grid-template-columns:88px minmax(0,1fr);gap:24px}
|
|
11
|
+
.date{display:flex;flex-direction:column;gap:8px;padding-top:8px;border-right:1px solid var(--border)}
|
|
12
|
+
.weekday,.context{color:color-mix(in srgb,var(--foreground) 65%,var(--background))}
|
|
13
|
+
.day{font-size:48px;line-height:1.1;letter-spacing:-.03em}
|
|
14
|
+
.context{font-size:12px;line-height:16px;overflow-wrap:anywhere}
|
|
15
|
+
.axis{--hour:max(48px,var(--minimum-hour));position:relative;height:calc(var(--hours)*var(--hour) + 16px);margin-top:8px;min-width:0}
|
|
16
|
+
.axis.compact{--hour:max(32px,var(--minimum-hour))}
|
|
17
|
+
.hour{position:absolute;top:calc(var(--at)*var(--hour));inset-inline:0;color:var(--muted-foreground)}
|
|
18
|
+
.hour span{display:block;width:36px;text-align:right;transform:translateY(-50%);font-variant-numeric:tabular-nums}
|
|
19
|
+
.hour::after{content:"";position:absolute;top:0;left:48px;right:0;border-top:1px solid var(--border)}
|
|
20
|
+
.events{position:absolute;inset:0 0 16px 48px;margin:0;padding:0;list-style:none;overflow:hidden}
|
|
21
|
+
.event{position:absolute;top:calc(var(--at)*var(--hour) + 2px);height:calc(var(--duration)*var(--hour) - 4px);left:calc(var(--lane)*100%/var(--lanes) + var(--lane)*8px/var(--lanes));width:calc((100% - (var(--lanes) - 1)*8px)/var(--lanes));border-radius:8px;background:linear-gradient(110deg,color-mix(in srgb,var(--tone) 24%,var(--background)),color-mix(in srgb,var(--tone) 32%,var(--background)));overflow:hidden;container-type:size}
|
|
22
|
+
.event.past{background:color-mix(in srgb,var(--tone) 12%,var(--background));color:color-mix(in srgb,var(--foreground) 70%,var(--background))}
|
|
23
|
+
.event-body{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%;height:100%;padding:4px 12px;font:inherit;color:inherit;text-align:left}
|
|
24
|
+
button.event-body{appearance:none;border:0;border-radius:inherit;background:transparent}
|
|
25
|
+
.cursor-interaction{cursor:var(--cursor-interaction,pointer)}
|
|
26
|
+
button.event-body:hover{background:color-mix(in srgb,var(--foreground) 2%,transparent)}
|
|
27
|
+
button.event-body:focus-visible{outline:2px solid var(--ring);outline-offset:-2px}
|
|
28
|
+
/* Optically center Inter's glyphs within the unchanged line boxes. */
|
|
29
|
+
.event-content{min-width:0;transform:translateY(-1px)}
|
|
30
|
+
.title{display:block;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
31
|
+
.detail{display:block;font-size:12px;line-height:16px;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
32
|
+
@container(max-height:48px){.detail{display:none}.event-body{padding-block:0}}
|
|
33
|
+
.video{width:16px;height:16px;flex:none}
|
|
34
|
+
.now{position:absolute;top:calc(var(--at)*var(--hour));left:48px;right:0;border-top:2px solid var(--red);pointer-events:none}
|
|
35
|
+
.now::before{content:"";position:absolute;left:-4px;top:-5px;width:8px;height:8px;border-radius:50%;background:var(--red)}
|
|
36
|
+
.now span{position:absolute;right:calc(100% + 12px);transform:translateY(-50%);color:var(--red);font:400 12px/16px Inter,system-ui,sans-serif;font-variant-numeric:tabular-nums}
|
|
37
|
+
.empty{position:absolute;top:24px;left:64px;color:var(--muted-foreground)}
|
|
38
|
+
@media(pointer:coarse){:host .axis{--hour:max(48px,var(--minimum-hour),var(--minimum-target-hour))}}
|
|
39
|
+
@container(max-width:520px){.layout{grid-template-columns:minmax(0,1fr)}.date{flex-direction:row;align-items:baseline;border:0;padding:0}.event-body{padding-inline:8px}}
|
|
40
|
+
`;
|
|
41
|
+
const escape = (value) =>
|
|
42
|
+
String(value).replace(
|
|
43
|
+
/[&<>"']/g,
|
|
44
|
+
(char) =>
|
|
45
|
+
({
|
|
46
|
+
"&": "&",
|
|
47
|
+
"<": "<",
|
|
48
|
+
">": ">",
|
|
49
|
+
'"': """,
|
|
50
|
+
"'": "'",
|
|
51
|
+
})[char],
|
|
52
|
+
);
|
|
53
|
+
const minutes = (value) => {
|
|
54
|
+
if (
|
|
55
|
+
typeof value !== "string" ||
|
|
56
|
+
!/^(?:[01]\d|2[0-3]):[0-5]\d$|^24:00$/.test(value)
|
|
57
|
+
) {
|
|
58
|
+
throw new Error("Use HH:MM times between 00:00 and 24:00.");
|
|
59
|
+
}
|
|
60
|
+
return Number(value.slice(0, 2)) * 60 + Number(value.slice(3));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
class Calendar extends HTMLElement {
|
|
64
|
+
#initialized = false;
|
|
65
|
+
#events;
|
|
66
|
+
static observedAttributes = [
|
|
67
|
+
"date",
|
|
68
|
+
"start",
|
|
69
|
+
"end",
|
|
70
|
+
"now",
|
|
71
|
+
"events",
|
|
72
|
+
"lang",
|
|
73
|
+
"time-zone",
|
|
74
|
+
"empty-label",
|
|
75
|
+
"interactive",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
constructor() {
|
|
79
|
+
super();
|
|
80
|
+
// Replay data assigned before the custom element was registered.
|
|
81
|
+
if (Object.hasOwn(this, "events")) {
|
|
82
|
+
const events = this.events;
|
|
83
|
+
delete this.events;
|
|
84
|
+
this.events = events;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get events() {
|
|
89
|
+
return this.#events === undefined
|
|
90
|
+
? JSON.parse(this.getAttribute("events") ?? "[]")
|
|
91
|
+
: this.#events;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set events(events) {
|
|
95
|
+
this.#events = events;
|
|
96
|
+
if (this.#initialized) this.render();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
connectedCallback() {
|
|
100
|
+
// Keep the shared widget surface outside Shadow DOM; only layout is private.
|
|
101
|
+
this.classList.add("widget");
|
|
102
|
+
// Preserve a server-rendered declarative shadow root when upgrading it.
|
|
103
|
+
// https://web.dev/articles/declarative-shadow-dom
|
|
104
|
+
if (!this.shadowRoot) {
|
|
105
|
+
this.attachShadow({ mode: "open", serializable: true });
|
|
106
|
+
this.render();
|
|
107
|
+
} else if (!this.#initialized && this.#events !== undefined) {
|
|
108
|
+
this.render();
|
|
109
|
+
}
|
|
110
|
+
if (!this.#initialized) {
|
|
111
|
+
this.shadowRoot.addEventListener("click", (event) => {
|
|
112
|
+
const button = event.target.closest?.("button[data-event-index]");
|
|
113
|
+
if (!button) return;
|
|
114
|
+
const index = Number(button.dataset.eventIndex);
|
|
115
|
+
this.dispatchEvent(
|
|
116
|
+
new CustomEvent("eventselect", {
|
|
117
|
+
bubbles: true,
|
|
118
|
+
composed: true,
|
|
119
|
+
detail: { event: this.events[index], index },
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
this.#initialized = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
attributeChangedCallback(name, before, after) {
|
|
128
|
+
if (before !== after && this.#initialized && this.shadowRoot)
|
|
129
|
+
this.render();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
render() {
|
|
133
|
+
const shadow = this.shadowRoot;
|
|
134
|
+
try {
|
|
135
|
+
const date = this.getAttribute("date") ?? "";
|
|
136
|
+
const calendarDate = new Date(`${date}T12:00:00Z`);
|
|
137
|
+
if (
|
|
138
|
+
!/^\d{4}-\d{2}-\d{2}$/.test(date) ||
|
|
139
|
+
!Number.isFinite(calendarDate.getTime()) ||
|
|
140
|
+
calendarDate.toISOString().slice(0, 10) !== date
|
|
141
|
+
) {
|
|
142
|
+
throw new Error("Supply a valid calendar date as YYYY-MM-DD.");
|
|
143
|
+
}
|
|
144
|
+
const start = minutes(this.getAttribute("start") ?? "09:00");
|
|
145
|
+
const end = minutes(this.getAttribute("end") ?? "17:00");
|
|
146
|
+
if (end <= start)
|
|
147
|
+
throw new Error("The visible end must be later than the start.");
|
|
148
|
+
const now = this.hasAttribute("now")
|
|
149
|
+
? minutes(this.getAttribute("now"))
|
|
150
|
+
: null;
|
|
151
|
+
const input = this.events;
|
|
152
|
+
if (!Array.isArray(input) || input.length > 200)
|
|
153
|
+
throw new Error("Supply an array of at most 200 events.");
|
|
154
|
+
const tones = new Set([
|
|
155
|
+
"blue",
|
|
156
|
+
"green",
|
|
157
|
+
"red",
|
|
158
|
+
"orange",
|
|
159
|
+
"purple",
|
|
160
|
+
"yellow",
|
|
161
|
+
]);
|
|
162
|
+
const events = input
|
|
163
|
+
.map((event, index) => {
|
|
164
|
+
if (
|
|
165
|
+
event == null ||
|
|
166
|
+
typeof event !== "object" ||
|
|
167
|
+
typeof event.title !== "string"
|
|
168
|
+
) {
|
|
169
|
+
throw new Error("Each event needs a title, start and end.");
|
|
170
|
+
}
|
|
171
|
+
const from = minutes(event.start),
|
|
172
|
+
to = minutes(event.end);
|
|
173
|
+
if (to <= from)
|
|
174
|
+
throw new Error("An event must end after it starts.");
|
|
175
|
+
if (event.detail != null && typeof event.detail !== "string")
|
|
176
|
+
throw new Error("Event detail must be text.");
|
|
177
|
+
return {
|
|
178
|
+
...event,
|
|
179
|
+
index,
|
|
180
|
+
from,
|
|
181
|
+
to,
|
|
182
|
+
tone: tones.has(event.tone) ? event.tone : "blue",
|
|
183
|
+
lane: 0,
|
|
184
|
+
lanes: 1,
|
|
185
|
+
};
|
|
186
|
+
})
|
|
187
|
+
.filter((event) => event.from < end && event.to > start)
|
|
188
|
+
.sort((a, b) => a.from - b.from || b.to - a.to);
|
|
189
|
+
|
|
190
|
+
// Allocate interval lanes within each connected overlap group. Adjacent
|
|
191
|
+
// events share a lane; a chain of overlaps shares one column count.
|
|
192
|
+
let group = [],
|
|
193
|
+
laneEnds = [],
|
|
194
|
+
groupEnd = -1;
|
|
195
|
+
const finishGroup = () => {
|
|
196
|
+
for (const event of group) event.lanes = laneEnds.length;
|
|
197
|
+
};
|
|
198
|
+
for (const event of events) {
|
|
199
|
+
if (event.from >= groupEnd) {
|
|
200
|
+
finishGroup();
|
|
201
|
+
group = [];
|
|
202
|
+
laneEnds = [];
|
|
203
|
+
}
|
|
204
|
+
let lane = laneEnds.findIndex((until) => until <= event.from);
|
|
205
|
+
if (lane < 0) lane = laneEnds.length;
|
|
206
|
+
event.lane = lane;
|
|
207
|
+
laneEnds[lane] = event.to;
|
|
208
|
+
group.push(event);
|
|
209
|
+
groupEnd = Math.max(event.to, groupEnd);
|
|
210
|
+
}
|
|
211
|
+
finishGroup();
|
|
212
|
+
|
|
213
|
+
const locale = this.lang || document.documentElement.lang || "en";
|
|
214
|
+
const weekday = new Intl.DateTimeFormat(locale, {
|
|
215
|
+
weekday: "short",
|
|
216
|
+
timeZone: "UTC",
|
|
217
|
+
}).format(calendarDate);
|
|
218
|
+
const fullDate = new Intl.DateTimeFormat(locale, {
|
|
219
|
+
dateStyle: "full",
|
|
220
|
+
timeZone: "UTC",
|
|
221
|
+
}).format(calendarDate);
|
|
222
|
+
const timeZone = this.getAttribute("time-zone");
|
|
223
|
+
const ticks = [start];
|
|
224
|
+
for (
|
|
225
|
+
let tick = (Math.floor(start / 60) + 1) * 60;
|
|
226
|
+
tick < end;
|
|
227
|
+
tick += 60
|
|
228
|
+
)
|
|
229
|
+
ticks.push(tick);
|
|
230
|
+
ticks.push(end);
|
|
231
|
+
const labelTime = (time) =>
|
|
232
|
+
`${String(Math.floor(time / 60)).padStart(2, "0")}:${String(time % 60).padStart(2, "0")}`;
|
|
233
|
+
const compact = end - start > 240;
|
|
234
|
+
// Size from full event durations; the window clips partial events
|
|
235
|
+
// without letting a one-minute sliver stretch the entire time axis.
|
|
236
|
+
const minimumHour = Math.max(
|
|
237
|
+
0,
|
|
238
|
+
...events.map((event) => (28 * 60) / (event.to - event.from)),
|
|
239
|
+
);
|
|
240
|
+
const minimumTargetHour = Math.max(
|
|
241
|
+
0,
|
|
242
|
+
...events.map((event) => (48 * 60) / (event.to - event.from)),
|
|
243
|
+
);
|
|
244
|
+
const hourMarkup = ticks
|
|
245
|
+
.map(
|
|
246
|
+
(tick) =>
|
|
247
|
+
`<div class="hour" style="--at:${(tick - start) / 60}">${now != null && now >= start && now <= end && Math.abs(tick - now) < 15 ? "" : `<span>${tick % 60 ? labelTime(tick) : tick / 60}</span>`}</div>`,
|
|
248
|
+
)
|
|
249
|
+
.join("");
|
|
250
|
+
const interactive = this.hasAttribute("interactive");
|
|
251
|
+
const eventMarkup = events
|
|
252
|
+
.map((event) => {
|
|
253
|
+
const label = escape(
|
|
254
|
+
`${event.title}, ${event.start}-${event.end}${event.detail ? `, ${event.detail}` : ""}`,
|
|
255
|
+
);
|
|
256
|
+
const body = `button type="button"${interactive ? ` data-event-index="${event.index}"` : ""} aria-label="${label}" data-tooltip="${label}"`;
|
|
257
|
+
return `<li class="event${now != null && event.to <= now ? " past" : ""}" style="--at:${(event.from - start) / 60};--duration:${(event.to - event.from) / 60};--lane:${event.lane};--lanes:${event.lanes};--tone:var(--${event.tone})"><${body} class="event-body cursor-interaction"><span class="event-content"><span class="title">${escape(event.title)}</span>${event.detail ? `<span class="detail">${escape(event.detail)}</span>` : ""}</span>${event.video ? '<svg class="video" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"/><rect x="2" y="6" width="14" height="12" rx="2"/></svg>' : ""}</button></li>`;
|
|
258
|
+
})
|
|
259
|
+
.join("");
|
|
260
|
+
const nowMarkup =
|
|
261
|
+
now != null && now >= start && now <= end
|
|
262
|
+
? `<div class="now" style="--at:${(now - start) / 60}" role="img" aria-label="${escape(labelTime(now))}"><span>${labelTime(now)}</span></div>`
|
|
263
|
+
: "";
|
|
264
|
+
shadow.innerHTML = `<style>${style}</style><section class="calendar" aria-label="${escape(fullDate)}"><div class="layout"><div class="date"><span class="weekday">${escape(weekday)}</span><span class="day">${Number(date.slice(-2))}</span>${timeZone ? `<span class="context">${escape(timeZone)}</span>` : ""}</div><div class="axis${compact ? " compact" : ""}" style="--hours:${(end - start) / 60};--minimum-hour:${minimumHour}px;--minimum-target-hour:${minimumTargetHour}px">${hourMarkup}<ol class="events">${eventMarkup}</ol>${nowMarkup}${events.length ? "" : `<span class="empty">${escape(this.getAttribute("empty-label") ?? "No events")}</span>`}</div></div></section>`;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
// Invalid model-authored input remains visible and recoverable through
|
|
267
|
+
// the same attributes; never silently invent dates or drop events.
|
|
268
|
+
shadow.innerHTML = `<style>${style}</style><div class="calendar" role="alert">${escape(error instanceof Error ? error.message : "Invalid calendar data.")}</div>`;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
customElements.define("viz-calendar", Calendar);
|
|
273
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
"visualize.css": {
|
|
4
|
+
"sha256": "67aea8a8ab5c4b98dd39b949d8cb895f45af3994de17357376cb824ef280d39c"
|
|
5
|
+
},
|
|
6
|
+
"visualize.html": {
|
|
7
|
+
"sha256": "42d9c7d924174a23545ad2ffc31ec0692ca589b3999c2ffdc21c1d358f4185bf"
|
|
8
|
+
},
|
|
9
|
+
"tweak.js": {
|
|
10
|
+
"sha256": "669e78ea50dc7482bc3572b3d9db5070634d52b9c574ce9cdbef4a2a5a50a3e3"
|
|
11
|
+
},
|
|
12
|
+
"calendar.js": {
|
|
13
|
+
"sha256": "19f40e0a15ae7a9b9a4e17bc53c5bb47c5b21e6d32317d80cf030f9e012c221b"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const root = document.documentElement;
|
|
3
|
+
const mediaQuery = globalThis.matchMedia("(prefers-color-scheme: dark)");
|
|
4
|
+
const apply = Reflect.apply;
|
|
5
|
+
const isArray = Array.isArray;
|
|
6
|
+
const hasOwn = Object.hasOwn;
|
|
7
|
+
const parentWindow = globalThis.parent;
|
|
8
|
+
const stringify = JSON.stringify;
|
|
9
|
+
const parse = JSON.parse;
|
|
10
|
+
const encode = TextEncoder.prototype.encode.bind(new TextEncoder());
|
|
11
|
+
const initialStateElement = document.getElementById("zcode-visualization-widget-state");
|
|
12
|
+
const initialGlobals = parse(initialStateElement?.textContent ?? "{}");
|
|
13
|
+
initialStateElement?.remove();
|
|
14
|
+
/** @type {Record<string, unknown> | null} */
|
|
15
|
+
let state = initialGlobals.widgetState ?? null;
|
|
16
|
+
const statePersistence = initialGlobals.statePersistence ?? "none";
|
|
17
|
+
let nextStateRequestId = 0;
|
|
18
|
+
/** @type {Map<number, { resolve: () => void; reject: (error: Error) => void; timeout: ReturnType<typeof globalThis.setTimeout>; serializedState: string }>} */
|
|
19
|
+
const pendingStateWrites = new Map();
|
|
20
|
+
const persistenceError = () =>
|
|
21
|
+
Object.assign(new Error("The host could not persist the widget state update"), {
|
|
22
|
+
code: -32000,
|
|
23
|
+
data: { code: "widget_state_persistence_failed", retryable: false },
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} prototype
|
|
27
|
+
* @param {string} property
|
|
28
|
+
*/
|
|
29
|
+
const getPrototypeGetter = (prototype, property) => {
|
|
30
|
+
// oxlint-disable-next-line typescript/unbound-method -- invoked through captured Reflect.apply
|
|
31
|
+
const getter = Object.getOwnPropertyDescriptor(prototype, property)?.get;
|
|
32
|
+
if (getter == null) {
|
|
33
|
+
throw new Error(`Missing ${property} getter`);
|
|
34
|
+
}
|
|
35
|
+
return getter;
|
|
36
|
+
};
|
|
37
|
+
const getMessageData = getPrototypeGetter(MessageEvent.prototype, "data");
|
|
38
|
+
const getMessagePorts = getPrototypeGetter(MessageEvent.prototype, "ports");
|
|
39
|
+
const getMessageSource = getPrototypeGetter(MessageEvent.prototype, "source");
|
|
40
|
+
// oxlint-disable-next-line typescript/unbound-method -- captured before the untrusted fragment runs
|
|
41
|
+
const addHostMessageListener = MessagePort.prototype.addEventListener;
|
|
42
|
+
// oxlint-disable-next-line typescript/unbound-method -- captured before the untrusted fragment runs
|
|
43
|
+
const postHostMessage = MessagePort.prototype.postMessage;
|
|
44
|
+
// oxlint-disable-next-line typescript/unbound-method -- captured before the untrusted fragment runs
|
|
45
|
+
const startHostPort = MessagePort.prototype.start;
|
|
46
|
+
// oxlint-disable-next-line typescript/unbound-method -- captured before the untrusted fragment runs
|
|
47
|
+
const stopMessagePropagation = Event.prototype.stopImmediatePropagation;
|
|
48
|
+
/** @type {MessagePort | null} */
|
|
49
|
+
let hostPort = null;
|
|
50
|
+
const postToHost = (type, payload) => {
|
|
51
|
+
if (hostPort != null) {
|
|
52
|
+
apply(postHostMessage, hostPort, [{ type, ...payload }]);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const openExternal = ({ href }) => {
|
|
56
|
+
if (globalThis.navigator.userActivation?.isActive === true) {
|
|
57
|
+
postToHost("open-external", { href });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const sendFollowUpMessage = ({ context, prompt, title }) => {
|
|
61
|
+
if (globalThis.navigator.userActivation?.isActive === true) {
|
|
62
|
+
postToHost("follow-up", { context, prompt, title });
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* @param {Record<string, unknown> | ((previous: Record<string, unknown> | null) => Record<string, unknown>)} next
|
|
68
|
+
* @returns {Promise<void>}
|
|
69
|
+
*/
|
|
70
|
+
const setWidgetState = async (next) => {
|
|
71
|
+
const nextState = typeof next === "function" ? next(state) : next;
|
|
72
|
+
if (nextState == null || typeof nextState !== "object" || isArray(nextState)) {
|
|
73
|
+
throw new TypeError("Widget state must be a JSON object");
|
|
74
|
+
}
|
|
75
|
+
const inputState = stringify(nextState, (_key, /** @type {unknown} */ value) => {
|
|
76
|
+
if (
|
|
77
|
+
typeof value === "undefined" ||
|
|
78
|
+
typeof value === "function" ||
|
|
79
|
+
typeof value === "symbol" ||
|
|
80
|
+
(typeof value === "number" && !Number.isFinite(value))
|
|
81
|
+
) {
|
|
82
|
+
throw new TypeError("Widget state must be a JSON object");
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
});
|
|
86
|
+
const parsedState = parse(inputState);
|
|
87
|
+
if (parsedState == null || typeof parsedState !== "object" || isArray(parsedState)) {
|
|
88
|
+
throw new TypeError("Widget state must be a JSON object");
|
|
89
|
+
}
|
|
90
|
+
const storedState = {
|
|
91
|
+
modelContent: null,
|
|
92
|
+
privateContent: null,
|
|
93
|
+
...parsedState,
|
|
94
|
+
};
|
|
95
|
+
const serializedState = stringify(storedState);
|
|
96
|
+
if (encode(serializedState).length > 16 * 1024) {
|
|
97
|
+
throw new TypeError("Widget state must be a JSON object of at most 16 KiB");
|
|
98
|
+
}
|
|
99
|
+
if (
|
|
100
|
+
hasOwn(storedState, "imageIds") &&
|
|
101
|
+
(!isArray(storedState.imageIds) ||
|
|
102
|
+
storedState.imageIds.some((/** @type {unknown} */ id) => typeof id !== "string"))
|
|
103
|
+
) {
|
|
104
|
+
throw new TypeError("Widget state imageIds must be an array of strings");
|
|
105
|
+
}
|
|
106
|
+
if (storedState.imageIds?.length > 0) {
|
|
107
|
+
throw Object.assign(new TypeError("Visualization state does not support image attachments"), {
|
|
108
|
+
code: -32602,
|
|
109
|
+
data: { code: "images_unsupported" },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
state = storedState;
|
|
113
|
+
globalThis.zcode.widgetState = state;
|
|
114
|
+
globalThis.dispatchEvent(
|
|
115
|
+
new CustomEvent("zcode:set_globals", {
|
|
116
|
+
detail: { globals: { widgetState: state } },
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
if (statePersistence === "none") {
|
|
120
|
+
throw persistenceError();
|
|
121
|
+
}
|
|
122
|
+
const id = ++nextStateRequestId;
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const timeout = globalThis.setTimeout(() => {
|
|
125
|
+
pendingStateWrites.delete(id);
|
|
126
|
+
reject(persistenceError());
|
|
127
|
+
}, 30_000);
|
|
128
|
+
pendingStateWrites.set(id, { resolve, reject, timeout, serializedState });
|
|
129
|
+
postToHost("widget-state-write", { id, state: serializedState });
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const syncTheme = () => {
|
|
133
|
+
const theme = mediaQuery.matches ? "dark" : "light";
|
|
134
|
+
root.dataset.theme = theme;
|
|
135
|
+
globalThis.zcode = {
|
|
136
|
+
...globalThis.zcode,
|
|
137
|
+
openExternal,
|
|
138
|
+
sendFollowUpMessage,
|
|
139
|
+
setWidgetState,
|
|
140
|
+
theme,
|
|
141
|
+
visualizationStyleVariables: {},
|
|
142
|
+
visualizationTheme: theme,
|
|
143
|
+
widgetState: state,
|
|
144
|
+
statePersistence,
|
|
145
|
+
stateModelContext: "none",
|
|
146
|
+
};
|
|
147
|
+
globalThis.dispatchEvent(
|
|
148
|
+
new CustomEvent("zcode:set_globals", {
|
|
149
|
+
detail: { globals: globalThis.zcode },
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
const sendHeight = () => {
|
|
154
|
+
postToHost("height", {
|
|
155
|
+
height: Math.ceil(
|
|
156
|
+
Math.max(document.body.scrollHeight, document.body.getBoundingClientRect().height),
|
|
157
|
+
),
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
globalThis.addEventListener(
|
|
162
|
+
"message",
|
|
163
|
+
(event) => {
|
|
164
|
+
const data = apply(getMessageData, event, []);
|
|
165
|
+
const ports = apply(getMessagePorts, event, []);
|
|
166
|
+
const source = apply(getMessageSource, event, []);
|
|
167
|
+
if (
|
|
168
|
+
hostPort != null ||
|
|
169
|
+
source !== parentWindow ||
|
|
170
|
+
typeof data !== "object" ||
|
|
171
|
+
data?.type !== "zcode-visualization-initialize" ||
|
|
172
|
+
!isArray(ports) ||
|
|
173
|
+
ports.length !== 1
|
|
174
|
+
) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
apply(stopMessagePropagation, event, []);
|
|
178
|
+
const nextHostPort = ports[0];
|
|
179
|
+
try {
|
|
180
|
+
apply(addHostMessageListener, nextHostPort, [
|
|
181
|
+
"message",
|
|
182
|
+
(event) => {
|
|
183
|
+
const data = apply(getMessageData, event, []);
|
|
184
|
+
if (typeof data === "object" && data?.type === "measure") {
|
|
185
|
+
sendHeight();
|
|
186
|
+
} else if (typeof data === "object" && data?.type === "widget-state-result") {
|
|
187
|
+
/** @type {unknown} */
|
|
188
|
+
const id = data.id;
|
|
189
|
+
if (typeof id !== "number") {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const pending = pendingStateWrites.get(id);
|
|
193
|
+
if (pending != null) {
|
|
194
|
+
pendingStateWrites.delete(id);
|
|
195
|
+
globalThis.clearTimeout(pending.timeout);
|
|
196
|
+
if (data.ok === true) {
|
|
197
|
+
pending.resolve();
|
|
198
|
+
} else {
|
|
199
|
+
pending.reject(persistenceError());
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
]);
|
|
205
|
+
apply(startHostPort, nextHostPort, []);
|
|
206
|
+
} catch {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
hostPort = nextHostPort;
|
|
210
|
+
for (const [id, { serializedState }] of pendingStateWrites) {
|
|
211
|
+
postToHost("widget-state-write", { id, state: serializedState });
|
|
212
|
+
}
|
|
213
|
+
sendHeight();
|
|
214
|
+
},
|
|
215
|
+
{ capture: true },
|
|
216
|
+
);
|
|
217
|
+
document.currentScript?.remove();
|
|
218
|
+
mediaQuery.addEventListener("change", syncTheme);
|
|
219
|
+
globalThis.addEventListener("click", (event) => {
|
|
220
|
+
if (event.defaultPrevented) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
let element = null;
|
|
224
|
+
if (event.target instanceof globalThis.Element) {
|
|
225
|
+
element = event.target;
|
|
226
|
+
} else if (event.target instanceof globalThis.Node) {
|
|
227
|
+
element = event.target.parentElement;
|
|
228
|
+
}
|
|
229
|
+
const link = element?.closest("a[href]");
|
|
230
|
+
const href = link?.getAttribute("href");
|
|
231
|
+
if (href == null) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (href.startsWith("#")) {
|
|
235
|
+
let id;
|
|
236
|
+
try {
|
|
237
|
+
id = decodeURIComponent(href.slice(1));
|
|
238
|
+
} catch {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const target = id.length === 0 ? root : document.getElementById(id);
|
|
242
|
+
if (target == null || globalThis.navigator.userActivation?.isActive !== true) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
postToHost("scroll-to", {
|
|
247
|
+
top: target.getBoundingClientRect().top + globalThis.scrollY,
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
openExternal({ href });
|
|
253
|
+
});
|
|
254
|
+
new ResizeObserver(sendHeight).observe(document.body);
|
|
255
|
+
syncTheme();
|
|
256
|
+
})();
|