@spirobel/mininext 0.2.7 → 0.2.9

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/dist/html.d.ts CHANGED
@@ -19,8 +19,8 @@ export declare class DangerJsonInHtml extends HtmlString {
19
19
  }
20
20
  export declare const json: <X = undefined>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => JsonString;
21
21
  export declare const dangerjson: <X = undefined>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => DangerJsonInHtml;
22
- export declare const commonHead = "\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <script>\n /* prevent form resubmission */\n if (window.history.replaceState) {\n window.history.replaceState(null, null, window.location.href);\n }\n </script>";
23
- export declare const cssReset = "\n <style>\n /* CSS Reset */\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n\n /* Set the background color to black */\n html,\n body {\n background-color: #000;\n color: #fff; /* Set the default text color to white for better contrast */\n }\n </style>";
22
+ export declare const commonHead: HtmlString;
23
+ export declare const cssReset: HtmlString;
24
24
  /**
25
25
  * Set the default head for all pages. Can still be overwritten on a per page basis
26
26
  * @param defaultHead - HtmlString
@@ -53,5 +53,5 @@ export declare function isError(submissionResult: any | {
53
53
  error: HtmlString;
54
54
  };
55
55
  declare global {
56
- var Reloader: string | undefined;
56
+ var Reloader: HtmlString | undefined;
57
57
  }
package/dist/html.js CHANGED
@@ -103,30 +103,31 @@ function JsonTemplateProcessor(danger = false) {
103
103
  }
104
104
  export const json = JsonTemplateProcessor();
105
105
  export const dangerjson = JsonTemplateProcessor(true);
106
- export const commonHead = /*html*/ `
107
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
106
+ export const commonHead = html ` <meta
107
+ name="viewport"
108
+ content="width=device-width, initial-scale=1.0"
109
+ />
108
110
  <script>
109
111
  /* prevent form resubmission */
110
112
  if (window.history.replaceState) {
111
113
  window.history.replaceState(null, null, window.location.href);
112
114
  }
113
115
  </script>`;
114
- export const cssReset = /*html*/ `
115
- <style>
116
- /* CSS Reset */
117
- * {
118
- margin: 0;
119
- padding: 0;
120
- box-sizing: border-box;
121
- }
116
+ export const cssReset = html ` <style>
117
+ /* CSS Reset */
118
+ * {
119
+ margin: 0;
120
+ padding: 0;
121
+ box-sizing: border-box;
122
+ }
122
123
 
123
- /* Set the background color to black */
124
- html,
125
- body {
126
- background-color: #000;
127
- color: #fff; /* Set the default text color to white for better contrast */
128
- }
129
- </style>`;
124
+ /* Set the background color to black */
125
+ html,
126
+ body {
127
+ background-color: #000;
128
+ color: #fff; /* Set the default text color to white for better contrast */
129
+ }
130
+ </style>`;
130
131
  let default_head = html `
131
132
  <title>mini-next</title>
132
133
  ${commonHead} ${cssReset}
@@ -167,16 +168,16 @@ export async function htmlResponder(mini, maybeUnresolved, head = default_head,
167
168
  when you embed unescaped json elements in an html document.
168
169
  </div>`;
169
170
  }
170
- const definitelyResolved = await maybeUnresolved.resolve(mini);
171
- const flattend = definitelyResolved.flat(Infinity);
172
171
  if (!(maybeUnresolved instanceof JsonString)) {
173
- flattend.unshift(/*html*/ `<!DOCTYPE html>
172
+ maybeUnresolved = html `<!DOCTYPE html>
174
173
  <html>
175
174
  <head>
176
175
  ${global.Reloader || ""} ${head}
177
176
  </head>
178
177
  <body>
179
- `);
178
+ ${maybeUnresolved}
179
+ </body>
180
+ </html> `;
180
181
  }
181
182
  else {
182
183
  const headers = {
@@ -185,6 +186,8 @@ export async function htmlResponder(mini, maybeUnresolved, head = default_head,
185
186
  };
186
187
  options.headers = headers;
187
188
  }
189
+ const definitelyResolved = await maybeUnresolved.resolve(mini);
190
+ const flattend = definitelyResolved.flat(Infinity);
188
191
  async function* stepGen() {
189
192
  let index = 0;
190
193
  while (index < flattend.length) {
@@ -1,5 +1,5 @@
1
1
  import { url, Mini, type HtmlHandler } from "./url";
2
2
  import { html, isError, HtmlString, head, commonHead, cssReset } from "./html";
3
3
  declare function build(backendPath?: string): Promise<void>;
4
- declare const standardDevReloader = "\n <script>\n function reloader() {\n let socket = null;\n\n function connectWebSocket() {\n if (socket) {\n return;\n }\n socket = new WebSocket(\"ws://localhost:3001/reload\");\n\n socket.addEventListener(\"message\", (event) => {\n window.location.reload();\n });\n\n socket.addEventListener(\"close\", (event) => {\n // Reestablish the connection after 1 second\n socket = null;\n });\n\n socket.addEventListener(\"error\", (event) => {\n socket = null;\n });\n }\n connectWebSocket(); // connect to reloader, if it does not work:\n setInterval(connectWebSocket, 1000); // retry every 1 second\n }\n reloader();\n </script>\n ";
4
+ declare const standardDevReloader: HtmlString;
5
5
  export { url, html, head, build, isError, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
package/dist/mininext.js CHANGED
@@ -112,34 +112,34 @@ async function devServer() {
112
112
  watchAndBuild("frontend");
113
113
  watchAndBuild("backend");
114
114
  }
115
- const standardDevReloader = /*html*/ `
116
- <script>
117
- function reloader() {
118
- let socket = null;
115
+ const standardDevReloader = html `
116
+ <script>
117
+ function reloader() {
118
+ let socket = null;
119
119
 
120
- function connectWebSocket() {
121
- if (socket) {
122
- return;
123
- }
124
- socket = new WebSocket("ws://localhost:3001/reload");
120
+ function connectWebSocket() {
121
+ if (socket) {
122
+ return;
123
+ }
124
+ socket = new WebSocket("ws://localhost:3001/reload");
125
125
 
126
- socket.addEventListener("message", (event) => {
127
- window.location.reload();
128
- });
126
+ socket.addEventListener("message", (event) => {
127
+ window.location.reload();
128
+ });
129
129
 
130
- socket.addEventListener("close", (event) => {
131
- // Reestablish the connection after 1 second
132
- socket = null;
133
- });
130
+ socket.addEventListener("close", (event) => {
131
+ // Reestablish the connection after 1 second
132
+ socket = null;
133
+ });
134
134
 
135
- socket.addEventListener("error", (event) => {
136
- socket = null;
137
- });
138
- }
139
- connectWebSocket(); // connect to reloader, if it does not work:
140
- setInterval(connectWebSocket, 1000); // retry every 1 second
135
+ socket.addEventListener("error", (event) => {
136
+ socket = null;
137
+ });
141
138
  }
142
- reloader();
143
- </script>
144
- `;
139
+ connectWebSocket(); // connect to reloader, if it does not work:
140
+ setInterval(connectWebSocket, 1000); // retry every 1 second
141
+ }
142
+ reloader();
143
+ </script>
144
+ `;
145
145
  export { url, html, head, build, isError, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
package/mininext/html.ts CHANGED
@@ -145,30 +145,31 @@ function JsonTemplateProcessor(danger: boolean = false) {
145
145
  }
146
146
  export const json = JsonTemplateProcessor();
147
147
  export const dangerjson = JsonTemplateProcessor(true);
148
- export const commonHead = /*html*/ `
149
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
148
+ export const commonHead = html` <meta
149
+ name="viewport"
150
+ content="width=device-width, initial-scale=1.0"
151
+ />
150
152
  <script>
151
153
  /* prevent form resubmission */
152
154
  if (window.history.replaceState) {
153
155
  window.history.replaceState(null, null, window.location.href);
154
156
  }
155
157
  </script>`;
156
- export const cssReset = /*html*/ `
157
- <style>
158
- /* CSS Reset */
159
- * {
160
- margin: 0;
161
- padding: 0;
162
- box-sizing: border-box;
163
- }
158
+ export const cssReset = html` <style>
159
+ /* CSS Reset */
160
+ * {
161
+ margin: 0;
162
+ padding: 0;
163
+ box-sizing: border-box;
164
+ }
164
165
 
165
- /* Set the background color to black */
166
- html,
167
- body {
168
- background-color: #000;
169
- color: #fff; /* Set the default text color to white for better contrast */
170
- }
171
- </style>`;
166
+ /* Set the background color to black */
167
+ html,
168
+ body {
169
+ background-color: #000;
170
+ color: #fff; /* Set the default text color to white for better contrast */
171
+ }
172
+ </style>`;
172
173
  let default_head = html`
173
174
  <title>mini-next</title>
174
175
  ${commonHead} ${cssReset}
@@ -215,16 +216,16 @@ export async function htmlResponder(
215
216
  when you embed unescaped json elements in an html document.
216
217
  </div>`;
217
218
  }
218
- const definitelyResolved = await maybeUnresolved.resolve(mini);
219
- const flattend = definitelyResolved.flat(Infinity);
220
219
  if (!(maybeUnresolved instanceof JsonString)) {
221
- flattend.unshift(/*html*/ `<!DOCTYPE html>
220
+ maybeUnresolved = html`<!DOCTYPE html>
222
221
  <html>
223
222
  <head>
224
223
  ${global.Reloader || ""} ${head}
225
224
  </head>
226
225
  <body>
227
- `);
226
+ ${maybeUnresolved}
227
+ </body>
228
+ </html> `;
228
229
  } else {
229
230
  const headers = {
230
231
  ...options.headers,
@@ -232,6 +233,8 @@ export async function htmlResponder(
232
233
  };
233
234
  options.headers = headers;
234
235
  }
236
+ const definitelyResolved = await maybeUnresolved.resolve(mini);
237
+ const flattend = definitelyResolved.flat(Infinity);
235
238
 
236
239
  async function* stepGen() {
237
240
  let index = 0;
@@ -262,5 +265,5 @@ export function isError(
262
265
  }
263
266
 
264
267
  declare global {
265
- var Reloader: string | undefined;
268
+ var Reloader: HtmlString | undefined;
266
269
  }
@@ -121,36 +121,36 @@ async function devServer() {
121
121
  watchAndBuild("frontend");
122
122
  watchAndBuild("backend");
123
123
  }
124
- const standardDevReloader = /*html*/ `
125
- <script>
126
- function reloader() {
127
- let socket = null;
124
+ const standardDevReloader = html`
125
+ <script>
126
+ function reloader() {
127
+ let socket = null;
128
128
 
129
- function connectWebSocket() {
130
- if (socket) {
131
- return;
132
- }
133
- socket = new WebSocket("ws://localhost:3001/reload");
129
+ function connectWebSocket() {
130
+ if (socket) {
131
+ return;
132
+ }
133
+ socket = new WebSocket("ws://localhost:3001/reload");
134
134
 
135
- socket.addEventListener("message", (event) => {
136
- window.location.reload();
137
- });
135
+ socket.addEventListener("message", (event) => {
136
+ window.location.reload();
137
+ });
138
138
 
139
- socket.addEventListener("close", (event) => {
140
- // Reestablish the connection after 1 second
141
- socket = null;
142
- });
139
+ socket.addEventListener("close", (event) => {
140
+ // Reestablish the connection after 1 second
141
+ socket = null;
142
+ });
143
143
 
144
- socket.addEventListener("error", (event) => {
145
- socket = null;
146
- });
147
- }
148
- connectWebSocket(); // connect to reloader, if it does not work:
149
- setInterval(connectWebSocket, 1000); // retry every 1 second
144
+ socket.addEventListener("error", (event) => {
145
+ socket = null;
146
+ });
150
147
  }
151
- reloader();
152
- </script>
153
- `;
148
+ connectWebSocket(); // connect to reloader, if it does not work:
149
+ setInterval(connectWebSocket, 1000); // retry every 1 second
150
+ }
151
+ reloader();
152
+ </script>
153
+ `;
154
154
 
155
155
  export {
156
156
  url,
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  },
14
14
  "files": ["dist", "mininext"],
15
- "version": "0.2.7",
15
+ "version": "0.2.9",
16
16
  "devDependencies": {
17
17
  "@types/bun": "latest"
18
18
  },