Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results
Show changes
Showing
with 476 additions and 562 deletions
...@@ -15,11 +15,11 @@ import { ...@@ -15,11 +15,11 @@ import {
ATTRIBUTE_SRC, ATTRIBUTE_SRC,
ATTRIBUTE_TITLE, ATTRIBUTE_TITLE,
ATTRIBUTE_TYPE, ATTRIBUTE_TYPE,
TAG_SCRIPT TAG_SCRIPT,
} from "../constants.mjs"; } from "../constants.mjs";
import { KEY_DOCUMENT, KEY_QUERY, referenceSymbol, Resource } from "../resource.mjs"; import { KEY_DOCUMENT, KEY_QUERY, referenceSymbol, Resource } from "../resource.mjs";
import {instanceSymbol} from '../../constants.mjs'; import { instanceSymbol } from "../../constants.mjs";
export {Data} export { Data };
/** /**
* This class is used by the resource manager to embed data. * This class is used by the resource manager to embed data.
...@@ -31,7 +31,6 @@ export {Data} ...@@ -31,7 +31,6 @@ export {Data}
* @summary A Data Resource class * @summary A Data Resource class
*/ */
class Data extends Resource { class Data extends Resource {
/** /**
* @property {string} mode=cors https://developer.mozilla.org/en-US/docs/Web/API/fetch * @property {string} mode=cors https://developer.mozilla.org/en-US/docs/Web/API/fetch
* @property {string} credentials=same-origin https://developer.mozilla.org/en-US/docs/Web/API/fetch * @property {string} credentials=same-origin https://developer.mozilla.org/en-US/docs/Web/API/fetch
...@@ -39,10 +38,10 @@ class Data extends Resource { ...@@ -39,10 +38,10 @@ class Data extends Resource {
*/ */
get defaults() { get defaults() {
return extend({}, super.defaults, { return extend({}, super.defaults, {
mode: 'cors', mode: "cors",
credentials: 'same-origin', credentials: "same-origin",
type: 'application/json', type: "application/json",
}) });
} }
/** /**
...@@ -61,7 +60,6 @@ class Data extends Resource { ...@@ -61,7 +60,6 @@ class Data extends Resource {
* @return {Monster.DOM.Resource} * @return {Monster.DOM.Resource}
*/ */
connect() { connect() {
if (!(this[referenceSymbol] instanceof HTMLElement)) { if (!(this[referenceSymbol] instanceof HTMLElement)) {
this.create(); this.create();
} }
...@@ -79,14 +77,12 @@ class Data extends Resource { ...@@ -79,14 +77,12 @@ class Data extends Resource {
return Symbol.for("@schukai/monster/dom/resource/data"); return Symbol.for("@schukai/monster/dom/resource/data");
} }
/** /**
* @return {string} * @return {string}
*/ */
static getURLAttribute() { static getURLAttribute() {
return ATTRIBUTE_SRC return ATTRIBUTE_SRC;
} }
} }
/** /**
...@@ -108,7 +104,6 @@ function createElement() { ...@@ -108,7 +104,6 @@ function createElement() {
return self; return self;
} }
/** /**
* @private * @private
* @return {Promise} * @return {Promise}
...@@ -117,44 +112,41 @@ function createElement() { ...@@ -117,44 +112,41 @@ function createElement() {
function appendToDocument() { function appendToDocument() {
const self = this; const self = this;
const targetNode = document.querySelector(self.getOption(KEY_QUERY, 'head')) const targetNode = document.querySelector(self.getOption(KEY_QUERY, "head"));
if (!(targetNode instanceof HTMLElement)) { if (!(targetNode instanceof HTMLElement)) {
throw new Error('target not found') throw new Error("target not found");
} }
targetNode.appendChild(self[referenceSymbol]); targetNode.appendChild(self[referenceSymbol]);
getGlobalFunction('fetch')(self.getOption(ATTRIBUTE_SRC), { getGlobalFunction("fetch")(self.getOption(ATTRIBUTE_SRC), {
method: 'GET', // *GET, POST, PUT, DELETE, etc. method: "GET", // *GET, POST, PUT, DELETE, etc.
mode: self.getOption('mode', 'cors'), // no-cors, *cors, same-origin mode: self.getOption("mode", "cors"), // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: self.getOption('credentials', 'same-origin'), // include, *same-origin, omit credentials: self.getOption("credentials", "same-origin"), // include, *same-origin, omit
headers: { headers: {
'Accept': self.getOption('type', 'application/json') Accept: self.getOption("type", "application/json"),
}, },
redirect: 'follow', // manual, *follow, error redirect: "follow", // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, referrerPolicy: "no-referrer", // no-referrer,
}).then(response => { })
.then((response) => {
return response.text() return response.text();
})
.then((text) => {
}).then(text => {
const textNode = document.createTextNode(text); const textNode = document.createTextNode(text);
self[referenceSymbol].appendChild(textNode); self[referenceSymbol].appendChild(textNode);
self[internalStateSymbol].getSubject()['loaded'] = true; self[internalStateSymbol].getSubject()["loaded"] = true;
})
.catch((e) => {
}).catch(e => {
self[internalStateSymbol].setSubject({ self[internalStateSymbol].setSubject({
loaded: true, loaded: true,
error: e.toString(), error: e.toString(),
}) });
targetNode.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.toString()); targetNode.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.toString());
}) });
return self; return self;
} }
...@@ -10,13 +10,15 @@ import { ...@@ -10,13 +10,15 @@ import {
ATTRIBUTE_CLASS, ATTRIBUTE_CLASS,
ATTRIBUTE_HREF, ATTRIBUTE_HREF,
ATTRIBUTE_ID, ATTRIBUTE_ID,
ATTRIBUTE_NONCE, ATTRIBUTE_SRC, ATTRIBUTE_NONCE,
ATTRIBUTE_TITLE, ATTRIBUTE_TYPE, ATTRIBUTE_SRC,
TAG_LINK ATTRIBUTE_TITLE,
ATTRIBUTE_TYPE,
TAG_LINK,
} from "../constants.mjs"; } from "../constants.mjs";
import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs"; import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs";
import {instanceSymbol} from '../../constants.mjs'; import { instanceSymbol } from "../../constants.mjs";
export {Link} export { Link };
/** /**
* This class is used by the resource manager to embed external resources. * This class is used by the resource manager to embed external resources.
...@@ -29,7 +31,6 @@ export {Link} ...@@ -29,7 +31,6 @@ export {Link}
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
*/ */
class Link extends Resource { class Link extends Resource {
/** /**
* @property {string} as {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as} * @property {string} as {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as}
* @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin} * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
...@@ -50,7 +51,7 @@ class Link extends Resource { ...@@ -50,7 +51,7 @@ class Link extends Resource {
get defaults() { get defaults() {
return extend({}, super.defaults, { return extend({}, super.defaults, {
as: undefined, as: undefined,
crossOrigin: 'anonymous', crossOrigin: "anonymous",
disabled: undefined, disabled: undefined,
href: undefined, href: undefined,
hreflang: undefined, hreflang: undefined,
...@@ -63,8 +64,8 @@ class Link extends Resource { ...@@ -63,8 +64,8 @@ class Link extends Resource {
rel: undefined, rel: undefined,
sizes: undefined, sizes: undefined,
type: undefined, type: undefined,
nonce: undefined nonce: undefined,
}) });
} }
/** /**
...@@ -76,7 +77,6 @@ class Link extends Resource { ...@@ -76,7 +77,6 @@ class Link extends Resource {
return Symbol.for("@schukai/monster/dom/resource/link"); return Symbol.for("@schukai/monster/dom/resource/link");
} }
/** /**
* *
* @return {Monster.DOM.Resource.Link} * @return {Monster.DOM.Resource.Link}
...@@ -90,9 +90,8 @@ class Link extends Resource { ...@@ -90,9 +90,8 @@ class Link extends Resource {
* @return {string} * @return {string}
*/ */
static getURLAttribute() { static getURLAttribute() {
return ATTRIBUTE_HREF return ATTRIBUTE_HREF;
} }
} }
/** /**
...@@ -105,7 +104,27 @@ function createElement() { ...@@ -105,7 +104,27 @@ function createElement() {
const document = self.getOption(KEY_DOCUMENT); const document = self.getOption(KEY_DOCUMENT);
self[referenceSymbol] = document.createElement(TAG_LINK); self[referenceSymbol] = document.createElement(TAG_LINK);
for (let key of ['as','crossOrigin','disabled','href','hreflang','imagesizes','imagesrcset','integrity','media','prefetch','referrerpolicy','sizes','rel','type',ATTRIBUTE_HREF,ATTRIBUTE_ID,ATTRIBUTE_CLASS,ATTRIBUTE_TITLE,ATTRIBUTE_NONCE]) { for (let key of [
"as",
"crossOrigin",
"disabled",
"href",
"hreflang",
"imagesizes",
"imagesrcset",
"integrity",
"media",
"prefetch",
"referrerpolicy",
"sizes",
"rel",
"type",
ATTRIBUTE_HREF,
ATTRIBUTE_ID,
ATTRIBUTE_CLASS,
ATTRIBUTE_TITLE,
ATTRIBUTE_NONCE,
]) {
if (self.getOption(key) !== undefined) { if (self.getOption(key) !== undefined) {
self[referenceSymbol][key] = self.getOption(key); self[referenceSymbol][key] = self.getOption(key);
} }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0 * SPDX-License-Identifier: AGPL-3.0
*/ */
/** /**
* In this namespace you will find classes and methods for links * In this namespace you will find classes and methods for links
* *
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
import { extend } from "../../../data/extend.mjs"; import { extend } from "../../../data/extend.mjs";
import { Link } from "../link.mjs"; import { Link } from "../link.mjs";
import {instanceSymbol} from '../../../constants.mjs'; import { instanceSymbol } from "../../../constants.mjs";
export {Stylesheet} export { Stylesheet };
/** /**
* This class is used by the resource manager to embed external resources. * This class is used by the resource manager to embed external resources.
...@@ -21,14 +21,13 @@ export {Stylesheet} ...@@ -21,14 +21,13 @@ export {Stylesheet}
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
*/ */
class Stylesheet extends Link { class Stylesheet extends Link {
/** /**
* @property {string} rel {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-rel} * @property {string} rel {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-rel}
*/ */
get defaults() { get defaults() {
return extend({}, super.defaults, { return extend({}, super.defaults, {
rel: 'stylesheet' rel: "stylesheet",
}) });
} }
/** /**
...@@ -37,9 +36,6 @@ class Stylesheet extends Link { ...@@ -37,9 +36,6 @@ class Stylesheet extends Link {
* @since 2.1.0 * @since 2.1.0
*/ */
static get [instanceSymbol]() { static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/dom/resource/link/stylesheet") return Symbol.for("@schukai/monster/dom/resource/link/stylesheet");
} }
} }
...@@ -13,11 +13,11 @@ import { ...@@ -13,11 +13,11 @@ import {
ATTRIBUTE_SRC, ATTRIBUTE_SRC,
ATTRIBUTE_TITLE, ATTRIBUTE_TITLE,
ATTRIBUTE_TYPE, ATTRIBUTE_TYPE,
TAG_SCRIPT TAG_SCRIPT,
} from "../constants.mjs"; } from "../constants.mjs";
import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs"; import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs";
import {instanceSymbol} from '../../constants.mjs'; import { instanceSymbol } from "../../constants.mjs";
export {Script} export { Script };
/** /**
* This class is used by the resource manager to embed scripts. * This class is used by the resource manager to embed scripts.
...@@ -29,7 +29,6 @@ export {Script} ...@@ -29,7 +29,6 @@ export {Script}
* @summary A Resource class * @summary A Resource class
*/ */
class Script extends Resource { class Script extends Resource {
/** /**
* @property {boolean} async=true {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async} * @property {boolean} async=true {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async}
* @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin} * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
...@@ -43,14 +42,14 @@ class Script extends Resource { ...@@ -43,14 +42,14 @@ class Script extends Resource {
get defaults() { get defaults() {
return extend({}, super.defaults, { return extend({}, super.defaults, {
async: true, async: true,
crossOrigin: 'anonymous', crossOrigin: "anonymous",
defer: false, defer: false,
integrity: undefined, integrity: undefined,
nomodule: false, nomodule: false,
nonce: undefined, nonce: undefined,
referrerpolicy: undefined, referrerpolicy: undefined,
type: 'text/javascript', type: "text/javascript",
}) });
} }
/** /**
...@@ -75,9 +74,8 @@ class Script extends Resource { ...@@ -75,9 +74,8 @@ class Script extends Resource {
* @return {string} * @return {string}
*/ */
static getURLAttribute() { static getURLAttribute() {
return ATTRIBUTE_SRC return ATTRIBUTE_SRC;
} }
} }
/** /**
...@@ -90,12 +88,24 @@ function createElement() { ...@@ -90,12 +88,24 @@ function createElement() {
const document = self.getOption(KEY_DOCUMENT); const document = self.getOption(KEY_DOCUMENT);
self[referenceSymbol] = document.createElement(TAG_SCRIPT); self[referenceSymbol] = document.createElement(TAG_SCRIPT);
for (let key of ['crossOrigin', 'defer', 'async', 'integrity', 'nomodule', ATTRIBUTE_NONCE, 'referrerpolicy', ATTRIBUTE_TYPE, ATTRIBUTE_SRC, ATTRIBUTE_ID, ATTRIBUTE_CLASS, ATTRIBUTE_TITLE]) { for (let key of [
"crossOrigin",
"defer",
"async",
"integrity",
"nomodule",
ATTRIBUTE_NONCE,
"referrerpolicy",
ATTRIBUTE_TYPE,
ATTRIBUTE_SRC,
ATTRIBUTE_ID,
ATTRIBUTE_CLASS,
ATTRIBUTE_TITLE,
]) {
if (self.getOption(key) !== undefined) { if (self.getOption(key) !== undefined) {
self[referenceSymbol][key] = self.getOption(key); self[referenceSymbol][key] = self.getOption(key);
} }
} }
return self; return self;
} }
...@@ -15,7 +15,7 @@ import {Data} from "./resource/data.mjs"; ...@@ -15,7 +15,7 @@ import {Data} from "./resource/data.mjs";
import { Stylesheet } from "./resource/link/stylesheet.mjs"; import { Stylesheet } from "./resource/link/stylesheet.mjs";
import { Script } from "./resource/script.mjs"; import { Script } from "./resource/script.mjs";
export {ResourceManager} export { ResourceManager };
/** /**
* The ResourceManager is a singleton that manages all resources. * The ResourceManager is a singleton that manages all resources.
...@@ -27,7 +27,6 @@ export {ResourceManager} ...@@ -27,7 +27,6 @@ export {ResourceManager}
* @summary A Resource class * @summary A Resource class
*/ */
class ResourceManager extends BaseWithOptions { class ResourceManager extends BaseWithOptions {
/** /**
* *
* @param {Object} options * @param {Object} options
...@@ -36,18 +35,16 @@ export {ResourceManager} ...@@ -36,18 +35,16 @@ export {ResourceManager}
constructor(options) { constructor(options) {
super(options); super(options);
if (!(this.getOption('document') instanceof Document)) { if (!(this.getOption("document") instanceof Document)) {
throw new Error('unsupported document type') throw new Error("unsupported document type");
} }
} }
/** /**
* @property {string} baseurl * @property {string} baseurl
*/ */
getBaseURL() { getBaseURL() {
this.getOption('document')?.baseURL; this.getOption("document")?.baseURL;
} }
/** /**
...@@ -60,13 +57,13 @@ export {ResourceManager} ...@@ -60,13 +57,13 @@ export {ResourceManager}
*/ */
get defaults() { get defaults() {
return Object.assign({}, super.defaults, { return Object.assign({}, super.defaults, {
document: getGlobalObject('document'), document: getGlobalObject("document"),
resources: { resources: {
scripts: [], scripts: [],
stylesheets: [], stylesheets: [],
data: [] data: [],
} },
}) });
} }
/** /**
...@@ -76,7 +73,7 @@ export {ResourceManager} ...@@ -76,7 +73,7 @@ export {ResourceManager}
* @throws {Error} unsupported resource definition * @throws {Error} unsupported resource definition
*/ */
connect() { connect() {
runResourceMethod.call(this, 'connect'); runResourceMethod.call(this, "connect");
return this; return this;
} }
...@@ -87,7 +84,7 @@ export {ResourceManager} ...@@ -87,7 +84,7 @@ export {ResourceManager}
* @throws {Error} unsupported resource definition * @throws {Error} unsupported resource definition
*/ */
available() { available() {
return Promise.all(runResourceMethod.call(this, 'available')); return Promise.all(runResourceMethod.call(this, "available"));
} }
/** /**
...@@ -99,10 +96,9 @@ export {ResourceManager} ...@@ -99,10 +96,9 @@ export {ResourceManager}
* @see Monster.DOM.Resource.Script * @see Monster.DOM.Resource.Script
*/ */
addScript(url, options) { addScript(url, options) {
return addResource.call(this, 'scripts', url, options); return addResource.call(this, "scripts", url, options);
} }
/** /**
* Add Stylesheet * Add Stylesheet
* *
...@@ -112,7 +108,7 @@ export {ResourceManager} ...@@ -112,7 +108,7 @@ export {ResourceManager}
* @see Monster.DOM.Resource.Link.Stylesheet * @see Monster.DOM.Resource.Link.Stylesheet
*/ */
addStylesheet(url, options) { addStylesheet(url, options) {
return addResource.call(this, 'stylesheets', url, options); return addResource.call(this, "stylesheets", url, options);
} }
/** /**
...@@ -124,10 +120,8 @@ export {ResourceManager} ...@@ -124,10 +120,8 @@ export {ResourceManager}
* @see Monster.DOM.Resource.Data * @see Monster.DOM.Resource.Data
*/ */
addData(url, options) { addData(url, options) {
return addResource.call(this, 'data', url, options); return addResource.call(this, "data", url, options);
} }
} }
/** /**
...@@ -140,20 +134,19 @@ function runResourceMethod(method) { ...@@ -140,20 +134,19 @@ function runResourceMethod(method) {
const result = []; const result = [];
for (const type of ['scripts', 'stylesheets', 'data']) { for (const type of ["scripts", "stylesheets", "data"]) {
const resources = self.getOption('resources.' + type); const resources = self.getOption(`resources.${type}`);
if (!isArray(resources)) { if (!isArray(resources)) {
continue; continue;
} }
for (const resource of resources) { for (const resource of resources) {
if (!(resource instanceof Resource)) { if (!(resource instanceof Resource)) {
throw new Error('unsupported resource definition') throw new Error("unsupported resource definition");
} }
result.push(resource[method]()); result.push(resource[method]());
} }
} }
return result; return result;
...@@ -174,23 +167,23 @@ function addResource(type, url, options) { ...@@ -174,23 +167,23 @@ function addResource(type, url, options) {
url = url.toString(); url = url.toString();
} }
options = options || {} options = options || {};
let resource; let resource;
switch (type) { switch (type) {
case 'scripts': case "scripts":
resource = new Script(extend({}, options, {[ATTRIBUTE_SRC]: url})) resource = new Script(extend({}, options, { [ATTRIBUTE_SRC]: url }));
break; break;
case 'stylesheets': case "stylesheets":
resource = new Stylesheet(extend({}, options, {[ATTRIBUTE_HREF]: url})) resource = new Stylesheet(extend({}, options, { [ATTRIBUTE_HREF]: url }));
break; break;
case 'data': case "data":
resource = new Data(extend({}, options, {[ATTRIBUTE_SRC]: url})) resource = new Data(extend({}, options, { [ATTRIBUTE_SRC]: url }));
break; break;
default: default:
throw new Error('unsupported type ' + type) throw new Error(`unsupported type ${type}`);
} }
(self.getOption('resources')?.[type]).push(resource); self.getOption("resources")?.[type].push(resource);
return self; return self;
} }
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import {Base} from '../types/base.mjs'; import { Base } from "../types/base.mjs";
import {getGlobalFunction, getGlobalObject} from '../types/global.mjs'; import { getGlobalFunction, getGlobalObject } from "../types/global.mjs";
import { validateInstance, validateString } from "../types/validate.mjs"; import { validateInstance, validateString } from "../types/validate.mjs";
import { ATTRIBUTE_TEMPLATE_PREFIX } from "./constants.mjs"; import { ATTRIBUTE_TEMPLATE_PREFIX } from "./constants.mjs";
import { getDocumentTheme } from "./theme.mjs"; import { getDocumentTheme } from "./theme.mjs";
import {instanceSymbol} from '../constants.mjs'; import { instanceSymbol } from "../constants.mjs";
export {Template} export { Template };
/** /**
* The template class provides methods for creating templates. * The template class provides methods for creating templates.
...@@ -32,7 +32,7 @@ class Template extends Base { ...@@ -32,7 +32,7 @@ class Template extends Base {
*/ */
constructor(template) { constructor(template) {
super(); super();
const HTMLTemplateElement = getGlobalFunction('HTMLTemplateElement'); const HTMLTemplateElement = getGlobalFunction("HTMLTemplateElement");
validateInstance(template, HTMLTemplateElement); validateInstance(template, HTMLTemplateElement);
this.template = template; this.template = template;
} }
...@@ -46,7 +46,6 @@ class Template extends Base { ...@@ -46,7 +46,6 @@ class Template extends Base {
return Symbol.for("@schukai/monster/dom/resource/template"); return Symbol.for("@schukai/monster/dom/resource/template");
} }
/** /**
* *
* @returns {HTMLTemplateElement} * @returns {HTMLTemplateElement}
...@@ -63,7 +62,6 @@ class Template extends Base { ...@@ -63,7 +62,6 @@ class Template extends Base {
createDocumentFragment() { createDocumentFragment() {
return this.template.content.cloneNode(true); return this.template.content.cloneNode(true);
} }
} }
/** /**
...@@ -132,20 +130,17 @@ class Template extends Base { ...@@ -132,20 +130,17 @@ class Template extends Base {
export function findDocumentTemplate(id, currentNode) { export function findDocumentTemplate(id, currentNode) {
validateString(id); validateString(id);
const document = getGlobalObject('document'); const document = getGlobalObject("document");
const HTMLTemplateElement = getGlobalFunction('HTMLTemplateElement'); const HTMLTemplateElement = getGlobalFunction("HTMLTemplateElement");
const DocumentFragment = getGlobalFunction('DocumentFragment'); const DocumentFragment = getGlobalFunction("DocumentFragment");
const Document = getGlobalFunction('Document'); const Document = getGlobalFunction("Document");
let prefixID; let prefixID;
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) { if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
if (currentNode instanceof Node) { if (currentNode instanceof Node) {
if (currentNode.hasAttribute(ATTRIBUTE_TEMPLATE_PREFIX)) { if (currentNode.hasAttribute(ATTRIBUTE_TEMPLATE_PREFIX)) {
prefixID = currentNode.getAttribute(ATTRIBUTE_TEMPLATE_PREFIX) prefixID = currentNode.getAttribute(ATTRIBUTE_TEMPLATE_PREFIX);
} }
currentNode = currentNode.getRootNode(); currentNode = currentNode.getRootNode();
...@@ -153,7 +148,6 @@ export function findDocumentTemplate(id, currentNode) { ...@@ -153,7 +148,6 @@ export function findDocumentTemplate(id, currentNode) {
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) { if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
currentNode = currentNode.ownerDocument; currentNode = currentNode.ownerDocument;
} }
} }
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) { if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
...@@ -162,10 +156,10 @@ export function findDocumentTemplate(id, currentNode) { ...@@ -162,10 +156,10 @@ export function findDocumentTemplate(id, currentNode) {
} }
let template; let template;
let theme = getDocumentTheme() let theme = getDocumentTheme();
if (prefixID) { if (prefixID) {
let themedPrefixID = prefixID + '-' + id + '-' + theme.getName(); let themedPrefixID = `${prefixID}-${id}-${theme.getName()}`;
// current + themedPrefixID // current + themedPrefixID
template = currentNode.getElementById(themedPrefixID); template = currentNode.getElementById(themedPrefixID);
...@@ -180,7 +174,7 @@ export function findDocumentTemplate(id, currentNode) { ...@@ -180,7 +174,7 @@ export function findDocumentTemplate(id, currentNode) {
} }
} }
let themedID = id + '-' + theme.getName(); let themedID = `${id}-${theme.getName()}`;
// current + themedID // current + themedID
template = currentNode.getElementById(themedID); template = currentNode.getElementById(themedID);
...@@ -206,6 +200,5 @@ export function findDocumentTemplate(id, currentNode) { ...@@ -206,6 +200,5 @@ export function findDocumentTemplate(id, currentNode) {
return new Template(template); return new Template(template);
} }
throw new Error("template " + id + " not found.") throw new Error(`template ${id} not found.`);
} }
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import {Base} from '../types/base.mjs'; import { Base } from "../types/base.mjs";
import {getGlobalObject} from '../types/global.mjs'; import { getGlobalObject } from "../types/global.mjs";
import { validateString } from "../types/validate.mjs"; import { validateString } from "../types/validate.mjs";
import { ATTRIBUTE_THEME_NAME, DEFAULT_THEME } from "./constants.mjs"; import { ATTRIBUTE_THEME_NAME, DEFAULT_THEME } from "./constants.mjs";
import {instanceSymbol} from '../constants.mjs'; import { instanceSymbol } from "../constants.mjs";
export {Theme, getDocumentTheme} export { Theme, getDocumentTheme };
/** /**
* The Theme class provides the functionality for the theme. * The Theme class provides the functionality for the theme.
...@@ -23,7 +23,6 @@ export {Theme, getDocumentTheme} ...@@ -23,7 +23,6 @@ export {Theme, getDocumentTheme}
* @summary A theme class * @summary A theme class
*/ */
class Theme extends Base { class Theme extends Base {
/** /**
* *
* @param name * @param name
...@@ -44,7 +43,6 @@ class Theme extends Base { ...@@ -44,7 +43,6 @@ class Theme extends Base {
return Symbol.for("@schukai/monster/dom/theme"); return Symbol.for("@schukai/monster/dom/theme");
} }
/** /**
* *
* @returns {string} * @returns {string}
...@@ -52,7 +50,6 @@ class Theme extends Base { ...@@ -52,7 +50,6 @@ class Theme extends Base {
getName() { getName() {
return this.name; return this.name;
} }
} }
/** /**
...@@ -73,10 +70,10 @@ class Theme extends Base { ...@@ -73,10 +70,10 @@ class Theme extends Base {
* @since 1.7.0 * @since 1.7.0
*/ */
function getDocumentTheme() { function getDocumentTheme() {
let document = getGlobalObject('document'); let document = getGlobalObject("document");
let name = DEFAULT_THEME; let name = DEFAULT_THEME;
let element = document.querySelector('html'); let element = document.querySelector("html");
if (element instanceof HTMLElement) { if (element instanceof HTMLElement) {
let theme = element.getAttribute(ATTRIBUTE_THEME_NAME); let theme = element.getAttribute(ATTRIBUTE_THEME_NAME);
if (theme) { if (theme) {
...@@ -85,5 +82,4 @@ function getDocumentTheme() { ...@@ -85,5 +82,4 @@ function getDocumentTheme() {
} }
return new Theme(name); return new Theme(name);
} }
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import { getGlobal } from "../types/global.mjs"; import { getGlobal } from "../types/global.mjs";
import { validateString } from "../types/validate.mjs"; import { validateString } from "../types/validate.mjs";
export {getDocument, getWindow, getDocumentFragmentFromString} export { getDocument, getWindow, getDocumentFragmentFromString };
/** /**
* This method fetches the document object * This method fetches the document object
...@@ -48,9 +48,9 @@ export {getDocument, getWindow, getDocumentFragmentFromString} ...@@ -48,9 +48,9 @@ export {getDocument, getWindow, getDocumentFragmentFromString}
* @throws {Error} not supported environment * @throws {Error} not supported environment
*/ */
function getDocument() { function getDocument() {
let document = getGlobal()?.['document']; let document = getGlobal()?.["document"];
if (typeof document !== 'object') { if (typeof document !== "object") {
throw new Error("not supported environment") throw new Error("not supported environment");
} }
return document; return document;
...@@ -96,15 +96,14 @@ function getDocument() { ...@@ -96,15 +96,14 @@ function getDocument() {
* @throws {Error} not supported environment * @throws {Error} not supported environment
*/ */
function getWindow() { function getWindow() {
let window = getGlobal()?.['window']; let window = getGlobal()?.["window"];
if (typeof window !== 'object') { if (typeof window !== "object") {
throw new Error("not supported environment") throw new Error("not supported environment");
} }
return window; return window;
} }
/** /**
* This method fetches the document object * This method fetches the document object
* *
...@@ -147,7 +146,7 @@ function getDocumentFragmentFromString(html) { ...@@ -147,7 +146,7 @@ function getDocumentFragmentFromString(html) {
validateString(html); validateString(html);
const document = getDocument(); const document = getDocument();
const template = document.createElement('template'); const template = document.createElement("template");
template.innerHTML = html; template.innerHTML = html;
return template.content; return template.content;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.