@overlaysymphony/core 0.1.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 CHANGED
@@ -1,33 +1,31 @@
1
1
  {
2
2
  "name": "@overlaysymphony/core",
3
- "version": "0.1.0",
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
- "./libs/*": "./src/libs/*/index.js",
9
- "./ui/*": "./src/ui/*.js",
8
+ "./libs/*": "./src/libs/*/index.ts",
9
+ "./ui/*": "./src/ui/*.ts",
10
10
  "./package.json": "./package.json"
11
11
  },
12
+ "devDependencies": {
13
+ "@vitest/coverage-v8": "^2.1.2",
14
+ "depcheck": "^1.4.7",
15
+ "eslint": "^9.19.0",
16
+ "prettier": "^3.4.2",
17
+ "typescript": "^5.7.2",
18
+ "vite": "^6.2.1",
19
+ "vitest": "^2.1.2",
20
+ "@overlaysymphony/tooling": "0.0.0"
21
+ },
12
22
  "scripts": {
13
23
  "lint": "pnpm run \"/^lint-.*/\"",
14
24
  "lint-typecheck": "tsc --noEmit",
15
- "lint-eslint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
25
+ "lint-eslint": "eslint .",
16
26
  "lint-prettier": "prettier --check .",
17
27
  "lint-depcheck": "depcheck .",
18
28
  "test": "vitest",
19
- "dev": "echo TODO",
20
- "clean": "rm -rf node_modules/.cache tsconfig.tsbuildinfo dist",
21
- "build": "echo TODO"
22
- },
23
- "devDependencies": {
24
- "@overlaysymphony/eslint-config": "workspace:*",
25
- "@overlaysymphony/tooling": "workspace:*",
26
- "@vitest/coverage-v8": "^2.1.2",
27
- "depcheck": "catalog:",
28
- "eslint": "catalog:",
29
- "prettier": "catalog:",
30
- "typescript": "catalog:",
31
- "vitest": "^2.1.2"
29
+ "clean": "rm -rf node_modules/.cache tsconfig.tsbuildinfo"
32
30
  }
33
- }
31
+ }
@@ -1 +1 @@
1
- export { default } from "./broadcast.js"
1
+ export { default } from "./broadcast.ts"
@@ -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: (reason?: string) => void
4
+ reject: (error?: string | Error) => void
5
5
  } {
6
6
  let resolve: ((value: Data) => void) | undefined = undefined
7
- let reject: ((reason?: string) => void) | undefined = undefined
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 = reject_
11
+ reject = (error) =>
12
+ reject_(error instanceof Error ? error : new Error(error))
12
13
  })
13
14
 
14
15
  return {
@@ -1 +1 @@
1
- export { default } from "./defer.js"
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
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from "./events.ts"
2
+ export * from "./events.ts"
@@ -1,2 +1,2 @@
1
- export { default } from "./pubsub.js"
2
- export * from "./pubsub.js"
1
+ export { default } from "./pubsub.ts"
2
+ export * from "./pubsub.ts"
@@ -1,2 +1,2 @@
1
- export { default } from "./querystring.js"
2
- export * from "./querystring.js"
1
+ export { default } from "./querystring.ts"
2
+ export * from "./querystring.ts"
@@ -17,8 +17,8 @@ export function stringify(input: ParsedQuerystring): string {
17
17
 
18
18
  export function parse(input: string): ParsedQuerystring {
19
19
  input = decodeURIComponent(input)
20
- if (input[0] === "#") input = input.slice(1)
21
- if (input[0] === "?") input = input.slice(1)
20
+ if (input.startsWith("#")) input = input.slice(1)
21
+ if (input.startsWith("?")) input = input.slice(1)
22
22
 
23
23
  if (input.length === 0) {
24
24
  return {}
@@ -1,2 +1,2 @@
1
- export { default } from "./queue.js"
2
- export * from "./queue.js"
1
+ export { default } from "./queue.ts"
2
+ export * from "./queue.ts"
@@ -59,7 +59,7 @@ export default function createQueue<Data>(): Queue<Data> {
59
59
  }
60
60
 
61
61
  function dismiss() {
62
- const { data } = queue.shift() || {}
62
+ const { data } = queue.shift() ?? {}
63
63
  return dispatch(data)
64
64
  }
65
65
 
@@ -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" />