dommy 0.16.0 → 0.17.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 (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dommy/animation.rb +1 -0
  3. data/lib/dommy/backend.rb +3 -0
  4. data/lib/dommy/blob.rb +6 -0
  5. data/lib/dommy/browser.rb +12 -4
  6. data/lib/dommy/character_data.rb +1 -13
  7. data/lib/dommy/cookie_store.rb +2 -1
  8. data/lib/dommy/document.rb +67 -30
  9. data/lib/dommy/element.rb +11 -0
  10. data/lib/dommy/element_internals.rb +12 -0
  11. data/lib/dommy/encodings/legacy_multibyte.rb +800 -0
  12. data/lib/dommy/encodings/multibyte_overrides.rb +76 -0
  13. data/lib/dommy/encodings/prescan.rb +234 -0
  14. data/lib/dommy/encodings.rb +121 -57
  15. data/lib/dommy/event.rb +107 -54
  16. data/lib/dommy/event_source.rb +1 -0
  17. data/lib/dommy/fetch.rb +244 -53
  18. data/lib/dommy/file_reader.rb +1 -0
  19. data/lib/dommy/form_data.rb +22 -9
  20. data/lib/dommy/form_entry_list.rb +3 -3
  21. data/lib/dommy/html_canvas_element.rb +85 -12
  22. data/lib/dommy/html_elements/base.rb +1 -0
  23. data/lib/dommy/html_elements/forms/input.rb +3 -0
  24. data/lib/dommy/html_elements/interactive.rb +56 -48
  25. data/lib/dommy/html_elements/metadata.rb +23 -0
  26. data/lib/dommy/interaction/form_submission.rb +24 -42
  27. data/lib/dommy/internal/accessibility_tree.rb +149 -162
  28. data/lib/dommy/internal/accessibility_visibility.rb +16 -17
  29. data/lib/dommy/internal/accessible_name.rb +231 -246
  30. data/lib/dommy/internal/aria_role.rb +182 -195
  31. data/lib/dommy/internal/aria_snapshot.rb +35 -38
  32. data/lib/dommy/internal/aria_state.rb +102 -118
  33. data/lib/dommy/internal/autofill.rb +75 -75
  34. data/lib/dommy/internal/backend_prefilter.rb +127 -130
  35. data/lib/dommy/internal/child_navigable.rb +86 -83
  36. data/lib/dommy/internal/close_watcher_manager.rb +1 -0
  37. data/lib/dommy/internal/css/ancestor_filter.rb +64 -64
  38. data/lib/dommy/internal/css/calc.rb +90 -71
  39. data/lib/dommy/internal/css/cascade.rb +69 -67
  40. data/lib/dommy/internal/css/color.rb +249 -187
  41. data/lib/dommy/internal/css/computed_style_builder.rb +34 -0
  42. data/lib/dommy/internal/css/computed_style_declaration.rb +50 -11
  43. data/lib/dommy/internal/css/counters.rb +67 -67
  44. data/lib/dommy/internal/css/custom_properties.rb +114 -114
  45. data/lib/dommy/internal/css/parser.rb +277 -239
  46. data/lib/dommy/internal/css/property_registry.rb +321 -302
  47. data/lib/dommy/internal/css/renderability.rb +37 -35
  48. data/lib/dommy/internal/css/rule_index.rb +2 -2
  49. data/lib/dommy/internal/css/rule_index_inputs.rb +2 -2
  50. data/lib/dommy/internal/css/supports.rb +115 -113
  51. data/lib/dommy/internal/css/ua_stylesheet.rb +55 -53
  52. data/lib/dommy/internal/css_rule_text.rb +121 -119
  53. data/lib/dommy/internal/css_source.rb +1 -3
  54. data/lib/dommy/internal/css_syntax.rb +157 -92
  55. data/lib/dommy/internal/declarative_shadow_roots.rb +1 -0
  56. data/lib/dommy/internal/directionality.rb +120 -123
  57. data/lib/dommy/internal/document_live_ranges.rb +26 -1
  58. data/lib/dommy/internal/dom_matching.rb +185 -184
  59. data/lib/dommy/internal/element_geometry.rb +8 -1
  60. data/lib/dommy/internal/element_matching.rb +71 -69
  61. data/lib/dommy/internal/element_shadow.rb +1 -13
  62. data/lib/dommy/internal/element_state.rb +255 -265
  63. data/lib/dommy/internal/event_handlers.rb +66 -64
  64. data/lib/dommy/internal/exception_report.rb +88 -86
  65. data/lib/dommy/internal/focusability.rb +205 -205
  66. data/lib/dommy/internal/global_functions.rb +49 -47
  67. data/lib/dommy/internal/idl_reflection.rb +99 -97
  68. data/lib/dommy/internal/js_number.rb +35 -33
  69. data/lib/dommy/internal/light_dismiss.rb +130 -132
  70. data/lib/dommy/internal/literal_lookup.rb +75 -75
  71. data/lib/dommy/internal/mime_type.rb +54 -49
  72. data/lib/dommy/internal/mutation_coordinator.rb +46 -0
  73. data/lib/dommy/internal/mutation_observer_microtask.rb +60 -0
  74. data/lib/dommy/internal/namespaces.rb +51 -49
  75. data/lib/dommy/internal/node_adopter.rb +25 -1
  76. data/lib/dommy/internal/node_equality.rb +61 -59
  77. data/lib/dommy/internal/post_insertion_steps.rb +1 -0
  78. data/lib/dommy/internal/referrer.rb +144 -0
  79. data/lib/dommy/internal/rendered_text/collector.rb +22 -3
  80. data/lib/dommy/internal/rendered_text/computed_box.rb +3 -2
  81. data/lib/dommy/internal/rendered_text/fragment.rb +37 -38
  82. data/lib/dommy/internal/rendered_text/items.rb +7 -5
  83. data/lib/dommy/internal/selector_matcher.rb +361 -359
  84. data/lib/dommy/internal/selector_parser.rb +74 -62
  85. data/lib/dommy/internal/sequential_focus_navigation.rb +150 -151
  86. data/lib/dommy/internal/shadow_root_registry.rb +7 -0
  87. data/lib/dommy/internal/slot_assignment.rb +117 -0
  88. data/lib/dommy/internal/slot_signals.rb +125 -0
  89. data/lib/dommy/internal/unsafe_html.rb +79 -77
  90. data/lib/dommy/internal/url_parser.rb +5 -29
  91. data/lib/dommy/internal/web_idl.rb +158 -153
  92. data/lib/dommy/internal/window_bound.rb +14 -0
  93. data/lib/dommy/internal/window_constructors.rb +3 -0
  94. data/lib/dommy/internal/xml_serialization.rb +298 -296
  95. data/lib/dommy/js/dom_interfaces.rb +13 -1
  96. data/lib/dommy/js/host_bridge.rb +23 -1
  97. data/lib/dommy/js/host_callbacks.rb +7 -0
  98. data/lib/dommy/js/host_runtime.js +625 -61
  99. data/lib/dommy/js/import_map.rb +1 -1
  100. data/lib/dommy/js/observable_runtime.js +295 -128
  101. data/lib/dommy/js/webidl_members.js +1 -1
  102. data/lib/dommy/js/webidl_signatures.js +35 -6
  103. data/lib/dommy/media_query_list.rb +1 -0
  104. data/lib/dommy/message_channel.rb +2 -0
  105. data/lib/dommy/mutation_observer.rb +25 -29
  106. data/lib/dommy/navigator.rb +4 -1
  107. data/lib/dommy/node.rb +4 -0
  108. data/lib/dommy/notification.rb +1 -0
  109. data/lib/dommy/promise.rb +12 -0
  110. data/lib/dommy/range.rb +20 -3
  111. data/lib/dommy/shadow_root.rb +25 -1
  112. data/lib/dommy/streams.rb +18 -0
  113. data/lib/dommy/style_declaration.rb +15 -4
  114. data/lib/dommy/text_codec.rb +7 -5
  115. data/lib/dommy/tree_walker.rb +68 -61
  116. data/lib/dommy/version.rb +1 -1
  117. data/lib/dommy/web_socket.rb +1 -0
  118. data/lib/dommy/window.rb +22 -4
  119. data/lib/dommy/worker.rb +1 -0
  120. data/lib/dommy/xml_http_request.rb +12 -2
  121. data/lib/dommy.rb +17 -2
  122. metadata +11 -3
@@ -49,230 +49,217 @@ module Dommy
49
49
 
50
50
  extend NodeIdentity
51
51
 
52
- module_function
53
-
54
- # The computed role string, or "" when the element maps to no role.
55
- def compute(element)
56
- explicit_role(element) || implicit_role(element) || ""
57
- end
52
+ INPUT_ROLES = {
53
+ "button" => "button", "submit" => "button", "reset" => "button",
54
+ "image" => "button", "file" => "button", "checkbox" => "checkbox", "radio" => "radio",
55
+ "range" => "slider", "number" => "spinbutton", "email" => "textbox",
56
+ "tel" => "textbox", "text" => "textbox", "url" => "textbox", "search" => "searchbox",
57
+ # type=password has no ARIA role per HTML-AAM (to avoid exposing the
58
+ # value) but Chromium / Playwright expose it as a textbox. The
59
+ # date/time family and color likewise expose as a textbox.
60
+ "password" => "textbox", "color" => "textbox", "date" => "textbox",
61
+ "datetime-local" => "textbox", "month" => "textbox", "week" => "textbox",
62
+ "time" => "textbox"
63
+ }.freeze
58
64
 
59
- # The heading level for a heading element: an explicit positive
60
- # `aria-level`, else the `hN` tag's number, else nil. The role itself
61
- # stays "heading" (level is a separate ARIA property the a11y tree emits).
62
- def heading_level(element)
63
- aria = element.__internal_attribute_value__("aria-level").to_s
64
- return aria.to_i if aria.match?(/\A\d+\z/) && aria.to_i.positive?
65
+ class << self
66
+ # The computed role string, or "" when the element maps to no role.
67
+ def compute(element)
68
+ explicit_role(element) || implicit_role(element) || ""
69
+ end
65
70
 
66
- tag = element.local_name.to_s.downcase
67
- tag.match?(/\Ah[1-6]\z/) ? tag[1].to_i : nil
68
- end
71
+ # The heading level for a heading element: an explicit positive
72
+ # `aria-level`, else the `hN` tag's number, else nil. The role itself
73
+ # stays "heading" (level is a separate ARIA property the a11y tree emits).
74
+ def heading_level(element)
75
+ aria = element.__internal_attribute_value__("aria-level").to_s
76
+ return aria.to_i if aria.match?(/\A\d+\z/) && aria.to_i.positive?
69
77
 
70
- def explicit_role(element)
71
- raw = element.__internal_attribute_value__("role").to_s.strip
72
- return nil if raw.empty?
73
-
74
- raw.split(/\s+/).each do |token|
75
- role = SYNONYMS.fetch(token.downcase, token.downcase)
76
- next unless CONCRETE.include?(role) && !ABSTRACT.include?(role)
77
- # region / form need an author-supplied name; otherwise fall through to
78
- # the next token (or the implicit role).
79
- next if NAME_REQUIRED.include?(role) && !named?(element)
80
- # A presentational role yields to the implicit role when the element is
81
- # focusable or carries a global ARIA state/property (conflict
82
- # resolution); otherwise it stands.
83
- return nil if role == "none" && presentation_conflict?(element)
84
-
85
- return role
78
+ tag = element.local_name.to_s.downcase
79
+ tag.match?(/\Ah[1-6]\z/) ? tag[1].to_i : nil
86
80
  end
87
- nil
88
- end
89
81
 
90
- def implicit_role(element)
91
- case element.tag_name.to_s.downcase
92
- when "a", "area" then element.__internal_has_attribute__?("href") ? "link" : (element.tag_name.casecmp?("a") ? "generic" : nil)
93
- when "article" then "article"
94
- when "aside" then "complementary"
95
- when "b", "bdi", "bdo", "data", "i", "q", "samp", "small", "span", "u", "div" then "generic"
96
- when "blockquote" then "blockquote"
97
- when "button" then "button"
98
- when "caption" then "caption"
99
- when "code" then "code"
100
- when "del" then "deletion"
101
- when "dialog" then "dialog"
102
- when "dd" then "definition"
103
- when "details" then "group"
104
- when "dfn" then "term"
105
- when "dt" then "term"
106
- when "em" then "emphasis"
107
- when "fieldset" then "group"
108
- when "figure" then "figure"
109
- when "footer" then landmark_or_generic(element, "contentinfo")
110
- when "form" then named?(element) ? "form" : "generic"
111
- when "h1", "h2", "h3", "h4", "h5", "h6" then "heading"
112
- when "header" then landmark_or_generic(element, "banner")
113
- when "hr" then "separator"
114
- when "img" then img_role(element)
115
- when "input" then input_role(element)
116
- when "ins" then "insertion"
117
- when "li" then "listitem"
118
- when "main" then "main"
119
- when "mark" then "mark"
120
- when "math" then "math"
121
- when "menu", "ol", "ul" then "list"
122
- when "meter" then "meter"
123
- when "nav" then "navigation"
124
- when "optgroup" then "group"
125
- when "option" then "option"
126
- when "output" then "status"
127
- when "p" then "paragraph"
128
- when "progress" then "progressbar"
129
- when "search" then "search"
130
- when "section" then named?(element) ? "region" : "generic"
131
- when "select" then select_role(element)
132
- when "strong" then "strong"
133
- when "sub" then "subscript"
134
- when "sup" then "superscript"
135
- when "table" then "table"
136
- when "tbody", "tfoot", "thead" then "rowgroup"
137
- when "td" then "cell"
138
- when "textarea" then "textbox"
139
- when "th" then th_role(element)
140
- when "time" then "time"
141
- when "tr" then "row"
82
+ private
83
+
84
+ def explicit_role(element)
85
+ raw = element.__internal_aria_value__("role").to_s.strip
86
+ return nil if raw.empty?
87
+
88
+ raw.split(/\s+/).each do |token|
89
+ role = SYNONYMS.fetch(token.downcase, token.downcase)
90
+ next unless CONCRETE.include?(role) && !ABSTRACT.include?(role)
91
+ # region / form need an author-supplied name; otherwise fall through to
92
+ # the next token (or the implicit role).
93
+ next if NAME_REQUIRED.include?(role) && !named?(element)
94
+ # A presentational role yields to the implicit role when the element is
95
+ # focusable or carries a global ARIA state/property (conflict
96
+ # resolution); otherwise it stands.
97
+ return nil if role == "none" && presentation_conflict?(element)
98
+
99
+ return role
100
+ end
101
+ nil
142
102
  end
143
- end
144
103
 
145
- # --- helpers --------------------------------------------------------
104
+ def implicit_role(element)
105
+ case element.tag_name.to_s.downcase
106
+ when "a", "area" then element.__internal_has_attribute__?("href") ? "link" : (element.tag_name.casecmp?("a") ? "generic" : nil)
107
+ when "article" then "article"
108
+ when "aside" then "complementary"
109
+ when "b", "bdi", "bdo", "data", "i", "q", "samp", "small", "span", "u", "div" then "generic"
110
+ when "blockquote" then "blockquote"
111
+ when "button" then "button"
112
+ when "caption" then "caption"
113
+ when "code" then "code"
114
+ when "del" then "deletion"
115
+ when "dialog" then "dialog"
116
+ when "dd" then "definition"
117
+ when "details" then "group"
118
+ when "dfn" then "term"
119
+ when "dt" then "term"
120
+ when "em" then "emphasis"
121
+ when "fieldset" then "group"
122
+ when "figure" then "figure"
123
+ when "footer" then landmark_or_generic(element, "contentinfo")
124
+ when "form" then named?(element) ? "form" : "generic"
125
+ when "h1", "h2", "h3", "h4", "h5", "h6" then "heading"
126
+ when "header" then landmark_or_generic(element, "banner")
127
+ when "hr" then "separator"
128
+ when "img" then img_role(element)
129
+ when "input" then input_role(element)
130
+ when "ins" then "insertion"
131
+ when "li" then "listitem"
132
+ when "main" then "main"
133
+ when "mark" then "mark"
134
+ when "math" then "math"
135
+ when "menu", "ol", "ul" then "list"
136
+ when "meter" then "meter"
137
+ when "nav" then "navigation"
138
+ when "optgroup" then "group"
139
+ when "option" then "option"
140
+ when "output" then "status"
141
+ when "p" then "paragraph"
142
+ when "progress" then "progressbar"
143
+ when "search" then "search"
144
+ when "section" then named?(element) ? "region" : "generic"
145
+ when "select" then select_role(element)
146
+ when "strong" then "strong"
147
+ when "sub" then "subscript"
148
+ when "sup" then "superscript"
149
+ when "table" then "table"
150
+ when "tbody", "tfoot", "thead" then "rowgroup"
151
+ when "td" then "cell"
152
+ when "textarea" then "textbox"
153
+ when "th" then th_role(element)
154
+ when "time" then "time"
155
+ when "tr" then "row"
156
+ end
157
+ end
146
158
 
147
- def img_role(element)
148
- alt = element.__internal_attribute_value__("alt")
149
- # An explicitly empty alt makes the image presentational. Return the
150
- # canonical "none" (not its "presentation" synonym) so the accessibility
151
- # tree flattens it like any other presentational node.
152
- alt == "" ? "none" : "image"
153
- end
159
+ # --- helpers --------------------------------------------------------
154
160
 
155
- # A <th> is a column or row header. An explicit `scope` wins; otherwise the
156
- # auto algorithm: a header cell that borders a data cell (<td>) within its
157
- # row heads that row, so it is a row header; a header cell with only header
158
- # neighbors heads its column.
159
- def th_role(element)
160
- case element.__internal_attribute_value__("scope").to_s.downcase
161
- when "row", "rowgroup" then "rowheader"
162
- when "col", "colgroup" then "columnheader"
163
- else auto_th_role(element)
161
+ def img_role(element)
162
+ alt = element.__internal_attribute_value__("alt")
163
+ # An explicitly empty alt makes the image presentational. Return the
164
+ # canonical "none" (not its "presentation" synonym) so the accessibility
165
+ # tree flattens it like any other presentational node.
166
+ alt == "" ? "none" : "image"
164
167
  end
165
- end
166
168
 
167
- def auto_th_role(element)
168
- row = element.respond_to?(:parent_element) ? element.parent_element : nil
169
- return "columnheader" unless row
169
+ # A <th> is a column or row header. An explicit `scope` wins; otherwise the
170
+ # auto algorithm: a header cell that borders a data cell (<td>) within its
171
+ # row heads that row, so it is a row header; a header cell with only header
172
+ # neighbors heads its column.
173
+ def th_role(element)
174
+ case element.__internal_attribute_value__("scope").to_s.downcase
175
+ when "row", "rowgroup" then "rowheader"
176
+ when "col", "colgroup" then "columnheader"
177
+ else auto_th_role(element)
178
+ end
179
+ end
170
180
 
171
- cells = row.children.select { |cell| %w[td th].include?(cell.local_name.to_s.downcase) }
172
- index = cells.index { |cell| same_node?(cell, element) }
173
- return "columnheader" unless index
181
+ def auto_th_role(element)
182
+ row = element.respond_to?(:parent_element) ? element.parent_element : nil
183
+ return "columnheader" unless row
174
184
 
175
- previous = index.zero? ? nil : cells[index - 1]
176
- neighbors = [previous, cells[index + 1]].compact
177
- neighbors.any? { |cell| cell.local_name.to_s.casecmp?("td") } ? "rowheader" : "columnheader"
178
- end
185
+ cells = row.children.select { |cell| %w[td th].include?(cell.local_name.to_s.downcase) }
186
+ index = cells.index { |cell| same_node?(cell, element) }
187
+ return "columnheader" unless index
179
188
 
180
- INPUT_ROLES = {
181
- "button" => "button", "submit" => "button", "reset" => "button",
182
- "image" => "button", "file" => "button", "checkbox" => "checkbox", "radio" => "radio",
183
- "range" => "slider", "number" => "spinbutton", "email" => "textbox",
184
- "tel" => "textbox", "text" => "textbox", "url" => "textbox", "search" => "searchbox",
185
- # type=password has no ARIA role per HTML-AAM (to avoid exposing the
186
- # value) but Chromium / Playwright expose it as a textbox. The
187
- # date/time family and color likewise expose as a textbox.
188
- "password" => "textbox", "color" => "textbox", "date" => "textbox",
189
- "datetime-local" => "textbox", "month" => "textbox", "week" => "textbox",
190
- "time" => "textbox"
191
- }.freeze
189
+ previous = index.zero? ? nil : cells[index - 1]
190
+ neighbors = [previous, cells[index + 1]].compact
191
+ neighbors.any? { |cell| cell.local_name.to_s.casecmp?("td") } ? "rowheader" : "columnheader"
192
+ end
192
193
 
193
- def input_role(element)
194
- type = element.__internal_attribute_value__("type").to_s.downcase
195
- return "textbox" if type.empty?
194
+ def input_role(element)
195
+ type = element.__internal_attribute_value__("type").to_s.downcase
196
+ return "textbox" if type.empty?
196
197
 
197
- # `type=search` is `combobox` when the control has a suggestions list
198
- # and `searchbox` otherwise; INPUT_ROLES maps it to searchbox, because
199
- # Dommy has no list to consult.
200
- INPUT_ROLES[type]
201
- end
198
+ # `type=search` is `combobox` when the control has a suggestions list
199
+ # and `searchbox` otherwise; INPUT_ROLES maps it to searchbox, because
200
+ # Dommy has no list to consult.
201
+ INPUT_ROLES[type]
202
+ end
202
203
 
203
- def select_role(element)
204
- multiple = element.__internal_has_attribute__?("multiple")
205
- size = element.__internal_attribute_value__("size").to_s.to_i
206
- multiple || size > 1 ? "listbox" : "combobox"
207
- end
204
+ def select_role(element)
205
+ multiple = element.__internal_has_attribute__?("multiple")
206
+ size = element.__internal_attribute_value__("size").to_s.to_i
207
+ multiple || size > 1 ? "listbox" : "combobox"
208
+ end
208
209
 
209
- # <header>/<footer> are landmarks only when not scoped to sectioning
210
- # content; otherwise generic.
211
- def landmark_or_generic(element, landmark)
212
- node = element.__dommy_backend_node__&.parent
213
- while node
214
- return "generic" if SECTIONING.include?(node.name.to_s.downcase)
210
+ # <header>/<footer> are landmarks only when not scoped to sectioning
211
+ # content; otherwise generic.
212
+ def landmark_or_generic(element, landmark)
213
+ node = element.__dommy_backend_node__&.parent
214
+ while node
215
+ return "generic" if SECTIONING.include?(node.name.to_s.downcase)
215
216
 
216
- node = node.parent
217
+ node = node.parent
218
+ end
219
+ landmark
217
220
  end
218
- landmark
219
- end
220
221
 
221
- def named?(element)
222
- return true if present?(element.__internal_attribute_value__("aria-label"))
223
- return true if references?(element, "aria-labelledby")
222
+ def named?(element)
223
+ return true if present?(element.__internal_aria_value__("aria-label"))
224
+ return true if references?(element, "aria-labelledby")
224
225
 
225
- present?(element.__internal_attribute_value__("title"))
226
- end
226
+ present?(element.__internal_attribute_value__("title"))
227
+ end
227
228
 
228
- def present?(value)
229
- !value.nil? && !value.to_s.empty?
230
- end
229
+ def present?(value)
230
+ !value.nil? && !value.to_s.empty?
231
+ end
231
232
 
232
- # Whether an element-list attribute says something: a value, or the
233
- # elements set through its reflection (which leave the value "").
234
- def references?(element, attribute)
235
- present?(element.__internal_attribute_value__(attribute)) ||
236
- !element.__internal_aria_associated_elements__(attribute).to_a.empty?
237
- end
233
+ # Whether an element-list attribute says something: a value, or the
234
+ # elements set through its reflection (which leave the value "").
235
+ def references?(element, attribute)
236
+ present?(element.__internal_attribute_value__(attribute)) ||
237
+ !element.__internal_aria_associated_elements__(attribute).to_a.empty?
238
+ end
238
239
 
239
- # Presentation conflict resolution (simplified): a focusable element or one
240
- # with a global ARIA attribute keeps its implicit role.
241
- def presentation_conflict?(element)
242
- return true if focusable?(element)
240
+ # Presentation conflict resolution (simplified): a focusable element or one
241
+ # with a global ARIA attribute keeps its implicit role.
242
+ def presentation_conflict?(element)
243
+ return true if focusable?(element)
243
244
 
244
- present?(element.__internal_attribute_value__("aria-label")) ||
245
- %w[aria-labelledby aria-describedby].any? { |a| references?(element, a) }
246
- end
245
+ present?(element.__internal_aria_value__("aria-label")) ||
246
+ %w[aria-labelledby aria-describedby].any? { |a| references?(element, a) }
247
+ end
247
248
 
248
- # Whether the element is focusable — a tabindex, or a natively-focusable
249
- # control (a/area with href, or a non-disabled form control). Native
250
- # focusability matters: <a href role=presentation> is still a link.
251
- def focusable?(element)
252
- return true if present?(element.__internal_attribute_value__("tabindex"))
253
-
254
- case element.local_name.to_s.downcase
255
- when "a", "area" then element.__internal_has_attribute__?("href")
256
- when "button", "select", "textarea" then !element.__internal_has_attribute__?("disabled")
257
- when "input" then element.__internal_attribute_value__("type").to_s.downcase != "hidden" && !element.__internal_has_attribute__?("disabled")
258
- else false
249
+ # Whether the element is focusable — a tabindex, or a natively-focusable
250
+ # control (a/area with href, or a non-disabled form control). Native
251
+ # focusability matters: <a href role=presentation> is still a link.
252
+ def focusable?(element)
253
+ return true if present?(element.__internal_attribute_value__("tabindex"))
254
+
255
+ case element.local_name.to_s.downcase
256
+ when "a", "area" then element.__internal_has_attribute__?("href")
257
+ when "button", "select", "textarea" then !element.__internal_has_attribute__?("disabled")
258
+ when "input" then element.__internal_attribute_value__("type").to_s.downcase != "hidden" && !element.__internal_has_attribute__?("disabled")
259
+ else false
260
+ end
259
261
  end
260
262
  end
261
-
262
- # Everything below compute is how it is computed, not API.
263
- private_class_method :explicit_role
264
- private_class_method :implicit_role
265
- private_class_method :img_role
266
- private_class_method :th_role
267
- private_class_method :auto_th_role
268
- private_class_method :input_role
269
- private_class_method :select_role
270
- private_class_method :landmark_or_generic
271
- private_class_method :named?
272
- private_class_method :present?
273
- private_class_method :references?
274
- private_class_method :presentation_conflict?
275
- private_class_method :focusable?
276
263
  end
277
264
  end
278
265
  end
@@ -17,53 +17,50 @@ module Dommy
17
17
  # neither in its snapshot — so they stay out of this list.
18
18
  FLAG_ORDER = %i[checked disabled expanded level pressed selected].freeze
19
19
 
20
- module_function
20
+ class << self
21
+ def serialize(root)
22
+ lines = []
23
+ root.children.each { |child| emit(child, 0, lines) }
24
+ return "" if lines.empty?
21
25
 
22
- def serialize(root)
23
- lines = []
24
- root.children.each { |child| emit(child, 0, lines) }
25
- return "" if lines.empty?
26
+ "#{lines.join("\n")}\n"
27
+ end
26
28
 
27
- "#{lines.join("\n")}\n"
28
- end
29
+ private
29
30
 
30
- def emit(node, depth, lines)
31
- indent = " " * depth
32
- if node.text?
33
- lines << "#{indent}- text: #{quote(node.name)}"
34
- return
35
- end
31
+ def emit(node, depth, lines)
32
+ indent = " " * depth
33
+ if node.text?
34
+ lines << "#{indent}- text: #{quote(node.name)}"
35
+ return
36
+ end
36
37
 
37
- header = "#{indent}- #{node.role}"
38
- header += " #{quote(node.name)}" unless node.name.to_s.empty?
39
- flags(node.states).each { |flag| header += " #{flag}" }
40
- header += ":" unless node.children.empty?
41
- lines << header
38
+ header = "#{indent}- #{node.role}"
39
+ header += " #{quote(node.name)}" unless node.name.to_s.empty?
40
+ flags(node.states).each { |flag| header += " #{flag}" }
41
+ header += ":" unless node.children.empty?
42
+ lines << header
42
43
 
43
- node.children.each { |child| emit(child, depth + 1, lines) }
44
- end
44
+ node.children.each { |child| emit(child, depth + 1, lines) }
45
+ end
45
46
 
46
- # The bracketed flag tokens for a node's states, in FLAG_ORDER. Booleans
47
- # render only when true/"mixed"; a "mixed" value renders `[flag=mixed]`.
48
- def flags(states)
49
- FLAG_ORDER.filter_map do |key|
50
- value = states[key]
51
- if key == :level
52
- "[level=#{value}]" if value
53
- elsif value == "mixed"
54
- "[#{key}=mixed]"
55
- elsif value == true
56
- "[#{key}]"
47
+ # The bracketed flag tokens for a node's states, in FLAG_ORDER. Booleans
48
+ # render only when true/"mixed"; a "mixed" value renders `[flag=mixed]`.
49
+ def flags(states)
50
+ FLAG_ORDER.filter_map do |key|
51
+ value = states[key]
52
+ if key == :level
53
+ "[level=#{value}]" if value
54
+ elsif value == "mixed"
55
+ "[#{key}=mixed]"
56
+ elsif value == true
57
+ "[#{key}]"
58
+ end
57
59
  end
58
60
  end
59
- end
60
61
 
61
- def quote(text) = "\"#{text.to_s.gsub("\\", "\\\\\\\\").gsub("\"", "\\\"")}\""
62
-
63
- # Everything below compute is how it is computed, not API.
64
- private_class_method :emit
65
- private_class_method :flags
66
- private_class_method :quote
62
+ def quote(text) = "\"#{text.to_s.gsub("\\", "\\\\\\\\").gsub("\"", "\\\"")}\""
63
+ end
67
64
  end
68
65
  end
69
66
  end