@zeecoder/container-query
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -8,2 +8,4 @@ 'use strict'; | ||
var WIDTH_UNIT = exports.WIDTH_UNIT = 'cw'; | ||
var MIN_UNIT = exports.MIN_UNIT = 'cmin'; | ||
var MAX_UNIT = exports.MAX_UNIT = 'cmax'; | ||
var DEFINE_CONTAINER_NAME = exports.DEFINE_CONTAINER_NAME = 'define-container'; |
@@ -20,2 +20,3 @@ 'use strict'; | ||
// Matching numbers followed by alphanumeric characters and % | ||
var match = value.toLowerCase().match(/(\d+(\.\d+)?)([a-z%]+)/i); | ||
@@ -29,3 +30,3 @@ | ||
return unit !== _constants.HEIGHT_UNIT && unit !== _constants.WIDTH_UNIT && (unit.indexOf(_constants.HEIGHT_UNIT) === 0 || unit.indexOf(_constants.WIDTH_UNIT) === 0); | ||
return unit !== _constants.HEIGHT_UNIT && unit !== _constants.WIDTH_UNIT && unit !== _constants.MIN_UNIT && unit !== _constants.MAX_UNIT && (unit.indexOf(_constants.HEIGHT_UNIT) === 0 || unit.indexOf(_constants.WIDTH_UNIT) === 0 || unit.indexOf(_constants.MIN_UNIT) === 0 || unit.indexOf(_constants.MAX_UNIT) === 0); | ||
} |
@@ -11,4 +11,5 @@ 'use strict'; | ||
/** | ||
* Normalise unit by removing height or width container unit from the | ||
* beginning of the string. | ||
* Normalise unit by removing the container unit from the beginning of the | ||
* string. | ||
* Ex: "chpx" => "px", "cwem" => "em", etc. | ||
* | ||
@@ -26,2 +27,10 @@ * @param {string} unit | ||
if (unit.indexOf(_constants.MIN_UNIT) === 0) { | ||
return unit.substr(_constants.MIN_UNIT.length); | ||
} | ||
if (unit.indexOf(_constants.MAX_UNIT) === 0) { | ||
return unit.substr(_constants.MAX_UNIT.length); | ||
} | ||
return unit; | ||
@@ -48,16 +57,14 @@ } | ||
if (unit === _constants.HEIGHT_UNIT || unit === _constants.WIDTH_UNIT) { | ||
if (unit === _constants.HEIGHT_UNIT || unit === _constants.WIDTH_UNIT || unit === _constants.MIN_UNIT || unit === _constants.MAX_UNIT) { | ||
return value; | ||
} | ||
var relativeToHeight = unit.indexOf(_constants.HEIGHT_UNIT) === 0; | ||
var normalisedUnit = normaliseUnit(unit); | ||
var relativeToHeight = unit.indexOf(_constants.HEIGHT_UNIT) === 0 || unit.indexOf(_constants.MIN_UNIT) === 0 && dimensions.height < dimensions.width || unit.indexOf(_constants.MAX_UNIT) === 0 && dimensions.height > dimensions.width; | ||
var relativeToWidth = unit.indexOf(_constants.WIDTH_UNIT) === 0 || unit.indexOf(_constants.MIN_UNIT) === 0 && dimensions.height >= dimensions.width || unit.indexOf(_constants.MAX_UNIT) === 0 && dimensions.height <= dimensions.width; | ||
if (relativeToHeight) { | ||
return dimensions.height * parseFloat(num) / 100 + normalisedUnit; | ||
} | ||
var relativeToWidth = unit.indexOf(_constants.WIDTH_UNIT) === 0; | ||
if (relativeToWidth) { | ||
} else if (relativeToWidth) { | ||
return dimensions.width * parseFloat(num) / 100 + normalisedUnit; | ||
@@ -64,0 +71,0 @@ } |
# CHANGELOG | ||
## 1.1.0 (2017-02-27) | ||
- cmin / cmax unit support | ||
## 1.0.4 (2017-02-27) | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "@zeecoder/container-query", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "A PostCSS plugin and Javascript runtime combination, which allows you to write @container queries in your CSS the same way you would write @media queries.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
30086
669