Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Math ml tag defs #105

Merged
merged 31 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ js/yarn.lock
.idea

.DS_Store

.bloop
.metals
metals.sbt
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.watcherExclude": {
"**/target": true
}
}
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import VersionHelper.{versionFmt, fallbackVersion}

// Lets me depend on Maven Central artifacts immediately without waiting
resolvers ++= Resolver.sonatypeOssRepos("public")
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("public")
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")


// Makes sure to increment the version for local development
ThisBuild / version := dynverGitDescribeOutput.value
Expand All @@ -12,9 +14,11 @@ ThisBuild / dynver := {
sbtdynver.DynVer
.getGitDescribeOutput(d)
.mkVersion(out => versionFmt(out, dynverSonatypeSnapshots.value), fallbackVersion(d))


}

(ThisBuild / scalaVersion) := Versions.Scala_2_12
(ThisBuild / scalaVersion) := Versions.Scala_3
Quafadas marked this conversation as resolved.
Show resolved Hide resolved

(ThisBuild / crossScalaVersions) := Seq(
Versions.Scala_3,
Expand Down
161 changes: 161 additions & 0 deletions js/src/test/scala/com/thirdparty/defs/tags/MathMLTags.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.thirdparty.defs.tags

import com.thirdparty.tags.MathTag
import org.scalajs.dom

// #NOTE: GENERATED CODE
// - This file is generated at compile time from the data in Scala DOM Types
// - See `GeneratorSpec.scala` for code generation params
// - Contribute to https://github.com/raquo/scala-dom-types to add missing tags / attrs / props / etc.

trait MathMLTags {


def mathMLTag[El <: dom.MathMLElement](name: String): MathTag[El] = new MathTag(name)


/**
* The top-level element in MathML, representing a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math math @ MDN]]
*/
lazy val math: MathTag[dom.MathMLElement] = mathMLTag("math")


/**
* Represents a mathematical identifier, such as a variable name.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mi mi @ MDN]]
*/
lazy val mi: MathTag[dom.MathMLElement] = mathMLTag("mi")


/**
* Represents a mathematical operator.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo mo @ MDN]]
*/
lazy val mo: MathTag[dom.MathMLElement] = mathMLTag("mo")


/**
* Represents a number in a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mn mn @ MDN]]
*/
lazy val mn: MathTag[dom.MathMLElement] = mathMLTag("mn")


/**
* Represents a superscript expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup msup @ MDN]]
*/
lazy val msup: MathTag[dom.MathMLElement] = mathMLTag("msup")


/**
* Represents a subscript expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub msub @ MDN]]
*/
lazy val msub: MathTag[dom.MathMLElement] = mathMLTag("msub")


/**
* Represents a fraction.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfrac mfrac @ MDN]]
*/
lazy val mfrac: MathTag[dom.MathMLElement] = mathMLTag("mfrac")


/**
* Represents a square root.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt msqrt @ MDN]]
*/
lazy val msqrt: MathTag[dom.MathMLElement] = mathMLTag("msqrt")


/**
* Represents a root expression with a specified degree.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mroot mroot @ MDN]]
*/
lazy val mroot: MathTag[dom.MathMLElement] = mathMLTag("mroot")


/**
* Represents text within a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtext mtext @ MDN]]
*/
lazy val mtext: MathTag[dom.MathMLElement] = mathMLTag("mtext")


/**
* The <munder> MathML element is used to attach an accent or a limit under an expression. It uses the following syntax: <munder> base underscript </munder>
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover munderover @ MDN]]
*/
lazy val munderover: MathTag[dom.MathMLElement] = mathMLTag("munderover")


/**
* The <mtr> MathML element represents a row in a table or a matrix. It may only appear in a <mtable> element and its children are <mtd> elements representing cells. This element is similar to the <tr> element of HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtr mtr @ MDN]]
*/
lazy val mtr: MathTag[dom.MathMLElement] = mathMLTag("mtr")


/**
* The <mtd> MathML element represents a cell in a table or a matrix. It may only appear in an <mtr> element.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtd mtd @ MDN]]
*/
lazy val mtd: MathTag[dom.MathMLElement] = mathMLTag("mtd")


/**
* The <mtable> MathML element allows you to create tables or matrices. Its children are <mtr> elements (representing rows), each of them having <mtd> elements as its children (representing cells). These elements are similar to <table>, <tr> and <td> elements of HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtable mtable @ MDN]]
*/
lazy val mtable: MathTag[dom.MathMLElement] = mathMLTag("mtable")


/**
* Represents a base with both a subscript and a superscript.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup msubsup @ MDN]]
*/
lazy val msubsup: MathTag[dom.MathMLElement] = mathMLTag("msubsup")


/**
* The <mstyle> MathML element is used to change the style of its contents. It is similar to the <style> element in HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mstyle mstyle @ MDN]]
*/
lazy val mstyle: MathTag[dom.MathMLElement] = mathMLTag("mstyle")


/**
* The <mspace> MathML element is used to display a blank space, whose size is set by its attributes.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace mspace @ MDN]]
*/
lazy val mspace: MathTag[dom.MathMLElement] = mathMLTag("mspace")


/**
* Represents a string literal.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms ms @ MDN]]
*/
lazy val ms: MathTag[dom.MathMLElement] = mathMLTag("ms")


}
5 changes: 5 additions & 0 deletions js/src/test/scala/com/thirdparty/tags/Tag.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thirdparty.tags

import org.scalajs.dom
import org.scalajs.dom.MathMLElement

trait Tag[El <: dom.Element] {
val domName: String
Expand All @@ -14,3 +15,7 @@ case class HtmlTag[El <: dom.html.Element](
case class SvgTag[El <: dom.svg.Element](
override val domName: String
) extends Tag[El]

case class MathTag[El <: MathMLElement](
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
override val domName: String
) extends Tag[org.scalajs.dom.MathMLElement]
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 26 additions & 1 deletion jvm/src/test/scala/com/raquo/domtypes/GeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.raquo.domtypes

import com.raquo.domtypes.codegen.DefType.LazyVal
import com.raquo.domtypes.codegen._
import com.raquo.domtypes.common.{HtmlTagType, SvgTagType}
import com.raquo.domtypes.common.{HtmlTagType, SvgTagType, MathMLTagType}
import com.raquo.domtypes.defs.styles.StyleTraitDefs
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -90,6 +90,31 @@ class GeneratorSpec extends AnyFunSpec with Matchers {
)
}

it("Generate MathMl tags") {
println("=== MATHML TAGS ===")

val traitName = "MathMLTags"
Quafadas marked this conversation as resolved.
Show resolved Hide resolved

val fileContent = generator.generateTagsTrait(
tagType = MathMLTagType,
defGroups = defGroups.mathMlTagsDefGroups,
printDefGroupComments = false,
traitCommentLines = Nil,
traitModifiers = Nil,
traitName = traitName,
keyKind = "MathTag",
baseImplDefComments = Nil,
keyImplName = "mathMLTag",
defType = LazyVal
)

generator.writeToFile(
packagePath = generator.tagDefsPackagePath,
fileName = traitName,
fileContent = fileContent
)
}

it("Generate HTML attributes ") {
println("=== HTML ATTRS ===")

Expand Down
3 changes: 1 addition & 2 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ object Versions {
val Scala_3 = "3.3.3"

// -- Dependencies --

val ScalaJsDom = "2.8.0"
val ScalaJsDom = "2.8.0+69-8c4ee126-SNAPSHOT"

// -- Test --

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.9.7
sbt.version = 1.10.6
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class CanonicalDefGroups {
"SVG Tags" -> SvgTagDefs.defs,
)

val mathMlTagsDefGroups: List[(String, List[TagDef])] = List(
"MathMl Tags" -> MathMLTagDefs.defs,
)

val htmlAttrDefGroups: List[(String, List[AttrDef])] = List(
"HTML Attrs" -> HtmlAttrDefs.defs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class CanonicalGenerator(

def baseScalaJsHtmlElementType: String = "dom.html.Element"

def baseScalaJsMathMlElementType: String = "dom.MathMLElement"

def baseScalaJsSvgElementType: String = "dom.svg.Element"

def scalaJsElementTypeParam: String = "El"
Expand Down Expand Up @@ -168,10 +170,16 @@ class CanonicalGenerator(
List(
s"def ${keyImplName}[$scalaJsElementTypeParam <: $baseScalaJsHtmlElementType]($keyImplNameArgName: String, void: Boolean = false): ${keyKind}[$scalaJsElementTypeParam] = ${keyKindConstructor(keyKind)}($keyImplNameArgName, void)"
)
} else {
} else if (tagType == SvgTagType) {
List(
s"def ${keyImplName}[$scalaJsElementTypeParam <: $baseScalaJsSvgElementType]($keyImplNameArgName: String): ${keyKind}[$scalaJsElementTypeParam] = ${keyKindConstructor(keyKind)}($keyImplNameArgName)",
)
} else if (tagType == MathMLTagType) {
List(
s"def ${keyImplName}[$scalaJsElementTypeParam <: $baseScalaJsMathMlElementType]($keyImplNameArgName: String): ${keyKind}[$scalaJsElementTypeParam] = ${keyKindConstructor(keyKind)}($keyImplNameArgName)",
)
} else {
???
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
}

val headerLines = List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ object HtmlTagType extends TagType {
object SvgTagType extends TagType {
override val sourceStr: String = "SvgTagType"
}

object MathMLTagType extends TagType {
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
override val sourceStr: String = "MathMLTagType"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.raquo.domtypes.defs.attrs

import com.raquo.domtypes.common.MathMLTagType
import com.raquo.domtypes.common.AttrDef

object MathMlAttrDefs {

// @nikita: Wasn't this the part we concluded didn't work?
/**
* If you break open the browser tools and noodle around with mathml elements, you'll see that they have a bunch of attributes.,
* you may find they have little effect or are "undefined" in the browser.
*
* This would appear to be because they aren't part of the browser API?
*
* We take a pass on these here.
*
*/
val defs: List[AttrDef] = List(


)
}
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
Loading