@analogjs/astro-angular 2.5.0-beta.4 → 2.5.0-beta.6
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 +57 -0
- package/package.json +4 -2
- package/src/client-ngh.d.ts +8 -0
- package/src/client-ngh.d.ts.map +1 -0
- package/src/client-ngh.js +53 -0
- package/src/client-ngh.js.map +1 -0
- package/src/context.d.ts +12 -0
- package/src/context.d.ts.map +1 -0
- package/src/context.js +21 -0
- package/src/context.js.map +1 -0
- package/src/create-component.d.ts +6 -0
- package/src/create-component.d.ts.map +1 -0
- package/src/create-component.js +35 -0
- package/src/create-component.js.map +1 -0
- package/src/id.d.ts +5 -0
- package/src/id.d.ts.map +1 -0
- package/src/id.js +5 -0
- package/src/id.js.map +1 -0
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +15 -8
- package/src/index.js.map +1 -1
- package/src/middleware.d.ts.map +1 -1
- package/src/middleware.js +3 -1
- package/src/middleware.js.map +1 -1
- package/src/server-ngh.d.ts +18 -0
- package/src/server-ngh.d.ts.map +1 -0
- package/src/server-ngh.js +76 -0
- package/src/server-ngh.js.map +1 -0
- package/src/server-providers.d.ts +9 -0
- package/src/server-providers.d.ts.map +1 -0
- package/src/server-providers.js +25 -0
- package/src/server-providers.js.map +1 -0
- package/src/ssr-integrity.d.ts +2 -0
- package/src/ssr-integrity.d.ts.map +1 -0
- package/src/ssr-integrity.js +13 -0
- package/src/ssr-integrity.js.map +1 -0
package/README.md
CHANGED
|
@@ -191,6 +191,26 @@ export default defineConfig({
|
|
|
191
191
|
});
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
### Angular Client Hydration (Experimental)
|
|
195
|
+
|
|
196
|
+
By default, `@analogjs/astro-angular` performs hydration by bootstrapping the component on the client, replacing the DOM that was rendered on the server.
|
|
197
|
+
|
|
198
|
+
To opt-in to Angular's client hydration, enable the `experimental.useAngularHydration` option in the integration config. This will switch the hydration strategy to use [provideClientHydration](https://angular.dev/api/platform-browser/provideClientHydration).
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
import { defineConfig } from 'astro/config';
|
|
202
|
+
|
|
203
|
+
import angular from '@analogjs/astro-angular';
|
|
204
|
+
|
|
205
|
+
export default defineConfig({
|
|
206
|
+
integrations: [angular({ useAngularHydration: true })],
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Skip Hydration
|
|
211
|
+
|
|
212
|
+
Use the `ngSkipHydration` attribute on any components which do not work properly with hydration enabled. Read more [here](https://angular.dev/guide/hydration#how-to-skip-hydration-for-particular-components).
|
|
213
|
+
|
|
194
214
|
## Defining A Component
|
|
195
215
|
|
|
196
216
|
The Astro Angular integration **only** supports rendering standalone components:
|
|
@@ -323,6 +343,43 @@ export class TodosComponent implements OnInit {
|
|
|
323
343
|
}
|
|
324
344
|
```
|
|
325
345
|
|
|
346
|
+
### Client Hydration Features (Experimental)
|
|
347
|
+
|
|
348
|
+
First, make sure the experimental Angular client hydration option is enabled in the integration config. Read more [here](#angular-client-hydration-experimental).
|
|
349
|
+
|
|
350
|
+
To add Angular hydration features, add a static property to the component class named `hydrationFeatures`. This should be a function that returns an array of hydration features to enable.
|
|
351
|
+
|
|
352
|
+
The example below adds the [event replay](https://angular.dev/guide/hydration#how-event-replay-works) feature to the component.
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import { Component, input, signal } from '@angular/core';
|
|
356
|
+
import { withEventReplay } from '@angular/platform-browser';
|
|
357
|
+
|
|
358
|
+
@Component({
|
|
359
|
+
selector: 'app-hello',
|
|
360
|
+
template: `
|
|
361
|
+
<p>Hello from Angular!!</p>
|
|
362
|
+
|
|
363
|
+
@if (show()) {
|
|
364
|
+
<p>{{ helpText() }}</p>
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
<button (click)="toggle()">Toggle</button>
|
|
368
|
+
`,
|
|
369
|
+
})
|
|
370
|
+
export class HelloComponent {
|
|
371
|
+
static hydrationFeatures = () => [withEventReplay()];
|
|
372
|
+
|
|
373
|
+
helpText = input('help');
|
|
374
|
+
|
|
375
|
+
show = signal(false);
|
|
376
|
+
|
|
377
|
+
toggle() {
|
|
378
|
+
this.show.update((show) => !show);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
326
383
|
## Using Components in MDX pages
|
|
327
384
|
|
|
328
385
|
To use components with MDX pages, you must install and configure MDX support by following the Astro integration of [@astrojs/mdx](https://docs.astro.build/en/guides/integrations-guide/mdx/). Your `astro.config.mjs` should now include the `@astrojs/mdx` integration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/astro-angular",
|
|
3
|
-
"version": "2.5.0-beta.
|
|
3
|
+
"version": "2.5.0-beta.6",
|
|
4
4
|
"description": "Use Angular components within Astro",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Brandon Roberts <robertsbt@gmail.com>",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
".": "./src/index.js",
|
|
9
9
|
"./utils": "./src/utils.js",
|
|
10
10
|
"./client.js": "./src/client.js",
|
|
11
|
+
"./client-ngh.js": "./src/client-ngh.js",
|
|
11
12
|
"./server.js": "./src/server.js",
|
|
13
|
+
"./server-ngh.js": "./src/server-ngh.js",
|
|
12
14
|
"./package.json": "./package.json"
|
|
13
15
|
},
|
|
14
16
|
"keywords": [
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
"url": "https://github.com/sponsors/brandonroberts"
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"@analogjs/vite-plugin-angular": "^2.5.0-beta.
|
|
37
|
+
"@analogjs/vite-plugin-angular": "^2.5.0-beta.6",
|
|
36
38
|
"rehype": "^13.0.2"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EnvironmentProviders, type Provider, Type } from '@angular/core';
|
|
2
|
+
import { type HydrationFeature, type HydrationFeatureKind } from '@angular/platform-browser';
|
|
3
|
+
declare const _default: (element: HTMLElement) => (Component: Type<unknown> & {
|
|
4
|
+
clientProviders?: (Provider | EnvironmentProviders)[];
|
|
5
|
+
hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
|
|
6
|
+
}, props?: Record<string, unknown>) => void;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=client-ngh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ngh.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/client-ngh.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,QAAQ,EAGb,IAAI,EAIL,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAE1B,MAAM,2BAA2B,CAAC;yBAQnB,SAAS,WAAW,MAEhC,WAAW,IAAI,CAAC,OAAO,CAAC,GAAG;IACzB,eAAe,CAAC,EAAE,CAAC,QAAQ,GAAG,oBAAoB,CAAC,EAAE,CAAC;IACtD,iBAAiB,CAAC,EAAE,MAAM,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,CAAC;CACpE,EACD,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;AANnC,wBA6DE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { reflectComponentType, provideZonelessChangeDetection, APP_ID, createComponent, APP_BOOTSTRAP_LISTENER, } from '@angular/core';
|
|
2
|
+
import { createApplication, provideClientHydration, } from '@angular/platform-browser';
|
|
3
|
+
import { createComponentBindings, getComponentElementTag, } from "./create-component.js";
|
|
4
|
+
import { ID_PROP_NAME } from "./id.js";
|
|
5
|
+
import { ensureSsrIntegrityMarker } from "./ssr-integrity.js";
|
|
6
|
+
export default (element) => {
|
|
7
|
+
return (Component, props) => {
|
|
8
|
+
const mirror = reflectComponentType(Component);
|
|
9
|
+
if (!mirror) {
|
|
10
|
+
// Not an Angular component
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
ensureSsrIntegrityMarker();
|
|
14
|
+
let hostElement = element.querySelector(mirror.selector);
|
|
15
|
+
let reuseDom = true;
|
|
16
|
+
if (!hostElement) {
|
|
17
|
+
// This is a client-only component
|
|
18
|
+
hostElement = document.createElement(getComponentElementTag(mirror));
|
|
19
|
+
element.appendChild(hostElement);
|
|
20
|
+
reuseDom = false;
|
|
21
|
+
}
|
|
22
|
+
const ngAppId = hostElement?.getAttribute(ID_PROP_NAME);
|
|
23
|
+
createApplication({
|
|
24
|
+
providers: [
|
|
25
|
+
provideZonelessChangeDetection(),
|
|
26
|
+
reuseDom
|
|
27
|
+
? provideClientHydration(...(Component.hydrationFeatures?.() || []))
|
|
28
|
+
: [],
|
|
29
|
+
{
|
|
30
|
+
provide: APP_ID,
|
|
31
|
+
useValue: ngAppId || 'ng',
|
|
32
|
+
},
|
|
33
|
+
...(Component.clientProviders || []),
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
.then((appRef) => {
|
|
37
|
+
const componentRef = createComponent(Component, {
|
|
38
|
+
environmentInjector: appRef.injector,
|
|
39
|
+
hostElement,
|
|
40
|
+
bindings: createComponentBindings(mirror, props, hostElement),
|
|
41
|
+
});
|
|
42
|
+
appRef.attachView(componentRef.hostView);
|
|
43
|
+
appRef.components.push(componentRef);
|
|
44
|
+
appRef.injector
|
|
45
|
+
.get(APP_BOOTSTRAP_LISTENER, [])
|
|
46
|
+
.forEach((cb) => cb(componentRef));
|
|
47
|
+
})
|
|
48
|
+
.catch((error) => {
|
|
49
|
+
console.error('Failed to hydrate Angular component:', error);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=client-ngh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ngh.js","source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CAAC,EAAE;gBACN;oBACE,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,OAAO,IAAI,IAAI;iBAC1B;gBACD,GAAG,CAAC,SAAS,CAAC,eAAe,IAAI,EAAE,CAAC;aACrC;SACF,CAAC;aACC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,EAAE;gBAC9C,mBAAmB,EAAE,MAAM,CAAC,QAAQ;gBACpC,WAAW;gBACX,QAAQ,EAAE,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC;aAC9D,CAAC,CAAC;YAEH,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YAEzC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAErC,MAAM,CAAC,QAAQ;iBACZ,GAAG,CAAC,sBAAsB,EAAE,EAAE,CAAC;iBAC/B,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n type EnvironmentProviders,\n type Provider,\n reflectComponentType,\n provideZonelessChangeDetection,\n Type,\n APP_ID,\n createComponent,\n APP_BOOTSTRAP_LISTENER,\n} from '@angular/core';\nimport {\n createApplication,\n type HydrationFeature,\n type HydrationFeatureKind,\n provideClientHydration,\n} from '@angular/platform-browser';\nimport {\n createComponentBindings,\n getComponentElementTag,\n} from './create-component.ts';\nimport { ID_PROP_NAME } from './id.ts';\nimport { ensureSsrIntegrityMarker } from './ssr-integrity.ts';\n\nexport default (element: HTMLElement) => {\n return (\n Component: Type<unknown> & {\n clientProviders?: (Provider | EnvironmentProviders)[];\n hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];\n },\n props?: Record<string, unknown>,\n ) => {\n const mirror = reflectComponentType(Component);\n\n if (!mirror) {\n // Not an Angular component\n return;\n }\n\n ensureSsrIntegrityMarker();\n\n let hostElement = element.querySelector(mirror.selector);\n let reuseDom = true;\n\n if (!hostElement) {\n // This is a client-only component\n hostElement = document.createElement(getComponentElementTag(mirror));\n element.appendChild(hostElement);\n reuseDom = false;\n }\n\n const ngAppId = hostElement?.getAttribute(ID_PROP_NAME);\n\n createApplication({\n providers: [\n provideZonelessChangeDetection(),\n reuseDom\n ? provideClientHydration(...(Component.hydrationFeatures?.() || []))\n : [],\n {\n provide: APP_ID,\n useValue: ngAppId || 'ng',\n },\n ...(Component.clientProviders || []),\n ],\n })\n .then((appRef) => {\n const componentRef = createComponent(Component, {\n environmentInjector: appRef.injector,\n hostElement,\n bindings: createComponentBindings(mirror, props, hostElement),\n });\n\n appRef.attachView(componentRef.hostView);\n\n appRef.components.push(componentRef);\n\n appRef.injector\n .get(APP_BOOTSTRAP_LISTENER, [])\n .forEach((cb) => cb(componentRef));\n })\n .catch((error) => {\n console.error('Failed to hydrate Angular component:', error);\n });\n };\n};\n"]}
|
package/src/context.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SSRResult } from 'astro';
|
|
2
|
+
export type RendererContext = {
|
|
3
|
+
result: SSRResult;
|
|
4
|
+
};
|
|
5
|
+
type Context = {
|
|
6
|
+
c: number;
|
|
7
|
+
getId(): string;
|
|
8
|
+
};
|
|
9
|
+
export declare function getContext(result: SSRResult): Context;
|
|
10
|
+
export declare function incrementId(ctx: Context): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,IAAI,MAAM,CAAC;CACjB,CAAC;AAIF,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAarD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAIhD"}
|
package/src/context.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const contexts = new WeakMap();
|
|
2
|
+
export function getContext(result) {
|
|
3
|
+
let ctx = contexts.get(result);
|
|
4
|
+
if (ctx) {
|
|
5
|
+
return ctx;
|
|
6
|
+
}
|
|
7
|
+
ctx = {
|
|
8
|
+
c: 0,
|
|
9
|
+
getId() {
|
|
10
|
+
return 'analog-' + this.c.toString();
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
contexts.set(result, ctx);
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
export function incrementId(ctx) {
|
|
17
|
+
const id = ctx.getId();
|
|
18
|
+
ctx.c++;
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/context.ts"],"names":[],"mappings":"AAWA,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAsB,CAAC;AAEnD,MAAM,UAAU,UAAU,CAAC,MAAiB;IAC1C,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,GAAG,CAAC;IACb,CAAC;IACD,GAAG,GAAG;QACJ,CAAC,EAAE,CAAC;QACJ,KAAK;YACH,OAAO,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;KACF,CAAC;IACF,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;IACvB,GAAG,CAAC,CAAC,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import type { SSRResult } from 'astro';\n\nexport type RendererContext = {\n result: SSRResult;\n};\n\ntype Context = {\n c: number;\n getId(): string;\n};\n\nconst contexts = new WeakMap<SSRResult, Context>();\n\nexport function getContext(result: SSRResult): Context {\n let ctx = contexts.get(result);\n if (ctx) {\n return ctx;\n }\n ctx = {\n c: 0,\n getId() {\n return 'analog-' + this.c.toString();\n },\n };\n contexts.set(result, ctx);\n return ctx;\n}\n\nexport function incrementId(ctx: Context): string {\n const id = ctx.getId();\n ctx.c++;\n return id;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Binding, type ComponentMirror } from '@angular/core';
|
|
2
|
+
export declare function getComponentElementTag(mirror: ComponentMirror<unknown>): string;
|
|
3
|
+
export declare function createInputBindings(mirror: ComponentMirror<unknown>, props?: Record<string, unknown>): Binding[];
|
|
4
|
+
export declare function createOutputBindings(hostElement: Element, mirror: ComponentMirror<unknown>): Binding[];
|
|
5
|
+
export declare function createComponentBindings(mirror: ComponentMirror<unknown>, props?: Record<string, unknown>, hostElement?: Element): Binding[];
|
|
6
|
+
//# sourceMappingURL=create-component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-component.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/create-component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,eAAe,EAGrB,MAAM,eAAe,CAAC;AAGvB,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,EAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,EAAE,CAYX;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,OAAO,EAAE,CAcX;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,EAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,EAAE,CAUX"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { inputBinding, outputBinding, } from '@angular/core';
|
|
2
|
+
import { ID_PROP_NAME } from "./id.js";
|
|
3
|
+
export function getComponentElementTag(mirror) {
|
|
4
|
+
return mirror.selector.split(',')[0] || 'ng-component';
|
|
5
|
+
}
|
|
6
|
+
export function createInputBindings(mirror, props) {
|
|
7
|
+
if (!props) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
const inputBindings = Object.entries(props)
|
|
11
|
+
.filter(([key]) => mirror.inputs.some(({ templateName }) => templateName === key))
|
|
12
|
+
.map(([key, value]) => inputBinding(key, () => value));
|
|
13
|
+
return inputBindings;
|
|
14
|
+
}
|
|
15
|
+
export function createOutputBindings(hostElement, mirror) {
|
|
16
|
+
const outputBindings = mirror.outputs.map(({ templateName }) => outputBinding(templateName, (detail) => {
|
|
17
|
+
const event = new CustomEvent(templateName, {
|
|
18
|
+
bubbles: true,
|
|
19
|
+
cancelable: true,
|
|
20
|
+
composed: true,
|
|
21
|
+
detail,
|
|
22
|
+
});
|
|
23
|
+
hostElement.dispatchEvent(event);
|
|
24
|
+
}));
|
|
25
|
+
return outputBindings;
|
|
26
|
+
}
|
|
27
|
+
export function createComponentBindings(mirror, props, hostElement) {
|
|
28
|
+
const inputBindings = createInputBindings(mirror, props);
|
|
29
|
+
if (!mirror.outputs.length || !props?.[ID_PROP_NAME] || !hostElement) {
|
|
30
|
+
return inputBindings;
|
|
31
|
+
}
|
|
32
|
+
const outputBindings = createOutputBindings(hostElement, mirror);
|
|
33
|
+
return [...inputBindings, ...outputBindings];
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=create-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-component.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/create-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,UAAU,sBAAsB,CACpC,MAAgC;IAEhC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,MAAgC,EAChC,KAA+B;IAE/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SACxC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,GAAG,CAAC,CAC/D;SACA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEzD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,WAAoB,EACpB,MAAgC;IAEhC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAC7D,aAAa,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE;YAC1C,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,MAAM;SACP,CAAC,CAAC;QACH,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,MAAgC,EAChC,KAA+B,EAC/B,WAAqB;IAErB,MAAM,aAAa,GAAG,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAEzD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACrE,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,cAAc,GAAG,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAEjE,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,cAAc,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import {\n type Binding,\n type ComponentMirror,\n inputBinding,\n outputBinding,\n} from '@angular/core';\nimport { ID_PROP_NAME } from './id.ts';\n\nexport function getComponentElementTag(\n mirror: ComponentMirror<unknown>,\n): string {\n return mirror.selector.split(',')[0] || 'ng-component';\n}\n\nexport function createInputBindings(\n mirror: ComponentMirror<unknown>,\n props?: Record<string, unknown>,\n): Binding[] {\n if (!props) {\n return [];\n }\n\n const inputBindings = Object.entries(props)\n .filter(([key]) =>\n mirror.inputs.some(({ templateName }) => templateName === key),\n )\n .map(([key, value]) => inputBinding(key, () => value));\n\n return inputBindings;\n}\n\nexport function createOutputBindings(\n hostElement: Element,\n mirror: ComponentMirror<unknown>,\n): Binding[] {\n const outputBindings = mirror.outputs.map(({ templateName }) =>\n outputBinding(templateName, (detail) => {\n const event = new CustomEvent(templateName, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n });\n hostElement.dispatchEvent(event);\n }),\n );\n\n return outputBindings;\n}\n\nexport function createComponentBindings(\n mirror: ComponentMirror<unknown>,\n props?: Record<string, unknown>,\n hostElement?: Element,\n): Binding[] {\n const inputBindings = createInputBindings(mirror, props);\n\n if (!mirror.outputs.length || !props?.[ID_PROP_NAME] || !hostElement) {\n return inputBindings;\n }\n\n const outputBindings = createOutputBindings(hostElement, mirror);\n\n return [...inputBindings, ...outputBindings];\n}\n"]}
|
package/src/id.d.ts
ADDED
package/src/id.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/id.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,YAAY,mBAAmB,CAAC"}
|
package/src/id.js
ADDED
package/src/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/id.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["/**\n * Property name used to serialize the APP_ID of each component.\n */\nexport const ID_PROP_NAME = 'data-analog-id';\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ interface AngularOptions {
|
|
|
9
9
|
* Enabling this option disables astro's streaming under SSR.
|
|
10
10
|
*/
|
|
11
11
|
strictStylePlacement?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Use Angular's `provideClientHydration` to hydrate components.
|
|
14
|
+
*/
|
|
15
|
+
useAngularHydration?: boolean;
|
|
12
16
|
}
|
|
13
17
|
export default function (options?: AngularOptions): AstroIntegration;
|
|
14
18
|
export {};
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AACA,OAAoB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,OAAO,CAAC;AAE7E,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AACA,OAAoB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,OAAO,CAAC;AAE7E,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA0ED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAyBnE"}
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import viteAngular from '@analogjs/vite-plugin-angular';
|
|
3
3
|
import { enableProdMode } from '@angular/core';
|
|
4
|
-
function getRenderer() {
|
|
4
|
+
function getRenderer(ngHydration) {
|
|
5
5
|
return {
|
|
6
6
|
name: '@analogjs/astro-angular',
|
|
7
|
-
clientEntrypoint:
|
|
8
|
-
|
|
7
|
+
clientEntrypoint: ngHydration
|
|
8
|
+
? '@analogjs/astro-angular/client-ngh.js'
|
|
9
|
+
: '@analogjs/astro-angular/client.js',
|
|
10
|
+
serverEntrypoint: ngHydration
|
|
11
|
+
? '@analogjs/astro-angular/server-ngh.js'
|
|
12
|
+
: '@analogjs/astro-angular/server.js',
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
|
-
function getViteConfiguration(
|
|
15
|
+
function getViteConfiguration(options) {
|
|
12
16
|
return {
|
|
13
17
|
esbuild: {
|
|
14
18
|
jsxDev: true,
|
|
@@ -17,15 +21,18 @@ function getViteConfiguration(vite) {
|
|
|
17
21
|
include: [
|
|
18
22
|
'@angular/platform-browser',
|
|
19
23
|
'@angular/core',
|
|
20
|
-
|
|
24
|
+
options?.useAngularHydration
|
|
25
|
+
? '@analogjs/astro-angular/client-ngh.js'
|
|
26
|
+
: '@analogjs/astro-angular/client.js',
|
|
21
27
|
],
|
|
22
28
|
exclude: [
|
|
23
29
|
'@angular/platform-server',
|
|
24
30
|
'@analogjs/astro-angular/server.js',
|
|
31
|
+
'@analogjs/astro-angular/server-ngh.js',
|
|
25
32
|
],
|
|
26
33
|
},
|
|
27
34
|
plugins: [
|
|
28
|
-
viteAngular(vite),
|
|
35
|
+
viteAngular(options?.vite),
|
|
29
36
|
{
|
|
30
37
|
name: '@analogjs/astro-angular-platform-server',
|
|
31
38
|
transform(code, id) {
|
|
@@ -63,9 +70,9 @@ export default function (options) {
|
|
|
63
70
|
name: '@analogjs/astro-angular',
|
|
64
71
|
hooks: {
|
|
65
72
|
'astro:config:setup': ({ addRenderer, updateConfig, addMiddleware }) => {
|
|
66
|
-
addRenderer(getRenderer());
|
|
73
|
+
addRenderer(getRenderer(options?.useAngularHydration));
|
|
67
74
|
updateConfig({
|
|
68
|
-
vite: getViteConfiguration(options
|
|
75
|
+
vite: getViteConfiguration(options),
|
|
69
76
|
});
|
|
70
77
|
if (options?.strictStylePlacement) {
|
|
71
78
|
addMiddleware({
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,WAA8B,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,WAA8B,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAkB/C,SAAS,WAAW,CAAC,WAAgC;IACnD,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,gBAAgB,EAAE,WAAW;YAC3B,CAAC,CAAC,uCAAuC;YACzC,CAAC,CAAC,mCAAmC;QACvC,gBAAgB,EAAE,WAAW;YAC3B,CAAC,CAAC,uCAAuC;YACzC,CAAC,CAAC,mCAAmC;KACxC,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAwB;IACpD,OAAO;QACL,OAAO,EAAE;YACP,MAAM,EAAE,IAAI;SACb;QACD,YAAY,EAAE;YACZ,OAAO,EAAE;gBACP,2BAA2B;gBAC3B,eAAe;gBACf,OAAO,EAAE,mBAAmB;oBAC1B,CAAC,CAAC,uCAAuC;oBACzC,CAAC,CAAC,mCAAmC;aACxC;YACD,OAAO,EAAE;gBACP,0BAA0B;gBAC1B,mCAAmC;gBACnC,uCAAuC;aACxC;SACF;QAED,OAAO,EAAE;YACP,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC;YAC1B;gBACE,IAAI,EAAE,yCAAyC;gBAC/C,SAAS,CAAC,IAAY,EAAE,EAAU;oBAChC,IAAI,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;wBACnC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WA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CAAC;gBACnB,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { fileURLToPath } from 'node:url';\nimport viteAngular, { PluginOptions } from '@analogjs/vite-plugin-angular';\nimport { enableProdMode } from '@angular/core';\nimport type { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro';\n\ninterface AngularOptions {\n vite?: PluginOptions;\n /**\n * Enable stricter rendering, which ensures Angular style tags are added to the document head instead of next to the\n * component in the body.\n *\n * Enabling this option disables astro's streaming under SSR.\n */\n strictStylePlacement?: boolean;\n /**\n * Use Angular's `provideClientHydration` to hydrate components.\n */\n useAngularHydration?: boolean;\n}\n\nfunction getRenderer(ngHydration: boolean | undefined): AstroRenderer {\n return {\n name: '@analogjs/astro-angular',\n clientEntrypoint: ngHydration\n ? '@analogjs/astro-angular/client-ngh.js'\n : '@analogjs/astro-angular/client.js',\n serverEntrypoint: ngHydration\n ? '@analogjs/astro-angular/server-ngh.js'\n : '@analogjs/astro-angular/server.js',\n };\n}\n\nfunction getViteConfiguration(options?: AngularOptions): ViteUserConfig {\n return {\n esbuild: {\n jsxDev: true,\n },\n optimizeDeps: {\n include: [\n '@angular/platform-browser',\n '@angular/core',\n options?.useAngularHydration\n ? '@analogjs/astro-angular/client-ngh.js'\n : '@analogjs/astro-angular/client.js',\n ],\n exclude: [\n '@angular/platform-server',\n '@analogjs/astro-angular/server.js',\n '@analogjs/astro-angular/server-ngh.js',\n ],\n },\n\n plugins: [\n viteAngular(options?.vite),\n {\n name: '@analogjs/astro-angular-platform-server',\n transform(code: string, id: string) {\n if (id.includes('platform-server')) {\n code = code.replace(/global\\./g, 'globalThis.');\n\n return {\n code: code.replace(\n 'new xhr2.XMLHttpRequest',\n 'new (xhr2.default.XMLHttpRequest || xhr2.default)',\n ),\n };\n }\n\n return;\n },\n },\n {\n name: 'analogjs-astro-client-ngservermode',\n configEnvironment(name: string) {\n if (name === 'client') {\n return {\n define: {\n ngServerMode: 'false',\n },\n };\n }\n\n return undefined;\n },\n },\n ],\n ssr: {\n noExternal: ['@angular/**', '@analogjs/**'],\n },\n };\n}\n\nexport default function (options?: AngularOptions): AstroIntegration {\n process.env['ANALOG_ASTRO'] = 'true';\n\n return {\n name: '@analogjs/astro-angular',\n hooks: {\n 'astro:config:setup': ({ addRenderer, updateConfig, addMiddleware }) => {\n addRenderer(getRenderer(options?.useAngularHydration));\n updateConfig({\n vite: getViteConfiguration(options),\n });\n if (options?.strictStylePlacement) {\n addMiddleware({\n order: 'pre',\n entrypoint: fileURLToPath(import.meta.resolve('./middleware.js')),\n });\n }\n },\n 'astro:config:done': () => {\n if (process.env['NODE_ENV'] === 'production') {\n enableProdMode();\n }\n },\n },\n };\n}\n"]}
|
package/src/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAM/C,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAM/C,eAAO,MAAM,SAAS,EAAE,iBA8EvB,CAAC"}
|
package/src/middleware.js
CHANGED
|
@@ -53,6 +53,8 @@ export const onRequest = async (_ctx, next) => {
|
|
|
53
53
|
tree.children.unshift(head);
|
|
54
54
|
}
|
|
55
55
|
const newBody = processor.stringify(tree);
|
|
56
|
-
|
|
56
|
+
const newResponse = new Response(newBody, response);
|
|
57
|
+
newResponse.headers.set('content-length', Buffer.byteLength(newBody).toFixed(0));
|
|
58
|
+
return newResponse;
|
|
57
59
|
};
|
|
58
60
|
//# sourceMappingURL=middleware.js.map
|
package/src/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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 'astro';\nimport type { Root, RootContent, Element } from 'hast';\nimport { rehype } from 'rehype';\n\nconst processor = rehype();\n\nexport const onRequest: MiddlewareHandler = async (_ctx, next) => {\n const response = await next();\n if (response.headers.get('content-type')?.includes('text/html') !== true) {\n return response;\n }\n\n // Find all <style ng-app-id=\"...\"> tags in the body and move them to the head\n\n const responseBody = await response.text();\n\n const tree = processor.parse(responseBody);\n\n const stack: (Root | RootContent)[] = [tree];\n\n const styleTags: Element[] = [];\n let head: Element | null = null;\n\n while (stack.length) {\n const top = stack.pop()!;\n\n if (top.type === 'element' && top.tagName === 'template') {\n // Templates create a shadow-root, so styles should not be moved outside.\n continue;\n }\n\n if (top.type === 'element' && top.tagName === 'style') {\n if ('ng-app-id' in top.properties) {\n styleTags.push(top);\n }\n continue;\n }\n\n if (top.type === 'element' && top.tagName === 'head' && !head) {\n head = top;\n continue;\n }\n\n if (top.type !== 'root' && top.type !== 'element') {\n continue;\n }\n\n for (let index = top.children.length - 1; index >= 0; index--) {\n const child = top.children[index];\n\n stack.push(child);\n\n if (\n child.type === 'element' &&\n child.tagName === 'style' &&\n 'ng-app-id' in child.properties\n ) {\n top.children.splice(index, 1);\n }\n }\n }\n\n if (head) {\n head.children.push(...styleTags);\n } else {\n const head: Element = {\n type: 'element',\n children: styleTags,\n properties: {},\n tagName: 'head',\n };\n\n tree.children.unshift(head);\n }\n\n const newBody = processor.stringify(tree);\n\n const newResponse = new Response(newBody, response);\n newResponse.headers.set(\n 'content-length',\n Buffer.byteLength(newBody).toFixed(0),\n );\n\n return newResponse;\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EnvironmentProviders, Provider, Type } from '@angular/core';
|
|
2
|
+
import { type HydrationFeature, type HydrationFeatureKind } from '@angular/platform-browser';
|
|
3
|
+
import type { AstroComponentMetadata } from 'astro';
|
|
4
|
+
import { type RendererContext } from './context.ts';
|
|
5
|
+
declare function check(Component: Type<unknown>): Promise<boolean>;
|
|
6
|
+
declare function renderToStaticMarkup(this: RendererContext, Component: Type<unknown> & {
|
|
7
|
+
renderProviders?: (Provider | EnvironmentProviders)[];
|
|
8
|
+
hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
|
|
9
|
+
}, props: Record<string, unknown>, _children: unknown, metadata?: AstroComponentMetadata): Promise<{
|
|
10
|
+
html: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
check: typeof check;
|
|
14
|
+
renderToStaticMarkup: typeof renderToStaticMarkup;
|
|
15
|
+
renderHydrationScript: () => string;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
//# sourceMappingURL=server-ngh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-ngh.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server-ngh.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAa1E,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAG1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAA0B,MAAM,OAAO,CAAC;AAC5E,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAqB7E,iBAAe,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,oBAE5C;AAED,iBAAe,oBAAoB,CACjC,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;IACzB,eAAe,CAAC,EAAE,CAAC,QAAQ,GAAG,oBAAoB,CAAC,EAAE,CAAC;IACtD,iBAAiB,CAAC,EAAE,MAAM,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,CAAC;CACpE,EACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,sBAAsB;;GAoElC;;;;;;AAED,wBAImC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { reflectComponentType, provideZonelessChangeDetection, DOCUMENT, APP_ID, } from '@angular/core';
|
|
4
|
+
import { provideServerRendering, renderApplication, ɵSERVER_CONTEXT, platformServer, } from '@angular/platform-server';
|
|
5
|
+
import { bootstrapApplication, provideClientHydration, } from '@angular/platform-browser';
|
|
6
|
+
import { getContext, incrementId } from "./context.js";
|
|
7
|
+
import { provideBootstrapListener } from "./server-providers.js";
|
|
8
|
+
import { ID_PROP_NAME } from "./id.js";
|
|
9
|
+
import { getComponentElementTag } from "./create-component.js";
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
let jsActionContractScript = undefined;
|
|
12
|
+
const HYDRATION_SCRIPT_ID = 'ng-event-dispatch-contract';
|
|
13
|
+
function getHydrationScript() {
|
|
14
|
+
jsActionContractScript ??=
|
|
15
|
+
`<script type="text/javascript" id="${HYDRATION_SCRIPT_ID}">` +
|
|
16
|
+
readFileSync(require.resolve('@angular/core/event-dispatch-contract.min.js'), 'utf-8') +
|
|
17
|
+
'</script>';
|
|
18
|
+
return jsActionContractScript;
|
|
19
|
+
}
|
|
20
|
+
async function check(Component) {
|
|
21
|
+
return !!reflectComponentType(Component);
|
|
22
|
+
}
|
|
23
|
+
async function renderToStaticMarkup(Component, props, _children, metadata) {
|
|
24
|
+
const mirror = reflectComponentType(Component);
|
|
25
|
+
if (!mirror) {
|
|
26
|
+
// This should be unreachable: the `check` function verifies that Component is an Angular component.
|
|
27
|
+
throw new Error((metadata?.displayName || '<unknown component>') +
|
|
28
|
+
' is not an Angular component');
|
|
29
|
+
}
|
|
30
|
+
const elementTag = getComponentElementTag(mirror);
|
|
31
|
+
const ngAppId = props?.[ID_PROP_NAME] || incrementId(getContext(this.result));
|
|
32
|
+
// When the platform ref is destroyed, it will reset ngServerMode back to `undefined` if it was not defined when it is
|
|
33
|
+
// created. See https://github.com/angular/angular/blob/2ce0e98f79a02ddc550d00580e8e232cfed3bfb2/packages/platform-server/src/server.ts#L138
|
|
34
|
+
globalThis.ngServerMode = true;
|
|
35
|
+
const platformRef = platformServer();
|
|
36
|
+
const document = platformRef.injector.get(DOCUMENT);
|
|
37
|
+
// Incremental hydration requires the event dispatch script to be present.
|
|
38
|
+
document.body.innerHTML = `${getHydrationScript()}<${elementTag} ${ID_PROP_NAME}="${ngAppId}"></${elementTag}>`;
|
|
39
|
+
const bootstrap = (context) => bootstrapApplication(Component, {
|
|
40
|
+
providers: [
|
|
41
|
+
provideBootstrapListener(mirror, props),
|
|
42
|
+
provideServerRendering(),
|
|
43
|
+
{ provide: ɵSERVER_CONTEXT, useValue: 'analog' },
|
|
44
|
+
provideZonelessChangeDetection(),
|
|
45
|
+
metadata?.hydrate
|
|
46
|
+
? provideClientHydration(...(Component.hydrationFeatures?.() || []))
|
|
47
|
+
: [],
|
|
48
|
+
{
|
|
49
|
+
provide: APP_ID,
|
|
50
|
+
useValue: ngAppId,
|
|
51
|
+
},
|
|
52
|
+
...(Component.renderProviders || []),
|
|
53
|
+
],
|
|
54
|
+
}, context);
|
|
55
|
+
const html = await renderApplication(bootstrap, {
|
|
56
|
+
document,
|
|
57
|
+
});
|
|
58
|
+
document.documentElement.innerHTML = html;
|
|
59
|
+
let styleTags = '';
|
|
60
|
+
document.head.childNodes.forEach((node) => {
|
|
61
|
+
if (node.nodeName === 'STYLE') {
|
|
62
|
+
styleTags += node.outerHTML;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Remove the hydration script, so only one is present on the page.
|
|
66
|
+
document.getElementById(HYDRATION_SCRIPT_ID)?.remove();
|
|
67
|
+
const correctedHtml = styleTags + document.body.innerHTML;
|
|
68
|
+
platformRef.destroy();
|
|
69
|
+
return { html: correctedHtml };
|
|
70
|
+
}
|
|
71
|
+
export default {
|
|
72
|
+
check,
|
|
73
|
+
renderToStaticMarkup,
|
|
74
|
+
renderHydrationScript: () => getHydrationScript(),
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=server-ngh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-ngh.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server-ngh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,QAAQ,EACR,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EAGpB,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAwB,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,IAAI,sBAAsB,GAAuB,SAAS,CAAC;AAE3D,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;AAEzD,SAAS,kBAAkB;IACzB,sBAAsB;QACpB,sCAAsC,mBAAmB,IAAI;YAC7D,YAAY,CACV,OAAO,CAAC,OAAO,CAAC,8CAA8C,CAAC,EAC/D,OAAO,CACR;YACD,WAAW,CAAC;IACd,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED,KAAK,UAAU,KAAK,CAAC,SAAwB;IAC3C,OAAO,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,CA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YACN;gBACE,OAAO,EAAE,MAAM;gBACf,QAAQ,EAAE,OAAO;aAClB;YACD,GAAG,CAAC,SAAS,CAAC,eAAe,IAAI,EAAE,CAAC;SACrC;KACF,EACD,OAAO,CACR,CAAC;IAEJ,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE;QAC9C,QAAQ;KACT,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1C,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC9B,SAAS,IAAK,IAAoB,CAAC,SAAS,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,mEAAmE;IACnE,QAAQ,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvD,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;IAE1D,WAAW,CAAC,OAAO,EAAE,CAAC;IAEtB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AACjC,CAAC;AAED,eAAe;IACb,KAAK;IACL,oBAAoB;IACpB,qBAAqB,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;CACjB,CAAC","sourcesContent":["import { readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\n\nimport type { EnvironmentProviders, Provider, Type } from '@angular/core';\nimport {\n reflectComponentType,\n provideZonelessChangeDetection,\n DOCUMENT,\n APP_ID,\n} from '@angular/core';\nimport {\n provideServerRendering,\n renderApplication,\n ɵSERVER_CONTEXT,\n platformServer,\n} from '@angular/platform-server';\nimport {\n bootstrapApplication,\n type HydrationFeature,\n type HydrationFeatureKind,\n provideClientHydration,\n type BootstrapContext,\n} from '@angular/platform-browser';\nimport type { AstroComponentMetadata, SSRLoadedRendererValue } from 'astro';\nimport { getContext, incrementId, type RendererContext } from './context.ts';\nimport { provideBootstrapListener } from './server-providers.ts';\nimport { ID_PROP_NAME } from './id.ts';\nimport { getComponentElementTag } from './create-component.ts';\n\nconst require = createRequire(import.meta.url);\nlet jsActionContractScript: string | undefined = undefined;\n\nconst HYDRATION_SCRIPT_ID = 'ng-event-dispatch-contract';\n\nfunction getHydrationScript(): string {\n jsActionContractScript ??=\n `<script type=\"text/javascript\" id=\"${HYDRATION_SCRIPT_ID}\">` +\n readFileSync(\n require.resolve('@angular/core/event-dispatch-contract.min.js'),\n 'utf-8',\n ) +\n '</script>';\n return jsActionContractScript;\n}\n\nasync function check(Component: Type<unknown>) {\n return !!reflectComponentType(Component);\n}\n\nasync function renderToStaticMarkup(\n this: RendererContext,\n Component: Type<unknown> & {\n renderProviders?: (Provider | EnvironmentProviders)[];\n hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];\n },\n props: Record<string, unknown>,\n _children: unknown,\n metadata?: AstroComponentMetadata,\n) {\n const mirror = reflectComponentType(Component);\n\n if (!mirror) {\n // This should be unreachable: the `check` function verifies that Component is an Angular component.\n throw new Error(\n (metadata?.displayName || '<unknown component>') +\n ' is not an Angular component',\n );\n }\n\n const elementTag = getComponentElementTag(mirror);\n const ngAppId = props?.[ID_PROP_NAME] || incrementId(getContext(this.result));\n\n // When the platform ref is destroyed, it will reset ngServerMode back to `undefined` if it was not defined when it is\n // created. See https://github.com/angular/angular/blob/2ce0e98f79a02ddc550d00580e8e232cfed3bfb2/packages/platform-server/src/server.ts#L138\n globalThis.ngServerMode = true;\n\n const platformRef = platformServer();\n const document = platformRef.injector.get(DOCUMENT);\n\n // Incremental hydration requires the event dispatch script to be present.\n document.body.innerHTML = `${getHydrationScript()}<${elementTag} ${ID_PROP_NAME}=\"${ngAppId}\"></${elementTag}>`;\n\n const bootstrap = (context?: BootstrapContext) =>\n bootstrapApplication(\n Component,\n {\n providers: [\n provideBootstrapListener(mirror, props),\n provideServerRendering(),\n { provide: ɵSERVER_CONTEXT, useValue: 'analog' },\n provideZonelessChangeDetection(),\n metadata?.hydrate\n ? provideClientHydration(...(Component.hydrationFeatures?.() || []))\n : [],\n {\n provide: APP_ID,\n useValue: ngAppId,\n },\n ...(Component.renderProviders || []),\n ],\n },\n context,\n );\n\n const html = await renderApplication(bootstrap, {\n document,\n });\n\n document.documentElement.innerHTML = html;\n let styleTags = '';\n\n document.head.childNodes.forEach((node) => {\n if (node.nodeName === 'STYLE') {\n styleTags += (node as HTMLElement).outerHTML;\n }\n });\n\n // Remove the hydration script, so only one is present on the page.\n document.getElementById(HYDRATION_SCRIPT_ID)?.remove();\n\n const correctedHtml = styleTags + document.body.innerHTML;\n\n platformRef.destroy();\n\n return { html: correctedHtml };\n}\n\nexport default {\n check,\n renderToStaticMarkup,\n renderHydrationScript: () => getHydrationScript(),\n} satisfies SSRLoadedRendererValue;\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ComponentMirror, type Provider } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Provide bootstrap listeners to ensure the rendered state matches the settled component state after applying component inputs.
|
|
4
|
+
* @param mirror The component mirror, to detect component inputs
|
|
5
|
+
* @param props Properties applied to the component in the Astro file
|
|
6
|
+
* @returns A providers array for the server renderer
|
|
7
|
+
*/
|
|
8
|
+
export declare function provideBootstrapListener(mirror: ComponentMirror<unknown>, props: Record<string, unknown>): Provider[];
|
|
9
|
+
//# sourceMappingURL=server-providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-providers.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AAEvB;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,EAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,QAAQ,EAAE,CAkBZ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { APP_BOOTSTRAP_LISTENER, } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Provide bootstrap listeners to ensure the rendered state matches the settled component state after applying component inputs.
|
|
4
|
+
* @param mirror The component mirror, to detect component inputs
|
|
5
|
+
* @param props Properties applied to the component in the Astro file
|
|
6
|
+
* @returns A providers array for the server renderer
|
|
7
|
+
*/
|
|
8
|
+
export function provideBootstrapListener(mirror, props) {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
provide: APP_BOOTSTRAP_LISTENER,
|
|
12
|
+
useValue: (compRef) => {
|
|
13
|
+
if (props) {
|
|
14
|
+
for (const [key, value] of Object.entries(props)) {
|
|
15
|
+
if (mirror.inputs.some(({ templateName }) => templateName === key)) {
|
|
16
|
+
compRef.setInput(key, value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
multi: true,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=server-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-providers.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAIvB,MAAM,eAAe,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAgC,EAChC,KAA8B;IAE9B,OAAO;QACL;YACE,OAAO,EAAE,sBAAsB;YAC/B,QAAQ,EAAE,CAAC,OAA8B,EAAE,EAAE;gBAC3C,IAAI,KAAK,EAAE,CAAC;oBACV,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;wBACjD,IACE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,GAAG,CAAC,EAC9D,CAAC;4BACD,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;wBAC/B,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,KAAK,EAAE,IAAI;SACZ;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n APP_BOOTSTRAP_LISTENER,\n type ComponentMirror,\n type ComponentRef,\n type Provider,\n} from '@angular/core';\n\n/**\n * Provide bootstrap listeners to ensure the rendered state matches the settled component state after applying component inputs.\n * @param mirror The component mirror, to detect component inputs\n * @param props Properties applied to the component in the Astro file\n * @returns A providers array for the server renderer\n */\nexport function provideBootstrapListener(\n mirror: ComponentMirror<unknown>,\n props: Record<string, unknown>,\n): Provider[] {\n return [\n {\n provide: APP_BOOTSTRAP_LISTENER,\n useValue: (compRef: ComponentRef<unknown>) => {\n if (props) {\n for (const [key, value] of Object.entries(props)) {\n if (\n mirror.inputs.some(({ templateName }) => templateName === key)\n ) {\n compRef.setInput(key, value);\n }\n }\n }\n },\n multi: true,\n },\n ];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-integrity.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/ssr-integrity.ts"],"names":[],"mappings":"AAKA,wBAAgB,wBAAwB,IAAI,IAAI,CAe/C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ɵCLIENT_RENDER_MODE_FLAG, ɵSSR_CONTENT_INTEGRITY_MARKER, } from '@angular/core';
|
|
2
|
+
export function ensureSsrIntegrityMarker() {
|
|
3
|
+
// Insert Angular client hydration marker
|
|
4
|
+
// See https://github.com/angular/angular/issues/67785
|
|
5
|
+
if (document.body.firstChild?.nodeType !== Node.COMMENT_NODE ||
|
|
6
|
+
document.body.firstChild.textContent !== ɵSSR_CONTENT_INTEGRITY_MARKER) {
|
|
7
|
+
document.body.prepend(document.createComment(ɵSSR_CONTENT_INTEGRITY_MARKER));
|
|
8
|
+
}
|
|
9
|
+
if (!document.body.hasAttribute(ɵCLIENT_RENDER_MODE_FLAG)) {
|
|
10
|
+
document.body.setAttribute(ɵCLIENT_RENDER_MODE_FLAG, '');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ssr-integrity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-integrity.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/ssr-integrity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,MAAM,UAAU,wBAAwB;IACtC,yCAAyC;IACzC,sDAAsD;IACtD,IACE,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,KAAK,IAAI,CAAC,YAAY;QACxD,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,6BAA6B,EACtE,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CACnB,QAAQ,CAAC,aAAa,CAAC,6BAA6B,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,wBAAwB,CAAC,EAAE,CAAC;QAC1D,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import {\n ɵCLIENT_RENDER_MODE_FLAG,\n ɵSSR_CONTENT_INTEGRITY_MARKER,\n} from '@angular/core';\n\nexport function ensureSsrIntegrityMarker(): void {\n // Insert Angular client hydration marker\n // See https://github.com/angular/angular/issues/67785\n if (\n document.body.firstChild?.nodeType !== Node.COMMENT_NODE ||\n document.body.firstChild.textContent !== ɵSSR_CONTENT_INTEGRITY_MARKER\n ) {\n document.body.prepend(\n document.createComment(ɵSSR_CONTENT_INTEGRITY_MARKER),\n );\n }\n\n if (!document.body.hasAttribute(ɵCLIENT_RENDER_MODE_FLAG)) {\n document.body.setAttribute(ɵCLIENT_RENDER_MODE_FLAG, '');\n }\n}\n"]}
|