diff --git a/package.json b/package.json index 147b8e7..bf78394 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.1.0", + "version": "1.2.0", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", @@ -9,7 +9,7 @@ ], "scripts": { "build": "esbuild src/index.js --minify --bundle --format=esm --target=esnext --outfile=dist/index.js", - "build-es6": "esbuild src/index.js --minify --bundle --format=esm --target=es6 --outfile=dist/index.es6.js" + "build:es6": "esbuild src/index.js --minify --bundle --format=esm --target=es6 --outfile=dist/index.es6.js" }, "repository": { "type": "git", diff --git a/src/css.js b/src/css.js index a831e9e..1aa4f1e 100644 --- a/src/css.js +++ b/src/css.js @@ -6,6 +6,18 @@ import { RESET_CSS_STYLE } from './constants.js' +let MyCSSStyleSheet = CSSStyleSheet + +if (!document.adoptedStyleSheets) { + MyCSSStyleSheet = class { + elem = document.createElement('style') + + replaceSync(css) { + this.elem.textContent = css.replace(/\s+/g, ' ') + } + } +} + export function css(strs, ...args) { let output = '' let tmp = Array.from(strs) @@ -16,7 +28,7 @@ export function css(strs, ...args) { } export function adoptStyles(root, styles = '') { - let sheet = new CSSStyleSheet() + let sheet = new MyCSSStyleSheet() if (typeof styles === 'string') { styles = [styles] } else { @@ -24,5 +36,9 @@ export function adoptStyles(root, styles = '') { } styles = (RESET_CSS_STYLE + styles.join(' ')).trim() sheet.replaceSync(styles) - root.adoptedStyleSheets.push(sheet) + if (root.adoptedStyleSheets) { + root.adoptedStyleSheets.push(sheet) + } else { + root.appendChild(sheet.elem) + } }