Skip to content

Commit

Permalink
v0.5.5; CHANGE: rawVal as array instead of last value
Browse files Browse the repository at this point in the history
  • Loading branch information
futurist committed Oct 6, 2016
1 parent 4ea7749 commit e1b3e7d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 102 deletions.
7 changes: 6 additions & 1 deletion dist/cssobj-core.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ define('cssobj_core', function () { 'use strict';
if (val.hasOwnProperty(k)) parseProp(node, val, k, result, propName)
}
} else {
node.rawVal[propName] = rawVal
arrayKV(
node.rawVal,
propName,
rawVal,
true
)
if (isValidCSSValue(val)) {
// only valid val can enter node.prop and lastVal
// push every val to prop
Expand Down
7 changes: 6 additions & 1 deletion dist/cssobj-core.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ function parseProp (node, d, key, result, propKey) {
if (val.hasOwnProperty(k)) parseProp(node, val, k, result, propName)
}
} else {
node.rawVal[propName] = rawVal
arrayKV(
node.rawVal,
propName,
rawVal,
true
)
if (isValidCSSValue(val)) {
// only valid val can enter node.prop and lastVal
// push every val to prop
Expand Down
7 changes: 6 additions & 1 deletion dist/cssobj-core.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ function parseProp (node, d, key, result, propKey) {
if (val.hasOwnProperty(k)) parseProp(node, val, k, result, propName)
}
} else {
node.rawVal[propName] = rawVal
arrayKV(
node.rawVal,
propName,
rawVal,
true
)
if (isValidCSSValue(val)) {
// only valid val can enter node.prop and lastVal
// push every val to prop
Expand Down
7 changes: 6 additions & 1 deletion dist/cssobj-core.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ var cssobj_core = (function () {
if (val.hasOwnProperty(k)) parseProp(node, val, k, result, propName)
}
} else {
node.rawVal[propName] = rawVal
arrayKV(
node.rawVal,
propName,
rawVal,
true
)
if (isValidCSSValue(val)) {
// only valid val can enter node.prop and lastVal
// push every val to prop
Expand Down
2 changes: 1 addition & 1 deletion dist/cssobj-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/cssobj-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ function parseProp (node, d, key, result, propKey) {
if (val.hasOwnProperty(k)) parseProp(node, val, k, result, propName)
}
} else {
node.rawVal[propName] = rawVal
arrayKV(
node.rawVal,
propName,
rawVal,
true
)
if (isValidCSSValue(val)) {
// only valid val can enter node.prop and lastVal
// push every val to prop
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cssobj-core",
"version": "0.5.4",
"version": "0.5.5",
"description": "Generate Virtual CSS middle format, support for all cssobj functions and plugins.",
"keywords": [
"cssom",
Expand Down
85 changes: 3 additions & 82 deletions play/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// for page css
function h3Height() {
var h3Val = refh3.rawVal
return h3Val.fontSize * h3Val.lineHeight + h3Val.marginTop + h3Val.marginBottom
return h3Val.fontSize[0] * h3Val.lineHeight[0] + h3Val.marginTop[0] + h3Val.marginBottom[0]
}

reftextarea.height=function(last, node, result) {
Expand Down Expand Up @@ -91,88 +91,9 @@ <h3 id="h3">CSS Text: (paste/change below)
return document.getElementById(sel)
}
var src = $('src')
function cssobj_plugin_replace (option) {
option = option || {}

var replaceMap = option.maps || [
[
'display',
'flex',
[
{
display: '-webkit-box'
}, {
display: '-moz-box'
}, {
display: '-ms-flexbox',
'-ms-flex-preferred-size': 'initial' // IE10
}, {
display: '-webkit-flex'
}, {
display: 'flex'
}
]
],
[
'display',
'inline-flex',
[
{
display: '-ms-inline-flexbox'
}, {
display: '-webkit-inline-flex'
}, {
display: 'inline-flex'
}
]
],
[
'flex-direction',
'row',
{
'-ms-flex-direction': 'row',
'-webkit-flex-direction': 'row',
'flex-direction': 'row'
}
],
[null,null, function(key, value){return key=='color'? {[key]:value, zoom:1} : {}}]
]

return {
value: function (value, key, node, result, propKey) {

if(propKey!==undefined) return value

// retVal hold all maps result
var retVal = []

// replace from prop+value, to mapped value
for(var map, val, i = 0, len = replaceMap.length; i < len; i++) {

map = replaceMap[i]
val = map[2]

// map[0] : prop, null as placeholder
// map[1] : value, null as placeholder
// map[2] : replacement, function(key, value){} || any
if((map[0]===null || map[0]==key)
&& (map[1]===null || map[1]==value))

retVal.push(
typeof val=='function'
? val(key, value, node, result)
: val
)
}

// only accept replaced value, return original value as fallback
return retVal.length ? retVal : value
}
}
}

var opt = {local:1, propSugar:1, plugins: [
cssobj_plugin_gencss({indent:' '}),
cssobj_plugin_replace()
cssobj_plugin_gencss({indent:' '})
], localNames:{p:'_prefix_p'}}

var cssobjFunc = cssobj_core(opt)
Expand Down
44 changes: 31 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,6 @@ color: red;

})

xit('css with reset.css', function() {

var ret = cssobj({p:{'_fontSize':'12px', 'background\\Color':'#fff'}}, {propSugar:0})
expect(ret.css.trim()).deep.equal(
`p {
_fontSize: 12px;
background\\Color: #fff;
}`
)

})


})

//
Expand Down Expand Up @@ -1235,6 +1222,37 @@ line-height: 24px;

})

it('should work with .clearfix', function() {
var ret = cssobj({
// clearfix hack
'.clearfix': {
'&:before, &:after': {
content: '" "',
display: 'table'
},
'&:after': {
clear: 'both'
},
'&': {
'*zoom': 1
}
}
})

expect(ret.css).equal(
`.clearfix:before, .clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
`)
})

it('@media nested rule', function() {
var ret = cssobj({
h3:{
Expand Down

0 comments on commit e1b3e7d

Please sign in to comment.