Created
November 25, 2019 12:00
-
-
Save PhilCai1993/ea89fa4636f6b5d9889f967a2ccbf1b2 to your computer and use it in GitHub Desktop.
safari_jsbox.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ©2019, Bionic Reading® */ | |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BionicReader = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | |
(function (process){ | |
"use strict"; | |
var isNode = false; | |
try { | |
isNode = process ? true : false; | |
} catch (error) {} | |
//console.log('isNode', isNode) | |
var _require = require("./Parser"), | |
calculateFixationWordIndex = _require.calculateFixationWordIndex, | |
shouldHighlightWord = _require.shouldHighlightWord; | |
var _require2 = require("./libs/Utils"), | |
isNumber = _require2.isNumber, | |
leftTrim = _require2.leftTrim; | |
/* define patterns */ | |
var REGEX_PATTERN = { | |
NEWLINE: '\r\n', | |
WHITESPACE: '\t ', | |
WORD_CHARACTERS: 'a-zA-Z0-9äöüÄÖÜß' | |
}; | |
var MULTI_WORD_SEPERATORS = ['-', '’']; //['-', '@', '/', '.'] | |
var HTML_TAGS_TO_CLEAN = ['span']; // ['span','i','b','strong'] | |
/* import black list */ | |
var blackList = require('./lists/de/blacklist.json'); | |
/* import particles list*/ | |
var particles = require('./lists/de/particles.json'); | |
/* import pronouns list */ | |
var pronouns = require('./lists/de/pronouns.json'); | |
/** | |
* Bionic Reader class | |
* @param {String} content - Html content | |
* @param {Integer} fixation | |
* @param {Integer} saccade | |
* @param {bool} particlesEnabled | |
* @param {bool} pronounsEnabled | |
*/ | |
function BionicReader() { | |
var fixation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | |
var saccade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; | |
var particlesEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | |
var pronounsEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; | |
this.fixation = fixation; | |
this.saccade = saccade; | |
this.particlesEnabled = particlesEnabled; | |
this.pronounsEnabled = pronounsEnabled; | |
//rizzi - unused | |
// this.setContent = function(content) | |
// this.getRenderedContent = function() | |
this.renderNode = function (node) { | |
//rizzi | |
var me = this; | |
this.numberNotHighlightedWords = 0; | |
this.suffixPrevWord = ''; | |
var textNodes = this.fetchAllTextNodes(node); | |
textNodes.map(function (_ref) { | |
var el = _ref.el, | |
startNewSentence = _ref.startNewSentence; | |
var textNode = el; | |
textNode.text = function () { | |
return this.nodeValue; | |
}; | |
var template = document.createElement('span'); | |
template.innerHTML = me.parseStringFromTextNode(textNode, startNewSentence); | |
textNode.parentNode.replaceChild(template, textNode); | |
}); | |
}; | |
/** | |
* Parse highlighted content from given textNode | |
* @param {TextNode} textNode | |
* @param {Boolean} isStartOfNewSentence | |
* @returns {String} | |
*/ | |
this.parseStringFromTextNode = function (textNode, isStartOfNewSentence) { | |
var me = this; | |
var textValue = textNode.text(); | |
if (textValue.trim() === "") { | |
return textValue; // rizzi => textNode -> textValue | |
} | |
var parsedWords = this.splitWordsFromString(textValue).map(function (words) { | |
return words.map(function (word, index) { | |
if (me.hasWordTextToHighlight(word)) { | |
//rizzi => this -> me | |
if (isStartOfNewSentence || shouldHighlightWord(me.numberOfNotHighlightedWords, me.saccade)) { | |
var parsedWord = me.parseWord(word); | |
if (parsedWord.highlighted) { | |
me.numberOfNotHighlightedWords = 0; //rizzi => this -> me | |
isStartOfNewSentence = false; | |
word = parsedWord.word; | |
} | |
} | |
me.numberOfNotHighlightedWords++; | |
} | |
return word; | |
}).join(" "); | |
}); | |
return parsedWords.join("\n"); | |
}; | |
/** | |
* Check if given word has text to highlight | |
* @param {String} word | |
* @returns {Boolean} | |
*/ | |
this.hasWordTextToHighlight = function (word) { | |
if (!word || word.trim() === "") { | |
return false; | |
} | |
var preparedWord = word.trim().toLowerCase(); | |
if (isNumber(word) || blackList.indexOf(preparedWord) >= 0) { | |
return false; | |
} | |
if (!this.particlesEnabled && particles.indexOf(preparedWord) >= 0) { | |
return false; | |
} | |
if (!this.pronounsEnabled && pronouns.indexOf(preparedWord) >= 0) { | |
return false; | |
} | |
return new RegExp('[' + REGEX_PATTERN.WORD_CHARACTERS + ']+', 'g').exec(word) !== null; | |
}; | |
/** | |
* Fetch prefix and suffix from given word | |
* @param word | |
* @returns {Object<{prefix,suffix}>} | |
*/ | |
this.fetchPrefixAndSuffix = function (word) { | |
var prefixClean = new RegExp('^([^' + REGEX_PATTERN.WORD_CHARACTERS + ']+)', 'g'); | |
var suffixClean = new RegExp('([^' + REGEX_PATTERN.WORD_CHARACTERS + ']+)$', 'g'); | |
var prefix = prefixClean.exec(word); | |
prefix = prefix && prefix.length > 1 ? prefix[1] : ''; | |
var suffix = suffixClean.exec(word.substr(prefix.length)); | |
suffix = suffix && suffix.length > 1 ? suffix[1] : ''; | |
return { prefix: prefix, suffix: suffix }; | |
}; | |
/** | |
* Parse given word | |
* @param {String} word | |
* @returns {Object<{word, highlighted}>} | |
*/ | |
this.parseWord = function (word) { | |
var response = function response(word) { | |
var highlighted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | |
return { word: word, highlighted: highlighted }; | |
}; | |
var _fetchPrefixAndSuffix = this.fetchPrefixAndSuffix(word), | |
prefix = _fetchPrefixAndSuffix.prefix, | |
suffix = _fetchPrefixAndSuffix.suffix; | |
if (suffix.length + prefix.length < word.length) { | |
word = word.substr(prefix.length, word.length - prefix.length - suffix.length); | |
} | |
if (!this.hasWordTextToHighlight(word)) return response(word); | |
// handle special characters | |
var highlighted = false; | |
for (var i = 0; i < MULTI_WORD_SEPERATORS.length; i++) { | |
var character = MULTI_WORD_SEPERATORS[i]; | |
if (word.indexOf(character) > 0) { | |
var words = word.split(character); | |
var highlighted = false; | |
var joinedWords = words.map(this.parseWord.bind(this)).map(function (parsedWord) { | |
if (highlighted === false && parsedWord.highlighted) highlighted = true; | |
return parsedWord.word; | |
}).join(character); | |
return response(prefix + joinedWords + suffix, highlighted); | |
} | |
} | |
var splitIndex = calculateFixationWordIndex(word, this.fixation); | |
if (splitIndex > 0) { | |
var wordHightlightPart = word.substr(0, splitIndex); | |
var wordRemainsPart = word.substr(splitIndex, word.length); | |
word = prefix + this.wrapText(wordHightlightPart) + wordRemainsPart + suffix; | |
} | |
return response(word, splitIndex > 0); | |
}; | |
/** | |
* Wrap text with span element (to highlight) | |
*/ | |
this.wrapText = function (text) { | |
//rizzi | |
//return $('<div>').append( $('<span>').addClass('bionic').addClass('b').text(text) ).html() | |
return "<span class=\"bionic-b\">" + text + "</span>"; | |
}; | |
//rizzi - unused | |
// this.cleanHtml = function() | |
/** | |
* Fetch all text nodes from given document | |
* @param {Document} doc | |
* @returns {Array<Text Node>} - array of Text nodes (DOM) | |
*/ | |
this.fetchAllTextNodes = function (doc) { | |
var nodes = []; | |
var isNewTextBlock = true; | |
var walkNodes = function walkNodes(parentNode) { | |
//rizzi | |
if ( parentNode.nodeName == 'PRE' || parentNode.nodeName == 'CODE' ) { | |
return | |
} | |
if (parentNode.nodeName === 'DIV' || parentNode.nodeName === 'P') { | |
isNewTextBlock = true; | |
} | |
for (var index = 0; index < parentNode.childNodes.length; index++) { | |
var child = parentNode.childNodes[index]; | |
if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() != "") { | |
if (isNewTextBlock) { | |
child.textContent = leftTrim(child.textContent); | |
} | |
nodes.push({ el: child, startNewSentence: isNewTextBlock }); | |
if (isNewTextBlock) { | |
isNewTextBlock = false; | |
} | |
} | |
if (child && child.childNodes) walkNodes(child); | |
} | |
}; | |
walkNodes(doc); | |
return nodes; | |
}; | |
/** | |
* Split words from given string | |
* @param {String} text | |
* @returns {Array<String>} - array of words | |
*/ | |
this.splitWordsFromString = function (text) { | |
var wordList = text.split(new RegExp('[' + REGEX_PATTERN.NEWLINE + ']+', 'g')); | |
wordList = wordList.map(function (childrens) { | |
return childrens.split(new RegExp('[' + REGEX_PATTERN.WHITESPACE + ']+', 'g')); | |
}); | |
return wordList; | |
}; | |
return this; | |
} | |
module.exports = BionicReader; | |
}).call(this,require('_process')) | |
},{"./Parser":2,"./libs/Utils":3,"./lists/de/blacklist.json":18,"./lists/de/particles.json":19,"./lists/de/pronouns.json":20,"_process":21}],2:[function(require,module,exports){ | |
"use strict"; | |
var ExprParser = require('./libs/expr-eval').default.Parser; | |
/** | |
* Define rule conditions | |
*/ | |
var RULE_CONDITIONS = { | |
GREATER_THAN: "GREATER_THAN", | |
GREATER_THAN_AND_EQUALS: "GREATER_THAN_AND_EQUALS", | |
LESS_THAN: "LESS_THAN", | |
LESS_THAN_AND_EQUALS: "LESS_THAN_AND_EQUALS", | |
EQUALS: "EQUALS" | |
/** | |
* Define rules | |
*/ | |
};var RULES = { | |
FIXATION: { | |
1: { | |
name: "ultralong", | |
rules: [{ | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 5 | |
}, { | |
type: RULE_CONDITIONS.LESS_THAN_AND_EQUALS, | |
value: 6 | |
}], | |
calc: 'x-2' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 1 | |
}], | |
calc: 'floor(x*(1/6*5))' | |
}] | |
}, | |
2: { | |
name: "long", | |
rules: [{ | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 5 | |
}], | |
calc: 'round(x*(1/6*4))' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.EQUALS, | |
value: 4 | |
}], | |
calc: 'x-2' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.LESS_THAN_AND_EQUALS, | |
value: 3 | |
}], | |
calc: 'min(x,1)' | |
}] | |
}, | |
3: { | |
name: "medium", | |
rules: [{ | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 4 | |
}], | |
calc: 'round(x*(1/6*3))' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.LESS_THAN_AND_EQUALS, | |
value: 3 | |
}], | |
calc: 'min(x,1)' | |
}] | |
}, | |
4: { | |
name: "short", | |
rules: [{ | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 13 | |
}, { | |
type: RULE_CONDITIONS.LESS_THAN_AND_EQUALS, | |
value: 20 | |
}], | |
calc: 'round((x*(1/6*2)))+1' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 5 | |
}], | |
calc: 'round(x*(1/6*2))' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.EQUALS, | |
value: 4 | |
}], | |
calc: 'x-2' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.LESS_THAN_AND_EQUALS, | |
value: 3 | |
}, { | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 2 | |
}], | |
calc: 'min(x, 1)' | |
}] | |
}, | |
5: { | |
name: "ultrashort", | |
rules: [{ | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 17 | |
}], | |
calc: 'ceil(x*(1/9*2))+1' | |
}, { | |
conditions: [{ | |
type: RULE_CONDITIONS.GREATER_THAN_AND_EQUALS, | |
value: 2 | |
}], | |
calc: 'ceil(x*(1/9*2))' | |
}] | |
} | |
} | |
/** | |
* Calculate Fixation index from given word | |
* @param {String} word | |
* @param {Integer} fixation - fixation number | |
* @returns {Integer} | |
*/ | |
};function calculateFixationWordIndex(word) { | |
var fixation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | |
var rules = RULES.FIXATION[fixation] && RULES.FIXATION[fixation].rules; | |
if (!rules) { | |
//console.warn('invalid fixation: ', fixation); | |
return 0; | |
} | |
if (!word || word.length === 0) { | |
//console.warn('invalid word length, word: ', word); | |
return 0; | |
} | |
for (var index = 0; index < rules.length; index++) { | |
var rule = rules[index]; | |
var conditions = rule.conditions; | |
var matched = null; | |
var matchedIndex = null; | |
conditions.map(function (condition, index) { | |
matched = (matched === null || matched === true) && validateCondition(word, condition); | |
if (matchedIndex === null && matched) { | |
matchedIndex = index; | |
} | |
}); | |
if (matched) { | |
return calculateWordIndex(word, rule); | |
} | |
} | |
return 0; | |
} | |
/** | |
* Should highlight word | |
* @param {Integer} numberNotHighlightedWords | |
* @param {Integer} saccade - saccade number | |
*/ | |
function shouldHighlightWord(numberNotHighlightedWords) { | |
var saccade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; | |
if (saccade === 10) { | |
return true; | |
} | |
if (saccade >= 20 && saccade <= 80) { | |
var nthWordNumberToHightlight = saccade / 10; | |
// console.log('Number.isInteger', numberNotHighlightedWords, nthWordNumberToHightlight, Number.isInteger(numberNotHighlightedWords / nthWordNumberToHightlight)); | |
return numberNotHighlightedWords > 0 && Number.isInteger(numberNotHighlightedWords / nthWordNumberToHightlight); | |
} | |
return true; | |
} | |
/** | |
* Validate condition | |
* @param {String} word | |
* @param {Object<type,value>} condition | |
*/ | |
function validateCondition(word, condition) { | |
var type = condition.type, | |
value = condition.value; | |
var wordLength = word && word.length || 0; | |
var valid = false; | |
switch (type) { | |
case RULE_CONDITIONS.EQUALS: | |
valid = wordLength === value; | |
//console.log('+++ RULE_CONDITIONS.EQUALS', valid, wordLength + ' === ' + value ) | |
break; | |
case RULE_CONDITIONS.GREATER_THAN: | |
valid = wordLength > value; | |
//console.log('+++ RULE_CONDITIONS.GREATER_THAN', valid, wordLength + ' > ' + value ) | |
break; | |
case RULE_CONDITIONS.GREATER_THAN_AND_EQUALS: | |
valid = wordLength >= value; | |
//console.log('+++ RULE_CONDITIONS.GREATER_THAN_AND_EQUALS', valid, wordLength + ' >= ' + value ) | |
break; | |
case RULE_CONDITIONS.LESS_THAN: | |
valid = wordLength < value; | |
//console.log('+++ RULE_CONDITIONS.LESS_THAN', valid, wordLength + ' < ' + value ) | |
break; | |
case RULE_CONDITIONS.LESS_THAN_AND_EQUALS: | |
valid = wordLength <= value; | |
//console.log('+++ RULE_CONDITIONS.LESS_THAN_AND_EQUALS', valid, wordLength + ' <= ' + value ) | |
break; | |
default: | |
break; | |
} | |
return valid; | |
} | |
/** | |
* Calculate word index | |
* @param {String} word | |
* @param {Object<conditions, calc>} rule | |
* @returns {UInteger} | |
*/ | |
function calculateWordIndex(word, rule) { | |
var wordLength = word && word.length || 0; | |
//console.log('Parser', ExprParser) | |
var calculated = ExprParser.evaluate(rule.calc, { x: wordLength }); | |
return calculated; | |
} | |
module.exports = { | |
calculateFixationWordIndex: calculateFixationWordIndex, | |
shouldHighlightWord: shouldHighlightWord | |
}; | |
},{"./libs/expr-eval":4}],3:[function(require,module,exports){ | |
"use strict"; | |
/*function isNumber(word) { | |
var numWord = parseFloat(word) | |
if (numWord == word) { | |
return word | |
} | |
if (word.indexOf(',') < 0) { | |
return false | |
} | |
return isNumber(word.replace(',', '.')) | |
}*/ | |
function isNumber(word) { | |
if (!word || word.trim() === "") return false; | |
var reg = /^[0-9.:,]*$/gm; | |
return reg.test(word.trim()); | |
} | |
function leftTrim(text) { | |
return text.replace(/^\s+/g, ''); | |
} | |
module.exports = { | |
isNumber: isNumber, | |
leftTrim: leftTrim | |
}; | |
},{}],4:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
var _expression = require('./src/expression'); | |
var _parser = require('./src/parser'); | |
/*! | |
Based on ndef.parser, by Raphael Graf([email protected]) | |
http://www.undefined.ch/mparser/index.html | |
Ported to JavaScript and modified by Matthew Crumley ([email protected], http://silentmatt.com/) | |
You are free to use and modify this code in anyway you find useful. Please leave this comment in the code | |
to acknowledge its original source. If you feel like it, I enjoy hearing about projects that use my code, | |
but don't feel like you have to let me know or ask permission. | |
*/ | |
exports.default = { | |
Parser: _parser.Parser, | |
Expression: _expression.Expression | |
}; | |
},{"./src/expression":8,"./src/parser":13}],5:[function(require,module,exports){ | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = contains; | |
function contains(array, obj) { | |
for (var i = 0; i < array.length; i++) { | |
if (array[i] === obj) { | |
return true; | |
} | |
} | |
return false; | |
} | |
},{}],6:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = evaluate; | |
var _instruction = require('./instruction'); | |
function evaluate(tokens, expr, values) { | |
var nstack = []; | |
var n1, n2, n3; | |
var f; | |
for (var i = 0; i < tokens.length; i++) { | |
var item = tokens[i]; | |
var type = item.type; | |
if (type === _instruction.INUMBER) { | |
nstack.push(item.value); | |
} else if (type === _instruction.IOP2) { | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
if (item.value === 'and') { | |
nstack.push(n1 ? !!evaluate(n2, expr, values) : false); | |
} else if (item.value === 'or') { | |
nstack.push(n1 ? true : !!evaluate(n2, expr, values)); | |
} else { | |
f = expr.binaryOps[item.value]; | |
nstack.push(f(n1, n2)); | |
} | |
} else if (type === _instruction.IOP3) { | |
n3 = nstack.pop(); | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
if (item.value === '?') { | |
nstack.push(evaluate(n1 ? n2 : n3, expr, values)); | |
} else { | |
f = expr.ternaryOps[item.value]; | |
nstack.push(f(n1, n2, n3)); | |
} | |
} else if (type === _instruction.IVAR) { | |
if (item.value in expr.functions) { | |
nstack.push(expr.functions[item.value]); | |
} else { | |
var v = values[item.value]; | |
if (v !== undefined) { | |
nstack.push(v); | |
} else { | |
throw new Error('undefined variable: ' + item.value); | |
} | |
} | |
} else if (type === _instruction.IOP1) { | |
n1 = nstack.pop(); | |
f = expr.unaryOps[item.value]; | |
nstack.push(f(n1)); | |
} else if (type === _instruction.IFUNCALL) { | |
var argCount = item.value; | |
var args = []; | |
while (argCount-- > 0) { | |
args.unshift(nstack.pop()); | |
} | |
f = nstack.pop(); | |
if (f.apply && f.call) { | |
nstack.push(f.apply(undefined, args)); | |
} else { | |
throw new Error(f + ' is not a function'); | |
} | |
} else if (type === _instruction.IEXPR) { | |
nstack.push(item.value); | |
} else if (type === _instruction.IMEMBER) { | |
n1 = nstack.pop(); | |
nstack.push(n1[item.value]); | |
} else { | |
throw new Error('invalid Expression'); | |
} | |
} | |
if (nstack.length > 1) { | |
throw new Error('invalid Expression (parity)'); | |
} | |
return nstack[0]; | |
} | |
},{"./instruction":11}],7:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = expressionToString; | |
var _instruction = require('./instruction'); | |
function expressionToString(tokens, toJS) { | |
var nstack = []; | |
var n1, n2, n3; | |
var f; | |
for (var i = 0; i < tokens.length; i++) { | |
var item = tokens[i]; | |
var type = item.type; | |
if (type === _instruction.INUMBER) { | |
if (typeof item.value === 'number' && item.value < 0) { | |
nstack.push('(' + item.value + ')'); | |
} else { | |
nstack.push(escapeValue(item.value)); | |
} | |
} else if (type === _instruction.IOP2) { | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
f = item.value; | |
if (toJS) { | |
if (f === '^') { | |
nstack.push('Math.pow(' + n1 + ', ' + n2 + ')'); | |
} else if (f === 'and') { | |
nstack.push('(!!' + n1 + ' && !!' + n2 + ')'); | |
} else if (f === 'or') { | |
nstack.push('(!!' + n1 + ' || !!' + n2 + ')'); | |
} else if (f === '||') { | |
nstack.push('(String(' + n1 + ') + String(' + n2 + '))'); | |
} else if (f === '==') { | |
nstack.push('(' + n1 + ' === ' + n2 + ')'); | |
} else if (f === '!=') { | |
nstack.push('(' + n1 + ' !== ' + n2 + ')'); | |
} else { | |
nstack.push('(' + n1 + ' ' + f + ' ' + n2 + ')'); | |
} | |
} else { | |
nstack.push('(' + n1 + ' ' + f + ' ' + n2 + ')'); | |
} | |
} else if (type === _instruction.IOP3) { | |
n3 = nstack.pop(); | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
f = item.value; | |
if (f === '?') { | |
nstack.push('(' + n1 + ' ? ' + n2 + ' : ' + n3 + ')'); | |
} else { | |
throw new Error('invalid Expression'); | |
} | |
} else if (type === _instruction.IVAR) { | |
nstack.push(item.value); | |
} else if (type === _instruction.IOP1) { | |
n1 = nstack.pop(); | |
f = item.value; | |
if (f === '-' || f === '+') { | |
nstack.push('(' + f + n1 + ')'); | |
} else if (toJS) { | |
if (f === 'not') { | |
nstack.push('(' + '!' + n1 + ')'); | |
} else if (f === '!') { | |
nstack.push('fac(' + n1 + ')'); | |
} else { | |
nstack.push(f + '(' + n1 + ')'); | |
} | |
} else if (f === '!') { | |
nstack.push('(' + n1 + '!)'); | |
} else { | |
nstack.push('(' + f + ' ' + n1 + ')'); | |
} | |
} else if (type === _instruction.IFUNCALL) { | |
var argCount = item.value; | |
var args = []; | |
while (argCount-- > 0) { | |
args.unshift(nstack.pop()); | |
} | |
f = nstack.pop(); | |
nstack.push(f + '(' + args.join(', ') + ')'); | |
} else if (type === _instruction.IMEMBER) { | |
n1 = nstack.pop(); | |
nstack.push(n1 + '.' + item.value); | |
} else if (type === _instruction.IEXPR) { | |
nstack.push('(' + expressionToString(item.value, toJS) + ')'); | |
} else { | |
throw new Error('invalid Expression'); | |
} | |
} | |
if (nstack.length > 1) { | |
throw new Error('invalid Expression (parity)'); | |
} | |
return String(nstack[0]); | |
} | |
function escapeValue(v) { | |
if (typeof v === 'string') { | |
return JSON.stringify(v).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'); | |
} | |
return v; | |
} | |
},{"./instruction":11}],8:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Expression = Expression; | |
var _simplify = require('./simplify'); | |
var _simplify2 = _interopRequireDefault(_simplify); | |
var _substitute = require('./substitute'); | |
var _substitute2 = _interopRequireDefault(_substitute); | |
var _evaluate = require('./evaluate'); | |
var _evaluate2 = _interopRequireDefault(_evaluate); | |
var _expressionToString = require('./expression-to-string'); | |
var _expressionToString2 = _interopRequireDefault(_expressionToString); | |
var _getSymbols = require('./get-symbols'); | |
var _getSymbols2 = _interopRequireDefault(_getSymbols); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function Expression(tokens, parser) { | |
this.tokens = tokens; | |
this.parser = parser; | |
this.unaryOps = parser.unaryOps; | |
this.binaryOps = parser.binaryOps; | |
this.ternaryOps = parser.ternaryOps; | |
this.functions = parser.functions; | |
} | |
Expression.prototype.simplify = function (values) { | |
values = values || {}; | |
return new Expression((0, _simplify2.default)(this.tokens, this.unaryOps, this.binaryOps, this.ternaryOps, values), this.parser); | |
}; | |
Expression.prototype.substitute = function (variable, expr) { | |
if (!(expr instanceof Expression)) { | |
expr = this.parser.parse(String(expr)); | |
} | |
return new Expression((0, _substitute2.default)(this.tokens, variable, expr), this.parser); | |
}; | |
Expression.prototype.evaluate = function (values) { | |
values = values || {}; | |
return (0, _evaluate2.default)(this.tokens, this, values); | |
}; | |
Expression.prototype.toString = function () { | |
return (0, _expressionToString2.default)(this.tokens, false); | |
}; | |
Expression.prototype.symbols = function (options) { | |
options = options || {}; | |
var vars = []; | |
(0, _getSymbols2.default)(this.tokens, vars, options); | |
return vars; | |
}; | |
Expression.prototype.variables = function (options) { | |
options = options || {}; | |
var vars = []; | |
(0, _getSymbols2.default)(this.tokens, vars, options); | |
var functions = this.functions; | |
return vars.filter(function (name) { | |
return !(name in functions); | |
}); | |
}; | |
Expression.prototype.toJSFunction = function (param, variables) { | |
var expr = this; | |
var f = new Function(param, 'with(this.functions) with (this.ternaryOps) with (this.binaryOps) with (this.unaryOps) { return ' + (0, _expressionToString2.default)(this.simplify(variables).tokens, true) + '; }'); // eslint-disable-line no-new-func | |
return function () { | |
return f.apply(expr, arguments); | |
}; | |
}; | |
},{"./evaluate":6,"./expression-to-string":7,"./get-symbols":10,"./simplify":14,"./substitute":15}],9:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.add = add; | |
exports.sub = sub; | |
exports.mul = mul; | |
exports.div = div; | |
exports.mod = mod; | |
exports.concat = concat; | |
exports.equal = equal; | |
exports.notEqual = notEqual; | |
exports.greaterThan = greaterThan; | |
exports.lessThan = lessThan; | |
exports.greaterThanEqual = greaterThanEqual; | |
exports.lessThanEqual = lessThanEqual; | |
exports.andOperator = andOperator; | |
exports.orOperator = orOperator; | |
exports.inOperator = inOperator; | |
exports.sinh = sinh; | |
exports.cosh = cosh; | |
exports.tanh = tanh; | |
exports.asinh = asinh; | |
exports.acosh = acosh; | |
exports.atanh = atanh; | |
exports.log10 = log10; | |
exports.neg = neg; | |
exports.not = not; | |
exports.trunc = trunc; | |
exports.random = random; | |
exports.factorial = factorial; | |
exports.gamma = gamma; | |
exports.stringLength = stringLength; | |
exports.hypot = hypot; | |
exports.condition = condition; | |
exports.roundTo = roundTo; | |
var _contains = require('./contains'); | |
var _contains2 = _interopRequireDefault(_contains); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function add(a, b) { | |
return Number(a) + Number(b); | |
} | |
function sub(a, b) { | |
return a - b; | |
} | |
function mul(a, b) { | |
return a * b; | |
} | |
function div(a, b) { | |
return a / b; | |
} | |
function mod(a, b) { | |
return a % b; | |
} | |
function concat(a, b) { | |
return '' + a + b; | |
} | |
function equal(a, b) { | |
return a === b; | |
} | |
function notEqual(a, b) { | |
return a !== b; | |
} | |
function greaterThan(a, b) { | |
return a > b; | |
} | |
function lessThan(a, b) { | |
return a < b; | |
} | |
function greaterThanEqual(a, b) { | |
return a >= b; | |
} | |
function lessThanEqual(a, b) { | |
return a <= b; | |
} | |
function andOperator(a, b) { | |
return Boolean(a && b); | |
} | |
function orOperator(a, b) { | |
return Boolean(a || b); | |
} | |
function inOperator(a, b) { | |
return (0, _contains2.default)(b, a); | |
} | |
function sinh(a) { | |
return (Math.exp(a) - Math.exp(-a)) / 2; | |
} | |
function cosh(a) { | |
return (Math.exp(a) + Math.exp(-a)) / 2; | |
} | |
function tanh(a) { | |
if (a === Infinity) return 1; | |
if (a === -Infinity) return -1; | |
return (Math.exp(a) - Math.exp(-a)) / (Math.exp(a) + Math.exp(-a)); | |
} | |
function asinh(a) { | |
if (a === -Infinity) return a; | |
return Math.log(a + Math.sqrt(a * a + 1)); | |
} | |
function acosh(a) { | |
return Math.log(a + Math.sqrt(a * a - 1)); | |
} | |
function atanh(a) { | |
return Math.log((1 + a) / (1 - a)) / 2; | |
} | |
function log10(a) { | |
return Math.log(a) * Math.LOG10E; | |
} | |
function neg(a) { | |
return -a; | |
} | |
function not(a) { | |
return !a; | |
} | |
function trunc(a) { | |
return a < 0 ? Math.ceil(a) : Math.floor(a); | |
} | |
function random(a) { | |
return Math.random() * (a || 1); | |
} | |
function factorial(a) { | |
// a! | |
return gamma(a + 1); | |
} | |
function isInteger(value) { | |
return isFinite(value) && value === Math.round(value); | |
} | |
var GAMMA_G = 4.7421875; | |
var GAMMA_P = [0.99999999999999709182, 57.156235665862923517, -59.597960355475491248, 14.136097974741747174, -0.49191381609762019978, 0.33994649984811888699e-4, 0.46523628927048575665e-4, -0.98374475304879564677e-4, 0.15808870322491248884e-3, -0.21026444172410488319e-3, 0.21743961811521264320e-3, -0.16431810653676389022e-3, 0.84418223983852743293e-4, -0.26190838401581408670e-4, 0.36899182659531622704e-5]; | |
// Gamma function from math.js | |
function gamma(n) { | |
var t, x; | |
if (isInteger(n)) { | |
if (n <= 0) { | |
return isFinite(n) ? Infinity : NaN; | |
} | |
if (n > 171) { | |
return Infinity; // Will overflow | |
} | |
var value = n - 2; | |
var res = n - 1; | |
while (value > 1) { | |
res *= value; | |
value--; | |
} | |
if (res === 0) { | |
res = 1; // 0! is per definition 1 | |
} | |
return res; | |
} | |
if (n < 0.5) { | |
return Math.PI / (Math.sin(Math.PI * n) * gamma(1 - n)); | |
} | |
if (n >= 171.35) { | |
return Infinity; // will overflow | |
} | |
if (n > 85.0) { | |
// Extended Stirling Approx | |
var twoN = n * n; | |
var threeN = twoN * n; | |
var fourN = threeN * n; | |
var fiveN = fourN * n; | |
return Math.sqrt(2 * Math.PI / n) * Math.pow(n / Math.E, n) * (1 + 1 / (12 * n) + 1 / (288 * twoN) - 139 / (51840 * threeN) - 571 / (2488320 * fourN) + 163879 / (209018880 * fiveN) + 5246819 / (75246796800 * fiveN * n)); | |
} | |
--n; | |
x = GAMMA_P[0]; | |
for (var i = 1; i < GAMMA_P.length; ++i) { | |
x += GAMMA_P[i] / (n + i); | |
} | |
t = n + GAMMA_G + 0.5; | |
return Math.sqrt(2 * Math.PI) * Math.pow(t, n + 0.5) * Math.exp(-t) * x; | |
} | |
function stringLength(s) { | |
return String(s).length; | |
} | |
function hypot() { | |
var sum = 0; | |
var larg = 0; | |
for (var i = 0; i < arguments.length; i++) { | |
var arg = Math.abs(arguments[i]); | |
var div; | |
if (larg < arg) { | |
div = larg / arg; | |
sum = sum * div * div + 1; | |
larg = arg; | |
} else if (arg > 0) { | |
div = arg / larg; | |
sum += div * div; | |
} else { | |
sum += arg; | |
} | |
} | |
return larg === Infinity ? Infinity : larg * Math.sqrt(sum); | |
} | |
function condition(cond, yep, nope) { | |
return cond ? yep : nope; | |
} | |
/** | |
* Decimal adjustment of a number. | |
* From @escopecz. | |
* | |
* @param {Number} value The number. | |
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base). | |
* @return {Number} The adjusted value. | |
*/ | |
function roundTo(value, exp) { | |
// If the exp is undefined or zero... | |
if (typeof exp === 'undefined' || +exp === 0) { | |
return Math.round(value); | |
} | |
value = +value; | |
exp = -+exp; | |
// If the value is not a number or the exp is not an integer... | |
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) { | |
return NaN; | |
} | |
// Shift | |
value = value.toString().split('e'); | |
value = Math.round(+(value[0] + 'e' + (value[1] ? +value[1] - exp : -exp))); | |
// Shift back | |
value = value.toString().split('e'); | |
return +(value[0] + 'e' + (value[1] ? +value[1] + exp : exp)); | |
} | |
},{"./contains":5}],10:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = getSymbols; | |
var _instruction = require('./instruction'); | |
var _contains = require('./contains'); | |
var _contains2 = _interopRequireDefault(_contains); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function getSymbols(tokens, symbols, options) { | |
options = options || {}; | |
var withMembers = !!options.withMembers; | |
var prevVar = null; | |
for (var i = 0; i < tokens.length; i++) { | |
var item = tokens[i]; | |
if (item.type === _instruction.IVAR && !(0, _contains2.default)(symbols, item.value)) { | |
if (!withMembers) { | |
symbols.push(item.value); | |
} else if (prevVar !== null) { | |
if (!(0, _contains2.default)(symbols, prevVar)) { | |
symbols.push(prevVar); | |
} | |
prevVar = item.value; | |
} else { | |
prevVar = item.value; | |
} | |
} else if (item.type === _instruction.IMEMBER && withMembers && prevVar !== null) { | |
prevVar += '.' + item.value; | |
} else if (item.type === _instruction.IEXPR) { | |
getSymbols(item.value, symbols, options); | |
} else if (prevVar !== null) { | |
if (!(0, _contains2.default)(symbols, prevVar)) { | |
symbols.push(prevVar); | |
} | |
prevVar = null; | |
} | |
} | |
if (prevVar !== null && !(0, _contains2.default)(symbols, prevVar)) { | |
symbols.push(prevVar); | |
} | |
} | |
},{"./contains":5,"./instruction":11}],11:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Instruction = Instruction; | |
exports.unaryInstruction = unaryInstruction; | |
exports.binaryInstruction = binaryInstruction; | |
exports.ternaryInstruction = ternaryInstruction; | |
var INUMBER = exports.INUMBER = 'INUMBER'; | |
var IOP1 = exports.IOP1 = 'IOP1'; | |
var IOP2 = exports.IOP2 = 'IOP2'; | |
var IOP3 = exports.IOP3 = 'IOP3'; | |
var IVAR = exports.IVAR = 'IVAR'; | |
var IFUNCALL = exports.IFUNCALL = 'IFUNCALL'; | |
var IEXPR = exports.IEXPR = 'IEXPR'; | |
var IMEMBER = exports.IMEMBER = 'IMEMBER'; | |
function Instruction(type, value) { | |
this.type = type; | |
this.value = value !== undefined && value !== null ? value : 0; | |
} | |
Instruction.prototype.toString = function () { | |
switch (this.type) { | |
case INUMBER: | |
case IOP1: | |
case IOP2: | |
case IOP3: | |
case IVAR: | |
return this.value; | |
case IFUNCALL: | |
return 'CALL ' + this.value; | |
case IMEMBER: | |
return '.' + this.value; | |
default: | |
return 'Invalid Instruction'; | |
} | |
}; | |
function unaryInstruction(value) { | |
return new Instruction(IOP1, value); | |
} | |
function binaryInstruction(value) { | |
return new Instruction(IOP2, value); | |
} | |
function ternaryInstruction(value) { | |
return new Instruction(IOP3, value); | |
} | |
},{}],12:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.ParserState = ParserState; | |
var _token = require('./token'); | |
var _instruction = require('./instruction'); | |
var _contains = require('./contains'); | |
var _contains2 = _interopRequireDefault(_contains); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function ParserState(parser, tokenStream, options) { | |
this.parser = parser; | |
this.tokens = tokenStream; | |
this.current = null; | |
this.nextToken = null; | |
this.next(); | |
this.savedCurrent = null; | |
this.savedNextToken = null; | |
this.allowMemberAccess = options.allowMemberAccess !== false; | |
} | |
ParserState.prototype.next = function () { | |
this.current = this.nextToken; | |
return this.nextToken = this.tokens.next(); | |
}; | |
ParserState.prototype.tokenMatches = function (token, value) { | |
if (typeof value === 'undefined') { | |
return true; | |
} else if (Array.isArray(value)) { | |
return (0, _contains2.default)(value, token.value); | |
} else if (typeof value === 'function') { | |
return value(token); | |
} else { | |
return token.value === value; | |
} | |
}; | |
ParserState.prototype.save = function () { | |
this.savedCurrent = this.current; | |
this.savedNextToken = this.nextToken; | |
this.tokens.save(); | |
}; | |
ParserState.prototype.restore = function () { | |
this.tokens.restore(); | |
this.current = this.savedCurrent; | |
this.nextToken = this.savedNextToken; | |
}; | |
ParserState.prototype.accept = function (type, value) { | |
if (this.nextToken.type === type && this.tokenMatches(this.nextToken, value)) { | |
this.next(); | |
return true; | |
} | |
return false; | |
}; | |
ParserState.prototype.expect = function (type, value) { | |
if (!this.accept(type, value)) { | |
var coords = this.tokens.getCoordinates(); | |
throw new Error('parse error [' + coords.line + ':' + coords.column + ']: Expected ' + (value || type)); | |
} | |
}; | |
ParserState.prototype.parseAtom = function (instr) { | |
if (this.accept(_token.TNAME)) { | |
instr.push(new _instruction.Instruction(_instruction.IVAR, this.current.value)); | |
} else if (this.accept(_token.TNUMBER)) { | |
instr.push(new _instruction.Instruction(_instruction.INUMBER, this.current.value)); | |
} else if (this.accept(_token.TSTRING)) { | |
instr.push(new _instruction.Instruction(_instruction.INUMBER, this.current.value)); | |
} else if (this.accept(_token.TPAREN, '(')) { | |
this.parseExpression(instr); | |
this.expect(_token.TPAREN, ')'); | |
} else { | |
throw new Error('unexpected ' + this.nextToken); | |
} | |
}; | |
ParserState.prototype.parseExpression = function (instr) { | |
this.parseConditionalExpression(instr); | |
}; | |
ParserState.prototype.parseConditionalExpression = function (instr) { | |
this.parseOrExpression(instr); | |
while (this.accept(_token.TOP, '?')) { | |
var trueBranch = []; | |
var falseBranch = []; | |
this.parseConditionalExpression(trueBranch); | |
this.expect(_token.TOP, ':'); | |
this.parseConditionalExpression(falseBranch); | |
instr.push(new _instruction.Instruction(_instruction.IEXPR, trueBranch)); | |
instr.push(new _instruction.Instruction(_instruction.IEXPR, falseBranch)); | |
instr.push((0, _instruction.ternaryInstruction)('?')); | |
} | |
}; | |
ParserState.prototype.parseOrExpression = function (instr) { | |
this.parseAndExpression(instr); | |
while (this.accept(_token.TOP, 'or')) { | |
var falseBranch = []; | |
this.parseAndExpression(falseBranch); | |
instr.push(new _instruction.Instruction(_instruction.IEXPR, falseBranch)); | |
instr.push((0, _instruction.binaryInstruction)('or')); | |
} | |
}; | |
ParserState.prototype.parseAndExpression = function (instr) { | |
this.parseComparison(instr); | |
while (this.accept(_token.TOP, 'and')) { | |
var trueBranch = []; | |
this.parseComparison(trueBranch); | |
instr.push(new _instruction.Instruction(_instruction.IEXPR, trueBranch)); | |
instr.push((0, _instruction.binaryInstruction)('and')); | |
} | |
}; | |
var COMPARISON_OPERATORS = ['==', '!=', '<', '<=', '>=', '>', 'in']; | |
ParserState.prototype.parseComparison = function (instr) { | |
this.parseAddSub(instr); | |
while (this.accept(_token.TOP, COMPARISON_OPERATORS)) { | |
var op = this.current; | |
this.parseAddSub(instr); | |
instr.push((0, _instruction.binaryInstruction)(op.value)); | |
} | |
}; | |
var ADD_SUB_OPERATORS = ['+', '-', '||']; | |
ParserState.prototype.parseAddSub = function (instr) { | |
this.parseTerm(instr); | |
while (this.accept(_token.TOP, ADD_SUB_OPERATORS)) { | |
var op = this.current; | |
this.parseTerm(instr); | |
instr.push((0, _instruction.binaryInstruction)(op.value)); | |
} | |
}; | |
var TERM_OPERATORS = ['*', '/', '%']; | |
ParserState.prototype.parseTerm = function (instr) { | |
this.parseFactor(instr); | |
while (this.accept(_token.TOP, TERM_OPERATORS)) { | |
var op = this.current; | |
this.parseFactor(instr); | |
instr.push((0, _instruction.binaryInstruction)(op.value)); | |
} | |
}; | |
ParserState.prototype.parseFactor = function (instr) { | |
var unaryOps = this.tokens.unaryOps; | |
function isPrefixOperator(token) { | |
return token.value in unaryOps; | |
} | |
this.save(); | |
if (this.accept(_token.TOP, isPrefixOperator)) { | |
if (this.current.value !== '-' && this.current.value !== '+' && this.nextToken.type === _token.TPAREN && this.nextToken.value === '(') { | |
this.restore(); | |
this.parseExponential(instr); | |
} else { | |
var op = this.current; | |
this.parseFactor(instr); | |
instr.push((0, _instruction.unaryInstruction)(op.value)); | |
} | |
} else { | |
this.parseExponential(instr); | |
} | |
}; | |
ParserState.prototype.parseExponential = function (instr) { | |
this.parsePostfixExpression(instr); | |
while (this.accept(_token.TOP, '^')) { | |
this.parseFactor(instr); | |
instr.push((0, _instruction.binaryInstruction)('^')); | |
} | |
}; | |
ParserState.prototype.parsePostfixExpression = function (instr) { | |
this.parseFunctionCall(instr); | |
while (this.accept(_token.TOP, '!')) { | |
instr.push((0, _instruction.unaryInstruction)('!')); | |
} | |
}; | |
ParserState.prototype.parseFunctionCall = function (instr) { | |
var unaryOps = this.tokens.unaryOps; | |
function isPrefixOperator(token) { | |
return token.value in unaryOps; | |
} | |
if (this.accept(_token.TOP, isPrefixOperator)) { | |
var op = this.current; | |
this.parseAtom(instr); | |
instr.push((0, _instruction.unaryInstruction)(op.value)); | |
} else { | |
this.parseMemberExpression(instr); | |
while (this.accept(_token.TPAREN, '(')) { | |
if (this.accept(_token.TPAREN, ')')) { | |
instr.push(new _instruction.Instruction(_instruction.IFUNCALL, 0)); | |
} else { | |
var argCount = this.parseArgumentList(instr); | |
instr.push(new _instruction.Instruction(_instruction.IFUNCALL, argCount)); | |
} | |
} | |
} | |
}; | |
ParserState.prototype.parseArgumentList = function (instr) { | |
var argCount = 0; | |
while (!this.accept(_token.TPAREN, ')')) { | |
this.parseExpression(instr); | |
++argCount; | |
while (this.accept(_token.TCOMMA)) { | |
this.parseExpression(instr); | |
++argCount; | |
} | |
} | |
return argCount; | |
}; | |
ParserState.prototype.parseMemberExpression = function (instr) { | |
this.parseAtom(instr); | |
while (this.accept(_token.TOP, '.')) { | |
if (!this.allowMemberAccess) { | |
throw new Error('unexpected ".", member access is not permitted'); | |
} | |
this.expect(_token.TNAME); | |
instr.push(new _instruction.Instruction(_instruction.IMEMBER, this.current.value)); | |
} | |
}; | |
},{"./contains":5,"./instruction":11,"./token":17}],13:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Parser = Parser; | |
var _token = require('./token'); | |
var _tokenStream = require('./token-stream'); | |
var _parserState = require('./parser-state'); | |
var _expression = require('./expression'); | |
var _functions = require('./functions'); | |
function Parser(options) { | |
this.options = options || {}; | |
this.unaryOps = { | |
sin: Math.sin, | |
cos: Math.cos, | |
tan: Math.tan, | |
asin: Math.asin, | |
acos: Math.acos, | |
atan: Math.atan, | |
sinh: Math.sinh || _functions.sinh, | |
cosh: Math.cosh || _functions.cosh, | |
tanh: Math.tanh || _functions.tanh, | |
asinh: Math.asinh || _functions.asinh, | |
acosh: Math.acosh || _functions.acosh, | |
atanh: Math.atanh || _functions.atanh, | |
sqrt: Math.sqrt, | |
log: Math.log, | |
ln: Math.log, | |
lg: Math.log10 || _functions.log10, | |
log10: Math.log10 || _functions.log10, | |
abs: Math.abs, | |
ceil: Math.ceil, | |
floor: Math.floor, | |
round: Math.round, | |
trunc: Math.trunc || _functions.trunc, | |
'-': _functions.neg, | |
'+': Number, | |
exp: Math.exp, | |
not: _functions.not, | |
length: _functions.stringLength, | |
'!': _functions.factorial | |
}; | |
this.binaryOps = { | |
'+': _functions.add, | |
'-': _functions.sub, | |
'*': _functions.mul, | |
'/': _functions.div, | |
'%': _functions.mod, | |
'^': Math.pow, | |
'||': _functions.concat, | |
'==': _functions.equal, | |
'!=': _functions.notEqual, | |
'>': _functions.greaterThan, | |
'<': _functions.lessThan, | |
'>=': _functions.greaterThanEqual, | |
'<=': _functions.lessThanEqual, | |
and: _functions.andOperator, | |
or: _functions.orOperator, | |
'in': _functions.inOperator | |
}; | |
this.ternaryOps = { | |
'?': _functions.condition | |
}; | |
this.functions = { | |
random: _functions.random, | |
fac: _functions.factorial, | |
min: Math.min, | |
max: Math.max, | |
hypot: Math.hypot || _functions.hypot, | |
pyt: Math.hypot || _functions.hypot, // backward compat | |
pow: Math.pow, | |
atan2: Math.atan2, | |
'if': _functions.condition, | |
gamma: _functions.gamma, | |
roundTo: _functions.roundTo | |
}; | |
this.consts = { | |
E: Math.E, | |
PI: Math.PI, | |
'true': true, | |
'false': false | |
}; | |
} | |
Parser.prototype.parse = function (expr) { | |
var instr = []; | |
var parserState = new _parserState.ParserState(this, new _tokenStream.TokenStream(this, expr), { allowMemberAccess: this.options.allowMemberAccess }); | |
parserState.parseExpression(instr); | |
parserState.expect(_token.TEOF, 'EOF'); | |
return new _expression.Expression(instr, this); | |
}; | |
Parser.prototype.evaluate = function (expr, variables) { | |
return this.parse(expr).evaluate(variables); | |
}; | |
var sharedParser = new Parser(); | |
Parser.parse = function (expr) { | |
return sharedParser.parse(expr); | |
}; | |
Parser.evaluate = function (expr, variables) { | |
return sharedParser.parse(expr).evaluate(variables); | |
}; | |
},{"./expression":8,"./functions":9,"./parser-state":12,"./token":17,"./token-stream":16}],14:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = simplify; | |
var _instruction = require('./instruction'); | |
function simplify(tokens, unaryOps, binaryOps, ternaryOps, values) { | |
var nstack = []; | |
var newexpression = []; | |
var n1, n2, n3; | |
var f; | |
for (var i = 0; i < tokens.length; i++) { | |
var item = tokens[i]; | |
var type = item.type; | |
if (type === _instruction.INUMBER) { | |
nstack.push(item); | |
} else if (type === _instruction.IVAR && values.hasOwnProperty(item.value)) { | |
item = new _instruction.Instruction(_instruction.INUMBER, values[item.value]); | |
nstack.push(item); | |
} else if (type === _instruction.IOP2 && nstack.length > 1) { | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
f = binaryOps[item.value]; | |
item = new _instruction.Instruction(_instruction.INUMBER, f(n1.value, n2.value)); | |
nstack.push(item); | |
} else if (type === _instruction.IOP3 && nstack.length > 2) { | |
n3 = nstack.pop(); | |
n2 = nstack.pop(); | |
n1 = nstack.pop(); | |
if (item.value === '?') { | |
nstack.push(n1.value ? n2.value : n3.value); | |
} else { | |
f = ternaryOps[item.value]; | |
item = new _instruction.Instruction(_instruction.INUMBER, f(n1.value, n2.value, n3.value)); | |
nstack.push(item); | |
} | |
} else if (type === _instruction.IOP1 && nstack.length > 0) { | |
n1 = nstack.pop(); | |
f = unaryOps[item.value]; | |
item = new _instruction.Instruction(_instruction.INUMBER, f(n1.value)); | |
nstack.push(item); | |
} else if (type === _instruction.IEXPR) { | |
while (nstack.length > 0) { | |
newexpression.push(nstack.shift()); | |
} | |
newexpression.push(new _instruction.Instruction(_instruction.IEXPR, simplify(item.value, unaryOps, binaryOps, ternaryOps, values))); | |
} else if (type === _instruction.IMEMBER && nstack.length > 0) { | |
n1 = nstack.pop(); | |
nstack.push(new _instruction.Instruction(_instruction.INUMBER, n1.value[item.value])); | |
} else { | |
while (nstack.length > 0) { | |
newexpression.push(nstack.shift()); | |
} | |
newexpression.push(item); | |
} | |
} | |
while (nstack.length > 0) { | |
newexpression.push(nstack.shift()); | |
} | |
return newexpression; | |
} | |
},{"./instruction":11}],15:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = substitute; | |
var _instruction = require('./instruction'); | |
function substitute(tokens, variable, expr) { | |
var newexpression = []; | |
for (var i = 0; i < tokens.length; i++) { | |
var item = tokens[i]; | |
var type = item.type; | |
if (type === _instruction.IVAR && item.value === variable) { | |
for (var j = 0; j < expr.tokens.length; j++) { | |
var expritem = expr.tokens[j]; | |
var replitem; | |
if (expritem.type === _instruction.IOP1) { | |
replitem = (0, _instruction.unaryInstruction)(expritem.value); | |
} else if (expritem.type === _instruction.IOP2) { | |
replitem = (0, _instruction.binaryInstruction)(expritem.value); | |
} else if (expritem.type === _instruction.IOP3) { | |
replitem = (0, _instruction.ternaryInstruction)(expritem.value); | |
} else { | |
replitem = new _instruction.Instruction(expritem.type, expritem.value); | |
} | |
newexpression.push(replitem); | |
} | |
} else if (type === _instruction.IEXPR) { | |
newexpression.push(new _instruction.Instruction(_instruction.IEXPR, substitute(item.value, variable, expr))); | |
} else { | |
newexpression.push(item); | |
} | |
} | |
return newexpression; | |
} | |
},{"./instruction":11}],16:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.TokenStream = TokenStream; | |
var _token = require('./token'); | |
function TokenStream(parser, expression) { | |
this.pos = 0; | |
this.current = null; | |
this.unaryOps = parser.unaryOps; | |
this.binaryOps = parser.binaryOps; | |
this.ternaryOps = parser.ternaryOps; | |
this.consts = parser.consts; | |
this.expression = expression; | |
this.savedPosition = 0; | |
this.savedCurrent = null; | |
this.options = parser.options; | |
} | |
TokenStream.prototype.newToken = function (type, value, pos) { | |
return new _token.Token(type, value, pos != null ? pos : this.pos); | |
}; | |
TokenStream.prototype.save = function () { | |
this.savedPosition = this.pos; | |
this.savedCurrent = this.current; | |
}; | |
TokenStream.prototype.restore = function () { | |
this.pos = this.savedPosition; | |
this.current = this.savedCurrent; | |
}; | |
TokenStream.prototype.next = function () { | |
if (this.pos >= this.expression.length) { | |
return this.newToken(_token.TEOF, 'EOF'); | |
} | |
if (this.isWhitespace() || this.isComment()) { | |
return this.next(); | |
} else if (this.isRadixInteger() || this.isNumber() || this.isOperator() || this.isString() || this.isParen() || this.isComma() || this.isNamedOp() || this.isConst() || this.isName()) { | |
return this.current; | |
} else { | |
this.parseError('Unknown character "' + this.expression.charAt(this.pos) + '"'); | |
} | |
}; | |
TokenStream.prototype.isString = function () { | |
var r = false; | |
var startPos = this.pos; | |
var quote = this.expression.charAt(startPos); | |
if (quote === '\'' || quote === '"') { | |
var index = this.expression.indexOf(quote, startPos + 1); | |
while (index >= 0 && this.pos < this.expression.length) { | |
this.pos = index + 1; | |
if (this.expression.charAt(index - 1) !== '\\') { | |
var rawString = this.expression.substring(startPos + 1, index); | |
this.current = this.newToken(_token.TSTRING, this.unescape(rawString), startPos); | |
r = true; | |
break; | |
} | |
index = this.expression.indexOf(quote, index + 1); | |
} | |
} | |
return r; | |
}; | |
TokenStream.prototype.isParen = function () { | |
var c = this.expression.charAt(this.pos); | |
if (c === '(' || c === ')') { | |
this.current = this.newToken(_token.TPAREN, c); | |
this.pos++; | |
return true; | |
} | |
return false; | |
}; | |
TokenStream.prototype.isComma = function () { | |
var c = this.expression.charAt(this.pos); | |
if (c === ',') { | |
this.current = this.newToken(_token.TCOMMA, ','); | |
this.pos++; | |
return true; | |
} | |
return false; | |
}; | |
TokenStream.prototype.isConst = function () { | |
var startPos = this.pos; | |
var i = startPos; | |
for (; i < this.expression.length; i++) { | |
var c = this.expression.charAt(i); | |
if (c.toUpperCase() === c.toLowerCase()) { | |
if (i === this.pos || c !== '_' && c !== '.' && (c < '0' || c > '9')) { | |
break; | |
} | |
} | |
} | |
if (i > startPos) { | |
var str = this.expression.substring(startPos, i); | |
if (str in this.consts) { | |
this.current = this.newToken(_token.TNUMBER, this.consts[str]); | |
this.pos += str.length; | |
return true; | |
} | |
} | |
return false; | |
}; | |
TokenStream.prototype.isNamedOp = function () { | |
var startPos = this.pos; | |
var i = startPos; | |
for (; i < this.expression.length; i++) { | |
var c = this.expression.charAt(i); | |
if (c.toUpperCase() === c.toLowerCase()) { | |
if (i === this.pos || c !== '_' && (c < '0' || c > '9')) { | |
break; | |
} | |
} | |
} | |
if (i > startPos) { | |
var str = this.expression.substring(startPos, i); | |
if (this.isOperatorEnabled(str) && (str in this.binaryOps || str in this.unaryOps || str in this.ternaryOps)) { | |
this.current = this.newToken(_token.TOP, str); | |
this.pos += str.length; | |
return true; | |
} | |
} | |
return false; | |
}; | |
TokenStream.prototype.isName = function () { | |
var startPos = this.pos; | |
var i = startPos; | |
var hasLetter = false; | |
for (; i < this.expression.length; i++) { | |
var c = this.expression.charAt(i); | |
if (c.toUpperCase() === c.toLowerCase()) { | |
if (i === this.pos && (c === '$' || c === '_')) { | |
if (c === '_') { | |
hasLetter = true; | |
} | |
continue; | |
} else if (i === this.pos || !hasLetter || c !== '_' && (c < '0' || c > '9')) { | |
break; | |
} | |
} else { | |
hasLetter = true; | |
} | |
} | |
if (hasLetter) { | |
var str = this.expression.substring(startPos, i); | |
this.current = this.newToken(_token.TNAME, str); | |
this.pos += str.length; | |
return true; | |
} | |
return false; | |
}; | |
TokenStream.prototype.isWhitespace = function () { | |
var r = false; | |
var c = this.expression.charAt(this.pos); | |
while (c === ' ' || c === '\t' || c === '\n' || c === '\r') { | |
r = true; | |
this.pos++; | |
if (this.pos >= this.expression.length) { | |
break; | |
} | |
c = this.expression.charAt(this.pos); | |
} | |
return r; | |
}; | |
var codePointPattern = /^[0-9a-f]{4}$/i; | |
TokenStream.prototype.unescape = function (v) { | |
var index = v.indexOf('\\'); | |
if (index < 0) { | |
return v; | |
} | |
var buffer = v.substring(0, index); | |
while (index >= 0) { | |
var c = v.charAt(++index); | |
switch (c) { | |
case '\'': | |
buffer += '\''; | |
break; | |
case '"': | |
buffer += '"'; | |
break; | |
case '\\': | |
buffer += '\\'; | |
break; | |
case '/': | |
buffer += '/'; | |
break; | |
case 'b': | |
buffer += '\b'; | |
break; | |
case 'f': | |
buffer += '\f'; | |
break; | |
case 'n': | |
buffer += '\n'; | |
break; | |
case 'r': | |
buffer += '\r'; | |
break; | |
case 't': | |
buffer += '\t'; | |
break; | |
case 'u': | |
// interpret the following 4 characters as the hex of the unicode code point | |
var codePoint = v.substring(index + 1, index + 5); | |
if (!codePointPattern.test(codePoint)) { | |
this.parseError('Illegal escape sequence: \\u' + codePoint); | |
} | |
buffer += String.fromCharCode(parseInt(codePoint, 16)); | |
index += 4; | |
break; | |
default: | |
throw this.parseError('Illegal escape sequence: "\\' + c + '"'); | |
} | |
++index; | |
var backslash = v.indexOf('\\', index); | |
buffer += v.substring(index, backslash < 0 ? v.length : backslash); | |
index = backslash; | |
} | |
return buffer; | |
}; | |
TokenStream.prototype.isComment = function () { | |
var c = this.expression.charAt(this.pos); | |
if (c === '/' && this.expression.charAt(this.pos + 1) === '*') { | |
this.pos = this.expression.indexOf('*/', this.pos) + 2; | |
if (this.pos === 1) { | |
this.pos = this.expression.length; | |
} | |
return true; | |
} | |
return false; | |
}; | |
TokenStream.prototype.isRadixInteger = function () { | |
var pos = this.pos; | |
if (pos >= this.expression.length - 2 || this.expression.charAt(pos) !== '0') { | |
return false; | |
} | |
++pos; | |
var radix; | |
var validDigit; | |
if (this.expression.charAt(pos) === 'x') { | |
radix = 16; | |
validDigit = /^[0-9a-f]$/i; | |
++pos; | |
} else if (this.expression.charAt(pos) === 'b') { | |
radix = 2; | |
validDigit = /^[01]$/i; | |
++pos; | |
} else { | |
return false; | |
} | |
var valid = false; | |
var startPos = pos; | |
while (pos < this.expression.length) { | |
var c = this.expression.charAt(pos); | |
if (validDigit.test(c)) { | |
pos++; | |
valid = true; | |
} else { | |
break; | |
} | |
} | |
if (valid) { | |
this.current = this.newToken(_token.TNUMBER, parseInt(this.expression.substring(startPos, pos), radix)); | |
this.pos = pos; | |
} | |
return valid; | |
}; | |
TokenStream.prototype.isNumber = function () { | |
var valid = false; | |
var pos = this.pos; | |
var startPos = pos; | |
var resetPos = pos; | |
var foundDot = false; | |
var foundDigits = false; | |
var c; | |
while (pos < this.expression.length) { | |
c = this.expression.charAt(pos); | |
if (c >= '0' && c <= '9' || !foundDot && c === '.') { | |
if (c === '.') { | |
foundDot = true; | |
} else { | |
foundDigits = true; | |
} | |
pos++; | |
valid = foundDigits; | |
} else { | |
break; | |
} | |
} | |
if (valid) { | |
resetPos = pos; | |
} | |
if (c === 'e' || c === 'E') { | |
pos++; | |
var acceptSign = true; | |
var validExponent = false; | |
while (pos < this.expression.length) { | |
c = this.expression.charAt(pos); | |
if (acceptSign && (c === '+' || c === '-')) { | |
acceptSign = false; | |
} else if (c >= '0' && c <= '9') { | |
validExponent = true; | |
acceptSign = false; | |
} else { | |
break; | |
} | |
pos++; | |
} | |
if (!validExponent) { | |
pos = resetPos; | |
} | |
} | |
if (valid) { | |
this.current = this.newToken(_token.TNUMBER, parseFloat(this.expression.substring(startPos, pos))); | |
this.pos = pos; | |
} else { | |
this.pos = resetPos; | |
} | |
return valid; | |
}; | |
TokenStream.prototype.isOperator = function () { | |
var startPos = this.pos; | |
var c = this.expression.charAt(this.pos); | |
if (c === '+' || c === '-' || c === '*' || c === '/' || c === '%' || c === '^' || c === '?' || c === ':' || c === '.') { | |
this.current = this.newToken(_token.TOP, c); | |
} else if (c === '∙' || c === '•') { | |
this.current = this.newToken(_token.TOP, '*'); | |
} else if (c === '>') { | |
if (this.expression.charAt(this.pos + 1) === '=') { | |
this.current = this.newToken(_token.TOP, '>='); | |
this.pos++; | |
} else { | |
this.current = this.newToken(_token.TOP, '>'); | |
} | |
} else if (c === '<') { | |
if (this.expression.charAt(this.pos + 1) === '=') { | |
this.current = this.newToken(_token.TOP, '<='); | |
this.pos++; | |
} else { | |
this.current = this.newToken(_token.TOP, '<'); | |
} | |
} else if (c === '|') { | |
if (this.expression.charAt(this.pos + 1) === '|') { | |
this.current = this.newToken(_token.TOP, '||'); | |
this.pos++; | |
} else { | |
return false; | |
} | |
} else if (c === '=') { | |
if (this.expression.charAt(this.pos + 1) === '=') { | |
this.current = this.newToken(_token.TOP, '=='); | |
this.pos++; | |
} else { | |
return false; | |
} | |
} else if (c === '!') { | |
if (this.expression.charAt(this.pos + 1) === '=') { | |
this.current = this.newToken(_token.TOP, '!='); | |
this.pos++; | |
} else { | |
this.current = this.newToken(_token.TOP, c); | |
} | |
} else { | |
return false; | |
} | |
this.pos++; | |
if (this.isOperatorEnabled(this.current.value)) { | |
return true; | |
} else { | |
this.pos = startPos; | |
return false; | |
} | |
}; | |
var optionNameMap = { | |
'+': 'add', | |
'-': 'subtract', | |
'*': 'multiply', | |
'/': 'divide', | |
'%': 'remainder', | |
'^': 'power', | |
'!': 'factorial', | |
'<': 'comparison', | |
'>': 'comparison', | |
'<=': 'comparison', | |
'>=': 'comparison', | |
'==': 'comparison', | |
'!=': 'comparison', | |
'||': 'concatenate', | |
'and': 'logical', | |
'or': 'logical', | |
'not': 'logical', | |
'?': 'conditional', | |
':': 'conditional' | |
}; | |
function getOptionName(op) { | |
return optionNameMap.hasOwnProperty(op) ? optionNameMap[op] : op; | |
} | |
TokenStream.prototype.isOperatorEnabled = function (op) { | |
var optionName = getOptionName(op); | |
var operators = this.options.operators || {}; | |
// in is a special case for now because it's disabled by default | |
if (optionName === 'in') { | |
return !!operators['in']; | |
} | |
return !(optionName in operators) || !!operators[optionName]; | |
}; | |
TokenStream.prototype.getCoordinates = function () { | |
var line = 0; | |
var column; | |
var newline = -1; | |
do { | |
line++; | |
column = this.pos - newline; | |
newline = this.expression.indexOf('\n', newline + 1); | |
} while (newline >= 0 && newline < this.pos); | |
return { | |
line: line, | |
column: column | |
}; | |
}; | |
TokenStream.prototype.parseError = function (msg) { | |
var coords = this.getCoordinates(); | |
throw new Error('parse error [' + coords.line + ':' + coords.column + ']: ' + msg); | |
}; | |
},{"./token":17}],17:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Token = Token; | |
var TEOF = exports.TEOF = 'TEOF'; | |
var TOP = exports.TOP = 'TOP'; | |
var TNUMBER = exports.TNUMBER = 'TNUMBER'; | |
var TSTRING = exports.TSTRING = 'TSTRING'; | |
var TPAREN = exports.TPAREN = 'TPAREN'; | |
var TCOMMA = exports.TCOMMA = 'TCOMMA'; | |
var TNAME = exports.TNAME = 'TNAME'; | |
function Token(type, value, index) { | |
this.type = type; | |
this.value = value; | |
this.index = index; | |
} | |
Token.prototype.toString = function () { | |
return this.type + ': ' + this.value; | |
}; | |
},{}],18:[function(require,module,exports){ | |
module.exports=[ | |
"mm", | |
"cm", | |
"dm", | |
"m", | |
"µg", | |
"mg,", | |
"g", | |
"kg", | |
"t", | |
"ms", | |
"s", | |
"min", | |
"h", | |
"d" | |
] | |
},{}],19:[function(require,module,exports){ | |
module.exports=[ | |
"abends", | |
"aber", | |
"alle", | |
"allein", | |
"allerdings", | |
"allzu", | |
"alsbald", | |
"also", | |
"andererseits", | |
"andernfalls", | |
"anders", | |
"anfangs", | |
"auch", | |
"aufwärts", | |
"aussen", | |
"ausserdem", | |
"bald", | |
"beieinander", | |
"beinahe", | |
"beizeiten", | |
"bekanntlich", | |
"bereits", | |
"besonders", | |
"bestens", | |
"bisher", | |
"bisschen", | |
"bloss", | |
"dabei", | |
"dadurch", | |
"dafür", | |
"damals", | |
"damit", | |
"danach", | |
"daneben", | |
"dann", | |
"daran", | |
"darauf", | |
"daraus", | |
"darin", | |
"darüber", | |
"darum", | |
"davon", | |
"dazu", | |
"dazwischen", | |
"demnach", | |
"derart", | |
"dereinst", | |
"deshalb", | |
"deswegen", | |
"doch", | |
"dort", | |
"dorther", | |
"dorthin", | |
"draussen", | |
"drüben", | |
"durchaus", | |
"ebenso", | |
"ehedem", | |
"ehemals", | |
"eher", | |
"eigentlich", | |
"eilends", | |
"einfach", | |
"einigermassen", | |
"einmal", | |
"eins", | |
"einst", | |
"einstmals", | |
"endlich", | |
"entgegen", | |
"erst", | |
"etwa", | |
"etwas", | |
"fast", | |
"folglich", | |
"fortan", | |
"freilich", | |
"ganz", | |
"gegebenenfalls", | |
"genug", | |
"gern", | |
"gestern", | |
"gleich", | |
"gleichfalls", | |
"gleichwohl", | |
"glücklicherweise", | |
"günstigenfalls", | |
"her", | |
"heraus", | |
"herein", | |
"herum", | |
"herunter", | |
"heute", | |
"hier", | |
"hierauf", | |
"hierbei", | |
"hierdurch", | |
"hierfür", | |
"hierher", | |
"hierhin", | |
"hiermit", | |
"hierzu", | |
"hin", | |
"hinauf", | |
"hinein", | |
"hinten", | |
"hinterher", | |
"hinunter", | |
"höchstens", | |
"hoffentlich", | |
"immer", | |
"innen", | |
"irgendwo", | |
"ja", | |
"jawohl", | |
"jedenfalls", | |
"jemals", | |
"jetzt", | |
"kaum", | |
"keinesfalls", | |
"keineswegs", | |
"kopfüber", | |
"kurzerhand", | |
"leider", | |
"links", | |
"los", | |
"mal", | |
"manchmal", | |
"mehrmals", | |
"meist", | |
"meistens", | |
"minder", | |
"mindestens", | |
"miteinander", | |
"mithin", | |
"mittags", | |
"mittlerweile", | |
"möglicherweise", | |
"morgen", | |
"morgens", | |
"nacheinander", | |
"nachher", | |
"nächstens", | |
"nachts", | |
"nebenbei", | |
"nebeneinander", | |
"nein", | |
"nicht", | |
"nie", | |
"niemals", | |
"nirgends", | |
"noch", | |
"nochmals", | |
"nötigenfalls", | |
"nun", | |
"nur", | |
"oben", | |
"oft", | |
"öfters", | |
"rechts", | |
"ringsum", | |
"ringsumher", | |
"rückw.rts", | |
"rundum", | |
"schliesslich", | |
"schlimmstenfalls", | |
"schon", | |
"schwerlich", | |
"sehr", | |
"seinerzeit", | |
"seither", | |
"seitwärts", | |
"sicherlich", | |
"so", | |
"sodann", | |
"soeben", | |
"sofort", | |
"sogar", | |
"sogleich", | |
"sonst", | |
"stets", | |
"tagsüber", | |
"trotzdem", | |
"überall", | |
"überallhin", | |
"überaus", | |
"überdies", | |
"überhaupt", | |
"übrigens", | |
"umsonst", | |
"ungefähr", | |
"ungestraft", | |
"unglücklicherweise", | |
"unten", | |
"unterdessen", | |
"untereinander", | |
"unterwegs", | |
"vergebens", | |
"vermutlich", | |
"vielleicht", | |
"vielmals", | |
"vielmehr", | |
"vorbei", | |
"vordem", | |
"vorgestern", | |
"vorher", | |
"vorhin", | |
"vormals", | |
"vorn", | |
"vorne", | |
"wann", | |
"warum", | |
"weg", | |
"weitaus", | |
"weiter", | |
"wenigstens", | |
"wieder", | |
"wiederum", | |
"wirklich", | |
"wo", | |
"wohl", | |
"zeitlebens", | |
"zeitweise", | |
"zuerst", | |
"zugleich", | |
"zuletzt", | |
"zusammen", | |
"zuweilen" | |
] | |
},{}],20:[function(require,module,exports){ | |
module.exports=[ | |
"acht", | |
"achtmal", | |
"alle", | |
"allen", | |
"aller", | |
"allerhand", | |
"allerlei", | |
"alles", | |
"andere", | |
"anderem", | |
"anderen", | |
"anderer", | |
"anderes", | |
"beide", | |
"beidem", | |
"beiden", | |
"beider", | |
"beides", | |
"beiderlei", | |
"das", | |
"dasjenige", | |
"dasselbe", | |
"dein", | |
"deine", | |
"deinem", | |
"deinen", | |
"deiner", | |
"deines", | |
"deinerseits", | |
"deinesgleichen", | |
"dem", | |
"demjenigen", | |
"demselben", | |
"den", | |
"denen", | |
"denjenigen", | |
"denselben", | |
"der", | |
"ihrige", | |
"seinige", | |
"deren", | |
"derer", | |
"dergleichen", | |
"derjenige", | |
"derlei", | |
"derselbe", | |
"des", | |
"desjenigen", | |
"desselben", | |
"dessen", | |
"dich", | |
"die", | |
"meisten", | |
"wenigsten", | |
"diejenige", | |
"diejenigen", | |
"dies", | |
"diese", | |
"diesem", | |
"diesen", | |
"dieser", | |
"dieses", | |
"dieselbe", | |
"dieselben", | |
"dir", | |
"drei", | |
"dreierlei", | |
"dreimal", | |
"du", | |
"ein", | |
"bisschen", | |
"paar", | |
"wenig", | |
"einander", | |
"eine", | |
"einem", | |
"einen", | |
"einer", | |
"eines", | |
"einerlei", | |
"einige", | |
"einigem", | |
"einigen", | |
"einiger", | |
"einiges", | |
"einmal", | |
"einzelne", | |
"einzelnem", | |
"einzelnen", | |
"einzelner", | |
"einzelnes", | |
"er", | |
"es", | |
"etliche", | |
"etwas", | |
"etwelche", | |
"euch", | |
"euer", | |
"euereiner", | |
"eure", | |
"eurem", | |
"euren", | |
"eurer", | |
"eures", | |
"eurerseits", | |
"euresgleichen", | |
"fünfmal", | |
"fünf", | |
"genug", | |
"genügend", | |
"ich", | |
"ihm", | |
"ihn", | |
"ihnen", | |
"ihr", | |
"ihre", | |
"ihrem", | |
"ihren", | |
"ihrer", | |
"ihres", | |
"ihrerseits", | |
"ihresgleichen", | |
"irgend", | |
"irgendein", | |
"irgendeine", | |
"irgendwelche", | |
"irgendwelchen", | |
"irgendwelcher", | |
"irgendwer", | |
"jede", | |
"jedem", | |
"jeden", | |
"jeder", | |
"jedes", | |
"jedermann", | |
"jedweder", | |
"jegliche", | |
"jeglichem", | |
"jeglichen", | |
"jeglicher", | |
"jegliches", | |
"jemand", | |
"jemandem", | |
"jemanden", | |
"jene", | |
"jenem", | |
"jenen", | |
"jener", | |
"jenes", | |
"kein", | |
"keine", | |
"keinem", | |
"keinen", | |
"keiner", | |
"keines", | |
"man", | |
"manche", | |
"manchem", | |
"manchen", | |
"mancher", | |
"manches", | |
"mancherlei", | |
"mehr", | |
"mehrere", | |
"mehrerem", | |
"mehreren", | |
"mehreres", | |
"mein", | |
"meine", | |
"meinem", | |
"meinen", | |
"meiner", | |
"meines", | |
"meinerseits", | |
"meinesgleichen", | |
"mich", | |
"mir", | |
"neun", | |
"neunmal", | |
"nichts", | |
"niemand", | |
"niemandem", | |
"niemanden", | |
"sämtliche", | |
"sämtlichem", | |
"sämtlichen", | |
"sämtlicher", | |
"sämtliches", | |
"sechsmal", | |
"sechs", | |
"siebenmal", | |
"sieben", | |
"sein", | |
"seine", | |
"seinem", | |
"seinen", | |
"seiner", | |
"seines", | |
"seinerseits", | |
"seinesgleichen", | |
"sich", | |
"sie", | |
"solche", | |
"solchem", | |
"solchen", | |
"solcher", | |
"solches", | |
"solcherlei", | |
"uns", | |
"unser", | |
"unsere", | |
"unserem", | |
"unseren", | |
"unserer", | |
"unseres", | |
"unsereine", | |
"unsereinem", | |
"unsereinen", | |
"unsereiner", | |
"unsererseits", | |
"unseresgleichen", | |
"verschiedenerlei", | |
"viel", | |
"viele", | |
"vielem", | |
"vielen", | |
"vieler", | |
"vieles", | |
"vielerlei", | |
"vier", | |
"viermal", | |
"was", | |
"welche", | |
"welchem", | |
"welchen", | |
"welcher", | |
"welches", | |
"wem", | |
"wen", | |
"wer", | |
"wessen", | |
"wir", | |
"zehnmal", | |
"zehn", | |
"zwei", | |
"zweierlei", | |
"zweimal" | |
] | |
},{}],21:[function(require,module,exports){ | |
// shim for using process in browser | |
var process = module.exports = {}; | |
// cached from whatever global is present so that test runners that stub it | |
// don't break things. But we need to wrap it in a try catch in case it is | |
// wrapped in strict mode code which doesn't define any globals. It's inside a | |
// function because try/catches deoptimize in certain engines. | |
var cachedSetTimeout; | |
var cachedClearTimeout; | |
function defaultSetTimout() { | |
throw new Error('setTimeout has not been defined'); | |
} | |
function defaultClearTimeout () { | |
throw new Error('clearTimeout has not been defined'); | |
} | |
(function () { | |
try { | |
if (typeof setTimeout === 'function') { | |
cachedSetTimeout = setTimeout; | |
} else { | |
cachedSetTimeout = defaultSetTimout; | |
} | |
} catch (e) { | |
cachedSetTimeout = defaultSetTimout; | |
} | |
try { | |
if (typeof clearTimeout === 'function') { | |
cachedClearTimeout = clearTimeout; | |
} else { | |
cachedClearTimeout = defaultClearTimeout; | |
} | |
} catch (e) { | |
cachedClearTimeout = defaultClearTimeout; | |
} | |
} ()) | |
function runTimeout(fun) { | |
if (cachedSetTimeout === setTimeout) { | |
//normal enviroments in sane situations | |
return setTimeout(fun, 0); | |
} | |
// if setTimeout wasn't available but was latter defined | |
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | |
cachedSetTimeout = setTimeout; | |
return setTimeout(fun, 0); | |
} | |
try { | |
// when when somebody has screwed with setTimeout but no I.E. maddness | |
return cachedSetTimeout(fun, 0); | |
} catch(e){ | |
try { | |
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | |
return cachedSetTimeout.call(null, fun, 0); | |
} catch(e){ | |
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error | |
return cachedSetTimeout.call(this, fun, 0); | |
} | |
} | |
} | |
function runClearTimeout(marker) { | |
if (cachedClearTimeout === clearTimeout) { | |
//normal enviroments in sane situations | |
return clearTimeout(marker); | |
} | |
// if clearTimeout wasn't available but was latter defined | |
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | |
cachedClearTimeout = clearTimeout; | |
return clearTimeout(marker); | |
} | |
try { | |
// when when somebody has screwed with setTimeout but no I.E. maddness | |
return cachedClearTimeout(marker); | |
} catch (e){ | |
try { | |
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | |
return cachedClearTimeout.call(null, marker); | |
} catch (e){ | |
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. | |
// Some versions of I.E. have different rules for clearTimeout vs setTimeout | |
return cachedClearTimeout.call(this, marker); | |
} | |
} | |
} | |
var queue = []; | |
var draining = false; | |
var currentQueue; | |
var queueIndex = -1; | |
function cleanUpNextTick() { | |
if (!draining || !currentQueue) { | |
return; | |
} | |
draining = false; | |
if (currentQueue.length) { | |
queue = currentQueue.concat(queue); | |
} else { | |
queueIndex = -1; | |
} | |
if (queue.length) { | |
drainQueue(); | |
} | |
} | |
function drainQueue() { | |
if (draining) { | |
return; | |
} | |
var timeout = runTimeout(cleanUpNextTick); | |
draining = true; | |
var len = queue.length; | |
while(len) { | |
currentQueue = queue; | |
queue = []; | |
while (++queueIndex < len) { | |
if (currentQueue) { | |
currentQueue[queueIndex].run(); | |
} | |
} | |
queueIndex = -1; | |
len = queue.length; | |
} | |
currentQueue = null; | |
draining = false; | |
runClearTimeout(timeout); | |
} | |
process.nextTick = function (fun) { | |
var args = new Array(arguments.length - 1); | |
if (arguments.length > 1) { | |
for (var i = 1; i < arguments.length; i++) { | |
args[i - 1] = arguments[i]; | |
} | |
} | |
queue.push(new Item(fun, args)); | |
if (queue.length === 1 && !draining) { | |
runTimeout(drainQueue); | |
} | |
}; | |
// v8 likes predictible objects | |
function Item(fun, array) { | |
this.fun = fun; | |
this.array = array; | |
} | |
Item.prototype.run = function () { | |
this.fun.apply(null, this.array); | |
}; | |
process.title = 'browser'; | |
process.browser = true; | |
process.env = {}; | |
process.argv = []; | |
process.version = ''; // empty string to avoid regexp issues | |
process.versions = {}; | |
function noop() {} | |
process.on = noop; | |
process.addListener = noop; | |
process.once = noop; | |
process.off = noop; | |
process.removeListener = noop; | |
process.removeAllListeners = noop; | |
process.emit = noop; | |
process.prependListener = noop; | |
process.prependOnceListener = noop; | |
process.listeners = function (name) { return [] } | |
process.binding = function (name) { | |
throw new Error('process.binding is not supported'); | |
}; | |
process.cwd = function () { return '/' }; | |
process.chdir = function (dir) { | |
throw new Error('process.chdir is not supported'); | |
}; | |
process.umask = function() { return 0; }; | |
},{}]},{},[1])(1) | |
}); | |
var br = new BionicReader(3, 10); | |
br.renderNode(document.body); | |
var style = document.createElement('style'); | |
style.innerHTML = ` | |
div * { | |
font-weight: normal !important; | |
color: var(--bold-text-color) !important; | |
} | |
div .bionic-b { | |
font-weight: bold !important; | |
} | |
div a[data-image="false"] { | |
margin: -0.05em -0.1em -0.05em -0.1em; | |
padding: 0.05em 0.1em 0.05em 0.1em; | |
border-radius: 0 !important; | |
border-bottom: 1px solid var(--text-color) !important; | |
} | |
div .bionic-b { | |
font-weight: bold !important; | |
} | |
`; | |
document.head.appendChild(style); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment