unhead 2.0.16 → 2.0.18
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 +105 -5
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/legacy.d.mts +3 -3
- package/dist/legacy.d.ts +3 -3
- package/dist/parser.d.mts +54 -0
- package/dist/parser.d.ts +54 -0
- package/dist/parser.mjs +508 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/scripts.d.mts +3 -3
- package/dist/scripts.d.ts +3 -3
- package/dist/server.d.mts +7 -20
- package/dist/server.d.ts +7 -20
- package/dist/server.mjs +6 -513
- package/dist/shared/{unhead.YQlj2HXR.d.mts → unhead.CnYfgE7E.d.mts} +1 -1
- package/dist/shared/{unhead.DcRvKVx9.d.mts → unhead.Ctcwz9O1.d.mts} +1 -1
- package/dist/shared/{unhead.BzieZHWV.d.ts → unhead.DQUgqVjB.d.ts} +1 -1
- package/dist/shared/{unhead.BxIzrSMV.d.mts → unhead.Prz0gZXE.d.mts} +1 -1
- package/dist/shared/{unhead.BxIzrSMV.d.ts → unhead.Prz0gZXE.d.ts} +1 -1
- package/dist/shared/{unhead.jgc6RGmf.d.ts → unhead.kTflSlNr.d.ts} +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +5 -1
- package/parser.d.ts +1 -0
package/README.md
CHANGED
|
@@ -1,13 +1,113 @@
|
|
|
1
|
-
#
|
|
1
|
+
# unhead
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Full-stack `<head>` manager built for any framework
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
6
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
7
|
+
[![License][license-src]][license-href]
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🚀 Framework agnostic - works with any framework
|
|
12
|
+
- 🔄 Reactive head management
|
|
13
|
+
- 🔍 SEO-friendly with rich meta tag support
|
|
14
|
+
- 🖥️ Server-side rendering support
|
|
15
|
+
- 📦 Lightweight and tree-shakable
|
|
16
|
+
- ⚡ Performance optimized with minimal runtime overhead
|
|
17
|
+
- 🎯 Type-safe with full TypeScript support
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
6
20
|
|
|
7
21
|
```bash
|
|
8
|
-
npm
|
|
22
|
+
# npm
|
|
23
|
+
npm install unhead
|
|
24
|
+
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add unhead
|
|
27
|
+
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm add unhead
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createHead, useHead } from 'unhead'
|
|
38
|
+
|
|
39
|
+
// Create a head instance
|
|
40
|
+
const head = createHead()
|
|
41
|
+
|
|
42
|
+
// Use head tags
|
|
43
|
+
useHead({
|
|
44
|
+
title: 'My App',
|
|
45
|
+
meta: [
|
|
46
|
+
{
|
|
47
|
+
name: 'description',
|
|
48
|
+
content: 'My awesome application'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}, { head })
|
|
9
52
|
```
|
|
10
53
|
|
|
54
|
+
### Server-Side Rendering
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { createHead, renderSSRHead } from 'unhead/server'
|
|
58
|
+
|
|
59
|
+
const head = createHead()
|
|
60
|
+
|
|
61
|
+
// Add head entries
|
|
62
|
+
useHead({
|
|
63
|
+
title: 'SSR App',
|
|
64
|
+
meta: [{ name: 'description', content: 'Server-rendered app' }]
|
|
65
|
+
}, { head })
|
|
66
|
+
|
|
67
|
+
// Render head tags
|
|
68
|
+
const { headTags, bodyTags } = await renderSSRHead(head)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Client-Side Hydration
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { createHead, renderDOMHead } from 'unhead/client'
|
|
75
|
+
|
|
76
|
+
const head = createHead()
|
|
77
|
+
|
|
78
|
+
// Enable DOM rendering
|
|
79
|
+
renderDOMHead(head)
|
|
80
|
+
|
|
81
|
+
// Add reactive head entries
|
|
82
|
+
useHead({
|
|
83
|
+
title: 'Client App'
|
|
84
|
+
}, { head })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Framework Integrations
|
|
88
|
+
|
|
89
|
+
Unhead provides optimized integrations for popular frameworks:
|
|
90
|
+
|
|
91
|
+
- **Vue**: [`@unhead/vue`](../vue)
|
|
92
|
+
- **React**: [`@unhead/react`](../react)
|
|
93
|
+
- **Angular**: [`@unhead/angular`](../angular)
|
|
94
|
+
- **Svelte**: [`@unhead/svelte`](../svelte)
|
|
95
|
+
- **SolidJS**: [`@unhead/solid-js`](../solid-js)
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
Visit the [documentation site](https://unhead.unjs.io/) for comprehensive guides and API references.
|
|
100
|
+
|
|
11
101
|
## License
|
|
12
102
|
|
|
13
|
-
MIT
|
|
103
|
+
[MIT](./LICENSE)
|
|
104
|
+
|
|
105
|
+
<!-- Badges -->
|
|
106
|
+
[npm-version-src]: https://img.shields.io/npm/v/unhead/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
107
|
+
[npm-version-href]: https://npmjs.com/package/unhead
|
|
108
|
+
|
|
109
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/unhead.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
110
|
+
[npm-downloads-href]: https://npmjs.com/package/unhead
|
|
111
|
+
|
|
112
|
+
[license-src]: https://img.shields.io/github/license/unjs/unhead.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
113
|
+
[license-href]: https://github.com/unjs/unhead/blob/main/LICENSE
|
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ResolvableHead,
|
|
1
|
+
import { R as ResolvableHead, r as CreateClientHeadOptions, U as Unhead, I as RenderDomHeadOptions } from './shared/unhead.Prz0gZXE.mjs';
|
|
2
2
|
import 'hookable';
|
|
3
3
|
|
|
4
4
|
declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ResolvableHead,
|
|
1
|
+
import { R as ResolvableHead, r as CreateClientHeadOptions, U as Unhead, I as RenderDomHeadOptions } from './shared/unhead.Prz0gZXE.js';
|
|
2
2
|
import 'hookable';
|
|
3
3
|
|
|
4
4
|
declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HeadSafe } from './shared/unhead.
|
|
2
|
-
import { U as Unhead, R as ResolvableHead,
|
|
3
|
-
export { u as useScript } from './shared/unhead.
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.Ctcwz9O1.mjs';
|
|
2
|
+
import { U as Unhead, R as ResolvableHead, s as HeadEntryOptions, p as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.Prz0gZXE.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.CnYfgE7E.mjs';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HeadSafe } from './shared/unhead.
|
|
2
|
-
import { U as Unhead, R as ResolvableHead,
|
|
3
|
-
export { u as useScript } from './shared/unhead.
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.DQUgqVjB.js';
|
|
2
|
+
import { U as Unhead, R as ResolvableHead, s as HeadEntryOptions, p as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.Prz0gZXE.js';
|
|
3
|
+
export { u as useScript } from './shared/unhead.kTflSlNr.js';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
|
package/dist/legacy.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createUnhead } from './index.mjs';
|
|
2
2
|
export { useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from './index.mjs';
|
|
3
|
-
import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.
|
|
4
|
-
export { u as useScript } from './shared/unhead.
|
|
5
|
-
import './shared/unhead.
|
|
3
|
+
import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.Prz0gZXE.mjs';
|
|
4
|
+
export { u as useScript } from './shared/unhead.CnYfgE7E.mjs';
|
|
5
|
+
import './shared/unhead.Ctcwz9O1.mjs';
|
|
6
6
|
import 'hookable';
|
|
7
7
|
|
|
8
8
|
declare const activeHead: {
|
package/dist/legacy.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createUnhead } from './index.js';
|
|
2
2
|
export { useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from './index.js';
|
|
3
|
-
import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.
|
|
4
|
-
export { u as useScript } from './shared/unhead.
|
|
5
|
-
import './shared/unhead.
|
|
3
|
+
import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.Prz0gZXE.js';
|
|
4
|
+
export { u as useScript } from './shared/unhead.kTflSlNr.js';
|
|
5
|
+
import './shared/unhead.DQUgqVjB.js';
|
|
6
6
|
import 'hookable';
|
|
7
7
|
|
|
8
8
|
declare const activeHead: {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { S as SerializableHead } from './shared/unhead.Prz0gZXE.mjs';
|
|
2
|
+
import 'hookable';
|
|
3
|
+
|
|
4
|
+
declare const TagIdMap: {
|
|
5
|
+
readonly html: 0;
|
|
6
|
+
readonly head: 1;
|
|
7
|
+
readonly title: 4;
|
|
8
|
+
readonly meta: 5;
|
|
9
|
+
readonly body: 44;
|
|
10
|
+
readonly script: 52;
|
|
11
|
+
readonly style: 53;
|
|
12
|
+
readonly link: 54;
|
|
13
|
+
readonly base: 56;
|
|
14
|
+
};
|
|
15
|
+
interface PreparedHtmlTemplate {
|
|
16
|
+
html: string;
|
|
17
|
+
input: SerializableHead;
|
|
18
|
+
}
|
|
19
|
+
interface PreparedHtmlTemplateWithIndexes {
|
|
20
|
+
html: string;
|
|
21
|
+
input: SerializableHead;
|
|
22
|
+
indexes: {
|
|
23
|
+
htmlTagStart: number;
|
|
24
|
+
htmlTagEnd: number;
|
|
25
|
+
headTagEnd: number;
|
|
26
|
+
bodyTagStart: number;
|
|
27
|
+
bodyTagEnd: number;
|
|
28
|
+
bodyCloseTagStart: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse HTML attributes string into key-value object
|
|
33
|
+
*/
|
|
34
|
+
declare function parseAttributes(attrStr: string): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Parse HTML to find tag indexes without extracting head elements
|
|
37
|
+
* Used for transformHtmlTemplateRaw where we don't want to extract existing head content
|
|
38
|
+
*/
|
|
39
|
+
declare function parseHtmlForIndexes(html: string): PreparedHtmlTemplateWithIndexes;
|
|
40
|
+
declare function parseHtmlForUnheadExtraction(html: string): PreparedHtmlTemplateWithIndexes;
|
|
41
|
+
/**
|
|
42
|
+
* Optimized HTML construction function that uses indexes instead of string.replace()
|
|
43
|
+
* This avoids searching through the entire HTML
|
|
44
|
+
*/
|
|
45
|
+
declare function applyHeadToHtml(template: PreparedHtmlTemplateWithIndexes, headHtml: {
|
|
46
|
+
htmlAttrs: string;
|
|
47
|
+
headTags: string;
|
|
48
|
+
bodyAttrs: string;
|
|
49
|
+
bodyTagsOpen?: string;
|
|
50
|
+
bodyTags: string;
|
|
51
|
+
}): string;
|
|
52
|
+
|
|
53
|
+
export { TagIdMap, applyHeadToHtml, parseAttributes, parseHtmlForIndexes, parseHtmlForUnheadExtraction };
|
|
54
|
+
export type { PreparedHtmlTemplate, PreparedHtmlTemplateWithIndexes };
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { S as SerializableHead } from './shared/unhead.Prz0gZXE.js';
|
|
2
|
+
import 'hookable';
|
|
3
|
+
|
|
4
|
+
declare const TagIdMap: {
|
|
5
|
+
readonly html: 0;
|
|
6
|
+
readonly head: 1;
|
|
7
|
+
readonly title: 4;
|
|
8
|
+
readonly meta: 5;
|
|
9
|
+
readonly body: 44;
|
|
10
|
+
readonly script: 52;
|
|
11
|
+
readonly style: 53;
|
|
12
|
+
readonly link: 54;
|
|
13
|
+
readonly base: 56;
|
|
14
|
+
};
|
|
15
|
+
interface PreparedHtmlTemplate {
|
|
16
|
+
html: string;
|
|
17
|
+
input: SerializableHead;
|
|
18
|
+
}
|
|
19
|
+
interface PreparedHtmlTemplateWithIndexes {
|
|
20
|
+
html: string;
|
|
21
|
+
input: SerializableHead;
|
|
22
|
+
indexes: {
|
|
23
|
+
htmlTagStart: number;
|
|
24
|
+
htmlTagEnd: number;
|
|
25
|
+
headTagEnd: number;
|
|
26
|
+
bodyTagStart: number;
|
|
27
|
+
bodyTagEnd: number;
|
|
28
|
+
bodyCloseTagStart: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse HTML attributes string into key-value object
|
|
33
|
+
*/
|
|
34
|
+
declare function parseAttributes(attrStr: string): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Parse HTML to find tag indexes without extracting head elements
|
|
37
|
+
* Used for transformHtmlTemplateRaw where we don't want to extract existing head content
|
|
38
|
+
*/
|
|
39
|
+
declare function parseHtmlForIndexes(html: string): PreparedHtmlTemplateWithIndexes;
|
|
40
|
+
declare function parseHtmlForUnheadExtraction(html: string): PreparedHtmlTemplateWithIndexes;
|
|
41
|
+
/**
|
|
42
|
+
* Optimized HTML construction function that uses indexes instead of string.replace()
|
|
43
|
+
* This avoids searching through the entire HTML
|
|
44
|
+
*/
|
|
45
|
+
declare function applyHeadToHtml(template: PreparedHtmlTemplateWithIndexes, headHtml: {
|
|
46
|
+
htmlAttrs: string;
|
|
47
|
+
headTags: string;
|
|
48
|
+
bodyAttrs: string;
|
|
49
|
+
bodyTagsOpen?: string;
|
|
50
|
+
bodyTags: string;
|
|
51
|
+
}): string;
|
|
52
|
+
|
|
53
|
+
export { TagIdMap, applyHeadToHtml, parseAttributes, parseHtmlForIndexes, parseHtmlForUnheadExtraction };
|
|
54
|
+
export type { PreparedHtmlTemplate, PreparedHtmlTemplateWithIndexes };
|