@opendaw/lib-jsx 0.0.6

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.
Files changed (44) hide show
  1. package/README.md +1 -0
  2. package/dist/create-element.d.ts +14 -0
  3. package/dist/create-element.d.ts.map +1 -0
  4. package/dist/create-element.js +130 -0
  5. package/dist/index.d.ts +12 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +19 -0
  8. package/dist/inject.d.ts +45 -0
  9. package/dist/inject.d.ts.map +1 -0
  10. package/dist/inject.js +111 -0
  11. package/dist/routes.d.ts +20 -0
  12. package/dist/routes.d.ts.map +1 -0
  13. package/dist/routes.js +87 -0
  14. package/dist/std/Await.d.ts +13 -0
  15. package/dist/std/Await.d.ts.map +1 -0
  16. package/dist/std/Await.js +10 -0
  17. package/dist/std/Frag.d.ts +3 -0
  18. package/dist/std/Frag.d.ts.map +1 -0
  19. package/dist/std/Frag.js +2 -0
  20. package/dist/std/Group.d.ts +3 -0
  21. package/dist/std/Group.d.ts.map +1 -0
  22. package/dist/std/Group.js +2 -0
  23. package/dist/std/Hotspot.d.ts +12 -0
  24. package/dist/std/Hotspot.d.ts.map +1 -0
  25. package/dist/std/Hotspot.js +7 -0
  26. package/dist/std/LocalLink.d.ts +4 -0
  27. package/dist/std/LocalLink.d.ts.map +1 -0
  28. package/dist/std/LocalLink.js +8 -0
  29. package/dist/std/Preloader.d.ts +5 -0
  30. package/dist/std/Preloader.d.ts.map +1 -0
  31. package/dist/std/Preloader.js +23 -0
  32. package/dist/std/Router.d.ts +23 -0
  33. package/dist/std/Router.d.ts.map +1 -0
  34. package/dist/std/Router.js +73 -0
  35. package/dist/supported-svg-tags.d.ts +2 -0
  36. package/dist/supported-svg-tags.d.ts.map +1 -0
  37. package/dist/supported-svg-tags.js +98 -0
  38. package/dist/types.d.ts +27 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +1 -0
  41. package/dist/weak.d.ts +7 -0
  42. package/dist/weak.d.ts.map +1 -0
  43. package/dist/weak.js +16 -0
  44. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This package is part of the openDAW SDK
@@ -0,0 +1,14 @@
1
+ import { DomElement, JsxValue } from "./types";
2
+ type Factory = (attributes: Readonly<Record<string, any>>, children?: ReadonlyArray<JsxValue>) => JsxValue;
3
+ type TagOrFactoryOrElement = string | Factory | DomElement;
4
+ /**
5
+ * This method must be exposed as the "createElement" method
6
+ * to be passively called on each element defined in jsx files.
7
+ * This is secured by injection defined in vite.config
8
+ * Most magic happens here, but we try to keep it civil.
9
+ */
10
+ export declare function createElement(tagOrFactoryOrElement: TagOrFactoryOrElement, attributes: Readonly<Record<string, any>> | null, ...children: ReadonlyArray<JsxValue>): JsxValue;
11
+ export declare const replaceChildren: (element: DomElement, ...children: ReadonlyArray<JsxValue>) => void;
12
+ export declare const appendChildren: (element: DomElement, ...children: ReadonlyArray<JsxValue>) => void;
13
+ export {};
14
+ //# sourceMappingURL=create-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-element.d.ts","sourceRoot":"","sources":["../src/create-element.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAA;AAE5C,KAAK,OAAO,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAA;AAC1G,KAAK,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;AAK1D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,qBAAqB,EAAE,qBAAqB,EAC5C,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAChD,GAAG,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAsC5E;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,UAAU,EAAE,GAAG,UAAU,aAAa,CAAC,QAAQ,CAAC,SAGxF,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,SAAS,UAAU,EAAE,GAAG,UAAU,aAAa,CAAC,QAAQ,CAAC,SAiBvF,CAAA"}
@@ -0,0 +1,130 @@
1
+ import { canWrite, panic } from "@opendaw/lib-std";
2
+ import { Html } from "@opendaw/lib-dom";
3
+ import { SupportedSvgTags } from "./supported-svg-tags";
4
+ import { Inject } from "./inject";
5
+ const EmptyAttributes = Object.freeze({});
6
+ const EmptyChildren = Object.freeze([]);
7
+ /**
8
+ * This method must be exposed as the "createElement" method
9
+ * to be passively called on each element defined in jsx files.
10
+ * This is secured by injection defined in vite.config
11
+ * Most magic happens here, but we try to keep it civil.
12
+ */
13
+ export function createElement(tagOrFactoryOrElement, attributes, ...children) {
14
+ if (tagOrFactoryOrElement instanceof HTMLElement || tagOrFactoryOrElement instanceof SVGElement) {
15
+ // already an element > early out
16
+ return tagOrFactoryOrElement;
17
+ }
18
+ let element;
19
+ if (typeof tagOrFactoryOrElement === "function") {
20
+ // this is the usual component factory case
21
+ element = tagOrFactoryOrElement(attributes ?? EmptyAttributes, children);
22
+ if (tagOrFactoryOrElement.length === 2) {
23
+ // we expect the children to be consumed by the function, since it accepted a second parameter
24
+ children = EmptyChildren;
25
+ }
26
+ if (element === false
27
+ || element === true
28
+ || element === null
29
+ || element === undefined
30
+ || typeof element === "string"
31
+ || typeof element === "number"
32
+ || Array.isArray(element)) {
33
+ // primitives and arrays are ready to be returned immediately and handled as children for the parent
34
+ return element;
35
+ }
36
+ // we expect the attributes to be consumed by the factory
37
+ attributes = null;
38
+ }
39
+ else {
40
+ // strings are supposed to be valid html or svg elements
41
+ element = SupportedSvgTags.has(tagOrFactoryOrElement)
42
+ ? document.createElementNS("http://www.w3.org/2000/svg", tagOrFactoryOrElement)
43
+ : document.createElement(tagOrFactoryOrElement);
44
+ }
45
+ if (children.length > 0) {
46
+ appendChildren(element, ...children);
47
+ }
48
+ if (attributes !== null) {
49
+ transferAttributes(element, attributes);
50
+ }
51
+ return element;
52
+ }
53
+ export const replaceChildren = (element, ...children) => {
54
+ Html.empty(element);
55
+ appendChildren(element, ...children);
56
+ };
57
+ export const appendChildren = (element, ...children) => {
58
+ children.forEach((value) => {
59
+ if (value === null || value === undefined || value === false) {
60
+ return;
61
+ }
62
+ if (Array.isArray(value)) {
63
+ appendChildren(element, ...value);
64
+ }
65
+ else if (value instanceof Inject.Value) {
66
+ const text = document.createTextNode(String(value.value));
67
+ value.addTarget(text);
68
+ element.append(text);
69
+ }
70
+ else if (typeof value === "string") {
71
+ element.append(document.createTextNode(value));
72
+ }
73
+ else if (typeof value === "number") {
74
+ element.append(document.createTextNode(String(value)));
75
+ }
76
+ else if (value instanceof Node) {
77
+ element.append(value);
78
+ }
79
+ });
80
+ };
81
+ const transferAttributes = (element, attributes) => {
82
+ Object.entries(attributes).forEach(([key, value]) => {
83
+ if (value === undefined) {
84
+ return;
85
+ }
86
+ if (key === "class" || key === "className") {
87
+ if (value instanceof Inject.ClassList) {
88
+ value.addTarget(element);
89
+ }
90
+ else {
91
+ element.classList.add(...value.split(" "));
92
+ }
93
+ }
94
+ else if (key === "style") {
95
+ if (typeof value === "string") {
96
+ element.setAttribute(key, value);
97
+ }
98
+ else {
99
+ Object.assign(element.style, value);
100
+ }
101
+ }
102
+ else if (key === "ref") {
103
+ if (value instanceof Inject.Ref) {
104
+ value.addTarget(element);
105
+ }
106
+ else {
107
+ return panic("value of 'ref' must be of type '_Ref'");
108
+ }
109
+ }
110
+ else if (key === "onLoad") {
111
+ if (value instanceof Function && value.length === 1) {
112
+ value(element);
113
+ }
114
+ else {
115
+ return panic("value of 'onLoad' must be a Function with a single argument");
116
+ }
117
+ }
118
+ else if (value instanceof Inject.Attribute) {
119
+ value.addTarget(element, key);
120
+ }
121
+ else {
122
+ if (canWrite(element, key)) {
123
+ element[key] = value;
124
+ }
125
+ else {
126
+ element.setAttribute(key, String(value));
127
+ }
128
+ }
129
+ });
130
+ };
@@ -0,0 +1,12 @@
1
+ export * from "./types";
2
+ export * from "./create-element";
3
+ export * from "./inject";
4
+ export * from "./routes";
5
+ export * from "./std/Await";
6
+ export * from "./std/Frag";
7
+ export * from "./std/Group";
8
+ export * from "./std/Hotspot";
9
+ export * from "./std/LocalLink";
10
+ export * from "./std/Router";
11
+ export * from "./std/Preloader";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ const key = Symbol.for("@openDAW/lib-jsx");
2
+ if (globalThis[key]) {
3
+ console.debug(`%c${key.description}%c is already available in ${globalThis.constructor.name}.`, "color: hsl(10, 83%, 60%)", "color: inherit");
4
+ }
5
+ else {
6
+ globalThis[key] = true;
7
+ console.debug(`%c${key.description}%c is now available in ${globalThis.constructor.name}.`, "color: hsl(200, 83%, 60%)", "color: inherit");
8
+ }
9
+ export * from "./types";
10
+ export * from "./create-element";
11
+ export * from "./inject";
12
+ export * from "./routes";
13
+ export * from "./std/Await";
14
+ export * from "./std/Frag";
15
+ export * from "./std/Group";
16
+ export * from "./std/Hotspot";
17
+ export * from "./std/LocalLink";
18
+ export * from "./std/Router";
19
+ export * from "./std/Preloader";
@@ -0,0 +1,45 @@
1
+ import { Stringifiable, Terminable } from "@opendaw/lib-std";
2
+ export declare namespace Inject {
3
+ export const ref: <T>() => Ref<T>;
4
+ export const value: <T extends Stringifiable>(initialValue: T) => Value<T>;
5
+ export const classList: (...initialClassNames: Array<string>) => ClassList;
6
+ export const attribute: (initialAttributeValue: string) => Attribute;
7
+ interface Injector<T> extends Terminable {
8
+ addTarget(target: T, ...args: Array<unknown>): void;
9
+ }
10
+ export class Ref<T> implements Injector<T> {
11
+ #private;
12
+ get(): T;
13
+ addTarget(target: T): void;
14
+ hasTarget(): boolean;
15
+ terminate(): void;
16
+ }
17
+ export class Value<T extends Stringifiable = Stringifiable> implements Injector<Text> {
18
+ #private;
19
+ constructor(value: T);
20
+ get value(): T;
21
+ set value(value: T);
22
+ addTarget(text: Text): void;
23
+ terminate(): void;
24
+ }
25
+ export class ClassList implements Injector<Element> {
26
+ #private;
27
+ constructor(classes: Array<string>);
28
+ add(className: string): void;
29
+ remove(className: string): void;
30
+ toggle(className: string, force?: boolean): void;
31
+ addTarget(target: Element): void;
32
+ terminate(): void;
33
+ }
34
+ export class Attribute implements Injector<Element> {
35
+ #private;
36
+ constructor(value: string);
37
+ get value(): string;
38
+ set value(value: string);
39
+ toggle(expected: string, alternative: string): void;
40
+ addTarget(target: Element, key: string): void;
41
+ terminate(): void;
42
+ }
43
+ export {};
44
+ }
45
+ //# sourceMappingURL=inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAG7E,yBAAiB,MAAM,CAAC;IACpB,MAAM,CAAC,MAAM,GAAG,GAAI,CAAC,aAAmB,CAAA;IACxC,MAAM,CAAC,MAAM,KAAK,GAAI,CAAC,SAAS,aAAa,EAAE,cAAc,CAAC,aAA+B,CAAA;IAC7F,MAAM,CAAC,MAAM,SAAS,GAAI,GAAG,mBAAmB,KAAK,CAAC,MAAM,CAAC,cAAqC,CAAA;IAClG,MAAM,CAAC,MAAM,SAAS,GAAI,uBAAuB,MAAM,cAAyC,CAAA;IAEhG,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,UAAU;QAAE,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;KAAC;IAE9F,MAAM,OAAO,GAAG,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;;QAEtC,GAAG,IAAI,CAAC;QACR,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;QAC1B,SAAS,IAAI,OAAO;QACpB,SAAS,IAAI,IAAI;KACpB;IAED,MAAM,OAAO,KAAK,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CAAE,YAAW,QAAQ,CAAC,IAAI,CAAC;;oBAKrE,KAAK,EAAE,CAAC;QAEpB,IAAI,KAAK,IAAI,CAAC,CAAqB;QACnC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC,EAIjB;QACD,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;QAC3B,SAAS,IAAI,IAAI;KACpB;IAED,MAAM,OAAO,SAAU,YAAW,QAAQ,CAAC,OAAO,CAAC;;oBAInC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC;QAKlC,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;QAK5B,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;QAK/B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;QAiBhD,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;QAKhC,SAAS,IAAI,IAAI;KAMpB;IAED,MAAM,OAAO,SAAU,YAAW,QAAQ,CAAC,OAAO,CAAC;;oBAMnC,KAAK,EAAE,MAAM;QAMzB,IAAI,KAAK,IAAI,MAAM,CAAqB;QACxC,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAItB;QAED,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;QAInD,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;QAM7C,SAAS,IAAI,IAAI;KAUpB;;CACJ"}
package/dist/inject.js ADDED
@@ -0,0 +1,111 @@
1
+ import { isDefined, Option } from "@opendaw/lib-std";
2
+ import { WeakRefSet } from "./weak";
3
+ export var Inject;
4
+ (function (Inject) {
5
+ Inject.ref = () => new Ref();
6
+ Inject.value = (initialValue) => new Value(initialValue);
7
+ Inject.classList = (...initialClassNames) => new ClassList(initialClassNames);
8
+ Inject.attribute = (initialAttributeValue) => new Attribute(initialAttributeValue);
9
+ class Ref {
10
+ #target = Option.None;
11
+ get() { return this.#target.unwrap("No target provided"); }
12
+ addTarget(target) { this.#target = Option.wrap(target); }
13
+ hasTarget() { return this.#target.nonEmpty(); }
14
+ terminate() { this.#target = Option.None; }
15
+ }
16
+ Inject.Ref = Ref;
17
+ class Value {
18
+ #targets = new WeakRefSet();
19
+ #value;
20
+ constructor(value) { this.#value = value; }
21
+ get value() { return this.#value; }
22
+ set value(value) {
23
+ if (this.#value === value) {
24
+ return;
25
+ }
26
+ this.#value = value;
27
+ this.#targets.forEach(text => { text.nodeValue = String(value); });
28
+ }
29
+ addTarget(text) { this.#targets.add(text); }
30
+ terminate() { this.#targets.clear(); }
31
+ }
32
+ Inject.Value = Value;
33
+ class ClassList {
34
+ #targets;
35
+ #classes;
36
+ constructor(classes) {
37
+ this.#targets = new WeakRefSet();
38
+ this.#classes = new Set(classes);
39
+ }
40
+ add(className) {
41
+ this.#classes.add(className);
42
+ this.#updateElements();
43
+ }
44
+ remove(className) {
45
+ this.#classes.delete(className);
46
+ this.#updateElements();
47
+ }
48
+ toggle(className, force) {
49
+ if (isDefined(force)) {
50
+ if (force) {
51
+ this.#classes.add(className);
52
+ }
53
+ else {
54
+ this.#classes.delete(className);
55
+ }
56
+ }
57
+ else {
58
+ if (this.#classes.has(className)) {
59
+ this.#classes.delete(className);
60
+ }
61
+ else {
62
+ this.#classes.add(className);
63
+ }
64
+ }
65
+ this.#updateElements();
66
+ }
67
+ addTarget(target) {
68
+ this.#targets.add(target);
69
+ this.#updateElement(target);
70
+ }
71
+ terminate() { this.#targets.clear(); }
72
+ #updateElements() { this.#targets.forEach(this.#updateElement); }
73
+ #updateElement = (element) => { element.className = Array.from(this.#classes).join(" "); };
74
+ }
75
+ Inject.ClassList = ClassList;
76
+ class Attribute {
77
+ #targets;
78
+ #keys;
79
+ #value;
80
+ constructor(value) {
81
+ this.#targets = new WeakRefSet();
82
+ this.#keys = new WeakMap();
83
+ this.#value = value;
84
+ }
85
+ get value() { return this.#value; }
86
+ set value(value) {
87
+ if (this.#value === value) {
88
+ return;
89
+ }
90
+ this.#value = value;
91
+ this.#updateElements();
92
+ }
93
+ toggle(expected, alternative) {
94
+ this.value = this.value === expected ? alternative : expected;
95
+ }
96
+ addTarget(target, key) {
97
+ this.#targets.add(target);
98
+ this.#keys.set(target, key);
99
+ this.#updateElement(target);
100
+ }
101
+ terminate() { this.#targets.clear(); }
102
+ #updateElements() { this.#targets.forEach(this.#updateElement); }
103
+ #updateElement = (element) => {
104
+ const key = this.#keys.get(element);
105
+ if (key !== undefined) {
106
+ element.setAttribute(key, this.#value);
107
+ }
108
+ };
109
+ }
110
+ Inject.Attribute = Attribute;
111
+ })(Inject || (Inject = {}));
@@ -0,0 +1,20 @@
1
+ import { Observer, Option, Subscription } from "@opendaw/lib-std";
2
+ export declare class RouteLocation {
3
+ #private;
4
+ static get(): RouteLocation;
5
+ private constructor();
6
+ navigateTo(path: string): boolean;
7
+ catchupAndSubscribe(observer: Observer<RouteLocation>): Subscription;
8
+ get path(): string;
9
+ }
10
+ export type Route = {
11
+ path: string;
12
+ };
13
+ export declare class RouteMatcher<R extends Route> {
14
+ #private;
15
+ static create<R extends Route>(routes: ReadonlyArray<R>): RouteMatcher<R>;
16
+ static match(route: string, path: string): boolean;
17
+ private constructor();
18
+ resolve(path: string): Option<R>;
19
+ }
20
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAE1F,qBAAa,aAAa;;IAEtB,MAAM,CAAC,GAAG,IAAI,aAAa;IAI3B,OAAO;IAKP,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAUjC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,YAAY;IAKpE,IAAI,IAAI,IAAI,MAAM,CAA2B;CAchD;AAED,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpC,qBAAa,YAAY,CAAC,CAAC,SAAS,KAAK;;IACrC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAIzE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAmBlD,OAAO;IAYP,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;CAGnC"}
package/dist/routes.js ADDED
@@ -0,0 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { isDefined, Lazy, Notifier, Option } from "@opendaw/lib-std";
11
+ export class RouteLocation {
12
+ static get() { return new RouteLocation(); }
13
+ #notifier = new Notifier();
14
+ constructor() {
15
+ window.addEventListener("popstate", () => this.#notifier.notify(this));
16
+ this.#setCanonical();
17
+ }
18
+ navigateTo(path) {
19
+ if (this.path === path) {
20
+ return false;
21
+ }
22
+ history.pushState(null, "", path);
23
+ this.#setCanonical();
24
+ this.#notifier.notify(this);
25
+ return true;
26
+ }
27
+ catchupAndSubscribe(observer) {
28
+ observer(this);
29
+ return this.#notifier.subscribe(observer);
30
+ }
31
+ get path() { return location.pathname; }
32
+ #setCanonical() {
33
+ const url = location.href;
34
+ let link = document.querySelector("link[rel=\"canonical\"]");
35
+ if (isDefined(link)) {
36
+ link.setAttribute("href", url);
37
+ }
38
+ else {
39
+ link = document.createElement("link");
40
+ link.setAttribute("rel", "canonical");
41
+ link.setAttribute("href", url);
42
+ document.head.appendChild(link);
43
+ }
44
+ }
45
+ }
46
+ __decorate([
47
+ Lazy,
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", []),
50
+ __metadata("design:returntype", RouteLocation)
51
+ ], RouteLocation, "get", null);
52
+ export class RouteMatcher {
53
+ static create(routes) {
54
+ return new RouteMatcher(routes);
55
+ }
56
+ static match(route, path) {
57
+ if (!path.startsWith("/") || !route.startsWith("/")) {
58
+ return false;
59
+ }
60
+ const routeSegments = route.split("/");
61
+ const pathSegments = path.split("/");
62
+ for (let i = 1; i < pathSegments.length; i++) {
63
+ if (routeSegments[i] === "*") {
64
+ return true;
65
+ }
66
+ if (pathSegments[i] !== routeSegments[i]) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ }
72
+ #routes;
73
+ constructor(routes) {
74
+ this.#routes = routes.toSorted((a, b) => {
75
+ if (a.path < b.path) {
76
+ return -1;
77
+ }
78
+ if (a.path > b.path) {
79
+ return 1;
80
+ }
81
+ return 0;
82
+ });
83
+ }
84
+ resolve(path) {
85
+ return Option.wrap(this.#routes.find(route => RouteMatcher.match(route.path, path)));
86
+ }
87
+ }
@@ -0,0 +1,13 @@
1
+ import { Exec, Func, Provider } from "@opendaw/lib-std";
2
+ import { DomElement, JsxValue } from "../types";
3
+ export type AwaitProps<T> = {
4
+ factory: Provider<Promise<T>>;
5
+ loading: Provider<JsxValue>;
6
+ success: Func<T, JsxValue>;
7
+ failure: Func<{
8
+ reason: any;
9
+ retry: Exec;
10
+ }, JsxValue>;
11
+ };
12
+ export declare const Await: <T>({ factory, loading, success, failure }: AwaitProps<T>) => DomElement;
13
+ //# sourceMappingURL=Await.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Await.d.ts","sourceRoot":"","sources":["../../src/std/Await.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAA;AAE7C,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IACxB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAE,EAAE,QAAQ,CAAC,CAAA;CACxD,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,CAAC,EAAI,wCAAsC,UAAU,CAAC,CAAC,CAAC,eAU7E,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { createElement, replaceChildren } from "../create-element";
2
+ export const Await = ({ factory, loading, success, failure }) => {
3
+ const contents = createElement("div", { style: { display: "contents" } });
4
+ const start = () => {
5
+ replaceChildren(contents, loading());
6
+ factory().then(result => replaceChildren(contents, success(result)), reason => replaceChildren(contents, failure({ reason, retry: () => start() })));
7
+ };
8
+ start();
9
+ return contents;
10
+ };
@@ -0,0 +1,3 @@
1
+ import { JsxValue } from "../types";
2
+ export declare const Frag: (_: unknown, children: ReadonlyArray<JsxValue>) => readonly JsxValue[];
3
+ //# sourceMappingURL=Frag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Frag.d.ts","sourceRoot":"","sources":["../../src/std/Frag.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAA;AAGjC,eAAO,MAAM,IAAI,GAAI,GAAG,OAAO,EAAE,UAAU,aAAa,CAAC,QAAQ,CAAC,wBAAa,CAAA"}
@@ -0,0 +1,2 @@
1
+ // will not generate its own element, similar to React's empty tags </>
2
+ export const Frag = (_, children) => children;
@@ -0,0 +1,3 @@
1
+ import { JsxValue } from "../types";
2
+ export declare const Group: (_: unknown, children: ReadonlyArray<JsxValue>) => any;
3
+ //# sourceMappingURL=Group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Group.d.ts","sourceRoot":"","sources":["../../src/std/Group.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAA;AAGjC,eAAO,MAAM,KAAK,GAAI,GAAG,OAAO,EAAE,UAAU,aAAa,CAAC,QAAQ,CAAC,QAElE,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { createElement } from "../create-element";
2
+ export const Group = (_, children) => (createElement("div", { style: { display: "contents" } }, children));
@@ -0,0 +1,12 @@
1
+ import { Exec, Provider } from "@opendaw/lib-std";
2
+ import { DomElement, JsxValue } from "../types";
3
+ import { Inject } from "../inject";
4
+ export type HotspotUpdater = {
5
+ update: Exec;
6
+ };
7
+ export type HotSpotProps = {
8
+ render: Provider<JsxValue>;
9
+ ref: Inject.Ref<HotspotUpdater>;
10
+ };
11
+ export declare const Hotspot: ({ render, ref }: HotSpotProps) => DomElement;
12
+ //# sourceMappingURL=Hotspot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hotspot.d.ts","sourceRoot":"","sources":["../../src/std/Hotspot.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAEhC,MAAM,MAAM,cAAc,GAAG;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,CAAA;AAC7C,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;CAAE,CAAA;AAE1F,eAAO,MAAM,OAAO,GAAI,iBAAe,YAAY,eAKlD,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { createElement, replaceChildren } from "../create-element";
2
+ export const Hotspot = ({ render, ref }) => {
3
+ const contents = createElement("div", { style: { display: "contents" } });
4
+ replaceChildren(contents, render());
5
+ ref.addTarget({ update: () => replaceChildren(contents, render()) });
6
+ return contents;
7
+ };
@@ -0,0 +1,4 @@
1
+ export declare const LocalLink: ({ href }: {
2
+ href: string;
3
+ }) => HTMLAnchorElement;
4
+ //# sourceMappingURL=LocalLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalLink.d.ts","sourceRoot":"","sources":["../../src/std/LocalLink.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,GAAI,UAAQ;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,sBAQgD,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { TerminatorUtils } from "@opendaw/lib-dom";
2
+ import { createElement } from "../create-element";
3
+ import { RouteLocation, RouteMatcher } from "../routes";
4
+ export const LocalLink = ({ href }) => TerminatorUtils
5
+ .watchWeak(createElement("a", { href: href, onclick: (event) => {
6
+ event.preventDefault();
7
+ RouteLocation.get().navigateTo(href);
8
+ }, link: true }), weakRef => RouteLocation.get().catchupAndSubscribe(location => weakRef.deref()?.classList.toggle("active", RouteMatcher.match(location.path, href))));
@@ -0,0 +1,5 @@
1
+ import { Terminable } from "@opendaw/lib-std";
2
+ export declare const Preloader: ({ color }: {
3
+ color?: string;
4
+ }) => Terminable;
5
+ //# sourceMappingURL=Preloader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Preloader.d.ts","sourceRoot":"","sources":["../../src/std/Preloader.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAqB3C,eAAO,MAAM,SAAS,GAAI,WAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,UAIvD,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { Html } from "@opendaw/lib-dom";
2
+ import { createElement } from "../create-element";
3
+ const className = Html.adoptStyleSheet(`
4
+ @keyframes fill {
5
+ from {width: 5%;}
6
+ to {width: 95%;}
7
+ }
8
+
9
+ component {
10
+ position: fixed;
11
+ top: 0;
12
+ left: 0;
13
+ width: 5%;
14
+ height: 2px;
15
+ animation: fill 3s ease-in-out forwards;
16
+ z-index: 999999;
17
+ }
18
+ `, "__preloader__");
19
+ export const Preloader = ({ color }) => {
20
+ const element = createElement("div", { className: className, style: { backgroundColor: color ?? "orange" } });
21
+ document.body.appendChild(element);
22
+ return { terminate: () => element.remove() };
23
+ };
@@ -0,0 +1,23 @@
1
+ import { Exec, Provider, Terminable, TerminableOwner } from "@opendaw/lib-std";
2
+ import { JsxValue } from "../types";
3
+ export type PageContext<SERVICE = never> = {
4
+ service: SERVICE;
5
+ lifecycle: TerminableOwner;
6
+ path: string;
7
+ error: string;
8
+ };
9
+ export type PageFactory<SERVICE = never> = (context: PageContext<SERVICE>) => JsxValue | Promise<JsxValue>;
10
+ export type RouterConstruct<SERVICE = never> = {
11
+ runtime: TerminableOwner;
12
+ service: SERVICE;
13
+ routes: Array<{
14
+ path: string;
15
+ factory: PageFactory<SERVICE>;
16
+ }>;
17
+ fallback: PageFactory<SERVICE>;
18
+ error?: PageFactory<SERVICE>;
19
+ preloader?: Provider<Terminable>;
20
+ onshow?: Exec;
21
+ };
22
+ export declare const Router: <SERVICE = never>({ runtime, service, routes, fallback, preloader, error, onshow }: RouterConstruct<SERVICE>) => HTMLDivElement;
23
+ //# sourceMappingURL=Router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/std/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAqB,QAAQ,EAAe,UAAU,EAAE,eAAe,EAAa,MAAM,kBAAkB,CAAA;AACxH,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAA;AAGjC,MAAM,MAAM,WAAW,CAAC,OAAO,GAAG,KAAK,IAAI;IACvC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,eAAe,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,OAAO,GAAG,KAAK,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE1G,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,KAAK,IAAI;IAC3C,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC,CAAA;IAC9D,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC5B,SAAS,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,IAAI,CAAA;CAChB,CAAA;AAUD,eAAO,MAAM,MAAM,GAAI,OAAO,GAAG,KAAK,EAAE,kEAQG,eAAe,CAAC,OAAO,CAAC,mBAqElE,CAAA"}
@@ -0,0 +1,73 @@
1
+ import { createElement, replaceChildren } from "../create-element";
2
+ import { isDefined, Option, safeExecute, Terminator } from "@opendaw/lib-std";
3
+ import { RouteLocation, RouteMatcher } from "../routes";
4
+ export const Router = ({ runtime, service, routes, fallback, preloader, error, onshow }) => {
5
+ const routing = RouteMatcher.create(routes);
6
+ const resolvePageFactory = (path) => routing
7
+ .resolve(path)
8
+ .mapOr(route => route.factory, () => fallback);
9
+ const container = createElement("div", { style: { display: "contents" } });
10
+ let loading = Option.None;
11
+ let showing = Option.None;
12
+ const fetchPage = async (pageFactory, path) => {
13
+ if (loading.nonEmpty()) {
14
+ const request = loading.unwrap();
15
+ request.preloader.ifSome(lifecycle => lifecycle.terminate());
16
+ request.state = "cancelled";
17
+ loading = Option.None;
18
+ }
19
+ const lifecycle = new Terminator();
20
+ const pageResult = pageFactory({
21
+ service,
22
+ lifecycle,
23
+ path,
24
+ error: ""
25
+ });
26
+ const content = pageResult instanceof Promise ? pageResult : Promise.resolve(pageResult);
27
+ const request = {
28
+ path,
29
+ content,
30
+ lifecycle,
31
+ preloader: Option.wrap(safeExecute(preloader)),
32
+ state: "loading"
33
+ };
34
+ loading = Option.wrap(request);
35
+ let element;
36
+ try {
37
+ element = await content;
38
+ }
39
+ catch (reason) {
40
+ console.warn(reason);
41
+ if (isDefined(error)) {
42
+ return fetchPage(error, path);
43
+ }
44
+ else {
45
+ alert(`Could not load page (${reason})`);
46
+ }
47
+ }
48
+ if (request.state === "cancelled") {
49
+ request.lifecycle.terminate();
50
+ }
51
+ else if (request.path === path) {
52
+ if (showing.nonEmpty()) {
53
+ showing.unwrap().lifecycle.terminate();
54
+ showing = Option.None;
55
+ }
56
+ if (loading.nonEmpty()) {
57
+ loading.unwrap().preloader.ifSome(lifecycle => lifecycle.terminate());
58
+ loading = Option.None;
59
+ }
60
+ replaceChildren(container, element);
61
+ showing = Option.wrap(request);
62
+ safeExecute(onshow);
63
+ }
64
+ };
65
+ runtime.own(RouteLocation.get()
66
+ .catchupAndSubscribe((location) => {
67
+ if (showing.unwrapOrNull()?.path === location.path) {
68
+ return;
69
+ }
70
+ return fetchPage(resolvePageFactory(location.path), location.path);
71
+ }));
72
+ return container;
73
+ };
@@ -0,0 +1,2 @@
1
+ export declare const SupportedSvgTags: Set<string>;
2
+ //# sourceMappingURL=supported-svg-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supported-svg-tags.d.ts","sourceRoot":"","sources":["../src/supported-svg-tags.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,aA+F3B,CAAA"}
@@ -0,0 +1,98 @@
1
+ // We cannot support tags that are used in html as well.
2
+ // TSX builds its DOM from the bottom up, meaning you have no information about the scope (html or svg).
3
+ export const SupportedSvgTags = new Set([
4
+ // "a",
5
+ "altGlyph",
6
+ "altGlyphDef",
7
+ "altGlyphItem",
8
+ "animate",
9
+ "animateColor",
10
+ "animateMotion",
11
+ "animateTransform",
12
+ "animation",
13
+ // "audio",
14
+ // "canvas",
15
+ "circle",
16
+ "clipPath",
17
+ "color-profile",
18
+ "cursor",
19
+ "defs",
20
+ "desc",
21
+ "discard",
22
+ "ellipse",
23
+ "feBlend",
24
+ "feColorMatrix",
25
+ "feComponentTransfer",
26
+ "feComposite",
27
+ "feConvolveMatrix",
28
+ "feDiffuseLighting",
29
+ "feDisplacementMap",
30
+ "feDistantLight",
31
+ "feDropShadow",
32
+ "feFlood",
33
+ "feFuncA",
34
+ "feFuncB",
35
+ "feFuncG",
36
+ "feFuncR",
37
+ "feGaussianBlur",
38
+ "feImage",
39
+ "feMerge",
40
+ "feMergeNode",
41
+ "feMorphology",
42
+ "feOffset",
43
+ "fePointLight",
44
+ "feSpecularLighting",
45
+ "feSpotLight",
46
+ "feTile",
47
+ "feTurbulence",
48
+ "filter",
49
+ "font",
50
+ "font-face",
51
+ "font-face-format",
52
+ "font-face-name",
53
+ "font-face-src",
54
+ "font-face-uri",
55
+ "foreignObject",
56
+ "g",
57
+ "glyph",
58
+ "glyphRef",
59
+ "handler",
60
+ "hkern",
61
+ // "iframe",
62
+ "image",
63
+ "line",
64
+ "linearGradient",
65
+ "listener",
66
+ "marker",
67
+ "mask",
68
+ "metadata",
69
+ "missing-glyph",
70
+ "mpath",
71
+ "path",
72
+ "pattern",
73
+ "polygon",
74
+ "polyline",
75
+ "prefetch",
76
+ "radialGradient",
77
+ "rect",
78
+ "script",
79
+ "set",
80
+ "solidColor",
81
+ "stop",
82
+ // "style",
83
+ "svg",
84
+ "switch",
85
+ "symbol",
86
+ "tbreak",
87
+ "text",
88
+ // "textArea",
89
+ "textPath",
90
+ "title",
91
+ "tref",
92
+ "tspan",
93
+ "unknown",
94
+ "use",
95
+ // "video",
96
+ "view",
97
+ "vkern"
98
+ ]);
@@ -0,0 +1,27 @@
1
+ import { Procedure } from "@opendaw/lib-std";
2
+ import { Inject } from "./inject";
3
+ export type DomElement = HTMLElement | SVGElement;
4
+ export type JsxValue = null | undefined | boolean | string | number | DomElement | Array<JsxValue>;
5
+ type AttributeMap = {
6
+ className?: string | Inject.ClassList;
7
+ style?: Partial<CSSStyleDeclaration>;
8
+ };
9
+ type ExtractProperties<T extends Element> = Partial<{
10
+ [K in keyof T]: K extends keyof AttributeMap ? AttributeMap[K] : K extends keyof GlobalEventHandlers ? GlobalEventHandlers[K] : T[K] extends Function ? never : (T[K] extends SVGAnimatedBoolean ? boolean | string : T[K] extends SVGAnimatedAngle ? number | string : T[K] extends SVGAnimatedLength ? number | string : T[K] extends number ? number | string : T[K] extends boolean ? boolean | string : string) | Inject.Attribute;
11
+ }> & {
12
+ ref?: Inject.Ref<T>;
13
+ onLoad?: Procedure<T>;
14
+ } & Record<string, unknown>;
15
+ declare global {
16
+ namespace JSX {
17
+ type IntrinsicElements = {
18
+ [K in keyof Omit<SVGElementTagNameMap, "a">]: ExtractProperties<Omit<SVGElementTagNameMap, "a">[K]>;
19
+ } & {
20
+ [K in keyof Omit<HTMLElementTagNameMap, "a">]: ExtractProperties<Omit<HTMLElementTagNameMap, "a">[K]>;
21
+ } & {
22
+ a: any;
23
+ };
24
+ }
25
+ }
26
+ export {};
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAE/B,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,UAAU,CAAA;AACjD,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;AAIlG,KAAK,YAAY,GAAG;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;CACvC,CAAA;AAED,KAAK,iBAAiB,CAAC,CAAC,SAAS,OAAO,IAAI,OAAO,CAAC;KAC/C,CAAC,IAAI,MAAM,CAAC,GACb,CAAC,SAAS,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,GAC1C,CAAC,SAAS,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,CAAC,CAAC,GACxD,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GACzB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAC/C,CAAC,CAAC,CAAC,CAAC,SAAS,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAC3C,CAAC,CAAC,CAAC,CAAC,SAAS,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAC5C,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GACjC,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,GAAG,MAAM,GACnC,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS;CAC7D,CAAC,GAAG;IACD,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;CACxB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE3B,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,GAAG,CAAC;QAEV,KAAK,iBAAiB,GAChB;aAAG,CAAC,IAAI,MAAM,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAAE,GACvG;aAAG,CAAC,IAAI,MAAM,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAAE,GAEzG;YAAE,CAAC,EAAE,GAAG,CAAA;SAAE,CAAA;KACnB;CACJ"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/weak.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare class WeakRefSet<T extends WeakKey> {
2
+ #private;
3
+ add(value: T): void;
4
+ forEach(callback: (value: T) => void): void;
5
+ clear(): void;
6
+ }
7
+ //# sourceMappingURL=weak.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weak.d.ts","sourceRoot":"","sources":["../src/weak.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU,CAAC,CAAC,SAAS,OAAO;;IAGrC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAEnB,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI;IAW3C,KAAK,IAAI,IAAI;CAChB"}
package/dist/weak.js ADDED
@@ -0,0 +1,16 @@
1
+ export class WeakRefSet {
2
+ #set = new Set();
3
+ add(value) { this.#set.add(new WeakRef(value)); }
4
+ forEach(callback) {
5
+ for (const weakRef of this.#set) {
6
+ const value = weakRef.deref();
7
+ if (value === undefined) {
8
+ this.#set.delete(weakRef);
9
+ }
10
+ else {
11
+ callback(value);
12
+ }
13
+ }
14
+ }
15
+ clear() { this.#set.clear(); }
16
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@opendaw/lib-jsx",
3
+ "version": "0.0.6",
4
+ "license": "LGPL-3.0-or-later",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/**/*"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "lint": "eslint \"**/*.ts\"",
22
+ "test": "echo \"No tests to run\""
23
+ },
24
+ "dependencies": {
25
+ "@opendaw/lib-dom": "^0.0.6",
26
+ "@opendaw/lib-std": "^0.0.6"
27
+ },
28
+ "devDependencies": {
29
+ "@opendaw/eslint-config": "^0.0.6",
30
+ "@opendaw/typescript-config": "^0.0.6"
31
+ },
32
+ "gitHead": "04e5363a9851c7e116a306c2e933c5f410980fbe"
33
+ }