@hyperspan/framework 0.1.1 → 0.1.3

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/build.ts CHANGED
@@ -1,27 +1,29 @@
1
1
  import {build} from 'bun';
2
2
  import dts from 'bun-plugin-dts';
3
3
 
4
- const filesToBuild = ['./src/index.ts', './src/server.ts', './src/assets.ts'];
4
+ const entrypoints = ['./src/server.ts', './src/assets.ts'];
5
+ const external = ['@hyperspan/html'];
5
6
  const outdir = './dist';
6
7
  const target = 'node';
8
+ const splitting = true;
7
9
 
8
- await Promise.all(
9
- filesToBuild.map((file) =>
10
- Promise.all([
11
- // Build JS
12
- build({
13
- entrypoints: [file],
14
- outdir,
15
- target,
16
- }),
10
+ await Promise.all([
11
+ // Build JS
12
+ build({
13
+ entrypoints,
14
+ external,
15
+ outdir,
16
+ target,
17
+ splitting,
18
+ }),
17
19
 
18
- // Build type files for TypeScript
19
- build({
20
- entrypoints: [file],
21
- outdir,
22
- target,
23
- plugins: [dts()],
24
- }),
25
- ])
26
- )
27
- );
20
+ // Build type files for TypeScript
21
+ build({
22
+ entrypoints,
23
+ external,
24
+ outdir,
25
+ target,
26
+ splitting,
27
+ plugins: [dts()],
28
+ }),
29
+ ]);
package/dist/assets.d.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ declare class TmplHtml {
4
+ _kind: string;
5
+ content: string;
6
+ asyncContent: Array<{
7
+ id: string;
8
+ promise: Promise<{
9
+ id: string;
10
+ value: unknown;
11
+ }>;
12
+ }>;
13
+ constructor(props: Pick<TmplHtml, "content" | "asyncContent">);
14
+ }
3
15
  /**
4
16
  * Build client JS for end users (minimal JS for Hyperspan to work)
5
17
  */
@@ -7,7 +19,7 @@ export declare const clientJSFiles: Map<string, {
7
19
  src: string;
8
20
  type?: string;
9
21
  }>;
10
- export declare function buildClientJS(): Promise<string>;
22
+ export declare function buildClientJS(): Promise<void>;
11
23
  /**
12
24
  * Find client CSS file built for end users
13
25
  * @TODO: Build this in code here vs. relying on tailwindcss CLI tool from package scripts
@@ -17,12 +29,12 @@ export declare function buildClientCSS(): Promise<string | undefined>;
17
29
  /**
18
30
  * Output HTML style tag for Hyperspan app
19
31
  */
20
- export declare function hyperspanStyleTags(): import("@hyperspan/html").TmplHtml;
32
+ export declare function hyperspanStyleTags(): TmplHtml;
21
33
  /**
22
34
  * Output HTML script tag for Hyperspan app
23
35
  * Required for functioning streaming so content can pop into place properly once ready
24
36
  */
25
- export declare function hyperspanScriptTags(): import("@hyperspan/html").TmplHtml;
37
+ export declare function hyperspanScriptTags(): TmplHtml;
26
38
  /**
27
39
  * Return a Preact component, mounted as an island in a <script> tag so it can be embedded into the page response.
28
40
  */
package/dist/assets.js CHANGED
@@ -1,162 +1,5 @@
1
- // node_modules/@hyperspan/html/dist/html.js
2
- /*!
3
- * escape-html
4
- * Copyright(c) 2012-2013 TJ Holowaychuk
5
- * Copyright(c) 2015 Andreas Lubbe
6
- * Copyright(c) 2015 Tiancheng "Timothy" Gu
7
- * MIT Licensed
8
- */
9
- var matchHtmlRegExp = /["'&<>]/;
10
- function escapeHtml(string) {
11
- const str = "" + string;
12
- const match = matchHtmlRegExp.exec(str);
13
- if (!match) {
14
- return str;
15
- }
16
- let escape;
17
- let html = "";
18
- let index = 0;
19
- let lastIndex = 0;
20
- for (index = match.index;index < str.length; index++) {
21
- switch (str.charCodeAt(index)) {
22
- case 34:
23
- escape = "&quot;";
24
- break;
25
- case 38:
26
- escape = "&amp;";
27
- break;
28
- case 39:
29
- escape = "&#39;";
30
- break;
31
- case 60:
32
- escape = "&lt;";
33
- break;
34
- case 62:
35
- escape = "&gt;";
36
- break;
37
- default:
38
- continue;
39
- }
40
- if (lastIndex !== index) {
41
- html += str.substring(lastIndex, index);
42
- }
43
- lastIndex = index + 1;
44
- html += escape;
45
- }
46
- return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
47
- }
48
-
49
- class TmplHtml {
50
- content = "";
51
- asyncContent;
52
- constructor(props) {
53
- this.content = props.content;
54
- this.asyncContent = props.asyncContent;
55
- }
56
- }
57
- var htmlId = 0;
58
- function html(strings, ...values) {
59
- const asyncContent = [];
60
- let content = "";
61
- for (let i = 0;i < strings.length; i++) {
62
- let value = values[i];
63
- let renderValue;
64
- if (value !== null && value !== undefined) {
65
- let id = `async_loading_${htmlId++}`;
66
- let kind = _typeOf(value);
67
- if (!renderValue) {
68
- renderValue = _renderValue(value, { id, kind, asyncContent }) || "";
69
- }
70
- }
71
- content += strings[i] + (renderValue ? renderValue : "");
72
- }
73
- return new TmplHtml({ content, asyncContent });
74
- }
75
- html.raw = (content) => ({ _kind: "html_safe", content });
76
- function _renderValue(value, opts = {
77
- kind: undefined,
78
- id: undefined,
79
- asyncContent: []
80
- }) {
81
- if (value === null || value === undefined || Number.isNaN(value)) {
82
- return "";
83
- }
84
- const kind = opts.kind || _typeOf(value);
85
- const id = opts.id || "";
86
- switch (kind) {
87
- case "array":
88
- return value.map((v) => _renderValue(v, { id, asyncContent: opts.asyncContent })).join("");
89
- case "object":
90
- if (value instanceof TmplHtml) {
91
- opts.asyncContent.push(...value.asyncContent);
92
- return value.content;
93
- }
94
- if (value?._kind === "html_safe") {
95
- return value?.content || "";
96
- }
97
- if (typeof value.renderAsync === "function") {
98
- opts.asyncContent.push({
99
- id,
100
- promise: value.renderAsync().then((result) => ({
101
- id,
102
- value: result,
103
- asyncContent: opts.asyncContent
104
- }))
105
- });
106
- }
107
- if (typeof value.render === "function") {
108
- return render(_htmlPlaceholder(id, value.render()));
109
- }
110
- return JSON.stringify(value);
111
- case "promise":
112
- opts.asyncContent.push({
113
- id,
114
- promise: value.then((result) => ({
115
- id,
116
- value: result,
117
- asyncContent: opts.asyncContent
118
- }))
119
- });
120
- return render(_htmlPlaceholder(id));
121
- case "generator":
122
- throw new Error("Generators are not supported as a template value at this time. Sorry :(");
123
- }
124
- return escapeHtml(String(value));
125
- }
126
- function _htmlPlaceholder(id, content = "Loading...") {
127
- return html`<!--hs:loading:${id}--><slot id="${id}">${content}</slot><!--/hs:loading:${id}-->`;
128
- }
129
- function render(tmpl) {
130
- return tmpl.content;
131
- }
132
- function _typeOf(obj) {
133
- if (obj instanceof Promise)
134
- return "promise";
135
- if (obj instanceof Date)
136
- return "date";
137
- if (obj instanceof String)
138
- return "string";
139
- if (obj instanceof Number)
140
- return "number";
141
- if (obj instanceof Boolean)
142
- return "boolean";
143
- if (obj instanceof Function)
144
- return "function";
145
- if (Array.isArray(obj))
146
- return "array";
147
- if (Number.isNaN(obj))
148
- return "NaN";
149
- if (obj === undefined)
150
- return "undefined";
151
- if (obj === null)
152
- return "null";
153
- if (isGenerator(obj))
154
- return "generator";
155
- return typeof obj;
156
- }
157
- function isGenerator(obj) {
158
- return obj && typeof obj.next == "function" && typeof obj.throw == "function";
159
- }
1
+ // src/assets.ts
2
+ import { html } from "@hyperspan/html";
160
3
 
161
4
  // src/clientjs/md5.js
162
5
  function md5cycle(x, k) {
@@ -299,7 +142,7 @@ var IS_PROD = false;
299
142
  var PWD = import.meta.dir;
300
143
  var clientJSFiles = new Map;
301
144
  async function buildClientJS() {
302
- const sourceFile = resolve(PWD, "../", "./hyperspan/clientjs/hyperspan-client.ts");
145
+ const sourceFile = resolve(PWD, "../", "./src/clientjs/hyperspan-client.ts");
303
146
  const output = await Bun.build({
304
147
  entrypoints: [sourceFile],
305
148
  outdir: `./public/_hs/js`,
@@ -308,7 +151,6 @@ async function buildClientJS() {
308
151
  });
309
152
  const jsFile = output.outputs[0].path.split("/").reverse()[0];
310
153
  clientJSFiles.set("_hs", { src: "/_hs/js/" + jsFile });
311
- return jsFile;
312
154
  }
313
155
  var clientCSSFiles = new Map;
314
156
  async function buildClientCSS() {
@@ -332,7 +174,7 @@ async function buildClientCSS() {
332
174
  }
333
175
  function hyperspanStyleTags() {
334
176
  const cssFiles = Array.from(clientCSSFiles.entries());
335
- return html`${cssFiles.map(([key, file]) => html`<link rel="stylesheet" href="/_hs/css/${file}" />`)}`;
177
+ return html`${cssFiles.map(([_, file]) => html`<link rel="stylesheet" href="/_hs/css/${file}" />`)}`;
336
178
  }
337
179
  function hyperspanScriptTags() {
338
180
  const jsFiles = Array.from(clientJSFiles.entries());
@@ -392,3 +234,4 @@ export {
392
234
  buildClientJS,
393
235
  buildClientCSS
394
236
  };
237
+
package/dist/server.d.ts CHANGED
@@ -1,8 +1,19 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { TmplHtml } from '@hyperspan/html';
4
3
  import { Context, Handler, Hono } from 'hono';
5
4
 
5
+ declare class TmplHtml {
6
+ _kind: string;
7
+ content: string;
8
+ asyncContent: Array<{
9
+ id: string;
10
+ promise: Promise<{
11
+ id: string;
12
+ value: unknown;
13
+ }>;
14
+ }>;
15
+ constructor(props: Pick<TmplHtml, "content" | "asyncContent">);
16
+ }
6
17
  export declare const IS_PROD: boolean;
7
18
  /**
8
19
  * Route