@pie-players/pie-section-player-tools-shared 0.3.43 → 0.3.44

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.
@@ -1,304 +0,0 @@
1
- <script lang="ts">
2
- import { onDestroy, onMount, untrack } from "svelte";
3
- import type { Snippet } from "svelte";
4
- import PanelResizeHandle from "./PanelResizeHandle.svelte";
5
- import PanelWindowControls from "./PanelWindowControls.svelte";
6
- import {
7
- claimNextFloatingPanelZIndex,
8
- computePanelSizeFromViewport,
9
- createFloatingPanelPointerController,
10
- type FloatingPanelViewportSizing,
11
- } from "./floating-panel.js";
12
-
13
- let {
14
- title,
15
- ariaLabel = "Drag panel",
16
- initialSizing,
17
- minWidth = 320,
18
- minHeight = 260,
19
- defaultMinimized = false,
20
- persistenceScope = "",
21
- persistencePanelId = "",
22
- onClose,
23
- className = "",
24
- bodyClass = "",
25
- headerClass = "",
26
- children,
27
- icon,
28
- headerActions,
29
- }: {
30
- title: string;
31
- ariaLabel?: string;
32
- initialSizing: FloatingPanelViewportSizing;
33
- minWidth?: number;
34
- minHeight?: number;
35
- defaultMinimized?: boolean;
36
- persistenceScope?: string;
37
- persistencePanelId?: string;
38
- onClose?: () => void;
39
- className?: string;
40
- bodyClass?: string;
41
- headerClass?: string;
42
- children?: Snippet;
43
- icon?: Snippet;
44
- headerActions?: Snippet;
45
- } = $props();
46
-
47
- let panelX = $state(16);
48
- let panelY = $state(16);
49
- let panelWidth = $state(420);
50
- let panelHeight = $state(480);
51
- let panelZIndex = $state(claimNextFloatingPanelZIndex());
52
- let isMinimized = $state(untrack(() => defaultMinimized));
53
- let hasMounted = $state(false);
54
-
55
- const STORAGE_KEY_PREFIX = "pie:debug-panels:v1";
56
-
57
- const pointerController = createFloatingPanelPointerController({
58
- getState: () => ({
59
- x: panelX,
60
- y: panelY,
61
- width: panelWidth,
62
- height: panelHeight,
63
- }),
64
- setState: (next) => {
65
- panelX = next.x;
66
- panelY = next.y;
67
- panelWidth = next.width;
68
- panelHeight = next.height;
69
- },
70
- minWidth: untrack(() => minWidth),
71
- minHeight: untrack(() => minHeight),
72
- onFocus: () => {
73
- panelZIndex = claimNextFloatingPanelZIndex();
74
- },
75
- });
76
-
77
- function bringToFront(): void {
78
- panelZIndex = claimNextFloatingPanelZIndex();
79
- }
80
-
81
- function getPersistenceKey(): string | null {
82
- const scope = String(persistenceScope || "").trim();
83
- const panelId = String(persistencePanelId || "").trim();
84
- if (!scope || !panelId) return null;
85
- return `${STORAGE_KEY_PREFIX}:${scope}:${panelId}:layout`;
86
- }
87
-
88
- function clampPanelStateToViewport(state: {
89
- x: number;
90
- y: number;
91
- width: number;
92
- height: number;
93
- minimized: boolean;
94
- }): {
95
- x: number;
96
- y: number;
97
- width: number;
98
- height: number;
99
- minimized: boolean;
100
- } {
101
- const viewportWidth = window.innerWidth;
102
- const viewportHeight = window.innerHeight;
103
- const width = Math.max(minWidth, Math.min(viewportWidth, state.width));
104
- const height = Math.max(minHeight, Math.min(viewportHeight, state.height));
105
- const maxX = Math.max(0, viewportWidth - width);
106
- // Keep restore bounds aligned with drag bounds in floating-panel pointer controller.
107
- const maxY = Math.max(0, viewportHeight - 100);
108
- return {
109
- x: Math.max(0, Math.min(maxX, state.x)),
110
- y: Math.max(0, Math.min(maxY, state.y)),
111
- width,
112
- height,
113
- minimized: Boolean(state.minimized),
114
- };
115
- }
116
-
117
- function restorePersistedLayout(): boolean {
118
- const key = getPersistenceKey();
119
- if (!key) return false;
120
- if (typeof localStorage === "undefined") return false;
121
- try {
122
- const raw = localStorage.getItem(key);
123
- if (!raw) return false;
124
- const parsed = JSON.parse(raw) as {
125
- x?: number;
126
- y?: number;
127
- width?: number;
128
- height?: number;
129
- minimized?: boolean;
130
- };
131
- if (
132
- typeof parsed.x !== "number" ||
133
- typeof parsed.y !== "number" ||
134
- typeof parsed.width !== "number" ||
135
- typeof parsed.height !== "number"
136
- ) {
137
- return false;
138
- }
139
- const clamped = clampPanelStateToViewport({
140
- x: parsed.x,
141
- y: parsed.y,
142
- width: parsed.width,
143
- height: parsed.height,
144
- minimized: Boolean(parsed.minimized),
145
- });
146
- panelX = clamped.x;
147
- panelY = clamped.y;
148
- panelWidth = clamped.width;
149
- panelHeight = clamped.height;
150
- isMinimized = clamped.minimized;
151
- return true;
152
- } catch {
153
- return false;
154
- }
155
- }
156
-
157
- onMount(() => {
158
- if (!restorePersistedLayout()) {
159
- const initial = computePanelSizeFromViewport(
160
- { width: window.innerWidth, height: window.innerHeight },
161
- initialSizing,
162
- );
163
- panelX = initial.x;
164
- panelY = initial.y;
165
- panelWidth = initial.width;
166
- panelHeight = initial.height;
167
- }
168
- hasMounted = true;
169
- });
170
-
171
- onDestroy(() => {
172
- pointerController.stop();
173
- });
174
-
175
- const resolvedPanelClass = $derived.by(() =>
176
- ["pie-shared-floating-panel", className || ""].join(" ").trim(),
177
- );
178
- const resolvedBodyClass = $derived.by(() =>
179
- ["pie-shared-floating-panel__body", bodyClass || ""].join(" ").trim(),
180
- );
181
- const resolvedHeaderClass = $derived.by(() =>
182
- ["pie-shared-floating-panel__header", headerClass || ""].join(" ").trim(),
183
- );
184
-
185
- $effect(() => {
186
- if (!hasMounted) return;
187
- const key = getPersistenceKey();
188
- if (!key) return;
189
- if (typeof localStorage === "undefined") return;
190
- try {
191
- localStorage.setItem(
192
- key,
193
- JSON.stringify({
194
- x: panelX,
195
- y: panelY,
196
- width: panelWidth,
197
- height: panelHeight,
198
- minimized: isMinimized,
199
- }),
200
- );
201
- } catch {
202
- // ignore storage write failures
203
- }
204
- });
205
- </script>
206
-
207
- <section
208
- class={resolvedPanelClass}
209
- style={`left: ${panelX}px; top: ${panelY}px; width: ${panelWidth}px; z-index: ${panelZIndex}; ${
210
- isMinimized ? "height: auto;" : `height: ${panelHeight}px;`
211
- }`}
212
- >
213
- <header
214
- class={resolvedHeaderClass}
215
- onmousedown={(event: MouseEvent) => {
216
- bringToFront();
217
- pointerController.startDrag(event);
218
- }}
219
- role="button"
220
- tabindex="0"
221
- aria-label={ariaLabel}
222
- >
223
- <div class="pie-shared-floating-panel__header-main">
224
- <div class="pie-shared-floating-panel__header-title-wrap">
225
- {@render icon?.()}
226
- <h3 class="pie-shared-floating-panel__title">{title}</h3>
227
- </div>
228
- {@render headerActions?.()}
229
- </div>
230
- <div class="pie-shared-floating-panel__header-controls">
231
- <PanelWindowControls
232
- minimized={isMinimized}
233
- onToggle={() => (isMinimized = !isMinimized)}
234
- onClose={onClose}
235
- />
236
- </div>
237
- </header>
238
-
239
- {#if !isMinimized}
240
- <div class={resolvedBodyClass}>
241
- {@render children?.()}
242
- </div>
243
- <PanelResizeHandle onPointerDown={(event: MouseEvent) => pointerController.startResize(event)} />
244
- {/if}
245
- </section>
246
-
247
- <style>
248
- .pie-shared-floating-panel {
249
- position: fixed;
250
- display: flex;
251
- flex-direction: column;
252
- background: var(--color-base-100, #fff);
253
- color: var(--color-base-content, #1f2937);
254
- border: 2px solid var(--color-base-300, #d1d5db);
255
- border-radius: 8px;
256
- box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
257
- overflow: hidden;
258
- font-family: var(--pie-font-family, Inter, system-ui, sans-serif);
259
- }
260
-
261
- .pie-shared-floating-panel__header {
262
- padding: 8px 16px;
263
- display: flex;
264
- align-items: center;
265
- justify-content: space-between;
266
- background: var(--color-base-200, #f3f4f6);
267
- cursor: move;
268
- user-select: none;
269
- border-bottom: 1px solid var(--color-base-300, #d1d5db);
270
- }
271
-
272
- .pie-shared-floating-panel__header-main {
273
- display: flex;
274
- align-items: center;
275
- gap: 8px;
276
- min-width: 0;
277
- flex: 1;
278
- }
279
-
280
- .pie-shared-floating-panel__header-title-wrap {
281
- display: flex;
282
- align-items: center;
283
- gap: 8px;
284
- min-width: 0;
285
- }
286
-
287
- .pie-shared-floating-panel__title {
288
- margin: 0;
289
- font-size: 0.95rem;
290
- font-weight: 700;
291
- }
292
-
293
- .pie-shared-floating-panel__header-controls {
294
- display: flex;
295
- gap: 4px;
296
- }
297
-
298
- .pie-shared-floating-panel__body {
299
- flex: 1;
300
- min-height: 0;
301
- display: flex;
302
- flex-direction: column;
303
- }
304
- </style>
@@ -1 +0,0 @@
1
- {"version":3,"file":"floating-panel.d.ts","sourceRoot":"","sources":["../floating-panel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AASF,wBAAgB,4BAA4B,IAAI,MAAM,CAUrD;AAED,MAAM,MAAM,2BAA2B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,4BAA4B,CAC3C,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC3C,MAAM,EAAE,2BAA2B,GACjC,kBAAkB,CA8BpB;AAED,KAAK,qBAAqB,GAAG;IAC5B,QAAQ,EAAE,MAAM,kBAAkB,CAAC;IACnC,QAAQ,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC5C,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,WAAW,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,IAAI,EAAE,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,qBAAqB,GACzB,8BAA8B,CA+FhC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EACN,oCAAoC,EACpC,4BAA4B,EAC5B,4BAA4B,EAC5B,KAAK,8BAA8B,EACnC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,GAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,mCAAmC,EACnC,yCAAyC,EACzC,gBAAgB,EAChB,KAAK,mCAAmC,EACxC,KAAK,wBAAwB,EAC7B,KAAK,uCAAuC,GAC5C,MAAM,yBAAyB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"section-controller.d.ts","sourceRoot":"","sources":["../section-controller.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IACjD,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IACrC,GAAG,CAAC,EAAE,wBAAwB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,uCAAuC,CAAC,WAAW,IAAI;IAClE,oBAAoB,CAAC,EAAE,CAAC,IAAI,EAAE;QAC7B,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,KAAK,WAAW,GAAG,SAAS,CAAC;IAC9B,4BAA4B,CAAC,EAAE,CAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,mCAAmC,KAAK,IAAI,KAC1D,MAAM,IAAI,CAAC;CAChB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED,wBAAgB,yCAAyC,CACxD,KAAK,EAAE,mCAAmC,EAC1C,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAKT;AAED,wBAAgB,mCAAmC,CAAC,WAAW,EAC9D,WAAW,EACR,uCAAuC,CAAC,WAAW,CAAC,GACpD,IAAI,GACJ,SAAS,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GAChB,WAAW,GAAG,IAAI,CAQpB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite.config.d.ts","sourceRoot":"","sources":["../vite.config.ts"],"names":[],"mappings":";AAKA,wBA8BG"}
package/floating-panel.ts DELETED
@@ -1,187 +0,0 @@
1
- export type FloatingPanelState = {
2
- x: number;
3
- y: number;
4
- width: number;
5
- height: number;
6
- };
7
-
8
- const FLOATING_PANEL_BASE_Z_INDEX = 9999;
9
- const FLOATING_PANEL_Z_INDEX_KEY = "__pieFloatingPanelZIndex";
10
-
11
- type FloatingPanelZIndexGlobal = typeof globalThis & {
12
- [FLOATING_PANEL_Z_INDEX_KEY]?: number;
13
- };
14
-
15
- export function claimNextFloatingPanelZIndex(): number {
16
- const runtime = globalThis as FloatingPanelZIndexGlobal;
17
- const currentValue = runtime[FLOATING_PANEL_Z_INDEX_KEY];
18
- const normalizedCurrent =
19
- typeof currentValue === "number" && Number.isFinite(currentValue)
20
- ? currentValue
21
- : FLOATING_PANEL_BASE_Z_INDEX;
22
- const nextValue = normalizedCurrent + 1;
23
- runtime[FLOATING_PANEL_Z_INDEX_KEY] = nextValue;
24
- return nextValue;
25
- }
26
-
27
- export type FloatingPanelViewportSizing = {
28
- widthRatio: number;
29
- heightRatio: number;
30
- minWidth: number;
31
- maxWidth: number;
32
- minHeight: number;
33
- maxHeight: number;
34
- alignX: "left" | "center" | "right";
35
- alignY: "top" | "center" | "bottom";
36
- paddingX?: number;
37
- paddingY?: number;
38
- };
39
-
40
- export function computePanelSizeFromViewport(
41
- viewport: { width: number; height: number },
42
- sizing: FloatingPanelViewportSizing,
43
- ): FloatingPanelState {
44
- const clamp = (value: number, min: number, max: number) =>
45
- Math.max(min, Math.min(value, max));
46
- const width = clamp(
47
- Math.round(viewport.width * sizing.widthRatio),
48
- sizing.minWidth,
49
- sizing.maxWidth,
50
- );
51
- const height = clamp(
52
- Math.round(viewport.height * sizing.heightRatio),
53
- sizing.minHeight,
54
- sizing.maxHeight,
55
- );
56
- const paddingX = sizing.paddingX ?? 16;
57
- const paddingY = sizing.paddingY ?? 16;
58
- const maxX = Math.max(paddingX, viewport.width - width - paddingX);
59
- const maxY = Math.max(paddingY, viewport.height - height - paddingY);
60
- const x =
61
- sizing.alignX === "left"
62
- ? paddingX
63
- : sizing.alignX === "right"
64
- ? maxX
65
- : Math.max(paddingX, Math.round((viewport.width - width) / 2));
66
- const y =
67
- sizing.alignY === "top"
68
- ? paddingY
69
- : sizing.alignY === "bottom"
70
- ? maxY
71
- : Math.max(paddingY, Math.round((viewport.height - height) / 2));
72
- return { x, y, width, height };
73
- }
74
-
75
- type PointerControllerArgs = {
76
- getState: () => FloatingPanelState;
77
- setState: (next: FloatingPanelState) => void;
78
- minWidth: number;
79
- minHeight: number;
80
- padding?: number;
81
- onFocus?: () => void;
82
- };
83
-
84
- export type FloatingPanelPointerController = {
85
- startDrag: (event: MouseEvent) => void;
86
- startResize: (event: MouseEvent) => void;
87
- stop: () => void;
88
- };
89
-
90
- export function createFloatingPanelPointerController(
91
- args: PointerControllerArgs,
92
- ): FloatingPanelPointerController {
93
- const padding = args.padding ?? 0;
94
- let isDragging = false;
95
- let isResizing = false;
96
- let dragStartX = 0;
97
- let dragStartY = 0;
98
- let dragStartPanelX = 0;
99
- let dragStartPanelY = 0;
100
- let resizeStartX = 0;
101
- let resizeStartY = 0;
102
- let resizeStartWidth = 0;
103
- let resizeStartHeight = 0;
104
-
105
- const onDrag = (event: MouseEvent) => {
106
- if (!isDragging) return;
107
- const state = args.getState();
108
- const deltaX = event.clientX - dragStartX;
109
- const deltaY = event.clientY - dragStartY;
110
- const maxX = Math.max(padding, window.innerWidth - state.width - padding);
111
- const maxY = Math.max(padding, window.innerHeight - 100 - padding);
112
- args.setState({
113
- ...state,
114
- x: Math.max(padding, Math.min(dragStartPanelX + deltaX, maxX)),
115
- y: Math.max(padding, Math.min(dragStartPanelY + deltaY, maxY)),
116
- });
117
- };
118
-
119
- const onResize = (event: MouseEvent) => {
120
- if (!isResizing) return;
121
- const state = args.getState();
122
- const deltaX = event.clientX - resizeStartX;
123
- const deltaY = event.clientY - resizeStartY;
124
- const maxWidth = Math.max(
125
- args.minWidth,
126
- window.innerWidth - state.x - padding,
127
- );
128
- const maxHeight = Math.max(
129
- args.minHeight,
130
- window.innerHeight - state.y - padding,
131
- );
132
- args.setState({
133
- ...state,
134
- width: Math.max(
135
- args.minWidth,
136
- Math.min(resizeStartWidth + deltaX, maxWidth),
137
- ),
138
- height: Math.max(
139
- args.minHeight,
140
- Math.min(resizeStartHeight + deltaY, maxHeight),
141
- ),
142
- });
143
- };
144
-
145
- const stopDrag = () => {
146
- isDragging = false;
147
- document.removeEventListener("mousemove", onDrag);
148
- document.removeEventListener("mouseup", stopDrag);
149
- };
150
-
151
- const stopResize = () => {
152
- isResizing = false;
153
- document.removeEventListener("mousemove", onResize);
154
- document.removeEventListener("mouseup", stopResize);
155
- };
156
-
157
- return {
158
- startDrag(event: MouseEvent) {
159
- args.onFocus?.();
160
- isDragging = true;
161
- dragStartX = event.clientX;
162
- dragStartY = event.clientY;
163
- const state = args.getState();
164
- dragStartPanelX = state.x;
165
- dragStartPanelY = state.y;
166
- document.addEventListener("mousemove", onDrag);
167
- document.addEventListener("mouseup", stopDrag);
168
- },
169
- startResize(event: MouseEvent) {
170
- args.onFocus?.();
171
- isResizing = true;
172
- resizeStartX = event.clientX;
173
- resizeStartY = event.clientY;
174
- const state = args.getState();
175
- resizeStartWidth = state.width;
176
- resizeStartHeight = state.height;
177
- document.addEventListener("mousemove", onResize);
178
- document.addEventListener("mouseup", stopResize);
179
- event.preventDefault();
180
- event.stopPropagation();
181
- },
182
- stop() {
183
- stopDrag();
184
- stopResize();
185
- },
186
- };
187
- }
package/index.ts DELETED
@@ -1,21 +0,0 @@
1
- export { default as PanelWindowControls } from "./PanelWindowControls.svelte";
2
- export { default as PanelResizeHandle } from "./PanelResizeHandle.svelte";
3
- export { default as SharedFloatingPanel } from "./SharedFloatingPanel.svelte";
4
- export { default as SessionDbPanel } from "./SessionDbPanel.svelte";
5
- export { default as DebugPanelToggles } from "./DebugPanelToggles.svelte";
6
- export {
7
- createFloatingPanelPointerController,
8
- computePanelSizeFromViewport,
9
- claimNextFloatingPanelZIndex,
10
- type FloatingPanelPointerController,
11
- type FloatingPanelState,
12
- type FloatingPanelViewportSizing,
13
- } from "./floating-panel.js";
14
- export {
15
- getSectionControllerFromCoordinator,
16
- isMatchingSectionControllerLifecycleEvent,
17
- optionalIdsEqual,
18
- type SectionControllerLifecycleEventLike,
19
- type SectionControllerKeyLike,
20
- type ToolkitCoordinatorWithSectionController,
21
- } from "./section-controller.js";
@@ -1,51 +0,0 @@
1
- export type SectionControllerKeyLike = {
2
- sectionId?: string;
3
- attemptId?: string;
4
- };
5
-
6
- export type SectionControllerLifecycleEventLike = {
7
- type?: "ready" | "disposed" | string;
8
- key?: SectionControllerKeyLike;
9
- };
10
-
11
- export type ToolkitCoordinatorWithSectionController<TController> = {
12
- getSectionController?: (args: {
13
- sectionId: string;
14
- attemptId?: string;
15
- }) => TController | undefined;
16
- onSectionControllerLifecycle?: (
17
- listener: (event: SectionControllerLifecycleEventLike) => void,
18
- ) => () => void;
19
- };
20
-
21
- export function optionalIdsEqual(left?: string, right?: string): boolean {
22
- return (left || undefined) === (right || undefined);
23
- }
24
-
25
- export function isMatchingSectionControllerLifecycleEvent(
26
- event: SectionControllerLifecycleEventLike,
27
- sectionId: string,
28
- attemptId?: string,
29
- ): boolean {
30
- const eventSectionId = event?.key?.sectionId || "";
31
- const eventAttemptId = event?.key?.attemptId || undefined;
32
- if (eventSectionId !== sectionId) return false;
33
- return optionalIdsEqual(eventAttemptId, attemptId);
34
- }
35
-
36
- export function getSectionControllerFromCoordinator<TController>(
37
- coordinator:
38
- | ToolkitCoordinatorWithSectionController<TController>
39
- | null
40
- | undefined,
41
- sectionId: string,
42
- attemptId?: string,
43
- ): TController | null {
44
- if (!coordinator?.getSectionController || !sectionId) return null;
45
- return (
46
- coordinator.getSectionController({
47
- sectionId,
48
- attemptId,
49
- }) || null
50
- );
51
- }
package/vite.config.ts DELETED
@@ -1,36 +0,0 @@
1
- import { svelte } from "@sveltejs/vite-plugin-svelte";
2
- import { resolve } from "path";
3
- import { defineConfig } from "vite";
4
- import dts from "vite-plugin-dts";
5
-
6
- export default defineConfig({
7
- plugins: [
8
- svelte({
9
- emitCss: false,
10
- }),
11
- dts({
12
- tsconfigPath: resolve(__dirname, "tsconfig.json"),
13
- outDir: "dist",
14
- insertTypesEntry: true,
15
- include: ["**/*.ts", "**/*.svelte"],
16
- }),
17
- ],
18
- build: {
19
- lib: {
20
- entry: resolve(__dirname, "index.ts"),
21
- name: "PieSectionPlayerToolsShared",
22
- fileName: () => "index.js",
23
- formats: ["es"],
24
- },
25
- outDir: "dist",
26
- emptyOutDir: true,
27
- target: "es2020",
28
- minify: "esbuild",
29
- sourcemap: false,
30
- rollupOptions: {
31
- output: {
32
- format: "es",
33
- },
34
- },
35
- },
36
- });