<commit_before>Ext.namespace('Kwc.Abstract.Image');
Kwc.Abstract.Image.ImageUploadField = Ext.extend(Ext.Panel, {

    _scaleFactor: null,
    baseParams: null,

    initComponent: function() {
        this.baseParams = {};
        Kwc.Abstract.Image.ImageUploadField.superclass.initComponent.call(this);
        var dimensionField = this._getDimensionField();
        if (dimensionField) {// because it's possible to define only a single dimension
            dimensionField.on('render', function () {
                // fileUploadField also has to be rendered
                var dimensionField = this._getDimensionField();
                var fileUploadField = this._getFileUploadField();
                fileUploadField.container.addClass('kwc-abstract-image-imageuploadfile-container');
                if (dimensionField.getEl() && fileUploadField.getEl()) {
                    dimensionField.getEl().parent().parent().addClass('kwc-dimensionfield-container');
                }
            }, this);
            dimensionField.on('change', function (dimension) {
                this._setPreviewUrl(dimension);
                this._checkForImageTooSmall();
            }, this);
        }
        var fileUploadField = this._getFileUploadField();
        fileUploadField.on('change', function (el, value) {
            var dimensionField = this._getDimensionField();
            if (dimensionField && value.contentWidth) {
                dimensionField.setContentWidth(value.contentWidth);
            }
            if (!value || !value.mimeType || !value.mimeType.match(/(^image\/)/)) {
                dimensionField.newImageUploaded('');
                this._getFileUploadField().setPreviewUrl(null);
                this.removeClass('image-uploaded');
                return;
            }
            this.addClass('image-uploaded');
            var dimension = null;
            if (dimensionField) {
                this._scaleFactor = value.imageHandyScaleFactor;
                dimensionField.setScaleFactor(value.imageHandyScaleFactor);
                dimensionField.newImageUploaded(value);
                dimension = dimensionField.getValue();
            }
            this._setPreviewUrl(dimension);
            this._checkForImageTooSmall();
        }, this);
    },

    _checkForImageTooSmall: function () {
        var dimensionField = this._getDimensionField();
        var value = Kwf.clone(dimensionField.getValue());
        var fileUploadField = this._getFileUploadField();
        if (!fileUploadField.getEl().child('.hover-background')) return;
        var scaleFactor = this._scaleFactor;
        if (dimensionField.dpr2Check) scaleFactor /= 2;
        this._validateImageTooSmallUserNotification(value, dimensionField.dimensions, scaleFactor, fileUploadField, dimensionField);
    },

    _validateImageTooSmallUserNotification: function (value, dimensions, scaleFactor, fileUploadField, dimensionField) {
        if (!fileUploadField.getEl().child('.hover-background .message')) {
            fileUploadField.getEl().child('.hover-background').createChild({
                html:trlKwf('Caution! Image size of uploaded image does not match minimum requirement.'),
                cls: 'message'
            });
        } else {
            fileUploadField.getEl().child('.hover-background .message')
                .update(trlKwf('Caution! Image size of uploaded image does not match minimum requirement.'));
        }
        if (!value.cropData) {
            var dimension = dimensionField.dimensions[value.dimension];
            value.cropData = Kwc.Abstract.Image.CropImage
                .calculateDefaultCrop(dimension.width, dimension.height,
                    dimensionField.imageData.imageWidth, dimensionField.imageData.imageHeight);
        } else {
            fileUploadField.getEl().child('.hover-background .message')
                .update(trlKwf('Caution! Crop region does not match minimum requirement.'));
        }
        if (!Kwc.Abstract.Image.DimensionField.isValidImageSize(value, dimensions, scaleFactor)) {
            this.getEl().addClass('error');
            fileUploadField.getEl().child('.hover-background').addClass('error');
        } else {
            this.getEl().removeClass('error');
            fileUploadField.getEl().child('.hover-background').removeClass('error');
        }
    },

    _getFileUploadField: function () {
        return this.findByType('kwc.imagefile')[0];
    },

    _getDimensionField: function () {
        return this.findByType('kwc.image.dimensionfield')[0];
    },

    _setPreviewUrl: function(dimension) {
        var previewParams = {
            componentId: this.baseParams.componentId
        };
        if (dimension && dimension.dimension != null) previewParams.dimension = dimension.dimension;

        value = this._getDimensionField().getValue();
        if (value.width != null) previewParams.width = value.width;
        if (value.height != null) previewParams.height = value.height;

        if (dimension && dimension.cropData) {
            if (dimension.cropData.x != null) previewParams.cropX = dimension.cropData.x;
            if (dimension.cropData.y != null) previewParams.cropY = dimension.cropData.y;
            if (dimension.cropData.width != null) previewParams.cropWidth = dimension.cropData.width;
            if (dimension.cropData.height != null) previewParams.cropHeight = dimension.cropData.height;
        }
        this._getFileUploadField().setPreviewUrl(this.previewUrl+'?'
            +Ext.urlEncode(previewParams)+'&'
        );
    },

    setFormBaseParams: function(params) {
        Ext.apply(this.baseParams, params);
    }
});

Ext.reg('kwc.image.imageuploadfield', Kwc.Abstract.Image.ImageUploadField);
<commit_msg>Only checkForImageTooSmall if every needed value is loaded<commit_after>Ext.namespace('Kwc.Abstract.Image');
Kwc.Abstract.Image.ImageUploadField = Ext.extend(Ext.Panel, {

    _scaleFactor: null,
    baseParams: null,

    initComponent: function() {
        this.baseParams = {};
        Kwc.Abstract.Image.ImageUploadField.superclass.initComponent.call(this);
        var dimensionField = this._getDimensionField();
        if (dimensionField) {// because it's possible to define only a single dimension
            dimensionField.on('render', function () {
                // fileUploadField also has to be rendered
                var dimensionField = this._getDimensionField();
                var fileUploadField = this._getFileUploadField();
                fileUploadField.container.addClass('kwc-abstract-image-imageuploadfile-container');
                if (dimensionField.getEl() && fileUploadField.getEl()) {
                    dimensionField.getEl().parent().parent().addClass('kwc-dimensionfield-container');
                }
            }, this);
            dimensionField.on('change', function (dimension) {
                this._setPreviewUrl(dimension);
                this._checkForImageTooSmall();
            }, this);
        }
        var fileUploadField = this._getFileUploadField();
        fileUploadField.on('change', function (el, value) {
            var dimensionField = this._getDimensionField();
            if (dimensionField && value.contentWidth) {
                dimensionField.setContentWidth(value.contentWidth);
            }
            if (!value || !value.mimeType || !value.mimeType.match(/(^image\/)/)) {
                dimensionField.newImageUploaded('');
                this._getFileUploadField().setPreviewUrl(null);
                this.removeClass('image-uploaded');
                return;
            }
            this.addClass('image-uploaded');
            var dimensionValue = null;
            if (dimensionField) {
                this._scaleFactor = value.imageHandyScaleFactor;
                dimensionField.setScaleFactor(value.imageHandyScaleFactor);
                dimensionField.newImageUploaded(value);
                dimensionValue = dimensionField.getValue();
                if (dimensionValue.dimension) {
                    this._checkForImageTooSmall();
                }
            }
            this._setPreviewUrl(dimensionValue);
        }, this);
    },

    _checkForImageTooSmall: function () {
        var dimensionField = this._getDimensionField();
        var value = Kwf.clone(dimensionField.getValue());
        var fileUploadField = this._getFileUploadField();
        if (!fileUploadField.getEl().child('.hover-background')) return;
        var scaleFactor = this._scaleFactor;
        if (dimensionField.dpr2Check) scaleFactor /= 2;
        this._validateImageTooSmallUserNotification(value, dimensionField.dimensions, scaleFactor, fileUploadField, dimensionField);
    },

    _validateImageTooSmallUserNotification: function (value, dimensions, scaleFactor, fileUploadField, dimensionField) {
        if (!fileUploadField.getEl().child('.hover-background .message')) {
            fileUploadField.getEl().child('.hover-background').createChild({
                html:trlKwf('Caution! Image size of uploaded image does not match minimum requirement.'),
                cls: 'message'
            });
        } else {
            fileUploadField.getEl().child('.hover-background .message')
                .update(trlKwf('Caution! Image size of uploaded image does not match minimum requirement.'));
        }
        if (!value.cropData) {
            var dimension = dimensionField.dimensions[value.dimension];
            value.cropData = Kwc.Abstract.Image.CropImage
                .calculateDefaultCrop(dimension.width, dimension.height,
                    dimensionField.imageData.imageWidth, dimensionField.imageData.imageHeight);
        } else {
            fileUploadField.getEl().child('.hover-background .message')
                .update(trlKwf('Caution! Crop region does not match minimum requirement.'));
        }
        if (!Kwc.Abstract.Image.DimensionField.isValidImageSize(value, dimensions, scaleFactor)) {
            this.getEl().addClass('error');
            fileUploadField.getEl().child('.hover-background').addClass('error');
        } else {
            this.getEl().removeClass('error');
            fileUploadField.getEl().child('.hover-background').removeClass('error');
        }
    },

    _getFileUploadField: function () {
        return this.findByType('kwc.imagefile')[0];
    },

    _getDimensionField: function () {
        return this.findByType('kwc.image.dimensionfield')[0];
    },

    _setPreviewUrl: function(dimension) {
        var previewParams = {
            componentId: this.baseParams.componentId
        };
        if (dimension && dimension.dimension != null) previewParams.dimension = dimension.dimension;

        value = this._getDimensionField().getValue();
        if (value.width != null) previewParams.width = value.width;
        if (value.height != null) previewParams.height = value.height;

        if (dimension && dimension.cropData) {
            if (dimension.cropData.x != null) previewParams.cropX = dimension.cropData.x;
            if (dimension.cropData.y != null) previewParams.cropY = dimension.cropData.y;
            if (dimension.cropData.width != null) previewParams.cropWidth = dimension.cropData.width;
            if (dimension.cropData.height != null) previewParams.cropHeight = dimension.cropData.height;
        }
        this._getFileUploadField().setPreviewUrl(this.previewUrl+'?'
            +Ext.urlEncode(previewParams)+'&'
        );
    },

    setFormBaseParams: function(params) {
        Ext.apply(this.baseParams, params);
    }
});

Ext.reg('kwc.image.imageuploadfield', Kwc.Abstract.Image.ImageUploadField);
<|endoftext|>


<commit_before>const ACCELERATION_REPORT_MIN = 12;

app.controller('PhoneController', function($scope) {
  $scope.greeting = 'Hello World Of Physics!';
  $scope.socket = io();

  $scope.emitShake = function(data) {
    return $scope.socket.emit('shake', data);
  };

  $scope.handleDeviceAccelChange = function(e) {
    event.preventDefault();

    $scope.totalAcceleration = event.acceleration.x +
      event.acceleration.y +
      event.acceleration.z;

    if($scope.totalAcceleration > 50) {
      $scope.emitShake({shakeIncrement: 1});
    }
    // $scope.accelEventData = event.acceleration;
    $scope.$apply();
  };
  window.addEventListener('devicemotion', $scope.handleDeviceAccelChange, true);

}).controller('PlayGridController', function($scope) {
  if(!$scope.socket) { $scope.socket = io(); }
  // players are hardcoded for now, eventually this will be aggregated from somewhere else
  // so it's sort of a stub that will be adjusted later
  // $scope.players = [{name: 'Bob', score: 5}, {name: 'Fred', score: 7}, {name: 'Jenny', score: 4}]
  // $scope.title = "SHAKE RACE!!!";

  $scope.socket.on('moveracer', function (data) {
    // change the 1 object in the array that matches (data)
    $scope.players = [{name: "Tester Testington", score: data.shakes}]; // DEBUG DEBUG DEBUG
    // $scope.players = [{name: "Tester Testington", score: data.shakes, userId: data.userId }]; // test data
    $scope.apply();
  });

});
<commit_msg>fixing in progress<commit_after>const ACCELERATION_REPORT_MIN = 12;

app.controller('PhoneController', function($scope) {
  $scope.greeting = 'Hello World Of Physics!';
  const socket = io();

  $scope.emitShake = function(data) {
    return socket.emit('shake', data);
  };

  $scope.handleDeviceAccelChange = function(e) {
    event.preventDefault();

    $scope.totalAcceleration = event.acceleration.x +
      event.acceleration.y +
      event.acceleration.z;

    if($scope.totalAcceleration > 50) {
      $scope.emitShake({shakeIncrement: 1});
    }
    // $scope.accelEventData = event.acceleration;
    $scope.$apply();
  };
  window.addEventListener('devicemotion', $scope.handleDeviceAccelChange, true);

}).controller('PlayGridController', function($scope) {
  // players are hardcoded for now, eventually this will be aggregated from somewhere else
  // so it's sort of a stub that will be adjusted later
  // $scope.players = [{name: 'Bob', score: 5}, {name: 'Fred', score: 7}, {name: 'Jenny', score: 4}]

  socket.on('moveracer', function (data) {
    // change the 1 object in the array that matches (data)
    $scope.players = [{name: "Tester Testington", score: data.shakes, userId: data.userId }]; // test data
    $scope.apply();
  });

  $scope.title = "SHAKE RACE!!!";
});
<|endoftext|>


<commit_before>var log = require('../../../log').logger('sbp');
var g2 = require('../../../g2');
var sb3_commands = require('../sb3_commands');
var config = require('../../../config');

// Move X axis
exports.MX = function(args) {
	x = args[0];
	if(isNaN(x)) { throw "Invalid MX argument: " + x; }
	this.emit_gcode("G1X" + x + " F" + ( 60.0 * config.opensbp.get('movexy_speed')));
	this.cmd_posx = x;
};

// Move Y axis
exports.MY = function(args) {
	this.emit_gcode("G1Y" + args[0] + " F" + ( 60.0 * config.opensbp.get('movexy_speed')));
	this.cmd_posy = args[0];
};

// Move Z axis
exports.MZ = function(args) {
	this.emit_gcode("G1Z" + args[0] + " F" + ( 60.0 * config.opensbp.get('movez_speed')));
	this.cmd_posz = args[0];
};

// Move A axis
exports.MA = function(args) {
	this.emit_gcode("G1A" + args[0] + " F" + ( 60.0 * config.opensbp.get('movea_speed')));
	this.cmd_posa = args[0];
};

// Move B axis
exports.MB = function(args) {
	this.emit_gcode("G1B" + args[0] + " F" + ( 60.0 * config.opensbp.get('moveb_speed')));
	this.cmd_posb = args[0];
};

// Move C axis
exports.MC = function(args) {
	this.emit_gcode("G1C" + args[0] + " F" + ( 60.0 * config.opensbp.get('movec_speed')));
	this.cmd_posc = args[0];
};

// Move 2 axes (XY). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M2 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move 3 axes (XYZ). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M3 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move 4 axes (XYZA). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M4 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move 5 axes (XYZAB). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M5 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	if (args[4] !== undefined) {
		outStr = outStr + "B" + args[4];
		this.cmd_posb = args[4];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move all 6 axes (XYZABC). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M6 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	if (args[4] !== undefined) {
		outStr = outStr + "B" + args[4];
		this.cmd_posb = args[4];
	}
	if (args[5] !== undefined) {
		outStr = outStr + "C" + args[5];
		this.cmd_posc = args[5];
	}
	outStr = outStr + "F" + ( 60 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move to the XY home position (0,0)
exports.MH = function(args) {
	this.emit_gcode("G1X0Y0F" + ( 60 * config.opensbp.get('movexy_speed')));
	this.cmd_posx = 0;
	this.cmd_posy = 0;
};

// Set the Move (cut) speed for any of the 6 axes
exports.MS = function(args, callback) {

	log.debug( "MS - args = " + args );

	var speed_change = 0.0;
	var g2_values = {};
	var sbp_values = {};

	if (args[0] !== undefined) {
		speed_change = args[0];
		g2_values.xfr = g2_values.yfr = (60 * speed_change);
		sbp_values.movexy_speed = speed_change;
	}
	if (args[1] !== undefined) {
		speed_change = args[1];
		if ( speed_change !== undefined ){
			g2_values.zfr = (60 * speed_change);
			sbp_values.movez_speed = speed_change;
		}
	}
	if (args[2] !== undefined) {
		speed_change = args[2];
		if ( speed_change !== undefined ){
			g2_values.afr = (60 * speed_change);
			sbp_values.movea_speed = speed_change;
		}
	}
	if (args[3] !== undefined) {
		speed_change = args[3];
		if ( speed_change !== undefined ){
			g2_values.bfr = (60 * speed_change);
			sbp_values.moveb_speed = speed_change;
		}
	}
	if (args[4] !== undefined) {
		speed_change = args[4];
		if ( speed_change !== undefined ){
			g2_values.cfr = (60 * speed_change);
			sbp_values.movec_speed = speed_change;
		}
	}

	log.debug( "MS-g2_values = " + JSON.stringify(g2_values) );
	log.debug( "MS-sbp_values = " + JSON.stringify(sbp_values) );

	// We have created the objects containing both the values to set on the G2 driver as well as for shopbot
	// Now send them to their appropriate places (shopbot first, followed by G2)
	config.opensbp.setMany(sbp_values, function(err, values) {
		log.debug("SBP_setMany values:" + JSON.stringify(values));
		config.driver.setMany(g2_values, function(err, values) {
			log.debug("G2_setMany values:" + JSON.stringify(values));
			callback();
		});
	});

};

exports.MI = function(args) {
	//?????????????????????????????????????????????
};

exports.MO = function(args) {
	//?????????????????????????????????????????????
};
<commit_msg>Move changes<commit_after>var log = require('../../../log').logger('sbp');
var g2 = require('../../../g2');
var sb3_commands = require('../sb3_commands');
var config = require('../../../config');

// Move X axis
exports.MX = function(args) {
	var x = args[0];
	var xyspeed = config.opensbp.get('movexy_speed');
	if(isNaN(x)) { throw "Invalid MX argument: " + x; }
	this.emit_gcode("G1X" + x + " F" + ( 60.0 * xyspeed ));
	this.cmd_posx = x;
};

// Move Y axis
exports.MY = function(args) {
	var y = args[0];
	var xyspeed = config.opensbp.get('movexy_speed');
	if(isNaN(y)) { throw "Invalid MY argument: " + y; }
	this.emit_gcode("G1Y" + args[0] + " F" + ( 60.0 * xyspeed));
	this.cmd_posy = args[0];
};

// Move Z axis
exports.MZ = function(args) {
	var z = args[0];
	var zspeed = config.opensbp.get('movez_speed');
	if(isNaN(z)) { throw "Invalid MZ argument: " + z; }
	this.emit_gcode("G1Z" + args[0] + " F" + ( 60.0 * zspeed));
	this.cmd_posz = args[0];
};

// Move A axis
exports.MA = function(args) {
	var a = args[0];
	var aspeed = config.opensbp.get('movea_speed');
	if(isNaN(a)) { throw "Invalid MA argument: " + a; }
	this.emit_gcode("G1A" + args[0] + " F" + ( 60.0 * aspeed));
	this.cmd_posa = args[0];
};

// Move B axis
exports.MB = function(args) {
	var b = args[0];
	var bspeed = config.opensbp.get('moveb_speed');
	if(isNaN(b)) { throw "Invalid MB argument: " + b; }
	this.emit_gcode("G1B" + args[0] + " F" + ( 60.0 * bspeed));
	this.cmd_posb = args[0];
};

// Move C axis
exports.MC = function(args) {
	var c = args[0];
	var cspeed = config.opensbp.get('moveb_speed');
	if(isNaN(c)) { throw "Invalid MC argument: " + c; }
	this.emit_gcode("G1C" + args[0] + " F" + ( 60.0 * cspeed));
	this.cmd_posc = args[0];
};

// Move 2 axes (XY). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M2 = function(args) {
	var xyspeed = config.opensbp.get('movexy_speed');
	var outStr = "G1";
	if (args[0] !== undefined) {
		var x = args[0];
		if(isNaN(x)) { throw "Invalid MX argument: " + x; }
		outStr = outStr + "X" + x;
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		var y = args[0];
		if(isNaN(y)) { throw "Invalid MX argument: " + y; }
		outStr = outStr + "Y" + y;
		this.cmd_posy = args[1];
	}
	outStr = outStr + "F" + ( 60.0 * xyspeed);
	this.emit_gcode(outStr);
};

// Move 3 axes (XYZ). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M3 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move 4 axes (XYZA). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M4 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move 5 axes (XYZAB). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M5 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	if (args[4] !== undefined) {
		outStr = outStr + "B" + args[4];
		this.cmd_posb = args[4];
	}
	outStr = outStr + "F" + ( 60.0 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move all 6 axes (XYZABC). This is a modal command, any axis location that is left out
//   of the command will default to it's current position and not move
exports.M6 = function(args) {
	var outStr = "G1";
	if (args[0] !== undefined) {
		outStr = outStr + "X" + args[0];
		this.cmd_posx = args[0];
	}
	if (args[1] !== undefined) {
		outStr = outStr + "Y" + args[1];
		this.cmd_posy = args[1];
	}
	if (args[2] !== undefined) {
		outStr = outStr + "Z" + args[2];
		this.cmd_posz = args[2];
	}
	if (args[3] !== undefined) {
		outStr = outStr + "A" + args[3];
		this.cmd_posa = args[3];
	}
	if (args[4] !== undefined) {
		outStr = outStr + "B" + args[4];
		this.cmd_posb = args[4];
	}
	if (args[5] !== undefined) {
		outStr = outStr + "C" + args[5];
		this.cmd_posc = args[5];
	}
	outStr = outStr + "F" + ( 60 * config.opensbp.get('movexy_speed'));
	this.emit_gcode(outStr);
};

// Move to the XY home position (0,0)
exports.MH = function(args) {
	this.emit_gcode("G1X0Y0F" + ( 60 * config.opensbp.get('movexy_speed')));
	this.cmd_posx = 0;
	this.cmd_posy = 0;
};

// Set the Move (cut) speed for any of the 6 axes
exports.MS = function(args, callback) {

	log.debug( "MS - args = " + args );

	var speed_change = 0.0;
	var g2_values = {};
	var sbp_values = {};

	if (args[0] !== undefined) {
		speed_change = args[0];
		g2_values.xfr = g2_values.yfr = (60 * speed_change);
		sbp_values.movexy_speed = speed_change;
	}
	if (args[1] !== undefined) {
		speed_change = args[1];
		if ( speed_change !== undefined ){
			g2_values.zfr = (60 * speed_change);
			sbp_values.movez_speed = speed_change;
		}
	}
	if (args[2] !== undefined) {
		speed_change = args[2];
		if ( speed_change !== undefined ){
			g2_values.afr = (60 * speed_change);
			sbp_values.movea_speed = speed_change;
		}
	}
	if (args[3] !== undefined) {
		speed_change = args[3];
		if ( speed_change !== undefined ){
			g2_values.bfr = (60 * speed_change);
			sbp_values.moveb_speed = speed_change;
		}
	}
	if (args[4] !== undefined) {
		speed_change = args[4];
		if ( speed_change !== undefined ){
			g2_values.cfr = (60 * speed_change);
			sbp_values.movec_speed = speed_change;
		}
	}

	log.debug( "MS-g2_values = " + JSON.stringify(g2_values) );
	log.debug( "MS-sbp_values = " + JSON.stringify(sbp_values) );

	// We have created the objects containing both the values to set on the G2 driver as well as for shopbot
	// Now send them to their appropriate places (shopbot first, followed by G2)
	config.opensbp.setMany(sbp_values, function(err, values) {
		log.debug("SBP_setMany values:" + JSON.stringify(values));
		config.driver.setMany(g2_values, function(err, values) {
			log.debug("G2_setMany values:" + JSON.stringify(values));
			callback();
		});
	});

};

exports.MI = function(args) {
	//?????????????????????????????????????????????
};

exports.MO = function(args) {
	//?????????????????????????????????????????????
};
<|endoftext|>


<commit_before>import {expect} from 'chai';

import walkTree from '../../src/utils/walkTree';

describe('walkTree', function () {

    it('should do nothing when not provided with no data', function () {
        const result = [];
        walkTree();
        expect(result).to.deep.equal([]);
    });

    it('should do nothing when not provided with a callback function', function () {
        const result = [];
        walkTree(paragraphsWithNamespaces);
        expect(result).to.deep.equal([]);
    });

    it('should produce the correct payloads for each tree step', function () {
        const result = [];
        walkTree(paragraphsWithNamespaces, payload => result.push(payload));
        expect(result).to.deep.equal(expectedPayload);
    });

});

const paragraphsWithNamespaces = {
    elements: [{
        'type': 'element',
        'name': 'paragraph',
        'attributes': {
            'xmlns': 'http://example.com/ns',
            'xmlns:ns': 'http://example.com/ns',
        },
        'elements': [
            {'type': 'text', 'text': 'This '},
            {
                'type': 'element',
                'name': 'ns:emph',
                'attributes': {
                    'style': 'italics',
                },
                'elements': [
                    {'type': 'text', 'text': 'should be '},
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes': {
                            'xmlns': 'http://example.com/another',
                        },
                        'elements': [
                            {'type': 'text', 'text': 'a'},
                        ],
                    },
                    {'type': 'text', 'text': ' complete'},
                ],
            },
            {'type': 'text', 'text': ' sentence.'},
        ],
    }],
};

const expectedPayload = [
    {
        'jml':
            {
                'type': 'text',
                'text': 'This ',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': 'should be ',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': 'a',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/another',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/another',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'a',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/another',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'bold',
                'attributes':
                    {
                        'xmlns': 'http://example.com/another',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'a',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/another',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': ' complete',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'ns:emph',
                'attributes':
                    {
                        'style': 'italics',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'should be ',
                    },
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/another',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'a',
                            },
                        ],
                    },
                    {
                        'type': 'text',
                        'text': ' complete',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': ' sentence.',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'paragraph',
                'attributes':
                    {
                        'xmlns': 'http://example.com/ns',
                        'xmlns:ns': 'http://example.com/ns',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'This ',
                    },
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                    {
                        'type': 'text',
                        'text': ' sentence.',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
    },
];<commit_msg>Improve test description<commit_after>import {expect} from 'chai';

import walkTree from '../../src/utils/walkTree';

describe('walkTree', function () {

    it('should do nothing when called without arguments', function () {
        const result = [];
        walkTree();
        expect(result).to.deep.equal([]);
    });

    it('should do nothing when not provided with a callback function', function () {
        const result = [];
        walkTree(paragraphsWithNamespaces);
        expect(result).to.deep.equal([]);
    });

    it('should produce the correct payloads for each tree step', function () {
        const result = [];
        walkTree(paragraphsWithNamespaces, payload => result.push(payload));
        expect(result).to.deep.equal(expectedPayload);
    });

});

const paragraphsWithNamespaces = {
    elements: [{
        'type': 'element',
        'name': 'paragraph',
        'attributes': {
            'xmlns': 'http://example.com/ns',
            'xmlns:ns': 'http://example.com/ns',
        },
        'elements': [
            {'type': 'text', 'text': 'This '},
            {
                'type': 'element',
                'name': 'ns:emph',
                'attributes': {
                    'style': 'italics',
                },
                'elements': [
                    {'type': 'text', 'text': 'should be '},
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes': {
                            'xmlns': 'http://example.com/another',
                        },
                        'elements': [
                            {'type': 'text', 'text': 'a'},
                        ],
                    },
                    {'type': 'text', 'text': ' complete'},
                ],
            },
            {'type': 'text', 'text': ' sentence.'},
        ],
    }],
};

const expectedPayload = [
    {
        'jml':
            {
                'type': 'text',
                'text': 'This ',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': 'should be ',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': 'a',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/another',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/another',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'a',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/another',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'bold',
                'attributes':
                    {
                        'xmlns': 'http://example.com/another',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'a',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/another',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': ' complete',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'ns:emph',
                'attributes':
                    {
                        'style': 'italics',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'should be ',
                    },
                    {
                        'type': 'element',
                        'name': 'bold',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/another',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'a',
                            },
                        ],
                    },
                    {
                        'type': 'text',
                        'text': ' complete',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'text',
                'text': ' sentence.',
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
        'parent':
            {
                'jml':
                    {
                        'type': 'element',
                        'name': 'paragraph',
                        'attributes':
                            {
                                'xmlns': 'http://example.com/ns',
                                'xmlns:ns': 'http://example.com/ns',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'This ',
                            },
                            {
                                'type': 'element',
                                'name': 'ns:emph',
                                'attributes':
                                    {
                                        'style': 'italics',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'should be ',
                                    },
                                    {
                                        'type': 'element',
                                        'name': 'bold',
                                        'attributes':
                                            {
                                                'xmlns': 'http://example.com/another',
                                            },
                                        'elements': [
                                            {
                                                'type': 'text',
                                                'text': 'a',
                                            },
                                        ],
                                    },
                                    {
                                        'type': 'text',
                                        'text': ' complete',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' sentence.',
                            },
                        ],
                    },
                'namespaces': [
                    {
                        'uri': 'http://example.com/ns',
                    },
                    {
                        'prefix': 'ns',
                        'uri': 'http://example.com/ns',
                    },
                ],
            },
    },
    {
        'jml':
            {
                'type': 'element',
                'name': 'paragraph',
                'attributes':
                    {
                        'xmlns': 'http://example.com/ns',
                        'xmlns:ns': 'http://example.com/ns',
                    },
                'elements': [
                    {
                        'type': 'text',
                        'text': 'This ',
                    },
                    {
                        'type': 'element',
                        'name': 'ns:emph',
                        'attributes':
                            {
                                'style': 'italics',
                            },
                        'elements': [
                            {
                                'type': 'text',
                                'text': 'should be ',
                            },
                            {
                                'type': 'element',
                                'name': 'bold',
                                'attributes':
                                    {
                                        'xmlns': 'http://example.com/another',
                                    },
                                'elements': [
                                    {
                                        'type': 'text',
                                        'text': 'a',
                                    },
                                ],
                            },
                            {
                                'type': 'text',
                                'text': ' complete',
                            },
                        ],
                    },
                    {
                        'type': 'text',
                        'text': ' sentence.',
                    },
                ],
            },
        'namespaces': [
            {
                'uri': 'http://example.com/ns',
            },
            {
                'prefix': 'ns',
                'uri': 'http://example.com/ns',
            },
        ],
    },
];<|endoftext|>


<commit_before>/**
 * Created with JetBrains PhpStorm.
 * User: jasonsykes
 * Date: 1/7/13
 * Time: 11:37 AM
 * To change this template use File | Settings | File Templates.
 */
var Templates = {
	thumbPanel:   "
{{name}}

{{desc}}",
	alertMessage: '
' + 'x' + '{{message}}' + '
',
	gridTemplate: '
' + '
' + '
' + 'Table Name	' + '
' + '
' + '
' + '{{#table}}' + '
' + '{{name}}	' + '
 ' + '{{/table}}' + '
' + '
',
	appTemplate: '
' + '
' + '
' + 'Applications	' + '
' + '
' + '
' + '{{#record}}' + '
' + '{{fields.label}}	' + '
 ' + '{{/record}}' + '
' + '
',
	appIconTemplate: '
' + '{{#Applications.app_groups}}' + '
' + '
' + '' + '
' + '
' + '' + '
' +

					 '
{{name}}
' + //'
{{description}}
' +
					 '
' + '' + '
' + '
' + '
' + '
' + '{{#apps}}' +

					 '
' + '' + '
{{name}}
' + '
{{description}}
' + '' + '
' + '{{/apps}}' + '
' + '
' + '
' + '
' + '{{/Applications.app_groups}}' + '{{#Applications.mnm_ng_apps}}' + '
' + '
' + '' + '
' + '
' + '' + '
' + '
Default Group
' + //'
{{description}}
' +
					 '
' + '' + '
' + '
' + '
' + '
' + '{{#apps}}' + '
' + '' + '
{{name}}
' + '
{{description}}
' + '' + '
' + '{{/apps}}' + '
' + '
' + '
' + '
' + '{{/Applications.mnm_ng_apps}}' + '
',
	navBarTemplate: '
' + '
' + '
' + '

' + '' + '' + '' + '' + '' + '
' + '

' + ' ' + '
' + '' + '{{#User.activeSession}}' + '' + '' + '' + '' + '{{#User.is_sys_admin}}' + '' + '{{/User.is_sys_admin}}' + '' + '' + '{{/User.activeSession}}' + '{{^User.activeSession}}' + '{{#User.allow_guest_user}}' + '' + '' + '{{/User.allow_guest_user}}' + '' + '

 Sign In' + '{{#User.allow_open_registration}}' + '

 Create Account' + '{{/User.allow_open_registration}}' + '{{/User.activeSession}}' + '
' + '
' + '
',
	errorTemplate: '{{#error}}
' + '<button type="button" class="close" data-dismiss="alert">x</button>' + '{{message}}' + '
{{/error}}',
	loadTemplate: function (template, data, renderTo) {
		var processTpl;
		processTpl = Mustache.to_html(template, data);
		$('#' + renderTo).html(processTpl);

	}
};
<commit_msg>reverted templates.js<commit_after>/**
 * Created with JetBrains PhpStorm.
 * User: jasonsykes
 * Date: 1/7/13
 * Time: 11:37 AM
 * To change this template use File | Settings | File Templates.
 */
var Templates = {
	thumbPanel:      "
{{name}}

{{desc}}",
	alertMessage:    '
' +
					 'x' +
					 '{{message}}' +
	'
',
	gridTemplate:    '
' +
					 '
' +
					 '
' +
					 'Table Name	' +
					 '
' +
					 '
' +
					 '
' +
					 '{{#table}}' +
					 '
' +
					 '{{name}}	' +
					 '
 ' +
					 '{{/table}}' +
					 '
' +
	'
',
	appTemplate:     '
' +
					 '
' +
					 '
' +
					 'Applications	' +
					 '
' +
					 '
' +
					 '
' +
					 '{{#record}}' +
					 '
' +
					 '{{fields.label}}	' +
					 '
 ' +
					 '{{/record}}' +
					 '
' +
	'
',
	appIconTemplate: '
' +
					 '{{#Applications.app_groups}}' +
					 '
' +
					 '
' +
					 '' +
					 '
' +
					 '
' +
					 '' +
					 '
' +

					 '
{{name}}
' +
						 //'
{{description}}
' +
					 '
' +
					 '' +
					 '
' +
					 '
' +
					 '
' +
					 '
' +
					 '{{#apps}}' +

					 '
' +
					 '' +
					 '
{{name}}
' +
					 '
{{description}}
' +
					 '' +
					 '
' +
					 '{{/apps}}' +
					 '
' +
					 '
' +
					 '
' +
					 '
' +
					 '{{/Applications.app_groups}}' +
					 '{{#Applications.mnm_ng_apps}}' +
					 '
' +
					 '
' +
					 '' +
					 '
' +
					 '
' +
					 '' +
					 '
' +
					 '
Default Group
' +
						 //'
{{description}}
' +
					 '
' +
					 '' +
					 '
' +
					 '
' +
					 '
' +
					 '
' +
					 '{{#apps}}' +
					 '
' +
					 '' +
					 '
{{name}}
' +
					 '
{{description}}
' +
					 '' +
					 '
' +
					 '{{/apps}}' +
					 '
' +
					 '
' +
					 '
' +
					 '
' +
					 '{{/Applications.mnm_ng_apps}}' +
	'
',
    navBarTemplate :
        '
' +
            '
' +
            '
' +
            '

' +
            '' +
            '' +
            '' +
            '' +
            '' +
            '
' +
            '

' +
					 ' ' +
					 '
' +
					 '' +
					 '{{#User.activeSession}}' +
					 '' +
					 '' +
					 '' +
					 '' +
					 '{{#User.is_sys_admin}}' +
					 '' +
					 '{{/User.is_sys_admin}}' +
					 '' +
					 '' +
					 '{{/User.activeSession}}' +
					 '{{^User.activeSession}}' +
					 '{{#User.allow_guest_user}}' +
					 '' +
					 '' +
					 '{{/User.allow_guest_user}}' +
					 '' +
					 '

 Sign In' +
					 '{{#User.allow_open_registration}}' +
					 '

 Create Account' +
					 '{{/User.allow_open_registration}}' +
					 '{{/User.activeSession}}' +
            '
' +
            '
' +
	'
',
	errorTemplate:   '{{#error}}
' +
					 '<button type="button" class="close" data-dismiss="alert">x</button>' +
					 '{{message}}' +
	'
{{/error}}',
	loadTemplate:    function (template, data, renderTo) {
		var processTpl;
		processTpl = Mustache.to_html(template, data);
		$('#' + renderTo).html(processTpl);

	}
};
<|endoftext|>


<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/* jshint asi: true */
/* jshint esversion: 6 */

(function () { try {
  var resolve = (tree, context) => {
    var node = tree.body ? tree.body[0] : tree

    var traverse = (expr, computed) => {
      var args, op1, op2, value

      switch (expr.type) {
        case 'ExpressionStatement':
          return traverse(expr.expression)

        case 'ArrayExpression':
          value = []
          expr.elements.forEach((element) => { value.push(traverse(element)) })
          return value

        case 'BinaryExpression':
          op1 = traverse(expr.left)
          op2 = traverse(expr.right)
          switch (expr.operator) {
            case '==': return (op1 === op2)
            case '===': return (op1 === op2)
            case '!=': return (op1 !== op2)
            case '!==': return (op1 !== op2)
            case '<': return (op1 < op2)
            case '<=': return (op1 <= op2)
            case '>': return (op1 > op2)
            case '>=': return (op1 >= op2)
            case '<<': return (op1 << op2)
            case '>>': return (op1 >> op2)
            case '>>>': return (op1 >>> op2)
            case '+': return (op1 + op2)
            case '-': return (op1 - op2)
            case '*': return (op1 * op2)
            case '/': return (op1 < op2)
            case '%': return (op1 % op2)
            case '|': return (op1 | op2)
            case '^': return (op1 ^ op2)
            case '&': return (op1 & op2)
            case 'in': return (op1 in op2)

            default:
              throw new Error('unsupported binary operator: ' + expr.operator)
          }
          break

        case 'CallExpression':
          op1 = expr.callee
          if (op1.type !== 'MemberExpression') throw new Error('unexpected callee: ' + op1.type)
          value = traverse(op1.object, op1.computed)
          args = []
          expr['arguments'].forEach((argument) => { args.push(traverse(argument)) })
          return value[traverse(op1.property, true)].apply(value, args)

        case 'NewExpression':
          op1 = expr.callee
          if (op1.type !== 'Identifier') throw new Error('unexpected callee: ' + op1.type)
          if (op1.name !== 'Set') throw new Error('only new Set(...) is allowed, not new ' + op1.name)
          args = []
          expr['arguments'].forEach((argument) => { args.push(traverse(argument)) })
          return new Set(args[0])

        case 'ConditionalExpression':
          return (traverse(expr.test) ? traverse(expr.consequent) : traverse(expr.alternate))

        case 'LogicalExpression':
          op1 = traverse(expr.left)
          op2 = traverse(expr.right)
          switch (expr.operator) {
            case '&&': return (op1 && op2)
            case '||': return (op1 || op2)

            default:
              throw new Error('unsupported logical operator: ' + expr.operator)
          }
          break

        case 'MemberExpression':
          value = traverse(expr.object, expr.computed)
          return value[traverse(expr.property)]

        case 'UnaryExpression':
          if (!expr.prefix) throw new Error('unsupported unary operator suffix: ' + expr.operator)

          op1 = traverse(expr.argument)
          switch (expr.operator) {
            case '-': return (-op1)
            case '+': return (+op1)
            case '!': return (!op1)
            case '~': return (~op1)
            case 'typeof': return (typeof op1)

            default:
              throw new Error('unsupported unary operator: ' + expr.operator)
          }
          break

        case 'Identifier':
          value = computed ? expr.name : context[expr.name]
          if (value !== 'eval') return value
          throw new Error('eval not allowed in expression')

        case 'Literal':
          return (expr.regex ? new RegExp(expr.regex.pattern) : expr.value)

        default:
          throw new Error('unsupported evaluation type: ' + expr.type)
      }
    }

    if ((!node) || (node.type !== 'ExpressionStatement')) throw new Error('invalid expression')

    return traverse(node.expression)
  }

  if ((typeof module !== 'undefined') &&  (typeof exports !== 'undefined')) {
    module.exports = { resolve: resolve }

    return
  }

  if (window.top !== window.self) return

  var results = { timestamp: new Date().getTime(), protocol: document.location.protocol }

  var node = document.head.querySelector("link[rel='icon']")
  if (!node) node = document.head.querySelector("link[rel='shortcut icon']")
  if (node) results.faviconURL = node.getAttribute('href')

  var pubinfo = chrome.ipc.sendSync('ledger-publisher', document.location.href)
  if ((!pubinfo) || (!pubinfo.context) || (!pubinfo.rules)) return console.log('no pubinfo avaialble')

  var context = pubinfo.context
  var rules = pubinfo.rules

  var i, publisher, rule
  for (i = 0; i < rules.length; i++) {
    rule = rules[i]

    try {
      if (!resolve(rule.condition, context)) continue
    } catch (ex) {
      console.log('error resolving rule at position #' + i + '\n' + ex.stack)
      continue
    }

    if (rule.publisher) {
      context.node = document.body.querySelector(rule.publisher.selector)
      publisher = resolve(rule.publisher.consequent, context)
    } else {
      delete context.node
      publisher = rule.consequent ? resolve(rule.consequent, context) : rule.consequent
    }
    if (publisher === '') continue

    if (typeof publisher !== 'string') return console.log('NOT a string')

    publisher.replace(new RegExp('^./+|./+$', 'g'), '')

    results.publisher = publisher
    if (rule.faviconURL) {
      context.node = document.body.querySelector(rule.faviconURL.selector)
      results.faviconURL = resolve(rule.faviconURL.consequent, context)
    }
    break
  }

  if (results.faviconURL) {
    var prefix = (results.faviconURL.indexOf('//') === 0) ? document.location.protocol
                 : (results.faviconURL.indexOf('/') === 0) ? document.location.protocol + '//' + document.location.host
                 : (results.faviconURL.indexOf(':') === -1) ? document.location.protocol + '//' + document.location.host + '/'
                 : null
    if (prefix) results.faviconURL = prefix + results.faviconURL
  }

  results.url = window.location.href
  chrome.ipc.send('dispatch-action', JSON.stringify({
    location: window.location.href,
    actionType: 'event-set-page-info',
    pageInfo: results
  }))
} catch (ex) { console.log(ex.toString() + '\n' + ex.stack) } })()
<commit_msg>explain why the argument length may be at most one<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/* jshint asi: true */
/* jshint esversion: 6 */

(function () { try {
  var resolve = (tree, context) => {
    var node = tree.body ? tree.body[0] : tree

    var traverse = (expr, computed) => {
      var args, op1, op2, value

      switch (expr.type) {
        case 'ExpressionStatement':
          return traverse(expr.expression)

        case 'ArrayExpression':
          value = []
          expr.elements.forEach((element) => { value.push(traverse(element)) })
          return value

        case 'BinaryExpression':
          op1 = traverse(expr.left)
          op2 = traverse(expr.right)
          switch (expr.operator) {
            case '==': return (op1 === op2)
            case '===': return (op1 === op2)
            case '!=': return (op1 !== op2)
            case '!==': return (op1 !== op2)
            case '<': return (op1 < op2)
            case '<=': return (op1 <= op2)
            case '>': return (op1 > op2)
            case '>=': return (op1 >= op2)
            case '<<': return (op1 << op2)
            case '>>': return (op1 >> op2)
            case '>>>': return (op1 >>> op2)
            case '+': return (op1 + op2)
            case '-': return (op1 - op2)
            case '*': return (op1 * op2)
            case '/': return (op1 < op2)
            case '%': return (op1 % op2)
            case '|': return (op1 | op2)
            case '^': return (op1 ^ op2)
            case '&': return (op1 & op2)
            case 'in': return (op1 in op2)

            default:
              throw new Error('unsupported binary operator: ' + expr.operator)
          }
          break

        case 'CallExpression':
          op1 = expr.callee
          if (op1.type !== 'MemberExpression') throw new Error('unexpected callee: ' + op1.type)
          value = traverse(op1.object, op1.computed)
          args = []
          expr['arguments'].forEach((argument) => { args.push(traverse(argument)) })
          return value[traverse(op1.property, true)].apply(value, args)

        case 'NewExpression':
          op1 = expr.callee
          if (op1.type !== 'Identifier') throw new Error('unexpected callee: ' + op1.type)
          if (op1.name !== 'Set') throw new Error('only new Set(...) is allowed, not new ' + op1.name)
          args = []
          expr['arguments'].forEach((argument) => { args.push(traverse(argument)) })
          if (args.length > 1) throw new Error('Set(...) takes at most one argument')
          return new Set(args[0])

        case 'ConditionalExpression':
          return (traverse(expr.test) ? traverse(expr.consequent) : traverse(expr.alternate))

        case 'LogicalExpression':
          op1 = traverse(expr.left)
          op2 = traverse(expr.right)
          switch (expr.operator) {
            case '&&': return (op1 && op2)
            case '||': return (op1 || op2)

            default:
              throw new Error('unsupported logical operator: ' + expr.operator)
          }
          break

        case 'MemberExpression':
          value = traverse(expr.object, expr.computed)
          return value[traverse(expr.property)]

        case 'UnaryExpression':
          if (!expr.prefix) throw new Error('unsupported unary operator suffix: ' + expr.operator)

          op1 = traverse(expr.argument)
          switch (expr.operator) {
            case '-': return (-op1)
            case '+': return (+op1)
            case '!': return (!op1)
            case '~': return (~op1)
            case 'typeof': return (typeof op1)

            default:
              throw new Error('unsupported unary operator: ' + expr.operator)
          }
          break

        case 'Identifier':
          value = computed ? expr.name : context[expr.name]
          if (value !== 'eval') return value
          throw new Error('eval not allowed in expression')

        case 'Literal':
          return (expr.regex ? new RegExp(expr.regex.pattern) : expr.value)

        default:
          throw new Error('unsupported evaluation type: ' + expr.type)
      }
    }

    if ((!node) || (node.type !== 'ExpressionStatement')) throw new Error('invalid expression')

    return traverse(node.expression)
  }

  if ((typeof module !== 'undefined') &&  (typeof exports !== 'undefined')) {
    module.exports = { resolve: resolve }

    return
  }

  if (window.top !== window.self) return

  var results = { timestamp: new Date().getTime(), protocol: document.location.protocol }

  var node = document.head.querySelector("link[rel='icon']")
  if (!node) node = document.head.querySelector("link[rel='shortcut icon']")
  if (node) results.faviconURL = node.getAttribute('href')

  var pubinfo = chrome.ipc.sendSync('ledger-publisher', document.location.href)
  if ((!pubinfo) || (!pubinfo.context) || (!pubinfo.rules)) return console.log('no pubinfo avaialble')

  var context = pubinfo.context
  var rules = pubinfo.rules

  var i, publisher, rule
  for (i = 0; i < rules.length; i++) {
    rule = rules[i]

    try {
      if (!resolve(rule.condition, context)) continue
    } catch (ex) {
      console.log('error resolving rule at position #' + i + '\n' + ex.stack)
      continue
    }

    if (rule.publisher) {
      context.node = document.body.querySelector(rule.publisher.selector)
      publisher = resolve(rule.publisher.consequent, context)
    } else {
      delete context.node
      publisher = rule.consequent ? resolve(rule.consequent, context) : rule.consequent
    }
    if (publisher === '') continue

    if (typeof publisher !== 'string') return console.log('NOT a string')

    publisher.replace(new RegExp('^./+|./+$', 'g'), '')

    results.publisher = publisher
    if (rule.faviconURL) {
      context.node = document.body.querySelector(rule.faviconURL.selector)
      results.faviconURL = resolve(rule.faviconURL.consequent, context)
    }
    break
  }

  if (results.faviconURL) {
    var prefix = (results.faviconURL.indexOf('//') === 0) ? document.location.protocol
                 : (results.faviconURL.indexOf('/') === 0) ? document.location.protocol + '//' + document.location.host
                 : (results.faviconURL.indexOf(':') === -1) ? document.location.protocol + '//' + document.location.host + '/'
                 : null
    if (prefix) results.faviconURL = prefix + results.faviconURL
  }

  results.url = window.location.href
  chrome.ipc.send('dispatch-action', JSON.stringify({
    location: window.location.href,
    actionType: 'event-set-page-info',
    pageInfo: results
  }))
} catch (ex) { console.log(ex.toString() + '\n' + ex.stack) } })()
<|endoftext|>


<commit_before>/*
 * @providesModule FancyLabel
 * @flow
 */

'use strict';

var React = require('react-native');
var ReactPropTypes = require('react/lib/ReactPropTypes');
var StyleSheetPropType = require('react-native/Libraries/StyleSheet/StyleSheetPropType');
var ColorPropType = require('react-native/Libraries/StyleSheet/ColorPropType');
var ViewStylePropTypes = require('react-native/Libraries/Components/View/ViewStylePropTypes');
var StyleSheetValidation = require('react-native/Libraries/StyleSheet/StyleSheetValidation')
var PointPropType = require('react-native/Libraries/StyleSheet/PointPropType');

var _ = require('lodash');

var {
  requireNativeComponent,
  processColor,
  View,
  Text,
  StyleSheet
} = React;

var FancyLabelOwnPropTypes = {
  fadeTruncatingMode: ReactPropTypes.oneOf(
    [ 'None', 'Tail', 'Head', 'HeadAndTail']
  ),
  textInsets: ReactPropTypes.object,
  automaticallyAdjustTextInsets: ReactPropTypes.bool,
  letterSpacing: ReactPropTypes.number,
  baselineAdjustment: ReactPropTypes.oneOf(
    [ 'AlignBaselines', 'AlignCenters', 'None']
  ),
  minimumScaleFactor: ReactPropTypes.number,
  textAlign: ReactPropTypes.oneOf(
    ['auto', 'left', 'right', 'center', 'justify']
  ),
  strokeSize: ReactPropTypes.number,
  strokeColor: ColorPropType,
  strokePosition: ReactPropTypes.oneOf(
    ["Outside", "Center", "Inside"]
  ),

  textShadowOffset: PointPropType,
  textShadowBlur: ReactPropTypes.number,
  textShadowColor: ColorPropType,

  innerTextShadowOffset: PointPropType,
  innerTextShadowBlur: ReactPropTypes.number,
  innerTextShadowColor: ColorPropType,

  gradientStartPoint: PointPropType,
  gradientEndPoint: PointPropType,

  gradientColors: ReactPropTypes.arrayOf(ColorPropType),

  fontFamily: ReactPropTypes.string,
  fontSize: ReactPropTypes.number,
  color: ColorPropType,
  adjustsFontSizeToFitWidth: ReactPropTypes.bool
};

var FancyLabelPropTypes = Object.assign(
  Object.create(ViewStylePropTypes), FancyLabelOwnPropTypes);

class FancyLabel extends React.Component {
  static propTypes = {
      ...View.propTypes,
      style: StyleSheetPropType(FancyLabelPropTypes)
  };

  render() {
    let styleProps = StyleSheet.flatten(this.props.style);

    let viewProps = {
      ...this.props,
      style: {
        ..._.omit(styleProps, _.keys(FancyLabelOwnPropTypes))
      }
    };

    let labelProps = _.pick(styleProps, _.keys(FancyLabelOwnPropTypes));
    let textProps = _.pick(styleProps, ['fontSize', 'fontFamily', 'letterSpacing']);

    if (processColor) {
      const colorPropKeys = ["gradientColors", "strokeColor", "textShadowColor", "innerTextShadowColor", "color"];
      _.assign(labelProps, _.mapValues(_.pick(styleProps, colorPropKeys), c => processColor(c)));
    }

    return (
      <RNFancyLabel  {..._.merge(viewProps, labelProps)} >
        <Text style={[textProps]}>
          {this.props.children}
        </Text>
      </RNFancyLabel>
    );
  }
}

let RNFancyLabel = React.requireNativeComponent('MFLReactFancyLabel', FancyLabel, {
  nativeOnly :  _.mapValues(FancyLabelOwnPropTypes, (o) => true)
});

StyleSheetValidation.addValidStylePropTypes(FancyLabelPropTypes);

module.exports = FancyLabel;
<commit_msg>Fix for 0.32<commit_after>/*
 * @providesModule FancyLabel
 * @flow
 */

var React = require('react');
var ReactNative = require('react-native');
var ReactPropTypes = require('react/lib/ReactPropTypes');
var StyleSheetPropType = require('react-native/Libraries/StyleSheet/StyleSheetPropType');
var ColorPropType = require('react-native/Libraries/StyleSheet/ColorPropType');
var ViewStylePropTypes = require('react-native/Libraries/Components/View/ViewStylePropTypes');
var StyleSheetValidation = require('react-native/Libraries/StyleSheet/StyleSheetValidation')
var PointPropType = require('react-native/Libraries/StyleSheet/PointPropType');

var _ = require('lodash');

import {
  requireNativeComponent,
  processColor,
  View,
  Text,
  StyleSheet
} from 'react-native';

var FancyLabelOwnPropTypes = {
  fadeTruncatingMode: ReactPropTypes.oneOf(
    [ 'None', 'Tail', 'Head', 'HeadAndTail']
  ),
  textInsets: ReactPropTypes.object,
  automaticallyAdjustTextInsets: ReactPropTypes.bool,
  letterSpacing: ReactPropTypes.number,
  baselineAdjustment: ReactPropTypes.oneOf(
    [ 'AlignBaselines', 'AlignCenters', 'None']
  ),
  minimumScaleFactor: ReactPropTypes.number,
  textAlign: ReactPropTypes.oneOf(
    ['auto', 'left', 'right', 'center', 'justify']
  ),
  strokeSize: ReactPropTypes.number,
  strokeColor: ColorPropType,
  strokePosition: ReactPropTypes.oneOf(
    ["Outside", "Center", "Inside"]
  ),

  textShadowOffset: PointPropType,
  textShadowBlur: ReactPropTypes.number,
  textShadowColor: ColorPropType,

  innerTextShadowOffset: PointPropType,
  innerTextShadowBlur: ReactPropTypes.number,
  innerTextShadowColor: ColorPropType,

  gradientStartPoint: PointPropType,
  gradientEndPoint: PointPropType,

  gradientColors: ReactPropTypes.arrayOf(ColorPropType),

  fontFamily: ReactPropTypes.string,
  fontSize: ReactPropTypes.number,
  color: ColorPropType,
  adjustsFontSizeToFitWidth: ReactPropTypes.bool
};

var FancyLabelPropTypes = Object.assign(
  Object.create(ViewStylePropTypes), FancyLabelOwnPropTypes);

class FancyLabel extends React.Component {
  static propTypes = {
      ...View.propTypes,
      style: StyleSheetPropType(FancyLabelPropTypes)
  };

  render() {
    let styleProps = StyleSheet.flatten(this.props.style);

    let viewProps = {
      ...this.props,
      style: {
        ..._.omit(styleProps, _.keys(FancyLabelOwnPropTypes))
      }
    };

    let labelProps = _.pick(styleProps, _.keys(FancyLabelOwnPropTypes));
    let textProps = _.pick(styleProps, ['fontSize', 'fontFamily', 'letterSpacing']);

    if (processColor) {
      const colorPropKeys = ["gradientColors", "strokeColor", "textShadowColor", "innerTextShadowColor", "color"];
      _.assign(labelProps, _.mapValues(_.pick(styleProps, colorPropKeys), c => processColor(c)));
    }

    return (
      <RNFancyLabel  {..._.merge(viewProps, labelProps)} >
        <Text style={[textProps]}>
          {this.props.children}
        </Text>
      </RNFancyLabel>
    );
  }
}

var RNFancyLabel = requireNativeComponent('MFLReactFancyLabel', FancyLabel, {
  nativeOnly :  _.mapValues(FancyLabelOwnPropTypes, (o) => true)
});

StyleSheetValidation.addValidStylePropTypes(FancyLabelPropTypes);

module.exports = FancyLabel;
<|endoftext|>