@react-x11/components 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html/css/cascade.d.ts +42 -1
- package/dist/html/css/cascade.d.ts.map +1 -1
- package/dist/html/css/cascade.js +310 -12
- package/dist/html/css/cascade.js.map +1 -1
- package/dist/html/css/shapes.d.ts +44 -0
- package/dist/html/css/shapes.d.ts.map +1 -0
- package/dist/html/css/shapes.js +194 -0
- package/dist/html/css/shapes.js.map +1 -0
- package/dist/html/css/style.d.ts.map +1 -1
- package/dist/html/css/style.js +1 -15
- package/dist/html/css/style.js.map +1 -1
- package/dist/html/layout/block.d.ts +16 -5
- package/dist/html/layout/block.d.ts.map +1 -1
- package/dist/html/layout/block.js +26 -5
- package/dist/html/layout/block.js.map +1 -1
- package/dist/html/layout/boxes.d.ts +13 -0
- package/dist/html/layout/boxes.d.ts.map +1 -1
- package/dist/html/layout/boxes.js +18 -0
- package/dist/html/layout/boxes.js.map +1 -1
- package/dist/html/layout/css-grid.d.ts.map +1 -1
- package/dist/html/layout/css-grid.js +58 -10
- package/dist/html/layout/css-grid.js.map +1 -1
- package/dist/html/layout/flex.js +19 -6
- package/dist/html/layout/flex.js.map +1 -1
- package/dist/html/layout/table.d.ts.map +1 -1
- package/dist/html/layout/table.js +38 -16
- package/dist/html/layout/table.js.map +1 -1
- package/dist/html/node.d.ts +1 -0
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +57 -12
- package/dist/html/node.js.map +1 -1
- package/dist/html/paint.d.ts +4 -1
- package/dist/html/paint.d.ts.map +1 -1
- package/dist/html/paint.js +269 -84
- package/dist/html/paint.js.map +1 -1
- package/dist/html/svg.d.ts +27 -10
- package/dist/html/svg.d.ts.map +1 -1
- package/dist/html/svg.js +259 -46
- package/dist/html/svg.js.map +1 -1
- package/package.json +1 -1
- package/src/html/css/cascade.ts +343 -8
- package/src/html/css/shapes.ts +239 -0
- package/src/html/css/style.ts +1 -13
- package/src/html/layout/block.ts +27 -5
- package/src/html/layout/boxes.ts +30 -0
- package/src/html/layout/css-grid.ts +77 -13
- package/src/html/layout/flex.ts +22 -9
- package/src/html/layout/table.ts +45 -18
- package/src/html/node.ts +54 -11
- package/src/html/paint.ts +379 -90
- package/src/html/svg.ts +318 -39
|
@@ -3,6 +3,7 @@ import type { Stylesheet } from './parse.js';
|
|
|
3
3
|
import type { ComputedStyle, RootLook } from './style.js';
|
|
4
4
|
import type { FontFamilies } from '../fonts.js';
|
|
5
5
|
import { CounterStyles } from './counter-styles.js';
|
|
6
|
+
import type { ShapeStyles } from './shapes.js';
|
|
6
7
|
/** A style handed to every element with the same sharing key, and the key
|
|
7
8
|
* that element's children share under (`Cascade.sharedStyleFor`). */
|
|
8
9
|
export interface SharedStyle {
|
|
@@ -121,6 +122,13 @@ export declare class Cascade {
|
|
|
121
122
|
/** The rules for pseudo-elements, kept apart: they never style the
|
|
122
123
|
* element itself, and a document with none of them asks nothing. */
|
|
123
124
|
private _pseudo;
|
|
125
|
+
/** The author's rules that could style a shape in a drawing: the ones
|
|
126
|
+
* that declare a property a shape has (`shapes.ts`) and whose subject
|
|
127
|
+
* is no element of HTML's alone. They are in `_index` too, for the
|
|
128
|
+
* elements that have boxes; these are asked of the ones in an inline
|
|
129
|
+
* `<svg>`, which have none (`shapeStyles`). */
|
|
130
|
+
private _shapes;
|
|
131
|
+
private _shapeNeeds;
|
|
124
132
|
private _adapter;
|
|
125
133
|
/** The compounds of the selectors that test the pointer, each without
|
|
126
134
|
* its `:hover` or `:active` (`pointerCompounds`), and their matchers,
|
|
@@ -184,7 +192,12 @@ export declare class Cascade {
|
|
|
184
192
|
/** Whether any declaration has a length in `lh` or `rlh`: only then is
|
|
185
193
|
* the line height settled ahead of the declarations that read it. */
|
|
186
194
|
private _lh;
|
|
187
|
-
|
|
195
|
+
/** The pseudo-classes css-select is handed, `:root` this cascade's. */
|
|
196
|
+
private _pseudos;
|
|
197
|
+
constructor(sheets: Stylesheet[], look: RootLook, viewportWidth: number, viewportHeight: number, scale?: number, xHeight?: FaceMetric | null, zeroWidth?: FaceMetric | null, normalLine?: FaceMetric | null, families?: FontFamilies | null,
|
|
198
|
+
/** The document's element where it is not an `<html>`: an SVG image's
|
|
199
|
+
* `<svg>`, which is `:root` there (Selectors 4, 14.1). */
|
|
200
|
+
documentElement?: Element | null);
|
|
188
201
|
/** Whether declarations read the viewport's width or height (`vw`,
|
|
189
202
|
* `vh`, `vmin`, `vmax`), noted on the cascade. */
|
|
190
203
|
private _noteViewportUnits;
|
|
@@ -403,6 +416,34 @@ export declare class Cascade {
|
|
|
403
416
|
style: ComputedStyle;
|
|
404
417
|
html: ComputedStyle | null;
|
|
405
418
|
};
|
|
419
|
+
/** Whether any rule could style a shape in a drawing: a document with
|
|
420
|
+
* none asks nothing of its drawings (`shapeStyles`). */
|
|
421
|
+
get stylesShapes(): boolean;
|
|
422
|
+
/** Whether a pointer move can change what a rule gives a shape in a
|
|
423
|
+
* drawing. */
|
|
424
|
+
get shapesFollowPointer(): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* What the rules give the elements of an inline drawing, `root` and what
|
|
427
|
+
* is in it, or null where none reaches one: the narrow cascade of
|
|
428
|
+
* `shapes.ts`. `style` is the root's computed style — its `color`, its
|
|
429
|
+
* custom properties and its font size are what a value in the drawing is
|
|
430
|
+
* read against, as though every element in it had inherited them, which
|
|
431
|
+
* all but one a rule gives its own has.
|
|
432
|
+
*
|
|
433
|
+
* An element's rules and its `style` attribute are put in cascade order,
|
|
434
|
+
* and each property is the last valid declaration's. The presentation
|
|
435
|
+
* attributes are below them all (SVG 2, 6.2), and `SvgView` reads those
|
|
436
|
+
* itself. The root's box has its paint, its opacity and whether it is
|
|
437
|
+
* shown from its computed style, so those are left out for it.
|
|
438
|
+
*
|
|
439
|
+
* Asked as a drawing is first painted (`BoxTree.shapeStyler`), of the
|
|
440
|
+
* rules in `_shapes` alone: a page of hundreds of icons pays for the ones
|
|
441
|
+
* it shows, a look in the buckets for each of their elements where no
|
|
442
|
+
* rule reaches them, and a document with no such rule nothing.
|
|
443
|
+
*/
|
|
444
|
+
shapeStyles(root: Element, style: ComputedStyle): ShapeStyles | null;
|
|
445
|
+
/** `ShapeNeeds`, and each such rule's own (`IndexedRule.needs`). */
|
|
446
|
+
private _needsOfShapes;
|
|
406
447
|
/**
|
|
407
448
|
* Whether the pointer's move from `was` to where it is changed which
|
|
408
449
|
* rules match `el`, or its `::before`, `::after` or another of its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cascade.d.ts","sourceRoot":"","sources":["../../../src/html/css/cascade.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cascade.d.ts","sourceRoot":"","sources":["../../../src/html/css/cascade.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAU1C,OAAO,KAAK,EAA0B,UAAU,EAAE,MAAM,YAAY,CAAC;AAerE,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAoB,MAAM,qBAAqB,CAAC;AAatE,OAAO,KAAK,EAA4B,WAAW,EAAE,MAAM,aAAa,CAAC;AAmCzE;sEACsE;AACtE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,aAAa,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACxE,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC/B;AAED;;uCAEuC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AC,WAAW;CAkDpB"}
|
package/dist/html/css/cascade.js
CHANGED
|
@@ -19,7 +19,6 @@ import { compile } from 'css-select';
|
|
|
19
19
|
import * as DomUtils from 'domutils';
|
|
20
20
|
import { Element as DomElement, isTag } from 'domhandler';
|
|
21
21
|
import { attr, tagOf } from '../dom.js';
|
|
22
|
-
import { svgSizeHint } from '../svg.js';
|
|
23
22
|
import { asciiLower, escapeEnd, mediaMatches, readIdent, startsIdent, } from './parse.js';
|
|
24
23
|
import { applyDeclaration, blockify, settleButton, settleContentVisibility, settleOverflow, settleClamp, copyStyle, decorate, inherit, initialOne, initialStyle, isInherited, } from './style.js';
|
|
25
24
|
import { parseDeclarations } from './parse.js';
|
|
@@ -27,6 +26,7 @@ import { CounterStyles, counterStyleRule } from './counter-styles.js';
|
|
|
27
26
|
import { PALETTE_CHROME } from './ua.js';
|
|
28
27
|
import { viewportUnit } from './values.js';
|
|
29
28
|
import { customProperties, substituteIn } from './vars.js';
|
|
29
|
+
import { ROOT_BOX_PROPS, SHAPE_TAGS, isShapeProp, shapeValue, } from './shapes.js';
|
|
30
30
|
/** Where a declaration came from. Higher wins before specificity is asked. */
|
|
31
31
|
var Origin;
|
|
32
32
|
(function (Origin) {
|
|
@@ -104,6 +104,10 @@ class RuleIndex {
|
|
|
104
104
|
reaches(el) {
|
|
105
105
|
if (this.universal.length || this.byTag.has(tagOf(el)))
|
|
106
106
|
return true;
|
|
107
|
+
return this.names(el);
|
|
108
|
+
}
|
|
109
|
+
/** Whether a bucket here is for `el`'s id, or for a class of its. */
|
|
110
|
+
names(el) {
|
|
107
111
|
if (this.byId.size) {
|
|
108
112
|
const id = attr(el, 'id');
|
|
109
113
|
if (id && this.byId.has(id))
|
|
@@ -120,18 +124,19 @@ class RuleIndex {
|
|
|
120
124
|
}
|
|
121
125
|
return false;
|
|
122
126
|
}
|
|
123
|
-
add(rule) {
|
|
127
|
+
add(rule, key = rightmostKey(rule.selector)) {
|
|
124
128
|
this.size += 1;
|
|
125
129
|
const indexed = {
|
|
126
130
|
rule,
|
|
127
131
|
match: null,
|
|
128
132
|
compiled: false,
|
|
129
133
|
id: this._nextId++,
|
|
134
|
+
needs: null,
|
|
135
|
+
root: null,
|
|
130
136
|
};
|
|
131
137
|
if (rule.selector.includes(':hover') || rule.selector.includes(':active')) {
|
|
132
138
|
this.hoverSensitive = true;
|
|
133
139
|
}
|
|
134
|
-
const key = rightmostKey(rule.selector);
|
|
135
140
|
if (UNSHAREABLE.test(rule.selector)) {
|
|
136
141
|
if (key.kind === 'id')
|
|
137
142
|
this.ownStyleIds.add(key.name);
|
|
@@ -476,11 +481,11 @@ const POINTER_PSEUDO = /:(?:hover|active)(?![\w-])/i;
|
|
|
476
481
|
* `#box:has(a:hover) .m` answered what it did before the first move, for
|
|
477
482
|
* good.
|
|
478
483
|
*/
|
|
479
|
-
function compileSelector(selector, adapter) {
|
|
484
|
+
function compileSelector(selector, adapter, pseudos = PSEUDOS) {
|
|
480
485
|
return compile(noEmptyWords(selector), {
|
|
481
486
|
adapter,
|
|
482
487
|
xmlMode: false,
|
|
483
|
-
pseudos
|
|
488
|
+
pseudos,
|
|
484
489
|
cacheResults: !POINTER_PSEUDO.test(selector),
|
|
485
490
|
});
|
|
486
491
|
}
|
|
@@ -534,7 +539,10 @@ function rightmostKey(selector) {
|
|
|
534
539
|
start = i + 1;
|
|
535
540
|
}
|
|
536
541
|
}
|
|
537
|
-
|
|
542
|
+
return compoundKey(selector.slice(start));
|
|
543
|
+
}
|
|
544
|
+
/** A compound selector's most selective key (`rightmostKey`). */
|
|
545
|
+
function compoundKey(compound) {
|
|
538
546
|
let id = null;
|
|
539
547
|
let cls = null;
|
|
540
548
|
let tag = null;
|
|
@@ -577,6 +585,29 @@ function rightmostKey(selector) {
|
|
|
577
585
|
return { kind: 'tag', name: tag };
|
|
578
586
|
return { kind: 'any', name: '' };
|
|
579
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* The ids and classes a selector asks of its subject's ancestors: for each
|
|
590
|
+
* compound a descendant or a child combinator follows, its id, or else its
|
|
591
|
+
* first class, as `#name` or `.name`. Such a compound is an ancestor of
|
|
592
|
+
* the subject — one a sibling combinator follows is a sibling of one — so
|
|
593
|
+
* an element with no ancestor of some such name is not the rule's, which
|
|
594
|
+
* is known without matching it. A compound with neither asks nothing.
|
|
595
|
+
*/
|
|
596
|
+
function ancestorKeys(selector) {
|
|
597
|
+
const keys = [];
|
|
598
|
+
const compounds = compoundsOf(selector);
|
|
599
|
+
for (let i = 0; i < compounds.length - 1; i += 1) {
|
|
600
|
+
const { text, next } = compounds[i];
|
|
601
|
+
if (next !== ' ' && next !== '>')
|
|
602
|
+
continue;
|
|
603
|
+
const key = compoundKey(text);
|
|
604
|
+
if (key.kind === 'id')
|
|
605
|
+
keys.push(`#${key.name}`);
|
|
606
|
+
else if (key.kind === 'class')
|
|
607
|
+
keys.push(`.${key.name}`);
|
|
608
|
+
}
|
|
609
|
+
return keys;
|
|
610
|
+
}
|
|
580
611
|
function balancedEnd(text, from, open, close) {
|
|
581
612
|
let depth = 0;
|
|
582
613
|
for (let i = from; i < text.length; i += 1) {
|
|
@@ -618,6 +649,13 @@ export class Cascade {
|
|
|
618
649
|
marker: new RuleIndex(),
|
|
619
650
|
selection: new RuleIndex(),
|
|
620
651
|
};
|
|
652
|
+
/** The author's rules that could style a shape in a drawing: the ones
|
|
653
|
+
* that declare a property a shape has (`shapes.ts`) and whose subject
|
|
654
|
+
* is no element of HTML's alone. They are in `_index` too, for the
|
|
655
|
+
* elements that have boxes; these are asked of the ones in an inline
|
|
656
|
+
* `<svg>`, which have none (`shapeStyles`). */
|
|
657
|
+
_shapes = new RuleIndex();
|
|
658
|
+
_shapeNeeds = null;
|
|
621
659
|
_adapter;
|
|
622
660
|
/** The compounds of the selectors that test the pointer, each without
|
|
623
661
|
* its `:hover` or `:active` (`pointerCompounds`), and their matchers,
|
|
@@ -681,7 +719,15 @@ export class Cascade {
|
|
|
681
719
|
/** Whether any declaration has a length in `lh` or `rlh`: only then is
|
|
682
720
|
* the line height settled ahead of the declarations that read it. */
|
|
683
721
|
_lh = false;
|
|
684
|
-
|
|
722
|
+
/** The pseudo-classes css-select is handed, `:root` this cascade's. */
|
|
723
|
+
_pseudos;
|
|
724
|
+
constructor(sheets, look, viewportWidth, viewportHeight, scale = 1, xHeight = null, zeroWidth = null, normalLine = null, families = null,
|
|
725
|
+
/** The document's element where it is not an `<html>`: an SVG image's
|
|
726
|
+
* `<svg>`, which is `:root` there (Selectors 4, 14.1). */
|
|
727
|
+
documentElement = null) {
|
|
728
|
+
this._pseudos = documentElement
|
|
729
|
+
? { ...PSEUDOS, root: (el) => el === documentElement }
|
|
730
|
+
: PSEUDOS;
|
|
685
731
|
this._xHeightOf = xHeight;
|
|
686
732
|
this._zeroWidthOf = zeroWidth;
|
|
687
733
|
this._normalLineOf = normalLine;
|
|
@@ -712,8 +758,15 @@ export class Cascade {
|
|
|
712
758
|
const pseudo = splitPseudoElement(rule);
|
|
713
759
|
if (pseudo)
|
|
714
760
|
this._pseudo[pseudo.which].add(pseudo.rule);
|
|
715
|
-
else
|
|
716
|
-
|
|
761
|
+
else {
|
|
762
|
+
const key = rightmostKey(rule.selector);
|
|
763
|
+
this._index.add(rule, key);
|
|
764
|
+
if (rule.order >= 0 &&
|
|
765
|
+
(key.kind !== 'tag' || SHAPE_TAGS.has(key.name)) &&
|
|
766
|
+
declaresShape(rule.declarations)) {
|
|
767
|
+
this._shapes.add(rule, key);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
717
770
|
this._noteHover((pseudo?.rule ?? rule).selector);
|
|
718
771
|
}
|
|
719
772
|
for (const bp of sheet.breakpoints)
|
|
@@ -888,7 +941,7 @@ export class Cascade {
|
|
|
888
941
|
* it, as a rule it refuses drops out of the cascade. */
|
|
889
942
|
_compile(selector) {
|
|
890
943
|
try {
|
|
891
|
-
return compileSelector(selector, this._adapter);
|
|
944
|
+
return compileSelector(selector, this._adapter, this._pseudos);
|
|
892
945
|
}
|
|
893
946
|
catch {
|
|
894
947
|
return null;
|
|
@@ -1527,6 +1580,187 @@ export class Cascade {
|
|
|
1527
1580
|
// the root is still the initial containing block.
|
|
1528
1581
|
return { style: asRoot(this.styleFor(synthetic, parent, false)), html };
|
|
1529
1582
|
}
|
|
1583
|
+
/** Whether any rule could style a shape in a drawing: a document with
|
|
1584
|
+
* none asks nothing of its drawings (`shapeStyles`). */
|
|
1585
|
+
get stylesShapes() {
|
|
1586
|
+
return this._shapes.size > 0;
|
|
1587
|
+
}
|
|
1588
|
+
/** Whether a pointer move can change what a rule gives a shape in a
|
|
1589
|
+
* drawing. */
|
|
1590
|
+
get shapesFollowPointer() {
|
|
1591
|
+
return this._shapes.hoverSensitive;
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* What the rules give the elements of an inline drawing, `root` and what
|
|
1595
|
+
* is in it, or null where none reaches one: the narrow cascade of
|
|
1596
|
+
* `shapes.ts`. `style` is the root's computed style — its `color`, its
|
|
1597
|
+
* custom properties and its font size are what a value in the drawing is
|
|
1598
|
+
* read against, as though every element in it had inherited them, which
|
|
1599
|
+
* all but one a rule gives its own has.
|
|
1600
|
+
*
|
|
1601
|
+
* An element's rules and its `style` attribute are put in cascade order,
|
|
1602
|
+
* and each property is the last valid declaration's. The presentation
|
|
1603
|
+
* attributes are below them all (SVG 2, 6.2), and `SvgView` reads those
|
|
1604
|
+
* itself. The root's box has its paint, its opacity and whether it is
|
|
1605
|
+
* shown from its computed style, so those are left out for it.
|
|
1606
|
+
*
|
|
1607
|
+
* Asked as a drawing is first painted (`BoxTree.shapeStyler`), of the
|
|
1608
|
+
* rules in `_shapes` alone: a page of hundreds of icons pays for the ones
|
|
1609
|
+
* it shows, a look in the buckets for each of their elements where no
|
|
1610
|
+
* rule reaches them, and a document with no such rule nothing.
|
|
1611
|
+
*/
|
|
1612
|
+
shapeStyles(root, style) {
|
|
1613
|
+
const index = this._shapes;
|
|
1614
|
+
if (!index.size)
|
|
1615
|
+
return null;
|
|
1616
|
+
// The rules kept by a class or an id are asked of the elements with
|
|
1617
|
+
// that name. The rest — `.dark .logo path`, `.menu [aria-hidden]` — are
|
|
1618
|
+
// asked of every `<path>`, or of every element, and nearly all of them
|
|
1619
|
+
// are for some other part of the page: each says so by the class or the
|
|
1620
|
+
// id it asks of an ancestor, which is looked for once for the drawing,
|
|
1621
|
+
// around it and in it, where matching the rule would look for it from
|
|
1622
|
+
// each of its elements. On a page with none of them around a drawing,
|
|
1623
|
+
// nothing is matched at all.
|
|
1624
|
+
const needs = (this._shapeNeeds ??= this._needsOfShapes());
|
|
1625
|
+
const found = new Set();
|
|
1626
|
+
const asks = needs.classes.size > 0 || needs.ids.size > 0;
|
|
1627
|
+
const note = (el) => {
|
|
1628
|
+
if (needs.ids.size) {
|
|
1629
|
+
const id = attr(el, 'id');
|
|
1630
|
+
if (id && needs.ids.has(id))
|
|
1631
|
+
found.add(`#${id}`);
|
|
1632
|
+
}
|
|
1633
|
+
if (needs.classes.size) {
|
|
1634
|
+
const className = attr(el, 'class');
|
|
1635
|
+
if (className) {
|
|
1636
|
+
for (const name of className.split(/\s+/)) {
|
|
1637
|
+
if (needs.classes.has(name))
|
|
1638
|
+
found.add(`.${name}`);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
if (asks) {
|
|
1644
|
+
let at = root.parent;
|
|
1645
|
+
while (at && at.type === 'tag') {
|
|
1646
|
+
note(at);
|
|
1647
|
+
at = at.parent;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
const live = (indexed) => {
|
|
1651
|
+
const keys = indexed.needs;
|
|
1652
|
+
if (keys)
|
|
1653
|
+
for (const key of keys)
|
|
1654
|
+
if (!found.has(key))
|
|
1655
|
+
return false;
|
|
1656
|
+
return true;
|
|
1657
|
+
};
|
|
1658
|
+
// The root's box has its paint from its computed style, so most of the
|
|
1659
|
+
// rules that name a drawing by its class — an icon set's — have
|
|
1660
|
+
// nothing else to say of it.
|
|
1661
|
+
const liveForRoot = (indexed) => (indexed.root ??= declaresRootShape(indexed.rule.declarations)) &&
|
|
1662
|
+
live(indexed);
|
|
1663
|
+
let of = null;
|
|
1664
|
+
let key = '';
|
|
1665
|
+
let ctx = null;
|
|
1666
|
+
// in document order, the root first: an element's place in it is what
|
|
1667
|
+
// the key names it by, and its ancestors in the drawing are noted
|
|
1668
|
+
// before it is asked of
|
|
1669
|
+
const stack = [root];
|
|
1670
|
+
let place = -1;
|
|
1671
|
+
while (stack.length) {
|
|
1672
|
+
const el = stack.pop();
|
|
1673
|
+
place += 1;
|
|
1674
|
+
// what is in a `<foreignObject>` is not the drawing's to draw
|
|
1675
|
+
if (el.name !== 'foreignobject' && el.name !== 'foreignObject') {
|
|
1676
|
+
const children = el.children;
|
|
1677
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
1678
|
+
const child = children[i];
|
|
1679
|
+
if (child.type === 'tag')
|
|
1680
|
+
stack.push(child);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
if (asks)
|
|
1684
|
+
note(el);
|
|
1685
|
+
const tag = tagOf(el);
|
|
1686
|
+
const asked = found.size
|
|
1687
|
+
? index.universal.length > 0 || index.byTag.has(tag)
|
|
1688
|
+
: needs.universal || needs.tags.has(tag);
|
|
1689
|
+
if (!asked && !index.names(el))
|
|
1690
|
+
continue;
|
|
1691
|
+
const candidates = [];
|
|
1692
|
+
this._matchInto(index, el, candidates, undefined, el === root ? liveForRoot : live);
|
|
1693
|
+
if (!candidates.length)
|
|
1694
|
+
continue;
|
|
1695
|
+
const inline = attr(el, 'style');
|
|
1696
|
+
if (inline)
|
|
1697
|
+
pushInlineShapes(candidates, inline);
|
|
1698
|
+
candidates.sort(byCascade);
|
|
1699
|
+
ctx ??= {
|
|
1700
|
+
color: style.color,
|
|
1701
|
+
scheme: style.colorScheme,
|
|
1702
|
+
units: {
|
|
1703
|
+
em: style.fontSize,
|
|
1704
|
+
rem: (this._root ?? this.initial).fontSize,
|
|
1705
|
+
vw: this.viewportWidth,
|
|
1706
|
+
vh: this.viewportHeight,
|
|
1707
|
+
scale: this.scale,
|
|
1708
|
+
initial: this.initial,
|
|
1709
|
+
},
|
|
1710
|
+
};
|
|
1711
|
+
let own = null;
|
|
1712
|
+
for (const c of candidates) {
|
|
1713
|
+
for (const d of pick(c)) {
|
|
1714
|
+
if (!isShapeProp(d.prop))
|
|
1715
|
+
continue;
|
|
1716
|
+
if (el === root && ROOT_BOX_PROPS.has(d.prop))
|
|
1717
|
+
continue;
|
|
1718
|
+
// a `var()` with nothing to stand for it is invalid at
|
|
1719
|
+
// computed-value time, and the property as though `unset`
|
|
1720
|
+
const value = shapeValue(d.prop, d.vars ? (substituteIn(d.value, style.custom) ?? 'unset') : d.value, ctx);
|
|
1721
|
+
if (value !== null)
|
|
1722
|
+
(own ??= {})[d.prop] = value;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
if (!own)
|
|
1726
|
+
continue;
|
|
1727
|
+
(of ??= new Map()).set(el, own);
|
|
1728
|
+
key += `${place}{`;
|
|
1729
|
+
for (const prop in own)
|
|
1730
|
+
key += `${prop}:${own[prop]};`;
|
|
1731
|
+
key += '}';
|
|
1732
|
+
}
|
|
1733
|
+
return of ? { of, key } : null;
|
|
1734
|
+
}
|
|
1735
|
+
/** `ShapeNeeds`, and each such rule's own (`IndexedRule.needs`). */
|
|
1736
|
+
_needsOfShapes() {
|
|
1737
|
+
const index = this._shapes;
|
|
1738
|
+
const needs = {
|
|
1739
|
+
classes: new Set(),
|
|
1740
|
+
ids: new Set(),
|
|
1741
|
+
universal: false,
|
|
1742
|
+
tags: new Set(),
|
|
1743
|
+
};
|
|
1744
|
+
const read = (bucket) => {
|
|
1745
|
+
let free = false;
|
|
1746
|
+
for (const indexed of bucket) {
|
|
1747
|
+
const keys = ancestorKeys(indexed.rule.selector);
|
|
1748
|
+
indexed.needs = keys;
|
|
1749
|
+
if (!keys.length)
|
|
1750
|
+
free = true;
|
|
1751
|
+
for (const key of keys) {
|
|
1752
|
+
(key[0] === '#' ? needs.ids : needs.classes).add(key.slice(1));
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
return free;
|
|
1756
|
+
};
|
|
1757
|
+
needs.universal = read(index.universal);
|
|
1758
|
+
for (const [tag, bucket] of index.byTag) {
|
|
1759
|
+
if (read(bucket))
|
|
1760
|
+
needs.tags.add(tag);
|
|
1761
|
+
}
|
|
1762
|
+
return needs;
|
|
1763
|
+
}
|
|
1530
1764
|
/**
|
|
1531
1765
|
* Whether the pointer's move from `was` to where it is changed which
|
|
1532
1766
|
* rules match `el`, or its `::before`, `::after` or another of its
|
|
@@ -1564,7 +1798,9 @@ export class Cascade {
|
|
|
1564
1798
|
}
|
|
1565
1799
|
/** The rules of `index` that match `el`, pushed onto `out` as candidates,
|
|
1566
1800
|
* and their ids onto `matched` in the order they were tried. */
|
|
1567
|
-
_matchInto(index, el, out, matched
|
|
1801
|
+
_matchInto(index, el, out, matched,
|
|
1802
|
+
/** The rules to try, where some are known not to match without it. */
|
|
1803
|
+
live) {
|
|
1568
1804
|
// A media query's width is CSS pixels; the viewport is kept in device.
|
|
1569
1805
|
const width = this.viewportWidth / this.scale;
|
|
1570
1806
|
const height = this.viewportHeight / this.scale;
|
|
@@ -1572,6 +1808,8 @@ export class Cascade {
|
|
|
1572
1808
|
if (!bucket)
|
|
1573
1809
|
return;
|
|
1574
1810
|
for (const indexed of bucket) {
|
|
1811
|
+
if (live !== undefined && !live(indexed))
|
|
1812
|
+
continue;
|
|
1575
1813
|
const rule = indexed.rule;
|
|
1576
1814
|
if (!mediaMatches(rule.media, width, this.look.colorScheme, height, this.scale)) {
|
|
1577
1815
|
continue;
|
|
@@ -1579,7 +1817,7 @@ export class Cascade {
|
|
|
1579
1817
|
if (!indexed.compiled) {
|
|
1580
1818
|
indexed.compiled = true;
|
|
1581
1819
|
try {
|
|
1582
|
-
indexed.match = compileSelector(rule.selector, this._adapter);
|
|
1820
|
+
indexed.match = compileSelector(rule.selector, this._adapter, this._pseudos);
|
|
1583
1821
|
}
|
|
1584
1822
|
catch {
|
|
1585
1823
|
// A selector this matcher does not know (`::-moz-…`, a CSS4 form
|
|
@@ -1858,6 +2096,49 @@ function setsContent(c) {
|
|
|
1858
2096
|
}
|
|
1859
2097
|
/** Whether a rule's declarations set a custom property, by the array. */
|
|
1860
2098
|
const CUSTOM_IN = new WeakMap();
|
|
2099
|
+
/** Whether declarations set a property a shape in a drawing has. */
|
|
2100
|
+
function declaresShape(declarations) {
|
|
2101
|
+
for (const d of declarations)
|
|
2102
|
+
if (isShapeProp(d.prop))
|
|
2103
|
+
return true;
|
|
2104
|
+
return false;
|
|
2105
|
+
}
|
|
2106
|
+
/** Whether declarations set one a drawing's root does not have from its
|
|
2107
|
+
* box's style (`ROOT_BOX_PROPS`). */
|
|
2108
|
+
function declaresRootShape(declarations) {
|
|
2109
|
+
for (const d of declarations) {
|
|
2110
|
+
if (isShapeProp(d.prop) && !ROOT_BOX_PROPS.has(d.prop))
|
|
2111
|
+
return true;
|
|
2112
|
+
}
|
|
2113
|
+
return false;
|
|
2114
|
+
}
|
|
2115
|
+
/** A `style` attribute's declarations of a shape's properties, as
|
|
2116
|
+
* candidates: over every rule, and its `!important` ones over theirs. */
|
|
2117
|
+
function pushInlineShapes(out, inline) {
|
|
2118
|
+
const declarations = parseDeclarations(inline).filter((d) => isShapeProp(d.prop));
|
|
2119
|
+
const normal = declarations.filter((d) => !d.important);
|
|
2120
|
+
const important = declarations.filter((d) => d.important);
|
|
2121
|
+
if (normal.length) {
|
|
2122
|
+
out.push({
|
|
2123
|
+
origin: Origin.Inline,
|
|
2124
|
+
layer: null,
|
|
2125
|
+
specificity: 0,
|
|
2126
|
+
order: 0,
|
|
2127
|
+
declarations: normal,
|
|
2128
|
+
only: -1,
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
if (important.length) {
|
|
2132
|
+
out.push({
|
|
2133
|
+
origin: Origin.InlineImportant,
|
|
2134
|
+
layer: null,
|
|
2135
|
+
specificity: 0,
|
|
2136
|
+
order: 0,
|
|
2137
|
+
declarations: important,
|
|
2138
|
+
only: -1,
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
1861
2142
|
function pick(c) {
|
|
1862
2143
|
return c.only < 0 ? c.declarations : [c.declarations[c.only]];
|
|
1863
2144
|
}
|
|
@@ -2252,6 +2533,23 @@ function lengthAttr(value) {
|
|
|
2252
2533
|
const n = parseFloat(v);
|
|
2253
2534
|
return Number.isFinite(n) ? `${n}px` : v;
|
|
2254
2535
|
}
|
|
2536
|
+
/** A number and a unit, as an SVG's `width` and `height` are written. */
|
|
2537
|
+
const SVG_LENGTH = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*([a-z]*)\s*$/i;
|
|
2538
|
+
/**
|
|
2539
|
+
* The `width`/`height` of an inline `<svg>` as CSS: they are presentation
|
|
2540
|
+
* attributes for the properties of the same names (SVG 2, 5.1.1), so
|
|
2541
|
+
* `height="50%"` is a percentage of the containing block like a style's.
|
|
2542
|
+
* A bare number is pixels; null for what CSS would not parse.
|
|
2543
|
+
*/
|
|
2544
|
+
function svgSizeHint(value) {
|
|
2545
|
+
const v = value.trim();
|
|
2546
|
+
if (/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?%$/i.test(v))
|
|
2547
|
+
return v;
|
|
2548
|
+
const m = SVG_LENGTH.exec(v);
|
|
2549
|
+
if (!m)
|
|
2550
|
+
return null;
|
|
2551
|
+
return m[2] ? v : `${parseFloat(m[1])}px`;
|
|
2552
|
+
}
|
|
2255
2553
|
function closestTable(el) {
|
|
2256
2554
|
let node = el.parent;
|
|
2257
2555
|
while (node) {
|