@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/README.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
|
-
# patch-css
|
|
1
|
+
# @jesscss/patch-css
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
**A tiny runtime helper that attaches cached stylesheets from `localStorage` in
|
|
4
|
+
the document head.**
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
`@jesscss/patch-css` is a small browser utility from the
|
|
7
|
+
[Jess](https://github.com/jesscss/jess) project. Loaded synchronously in the
|
|
8
|
+
`<head>` — without `async` or `defer` — it re-attaches any stylesheets that were
|
|
9
|
+
previously cached in `localStorage`, so styling is in place before first paint.
|
|
10
|
+
|
|
11
|
+
It exposes a single function, `updateSheet(text, id)`, which inserts (or updates)
|
|
12
|
+
a `<style>` element for the given id and writes the current stylesheet cache back
|
|
13
|
+
to `localStorage`. To refresh the cache, call `updateSheet` for each stylesheet.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @jesscss/patch-css
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The `latest` and `alpha` dist-tags both point at the current alpha.
|
|
22
|
+
|
|
23
|
+
## Status
|
|
24
|
+
|
|
25
|
+
Alpha, and an early utility surface — expect the shape to change. Please
|
|
26
|
+
[report bugs](https://github.com/jesscss/jess/issues).
|
|
27
|
+
|
|
28
|
+
## Links
|
|
29
|
+
|
|
30
|
+
- Repository: <https://github.com/jesscss/jess>
|
|
31
|
+
- Documentation: <https://jesscss.github.io/> (currently pre-alpha content)
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
[MIT](https://github.com/jesscss/jess/blob/dev/LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.patchCss = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
/** Detect that we're in a browser */
|
|
8
|
-
|
|
7
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }/** Detect that we're in a browser */
|
|
8
|
+
const isBrowser = new Function('try { return this===window } catch(e) { return false }')();
|
|
9
9
|
|
|
10
10
|
const sheetMap = {};
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Insert a stylesheet by id
|
|
13
14
|
*/
|
|
14
15
|
const updateSheet = (text, id) => {
|
|
15
16
|
if (!isBrowser) {
|
|
16
|
-
return
|
|
17
|
+
return;
|
|
17
18
|
}
|
|
18
19
|
if (!id) {
|
|
19
|
-
throw new Error('ID is required.')
|
|
20
|
+
throw new Error('ID is required.');
|
|
20
21
|
}
|
|
21
22
|
id = 'id_' + id;
|
|
22
23
|
let el = document.getElementById(id);
|
|
@@ -24,6 +25,9 @@
|
|
|
24
25
|
el = document.createElement('style');
|
|
25
26
|
el.setAttribute('id', id);
|
|
26
27
|
const head = document.getElementsByTagName('head')[0];
|
|
28
|
+
if (!head) {
|
|
29
|
+
throw new Error('Missing <head> element.');
|
|
30
|
+
}
|
|
27
31
|
el.innerHTML = text;
|
|
28
32
|
head.appendChild(el);
|
|
29
33
|
} else {
|
|
@@ -31,7 +35,7 @@
|
|
|
31
35
|
}
|
|
32
36
|
sheetMap[id] = text;
|
|
33
37
|
localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap));
|
|
34
|
-
return el
|
|
38
|
+
return el;
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
/**
|
|
@@ -42,10 +46,13 @@
|
|
|
42
46
|
function getCachedSheets() {
|
|
43
47
|
const cache = localStorage.getItem('patchcss:sheets');
|
|
44
48
|
if (!cache) {
|
|
45
|
-
return
|
|
49
|
+
return;
|
|
46
50
|
}
|
|
47
51
|
const coll = JSON.parse(cache);
|
|
48
52
|
const head = document.getElementsByTagName('head')[0];
|
|
53
|
+
if (!head) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
|
|
50
57
|
const fragment = document.createDocumentFragment();
|
|
51
58
|
|
|
@@ -54,12 +61,12 @@
|
|
|
54
61
|
/** Sanity check, in case this script gets loaded twice */
|
|
55
62
|
const exists = document.getElementById(id);
|
|
56
63
|
if (exists) {
|
|
57
|
-
continue
|
|
64
|
+
continue;
|
|
58
65
|
}
|
|
59
66
|
const el = document.createElement('style');
|
|
60
67
|
const text = coll[id];
|
|
61
68
|
el.setAttribute('id', id);
|
|
62
|
-
el.innerHTML = text;
|
|
69
|
+
el.innerHTML = _nullishCoalesce(text, () => ( ''));
|
|
63
70
|
fragment.appendChild(el);
|
|
64
71
|
}
|
|
65
72
|
}
|
|
@@ -72,6 +79,4 @@
|
|
|
72
79
|
|
|
73
80
|
exports.updateSheet = updateSheet;
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})));
|
|
82
|
+
}));
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/** Detect that we're in a browser */
|
|
4
|
+
const isBrowser = new Function("try { return this===window } catch(e) { return false }")();
|
|
5
|
+
const sheetMap = {};
|
|
6
|
+
/**
|
|
7
|
+
* Insert a stylesheet by id
|
|
8
|
+
*/
|
|
9
|
+
const updateSheet = (text, id) => {
|
|
10
|
+
if (!isBrowser) return;
|
|
11
|
+
if (!id) throw new Error("ID is required.");
|
|
12
|
+
id = "id_" + id;
|
|
13
|
+
let el = document.getElementById(id);
|
|
14
|
+
if (!el) {
|
|
15
|
+
el = document.createElement("style");
|
|
16
|
+
el.setAttribute("id", id);
|
|
17
|
+
const head = document.getElementsByTagName("head")[0];
|
|
18
|
+
if (!head) throw new Error("Missing <head> element.");
|
|
19
|
+
el.innerHTML = text;
|
|
20
|
+
head.appendChild(el);
|
|
21
|
+
} else el.innerHTML = text;
|
|
22
|
+
sheetMap[id] = text;
|
|
23
|
+
localStorage.setItem("patchcss:sheets", JSON.stringify(sheetMap));
|
|
24
|
+
return el;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* We don't set sheetMap to the cached value, because ids can
|
|
28
|
+
* change (maybe?), and we expect the host script to run
|
|
29
|
+
* updateSheet for every current value.
|
|
30
|
+
*/
|
|
31
|
+
function getCachedSheets() {
|
|
32
|
+
const cache = localStorage.getItem("patchcss:sheets");
|
|
33
|
+
if (!cache) return;
|
|
34
|
+
const coll = JSON.parse(cache);
|
|
35
|
+
const head = document.getElementsByTagName("head")[0];
|
|
36
|
+
if (!head) return;
|
|
37
|
+
const fragment = document.createDocumentFragment();
|
|
38
|
+
for (let id in coll) if (coll.hasOwnProperty(id)) {
|
|
39
|
+
if (document.getElementById(id)) continue;
|
|
40
|
+
const el = document.createElement("style");
|
|
41
|
+
const text = coll[id];
|
|
42
|
+
el.setAttribute("id", id);
|
|
43
|
+
el.innerHTML = text ?? "";
|
|
44
|
+
fragment.appendChild(el);
|
|
45
|
+
}
|
|
46
|
+
head.appendChild(fragment);
|
|
47
|
+
}
|
|
48
|
+
if (isBrowser) getCachedSheets();
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.updateSheet = updateSheet;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,65 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateSheet = void 0;
|
|
1
|
+
//#region src/index.ts
|
|
4
2
|
/** Detect that we're in a browser */
|
|
5
|
-
|
|
3
|
+
const isBrowser = new Function("try { return this===window } catch(e) { return false }")();
|
|
6
4
|
const sheetMap = {};
|
|
7
5
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* Insert a stylesheet by id
|
|
7
|
+
*/
|
|
10
8
|
const updateSheet = (text, id) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
else {
|
|
27
|
-
el.innerHTML = text;
|
|
28
|
-
}
|
|
29
|
-
sheetMap[id] = text;
|
|
30
|
-
localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap));
|
|
31
|
-
return el;
|
|
9
|
+
if (!isBrowser) return;
|
|
10
|
+
if (!id) throw new Error("ID is required.");
|
|
11
|
+
id = "id_" + id;
|
|
12
|
+
let el = document.getElementById(id);
|
|
13
|
+
if (!el) {
|
|
14
|
+
el = document.createElement("style");
|
|
15
|
+
el.setAttribute("id", id);
|
|
16
|
+
const head = document.getElementsByTagName("head")[0];
|
|
17
|
+
if (!head) throw new Error("Missing <head> element.");
|
|
18
|
+
el.innerHTML = text;
|
|
19
|
+
head.appendChild(el);
|
|
20
|
+
} else el.innerHTML = text;
|
|
21
|
+
sheetMap[id] = text;
|
|
22
|
+
localStorage.setItem("patchcss:sheets", JSON.stringify(sheetMap));
|
|
23
|
+
return el;
|
|
32
24
|
};
|
|
33
|
-
exports.updateSheet = updateSheet;
|
|
34
25
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
* We don't set sheetMap to the cached value, because ids can
|
|
27
|
+
* change (maybe?), and we expect the host script to run
|
|
28
|
+
* updateSheet for every current value.
|
|
29
|
+
*/
|
|
39
30
|
function getCachedSheets() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const text = coll[id];
|
|
56
|
-
el.setAttribute('id', id);
|
|
57
|
-
el.innerHTML = text;
|
|
58
|
-
fragment.appendChild(el);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
head.appendChild(fragment);
|
|
62
|
-
}
|
|
63
|
-
if (isBrowser) {
|
|
64
|
-
getCachedSheets();
|
|
31
|
+
const cache = localStorage.getItem("patchcss:sheets");
|
|
32
|
+
if (!cache) return;
|
|
33
|
+
const coll = JSON.parse(cache);
|
|
34
|
+
const head = document.getElementsByTagName("head")[0];
|
|
35
|
+
if (!head) return;
|
|
36
|
+
const fragment = document.createDocumentFragment();
|
|
37
|
+
for (let id in coll) if (coll.hasOwnProperty(id)) {
|
|
38
|
+
if (document.getElementById(id)) continue;
|
|
39
|
+
const el = document.createElement("style");
|
|
40
|
+
const text = coll[id];
|
|
41
|
+
el.setAttribute("id", id);
|
|
42
|
+
el.innerHTML = text ?? "";
|
|
43
|
+
fragment.appendChild(el);
|
|
44
|
+
}
|
|
45
|
+
head.appendChild(fragment);
|
|
65
46
|
}
|
|
47
|
+
if (isBrowser) getCachedSheets();
|
|
48
|
+
//#endregion
|
|
49
|
+
export { updateSheet };
|
package/package.json
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jesscss/patch-css",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.0-alpha.10",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
7
|
+
},
|
|
4
8
|
"publishConfig": {
|
|
5
9
|
"access": "public"
|
|
6
10
|
},
|
|
11
|
+
"description": "Attach stylesheets given an id",
|
|
12
|
+
"main": "lib/index.cjs",
|
|
13
|
+
"module": "lib/index.js",
|
|
14
|
+
"types": "lib/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"import": "./lib/index.js",
|
|
19
|
+
"require": "./lib/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib",
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"author": "Matthew Dean",
|
|
28
|
+
"license": "MIT",
|
|
7
29
|
"scripts": {
|
|
8
|
-
"ci": "
|
|
9
|
-
"
|
|
30
|
+
"ci": "pnpm build && pnpm test",
|
|
31
|
+
"test": "echo 'patch-css has no active test suite (see test:tofix)'",
|
|
10
32
|
"dist": "rollup -c",
|
|
11
|
-
"build": "
|
|
33
|
+
"build": "pnpm clean && pnpm compile",
|
|
12
34
|
"clean": "shx rm -rf ./dist ./lib tsconfig.tsbuildinfo",
|
|
13
|
-
"compile": "tsc -
|
|
14
|
-
"dev": "tsc -
|
|
35
|
+
"compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly && pnpm dist",
|
|
36
|
+
"dev": "tsc -p tsconfig.build.json -w",
|
|
15
37
|
"serve": "lite-server --baseDir=\"test\"",
|
|
16
|
-
"test": "
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"gitHead": "44d328040c6bc3fde2b2ab9a5bdefb19417f4ae2"
|
|
23
|
-
}
|
|
38
|
+
"test:tofix": "pnpm dist && jest",
|
|
39
|
+
"lint:fix:TOFIX": "eslint --fix '**/*.{js,ts}'",
|
|
40
|
+
"lint:TOFIX": "eslint '**/*.{js,ts}'"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Detect that we're in a browser */
|
|
2
|
-
export declare let isBrowser: any;
|
|
3
|
-
export declare function init({ searchStart, searchEnd }: {
|
|
4
|
-
searchStart: any;
|
|
5
|
-
searchEnd: any;
|
|
6
|
-
}): void;
|
|
7
|
-
/**
|
|
8
|
-
* Insert a stylesheet just after the node where styles are found.
|
|
9
|
-
*
|
|
10
|
-
* @todo
|
|
11
|
-
* This is prime for lots of optimization. For Alpha, we just always
|
|
12
|
-
* generate or replace a style block without diffing.
|
|
13
|
-
*/
|
|
14
|
-
export declare function updateSheet(styleContents: string, id: string): void;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/** Detect that we're in a browser */
|
|
2
|
-
export var isBrowser = new Function('try { return this===window } catch(e) { return false }')();
|
|
3
|
-
var sheetLength;
|
|
4
|
-
var _searchStart = '#__jess_start';
|
|
5
|
-
var _searchEnd = '#__jess_end';
|
|
6
|
-
var sheetMap = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* Stringify the contents of all loaded stylesheets
|
|
9
|
-
*/
|
|
10
|
-
function collectStylesheets() {
|
|
11
|
-
sheetLength = document.styleSheets.length;
|
|
12
|
-
for (var i = 0; i < sheetLength; i++) {
|
|
13
|
-
var sheet = document.styleSheets[i];
|
|
14
|
-
if (sheetMap.has(sheet.ownerNode)) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
var rules = sheet.cssRules;
|
|
19
|
-
var numRules = rules.length;
|
|
20
|
-
var ruleText = '';
|
|
21
|
-
for (var j = 0; j < numRules; j++) {
|
|
22
|
-
ruleText += rules[j].cssText;
|
|
23
|
-
}
|
|
24
|
-
sheetMap.set(sheet.ownerNode, ruleText);
|
|
25
|
-
}
|
|
26
|
-
catch (e) { }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function attachLoad() {
|
|
30
|
-
window.addEventListener('DOMContentLoaded', collectStylesheets);
|
|
31
|
-
}
|
|
32
|
-
export function init(_a) {
|
|
33
|
-
var searchStart = _a.searchStart, searchEnd = _a.searchEnd;
|
|
34
|
-
_searchStart = searchStart || _searchStart;
|
|
35
|
-
_searchEnd = searchEnd || _searchEnd;
|
|
36
|
-
if (isBrowser) {
|
|
37
|
-
attachLoad();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Insert a stylesheet just after the node where styles are found.
|
|
42
|
-
*
|
|
43
|
-
* @todo
|
|
44
|
-
* This is prime for lots of optimization. For Alpha, we just always
|
|
45
|
-
* generate or replace a style block without diffing.
|
|
46
|
-
*/
|
|
47
|
-
export function updateSheet(styleContents, id) {
|
|
48
|
-
var previousSheet;
|
|
49
|
-
sheetMap.forEach(function (text, node) {
|
|
50
|
-
if (previousSheet) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (node instanceof Element && node.id === id) {
|
|
54
|
-
previousSheet = { node: node, text: text };
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
var key = id;
|
|
58
|
-
if (!previousSheet) {
|
|
59
|
-
/** Update our map */
|
|
60
|
-
collectStylesheets();
|
|
61
|
-
key = null;
|
|
62
|
-
var startText_1 = _searchStart + " { content: \"" + id + "\"; }";
|
|
63
|
-
var endText_1 = _searchEnd + " { content: \"" + id + "\"; }";
|
|
64
|
-
sheetMap.forEach(function (text, node) {
|
|
65
|
-
if (key !== null) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
var start = text.indexOf(startText_1);
|
|
69
|
-
if (start !== -1) {
|
|
70
|
-
/** This should be the sheet */
|
|
71
|
-
var end = text.indexOf(endText_1);
|
|
72
|
-
if (end !== -1) {
|
|
73
|
-
previousSheet = { text: text, node: node };
|
|
74
|
-
key = 'true';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
var createStyleElement = function (text) {
|
|
80
|
-
var style = document.createElement('style');
|
|
81
|
-
style.setAttribute('media', 'all,jess');
|
|
82
|
-
style.setAttribute('id', id);
|
|
83
|
-
style.innerHTML = text;
|
|
84
|
-
return style;
|
|
85
|
-
};
|
|
86
|
-
if (previousSheet) {
|
|
87
|
-
/** Update existing sheet */
|
|
88
|
-
if (key === id && previousSheet.node instanceof Element) {
|
|
89
|
-
previousSheet.node.innerHTML = styleContents;
|
|
90
|
-
collectStylesheets();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
var next = previousSheet.node.nextElementSibling;
|
|
94
|
-
var style_1 = createStyleElement(styleContents);
|
|
95
|
-
if (next) {
|
|
96
|
-
previousSheet.node.parentNode.insertBefore(style_1, next);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
var head = document.getElementById('head');
|
|
101
|
-
var style = createStyleElement(styleContents);
|
|
102
|
-
head.appendChild(style);
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceR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AkB,GAAG,UAAC,IAAY;QACtC,IAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QAC7C,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QACvC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAC5B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAA;QACtB,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;IAED,IAAI,aAAa,EAAE;QACjB,4BAA4B;QAC5B,IAAI,GAAG,KAAK,EAAE,IAAI,aAAa,CAAC,IAAI,YAAY,OAAO,EAAE;YACvD,aAAa,CAAC,IAAI,CAAC,SAAS,GAAG,aAAa,CAAA;YAC5C,kBAAkB,EAAE,CAAA;YACpB,OAAM;SACP;QACD,IAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAA;QAClD,IAAM,OAAK,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAA;QAC/C,IAAI,IAAI,EAAE;YACR,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAK,EAAE,IAAI,CAAC,CAAA;YACvD,OAAM;SACP;KACF;IAED,IAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAM,KAAK,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAA;IAC/C,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/** Detect that we're in a browser */\nexport let isBrowser = new Function('try { return this===window } catch(e) { return false }')()\n\nlet sheetLength: number\n\nlet _searchStart: string = '#__jess_start'\nlet _searchEnd: string = '#__jess_end'\n\n\nconst sheetMap: Map<Element | ProcessingInstruction, string> = new Map()\n\n/**\n * Stringify the contents of all loaded stylesheets\n */\nfunction collectStylesheets() {\n sheetLength = document.styleSheets.length\n for(let i = 0; i < sheetLength; i++) {\n const sheet = document.styleSheets[i]\n if (sheetMap.has(sheet.ownerNode)) {\n continue\n }\n\n try {\n const rules = sheet.cssRules\n const numRules = rules.length\n let ruleText: string = ''\n for (let j = 0; j < numRules; j++) {\n ruleText += rules[j].cssText\n }\n sheetMap.set(sheet.ownerNode, ruleText)\n } catch (e) {}\n }\n}\n\nfunction attachLoad() {\n window.addEventListener('DOMContentLoaded', collectStylesheets)\n}\n\nexport function init({ searchStart, searchEnd }) {\n _searchStart = searchStart || _searchStart\n _searchEnd = searchEnd || _searchEnd\n\n if (isBrowser) {\n attachLoad()\n }\n}\n\n/**\n * Insert a stylesheet just after the node where styles are found.\n * \n * @todo\n * This is prime for lots of optimization. For Alpha, we just always\n * generate or replace a style block without diffing.\n */\nexport function updateSheet(styleContents: string, id: string) {\n let previousSheet: {\n node: Element | ProcessingInstruction\n text: string\n }\n\n sheetMap.forEach((text, node) => {\n if (previousSheet) {\n return\n }\n if (node instanceof Element && node.id === id) {\n previousSheet = { node, text }\n }\n })\n\n let key = id\n\n if (!previousSheet) {\n /** Update our map */\n collectStylesheets()\n key = null\n\n let startText = `${_searchStart} { content: \"${id}\"; }`\n let endText = `${_searchEnd} { content: \"${id}\"; }`\n\n sheetMap.forEach((text, node) => {\n if (key !== null) {\n return\n }\n let start = text.indexOf(startText)\n if (start !== -1) {\n /** This should be the sheet */\n let end = text.indexOf(endText)\n if (end !== -1) {\n previousSheet = { text, node }\n key = 'true'\n }\n }\n })\n }\n\n const createStyleElement = (text: string) => {\n const style = document.createElement('style')\n style.setAttribute('media', 'all,jess')\n style.setAttribute('id', id)\n style.innerHTML = text\n return style\n }\n\n if (previousSheet) {\n /** Update existing sheet */\n if (key === id && previousSheet.node instanceof Element) {\n previousSheet.node.innerHTML = styleContents\n collectStylesheets()\n return\n }\n const next = previousSheet.node.nextElementSibling\n const style = createStyleElement(styleContents)\n if (next) {\n previousSheet.node.parentNode.insertBefore(style, next)\n return\n }\n }\n\n const head = document.getElementById('head')\n const style = createStyleElement(styleContents)\n head.appendChild(style)\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Detect that we're in a browser */
|
|
2
|
-
export declare let isBrowser: any;
|
|
3
|
-
export declare function init({ searchStart, searchEnd }: {
|
|
4
|
-
searchStart: any;
|
|
5
|
-
searchEnd: any;
|
|
6
|
-
}): void;
|
|
7
|
-
/**
|
|
8
|
-
* Insert a stylesheet just after the node where styles are found.
|
|
9
|
-
*
|
|
10
|
-
* @todo
|
|
11
|
-
* This is prime for lots of optimization. For Alpha, we just always
|
|
12
|
-
* generate or replace a style block without diffing.
|
|
13
|
-
*/
|
|
14
|
-
export declare function updateSheet(styleContents: string, id: string): void;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/** Detect that we're in a browser */
|
|
2
|
-
export var isBrowser = new Function('try { return this===window } catch(e) { return false }')();
|
|
3
|
-
var sheetLength;
|
|
4
|
-
var _searchStart = '#__jess_start';
|
|
5
|
-
var _searchEnd = '#__jess_end';
|
|
6
|
-
var sheetMap = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* Stringify the contents of all loaded stylesheets
|
|
9
|
-
*/
|
|
10
|
-
function collectStylesheets() {
|
|
11
|
-
sheetLength = document.styleSheets.length;
|
|
12
|
-
for (var i = 0; i < sheetLength; i++) {
|
|
13
|
-
var sheet = document.styleSheets[i];
|
|
14
|
-
if (sheetMap.has(sheet.ownerNode)) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
var rules = sheet.cssRules;
|
|
19
|
-
var numRules = rules.length;
|
|
20
|
-
var ruleText = '';
|
|
21
|
-
for (var j = 0; j < numRules; j++) {
|
|
22
|
-
ruleText += rules[j].cssText;
|
|
23
|
-
}
|
|
24
|
-
sheetMap.set(sheet.ownerNode, ruleText);
|
|
25
|
-
}
|
|
26
|
-
catch (e) { }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function attachLoad() {
|
|
30
|
-
window.addEventListener('DOMContentLoaded', collectStylesheets);
|
|
31
|
-
}
|
|
32
|
-
export function init(_a) {
|
|
33
|
-
var searchStart = _a.searchStart, searchEnd = _a.searchEnd;
|
|
34
|
-
_searchStart = searchStart || _searchStart;
|
|
35
|
-
_searchEnd = searchEnd || _searchEnd;
|
|
36
|
-
if (isBrowser) {
|
|
37
|
-
attachLoad();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Insert a stylesheet just after the node where styles are found.
|
|
42
|
-
*
|
|
43
|
-
* @todo
|
|
44
|
-
* This is prime for lots of optimization. For Alpha, we just always
|
|
45
|
-
* generate or replace a style block without diffing.
|
|
46
|
-
*/
|
|
47
|
-
export function updateSheet(styleContents, id) {
|
|
48
|
-
var previousSheet;
|
|
49
|
-
sheetMap.forEach(function (text, node) {
|
|
50
|
-
if (previousSheet) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (node instanceof Element && node.id === id) {
|
|
54
|
-
previousSheet = { node: node, text: text };
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
var key = id;
|
|
58
|
-
if (!previousSheet) {
|
|
59
|
-
/** Update our map */
|
|
60
|
-
collectStylesheets();
|
|
61
|
-
key = null;
|
|
62
|
-
var startText_1 = _searchStart + " { content: \"" + id + "\"; }";
|
|
63
|
-
var endText_1 = _searchEnd + " { content: \"" + id + "\"; }";
|
|
64
|
-
sheetMap.forEach(function (text, node) {
|
|
65
|
-
if (key !== null) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
var start = text.indexOf(startText_1);
|
|
69
|
-
if (start !== -1) {
|
|
70
|
-
/** This should be the sheet */
|
|
71
|
-
var end = text.indexOf(endText_1);
|
|
72
|
-
if (end !== -1) {
|
|
73
|
-
previousSheet = { text: text, node: node };
|
|
74
|
-
key = 'true';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
var createStyleElement = function (text) {
|
|
80
|
-
var style = document.createElement('style');
|
|
81
|
-
style.setAttribute('media', 'all,jess');
|
|
82
|
-
style.setAttribute('id', id);
|
|
83
|
-
style.innerHTML = text;
|
|
84
|
-
return style;
|
|
85
|
-
};
|
|
86
|
-
if (previousSheet) {
|
|
87
|
-
/** Update existing sheet */
|
|
88
|
-
if (key === id && previousSheet.node instanceof Element) {
|
|
89
|
-
previousSheet.node.innerHTML = styleContents;
|
|
90
|
-
collectStylesheets();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
var next = previousSheet.node.nextElementSibling;
|
|
94
|
-
var style_1 = createStyleElement(styleContents);
|
|
95
|
-
if (next) {
|
|
96
|
-
previousSheet.node.parentNode.insertBefore(style_1, next);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
var head = document.getElementById('head');
|
|
101
|
-
var style = createStyleElement(styleContents);
|
|
102
|
-
head.appendChild(style);
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,CAAC,IAAI,SAAS,GAAG,IAAI,QAAQ,CAAC,wDAAwD,CAAC,EAAE,CAAA;AAE/F,IAAI,WAAmB,CAAA;AAEvB,IAAI,YAAY,GAAW,eAAe,CAAA;AAC1C,IAAI,UAAU,GAAW,aAAa,CAAA;AAGtC,IAAM,QAAQ,GAAiD,IAAI,GAAG,EAAE,CAAA;AAExE;;GAEG;AACH,SAAS,kBAAkB;IACzB,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAA;IACzC,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE;QACnC,IAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACrC,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,S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AAM,OAAK,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAA;QAC/C,IAAI,IAAI,EAAE;YACR,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAK,EAAE,IAAI,CAAC,CAAA;YACvD,OAAM;SACP;KACF;IAED,IAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAM,KAAK,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAA;IAC/C,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/** Detect that we're in a browser */\nexport let isBrowser = new Function('try { return this===window } catch(e) { return false }')()\n\nlet sheetLength: number\n\nlet _searchStart: string = '#__jess_start'\nlet _searchEnd: string = '#__jess_end'\n\n\nconst sheetMap: Map<Element | ProcessingInstruction, string> = new Map()\n\n/**\n * Stringify the contents of all loaded stylesheets\n */\nfunction collectStylesheets() {\n sheetLength = document.styleSheets.length\n for(let i = 0; i < sheetLength; i++) {\n const sheet = document.styleSheets[i]\n if (sheetMap.has(sheet.ownerNode)) {\n continue\n }\n\n try {\n const rules = sheet.cssRules\n const numRules = rules.length\n let ruleText: string = ''\n for (let j = 0; j < numRules; j++) {\n ruleText += rules[j].cssText\n }\n sheetMap.set(sheet.ownerNode, ruleText)\n } catch (e) {}\n }\n}\n\nfunction attachLoad() {\n window.addEventListener('DOMContentLoaded', collectStylesheets)\n}\n\nexport function init({ searchStart, searchEnd }) {\n _searchStart = searchStart || _searchStart\n _searchEnd = searchEnd || _searchEnd\n\n if (isBrowser) {\n attachLoad()\n }\n}\n\n/**\n * Insert a stylesheet just after the node where styles are found.\n * \n * @todo\n * This is prime for lots of optimization. For Alpha, we just always\n * generate or replace a style block without diffing.\n */\nexport function updateSheet(styleContents: string, id: string) {\n let previousSheet: {\n node: Element | ProcessingInstruction\n text: string\n }\n\n sheetMap.forEach((text, node) => {\n if (previousSheet) {\n return\n }\n if (node instanceof Element && node.id === id) {\n previousSheet = { node, text }\n }\n })\n\n let key = id\n\n if (!previousSheet) {\n /** Update our map */\n collectStylesheets()\n key = null\n\n let startText = `${_searchStart} { content: \"${id}\"; }`\n let endText = `${_searchEnd} { content: \"${id}\"; }`\n\n sheetMap.forEach((text, node) => {\n if (key !== null) {\n return\n }\n let start = text.indexOf(startText)\n if (start !== -1) {\n /** This should be the sheet */\n let end = text.indexOf(endText)\n if (end !== -1) {\n previousSheet = { text, node }\n key = 'true'\n }\n }\n })\n }\n\n const createStyleElement = (text: string) => {\n const style = document.createElement('style')\n style.setAttribute('media', 'all,jess')\n style.setAttribute('id', id)\n style.innerHTML = text\n return style\n }\n\n if (previousSheet) {\n /** Update existing sheet */\n if (key === id && previousSheet.node instanceof Element) {\n previousSheet.node.innerHTML = styleContents\n collectStylesheets()\n return\n }\n const next = previousSheet.node.nextElementSibling\n const style = createStyleElement(styleContents)\n if (next) {\n previousSheet.node.parentNode.insertBefore(style, next)\n return\n }\n }\n\n const head = document.getElementById('head')\n const style = createStyleElement(styleContents)\n head.appendChild(style)\n}\n"]}
|