@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.
- package/LICENSE +21 -0
- package/NitroJsdom.podspec +63 -0
- package/README.md +95 -0
- package/android/CMakeLists.txt +86 -0
- package/android/build.gradle +148 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/nitrojsdom/NitroJsdomPackage.kt +20 -0
- package/cpp/HybridHtmlSandbox.cpp +171 -0
- package/cpp/HybridHtmlSandbox.hpp +47 -0
- package/cpp/lexbor/LexborDocument.cpp +365 -0
- package/cpp/lexbor/LexborDocument.hpp +71 -0
- package/cpp/quickjs/DOMBindings.cpp +57 -0
- package/cpp/quickjs/DOMBindings.hpp +21 -0
- package/cpp/quickjs/DOMBindingsInternal.cpp +157 -0
- package/cpp/quickjs/DOMBindingsInternal.hpp +83 -0
- package/cpp/quickjs/MutationObservers.cpp +546 -0
- package/cpp/quickjs/MutationObservers.hpp +127 -0
- package/cpp/quickjs/QuickJSRuntime.cpp +475 -0
- package/cpp/quickjs/QuickJSRuntime.hpp +110 -0
- package/cpp/quickjs/Storage.cpp +130 -0
- package/cpp/quickjs/Storage.hpp +40 -0
- package/cpp/quickjs/bindings/ClassListBindings.cpp +241 -0
- package/cpp/quickjs/bindings/ClassListBindings.hpp +29 -0
- package/cpp/quickjs/bindings/DatasetBindings.cpp +120 -0
- package/cpp/quickjs/bindings/DatasetBindings.hpp +20 -0
- package/cpp/quickjs/bindings/DocumentBindings.cpp +155 -0
- package/cpp/quickjs/bindings/DocumentBindings.hpp +19 -0
- package/cpp/quickjs/bindings/ElementBindings.cpp +1106 -0
- package/cpp/quickjs/bindings/ElementBindings.hpp +19 -0
- package/cpp/quickjs/bindings/EventBindings.cpp +352 -0
- package/cpp/quickjs/bindings/EventBindings.hpp +21 -0
- package/cpp/quickjs/bindings/FetchBindings.cpp +347 -0
- package/cpp/quickjs/bindings/FetchBindings.hpp +16 -0
- package/cpp/quickjs/bindings/StyleBindings.cpp +245 -0
- package/cpp/quickjs/bindings/StyleBindings.hpp +22 -0
- package/cpp/quickjs/bindings/TimerBindings.cpp +94 -0
- package/cpp/quickjs/bindings/TimerBindings.hpp +16 -0
- package/cpp/quickjs/bindings/WindowBindings.cpp +211 -0
- package/cpp/quickjs/bindings/WindowBindings.hpp +16 -0
- package/ios/Bridge.h +8 -0
- package/lib/commonjs/classes/JSDOM/JSDOM.class.js +138 -0
- package/lib/commonjs/classes/JSDOM/JSDOM.class.js.map +1 -0
- package/lib/commonjs/classes/JSDOM/index.js +17 -0
- package/lib/commonjs/classes/JSDOM/index.js.map +1 -0
- package/lib/commonjs/classes/JSDOM/types/IFetchOptions.js +2 -0
- package/lib/commonjs/classes/JSDOM/types/IFetchOptions.js.map +1 -0
- package/lib/commonjs/classes/JSDOM/types/IJSDOMOptions.js +6 -0
- package/lib/commonjs/classes/JSDOM/types/IJSDOMOptions.js.map +1 -0
- package/lib/commonjs/classes/JSDOM/types/index.js +2 -0
- package/lib/commonjs/classes/JSDOM/types/index.js.map +1 -0
- package/lib/commonjs/classes/index.js +17 -0
- package/lib/commonjs/classes/index.js.map +1 -0
- package/lib/commonjs/index.js +17 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/HtmlSandbox.nitro.js +6 -0
- package/lib/commonjs/specs/HtmlSandbox.nitro.js.map +1 -0
- package/lib/module/classes/JSDOM/JSDOM.class.js +133 -0
- package/lib/module/classes/JSDOM/JSDOM.class.js.map +1 -0
- package/lib/module/classes/JSDOM/index.js +4 -0
- package/lib/module/classes/JSDOM/index.js.map +1 -0
- package/lib/module/classes/JSDOM/types/IFetchOptions.js +2 -0
- package/lib/module/classes/JSDOM/types/IFetchOptions.js.map +1 -0
- package/lib/module/classes/JSDOM/types/IJSDOMOptions.js +4 -0
- package/lib/module/classes/JSDOM/types/IJSDOMOptions.js.map +1 -0
- package/lib/module/classes/JSDOM/types/index.js +2 -0
- package/lib/module/classes/JSDOM/types/index.js.map +1 -0
- package/lib/module/classes/index.js +4 -0
- package/lib/module/classes/index.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/HtmlSandbox.nitro.js +4 -0
- package/lib/module/specs/HtmlSandbox.nitro.js.map +1 -0
- package/lib/typescript/src/classes/JSDOM/JSDOM.class.d.ts +74 -0
- package/lib/typescript/src/classes/JSDOM/JSDOM.class.d.ts.map +1 -0
- package/lib/typescript/src/classes/JSDOM/index.d.ts +3 -0
- package/lib/typescript/src/classes/JSDOM/index.d.ts.map +1 -0
- package/lib/typescript/src/classes/JSDOM/types/IFetchOptions.d.ts +14 -0
- package/lib/typescript/src/classes/JSDOM/types/IFetchOptions.d.ts.map +1 -0
- package/lib/typescript/src/classes/JSDOM/types/IJSDOMOptions.d.ts +57 -0
- package/lib/typescript/src/classes/JSDOM/types/IJSDOMOptions.d.ts.map +1 -0
- package/lib/typescript/src/classes/JSDOM/types/index.d.ts +3 -0
- package/lib/typescript/src/classes/JSDOM/types/index.d.ts.map +1 -0
- package/lib/typescript/src/classes/index.d.ts +2 -0
- package/lib/typescript/src/classes/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/HtmlSandbox.nitro.d.ts +13 -0
- package/lib/typescript/src/specs/HtmlSandbox.nitro.d.ts.map +1 -0
- package/nitro.json +26 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroJsdom+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroJsdom+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroJsdomOnLoad.cpp +49 -0
- package/nitrogen/generated/android/NitroJsdomOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrojsdom/NitroJsdomOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroJsdom+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/NitroJsdom-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/NitroJsdomAutolinking.mm +35 -0
- package/nitrogen/generated/ios/NitroJsdomAutolinking.swift +16 -0
- package/nitrogen/generated/shared/c++/HybridHtmlSandboxSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridHtmlSandboxSpec.hpp +73 -0
- package/package.json +131 -0
- package/src/classes/JSDOM/JSDOM.class.ts +145 -0
- package/src/classes/JSDOM/index.ts +2 -0
- package/src/classes/JSDOM/types/IFetchOptions.ts +14 -0
- package/src/classes/JSDOM/types/IJSDOMOptions.ts +57 -0
- package/src/classes/JSDOM/types/index.ts +2 -0
- package/src/classes/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/specs/HtmlSandbox.nitro.ts +33 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#include "DocumentBindings.hpp"
|
|
2
|
+
#include "../DOMBindingsInternal.hpp"
|
|
3
|
+
#include "../../lexbor/LexborDocument.hpp"
|
|
4
|
+
#include <cstring>
|
|
5
|
+
|
|
6
|
+
namespace margelo::nitro::nitrojsdom {
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
JSValue js_doc_getElementById(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
11
|
+
if (argc < 1) return JS_NULL;
|
|
12
|
+
const char* id = JS_ToCString(ctx, argv[0]);
|
|
13
|
+
if (!id) return JS_NULL;
|
|
14
|
+
void* el = get_doc(ctx)->getElementById(id);
|
|
15
|
+
JS_FreeCString(ctx, id);
|
|
16
|
+
return make_element(ctx, el);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
JSValue js_doc_querySelector(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
20
|
+
if (argc < 1) return JS_NULL;
|
|
21
|
+
const char* sel = JS_ToCString(ctx, argv[0]);
|
|
22
|
+
if (!sel) return JS_NULL;
|
|
23
|
+
void* el = get_doc(ctx)->querySelector_el(sel);
|
|
24
|
+
JS_FreeCString(ctx, sel);
|
|
25
|
+
return make_element(ctx, el);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
JSValue js_doc_querySelectorAll(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
29
|
+
if (argc < 1) return JS_NewArray(ctx);
|
|
30
|
+
const char* sel = JS_ToCString(ctx, argv[0]);
|
|
31
|
+
if (!sel) return JS_NewArray(ctx);
|
|
32
|
+
auto results = get_doc(ctx)->querySelectorAll_el(sel);
|
|
33
|
+
JS_FreeCString(ctx, sel);
|
|
34
|
+
return make_element_array(ctx, results);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
JSValue js_doc_getElementsByClassName(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
38
|
+
if (argc < 1) return JS_NewArray(ctx);
|
|
39
|
+
const char* names = JS_ToCString(ctx, argv[0]);
|
|
40
|
+
if (!names) return JS_NewArray(ctx);
|
|
41
|
+
auto results = get_doc(ctx)->querySelectorAll_el(classNames_to_selector(names));
|
|
42
|
+
JS_FreeCString(ctx, names);
|
|
43
|
+
return make_element_array(ctx, results);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
JSValue js_doc_getElementsByTagName(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
47
|
+
if (argc < 1) return JS_NewArray(ctx);
|
|
48
|
+
const char* tag = JS_ToCString(ctx, argv[0]);
|
|
49
|
+
if (!tag) return JS_NewArray(ctx);
|
|
50
|
+
auto results = get_doc(ctx)->querySelectorAll_el(tag);
|
|
51
|
+
JS_FreeCString(ctx, tag);
|
|
52
|
+
return make_element_array(ctx, results);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
JSValue js_doc_createElement(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
56
|
+
if (argc < 1) return JS_NULL;
|
|
57
|
+
const char* tag = JS_ToCString(ctx, argv[0]);
|
|
58
|
+
if (!tag) return JS_NULL;
|
|
59
|
+
void* el = get_doc(ctx)->createElement(tag);
|
|
60
|
+
JS_FreeCString(ctx, tag);
|
|
61
|
+
return make_element(ctx, el);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
JSValue js_doc_createTextNode(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
65
|
+
if (argc < 1) return JS_NULL;
|
|
66
|
+
const char* text = JS_ToCString(ctx, argv[0]);
|
|
67
|
+
if (!text) return JS_NULL;
|
|
68
|
+
void* node = get_doc(ctx)->createTextNode(text);
|
|
69
|
+
JS_FreeCString(ctx, text);
|
|
70
|
+
// Text nodes share the Element class so they can be passed to appendChild.
|
|
71
|
+
return make_element(ctx, node);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
JSValue js_doc_createComment(JSContext* ctx, JSValue, int argc, JSValue* argv) {
|
|
75
|
+
if (argc < 1) return JS_NULL;
|
|
76
|
+
const char* text = JS_ToCString(ctx, argv[0]);
|
|
77
|
+
if (!text) return JS_NULL;
|
|
78
|
+
void* node = get_doc(ctx)->createComment(text);
|
|
79
|
+
JS_FreeCString(ctx, text);
|
|
80
|
+
return make_element(ctx, node);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
JSValue js_doc_createDocumentFragment(JSContext* ctx, JSValue, int, JSValue*) {
|
|
84
|
+
return make_element(ctx, get_doc(ctx)->createDocumentFragment());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
JSValue js_doc_get_body(JSContext* ctx, JSValue) {
|
|
88
|
+
return make_element(ctx, get_doc(ctx)->body());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
JSValue js_doc_get_head(JSContext* ctx, JSValue) {
|
|
92
|
+
return make_element(ctx, get_doc(ctx)->head());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
JSValue js_doc_get_documentElement(JSContext* ctx, JSValue) {
|
|
96
|
+
return make_element(ctx, get_doc(ctx)->documentElement());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const char* kDocumentTitleBootstrapScript = R"JS(
|
|
100
|
+
(function() {
|
|
101
|
+
Object.defineProperty(document, 'title', {
|
|
102
|
+
get: function() {
|
|
103
|
+
var head = document.head;
|
|
104
|
+
if (!head) return '';
|
|
105
|
+
var titleEl = head.querySelector('title');
|
|
106
|
+
return titleEl ? titleEl.textContent : '';
|
|
107
|
+
},
|
|
108
|
+
set: function(value) {
|
|
109
|
+
var head = document.head;
|
|
110
|
+
if (!head) return;
|
|
111
|
+
var titleEl = head.querySelector('title');
|
|
112
|
+
if (!titleEl) {
|
|
113
|
+
titleEl = document.createElement('title');
|
|
114
|
+
head.appendChild(titleEl);
|
|
115
|
+
}
|
|
116
|
+
titleEl.textContent = String(value);
|
|
117
|
+
},
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
});
|
|
121
|
+
})();
|
|
122
|
+
)JS";
|
|
123
|
+
|
|
124
|
+
} // namespace
|
|
125
|
+
|
|
126
|
+
void DocumentBindings::install(JSContext* ctx) {
|
|
127
|
+
JSValue global = JS_GetGlobalObject(ctx);
|
|
128
|
+
JSValue doc = JS_NewObject(ctx);
|
|
129
|
+
|
|
130
|
+
JS_SetPropertyStr(ctx, doc, "getElementById", JS_NewCFunction(ctx, js_doc_getElementById, "getElementById", 1));
|
|
131
|
+
JS_SetPropertyStr(ctx, doc, "querySelector", JS_NewCFunction(ctx, js_doc_querySelector, "querySelector", 1));
|
|
132
|
+
JS_SetPropertyStr(ctx, doc, "querySelectorAll", JS_NewCFunction(ctx, js_doc_querySelectorAll, "querySelectorAll", 1));
|
|
133
|
+
JS_SetPropertyStr(ctx, doc, "getElementsByClassName", JS_NewCFunction(ctx, js_doc_getElementsByClassName, "getElementsByClassName", 1));
|
|
134
|
+
JS_SetPropertyStr(ctx, doc, "getElementsByTagName", JS_NewCFunction(ctx, js_doc_getElementsByTagName, "getElementsByTagName", 1));
|
|
135
|
+
JS_SetPropertyStr(ctx, doc, "createElement", JS_NewCFunction(ctx, js_doc_createElement, "createElement", 1));
|
|
136
|
+
JS_SetPropertyStr(ctx, doc, "createTextNode", JS_NewCFunction(ctx, js_doc_createTextNode, "createTextNode", 1));
|
|
137
|
+
JS_SetPropertyStr(ctx, doc, "createComment", JS_NewCFunction(ctx, js_doc_createComment, "createComment", 1));
|
|
138
|
+
JS_SetPropertyStr(ctx, doc, "createDocumentFragment", JS_NewCFunction(ctx, js_doc_createDocumentFragment, "createDocumentFragment", 0));
|
|
139
|
+
|
|
140
|
+
define_prop(ctx, doc, "body", js_doc_get_body, nullptr);
|
|
141
|
+
define_prop(ctx, doc, "head", js_doc_get_head, nullptr);
|
|
142
|
+
define_prop(ctx, doc, "documentElement", js_doc_get_documentElement, nullptr);
|
|
143
|
+
|
|
144
|
+
JS_SetPropertyStr(ctx, global, "document", doc);
|
|
145
|
+
JS_FreeValue(ctx, global);
|
|
146
|
+
|
|
147
|
+
JSValue title_result = JS_Eval(ctx, kDocumentTitleBootstrapScript, strlen(kDocumentTitleBootstrapScript),
|
|
148
|
+
"<document-title-bootstrap>", JS_EVAL_TYPE_GLOBAL);
|
|
149
|
+
if (JS_IsException(title_result)) {
|
|
150
|
+
JS_FreeValue(ctx, JS_GetException(ctx));
|
|
151
|
+
}
|
|
152
|
+
JS_FreeValue(ctx, title_result);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} // namespace margelo::nitro::nitrojsdom
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Creates globalThis.document and attaches its non-event methods/properties:
|
|
4
|
+
// getElementById, querySelector(All), getElementsBy{ClassName,TagName},
|
|
5
|
+
// createElement, createTextNode, body/head/documentElement, and document.title.
|
|
6
|
+
//
|
|
7
|
+
// EventBindings::install() runs afterwards and attaches
|
|
8
|
+
// addEventListener/dispatchEvent onto the same `document` object.
|
|
9
|
+
|
|
10
|
+
#include "quickjs.h"
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::nitrojsdom {
|
|
13
|
+
|
|
14
|
+
class DocumentBindings {
|
|
15
|
+
public:
|
|
16
|
+
static void install(JSContext* ctx);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace margelo::nitro::nitrojsdom
|