@luci-dev/capture 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/dist/a11y.d.ts +54 -0
- package/dist/a11y.d.ts.map +1 -0
- package/dist/a11y.js +144 -0
- package/dist/a11y.js.map +1 -0
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +4 -0
- package/dist/browser.js.map +1 -0
- package/dist/color.d.ts +44 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +230 -0
- package/dist/color.js.map +1 -0
- package/dist/component.d.ts +94 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +445 -0
- package/dist/component.js.map +1 -0
- package/dist/dom.d.ts +36 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +365 -0
- package/dist/dom.js.map +1 -0
- package/dist/eligibility.d.ts +24 -0
- package/dist/eligibility.d.ts.map +1 -0
- package/dist/eligibility.js +33 -0
- package/dist/eligibility.js.map +1 -0
- package/dist/font.d.ts +18 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +86 -0
- package/dist/font.js.map +1 -0
- package/dist/icon.d.ts +11 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +221 -0
- package/dist/icon.js.map +1 -0
- package/dist/image.d.ts +82 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +283 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +9 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +115 -0
- package/dist/layout.js.map +1 -0
- package/dist/luci-capture.js +35510 -0
- package/dist/model.d.ts +60 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +43 -0
- package/dist/model.js.map +1 -0
- package/dist/naming.d.ts +8 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +33 -0
- package/dist/naming.js.map +1 -0
- package/dist/page.d.ts +38 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +102 -0
- package/dist/page.js.map +1 -0
- package/dist/realm.d.ts +17 -0
- package/dist/realm.d.ts.map +1 -0
- package/dist/realm.js +18 -0
- package/dist/realm.js.map +1 -0
- package/dist/responsive.d.ts +74 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +237 -0
- package/dist/responsive.js.map +1 -0
- package/dist/section.d.ts +50 -0
- package/dist/section.d.ts.map +1 -0
- package/dist/section.js +244 -0
- package/dist/section.js.map +1 -0
- package/dist/spacing.d.ts +43 -0
- package/dist/spacing.d.ts.map +1 -0
- package/dist/spacing.js +113 -0
- package/dist/spacing.js.map +1 -0
- package/dist/stack.d.ts +11 -0
- package/dist/stack.d.ts.map +1 -0
- package/dist/stack.js +150 -0
- package/dist/stack.js.map +1 -0
- package/dist/states.d.ts +89 -0
- package/dist/states.d.ts.map +1 -0
- package/dist/states.js +457 -0
- package/dist/states.js.map +1 -0
- package/dist/text.d.ts +30 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +156 -0
- package/dist/text.js.map +1 -0
- package/dist/ui/basket.d.ts +50 -0
- package/dist/ui/basket.d.ts.map +1 -0
- package/dist/ui/basket.js +93 -0
- package/dist/ui/basket.js.map +1 -0
- package/dist/ui/check.d.ts +43 -0
- package/dist/ui/check.d.ts.map +1 -0
- package/dist/ui/check.js +168 -0
- package/dist/ui/check.js.map +1 -0
- package/dist/ui/devSettings.d.ts +66 -0
- package/dist/ui/devSettings.d.ts.map +1 -0
- package/dist/ui/devSettings.js +115 -0
- package/dist/ui/devSettings.js.map +1 -0
- package/dist/ui/index.d.ts +14 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +14 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/loading.d.ts +18 -0
- package/dist/ui/loading.d.ts.map +1 -0
- package/dist/ui/loading.js +23 -0
- package/dist/ui/loading.js.map +1 -0
- package/dist/ui/modeSwitch.d.ts +17 -0
- package/dist/ui/modeSwitch.d.ts.map +1 -0
- package/dist/ui/modeSwitch.js +6 -0
- package/dist/ui/modeSwitch.js.map +1 -0
- package/dist/ui/mount.d.ts +83 -0
- package/dist/ui/mount.d.ts.map +1 -0
- package/dist/ui/mount.js +81 -0
- package/dist/ui/mount.js.map +1 -0
- package/dist/ui/picker.d.ts +22 -0
- package/dist/ui/picker.d.ts.map +1 -0
- package/dist/ui/picker.js +73 -0
- package/dist/ui/picker.js.map +1 -0
- package/dist/ui/remap.d.ts +27 -0
- package/dist/ui/remap.d.ts.map +1 -0
- package/dist/ui/remap.js +76 -0
- package/dist/ui/remap.js.map +1 -0
- package/dist/ui/screenshot.d.ts +39 -0
- package/dist/ui/screenshot.d.ts.map +1 -0
- package/dist/ui/screenshot.js +59 -0
- package/dist/ui/screenshot.js.map +1 -0
- package/dist/ui/styles.d.ts +2 -0
- package/dist/ui/styles.d.ts.map +1 -0
- package/dist/ui/styles.js +381 -0
- package/dist/ui/styles.js.map +1 -0
- package/dist/ui/theme.d.ts +59 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +93 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/ui/toolbar.d.ts +101 -0
- package/dist/ui/toolbar.d.ts.map +1 -0
- package/dist/ui/toolbar.js +1494 -0
- package/dist/ui/toolbar.js.map +1 -0
- package/dist/ui/tools.d.ts +165 -0
- package/dist/ui/tools.d.ts.map +1 -0
- package/dist/ui/tools.js +345 -0
- package/dist/ui/tools.js.map +1 -0
- package/dist/ui/zip.d.ts +16 -0
- package/dist/ui/zip.d.ts.map +1 -0
- package/dist/ui/zip.js +104 -0
- package/dist/ui/zip.js.map +1 -0
- package/package.json +29 -3
- package/README.md +0 -3
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page snapshot every capture tool works on. The DOM reader (dom.ts) builds it from the
|
|
3
|
+
* live page; the analysis (text.ts, color.ts, spacing.ts) only reads it, so it is plain data,
|
|
4
|
+
* easy to test and identical in both toolbar shells.
|
|
5
|
+
*/
|
|
6
|
+
/** Computed style properties the tools read. */
|
|
7
|
+
export declare const SNAPSHOT_PROPERTIES: readonly ['display', 'visibility', 'opacity', 'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'font-style', 'text-transform', 'text-decoration-line', 'color', 'background-color', 'background-image', 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width', 'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'outline-width', 'outline-style', 'outline-color', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', 'gap', 'row-gap', 'column-gap', 'fill', 'stroke', 'stroke-width', 'width', 'height', 'flex-direction', 'align-items', 'justify-content', 'border-radius', 'box-shadow', 'cursor', 'outline-offset', 'text-align', 'transform', 'transition-property', 'transition-duration', 'transition-timing-function', 'transition-delay', 'animation-name', 'animation-duration', 'animation-timing-function', 'animation-iteration-count', 'grid-template-columns', 'flex-wrap', 'max-width', 'align-self', 'justify-self', 'justify-items', 'align-content', 'flex-grow', 'flex-shrink', 'flex-basis', 'grid-template-rows', 'grid-auto-flow', 'grid-column', 'grid-row', 'order'];
|
|
8
|
+
export type SnapshotProperty = (typeof SNAPSHOT_PROPERTIES)[number];
|
|
9
|
+
export interface Rect {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ElementSnapshot {
|
|
16
|
+
/** Index in the snapshot. */
|
|
17
|
+
id: number;
|
|
18
|
+
/** Lowercase tag name. */
|
|
19
|
+
tag: string;
|
|
20
|
+
/** Explicit or implicit ARIA role, if any. */
|
|
21
|
+
role: string | null;
|
|
22
|
+
/** A selector that finds this element (structure, not hashed classes, where possible). */
|
|
23
|
+
selector: string;
|
|
24
|
+
rect: Rect;
|
|
25
|
+
/** Rendered and not hidden (visibility, display, zero size, zero opacity). */
|
|
26
|
+
visible: boolean;
|
|
27
|
+
/** Has its own non-whitespace text (not only through children). */
|
|
28
|
+
hasText: boolean;
|
|
29
|
+
/** Inside a shadow root. */
|
|
30
|
+
inShadow: boolean;
|
|
31
|
+
/** The id of the element around it (a shadow root's host for its top elements); absent for the root. */
|
|
32
|
+
parent?: number;
|
|
33
|
+
styles: Partial<Record<SnapshotProperty, string>>;
|
|
34
|
+
/** What the site wrote, for properties where it is known and differs: "var(--space-4)", "clamp(...)". */
|
|
35
|
+
authored: Partial<Record<SnapshotProperty, string>>;
|
|
36
|
+
/** Properties whose value is only the browser's default for this tag (e.g. a paragraph's 1em margin). */
|
|
37
|
+
browserDefault?: Partial<Record<SnapshotProperty, true>>;
|
|
38
|
+
/** Properties a stylesheet rule or inline style sets on this element itself (not inherited). */
|
|
39
|
+
declared?: Partial<Record<SnapshotProperty, true>>;
|
|
40
|
+
}
|
|
41
|
+
export interface PageSnapshot {
|
|
42
|
+
/** The page URL (the format drops the query and fragment). */
|
|
43
|
+
url: string;
|
|
44
|
+
/** Computed font size of the root element, in px. */
|
|
45
|
+
rootFontSize: number;
|
|
46
|
+
/** Custom properties defined on :root, resolved: { "--color-primary": "#0f62fe" }. */
|
|
47
|
+
customProperties: Record<string, string>;
|
|
48
|
+
elements: ElementSnapshot[];
|
|
49
|
+
/** False when a stylesheet could not be read (cross-origin), so "declared" may miss rules. */
|
|
50
|
+
stylesReadable?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** The custom property an authored value goes through: "var(--space-4, 16px)" -> "--space-4". */
|
|
53
|
+
export declare function tokenOf(authored: string | undefined): string | undefined;
|
|
54
|
+
/** A captured value from a snapshot property: computed, plus authored and token when known. */
|
|
55
|
+
export declare function valueOf(el: ElementSnapshot, prop: SnapshotProperty): {
|
|
56
|
+
computed: string;
|
|
57
|
+
authored?: string;
|
|
58
|
+
token?: string;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,YAC9B,SAAS,EAAE,YAAY,EAAE,SAAS,EAClC,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,OAAO,EAC3I,kBAAkB,EAAE,kBAAkB,EACtC,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EACpF,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EACpF,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EACpF,eAAe,EAAE,eAAe,EAAE,eAAe,EACjD,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAChE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAC5D,KAAK,EAAE,SAAS,EAAE,YAAY,EAC9B,MAAM,EAAE,QAAQ,EAAE,cAAc,EAEhC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EACrE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EACpF,qBAAqB,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,kBAAkB,EAC9F,gBAAgB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,2BAA2B,EAEhG,uBAAuB,EAAE,WAAW,EAAE,WAAW,EAEjD,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAC9D,WAAW,EAAE,aAAa,EAAE,YAAY,EACxC,oB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C;IACrB,sFAAsF;IACtF,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,iGAAiG;AACjG,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxE;AAED,+FAA+F;AAC/F,wBAAgB,OAAO,CAAC,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAK5H"}
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page snapshot every capture tool works on. The DOM reader (dom.ts) builds it from the
|
|
3
|
+
* live page; the analysis (text.ts, color.ts, spacing.ts) only reads it, so it is plain data,
|
|
4
|
+
* easy to test and identical in both toolbar shells.
|
|
5
|
+
*/
|
|
6
|
+
/** Computed style properties the tools read. */
|
|
7
|
+
export const SNAPSHOT_PROPERTIES = [
|
|
8
|
+
'display', 'visibility', 'opacity',
|
|
9
|
+
'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'font-style', 'text-transform', 'text-decoration-line', 'color',
|
|
10
|
+
'background-color', 'background-image',
|
|
11
|
+
'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width',
|
|
12
|
+
'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style',
|
|
13
|
+
'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color',
|
|
14
|
+
'outline-width', 'outline-style', 'outline-color',
|
|
15
|
+
'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
|
|
16
|
+
'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
|
|
17
|
+
'gap', 'row-gap', 'column-gap',
|
|
18
|
+
'fill', 'stroke', 'stroke-width',
|
|
19
|
+
// The Component tool (M5) also reads these
|
|
20
|
+
'width', 'height', 'flex-direction', 'align-items', 'justify-content',
|
|
21
|
+
'border-radius', 'box-shadow', 'cursor', 'outline-offset', 'text-align', 'transform',
|
|
22
|
+
'transition-property', 'transition-duration', 'transition-timing-function', 'transition-delay',
|
|
23
|
+
'animation-name', 'animation-duration', 'animation-timing-function', 'animation-iteration-count',
|
|
24
|
+
// Sections (v0.2) also read these
|
|
25
|
+
'grid-template-columns', 'flex-wrap', 'max-width',
|
|
26
|
+
// Computed layout tree (v0.4.3)
|
|
27
|
+
'align-self', 'justify-self', 'justify-items', 'align-content',
|
|
28
|
+
'flex-grow', 'flex-shrink', 'flex-basis',
|
|
29
|
+
'grid-template-rows', 'grid-auto-flow', 'grid-column', 'grid-row', 'order'
|
|
30
|
+
];
|
|
31
|
+
/** The custom property an authored value goes through: "var(--space-4, 16px)" -> "--space-4". */
|
|
32
|
+
export function tokenOf(authored) {
|
|
33
|
+
const m = authored ? /^var\(\s*(--[\w-]+)\s*(?:,[^)]*)?\)$/.exec(authored.trim()) : null;
|
|
34
|
+
return m?.[1];
|
|
35
|
+
}
|
|
36
|
+
/** A captured value from a snapshot property: computed, plus authored and token when known. */
|
|
37
|
+
export function valueOf(el, prop) {
|
|
38
|
+
const computed = el.styles[prop] ?? '';
|
|
39
|
+
const authored = el.authored[prop];
|
|
40
|
+
const token = tokenOf(authored);
|
|
41
|
+
return { computed, ...(authored && authored !== computed ? { authored } : {}), ...(token ? { token } : {}) };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gDAAgD;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,YAAY,EAAE,SAAS;IA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,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAC,EAAmB,EAAE,IAAsB;IACjE,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/G,CAAC"}
|
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Names for elements in capture files: from tag and role, never from class names (often hashed). */
|
|
2
|
+
export declare function implicitRole(tag: string, attrs?: {
|
|
3
|
+
href?: boolean;
|
|
4
|
+
type?: string;
|
|
5
|
+
}): string | null;
|
|
6
|
+
/** "h1 (heading)", "ul (list)", "button", "div". The role is shown when it adds something. */
|
|
7
|
+
export declare function elementName(tag: string, role: string | null): string;
|
|
8
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAWrG,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,GAAG,IAAI,CAWtG;AAED,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAIpE"}
|
package/dist/naming.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Names for elements in capture files: from tag and role, never from class names (often hashed). */
|
|
2
|
+
/** Implicit ARIA roles for common tags. */
|
|
3
|
+
const IMPLICIT_ROLES = {
|
|
4
|
+
a: 'link', button: 'button', nav: 'navigation', main: 'main', header: 'banner', footer: 'contentinfo',
|
|
5
|
+
aside: 'complementary', section: 'region', article: 'article', form: 'form', ul: 'list', ol: 'list',
|
|
6
|
+
li: 'listitem', table: 'table', tr: 'row', td: 'cell', th: 'columnheader', h1: 'heading', h2: 'heading',
|
|
7
|
+
h3: 'heading', h4: 'heading', h5: 'heading', h6: 'heading', p: 'paragraph', img: 'img', input: 'textbox',
|
|
8
|
+
select: 'combobox', textarea: 'textbox', dialog: 'dialog', hr: 'separator', figure: 'figure', label: 'label'
|
|
9
|
+
};
|
|
10
|
+
export function implicitRole(tag, attrs = {}) {
|
|
11
|
+
const t = tag.toLowerCase();
|
|
12
|
+
if (t === 'a' && attrs.href === false)
|
|
13
|
+
return null;
|
|
14
|
+
if (t === 'input') {
|
|
15
|
+
const type = (attrs.type ?? 'text').toLowerCase();
|
|
16
|
+
if (type === 'checkbox')
|
|
17
|
+
return 'checkbox';
|
|
18
|
+
if (type === 'radio')
|
|
19
|
+
return 'radio';
|
|
20
|
+
if (['button', 'submit', 'reset'].includes(type))
|
|
21
|
+
return 'button';
|
|
22
|
+
return 'textbox';
|
|
23
|
+
}
|
|
24
|
+
return IMPLICIT_ROLES[t] ?? null;
|
|
25
|
+
}
|
|
26
|
+
/** "h1 (heading)", "ul (list)", "button", "div". The role is shown when it adds something. */
|
|
27
|
+
export function elementName(tag, role) {
|
|
28
|
+
const t = tag.toLowerCase();
|
|
29
|
+
if (!role || role === t)
|
|
30
|
+
return t;
|
|
31
|
+
return `${t} (${role})`;
|
|
32
|
+
}
|
|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IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAClD,IAAI,IAAI,KAAK,UAAU;YAAE,OAAO,UAAU,CAAC;QAC3C,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,OAAO,CAAC;QACrC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,QAAQ,CAAC;QAClE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,IAAmB;IAC1D,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC;AAC1B,CAAC"}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The full-page reference: the page's typography, color and spacing systems, plus one entry per kind
|
|
3
|
+
* of component on it (buttons, links, fields, cards...), each with its variants and states.
|
|
4
|
+
*/
|
|
5
|
+
import { type ComponentCapture, type PageCapture } from '@luci-dev/format/capture';
|
|
6
|
+
import { type ComponentImageInput } from './component.js';
|
|
7
|
+
import type { ElementSnapshot, PageSnapshot } from './model.js';
|
|
8
|
+
/** The kinds of component a page file describes. Headings, lists and plain boxes are covered by the systems. */
|
|
9
|
+
export declare const PAGE_COMPONENT_TYPES: ReadonlySet<string>;
|
|
10
|
+
/** At most this many component entries, so the file stays readable. */
|
|
11
|
+
export declare const MAX_PAGE_COMPONENTS = 16;
|
|
12
|
+
/** A "card" larger than this share of the page is a page wrapper with a background, not a card. */
|
|
13
|
+
export declare const MAX_CARD_SHARE = 0.5;
|
|
14
|
+
/**
|
|
15
|
+
* One example of each kind of component, in page order: the first visible element of each tag and
|
|
16
|
+
* type (variantsOf then lists every look of it on the page).
|
|
17
|
+
*/
|
|
18
|
+
export declare function pageComponents(snap: PageSnapshot): ElementSnapshot[];
|
|
19
|
+
/** The page's name from its path: "/pricing/" -> "pricing", "/" -> "home". */
|
|
20
|
+
export declare function pageName(url: string): string;
|
|
21
|
+
export interface PageComponentInput {
|
|
22
|
+
entry: ElementSnapshot;
|
|
23
|
+
/** How deep an element is inside this component (0 for itself, null outside). */
|
|
24
|
+
inside: (el: ElementSnapshot) => number | null;
|
|
25
|
+
states: ComponentCapture['states'];
|
|
26
|
+
/** The images inside it, read from the live page. */
|
|
27
|
+
images?: readonly ComponentImageInput[];
|
|
28
|
+
}
|
|
29
|
+
export type SkippedPart = NonNullable<PageCapture['skipped']>[number];
|
|
30
|
+
/**
|
|
31
|
+
* The full-page reference from a snapshot and the components found on it (with their states).
|
|
32
|
+
* A part that cannot be read (one odd value on a real site) is left out and listed, never the whole file.
|
|
33
|
+
*/
|
|
34
|
+
export declare function pageCapture(snap: PageSnapshot, components: readonly PageComponentInput[], options?: {
|
|
35
|
+
captured?: string;
|
|
36
|
+
skipped?: readonly SkippedPart[];
|
|
37
|
+
}): PageCapture;
|
|
38
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAkG,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEnL,OAAO,EAAmC,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAMhE,gHAAgH;AAChH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAsH,CAAC;AAC5K,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,mGAAmG;AACnG,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,EAAE,CAkBpE;AAED,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5C;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,eAAe,CAAC;IACvB,iFAAiF;IACjF,MAAM,EAAE,CAAC,EAAE,EAAE,eAAe,KAAK,MAAM,GAAG,IAAI,CAAC;IAC/C,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACnC,qDAAqD;IACrD,MAAM,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACzC;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAStE;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,kBAAkB,EAAE,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;CAAO,GAAG,WAAW,CAiC7K"}
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The full-page reference: the page's typography, color and spacing systems, plus one entry per kind
|
|
3
|
+
* of component on it (buttons, links, fields, cards...), each with its variants and states.
|
|
4
|
+
*/
|
|
5
|
+
import { colorSystemSchema, componentSchema, spacingSystemSchema, toCaptureName, typographySystemSchema } from '@luci-dev/format/capture';
|
|
6
|
+
import { colorSystem } from './color.js';
|
|
7
|
+
import { componentCapture, componentType } from './component.js';
|
|
8
|
+
import { eligibility } from './eligibility.js';
|
|
9
|
+
import { spacingSystem } from './spacing.js';
|
|
10
|
+
import { typographySystem } from './text.js';
|
|
11
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
12
|
+
/** The kinds of component a page file describes. Headings, lists and plain boxes are covered by the systems. */
|
|
13
|
+
export const PAGE_COMPONENT_TYPES = new Set(['button', 'link', 'field', 'navigation', 'header', 'footer', 'form', 'dialog', 'table', 'card', 'badge']);
|
|
14
|
+
/** At most this many component entries, so the file stays readable. */
|
|
15
|
+
export const MAX_PAGE_COMPONENTS = 16;
|
|
16
|
+
/** A "card" larger than this share of the page is a page wrapper with a background, not a card. */
|
|
17
|
+
export const MAX_CARD_SHARE = 0.5;
|
|
18
|
+
/**
|
|
19
|
+
* One example of each kind of component, in page order: the first visible element of each tag and
|
|
20
|
+
* type (variantsOf then lists every look of it on the page).
|
|
21
|
+
*/
|
|
22
|
+
export function pageComponents(snap) {
|
|
23
|
+
const body = snap.elements.find(e => e.tag === 'body');
|
|
24
|
+
const pageArea = body ? body.rect.width * body.rect.height : Infinity;
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const el of snap.elements) {
|
|
28
|
+
if (out.length >= MAX_PAGE_COMPONENTS)
|
|
29
|
+
break;
|
|
30
|
+
// A bare image is not a component: it is an image slot of the component around it (FR4)
|
|
31
|
+
if (!el.visible || eligibility({ tag: el.tag }).status !== 'allowed')
|
|
32
|
+
continue;
|
|
33
|
+
const type = componentType(el);
|
|
34
|
+
if (!PAGE_COMPONENT_TYPES.has(type))
|
|
35
|
+
continue;
|
|
36
|
+
if (type === 'card' && el.rect.width * el.rect.height > pageArea * MAX_CARD_SHARE)
|
|
37
|
+
continue;
|
|
38
|
+
const key = `${el.tag}|${type}`;
|
|
39
|
+
if (seen.has(key))
|
|
40
|
+
continue;
|
|
41
|
+
seen.add(key);
|
|
42
|
+
out.push(el);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
/** The page's name from its path: "/pricing/" -> "pricing", "/" -> "home". */
|
|
47
|
+
export function pageName(url) {
|
|
48
|
+
let path = '';
|
|
49
|
+
try {
|
|
50
|
+
path = new URL(url).pathname;
|
|
51
|
+
}
|
|
52
|
+
catch { /* not a URL */ }
|
|
53
|
+
const trimmed = path.replace(/\/(index\.html?)?$/, '').replace(/^\//, '');
|
|
54
|
+
return trimmed ? toCaptureName(trimmed) : 'home';
|
|
55
|
+
}
|
|
56
|
+
/** A short reason: a format check's first problem ("color.tokens.34.token: ..."), or the error's message. */
|
|
57
|
+
const reasonOf = (err) => {
|
|
58
|
+
const issues = err.issues;
|
|
59
|
+
const text = issues?.length ? `${issues[0].path.map(String).join('.')}: ${issues[0].message}` : err instanceof Error ? err.message : String(err);
|
|
60
|
+
return text.replace(/\s+/g, ' ').slice(0, 200);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The full-page reference from a snapshot and the components found on it (with their states).
|
|
64
|
+
* A part that cannot be read (one odd value on a real site) is left out and listed, never the whole file.
|
|
65
|
+
*/
|
|
66
|
+
export function pageCapture(snap, components, options = {}) {
|
|
67
|
+
const captured = options.captured ?? today();
|
|
68
|
+
const skipped = [...(options.skipped ?? [])];
|
|
69
|
+
const used = new Map();
|
|
70
|
+
const entries = components.flatMap(({ entry, inside, states, images }) => {
|
|
71
|
+
try {
|
|
72
|
+
// Checked against the format here, so one part that does not fit is left out, not the whole file
|
|
73
|
+
const c = componentSchema.parse(componentCapture(snap, entry, inside, { captured, system: true, states, ...(images ? { images } : {}) }));
|
|
74
|
+
const n = (used.get(c.meta.name) ?? 0) + 1;
|
|
75
|
+
used.set(c.meta.name, n);
|
|
76
|
+
return [n > 1 ? { ...c, meta: { ...c.meta, name: `${c.meta.name}-${n}` } } : c];
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
skipped.push({ part: `component ${entry.selector}`, reason: reasonOf(err) });
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const system = (part, read, schema) => {
|
|
84
|
+
try {
|
|
85
|
+
const value = read();
|
|
86
|
+
return value === null ? null : schema.parse(value);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
skipped.push({ part, reason: reasonOf(err) });
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
meta: { name: pageName(snap.url), scope: 'page', type: 'page', source: snap.url, captured, method: 'measured' },
|
|
95
|
+
typography: system('typography', () => typographySystem(snap, { captured }), typographySystemSchema),
|
|
96
|
+
color: system('colors', () => colorSystem(snap, { captured }), colorSystemSchema),
|
|
97
|
+
spacing: system('spacing', () => spacingSystem(snap, { captured }), spacingSystemSchema),
|
|
98
|
+
components: entries,
|
|
99
|
+
...(skipped.length ? { skipped } : {})
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=page.js.map
|
package/dist/page.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EAAE,sBAAsB,EAA2C,MAAM,0BAA0B,CAAC;AACnL,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE1D,gHAAgH;AAChH,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,G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AE,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,mBAAmB,CAAC;QACxF,UAAU,EAAE,OAAO;QACnB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvC,CAAC;AACJ,CAAC"}
|
package/dist/realm.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that work for a document of another window too (v0.3.4: responsive capture reads the page
|
|
3
|
+
* in a hidden frame). `instanceof CSSStyleRule` is false for a frame's rules, which are made by the
|
|
4
|
+
* frame's own CSSStyleRule, and the global matchMedia answers for this window, not the frame's.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isStyleRule: (rule: CSSRule) => rule is CSSStyleRule;
|
|
7
|
+
export declare const isMediaRule: (rule: CSSRule) => rule is CSSMediaRule;
|
|
8
|
+
export declare const isSupportsRule: (rule: CSSRule) => rule is CSSSupportsRule;
|
|
9
|
+
/** A rule that holds other rules (@layer, @container, @scope...). */
|
|
10
|
+
export declare const hasRules: (rule: CSSRule) => rule is CSSGroupingRule;
|
|
11
|
+
export declare const isDocument: (node: Node) => node is Document;
|
|
12
|
+
export declare const isShadowRoot: (node: Node) => node is ShadowRoot;
|
|
13
|
+
/** The window a document or shadow root lives in. */
|
|
14
|
+
export declare const windowOf: (root: Document | ShadowRoot) => Window;
|
|
15
|
+
/** Does a media condition apply in this window (the frame's own width)? */
|
|
16
|
+
export declare const mediaMatches: (win: Window, condition: string) => boolean;
|
|
17
|
+
//# sourceMappingURL=realm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realm.d.ts","sourceRoot":"","sources":["../src/realm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,WAAW,SAAU,OAAO,KAAG,IAAI,IAAI,YAA0C,CAAC;AAC/F,eAAO,MAAM,WAAW,SAAU,OAAO,KAAG,IAAI,IAAI,YAA0C,CAAC;AAC/F,eAAO,MAAM,cAAc,SAAU,OAAO,KAAG,IAAI,IAAI,eAAgD,CAAC;AACxG,qEAAqE;AACrE,eAAO,MAAM,QAAQ,SAAU,OAAO,KAAG,IAAI,IAAI,eAAoF,CAAC;AAEtI,eAAO,MAAM,UAAU,SAAU,IAAI,KAAG,IAAI,IAAI,QAA+B,CAAC;AAChF,eAAO,MAAM,YAAY,SAAU,IAAI,KAAG,IAAI,IAAI,UAAoD,CAAC;AAEvG,qDAAqD;AACrD,eAAO,MAAM,QAAQ,SAAU,QAAQ,GAAG,UAAU,KAAG,MAA8E,CAAC;AACtI,2EAA2E;AAC3E,eAAO,MAAM,YAAY,QAAS,MAAM,aAAa,MAAM,YAAsC,CAAC"}
|
package/dist/realm.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that work for a document of another window too (v0.3.4: responsive capture reads the page
|
|
3
|
+
* in a hidden frame). `instanceof CSSStyleRule` is false for a frame's rules, which are made by the
|
|
4
|
+
* frame's own CSSStyleRule, and the global matchMedia answers for this window, not the frame's.
|
|
5
|
+
*/
|
|
6
|
+
const kind = (rule, name) => rule.constructor?.name === name;
|
|
7
|
+
export const isStyleRule = (rule) => kind(rule, 'CSSStyleRule');
|
|
8
|
+
export const isMediaRule = (rule) => kind(rule, 'CSSMediaRule');
|
|
9
|
+
export const isSupportsRule = (rule) => kind(rule, 'CSSSupportsRule');
|
|
10
|
+
/** A rule that holds other rules (@layer, @container, @scope...). */
|
|
11
|
+
export const hasRules = (rule) => 'cssRules' in rule && Boolean(rule.cssRules);
|
|
12
|
+
export const isDocument = (node) => node.nodeType === 9;
|
|
13
|
+
export const isShadowRoot = (node) => node.nodeType === 11 && 'host' in node;
|
|
14
|
+
/** The window a document or shadow root lives in. */
|
|
15
|
+
export const windowOf = (root) => (isDocument(root) ? root : root.ownerDocument).defaultView ?? window;
|
|
16
|
+
/** Does a media condition apply in this window (the frame's own width)? */
|
|
17
|
+
export const mediaMatches = (win, condition) => win.matchMedia(condition).matches;
|
|
18
|
+
//# sourceMappingURL=realm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realm.js","sourceRoot":"","sources":["../src/realm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,MAAM,IAAI,GAAG,CAAC,IAAa,EAAE,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,KAAK,IAAI,CAAC;AAEhF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAa,EAAwB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAa,EAAwB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAa,EAA2B,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;AACxG,qEAAqE;AACrE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAa,EAA2B,EAAE,CAAC,UAAU,IAAI,IAAI,IAAI,OAAO,CAAE,IAAwB,CAAC,QAAQ,CAAC,CAAC;AAEtI,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAoB,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAU,EAAsB,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,EAAE,IAAI,MAAM,IAAI,IAAI,CAAC;AAEvG,qDAAqD;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAA2B,EAAU,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC;AACtI,2EAA2E;AAC3E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,SAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Responsive capture (v0.3.4): a component or section read at 2 or 3 window widths, chosen from the
|
|
3
|
+
* site's own media queries that style it, and the properties that differ between those widths.
|
|
4
|
+
*
|
|
5
|
+
* Two ways to read another width: resize the real window (the extension, through the debugger:
|
|
6
|
+
* `setWidth`), or load the same page in a hidden frame of that width (any shell; the page must allow
|
|
7
|
+
* itself in a frame). The pure parts (thresholds, widths, differences) are tested without a browser.
|
|
8
|
+
*/
|
|
9
|
+
import type { CapturedValue, Responsive } from '@luci-dev/format/capture';
|
|
10
|
+
/** The name of Luci's width frames: the dev toolbar does not start inside one. */
|
|
11
|
+
export declare const LUCI_FRAME_NAME = "luci-width";
|
|
12
|
+
/** The widths that stand for "a phone" and "a desktop" when a range has no better one. */
|
|
13
|
+
export declare const PHONE_WIDTH = 375;
|
|
14
|
+
export declare const DESKTOP_WIDTH = 1280;
|
|
15
|
+
/** At most this many breakpoints (so at most 3 widths). */
|
|
16
|
+
export declare const MAX_THRESHOLDS = 2;
|
|
17
|
+
/**
|
|
18
|
+
* The widths where a media condition starts or stops applying: "(min-width: 768px)" -> [768],
|
|
19
|
+
* "(max-width: 767px)" -> [768], "(width >= 64em)" -> [1024]. em and rem count 16px.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mediaThresholds(condition: string, rootFontSize?: number): number[];
|
|
22
|
+
/**
|
|
23
|
+
* The widths to read at: one per range between breakpoints, the breakpoints that style the most
|
|
24
|
+
* rules first (at most two). Below the first, a phone (375px, or just under it); between two, the
|
|
25
|
+
* breakpoint itself; above the last, a desktop (1280px, or the breakpoint). Empty without breakpoints.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pickWidths(thresholds: readonly {
|
|
28
|
+
px: number;
|
|
29
|
+
weight: number;
|
|
30
|
+
}[]): number[];
|
|
31
|
+
/** The breakpoints that style the most rules (at most two), narrowest first. */
|
|
32
|
+
export declare function chooseThresholds(thresholds: readonly {
|
|
33
|
+
px: number;
|
|
34
|
+
weight: number;
|
|
35
|
+
}[]): number[];
|
|
36
|
+
/** One width per range between the breakpoints. */
|
|
37
|
+
export declare function widthsFor(chosen: readonly number[]): number[];
|
|
38
|
+
/** One part as read at one width: its name (unique in the reading) and its styles. */
|
|
39
|
+
export interface PartReading {
|
|
40
|
+
part: string;
|
|
41
|
+
styles: {
|
|
42
|
+
property: string;
|
|
43
|
+
value: CapturedValue;
|
|
44
|
+
}[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The properties that differ between the readings (one per width, null where it could not be read):
|
|
48
|
+
* a part found at some widths only gives a `shown` row; grid columns compare by count; a size the
|
|
49
|
+
* site wrote the same way everywhere is fluid, not a change. Parts and properties in reading order.
|
|
50
|
+
*/
|
|
51
|
+
export declare function responsiveChanges(readings: readonly (readonly PartReading[] | null)[]): Responsive['changes'];
|
|
52
|
+
/** Give each repeated part name a number in order: heading, heading (2), heading (3). */
|
|
53
|
+
export declare function uniqueParts(parts: readonly PartReading[]): PartReading[];
|
|
54
|
+
/**
|
|
55
|
+
* The media conditions that style an element or anything inside it (a rule in the block matches
|
|
56
|
+
* one of them), or set custom properties on an element around it. With the number of such rules.
|
|
57
|
+
* Stylesheets the page cannot read (another origin without CORS) are skipped.
|
|
58
|
+
*/
|
|
59
|
+
export declare function mediaQueriesFor(root: Element): {
|
|
60
|
+
condition: string;
|
|
61
|
+
rules: number;
|
|
62
|
+
}[];
|
|
63
|
+
/** Sets the window's width for reading (the extension, through the debugger); null puts it back. */
|
|
64
|
+
export type ViewportWidth = (width: number | null) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Read something at each width: by resizing the window when the shell can (`setWidth`), else in a
|
|
67
|
+
* hidden frame of the same page. The window is always put back. `onWidth` says where Luci is.
|
|
68
|
+
*/
|
|
69
|
+
export declare function readAtWidths<T>(doc: Document, widths: readonly number[], read: (doc: Document) => T | null, options?: {
|
|
70
|
+
setWidth?: ViewportWidth;
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
onWidth?: (width: number, index: number) => void;
|
|
73
|
+
}): Promise<T[]>;
|
|
74
|
+
//# sourceMappingURL=responsive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsive.d.ts","sourceRoot":"","sources":["../src/responsive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAI1E,kFAAkF;AAClF,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,0FAA0F;AAC1F,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,aAAa,OAAO,CAAC;AAClC,2DAA2D;AAC3D,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,SAAK,GAAG,MAAM,EAAE,CAY9E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,MAAM,EAAE,CAE1F;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,MAAM,EAAE,CAIhG;AAED,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAK7D;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAAG,IAAI,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