@uiw/react-md-editor 3.20.1 → 3.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mdeditor.js CHANGED
@@ -9661,9 +9661,7 @@ function _iterableToArrayLimit(arr, i) {
9661
9661
  if (_x = (_i = _i.call(arr)).next, 0 === i) {
9662
9662
  if (Object(_i) !== _i) return;
9663
9663
  _n = !1;
9664
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
9665
- ;
9666
- }
9664
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
9667
9665
  } catch (err) {
9668
9666
  _d = !0, _e = err;
9669
9667
  } finally {
@@ -9679,9 +9677,7 @@ function _iterableToArrayLimit(arr, i) {
9679
9677
  ;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
9680
9678
  function _arrayLikeToArray(arr, len) {
9681
9679
  if (len == null || len > arr.length) len = arr.length;
9682
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
9683
- arr2[i] = arr[i];
9684
- }
9680
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
9685
9681
  return arr2;
9686
9682
  }
9687
9683
  ;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
@@ -31389,7 +31385,7 @@ function rehypeAutolinkHeadings(options = {}) {
31389
31385
  }
31390
31386
 
31391
31387
  ;// CONCATENATED MODULE: ../node_modules/rehype-attr/lib/utils.js
31392
- const getURLParameters = (url) => (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
31388
+ const getURLParameters = (url = '') => (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
31393
31389
  const prevChild = (data = [], index) => {
31394
31390
  let i = index;
31395
31391
  while (i > -1) {
@@ -31420,8 +31416,8 @@ const nextChild = (data = [], index, tagName, codeBlockParames) => {
31420
31416
  return;
31421
31417
  if (element.type === 'text' && element.value.replace(/(\n|\s)/g, '') !== '')
31422
31418
  return;
31423
- if (/^(comment|raw)$/ig.test(element?.type)) {
31424
- if (!/^rehype:/.test(element.value?.replace(/^(\s+)?<!--(.*?)-->/, '$2') || '')) {
31419
+ if (element.type && /^(comment|raw)$/ig.test(element.type)) {
31420
+ if (element.value && !/^rehype:/.test(element.value.replace(/^(\s+)?<!--(.*?)-->/, '$2') || '')) {
31425
31421
  return;
31426
31422
  }
31427
31423
  ;
@@ -31429,11 +31425,11 @@ const nextChild = (data = [], index, tagName, codeBlockParames) => {
31429
31425
  const nextNode = nextChild(data, i, 'pre', codeBlockParames);
31430
31426
  if (nextNode)
31431
31427
  return;
31432
- element.value = element.value?.replace(/^(\n|\s)+/, '');
31428
+ element.value = (element.value || '').replace(/^(\n|\s)+/, '');
31433
31429
  return element;
31434
31430
  }
31435
31431
  else {
31436
- element.value = element.value?.replace(/^(\n|\s)+/, '');
31432
+ element.value = (element.value || '').replace(/^(\n|\s)+/, '');
31437
31433
  return element;
31438
31434
  }
31439
31435
  }
@@ -58435,36 +58431,13 @@ function direction(value) {
58435
58431
  return rtl.test(source) ? 'rtl' : ltr.test(source) ? 'ltr' : 'neutral'
58436
58432
  }
58437
58433
 
58438
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/util.js
58439
- /**
58440
- * @typedef {import('./types.js').Node} Node
58441
- * @typedef {import('./types.js').Element} Element
58442
- * @typedef {import('./types.js').Parent} Parent
58443
- * @typedef {import('hast-util-is-element').AssertPredicate<Element>} IsElement
58444
- */
58445
-
58446
-
58447
-
58448
- /**
58449
- * @param {Node} node
58450
- * @returns {node is Parent}
58451
- */
58452
- function util_parent(node) {
58453
- // @ts-expect-error: hush.
58454
- return Array.isArray(node.children)
58455
- }
58456
-
58457
- /** @type {IsElement} */
58458
- // @ts-expect-error it works.
58459
- const util_element = convertElement()
58460
-
58461
58434
  ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/enter-state.js
58462
58435
  /**
58463
58436
  * @typedef {import('./types.js').SelectState} SelectState
58464
- * @typedef {import('./types.js').HastNode} HastNode
58437
+ * @typedef {import('./types.js').Node} Node
58465
58438
  * @typedef {import('./types.js').ElementChild} ElementChild
58466
58439
  * @typedef {import('./types.js').Direction} Direction
58467
- * @typedef {import('unist-util-visit/complex-types').Visitor<ElementChild>} Visitor
58440
+ * @typedef {import('unist-util-visit/complex-types.js').Visitor<ElementChild>} Visitor
58468
58441
  */
58469
58442
 
58470
58443
 
@@ -58472,12 +58445,19 @@ const util_element = convertElement()
58472
58445
 
58473
58446
 
58474
58447
 
58475
-
58476
-
58477
58448
  /**
58449
+ * Enter a node.
58450
+ *
58451
+ * The caller is responsible for calling the return value `exit`.
58452
+ *
58478
58453
  * @param {SelectState} state
58479
- * @param {HastNode} node
58454
+ * Current state.
58455
+ *
58456
+ * Will be mutated: `exit` undos the changes.
58457
+ * @param {Node} node
58458
+ * Node to enter.
58480
58459
  * @returns {() => void}
58460
+ * Call to exit.
58481
58461
  */
58482
58462
  // eslint-disable-next-line complexity
58483
58463
  function enterState(state, node) {
@@ -58485,30 +58465,25 @@ function enterState(state, node) {
58485
58465
  const language = state.language
58486
58466
  const currentDirection = state.direction
58487
58467
  const editableOrEditingHost = state.editableOrEditingHost
58488
- /** @type {Direction|undefined} */
58468
+ /** @type {Direction | undefined} */
58489
58469
  let dirInferred
58490
- /** @type {boolean|undefined} */
58491
- let found
58492
58470
 
58493
- if (util_element(node) && node.properties) {
58471
+ if (node.type === 'element' && node.properties) {
58494
58472
  const lang = node.properties.xmlLang || node.properties.lang
58495
58473
  const type = node.properties.type || 'text'
58496
58474
  const dir = dirProperty(node)
58497
58475
 
58498
58476
  if (lang !== undefined && lang !== null) {
58499
58477
  state.language = String(lang)
58500
- found = true
58501
58478
  }
58502
58479
 
58503
58480
  if (schema && schema.space === 'html') {
58504
58481
  if (node.properties.contentEditable === 'true') {
58505
58482
  state.editableOrEditingHost = true
58506
- found = true
58507
58483
  }
58508
58484
 
58509
- if (isElement(node, 'svg')) {
58485
+ if (node.tagName === 'svg') {
58510
58486
  state.schema = property_information_svg
58511
- found = true
58512
58487
  }
58513
58488
 
58514
58489
  // See: <https://html.spec.whatwg.org/#the-directionality>.
@@ -58519,25 +58494,24 @@ function enterState(state, node) {
58519
58494
  // Explicit `[dir=ltr]`.
58520
58495
  dir === 'ltr' ||
58521
58496
  // HTML with an invalid or no `[dir]`.
58522
- (dir !== 'auto' && isElement(node, 'html')) ||
58497
+ (dir !== 'auto' && node.tagName === 'html') ||
58523
58498
  // `input[type=tel]` with an invalid or no `[dir]`.
58524
- (dir !== 'auto' && isElement(node, 'input') && type === 'tel')
58499
+ (dir !== 'auto' && node.tagName === 'input' && type === 'tel')
58525
58500
  ) {
58526
58501
  dirInferred = 'ltr'
58527
58502
  // `[dir=auto]` or `bdi` with an invalid or no `[dir]`.
58528
- } else if (dir === 'auto' || isElement(node, 'bdi')) {
58529
- if (isElement(node, 'textarea')) {
58503
+ } else if (dir === 'auto' || node.tagName === 'bdi') {
58504
+ if (node.tagName === 'textarea') {
58530
58505
  // Check contents of `<textarea>`.
58531
58506
  dirInferred = dirBidi(hast_util_to_string_toString(node))
58532
58507
  } else if (
58533
- isElement(node, 'input') &&
58508
+ node.tagName === 'input' &&
58534
58509
  (type === 'email' ||
58535
58510
  type === 'search' ||
58536
58511
  type === 'tel' ||
58537
58512
  type === 'text')
58538
58513
  ) {
58539
58514
  // Check value of `<input>`.
58540
- // @ts-expect-error something is `never` in types but this is needed.
58541
58515
  dirInferred = node.properties.value
58542
58516
  ? // @ts-expect-error Assume string
58543
58517
  dirBidi(node.properties.value)
@@ -58550,17 +58524,15 @@ function enterState(state, node) {
58550
58524
 
58551
58525
  if (dirInferred) {
58552
58526
  state.direction = dirInferred
58553
- found = true
58554
58527
  }
58555
58528
  }
58556
58529
  // Turn off editing mode in non-HTML spaces.
58557
58530
  else if (state.editableOrEditingHost) {
58558
58531
  state.editableOrEditingHost = false
58559
- found = true
58560
58532
  }
58561
58533
  }
58562
58534
 
58563
- return found ? reset : noop
58535
+ return reset
58564
58536
 
58565
58537
  function reset() {
58566
58538
  state.schema = schema
@@ -58573,12 +58545,16 @@ function enterState(state, node) {
58573
58545
  function inferDirectionality(child) {
58574
58546
  if (child.type === 'text') {
58575
58547
  dirInferred = dirBidi(child.value)
58576
- return dirInferred ? EXIT : null
58548
+ return dirInferred ? EXIT : undefined
58577
58549
  }
58578
58550
 
58579
58551
  if (
58580
58552
  child !== node &&
58581
- (isElement(child, ['bdi', 'script', 'style', 'textare']) ||
58553
+ child.type === 'element' &&
58554
+ (child.tagName === 'bdi' ||
58555
+ child.tagName === 'script' ||
58556
+ child.tagName === 'style' ||
58557
+ child.tagName === 'textare' ||
58582
58558
  dirProperty(child))
58583
58559
  ) {
58584
58560
  return SKIP
@@ -58588,7 +58564,7 @@ function enterState(state, node) {
58588
58564
 
58589
58565
  /**
58590
58566
  * @param {string} value
58591
- * @returns {Direction|undefined}
58567
+ * @returns {Direction | undefined}
58592
58568
  */
58593
58569
  function dirBidi(value) {
58594
58570
  const result = direction(value)
@@ -58597,11 +58573,13 @@ function dirBidi(value) {
58597
58573
 
58598
58574
  /**
58599
58575
  * @param {ElementChild} node
58600
- * @returns {Direction|undefined}
58576
+ * @returns {Direction | undefined}
58601
58577
  */
58602
58578
  function dirProperty(node) {
58603
58579
  const value =
58604
- util_element(node) && node.properties && typeof node.properties.dir === 'string'
58580
+ node.type === 'element' &&
58581
+ node.properties &&
58582
+ typeof node.properties.dir === 'string'
58605
58583
  ? node.properties.dir.toLowerCase()
58606
58584
  : undefined
58607
58585
 
@@ -58610,231 +58588,297 @@ function dirProperty(node) {
58610
58588
  : undefined
58611
58589
  }
58612
58590
 
58613
- function noop() {}
58614
-
58615
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/nest.js
58591
+ ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/attribute.js
58616
58592
  /**
58617
58593
  * @typedef {import('./types.js').Rule} Rule
58618
- * @typedef {import('./types.js').Node} Node
58594
+ * @typedef {import('./types.js').RuleAttr} RuleAttr
58619
58595
  * @typedef {import('./types.js').Element} Element
58620
- * @typedef {import('./types.js').Parent} Parent
58621
- * @typedef {import('./types.js').SelectState} SelectState
58622
- * @typedef {import('./types.js').SelectIterator} SelectIterator
58623
- * @typedef {import('./types.js').Handler} Handler
58596
+ * @typedef {import('./types.js').Schema} Schema
58597
+ * @typedef {import('./types.js').Info} Info
58598
+ * @typedef {import('./types.js').PropertyValue} PropertyValue
58624
58599
  */
58625
58600
 
58626
58601
 
58627
58602
 
58628
58603
 
58629
58604
 
58630
- const nest_own = {}.hasOwnProperty
58631
58605
 
58632
- const handle = zwitch('nestingOperator', {
58633
- // @ts-expect-error: hush.
58634
- unknown: unknownNesting,
58606
+
58607
+ /** @type {(query: RuleAttr, element: Element, info: Info) => boolean} */
58608
+ const handle = zwitch('operator', {
58609
+ unknown: unknownOperator,
58635
58610
  // @ts-expect-error: hush.
58636
- invalid: topScan, // `undefined` is the top query selector.
58611
+ invalid: exists,
58637
58612
  handlers: {
58638
- // @ts-expect-error: hush.
58639
- null: descendant, // `null` is the descendant combinator.
58640
- // @ts-expect-error: hush.
58641
- '>': child,
58642
- // @ts-expect-error: hush.
58643
- '+': adjacentSibling,
58644
- // @ts-expect-error: hush.
58645
- '~': generalSibling
58613
+ '=': exact,
58614
+ '~=': spaceSeparatedList,
58615
+ '|=': exactOrPrefix,
58616
+ '^=': begins,
58617
+ '$=': ends,
58618
+ '*=': contains
58646
58619
  }
58647
58620
  })
58648
58621
 
58649
- /** @type {Handler} */
58650
- function nest(query, node, index, parent, state) {
58651
- handle(query, node, index, parent, state)
58652
- }
58653
-
58654
- // Shouldn’t be called, parser gives correct data.
58655
- /* c8 ignore next 6 */
58656
58622
  /**
58657
- * @param {{[x: string]: unknown, type: string}} query
58623
+ * @param {Rule} query
58624
+ * @param {Element} element
58625
+ * @param {Schema} schema
58626
+ * @returns {boolean}
58658
58627
  */
58659
- function unknownNesting(query) {
58660
- throw new Error('Unexpected nesting `' + query.nestingOperator + '`')
58661
- }
58628
+ function attribute(query, element, schema) {
58629
+ const attrs = query.attrs
58630
+ let index = -1
58662
58631
 
58663
- /** @type {Handler} */
58664
- function topScan(query, node, index, parent, state) {
58665
- // Shouldn’t happen.
58666
- /* c8 ignore next 3 */
58667
- if (parent || index === null) {
58668
- throw new Error('topScan is supposed to be called from the root node')
58632
+ while (++index < attrs.length) {
58633
+ if (!handle(attrs[index], element, find(schema, attrs[index].name))) {
58634
+ return false
58635
+ }
58669
58636
  }
58670
58637
 
58671
- // Shouldn’t happen.
58672
- /* c8 ignore next 3 */
58673
- if (!state.iterator) {
58674
- throw new Error('Expected `iterator`')
58675
- }
58638
+ return true
58639
+ }
58676
58640
 
58677
- state.iterator(query, node, index, parent, state)
58678
- if (!state.shallow) descendant(query, node, index, parent, state)
58641
+ /**
58642
+ * Check whether an attribute exists.
58643
+ *
58644
+ * `[attr]`
58645
+ *
58646
+ * @param {RuleAttr} _
58647
+ * @param {Element} element
58648
+ * @param {Info} info
58649
+ * @returns {boolean}
58650
+ */
58651
+ function exists(_, element, info) {
58652
+ return hasProperty(element, info.property)
58679
58653
  }
58680
58654
 
58681
- /** @type {Handler} */
58682
- function descendant(query, node, index, parent, state) {
58683
- const previous = state.iterator
58655
+ /**
58656
+ * Check whether an attribute has an exact value.
58657
+ *
58658
+ * `[attr=value]`
58659
+ *
58660
+ * @param {RuleAttr} query
58661
+ * @param {Element} element
58662
+ * @param {Info} info
58663
+ * @returns {boolean}
58664
+ */
58665
+ function exact(query, element, info) {
58666
+ return Boolean(
58667
+ hasProperty(element, info.property) &&
58668
+ element.properties &&
58669
+ normalizeValue(element.properties[info.property], info) === query.value
58670
+ )
58671
+ }
58684
58672
 
58685
- state.iterator = iterator
58686
- child(query, node, index, parent, state)
58673
+ /**
58674
+ * Check whether an attribute, interpreted as a space-separated list, contains
58675
+ * a value.
58676
+ *
58677
+ * `[attr~=value]`
58678
+ *
58679
+ * @param {RuleAttr} query
58680
+ * @param {Element} element
58681
+ * @param {Info} info
58682
+ * @returns {boolean}
58683
+ */
58684
+ function spaceSeparatedList(query, element, info) {
58685
+ const value = element.properties && element.properties[info.property]
58687
58686
 
58688
- /** @type {SelectIterator} */
58689
- function iterator(query, node, index, parent, state) {
58690
- // Shouldn’t happen.
58691
- /* c8 ignore next 3 */
58692
- if (!previous) {
58693
- throw new Error('Expected `iterator`')
58694
- }
58687
+ return (
58688
+ // If this is a space-separated list, and the query is contained in it, return
58689
+ // true.
58690
+ (!info.commaSeparated &&
58691
+ value &&
58692
+ typeof value === 'object' &&
58693
+ query.value &&
58694
+ value.includes(query.value)) ||
58695
+ // For all other values (including comma-separated lists), return whether this
58696
+ // is an exact match.
58697
+ (hasProperty(element, info.property) &&
58698
+ normalizeValue(value, info) === query.value)
58699
+ )
58700
+ }
58695
58701
 
58696
- state.iterator = previous
58697
- previous(query, node, index, parent, state)
58698
- state.iterator = iterator
58702
+ /**
58703
+ * Check whether an attribute has a substring as either the exact value or a
58704
+ * prefix.
58705
+ *
58706
+ * `[attr|=value]`
58707
+ *
58708
+ * @param {RuleAttr} query
58709
+ * @param {Element} element
58710
+ * @param {Info} info
58711
+ * @returns {boolean}
58712
+ */
58713
+ function exactOrPrefix(query, element, info) {
58714
+ const value = normalizeValue(
58715
+ element.properties && element.properties[info.property],
58716
+ info
58717
+ )
58699
58718
 
58700
- if (state.one && state.found) return
58719
+ return Boolean(
58720
+ hasProperty(element, info.property) &&
58721
+ query.value &&
58722
+ (value === query.value ||
58723
+ (value.slice(0, query.value.length) === query.value &&
58724
+ value.charAt(query.value.length) === '-'))
58725
+ )
58726
+ }
58701
58727
 
58702
- child(query, node, index, parent, state)
58703
- }
58728
+ /**
58729
+ * Check whether an attribute has a substring as its start.
58730
+ *
58731
+ * `[attr^=value]`
58732
+ *
58733
+ * @param {RuleAttr} query
58734
+ * @param {Element} element
58735
+ * @param {Info} info
58736
+ * @returns {boolean}
58737
+ */
58738
+ function begins(query, element, info) {
58739
+ return Boolean(
58740
+ hasProperty(element, info.property) &&
58741
+ element.properties &&
58742
+ query.value &&
58743
+ normalizeValue(element.properties[info.property], info).slice(
58744
+ 0,
58745
+ query.value.length
58746
+ ) === query.value
58747
+ )
58704
58748
  }
58705
58749
 
58706
- /** @type {Handler} */
58707
- function child(query, node, _1, _2, state) {
58708
- if (!util_parent(node)) return
58709
- if (node.children.length === 0) return
58710
- indexedSearch(query, node, state)
58750
+ /**
58751
+ * Check whether an attribute has a substring as its end.
58752
+ *
58753
+ * `[attr$=value]`
58754
+ *
58755
+ * @param {RuleAttr} query
58756
+ * @param {Element} element
58757
+ * @param {Info} info
58758
+ * @returns {boolean}
58759
+ */
58760
+ function ends(query, element, info) {
58761
+ return Boolean(
58762
+ hasProperty(element, info.property) &&
58763
+ element.properties &&
58764
+ query.value &&
58765
+ normalizeValue(element.properties[info.property], info).slice(
58766
+ -query.value.length
58767
+ ) === query.value
58768
+ )
58711
58769
  }
58712
58770
 
58713
- /** @type {Handler} */
58714
- function adjacentSibling(query, _, index, parent, state) {
58715
- // Shouldn’t happen.
58716
- /* c8 ignore next */
58717
- if (!parent || index === null) return
58718
- indexedSearch(query, parent, state, index + 1, true)
58771
+ /**
58772
+ * Check whether an attribute contains a substring.
58773
+ *
58774
+ * `[attr*=value]`
58775
+ *
58776
+ * @param {RuleAttr} query
58777
+ * @param {Element} element
58778
+ * @param {Info} info
58779
+ * @returns {boolean}
58780
+ */
58781
+ function contains(query, element, info) {
58782
+ return Boolean(
58783
+ hasProperty(element, info.property) &&
58784
+ element.properties &&
58785
+ query.value &&
58786
+ normalizeValue(element.properties[info.property], info).includes(
58787
+ query.value
58788
+ )
58789
+ )
58719
58790
  }
58720
58791
 
58721
- /** @type {Handler} */
58722
- function generalSibling(query, _, index, parent, state) {
58723
- // Shouldn’t happen.
58724
- /* c8 ignore next */
58725
- if (!parent || index === null) return
58726
- indexedSearch(query, parent, state, index + 1)
58792
+ // Shouldn’t be called, Parser throws an error instead.
58793
+ /**
58794
+ * @param {unknown} query
58795
+ * @returns {never}
58796
+ */
58797
+ /* c8 ignore next 4 */
58798
+ function unknownOperator(query) {
58799
+ // @ts-expect-error: `operator` guaranteed.
58800
+ throw new Error('Unknown operator `' + query.operator + '`')
58727
58801
  }
58728
58802
 
58729
58803
  /**
58730
- * Handles `typeIndex` and `typeCount` properties for every walker.
58804
+ * Stringify a hast value back to its HTML form.
58731
58805
  *
58732
- * @param {Rule} query
58733
- * @param {Parent} parent
58734
- * @param {SelectState} state
58735
- * @param {number} [from=0]
58736
- * @param {boolean} [firstElementOnly=false]
58806
+ * @param {PropertyValue} value
58807
+ * @param {Info} info
58808
+ * @returns {string}
58737
58809
  */
58738
- function indexedSearch(query, parent, state, from, firstElementOnly) {
58739
- const handle = state.index ? delay : add
58740
- const children = parent.children
58741
- let elements = 0
58742
- let index = -1
58743
- /** @type {Record<string, number>} */
58744
- const types = {}
58745
- /** @type {Array<Function>} */
58746
- const delayed = []
58747
-
58748
- // Start looking at `from`
58749
- if (from === undefined || from === null) from = 0
58750
-
58751
- // Exit if there are no further nodes.
58752
- if (from >= children.length) return
58753
-
58754
- // If we need to index for types, do so for all elements before `from`.
58755
- if (state.index) {
58756
- while (++index < from) {
58757
- const child = children[index]
58758
- if (util_element(child)) count(child.tagName)
58759
- }
58760
- }
58761
-
58762
- index = from - 1
58763
-
58764
- while (++index < children.length) {
58765
- const child = children[index]
58766
- // Only check elements.
58767
- // Check either all elements, or only check the first sibling
58768
- if (util_element(child)) {
58769
- handle(child, index)
58770
-
58771
- // Stop if we’re looking for one node and it’s already found.
58772
- if (state.one && state.found) return
58773
- if (firstElementOnly) break
58774
- }
58810
+ function normalizeValue(value, info) {
58811
+ if (typeof value === 'boolean') {
58812
+ return info.attribute
58775
58813
  }
58776
58814
 
58777
- if (state.index) {
58778
- index = -1
58779
-
58780
- while (++index < delayed.length) {
58781
- delayed[index]()
58782
- if (state.one && state.found) return
58783
- }
58815
+ if (Array.isArray(value)) {
58816
+ return (info.commaSeparated ? comma_separated_tokens_stringify : stringify)(value)
58784
58817
  }
58785
58818
 
58786
- /**
58787
- * @param {Element} node
58788
- * @param {number} childIndex
58789
- */
58790
- function delay(node, childIndex) {
58791
- const elementsBefore = elements
58792
- const elementsByTypeBefore = nest_own.call(types, node.tagName)
58793
- ? types[node.tagName]
58794
- : 0
58795
-
58796
- count(node.tagName)
58797
-
58798
- delayed.push(fn)
58819
+ return String(value)
58820
+ }
58799
58821
 
58800
- function fn() {
58801
- // Before counting further elements:
58802
- state.elementIndex = elementsBefore
58803
- state.typeIndex = elementsByTypeBefore
58822
+ ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/class-name.js
58823
+ /**
58824
+ * @typedef {import('./types.js').Rule} Rule
58825
+ * @typedef {import('./types.js').Element} Element
58826
+ */
58804
58827
 
58805
- // After counting all elements.
58806
- state.elementCount = elements
58807
- state.typeCount = types[node.tagName]
58828
+ /**
58829
+ * Check whether an element has all class names.
58830
+ *
58831
+ * @param {Rule} query
58832
+ * @param {Element} element
58833
+ * @returns {boolean}
58834
+ */
58835
+ function className(query, element) {
58836
+ /** @type {readonly string[]} */
58837
+ // @ts-expect-error Assume array.
58838
+ const value = element.properties.className || []
58839
+ let index = -1
58808
58840
 
58809
- add(node, childIndex)
58841
+ if (query.classNames) {
58842
+ while (++index < query.classNames.length) {
58843
+ if (!value.includes(query.classNames[index])) return false
58810
58844
  }
58811
58845
  }
58812
58846
 
58813
- /**
58814
- * @param {Element} node
58815
- * @param {number} childIndex
58816
- */
58817
- function add(node, childIndex) {
58818
- const exit = enterState(state, node)
58847
+ return true
58848
+ }
58819
58849
 
58820
- // Shouldn’t happen.
58821
- /* c8 ignore next 3 */
58822
- if (!state.iterator) {
58823
- throw new Error('Expected `iterator`')
58824
- }
58850
+ ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/id.js
58851
+ /**
58852
+ * @typedef {import('./types.js').Rule} Rule
58853
+ * @typedef {import('./types.js').Element} Element
58854
+ */
58825
58855
 
58826
- state.iterator(query, node, childIndex, parent, state)
58827
- exit()
58828
- }
58856
+ /**
58857
+ * Check whether an element has an ID.
58858
+ *
58859
+ * @param {Rule} query
58860
+ * @param {Element} element
58861
+ * @returns {boolean}
58862
+ */
58863
+ function id(query, element) {
58864
+ return Boolean(element.properties && element.properties.id === query.id)
58865
+ }
58829
58866
 
58830
- /**
58831
- * @param {string} name
58832
- */
58833
- function count(name) {
58834
- if (!nest_own.call(types, name)) types[name] = 0
58835
- elements++
58836
- types[name]++
58837
- }
58867
+ ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/name.js
58868
+ /**
58869
+ * @typedef {import('./types.js').Rule} Rule
58870
+ * @typedef {import('./types.js').Element} Element
58871
+ */
58872
+
58873
+ /**
58874
+ * Check whether an element has a tag name.
58875
+ *
58876
+ * @param {Rule} query
58877
+ * @param {Element} element
58878
+ * @returns {boolean}
58879
+ */
58880
+ function name_name(query, element) {
58881
+ return query.tagName === '*' || query.tagName === element.tagName
58838
58882
  }
58839
58883
 
58840
58884
  ;// CONCATENATED MODULE: ../node_modules/bcp-47-match/index.js
@@ -59073,15 +59117,266 @@ function cast(values, name) {
59073
59117
  return value
59074
59118
  }
59075
59119
 
59120
+ ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/parse.js
59121
+ // Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
59122
+ // Whitespace as per https://www.w3.org/TR/selectors-3/#lex is " \t\r\n\f"
59123
+ const parse_whitespace = new Set([9, 10, 12, 13, 32]);
59124
+ const ZERO = "0".charCodeAt(0);
59125
+ const NINE = "9".charCodeAt(0);
59126
+ /**
59127
+ * Parses an expression.
59128
+ *
59129
+ * @throws An `Error` if parsing fails.
59130
+ * @returns An array containing the integer step size and the integer offset of the nth rule.
59131
+ * @example nthCheck.parse("2n+3"); // returns [2, 3]
59132
+ */
59133
+ function esm_parse_parse(formula) {
59134
+ formula = formula.trim().toLowerCase();
59135
+ if (formula === "even") {
59136
+ return [2, 0];
59137
+ }
59138
+ else if (formula === "odd") {
59139
+ return [2, 1];
59140
+ }
59141
+ // Parse [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
59142
+ let idx = 0;
59143
+ let a = 0;
59144
+ let sign = readSign();
59145
+ let number = readNumber();
59146
+ if (idx < formula.length && formula.charAt(idx) === "n") {
59147
+ idx++;
59148
+ a = sign * (number !== null && number !== void 0 ? number : 1);
59149
+ skipWhitespace();
59150
+ if (idx < formula.length) {
59151
+ sign = readSign();
59152
+ skipWhitespace();
59153
+ number = readNumber();
59154
+ }
59155
+ else {
59156
+ sign = number = 0;
59157
+ }
59158
+ }
59159
+ // Throw if there is anything else
59160
+ if (number === null || idx < formula.length) {
59161
+ throw new Error(`n-th rule couldn't be parsed ('${formula}')`);
59162
+ }
59163
+ return [a, sign * number];
59164
+ function readSign() {
59165
+ if (formula.charAt(idx) === "-") {
59166
+ idx++;
59167
+ return -1;
59168
+ }
59169
+ if (formula.charAt(idx) === "+") {
59170
+ idx++;
59171
+ }
59172
+ return 1;
59173
+ }
59174
+ function readNumber() {
59175
+ const start = idx;
59176
+ let value = 0;
59177
+ while (idx < formula.length &&
59178
+ formula.charCodeAt(idx) >= ZERO &&
59179
+ formula.charCodeAt(idx) <= NINE) {
59180
+ value = value * 10 + (formula.charCodeAt(idx) - ZERO);
59181
+ idx++;
59182
+ }
59183
+ // Return `null` if we didn't read anything.
59184
+ return idx === start ? null : value;
59185
+ }
59186
+ function skipWhitespace() {
59187
+ while (idx < formula.length &&
59188
+ parse_whitespace.has(formula.charCodeAt(idx))) {
59189
+ idx++;
59190
+ }
59191
+ }
59192
+ }
59193
+ //# sourceMappingURL=parse.js.map
59194
+ // EXTERNAL MODULE: ../node_modules/boolbase/index.js
59195
+ var boolbase = __webpack_require__(286);
59196
+ ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/compile.js
59197
+
59198
+ /**
59199
+ * Returns a function that checks if an elements index matches the given rule
59200
+ * highly optimized to return the fastest solution.
59201
+ *
59202
+ * @param parsed A tuple [a, b], as returned by `parse`.
59203
+ * @returns A highly optimized function that returns whether an index matches the nth-check.
59204
+ * @example
59205
+ *
59206
+ * ```js
59207
+ * const check = nthCheck.compile([2, 3]);
59208
+ *
59209
+ * check(0); // `false`
59210
+ * check(1); // `false`
59211
+ * check(2); // `true`
59212
+ * check(3); // `false`
59213
+ * check(4); // `true`
59214
+ * check(5); // `false`
59215
+ * check(6); // `true`
59216
+ * ```
59217
+ */
59218
+ function compile(parsed) {
59219
+ const a = parsed[0];
59220
+ // Subtract 1 from `b`, to convert from one- to zero-indexed.
59221
+ const b = parsed[1] - 1;
59222
+ /*
59223
+ * When `b <= 0`, `a * n` won't be lead to any matches for `a < 0`.
59224
+ * Besides, the specification states that no elements are
59225
+ * matched when `a` and `b` are 0.
59226
+ *
59227
+ * `b < 0` here as we subtracted 1 from `b` above.
59228
+ */
59229
+ if (b < 0 && a <= 0)
59230
+ return boolbase.falseFunc;
59231
+ // When `a` is in the range -1..1, it matches any element (so only `b` is checked).
59232
+ if (a === -1)
59233
+ return (index) => index <= b;
59234
+ if (a === 0)
59235
+ return (index) => index === b;
59236
+ // When `b <= 0` and `a === 1`, they match any element.
59237
+ if (a === 1)
59238
+ return b < 0 ? boolbase.trueFunc : (index) => index >= b;
59239
+ /*
59240
+ * Otherwise, modulo can be used to check if there is a match.
59241
+ *
59242
+ * Modulo doesn't care about the sign, so let's use `a`s absolute value.
59243
+ */
59244
+ const absA = Math.abs(a);
59245
+ // Get `b mod a`, + a if this is negative.
59246
+ const bMod = ((b % absA) + absA) % absA;
59247
+ return a > 1
59248
+ ? (index) => index >= b && index % absA === bMod
59249
+ : (index) => index <= b && index % absA === bMod;
59250
+ }
59251
+ /**
59252
+ * Returns a function that produces a monotonously increasing sequence of indices.
59253
+ *
59254
+ * If the sequence has an end, the returned function will return `null` after
59255
+ * the last index in the sequence.
59256
+ *
59257
+ * @param parsed A tuple [a, b], as returned by `parse`.
59258
+ * @returns A function that produces a sequence of indices.
59259
+ * @example <caption>Always increasing (2n+3)</caption>
59260
+ *
59261
+ * ```js
59262
+ * const gen = nthCheck.generate([2, 3])
59263
+ *
59264
+ * gen() // `1`
59265
+ * gen() // `3`
59266
+ * gen() // `5`
59267
+ * gen() // `8`
59268
+ * gen() // `11`
59269
+ * ```
59270
+ *
59271
+ * @example <caption>With end value (-2n+10)</caption>
59272
+ *
59273
+ * ```js
59274
+ *
59275
+ * const gen = nthCheck.generate([-2, 5]);
59276
+ *
59277
+ * gen() // 0
59278
+ * gen() // 2
59279
+ * gen() // 4
59280
+ * gen() // null
59281
+ * ```
59282
+ */
59283
+ function compile_generate(parsed) {
59284
+ const a = parsed[0];
59285
+ // Subtract 1 from `b`, to convert from one- to zero-indexed.
59286
+ let b = parsed[1] - 1;
59287
+ let n = 0;
59288
+ // Make sure to always return an increasing sequence
59289
+ if (a < 0) {
59290
+ const aPos = -a;
59291
+ // Get `b mod a`
59292
+ const minValue = ((b % aPos) + aPos) % aPos;
59293
+ return () => {
59294
+ const val = minValue + aPos * n++;
59295
+ return val > b ? null : val;
59296
+ };
59297
+ }
59298
+ if (a === 0)
59299
+ return b < 0
59300
+ ? // There are no result — always return `null`
59301
+ () => null
59302
+ : // Return `b` exactly once
59303
+ () => (n++ === 0 ? b : null);
59304
+ if (b < 0) {
59305
+ b += a * Math.ceil(-b / a);
59306
+ }
59307
+ return () => a * n++ + b;
59308
+ }
59309
+ //# sourceMappingURL=compile.js.map
59310
+ ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/index.js
59311
+
59312
+
59313
+
59314
+ /**
59315
+ * Parses and compiles a formula to a highly optimized function.
59316
+ * Combination of {@link parse} and {@link compile}.
59317
+ *
59318
+ * If the formula doesn't match any elements,
59319
+ * it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
59320
+ * Otherwise, a function accepting an _index_ is returned, which returns
59321
+ * whether or not the passed _index_ matches the formula.
59322
+ *
59323
+ * Note: The nth-rule starts counting at `1`, the returned function at `0`.
59324
+ *
59325
+ * @param formula The formula to compile.
59326
+ * @example
59327
+ * const check = nthCheck("2n+3");
59328
+ *
59329
+ * check(0); // `false`
59330
+ * check(1); // `false`
59331
+ * check(2); // `true`
59332
+ * check(3); // `false`
59333
+ * check(4); // `true`
59334
+ * check(5); // `false`
59335
+ * check(6); // `true`
59336
+ */
59337
+ function nthCheck(formula) {
59338
+ return compile(esm_parse_parse(formula));
59339
+ }
59340
+ /**
59341
+ * Parses and compiles a formula to a generator that produces a sequence of indices.
59342
+ * Combination of {@link parse} and {@link generate}.
59343
+ *
59344
+ * @param formula The formula to compile.
59345
+ * @returns A function that produces a sequence of indices.
59346
+ * @example <caption>Always increasing</caption>
59347
+ *
59348
+ * ```js
59349
+ * const gen = nthCheck.sequence('2n+3')
59350
+ *
59351
+ * gen() // `1`
59352
+ * gen() // `3`
59353
+ * gen() // `5`
59354
+ * gen() // `8`
59355
+ * gen() // `11`
59356
+ * ```
59357
+ *
59358
+ * @example <caption>With end value</caption>
59359
+ *
59360
+ * ```js
59361
+ *
59362
+ * const gen = nthCheck.sequence('-2n+5');
59363
+ *
59364
+ * gen() // 0
59365
+ * gen() // 2
59366
+ * gen() // 4
59367
+ * gen() // null
59368
+ * ```
59369
+ */
59370
+ function sequence(formula) {
59371
+ return generate(parse(formula));
59372
+ }
59373
+ //# sourceMappingURL=index.js.map
59076
59374
  ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/pseudo.js
59077
59375
  /**
59078
59376
  * @typedef {import('./types.js').Rule} Rule
59079
59377
  * @typedef {import('./types.js').RulePseudo} RulePseudo
59080
- * @typedef {import('./types.js').RulePseudoNth} RulePseudoNth
59081
59378
  * @typedef {import('./types.js').RulePseudoSelector} RulePseudoSelector
59082
59379
  * @typedef {import('./types.js').Parent} Parent
59083
- * @typedef {import('./types.js').Selector} Selector
59084
- * @typedef {import('./types.js').Selectors} Selectors
59085
59380
  * @typedef {import('./types.js').SelectState} SelectState
59086
59381
  * @typedef {import('./types.js').Element} Element
59087
59382
  * @typedef {import('./types.js').ElementChild} ElementChild
@@ -59095,75 +59390,54 @@ function cast(values, name) {
59095
59390
 
59096
59391
 
59097
59392
 
59393
+ /** @type {import('nth-check').default} */
59394
+ // @ts-expect-error
59395
+ const pseudo_nthCheck = nthCheck["default"] || nthCheck
59396
+
59397
+ /** @type {(rule: Rule | RulePseudo, element: Element, index: number | undefined, parent: Parent | undefined, state: SelectState) => boolean} */
59098
59398
  const pseudo_handle = zwitch('name', {
59099
- // @ts-expect-error: hush.
59100
59399
  unknown: unknownPseudo,
59101
59400
  invalid: invalidPseudo,
59102
59401
  handlers: {
59103
- // @ts-expect-error: hush.
59104
59402
  any: matches,
59105
- // @ts-expect-error: hush.
59106
59403
  'any-link': anyLink,
59107
- // @ts-expect-error: hush.
59108
59404
  blank,
59109
- // @ts-expect-error: hush.
59110
59405
  checked,
59111
- // @ts-expect-error: hush.
59112
59406
  dir,
59113
- // @ts-expect-error: hush.
59114
59407
  disabled,
59115
- // @ts-expect-error: hush.
59116
59408
  empty,
59117
- // @ts-expect-error: hush.
59118
59409
  enabled,
59119
- // @ts-expect-error: hush.
59120
59410
  'first-child': firstChild,
59121
- // @ts-expect-error: hush.
59122
59411
  'first-of-type': firstOfType,
59123
- // @ts-expect-error: hush.
59124
59412
  has,
59125
- // @ts-expect-error: hush.
59126
59413
  lang: pseudo_lang,
59127
- // @ts-expect-error: hush.
59128
59414
  'last-child': lastChild,
59129
- // @ts-expect-error: hush.
59130
59415
  'last-of-type': lastOfType,
59131
- // @ts-expect-error: hush.
59132
59416
  matches,
59133
- // @ts-expect-error: hush.
59134
59417
  not,
59135
- // @ts-expect-error: hush.
59136
59418
  'nth-child': nthChild,
59137
- // @ts-expect-error: hush.
59138
59419
  'nth-last-child': nthLastChild,
59139
- // @ts-expect-error: hush.
59140
59420
  'nth-of-type': nthOfType,
59141
- // @ts-expect-error: hush.
59142
59421
  'nth-last-of-type': nthLastOfType,
59143
- // @ts-expect-error: hush.
59144
59422
  'only-child': onlyChild,
59145
- // @ts-expect-error: hush.
59146
59423
  'only-of-type': onlyOfType,
59147
- // @ts-expect-error: hush.
59148
59424
  optional,
59149
- // @ts-expect-error: hush.
59150
59425
  'read-only': readOnly,
59151
- // @ts-expect-error: hush.
59152
59426
  'read-write': readWrite,
59153
- // @ts-expect-error: hush.
59154
59427
  required,
59155
- // @ts-expect-error: hush.
59156
59428
  root: pseudo_root,
59157
- // @ts-expect-error: hush.
59158
59429
  scope
59159
59430
  }
59160
59431
  })
59161
59432
 
59162
59433
  pseudo.needsIndex = [
59434
+ 'any',
59163
59435
  'first-child',
59164
59436
  'first-of-type',
59165
59437
  'last-child',
59166
59438
  'last-of-type',
59439
+ 'matches',
59440
+ 'not',
59167
59441
  'nth-child',
59168
59442
  'nth-last-child',
59169
59443
  'nth-of-type',
@@ -59173,10 +59447,12 @@ pseudo.needsIndex = [
59173
59447
  ]
59174
59448
 
59175
59449
  /**
59450
+ * Check whether an element matches pseudo selectors.
59451
+ *
59176
59452
  * @param {Rule} query
59177
59453
  * @param {Element} element
59178
- * @param {number|null} index
59179
- * @param {Parent|null} parent
59454
+ * @param {number | undefined} index
59455
+ * @param {Parent | undefined} parent
59180
59456
  * @param {SelectState} state
59181
59457
  * @returns {boolean}
59182
59458
  */
@@ -59192,58 +59468,51 @@ function pseudo(query, element, index, parent, state) {
59192
59468
  }
59193
59469
 
59194
59470
  /**
59195
- * @param {RulePseudoSelector} query
59196
- * @param {Element} element
59197
- * @param {number|null} _1
59198
- * @param {Parent|null} _2
59199
- * @param {SelectState} state
59200
- * @returns {boolean}
59201
- */
59202
- function matches(query, element, _1, _2, state) {
59203
- const shallow = state.shallow
59204
- const one = state.one
59205
-
59206
- state.shallow = true
59207
- state.one = true
59208
-
59209
- const result = any_any(query.value, element, state)[0] === element
59210
-
59211
- state.shallow = shallow
59212
- state.one = one
59213
-
59214
- return result
59215
- }
59216
-
59217
- /**
59218
- * @param {RulePseudoSelector} query
59471
+ * Check whether an element matches an `:any-link` pseudo.
59472
+ *
59473
+ * @param {RulePseudo} _
59219
59474
  * @param {Element} element
59220
- * @param {number|null} index
59221
- * @param {Parent|null} parent
59222
- * @param {SelectState} state
59223
59475
  * @returns {boolean}
59224
59476
  */
59225
- function not(query, element, index, parent, state) {
59226
- return !matches(query, element, index, parent, state)
59477
+ function anyLink(_, element) {
59478
+ return (
59479
+ (element.tagName === 'a' ||
59480
+ element.tagName === 'area' ||
59481
+ element.tagName === 'link') &&
59482
+ hasProperty(element, 'href')
59483
+ )
59227
59484
  }
59228
59485
 
59229
59486
  /**
59487
+ * Check whether an element matches a `:blank` pseudo.
59488
+ *
59230
59489
  * @param {RulePseudo} _
59231
59490
  * @param {Element} element
59232
59491
  * @returns {boolean}
59233
59492
  */
59234
- function anyLink(_, element) {
59235
- return (
59236
- isElement(element, ['a', 'area', 'link']) && hasProperty(element, 'href')
59237
- )
59493
+ function blank(_, element) {
59494
+ return !someChildren(element, check)
59495
+
59496
+ /**
59497
+ * @param {ElementChild} child
59498
+ * @returns {boolean}
59499
+ */
59500
+ function check(child) {
59501
+ return (
59502
+ child.type === 'element' || (child.type === 'text' && !whitespace(child))
59503
+ )
59504
+ }
59238
59505
  }
59239
59506
 
59240
59507
  /**
59508
+ * Check whether an element matches a `:checked` pseudo.
59509
+ *
59241
59510
  * @param {RulePseudo} _
59242
59511
  * @param {Element} element
59243
59512
  * @returns {boolean}
59244
59513
  */
59245
59514
  function checked(_, element) {
59246
- if (isElement(element, ['input', 'menuitem'])) {
59515
+ if (element.tagName === 'input' || element.tagName === 'menuitem') {
59247
59516
  return Boolean(
59248
59517
  element.properties &&
59249
59518
  (element.properties.type === 'checkbox' ||
@@ -59252,7 +59521,7 @@ function checked(_, element) {
59252
59521
  )
59253
59522
  }
59254
59523
 
59255
- if (isElement(element, 'option')) {
59524
+ if (element.tagName === 'option') {
59256
59525
  return hasProperty(element, 'selected')
59257
59526
  }
59258
59527
 
@@ -59260,10 +59529,12 @@ function checked(_, element) {
59260
59529
  }
59261
59530
 
59262
59531
  /**
59532
+ * Check whether an element matches a `:dir()` pseudo.
59533
+ *
59263
59534
  * @param {RulePseudo} query
59264
59535
  * @param {Element} _1
59265
- * @param {number|null} _2
59266
- * @param {Parent|null} _3
59536
+ * @param {number | undefined} _2
59537
+ * @param {Parent | undefined} _3
59267
59538
  * @param {SelectState} state
59268
59539
  * @returns {boolean}
59269
59540
  */
@@ -59272,168 +59543,119 @@ function dir(query, _1, _2, _3, state) {
59272
59543
  }
59273
59544
 
59274
59545
  /**
59546
+ * Check whether an element matches a `:disabled` pseudo.
59547
+ *
59275
59548
  * @param {RulePseudo} _
59276
59549
  * @param {Element} element
59277
59550
  * @returns {boolean}
59278
59551
  */
59279
59552
  function disabled(_, element) {
59280
59553
  return (
59281
- isElement(element, [
59282
- 'button',
59283
- 'input',
59284
- 'select',
59285
- 'textarea',
59286
- 'optgroup',
59287
- 'option',
59288
- 'menuitem',
59289
- 'fieldset'
59290
- ]) && hasProperty(element, 'disabled')
59554
+ (element.tagName === 'button' ||
59555
+ element.tagName === 'input' ||
59556
+ element.tagName === 'select' ||
59557
+ element.tagName === 'textarea' ||
59558
+ element.tagName === 'optgroup' ||
59559
+ element.tagName === 'option' ||
59560
+ element.tagName === 'menuitem' ||
59561
+ element.tagName === 'fieldset') &&
59562
+ hasProperty(element, 'disabled')
59291
59563
  )
59292
59564
  }
59293
59565
 
59294
59566
  /**
59295
- * @param {RulePseudo} query
59296
- * @param {Element} element
59297
- * @returns {boolean}
59298
- */
59299
- function enabled(query, element) {
59300
- return !disabled(query, element)
59301
- }
59302
-
59303
- /**
59567
+ * Check whether an element matches an `:empty` pseudo.
59568
+ *
59304
59569
  * @param {RulePseudo} _
59305
59570
  * @param {Element} element
59306
59571
  * @returns {boolean}
59307
59572
  */
59308
- function required(_, element) {
59309
- return (
59310
- isElement(element, ['input', 'textarea', 'select']) &&
59311
- hasProperty(element, 'required')
59312
- )
59313
- }
59573
+ function empty(_, element) {
59574
+ return !someChildren(element, check)
59314
59575
 
59315
- /**
59316
- * @param {RulePseudo} query
59317
- * @param {Element} element
59318
- * @returns {boolean}
59319
- */
59320
- function optional(query, element) {
59321
- return !required(query, element)
59576
+ /**
59577
+ * @param {ElementChild} child
59578
+ * @returns {boolean}
59579
+ */
59580
+ function check(child) {
59581
+ return child.type === 'element' || child.type === 'text'
59582
+ }
59322
59583
  }
59323
59584
 
59324
59585
  /**
59325
- * @param {RulePseudo} _
59586
+ * Check whether an element matches an `:enabled` pseudo.
59587
+ *
59588
+ * @param {RulePseudo} query
59326
59589
  * @param {Element} element
59327
- * @param {number|null} _1
59328
- * @param {Parent|null} _2
59329
- * @param {SelectState} state
59330
59590
  * @returns {boolean}
59331
59591
  */
59332
- function readWrite(_, element, _1, _2, state) {
59333
- return isElement(element, ['input', 'textarea'])
59334
- ? !hasProperty(element, 'readOnly') && !hasProperty(element, 'disabled')
59335
- : Boolean(state.editableOrEditingHost)
59592
+ function enabled(query, element) {
59593
+ return !disabled(query, element)
59336
59594
  }
59337
59595
 
59338
59596
  /**
59597
+ * Check whether an element matches a `:first-child` pseudo.
59598
+ *
59339
59599
  * @param {RulePseudo} query
59340
- * @param {Element} element
59341
- * @param {number|null} index
59342
- * @param {Parent|null} parent
59600
+ * @param {Element} _1
59601
+ * @param {number | undefined} _2
59602
+ * @param {Parent | undefined} _3
59343
59603
  * @param {SelectState} state
59344
59604
  * @returns {boolean}
59345
59605
  */
59346
- function readOnly(query, element, index, parent, state) {
59347
- return !readWrite(query, element, index, parent, state)
59606
+ function firstChild(query, _1, _2, _3, state) {
59607
+ assertDeep(state, query)
59608
+ return state.elementIndex === 0
59348
59609
  }
59349
59610
 
59350
59611
  /**
59351
- * @param {RulePseudo} _
59352
- * @param {Element} element
59353
- * @param {number|null} _1
59354
- * @param {Parent|null} parent
59612
+ * Check whether an element matches a `:first-of-type` pseudo.
59613
+ *
59614
+ * @param {RulePseudo} query
59615
+ * @param {Element} _1
59616
+ * @param {number | undefined} _2
59617
+ * @param {Parent | undefined} _3
59355
59618
  * @param {SelectState} state
59356
59619
  * @returns {boolean}
59357
59620
  */
59358
- function pseudo_root(_, element, _1, parent, state) {
59359
- return Boolean(
59360
- (!parent || parent.type === 'root') &&
59361
- state.schema &&
59362
- (state.schema.space === 'html' || state.schema.space === 'svg') &&
59363
- isElement(element, ['html', 'svg'])
59364
- )
59621
+ function firstOfType(query, _1, _2, _3, state) {
59622
+ assertDeep(state, query)
59623
+ return state.typeIndex === 0
59365
59624
  }
59366
59625
 
59367
59626
  /**
59368
- * @param {RulePseudo} _
59627
+ * @param {RulePseudoSelector} query
59369
59628
  * @param {Element} element
59370
- * @param {number|null} _1
59371
- * @param {Parent|null} _2
59629
+ * @param {number | undefined} _1
59630
+ * @param {Parent | undefined} _2
59372
59631
  * @param {SelectState} state
59373
59632
  * @returns {boolean}
59374
59633
  */
59375
- function scope(_, element, _1, _2, state) {
59376
- return Boolean(
59377
- isElement(element) &&
59378
- state.scopeElements &&
59379
- state.scopeElements.includes(element)
59380
- )
59381
- }
59382
-
59383
- /**
59384
- * @param {RulePseudo} _
59385
- * @param {Element} element
59386
- * @returns {boolean}
59387
- */
59388
- function empty(_, element) {
59389
- return !someChildren(element, check)
59390
-
59391
- /**
59392
- * @param {ElementChild} child
59393
- * @returns {boolean}
59394
- */
59395
- function check(child) {
59396
- return child.type === 'element' || child.type === 'text'
59634
+ function has(query, element, _1, _2, state) {
59635
+ /** @type {SelectState} */
59636
+ const childState = {
59637
+ ...state,
59638
+ // Do walk deep.
59639
+ shallow: false,
59640
+ // One result is enough.
59641
+ one: true,
59642
+ scopeElements: [element],
59643
+ results: [],
59644
+ rootQuery: queryToSelectors(query.value)
59397
59645
  }
59398
- }
59399
-
59400
- /**
59401
- * @param {RulePseudo} _
59402
- * @param {Element} element
59403
- * @returns {boolean}
59404
- */
59405
- function blank(_, element) {
59406
- return !someChildren(element, check)
59407
59646
 
59408
- /**
59409
- * @param {ElementChild} child
59410
- * @returns {boolean}
59411
- */
59412
- function check(child) {
59413
- return (
59414
- child.type === 'element' || (child.type === 'text' && !whitespace(child))
59415
- )
59416
- }
59417
- }
59647
+ walk_walk(childState, {type: 'root', children: element.children})
59418
59648
 
59419
- /**
59420
- * @param {RulePseudo} query
59421
- * @param {Element} _1
59422
- * @param {number|null} _2
59423
- * @param {Parent|null} _3
59424
- * @param {SelectState} state
59425
- * @returns {boolean}
59426
- */
59427
- function firstChild(query, _1, _2, _3, state) {
59428
- assertDeep(state, query)
59429
- return state.elementIndex === 0
59649
+ return childState.results.length > 0
59430
59650
  }
59431
59651
 
59432
59652
  /**
59653
+ * Check whether an element matches a `:lang()` pseudo.
59654
+ *
59433
59655
  * @param {RulePseudo} query
59434
59656
  * @param {Element} _1
59435
- * @param {number|null} _2
59436
- * @param {Parent|null} _3
59657
+ * @param {number | undefined} _2
59658
+ * @param {Parent | undefined} _3
59437
59659
  * @param {SelectState} state
59438
59660
  * @returns {boolean}
59439
59661
  */
@@ -59441,17 +59663,18 @@ function pseudo_lang(query, _1, _2, _3, state) {
59441
59663
  return (
59442
59664
  state.language !== '' &&
59443
59665
  state.language !== undefined &&
59444
- state.language !== null &&
59445
59666
  // @ts-expect-error never `selectors`.
59446
59667
  extendedFilter(state.language, comma_separated_tokens_parse(query.value)).length > 0
59447
59668
  )
59448
59669
  }
59449
59670
 
59450
59671
  /**
59672
+ * Check whether an element matches a `:last-child` pseudo.
59673
+ *
59451
59674
  * @param {RulePseudo} query
59452
59675
  * @param {Element} _1
59453
- * @param {number|null} _2
59454
- * @param {Parent|null} _3
59676
+ * @param {number | undefined} _2
59677
+ * @param {Parent | undefined} _3
59455
59678
  * @param {SelectState} state
59456
59679
  * @returns {boolean}
59457
59680
  */
@@ -59463,115 +59686,160 @@ function lastChild(query, _1, _2, _3, state) {
59463
59686
  }
59464
59687
 
59465
59688
  /**
59689
+ * Check whether an element matches a `:last-of-type` pseudo.
59690
+ *
59466
59691
  * @param {RulePseudo} query
59467
59692
  * @param {Element} _1
59468
- * @param {number|null} _2
59469
- * @param {Parent|null} _3
59693
+ * @param {number | undefined} _2
59694
+ * @param {Parent | undefined} _3
59470
59695
  * @param {SelectState} state
59471
59696
  * @returns {boolean}
59472
59697
  */
59473
- function onlyChild(query, _1, _2, _3, state) {
59698
+ function lastOfType(query, _1, _2, _3, state) {
59474
59699
  assertDeep(state, query)
59475
- return state.elementCount === 1
59700
+ return (
59701
+ typeof state.typeIndex === 'number' &&
59702
+ typeof state.typeCount === 'number' &&
59703
+ state.typeIndex === state.typeCount - 1
59704
+ )
59476
59705
  }
59477
59706
 
59478
59707
  /**
59479
- * @param {RulePseudoNth} query
59480
- * @param {Element} _1
59481
- * @param {number|null} _2
59482
- * @param {Parent|null} _3
59708
+ * Check whether an element `:matches` further selectors.
59709
+ *
59710
+ * @param {RulePseudoSelector} query
59711
+ * @param {Element} element
59712
+ * @param {number | undefined} _
59713
+ * @param {Parent | undefined} parent
59483
59714
  * @param {SelectState} state
59484
59715
  * @returns {boolean}
59485
59716
  */
59486
- function nthChild(query, _1, _2, _3, state) {
59487
- assertDeep(state, query)
59488
- return (
59489
- typeof state.elementIndex === 'number' && query.value(state.elementIndex)
59490
- )
59717
+ function matches(query, element, _, parent, state) {
59718
+ /** @type {SelectState} */
59719
+ const childState = {
59720
+ ...state,
59721
+ // Do walk deep.
59722
+ shallow: false,
59723
+ // One result is enough.
59724
+ one: true,
59725
+ scopeElements: [element],
59726
+ results: [],
59727
+ rootQuery: queryToSelectors(query.value)
59728
+ }
59729
+
59730
+ walk_walk(childState, element)
59731
+
59732
+ return childState.results[0] === element
59733
+ }
59734
+
59735
+ /**
59736
+ * Check whether an element does `:not` match further selectors.
59737
+ *
59738
+ * @param {RulePseudoSelector} query
59739
+ * @param {Element} element
59740
+ * @param {number | undefined} index
59741
+ * @param {Parent | undefined} parent
59742
+ * @param {SelectState} state
59743
+ * @returns {boolean}
59744
+ */
59745
+ function not(query, element, index, parent, state) {
59746
+ return !matches(query, element, index, parent, state)
59491
59747
  }
59492
59748
 
59493
59749
  /**
59494
- * @param {RulePseudoNth} query
59750
+ * Check whether an element matches an `:nth-child` pseudo.
59751
+ *
59752
+ * @param {RulePseudo} query
59495
59753
  * @param {Element} _1
59496
- * @param {number|null} _2
59497
- * @param {Parent|null} _3
59754
+ * @param {number | undefined} _2
59755
+ * @param {Parent | undefined} _3
59498
59756
  * @param {SelectState} state
59499
59757
  * @returns {boolean}
59500
59758
  */
59501
- function nthLastChild(query, _1, _2, _3, state) {
59759
+ function nthChild(query, _1, _2, _3, state) {
59760
+ const fn = getCachedNthCheck(query)
59502
59761
  assertDeep(state, query)
59503
- return Boolean(
59504
- typeof state.elementCount === 'number' &&
59505
- typeof state.elementIndex === 'number' &&
59506
- query.value(state.elementCount - state.elementIndex - 1)
59507
- )
59762
+ return typeof state.elementIndex === 'number' && fn(state.elementIndex)
59508
59763
  }
59509
59764
 
59510
59765
  /**
59511
- * @param {RulePseudoNth} query
59766
+ * Check whether an element matches an `:nth-last-child` pseudo.
59767
+ *
59768
+ * @param {RulePseudo} query
59512
59769
  * @param {Element} _1
59513
- * @param {number|null} _2
59514
- * @param {Parent|null} _3
59770
+ * @param {number | undefined} _2
59771
+ * @param {Parent | undefined} _3
59515
59772
  * @param {SelectState} state
59516
59773
  * @returns {boolean}
59517
59774
  */
59518
- function nthOfType(query, _1, _2, _3, state) {
59775
+ function nthLastChild(query, _1, _2, _3, state) {
59776
+ const fn = getCachedNthCheck(query)
59519
59777
  assertDeep(state, query)
59520
- return typeof state.typeIndex === 'number' && query.value(state.typeIndex)
59778
+ return Boolean(
59779
+ typeof state.elementCount === 'number' &&
59780
+ typeof state.elementIndex === 'number' &&
59781
+ fn(state.elementCount - state.elementIndex - 1)
59782
+ )
59521
59783
  }
59522
59784
 
59523
59785
  /**
59524
- * @param {RulePseudoNth} query
59786
+ * Check whether an element matches a `:nth-last-of-type` pseudo.
59787
+ *
59788
+ * @param {RulePseudo} query
59525
59789
  * @param {Element} _1
59526
- * @param {number|null} _2
59527
- * @param {Parent|null} _3
59790
+ * @param {number | undefined} _2
59791
+ * @param {Parent | undefined} _3
59528
59792
  * @param {SelectState} state
59529
59793
  * @returns {boolean}
59530
59794
  */
59531
59795
  function nthLastOfType(query, _1, _2, _3, state) {
59796
+ const fn = getCachedNthCheck(query)
59532
59797
  assertDeep(state, query)
59533
59798
  return (
59534
59799
  typeof state.typeCount === 'number' &&
59535
59800
  typeof state.typeIndex === 'number' &&
59536
- query.value(state.typeCount - 1 - state.typeIndex)
59801
+ fn(state.typeCount - 1 - state.typeIndex)
59537
59802
  )
59538
59803
  }
59539
59804
 
59540
59805
  /**
59806
+ * Check whether an element matches an `:nth-of-type` pseudo.
59807
+ *
59541
59808
  * @param {RulePseudo} query
59542
59809
  * @param {Element} _1
59543
- * @param {number|null} _2
59544
- * @param {Parent|null} _3
59810
+ * @param {number | undefined} _2
59811
+ * @param {Parent | undefined} _3
59545
59812
  * @param {SelectState} state
59546
59813
  * @returns {boolean}
59547
59814
  */
59548
- function firstOfType(query, _1, _2, _3, state) {
59815
+ function nthOfType(query, _1, _2, _3, state) {
59816
+ const fn = getCachedNthCheck(query)
59549
59817
  assertDeep(state, query)
59550
- return state.typeIndex === 0
59818
+ return typeof state.typeIndex === 'number' && fn(state.typeIndex)
59551
59819
  }
59552
59820
 
59553
59821
  /**
59822
+ * Check whether an element matches an `:only-child` pseudo.
59823
+ *
59554
59824
  * @param {RulePseudo} query
59555
59825
  * @param {Element} _1
59556
- * @param {number|null} _2
59557
- * @param {Parent|null} _3
59826
+ * @param {number | undefined} _2
59827
+ * @param {Parent | undefined} _3
59558
59828
  * @param {SelectState} state
59559
59829
  * @returns {boolean}
59560
59830
  */
59561
- function lastOfType(query, _1, _2, _3, state) {
59831
+ function onlyChild(query, _1, _2, _3, state) {
59562
59832
  assertDeep(state, query)
59563
- return (
59564
- typeof state.typeIndex === 'number' &&
59565
- typeof state.typeCount === 'number' &&
59566
- state.typeIndex === state.typeCount - 1
59567
- )
59833
+ return state.elementCount === 1
59568
59834
  }
59569
59835
 
59570
59836
  /**
59837
+ * Check whether an element matches an `:only-of-type` pseudo.
59838
+ *
59571
59839
  * @param {RulePseudo} query
59572
59840
  * @param {Element} _1
59573
- * @param {number|null} _2
59574
- * @param {Parent|null} _3
59841
+ * @param {number | undefined} _2
59842
+ * @param {Parent | undefined} _3
59575
59843
  * @param {SelectState} state
59576
59844
  * @returns {boolean}
59577
59845
  */
@@ -59581,389 +59849,168 @@ function onlyOfType(query, _1, _2, _3, state) {
59581
59849
  }
59582
59850
 
59583
59851
  /**
59584
- * @param {Element} element
59585
- * @param {(child: ElementChild) => boolean} check
59586
- * @returns {boolean}
59587
- */
59588
- function someChildren(element, check) {
59589
- const children = element.children
59590
- let index = -1
59591
-
59592
- while (++index < children.length) {
59593
- if (check(children[index])) return true
59594
- }
59595
-
59596
- return false
59597
- }
59598
-
59599
- // Shouldn’t be called, parser gives correct data.
59600
- /* c8 ignore next 3 */
59601
- function invalidPseudo() {
59602
- throw new Error('Invalid pseudo-selector')
59603
- }
59604
-
59605
- /**
59852
+ * Check whether an element matches an `:optional` pseudo.
59853
+ *
59606
59854
  * @param {RulePseudo} query
59607
- */
59608
- function unknownPseudo(query) {
59609
- if (query.name) {
59610
- throw new Error('Unknown pseudo-selector `' + query.name + '`')
59611
- }
59612
-
59613
- throw new Error('Unexpected pseudo-element or empty pseudo-class')
59614
- }
59615
-
59616
- /**
59617
- * @param {SelectState} state
59618
- * @param {RulePseudo|RulePseudoNth} query
59619
- */
59620
- function assertDeep(state, query) {
59621
- if (state.shallow) {
59622
- throw new Error('Cannot use `:' + query.name + '` without parent')
59623
- }
59624
- }
59625
-
59626
- /**
59627
- * @param {RulePseudoSelector} query
59628
59855
  * @param {Element} element
59629
- * @param {number|null} _2
59630
- * @param {Parent|null} _3
59631
- * @param {SelectState} state
59632
59856
  * @returns {boolean}
59633
59857
  */
59634
- function has(query, element, _2, _3, state) {
59635
- const shallow = state.shallow
59636
- const one = state.one
59637
- const scopeElements = state.scopeElements
59638
- const value = appendScope(query.value)
59639
-
59640
- state.shallow = false
59641
- state.one = true
59642
- state.scopeElements = [element]
59643
-
59644
- const result = any_any(value, element, state).length > 0
59645
-
59646
- state.shallow = shallow
59647
- state.one = one
59648
- state.scopeElements = scopeElements
59649
-
59650
- return result
59651
- }
59652
-
59653
- /**
59654
- * @param {Selector} value
59655
- * @returns {Selectors}
59656
- */
59657
- function appendScope(value) {
59658
- /** @type {Selectors} */
59659
- const selector =
59660
- value.type === 'ruleSet' ? {type: 'selectors', selectors: [value]} : value
59661
- let index = -1
59662
-
59663
- while (++index < selector.selectors.length) {
59664
- const rule = selector.selectors[index].rule
59665
- rule.nestingOperator = null
59666
-
59667
- if (
59668
- !rule.pseudos ||
59669
- rule.pseudos.length !== 1 ||
59670
- rule.pseudos[0].name !== 'scope'
59671
- ) {
59672
- selector.selectors[index] = {
59673
- type: 'ruleSet',
59674
- // @ts-expect-error pseudos are fine w/ just a name!
59675
- rule: {type: 'rule', rule, pseudos: [{name: 'scope'}]}
59676
- }
59677
- }
59678
- }
59679
-
59680
- return selector
59681
- }
59682
-
59683
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/attribute.js
59684
- /**
59685
- * @typedef {import('./types.js').Rule} Rule
59686
- * @typedef {import('./types.js').RuleAttr} RuleAttr
59687
- * @typedef {import('./types.js').Element} Element
59688
- * @typedef {import('./types.js').Schema} Schema
59689
- * @typedef {import('./types.js').Info} Info
59690
- * @typedef {import('./types.js').PropertyValue} PropertyValue
59691
- */
59692
-
59693
-
59694
-
59695
-
59696
-
59697
-
59698
-
59699
- const attribute_handle = zwitch('operator', {
59700
- // @ts-expect-error: hush.
59701
- unknown: unknownOperator,
59702
- // @ts-expect-error: hush.
59703
- invalid: exists,
59704
- handlers: {
59705
- // @ts-expect-error: hush.
59706
- '=': exact,
59707
- // @ts-expect-error: hush.
59708
- '~=': spaceSeparatedList,
59709
- // @ts-expect-error: hush.
59710
- '|=': exactOrPrefix,
59711
- // @ts-expect-error: hush.
59712
- '^=': begins,
59713
- // @ts-expect-error: hush.
59714
- '$=': ends,
59715
- // @ts-expect-error: hush.
59716
- '*=': contains
59717
- }
59718
- })
59719
-
59720
- /**
59721
- * @param {Rule} query
59722
- * @param {Element} element
59723
- * @param {Schema} schema
59724
- * @returns {boolean}
59725
- */
59726
- function attribute(query, element, schema) {
59727
- const attrs = query.attrs
59728
- let index = -1
59729
-
59730
- while (++index < attrs.length) {
59731
- if (!attribute_handle(attrs[index], element, find(schema, attrs[index].name))) {
59732
- return false
59733
- }
59734
- }
59735
-
59736
- return true
59858
+ function optional(query, element) {
59859
+ return !required(query, element)
59737
59860
  }
59738
59861
 
59739
59862
  /**
59740
- * `[attr]`
59863
+ * Check whether an element matches a `:read-only` pseudo.
59741
59864
  *
59742
- * @param {RuleAttr} _
59865
+ * @param {RulePseudo} query
59743
59866
  * @param {Element} element
59744
- * @param {Info} info
59867
+ * @param {number | undefined} index
59868
+ * @param {Parent | undefined} parent
59869
+ * @param {SelectState} state
59745
59870
  * @returns {boolean}
59746
59871
  */
59747
- function exists(_, element, info) {
59748
- return hasProperty(element, info.property)
59872
+ function readOnly(query, element, index, parent, state) {
59873
+ return !readWrite(query, element, index, parent, state)
59749
59874
  }
59750
59875
 
59751
59876
  /**
59752
- * `[attr=value]`
59877
+ * Check whether an element matches a `:read-write` pseudo.
59753
59878
  *
59754
- * @param {RuleAttr} query
59879
+ * @param {RulePseudo} _
59755
59880
  * @param {Element} element
59756
- * @param {Info} info
59881
+ * @param {number | undefined} _1
59882
+ * @param {Parent | undefined} _2
59883
+ * @param {SelectState} state
59757
59884
  * @returns {boolean}
59758
59885
  */
59759
- function exact(query, element, info) {
59760
- return Boolean(
59761
- hasProperty(element, info.property) &&
59762
- element.properties &&
59763
- normalizeValue(element.properties[info.property], info) === query.value
59764
- )
59886
+ function readWrite(_, element, _1, _2, state) {
59887
+ return element.tagName === 'input' || element.tagName === 'textarea'
59888
+ ? !hasProperty(element, 'readOnly') && !hasProperty(element, 'disabled')
59889
+ : Boolean(state.editableOrEditingHost)
59765
59890
  }
59766
59891
 
59767
59892
  /**
59768
- * `[attr~=value]`
59893
+ * Check whether an element matches a `:required` pseudo.
59769
59894
  *
59770
- * @param {RuleAttr} query
59895
+ * @param {RulePseudo} _
59771
59896
  * @param {Element} element
59772
- * @param {Info} info
59773
59897
  * @returns {boolean}
59774
59898
  */
59775
- function spaceSeparatedList(query, element, info) {
59776
- const value = element.properties && element.properties[info.property]
59777
-
59899
+ function required(_, element) {
59778
59900
  return (
59779
- // If this is a comma-separated list, and the query is contained in it, return
59780
- // true.
59781
- (!info.commaSeparated &&
59782
- value &&
59783
- typeof value === 'object' &&
59784
- query.value &&
59785
- value.includes(query.value)) ||
59786
- // For all other values (including comma-separated lists), return whether this
59787
- // is an exact match.
59788
- (hasProperty(element, info.property) &&
59789
- normalizeValue(value, info) === query.value)
59790
- )
59791
- }
59792
-
59793
- /**
59794
- * `[attr|=value]`
59795
- *
59796
- * @param {RuleAttr} query
59797
- * @param {Element} element
59798
- * @param {Info} info
59799
- * @returns {boolean}
59800
- */
59801
- function exactOrPrefix(query, element, info) {
59802
- const value = normalizeValue(
59803
- element.properties && element.properties[info.property],
59804
- info
59805
- )
59806
-
59807
- return Boolean(
59808
- hasProperty(element, info.property) &&
59809
- query.value &&
59810
- (value === query.value ||
59811
- (value.slice(0, query.value.length) === query.value &&
59812
- value.charAt(query.value.length) === '-'))
59813
- )
59814
- }
59815
-
59816
- /**
59817
- * `[attr^=value]`
59818
- *
59819
- * @param {RuleAttr} query
59820
- * @param {Element} element
59821
- * @param {Info} info
59822
- * @returns {boolean}
59823
- */
59824
- function begins(query, element, info) {
59825
- return Boolean(
59826
- hasProperty(element, info.property) &&
59827
- element.properties &&
59828
- query.value &&
59829
- normalizeValue(element.properties[info.property], info).slice(
59830
- 0,
59831
- query.value.length
59832
- ) === query.value
59901
+ (element.tagName === 'input' ||
59902
+ element.tagName === 'textarea' ||
59903
+ element.tagName === 'select') &&
59904
+ hasProperty(element, 'required')
59833
59905
  )
59834
59906
  }
59835
59907
 
59836
59908
  /**
59837
- * `[attr$=value]`
59909
+ * Check whether an element matches a `:root` pseudo.
59838
59910
  *
59839
- * @param {RuleAttr} query
59911
+ * @param {RulePseudo} _
59840
59912
  * @param {Element} element
59841
- * @param {Info} info
59913
+ * @param {number | undefined} _1
59914
+ * @param {Parent | undefined} parent
59915
+ * @param {SelectState} state
59842
59916
  * @returns {boolean}
59843
59917
  */
59844
- function ends(query, element, info) {
59918
+ function pseudo_root(_, element, _1, parent, state) {
59845
59919
  return Boolean(
59846
- hasProperty(element, info.property) &&
59847
- element.properties &&
59848
- query.value &&
59849
- normalizeValue(element.properties[info.property], info).slice(
59850
- -query.value.length
59851
- ) === query.value
59920
+ (!parent || parent.type === 'root') &&
59921
+ state.schema &&
59922
+ (state.schema.space === 'html' || state.schema.space === 'svg') &&
59923
+ (element.tagName === 'html' || element.tagName === 'svg')
59852
59924
  )
59853
59925
  }
59854
59926
 
59855
59927
  /**
59856
- * `[attr*=value]`
59928
+ * Check whether an element matches a `:scope` pseudo.
59857
59929
  *
59858
- * @param {RuleAttr} query
59930
+ * @param {RulePseudo} _
59859
59931
  * @param {Element} element
59860
- * @param {Info} info
59932
+ * @param {number | undefined} _1
59933
+ * @param {Parent | undefined} _2
59934
+ * @param {SelectState} state
59861
59935
  * @returns {boolean}
59862
59936
  */
59863
- function contains(query, element, info) {
59864
- return Boolean(
59865
- hasProperty(element, info.property) &&
59866
- element.properties &&
59867
- query.value &&
59868
- normalizeValue(element.properties[info.property], info).includes(
59869
- query.value
59870
- )
59871
- )
59937
+ function scope(_, element, _1, _2, state) {
59938
+ return state.scopeElements.includes(element)
59872
59939
  }
59873
59940
 
59874
- // Shouldn’t be called, Parser throws an error instead.
59875
- /**
59876
- * @param {RuleAttr} query
59877
- * @returns {boolean}
59878
- */
59941
+ // Shouldn’t be called, parser gives correct data.
59879
59942
  /* c8 ignore next 3 */
59880
- function unknownOperator(query) {
59881
- throw new Error('Unknown operator `' + query.operator + '`')
59943
+ function invalidPseudo() {
59944
+ throw new Error('Invalid pseudo-selector')
59882
59945
  }
59883
59946
 
59884
59947
  /**
59885
- * Stringify a hast value back to its HTML form.
59886
- *
59887
- * @param {PropertyValue} value
59888
- * @param {Info} info
59889
- * @returns {string}
59948
+ * @param {unknown} query
59949
+ * @returns {never}
59890
59950
  */
59891
- function normalizeValue(value, info) {
59892
- if (typeof value === 'boolean') {
59893
- return info.attribute
59894
- }
59895
-
59896
- if (Array.isArray(value)) {
59897
- return (info.commaSeparated ? comma_separated_tokens_stringify : stringify)(value)
59951
+ function unknownPseudo(query) {
59952
+ // @ts-expect-error: indexable.
59953
+ if (query.name) {
59954
+ // @ts-expect-error: indexable.
59955
+ throw new Error('Unknown pseudo-selector `' + query.name + '`')
59898
59956
  }
59899
59957
 
59900
- return String(value)
59958
+ throw new Error('Unexpected pseudo-element or empty pseudo-class')
59901
59959
  }
59902
59960
 
59903
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/class-name.js
59904
59961
  /**
59905
- * @typedef {import('./types.js').Rule} Rule
59906
- * @typedef {import('./types.js').Element} Element
59907
- */
59908
-
59909
- /**
59910
- * @param {Rule} query
59962
+ * Check children.
59963
+ *
59911
59964
  * @param {Element} element
59965
+ * @param {(child: ElementChild) => boolean} check
59912
59966
  * @returns {boolean}
59913
59967
  */
59914
- function className(query, element) {
59915
- /** @type {Array<string>} */
59916
- // @ts-expect-error Assume array.
59917
- const value = element.properties.className || []
59968
+ function someChildren(element, check) {
59969
+ const children = element.children
59918
59970
  let index = -1
59919
59971
 
59920
- if (query.classNames) {
59921
- while (++index < query.classNames.length) {
59922
- if (!value.includes(query.classNames[index])) return false
59923
- }
59972
+ while (++index < children.length) {
59973
+ if (check(children[index])) return true
59924
59974
  }
59925
59975
 
59926
- return true
59976
+ return false
59927
59977
  }
59928
59978
 
59929
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/id.js
59930
59979
  /**
59931
- * @typedef {import('./types.js').Rule} Rule
59932
- * @typedef {import('./types.js').Element} Element
59933
- */
59934
-
59935
- /**
59936
- * @param {Rule} query
59937
- * @param {Element} element
59938
- * @returns {boolean}
59980
+ * @param {SelectState} state
59981
+ * @param {RulePseudo} query
59939
59982
  */
59940
- function id(query, element) {
59941
- return Boolean(element.properties && element.properties.id === query.id)
59983
+ function assertDeep(state, query) {
59984
+ if (state.shallow) {
59985
+ throw new Error('Cannot use `:' + query.name + '` without parent')
59986
+ }
59942
59987
  }
59943
59988
 
59944
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/name.js
59945
59989
  /**
59946
- * @typedef {import('./types.js').Rule} Rule
59947
- * @typedef {import('./types.js').Element} Element
59990
+ * @param {RulePseudo} query
59991
+ * @returns {(value: number) => boolean}
59948
59992
  */
59993
+ function getCachedNthCheck(query) {
59994
+ /** @type {(value: number) => boolean} */
59995
+ // @ts-expect-error: cache.
59996
+ let fn = query._cachedFn
59949
59997
 
59950
- /**
59951
- * @param {Rule} query
59952
- * @param {Element} element
59953
- * @returns {boolean}
59954
- */
59955
- function name_name(query, element) {
59956
- return query.tagName === '*' || query.tagName === element.tagName
59998
+ if (!fn) {
59999
+ // @ts-expect-error: always string.
60000
+ fn = pseudo_nthCheck(query.value)
60001
+ // @ts-expect-error: cache.
60002
+ query._cachedFn = fn
60003
+ }
60004
+
60005
+ return fn
59957
60006
  }
59958
60007
 
59959
60008
  ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/test.js
59960
60009
  /**
59961
60010
  * @typedef {import('./types.js').Rule} Rule
59962
- * @typedef {import('./types.js').HastNode} HastNode
59963
60011
  * @typedef {import('./types.js').Element} Element
59964
60012
  * @typedef {import('./types.js').Parent} Parent
59965
60013
  * @typedef {import('./types.js').SelectState} SelectState
59966
- * @typedef {import('hast-util-is-element').AssertPredicate<Element>} IsElement
59967
60014
  */
59968
60015
 
59969
60016
 
@@ -59972,609 +60019,468 @@ function name_name(query, element) {
59972
60019
 
59973
60020
 
59974
60021
 
59975
-
59976
60022
  /**
60023
+ * Test a rule.
60024
+ *
59977
60025
  * @param {Rule} query
59978
- * @param {HastNode} node
59979
- * @param {number|null} index
59980
- * @param {Parent|null} parent
60026
+ * @param {Element} element
60027
+ * @param {number | undefined} index
60028
+ * @param {Parent | undefined} parent
59981
60029
  * @param {SelectState} state
59982
60030
  * @returns {boolean}
59983
60031
  */
59984
- function test(query, node, index, parent, state) {
60032
+ function test(query, element, index, parent, state) {
59985
60033
  return Boolean(
59986
- util_element(node) &&
59987
- state.schema &&
59988
- (!query.tagName || name_name(query, node)) &&
59989
- (!query.classNames || className(query, node)) &&
59990
- (!query.id || id(query, node)) &&
59991
- (!query.attrs || attribute(query, node, state.schema)) &&
59992
- (!query.pseudos || pseudo(query, node, index, parent, state))
60034
+ (!query.tagName || name_name(query, element)) &&
60035
+ (!query.classNames || className(query, element)) &&
60036
+ (!query.id || id(query, element)) &&
60037
+ (!query.attrs || attribute(query, element, state.schema)) &&
60038
+ (!query.pseudos || pseudo(query, element, index, parent, state))
59993
60039
  )
59994
60040
  }
59995
60041
 
59996
- ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/any.js
60042
+ ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/walk.js
59997
60043
  /**
59998
- * @typedef {import('hast').Element} Element
59999
- * @typedef {import('./types.js').Selectors} Selectors
60000
- * @typedef {import('./types.js').Rule} Rule
60044
+ * @typedef {import('./types.js').Node} Node
60045
+ * @typedef {import('./types.js').Element} Element
60046
+ * @typedef {import('./types.js').Parent} Parent
60001
60047
  * @typedef {import('./types.js').RuleSet} RuleSet
60002
- * @typedef {import('./types.js').HastNode} HastNode
60003
- * @typedef {import('./types.js').SelectIterator} SelectIterator
60004
60048
  * @typedef {import('./types.js').SelectState} SelectState
60049
+ * @typedef {import('./types.js').Selectors} Selectors
60050
+ *
60051
+ * @typedef Nest
60052
+ * Rule sets by nesting.
60053
+ * @property {Array<RuleSet> | undefined} descendant
60054
+ * `a b`
60055
+ * @property {Array<RuleSet> | undefined} directChild
60056
+ * `a > b`
60057
+ * @property {Array<RuleSet> | undefined} adjacentSibling
60058
+ * `a + b`
60059
+ * @property {Array<RuleSet> | undefined} generalSibling
60060
+ * `a ~ b`
60061
+ *
60062
+ * @typedef Counts
60063
+ * Info on elements in a parent.
60064
+ * @property {number} count
60065
+ * Number of elements.
60066
+ * @property {Map<string, number>} types
60067
+ * Number of elements by tag name.
60005
60068
  */
60006
60069
 
60007
60070
 
60008
60071
 
60009
60072
 
60010
-
60011
-
60012
-
60013
-
60014
- const type = zwitch('type', {
60015
- // @ts-expect-error: hush.
60016
- unknown: unknownType,
60017
- invalid: invalidType,
60018
- // @ts-expect-error: hush.
60019
- handlers: {selectors, ruleSet, rule}
60020
- })
60073
+ /** @type {Array<never>} */
60074
+ const walk_empty = []
60021
60075
 
60022
60076
  /**
60023
- * @param {Selectors|RuleSet|Rule} query
60024
- * @param {HastNode|undefined} node
60025
- * @param {SelectState} state
60026
- * @returns {Array<Element>}
60027
- */
60028
- function any_any(query, node, state) {
60029
- // @ts-expect-error zwitch types are off.
60030
- return query && node ? type(query, node, state) : []
60031
- }
60032
-
60033
- /**
60034
- * @param {Selectors} query
60035
- * @param {HastNode} node
60036
- * @param {SelectState} state
60037
- * @returns {Array<Element>}
60077
+ * Turn a query into a uniform object.
60078
+ *
60079
+ * @param {Selectors | RuleSet | null} query
60080
+ * @returns {Selectors}
60038
60081
  */
60039
- function selectors(query, node, state) {
60040
- const collector = new Collector(state.one)
60041
- let index = -1
60082
+ function queryToSelectors(query) {
60083
+ if (query === null) {
60084
+ return {type: 'selectors', selectors: []}
60085
+ }
60042
60086
 
60043
- while (++index < query.selectors.length) {
60044
- collector.collectAll(ruleSet(query.selectors[index], node, state))
60087
+ if (query.type === 'ruleSet') {
60088
+ return {type: 'selectors', selectors: [query]}
60045
60089
  }
60046
60090
 
60047
- return collector.result
60091
+ return query
60048
60092
  }
60049
60093
 
60050
60094
  /**
60051
- * @param {RuleSet} query
60052
- * @param {HastNode} node
60095
+ * Walk a tree.
60096
+ *
60053
60097
  * @param {SelectState} state
60054
- * @returns {Array<Element>}
60098
+ * @param {Node | undefined} tree
60055
60099
  */
60056
- function ruleSet(query, node, state) {
60057
- return rule(query.rule, node, state)
60100
+ function walk_walk(state, tree) {
60101
+ if (tree) {
60102
+ walk_one(state, [], tree, undefined, undefined)
60103
+ }
60058
60104
  }
60059
60105
 
60060
60106
  /**
60061
- * @param {Rule} query
60062
- * @param {HastNode} tree
60107
+ * Check a node.
60108
+ *
60063
60109
  * @param {SelectState} state
60064
- * @returns {Array<Element>}
60110
+ * @param {Array<RuleSet>} currentRules
60111
+ * @param {Node} node
60112
+ * @param {number | undefined} index
60113
+ * @param {Parent | undefined} parent
60114
+ * @returns {Nest}
60065
60115
  */
60066
- function rule(query, tree, state) {
60067
- const collector = new Collector(state.one)
60068
-
60069
- if (state.shallow && query.rule) {
60070
- throw new Error('Expected selector without nesting')
60116
+ function walk_one(state, currentRules, node, index, parent) {
60117
+ /** @type {Nest} */
60118
+ let nestResult = {
60119
+ directChild: undefined,
60120
+ descendant: undefined,
60121
+ adjacentSibling: undefined,
60122
+ generalSibling: undefined
60071
60123
  }
60124
+ const exit = enterState(state, node)
60072
60125
 
60073
- nest(
60074
- query,
60075
- tree,
60076
- 0,
60077
- null,
60078
- configure(query, {
60079
- schema: state.space === 'svg' ? property_information_svg : property_information_html,
60080
- language: undefined,
60081
- direction: 'ltr',
60082
- editableOrEditingHost: false,
60083
- // @ts-expect-error assume elements.
60084
- scopeElements: tree.type === 'root' ? tree.children : [tree],
60085
- iterator,
60086
- one: state.one,
60087
- shallow: state.shallow
60088
- })
60089
- )
60090
-
60091
- return collector.result
60092
-
60093
- /** @type {SelectIterator} */
60094
- function iterator(query, node, index, parent, state) {
60095
- const exit = enterState(state, node)
60096
-
60097
- if (test(query, node, index, parent, state)) {
60098
- if (query.rule) {
60099
- nest(query.rule, node, index, parent, configure(query.rule, state))
60100
- } else {
60101
- // @ts-expect-error `test` also asserts `node is Element`
60102
- collector.collect(node)
60103
- state.found = true
60104
- }
60105
- }
60106
-
60107
- exit()
60126
+ if (node.type === 'element') {
60127
+ nestResult = applySelectors(
60128
+ state,
60129
+ // Try the root rules for this element too.
60130
+ combine(currentRules, state.rootQuery.selectors),
60131
+ node,
60132
+ index,
60133
+ parent
60134
+ )
60108
60135
  }
60109
60136
 
60110
- /**
60111
- * @template {SelectState} S
60112
- * @param {Rule} query
60113
- * @param {S} state
60114
- * @returns {S}
60115
- */
60116
- function configure(query, state) {
60117
- const pseudos = query.pseudos || []
60118
- let index = -1
60137
+ // If this is a parent, and we want to delve into them, and we haven’t found
60138
+ // our single result yet.
60139
+ if ('children' in node && !state.shallow && !(state.one && state.found)) {
60140
+ walk_all(state, nestResult, node)
60141
+ }
60119
60142
 
60120
- while (++index < pseudos.length) {
60121
- if (pseudo.needsIndex.includes(pseudos[index].name)) {
60122
- state.index = true
60123
- break
60124
- }
60125
- }
60143
+ exit()
60126
60144
 
60127
- return state
60128
- }
60145
+ return nestResult
60129
60146
  }
60130
60147
 
60131
- // Shouldn’t be called, all data is handled.
60132
- /* c8 ignore next 6 */
60133
60148
  /**
60134
- * @param {{[x: string]: unknown, type: string}} query
60149
+ * Check a node.
60150
+ *
60151
+ * @param {SelectState} state
60152
+ * @param {Nest} nest
60153
+ * @param {Parent} node
60154
+ * @returns {void}
60135
60155
  */
60136
- function unknownType(query) {
60137
- throw new Error('Unknown type `' + query.type + '`')
60138
- }
60139
-
60140
- // Shouldn’t be called, parser gives correct data.
60141
- /* c8 ignore next 3 */
60142
- function invalidType() {
60143
- throw new Error('Invalid type')
60144
- }
60145
-
60146
- class Collector {
60156
+ function walk_all(state, nest, node) {
60157
+ const fromParent = combine(nest.descendant, nest.directChild)
60158
+ /** @type {Array<RuleSet> | undefined} */
60159
+ let fromSibling
60160
+ let index = -1
60147
60161
  /**
60148
- * @param {boolean|undefined} [one]
60162
+ * Total counts.
60163
+ * @type {Counts}
60149
60164
  */
60150
- constructor(one) {
60151
- /** @type {Array<Element>} */
60152
- this.result = []
60153
- /** @type {boolean|undefined} */
60154
- this.one = one
60155
- /** @type {boolean} */
60156
- this.found = false
60157
- }
60158
-
60165
+ const total = {count: 0, types: new Map()}
60159
60166
  /**
60160
- * Append nodes to array, filtering out duplicates.
60161
- *
60162
- * @param {Array<Element>} elements
60167
+ * Counts of previous siblings.
60168
+ * @type {Counts}
60163
60169
  */
60164
- collectAll(elements) {
60165
- let index = -1
60170
+ const before = {count: 0, types: new Map()}
60166
60171
 
60167
- while (++index < elements.length) {
60168
- this.collect(elements[index])
60169
- }
60172
+ while (++index < node.children.length) {
60173
+ count(total, node.children[index])
60170
60174
  }
60171
60175
 
60172
- /**
60173
- * Append one node.
60174
- *
60175
- * @param {Element} element
60176
- */
60177
- collect(element) {
60178
- if (this.one) {
60179
- // Shouldn’t happen, safeguards performance problems.
60180
- /* c8 ignore next */
60181
- if (this.found) return
60182
- this.found = true
60176
+ index = -1
60177
+
60178
+ while (++index < node.children.length) {
60179
+ const child = node.children[index]
60180
+ // Uppercase to prevent prototype polution, injecting `constructor` or so.
60181
+ // Normalize because HTML is insensitive.
60182
+ const name =
60183
+ child.type === 'element' ? child.tagName.toUpperCase() : undefined
60184
+ // Before counting further elements:
60185
+ state.elementIndex = before.count
60186
+ state.typeIndex = name ? before.types.get(name) || 0 : 0
60187
+ // After counting all elements.
60188
+ state.elementCount = total.count
60189
+ state.typeCount = name ? total.types.get(name) : 0
60190
+
60191
+ // Only apply if this is a parent, this should be an element, but we check
60192
+ // for parents so that we delve into custom nodes too.
60193
+ if ('children' in child) {
60194
+ const forSibling = combine(fromParent, fromSibling)
60195
+ const nest = walk_one(state, forSibling, node.children[index], index, node)
60196
+ fromSibling = combine(nest.generalSibling, nest.adjacentSibling)
60197
+ }
60198
+
60199
+ // We found one thing, and one is enough.
60200
+ if (state.one && state.found) {
60201
+ break
60183
60202
  }
60184
60203
 
60185
- if (!this.result.includes(element)) this.result.push(element)
60204
+ count(before, node.children[index])
60186
60205
  }
60187
60206
  }
60188
60207
 
60189
- // EXTERNAL MODULE: ../node_modules/css-selector-parser/lib/index.js
60190
- var css_selector_parser_lib = __webpack_require__(510);
60191
- ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/parse.js
60192
- // Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
60193
- // Whitespace as per https://www.w3.org/TR/selectors-3/#lex is " \t\r\n\f"
60194
- const parse_whitespace = new Set([9, 10, 12, 13, 32]);
60195
- const ZERO = "0".charCodeAt(0);
60196
- const NINE = "9".charCodeAt(0);
60197
60208
  /**
60198
- * Parses an expression.
60209
+ * Apply selectors to an element.
60199
60210
  *
60200
- * @throws An `Error` if parsing fails.
60201
- * @returns An array containing the integer step size and the integer offset of the nth rule.
60202
- * @example nthCheck.parse("2n+3"); // returns [2, 3]
60203
- */
60204
- function esm_parse_parse(formula) {
60205
- formula = formula.trim().toLowerCase();
60206
- if (formula === "even") {
60207
- return [2, 0];
60208
- }
60209
- else if (formula === "odd") {
60210
- return [2, 1];
60211
- }
60212
- // Parse [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
60213
- let idx = 0;
60214
- let a = 0;
60215
- let sign = readSign();
60216
- let number = readNumber();
60217
- if (idx < formula.length && formula.charAt(idx) === "n") {
60218
- idx++;
60219
- a = sign * (number !== null && number !== void 0 ? number : 1);
60220
- skipWhitespace();
60221
- if (idx < formula.length) {
60222
- sign = readSign();
60223
- skipWhitespace();
60224
- number = readNumber();
60225
- }
60226
- else {
60227
- sign = number = 0;
60228
- }
60229
- }
60230
- // Throw if there is anything else
60231
- if (number === null || idx < formula.length) {
60232
- throw new Error(`n-th rule couldn't be parsed ('${formula}')`);
60211
+ * @param {SelectState} state
60212
+ * Current state.
60213
+ * @param {Array<RuleSet>} rules
60214
+ * Rules to apply.
60215
+ * @param {Element} node
60216
+ * Element to apply rules to.
60217
+ * @param {number | undefined} index
60218
+ * Index of node in parent.
60219
+ * @param {Parent | undefined} parent
60220
+ * Parent of node.
60221
+ * @returns {Nest}
60222
+ * Further rules.
60223
+ */
60224
+ function applySelectors(state, rules, node, index, parent) {
60225
+ /** @type {Nest} */
60226
+ const nestResult = {
60227
+ directChild: undefined,
60228
+ descendant: undefined,
60229
+ adjacentSibling: undefined,
60230
+ generalSibling: undefined
60231
+ }
60232
+ let selectorIndex = -1
60233
+
60234
+ while (++selectorIndex < rules.length) {
60235
+ const ruleSet = rules[selectorIndex]
60236
+
60237
+ // We found one thing, and one is enough.
60238
+ if (state.one && state.found) {
60239
+ break
60233
60240
  }
60234
- return [a, sign * number];
60235
- function readSign() {
60236
- if (formula.charAt(idx) === "-") {
60237
- idx++;
60238
- return -1;
60239
- }
60240
- if (formula.charAt(idx) === "+") {
60241
- idx++;
60241
+
60242
+ // When shallow, we don’t allow nested rules.
60243
+ // Idea: we could allow a stack of parents?
60244
+ // Might get quite complex though.
60245
+ if (state.shallow && ruleSet.rule.rule) {
60246
+ throw new Error('Expected selector without nesting')
60247
+ }
60248
+
60249
+ // If this rule matches:
60250
+ if (test(ruleSet.rule, node, index, parent, state)) {
60251
+ const nest = ruleSet.rule.rule
60252
+
60253
+ // Are there more?
60254
+ if (nest) {
60255
+ /** @type {RuleSet} */
60256
+ const rule = {type: 'ruleSet', rule: nest}
60257
+ /** @type {keyof Nest} */
60258
+ const label =
60259
+ nest.nestingOperator === '+'
60260
+ ? 'adjacentSibling'
60261
+ : nest.nestingOperator === '~'
60262
+ ? 'generalSibling'
60263
+ : nest.nestingOperator === '>'
60264
+ ? 'directChild'
60265
+ : 'descendant'
60266
+ add(nestResult, label, rule)
60267
+ } else {
60268
+ // We have a match!
60269
+ state.found = true
60270
+
60271
+ if (!state.results.includes(node)) {
60272
+ state.results.push(node)
60242
60273
  }
60243
- return 1;
60274
+ }
60244
60275
  }
60245
- function readNumber() {
60246
- const start = idx;
60247
- let value = 0;
60248
- while (idx < formula.length &&
60249
- formula.charCodeAt(idx) >= ZERO &&
60250
- formula.charCodeAt(idx) <= NINE) {
60251
- value = value * 10 + (formula.charCodeAt(idx) - ZERO);
60252
- idx++;
60253
- }
60254
- // Return `null` if we didn't read anything.
60255
- return idx === start ? null : value;
60276
+
60277
+ // Descendant.
60278
+ if (ruleSet.rule.nestingOperator === null) {
60279
+ add(nestResult, 'descendant', ruleSet)
60256
60280
  }
60257
- function skipWhitespace() {
60258
- while (idx < formula.length &&
60259
- parse_whitespace.has(formula.charCodeAt(idx))) {
60260
- idx++;
60261
- }
60281
+ // Adjacent.
60282
+ else if (ruleSet.rule.nestingOperator === '~') {
60283
+ add(nestResult, 'generalSibling', ruleSet)
60262
60284
  }
60263
- }
60264
- //# sourceMappingURL=parse.js.map
60265
- // EXTERNAL MODULE: ../node_modules/boolbase/index.js
60266
- var boolbase = __webpack_require__(286);
60267
- ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/compile.js
60285
+ // Drop top-level nesting (`undefined`), direct child (`>`), adjacent sibling (`+`).
60286
+ }
60268
60287
 
60269
- /**
60270
- * Returns a function that checks if an elements index matches the given rule
60271
- * highly optimized to return the fastest solution.
60272
- *
60273
- * @param parsed A tuple [a, b], as returned by `parse`.
60274
- * @returns A highly optimized function that returns whether an index matches the nth-check.
60275
- * @example
60276
- *
60277
- * ```js
60278
- * const check = nthCheck.compile([2, 3]);
60279
- *
60280
- * check(0); // `false`
60281
- * check(1); // `false`
60282
- * check(2); // `true`
60283
- * check(3); // `false`
60284
- * check(4); // `true`
60285
- * check(5); // `false`
60286
- * check(6); // `true`
60287
- * ```
60288
- */
60289
- function compile(parsed) {
60290
- const a = parsed[0];
60291
- // Subtract 1 from `b`, to convert from one- to zero-indexed.
60292
- const b = parsed[1] - 1;
60293
- /*
60294
- * When `b <= 0`, `a * n` won't be lead to any matches for `a < 0`.
60295
- * Besides, the specification states that no elements are
60296
- * matched when `a` and `b` are 0.
60297
- *
60298
- * `b < 0` here as we subtracted 1 from `b` above.
60299
- */
60300
- if (b < 0 && a <= 0)
60301
- return boolbase.falseFunc;
60302
- // When `a` is in the range -1..1, it matches any element (so only `b` is checked).
60303
- if (a === -1)
60304
- return (index) => index <= b;
60305
- if (a === 0)
60306
- return (index) => index === b;
60307
- // When `b <= 0` and `a === 1`, they match any element.
60308
- if (a === 1)
60309
- return b < 0 ? boolbase.trueFunc : (index) => index >= b;
60310
- /*
60311
- * Otherwise, modulo can be used to check if there is a match.
60312
- *
60313
- * Modulo doesn't care about the sign, so let's use `a`s absolute value.
60314
- */
60315
- const absA = Math.abs(a);
60316
- // Get `b mod a`, + a if this is negative.
60317
- const bMod = ((b % absA) + absA) % absA;
60318
- return a > 1
60319
- ? (index) => index >= b && index % absA === bMod
60320
- : (index) => index <= b && index % absA === bMod;
60288
+ return nestResult
60321
60289
  }
60290
+
60322
60291
  /**
60323
- * Returns a function that produces a monotonously increasing sequence of indices.
60324
- *
60325
- * If the sequence has an end, the returned function will return `null` after
60326
- * the last index in the sequence.
60292
+ * Combine two lists, if needed.
60327
60293
  *
60328
- * @param parsed A tuple [a, b], as returned by `parse`.
60329
- * @returns A function that produces a sequence of indices.
60330
- * @example <caption>Always increasing (2n+3)</caption>
60294
+ * This is optimized to create as few lists as possible.
60331
60295
  *
60332
- * ```js
60333
- * const gen = nthCheck.generate([2, 3])
60334
- *
60335
- * gen() // `1`
60336
- * gen() // `3`
60337
- * gen() // `5`
60338
- * gen() // `8`
60339
- * gen() // `11`
60340
- * ```
60341
- *
60342
- * @example <caption>With end value (-2n+10)</caption>
60343
- *
60344
- * ```js
60345
- *
60346
- * const gen = nthCheck.generate([-2, 5]);
60347
- *
60348
- * gen() // 0
60349
- * gen() // 2
60350
- * gen() // 4
60351
- * gen() // null
60352
- * ```
60296
+ * @param {Array<RuleSet> | undefined} left
60297
+ * @param {Array<RuleSet> | undefined} right
60298
+ * @returns {Array<RuleSet>}
60353
60299
  */
60354
- function compile_generate(parsed) {
60355
- const a = parsed[0];
60356
- // Subtract 1 from `b`, to convert from one- to zero-indexed.
60357
- let b = parsed[1] - 1;
60358
- let n = 0;
60359
- // Make sure to always return an increasing sequence
60360
- if (a < 0) {
60361
- const aPos = -a;
60362
- // Get `b mod a`
60363
- const minValue = ((b % aPos) + aPos) % aPos;
60364
- return () => {
60365
- const val = minValue + aPos * n++;
60366
- return val > b ? null : val;
60367
- };
60368
- }
60369
- if (a === 0)
60370
- return b < 0
60371
- ? // There are no result — always return `null`
60372
- () => null
60373
- : // Return `b` exactly once
60374
- () => (n++ === 0 ? b : null);
60375
- if (b < 0) {
60376
- b += a * Math.ceil(-b / a);
60377
- }
60378
- return () => a * n++ + b;
60300
+ function combine(left, right) {
60301
+ return left && right && left.length > 0 && right.length > 0
60302
+ ? [...left, ...right]
60303
+ : left && left.length > 0
60304
+ ? left
60305
+ : right && right.length > 0
60306
+ ? right
60307
+ : walk_empty
60379
60308
  }
60380
- //# sourceMappingURL=compile.js.map
60381
- ;// CONCATENATED MODULE: ../node_modules/nth-check/lib/esm/index.js
60382
-
60383
-
60384
60309
 
60385
60310
  /**
60386
- * Parses and compiles a formula to a highly optimized function.
60387
- * Combination of {@link parse} and {@link compile}.
60311
+ * Add a rule to a nesting map.
60388
60312
  *
60389
- * If the formula doesn't match any elements,
60390
- * it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
60391
- * Otherwise, a function accepting an _index_ is returned, which returns
60392
- * whether or not the passed _index_ matches the formula.
60393
- *
60394
- * Note: The nth-rule starts counting at `1`, the returned function at `0`.
60395
- *
60396
- * @param formula The formula to compile.
60397
- * @example
60398
- * const check = nthCheck("2n+3");
60399
- *
60400
- * check(0); // `false`
60401
- * check(1); // `false`
60402
- * check(2); // `true`
60403
- * check(3); // `false`
60404
- * check(4); // `true`
60405
- * check(5); // `false`
60406
- * check(6); // `true`
60313
+ * @param {Nest} nest
60314
+ * @param {keyof Nest} field
60315
+ * @param {RuleSet} rule
60407
60316
  */
60408
- function nthCheck(formula) {
60409
- return compile(esm_parse_parse(formula));
60317
+ function add(nest, field, rule) {
60318
+ const list = nest[field]
60319
+ if (list) {
60320
+ list.push(rule)
60321
+ } else {
60322
+ nest[field] = [rule]
60323
+ }
60410
60324
  }
60325
+
60411
60326
  /**
60412
- * Parses and compiles a formula to a generator that produces a sequence of indices.
60413
- * Combination of {@link parse} and {@link generate}.
60414
- *
60415
- * @param formula The formula to compile.
60416
- * @returns A function that produces a sequence of indices.
60417
- * @example <caption>Always increasing</caption>
60418
- *
60419
- * ```js
60420
- * const gen = nthCheck.sequence('2n+3')
60421
- *
60422
- * gen() // `1`
60423
- * gen() // `3`
60424
- * gen() // `5`
60425
- * gen() // `8`
60426
- * gen() // `11`
60427
- * ```
60327
+ * Count a node.
60428
60328
  *
60429
- * @example <caption>With end value</caption>
60430
- *
60431
- * ```js
60432
- *
60433
- * const gen = nthCheck.sequence('-2n+5');
60434
- *
60435
- * gen() // 0
60436
- * gen() // 2
60437
- * gen() // 4
60438
- * gen() // null
60439
- * ```
60329
+ * @param {Counts} counts
60330
+ * Counts.
60331
+ * @param {Node} node
60332
+ * Node (we’re looking for elements).
60333
+ * @returns {void}
60334
+ * Nothing.
60440
60335
  */
60441
- function sequence(formula) {
60442
- return generate(parse(formula));
60336
+ function count(counts, node) {
60337
+ if (node.type === 'element') {
60338
+ // Uppercase to prevent prototype polution, injecting `constructor` or so.
60339
+ // Normalize because HTML is insensitive.
60340
+ const name = node.tagName.toUpperCase()
60341
+ const count = (counts.types.get(name) || 0) + 1
60342
+ counts.count++
60343
+ counts.types.set(name, count)
60344
+ }
60443
60345
  }
60444
- //# sourceMappingURL=index.js.map
60346
+
60347
+ // EXTERNAL MODULE: ../node_modules/css-selector-parser/lib/index.js
60348
+ var css_selector_parser_lib = __webpack_require__(510);
60445
60349
  ;// CONCATENATED MODULE: ../node_modules/hast-util-select/lib/parse.js
60446
60350
  /**
60447
- * @typedef {import('./types.js').Selector} Selector
60448
60351
  * @typedef {import('./types.js').Selectors} Selectors
60449
60352
  * @typedef {import('./types.js').RuleSet} RuleSet
60450
- * @typedef {import('./types.js').Rule} Rule
60451
- * @typedef {import('./types.js').RulePseudo} RulePseudo
60452
- * @typedef {import('./types.js').RulePseudoNth} RulePseudoNth
60453
60353
  */
60454
60354
 
60455
60355
 
60456
60356
 
60457
-
60458
-
60459
- /** @type {import('nth-check').default} */
60460
- // @ts-expect-error
60461
- const parse_nthCheck = nthCheck["default"] || nthCheck
60462
-
60463
- const nth = new Set([
60464
- 'nth-child',
60465
- 'nth-last-child',
60466
- 'nth-of-type',
60467
- 'nth-last-of-type'
60468
- ])
60469
-
60470
60357
  const parse_parser = new css_selector_parser_lib/* CssSelectorParser */.N()
60471
60358
 
60472
- // @ts-expect-error: hush.
60473
- const parse_compile = zwitch('type', {handlers: {selectors: parse_selectors, ruleSet: parse_ruleSet, rule: parse_rule}})
60474
-
60475
60359
  parse_parser.registerAttrEqualityMods('~', '|', '^', '$', '*')
60476
60360
  parse_parser.registerSelectorPseudos('any', 'matches', 'not', 'has')
60477
60361
  parse_parser.registerNestingOperators('>', '+', '~')
60478
60362
 
60479
60363
  /**
60480
60364
  * @param {string} selector
60481
- * @returns {Selector}
60365
+ * @returns {Selectors | RuleSet | null}
60482
60366
  */
60483
60367
  function lib_parse_parse(selector) {
60484
60368
  if (typeof selector !== 'string') {
60485
60369
  throw new TypeError('Expected `string` as selector, not `' + selector + '`')
60486
60370
  }
60487
60371
 
60488
- // @ts-expect-error types are wrong.
60489
- return parse_compile(parse_parser.parse(selector))
60490
- }
60491
-
60492
- /**
60493
- * @param {Selectors} query
60494
- * @returns {Selectors}
60495
- */
60496
- function parse_selectors(query) {
60497
- let index = -1
60498
-
60499
- while (++index < query.selectors.length) {
60500
- parse_compile(query.selectors[index])
60501
- }
60502
-
60503
- return query
60504
- }
60505
-
60506
- /**
60507
- * @param {RuleSet} query
60508
- * @returns {Rule}
60509
- */
60510
- function parse_ruleSet(query) {
60511
- return parse_rule(query.rule)
60512
- }
60513
-
60514
- /**
60515
- * @param {Rule} query
60516
- * @returns {Rule}
60517
- */
60518
- function parse_rule(query) {
60519
- const pseudos = query.pseudos || []
60520
- let index = -1
60521
-
60522
- while (++index < pseudos.length) {
60523
- const pseudo = pseudos[index]
60524
-
60525
- if (nth.has(pseudo.name)) {
60526
- // @ts-expect-error Patch a non-primitive type.
60527
- pseudo.value = parse_nthCheck(pseudo.value)
60528
- // @ts-expect-error Patch a non-primitive type.
60529
- pseudo.valueType = 'function'
60530
- }
60531
- }
60532
-
60533
- parse_compile(query.rule)
60534
-
60535
- return query
60372
+ return parse_parser.parse(selector)
60536
60373
  }
60537
60374
 
60538
60375
  ;// CONCATENATED MODULE: ../node_modules/hast-util-select/index.js
60539
60376
  /**
60540
60377
  * @typedef {import('./lib/types.js').Element} Element
60541
- * @typedef {import('./lib/types.js').HastNode} HastNode
60378
+ * @typedef {import('./lib/types.js').Node} Node
60542
60379
  * @typedef {import('./lib/types.js').Space} Space
60380
+ * @typedef {import('./lib/types.js').SelectState} SelectState
60543
60381
  */
60544
60382
 
60545
60383
 
60546
60384
 
60547
60385
 
60386
+
60548
60387
  /**
60388
+ * Check that the given `node` matches `selector`.
60389
+ *
60390
+ * This only checks the element itself, not the surrounding tree.
60391
+ * Thus, nesting in selectors is not supported (`p b`, `p > b`), neither are
60392
+ * selectors like `:first-child`, etc.
60393
+ * This only checks that the given element matches the selector.
60394
+ *
60549
60395
  * @param {string} selector
60550
- * @param {HastNode} [node]
60551
- * @param {Space} [space]
60396
+ * CSS selector, such as (`h1`, `a, b`).
60397
+ * @param {Node | null | undefined} [node]
60398
+ * Node that might match `selector`, should be an element.
60399
+ * @param {Space | null | undefined} [space='html']
60400
+ * Name of namespace (`'svg'` or `'html'`).
60552
60401
  * @returns {boolean}
60402
+ * Whether `node` matches `selector`.
60553
60403
  */
60554
60404
  function hast_util_select_matches(selector, node, space) {
60555
- return Boolean(
60556
- any(parse(selector), node, {space, one: true, shallow: true})[0]
60557
- )
60405
+ const state = createState(selector, node, space)
60406
+ state.one = true
60407
+ state.shallow = true
60408
+ walk(state, node || undefined)
60409
+ return state.results.length > 0
60558
60410
  }
60559
60411
 
60560
60412
  /**
60413
+ * Select the first element that matches `selector` in the given `tree`.
60414
+ * Searches the tree in *preorder*.
60415
+ *
60561
60416
  * @param {string} selector
60562
- * @param {HastNode} [node]
60563
- * @param {Space} [space]
60564
- * @returns {Element|null}
60565
- */
60566
- function hast_util_select_select(selector, node, space) {
60567
- return any(parse(selector), node, {space, one: true})[0] || null
60417
+ * CSS selector, such as (`h1`, `a, b`).
60418
+ * @param {Node | null | undefined} [tree]
60419
+ * Tree to search.
60420
+ * @param {Space | null | undefined} [space='html']
60421
+ * Name of namespace (`'svg'` or `'html'`).
60422
+ * @returns {Element | null}
60423
+ * First element in `tree` that matches `selector` or `null` if nothing is
60424
+ * found.
60425
+ * This could be `tree` itself.
60426
+ */
60427
+ function hast_util_select_select(selector, tree, space) {
60428
+ const state = createState(selector, tree, space)
60429
+ state.one = true
60430
+ walk(state, tree || undefined)
60431
+ // To do in major: return `undefined` instead.
60432
+ return state.results[0] || null
60568
60433
  }
60569
60434
 
60570
60435
  /**
60436
+ * Select all elements that match `selector` in the given `tree`.
60437
+ * Searches the tree in *preorder*.
60438
+ *
60571
60439
  * @param {string} selector
60572
- * @param {HastNode} [node]
60573
- * @param {Space} [space]
60440
+ * CSS selector, such as (`h1`, `a, b`).
60441
+ * @param {Node | null | undefined} [tree]
60442
+ * Tree to search.
60443
+ * @param {Space | null | undefined} [space='html']
60444
+ * Name of namespace (`'svg'` or `'html'`).
60574
60445
  * @returns {Array<Element>}
60446
+ * Elements in `tree` that match `selector`.
60447
+ * This could include `tree` itself.
60575
60448
  */
60576
- function selectAll(selector, node, space) {
60577
- return any_any(lib_parse_parse(selector), node, {space})
60449
+ function selectAll(selector, tree, space) {
60450
+ const state = createState(selector, tree, space)
60451
+ walk_walk(state, tree || undefined)
60452
+ return state.results
60453
+ }
60454
+
60455
+ /**
60456
+ * @param {string} selector
60457
+ * Tree to search.
60458
+ * @param {Node | null | undefined} [tree]
60459
+ * Tree to search.
60460
+ * @param {Space | null | undefined} [space='html']
60461
+ * Name of namespace (`'svg'` or `'html'`).
60462
+ * @returns {SelectState} SelectState
60463
+ */
60464
+ function createState(selector, tree, space) {
60465
+ return {
60466
+ // State of the query.
60467
+ rootQuery: queryToSelectors(lib_parse_parse(selector)),
60468
+ results: [],
60469
+ // @ts-expect-error assume elements.
60470
+ scopeElements: tree ? (tree.type === 'root' ? tree.children : [tree]) : [],
60471
+ one: false,
60472
+ shallow: false,
60473
+ found: false,
60474
+ // State in the tree.
60475
+ schema: space === 'svg' ? property_information_svg : property_information_html,
60476
+ language: undefined,
60477
+ direction: 'ltr',
60478
+ editableOrEditingHost: false,
60479
+ typeIndex: undefined,
60480
+ elementIndex: undefined,
60481
+ typeCount: undefined,
60482
+ elementCount: undefined
60483
+ }
60578
60484
  }
60579
60485
 
60580
60486
  ;// CONCATENATED MODULE: ../node_modules/rehype-rewrite/lib/index.js