From 4e03571ba5822f6208a68e62f29a5d25d310b581 Mon Sep 17 00:00:00 2001 From: Vlad Rindevich Date: Wed, 13 Oct 2021 06:50:26 +0300 Subject: [PATCH] Reimplement sharing system to address Safari issues (#88) * refactor: use alternative implementation approach to fix safari issues * docs: fix README badges * chore: use 2kB for size-limit * test: small fixes --- .size-limit.js | 2 +- README.md | 4 +-- karma.conf.js | 4 +-- src/ConstructedStyleSheet.ts | 68 +++++++++++++++++++++--------------- src/safari.ts | 42 ---------------------- src/utils.ts | 15 +------- test/polyfill.test.ts | 32 +++++++++++++++++ 7 files changed, 77 insertions(+), 90 deletions(-) delete mode 100644 src/safari.ts diff --git a/.size-limit.js b/.size-limit.js index 55aa10b..2aafdff 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -1,6 +1,6 @@ module.exports = [ { path: 'dist/adoptedStyleSheets.js', - limit: '2.5 kB', + limit: '2 kB', }, ]; diff --git a/README.md b/README.md index 922cf00..3557123 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Constructible style sheets polyfill -[![CI](https://github.com/calebdwilliams/construct-style-sheets/actions/workflows/ci/badge.svg)](https://github.com/calebdwilliams/construct-style-sheets/actions) +[![CI](https://github.com/calebdwilliams/construct-style-sheets/actions/workflows/ci.yml/badge.svg)](https://github.com/calebdwilliams/construct-style-sheets/actions) [![npm version](https://img.shields.io/npm/v/construct-style-sheets-polyfill.svg?style=flat)](https://npmjs.org/package/construct-style-sheets-polyfill 'View this project on npm') -[![codecov](https://codecov.io/gh/calebdwilliams/construct-style-sheets/branch/master/graph/badge.svg)](https://codecov.io/gh/calebdwilliams/construct-style-sheets) +[![codecov](https://codecov.io/gh/calebdwilliams/construct-style-sheets/branch/main/graph/badge.svg)](https://codecov.io/gh/calebdwilliams/construct-style-sheets) This package is a polyfill for the [constructible style sheets/adopted style sheets specification](https://github.com/WICG/construct-stylesheets/blob/gh-pages/explainer.md). The full specificaiton is enabled by default in Google Chrome as of version 73. diff --git a/karma.conf.js b/karma.conf.js index 6bc4d11..303a4b9 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -163,14 +163,14 @@ module.exports = (config) => { isolatedModules: true, tsconfig: require.resolve('./tsconfig.test.json'), }), - rollupPluginInstrumentTsCode(), + coverage && rollupPluginInstrumentTsCode(), rollupPluginInjectCode({ 'index.js': { line: 3, code: " if ('adoptedStyleSheets' in document) { return; }\n", }, }), - ], + ].filter(Boolean), output: { format: 'iife', name: 'source', diff --git a/src/ConstructedStyleSheet.ts b/src/ConstructedStyleSheet.ts index ec5887f..e40f3a2 100644 --- a/src/ConstructedStyleSheet.ts +++ b/src/ConstructedStyleSheet.ts @@ -1,7 +1,6 @@ import type Location from './Location'; -import {fixBrokenRules, hasBrokenRules} from './safari'; import {_DOMException, bootstrapper, defineProperty} from './shared'; -import {clearRules, insertAllRules, rejectImports} from './utils'; +import {rejectImports} from './utils'; const cssStyleSheetMethods = [ 'addRule', @@ -45,12 +44,15 @@ export function isNonConstructedStyleSheetInstance(instance: object): boolean { */ /** - * Basic stylesheet is an sample stylesheet that contains all the CSS rules of - * the current constructable stylesheet. The document or custom elements can - * adopt constructable stylesheet; in this case, basic stylesheet's CSS rules - * are reflected in document/custom element internal