@tempots/dom 9.0.1 → 10.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 (129) hide show
  1. package/README.md +6 -1
  2. package/{components → dom}/animatable.d.ts +7 -1
  3. package/dom/attr.d.ts +73 -0
  4. package/dom/dom-context.d.ts +108 -0
  5. package/dom/dom-utils.d.ts +21 -0
  6. package/dom/handle-anchor-click.d.ts +13 -0
  7. package/dom/ssr-tracker.d.ts +1 -0
  8. package/dom/ssr.d.ts +8 -0
  9. package/index.cjs +1 -0
  10. package/index.d.ts +52 -34
  11. package/index.js +1397 -31
  12. package/mountable/appearance.d.ts +38 -0
  13. package/mountable/async.d.ts +7 -0
  14. package/mountable/attribute.d.ts +489 -0
  15. package/mountable/autofocus.d.ts +3 -0
  16. package/mountable/autoselect.d.ts +3 -0
  17. package/mountable/bind.d.ts +16 -0
  18. package/mountable/conjunction.d.ts +8 -0
  19. package/mountable/consumers.d.ts +12 -0
  20. package/mountable/ctx.d.ts +3 -0
  21. package/mountable/domel.d.ts +3 -0
  22. package/mountable/element.d.ts +236 -0
  23. package/mountable/empty.d.ts +3 -0
  24. package/mountable/ensure.d.ts +4 -0
  25. package/mountable/foreach.d.ts +5 -0
  26. package/mountable/fragment.d.ts +3 -0
  27. package/mountable/handler.d.ts +102 -0
  28. package/mountable/hidden-when-empty.d.ts +3 -0
  29. package/mountable/html-title.d.ts +3 -0
  30. package/mountable/inviewport.d.ts +6 -0
  31. package/mountable/map-signal.d.ts +4 -0
  32. package/mountable/not-empty.d.ts +4 -0
  33. package/mountable/ondispose.d.ts +4 -0
  34. package/mountable/oneof.d.ts +22 -0
  35. package/mountable/onmount.d.ts +3 -0
  36. package/mountable/portal.d.ts +4 -0
  37. package/mountable/providers.d.ts +16 -0
  38. package/mountable/render.d.ts +8 -0
  39. package/mountable/repeat.d.ts +5 -0
  40. package/mountable/size.d.ts +8 -0
  41. package/mountable/style.d.ts +504 -0
  42. package/mountable/task.d.ts +7 -0
  43. package/mountable/text.d.ts +6 -0
  44. package/mountable/when.d.ts +4 -0
  45. package/package.json +15 -8
  46. package/std/interpolate.d.ts +5 -0
  47. package/std/position.d.ts +9 -0
  48. package/std/signal.d.ts +120 -0
  49. package/types/aria-attributes.d.ts +50 -0
  50. package/types/css-styles.d.ts +3 -0
  51. package/types/domain.d.ts +14 -0
  52. package/types/html-attributes.d.ts +115 -0
  53. package/types/html-events.d.ts +89 -0
  54. package/types/html-tags.d.ts +113 -0
  55. package/types/mathml-attributes.d.ts +50 -0
  56. package/types/mathml-tags.d.ts +30 -0
  57. package/types/svg-attributes.d.ts +243 -0
  58. package/types/svg-tags.d.ts +64 -0
  59. package/clean.d.ts +0 -2
  60. package/clean.js +0 -1
  61. package/components/Attribute.d.ts +0 -15
  62. package/components/Attribute.js +0 -16
  63. package/components/Autofocus.d.ts +0 -2
  64. package/components/Autofocus.js +0 -4
  65. package/components/BooleanAttribute.d.ts +0 -15
  66. package/components/BooleanAttribute.js +0 -16
  67. package/components/ClassName.d.ts +0 -13
  68. package/components/ClassName.js +0 -14
  69. package/components/El.d.ts +0 -15
  70. package/components/El.js +0 -21
  71. package/components/FadeIn.d.ts +0 -20
  72. package/components/FadeIn.js +0 -54
  73. package/components/FadeOut.d.ts +0 -16
  74. package/components/FadeOut.js +0 -39
  75. package/components/For.d.ts +0 -18
  76. package/components/For.js +0 -27
  77. package/components/Fragment.d.ts +0 -12
  78. package/components/Fragment.js +0 -16
  79. package/components/HiddenWhenEmpty.d.ts +0 -7
  80. package/components/HiddenWhenEmpty.js +0 -13
  81. package/components/If.d.ts +0 -14
  82. package/components/If.js +0 -19
  83. package/components/InnerHTML.d.ts +0 -13
  84. package/components/InnerHTML.js +0 -23
  85. package/components/Lifecycle.d.ts +0 -14
  86. package/components/Lifecycle.js +0 -18
  87. package/components/NotEmpty.d.ts +0 -9
  88. package/components/NotEmpty.js +0 -11
  89. package/components/On.d.ts +0 -15
  90. package/components/On.js +0 -14
  91. package/components/OnRemove.d.ts +0 -6
  92. package/components/OnRemove.js +0 -4
  93. package/components/OneOf.d.ts +0 -62
  94. package/components/OneOf.js +0 -68
  95. package/components/Portal.d.ts +0 -15
  96. package/components/Portal.js +0 -20
  97. package/components/Property.d.ts +0 -15
  98. package/components/Property.js +0 -16
  99. package/components/Provider.d.ts +0 -28
  100. package/components/Provider.js +0 -44
  101. package/components/Repeat.d.ts +0 -28
  102. package/components/Repeat.js +0 -146
  103. package/components/Show.d.ts +0 -15
  104. package/components/Show.js +0 -8
  105. package/components/Text.d.ts +0 -15
  106. package/components/Text.js +0 -33
  107. package/components/TextContent.d.ts +0 -13
  108. package/components/TextContent.js +0 -23
  109. package/components/animatable.js +0 -283
  110. package/dom-context.d.ts +0 -39
  111. package/dom-context.js +0 -263
  112. package/helpers/handle-anchor-click.d.ts +0 -4
  113. package/helpers/handle-anchor-click.js +0 -43
  114. package/helpers/handle-text-input.d.ts +0 -1
  115. package/helpers/handle-text-input.js +0 -4
  116. package/helpers/is-empty-element.d.ts +0 -2
  117. package/helpers/is-empty-element.js +0 -8
  118. package/jsx-dev-runtime.d.ts +0 -1
  119. package/jsx-dev-runtime.js +0 -1
  120. package/jsx-runtime.d.ts +0 -9
  121. package/jsx-runtime.js +0 -157
  122. package/jsx.d.ts +0 -806
  123. package/jsx.js +0 -1
  124. package/prop.d.ts +0 -58
  125. package/prop.js +0 -256
  126. package/render.d.ts +0 -3
  127. package/render.js +0 -7
  128. package/renderable.d.ts +0 -5
  129. package/renderable.js +0 -1
package/jsx.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/prop.d.ts DELETED
@@ -1,58 +0,0 @@
1
- export type ArgsToSignals<T extends [...unknown[]]> = T extends [] ? [] : T extends [infer U, ...infer V] ? [Signal<U>, ...ArgsToSignals<V>] : [];
2
- declare const $isSignal: unique symbol;
3
- declare const $isProp: unique symbol;
4
- export type Value<T> = T | Signal<T>;
5
- export declare class Signal<T> {
6
- protected _value: T;
7
- static of<T>(value: T): Signal<T>;
8
- static ofValue<T>(value: Value<T> | null | undefined): Signal<T> | undefined;
9
- static wrap<T>(value: T | Signal<T>): Signal<T>;
10
- static isSignal<T = unknown>(x: unknown): x is Signal<T>;
11
- static unwrap<T>(value: Value<T>): T;
12
- /**
13
- * Combines many into one using a merging function
14
- */
15
- static combine<Args extends [...unknown[]], Out>(signals: ArgsToSignals<Args>, f: (...args: Args) => Out): Signal<Out>;
16
- readonly [$isSignal] = true;
17
- protected readonly _listeners: Array<(value: T) => void>;
18
- constructor(_value: T);
19
- readonly get: () => T;
20
- readonly subscribe: (listener: (value: T) => void) => () => void;
21
- readonly map: <V>(f: (value: T) => V) => Signal<V>;
22
- readonly flatMap: <V>(f: (value: T) => Signal<V>) => Signal<V>;
23
- readonly flatMapProp: <V>(f: (value: T) => Prop<V>) => Prop<V>;
24
- readonly tap: (f: (value: T) => void) => this;
25
- readonly at: <K extends keyof T>(key: K) => Signal<T[K]>;
26
- readonly filter: (predicate: (value: T) => boolean) => Signal<T>;
27
- readonly distinct: (equality: (a: T, b: T) => boolean) => Signal<T>;
28
- readonly mapAsync: <V>(f: (value: T) => Promise<V>, alt: V) => Signal<V>;
29
- readonly mapMaybe: <V>(f: (value: T) => V | null | undefined, alt: V) => Signal<V>;
30
- readonly combine: <V, Z>(other: Signal<V>, f: (a: T, b: V) => Z) => Signal<Z>;
31
- readonly feed: (prop: Prop<T>) => () => void;
32
- readonly deriveProp: () => Prop<T>;
33
- readonly clean: () => void;
34
- readonly count: () => Signal<number>;
35
- readonly animate: (duration: number, interpolate: (start: T, end: T, delta: number) => T, initialValue?: T | null, easing?: (t: number) => number) => Signal<T>;
36
- readonly equals: (other: Signal<T>, equality?: ((a: T, b: T) => boolean) | undefined) => Signal<boolean>;
37
- readonly isNull: () => Signal<boolean>;
38
- readonly isNotNull: () => Signal<boolean>;
39
- readonly isEmpty: () => Signal<boolean>;
40
- readonly isNotEmpty: () => Signal<boolean>;
41
- }
42
- export declare class Prop<T> extends Signal<T> {
43
- static isProp<T = unknown>(x: unknown): x is Prop<T>;
44
- static of<T>(value: T): Prop<T>;
45
- static ofStorage<T>(key: string, defaultValue: T, store: {
46
- getItem: (key: string) => string | null;
47
- setItem: (key: string, value: string) => void;
48
- }, serialize?: (v: T) => string, deserilize?: (v: string) => T): Prop<T>;
49
- static ofLocalStorage<T>(key: string, defaultValue: T, serialize?: (v: T) => string, deserilize?: (v: string) => T): Prop<T>;
50
- static ofSessionStorage<T>(key: string, defaultValue: T, serialize?: (v: T) => string, deserilize?: (v: string) => T): Prop<T>;
51
- readonly [$isProp] = true;
52
- readonly set: (value: T) => void;
53
- readonly update: (f: (value: T) => T) => void;
54
- readonly atLens: <K extends keyof T>(key: K) => Prop<T[K]>;
55
- readonly reducer: <V>(f: (state: T, action: V) => T) => (action: V) => void;
56
- readonly iso: <V>(map: (value: T) => V, reverse: (value: V) => T) => Prop<V>;
57
- }
58
- export {};
package/prop.js DELETED
@@ -1,256 +0,0 @@
1
- const $isSignal = Symbol('isSignal');
2
- const $isProp = Symbol('isProp');
3
- export class Signal {
4
- _value;
5
- static of(value) {
6
- return new Signal(value);
7
- }
8
- static ofValue(value) {
9
- return value == null ? undefined : Signal.wrap(value);
10
- }
11
- static wrap(value) {
12
- return Signal.isSignal(value) ? value : new Signal(value);
13
- }
14
- static isSignal(x) {
15
- const s = x;
16
- return s != null && typeof s.get === 'function' && typeof s.subscribe === 'function';
17
- }
18
- static unwrap(value) {
19
- return (Signal.isSignal(value) ? value.get() : value);
20
- }
21
- /**
22
- * Combines many into one using a merging function
23
- */
24
- static combine(signals, f) {
25
- function getValues(others) {
26
- return others.map(other => other.get());
27
- }
28
- const prop = new Prop(f(...getValues(signals)));
29
- signals.forEach((other) => {
30
- other.subscribe(() => {
31
- prop.set(f(...getValues(signals)));
32
- });
33
- });
34
- return prop;
35
- }
36
- [$isSignal] = true;
37
- _listeners = [];
38
- constructor(_value) {
39
- this._value = _value;
40
- }
41
- get = () => {
42
- return this._value;
43
- };
44
- subscribe = (listener) => {
45
- this._listeners.push(listener);
46
- return () => {
47
- const index = this._listeners.indexOf(listener);
48
- if (index >= 0) {
49
- this._listeners.splice(index, 1);
50
- }
51
- };
52
- };
53
- map = (f) => {
54
- const prop = new Prop(f(this._value));
55
- this.subscribe(value => { prop.set(f(value)); });
56
- return prop;
57
- };
58
- flatMap = (f) => {
59
- let signal = f(this._value);
60
- const prop = new Prop(signal.get());
61
- this.subscribe(value => {
62
- signal.clean();
63
- signal = f(value);
64
- signal.subscribe(value => { prop.set(value); });
65
- });
66
- return prop;
67
- };
68
- flatMapProp = (f) => {
69
- let tprop = f(this._value);
70
- const prop = Prop.of(tprop.get());
71
- let cancel = prop.feed(tprop);
72
- this.subscribe(value => {
73
- cancel();
74
- tprop = f(value);
75
- prop.set(tprop.get());
76
- cancel = prop.feed(tprop);
77
- });
78
- return prop;
79
- };
80
- tap = (f) => {
81
- f(this._value);
82
- this.subscribe(f);
83
- return this;
84
- };
85
- at = (key) => {
86
- return this.map(value => value[key]);
87
- };
88
- filter = (predicate) => {
89
- const prop = new Prop(this._value);
90
- this.subscribe(value => {
91
- if (predicate(value)) {
92
- prop.set(value);
93
- }
94
- });
95
- return prop;
96
- };
97
- distinct = (equality) => {
98
- let lastValue = this._value;
99
- return this.filter(value => {
100
- const result = !equality(value, lastValue);
101
- lastValue = value;
102
- return result;
103
- });
104
- };
105
- mapAsync = (f, alt) => {
106
- let counter = 0;
107
- const prop = new Prop(alt);
108
- f(this._value)
109
- .then(value => {
110
- if (counter === 0)
111
- prop.set(value);
112
- })
113
- .catch(e => {
114
- throw e;
115
- });
116
- this.subscribe(value => {
117
- const matchCounter = ++counter;
118
- f(value)
119
- .then(value => {
120
- if (matchCounter === counter) {
121
- prop.set(value);
122
- }
123
- })
124
- .catch(e => {
125
- throw e;
126
- });
127
- });
128
- return prop;
129
- };
130
- mapMaybe = (f, alt) => {
131
- const prop = new Prop(f(this._value) ?? alt);
132
- this.subscribe(value => {
133
- const newValue = f(value);
134
- if (newValue != null)
135
- prop.set(newValue);
136
- });
137
- return prop;
138
- };
139
- combine = (other, f) => {
140
- const prop = new Prop(f(this._value, other.get()));
141
- this.subscribe(value => { prop.set(f(value, other.get())); });
142
- other.subscribe(value => { prop.set(f(this._value, value)); });
143
- return prop;
144
- };
145
- feed = (prop) => {
146
- return this.subscribe(value => { prop.set(value); });
147
- };
148
- deriveProp = () => {
149
- const prop = new Prop(this._value);
150
- this.feed(prop);
151
- return prop;
152
- };
153
- clean = () => {
154
- this._listeners.length = 0;
155
- };
156
- count = () => {
157
- let count = 0;
158
- return this.map(() => ++count);
159
- };
160
- animate = (duration, interpolate, initialValue = null, easing = t => t) => {
161
- let startValue = initialValue ?? this.get();
162
- let endValue = this.get();
163
- const prop = new Prop(startValue);
164
- let startTime = 0;
165
- let endTime = 0;
166
- let animationFrame = null;
167
- const animate = (time) => {
168
- if (this._listeners.length === 0) {
169
- animationFrame = null;
170
- return;
171
- }
172
- if (time < endTime) {
173
- const delta = (time - startTime) / (endTime - startTime);
174
- prop.set(interpolate(startValue, endValue, easing(delta)));
175
- animationFrame = requestAnimationFrame(animate);
176
- }
177
- else {
178
- prop.set(endValue);
179
- animationFrame = null;
180
- }
181
- };
182
- this.subscribe(value => {
183
- if (animationFrame != null)
184
- cancelAnimationFrame(animationFrame);
185
- if (this._listeners.length === 0) {
186
- animationFrame = null;
187
- return;
188
- }
189
- startValue = prop.get();
190
- endValue = value;
191
- startTime = performance.now();
192
- endTime = startTime + duration;
193
- animationFrame = requestAnimationFrame(animate);
194
- });
195
- return prop;
196
- };
197
- equals = (other, equality) => {
198
- return this.combine(other, (a, b) => {
199
- if (equality != null)
200
- return equality(a, b);
201
- return a === b;
202
- });
203
- };
204
- isNull = () => this.map(value => value == null);
205
- isNotNull = () => this.map(value => value != null);
206
- isEmpty = () => this.map(value => value == null || (Reflect.has(value, 'length') && Reflect.get(value, 'length') === 0));
207
- isNotEmpty = () => this.map(value => value != null && (!Reflect.has(value, 'length') || Reflect.get(value, 'length') !== 0));
208
- }
209
- export class Prop extends Signal {
210
- static isProp(x) {
211
- const p = x;
212
- return Signal.isSignal(x) && typeof p.set === 'function';
213
- // return x != null && (x as Prop<T>)[$isProp] === true
214
- }
215
- static of(value) {
216
- return new Prop(value);
217
- }
218
- static ofStorage(key, defaultValue, store, serialize = JSON.stringify, deserilize = JSON.parse) {
219
- const initialValue = store.getItem(key);
220
- const prop = new Prop(initialValue !== null ? deserilize(initialValue) : defaultValue);
221
- prop.subscribe((value) => {
222
- store.setItem(key, serialize(value));
223
- });
224
- return prop;
225
- }
226
- static ofLocalStorage(key, defaultValue, serialize = JSON.stringify, deserilize = JSON.parse) {
227
- return Prop.ofStorage(key, defaultValue, window.localStorage, serialize, deserilize);
228
- }
229
- static ofSessionStorage(key, defaultValue, serialize = JSON.stringify, deserilize = JSON.parse) {
230
- return Prop.ofStorage(key, defaultValue, window.sessionStorage, serialize, deserilize);
231
- }
232
- [$isProp] = true;
233
- set = (value) => {
234
- if (this._value === value)
235
- return;
236
- this._value = value;
237
- this._listeners.forEach(listener => { listener(value); });
238
- };
239
- update = (f) => {
240
- this.set(f(this._value));
241
- };
242
- atLens = (key) => {
243
- return this.iso(value => value[key], value => ({ ...this._value, [key]: value }));
244
- };
245
- reducer = (f) => {
246
- return (action) => {
247
- this.set(f(this._value, action));
248
- };
249
- };
250
- iso = (map, reverse) => {
251
- const prop = new Prop(map(this._value));
252
- this.subscribe(value => { prop.set(map(value)); });
253
- prop.subscribe(value => { this.set(reverse(value)); });
254
- return prop;
255
- };
256
- }
package/render.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { type JSX } from './jsx-runtime';
2
- import { type Clean } from './clean';
3
- export declare function render(renderable: JSX.DOMNode, element: HTMLElement): Clean;
package/render.js DELETED
@@ -1,7 +0,0 @@
1
- import { DOMContext } from './dom-context';
2
- import { makeRenderable } from './jsx-runtime';
3
- export function render(renderable, element) {
4
- const ctx = DOMContext.of(element);
5
- const clear = makeRenderable(renderable).appendTo(ctx);
6
- return () => { clear(true); };
7
- }
package/renderable.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { type DOMContext } from './dom-context';
2
- import { type Clear } from './clean';
3
- export interface Renderable {
4
- appendTo: (ctx: DOMContext) => Clear;
5
- }
package/renderable.js DELETED
@@ -1 +0,0 @@
1
- export {};