JS Introduce SVG DOM support
This commit is contained in:
committed by
Sergey Mashkov
parent
6366f966b7
commit
d24bdf5ad0
@@ -11,6 +11,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
@@ -2726,7 +2727,7 @@ native public open class CanvasRenderingContext2D {
|
||||
var height: Int
|
||||
get() = noImpl
|
||||
set(value) = noImpl
|
||||
var currentTransform: dynamic
|
||||
var currentTransform: SVGMatrix
|
||||
get() = noImpl
|
||||
set(value) = noImpl
|
||||
var globalAlpha: Double
|
||||
@@ -2847,7 +2848,7 @@ native public trait CanvasGradient {
|
||||
}
|
||||
|
||||
native public trait CanvasPattern {
|
||||
fun setTransform(transform: dynamic): Unit = noImpl
|
||||
fun setTransform(transform: SVGMatrix): Unit = noImpl
|
||||
}
|
||||
|
||||
native public trait TextMetrics {
|
||||
@@ -2945,12 +2946,12 @@ native public open class DrawingStyle(scope: Element = noImpl) {
|
||||
}
|
||||
|
||||
native public open class Path2D {
|
||||
fun addPath(path: Path2D, transformation: dynamic = null): Unit = noImpl
|
||||
fun addPathByStrokingPath(path: Path2D, styles: dynamic, transformation: dynamic = null): Unit = noImpl
|
||||
fun addText(text: String, styles: dynamic, transformation: dynamic, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addPathByStrokingText(text: String, styles: dynamic, transformation: dynamic, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addText(text: String, styles: dynamic, transformation: dynamic, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addPathByStrokingText(text: String, styles: dynamic, transformation: dynamic, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addPath(path: Path2D, transformation: SVGMatrix? = null): Unit = noImpl
|
||||
fun addPathByStrokingPath(path: Path2D, styles: dynamic, transformation: SVGMatrix? = null): Unit = noImpl
|
||||
fun addText(text: String, styles: dynamic, transformation: SVGMatrix?, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addPathByStrokingText(text: String, styles: dynamic, transformation: SVGMatrix?, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addText(text: String, styles: dynamic, transformation: SVGMatrix?, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun addPathByStrokingText(text: String, styles: dynamic, transformation: SVGMatrix?, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
|
||||
fun closePath(): Unit = noImpl
|
||||
fun moveTo(x: Double, y: Double): Unit = noImpl
|
||||
fun lineTo(x: Double, y: Double): Unit = noImpl
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
import org.w3c.workers.*
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.notifications.*
|
||||
import org.w3c.workers.*
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.workers.*
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.w3c.dom.*
|
||||
import org.w3c.dom.css.*
|
||||
import org.w3c.dom.events.*
|
||||
import org.w3c.dom.parsing.*
|
||||
import org.w3c.dom.svg.*
|
||||
import org.w3c.fetch.*
|
||||
import org.w3c.files.*
|
||||
import org.w3c.notifications.*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -67,14 +67,25 @@ definition
|
||||
| dictionary
|
||||
| enum_
|
||||
| typedef
|
||||
| exception_
|
||||
| const_
|
||||
| module
|
||||
| implementsStatement
|
||||
;
|
||||
|
||||
module
|
||||
: 'module' IDENTIFIER_WEBIDL '{' definitions '}' ';'?
|
||||
;
|
||||
|
||||
callbackOrInterface
|
||||
: 'callback' callbackRestOrInterface
|
||||
| interface_
|
||||
;
|
||||
|
||||
exception_
|
||||
: 'exception' IDENTIFIER_WEBIDL inheritance '{' dictionaryMembers '}' ';'
|
||||
;
|
||||
|
||||
callbackRestOrInterface
|
||||
: callbackRest
|
||||
| interface_
|
||||
@@ -150,7 +161,7 @@ defaultValue
|
||||
;
|
||||
|
||||
inheritance
|
||||
: ':' IDENTIFIER_WEBIDL
|
||||
: ':' IDENTIFIER_WEBIDL ( ',' IDENTIFIER_WEBIDL )*
|
||||
| /* empty */
|
||||
;
|
||||
|
||||
@@ -271,16 +282,11 @@ readWriteAttribute
|
||||
;
|
||||
|
||||
attributeRest
|
||||
: 'attribute' type (IDENTIFIER_WEBIDL | 'required') ';'
|
||||
: 'attribute' type (IDENTIFIER_WEBIDL | 'required') attributeAnnotations* ';'
|
||||
;
|
||||
|
||||
attributeName
|
||||
: attributeNameKeyword
|
||||
| IDENTIFIER_WEBIDL
|
||||
;
|
||||
|
||||
attributeNameKeyword
|
||||
: 'required'
|
||||
attributeAnnotations
|
||||
: IDENTIFIER_WEBIDL ( '(' type (',' type)* ')' )?
|
||||
;
|
||||
|
||||
inherit
|
||||
@@ -316,7 +322,7 @@ special
|
||||
;
|
||||
|
||||
operationRest
|
||||
: optionalIdentifier '(' argumentList ')' ';'
|
||||
: optionalIdentifier '(' argumentList ')' attributeAnnotations* ';'
|
||||
;
|
||||
|
||||
optionalIdentifier
|
||||
@@ -339,7 +345,7 @@ argument
|
||||
;
|
||||
|
||||
optionalOrRequiredArgument
|
||||
: 'optional'? type ellipsis argumentName default_
|
||||
: 'optional'? ('in'|'out')? type ellipsis argumentName default_
|
||||
;
|
||||
|
||||
argumentName
|
||||
|
||||
@@ -37,6 +37,7 @@ val urls = listOf(
|
||||
"https://raw.githubusercontent.com/whatwg/fetch/master/Overview.src.html" to "org.w3c.fetch",
|
||||
"http://www.w3.org/TR/vibration/" to "org.w3c.vibration",
|
||||
"http://dev.w3.org/csswg/cssom/" to "org.w3c.dom.css",
|
||||
"http://web.archive.org/web/20150317051602/http://www.w3.org/TR/SVG11/single-page.html" to "org.w3c.dom.svg",
|
||||
"https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl" to "org.khronos.webgl",
|
||||
"https://www.khronos.org/registry/typedarray/specs/latest/typedarray.idl" to "org.khronos.webgl"
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.idl2k
|
||||
import org.antlr.v4.runtime.CharStream
|
||||
import org.antlr.v4.runtime.CommonTokenStream
|
||||
import org.antlr.v4.runtime.ParserRuleContext
|
||||
import org.antlr.v4.runtime.tree.ParseTree
|
||||
import org.antlr.v4.runtime.tree.TerminalNode
|
||||
import org.antlr.webidl.WebIDLBaseVisitor
|
||||
import org.antlr.webidl.WebIDLLexer
|
||||
@@ -82,7 +83,7 @@ class ExtendedAttributeParser : WebIDLBaseVisitor<ExtendedAttribute>() {
|
||||
override fun defaultResult(): ExtendedAttribute = ExtendedAttribute(name, call, arguments)
|
||||
|
||||
override fun visitExtendedAttribute(ctx: WebIDLParser.ExtendedAttributeContext): ExtendedAttribute {
|
||||
call = ctx.children?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }?.firstOrNull()?.getText() ?: ""
|
||||
call = ctx.children.filterIdentifiers().firstOrNull()?.getText() ?: ""
|
||||
|
||||
visitChildren(ctx)
|
||||
return defaultResult()
|
||||
@@ -259,7 +260,7 @@ class ConstantVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisit
|
||||
}
|
||||
}
|
||||
|
||||
class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String) : WebIDLBaseVisitor<Definition>() {
|
||||
class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String, val declarations : MutableList<Definition>) : WebIDLBaseVisitor<Definition>() {
|
||||
private var type: DefinitionType = DefinitionType.INTERFACE
|
||||
private var name = ""
|
||||
private val memberAttributes = ArrayList<ExtendedAttribute>()
|
||||
@@ -295,6 +296,15 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
||||
return defaultResult()
|
||||
}
|
||||
|
||||
override fun visitModule(ctx: ModuleContext): Definition {
|
||||
val moduleName = getName(ctx)
|
||||
val namespace = if (this.namespace.endsWith(moduleName)) this.namespace else this.namespace + "." + moduleName
|
||||
|
||||
ModuleVisitor(declarations, namespace).visitChildren(ctx)
|
||||
|
||||
return defaultResult()
|
||||
}
|
||||
|
||||
override fun visitInterface_(ctx: Interface_Context): Definition {
|
||||
name = getName(ctx)
|
||||
visitChildren(ctx)
|
||||
@@ -347,8 +357,8 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
||||
|
||||
override fun visitDictionaryMember(ctx: DictionaryMemberContext): Definition {
|
||||
val name = ctx.children
|
||||
?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }
|
||||
?.first { it.getText() != "" }
|
||||
.filterIdentifiers()
|
||||
.firstOrNull { it.getText() != "" }
|
||||
?.getText()
|
||||
|
||||
val type = TypeVisitor().visit(ctx.children.first { it is TypeContext })
|
||||
@@ -369,7 +379,7 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
||||
}
|
||||
|
||||
override fun visitImplementsStatement(ctx: ImplementsStatementContext): Definition {
|
||||
val identifiers = ctx.children.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }.map { it.getText() }
|
||||
val identifiers = ctx.children.filterIdentifiers().map { it.getText() }
|
||||
|
||||
if (identifiers.size() >= 2) {
|
||||
type = DefinitionType.EXTENSION_INTERFACE
|
||||
@@ -390,8 +400,8 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
||||
}
|
||||
|
||||
override fun visitInheritance(ctx: WebIDLParser.InheritanceContext): Definition {
|
||||
if (ctx.children != null && ctx.isEmpty().not()) {
|
||||
inherited.add(getName(ctx))
|
||||
if (ctx.children != null) {
|
||||
inherited.addAll(ctx.children.filterIdentifiers().map {it.getText().trim()}.filter {it != ""})
|
||||
}
|
||||
return defaultResult()
|
||||
}
|
||||
@@ -431,38 +441,38 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
||||
|
||||
}
|
||||
|
||||
private fun getName(ctx: ParserRuleContext) = ctx.children.first { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }.getText()
|
||||
class ModuleVisitor(val declarations : MutableList<Definition>, var namespace : String = "") : WebIDLBaseVisitor<Unit>() {
|
||||
val extendedAttributes = ArrayList<ExtendedAttribute>()
|
||||
|
||||
override fun visitDefinition(ctx: WebIDLParser.DefinitionContext) {
|
||||
val declaration = DefinitionVisitor(extendedAttributes.toList(), namespace, declarations).visitChildren(ctx)
|
||||
extendedAttributes.clear()
|
||||
declarations.add(declaration)
|
||||
}
|
||||
|
||||
override fun visitExtendedAttribute(ctx: ExtendedAttributeContext?) {
|
||||
val att = with(ExtendedAttributeParser()) {
|
||||
visit(ctx)
|
||||
}
|
||||
|
||||
extendedAttributes.add(att)
|
||||
}
|
||||
|
||||
override fun visitNamespaceRest(ctx: NamespaceRestContext) {
|
||||
this.namespace = ctx.getText()
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<ParseTree>?.filterIdentifiers(): List<ParseTree> = this?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL } ?: emptyList()
|
||||
private fun getName(ctx: ParserRuleContext) = ctx.children.filterIdentifiers().first().getText()
|
||||
|
||||
fun parseIDL(reader: CharStream): Repository {
|
||||
val ll = WebIDLLexer(reader)
|
||||
val pp = WebIDLParser(CommonTokenStream(ll))
|
||||
|
||||
val idl = pp.webIDL()
|
||||
|
||||
val declarations = ArrayList<Definition>()
|
||||
|
||||
idl.accept(object : WebIDLBaseVisitor<Unit>() {
|
||||
val extendedAttributes = ArrayList<ExtendedAttribute>()
|
||||
var namespace = ""
|
||||
|
||||
override fun visitDefinition(ctx: WebIDLParser.DefinitionContext) {
|
||||
val declaration = DefinitionVisitor(extendedAttributes.toList(), namespace).visitChildren(ctx)
|
||||
extendedAttributes.clear()
|
||||
declarations.add(declaration)
|
||||
}
|
||||
|
||||
override fun visitExtendedAttribute(ctx: ExtendedAttributeContext?) {
|
||||
val att = with(ExtendedAttributeParser()) {
|
||||
visit(ctx)
|
||||
}
|
||||
|
||||
extendedAttributes.add(att)
|
||||
}
|
||||
|
||||
override fun visitNamespaceRest(ctx: NamespaceRestContext) {
|
||||
this.namespace = ctx.getText()
|
||||
}
|
||||
})
|
||||
ModuleVisitor(declarations).visit(idl)
|
||||
|
||||
return Repository(
|
||||
declarations.filterIsInstance<InterfaceDefinition>().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.getValue().reduce(::merge) },
|
||||
|
||||
Reference in New Issue
Block a user