chemicaljs 2.1.1 → 2.3.1

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.
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Demo Site</title>
7
+ <style>
8
+ *,
9
+ *::before,
10
+ *::after {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ margin: 0;
16
+ min-height: 100vh;
17
+ display: flex;
18
+ flex-direction: column;
19
+ justify-content: center;
20
+ align-items: center;
21
+ font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
22
+ "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
23
+ background: #e5e5e5;
24
+ color: black;
25
+ }
26
+
27
+ @media (prefers-color-scheme: dark) {
28
+ body {
29
+ background: #0a0a0a;
30
+ color: #fafafa;
31
+ }
32
+ }
33
+
34
+ h1 {
35
+ margin: 0;
36
+ }
37
+ </style>
38
+ </head>
39
+ <body>
40
+ <h1>Demo Site</h1>
41
+ <p>This is a demo site without proxy functionality.</p>
42
+ </body>
43
+ </html>
@@ -2,6 +2,7 @@ const currentScript = document.currentScript;
2
2
 
3
3
  window.chemical = {
4
4
  loaded: false,
5
+ demoMode,
5
6
  transport:
6
7
  currentScript.dataset.transportStore !== undefined
7
8
  ? localStorage.getItem("@chemical/transport") ||
@@ -229,20 +230,7 @@ async function encodeService(url, service) {
229
230
  break;
230
231
  case "scramjet":
231
232
  if (scramjetEnabled) {
232
- return (
233
- window.location.origin +
234
- __scramjet$config.prefix +
235
- __scramjet$config.codec.encode(url)
236
- );
237
- }
238
- break;
239
- case "meteor":
240
- if (meteorEnabled) {
241
- return (
242
- window.location.origin +
243
- $meteor_config.prefix +
244
- $meteor_config.codec.encode(url)
245
- );
233
+ return window.location.origin + chemical.scramjet.encodeUrl(url);
246
234
  }
247
235
  break;
248
236
  }
@@ -264,6 +252,10 @@ window.chemical.encode = async function (url, config) {
264
252
  config.autoHttps = false;
265
253
  }
266
254
 
255
+ if (demoMode) {
256
+ return "/chemical.demo.html";
257
+ }
258
+
267
259
  if (url.match(/^https?:\/\//)) {
268
260
  return await encodeService(url, config.service);
269
261
  } else if (
@@ -305,14 +297,7 @@ window.chemical.decode = async function (url, config) {
305
297
  break;
306
298
  case "scramjet":
307
299
  if (scramjetEnabled) {
308
- return __scramjet$config.codec.decode(
309
- url.split(__scramjet$config.prefix)[1]
310
- );
311
- }
312
- break;
313
- case "meteor":
314
- if (meteorEnabled) {
315
- return $meteor_config.codec.decode(url.split($meteor_config.prefix)[1]);
300
+ return $scramjet.codec.decode(url.split($scramjet.config.prefix)[1]);
316
301
  }
317
302
  break;
318
303
  }
@@ -456,12 +441,19 @@ if (uvEnabled) {
456
441
  await loadScript("/uv/uv.config.js");
457
442
  }
458
443
  if (scramjetEnabled) {
459
- await loadScript("/scramjet/scramjet.codecs.js");
460
- await loadScript("/scramjet/scramjet.config.js");
461
- }
462
- if (meteorEnabled) {
463
- await loadScript("/meteor/meteor.codecs.js");
464
- await loadScript("/meteor/meteor.config.js");
444
+ await loadScript("/scramjet/scramjet.shared.js");
445
+ await loadScript("/scramjet/scramjet.controller.js");
446
+ chemical.scramjet = new ScramjetController({
447
+ prefix: "/~/scramjet/",
448
+ files: {
449
+ wasm: "/scramjet/scramjet.wasm.js",
450
+ worker: "/scramjet/scramjet.worker.js",
451
+ client: "/scramjetetscramjet.client.js",
452
+ shared: "/scramjetetscramjet.shared.js",
453
+ sync: "/scramjet/scramjet.sync.js",
454
+ },
455
+ });
456
+ chemical.scramjet.init("/chemical.sw.js");
465
457
  }
466
458
  window.chemical.connection = new window.BareMux.BareMuxConnection(
467
459
  "/baremux/worker.js"
@@ -4,21 +4,19 @@ if (uvEnabled) {
4
4
  importScripts(__uv$config.sw || "/uv/uv.sw.js");
5
5
  }
6
6
  if (scramjetEnabled) {
7
- importScripts("/scramjet/scramjet.codecs.js");
8
- importScripts("/scramjet/scramjet.config.js");
9
- importScripts(__scramjet$config.bundle || "/scramjet/scramjet.bundle.js");
10
- importScripts(__scramjet$config.worker || "/scramjet/scramjet.worker.js");
11
- }
12
- if (meteorEnabled) {
13
- importScripts("/meteor/meteor.codecs.js");
14
- importScripts("/meteor/meteor.config.js");
15
- importScripts($meteor_config.files.bundle || "/meteor/meteor.bundle.js");
16
- importScripts($meteor_config.files.worker || "/meteor/meteor.worker.js");
7
+ importScripts("/scramjet/scramjet.wasm.js");
8
+ importScripts("/scramjet/scramjet.shared.js");
9
+ importScripts("/scramjet/scramjet.worker.js");
17
10
  }
18
11
 
19
- Object.defineProperty(self, "crossOriginIsolated", { value: true }); // Firefox fix
12
+ if (navigator.userAgent.includes("Firefox")) {
13
+ Object.defineProperty(globalThis, "crossOriginIsolated", {
14
+ value: true,
15
+ writable: false,
16
+ });
17
+ }
20
18
 
21
- let uv, scramjet, meteor;
19
+ let uv, scramjet;
22
20
 
23
21
  if (uvEnabled) {
24
22
  uv = new UVServiceWorker();
@@ -26,19 +24,18 @@ if (uvEnabled) {
26
24
  if (scramjetEnabled) {
27
25
  scramjet = new ScramjetServiceWorker();
28
26
  }
29
- if (meteorEnabled) {
30
- meteor = new MeteorServiceWorker();
31
- }
32
27
 
33
28
  self.addEventListener("fetch", (event) => {
34
29
  event.respondWith(
35
30
  (async () => {
31
+ if (scramjetEnabled) {
32
+ await scramjet.loadConfig();
33
+ }
34
+
36
35
  if (uvEnabled && uv.route(event)) {
37
36
  return await uv.fetch(event);
38
37
  } else if (scramjetEnabled && scramjet.route(event)) {
39
38
  return await scramjet.fetch(event);
40
- } else if (meteorEnabled && meteor.shouldRoute(event)) {
41
- return meteor.handleFetch(event);
42
39
  }
43
40
  return await fetch(event.request);
44
41
  })()
package/index.js CHANGED
@@ -17,8 +17,7 @@ import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
17
17
  import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
18
18
  import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
19
19
  import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
20
- import { scramjetPath } from "@mercuryworkshop/scramjet";
21
- import { meteorPath } from "meteorproxy";
20
+ import { scramjetPath } from "./scramjet/index.js";
22
21
  import createRammerhead from "rammerhead/src/server/index.js";
23
22
  const __dirname = dirname(fileURLToPath(import.meta.url));
24
23
 
@@ -39,22 +38,18 @@ class ChemicalServer {
39
38
  options.uv = true;
40
39
  }
41
40
 
42
- if (options.experimental === undefined) {
43
- options.experimental = {};
44
- }
45
-
46
- if (options.experimental.scramjet === undefined) {
47
- options.experimental.scramjet = false;
48
- }
49
-
50
- if (options.experimental.meteor === undefined) {
51
- options.experimental.meteor = false;
41
+ if (options.scramjet === undefined) {
42
+ options.scramjet = true;
52
43
  }
53
44
 
54
45
  if (options.rammerhead === undefined) {
55
46
  options.rammerhead = true;
56
47
  }
57
48
 
49
+ if (options.demoMode === undefined) {
50
+ options.demoMode = false;
51
+ }
52
+
58
53
  this.options = options;
59
54
  this.server = createServer();
60
55
  this.app = express();
@@ -102,11 +97,7 @@ class ChemicalServer {
102
97
  );
103
98
 
104
99
  if (this.options.default) {
105
- if (
106
- ["uv", "rammerhead", "scramjet", "meteor"].includes(
107
- this.options.default
108
- )
109
- ) {
100
+ if (["uv", "rammerhead", "scramjet"].includes(this.options.default)) {
110
101
  chemicalMain =
111
102
  `const defaultService = "${this.options.default}";\n\n` +
112
103
  chemicalMain;
@@ -122,17 +113,17 @@ class ChemicalServer {
122
113
  "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalMain;
123
114
  chemicalMain =
124
115
  "const scramjetEnabled = " +
125
- String(this.options.experimental.scramjet) +
116
+ String(this.options.scramjet) +
126
117
  ";\n" +
127
118
  chemicalMain;
128
119
  chemicalMain =
129
- "const meteorEnabled = " +
130
- String(this.options.experimental.meteor) +
120
+ "const rammerheadEnabled = " +
121
+ String(this.options.rammerhead) +
131
122
  ";\n" +
132
123
  chemicalMain;
133
124
  chemicalMain =
134
- "const rammerheadEnabled = " +
135
- String(this.options.rammerhead) +
125
+ "const demoMode = " +
126
+ String(this.options.demoMode) +
136
127
  ";\n" +
137
128
  chemicalMain;
138
129
 
@@ -151,12 +142,7 @@ class ChemicalServer {
151
142
  "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalSW;
152
143
  chemicalSW =
153
144
  "const scramjetEnabled = " +
154
- String(this.options.experimental.scramjet) +
155
- ";\n" +
156
- chemicalSW;
157
- chemicalSW =
158
- "const meteorEnabled = " +
159
- String(this.options.experimental.meteor) +
145
+ String(this.options.scramjet) +
160
146
  ";\n" +
161
147
  chemicalSW;
162
148
  chemicalSW =
@@ -176,20 +162,9 @@ class ChemicalServer {
176
162
  this.app.use("/uv/", express.static(resolve(__dirname, "config/uv")));
177
163
  this.app.use("/uv/", express.static(uvPath));
178
164
  }
179
- if (this.options.experimental.scramjet) {
180
- this.app.use(
181
- "/scramjet/",
182
- express.static(resolve(__dirname, "config/scramjet"))
183
- );
165
+ if (this.options.scramjet) {
184
166
  this.app.use("/scramjet/", express.static(scramjetPath));
185
167
  }
186
- if (this.options.experimental.meteor) {
187
- this.app.use(
188
- "/meteor/",
189
- express.static(resolve(__dirname, "config/meteor"))
190
- );
191
- this.app.use("/meteor/", express.static(meteorPath));
192
- }
193
168
  this.server.on("request", (req, res) => {
194
169
  if (this.options.rammerhead && shouldRouteRh(req)) {
195
170
  routeRhRequest(req, res);
@@ -233,22 +208,18 @@ const ChemicalVitePlugin = (options) => ({
233
208
  options.uv = true;
234
209
  }
235
210
 
236
- if (options.experimental === undefined) {
237
- options.experimental = {};
238
- }
239
-
240
- if (options.experimental.scramjet === undefined) {
241
- options.experimental.scramjet = false;
242
- }
243
-
244
- if (options.experimental.meteor === undefined) {
245
- options.experimental.meteor = false;
211
+ if (options.scramjet === undefined) {
212
+ options.scramjet = true;
246
213
  }
247
214
 
248
215
  if (options.rammerhead === undefined) {
249
216
  options.rammerhead = true;
250
217
  }
251
218
 
219
+ if (options.demoMode === undefined) {
220
+ options.demoMode = false;
221
+ }
222
+
252
223
  const rh = createRammerhead();
253
224
  const rammerheadScopes = [
254
225
  "/rammerhead.js",
@@ -289,9 +260,7 @@ const ChemicalVitePlugin = (options) => ({
289
260
  );
290
261
 
291
262
  if (options.default) {
292
- if (
293
- ["uv", "rammerhead", "scramjet", "meteor"].includes(options.default)
294
- ) {
263
+ if (["uv", "rammerhead", "scramjet"].includes(options.default)) {
295
264
  chemicalMain =
296
265
  `const defaultService = "${options.default}";\n\n` + chemicalMain;
297
266
  } else {
@@ -306,12 +275,7 @@ const ChemicalVitePlugin = (options) => ({
306
275
  "const uvEnabled = " + String(options.uv) + ";\n" + chemicalMain;
307
276
  chemicalMain =
308
277
  "const scramjetEnabled = " +
309
- String(options.experimental.scramjet) +
310
- ";\n" +
311
- chemicalMain;
312
- chemicalMain =
313
- "const meteorEnabled = " +
314
- String(options.experimental.meteor) +
278
+ String(options.scramjet) +
315
279
  ";\n" +
316
280
  chemicalMain;
317
281
  chemicalMain =
@@ -319,6 +283,8 @@ const ChemicalVitePlugin = (options) => ({
319
283
  String(options.rammerhead) +
320
284
  ";\n" +
321
285
  chemicalMain;
286
+ chemicalMain =
287
+ "const demoMode = " + String(options.demoMode) + ";\n" + chemicalMain;
322
288
 
323
289
  chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
324
290
 
@@ -335,12 +301,7 @@ const ChemicalVitePlugin = (options) => ({
335
301
  "const uvEnabled = " + String(options.uv) + ";\n" + chemicalSW;
336
302
  chemicalSW =
337
303
  "const scramjetEnabled = " +
338
- String(options.experimental.scramjet) +
339
- ";\n" +
340
- chemicalSW;
341
- chemicalSW =
342
- "const meteorEnabled = " +
343
- String(options.experimental.meteor) +
304
+ String(options.scramjet) +
344
305
  ";\n" +
345
306
  chemicalSW;
346
307
  chemicalSW =
@@ -360,18 +321,9 @@ const ChemicalVitePlugin = (options) => ({
360
321
  app.use("/uv/", express.static(resolve(__dirname, "config/uv")));
361
322
  app.use("/uv/", express.static(uvPath));
362
323
  }
363
- if (options.experimental.scramjet) {
364
- app.use(
365
- "/scramjet/",
366
- express.static(resolve(__dirname, "config/scramjet"))
367
- );
324
+ if (options.scramjet) {
368
325
  app.use("/scramjet/", express.static(scramjetPath));
369
326
  }
370
- if (options.experimental.meteor) {
371
- app.use("/meteor/", express.static(resolve(__dirname, "config/meteor")));
372
- app.use("/meteor/", express.static(meteorPath));
373
- }
374
-
375
327
  server.middlewares.use(app);
376
328
 
377
329
  server.middlewares.use((req, res, next) => {
@@ -434,22 +386,18 @@ class ChemicalBuild {
434
386
  options.uv = true;
435
387
  }
436
388
 
437
- if (options.experimental === undefined) {
438
- options.experimental = {};
439
- }
440
-
441
- if (options.experimental.scramjet === undefined) {
442
- options.experimental.scramjet = false;
443
- }
444
-
445
- if (options.experimental.meteor === undefined) {
446
- options.experimental.meteor = false;
389
+ if (options.scramjet === undefined) {
390
+ options.scramjet = true;
447
391
  }
448
392
 
449
393
  if (options.rammerhead === undefined) {
450
394
  options.rammerhead = true;
451
395
  }
452
396
 
397
+ if (options.demoMode === undefined) {
398
+ options.demoMode = false;
399
+ }
400
+
453
401
  this.options = options;
454
402
  }
455
403
  async write(deletePath = false) {
@@ -469,11 +417,7 @@ class ChemicalBuild {
469
417
  );
470
418
 
471
419
  if (this.options.default) {
472
- if (
473
- ["uv", "rammerhead", "scramjet", "meteor"].includes(
474
- this.options.default
475
- )
476
- ) {
420
+ if (["uv", "rammerhead", "scramjet"].includes(this.options.default)) {
477
421
  chemicalMain =
478
422
  `const defaultService = "${this.options.default}";\n\n` +
479
423
  chemicalMain;
@@ -489,17 +433,17 @@ class ChemicalBuild {
489
433
  "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalMain;
490
434
  chemicalMain =
491
435
  "const scramjetEnabled = " +
492
- String(this.options.experimental.scramjet) +
436
+ String(this.options.scramjet) +
493
437
  ";\n" +
494
438
  chemicalMain;
495
439
  chemicalMain =
496
- "const meteorEnabled = " +
497
- String(this.options.experimental.meteor) +
440
+ "const rammerheadEnabled = " +
441
+ String(this.options.rammerhead) +
498
442
  ";\n" +
499
443
  chemicalMain;
500
444
  chemicalMain =
501
- "const rammerheadEnabled = " +
502
- String(this.options.rammerhead) +
445
+ "const demoMode = " +
446
+ String(this.options.demoMode) +
503
447
  ";\n" +
504
448
  chemicalMain;
505
449
 
@@ -516,12 +460,7 @@ class ChemicalBuild {
516
460
  "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalSW;
517
461
  chemicalSW =
518
462
  "const scramjetEnabled = " +
519
- String(this.options.experimental.scramjet) +
520
- ";\n" +
521
- chemicalSW;
522
- chemicalSW =
523
- "const meteorEnabled = " +
524
- String(this.options.experimental.meteor) +
463
+ String(this.options.scramjet) +
525
464
  ";\n" +
526
465
  chemicalSW;
527
466
  chemicalSW =
@@ -532,6 +471,13 @@ class ChemicalBuild {
532
471
 
533
472
  writeFileSync(resolve(this.options.path, "chemical.sw.js"), chemicalSW);
534
473
 
474
+ if (this.options.demoMode) {
475
+ copyFileSync(
476
+ resolve(__dirname, "client/chemical.demo.html"),
477
+ resolve(this.options.path, "chemical.demo.html")
478
+ );
479
+ }
480
+
535
481
  cpSync(baremuxPath, resolve(this.options.path, "baremux"), {
536
482
  recursive: true,
537
483
  });
@@ -549,24 +495,6 @@ class ChemicalBuild {
549
495
  resolve(this.options.path, "uv/uv.config.js")
550
496
  );
551
497
  }
552
- if (this.options.experimental.scramjet) {
553
- cpSync(scramjetPath, resolve(this.options.path, "scramjet"), {
554
- recursive: true,
555
- });
556
- copyFileSync(
557
- resolve(__dirname, "config/scramjet/scramjet.config.js"),
558
- resolve(this.options.path, "scramjet/scramjet.config.js")
559
- );
560
- }
561
- if (this.options.experimental.meteor) {
562
- cpSync(meteorPath, resolve(this.options.path, "meteor"), {
563
- recursive: true,
564
- });
565
- copyFileSync(
566
- resolve(__dirname, "config/meteor/meteor.config.js"),
567
- resolve(this.options.path, "meteor/meteor.config.js")
568
- );
569
- }
570
498
  }
571
499
  }
572
500
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chemicaljs",
3
- "version": "2.1.1",
3
+ "version": "2.3.1",
4
4
  "description": "Easily create your own web proxy with no experience required.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,14 +14,13 @@
14
14
  "update": "npx npm-check-updates -u && npm i"
15
15
  },
16
16
  "dependencies": {
17
- "@mercuryworkshop/bare-mux": "^2.1.2",
18
- "@mercuryworkshop/epoxy-transport": "^2.1.17",
19
- "@mercuryworkshop/libcurl-transport": "^1.3.10",
17
+ "@mercuryworkshop/bare-mux": "^2.1.6",
18
+ "@mercuryworkshop/epoxy-transport": "^2.1.26",
19
+ "@mercuryworkshop/libcurl-transport": "^1.3.12",
20
20
  "@mercuryworkshop/scramjet": "^1.0.2",
21
- "@mercuryworkshop/wisp-js": "^0.3.2",
22
- "@titaniumnetwork-dev/ultraviolet": "^3.2.7",
21
+ "@mercuryworkshop/wisp-js": "^0.3.3",
22
+ "@titaniumnetwork-dev/ultraviolet": "^3.2.10",
23
23
  "express": "^4.21.1",
24
- "meteorproxy": "^1.0.6-patch.1",
25
24
  "rammerhead": "https://github.com/chemicaljs/chemical/raw/main/rammerhead.tgz"
26
25
  },
27
26
  "engines": {