001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import static org.apache.juneau.html.annotation.HtmlFormat.*;
020import static org.apache.juneau.internal.CollectionUtils.*;
021import static org.apache.juneau.xml.annotation.XmlFormat.*;
022
023import java.net.*;
024
025import org.apache.juneau.common.utils.*;
026import org.apache.juneau.*;
027import org.apache.juneau.annotation.*;
028import org.apache.juneau.html.*;
029import org.apache.juneau.internal.*;
030import org.apache.juneau.xml.annotation.*;
031
032/**
033 * Superclass for all HTML elements.
034 *
035 * <p>
036 * These are beans that when serialized using {@link HtmlSerializer} generate valid HTML5 elements.
037 *
038 * <h5 class='section'>See Also:</h5><ul>
039 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
040
041 * </ul>
042 */
043@org.apache.juneau.html.annotation.Html(format=XML)
044public abstract class HtmlElement {
045
046   private java.util.Map<String,Object> attrs;
047
048   /**
049    * The attributes of this element.
050    *
051    * @return The attributes of this element.
052    */
053   @Xml(format=ATTRS)
054   @Beanp("a")
055   public java.util.Map<String,Object> getAttrs() {
056      return attrs;
057   }
058
059   /**
060    * Sets the attributes for this element.
061    *
062    * @param attrs The new attributes for this element.
063    * @return This object.
064    */
065   @Beanp("a")
066   public HtmlElement setAttrs(java.util.Map<String,Object> attrs) {
067      if (attrs != null) {
068         attrs.entrySet().forEach(x -> {
069            var key = x.getKey();
070            if ("url".equals(key) || "href".equals(key) || key.endsWith("action"))
071               x.setValue(StringUtils.toURI(x.getValue()));
072         });
073      }
074      this.attrs = attrs;
075      return this;
076   }
077
078   /**
079    * Adds an arbitrary attribute to this element.
080    *
081    * @param key The attribute name.
082    * @param val The attribute value.
083    * @return This object.
084    */
085   public HtmlElement attr(String key, Object val) {
086      if (attrs == null)
087         attrs = map();
088      if (val == null)
089         attrs.remove(key);
090      else {
091         if ("url".equals(key) || "href".equals(key) || key.endsWith("action"))
092            val = StringUtils.toURI(val);
093         attrs.put(key, val);
094      }
095      return this;
096   }
097
098   /**
099    * Adds an arbitrary URI attribute to this element.
100    *
101    * <p>
102    * Same as {@link #attr(String, Object)}, except if the value is a string that appears to be a URI
103    * (e.g. <js>"servlet:/xxx"</js>).
104    *
105    * <p>
106    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
107    * Strings must be valid URIs.
108    *
109    * <p>
110    * URIs defined by {@link UriResolver} can be used for values.
111    *
112    * @param key The attribute name.
113    * @param val The attribute value.
114    * @return This object.
115    */
116   public HtmlElement attrUri(String key, Object val) {
117      if (attrs == null)
118         attrs = map();
119      attrs.put(key, StringUtils.toURI(val));
120      return this;
121   }
122
123   /**
124    * Returns the attribute with the specified name.
125    *
126    * @param key The attribute name.
127    * @return The attribute value, or <jk>null</jk> if the named attribute does not exist.
128    */
129   public String getAttr(String key) {
130      return getAttr(String.class, key);
131   }
132
133   /**
134    * Returns the attribute with the specified name converted to the specified class type.
135    *
136    * @param <T> The class type to convert this class to.
137    * @param type
138    *    The class type to convert this class to.
139    *    See {@link ConverterUtils} for a list of supported conversion types.
140    * @param key The attribute name.
141    * @return The attribute value, or <jk>null</jk> if the named attribute does not exist.
142    */
143   public <T> T getAttr(Class<T> type, String key) {
144      return attrs == null ? null : ConverterUtils.toType(attrs.get(key), type);
145   }
146
147   /**
148    * <a class="doclink" href="https://www.w3.org/TR/html5/editing.html#the-accesskey-attribute">accesskey</a>
149    * attribute.
150    *
151    * <p>
152    * Defines a keyboard shortcut to activate or focus an element.
153    * The value should be a single character that, when pressed with a modifier key (usually Alt),
154    * activates the element.
155    *
156    * @param accesskey The keyboard shortcut character (e.g., <js>"a"</js>, <js>"1"</js>).
157    * @return This object.
158    */
159   public HtmlElement accesskey(String value) {
160      attr("accesskey", value);
161      return this;
162   }
163
164   /**
165    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#classes">class</a> attribute.
166    *
167    * <p>
168    * Specifies one or more CSS class names for the element, separated by spaces.
169    * These classes can be used for styling and JavaScript selection.
170    *
171    * @param _class Space-separated CSS class names (e.g., <js>"btn btn-primary"</js>).
172    * @return This object.
173    */
174   public HtmlElement _class(String value) {  // NOSONAR - Intentional naming.
175      attr("class", value);
176      return this;
177   }
178
179   /**
180    * <a class="doclink" href="https://www.w3.org/TR/html5/editing.html#attr-contenteditable">contenteditable</a>
181    * attribute.
182    *
183    * <p>
184    * Indicates whether the element's content is editable by the user.
185    *
186    * <p>
187    * Possible values:
188    * <ul>
189    *    <li><js>"true"</js> or empty string - Element content is editable</li>
190    *    <li><js>"false"</js> - Element content is not editable</li>
191    *    <li><js>"plaintext-only"</js> - Element content is editable, but rich text formatting is disabled</li>
192    * </ul>
193    *
194    * @param contenteditable The editability state of the element.
195    * @return This object.
196    */
197   public HtmlElement contenteditable(Object value) {
198      attr("contenteditable", value);
199      return this;
200   }
201
202   /**
203    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#the-dir-attribute">dir</a> attribute.
204    *
205    * <p>
206    * Specifies the text direction of the element's content.
207    *
208    * <p>
209    * Possible values:
210    * <ul>
211    *    <li><js>"ltr"</js> - Left-to-right text direction</li>
212    *    <li><js>"rtl"</js> - Right-to-left text direction</li>
213    *    <li><js>"auto"</js> - Browser determines direction based on content</li>
214    * </ul>
215    *
216    * @param dir The text direction for the element.
217    * @return This object.
218    */
219   public HtmlElement dir(String value) {
220      attr("dir", value);
221      return this;
222   }
223
224   /**
225    * <a class="doclink" href="https://www.w3.org/TR/html5/editing.html#the-hidden-attribute">hidden</a> attribute.
226    *
227    * <p>
228    * This attribute uses deminimized values:
229    * <ul>
230    *    <li><jk>false</jk> - Attribute is not added</li>
231    *    <li><jk>true</jk> - Attribute is added as <js>"hidden"</js></li>
232    *    <li>Other values - Passed through as-is</li>
233    * </ul>
234    *
235    * @param hidden
236    *    The new value for this attribute.
237    *    Typically a {@link Boolean} or {@link String}.
238    * @return This object.
239    */
240   public HtmlElement hidden(Object value) {
241      attr("hidden", deminimize(value, "hidden"));
242      return this;
243   }
244
245   /**
246    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#the-id-attribute">id</a> attribute.
247    *
248    * <p>
249    * Specifies a unique identifier for the element. The ID must be unique within the document
250    * and can be used for CSS styling, JavaScript selection, and anchor links.
251    *
252    * @param id A unique identifier for the element (e.g., <js>"header"</js>, <js>"main-content"</js>).
253    * @return This object.
254    */
255   public HtmlElement id(String value) {
256      attr("id", value);
257      return this;
258   }
259
260   /**
261    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#attr-lang">lang</a> attribute.
262    *
263    * <p>
264    * Specifies the primary language of the element's content using a language tag.
265    * This helps with accessibility, search engines, and browser features like spell checking.
266    *
267    * @param lang A language tag (e.g., <js>"en"</js>, <js>"en-US"</js>, <js>"es"</js>, <js>"fr-CA"</js>).
268    * @return This object.
269    */
270   public HtmlElement lang(String value) {
271      attr("lang", value);
272      return this;
273   }
274
275   /**
276    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onabort">onabort</a> attribute.
277    *
278    * <p>
279    * Event handler for when an operation is aborted (e.g., image loading is cancelled).
280    *
281    * @param onabort JavaScript code to execute when the abort event occurs.
282    * @return This object.
283    */
284   public HtmlElement onabort(String value) {
285      attr("onabort", value);
286      return this;
287   }
288
289   /**
290    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onblur">onblur</a> attribute.
291    *
292    * <p>
293    * Event handler for when the element loses focus.
294    *
295    * <h5 class='section'>Note:</h5>
296    * <p>
297    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
298    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
299    * For example:
300    * <ul>
301    *    <li>If using single quotes for attributes: <c>onblur(<js>"validate(\"email\")"</js>)</c>
302    *    <li>If using double quotes for attributes: <c>onblur(<js>"validate('email')"</js>)</c>
303    * </ul>
304    *
305    * @param onblur JavaScript code to execute when the element loses focus.
306    * @return This object.
307    */
308   public HtmlElement onblur(String value) {
309      attr("onblur", value);
310      return this;
311   }
312
313   /**
314    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oncancel">oncancel</a> attribute.
315    *
316    * <p>
317    * Event handler for when a dialog is cancelled.
318    *
319    * @param oncancel JavaScript code to execute when the cancel event occurs.
320    * @return This object.
321    */
322   public HtmlElement oncancel(String value) {
323      attr("oncancel", value);
324      return this;
325   }
326
327   /**
328    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oncanplay">oncanplay</a> attribute.
329    *
330    * <p>
331    * Event handler for when the media can start playing (enough data has been buffered).
332    *
333    * @param oncanplay JavaScript code to execute when the canplay event occurs.
334    * @return This object.
335    */
336   public HtmlElement oncanplay(String value) {
337      attr("oncanplay", value);
338      return this;
339   }
340
341   /**
342    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oncanplaythrough">oncanplaythrough</a>
343    * attribute.
344    *
345    * <p>
346    * Event handler for when the media can play through to the end without buffering.
347    *
348    * @param oncanplaythrough JavaScript code to execute when the canplaythrough event occurs.
349    * @return This object.
350    */
351   public HtmlElement oncanplaythrough(String value) {
352      attr("oncanplaythrough", value);
353      return this;
354   }
355
356   /**
357    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onchange">onchange</a> attribute.
358    *
359    * <p>
360    * Event handler for when the value of a form element changes and loses focus.
361    *
362    * <h5 class='section'>Note:</h5>
363    * <p>
364    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
365    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
366    * For example:
367    * <ul>
368    *    <li>If using single quotes for attributes: <c>onchange(<js>"validate(\"field\")"</js>)</c>
369    *    <li>If using double quotes for attributes: <c>onchange(<js>"validate('field')"</js>)</c>
370    * </ul>
371    *
372    * @param onchange JavaScript code to execute when the change event occurs.
373    * @return This object.
374    */
375   public HtmlElement onchange(String value) {
376      attr("onchange", value);
377      return this;
378   }
379
380   /**
381    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onclick">onclick</a> attribute.
382    *
383    * <p>
384    * Event handler for when the element is clicked.
385    *
386    * <h5 class='section'>Note:</h5>
387    * <p>
388    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
389    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
390    * For example:
391    * <ul>
392    *    <li>If using single quotes for attributes: <c>onclick(<js>"alert(\"Hello\")"</js>)</c>
393    *    <li>If using double quotes for attributes: <c>onclick(<js>"alert('Hello')"</js>)</c>
394    * </ul>
395    *
396    * @param onclick JavaScript code to execute when the click event occurs.
397    * @return This object.
398    */
399   public HtmlElement onclick(String value) {
400      attr("onclick", value);
401      return this;
402   }
403
404   /**
405    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oncuechange">oncuechange</a>
406    * attribute.
407    *
408    * <p>
409    * Event handler for when a text track cue changes.
410    *
411    * @param oncuechange JavaScript code to execute when the cuechange event occurs.
412    * @return This object.
413    */
414   public HtmlElement oncuechange(String value) {
415      attr("oncuechange", value);
416      return this;
417   }
418
419   /**
420    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-ondblclick">ondblclick</a> attribute.
421    *
422    * <p>
423    * Event handler for when the element is double-clicked.
424    *
425    * @param ondblclick JavaScript code to execute when the dblclick event occurs.
426    * @return This object.
427    */
428   public HtmlElement ondblclick(String value) {
429      attr("ondblclick", value);
430      return this;
431   }
432
433   /**
434    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-ondurationchange">ondurationchange</a>
435    * attribute.
436    *
437    * <p>
438    * Event handler for when the duration of the media changes.
439    *
440    * @param ondurationchange JavaScript code to execute when the durationchange event occurs.
441    * @return This object.
442    */
443   public HtmlElement ondurationchange(String value) {
444      attr("ondurationchange", value);
445      return this;
446   }
447
448   /**
449    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onemptied">onemptied</a> attribute.
450    *
451    * <p>
452    * Event handler for when the media element becomes empty (e.g., network error).
453    *
454    * @param onemptied JavaScript code to execute when the emptied event occurs.
455    * @return This object.
456    */
457   public HtmlElement onemptied(String value) {
458      attr("onemptied", value);
459      return this;
460   }
461
462   /**
463    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onended">onended</a> attribute.
464    *
465    * <p>
466    * Event handler for when the media playback reaches the end.
467    *
468    * @param onended JavaScript code to execute when the ended event occurs.
469    * @return This object.
470    */
471   public HtmlElement onended(String value) {
472      attr("onended", value);
473      return this;
474   }
475
476   /**
477    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onerror">onerror</a> attribute.
478    *
479    * <p>
480    * Event handler for when an error occurs (e.g., failed resource loading).
481    *
482    * @param onerror JavaScript code to execute when the error event occurs.
483    * @return This object.
484    */
485   public HtmlElement onerror(String value) {
486      attr("onerror", value);
487      return this;
488   }
489
490   /**
491    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onfocus">onfocus</a> attribute.
492    *
493    * <p>
494    * Event handler for when the element receives focus.
495    *
496    * <h5 class='section'>Note:</h5>
497    * <p>
498    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
499    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
500    * For example:
501    * <ul>
502    *    <li>If using single quotes for attributes: <c>onfocus(<js>"highlight(\"field\")"</js>)</c>
503    *    <li>If using double quotes for attributes: <c>onfocus(<js>"highlight('field')"</js>)</c>
504    * </ul>
505    *
506    * @param onfocus JavaScript code to execute when the focus event occurs.
507    * @return This object.
508    */
509   public HtmlElement onfocus(String value) {
510      attr("onfocus", value);
511      return this;
512   }
513
514   /**
515    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oninput">oninput</a> attribute.
516    *
517    * <p>
518    * Event handler for when the value of an input element changes (fires on every keystroke).
519    *
520    * @param oninput JavaScript code to execute when the input event occurs.
521    * @return This object.
522    */
523   public HtmlElement oninput(String value) {
524      attr("oninput", value);
525      return this;
526   }
527
528   /**
529    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-oninvalid">oninvalid</a> attribute.
530    *
531    * <p>
532    * Event handler for when form validation fails.
533    *
534    * @param oninvalid JavaScript code to execute when the invalid event occurs.
535    * @return This object.
536    */
537   public HtmlElement oninvalid(String value) {
538      attr("oninvalid", value);
539      return this;
540   }
541
542   /**
543    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onkeydown">onkeydown</a> attribute.
544    *
545    * <p>
546    * Event handler for when a key is pressed down.
547    *
548    * @param onkeydown JavaScript code to execute when the keydown event occurs.
549    * @return This object.
550    */
551   public HtmlElement onkeydown(String value) {
552      attr("onkeydown", value);
553      return this;
554   }
555
556   /**
557    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onkeypress">onkeypress</a> attribute.
558    *
559    * <p>
560    * Event handler for when a key is pressed (deprecated, use onkeydown instead).
561    *
562    * @param onkeypress JavaScript code to execute when the keypress event occurs.
563    * @return This object.
564    */
565   public HtmlElement onkeypress(String value) {
566      attr("onkeypress", value);
567      return this;
568   }
569
570   /**
571    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onkeyup">onkeyup</a> attribute.
572    *
573    * <p>
574    * Event handler for when a key is released.
575    *
576    * @param onkeyup JavaScript code to execute when the keyup event occurs.
577    * @return This object.
578    */
579   public HtmlElement onkeyup(String value) {
580      attr("onkeyup", value);
581      return this;
582   }
583
584   /**
585    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onload">onload</a> attribute.
586    *
587    * <p>
588    * Event handler for when the element and its resources have finished loading.
589    *
590    * <h5 class='section'>Note:</h5>
591    * <p>
592    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
593    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
594    * For example:
595    * <ul>
596    *    <li>If using single quotes for attributes: <c>onload(<js>"init(\"config\")"</js>)</c>
597    *    <li>If using double quotes for attributes: <c>onload(<js>"init('config')"</js>)</c>
598    * </ul>
599    *
600    * @param onload JavaScript code to execute when the load event occurs.
601    * @return This object.
602    */
603   public HtmlElement onload(String value) {
604      attr("onload", value);
605      return this;
606   }
607
608   /**
609    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onloadeddata">onloadeddata</a>
610    * attribute.
611    *
612    * <p>
613    * Event handler for when the first frame of media has finished loading.
614    *
615    * @param onloadeddata JavaScript code to execute when the loadeddata event occurs.
616    * @return This object.
617    */
618   public HtmlElement onloadeddata(String value) {
619      attr("onloadeddata", value);
620      return this;
621   }
622
623   /**
624    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onloadedmetadata">onloadedmetadata</a>
625    * attribute.
626    *
627    * <p>
628    * Event handler for when metadata (duration, dimensions, etc.) has been loaded.
629    *
630    * @param onloadedmetadata JavaScript code to execute when the loadedmetadata event occurs.
631    * @return This object.
632    */
633   public HtmlElement onloadedmetadata(String value) {
634      attr("onloadedmetadata", value);
635      return this;
636   }
637
638   /**
639    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onloadstart">onloadstart</a>
640    * attribute.
641    *
642    * <p>
643    * Event handler for when the browser starts loading the media.
644    *
645    * @param onloadstart JavaScript code to execute when the loadstart event occurs.
646    * @return This object.
647    */
648   public HtmlElement onloadstart(String value) {
649      attr("onloadstart", value);
650      return this;
651   }
652
653   /**
654    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmousedown">onmousedown</a>
655    * attribute.
656    *
657    * <p>
658    * Event handler for when a mouse button is pressed down on the element.
659    *
660    * @param onmousedown JavaScript code to execute when the mousedown event occurs.
661    * @return This object.
662    */
663   public HtmlElement onmousedown(String value) {
664      attr("onmousedown", value);
665      return this;
666   }
667
668   /**
669    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmouseenter">onmouseenter</a> attribute.
670    *
671    * <p>
672    * Event handler for when the mouse pointer enters the element (does not bubble).
673    *
674    * @param onmouseenter JavaScript code to execute when the mouseenter event occurs.
675    * @return This object.
676    */
677   public HtmlElement onmouseenter(String value) {
678      attr("onmouseenter", value);
679      return this;
680   }
681
682   /**
683    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmouseleave">onmouseleave</a>
684    * attribute.
685    *
686    * <p>
687    * Event handler for when the mouse pointer leaves the element (does not bubble).
688    *
689    * @param onmouseleave JavaScript code to execute when the mouseleave event occurs.
690    * @return This object.
691    */
692   public HtmlElement onmouseleave(String value) {
693      attr("onmouseleave", value);
694      return this;
695   }
696
697   /**
698    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmousemove">onmousemove</a>
699    * attribute.
700    *
701    * <p>
702    * Event handler for when the mouse pointer moves over the element.
703    *
704    * @param onmousemove JavaScript code to execute when the mousemove event occurs.
705    * @return This object.
706    */
707   public HtmlElement onmousemove(String value) {
708      attr("onmousemove", value);
709      return this;
710   }
711
712   /**
713    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmouseout">onmouseout</a> attribute.
714    *
715    * <p>
716    * Event handler for when the mouse pointer moves out of the element (bubbles).
717    *
718    * @param onmouseout JavaScript code to execute when the mouseout event occurs.
719    * @return This object.
720    */
721   public HtmlElement onmouseout(String value) {
722      attr("onmouseout", value);
723      return this;
724   }
725
726   /**
727    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmouseover">onmouseover</a>
728    * attribute.
729    *
730    * <p>
731    * Event handler for when the mouse pointer moves over the element (bubbles).
732    *
733    * <h5 class='section'>Note:</h5>
734    * <p>
735    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
736    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
737    * For example:
738    * <ul>
739    *    <li>If using single quotes for attributes: <c>onmouseover(<js>"showTooltip(\"info\")"</js>)</c>
740    *    <li>If using double quotes for attributes: <c>onmouseover(<js>"showTooltip('info')"</js>)</c>
741    * </ul>
742    *
743    * @param onmouseover JavaScript code to execute when the mouseover event occurs.
744    * @return This object.
745    */
746   public HtmlElement onmouseover(String value) {
747      attr("onmouseover", value);
748      return this;
749   }
750
751   /**
752    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmouseup">onmouseup</a> attribute.
753    *
754    * <p>
755    * Event handler for when a mouse button is released over the element.
756    *
757    * @param onmouseup JavaScript code to execute when the mouseup event occurs.
758    * @return This object.
759    */
760   public HtmlElement onmouseup(String value) {
761      attr("onmouseup", value);
762      return this;
763   }
764
765   /**
766    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onmousewheel">onmousewheel</a>
767    * attribute.
768    *
769    * <p>
770    * Event handler for when the mouse wheel is rotated over the element (deprecated, use onwheel).
771    *
772    * @param onmousewheel JavaScript code to execute when the mousewheel event occurs.
773    * @return This object.
774    */
775   public HtmlElement onmousewheel(String value) {
776      attr("onmousewheel", value);
777      return this;
778   }
779
780   /**
781    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onpause">onpause</a> attribute.
782    *
783    * <p>
784    * Event handler for when media playback is paused.
785    *
786    * @param onpause JavaScript code to execute when the pause event occurs.
787    * @return This object.
788    */
789   public HtmlElement onpause(String value) {
790      attr("onpause", value);
791      return this;
792   }
793
794   /**
795    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onplay">onplay</a> attribute.
796    *
797    * <p>
798    * Event handler for when media playback starts.
799    *
800    * @param onplay JavaScript code to execute when the play event occurs.
801    * @return This object.
802    */
803   public HtmlElement onplay(String value) {
804      attr("onplay", value);
805      return this;
806   }
807
808   /**
809    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onplaying">onplaying</a> attribute.
810    *
811    * <p>
812    * Event handler for when media playback starts after being paused or delayed.
813    *
814    * @param onplaying JavaScript code to execute when the playing event occurs.
815    * @return This object.
816    */
817   public HtmlElement onplaying(String value) {
818      attr("onplaying", value);
819      return this;
820   }
821
822   /**
823    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onprogress">onprogress</a> attribute.
824    *
825    * <p>
826    * Event handler for when the browser is downloading media data.
827    *
828    * @param onprogress JavaScript code to execute when the progress event occurs.
829    * @return This object.
830    */
831   public HtmlElement onprogress(String value) {
832      attr("onprogress", value);
833      return this;
834   }
835
836   /**
837    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onratechange">onratechange</a>
838    * attribute.
839    *
840    * <p>
841    * Event handler for when the playback rate of media changes.
842    *
843    * @param onratechange JavaScript code to execute when the ratechange event occurs.
844    * @return This object.
845    */
846   public HtmlElement onratechange(String value) {
847      attr("onratechange", value);
848      return this;
849   }
850
851   /**
852    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onreset">onreset</a> attribute.
853    *
854    * <p>
855    * Event handler for when a form is reset.
856    *
857    * @param onreset JavaScript code to execute when the reset event occurs.
858    * @return This object.
859    */
860   public HtmlElement onreset(String value) {
861      attr("onreset", value);
862      return this;
863   }
864
865   /**
866    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onresize">onresize</a> attribute.
867    *
868    * <p>
869    * Event handler for when the element is resized.
870    *
871    * @param onresize JavaScript code to execute when the resize event occurs.
872    * @return This object.
873    */
874   public HtmlElement onresize(String value) {
875      attr("onresize", value);
876      return this;
877   }
878
879   /**
880    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onscroll">onscroll</a> attribute.
881    *
882    * <p>
883    * Event handler for when the element's scrollbar is scrolled.
884    *
885    * @param onscroll JavaScript code to execute when the scroll event occurs.
886    * @return This object.
887    */
888   public HtmlElement onscroll(String value) {
889      attr("onscroll", value);
890      return this;
891   }
892
893   /**
894    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onseeked">onseeked</a> attribute.
895    *
896    * <p>
897    * Event handler for when a seek operation completes.
898    *
899    * @param onseeked JavaScript code to execute when the seeked event occurs.
900    * @return This object.
901    */
902   public HtmlElement onseeked(String value) {
903      attr("onseeked", value);
904      return this;
905   }
906
907   /**
908    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onseeking">onseeking</a> attribute.
909    *
910    * <p>
911    * Event handler for when a seek operation begins.
912    *
913    * @param onseeking JavaScript code to execute when the seeking event occurs.
914    * @return This object.
915    */
916   public HtmlElement onseeking(String value) {
917      attr("onseeking", value);
918      return this;
919   }
920
921   /**
922    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onselect">onselect</a> attribute.
923    *
924    * <p>
925    * Event handler for when text is selected in the element.
926    *
927    * @param onselect JavaScript code to execute when the select event occurs.
928    * @return This object.
929    */
930   public HtmlElement onselect(String value) {
931      attr("onselect", value);
932      return this;
933   }
934
935   /**
936    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onshow">onshow</a> attribute.
937    *
938    * <p>
939    * Event handler for when a context menu is shown.
940    *
941    * @param onshow JavaScript code to execute when the show event occurs.
942    * @return This object.
943    */
944   public HtmlElement onshow(String value) {
945      attr("onshow", value);
946      return this;
947   }
948
949   /**
950    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onstalled">onstalled</a> attribute.
951    *
952    * <p>
953    * Event handler for when media loading is stalled.
954    *
955    * @param onstalled JavaScript code to execute when the stalled event occurs.
956    * @return This object.
957    */
958   public HtmlElement onstalled(String value) {
959      attr("onstalled", value);
960      return this;
961   }
962
963   /**
964    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onsubmit">onsubmit</a> attribute.
965    *
966    * <p>
967    * Event handler for when a form is submitted.
968    *
969    * <h5 class='section'>Note:</h5>
970    * <p>
971    * If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes
972    * in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities.
973    * For example:
974    * <ul>
975    *    <li>If using single quotes for attributes: <c>onsubmit(<js>"return validate(\"form\")"</js>)</c>
976    *    <li>If using double quotes for attributes: <c>onsubmit(<js>"return validate('form')"</js>)</c>
977    * </ul>
978    *
979    * @param onsubmit JavaScript code to execute when the submit event occurs.
980    * @return This object.
981    */
982   public HtmlElement onsubmit(String value) {
983      attr("onsubmit", value);
984      return this;
985   }
986
987   /**
988    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onsuspend">onsuspend</a> attribute.
989    *
990    * <p>
991    * Event handler for when media loading is suspended.
992    *
993    * @param onsuspend JavaScript code to execute when the suspend event occurs.
994    * @return This object.
995    */
996   public HtmlElement onsuspend(String value) {
997      attr("onsuspend", value);
998      return this;
999   }
1000
1001   /**
1002    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-ontimeupdate">ontimeupdate</a>
1003    * attribute.
1004    *
1005    * <p>
1006    * Event handler for when the current playback position changes.
1007    *
1008    * @param ontimeupdate JavaScript code to execute when the timeupdate event occurs.
1009    * @return This object.
1010    */
1011   public HtmlElement ontimeupdate(String value) {
1012      attr("ontimeupdate", value);
1013      return this;
1014   }
1015
1016   /**
1017    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-ontoggle">ontoggle</a> attribute.
1018    *
1019    * <p>
1020    * Event handler for when a details element is opened or closed.
1021    *
1022    * @param ontoggle JavaScript code to execute when the toggle event occurs.
1023    * @return This object.
1024    */
1025   public HtmlElement ontoggle(String value) {
1026      attr("ontoggle", value);
1027      return this;
1028   }
1029
1030   /**
1031    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onvolumechange">onvolumechange</a>
1032    * attribute.
1033    *
1034    * <p>
1035    * Event handler for when the volume of media changes.
1036    *
1037    * @param onvolumechange JavaScript code to execute when the volumechange event occurs.
1038    * @return This object.
1039    */
1040   public HtmlElement onvolumechange(String value) {
1041      attr("onvolumechange", value);
1042      return this;
1043   }
1044
1045   /**
1046    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-onwaiting">onwaiting</a> attribute.
1047    *
1048    * <p>
1049    * Event handler for when media playback stops to buffer more data.
1050    *
1051    * @param onwaiting JavaScript code to execute when the waiting event occurs.
1052    * @return This object.
1053    */
1054   public HtmlElement onwaiting(String value) {
1055      attr("onwaiting", value);
1056      return this;
1057   }
1058
1059   /**
1060    * <a class="doclink" href="https://www.w3.org/TR/html5/editing.html#attr-spellcheck">spellcheck</a> attribute.
1061    *
1062    * <p>
1063    * Indicates whether the element should have its spelling and grammar checked.
1064    *
1065    * <p>
1066    * Possible values:
1067    * <ul>
1068    *    <li><js>"true"</js> - Enable spell checking for this element</li>
1069    *    <li><js>"false"</js> - Disable spell checking for this element</li>
1070    * </ul>
1071    *
1072    * @param spellcheck Whether spell checking should be enabled.
1073    * @return This object.
1074    */
1075   public HtmlElement spellcheck(Object value) {
1076      attr("spellcheck", value);
1077      return this;
1078   }
1079
1080   /**
1081    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#the-style-attribute">style</a> attribute.
1082    *
1083    * <p>
1084    * Specifies inline CSS styles for the element. The value should be valid CSS
1085    * property-value pairs separated by semicolons.
1086    *
1087    * @param style Inline CSS styles (e.g., <js>"color: red; font-size: 14px;"</js>).
1088    * @return This object.
1089    */
1090   public HtmlElement style(String value) {
1091      attr("style", value);
1092      return this;
1093   }
1094
1095   /**
1096    * <a class="doclink" href="https://www.w3.org/TR/html5/editing.html#attr-tabindex">tabindex</a> attribute.
1097    *
1098    * <p>
1099    * Specifies the tab order of the element when navigating with the keyboard.
1100    *
1101    * <p>
1102    * Possible values:
1103    * <ul>
1104    *    <li>Positive integer - Element is focusable and participates in tab order</li>
1105    *    <li><js>"0"</js> - Element is focusable but not in tab order</li>
1106    *    <li>Negative integer - Element is not focusable</li>
1107    * </ul>
1108    *
1109    * @param tabindex The tab order value for keyboard navigation.
1110    * @return This object.
1111    */
1112   public HtmlElement tabindex(Object value) {
1113      attr("tabindex", value);
1114      return this;
1115   }
1116
1117   /**
1118    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#attr-title">title</a> attribute.
1119    *
1120    * <p>
1121    * Specifies additional information about the element, typically displayed as a tooltip
1122    * when the user hovers over the element.
1123    *
1124    * @param title Tooltip text to display on hover (e.g., <js>"Click to submit form"</js>).
1125    * @return This object.
1126    */
1127   public HtmlElement title(String value) {
1128      attr("title", value);
1129      return this;
1130   }
1131
1132   /**
1133    * <a class="doclink" href="https://www.w3.org/TR/html5/dom.html#attr-translate">translate</a> attribute.
1134    *
1135    * <p>
1136    * Specifies whether the element's content should be translated when the page is localized.
1137    *
1138    * <p>
1139    * Possible values:
1140    * <ul>
1141    *    <li><js>"yes"</js> - Content should be translated (default)</li>
1142    *    <li><js>"no"</js> - Content should not be translated</li>
1143    * </ul>
1144    *
1145    * @param translate Whether the element content should be translated.
1146    * @return This object.
1147    */
1148   public HtmlElement translate(Object value) {
1149      attr("translate", value);
1150      return this;
1151   }
1152
1153   /**
1154    * If the specified attribute is a boolean, it gets converted to the attribute name if <jk>true</jk> or <jk>null</jk> if <jk>false</jk>.
1155    *
1156    * @param value The attribute value.
1157    * @param attr The attribute name.
1158    * @return The deminimized value, or the same value if the value wasn't a boolean.
1159    */
1160   protected Object deminimize(Object value, String attr) {
1161      if (value instanceof Boolean b) {
1162         if (Boolean.TRUE.equals(b))
1163            return attr;
1164         return null;
1165      }
1166      return value;
1167   }
1168   @Override /* Object */
1169   public String toString() {
1170      return HtmlSerializer.DEFAULT_SIMPLE_SQ.toString(this);
1171   }
1172}