xbintsc 0.6.9 → 0.6.12

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 (164) hide show
  1. package/dist/src/checker/globals.js +2 -1
  2. package/dist/src/checker/globals.js.map +1 -1
  3. package/dist/src/cli/help.d.ts +1 -1
  4. package/dist/src/cli/main.js +1 -0
  5. package/dist/src/cli/main.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +3 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.js +3 -0
  9. package/dist/src/codegen/generator/tables.js.map +1 -1
  10. package/dist/src/driver/compiler.js +1 -1
  11. package/dist/src/driver/compiler.js.map +1 -1
  12. package/dist/src/driver/config.js +1 -0
  13. package/dist/src/driver/config.js.map +1 -1
  14. package/dist/src/driver/runtime-objects.d.ts +1 -1
  15. package/dist/src/driver/runtime-objects.js +2 -0
  16. package/dist/src/driver/runtime-objects.js.map +1 -1
  17. package/dist/src/driver/version.d.ts +1 -1
  18. package/dist/src/driver/version.js +1 -1
  19. package/dist/src/driver/version.js.map +1 -1
  20. package/dist/src/extensions/node/crypto/index.js +12 -1
  21. package/dist/src/extensions/node/crypto/index.js.map +1 -1
  22. package/dist/tests/driver/config.test.js +15 -2
  23. package/dist/tests/driver/config.test.js.map +1 -1
  24. package/dist/tests/e2e/compile-builtins.test.js +26 -0
  25. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  26. package/dist/tests/e2e/compile-node.test.js +37 -1
  27. package/dist/tests/e2e/compile-node.test.js.map +1 -1
  28. package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
  29. package/dist/tests/e2e/crypto-random.test.js +63 -0
  30. package/dist/tests/e2e/crypto-random.test.js.map +1 -0
  31. package/dist/tests/e2e/date-parse.test.js +27 -1
  32. package/dist/tests/e2e/date-parse.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
  34. package/dist/tests/e2e/gui-dom.test.js +29 -0
  35. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  36. package/dist/tests/e2e/gui-form.test.d.ts +9 -0
  37. package/dist/tests/e2e/gui-form.test.js +359 -0
  38. package/dist/tests/e2e/gui-form.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  40. package/dist/tests/e2e/gui-helpers.js +1 -0
  41. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  42. package/dist/tests/e2e/gui-layout.test.js +47 -0
  43. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-paint.test.js +108 -0
  45. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  46. package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
  47. package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
  48. package/dist/tests/e2e/gui-style.test.js +82 -0
  49. package/dist/tests/e2e/gui-style.test.js.map +1 -1
  50. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  51. package/dist/tests/e2e/gui-unsupported.test.js +124 -0
  52. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  53. package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
  54. package/dist/tests/e2e/json-parse-errors.test.js +48 -0
  55. package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
  56. package/doc/ai/extensions.md +7 -4
  57. package/doc/ai/language-support.md +2 -1
  58. package/doc/ai/zh-CN/extensions.md +6 -3
  59. package/doc/ai/zh-CN/language-support.md +2 -1
  60. package/doc/gui/api.md +8 -2
  61. package/doc/gui/dom.md +81 -4
  62. package/doc/gui/input.md +74 -3
  63. package/doc/gui/known-issues.md +12 -5
  64. package/doc/gui/layout.md +19 -6
  65. package/doc/gui/rendering.md +16 -9
  66. package/doc/implemented/node/crypto.md +8 -0
  67. package/doc/implemented/node/fs.md +1 -1
  68. package/doc/implemented/stdlib.md +10 -2
  69. package/doc/zh-CN/gui/api.md +8 -2
  70. package/doc/zh-CN/gui/dom.md +70 -4
  71. package/doc/zh-CN/gui/input.md +65 -4
  72. package/doc/zh-CN/gui/known-issues.md +11 -4
  73. package/doc/zh-CN/gui/layout.md +14 -4
  74. package/doc/zh-CN/gui/rendering.md +13 -10
  75. package/doc/zh-CN/implemented/node/crypto.md +6 -0
  76. package/doc/zh-CN/implemented/node/fs.md +1 -1
  77. package/doc/zh-CN/implemented/stdlib.md +10 -2
  78. package/package.json +7 -7
  79. package/runtime/ext_gui/clip_values.cpp +11 -0
  80. package/runtime/ext_gui/css.cpp +27 -2
  81. package/runtime/ext_gui/css_match.cpp +21 -1
  82. package/runtime/ext_gui/css_selector.cpp +23 -0
  83. package/runtime/ext_gui/css_sheet.cpp +7 -0
  84. package/runtime/ext_gui/document.cpp +15 -0
  85. package/runtime/ext_gui/document_animation.cpp +4 -1
  86. package/runtime/ext_gui/dom.h +41 -2
  87. package/runtime/ext_gui/dom_api.cpp +3 -0
  88. package/runtime/ext_gui/dom_api_document.cpp +28 -0
  89. package/runtime/ext_gui/dom_api_events.cpp +17 -14
  90. package/runtime/ext_gui/dom_api_form.cpp +567 -0
  91. package/runtime/ext_gui/dom_api_internal.h +46 -214
  92. package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
  93. package/runtime/ext_gui/dom_api_node.cpp +10 -3
  94. package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
  95. package/runtime/ext_gui/dom_api_proto.cpp +45 -0
  96. package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
  97. package/runtime/ext_gui/dom_parse.cpp +118 -1
  98. package/runtime/ext_gui/effect_values.cpp +28 -7
  99. package/runtime/ext_gui/form_focus.cpp +293 -0
  100. package/runtime/ext_gui/form_input.cpp +448 -0
  101. package/runtime/ext_gui/form_internal.h +30 -0
  102. package/runtime/ext_gui/form_shared.cpp +126 -0
  103. package/runtime/ext_gui/form_state.cpp +536 -0
  104. package/runtime/ext_gui/form_state.h +97 -0
  105. package/runtime/ext_gui/gradient_values.cpp +25 -5
  106. package/runtime/ext_gui/gui_engine.h +40 -4
  107. package/runtime/ext_gui/gui_events.cpp +63 -48
  108. package/runtime/ext_gui/inline_svg.cpp +3 -0
  109. package/runtime/ext_gui/layout.cpp +6 -0
  110. package/runtime/ext_gui/layout.h +4 -0
  111. package/runtime/ext_gui/layout_flow.cpp +35 -3
  112. package/runtime/ext_gui/layout_inline.cpp +80 -7
  113. package/runtime/ext_gui/media_query.cpp +7 -1
  114. package/runtime/ext_gui/paint.cpp +62 -24
  115. package/runtime/ext_gui/paint.h +7 -4
  116. package/runtime/ext_gui/paint_clip.cpp +74 -19
  117. package/runtime/ext_gui/paint_form.cpp +389 -0
  118. package/runtime/ext_gui/paint_internal.h +13 -1
  119. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  120. package/runtime/ext_gui/style.cpp +5 -1
  121. package/runtime/ext_gui/style.h +5 -0
  122. package/runtime/ext_gui/style_cascade.cpp +2 -0
  123. package/runtime/ext_gui/style_internal.h +7 -2
  124. package/runtime/ext_gui/style_print.cpp +33 -0
  125. package/runtime/ext_gui/style_text.cpp +11 -0
  126. package/runtime/ext_gui/style_ua.cpp +42 -0
  127. package/runtime/ext_gui/style_values.cpp +89 -90
  128. package/runtime/ext_gui/transform.cpp +2 -0
  129. package/runtime/ext_gui/warnings.cpp +298 -0
  130. package/runtime/ext_gui/warnings.h +59 -0
  131. package/runtime/ext_gui/window.cpp +31 -55
  132. package/runtime/ext_gui/window_diagnostics.cpp +58 -0
  133. package/runtime/ext_gui/window_emit.cpp +51 -0
  134. package/runtime/ext_node/crypto/crypto.c +3 -2
  135. package/runtime/ext_node/crypto/crypto_hash.h +13 -0
  136. package/runtime/ext_node/crypto/crypto_random.c +339 -0
  137. package/runtime/ext_node/fs/async_worker.c +1 -1
  138. package/runtime/ext_node/fs/fs_ops.c +1 -1
  139. package/runtime/ext_node/fs/parts/platform.inc +65 -0
  140. package/runtime/rt.h +27 -0
  141. package/runtime/xt_crypto.c +132 -0
  142. package/runtime/xt_random.c +143 -0
  143. package/runtime/xt_regex/matcher.inc +9 -28
  144. package/runtime/xt_regex/parser.inc +65 -2
  145. package/runtime/xt_regex/types.inc +11 -1
  146. package/runtime/xt_regex.h +6 -2
  147. package/runtime/xt_stdlib/dispatch.inc +2 -0
  148. package/runtime/xt_stdlib/math.inc +1 -1
  149. package/runtime/xt_stdlib2/date.inc +204 -4
  150. package/runtime/xt_stdlib2/json.inc +4 -546
  151. package/runtime/xt_stdlib2/json_parse.inc +347 -0
  152. package/runtime/xt_stdlib2/json_stringify.inc +368 -0
  153. package/runtime/xt_stdlib2/regexp-match.inc +6 -11
  154. package/runtime/xt_stdlib2.c +0 -4
  155. package/runtime/xt_typed_array/elements.inc +6 -1
  156. package/src/checker/globals.ts +2 -0
  157. package/src/cli/main.ts +1 -0
  158. package/src/codegen/generator/state.ts +3 -0
  159. package/src/codegen/generator/tables.ts +3 -0
  160. package/src/driver/compiler.ts +1 -1
  161. package/src/driver/config.ts +1 -0
  162. package/src/driver/runtime-objects.ts +2 -0
  163. package/src/driver/version.ts +1 -1
  164. package/src/extensions/node/crypto/index.ts +12 -1
@@ -65,15 +65,22 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
65
65
 
66
66
  /** The clip a box imposes on its content: its padding box, intersected with the
67
67
  * clip already in effect. Only `overflow: hidden/scroll/auto` clips. A
68
- * transformed box clips to the bounding box of its transformed padding box. */
69
- PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent) {
68
+ * `border-radius` makes that clip a rounded rectangle, exactly as a browser
69
+ * rounds `overflow` (the GPU scissor stays the bounding box; the rounded shape
70
+ * joins the `clip-path` polygons the renderer intersects). A transformed box
71
+ * clips to the bounding box of its transformed padding box. */
72
+ PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent, DisplayList &out) {
70
73
  if (box->style == nullptr || box->style->overflow == Overflow::Visible) return parent;
71
- float x = box->x + box->border_left;
72
- float y = box->y + box->border_top;
73
- float width = box->width - box->border_left - box->border_right;
74
- float height = box->height - box->border_top - box->border_bottom;
75
- if (width < 0) width = 0;
76
- if (height < 0) height = 0;
74
+ float padding_x = box->x + box->border_left;
75
+ float padding_y = box->y + box->border_top;
76
+ float padding_width = box->width - box->border_left - box->border_right;
77
+ float padding_height = box->height - box->border_top - box->border_bottom;
78
+ if (padding_width < 0) padding_width = 0;
79
+ if (padding_height < 0) padding_height = 0;
80
+ float x = padding_x;
81
+ float y = padding_y;
82
+ float width = padding_width;
83
+ float height = padding_height;
77
84
  if (box->has_transform) {
78
85
  LayoutRect bounds = xt_layout_transform_rect(box->world, x, y, width, height);
79
86
  x = bounds.x;
@@ -88,16 +95,28 @@ PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent) {
88
95
  result.y = y;
89
96
  result.width = width;
90
97
  result.height = height;
91
- return result;
98
+ } else {
99
+ float x0 = std::max(x, parent.x);
100
+ float y0 = std::max(y, parent.y);
101
+ float x1 = std::min(x + width, parent.x + parent.width);
102
+ float y1 = std::min(y + height, parent.y + parent.height);
103
+ result.x = x0;
104
+ result.y = y0;
105
+ result.width = std::max(0.0f, x1 - x0);
106
+ result.height = std::max(0.0f, y1 - y0);
107
+ }
108
+ /* The radius belongs to the border box, so the padding box's inner radius is
109
+ * reduced by the widest border (CSS 8.1). The polygon is built from the
110
+ * *untransformed* padding box and mapped point by point, so a rotated box
111
+ * keeps a round circle instead of a rounded AABB. */
112
+ if (box->border_radius > 0.0f && padding_width > 0.0f && padding_height > 0.0f) {
113
+ float inset = std::max(std::max(box->border_left, box->border_right),
114
+ std::max(box->border_top, box->border_bottom));
115
+ float radius = box->border_radius - inset;
116
+ int index = paint_detail::addRoundedClipPath(out, box->world, padding_x, padding_y,
117
+ padding_width, padding_height, radius);
118
+ result = paint_detail::addClipPath(result, index);
92
119
  }
93
- float x0 = std::max(x, parent.x);
94
- float y0 = std::max(y, parent.y);
95
- float x1 = std::min(x + width, parent.x + parent.width);
96
- float y1 = std::min(y + height, parent.y + parent.height);
97
- result.x = x0;
98
- result.y = y0;
99
- result.width = std::max(0.0f, x1 - x0);
100
- result.height = std::max(0.0f, y1 - y0);
101
120
  return result;
102
121
  }
103
122
 
@@ -209,6 +228,21 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
209
228
  }
210
229
  }
211
230
 
231
+ /* `border-radius` also clips the box's own background images/gradients and
232
+ * replaced content; a solid background is already painted as a rounded
233
+ * rectangle and needs no polygon. An `<img>`/`<svg>` with only a radius
234
+ * (no `overflow: hidden`) gets its corners clipped this way too. */
235
+ PaintClip contentClip = own;
236
+ if (style != nullptr && !box->is_text && box->border_radius > 0.0f && box->width > 0.0f &&
237
+ box->height > 0.0f) {
238
+ bool replaces = box->is_image || box->is_canvas || box->is_media || box->is_inline_svg;
239
+ if (!style->background_layers.empty() || replaces) {
240
+ int index = paint_detail::addRoundedClipPath(out, box->world, box->x, box->y, box->width,
241
+ box->height, box->border_radius);
242
+ contentClip = paint_detail::addClipPath(contentClip, index);
243
+ }
244
+ }
245
+
212
246
  if (style != nullptr && box->display != Display::None) {
213
247
  if (box->is_text) {
214
248
  addTextRuns(box, *style, out, own, chain, viewportWidth, viewportHeight);
@@ -223,7 +257,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
223
257
  * paint above it. */
224
258
  paint_detail::addBoxShadows(out, *box, *style, chain, own, false, viewportWidth,
225
259
  viewportHeight);
226
- paint_detail::paintBackgrounds(out, *box, *style, chain, own, viewportWidth,
260
+ paint_detail::paintBackgrounds(out, *box, *style, chain, contentClip, viewportWidth,
227
261
  viewportHeight);
228
262
  const Matrix2D &matrix = box->world;
229
263
  if (style->border_style != BorderStyle::None && style->has_border_color) {
@@ -245,7 +279,10 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
245
279
  paint_detail::addBoxShadows(out, *box, *style, chain, own, true, viewportWidth,
246
280
  viewportHeight);
247
281
  paint_detail::addOutline(out, *box, *style, chain, own, viewportWidth, viewportHeight);
248
- if (box->is_canvas && box->canvas_id != 0 && box->content_width > 0.0f &&
282
+ if (box->is_control) {
283
+ paint_detail::xt_paint_form_control(*box, *style, out, contentClip, chain, viewportWidth,
284
+ viewportHeight);
285
+ } else if (box->is_canvas && box->canvas_id != 0 && box->content_width > 0.0f &&
249
286
  box->content_height > 0.0f) {
250
287
  PaintImage image;
251
288
  image.x = box->content_x;
@@ -254,7 +291,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
254
291
  image.height = box->content_height;
255
292
  image.canvas_id = box->canvas_id;
256
293
  image.transform = matrix;
257
- paint_detail::addImage(out, image, own, chain);
294
+ paint_detail::addImage(out, image, contentClip, chain);
258
295
  } else if (box->is_media && box->media_id != 0 && box->content_width > 0.0f &&
259
296
  box->content_height > 0.0f) {
260
297
  PaintImage image;
@@ -264,7 +301,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
264
301
  image.height = box->content_height;
265
302
  image.media_id = box->media_id;
266
303
  image.transform = matrix;
267
- paint_detail::addImage(out, image, own, chain);
304
+ paint_detail::addImage(out, image, contentClip, chain);
268
305
  } else if (box->is_inline_svg && !box->svg_markup.empty() && box->content_width > 0.0f &&
269
306
  box->content_height > 0.0f) {
270
307
  PaintImage image;
@@ -274,7 +311,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
274
311
  image.height = box->content_height;
275
312
  image.svg = box->svg_markup;
276
313
  image.transform = matrix;
277
- paint_detail::addImage(out, image, own, chain);
314
+ paint_detail::addImage(out, image, contentClip, chain);
278
315
  } else if (box->is_image && !box->image_src.empty() && box->content_width > 0.0f &&
279
316
  box->content_height > 0.0f) {
280
317
  PaintImage image;
@@ -284,7 +321,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
284
321
  image.height = box->content_height;
285
322
  image.src = box->image_src;
286
323
  image.transform = matrix;
287
- paint_detail::addImage(out, image, own, chain);
324
+ paint_detail::addImage(out, image, contentClip, chain);
288
325
  }
289
326
  }
290
327
  }
@@ -293,7 +330,8 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
293
330
  * already been emitted, so descendants must not repeat it. */
294
331
  paint_detail::FilterChain childChain = chain;
295
332
  childChain.shadows.clear();
296
- paintChildren(box, out, clipForChildren(box, own), childChain, viewportWidth, viewportHeight);
333
+ paintChildren(box, out, clipForChildren(box, own, out), childChain, viewportWidth,
334
+ viewportHeight);
297
335
  }
298
336
 
299
337
  /** Paint one box, wrapping it in a `mix-blend-mode` group when it declares one.
@@ -156,17 +156,20 @@ struct ClipPathGeometry {
156
156
 
157
157
  /** The clip rectangle in effect for a painted shape (device-space logical
158
158
  * pixels — a transformed subtree contributes the bounding box of its clip).
159
- * `width <= 0` means "no clip". `paths` index `DisplayList::clip_paths`; at most
160
- * two nested `clip-path` shapes are kept (CSS would intersect every ancestor;
161
- * deeper nesting is rare and the outermost two are the ones a UI uses). */
159
+ * `width <= 0` means "no clip". `paths` index `DisplayList::clip_paths`: the
160
+ * `clip-path` shapes and the rounded padding boxes of `overflow` ancestors
161
+ * intersected down the tree. Four nested shapes are kept (CSS would intersect
162
+ * every ancestor; deeper nesting is rare and the outermost four are the ones a
163
+ * shape has to satisfy). */
162
164
  struct PaintClip {
165
+ static constexpr int kMaxPaths = 4;
163
166
  bool active = false;
164
167
  float x = 0;
165
168
  float y = 0;
166
169
  float width = 0;
167
170
  float height = 0;
168
171
  int path_count = 0;
169
- int paths[2] = {-1, -1};
172
+ int paths[kMaxPaths] = {-1, -1, -1, -1};
170
173
  };
171
174
 
172
175
  enum class PaintKind { Rect, Text, Image, LayerBegin, LayerEnd, Backdrop };
@@ -215,6 +215,49 @@ void triangulate(std::vector<Point> points, std::vector<ClipTriangle> *triangles
215
215
  }
216
216
  }
217
217
 
218
+ /** Transform a box-local polygon into device space, triangulate it and store it
219
+ * on the display list. A polygon with fewer than three points is kept as an
220
+ * empty clip: a valid `clip-path` that hides everything must not degrade into
221
+ * "no clip". `convex` lets a caller that knows the shape (a rounded rectangle)
222
+ * skip ear clipping and emit a fan. */
223
+ int storeClipPolygon(DisplayList &out, const std::vector<Point> &points, const Matrix2D &world,
224
+ bool convex) {
225
+ ClipPathGeometry geometry;
226
+ geometry.points.reserve(points.size() * 2);
227
+ for (const Point &point : points) {
228
+ float x = point.x;
229
+ float y = point.y;
230
+ world.apply(point.x, point.y, &x, &y);
231
+ geometry.points.push_back(x);
232
+ geometry.points.push_back(y);
233
+ }
234
+ if (points.size() >= 3) {
235
+ if (convex) {
236
+ /* A convex outline is triangulated by a fan from its first vertex; the
237
+ * rounded-overflow shape (the common case) has ~68 points and this keeps
238
+ * its cost linear. */
239
+ for (size_t i = 1; i + 1 < points.size(); i++) {
240
+ ClipTriangle triangle;
241
+ triangle.x[0] = geometry.points[0];
242
+ triangle.y[0] = geometry.points[1];
243
+ triangle.x[1] = geometry.points[i * 2];
244
+ triangle.y[1] = geometry.points[i * 2 + 1];
245
+ triangle.x[2] = geometry.points[(i + 1) * 2];
246
+ triangle.y[2] = geometry.points[(i + 1) * 2 + 1];
247
+ geometry.triangles.push_back(triangle);
248
+ }
249
+ } else {
250
+ std::vector<Point> device;
251
+ device.reserve(points.size());
252
+ for (size_t i = 0; i + 1 < geometry.points.size(); i += 2)
253
+ device.push_back({geometry.points[i], geometry.points[i + 1]});
254
+ triangulate(device, &geometry.triangles);
255
+ }
256
+ }
257
+ out.clip_paths.push_back(std::move(geometry));
258
+ return (int)(out.clip_paths.size() - 1);
259
+ }
260
+
218
261
  } // namespace
219
262
 
220
263
  int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &style,
@@ -238,29 +281,41 @@ int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &sty
238
281
  /* An empty but valid shape (`inset(50%)`, `circle(0)`) clips everything away;
239
282
  * it must not fall back to "no clip". The paint walk keeps the empty geometry
240
283
  * and the renderer emits no geometry for ops that reference it. */
241
- ClipPathGeometry geometry;
242
- geometry.points.reserve(points.size() * 2);
243
- for (Point &point : points) {
244
- float x = point.x;
245
- float y = point.y;
246
- box.world.apply(point.x, point.y, &x, &y);
247
- geometry.points.push_back(x);
248
- geometry.points.push_back(y);
249
- }
250
- if (points.size() >= 3) {
251
- std::vector<Point> device;
252
- device.reserve(points.size());
253
- for (size_t i = 0; i + 1 < geometry.points.size(); i += 2)
254
- device.push_back({geometry.points[i], geometry.points[i + 1]});
255
- triangulate(device, &geometry.triangles);
256
- }
257
- out.clip_paths.push_back(std::move(geometry));
258
- return (int)(out.clip_paths.size() - 1);
284
+ return storeClipPolygon(out, points, box.world, false);
285
+ }
286
+
287
+ int addRoundedClipPath(DisplayList &out, const Matrix2D &world, float x, float y, float width,
288
+ float height, float radius) {
289
+ if (width <= 0.0f || height <= 0.0f || radius <= 0.0f) return -1;
290
+ /* CSS never lets a corner arc exceed half of the shorter side. */
291
+ float limit = std::min(width, height) * 0.5f;
292
+ if (radius > limit) radius = limit;
293
+ if (radius <= 0.0f) return -1;
294
+ /* Sixteen chords per quarter circle keep a large (176px) preview avatar
295
+ * visually round — the chord error at that radius is under half a pixel —
296
+ * and stay cheap to clip quads against. The `inset(... round ...)` outline
297
+ * keeps its coarser six-segment construction. */
298
+ constexpr int kSegments = 16;
299
+ std::vector<Point> points;
300
+ points.reserve((size_t)(kSegments + 1) * 4);
301
+ auto arc = [&](float centerX, float centerY, float start) {
302
+ for (int i = 0; i <= kSegments; i++) {
303
+ float angle = start + (float)i / (float)kSegments * (kPi * 0.5f);
304
+ appendPoint(&points,
305
+ {centerX + std::cos(angle) * radius, centerY + std::sin(angle) * radius});
306
+ }
307
+ };
308
+ /* Clockwise from the top-left corner, matching `insetOutline`. */
309
+ arc(x + radius, y + radius, kPi);
310
+ arc(x + width - radius, y + radius, kPi * 1.5f);
311
+ arc(x + width - radius, y + height - radius, 0.0f);
312
+ arc(x + radius, y + height - radius, kPi * 0.5f);
313
+ return storeClipPolygon(out, points, world, true);
259
314
  }
260
315
 
261
316
  PaintClip addClipPath(PaintClip clip, int index) {
262
317
  if (index < 0) return clip;
263
- if (clip.path_count < 2) clip.paths[clip.path_count++] = index;
318
+ if (clip.path_count < PaintClip::kMaxPaths) clip.paths[clip.path_count++] = index;
264
319
  return clip;
265
320
  }
266
321