leanweb 3.10.0 → 3.10.1
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/commands/build.js +9 -2
- package/package.json +1 -1
- package/templates/lib/lw-element.js +7 -2
package/commands/build.js
CHANGED
|
@@ -40,14 +40,21 @@ const buildModule = (projectPath) => {
|
|
|
40
40
|
const cmpName = utils.getComponentName(cur);
|
|
41
41
|
let importString = `import './components/${cur}/${cmpName}.js';`;
|
|
42
42
|
return acc + importString + '\n';
|
|
43
|
-
}, '');
|
|
43
|
+
}, `import './global-styles.js';\n`);
|
|
44
44
|
utils.writeIfChanged(`${utils.dirs.build}/${project.name}.js`, jsString);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const buildGlobalStyles = () => {
|
|
48
48
|
const globalCssPath = `${utils.dirs.build}/global-styles.css`;
|
|
49
49
|
const globalCss = fs.existsSync(globalCssPath) ? fs.readFileSync(globalCssPath, 'utf8') : '';
|
|
50
|
-
|
|
50
|
+
|
|
51
|
+
// Extract @import statements and create a JS module that sets up the global styles, including the inline styles and the imports, and write it to global-styles.js
|
|
52
|
+
const imports = [];
|
|
53
|
+
const inlineCss = globalCss.replace(/@import\s+(?:url\()?['"]?([^'"\)]+)['"]?\)?[^;]*;/g, (_, url) => {
|
|
54
|
+
imports.push(url);
|
|
55
|
+
return '';
|
|
56
|
+
});
|
|
57
|
+
const jsModule = `const sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(inlineCss)});\nglobalThis.__lw_globalStyleSheet = sheet;\nglobalThis.__lw_globalStyleImports = ${JSON.stringify(imports)};\n`;
|
|
51
58
|
utils.writeIfChanged(`${utils.dirs.build}/global-styles.js`, jsModule);
|
|
52
59
|
};
|
|
53
60
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as parser from './lw-expr-parser.js';
|
|
2
2
|
import LWEventBus from './lw-event-bus.js';
|
|
3
|
-
import globalStyleSheet from '../global-styles.js';
|
|
4
3
|
|
|
5
4
|
globalThis.leanweb = globalThis.leanweb ?? {
|
|
6
5
|
componentsListeningOnUrlChanges: [],
|
|
@@ -111,7 +110,13 @@ export default class LWElement extends HTMLElement {
|
|
|
111
110
|
componentSheet.replaceSync(ast.css);
|
|
112
111
|
node.innerHTML = ast.html;
|
|
113
112
|
this.attachShadow({ mode: 'open' }).appendChild(node.content);
|
|
114
|
-
this.shadowRoot.adoptedStyleSheets = [
|
|
113
|
+
this.shadowRoot.adoptedStyleSheets = [globalThis.__lw_globalStyleSheet, componentSheet];
|
|
114
|
+
globalThis.__lw_globalStyleImports?.forEach(url => {
|
|
115
|
+
const link = document.createElement('link');
|
|
116
|
+
link.rel = 'stylesheet';
|
|
117
|
+
link.href = url;
|
|
118
|
+
this.shadowRoot.appendChild(link);
|
|
119
|
+
});
|
|
115
120
|
|
|
116
121
|
this._bindMethods();
|
|
117
122
|
setTimeout(() => {
|