@revojs/client 0.2.7 → 0.2.8
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/dist/module/index.d.ts +1 -0
- package/dist/module/index.js +24 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/module/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface ClientConfig {
|
|
|
9
9
|
html: Record<HtmlTags, HtmlTag>;
|
|
10
10
|
}
|
|
11
11
|
export declare function toHtmlTagDescriptor(htmlTag: HtmlTag, injectTo: HtmlTagDescriptor["injectTo"]): HtmlTagDescriptor;
|
|
12
|
+
export declare function cssImportSpecifiers(children: Array<string>): Array<string> | undefined;
|
|
12
13
|
declare const _default: import("revojs/module").Module<"client", ClientConfig, []>;
|
|
13
14
|
export default _default;
|
|
14
15
|
export declare const CLIENT = "client";
|
package/dist/module/index.js
CHANGED
|
@@ -21,6 +21,16 @@ function toHtmlTagDescriptor(htmlTag, injectTo) {
|
|
|
21
21
|
injectTo
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
function cssImportSpecifiers(children) {
|
|
25
|
+
const specifiers = new Array();
|
|
26
|
+
for (const statement of children.join("").split(";")) {
|
|
27
|
+
if (statement.trim() === "") continue;
|
|
28
|
+
const specifier = /^import\s*["']([^"']+)["']$/.exec(statement.trim())?.[1];
|
|
29
|
+
if (specifier === void 0 || !specifier.endsWith(".css")) return;
|
|
30
|
+
specifiers.push(specifier);
|
|
31
|
+
}
|
|
32
|
+
return specifiers.length > 0 ? specifiers : void 0;
|
|
33
|
+
}
|
|
24
34
|
var module_default = defineModule({
|
|
25
35
|
name: "client",
|
|
26
36
|
config: () => ({ html: {
|
|
@@ -65,6 +75,19 @@ var module_default = defineModule({
|
|
|
65
75
|
if (typeof entry === "string" || entry.tagName !== "script" || entry.attributes.type !== "module") return entry;
|
|
66
76
|
const children = entry.children.filter((child) => typeof child === "string");
|
|
67
77
|
if (children.length === 0 || children.length !== entry.children.length) return entry;
|
|
78
|
+
const specifiers = cssImportSpecifiers(children);
|
|
79
|
+
if (specifiers) {
|
|
80
|
+
const name = `client-entry/${index++}.css`;
|
|
81
|
+
addVirtual(config, name, () => specifiers.map((specifier) => `@import ${JSON.stringify(specifier)};`).join("\n"));
|
|
82
|
+
return {
|
|
83
|
+
tagName: "link",
|
|
84
|
+
attributes: {
|
|
85
|
+
rel: "stylesheet",
|
|
86
|
+
href: `/@id/__x00__${name}`
|
|
87
|
+
},
|
|
88
|
+
children: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
68
91
|
const name = `client-entry/${index++}.js`;
|
|
69
92
|
addVirtual(config, name, () => children.join(""));
|
|
70
93
|
return {
|
|
@@ -124,4 +147,4 @@ var module_default = defineModule({
|
|
|
124
147
|
var CLIENT = "client";
|
|
125
148
|
var CLIENT_SUFFIX = "?client";
|
|
126
149
|
//#endregion
|
|
127
|
-
export { CLIENT, CLIENT_SUFFIX, module_default as default, toHtmlTagDescriptor };
|
|
150
|
+
export { CLIENT, CLIENT_SUFFIX, cssImportSpecifiers, module_default as default, toHtmlTagDescriptor };
|
package/dist/package.js
CHANGED