Permalink
Browse files

Add YUI3 plugin prototype

  • Loading branch information...
1 parent 23a2d75 commit dd671d49363dec5d3f067c63aadcd06bfe1a39b5 @jbalsas jbalsas committed Jan 23, 2014
Showing with 100 additions and 4 deletions.
  1. +92 −0 plugins/yui3.js
  2. +8 −4 r2.js
View
92 plugins/yui3.js
@@ -0,0 +1,92 @@
+var resizeHandleRegexp = /.yui3-resize-handle/,
+ resizeHandleInnerRegexp = /.yui3-resize-handle-inner-(tr|tl|br|bl)/,
+ cursorRegexp = /(.*)-resize/,
+
+ swapCursor = {
+ 'e-resize' : 'w-resize',
+ 'w-resize' : 'e-resize',
+ 'ne-resize': 'nw-resize',
+ 'nw-resize': 'ne-resize',
+ 'se-resize': 'sw-resize',
+ 'sw-resize': 'se-resize'
+ },
+
+ swapHandleInnerBg = {
+ 'tr': '-47px 0',
+ 'br': '-75px 0',
+ 'tl': '-58px 0',
+ 'bl': '-30px 0'
+ },
+
+ plug = function(r2) {
+ var bgValueMap = r2.valueMap['background-position'];
+
+ var yui3ResizeCursor = function(v, ctx) {
+ var swap = false;
+
+ var selectors = ctx.rule.selectors;
+
+ ctx.rule.selectors.forEach(
+ function(selector) {
+ if (resizeHandleRegexp.test(selector) && cursorRegexp.test(v)) {
+ swap = true;
+ }
+ }
+ );
+
+ if (swap) {
+ v = swapCursor[v] || v;
+ }
+
+ return v;
+ };
+
+ var yui3ResizeBgPosition = function(v, ctx) {
+ var swap = '';
+
+ ctx.rule.selectors.some(
+ function(selector) {
+ if (resizeHandleInnerRegexp.test(selector)) {
+ swap = selector;
+ return true;
+ }
+ }
+ );
+
+ if (swap) {
+ var handle = resizeHandleInnerRegexp.exec(swap)[1];
+ v = swapHandleInnerBg[handle] || v;
+ }
+ else {
+ v = bgValueMap(v, ctx);
+ }
+
+ return v;
+ };
+
+ var yui3ResizeOffset = function(v, ctx) {
+ var swap = '';
+
+ ctx.rule.selectors.some(
+ function(selector) {
+ if (resizeHandleInnerRegexp.test(selector)) {
+ swap = selector;
+ return true;
+ }
+ }
+ );
+
+ if (swap) {
+ v = '2px';
+ }
+
+ return v;
+ };
+
+ r2.valueMap['background-position'] = yui3ResizeBgPosition;
+ r2.valueMap['cursor'] = yui3ResizeCursor;
+ r2.valueMap['left'] = yui3ResizeOffset;
+ r2.valueMap['right'] = yui3ResizeOffset;
+ };
+
+module.exports.plug = plug;
View
12 r2.js
@@ -9,7 +9,8 @@ var fs = require('fs')
, parser = require('css-parse')
, builder = require('css-stringify')
, fa = require('./plugins/fontawesome')
- , bg = require('./plugins/bgimage');
+ , bg = require('./plugins/bgimage')
+ , yui3 = require('./plugins/yui3');
function quad(v, m) {
// 1px 2px 3px 4px => 1px 4px 3px 2px
@@ -122,12 +123,14 @@ function processRule(rule, idx, list) {
return;
if (rule.declarations)
- rule.declarations.forEach(processDeclaration)
+ rule.declarations.forEach(function(declaration) {
+ processDeclaration(declaration, rule);
+ });
else if (rule.rules)
rule.rules.forEach(processRule)
}
-function processDeclaration(declaration) {
+function processDeclaration(declaration, rule) {
// Ignore comments in declarations
if (declaration.type !== 'declaration')
return
@@ -147,7 +150,7 @@ function processDeclaration(declaration) {
asterisk = ''
}
prop = propertyMap[prop] || prop
- val = valueMap[prop] ? valueMap[prop](val) : val
+ val = valueMap[prop] ? valueMap[prop](val, {rule: rule, decl: declaration}) : val
if (!val.match(important) && isImportant) val += '!important'
@@ -217,3 +220,4 @@ module.exports.valueMap = valueMap;
fa.plug(module.exports);
bg.plug(module.exports);
+yui3.plug(module.exports);

0 comments on commit dd671d4

Please sign in to comment.