|
| 1 | +var needs = (function () { |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +function createCommonjsModule(fn, module) { |
| 11 | + return module = { exports: {} }, fn(module, module.exports), module.exports; |
| 12 | +} |
| 13 | + |
| 14 | +var is_1 = is; |
| 15 | +is.fn = isFunction; |
| 16 | +is.str = isString; |
| 17 | +is.num = isNumber; |
| 18 | +is.obj = isObject; |
| 19 | +is.lit = isLiteral; |
| 20 | +is.bol = isBoolean; |
| 21 | +is.truthy = isTruthy; |
| 22 | +is.falsy = isFalsy; |
| 23 | +is.arr = isArray; |
| 24 | +is.null = isNull; |
| 25 | +is.def = isDef; |
| 26 | +is.in = isIn; |
| 27 | +is.promise = isPromise; |
| 28 | +is.stream = isStream; |
| 29 | + |
| 30 | +function is(v){ |
| 31 | + return function(d){ |
| 32 | + return d == v |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +function isFunction(d) { |
| 37 | + return typeof d == 'function' |
| 38 | +} |
| 39 | + |
| 40 | +function isBoolean(d) { |
| 41 | + return typeof d == 'boolean' |
| 42 | +} |
| 43 | + |
| 44 | +function isString(d) { |
| 45 | + return typeof d == 'string' |
| 46 | +} |
| 47 | + |
| 48 | +function isNumber(d) { |
| 49 | + return typeof d == 'number' |
| 50 | +} |
| 51 | + |
| 52 | +function isObject(d) { |
| 53 | + return typeof d == 'object' |
| 54 | +} |
| 55 | + |
| 56 | +function isLiteral(d) { |
| 57 | + return typeof d == 'object' |
| 58 | + && !(d instanceof Array) |
| 59 | +} |
| 60 | + |
| 61 | +function isTruthy(d) { |
| 62 | + return !!d == true |
| 63 | +} |
| 64 | + |
| 65 | +function isFalsy(d) { |
| 66 | + return !!d == false |
| 67 | +} |
| 68 | + |
| 69 | +function isArray(d) { |
| 70 | + return d instanceof Array |
| 71 | +} |
| 72 | + |
| 73 | +function isNull(d) { |
| 74 | + return d === null |
| 75 | +} |
| 76 | + |
| 77 | +function isDef(d) { |
| 78 | + return typeof d !== 'undefined' |
| 79 | +} |
| 80 | + |
| 81 | +function isPromise(d) { |
| 82 | + return d instanceof Promise |
| 83 | +} |
| 84 | + |
| 85 | +function isStream(d) { |
| 86 | + return !!(d && d.next) |
| 87 | +} |
| 88 | + |
| 89 | +function isIn(set) { |
| 90 | + return function(d){ |
| 91 | + return !set ? false |
| 92 | + : set.indexOf ? ~set.indexOf(d) |
| 93 | + : d in set |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +var to = { |
| 98 | + arr: toArray |
| 99 | +, obj: toObject |
| 100 | +}; |
| 101 | + |
| 102 | +function toArray(d){ |
| 103 | + return Array.prototype.slice.call(d, 0) |
| 104 | +} |
| 105 | + |
| 106 | +function toObject(d) { |
| 107 | + var by = 'id'; |
| 108 | + |
| 109 | + return arguments.length == 1 |
| 110 | + ? (by = d, reduce) |
| 111 | + : reduce.apply(this, arguments) |
| 112 | + |
| 113 | + function reduce(p,v,i){ |
| 114 | + if (i === 0) { p = {}; } |
| 115 | + p[is_1.fn(by) ? by(v, i) : v[by]] = v; |
| 116 | + return p |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +var client = typeof window != 'undefined'; |
| 121 | + |
| 122 | +var owner = client ? /* istanbul ignore next */ window : commonjsGlobal; |
| 123 | + |
| 124 | +var log = function log(ns){ |
| 125 | + return function(d){ |
| 126 | + if (!owner.console || !console.log.apply) { return d; } |
| 127 | + is_1.arr(arguments[2]) && (arguments[2] = arguments[2].length); |
| 128 | + var args = to.arr(arguments) |
| 129 | + , prefix = '[log][' + (new Date()).toISOString() + ']' + ns; |
| 130 | + |
| 131 | + args.unshift(prefix.grey ? prefix.grey : prefix); |
| 132 | + return console.log.apply(console, args), d |
| 133 | + } |
| 134 | +}; |
| 135 | + |
| 136 | +var includes = function includes(pattern){ |
| 137 | + return function(d){ |
| 138 | + return d && d.indexOf && ~d.indexOf(pattern) |
| 139 | + } |
| 140 | +}; |
| 141 | + |
| 142 | +var replace = function replace(from, to){ |
| 143 | + return function(d){ |
| 144 | + return d.replace(from, to) |
| 145 | + } |
| 146 | +}; |
| 147 | + |
| 148 | +var split = function split(delimiter){ |
| 149 | + return function(d){ |
| 150 | + return d.split(delimiter) |
| 151 | + } |
| 152 | +}; |
| 153 | + |
| 154 | +var attr = function attr(name, value) { |
| 155 | + var args = arguments.length; |
| 156 | + |
| 157 | + return !is_1.str(name) && args == 2 ? attr(arguments[1]).call(this, arguments[0]) |
| 158 | + : !is_1.str(name) && args == 3 ? attr(arguments[1], arguments[2]).call(this, arguments[0]) |
| 159 | + : function(el){ |
| 160 | + var ctx = this || {}; |
| 161 | + el = ctx.nodeName || is_1.fn(ctx.node) ? ctx : el; |
| 162 | + el = el.node ? el.node() : el; |
| 163 | + el = el.host || el; |
| 164 | + |
| 165 | + return args > 1 && value === false ? el.removeAttribute(name) |
| 166 | + : args > 1 ? (el.setAttribute(name, value), value) |
| 167 | + : el.attributes.getNamedItem(name) |
| 168 | + && el.attributes.getNamedItem(name).value |
| 169 | + } |
| 170 | +}; |
| 171 | + |
| 172 | +var lo = function lo(d){ |
| 173 | + return (d || '').toLowerCase() |
| 174 | +}; |
| 175 | + |
| 176 | +var needs = createCommonjsModule(function (module) { |
| 177 | +// ------------------------------------------- |
| 178 | +// Define Default Attributes for Components |
| 179 | +// ------------------------------------------- |
| 180 | +module.exports = function needs(ripple){ |
| 181 | + if (!client) { return; } |
| 182 | + log$$1('creating'); |
| 183 | + ripple.render = render(ripple)(ripple.render); |
| 184 | + return ripple |
| 185 | +}; |
| 186 | + |
| 187 | +var render = function (ripple) { return function (next) { return function (el) { |
| 188 | + var component = lo(el.nodeName); |
| 189 | + if (!(component in ripple.resources)) { return } |
| 190 | + |
| 191 | + var headers = ripple.resources[component].headers |
| 192 | + , attrs = headers.attrs = headers.attrs || parse(headers.needs, component); |
| 193 | + |
| 194 | + return attrs |
| 195 | + .map(function (ref) { |
| 196 | + var name = ref[0]; |
| 197 | + var values = ref[1]; |
| 198 | + |
| 199 | + return values.some(function (v, i) { |
| 200 | + var from = attr(el, name) || ''; |
| 201 | + return includes(v)(from) ? false |
| 202 | + : attr(el, name, (from + ' ' + v).trim()) |
| 203 | + }) |
| 204 | + }) |
| 205 | + .some(Boolean) ? el.draw() : next(el) |
| 206 | +}; }; }; |
| 207 | + |
| 208 | +var parse = function (attrs, component) { |
| 209 | + if ( attrs === void 0 ) attrs = ''; |
| 210 | + |
| 211 | + return attrs |
| 212 | + .split('[') |
| 213 | + .slice(1) |
| 214 | + .map(replace(']', '')) |
| 215 | + .map(split('=')) |
| 216 | + .map(function (ref) { |
| 217 | + var k = ref[0]; |
| 218 | + var v = ref[1]; |
| 219 | + |
| 220 | + return v ? [k, v.split(' ')] |
| 221 | + : k == 'css' ? [k, [component + '.css']] |
| 222 | + : [k, []]; |
| 223 | + } |
| 224 | + ); |
| 225 | +}; |
| 226 | + |
| 227 | +var log$$1 = log('[ri/needs]'); |
| 228 | +}); |
| 229 | + |
| 230 | +return needs; |
| 231 | + |
| 232 | +}()); |
0 commit comments