chemicaljs 1.2.5 → 1.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.
package/README.md CHANGED
@@ -3,7 +3,9 @@ Easily create your own web proxy with no experience required.
3
3
 
4
4
  ## Setup
5
5
 
6
- A simple example can be found in `/example/`.
6
+ A simple example can be found in [`/example/`](https://github.com/chemicaljs/chemical/tree/main/example).
7
+
8
+ A example with the vite plugin can be found in [`/example-vite/`](https://github.com/chemicaljs/chemical/tree/main/example-vite).
7
9
 
8
10
  ### Server
9
11
 
@@ -79,6 +81,12 @@ If you want to set the wisp server to an external server just change the `wisp`
79
81
  <script wisp="wss://wisp.mercurywork.shop" src="/chemical.js"></script>
80
82
  ```
81
83
 
84
+ If you want to set the transport just change the `transport` attribute. Choose `libcurl` (default becuase it supports Firefox) or `epoxy`.
85
+
86
+ ```html
87
+ <script transport="epoxy" src="/chemical.js"></script>
88
+ ```
89
+
82
90
  2. In a inline script or javascript file, encode a URL with Chemical using the async function `window.chemicalEncode`.
83
91
 
84
92
  ```js
@@ -105,6 +113,12 @@ window.addEventListener("chemicalLoaded", function(e) {
105
113
  });
106
114
  ```
107
115
 
116
+ 4. Change the transport and Wisp URL with `chemicalTransport`
117
+
118
+ ```js
119
+ await chemicalTransport("libcurl", "wss://wisp.mercurywork.shop")
120
+ ```
121
+
108
122
  Below is a simple example of a simple input that redirects to the encoded URL when the user presses enter. It checks if there is any input and if Chemical has loaded before loading.
109
123
 
110
124
  ```html
@@ -123,6 +137,36 @@ Below is a simple example of a simple input that redirects to the encoded URL wh
123
137
  </script>
124
138
  ```
125
139
 
140
+ ### Vite Plugin
141
+
142
+ 1. Create a new vite app and open `vite.config.js` or `vite.config.ts`
143
+
144
+ 2. Import `ChemicalPluginVite` and add it to plugins.
145
+
146
+ ```js
147
+ import { defineConfig } from "vite"
148
+ import { ChemicalPluginVite } from "chemicaljs"
149
+
150
+ export default defineConfig({
151
+ plugins: [/*Other plugins*/ChemicalPluginVite()],
152
+ })
153
+ ```
154
+
155
+ You can pass options to just like on the main server.
156
+
157
+ ```js
158
+ export default defineConfig({
159
+ plugins: [
160
+ ChemicalPluginVite({
161
+ default: "rammerhead",
162
+ uv: true,
163
+ scramjet: false,
164
+ rammerhead: true
165
+ })
166
+ ],
167
+ })
168
+ ```
169
+
126
170
  ## Future Addition
127
171
 
128
172
  Some features that may come in the future are:
@@ -202,11 +202,29 @@ async function chemicalEncode(url, service = defaultService) {
202
202
  }
203
203
  }
204
204
 
205
+ function getTransport(transport) {
206
+ switch (transport) {
207
+ case "libcurl":
208
+ return "/libcurl/index.mjs"
209
+ break;
210
+ case "epoxy":
211
+ return "/epoxy/index.mjs"
212
+ break;
213
+ }
214
+ }
215
+
216
+ let connection;
217
+
205
218
  let wispURL = document.currentScript.getAttribute("wisp");
219
+ let transport = document.currentScript.getAttribute("transport");
220
+
221
+ async function chemicalTransport(transport, wisp) {
222
+ await connection.setTransport(getTransport(transport) || "/libcurl/index.mjs", [{ wisp: wisp || (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/" }]);
223
+ }
206
224
 
207
225
  async function registerSW() {
208
- const connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
209
- await connection.setTransport("/epoxy/index.mjs", [{ wisp: wispURL || (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/" }]);
226
+ connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
227
+ await chemicalTransport();
210
228
 
211
229
  if ("serviceWorker" in navigator) {
212
230
  await navigator.serviceWorker.register("/chemical.sw.js");
package/example/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ChemicalServer } from "chemicaljs";
1
+ import { ChemicalServer } from "../index.js";
2
2
  import express from "express";
3
3
 
4
4
  const chemical = new ChemicalServer();
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.2.4",
12
+ "chemicaljs": "^1.3.0",
13
13
  "express": "^4.19.2"
14
14
  }
15
15
  },
@@ -1146,12 +1146,12 @@
1146
1146
  }
1147
1147
  },
1148
1148
  "node_modules/chemicaljs": {
1149
- "version": "1.2.4",
1150
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.2.4.tgz",
1151
- "integrity": "sha512-gHFje3KkFNHT49jsRibzcSFACAg49VjNAy9mcqB7yII2vwIQr41SvRZ2+BwHIa8uA3ep/ovlty6qGBZxkTjgbg==",
1149
+ "version": "1.3.0",
1150
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.3.0.tgz",
1151
+ "integrity": "sha512-WJf2OA33QuFxhqRJCECk8lh8VWzURVc2CqIPfkAYBBIY/6XO98xvEbsxjkrQoxGegz7ilC7BqvQkV3h2ASIjQQ==",
1152
1152
  "dependencies": {
1153
1153
  "@mercuryworkshop/bare-mux": "^2.0.1",
1154
- "@mercuryworkshop/epoxy-transport": "^2.1.2",
1154
+ "@mercuryworkshop/epoxy-transport": "^2.1.3",
1155
1155
  "@mercuryworkshop/scramjet": "^1.0.2",
1156
1156
  "@titaniumnetwork-dev/ultraviolet": "^3.2.1",
1157
1157
  "express": "^4.19.2",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.2.4",
21
+ "chemicaljs": "^1.3.0",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -0,0 +1,9 @@
1
+ # Chemical Example Vite
2
+
3
+ Note: This example uses Preact but any framework will work.
4
+
5
+ Run `npm install` to install dependencies.
6
+
7
+ Run `npm run build` to build and `npm start` to start.
8
+
9
+ Run `npm run dev` to start the dev server which is the point of this example.
@@ -0,0 +1,12 @@
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
+ <script src="/chemical.js"></script>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.jsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,14 @@
1
+ import { ChemicalServer } from "chemicaljs";
2
+ import express from "express";
3
+
4
+ const chemical = new ChemicalServer();
5
+ const port = process.env.PORT || 3000;
6
+
7
+ chemical.app.use(express.static("dist", {
8
+ index: "index.html",
9
+ extensions: ["html"]
10
+ }));
11
+
12
+ chemical.server.listen(port, () => {
13
+ console.log(`Chemical example vite listening on port ${port}`);
14
+ });