@webqit/oohtml 5.0.7 → 5.0.8

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.
@@ -401,7 +401,7 @@ function containsNode(window2, a, b, crossRoots = false, testCache = null) {
401
401
  const rootNodeB = b.getRootNode();
402
402
  if (rootNodeA === rootNodeB)
403
403
  return response(a.contains(b));
404
- if (crossRoots && rootNodeB instanceof window2.ShadowRoot)
404
+ if (crossRoots && isShadowRoot(rootNodeB))
405
405
  return response(containsNode(window2, a, rootNodeB.host, crossRoots, testCache));
406
406
  return response(false);
407
407
  }
@@ -457,7 +457,7 @@ var Realtime = class {
457
457
  } else {
458
458
  args[0] = from_default(args[0], false);
459
459
  }
460
- if (args[0].filter((x) => typeof x !== "string" && !(x instanceof DOMSpec) && !(x instanceof this.window.Node)).length) {
460
+ if (args[0].filter((x) => typeof x !== "string" && !(x instanceof DOMSpec) && !isNode(x)).length) {
461
461
  throw new Error(`Argument #2 must be either a string or a Node object, or a list of those.`);
462
462
  }
463
463
  args[0] = args[0].map((s) => s instanceof DOMSpec ? s : new DOMSpec(s));
@@ -835,10 +835,12 @@ var DOMRealtime = class extends Realtime {
835
835
  dispatch2.call(window2, registration, record, context);
836
836
  }));
837
837
  mo.observe(context, { childList: true, subtree: params.subtree && true });
838
- const disconnectable = { disconnect() {
839
- registry.delete(registration);
840
- mo.disconnect();
841
- } };
838
+ const disconnectable = {
839
+ disconnect() {
840
+ registry.delete(registration);
841
+ mo.disconnect();
842
+ }
843
+ };
842
844
  const signalGenerator = params.signalGenerator || params.lifecycleSignals && this.createSignalGenerator();
843
845
  const registration = { context, spec, callback, params, signalGenerator, disconnectable };
844
846
  const registry = this.registry(interceptionTiming);
@@ -1041,7 +1043,7 @@ function domInterception(timing, callback) {
1041
1043
  _apiOriginals[DOMClassName][apiName] = _apiOriginal;
1042
1044
  });
1043
1045
  function method(...args) {
1044
- const DOMClassName = Object.keys(_apiOriginals).find((name) => this instanceof window2[name] && apiName in _apiOriginals[name]);
1046
+ const DOMClassName = Object.keys(_apiOriginals).find((name) => isNodeInterface(this, name) && apiName in _apiOriginals[name]);
1045
1047
  const $apiOriginals = _apiOriginals[DOMClassName];
1046
1048
  let exec = () => $apiOriginals[apiName].value.call(this, ...args);
1047
1049
  if (webqit.realdom.domInterceptionNoRecurse.get(this) === apiName)
@@ -1100,17 +1102,17 @@ function domInterception(timing, callback) {
1100
1102
  });
1101
1103
  }
1102
1104
  function setter(value) {
1103
- const DOMClassName = Object.keys(_apiOriginals).find((name) => this instanceof window2[name] && apiName in _apiOriginals[name]);
1105
+ const DOMClassName = Object.keys(_apiOriginals).find((name) => isNodeInterface(this, name) && apiName in _apiOriginals[name]);
1104
1106
  const $apiOriginals = _apiOriginals[DOMClassName];
1105
1107
  let exec = () => $apiOriginals[apiName].set.call(this, value);
1106
- if (this instanceof HTMLScriptElement || webqit.realdom.domInterceptionNoRecurse.get(this) === apiName)
1108
+ if (isNodeInterface(this, "HTMLScriptElement") || webqit.realdom.domInterceptionNoRecurse.get(this) === apiName)
1107
1109
  return exec();
1108
1110
  let exits = [], entrants = [], target = this;
1109
1111
  if (["outerHTML", "outerText"].includes(apiName)) {
1110
1112
  exits = [this];
1111
1113
  target = this.parentNode;
1112
1114
  } else {
1113
- if (this instanceof HTMLTemplateElement) {
1115
+ if (isNodeInterface(this, "HTMLTemplateElement")) {
1114
1116
  target = this.content;
1115
1117
  exits = [...this.content.childNodes];
1116
1118
  } else {
@@ -1126,18 +1128,18 @@ function domInterception(timing, callback) {
1126
1128
  }
1127
1129
  const temp = document.createElement(tempNodeName.includes("-") ? "div" : tempNodeName);
1128
1130
  noRecurse(temp, apiName, () => temp[apiName] = value);
1129
- entrants = this instanceof HTMLTemplateElement ? [...temp.content.childNodes] : [...temp.childNodes];
1130
- if (this instanceof HTMLTemplateElement && this.hasAttribute("src") || this instanceof ShadowRoot) {
1131
+ entrants = isNodeInterface(this, "HTMLTemplateElement") ? [...temp.content.childNodes] : [...temp.childNodes];
1132
+ if (isNodeInterface(this, "HTMLTemplateElement") && this.hasAttribute("src") || isShadowRoot(this)) {
1131
1133
  const getScripts = (nodes) => nodes.reduce((scripts, el) => {
1132
- if (el instanceof HTMLScriptElement)
1134
+ if (isNodeInterface(el, "HTMLScriptElement"))
1133
1135
  return scripts.concat(el);
1134
- if (el instanceof HTMLTemplateElement)
1136
+ if (isNodeInterface(el, "HTMLTemplateElement"))
1135
1137
  return scripts.concat(getScripts([el.content]));
1136
1138
  scripts = scripts.concat(getScripts([...el.querySelectorAll?.("template") || []].map((t) => t.content)));
1137
1139
  return scripts.concat(...el.querySelectorAll?.("script") || []);
1138
1140
  }, []);
1139
1141
  for (const script of getScripts(entrants)) {
1140
- if (this instanceof ShadowRoot) {
1142
+ if (isShadowRoot(this)) {
1141
1143
  script.setAttribute("data-handling", "manual");
1142
1144
  continue;
1143
1145
  }
@@ -1152,7 +1154,7 @@ function domInterception(timing, callback) {
1152
1154
  noRecurse(value, "append", () => value.append(...entrants));
1153
1155
  exec = () => noRecurse(this, "replaceWith", () => Element.prototype.replaceWith.call(this, value));
1154
1156
  } else {
1155
- if (this instanceof HTMLTemplateElement) {
1157
+ if (isNodeInterface(this, "HTMLTemplateElement")) {
1156
1158
  exec = () => noRecurse(this.content, "replaceChildren", () => this.content.replaceChildren(...entrants));
1157
1159
  } else {
1158
1160
  exec = () => noRecurse(this, "replaceChildren", () => Element.prototype.replaceChildren.call(this, ...entrants));
@@ -1269,17 +1271,57 @@ function meta(name) {
1269
1271
  if (_el = window2.document.querySelector(`meta[name="${name}"]`)) {
1270
1272
  _content = (_el.content || "").split(";").filter((v) => v).reduce((_metaVars, directive) => {
1271
1273
  const directiveSplit = directive.split("=").map((d) => d.trim());
1272
- set_default(_metaVars, directiveSplit[0].split("."), directiveSplit[1] === "true" ? true : directiveSplit[1] === "false" ? false : isNumeric_default(directiveSplit[1]) ? parseInt(directiveSplit[1]) : directiveSplit[1]);
1274
+ set_default(
1275
+ _metaVars,
1276
+ directiveSplit[0].split("."),
1277
+ directiveSplit[1] === "true" ? true : directiveSplit[1] === "false" ? false : isNumeric_default(directiveSplit[1]) ? parseInt(directiveSplit[1]) : directiveSplit[1]
1278
+ );
1273
1279
  return _metaVars;
1274
1280
  }, {});
1275
1281
  }
1276
- return { get name() {
1277
- return name;
1278
- }, get content() {
1279
- return _el.content;
1280
- }, json() {
1281
- return JSON.parse(JSON.stringify(_content));
1282
- } };
1282
+ return {
1283
+ get name() {
1284
+ return name;
1285
+ },
1286
+ get content() {
1287
+ return _el.content;
1288
+ },
1289
+ json() {
1290
+ return JSON.parse(JSON.stringify(_content));
1291
+ }
1292
+ };
1293
+ }
1294
+ function isNode(value) {
1295
+ return value !== null && typeof value === "object" && typeof value.nodeType === "number" && typeof value.nodeName === "string";
1296
+ }
1297
+ function isElement(value) {
1298
+ return value?.nodeType === 1;
1299
+ }
1300
+ function isShadowRoot(value) {
1301
+ return value?.nodeType === 11 && Object.prototype.toString.call(value) === "[object ShadowRoot]";
1302
+ }
1303
+ function isDocument(value) {
1304
+ return value?.nodeType === 9 && Object.prototype.toString.call(value) === "[object Document]";
1305
+ }
1306
+ function isCharacterData(value) {
1307
+ const toStringValue = Object.prototype.toString.call(value);
1308
+ return toStringValue === "[object Text]" || toStringValue === "[object Comment]" || toStringValue === "[object CDATASection]" || toStringValue === "[object ProcessingInstruction]";
1309
+ }
1310
+ function isNodeInterface(value, interfaceName) {
1311
+ if (!isNode(value))
1312
+ return false;
1313
+ if (interfaceName === "ShadowRoot") {
1314
+ return isShadowRoot(value);
1315
+ HTMLUnknownElement;
1316
+ }
1317
+ const toStringValue = Object.prototype.toString.call(value);
1318
+ if (toStringValue === `[object ${interfaceName}]`)
1319
+ return true;
1320
+ if (interfaceName === "DocumentFragment" && isShadowRoot(value))
1321
+ return true;
1322
+ if (interfaceName === "CharacterData" && isCharacterData(value))
1323
+ return true;
1324
+ return (interfaceName === "Node" || interfaceName === "Element" || interfaceName === "HTMLElement") && isElement(value) || interfaceName === "Node" && isNode(value);
1283
1325
  }
1284
1326
 
1285
1327
  // node_modules/@webqit/util/str/toTitle.js
@@ -1477,7 +1519,7 @@ var _DOMContext = class {
1477
1519
  return configs;
1478
1520
  }
1479
1521
  get name() {
1480
- return [env.window.Document, env.window.ShadowRoot].some((x) => this.host instanceof x) ? Infinity : this.host.getAttribute(this.configs.CONTEXT_API.attr.contextname);
1522
+ return isDocument(this.host) || isShadowRoot(this.host) ? Infinity : this.host.getAttribute(this.configs.CONTEXT_API.attr.contextname);
1481
1523
  }
1482
1524
  subscribed(event) {
1483
1525
  }
@@ -1603,7 +1645,7 @@ function getBindings(config, node) {
1603
1645
  const bindingsObj = /* @__PURE__ */ Object.create(null);
1604
1646
  _wq(node).set("bindings", bindingsObj);
1605
1647
  Observer.observe(bindingsObj, (mutations) => {
1606
- if (node instanceof window2.Element) {
1648
+ if (isElement(node)) {
1607
1649
  const bindingsParse = parseBindingsAttr(node.getAttribute(config.attr.bindingsreflection) || "");
1608
1650
  const bindingsParseBefore = new Map(bindingsParse);
1609
1651
  for (const m of mutations) {
@@ -1644,12 +1686,16 @@ function exposeAPIs(config) {
1644
1686
  if (config.api.bindings in prototype) {
1645
1687
  throw new Error(`The ${type} prototype already has a "${config.api.bindings}" API!`);
1646
1688
  }
1647
- Object.defineProperty(prototype, config.api.bind, { value: function(bindings, options = {}) {
1648
- return applyBindings.call(window2, config, this, bindings, options);
1649
- } });
1650
- Object.defineProperty(prototype, config.api.bindings, { get: function() {
1651
- return Observer.proxy(getBindings.call(window2, config, this));
1652
- } });
1689
+ Object.defineProperty(prototype, config.api.bind, {
1690
+ value: function(bindings, options = {}) {
1691
+ return applyBindings.call(window2, config, this, bindings, options);
1692
+ }
1693
+ });
1694
+ Object.defineProperty(prototype, config.api.bindings, {
1695
+ get: function() {
1696
+ return Observer.proxy(getBindings.call(window2, config, this));
1697
+ }
1698
+ });
1653
1699
  });
1654
1700
  }
1655
1701
  function applyBindings(config, target, bindings, { merge, diff, publish, namespace } = {}) {