@neobyzantine/series-player 0.2.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/dist/index.js ADDED
@@ -0,0 +1,732 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AnimatedEventMap: () => AnimatedEventMap,
34
+ AnimatorControls: () => AnimatorControls,
35
+ EventAnimator: () => EventAnimator,
36
+ SeriesEventPanel: () => SeriesEventPanel,
37
+ SeriesPlayer: () => SeriesPlayer,
38
+ SeriesStepList: () => SeriesStepList,
39
+ useSeriesPlayer: () => useSeriesPlayer
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/SeriesPlayer.tsx
44
+ var import_react3 = require("react");
45
+
46
+ // src/useSeriesPlayer.ts
47
+ var import_react = require("react");
48
+ function useSeriesPlayer(entries, onEventLoad, opts) {
49
+ const [currentIndex, setCurrentIndex] = (0, import_react.useState)(0);
50
+ const [event, setEvent] = (0, import_react.useState)(null);
51
+ const [loading, setLoading] = (0, import_react.useState)(false);
52
+ const [error, setError] = (0, import_react.useState)(null);
53
+ const [jumpHistory, setJumpHistory] = (0, import_react.useState)([]);
54
+ const [autoPlaying, setAutoPlaying] = (0, import_react.useState)(false);
55
+ const autoTimerRef = (0, import_react.useRef)(null);
56
+ const loadingSlugRef = (0, import_react.useRef)(null);
57
+ const onEventChangeRef = (0, import_react.useRef)(opts?.onEventChange);
58
+ onEventChangeRef.current = opts?.onEventChange;
59
+ const autoPlayIntervalRef = (0, import_react.useRef)(opts?.autoPlayInterval ?? 12e3);
60
+ autoPlayIntervalRef.current = opts?.autoPlayInterval ?? 12e3;
61
+ const clearAutoTimer = (0, import_react.useCallback)(() => {
62
+ if (autoTimerRef.current) {
63
+ clearTimeout(autoTimerRef.current);
64
+ autoTimerRef.current = null;
65
+ }
66
+ }, []);
67
+ const loadSlug = (0, import_react.useCallback)(
68
+ async (slug, index) => {
69
+ loadingSlugRef.current = slug;
70
+ clearAutoTimer();
71
+ setLoading(true);
72
+ setError(null);
73
+ try {
74
+ const ev = await onEventLoad(slug);
75
+ if (loadingSlugRef.current !== slug) return;
76
+ setEvent(ev);
77
+ if (index >= 0) onEventChangeRef.current?.(index, ev);
78
+ } catch (err) {
79
+ if (loadingSlugRef.current === slug) {
80
+ setError(err instanceof Error ? err.message : "Failed to load event");
81
+ }
82
+ } finally {
83
+ if (loadingSlugRef.current === slug) setLoading(false);
84
+ }
85
+ },
86
+ [onEventLoad, clearAutoTimer]
87
+ );
88
+ (0, import_react.useEffect)(() => {
89
+ const entry = entries[0];
90
+ if (entry) void loadSlug(entry.slug, 0);
91
+ }, []);
92
+ const loadAtIndex = (0, import_react.useCallback)(
93
+ (index) => {
94
+ const entry = entries[index];
95
+ if (entry) void loadSlug(entry.slug, index);
96
+ },
97
+ [entries, loadSlug]
98
+ );
99
+ const next = (0, import_react.useCallback)(() => {
100
+ setCurrentIndex((prev2) => {
101
+ if (prev2 >= entries.length - 1) {
102
+ setAutoPlaying(false);
103
+ clearAutoTimer();
104
+ return prev2;
105
+ }
106
+ const next2 = prev2 + 1;
107
+ setJumpHistory([]);
108
+ loadAtIndex(next2);
109
+ return next2;
110
+ });
111
+ }, [entries.length, loadAtIndex, clearAutoTimer]);
112
+ const prev = (0, import_react.useCallback)(() => {
113
+ setJumpHistory((hist) => {
114
+ if (hist.length > 0) {
115
+ const restored = hist[hist.length - 1];
116
+ const newHist = hist.slice(0, -1);
117
+ setCurrentIndex(restored);
118
+ loadAtIndex(restored);
119
+ return newHist;
120
+ }
121
+ setCurrentIndex((idx) => {
122
+ if (idx <= 0) return idx;
123
+ const newIdx = idx - 1;
124
+ loadAtIndex(newIdx);
125
+ return newIdx;
126
+ });
127
+ return hist;
128
+ });
129
+ }, [loadAtIndex]);
130
+ const goTo = (0, import_react.useCallback)(
131
+ (index) => {
132
+ if (index < 0 || index >= entries.length) return;
133
+ setJumpHistory([]);
134
+ setAutoPlaying(false);
135
+ clearAutoTimer();
136
+ setCurrentIndex(index);
137
+ loadAtIndex(index);
138
+ },
139
+ [entries.length, loadAtIndex, clearAutoTimer]
140
+ );
141
+ const jumpToRelated = (0, import_react.useCallback)(
142
+ (slug) => {
143
+ setJumpHistory((hist) => [...hist, currentIndex]);
144
+ loadingSlugRef.current = slug;
145
+ clearAutoTimer();
146
+ setLoading(true);
147
+ setError(null);
148
+ onEventLoad(slug).then((ev) => {
149
+ if (loadingSlugRef.current !== slug) return;
150
+ setEvent(ev);
151
+ setLoading(false);
152
+ }).catch((err) => {
153
+ if (loadingSlugRef.current === slug) {
154
+ setError(err instanceof Error ? err.message : "Failed to load event");
155
+ setLoading(false);
156
+ }
157
+ });
158
+ },
159
+ [currentIndex, onEventLoad, clearAutoTimer]
160
+ );
161
+ const backFromJump = (0, import_react.useCallback)(() => {
162
+ setJumpHistory((hist) => {
163
+ if (!hist.length) return hist;
164
+ const restored = hist[hist.length - 1];
165
+ const newHist = hist.slice(0, -1);
166
+ setCurrentIndex(restored);
167
+ loadAtIndex(restored);
168
+ return newHist;
169
+ });
170
+ }, [loadAtIndex]);
171
+ const toggleAutoPlay = (0, import_react.useCallback)(() => {
172
+ setAutoPlaying((prev2) => {
173
+ if (prev2) {
174
+ clearAutoTimer();
175
+ return false;
176
+ }
177
+ autoTimerRef.current = setTimeout(() => {
178
+ next();
179
+ }, autoPlayIntervalRef.current);
180
+ return true;
181
+ });
182
+ }, [clearAutoTimer, next]);
183
+ return [
184
+ { currentIndex, event, loading, error, jumpHistory, autoPlaying },
185
+ { next, prev, goTo, jumpToRelated, backFromJump, toggleAutoPlay }
186
+ ];
187
+ }
188
+
189
+ // src/SeriesStepList.tsx
190
+ var import_jsx_runtime = require("react/jsx-runtime");
191
+ function SeriesStepList({ entries, currentIndex, jumpHistory, onSelect }) {
192
+ const isJumped = jumpHistory.length > 0;
193
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ol", { className: "nb-sp-steps", children: entries.map((entry, i) => {
194
+ const isActive = !isJumped && i === currentIndex;
195
+ const isDone = !isJumped && i < currentIndex;
196
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
197
+ "li",
198
+ {
199
+ className: `nb-sp-step${isActive ? " nb-sp-step--active" : ""}${isDone ? " nb-sp-step--done" : ""}`,
200
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
201
+ "button",
202
+ {
203
+ type: "button",
204
+ className: "nb-sp-step-btn",
205
+ onClick: () => onSelect(i),
206
+ "aria-current": isActive ? "step" : void 0,
207
+ children: [
208
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nb-sp-step-num", children: i + 1 }),
209
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "nb-sp-step-body", children: [
210
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nb-sp-step-title", children: entry.title }),
211
+ entry.date_display && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nb-sp-step-date", children: entry.date_display })
212
+ ] })
213
+ ]
214
+ }
215
+ )
216
+ },
217
+ entry.slug
218
+ );
219
+ }) });
220
+ }
221
+
222
+ // src/AnimatorControls.tsx
223
+ var import_jsx_runtime2 = require("react/jsx-runtime");
224
+ function AnimatorControls({
225
+ playing,
226
+ current,
227
+ total,
228
+ currentStep,
229
+ accentColor = "#CFB53B",
230
+ onPlay,
231
+ onPause,
232
+ onReset,
233
+ onStepForward,
234
+ onStepBack
235
+ }) {
236
+ if (total === 0) return null;
237
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "nb-sp-anim-controls", children: [
238
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "nb-sp-anim-btns", children: [
239
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
240
+ "button",
241
+ {
242
+ type: "button",
243
+ className: "nb-sp-anim-btn",
244
+ onClick: onReset,
245
+ title: "Reset animation",
246
+ disabled: current < 0,
247
+ children: "\u23EE"
248
+ }
249
+ ),
250
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
251
+ "button",
252
+ {
253
+ type: "button",
254
+ className: "nb-sp-anim-btn",
255
+ onClick: onStepBack,
256
+ title: "Step back",
257
+ disabled: current <= 0,
258
+ children: "\u23EA"
259
+ }
260
+ ),
261
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
262
+ "button",
263
+ {
264
+ type: "button",
265
+ className: `nb-sp-anim-btn nb-sp-anim-btn--play${playing ? " nb-sp-anim-btn--active" : ""}`,
266
+ onClick: playing ? onPause : onPlay,
267
+ style: { borderColor: `${accentColor}66`, color: accentColor },
268
+ children: playing ? "\u23F8" : "\u25B6"
269
+ }
270
+ ),
271
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
272
+ "button",
273
+ {
274
+ type: "button",
275
+ className: "nb-sp-anim-btn",
276
+ onClick: onStepForward,
277
+ title: "Step forward",
278
+ disabled: current >= total - 1,
279
+ children: "\u23E9"
280
+ }
281
+ ),
282
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "nb-sp-anim-counter", children: current < 0 ? `0 / ${total}` : `${current + 1} / ${total}` })
283
+ ] }),
284
+ currentStep && (currentStep.label || currentStep.narration) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "nb-sp-anim-narration", children: [
285
+ currentStep.label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "nb-sp-anim-label", style: { color: accentColor }, children: currentStep.label }),
286
+ currentStep.narration && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "nb-sp-anim-text", children: currentStep.narration })
287
+ ] })
288
+ ] });
289
+ }
290
+
291
+ // src/AnimatedEventMap.tsx
292
+ var import_react2 = require("react");
293
+ var import_react_leaflet = require("react-leaflet");
294
+
295
+ // src/EventAnimator.ts
296
+ var import_leaflet = __toESM(require("leaflet"));
297
+ var EventAnimator = class {
298
+ constructor(map, geojson, color, options) {
299
+ this.current = -1;
300
+ this.playing = false;
301
+ this.timer = null;
302
+ this.pulseMarker = null;
303
+ this.listeners = /* @__PURE__ */ new Map();
304
+ this.map = map;
305
+ this.color = color;
306
+ this.stepMs = options?.stepMs ?? 7500;
307
+ this.ttsEnabled = options?.ttsEnabled ?? false;
308
+ this.steps = (geojson.features ?? []).filter((f) => f.properties.sort_order != null && f.geometry?.type === "Point").sort((a, b) => a.properties.sort_order - b.properties.sort_order);
309
+ }
310
+ get total() {
311
+ return this.steps.length;
312
+ }
313
+ on(event, fn) {
314
+ if (!this.listeners.has(event)) this.listeners.set(event, []);
315
+ this.listeners.get(event).push(fn);
316
+ return this;
317
+ }
318
+ emit(event, data) {
319
+ this.listeners.get(event)?.forEach((fn) => fn(data));
320
+ }
321
+ play() {
322
+ if (this.playing || this.total === 0) return;
323
+ this.playing = true;
324
+ this.emit("play");
325
+ if (this.current < 0) {
326
+ this.goto(0);
327
+ } else {
328
+ this.schedule();
329
+ }
330
+ }
331
+ pause() {
332
+ if (!this.playing) return;
333
+ this.playing = false;
334
+ if (this.timer) {
335
+ clearTimeout(this.timer);
336
+ this.timer = null;
337
+ }
338
+ window.speechSynthesis?.cancel();
339
+ this.emit("pause");
340
+ }
341
+ reset() {
342
+ this.pause();
343
+ this.current = -1;
344
+ this.clearPulse();
345
+ window.speechSynthesis?.cancel();
346
+ this.emit("reset");
347
+ }
348
+ stepForward() {
349
+ this.pause();
350
+ if (this.current + 1 < this.total) this.goto(this.current + 1);
351
+ }
352
+ stepBack() {
353
+ this.pause();
354
+ if (this.current - 1 >= 0) this.goto(this.current - 1);
355
+ }
356
+ setTTS(enabled) {
357
+ this.ttsEnabled = enabled;
358
+ if (!enabled) window.speechSynthesis?.cancel();
359
+ }
360
+ goto(index) {
361
+ if (index < 0 || index >= this.total) return;
362
+ this.current = index;
363
+ const feat = this.steps[index];
364
+ const props = feat.properties;
365
+ const [lng, lat] = feat.geometry.coordinates;
366
+ this.map.flyTo([lat, lng], props.zoom ?? 8, { duration: 1.4, easeLinearity: 0.4 });
367
+ this.clearPulse();
368
+ this.pulseMarker = import_leaflet.default.marker([lat, lng], {
369
+ icon: import_leaflet.default.divIcon({
370
+ className: "",
371
+ html: `<div class="nb-anim-pulse" style="--anim-color:${this.color}"></div>`,
372
+ iconSize: [48, 48],
373
+ iconAnchor: [24, 24]
374
+ }),
375
+ zIndexOffset: 1e3,
376
+ interactive: false
377
+ }).addTo(this.map);
378
+ if (this.ttsEnabled) this.speak(props.narration ?? props.label ?? "");
379
+ this.emit("step", { index, total: this.total, props });
380
+ if (this.playing) this.schedule();
381
+ }
382
+ schedule() {
383
+ const props = this.steps[this.current]?.properties;
384
+ const delay = props?.animation_pause_ms ?? this.stepMs;
385
+ this.timer = setTimeout(() => {
386
+ if (this.current + 1 >= this.total) {
387
+ this.playing = false;
388
+ window.speechSynthesis?.cancel();
389
+ this.emit("complete");
390
+ } else {
391
+ this.goto(this.current + 1);
392
+ }
393
+ }, delay);
394
+ }
395
+ clearPulse() {
396
+ if (this.pulseMarker) {
397
+ this.map.removeLayer(this.pulseMarker);
398
+ this.pulseMarker = null;
399
+ }
400
+ }
401
+ speak(text) {
402
+ const ss = window.speechSynthesis;
403
+ if (!ss || !text) return;
404
+ ss.cancel();
405
+ setTimeout(() => {
406
+ if (ss.paused) ss.resume();
407
+ const u = new SpeechSynthesisUtterance(text);
408
+ u.lang = "en-GB";
409
+ u.rate = 0.7;
410
+ u.pitch = 0.95;
411
+ u.volume = 1;
412
+ ss.speak(u);
413
+ }, 80);
414
+ }
415
+ };
416
+
417
+ // src/AnimatedEventMap.tsx
418
+ var import_jsx_runtime3 = require("react/jsx-runtime");
419
+ function AnimatorDriver({ geojson, color, stepMs, ttsEnabled, onAnimatorReady, onStep, onComplete }) {
420
+ const map = (0, import_react_leaflet.useMap)();
421
+ const animatorRef = (0, import_react2.useRef)(null);
422
+ (0, import_react2.useEffect)(() => {
423
+ const animator = new EventAnimator(map, geojson, color, { stepMs, ttsEnabled });
424
+ if (onStep) animator.on("step", onStep);
425
+ if (onComplete) animator.on("complete", onComplete);
426
+ animatorRef.current = animator;
427
+ onAnimatorReady?.(animator);
428
+ return () => {
429
+ animator.reset();
430
+ animatorRef.current = null;
431
+ };
432
+ }, [geojson, color, stepMs, ttsEnabled]);
433
+ return null;
434
+ }
435
+ function AnimatedEventMap({
436
+ geojson,
437
+ color = "#CFB53B",
438
+ stepMs = 7500,
439
+ ttsEnabled = false,
440
+ onAnimatorReady,
441
+ onStep,
442
+ onComplete,
443
+ center = [41, 29],
444
+ // Constantinople
445
+ zoom = 5,
446
+ height = "400px",
447
+ className
448
+ }) {
449
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `nb-sp-map-wrap${className ? ` ${className}` : ""}`, style: { height }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
450
+ import_react_leaflet.MapContainer,
451
+ {
452
+ center,
453
+ zoom,
454
+ style: { height: "100%", width: "100%" },
455
+ zoomControl: true,
456
+ scrollWheelZoom: false,
457
+ children: [
458
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
459
+ import_react_leaflet.TileLayer,
460
+ {
461
+ url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
462
+ attribution: '\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
463
+ maxZoom: 18
464
+ }
465
+ ),
466
+ geojson && geojson.features.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
467
+ AnimatorDriver,
468
+ {
469
+ geojson,
470
+ color,
471
+ stepMs,
472
+ ttsEnabled,
473
+ onAnimatorReady,
474
+ onStep,
475
+ onComplete
476
+ }
477
+ )
478
+ ]
479
+ }
480
+ ) });
481
+ }
482
+
483
+ // src/SeriesEventPanel.tsx
484
+ var import_actor = require("@neobyzantine/actor");
485
+ var import_jsx_runtime4 = require("react/jsx-runtime");
486
+ function defaultSanitize(html) {
487
+ return html.replace(/<[^>]*>/g, "");
488
+ }
489
+ function SeriesEventPanel({
490
+ event,
491
+ loading,
492
+ error,
493
+ accentColor = "#CFB53B",
494
+ resolvePortrait,
495
+ sanitizeHtml = defaultSanitize,
496
+ onActorClick,
497
+ onRelatedClick,
498
+ className
499
+ }) {
500
+ if (loading) {
501
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `nb-sp-panel nb-sp-panel--loading${className ? ` ${className}` : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "nb-sp-panel-spinner" }) });
502
+ }
503
+ if (error) {
504
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `nb-sp-panel nb-sp-panel--error${className ? ` ${className}` : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "nb-sp-panel-error", children: error }) });
505
+ }
506
+ if (!event) return null;
507
+ const hasActors = (event.actors?.length ?? 0) > 0;
508
+ const hasGallery = (event.gallery_images?.length ?? 0) > 0;
509
+ const hasRelations = (event.relations?.length ?? 0) > 0;
510
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { className: `nb-sp-panel${className ? ` ${className}` : ""}`, children: [
511
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "nb-sp-panel-header", children: [
512
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "nb-sp-panel-title", style: { color: accentColor }, children: event.title }),
513
+ event.date_display && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "nb-sp-panel-date", children: event.date_display })
514
+ ] }),
515
+ event.description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
516
+ "div",
517
+ {
518
+ className: "nb-sp-panel-body",
519
+ dangerouslySetInnerHTML: { __html: sanitizeHtml(event.description) }
520
+ }
521
+ ),
522
+ hasActors && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "nb-sp-panel-section", children: [
523
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h3", { className: "nb-sp-panel-section-title", children: "Key Figures" }),
524
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
525
+ import_actor.ActorGrid,
526
+ {
527
+ actors: event.actors,
528
+ resolvePortrait,
529
+ onActorClick,
530
+ columns: 2,
531
+ compact: true
532
+ }
533
+ )
534
+ ] }),
535
+ hasGallery && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "nb-sp-panel-section", children: [
536
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h3", { className: "nb-sp-panel-section-title", children: "Gallery" }),
537
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "nb-sp-panel-gallery", children: event.gallery_images.map((src, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
538
+ "img",
539
+ {
540
+ src,
541
+ alt: "",
542
+ className: "nb-sp-panel-gallery-img",
543
+ loading: "lazy"
544
+ },
545
+ i
546
+ )) })
547
+ ] }),
548
+ hasRelations && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "nb-sp-panel-section", children: [
549
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h3", { className: "nb-sp-panel-section-title", children: "Related Events" }),
550
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "nb-sp-panel-relations", children: event.relations.map((rel) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { className: `nb-sp-panel-rel nb-sp-panel-rel--${rel.type}`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
551
+ "button",
552
+ {
553
+ type: "button",
554
+ className: "nb-sp-panel-rel-btn",
555
+ onClick: () => onRelatedClick?.(rel.slug),
556
+ children: [
557
+ rel.title,
558
+ rel.date && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "nb-sp-panel-rel-date", children: [
559
+ " (",
560
+ rel.date,
561
+ ")"
562
+ ] })
563
+ ]
564
+ }
565
+ ) }, rel.slug)) })
566
+ ] })
567
+ ] });
568
+ }
569
+
570
+ // src/SeriesPlayer.tsx
571
+ var import_jsx_runtime5 = require("react/jsx-runtime");
572
+ function SeriesPlayer({
573
+ entries,
574
+ onEventLoad,
575
+ accentColor,
576
+ ttsEnabled = false,
577
+ autoPlayInterval = 12e3,
578
+ resolvePortrait,
579
+ sanitizeHtml,
580
+ onEventChange,
581
+ height = "600px",
582
+ className
583
+ }) {
584
+ const [animatorState, setAnimatorState] = (0, import_react3.useState)({ playing: false, current: -1, currentProps: null });
585
+ const animatorRef = (0, import_react3.useRef)(null);
586
+ const [state, actions] = useSeriesPlayer(entries, onEventLoad, {
587
+ onEventChange,
588
+ autoPlayInterval
589
+ });
590
+ const currentEntry = entries[state.currentIndex];
591
+ const resolvedColor = accentColor ?? currentEntry?.color ?? "#CFB53B";
592
+ const geojson = state.event?.locations ? {
593
+ type: "FeatureCollection",
594
+ features: state.event.locations.map((loc) => ({
595
+ type: "Feature",
596
+ geometry: { type: "Point", coordinates: [loc.lng, loc.lat] },
597
+ properties: {
598
+ sort_order: loc.sort_order,
599
+ label: loc.label,
600
+ narration: loc.narration_text,
601
+ zoom: void 0,
602
+ animation_pause_ms: void 0
603
+ }
604
+ }))
605
+ } : null;
606
+ const handleAnimatorReady = (0, import_react3.useCallback)((animator) => {
607
+ animatorRef.current = animator;
608
+ setAnimatorState({ playing: false, current: -1, currentProps: null });
609
+ }, []);
610
+ const handleStep = (0, import_react3.useCallback)((data) => {
611
+ setAnimatorState((prev) => ({ ...prev, current: data.index, currentProps: data.props }));
612
+ }, []);
613
+ const handleComplete = (0, import_react3.useCallback)(() => {
614
+ setAnimatorState((prev) => ({ ...prev, playing: false }));
615
+ }, []);
616
+ const handlePlay = (0, import_react3.useCallback)(() => {
617
+ animatorRef.current?.play();
618
+ setAnimatorState((prev) => ({ ...prev, playing: true }));
619
+ }, []);
620
+ const handlePause = (0, import_react3.useCallback)(() => {
621
+ animatorRef.current?.pause();
622
+ setAnimatorState((prev) => ({ ...prev, playing: false }));
623
+ }, []);
624
+ const handleReset = (0, import_react3.useCallback)(() => {
625
+ animatorRef.current?.reset();
626
+ setAnimatorState({ playing: false, current: -1, currentProps: null });
627
+ }, []);
628
+ const handleStepForward = (0, import_react3.useCallback)(() => {
629
+ animatorRef.current?.stepForward();
630
+ }, []);
631
+ const handleStepBack = (0, import_react3.useCallback)(() => {
632
+ animatorRef.current?.stepBack();
633
+ }, []);
634
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
635
+ "div",
636
+ {
637
+ className: `nb-sp-root${className ? ` ${className}` : ""}`,
638
+ style: { "--nb-sp-accent": resolvedColor },
639
+ children: [
640
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("aside", { className: "nb-sp-sidebar", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
641
+ SeriesStepList,
642
+ {
643
+ entries,
644
+ currentIndex: state.currentIndex,
645
+ jumpHistory: state.jumpHistory,
646
+ onSelect: actions.goTo
647
+ }
648
+ ) }),
649
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("main", { className: "nb-sp-main", style: { height }, children: [
650
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
651
+ AnimatedEventMap,
652
+ {
653
+ geojson,
654
+ color: resolvedColor,
655
+ ttsEnabled,
656
+ onAnimatorReady: handleAnimatorReady,
657
+ onStep: handleStep,
658
+ onComplete: handleComplete,
659
+ height: "100%",
660
+ className: "nb-sp-map"
661
+ }
662
+ ),
663
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
664
+ AnimatorControls,
665
+ {
666
+ playing: animatorState.playing,
667
+ current: animatorState.current,
668
+ total: geojson?.features.length ?? 0,
669
+ currentStep: animatorState.currentProps,
670
+ accentColor: resolvedColor,
671
+ onPlay: handlePlay,
672
+ onPause: handlePause,
673
+ onReset: handleReset,
674
+ onStepForward: handleStepForward,
675
+ onStepBack: handleStepBack
676
+ }
677
+ ),
678
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "nb-sp-nav-row", children: [
679
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
680
+ "button",
681
+ {
682
+ type: "button",
683
+ className: "nb-sp-nav-btn",
684
+ onClick: actions.prev,
685
+ disabled: state.currentIndex === 0 && state.jumpHistory.length === 0,
686
+ children: "\u2190 Previous"
687
+ }
688
+ ),
689
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "nb-sp-nav-label", children: [
690
+ state.currentIndex + 1,
691
+ " / ",
692
+ entries.length
693
+ ] }),
694
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
695
+ "button",
696
+ {
697
+ type: "button",
698
+ className: "nb-sp-nav-btn",
699
+ onClick: actions.next,
700
+ disabled: state.currentIndex >= entries.length - 1,
701
+ children: "Next \u2192"
702
+ }
703
+ )
704
+ ] })
705
+ ] }),
706
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("aside", { className: "nb-sp-detail", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
707
+ SeriesEventPanel,
708
+ {
709
+ event: state.event,
710
+ loading: state.loading,
711
+ error: state.error,
712
+ accentColor: resolvedColor,
713
+ resolvePortrait,
714
+ sanitizeHtml,
715
+ onRelatedClick: actions.jumpToRelated
716
+ }
717
+ ) })
718
+ ]
719
+ }
720
+ );
721
+ }
722
+ // Annotate the CommonJS export names for ESM import in node:
723
+ 0 && (module.exports = {
724
+ AnimatedEventMap,
725
+ AnimatorControls,
726
+ EventAnimator,
727
+ SeriesEventPanel,
728
+ SeriesPlayer,
729
+ SeriesStepList,
730
+ useSeriesPlayer
731
+ });
732
+ //# sourceMappingURL=index.js.map