@salve-software/react-native-nitro-jsdom 1.0.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 (116) hide show
  1. package/LICENSE +21 -0
  2. package/NitroJsdom.podspec +63 -0
  3. package/README.md +95 -0
  4. package/android/CMakeLists.txt +86 -0
  5. package/android/build.gradle +148 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  10. package/android/src/main/java/com/nitrojsdom/NitroJsdomPackage.kt +20 -0
  11. package/cpp/HybridHtmlSandbox.cpp +171 -0
  12. package/cpp/HybridHtmlSandbox.hpp +47 -0
  13. package/cpp/lexbor/LexborDocument.cpp +365 -0
  14. package/cpp/lexbor/LexborDocument.hpp +71 -0
  15. package/cpp/quickjs/DOMBindings.cpp +57 -0
  16. package/cpp/quickjs/DOMBindings.hpp +21 -0
  17. package/cpp/quickjs/DOMBindingsInternal.cpp +157 -0
  18. package/cpp/quickjs/DOMBindingsInternal.hpp +83 -0
  19. package/cpp/quickjs/MutationObservers.cpp +546 -0
  20. package/cpp/quickjs/MutationObservers.hpp +127 -0
  21. package/cpp/quickjs/QuickJSRuntime.cpp +475 -0
  22. package/cpp/quickjs/QuickJSRuntime.hpp +110 -0
  23. package/cpp/quickjs/Storage.cpp +130 -0
  24. package/cpp/quickjs/Storage.hpp +40 -0
  25. package/cpp/quickjs/bindings/ClassListBindings.cpp +241 -0
  26. package/cpp/quickjs/bindings/ClassListBindings.hpp +29 -0
  27. package/cpp/quickjs/bindings/DatasetBindings.cpp +120 -0
  28. package/cpp/quickjs/bindings/DatasetBindings.hpp +20 -0
  29. package/cpp/quickjs/bindings/DocumentBindings.cpp +155 -0
  30. package/cpp/quickjs/bindings/DocumentBindings.hpp +19 -0
  31. package/cpp/quickjs/bindings/ElementBindings.cpp +1106 -0
  32. package/cpp/quickjs/bindings/ElementBindings.hpp +19 -0
  33. package/cpp/quickjs/bindings/EventBindings.cpp +352 -0
  34. package/cpp/quickjs/bindings/EventBindings.hpp +21 -0
  35. package/cpp/quickjs/bindings/FetchBindings.cpp +347 -0
  36. package/cpp/quickjs/bindings/FetchBindings.hpp +16 -0
  37. package/cpp/quickjs/bindings/StyleBindings.cpp +245 -0
  38. package/cpp/quickjs/bindings/StyleBindings.hpp +22 -0
  39. package/cpp/quickjs/bindings/TimerBindings.cpp +94 -0
  40. package/cpp/quickjs/bindings/TimerBindings.hpp +16 -0
  41. package/cpp/quickjs/bindings/WindowBindings.cpp +211 -0
  42. package/cpp/quickjs/bindings/WindowBindings.hpp +16 -0
  43. package/ios/Bridge.h +8 -0
  44. package/lib/commonjs/classes/JSDOM/JSDOM.class.js +138 -0
  45. package/lib/commonjs/classes/JSDOM/JSDOM.class.js.map +1 -0
  46. package/lib/commonjs/classes/JSDOM/index.js +17 -0
  47. package/lib/commonjs/classes/JSDOM/index.js.map +1 -0
  48. package/lib/commonjs/classes/JSDOM/types/IFetchOptions.js +2 -0
  49. package/lib/commonjs/classes/JSDOM/types/IFetchOptions.js.map +1 -0
  50. package/lib/commonjs/classes/JSDOM/types/IJSDOMOptions.js +6 -0
  51. package/lib/commonjs/classes/JSDOM/types/IJSDOMOptions.js.map +1 -0
  52. package/lib/commonjs/classes/JSDOM/types/index.js +2 -0
  53. package/lib/commonjs/classes/JSDOM/types/index.js.map +1 -0
  54. package/lib/commonjs/classes/index.js +17 -0
  55. package/lib/commonjs/classes/index.js.map +1 -0
  56. package/lib/commonjs/index.js +17 -0
  57. package/lib/commonjs/index.js.map +1 -0
  58. package/lib/commonjs/package.json +1 -0
  59. package/lib/commonjs/specs/HtmlSandbox.nitro.js +6 -0
  60. package/lib/commonjs/specs/HtmlSandbox.nitro.js.map +1 -0
  61. package/lib/module/classes/JSDOM/JSDOM.class.js +133 -0
  62. package/lib/module/classes/JSDOM/JSDOM.class.js.map +1 -0
  63. package/lib/module/classes/JSDOM/index.js +4 -0
  64. package/lib/module/classes/JSDOM/index.js.map +1 -0
  65. package/lib/module/classes/JSDOM/types/IFetchOptions.js +2 -0
  66. package/lib/module/classes/JSDOM/types/IFetchOptions.js.map +1 -0
  67. package/lib/module/classes/JSDOM/types/IJSDOMOptions.js +4 -0
  68. package/lib/module/classes/JSDOM/types/IJSDOMOptions.js.map +1 -0
  69. package/lib/module/classes/JSDOM/types/index.js +2 -0
  70. package/lib/module/classes/JSDOM/types/index.js.map +1 -0
  71. package/lib/module/classes/index.js +4 -0
  72. package/lib/module/classes/index.js.map +1 -0
  73. package/lib/module/index.js +4 -0
  74. package/lib/module/index.js.map +1 -0
  75. package/lib/module/specs/HtmlSandbox.nitro.js +4 -0
  76. package/lib/module/specs/HtmlSandbox.nitro.js.map +1 -0
  77. package/lib/typescript/src/classes/JSDOM/JSDOM.class.d.ts +74 -0
  78. package/lib/typescript/src/classes/JSDOM/JSDOM.class.d.ts.map +1 -0
  79. package/lib/typescript/src/classes/JSDOM/index.d.ts +3 -0
  80. package/lib/typescript/src/classes/JSDOM/index.d.ts.map +1 -0
  81. package/lib/typescript/src/classes/JSDOM/types/IFetchOptions.d.ts +14 -0
  82. package/lib/typescript/src/classes/JSDOM/types/IFetchOptions.d.ts.map +1 -0
  83. package/lib/typescript/src/classes/JSDOM/types/IJSDOMOptions.d.ts +57 -0
  84. package/lib/typescript/src/classes/JSDOM/types/IJSDOMOptions.d.ts.map +1 -0
  85. package/lib/typescript/src/classes/JSDOM/types/index.d.ts +3 -0
  86. package/lib/typescript/src/classes/JSDOM/types/index.d.ts.map +1 -0
  87. package/lib/typescript/src/classes/index.d.ts +2 -0
  88. package/lib/typescript/src/classes/index.d.ts.map +1 -0
  89. package/lib/typescript/src/index.d.ts +2 -0
  90. package/lib/typescript/src/index.d.ts.map +1 -0
  91. package/lib/typescript/src/specs/HtmlSandbox.nitro.d.ts +13 -0
  92. package/lib/typescript/src/specs/HtmlSandbox.nitro.d.ts.map +1 -0
  93. package/nitro.json +26 -0
  94. package/nitrogen/generated/.gitattributes +1 -0
  95. package/nitrogen/generated/android/NitroJsdom+autolinking.cmake +81 -0
  96. package/nitrogen/generated/android/NitroJsdom+autolinking.gradle +27 -0
  97. package/nitrogen/generated/android/NitroJsdomOnLoad.cpp +49 -0
  98. package/nitrogen/generated/android/NitroJsdomOnLoad.hpp +34 -0
  99. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrojsdom/NitroJsdomOnLoad.kt +35 -0
  100. package/nitrogen/generated/ios/NitroJsdom+autolinking.rb +62 -0
  101. package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Bridge.cpp +17 -0
  102. package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Bridge.hpp +27 -0
  103. package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Umbrella.hpp +38 -0
  104. package/nitrogen/generated/ios/NitroJsdomAutolinking.mm +35 -0
  105. package/nitrogen/generated/ios/NitroJsdomAutolinking.swift +16 -0
  106. package/nitrogen/generated/shared/c++/HybridHtmlSandboxSpec.cpp +26 -0
  107. package/nitrogen/generated/shared/c++/HybridHtmlSandboxSpec.hpp +73 -0
  108. package/package.json +131 -0
  109. package/src/classes/JSDOM/JSDOM.class.ts +145 -0
  110. package/src/classes/JSDOM/index.ts +2 -0
  111. package/src/classes/JSDOM/types/IFetchOptions.ts +14 -0
  112. package/src/classes/JSDOM/types/IJSDOMOptions.ts +57 -0
  113. package/src/classes/JSDOM/types/index.ts +2 -0
  114. package/src/classes/index.ts +1 -0
  115. package/src/index.ts +1 -0
  116. package/src/specs/HtmlSandbox.nitro.ts +33 -0
@@ -0,0 +1,57 @@
1
+ import type { IFetchRequestInit, IFetchResponseInit } from './IFetchOptions';
2
+
3
+ export interface IJSDOMOptions {
4
+ /** Execute <script> tags found in the initial HTML. Default: true */
5
+ runScripts?: boolean;
6
+ /** Value of window.location.href inside the sandbox. Default: 'about:blank' */
7
+ url?: string;
8
+ /** Sets document.hidden = false. Default: false */
9
+ pretendToBeVisual?: boolean;
10
+ /**
11
+ * Callback invoked whenever console.log / warn / error / info / debug is called
12
+ * inside the sandbox. If not provided, console output is silently discarded.
13
+ */
14
+ onConsole?: (level: 'log' | 'warn' | 'error' | 'info' | 'debug', args: string[]) => void;
15
+ /**
16
+ * Callback invoked when `window.alert(message)` is called inside the sandbox.
17
+ * If not provided, alert() is a silent no-op (browser default when no UI is available).
18
+ *
19
+ * WARNING: The callback is synchronous. Do NOT call back into the same sandbox
20
+ * from inside the callback — QuickJS is not re-entrant.
21
+ */
22
+ onAlert?: (message: string) => void;
23
+ /**
24
+ * Callback invoked when `window.confirm(message)` is called inside the sandbox.
25
+ * Must return a boolean. If not provided, confirm() returns false (browser default).
26
+ *
27
+ * WARNING: The callback is synchronous. Do NOT call back into the same sandbox
28
+ * from inside the callback — QuickJS is not re-entrant.
29
+ */
30
+ onConfirm?: (message: string) => boolean;
31
+ /**
32
+ * Callback invoked when `window.prompt(message, defaultValue?)` is called inside
33
+ * the sandbox. Return a string for the user input, or null for a dismissed prompt.
34
+ * If not provided, prompt() returns null (browser default for dismissed prompts).
35
+ *
36
+ * WARNING: The callback is synchronous. Do NOT call back into the same sandbox
37
+ * from inside the callback — QuickJS is not re-entrant.
38
+ */
39
+ onPrompt?: (message: string, defaultValue?: string) => string | null;
40
+ /**
41
+ * Callback invoked when `fetch(url, init)` is called inside the sandbox.
42
+ * Receives the request and must resolve with the response. If not provided,
43
+ * `fetch()` inside the sandbox rejects with "fetch is not available".
44
+ *
45
+ * Typically wired to React Native's real `fetch()`:
46
+ * ```ts
47
+ * onFetch: async (url, init) => {
48
+ * const res = await fetch(url, init)
49
+ * return { status: res.status, statusText: res.statusText, headers: Object.fromEntries(res.headers), body: await res.text() }
50
+ * }
51
+ * ```
52
+ *
53
+ * WARNING: Do NOT call back into the same sandbox (`dom.evaluate()`) from inside
54
+ * this callback — QuickJS is not re-entrant.
55
+ */
56
+ onFetch?: (url: string, init: IFetchRequestInit) => Promise<IFetchResponseInit>;
57
+ }
@@ -0,0 +1,2 @@
1
+ export type * from './IJSDOMOptions';
2
+ export type * from './IFetchOptions';
@@ -0,0 +1 @@
1
+ export * from './JSDOM';
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './classes';
@@ -0,0 +1,33 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface HtmlSandbox extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
+ // Must be called once right after createHybridObject()
5
+ initialize(html: string, runScripts: boolean, url: string): void;
6
+
7
+ // Run arbitrary JS inside the QuickJS sandbox; returns the result as a string
8
+ evaluate(script: string): Promise<string>;
9
+
10
+ // Returns the current HTML of the document
11
+ serialize(): string;
12
+
13
+ // Set (or clear) the console output callback. Pass null to silence console output.
14
+ setConsoleCallback(callback: ((level: string, args: string[]) => void) | null): void;
15
+
16
+ // Set (or clear) the dialog callbacks for window.alert / confirm / prompt.
17
+ // Pass null for any callback to use the browser default (no-op / false / null).
18
+ setDialogCallbacks(
19
+ onAlert: ((message: string) => void) | null,
20
+ onConfirm: ((message: string) => boolean) | null,
21
+ onPrompt: ((message: string, defaultValue?: string) => string | null) | null,
22
+ ): void;
23
+
24
+ // Set (or clear) the fetch() bridge. Pass null to disable fetch() inside the sandbox
25
+ // (calling it will reject). The callback receives (url, method, headersJson, body) and
26
+ // must resolve with a JSON-encoded response: {ok, status, statusText, headersJson, body}.
27
+ // Declared as returning Promise<string> (not `string`) so Nitro's JSIConverter for
28
+ // Promise<T> properly chains `.then()` on the real async JS callback — a plain `string`
29
+ // return type is only auto-dispatched across threads, it does NOT await a returned Promise.
30
+ setFetchCallback(
31
+ callback: ((url: string, method: string, headersJson: string, body?: string) => Promise<string>) | null,
32
+ ): void;
33
+ }