dothtml-interfaces 0.4.6 → 1.0.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.
Files changed (27) hide show
  1. package/README.md +3 -3
  2. package/package.json +6 -4
  3. package/src/bindings/{i-binding.d.ts → i-binding.ts} +11 -11
  4. package/src/bindings/{i-observer.d.ts → i-observer.ts} +2 -2
  5. package/src/bindings/{i-reactive.d.ts → i-reactive.ts} +4 -4
  6. package/src/bindings/i-ref.ts +5 -0
  7. package/src/bindings/{i-watcher.d.ts → i-watcher.ts} +52 -38
  8. package/src/{i-dot-component.d.ts → i-dot-component.ts} +113 -84
  9. package/src/{i-dot.d.ts → i-dot.ts} +1041 -1047
  10. package/src/{i-event-bus.d.ts → i-event-bus.ts} +10 -10
  11. package/src/{index.d.ts → index.ts} +14 -14
  12. package/src/styles/at-rules/{i-at-color-profile-builder.d.ts → i-at-color-profile-builder.ts} +4 -4
  13. package/src/styles/at-rules/{i-at-counter-style-builder.d.ts → i-at-counter-style-builder.ts} +14 -14
  14. package/src/styles/at-rules/{i-at-font-family-builder.d.ts → i-at-font-family-builder.ts} +18 -18
  15. package/src/styles/at-rules/{i-at-font-palette-values.d.ts → i-at-font-palette-values.ts} +5 -5
  16. package/src/styles/at-rules/{i-at-keyframes-builder.d.ts → i-at-keyframes-builder.ts} +7 -7
  17. package/src/styles/at-rules/{i-at-page-builder.d.ts → i-at-page-builder.ts} +19 -19
  18. package/src/styles/complex-css-types/{i-filter-prop.d.ts → i-filter-prop.ts} +19 -19
  19. package/src/styles/complex-css-types/{i-shadow-prop.d.ts → i-shadow-prop.ts} +11 -11
  20. package/src/styles/complex-css-types/{i-transformation-prop.d.ts → i-transformation-prop.ts} +32 -32
  21. package/src/styles/{css-types.d.ts → css-types.ts} +141 -141
  22. package/src/styles/{i-css-prop.d.ts → i-css-prop.ts} +295 -295
  23. package/src/styles/{i-dot-css.d.ts → i-dot-css.ts} +218 -214
  24. package/src/styles/mapped-types/{angle-prop.d.ts → angle-prop.ts} +15 -15
  25. package/src/styles/mapped-types/{color-props.d.ts → color-props.ts} +60 -60
  26. package/src/styles/mapped-types/{length-prop.d.ts → length-prop.ts} +21 -19
  27. package/src/bindings/i-ref.d.ts +0 -4
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
-
2
- # DOThtml Interfaces
3
-
1
+
2
+ # DOThtml Interfaces
3
+
4
4
  DOThtml interfaces allows DOThtml to be used in projects requiring dependency injection!
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "dothtml-interfaces",
3
- "version": "0.4.6",
3
+ "version": "1.0.0",
4
4
  "description": "Dependency injection interfaces for DOTHtml.",
5
- "main": "src/index.d.ts",
6
- "types": "src/index.d.ts",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
7
  "scripts": {},
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "devDependencies": {
11
11
  "typescript": "^5.3.2"
12
12
  },
13
- "exports": "./src/index.d.ts",
13
+ "exports": {
14
+ ".": "./src/index.ts"
15
+ },
14
16
  "files": [
15
17
  "src/**/*"
16
18
  ]
@@ -1,12 +1,12 @@
1
- import { IWatcher } from "./i-watcher";
2
-
3
- export interface IBinding<T = any, Td = T>{
4
- _source: IWatcher<T>;
5
- _get: ()=>Td;
6
- _set: (v: string|number|boolean)=>void;
7
-
8
- _transform: {
9
- display?: (v: T)=>Td;
10
- read?: (v: string)=>T;
11
- }
1
+ import { IWatcher } from "./i-watcher";
2
+
3
+ export interface IBinding<T = any, Td = T>{
4
+ _source: IWatcher<T>;
5
+ _get: ()=>Td;
6
+ _set: (v: string|number|boolean)=>void;
7
+
8
+ _transform: {
9
+ display?: (v: T)=>Td;
10
+ read?: (v: string)=>T;
11
+ }
12
12
  }
@@ -1,3 +1,3 @@
1
- export interface IObserver<T = any>{
2
- observerUpdate(value: T, obsreverId: number): void;
1
+ export interface IObserver<T = any>{
2
+ observerUpdate(value: T, obsreverId: number): void;
3
3
  }
@@ -1,4 +1,4 @@
1
- import { IBinding } from "./i-binding";
2
- import { IWatcher } from "./i-watcher";
3
-
4
- export type IReactive = IBinding|IWatcher;
1
+ import { IBinding } from "./i-binding";
2
+ import { IWatcher } from "./i-watcher";
3
+
4
+ export type IReactive<T = any> = IBinding<any, T>|IWatcher<T>;
@@ -0,0 +1,5 @@
1
+ import { IWatcher } from "./i-watcher";
2
+
3
+ export interface IRef<T = any> extends IWatcher<T | null> {
4
+ get element(): T;
5
+ }
@@ -1,38 +1,52 @@
1
- import { IBinding } from "./i-binding";
2
-
3
- export interface IWatcher<T = any>{
4
- // Get the value.
5
- get value(): T;
6
- // Set the value.
7
- set value(v: T|null|undefined);
8
-
9
- // Key is used for observable array proxy bindings.
10
- // If a key is provided, it's used to uniquely identify array elements.
11
- // If a key is not provided, identification is done automatically by the framework by comparing object references.
12
- key: string;
13
- // subscribeNode(node: Node): number;
14
- // subscribeAttr(node: HTMLElement, attributeName: string): number;
15
- // subscribeCallback(callback: (value: T)=>void): number;
16
- // detachBinding(id: number);
17
-
18
- /**
19
- * Subscribe to changes in the reactive object.
20
- */
21
- subscribe(callback: Function): number;
22
-
23
- _subscribe(boundReactive: IBinding, item: any);
24
- _detachBinding(id: number);
25
-
26
- /**
27
- * Called manually by the user to trigger an update.
28
- * Useful for arrays and objects.
29
- */
30
- updateObservers(): void;
31
-
32
- bindAs<Td = string>(transform: (((v: T)=>Td)|({
33
- display?: (v: T)=>Td;
34
- read?: (v: string)=>T;
35
- }))): IBinding<T, Td>;
36
-
37
- bind(): IBinding<T>;
38
- }
1
+ import { IBinding } from "./i-binding";
2
+
3
+ export interface IWatcher<T = any>{
4
+ /**
5
+ * Gets or sets the current value of the signal.
6
+ * Accessing this property inside a computed signal or effect automatically registers it as a dependency.
7
+ */
8
+ get value(): T;
9
+ set value(v: T|null|undefined);
10
+ getValue(): T;
11
+ getValue(): T;
12
+
13
+ // Key is used for observable array proxy bindings.
14
+ // If a key is provided, it's used to uniquely identify array elements.
15
+ // If a key is not provided, identification is done automatically by the framework by comparing object references.
16
+ key: string;
17
+ // subscribeNode(node: Node): number;
18
+ // subscribeAttr(node: HTMLElement, attributeName: string): number;
19
+ // subscribeCallback(callback: (value: T)=>void): number;
20
+ // detachBinding(id: number);
21
+
22
+ /**
23
+ * Subscribe to changes in the reactive object.
24
+ */
25
+ subscribe(callback: Function): number;
26
+
27
+ _subscribe(boundReactive: IBinding, item: any);
28
+ _detachBinding(id: number);
29
+
30
+ /**
31
+ * Called manually by the user to trigger an update.
32
+ * Useful for arrays and objects.
33
+ */
34
+ updateObservers(): void;
35
+
36
+ bindAs<Td = string>(transform: (((v: T)=>Td)|({
37
+ display?: (v: T)=>Td;
38
+ read?: (v: string)=>T;
39
+ }))): IBinding<T, Td>;
40
+
41
+ bind(): IBinding<T>;
42
+ unsubscribe(id: number): void;
43
+ refresh(priority?: any): void;
44
+
45
+ /**
46
+ * Sets a new value for the signal.
47
+ * Equivalent to setting the `.value` property, but allows specifying an update priority.
48
+ * @param v The new value.
49
+ * @param priority Optional update priority.
50
+ */
51
+ setValue(v: T, priority?: any): void;
52
+ }
@@ -1,84 +1,113 @@
1
-
2
- import { IDotCore, IDotDocument } from "./i-dot";
3
-
4
- // export type EventNames<T> = T extends { allowedEvents: infer E } ? E : never;
5
-
6
- // TODO: I think this could be typed so that it forces you to emit events from the list of strings.
7
- export interface FrameworkItems {
8
- /**
9
- * The shadow root element of the component.
10
- */
11
- readonly refs: { [key: string]: HTMLElement };
12
- emit<T>(event: string, ...args: Array<any>): void;
13
- restyle(): void;
14
- readonly props: Record<string, any>;
15
- readonly _meta: {
16
- readonly allowedEvents: string[];
17
- readonly shadowRoot: ShadowRoot;
18
- readonly isRendered: boolean;
19
- readonly tagName: string;
20
- // readonly styles: Array<string>; // Can't have this anymore because it's a memory leak.
21
- readonly args: Array<any>;
22
- // readonly styleElement: HTMLStyleElement;
23
- readonly sharedStyles: CSSStyleSheet[];
24
- }
25
- // css: IDotCss;
26
- // html: IDotGenericElement;
27
- }
28
-
29
-
30
- // TODO: there's a weird problem where if a constructor is not provided, it's not possible have a custom builder.
31
- // It should be the contsructor that depends on the builder, not the other way around. If we can't get this working,
32
- // it might just be better to rethink how stuff gets passed into components.
33
- export default interface IDotComponent/*<TProps extends Array<string> = [], TEvents extends Array<string> = []>*/ {
34
-
35
- readonly _?: FrameworkItems;
36
-
37
- // Regrettably, TS forces clients to implement the constructor, which is not ideal because we want to internalize that.
38
- // There's no way to make the constructor optional.
39
- // new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents>;
40
- // new (): IComponent<TProps, TEvents>;
41
-
42
- // Lifecycle hooks
43
-
44
- /**
45
- * A function returning DOThtml (required). The `build` hook is called once per component instance, and constructs the component's virtual DOM.
46
- * @param dot - The DOThtml core object passed in for DI purposes. You can also just use the main .
47
- * @returns The DOThtml document representing the component's virtual DOM. */
48
- build(dot: IDotCore): IDotDocument;
49
-
50
- /**
51
- * An optional function called after the component is built. Is only called once per component instance.
52
- */
53
- built?(): void;
54
-
55
- /**
56
- * An optional function that gets called before the component is mounted.
57
- */
58
- mounting?(): void;
59
-
60
- /**
61
- * An optional function called after the element has been mounted. May be called mulitple times if the component is rerendered.
62
- */
63
- mounted?(): void;
64
-
65
- /**
66
- * An optional function that gets called before the component is unmounted. Use it to do custom cleanup or data saving.
67
- */
68
- unmounting?(): void;
69
-
70
- /**
71
- * An optional function called after the element has been unmounted. May be called mulitple times if the component is rerendered.
72
- */
73
- unmounted?(): void;
74
-
75
- /**
76
- * A function that returns a string containing CSS rules to be applied to all instances of the component.
77
- * It will only be called exactly once per component. We use a function so that you can return a potentially
78
- * large string containing CSS without introducing a memory leak. The reason it's not static is so that
79
- * it will work in JavaScript, and because static members are not valid in DI interfaces. All styles are scoped
80
- * to the component's shadow DOM.
81
- * @returns A string (or array of strings) containing imported CSS rules.
82
- */
83
- stylize?(): string|Array<string>;
84
- }
1
+
2
+ import { IDotCore, IDotDocument } from "./i-dot";
3
+
4
+ // export type EventNames<T> = T extends { allowedEvents: infer E } ? E : never;
5
+
6
+ // TODO: I think this could be typed so that it forces you to emit events from the list of strings.
7
+ export interface FrameworkItems {
8
+ /**
9
+ * The shadow root element of the component.
10
+ */
11
+ readonly refs: { [key: string]: HTMLElement };
12
+ emit<T>(event: string, ...args: Array<any>): void;
13
+ restyle(): void;
14
+ readonly props: Record<string, any>;
15
+ readonly cvdom: any;
16
+ readonly _meta: {
17
+ readonly allowedEvents: string[];
18
+ readonly shadowRoot: ShadowRoot;
19
+ readonly isRendered: boolean;
20
+ readonly tagName: string;
21
+ readonly args: Array<any>;
22
+ readonly sharedStyles: CSSStyleSheet[];
23
+ }
24
+ }
25
+
26
+
27
+ // TODO: there's a weird problem where if a constructor is not provided, it's not possible have a custom builder.
28
+ // It should be the contsructor that depends on the builder, not the other way around. If we can't get this working,
29
+ // it might just be better to rethink how stuff gets passed into components.
30
+ export default interface IDotComponent/*<TProps extends Array<string> = [], TEvents extends Array<string> = []>*/ {
31
+
32
+ readonly _?: FrameworkItems;
33
+ props?: any;
34
+ slots?: Record<string, any>;
35
+
36
+ /**
37
+ * Registers a side effect that is automatically cleaned up when the component is unmounted.
38
+ * @param callback The side effect to run. Can return a cleanup function.
39
+ */
40
+ effect?(callback: () => void | (() => void)): void;
41
+
42
+ // Regrettably, TS forces clients to implement the constructor, which is not ideal because we want to internalize that.
43
+ // There's no way to make the constructor optional.
44
+ // new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents>;
45
+ // new (): IComponent<TProps, TEvents>;
46
+
47
+ // Lifecycle hooks
48
+
49
+ /**
50
+ * A function returning DOThtml (required). The `build` hook is called once per component instance, and constructs the component's virtual DOM.
51
+ * @param dot - The DOThtml core object passed in for DI purposes. You can also just use the main .
52
+ * @returns The DOThtml document representing the component's virtual DOM. */
53
+ build(dot: IDotCore): IDotDocument;
54
+
55
+ /**
56
+ * An optional function called after the component is built. Is only called once per component instance.
57
+ */
58
+ built?(): void;
59
+
60
+ /**
61
+ * An optional function that gets called before the component is mounted.
62
+ */
63
+ mounting?(): void;
64
+
65
+ /**
66
+ * An optional function called after the element has been mounted. May be called mulitple times if the component is rerendered.
67
+ */
68
+ mounted?(): void;
69
+
70
+ /**
71
+ * An optional function that gets called before the component is unmounted. Use it to do custom cleanup or data saving.
72
+ */
73
+ unmounting?(): void;
74
+
75
+ /**
76
+ * An optional function called after the element has been unmounted. May be called mulitple times if the component is rerendered.
77
+ */
78
+ unmounted?(): void;
79
+
80
+ /**
81
+ * An optional function called after the component has entered the DOM.
82
+ */
83
+ onEnter?(): void;
84
+
85
+ /**
86
+ * An optional function called before the component leaves the DOM.
87
+ * If it returns a Promise, the VDOM engine will wait for it to resolve before removing the component.
88
+ */
89
+ onLeave?(): Promise<void> | void;
90
+
91
+ /**
92
+ * A function that returns a string containing CSS rules to be applied to all instances of the component.
93
+ * It will only be called exactly once per component. We use a function so that you can return a potentially
94
+ * large string containing CSS without introducing a memory leak. The reason it's not static is so that
95
+ * it will work in JavaScript, and because static members are not valid in DI interfaces. All styles are scoped
96
+ * to the component's shadow DOM.
97
+ * @returns A string (or array of strings) containing imported CSS rules.
98
+ */
99
+ stylize?(s?: any): string | string[] | any;
100
+
101
+ /**
102
+ * An optional function that allows you to apply styles directly to the component's host element.
103
+ */
104
+ hostStyle?(s: any): void;
105
+
106
+ /**
107
+ * An optional function that gets called when an error occurs during the component's lifecycle.
108
+ * If implemented, the component acts as an error boundary.
109
+ * @param error - The error that occurred.
110
+ * @returns The DOThtml document to render as a fallback UI.
111
+ */
112
+ errorCaught?(error: any): IDotDocument | void;
113
+ }