maquette 3.5.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cache.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { CalculationCache } from "./interfaces";
2
- /**
3
- * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
4
- * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
5
- * For more information, see [[CalculationCache]].
6
- *
7
- * @param <Result> The type of the value that is cached.
8
- */
9
- export declare let createCache: <Result>() => CalculationCache<Result>;
1
+ import { CalculationCache } from "./interfaces";
2
+ /**
3
+ * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
4
+ * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
5
+ * For more information, see [[CalculationCache]].
6
+ *
7
+ * @param <Result> The type of the value that is cached.
8
+ */
9
+ export declare let createCache: <Result>() => CalculationCache<Result>;
package/dist/cache.js CHANGED
@@ -1,32 +1,32 @@
1
- /**
2
- * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
3
- * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
4
- * For more information, see [[CalculationCache]].
5
- *
6
- * @param <Result> The type of the value that is cached.
7
- */
8
- export var createCache = function () {
9
- var cachedInputs;
10
- var cachedOutcome;
11
- return {
12
- invalidate: function () {
13
- cachedOutcome = undefined;
14
- cachedInputs = undefined;
15
- },
16
- result: function (inputs, calculation) {
17
- if (cachedInputs) {
18
- for (var i = 0; i < inputs.length; i++) {
19
- if (cachedInputs[i] !== inputs[i]) {
20
- cachedOutcome = undefined;
21
- }
22
- }
23
- }
24
- if (!cachedOutcome) {
25
- cachedOutcome = calculation();
26
- cachedInputs = inputs;
27
- }
28
- return cachedOutcome;
29
- },
30
- };
31
- };
1
+ /**
2
+ * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
3
+ * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
4
+ * For more information, see [[CalculationCache]].
5
+ *
6
+ * @param <Result> The type of the value that is cached.
7
+ */
8
+ export var createCache = function () {
9
+ var cachedInputs;
10
+ var cachedOutcome;
11
+ return {
12
+ invalidate: function () {
13
+ cachedOutcome = undefined;
14
+ cachedInputs = undefined;
15
+ },
16
+ result: function (inputs, calculation) {
17
+ if (cachedInputs) {
18
+ for (var i = 0; i < inputs.length; i++) {
19
+ if (cachedInputs[i] !== inputs[i]) {
20
+ cachedOutcome = undefined;
21
+ }
22
+ }
23
+ }
24
+ if (!cachedOutcome) {
25
+ cachedOutcome = calculation();
26
+ cachedInputs = inputs;
27
+ }
28
+ return cachedOutcome;
29
+ },
30
+ };
31
+ };
32
32
  //# sourceMappingURL=cache.js.map
package/dist/cache.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,IAAI,WAAW,GAAG;IACvB,IAAI,YAAmC,CAAC;IACxC,IAAI,aAAiC,CAAC;IAEtC,OAAO;QACL,UAAU,EAAE;YACV,aAAa,GAAG,SAAS,CAAC;YAC1B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,MAAM,EAAE,UAAC,MAAiB,EAAE,WAAyB;YACnD,IAAI,YAAY,EAAE;gBAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBACtC,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE;wBACjC,aAAa,GAAG,SAAS,CAAC;qBAC3B;iBACF;aACF;YACD,IAAI,CAAC,aAAa,EAAE;gBAClB,aAAa,GAAG,WAAW,EAAE,CAAC;gBAC9B,YAAY,GAAG,MAAM,CAAC;aACvB;YACD,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { CalculationCache } from \"./interfaces\";\n\n/**\n * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.\n * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.\n * For more information, see [[CalculationCache]].\n *\n * @param <Result> The type of the value that is cached.\n */\nexport let createCache = <Result>(): CalculationCache<Result> => {\n let cachedInputs: unknown[] | undefined;\n let cachedOutcome: Result | undefined;\n\n return {\n invalidate: () => {\n cachedOutcome = undefined;\n cachedInputs = undefined;\n },\n\n result: (inputs: unknown[], calculation: () => Result) => {\n if (cachedInputs) {\n for (let i = 0; i < inputs.length; i++) {\n if (cachedInputs[i] !== inputs[i]) {\n cachedOutcome = undefined;\n }\n }\n }\n if (!cachedOutcome) {\n cachedOutcome = calculation();\n cachedInputs = inputs;\n }\n return cachedOutcome;\n },\n };\n};\n"]}
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,IAAI,WAAW,GAAG;IACvB,IAAI,YAAmC,CAAC;IACxC,IAAI,aAAiC,CAAC;IAEtC,OAAO;QACL,UAAU,EAAE;YACV,aAAa,GAAG,SAAS,CAAC;YAC1B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,MAAM,EAAE,UAAC,MAAiB,EAAE,WAAyB;YACnD,IAAI,YAAY,EAAE,CAAC;gBACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBACvC,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;wBAClC,aAAa,GAAG,SAAS,CAAC;oBAC5B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,aAAa,GAAG,WAAW,EAAE,CAAC;gBAC9B,YAAY,GAAG,MAAM,CAAC;YACxB,CAAC;YACD,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { CalculationCache } from \"./interfaces\";\n\n/**\n * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.\n * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.\n * For more information, see [[CalculationCache]].\n *\n * @param <Result> The type of the value that is cached.\n */\nexport let createCache = <Result,>(): CalculationCache<Result> => {\n let cachedInputs: unknown[] | undefined;\n let cachedOutcome: Result | undefined;\n\n return {\n invalidate: () => {\n cachedOutcome = undefined;\n cachedInputs = undefined;\n },\n\n result: (inputs: unknown[], calculation: () => Result) => {\n if (cachedInputs) {\n for (let i = 0; i < inputs.length; i++) {\n if (cachedInputs[i] !== inputs[i]) {\n cachedOutcome = undefined;\n }\n }\n }\n if (!cachedOutcome) {\n cachedOutcome = calculation();\n cachedInputs = inputs;\n }\n return cachedOutcome;\n },\n };\n};\n"]}
package/dist/dom.d.ts CHANGED
@@ -1,59 +1,59 @@
1
- /**
2
- * Contains simple low-level utility functions to manipulate the real DOM.
3
- */
4
- import { Projection, ProjectionOptions, VNode } from "./interfaces";
5
- export declare let applyDefaultProjectionOptions: (projectorOptions?: ProjectionOptions) => ProjectionOptions;
6
- export declare let dom: {
7
- /**
8
- * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
9
- * its [[Projection.domNode|domNode]] property.
10
- * This is a low-level method. Users will typically use a [[Projector]] instead.
11
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
12
- * objects may only be rendered once.
13
- * @param projectionOptions - Options to be used to create and update the projection.
14
- * @returns The [[Projection]] which also contains the DOM Node that was created.
15
- */
16
- create: (vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
17
- /**
18
- * Appends a new child node to the DOM which is generated from a [[VNode]].
19
- * This is a low-level method. Users will typically use a [[Projector]] instead.
20
- * @param parentNode - The parent node for the new child node.
21
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
22
- * objects may only be rendered once.
23
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
24
- * @returns The [[Projection]] that was created.
25
- */
26
- append: (parentNode: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
27
- /**
28
- * Inserts a new DOM node which is generated from a [[VNode]].
29
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
30
- * @param beforeNode - The node that the DOM Node is inserted before.
31
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
32
- * NOTE: [[VNode]] objects may only be rendered once.
33
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
34
- * @returns The [[Projection]] that was created.
35
- */
36
- insertBefore: (beforeNode: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
37
- /**
38
- * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
39
- * This means that the virtual DOM and the real DOM will have one overlapping element.
40
- * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
41
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
42
- * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
43
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
44
- * may only be rendered once.
45
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
46
- * @returns The [[Projection]] that was created.
47
- */
48
- merge: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
49
- /**
50
- * Replaces an existing DOM node with a node generated from a [[VNode]].
51
- * This is a low-level method. Users will typically use a [[Projector]] instead.
52
- * @param element - The node for the [[VNode]] to replace.
53
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
54
- * objects may only be rendered once.
55
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
56
- * @returns The [[Projection]] that was created.
57
- */
58
- replace: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
59
- };
1
+ /**
2
+ * Contains simple low-level utility functions to manipulate the real DOM.
3
+ */
4
+ import { Projection, ProjectionOptions, VNode } from "./interfaces";
5
+ export declare let applyDefaultProjectionOptions: (projectorOptions?: ProjectionOptions) => ProjectionOptions;
6
+ export declare let dom: {
7
+ /**
8
+ * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
9
+ * its [[Projection.domNode|domNode]] property.
10
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
11
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
12
+ * objects may only be rendered once.
13
+ * @param projectionOptions - Options to be used to create and update the projection.
14
+ * @returns The [[Projection]] which also contains the DOM Node that was created.
15
+ */
16
+ create: (vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
17
+ /**
18
+ * Appends a new child node to the DOM which is generated from a [[VNode]].
19
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
20
+ * @param parentNode - The parent node for the new child node.
21
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
22
+ * objects may only be rendered once.
23
+ * @param projectionOptions - Options to be used to create and update the [[Projection]].
24
+ * @returns The [[Projection]] that was created.
25
+ */
26
+ append: (parentNode: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
27
+ /**
28
+ * Inserts a new DOM node which is generated from a [[VNode]].
29
+ * This is a low-level method. Users wil typically use a [[Projector]] instead.
30
+ * @param beforeNode - The node that the DOM Node is inserted before.
31
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
32
+ * NOTE: [[VNode]] objects may only be rendered once.
33
+ * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
34
+ * @returns The [[Projection]] that was created.
35
+ */
36
+ insertBefore: (beforeNode: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
37
+ /**
38
+ * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
39
+ * This means that the virtual DOM and the real DOM will have one overlapping element.
40
+ * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
41
+ * This is a low-level method. Users wil typically use a [[Projector]] instead.
42
+ * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
43
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
44
+ * may only be rendered once.
45
+ * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
46
+ * @returns The [[Projection]] that was created.
47
+ */
48
+ merge: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
49
+ /**
50
+ * Replaces an existing DOM node with a node generated from a [[VNode]].
51
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
52
+ * @param element - The node for the [[VNode]] to replace.
53
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
54
+ * objects may only be rendered once.
55
+ * @param projectionOptions - Options to be used to create and update the [[Projection]].
56
+ * @returns The [[Projection]] that was created.
57
+ */
58
+ replace: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions) => Projection;
59
+ };
package/dist/dom.js CHANGED
@@ -1,96 +1,96 @@
1
- import { createDom, createProjection, extend, initPropertiesAndChildren } from "./projection";
2
- var DEFAULT_PROJECTION_OPTIONS = {
3
- namespace: undefined,
4
- performanceLogger: function () { return undefined; },
5
- eventHandlerInterceptor: undefined,
6
- styleApplyer: function (domNode, styleName, value) {
7
- if (styleName.charAt(0) === "-") {
8
- // CSS variables must be set using setProperty
9
- domNode.style.setProperty(styleName, value);
10
- }
11
- else {
12
- // properties like 'backgroundColor' must be set as a js-property
13
- domNode.style[styleName] = value;
14
- }
15
- },
16
- };
17
- export var applyDefaultProjectionOptions = function (projectorOptions) {
18
- return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
19
- };
20
- export var dom = {
21
- /**
22
- * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
23
- * its [[Projection.domNode|domNode]] property.
24
- * This is a low-level method. Users will typically use a [[Projector]] instead.
25
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
26
- * objects may only be rendered once.
27
- * @param projectionOptions - Options to be used to create and update the projection.
28
- * @returns The [[Projection]] which also contains the DOM Node that was created.
29
- */
30
- create: function (vnode, projectionOptions) {
31
- projectionOptions = applyDefaultProjectionOptions(projectionOptions);
32
- createDom(vnode, document.createElement("div"), undefined, projectionOptions);
33
- return createProjection(vnode, projectionOptions);
34
- },
35
- /**
36
- * Appends a new child node to the DOM which is generated from a [[VNode]].
37
- * This is a low-level method. Users will typically use a [[Projector]] instead.
38
- * @param parentNode - The parent node for the new child node.
39
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
40
- * objects may only be rendered once.
41
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
42
- * @returns The [[Projection]] that was created.
43
- */
44
- append: function (parentNode, vnode, projectionOptions) {
45
- projectionOptions = applyDefaultProjectionOptions(projectionOptions);
46
- createDom(vnode, parentNode, undefined, projectionOptions);
47
- return createProjection(vnode, projectionOptions);
48
- },
49
- /**
50
- * Inserts a new DOM node which is generated from a [[VNode]].
51
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
52
- * @param beforeNode - The node that the DOM Node is inserted before.
53
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
54
- * NOTE: [[VNode]] objects may only be rendered once.
55
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
56
- * @returns The [[Projection]] that was created.
57
- */
58
- insertBefore: function (beforeNode, vnode, projectionOptions) {
59
- projectionOptions = applyDefaultProjectionOptions(projectionOptions);
60
- createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
61
- return createProjection(vnode, projectionOptions);
62
- },
63
- /**
64
- * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
65
- * This means that the virtual DOM and the real DOM will have one overlapping element.
66
- * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
67
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
68
- * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
69
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
70
- * may only be rendered once.
71
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
72
- * @returns The [[Projection]] that was created.
73
- */
74
- merge: function (element, vnode, projectionOptions) {
75
- projectionOptions = applyDefaultProjectionOptions(projectionOptions);
76
- vnode.domNode = element;
77
- initPropertiesAndChildren(element, vnode, projectionOptions);
78
- return createProjection(vnode, projectionOptions);
79
- },
80
- /**
81
- * Replaces an existing DOM node with a node generated from a [[VNode]].
82
- * This is a low-level method. Users will typically use a [[Projector]] instead.
83
- * @param element - The node for the [[VNode]] to replace.
84
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
85
- * objects may only be rendered once.
86
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
87
- * @returns The [[Projection]] that was created.
88
- */
89
- replace: function (element, vnode, projectionOptions) {
90
- projectionOptions = applyDefaultProjectionOptions(projectionOptions);
91
- createDom(vnode, element.parentNode, element, projectionOptions);
92
- element.parentNode.removeChild(element);
93
- return createProjection(vnode, projectionOptions);
94
- },
95
- };
1
+ import { createDom, createProjection, extend, initPropertiesAndChildren } from "./projection";
2
+ var DEFAULT_PROJECTION_OPTIONS = {
3
+ namespace: undefined,
4
+ performanceLogger: function () { return undefined; },
5
+ eventHandlerInterceptor: undefined,
6
+ styleApplyer: function (domNode, styleName, value) {
7
+ if (styleName.charAt(0) === "-") {
8
+ // CSS variables must be set using setProperty
9
+ domNode.style.setProperty(styleName, value);
10
+ }
11
+ else {
12
+ // properties like 'backgroundColor' must be set as a js-property
13
+ domNode.style[styleName] = value;
14
+ }
15
+ },
16
+ };
17
+ export var applyDefaultProjectionOptions = function (projectorOptions) {
18
+ return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
19
+ };
20
+ export var dom = {
21
+ /**
22
+ * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
23
+ * its [[Projection.domNode|domNode]] property.
24
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
25
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
26
+ * objects may only be rendered once.
27
+ * @param projectionOptions - Options to be used to create and update the projection.
28
+ * @returns The [[Projection]] which also contains the DOM Node that was created.
29
+ */
30
+ create: function (vnode, projectionOptions) {
31
+ projectionOptions = applyDefaultProjectionOptions(projectionOptions);
32
+ createDom(vnode, document.createElement("div"), undefined, projectionOptions);
33
+ return createProjection(vnode, projectionOptions);
34
+ },
35
+ /**
36
+ * Appends a new child node to the DOM which is generated from a [[VNode]].
37
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
38
+ * @param parentNode - The parent node for the new child node.
39
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
40
+ * objects may only be rendered once.
41
+ * @param projectionOptions - Options to be used to create and update the [[Projection]].
42
+ * @returns The [[Projection]] that was created.
43
+ */
44
+ append: function (parentNode, vnode, projectionOptions) {
45
+ projectionOptions = applyDefaultProjectionOptions(projectionOptions);
46
+ createDom(vnode, parentNode, undefined, projectionOptions);
47
+ return createProjection(vnode, projectionOptions);
48
+ },
49
+ /**
50
+ * Inserts a new DOM node which is generated from a [[VNode]].
51
+ * This is a low-level method. Users wil typically use a [[Projector]] instead.
52
+ * @param beforeNode - The node that the DOM Node is inserted before.
53
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
54
+ * NOTE: [[VNode]] objects may only be rendered once.
55
+ * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
56
+ * @returns The [[Projection]] that was created.
57
+ */
58
+ insertBefore: function (beforeNode, vnode, projectionOptions) {
59
+ projectionOptions = applyDefaultProjectionOptions(projectionOptions);
60
+ createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
61
+ return createProjection(vnode, projectionOptions);
62
+ },
63
+ /**
64
+ * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
65
+ * This means that the virtual DOM and the real DOM will have one overlapping element.
66
+ * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
67
+ * This is a low-level method. Users wil typically use a [[Projector]] instead.
68
+ * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
69
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
70
+ * may only be rendered once.
71
+ * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
72
+ * @returns The [[Projection]] that was created.
73
+ */
74
+ merge: function (element, vnode, projectionOptions) {
75
+ projectionOptions = applyDefaultProjectionOptions(projectionOptions);
76
+ vnode.domNode = element;
77
+ initPropertiesAndChildren(element, vnode, projectionOptions);
78
+ return createProjection(vnode, projectionOptions);
79
+ },
80
+ /**
81
+ * Replaces an existing DOM node with a node generated from a [[VNode]].
82
+ * This is a low-level method. Users will typically use a [[Projector]] instead.
83
+ * @param element - The node for the [[VNode]] to replace.
84
+ * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
85
+ * objects may only be rendered once.
86
+ * @param projectionOptions - Options to be used to create and update the [[Projection]].
87
+ * @returns The [[Projection]] that was created.
88
+ */
89
+ replace: function (element, vnode, projectionOptions) {
90
+ projectionOptions = applyDefaultProjectionOptions(projectionOptions);
91
+ createDom(vnode, element.parentNode, element, projectionOptions);
92
+ element.parentNode.removeChild(element);
93
+ return createProjection(vnode, projectionOptions);
94
+ },
95
+ };
96
96
  //# sourceMappingURL=dom.js.map
package/dist/dom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9F,IAAM,0BAA0B,GAAsB;IACpD,SAAS,EAAE,SAAS;IACpB,iBAAiB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;IAClC,uBAAuB,EAAE,SAAS;IAClC,YAAY,EAAE,UAAC,OAAoB,EAAE,SAAiB,EAAE,KAAa;QACnE,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YAC/B,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC7C;aAAM;YACL,iEAAiE;YAChE,OAAO,CAAC,KAAa,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;SAC3C;IACH,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,IAAI,6BAA6B,GAAG,UACzC,gBAAoC;IAEpC,OAAO,MAAM,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,CAAC,IAAI,GAAG,GAAG;IACf;;;;;;;;OAQG;IACH,MAAM,EAAE,UAAC,KAAY,EAAE,iBAAqC;QAC1D,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;QAC9E,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,EAAE,UACN,UAAmB,EACnB,KAAY,EACZ,iBAAqC;QAErC,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;QAC3D,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,EAAE,UACZ,UAAmB,EACnB,KAAY,EACZ,iBAAqC;QAErC,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,UAAW,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;QACxE,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,EAAE,UAAC,OAAgB,EAAE,KAAY,EAAE,iBAAqC;QAC3E,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QACxB,yBAAyB,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QAC7D,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,EAAE,UAAC,OAAgB,EAAE,KAAY,EAAE,iBAAqC;QAC7E,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,UAAW,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAClE,OAAO,CAAC,UAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;CACF,CAAC","sourcesContent":["/**\n * Contains simple low-level utility functions to manipulate the real DOM.\n */\nimport { Projection, ProjectionOptions, VNode } from \"./interfaces\";\nimport { createDom, createProjection, extend, initPropertiesAndChildren } from \"./projection\";\n\nconst DEFAULT_PROJECTION_OPTIONS: ProjectionOptions = {\n namespace: undefined,\n performanceLogger: () => undefined,\n eventHandlerInterceptor: undefined,\n styleApplyer: (domNode: HTMLElement, styleName: string, value: string) => {\n if (styleName.charAt(0) === \"-\") {\n // CSS variables must be set using setProperty\n domNode.style.setProperty(styleName, value);\n } else {\n // properties like 'backgroundColor' must be set as a js-property\n (domNode.style as any)[styleName] = value;\n }\n },\n};\n\nexport let applyDefaultProjectionOptions = (\n projectorOptions?: ProjectionOptions\n): ProjectionOptions => {\n return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);\n};\n\nexport let dom = {\n /**\n * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in\n * its [[Projection.domNode|domNode]] property.\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection.\n * @returns The [[Projection]] which also contains the DOM Node that was created.\n */\n create: (vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, document.createElement(\"div\"), undefined, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Appends a new child node to the DOM which is generated from a [[VNode]].\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param parentNode - The parent node for the new child node.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the [[Projection]].\n * @returns The [[Projection]] that was created.\n */\n append: (\n parentNode: Element,\n vnode: VNode,\n projectionOptions?: ProjectionOptions\n ): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, parentNode, undefined, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Inserts a new DOM node which is generated from a [[VNode]].\n * This is a low-level method. Users wil typically use a [[Projector]] instead.\n * @param beforeNode - The node that the DOM Node is inserted before.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.\n * NOTE: [[VNode]] objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].\n * @returns The [[Projection]] that was created.\n */\n insertBefore: (\n beforeNode: Element,\n vnode: VNode,\n projectionOptions?: ProjectionOptions\n ): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, beforeNode.parentNode!, beforeNode, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.\n * This means that the virtual DOM and the real DOM will have one overlapping element.\n * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.\n * This is a low-level method. Users wil typically use a [[Projector]] instead.\n * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects\n * may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].\n * @returns The [[Projection]] that was created.\n */\n merge: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n vnode.domNode = element;\n initPropertiesAndChildren(element, vnode, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Replaces an existing DOM node with a node generated from a [[VNode]].\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param element - The node for the [[VNode]] to replace.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the [[Projection]].\n * @returns The [[Projection]] that was created.\n */\n replace: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, element.parentNode!, element, projectionOptions);\n element.parentNode!.removeChild(element);\n return createProjection(vnode, projectionOptions);\n },\n};\n"]}
1
+ {"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9F,IAAM,0BAA0B,GAAsB;IACpD,SAAS,EAAE,SAAS;IACpB,iBAAiB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;IAClC,uBAAuB,EAAE,SAAS;IAClC,YAAY,EAAE,UAAC,OAAoB,EAAE,SAAiB,EAAE,KAAa;QACnE,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAChC,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,iEAAiE;YAChE,OAAO,CAAC,KAAa,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QAC5C,CAAC;IACH,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,IAAI,6BAA6B,GAAG,UACzC,gBAAoC;IAEpC,OAAO,MAAM,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,CAAC,IAAI,GAAG,GAAG;IACf;;;;;;;;OAQG;IACH,MAAM,EAAE,UAAC,KAAY,EAAE,iBAAqC;QAC1D,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;QAC9E,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,EAAE,UACN,UAAmB,EACnB,KAAY,EACZ,iBAAqC;QAErC,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;QAC3D,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,EAAE,UACZ,UAAmB,EACnB,KAAY,EACZ,iBAAqC;QAErC,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,UAAW,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;QACxE,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,EAAE,UAAC,OAAgB,EAAE,KAAY,EAAE,iBAAqC;QAC3E,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QACxB,yBAAyB,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QAC7D,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,EAAE,UAAC,OAAgB,EAAE,KAAY,EAAE,iBAAqC;QAC7E,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QACrE,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,UAAW,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAClE,OAAO,CAAC,UAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;CACF,CAAC","sourcesContent":["/**\n * Contains simple low-level utility functions to manipulate the real DOM.\n */\nimport { Projection, ProjectionOptions, VNode } from \"./interfaces\";\nimport { createDom, createProjection, extend, initPropertiesAndChildren } from \"./projection\";\n\nconst DEFAULT_PROJECTION_OPTIONS: ProjectionOptions = {\n namespace: undefined,\n performanceLogger: () => undefined,\n eventHandlerInterceptor: undefined,\n styleApplyer: (domNode: HTMLElement, styleName: string, value: string) => {\n if (styleName.charAt(0) === \"-\") {\n // CSS variables must be set using setProperty\n domNode.style.setProperty(styleName, value);\n } else {\n // properties like 'backgroundColor' must be set as a js-property\n (domNode.style as any)[styleName] = value;\n }\n },\n};\n\nexport let applyDefaultProjectionOptions = (\n projectorOptions?: ProjectionOptions\n): ProjectionOptions => {\n return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);\n};\n\nexport let dom = {\n /**\n * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in\n * its [[Projection.domNode|domNode]] property.\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection.\n * @returns The [[Projection]] which also contains the DOM Node that was created.\n */\n create: (vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, document.createElement(\"div\"), undefined, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Appends a new child node to the DOM which is generated from a [[VNode]].\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param parentNode - The parent node for the new child node.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the [[Projection]].\n * @returns The [[Projection]] that was created.\n */\n append: (\n parentNode: Element,\n vnode: VNode,\n projectionOptions?: ProjectionOptions\n ): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, parentNode, undefined, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Inserts a new DOM node which is generated from a [[VNode]].\n * This is a low-level method. Users wil typically use a [[Projector]] instead.\n * @param beforeNode - The node that the DOM Node is inserted before.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.\n * NOTE: [[VNode]] objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].\n * @returns The [[Projection]] that was created.\n */\n insertBefore: (\n beforeNode: Element,\n vnode: VNode,\n projectionOptions?: ProjectionOptions\n ): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, beforeNode.parentNode!, beforeNode, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.\n * This means that the virtual DOM and the real DOM will have one overlapping element.\n * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.\n * This is a low-level method. Users wil typically use a [[Projector]] instead.\n * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects\n * may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].\n * @returns The [[Projection]] that was created.\n */\n merge: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n vnode.domNode = element;\n initPropertiesAndChildren(element, vnode, projectionOptions);\n return createProjection(vnode, projectionOptions);\n },\n\n /**\n * Replaces an existing DOM node with a node generated from a [[VNode]].\n * This is a low-level method. Users will typically use a [[Projector]] instead.\n * @param element - The node for the [[VNode]] to replace.\n * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]\n * objects may only be rendered once.\n * @param projectionOptions - Options to be used to create and update the [[Projection]].\n * @returns The [[Projection]] that was created.\n */\n replace: (element: Element, vnode: VNode, projectionOptions?: ProjectionOptions): Projection => {\n projectionOptions = applyDefaultProjectionOptions(projectionOptions);\n createDom(vnode, element.parentNode!, element, projectionOptions);\n element.parentNode!.removeChild(element);\n return createProjection(vnode, projectionOptions);\n },\n};\n"]}
package/dist/h.d.ts CHANGED
@@ -1,34 +1,34 @@
1
- import { VNode, VNodeChild, VNodeProperties } from "./interfaces";
2
- /**
3
- * The `h` function is used to create a virtual DOM node.
4
- * This function is largely inspired by the mercuryjs and mithril frameworks.
5
- * The `h` stands for (virtual) hyperscript.
6
- *
7
- * @param selector Contains the tagName, id and fixed css classnames in CSS selector format.
8
- * It is formatted as follows: `tagname.cssclass1.cssclass2#id`.
9
- * @param properties An object literal containing properties that will be placed on the DOM node.
10
- * @param children Virtual DOM nodes and strings to add as child nodes.
11
- * `children` may contain [[VNode]]s, `string`s, nested arrays, `null` and `undefined`.
12
- * Nested arrays are flattened, `null` and `undefined` are removed.
13
- *
14
- * @returns A VNode object, used to render a real DOM later.
15
- *
16
- * NOTE: There are {@link http://maquettejs.org/docs/rules.html|two basic rules} you should be aware of when updating the virtual DOM.
17
- */
18
- export declare function h(selector: string, properties?: VNodeProperties, children?: VNodeChild[] | null): VNode;
19
- /**
20
- * The `h` function is used to create a virtual DOM node.
21
- * This function is largely inspired by the mercuryjs and mithril frameworks.
22
- * The `h` stands for (virtual) hyperscript.
23
- *
24
- * @param selector Contains the tagName, id and fixed css classnames in CSS selector format.
25
- * It is formatted as follows: `tagname.cssclass1.cssclass2#id`.
26
- * @param children Virtual DOM nodes and strings to add as child nodes.
27
- * `children` may contain [[VNode]]s, `string`s, nested arrays, `null` and `undefined`.
28
- * Nested arrays are flattened, `null` and `undefined` are removed.
29
- *
30
- * @returns A VNode object, used to render a real DOM later.
31
- *
32
- * NOTE: There are {@link http://maquettejs.org/docs/rules.html|two basic rules} you should be aware of when updating the virtual DOM.
33
- */
34
- export declare function h(selector: string, children: VNodeChild[]): VNode;
1
+ import { VNode, VNodeChild, VNodeProperties } from "./interfaces";
2
+ /**
3
+ * The `h` function is used to create a virtual DOM node.
4
+ * This function is largely inspired by the mercuryjs and mithril frameworks.
5
+ * The `h` stands for (virtual) hyperscript.
6
+ *
7
+ * @param selector Contains the tagName, id and fixed css classnames in CSS selector format.
8
+ * It is formatted as follows: `tagname.cssclass1.cssclass2#id`.
9
+ * @param properties An object literal containing properties that will be placed on the DOM node.
10
+ * @param children Virtual DOM nodes and strings to add as child nodes.
11
+ * `children` may contain [[VNode]]s, `string`s, nested arrays, `null` and `undefined`.
12
+ * Nested arrays are flattened, `null` and `undefined` are removed.
13
+ *
14
+ * @returns A VNode object, used to render a real DOM later.
15
+ *
16
+ * NOTE: There are {@link http://maquettejs.org/docs/rules.html two basic rules} you should be aware of when updating the virtual DOM.
17
+ */
18
+ export declare function h(selector: string, properties?: VNodeProperties, children?: VNodeChild[] | null): VNode;
19
+ /**
20
+ * The `h` function is used to create a virtual DOM node.
21
+ * This function is largely inspired by the mercuryjs and mithril frameworks.
22
+ * The `h` stands for (virtual) hyperscript.
23
+ *
24
+ * @param selector Contains the tagName, id and fixed css classnames in CSS selector format.
25
+ * It is formatted as follows: `tagname.cssclass1.cssclass2#id`.
26
+ * @param children Virtual DOM nodes and strings to add as child nodes.
27
+ * `children` may contain [[VNode]]s, `string`s, nested arrays, `null` and `undefined`.
28
+ * Nested arrays are flattened, `null` and `undefined` are removed.
29
+ *
30
+ * @returns A VNode object, used to render a real DOM later.
31
+ *
32
+ * NOTE: There are {@link http://maquettejs.org/docs/rules.html two basic rules} you should be aware of when updating the virtual DOM.
33
+ */
34
+ export declare function h(selector: string, children: VNodeChild[]): VNode;
package/dist/h.js CHANGED
@@ -1,56 +1,56 @@
1
- var toTextVNode = function (data) {
2
- return {
3
- vnodeSelector: "",
4
- properties: undefined,
5
- children: undefined,
6
- text: data.toString(),
7
- domNode: null,
8
- };
9
- };
10
- var appendChildren = function (parentSelector, insertions, main) {
11
- for (var i = 0, length_1 = insertions.length; i < length_1; i++) {
12
- var item = insertions[i];
13
- if (Array.isArray(item)) {
14
- appendChildren(parentSelector, item, main);
15
- }
16
- else {
17
- if (item !== null && item !== undefined && item !== false) {
18
- if (typeof item === "string") {
19
- item = toTextVNode(item);
20
- }
21
- main.push(item);
22
- }
23
- }
24
- }
25
- };
26
- export function h(selector, properties, children) {
27
- if (Array.isArray(properties)) {
28
- children = properties;
29
- properties = undefined;
30
- }
31
- else if ((properties && (typeof properties === "string" || properties.vnodeSelector)) ||
32
- (children && (typeof children === "string" || children.vnodeSelector))) {
33
- throw new Error("h called with invalid arguments");
34
- }
35
- var text;
36
- var flattenedChildren;
37
- // Recognize a common special case where there is only a single text node
38
- if (children && children.length === 1 && typeof children[0] === "string") {
39
- text = children[0];
40
- }
41
- else if (children) {
42
- flattenedChildren = [];
43
- appendChildren(selector, children, flattenedChildren);
44
- if (flattenedChildren.length === 0) {
45
- flattenedChildren = undefined;
46
- }
47
- }
48
- return {
49
- vnodeSelector: selector,
50
- properties: properties,
51
- children: flattenedChildren,
52
- text: text === "" ? undefined : text,
53
- domNode: null,
54
- };
55
- }
1
+ var toTextVNode = function (data) {
2
+ return {
3
+ vnodeSelector: "",
4
+ properties: undefined,
5
+ children: undefined,
6
+ text: data.toString(),
7
+ domNode: null,
8
+ };
9
+ };
10
+ var appendChildren = function (parentSelector, insertions, main) {
11
+ for (var i = 0, length_1 = insertions.length; i < length_1; i++) {
12
+ var item = insertions[i];
13
+ if (Array.isArray(item)) {
14
+ appendChildren(parentSelector, item, main);
15
+ }
16
+ else {
17
+ if (item !== null && item !== undefined && item !== false) {
18
+ if (typeof item === "string") {
19
+ item = toTextVNode(item);
20
+ }
21
+ main.push(item);
22
+ }
23
+ }
24
+ }
25
+ };
26
+ export function h(selector, properties, children) {
27
+ if (Array.isArray(properties)) {
28
+ children = properties;
29
+ properties = undefined;
30
+ }
31
+ else if ((properties && (typeof properties === "string" || properties.vnodeSelector)) ||
32
+ (children && (typeof children === "string" || children.vnodeSelector))) {
33
+ throw new Error("h called with invalid arguments");
34
+ }
35
+ var text;
36
+ var flattenedChildren;
37
+ // Recognize a common special case where there is only a single text node
38
+ if (children && children.length === 1 && typeof children[0] === "string") {
39
+ text = children[0];
40
+ }
41
+ else if (children) {
42
+ flattenedChildren = [];
43
+ appendChildren(selector, children, flattenedChildren);
44
+ if (flattenedChildren.length === 0) {
45
+ flattenedChildren = undefined;
46
+ }
47
+ }
48
+ return {
49
+ vnodeSelector: selector,
50
+ properties: properties,
51
+ children: flattenedChildren,
52
+ text: text === "" ? undefined : text,
53
+ domNode: null,
54
+ };
55
+ }
56
56
  //# sourceMappingURL=h.js.map