very-happy-dom 0.1.11 → 0.2.0
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/CHANGELOG.md +33 -0
- package/README.md +35 -0
- package/dist/aria/visibility.d.ts +33 -0
- package/dist/browser/Locator.d.ts +41 -9
- package/dist/browser/waiting.d.ts +57 -0
- package/dist/{chunk-7p32fjmd.js → chunk-182syxjh.js} +1 -1
- package/dist/chunk-3d9kwyx0.js +3 -0
- package/dist/{chunk-92x5ndzm.js → chunk-76fz7rx8.js} +2 -2
- package/dist/chunk-7c8vh5me.js +11 -0
- package/dist/{chunk-qtt1xmnv.js → chunk-7yd4gnqy.js} +2 -2
- package/dist/chunk-a7z9k802.js +2 -0
- package/dist/{chunk-va7sjb9f.js → chunk-c195vfyf.js} +2 -2
- package/dist/chunk-ew1knb9c.js +2 -0
- package/dist/chunk-gkeyaw9g.js +2 -0
- package/dist/{chunk-dezhaygj.js → chunk-h2qtm7yn.js} +2 -2
- package/dist/{chunk-4tbk0vce.js → chunk-httdr8re.js} +2 -2
- package/dist/{chunk-m1aq1c2f.js → chunk-j2wys65b.js} +1 -1
- package/dist/{chunk-ycyna330.js → chunk-jk62hdff.js} +2 -2
- package/dist/chunk-ptess7d1.js +3 -0
- package/dist/chunk-qkxcr7jt.js +2 -0
- package/dist/chunk-rr2grqs5.js +2 -0
- package/dist/chunk-t7xttfys.js +2 -0
- package/dist/chunk-vxcq2fte.js +10 -0
- package/dist/chunk-wktrnbx6.js +2 -0
- package/dist/chunk-yqxxa2ez.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -12
- package/dist/jsdom/index.js +1 -1
- package/dist/matchers.d.ts +147 -0
- package/dist/matchers.js +3 -0
- package/dist/register.js +1 -1
- package/package.json +10 -6
- package/dist/chunk-1jpw1e24.js +0 -10
- package/dist/chunk-79rzqkbn.js +0 -2
- package/dist/chunk-c7rwegdn.js +0 -2
- package/dist/chunk-cb96nefp.js +0 -2
- package/dist/chunk-e6nqch55.js +0 -2
- package/dist/chunk-hm6bwjwc.js +0 -2
- package/dist/chunk-j9vry05w.js +0 -11
- package/dist/chunk-kcmqqh5e.js +0 -3
- package/dist/chunk-qvrtvjqf.js +0 -2
- package/dist/chunk-s3kg89em.js +0 -2
- package/dist/chunk-yvy9t0as.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
[Compare changes](https://github.com/stacksjs/very-happy-dom/compare/v0.1.12...HEAD)
|
|
2
|
+
|
|
3
|
+
## 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **matchers**: add web-first assertions through expect.extend ([1f34e25](https://github.com/stacksjs/very-happy-dom/commit/1f34e25)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1603](https://github.com/stacksjs/very-happy-dom/issues/1603))
|
|
6
|
+
- **locator**: auto-wait for actionability, and add locator.waitFor() ([ac1eba9](https://github.com/stacksjs/very-happy-dom/commit/ac1eba9)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1604](https://github.com/stacksjs/very-happy-dom/issues/1604), [#1605](https://github.com/stacksjs/very-happy-dom/issues/1605))
|
|
7
|
+
|
|
8
|
+
## Contributors
|
|
9
|
+
|
|
10
|
+
- _glennmichael123 <gtorregosa@gmail.com>_
|
|
11
|
+
|
|
12
|
+
[Compare changes](https://github.com/stacksjs/very-happy-dom/compare/v0.1.11...HEAD)
|
|
13
|
+
|
|
14
|
+
## 🐛 Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **browser**: make the console, response and error page events fire ([029bb19](https://github.com/stacksjs/very-happy-dom/commit/029bb19)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1602](https://github.com/stacksjs/very-happy-dom/issues/1602))
|
|
17
|
+
- **locator**: skip hidden elements in getBy* queries ([56dab61](https://github.com/stacksjs/very-happy-dom/commit/56dab61)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1601](https://github.com/stacksjs/very-happy-dom/issues/1601), [#1600](https://github.com/stacksjs/very-happy-dom/issues/1600))
|
|
18
|
+
- **dom**: resolve box metrics through the cascade ([4060bad](https://github.com/stacksjs/very-happy-dom/commit/4060bad)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1600](https://github.com/stacksjs/very-happy-dom/issues/1600))
|
|
19
|
+
|
|
20
|
+
## 🧪 Tests
|
|
21
|
+
|
|
22
|
+
- **package**: assert the packed tarball carries every export ([9cbcf24](https://github.com/stacksjs/very-happy-dom/commit/9cbcf24)) _(by glennmichael123 <gtorregosa@gmail.com>)_ ([#1598](https://github.com/stacksjs/very-happy-dom/issues/1598))
|
|
23
|
+
|
|
24
|
+
## 🧹 Chores
|
|
25
|
+
|
|
26
|
+
- run bun-git-hooks and @stacksjs/logsmith, not the unrelated npm 'git-hooks' and 'logsmith' ([4402f91](https://github.com/stacksjs/very-happy-dom/commit/4402f91)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
27
|
+
- release through @stacksjs/bumpx, not the unrelated npm 'bumpx' ([9a43a7d](https://github.com/stacksjs/very-happy-dom/commit/9a43a7d)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
28
|
+
|
|
29
|
+
## Contributors
|
|
30
|
+
|
|
31
|
+
- _Chris <chrisbreuer93@gmail.com>_
|
|
32
|
+
- _glennmichael123 <gtorregosa@gmail.com>_
|
|
33
|
+
|
|
1
34
|
[Compare changes](https://github.com/stacksjs/very-happy-dom/compare/v0.1.10...HEAD)
|
|
2
35
|
|
|
3
36
|
## 🚀 Features
|
package/README.md
CHANGED
|
@@ -123,6 +123,41 @@ GlobalRegistrator.register()
|
|
|
123
123
|
|
|
124
124
|
## Advanced Usage
|
|
125
125
|
|
|
126
|
+
### Web-First Assertions
|
|
127
|
+
|
|
128
|
+
Importing `very-happy-dom/matchers` registers Playwright-style matchers into
|
|
129
|
+
`bun:test`. They retry until the expectation holds or the timeout expires, which
|
|
130
|
+
is the difference that matters:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { expect, test } from 'bun:test'
|
|
134
|
+
import { Browser } from 'very-happy-dom'
|
|
135
|
+
import 'very-happy-dom/matchers'
|
|
136
|
+
|
|
137
|
+
test('the alert reports the save', async () => {
|
|
138
|
+
const page = new Browser().newPage()
|
|
139
|
+
|
|
140
|
+
await expect(page.getByRole('alert')).toContainText('Saved')
|
|
141
|
+
})
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The one-shot rewrite — `expect(await page.getByRole('alert').textContent()).toContain('Saved')`
|
|
145
|
+
— samples once, so anything that appears after a `fetch` settles or a microtask
|
|
146
|
+
drains is a race. `.not` waits for the opposite to become true rather than
|
|
147
|
+
inverting a single sample.
|
|
148
|
+
|
|
149
|
+
Locators: `toBeAttached`, `toBeVisible`, `toBeHidden`, `toHaveCount`,
|
|
150
|
+
`toHaveText`, `toContainText`, `toHaveValue`, `toHaveAttribute`, `toHaveClass`,
|
|
151
|
+
`toBeEnabled`, `toBeDisabled`, `toBeChecked`, `toBeEditable`, `toBeFocused`,
|
|
152
|
+
`toBeEmpty`. Pages: `toHaveURL`, `toHaveTitle`. Each takes an optional
|
|
153
|
+
`{ timeout }`, defaulting to `page.setDefaultTimeout()`.
|
|
154
|
+
|
|
155
|
+
Locator actions auto-wait on the same terms — present, rendered and not
|
|
156
|
+
disabled — and `locator.waitFor({ state })` covers `attached`, `detached`,
|
|
157
|
+
`visible` and `hidden`. Two conditions Playwright checks are not checked here:
|
|
158
|
+
stable (not mid-animation) and receives-events (not covered by another element).
|
|
159
|
+
Both need a layout pass.
|
|
160
|
+
|
|
126
161
|
### Browser Context
|
|
127
162
|
|
|
128
163
|
```typescript
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the element is painted: nothing in its ancestor chain hides it with
|
|
3
|
+
* `display: none`, `visibility: hidden|collapse` or the `hidden` attribute.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isRendered(element: ElementLike): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the element reaches the accessibility tree: painted, and not marked
|
|
8
|
+
* `aria-hidden` on itself or an ancestor.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isExposedToAria(element: ElementLike): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Two related questions with different answers, kept deliberately apart.
|
|
13
|
+
*
|
|
14
|
+
* "Can a user see this?" is about painting: `display`, `visibility` and the
|
|
15
|
+
* `hidden` attribute, inherited from every ancestor. That is what `isVisible()`
|
|
16
|
+
* asks.
|
|
17
|
+
*
|
|
18
|
+
* "Would a screen reader announce this?" is the same, plus `aria-hidden`. An
|
|
19
|
+
* `aria-hidden` element is painted — it is still visible — but it is removed
|
|
20
|
+
* from the accessibility tree, and a role query reads that tree. That is what
|
|
21
|
+
* `getByRole()` and the other `getBy*` helpers ask (#1601).
|
|
22
|
+
*
|
|
23
|
+
* Both walk the ancestor chain, because hiding a container hides everything
|
|
24
|
+
* inside it, and both resolve through `getComputedStyle()` so a rule from a
|
|
25
|
+
* stylesheet counts, not only an inline style.
|
|
26
|
+
*/
|
|
27
|
+
declare interface ElementLike {
|
|
28
|
+
nodeType?: number
|
|
29
|
+
parentNode?: any
|
|
30
|
+
ownerDocument?: any
|
|
31
|
+
hasAttribute?: (name: string) => boolean
|
|
32
|
+
getAttribute?: (name: string) => string | null
|
|
33
|
+
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { accessibleName } from '../aria/roles';
|
|
2
|
+
/** @internal Collapse whitespace, the way Playwright compares rendered text. */
|
|
3
|
+
export declare function normalize(value: string | null | undefined): string;
|
|
4
|
+
/**
|
|
5
|
+
* Compare a candidate against a matcher.
|
|
6
|
+
*
|
|
7
|
+
* A string is a substring match after whitespace normalisation unless `exact`,
|
|
8
|
+
* which is Playwright's behaviour and what makes `getByText('Save')` find
|
|
9
|
+
* "Save changes". A RegExp is always used as written.
|
|
10
|
+
*
|
|
11
|
+
* @internal Shared with the web-first matchers, so `toContainText` and
|
|
12
|
+
* `getByText` cannot disagree about what "contains" means.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchesText(candidate: string, expected: string | RegExp, exact?: boolean): boolean;
|
|
2
15
|
/** Elements under `root` carrying `role`, narrowed by the options given. */
|
|
3
16
|
export declare function byRole(root: any, role: string, options?: GetByRoleOptions): any[];
|
|
4
17
|
/**
|
|
@@ -16,6 +29,7 @@ export declare function byAttribute(root: any, attribute: string, text: string |
|
|
|
16
29
|
export declare interface GetByRoleOptions {
|
|
17
30
|
name?: string | RegExp
|
|
18
31
|
exact?: boolean
|
|
32
|
+
includeHidden?: boolean
|
|
19
33
|
checked?: boolean
|
|
20
34
|
disabled?: boolean
|
|
21
35
|
selected?: boolean
|
|
@@ -24,17 +38,35 @@ export declare interface GetByRoleOptions {
|
|
|
24
38
|
}
|
|
25
39
|
export declare interface GetByTextOptions {
|
|
26
40
|
exact?: boolean
|
|
41
|
+
includeHidden?: boolean
|
|
27
42
|
}
|
|
28
43
|
export declare interface FilterOptions {
|
|
29
44
|
hasText?: string | RegExp
|
|
30
45
|
hasNotText?: string | RegExp
|
|
31
46
|
}
|
|
47
|
+
export declare interface WaitForOptions {
|
|
48
|
+
state?: WaitForState
|
|
49
|
+
timeout?: number
|
|
50
|
+
}
|
|
51
|
+
/** Every action takes a timeout, falling back to the page's default. */
|
|
52
|
+
export declare interface ActionOptions {
|
|
53
|
+
timeout?: number
|
|
54
|
+
}
|
|
32
55
|
/** Returns the current matches, re-evaluated on each call. */
|
|
33
56
|
declare type Resolver = () => any[];
|
|
57
|
+
/**
|
|
58
|
+
* What a wait is waiting for.
|
|
59
|
+
*
|
|
60
|
+
* `attached` and `visible` are about one element arriving; `detached` and
|
|
61
|
+
* `hidden` are about it going away, which is the state a closing modal or a
|
|
62
|
+
* finished spinner passes through.
|
|
63
|
+
*/
|
|
64
|
+
export type WaitForState = 'attached' | 'detached' | 'visible' | 'hidden';
|
|
34
65
|
export declare class Locator {
|
|
35
66
|
constructor(_page: any, _resolver: Resolver, _description: string);
|
|
36
67
|
toString(): string;
|
|
37
|
-
|
|
68
|
+
waitFor(options?: WaitForOptions): Promise<void>;
|
|
69
|
+
elementHandle(options?: ActionOptions): Promise<any>;
|
|
38
70
|
elementHandles(): Promise<any[]>;
|
|
39
71
|
locator(selector: string): Locator;
|
|
40
72
|
filter(options: FilterOptions): Locator;
|
|
@@ -63,12 +95,12 @@ export declare class Locator {
|
|
|
63
95
|
isEnabled(): Promise<boolean>;
|
|
64
96
|
isDisabled(): Promise<boolean>;
|
|
65
97
|
isEditable(): Promise<boolean>;
|
|
66
|
-
click(): Promise<void>;
|
|
67
|
-
focus(): Promise<void>;
|
|
68
|
-
blur(): Promise<void>;
|
|
69
|
-
hover(): Promise<void>;
|
|
70
|
-
fill(value: string): Promise<void>;
|
|
71
|
-
type(text: string, options?: { delay?: number }): Promise<void>;
|
|
72
|
-
check(): Promise<void>;
|
|
73
|
-
uncheck(): Promise<void>;
|
|
98
|
+
click(options?: ActionOptions): Promise<void>;
|
|
99
|
+
focus(options?: ActionOptions): Promise<void>;
|
|
100
|
+
blur(options?: ActionOptions): Promise<void>;
|
|
101
|
+
hover(options?: ActionOptions): Promise<void>;
|
|
102
|
+
fill(value: string, options?: ActionOptions): Promise<void>;
|
|
103
|
+
type(text: string, options?: { delay?: number, timeout?: number }): Promise<void>;
|
|
104
|
+
check(options?: ActionOptions): Promise<void>;
|
|
105
|
+
uncheck(options?: ActionOptions): Promise<void>;
|
|
74
106
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poll `check` until it is satisfied, then return its value; throw once
|
|
3
|
+
* `timeout` has elapsed.
|
|
4
|
+
*
|
|
5
|
+
* `reason` is the last thing actually observed, and it goes into the timeout
|
|
6
|
+
* message because "it was never there" and "it was there but hidden" are
|
|
7
|
+
* different bugs that a bare "timed out" cannot tell apart.
|
|
8
|
+
*
|
|
9
|
+
* The first check runs before any sleep, so the ordinary case — the condition
|
|
10
|
+
* already holds — costs nothing. A `timeout` of 0 therefore means exactly one
|
|
11
|
+
* check.
|
|
12
|
+
*
|
|
13
|
+
* A `check` that throws is not retried. Some failures are not states the DOM
|
|
14
|
+
* will grow out of, and retrying them would turn a clear error into a timeout.
|
|
15
|
+
*/
|
|
16
|
+
export declare function waitUntil<T>(check: () => Settled<T> | Pending, options: { timeout: number, describe: (reason: string) => string }): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* How often a wait re-checks.
|
|
19
|
+
*
|
|
20
|
+
* There is no rendering loop here, so what a wait is really waiting for is the
|
|
21
|
+
* task queue to turn over: a timer firing, a `fetch` settling, a microtask
|
|
22
|
+
* draining, a custom element upgrading. 20ms is short enough that a passing
|
|
23
|
+
* test does not feel it, and long enough that a failing one does not re-walk
|
|
24
|
+
* the DOM thousands of times on its way to the timeout.
|
|
25
|
+
*
|
|
26
|
+
* Exported so the web-first matchers re-check on the same cadence. Two waits
|
|
27
|
+
* polling at different rates would be a needless second thing to reason about.
|
|
28
|
+
*/
|
|
29
|
+
export declare const POLL_INTERVAL_MS: 20;
|
|
30
|
+
/** Satisfied, carrying the value the caller wanted. */
|
|
31
|
+
declare interface Settled<T> {
|
|
32
|
+
done: true
|
|
33
|
+
value: T
|
|
34
|
+
}
|
|
35
|
+
/** Not satisfied yet, carrying what was actually seen. */
|
|
36
|
+
declare interface Pending {
|
|
37
|
+
done: false
|
|
38
|
+
reason: string
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One definition of "wait until this holds", and one error for when it does not.
|
|
42
|
+
*
|
|
43
|
+
* `waitForSelector` and `waitForFunction` each grew their own loop and then
|
|
44
|
+
* disagreed about what a timeout is: one returns `null`, the other throws
|
|
45
|
+
* (#1605). A third copy for locators would have made three copies and three
|
|
46
|
+
* opinions, so this is the one locators use and the one those two should move
|
|
47
|
+
* onto.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when a wait gives up.
|
|
51
|
+
*
|
|
52
|
+
* A distinct type so a caller can catch a timeout without matching on the
|
|
53
|
+
* message, which is the only thing available today.
|
|
54
|
+
*/
|
|
55
|
+
export declare class TimeoutError extends Error {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{r,
|
|
2
|
+
import{r,E}from"./chunk-3d9kwyx0.js";import{L,b}from"./chunk-7c8vh5me.js";function m(e,t){let[o,...s]=e.split(";").map((p)=>p.trim()),n=o.indexOf("="),i=n===-1?o:o.slice(0,n),l=n===-1?"":o.slice(n+1),c={key:i,value:l,originURL:t};for(let p of s){let[d,u=""]=p.split("=").map((a)=>a.trim());switch(d.toLowerCase()){case"domain":c.domain=u.replace(/^\./,"").toLowerCase();break;case"path":c.path=u;break;case"expires":{let a=new Date(u);if(!Number.isNaN(a.getTime()))c.expires=a;break}case"max-age":{let a=Number(u);if(Number.isFinite(a))c.expires=new Date(Date.now()+a*1000);break}case"httponly":c.httpOnly=!0;break;case"secure":c.secure=!0;break;case"samesite":{let a=u.toLowerCase();if(a==="strict"||a==="lax"||a==="none")c.sameSite=a.charAt(0).toUpperCase()+a.slice(1);break}}}return c}function k(e){return e.map((t)=>`${t.key}=${t.value??""}`).join("; ")}class Q{_container;constructor(e){this._container=e??new L}_getContainer(){return this._container}setCookie(e,t,o,s){let n=typeof o==="function"?o:s;try{let i=m(e,t);if(this._container.addCookies([i]),n)return n(null,i);return Promise.resolve(i)}catch(i){if(n)return n(i);return Promise.reject(i)}}getCookies(e,t,o){let s=typeof t==="object"&&t!==null?t:{},n=typeof t==="function"?t:o;try{let i=this._container.getCookies(e,s.http===!0);if(n)return n(null,i);return Promise.resolve(i)}catch(i){if(n)return n(i);return Promise.reject(i)}}getCookieString(e,t){try{let o=k(this._container.getCookies(e));if(t)return t(null,o);return Promise.resolve(o)}catch(o){if(t)return t(o);return Promise.reject(o)}}}import{Buffer as f}from"buffer";class Ye{_strictSSL;_proxy;_userAgent;constructor(e={}){this._strictSSL=e.strictSSL??!0,this._proxy=e.proxy,this._userAgent=e.userAgent??"Mozilla/5.0 (VeryHappyDOM)"}get userAgent(){return this._userAgent}fetch(e,t={}){return globalThis.fetch(e,{headers:{"User-Agent":this._userAgent,...t.accept?{Accept:t.accept}:{},...t.referrer?{Referer:t.referrer}:{}}}).then((o)=>o.arrayBuffer()).then((o)=>f.from(o))}}var w=["log","info","warn","error","debug","dir","dirxml","trace","table","group","groupCollapsed","groupEnd","time","timeEnd","timeLog","count","countReset","assert","clear"];class Z{_listeners=new Map;_sinks=[];on(e,t){let o=this._listeners.get(e);if(!o)o=new Set,this._listeners.set(e,o);return o.add(t),this}off(e,t){return this._listeners.get(e)?.delete(t),this}removeAllListeners(e){if(e)this._listeners.delete(e);else this._listeners.clear();return this}listeners(e){return Array.from(this._listeners.get(e)??[])}emit(e,...t){let o=this._listeners.get(e),s=!1;if(o&&o.size>0){s=!0;for(let n of o)try{n(...t)}catch{}}for(let n of this._sinks){if(e==="jsdomError"&&n.options.omitJSDOMErrors)continue;let i=n.target[e];if(typeof i==="function")i.apply(n.target,t)}return s}sendTo(e,t={}){return this._sinks.push({target:e,options:t}),this}_asConsole(){let e=this,t={};for(let o of w)t[o]=(...s)=>{e.emit(o,...s)};return t}}class F{window;virtualConsole;cookieJar;constructor(e="",t={}){let{url:o="about:blank",referrer:s,contentType:n="text/html",virtualConsole:i=new Z,cookieJar:l=new Q,beforeParse:c,pretendToBeVisual:p=!1,runScripts:d}=t;this.virtualConsole=i,this.cookieJar=l;let u={url:o,console:i._asConsole()};this.window=new b(u);let C=this.window;if(C._cookieJar=l,s)this.window.document.referrer=s;if(n)this.window.document.contentType=n;if(this.window.addEventListener("error",(a)=>{let g=a?.error??a;this.virtualConsole.emit("jsdomError",g)}),d==="outside-only"||d==="dangerously"){let a=this.window;a.eval=globalThis.eval.bind(globalThis),a.Function=globalThis.Function}if(c?.(this.window),this.window.document.readyState="loading",e)this._parse(e,n);if(d==="dangerously")this._executeScripts();queueMicrotask(()=>{this.window.document.readyState="interactive",this.window.document.dispatchEvent(new r("DOMContentLoaded",{bubbles:!0,cancelable:!1})),this.window.document.readyState="complete",this.window.dispatchEvent(new r("load"))})}_executeScripts(){let t=this.window.document.querySelectorAll("script");for(let o of t){if(o.getAttribute("src"))continue;let n=o.getAttribute("type");if(n&&n!=="text/javascript"&&n!=="application/javascript"&&n!=="module")continue;let i=o.textContent??"";if(!i.trim())continue;try{Function("window","document",`with (window) { ${i} }`)(this.window,this.window.document)}catch(l){this.virtualConsole.emit("jsdomError",l)}}}serialize(){let e=this.window.document,t=e.documentElement;if(!t)return"";let o=e.doctype===null?"<!DOCTYPE html>":"",s=t.outerHTML??"";return`${o}${s}`}reconfigure(e){if(e.url!==void 0){let t=this.window;t.location=e.url}}nodeLocation(e){return null}toString(){return this.serialize()}static fragment(e=""){let o=new F().window.document.createElement("template");return o.innerHTML=e,o.content}static async fromURL(e,t={}){let o=await globalThis.fetch(e),s=await o.text(),n=o.headers.get("content-type")??t.contentType;return new F(s,{...t,url:e,contentType:n??void 0})}static async fromFile(e,t={}){let s=await Bun.file(e).text(),n=t.url??`file://${e.startsWith("/")?e:`${process.cwd()}/${e}`}`;return new F(s,{...t,url:n})}_parse(e,t){let o=this.window.document,n=new this.window.DOMParser().parseFromString(e,t);if(n.documentElement)o.documentElement=n.documentElement,o.childNodes=n.childNodes,o.head=n.head,o.body=n.body,E(o.documentElement,o);o.contentType=t}}export{Q,Ye,Z,F};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function g(e,n,a){try{e[n]=a;return}catch{}try{Object.defineProperty(e,n,{configurable:!0,enumerable:n!=="_path",writable:!0,value:a})}catch{}}function m(e,n){return Boolean(e?.[n])}function se(e){return Boolean(e&&typeof e==="object")}function k(e){return se(e)?e.parentNode??null:null}function F(e){return e?.nodeType===11&&e?.nodeName==="#shadow-root"&&e?.host}function de(e,n){let a=[],u=e;while(u){if(a.push(u),F(u)&&n?.composed!==!0)break;u=u._getEventParent?.()??null}return a}function ue(e){let n=e;while(n){if(F(n))return n;n=k(n)}return null}function ce(e,n){let a=e;while(a){if(a===n)return!0;a=k(a)}return!1}function U(e,n){let a=ue(e);if(!a)return e;if(n===a||ce(n,a))return e;return a.host??e}class f{_eventListeners=new Map;addEventListener(e,n,a={}){if(!n)return;let u=a!==void 0&&a!==!1&&a!==!0&&typeof a==="object",N=u?a.capture??!1:a===!0,p=u?a.once??!1:!1,T=u?a.passive??!1:!1,h=u?a.signal:void 0;if(h?.aborted)return;let y=this._eventListeners.get(e);if(y){for(let _=0;_<y.length;_++)if(y[_].listener===n&&y[_].options.capture===N)return;y.push({listener:n,options:{capture:N,once:p,passive:T},signal:h})}else this._eventListeners.set(e,[{listener:n,options:{capture:N,once:p,passive:T},signal:h}]);if(h)h.addEventListener("abort",()=>{this.removeEventListener(e,n,{capture:N})},{once:!0})}removeEventListener(e,n,a={}){if(!n)return;let u=this._eventListeners.get(e);if(!u)return;let N=typeof a==="boolean"?{capture:a}:{capture:a.capture??!1},p=u.findIndex((T)=>T.listener===n&&T.options.capture===N.capture);if(p!==-1)u.splice(p,1);if(u.length===0)this._eventListeners.delete(e)}dispatchEvent(e){if(!e||typeof e.type!=="string"||!e.type)throw Error("Failed to execute dispatchEvent: event.type must be a non-empty string");let n=de(this,e);if(n.length===1){if(g(e,"target",this),g(e,"eventPhase",2),g(e,"currentTarget",this),typeof e.composedPath!=="function")g(e,"composedPath",()=>[this]);g(e,"_path",[this]);let h=()=>!1;return this._invokeEventListeners(e,!0,h),this._invokeEventListeners(e,!1,h),g(e,"eventPhase",0),g(e,"currentTarget",null),!e.defaultPrevented}let a=this,u=e?.relatedTarget??null,N=(h,y)=>{if(g(e,"eventPhase",y),g(e,"currentTarget",h),h){if(g(e,"target",U(a,h)),u)g(e,"relatedTarget",U(u,h))}};if(g(e,"target",a),g(e,"_path",[...n]),typeof e.composedPath!=="function")g(e,"composedPath",()=>[...n]);let p=()=>m(e,"_propagationStopped")||m(e,"propagationStopped"),T=()=>m(e,"_immediatePropagationStopped")||m(e,"immediatePropagationStopped");for(let h=n.length-1;h>=1;h--){if(p())break;N(n[h],1),n[h]._invokeEventListeners(e,!0,T)}if(!p()){if(N(this,2),this._invokeEventListeners(e,!0,T),!T())this._invokeEventListeners(e,!1,T)}if(e.bubbles===!0&&!p())for(let h=1;h<n.length;h++){if(p())break;N(n[h],3),n[h]._invokeEventListeners(e,!1,T)}if(g(e,"eventPhase",0),g(e,"currentTarget",null),g(e,"target",a),u)g(e,"relatedTarget",u);return!Boolean(e.defaultPrevented)}_getEventParent(){return null}_invokeEventListeners(e,n,a){let u=this._eventListeners.get(e.type);if(!u||u.length===0)return;let N=u.length===1?u:[...u];for(let p of N){if((p.options.capture??!1)!==n)continue;if(a())break;if(p.options.passive){let T=e.preventDefault;e.preventDefault=()=>{};try{p.listener.call(this,e)}catch(h){console.error("Error in event listener:",h)}e.preventDefault=T}else try{p.listener.call(this,e)}catch(T){console.error("Error in event listener:",T)}if(p.options.once)this.removeEventListener(e.type,p.listener,{capture:n})}}}var t=1,G=2,i=3,z=4,Y=5,q=6,W=7,c=8,o=9,K=10,C=11,X=12,x=1,v=2,J=4,M=8,Te=16,w=32;function Ii(e){return e?.nodeType===t}function j(e,n){let a=e.nodeType===o?e:e.ownerDocument,u=a?.createTextNode?.(`${n}`);if(u)return u;let{VirtualTextNode:N}=import.meta.require("./chunk-qkxcr7jt.js"),p=new N(`${n}`);return p.ownerDocument=a??null,p}function O(e){let n=e.nodeType===o?e:e.ownerDocument,a=n?.createDocumentFragment?.();if(a)return a;let{VirtualDocumentFragment:u}=import.meta.require("./chunk-yqxxa2ez.js"),N=new u;return N.ownerDocument=n??null,N}function b(e,n){return n.map((a)=>typeof a==="string"?j(e,a):a)}function Q(e,n){if(e===n)return!0;if(!e||!n)return!1;if(e.nodeType!==n.nodeType||e.nodeName!==n.nodeName||e.nodeValue!==n.nodeValue)return!1;if(e.attributes.size!==n.attributes.size)return!1;for(let[a,u]of e.attributes)if(n.attributes.get(a)!==u)return!1;if(e.childNodes.length!==n.childNodes.length)return!1;for(let a=0;a<e.childNodes.length;a++)if(!Q(e.childNodes[a],n.childNodes[a]))return!1;return!0}class d extends f{static ELEMENT_NODE=t;static ATTRIBUTE_NODE=G;static TEXT_NODE=i;static CDATA_SECTION_NODE=z;static ENTITY_REFERENCE_NODE=Y;static ENTITY_NODE=q;static PROCESSING_INSTRUCTION_NODE=W;static COMMENT_NODE=c;static DOCUMENT_NODE=o;static DOCUMENT_TYPE_NODE=K;static DOCUMENT_FRAGMENT_NODE=C;static NOTATION_NODE=X;static DOCUMENT_POSITION_DISCONNECTED=x;static DOCUMENT_POSITION_PRECEDING=v;static DOCUMENT_POSITION_FOLLOWING=J;static DOCUMENT_POSITION_CONTAINS=M;static DOCUMENT_POSITION_CONTAINED_BY=Te;static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=w;ELEMENT_NODE=t;ATTRIBUTE_NODE=G;TEXT_NODE=i;CDATA_SECTION_NODE=z;ENTITY_REFERENCE_NODE=Y;ENTITY_NODE=q;PROCESSING_INSTRUCTION_NODE=W;COMMENT_NODE=c;DOCUMENT_NODE=o;DOCUMENT_TYPE_NODE=K;DOCUMENT_FRAGMENT_NODE=C;NOTATION_NODE=X;DOCUMENT_POSITION_DISCONNECTED=x;DOCUMENT_POSITION_PRECEDING=v;DOCUMENT_POSITION_FOLLOWING=J;DOCUMENT_POSITION_CONTAINS=M;DOCUMENT_POSITION_CONTAINED_BY=Te;DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=w;nodeValue=null;attributes=new Map;childNodes=[];parentNode=null;ownerDocument=null;get children(){let e=this.childNodes,n=[];for(let a=0;a<e.length;a++)if(e[a].nodeType===t)n.push(e[a]);return n}get firstElementChild(){return this.childNodes.find((e)=>e.nodeType===t)??null}get lastElementChild(){for(let e=this.childNodes.length-1;e>=0;e--)if(this.childNodes[e].nodeType===t)return this.childNodes[e];return null}get childElementCount(){let e=0;for(let n of this.childNodes)if(n.nodeType===t)e++;return e}get firstChild(){return this.childNodes[0]??null}get lastChild(){return this.childNodes.length>0?this.childNodes[this.childNodes.length-1]:null}get previousSibling(){if(!this.parentNode)return null;let e=this.parentNode.childNodes;for(let n=0;n<e.length;n++)if(e[n]===this)return n>0?e[n-1]:null;return null}get nextSibling(){if(!this.parentNode)return null;let e=this.parentNode.childNodes;for(let n=0;n<e.length;n++)if(e[n]===this)return n<e.length-1?e[n+1]:null;return null}get parentElement(){return Ii(this.parentNode)?this.parentNode:null}get isConnected(){let e=this;while(e){if(e.nodeType===o)return!0;e=e.parentNode}return!1}hasChildNodes(){return this.childNodes.length>0}get baseURI(){return this.ownerDocument?.baseURI||""}append(...e){let n=this;if(typeof n.appendChild!=="function")throw Error("This node type does not support append()");let a=b(this,e);if(a.length===0)return;if(a.length===1){n.appendChild(a[0]);return}let u=O(this);for(let N of a)u.appendChild(N);n.appendChild(u)}prepend(...e){let n=this;if(typeof n.insertBefore!=="function")throw Error("This node type does not support prepend()");let a=b(this,e);if(a.length===0)return;if(a.length===1){n.insertBefore(a[0],this.firstChild??null);return}let u=O(this);for(let N of a)u.appendChild(N);n.insertBefore(u,this.firstChild??null)}before(...e){if(!this.parentNode)return;let n=this.parentNode,a=b(this.parentNode,e);if(a.length===0)return;if(a.length===1){n.insertBefore(a[0],this);return}let u=O(this.parentNode);for(let N of a)u.appendChild(N);n.insertBefore(u,this)}after(...e){if(!this.parentNode)return;let n=this.parentNode,a=this.nextSibling,u=b(this.parentNode,e);if(u.length===0)return;if(u.length===1){n.insertBefore(u[0],a??null);return}let N=O(this.parentNode);for(let p of u)N.appendChild(p);n.insertBefore(N,a??null)}replaceWith(...e){if(!this.parentNode)return;let n=this.parentNode,a=b(this.parentNode,e);if(a.length===0){n.removeChild(this);return}if(a.length===1){n.replaceChild(a[0],this);return}let u=O(this.parentNode);for(let N of a)u.appendChild(N);n.replaceChild(u,this)}remove(){if(this.parentNode)this.parentNode.removeChild(this)}replaceChildren(...e){let n=this;if(typeof n.removeChild!=="function"||typeof n.appendChild!=="function")throw Error("This node type does not support replaceChildren()");while(this.childNodes.length>0)n.removeChild(this.childNodes[this.childNodes.length-1]);for(let a of e)if(typeof a==="string")n.appendChild(j(this,a));else n.appendChild(a)}isSameNode(e){return this===e}isEqualNode(e){return Q(this,e)}getRootNode(e={}){let n=this,a=this;while(n.parentNode){let u=n.parentNode;if(a=u,u.nodeType===C&&u.host&&e.composed!==!0)return u;n=u}return a}contains(e){if(!e)return!1;let n=e;while(n){if(n===this)return!0;n=n.parentNode}return!1}normalize(){let e=0;while(e<this.childNodes.length){let n=this.childNodes[e];if(n.nodeType===i){let a=n.nodeValue||"",u=e+1;while(u<this.childNodes.length&&this.childNodes[u].nodeType===i)a+=this.childNodes[u].nodeValue||"",this.childNodes.splice(u,1);if(a===""){this.childNodes.splice(e,1),n.parentNode=null;continue}n.nodeValue=a}else if(typeof n.normalize==="function")n.normalize();e++}}compareDocumentPosition(e){if(e===this)return 0;let n=this._virtualRootNode(this),a=this._virtualRootNode(e);if(n!==a)return x|w;if(this!==e&&this.contains(e))return M|v;if(e!==this&&this._virtualNodeContains(e,this))return Te|J;let u=this._virtualDocumentOrder(n);return u.indexOf(this)<u.indexOf(e)?J:v}_getEventParent(){if(this.parentNode)return this.parentNode;if(this.nodeType===o)return this.defaultView??null;return null}_virtualRootNode(e){let n=e;while(n.parentNode)n=n.parentNode;return n}_virtualNodeContains(e,n){return e!==n&&typeof e.contains==="function"?e.contains(n):!1}_virtualDocumentOrder(e){let n=[],a=(u)=>{n.push(u);for(let N of u.childNodes)a(N)};return a(e),n}}function Ne(e){let n=e?.constructor;if(!n||!Array.isArray(n.observedAttributes))return[];return n.observedAttributes.map((a)=>`${a}`.toLowerCase())}function Z(e){return e._getInternalShadowRoot?.()??null}function ee(e){return e.tagName==="TEMPLATE"?e.content??null:null}function D(e,n){if(e.nodeType===t)n(e);let a=Z(e);if(a)D(a,n);if(ee(e))return;for(let u of e.childNodes)D(u,n)}function V(e,n){if(e.nodeType===t)n(e);let a=Z(e);if(a)V(a,n);let u=ee(e);if(u){V(u,n);return}for(let N of e.childNodes)V(N,n)}function Ee(e){D(e,(n)=>{if(typeof n.connectedCallback==="function"&&n.isConnected)n.connectedCallback()})}function I(e){D(e,(n)=>{if(typeof n.disconnectedCallback==="function")n.disconnectedCallback()})}function te(e,n,a){if(!n||!a||n===a)return;V(e,(u)=>{if(typeof u.adoptedCallback==="function")u.adoptedCallback()})}function ve(e,n,a,u){if(typeof e?.attributeChangedCallback!=="function")return;if(a===u)return;if(!Ne(e).includes(n.toLowerCase()))return;e.attributeChangedCallback(n,a,u)}class r{static NONE=0;static CAPTURING_PHASE=1;static AT_TARGET=2;static BUBBLING_PHASE=3;NONE=0;CAPTURING_PHASE=1;AT_TARGET=2;BUBBLING_PHASE=3;type;target=null;currentTarget=null;bubbles;cancelable;composed;defaultPrevented=!1;propagationStopped=!1;immediatePropagationStopped=!1;eventPhase=0;timeStamp;isTrusted=!1;_path=[];_propagationStopped=!1;_immediatePropagationStopped=!1;constructor(e,n={}){this.type=e,this.bubbles=n.bubbles??!1,this.cancelable=n.cancelable??!1,this.composed=n.composed??!1,this.timeStamp=Date.now()}initEvent(e,n=!1,a=!1){this.type=e,this.bubbles=n,this.cancelable=a,this.defaultPrevented=!1,this.propagationStopped=!1,this.immediatePropagationStopped=!1,this._propagationStopped=!1,this._immediatePropagationStopped=!1}preventDefault(){if(this.cancelable)this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0,this._propagationStopped=!0}stopImmediatePropagation(){this.immediatePropagationStopped=!0,this.propagationStopped=!0,this._immediatePropagationStopped=!0,this._propagationStopped=!0}composedPath(){return[...this._path]}get cancelBubble(){return this.propagationStopped}set cancelBubble(e){if(e)this.stopPropagation()}get returnValue(){return!this.defaultPrevented}set returnValue(e){if(!e)this.preventDefault()}get srcElement(){return this.target}}var ne=new WeakMap,R=new WeakSet;function oe(e){return e?.nodeType===11&&e?.nodeName==="#shadow-root"&&Boolean(e.host)}function re(e){let n=e;while(n){if(oe(n))return n;n=n.parentNode}return null}function ie(e){return e?._getInternalShadowRoot?.()?.querySelectorAll?.("slot")??[]}function pe(e,n){return e.length===n.length&&e.every((a,u)=>a===n[u])}function he(e){if(R.has(e))return;R.add(e),queueMicrotask(()=>{R.delete(e);let n=ne.get(e)??[],a=ci(e);if(ne.set(e,a),!pe(n,a))e.dispatchEvent(new r("slotchange"))})}function ci(e,n={}){let a=re(e);if(!a)return[];let u=e.getAttribute?.("name")??"";if(ie(a.host).find((h)=>(h.getAttribute?.("name")??"")===u)!==e)return[];let p=(a.host?.childNodes??[]).filter((h)=>{if(h.nodeType!==t&&h.nodeType!==i)return!1;return(h.nodeType===t?h.getAttribute?.("slot")??"":"")===u});if(!n.flatten)return p;return(p.length>0?p:e.childNodes??[]).flatMap((h)=>{if(h?.tagName==="SLOT"&&typeof h.assignedNodes==="function")return h.assignedNodes({flatten:!0});return[h]})}function Gi(e,n={}){return ci(e,n).filter((a)=>a.nodeType===t)}function B(e){let n=e?._getInternalShadowRoot?.()?e:null,a=oe(e)?e:re(e),u=e?.parentNode?._getInternalShadowRoot?.()?e.parentNode:null,N=n??a?.host??u;if(!N)return;for(let p of ie(N))he(p)}function S(e,n,a,u,N){if(n.length===0&&a.length===0)return;l._queueMutationRecord({type:"childList",target:e,addedNodes:n,removedNodes:a,previousSibling:u,nextSibling:N,attributeName:null,attributeNamespace:null,oldValue:null}),B(e)}function ae(e){return e.nodeType===o?e:e.ownerDocument}function fe(e){return e._getInternalShadowRoot?.()??null}function ge(e){return e.tagName==="TEMPLATE"?e.content??null:null}function A(e){if(!e._lastTraversalParent&&!e._lastTraversalNextSibling)return;e._lastTraversalParent=null,e._lastTraversalNextSibling=null;for(let n of e.childNodes)A(n)}function E(e,n){if(e.ownerDocument===n&&e.nodeType!==o)return;let a=e.ownerDocument??null;if(e.nodeType!==o)e.ownerDocument=n;if(e.nodeType===t){let u=e.attributes?.get("id");if(u!==void 0){if(a?._idIndex)a._idIndex.delete(u);if(n?._idIndex)n._idIndex.set(u,e)}let N=fe(e);if(N)E(N,n);let p=ge(e);if(p)p.ownerDocument=n}te(e,a,n);for(let u of e.childNodes)E(u,n)}function we(e,n){let a=n;while(a){if(a===e)return!0;a=a.parentNode}return!1}function _e(e){let n=e.ownerDocument;if(!n||!n._idIndex||n._idIndex.size===0)return;if(e.nodeType===t){let a=e.attributes?.get("id");if(a!==void 0)n._idIndex.delete(a);for(let u of e.childNodes)if(u.nodeType===t)_e(u)}}function le(e){let n=e.isConnected===!0;if(!e.parentNode)return;_e(e);let a=e.parentNode,u=a.childNodes,N=u.indexOf(e),p=N>=0&&N<u.length-1?u[N+1]:null;if(N!==-1)u.splice(N,1);if(e._lastTraversalParent=a,e._lastTraversalNextSibling=p,e.parentNode=null,B(a),n)I(e)}function L(e,n){if(n===e||we(n,e))throw Error("The new child element contains the parent");if(n.nodeType===C){let a=[...n.childNodes];n.childNodes=[];let u=ae(e);for(let N of a){if(N.parentNode)le(N),A(N);N.parentNode=e,E(N,u)}return a}if(n.parentNode)le(n),A(n);return n.parentNode=e,E(n,ae(e)),[n]}function P(e,n){let a=L(e,n),u=e.childNodes.length>0?e.childNodes[e.childNodes.length-1]:null;if(a.length===1)e.childNodes.push(a[0]);else e.childNodes.push(...a);for(let N of a)if(N.isConnected===!0)Ee(N);return S(e,a,[],u,null),n}function ze(e,n,a){if(a===null)return P(e,n);let u=e.childNodes.indexOf(a);if(u===-1)throw Error("Reference node not found");let N=L(e,n),p=u>0?e.childNodes[u-1]:null;e.childNodes.splice(u,0,...N);for(let T of N)if(T.isConnected===!0)Ee(T);return S(e,N,[],p,a),n}function Se(e,n){let a=e.childNodes.indexOf(n);if(a===-1)throw Error("Child node not found");_e(n);let u=n.isConnected===!0,N=a>0?e.childNodes[a-1]:null,p=a<e.childNodes.length-1?e.childNodes[a+1]:null;if(e.childNodes.splice(a,1),n._lastTraversalParent=e,n._lastTraversalNextSibling=p,n.parentNode=null,u)I(n);return S(e,[],[n],N,p),n}function je(e,n,a){let u=e.childNodes.indexOf(a);if(u===-1)throw Error("Old node not found");_e(a);let N=L(e,n),p=a.isConnected===!0,T=u>0?e.childNodes[u-1]:null,h=u<e.childNodes.length-1?e.childNodes[u+1]:null;if(e.childNodes.splice(u,1,...N),a._lastTraversalParent=e,a._lastTraversalNextSibling=h,a.parentNode=null,p)I(a);for(let y of N)if(y.isConnected===!0)Ee(y);return S(e,N,[a],T,h),a}function H(e){if(e.nodeType===i)return e.nodeValue||"";if(e.nodeType===c)return"";let n="";for(let a of e.childNodes)n+=H(a);return n}function ye(e,n,a,u){if(e===n)return!0;if(!a)return!1;let N=e.parentNode;while(N){if(N===n)return!0;N=N.parentNode}for(let p of u)if(e===p||we(p,e))return!0;return!1}function Oe(e,n){if(e.type==="childList")return n.childList===!0;if(e.type==="attributes"){if(n.attributes!==!0)return!1;if(n.attributeFilter&&e.attributeName)return n.attributeFilter.map((a)=>a.toLowerCase()).includes(e.attributeName.toLowerCase());return!0}if(e.type==="characterData")return n.characterData===!0;return!1}function be(e){let n={...e};if(n.attributeOldValue===!0||n.attributeFilter){if(n.attributes===!1)throw TypeError("Failed to execute observe: attributeOldValue/attributeFilter requires attributes to be true");n.attributes=!0}if(n.characterDataOldValue===!0){if(n.characterData===!1)throw TypeError("Failed to execute observe: characterDataOldValue requires characterData to be true");n.characterData=!0}if(n.childList!==!0&&n.attributes!==!0&&n.characterData!==!0)throw TypeError("Failed to execute observe: at least one of childList, attributes, or characterData must be true");return n}class l{static _observers=new Set;_callback;_records=[];_observations=new Map;_scheduled=!1;_transientRoots=new Set;constructor(e){this._callback=e}observe(e,n={}){let a=be(n),u=this._observations.get(e);if(u){let N={...u,...a};if(u.attributeFilter&&a.attributeFilter){let p=new Set([...u.attributeFilter,...a.attributeFilter]);N.attributeFilter=Array.from(p)}this._observations.set(e,N)}else this._observations.set(e,a);l._observers.add(this)}disconnect(){this._observations.clear(),l._observers.delete(this),this._records=[],this._scheduled=!1,this._transientRoots.clear()}takeRecords(){let e=this._records;return this._records=[],e}_addRecord(e){if(this._records.push(e),this._scheduled)return;this._scheduled=!0,queueMicrotask(()=>{if(this._scheduled=!1,this._records.length>0){let n=this.takeRecords();this._callback(n,this)}this._transientRoots.clear()})}static _queueMutationRecord(e){if(l._observers.size===0)return;for(let n of l._observers)for(let[a,u]of n._observations){if(!ye(e.target,a,u.subtree===!0,n._transientRoots))continue;if(e.type==="childList"&&e.removedNodes.length>0&&u.subtree===!0)for(let p of e.removedNodes)n._transientRoots.add(p);if(!Oe(e,u))continue;n._addRecord({...e,oldValue:e.type==="attributes"?u.attributeOldValue?e.oldValue:null:e.type==="characterData"?u.characterDataOldValue?e.oldValue:null:null})}}}class s extends d{nodeType=i;nodeKind="text";nodeName="#text";nodeValue;constructor(e){super();this.nodeValue=e}get textContent(){return this.nodeValue||""}set textContent(e){let n=this.nodeValue||"";this.nodeValue=e,l._queueMutationRecord({type:"characterData",target:this,addedNodes:[],removedNodes:[],previousSibling:null,nextSibling:null,attributeName:null,attributeNamespace:null,oldValue:n})}get data(){return this.nodeValue||""}set data(e){this.textContent=e}get length(){return(this.nodeValue||"").length}substringData(e,n){let a=this.nodeValue||"";if(e<0||e>a.length)throw new DOMException("The index is not in the allowed range.","IndexSizeError");return a.slice(e,e+n)}appendData(e){this.textContent=(this.nodeValue||"")+e}insertData(e,n){let a=this.nodeValue||"";if(e<0||e>a.length)throw new DOMException("The index is not in the allowed range.","IndexSizeError");this.textContent=a.slice(0,e)+n+a.slice(e)}deleteData(e,n){let a=this.nodeValue||"";if(e<0||e>a.length)throw new DOMException("The index is not in the allowed range.","IndexSizeError");this.textContent=a.slice(0,e)+a.slice(e+n)}replaceData(e,n,a){let u=this.nodeValue||"";if(e<0||e>u.length)throw new DOMException("The index is not in the allowed range.","IndexSizeError");this.textContent=u.slice(0,e)+a+u.slice(e+n)}splitText(e){let n=this.nodeValue||"";if(e<0||e>n.length)throw new DOMException("The index is not in the allowed range.","IndexSizeError");let a=n.slice(e);this.textContent=n.slice(0,e);let u=new s(a);if(u.ownerDocument=this.ownerDocument,this.parentNode){let N=this.parentNode,p=N.childNodes,T=p.indexOf(this);if(T!==-1&&T<p.length-1)N.insertBefore(u,p[T+1]);else N.appendChild(u)}return u}get wholeText(){let e="",n=this;while(n?.previousSibling?.nodeType===i)n=n.previousSibling;while(n&&n.nodeType===i)e+=n.nodeValue||"",n=n.nextSibling;return e}cloneNode(){return new s(this.nodeValue)}}
|
|
3
|
+
export{f,r,Ee,ve,ci,Gi,B,E,we,_e,P,ze,Se,je,H,l,s,t,i,c,o,C,J,Te,Ii,d};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var Z={transparent:{r:0,g:0,b:0,a:0},black:{r:0,g:0,b:0,a:255},white:{r:255,g:255,b:255,a:255},red:{r:255,g:0,b:0,a:255},green:{r:0,g:128,b:0,a:255},blue:{r:0,g:0,b:255,a:255},yellow:{r:255,g:255,b:0,a:255},cyan:{r:0,g:255,b:255,a:255},magenta:{r:255,g:0,b:255,a:255},gray:{r:128,g:128,b:128,a:255},grey:{r:128,g:128,b:128,a:255},silver:{r:192,g:192,b:192,a:255},maroon:{r:128,g:0,b:0,a:255},olive:{r:128,g:128,b:0,a:255},lime:{r:0,g:255,b:0,a:255},aqua:{r:0,g:255,b:255,a:255},teal:{r:0,g:128,b:128,a:255},navy:{r:0,g:0,b:128,a:255},fuchsia:{r:255,g:0,b:255,a:255},purple:{r:128,g:0,b:128,a:255},orange:{r:255,g:165,b:0,a:255},pink:{r:255,g:192,b:203,a:255},brown:{r:165,g:42,b:42,a:255},gold:{r:255,g:215,b:0,a:255},indigo:{r:75,g:0,b:130,a:255},violet:{r:238,g:130,b:238,a:255},coral:{r:255,g:127,b:80,a:255},salmon:{r:250,g:128,b:114,a:255},khaki:{r:240,g:230,b:140,a:255},plum:{r:221,g:160,b:221,a:255},orchid:{r:218,g:112,b:214,a:255},turquoise:{r:64,g:224,b:208,a:255},tan:{r:210,g:180,b:140,a:255},chocolate:{r:210,g:105,b:30,a:255},tomato:{r:255,g:99,b:71,a:255},crimson:{r:220,g:20,b:60,a:255},darkblue:{r:0,g:0,b:139,a:255},darkgreen:{r:0,g:100,b:0,a:255},darkred:{r:139,g:0,b:0,a:255},darkorange:{r:255,g:140,b:0,a:255},lightblue:{r:173,g:216,b:230,a:255},lightgreen:{r:144,g:238,b:144,a:255},lightgray:{r:211,g:211,b:211,a:255},lightgrey:{r:211,g:211,b:211,a:255},lightpink:{r:255,g:182,b:193,a:255},lightyellow:{r:255,g:255,b:224,a:255},darkgray:{r:169,g:169,b:169,a:255},darkgrey:{r:169,g:169,b:169,a:255},slategray:{r:112,g:128,b:144,a:255},slategrey:{r:112,g:128,b:144,a:255},dimgray:{r:105,g:105,b:105,a:255},dimgrey:{r:105,g:105,b:105,a:255},whitesmoke:{r:245,g:245,b:245,a:255},snow:{r:255,g:250,b:250,a:255},ivory:{r:255,g:255,b:240,a:255},beige:{r:245,g:245,b:220,a:255},linen:{r:250,g:240,b:230,a:255},aliceblue:{r:240,g:248,b:255,a:255},antiquewhite:{r:250,g:235,b:215,a:255},azure:{r:240,g:255,b:255,a:255},bisque:{r:255,g:228,b:196,a:255},blanchedalmond:{r:255,g:235,b:205,a:255},burlywood:{r:222,g:184,b:135,a:255},cadetblue:{r:95,g:158,b:160,a:255},chartreuse:{r:127,g:255,b:0,a:255},cornflowerblue:{r:100,g:149,b:237,a:255},cornsilk:{r:255,g:248,b:220,a:255},deeppink:{r:255,g:20,b:147,a:255},deepskyblue:{r:0,g:191,b:255,a:255},dodgerblue:{r:30,g:144,b:255,a:255},firebrick:{r:178,g:34,b:34,a:255},floralwhite:{r:255,g:250,b:240,a:255},forestgreen:{r:34,g:139,b:34,a:255},gainsboro:{r:220,g:220,b:220,a:255},ghostwhite:{r:248,g:248,b:255,a:255},greenyellow:{r:173,g:255,b:47,a:255},honeydew:{r:240,g:255,b:240,a:255},hotpink:{r:255,g:105,b:180,a:255},indianred:{r:205,g:92,b:92,a:255},lavender:{r:230,g:230,b:250,a:255},lavenderblush:{r:255,g:240,b:245,a:255},lawngreen:{r:124,g:252,b:0,a:255},lemonchiffon:{r:255,g:250,b:205,a:255},lightcoral:{r:240,g:128,b:128,a:255},lightcyan:{r:224,g:255,b:255,a:255},lightgoldenrodyellow:{r:250,g:250,b:210,a:255},lightsalmon:{r:255,g:160,b:122,a:255},lightseagreen:{r:32,g:178,b:170,a:255},lightskyblue:{r:135,g:206,b:250,a:255},lightslategray:{r:119,g:136,b:153,a:255},lightslategrey:{r:119,g:136,b:153,a:255},lightsteelblue:{r:176,g:196,b:222,a:255},limegreen:{r:50,g:205,b:50,a:255},mediumaquamarine:{r:102,g:205,b:170,a:255},mediumblue:{r:0,g:0,b:205,a:255},mediumorchid:{r:186,g:85,b:211,a:255},mediumpurple:{r:147,g:112,b:219,a:255},mediumseagreen:{r:60,g:179,b:113,a:255},mediumslateblue:{r:123,g:104,b:238,a:255},mediumspringgreen:{r:0,g:250,b:154,a:255},mediumturquoise:{r:72,g:209,b:204,a:255},mediumvioletred:{r:199,g:21,b:133,a:255},midnightblue:{r:25,g:25,b:112,a:255},mintcream:{r:245,g:255,b:250,a:255},mistyrose:{r:255,g:228,b:225,a:255},moccasin:{r:255,g:228,b:181,a:255},navajowhite:{r:255,g:222,b:173,a:255},oldlace:{r:253,g:245,b:230,a:255},olivedrab:{r:107,g:142,b:35,a:255},orangered:{r:255,g:69,b:0,a:255},palegoldenrod:{r:238,g:232,b:170,a:255},palegreen:{r:152,g:251,b:152,a:255},paleturquoise:{r:175,g:238,b:238,a:255},palevioletred:{r:219,g:112,b:147,a:255},papayawhip:{r:255,g:239,b:213,a:255},peachpuff:{r:255,g:218,b:185,a:255},peru:{r:205,g:133,b:63,a:255},powderblue:{r:176,g:224,b:230,a:255},rosybrown:{r:188,g:143,b:143,a:255},royalblue:{r:65,g:105,b:225,a:255},saddlebrown:{r:139,g:69,b:19,a:255},sandybrown:{r:244,g:164,b:96,a:255},seagreen:{r:46,g:139,b:87,a:255},seashell:{r:255,g:245,b:238,a:255},sienna:{r:160,g:82,b:45,a:255},skyblue:{r:135,g:206,b:235,a:255},slateblue:{r:106,g:90,b:205,a:255},springgreen:{r:0,g:255,b:127,a:255},steelblue:{r:70,g:130,b:180,a:255},thistle:{r:216,g:191,b:216,a:255},wheat:{r:245,g:222,b:179,a:255},yellowgreen:{r:154,g:205,b:50,a:255}};function _(r){if(!r)return{r:0,g:0,b:0,a:0};if(r=r.trim().toLowerCase(),Z[r])return{...Z[r]};if(r.startsWith("#"))return dr(r);if(r.startsWith("rgb"))return cr(r);if(r.startsWith("hsl"))return lr(r);return{r:0,g:0,b:0,a:0}}function dr(r){r=r.slice(1);let o,e,a,t=255;if(r.length===3)o=Number.parseInt(r[0]+r[0],16),e=Number.parseInt(r[1]+r[1],16),a=Number.parseInt(r[2]+r[2],16);else if(r.length===4)o=Number.parseInt(r[0]+r[0],16),e=Number.parseInt(r[1]+r[1],16),a=Number.parseInt(r[2]+r[2],16),t=Number.parseInt(r[3]+r[3],16);else if(r.length===6)o=Number.parseInt(r.slice(0,2),16),e=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16);else if(r.length===8)o=Number.parseInt(r.slice(0,2),16),e=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16),t=Number.parseInt(r.slice(6,8),16);else return{r:0,g:0,b:0,a:0};return{r:o,g:e,b:a,a:t}}function cr(r){let o=r.match(/rgba?\s*\(\s*([^)]+)\s*\)/);if(!o)return{r:0,g:0,b:0,a:0};let e=o[1].split(/[\s,/]+/).map((b)=>b.trim()).filter(Boolean),a=w(e[0],255),t=w(e[1],255),n=w(e[2],255),g=e[3]!==void 0?w(e[3],1)*255:255;return{r:Math.round(Math.min(255,Math.max(0,a))),g:Math.round(Math.min(255,Math.max(0,t))),b:Math.round(Math.min(255,Math.max(0,n))),a:Math.round(Math.min(255,Math.max(0,g)))}}function lr(r){let o=r.match(/hsla?\s*\(\s*([^)]+)\s*\)/);if(!o)return{r:0,g:0,b:0,a:0};let e=o[1].split(/[\s,/]+/).map((p)=>p.trim()).filter(Boolean),a=ur(e[0]),t=w(e[1],100)/100,n=w(e[2],100)/100,g=e[3]!==void 0?w(e[3],1):1,{r:b,g:s,b:l}=mr(a,t,n);return{r:Math.round(b),g:Math.round(s),b:Math.round(l),a:Math.round(g*255)}}function w(r,o){if(!r)return 0;if(r.endsWith("%"))return Number.parseFloat(r)/100*o;return Number.parseFloat(r)}function ur(r){if(!r)return 0;if(r=r.toLowerCase(),r.endsWith("deg"))return Number.parseFloat(r)/360;if(r.endsWith("rad"))return Number.parseFloat(r)/(2*Math.PI);if(r.endsWith("grad"))return Number.parseFloat(r)/400;if(r.endsWith("turn"))return Number.parseFloat(r);return Number.parseFloat(r)/360}function mr(r,o,e){let a,t,n;if(o===0)a=t=n=e*255;else{let g=(l,p,i)=>{if(i<0)i+=1;if(i>1)i-=1;if(i<0.16666666666666666)return l+(p-l)*6*i;if(i<0.5)return p;if(i<0.6666666666666666)return l+(p-l)*(0.6666666666666666-i)*6;return l},b=e<0.5?e*(1+o):e+o-e*o,s=2*e-b;a=g(s,b,r+0.3333333333333333)*255,t=g(s,b,r)*255,n=g(s,b,r-0.3333333333333333)*255}return{r:a,g:t,b:n}}function c(r,o=0,e=0){if(!r)return o;if(r=r.trim().toLowerCase(),r==="auto")return o;if(r.endsWith("px"))return Number.parseFloat(r);if(r.endsWith("%"))return Number.parseFloat(r)/100*e;if(r.endsWith("em"))return Number.parseFloat(r)*16;if(r.endsWith("rem"))return Number.parseFloat(r)*16;if(r.endsWith("vw"))return Number.parseFloat(r)/100*e;if(r.endsWith("vh"))return Number.parseFloat(r)/100*e;let a=Number.parseFloat(r);return Number.isNaN(a)?o:a}function I(r){if(!r)return[0,0,0,0];let e=r.trim().split(/\s+/).map((a)=>c(a,0));switch(e.length){case 1:return[e[0],e[0],e[0],e[0]];case 2:return[e[0],e[1],e[0],e[1]];case 3:return[e[0],e[1],e[2],e[1]];case 4:return[e[0],e[1],e[2],e[3]];default:return[0,0,0,0]}}function v(r){let o={};if(!r)return o;let e=r.split(";");for(let a of e){let[t,...n]=a.split(":");if(t&&n.length>0){let g=t.trim().toLowerCase(),b=n.join(":").trim();o[g]=b}}return o}function wi(r,o){let e=r.a/255,a=o.a/255,t=e+a*(1-e);if(t===0)return{r:0,g:0,b:0,a:0};return{r:Math.round((r.r*e+o.r*a*(1-e))/t),g:Math.round((r.g*e+o.g*a*(1-e))/t),b:Math.round((r.b*e+o.b*a*(1-e))/t),a:Math.round(t*255)}}var or={backgroundColor:{r:0,g:0,b:0,a:0},color:{r:0,g:0,b:0,a:255},borderTopWidth:0,borderRightWidth:0,borderBottomWidth:0,borderLeftWidth:0,borderTopColor:{r:0,g:0,b:0,a:255},borderRightColor:{r:0,g:0,b:0,a:255},borderBottomColor:{r:0,g:0,b:0,a:255},borderLeftColor:{r:0,g:0,b:0,a:255},borderRadius:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0,fontSize:16,fontWeight:"normal",fontFamily:"sans-serif",textAlign:"left",display:"block",position:"static",top:0,right:0,bottom:0,left:0,opacity:1,overflow:"visible",boxShadow:null},ar=new Set(["div","p","h1","h2","h3","h4","h5","h6","section","article","header","footer","main","nav","aside","ul","ol","li","dl","dt","dd","table","tr","th","td","thead","tbody","tfoot","form","fieldset","legend","blockquote","pre","address","hr","figure","figcaption"]);function pr(r){let o={tagName:"div",attributes:{},children:[]},e=[o],a=o,t=0,n=(g)=>g.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/&#(\d+);/g,(b,s)=>String.fromCharCode(Number.parseInt(s))).replace(/&#x([0-9a-f]+);/gi,(b,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/ /g," ");while(t<r.length){let g=r.indexOf("<",t);if(g>t||g===-1){let i=g===-1?r.length:g,u=n(r.slice(t,i).trim());if(u)a.children.push(u);if(g===-1)break;t=g}if(r.slice(t,t+4)==="<!--"){let i=r.indexOf("-->",t+4);t=i===-1?r.length:i+3;continue}if(r.slice(t,t+2).toLowerCase()==="<!"){let i=r.indexOf(">",t);t=i===-1?r.length:i+1;continue}let b=r.indexOf(">",t);if(b===-1)break;let s=r.slice(t+1,b),l=s.endsWith("/")||s.endsWith("/");if(s.startsWith("/")){let i=s.slice(1).trim().toLowerCase().split(/\s/)[0];while(e.length>1){let u=e.pop();if(a=e[e.length-1],u.tagName===i)break}}else{let i=s.search(/\s/),u=i===-1?s:s.slice(0,i);u=u.replace(/\/$/,"").toLowerCase();let h={};if(i!==-1){let W=s.slice(i).replace(/\/$/,""),d=/([a-z-]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi,f;while((f=d.exec(W))!==null){let z=f[1].toLowerCase(),G=f[2]??f[3]??f[4]??"";h[z]=n(G)}}let N={tagName:u,attributes:h,children:[]};if(a.children.push(N),!l&&!new Set(["br","hr","img","input","meta","link","area","base","col","embed","param","source","track","wbr"]).has(u))e.push(N),a=N}t=b+1}return o}function rr(r){let o=[];r=r.replace(/\/\*[\s\S]*?\*\//g,"");let e=/([^{}]+)\{([^}]*)\}/g,a;while((a=e.exec(r))!==null){let t=a[1].trim(),n={},b=a[2].split(";");for(let s of b){let l=s.indexOf(":");if(l!==-1){let p=s.slice(0,l).trim().toLowerCase(),i=s.slice(l+1).trim();if(p&&i)n[p]=i}}if(Object.keys(n).length>0)o.push({selector:t,properties:n})}return o}function hr(r,o){if(o=o.trim(),o==="*")return!0;if(/^[a-z][a-z0-9-]*$/i.test(o))return r.tagName===o.toLowerCase();if(o.startsWith(".")){let g=o.slice(1);return(r.attributes.class||"").split(/\s+/).includes(g)}if(o.startsWith("#")){let g=o.slice(1);return r.attributes.id===g}let e=o.match(/^([a-z][a-z0-9-]*)/i),a=o.match(/\.([a-z][a-z0-9-]*)/gi)||[],t=o.match(/#([a-z][a-z0-9-]*)/i),n=!0;if(e)n=n&&r.tagName===e[1].toLowerCase();if(t)n=n&&r.attributes.id===t[1];for(let g of a){let b=g.slice(1),s=(r.attributes.class||"").split(/\s+/);n=n&&s.includes(b)}return n}function tr(r,o,e,a){let t={...or};t.color={...e.color},t.fontSize=e.fontSize,t.fontFamily=e.fontFamily,t.fontWeight=e.fontWeight;for(let g of o){let b=g.selector.split(",").map((s)=>s.trim());for(let s of b)if(hr(r,s))er(t,g.properties,a)}let n=v(r.attributes.style);if(er(t,n,a),t.display==="block"&&!n.display)t.display=ar.has(r.tagName)?"block":"inline";return t}function er(r,o,e){for(let[a,t]of Object.entries(o))switch(a){case"background":case"background-color":r.backgroundColor=_(t);break;case"color":r.color=_(t);break;case"border":{let n=t.match(/(\d+(?:px)?)\s+(\w+)\s+(\S+)/);if(n){let g=c(n[1],0),b=_(n[3]);r.borderTopWidth=r.borderRightWidth=r.borderBottomWidth=r.borderLeftWidth=g,r.borderTopColor=r.borderRightColor=r.borderBottomColor=r.borderLeftColor={...b}}break}case"border-width":{let[n,g,b,s]=I(t);r.borderTopWidth=n,r.borderRightWidth=g,r.borderBottomWidth=b,r.borderLeftWidth=s;break}case"border-color":{let n=_(t);r.borderTopColor=r.borderRightColor=r.borderBottomColor=r.borderLeftColor={...n};break}case"border-top-width":r.borderTopWidth=c(t,0);break;case"border-right-width":r.borderRightWidth=c(t,0);break;case"border-bottom-width":r.borderBottomWidth=c(t,0);break;case"border-left-width":r.borderLeftWidth=c(t,0);break;case"border-top-color":r.borderTopColor=_(t);break;case"border-right-color":r.borderRightColor=_(t);break;case"border-bottom-color":r.borderBottomColor=_(t);break;case"border-left-color":r.borderLeftColor=_(t);break;case"border-radius":r.borderRadius=c(t,0);break;case"padding":{let[n,g,b,s]=I(t);r.paddingTop=n,r.paddingRight=g,r.paddingBottom=b,r.paddingLeft=s;break}case"padding-top":r.paddingTop=c(t,0,e);break;case"padding-right":r.paddingRight=c(t,0,e);break;case"padding-bottom":r.paddingBottom=c(t,0,e);break;case"padding-left":r.paddingLeft=c(t,0,e);break;case"margin":{let[n,g,b,s]=I(t);r.marginTop=n,r.marginRight=g,r.marginBottom=b,r.marginLeft=s;break}case"margin-top":r.marginTop=c(t,0,e);break;case"margin-right":r.marginRight=c(t,0,e);break;case"margin-bottom":r.marginBottom=c(t,0,e);break;case"margin-left":r.marginLeft=c(t,0,e);break;case"font-size":r.fontSize=c(t,16);break;case"font-weight":r.fontWeight=t;break;case"font-family":r.fontFamily=t.split(",")[0].trim().replace(/['"]/g,"");break;case"text-align":r.textAlign=t;break;case"display":r.display=t;break;case"position":r.position=t;break;case"top":r.top=c(t,0,e);break;case"right":r.right=c(t,0,e);break;case"bottom":r.bottom=c(t,0,e);break;case"left":r.left=c(t,0,e);break;case"opacity":r.opacity=Number.parseFloat(t)||1;break;case"overflow":r.overflow=t;break;case"width":break;case"height":break;case"box-shadow":r.boxShadow=t;break}}function ii(r,o,e,a){let t=pr(r),n=rr(o),g=(i)=>{let u="";if(i.tagName==="style"){for(let h of i.children)if(typeof h==="string")u+=h}for(let h of i.children)if(typeof h!=="string")u+=g(h);return u},b=g(t),s=[...n,...rr(b)];function l(i,u,h,N,S,W){let d=tr(i,s,u,S);if(d.display==="none")return{tagName:i.tagName,box:{x:0,y:0,width:0,height:0},styles:d,text:null,children:[],visible:!1};let{marginLeft:f,marginTop:z,marginRight:G,marginBottom:fr,borderLeftWidth:M,borderTopWidth:D,borderRightWidth:V,borderBottomWidth:nr,paddingLeft:T,paddingTop:Y,paddingRight:K,paddingBottom:ir}=d,U=null;if(i.attributes.style){let m=i.attributes.style.match(/width\s*:\s*(\S+)/);if(m)U=c(m[1],S,S)}let B=U??S-f-G-M-V-T-K,X=null;if(i.attributes.style){let m=i.attributes.style.match(/height\s*:\s*(\S+)/);if(m)X=c(m[1],0,W)}let E=h+f,P=N+z;if(d.position==="absolute"||d.position==="fixed"){if(d.left!==0)E=d.left;if(d.top!==0)P=d.top}let J=[],O=E+M+T,H=P+D+Y,A=0,L=0,C=0,x=0;for(let m of i.children){if(typeof m==="string")continue;let k=tr(m,s,d,B);if(k.display==="none")continue;let j=k.display==="block"||ar.has(m.tagName);if(j&&x>0)H+=C,L+=C,C=0,x=0,O=E+M+T;let R=l(m,d,O,H,j?B:B-x,W-L);if(J.push(R),R.visible)if(j){let y=R.box.height+k.marginTop+k.marginBottom;H+=y,L+=y,A=Math.max(A,R.box.width)}else{let y=R.box.width+k.marginLeft+k.marginRight;x+=y,O+=y,C=Math.max(C,R.box.height+k.marginTop+k.marginBottom),A=Math.max(A,x)}}if(C>0)L+=C;let F=null,q=[];for(let m of i.children)if(typeof m==="string")q.push(m);if(q.length>0)F=q.join(" ");let Q=0;if(F)Q=(Math.ceil(F.length*d.fontSize*0.6/B)||1)*d.fontSize*1.2;let gr=Math.max(L,Q,X??0),sr=M+T+B+K+V,br=D+Y+gr+ir+nr;return{tagName:i.tagName,box:{x:E,y:P,width:sr,height:br},styles:d,text:F,children:J,visible:!0}}let p={...or,backgroundColor:{r:255,g:255,b:255,a:255}};return l(t,p,0,0,e,a)}
|
|
3
|
-
export{
|
|
2
|
+
var Z={transparent:{r:0,g:0,b:0,a:0},black:{r:0,g:0,b:0,a:255},white:{r:255,g:255,b:255,a:255},red:{r:255,g:0,b:0,a:255},green:{r:0,g:128,b:0,a:255},blue:{r:0,g:0,b:255,a:255},yellow:{r:255,g:255,b:0,a:255},cyan:{r:0,g:255,b:255,a:255},magenta:{r:255,g:0,b:255,a:255},gray:{r:128,g:128,b:128,a:255},grey:{r:128,g:128,b:128,a:255},silver:{r:192,g:192,b:192,a:255},maroon:{r:128,g:0,b:0,a:255},olive:{r:128,g:128,b:0,a:255},lime:{r:0,g:255,b:0,a:255},aqua:{r:0,g:255,b:255,a:255},teal:{r:0,g:128,b:128,a:255},navy:{r:0,g:0,b:128,a:255},fuchsia:{r:255,g:0,b:255,a:255},purple:{r:128,g:0,b:128,a:255},orange:{r:255,g:165,b:0,a:255},pink:{r:255,g:192,b:203,a:255},brown:{r:165,g:42,b:42,a:255},gold:{r:255,g:215,b:0,a:255},indigo:{r:75,g:0,b:130,a:255},violet:{r:238,g:130,b:238,a:255},coral:{r:255,g:127,b:80,a:255},salmon:{r:250,g:128,b:114,a:255},khaki:{r:240,g:230,b:140,a:255},plum:{r:221,g:160,b:221,a:255},orchid:{r:218,g:112,b:214,a:255},turquoise:{r:64,g:224,b:208,a:255},tan:{r:210,g:180,b:140,a:255},chocolate:{r:210,g:105,b:30,a:255},tomato:{r:255,g:99,b:71,a:255},crimson:{r:220,g:20,b:60,a:255},darkblue:{r:0,g:0,b:139,a:255},darkgreen:{r:0,g:100,b:0,a:255},darkred:{r:139,g:0,b:0,a:255},darkorange:{r:255,g:140,b:0,a:255},lightblue:{r:173,g:216,b:230,a:255},lightgreen:{r:144,g:238,b:144,a:255},lightgray:{r:211,g:211,b:211,a:255},lightgrey:{r:211,g:211,b:211,a:255},lightpink:{r:255,g:182,b:193,a:255},lightyellow:{r:255,g:255,b:224,a:255},darkgray:{r:169,g:169,b:169,a:255},darkgrey:{r:169,g:169,b:169,a:255},slategray:{r:112,g:128,b:144,a:255},slategrey:{r:112,g:128,b:144,a:255},dimgray:{r:105,g:105,b:105,a:255},dimgrey:{r:105,g:105,b:105,a:255},whitesmoke:{r:245,g:245,b:245,a:255},snow:{r:255,g:250,b:250,a:255},ivory:{r:255,g:255,b:240,a:255},beige:{r:245,g:245,b:220,a:255},linen:{r:250,g:240,b:230,a:255},aliceblue:{r:240,g:248,b:255,a:255},antiquewhite:{r:250,g:235,b:215,a:255},azure:{r:240,g:255,b:255,a:255},bisque:{r:255,g:228,b:196,a:255},blanchedalmond:{r:255,g:235,b:205,a:255},burlywood:{r:222,g:184,b:135,a:255},cadetblue:{r:95,g:158,b:160,a:255},chartreuse:{r:127,g:255,b:0,a:255},cornflowerblue:{r:100,g:149,b:237,a:255},cornsilk:{r:255,g:248,b:220,a:255},deeppink:{r:255,g:20,b:147,a:255},deepskyblue:{r:0,g:191,b:255,a:255},dodgerblue:{r:30,g:144,b:255,a:255},firebrick:{r:178,g:34,b:34,a:255},floralwhite:{r:255,g:250,b:240,a:255},forestgreen:{r:34,g:139,b:34,a:255},gainsboro:{r:220,g:220,b:220,a:255},ghostwhite:{r:248,g:248,b:255,a:255},greenyellow:{r:173,g:255,b:47,a:255},honeydew:{r:240,g:255,b:240,a:255},hotpink:{r:255,g:105,b:180,a:255},indianred:{r:205,g:92,b:92,a:255},lavender:{r:230,g:230,b:250,a:255},lavenderblush:{r:255,g:240,b:245,a:255},lawngreen:{r:124,g:252,b:0,a:255},lemonchiffon:{r:255,g:250,b:205,a:255},lightcoral:{r:240,g:128,b:128,a:255},lightcyan:{r:224,g:255,b:255,a:255},lightgoldenrodyellow:{r:250,g:250,b:210,a:255},lightsalmon:{r:255,g:160,b:122,a:255},lightseagreen:{r:32,g:178,b:170,a:255},lightskyblue:{r:135,g:206,b:250,a:255},lightslategray:{r:119,g:136,b:153,a:255},lightslategrey:{r:119,g:136,b:153,a:255},lightsteelblue:{r:176,g:196,b:222,a:255},limegreen:{r:50,g:205,b:50,a:255},mediumaquamarine:{r:102,g:205,b:170,a:255},mediumblue:{r:0,g:0,b:205,a:255},mediumorchid:{r:186,g:85,b:211,a:255},mediumpurple:{r:147,g:112,b:219,a:255},mediumseagreen:{r:60,g:179,b:113,a:255},mediumslateblue:{r:123,g:104,b:238,a:255},mediumspringgreen:{r:0,g:250,b:154,a:255},mediumturquoise:{r:72,g:209,b:204,a:255},mediumvioletred:{r:199,g:21,b:133,a:255},midnightblue:{r:25,g:25,b:112,a:255},mintcream:{r:245,g:255,b:250,a:255},mistyrose:{r:255,g:228,b:225,a:255},moccasin:{r:255,g:228,b:181,a:255},navajowhite:{r:255,g:222,b:173,a:255},oldlace:{r:253,g:245,b:230,a:255},olivedrab:{r:107,g:142,b:35,a:255},orangered:{r:255,g:69,b:0,a:255},palegoldenrod:{r:238,g:232,b:170,a:255},palegreen:{r:152,g:251,b:152,a:255},paleturquoise:{r:175,g:238,b:238,a:255},palevioletred:{r:219,g:112,b:147,a:255},papayawhip:{r:255,g:239,b:213,a:255},peachpuff:{r:255,g:218,b:185,a:255},peru:{r:205,g:133,b:63,a:255},powderblue:{r:176,g:224,b:230,a:255},rosybrown:{r:188,g:143,b:143,a:255},royalblue:{r:65,g:105,b:225,a:255},saddlebrown:{r:139,g:69,b:19,a:255},sandybrown:{r:244,g:164,b:96,a:255},seagreen:{r:46,g:139,b:87,a:255},seashell:{r:255,g:245,b:238,a:255},sienna:{r:160,g:82,b:45,a:255},skyblue:{r:135,g:206,b:235,a:255},slateblue:{r:106,g:90,b:205,a:255},springgreen:{r:0,g:255,b:127,a:255},steelblue:{r:70,g:130,b:180,a:255},thistle:{r:216,g:191,b:216,a:255},wheat:{r:245,g:222,b:179,a:255},yellowgreen:{r:154,g:205,b:50,a:255}};function S(r){if(!r)return{r:0,g:0,b:0,a:0};if(r=r.trim().toLowerCase(),Z[r])return{...Z[r]};if(r.startsWith("#"))return dr(r);if(r.startsWith("rgb"))return cr(r);if(r.startsWith("hsl"))return lr(r);return{r:0,g:0,b:0,a:0}}function dr(r){r=r.slice(1);let o,e,a,t=255;if(r.length===3)o=Number.parseInt(r[0]+r[0],16),e=Number.parseInt(r[1]+r[1],16),a=Number.parseInt(r[2]+r[2],16);else if(r.length===4)o=Number.parseInt(r[0]+r[0],16),e=Number.parseInt(r[1]+r[1],16),a=Number.parseInt(r[2]+r[2],16),t=Number.parseInt(r[3]+r[3],16);else if(r.length===6)o=Number.parseInt(r.slice(0,2),16),e=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16);else if(r.length===8)o=Number.parseInt(r.slice(0,2),16),e=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16),t=Number.parseInt(r.slice(6,8),16);else return{r:0,g:0,b:0,a:0};return{r:o,g:e,b:a,a:t}}function cr(r){let o=r.match(/rgba?\s*\(\s*([^)]+)\s*\)/);if(!o)return{r:0,g:0,b:0,a:0};let e=o[1].split(/[\s,/]+/).map((b)=>b.trim()).filter(Boolean),a=w(e[0],255),t=w(e[1],255),n=w(e[2],255),g=e[3]!==void 0?w(e[3],1)*255:255;return{r:Math.round(Math.min(255,Math.max(0,a))),g:Math.round(Math.min(255,Math.max(0,t))),b:Math.round(Math.min(255,Math.max(0,n))),a:Math.round(Math.min(255,Math.max(0,g)))}}function lr(r){let o=r.match(/hsla?\s*\(\s*([^)]+)\s*\)/);if(!o)return{r:0,g:0,b:0,a:0};let e=o[1].split(/[\s,/]+/).map((p)=>p.trim()).filter(Boolean),a=ur(e[0]),t=w(e[1],100)/100,n=w(e[2],100)/100,g=e[3]!==void 0?w(e[3],1):1,{r:b,g:s,b:l}=mr(a,t,n);return{r:Math.round(b),g:Math.round(s),b:Math.round(l),a:Math.round(g*255)}}function w(r,o){if(!r)return 0;if(r.endsWith("%"))return Number.parseFloat(r)/100*o;return Number.parseFloat(r)}function ur(r){if(!r)return 0;if(r=r.toLowerCase(),r.endsWith("deg"))return Number.parseFloat(r)/360;if(r.endsWith("rad"))return Number.parseFloat(r)/(2*Math.PI);if(r.endsWith("grad"))return Number.parseFloat(r)/400;if(r.endsWith("turn"))return Number.parseFloat(r);return Number.parseFloat(r)/360}function mr(r,o,e){let a,t,n;if(o===0)a=t=n=e*255;else{let g=(l,p,i)=>{if(i<0)i+=1;if(i>1)i-=1;if(i<0.16666666666666666)return l+(p-l)*6*i;if(i<0.5)return p;if(i<0.6666666666666666)return l+(p-l)*(0.6666666666666666-i)*6;return l},b=e<0.5?e*(1+o):e+o-e*o,s=2*e-b;a=g(s,b,r+0.3333333333333333)*255,t=g(s,b,r)*255,n=g(s,b,r-0.3333333333333333)*255}return{r:a,g:t,b:n}}function c(r,o=0,e=0){if(!r)return o;if(r=r.trim().toLowerCase(),r==="auto")return o;if(r.endsWith("px"))return Number.parseFloat(r);if(r.endsWith("%"))return Number.parseFloat(r)/100*e;if(r.endsWith("em"))return Number.parseFloat(r)*16;if(r.endsWith("rem"))return Number.parseFloat(r)*16;if(r.endsWith("vw"))return Number.parseFloat(r)/100*e;if(r.endsWith("vh"))return Number.parseFloat(r)/100*e;let a=Number.parseFloat(r);return Number.isNaN(a)?o:a}function z(r){if(!r)return[0,0,0,0];let e=r.trim().split(/\s+/).map((a)=>c(a,0));switch(e.length){case 1:return[e[0],e[0],e[0],e[0]];case 2:return[e[0],e[1],e[0],e[1]];case 3:return[e[0],e[1],e[2],e[1]];case 4:return[e[0],e[1],e[2],e[3]];default:return[0,0,0,0]}}function v(r){let o={};if(!r)return o;let e=r.split(";");for(let a of e){let[t,...n]=a.split(":");if(t&&n.length>0){let g=t.trim().toLowerCase(),b=n.join(":").trim();o[g]=b}}return o}function Pi(r,o){let e=r.a/255,a=o.a/255,t=e+a*(1-e);if(t===0)return{r:0,g:0,b:0,a:0};return{r:Math.round((r.r*e+o.r*a*(1-e))/t),g:Math.round((r.g*e+o.g*a*(1-e))/t),b:Math.round((r.b*e+o.b*a*(1-e))/t),a:Math.round(t*255)}}var or={backgroundColor:{r:0,g:0,b:0,a:0},color:{r:0,g:0,b:0,a:255},borderTopWidth:0,borderRightWidth:0,borderBottomWidth:0,borderLeftWidth:0,borderTopColor:{r:0,g:0,b:0,a:255},borderRightColor:{r:0,g:0,b:0,a:255},borderBottomColor:{r:0,g:0,b:0,a:255},borderLeftColor:{r:0,g:0,b:0,a:255},borderRadius:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0,fontSize:16,fontWeight:"normal",fontFamily:"sans-serif",textAlign:"left",display:"block",position:"static",top:0,right:0,bottom:0,left:0,opacity:1,overflow:"visible",boxShadow:null},ar=new Set(["div","p","h1","h2","h3","h4","h5","h6","section","article","header","footer","main","nav","aside","ul","ol","li","dl","dt","dd","table","tr","th","td","thead","tbody","tfoot","form","fieldset","legend","blockquote","pre","address","hr","figure","figcaption"]);function pr(r){let o={tagName:"div",attributes:{},children:[]},e=[o],a=o,t=0,n=(g)=>g.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/&#(\d+);/g,(b,s)=>String.fromCharCode(Number.parseInt(s))).replace(/&#x([0-9a-f]+);/gi,(b,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/ /g," ");while(t<r.length){let g=r.indexOf("<",t);if(g>t||g===-1){let i=g===-1?r.length:g,u=n(r.slice(t,i).trim());if(u)a.children.push(u);if(g===-1)break;t=g}if(r.slice(t,t+4)==="<!--"){let i=r.indexOf("-->",t+4);t=i===-1?r.length:i+3;continue}if(r.slice(t,t+2).toLowerCase()==="<!"){let i=r.indexOf(">",t);t=i===-1?r.length:i+1;continue}let b=r.indexOf(">",t);if(b===-1)break;let s=r.slice(t+1,b),l=s.endsWith("/")||s.endsWith("/");if(s.startsWith("/")){let i=s.slice(1).trim().toLowerCase().split(/\s/)[0];while(e.length>1){let u=e.pop();if(a=e[e.length-1],u.tagName===i)break}}else{let i=s.search(/\s/),u=i===-1?s:s.slice(0,i);u=u.replace(/\/$/,"").toLowerCase();let h={};if(i!==-1){let M=s.slice(i).replace(/\/$/,""),d=/([a-z-]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi,f;while((f=d.exec(M))!==null){let G=f[1].toLowerCase(),P=f[2]??f[3]??f[4]??"";h[G]=n(P)}}let N={tagName:u,attributes:h,children:[]};if(a.children.push(N),!l&&!new Set(["br","hr","img","input","meta","link","area","base","col","embed","param","source","track","wbr"]).has(u))e.push(N),a=N}t=b+1}return o}function rr(r){let o=[];r=r.replace(/\/\*[\s\S]*?\*\//g,"");let e=/([^{}]+)\{([^}]*)\}/g,a;while((a=e.exec(r))!==null){let t=a[1].trim(),n={},b=a[2].split(";");for(let s of b){let l=s.indexOf(":");if(l!==-1){let p=s.slice(0,l).trim().toLowerCase(),i=s.slice(l+1).trim();if(p&&i)n[p]=i}}if(Object.keys(n).length>0)o.push({selector:t,properties:n})}return o}function hr(r,o){if(o=o.trim(),o==="*")return!0;if(/^[a-z][a-z0-9-]*$/i.test(o))return r.tagName===o.toLowerCase();if(o.startsWith(".")){let g=o.slice(1);return(r.attributes.class||"").split(/\s+/).includes(g)}if(o.startsWith("#")){let g=o.slice(1);return r.attributes.id===g}let e=o.match(/^([a-z][a-z0-9-]*)/i),a=o.match(/\.([a-z][a-z0-9-]*)/gi)||[],t=o.match(/#([a-z][a-z0-9-]*)/i),n=!0;if(e)n=n&&r.tagName===e[1].toLowerCase();if(t)n=n&&r.attributes.id===t[1];for(let g of a){let b=g.slice(1),s=(r.attributes.class||"").split(/\s+/);n=n&&s.includes(b)}return n}function tr(r,o,e,a){let t={...or};t.color={...e.color},t.fontSize=e.fontSize,t.fontFamily=e.fontFamily,t.fontWeight=e.fontWeight;for(let g of o){let b=g.selector.split(",").map((s)=>s.trim());for(let s of b)if(hr(r,s))er(t,g.properties,a)}let n=v(r.attributes.style);if(er(t,n,a),t.display==="block"&&!n.display)t.display=ar.has(r.tagName)?"block":"inline";return t}function er(r,o,e){for(let[a,t]of Object.entries(o))switch(a){case"background":case"background-color":r.backgroundColor=S(t);break;case"color":r.color=S(t);break;case"border":{let n=t.match(/(\d+(?:px)?)\s+(\w+)\s+(\S+)/);if(n){let g=c(n[1],0),b=S(n[3]);r.borderTopWidth=r.borderRightWidth=r.borderBottomWidth=r.borderLeftWidth=g,r.borderTopColor=r.borderRightColor=r.borderBottomColor=r.borderLeftColor={...b}}break}case"border-width":{let[n,g,b,s]=z(t);r.borderTopWidth=n,r.borderRightWidth=g,r.borderBottomWidth=b,r.borderLeftWidth=s;break}case"border-color":{let n=S(t);r.borderTopColor=r.borderRightColor=r.borderBottomColor=r.borderLeftColor={...n};break}case"border-top-width":r.borderTopWidth=c(t,0);break;case"border-right-width":r.borderRightWidth=c(t,0);break;case"border-bottom-width":r.borderBottomWidth=c(t,0);break;case"border-left-width":r.borderLeftWidth=c(t,0);break;case"border-top-color":r.borderTopColor=S(t);break;case"border-right-color":r.borderRightColor=S(t);break;case"border-bottom-color":r.borderBottomColor=S(t);break;case"border-left-color":r.borderLeftColor=S(t);break;case"border-radius":r.borderRadius=c(t,0);break;case"padding":{let[n,g,b,s]=z(t);r.paddingTop=n,r.paddingRight=g,r.paddingBottom=b,r.paddingLeft=s;break}case"padding-top":r.paddingTop=c(t,0,e);break;case"padding-right":r.paddingRight=c(t,0,e);break;case"padding-bottom":r.paddingBottom=c(t,0,e);break;case"padding-left":r.paddingLeft=c(t,0,e);break;case"margin":{let[n,g,b,s]=z(t);r.marginTop=n,r.marginRight=g,r.marginBottom=b,r.marginLeft=s;break}case"margin-top":r.marginTop=c(t,0,e);break;case"margin-right":r.marginRight=c(t,0,e);break;case"margin-bottom":r.marginBottom=c(t,0,e);break;case"margin-left":r.marginLeft=c(t,0,e);break;case"font-size":r.fontSize=c(t,16);break;case"font-weight":r.fontWeight=t;break;case"font-family":r.fontFamily=t.split(",")[0].trim().replace(/['"]/g,"");break;case"text-align":r.textAlign=t;break;case"display":r.display=t;break;case"position":r.position=t;break;case"top":r.top=c(t,0,e);break;case"right":r.right=c(t,0,e);break;case"bottom":r.bottom=c(t,0,e);break;case"left":r.left=c(t,0,e);break;case"opacity":r.opacity=Number.parseFloat(t)||1;break;case"overflow":r.overflow=t;break;case"width":break;case"height":break;case"box-shadow":r.boxShadow=t;break}}function hi(r,o,e,a){let t=pr(r),n=rr(o),g=(i)=>{let u="";if(i.tagName==="style"){for(let h of i.children)if(typeof h==="string")u+=h}for(let h of i.children)if(typeof h!=="string")u+=g(h);return u},b=g(t),s=[...n,...rr(b)];function l(i,u,h,N,B,M){let d=tr(i,s,u,B);if(d.display==="none")return{tagName:i.tagName,box:{x:0,y:0,width:0,height:0},styles:d,text:null,children:[],visible:!1};let{marginLeft:f,marginTop:G,marginRight:P,marginBottom:fr,borderLeftWidth:T,borderTopWidth:D,borderRightWidth:V,borderBottomWidth:nr,paddingLeft:E,paddingTop:Y,paddingRight:K,paddingBottom:ir}=d,U=null;if(i.attributes.style){let m=i.attributes.style.match(/width\s*:\s*(\S+)/);if(m)U=c(m[1],B,B)}let L=U??B-f-P-T-V-E-K,X=null;if(i.attributes.style){let m=i.attributes.style.match(/height\s*:\s*(\S+)/);if(m)X=c(m[1],0,M)}let A=h+f,O=N+G;if(d.position==="absolute"||d.position==="fixed"){if(d.left!==0)A=d.left;if(d.top!==0)O=d.top}let J=[],H=A+T+E,q=O+D+Y,F=0,x=0,C=0,y=0;for(let m of i.children){if(typeof m==="string")continue;let k=tr(m,s,d,L);if(k.display==="none")continue;let _=k.display==="block"||ar.has(m.tagName);if(_&&y>0)q+=C,x+=C,C=0,y=0,H=A+T+E;let R=l(m,d,H,q,_?L:L-y,M-x);if(J.push(R),R.visible)if(_){let W=R.box.height+k.marginTop+k.marginBottom;q+=W,x+=W,F=Math.max(F,R.box.width)}else{let W=R.box.width+k.marginLeft+k.marginRight;y+=W,H+=W,C=Math.max(C,R.box.height+k.marginTop+k.marginBottom),F=Math.max(F,y)}}if(C>0)x+=C;let I=null,j=[];for(let m of i.children)if(typeof m==="string")j.push(m);if(j.length>0)I=j.join(" ");let Q=0;if(I)Q=(Math.ceil(I.length*d.fontSize*0.6/L)||1)*d.fontSize*1.2;let gr=Math.max(x,Q,X??0),sr=T+E+L+K+V,br=D+Y+gr+ir+nr;return{tagName:i.tagName,box:{x:A,y:O,width:sr,height:br},styles:d,text:I,children:J,visible:!0}}let p={...or,backgroundColor:{r:255,g:255,b:255,a:255}};return l(t,p,0,0,e,a)}
|
|
3
|
+
export{S,Pi,hi};
|