ruricolist / spinneret

Common Lisp HTML5 generator
MIT License
369 stars 26 forks source link

tags.lisp: Added SVG tags to *html5-elements* #94

Closed nerap528 closed 6 months ago

nerap528 commented 6 months ago

Spinneret screams at me when I work with SVG files. I also added every SVG element listed here https://developer.mozilla.org/en-US/docs/Web/SVG/Element, so it will be happy forever.

ruricolist commented 6 months ago

Could you fix the whitespace change to *html3-elements*?

Also, I'm curious, how well does this actually work? I was under the impression embedded SVG had to use XML syntax, which is not exactly what Spinneret produces. Are there any issues with SVG attributes?

nerap528 commented 6 months ago

The added whitespace at *html3-elements* has been removed. Here is an example of how the svg elements are used. (The relevant codepen: https://codepen.io/alvarotrigo/pen/RwLGjKq)

The output spinneret generates is rendered exactly as shown in the codepen.

Hamburger-menu

   (:div :class "wrapper"
          (:nav
           (:input :type "checkbox" :id "menu" :name "menu" :class "m-menu__checkbox")
           (:label :class "m-menu__toggle" :for "menu"
                   (:svg :width "35" :height "35" :viewBox "0 0 24 24" :fill "none" :stroke "#fff" :stroke-width "2" :stroke-linecap "butt" :stroke-linejoin "arcs"
                         (:line :x1 "3" :y1 "12" :x2 "21" :y2 "12")
                         (:line :x1 "3" :y1 "6" :x2 "21" :y2 "6")
                         (:line :x1 "3" :y1 "18" :x2 "21" :y2 "18")))
           (:label :class "m-menu__overlay" :for "menu")
           (:div :class "m-menu"
                 (:div :class "m-menu__header"
                       (:label :class "m-menu__toggle" :for "menu"
                               (:svg :width "35" :height "35" :viewBox "0 0 24 24" :fill "none" :stroke "#000000" :stroke-width "2" :stroke-linecap "butt" :stroke-linejoin "arcs"
                                     (:line :x1 "18" :y1 "6" :x2 "6" :y2 "18")
                                     (:line :x1 "6" :y1 "6" :x2 "18" :y2 "18")))
                       (:span "MENU"))
                 (:ul
                  (:li
                   (:label "Item 1"))
                  (:li
                   (:label :class "a-label__chevron" :for "item-2" "Item 2")
                   (:input :type "checkbox" :id "item-2" :name "item-2" :class "m-menu__checkbox")
                   (:div :class "m-menu"
                         (:div :class "m-menu__header"
                               (:label :class "m-menu__toggle" :for "item-2"
                                       (:svg :width "35" :height "35" :viewBox "0 0 24 24" :fill "none" :stroke "#000000" :stroke-width "2" :stroke-linecap "butt" :stroke-linejoin "arcs"
                                             (:path :d "M19 12H6M12 5l-7 7 7 7")))
                               (:span "Item 2"))
                         (:ul
                          (:li
                           (:label "Item 2.1"))
                          (:li
                           (:label "Item 2.2"))
                          (:li
                           (:label :class "a-label__chevron" :for "item-2-3" "Item 2.3")
                           (:input :type "checkbox" :id "item-2-3" :name "item-2" :class "m-menu__checkbox")
                           (:div :class "m-menu"
                                 (:div :class "m-menu__header"
                                       (:label :class "m-menu__toggle" :for "item-2-3"
                                               (:svg :width "35" :height "35" :viewBox "0 0 24 24" :fill "none" :stroke "#000000" :stroke-width "2" :stroke-linecap "butt" :stroke-linejoin "arcs"
                                                     (:path :d "M19 12H6M12 5l-7 7 7 7")))
                                       (:span "Item 2.3"))
                                 (:ul
                                  (:li
                                   (:label "Item 2.3.1"))
                                  (:li
                                   (:label "Item 2.3.2"))
                                  (:li
                                   (:label "Item 2.3.3"))
                                  (:li
                                   (:label "Item 2.3.4"))
                                  (:li
                                   (:label "Item 2.3.5")))))
                          (:li
                           (:label "Item 2.4"))
                          (:li
                           (:label "Item 2.5"))
                          (:li
                           (:label "Item 2.6"))
                          (:li
                           (:label "Item 2.7"))
                          (:li
                           (:label "Item 2.8"))
                          (:li
                           (:label "Item 2.9")))))
                  (:li
                   (:label "Item 3"))
                  (:li
                   (:label "Item 4"))
                  (:li
                   (:label "Item 5"))
                  (:li
                   (:label "Item 6"))))))

And the css:

* {
  padding: 0;
  margin: 0;
}

nav {
  background-color: #91cfa1;
  height: 50px;
  padding: 0 16px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  /* fade in checked menu */
}
nav .m-menu__checkbox {
  display: none;
}
nav label.m-menu__toggle {
  cursor: pointer;
}
nav .m-menu {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 450px;
  width: calc(100vw - 30px);
  height: 100%;
  -moz-transform: translate3d(-450px, 0, 0);
  -o-transform: translate3d(-450px, 0, 0);
  -ms-transform: translate3d(-450px, 0, 0);
  -webkit-transform: translate3d(-450px, 0, 0);
  transform: translate3d(-450px, 0, 0);
  -moz-transition: transform 0.35s;
  -o-transition: transform 0.35s;
  -webkit-transition: transform 0.35s;
  transition: transform 0.35s;
  z-index: 1;
  overflow: hidden;
  background-color: #fff;
}
nav .m-menu__overlay {
  background-color: rgba(103, 103, 103, 0.5);
  position: absolute;
  top: 0;
  width: 100%;
  bottom: 0;
  z-index: 1;
  display: none;
}
nav .m-menu__header {
  padding: 0 16px;
  height: 50px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: space-around;
  justify-content: space-around;
  -ms-flex-pack: space-around;
  -webkit-align-items: center;
  align-items: center;
  border-bottom: 1px solid #e8e8e8;
}
nav .m-menu__header span {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  width: 100%;
}
nav .m-menu .m-menu {
  -moz-transform: translate3d(480px, 0, 0);
  -o-transform: translate3d(480px, 0, 0);
  -ms-transform: translate3d(480px, 0, 0);
  -webkit-transform: translate3d(480px, 0, 0);
  transform: translate3d(480px, 0, 0);
}
nav .m-menu ul {
  height: 100%;
  overflow-y: auto;
}
nav .m-menu ul li a, nav .m-menu ul li label {
  display: block;
  text-align: left;
  padding: 0 15px;
  line-height: 47px;
  text-decoration: none;
  color: #333;
  cursor: pointer;
  font-size: 1rem;
  border-bottom: 1px solid #e8e8e8;
  position: relative;
}
nav .m-menu ul li label.a-label__chevron::after {
  content: "";
  position: absolute;
  display: inline-block;
  height: 10px;
  width: 10px;
  border-color: #333;
  border-style: solid;
  border-width: 1px 1px 0 0;
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  top: 50%;
  margin-top: -5px;
  right: 16px;
}
nav .m-menu ul li .-invisible {
  border-bottom: 0;
}
nav .m-menu .m-menu label.m-menu__toggle {
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  border-bottom: 0;
  padding: 0;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}
nav .m-menu__checkbox:checked ~ .m-menu__overlay {
  display: block;
}
nav .m-menu__checkbox:checked ~ .m-menu {
  -moz-transform: translate3d(0, 0, 0);
  -o-transform: translate3d(0, 0, 0);
  -ms-transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.wrapper {
  width: 480px;
  height: 667px;
  margin: 0 auto;
  overflow: hidden;
  background-color: #fff;
  position: relative;
}

body {
  background-color: #f1f1f1;
  padding: 0;
  margin: 0;
  font-family: sans-serif;
}
nerap528 commented 6 months ago

Apparently tags from the math and svg namespace don't have to be self-closing, so the output generated by spinneret is totally fine. Neither Firefox nor Chromium complain. Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag. https://html.spec.whatwg.org/multipage/syntax.html#foreign-elements

nerap528 commented 6 months ago

All obsolete and deprecated SVG-tags have been removed from the tags that were added. As listed here: https://oreillymedia.github.io/Using_SVG/guide/markup.html#obsolete

;; Deprecated SVG tags
:font :glyph :hkern :missing-glyph :vkern
:font-face :font-face-format :font-face-name :font-face-src :font-face-uri
:altGlyph
:altGlyphDef :altGlyphItem :glyphRef
:tref
:color-profile
:cursor