@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.
Files changed (193) hide show
  1. package/README.md +1 -0
  2. package/clean.d.ts +2 -0
  3. package/clean.js +1 -0
  4. package/components/Attribute.d.ts +15 -0
  5. package/components/Attribute.js +16 -0
  6. package/components/BooleanAttribute.d.ts +15 -0
  7. package/components/BooleanAttribute.js +16 -0
  8. package/components/ClassName.d.ts +13 -0
  9. package/components/ClassName.js +14 -0
  10. package/components/El.d.ts +15 -0
  11. package/components/El.js +21 -0
  12. package/components/FadeIn.d.ts +18 -0
  13. package/components/FadeIn.js +52 -0
  14. package/components/FadeOut.d.ts +16 -0
  15. package/components/FadeOut.js +39 -0
  16. package/components/For.d.ts +7 -0
  17. package/components/For.js +15 -0
  18. package/components/Fragment.d.ts +12 -0
  19. package/components/Fragment.js +16 -0
  20. package/components/HiddenWhenEmpty.d.ts +7 -0
  21. package/components/HiddenWhenEmpty.js +12 -0
  22. package/components/If.d.ts +14 -0
  23. package/components/If.js +19 -0
  24. package/components/InnerHTML.d.ts +13 -0
  25. package/components/InnerHTML.js +23 -0
  26. package/components/Lifecycle.d.ts +14 -0
  27. package/components/Lifecycle.js +18 -0
  28. package/components/Match.d.ts +33 -0
  29. package/components/Match.js +44 -0
  30. package/components/NotEmpty.d.ts +10 -0
  31. package/components/NotEmpty.js +11 -0
  32. package/components/On.d.ts +15 -0
  33. package/components/On.js +14 -0
  34. package/components/OnRemove.d.ts +11 -0
  35. package/components/OnRemove.js +14 -0
  36. package/components/OneOf.d.ts +20 -0
  37. package/components/OneOf.js +45 -0
  38. package/components/Portal.d.ts +15 -0
  39. package/components/Portal.js +20 -0
  40. package/components/Property.d.ts +15 -0
  41. package/components/Property.js +16 -0
  42. package/components/Provider.d.ts +28 -0
  43. package/components/Provider.js +44 -0
  44. package/components/Repeat.d.ts +15 -0
  45. package/components/Repeat.js +33 -0
  46. package/components/Shadow.d.ts +0 -0
  47. package/components/Shadow.js +1 -0
  48. package/components/Show.d.ts +20 -0
  49. package/components/Show.js +22 -0
  50. package/components/Text.d.ts +15 -0
  51. package/components/Text.js +33 -0
  52. package/components/TextContent.d.ts +13 -0
  53. package/components/TextContent.js +23 -0
  54. package/components/Tween.d.ts +75 -0
  55. package/components/Tween.js +242 -0
  56. package/components/animatable.d.ts +53 -0
  57. package/components/animatable.js +156 -0
  58. package/dom-context.d.ts +38 -0
  59. package/dom-context.js +260 -0
  60. package/helpers/handle-anchor-click.d.ts +4 -0
  61. package/helpers/handle-anchor-click.js +43 -0
  62. package/helpers/handle-text-input.d.ts +1 -0
  63. package/helpers/handle-text-input.js +4 -0
  64. package/helpers/is-empty-element.d.ts +2 -0
  65. package/helpers/is-empty-element.js +8 -0
  66. package/index.d.ts +36 -0
  67. package/jsx-dev-runtime.d.ts +1 -0
  68. package/jsx-dev-runtime.js +1 -0
  69. package/jsx-runtime.d.ts +9 -0
  70. package/jsx-runtime.js +157 -0
  71. package/jsx.d.ts +806 -0
  72. package/jsx.js +1 -0
  73. package/package.json +5 -3
  74. package/prop.d.ts +43 -0
  75. package/prop.js +174 -0
  76. package/render.d.ts +3 -0
  77. package/render.js +7 -0
  78. package/renderable.d.ts +5 -0
  79. package/renderable.js +1 -0
  80. package/types/clean.d.ts +2 -0
  81. package/types/clean.js +1 -0
  82. package/types/idom-context.d.ts +27 -0
  83. package/types/idom-context.js +3 -0
  84. package/types/renderable.d.ts +5 -0
  85. package/types/renderable.js +1 -0
  86. package/.eslintignore +0 -10
  87. package/.eslintrc.cjs +0 -28
  88. package/coverage/clover.xml +0 -39
  89. package/coverage/coverage-final.json +0 -2
  90. package/coverage/lcov-report/OneOf.ts.html +0 -256
  91. package/coverage/lcov-report/base.css +0 -224
  92. package/coverage/lcov-report/block-navigation.js +0 -87
  93. package/coverage/lcov-report/dom-context.ts.html +0 -928
  94. package/coverage/lcov-report/favicon.png +0 -0
  95. package/coverage/lcov-report/index.html +0 -116
  96. package/coverage/lcov-report/prettify.css +0 -1
  97. package/coverage/lcov-report/prettify.js +0 -2
  98. package/coverage/lcov-report/prop.ts.html +0 -691
  99. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  100. package/coverage/lcov-report/sorter.js +0 -196
  101. package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
  102. package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
  103. package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
  104. package/coverage/lcov-report/src/components/El.ts.html +0 -166
  105. package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
  106. package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
  107. package/coverage/lcov-report/src/components/For.ts.html +0 -151
  108. package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
  109. package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
  110. package/coverage/lcov-report/src/components/If.ts.html +0 -217
  111. package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
  112. package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
  113. package/coverage/lcov-report/src/components/Match.ts.html +0 -286
  114. package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
  115. package/coverage/lcov-report/src/components/On.ts.html +0 -151
  116. package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
  117. package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
  118. package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
  119. package/coverage/lcov-report/src/components/Property.ts.html +0 -154
  120. package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
  121. package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
  122. package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
  123. package/coverage/lcov-report/src/components/Text.ts.html +0 -229
  124. package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
  125. package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
  126. package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
  127. package/coverage/lcov-report/src/components/index.html +0 -476
  128. package/coverage/lcov-report/src/dom-context.ts.html +0 -928
  129. package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
  130. package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
  131. package/coverage/lcov-report/src/helpers/index.html +0 -146
  132. package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
  133. package/coverage/lcov-report/src/index.html +0 -176
  134. package/coverage/lcov-report/src/index.ts.html +0 -412
  135. package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
  136. package/coverage/lcov-report/src/prop.ts.html +0 -691
  137. package/coverage/lcov-report/src/render.ts.html +0 -112
  138. package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
  139. package/coverage/lcov-report/src/types/index.html +0 -116
  140. package/coverage/lcov-report/test/common.ts.html +0 -112
  141. package/coverage/lcov-report/test/index.html +0 -116
  142. package/coverage/lcov.info +0 -57
  143. package/jest.config.js +0 -5
  144. package/src/clean.ts +0 -2
  145. package/src/components/Attribute.ts +0 -23
  146. package/src/components/BooleanAttribute.ts +0 -23
  147. package/src/components/ClassName.ts +0 -22
  148. package/src/components/El.ts +0 -27
  149. package/src/components/FadeIn.ts +0 -59
  150. package/src/components/FadeOut.ts +0 -47
  151. package/src/components/For.ts +0 -22
  152. package/src/components/Fragment.ts +0 -19
  153. package/src/components/HiddenWhenEmpty.ts +0 -16
  154. package/src/components/If.ts +0 -44
  155. package/src/components/InnerHTML.ts +0 -31
  156. package/src/components/Lifecycle.ts +0 -24
  157. package/src/components/Match.ts +0 -67
  158. package/src/components/NotEmpty.tsx +0 -33
  159. package/src/components/On.ts +0 -22
  160. package/src/components/OnRemove.ts +0 -20
  161. package/src/components/OneOf.ts +0 -57
  162. package/src/components/Portal.ts +0 -30
  163. package/src/components/Property.ts +0 -23
  164. package/src/components/Provider.ts +0 -53
  165. package/src/components/Repeat.ts +0 -46
  166. package/src/components/Show.tsx +0 -35
  167. package/src/components/Text.ts +0 -48
  168. package/src/components/TextContent.ts +0 -31
  169. package/src/components/animatable.ts +0 -178
  170. package/src/dom-context.ts +0 -281
  171. package/src/helpers/handle-anchor-click.ts +0 -64
  172. package/src/helpers/handle-text-input.ts +0 -5
  173. package/src/helpers/is-empty-element.ts +0 -9
  174. package/src/index.ts +0 -109
  175. package/src/jsx-dev-runtime.ts +0 -8
  176. package/src/jsx-runtime.ts +0 -172
  177. package/src/jsx.ts +0 -1046
  178. package/src/prop.ts +0 -202
  179. package/src/render.ts +0 -9
  180. package/src/renderable.ts +0 -6
  181. package/test/common.ts +0 -9
  182. package/test/component.spec.tsx +0 -27
  183. package/test/domcontext.spec.ts +0 -36
  184. package/test/fadein.spec.tsx +0 -36
  185. package/test/fadeout.spec.tsx +0 -41
  186. package/test/if.spec.tsx +0 -30
  187. package/test/innerhtml.spec.tsx +0 -45
  188. package/test/prop.spec.ts +0 -10
  189. package/test/render.spec.tsx +0 -19
  190. package/test/textcontent.spec.tsx +0 -45
  191. package/test/when.spec.tsx +0 -30
  192. package/tsconfig.json +0 -21
  193. /package/{dist/index.js → index.js} +0 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @tempots/dom
package/clean.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type Clear = (removeTree: boolean) => void;
2
+ export type Clean = () => void;
package/clean.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type DOMContext } from '../dom-context';
2
+ import { type Signal } from '../prop';
3
+ import { type Clear } from '../clean';
4
+ import { type Renderable } from '../renderable';
5
+ export declare class AttributeImpl implements Renderable {
6
+ private readonly name;
7
+ private readonly value;
8
+ constructor(name: string, value: Signal<string>);
9
+ readonly appendTo: (ctx: DOMContext) => Clear;
10
+ }
11
+ export interface AttributeProps {
12
+ name: string;
13
+ value: Signal<string>;
14
+ }
15
+ export declare function Attribute({ name, value }: AttributeProps): Renderable;
@@ -0,0 +1,16 @@
1
+ import { subscribeToSignal } from './Text';
2
+ export class AttributeImpl {
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.createAttribute(this.name, this.value.get());
11
+ return subscribeToSignal(this.value, set, clear);
12
+ };
13
+ }
14
+ export function Attribute({ name, value }) {
15
+ return new AttributeImpl(name, value);
16
+ }
@@ -0,0 +1,15 @@
1
+ import { type DOMContext } from '../dom-context';
2
+ import { type Signal } from '../prop';
3
+ import { type Clear } from '../clean';
4
+ import { type Renderable } from '../renderable';
5
+ export declare class BooleanAttributeImpl implements Renderable {
6
+ private readonly name;
7
+ private readonly value;
8
+ constructor(name: string, value: Signal<boolean>);
9
+ readonly appendTo: (ctx: DOMContext) => Clear;
10
+ }
11
+ export interface BooleanAttributeProps {
12
+ name: string;
13
+ value: Signal<boolean>;
14
+ }
15
+ export declare function BooleanAttribute({ name, value }: BooleanAttributeProps): Renderable;
@@ -0,0 +1,16 @@
1
+ import { subscribeToSignal } from './Text';
2
+ export class BooleanAttributeImpl {
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.createBooleanAttribute(this.name, this.value.get());
11
+ return subscribeToSignal(this.value, set, clear);
12
+ };
13
+ }
14
+ export function BooleanAttribute({ name, value }) {
15
+ return new BooleanAttributeImpl(name, value);
16
+ }
@@ -0,0 +1,13 @@
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 ClassNameImpl implements Renderable {
6
+ private readonly cls;
7
+ constructor(cls: Signal<string> | Signal<string | undefined>);
8
+ readonly appendTo: (ctx: DOMContext) => Clear;
9
+ }
10
+ export interface ClassNameProps {
11
+ value: Signal<string> | Signal<string | undefined>;
12
+ }
13
+ export declare function ClassName({ value }: ClassNameProps): Renderable;
@@ -0,0 +1,14 @@
1
+ import { subscribeToSignal } from './Text';
2
+ export class ClassNameImpl {
3
+ cls;
4
+ constructor(cls) {
5
+ this.cls = cls;
6
+ }
7
+ appendTo = (ctx) => {
8
+ const [set, clear] = ctx.createClass(this.cls.get() ?? '');
9
+ return subscribeToSignal(this.cls.map(v => v ?? ''), set, clear);
10
+ };
11
+ }
12
+ export function ClassName({ value }) {
13
+ return new ClassNameImpl(value);
14
+ }
@@ -0,0 +1,15 @@
1
+ import { type DOMContext } from '../dom-context';
2
+ import { type Clear } from '../clean';
3
+ import { type Renderable } from '../renderable';
4
+ import { type JSX } from '../jsx';
5
+ export declare class ElImpl implements Renderable {
6
+ private readonly tagName;
7
+ private readonly children;
8
+ constructor(tagName: string, children: Renderable[]);
9
+ readonly appendTo: (ctx: DOMContext) => Clear;
10
+ }
11
+ export interface ElProps {
12
+ tagName: string;
13
+ children?: JSX.DOMNode;
14
+ }
15
+ export declare function El({ tagName, children }: ElProps): Renderable;
@@ -0,0 +1,21 @@
1
+ import { makeRenderables } from '../jsx-runtime';
2
+ export class ElImpl {
3
+ tagName;
4
+ children;
5
+ constructor(tagName, children) {
6
+ this.tagName = tagName;
7
+ this.children = children;
8
+ }
9
+ appendTo = (ctx) => {
10
+ const newCtx = ctx.makeElement(this.tagName);
11
+ const clears = this.children.map(child => child.appendTo(newCtx));
12
+ return (removeTree) => {
13
+ newCtx.requestClear(removeTree, () => {
14
+ clears.forEach(clear => { clear(false); });
15
+ });
16
+ };
17
+ };
18
+ }
19
+ export function El({ tagName, children }) {
20
+ return new ElImpl(tagName, makeRenderables(children));
21
+ }
@@ -0,0 +1,18 @@
1
+ import { Clear } from "../clean";
2
+ import { DOMContext } from "../dom-context";
3
+ import { Renderable } from "../renderable";
4
+ import { Animatable } from "./animatable";
5
+ export declare class FadeInImpl implements Renderable {
6
+ private readonly end;
7
+ private readonly start;
8
+ private readonly duration;
9
+ private readonly delay;
10
+ constructor(end: Animatable, start: Animatable | undefined, duration: number, delay: number);
11
+ appendTo(ctx: DOMContext): Clear;
12
+ }
13
+ export interface FadeInProps extends Animatable {
14
+ start?: Animatable;
15
+ duration?: number;
16
+ delay?: number;
17
+ }
18
+ export declare function FadeIn(props: FadeInProps): Renderable;
@@ -0,0 +1,52 @@
1
+ import { getComputedAnimatable, applyInterpolatedAnimatable, applyAnimatable } from "./animatable";
2
+ export class FadeInImpl {
3
+ end;
4
+ start;
5
+ duration;
6
+ delay;
7
+ constructor(end, start, duration, delay) {
8
+ this.end = end;
9
+ this.start = start;
10
+ this.duration = duration;
11
+ this.delay = delay;
12
+ }
13
+ appendTo(ctx) {
14
+ const el = ctx.getElement();
15
+ const start = (() => {
16
+ if (this.start != null) {
17
+ applyAnimatable(el, this.start);
18
+ return this.start;
19
+ }
20
+ else {
21
+ return getComputedAnimatable(el, this.end);
22
+ }
23
+ })();
24
+ const startTime = Date.now() + this.delay;
25
+ const { duration, end } = this;
26
+ let nextFrameId = null;
27
+ function frame() {
28
+ const now = Date.now();
29
+ if (now < startTime) {
30
+ nextFrameId = requestAnimationFrame(frame);
31
+ return;
32
+ }
33
+ const progress = Math.min((now - startTime) / duration, 1);
34
+ applyInterpolatedAnimatable(el, start, end, progress);
35
+ if (progress < 1) {
36
+ nextFrameId = requestAnimationFrame(frame);
37
+ }
38
+ else {
39
+ nextFrameId = null;
40
+ }
41
+ }
42
+ frame();
43
+ return (_) => {
44
+ if (nextFrameId != null)
45
+ cancelAnimationFrame(nextFrameId);
46
+ };
47
+ }
48
+ }
49
+ export function FadeIn(props) {
50
+ const { start, duration, delay, ...end } = props;
51
+ return new FadeInImpl(end, start, duration ?? 200, delay ?? 0);
52
+ }
@@ -0,0 +1,16 @@
1
+ import { Clear } from "../clean";
2
+ import { DOMContext } from "../dom-context";
3
+ import { Renderable } from "../renderable";
4
+ import { Animatable } from "./animatable";
5
+ export declare class FadeOutImpl implements Renderable {
6
+ private readonly end;
7
+ private readonly duration;
8
+ private readonly delay;
9
+ constructor(end: Animatable, duration: number, delay: number);
10
+ appendTo(ctx: DOMContext): Clear;
11
+ }
12
+ export interface FadeOutProps extends Animatable {
13
+ duration?: number;
14
+ delay?: number;
15
+ }
16
+ export declare function FadeOut(props: FadeOutProps): Renderable;
@@ -0,0 +1,39 @@
1
+ import { getComputedAnimatable, applyInterpolatedAnimatable } from "./animatable";
2
+ export class FadeOutImpl {
3
+ end;
4
+ duration;
5
+ delay;
6
+ constructor(end, duration, delay) {
7
+ this.end = end;
8
+ this.duration = duration;
9
+ this.delay = delay;
10
+ }
11
+ appendTo(ctx) {
12
+ const el = ctx.getElement();
13
+ const { duration, end } = this;
14
+ return ctx.delayClear((removeTree, clear) => {
15
+ const start = getComputedAnimatable(el, this.end);
16
+ const startTime = Date.now() + this.delay;
17
+ function frame() {
18
+ const now = Date.now();
19
+ if (now < startTime) {
20
+ requestAnimationFrame(frame);
21
+ return;
22
+ }
23
+ const progress = Math.min((now - startTime) / duration, 1);
24
+ applyInterpolatedAnimatable(el, start, end, progress);
25
+ if (progress < 1) {
26
+ requestAnimationFrame(frame);
27
+ }
28
+ else {
29
+ clear();
30
+ }
31
+ }
32
+ requestAnimationFrame(frame);
33
+ });
34
+ }
35
+ }
36
+ export function FadeOut(props) {
37
+ const { duration, delay, ...end } = props;
38
+ return new FadeOutImpl(end, duration ?? 200, delay ?? 0);
39
+ }
@@ -0,0 +1,7 @@
1
+ import { type Signal } from '../prop';
2
+ import { type JSX } from '../jsx-runtime';
3
+ export interface ForProps<T> {
4
+ of: Signal<T[]>;
5
+ children?: (value: Signal<T>, index: number) => JSX.DOMNode;
6
+ }
7
+ export declare function For<T>({ of, children: render }: ForProps<T>): JSX.DOMNode;
@@ -0,0 +1,15 @@
1
+ import { RepeatImpl } from './Repeat';
2
+ import { makeRenderable } from '../jsx-runtime';
3
+ import { FragmentImpl } from './Fragment';
4
+ import { OnRemoveImpl } from './OnRemove';
5
+ // <For of={values}>{(value) => <span>{value}</span>}</For>
6
+ export function For({ of, children: render }) {
7
+ const times = of.map(v => v.length);
8
+ return new RepeatImpl(times, (index) => {
9
+ const value = of.at(index);
10
+ return new FragmentImpl([
11
+ makeRenderable(render?.(value, index)),
12
+ new OnRemoveImpl(value.clean)
13
+ ]);
14
+ });
15
+ }
@@ -0,0 +1,12 @@
1
+ import { type Renderable } from '../renderable';
2
+ import { type Clear } from '../clean';
3
+ import { type DOMContext } from '../dom-context';
4
+ import { type JSX } from '../jsx';
5
+ export declare class FragmentImpl implements Renderable {
6
+ private readonly children;
7
+ constructor(children: Renderable[]);
8
+ readonly appendTo: (ctx: DOMContext) => Clear;
9
+ }
10
+ export declare function Fragment({ children }: {
11
+ children: JSX.DOMNode;
12
+ }): Renderable;
@@ -0,0 +1,16 @@
1
+ import { makeRenderables } from '../jsx-runtime';
2
+ export class FragmentImpl {
3
+ children;
4
+ constructor(children) {
5
+ this.children = children;
6
+ }
7
+ appendTo = (ctx) => {
8
+ const clears = this.children.map(child => child.appendTo(ctx));
9
+ return (removeTree) => {
10
+ clears.forEach(clear => { clear(removeTree); });
11
+ };
12
+ };
13
+ }
14
+ export function Fragment({ children }) {
15
+ return new FragmentImpl(makeRenderables(children));
16
+ }
@@ -0,0 +1,7 @@
1
+ import { type Renderable } from '../renderable';
2
+ import { type DOMContext } from '../dom-context';
3
+ import { type Clear } from '../clean';
4
+ export declare class HiddenWhenEmptyImpl implements Renderable {
5
+ appendTo(ctx: DOMContext): Clear;
6
+ }
7
+ export declare function HiddenWhenEmpty(): HiddenWhenEmptyImpl;
@@ -0,0 +1,12 @@
1
+ export class HiddenWhenEmptyImpl {
2
+ appendTo(ctx) {
3
+ ctx.setStyle(':empty', 'display: none');
4
+ return (removeTree) => {
5
+ if (removeTree)
6
+ ctx.setStyle(':empty', null);
7
+ };
8
+ }
9
+ }
10
+ export function HiddenWhenEmpty() {
11
+ return new HiddenWhenEmptyImpl();
12
+ }
@@ -0,0 +1,14 @@
1
+ import { type JSX } from '../jsx';
2
+ import { type Signal } from '../prop';
3
+ export interface IfProps {
4
+ is: Signal<boolean>;
5
+ then?: JSX.DOMNode;
6
+ otherwise?: JSX.DOMNode;
7
+ }
8
+ export declare function If({ is, then, otherwise }: IfProps): JSX.DOMNode;
9
+ export interface WhenProps {
10
+ is: Signal<boolean>;
11
+ children?: JSX.DOMNode;
12
+ }
13
+ export declare function When({ is, children }: WhenProps): JSX.DOMNode;
14
+ export declare function Unless({ is, children }: WhenProps): JSX.DOMNode;
@@ -0,0 +1,19 @@
1
+ import { OneOfImpl } from './OneOf';
2
+ export function If({ is, then, otherwise }) {
3
+ return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
4
+ 1: () => then,
5
+ 2: () => otherwise
6
+ });
7
+ }
8
+ export function When({ is, children }) {
9
+ return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
10
+ 1: () => children,
11
+ 2: () => null
12
+ });
13
+ }
14
+ export function Unless({ is, children }) {
15
+ return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
16
+ 1: () => null,
17
+ 2: () => children
18
+ });
19
+ }
@@ -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 InnerHTMLImpl implements Renderable {
6
+ private readonly html;
7
+ constructor(html: Signal<string> | Signal<string | undefined>);
8
+ readonly appendTo: (ctx: DOMContext) => Clear;
9
+ }
10
+ export interface InnerHTMLProps {
11
+ html: Signal<string> | Signal<string | undefined>;
12
+ }
13
+ export declare function InnerHTML({ html }: InnerHTMLProps): InnerHTMLImpl;
@@ -0,0 +1,23 @@
1
+ export class InnerHTMLImpl {
2
+ html;
3
+ constructor(html) {
4
+ this.html = html;
5
+ }
6
+ appendTo = (ctx) => {
7
+ const el = ctx.getElement();
8
+ const previous = el.innerHTML;
9
+ el.innerHTML = this.html.get() ?? '';
10
+ const cancel = this.html.subscribe(value => {
11
+ el.innerHTML = value ?? '';
12
+ });
13
+ return (removeTree) => {
14
+ cancel();
15
+ if (removeTree) {
16
+ el.innerHTML = previous;
17
+ }
18
+ };
19
+ };
20
+ }
21
+ export function InnerHTML({ html }) {
22
+ return new InnerHTMLImpl(html);
23
+ }
@@ -0,0 +1,14 @@
1
+ import { type Clear } from '../clean';
2
+ import { type DOMContext } from '../dom-context';
3
+ import { type Renderable } from '../renderable';
4
+ export declare class LifecycleImpl implements Renderable {
5
+ private readonly onMount;
6
+ private readonly onUnmount;
7
+ constructor(onMount: (el: HTMLElement) => void, onUnmount: (el: HTMLElement) => void);
8
+ readonly appendTo: (ctx: DOMContext) => Clear;
9
+ }
10
+ export interface LifecycleProps {
11
+ onMount?: (el: HTMLElement) => void;
12
+ onUnmount?: (el: HTMLElement) => void;
13
+ }
14
+ export declare function Lifecycle({ onMount, onUnmount }: LifecycleProps): Renderable;
@@ -0,0 +1,18 @@
1
+ export class LifecycleImpl {
2
+ onMount;
3
+ onUnmount;
4
+ constructor(onMount, onUnmount) {
5
+ this.onMount = onMount;
6
+ this.onUnmount = onUnmount;
7
+ }
8
+ appendTo = (ctx) => {
9
+ this.onMount(ctx.getElement());
10
+ return () => {
11
+ this.onUnmount(ctx.getElement());
12
+ };
13
+ };
14
+ }
15
+ export function Lifecycle({ onMount, onUnmount }) {
16
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
17
+ return new LifecycleImpl(onMount ?? (() => { }), onUnmount ?? (() => { }));
18
+ }
@@ -0,0 +1,33 @@
1
+ import { type Signal } from '../prop';
2
+ import { type DOMContext } from '../dom-context';
3
+ import { type AnyKey } from './OneOf';
4
+ import { type JSX } from '../jsx-runtime';
5
+ import { type Clear } from '../clean';
6
+ export declare class MatchImpl<T extends {
7
+ [_ in K]: any;
8
+ }, K extends keyof T> {
9
+ private readonly on;
10
+ private readonly using;
11
+ private readonly matches;
12
+ constructor(on: Signal<T>, using: K, matches: {
13
+ [KIND in T[K]]: (_: Signal<T & {
14
+ [KK in K]: KIND extends T[KK] ? KIND : never;
15
+ }>) => JSX.DOMNode;
16
+ });
17
+ readonly appendTo: (ctx: DOMContext) => Clear;
18
+ }
19
+ export type MatchProps<T extends {
20
+ [_ in K]: AnyKey;
21
+ }, K extends keyof T> = {
22
+ on: Signal<T>;
23
+ using: K;
24
+ } & {
25
+ matches: {
26
+ [KIND in T[K]]: (_: Signal<T & {
27
+ [KK in K]: KIND extends T[KK] ? KIND : never;
28
+ }>) => JSX.DOMNode;
29
+ };
30
+ };
31
+ export declare function Match<T extends {
32
+ [_ in K]: AnyKey;
33
+ }, K extends keyof T>({ on, using, matches }: MatchProps<T, K>): JSX.DOMNode;
@@ -0,0 +1,44 @@
1
+ import { makeRenderable } from '../jsx-runtime';
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ export class MatchImpl {
4
+ on;
5
+ using;
6
+ matches;
7
+ constructor(on, using, matches) {
8
+ this.on = on;
9
+ this.using = using;
10
+ this.matches = matches;
11
+ }
12
+ appendTo = (ctx) => {
13
+ let newCtx = ctx.makeReference();
14
+ const value = this.on.get();
15
+ let key = value[this.using];
16
+ let derived = this.on.map(v => v);
17
+ let renderable = makeRenderable(this.matches[key](derived));
18
+ let clear = renderable.appendTo(newCtx);
19
+ const cancel = this.on.subscribe(newValue => {
20
+ const newKey = newValue[this.using];
21
+ if (newKey === key)
22
+ return;
23
+ newCtx.requestClear(true, () => {
24
+ clear(true);
25
+ derived.clean();
26
+ key = newKey;
27
+ derived = this.on.map(v => v);
28
+ newCtx = newCtx.makeReference();
29
+ renderable = makeRenderable(this.matches[key](derived));
30
+ clear = renderable.appendTo(newCtx);
31
+ });
32
+ });
33
+ return (removeTree) => {
34
+ newCtx.requestClear(removeTree, () => {
35
+ cancel();
36
+ derived.clean();
37
+ clear(removeTree);
38
+ });
39
+ };
40
+ };
41
+ }
42
+ export function Match({ on, using, matches }) {
43
+ return new MatchImpl(on, using, matches);
44
+ }
@@ -0,0 +1,10 @@
1
+ /** @jsxImportSource .. */
2
+ import { type Signal } from '../prop';
3
+ import { type AnyKey } from './OneOf';
4
+ import { type JSX } from '../jsx-runtime';
5
+ export interface NotEmptyProps<T> {
6
+ on: Signal<T>;
7
+ whenEmpty?: JSX.DOMNode;
8
+ display: JSX.DOMNode;
9
+ }
10
+ export declare function NotEmpty<T extends unknown[] | Record<AnyKey, unknown>>({ on, display, whenEmpty }: NotEmptyProps<T>): JSX.DOMNode;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "../jsx-runtime";
2
+ import { If } from './If';
3
+ function isEmpty(obj) {
4
+ return Object.keys(obj).length === 0;
5
+ }
6
+ // <NotEmpty on={maybevalue} whenEmpty={<span>nothing to show</span>}}>{value => value.toText()}</NotEmpty>
7
+ export function NotEmpty({ on, display, whenEmpty }) {
8
+ return (_jsx(If, { is: on.map((v) =>
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ Array.isArray(v) ? v.length > 0 : v != null && !isEmpty(v)), then: display, otherwise: whenEmpty }));
11
+ }
@@ -0,0 +1,15 @@
1
+ import { type Renderable } from '../renderable';
2
+ import { type Clear } from '../clean';
3
+ import { type DOMContext } from '../dom-context';
4
+ export type OnFn<T> = (value: T) => void;
5
+ export declare class OnImpl<T> implements Renderable {
6
+ private readonly name;
7
+ private readonly handler;
8
+ constructor(name: string, handler: OnFn<T>);
9
+ readonly appendTo: (ctx: DOMContext) => Clear;
10
+ }
11
+ export interface OnProps<T> {
12
+ name: string;
13
+ handler: OnFn<T>;
14
+ }
15
+ export declare function On<T>({ name, handler }: OnProps<T>): Renderable;
@@ -0,0 +1,14 @@
1
+ export class OnImpl {
2
+ name;
3
+ handler;
4
+ constructor(name, handler) {
5
+ this.name = name;
6
+ this.handler = handler;
7
+ }
8
+ appendTo = (ctx) => {
9
+ return ctx.createHandler(this.name, this.handler);
10
+ };
11
+ }
12
+ export function On({ name, handler }) {
13
+ return new OnImpl(name, handler);
14
+ }
@@ -0,0 +1,11 @@
1
+ import { type Clear } from '../clean';
2
+ import { type Renderable } from '../renderable';
3
+ export declare class OnRemoveImpl implements Renderable {
4
+ private readonly clear;
5
+ constructor(clear: Clear);
6
+ readonly appendTo: () => Clear;
7
+ }
8
+ export interface OnRemoveProps {
9
+ clear: Clear;
10
+ }
11
+ export declare function OnRemove(props: OnRemoveProps): OnRemoveImpl;
@@ -0,0 +1,14 @@
1
+ export class OnRemoveImpl {
2
+ clear;
3
+ constructor(clear) {
4
+ this.clear = clear;
5
+ }
6
+ appendTo = () => {
7
+ return (removeTree) => {
8
+ this.clear(removeTree);
9
+ };
10
+ };
11
+ }
12
+ export function OnRemove(props) {
13
+ return new OnRemoveImpl(props.clear);
14
+ }
@@ -0,0 +1,20 @@
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
+ import { type JSX } from '../jsx';
6
+ export type AnyKey = string | number | symbol;
7
+ export declare class OneOfImpl<T extends [AnyKey, unknown]> implements Renderable {
8
+ private readonly match;
9
+ private readonly cases;
10
+ constructor(match: Signal<T>, cases: {
11
+ [KK in T[0]]: (value: Signal<T[1]>) => JSX.DOMNode;
12
+ });
13
+ readonly appendTo: (ctx: DOMContext) => Clear;
14
+ }
15
+ export type OneOfProps<T extends [AnyKey, unknown]> = {
16
+ match: Signal<T>;
17
+ } & {
18
+ [KK in T[0]]: (value: Signal<T[1]>) => JSX.DOMNode;
19
+ };
20
+ export declare function OneOf<T extends [AnyKey, unknown]>(props: OneOfProps<T>): JSX.DOMNode;