yass-css 0.2.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 (429) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +11 -0
  3. data/CODE_OF_CONDUCT.md +132 -0
  4. data/Cargo.lock +1447 -0
  5. data/Cargo.toml +7 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +139 -0
  8. data/Rakefile +130 -0
  9. data/codegen/ruby_module_tree.rb +178 -0
  10. data/codegen/rust_file_set.rb +84 -0
  11. data/codegen/utils.rb +27 -0
  12. data/dockerfiles/windows.dockerfile +3 -0
  13. data/examples/basic_example.rb +32 -0
  14. data/examples/font_example.rb +19 -0
  15. data/examples/media_example.rb +31 -0
  16. data/examples/visitor_example.rb +41 -0
  17. data/ext/.DS_Store +0 -0
  18. data/ext/yass/Cargo.toml +24 -0
  19. data/ext/yass/extconf.rb +6 -0
  20. data/ext/yass/src/.DS_Store +0 -0
  21. data/ext/yass/src/cached_value.rs +48 -0
  22. data/ext/yass/src/cached_value_list.rs +63 -0
  23. data/ext/yass/src/declarations/.DS_Store +0 -0
  24. data/ext/yass/src/declarations/align_content.rs +19 -0
  25. data/ext/yass/src/declarations/align_flags.rs +26 -0
  26. data/ext/yass/src/declarations/align_items.rs +37 -0
  27. data/ext/yass/src/declarations/align_self.rs +19 -0
  28. data/ext/yass/src/declarations/alignment_baseline.rs +27 -0
  29. data/ext/yass/src/declarations/angle.rs +25 -0
  30. data/ext/yass/src/declarations/animation/auto.rs +8 -0
  31. data/ext/yass/src/declarations/animation/init.rs +40 -0
  32. data/ext/yass/src/declarations/animation/inset.rs +50 -0
  33. data/ext/yass/src/declarations/animation/length_auto.rs +8 -0
  34. data/ext/yass/src/declarations/animation/mod.rs +11 -0
  35. data/ext/yass/src/declarations/animation/range_value.rs +47 -0
  36. data/ext/yass/src/declarations/animation/scroll_axis.rs +22 -0
  37. data/ext/yass/src/declarations/animation/scroll_function.rs +40 -0
  38. data/ext/yass/src/declarations/animation/scroller.rs +21 -0
  39. data/ext/yass/src/declarations/animation/timeline_name.rs +16 -0
  40. data/ext/yass/src/declarations/animation/timing_function/cubic_bezier.rs +60 -0
  41. data/ext/yass/src/declarations/animation/timing_function/init.rs +29 -0
  42. data/ext/yass/src/declarations/animation/timing_function/keyword.rs +23 -0
  43. data/ext/yass/src/declarations/animation/timing_function/mod.rs +5 -0
  44. data/ext/yass/src/declarations/animation/timing_function/piecewise_linear_function.rs +49 -0
  45. data/ext/yass/src/declarations/animation/timing_function/steps.rs +30 -0
  46. data/ext/yass/src/declarations/animation/view_function.rs +40 -0
  47. data/ext/yass/src/declarations/animation_composition.rs +29 -0
  48. data/ext/yass/src/declarations/animation_delay.rs +30 -0
  49. data/ext/yass/src/declarations/animation_direction.rs +30 -0
  50. data/ext/yass/src/declarations/animation_duration.rs +67 -0
  51. data/ext/yass/src/declarations/animation_fill_mode.rs +30 -0
  52. data/ext/yass/src/declarations/animation_iteration_count.rs +33 -0
  53. data/ext/yass/src/declarations/animation_name.rs +23 -0
  54. data/ext/yass/src/declarations/animation_play_state.rs +28 -0
  55. data/ext/yass/src/declarations/animation_range_end.rs +30 -0
  56. data/ext/yass/src/declarations/animation_range_start.rs +30 -0
  57. data/ext/yass/src/declarations/animation_timeline.rs +42 -0
  58. data/ext/yass/src/declarations/animation_timing_function.rs +46 -0
  59. data/ext/yass/src/declarations/aspect_ratio.rs +43 -0
  60. data/ext/yass/src/declarations/backdrop_filter.rs +30 -0
  61. data/ext/yass/src/declarations/backface_visibility.rs +20 -0
  62. data/ext/yass/src/declarations/background_attachment.rs +25 -0
  63. data/ext/yass/src/declarations/background_blend_mode.rs +42 -0
  64. data/ext/yass/src/declarations/background_clip.rs +25 -0
  65. data/ext/yass/src/declarations/background_color.rs +30 -0
  66. data/ext/yass/src/declarations/background_image.rs +30 -0
  67. data/ext/yass/src/declarations/background_origin.rs +29 -0
  68. data/ext/yass/src/declarations/background_position_x.rs +30 -0
  69. data/ext/yass/src/declarations/background_position_y.rs +30 -0
  70. data/ext/yass/src/declarations/background_repeat.rs +58 -0
  71. data/ext/yass/src/declarations/background_size.rs +120 -0
  72. data/ext/yass/src/declarations/baseline_shift.rs +63 -0
  73. data/ext/yass/src/declarations/baseline_source.rs +21 -0
  74. data/ext/yass/src/declarations/block_size.rs +30 -0
  75. data/ext/yass/src/declarations/border_block_end_color.rs +30 -0
  76. data/ext/yass/src/declarations/border_block_end_style.rs +19 -0
  77. data/ext/yass/src/declarations/border_block_end_width.rs +24 -0
  78. data/ext/yass/src/declarations/border_block_start_color.rs +30 -0
  79. data/ext/yass/src/declarations/border_block_start_style.rs +19 -0
  80. data/ext/yass/src/declarations/border_block_start_width.rs +24 -0
  81. data/ext/yass/src/declarations/border_bottom_color.rs +30 -0
  82. data/ext/yass/src/declarations/border_bottom_left_radius.rs +40 -0
  83. data/ext/yass/src/declarations/border_bottom_right_radius.rs +40 -0
  84. data/ext/yass/src/declarations/border_bottom_style.rs +19 -0
  85. data/ext/yass/src/declarations/border_bottom_width.rs +24 -0
  86. data/ext/yass/src/declarations/border_collapse.rs +20 -0
  87. data/ext/yass/src/declarations/border_end_end_radius.rs +40 -0
  88. data/ext/yass/src/declarations/border_end_start_radius.rs +40 -0
  89. data/ext/yass/src/declarations/border_image_outset.rs +73 -0
  90. data/ext/yass/src/declarations/border_image_repeat.rs +30 -0
  91. data/ext/yass/src/declarations/border_image_slice.rs +78 -0
  92. data/ext/yass/src/declarations/border_image_source.rs +28 -0
  93. data/ext/yass/src/declarations/border_image_width.rs +85 -0
  94. data/ext/yass/src/declarations/border_inline_end_color.rs +30 -0
  95. data/ext/yass/src/declarations/border_inline_end_style.rs +19 -0
  96. data/ext/yass/src/declarations/border_inline_end_width.rs +24 -0
  97. data/ext/yass/src/declarations/border_inline_start_color.rs +30 -0
  98. data/ext/yass/src/declarations/border_inline_start_style.rs +19 -0
  99. data/ext/yass/src/declarations/border_inline_start_width.rs +24 -0
  100. data/ext/yass/src/declarations/border_left_color.rs +30 -0
  101. data/ext/yass/src/declarations/border_left_style.rs +19 -0
  102. data/ext/yass/src/declarations/border_left_width.rs +24 -0
  103. data/ext/yass/src/declarations/border_right_color.rs +30 -0
  104. data/ext/yass/src/declarations/border_right_style.rs +19 -0
  105. data/ext/yass/src/declarations/border_right_width.rs +24 -0
  106. data/ext/yass/src/declarations/border_spacing.rs +51 -0
  107. data/ext/yass/src/declarations/border_start_end_radius.rs +40 -0
  108. data/ext/yass/src/declarations/border_start_start_radius.rs +40 -0
  109. data/ext/yass/src/declarations/border_style.rs +17 -0
  110. data/ext/yass/src/declarations/border_top_color.rs +30 -0
  111. data/ext/yass/src/declarations/border_top_left_radius.rs +40 -0
  112. data/ext/yass/src/declarations/border_top_right_radius.rs +40 -0
  113. data/ext/yass/src/declarations/border_top_style.rs +19 -0
  114. data/ext/yass/src/declarations/border_top_width.rs +24 -0
  115. data/ext/yass/src/declarations/bottom.rs +28 -0
  116. data/ext/yass/src/declarations/box_shadow.rs +113 -0
  117. data/ext/yass/src/declarations/box_sizing.rs +20 -0
  118. data/ext/yass/src/declarations/calc/abs.rs +32 -0
  119. data/ext/yass/src/declarations/calc/anchor_function.rs +96 -0
  120. data/ext/yass/src/declarations/calc/anchor_size_function.rs +84 -0
  121. data/ext/yass/src/declarations/calc/clamp.rs +58 -0
  122. data/ext/yass/src/declarations/calc/hypot.rs +30 -0
  123. data/ext/yass/src/declarations/calc/init.rs +72 -0
  124. data/ext/yass/src/declarations/calc/invert.rs +32 -0
  125. data/ext/yass/src/declarations/calc/leaf.rs +36 -0
  126. data/ext/yass/src/declarations/calc/min_max.rs +40 -0
  127. data/ext/yass/src/declarations/calc/mod.rs +118 -0
  128. data/ext/yass/src/declarations/calc/mod_rem.rs +57 -0
  129. data/ext/yass/src/declarations/calc/negate.rs +32 -0
  130. data/ext/yass/src/declarations/calc/product.rs +30 -0
  131. data/ext/yass/src/declarations/calc/round.rs +59 -0
  132. data/ext/yass/src/declarations/calc/sign.rs +32 -0
  133. data/ext/yass/src/declarations/calc/sum.rs +30 -0
  134. data/ext/yass/src/declarations/caption_side.rs +20 -0
  135. data/ext/yass/src/declarations/caret_color.rs +32 -0
  136. data/ext/yass/src/declarations/channel_keyword.rs +31 -0
  137. data/ext/yass/src/declarations/clear.rs +24 -0
  138. data/ext/yass/src/declarations/clip.rs +135 -0
  139. data/ext/yass/src/declarations/clip_path/circle_ellipse.rs +168 -0
  140. data/ext/yass/src/declarations/clip_path/init.rs +267 -0
  141. data/ext/yass/src/declarations/clip_path/mod.rs +419 -0
  142. data/ext/yass/src/declarations/clip_path/path.rs +734 -0
  143. data/ext/yass/src/declarations/clip_path/rect.rs +288 -0
  144. data/ext/yass/src/declarations/clip_path/shape.rs +672 -0
  145. data/ext/yass/src/declarations/clip_path/shape_box.rs +71 -0
  146. data/ext/yass/src/declarations/color/absolute.rs +46 -0
  147. data/ext/yass/src/declarations/color/absolute_color.rs +53 -0
  148. data/ext/yass/src/declarations/color/auto.rs +8 -0
  149. data/ext/yass/src/declarations/color/color.rs +38 -0
  150. data/ext/yass/src/declarations/color/color_components.rs +25 -0
  151. data/ext/yass/src/declarations/color/color_function.rs +151 -0
  152. data/ext/yass/src/declarations/color/color_function_component.rs +61 -0
  153. data/ext/yass/src/declarations/color/color_interpolation_method.rs +29 -0
  154. data/ext/yass/src/declarations/color/color_mix.rs +60 -0
  155. data/ext/yass/src/declarations/color/color_mix_item.rs +43 -0
  156. data/ext/yass/src/declarations/color/current_color.rs +8 -0
  157. data/ext/yass/src/declarations/color/init.rs +60 -0
  158. data/ext/yass/src/declarations/color/light_dark.rs +43 -0
  159. data/ext/yass/src/declarations/color/mod.rs +69 -0
  160. data/ext/yass/src/declarations/color/stored_color_function_component.rs +70 -0
  161. data/ext/yass/src/declarations/color/system_color.rs +60 -0
  162. data/ext/yass/src/declarations/color_scheme.rs +26 -0
  163. data/ext/yass/src/declarations/column_count.rs +37 -0
  164. data/ext/yass/src/declarations/column_gap.rs +74 -0
  165. data/ext/yass/src/declarations/column_span.rs +20 -0
  166. data/ext/yass/src/declarations/column_width.rs +70 -0
  167. data/ext/yass/src/declarations/contain.rs +106 -0
  168. data/ext/yass/src/declarations/container_name.rs +32 -0
  169. data/ext/yass/src/declarations/container_type.rs +52 -0
  170. data/ext/yass/src/declarations/content.rs +309 -0
  171. data/ext/yass/src/declarations/counter_increment.rs +60 -0
  172. data/ext/yass/src/declarations/counter_reset.rs +60 -0
  173. data/ext/yass/src/declarations/csswide_keyword.rs +28 -0
  174. data/ext/yass/src/declarations/cursor.rs +125 -0
  175. data/ext/yass/src/declarations/custom.rs +108 -0
  176. data/ext/yass/src/declarations/declaration.rs +716 -0
  177. data/ext/yass/src/declarations/direction.rs +20 -0
  178. data/ext/yass/src/declarations/display.rs +74 -0
  179. data/ext/yass/src/declarations/empty_cells.rs +20 -0
  180. data/ext/yass/src/declarations/filter/blur.rs +28 -0
  181. data/ext/yass/src/declarations/filter/brightness.rs +30 -0
  182. data/ext/yass/src/declarations/filter/contrast.rs +30 -0
  183. data/ext/yass/src/declarations/filter/drop_shadow.rs +68 -0
  184. data/ext/yass/src/declarations/filter/grayscale.rs +30 -0
  185. data/ext/yass/src/declarations/filter/hue_rotate.rs +28 -0
  186. data/ext/yass/src/declarations/filter/init.rs +43 -0
  187. data/ext/yass/src/declarations/filter/invert.rs +30 -0
  188. data/ext/yass/src/declarations/filter/mod.rs +80 -0
  189. data/ext/yass/src/declarations/filter/opacity.rs +30 -0
  190. data/ext/yass/src/declarations/filter/saturate.rs +30 -0
  191. data/ext/yass/src/declarations/filter/sepia.rs +30 -0
  192. data/ext/yass/src/declarations/flex_basis.rs +71 -0
  193. data/ext/yass/src/declarations/flex_direction.rs +22 -0
  194. data/ext/yass/src/declarations/flex_grow.rs +30 -0
  195. data/ext/yass/src/declarations/flex_shrink.rs +30 -0
  196. data/ext/yass/src/declarations/flex_wrap.rs +21 -0
  197. data/ext/yass/src/declarations/float.rs +23 -0
  198. data/ext/yass/src/declarations/font_family.rs +28 -0
  199. data/ext/yass/src/declarations/font_language_override.rs +30 -0
  200. data/ext/yass/src/declarations/font_optical_sizing.rs +20 -0
  201. data/ext/yass/src/declarations/font_size.rs +126 -0
  202. data/ext/yass/src/declarations/font_stretch.rs +102 -0
  203. data/ext/yass/src/declarations/font_style.rs +101 -0
  204. data/ext/yass/src/declarations/font_synthesis_weight.rs +20 -0
  205. data/ext/yass/src/declarations/font_variant_caps.rs +20 -0
  206. data/ext/yass/src/declarations/font_variation_settings.rs +54 -0
  207. data/ext/yass/src/declarations/font_weight.rs +85 -0
  208. data/ext/yass/src/declarations/grid_auto_columns.rs +32 -0
  209. data/ext/yass/src/declarations/grid_auto_flow.rs +35 -0
  210. data/ext/yass/src/declarations/grid_auto_rows.rs +33 -0
  211. data/ext/yass/src/declarations/grid_column_end.rs +39 -0
  212. data/ext/yass/src/declarations/grid_column_start.rs +39 -0
  213. data/ext/yass/src/declarations/grid_row_end.rs +39 -0
  214. data/ext/yass/src/declarations/grid_row_start.rs +39 -0
  215. data/ext/yass/src/declarations/grid_template.rs +355 -0
  216. data/ext/yass/src/declarations/grid_template_areas.rs +131 -0
  217. data/ext/yass/src/declarations/grid_template_columns.rs +31 -0
  218. data/ext/yass/src/declarations/grid_template_rows.rs +31 -0
  219. data/ext/yass/src/declarations/height.rs +30 -0
  220. data/ext/yass/src/declarations/horizontal_position_component.rs +93 -0
  221. data/ext/yass/src/declarations/image_rendering.rs +21 -0
  222. data/ext/yass/src/declarations/images/angle_or_percentage.rs +35 -0
  223. data/ext/yass/src/declarations/images/circle.rs +72 -0
  224. data/ext/yass/src/declarations/images/conic_gradient.rs +80 -0
  225. data/ext/yass/src/declarations/images/cross_fade.rs +33 -0
  226. data/ext/yass/src/declarations/images/cross_fade_element.rs +44 -0
  227. data/ext/yass/src/declarations/images/cross_fade_image.rs +68 -0
  228. data/ext/yass/src/declarations/images/ellipse.rs +67 -0
  229. data/ext/yass/src/declarations/images/ending_shape.rs +38 -0
  230. data/ext/yass/src/declarations/images/gradient_angle_or_percentage_item.rs +103 -0
  231. data/ext/yass/src/declarations/images/gradient_length_percentage_item.rs +106 -0
  232. data/ext/yass/src/declarations/images/image_set.rs +30 -0
  233. data/ext/yass/src/declarations/images/image_set_item.rs +53 -0
  234. data/ext/yass/src/declarations/images/init.rs +145 -0
  235. data/ext/yass/src/declarations/images/light_dark.rs +40 -0
  236. data/ext/yass/src/declarations/images/line_direction.rs +100 -0
  237. data/ext/yass/src/declarations/images/linear_gradient.rs +75 -0
  238. data/ext/yass/src/declarations/images/mod.rs +93 -0
  239. data/ext/yass/src/declarations/images/none.rs +8 -0
  240. data/ext/yass/src/declarations/images/position.rs +40 -0
  241. data/ext/yass/src/declarations/images/radial_gradient.rs +86 -0
  242. data/ext/yass/src/declarations/images/url.rs +28 -0
  243. data/ext/yass/src/declarations/init.rs +1620 -0
  244. data/ext/yass/src/declarations/inline_size.rs +30 -0
  245. data/ext/yass/src/declarations/inset.rs +114 -0
  246. data/ext/yass/src/declarations/inset_block_end.rs +28 -0
  247. data/ext/yass/src/declarations/inset_block_start.rs +28 -0
  248. data/ext/yass/src/declarations/inset_inline_end.rs +28 -0
  249. data/ext/yass/src/declarations/inset_inline_start.rs +28 -0
  250. data/ext/yass/src/declarations/isolation.rs +20 -0
  251. data/ext/yass/src/declarations/justify_content.rs +19 -0
  252. data/ext/yass/src/declarations/justify_items.rs +37 -0
  253. data/ext/yass/src/declarations/justify_self.rs +19 -0
  254. data/ext/yass/src/declarations/left.rs +28 -0
  255. data/ext/yass/src/declarations/length.rs +230 -0
  256. data/ext/yass/src/declarations/letter_spacing.rs +47 -0
  257. data/ext/yass/src/declarations/line_break.rs +23 -0
  258. data/ext/yass/src/declarations/line_height.rs +51 -0
  259. data/ext/yass/src/declarations/list_style_image.rs +28 -0
  260. data/ext/yass/src/declarations/list_style_position.rs +20 -0
  261. data/ext/yass/src/declarations/list_style_type.rs +132 -0
  262. data/ext/yass/src/declarations/margin.rs +103 -0
  263. data/ext/yass/src/declarations/margin_block_end.rs +28 -0
  264. data/ext/yass/src/declarations/margin_block_start.rs +28 -0
  265. data/ext/yass/src/declarations/margin_bottom.rs +28 -0
  266. data/ext/yass/src/declarations/margin_inline_end.rs +28 -0
  267. data/ext/yass/src/declarations/margin_inline_start.rs +28 -0
  268. data/ext/yass/src/declarations/margin_left.rs +28 -0
  269. data/ext/yass/src/declarations/margin_right.rs +28 -0
  270. data/ext/yass/src/declarations/margin_top.rs +28 -0
  271. data/ext/yass/src/declarations/mask_image.rs +30 -0
  272. data/ext/yass/src/declarations/max_block_size.rs +30 -0
  273. data/ext/yass/src/declarations/max_height.rs +30 -0
  274. data/ext/yass/src/declarations/max_inline_size.rs +30 -0
  275. data/ext/yass/src/declarations/max_width.rs +30 -0
  276. data/ext/yass/src/declarations/min_block_size.rs +30 -0
  277. data/ext/yass/src/declarations/min_height.rs +30 -0
  278. data/ext/yass/src/declarations/min_inline_size.rs +30 -0
  279. data/ext/yass/src/declarations/min_width.rs +30 -0
  280. data/ext/yass/src/declarations/mix_blend_mode.rs +35 -0
  281. data/ext/yass/src/declarations/mod.rs +257 -0
  282. data/ext/yass/src/declarations/number.rs +16 -0
  283. data/ext/yass/src/declarations/object_fit.rs +23 -0
  284. data/ext/yass/src/declarations/object_position.rs +40 -0
  285. data/ext/yass/src/declarations/offset_path.rs +275 -0
  286. data/ext/yass/src/declarations/opacity.rs +39 -0
  287. data/ext/yass/src/declarations/order.rs +17 -0
  288. data/ext/yass/src/declarations/outline_color.rs +30 -0
  289. data/ext/yass/src/declarations/outline_offset.rs +22 -0
  290. data/ext/yass/src/declarations/outline_style.rs +22 -0
  291. data/ext/yass/src/declarations/outline_width.rs +24 -0
  292. data/ext/yass/src/declarations/overflow.rs +12 -0
  293. data/ext/yass/src/declarations/overflow_block.rs +19 -0
  294. data/ext/yass/src/declarations/overflow_clip_margin.rs +40 -0
  295. data/ext/yass/src/declarations/overflow_inline.rs +19 -0
  296. data/ext/yass/src/declarations/overflow_wrap.rs +21 -0
  297. data/ext/yass/src/declarations/overflow_x.rs +19 -0
  298. data/ext/yass/src/declarations/overflow_y.rs +19 -0
  299. data/ext/yass/src/declarations/padding_block_end.rs +30 -0
  300. data/ext/yass/src/declarations/padding_block_start.rs +30 -0
  301. data/ext/yass/src/declarations/padding_bottom.rs +30 -0
  302. data/ext/yass/src/declarations/padding_inline_end.rs +30 -0
  303. data/ext/yass/src/declarations/padding_inline_start.rs +30 -0
  304. data/ext/yass/src/declarations/padding_left.rs +30 -0
  305. data/ext/yass/src/declarations/padding_right.rs +30 -0
  306. data/ext/yass/src/declarations/padding_top.rs +30 -0
  307. data/ext/yass/src/declarations/percentage.rs +16 -0
  308. data/ext/yass/src/declarations/perspective.rs +72 -0
  309. data/ext/yass/src/declarations/perspective_origin.rs +41 -0
  310. data/ext/yass/src/declarations/pointer_events.rs +20 -0
  311. data/ext/yass/src/declarations/position.rs +23 -0
  312. data/ext/yass/src/declarations/position_area.rs +82 -0
  313. data/ext/yass/src/declarations/position_try_fallbacks.rs +175 -0
  314. data/ext/yass/src/declarations/quotes.rs +107 -0
  315. data/ext/yass/src/declarations/resolution.rs +17 -0
  316. data/ext/yass/src/declarations/right.rs +28 -0
  317. data/ext/yass/src/declarations/rotate.rs +103 -0
  318. data/ext/yass/src/declarations/row_gap.rs +74 -0
  319. data/ext/yass/src/declarations/scale.rs +90 -0
  320. data/ext/yass/src/declarations/servo_overflow_clip_box.rs +20 -0
  321. data/ext/yass/src/declarations/servo_top_layer.rs +20 -0
  322. data/ext/yass/src/declarations/size/anchor_max_size_function.rs +53 -0
  323. data/ext/yass/src/declarations/size/anchor_size_function.rs +56 -0
  324. data/ext/yass/src/declarations/size/anchor_size_keyword.rs +25 -0
  325. data/ext/yass/src/declarations/size/init.rs +45 -0
  326. data/ext/yass/src/declarations/size/mod.rs +227 -0
  327. data/ext/yass/src/declarations/table_layout.rs +20 -0
  328. data/ext/yass/src/declarations/text_align.rs +31 -0
  329. data/ext/yass/src/declarations/text_align_last.rs +25 -0
  330. data/ext/yass/src/declarations/text_decoration_color.rs +30 -0
  331. data/ext/yass/src/declarations/text_decoration_line.rs +77 -0
  332. data/ext/yass/src/declarations/text_decoration_style.rs +24 -0
  333. data/ext/yass/src/declarations/text_indent.rs +40 -0
  334. data/ext/yass/src/declarations/text_justify.rs +22 -0
  335. data/ext/yass/src/declarations/text_overflow.rs +86 -0
  336. data/ext/yass/src/declarations/text_rendering.rs +22 -0
  337. data/ext/yass/src/declarations/text_shadow.rs +98 -0
  338. data/ext/yass/src/declarations/text_transform.rs +50 -0
  339. data/ext/yass/src/declarations/text_wrap_mode.rs +20 -0
  340. data/ext/yass/src/declarations/time.rs +21 -0
  341. data/ext/yass/src/declarations/top.rs +28 -0
  342. data/ext/yass/src/declarations/track_breadth.rs +88 -0
  343. data/ext/yass/src/declarations/track_size.rs +71 -0
  344. data/ext/yass/src/declarations/transform.rs +844 -0
  345. data/ext/yass/src/declarations/transform_origin.rs +99 -0
  346. data/ext/yass/src/declarations/transform_style.rs +20 -0
  347. data/ext/yass/src/declarations/transition_behavior.rs +28 -0
  348. data/ext/yass/src/declarations/transition_delay.rs +30 -0
  349. data/ext/yass/src/declarations/transition_duration.rs +30 -0
  350. data/ext/yass/src/declarations/transition_property.rs +122 -0
  351. data/ext/yass/src/declarations/transition_timing_function.rs +46 -0
  352. data/ext/yass/src/declarations/translate.rs +84 -0
  353. data/ext/yass/src/declarations/unicode_bidi.rs +24 -0
  354. data/ext/yass/src/declarations/vertical_position_component.rs +93 -0
  355. data/ext/yass/src/declarations/view_transition_class.rs +31 -0
  356. data/ext/yass/src/declarations/view_transition_name.rs +18 -0
  357. data/ext/yass/src/declarations/visibility.rs +21 -0
  358. data/ext/yass/src/declarations/webkit_text_security.rs +22 -0
  359. data/ext/yass/src/declarations/white_space_collapse.rs +22 -0
  360. data/ext/yass/src/declarations/width.rs +30 -0
  361. data/ext/yass/src/declarations/will_change.rs +83 -0
  362. data/ext/yass/src/declarations/with_variables.rs +35 -0
  363. data/ext/yass/src/declarations/word_break.rs +21 -0
  364. data/ext/yass/src/declarations/word_spacing.rs +47 -0
  365. data/ext/yass/src/declarations/writing_mode.rs +21 -0
  366. data/ext/yass/src/declarations/xlang.rs +21 -0
  367. data/ext/yass/src/declarations/zindex.rs +61 -0
  368. data/ext/yass/src/declarations/zoom.rs +87 -0
  369. data/ext/yass/src/general/init.rs +15 -0
  370. data/ext/yass/src/general/mod.rs +43 -0
  371. data/ext/yass/src/lib.rs +72 -0
  372. data/ext/yass/src/optional_cached_value.rs +33 -0
  373. data/ext/yass/src/rules/font_face_rule.rs +206 -0
  374. data/ext/yass/src/rules/fonts/family.rs +98 -0
  375. data/ext/yass/src/rules/fonts/init.rs +81 -0
  376. data/ext/yass/src/rules/fonts/metrics.rs +26 -0
  377. data/ext/yass/src/rules/fonts/mod.rs +7 -0
  378. data/ext/yass/src/rules/fonts/source.rs +126 -0
  379. data/ext/yass/src/rules/fonts/stretch.rs +96 -0
  380. data/ext/yass/src/rules/fonts/style.rs +59 -0
  381. data/ext/yass/src/rules/fonts/weight.rs +74 -0
  382. data/ext/yass/src/rules/init.rs +89 -0
  383. data/ext/yass/src/rules/media_rule.rs +474 -0
  384. data/ext/yass/src/rules/mod.rs +6 -0
  385. data/ext/yass/src/rules/rule.rs +33 -0
  386. data/ext/yass/src/rules/style_rule.rs +82 -0
  387. data/ext/yass/src/selectors/an_plus_b.rs +21 -0
  388. data/ext/yass/src/selectors/attribute_in_no_namespace.rs +34 -0
  389. data/ext/yass/src/selectors/attribute_in_no_namespace_exists.rs +16 -0
  390. data/ext/yass/src/selectors/attribute_other.rs +41 -0
  391. data/ext/yass/src/selectors/class.rs +16 -0
  392. data/ext/yass/src/selectors/combinator.rs +49 -0
  393. data/ext/yass/src/selectors/default_namespace.rs +16 -0
  394. data/ext/yass/src/selectors/has.rs +31 -0
  395. data/ext/yass/src/selectors/host.rs +35 -0
  396. data/ext/yass/src/selectors/id.rs +16 -0
  397. data/ext/yass/src/selectors/init.rs +146 -0
  398. data/ext/yass/src/selectors/is.rs +27 -0
  399. data/ext/yass/src/selectors/local_name.rs +18 -0
  400. data/ext/yass/src/selectors/mod.rs +54 -0
  401. data/ext/yass/src/selectors/namespace.rs +21 -0
  402. data/ext/yass/src/selectors/negation.rs +27 -0
  403. data/ext/yass/src/selectors/non_ts_pseudo_class.rs +63 -0
  404. data/ext/yass/src/selectors/nth.rs +51 -0
  405. data/ext/yass/src/selectors/nth_of.rs +43 -0
  406. data/ext/yass/src/selectors/part.rs +22 -0
  407. data/ext/yass/src/selectors/relative_selector.rs +40 -0
  408. data/ext/yass/src/selectors/selector.rs +230 -0
  409. data/ext/yass/src/selectors/selector_child.rs +460 -0
  410. data/ext/yass/src/selectors/selector_list.rs +27 -0
  411. data/ext/yass/src/selectors/slotted.rs +28 -0
  412. data/ext/yass/src/selectors/specific_namespace_constraint.rs +21 -0
  413. data/ext/yass/src/selectors/unit_selectors.rs +87 -0
  414. data/ext/yass/src/selectors/where.rs +27 -0
  415. data/ext/yass/src/sheet.rs +42 -0
  416. data/ext/yass/src/utils.rs +9 -0
  417. data/lib/yass/declarations.rb +7975 -0
  418. data/lib/yass/general.rb +31 -0
  419. data/lib/yass/node.rb +9 -0
  420. data/lib/yass/rules.rb +515 -0
  421. data/lib/yass/selectors.rb +325 -0
  422. data/lib/yass/stylesheet.rb +13 -0
  423. data/lib/yass/version.rb +5 -0
  424. data/lib/yass/visitor.rb +2463 -0
  425. data/lib/yass.rb +49 -0
  426. data/scripts/build_all.sh +44 -0
  427. data/scripts/detect.rb +39 -0
  428. data/scripts/wpt.rb +20 -0
  429. metadata +486 -0
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/yass"]
7
+ resolver = "2"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Cameron Dutro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Yass
2
+
3
+ Yass is a Ruby wrapper around the [Stylo](https://github.com/servo/stylo) CSS engine, the parser behind the Firefox and Servo browsers developed by Mozilla.
4
+
5
+ ## Rationale
6
+
7
+ I needed a CSS parser in Ruby but couldn't find one that could handle nested CSS rules. Stylo was born out of that need, and aims to be a complete CSS parser for Ruby, covering the entire CSS spec.
8
+
9
+ Stylo is itself under active development, and Yass does not yet wrap the entire Stylo API. If Yass doesn't support a feature you need, consider adding the missing functionality and submitting a pull request.
10
+
11
+ ## Installation
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ ```bash
16
+ bundle add yass-css
17
+ ```
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by executing:
20
+
21
+ ```bash
22
+ gem install yass-css
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ There are two main ways to use Yass: by navigating the object hierarchy by hand, or by using the visitor pattern.
28
+
29
+ By "navigating the object hierarchy," I just mean "calling methods on objects." Here's an example.
30
+
31
+ ```ruby
32
+ require "yass"
33
+
34
+ sheet = Yass::Parser.parse(<<~CSS)
35
+ h1 {
36
+ align-items: center;
37
+ display: flex;
38
+ position: absolute;
39
+ }
40
+ CSS
41
+
42
+ # this is the whole h1 { ... } rule
43
+ first_rule = sheet.rules.first
44
+ puts first_rule.class # => Yass::StyleRule
45
+
46
+ # this is the h1 selector
47
+ first_selector = first_rule.selectors.first.children.first
48
+ puts first_selector.value # => "h1"
49
+ ```
50
+
51
+ The entire object hierarchy can be discovered by dropping into a console session (via `bin/console`) and playing around.
52
+
53
+ ### The Visitor Pattern
54
+
55
+ Yass also comes with a `Yass::Visitor` class that implements the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern).
56
+
57
+ Some people love the visitor pattern, and some people seem to hate it. If you're in the second camp, feel free to skip this section.
58
+
59
+ Visitor classes contain `visit_*` methods that the library calls in-order as it traverses the object hierarchy contained within a parsed stylesheet. The methods the visitor supports can be examined by reading the code in lib/yass/visitor.rb.
60
+
61
+ Let's write a visitor class that prints all the class names in the given stylesheet:
62
+
63
+ ```ruby
64
+ class MyVisitor < Yass::Visitor
65
+ def visit_selector_klass(node)
66
+ # node is an instance of Yass::Selector::Klass
67
+ puts node.value
68
+ end
69
+ end
70
+ ```
71
+
72
+ Now we can use our visitor to visit a stylesheet:
73
+
74
+ ```ruby
75
+ sheet = Yass::Parser.parse(<<~CSS)
76
+ .left {
77
+ float: left;
78
+ }
79
+
80
+ .right {
81
+ float: right;
82
+ }
83
+ CSS
84
+
85
+ visitor = MyVisitor.new
86
+
87
+ # this will result in "left" and "right" being printed to stdout
88
+ visitor.visit(sheet)
89
+ ```
90
+
91
+ ## Examples
92
+
93
+ For more examples, see the examples/ directory.
94
+
95
+ ## Development
96
+
97
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to compile the native extension and run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+
99
+ ### Running Tests
100
+
101
+ Simply execute:
102
+
103
+ ```bash
104
+ bundle exec rake
105
+ ```
106
+
107
+ This will compile the native extension and run the tests immediately afterwards. To compile only, run:
108
+
109
+ ```bash
110
+ bundle exec rake compile
111
+ ```
112
+
113
+ To run the tests only, run:
114
+
115
+ ```bash
116
+ bundle exec rake spec
117
+ ```
118
+
119
+ To run the full test suite (much slower) that attempts to parse the ~33k example CSS files from the [Web Platform Test (WPT) suite](https://github.com/web-platform-tests/wpt), run:
120
+
121
+ ```ruby
122
+ bundle exec rake spec:full
123
+ ```
124
+
125
+ ## Releasing
126
+
127
+ Releasing Yass is done by creating a new release on GitHub. Doing so will trigger a special CI job capable of building the native extension for all supported plaforms and publishing a "fat" .gem file to rubygems.org.
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/camertron/yass. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/camertron/yass/blob/main/CODE_OF_CONDUCT.md).
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## Code of Conduct
138
+
139
+ Everyone interacting in the Yass project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/camertron/yass/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rb_sys/extensiontask"
9
+
10
+ # task build: :compile
11
+
12
+ GEMSPEC = Gem::Specification.load("yass.gemspec")
13
+
14
+ RbSys::ExtensionTask.new("yass", GEMSPEC) do |ext|
15
+ ext.lib_dir = "lib/yass"
16
+ ext.cross_compile = true
17
+ ext.cross_platform = [
18
+ "x86_64-linux",
19
+ "aarch64-linux",
20
+ "x86_64-darwin",
21
+ "arm64-darwin",
22
+ "x64-mingw-ucrt",
23
+ ]
24
+ end
25
+
26
+ task default: %i[compile spec]
27
+
28
+ namespace :spec do
29
+ desc 'Run full specs suit'
30
+ task full: [:full_spec_env, :compile, :spec]
31
+
32
+ task :full_spec_env do
33
+ ENV['FULL_SPEC'] = 'true'
34
+ end
35
+ end
36
+
37
+ # For whatever reason, the :native task that comes with rb-sys doesn't work, so
38
+ # we define our own
39
+ task :native, [:platform] do |task, args|
40
+ env = if args[:platform] =~ /mingw/
41
+ # custom docker image that includes Python, which stylo seems to need
42
+ sh(
43
+ "docker", "build",
44
+ "--platform", "linux/amd64",
45
+ "-f", "dockerfiles/windows.dockerfile",
46
+ "-t", "camertron/rbsys-x64-mingw-ucrt:latest",
47
+ "dockerfiles/"
48
+ )
49
+
50
+ { "RCD_IMAGE" => "camertron/rbsys-x64-mingw-ucrt:latest" }
51
+ else
52
+ {}
53
+ end
54
+
55
+ sh(env, "bundle", "exec", "rb-sys-dock", "--platform", args[:platform], "--build")
56
+ end
57
+
58
+ task :codegen do
59
+ require "yass"
60
+ require_relative "codegen/rust_file_set"
61
+
62
+ general_files = Yass::Codegen::RustFileSet::new(
63
+ Dir.glob("ext/yass/src/general/**/*.rs")
64
+ )
65
+
66
+ File.write("lib/yass/general.rb", <<~RUBY)
67
+ # frozen_string_literal: true
68
+
69
+ #{general_files.module_tree.to_ruby_classes}
70
+ RUBY
71
+
72
+ declaration_files = Yass::Codegen::RustFileSet.new(Dir.glob("ext/yass/src/declarations/**/*.rs"))
73
+
74
+ File.write("lib/yass/declarations.rb", <<~RUBY)
75
+ # frozen_string_literal: true
76
+
77
+ #{declaration_files.module_tree.to_ruby_classes}
78
+ RUBY
79
+
80
+ selector_files = Yass::Codegen::RustFileSet.new(Dir.glob("ext/yass/src/selectors/**/*.rs"))
81
+
82
+ File.write("lib/yass/selectors.rb", <<~RUBY)
83
+ # frozen_string_literal: true
84
+
85
+ #{selector_files.module_tree.to_ruby_classes}
86
+ RUBY
87
+
88
+ rule_files = Yass::Codegen::RustFileSet.new([
89
+ "ext/yass/src/rules/rule.rs",
90
+ "ext/yass/src/rules/style_rule.rs",
91
+ "ext/yass/src/rules/media_rule.rs",
92
+ "ext/yass/src/rules/font_face_rule.rs",
93
+ *Dir.glob("ext/yass/src/rules/fonts/**/*.rs"),
94
+ ])
95
+
96
+ File.write("lib/yass/rules.rb", <<~RUBY)
97
+ # frozen_string_literal: true
98
+
99
+ #{rule_files.module_tree.to_ruby_classes}
100
+ RUBY
101
+
102
+ all_modules = general_files.module_tree
103
+ .merge(declaration_files.module_tree)
104
+ .merge(selector_files.module_tree)
105
+ .merge(rule_files.module_tree)
106
+
107
+ visitor_class = <<~RUBY
108
+ # frozen_string_literal: true
109
+
110
+ module Yass
111
+ class Visitor
112
+ def visit(node)
113
+ node.accept(self) if node
114
+ end
115
+
116
+ def visit_list(nodes)
117
+ nodes.each { |node| visit(node) }
118
+ end
119
+
120
+ def visit_stylesheet(node)
121
+ visit_list(node.rules)
122
+ end
123
+
124
+ #{all_modules.to_visitor_methods(indent: " ").join("\n")}
125
+ end
126
+ end
127
+ RUBY
128
+
129
+ File.write("lib/yass/visitor.rb", visitor_class)
130
+ end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "utils"
4
+
5
+ module Yass
6
+ module Codegen
7
+ class RubyModule
8
+ attr_reader :name
9
+ attr_accessor :rust_struct
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+
15
+ def children
16
+ @children ||= {}
17
+ end
18
+ end
19
+
20
+ class RubyModuleTree
21
+ class << self
22
+ def from_structs(rust_structs)
23
+ root = RubyModule.new(nil)
24
+
25
+ rust_structs.each do |rust_struct|
26
+ current = root
27
+
28
+ rust_struct.ruby_class_name.split("::").each do |ns|
29
+ if !current.children.include?(ns)
30
+ current.children[ns] = RubyModule.new(ns)
31
+ end
32
+
33
+ current = current.children[ns]
34
+ end
35
+
36
+ current.rust_struct = rust_struct
37
+ end
38
+
39
+ new(root)
40
+ end
41
+ end
42
+
43
+ include Utils
44
+
45
+ attr_reader :root
46
+
47
+ def initialize(root)
48
+ @root = root
49
+ end
50
+
51
+ def to_ruby_classes(indent: "")
52
+ to_ruby_classes_helper(root.children["Yass"], ["Yass"], indent)
53
+ end
54
+
55
+ def to_visitor_methods(indent:)
56
+ to_visitor_methods_helper(root.children["Yass"], ["Yass"], indent)
57
+ end
58
+
59
+ def merge(other)
60
+ if root.name != other.root.name
61
+ raise ArgumentError, "this tree and other tree have different names, '#{name}' vs '#{other.root.name}'"
62
+ end
63
+
64
+ new_root = merge_helper(root, other.root)
65
+ self.class.new(new_root)
66
+ end
67
+
68
+ private
69
+
70
+ def merge_helper(first, second)
71
+ RubyModule.new(first.name).tap do |mod|
72
+ first.children.each do |key, first_child_mod|
73
+ if (second_child_mod = second.children[key])
74
+ mod.children[key] = merge_helper(first_child_mod, second_child_mod)
75
+ else
76
+ mod.children[key] = first_child_mod
77
+ end
78
+ end
79
+
80
+ second.children.each do |key, second_child_mod|
81
+ # merge for identical keys should happen in first pass above
82
+ if !first.children.include?(key)
83
+ mod.children[key] = second_child_mod
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def to_ruby_classes_helper(mod, nesting, indent = "")
90
+ class_or_module = Kernel.const_get(nesting.join("::"))
91
+ class_or_module_def = class_or_module.class == Class ? "class #{mod.name}" : "module #{mod.name}"
92
+
93
+ children = mod.children.map do |mod_name, child|
94
+ to_ruby_classes_helper(child, [*nesting, mod_name], indent + " ")
95
+ end
96
+
97
+ accept_method = if mod.rust_struct
98
+ [
99
+ "#{indent} def accept(visitor)",
100
+ "#{indent} visitor.visit_#{nesting_to_s(nesting[1..-1])}(self)",
101
+ "#{indent} end",
102
+ ]
103
+ end
104
+
105
+ kind_method = if mod.rust_struct
106
+ [
107
+ "#{indent} def kind",
108
+ "#{indent} :#{underscore(nesting.last).downcase}",
109
+ "#{indent} end",
110
+ ]
111
+ end
112
+
113
+ constants = if mod.rust_struct
114
+ method_names = class_or_module.instance_methods - Object.methods - [:accept, :to_h]
115
+
116
+ if method_names.size > 0
117
+ [
118
+ "#{indent} RUBY_METHODS = %i(#{method_names.map(&:to_s).sort.join(" ")}).freeze"
119
+ ]
120
+ end
121
+ end
122
+
123
+ includes = if mod.rust_struct
124
+ ["#{indent} include ::Yass::Node"]
125
+ end
126
+
127
+ lines = [
128
+ "#{indent}#{class_or_module_def}",
129
+ *join_line_groups(
130
+ constants,
131
+ includes,
132
+ accept_method,
133
+ kind_method,
134
+ (children.empty? ? [] : [children.join("\n\n")]),
135
+ ),
136
+ "#{indent}end",
137
+ ]
138
+
139
+ lines.join("\n")
140
+ end
141
+
142
+ def to_visitor_methods_helper(mod, nesting, indent)
143
+ line_groups = []
144
+
145
+ if mod.rust_struct
146
+ method_name = "visit_#{nesting_to_s(nesting[1..-1])}"
147
+
148
+ line_groups << [
149
+ "#{indent}def #{method_name}(node)",
150
+ *(debug? ? ["#{indent} puts \"Visiting #{method_name}\""] : []),
151
+ *mod.rust_struct.rust_methods.map do |rust_method|
152
+ if rust_method.visit_kind == :single
153
+ [
154
+ "#{indent} visit(node.#{rust_method.name})"
155
+ ]
156
+ else
157
+ [
158
+ "#{indent} visit_list(node.#{rust_method.name})"
159
+ ]
160
+ end
161
+ end,
162
+ "#{indent}end",
163
+ ]
164
+ end
165
+
166
+ mod.children.each do |mod_name, child|
167
+ line_groups << to_visitor_methods_helper(child, [*nesting, mod_name], indent)
168
+ end
169
+
170
+ join_line_groups(*line_groups)
171
+ end
172
+
173
+ def debug?
174
+ !!ENV["DEBUG"]
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_module_tree"
4
+
5
+ module Yass
6
+ module Codegen
7
+ class RustStruct
8
+ attr_reader :name, :ruby_class_name, :rust_methods
9
+
10
+ def initialize(name:, ruby_class_name:, rust_methods:)
11
+ @name = name
12
+ @ruby_class_name = ruby_class_name
13
+ @rust_methods = rust_methods
14
+ end
15
+ end
16
+
17
+ class RustMethod
18
+ attr_reader :name, :return_type, :visit_kind
19
+
20
+ def initialize(name:, return_type:, visit_kind:)
21
+ @name = name
22
+ @return_type = return_type
23
+ @visit_kind = visit_kind
24
+ end
25
+ end
26
+
27
+ class RustFileSet
28
+ attr_reader :rust_file_paths
29
+
30
+ def initialize(rust_file_paths)
31
+ @rust_file_paths = rust_file_paths
32
+ end
33
+
34
+ def structs
35
+ @structs ||= rust_file_paths.flat_map do |rust_file|
36
+ rust_code = File.read(rust_file)
37
+
38
+ rust_code.scan(/#\[magnus(?:\:\:wrap)?\(class = "([\w:]+)"(?:, mark)?\)\]\s+pub struct (\w+)/).map do |ruby_class_name, rust_struct_name|
39
+ next unless ruby_class_name && rust_struct_name
40
+
41
+ m = rust_code.match(/impl\s+#{rust_struct_name}\s+(\{)/)
42
+ next unless m
43
+
44
+ start = pos = m.end(1)
45
+ count = 1
46
+
47
+ while count > 0
48
+ case rust_code[pos]
49
+ when "{"
50
+ count += 1
51
+ when "}"
52
+ count -= 1
53
+ end
54
+
55
+ pos += 1
56
+ end
57
+
58
+ impl_body = rust_code[start..pos]
59
+ rust_method_names = impl_body.scan(/pub fn (\w+)\(ruby: &Ruby, rb_self: typed_data::Obj<Self>\) -> ([\w<>:, ]+) \{/)
60
+ rust_methods = []
61
+
62
+ rust_method_names.each do |name, return_type|
63
+ if ["Option<Value>", "Value"].include?(return_type)
64
+ rust_methods << RustMethod.new(name: name, return_type: return_type, visit_kind: :single)
65
+ elsif ["RArray", "Result<RArray, Error>"].include?(return_type)
66
+ rust_methods << RustMethod.new(name: name, return_type: return_type, visit_kind: :multiple)
67
+ end
68
+ end
69
+
70
+ RustStruct.new(
71
+ name: rust_struct_name,
72
+ ruby_class_name: ruby_class_name,
73
+ rust_methods: rust_methods
74
+ )
75
+ end
76
+ end
77
+ end
78
+
79
+ def module_tree
80
+ @module_tree ||= RubyModuleTree.from_structs(structs)
81
+ end
82
+ end
83
+ end
84
+ end
data/codegen/utils.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yass
4
+ module Codegen
5
+ module Utils
6
+ def underscore(str)
7
+ str.gsub(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
8
+ end
9
+
10
+ def nesting_to_s(nesting)
11
+ nesting
12
+ .map { |part| underscore(part).downcase }
13
+ .map { |part| part == "declarations" ? "declaration" : part }
14
+ .join("_")
15
+ end
16
+
17
+ def join_line_groups(*line_groups)
18
+ result = line_groups.compact.reject(&:empty?).flat_map do |group|
19
+ [*group.flatten, ""]
20
+ end
21
+
22
+ result.pop
23
+ result
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ FROM rbsys/x64-mingw-ucrt:0.9.126
2
+
3
+ RUN apt-get update && apt-get install -y python3
@@ -0,0 +1,32 @@
1
+ require "yass"
2
+ require "pp"
3
+
4
+ sheet = Yass::Parser.parse(<<~CSS)
5
+ h1 {
6
+ align-items: center;
7
+ display: flex;
8
+ position: absolute;
9
+ }
10
+ CSS
11
+
12
+ # this is the whole h1 { ... } rule
13
+ first_rule = sheet.rules.first
14
+ puts first_rule.class # => Yass::StyleRule
15
+
16
+ # this is the h1 selector
17
+ first_selector = first_rule.selectors.first.children.first
18
+ puts first_selector.value # => "h1"
19
+
20
+ # this is all the declarations inside the h1 rule
21
+ declarations = first_rule.declarations
22
+
23
+ # this is the first align-items declaration
24
+ declaration = declarations.first
25
+ puts declaration.kind # => :align_items
26
+ puts declaration.class # => Yass::Declarations::AlignItems
27
+ puts declaration.value # => :center
28
+
29
+ # this will turn the entire stylesheet into a JSON-compatible
30
+ # data structure (only arrays, hashes, strings, etc) and
31
+ # pretty-print it
32
+ pp sheet.to_h
@@ -0,0 +1,19 @@
1
+ require "yass"
2
+
3
+ sheet = Yass::Parser.parse(<<~CSS)
4
+ @font-face {
5
+ font-family: "Bitstream Vera Serif Bold";
6
+ src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Regular.woff2");
7
+ }
8
+ CSS
9
+
10
+ # this is the whole @font-face { ... } rule
11
+ first_rule = sheet.rules.first
12
+ puts first_rule.class # => Yass::FontFaceRule
13
+
14
+ family = first_rule.family
15
+ puts family.name # => "Bitstream Vera Serif Bold"
16
+
17
+ first_source = first_rule.sources.first
18
+ puts first_source.class # => Yass::Font::Source::Url
19
+ puts first_source.specified_url # => "https://mdn.github.io/shared-assets/fonts/FiraSans-Regular.woff2"
@@ -0,0 +1,31 @@
1
+ require "yass"
2
+
3
+ sheet = Yass::Parser.parse(<<~CSS)
4
+ @media screen and (max-width: 600px) {
5
+ .container {
6
+ flex-direction: column;
7
+ }
8
+ }
9
+ CSS
10
+
11
+ # this is the whole @media { ... } rule
12
+ first_rule = sheet.rules.first
13
+ puts first_rule.class # => Yass::MediaRule
14
+
15
+ # this is the "screen and ..." part
16
+ first_query = first_rule.media_queries.first
17
+ puts first_query.media_type.value # => "screen"
18
+ puts first_query.query_condition.value # => "(max-width: 600px)"
19
+
20
+ # Sadly Stylo doesn't give us access to the full parse tree for the
21
+ # query condition, so the best we can do is emit the unparsed string.
22
+
23
+ # this is the .container rule
24
+ first_nested_rule = first_rule.rules.first
25
+ first_selector = first_nested_rule.selectors.first.children.first
26
+ puts first_selector.value # => "container"
27
+
28
+ # this is the flex-direction declaration
29
+ first_declaration = first_nested_rule.declarations.first
30
+ puts first_declaration.kind # => :flex_direction
31
+ puts first_declaration.value # => :column