@analogjs/astro-angular 3.0.0-alpha.8 → 3.0.0-alpha.9

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.8",
3
+ "version": "3.0.0-alpha.9",
4
4
  "description": "Use Angular components within Astro",
5
5
  "type": "module",
6
6
  "author": "Brandon Roberts <robertsbt@gmail.com>",
@@ -32,7 +32,7 @@
32
32
  "url": "https://github.com/sponsors/brandonroberts"
33
33
  },
34
34
  "dependencies": {
35
- "@analogjs/vite-plugin-angular": "^3.0.0-alpha.8"
35
+ "@analogjs/vite-plugin-angular": "^3.0.0-alpha.9"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@angular/build": ">=20.0.0",
@@ -63,8 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public",
65
65
  "provenance": true
66
- },
67
- "types": "./src/index.d.ts",
68
- "module": "./src/index.js",
69
- "main": "./src/index.js"
70
- }
66
+ }
67
+ }
package/src/client.js CHANGED
@@ -1,52 +1,43 @@
1
- import { reflectComponentType, provideZonelessChangeDetection, } from '@angular/core';
2
- import { createComponent } from '@angular/core';
3
- import { createApplication } from '@angular/platform-browser';
4
- import { Subject, takeUntil } from 'rxjs';
5
- export default (element) => {
6
- return (Component, props, _childHTML) => {
7
- createApplication({
8
- providers: [
9
- provideZonelessChangeDetection(),
10
- ...(Component.clientProviders || []),
11
- ],
12
- }).then((appRef) => {
13
- const componentRef = createComponent(Component, {
14
- environmentInjector: appRef.injector,
15
- hostElement: element,
16
- });
17
- const mirror = reflectComponentType(Component);
18
- if (props && mirror) {
19
- for (const [key, value] of Object.entries(props)) {
20
- if (mirror.inputs.some(({ templateName, propName }) => templateName === key || propName === key)) {
21
- componentRef.setInput(key, value);
22
- }
23
- }
24
- }
25
- if (mirror?.outputs.length && props?.['data-analog-id']) {
26
- const destroySubject = new Subject();
27
- element.setAttribute('data-analog-id', props['data-analog-id']);
28
- mirror.outputs.forEach(({ templateName, propName }) => {
29
- const outputName = templateName || propName;
30
- const component = componentRef.instance;
31
- component[outputName]
32
- .pipe(takeUntil(destroySubject))
33
- .subscribe((detail) => {
34
- const event = new CustomEvent(outputName, {
35
- bubbles: true,
36
- cancelable: true,
37
- composed: true,
38
- detail,
39
- });
40
- element.dispatchEvent(event);
41
- });
42
- });
43
- appRef.onDestroy(() => {
44
- destroySubject.next();
45
- destroySubject.complete();
46
- });
47
- }
48
- appRef.attachView(componentRef.hostView);
49
- });
50
- };
1
+ import { createComponent, provideZonelessChangeDetection, reflectComponentType } from "@angular/core";
2
+ import { createApplication } from "@angular/platform-browser";
3
+ import { Subject, takeUntil } from "rxjs";
4
+ //#region packages/astro-angular/src/client.ts
5
+ var client_default = (element) => {
6
+ return (Component, props, _childHTML) => {
7
+ createApplication({ providers: [provideZonelessChangeDetection(), ...Component.clientProviders || []] }).then((appRef) => {
8
+ const componentRef = createComponent(Component, {
9
+ environmentInjector: appRef.injector,
10
+ hostElement: element
11
+ });
12
+ const mirror = reflectComponentType(Component);
13
+ if (props && mirror) {
14
+ for (const [key, value] of Object.entries(props)) if (mirror.inputs.some(({ templateName, propName }) => templateName === key || propName === key)) componentRef.setInput(key, value);
15
+ }
16
+ if (mirror?.outputs.length && props?.["data-analog-id"]) {
17
+ const destroySubject = new Subject();
18
+ element.setAttribute("data-analog-id", props["data-analog-id"]);
19
+ mirror.outputs.forEach(({ templateName, propName }) => {
20
+ const outputName = templateName || propName;
21
+ componentRef.instance[outputName].pipe(takeUntil(destroySubject)).subscribe((detail) => {
22
+ const event = new CustomEvent(outputName, {
23
+ bubbles: true,
24
+ cancelable: true,
25
+ composed: true,
26
+ detail
27
+ });
28
+ element.dispatchEvent(event);
29
+ });
30
+ });
31
+ appRef.onDestroy(() => {
32
+ destroySubject.next();
33
+ destroySubject.complete();
34
+ });
35
+ }
36
+ appRef.attachView(componentRef.hostView);
37
+ });
38
+ };
51
39
  };
40
+ //#endregion
41
+ export { client_default as default };
42
+
52
43
  //# sourceMappingURL=client.js.map
package/src/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oBAAoB,EAEpB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAc,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtD,eAAe,CACb,OAAoB,EAOX,EAAE;IACX,OAAO,CACL,SAEC,EACD,KAA+B,EAC/B,UAAoB,EACd,EAAE;QACR,iBAAiB,CAAC;YAChB,SAAS,EAAE;gBACT,8BAA8B,EAAE;gBAChC,GAAG,CAAC,SAAS,CAAC,eAAe,IAAI,EAAE,CAAC;aACrC;SACF,CAAC,CAAC,IAAI,CAAC,CAAC,MAAsB,EAAE,EAAE;YACjC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,EAAE;gBAC9C,mBAAmB,EAAE,MAAM,CAAC,QAAQ;gBACpC,WAAW,EAAE,OAAO;aACrB,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;YAC/C,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;gBACpB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjD,IACE,MAAM,CAAC,MAAM,CAAC,IAAI,CAChB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC7B,YAAY,KAAK,GAAG,IAAI,QAAQ,KAAK,GAAG,CAC3C,EACD,CAAC;wBACD,YAAY,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBACpC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACxD,MAAM,cAAc,GAAG,IAAI,OAAO,EAAQ,CAAC;gBAC3C,OAAO,CAAC,YAAY,CAClB,gBAAgB,EAChB,KAAK,CAAC,gBAAgB,CAAW,CAClC,CAAC;gBAEF,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE;oBACpD,MAAM,UAAU,GAAG,YAAY,IAAI,QAAQ,CAAC;oBAC5C,MAAM,SAAS,GAAG,YAAY,CAAC,QAG9B,CAAC;oBACF,SAAS,CAAC,UAAU,CAAC;yBAClB,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;yBAC/B,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;wBACpB,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,UAAU,EAAE;4BACxC,OAAO,EAAE,IAAI;4BACb,UAAU,EAAE,IAAI;4BAChB,QAAQ,EAAE,IAAI;4BACd,MAAM;yBACP,CAAC,CAAC;wBACH,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;oBAC/B,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;gBAEH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;oBACpB,cAAc,CAAC,IAAI,EAAE,CAAC;oBACtB,cAAc,CAAC,QAAQ,EAAE,CAAC;gBAC5B,CAAC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n EnvironmentProviders,\n Provider,\n reflectComponentType,\n ɵComponentType as ComponentType,\n provideZonelessChangeDetection,\n} from '@angular/core';\nimport { ApplicationRef, createComponent } from '@angular/core';\nimport { createApplication } from '@angular/platform-browser';\nimport { Observable, Subject, takeUntil } from 'rxjs';\n\nexport default (\n element: HTMLElement,\n): ((\n Component: ComponentType<unknown> & {\n clientProviders?: (Provider | EnvironmentProviders)[];\n },\n props?: Record<string, unknown>,\n _childHTML?: unknown,\n) => void) => {\n return (\n Component: ComponentType<unknown> & {\n clientProviders?: (Provider | EnvironmentProviders)[];\n },\n props?: Record<string, unknown>,\n _childHTML?: unknown,\n ): void => {\n createApplication({\n providers: [\n provideZonelessChangeDetection(),\n ...(Component.clientProviders || []),\n ],\n }).then((appRef: ApplicationRef) => {\n const componentRef = createComponent(Component, {\n environmentInjector: appRef.injector,\n hostElement: element,\n });\n\n const mirror = reflectComponentType(Component);\n if (props && mirror) {\n for (const [key, value] of Object.entries(props)) {\n if (\n mirror.inputs.some(\n ({ templateName, propName }) =>\n templateName === key || propName === key,\n )\n ) {\n componentRef.setInput(key, value);\n }\n }\n }\n\n if (mirror?.outputs.length && props?.['data-analog-id']) {\n const destroySubject = new Subject<void>();\n element.setAttribute(\n 'data-analog-id',\n props['data-analog-id'] as string,\n );\n\n mirror.outputs.forEach(({ templateName, propName }) => {\n const outputName = templateName || propName;\n const component = componentRef.instance as Record<\n string,\n Observable<unknown>\n >;\n component[outputName]\n .pipe(takeUntil(destroySubject))\n .subscribe((detail) => {\n const event = new CustomEvent(outputName, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n });\n element.dispatchEvent(event);\n });\n });\n\n appRef.onDestroy(() => {\n destroySubject.next();\n destroySubject.complete();\n });\n }\n\n appRef.attachView(componentRef.hostView);\n });\n };\n};\n"]}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../../../packages/astro-angular/src/client.ts"],"sourcesContent":["import {\n EnvironmentProviders,\n Provider,\n reflectComponentType,\n ɵComponentType as ComponentType,\n provideZonelessChangeDetection,\n} from '@angular/core';\nimport { ApplicationRef, createComponent } from '@angular/core';\nimport { createApplication } from '@angular/platform-browser';\nimport { Observable, Subject, takeUntil } from 'rxjs';\n\nexport default (\n element: HTMLElement,\n): ((\n Component: ComponentType<unknown> & {\n clientProviders?: (Provider | EnvironmentProviders)[];\n },\n props?: Record<string, unknown>,\n _childHTML?: unknown,\n) => void) => {\n return (\n Component: ComponentType<unknown> & {\n clientProviders?: (Provider | EnvironmentProviders)[];\n },\n props?: Record<string, unknown>,\n _childHTML?: unknown,\n ): void => {\n createApplication({\n providers: [\n provideZonelessChangeDetection(),\n ...(Component.clientProviders || []),\n ],\n }).then((appRef: ApplicationRef) => {\n const componentRef = createComponent(Component, {\n environmentInjector: appRef.injector,\n hostElement: element,\n });\n\n const mirror = reflectComponentType(Component);\n if (props && mirror) {\n for (const [key, value] of Object.entries(props)) {\n if (\n mirror.inputs.some(\n ({ templateName, propName }) =>\n templateName === key || propName === key,\n )\n ) {\n componentRef.setInput(key, value);\n }\n }\n }\n\n if (mirror?.outputs.length && props?.['data-analog-id']) {\n const destroySubject = new Subject<void>();\n element.setAttribute(\n 'data-analog-id',\n props['data-analog-id'] as string,\n );\n\n mirror.outputs.forEach(({ templateName, propName }) => {\n const outputName = templateName || propName;\n const component = componentRef.instance as Record<\n string,\n Observable<unknown>\n >;\n component[outputName]\n .pipe(takeUntil(destroySubject))\n .subscribe((detail) => {\n const event = new CustomEvent(outputName, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n });\n element.dispatchEvent(event);\n });\n });\n\n appRef.onDestroy(() => {\n destroySubject.next();\n destroySubject.complete();\n });\n }\n\n appRef.attachView(componentRef.hostView);\n });\n };\n};\n"],"mappings":";;;;AAWA,IAAA,kBACE,YAOY;AACZ,SACE,WAGA,OACA,eACS;AACT,oBAAkB,EAChB,WAAW,CACT,gCAAgC,EAChC,GAAI,UAAU,mBAAmB,EAAE,CACpC,EACF,CAAC,CAAC,MAAM,WAA2B;GAClC,MAAM,eAAe,gBAAgB,WAAW;IAC9C,qBAAqB,OAAO;IAC5B,aAAa;IACd,CAAC;GAEF,MAAM,SAAS,qBAAqB,UAAU;AAC9C,OAAI,SAAS;SACN,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,CAC9C,KACE,OAAO,OAAO,MACX,EAAE,cAAc,eACf,iBAAiB,OAAO,aAAa,IACxC,CAED,cAAa,SAAS,KAAK,MAAM;;AAKvC,OAAI,QAAQ,QAAQ,UAAU,QAAQ,mBAAmB;IACvD,MAAM,iBAAiB,IAAI,SAAe;AAC1C,YAAQ,aACN,kBACA,MAAM,kBACP;AAED,WAAO,QAAQ,SAAS,EAAE,cAAc,eAAe;KACrD,MAAM,aAAa,gBAAgB;AACjB,kBAAa,SAIrB,YACP,KAAK,UAAU,eAAe,CAAC,CAC/B,WAAW,WAAW;MACrB,MAAM,QAAQ,IAAI,YAAY,YAAY;OACxC,SAAS;OACT,YAAY;OACZ,UAAU;OACV;OACD,CAAC;AACF,cAAQ,cAAc,MAAM;OAC5B;MACJ;AAEF,WAAO,gBAAgB;AACrB,oBAAe,MAAM;AACrB,oBAAe,UAAU;MACzB;;AAGJ,UAAO,WAAW,aAAa,SAAS;IACxC"}
package/src/index.js CHANGED
@@ -1,80 +1,63 @@
1
- import viteAngular from '@analogjs/vite-plugin-angular';
2
- import { enableProdMode } from '@angular/core';
3
- import * as vite from 'vite';
1
+ import { enableProdMode } from "@angular/core";
2
+ import viteAngular from "@analogjs/vite-plugin-angular";
3
+ import * as vite from "vite";
4
+ //#region packages/astro-angular/src/index.ts
4
5
  function getRenderer() {
5
- return {
6
- name: '@analogjs/astro-angular',
7
- clientEntrypoint: '@analogjs/astro-angular/client.js',
8
- serverEntrypoint: '@analogjs/astro-angular/server.js',
9
- };
6
+ return {
7
+ name: "@analogjs/astro-angular",
8
+ clientEntrypoint: "@analogjs/astro-angular/client.js",
9
+ serverEntrypoint: "@analogjs/astro-angular/server.js"
10
+ };
10
11
  }
11
12
  function getViteConfiguration(pluginOptions) {
12
- const isRolldown = !!vite.rolldownVersion;
13
- return {
14
- [isRolldown ? 'oxc' : 'esbuild']: {
15
- ...(isRolldown ? { jsx: { development: true } } : { jsxDev: true }),
16
- },
17
- optimizeDeps: {
18
- include: [
19
- '@angular/platform-browser',
20
- '@angular/core',
21
- '@analogjs/astro-angular/client.js',
22
- ],
23
- exclude: [
24
- '@angular/platform-server',
25
- '@analogjs/astro-angular/server.js',
26
- ],
27
- },
28
- plugins: [
29
- viteAngular(pluginOptions),
30
- {
31
- name: '@analogjs/astro-angular-platform-server',
32
- transform(code, id) {
33
- if (id.includes('platform-server')) {
34
- code = code.replace(/global\./g, 'globalThis.');
35
- return {
36
- code: code.replace('new xhr2.XMLHttpRequest', 'new (xhr2.default.XMLHttpRequest || xhr2.default)'),
37
- };
38
- }
39
- return;
40
- },
41
- },
42
- {
43
- name: 'analogjs-astro-client-ngservermode',
44
- configEnvironment(name) {
45
- if (name === 'client') {
46
- return {
47
- define: {
48
- ngServerMode: 'false',
49
- },
50
- };
51
- }
52
- return undefined;
53
- },
54
- },
55
- ],
56
- ssr: {
57
- noExternal: ['@angular/**', '@analogjs/**'],
58
- },
59
- };
13
+ const isRolldown = !!vite.rolldownVersion;
14
+ return {
15
+ [isRolldown ? "oxc" : "esbuild"]: { ...isRolldown ? { jsx: { development: true } } : { jsxDev: true } },
16
+ optimizeDeps: {
17
+ include: [
18
+ "@angular/platform-browser",
19
+ "@angular/core",
20
+ "@analogjs/astro-angular/client.js"
21
+ ],
22
+ exclude: ["@angular/platform-server", "@analogjs/astro-angular/server.js"]
23
+ },
24
+ plugins: [
25
+ viteAngular(pluginOptions),
26
+ {
27
+ name: "@analogjs/astro-angular-platform-server",
28
+ transform(code, id) {
29
+ if (id.includes("platform-server")) {
30
+ code = code.replace(/global\./g, "globalThis.");
31
+ return { code: code.replace("new xhr2.XMLHttpRequest", "new (xhr2.default.XMLHttpRequest || xhr2.default)") };
32
+ }
33
+ }
34
+ },
35
+ {
36
+ name: "analogjs-astro-client-ngservermode",
37
+ configEnvironment(name) {
38
+ if (name === "client") return { define: { ngServerMode: "false" } };
39
+ }
40
+ }
41
+ ],
42
+ ssr: { noExternal: ["@angular/**", "@analogjs/**"] }
43
+ };
60
44
  }
61
- export default function (options) {
62
- process.env['ANALOG_ASTRO'] = 'true';
63
- return {
64
- name: '@analogjs/astro-angular',
65
- hooks: {
66
- 'astro:config:setup': ({ addRenderer, updateConfig }) => {
67
- addRenderer(getRenderer());
68
- updateConfig({
69
- vite: getViteConfiguration(options?.vite),
70
- });
71
- },
72
- 'astro:config:done': () => {
73
- if (process.env['NODE_ENV'] === 'production') {
74
- enableProdMode();
75
- }
76
- },
77
- },
78
- };
45
+ function src_default(options) {
46
+ process.env["ANALOG_ASTRO"] = "true";
47
+ return {
48
+ name: "@analogjs/astro-angular",
49
+ hooks: {
50
+ "astro:config:setup": ({ addRenderer, updateConfig }) => {
51
+ addRenderer(getRenderer());
52
+ updateConfig({ vite: getViteConfiguration(options?.vite) });
53
+ },
54
+ "astro:config:done": () => {
55
+ if (process.env.NODE_ENV === "production") enableProdMode();
56
+ }
57
+ }
58
+ };
79
59
  }
60
+ //#endregion
61
+ export { src_default as default };
62
+
80
63
  //# sourceMappingURL=index.js.map
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,WAA8B,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAM7B,SAAS,WAAW;IAClB,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,gBAAgB,EAAE,mCAAmC;QACrD,gBAAgB,EAAE,mCAAmC;KACtD,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,aAA6B;IACzD,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;IAC1C,OAAO;QACL,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE;YAChC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SACpE;QACD,YAAY,EAAE;YACZ,OAAO,EAAE;gBACP,2BAA2B;gBAC3B,eAAe;gBACf,mCAAmC;aACpC;YACD,OAAO,EAAE;gBACP,0BAA0B;gBAC1B,mCAAmC;aACpC;SACF;QAED,OAAO,EAAE;YACP,WAAW,CAAC,aAAa,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,WAAW,EAAE,aAAa,CAAC,CAAC;wBAEhD,OAAO;4BACL,IAAI,EAAE,IAAI,CAAC,OAAO,CAChB,yBAAyB,EACzB,mDAAmD,CACpD;yBACF,CAAC;oBACJ,CAAC;oBAED,OAAO;gBACT,CAAC;aACF;YACD;gBACE,IAAI,EAAE,oCAAoC;gBAC1C,iBAAiB,CAAC,IAAY;oBAC5B,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;wBACtB,OAAO;4BACL,MAAM,EAAE;gCACN,YAAY,EAAE,OAAO;6BACtB;yBACF,CAAC;oBACJ,CAAC;oBAED,OAAO,SAAS,CAAC;gBACnB,CAAC;aACF;SACF;QACD,GAAG,EAAE;YACH,UAAU,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC;SAC5C;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,WAAW,OAAwB;IAC/C,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;IAErC,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,EAAE;gBACtD,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC3B,YAAY,CAAC;oBACX,IAAI,EAAE,oBAAoB,CACxB,OAAO,EAAE,IAAI,CACe;iBAC/B,CAAC,CAAC;YACL,CAAC;YACD,mBAAmB,EAAE,GAAG,EAAE;gBACxB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY,EAAE,CAAC;oBAC7C,cAAc,EAAE,CAAC;gBACnB,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import viteAngular, { 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\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 }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite: getViteConfiguration(\n options?.vite,\n ) as unknown as ViteUserConfig,\n });\n },\n 'astro:config:done': () => {\n if (process.env['NODE_ENV'] === 'production') {\n enableProdMode();\n }\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../packages/astro-angular/src/index.ts"],"sourcesContent":["import viteAngular, { 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\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 }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite: getViteConfiguration(\n options?.vite,\n ) as unknown as ViteUserConfig,\n });\n },\n 'astro:config:done': () => {\n if (process.env['NODE_ENV'] === 'production') {\n enableProdMode();\n }\n },\n },\n };\n}\n"],"mappings":";;;;AASA,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,mBAAmB;AACvD,gBAAY,aAAa,CAAC;AAC1B,iBAAa,EACX,MAAM,qBACJ,SAAS,KACV,EACF,CAAC;;GAEJ,2BAA2B;AACzB,QAAA,QAAA,IAAA,aAAgC,aAC9B,iBAAgB;;GAGrB;EACF"}
package/src/server.js CHANGED
@@ -1,63 +1,58 @@
1
- import { ApplicationRef, InjectionToken, reflectComponentType, provideZonelessChangeDetection, } from '@angular/core';
2
- import { BEFORE_APP_SERIALIZED, provideServerRendering, renderApplication, ɵSERVER_CONTEXT, } from '@angular/platform-server';
3
- import { bootstrapApplication, } from '@angular/platform-browser';
4
- const ANALOG_ASTRO_STATIC_PROPS = new InjectionToken('@analogjs/astro-angular: Static Props w/ Mirror Provider', {
5
- factory() {
6
- return { props: {}, mirror: {} };
7
- },
8
- });
1
+ import { ApplicationRef, InjectionToken, provideZonelessChangeDetection, reflectComponentType } from "@angular/core";
2
+ import { bootstrapApplication } from "@angular/platform-browser";
3
+ import { BEFORE_APP_SERIALIZED, provideServerRendering, renderApplication, ɵSERVER_CONTEXT } from "@angular/platform-server";
4
+ //#region packages/astro-angular/src/server.ts
5
+ var ANALOG_ASTRO_STATIC_PROPS = new InjectionToken("@analogjs/astro-angular: Static Props w/ Mirror Provider", { factory() {
6
+ return {
7
+ props: {},
8
+ mirror: {}
9
+ };
10
+ } });
9
11
  function check(Component, _props, _children) {
10
- return !!reflectComponentType(Component);
12
+ return !!reflectComponentType(Component);
11
13
  }
12
- // Run beforeAppInitialized hook to set Input on the ComponentRef
13
- // before the platform renders to string
14
- const STATIC_PROPS_HOOK_PROVIDER = {
15
- provide: BEFORE_APP_SERIALIZED,
16
- useFactory: (appRef, { props, mirror, }) => {
17
- return () => {
18
- const compRef = appRef.components[0];
19
- if (compRef && props && mirror) {
20
- for (const [key, value] of Object.entries(props)) {
21
- if (
22
- // we double-check inputs on ComponentMirror
23
- // because Astro might add additional props
24
- // that aren't actually Input defined on the Component
25
- mirror.inputs.some(({ templateName, propName }) => templateName === key || propName === key)) {
26
- compRef.setInput(key, value);
27
- }
28
- }
29
- compRef.changeDetectorRef.detectChanges();
30
- }
31
- };
32
- },
33
- deps: [ApplicationRef, ANALOG_ASTRO_STATIC_PROPS],
34
- multi: true,
14
+ var STATIC_PROPS_HOOK_PROVIDER = {
15
+ provide: BEFORE_APP_SERIALIZED,
16
+ useFactory: (appRef, { props, mirror }) => {
17
+ return () => {
18
+ const compRef = appRef.components[0];
19
+ if (compRef && props && mirror) {
20
+ for (const [key, value] of Object.entries(props)) if (mirror.inputs.some(({ templateName, propName }) => templateName === key || propName === key)) compRef.setInput(key, value);
21
+ compRef.changeDetectorRef.detectChanges();
22
+ }
23
+ };
24
+ },
25
+ deps: [ApplicationRef, ANALOG_ASTRO_STATIC_PROPS],
26
+ multi: true
35
27
  };
36
28
  async function renderToStaticMarkup(Component, props, _children) {
37
- const mirror = reflectComponentType(Component);
38
- const appId = mirror?.selector.split(',')[0] || Component.name.toString().toLowerCase();
39
- const document = `<${appId}></${appId}>`;
40
- const bootstrap = (context) => bootstrapApplication(Component, {
41
- providers: [
42
- {
43
- provide: ANALOG_ASTRO_STATIC_PROPS,
44
- useValue: { props, mirror },
45
- },
46
- STATIC_PROPS_HOOK_PROVIDER,
47
- provideServerRendering(),
48
- { provide: ɵSERVER_CONTEXT, useValue: 'analog' },
49
- provideZonelessChangeDetection(),
50
- ...(Component.renderProviders || []),
51
- ],
52
- }, context);
53
- const html = await renderApplication(bootstrap, {
54
- document,
55
- });
56
- return { html };
29
+ const mirror = reflectComponentType(Component);
30
+ const appId = mirror?.selector.split(",")[0] || Component.name.toString().toLowerCase();
31
+ const document = `<${appId}></${appId}>`;
32
+ const bootstrap = (context) => bootstrapApplication(Component, { providers: [
33
+ {
34
+ provide: ANALOG_ASTRO_STATIC_PROPS,
35
+ useValue: {
36
+ props,
37
+ mirror
38
+ }
39
+ },
40
+ STATIC_PROPS_HOOK_PROVIDER,
41
+ provideServerRendering(),
42
+ {
43
+ provide: ɵSERVER_CONTEXT,
44
+ useValue: "analog"
45
+ },
46
+ provideZonelessChangeDetection(),
47
+ ...Component.renderProviders || []
48
+ ] }, context);
49
+ return { html: await renderApplication(bootstrap, { document }) };
57
50
  }
58
- const renderer = {
59
- check: check,
60
- renderToStaticMarkup: renderToStaticMarkup,
51
+ var renderer = {
52
+ check,
53
+ renderToStaticMarkup
61
54
  };
62
- export default renderer;
55
+ //#endregion
56
+ export { renderer as default };
57
+
63
58
  //# sourceMappingURL=server.js.map
package/src/server.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,yBAAyB,GAAG,IAAI,cAAc,CAGjD,0DAA0D,EAAE;IAC7D,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAA8B,EAAE,CAAC;IAC/D,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,KAAK,CACZ,SAAiC,EACjC,MAA+B,EAC/B,SAAkB;IAElB,OAAO,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED,iEAAiE;AACjE,wCAAwC;AACxC,MAAM,0BAA0B,GAAa;IAC3C,OAAO,EAAE,qBAAqB;IAC9B,UAAU,EAAE,CACV,MAAsB,EACtB,EACE,KAAK,EACL,MAAM,GAIP,EACD,EAAE;QACF,OAAO,GAAG,EAAE;YACV,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,OAAO,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjD;oBACE,4CAA4C;oBAC5C,2CAA2C;oBAC3C,sDAAsD;oBACtD,MAAM,CAAC,MAAM,CAAC,IAAI,CAChB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC7B,YAAY,KAAK,GAAG,IAAI,QAAQ,KAAK,GAAG,CAC3C,EACD,CAAC;wBACD,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC;gBACD,OAAO,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC;YAC5C,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,EAAE,CAAC,cAAc,EAAE,yBAAyB,CAAC;IACjD,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,KAAK,UAAU,oBAAoB,CACjC,SAEC,EACD,KAA8B,EAC9B,SAAkB;IAElB,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,KAAK,GACT,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5E,MAAM,QAAQ,GAAG,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;IACzC,MAAM,SAAS,GAAG,CAAC,OAA0B,EAAE,EAAE,CAC/C,oBAAoB,CAClB,SAAS,EACT;QACE,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,yBAAyB;gBAClC,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;aAC5B;YACD,0BAA0B;YAC1B,sBAAsB,EAAE;YACxB,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE;YAChD,8BAA8B,EAAE;YAChC,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,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC;AAED,MAAM,QAAQ,GAGV;IACF,KAAK,EAAE,KAAK;IACZ,oBAAoB,EAAE,oBAAoB;CAC3C,CAAC;AACF,eAAe,QAAQ,CAAC","sourcesContent":["import type {\n ComponentMirror,\n EnvironmentProviders,\n Provider,\n ɵComponentType as ComponentType,\n} from '@angular/core';\nimport {\n ApplicationRef,\n InjectionToken,\n reflectComponentType,\n provideZonelessChangeDetection,\n} from '@angular/core';\nimport {\n BEFORE_APP_SERIALIZED,\n provideServerRendering,\n renderApplication,\n ɵSERVER_CONTEXT,\n} from '@angular/platform-server';\nimport {\n bootstrapApplication,\n type BootstrapContext,\n} from '@angular/platform-browser';\n\nconst ANALOG_ASTRO_STATIC_PROPS = new InjectionToken<{\n props: Record<string, unknown>;\n mirror: ComponentMirror<unknown>;\n}>('@analogjs/astro-angular: Static Props w/ Mirror Provider', {\n factory() {\n return { props: {}, mirror: {} as ComponentMirror<unknown> };\n },\n});\n\nfunction check(\n Component: ComponentType<unknown>,\n _props: Record<string, unknown>,\n _children: unknown,\n): boolean {\n return !!reflectComponentType(Component);\n}\n\n// Run beforeAppInitialized hook to set Input on the ComponentRef\n// before the platform renders to string\nconst STATIC_PROPS_HOOK_PROVIDER: Provider = {\n provide: BEFORE_APP_SERIALIZED,\n useFactory: (\n appRef: ApplicationRef,\n {\n props,\n mirror,\n }: {\n props: Record<string, unknown>;\n mirror: ComponentMirror<unknown>;\n },\n ) => {\n return () => {\n const compRef = appRef.components[0];\n if (compRef && props && mirror) {\n for (const [key, value] of Object.entries(props)) {\n if (\n // we double-check inputs on ComponentMirror\n // because Astro might add additional props\n // that aren't actually Input defined on the Component\n mirror.inputs.some(\n ({ templateName, propName }) =>\n templateName === key || propName === key,\n )\n ) {\n compRef.setInput(key, value);\n }\n }\n compRef.changeDetectorRef.detectChanges();\n }\n };\n },\n deps: [ApplicationRef, ANALOG_ASTRO_STATIC_PROPS],\n multi: true,\n};\n\nasync function renderToStaticMarkup(\n Component: ComponentType<unknown> & {\n renderProviders: (Provider | EnvironmentProviders)[];\n },\n props: Record<string, unknown>,\n _children: unknown,\n): Promise<{ html: string }> {\n const mirror = reflectComponentType(Component);\n const appId =\n mirror?.selector.split(',')[0] || Component.name.toString().toLowerCase();\n const document = `<${appId}></${appId}>`;\n const bootstrap = (context?: BootstrapContext) =>\n bootstrapApplication(\n Component,\n {\n providers: [\n {\n provide: ANALOG_ASTRO_STATIC_PROPS,\n useValue: { props, mirror },\n },\n STATIC_PROPS_HOOK_PROVIDER,\n provideServerRendering(),\n { provide: ɵSERVER_CONTEXT, useValue: 'analog' },\n provideZonelessChangeDetection(),\n ...(Component.renderProviders || []),\n ],\n },\n context,\n );\n\n const html = await renderApplication(bootstrap, {\n document,\n });\n\n return { html };\n}\n\nconst renderer: {\n check: typeof check;\n renderToStaticMarkup: typeof renderToStaticMarkup;\n} = {\n check: check,\n renderToStaticMarkup: renderToStaticMarkup,\n};\nexport default renderer;\n"]}
1
+ {"version":3,"file":"server.js","names":[],"sources":["../../../../packages/astro-angular/src/server.ts"],"sourcesContent":["import type {\n ComponentMirror,\n EnvironmentProviders,\n Provider,\n ɵComponentType as ComponentType,\n} from '@angular/core';\nimport {\n ApplicationRef,\n InjectionToken,\n reflectComponentType,\n provideZonelessChangeDetection,\n} from '@angular/core';\nimport {\n BEFORE_APP_SERIALIZED,\n provideServerRendering,\n renderApplication,\n ɵSERVER_CONTEXT,\n} from '@angular/platform-server';\nimport {\n bootstrapApplication,\n type BootstrapContext,\n} from '@angular/platform-browser';\n\nconst ANALOG_ASTRO_STATIC_PROPS = new InjectionToken<{\n props: Record<string, unknown>;\n mirror: ComponentMirror<unknown>;\n}>('@analogjs/astro-angular: Static Props w/ Mirror Provider', {\n factory() {\n return { props: {}, mirror: {} as ComponentMirror<unknown> };\n },\n});\n\nfunction check(\n Component: ComponentType<unknown>,\n _props: Record<string, unknown>,\n _children: unknown,\n): boolean {\n return !!reflectComponentType(Component);\n}\n\n// Run beforeAppInitialized hook to set Input on the ComponentRef\n// before the platform renders to string\nconst STATIC_PROPS_HOOK_PROVIDER: Provider = {\n provide: BEFORE_APP_SERIALIZED,\n useFactory: (\n appRef: ApplicationRef,\n {\n props,\n mirror,\n }: {\n props: Record<string, unknown>;\n mirror: ComponentMirror<unknown>;\n },\n ) => {\n return () => {\n const compRef = appRef.components[0];\n if (compRef && props && mirror) {\n for (const [key, value] of Object.entries(props)) {\n if (\n // we double-check inputs on ComponentMirror\n // because Astro might add additional props\n // that aren't actually Input defined on the Component\n mirror.inputs.some(\n ({ templateName, propName }) =>\n templateName === key || propName === key,\n )\n ) {\n compRef.setInput(key, value);\n }\n }\n compRef.changeDetectorRef.detectChanges();\n }\n };\n },\n deps: [ApplicationRef, ANALOG_ASTRO_STATIC_PROPS],\n multi: true,\n};\n\nasync function renderToStaticMarkup(\n Component: ComponentType<unknown> & {\n renderProviders: (Provider | EnvironmentProviders)[];\n },\n props: Record<string, unknown>,\n _children: unknown,\n): Promise<{ html: string }> {\n const mirror = reflectComponentType(Component);\n const appId =\n mirror?.selector.split(',')[0] || Component.name.toString().toLowerCase();\n const document = `<${appId}></${appId}>`;\n const bootstrap = (context?: BootstrapContext) =>\n bootstrapApplication(\n Component,\n {\n providers: [\n {\n provide: ANALOG_ASTRO_STATIC_PROPS,\n useValue: { props, mirror },\n },\n STATIC_PROPS_HOOK_PROVIDER,\n provideServerRendering(),\n { provide: ɵSERVER_CONTEXT, useValue: 'analog' },\n provideZonelessChangeDetection(),\n ...(Component.renderProviders || []),\n ],\n },\n context,\n );\n\n const html = await renderApplication(bootstrap, {\n document,\n });\n\n return { html };\n}\n\nconst renderer: {\n check: typeof check;\n renderToStaticMarkup: typeof renderToStaticMarkup;\n} = {\n check: check,\n renderToStaticMarkup: renderToStaticMarkup,\n};\nexport default renderer;\n"],"mappings":";;;;AAuBA,IAAM,4BAA4B,IAAI,eAGnC,4DAA4D,EAC7D,UAAU;AACR,QAAO;EAAE,OAAO,EAAE;EAAE,QAAQ,EAAE;EAA8B;GAE/D,CAAC;AAEF,SAAS,MACP,WACA,QACA,WACS;AACT,QAAO,CAAC,CAAC,qBAAqB,UAAU;;AAK1C,IAAM,6BAAuC;CAC3C,SAAS;CACT,aACE,QACA,EACE,OACA,aAKC;AACH,eAAa;GACX,MAAM,UAAU,OAAO,WAAW;AAClC,OAAI,WAAW,SAAS,QAAQ;AAC9B,SAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,CAC9C,KAIE,OAAO,OAAO,MACX,EAAE,cAAc,eACf,iBAAiB,OAAO,aAAa,IACxC,CAED,SAAQ,SAAS,KAAK,MAAM;AAGhC,YAAQ,kBAAkB,eAAe;;;;CAI/C,MAAM,CAAC,gBAAgB,0BAA0B;CACjD,OAAO;CACR;AAED,eAAe,qBACb,WAGA,OACA,WAC2B;CAC3B,MAAM,SAAS,qBAAqB,UAAU;CAC9C,MAAM,QACJ,QAAQ,SAAS,MAAM,IAAI,CAAC,MAAM,UAAU,KAAK,UAAU,CAAC,aAAa;CAC3E,MAAM,WAAW,IAAI,MAAM,KAAK,MAAM;CACtC,MAAM,aAAa,YACjB,qBACE,WACA,EACE,WAAW;EACT;GACE,SAAS;GACT,UAAU;IAAE;IAAO;IAAQ;GAC5B;EACD;EACA,wBAAwB;EACxB;GAAE,SAAS;GAAiB,UAAU;GAAU;EAChD,gCAAgC;EAChC,GAAI,UAAU,mBAAmB,EAAE;EACpC,EACF,EACD,QACD;AAMH,QAAO,EAAE,MAJI,MAAM,kBAAkB,WAAW,EAC9C,UACD,CAAC,EAEa;;AAGjB,IAAM,WAGF;CACK;CACe;CACvB"}
package/src/utils.js CHANGED
@@ -1,12 +1,19 @@
1
- export function addOutputListener(analogId, outputName, callback, eventListenerOptions = {}) {
2
- const observer = new MutationObserver((mutations) => {
3
- const foundTarget = mutations.find((mutation) => mutation.target.dataset?.['analogId'] === analogId)?.target;
4
- if (foundTarget) {
5
- foundTarget.addEventListener(outputName, callback, eventListenerOptions);
6
- observer.disconnect();
7
- }
8
- });
9
- observer.observe(document.body, { attributes: true, subtree: true });
10
- return () => observer.disconnect();
1
+ //#region packages/astro-angular/src/utils.ts
2
+ function addOutputListener(analogId, outputName, callback, eventListenerOptions = {}) {
3
+ const observer = new MutationObserver((mutations) => {
4
+ const foundTarget = mutations.find((mutation) => mutation.target.dataset?.["analogId"] === analogId)?.target;
5
+ if (foundTarget) {
6
+ foundTarget.addEventListener(outputName, callback, eventListenerOptions);
7
+ observer.disconnect();
8
+ }
9
+ });
10
+ observer.observe(document.body, {
11
+ attributes: true,
12
+ subtree: true
13
+ });
14
+ return () => observer.disconnect();
11
15
  }
16
+ //#endregion
17
+ export { addOutputListener };
18
+
12
19
  //# sourceMappingURL=utils.js.map
package/src/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAC/B,QAAgB,EAChB,UAAkB,EAClB,QAAyC,EACzC,uBAA6C,EAAE;IAE/C,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE;QAClD,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAChC,CAAC,QAAQ,EAAE,EAAE,CACV,QAAQ,CAAC,MAAsB,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,KAAK,QAAQ,CACtE,EAAE,MAAM,CAAC;QAEV,IAAI,WAAW,EAAE,CAAC;YAChB,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;YACzE,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAErE,OAAO,GAAS,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["export function addOutputListener(\n analogId: string,\n outputName: string,\n callback: (...args: unknown[]) => unknown,\n eventListenerOptions: EventListenerOptions = {},\n): () => void {\n const observer = new MutationObserver((mutations) => {\n const foundTarget = mutations.find(\n (mutation) =>\n (mutation.target as HTMLElement).dataset?.['analogId'] === analogId,\n )?.target;\n\n if (foundTarget) {\n foundTarget.addEventListener(outputName, callback, eventListenerOptions);\n observer.disconnect();\n }\n });\n observer.observe(document.body, { attributes: true, subtree: true });\n\n return (): void => observer.disconnect();\n}\n"]}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../packages/astro-angular/src/utils.ts"],"sourcesContent":["export function addOutputListener(\n analogId: string,\n outputName: string,\n callback: (...args: unknown[]) => unknown,\n eventListenerOptions: EventListenerOptions = {},\n): () => void {\n const observer = new MutationObserver((mutations) => {\n const foundTarget = mutations.find(\n (mutation) =>\n (mutation.target as HTMLElement).dataset?.['analogId'] === analogId,\n )?.target;\n\n if (foundTarget) {\n foundTarget.addEventListener(outputName, callback, eventListenerOptions);\n observer.disconnect();\n }\n });\n observer.observe(document.body, { attributes: true, subtree: true });\n\n return (): void => observer.disconnect();\n}\n"],"mappings":";AAAA,SAAgB,kBACd,UACA,YACA,UACA,uBAA6C,EAAE,EACnC;CACZ,MAAM,WAAW,IAAI,kBAAkB,cAAc;EACnD,MAAM,cAAc,UAAU,MAC3B,aACE,SAAS,OAAuB,UAAU,gBAAgB,SAC9D,EAAE;AAEH,MAAI,aAAa;AACf,eAAY,iBAAiB,YAAY,UAAU,qBAAqB;AACxE,YAAS,YAAY;;GAEvB;AACF,UAAS,QAAQ,SAAS,MAAM;EAAE,YAAY;EAAM,SAAS;EAAM,CAAC;AAEpE,cAAmB,SAAS,YAAY"}
package/README.md DELETED
@@ -1,359 +0,0 @@
1
- # @analogjs/astro-angular
2
-
3
- [Astro](https://astro.build) is a modern web framework designed for building fast, content-focused websites, compatible with all major frontend frameworks. Though primarily a static site generation (SSG) tool, it can also integrate dynamic components called "islands", which support partial hydration.
4
-
5
- This package allows rendering [Angular](https://angular.dev) components as islands in Astro.
6
-
7
- ## Setup
8
-
9
- ### Using the Astro CLI
10
-
11
- Use the `astro add` command to install the integration
12
-
13
- Using npm:
14
-
15
- ```sh
16
- npx astro add @analogjs/astro-angular
17
- ```
18
-
19
- Using pnpm:
20
-
21
- ```sh
22
- pnpm astro add @analogjs/astro-angular
23
- ```
24
-
25
- Using yarn:
26
-
27
- ```sh
28
- yarn astro add @analogjs/astro-angular
29
- ```
30
-
31
- This command:
32
-
33
- - Installs the `@analogjs/astro-angular` package.
34
- - Adds the `@analogjs/astro-angular` integration to the `astro.config.mjs` file.
35
- - Installs the necessary dependencies to render Angular components on the server and client, and common Angular dependencies, such as `@angular/common`.
36
-
37
- ### Setting up the TypeScript config
38
-
39
- The integration needs a `tsconfig.app.json` at the root of the project for compilation.
40
-
41
- Create a `tsconfig.app.json` in the root of the project.
42
-
43
- ```json
44
- {
45
- "extends": "./tsconfig.json",
46
- "compileOnSave": false,
47
- "compilerOptions": {
48
- "baseUrl": "./",
49
- "outDir": "./dist/out-tsc",
50
- "forceConsistentCasingInFileNames": true,
51
- "strict": true,
52
- "noImplicitOverride": true,
53
- "noPropertyAccessFromIndexSignature": true,
54
- "noImplicitReturns": true,
55
- "noFallthroughCasesInSwitch": true,
56
- "sourceMap": true,
57
- "declaration": false,
58
- "downlevelIteration": true,
59
- "experimentalDecorators": true,
60
- "moduleResolution": "node",
61
- "importHelpers": true,
62
- "noEmit": false,
63
- "target": "es2020",
64
- "module": "es2020",
65
- "lib": ["es2020", "dom"],
66
- "skipLibCheck": true
67
- },
68
- "angularCompilerOptions": {
69
- "enableI18nLegacyMessageIdFormat": false,
70
- "strictInjectionParameters": true,
71
- "strictInputAccessModifiers": true,
72
- "strictTemplates": true,
73
- "allowJs": false
74
- },
75
- "files": [],
76
- "include": ["src/**/*.ts", "src/**/*.tsx"]
77
- }
78
- ```
79
-
80
- Go to [Defining A Component](#defining-a-component) to set up an Angular component
81
- to use in an Astro component.
82
-
83
- ## Manual Installation
84
-
85
- The integration can also be installed manually
86
-
87
- ### Install the Astro Integration
88
-
89
- ```sh
90
- yarn add @analogjs/astro-angular
91
- ```
92
-
93
- ### Install the necessary Angular dependencies
94
-
95
- ```sh
96
- npm install @angular/build @angular/{animations,common,compiler-cli,compiler,core,language-service,forms,platform-browser,platform-server} rxjs tslib --save
97
- ```
98
-
99
- ### Adding the integration
100
-
101
- Add the integration to the `astro.config.mjs`
102
-
103
- ```js
104
- import { defineConfig } from 'astro/config';
105
- import angular from '@analogjs/astro-angular';
106
-
107
- export default defineConfig({
108
- integrations: [angular()],
109
- });
110
- ```
111
-
112
- Go to [Defining A Component](#defining-a-component)
113
-
114
- ## Configuration
115
-
116
- ### Configure Vite Angular Plugin
117
-
118
- Provide an option object to configure the `@analogjs/vite-plugin-angular` powering this plugin.
119
-
120
- ```js
121
- import { defineConfig } from 'astro/config';
122
- import angular from '@analogjs/astro-angular';
123
-
124
- export default defineConfig({
125
- integrations: [
126
- angular({
127
- vite: {
128
- inlineStylesExtension: 'scss|sass|less',
129
- },
130
- }),
131
- ],
132
- });
133
- ```
134
-
135
- ### Filtering File Transforms
136
-
137
- For better compatibility when integrating with other plugins such as [Starlight](https://starlight.astro.build), put the Angular components in a specific folder and use the `transformFilter` callback function to only transform those files.
138
-
139
- ```js
140
- import { defineConfig } from 'astro/config';
141
- import angular from '@analogjs/astro-angular';
142
-
143
- export default defineConfig({
144
- integrations: [
145
- angular({
146
- vite: {
147
- transformFilter: (_code, id) => {
148
- return id.includes('src/components'); // <- only transform Angular TypeScript files
149
- },
150
- },
151
- }),
152
- ],
153
- });
154
- ```
155
-
156
- ### Transforming Packages for SSR Compatibility
157
-
158
- To ensure Angular libraries are transformed during Astro's SSR process, add them to the `ssr.noExternal` array in the Vite config.
159
-
160
- ```js
161
- import { defineConfig } from 'astro/config';
162
-
163
- import angular from '@analogjs/astro-angular';
164
-
165
- export default defineConfig({
166
- integrations: [angular()],
167
- vite: {
168
- ssr: {
169
- // transform these packages during SSR. Globs supported
170
- noExternal: ['@rx-angular/**'],
171
- },
172
- },
173
- });
174
- ```
175
-
176
- ## Defining A Component
177
-
178
- The Astro Angular integration **only** supports rendering standalone components:
179
-
180
- ```ts
181
- import { Component, Input } from '@angular/core';
182
-
183
- @Component({
184
- selector: 'app-hello',
185
- template: `
186
- <p>Hello from Angular!!</p>
187
-
188
- @if (show()) {
189
- <p>{{ helpText() }}</p>
190
- }
191
-
192
- <button (click)="toggle()">Toggle</button>
193
- `,
194
- })
195
- export class HelloComponent {
196
- helpText = input('help');
197
-
198
- show = signal(false);
199
-
200
- toggle() {
201
- this.show.update((show) => !show);
202
- }
203
- }
204
- ```
205
-
206
- Add the Angular component to the Astro component template. This only renders the HTML from the Angular component.
207
-
208
- ```tsx
209
- ---
210
- import { HelloComponent } from '../components/hello.component';
211
-
212
- const helpText = "Helping binding";
213
- ---
214
-
215
- <HelloComponent />
216
- <HelloComponent helpText="Helping" />
217
- <HelloComponent helpText={helpText} />
218
- ```
219
-
220
- To hydrate the component on the client, use one of the Astro [client directives](https://docs.astro.build/en/reference/directives-reference/#client-directives):
221
-
222
- ```tsx
223
- ---
224
- import { HelloComponent } from '../components/hello.component';
225
- ---
226
-
227
- <HelloComponent client:visible />
228
- ```
229
-
230
- Find more information about [Client Directives](https://docs.astro.build/en/reference/directives-reference/#client-directives) in the Astro documentation.
231
-
232
- ### Listening to Component Outputs
233
-
234
- Outputs can be emitted by the Angular component are forwarded as HTML events to the Astro island.
235
- To enable this feature, add a client directive and a unique `[data-analog-id]` property to each Angular component:
236
-
237
- ```tsx
238
- ---
239
- import { HelloComponent } from '../components/hello.component';
240
- ---
241
-
242
- <HelloComponent client:visible data-analog-id="hello-component-1" />
243
- ```
244
-
245
- Then, listen to the event in the Astro component using the `addOutputListener` function:
246
-
247
- ```tsx
248
- ---
249
- import { HelloComponent } from '../components/hello.component';
250
- ---
251
-
252
- <HelloComponent client:visible data-analog-id="hello-component-1" />
253
-
254
- <script>
255
- import { addOutputListener } from '@analogjs/astro-angular/utils';
256
-
257
- addOutputListener('hello-component-1', 'outputName', (event) => {
258
- console.log(event.detail);
259
- });
260
- </script>
261
- ```
262
-
263
- ## Adding Component Providers
264
-
265
- Additional providers can be added to a component for static rendering and client hydration.
266
-
267
- These are `renderProviders` and `clientProviders` respectively. These providers are defined as static arrays on the Component class, and are registered when the component is rendered, and hydrated on the client.
268
-
269
- ```ts
270
- import { Component, OnInit, inject } from '@angular/core';
271
- import { provideHttpClient, HttpClient } from '@angular/common/http';
272
-
273
- interface Todo {
274
- id: number;
275
- title: string;
276
- completed: boolean;
277
- }
278
-
279
- @Component({
280
- selector: 'app-todos',
281
- template: `
282
- <h2>Todos</h2>
283
-
284
- <ul>
285
- @for (todo of todos(); track todo.id) {
286
- <li>
287
- {{ todo.title }}
288
- </li>
289
- }
290
- </ul>
291
- `,
292
- })
293
- export class TodosComponent implements OnInit {
294
- static clientProviders = [provideHttpClient()];
295
- static renderProviders = [TodosComponent.clientProviders];
296
-
297
- http = inject(HttpClient);
298
- todos = signal<Todo[]>([]);
299
-
300
- ngOnInit() {
301
- this.http
302
- .get<Todo[]>('https://jsonplaceholder.typicode.com/todos')
303
- .subscribe((todos) => this.todos.set(todos));
304
- }
305
- }
306
- ```
307
-
308
- ## Using Components in MDX pages
309
-
310
- 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.
311
-
312
- ```js
313
- import { defineConfig } from 'astro/config';
314
- import mdx from '@astrojs/mdx';
315
- import angular from '@analogjs/astro-angular';
316
-
317
- export default defineConfig({
318
- integrations: [mdx(), angular()],
319
- });
320
- ```
321
-
322
- Create an `.mdx` file inside the `src/pages` directory and add the Angular component import below the frontmatter.
323
-
324
- ```md
325
- ---
326
- layout: '../../layouts/BlogPost.astro'
327
- title: 'Using Angular in MDX'
328
- description: 'Lorem ipsum dolor sit amet'
329
- pubDate: 'Sep 22 2022'
330
- ---
331
-
332
- import { HelloComponent } from "../../components/hello.component.ts";
333
-
334
- <HelloComponent />
335
- <HelloComponent helpText="Helping" />
336
- ```
337
-
338
- To hydrate the component on the client, use one of the Astro [client directives](https://docs.astro.build/en/reference/directives-reference/#client-directives):
339
-
340
- ```md
341
- ---
342
- layout: '../../layouts/BlogPost.astro'
343
- title: 'Using Angular in MDX'
344
- description: 'Lorem ipsum dolor sit amet'
345
- pubDate: 'Sep 22 2022'
346
- ---
347
-
348
- import { HelloComponent } from "../../components/hello.component.ts";
349
-
350
- <HelloComponent client:load />
351
- <HelloComponent client:visible helpText="Helping" />
352
- ```
353
-
354
- > Important: In `.mdx` files the component import must end with the `.ts` suffix. Otherwise the dynamic import of the component will fail and the component won't be hydrated.
355
-
356
- ## Current Limitations
357
-
358
- - Only standalone Angular components in version v14.2+ are supported
359
- - Content projection to island components is not supported