chemicaljs 1.9.0 → 2.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/client/chemical.components.js +63 -14
- package/client/chemical.js +69 -14
- package/index.js +25 -22
- package/package.json +1 -1
|
@@ -4,10 +4,23 @@ class ChemicalInput extends HTMLInputElement {
|
|
|
4
4
|
}
|
|
5
5
|
connectedCallback() {
|
|
6
6
|
this.addEventListener("keydown", async function (e) {
|
|
7
|
-
if (e.key
|
|
8
|
-
let service =
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
if (e.key === "Enter" && window.chemical.loaded && e.target.value) {
|
|
8
|
+
let service =
|
|
9
|
+
this.dataset.serviceStore !== undefined
|
|
10
|
+
? localStorage.getItem("@chemical/service") ||
|
|
11
|
+
this.dataset.service ||
|
|
12
|
+
"uv"
|
|
13
|
+
: this.dataset.service || "uv";
|
|
14
|
+
let autoHttps =
|
|
15
|
+
this.dataset.autoHttpsStore !== undefined
|
|
16
|
+
? localStorage.getItem("@chemical/autoHttps") === "true"
|
|
17
|
+
: this.dataset.autoHttps !== undefined
|
|
18
|
+
? true
|
|
19
|
+
: false;
|
|
20
|
+
let searchEngine =
|
|
21
|
+
this.dataset.searchEngineStore !== undefined
|
|
22
|
+
? localStorage.getItem("@chemical/searchEngine")
|
|
23
|
+
: this.dataset.searchEngine;
|
|
11
24
|
let action = this.dataset.action;
|
|
12
25
|
let target = this.dataset.target;
|
|
13
26
|
let frame = this.dataset.frame;
|
|
@@ -28,9 +41,9 @@ class ChemicalInput extends HTMLInputElement {
|
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
if (target) {
|
|
31
|
-
if (target
|
|
44
|
+
if (target === "_self") {
|
|
32
45
|
window.location = encodedURL;
|
|
33
|
-
} else if (target
|
|
46
|
+
} else if (target === "_blank") {
|
|
34
47
|
window.open(encodedURL);
|
|
35
48
|
}
|
|
36
49
|
}
|
|
@@ -65,12 +78,12 @@ class ChemicalIFrame extends HTMLIFrameElement {
|
|
|
65
78
|
}
|
|
66
79
|
connectedCallback() {
|
|
67
80
|
let open = this.dataset.open;
|
|
68
|
-
this.style.display = open
|
|
81
|
+
this.style.display = open === "true" ? "" : "none";
|
|
69
82
|
}
|
|
70
83
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
71
|
-
if (name
|
|
84
|
+
if (name === "data-open") {
|
|
72
85
|
let open = this.dataset.open;
|
|
73
|
-
this.style.display = open
|
|
86
|
+
this.style.display = open === "true" ? "" : "none";
|
|
74
87
|
|
|
75
88
|
let controls = document.getElementById(this.dataset.controls);
|
|
76
89
|
|
|
@@ -88,12 +101,12 @@ class ChemicalControls extends HTMLElement {
|
|
|
88
101
|
}
|
|
89
102
|
connectedCallback() {
|
|
90
103
|
let open = this.dataset.open;
|
|
91
|
-
this.style.display = open
|
|
104
|
+
this.style.display = open === "true" ? "" : "none";
|
|
92
105
|
}
|
|
93
106
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
94
|
-
if (name
|
|
107
|
+
if (name === "data-open") {
|
|
95
108
|
let open = this.dataset.open;
|
|
96
|
-
this.style.display = open
|
|
109
|
+
this.style.display = open === "true" ? "" : "none";
|
|
97
110
|
}
|
|
98
111
|
}
|
|
99
112
|
}
|
|
@@ -135,6 +148,41 @@ class ChemicalLink extends HTMLAnchorElement {
|
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
150
|
|
|
151
|
+
class ChemicalSelect extends HTMLSelectElement {
|
|
152
|
+
constructor() {
|
|
153
|
+
super();
|
|
154
|
+
}
|
|
155
|
+
connectedCallback() {
|
|
156
|
+
const store = this.dataset.defaultStore;
|
|
157
|
+
|
|
158
|
+
this.addEventListener("change", function () {
|
|
159
|
+
window.chemical.setStore(store, this.value);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (store) {
|
|
163
|
+
const value = window.chemical.getStore(store);
|
|
164
|
+
|
|
165
|
+
const observerOptions = {
|
|
166
|
+
childList: true,
|
|
167
|
+
subtree: false,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const observer = new MutationObserver((records, observer) => {
|
|
171
|
+
for (const record of records) {
|
|
172
|
+
for (const addedNode of record.addedNodes) {
|
|
173
|
+
if (addedNode.tagName === "OPTION") {
|
|
174
|
+
if (addedNode.getAttribute("value") === value) {
|
|
175
|
+
addedNode.setAttribute("selected", "");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
observer.observe(this, observerOptions);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
138
186
|
customElements.define("chemical-input", ChemicalInput, { extends: "input" });
|
|
139
187
|
customElements.define("chemical-button", ChemicalButton, { extends: "button" });
|
|
140
188
|
customElements.define("chemical-iframe", ChemicalIFrame, { extends: "iframe" });
|
|
@@ -142,8 +190,9 @@ customElements.define("chemical-controls", ChemicalControls, {
|
|
|
142
190
|
extends: "section",
|
|
143
191
|
});
|
|
144
192
|
customElements.define("chemical-link", ChemicalLink, { extends: "a" });
|
|
193
|
+
customElements.define("chemical-select", ChemicalSelect, { extends: "select" });
|
|
145
194
|
|
|
146
|
-
function
|
|
195
|
+
window.chemical.componentAction = function (action, frameID) {
|
|
147
196
|
let frame = document.getElementById(frameID);
|
|
148
197
|
|
|
149
198
|
if (frame) {
|
|
@@ -162,4 +211,4 @@ function chemicalAction(action, frameID) {
|
|
|
162
211
|
frame.src = "";
|
|
163
212
|
}
|
|
164
213
|
}
|
|
165
|
-
}
|
|
214
|
+
};
|
package/client/chemical.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
const currentScript = document.currentScript;
|
|
2
|
+
|
|
1
3
|
window.chemical = {
|
|
2
4
|
loaded: false,
|
|
3
|
-
transport:
|
|
5
|
+
transport:
|
|
6
|
+
currentScript.dataset.transportStore !== undefined
|
|
7
|
+
? localStorage.getItem("@chemical/transport") ||
|
|
8
|
+
currentScript.dataset.transport ||
|
|
9
|
+
"libcurl"
|
|
10
|
+
: currentScript.dataset.transport || "libcurl",
|
|
4
11
|
wisp:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
currentScript.dataset.wispStore !== undefined
|
|
13
|
+
? localStorage.getItem("@chemical/wisp") ||
|
|
14
|
+
currentScript.dataset.wisp ||
|
|
15
|
+
(location.protocol === "https:" ? "wss" : "ws") +
|
|
16
|
+
"://" +
|
|
17
|
+
location.host +
|
|
18
|
+
"/wisp/"
|
|
19
|
+
: currentScript.dataset.wisp ||
|
|
20
|
+
(location.protocol === "https:" ? "wss" : "ws") +
|
|
21
|
+
"://" +
|
|
22
|
+
location.host +
|
|
23
|
+
"/wisp/",
|
|
10
24
|
};
|
|
11
25
|
|
|
12
26
|
function rammerheadEncode(baseUrl, decode = false) {
|
|
@@ -242,18 +256,18 @@ window.chemical.encode = async function (url, config) {
|
|
|
242
256
|
};
|
|
243
257
|
}
|
|
244
258
|
|
|
245
|
-
if (config.service
|
|
259
|
+
if (config.service === undefined) {
|
|
246
260
|
config.service = defaultService;
|
|
247
261
|
}
|
|
248
262
|
|
|
249
|
-
if (config.autoHttps
|
|
263
|
+
if (config.autoHttps === undefined) {
|
|
250
264
|
config.autoHttps = false;
|
|
251
265
|
}
|
|
252
266
|
|
|
253
267
|
if (url.match(/^https?:\/\//)) {
|
|
254
268
|
return await encodeService(url, config.service);
|
|
255
269
|
} else if (
|
|
256
|
-
config.autoHttps
|
|
270
|
+
config.autoHttps === true &&
|
|
257
271
|
url.includes(".") &&
|
|
258
272
|
!url.includes(" ")
|
|
259
273
|
) {
|
|
@@ -304,6 +318,41 @@ window.chemical.decode = async function (url, config) {
|
|
|
304
318
|
}
|
|
305
319
|
};
|
|
306
320
|
|
|
321
|
+
window.chemical.setStore = function (key, value) {
|
|
322
|
+
const allowed = ["transport", "wisp", "service", "autoHttps", "searchEngine"];
|
|
323
|
+
|
|
324
|
+
if (allowed.includes(key)) {
|
|
325
|
+
localStorage.setItem("@chemical/" + key, String(value));
|
|
326
|
+
if (key === "transport") {
|
|
327
|
+
window.chemical.setTransport(value);
|
|
328
|
+
}
|
|
329
|
+
if (key === "wisp") {
|
|
330
|
+
window.chemical.setWisp(value);
|
|
331
|
+
}
|
|
332
|
+
window.dispatchEvent(
|
|
333
|
+
new CustomEvent("chemicalStoreChange", {
|
|
334
|
+
detail: { key, value },
|
|
335
|
+
})
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
window.chemical.getStore = function (key) {
|
|
341
|
+
const value =
|
|
342
|
+
key === "autoHttps"
|
|
343
|
+
? localStorage.getItem("@chemical/" + key) === "true"
|
|
344
|
+
: localStorage.getItem("@chemical/" + key);
|
|
345
|
+
|
|
346
|
+
const defaults = {
|
|
347
|
+
transport: window.chemical.transport,
|
|
348
|
+
wisp: window.chemical.wisp,
|
|
349
|
+
service: "uv",
|
|
350
|
+
autoHttps: false,
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
return value || defaults[key];
|
|
354
|
+
};
|
|
355
|
+
|
|
307
356
|
function getTransport(transport) {
|
|
308
357
|
switch (transport) {
|
|
309
358
|
default:
|
|
@@ -316,16 +365,22 @@ function getTransport(transport) {
|
|
|
316
365
|
}
|
|
317
366
|
}
|
|
318
367
|
|
|
319
|
-
window.chemical.setTransport = async function (
|
|
320
|
-
newTransport =
|
|
321
|
-
) {
|
|
368
|
+
window.chemical.setTransport = async function (newTransport) {
|
|
369
|
+
newTransport = newTransport || currentScript.dataset.transport || "libcurl";
|
|
322
370
|
await window.chemical.connection.setTransport(getTransport(newTransport), [
|
|
323
371
|
{ wisp: window.chemical.wisp },
|
|
324
372
|
]);
|
|
325
373
|
window.chemical.transport = newTransport;
|
|
326
374
|
};
|
|
327
375
|
|
|
328
|
-
window.chemical.setWisp = async function (wisp
|
|
376
|
+
window.chemical.setWisp = async function (wisp) {
|
|
377
|
+
wisp =
|
|
378
|
+
wisp ||
|
|
379
|
+
currentScript.dataset.wisp ||
|
|
380
|
+
(location.protocol === "https:" ? "wss" : "ws") +
|
|
381
|
+
"://" +
|
|
382
|
+
location.host +
|
|
383
|
+
"/wisp/";
|
|
329
384
|
await window.chemical.connection.setTransport(
|
|
330
385
|
getTransport(window.chemical.transport),
|
|
331
386
|
[{ wisp: wisp }]
|
|
@@ -411,7 +466,7 @@ if (meteorEnabled) {
|
|
|
411
466
|
window.chemical.connection = new window.BareMux.BareMuxConnection(
|
|
412
467
|
"/baremux/worker.js"
|
|
413
468
|
);
|
|
414
|
-
await window.chemical.setTransport();
|
|
469
|
+
await window.chemical.setTransport(window.chemical.transport);
|
|
415
470
|
setupFetch();
|
|
416
471
|
await registerSW();
|
|
417
472
|
window.chemical.loaded = true;
|
package/index.js
CHANGED
|
@@ -40,23 +40,23 @@ class ChemicalServer {
|
|
|
40
40
|
options = {};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if (options.uv
|
|
43
|
+
if (options.uv === undefined) {
|
|
44
44
|
options.uv = true;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (options.experimental
|
|
48
|
-
options.experimental = {}
|
|
47
|
+
if (options.experimental === undefined) {
|
|
48
|
+
options.experimental = {};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
if (options.experimental.scramjet
|
|
51
|
+
if (options.experimental.scramjet === undefined) {
|
|
52
52
|
options.experimental.scramjet = false;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
if (options.experimental.meteor
|
|
55
|
+
if (options.experimental.meteor === undefined) {
|
|
56
56
|
options.experimental.meteor = false;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (options.rammerhead
|
|
59
|
+
if (options.rammerhead === undefined) {
|
|
60
60
|
options.rammerhead = true;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -178,7 +178,7 @@ class ChemicalServer {
|
|
|
178
178
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
179
179
|
if (this.options.wispOptions) {
|
|
180
180
|
for (let option in this.options.wispOptions) {
|
|
181
|
-
wisp.options[option] = this.options.wispOptions[option]
|
|
181
|
+
wisp.options[option] = this.options.wispOptions[option];
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
wisp.routeRequest(req, socket, head);
|
|
@@ -206,23 +206,23 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
206
206
|
options = {};
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
if (options.uv
|
|
209
|
+
if (options.uv === undefined) {
|
|
210
210
|
options.uv = true;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
if (options.experimental
|
|
214
|
-
options.experimental = {}
|
|
213
|
+
if (options.experimental === undefined) {
|
|
214
|
+
options.experimental = {};
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
if (options.experimental.scramjet
|
|
217
|
+
if (options.experimental.scramjet === undefined) {
|
|
218
218
|
options.experimental.scramjet = false;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
if (options.experimental.meteor
|
|
221
|
+
if (options.experimental.meteor === undefined) {
|
|
222
222
|
options.experimental.meteor = false;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
if (options.rammerhead
|
|
225
|
+
if (options.rammerhead === undefined) {
|
|
226
226
|
options.rammerhead = true;
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -288,7 +288,10 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
288
288
|
";\n" +
|
|
289
289
|
chemicalSW;
|
|
290
290
|
chemicalSW =
|
|
291
|
-
"const meteorEnabled = " +
|
|
291
|
+
"const meteorEnabled = " +
|
|
292
|
+
String(options.experimental.meteor) +
|
|
293
|
+
";\n" +
|
|
294
|
+
chemicalSW;
|
|
292
295
|
chemicalSW =
|
|
293
296
|
"const rammerheadEnabled = " +
|
|
294
297
|
String(options.rammerhead) +
|
|
@@ -338,7 +341,7 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
338
341
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
339
342
|
if (options.wispOptions) {
|
|
340
343
|
for (let option in options.wispOptions) {
|
|
341
|
-
wisp.options[option] = options.wispOptions[option]
|
|
344
|
+
wisp.options[option] = options.wispOptions[option];
|
|
342
345
|
}
|
|
343
346
|
}
|
|
344
347
|
wisp.routeRequest(req, socket, head);
|
|
@@ -364,7 +367,7 @@ class ChemicalBuild {
|
|
|
364
367
|
options = {};
|
|
365
368
|
}
|
|
366
369
|
|
|
367
|
-
if (options.path
|
|
370
|
+
if (options.path === undefined) {
|
|
368
371
|
options.path = "dist";
|
|
369
372
|
}
|
|
370
373
|
|
|
@@ -376,23 +379,23 @@ class ChemicalBuild {
|
|
|
376
379
|
options.path = options.path.slice(0, -1);
|
|
377
380
|
}
|
|
378
381
|
|
|
379
|
-
if (options.uv
|
|
382
|
+
if (options.uv === undefined) {
|
|
380
383
|
options.uv = true;
|
|
381
384
|
}
|
|
382
385
|
|
|
383
|
-
if (options.experimental
|
|
384
|
-
options.experimental = {}
|
|
386
|
+
if (options.experimental === undefined) {
|
|
387
|
+
options.experimental = {};
|
|
385
388
|
}
|
|
386
389
|
|
|
387
|
-
if (options.experimental.scramjet
|
|
390
|
+
if (options.experimental.scramjet === undefined) {
|
|
388
391
|
options.experimental.scramjet = false;
|
|
389
392
|
}
|
|
390
393
|
|
|
391
|
-
if (options.experimental.meteor
|
|
394
|
+
if (options.experimental.meteor === undefined) {
|
|
392
395
|
options.experimental.meteor = false;
|
|
393
396
|
}
|
|
394
397
|
|
|
395
|
-
if (options.rammerhead
|
|
398
|
+
if (options.rammerhead === undefined) {
|
|
396
399
|
options.rammerhead = true;
|
|
397
400
|
}
|
|
398
401
|
|