leanweb 3.10.0 → 3.10.2

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 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
- const jsModule = `const sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(globalCss)});\nexport default sheet;\n`;
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 = `globalThis.leanweb = globalThis.leanweb ?? {};\nconst sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(inlineCss)});\nglobalThis.leanweb.__lw_globalStyleSheet = sheet;\nglobalThis.leanweb.__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,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "3.10.0",
3
+ "version": "3.10.2",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -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 = [globalStyleSheet, componentSheet];
113
+ this.shadowRoot.adoptedStyleSheets = [globalThis.leanweb.__lw_globalStyleSheet, componentSheet];
114
+ globalThis.leanweb.__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(() => {