@vyriy/html 0.4.0 → 0.4.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/README.md CHANGED
@@ -27,6 +27,8 @@ The function returns a full `<!DOCTYPE html>` page and lets you inject common do
27
27
 
28
28
  Missing sections default to empty strings, so the function always returns the same document shape.
29
29
 
30
+ `minify` can be used as an explicit wrapper when the rendered document should not contain line breaks. It removes line breaks from the whole document, including injected style and script sections, while preserving ordinary spaces.
31
+
30
32
  ## Signature
31
33
 
32
34
  ```ts
@@ -44,6 +46,8 @@ type HtmlProps = {
44
46
  };
45
47
 
46
48
  type Html = (props?: HtmlProps) => string;
49
+
50
+ type Minify = (html: string) => string;
47
51
  ```
48
52
 
49
53
  ## Example
@@ -61,13 +65,29 @@ const page = html({
61
65
  });
62
66
  ```
63
67
 
68
+ Minified output:
69
+
70
+ ```ts
71
+ import { html, minify } from '@vyriy/html';
72
+
73
+ const page = minify(
74
+ html({
75
+ body: '<div id="root"></div>',
76
+ script: `<script>
77
+ window.__APP_READY__ = true;
78
+ </script>`,
79
+ }),
80
+ );
81
+ ```
82
+
64
83
  ## Exports
65
84
 
66
85
  The package exposes both the root entry and the direct utility module:
67
86
 
68
87
  ```ts
69
88
  import { html } from '@vyriy/html';
70
- import { html as htmlDocument } from '@vyriy/html/html';
89
+ import { html as htmlDocument } from '@vyriy/html/html.js';
90
+ import { minify } from '@vyriy/html/minify,js';
71
91
  ```
72
92
 
73
93
  ## When to use it
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './html.js';
2
+ export * from './minify.js';
2
3
  export type * from './types.js';
package/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './html.js';
2
+ export * from './minify.js';
package/minify.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Minify } from './types.js';
2
+ export declare const minify: Minify;
package/minify.js ADDED
@@ -0,0 +1,35 @@
1
+ const isLineBreak = (character) => character === '\n' || character === '\r';
2
+ const isWhitespace = (character) => character === ' ' || character === '\t' || character === '\n' || character === '\r' || character === '\f';
3
+ const trimWhitespaceEnd = (value) => {
4
+ let end = value.length;
5
+ while (end > 0 && isWhitespace(value.charAt(end - 1))) {
6
+ end -= 1;
7
+ }
8
+ return value.slice(0, end);
9
+ };
10
+ const trimTagGapEnd = (value) => {
11
+ const trimmed = trimWhitespaceEnd(value);
12
+ return trimmed.at(-1) === '>' ? trimmed : value;
13
+ };
14
+ export const minify = (html) => {
15
+ const trimmed = html.trim();
16
+ let minified = '';
17
+ for (let index = 0; index < trimmed.length; index += 1) {
18
+ const character = trimmed.charAt(index);
19
+ if (isLineBreak(character)) {
20
+ minified = trimWhitespaceEnd(minified);
21
+ while (isWhitespace(trimmed.charAt(index + 1))) {
22
+ index += 1;
23
+ }
24
+ if (minified.at(-1) !== '>' || trimmed.charAt(index + 1) !== '<') {
25
+ minified += ' ';
26
+ }
27
+ continue;
28
+ }
29
+ if (character === '<') {
30
+ minified = trimTagGapEnd(minified);
31
+ }
32
+ minified += character;
33
+ }
34
+ return minified;
35
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyriy/html",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "HTML document utility for Vyriy projects",
5
5
  "type": "module",
6
6
  "agents": "./AGENTS.md",
@@ -37,6 +37,16 @@
37
37
  "types": "./index.d.ts",
38
38
  "import": "./index.js",
39
39
  "default": "./index.js"
40
+ },
41
+ "./minify": {
42
+ "types": "./minify.d.ts",
43
+ "import": "./minify.js",
44
+ "default": "./minify.js"
45
+ },
46
+ "./minify.js": {
47
+ "types": "./minify.d.ts",
48
+ "import": "./minify.js",
49
+ "default": "./minify.js"
40
50
  }
41
51
  }
42
52
  }
package/types.d.ts CHANGED
@@ -11,3 +11,4 @@ export type HtmlProps = {
11
11
  script?: string;
12
12
  };
13
13
  export type Html = (props?: HtmlProps) => string;
14
+ export type Minify = (html: string) => string;