@abide/harness 0.4.1 → 0.4.2

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": "@abide/harness",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Ratios against hand-written code, counts of the work an op did, and gates whose revert can be run — three measurement lanes for anything that renders, on bun",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@playwright/test": "^1.64.0",
60
- "@abide/abide": ">=0.127.0"
60
+ "@abide/abide": ">=0.130.0"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@playwright/test": {
@@ -0,0 +1,49 @@
1
+ // 43.36 — happy-dom gives an element its `popover` attribute and none of the methods that open one,
2
+ // and its selector engine matches no `:popover-open`. These are the methods, holding the open state
3
+ // beside the element, and `matches(':popover-open')` reading it — the selector a component asks
4
+ // whether its popover is showing with. A selector that only CONTAINS `:popover-open` still goes to
5
+ // happy-dom and matches nothing. `toggle` fires synchronously where a browser queues it, so a test
6
+ // sees it without waiting a task. Nothing here lays a popover out in a top layer.
7
+
8
+ export function installPopover(): void {
9
+ const prototype = HTMLElement.prototype
10
+ if (typeof prototype.showPopover === 'function') return
11
+ const open = new WeakSet<Element>()
12
+ const flip = (element: HTMLElement, opening: boolean): void => {
13
+ if (!element.hasAttribute('popover')) {
14
+ throw new DOMException(
15
+ 'Not supported on elements that do not have a valid value for the popover attribute',
16
+ 'NotSupportedError',
17
+ )
18
+ }
19
+ if (open.has(element) === opening) return
20
+ if (opening) open.add(element)
21
+ else open.delete(element)
22
+ const toggle = new Event('toggle')
23
+ Object.assign(toggle, {
24
+ oldState: opening ? 'closed' : 'open',
25
+ newState: opening ? 'open' : 'closed',
26
+ })
27
+ element.dispatchEvent(toggle)
28
+ }
29
+ prototype.showPopover = function (this: HTMLElement) {
30
+ flip(this, true)
31
+ }
32
+ prototype.hidePopover = function (this: HTMLElement) {
33
+ flip(this, false)
34
+ }
35
+ prototype.togglePopover = function (
36
+ this: HTMLElement,
37
+ force?: boolean | object,
38
+ ) {
39
+ const opening = typeof force === 'boolean' ? force : !open.has(this)
40
+ flip(this, opening)
41
+ return opening
42
+ }
43
+ const matches = Element.prototype.matches
44
+ Element.prototype.matches = function (this: Element, selector: string) {
45
+ return selector.trim() === ':popover-open'
46
+ ? open.has(this)
47
+ : matches.call(this, selector)
48
+ } as Element['matches']
49
+ }
@@ -4,6 +4,7 @@
4
4
  import { GlobalRegistrator } from '@happy-dom/global-registrator'
5
5
 
6
6
  import { install } from './install.ts'
7
+ import { installPopover } from './installPopover.ts'
7
8
 
8
9
  // A child spawned with this env would paint its output in ANSI off a pipe (bun's console, and
9
10
  // abide's own log under RULEBOOK 36.9), and the suites compare that output as text. A terminal
@@ -42,3 +43,4 @@ GlobalRegistrator.register({
42
43
  })
43
44
  for (const name of WIRE) Object.assign(globalThis, { [name]: native[name] })
44
45
  install()
46
+ installPopover()