UNPKG

aqueous

Version:

Proportional vertical layouts

1,179 lines (1,078 loc) 181 kB
/*! * ============================================================= * Ender: open module JavaScript framework (https://enderjs.com) * Build: ender build placebo-js * Packages: ender-core@2.0.0 ender-commonjs@1.0.8 placebo-js@1.0.8 * ============================================================= */ (function () { /*! * Ender: open module JavaScript framework (client-lib) * http://enderjs.com * License MIT */ /** * @constructor * @param {*=} item selector|node|collection|callback|anything * @param {Object=} root node(s) from which to base selector queries */ function Ender(item, root) { var i this.length = 0 // Ensure that instance owns length if (typeof item == 'string') // start with strings so the result parlays into the other checks // the .selector prop only applies to strings item = ender._select(this['selector'] = item, root) if (null == item) return this // Do not wrap null|undefined if (typeof item == 'function') ender._closure(item, root) // DOM node | scalar | not array-like else if (typeof item != 'object' || item.nodeType || (i = item.length) !== +i || item == item.window) this[this.length++] = item // array-like - bitwise ensures integer length else for (this.length = i = (i > 0 ? ~~i : 0); i--;) this[i] = item[i] } /** * @param {*=} item selector|node|collection|callback|anything * @param {Object=} root node(s) from which to base selector queries * @return {Ender} */ function ender(item, root) { return new Ender(item, root) } /** * @expose * sync the prototypes for jQuery compatibility */ ender.fn = ender.prototype = Ender.prototype /** * @enum {number} protects local symbols from being overwritten */ ender._reserved = { reserved: 1, ender: 1, expose: 1, noConflict: 1, fn: 1 } /** * @expose * handy reference to self */ Ender.prototype.$ = ender /** * @expose * make webkit dev tools pretty-print ender instances like arrays */ Ender.prototype.splice = function () { throw new Error('Not implemented') } /** * @expose * @param {function(*, number, Ender)} fn * @param {object=} scope * @return {Ender} */ Ender.prototype.forEach = function (fn, scope) { var i, l // opt out of native forEach so we can intentionally call our own scope // defaulting to the current item and be able to return self for (i = 0, l = this.length; i < l; ++i) i in this && fn.call(scope || this[i], this[i], i, this) // return self for chaining return this } /** * @expose * @param {object|function} o * @param {boolean=} chain */ ender.ender = function (o, chain) { var o2 = chain ? Ender.prototype : ender for (var k in o) !(k in ender._reserved) && (o2[k] = o[k]) return o2 } /** * @expose * @param {string} s * @param {Node=} r */ ender._select = function (s, r) { return s ? (r || document).querySelectorAll(s) : [] } /** * @expose * @param {function} fn */ ender._closure = function (fn) { fn.call(document, ender) } if (typeof module !== 'undefined' && module['exports']) module['exports'] = ender var $ = ender /** * @expose * @param {string} name * @param {*} value */ ender.expose = function (name, value) { ender.expose.old[name] = window[name] window[name] = value } /** * @expose */ ender.expose.old = {} /** * @expose * @param {boolean} all restore only $ or all ender globals */ ender.noConflict = function (all) { window['$'] = ender.expose.old['$'] if (all) for (var k in ender.expose.old) window[k] = ender.expose.old[k] return this } ender.expose('$', ender) ender.expose('ender', ender); // uglify needs this semi-colon between concating files /*! * Ender: open module JavaScript framework (module-lib) * http://enderjs.com * License MIT */ var global = this /** * @param {string} id module id to load * @return {object} */ function require(id) { if ('$' + id in require._cache) return require._cache['$' + id] if ('$' + id in require._modules) return (require._cache['$' + id] = require._modules['$' + id]._load()) if (id in window) return window[id] throw new Error('Requested module "' + id + '" has not been defined.') } /** * @param {string} id module id to provide to require calls * @param {object} exports the exports object to be returned */ function provide(id, exports) { return (require._cache['$' + id] = exports) } /** * @expose * @dict */ require._cache = {} /** * @expose * @dict */ require._modules = {} /** * @constructor * @param {string} id module id for this module * @param {function(Module, object, function(id), object)} fn module definition */ function Module(id, fn) { this.id = id this.fn = fn require._modules['$' + id] = this } /** * @expose * @param {string} id module id to load from the local module context * @return {object} */ Module.prototype.require = function (id) { var parts, i if (id.charAt(0) == '.') { parts = (this.id.replace(/\/.*?$/, '/') + id.replace(/\.js$/, '')).split('/') while (~(i = parts.indexOf('.'))) parts.splice(i, 1) while ((i = parts.lastIndexOf('..')) > 0) parts.splice(i - 1, 2) id = parts.join('/') } return require(id) } /** * @expose * @return {object} */ Module.prototype._load = function () { var m = this var dotdotslash = /^\.\.\//g var dotslash = /^\.\/[^\/]+$/g if (!m._loaded) { m._loaded = true /** * @expose */ m.exports = {} m.fn.call(global, m, m.exports, function (id) { if (id.match(dotdotslash)) { id = m.id.replace(/[^\/]+\/[^\/]+$/, '') + id.replace(dotdotslash, '') } else if (id.match(dotslash)) { id = m.id.replace(/\/[^\/]+$/, '') + id.replace('.', '') } return m.require(id) }, global) } return m.exports } /** * @expose * @param {string} id main module id * @param {Object.<string, function>} modules mapping of module ids to definitions * @param {string} main the id of the main module */ Module.createPackage = function (id, modules, main) { var path, m for (path in modules) { new Module(id + '/' + path, modules[path]) if (m = path.match(/^(.+)\/index$/)) new Module(id + '/' + m[1], modules[path]) } if (main) require._modules['$' + id] = require._modules['$' + id + '/' + main] } if (ender && ender.expose) { /*global global,require,provide,Module */ ender.expose('global', global) ender.expose('require', require) ender.expose('provide', provide) ender.expose('Module', Module) } Module.createPackage('placebo-js', { 'placebo': function (module, exports, require, global) { /** * Placebo 1.0.8 */ (function(context) { 'use strict'; var parser = (function() { /* * Generated by PEG.js 0.8.0. * * http://pegjs.majda.cz/ */ function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function SyntaxError(message, expected, found, offset, line, column) { this.message = message; this.expected = expected; this.found = found; this.offset = offset; this.line = line; this.column = column; this.name = "SyntaxError"; } peg$subclass(SyntaxError, Error); function parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = peg$FAILED, peg$c1 = null, peg$c2 = function(e, extra) { return { "node": e.join("") || "div", "extra": extra } }, peg$c3 = /^[^.#,>+~[\]|=\^$*:)( ]/, peg$c4 = { type: "class", value: "[^.#,>+~[\\]|=\\^$*:)( ]", description: "[^.#,>+~[\\]|=\\^$*:)( ]" }, peg$c5 = [], peg$c6 = "*", peg$c7 = { type: "literal", value: "*", description: "\"*\"" }, peg$c8 = function(node) { return node }, peg$c9 = ":", peg$c10 = { type: "literal", value: ":", description: "\":\"" }, peg$c11 = "active", peg$c12 = { type: "literal", value: "active", description: "\"active\"" }, peg$c13 = "after", peg$c14 = { type: "literal", value: "after", description: "\"after\"" }, peg$c15 = "before", peg$c16 = { type: "literal", value: "before", description: "\"before\"" }, peg$c17 = "checked", peg$c18 = { type: "literal", value: "checked", description: "\"checked\"" }, peg$c19 = "disabled", peg$c20 = { type: "literal", value: "disabled", description: "\"disabled\"" }, peg$c21 = "empty", peg$c22 = { type: "literal", value: "empty", description: "\"empty\"" }, peg$c23 = "enabled", peg$c24 = { type: "literal", value: "enabled", description: "\"enabled\"" }, peg$c25 = "first-child", peg$c26 = { type: "literal", value: "first-child", description: "\"first-child\"" }, peg$c27 = "first-letter", peg$c28 = { type: "literal", value: "first-letter", description: "\"first-letter\"" }, peg$c29 = "first-line", peg$c30 = { type: "literal", value: "first-line", description: "\"first-line\"" }, peg$c31 = "first-of-type", peg$c32 = { type: "literal", value: "first-of-type", description: "\"first-of-type\"" }, peg$c33 = "focus", peg$c34 = { type: "literal", value: "focus", description: "\"focus\"" }, peg$c35 = "hover", peg$c36 = { type: "literal", value: "hover", description: "\"hover\"" }, peg$c37 = "in-range", peg$c38 = { type: "literal", value: "in-range", description: "\"in-range\"" }, peg$c39 = "invalid", peg$c40 = { type: "literal", value: "invalid", description: "\"invalid\"" }, peg$c41 = "last-child", peg$c42 = { type: "literal", value: "last-child", description: "\"last-child\"" }, peg$c43 = "last-of-type", peg$c44 = { type: "literal", value: "last-of-type", description: "\"last-of-type\"" }, peg$c45 = "link", peg$c46 = { type: "literal", value: "link", description: "\"link\"" }, peg$c47 = "only-of-type", peg$c48 = { type: "literal", value: "only-of-type", description: "\"only-of-type\"" }, peg$c49 = "only-child", peg$c50 = { type: "literal", value: "only-child", description: "\"only-child\"" }, peg$c51 = "optional", peg$c52 = { type: "literal", value: "optional", description: "\"optional\"" }, peg$c53 = "out-of-range", peg$c54 = { type: "literal", value: "out-of-range", description: "\"out-of-range\"" }, peg$c55 = "read-only", peg$c56 = { type: "literal", value: "read-only", description: "\"read-only\"" }, peg$c57 = "read-write", peg$c58 = { type: "literal", value: "read-write", description: "\"read-write\"" }, peg$c59 = "required", peg$c60 = { type: "literal", value: "required", description: "\"required\"" }, peg$c61 = "root", peg$c62 = { type: "literal", value: "root", description: "\"root\"" }, peg$c63 = "selection", peg$c64 = { type: "literal", value: "selection", description: "\"selection\"" }, peg$c65 = "target", peg$c66 = { type: "literal", value: "target", description: "\"target\"" }, peg$c67 = "valid", peg$c68 = { type: "literal", value: "valid", description: "\"valid\"" }, peg$c69 = "visited", peg$c70 = { type: "literal", value: "visited", description: "\"visited\"" }, peg$c71 = function(p, extra) { var a = {}; a.pseudo = p; a.extra = extra || {}; return a }, peg$c72 = "lang", peg$c73 = { type: "literal", value: "lang", description: "\"lang\"" }, peg$c74 = "nth-child", peg$c75 = { type: "literal", value: "nth-child", description: "\"nth-child\"" }, peg$c76 = "nth-last-child", peg$c77 = { type: "literal", value: "nth-last-child", description: "\"nth-last-child\"" }, peg$c78 = "nth-last-of-type", peg$c79 = { type: "literal", value: "nth-last-of-type", description: "\"nth-last-of-type\"" }, peg$c80 = "nth-of-type", peg$c81 = { type: "literal", value: "nth-of-type", description: "\"nth-of-type\"" }, peg$c82 = "(", peg$c83 = { type: "literal", value: "(", description: "\"(\"" }, peg$c84 = /^[0-9]/, peg$c85 = { type: "class", value: "[0-9]", description: "[0-9]" }, peg$c86 = ")", peg$c87 = { type: "literal", value: ")", description: "\")\"" }, peg$c88 = function(p, v, extra) { var a = {}; a.pseudo = p; a.value = v.join(""); a.extra = extra || {}; return a }, peg$c89 = "not", peg$c90 = { type: "literal", value: "not", description: "\"not\"" }, peg$c91 = function(p, e, v, extra) { var a = {}; a.pseudo = p; a.value = {}; a.value.node = e.join("") || "div"; a.value.extra = v; a.extra = extra || {}; return a }, peg$c92 = "[", peg$c93 = { type: "literal", value: "[", description: "\"[\"" }, peg$c94 = "]", peg$c95 = { type: "literal", value: "]", description: "\"]\"" }, peg$c96 = function(cond, extra) { cond.extra = extra || {}; return cond }, peg$c97 = ".", peg$c98 = { type: "literal", value: ".", description: "\".\"" }, peg$c99 = function(val, extra) { return { "class": val.join(""), "extra": extra || {} } }, peg$c100 = "#", peg$c101 = { type: "literal", value: "#", description: "\"#\"" }, peg$c102 = function(val, extra) { return { "id": val.join(""), "extra": extra || {} } }, peg$c103 = " ", peg$c104 = { type: "literal", value: " ", description: "\" \"" }, peg$c105 = ",", peg$c106 = { type: "literal", value: ",", description: "\",\"" }, peg$c107 = function(e, extra) { return { "node": e.join(""), "extra": extra || {} } }, peg$c108 = function(e, extra) { return { "contains": e.join(""), "extra": extra || {} } }, peg$c109 = ">", peg$c110 = { type: "literal", value: ">", description: "\">\"" }, peg$c111 = function(e, extra) { return { "child": e.join(""), "extra": extra || {} } }, peg$c112 = "+", peg$c113 = { type: "literal", value: "+", description: "\"+\"" }, peg$c114 = function(e, extra) { return { "immediate_child": e.join(""), "extra": extra || {} } }, peg$c115 = "~", peg$c116 = { type: "literal", value: "~", description: "\"~\"" }, peg$c117 = function(e, extra) { return { "after": e.join(""), "extra": extra || {} } }, peg$c118 = function(attr) { return { "attr": attr.join("") } }, peg$c119 = "=", peg$c120 = { type: "literal", value: "=", description: "\"=\"" }, peg$c121 = /^[^\]]/, peg$c122 = { type: "class", value: "[^\\]]", description: "[^\\]]" }, peg$c123 = function(attr, val) { return { "attr_is": attr.join(""), "value": val.join("") } }, peg$c124 = "~=", peg$c125 = { type: "literal", value: "~=", description: "\"~=\"" }, peg$c126 = function(attr, val) { return { "attr_has_word": attr.join(""), "value": val.join("") } }, peg$c127 = "|=", peg$c128 = { type: "literal", value: "|=", description: "\"|=\"" }, peg$c129 = function(attr, val) { return { "attr_starts_hyphen": attr.join(""), "value": val.join("") } }, peg$c130 = "^=", peg$c131 = { type: "literal", value: "^=", description: "\"^=\"" }, peg$c132 = function(attr, val) { return { "attr_starts": attr.join(""), "value": val.join("") } }, peg$c133 = "$=", peg$c134 = { type: "literal", value: "$=", description: "\"$=\"" }, peg$c135 = function(attr, val) { return { "attr_ends": attr.join(""), "value": val.join("") } }, peg$c136 = "*=", peg$c137 = { type: "literal", value: "*=", description: "\"*=\"" }, peg$c138 = function(attr, val) { return { "attr_has": attr.join(""), "value": val.join("") } }, peg$currPos = 0, peg$reportedPos = 0, peg$cachedPos = 0, peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }, peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$reportedPos, peg$currPos); } function offset() { return peg$reportedPos; } function line() { return peg$computePosDetails(peg$reportedPos).line; } function column() { return peg$computePosDetails(peg$reportedPos).column; } function expected(description) { throw peg$buildException( null, [{ type: "other", description: description }], peg$reportedPos ); } function error(message) { throw peg$buildException(message, null, peg$reportedPos); } function peg$computePosDetails(pos) { function advance(details, startPos, endPos) { var p, ch; for (p = startPos; p < endPos; p++) { ch = input.charAt(p); if (ch === "\n") { if (!details.seenCR) { details.line++; } details.column = 1; details.seenCR = false; } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { details.line++; details.column = 1; details.seenCR = true; } else { details.column++; details.seenCR = false; } } } if (peg$cachedPos !== pos) { if (peg$cachedPos > pos) { peg$cachedPos = 0; peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }; } advance(peg$cachedPosDetails, peg$cachedPos, pos); peg$cachedPos = pos; } return peg$cachedPosDetails; } function peg$fail(expected) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected); } function peg$buildException(message, expected, pos) { function cleanupExpected(expected) { var i = 1; expected.sort(function(a, b) { if (a.description < b.description) { return -1; } else if (a.description > b.description) { return 1; } else { return 0; } }); while (i < expected.length) { if (expected[i - 1] === expected[i]) { expected.splice(i, 1); } else { i++; } } } function buildMessage(expected, found) { function stringEscape(s) { function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\x08/g, '\\b') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\f/g, '\\f') .replace(/\r/g, '\\r') .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); } var expectedDescs = new Array(expected.length), expectedDesc, foundDesc, i; for (i = 0; i < expected.length; i++) { expectedDescs[i] = expected[i].description; } expectedDesc = expected.length > 1 ? expectedDescs.slice(0, -1).join(", ") + " or " + expectedDescs[expected.length - 1] : expectedDescs[0]; foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; return "Expected " + expectedDesc + " but " + foundDesc + " found."; } var posDetails = peg$computePosDetails(pos), found = pos < input.length ? input.charAt(pos) : null; if (expected !== null) { cleanupExpected(expected); } return new SyntaxError( message !== null ? message : buildMessage(expected, found), expected, found, pos, posDetails.line, posDetails.column ); } function peg$parsestart() { var s0, s1, s2; s0 = peg$currPos; s1 = peg$parseelement(); if (s1 === peg$FAILED) { s1 = peg$c1; } if (s1 !== peg$FAILED) { s2 = peg$parseextra(); if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c2(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsevalid() { var s0; if (peg$c3.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } return s0; } function peg$parseelement() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parsevalid(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { s2 = peg$c6; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } } while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsevalid(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { s2 = peg$c6; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c8(s1); } s0 = s1; return s0; } function peg$parseextra() { var s0; s0 = peg$parseattributes(); if (s0 === peg$FAILED) { s0 = peg$parsepseudo(); if (s0 === peg$FAILED) { s0 = peg$parsepseudoSpecial(); if (s0 === peg$FAILED) { s0 = peg$parsepseudoSpecialO(); if (s0 === peg$FAILED) { s0 = peg$parsemulti(); if (s0 === peg$FAILED) { s0 = peg$parsechild(); if (s0 === peg$FAILED) { s0 = peg$parseichild(); if (s0 === peg$FAILED) { s0 = peg$parseafter(); if (s0 === peg$FAILED) { s0 = peg$parsecontains(); if (s0 === peg$FAILED) { s0 = peg$parsebrackets(); } } } } } } } } } return s0; } function peg$parseattributes() { var s0; s0 = peg$parseclass(); if (s0 === peg$FAILED) { s0 = peg$parseid(); } return s0; } function peg$parsepseudo() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 58) { s1 = peg$c9; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 58) { s2 = peg$c9; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c11) { s3 = peg$c11; peg$currPos += 6; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s3 === peg$FAILED) { if (input.substr(peg$currPos, 5) === peg$c13) { s3 = peg$c13; peg$currPos += 5; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c14); } } if (s3 === peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c15) { s3 = peg$c15; peg$currPos += 6; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c16); } } if (s3 === peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c17) {