@analogjs/astro-angular 3.0.0-alpha.30 → 3.0.0-alpha.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/astro-angular",
3
- "version": "3.0.0-alpha.30",
3
+ "version": "3.0.0-alpha.32",
4
4
  "description": "Use Angular components within Astro",
5
5
  "type": "module",
6
6
  "author": "Brandon Roberts <robertsbt@gmail.com>",
@@ -13,10 +13,18 @@
13
13
  "types": "./src/utils.d.ts",
14
14
  "default": "./src/utils.js"
15
15
  },
16
+ "./client-ngh.js": {
17
+ "types": "./src/client-ngh.d.ts",
18
+ "default": "./src/client-ngh.js"
19
+ },
16
20
  "./client.js": {
17
21
  "types": "./src/client.d.ts",
18
22
  "default": "./src/client.js"
19
23
  },
24
+ "./server-ngh.js": {
25
+ "types": "./src/server-ngh.d.ts",
26
+ "default": "./src/server-ngh.js"
27
+ },
20
28
  "./server.js": {
21
29
  "types": "./src/server.d.ts",
22
30
  "default": "./src/server.js"
@@ -48,7 +56,7 @@
48
56
  "url": "https://github.com/sponsors/brandonroberts"
49
57
  },
50
58
  "dependencies": {
51
- "@analogjs/vite-plugin-angular": "3.0.0-alpha.30",
59
+ "@analogjs/vite-plugin-angular": "3.0.0-alpha.32",
52
60
  "rehype": "^13.0.2"
53
61
  },
54
62
  "peerDependencies": {
@@ -73,7 +81,8 @@
73
81
  "@analogjs/storybook-angular",
74
82
  "@analogjs/vite-plugin-angular",
75
83
  "@analogjs/vite-plugin-nitro",
76
- "@analogjs/vitest-angular"
84
+ "@analogjs/vitest-angular",
85
+ "@analogjs/angular-compiler"
77
86
  ],
78
87
  "migrations": "./migrations/migration.json"
79
88
  },
@@ -0,0 +1,2 @@
1
+ declare const _default: (element: HTMLElement) => unknown;
2
+ export default _default;
@@ -0,0 +1,45 @@
1
+ import { ID_PROP_NAME } from "./id.js";
2
+ import { createComponentBindings, getComponentElementTag } from "./create-component.js";
3
+ import { ensureSsrIntegrityMarker } from "./ssr-integrity.js";
4
+ import { APP_BOOTSTRAP_LISTENER, APP_ID, createComponent, provideZonelessChangeDetection, reflectComponentType } from "@angular/core";
5
+ import { createApplication, provideClientHydration } from "@angular/platform-browser";
6
+ //#region packages/astro-angular/src/client-ngh.ts
7
+ var client_ngh_default = (element) => {
8
+ return (Component, props) => {
9
+ const mirror = reflectComponentType(Component);
10
+ if (!mirror) return;
11
+ ensureSsrIntegrityMarker();
12
+ let hostElement = element.querySelector(mirror.selector);
13
+ let reuseDom = true;
14
+ if (!hostElement) {
15
+ hostElement = document.createElement(getComponentElementTag(mirror));
16
+ element.appendChild(hostElement);
17
+ reuseDom = false;
18
+ }
19
+ const ngAppId = hostElement?.getAttribute(ID_PROP_NAME);
20
+ createApplication({ providers: [
21
+ provideZonelessChangeDetection(),
22
+ reuseDom ? provideClientHydration(...Component.hydrationFeatures?.() || []) : [],
23
+ {
24
+ provide: APP_ID,
25
+ useValue: ngAppId || "ng"
26
+ },
27
+ ...Component.clientProviders || []
28
+ ] }).then((appRef) => {
29
+ const componentRef = createComponent(Component, {
30
+ environmentInjector: appRef.injector,
31
+ hostElement,
32
+ bindings: createComponentBindings(mirror, props, hostElement)
33
+ });
34
+ appRef.attachView(componentRef.hostView);
35
+ appRef.components.push(componentRef);
36
+ appRef.injector.get(APP_BOOTSTRAP_LISTENER, []).forEach((cb) => cb(componentRef));
37
+ }).catch((error) => {
38
+ console.error("Failed to hydrate Angular component:", error);
39
+ });
40
+ };
41
+ };
42
+ //#endregion
43
+ export { client_ngh_default as default };
44
+
45
+ //# sourceMappingURL=client-ngh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-ngh.js","names":[],"sources":["../../src/client-ngh.ts"],"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"],"mappings":";;;;;;AAuBA,IAAA,sBAAgB,YAAyB;AACvC,SACE,WAIA,UACG;EACH,MAAM,SAAS,qBAAqB,UAAU;AAE9C,MAAI,CAAC,OAEH;AAGF,4BAA0B;EAE1B,IAAI,cAAc,QAAQ,cAAc,OAAO,SAAS;EACxD,IAAI,WAAW;AAEf,MAAI,CAAC,aAAa;AAEhB,iBAAc,SAAS,cAAc,uBAAuB,OAAO,CAAC;AACpE,WAAQ,YAAY,YAAY;AAChC,cAAW;;EAGb,MAAM,UAAU,aAAa,aAAa,aAAa;AAEvD,oBAAkB,EAChB,WAAW;GACT,gCAAgC;GAChC,WACI,uBAAuB,GAAI,UAAU,qBAAqB,IAAI,EAAE,CAAE,GAClE,EAAE;GACN;IACE,SAAS;IACT,UAAU,WAAW;IACtB;GACD,GAAI,UAAU,mBAAmB,EAAE;GACpC,EACF,CAAC,CACC,MAAM,WAAW;GAChB,MAAM,eAAe,gBAAgB,WAAW;IAC9C,qBAAqB,OAAO;IAC5B;IACA,UAAU,wBAAwB,QAAQ,OAAO,YAAY;IAC9D,CAAC;AAEF,UAAO,WAAW,aAAa,SAAS;AAExC,UAAO,WAAW,KAAK,aAAa;AAEpC,UAAO,SACJ,IAAI,wBAAwB,EAAE,CAAC,CAC/B,SAAS,OAAO,GAAG,aAAa,CAAC;IACpC,CACD,OAAO,UAAU;AAChB,WAAQ,MAAM,wCAAwC,MAAM;IAC5D"}
@@ -0,0 +1,11 @@
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 {};
package/src/context.js ADDED
@@ -0,0 +1,23 @@
1
+ //#region packages/astro-angular/src/context.ts
2
+ var contexts = /* @__PURE__ */ new WeakMap();
3
+ function getContext(result) {
4
+ let ctx = contexts.get(result);
5
+ if (ctx) return ctx;
6
+ ctx = {
7
+ c: 0,
8
+ getId() {
9
+ return "analog-" + this.c.toString();
10
+ }
11
+ };
12
+ contexts.set(result, ctx);
13
+ return ctx;
14
+ }
15
+ function incrementId(ctx) {
16
+ const id = ctx.getId();
17
+ ctx.c++;
18
+ return id;
19
+ }
20
+ //#endregion
21
+ export { getContext, incrementId };
22
+
23
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/context.ts"],"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"],"mappings":";AAWA,IAAM,2BAAW,IAAI,SAA6B;AAElD,SAAgB,WAAW,QAA4B;CACrD,IAAI,MAAM,SAAS,IAAI,OAAO;AAC9B,KAAI,IACF,QAAO;AAET,OAAM;EACJ,GAAG;EACH,QAAQ;AACN,UAAO,YAAY,KAAK,EAAE,UAAU;;EAEvC;AACD,UAAS,IAAI,QAAQ,IAAI;AACzB,QAAO;;AAGT,SAAgB,YAAY,KAAsB;CAChD,MAAM,KAAK,IAAI,OAAO;AACtB,KAAI;AACJ,QAAO"}
@@ -0,0 +1,5 @@
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[];
@@ -0,0 +1,31 @@
1
+ import "./id.js";
2
+ import { inputBinding, outputBinding } from "@angular/core";
3
+ //#region packages/astro-angular/src/create-component.ts
4
+ function getComponentElementTag(mirror) {
5
+ return mirror.selector.split(",")[0] || "ng-component";
6
+ }
7
+ function createInputBindings(mirror, props) {
8
+ if (!props) return [];
9
+ return Object.entries(props).filter(([key]) => mirror.inputs.some(({ templateName }) => templateName === key)).map(([key, value]) => inputBinding(key, () => value));
10
+ }
11
+ function createOutputBindings(hostElement, mirror) {
12
+ return mirror.outputs.map(({ templateName }) => outputBinding(templateName, (detail) => {
13
+ const event = new CustomEvent(templateName, {
14
+ bubbles: true,
15
+ cancelable: true,
16
+ composed: true,
17
+ detail
18
+ });
19
+ hostElement.dispatchEvent(event);
20
+ }));
21
+ }
22
+ function createComponentBindings(mirror, props, hostElement) {
23
+ const inputBindings = createInputBindings(mirror, props);
24
+ if (!mirror.outputs.length || !props?.["data-analog-id"] || !hostElement) return inputBindings;
25
+ const outputBindings = createOutputBindings(hostElement, mirror);
26
+ return [...inputBindings, ...outputBindings];
27
+ }
28
+ //#endregion
29
+ export { createComponentBindings, getComponentElementTag };
30
+
31
+ //# sourceMappingURL=create-component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-component.js","names":[],"sources":["../../src/create-component.ts"],"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"],"mappings":";;;AAQA,SAAgB,uBACd,QACQ;AACR,QAAO,OAAO,SAAS,MAAM,IAAI,CAAC,MAAM;;AAG1C,SAAgB,oBACd,QACA,OACW;AACX,KAAI,CAAC,MACH,QAAO,EAAE;AASX,QANsB,OAAO,QAAQ,MAAM,CACxC,QAAQ,CAAC,SACR,OAAO,OAAO,MAAM,EAAE,mBAAmB,iBAAiB,IAAI,CAC/D,CACA,KAAK,CAAC,KAAK,WAAW,aAAa,WAAW,MAAM,CAAC;;AAK1D,SAAgB,qBACd,aACA,QACW;AAaX,QAZuB,OAAO,QAAQ,KAAK,EAAE,mBAC3C,cAAc,eAAe,WAAW;EACtC,MAAM,QAAQ,IAAI,YAAY,cAAc;GAC1C,SAAS;GACT,YAAY;GACZ,UAAU;GACV;GACD,CAAC;AACF,cAAY,cAAc,MAAM;GAChC,CACH;;AAKH,SAAgB,wBACd,QACA,OACA,aACW;CACX,MAAM,gBAAgB,oBAAoB,QAAQ,MAAM;AAExD,KAAI,CAAC,OAAO,QAAQ,UAAU,CAAC,QAAA,qBAAyB,CAAC,YACvD,QAAO;CAGT,MAAM,iBAAiB,qBAAqB,aAAa,OAAO;AAEhE,QAAO,CAAC,GAAG,eAAe,GAAG,eAAe"}
package/src/id.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Property name used to serialize the APP_ID of each component.
3
+ */
4
+ export declare const ID_PROP_NAME = "data-analog-id";
package/src/id.js ADDED
@@ -0,0 +1,9 @@
1
+ //#region packages/astro-angular/src/id.ts
2
+ /**
3
+ * Property name used to serialize the APP_ID of each component.
4
+ */
5
+ var ID_PROP_NAME = "data-analog-id";
6
+ //#endregion
7
+ export { ID_PROP_NAME };
8
+
9
+ //# sourceMappingURL=id.js.map
package/src/id.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.js","names":[],"sources":["../../src/id.ts"],"sourcesContent":["/**\n * Property name used to serialize the APP_ID of each component.\n */\nexport const ID_PROP_NAME = 'data-analog-id';\n"],"mappings":";;;;AAGA,IAAa,eAAe"}
package/src/index.d.ts CHANGED
@@ -9,5 +9,9 @@ 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;
package/src/index.js CHANGED
@@ -2,11 +2,11 @@ import viteAngular from "@analogjs/vite-plugin-angular";
2
2
  import { enableProdMode } from "@angular/core";
3
3
  import * as vite from "vite";
4
4
  //#region packages/astro-angular/src/index.ts
5
- function getRenderer() {
5
+ function getRenderer(ngHydration) {
6
6
  return {
7
7
  name: "@analogjs/astro-angular",
8
- clientEntrypoint: "@analogjs/astro-angular/client.js",
9
- serverEntrypoint: "@analogjs/astro-angular/server.js"
8
+ clientEntrypoint: ngHydration ? "@analogjs/astro-angular/client-ngh.js" : "@analogjs/astro-angular/client.js",
9
+ serverEntrypoint: ngHydration ? "@analogjs/astro-angular/server-ngh.js" : "@analogjs/astro-angular/server.js"
10
10
  };
11
11
  }
12
12
  function getViteConfiguration(pluginOptions) {
@@ -17,12 +17,16 @@ function getViteConfiguration(pluginOptions) {
17
17
  include: [
18
18
  "@angular/platform-browser",
19
19
  "@angular/core",
20
- "@analogjs/astro-angular/client.js"
20
+ pluginOptions?.useAngularHydration ? "@analogjs/astro-angular/client-ngh.js" : "@analogjs/astro-angular/client.js"
21
21
  ],
22
- exclude: ["@angular/platform-server", "@analogjs/astro-angular/server.js"]
22
+ exclude: [
23
+ "@angular/platform-server",
24
+ "@analogjs/astro-angular/server.js",
25
+ "@analogjs/astro-angular/server-ngh.js"
26
+ ]
23
27
  },
24
28
  plugins: [
25
- viteAngular(pluginOptions),
29
+ viteAngular(pluginOptions?.vite),
26
30
  {
27
31
  name: "@analogjs/astro-angular-platform-server",
28
32
  transform(code, id) {
@@ -48,8 +52,8 @@ function src_default(options) {
48
52
  name: "@analogjs/astro-angular",
49
53
  hooks: {
50
54
  "astro:config:setup": ({ addRenderer, updateConfig, addMiddleware }) => {
51
- addRenderer(getRenderer());
52
- updateConfig({ vite: getViteConfiguration(options?.vite) });
55
+ addRenderer(getRenderer(options?.useAngularHydration));
56
+ updateConfig({ vite: getViteConfiguration(options) });
53
57
  if (options?.strictStylePlacement) addMiddleware({
54
58
  order: "pre",
55
59
  entrypoint: "@analogjs/astro-angular/middleware"
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import viteAngular from '@analogjs/vite-plugin-angular';\nimport type { PluginOptions } from '@analogjs/vite-plugin-angular';\nimport { enableProdMode } from '@angular/core';\nimport type { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro';\nimport * as vite from 'vite';\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\nfunction getRenderer(): AstroRenderer {\n return {\n name: '@analogjs/astro-angular',\n clientEntrypoint: '@analogjs/astro-angular/client.js',\n serverEntrypoint: '@analogjs/astro-angular/server.js',\n };\n}\n\nfunction getViteConfiguration(pluginOptions?: PluginOptions) {\n const isRolldown = !!vite.rolldownVersion;\n return {\n [isRolldown ? 'oxc' : 'esbuild']: {\n ...(isRolldown ? { jsx: { development: true } } : { jsxDev: true }),\n },\n optimizeDeps: {\n include: [\n '@angular/platform-browser',\n '@angular/core',\n '@analogjs/astro-angular/client.js',\n ],\n exclude: [\n '@angular/platform-server',\n '@analogjs/astro-angular/server.js',\n ],\n },\n\n plugins: [\n viteAngular(pluginOptions),\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());\n updateConfig({\n vite: getViteConfiguration(\n options?.vite,\n ) as unknown as ViteUserConfig,\n });\n if (options?.strictStylePlacement) {\n addMiddleware({\n order: 'pre',\n entrypoint: '@analogjs/astro-angular/middleware',\n });\n }\n },\n 'astro:config:done': () => {\n if (process.env['NODE_ENV'] === 'production') {\n enableProdMode();\n }\n },\n },\n };\n}\n"],"mappings":";;;;AAiBA,SAAS,cAA6B;AACpC,QAAO;EACL,MAAM;EACN,kBAAkB;EAClB,kBAAkB;EACnB;;AAGH,SAAS,qBAAqB,eAA+B;CAC3D,MAAM,aAAa,CAAC,CAAC,KAAK;AAC1B,QAAO;GACJ,aAAa,QAAQ,YAAY,EAChC,GAAI,aAAa,EAAE,KAAK,EAAE,aAAa,MAAM,EAAE,GAAG,EAAE,QAAQ,MAAM,EACnE;EACD,cAAc;GACZ,SAAS;IACP;IACA;IACA;IACD;GACD,SAAS,CACP,4BACA,oCACD;GACF;EAED,SAAS;GACP,YAAY,cAAc;GAC1B;IACE,MAAM;IACN,UAAU,MAAc,IAAY;AAClC,SAAI,GAAG,SAAS,kBAAkB,EAAE;AAClC,aAAO,KAAK,QAAQ,aAAa,cAAc;AAE/C,aAAO,EACL,MAAM,KAAK,QACT,2BACA,oDACD,EACF;;;IAKN;GACD;IACE,MAAM;IACN,kBAAkB,MAAc;AAC9B,SAAI,SAAS,SACX,QAAO,EACL,QAAQ,EACN,cAAc,SACf,EACF;;IAKN;GACF;EACD,KAAK,EACH,YAAY,CAAC,eAAe,eAAe,EAC5C;EACF;;AAGH,SAAA,YAAyB,SAA4C;AACnE,SAAQ,IAAI,kBAAkB;AAE9B,QAAO;EACL,MAAM;EACN,OAAO;GACL,uBAAuB,EAAE,aAAa,cAAc,oBAAoB;AACtE,gBAAY,aAAa,CAAC;AAC1B,iBAAa,EACX,MAAM,qBACJ,SAAS,KACV,EACF,CAAC;AACF,QAAI,SAAS,qBACX,eAAc;KACZ,OAAO;KACP,YAAY;KACb,CAAC;;GAGN,2BAA2B;AACzB,QAAA,QAAA,IAAA,aAAgC,aAC9B,iBAAgB;;GAGrB;EACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import viteAngular from '@analogjs/vite-plugin-angular';\nimport type { PluginOptions } from '@analogjs/vite-plugin-angular';\nimport { enableProdMode } from '@angular/core';\nimport type { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro';\nimport * as vite from 'vite';\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(pluginOptions?: AngularOptions) {\n const isRolldown = !!vite.rolldownVersion;\n return {\n [isRolldown ? 'oxc' : 'esbuild']: {\n ...(isRolldown ? { jsx: { development: true } } : { jsxDev: true }),\n },\n optimizeDeps: {\n include: [\n '@angular/platform-browser',\n '@angular/core',\n pluginOptions?.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(pluginOptions?.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: '@analogjs/astro-angular/middleware',\n });\n }\n },\n 'astro:config:done': () => {\n if (process.env['NODE_ENV'] === 'production') {\n enableProdMode();\n }\n },\n },\n };\n}\n"],"mappings":";;;;AAqBA,SAAS,YAAY,aAAiD;AACpE,QAAO;EACL,MAAM;EACN,kBAAkB,cACd,0CACA;EACJ,kBAAkB,cACd,0CACA;EACL;;AAGH,SAAS,qBAAqB,eAAgC;CAC5D,MAAM,aAAa,CAAC,CAAC,KAAK;AAC1B,QAAO;GACJ,aAAa,QAAQ,YAAY,EAChC,GAAI,aAAa,EAAE,KAAK,EAAE,aAAa,MAAM,EAAE,GAAG,EAAE,QAAQ,MAAM,EACnE;EACD,cAAc;GACZ,SAAS;IACP;IACA;IACA,eAAe,sBACX,0CACA;IACL;GACD,SAAS;IACP;IACA;IACA;IACD;GACF;EAED,SAAS;GACP,YAAY,eAAe,KAAK;GAChC;IACE,MAAM;IACN,UAAU,MAAc,IAAY;AAClC,SAAI,GAAG,SAAS,kBAAkB,EAAE;AAClC,aAAO,KAAK,QAAQ,aAAa,cAAc;AAE/C,aAAO,EACL,MAAM,KAAK,QACT,2BACA,oDACD,EACF;;;IAKN;GACD;IACE,MAAM;IACN,kBAAkB,MAAc;AAC9B,SAAI,SAAS,SACX,QAAO,EACL,QAAQ,EACN,cAAc,SACf,EACF;;IAKN;GACF;EACD,KAAK,EACH,YAAY,CAAC,eAAe,eAAe,EAC5C;EACF;;AAGH,SAAA,YAAyB,SAA4C;AACnE,SAAQ,IAAI,kBAAkB;AAE9B,QAAO;EACL,MAAM;EACN,OAAO;GACL,uBAAuB,EAAE,aAAa,cAAc,oBAAoB;AACtE,gBAAY,YAAY,SAAS,oBAAoB,CAAC;AACtD,iBAAa,EACX,MAAM,qBAAqB,QAAQ,EACpC,CAAC;AACF,QAAI,SAAS,qBACX,eAAc;KACZ,OAAO;KACP,YAAY;KACb,CAAC;;GAGN,2BAA2B;AACzB,QAAA,QAAA,IAAA,aAAgC,aAC9B,iBAAgB;;GAGrB;EACF"}
package/src/middleware.js CHANGED
@@ -38,7 +38,9 @@ var onRequest = async (_ctx, next) => {
38
38
  tree.children.unshift(head);
39
39
  }
40
40
  const newBody = processor.stringify(tree);
41
- return new Response(newBody, response);
41
+ const newResponse = new Response(newBody, response);
42
+ newResponse.headers.set("content-length", Buffer.byteLength(newBody).toFixed(0));
43
+ return newResponse;
42
44
  };
43
45
  //#endregion
44
46
  export { onRequest };
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { MiddlewareHandler } from '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 return new Response(newBody, response);\n};\n"],"mappings":";;AAIA,IAAM,YAAY,QAAQ;AAE1B,IAAa,YAA+B,OAAO,MAAM,SAAS;CAChE,MAAM,WAAW,MAAM,MAAM;AAC7B,KAAI,SAAS,QAAQ,IAAI,eAAe,EAAE,SAAS,YAAY,KAAK,KAClE,QAAO;CAKT,MAAM,eAAe,MAAM,SAAS,MAAM;CAE1C,MAAM,OAAO,UAAU,MAAM,aAAa;CAE1C,MAAM,QAAgC,CAAC,KAAK;CAE5C,MAAM,YAAuB,EAAE;CAC/B,IAAI,OAAuB;AAE3B,QAAO,MAAM,QAAQ;EACnB,MAAM,MAAM,MAAM,KAAK;AAEvB,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,WAE5C;AAGF,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,SAAS;AACrD,OAAI,eAAe,IAAI,WACrB,WAAU,KAAK,IAAI;AAErB;;AAGF,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,UAAU,CAAC,MAAM;AAC7D,UAAO;AACP;;AAGF,MAAI,IAAI,SAAS,UAAU,IAAI,SAAS,UACtC;AAGF,OAAK,IAAI,QAAQ,IAAI,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS;GAC7D,MAAM,QAAQ,IAAI,SAAS;AAE3B,SAAM,KAAK,MAAM;AAEjB,OACE,MAAM,SAAS,aACf,MAAM,YAAY,WAClB,eAAe,MAAM,WAErB,KAAI,SAAS,OAAO,OAAO,EAAE;;;AAKnC,KAAI,KACF,MAAK,SAAS,KAAK,GAAG,UAAU;MAC3B;EACL,MAAM,OAAgB;GACpB,MAAM;GACN,UAAU;GACV,YAAY,EAAE;GACd,SAAS;GACV;AAED,OAAK,SAAS,QAAQ,KAAK;;CAG7B,MAAM,UAAU,UAAU,UAAU,KAAK;AAEzC,QAAO,IAAI,SAAS,SAAS,SAAS"}
1
+ {"version":3,"file":"middleware.js","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { MiddlewareHandler } from '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"],"mappings":";;AAIA,IAAM,YAAY,QAAQ;AAE1B,IAAa,YAA+B,OAAO,MAAM,SAAS;CAChE,MAAM,WAAW,MAAM,MAAM;AAC7B,KAAI,SAAS,QAAQ,IAAI,eAAe,EAAE,SAAS,YAAY,KAAK,KAClE,QAAO;CAKT,MAAM,eAAe,MAAM,SAAS,MAAM;CAE1C,MAAM,OAAO,UAAU,MAAM,aAAa;CAE1C,MAAM,QAAgC,CAAC,KAAK;CAE5C,MAAM,YAAuB,EAAE;CAC/B,IAAI,OAAuB;AAE3B,QAAO,MAAM,QAAQ;EACnB,MAAM,MAAM,MAAM,KAAK;AAEvB,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,WAE5C;AAGF,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,SAAS;AACrD,OAAI,eAAe,IAAI,WACrB,WAAU,KAAK,IAAI;AAErB;;AAGF,MAAI,IAAI,SAAS,aAAa,IAAI,YAAY,UAAU,CAAC,MAAM;AAC7D,UAAO;AACP;;AAGF,MAAI,IAAI,SAAS,UAAU,IAAI,SAAS,UACtC;AAGF,OAAK,IAAI,QAAQ,IAAI,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS;GAC7D,MAAM,QAAQ,IAAI,SAAS;AAE3B,SAAM,KAAK,MAAM;AAEjB,OACE,MAAM,SAAS,aACf,MAAM,YAAY,WAClB,eAAe,MAAM,WAErB,KAAI,SAAS,OAAO,OAAO,EAAE;;;AAKnC,KAAI,KACF,MAAK,SAAS,KAAK,GAAG,UAAU;MAC3B;EACL,MAAM,OAAgB;GACpB,MAAM;GACN,UAAU;GACV,YAAY,EAAE;GACd,SAAS;GACV;AAED,OAAK,SAAS,QAAQ,KAAK;;CAG7B,MAAM,UAAU,UAAU,UAAU,KAAK;CAEzC,MAAM,cAAc,IAAI,SAAS,SAAS,SAAS;AACnD,aAAY,QAAQ,IAClB,kBACA,OAAO,WAAW,QAAQ,CAAC,QAAQ,EAAE,CACtC;AAED,QAAO"}
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,64 @@
1
+ import { ID_PROP_NAME } from "./id.js";
2
+ import { getComponentElementTag } from "./create-component.js";
3
+ import { getContext, incrementId } from "./context.js";
4
+ import { provideBootstrapListener } from "./server-providers.js";
5
+ import { APP_ID, DOCUMENT, provideZonelessChangeDetection, reflectComponentType } from "@angular/core";
6
+ import { bootstrapApplication, provideClientHydration } from "@angular/platform-browser";
7
+ import { platformServer, provideServerRendering, renderApplication, ɵSERVER_CONTEXT } from "@angular/platform-server";
8
+ import { readFileSync } from "node:fs";
9
+ import { createRequire } from "node:module";
10
+ //#region packages/astro-angular/src/server-ngh.ts
11
+ var require = createRequire(import.meta.url);
12
+ var jsActionContractScript = void 0;
13
+ var HYDRATION_SCRIPT_ID = "ng-event-dispatch-contract";
14
+ function getHydrationScript() {
15
+ jsActionContractScript ??= `<script type="text/javascript" id="${HYDRATION_SCRIPT_ID}">` + readFileSync(require.resolve("@angular/core/event-dispatch-contract.min.js"), "utf-8") + "<\/script>";
16
+ return jsActionContractScript;
17
+ }
18
+ async function check(Component) {
19
+ return !!reflectComponentType(Component);
20
+ }
21
+ async function renderToStaticMarkup(Component, props, _children, metadata) {
22
+ const mirror = reflectComponentType(Component);
23
+ if (!mirror) throw new Error((metadata?.displayName || "<unknown component>") + " is not an Angular component");
24
+ const elementTag = getComponentElementTag(mirror);
25
+ const ngAppId = props?.["data-analog-id"] || incrementId(getContext(this.result));
26
+ globalThis.ngServerMode = true;
27
+ const platformRef = platformServer();
28
+ const document = platformRef.injector.get(DOCUMENT);
29
+ document.body.innerHTML = `${getHydrationScript()}<${elementTag} ${ID_PROP_NAME}="${ngAppId}"></${elementTag}>`;
30
+ const bootstrap = (context) => bootstrapApplication(Component, { providers: [
31
+ provideBootstrapListener(mirror, props),
32
+ provideServerRendering(),
33
+ {
34
+ provide: ɵSERVER_CONTEXT,
35
+ useValue: "analog"
36
+ },
37
+ provideZonelessChangeDetection(),
38
+ metadata?.hydrate ? provideClientHydration(...Component.hydrationFeatures?.() || []) : [],
39
+ {
40
+ provide: APP_ID,
41
+ useValue: ngAppId
42
+ },
43
+ ...Component.renderProviders || []
44
+ ] }, context);
45
+ const html = await renderApplication(bootstrap, { document });
46
+ document.documentElement.innerHTML = html;
47
+ let styleTags = "";
48
+ document.head.childNodes.forEach((node) => {
49
+ if (node.nodeName === "STYLE") styleTags += node.outerHTML;
50
+ });
51
+ document.getElementById(HYDRATION_SCRIPT_ID)?.remove();
52
+ const correctedHtml = styleTags + document.body.innerHTML;
53
+ platformRef.destroy();
54
+ return { html: correctedHtml };
55
+ }
56
+ var server_ngh_default = {
57
+ check,
58
+ renderToStaticMarkup,
59
+ renderHydrationScript: () => getHydrationScript()
60
+ };
61
+ //#endregion
62
+ export { server_ngh_default as default };
63
+
64
+ //# sourceMappingURL=server-ngh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-ngh.js","names":[],"sources":["../../src/server-ngh.ts"],"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"],"mappings":";;;;;;;;;;AA6BA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAC9C,IAAI,yBAA6C,KAAA;AAEjD,IAAM,sBAAsB;AAE5B,SAAS,qBAA6B;AACpC,4BACE,sCAAsC,oBAAoB,MAC1D,aACE,QAAQ,QAAQ,+CAA+C,EAC/D,QACD,GACD;AACF,QAAO;;AAGT,eAAe,MAAM,WAA0B;AAC7C,QAAO,CAAC,CAAC,qBAAqB,UAAU;;AAG1C,eAAe,qBAEb,WAIA,OACA,WACA,UACA;CACA,MAAM,SAAS,qBAAqB,UAAU;AAE9C,KAAI,CAAC,OAEH,OAAM,IAAI,OACP,UAAU,eAAe,yBACxB,+BACH;CAGH,MAAM,aAAa,uBAAuB,OAAO;CACjD,MAAM,UAAU,QAAA,qBAAyB,YAAY,WAAW,KAAK,OAAO,CAAC;AAI7E,YAAW,eAAe;CAE1B,MAAM,cAAc,gBAAgB;CACpC,MAAM,WAAW,YAAY,SAAS,IAAI,SAAS;AAGnD,UAAS,KAAK,YAAY,GAAG,oBAAoB,CAAC,GAAG,WAAW,GAAG,aAAa,IAAI,QAAQ,MAAM,WAAW;CAE7G,MAAM,aAAa,YACjB,qBACE,WACA,EACE,WAAW;EACT,yBAAyB,QAAQ,MAAM;EACvC,wBAAwB;EACxB;GAAE,SAAS;GAAiB,UAAU;GAAU;EAChD,gCAAgC;EAChC,UAAU,UACN,uBAAuB,GAAI,UAAU,qBAAqB,IAAI,EAAE,CAAE,GAClE,EAAE;EACN;GACE,SAAS;GACT,UAAU;GACX;EACD,GAAI,UAAU,mBAAmB,EAAE;EACpC,EACF,EACD,QACD;CAEH,MAAM,OAAO,MAAM,kBAAkB,WAAW,EAC9C,UACD,CAAC;AAEF,UAAS,gBAAgB,YAAY;CACrC,IAAI,YAAY;AAEhB,UAAS,KAAK,WAAW,SAAS,SAAS;AACzC,MAAI,KAAK,aAAa,QACpB,cAAc,KAAqB;GAErC;AAGF,UAAS,eAAe,oBAAoB,EAAE,QAAQ;CAEtD,MAAM,gBAAgB,YAAY,SAAS,KAAK;AAEhD,aAAY,SAAS;AAErB,QAAO,EAAE,MAAM,eAAe;;AAGhC,IAAA,qBAAe;CACb;CACA;CACA,6BAA6B,oBAAoB;CAClD"}
@@ -0,0 +1,8 @@
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[];
@@ -0,0 +1,23 @@
1
+ import { APP_BOOTSTRAP_LISTENER } from "@angular/core";
2
+ //#region packages/astro-angular/src/server-providers.ts
3
+ /**
4
+ * Provide bootstrap listeners to ensure the rendered state matches the settled component state after applying component inputs.
5
+ * @param mirror The component mirror, to detect component inputs
6
+ * @param props Properties applied to the component in the Astro file
7
+ * @returns A providers array for the server renderer
8
+ */
9
+ function provideBootstrapListener(mirror, props) {
10
+ return [{
11
+ provide: APP_BOOTSTRAP_LISTENER,
12
+ useValue: (compRef) => {
13
+ if (props) {
14
+ for (const [key, value] of Object.entries(props)) if (mirror.inputs.some(({ templateName }) => templateName === key)) compRef.setInput(key, value);
15
+ }
16
+ },
17
+ multi: true
18
+ }];
19
+ }
20
+ //#endregion
21
+ export { provideBootstrapListener };
22
+
23
+ //# sourceMappingURL=server-providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-providers.js","names":[],"sources":["../../src/server-providers.ts"],"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"],"mappings":";;;;;;;;AAaA,SAAgB,yBACd,QACA,OACY;AACZ,QAAO,CACL;EACE,SAAS;EACT,WAAW,YAAmC;AAC5C,OAAI;SACG,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,CAC9C,KACE,OAAO,OAAO,MAAM,EAAE,mBAAmB,iBAAiB,IAAI,CAE9D,SAAQ,SAAS,KAAK,MAAM;;;EAKpC,OAAO;EACR,CACF"}
@@ -0,0 +1 @@
1
+ export declare function ensureSsrIntegrityMarker(): void;
@@ -0,0 +1,10 @@
1
+ import { ɵCLIENT_RENDER_MODE_FLAG, ɵSSR_CONTENT_INTEGRITY_MARKER } from "@angular/core";
2
+ //#region packages/astro-angular/src/ssr-integrity.ts
3
+ function ensureSsrIntegrityMarker() {
4
+ if (document.body.firstChild?.nodeType !== Node.COMMENT_NODE || document.body.firstChild.textContent !== ɵSSR_CONTENT_INTEGRITY_MARKER) document.body.prepend(document.createComment(ɵSSR_CONTENT_INTEGRITY_MARKER));
5
+ if (!document.body.hasAttribute(ɵCLIENT_RENDER_MODE_FLAG)) document.body.setAttribute(ɵCLIENT_RENDER_MODE_FLAG, "");
6
+ }
7
+ //#endregion
8
+ export { ensureSsrIntegrityMarker };
9
+
10
+ //# sourceMappingURL=ssr-integrity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-integrity.js","names":[],"sources":["../../src/ssr-integrity.ts"],"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"],"mappings":";;AAKA,SAAgB,2BAAiC;AAG/C,KACE,SAAS,KAAK,YAAY,aAAa,KAAK,gBAC5C,SAAS,KAAK,WAAW,gBAAgB,8BAEzC,UAAS,KAAK,QACZ,SAAS,cAAc,8BAA8B,CACtD;AAGH,KAAI,CAAC,SAAS,KAAK,aAAa,yBAAyB,CACvD,UAAS,KAAK,aAAa,0BAA0B,GAAG"}