@unhead/angular 2.0.0-alpha.19
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/LICENSE +21 -0
- package/README.md +171 -0
- package/dist/README.md +171 -0
- package/dist/fesm2022/unhead-angular.mjs +230 -0
- package/dist/fesm2022/unhead-angular.mjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/lib/head.component.d.ts +17 -0
- package/dist/lib/head.component.d.ts.map +1 -0
- package/dist/lib/unhead.service.d.ts +11 -0
- package/dist/lib/unhead.service.d.ts.map +1 -0
- package/dist/public-api.d.ts +5 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/unhead/composables.d.ts +8 -0
- package/dist/unhead/composables.d.ts.map +1 -0
- package/dist/unhead/install.d.ts +7 -0
- package/dist/unhead/install.d.ts.map +1 -0
- package/dist/unhead-angular.d.ts.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Harlan Wilton <harlan@harlanzw.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @unhead/angular
|
|
2
|
+
|
|
3
|
+
> Full-stack `<head>` management for Angular applications
|
|
4
|
+
|
|
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
|
+
- 🧩 Angular-optimized head management
|
|
12
|
+
- 🔄 Reactive titles, meta tags, and other head elements
|
|
13
|
+
- 🔍 SEO-friendly head control
|
|
14
|
+
- 🖥️ Server-side rendering support
|
|
15
|
+
- 💉 Angular dependency injection integration
|
|
16
|
+
- 📦 Lightweight with zero dependencies (except for Angular & unhead)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# npm
|
|
22
|
+
npm install @unhead/angular
|
|
23
|
+
|
|
24
|
+
# yarn
|
|
25
|
+
yarn add @unhead/angular
|
|
26
|
+
|
|
27
|
+
# pnpm
|
|
28
|
+
pnpm add @unhead/angular
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Setup
|
|
34
|
+
|
|
35
|
+
First, provide the Unhead service in your application:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// app.config.ts
|
|
39
|
+
import { ApplicationConfig } from '@angular/core'
|
|
40
|
+
import { provideClientHead } from '@unhead/angular'
|
|
41
|
+
|
|
42
|
+
export const appConfig: ApplicationConfig = {
|
|
43
|
+
providers: [
|
|
44
|
+
// ... other providers
|
|
45
|
+
provideClientHead(),
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For server-side rendering (Angular Universal):
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// server.ts
|
|
54
|
+
import { provideServerHead } from '@unhead/angular'
|
|
55
|
+
|
|
56
|
+
// In your server module providers:
|
|
57
|
+
providers: [
|
|
58
|
+
// ... other providers
|
|
59
|
+
provideServerHead(),
|
|
60
|
+
]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// app.component.ts
|
|
67
|
+
import { Component } from '@angular/core'
|
|
68
|
+
import { Unhead } from '@unhead/angular'
|
|
69
|
+
|
|
70
|
+
@Component({
|
|
71
|
+
selector: 'app-root',
|
|
72
|
+
template: '<router-outlet></router-outlet>',
|
|
73
|
+
})
|
|
74
|
+
export class AppComponent {
|
|
75
|
+
constructor(private unhead: Unhead) {
|
|
76
|
+
// Set page title
|
|
77
|
+
this.unhead.useHead({
|
|
78
|
+
title: 'My Application',
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Setting Meta Tags
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// home.component.ts
|
|
88
|
+
import { Component, OnInit } from '@angular/core'
|
|
89
|
+
import { Unhead } from '@unhead/angular'
|
|
90
|
+
|
|
91
|
+
@Component({
|
|
92
|
+
selector: 'app-home',
|
|
93
|
+
template: '<h1>Home</h1>',
|
|
94
|
+
})
|
|
95
|
+
export class HomeComponent implements OnInit {
|
|
96
|
+
constructor(private unhead: Unhead) {}
|
|
97
|
+
|
|
98
|
+
ngOnInit() {
|
|
99
|
+
this.unhead.useSeoMeta({
|
|
100
|
+
title: 'Home Page',
|
|
101
|
+
description: 'Welcome to our website',
|
|
102
|
+
ogTitle: 'Welcome to Home Page',
|
|
103
|
+
ogDescription: 'Our fantastic home page',
|
|
104
|
+
ogImage: 'https://example.com/image.jpg',
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Reactive Head Elements
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// profile.component.ts
|
|
114
|
+
import { Component, signal } from '@angular/core'
|
|
115
|
+
import { Unhead } from '@unhead/angular'
|
|
116
|
+
|
|
117
|
+
@Component({
|
|
118
|
+
selector: 'app-profile',
|
|
119
|
+
template: `
|
|
120
|
+
<h1>{{ userName() }}'s Profile</h1>
|
|
121
|
+
<button (click)="updateName('New Name')">Update Name</button>
|
|
122
|
+
`,
|
|
123
|
+
})
|
|
124
|
+
export class ProfileComponent {
|
|
125
|
+
userName = signal('User')
|
|
126
|
+
|
|
127
|
+
constructor(private unhead: Unhead) {
|
|
128
|
+
this.unhead.useHead({
|
|
129
|
+
title: () => `${this.userName()} - Profile`, // Reactive title
|
|
130
|
+
meta: [
|
|
131
|
+
{
|
|
132
|
+
name: 'description',
|
|
133
|
+
content: () => `${this.userName()}'s profile page`, // Reactive description
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updateName(name: string) {
|
|
140
|
+
this.userName.set(name)
|
|
141
|
+
// Title and meta automatically update!
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Install dependencies
|
|
150
|
+
npm install
|
|
151
|
+
|
|
152
|
+
# Generate build files
|
|
153
|
+
npm run build
|
|
154
|
+
|
|
155
|
+
# Run tests
|
|
156
|
+
npm run test
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
[MIT](./LICENSE)
|
|
162
|
+
|
|
163
|
+
<!-- Badges -->
|
|
164
|
+
[npm-version-src]: https://img.shields.io/npm/v/@unhead/angular/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
165
|
+
[npm-version-href]: https://npmjs.com/package/@unhead/angular
|
|
166
|
+
|
|
167
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@unhead/angular.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
168
|
+
[npm-downloads-href]: https://npmjs.com/package/@unhead/angular
|
|
169
|
+
|
|
170
|
+
[license-src]: https://img.shields.io/github/license/unjs/unhead.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
171
|
+
[license-href]: https://github.com/unjs/unhead/blob/main/LICENSE
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @unhead/angular
|
|
2
|
+
|
|
3
|
+
> Full-stack `<head>` management for Angular applications
|
|
4
|
+
|
|
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
|
+
- 🧩 Angular-optimized head management
|
|
12
|
+
- 🔄 Reactive titles, meta tags, and other head elements
|
|
13
|
+
- 🔍 SEO-friendly head control
|
|
14
|
+
- 🖥️ Server-side rendering support
|
|
15
|
+
- 💉 Angular dependency injection integration
|
|
16
|
+
- 📦 Lightweight with zero dependencies (except for Angular & unhead)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# npm
|
|
22
|
+
npm install @unhead/angular
|
|
23
|
+
|
|
24
|
+
# yarn
|
|
25
|
+
yarn add @unhead/angular
|
|
26
|
+
|
|
27
|
+
# pnpm
|
|
28
|
+
pnpm add @unhead/angular
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Setup
|
|
34
|
+
|
|
35
|
+
First, provide the Unhead service in your application:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// app.config.ts
|
|
39
|
+
import { ApplicationConfig } from '@angular/core'
|
|
40
|
+
import { provideClientHead } from '@unhead/angular'
|
|
41
|
+
|
|
42
|
+
export const appConfig: ApplicationConfig = {
|
|
43
|
+
providers: [
|
|
44
|
+
// ... other providers
|
|
45
|
+
provideClientHead(),
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For server-side rendering (Angular Universal):
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// server.ts
|
|
54
|
+
import { provideServerHead } from '@unhead/angular'
|
|
55
|
+
|
|
56
|
+
// In your server module providers:
|
|
57
|
+
providers: [
|
|
58
|
+
// ... other providers
|
|
59
|
+
provideServerHead(),
|
|
60
|
+
]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// app.component.ts
|
|
67
|
+
import { Component } from '@angular/core'
|
|
68
|
+
import { Unhead } from '@unhead/angular'
|
|
69
|
+
|
|
70
|
+
@Component({
|
|
71
|
+
selector: 'app-root',
|
|
72
|
+
template: '<router-outlet></router-outlet>',
|
|
73
|
+
})
|
|
74
|
+
export class AppComponent {
|
|
75
|
+
constructor(private unhead: Unhead) {
|
|
76
|
+
// Set page title
|
|
77
|
+
this.unhead.useHead({
|
|
78
|
+
title: 'My Application',
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Setting Meta Tags
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// home.component.ts
|
|
88
|
+
import { Component, OnInit } from '@angular/core'
|
|
89
|
+
import { Unhead } from '@unhead/angular'
|
|
90
|
+
|
|
91
|
+
@Component({
|
|
92
|
+
selector: 'app-home',
|
|
93
|
+
template: '<h1>Home</h1>',
|
|
94
|
+
})
|
|
95
|
+
export class HomeComponent implements OnInit {
|
|
96
|
+
constructor(private unhead: Unhead) {}
|
|
97
|
+
|
|
98
|
+
ngOnInit() {
|
|
99
|
+
this.unhead.useSeoMeta({
|
|
100
|
+
title: 'Home Page',
|
|
101
|
+
description: 'Welcome to our website',
|
|
102
|
+
ogTitle: 'Welcome to Home Page',
|
|
103
|
+
ogDescription: 'Our fantastic home page',
|
|
104
|
+
ogImage: 'https://example.com/image.jpg',
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Reactive Head Elements
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// profile.component.ts
|
|
114
|
+
import { Component, signal } from '@angular/core'
|
|
115
|
+
import { Unhead } from '@unhead/angular'
|
|
116
|
+
|
|
117
|
+
@Component({
|
|
118
|
+
selector: 'app-profile',
|
|
119
|
+
template: `
|
|
120
|
+
<h1>{{ userName() }}'s Profile</h1>
|
|
121
|
+
<button (click)="updateName('New Name')">Update Name</button>
|
|
122
|
+
`,
|
|
123
|
+
})
|
|
124
|
+
export class ProfileComponent {
|
|
125
|
+
userName = signal('User')
|
|
126
|
+
|
|
127
|
+
constructor(private unhead: Unhead) {
|
|
128
|
+
this.unhead.useHead({
|
|
129
|
+
title: () => `${this.userName()} - Profile`, // Reactive title
|
|
130
|
+
meta: [
|
|
131
|
+
{
|
|
132
|
+
name: 'description',
|
|
133
|
+
content: () => `${this.userName()}'s profile page`, // Reactive description
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updateName(name: string) {
|
|
140
|
+
this.userName.set(name)
|
|
141
|
+
// Title and meta automatically update!
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Install dependencies
|
|
150
|
+
npm install
|
|
151
|
+
|
|
152
|
+
# Generate build files
|
|
153
|
+
npm run build
|
|
154
|
+
|
|
155
|
+
# Run tests
|
|
156
|
+
npm run test
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
[MIT](./LICENSE)
|
|
162
|
+
|
|
163
|
+
<!-- Badges -->
|
|
164
|
+
[npm-version-src]: https://img.shields.io/npm/v/@unhead/angular/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
165
|
+
[npm-version-href]: https://npmjs.com/package/@unhead/angular
|
|
166
|
+
|
|
167
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@unhead/angular.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
168
|
+
[npm-downloads-href]: https://npmjs.com/package/@unhead/angular
|
|
169
|
+
|
|
170
|
+
[license-src]: https://img.shields.io/github/license/unjs/unhead.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
171
|
+
[license-href]: https://github.com/unjs/unhead/blob/main/LICENSE
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Inject, InjectionToken, makeEnvironmentProviders, inject, DestroyRef, effect, CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
|
|
3
|
+
import { useHead as useHead$1, useHeadSafe as useHeadSafe$1, useSeoMeta as useSeoMeta$1, useScript as useScript$1 } from 'unhead';
|
|
4
|
+
import { BEFORE_APP_SERIALIZED } from '@angular/platform-server';
|
|
5
|
+
import { createHead as createHead$1, createDebouncedFn, renderDOMHead } from 'unhead/client';
|
|
6
|
+
import { renderSSRHead, createHead } from 'unhead/server';
|
|
7
|
+
import { DOCUMENT } from '@angular/common';
|
|
8
|
+
|
|
9
|
+
function attrToElement(element, acc) {
|
|
10
|
+
const [key, value] = acc.match(/([a-z0-9-]+)(?:="([^"]*)")?/i)?.slice(1, 3) || [];
|
|
11
|
+
if (!key)
|
|
12
|
+
return;
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
element.setAttribute(key, '');
|
|
15
|
+
}
|
|
16
|
+
else if (key === 'style') {
|
|
17
|
+
const styleObj = value.split(';').reduce((acc, style) => {
|
|
18
|
+
const [prop, val] = style.split(':').map(s => s.trim());
|
|
19
|
+
if (prop && val)
|
|
20
|
+
acc[prop] = val;
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
Object.entries(styleObj).forEach(([prop, val]) => {
|
|
24
|
+
element.style.setProperty(prop, val);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else if (key === 'class') {
|
|
28
|
+
value.split(' ').forEach(className => element.classList.add(className));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
element.setAttribute(key, value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const attrRegex = /([a-z0-9-]+(?:="[^"]*")?)/gi;
|
|
35
|
+
class Unhead {
|
|
36
|
+
document;
|
|
37
|
+
unhead;
|
|
38
|
+
constructor(document, unhead) {
|
|
39
|
+
this.document = document;
|
|
40
|
+
this.unhead = unhead;
|
|
41
|
+
}
|
|
42
|
+
async _ssrModifyResponse() {
|
|
43
|
+
const { headTags, htmlAttrs, bodyAttrs, bodyTags, bodyTagsOpen } = await renderSSRHead(this.unhead, {
|
|
44
|
+
omitLineBreaks: false,
|
|
45
|
+
});
|
|
46
|
+
htmlAttrs.match(attrRegex)?.forEach(attr => attrToElement(this.document.documentElement, attr));
|
|
47
|
+
bodyAttrs.match(attrRegex)?.forEach(attr => attrToElement(this.document.body, attr));
|
|
48
|
+
this.document.body.innerHTML = bodyTagsOpen + this.document.body.innerHTML + bodyTags;
|
|
49
|
+
this.document.head.innerHTML = headTags + this.document.head.innerHTML;
|
|
50
|
+
}
|
|
51
|
+
static ɵfac = function Unhead_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || Unhead)(i0.ɵɵinject(DOCUMENT), i0.ɵɵinject(UnheadInjectionToken)); };
|
|
52
|
+
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: Unhead, factory: Unhead.ɵfac, providedIn: 'root' });
|
|
53
|
+
}
|
|
54
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(Unhead, [{
|
|
55
|
+
type: Injectable,
|
|
56
|
+
args: [{
|
|
57
|
+
providedIn: 'root',
|
|
58
|
+
}]
|
|
59
|
+
}], () => [{ type: Document, decorators: [{
|
|
60
|
+
type: Inject,
|
|
61
|
+
args: [DOCUMENT]
|
|
62
|
+
}] }, { type: undefined, decorators: [{
|
|
63
|
+
type: Inject,
|
|
64
|
+
args: [UnheadInjectionToken]
|
|
65
|
+
}] }], null); })();
|
|
66
|
+
|
|
67
|
+
const headSymbol = 'usehead';
|
|
68
|
+
const UnheadInjectionToken = new InjectionToken(headSymbol);
|
|
69
|
+
function provideServerHead(options = {}) {
|
|
70
|
+
const head = createHead(options);
|
|
71
|
+
return makeEnvironmentProviders([
|
|
72
|
+
{ provide: UnheadInjectionToken, useValue: head },
|
|
73
|
+
Unhead,
|
|
74
|
+
{
|
|
75
|
+
provide: BEFORE_APP_SERIALIZED,
|
|
76
|
+
useFactory: (service) => () => {
|
|
77
|
+
return service._ssrModifyResponse();
|
|
78
|
+
},
|
|
79
|
+
deps: [Unhead],
|
|
80
|
+
multi: true,
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
function provideClientHead(options = {}) {
|
|
85
|
+
const head = createHead$1({
|
|
86
|
+
domOptions: {
|
|
87
|
+
render: createDebouncedFn(() => renderDOMHead(head), fn => setTimeout(() => fn(), 0)),
|
|
88
|
+
},
|
|
89
|
+
...options,
|
|
90
|
+
});
|
|
91
|
+
return makeEnvironmentProviders([
|
|
92
|
+
{ provide: UnheadInjectionToken, useValue: head },
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function useUnhead() {
|
|
97
|
+
const instance = inject(UnheadInjectionToken);
|
|
98
|
+
if (!instance) {
|
|
99
|
+
throw new Error('useHead() was called without proper injection context.');
|
|
100
|
+
}
|
|
101
|
+
return instance;
|
|
102
|
+
}
|
|
103
|
+
function withSideEffects(input, options, fn) {
|
|
104
|
+
const head = options.head || useUnhead();
|
|
105
|
+
const entry = fn(head, input, options);
|
|
106
|
+
const destroyRef = inject(DestroyRef);
|
|
107
|
+
destroyRef.onDestroy(() => {
|
|
108
|
+
entry.dispose();
|
|
109
|
+
});
|
|
110
|
+
return entry;
|
|
111
|
+
}
|
|
112
|
+
function useHead(input = {}, options = {}) {
|
|
113
|
+
return withSideEffects(input, options, useHead$1);
|
|
114
|
+
}
|
|
115
|
+
function useHeadSafe(input = {}, options = {}) {
|
|
116
|
+
return withSideEffects(input, options, useHeadSafe$1);
|
|
117
|
+
}
|
|
118
|
+
function useSeoMeta(input = {}, options = {}) {
|
|
119
|
+
return withSideEffects(input, options, useSeoMeta$1);
|
|
120
|
+
}
|
|
121
|
+
function useScript(_input, _options) {
|
|
122
|
+
const input = (typeof _input === 'string' ? { src: _input } : _input);
|
|
123
|
+
const options = _options || {};
|
|
124
|
+
const head = options?.head || useUnhead();
|
|
125
|
+
options.head = head;
|
|
126
|
+
const mountCbs = [];
|
|
127
|
+
const sideEffects = [];
|
|
128
|
+
let isMounted = false;
|
|
129
|
+
const destroyRef = inject(DestroyRef);
|
|
130
|
+
effect(() => {
|
|
131
|
+
isMounted = true;
|
|
132
|
+
mountCbs.forEach(i => i());
|
|
133
|
+
});
|
|
134
|
+
if (typeof options.trigger === 'undefined') {
|
|
135
|
+
options.trigger = (load) => {
|
|
136
|
+
if (isMounted) {
|
|
137
|
+
load();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
mountCbs.push(load);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// @ts-expect-error untyped
|
|
145
|
+
const script = useScript$1(head, input, options);
|
|
146
|
+
const _registerCb = (key, cb) => {
|
|
147
|
+
let i;
|
|
148
|
+
const destroy = () => {
|
|
149
|
+
// avoid removing the wrong callback
|
|
150
|
+
if (i) {
|
|
151
|
+
script._cbs[key]?.splice(i - 1, 1);
|
|
152
|
+
i = null;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
mountCbs.push(() => {
|
|
156
|
+
if (!script._cbs[key]) {
|
|
157
|
+
cb(script.instance);
|
|
158
|
+
return () => { };
|
|
159
|
+
}
|
|
160
|
+
i = script._cbs[key].push(cb);
|
|
161
|
+
sideEffects.push(destroy);
|
|
162
|
+
return destroy;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
destroyRef.onDestroy(() => {
|
|
166
|
+
isMounted = false;
|
|
167
|
+
script._triggerAbortController?.abort();
|
|
168
|
+
sideEffects.forEach(i => i());
|
|
169
|
+
});
|
|
170
|
+
script.onLoaded = (cb) => _registerCb('loaded', cb);
|
|
171
|
+
script.onError = (cb) => _registerCb('error', cb);
|
|
172
|
+
return script;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const _c0 = ["*"];
|
|
176
|
+
class Head {
|
|
177
|
+
headEntry = useHead({});
|
|
178
|
+
updateHead(nodes) {
|
|
179
|
+
const transformed = this.transformNodes(nodes);
|
|
180
|
+
this.headEntry.patch(transformed);
|
|
181
|
+
}
|
|
182
|
+
transformNodes(nodes) {
|
|
183
|
+
const result = {};
|
|
184
|
+
const processNode = (node) => {
|
|
185
|
+
if (typeof node.type === 'symbol') {
|
|
186
|
+
node.children?.forEach(child => processNode(child));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const type = node.type;
|
|
190
|
+
if (node.children?.length === 1) {
|
|
191
|
+
result[type] = node.children[0];
|
|
192
|
+
}
|
|
193
|
+
else if (Object.keys(node.props || {}).length) {
|
|
194
|
+
result[type] = result[type] || [];
|
|
195
|
+
result[type].push(node.props);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
nodes.forEach(processNode);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
ngOnDestroy() {
|
|
202
|
+
this.headEntry.dispose();
|
|
203
|
+
}
|
|
204
|
+
static ɵfac = function Head_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || Head)(); };
|
|
205
|
+
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: Head, selectors: [["unhead-head"]], ngContentSelectors: _c0, decls: 1, vars: 0, template: function Head_Template(rf, ctx) { if (rf & 1) {
|
|
206
|
+
i0.ɵɵprojectionDef();
|
|
207
|
+
i0.ɵɵprojection(0);
|
|
208
|
+
} }, encapsulation: 2 });
|
|
209
|
+
}
|
|
210
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(Head, [{
|
|
211
|
+
type: Component,
|
|
212
|
+
args: [{
|
|
213
|
+
selector: 'unhead-head',
|
|
214
|
+
standalone: true,
|
|
215
|
+
template: '<ng-content></ng-content>',
|
|
216
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
217
|
+
}]
|
|
218
|
+
}], null, null); })();
|
|
219
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(Head, { className: "Head", filePath: "lib/head.component.ts", lineNumber: 17 }); })();
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
* Public API Surface of unhead
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Generated bundle index. Do not edit.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
export { Head, Unhead, UnheadInjectionToken, headSymbol, provideClientHead, provideServerHead, useHead, useHeadSafe, useScript, useSeoMeta, useUnhead };
|
|
230
|
+
//# sourceMappingURL=unhead-angular.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unhead-angular.mjs","sources":["../../src/lib/unhead.service.ts","../../src/unhead/install.ts","../../src/unhead/composables.ts","../../src/lib/head.component.ts","../../src/public-api.ts","../../src/unhead-angular.ts"],"sourcesContent":["import type { Unhead as UnheadSchema } from 'unhead/types'\nimport { DOCUMENT } from '@angular/common'\nimport { Inject, Injectable, Optional } from '@angular/core'\nimport { renderSSRHead } from 'unhead/server'\nimport { UnheadInjectionToken } from '../unhead/install'\n\nfunction attrToElement(element: HTMLElement, acc: string) {\n const [key, value] = acc.match(/([a-z0-9-]+)(?:=\"([^\"]*)\")?/i)?.slice(1, 3) || []\n if (!key)\n return\n\n if (value === undefined) {\n element.setAttribute(key, '')\n }\n else if (key === 'style') {\n const styleObj = value.split(';').reduce((acc, style) => {\n const [prop, val] = style.split(':').map(s => s.trim())\n if (prop && val)\n acc[prop] = val\n return acc\n }, {} as Record<string, string>)\n Object.entries(styleObj).forEach(([prop, val]) => {\n element.style.setProperty(prop, val)\n })\n }\n else if (key === 'class') {\n value.split(' ').forEach(className => element.classList.add(className))\n }\n else {\n element.setAttribute(key, value)\n }\n}\n\nconst attrRegex = /([a-z0-9-]+(?:=\"[^\"]*\")?)/gi\n\n@Injectable({\n providedIn: 'root',\n})\nexport class Unhead {\n constructor(\n @Inject(DOCUMENT) private document: Document,\n @Inject(UnheadInjectionToken) private unhead: UnheadSchema,\n ) {}\n\n async _ssrModifyResponse() {\n const { headTags, htmlAttrs, bodyAttrs, bodyTags, bodyTagsOpen } = await renderSSRHead(this.unhead, {\n omitLineBreaks: false,\n })\n htmlAttrs.match(attrRegex)?.forEach(attr => attrToElement(this.document.documentElement, attr))\n bodyAttrs.match(attrRegex)?.forEach(attr => attrToElement(this.document.body, attr))\n this.document.body.innerHTML = bodyTagsOpen + this.document.body.innerHTML + bodyTags\n this.document.head.innerHTML = headTags + this.document.head.innerHTML\n }\n}\n","import type { CreateClientHeadOptions, CreateServerHeadOptions, Unhead as UnheadSchema } from 'unhead/types'\nimport { InjectionToken, makeEnvironmentProviders } from '@angular/core'\nimport { BEFORE_APP_SERIALIZED } from '@angular/platform-server'\nimport { createHead as _createClientHead, createDebouncedFn, renderDOMHead } from 'unhead/client'\nimport { createHead as _createServerHead } from 'unhead/server'\nimport { Unhead } from '../lib/unhead.service'\n\nexport const headSymbol = 'usehead'\n\nexport const UnheadInjectionToken = new InjectionToken<UnheadSchema>(headSymbol)\n\nexport function provideServerHead(options: CreateServerHeadOptions = {}) {\n const head = _createServerHead(options)\n return makeEnvironmentProviders([\n { provide: UnheadInjectionToken, useValue: head },\n Unhead,\n {\n provide: BEFORE_APP_SERIALIZED,\n useFactory: (service: Unhead) => () => {\n return service._ssrModifyResponse()\n },\n deps: [Unhead],\n multi: true,\n },\n ])\n}\n\nexport function provideClientHead(options: CreateClientHeadOptions = {}) {\n const head = _createClientHead({\n domOptions: {\n render: createDebouncedFn(() => renderDOMHead(head), fn => setTimeout(() => fn(), 0)),\n },\n ...options,\n })\n return makeEnvironmentProviders([\n { provide: UnheadInjectionToken, useValue: head },\n ])\n}\n","import type { UseScriptInput, UseScriptOptions, UseScriptReturn } from 'unhead/scripts'\nimport type { ActiveHeadEntry, HeadEntryOptions, HeadSafe, Unhead, UseHeadInput, UseSeoMetaInput } from 'unhead/types'\nimport { DestroyRef, effect, inject } from '@angular/core'\nimport { useHead as baseHead, useHeadSafe as baseHeadSafe, useSeoMeta as baseSeoMeta, useScript as baseUseScript } from 'unhead'\nimport { UnheadInjectionToken } from './install'\n\nexport function useUnhead() {\n const instance = inject<Unhead>(UnheadInjectionToken)\n if (!instance) {\n throw new Error('useHead() was called without proper injection context.')\n }\n return instance\n}\n\nfunction withSideEffects<T extends ActiveHeadEntry<any>>(input: any, options: any, fn: any): T {\n const head = options.head || useUnhead()\n const entry = fn(head, input, options)\n\n const destroyRef = inject(DestroyRef)\n destroyRef.onDestroy(() => {\n entry.dispose()\n })\n\n return entry\n}\n\nexport function useHead(input: UseHeadInput = {}, options: HeadEntryOptions = {}): ActiveHeadEntry<UseHeadInput> {\n return withSideEffects(input, options, baseHead)\n}\n\nexport function useHeadSafe(input: HeadSafe = {}, options: HeadEntryOptions = {}): ActiveHeadEntry<HeadSafe> {\n return withSideEffects<ActiveHeadEntry<HeadSafe>>(input, options, baseHeadSafe)\n}\n\nexport function useSeoMeta(input: UseSeoMetaInput = {}, options: HeadEntryOptions = {}): ActiveHeadEntry<UseSeoMetaInput> {\n return withSideEffects<ActiveHeadEntry<UseSeoMetaInput>>(input, options, baseSeoMeta)\n}\n\nexport function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptReturn<T> {\n const input = (typeof _input === 'string' ? { src: _input } : _input) as UseScriptInput\n const options = _options || {} as UseScriptOptions<T>\n const head = options?.head || useUnhead()\n options.head = head\n\n const mountCbs: (() => void)[] = []\n const sideEffects: (() => void)[] = []\n let isMounted = false\n\n const destroyRef = inject(DestroyRef)\n\n effect(() => {\n isMounted = true\n mountCbs.forEach(i => i())\n })\n\n if (typeof options.trigger === 'undefined') {\n options.trigger = (load) => {\n if (isMounted) {\n load()\n }\n else {\n mountCbs.push(load)\n }\n }\n }\n\n // @ts-expect-error untyped\n const script = baseUseScript(head, input as BaseUseScriptInput, options)\n\n const _registerCb = (key: 'loaded' | 'error', cb: any) => {\n let i: number | null\n const destroy = () => {\n // avoid removing the wrong callback\n if (i) {\n script._cbs[key]?.splice(i - 1, 1)\n i = null\n }\n }\n mountCbs.push(() => {\n if (!script._cbs[key]) {\n cb(script.instance)\n return () => {}\n }\n i = script._cbs[key].push(cb)\n sideEffects.push(destroy)\n return destroy\n })\n }\n\n destroyRef.onDestroy(() => {\n isMounted = false\n script._triggerAbortController?.abort()\n sideEffects.forEach(i => i())\n })\n script.onLoaded = (cb: (instance: T) => void | Promise<void>) => _registerCb('loaded', cb)\n script.onError = (cb: (err?: Error) => void | Promise<void>) => _registerCb('error', cb)\n return script\n}\n","import type { OnDestroy } from '@angular/core'\nimport { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'\nimport { useHead } from '../unhead/composables'\n\ninterface NodeProps {\n type: string | symbol\n props?: Record<string, any>\n children?: NodeProps[]\n}\n\n@Component({\n selector: 'unhead-head',\n standalone: true,\n template: '<ng-content></ng-content>',\n schemas: [CUSTOM_ELEMENTS_SCHEMA],\n})\nexport class Head implements OnDestroy {\n private headEntry = useHead({})\n\n updateHead(nodes: NodeProps[]) {\n const transformed = this.transformNodes(nodes)\n this.headEntry.patch(transformed)\n }\n\n private transformNodes(nodes: NodeProps[]) {\n const result: Record<string, any> = {}\n\n const processNode = (node: NodeProps) => {\n if (typeof node.type === 'symbol') {\n node.children?.forEach(child => processNode(child as NodeProps))\n return\n }\n\n const type = node.type as string\n if (node.children?.length === 1) {\n result[type] = node.children[0]\n }\n else if (Object.keys(node.props || {}).length) {\n result[type] = result[type] || []\n result[type].push(node.props)\n }\n }\n\n nodes.forEach(processNode)\n return result\n }\n\n ngOnDestroy() {\n this.headEntry.dispose()\n }\n}\n","/*\n * Public API Surface of unhead\n */\n\nexport * from './lib/head.component'\nexport * from './lib/unhead.service'\nexport * from './unhead/composables'\nexport * from './unhead/install'\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["_createServerHead","_createClientHead","baseHead","baseHeadSafe","baseSeoMeta","baseUseScript"],"mappings":";;;;;;;;AAMA,SAAS,aAAa,CAAC,OAAoB,EAAE,GAAW,EAAA;IACtD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE;AACjF,IAAA,IAAI,CAAC,GAAG;QACN;AAEF,IAAA,IAAI,KAAK,KAAK,SAAS,EAAE;AACvB,QAAA,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC;;AAE1B,SAAA,IAAI,GAAG,KAAK,OAAO,EAAE;AACxB,QAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,KAAI;YACtD,MAAM,CA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AACT,gBAAA,QAAQ,EAAE,aAAa;AACvB,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,QAAQ,EAAE,2BAA2B;gBACrC,OAAO,EAAE,CAAC,sBAAsB,CAAC;AAClC,aAAA;;kFACY,IAAI,EAAA,EAAA,SAAA,EAAA,MAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,UAAA,EAAA,EAAA,EAAA,CAAA,CAAA,EAAA,GAAA;;AChBjB;;AAEG;;ACFH;;AAEG;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { OnDestroy } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
interface NodeProps {
|
|
4
|
+
type: string | symbol;
|
|
5
|
+
props?: Record<string, any>;
|
|
6
|
+
children?: NodeProps[];
|
|
7
|
+
}
|
|
8
|
+
export declare class Head implements OnDestroy {
|
|
9
|
+
private headEntry;
|
|
10
|
+
updateHead(nodes: NodeProps[]): void;
|
|
11
|
+
private transformNodes;
|
|
12
|
+
ngOnDestroy(): void;
|
|
13
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Head, never>;
|
|
14
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<Head, "unhead-head", never, {}, {}, never, ["*"], true, never>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=head.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head.component.d.ts","sourceRoot":"","sources":["../../src/lib/head.component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;;AAI9C,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAA;CACvB;AAED,qBAMa,IAAK,YAAW,SAAS;IACpC,OAAO,CAAC,SAAS,CAAc;IAE/B,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE;IAK7B,OAAO,CAAC,cAAc;IAuBtB,WAAW;yCA/BA,IAAI;2CAAJ,IAAI;CAkChB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Unhead as UnheadSchema } from 'unhead/types';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export declare class Unhead {
|
|
4
|
+
private document;
|
|
5
|
+
private unhead;
|
|
6
|
+
constructor(document: Document, unhead: UnheadSchema);
|
|
7
|
+
_ssrModifyResponse(): Promise<void>;
|
|
8
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Unhead, never>;
|
|
9
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<Unhead>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unhead.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unhead.service.d.ts","sourceRoot":"","sources":["../../src/lib/unhead.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;;AAmC1D,qBAGa,MAAM;IAEG,OAAO,CAAC,QAAQ;IACJ,OAAO,CAAC,MAAM;gBADlB,QAAQ,EAAE,QAAQ,EACN,MAAM,EAAE,YAAY;IAGtD,kBAAkB;yCANb,MAAM;6CAAN,MAAM;CAelB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UseScriptInput, UseScriptOptions, UseScriptReturn } from 'unhead/scripts';
|
|
2
|
+
import type { ActiveHeadEntry, HeadEntryOptions, HeadSafe, Unhead, UseHeadInput, UseSeoMetaInput } from 'unhead/types';
|
|
3
|
+
export declare function useUnhead(): Unhead<import("unhead/types").Head<import("unhead/types").SchemaAugmentations>>;
|
|
4
|
+
export declare function useHead(input?: UseHeadInput, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput>;
|
|
5
|
+
export declare function useHeadSafe(input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
6
|
+
export declare function useSeoMeta(input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
|
|
7
|
+
export declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptReturn<T>;
|
|
8
|
+
//# sourceMappingURL=composables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composables.d.ts","sourceRoot":"","sources":["../../src/unhead/composables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAKtH,wBAAgB,SAAS,oFAMxB;AAcD,wBAAgB,OAAO,CAAC,KAAK,GAAE,YAAiB,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAAC,YAAY,CAAC,CAE/G;AAED,wBAAgB,WAAW,CAAC,KAAK,GAAE,QAAa,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAAC,QAAQ,CAAC,CAE3G;AAED,wBAAgB,UAAU,CAAC,KAAK,GAAE,eAAoB,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAAC,eAAe,CAAC,CAExH;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CA2D3K"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CreateClientHeadOptions, CreateServerHeadOptions, Unhead as UnheadSchema } from 'unhead/types';
|
|
2
|
+
import { InjectionToken } from '@angular/core';
|
|
3
|
+
export declare const headSymbol = "usehead";
|
|
4
|
+
export declare const UnheadInjectionToken: InjectionToken<UnheadSchema<import("unhead/types").Head<import("unhead/types").SchemaAugmentations>>>;
|
|
5
|
+
export declare function provideServerHead(options?: CreateServerHeadOptions): import("@angular/core").EnvironmentProviders;
|
|
6
|
+
export declare function provideClientHead(options?: CreateClientHeadOptions): import("@angular/core").EnvironmentProviders;
|
|
7
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/unhead/install.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AAC5G,OAAO,EAAE,cAAc,EAA4B,MAAM,eAAe,CAAA;AAMxE,eAAO,MAAM,UAAU,YAAY,CAAA;AAEnC,eAAO,MAAM,oBAAoB,uGAA+C,CAAA;AAEhF,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,uBAA4B,gDActE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,uBAA4B,gDAUtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unhead-angular.d.ts","sourceRoot":"","sources":["../src/unhead-angular.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,cAAc,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unhead/angular",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.0-alpha.19",
|
|
5
|
+
"description": "Full-stack <head> manager built for Angular.",
|
|
6
|
+
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"funding": "https://github.com/sponsors/harlan-zw",
|
|
9
|
+
"homepage": "https://unhead.unjs.io",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/unjs/unhead.git",
|
|
13
|
+
"directory": "packages/angular"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"tag": "next"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/unjs/unhead/issues"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"module": "dist/fesm2022/unhead-angular.mjs",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/fesm2022/unhead-angular.mjs"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@angular/common": "^19.1.5",
|
|
34
|
+
"@angular/core": "^19.1.5"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"unhead": "2.0.0-alpha.19"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@angular/platform-browser-dynamic": "^19.1.5",
|
|
41
|
+
"@vitest/coverage-istanbul": "^1.2.1",
|
|
42
|
+
"zone.js": "^0.15.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "ng build",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest",
|
|
48
|
+
"test:coverage": "vitest run --coverage"
|
|
49
|
+
}
|
|
50
|
+
}
|