Comparing version 1.0.3 to 1.0.4
@@ -32,3 +32,3 @@ 'use strict'; | ||
* const element = apriori.createFragment(apriori.get('markup.html')); | ||
* const styles = mySophistry.process(element); | ||
* const [styles, promises] = mySophistry.process(element); | ||
* document.body.append(element); | ||
@@ -39,6 +39,7 @@ * for (let style of styles) style.style(element, document.body.firstElementChild); | ||
* @param {boolean} [replace] | ||
* @returns {StyleSheet[]} | ||
* @returns {[StyleSheet[], Promise<any>[]]} | ||
*/ | ||
process(root, replace) { | ||
const styleSheets = []; | ||
const promises = []; | ||
if ((root instanceof HTMLLinkElement && | ||
@@ -62,5 +63,5 @@ root.getAttribute("rel") === "stylesheet") || | ||
st = new CSSStyleSheet(); | ||
fetch(root.getAttribute("href")) | ||
promises.push(fetch(root.getAttribute("href")) | ||
.then((r) => r.text()) | ||
.then((t) => st.replaceSync(t)); | ||
.then((t) => st.replaceSync(t))); | ||
} | ||
@@ -80,9 +81,12 @@ else if (root instanceof HTMLStyleElement) { | ||
let node = root.children[0], node2; | ||
let nodeStyleSheets, nodePromises; | ||
while (node) { | ||
node2 = node.nextElementSibling; | ||
styleSheets.push(...this.process(node, replace)); | ||
[nodeStyleSheets, nodePromises] = this.process(node, replace); | ||
styleSheets.push(...nodeStyleSheets); | ||
promises.push(...nodePromises); | ||
node = node2; | ||
} | ||
} | ||
return styleSheets; | ||
return [styleSheets, promises]; | ||
} | ||
@@ -96,7 +100,7 @@ /** | ||
* @example | ||
* const style = mySophistry.import('style.css'); | ||
* const [style, onImport] = mySophistry.import('style.css'); | ||
* | ||
* @param {string} link | ||
* @param {string} [name] | ||
* @returns {StyleSheet} | ||
* @returns {[StyleSheet, Promise<any>]} | ||
*/ | ||
@@ -107,6 +111,6 @@ import(link, name) { | ||
this.styles[name || link.split(".")[0]] = st2; | ||
fetch(link) | ||
const promise = fetch(link) | ||
.then((r) => r.text()) | ||
.then((t) => st.replaceSync(t)); | ||
return st2; | ||
return [st2, promise]; | ||
} | ||
@@ -131,3 +135,2 @@ /** | ||
} | ||
return this.styles[name]; | ||
} | ||
@@ -134,0 +137,0 @@ } |
@@ -870,3 +870,3 @@ /** | ||
* const element = apriori.createFragment(apriori.get('markup.html')); | ||
* const styles = mySophistry.process(element); | ||
* const [styles, promises] = mySophistry.process(element); | ||
* document.body.append(element); | ||
@@ -877,5 +877,5 @@ * for (let style of styles) style.style(element, document.body.firstElementChild); | ||
* @param {boolean} [replace] | ||
* @returns {StyleSheet[]} | ||
* @returns {[StyleSheet[], Promise<any>[]]} | ||
*/ | ||
process(root: Element | DocumentFragment, replace?: boolean): StyleSheet[]; | ||
process(root: Element | DocumentFragment, replace?: boolean): [StyleSheet[], Promise<any>[]]; | ||
/** | ||
@@ -888,9 +888,9 @@ * Import a stylesheet defined in an external CSS file. Optionally | ||
* @example | ||
* const style = mySophistry.import('style.css'); | ||
* const [style, onImport] = mySophistry.import('style.css'); | ||
* | ||
* @param {string} link | ||
* @param {string} [name] | ||
* @returns {StyleSheet} | ||
* @returns {[StyleSheet, Promise<any>]} | ||
*/ | ||
import(link: string, name?: string): StyleSheet; | ||
import(link: string, name?: string): [StyleSheet, Promise<any>]; | ||
/** | ||
@@ -906,3 +906,3 @@ * Replaces the text of an existing stylesheet. This is reactive. | ||
*/ | ||
set(name: string, css: string): StyleSheet; | ||
set(name: string, css: string): void; | ||
} | ||
@@ -909,0 +909,0 @@ /** |
@@ -30,3 +30,3 @@ /** | ||
* const element = apriori.createFragment(apriori.get('markup.html')); | ||
* const styles = mySophistry.process(element); | ||
* const [styles, promises] = mySophistry.process(element); | ||
* document.body.append(element); | ||
@@ -37,6 +37,7 @@ * for (let style of styles) style.style(element, document.body.firstElementChild); | ||
* @param {boolean} [replace] | ||
* @returns {StyleSheet[]} | ||
* @returns {[StyleSheet[], Promise<any>[]]} | ||
*/ | ||
process(root, replace) { | ||
const styleSheets = []; | ||
const promises = []; | ||
if ((root instanceof HTMLLinkElement && | ||
@@ -60,5 +61,5 @@ root.getAttribute("rel") === "stylesheet") || | ||
st = new CSSStyleSheet(); | ||
fetch(root.getAttribute("href")) | ||
promises.push(fetch(root.getAttribute("href")) | ||
.then((r) => r.text()) | ||
.then((t) => st.replaceSync(t)); | ||
.then((t) => st.replaceSync(t))); | ||
} | ||
@@ -78,9 +79,12 @@ else if (root instanceof HTMLStyleElement) { | ||
let node = root.children[0], node2; | ||
let nodeStyleSheets, nodePromises; | ||
while (node) { | ||
node2 = node.nextElementSibling; | ||
styleSheets.push(...this.process(node, replace)); | ||
[nodeStyleSheets, nodePromises] = this.process(node, replace); | ||
styleSheets.push(...nodeStyleSheets); | ||
promises.push(...nodePromises); | ||
node = node2; | ||
} | ||
} | ||
return styleSheets; | ||
return [styleSheets, promises]; | ||
} | ||
@@ -94,7 +98,7 @@ /** | ||
* @example | ||
* const style = mySophistry.import('style.css'); | ||
* const [style, onImport] = mySophistry.import('style.css'); | ||
* | ||
* @param {string} link | ||
* @param {string} [name] | ||
* @returns {StyleSheet} | ||
* @returns {[StyleSheet, Promise<any>]} | ||
*/ | ||
@@ -105,6 +109,6 @@ import(link, name) { | ||
this.styles[name || link.split(".")[0]] = st2; | ||
fetch(link) | ||
const promise = fetch(link) | ||
.then((r) => r.text()) | ||
.then((t) => st.replaceSync(t)); | ||
return st2; | ||
return [st2, promise]; | ||
} | ||
@@ -129,3 +133,2 @@ /** | ||
} | ||
return this.styles[name]; | ||
} | ||
@@ -132,0 +135,0 @@ } |
{ | ||
"name": "deleight", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -47,2 +47,3 @@ "type": "module", | ||
"test": "node --experimental-modules --test", | ||
"otest": "node --test-only --experimental-modules --test", | ||
"wtest": "node --experimental-modules --test --watch", | ||
@@ -49,0 +50,0 @@ "doc": "npx typedoc --out ./docs//api ./src/*.ts", |
{ | ||
"name": "deleight", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -47,2 +47,3 @@ "type": "module", | ||
"test": "node --experimental-modules --test", | ||
"otest": "node --test-only --experimental-modules --test", | ||
"wtest": "node --experimental-modules --test --watch", | ||
@@ -49,0 +50,0 @@ "doc": "npx typedoc --out ./docs//api ./src/*.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167768
4317