@jesscss/patch-css 1.0.8-alpha.8 → 2.0.0-alpha.10

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/bs-config.js DELETED
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- open: false,
3
- server: {
4
- middleware: {
5
- 0: null
6
- }
7
- }
8
- }
package/rollup.config.js DELETED
@@ -1,16 +0,0 @@
1
-
2
- import sucrase from '@rollup/plugin-sucrase'
3
-
4
- export default {
5
- input: './src/index.ts',
6
- plugins: [
7
- sucrase({
8
- transforms: ['typescript']
9
- })
10
- ],
11
- output: {
12
- file: './dist/index.js',
13
- format: 'umd',
14
- name: 'patchCss'
15
- }
16
- }
package/src/index.ts DELETED
@@ -1,65 +0,0 @@
1
- /** Detect that we're in a browser */
2
- let isBrowser = new Function('try { return this===window } catch(e) { return false }')()
3
-
4
- const sheetMap: Record<string, string> = {}
5
- /**
6
- * Insert a stylesheet by id
7
- */
8
- export const updateSheet = (text: string, id: string) => {
9
- if (!isBrowser) {
10
- return
11
- }
12
- if (!id) {
13
- throw new Error('ID is required.')
14
- }
15
- id = 'id_' + id
16
- let el = document.getElementById(id)
17
- if (!el) {
18
- el = document.createElement('style')
19
- el.setAttribute('id', id)
20
- const head = document.getElementsByTagName('head')[0]
21
- el.innerHTML = text
22
- head.appendChild(el)
23
- } else {
24
- el.innerHTML = text
25
- }
26
- sheetMap[id] = text
27
- localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap))
28
- return el
29
- }
30
-
31
- /**
32
- * We don't set sheetMap to the cached value, because ids can
33
- * change (maybe?), and we expect the host script to run
34
- * updateSheet for every current value.
35
- */
36
- function getCachedSheets() {
37
- const cache = localStorage.getItem('patchcss:sheets')
38
- if (!cache) {
39
- return
40
- }
41
- const coll: Record<string, string> = JSON.parse(cache)
42
- const head = document.getElementsByTagName('head')[0]
43
-
44
- const fragment = document.createDocumentFragment()
45
-
46
- for (let id in coll) {
47
- if (coll.hasOwnProperty(id)) {
48
- /** Sanity check, in case this script gets loaded twice */
49
- const exists = document.getElementById(id)
50
- if (exists) {
51
- continue
52
- }
53
- const el = document.createElement('style')
54
- const text = coll[id]
55
- el.setAttribute('id', id)
56
- el.innerHTML = text
57
- fragment.appendChild(el)
58
- }
59
- }
60
- head.appendChild(fragment)
61
- }
62
-
63
- if (isBrowser) {
64
- getCachedSheets()
65
- }
package/test/bootstrap.js DELETED
@@ -1,45 +0,0 @@
1
- const puppeteer = require('puppeteer')
2
- const { expect } = require('chai')
3
- const globalVariables = {
4
- browser: global.browser,
5
- expect: global.expect
6
- }
7
-
8
- // puppeteer options
9
- const opts = {
10
- headless: true,
11
- timeout: 10000
12
- }
13
-
14
- const startServer = () => new Promise((resolve) => {
15
- const browserSync = require('browser-sync').create()
16
- browserSync.init({
17
- watch: true,
18
- open: false,
19
- server: {
20
- baseDir: './',
21
- directory: true
22
- },
23
- callbacks: {
24
- ready(err, bs) {
25
- resolve(browserSync)
26
- }
27
- }
28
- })
29
- })
30
- let browserSync
31
- // expose variables
32
- before (async () => {
33
- browserSync = await startServer()
34
- global.expect = expect
35
- global.browser = await puppeteer.launch(opts)
36
- })
37
-
38
- // close browser and reset global variables
39
- after (() => {
40
- browser.close()
41
- browserSync.exit()
42
-
43
- global.browser = globalVariables.browser
44
- global.expect = globalVariables.expect
45
- })
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <style>
5
- .box { color: red; }
6
- </style>
7
- </head>
8
- <body>
9
- <script src="../../dist/index.js"></script>
10
- <script>
11
- console.log('foo')
12
- </script>
13
- </body>
14
- </html>
@@ -1,19 +0,0 @@
1
- describe('simple test for updated CSS', function () {
2
- let page
3
-
4
- before(async () => {
5
- page = await browser.newPage()
6
- await page.goto('http://localhost:3000/test/files/01.html')
7
- })
8
-
9
- after(async () => {
10
- await page.close()
11
- })
12
-
13
- it('should add a new style block', async () => {
14
- console.log(await browser.version())
15
- await page.evaluate(`patchCss.updateSheet('body { background: blue }', 'foo')`)
16
- const bg = await page.$eval('body', el => getComputedStyle(el).backgroundColor)
17
- expect(bg).to.eq('rgb(0, 0, 255)')
18
- })
19
- })
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "rootDir": "./src",
6
- "lib": ["DOM"]
7
- },
8
- "include": ["src/**/*"],
9
- "exclude": ["node_modules", "lib", "dist"]
10
- }