@acepaste/ingress 0.9.1 → 0.9.21
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 +1 -1
- package/dist/src/adapters.d.ts +9 -0
- package/dist/src/adapters.js +76 -6
- package/dist/src/agent-hooks.d.ts +112 -0
- package/dist/src/agent-hooks.js +533 -0
- package/dist/src/approvers.d.ts +16 -0
- package/dist/src/approvers.js +50 -0
- package/dist/src/audio.d.ts +70 -0
- package/dist/src/audio.js +224 -0
- package/dist/src/audit-changes.d.ts +46 -0
- package/dist/src/audit-changes.js +110 -0
- package/dist/src/audit-local.d.ts +57 -0
- package/dist/src/audit-local.js +231 -0
- package/dist/src/audit-parsers.d.ts +1 -1
- package/dist/src/audit.js +48 -0
- package/dist/src/broker.d.ts +92 -1
- package/dist/src/broker.js +222 -3
- package/dist/src/calendar.d.ts +36 -0
- package/dist/src/calendar.js +227 -0
- package/dist/src/captions.d.ts +44 -0
- package/dist/src/captions.js +209 -0
- package/dist/src/changes.d.ts +105 -0
- package/dist/src/changes.js +174 -0
- package/dist/src/character.js +19 -3
- package/dist/src/classifier-model.d.ts +53 -0
- package/dist/src/classifier-model.js +3 -0
- package/dist/src/classifier.d.ts +41 -0
- package/dist/src/classifier.js +213 -0
- package/dist/src/cli.js +501 -1
- package/dist/src/codepass.d.ts +8 -0
- package/dist/src/codepass.js +39 -1
- package/dist/src/egress.d.ts +71 -0
- package/dist/src/egress.js +242 -0
- package/dist/src/email.d.ts +42 -0
- package/dist/src/email.js +424 -0
- package/dist/src/engine.d.ts +35 -12
- package/dist/src/engine.js +172 -45
- package/dist/src/image-meta.d.ts +33 -0
- package/dist/src/image-meta.js +433 -0
- package/dist/src/image.d.ts +104 -0
- package/dist/src/image.js +347 -0
- package/dist/src/index.d.ts +50 -5
- package/dist/src/index.js +28 -3
- package/dist/src/localguard.d.ts +33 -0
- package/dist/src/localguard.js +61 -0
- package/dist/src/meaning.d.ts +2 -0
- package/dist/src/meaning.js +348 -25
- package/dist/src/messages.d.ts +79 -0
- package/dist/src/messages.js +431 -0
- package/dist/src/multilingual.d.ts +3 -0
- package/dist/src/multilingual.js +117 -5
- package/dist/src/nearby.d.ts +52 -0
- package/dist/src/nearby.js +186 -0
- package/dist/src/netpolicy.js +50 -19
- package/dist/src/normalize.d.ts +36 -1
- package/dist/src/normalize.js +186 -4
- package/dist/src/provenance.d.ts +56 -0
- package/dist/src/provenance.js +114 -0
- package/dist/src/qr.d.ts +25 -0
- package/dist/src/qr.js +113 -0
- package/dist/src/safeguards.d.ts +61 -0
- package/dist/src/safeguards.js +199 -0
- package/dist/src/served.d.ts +20 -0
- package/dist/src/served.js +53 -0
- package/dist/src/shell-commands.d.ts +39 -0
- package/dist/src/shell-commands.js +291 -0
- package/dist/src/shortcuts.d.ts +45 -0
- package/dist/src/shortcuts.js +220 -0
- package/dist/src/stream.d.ts +88 -0
- package/dist/src/stream.js +119 -0
- package/dist/src/terminal.d.ts +29 -0
- package/dist/src/terminal.js +313 -0
- package/dist/src/tooldefs.d.ts +84 -0
- package/dist/src/tooldefs.js +122 -0
- package/dist/src/types.d.ts +50 -6
- package/dist/src/types.js +15 -2
- package/dist/src/visibility.d.ts +23 -3
- package/dist/src/visibility.js +285 -78
- package/native/ingress-presence.swift +48 -0
- package/native/ingress-vision.swift +417 -0
- package/package.json +4 -2
package/dist/src/types.d.ts
CHANGED
|
@@ -5,18 +5,52 @@
|
|
|
5
5
|
* at the same source would not see is suspect by default.
|
|
6
6
|
*/
|
|
7
7
|
import type { NetPolicy } from "./netpolicy.js";
|
|
8
|
-
export declare const ENGINE_VERSION = "0.9.
|
|
8
|
+
export declare const ENGINE_VERSION = "0.9.21";
|
|
9
9
|
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
10
|
-
export declare const RULESET_VERSION = "2026.11.
|
|
10
|
+
export declare const RULESET_VERSION = "2026.11.18-11";
|
|
11
11
|
/**
|
|
12
12
|
* clean: delivered. suspect: refused, overridable. hostile: refused, not overridable.
|
|
13
13
|
* unreachable: nothing could be fetched or read (network error, timeout, redirect loop,
|
|
14
14
|
* binary or oversized body). Not an attack verdict, and never written to the attack log.
|
|
15
15
|
*/
|
|
16
16
|
export type Tier = "clean" | "suspect" | "hostile" | "unreachable";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* What the content is. The first five are document formats; the rest are channels, each with its own adapter
|
|
19
|
+
* that turns the channel's structure into segments the passes read (see docs/ROADMAP.md, shared foundations).
|
|
20
|
+
*/
|
|
21
|
+
export type ContentKind = "html" | "markdown" | "json" | "text" | "javascript" | "log" | "email" | "calendar" | "message" | "notification" | "nearby" | "automation" | "captions" | "image" | "audio";
|
|
22
|
+
/**
|
|
23
|
+
* Who could have written the content. Lower is more trusted. It never makes a verdict more lenient than the
|
|
24
|
+
* default; from level 4 down, less evidence is needed to refuse.
|
|
25
|
+
* 1 the person, typing or approving 2 known contacts, own calendars, lists and files
|
|
26
|
+
* 3 content an agent wrote earlier 4 strangers: unknown senders, voicemail, fax, invitations, downloads
|
|
27
|
+
* 5 open channels: public chats, group chats, subscribed feeds, logs, the web
|
|
28
|
+
* 6 broadcasts: Bonjour, Bluetooth, beacons, anything on a shared network
|
|
29
|
+
*/
|
|
30
|
+
export type TrustLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
31
|
+
/** Where a piece of content came from, as far as the caller knows. */
|
|
32
|
+
export interface SourceInfo {
|
|
33
|
+
/** the app or system it arrived through: "gmail", "slack", "imessage", "bonjour", "nginx access log" */
|
|
34
|
+
channel?: string;
|
|
35
|
+
/** who sent or wrote it, as the channel names them */
|
|
36
|
+
sender?: string;
|
|
37
|
+
trust?: TrustLevel;
|
|
38
|
+
}
|
|
39
|
+
export declare const CONTENT_KINDS: readonly ContentKind[];
|
|
40
|
+
/** Read a content kind and source from untyped input (an HTTP body, tool arguments). Unknown values are dropped, never guessed. */
|
|
41
|
+
export declare function parseScanHints(o: {
|
|
42
|
+
kind?: unknown;
|
|
43
|
+
trust?: unknown;
|
|
44
|
+
channel?: unknown;
|
|
45
|
+
sender?: unknown;
|
|
46
|
+
}): {
|
|
47
|
+
kind?: ContentKind;
|
|
48
|
+
source?: SourceInfo;
|
|
49
|
+
};
|
|
50
|
+
/** multiplier on the suspect threshold per trust level: strangers and broadcasts need less evidence */
|
|
51
|
+
export declare const TRUST_SUSPECT_FACTOR: Record<TrustLevel, number>;
|
|
52
|
+
export type PassName = "acquire" | "policy" | "visibility" | "character" | "script" | "supplychain" | "secrets" | "meaning" | "cloaking" | "sandbox" | "code" | "channel" | "classifier" | "plugin";
|
|
53
|
+
export type FindingKind = "policy.denied_source" | "policy.redirect_chain" | "acquire.unreachable" | "acquire.cloaking_check_incomplete" | "acquire.ai_agent_refused" | "unicode.tag_characters" | "unicode.zero_width" | "unicode.bidi_control" | "unicode.variation_selector_smuggling" | "unicode.mixed_script_confusable" | "unicode.fullwidth_or_math_lookalike" | "unicode.combining_flood" | "unicode.encoded_payload" | "unicode.entity_smuggling" | "unicode.whitespace_channel" | "visibility.css_hidden" | "visibility.offscreen" | "visibility.attribute_only" | "visibility.html_comment" | "visibility.tiny_or_transparent" | "visibility.markdown_hidden" | "visibility.terminal_hidden" | "visibility.terminal_control" | "email.part_divergence" | "email.sender_mismatch" | "email.authentication_failed" | "email.remote_content" | "email.uninspected_part" | "calendar.alarm_action" | "calendar.description_divergence" | "message.text_divergence" | "message.sender_impersonation" | "message.scam_shape" | "message.verification_code" | "message.uninspected_part" | "notification.source_mismatch" | "nearby.authority_name" | "nearby.lookalike" | "nearby.link" | "nearby.oversized_field" | "automation.private_outside_send" | "automation.runs_code" | "automation.destination" | "automation.unreadable" | "image.clickfix" | "captions.hidden_cue" | "captions.unreadable_cue" | "captions.not_spoken" | "captions.addressed_to_notetaker" | "captions.spoken_approval" | "audio.quiet_speech" | "audio.transcript_unstable" | "audio.metadata_text" | "audio.not_transcribed" | "image.text_only_when_resized" | "image.low_contrast_text" | "image.transparency_text" | "image.later_frame_text" | "image.metadata_text" | "image.trailing_data" | "image.active_content" | "image.code_payload" | "image.code_action" | "image.caption_mismatch" | "image.pixels_not_inspected" | "classifier.injection_likely" | "script.obfuscation" | "script.runtime_codegen" | "script.automation_detection" | "script.post_load_text_injection" | "script.exfil_beacon" | "script.binary_decoding" | "supplychain.lifecycle_script" | "supplychain.url_dependency" | "supplychain.offregistry_resolution" | "supplychain.install_instruction" | "secrets.credential_in_content" | "sandbox.text_injected_after_load" | "sandbox.webdriver_keyed_divergence" | "sandbox.computed_hidden_text" | "sandbox.blocked_egress_attempt" | "meaning.instruction_shaped" | "meaning.role_token" | "meaning.system_prompt_imitation" | "meaning.tool_call_shaped" | "meaning.exfil_markdown_image" | "meaning.exfil_link" | "meaning.adversarial_suffix" | "cloaking.agent_targeted_divergence" | "code.download_execute" | "code.encoded_execution" | "code.reverse_shell" | "code.secret_exfiltration" | "code.persistence" | `plugin.${string}`;
|
|
20
54
|
export interface Finding {
|
|
21
55
|
pass: PassName;
|
|
22
56
|
kind: FindingKind;
|
|
@@ -63,7 +97,8 @@ export interface AcquireResult {
|
|
|
63
97
|
export interface TextSegment {
|
|
64
98
|
text: string;
|
|
65
99
|
/** visible: a sighted human reading the rendered page sees this */
|
|
66
|
-
|
|
100
|
+
/** concealed: the medium itself hides it from a person (terminal control codes, a part of a message no client shows) */
|
|
101
|
+
visibility: "visible" | "css_hidden" | "offscreen" | "attribute" | "comment" | "tiny_or_transparent" | "concealed";
|
|
67
102
|
/** selector-ish path for the location field */
|
|
68
103
|
path: string;
|
|
69
104
|
}
|
|
@@ -122,6 +157,8 @@ export interface TaintReceipt {
|
|
|
122
157
|
overridden: boolean;
|
|
123
158
|
/** which passes actually ran (sandbox may not have) */
|
|
124
159
|
passesRun: PassName[];
|
|
160
|
+
/** the trust level the caller gave for the source, when it gave one */
|
|
161
|
+
trust?: TrustLevel;
|
|
125
162
|
findings: Array<Pick<Finding, "pass" | "kind" | "confidence" | "severity" | "action" | "evidenceClass" | "band" | "artifactDigest">>;
|
|
126
163
|
/** how `signature` was made: a shared-secret HMAC (only the key holder can verify) or ECDSA P-256 (anyone with the public key can verify, nobody without the private key can forge) */
|
|
127
164
|
signatureAlg?: "hmac-sha256" | "ecdsa-p256-sha256";
|
|
@@ -152,6 +189,8 @@ export interface IngressResult {
|
|
|
152
189
|
/** what was inspected, and what was not (code languages, units skipped). Unknown is not clean. */
|
|
153
190
|
coverage?: {
|
|
154
191
|
code?: import("./codepass.js").CodeCoverage;
|
|
192
|
+
image?: import("./image.js").ImageCoverage;
|
|
193
|
+
audio?: import("./audio.js").AudioCoverage;
|
|
155
194
|
};
|
|
156
195
|
}
|
|
157
196
|
export interface IngressConfig {
|
|
@@ -202,5 +241,10 @@ export interface IngressConfig {
|
|
|
202
241
|
detectors: Detector[];
|
|
203
242
|
/** chain receipts: each receipt carries the digest of the previous one */
|
|
204
243
|
chainReceipts: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Run the learned pass beside the rules. On its own it can make content suspect, never hostile.
|
|
246
|
+
* Off reproduces the rules-only verdicts of 0.9.15 and earlier.
|
|
247
|
+
*/
|
|
248
|
+
classifier: boolean;
|
|
205
249
|
}
|
|
206
250
|
export declare const DEFAULT_CONFIG: IngressConfig;
|
package/dist/src/types.js
CHANGED
|
@@ -4,9 +4,21 @@
|
|
|
4
4
|
* Governing principle: anything the model would receive that a human looking
|
|
5
5
|
* at the same source would not see is suspect by default.
|
|
6
6
|
*/
|
|
7
|
-
export const ENGINE_VERSION = "0.9.
|
|
7
|
+
export const ENGINE_VERSION = "0.9.21";
|
|
8
8
|
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
9
|
-
export const RULESET_VERSION = "2026.11.
|
|
9
|
+
export const RULESET_VERSION = "2026.11.18-11";
|
|
10
|
+
export const CONTENT_KINDS = ["html", "markdown", "json", "text", "javascript", "log", "email", "calendar", "message", "notification", "nearby", "automation", "captions", "image", "audio"];
|
|
11
|
+
/** Read a content kind and source from untyped input (an HTTP body, tool arguments). Unknown values are dropped, never guessed. */
|
|
12
|
+
export function parseScanHints(o) {
|
|
13
|
+
const kind = typeof o.kind === "string" && CONTENT_KINDS.includes(o.kind) ? o.kind : undefined;
|
|
14
|
+
const trust = typeof o.trust === "number" && Number.isInteger(o.trust) && o.trust >= 1 && o.trust <= 6 ? o.trust : undefined;
|
|
15
|
+
const channel = typeof o.channel === "string" ? o.channel.slice(0, 120) : undefined;
|
|
16
|
+
const sender = typeof o.sender === "string" ? o.sender.slice(0, 200) : undefined;
|
|
17
|
+
const source = trust !== undefined || channel !== undefined || sender !== undefined ? { trust, channel, sender } : undefined;
|
|
18
|
+
return { kind, source };
|
|
19
|
+
}
|
|
20
|
+
/** multiplier on the suspect threshold per trust level: strangers and broadcasts need less evidence */
|
|
21
|
+
export const TRUST_SUSPECT_FACTOR = { 1: 1, 2: 1, 3: 1, 4: 0.9, 5: 0.85, 6: 0.7 };
|
|
10
22
|
export const DEFAULT_CONFIG = {
|
|
11
23
|
hostileThreshold: 0.7,
|
|
12
24
|
suspectThreshold: 0.25,
|
|
@@ -30,4 +42,5 @@ export const DEFAULT_CONFIG = {
|
|
|
30
42
|
policy: { domains: [] },
|
|
31
43
|
detectors: [],
|
|
32
44
|
chainReceipts: true,
|
|
45
|
+
classifier: true,
|
|
33
46
|
};
|
package/dist/src/visibility.d.ts
CHANGED
|
@@ -14,10 +14,30 @@ import { type RGBA } from "./color.js";
|
|
|
14
14
|
export interface HiddenRule {
|
|
15
15
|
selector: string;
|
|
16
16
|
reason: TextSegment["visibility"];
|
|
17
|
+
/** other classes the element must also have (`.a.b` is keyed on b and requires a) */
|
|
18
|
+
all?: string[];
|
|
19
|
+
/** classes the element must not have (`:not(.show)`) */
|
|
20
|
+
not?: string[];
|
|
21
|
+
/** tag the element must be (`div.note`) */
|
|
22
|
+
tag?: string;
|
|
17
23
|
}
|
|
18
|
-
/**
|
|
19
|
-
export
|
|
20
|
-
|
|
24
|
+
/** Custom properties (`--name`) and every value a stylesheet or inline style gives them. */
|
|
25
|
+
export type CssVars = Map<string, Set<string>>;
|
|
26
|
+
/**
|
|
27
|
+
* Split a declaration block into property -> value (lower case, whitespace removed, `!important` dropped).
|
|
28
|
+
* The last declaration of a property wins, as in the cascade. Semicolons inside parentheses or quotes
|
|
29
|
+
* (a data: URL) do not split.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseDeclarations(style: string): Map<string, string>;
|
|
32
|
+
/** Collect custom property definitions from CSS text (rule bodies or one inline style). */
|
|
33
|
+
export declare function collectCssVars(css: string, into?: CssVars): CssVars;
|
|
34
|
+
/**
|
|
35
|
+
* Classify a declaration block. Returns the hiding reason or null. Properties are matched by their exact
|
|
36
|
+
* names (so `-webkit-tap-highlight-color:transparent`, `background-color:rgba(0,0,0,0)` and
|
|
37
|
+
* `fill-opacity:0` hide nothing), and var() references are resolved against `vars` before judging.
|
|
38
|
+
*/
|
|
39
|
+
export declare function classifyStyle(style: string, vars?: CssVars): TextSegment["visibility"] | null;
|
|
40
|
+
export declare function rulesFromCss(cssIn: string, extraVars?: CssVars): HiddenRule[];
|
|
21
41
|
export interface ColorRule {
|
|
22
42
|
selector: string;
|
|
23
43
|
fg?: RGBA | null;
|
package/dist/src/visibility.js
CHANGED
|
@@ -16,94 +16,284 @@ import { colorsFromStyle, contrastRatio, blend, parseColor, INVISIBLE_CONTRAST }
|
|
|
16
16
|
const HIDDEN_CONTAINER_TAGS = new Set(["noscript", "template"]);
|
|
17
17
|
/** not rendered as page copy at all; skipped (scripts are collected separately) */
|
|
18
18
|
const SKIPPED_TAGS = new Set(["script", "style", "head", "meta", "link", "base"]);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
return "
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Class names that hide an element by convention, matched as whole class names. Matching inside names read
|
|
21
|
+
* `overflow-hidden`, `overflow-x-clip` and `bg-clip-text` as "hidden" and "clip", and hid the main column of
|
|
22
|
+
* every page that clips its overflow.
|
|
23
|
+
*/
|
|
24
|
+
const A11Y_CLASSES = new Set(["sr-only", "visually-hidden", "screen-reader-only", "visuallyhidden", "a11y-hidden", "screen-reader-text", "visually-hidden-focusable"]);
|
|
25
|
+
const HIDDEN_CLASSES = new Set(["hidden", "offscreen", "is-hidden", "d-none", "invisible", "u-hidden", "hide", "is-invisible"]);
|
|
26
|
+
/** utility-framework variants: `md:block` shows at a width, `dark:block` in a theme, `not-sr-only` undoes sr-only */
|
|
27
|
+
const SHOWS_AT_A_WIDTH_OR_THEME = /^(?:sm|md|lg|xl|2xl|dark|light|print|max-(?:sm|md|lg|xl|2xl)|min-\[[^\]]+\]|supports-\[[^\]]+\]):(?:block|flex|grid|inline|inline-block|inline-flex|inline-grid|table|table-cell|contents|flow-root|list-item|visible|not-sr-only)$/;
|
|
28
|
+
const HIDES_ON_DESKTOP = /^(?:sm|md|lg|xl|2xl):(?:hidden|invisible|sr-only)$/;
|
|
29
|
+
/** How an element's class names hide it, if they do. A person at a desktop width in either theme is the reference. */
|
|
30
|
+
function classHides(cls) {
|
|
31
|
+
const tokens = cls.toLowerCase().split(/\s+/).filter(Boolean);
|
|
32
|
+
if (!tokens.length)
|
|
33
|
+
return null;
|
|
34
|
+
const shownSomewhere = tokens.some((t) => SHOWS_AT_A_WIDTH_OR_THEME.test(t));
|
|
35
|
+
if (tokens.some((t) => A11Y_CLASSES.has(t)) && !tokens.includes("not-sr-only") && !shownSomewhere)
|
|
36
|
+
return { vis: "css_hidden", a11y: true };
|
|
37
|
+
// `hidden lg:block` is a desktop sidebar: hidden on a phone, shown to the reader we model
|
|
38
|
+
if (tokens.some((t) => HIDDEN_CLASSES.has(t)) && !shownSomewhere)
|
|
39
|
+
return { vis: "css_hidden", a11y: false };
|
|
40
|
+
// `lg:hidden` is the phone menu: not shown at desktop width
|
|
41
|
+
if (tokens.some((t) => HIDES_ON_DESKTOP.test(t)))
|
|
42
|
+
return { vis: "css_hidden", a11y: false };
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Split a declaration block into property -> value (lower case, whitespace removed, `!important` dropped).
|
|
47
|
+
* The last declaration of a property wins, as in the cascade. Semicolons inside parentheses or quotes
|
|
48
|
+
* (a data: URL) do not split.
|
|
49
|
+
*/
|
|
50
|
+
export function parseDeclarations(style) {
|
|
51
|
+
const out = new Map();
|
|
52
|
+
let depth = 0, quote = "", start = 0;
|
|
53
|
+
const flush = (end) => {
|
|
54
|
+
const d = style.slice(start, end);
|
|
55
|
+
const i = d.indexOf(":");
|
|
56
|
+
if (i > 0) {
|
|
57
|
+
const prop = d.slice(0, i).trim().toLowerCase();
|
|
58
|
+
const value = d.slice(i + 1).toLowerCase().replace(/\s+/g, "").replace(/!important$/, "");
|
|
59
|
+
if (prop && value) {
|
|
60
|
+
out.delete(prop);
|
|
61
|
+
out.set(prop, value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
start = end + 1;
|
|
65
|
+
};
|
|
66
|
+
for (let i = 0; i < style.length; i++) {
|
|
67
|
+
const c = style[i];
|
|
68
|
+
if (quote) {
|
|
69
|
+
if (c === quote && style[i - 1] !== "\\")
|
|
70
|
+
quote = "";
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (c === '"' || c === "'")
|
|
74
|
+
quote = c;
|
|
75
|
+
else if (c === "(")
|
|
76
|
+
depth++;
|
|
77
|
+
else if (c === ")")
|
|
78
|
+
depth = Math.max(0, depth - 1);
|
|
79
|
+
else if (c === ";" && depth === 0)
|
|
80
|
+
flush(i);
|
|
81
|
+
}
|
|
82
|
+
flush(style.length);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/** Collect custom property definitions from CSS text (rule bodies or one inline style). */
|
|
86
|
+
export function collectCssVars(css, into = new Map()) {
|
|
87
|
+
for (const m of css.matchAll(/(--[\w-]+)\s*:\s*([^;{}]+)/g)) {
|
|
88
|
+
const v = m[2].toLowerCase().replace(/\s+/g, "").replace(/!important$/, "");
|
|
89
|
+
if (!v)
|
|
90
|
+
continue;
|
|
91
|
+
const set = into.get(m[1].toLowerCase()) ?? new Set();
|
|
92
|
+
if (set.size < 12)
|
|
93
|
+
set.add(v);
|
|
94
|
+
into.set(m[1].toLowerCase(), set);
|
|
95
|
+
}
|
|
96
|
+
return into;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Every value a declaration could take once its var() references are resolved: each known definition of
|
|
100
|
+
* the variable, and the fallback. A variable nobody defines statically resolves to nothing: its value is
|
|
101
|
+
* unknown, and unknown is not hidden. (Tailwind 4 sets every text size as `font-size:var(--text-sm)`;
|
|
102
|
+
* reading that as "hidden" marked whole sites as hidden text.)
|
|
103
|
+
*/
|
|
104
|
+
function candidates(value, vars, depth = 0) {
|
|
105
|
+
const m = value.match(/var\((--[\w-]+)(?:,([^()]*(?:\([^()]*\)[^()]*)*))?\)/);
|
|
106
|
+
if (!m || depth > 4)
|
|
107
|
+
return [value];
|
|
108
|
+
const defs = [...(vars?.get(m[1]) ?? [])];
|
|
109
|
+
if (m[2] !== undefined && m[2] !== "")
|
|
110
|
+
defs.push(m[2]);
|
|
111
|
+
const out = [];
|
|
112
|
+
for (const d of defs.slice(0, 12))
|
|
113
|
+
out.push(...candidates(value.replace(m[0], d), vars, depth + 1));
|
|
114
|
+
return out.slice(0, 24);
|
|
115
|
+
}
|
|
116
|
+
const ZERO_ALPHA_COLOR = /^(?:transparent|rgba?\([^)]*[,/]0(?:\.0+)?%?\)|hsla?\([^)]*[,/]0(?:\.0+)?%?\)|#[0-9a-f]{6}00|#[0-9a-f]{3}0)$/;
|
|
117
|
+
const num = (v) => { const m = v.match(/^(-?\d*\.?\d+)(px|pt|em|rem|%|vw|vh)?$/); return m ? { n: Number(m[1]), unit: m[2] ?? "" } : undefined; };
|
|
118
|
+
/** One property with one concrete value: does it hide the element's text? */
|
|
119
|
+
function hidesByProperty(prop, v) {
|
|
120
|
+
switch (prop) {
|
|
121
|
+
case "display": return v === "none" ? "css_hidden" : null;
|
|
122
|
+
case "visibility": return v === "hidden" || v === "collapse" ? "css_hidden" : null;
|
|
123
|
+
case "content-visibility": return v === "hidden" ? "css_hidden" : null;
|
|
124
|
+
case "opacity": {
|
|
125
|
+
const x = num(v);
|
|
126
|
+
return x && (x.unit === "%" ? x.n < 10 : x.unit === "" && x.n < 0.1) ? "tiny_or_transparent" : null;
|
|
127
|
+
}
|
|
128
|
+
case "font-size": {
|
|
129
|
+
const x = num(v);
|
|
130
|
+
return x && x.n <= (x.unit === "em" || x.unit === "rem" ? 0.1 : x.unit === "%" ? 10 : 1) ? "tiny_or_transparent" : null;
|
|
131
|
+
}
|
|
132
|
+
case "color":
|
|
133
|
+
case "-webkit-text-fill-color": return ZERO_ALPHA_COLOR.test(v) ? "tiny_or_transparent" : null;
|
|
134
|
+
case "transform":
|
|
135
|
+
case "-webkit-transform":
|
|
136
|
+
if (/scale(x|y|3d)?\(0(\.0+)?[,)]/.test(v) || /scale(x|y)?\(0\.0\d/.test(v))
|
|
137
|
+
return "tiny_or_transparent";
|
|
138
|
+
return /translate(x|y|3d)?\(-?\d{3,}(px|em|rem|vw|vh)/.test(v) ? "offscreen" : null;
|
|
139
|
+
case "filter": return /opacity\(0(\.0\d*)?%?\)/.test(v) ? "tiny_or_transparent" : null;
|
|
140
|
+
case "scale": return /^0(\.0\d*)?($|[^\d.])/.test(v) ? "tiny_or_transparent" : null;
|
|
141
|
+
case "translate": return /^-?\d{3,}(px|em|rem|vw|vh|%)/.test(v) ? "offscreen" : null;
|
|
142
|
+
case "inset": return /-\d{3,}(px|em|rem|vw|vh|%)/.test(v) ? "offscreen" : null;
|
|
143
|
+
case "font": return /(^|[^\d.])0(px|pt|em|rem|%)?\//.test(v) || /^0(px)?(\/|$)/.test(v) ? "tiny_or_transparent" : null;
|
|
144
|
+
case "left":
|
|
145
|
+
case "top":
|
|
146
|
+
case "right":
|
|
147
|
+
case "bottom":
|
|
148
|
+
case "margin-left":
|
|
149
|
+
case "margin-top":
|
|
150
|
+
return /^-\d{3,}(px|em|rem|%|vw|vh)/.test(v) ? "offscreen" : null;
|
|
151
|
+
case "text-indent": return /^-\d{3,}(px|em|rem|%|vw|vh)/.test(v) || /^(1\d\d|[2-9]\d\d|\d{4,})%/.test(v) || /^\d{4,}px/.test(v) ? "offscreen" : null;
|
|
152
|
+
case "clip": return /^rect\(0(px)?,?0(px)?,?0(px)?,?0(px)?\)/.test(v) || /^rect\(1px,?1px,?1px,?1px\)/.test(v) ? "offscreen" : null;
|
|
153
|
+
case "clip-path": return /^(inset\(([4-9]\d|100)%|circle\(0|polygon\(0(px|%)?0)/.test(v) ? "offscreen" : null;
|
|
154
|
+
default: return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Classify a declaration block. Returns the hiding reason or null. Properties are matched by their exact
|
|
159
|
+
* names (so `-webkit-tap-highlight-color:transparent`, `background-color:rgba(0,0,0,0)` and
|
|
160
|
+
* `fill-opacity:0` hide nothing), and var() references are resolved against `vars` before judging.
|
|
161
|
+
*/
|
|
162
|
+
export function classifyStyle(style, vars) {
|
|
163
|
+
const d = parseDeclarations(style);
|
|
164
|
+
// variables this very block defines apply to it too (style="--o:0;opacity:var(--o)")
|
|
165
|
+
let scope = vars;
|
|
166
|
+
for (const [p, v] of d)
|
|
167
|
+
if (p.startsWith("--")) {
|
|
168
|
+
scope = scope === vars ? new Map(vars ?? []) : scope;
|
|
169
|
+
const s = new Set(scope.get(p) ?? []);
|
|
170
|
+
s.add(v);
|
|
171
|
+
scope.set(p, s);
|
|
172
|
+
}
|
|
173
|
+
for (const [prop, value] of d) {
|
|
174
|
+
if (prop.startsWith("--"))
|
|
175
|
+
continue;
|
|
176
|
+
for (const v of value.includes("var(") ? candidates(value, scope) : [value]) {
|
|
177
|
+
const r = hidesByProperty(prop, v);
|
|
178
|
+
if (r)
|
|
179
|
+
return r;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// combinations
|
|
183
|
+
const get = (p) => d.get(p) ?? "";
|
|
184
|
+
const zero = (p) => /^0(px)?$/.test(get(p));
|
|
185
|
+
const clips = get("overflow") === "hidden" || get("overflow-x") === "hidden" || get("overflow-y") === "hidden";
|
|
186
|
+
if (clips && (zero("width") || zero("height") || zero("max-height") || zero("max-width")))
|
|
65
187
|
return "offscreen";
|
|
66
|
-
if (
|
|
188
|
+
if (clips && (get("width") === "1px" || get("height") === "1px") && get("position") === "absolute")
|
|
67
189
|
return "offscreen";
|
|
68
|
-
if (
|
|
190
|
+
if (/^(absolute|fixed)$/.test(get("position")) && (/^\d{4,}(px|vw|vh)/.test(get("left")) || /^\d{4,}(px|vw|vh)/.test(get("top"))))
|
|
69
191
|
return "offscreen";
|
|
70
192
|
return null;
|
|
71
193
|
}
|
|
72
|
-
|
|
194
|
+
/** Split a selector list on commas that are not inside parentheses or brackets (`:is(.a, .b)` is one selector). */
|
|
195
|
+
function splitSelectors(list) {
|
|
196
|
+
const out = [];
|
|
197
|
+
let depth = 0, start = 0;
|
|
198
|
+
for (let i = 0; i < list.length; i++) {
|
|
199
|
+
const c = list[i];
|
|
200
|
+
if (c === "(" || c === "[")
|
|
201
|
+
depth++;
|
|
202
|
+
else if (c === ")" || c === "]")
|
|
203
|
+
depth = Math.max(0, depth - 1);
|
|
204
|
+
else if (c === "," && depth === 0) {
|
|
205
|
+
out.push(list.slice(start, i));
|
|
206
|
+
start = i + 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
out.push(list.slice(start));
|
|
210
|
+
return out.map((s) => s.trim()).filter(Boolean);
|
|
211
|
+
}
|
|
212
|
+
/** an ancestor that names a theme, a state or a script-set class: the rule applies in one mode of the page, not always */
|
|
213
|
+
const CONDITIONAL_ANCESTOR = /(^|[.#\[="'_-])(dark|light|theme|mode|print|no-?js|js|open|opened|closed|active|inactive|collapsed|expanded|loading|loaded|ready|is-|has-)/i;
|
|
214
|
+
/**
|
|
215
|
+
* Turn one selector into a rule the static pass can apply, or nothing when the selector does not describe
|
|
216
|
+
* what a reader at a desktop sees by default:
|
|
217
|
+
* - a pseudo-element (`::-webkit-scrollbar`, `::before`) styles another box, not the element's text.
|
|
218
|
+
* `.scroll::-webkit-scrollbar{display:none}` hides a scrollbar; read as hiding `.scroll`, it hid every
|
|
219
|
+
* table on a documentation page.
|
|
220
|
+
* - a state (`:hover`, `:checked`, `[data-state=closed]`, `[hidden]`) holds only sometimes. The `hidden`
|
|
221
|
+
* attribute itself is handled where elements are read.
|
|
222
|
+
* - an ancestor that names a theme or a state makes the rule one mode of the page.
|
|
223
|
+
* `:not(.class)` on the element is kept and checked (`.collapse:not(.show)`).
|
|
224
|
+
*/
|
|
225
|
+
function ruleFromSelector(sel, reason) {
|
|
226
|
+
if (/^[.#]?[\w-]+$/.test(sel))
|
|
227
|
+
return { selector: sel, reason };
|
|
228
|
+
const parts = sel.replace(/\s*([>+~])\s*/g, " $1 ").split(/\s+/).filter((p) => p && !/^[>+~]$/.test(p));
|
|
229
|
+
const last = parts.pop() ?? "";
|
|
230
|
+
if (/::|:(before|after|first-line|first-letter|placeholder|marker|selection|backdrop|file-selector-button)\b/i.test(last))
|
|
231
|
+
return null;
|
|
232
|
+
if (last.includes("\\"))
|
|
233
|
+
return null; // an escaped name (`.lg\:hidden`): a variant class, read from the class list instead
|
|
234
|
+
const nots = [...last.matchAll(/:not\(\.([\w-]+)\)/g)].map((m) => m[1]);
|
|
235
|
+
const bare = last.replace(/:not\(\.[\w-]+\)/g, "");
|
|
236
|
+
if (/[:\[()*]/.test(bare))
|
|
237
|
+
return null; // any other pseudo-class or attribute test: a state
|
|
238
|
+
if (parts.some((a) => /[:\[\\]/.test(a) || CONDITIONAL_ANCESTOR.test(a)))
|
|
239
|
+
return null;
|
|
240
|
+
const classes = (bare.match(/\.[\w-]+/g) ?? []).map((c) => c.slice(1));
|
|
241
|
+
const id = bare.match(/#([\w-]+)/)?.[1];
|
|
242
|
+
const tag = bare.match(/^[a-z][\w-]*/i)?.[0]?.toLowerCase();
|
|
243
|
+
if (id)
|
|
244
|
+
return { selector: `#${id}`, reason, all: classes, not: nots, tag };
|
|
245
|
+
if (classes.length)
|
|
246
|
+
return { selector: `.${classes[classes.length - 1]}`, reason, all: classes.slice(0, -1), not: nots, tag };
|
|
247
|
+
if (tag && parts.length)
|
|
248
|
+
return null; // `nav ul`: a tag under an ancestor over-matches every such tag on the page
|
|
249
|
+
return tag ? { selector: tag, reason, not: nots } : null;
|
|
250
|
+
}
|
|
251
|
+
export function rulesFromCss(cssIn, extraVars) {
|
|
73
252
|
const rules = [];
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
253
|
+
// media blocks that do not describe a desktop screen are dropped; the rest of the @-wrappers are flattened:
|
|
254
|
+
// "@media x { a{..} }" -> "a{..}". Keyframes and comments are dropped.
|
|
255
|
+
const css = dropAlternateMedia(cssIn.replace(/\/\*[\s\S]*?\*\//g, ""))
|
|
77
256
|
.replace(/@keyframes[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/g, "")
|
|
78
257
|
.replace(/@(media|supports|layer|container)[^{]*\{/g, "");
|
|
258
|
+
// custom properties defined anywhere in this stylesheet, so var() references can be resolved before judging
|
|
259
|
+
const vars = collectCssVars(css, new Map(extraVars ?? []));
|
|
79
260
|
const re = /([^{}]+)\{([^{}]*)\}/g;
|
|
80
261
|
let m;
|
|
81
262
|
let count = 0;
|
|
82
263
|
while ((m = re.exec(css)) && count++ < 20000) {
|
|
83
|
-
const reason = classifyStyle(m[2]);
|
|
264
|
+
const reason = classifyStyle(m[2], vars);
|
|
84
265
|
if (!reason)
|
|
85
266
|
continue;
|
|
86
|
-
for (const sel of m[1]
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
rules.push(
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
// compound/descendant selectors: key on the last simple class or id; over-matching only raises suspicion
|
|
93
|
-
const last = t.split(/[\s>+~]+/).pop() ?? "";
|
|
94
|
-
const simple = last.match(/[.#][\w-]+/g);
|
|
95
|
-
if (simple)
|
|
96
|
-
rules.push({ selector: simple[simple.length - 1], reason });
|
|
267
|
+
for (const sel of splitSelectors(m[1])) {
|
|
268
|
+
const r = ruleFromSelector(sel, reason);
|
|
269
|
+
if (r)
|
|
270
|
+
rules.push(r);
|
|
97
271
|
}
|
|
98
272
|
}
|
|
99
273
|
return rules;
|
|
100
274
|
}
|
|
101
|
-
/**
|
|
275
|
+
/** widths below this are phones and small tablets: `@media (max-width: 767px)` does not describe a desktop screen */
|
|
276
|
+
const DESKTOP_MIN_PX = 1024;
|
|
277
|
+
function isAlternateMedia(query) {
|
|
278
|
+
const q = query.toLowerCase();
|
|
279
|
+
if (/prefers-color-scheme\s*:\s*dark|\bprint\b|forced-colors|prefers-contrast|prefers-reduced-(motion|transparency)|\(\s*hover\s*:\s*none\s*\)|\(\s*pointer\s*:\s*coarse\s*\)|orientation\s*:\s*portrait/.test(q))
|
|
280
|
+
return true;
|
|
281
|
+
// a width cap below desktop: `max-width: 767px`, `width <= 40rem`, `width < 640px`
|
|
282
|
+
for (const m of q.matchAll(/(?:max-width\s*:|width\s*<=?)\s*(\d*\.?\d+)(px|em|rem)/g)) {
|
|
283
|
+
const px = Number(m[1]) * (m[2] === "px" ? 1 : 16);
|
|
284
|
+
if (px < DESKTOP_MIN_PX)
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
/** Remove @media blocks that do not describe the default desktop screen (dark mode, print, phone widths), brace-matched. */
|
|
102
290
|
function dropAlternateMedia(css) {
|
|
103
291
|
let out = "", i = 0;
|
|
104
|
-
const re = /@media[^{]*
|
|
292
|
+
const re = /@media([^{]*)\{/gi;
|
|
105
293
|
let m;
|
|
106
294
|
while ((m = re.exec(css))) {
|
|
295
|
+
if (!isAlternateMedia(m[1]))
|
|
296
|
+
continue;
|
|
107
297
|
out += css.slice(i, m.index);
|
|
108
298
|
let depth = 1, j = m.index + m[0].length;
|
|
109
299
|
while (j < css.length && depth > 0) {
|
|
@@ -153,10 +343,15 @@ function attr(el, name) {
|
|
|
153
343
|
return el.attrs.find((a) => a.name === name)?.value;
|
|
154
344
|
}
|
|
155
345
|
function matchesRule(el, rule) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return
|
|
159
|
-
|
|
346
|
+
const classes = (attr(el, "class") ?? "").split(/\s+/);
|
|
347
|
+
if (rule.tag && rule.selector !== rule.tag && el.tagName !== rule.tag)
|
|
348
|
+
return false;
|
|
349
|
+
if (rule.all?.some((c) => !classes.includes(c)))
|
|
350
|
+
return false;
|
|
351
|
+
if (rule.not?.some((c) => classes.includes(c)))
|
|
352
|
+
return false;
|
|
353
|
+
if (rule.selector.startsWith("."))
|
|
354
|
+
return classes.includes(rule.selector.slice(1));
|
|
160
355
|
if (rule.selector.startsWith("#"))
|
|
161
356
|
return attr(el, "id") === rule.selector.slice(1);
|
|
162
357
|
return el.tagName === rule.selector;
|
|
@@ -195,6 +390,9 @@ export function analyzeHtml(html, externalRules = [], externalColorRules = []) {
|
|
|
195
390
|
const lowContrast = new Map();
|
|
196
391
|
const lowContrastRatio = new Map();
|
|
197
392
|
let maxDepth = 0;
|
|
393
|
+
/** custom properties defined in the page's own <style> blocks and style attributes */
|
|
394
|
+
const cssVars = new Map();
|
|
395
|
+
const styleBlocks = [];
|
|
198
396
|
// pass 1: <style> rules and stylesheet links (iterative)
|
|
199
397
|
{
|
|
200
398
|
const stack = [doc];
|
|
@@ -203,15 +401,23 @@ export function analyzeHtml(html, externalRules = [], externalColorRules = []) {
|
|
|
203
401
|
if (defaultTreeAdapter.isElementNode(n)) {
|
|
204
402
|
if (n.tagName === "style") {
|
|
205
403
|
const css = n.childNodes.map((c) => (defaultTreeAdapter.isTextNode(c) ? c.value : "")).join("");
|
|
206
|
-
|
|
404
|
+
styleBlocks.push(css);
|
|
405
|
+
collectCssVars(css, cssVars);
|
|
207
406
|
colorRules.push(...colorRulesFromCss(css));
|
|
208
407
|
}
|
|
408
|
+
// a custom property set in a style attribute can drive a rule elsewhere (style="--o:0" with opacity:var(--o))
|
|
409
|
+
const inline = attr(n, "style");
|
|
410
|
+
if (inline && inline.includes("--"))
|
|
411
|
+
collectCssVars(inline, cssVars);
|
|
209
412
|
if (n.tagName === "link" && /\bstylesheet\b/.test((attr(n, "rel") ?? "").toLowerCase()) && attr(n, "href"))
|
|
210
413
|
stylesheetLinks.push(attr(n, "href"));
|
|
211
414
|
}
|
|
212
415
|
for (const c of children(n))
|
|
213
416
|
stack.push(c);
|
|
214
417
|
}
|
|
418
|
+
// rules are classified once every variable the page defines is known, wherever it was defined
|
|
419
|
+
for (const css of styleBlocks)
|
|
420
|
+
styleRules.push(...rulesFromCss(css, cssVars));
|
|
215
421
|
}
|
|
216
422
|
// pass 2: segments and scripts (iterative, document order)
|
|
217
423
|
let scriptIndex = 0;
|
|
@@ -360,20 +566,20 @@ export function analyzeHtml(html, externalRules = [], externalColorRules = []) {
|
|
|
360
566
|
vis = "css_hidden";
|
|
361
567
|
const style = attr(el, "style");
|
|
362
568
|
if (style)
|
|
363
|
-
vis = classifyStyle(style) ?? vis;
|
|
569
|
+
vis = classifyStyle(style, cssVars) ?? vis;
|
|
364
570
|
if (vis === "visible")
|
|
365
571
|
for (const r of styleRules)
|
|
366
572
|
if (matchesRule(el, r)) {
|
|
367
573
|
vis = r.reason;
|
|
368
574
|
break;
|
|
369
575
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
576
|
+
if (vis === "visible") {
|
|
577
|
+
const h = classHides(attr(el, "class") ?? "");
|
|
578
|
+
if (h) {
|
|
579
|
+
vis = h.vis;
|
|
580
|
+
a11y = a11y || h.a11y;
|
|
581
|
+
}
|
|
374
582
|
}
|
|
375
|
-
if (vis === "visible" && HIDDEN_CLASS_HINTS.test(cls))
|
|
376
|
-
vis = "css_hidden";
|
|
377
583
|
}
|
|
378
584
|
const kids = el.childNodes;
|
|
379
585
|
for (let i = kids.length - 1; i >= 0; i--) {
|
|
@@ -390,6 +596,7 @@ export function analyzeHtml(html, externalRules = [], externalColorRules = []) {
|
|
|
390
596
|
attribute: "visibility.attribute_only",
|
|
391
597
|
comment: "visibility.html_comment",
|
|
392
598
|
tiny_or_transparent: "visibility.tiny_or_transparent",
|
|
599
|
+
concealed: "visibility.css_hidden", // not produced by the HTML pass; here so the map is total
|
|
393
600
|
};
|
|
394
601
|
for (const s of segments) {
|
|
395
602
|
if (s.visibility === "visible")
|