-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(primitives): transition to new css primitives
GitHub no longer distributes primitives in JSON format. Also, the names of the values (CSS variables) have changed. Most of the new names correspond 1-to-1 with one of the old names. Some colors have also changed slightly (e.g. `fg-default`), but otherwise remain mostly the same. See https://primer.style/foundations/primitives/migrating
- Loading branch information
Showing
2 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
local res = {} | ||
|
||
local function set(cssvar, v) | ||
local before, after = cssvar:match('^(.+)%-+(.+)$') | ||
if not after then | ||
res[tonumber(cssvar) or cssvar] = v | ||
return | ||
end | ||
|
||
after = tonumber(after) or after | ||
local cur = res | ||
for k in before:gmatch('[^%-_]+') do | ||
k = tonumber(k) or k | ||
cur[k] = cur[k] or {} | ||
cur = cur[k] | ||
end | ||
|
||
if type(cur[after]) == 'table' then | ||
cur, after = cur[after], 'default' | ||
end | ||
assert(cur[after] == nil or cur[after] == v) | ||
cur[after] = v | ||
end | ||
|
||
local function print_recur(value, _ind) | ||
_ind = _ind or 0 | ||
|
||
if type(value) == 'table' then | ||
io.write('setmt {') | ||
_ind = _ind + 2 | ||
|
||
for k, v in pairs(value) do | ||
io.write(('\n%s[%q] = '):format(_ind, k)) | ||
print_recur(v, _ind) | ||
io.write(',\n') | ||
end | ||
|
||
_ind = _ind - 2 | ||
io.write(('%s}'):format(_ind)) | ||
else | ||
io.write(('%q'):format(value)) | ||
end | ||
end | ||
|
||
local defs = {} | ||
for ln in io.lines() do | ||
local k, v = ln:match('^%s*%-%-(%w.-)%s*:%s*(.-)%s*;%s*$') | ||
if k then | ||
table.insert(defs, { k, v }) | ||
end | ||
end | ||
|
||
table.sort(defs, function(a, b) | ||
return a[1] > b[1] | ||
end) | ||
|
||
for _, kv in ipairs(defs) do | ||
set(unpack(kv)) | ||
end | ||
|
||
assert(res.scale == nil) | ||
res.scale = {} | ||
for color, scale in pairs(res.base.color) do | ||
if type(scale) == 'table' then | ||
res.scale[color] = {} | ||
for i, v in pairs(scale) do | ||
res.scale[color][i + 1] = v | ||
end | ||
else | ||
res.scale[color] = scale | ||
end | ||
end | ||
|
||
io.write([=[ | ||
local mt = { | ||
__index = function(_, k) | ||
error('invalid index: ' .. k) | ||
end, | ||
} | ||
local function setmt(tbl) | ||
return setmetatable(tbl, mt) | ||
end | ||
local M = ]=]) | ||
|
||
print_recur(res) | ||
io.write('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters