defuddle-cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +77 -0
- package/dist/commands/parse.d.ts +8 -0
- package/dist/commands/parse.js +66 -0
- package/dist/dom/interfaces/css.d.ts +38 -0
- package/dist/dom/interfaces/css.js +20 -0
- package/dist/dom/interfaces/document.d.ts +3 -0
- package/dist/dom/interfaces/document.js +49 -0
- package/dist/dom/interfaces/global.d.ts +21 -0
- package/dist/dom/interfaces/global.js +182 -0
- package/dist/dom/interfaces/html.d.ts +57 -0
- package/dist/dom/interfaces/html.js +3 -0
- package/dist/dom/interfaces/range.d.ts +2 -0
- package/dist/dom/interfaces/range.js +87 -0
- package/dist/dom/interfaces/setup.d.ts +12 -0
- package/dist/dom/interfaces/setup.js +182 -0
- package/dist/dom/interfaces/svg.d.ts +59 -0
- package/dist/dom/interfaces/svg.js +161 -0
- package/dist/dom/setup.d.ts +9 -0
- package/dist/dom/setup.js +660 -0
- package/dist/dom.d.ts +1 -0
- package/dist/dom.js +586 -0
- package/dist/index.js +84 -339
- package/dist/markdown.js +0 -8
- package/package.json +1 -1
- package/src/dom/interfaces/document.ts +53 -0
- package/src/dom/interfaces/range.ts +120 -0
- package/src/dom/interfaces/setup.ts +196 -0
- package/src/index.ts +91 -366
- package/src/markdown.ts +0 -11
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
2
|
+
import { setupDOMInterfaces } from './interfaces/setup.js';
|
|
3
|
+
import { setupRange } from './interfaces/range.js';
|
|
4
|
+
import { setupDocumentMethods, setupWindowMethods } from './interfaces/document.js';
|
|
5
|
+
// Create a virtual console
|
|
6
|
+
const virtualConsole = new VirtualConsole();
|
|
7
|
+
// Create a virtual DOM
|
|
8
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
|
|
9
|
+
virtualConsole,
|
|
10
|
+
runScripts: 'dangerously',
|
|
11
|
+
resources: 'usable',
|
|
12
|
+
pretendToBeVisual: true,
|
|
13
|
+
beforeParse(window) {
|
|
14
|
+
setupDOMInterfaces(window);
|
|
15
|
+
setupRange(window);
|
|
16
|
+
setupDocumentMethods(window);
|
|
17
|
+
setupWindowMethods(window);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
// Get the window object
|
|
21
|
+
const window = dom.window;
|
|
22
|
+
// Add window to global scope
|
|
23
|
+
globalThis.window = window;
|
|
24
|
+
// Add document to global scope
|
|
25
|
+
globalThis.document = window.document;
|
|
26
|
+
// Add required DOM interfaces to global scope
|
|
27
|
+
globalThis.Element = window.Element;
|
|
28
|
+
globalThis.Node = window.Node;
|
|
29
|
+
globalThis.NodeFilter = window.NodeFilter;
|
|
30
|
+
globalThis.Range = window.Range;
|
|
31
|
+
globalThis.DOMParser = window.DOMParser;
|
|
32
|
+
globalThis.XMLSerializer = window.XMLSerializer;
|
|
33
|
+
globalThis.navigator = window.navigator;
|
|
34
|
+
globalThis.HTMLElement = window.HTMLElement;
|
|
35
|
+
// Define CSS interfaces globally first
|
|
36
|
+
globalThis.CSSRule = class {
|
|
37
|
+
constructor(type) {
|
|
38
|
+
this.type = 1;
|
|
39
|
+
if (type !== undefined) {
|
|
40
|
+
Object.defineProperty(this, 'type', { value: type });
|
|
41
|
+
}
|
|
42
|
+
this.cssText = '';
|
|
43
|
+
this.parentRule = null;
|
|
44
|
+
this.parentStyleSheet = null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
// Static properties
|
|
48
|
+
Object.defineProperties(globalThis.CSSRule, {
|
|
49
|
+
STYLE_RULE: { value: 1, writable: false },
|
|
50
|
+
CHARSET_RULE: { value: 2, writable: false },
|
|
51
|
+
IMPORT_RULE: { value: 3, writable: false },
|
|
52
|
+
MEDIA_RULE: { value: 4, writable: false },
|
|
53
|
+
FONT_FACE_RULE: { value: 5, writable: false },
|
|
54
|
+
PAGE_RULE: { value: 6, writable: false },
|
|
55
|
+
KEYFRAMES_RULE: { value: 7, writable: false },
|
|
56
|
+
KEYFRAME_RULE: { value: 8, writable: false },
|
|
57
|
+
NAMESPACE_RULE: { value: 10, writable: false },
|
|
58
|
+
COUNTER_STYLE_RULE: { value: 11, writable: false },
|
|
59
|
+
SUPPORTS_RULE: { value: 12, writable: false },
|
|
60
|
+
DOCUMENT_RULE: { value: 13, writable: false },
|
|
61
|
+
FONT_FEATURE_VALUES_RULE: { value: 14, writable: false },
|
|
62
|
+
VIEWPORT_RULE: { value: 15, writable: false },
|
|
63
|
+
REGION_STYLE_RULE: { value: 16, writable: false }
|
|
64
|
+
});
|
|
65
|
+
globalThis.CSSMediaRule = class extends globalThis.CSSRule {
|
|
66
|
+
constructor() {
|
|
67
|
+
super();
|
|
68
|
+
this.conditionText = '';
|
|
69
|
+
this.deleteRule = () => { };
|
|
70
|
+
this.insertRule = () => 0;
|
|
71
|
+
Object.defineProperty(this, 'type', { value: 4 }); // CSSRule.MEDIA_RULE
|
|
72
|
+
this.media = {
|
|
73
|
+
length: 0,
|
|
74
|
+
mediaText: '',
|
|
75
|
+
item: () => null,
|
|
76
|
+
appendMedium: () => { },
|
|
77
|
+
deleteMedium: () => { },
|
|
78
|
+
toString: () => '',
|
|
79
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
80
|
+
};
|
|
81
|
+
this.cssRules = {
|
|
82
|
+
length: 0,
|
|
83
|
+
item: () => null,
|
|
84
|
+
[Symbol.iterator]: function* () {
|
|
85
|
+
yield new globalThis.CSSRule();
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
globalThis.CSSStyleSheet = class {
|
|
92
|
+
constructor() {
|
|
93
|
+
this.type = 'text/css';
|
|
94
|
+
this.href = null;
|
|
95
|
+
this.ownerNode = null;
|
|
96
|
+
this.parentStyleSheet = null;
|
|
97
|
+
this.title = null;
|
|
98
|
+
this.disabled = false;
|
|
99
|
+
this.ownerRule = null;
|
|
100
|
+
this.addRule = () => 0;
|
|
101
|
+
this.removeRule = () => { };
|
|
102
|
+
this.replace = async () => this;
|
|
103
|
+
this.replaceSync = () => { };
|
|
104
|
+
this.media = {
|
|
105
|
+
length: 0,
|
|
106
|
+
mediaText: '',
|
|
107
|
+
item: () => null,
|
|
108
|
+
appendMedium: () => { },
|
|
109
|
+
deleteMedium: () => { },
|
|
110
|
+
toString: () => '',
|
|
111
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
112
|
+
};
|
|
113
|
+
this.cssRules = {
|
|
114
|
+
length: 0,
|
|
115
|
+
item: () => null,
|
|
116
|
+
[Symbol.iterator]: function* () {
|
|
117
|
+
yield new globalThis.CSSRule();
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
this.rules = this.cssRules;
|
|
122
|
+
}
|
|
123
|
+
insertRule(rule, index) {
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
deleteRule(index) { }
|
|
127
|
+
};
|
|
128
|
+
// Define SVGElement globally
|
|
129
|
+
globalThis.SVGElement = class {
|
|
130
|
+
constructor() {
|
|
131
|
+
this.id = '';
|
|
132
|
+
this.className = '';
|
|
133
|
+
this.style = {
|
|
134
|
+
cssText: '',
|
|
135
|
+
length: 0,
|
|
136
|
+
parentRule: null,
|
|
137
|
+
getPropertyPriority: () => '',
|
|
138
|
+
getPropertyValue: () => '',
|
|
139
|
+
item: () => '',
|
|
140
|
+
removeProperty: () => '',
|
|
141
|
+
setProperty: () => '',
|
|
142
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
143
|
+
};
|
|
144
|
+
this.ownerSVGElement = null;
|
|
145
|
+
this.viewportElement = null;
|
|
146
|
+
this.tagName = '';
|
|
147
|
+
this.namespaceURI = null;
|
|
148
|
+
this.prefix = null;
|
|
149
|
+
this.localName = '';
|
|
150
|
+
this.baseURI = '';
|
|
151
|
+
this.textContent = '';
|
|
152
|
+
this.innerHTML = '';
|
|
153
|
+
this.outerHTML = '';
|
|
154
|
+
this.hidden = false;
|
|
155
|
+
this.slot = '';
|
|
156
|
+
this.attributes = {
|
|
157
|
+
length: 0,
|
|
158
|
+
getNamedItem: () => null,
|
|
159
|
+
getNamedItemNS: () => null,
|
|
160
|
+
item: () => null,
|
|
161
|
+
removeNamedItem: () => null,
|
|
162
|
+
removeNamedItemNS: () => null,
|
|
163
|
+
setNamedItem: () => null,
|
|
164
|
+
setNamedItemNS: () => null,
|
|
165
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
166
|
+
};
|
|
167
|
+
this.childNodes = {
|
|
168
|
+
length: 0,
|
|
169
|
+
item: () => null,
|
|
170
|
+
forEach: () => { },
|
|
171
|
+
entries: function* () { yield [0, null]; return undefined; },
|
|
172
|
+
keys: function* () { yield 0; return undefined; },
|
|
173
|
+
values: function* () { yield null; return undefined; },
|
|
174
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
175
|
+
};
|
|
176
|
+
this.firstChild = null;
|
|
177
|
+
this.lastChild = null;
|
|
178
|
+
this.nextSibling = null;
|
|
179
|
+
this.previousSibling = null;
|
|
180
|
+
this.parentNode = null;
|
|
181
|
+
this.parentElement = null;
|
|
182
|
+
this.childElementCount = 0;
|
|
183
|
+
this.firstElementChild = null;
|
|
184
|
+
this.lastElementChild = null;
|
|
185
|
+
this.nextElementSibling = null;
|
|
186
|
+
this.previousElementSibling = null;
|
|
187
|
+
this.children = {
|
|
188
|
+
length: 0,
|
|
189
|
+
item: () => null,
|
|
190
|
+
namedItem: () => null,
|
|
191
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
192
|
+
};
|
|
193
|
+
// Initialize any required properties
|
|
194
|
+
}
|
|
195
|
+
getAttribute(name) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
getAttributeNS(namespaceURI, localName) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
setAttribute(name, value) { }
|
|
202
|
+
setAttributeNS(namespaceURI, qualifiedName, value) { }
|
|
203
|
+
removeAttributeNS(namespaceURI, localName) { }
|
|
204
|
+
hasAttribute(name) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
hasAttributeNS(namespaceURI, localName) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
getBoundingClientRect() {
|
|
211
|
+
return {
|
|
212
|
+
top: 0,
|
|
213
|
+
left: 0,
|
|
214
|
+
bottom: 0,
|
|
215
|
+
right: 0,
|
|
216
|
+
width: 0,
|
|
217
|
+
height: 0,
|
|
218
|
+
x: 0,
|
|
219
|
+
y: 0,
|
|
220
|
+
toJSON: function () { return this; }
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
getClientRects() {
|
|
224
|
+
return {
|
|
225
|
+
length: 0,
|
|
226
|
+
item: function () { return null; },
|
|
227
|
+
[Symbol.iterator]: function* () { }
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
getElementsByClassName(classNames) {
|
|
231
|
+
return {
|
|
232
|
+
length: 0,
|
|
233
|
+
item: () => null,
|
|
234
|
+
namedItem: () => null,
|
|
235
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
getElementsByTagName(qualifiedName) {
|
|
239
|
+
return {
|
|
240
|
+
length: 0,
|
|
241
|
+
item: () => null,
|
|
242
|
+
namedItem: () => null,
|
|
243
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
getElementsByTagNameNS(namespaceURI, localName) {
|
|
247
|
+
return {
|
|
248
|
+
length: 0,
|
|
249
|
+
item: () => null,
|
|
250
|
+
namedItem: () => null,
|
|
251
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
querySelector(selectors) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
querySelectorAll(selectors) {
|
|
258
|
+
return {
|
|
259
|
+
length: 0,
|
|
260
|
+
item: () => null,
|
|
261
|
+
forEach: () => { },
|
|
262
|
+
entries: function* () { yield [0, null]; return undefined; },
|
|
263
|
+
keys: function* () { yield 0; return undefined; },
|
|
264
|
+
values: function* () { yield null; return undefined; },
|
|
265
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
matches(selectors) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
closest(selectors) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
contains(other) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
append(...nodes) { }
|
|
278
|
+
prepend(...nodes) { }
|
|
279
|
+
after(...nodes) { }
|
|
280
|
+
before(...nodes) { }
|
|
281
|
+
replaceWith(...nodes) { }
|
|
282
|
+
remove() { }
|
|
283
|
+
insertAdjacentElement(where, element) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
insertAdjacentText(where, data) { }
|
|
287
|
+
insertAdjacentHTML(position, text) { }
|
|
288
|
+
replaceChildren(...nodes) { }
|
|
289
|
+
};
|
|
290
|
+
// Define HTMLImageElement globally
|
|
291
|
+
globalThis.HTMLImageElement = class {
|
|
292
|
+
constructor() {
|
|
293
|
+
this.alt = '';
|
|
294
|
+
this.src = '';
|
|
295
|
+
this.srcset = '';
|
|
296
|
+
this.sizes = '';
|
|
297
|
+
this.crossOrigin = null;
|
|
298
|
+
this.useMap = '';
|
|
299
|
+
this.isMap = false;
|
|
300
|
+
this.width = 0;
|
|
301
|
+
this.height = 0;
|
|
302
|
+
this.naturalWidth = 0;
|
|
303
|
+
this.naturalHeight = 0;
|
|
304
|
+
this.complete = false;
|
|
305
|
+
this.name = '';
|
|
306
|
+
this.lowsrc = '';
|
|
307
|
+
this.align = '';
|
|
308
|
+
this.hspace = 0;
|
|
309
|
+
this.vspace = 0;
|
|
310
|
+
this.longDesc = '';
|
|
311
|
+
this.border = '';
|
|
312
|
+
this.x = 0;
|
|
313
|
+
this.y = 0;
|
|
314
|
+
this.currentSrc = '';
|
|
315
|
+
this.decoding = 'auto';
|
|
316
|
+
this.fetchPriority = 'auto';
|
|
317
|
+
this.loading = 'eager';
|
|
318
|
+
this.referrerPolicy = '';
|
|
319
|
+
// Initialize any required properties
|
|
320
|
+
}
|
|
321
|
+
decode() {
|
|
322
|
+
return Promise.resolve();
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
// Define DOMSettableTokenList
|
|
326
|
+
globalThis.DOMSettableTokenList = class {
|
|
327
|
+
constructor() {
|
|
328
|
+
this.length = 0;
|
|
329
|
+
this.value = '';
|
|
330
|
+
}
|
|
331
|
+
add(token) { }
|
|
332
|
+
contains(token) { return false; }
|
|
333
|
+
item(index) { return null; }
|
|
334
|
+
remove(token) { }
|
|
335
|
+
replace(oldToken, newToken) { return false; }
|
|
336
|
+
supports(token) { return false; }
|
|
337
|
+
toggle(token, force) { return false; }
|
|
338
|
+
[Symbol.iterator]() {
|
|
339
|
+
return function* () { yield ''; return undefined; }();
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
// Define HTML element types
|
|
343
|
+
globalThis.HTMLIFrameElement = class extends globalThis.HTMLElement {
|
|
344
|
+
constructor() {
|
|
345
|
+
super();
|
|
346
|
+
this.align = '';
|
|
347
|
+
this.allow = '';
|
|
348
|
+
this.allowFullscreen = false;
|
|
349
|
+
this.contentDocument = null;
|
|
350
|
+
this.contentWindow = null;
|
|
351
|
+
this.frameBorder = '';
|
|
352
|
+
this.height = '';
|
|
353
|
+
this.longDesc = '';
|
|
354
|
+
this.marginHeight = '';
|
|
355
|
+
this.marginWidth = '';
|
|
356
|
+
this.name = '';
|
|
357
|
+
this.referrerPolicy = '';
|
|
358
|
+
this.sandbox = {
|
|
359
|
+
length: 0,
|
|
360
|
+
value: '',
|
|
361
|
+
add: () => { },
|
|
362
|
+
contains: () => false,
|
|
363
|
+
item: () => null,
|
|
364
|
+
remove: () => { },
|
|
365
|
+
replace: () => false,
|
|
366
|
+
supports: () => false,
|
|
367
|
+
toggle: () => false,
|
|
368
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
369
|
+
};
|
|
370
|
+
this.scrolling = '';
|
|
371
|
+
this.src = '';
|
|
372
|
+
this.srcdoc = '';
|
|
373
|
+
this.width = '';
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
globalThis.HTMLOListElement = class extends globalThis.HTMLElement {
|
|
377
|
+
constructor() {
|
|
378
|
+
super();
|
|
379
|
+
this.type = '';
|
|
380
|
+
this.compact = false;
|
|
381
|
+
this.reversed = false;
|
|
382
|
+
this.start = 0;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
globalThis.HTMLUListElement = class extends globalThis.HTMLElement {
|
|
386
|
+
constructor() {
|
|
387
|
+
super();
|
|
388
|
+
this.type = '';
|
|
389
|
+
this.compact = false;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
globalThis.HTMLTableElement = class extends globalThis.HTMLElement {
|
|
393
|
+
constructor() {
|
|
394
|
+
super();
|
|
395
|
+
this.caption = null;
|
|
396
|
+
this.tHead = null;
|
|
397
|
+
this.tFoot = null;
|
|
398
|
+
this.tBodies = {
|
|
399
|
+
length: 0,
|
|
400
|
+
item: () => null,
|
|
401
|
+
namedItem: () => null,
|
|
402
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
403
|
+
};
|
|
404
|
+
this.rows = {
|
|
405
|
+
length: 0,
|
|
406
|
+
item: () => null,
|
|
407
|
+
namedItem: () => null,
|
|
408
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
409
|
+
};
|
|
410
|
+
this.align = '';
|
|
411
|
+
this.bgColor = '';
|
|
412
|
+
this.border = '';
|
|
413
|
+
this.cellPadding = '';
|
|
414
|
+
this.cellSpacing = '';
|
|
415
|
+
this.frame = '';
|
|
416
|
+
this.rules = '';
|
|
417
|
+
this.summary = '';
|
|
418
|
+
this.width = '';
|
|
419
|
+
}
|
|
420
|
+
createCaption() {
|
|
421
|
+
return new globalThis.HTMLTableCaptionElement();
|
|
422
|
+
}
|
|
423
|
+
deleteCaption() { }
|
|
424
|
+
createTHead() {
|
|
425
|
+
return new globalThis.HTMLTableSectionElement();
|
|
426
|
+
}
|
|
427
|
+
deleteTHead() { }
|
|
428
|
+
createTFoot() {
|
|
429
|
+
return new globalThis.HTMLTableSectionElement();
|
|
430
|
+
}
|
|
431
|
+
deleteTFoot() { }
|
|
432
|
+
createTBody() {
|
|
433
|
+
return new globalThis.HTMLTableSectionElement();
|
|
434
|
+
}
|
|
435
|
+
insertRow(index) {
|
|
436
|
+
return new globalThis.HTMLTableRowElement();
|
|
437
|
+
}
|
|
438
|
+
deleteRow(index) { }
|
|
439
|
+
};
|
|
440
|
+
globalThis.HTMLTableRowElement = class extends globalThis.HTMLElement {
|
|
441
|
+
constructor() {
|
|
442
|
+
super();
|
|
443
|
+
this.rowIndex = 0;
|
|
444
|
+
this.sectionRowIndex = 0;
|
|
445
|
+
this.cells = {
|
|
446
|
+
length: 0,
|
|
447
|
+
item: () => null,
|
|
448
|
+
namedItem: () => null,
|
|
449
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
450
|
+
};
|
|
451
|
+
this.align = '';
|
|
452
|
+
this.bgColor = '';
|
|
453
|
+
this.ch = '';
|
|
454
|
+
this.chOff = '';
|
|
455
|
+
this.vAlign = '';
|
|
456
|
+
}
|
|
457
|
+
insertCell(index) {
|
|
458
|
+
return new globalThis.HTMLTableCellElement();
|
|
459
|
+
}
|
|
460
|
+
deleteCell(index) { }
|
|
461
|
+
};
|
|
462
|
+
globalThis.HTMLTableCellElement = class extends globalThis.HTMLElement {
|
|
463
|
+
constructor() {
|
|
464
|
+
super();
|
|
465
|
+
this.colSpan = 1;
|
|
466
|
+
this.rowSpan = 1;
|
|
467
|
+
this.headers = {
|
|
468
|
+
length: 0,
|
|
469
|
+
value: '',
|
|
470
|
+
add: () => { },
|
|
471
|
+
contains: () => false,
|
|
472
|
+
item: () => null,
|
|
473
|
+
remove: () => { },
|
|
474
|
+
replace: () => false,
|
|
475
|
+
supports: () => false,
|
|
476
|
+
toggle: () => false,
|
|
477
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
478
|
+
};
|
|
479
|
+
this.cellIndex = 0;
|
|
480
|
+
this.scope = '';
|
|
481
|
+
this.abbr = '';
|
|
482
|
+
this.align = '';
|
|
483
|
+
this.axis = '';
|
|
484
|
+
this.bgColor = '';
|
|
485
|
+
this.ch = '';
|
|
486
|
+
this.chOff = '';
|
|
487
|
+
this.height = '';
|
|
488
|
+
this.noWrap = false;
|
|
489
|
+
this.vAlign = '';
|
|
490
|
+
this.width = '';
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
globalThis.HTMLTableSectionElement = class extends globalThis.HTMLElement {
|
|
494
|
+
constructor() {
|
|
495
|
+
super();
|
|
496
|
+
this.rows = {
|
|
497
|
+
length: 0,
|
|
498
|
+
item: () => null,
|
|
499
|
+
namedItem: () => null,
|
|
500
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
501
|
+
};
|
|
502
|
+
this.align = '';
|
|
503
|
+
this.ch = '';
|
|
504
|
+
this.chOff = '';
|
|
505
|
+
this.vAlign = '';
|
|
506
|
+
}
|
|
507
|
+
insertRow(index) {
|
|
508
|
+
return new globalThis.HTMLTableRowElement();
|
|
509
|
+
}
|
|
510
|
+
deleteRow(index) { }
|
|
511
|
+
};
|
|
512
|
+
globalThis.HTMLTableCaptionElement = class extends globalThis.HTMLElement {
|
|
513
|
+
constructor() {
|
|
514
|
+
super();
|
|
515
|
+
this.align = '';
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
globalThis.HTMLButtonElement = class extends globalThis.HTMLElement {
|
|
519
|
+
constructor() {
|
|
520
|
+
super();
|
|
521
|
+
this.disabled = false;
|
|
522
|
+
this.form = null;
|
|
523
|
+
this.formAction = '';
|
|
524
|
+
this.formEnctype = '';
|
|
525
|
+
this.formMethod = '';
|
|
526
|
+
this.formNoValidate = false;
|
|
527
|
+
this.formTarget = '';
|
|
528
|
+
this.name = '';
|
|
529
|
+
this.type = 'submit';
|
|
530
|
+
this.value = '';
|
|
531
|
+
this.menu = null;
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
// Add HTMLSpanElement interface
|
|
535
|
+
globalThis.HTMLSpanElement = class extends globalThis.HTMLElement {
|
|
536
|
+
constructor() {
|
|
537
|
+
super();
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
// Add HTMLDivElement interface
|
|
541
|
+
globalThis.HTMLDivElement = class extends globalThis.HTMLElement {
|
|
542
|
+
constructor() {
|
|
543
|
+
super();
|
|
544
|
+
this.align = '';
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
globalThis.HTMLAnchorElement = class extends globalThis.HTMLElement {
|
|
548
|
+
constructor() {
|
|
549
|
+
super();
|
|
550
|
+
this.href = '';
|
|
551
|
+
this.target = '';
|
|
552
|
+
this.download = '';
|
|
553
|
+
this.ping = '';
|
|
554
|
+
this.rel = '';
|
|
555
|
+
this.relList = {
|
|
556
|
+
length: 0,
|
|
557
|
+
value: '',
|
|
558
|
+
add: () => { },
|
|
559
|
+
contains: () => false,
|
|
560
|
+
item: () => null,
|
|
561
|
+
remove: () => { },
|
|
562
|
+
replace: () => false,
|
|
563
|
+
supports: () => false,
|
|
564
|
+
toggle: () => false,
|
|
565
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
566
|
+
};
|
|
567
|
+
this.hreflang = '';
|
|
568
|
+
this.type = '';
|
|
569
|
+
this.text = '';
|
|
570
|
+
this.referrerPolicy = '';
|
|
571
|
+
this.origin = '';
|
|
572
|
+
this.protocol = '';
|
|
573
|
+
this.username = '';
|
|
574
|
+
this.password = '';
|
|
575
|
+
this.host = '';
|
|
576
|
+
this.hostname = '';
|
|
577
|
+
this.port = '';
|
|
578
|
+
this.pathname = '';
|
|
579
|
+
this.search = '';
|
|
580
|
+
this.hash = '';
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* Creates a virtual DOM instance with the given HTML content
|
|
585
|
+
*/
|
|
586
|
+
export function createVirtualDOM(html, url) {
|
|
587
|
+
const dom = new JSDOM(html, {
|
|
588
|
+
virtualConsole,
|
|
589
|
+
runScripts: 'dangerously',
|
|
590
|
+
resources: 'usable',
|
|
591
|
+
pretendToBeVisual: true,
|
|
592
|
+
url,
|
|
593
|
+
beforeParse(window) {
|
|
594
|
+
try {
|
|
595
|
+
setupDOMInterfaces(window);
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
console.error('Error setting up DOM interfaces:', error);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
return dom;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Sets up additional document properties
|
|
606
|
+
*/
|
|
607
|
+
export function setupDocumentProperties(doc) {
|
|
608
|
+
// Ensure document has required properties
|
|
609
|
+
if (!doc.documentElement) {
|
|
610
|
+
throw new Error('Document has no root element');
|
|
611
|
+
}
|
|
612
|
+
// Set up document properties
|
|
613
|
+
try {
|
|
614
|
+
doc.documentElement.style.cssText = '';
|
|
615
|
+
doc.documentElement.className = '';
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
console.warn('Warning: Could not set document element properties:', error);
|
|
619
|
+
}
|
|
620
|
+
// Ensure body exists and is properly set up
|
|
621
|
+
if (!doc.body) {
|
|
622
|
+
const body = doc.createElement('body');
|
|
623
|
+
doc.documentElement.appendChild(body);
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
doc.body.style.cssText = '';
|
|
627
|
+
doc.body.className = '';
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
console.warn('Warning: Could not set body properties:', error);
|
|
631
|
+
}
|
|
632
|
+
// Set up viewport and ensure head exists
|
|
633
|
+
if (!doc.head) {
|
|
634
|
+
const head = doc.createElement('head');
|
|
635
|
+
doc.documentElement.insertBefore(head, doc.body);
|
|
636
|
+
}
|
|
637
|
+
// Add viewport meta tag
|
|
638
|
+
try {
|
|
639
|
+
const viewport = doc.createElement('meta');
|
|
640
|
+
viewport.setAttribute('name', 'viewport');
|
|
641
|
+
viewport.setAttribute('content', 'width=device-width, initial-scale=1');
|
|
642
|
+
doc.head.appendChild(viewport);
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
console.warn('Warning: Could not add viewport meta tag:', error);
|
|
646
|
+
}
|
|
647
|
+
// Add a base style element for mobile styles
|
|
648
|
+
try {
|
|
649
|
+
const style = doc.createElement('style');
|
|
650
|
+
style.textContent = `
|
|
651
|
+
@media (max-width: 768px) {
|
|
652
|
+
body { width: 100%; }
|
|
653
|
+
}
|
|
654
|
+
`;
|
|
655
|
+
doc.head.appendChild(style);
|
|
656
|
+
}
|
|
657
|
+
catch (error) {
|
|
658
|
+
console.warn('Warning: Could not add style element:', error);
|
|
659
|
+
}
|
|
660
|
+
}
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|