@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/README.md +33 -3
- package/dist/index.js +17 -12
- package/lib/index.cjs +50 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +41 -57
- package/package.json +33 -14
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/dist/index.d.ts +0 -14
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/dist/index.js +0 -104
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/dist/index.js.map +0 -1
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/lib/index.d.ts +0 -14
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/lib/index.js +0 -104
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/lib/index.js.map +0 -1
- package/.rollup.cache/Users/matthew/git/oss/jess/packages/attach-css/tsconfig.tsbuildinfo +0 -1736
- package/bs-config.js +0 -8
- package/rollup.config.js +0 -16
- package/src/index.ts +0 -65
- package/test/bootstrap.js +0 -45
- package/test/files/01.html +0 -14
- package/test/files/01.spec.js +0 -19
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1753
package/bs-config.js
DELETED
package/rollup.config.js
DELETED
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
|
-
})
|
package/test/files/01.html
DELETED
package/test/files/01.spec.js
DELETED
|
@@ -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
|
-
})
|