@pie-lib/delivery-events-svelte 0.1.1-next.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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @pie-lib/delivery-events-svelte
3
+ *
4
+ * Shared host/session bridge utilities for Svelte delivery custom elements.
5
+ */
6
+ export * from './session-bridge.js';
7
+ export { ModelSetEvent, SessionChangedEvent } from '@pie-element/shared-player-events';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { ModelSetEvent as e, SessionChangedEvent as t } from "./index2.js";
2
+ import { forwardSessionChange as n, resolveDeliveryHost as r, writeSessionInPlace as i } from "./index3.js";
3
+ export { e as ModelSetEvent, t as SessionChangedEvent, n as forwardSessionChange, r as resolveDeliveryHost, i as writeSessionInPlace };
package/dist/index2.js ADDED
@@ -0,0 +1,33 @@
1
+ //#region ../../shared/player-events/dist/index.js
2
+ var e = class e extends CustomEvent {
3
+ static {
4
+ this.TYPE = "model-set";
5
+ }
6
+ constructor(t, n, r) {
7
+ super(e.TYPE, {
8
+ bubbles: !0,
9
+ composed: !0,
10
+ detail: {
11
+ complete: n,
12
+ component: t,
13
+ hasModel: r
14
+ }
15
+ }), this.component = t, this.complete = n;
16
+ }
17
+ }, t = class e extends CustomEvent {
18
+ static {
19
+ this.TYPE = "session-changed";
20
+ }
21
+ constructor(t, n) {
22
+ super(e.TYPE, {
23
+ bubbles: !0,
24
+ composed: !0,
25
+ detail: {
26
+ complete: n,
27
+ component: t
28
+ }
29
+ }), this.component = t, this.complete = n;
30
+ }
31
+ };
32
+ //#endregion
33
+ export { e as ModelSetEvent, t as SessionChangedEvent };
package/dist/index3.js ADDED
@@ -0,0 +1,38 @@
1
+ import { SessionChangedEvent as e } from "./index2.js";
2
+ //#region src/session-bridge.ts
3
+ var t = (e) => {
4
+ let t = e;
5
+ return t ? typeof t.onSessionChange == "function" || typeof t.onAudioStarted == "function" || typeof t.onAudioEnded == "function" : !1;
6
+ };
7
+ function n(e, n = {}) {
8
+ let r = n.hostPredicate ?? t, i = e;
9
+ for (; i;) {
10
+ if (r(i)) return i;
11
+ i = i.parentElement;
12
+ }
13
+ if (typeof document < "u" && n.fallbackSelector) {
14
+ let e = document.querySelector(n.fallbackSelector);
15
+ if (r(e)) return e;
16
+ }
17
+ return null;
18
+ }
19
+ function r(e) {
20
+ return !!e && typeof e == "object" && !Array.isArray(e);
21
+ }
22
+ function i(e, t) {
23
+ if (e === t) return e;
24
+ if (!r(e) || !r(t) || Object.isFrozen(e) || !Object.isExtensible(e)) return t;
25
+ try {
26
+ for (let n of Object.keys(e)) n in t || delete e[n];
27
+ Object.assign(e, t);
28
+ } catch {
29
+ return t;
30
+ }
31
+ return e;
32
+ }
33
+ function a({ sourceEl: t, fallbackSelector: r, component: i, complete: a, session: o }) {
34
+ let s = n(t, { fallbackSelector: r });
35
+ return s ? typeof s.onSessionChange == "function" ? (s.onSessionChange(o), s) : (s.dispatchEvent(new e(i, a)), s) : null;
36
+ }
37
+ //#endregion
38
+ export { a as forwardSessionChange, n as resolveDeliveryHost, i as writeSessionInPlace };
@@ -0,0 +1,52 @@
1
+ export type DeliveryHostElement = HTMLElement & {
2
+ session?: unknown;
3
+ onSessionChange?: (session: unknown) => void;
4
+ onAudioStarted?: () => void;
5
+ onAudioEnded?: () => void;
6
+ };
7
+ type HostPredicate = (node: unknown) => boolean;
8
+ export interface ResolveDeliveryHostOptions {
9
+ fallbackSelector?: string;
10
+ hostPredicate?: HostPredicate;
11
+ }
12
+ /**
13
+ * Walk up the DOM from a source element and find the nearest delivery host wrapper.
14
+ * Falls back to selector lookup to support detached nested render roots.
15
+ */
16
+ export declare function resolveDeliveryHost(sourceEl?: HTMLElement | null, options?: ResolveDeliveryHostOptions): DeliveryHostElement | null;
17
+ /**
18
+ * Assign a delivery update into the session object the player owns, keeping the
19
+ * reference.
20
+ *
21
+ * A player hands the element a session object and reads the learner's response
22
+ * back off that same object: `pie-player` pushes its entry into the host's own
23
+ * `session.data` array, and `pie-item-player`'s renderer forwards the array it
24
+ * holds rather than `element.session`. An element that only replaces its own
25
+ * reference leaves the player's entry at its load-time value, so the forwarded
26
+ * container compares equal to the previous one and normalizes to
27
+ * `intent: "metadata-only"` with `session: null` - the element reports a change
28
+ * and the response never arrives. The React elements mutate the session they
29
+ * were given (`updateSessionValue`); this is that contract for the Svelte
30
+ * elements, which additionally hand their component a fresh reference so
31
+ * `$derived` reads of `props.session` still re-run.
32
+ *
33
+ * Keys absent from `next` are removed, so clearing a response clears it on the
34
+ * player's object too. Anything that is not a plain object on both sides is
35
+ * returned as the replacement it already was, and so is a frozen or sealed
36
+ * target: writing into one throws in strict mode, which would take the
37
+ * learner's update with it before the element ever stored it.
38
+ */
39
+ export declare function writeSessionInPlace(target: unknown, next: unknown): unknown;
40
+ export interface ForwardSessionChangeOptions {
41
+ sourceEl?: HTMLElement | null;
42
+ fallbackSelector?: string;
43
+ component: string;
44
+ complete: boolean;
45
+ session: unknown;
46
+ }
47
+ /**
48
+ * Forward a delivery session update using the host callback when available.
49
+ * If no callback is exposed, dispatch the canonical session-changed metadata event.
50
+ */
51
+ export declare function forwardSessionChange({ sourceEl, fallbackSelector, component, complete, session, }: ForwardSessionChangeOptions): DeliveryHostElement | null;
52
+ export {};
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@pie-lib/delivery-events-svelte",
3
+ "version": "0.1.1-next.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/pie-framework/pie-elements-ng.git",
7
+ "directory": "packages/lib-svelte/delivery-events"
8
+ },
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "vite build && tsc --emitDeclarationOnly",
23
+ "dev": "vite build --watch"
24
+ },
25
+ "dependencies": {
26
+ "@pie-element/shared-player-events": "0.1.1-next.0"
27
+ }
28
+ }