@quenk/wml 2.13.11 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.d.ts +8 -8
- package/lib/cli.js +1 -3
- package/lib/cli.js.map +1 -1
- package/lib/cli.ts +48 -60
- package/lib/compile/codegen.d.ts +4 -9
- package/lib/compile/codegen.js +161 -367
- package/lib/compile/codegen.js.map +1 -1
- package/lib/compile/codegen.ts +643 -952
- package/lib/compile/index.d.ts +2 -2
- package/lib/compile/index.js +4 -4
- package/lib/compile/index.js.map +1 -1
- package/lib/compile/index.ts +14 -17
- package/lib/compile/transform.d.ts +1 -1
- package/lib/compile/transform.js +9 -11
- package/lib/compile/transform.js.map +1 -1
- package/lib/compile/transform.ts +136 -143
- package/lib/{dom.d.ts → dom/index.d.ts} +8 -2
- package/lib/{dom.js → dom/index.js} +84 -70
- package/lib/dom/index.js.map +1 -0
- package/lib/dom/index.ts +425 -0
- package/lib/dom/monitor.d.ts +33 -0
- package/lib/dom/monitor.js +60 -0
- package/lib/dom/monitor.js.map +1 -0
- package/lib/dom/monitor.ts +75 -0
- package/lib/index.d.ts +10 -95
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/lib/index.ts +57 -182
- package/lib/main.js +17 -17
- package/lib/main.js.map +1 -1
- package/lib/main.ts +38 -44
- package/lib/parse/ast.d.ts +2 -2
- package/lib/parse/ast.js +52 -53
- package/lib/parse/ast.js.map +1 -1
- package/lib/parse/ast.ts +396 -483
- package/lib/parse/generated.d.ts +3 -5
- package/lib/parse/generated.js +9504 -9264
- package/lib/parse/index.d.ts +2 -3
- package/lib/parse/index.js.map +1 -1
- package/lib/parse/index.ts +7 -9
- package/lib/parse/test.js +194 -192
- package/lib/parse/test.js.map +1 -1
- package/lib/parse/test.ts +294 -404
- package/lib/parse/wml.y +4 -0
- package/lib/tsconfig.json +19 -20
- package/lib/util.d.ts +10 -0
- package/lib/util.js +21 -0
- package/lib/util.js.map +1 -0
- package/lib/util.ts +39 -0
- package/lib/view/frame.d.ts +127 -0
- package/lib/view/frame.js +214 -0
- package/lib/view/frame.js.map +1 -0
- package/lib/view/frame.ts +295 -0
- package/lib/view/index.d.ts +58 -0
- package/lib/view/index.js +48 -0
- package/lib/view/index.js.map +1 -0
- package/lib/view/index.ts +98 -0
- package/package.json +3 -3
- package/lib/dom.js.map +0 -1
- package/lib/dom.ts +0 -479
package/lib/compile/index.d.ts
CHANGED
package/lib/compile/index.js
CHANGED
|
@@ -6,13 +6,13 @@ const record_1 = require("@quenk/noni/lib/data/record");
|
|
|
6
6
|
const parse_1 = require("../parse");
|
|
7
7
|
const codegen_1 = require("./codegen");
|
|
8
8
|
const defaultOptions = {
|
|
9
|
-
module:
|
|
10
|
-
dom:
|
|
11
|
-
EOL: os.EOL
|
|
9
|
+
module: "@quenk/wml",
|
|
10
|
+
dom: "@quenk/wml/lib/dom",
|
|
11
|
+
EOL: os.EOL,
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* compile a string of WML text directly into typescript.
|
|
15
15
|
*/
|
|
16
|
-
const compile = (src, opts = {}) => (0, parse_1.parse)(src).map(m => codegen_1.CodeGenerator.create((0, record_1.merge)(defaultOptions, opts)).generate(m));
|
|
16
|
+
const compile = (src, opts = {}) => (0, parse_1.parse)(src).map((m) => codegen_1.CodeGenerator.create((0, record_1.merge)(defaultOptions, opts)).generate(m));
|
|
17
17
|
exports.compile = compile;
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
package/lib/compile/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,wDAAoD;AAGpD,oCAAiC;AACjC,uCAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,wDAAoD;AAGpD,oCAAiC;AACjC,uCAAgE;AAgBhE,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,YAAY;IAEpB,GAAG,EAAE,oBAAoB;IAEzB,GAAG,EAAE,EAAE,CAAC,GAAG;CACZ,CAAC;AAEF;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,OAAgB,EAAE,EAAkB,EAAE,CACzE,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACnB,uBAAa,CAAC,MAAM,CAAC,IAAA,cAAK,EAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC9D,CAAC;AAHS,QAAA,OAAO,WAGhB"}
|
package/lib/compile/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as os from
|
|
1
|
+
import * as os from "os";
|
|
2
2
|
|
|
3
|
-
import { merge } from
|
|
4
|
-
import { Except } from
|
|
3
|
+
import { merge } from "@quenk/noni/lib/data/record";
|
|
4
|
+
import { Except } from "@quenk/noni/lib/control/error";
|
|
5
5
|
|
|
6
|
-
import { parse } from
|
|
7
|
-
import { CodeGenerator, CodeGeneratorOptions } from
|
|
6
|
+
import { parse } from "../parse";
|
|
7
|
+
import { CodeGenerator, CodeGeneratorOptions } from "./codegen";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* TypeScript output.
|
|
@@ -15,26 +15,23 @@ export type TypeScript = string;
|
|
|
15
15
|
* Options for changing the behaviour of compilation.
|
|
16
16
|
*/
|
|
17
17
|
export interface Options extends Partial<CodeGeneratorOptions> {
|
|
18
|
+
debug?: boolean;
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
main?: string,
|
|
22
|
-
|
|
20
|
+
main?: string;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
const defaultOptions = {
|
|
24
|
+
module: "@quenk/wml",
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
dom: '@quenk/wml/lib/dom',
|
|
26
|
+
dom: "@quenk/wml/lib/dom",
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
28
|
+
EOL: os.EOL,
|
|
29
|
+
};
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* compile a string of WML text directly into typescript.
|
|
37
33
|
*/
|
|
38
34
|
export const compile = (src: string, opts: Options = {}): Except<string> =>
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
parse(src).map((m) =>
|
|
36
|
+
CodeGenerator.create(merge(defaultOptions, opts)).generate(m),
|
|
37
|
+
);
|
package/lib/compile/transform.js
CHANGED
|
@@ -22,11 +22,9 @@ const rewriteViewStatementContext = (tree, node) => {
|
|
|
22
22
|
else if (node.context instanceof ast.ContextFromStatement) {
|
|
23
23
|
let { context } = node;
|
|
24
24
|
let { location } = context;
|
|
25
|
-
tree.imports.push(new ast.ImportStatement(new ast.CompositeMember([
|
|
26
|
-
context.cons.id
|
|
27
|
-
], location), context.module, location));
|
|
25
|
+
tree.imports.push(new ast.ImportStatement(new ast.CompositeMember([context.cons.id], location), context.module, location));
|
|
28
26
|
return [
|
|
29
|
-
new ast.ViewStatement(node.id, node.typeParameters, context.cons, node.directives, node.root, node.location)
|
|
27
|
+
new ast.ViewStatement(node.id, node.typeParameters, context.cons, node.directives, node.root, node.location),
|
|
30
28
|
];
|
|
31
29
|
}
|
|
32
30
|
else {
|
|
@@ -34,7 +32,7 @@ const rewriteViewStatementContext = (tree, node) => {
|
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
34
|
exports.rewriteViewStatementContext = rewriteViewStatementContext;
|
|
37
|
-
exports.TAG_NAME_SVG =
|
|
35
|
+
exports.TAG_NAME_SVG = "svg";
|
|
38
36
|
/**
|
|
39
37
|
* tagSVGNodes traverses the tree to detect any embedded svg.
|
|
40
38
|
*
|
|
@@ -49,9 +47,8 @@ const tagSVGNodes = (tag) => {
|
|
|
49
47
|
let [isSvg, stack] = pending.pop();
|
|
50
48
|
while (stack.length) {
|
|
51
49
|
let next = stack.pop();
|
|
52
|
-
if (
|
|
53
|
-
(
|
|
54
|
-
=== exports.TAG_NAME_SVG) &&
|
|
50
|
+
if (next instanceof ast.Node &&
|
|
51
|
+
(0, codegen_1.identifierOrConstructor2TS)(next.open) === exports.TAG_NAME_SVG &&
|
|
55
52
|
!isSvg) {
|
|
56
53
|
pending.push([true, [next]]);
|
|
57
54
|
break;
|
|
@@ -59,16 +56,17 @@ const tagSVGNodes = (tag) => {
|
|
|
59
56
|
let childrens = [];
|
|
60
57
|
if (next instanceof ast.Node) {
|
|
61
58
|
if (isSvg)
|
|
62
|
-
next.attributes.push(new ast.Attribute(new ast.UnqualifiedIdentifier(
|
|
59
|
+
next.attributes.push(new ast.Attribute(new ast.UnqualifiedIdentifier("wml", {}), new ast.UnqualifiedIdentifier("ns", {}), new ast.StringLiteral("svg", {}), {}));
|
|
63
60
|
childrens.push(next.children);
|
|
64
61
|
}
|
|
65
|
-
else if (
|
|
62
|
+
else if (next instanceof ast.Widget || next instanceof ast.ElseClause) {
|
|
66
63
|
childrens.push(next.children);
|
|
67
64
|
}
|
|
68
65
|
else if (next instanceof ast.ForOfStatement) {
|
|
69
66
|
childrens.push(next.body, next.otherwise);
|
|
70
67
|
}
|
|
71
|
-
else if (
|
|
68
|
+
else if (next instanceof ast.IfStatement ||
|
|
69
|
+
next instanceof ast.ElseIfClause) {
|
|
72
70
|
childrens.push(next.then);
|
|
73
71
|
if (next.elseClause)
|
|
74
72
|
childrens.push([next.elseClause]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["transform.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,uCAAuD;AAEvD;;;;;;GAMG;AACI,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["transform.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,uCAAuD;AAEvD;;;;;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E;QACb,IAAI,IAAI,YAAY,GAAG,CAAC,aAAa,EAAE,CAAC;YACtC,IAAI,CAAC,IAAI,GAAG,IAAA,mBAAW,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEnC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,IAAA,mCAA2B,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EACa,EAAE,CACjB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAjBW,QAAA,aAAa,iBAiBxB"}
|
package/lib/compile/transform.ts
CHANGED
|
@@ -1,163 +1,156 @@
|
|
|
1
|
-
import * as ast from
|
|
2
|
-
import { identifierOrConstructor2TS } from
|
|
1
|
+
import * as ast from "../parse/ast";
|
|
2
|
+
import { identifierOrConstructor2TS } from "./codegen";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* rewriteViewContext normalizes the various forms of the context declaration
|
|
6
6
|
* in a view statement.
|
|
7
7
|
*
|
|
8
|
-
* "where" clauses are turned into context declarations with id
|
|
8
|
+
* "where" clauses are turned into context declarations with id
|
|
9
9
|
* <view-type>Context, imports are included in the module's import list.
|
|
10
10
|
*/
|
|
11
|
-
export const rewriteViewStatementContext =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export const TAG_NAME_SVG = 'svg';
|
|
11
|
+
export const rewriteViewStatementContext = (
|
|
12
|
+
tree: ast.Module,
|
|
13
|
+
node: ast.ViewStatement,
|
|
14
|
+
): ast.Export[] => {
|
|
15
|
+
if (Array.isArray(node.context)) {
|
|
16
|
+
// TODO: Is this branch still needed?
|
|
17
|
+
|
|
18
|
+
let contextName = `${node.id.value}Context`;
|
|
19
|
+
|
|
20
|
+
let context = new ast.ContextStatement(
|
|
21
|
+
new ast.UnqualifiedIdentifier(contextName, node.id.location),
|
|
22
|
+
node.typeParameters,
|
|
23
|
+
node.context,
|
|
24
|
+
node.location,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
let consType = new ast.ConstructorType(
|
|
28
|
+
context.id,
|
|
29
|
+
context.typeParameters,
|
|
30
|
+
context.location,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
let view = new ast.ViewStatement(
|
|
34
|
+
node.id,
|
|
35
|
+
node.typeParameters,
|
|
36
|
+
consType,
|
|
37
|
+
node.directives,
|
|
38
|
+
node.root,
|
|
39
|
+
node.location,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return [context, view];
|
|
43
|
+
} else if (node.context instanceof ast.ContextFromStatement) {
|
|
44
|
+
let { context } = node;
|
|
45
|
+
|
|
46
|
+
let { location } = context;
|
|
47
|
+
|
|
48
|
+
tree.imports.push(
|
|
49
|
+
new ast.ImportStatement(
|
|
50
|
+
new ast.CompositeMember(
|
|
51
|
+
[<ast.UnqualifiedConstructor>context.cons.id],
|
|
52
|
+
location,
|
|
53
|
+
),
|
|
54
|
+
context.module,
|
|
55
|
+
location,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return [
|
|
60
|
+
new ast.ViewStatement(
|
|
61
|
+
node.id,
|
|
62
|
+
node.typeParameters,
|
|
63
|
+
context.cons,
|
|
64
|
+
node.directives,
|
|
65
|
+
node.root,
|
|
66
|
+
node.location,
|
|
67
|
+
),
|
|
68
|
+
];
|
|
69
|
+
} else {
|
|
70
|
+
return [node];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const TAG_NAME_SVG = "svg";
|
|
77
75
|
|
|
78
76
|
/**
|
|
79
77
|
* tagSVGNodes traverses the tree to detect any embedded svg.
|
|
80
78
|
*
|
|
81
|
-
* If an svg parent tag is found, it and all its children will receive a
|
|
79
|
+
* If an svg parent tag is found, it and all its children will receive a
|
|
82
80
|
* wml:ns=svg attribute. This will cause the runtime to use createElementNS()
|
|
83
|
-
* instead of createElement, allowing the svg document to be treated as SVG
|
|
81
|
+
* instead of createElement, allowing the svg document to be treated as SVG
|
|
84
82
|
* and not HTML DOM.
|
|
85
83
|
*/
|
|
86
|
-
export const tagSVGNodes =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return tag;
|
|
135
|
-
|
|
84
|
+
export const tagSVGNodes = (tag: ast.Tag) => {
|
|
85
|
+
let pending: [boolean, object[]][] = [[false, [tag]]];
|
|
86
|
+
|
|
87
|
+
while (pending.length) {
|
|
88
|
+
let [isSvg, stack] = <[boolean, object[]]>pending.pop();
|
|
89
|
+
|
|
90
|
+
while (stack.length) {
|
|
91
|
+
let next = stack.pop();
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
next instanceof ast.Node &&
|
|
95
|
+
identifierOrConstructor2TS(next.open) === TAG_NAME_SVG &&
|
|
96
|
+
!isSvg
|
|
97
|
+
) {
|
|
98
|
+
pending.push([true, [next]]);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let childrens = [];
|
|
103
|
+
if (next instanceof ast.Node) {
|
|
104
|
+
if (isSvg)
|
|
105
|
+
next.attributes.push(
|
|
106
|
+
new ast.Attribute(
|
|
107
|
+
new ast.UnqualifiedIdentifier("wml", {}),
|
|
108
|
+
new ast.UnqualifiedIdentifier("ns", {}),
|
|
109
|
+
new ast.StringLiteral("svg", {}),
|
|
110
|
+
{},
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
childrens.push(next.children);
|
|
115
|
+
} else if (next instanceof ast.Widget || next instanceof ast.ElseClause) {
|
|
116
|
+
childrens.push(next.children);
|
|
117
|
+
} else if (next instanceof ast.ForOfStatement) {
|
|
118
|
+
childrens.push(next.body, next.otherwise);
|
|
119
|
+
} else if (
|
|
120
|
+
next instanceof ast.IfStatement ||
|
|
121
|
+
next instanceof ast.ElseIfClause
|
|
122
|
+
) {
|
|
123
|
+
childrens.push(next.then);
|
|
124
|
+
if (next.elseClause) childrens.push([next.elseClause]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (let children of childrens)
|
|
128
|
+
for (let child of children) stack.push(child);
|
|
136
129
|
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return tag;
|
|
133
|
+
};
|
|
137
134
|
|
|
138
135
|
/**
|
|
139
|
-
* transformTree applies all the needed transforms to the AST before
|
|
136
|
+
* transformTree applies all the needed transforms to the AST before
|
|
140
137
|
* compilation.
|
|
141
138
|
*/
|
|
142
139
|
export const transformTree = (tree: ast.Module) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return newTree;
|
|
162
|
-
|
|
163
|
-
}
|
|
140
|
+
let newTree = tree.clone(); // Try not to modify what we don't own.
|
|
141
|
+
|
|
142
|
+
newTree.exports = tree.exports.reduce(
|
|
143
|
+
(prev, next) => {
|
|
144
|
+
if (next instanceof ast.ViewStatement) {
|
|
145
|
+
next.root = tagSVGNodes(next.root);
|
|
146
|
+
|
|
147
|
+
return [...prev, ...rewriteViewStatementContext(newTree, next)];
|
|
148
|
+
} else {
|
|
149
|
+
return [...prev, next];
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
<ast.Export[]>[],
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return newTree;
|
|
156
|
+
};
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* we can detect whether we are in a browser or elsewhere and adjust to
|
|
7
7
|
* suite.
|
|
8
8
|
*/
|
|
9
|
-
import { Record } from
|
|
10
|
-
import { Type } from
|
|
9
|
+
import { Record } from "@quenk/noni/lib/data/record";
|
|
10
|
+
import { Type } from "@quenk/noni/lib/data/type";
|
|
11
11
|
/**
|
|
12
12
|
* WMLDOMAttrs is a record of attributes bound for a WMLDOMElement.
|
|
13
13
|
*/
|
|
@@ -18,6 +18,11 @@ export interface WMLDOMAttrs extends Record<string | number | Function> {
|
|
|
18
18
|
* @private
|
|
19
19
|
*/
|
|
20
20
|
export declare class WMLNodeList implements NodeListOf<WMLDOMNode> {
|
|
21
|
+
entries(): ArrayIterator<[number, WMLDOMNode]>;
|
|
22
|
+
keys(): ArrayIterator<number>;
|
|
23
|
+
values(): ArrayIterator<WMLDOMNode>;
|
|
24
|
+
[Symbol.iterator](): ArrayIterator<WMLDOMNode>;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
21
26
|
[index: number]: WMLDOMNode;
|
|
22
27
|
length: number;
|
|
23
28
|
item(): WMLDOMNode;
|
|
@@ -65,6 +70,7 @@ export declare class WMLDOMNode implements Node {
|
|
|
65
70
|
parentNode: null;
|
|
66
71
|
previousSibling: null;
|
|
67
72
|
get textContent(): string;
|
|
73
|
+
[Symbol.dispose](): void;
|
|
68
74
|
addEventListener(): void;
|
|
69
75
|
dispatchEvent(): boolean;
|
|
70
76
|
removeEventListener(): void;
|