@playdrop/playdrop-cli 0.12.42 → 0.13.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.
Files changed (106) hide show
  1. package/config/client-meta.json +2 -2
  2. package/dist/apps/index.d.ts +2 -0
  3. package/dist/apps/index.js +2 -1
  4. package/dist/apps/loadCheck.d.ts +4 -1
  5. package/dist/apps/loadCheck.js +40 -10
  6. package/dist/apps/staticHtml.d.ts +28 -0
  7. package/dist/apps/staticHtml.js +343 -0
  8. package/dist/apps/validate.js +2 -1
  9. package/dist/commands/devServer.js +19 -0
  10. package/dist/commands/feedback.d.ts +2 -0
  11. package/dist/commands/feedback.js +44 -2
  12. package/dist/commands/upload.d.ts +24 -0
  13. package/dist/commands/upload.js +122 -4
  14. package/dist/commands/worker/instrument-evidence.js +1 -1
  15. package/dist/commands/worker/runtime.d.ts +14 -0
  16. package/dist/commands/worker/runtime.js +97 -8
  17. package/dist/commands/worker.d.ts +27 -2
  18. package/dist/commands/worker.js +688 -146
  19. package/dist/index.js +7 -0
  20. package/dist/listingPreflight.js +15 -4
  21. package/node_modules/@playdrop/api-client/dist/client.d.ts +5 -2
  22. package/node_modules/@playdrop/api-client/dist/client.d.ts.map +1 -1
  23. package/node_modules/@playdrop/api-client/dist/domains/agent-tasks.d.ts +3 -2
  24. package/node_modules/@playdrop/api-client/dist/domains/agent-tasks.d.ts.map +1 -1
  25. package/node_modules/@playdrop/api-client/dist/domains/agent-tasks.js +13 -2
  26. package/node_modules/@playdrop/api-client/dist/domains/apps.d.ts +2 -1
  27. package/node_modules/@playdrop/api-client/dist/domains/apps.d.ts.map +1 -1
  28. package/node_modules/@playdrop/api-client/dist/domains/me.d.ts +2 -1
  29. package/node_modules/@playdrop/api-client/dist/domains/me.d.ts.map +1 -1
  30. package/node_modules/@playdrop/api-client/dist/domains/me.js +11 -0
  31. package/node_modules/@playdrop/api-client/dist/index.d.ts +6 -3
  32. package/node_modules/@playdrop/api-client/dist/index.d.ts.map +1 -1
  33. package/node_modules/@playdrop/api-client/dist/index.js +14 -2
  34. package/node_modules/@playdrop/config/client-meta.json +2 -2
  35. package/node_modules/@playdrop/config/dist/src/constants.d.ts +1 -0
  36. package/node_modules/@playdrop/config/dist/src/constants.d.ts.map +1 -1
  37. package/node_modules/@playdrop/config/dist/src/constants.js +1 -0
  38. package/node_modules/@playdrop/config/dist/tsconfig.tsbuildinfo +1 -1
  39. package/node_modules/@playdrop/types/dist/api.d.ts +195 -4
  40. package/node_modules/@playdrop/types/dist/api.d.ts.map +1 -1
  41. package/node_modules/@playdrop/types/dist/api.js +25 -2
  42. package/node_modules/entities/decode-codepoint.d.ts +19 -0
  43. package/node_modules/entities/decode-codepoint.d.ts.map +1 -0
  44. package/node_modules/entities/decode-codepoint.js +77 -0
  45. package/node_modules/entities/decode-codepoint.js.map +1 -0
  46. package/node_modules/entities/decode.d.ts +209 -0
  47. package/node_modules/entities/decode.d.ts.map +1 -0
  48. package/node_modules/entities/decode.js +511 -0
  49. package/node_modules/entities/decode.js.map +1 -0
  50. package/node_modules/entities/encode.d.ts +22 -0
  51. package/node_modules/entities/encode.d.ts.map +1 -0
  52. package/node_modules/entities/encode.js +73 -0
  53. package/node_modules/entities/encode.js.map +1 -0
  54. package/node_modules/entities/escape.d.ts +43 -0
  55. package/node_modules/entities/escape.d.ts.map +1 -0
  56. package/node_modules/entities/escape.js +121 -0
  57. package/node_modules/entities/escape.js.map +1 -0
  58. package/node_modules/entities/generated/decode-data-html.d.ts +2 -0
  59. package/node_modules/entities/generated/decode-data-html.d.ts.map +1 -0
  60. package/node_modules/entities/generated/decode-data-html.js +10 -0
  61. package/node_modules/entities/generated/decode-data-html.js.map +1 -0
  62. package/node_modules/entities/generated/decode-data-xml.d.ts +2 -0
  63. package/node_modules/entities/generated/decode-data-xml.d.ts.map +1 -0
  64. package/node_modules/entities/generated/decode-data-xml.js +10 -0
  65. package/node_modules/entities/generated/decode-data-xml.js.map +1 -0
  66. package/node_modules/entities/generated/encode-html.d.ts +8 -0
  67. package/node_modules/entities/generated/encode-html.d.ts.map +1 -0
  68. package/node_modules/entities/generated/encode-html.js +13 -0
  69. package/node_modules/entities/generated/encode-html.js.map +1 -0
  70. package/node_modules/entities/index.d.ts +96 -0
  71. package/node_modules/entities/index.d.ts.map +1 -0
  72. package/node_modules/entities/index.js +131 -0
  73. package/node_modules/entities/index.js.map +1 -0
  74. package/node_modules/entities/package.json +3 -0
  75. package/node_modules/parse5/common/doctype.d.ts +4 -0
  76. package/node_modules/parse5/common/doctype.js +118 -0
  77. package/node_modules/parse5/common/error-codes.d.ts +67 -0
  78. package/node_modules/parse5/common/error-codes.js +66 -0
  79. package/node_modules/parse5/common/foreign-content.d.ts +9 -0
  80. package/node_modules/parse5/common/foreign-content.js +237 -0
  81. package/node_modules/parse5/common/html.d.ts +289 -0
  82. package/node_modules/parse5/common/html.js +528 -0
  83. package/node_modules/parse5/common/token.d.ts +84 -0
  84. package/node_modules/parse5/common/token.js +24 -0
  85. package/node_modules/parse5/common/unicode.d.ts +42 -0
  86. package/node_modules/parse5/common/unicode.js +70 -0
  87. package/node_modules/parse5/index.d.ts +71 -0
  88. package/node_modules/parse5/index.js +54 -0
  89. package/node_modules/parse5/package.json +1 -0
  90. package/node_modules/parse5/parser/formatting-element-list.d.ts +36 -0
  91. package/node_modules/parse5/parser/formatting-element-list.js +114 -0
  92. package/node_modules/parse5/parser/index.d.ts +221 -0
  93. package/node_modules/parse5/parser/index.js +3240 -0
  94. package/node_modules/parse5/parser/open-element-stack.d.ts +53 -0
  95. package/node_modules/parse5/parser/open-element-stack.js +328 -0
  96. package/node_modules/parse5/serializer/index.d.ts +60 -0
  97. package/node_modules/parse5/serializer/index.js +172 -0
  98. package/node_modules/parse5/tokenizer/index.d.ts +247 -0
  99. package/node_modules/parse5/tokenizer/index.js +2714 -0
  100. package/node_modules/parse5/tokenizer/preprocessor.d.ts +36 -0
  101. package/node_modules/parse5/tokenizer/preprocessor.js +200 -0
  102. package/node_modules/parse5/tree-adapters/default.d.ts +84 -0
  103. package/node_modules/parse5/tree-adapters/default.js +176 -0
  104. package/node_modules/parse5/tree-adapters/interface.d.ts +255 -0
  105. package/node_modules/parse5/tree-adapters/interface.js +2 -0
  106. package/package.json +7 -1
@@ -0,0 +1,36 @@
1
+ import { ERR, type ParserError, type ParserErrorHandler } from '../common/error-codes.js';
2
+ export declare class Preprocessor {
3
+ private handler;
4
+ html: string;
5
+ pos: number;
6
+ private lastGapPos;
7
+ private gapStack;
8
+ private skipNextNewLine;
9
+ lastChunkWritten: boolean;
10
+ endOfChunkHit: boolean;
11
+ bufferWaterline: number;
12
+ private isEol;
13
+ private lineStartPos;
14
+ droppedBufferSize: number;
15
+ line: number;
16
+ constructor(handler: {
17
+ onParseError?: ParserErrorHandler | null;
18
+ });
19
+ /** The column on the current line. If we just saw a gap (eg. a surrogate pair), return the index before. */
20
+ get col(): number;
21
+ get offset(): number;
22
+ getError(code: ERR, cpOffset: number): ParserError;
23
+ private lastErrOffset;
24
+ private _err;
25
+ private _addGap;
26
+ private _processSurrogate;
27
+ willDropParsedChunk(): boolean;
28
+ dropParsedChunk(): void;
29
+ write(chunk: string, isLastChunk: boolean): void;
30
+ insertHtmlAtCurrentPos(chunk: string): void;
31
+ startsWith(pattern: string, caseSensitive: boolean): boolean;
32
+ peek(offset: number): number;
33
+ advance(): number;
34
+ private _checkForProblematicCharacters;
35
+ retreat(count: number): void;
36
+ }
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Preprocessor = void 0;
4
+ const unicode_js_1 = require("../common/unicode.js");
5
+ const error_codes_js_1 = require("../common/error-codes.js");
6
+ //Const
7
+ const DEFAULT_BUFFER_WATERLINE = 1 << 16;
8
+ //Preprocessor
9
+ //NOTE: HTML input preprocessing
10
+ //(see: http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#preprocessing-the-input-stream)
11
+ class Preprocessor {
12
+ constructor(handler) {
13
+ this.handler = handler;
14
+ this.html = '';
15
+ this.pos = -1;
16
+ // NOTE: Initial `lastGapPos` is -2, to ensure `col` on initialisation is 0
17
+ this.lastGapPos = -2;
18
+ this.gapStack = [];
19
+ this.skipNextNewLine = false;
20
+ this.lastChunkWritten = false;
21
+ this.endOfChunkHit = false;
22
+ this.bufferWaterline = DEFAULT_BUFFER_WATERLINE;
23
+ this.isEol = false;
24
+ this.lineStartPos = 0;
25
+ this.droppedBufferSize = 0;
26
+ this.line = 1;
27
+ //NOTE: avoid reporting errors twice on advance/retreat
28
+ this.lastErrOffset = -1;
29
+ }
30
+ /** The column on the current line. If we just saw a gap (eg. a surrogate pair), return the index before. */
31
+ get col() {
32
+ return this.pos - this.lineStartPos + Number(this.lastGapPos !== this.pos);
33
+ }
34
+ get offset() {
35
+ return this.droppedBufferSize + this.pos;
36
+ }
37
+ getError(code, cpOffset) {
38
+ const { line, col, offset } = this;
39
+ const startCol = col + cpOffset;
40
+ const startOffset = offset + cpOffset;
41
+ return {
42
+ code,
43
+ startLine: line,
44
+ endLine: line,
45
+ startCol,
46
+ endCol: startCol,
47
+ startOffset,
48
+ endOffset: startOffset,
49
+ };
50
+ }
51
+ _err(code) {
52
+ if (this.handler.onParseError && this.lastErrOffset !== this.offset) {
53
+ this.lastErrOffset = this.offset;
54
+ this.handler.onParseError(this.getError(code, 0));
55
+ }
56
+ }
57
+ _addGap() {
58
+ this.gapStack.push(this.lastGapPos);
59
+ this.lastGapPos = this.pos;
60
+ }
61
+ _processSurrogate(cp) {
62
+ //NOTE: try to peek a surrogate pair
63
+ if (this.pos !== this.html.length - 1) {
64
+ const nextCp = this.html.charCodeAt(this.pos + 1);
65
+ if ((0, unicode_js_1.isSurrogatePair)(nextCp)) {
66
+ //NOTE: we have a surrogate pair. Peek pair character and recalculate code point.
67
+ this.pos++;
68
+ //NOTE: add a gap that should be avoided during retreat
69
+ this._addGap();
70
+ return (0, unicode_js_1.getSurrogatePairCodePoint)(cp, nextCp);
71
+ }
72
+ }
73
+ //NOTE: we are at the end of a chunk, therefore we can't infer the surrogate pair yet.
74
+ else if (!this.lastChunkWritten) {
75
+ this.endOfChunkHit = true;
76
+ return unicode_js_1.CODE_POINTS.EOF;
77
+ }
78
+ //NOTE: isolated surrogate
79
+ this._err(error_codes_js_1.ERR.surrogateInInputStream);
80
+ return cp;
81
+ }
82
+ willDropParsedChunk() {
83
+ return this.pos > this.bufferWaterline;
84
+ }
85
+ dropParsedChunk() {
86
+ if (this.willDropParsedChunk()) {
87
+ this.html = this.html.substring(this.pos);
88
+ this.lineStartPos -= this.pos;
89
+ this.droppedBufferSize += this.pos;
90
+ this.pos = 0;
91
+ this.lastGapPos = -2;
92
+ this.gapStack.length = 0;
93
+ }
94
+ }
95
+ write(chunk, isLastChunk) {
96
+ if (this.html.length > 0) {
97
+ this.html += chunk;
98
+ }
99
+ else {
100
+ this.html = chunk;
101
+ }
102
+ this.endOfChunkHit = false;
103
+ this.lastChunkWritten = isLastChunk;
104
+ }
105
+ insertHtmlAtCurrentPos(chunk) {
106
+ this.html = this.html.substring(0, this.pos + 1) + chunk + this.html.substring(this.pos + 1);
107
+ this.endOfChunkHit = false;
108
+ }
109
+ startsWith(pattern, caseSensitive) {
110
+ // Check if our buffer has enough characters
111
+ if (this.pos + pattern.length > this.html.length) {
112
+ this.endOfChunkHit = !this.lastChunkWritten;
113
+ return false;
114
+ }
115
+ if (caseSensitive) {
116
+ return this.html.startsWith(pattern, this.pos);
117
+ }
118
+ for (let i = 0; i < pattern.length; i++) {
119
+ const cp = this.html.charCodeAt(this.pos + i) | 0x20;
120
+ if (cp !== pattern.charCodeAt(i)) {
121
+ return false;
122
+ }
123
+ }
124
+ return true;
125
+ }
126
+ peek(offset) {
127
+ const pos = this.pos + offset;
128
+ if (pos >= this.html.length) {
129
+ this.endOfChunkHit = !this.lastChunkWritten;
130
+ return unicode_js_1.CODE_POINTS.EOF;
131
+ }
132
+ const code = this.html.charCodeAt(pos);
133
+ return code === unicode_js_1.CODE_POINTS.CARRIAGE_RETURN ? unicode_js_1.CODE_POINTS.LINE_FEED : code;
134
+ }
135
+ advance() {
136
+ this.pos++;
137
+ //NOTE: LF should be in the last column of the line
138
+ if (this.isEol) {
139
+ this.isEol = false;
140
+ this.line++;
141
+ this.lineStartPos = this.pos;
142
+ }
143
+ if (this.pos >= this.html.length) {
144
+ this.endOfChunkHit = !this.lastChunkWritten;
145
+ return unicode_js_1.CODE_POINTS.EOF;
146
+ }
147
+ let cp = this.html.charCodeAt(this.pos);
148
+ //NOTE: all U+000D CARRIAGE RETURN (CR) characters must be converted to U+000A LINE FEED (LF) characters
149
+ if (cp === unicode_js_1.CODE_POINTS.CARRIAGE_RETURN) {
150
+ this.isEol = true;
151
+ this.skipNextNewLine = true;
152
+ return unicode_js_1.CODE_POINTS.LINE_FEED;
153
+ }
154
+ //NOTE: any U+000A LINE FEED (LF) characters that immediately follow a U+000D CARRIAGE RETURN (CR) character
155
+ //must be ignored.
156
+ if (cp === unicode_js_1.CODE_POINTS.LINE_FEED) {
157
+ this.isEol = true;
158
+ if (this.skipNextNewLine) {
159
+ // `line` will be bumped again in the recursive call.
160
+ this.line--;
161
+ this.skipNextNewLine = false;
162
+ this._addGap();
163
+ return this.advance();
164
+ }
165
+ }
166
+ this.skipNextNewLine = false;
167
+ if ((0, unicode_js_1.isSurrogate)(cp)) {
168
+ cp = this._processSurrogate(cp);
169
+ }
170
+ //OPTIMIZATION: first check if code point is in the common allowed
171
+ //range (ASCII alphanumeric, whitespaces, big chunk of BMP)
172
+ //before going into detailed performance cost validation.
173
+ const isCommonValidRange = this.handler.onParseError === null ||
174
+ (cp > 0x1f && cp < 0x7f) ||
175
+ cp === unicode_js_1.CODE_POINTS.LINE_FEED ||
176
+ cp === unicode_js_1.CODE_POINTS.CARRIAGE_RETURN ||
177
+ (cp > 0x9f && cp < 64976);
178
+ if (!isCommonValidRange) {
179
+ this._checkForProblematicCharacters(cp);
180
+ }
181
+ return cp;
182
+ }
183
+ _checkForProblematicCharacters(cp) {
184
+ if ((0, unicode_js_1.isControlCodePoint)(cp)) {
185
+ this._err(error_codes_js_1.ERR.controlCharacterInInputStream);
186
+ }
187
+ else if ((0, unicode_js_1.isUndefinedCodePoint)(cp)) {
188
+ this._err(error_codes_js_1.ERR.noncharacterInInputStream);
189
+ }
190
+ }
191
+ retreat(count) {
192
+ this.pos -= count;
193
+ while (this.pos < this.lastGapPos) {
194
+ this.lastGapPos = this.gapStack.pop();
195
+ this.pos--;
196
+ }
197
+ this.isEol = false;
198
+ }
199
+ }
200
+ exports.Preprocessor = Preprocessor;
@@ -0,0 +1,84 @@
1
+ import { DOCUMENT_MODE, type NS } from '../common/html.js';
2
+ import type { Attribute, Location, ElementLocation } from '../common/token.js';
3
+ import type { TreeAdapter, TreeAdapterTypeMap } from './interface.js';
4
+ export interface Document {
5
+ /** The name of the node. */
6
+ nodeName: '#document';
7
+ /**
8
+ * Document mode.
9
+ *
10
+ * @see {@link DOCUMENT_MODE} */
11
+ mode: DOCUMENT_MODE;
12
+ /** The node's children. */
13
+ childNodes: ChildNode[];
14
+ /** Comment source code location info. Available if location info is enabled. */
15
+ sourceCodeLocation?: Location | null;
16
+ }
17
+ export interface DocumentFragment {
18
+ /** The name of the node. */
19
+ nodeName: '#document-fragment';
20
+ /** The node's children. */
21
+ childNodes: ChildNode[];
22
+ /** Comment source code location info. Available if location info is enabled. */
23
+ sourceCodeLocation?: Location | null;
24
+ }
25
+ export interface Element {
26
+ /** Element tag name. Same as {@link tagName}. */
27
+ nodeName: string;
28
+ /** Element tag name. Same as {@link nodeName}. */
29
+ tagName: string;
30
+ /** List of element attributes. */
31
+ attrs: Attribute[];
32
+ /** Element namespace. */
33
+ namespaceURI: NS;
34
+ /** Element source code location info, with attributes. Available if location info is enabled. */
35
+ sourceCodeLocation?: ElementLocation | null;
36
+ /** Parent node. */
37
+ parentNode: ParentNode | null;
38
+ /** The node's children. */
39
+ childNodes: ChildNode[];
40
+ }
41
+ export interface CommentNode {
42
+ /** The name of the node. */
43
+ nodeName: '#comment';
44
+ /** Parent node. */
45
+ parentNode: ParentNode | null;
46
+ /** Comment text. */
47
+ data: string;
48
+ /** Comment source code location info. Available if location info is enabled. */
49
+ sourceCodeLocation?: Location | null;
50
+ }
51
+ export interface TextNode {
52
+ nodeName: '#text';
53
+ /** Parent node. */
54
+ parentNode: ParentNode | null;
55
+ /** Text content. */
56
+ value: string;
57
+ /** Comment source code location info. Available if location info is enabled. */
58
+ sourceCodeLocation?: Location | null;
59
+ }
60
+ export interface Template extends Element {
61
+ nodeName: 'template';
62
+ tagName: 'template';
63
+ /** The content of a `template` tag. */
64
+ content: DocumentFragment;
65
+ }
66
+ export interface DocumentType {
67
+ /** The name of the node. */
68
+ nodeName: '#documentType';
69
+ /** Parent node. */
70
+ parentNode: ParentNode | null;
71
+ /** Document type name. */
72
+ name: string;
73
+ /** Document type public identifier. */
74
+ publicId: string;
75
+ /** Document type system identifier. */
76
+ systemId: string;
77
+ /** Comment source code location info. Available if location info is enabled. */
78
+ sourceCodeLocation?: Location | null;
79
+ }
80
+ export type ParentNode = Document | DocumentFragment | Element | Template;
81
+ export type ChildNode = Element | Template | CommentNode | TextNode | DocumentType;
82
+ export type Node = ParentNode | ChildNode;
83
+ export type DefaultTreeAdapterMap = TreeAdapterTypeMap<Node, ParentNode, ChildNode, Document, DocumentFragment, Element, CommentNode, TextNode, Template, DocumentType>;
84
+ export declare const defaultTreeAdapter: TreeAdapter<DefaultTreeAdapterMap>;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultTreeAdapter = void 0;
4
+ const html_js_1 = require("../common/html.js");
5
+ exports.defaultTreeAdapter = {
6
+ //Node construction
7
+ createDocument() {
8
+ return {
9
+ nodeName: '#document',
10
+ mode: html_js_1.DOCUMENT_MODE.NO_QUIRKS,
11
+ childNodes: [],
12
+ };
13
+ },
14
+ createDocumentFragment() {
15
+ return {
16
+ nodeName: '#document-fragment',
17
+ childNodes: [],
18
+ };
19
+ },
20
+ createElement(tagName, namespaceURI, attrs) {
21
+ return {
22
+ nodeName: tagName,
23
+ tagName,
24
+ attrs,
25
+ namespaceURI,
26
+ childNodes: [],
27
+ parentNode: null,
28
+ };
29
+ },
30
+ createCommentNode(data) {
31
+ return {
32
+ nodeName: '#comment',
33
+ data,
34
+ parentNode: null,
35
+ };
36
+ },
37
+ createTextNode(value) {
38
+ return {
39
+ nodeName: '#text',
40
+ value,
41
+ parentNode: null,
42
+ };
43
+ },
44
+ //Tree mutation
45
+ appendChild(parentNode, newNode) {
46
+ parentNode.childNodes.push(newNode);
47
+ newNode.parentNode = parentNode;
48
+ },
49
+ insertBefore(parentNode, newNode, referenceNode) {
50
+ const insertionIdx = parentNode.childNodes.indexOf(referenceNode);
51
+ parentNode.childNodes.splice(insertionIdx, 0, newNode);
52
+ newNode.parentNode = parentNode;
53
+ },
54
+ setTemplateContent(templateElement, contentElement) {
55
+ templateElement.content = contentElement;
56
+ },
57
+ getTemplateContent(templateElement) {
58
+ return templateElement.content;
59
+ },
60
+ setDocumentType(document, name, publicId, systemId) {
61
+ const doctypeNode = document.childNodes.find((node) => node.nodeName === '#documentType');
62
+ if (doctypeNode) {
63
+ doctypeNode.name = name;
64
+ doctypeNode.publicId = publicId;
65
+ doctypeNode.systemId = systemId;
66
+ }
67
+ else {
68
+ const node = {
69
+ nodeName: '#documentType',
70
+ name,
71
+ publicId,
72
+ systemId,
73
+ parentNode: null,
74
+ };
75
+ exports.defaultTreeAdapter.appendChild(document, node);
76
+ }
77
+ },
78
+ setDocumentMode(document, mode) {
79
+ document.mode = mode;
80
+ },
81
+ getDocumentMode(document) {
82
+ return document.mode;
83
+ },
84
+ detachNode(node) {
85
+ if (node.parentNode) {
86
+ const idx = node.parentNode.childNodes.indexOf(node);
87
+ node.parentNode.childNodes.splice(idx, 1);
88
+ node.parentNode = null;
89
+ }
90
+ },
91
+ insertText(parentNode, text) {
92
+ if (parentNode.childNodes.length > 0) {
93
+ const prevNode = parentNode.childNodes[parentNode.childNodes.length - 1];
94
+ if (exports.defaultTreeAdapter.isTextNode(prevNode)) {
95
+ prevNode.value += text;
96
+ return;
97
+ }
98
+ }
99
+ exports.defaultTreeAdapter.appendChild(parentNode, exports.defaultTreeAdapter.createTextNode(text));
100
+ },
101
+ insertTextBefore(parentNode, text, referenceNode) {
102
+ const prevNode = parentNode.childNodes[parentNode.childNodes.indexOf(referenceNode) - 1];
103
+ if (prevNode && exports.defaultTreeAdapter.isTextNode(prevNode)) {
104
+ prevNode.value += text;
105
+ }
106
+ else {
107
+ exports.defaultTreeAdapter.insertBefore(parentNode, exports.defaultTreeAdapter.createTextNode(text), referenceNode);
108
+ }
109
+ },
110
+ adoptAttributes(recipient, attrs) {
111
+ const recipientAttrsMap = new Set(recipient.attrs.map((attr) => attr.name));
112
+ for (let j = 0; j < attrs.length; j++) {
113
+ if (!recipientAttrsMap.has(attrs[j].name)) {
114
+ recipient.attrs.push(attrs[j]);
115
+ }
116
+ }
117
+ },
118
+ //Tree traversing
119
+ getFirstChild(node) {
120
+ return node.childNodes[0];
121
+ },
122
+ getChildNodes(node) {
123
+ return node.childNodes;
124
+ },
125
+ getParentNode(node) {
126
+ return node.parentNode;
127
+ },
128
+ getAttrList(element) {
129
+ return element.attrs;
130
+ },
131
+ //Node data
132
+ getTagName(element) {
133
+ return element.tagName;
134
+ },
135
+ getNamespaceURI(element) {
136
+ return element.namespaceURI;
137
+ },
138
+ getTextNodeContent(textNode) {
139
+ return textNode.value;
140
+ },
141
+ getCommentNodeContent(commentNode) {
142
+ return commentNode.data;
143
+ },
144
+ getDocumentTypeNodeName(doctypeNode) {
145
+ return doctypeNode.name;
146
+ },
147
+ getDocumentTypeNodePublicId(doctypeNode) {
148
+ return doctypeNode.publicId;
149
+ },
150
+ getDocumentTypeNodeSystemId(doctypeNode) {
151
+ return doctypeNode.systemId;
152
+ },
153
+ //Node types
154
+ isTextNode(node) {
155
+ return node.nodeName === '#text';
156
+ },
157
+ isCommentNode(node) {
158
+ return node.nodeName === '#comment';
159
+ },
160
+ isDocumentTypeNode(node) {
161
+ return node.nodeName === '#documentType';
162
+ },
163
+ isElementNode(node) {
164
+ return Object.prototype.hasOwnProperty.call(node, 'tagName');
165
+ },
166
+ // Source code location
167
+ setNodeSourceCodeLocation(node, location) {
168
+ node.sourceCodeLocation = location;
169
+ },
170
+ getNodeSourceCodeLocation(node) {
171
+ return node.sourceCodeLocation;
172
+ },
173
+ updateNodeSourceCodeLocation(node, endLocation) {
174
+ node.sourceCodeLocation = Object.assign(Object.assign({}, node.sourceCodeLocation), endLocation);
175
+ },
176
+ };