defuddle-cli 0.1.1 → 0.1.3
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 +14 -347
- package/package.json +2 -2
- 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 +16 -374
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { setupDocumentMethods, setupWindowMethods } from './document.js';
|
|
2
|
+
// Setup basic window properties
|
|
3
|
+
export const setupBasicWindow = (window) => {
|
|
4
|
+
if (!window.innerWidth) {
|
|
5
|
+
Object.defineProperty(window, 'innerWidth', { value: 1024 });
|
|
6
|
+
}
|
|
7
|
+
if (!window.innerHeight) {
|
|
8
|
+
Object.defineProperty(window, 'innerHeight', { value: 768 });
|
|
9
|
+
}
|
|
10
|
+
if (!window.devicePixelRatio) {
|
|
11
|
+
Object.defineProperty(window, 'devicePixelRatio', { value: 1 });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
// Setup CSS interfaces
|
|
15
|
+
export const setupCSSInterfaces = (window) => {
|
|
16
|
+
if (!window.CSSRule) {
|
|
17
|
+
window.CSSRule = globalThis.CSSRule;
|
|
18
|
+
}
|
|
19
|
+
if (!window.CSSMediaRule) {
|
|
20
|
+
window.CSSMediaRule = globalThis.CSSMediaRule;
|
|
21
|
+
}
|
|
22
|
+
if (!window.CSSStyleSheet) {
|
|
23
|
+
window.CSSStyleSheet = globalThis.CSSStyleSheet;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
// Setup HTML and SVG interfaces
|
|
27
|
+
export const setupHTMLAndSVG = (window) => {
|
|
28
|
+
if (!window.HTMLImageElement) {
|
|
29
|
+
window.HTMLImageElement = globalThis.HTMLImageElement;
|
|
30
|
+
}
|
|
31
|
+
if (!window.SVGElement) {
|
|
32
|
+
window.SVGElement = globalThis.SVGElement;
|
|
33
|
+
}
|
|
34
|
+
if (!window.HTMLAnchorElement) {
|
|
35
|
+
window.HTMLAnchorElement = globalThis.HTMLAnchorElement;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// Setup screen object
|
|
39
|
+
export const setupScreen = (window) => {
|
|
40
|
+
if (!window.screen) {
|
|
41
|
+
Object.defineProperty(window, 'screen', {
|
|
42
|
+
value: {
|
|
43
|
+
width: 1024,
|
|
44
|
+
height: 768,
|
|
45
|
+
availWidth: 1024,
|
|
46
|
+
availHeight: 768,
|
|
47
|
+
colorDepth: 24,
|
|
48
|
+
pixelDepth: 24,
|
|
49
|
+
orientation: {
|
|
50
|
+
type: 'landscape-primary',
|
|
51
|
+
angle: 0
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// Setup storage objects
|
|
58
|
+
export const setupStorage = (window) => {
|
|
59
|
+
const createStorage = () => {
|
|
60
|
+
const storage = {
|
|
61
|
+
length: 0,
|
|
62
|
+
getItem: () => null,
|
|
63
|
+
setItem: () => { },
|
|
64
|
+
removeItem: () => { },
|
|
65
|
+
clear: () => { },
|
|
66
|
+
key: () => null
|
|
67
|
+
};
|
|
68
|
+
// Make the storage object non-extensible
|
|
69
|
+
Object.preventExtensions(storage);
|
|
70
|
+
return storage;
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
// Create storage objects
|
|
74
|
+
const localStorage = createStorage();
|
|
75
|
+
const sessionStorage = createStorage();
|
|
76
|
+
// Define properties with more permissive attributes
|
|
77
|
+
Object.defineProperties(window, {
|
|
78
|
+
localStorage: {
|
|
79
|
+
value: localStorage,
|
|
80
|
+
writable: true,
|
|
81
|
+
configurable: true
|
|
82
|
+
},
|
|
83
|
+
sessionStorage: {
|
|
84
|
+
value: sessionStorage,
|
|
85
|
+
writable: true,
|
|
86
|
+
configurable: true
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// Log the error but don't throw
|
|
92
|
+
console.warn('Warning: Could not set up storage objects:', error instanceof Error ? error.message : 'Unknown error');
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Setup animation frame methods
|
|
96
|
+
export const setupAnimationFrame = (window) => {
|
|
97
|
+
if (!window.requestAnimationFrame) {
|
|
98
|
+
window.requestAnimationFrame = (callback) => {
|
|
99
|
+
return setTimeout(callback, 0);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (!window.cancelAnimationFrame) {
|
|
103
|
+
window.cancelAnimationFrame = (handle) => {
|
|
104
|
+
clearTimeout(handle);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
// Setup DOM methods
|
|
109
|
+
export const setupDOMMethods = (window) => {
|
|
110
|
+
if (!window.Document.prototype.getElementsByClassName) {
|
|
111
|
+
window.Document.prototype.getElementsByClassName = function (classNames) {
|
|
112
|
+
const elements = this.querySelectorAll('.' + classNames);
|
|
113
|
+
const collection = new HTMLCollection();
|
|
114
|
+
elements.forEach((el, i) => {
|
|
115
|
+
collection[i] = el;
|
|
116
|
+
});
|
|
117
|
+
return collection;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
// Setup Node methods
|
|
122
|
+
export const setupNodeMethods = (window) => {
|
|
123
|
+
if (!window.Node.prototype.contains) {
|
|
124
|
+
window.Node.prototype.contains = function (node) {
|
|
125
|
+
let current = node;
|
|
126
|
+
while (current) {
|
|
127
|
+
if (current === this)
|
|
128
|
+
return true;
|
|
129
|
+
current = current.parentNode;
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
// Setup Element methods
|
|
136
|
+
export const setupElementMethods = (window) => {
|
|
137
|
+
if (!window.Element.prototype.getBoundingClientRect) {
|
|
138
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
139
|
+
return {
|
|
140
|
+
top: 0,
|
|
141
|
+
left: 0,
|
|
142
|
+
bottom: 0,
|
|
143
|
+
right: 0,
|
|
144
|
+
width: 0,
|
|
145
|
+
height: 0,
|
|
146
|
+
x: 0,
|
|
147
|
+
y: 0,
|
|
148
|
+
toJSON: function () { return this; }
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
// Main setup function that orchestrates all the individual setups
|
|
154
|
+
export const setupDOMInterfaces = (window) => {
|
|
155
|
+
const setupFunctions = [
|
|
156
|
+
['basic window', setupBasicWindow],
|
|
157
|
+
['CSS interfaces', setupCSSInterfaces],
|
|
158
|
+
['HTML and SVG interfaces', setupHTMLAndSVG],
|
|
159
|
+
['screen object', setupScreen],
|
|
160
|
+
['storage objects', setupStorage],
|
|
161
|
+
['animation frame methods', setupAnimationFrame],
|
|
162
|
+
['DOM methods', setupDOMMethods],
|
|
163
|
+
['Node methods', setupNodeMethods],
|
|
164
|
+
['Element methods', setupElementMethods],
|
|
165
|
+
['Document methods', setupDocumentMethods],
|
|
166
|
+
['Window methods', setupWindowMethods]
|
|
167
|
+
];
|
|
168
|
+
try {
|
|
169
|
+
for (const [name, setup] of setupFunctions) {
|
|
170
|
+
try {
|
|
171
|
+
setup(window);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.warn(`Warning: Could not set up ${name}:`, error instanceof Error ? error.message : 'Unknown error');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
console.error('Error in setupDOMInterfaces:', error instanceof Error ? error.message : 'Unknown error');
|
|
180
|
+
// Don't throw the error, just log it
|
|
181
|
+
}
|
|
182
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare class SVGElement {
|
|
2
|
+
id: string;
|
|
3
|
+
className: string;
|
|
4
|
+
style: CSSStyleDeclaration;
|
|
5
|
+
ownerSVGElement: SVGElement | null;
|
|
6
|
+
viewportElement: SVGElement | null;
|
|
7
|
+
tagName: string;
|
|
8
|
+
namespaceURI: string | null;
|
|
9
|
+
prefix: string | null;
|
|
10
|
+
localName: string;
|
|
11
|
+
baseURI: string;
|
|
12
|
+
textContent: string | null;
|
|
13
|
+
innerHTML: string;
|
|
14
|
+
outerHTML: string;
|
|
15
|
+
hidden: boolean;
|
|
16
|
+
slot: string;
|
|
17
|
+
attributes: NamedNodeMap;
|
|
18
|
+
childNodes: NodeListOf<ChildNode>;
|
|
19
|
+
firstChild: ChildNode | null;
|
|
20
|
+
lastChild: ChildNode | null;
|
|
21
|
+
nextSibling: ChildNode | null;
|
|
22
|
+
previousSibling: ChildNode | null;
|
|
23
|
+
parentNode: Node & ParentNode | null;
|
|
24
|
+
parentElement: HTMLElement | null;
|
|
25
|
+
childElementCount: number;
|
|
26
|
+
firstElementChild: Element | null;
|
|
27
|
+
lastElementChild: Element | null;
|
|
28
|
+
nextElementSibling: Element | null;
|
|
29
|
+
previousElementSibling: Element | null;
|
|
30
|
+
children: HTMLCollection;
|
|
31
|
+
constructor();
|
|
32
|
+
getAttribute(name: string): string | null;
|
|
33
|
+
getAttributeNS(namespaceURI: string | null, localName: string): string | null;
|
|
34
|
+
setAttribute(name: string, value: string): void;
|
|
35
|
+
setAttributeNS(namespaceURI: string | null, qualifiedName: string, value: string): void;
|
|
36
|
+
removeAttributeNS(namespaceURI: string | null, localName: string): void;
|
|
37
|
+
hasAttribute(name: string): boolean;
|
|
38
|
+
hasAttributeNS(namespaceURI: string | null, localName: string): boolean;
|
|
39
|
+
getBoundingClientRect(): DOMRect;
|
|
40
|
+
getClientRects(): DOMRectList;
|
|
41
|
+
getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
|
|
42
|
+
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
|
|
43
|
+
getElementsByTagNameNS(namespaceURI: string | null, localName: string): HTMLCollectionOf<Element>;
|
|
44
|
+
querySelector(selectors: string): Element | null;
|
|
45
|
+
querySelectorAll(selectors: string): NodeListOf<Element>;
|
|
46
|
+
matches(selectors: string): boolean;
|
|
47
|
+
closest(selectors: string): Element | null;
|
|
48
|
+
contains(other: Node | null): boolean;
|
|
49
|
+
append(...nodes: (Node | string)[]): void;
|
|
50
|
+
prepend(...nodes: (Node | string)[]): void;
|
|
51
|
+
after(...nodes: (Node | string)[]): void;
|
|
52
|
+
before(...nodes: (Node | string)[]): void;
|
|
53
|
+
replaceWith(...nodes: (Node | string)[]): void;
|
|
54
|
+
remove(): void;
|
|
55
|
+
insertAdjacentElement(where: InsertPosition, element: Element): Element | null;
|
|
56
|
+
insertAdjacentText(where: InsertPosition, data: string): void;
|
|
57
|
+
insertAdjacentHTML(position: InsertPosition, text: string): void;
|
|
58
|
+
replaceChildren(...nodes: (Node | string)[]): void;
|
|
59
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export class SVGElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.id = '';
|
|
4
|
+
this.className = '';
|
|
5
|
+
this.style = {
|
|
6
|
+
cssText: '',
|
|
7
|
+
length: 0,
|
|
8
|
+
parentRule: null,
|
|
9
|
+
getPropertyPriority: () => '',
|
|
10
|
+
getPropertyValue: () => '',
|
|
11
|
+
item: () => '',
|
|
12
|
+
removeProperty: () => '',
|
|
13
|
+
setProperty: () => '',
|
|
14
|
+
[Symbol.iterator]: function* () { yield ''; return undefined; }
|
|
15
|
+
};
|
|
16
|
+
this.ownerSVGElement = null;
|
|
17
|
+
this.viewportElement = null;
|
|
18
|
+
this.tagName = '';
|
|
19
|
+
this.namespaceURI = null;
|
|
20
|
+
this.prefix = null;
|
|
21
|
+
this.localName = '';
|
|
22
|
+
this.baseURI = '';
|
|
23
|
+
this.textContent = '';
|
|
24
|
+
this.innerHTML = '';
|
|
25
|
+
this.outerHTML = '';
|
|
26
|
+
this.hidden = false;
|
|
27
|
+
this.slot = '';
|
|
28
|
+
this.attributes = {
|
|
29
|
+
length: 0,
|
|
30
|
+
getNamedItem: () => null,
|
|
31
|
+
getNamedItemNS: () => null,
|
|
32
|
+
item: () => null,
|
|
33
|
+
removeNamedItem: () => null,
|
|
34
|
+
removeNamedItemNS: () => null,
|
|
35
|
+
setNamedItem: () => null,
|
|
36
|
+
setNamedItemNS: () => null,
|
|
37
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
38
|
+
};
|
|
39
|
+
this.childNodes = {
|
|
40
|
+
length: 0,
|
|
41
|
+
item: () => null,
|
|
42
|
+
forEach: () => { },
|
|
43
|
+
entries: function* () { yield [0, null]; return undefined; },
|
|
44
|
+
keys: function* () { yield 0; return undefined; },
|
|
45
|
+
values: function* () { yield null; return undefined; },
|
|
46
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
47
|
+
};
|
|
48
|
+
this.firstChild = null;
|
|
49
|
+
this.lastChild = null;
|
|
50
|
+
this.nextSibling = null;
|
|
51
|
+
this.previousSibling = null;
|
|
52
|
+
this.parentNode = null;
|
|
53
|
+
this.parentElement = null;
|
|
54
|
+
this.childElementCount = 0;
|
|
55
|
+
this.firstElementChild = null;
|
|
56
|
+
this.lastElementChild = null;
|
|
57
|
+
this.nextElementSibling = null;
|
|
58
|
+
this.previousElementSibling = null;
|
|
59
|
+
this.children = {
|
|
60
|
+
length: 0,
|
|
61
|
+
item: () => null,
|
|
62
|
+
namedItem: () => null,
|
|
63
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
64
|
+
};
|
|
65
|
+
// Initialize any required properties
|
|
66
|
+
}
|
|
67
|
+
getAttribute(name) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
getAttributeNS(namespaceURI, localName) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
setAttribute(name, value) { }
|
|
74
|
+
setAttributeNS(namespaceURI, qualifiedName, value) { }
|
|
75
|
+
removeAttributeNS(namespaceURI, localName) { }
|
|
76
|
+
hasAttribute(name) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
hasAttributeNS(namespaceURI, localName) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
getBoundingClientRect() {
|
|
83
|
+
return {
|
|
84
|
+
top: 0,
|
|
85
|
+
left: 0,
|
|
86
|
+
bottom: 0,
|
|
87
|
+
right: 0,
|
|
88
|
+
width: 0,
|
|
89
|
+
height: 0,
|
|
90
|
+
x: 0,
|
|
91
|
+
y: 0,
|
|
92
|
+
toJSON: function () { return this; }
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
getClientRects() {
|
|
96
|
+
return {
|
|
97
|
+
length: 0,
|
|
98
|
+
item: function () { return null; },
|
|
99
|
+
[Symbol.iterator]: function* () { }
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
getElementsByClassName(classNames) {
|
|
103
|
+
return {
|
|
104
|
+
length: 0,
|
|
105
|
+
item: () => null,
|
|
106
|
+
namedItem: () => null,
|
|
107
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
getElementsByTagName(qualifiedName) {
|
|
111
|
+
return {
|
|
112
|
+
length: 0,
|
|
113
|
+
item: () => null,
|
|
114
|
+
namedItem: () => null,
|
|
115
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
getElementsByTagNameNS(namespaceURI, localName) {
|
|
119
|
+
return {
|
|
120
|
+
length: 0,
|
|
121
|
+
item: () => null,
|
|
122
|
+
namedItem: () => null,
|
|
123
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
querySelector(selectors) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
querySelectorAll(selectors) {
|
|
130
|
+
return {
|
|
131
|
+
length: 0,
|
|
132
|
+
item: () => null,
|
|
133
|
+
forEach: () => { },
|
|
134
|
+
entries: function* () { yield [0, null]; return undefined; },
|
|
135
|
+
keys: function* () { yield 0; return undefined; },
|
|
136
|
+
values: function* () { yield null; return undefined; },
|
|
137
|
+
[Symbol.iterator]: function* () { yield null; return undefined; }
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
matches(selectors) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
closest(selectors) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
contains(other) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
append(...nodes) { }
|
|
150
|
+
prepend(...nodes) { }
|
|
151
|
+
after(...nodes) { }
|
|
152
|
+
before(...nodes) { }
|
|
153
|
+
replaceWith(...nodes) { }
|
|
154
|
+
remove() { }
|
|
155
|
+
insertAdjacentElement(where, element) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
insertAdjacentText(where, data) { }
|
|
159
|
+
insertAdjacentHTML(position, text) { }
|
|
160
|
+
replaceChildren(...nodes) { }
|
|
161
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a virtual DOM instance with the given HTML content
|
|
4
|
+
*/
|
|
5
|
+
export declare function createVirtualDOM(html: string, url?: string): JSDOM;
|
|
6
|
+
/**
|
|
7
|
+
* Sets up additional document properties
|
|
8
|
+
*/
|
|
9
|
+
export declare function setupDocumentProperties(doc: Document): void;
|