@analogjs/astro-angular 2.4.0-beta.25 → 2.4.0-beta.27
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 +2 -2
- package/src/middleware.d.ts.map +1 -1
- package/src/middleware.js +14 -17
- package/src/middleware.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/astro-angular",
|
|
3
|
-
"version": "2.4.0-beta.
|
|
3
|
+
"version": "2.4.0-beta.27",
|
|
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": "^2.4.0-beta.
|
|
35
|
+
"@analogjs/vite-plugin-angular": "^2.4.0-beta.27",
|
|
36
36
|
"rehype": "^13.0.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
package/src/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAM/C,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAM/C,eAAO,MAAM,SAAS,EAAE,iBAwEvB,CAAC"}
|
package/src/middleware.js
CHANGED
|
@@ -5,7 +5,7 @@ export const onRequest = async (_ctx, next) => {
|
|
|
5
5
|
if (response.headers.get('content-type')?.includes('text/html') !== true) {
|
|
6
6
|
return response;
|
|
7
7
|
}
|
|
8
|
-
// Find all <style> tags in the body and move them to the head
|
|
8
|
+
// Find all <style ng-app-id="..."> tags in the body and move them to the head
|
|
9
9
|
const responseBody = await response.text();
|
|
10
10
|
const tree = processor.parse(responseBody);
|
|
11
11
|
const stack = [tree];
|
|
@@ -17,6 +17,12 @@ export const onRequest = async (_ctx, next) => {
|
|
|
17
17
|
// Templates create a shadow-root, so styles should not be moved outside.
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
|
+
if (top.type === 'element' && top.tagName === 'style') {
|
|
21
|
+
if ('ng-app-id' in top.properties) {
|
|
22
|
+
styleTags.push(top);
|
|
23
|
+
}
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
20
26
|
if (top.type === 'element' && top.tagName === 'head' && !head) {
|
|
21
27
|
head = top;
|
|
22
28
|
continue;
|
|
@@ -24,23 +30,14 @@ export const onRequest = async (_ctx, next) => {
|
|
|
24
30
|
if (top.type !== 'root' && top.type !== 'element') {
|
|
25
31
|
continue;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (child.type === 'element' &&
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
// style tags won't have any children to search
|
|
33
|
+
for (let index = top.children.length - 1; index >= 0; index--) {
|
|
34
|
+
const child = top.children[index];
|
|
35
|
+
stack.push(child);
|
|
36
|
+
if (child.type === 'element' &&
|
|
37
|
+
child.tagName === 'style' &&
|
|
38
|
+
'ng-app-id' in child.properties) {
|
|
39
|
+
top.children.splice(index, 1);
|
|
36
40
|
}
|
|
37
|
-
else {
|
|
38
|
-
stack.push(child);
|
|
39
|
-
}
|
|
40
|
-
index++;
|
|
41
|
-
}
|
|
42
|
-
for (let i = styleIndexes.length - 1; i >= 0; i--) {
|
|
43
|
-
top.children.splice(styleIndexes[i], 1);
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
if (head) {
|
package/src/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;AAE3B,MAAM,CAAC,MAAM,SAAS,GAAsB,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC;QACzE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;AAE3B,MAAM,CAAC,MAAM,SAAS,GAAsB,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC;QACzE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,8EAA8E;IAE9E,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAE3C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE3C,MAAM,KAAK,GAA2B,CAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,SAAS,GAAc,EAAE,CAAC;I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,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,GAAY;YACpB,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,SAAS;YACnB,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,MAAM;SAChB,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC,CAAC","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"]}
|