@tempots/dom 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/clean.d.ts +2 -0
- package/clean.js +1 -0
- package/components/Attribute.d.ts +15 -0
- package/components/Attribute.js +16 -0
- package/components/BooleanAttribute.d.ts +15 -0
- package/components/BooleanAttribute.js +16 -0
- package/components/ClassName.d.ts +13 -0
- package/components/ClassName.js +14 -0
- package/components/El.d.ts +15 -0
- package/components/El.js +21 -0
- package/components/FadeIn.d.ts +18 -0
- package/components/FadeIn.js +52 -0
- package/components/FadeOut.d.ts +16 -0
- package/components/FadeOut.js +39 -0
- package/components/For.d.ts +7 -0
- package/components/For.js +15 -0
- package/components/Fragment.d.ts +12 -0
- package/components/Fragment.js +16 -0
- package/components/HiddenWhenEmpty.d.ts +7 -0
- package/components/HiddenWhenEmpty.js +12 -0
- package/components/If.d.ts +14 -0
- package/components/If.js +19 -0
- package/components/InnerHTML.d.ts +13 -0
- package/components/InnerHTML.js +23 -0
- package/components/Lifecycle.d.ts +14 -0
- package/components/Lifecycle.js +18 -0
- package/components/Match.d.ts +33 -0
- package/components/Match.js +44 -0
- package/components/NotEmpty.d.ts +10 -0
- package/components/NotEmpty.js +11 -0
- package/components/On.d.ts +15 -0
- package/components/On.js +14 -0
- package/components/OnRemove.d.ts +11 -0
- package/components/OnRemove.js +14 -0
- package/components/OneOf.d.ts +20 -0
- package/components/OneOf.js +45 -0
- package/components/Portal.d.ts +15 -0
- package/components/Portal.js +20 -0
- package/components/Property.d.ts +15 -0
- package/components/Property.js +16 -0
- package/components/Provider.d.ts +28 -0
- package/components/Provider.js +44 -0
- package/components/Repeat.d.ts +15 -0
- package/components/Repeat.js +33 -0
- package/components/Shadow.d.ts +0 -0
- package/components/Shadow.js +1 -0
- package/components/Show.d.ts +20 -0
- package/components/Show.js +22 -0
- package/components/Text.d.ts +15 -0
- package/components/Text.js +33 -0
- package/components/TextContent.d.ts +13 -0
- package/components/TextContent.js +23 -0
- package/components/Tween.d.ts +75 -0
- package/components/Tween.js +242 -0
- package/components/animatable.d.ts +53 -0
- package/components/animatable.js +156 -0
- package/dom-context.d.ts +38 -0
- package/dom-context.js +260 -0
- package/helpers/handle-anchor-click.d.ts +4 -0
- package/helpers/handle-anchor-click.js +43 -0
- package/helpers/handle-text-input.d.ts +1 -0
- package/helpers/handle-text-input.js +4 -0
- package/helpers/is-empty-element.d.ts +2 -0
- package/helpers/is-empty-element.js +8 -0
- package/index.d.ts +36 -0
- package/jsx-dev-runtime.d.ts +1 -0
- package/jsx-dev-runtime.js +1 -0
- package/jsx-runtime.d.ts +9 -0
- package/jsx-runtime.js +157 -0
- package/jsx.d.ts +806 -0
- package/jsx.js +1 -0
- package/package.json +5 -3
- package/prop.d.ts +43 -0
- package/prop.js +174 -0
- package/render.d.ts +3 -0
- package/render.js +7 -0
- package/renderable.d.ts +5 -0
- package/renderable.js +1 -0
- package/types/clean.d.ts +2 -0
- package/types/clean.js +1 -0
- package/types/idom-context.d.ts +27 -0
- package/types/idom-context.js +3 -0
- package/types/renderable.d.ts +5 -0
- package/types/renderable.js +1 -0
- package/.eslintignore +0 -10
- package/.eslintrc.cjs +0 -28
- package/coverage/clover.xml +0 -39
- package/coverage/coverage-final.json +0 -2
- package/coverage/lcov-report/OneOf.ts.html +0 -256
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dom-context.ts.html +0 -928
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/prop.ts.html +0 -691
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
- package/coverage/lcov-report/src/components/El.ts.html +0 -166
- package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
- package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
- package/coverage/lcov-report/src/components/For.ts.html +0 -151
- package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
- package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
- package/coverage/lcov-report/src/components/If.ts.html +0 -217
- package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
- package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
- package/coverage/lcov-report/src/components/Match.ts.html +0 -286
- package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
- package/coverage/lcov-report/src/components/On.ts.html +0 -151
- package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
- package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
- package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
- package/coverage/lcov-report/src/components/Property.ts.html +0 -154
- package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
- package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
- package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
- package/coverage/lcov-report/src/components/Text.ts.html +0 -229
- package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
- package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
- package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
- package/coverage/lcov-report/src/components/index.html +0 -476
- package/coverage/lcov-report/src/dom-context.ts.html +0 -928
- package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
- package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
- package/coverage/lcov-report/src/helpers/index.html +0 -146
- package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
- package/coverage/lcov-report/src/index.html +0 -176
- package/coverage/lcov-report/src/index.ts.html +0 -412
- package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
- package/coverage/lcov-report/src/prop.ts.html +0 -691
- package/coverage/lcov-report/src/render.ts.html +0 -112
- package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/test/common.ts.html +0 -112
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -57
- package/jest.config.js +0 -5
- package/src/clean.ts +0 -2
- package/src/components/Attribute.ts +0 -23
- package/src/components/BooleanAttribute.ts +0 -23
- package/src/components/ClassName.ts +0 -22
- package/src/components/El.ts +0 -27
- package/src/components/FadeIn.ts +0 -59
- package/src/components/FadeOut.ts +0 -47
- package/src/components/For.ts +0 -22
- package/src/components/Fragment.ts +0 -19
- package/src/components/HiddenWhenEmpty.ts +0 -16
- package/src/components/If.ts +0 -44
- package/src/components/InnerHTML.ts +0 -31
- package/src/components/Lifecycle.ts +0 -24
- package/src/components/Match.ts +0 -67
- package/src/components/NotEmpty.tsx +0 -33
- package/src/components/On.ts +0 -22
- package/src/components/OnRemove.ts +0 -20
- package/src/components/OneOf.ts +0 -57
- package/src/components/Portal.ts +0 -30
- package/src/components/Property.ts +0 -23
- package/src/components/Provider.ts +0 -53
- package/src/components/Repeat.ts +0 -46
- package/src/components/Show.tsx +0 -35
- package/src/components/Text.ts +0 -48
- package/src/components/TextContent.ts +0 -31
- package/src/components/animatable.ts +0 -178
- package/src/dom-context.ts +0 -281
- package/src/helpers/handle-anchor-click.ts +0 -64
- package/src/helpers/handle-text-input.ts +0 -5
- package/src/helpers/is-empty-element.ts +0 -9
- package/src/index.ts +0 -109
- package/src/jsx-dev-runtime.ts +0 -8
- package/src/jsx-runtime.ts +0 -172
- package/src/jsx.ts +0 -1046
- package/src/prop.ts +0 -202
- package/src/render.ts +0 -9
- package/src/renderable.ts +0 -6
- package/test/common.ts +0 -9
- package/test/component.spec.tsx +0 -27
- package/test/domcontext.spec.ts +0 -36
- package/test/fadein.spec.tsx +0 -36
- package/test/fadeout.spec.tsx +0 -41
- package/test/if.spec.tsx +0 -30
- package/test/innerhtml.spec.tsx +0 -45
- package/test/prop.spec.ts +0 -10
- package/test/render.spec.tsx +0 -19
- package/test/textcontent.spec.tsx +0 -45
- package/test/when.spec.tsx +0 -30
- package/tsconfig.json +0 -21
- /package/{dist/index.js → index.js} +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
export function getComputedStyleValue(styles, key) {
|
|
2
|
+
if (key === 'translateX') {
|
|
3
|
+
return new WebKitCSSMatrix(styles.transform).m41;
|
|
4
|
+
}
|
|
5
|
+
else if (key === 'translateY') {
|
|
6
|
+
return new WebKitCSSMatrix(styles.transform).m42;
|
|
7
|
+
}
|
|
8
|
+
else if (key === 'translateZ') {
|
|
9
|
+
return new WebKitCSSMatrix(styles.transform).m43;
|
|
10
|
+
}
|
|
11
|
+
else if (key === 'rotateX') {
|
|
12
|
+
return new WebKitCSSMatrix(styles.transform).m12;
|
|
13
|
+
}
|
|
14
|
+
else if (key === 'rotateY') {
|
|
15
|
+
return new WebKitCSSMatrix(styles.transform).m21;
|
|
16
|
+
}
|
|
17
|
+
else if (key === 'rotateZ') {
|
|
18
|
+
return new WebKitCSSMatrix(styles.transform).m31;
|
|
19
|
+
}
|
|
20
|
+
else if (key === 'scaleX') {
|
|
21
|
+
return new WebKitCSSMatrix(styles.transform).m11;
|
|
22
|
+
}
|
|
23
|
+
else if (key === 'scaleY') {
|
|
24
|
+
return new WebKitCSSMatrix(styles.transform).m22;
|
|
25
|
+
}
|
|
26
|
+
else if (key === 'scaleZ') {
|
|
27
|
+
return new WebKitCSSMatrix(styles.transform).m33;
|
|
28
|
+
}
|
|
29
|
+
else if (key === 'skewX') {
|
|
30
|
+
return new WebKitCSSMatrix(styles.transform).m13;
|
|
31
|
+
}
|
|
32
|
+
else if (key === 'skewY') {
|
|
33
|
+
return new WebKitCSSMatrix(styles.transform).m23;
|
|
34
|
+
}
|
|
35
|
+
else if (key === 'grayScale') {
|
|
36
|
+
return Number(styles.filter.match(/grayscale\((\d+)%\)/)?.[1]);
|
|
37
|
+
}
|
|
38
|
+
else if (key === 'sepia') {
|
|
39
|
+
return Number(styles.filter.match(/sepia\((\d+)%\)/)?.[1]);
|
|
40
|
+
}
|
|
41
|
+
else if (key === 'saturate') {
|
|
42
|
+
return Number(styles.filter.match(/saturate\((\d+)%\)/)?.[1]);
|
|
43
|
+
}
|
|
44
|
+
else if (key === 'hueRotate') {
|
|
45
|
+
return Number(styles.filter.match(/hue-rotate\((\d+)deg\)/)?.[1]);
|
|
46
|
+
}
|
|
47
|
+
else if (key === 'invert') {
|
|
48
|
+
return Number(styles.filter.match(/invert\((\d+)%\)/)?.[1]);
|
|
49
|
+
}
|
|
50
|
+
else if (key === 'brightness') {
|
|
51
|
+
return Number(styles.filter.match(/brightness\((\d+)%\)/)?.[1]);
|
|
52
|
+
}
|
|
53
|
+
else if (key === 'contrast') {
|
|
54
|
+
return Number(styles.filter.match(/contrast\((\d+)%\)/)?.[1]);
|
|
55
|
+
}
|
|
56
|
+
else if (key === 'blur') {
|
|
57
|
+
return Number(styles.filter.match(/blur\((\d+)px\)/)?.[1]);
|
|
58
|
+
}
|
|
59
|
+
return Number(styles.getPropertyValue(key));
|
|
60
|
+
}
|
|
61
|
+
export function getCurrentStyleValues(el, styles) {
|
|
62
|
+
const result = {};
|
|
63
|
+
const computedStyles = getComputedStyle(el);
|
|
64
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
65
|
+
const k = key;
|
|
66
|
+
if (value != null) {
|
|
67
|
+
result[k] = getComputedStyleValue(computedStyles, k);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
export function applyStyle(el, key, value) {
|
|
73
|
+
if (value == null)
|
|
74
|
+
return;
|
|
75
|
+
if (key === 'translateX') {
|
|
76
|
+
el.style.transform += ` translateX(${value}px)`;
|
|
77
|
+
}
|
|
78
|
+
else if (key === 'translateY') {
|
|
79
|
+
el.style.transform += ` translateY(${value}px)`;
|
|
80
|
+
}
|
|
81
|
+
else if (key === 'translateZ') {
|
|
82
|
+
el.style.transform += ` translateZ(${value}px)`;
|
|
83
|
+
}
|
|
84
|
+
else if (key === 'rotateX') {
|
|
85
|
+
el.style.transform += ` rotateX(${value}deg)`;
|
|
86
|
+
}
|
|
87
|
+
else if (key === 'rotateY') {
|
|
88
|
+
el.style.transform += ` rotateY(${value}deg)`;
|
|
89
|
+
}
|
|
90
|
+
else if (key === 'rotateZ') {
|
|
91
|
+
el.style.transform += ` rotateZ(${value}deg)`;
|
|
92
|
+
}
|
|
93
|
+
else if (key === 'scaleX') {
|
|
94
|
+
el.style.transform += ` scaleX(${value})`;
|
|
95
|
+
}
|
|
96
|
+
else if (key === 'scaleY') {
|
|
97
|
+
el.style.transform += ` scaleY(${value})`;
|
|
98
|
+
}
|
|
99
|
+
else if (key === 'scaleZ') {
|
|
100
|
+
el.style.transform += ` scaleZ(${value})`;
|
|
101
|
+
}
|
|
102
|
+
else if (key === 'skewX') {
|
|
103
|
+
el.style.transform += ` skewX(${value}deg)`;
|
|
104
|
+
}
|
|
105
|
+
else if (key === 'skewY') {
|
|
106
|
+
el.style.transform += ` skewY(${value}deg)`;
|
|
107
|
+
}
|
|
108
|
+
else if (key === 'grayScale') {
|
|
109
|
+
el.style.filter += ` grayscale(${value}%)`;
|
|
110
|
+
}
|
|
111
|
+
else if (key === 'sepia') {
|
|
112
|
+
el.style.filter += ` sepia(${value}%)`;
|
|
113
|
+
}
|
|
114
|
+
else if (key === 'saturate') {
|
|
115
|
+
el.style.filter += ` saturate(${value}%)`;
|
|
116
|
+
}
|
|
117
|
+
else if (key === 'hueRotate') {
|
|
118
|
+
el.style.filter += ` hue-rotate(${value}deg)`;
|
|
119
|
+
}
|
|
120
|
+
else if (key === 'invert') {
|
|
121
|
+
el.style.filter += ` invert(${value}%)`;
|
|
122
|
+
}
|
|
123
|
+
else if (key === 'brightness') {
|
|
124
|
+
el.style.filter += ` brightness(${value}%)`;
|
|
125
|
+
}
|
|
126
|
+
else if (key === 'contrast') {
|
|
127
|
+
el.style.filter += ` contrast(${value}%)`;
|
|
128
|
+
}
|
|
129
|
+
else if (key === 'blur') {
|
|
130
|
+
el.style.filter += ` blur(${value}px)`;
|
|
131
|
+
}
|
|
132
|
+
el.style.setProperty(key, String(value));
|
|
133
|
+
}
|
|
134
|
+
export function applyInterpolatedStyle(el, key, from, to, progress) {
|
|
135
|
+
if (from != null && to != null) {
|
|
136
|
+
const value = from + (to - from) * progress;
|
|
137
|
+
applyStyle(el, key, value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function applyInterpolatedStyles(el, from, to, progress) {
|
|
141
|
+
el.style.transform = '';
|
|
142
|
+
el.style.filter = '';
|
|
143
|
+
for (const [key, value] of Object.entries(to)) {
|
|
144
|
+
const k = key;
|
|
145
|
+
applyInterpolatedStyle(el, k, from[k], value, progress);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export function applyStyles(el, styles) {
|
|
149
|
+
el.style.transform = '';
|
|
150
|
+
el.style.filter = '';
|
|
151
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
152
|
+
if (value != null) {
|
|
153
|
+
applyStyle(el, key, value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export class TweenImpl {
|
|
158
|
+
enter;
|
|
159
|
+
exit;
|
|
160
|
+
style;
|
|
161
|
+
constructor(enter = [], exit = [], style) {
|
|
162
|
+
this.enter = enter;
|
|
163
|
+
this.exit = exit;
|
|
164
|
+
this.style = style;
|
|
165
|
+
}
|
|
166
|
+
appendTo(ctx) {
|
|
167
|
+
const element = ctx.getElement();
|
|
168
|
+
let currentAnimation = 0;
|
|
169
|
+
let startTime = 0;
|
|
170
|
+
let animation = null;
|
|
171
|
+
let from = null;
|
|
172
|
+
let willClear = null;
|
|
173
|
+
// let unmounted = false
|
|
174
|
+
let animations = this.enter;
|
|
175
|
+
const { exit, style } = this;
|
|
176
|
+
function frame() {
|
|
177
|
+
// if (unmounted) return
|
|
178
|
+
if (animation == null || from == null)
|
|
179
|
+
return;
|
|
180
|
+
const now = Date.now();
|
|
181
|
+
const elapsed = now - startTime;
|
|
182
|
+
const { duration = 250, delay = 0 } = animation;
|
|
183
|
+
if (elapsed < delay)
|
|
184
|
+
return;
|
|
185
|
+
const progress = Math.min(1, (elapsed - delay) / duration);
|
|
186
|
+
applyInterpolatedStyles(element, from, animation.style, progress);
|
|
187
|
+
// console.log(
|
|
188
|
+
// element.style.opacity,
|
|
189
|
+
// // getComputedStyleValue(getComputedStyle(element), 'translateY')
|
|
190
|
+
// )
|
|
191
|
+
if (progress >= 1) {
|
|
192
|
+
if (exit === animations) {
|
|
193
|
+
console.log('exit');
|
|
194
|
+
willClear?.();
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log('play next');
|
|
198
|
+
playNextAnimation();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
requestAnimationFrame(frame);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function playNextAnimation() {
|
|
206
|
+
if (currentAnimation >= animations.length)
|
|
207
|
+
return;
|
|
208
|
+
startTime = Date.now();
|
|
209
|
+
animation = animations[currentAnimation];
|
|
210
|
+
if (currentAnimation === 0 && style != null && animations !== exit) {
|
|
211
|
+
applyStyles(element, style);
|
|
212
|
+
from = style;
|
|
213
|
+
console.log('playNextAnimation from style', currentAnimation, from, animation.style);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
from = getCurrentStyleValues(element, animation.style);
|
|
217
|
+
console.log('playNextAnimation from empty', currentAnimation, from, animation.style);
|
|
218
|
+
}
|
|
219
|
+
requestAnimationFrame(frame);
|
|
220
|
+
currentAnimation++;
|
|
221
|
+
}
|
|
222
|
+
playNextAnimation();
|
|
223
|
+
return (clearTree) => {
|
|
224
|
+
console.log('onUnmount');
|
|
225
|
+
animations = exit;
|
|
226
|
+
// unmounted = true
|
|
227
|
+
currentAnimation = 0;
|
|
228
|
+
ctx.delayClear(clearTree, (clear) => {
|
|
229
|
+
console.log('perform clear');
|
|
230
|
+
willClear = () => {
|
|
231
|
+
console.log('finalize clear');
|
|
232
|
+
animations = [];
|
|
233
|
+
clear();
|
|
234
|
+
};
|
|
235
|
+
playNextAnimation();
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export function Tween({ enter, exit, style }) {
|
|
241
|
+
return new TweenImpl(enter, exit, style);
|
|
242
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface Animatable {
|
|
2
|
+
width?: number;
|
|
3
|
+
maxWidth?: number;
|
|
4
|
+
minWidth?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
maxHeight?: number;
|
|
7
|
+
minHeight?: number;
|
|
8
|
+
lineHeight?: number;
|
|
9
|
+
opacity?: number;
|
|
10
|
+
top?: number;
|
|
11
|
+
left?: number;
|
|
12
|
+
right?: number;
|
|
13
|
+
bottom?: number;
|
|
14
|
+
padding?: number;
|
|
15
|
+
paddingTop?: number;
|
|
16
|
+
paddingBottom?: number;
|
|
17
|
+
paddingLeft?: number;
|
|
18
|
+
paddingRight?: number;
|
|
19
|
+
margin?: number;
|
|
20
|
+
marginTop?: number;
|
|
21
|
+
marginBottom?: number;
|
|
22
|
+
marginLeft?: number;
|
|
23
|
+
marginRight?: number;
|
|
24
|
+
fontSize?: number;
|
|
25
|
+
letterSpacing?: number;
|
|
26
|
+
borderWidth?: number;
|
|
27
|
+
borderRadius?: number;
|
|
28
|
+
translateX?: number;
|
|
29
|
+
translateY?: number;
|
|
30
|
+
translateZ?: number;
|
|
31
|
+
rotateX?: number;
|
|
32
|
+
rotateY?: number;
|
|
33
|
+
rotateZ?: number;
|
|
34
|
+
scaleX?: number;
|
|
35
|
+
scaleY?: number;
|
|
36
|
+
scaleZ?: number;
|
|
37
|
+
skewX?: number;
|
|
38
|
+
skewY?: number;
|
|
39
|
+
grayScale?: number;
|
|
40
|
+
sepia?: number;
|
|
41
|
+
saturate?: number;
|
|
42
|
+
hueRotate?: number;
|
|
43
|
+
invert?: number;
|
|
44
|
+
brightness?: number;
|
|
45
|
+
contrast?: number;
|
|
46
|
+
blur?: number;
|
|
47
|
+
}
|
|
48
|
+
export declare function getComputedAnimatableProp(styles: CSSStyleDeclaration, key: keyof Animatable): Animatable[typeof key];
|
|
49
|
+
export declare function getComputedAnimatable(el: HTMLElement, styles: Animatable): Animatable;
|
|
50
|
+
export declare function applyAnimatableProp(el: HTMLElement, key: keyof Animatable, value: Animatable[typeof key]): void;
|
|
51
|
+
export declare function applyInterpolatedAnimatableProp(el: HTMLElement, key: keyof Animatable, from: Animatable[typeof key], to: Animatable[typeof key], progress: number): void;
|
|
52
|
+
export declare function applyInterpolatedAnimatable(el: HTMLElement, from: Animatable, to: Animatable, progress: number): void;
|
|
53
|
+
export declare function applyAnimatable(el: HTMLElement, styles: Animatable): void;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export function getComputedAnimatableProp(styles, key) {
|
|
2
|
+
if (key === 'translateX') {
|
|
3
|
+
return new WebKitCSSMatrix(styles.transform).m41;
|
|
4
|
+
}
|
|
5
|
+
else if (key === 'translateY') {
|
|
6
|
+
return new WebKitCSSMatrix(styles.transform).m42;
|
|
7
|
+
}
|
|
8
|
+
else if (key === 'translateZ') {
|
|
9
|
+
return new WebKitCSSMatrix(styles.transform).m43;
|
|
10
|
+
}
|
|
11
|
+
else if (key === 'rotateX') {
|
|
12
|
+
return new WebKitCSSMatrix(styles.transform).m12;
|
|
13
|
+
}
|
|
14
|
+
else if (key === 'rotateY') {
|
|
15
|
+
return new WebKitCSSMatrix(styles.transform).m21;
|
|
16
|
+
}
|
|
17
|
+
else if (key === 'rotateZ') {
|
|
18
|
+
return new WebKitCSSMatrix(styles.transform).m31;
|
|
19
|
+
}
|
|
20
|
+
else if (key === 'scaleX') {
|
|
21
|
+
return new WebKitCSSMatrix(styles.transform).m11;
|
|
22
|
+
}
|
|
23
|
+
else if (key === 'scaleY') {
|
|
24
|
+
return new WebKitCSSMatrix(styles.transform).m22;
|
|
25
|
+
}
|
|
26
|
+
else if (key === 'scaleZ') {
|
|
27
|
+
return new WebKitCSSMatrix(styles.transform).m33;
|
|
28
|
+
}
|
|
29
|
+
else if (key === 'skewX') {
|
|
30
|
+
return new WebKitCSSMatrix(styles.transform).m13;
|
|
31
|
+
}
|
|
32
|
+
else if (key === 'skewY') {
|
|
33
|
+
return new WebKitCSSMatrix(styles.transform).m23;
|
|
34
|
+
}
|
|
35
|
+
else if (key === 'grayScale') {
|
|
36
|
+
return Number(styles.filter.match(/grayscale\((\d+)%\)/)?.[1]);
|
|
37
|
+
}
|
|
38
|
+
else if (key === 'sepia') {
|
|
39
|
+
return Number(styles.filter.match(/sepia\((\d+)%\)/)?.[1]);
|
|
40
|
+
}
|
|
41
|
+
else if (key === 'saturate') {
|
|
42
|
+
return Number(styles.filter.match(/saturate\((\d+)%\)/)?.[1]);
|
|
43
|
+
}
|
|
44
|
+
else if (key === 'hueRotate') {
|
|
45
|
+
return Number(styles.filter.match(/hue-rotate\((\d+)deg\)/)?.[1]);
|
|
46
|
+
}
|
|
47
|
+
else if (key === 'invert') {
|
|
48
|
+
return Number(styles.filter.match(/invert\((\d+)%\)/)?.[1]);
|
|
49
|
+
}
|
|
50
|
+
else if (key === 'brightness') {
|
|
51
|
+
return Number(styles.filter.match(/brightness\((\d+)%\)/)?.[1]);
|
|
52
|
+
}
|
|
53
|
+
else if (key === 'contrast') {
|
|
54
|
+
return Number(styles.filter.match(/contrast\((\d+)%\)/)?.[1]);
|
|
55
|
+
}
|
|
56
|
+
else if (key === 'blur') {
|
|
57
|
+
return Number(styles.filter.match(/blur\((\d+)px\)/)?.[1]);
|
|
58
|
+
}
|
|
59
|
+
return Number(styles.getPropertyValue(key));
|
|
60
|
+
}
|
|
61
|
+
export function getComputedAnimatable(el, styles) {
|
|
62
|
+
const result = {};
|
|
63
|
+
const computedStyles = getComputedStyle(el);
|
|
64
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
65
|
+
const k = key;
|
|
66
|
+
if (value != null) {
|
|
67
|
+
result[k] = getComputedAnimatableProp(computedStyles, k);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
export function applyAnimatableProp(el, key, value) {
|
|
73
|
+
if (value == null)
|
|
74
|
+
return;
|
|
75
|
+
if (key === 'translateX') {
|
|
76
|
+
el.style.transform += ` translateX(${value}px)`;
|
|
77
|
+
}
|
|
78
|
+
else if (key === 'translateY') {
|
|
79
|
+
el.style.transform += ` translateY(${value}px)`;
|
|
80
|
+
}
|
|
81
|
+
else if (key === 'translateZ') {
|
|
82
|
+
el.style.transform += ` translateZ(${value}px)`;
|
|
83
|
+
}
|
|
84
|
+
else if (key === 'rotateX') {
|
|
85
|
+
el.style.transform += ` rotateX(${value}deg)`;
|
|
86
|
+
}
|
|
87
|
+
else if (key === 'rotateY') {
|
|
88
|
+
el.style.transform += ` rotateY(${value}deg)`;
|
|
89
|
+
}
|
|
90
|
+
else if (key === 'rotateZ') {
|
|
91
|
+
el.style.transform += ` rotateZ(${value}deg)`;
|
|
92
|
+
}
|
|
93
|
+
else if (key === 'scaleX') {
|
|
94
|
+
el.style.transform += ` scaleX(${value})`;
|
|
95
|
+
}
|
|
96
|
+
else if (key === 'scaleY') {
|
|
97
|
+
el.style.transform += ` scaleY(${value})`;
|
|
98
|
+
}
|
|
99
|
+
else if (key === 'scaleZ') {
|
|
100
|
+
el.style.transform += ` scaleZ(${value})`;
|
|
101
|
+
}
|
|
102
|
+
else if (key === 'skewX') {
|
|
103
|
+
el.style.transform += ` skewX(${value}deg)`;
|
|
104
|
+
}
|
|
105
|
+
else if (key === 'skewY') {
|
|
106
|
+
el.style.transform += ` skewY(${value}deg)`;
|
|
107
|
+
}
|
|
108
|
+
else if (key === 'grayScale') {
|
|
109
|
+
el.style.filter += ` grayscale(${value}%)`;
|
|
110
|
+
}
|
|
111
|
+
else if (key === 'sepia') {
|
|
112
|
+
el.style.filter += ` sepia(${value}%)`;
|
|
113
|
+
}
|
|
114
|
+
else if (key === 'saturate') {
|
|
115
|
+
el.style.filter += ` saturate(${value}%)`;
|
|
116
|
+
}
|
|
117
|
+
else if (key === 'hueRotate') {
|
|
118
|
+
el.style.filter += ` hue-rotate(${value}deg)`;
|
|
119
|
+
}
|
|
120
|
+
else if (key === 'invert') {
|
|
121
|
+
el.style.filter += ` invert(${value}%)`;
|
|
122
|
+
}
|
|
123
|
+
else if (key === 'brightness') {
|
|
124
|
+
el.style.filter += ` brightness(${value}%)`;
|
|
125
|
+
}
|
|
126
|
+
else if (key === 'contrast') {
|
|
127
|
+
el.style.filter += ` contrast(${value}%)`;
|
|
128
|
+
}
|
|
129
|
+
else if (key === 'blur') {
|
|
130
|
+
el.style.filter += ` blur(${value}px)`;
|
|
131
|
+
}
|
|
132
|
+
el.style.setProperty(key, String(value));
|
|
133
|
+
}
|
|
134
|
+
export function applyInterpolatedAnimatableProp(el, key, from, to, progress) {
|
|
135
|
+
if (from != null && to != null) {
|
|
136
|
+
const value = from + (to - from) * progress;
|
|
137
|
+
applyAnimatableProp(el, key, value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function applyInterpolatedAnimatable(el, from, to, progress) {
|
|
141
|
+
el.style.transform = '';
|
|
142
|
+
el.style.filter = '';
|
|
143
|
+
for (const [key, value] of Object.entries(to)) {
|
|
144
|
+
const k = key;
|
|
145
|
+
applyInterpolatedAnimatableProp(el, k, from[k], value, progress);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export function applyAnimatable(el, styles) {
|
|
149
|
+
el.style.transform = '';
|
|
150
|
+
el.style.filter = '';
|
|
151
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
152
|
+
if (value != null) {
|
|
153
|
+
applyAnimatableProp(el, key, value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
package/dom-context.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
setStyle(name: string, value: string | undefined | null): void;
|
|
37
|
+
createStyle(name: string, value: string | undefined | null): [(newValue: string) => void, Clear];
|
|
38
|
+
}
|