@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,45 @@
|
|
|
1
|
+
import { Prop } from '../prop';
|
|
2
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
3
|
+
export class OneOfImpl {
|
|
4
|
+
match;
|
|
5
|
+
cases;
|
|
6
|
+
constructor(match, cases) {
|
|
7
|
+
this.match = match;
|
|
8
|
+
this.cases = cases;
|
|
9
|
+
}
|
|
10
|
+
appendTo = (ctx) => {
|
|
11
|
+
const pair = this.match.get();
|
|
12
|
+
let key = pair[0];
|
|
13
|
+
const value = pair[1];
|
|
14
|
+
const stableCtx = ctx.makeReference();
|
|
15
|
+
let prop = new Prop(value);
|
|
16
|
+
let newCtx = stableCtx.makeReference();
|
|
17
|
+
let clear = makeRenderable(this.cases[key](prop)).appendTo(newCtx);
|
|
18
|
+
const cancel = this.match.subscribe(([newKey, newValue]) => {
|
|
19
|
+
if (newKey !== key) {
|
|
20
|
+
newCtx.requestClear(true, () => {
|
|
21
|
+
newCtx = stableCtx.makeReference();
|
|
22
|
+
key = newKey;
|
|
23
|
+
prop.clean();
|
|
24
|
+
prop = new Prop(newValue);
|
|
25
|
+
clear(true);
|
|
26
|
+
clear = makeRenderable(this.cases[key](prop)).appendTo(newCtx);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
prop.set(newValue);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return (removeTree) => {
|
|
34
|
+
newCtx.requestClear(removeTree, () => {
|
|
35
|
+
cancel();
|
|
36
|
+
prop.clean();
|
|
37
|
+
stableCtx.requestClear(removeTree, () => { });
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// <OneOf match={counter.map(v => v % 2 == 0 ? [1, "odd"] : [2, "even"])} 1={t => <b>{t}</b>} 2={t => <i>{t}</i>} /
|
|
43
|
+
export function OneOf(props) {
|
|
44
|
+
return new OneOfImpl(props.match, props);
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Clear } from '../clean';
|
|
2
|
+
import { type DOMContext } from '../dom-context';
|
|
3
|
+
import { type Renderable } from '../renderable';
|
|
4
|
+
import { type JSX } from '../jsx';
|
|
5
|
+
export declare class PortalImpl implements Renderable {
|
|
6
|
+
private readonly selector;
|
|
7
|
+
private readonly children;
|
|
8
|
+
constructor(selector: string, children: JSX.DOMNode);
|
|
9
|
+
appendTo(ctx: DOMContext): Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface PortalProps {
|
|
12
|
+
selector: string;
|
|
13
|
+
children?: JSX.DOMNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function Portal(props: PortalProps): JSX.DOMNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { render } from '../render';
|
|
2
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
3
|
+
export class PortalImpl {
|
|
4
|
+
selector;
|
|
5
|
+
children;
|
|
6
|
+
constructor(selector, children) {
|
|
7
|
+
this.selector = selector;
|
|
8
|
+
this.children = children;
|
|
9
|
+
}
|
|
10
|
+
appendTo(ctx) {
|
|
11
|
+
const element = ctx.getDocument().querySelector(this.selector);
|
|
12
|
+
if (element === null) {
|
|
13
|
+
throw new Error(`Cannot find element by selector: ${this.selector}`);
|
|
14
|
+
}
|
|
15
|
+
return render(makeRenderable(this.children), element);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function Portal(props) {
|
|
19
|
+
return new PortalImpl(props.selector, props.children);
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type 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 class PropertyImpl<T> implements Renderable {
|
|
6
|
+
private readonly name;
|
|
7
|
+
private readonly value;
|
|
8
|
+
constructor(name: string, value: Signal<T>);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface PropertyProps<T> {
|
|
12
|
+
name: string;
|
|
13
|
+
value: Signal<T>;
|
|
14
|
+
}
|
|
15
|
+
export declare function Property<T>({ name, value }: PropertyProps<T>): Renderable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { subscribeToSignal } from './Text';
|
|
2
|
+
export class PropertyImpl {
|
|
3
|
+
name;
|
|
4
|
+
value;
|
|
5
|
+
constructor(name, value) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
appendTo = (ctx) => {
|
|
10
|
+
const [set, clear] = ctx.createProperty(this.name, this.value.get());
|
|
11
|
+
return subscribeToSignal(this.value, set, clear);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function Property({ name, value }) {
|
|
15
|
+
return new PropertyImpl(name, value);
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Clear } from '../clean';
|
|
2
|
+
import { type DOMContext, type ProviderMark } from '../dom-context';
|
|
3
|
+
import { type Renderable } from '../renderable';
|
|
4
|
+
import { type JSX } from '../jsx';
|
|
5
|
+
export declare class ProviderImpl<T> implements Renderable {
|
|
6
|
+
private readonly mark;
|
|
7
|
+
private readonly provider;
|
|
8
|
+
private readonly children;
|
|
9
|
+
constructor(mark: ProviderMark<T>, provider: T, children: JSX.DOMNode);
|
|
10
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderProps<T> {
|
|
13
|
+
mark: ProviderMark<T>;
|
|
14
|
+
value: T;
|
|
15
|
+
children?: JSX.DOMNode;
|
|
16
|
+
}
|
|
17
|
+
export declare function Provider<T>({ mark, value, children }: ProviderProps<T>): JSX.DOMNode;
|
|
18
|
+
export declare class ConsumerImpl<T> implements Renderable {
|
|
19
|
+
private readonly mark;
|
|
20
|
+
private readonly children;
|
|
21
|
+
constructor(mark: ProviderMark<T>, children: (provider: T) => JSX.DOMNode);
|
|
22
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
23
|
+
}
|
|
24
|
+
export interface ConsumerProps<T> {
|
|
25
|
+
mark: ProviderMark<T>;
|
|
26
|
+
children?: (provider: T) => JSX.DOMNode;
|
|
27
|
+
}
|
|
28
|
+
export declare function Consumer<T>({ mark, children }: ConsumerProps<T>): JSX.DOMNode;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
2
|
+
export class ProviderImpl {
|
|
3
|
+
mark;
|
|
4
|
+
provider;
|
|
5
|
+
children;
|
|
6
|
+
constructor(mark, provider, children) {
|
|
7
|
+
this.mark = mark;
|
|
8
|
+
this.provider = provider;
|
|
9
|
+
this.children = children;
|
|
10
|
+
}
|
|
11
|
+
appendTo = (ctx) => {
|
|
12
|
+
const newCtx = ctx.withProvider(this.mark, this.provider);
|
|
13
|
+
const clear = makeRenderable(this.children).appendTo(newCtx);
|
|
14
|
+
return (removeTree) => {
|
|
15
|
+
newCtx.requestClear(removeTree, () => {
|
|
16
|
+
clear(removeTree);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function Provider({ mark, value, children }) {
|
|
22
|
+
return new ProviderImpl(mark, value, children);
|
|
23
|
+
}
|
|
24
|
+
export class ConsumerImpl {
|
|
25
|
+
mark;
|
|
26
|
+
children;
|
|
27
|
+
constructor(mark, children) {
|
|
28
|
+
this.mark = mark;
|
|
29
|
+
this.children = children;
|
|
30
|
+
}
|
|
31
|
+
appendTo = (ctx) => {
|
|
32
|
+
const provider = ctx.getProvider(this.mark);
|
|
33
|
+
if (provider == null) {
|
|
34
|
+
throw new Error('No provider found for mark');
|
|
35
|
+
}
|
|
36
|
+
const clear = makeRenderable(this.children(provider)).appendTo(ctx);
|
|
37
|
+
return (removeTree) => {
|
|
38
|
+
clear(removeTree);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function Consumer({ mark, children }) {
|
|
43
|
+
return new ConsumerImpl(mark, children ?? (() => []));
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 RepeatImpl implements Renderable {
|
|
6
|
+
private readonly times;
|
|
7
|
+
private readonly children;
|
|
8
|
+
constructor(times: Signal<number>, children: (index: number) => Renderable);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface RepeatProps {
|
|
12
|
+
times: Signal<number>;
|
|
13
|
+
children?: (index: number) => Renderable;
|
|
14
|
+
}
|
|
15
|
+
export declare function Repeat(props: RepeatProps): Renderable;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fragment } from './Fragment';
|
|
2
|
+
export class RepeatImpl {
|
|
3
|
+
times;
|
|
4
|
+
children;
|
|
5
|
+
constructor(times, children) {
|
|
6
|
+
this.times = times;
|
|
7
|
+
this.children = children;
|
|
8
|
+
}
|
|
9
|
+
appendTo = (ctx) => {
|
|
10
|
+
const newCtx = ctx.makeReference();
|
|
11
|
+
const count = this.times.get();
|
|
12
|
+
const clears = new Array(count);
|
|
13
|
+
for (let i = 0; i < count; i++) {
|
|
14
|
+
clears[i] = this.children(i).appendTo(newCtx);
|
|
15
|
+
}
|
|
16
|
+
const cancel = this.times.subscribe((newCount) => {
|
|
17
|
+
while (newCount < clears.length) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
+
clears.pop()(true);
|
|
20
|
+
}
|
|
21
|
+
for (let i = clears.length; i < newCount; i++) {
|
|
22
|
+
clears[i] = this.children(i).appendTo(newCtx);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return (removeTree) => {
|
|
26
|
+
newCtx.requestClear(removeTree, () => {
|
|
27
|
+
cancel();
|
|
28
|
+
clears.forEach(clear => { clear(removeTree); });
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function Repeat(props) { return new RepeatImpl(props.times, props.children ?? (() => Fragment({ children: [] }))); }
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @jsxImportSource .. */
|
|
2
|
+
import { type Signal } from '../prop';
|
|
3
|
+
import { type Renderable } from '../renderable';
|
|
4
|
+
import { type JSX } from '../jsx';
|
|
5
|
+
import { type Clear } from '../clean';
|
|
6
|
+
import { type DOMContext } from '../dom-context';
|
|
7
|
+
export type Condition<T> = Signal<T | null | undefined> | Signal<T | undefined> | Signal<T | null> | Signal<T>;
|
|
8
|
+
export declare class ShowImpl<T> implements Renderable {
|
|
9
|
+
private readonly on;
|
|
10
|
+
private readonly otherwise;
|
|
11
|
+
private readonly children;
|
|
12
|
+
constructor(on: Condition<T>, otherwise: JSX.DOMNode, children: (value: Signal<NonNullable<T>>) => JSX.DOMNode);
|
|
13
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
14
|
+
}
|
|
15
|
+
export interface ShowProps<T> {
|
|
16
|
+
when: Condition<T>;
|
|
17
|
+
otherwise?: JSX.DOMNode;
|
|
18
|
+
children?: (value: Signal<NonNullable<T>>) => JSX.DOMNode;
|
|
19
|
+
}
|
|
20
|
+
export declare function Show<T>({ when, children, otherwise }: ShowProps<T>): ShowImpl<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "../jsx-runtime";
|
|
2
|
+
import { If } from './If';
|
|
3
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
4
|
+
export class ShowImpl {
|
|
5
|
+
on;
|
|
6
|
+
otherwise;
|
|
7
|
+
children;
|
|
8
|
+
constructor(on, otherwise, children) {
|
|
9
|
+
this.on = on;
|
|
10
|
+
this.otherwise = otherwise;
|
|
11
|
+
this.children = children;
|
|
12
|
+
}
|
|
13
|
+
appendTo = (ctx) => {
|
|
14
|
+
const condition = this.on.map(v => v != null);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
const el = makeRenderable(_jsx(If, { is: condition, then: this.children(this.on), otherwise: this.otherwise }));
|
|
17
|
+
return el.appendTo(ctx);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function Show({ when, children, otherwise }) {
|
|
21
|
+
return new ShowImpl(when, otherwise, children ?? (() => _jsx(_Fragment, {})));
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** @jsxImportSource .. */
|
|
2
|
+
import { type Renderable } from '../types/renderable';
|
|
3
|
+
import { type Clear } from '../types/clean';
|
|
4
|
+
import { type DOMContext } from '../dom-context';
|
|
5
|
+
export interface Animatable {
|
|
6
|
+
width?: number;
|
|
7
|
+
maxWidth?: number;
|
|
8
|
+
minWidth?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
maxHeight?: number;
|
|
11
|
+
minHeight?: number;
|
|
12
|
+
lineHeight?: number;
|
|
13
|
+
opacity?: number;
|
|
14
|
+
top?: number;
|
|
15
|
+
left?: number;
|
|
16
|
+
right?: number;
|
|
17
|
+
bottom?: number;
|
|
18
|
+
padding?: number;
|
|
19
|
+
paddingTop?: number;
|
|
20
|
+
paddingBottom?: number;
|
|
21
|
+
paddingLeft?: number;
|
|
22
|
+
paddingRight?: number;
|
|
23
|
+
margin?: number;
|
|
24
|
+
marginTop?: number;
|
|
25
|
+
marginBottom?: number;
|
|
26
|
+
marginLeft?: number;
|
|
27
|
+
marginRight?: number;
|
|
28
|
+
fontSize?: number;
|
|
29
|
+
letterSpacing?: number;
|
|
30
|
+
borderWidth?: number;
|
|
31
|
+
borderRadius?: number;
|
|
32
|
+
translateX?: number;
|
|
33
|
+
translateY?: number;
|
|
34
|
+
translateZ?: number;
|
|
35
|
+
rotateX?: number;
|
|
36
|
+
rotateY?: number;
|
|
37
|
+
rotateZ?: number;
|
|
38
|
+
scaleX?: number;
|
|
39
|
+
scaleY?: number;
|
|
40
|
+
scaleZ?: number;
|
|
41
|
+
skewX?: number;
|
|
42
|
+
skewY?: number;
|
|
43
|
+
grayScale?: number;
|
|
44
|
+
sepia?: number;
|
|
45
|
+
saturate?: number;
|
|
46
|
+
hueRotate?: number;
|
|
47
|
+
invert?: number;
|
|
48
|
+
brightness?: number;
|
|
49
|
+
contrast?: number;
|
|
50
|
+
blur?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface TweenAnimation {
|
|
53
|
+
style: Animatable;
|
|
54
|
+
duration?: number;
|
|
55
|
+
delay?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface TweenProps {
|
|
58
|
+
enter?: TweenAnimation[];
|
|
59
|
+
exit?: TweenAnimation[];
|
|
60
|
+
style?: Animatable;
|
|
61
|
+
}
|
|
62
|
+
export declare function getComputedStyleValue(styles: CSSStyleDeclaration, key: keyof Animatable): Animatable[typeof key];
|
|
63
|
+
export declare function getCurrentStyleValues(el: HTMLElement, styles: Animatable): Animatable;
|
|
64
|
+
export declare function applyStyle(el: HTMLElement, key: keyof Animatable, value: Animatable[typeof key]): void;
|
|
65
|
+
export declare function applyInterpolatedStyle(el: HTMLElement, key: keyof Animatable, from: Animatable[typeof key], to: Animatable[typeof key], progress: number): void;
|
|
66
|
+
export declare function applyInterpolatedStyles(el: HTMLElement, from: Animatable, to: Animatable, progress: number): void;
|
|
67
|
+
export declare function applyStyles(el: HTMLElement, styles: Animatable): void;
|
|
68
|
+
export declare class TweenImpl implements Renderable {
|
|
69
|
+
private readonly enter;
|
|
70
|
+
private readonly exit;
|
|
71
|
+
private readonly style?;
|
|
72
|
+
constructor(enter?: TweenAnimation[], exit?: TweenAnimation[], style?: Animatable | undefined);
|
|
73
|
+
appendTo(ctx: DOMContext): Clear;
|
|
74
|
+
}
|
|
75
|
+
export declare function Tween({ enter, exit, style }: TweenProps): TweenImpl;
|