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

Added alias table for deprecated css properties #552

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions crates/gosub_styling/tools/generate_definitions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.cache
.output
30 changes: 29 additions & 1 deletion crates/gosub_styling/tools/generate_definitions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"path"
"sort"
)

type ExportType int
Expand All @@ -21,7 +22,7 @@ const (

const (
exportType = Both
ResourcePath = "crates/gosub_styling/resources/definitions"
ResourcePath = ".output"
SingleFilePath = ResourcePath + "/definitions.json"
MultiFileDir = ResourcePath
MultiFilePrefix = "definitions_"
Expand All @@ -41,7 +42,16 @@ func main() {
len(webrefData.Properties), len(webrefData.Values), len(webrefData.AtRules), len(webrefData.Selectors),
)

sort.Slice(webrefData.Properties, func(i, j int) bool {
return webrefData.Properties[i].Name < webrefData.Properties[j].Name
})

Comment on lines +45 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to sort the properties alphabetically, it might make more sense to sort them after its spec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are looking for a specific prop, and it's syntax, the computed props might be nearer then, since they are all defined in the same spec.

I guess for expanded props it isn't really an issue, since of grid or mask, they all also start with grid- or mask.

for _, property := range webrefData.Properties {
if property.Syntax == "" {
// Skip any empty syntax, as they will be filled later with alias table
continue
}

prop := utils.Property{
Name: property.Name,
Syntax: property.Syntax,
Expand Down Expand Up @@ -100,6 +110,23 @@ func main() {
Descriptors: descriptors,
Values: atRule.Values,
})

for _, property := range webrefData.Properties {
if property.Syntax != "" {
// Skip properties with syntax
continue
}

alias, err := webref.GetAlias(property.Name)
if err != nil {
log.Panic("failed to get alias syntax for property: " + property.Name)
}

data.PropAliases = append(data.PropAliases, utils.PropAlias{
Name: property.Name,
For: alias,
})
}
}

data.Selectors = webrefData.Selectors
Expand Down Expand Up @@ -140,6 +167,7 @@ func ExportMultiFile(data *utils.Data) {
ExportData(data.Values, path.Join(MultiFileDir, MultiFilePrefix+"values.json"))
ExportData(data.AtRules, path.Join(MultiFileDir, MultiFilePrefix+"at-rules.json"))
ExportData(data.Selectors, path.Join(MultiFileDir, MultiFilePrefix+"selectors.json"))
ExportData(data.PropAliases, path.Join(MultiFileDir, MultiFilePrefix+"prop-aliases.json"))

}

Expand Down
14 changes: 10 additions & 4 deletions crates/gosub_styling/tools/generate_definitions/utils/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package utils

type Data struct {
Properties []Property `json:"properties"`
Values []Value `json:"values"`
AtRules []AtRule `json:"atrules"`
Selectors []Selector `json:"selectors"`
Properties []Property `json:"properties"`
Values []Value `json:"values"`
AtRules []AtRule `json:"atrules"`
Selectors []Selector `json:"selectors"`
PropAliases []PropAlias `json:"propAliases"`
}

type PropAlias struct {
Name string `json:"name"`
For string `json:"for"`
}

type Value struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
REPO = "w3c/webref"
LOCATION = "ed/css"
PATCH_LOCATION = "ed/csspatches"
CACHE_DIR = "crates/gosub_styling/resources/cache"
CACHE_DIR = ".cache"
CACHE_INDEX_FILE = CACHE_DIR + "/index/cache_index.json"
CUSTOM_PATCH_DIR = "crates/gosub_styling/resources/patches"
BRANCH = "curated"
Expand Down
96 changes: 91 additions & 5 deletions crates/gosub_styling/tools/generate_definitions/webref/webref.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webref

import (
"encoding/json"
"errors"
"generate_definitions/utils"
"io"
"log"
Expand Down Expand Up @@ -198,6 +199,10 @@ func DownloadFileContent(file *utils.DirectoryListItem) []byte {
return nil
}

if err := os.MkdirAll(path.Dir(cachePath), 0755); err != nil {
log.Panic("Failed to create cache directory ", path.Dir(cachePath), err)
}

if err := os.WriteFile(cachePath, body, 0644); err != nil {
log.Panic("Failed to write cache file ", cachePath, err)
}
Expand Down Expand Up @@ -306,12 +311,11 @@ func skip(shortname string) bool {
return true
}

// ProcessValue will process a single value (from either root values or propertt values) and add it
// ProcessValue will process a single value (from either root values or property values) and add it
// to the ParseData if possible.
func ProcessValue(name string, type_ string, syntax string, pd *ParseData) {
if name == syntax {
//log.Println("name == syntax for ", name)

// log.Println("name == syntax for ", name)
return
}

Expand Down Expand Up @@ -369,11 +373,13 @@ func DecodeFileContent(content []byte, pd *ParseData) {
}

for _, property := range fileData.Properties {
//log.Println("Processing property: ", property.Name)
if property.Name == "stop-color" || property.Name == "stop-opacity" {
// Some hardcoded skips
return
}

for _, v := range property.Values {
ProcessValue(v.Name, v.Type, v.Syntax, pd)

ProcessExtraValues(v.Values, pd)
}

Expand Down Expand Up @@ -444,3 +450,83 @@ func ProcessExtraValues(values []WebRefValue, pd *ParseData) {
ProcessExtraValues(value.Values, pd)
}
}

var PropertyAliasTable = map[string]string{
"-webkit-align-content": "align-content",
"-webkit-align-items": "align-items",
"-webkit-align-self": "align-self",
"-webkit-animation": "animation",
"-webkit-animation-delay": "animation-delay",
"-webkit-animation-direction": "animation-direction",
"-webkit-animation-duration": "animation-duration",
"-webkit-animation-fill-mode": "animation-fill-mode",
"-webkit-animation-iteration-count": "animation-iteration-count",
"-webkit-animation-name": "animation-name",
"-webkit-animation-play-state": "animation-play-state",
"-webkit-animation-timing-function": "animation-timing-function",
"-webkit-appearance": "appearance",
"-webkit-backface-visibility": "backface-visibility",
"-webkit-background-clip": "background-clip",
"-webkit-background-origin": "background-origin",
"-webkit-background-size": "background-size",
"-webkit-border-bottom-left-radius": "border-bottom-left-radius",
"-webkit-border-bottom-right-radius": "border-bottom-right-radius",
"-webkit-border-radius": "border-radius",
"-webkit-border-top-left-radius": "border-top-left-radius",
"-webkit-border-top-right-radius": "border-top-right-radius",
"-webkit-box-align": "box-align",
"-webkit-box-flex": "box-flex",
"-webkit-box-ordinal-group": "box-ordinal-group",
"-webkit-box-orient": "box-orient",
"-webkit-box-pack": "box-pack",
"-webkit-box-shadow": "box-shadow",
"-webkit-box-sizing": "box-sizing",
"-webkit-filter": "filter",
"-webkit-flex": "flex",
"-webkit-flex-basis": "flex-basis",
"-webkit-flex-direction": "flex-direction",
"-webkit-flex-flow": "flex-flow",
"-webkit-flex-grow": "flex-grow",
"-webkit-flex-shrink": "flex-shrink",
"-webkit-flex-wrap": "flex-wrap",
"-webkit-justify-content": "justify-content",
"-webkit-mask": "mask",
"-webkit-mask-box-image": "mask-border",
"-webkit-mask-box-image-outset": "mask-border-outset",
"-webkit-mask-box-image-repeat": "mask-border-repeat",
"-webkit-mask-box-image-slice": "mask-border-slice",
"-webkit-mask-box-image-source": "mask-border-source",
"-webkit-mask-box-image-width": "mask-border-width",
"-webkit-mask-clip": "mask-clip",
"-webkit-mask-composite": "mask-composite",
"-webkit-mask-image": "mask-image",
"-webkit-mask-origin": "mask-origin",
"-webkit-mask-position": "mask-position",
"-webkit-mask-repeat": "mask-repeat",
"-webkit-mask-size": "mask-size",
"-webkit-order": "order",
"-webkit-perspective": "perspective",
"-webkit-perspective-origin": "perspective-origin",
"-webkit-text-size-adjust": "text-size-adjust",
"-webkit-transform": "transform",
"-webkit-transform-origin": "transform-origin",
"-webkit-transform-style": "transform-style",
"-webkit-transition": "transition",
"-webkit-transition-delay": "transition-delay",
"-webkit-transition-duration": "transition-duration",
"-webkit-transition-property": "transition-property",
"-webkit-transition-timing-function": "transition-timing-function",
"-webkit-user-select": "user-select",
"font-stretch": "font-width",
"grid-column-gap": "column-gap",
"grid-gap": "gap",
"grid-row-gap": "row-gap",
}
jaytaph marked this conversation as resolved.
Show resolved Hide resolved

func GetAlias(propName string) (string, error) {
if PropertyAliasTable[propName] == "" {
return "", errors.New("No alias syntax for property: " + propName)
}

return PropertyAliasTable[propName], nil
}