@tempots/dom 9.0.2 → 10.0.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.
Files changed (129) hide show
  1. package/README.md +1 -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 +14 -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 +1412 -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 +503 -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
@@ -1,15 +0,0 @@
1
- import { Signal } from '../prop';
2
- import { type Renderable } from '../renderable';
3
- import { type Clear } from '../clean';
4
- import { type DOMContext } from '../dom-context';
5
- export declare function subscribeToSignal<T>(prop: Signal<T>, listener: (value: T) => void, clear: Clear): Clear;
6
- export declare class TextImpl implements Renderable {
7
- private readonly text;
8
- constructor(text: Signal<string>);
9
- readonly appendTo: (ctx: DOMContext) => Clear;
10
- }
11
- export type Primitive = string | number | boolean | Date;
12
- export interface TextProps {
13
- children?: Signal<Primitive | undefined> | Signal<Primitive> | Primitive;
14
- }
15
- export declare function Text({ children }: TextProps): Renderable;
@@ -1,33 +0,0 @@
1
- import { Signal } from '../prop';
2
- export function subscribeToSignal(prop, listener, clear) {
3
- const unsubscribe = prop.subscribe(listener);
4
- return (removeTree) => {
5
- unsubscribe();
6
- clear(removeTree);
7
- };
8
- }
9
- export class TextImpl {
10
- text;
11
- constructor(text) {
12
- this.text = text;
13
- }
14
- appendTo = (ctx) => {
15
- const [set, clear] = ctx.createText(this.text.get());
16
- return subscribeToSignal(this.text, set, clear);
17
- };
18
- }
19
- function propFromChildren(children) {
20
- if (children instanceof Signal) {
21
- return children.map((child) => {
22
- if (child == null) {
23
- return '';
24
- }
25
- return String(child);
26
- });
27
- }
28
- return new Signal(String(children));
29
- }
30
- export function Text({ children }) {
31
- const prop = propFromChildren(children);
32
- return new TextImpl(prop);
33
- }
@@ -1,13 +0,0 @@
1
- import { type Signal } from '../prop';
2
- import { type Clear } from '../clean';
3
- import { type DOMContext } from '../dom-context';
4
- import { type Renderable } from '../renderable';
5
- export declare class TextContentImpl implements Renderable {
6
- private readonly value;
7
- constructor(value: Signal<string> | Signal<string | undefined>);
8
- readonly appendTo: (ctx: DOMContext) => Clear;
9
- }
10
- export interface TextContentProps {
11
- value: Signal<string> | Signal<string | undefined>;
12
- }
13
- export declare function TextContent({ value }: TextContentProps): TextContentImpl;
@@ -1,23 +0,0 @@
1
- export class TextContentImpl {
2
- value;
3
- constructor(value) {
4
- this.value = value;
5
- }
6
- appendTo = (ctx) => {
7
- const el = ctx.getElement();
8
- const previous = el.textContent;
9
- el.textContent = this.value.get() ?? '';
10
- const cancel = this.value.subscribe(value => {
11
- el.textContent = value ?? '';
12
- });
13
- return (removeTree) => {
14
- cancel();
15
- if (removeTree) {
16
- el.textContent = previous;
17
- }
18
- };
19
- };
20
- }
21
- export function TextContent({ value }) {
22
- return new TextContentImpl(value);
23
- }
@@ -1,283 +0,0 @@
1
- export function parseColorChannels(color) {
2
- let match = color.match(/rgba?\((\d+), (\d+), (\d+)(, (\d+))?\)/);
3
- if (match != null) {
4
- return [
5
- Number(match[1]),
6
- Number(match[2]),
7
- Number(match[3]),
8
- match[4] != null ? Number(match[5]) : 1,
9
- 'rgba'
10
- ];
11
- }
12
- else {
13
- match = color.match(/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/);
14
- if (match != null) {
15
- return [
16
- parseInt(match[1], 16),
17
- parseInt(match[2], 16),
18
- parseInt(match[3], 16),
19
- 1,
20
- 'hex'
21
- ];
22
- }
23
- else {
24
- match = color.match(/hsla?\((\d+), (\d+)%?, (\d+)%?(, (\d+))?\)/);
25
- if (match != null) {
26
- return [
27
- Number(match[1]),
28
- Number(match[2]),
29
- Number(match[3]),
30
- match[4] != null ? Number(match[5]) : 1,
31
- 'hsla'
32
- ];
33
- }
34
- }
35
- }
36
- return [0, 0, 0, 1, 'rgba'];
37
- }
38
- function parseBoxShadow(cssString) {
39
- const boxShadowRegex = /^(inset\s)?(-?\d+)([a-zA-Z]*)(\s+)(-?\d+)([a-zA-Z]*)(?:\s+(-?\d+)([a-zA-Z]*))?(?:\s+(-?\d+)([a-zA-Z]*))?(?:\s+(-?\d+)([a-zA-Z]*))?(?:\s+)([a-zA-Z0-9(),.]+)$/i;
40
- const match = cssString.match(boxShadowRegex);
41
- if (match == null) {
42
- return {
43
- inset: false,
44
- x: 0,
45
- y: 0,
46
- blur: 0,
47
- spread: 0,
48
- color: 'rgba(0, 0, 0, 0)'
49
- };
50
- }
51
- const [, inset, x, , , y, , blur, , spread, , color] = match;
52
- const parsedBlur = blur != null ? parseInt(blur, 10) : 0;
53
- const parsedSpread = spread != null ? parseInt(spread, 10) : 0;
54
- return {
55
- inset: !!inset,
56
- x: parseInt(x, 10),
57
- y: parseInt(y, 10),
58
- blur: parsedBlur,
59
- spread: parsedSpread,
60
- color
61
- };
62
- }
63
- function boxShadowToString(shadow) {
64
- const { inset, x, y, blur, spread, color } = shadow;
65
- return `${inset ? 'inset ' : ''}${x}px ${y}px ${blur}px ${spread}px ${color}`;
66
- }
67
- export function colorChannelsToString(channels) {
68
- if (channels[4] === 'rgba') {
69
- return `rgba(${channels[0]}, ${channels[1]}, ${channels[2]}, ${channels[3]})`;
70
- }
71
- else if (channels[4] === 'hex') {
72
- return `#${channels[0].toString(16).padStart(2, '0')}${channels[1].toString(16).padStart(2, '0')}${channels[2].toString(16).padStart(2, '0')}`;
73
- }
74
- else if (channels[4] === 'hsla') {
75
- return `hsla(${channels[0]}, ${channels[1]}%, ${channels[2]}%, ${channels[3]})`;
76
- }
77
- return '';
78
- }
79
- export function interpolateColor(startColor, endColor) {
80
- const [startR, startG, startB, startA, startType] = parseColorChannels(startColor);
81
- const [endR, endG, endB, endA] = parseColorChannels(endColor);
82
- return (t) => {
83
- const r = startR + (endR - startR) * t;
84
- const g = startG + (endG - startG) * t;
85
- const b = startB + (endB - startB) * t;
86
- const a = startA + (endA - startA) * t;
87
- return colorChannelsToString([r, g, b, a, startType]);
88
- };
89
- }
90
- export function interpolateShadow(startShadow, endShadow) {
91
- const start = parseBoxShadow(startShadow);
92
- const end = parseBoxShadow(endShadow);
93
- return (t) => {
94
- const x = start.x + (end.x - start.x) * t;
95
- const y = start.y + (end.y - start.y) * t;
96
- const blur = start.blur + (end.blur - start.blur) * t;
97
- const spread = start.spread + (end.spread - start.spread) * t;
98
- const color = getColorInterpolation(start.color, end.color)(t);
99
- return boxShadowToString({ inset: start.inset, x, y, blur, spread, color });
100
- };
101
- }
102
- export function getComputedAnimatableProp(styles, key) {
103
- if (key === 'translateX') {
104
- return new WebKitCSSMatrix(styles.transform).m41;
105
- }
106
- else if (key === 'translateY') {
107
- return new WebKitCSSMatrix(styles.transform).m42;
108
- }
109
- else if (key === 'translateZ') {
110
- return new WebKitCSSMatrix(styles.transform).m43;
111
- }
112
- else if (key === 'rotateX') {
113
- return new WebKitCSSMatrix(styles.transform).m12;
114
- }
115
- else if (key === 'rotateY') {
116
- return new WebKitCSSMatrix(styles.transform).m21;
117
- }
118
- else if (key === 'rotateZ') {
119
- return new WebKitCSSMatrix(styles.transform).m31;
120
- }
121
- else if (key === 'scaleX') {
122
- return new WebKitCSSMatrix(styles.transform).m11;
123
- }
124
- else if (key === 'scaleY') {
125
- return new WebKitCSSMatrix(styles.transform).m22;
126
- }
127
- else if (key === 'scaleZ') {
128
- return new WebKitCSSMatrix(styles.transform).m33;
129
- }
130
- else if (key === 'skewX') {
131
- return new WebKitCSSMatrix(styles.transform).m13;
132
- }
133
- else if (key === 'skewY') {
134
- return new WebKitCSSMatrix(styles.transform).m23;
135
- }
136
- else if (key === 'grayScale') {
137
- return Number(styles.filter.match(/grayscale\((\d+)%\)/)?.[1]);
138
- }
139
- else if (key === 'sepia') {
140
- return Number(styles.filter.match(/sepia\((\d+)%\)/)?.[1]);
141
- }
142
- else if (key === 'saturate') {
143
- return Number(styles.filter.match(/saturate\((\d+)%\)/)?.[1]);
144
- }
145
- else if (key === 'hueRotate') {
146
- return Number(styles.filter.match(/hue-rotate\((\d+)deg\)/)?.[1]);
147
- }
148
- else if (key === 'invert') {
149
- return Number(styles.filter.match(/invert\((\d+)%\)/)?.[1]);
150
- }
151
- else if (key === 'brightness') {
152
- return Number(styles.filter.match(/brightness\((\d+)%\)/)?.[1]);
153
- }
154
- else if (key === 'contrast') {
155
- return Number(styles.filter.match(/contrast\((\d+)%\)/)?.[1]);
156
- }
157
- else if (key === 'blur') {
158
- return Number(styles.filter.match(/blur\((\d+)px\)/)?.[1]);
159
- }
160
- return Number(styles.getPropertyValue(key));
161
- }
162
- export function getComputedAnimatable(el, styles) {
163
- const result = {};
164
- const computedStyles = getComputedStyle(el);
165
- for (const [key, value] of Object.entries(styles)) {
166
- const k = key;
167
- if (value != null) {
168
- result[k] = getComputedAnimatableProp(computedStyles, k);
169
- }
170
- }
171
- return result;
172
- }
173
- export function applyAnimatableProp(el, key, value) {
174
- if (value == null)
175
- return;
176
- if (key === 'translateX') {
177
- el.style.transform += ` translateX(${value}px)`;
178
- }
179
- else if (key === 'translateY') {
180
- el.style.transform += ` translateY(${value}px)`;
181
- }
182
- else if (key === 'translateZ') {
183
- el.style.transform += ` translateZ(${value}px)`;
184
- }
185
- else if (key === 'rotateX') {
186
- el.style.transform += ` rotateX(${value}deg)`;
187
- }
188
- else if (key === 'rotateY') {
189
- el.style.transform += ` rotateY(${value}deg)`;
190
- }
191
- else if (key === 'rotateZ') {
192
- el.style.transform += ` rotateZ(${value}deg)`;
193
- }
194
- else if (key === 'scaleX') {
195
- el.style.transform += ` scaleX(${value})`;
196
- }
197
- else if (key === 'scaleY') {
198
- el.style.transform += ` scaleY(${value})`;
199
- }
200
- else if (key === 'scaleZ') {
201
- el.style.transform += ` scaleZ(${value})`;
202
- }
203
- else if (key === 'skewX') {
204
- el.style.transform += ` skewX(${value}deg)`;
205
- }
206
- else if (key === 'skewY') {
207
- el.style.transform += ` skewY(${value}deg)`;
208
- }
209
- else if (key === 'grayScale') {
210
- el.style.filter += ` grayscale(${value}%)`;
211
- }
212
- else if (key === 'sepia') {
213
- el.style.filter += ` sepia(${value}%)`;
214
- }
215
- else if (key === 'saturate') {
216
- el.style.filter += ` saturate(${value}%)`;
217
- }
218
- else if (key === 'hueRotate') {
219
- el.style.filter += ` hue-rotate(${value}deg)`;
220
- }
221
- else if (key === 'invert') {
222
- el.style.filter += ` invert(${value}%)`;
223
- }
224
- else if (key === 'brightness') {
225
- el.style.filter += ` brightness(${value}%)`;
226
- }
227
- else if (key === 'contrast') {
228
- el.style.filter += ` contrast(${value}%)`;
229
- }
230
- else if (key === 'blur') {
231
- el.style.filter += ` blur(${value}px)`;
232
- }
233
- el.style.setProperty(key, String(value));
234
- }
235
- const interpolationCache = new Map();
236
- function getInterpolate(from, to, type) {
237
- if (interpolationCache.has(type + ':' + from + to)) {
238
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
- return interpolationCache.get(from + to);
240
- }
241
- const f = interpolateColor(from, to);
242
- interpolationCache.set(type + ':' + from + to, f);
243
- return f;
244
- }
245
- function getColorInterpolation(from, to) {
246
- return getInterpolate(from, to, 'c');
247
- }
248
- function getShadowInterpolation(from, to) {
249
- return getInterpolate(from, to, 's');
250
- }
251
- export function applyInterpolatedAnimatableProp(el, key, from, to, progress) {
252
- if (from != null && to != null) {
253
- if (typeof from === 'number' && typeof to === 'number') {
254
- const value = from + (to - from) * progress;
255
- applyAnimatableProp(el, key, value);
256
- }
257
- else if (key === 'boxShadow' || key === 'textShadow') {
258
- const value = getShadowInterpolation(from, to)(progress);
259
- applyAnimatableProp(el, key, value);
260
- }
261
- else if (key === 'color' || key === 'backgroundColor' || key === 'borderColor' || key === 'outlineColor') {
262
- const value = getColorInterpolation(from, to)(progress);
263
- applyAnimatableProp(el, key, value);
264
- }
265
- }
266
- }
267
- export function applyInterpolatedAnimatable(el, from, to, progress) {
268
- el.style.transform = '';
269
- el.style.filter = '';
270
- for (const [key, value] of Object.entries(to)) {
271
- const k = key;
272
- applyInterpolatedAnimatableProp(el, k, from[k], value, progress);
273
- }
274
- }
275
- export function applyAnimatable(el, styles) {
276
- el.style.transform = '';
277
- el.style.filter = '';
278
- for (const [key, value] of Object.entries(styles)) {
279
- if (value != null) {
280
- applyAnimatableProp(el, key, value);
281
- }
282
- }
283
- }
package/dom-context.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { type Clear } from './clean';
2
- export type ProviderMark<T> = symbol;
3
- export declare function makeProviderMark<T>(): ProviderMark<T>;
4
- export type Providers = Record<ProviderMark<unknown>, unknown>;
5
- export declare class DOMContext {
6
- private readonly document;
7
- private readonly element;
8
- private readonly reference;
9
- private readonly ns;
10
- private readonly providers;
11
- static of(element: HTMLElement): DOMContext;
12
- constructor(document: Document, element: HTMLElement, reference: Text | undefined, ns: string | undefined, providers: Providers);
13
- append(node: Node): void;
14
- getElement(): HTMLElement;
15
- getDocument(): Document;
16
- makeReference(): DOMContext;
17
- makeElement(tagName: string): DOMContext;
18
- getBooleanAttribute(name: string): boolean;
19
- setBooleanAttribute(name: string, value: boolean): void;
20
- createBooleanAttribute(name: string, value: boolean): [(newValue: boolean) => void, Clear];
21
- getAttribute(name: string): string | null;
22
- setAttribute(name: string, value: string | null): void;
23
- createAttribute(name: string, value: string): [(newValue: string) => void, Clear];
24
- getProperty<T>(name: string): T;
25
- setProperty<T>(name: string, value: T): void;
26
- createProperty<T>(name: string, value: T): [(newValue: T) => void, Clear];
27
- createText(text: string): [(newText: string) => void, Clear];
28
- createClass(cls: string): [(newClass: string) => void, Clear];
29
- createHandler<T>(name: string, handler: (event: T) => void): Clear;
30
- private readonly suspendedClears;
31
- delayClear(f: (removeTree: boolean, clear: () => void) => void): (removeTree: boolean) => void;
32
- requestClear(removeTree: boolean, willClear: () => void): void;
33
- private clear;
34
- withProvider<T>(mark: ProviderMark<T>, provider: T): DOMContext;
35
- getProvider<T>(mark: ProviderMark<T>): T;
36
- getStyle(name: string): string | undefined | null;
37
- setStyle(name: string, value: string | undefined | null): void;
38
- createStyle(name: string, value: string | undefined | null): [(newValue: string) => void, Clear];
39
- }
package/dom-context.js DELETED
@@ -1,263 +0,0 @@
1
- function extractClassNames(cls) {
2
- return (cls ?? '').split(/\s+/g).filter((className) => className.length > 0);
3
- }
4
- function createIntegerSet(x) {
5
- const integerSet = new Set();
6
- for (let i = 0; i < x; i++) {
7
- integerSet.add(i);
8
- }
9
- return integerSet;
10
- }
11
- export function makeProviderMark() {
12
- return Symbol('providerMark');
13
- }
14
- export class DOMContext {
15
- document;
16
- element;
17
- reference;
18
- ns;
19
- providers;
20
- static of(element) {
21
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
- return new DOMContext(element.ownerDocument, element, undefined, undefined, {});
23
- }
24
- constructor(document, element, reference, ns, providers) {
25
- this.document = document;
26
- this.element = element;
27
- this.reference = reference;
28
- this.ns = ns;
29
- this.providers = providers;
30
- }
31
- append(node) {
32
- if (this.reference !== undefined) {
33
- try {
34
- // There are components (TextContent, InnerHTML) that can mess up with the internal state of an element
35
- this.element.insertBefore(node, this.reference);
36
- }
37
- catch (_) {
38
- this.element.appendChild(node);
39
- }
40
- }
41
- else {
42
- this.element.appendChild(node);
43
- }
44
- }
45
- getElement() {
46
- return this.element;
47
- }
48
- getDocument() {
49
- return this.document;
50
- }
51
- makeReference() {
52
- const textNode = this.document.createTextNode('');
53
- this.append(textNode);
54
- return new DOMContext(this.document, this.element, textNode, this.ns, this.providers);
55
- }
56
- makeElement(tagName) {
57
- if (this.ns !== undefined || tagName === 'svg') {
58
- const ns = this.ns ?? 'http://www.w3.org/2000/svg';
59
- const element = this.document.createElementNS(ns, tagName);
60
- this.append(element);
61
- return new DOMContext(this.document, element, undefined, ns, this.providers);
62
- }
63
- else {
64
- const element = this.document.createElement(tagName);
65
- this.append(element);
66
- return new DOMContext(this.document, element, undefined, this.ns, this.providers);
67
- }
68
- }
69
- getBooleanAttribute(name) {
70
- return this.element.hasAttribute(name);
71
- }
72
- setBooleanAttribute(name, value) {
73
- if (value) {
74
- this.element.setAttribute(name, '');
75
- }
76
- else {
77
- this.element.removeAttribute(name);
78
- }
79
- }
80
- createBooleanAttribute(name, value) {
81
- const current = this.element.hasAttribute(name);
82
- this.setBooleanAttribute(name, value);
83
- return [
84
- (newValue) => {
85
- this.setBooleanAttribute(name, newValue);
86
- },
87
- (removeTree) => {
88
- if (removeTree) {
89
- this.setBooleanAttribute(name, current);
90
- }
91
- }
92
- ];
93
- }
94
- getAttribute(name) {
95
- return this.element.getAttribute(name);
96
- }
97
- setAttribute(name, value) {
98
- if (value == null) {
99
- this.element.removeAttribute(name);
100
- }
101
- else {
102
- this.element.setAttribute(name, value);
103
- }
104
- }
105
- createAttribute(name, value) {
106
- const current = this.element.getAttribute(name);
107
- this.setAttribute(name, value);
108
- return [
109
- (newValue) => {
110
- this.setAttribute(name, newValue);
111
- },
112
- (removeTree) => {
113
- if (removeTree) {
114
- this.setAttribute(name, current);
115
- }
116
- }
117
- ];
118
- }
119
- getProperty(name) {
120
- return Reflect.get(this.element, name);
121
- }
122
- setProperty(name, value) {
123
- if (value == null) {
124
- Reflect.deleteProperty(this.element, name);
125
- }
126
- else {
127
- Reflect.set(this.element, name, value);
128
- }
129
- }
130
- createProperty(name, value) {
131
- const current = this.getProperty(name);
132
- this.setProperty(name, value);
133
- return [
134
- (newValue) => {
135
- this.setProperty(name, newValue);
136
- },
137
- (removeTree) => {
138
- if (removeTree) {
139
- this.setProperty(name, current);
140
- }
141
- }
142
- ];
143
- }
144
- createText(text) {
145
- const textNode = this.document.createTextNode(text);
146
- this.append(textNode);
147
- return [
148
- (newText) => {
149
- textNode.nodeValue = newText;
150
- },
151
- (removeTree) => {
152
- if (removeTree) {
153
- textNode.remove();
154
- }
155
- }
156
- ];
157
- }
158
- createClass(cls) {
159
- let current = extractClassNames(cls);
160
- current.forEach((className) => {
161
- this.element.classList.add(className);
162
- });
163
- return [
164
- (newClass) => {
165
- current.forEach((className) => {
166
- this.element.classList.remove(className);
167
- });
168
- current = extractClassNames(newClass);
169
- current.forEach((className) => {
170
- this.element.classList.add(className);
171
- });
172
- },
173
- (removeTree) => {
174
- if (removeTree) {
175
- current.forEach((className) => {
176
- this.element.classList.remove(className);
177
- if (this.element.classList.length === 0) {
178
- this.element.removeAttribute('class');
179
- }
180
- });
181
- }
182
- }
183
- ];
184
- }
185
- createHandler(name, handler) {
186
- this.element.addEventListener(name, handler);
187
- return (removeTree) => {
188
- if (removeTree) {
189
- this.element.removeEventListener(name, handler);
190
- }
191
- };
192
- }
193
- suspendedClears = [];
194
- delayClear(f) {
195
- this.suspendedClears.push(f);
196
- return (removeTree) => {
197
- // TODO nothing happens?
198
- };
199
- }
200
- requestClear(removeTree, willClear) {
201
- if (this.suspendedClears.length === 0) {
202
- willClear();
203
- this.clear(removeTree);
204
- }
205
- else {
206
- const set = createIntegerSet(this.suspendedClears.length);
207
- const clearSuspended = (index) => {
208
- set.delete(index);
209
- if (set.size === 0) {
210
- willClear();
211
- this.clear(removeTree);
212
- }
213
- };
214
- this.suspendedClears.forEach((f, i) => { f(removeTree, () => { clearSuspended(i); }); });
215
- this.suspendedClears.length = 0;
216
- }
217
- }
218
- clear(removeTree) {
219
- if (removeTree) {
220
- if (this.reference !== undefined) {
221
- this.reference.parentElement?.removeChild(this.reference);
222
- }
223
- else {
224
- this.element.onblur = null;
225
- this.element.parentElement?.removeChild(this.element);
226
- }
227
- }
228
- }
229
- withProvider(mark, provider) {
230
- return new DOMContext(this.document, this.element, this.reference, this.ns, {
231
- ...this.providers,
232
- [mark]: provider
233
- });
234
- }
235
- getProvider(mark) {
236
- return this.providers[mark];
237
- }
238
- getStyle(name) {
239
- return this.element.style.getPropertyValue(name);
240
- }
241
- setStyle(name, value) {
242
- if (value == null) {
243
- this.element.style.removeProperty(name);
244
- }
245
- else {
246
- this.element.style.setProperty(name, value);
247
- }
248
- }
249
- createStyle(name, value) {
250
- const current = this.element.style.getPropertyValue(name);
251
- this.setStyle(name, value);
252
- return [
253
- (newValue) => {
254
- this.setStyle(name, newValue);
255
- },
256
- (removeTree) => {
257
- if (removeTree) {
258
- this.setStyle(name, current);
259
- }
260
- }
261
- ];
262
- }
263
- }
@@ -1,4 +0,0 @@
1
- export declare const handleAnchorClick: (callback: () => boolean, options?: {
2
- checkExtension?: boolean;
3
- checkExternalUrl?: boolean;
4
- }) => (e: MouseEvent) => void;