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

@property javascript file for typed definitions #414

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions build/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {buildPropsStylesheet} from './to-stylesheet.js'
import {toTokens} from './to-tokens.js'
import {toObject} from './to-object.js'
import {toFigmaTokens} from './to-figmatokens.js'
import {toAtProperty} from './to-at-property.js'

const [,,prefix='',useWhere,customSubject='',filePrefix=''] = process.argv

Expand Down Expand Up @@ -86,6 +87,16 @@ const figmatokensSYNC = { 'open-props': { ...figmatokens } }
const FigmaTokensSync = fs.createWriteStream('../open-props.figma-tokens.sync.json')
FigmaTokensSync.end(JSON.stringify(figmatokensSYNC, null, 2))

// gen @property module
const atTokens = toAtProperty(Object.entries({
...Object.assign({}, ...Object.values(individual_colors)),
// ...Easings,
Copy link
Owner Author

Choose a reason for hiding this comment

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

there's no type for easings I dont think

...Zindex,
...Aspects,
}))
const atProperty = fs.createWriteStream('../open-props.typed.js')
atProperty.end(JSON.stringify(atTokens)+'.forEach(CSS.registerProperty)', null, 2)

if (!fs.existsSync('../dist'))
fs.mkdirSync('../dist')

Expand Down
31 changes: 31 additions & 0 deletions build/to-at-property.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as Colors from '../src/props.colors.js'

const colors = Object.keys(Colors)
.filter(exportName => exportName !== "default")
.map(hueName => hueName.toLowerCase())

export const toAtProperty = props =>
props.map(([key, token]) => {
let syntax

let isLength = key.includes('size')
let isRatio = key.includes('ratio')
let isEasing = key.includes('ease')
let isZIndex= key.includes('layer')
let isImage = key.includes('gradient')
let isColor = colors.some(color => key.includes(color))

if (isLength) syntax = 'dimension'
else if (isEasing) syntax = 'cubic-bezier'
else if (isColor) syntax = 'color'
else if (isRatio) syntax = 'ratio'
else if (isImage) syntax = 'image'
else if (isZIndex) syntax = 'number'

return {
name: key,
syntax: `<${syntax}>`,
initialValue: token,
inherits: false,
}
})