Skip to content

Commit

Permalink
feat: add atom addon
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 13, 2018
1 parent 923cced commit edc5d59
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
57 changes: 57 additions & 0 deletions addon/atoms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

var atoms = {
d: 'display',

mar: 'margin',
mart: 'margin-top',
marr: 'margin-right',
marb: 'margin-bottom',
marl: 'margin-left',
pad: 'padding',
padt: 'padding-top',
padr: 'padding-right',
padb: 'padding-bottom',
padl: 'padding-left',

bd: 'border',
bdt: 'border-top',
bdr: 'border-right',
bdb: 'border-bottom',
bdl: 'border-left',
bdrad: 'border-radius',

col: 'color',
op: 'opacity',
bg: 'background',
bgc: 'background-color',

fz: 'font-size',
fs: 'font-style',
fw: 'font-weight',
ff: 'font-family',

lh: 'line-height',
bxz: 'box-sizing',
cur: 'cursor',
ov: 'overflow',
pos: 'position',
ls: 'list-style',
ta: 'text-align',
td: 'text-decoration',
fl: 'float',
w: 'width',
h: 'height',
trs: 'transition',
out: 'outline',
vis: 'visibility',
ww: 'word-wrap',
con: 'content',
};

exports.addon = function (renderer) {
var originalKey = renderer.key;
renderer.key = function (key, value) {
return originalKey(atoms[key] || key, value);
};
};
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ exports.create = function (h) {
pfx: '_',
cnt: 0,
hash: hash,
decl: function (key, value) {
key = key.replace(KEBAB_REGEX, '-$&').toLowerCase();
return key + ':' + value + ';';
}
};

var putRaw;
Expand Down Expand Up @@ -41,8 +45,7 @@ exports.create = function (h) {
var selectorInterpolated = interpolateSelectors(selectors, prop);
put(selectorInterpolated, value);
} else {
prop = prop.replace(KEBAB_REGEX, '-$&').toLowerCase();
str += prop + ':' + value + ';';
str += renderer.decl(prop, value);
}
}

Expand Down

0 comments on commit edc5d59

Please sign in to comment.