buninu-browser 0.2.3 → 0.3.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 (116) hide show
  1. package/README.md +86 -1
  2. package/lib/cdp-server.js +47 -14
  3. package/lib/clipboard.js +22 -0
  4. package/lib/happy-dom/document-base.js +33 -0
  5. package/lib/happy-dom/parser.js +15 -6
  6. package/lib/happy-dom/selector-matcher.js +2 -2
  7. package/lib/happy-dom/selector-pseudo-adapter.js +19 -0
  8. package/lib/happy-dom/svg-attribute-adapter.js +50 -0
  9. package/lib/headless-shell.js +40 -11
  10. package/lib/input/hit-test.js +67 -19
  11. package/lib/layout/text-layout.js +213 -91
  12. package/lib/media/byte-pipe.js +2 -2
  13. package/lib/media/position-audio.js +10 -1
  14. package/lib/media/source-snapshots.js +126 -0
  15. package/lib/media/video-keyframe.js +17 -4
  16. package/lib/media/webm-stream.js +106 -0
  17. package/lib/network/network-service.js +268 -120
  18. package/lib/paint/display-list.js +8 -28
  19. package/lib/paint/frame-cache.js +25 -0
  20. package/lib/paint/frame.js +77 -16
  21. package/lib/paint/paragraph-text.js +24 -0
  22. package/lib/paint/raster-readback.js +41 -0
  23. package/lib/paint/raw-frames.js +47 -0
  24. package/lib/paint/rounded-rect.js +82 -0
  25. package/lib/paint/shared-frame-pool.js +105 -0
  26. package/lib/render-tree/index.js +38 -6
  27. package/lib/render-tree/svg.js +15 -7
  28. package/lib/renderer/bindings.js +233 -80
  29. package/lib/renderer/broadcast-channel.js +76 -0
  30. package/lib/renderer/canvas-2d.js +257 -14
  31. package/lib/renderer/canvas-text.js +120 -0
  32. package/lib/renderer/compositor-channel.js +103 -0
  33. package/lib/renderer/compositor.js +34 -40
  34. package/lib/renderer/custom-element-reactions.js +25 -1
  35. package/lib/renderer/flags.js +1 -1
  36. package/lib/renderer/font-loading.js +227 -0
  37. package/lib/renderer/host.js +133 -98
  38. package/lib/renderer/image-resources.js +65 -0
  39. package/lib/renderer/interfaces.js +28 -0
  40. package/lib/renderer/layout-observers.js +236 -0
  41. package/lib/renderer/main.js +52 -5
  42. package/lib/renderer/media-source.js +126 -55
  43. package/lib/renderer/page-realm.js +287 -99
  44. package/lib/renderer/page-renderer.js +663 -239
  45. package/lib/renderer/prepared-script-cache.js +50 -0
  46. package/lib/renderer/rendered-text.js +108 -0
  47. package/lib/renderer/rewrite-worker.js +4 -3
  48. package/lib/renderer/script-rewrite.js +13 -2
  49. package/lib/renderer/scroll-into-view.js +28 -0
  50. package/lib/renderer/slot-assignment.js +60 -0
  51. package/lib/renderer/video-presentation.js +23 -4
  52. package/lib/renderer/workers.js +2 -2
  53. package/lib/style/computed-style.js +611 -104
  54. package/lib/style/selector-traits.js +49 -5
  55. package/package.json +1 -1
  56. package/test/broadcast-channel.test.js +26 -0
  57. package/test/canvas-2d.test.js +83 -2
  58. package/test/canvas-paint.test.js +9 -0
  59. package/test/canvas-text.test.js +41 -0
  60. package/test/cdp-stream.test.js +56 -0
  61. package/test/clipboard.test.js +35 -0
  62. package/test/computed-style-binding.test.js +151 -0
  63. package/test/computed-style.test.js +258 -1
  64. package/test/display-list.test.js +12 -0
  65. package/test/document-base.test.js +87 -0
  66. package/test/dom-platform.test.js +461 -0
  67. package/test/fetch-lifecycle.test.js +161 -0
  68. package/test/fixtures/browser-raw-demo.html +36 -0
  69. package/test/fixtures/canvas-paint.js +117 -0
  70. package/test/fixtures/canvas-text.js +42 -0
  71. package/test/fixtures/image-lifetime.js +90 -0
  72. package/test/fixtures/media-seek-snapshot.js +77 -0
  73. package/test/fixtures/mse-audio-chirp.webm +0 -0
  74. package/test/fixtures/mse-switch-large.mp4 +0 -0
  75. package/test/fixtures/mse-switch-small.mp4 +0 -0
  76. package/test/fixtures/raw-capture-benchmark.json +76 -0
  77. package/test/fixtures/renderer-memory.js +110 -0
  78. package/test/fixtures/summary-style.js +28 -0
  79. package/test/font-loading.test.js +97 -0
  80. package/test/grid.test.js +58 -0
  81. package/test/hit-test.test.js +21 -1
  82. package/test/image-lifetime.test.js +12 -0
  83. package/test/image-resources.test.js +94 -0
  84. package/test/local-media.test.js +84 -0
  85. package/test/media-seek-snapshot.test.js +11 -0
  86. package/test/media-source-config.test.js +98 -0
  87. package/test/media-source-webm-accounting.test.js +98 -0
  88. package/test/media-source-webm.test.js +108 -0
  89. package/test/navigation.test.js +1 -0
  90. package/test/network-service.test.js +388 -0
  91. package/test/page-scripts.test.js +1 -1
  92. package/test/paint-frame.test.js +103 -0
  93. package/test/paint-paragraph-cache.test.js +87 -0
  94. package/test/position-audio.test.js +24 -0
  95. package/test/positioning.test.js +22 -0
  96. package/test/prepared-script-cache.test.js +45 -0
  97. package/test/pulse-client.test.js +10 -3
  98. package/test/raster-readback.test.js +40 -0
  99. package/test/raw-capture.test.js +152 -0
  100. package/test/render-tree.test.js +28 -0
  101. package/test/renderer-memory.test.js +11 -0
  102. package/test/selector-traits.test.js +24 -0
  103. package/test/shared-frame-pool.test.js +63 -0
  104. package/test/style-sheets.test.js +51 -0
  105. package/test/svg.test.js +29 -0
  106. package/test/text-layout.test.js +106 -0
  107. package/test/video-keyframe.test.js +61 -0
  108. package/test/video-presentation.test.js +69 -0
  109. package/test/window-resize.test.js +36 -0
  110. package/tools/bench-raw-capture.js +32 -0
  111. package/tools/browser-lab.js +78 -0
  112. package/tools/browser-soak.js +75 -0
  113. package/tools/network-reference.js +49 -0
  114. package/tools/process-memory.js +38 -0
  115. package/tools/script-benchmark.js +25 -0
  116. package/ai-debug.log +0 -5537
@@ -6,7 +6,7 @@
6
6
  * Supported: path, rect, circle, ellipse, line, polyline, polygon, nested g
7
7
  * and svg; fill, stroke, stroke-width, fill-rule, opacity, fill-opacity,
8
8
  * stroke-opacity and transform (matrix, translate, scale, rotate) from
9
- * attributes, inherited through groups; currentColor. Text, gradients,
9
+ * attributes, inherited through groups; CSS fill/stroke/opacity and currentColor. Text, gradients,
10
10
  * patterns, masks, filters and <use> are not drawn.
11
11
  */
12
12
 
@@ -19,7 +19,7 @@ const IDENTITY = Object.freeze([1, 0, 0, 1, 0, 0]);
19
19
  * @param {string} currentColor the element's computed color (rgba)
20
20
  * @returns {{ viewBox: number[] | null, width: number | null, height: number | null, shapes: object[] }}
21
21
  */
22
- export function extractSvg(element, currentColor) {
22
+ export function extractSvg(element, currentColor, styleEngine = null) {
23
23
  // HTML-parsed markup may carry the attribute lowercased (viewbox).
24
24
  const viewBox = parseNumbers(element.getAttribute("viewBox") ?? element.getAttribute("viewbox"));
25
25
  const shapes = [];
@@ -33,18 +33,21 @@ export function extractSvg(element, currentColor) {
33
33
  opacity: 1,
34
34
  matrix: IDENTITY,
35
35
  };
36
- walk(element, inherit(root, element, currentColor, true));
36
+ walk(element, inherit(root, element, currentColor, true, styleEngine?.get(element)));
37
37
 
38
38
  function walk(node, paint) {
39
39
  for (const child of node.children ?? []) {
40
40
  const name = child.localName?.toLowerCase();
41
- if (!name || SKIPPED.has(name) || child.getAttribute("display") === "none" || child.getAttribute("visibility") === "hidden") continue;
42
- const childPaint = inherit(paint, child, currentColor, false);
41
+ const style = styleEngine?.get(child);
42
+ if (!name || SKIPPED.has(name) || (style?.display ?? child.getAttribute("display")) === "none"
43
+ || !styleEngine && child.getAttribute("visibility") === "hidden") continue;
44
+ const childPaint = inherit(paint, child, style?.color ?? currentColor, false, style);
43
45
  if (name === "g" || name === "svg" || name === "a") {
44
46
  walk(child, childPaint);
45
47
  continue;
46
48
  }
47
49
  if (!SHAPES.has(name)) continue;
50
+ if (["hidden", "collapse"].includes(style?.visibility ?? child.getAttribute("visibility"))) continue;
48
51
  const d = shapePath(name, child);
49
52
  if (!d) continue;
50
53
  // A line has no interior to fill (SVG 2 §10.5).
@@ -72,8 +75,12 @@ export function extractSvg(element, currentColor) {
72
75
  }
73
76
 
74
77
  /** Paint properties of `element`, inheriting from `parent`. Opacity multiplies down the tree. */
75
- function inherit(parent, element, currentColor, isRoot) {
78
+ function inherit(parent, element, currentColor, isRoot, computed) {
76
79
  const attribute = (name) => {
80
+ if (computed) {
81
+ const field = name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
82
+ if (computed[field] != null) return computed[field];
83
+ }
77
84
  // Presentation attributes, overridden by the style attribute.
78
85
  const style = element.getAttribute("style") ?? "";
79
86
  const fromStyle = new RegExp(`(?:^|;)\\s*${name}\\s*:\\s*([^;]+)`, "i").exec(style)?.[1]?.trim();
@@ -94,7 +101,8 @@ function inherit(parent, element, currentColor, isRoot) {
94
101
  };
95
102
  paint.fillOpacity = number("fill-opacity") ?? parent.fillOpacity;
96
103
  paint.strokeOpacity = number("stroke-opacity") ?? parent.strokeOpacity;
97
- paint.opacity = parent.opacity * (number("opacity") ?? 1);
104
+ // The SVG CSS box already composites its own opacity in the display list.
105
+ paint.opacity = parent.opacity * (isRoot && computed ? 1 : number("opacity") ?? 1);
98
106
  // The root's own transform does not apply (it is a CSS box), its children's do.
99
107
  const transform = isRoot ? null : element.getAttribute("transform");
100
108
  if (transform) paint.matrix = multiply(parent.matrix, parseTransform(transform));