@overlaysymphony/core 0.2.0 → 0.2.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/package.json +4 -4
- package/src/libs/broadcast/index.ts +1 -1
- package/src/libs/defer/defer.ts +4 -3
- package/src/libs/defer/index.ts +1 -1
- package/src/libs/events/events.ts +57 -0
- package/src/libs/events/index.ts +2 -0
- package/src/libs/pubsub/index.ts +2 -2
- package/src/libs/querystring/index.ts +2 -2
- package/src/libs/queue/index.ts +2 -2
- package/src/ui/error.ts +42 -0
- package/src/ui/vite-env.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overlaysymphony/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Core module for the OverlaySymphony interactive streaming framework.",
|
|
5
5
|
"homepage": "https://github.com/OverlaySymphony/overlaysymphony",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./libs/*": "./src/libs/*/index.ts",
|
|
9
|
+
"./ui/*": "./src/ui/*.ts",
|
|
9
10
|
"./package.json": "./package.json"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
"eslint": "^9.19.0",
|
|
15
16
|
"prettier": "^3.4.2",
|
|
16
17
|
"typescript": "^5.7.2",
|
|
18
|
+
"vite": "^6.2.1",
|
|
17
19
|
"vitest": "^2.1.2",
|
|
18
20
|
"@overlaysymphony/tooling": "0.0.0"
|
|
19
21
|
},
|
|
@@ -24,8 +26,6 @@
|
|
|
24
26
|
"lint-prettier": "prettier --check .",
|
|
25
27
|
"lint-depcheck": "depcheck .",
|
|
26
28
|
"test": "vitest",
|
|
27
|
-
"
|
|
28
|
-
"clean": "rm -rf node_modules/.cache tsconfig.tsbuildinfo dist",
|
|
29
|
-
"build": "echo TODO"
|
|
29
|
+
"clean": "rm -rf node_modules/.cache tsconfig.tsbuildinfo"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from "./broadcast.
|
|
1
|
+
export { default } from "./broadcast.ts"
|
package/src/libs/defer/defer.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export default function createDefer<Data = void>(): {
|
|
2
2
|
promise: Promise<Data>
|
|
3
3
|
resolve: (value: Data) => void
|
|
4
|
-
reject: (
|
|
4
|
+
reject: (error?: string | Error) => void
|
|
5
5
|
} {
|
|
6
6
|
let resolve: ((value: Data) => void) | undefined = undefined
|
|
7
|
-
let reject: ((
|
|
7
|
+
let reject: ((error?: string | Error) => void) | undefined = undefined
|
|
8
8
|
|
|
9
9
|
const promise = new Promise<Data>((resolve_, reject_) => {
|
|
10
10
|
resolve = resolve_
|
|
11
|
-
reject =
|
|
11
|
+
reject = (error) =>
|
|
12
|
+
reject_(error instanceof Error ? error : new Error(error))
|
|
12
13
|
})
|
|
13
14
|
|
|
14
15
|
return {
|
package/src/libs/defer/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from "./defer.
|
|
1
|
+
export { default } from "./defer.ts"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import createPubSub, { type PubSub } from "../pubsub/index.ts"
|
|
2
|
+
|
|
3
|
+
type EventSubSubscriber<Payload extends { type: string }> = <
|
|
4
|
+
Type extends Payload["type"],
|
|
5
|
+
>(
|
|
6
|
+
types: Type[],
|
|
7
|
+
callback: (event: Extract<Payload, { type: Type }>) => void,
|
|
8
|
+
) => () => void
|
|
9
|
+
|
|
10
|
+
export type Events<Payload extends { type: string }> = {
|
|
11
|
+
on: EventSubSubscriber<Payload>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default async function createEvents<
|
|
15
|
+
Payload extends { type: string },
|
|
16
|
+
ConnectData,
|
|
17
|
+
>(
|
|
18
|
+
connect: (pubsub: PubSub<Payload>) => Promise<ConnectData | null>,
|
|
19
|
+
createSubscription: (
|
|
20
|
+
pubsub: PubSub<Payload>,
|
|
21
|
+
connectData: ConnectData,
|
|
22
|
+
type: Payload["type"],
|
|
23
|
+
) => Promise<void>,
|
|
24
|
+
): Promise<Events<Payload>> {
|
|
25
|
+
const pubsub = createPubSub<Payload>()
|
|
26
|
+
|
|
27
|
+
const connectData = await connect(pubsub)
|
|
28
|
+
if (connectData === null) {
|
|
29
|
+
return {
|
|
30
|
+
on: () => () => undefined,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const subscriptions: Partial<Record<Payload["type"], boolean>> = {}
|
|
35
|
+
|
|
36
|
+
const on: EventSubSubscriber<Payload> = (types, callback) => {
|
|
37
|
+
for (const type of types) {
|
|
38
|
+
if (!subscriptions[type]) {
|
|
39
|
+
subscriptions[type] = true
|
|
40
|
+
|
|
41
|
+
void createSubscription(pubsub, connectData, type)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return pubsub.subscribe((event) => {
|
|
46
|
+
// @ts-expect-error: generic events are complicated
|
|
47
|
+
if (types.includes(event.type)) {
|
|
48
|
+
// @ts-expect-error: generic events are complicated
|
|
49
|
+
callback(event)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
on,
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/libs/pubsub/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./pubsub.
|
|
2
|
-
export * from "./pubsub.
|
|
1
|
+
export { default } from "./pubsub.ts"
|
|
2
|
+
export * from "./pubsub.ts"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./querystring.
|
|
2
|
-
export * from "./querystring.
|
|
1
|
+
export { default } from "./querystring.ts"
|
|
2
|
+
export * from "./querystring.ts"
|
package/src/libs/queue/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./queue.
|
|
2
|
-
export * from "./queue.
|
|
1
|
+
export { default } from "./queue.ts"
|
|
2
|
+
export * from "./queue.ts"
|
package/src/ui/error.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class OverlaySymfonyCoreError extends HTMLElement {
|
|
2
|
+
static get observedAttributes(): string[] {
|
|
3
|
+
return ["module", "title"]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
root: ShadowRoot
|
|
7
|
+
element?: HTMLElement
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super()
|
|
11
|
+
|
|
12
|
+
const stylesheet = new CSSStyleSheet()
|
|
13
|
+
|
|
14
|
+
stylesheet.insertRule(`
|
|
15
|
+
:host {
|
|
16
|
+
display: block;
|
|
17
|
+
}
|
|
18
|
+
`)
|
|
19
|
+
|
|
20
|
+
stylesheet.insertRule(`
|
|
21
|
+
.dialog {}
|
|
22
|
+
`)
|
|
23
|
+
|
|
24
|
+
this.root = this.attachShadow({ mode: "closed" })
|
|
25
|
+
this.root.adoptedStyleSheets.push(stylesheet)
|
|
26
|
+
|
|
27
|
+
void this.render()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get clientId(): string {
|
|
31
|
+
return this.getAttribute("client-id") ?? ""
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async render(): Promise<void> {
|
|
35
|
+
this.root.innerHTML = '<div class="dialog"><slot /></div>'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
window.customElements.define(
|
|
40
|
+
"overlaysymfony-core-error",
|
|
41
|
+
OverlaySymfonyCoreError,
|
|
42
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|