@react-x11/components 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/code/index.d.ts.map +1 -1
  2. package/dist/code/index.js +25 -24
  3. package/dist/code/index.js.map +1 -1
  4. package/dist/code-language/index.d.ts +1 -1
  5. package/dist/code-language/index.d.ts.map +1 -1
  6. package/dist/code-language/index.js +1 -1
  7. package/dist/code-language/index.js.map +1 -1
  8. package/dist/code-language/runs.d.ts +31 -0
  9. package/dist/code-language/runs.d.ts.map +1 -1
  10. package/dist/code-language/runs.js +105 -0
  11. package/dist/code-language/runs.js.map +1 -1
  12. package/dist/codeblock/index.d.ts +13 -0
  13. package/dist/codeblock/index.d.ts.map +1 -1
  14. package/dist/codeblock/index.js +37 -1
  15. package/dist/codeblock/index.js.map +1 -1
  16. package/dist/flow/node.d.ts +14 -6
  17. package/dist/flow/node.d.ts.map +1 -1
  18. package/dist/flow/node.js +82 -64
  19. package/dist/flow/node.js.map +1 -1
  20. package/dist/html/controls.d.ts +26 -7
  21. package/dist/html/controls.d.ts.map +1 -1
  22. package/dist/html/controls.js +28 -3
  23. package/dist/html/controls.js.map +1 -1
  24. package/dist/html/css/cascade.d.ts +32 -10
  25. package/dist/html/css/cascade.d.ts.map +1 -1
  26. package/dist/html/css/cascade.js +89 -31
  27. package/dist/html/css/cascade.js.map +1 -1
  28. package/dist/html/css/color.d.ts +19 -0
  29. package/dist/html/css/color.d.ts.map +1 -1
  30. package/dist/html/css/color.js +86 -0
  31. package/dist/html/css/color.js.map +1 -1
  32. package/dist/html/css/parse.d.ts +11 -0
  33. package/dist/html/css/parse.d.ts.map +1 -1
  34. package/dist/html/css/parse.js +114 -4
  35. package/dist/html/css/parse.js.map +1 -1
  36. package/dist/html/css/style.d.ts +45 -5
  37. package/dist/html/css/style.d.ts.map +1 -1
  38. package/dist/html/css/style.js +363 -14
  39. package/dist/html/css/style.js.map +1 -1
  40. package/dist/html/css/ua.js +22 -5
  41. package/dist/html/css/ua.js.map +1 -1
  42. package/dist/html/css/values.d.ts +10 -1
  43. package/dist/html/css/values.d.ts.map +1 -1
  44. package/dist/html/css/values.js +27 -2
  45. package/dist/html/css/values.js.map +1 -1
  46. package/dist/html/css/vars.d.ts +5 -0
  47. package/dist/html/css/vars.d.ts.map +1 -1
  48. package/dist/html/css/vars.js +2 -2
  49. package/dist/html/css/vars.js.map +1 -1
  50. package/dist/html/dom.d.ts.map +1 -1
  51. package/dist/html/dom.js +35 -2
  52. package/dist/html/dom.js.map +1 -1
  53. package/dist/html/index.d.ts.map +1 -1
  54. package/dist/html/index.js +38 -1
  55. package/dist/html/index.js.map +1 -1
  56. package/dist/html/layout/block.d.ts +11 -2
  57. package/dist/html/layout/block.d.ts.map +1 -1
  58. package/dist/html/layout/block.js +306 -25
  59. package/dist/html/layout/block.js.map +1 -1
  60. package/dist/html/layout/boxes.d.ts +61 -6
  61. package/dist/html/layout/boxes.d.ts.map +1 -1
  62. package/dist/html/layout/boxes.js +65 -16
  63. package/dist/html/layout/boxes.js.map +1 -1
  64. package/dist/html/layout/cache.d.ts +2 -2
  65. package/dist/html/layout/cache.d.ts.map +1 -1
  66. package/dist/html/layout/cache.js +8 -3
  67. package/dist/html/layout/cache.js.map +1 -1
  68. package/dist/html/layout/floats.d.ts +4 -0
  69. package/dist/html/layout/floats.d.ts.map +1 -1
  70. package/dist/html/layout/floats.js +26 -0
  71. package/dist/html/layout/floats.js.map +1 -1
  72. package/dist/html/layout/inline.d.ts +29 -2
  73. package/dist/html/layout/inline.d.ts.map +1 -1
  74. package/dist/html/layout/inline.js +1454 -125
  75. package/dist/html/layout/inline.js.map +1 -1
  76. package/dist/html/node.d.ts +33 -0
  77. package/dist/html/node.d.ts.map +1 -1
  78. package/dist/html/node.js +608 -86
  79. package/dist/html/node.js.map +1 -1
  80. package/dist/html/paint.d.ts +53 -1
  81. package/dist/html/paint.d.ts.map +1 -1
  82. package/dist/html/paint.js +746 -214
  83. package/dist/html/paint.js.map +1 -1
  84. package/dist/html/surfaces.d.ts +7 -2
  85. package/dist/html/surfaces.d.ts.map +1 -1
  86. package/dist/html/surfaces.js +16 -0
  87. package/dist/html/surfaces.js.map +1 -1
  88. package/dist/html/svg.d.ts.map +1 -1
  89. package/dist/html/svg.js +27 -20
  90. package/dist/html/svg.js.map +1 -1
  91. package/dist/internal/codelines.d.ts +42 -0
  92. package/dist/internal/codelines.d.ts.map +1 -0
  93. package/dist/internal/codelines.js +170 -0
  94. package/dist/internal/codelines.js.map +1 -0
  95. package/dist/internal/window.d.ts +22 -0
  96. package/dist/internal/window.d.ts.map +1 -1
  97. package/dist/internal/window.js +35 -8
  98. package/dist/internal/window.js.map +1 -1
  99. package/dist/markdown/index.d.ts.map +1 -1
  100. package/dist/markdown/index.js +98 -26
  101. package/dist/markdown/index.js.map +1 -1
  102. package/dist/rich-text-editor/index.d.ts.map +1 -1
  103. package/dist/rich-text-editor/index.js +3 -8
  104. package/dist/rich-text-editor/index.js.map +1 -1
  105. package/dist/rich-text-editor/markdown.d.ts.map +1 -1
  106. package/dist/rich-text-editor/markdown.js +30 -1
  107. package/dist/rich-text-editor/markdown.js.map +1 -1
  108. package/dist/rich-text-editor/replace.d.ts +13 -0
  109. package/dist/rich-text-editor/replace.d.ts.map +1 -0
  110. package/dist/rich-text-editor/replace.js +64 -0
  111. package/dist/rich-text-editor/replace.js.map +1 -0
  112. package/dist/richtext/node.d.ts +7 -0
  113. package/dist/richtext/node.d.ts.map +1 -1
  114. package/dist/richtext/node.js.map +1 -1
  115. package/dist/terminal-output/index.d.ts.map +1 -1
  116. package/dist/terminal-output/index.js +100 -25
  117. package/dist/terminal-output/index.js.map +1 -1
  118. package/dist/terminal-output/runs.d.ts +4 -1
  119. package/dist/terminal-output/runs.d.ts.map +1 -1
  120. package/dist/terminal-output/runs.js +5 -1
  121. package/dist/terminal-output/runs.js.map +1 -1
  122. package/package.json +5 -3
  123. package/src/code/index.ts +34 -32
  124. package/src/code-language/index.ts +1 -1
  125. package/src/code-language/runs.ts +111 -1
  126. package/src/codeblock/index.ts +48 -1
  127. package/src/flow/node.ts +80 -64
  128. package/src/html/controls.ts +50 -9
  129. package/src/html/css/cascade.ts +134 -43
  130. package/src/html/css/color.ts +87 -0
  131. package/src/html/css/parse.ts +107 -4
  132. package/src/html/css/style.ts +386 -23
  133. package/src/html/css/ua.ts +22 -5
  134. package/src/html/css/values.ts +31 -3
  135. package/src/html/css/vars.ts +2 -2
  136. package/src/html/dom.ts +38 -2
  137. package/src/html/index.ts +39 -1
  138. package/src/html/layout/block.ts +360 -22
  139. package/src/html/layout/boxes.ts +98 -23
  140. package/src/html/layout/cache.ts +8 -3
  141. package/src/html/layout/floats.ts +24 -0
  142. package/src/html/layout/inline.ts +1690 -119
  143. package/src/html/node.ts +648 -101
  144. package/src/html/paint.ts +883 -283
  145. package/src/html/surfaces.ts +21 -1
  146. package/src/html/svg.ts +30 -19
  147. package/src/internal/codelines.ts +200 -0
  148. package/src/internal/window.ts +36 -8
  149. package/src/markdown/index.ts +145 -26
  150. package/src/rich-text-editor/index.ts +3 -11
  151. package/src/rich-text-editor/markdown.ts +36 -1
  152. package/src/rich-text-editor/replace.ts +85 -0
  153. package/src/richtext/node.ts +7 -0
  154. package/src/terminal-output/index.ts +127 -34
  155. package/src/terminal-output/runs.ts +16 -2
@@ -102,7 +102,7 @@ export interface UnitContext {
102
102
  em: number;
103
103
  /** The root element's `font-size`. */
104
104
  rem: number;
105
- /** Viewport, for `vw`/`vh`/`vmin`/`vmax`. */
105
+ /** Viewport, for `vw`/`vh`/`vmin`/`vmax` and their kin (`viewportUnit`). */
106
106
  vw: number;
107
107
  vh: number;
108
108
  /** Device pixels per CSS pixel — the display scale. */
@@ -131,9 +131,37 @@ export interface UnitContext {
131
131
  const NUMBER_SRC = '[+-]?(?:\\d*\\.\\d+|\\d+)(?:e[+-]?\\d+)?';
132
132
 
133
133
  const LENGTH_RE = new RegExp(
134
- `^(${NUMBER_SRC})(px|em|rem|pt|pc|in|cm|mm|ex|ch|lh|rlh|vw|vh|vmin|vmax|q|%)?$`,
134
+ `^(${NUMBER_SRC})(px|em|rem|pt|pc|in|cm|mm|ex|ch|lh|rlh|[sld]?v(?:w|h|i|b|min|max)|q|%)?$`,
135
135
  );
136
136
 
137
+ /**
138
+ * The viewport unit a viewport-percentage length is (CSS Values 4, 6.1.2),
139
+ * or null for another unit. The small, large and dynamic viewports —
140
+ * `svh`, `lvh`, `dvh` and their kin — are the one viewport here, as they
141
+ * are on a desktop, where no toolbar comes and goes over the page; and the
142
+ * inline and block axes, `vi` and `vb`, are the width and the height of
143
+ * the horizontal writing mode every document here is laid out in.
144
+ */
145
+ export function viewportUnit(
146
+ unit: string,
147
+ ): 'vw' | 'vh' | 'vmin' | 'vmax' | null {
148
+ const u = unit.toLowerCase();
149
+ const bare = /^[sld]v/.test(u) ? u.slice(1) : u;
150
+ switch (bare) {
151
+ case 'vw':
152
+ case 'vi':
153
+ return 'vw';
154
+ case 'vh':
155
+ case 'vb':
156
+ return 'vh';
157
+ case 'vmin':
158
+ case 'vmax':
159
+ return bare;
160
+ default:
161
+ return null;
162
+ }
163
+ }
164
+
137
165
  const NUMBER_RE = new RegExp(`^${NUMBER_SRC}$`, 'i');
138
166
 
139
167
  /** A math function: `calc()`, `min()`, `max()` or `clamp()`. */
@@ -166,7 +194,7 @@ export function parseLength(
166
194
  });
167
195
  }
168
196
  const n = Number(m[1]);
169
- const unit = m[2];
197
+ const unit = m[2] && (viewportUnit(m[2]) ?? m[2]);
170
198
  // a zero needs no unit however it is written — `-0`, `+0`, `0.0`
171
199
  if (!unit) return n === 0 ? 0 : bareIsPx ? n * ctx.scale : null;
172
200
  if (unit === '%') return { pct: n };
@@ -245,7 +245,7 @@ function findVar(value: string, from: number): number {
245
245
 
246
246
  /** The `)` that closes a bracket opened just before `from`, strings and
247
247
  * brackets inside it passed over; -1 where none does. */
248
- function closingParen(value: string, from: number): number {
248
+ export function closingParen(value: string, from: number): number {
249
249
  let depth = 0;
250
250
  for (let i = from; i < value.length; i += 1) {
251
251
  const c = value[i];
@@ -326,7 +326,7 @@ function topLevel(value: string, ch: string): number {
326
326
  }
327
327
 
328
328
  /** The first comma not inside a bracket or a string, or -1. */
329
- function topLevelComma(value: string): number {
329
+ export function topLevelComma(value: string): number {
330
330
  let depth = 0;
331
331
  for (let i = 0; i < value.length; i += 1) {
332
332
  const c = value[i];
package/src/html/dom.ts CHANGED
@@ -572,15 +572,51 @@ function createParser(): { parser: Parser; handler: DomHandler } {
572
572
  withStartIndices: false,
573
573
  withEndIndices: false,
574
574
  });
575
- const parser = new Parser(handler, {
575
+ const parser = new DocumentParser(handler, {
576
576
  lowerCaseTags: true,
577
577
  lowerCaseAttributeNames: true,
578
- recognizeSelfClosing: true,
578
+ // HTML closes an element written `<x/>` only where it is void, and so
579
+ // closed anyway, or in SVG or MathML (HTML 13.2.6.5, "acknowledge the
580
+ // self-closing flag"). A `<div/>` or an `<a href="" /*target="_blank"*/>`
581
+ // — melbcss.com's, a comment that is no comment in a tag — opens an
582
+ // element like any other, and closing it left the link's text outside
583
+ // the link.
584
+ recognizeSelfClosing: false,
579
585
  decodeEntities: true,
580
586
  });
581
587
  return { parser, handler };
582
588
  }
583
589
 
590
+ /**
591
+ * htmlparser2's parser, deciding a `/>` from the context its tag was read
592
+ * in, as HTML's does. htmlparser2 decides from the context the tag opens,
593
+ * and an integration point — SVG's `<title>`, `<desc>` and
594
+ * `<foreignObject>`, MathML's `<mi>` and its kin — opens an HTML one, so
595
+ * an `<svg><title/><path/>` took its path into the title.
596
+ */
597
+ class DocumentParser extends Parser {
598
+ private _foreignTag = false;
599
+ private _acknowledging = false;
600
+
601
+ override isInForeignContext(): boolean {
602
+ return this._acknowledging || super.isInForeignContext();
603
+ }
604
+
605
+ override onopentagname(start: number, endIndex: number): void {
606
+ this._foreignTag = this.isInForeignContext();
607
+ super.onopentagname(start, endIndex);
608
+ }
609
+
610
+ override onselfclosingtag(endIndex: number): void {
611
+ this._acknowledging = this._foreignTag;
612
+ try {
613
+ super.onselfclosingtag(endIndex);
614
+ } finally {
615
+ this._acknowledging = false;
616
+ }
617
+ }
618
+ }
619
+
584
620
  /**
585
621
  * Whether a `media` attribute is one a screen honours. Deliberately not a
586
622
  * media-query engine: `screen`, `all` and an empty list apply, `print` and
package/src/html/index.ts CHANGED
@@ -505,6 +505,9 @@ function renderControl(
505
505
  top: Math.round(at.y),
506
506
  width: Math.round(at.width),
507
507
  height: Math.round(at.height),
508
+ // core's `opacity` is CSS's: the widget faded as a group, and at 0 not
509
+ // drawn and still hit
510
+ ...(rect.opacity !== undefined && { opacity: rect.opacity }),
508
511
  };
509
512
  const field = rect.bare ? bareField(rect.bare) : fieldChrome(look);
510
513
  const report = (value: string | boolean): void => {
@@ -528,6 +531,9 @@ function renderControl(
528
531
  widget = h(Checkbox, {
529
532
  checked: attr(el, 'checked') !== undefined,
530
533
  disabled,
534
+ // the element's whole box takes the press, as it does in a browser:
535
+ // a page that sizes one over its label, invisible, means the label
536
+ style: { width: '100%', height: '100%' },
531
537
  onChange: (ev) => {
532
538
  const next = ev.value;
533
539
  if (next) el.attribs.checked = '';
@@ -570,7 +576,21 @@ function renderControl(
570
576
  options: options.map((o) => ({ value: o.value, label: o.label })),
571
577
  value: selectedOption(el) ?? undefined,
572
578
  disabled,
573
- style: { width: '100%', height: '100%' },
579
+ style: rect.bare
580
+ ? [BARE_TRIGGER, { width: '100%', height: '100%' }]
581
+ : { width: '100%', height: '100%' },
582
+ // the slots choose the drawn trigger on every backend, and put the
583
+ // caption and the arrow in the page's ink
584
+ ...(rect.bare && {
585
+ labelStyle: {
586
+ color: rect.bare.color,
587
+ fontFamily: rect.bare.fontFamily,
588
+ fontSize: rect.bare.fontSize,
589
+ },
590
+ chevronStyle: rect.bare.chevron
591
+ ? { color: rect.bare.color }
592
+ : { display: 'none' },
593
+ }),
574
594
  onChange: (ev) => {
575
595
  const next = String(ev.value ?? '');
576
596
  setSelectedOption(el, next);
@@ -655,6 +675,24 @@ function bareField(bare: BareField): Style {
655
675
  };
656
676
  }
657
677
 
678
+ /**
679
+ * The trigger of a `<select>` whose box the page styled: no frame, no fill
680
+ * and none of its own insets, and no wash under the pointer, since the box
681
+ * it would tint is the document's. Core's focus ring still marks it for the
682
+ * keyboard.
683
+ */
684
+ const BARE_TRIGGER: Style = {
685
+ paddingTop: 0,
686
+ paddingBottom: 0,
687
+ paddingLeft: 0,
688
+ paddingRight: 0,
689
+ borderWidth: 0,
690
+ borderRadius: 0,
691
+ backgroundColor: 'transparent',
692
+ ':hover': { backgroundColor: 'transparent' },
693
+ ':active': { backgroundColor: 'transparent' },
694
+ };
695
+
658
696
  function clearRadioGroup(el: Element): void {
659
697
  const name = attr(el, 'name');
660
698
  if (!name) return;