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