leanweb 3.0.9 → 3.10.0

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
@@ -44,6 +44,13 @@ const buildModule = (projectPath) => {
44
44
  utils.writeIfChanged(`${utils.dirs.build}/${project.name}.js`, jsString);
45
45
  };
46
46
 
47
+ const buildGlobalStyles = () => {
48
+ const globalCssPath = `${utils.dirs.build}/global-styles.css`;
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`;
51
+ utils.writeIfChanged(`${utils.dirs.build}/global-styles.js`, jsModule);
52
+ };
53
+
47
54
  const buildHTML = () => {
48
55
  try {
49
56
  project.components.forEach(cmp => {
@@ -53,7 +60,7 @@ const buildModule = (projectPath) => {
53
60
  if (htmlFileExists) {
54
61
  const cssFilename = `${utils.dirs.build}/components/${cmp}/${cmpName}.css`;
55
62
  const cssFileExists = fs.existsSync(cssFilename);
56
- let cssString = `@import "global-styles.css";\n`;
63
+ let cssString = '';
57
64
  if (cssFileExists) {
58
65
  cssString += fs.readFileSync(cssFilename, 'utf8');
59
66
  }
@@ -82,6 +89,7 @@ const buildModule = (projectPath) => {
82
89
  copySrc();
83
90
  copyEnv();
84
91
  buildJS();
92
+ buildGlobalStyles();
85
93
  buildHTML();
86
94
 
87
95
  return project.name;
package/commands/dist.js CHANGED
@@ -60,7 +60,6 @@ const appCSS = fs.readFileSync(`./${utils.dirs.build}/${project.name}.css`, 'utf
60
60
  fs.writeFileSync(`./${utils.dirs.dist}/${project.name}.css`, appCSS);
61
61
 
62
62
  fse.copySync(`./${utils.dirs.build}/favicon.svg`, `./${utils.dirs.dist}/favicon.svg`);
63
- fse.copySync(`./${utils.dirs.build}/global-styles.css`, `./${utils.dirs.dist}/global-styles.css`);
64
63
  project.resources?.forEach(resource => {
65
64
  const source = `./${utils.dirs.build}/${resource}`;
66
65
  if (fs.existsSync(source)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "3.0.9",
3
+ "version": "3.10.0",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -1,5 +1,6 @@
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';
3
4
 
4
5
  globalThis.leanweb = globalThis.leanweb ?? {
5
6
  componentsListeningOnUrlChanges: [],
@@ -106,8 +107,11 @@ export default class LWElement extends HTMLElement {
106
107
  leanweb.builderVersion = ast.builderVersion;
107
108
 
108
109
  const node = document.createElement('template');
109
- node.innerHTML = `<style>${ast.css}</style>${ast.html}`;
110
+ const componentSheet = new CSSStyleSheet();
111
+ componentSheet.replaceSync(ast.css);
112
+ node.innerHTML = ast.html;
110
113
  this.attachShadow({ mode: 'open' }).appendChild(node.content);
114
+ this.shadowRoot.adoptedStyleSheets = [globalStyleSheet, componentSheet];
111
115
 
112
116
  this._bindMethods();
113
117
  setTimeout(() => {