mount-observer 0.0.99 → 0.0.101

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.99",
3
+ "version": "0.0.101",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/refid/genIds.js CHANGED
@@ -20,7 +20,10 @@ export function genIds(enhancedElement) {
20
20
  // if(parentElement === null) throw 404;
21
21
  const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode());
22
22
  //first find all elements with attribute #
23
- const hashIds = Array.from(scopeFragment.querySelectorAll('[\\#]')).filter(x => inScope(scopeFragment, x));
23
+ const hashTest = '[\\#]';
24
+ const hashIds = Array.from(scopeFragment.querySelectorAll(hashTest)).filter(x => inScope(scopeFragment, x));
25
+ if (scopeFragment instanceof Element && scopeFragment.matches(hashTest))
26
+ hashIds.push(scopeFragment);
24
27
  const uniqueCheck = new Set();
25
28
  for (const hi of hashIds) {
26
29
  if (!(hi instanceof HTMLElement))
@@ -38,7 +41,10 @@ export function genIds(enhancedElement) {
38
41
  hi.removeAttribute('#');
39
42
  }
40
43
  //now find all elements with attribute @
41
- const names = Array.from(scopeFragment.querySelectorAll('[name]:not([name=""])[\\@]')).filter(x => inScope(scopeFragment, x));
44
+ const nameTest = '[name]:not([name=""])[\\@]';
45
+ const names = Array.from(scopeFragment.querySelectorAll(nameTest)).filter(x => inScope(scopeFragment, x));
46
+ if (scopeFragment instanceof Element && scopeFragment.matches(nameTest))
47
+ names.push(scopeFragment);
42
48
  for (const nameEl of names) {
43
49
  if (!(nameEl instanceof HTMLElement))
44
50
  continue;
@@ -55,7 +61,10 @@ export function genIds(enhancedElement) {
55
61
  nameEl.removeAttribute('@');
56
62
  }
57
63
  //now find all elements with attribute |
58
- const itemprops = Array.from(scopeFragment.querySelectorAll('[itemprop]:not([itemprop=""])[\\|]')).filter(x => inScope(scopeFragment, x));
64
+ const itemScopeTest = '[itemprop]:not([itemprop=""])[\\|]';
65
+ const itemprops = Array.from(scopeFragment.querySelectorAll(itemScopeTest)).filter(x => inScope(scopeFragment, x));
66
+ if (scopeFragment instanceof Element && scopeFragment.matches(itemScopeTest))
67
+ itemprops.push(scopeFragment);
59
68
  for (const itempropEl of itemprops) {
60
69
  if (!(itempropEl instanceof HTMLElement))
61
70
  continue;
@@ -71,7 +80,10 @@ export function genIds(enhancedElement) {
71
80
  itempropEl.dataset.id = `{{${sideEffects}${val}}}`;
72
81
  itempropEl.removeAttribute('|');
73
82
  }
74
- const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
83
+ const dataIdTest = '[data-id^="{{"][data-id$="}}"]';
84
+ const dataIds = Array.from(scopeFragment.querySelectorAll(dataIdTest)).filter(x => inScope(scopeFragment, x));
85
+ if (scopeFragment instanceof Element && scopeFragment.matches(dataIdTest))
86
+ dataIds.push(scopeFragment);
75
87
  const ids = [];
76
88
  for (const di of dataIds) {
77
89
  if (!(di instanceof HTMLElement))
package/refid/genIds.ts CHANGED
@@ -22,7 +22,9 @@ export function genIds(enhancedElement: Element){
22
22
  const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode()) as DocumentFragment | Element;
23
23
 
24
24
  //first find all elements with attribute #
25
- const hashIds = Array.from(scopeFragment.querySelectorAll('[\\#]')).filter(x => inScope(scopeFragment, x));
25
+ const hashTest = '[\\#]';
26
+ const hashIds = Array.from(scopeFragment.querySelectorAll(hashTest)).filter(x => inScope(scopeFragment, x));
27
+ if(scopeFragment instanceof Element && scopeFragment.matches(hashTest)) hashIds.push(scopeFragment);
26
28
  const uniqueCheck = new Set();
27
29
  for(const hi of hashIds){
28
30
  if(!(hi instanceof HTMLElement)) continue;
@@ -39,7 +41,9 @@ export function genIds(enhancedElement: Element){
39
41
  }
40
42
 
41
43
  //now find all elements with attribute @
42
- const names = Array.from(scopeFragment.querySelectorAll('[name]:not([name=""])[\\@]')).filter(x => inScope(scopeFragment, x));
44
+ const nameTest = '[name]:not([name=""])[\\@]';
45
+ const names = Array.from(scopeFragment.querySelectorAll(nameTest)).filter(x => inScope(scopeFragment, x));
46
+ if(scopeFragment instanceof Element && scopeFragment.matches(nameTest)) names.push(scopeFragment);
43
47
  for(const nameEl of names){
44
48
  if(!(nameEl instanceof HTMLElement)) continue;
45
49
  const val = nameEl.getAttribute('name');
@@ -55,7 +59,9 @@ export function genIds(enhancedElement: Element){
55
59
  }
56
60
 
57
61
  //now find all elements with attribute |
58
- const itemprops = Array.from(scopeFragment.querySelectorAll('[itemprop]:not([itemprop=""])[\\|]')).filter(x => inScope(scopeFragment, x));
62
+ const itemScopeTest = '[itemprop]:not([itemprop=""])[\\|]';
63
+ const itemprops = Array.from(scopeFragment.querySelectorAll(itemScopeTest)).filter(x => inScope(scopeFragment, x));
64
+ if(scopeFragment instanceof Element && scopeFragment.matches(itemScopeTest)) itemprops.push(scopeFragment);
59
65
  for(const itempropEl of itemprops){
60
66
  if(!(itempropEl instanceof HTMLElement)) continue;
61
67
  const val = itempropEl.getAttribute('itemprop');
@@ -69,8 +75,9 @@ export function genIds(enhancedElement: Element){
69
75
  itempropEl.dataset.id = `{{${sideEffects}${val}}}`;
70
76
  itempropEl.removeAttribute('|');
71
77
  }
72
-
73
- const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
78
+ const dataIdTest = '[data-id^="{{"][data-id$="}}"]';
79
+ const dataIds = Array.from(scopeFragment.querySelectorAll(dataIdTest)).filter(x => inScope(scopeFragment, x));
80
+ if(scopeFragment instanceof Element && scopeFragment.matches(dataIdTest)) dataIds.push(scopeFragment);
74
81
  const ids: Array<string> = [];
75
82
  for(const di of dataIds){
76
83
  if(!(di instanceof HTMLElement)) continue;
@@ -83,6 +90,7 @@ export function genIds(enhancedElement: Element){
83
90
  ids.push(id);
84
91
  }
85
92
  if(ids.length === 0) return;
93
+
86
94
  const allChildren = Array.from(scopeFragment.querySelectorAll('*')).filter(x => inScope(scopeFragment, x));
87
95
  if(scopeFragment instanceof Element) allChildren.push(scopeFragment);
88
96
 
@@ -43,6 +43,7 @@ export interface Specifier {
43
43
  ish?: boolean;
44
44
  //element to observe must be a shadowed custom element host.
45
45
  host?: boolean;
46
+ self?: boolean;
46
47
  }
47
48
 
48
49
 
package/waitForIsh.js CHANGED
@@ -2,7 +2,7 @@ export function waitForIsh(el) {
2
2
  return new Promise((resolve, reject) => {
3
3
  const ish = el['ish']; // [TODO] should we make this something that can
4
4
  // be passed in, more generic function -- waitForProperty?
5
- if (ish instanceof EventTarget) {
5
+ if (ish.constructor !== Object) {
6
6
  resolve(ish);
7
7
  }
8
8
  else {
package/waitForIsh.ts CHANGED
@@ -2,7 +2,7 @@ export function waitForIsh(el: Element) : Promise<any> {
2
2
  return new Promise((resolve, reject) => {
3
3
  const ish = (<any>el)['ish']; // [TODO] should we make this something that can
4
4
  // be passed in, more generic function -- waitForProperty?
5
- if (ish instanceof EventTarget) {
5
+ if (ish.constructor !== Object) {
6
6
  resolve(ish);
7
7
  } else {
8
8
  // If the element is not yet defined, wait for it to be defined