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

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/dist/index.js CHANGED
@@ -2,10 +2,10 @@
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
- let isBrowser = new Function('try { return this===window } catch(e) { return false }')();
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
  /**
@@ -13,10 +13,10 @@
13
13
  */
14
14
  const updateSheet = (text, id) => {
15
15
  if (!isBrowser) {
16
- return
16
+ return;
17
17
  }
18
18
  if (!id) {
19
- throw new Error('ID is required.')
19
+ throw new Error('ID is required.');
20
20
  }
21
21
  id = 'id_' + id;
22
22
  let el = document.getElementById(id);
@@ -24,6 +24,9 @@
24
24
  el = document.createElement('style');
25
25
  el.setAttribute('id', id);
26
26
  const head = document.getElementsByTagName('head')[0];
27
+ if (!head) {
28
+ throw new Error('Missing <head> element.');
29
+ }
27
30
  el.innerHTML = text;
28
31
  head.appendChild(el);
29
32
  } else {
@@ -31,7 +34,7 @@
31
34
  }
32
35
  sheetMap[id] = text;
33
36
  localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap));
34
- return el
37
+ return el;
35
38
  };
36
39
 
37
40
  /**
@@ -42,10 +45,13 @@
42
45
  function getCachedSheets() {
43
46
  const cache = localStorage.getItem('patchcss:sheets');
44
47
  if (!cache) {
45
- return
48
+ return;
46
49
  }
47
50
  const coll = JSON.parse(cache);
48
51
  const head = document.getElementsByTagName('head')[0];
52
+ if (!head) {
53
+ return;
54
+ }
49
55
 
50
56
  const fragment = document.createDocumentFragment();
51
57
 
@@ -54,12 +60,12 @@
54
60
  /** Sanity check, in case this script gets loaded twice */
55
61
  const exists = document.getElementById(id);
56
62
  if (exists) {
57
- continue
63
+ continue;
58
64
  }
59
65
  const el = document.createElement('style');
60
66
  const text = coll[id];
61
67
  el.setAttribute('id', id);
62
- el.innerHTML = text;
68
+ el.innerHTML = _nullishCoalesce(text, () => ( ''));
63
69
  fragment.appendChild(el);
64
70
  }
65
71
  }
@@ -72,6 +78,4 @@
72
78
 
73
79
  exports.updateSheet = updateSheet;
74
80
 
75
- Object.defineProperty(exports, '__esModule', { value: true });
76
-
77
- })));
81
+ }));
@@ -0,0 +1,16 @@
1
+ import rootConfig from '../../eslint.config.mjs';
2
+ import tseslint from 'typescript-eslint';
3
+
4
+ export default tseslint.config([
5
+ ...rootConfig,
6
+ {
7
+ files: ['*.ts', '*.tsx'],
8
+ languageOptions: {
9
+ parser: tseslint.parser,
10
+ parserOptions: {
11
+ projectService: true,
12
+ tsconfigRootDir: import.meta.dirname
13
+ }
14
+ }
15
+ }
16
+ ]);
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Insert a stylesheet by id
3
3
  */
4
- export declare const updateSheet: (text: string, id: string) => HTMLElement;
4
+ export declare const updateSheet: (text: string, id: string) => HTMLElement | undefined;
package/lib/index.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateSheet = void 0;
4
1
  /** Detect that we're in a browser */
5
- let isBrowser = new Function('try { return this===window } catch(e) { return false }')();
2
+ const isBrowser = new Function('try { return this===window } catch(e) { return false }')();
6
3
  const sheetMap = {};
7
4
  /**
8
5
  * Insert a stylesheet by id
9
6
  */
10
- const updateSheet = (text, id) => {
7
+ export const updateSheet = (text, id) => {
11
8
  if (!isBrowser) {
12
9
  return;
13
10
  }
@@ -20,6 +17,9 @@ const updateSheet = (text, id) => {
20
17
  el = document.createElement('style');
21
18
  el.setAttribute('id', id);
22
19
  const head = document.getElementsByTagName('head')[0];
20
+ if (!head) {
21
+ throw new Error('Missing <head> element.');
22
+ }
23
23
  el.innerHTML = text;
24
24
  head.appendChild(el);
25
25
  }
@@ -30,7 +30,6 @@ const updateSheet = (text, id) => {
30
30
  localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap));
31
31
  return el;
32
32
  };
33
- exports.updateSheet = updateSheet;
34
33
  /**
35
34
  * We don't set sheetMap to the cached value, because ids can
36
35
  * change (maybe?), and we expect the host script to run
@@ -43,6 +42,9 @@ function getCachedSheets() {
43
42
  }
44
43
  const coll = JSON.parse(cache);
45
44
  const head = document.getElementsByTagName('head')[0];
45
+ if (!head) {
46
+ return;
47
+ }
46
48
  const fragment = document.createDocumentFragment();
47
49
  for (let id in coll) {
48
50
  if (coll.hasOwnProperty(id)) {
@@ -54,7 +56,7 @@ function getCachedSheets() {
54
56
  const el = document.createElement('style');
55
57
  const text = coll[id];
56
58
  el.setAttribute('id', id);
57
- el.innerHTML = text;
59
+ el.innerHTML = text ?? '';
58
60
  fragment.appendChild(el);
59
61
  }
60
62
  }
@@ -63,3 +65,4 @@ function getCachedSheets() {
63
65
  if (isBrowser) {
64
66
  getCachedSheets();
65
67
  }
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,SAAS,GAAG,IAAI,QAAQ,CAAC,wDAAwD,CAAC,EAAE,CAAC;AAE3F,MAAM,QAAQ,GAA2B,EAAE,CAAC;AAC5C;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAU,EAAE,EAAE;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IACD,IAAI,C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C;QACV,OAAO;IACT,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;IAEnD,KAAK,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,0DAA0D;YAC1D,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;YAC3C,IAAI,MAAM,EAAE,CAAC;gBACX,SAAS;YACX,CAAC;YACD,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YACtB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,EAAE,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;YAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,IAAI,SAAS,EAAE,CAAC;IACd,eAAe,EAAE,CAAC;AACpB,CAAC"}
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@jesscss/patch-css",
3
- "version": "1.0.8-alpha.8",
3
+ "version": "2.0.0-alpha.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "scripts": {
8
- "ci": "yarn build && yarn test",
9
- "prepublishOnly": "yarn build",
10
- "dist": "rollup -c",
11
- "build": "yarn clean && yarn compile",
12
- "clean": "shx rm -rf ./dist ./lib tsconfig.tsbuildinfo",
13
- "compile": "tsc -b tsconfig.json && yarn dist",
14
- "dev": "tsc -b tsconfig.json -w",
15
- "serve": "lite-server --baseDir=\"test\"",
16
- "test": "yarn dist && mocha test/bootstrap.js --recursive test/**/*.spec.js"
17
- },
18
7
  "description": "Attach stylesheets given an id",
19
8
  "main": "lib/index",
20
9
  "author": "Matthew Dean",
21
10
  "license": "MIT",
22
- "gitHead": "44d328040c6bc3fde2b2ab9a5bdefb19417f4ae2"
23
- }
11
+ "scripts": {
12
+ "ci": "pnpm build && pnpm test",
13
+ "dist": "rollup -c",
14
+ "build": "pnpm clean && pnpm compile",
15
+ "clean": "shx rm -rf ./dist ./lib tsconfig.tsbuildinfo",
16
+ "compile": "tsc -p tsconfig.build.json && pnpm dist",
17
+ "dev": "tsc -p tsconfig.build.json -w",
18
+ "serve": "lite-server --baseDir=\"test\"",
19
+ "test:tofix": "pnpm dist && jest",
20
+ "lint:fix:TOFIX": "eslint --fix '**/*.{js,ts}'",
21
+ "lint:TOFIX": "eslint '**/*.{js,ts}'"
22
+ }
23
+ }
package/src/index.ts CHANGED
@@ -1,31 +1,34 @@
1
1
  /** Detect that we're in a browser */
2
- let isBrowser = new Function('try { return this===window } catch(e) { return false }')()
2
+ const isBrowser = new Function('try { return this===window } catch(e) { return false }')();
3
3
 
4
- const sheetMap: Record<string, string> = {}
4
+ const sheetMap: Record<string, string> = {};
5
5
  /**
6
6
  * Insert a stylesheet by id
7
7
  */
8
8
  export const updateSheet = (text: string, id: string) => {
9
9
  if (!isBrowser) {
10
- return
10
+ return;
11
11
  }
12
12
  if (!id) {
13
- throw new Error('ID is required.')
13
+ throw new Error('ID is required.');
14
14
  }
15
- id = 'id_' + id
16
- let el = document.getElementById(id)
15
+ id = 'id_' + id;
16
+ let el = document.getElementById(id);
17
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)
18
+ el = document.createElement('style');
19
+ el.setAttribute('id', id);
20
+ const head = document.getElementsByTagName('head')[0];
21
+ if (!head) {
22
+ throw new Error('Missing <head> element.');
23
+ }
24
+ el.innerHTML = text;
25
+ head.appendChild(el);
23
26
  } else {
24
- el.innerHTML = text
27
+ el.innerHTML = text;
25
28
  }
26
- sheetMap[id] = text
27
- localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap))
28
- return el
29
+ sheetMap[id] = text;
30
+ localStorage.setItem('patchcss:sheets', JSON.stringify(sheetMap));
31
+ return el;
29
32
  }
30
33
 
31
34
  /**
@@ -34,32 +37,35 @@ export const updateSheet = (text: string, id: string) => {
34
37
  * updateSheet for every current value.
35
38
  */
36
39
  function getCachedSheets() {
37
- const cache = localStorage.getItem('patchcss:sheets')
40
+ const cache = localStorage.getItem('patchcss:sheets');
38
41
  if (!cache) {
39
- return
42
+ return;
43
+ }
44
+ const coll: Record<string, string> = JSON.parse(cache);
45
+ const head = document.getElementsByTagName('head')[0];
46
+ if (!head) {
47
+ return;
40
48
  }
41
- const coll: Record<string, string> = JSON.parse(cache)
42
- const head = document.getElementsByTagName('head')[0]
43
49
 
44
- const fragment = document.createDocumentFragment()
50
+ const fragment = document.createDocumentFragment();
45
51
 
46
52
  for (let id in coll) {
47
53
  if (coll.hasOwnProperty(id)) {
48
54
  /** Sanity check, in case this script gets loaded twice */
49
- const exists = document.getElementById(id)
55
+ const exists = document.getElementById(id);
50
56
  if (exists) {
51
- continue
57
+ continue;
52
58
  }
53
- const el = document.createElement('style')
54
- const text = coll[id]
55
- el.setAttribute('id', id)
56
- el.innerHTML = text
57
- fragment.appendChild(el)
59
+ const el = document.createElement('style');
60
+ const text = coll[id];
61
+ el.setAttribute('id', id);
62
+ el.innerHTML = text ?? '';
63
+ fragment.appendChild(el);
58
64
  }
59
65
  }
60
- head.appendChild(fragment)
66
+ head.appendChild(fragment);
61
67
  }
62
68
 
63
69
  if (isBrowser) {
64
- getCachedSheets()
70
+ getCachedSheets();
65
71
  }
package/test/bootstrap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const puppeteer = require('puppeteer')
2
- const { expect } = require('chai')
2
+
3
3
  const globalVariables = {
4
4
  browser: global.browser,
5
5
  expect: global.expect
@@ -12,7 +12,7 @@ const opts = {
12
12
  }
13
13
 
14
14
  const startServer = () => new Promise((resolve) => {
15
- const browserSync = require('browser-sync').create()
15
+ let browserSync = require('browser-sync').create()
16
16
  browserSync.init({
17
17
  watch: true,
18
18
  open: false,
@@ -21,22 +21,23 @@ const startServer = () => new Promise((resolve) => {
21
21
  directory: true
22
22
  },
23
23
  callbacks: {
24
- ready(err, bs) {
24
+ ready() {
25
25
  resolve(browserSync)
26
26
  }
27
27
  }
28
28
  })
29
29
  })
30
30
  let browserSync
31
+ let browser
31
32
  // expose variables
32
- before (async () => {
33
+ beforeAll(async () => {
33
34
  browserSync = await startServer()
34
35
  global.expect = expect
35
- global.browser = await puppeteer.launch(opts)
36
+ browser = global.browser = await puppeteer.launch(opts)
36
37
  })
37
38
 
38
39
  // close browser and reset global variables
39
- after (() => {
40
+ afterAll(() => {
40
41
  browser.close()
41
42
  browserSync.exit()
42
43
 
@@ -1,19 +1,20 @@
1
- describe('simple test for updated CSS', function () {
1
+ describe('simple test for updated CSS', function() {
2
2
  let page
3
+ let browser
3
4
 
4
- before(async () => {
5
+ beforeAll(async () => {
5
6
  page = await browser.newPage()
6
7
  await page.goto('http://localhost:3000/test/files/01.html')
7
8
  })
8
9
 
9
- after(async () => {
10
+ afterAll(async () => {
10
11
  await page.close()
11
12
  })
12
13
 
13
14
  it('should add a new style block', async () => {
14
15
  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)
16
+ await page.evaluate('patchCss.updateSheet(\'body { background: blue }\', \'foo\')')
17
+ let bg = await page.$eval('body', el => getComputedStyle(el).backgroundColor)
17
18
  expect(bg).to.eq('rgb(0, 0, 255)')
18
19
  })
19
20
  })
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "noEmit": false
7
+ },
8
+ "include": ["src/**/*"],
9
+ "exclude": ["node_modules", "lib", "dist"]
10
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "noEmit": true,
4
5
  "outDir": "./lib",
5
6
  "rootDir": "./src",
6
7
  "lib": ["DOM"]
@@ -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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AAC,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,CAA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D,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"]}