UNPKG

react-7segments

Version:

React component for displaying seven segments

731 lines (592 loc) 21.1 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("React")); else if(typeof define === 'function' && define.amd) define(["React"], factory); else if(typeof exports === 'object') exports["React7Seg"] = factory(require("React")); else root["React7Seg"] = factory(root["React"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_2__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _SegDigit = __webpack_require__(1); var _SegDigit2 = _interopRequireDefault(_SegDigit); var _SegGroup = __webpack_require__(8); var _SegGroup2 = _interopRequireDefault(_SegGroup); var _SegMap = __webpack_require__(11); var _SegMap2 = _interopRequireDefault(_SegMap); var _SegUtil = __webpack_require__(12); var _SegUtil2 = _interopRequireDefault(_SegUtil); var _SegPoints = __webpack_require__(3); var _SegPoints2 = _interopRequireDefault(_SegPoints); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.Digit = _SegDigit2.default; exports.Group = _SegGroup2.default; exports.Map = _SegMap2.default; exports.Util = _SegUtil2.default; exports.Points = _SegPoints2.default; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = __webpack_require__(2); var _react2 = _interopRequireDefault(_react); var _SegPoints = __webpack_require__(3); var _SegPoints2 = _interopRequireDefault(_SegPoints); __webpack_require__(4); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _react2.default.createClass({ displayName: 'SegDigit', getDefaultProps: function getDefaultProps() { return { digitClass: 'seven-seg-digit', onClass: 'seven-seg-on', points: _SegPoints2.default, width: 75, height: 150 }; }, shouldComponentUpdate: function shouldComponentUpdate(nextProps) { return this.props.value !== nextProps.value; }, isOn: function isOn(pos) { return this.props.value & pos ? this.props.onClass : undefined; }, render: function render() { var digitWrapperStyle = { width: this.props.width + 'px', height: this.props.height + 'px' }; var polylines = []; for (var i = 0; i < 7; i++) { polylines[i] = _react2.default.createElement('polyline', { points: this.props.points[i], className: this.isOn(1 << i), key: i }); } return _react2.default.createElement( 'div', { className: 'seven-seg-digit-wrapper', style: digitWrapperStyle }, _react2.default.createElement( 'svg', { className: this.props.digitClass, viewBox: '0 0 57 80', version: '1.1', xmlns: 'http://www.w3.org/2000/svg', focusable: 'false' }, _react2.default.createElement( 'g', null, polylines, _react2.default.createElement('circle', { cx: '52', cy: '75', r: '5', className: this.isOn(128) }) ) ) ); } }); /***/ }, /* 2 */ /***/ function(module, exports) { module.exports = React; /***/ }, /* 3 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = ["11 0, 37 0, 42 5, 37 10, 11 10, 6 5", //1 "38 11, 43 6, 48 11, 48 34, 43 39, 38 34", //2 "38 46, 43 41, 48 46, 48 69, 43 74, 38 69", //4 "11 70, 37 70, 42 75, 37 80, 11 80, 6 75", //8 "0 46, 5 41, 10 46, 10 69, 5 74, 0 69", //16 "0 11, 5 6, 10 11, 10 34, 5 39, 0 34", //32 "11 35, 37 35, 42 40, 37 45, 11 45, 6 40" //64 ]; /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { // style-loader: Adds some css to the DOM by adding a <style> tag // load the styles var content = __webpack_require__(5); if(typeof content === 'string') content = [[module.id, content, '']]; // add the styles to the DOM var update = __webpack_require__(7)(content, {}); if(content.locals) module.exports = content.locals; // Hot Module Replacement if(false) { // When the styles change, update the <style> tags if(!content.locals) { module.hot.accept("!!./../../node_modules/css-loader/index.js!./../../node_modules/sass-loader/index.js?outputStyle=expanded&!./SegDigit.scss", function() { var newContent = require("!!./../../node_modules/css-loader/index.js!./../../node_modules/sass-loader/index.js?outputStyle=expanded&!./SegDigit.scss"); if(typeof newContent === 'string') newContent = [[module.id, newContent, '']]; update(newContent); }); } // When the module is disposed, remove the <style> tags module.hot.dispose(function() { update(); }); } /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { exports = module.exports = __webpack_require__(6)(); // imports // module exports.push([module.id, ".seven-seg-digit {\n overflow: hidden;\n stroke-width: 0;\n height: 100%;\n width: 100%;\n background-color: Black;\n fill: #320000;\n}\n\n.seven-seg-on {\n fill: red;\n}\n\n.seven-seg-digit-wrapper {\n display: inline-block;\n}\n", ""]); // exports /***/ }, /* 6 */ /***/ function(module, exports) { /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ // css base code, injected by the css-loader module.exports = function() { var list = []; // return the list of modules as css string list.toString = function toString() { var result = []; for(var i = 0; i < this.length; i++) { var item = this[i]; if(item[2]) { result.push("@media " + item[2] + "{" + item[1] + "}"); } else { result.push(item[1]); } } return result.join(""); }; // import a list of modules into the list list.i = function(modules, mediaQuery) { if(typeof modules === "string") modules = [[null, modules, ""]]; var alreadyImportedModules = {}; for(var i = 0; i < this.length; i++) { var id = this[i][0]; if(typeof id === "number") alreadyImportedModules[id] = true; } for(i = 0; i < modules.length; i++) { var item = modules[i]; // skip already imported module // this implementation is not 100% perfect for weird media query combinations // when a module is imported multiple times with different media queries. // I hope this will never occur (Hey this way we have smaller bundles) if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { if(mediaQuery && !item[2]) { item[2] = mediaQuery; } else if(mediaQuery) { item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; } list.push(item); } } }; return list; }; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var stylesInDom = {}, memoize = function(fn) { var memo; return function () { if (typeof memo === "undefined") memo = fn.apply(this, arguments); return memo; }; }, isOldIE = memoize(function() { return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase()); }), getHeadElement = memoize(function () { return document.head || document.getElementsByTagName("head")[0]; }), singletonElement = null, singletonCounter = 0, styleElementsInsertedAtTop = []; module.exports = function(list, options) { if(false) { if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment"); } options = options || {}; // Force single-tag solution on IE6-9, which has a hard limit on the # of <style> // tags it will allow on a page if (typeof options.singleton === "undefined") options.singleton = isOldIE(); // By default, add <style> tags to the bottom of <head>. if (typeof options.insertAt === "undefined") options.insertAt = "bottom"; var styles = listToStyles(list); addStylesToDom(styles, options); return function update(newList) { var mayRemove = []; for(var i = 0; i < styles.length; i++) { var item = styles[i]; var domStyle = stylesInDom[item.id]; domStyle.refs--; mayRemove.push(domStyle); } if(newList) { var newStyles = listToStyles(newList); addStylesToDom(newStyles, options); } for(var i = 0; i < mayRemove.length; i++) { var domStyle = mayRemove[i]; if(domStyle.refs === 0) { for(var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j](); delete stylesInDom[domStyle.id]; } } }; } function addStylesToDom(styles, options) { for(var i = 0; i < styles.length; i++) { var item = styles[i]; var domStyle = stylesInDom[item.id]; if(domStyle) { domStyle.refs++; for(var j = 0; j < domStyle.parts.length; j++) { domStyle.parts[j](item.parts[j]); } for(; j < item.parts.length; j++) { domStyle.parts.push(addStyle(item.parts[j], options)); } } else { var parts = []; for(var j = 0; j < item.parts.length; j++) { parts.push(addStyle(item.parts[j], options)); } stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts}; } } } function listToStyles(list) { var styles = []; var newStyles = {}; for(var i = 0; i < list.length; i++) { var item = list[i]; var id = item[0]; var css = item[1]; var media = item[2]; var sourceMap = item[3]; var part = {css: css, media: media, sourceMap: sourceMap}; if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]}); else newStyles[id].parts.push(part); } return styles; } function insertStyleElement(options, styleElement) { var head = getHeadElement(); var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1]; if (options.insertAt === "top") { if(!lastStyleElementInsertedAtTop) { head.insertBefore(styleElement, head.firstChild); } else if(lastStyleElementInsertedAtTop.nextSibling) { head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling); } else { head.appendChild(styleElement); } styleElementsInsertedAtTop.push(styleElement); } else if (options.insertAt === "bottom") { head.appendChild(styleElement); } else { throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'."); } } function removeStyleElement(styleElement) { styleElement.parentNode.removeChild(styleElement); var idx = styleElementsInsertedAtTop.indexOf(styleElement); if(idx >= 0) { styleElementsInsertedAtTop.splice(idx, 1); } } function createStyleElement(options) { var styleElement = document.createElement("style"); styleElement.type = "text/css"; insertStyleElement(options, styleElement); return styleElement; } function createLinkElement(options) { var linkElement = document.createElement("link"); linkElement.rel = "stylesheet"; insertStyleElement(options, linkElement); return linkElement; } function addStyle(obj, options) { var styleElement, update, remove; if (options.singleton) { var styleIndex = singletonCounter++; styleElement = singletonElement || (singletonElement = createStyleElement(options)); update = applyToSingletonTag.bind(null, styleElement, styleIndex, false); remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true); } else if(obj.sourceMap && typeof URL === "function" && typeof URL.createObjectURL === "function" && typeof URL.revokeObjectURL === "function" && typeof Blob === "function" && typeof btoa === "function") { styleElement = createLinkElement(options); update = updateLink.bind(null, styleElement); remove = function() { removeStyleElement(styleElement); if(styleElement.href) URL.revokeObjectURL(styleElement.href); }; } else { styleElement = createStyleElement(options); update = applyToTag.bind(null, styleElement); remove = function() { removeStyleElement(styleElement); }; } update(obj); return function updateStyle(newObj) { if(newObj) { if(newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) return; update(obj = newObj); } else { remove(); } }; } var replaceText = (function () { var textStore = []; return function (index, replacement) { textStore[index] = replacement; return textStore.filter(Boolean).join('\n'); }; })(); function applyToSingletonTag(styleElement, index, remove, obj) { var css = remove ? "" : obj.css; if (styleElement.styleSheet) { styleElement.styleSheet.cssText = replaceText(index, css); } else { var cssNode = document.createTextNode(css); var childNodes = styleElement.childNodes; if (childNodes[index]) styleElement.removeChild(childNodes[index]); if (childNodes.length) { styleElement.insertBefore(cssNode, childNodes[index]); } else { styleElement.appendChild(cssNode); } } } function applyToTag(styleElement, obj) { var css = obj.css; var media = obj.media; var sourceMap = obj.sourceMap; if(media) { styleElement.setAttribute("media", media) } if(styleElement.styleSheet) { styleElement.styleSheet.cssText = css; } else { while(styleElement.firstChild) { styleElement.removeChild(styleElement.firstChild); } styleElement.appendChild(document.createTextNode(css)); } } function updateLink(linkElement, obj) { var css = obj.css; var media = obj.media; var sourceMap = obj.sourceMap; if(sourceMap) { // http://stackoverflow.com/a/26603875 css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */"; } var blob = new Blob([css], { type: "text/css" }); var oldSrc = linkElement.href; linkElement.href = URL.createObjectURL(blob); if(oldSrc) URL.revokeObjectURL(oldSrc); } /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; Object.defineProperty(exports, "__esModule", { value: true }); var _react = __webpack_require__(2); var _react2 = _interopRequireDefault(_react); __webpack_require__(9); var _SegMap = __webpack_require__(11); var _SegMap2 = _interopRequireDefault(_SegMap); var _SegDigit = __webpack_require__(1); var _SegDigit2 = _interopRequireDefault(_SegDigit); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _react2.default.createClass({ displayName: 'SegGroup', getDefaultProps: function getDefaultProps() { return { value: '', align: undefined, map: _SegMap2.default }; }, isDot: function isDot(item) { return item === '.' || item === this.props.map['.']; }, getSegArray: function getSegArray(value) { var map = this.props.map; var newArr = [], cnt = 0; var size = this.props.size === void 0 ? value.length : this.props.size, i = 0; for (var len = value.length; i < len && cnt < size; cnt++, i++) { var item = value[i] || 0; if (this.isDot(item)) { // when item is dot var prev = value[i - 1]; if (prev === void 0 || this.isDot(prev)) newArr[cnt] = map['.'];else newArr[--cnt] |= map['.']; } else if (typeof item === 'string') { newArr[cnt] = map[item]; } else if (typeof item === 'number') { newArr[cnt] = item; } } if (this.isDot(value[i])) newArr[cnt - 1] |= map['.']; size = this.props.size === void 0 ? cnt : this.props.size; if (this.props.align === void 0 || this.props.align === 'right') return new Array(size - cnt).concat(newArr);else return newArr.concat(new Array(size - cnt)); }, getSegDigits: function getSegDigits(arr) { var digits = []; for (var i = 0; i < arr.length; i++) { digits[i] = _react2.default.createElement(_SegDigit2.default, _extends({ key: i }, this.props.digitOptions, { value: arr[i] })); } return digits; }, render: function render() { var digits = this.getSegDigits(this.getSegArray(this.props.value)); return _react2.default.createElement( 'div', { className: 'seven-seg-group' }, digits ); } }); /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { // style-loader: Adds some css to the DOM by adding a <style> tag // load the styles var content = __webpack_require__(10); if(typeof content === 'string') content = [[module.id, content, '']]; // add the styles to the DOM var update = __webpack_require__(7)(content, {}); if(content.locals) module.exports = content.locals; // Hot Module Replacement if(false) { // When the styles change, update the <style> tags if(!content.locals) { module.hot.accept("!!./../../node_modules/css-loader/index.js!./../../node_modules/sass-loader/index.js?outputStyle=expanded&!./SegGroup.scss", function() { var newContent = require("!!./../../node_modules/css-loader/index.js!./../../node_modules/sass-loader/index.js?outputStyle=expanded&!./SegGroup.scss"); if(typeof newContent === 'string') newContent = [[module.id, newContent, '']]; update(newContent); }); } // When the module is disposed, remove the <style> tags module.hot.dispose(function() { update(); }); } /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { exports = module.exports = __webpack_require__(6)(); // imports // module exports.push([module.id, "", ""]); // exports /***/ }, /* 11 */ /***/ function(module, exports) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { '1': 6, '2': 91, '3': 79, '4': 102, '5': 109, '6': 125, '7': 39, '8': 127, '9': 111, '0': 63, '-': 64, '_': 8, '.': 128, ' ': 0, 'S': 109, 'E': 121, 'G': 61 }; /***/ }, /* 12 */ /***/ function(module, exports) { 'use strict'; exports.arrToSegNum = function (arr) { var pos = 1, ret = 0; for (var i = 0, len = 8; i < len; pos <<= 1, i++) { if (!!arr[i] && arr[i] != '0') ret |= pos; } return ret; }; exports.segNumToArr = function (val, oldVal) { var pos = 1; val = val || 0; var xor = oldVal == void 0 ? val : val ^ oldVal; var array = []; for (var i = 0; i < 8; pos <<= 1, i++) { if (pos & xor) { array[i] = !!(pos & val); } } return array; }; /***/ } /******/ ]) }); ;