@pie-lib/delivery-events-svelte 0.1.1-next.0 → 0.1.1-next.1
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 +3 -3
- package/dist/index2.js +47 -30
- package/dist/session-bridge.d.ts +12 -6
- package/package.json +1 -1
- package/dist/index3.js +0 -38
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
1
|
+
import { forwardSessionChange as e, resolveDeliveryHost as t, writeSessionInPlace as n } from "./index2.js";
|
|
2
|
+
import { ModelSetEvent as r, SessionChangedEvent as i } from "@pie-element/shared-player-events";
|
|
3
|
+
export { r as ModelSetEvent, i as SessionChangedEvent, e as forwardSessionChange, t as resolveDeliveryHost, n as writeSessionInPlace };
|
package/dist/index2.js
CHANGED
|
@@ -1,33 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, t = class e extends CustomEvent {
|
|
18
|
-
static {
|
|
19
|
-
this.TYPE = "session-changed";
|
|
1
|
+
import { SessionChangedEvent as e } from "@pie-element/shared-player-events";
|
|
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) {
|
|
8
|
+
if (e.parentElement) return e.parentElement;
|
|
9
|
+
let t = e.getRootNode();
|
|
10
|
+
return t instanceof ShadowRoot ? t.host : null;
|
|
11
|
+
}
|
|
12
|
+
function r(e, r = {}) {
|
|
13
|
+
let i = r.hostPredicate ?? t, a = e;
|
|
14
|
+
for (; a;) {
|
|
15
|
+
if (i(a)) return a;
|
|
16
|
+
a = n(a);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function i(e) {
|
|
21
|
+
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
22
|
+
}
|
|
23
|
+
function a(e, t) {
|
|
24
|
+
if (e === t) return e;
|
|
25
|
+
if (!i(e) || !i(t) || Object.isFrozen(e) || !Object.isExtensible(e)) return t;
|
|
26
|
+
try {
|
|
27
|
+
for (let n of Object.keys(e)) n in t || delete e[n];
|
|
28
|
+
Object.assign(e, t);
|
|
29
|
+
} catch {
|
|
30
|
+
return t;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
return e;
|
|
33
|
+
}
|
|
34
|
+
var o = {}, s = /* @__PURE__ */ new WeakSet();
|
|
35
|
+
function c(e) {
|
|
36
|
+
let t = e ?? o;
|
|
37
|
+
if (s.has(t)) return;
|
|
38
|
+
s.add(t);
|
|
39
|
+
let n = e ? `above <${e.tagName.toLowerCase()}>` : "for an update with no source element";
|
|
40
|
+
console.warn(`[session-bridge] no delivery host ${n}; the session change was not forwarded to the player`);
|
|
41
|
+
}
|
|
42
|
+
function l({ sourceEl: t, complete: n, session: i }) {
|
|
43
|
+
let o = r(t);
|
|
44
|
+
if (!o) return c(t), null;
|
|
45
|
+
if (typeof o.onSessionChange == "function") return o.onSessionChange(i), o;
|
|
46
|
+
let s = a(o.session, i);
|
|
47
|
+
return s !== o.session && (o.session = s), o.dispatchEvent(new e(o.tagName.toLowerCase(), n)), o;
|
|
48
|
+
}
|
|
32
49
|
//#endregion
|
|
33
|
-
export {
|
|
50
|
+
export { l as forwardSessionChange, r as resolveDeliveryHost, a as writeSessionInPlace };
|
package/dist/session-bridge.d.ts
CHANGED
|
@@ -6,12 +6,16 @@ export type DeliveryHostElement = HTMLElement & {
|
|
|
6
6
|
};
|
|
7
7
|
type HostPredicate = (node: unknown) => boolean;
|
|
8
8
|
export interface ResolveDeliveryHostOptions {
|
|
9
|
-
fallbackSelector?: string;
|
|
10
9
|
hostPredicate?: HostPredicate;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Walk up the DOM from a source element and find the nearest delivery host wrapper.
|
|
14
|
-
*
|
|
13
|
+
* The walk continues from a shadow root to its host, so a wrapper that renders the
|
|
14
|
+
* element inside its own shadow root is still found.
|
|
15
|
+
*
|
|
16
|
+
* There is no lookup by tag name: a player registers the element under a tag it
|
|
17
|
+
* chooses (versioned, e.g. `simple-cloze--version-0-2-0`), so the element cannot
|
|
18
|
+
* know it, and a document-wide query could reach a different instance.
|
|
15
19
|
*/
|
|
16
20
|
export declare function resolveDeliveryHost(sourceEl?: HTMLElement | null, options?: ResolveDeliveryHostOptions): DeliveryHostElement | null;
|
|
17
21
|
/**
|
|
@@ -39,14 +43,16 @@ export declare function resolveDeliveryHost(sourceEl?: HTMLElement | null, optio
|
|
|
39
43
|
export declare function writeSessionInPlace(target: unknown, next: unknown): unknown;
|
|
40
44
|
export interface ForwardSessionChangeOptions {
|
|
41
45
|
sourceEl?: HTMLElement | null;
|
|
42
|
-
fallbackSelector?: string;
|
|
43
|
-
component: string;
|
|
44
46
|
complete: boolean;
|
|
45
47
|
session: unknown;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* Forward a delivery session update using the host callback when available.
|
|
49
|
-
* If no callback is exposed,
|
|
51
|
+
* If no callback is exposed, write the update into the host's session, as
|
|
52
|
+
* `writeSessionInPlace` does for a wrapper, and dispatch the canonical
|
|
53
|
+
* session-changed metadata event, named for the tag the host was registered
|
|
54
|
+
* under: the event carries no session, so a player reads the response off it.
|
|
55
|
+
* Returns `null`, and warns, when the source element has no delivery host.
|
|
50
56
|
*/
|
|
51
|
-
export declare function forwardSessionChange({ sourceEl,
|
|
57
|
+
export declare function forwardSessionChange({ sourceEl, complete, session, }: ForwardSessionChangeOptions): DeliveryHostElement | null;
|
|
52
58
|
export {};
|
package/package.json
CHANGED
package/dist/index3.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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 };
|