@stencil/mock-doc 5.0.0-alpha.33 → 5.0.0-alpha.35

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.d.mts CHANGED
@@ -139,6 +139,7 @@ declare class MockLocation implements Location {
139
139
  private _href;
140
140
  get href(): string;
141
141
  set href(value: string);
142
+ constructor();
142
143
  assign(_url: string): void;
143
144
  reload(_forcedReload?: boolean): void;
144
145
  replace(_url: string): void;
@@ -245,7 +246,7 @@ declare class MockWindow {
245
246
  KeyboardEvent: typeof MockKeyboardEvent;
246
247
  MouseEvent: typeof MockMouseEvent;
247
248
  constructor(html?: string | boolean);
248
- addEventListener(type: string, handler: (ev?: any) => void): void;
249
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
249
250
  alert(msg: string): void;
250
251
  blur(): any;
251
252
  cancelAnimationFrame(id: any): void;
@@ -332,7 +333,7 @@ declare class MockWindow {
332
333
  prompt(): string;
333
334
  open(): any;
334
335
  get origin(): string;
335
- removeEventListener(type: string, handler: any): void;
336
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
336
337
  requestAnimationFrame(callback: (timestamp: number) => void): number;
337
338
  requestIdleCallback(callback: (deadline: {
338
339
  didTimeout: boolean;
@@ -512,7 +513,9 @@ declare class MockFocusEvent extends MockUIEvent {
512
513
  declare class MockEventListener {
513
514
  type: string;
514
515
  handler: (ev?: any) => void;
515
- constructor(type: string, handler: any);
516
+ capture: boolean;
517
+ once: boolean;
518
+ constructor(type: string, handler: any, options?: boolean | AddEventListenerOptions);
516
519
  }
517
520
  interface EventTarget {
518
521
  __listeners: MockEventListener[];
@@ -603,8 +606,8 @@ declare class MockNode {
603
606
  replaceChild(newChild: MockNode, oldChild: MockNode): MockNode;
604
607
  get textContent(): string;
605
608
  set textContent(value: string);
606
- addEventListener(type: string, handler: (ev?: any) => void): void;
607
- removeEventListener(type: string, handler: any): void;
609
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
610
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
608
611
  dispatchEvent(ev: MockEvent): boolean;
609
612
  static ELEMENT_NODE: number;
610
613
  static TEXT_NODE: number;
@@ -623,7 +626,7 @@ declare class MockElement extends MockNode {
623
626
  __style: MockCSSStyleDeclaration | null | undefined;
624
627
  attachInternals(): MockElementInternals;
625
628
  constructor(ownerDocument: any, nodeName: string | null, namespaceURI?: string | null);
626
- addEventListener(type: string, handler: (ev?: any) => void): void;
629
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
627
630
  attachShadow(_opts: ShadowRootInit): any;
628
631
  blur(): void;
629
632
  get localName(): string;
@@ -707,7 +710,7 @@ declare class MockElement extends MockNode {
707
710
  querySelectorAll<E extends Element = Element>(selectors: string): E[];
708
711
  removeAttribute(attrName: string): void;
709
712
  removeAttributeNS(namespaceURI: string | null, attrName: string): void;
710
- removeEventListener(type: string, handler: any): void;
713
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
711
714
  setAttribute(attrName: string, value: any): void;
712
715
  setAttributeNS(namespaceURI: string | null, attrName: string, value: any): void;
713
716
  get style(): any;
@@ -871,6 +874,7 @@ interface NwsapiInstance {
871
874
  configure(config: {
872
875
  LOGERRORS?: boolean;
873
876
  VERBOSITY?: boolean;
877
+ IDS_DUPES?: boolean;
874
878
  }): void;
875
879
  match(selector: string, element: unknown): boolean;
876
880
  first(selector: string, context: unknown): unknown | null;
package/dist/index.mjs CHANGED
@@ -361,12 +361,12 @@ function createCustomElement(customElements, ownerDocument, tagName) {
361
361
  const host = new Proxy({}, {
362
362
  get(obj, prop) {
363
363
  const elm = proxyElements.get(host);
364
- if (elm != null) return elm[prop];
364
+ if (elm != null) return Reflect.get(elm, prop, host);
365
365
  return obj[prop];
366
366
  },
367
367
  set(obj, prop, val) {
368
368
  const elm = proxyElements.get(host);
369
- if (elm != null) elm[prop] = val;
369
+ if (elm != null) Reflect.set(elm, prop, val, host);
370
370
  else obj[prop] = val;
371
371
  return true;
372
372
  },
@@ -374,6 +374,26 @@ function createCustomElement(customElements, ownerDocument, tagName) {
374
374
  if (prop in proxyElements.get(host)) return true;
375
375
  if (prop in obj) return true;
376
376
  return false;
377
+ },
378
+ defineProperty(obj, prop, descriptor) {
379
+ const elm = proxyElements.get(host);
380
+ return Reflect.defineProperty(elm != null ? elm : obj, prop, descriptor);
381
+ },
382
+ deleteProperty(obj, prop) {
383
+ const elm = proxyElements.get(host);
384
+ return Reflect.deleteProperty(elm != null ? elm : obj, prop);
385
+ },
386
+ getOwnPropertyDescriptor(obj, prop) {
387
+ const elm = proxyElements.get(host);
388
+ return Reflect.getOwnPropertyDescriptor(elm != null ? elm : obj, prop);
389
+ },
390
+ ownKeys(obj) {
391
+ const elm = proxyElements.get(host);
392
+ return Reflect.ownKeys(elm != null ? elm : obj);
393
+ },
394
+ getPrototypeOf(obj) {
395
+ const elm = proxyElements.get(host);
396
+ return Reflect.getPrototypeOf(elm != null ? elm : obj);
377
397
  }
378
398
  });
379
399
  const elm = new MockHTMLElement(ownerDocument, tagName);
@@ -574,9 +594,18 @@ var MockFocusEvent = class extends MockUIEvent {
574
594
  var MockEventListener = class {
575
595
  type;
576
596
  handler;
577
- constructor(type, handler) {
597
+ capture;
598
+ once;
599
+ constructor(type, handler, options) {
578
600
  this.type = type;
579
601
  this.handler = handler;
602
+ if (typeof options === "boolean") {
603
+ this.capture = options;
604
+ this.once = false;
605
+ } else {
606
+ this.capture = options?.capture ?? false;
607
+ this.once = options?.once ?? false;
608
+ }
580
609
  }
581
610
  };
582
611
  /**
@@ -585,11 +614,12 @@ var MockEventListener = class {
585
614
  * @param elm - the element to add the listener to
586
615
  * @param type - the event type to listen for
587
616
  * @param handler - the event handler function
617
+ * @param options - `capture` and `once` are supported; `passive` and `signal` are accepted but not implemented
588
618
  */
589
- function addEventListener(elm, type, handler) {
619
+ function addEventListener(elm, type, handler, options) {
590
620
  const target = elm;
591
621
  if (target.__listeners == null) target.__listeners = [];
592
- target.__listeners.push(new MockEventListener(type, handler));
622
+ target.__listeners.push(new MockEventListener(type, handler, options));
593
623
  }
594
624
  /**
595
625
  * Remove an event listener from an element.
@@ -597,11 +627,13 @@ function addEventListener(elm, type, handler) {
597
627
  * @param elm - the element to remove the listener from
598
628
  * @param type - the event type to remove
599
629
  * @param handler - the event handler function to remove
630
+ * @param options - only `capture` is relevant here, since listeners are keyed by type + handler + capture
600
631
  */
601
- function removeEventListener(elm, type, handler) {
632
+ function removeEventListener(elm, type, handler, options) {
602
633
  const target = elm;
634
+ const capture = typeof options === "boolean" ? options : options?.capture ?? false;
603
635
  if (target != null && Array.isArray(target.__listeners) === true) {
604
- const elmListener = target.__listeners.find((e) => e.type === type && e.handler === handler);
636
+ const elmListener = target.__listeners.find((e) => e.type === type && e.handler === handler && e.capture === capture);
605
637
  if (elmListener != null) {
606
638
  const index = target.__listeners.indexOf(elmListener);
607
639
  target.__listeners.splice(index, 1);
@@ -627,6 +659,7 @@ function triggerEventListener(elm, ev) {
627
659
  const target = elm;
628
660
  ev.currentTarget = elm;
629
661
  if (Array.isArray(target.__listeners) === true) target.__listeners.filter((e) => e.type === ev.type).forEach((listener) => {
662
+ if (listener.once) removeEventListener(target, listener.type, listener.handler, { capture: listener.capture });
630
663
  try {
631
664
  listener.handler.call(target, ev);
632
665
  } catch (err) {
@@ -1430,8 +1463,9 @@ var MockNode = class {
1430
1463
  }
1431
1464
  get nextSibling() {
1432
1465
  if (this.parentNode != null) {
1433
- const index = this.parentNode.childNodes.indexOf(this) + 1;
1434
- return this.parentNode.childNodes[index] || null;
1466
+ const selfIndex = this.parentNode.childNodes.indexOf(this);
1467
+ if (selfIndex === -1) return null;
1468
+ return this.parentNode.childNodes[selfIndex + 1] || null;
1435
1469
  }
1436
1470
  return null;
1437
1471
  }
@@ -1492,11 +1526,11 @@ var MockNode = class {
1492
1526
  set textContent(value) {
1493
1527
  this._nodeValue = String(value);
1494
1528
  }
1495
- addEventListener(type, handler) {
1496
- addEventListener(this, type, handler);
1529
+ addEventListener(type, handler, options) {
1530
+ addEventListener(this, type, handler, options);
1497
1531
  }
1498
- removeEventListener(type, handler) {
1499
- removeEventListener(this, type, handler);
1532
+ removeEventListener(type, handler, options) {
1533
+ removeEventListener(this, type, handler, options);
1500
1534
  }
1501
1535
  dispatchEvent(ev) {
1502
1536
  return dispatchEvent(this, ev);
@@ -1541,8 +1575,8 @@ var MockElement = class extends MockNode {
1541
1575
  this.__shadowRoot = null;
1542
1576
  this.__attributeMap = null;
1543
1577
  }
1544
- addEventListener(type, handler) {
1545
- addEventListener(this, type, handler);
1578
+ addEventListener(type, handler, options) {
1579
+ addEventListener(this, type, handler, options);
1546
1580
  }
1547
1581
  attachShadow(_opts) {
1548
1582
  const shadowRoot = this.ownerDocument.createDocumentFragment();
@@ -1809,8 +1843,9 @@ var MockElement = class extends MockNode {
1809
1843
  get nextElementSibling() {
1810
1844
  const parentElement = this.parentElement;
1811
1845
  if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
1812
- const index = parentElement.children.indexOf(this) + 1;
1813
- return parentElement.children[index] || null;
1846
+ const selfIndex = parentElement.children.indexOf(this);
1847
+ if (selfIndex === -1) return null;
1848
+ return parentElement.children[selfIndex + 1] || null;
1814
1849
  }
1815
1850
  return null;
1816
1851
  }
@@ -1824,8 +1859,9 @@ var MockElement = class extends MockNode {
1824
1859
  get previousElementSibling() {
1825
1860
  const parentElement = this.parentElement;
1826
1861
  if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
1827
- const index = parentElement.children.indexOf(this) - 1;
1828
- return parentElement.children[index] || null;
1862
+ const selfIndex = parentElement.children.indexOf(this);
1863
+ if (selfIndex === -1) return null;
1864
+ return parentElement.children[selfIndex - 1] || null;
1829
1865
  }
1830
1866
  return null;
1831
1867
  }
@@ -1863,8 +1899,8 @@ var MockElement = class extends MockNode {
1863
1899
  if (checkAttributeChanged(this) === true) attributeChanged(this, attrName, attr.value, null);
1864
1900
  }
1865
1901
  }
1866
- removeEventListener(type, handler) {
1867
- removeEventListener(this, type, handler);
1902
+ removeEventListener(type, handler, options) {
1903
+ removeEventListener(this, type, handler, options);
1868
1904
  }
1869
1905
  setAttribute(attrName, value) {
1870
1906
  if (attrName === "style") this.style = value;
@@ -4554,6 +4590,7 @@ var MockIntersectionObserver = class {
4554
4590
  };
4555
4591
  //#endregion
4556
4592
  //#region src/location.ts
4593
+ const DEFAULT_LOCATION_HREF = "http://localhost/";
4557
4594
  var MockLocation = class {
4558
4595
  ancestorOrigins = null;
4559
4596
  protocol = "";
@@ -4584,6 +4621,9 @@ var MockLocation = class {
4584
4621
  this.password = url.password;
4585
4622
  this.origin = url.origin;
4586
4623
  }
4624
+ constructor() {
4625
+ this.href = DEFAULT_LOCATION_HREF;
4626
+ }
4587
4627
  assign(_url) {}
4588
4628
  reload(_forcedReload) {}
4589
4629
  replace(_url) {}
@@ -4797,8 +4837,8 @@ var MockWindow = class {
4797
4837
  resetWindowDefaults(this);
4798
4838
  resetWindowDimensions(this);
4799
4839
  }
4800
- addEventListener(type, handler) {
4801
- addEventListener(this, type, handler);
4840
+ addEventListener(type, handler, options) {
4841
+ addEventListener(this, type, handler, options);
4802
4842
  }
4803
4843
  alert(msg) {
4804
4844
  if (this.console) this.console.debug(msg);
@@ -5020,8 +5060,8 @@ var MockWindow = class {
5020
5060
  get origin() {
5021
5061
  return this.location.origin;
5022
5062
  }
5023
- removeEventListener(type, handler) {
5024
- removeEventListener(this, type, handler);
5063
+ removeEventListener(type, handler, options) {
5064
+ removeEventListener(this, type, handler, options);
5025
5065
  }
5026
5066
  requestAnimationFrame(callback) {
5027
5067
  return this.setTimeout(() => {
@@ -5337,7 +5377,8 @@ var MockDocument = class MockDocument extends MockHTMLElement {
5337
5377
  this.#nwsapi = (0, import_nwsapi.default)({ document: this });
5338
5378
  this.#nwsapi.configure({
5339
5379
  LOGERRORS: false,
5340
- VERBOSITY: false
5380
+ VERBOSITY: false,
5381
+ IDS_DUPES: false
5341
5382
  });
5342
5383
  }
5343
5384
  return this.#nwsapi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/mock-doc",
3
- "version": "5.0.0-alpha.33",
3
+ "version": "5.0.0-alpha.35",
4
4
  "description": "A minimal mock DOM implementation for SSR and testing",
5
5
  "keywords": [
6
6
  "dom",