defuddle-cli 0.2.0 → 0.3.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 (36) hide show
  1. package/dist/dom/document.d.ts +3 -0
  2. package/dist/dom/document.js +49 -0
  3. package/dist/dom/elements.d.ts +2 -0
  4. package/dist/dom/elements.js +478 -0
  5. package/dist/dom/interfaces/elements/base.d.ts +14 -0
  6. package/dist/dom/interfaces/elements/base.js +46 -0
  7. package/dist/dom/interfaces/elements/form.d.ts +2 -0
  8. package/dist/dom/interfaces/elements/form.js +123 -0
  9. package/dist/dom/interfaces/elements/index.d.ts +2 -0
  10. package/dist/dom/interfaces/elements/index.js +22 -0
  11. package/dist/dom/interfaces/elements/interactive.d.ts +2 -0
  12. package/dist/dom/interfaces/elements/interactive.js +83 -0
  13. package/dist/dom/interfaces/elements/media.d.ts +2 -0
  14. package/dist/dom/interfaces/elements/media.js +43 -0
  15. package/dist/dom/interfaces/elements/table.d.ts +2 -0
  16. package/dist/dom/interfaces/elements/table.js +155 -0
  17. package/dist/dom/interfaces/elements/text.d.ts +2 -0
  18. package/dist/dom/interfaces/elements/text.js +57 -0
  19. package/dist/dom/interfaces/elements.d.ts +2 -0
  20. package/dist/dom/interfaces/elements.js +478 -0
  21. package/dist/dom/interfaces/range.d.ts +1 -1
  22. package/dist/dom/range.d.ts +2 -0
  23. package/dist/dom/range.js +87 -0
  24. package/dist/dom/setup/document.d.ts +3 -0
  25. package/dist/dom/setup/document.js +49 -0
  26. package/dist/dom/setup.d.ts +12 -9
  27. package/dist/dom/setup.js +148 -533
  28. package/dist/dom/types/setup.d.ts +10 -0
  29. package/dist/dom/types/setup.js +1 -0
  30. package/dist/index.js +9 -684
  31. package/package.json +3 -5
  32. package/src/index.ts +9 -772
  33. package/src/dom/interfaces/document.ts +0 -53
  34. package/src/dom/interfaces/range.ts +0 -120
  35. package/src/dom/interfaces/setup.ts +0 -196
  36. package/src/markdown.ts +0 -592
@@ -1,53 +0,0 @@
1
- import { DOMWindow } from 'jsdom';
2
- import { SetupFunction } from './setup.js';
3
-
4
- export const setupDocumentMethods: SetupFunction = (window: DOMWindow) => {
5
- if (!window.Document.prototype.getSelection) {
6
- window.Document.prototype.getSelection = function(): Selection | null {
7
- const selection = {
8
- anchorNode: null,
9
- anchorOffset: 0,
10
- direction: 'forward',
11
- focusNode: null,
12
- focusOffset: 0,
13
- isCollapsed: true,
14
- rangeCount: 0,
15
- type: 'None',
16
- getRangeAt: function() { return new window.Range(); },
17
- removeAllRanges: function() {},
18
- addRange: function() {},
19
- collapse: function() {},
20
- collapseToEnd: function() {},
21
- collapseToStart: function() {},
22
- deleteFromDocument: function() {},
23
- empty: function() {},
24
- extend: function() {},
25
- modify: function() {},
26
- selectAllChildren: function() {},
27
- setBaseAndExtent: function() {},
28
- setPosition: function() {},
29
- toString: function() { return ''; },
30
- containsNode: function(node: Node, allowPartialContainment: boolean = false): boolean {
31
- return false;
32
- },
33
- removeRange: function(range: Range): void {}
34
- } as unknown as Selection;
35
- return selection;
36
- };
37
- }
38
- };
39
-
40
- export const setupWindowMethods: SetupFunction = (window: DOMWindow) => {
41
- if (!window.Window.prototype.getComputedStyle) {
42
- window.Window.prototype.getComputedStyle = function(elt: Element, pseudoElt?: string | null): CSSStyleDeclaration {
43
- const style = {
44
- accentColor: '',
45
- alignContent: '',
46
- alignItems: '',
47
- alignSelf: '',
48
- getPropertyValue: function(prop: string): string { return ''; }
49
- } as CSSStyleDeclaration;
50
- return style;
51
- };
52
- }
53
- };
@@ -1,120 +0,0 @@
1
- import { DOMWindow } from 'jsdom';
2
- import { SetupFunction } from './setup.js';
3
-
4
- export const setupRange: SetupFunction = (window: DOMWindow) => {
5
- if (!window.Range) {
6
- window.Range = class Range {
7
- static readonly START_TO_START = 0;
8
- static readonly START_TO_END = 1;
9
- static readonly END_TO_END = 2;
10
- static readonly END_TO_START = 3;
11
-
12
- readonly START_TO_START = 0;
13
- readonly START_TO_END = 1;
14
- readonly END_TO_END = 2;
15
- readonly END_TO_START = 3;
16
-
17
- startContainer: Node;
18
- startOffset: number;
19
- endContainer: Node;
20
- endOffset: number;
21
- collapsed: boolean;
22
- commonAncestorContainer: Node;
23
-
24
- constructor() {
25
- this.startContainer = document.documentElement;
26
- this.startOffset = 0;
27
- this.endContainer = document.documentElement;
28
- this.endOffset = 0;
29
- this.collapsed = true;
30
- this.commonAncestorContainer = document.documentElement;
31
- }
32
-
33
- createContextualFragment(fragment: string): DocumentFragment {
34
- return document.createDocumentFragment();
35
- }
36
-
37
- detach(): void {}
38
-
39
- cloneContents(): DocumentFragment {
40
- return document.createDocumentFragment();
41
- }
42
-
43
- cloneRange(): Range {
44
- return new Range();
45
- }
46
-
47
- collapse(toStart: boolean = false): void {}
48
-
49
- compareBoundaryPoints(how: number, sourceRange: Range): number {
50
- return 0;
51
- }
52
-
53
- comparePoint(node: Node, offset: number): number {
54
- return 0;
55
- }
56
-
57
- deleteContents(): void {}
58
-
59
- extractContents(): DocumentFragment {
60
- return document.createDocumentFragment();
61
- }
62
-
63
- getBoundingClientRect(): DOMRect {
64
- return {
65
- top: 0,
66
- left: 0,
67
- bottom: 0,
68
- right: 0,
69
- width: 0,
70
- height: 0,
71
- x: 0,
72
- y: 0,
73
- toJSON: function() { return this; }
74
- };
75
- }
76
-
77
- getClientRects(): DOMRectList {
78
- return {
79
- length: 0,
80
- item: function() { return null; },
81
- [Symbol.iterator]: function*() {}
82
- } as DOMRectList;
83
- }
84
-
85
- insertNode(node: Node): void {}
86
-
87
- intersectsNode(node: Node): boolean {
88
- return false;
89
- }
90
-
91
- isPointInRange(node: Node, offset: number): boolean {
92
- return false;
93
- }
94
-
95
- selectNode(node: Node): void {}
96
-
97
- selectNodeContents(node: Node): void {
98
- this.startContainer = node;
99
- this.startOffset = 0;
100
- this.endContainer = node;
101
- this.endOffset = node.childNodes.length;
102
- this.collapsed = false;
103
- }
104
-
105
- setEnd(node: Node, offset: number): void {}
106
-
107
- setEndAfter(node: Node): void {}
108
-
109
- setEndBefore(node: Node): void {}
110
-
111
- setStart(node: Node, offset: number): void {}
112
-
113
- setStartAfter(node: Node): void {}
114
-
115
- setStartBefore(node: Node): void {}
116
-
117
- surroundContents(newParent: Node): void {}
118
- };
119
- }
120
- };
@@ -1,196 +0,0 @@
1
- import { DOMWindow } from 'jsdom';
2
- import { setupDocumentMethods, setupWindowMethods } from './document.js';
3
-
4
- // Type for DOM interface setup functions
5
- export type SetupFunction = (window: DOMWindow) => void;
6
-
7
- // Setup basic window properties
8
- export const setupBasicWindow: SetupFunction = (window) => {
9
- if (!window.innerWidth) {
10
- Object.defineProperty(window, 'innerWidth', { value: 1024 });
11
- }
12
- if (!window.innerHeight) {
13
- Object.defineProperty(window, 'innerHeight', { value: 768 });
14
- }
15
- if (!window.devicePixelRatio) {
16
- Object.defineProperty(window, 'devicePixelRatio', { value: 1 });
17
- }
18
- };
19
-
20
- // Setup CSS interfaces
21
- export const setupCSSInterfaces: SetupFunction = (window) => {
22
- if (!window.CSSRule) {
23
- window.CSSRule = (globalThis as any).CSSRule as any;
24
- }
25
- if (!window.CSSMediaRule) {
26
- window.CSSMediaRule = (globalThis as any).CSSMediaRule as any;
27
- }
28
- if (!window.CSSStyleSheet) {
29
- window.CSSStyleSheet = (globalThis as any).CSSStyleSheet as any;
30
- }
31
- };
32
-
33
- // Setup HTML and SVG interfaces
34
- export const setupHTMLAndSVG: SetupFunction = (window) => {
35
- if (!window.HTMLImageElement) {
36
- window.HTMLImageElement = (globalThis as any).HTMLImageElement as any;
37
- }
38
- if (!window.SVGElement) {
39
- window.SVGElement = (globalThis as any).SVGElement as any;
40
- }
41
- if (!window.HTMLAnchorElement) {
42
- window.HTMLAnchorElement = (globalThis as any).HTMLAnchorElement as any;
43
- }
44
- };
45
-
46
- // Setup screen object
47
- export const setupScreen: SetupFunction = (window) => {
48
- if (!window.screen) {
49
- Object.defineProperty(window, 'screen', {
50
- value: {
51
- width: 1024,
52
- height: 768,
53
- availWidth: 1024,
54
- availHeight: 768,
55
- colorDepth: 24,
56
- pixelDepth: 24,
57
- orientation: {
58
- type: 'landscape-primary',
59
- angle: 0
60
- }
61
- }
62
- });
63
- }
64
- };
65
-
66
- // Setup storage objects
67
- export const setupStorage: SetupFunction = (window) => {
68
- const createStorage = () => {
69
- const storage = {
70
- length: 0,
71
- getItem: () => null,
72
- setItem: () => {},
73
- removeItem: () => {},
74
- clear: () => {},
75
- key: () => null
76
- };
77
-
78
- // Make the storage object non-extensible
79
- Object.preventExtensions(storage);
80
- return storage;
81
- };
82
-
83
- try {
84
- // Create storage objects
85
- const localStorage = createStorage();
86
- const sessionStorage = createStorage();
87
-
88
- // Define properties with more permissive attributes
89
- Object.defineProperties(window, {
90
- localStorage: {
91
- value: localStorage,
92
- writable: true,
93
- configurable: true
94
- },
95
- sessionStorage: {
96
- value: sessionStorage,
97
- writable: true,
98
- configurable: true
99
- }
100
- });
101
- } catch (error) {
102
- // Log the error but don't throw
103
- console.warn('Warning: Could not set up storage objects:', error instanceof Error ? error.message : 'Unknown error');
104
- }
105
- };
106
-
107
- // Setup animation frame methods
108
- export const setupAnimationFrame: SetupFunction = (window) => {
109
- if (!window.requestAnimationFrame) {
110
- window.requestAnimationFrame = (callback: FrameRequestCallback): number => {
111
- return setTimeout(callback, 0) as unknown as number;
112
- };
113
- }
114
- if (!window.cancelAnimationFrame) {
115
- window.cancelAnimationFrame = (handle: number): void => {
116
- clearTimeout(handle as unknown as number);
117
- };
118
- }
119
- };
120
-
121
- // Setup DOM methods
122
- export const setupDOMMethods: SetupFunction = (window) => {
123
- if (!window.Document.prototype.getElementsByClassName) {
124
- window.Document.prototype.getElementsByClassName = function(classNames: string): HTMLCollectionOf<Element> {
125
- const elements = this.querySelectorAll('.' + classNames);
126
- const collection = new HTMLCollection();
127
- elements.forEach((el, i) => {
128
- collection[i] = el;
129
- });
130
- return collection;
131
- };
132
- }
133
- };
134
-
135
- // Setup Node methods
136
- export const setupNodeMethods: SetupFunction = (window) => {
137
- if (!window.Node.prototype.contains) {
138
- window.Node.prototype.contains = function(node: Node): boolean {
139
- let current: Node | null = node;
140
- while (current) {
141
- if (current === this) return true;
142
- current = current.parentNode;
143
- }
144
- return false;
145
- };
146
- }
147
- };
148
-
149
- // Setup Element methods
150
- export const setupElementMethods: SetupFunction = (window) => {
151
- if (!window.Element.prototype.getBoundingClientRect) {
152
- window.Element.prototype.getBoundingClientRect = function(): DOMRect {
153
- return {
154
- top: 0,
155
- left: 0,
156
- bottom: 0,
157
- right: 0,
158
- width: 0,
159
- height: 0,
160
- x: 0,
161
- y: 0,
162
- toJSON: function() { return this; }
163
- };
164
- };
165
- }
166
- };
167
-
168
- // Main setup function that orchestrates all the individual setups
169
- export const setupDOMInterfaces = (window: DOMWindow): void => {
170
- const setupFunctions: [string, SetupFunction][] = [
171
- ['basic window', setupBasicWindow],
172
- ['CSS interfaces', setupCSSInterfaces],
173
- ['HTML and SVG interfaces', setupHTMLAndSVG],
174
- ['screen object', setupScreen],
175
- ['storage objects', setupStorage],
176
- ['animation frame methods', setupAnimationFrame],
177
- ['DOM methods', setupDOMMethods],
178
- ['Node methods', setupNodeMethods],
179
- ['Element methods', setupElementMethods],
180
- ['Document methods', setupDocumentMethods],
181
- ['Window methods', setupWindowMethods]
182
- ];
183
-
184
- try {
185
- for (const [name, setup] of setupFunctions) {
186
- try {
187
- setup(window);
188
- } catch (error) {
189
- console.warn(`Warning: Could not set up ${name}:`, error instanceof Error ? error.message : 'Unknown error');
190
- }
191
- }
192
- } catch (error) {
193
- console.error('Error in setupDOMInterfaces:', error instanceof Error ? error.message : 'Unknown error');
194
- // Don't throw the error, just log it
195
- }
196
- };