@litejs/dom 25.1.0 → 25.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  LiteJS DOM – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
11
11
  ==========
12
12
 
13
- Dependency-free DOM library for handling HTML and CSS files on server-side.
13
+ Dependency-free DOM library for handling HTML, XML and CSS files on server-side.
14
14
 
15
15
 
16
16
  ```javascript
package/css.js CHANGED
@@ -1,12 +1,37 @@
1
1
 
2
2
  /*! litejs.com/MIT-LICENSE.txt */
3
3
 
4
- exports.selectorSplit = selectorSplit
4
+ "use strict"
5
+
5
6
  exports.CSSStyleDeclaration = CSSStyleDeclaration
6
7
  exports.CSSStyleSheet = CSSStyleSheet
7
8
 
8
9
  var fs = require("fs")
9
10
  , path = require("path")
11
+ , read = (sheet, url, enc = "utf8") => fs.readFileSync(path.resolve(sheet.min.root || "", sheet.baseURI, url).split(/[+#]/)[0], enc)
12
+ , plugins = exports.plugins = {
13
+ "data-uri": function(sheet, v) {
14
+ var { DOMParser } = require("./dom.js")
15
+ return v.replace(urlRe, function(_, q1, q2, url) {
16
+ if (q1) return _
17
+ var frag = url.split("#")[1]
18
+ , ext = url.split(/[?#]/)[0].split(".").pop()
19
+ , enc = ext === "svg" ? "utf8" : "base64"
20
+ url = read(sheet, url, enc)
21
+ if (ext === "svg") {
22
+ url = new DOMParser().parseFromString(url, "application/xml")
23
+ if (frag && (frag = url.getElementById(frag))) {
24
+ frag.removeAttribute("id")
25
+ url.documentElement.childNodes = frag.tagName === "g" ? frag.childNodes : [ frag ]
26
+ }
27
+ url = url.toString(true).replace(/#/g, "%23")
28
+ enc = ""
29
+ ext += "+xml"
30
+ }
31
+ return "url('data:image/" + ext + ";" + enc + "," + url + "')"
32
+ })
33
+ }
34
+ }
10
35
  , urlRe = /(["']).*?\1|url\((['"]?)(?!\/|data:|https?:)(.*?)\2\)/g
11
36
  , clearFn = (_, q, str, c) =>
12
37
  q ? (q = str.indexOf("'") == -1 ? "'" : "\"", q + str.replace(q === "'" ? /\\(")/g : /\\(')/g, "$1")) + q :
@@ -19,18 +44,15 @@ var fs = require("fs")
19
44
  , clear = s => s
20
45
  .replace(/("|')((?:\\\1|[^\1])*?)\1|\s*(\/)\*(?:[^*]|\*(?!\/))*\*\/\s*|(?:[^"'\/]|\/(?!\*))+/g, clearFn)
21
46
  .replace(/(["']).*?\1|url\(("|')([^'"()\s]+)\2\)/g, (m,q1,q2,u) => q1 ? m : "url(" + u + ")")
22
- , read = (sheet, url, enc = "utf8") => fs.readFileSync(path.resolve(sheet.min.root || "", sheet.baseURI, url), enc)
47
+ , hex = n => (0 | +n + 256.5).toString(16).slice(1)
23
48
  , toRgb = {
24
- rgb(r, g, b) {
25
- var f = n => ((n | 0) + 256).toString(16).slice(1)
26
- return f(r) + f(g) + f(b)
27
- },
49
+ rgb: (r, g, b) => hex(r) + hex(g) + hex(b),
28
50
  hsl(h, s, l) {
29
51
  l /= 100
30
52
  s /= 100 / (l < 0.5 ? l : 1 - l)
31
53
  function f(n) {
32
54
  n = (n + h / 30) % 12
33
- return (0 | 256.5 + (255 * (l - s * (n < 2 || n > 10 ? -1 : n < 4 ? n - 3 : n > 8 ? 9 - n : 1)))).toString(16).slice(1)
55
+ return hex(255 * (l - s * (n < 2 || n > 10 ? -1 : n < 4 ? n - 3 : n > 8 ? 9 - n : 1)))
34
56
  }
35
57
  return f(0) + f(8) + f(4)
36
58
  }
@@ -63,8 +85,7 @@ var fs = require("fs")
63
85
  , lastIdx = {}
64
86
  for (; (m = re.exec(val)); ) {
65
87
  if (m[4]) {
66
- if (min && len) style[k = style[len - 1]] = clear(transformValue(m[4].trim(), style[k]))
67
- continue
88
+ if (min && len && plugins[m[4] = m[4].trim()]) style[k = style[len - 1]] = clear(plugins[m[4]](sheet, style[k]))
68
89
  } else {
69
90
  k = m[1]
70
91
  if (lastIdx[k] >= 0) style.__[lastIdx[k]] = style[k]
@@ -78,24 +99,7 @@ var fs = require("fs")
78
99
  if (!style[prop]) style[style.length++] = prop
79
100
  style[prop] = style[prop === "cssFloat" ? "float" : prop.replace(/[A-Z]/g, "-$&").toLowerCase()] = clear(val)
80
101
  }
81
- function transformValue(cmd, v) {
82
- var { DOMParser } = require("./dom.js")
83
- if (cmd === "data-uri") {
84
- return v.replace(urlRe, function(_, q1, q2, url) {
85
- if (q1) return _
86
- var ext = url.split(".").pop()
87
- , enc = ext === "svg" ? "utf8" : "base64"
88
- url = read(sheet, url, enc)
89
- if (ext === "svg") {
90
- enc = ""
91
- ext += "+xml"
92
- url = new DOMParser().parseFromString(url, "application/xml").toString(true).replace(/#/g, "%23")
93
- }
94
- return "url('data:image/" + ext + ";" + enc + "," + url + "')"
95
- })
96
- }
97
- return v
98
- }
102
+ return true
99
103
  }
100
104
  }
101
105
  , ruleTypes = {
@@ -227,10 +231,11 @@ CSSStyleSheet.prototype = {
227
231
  } else if (char === "{") {
228
232
  depth++
229
233
  } else if (char === "}" && --depth < 1 || char === ";" && depth < 1) {
230
- if (depth < 0) throw "Invalid css"
234
+ if (depth < 0) throw Error("Unexpected '}'")
231
235
  sheet.rules.push(CSSRule(text.slice(start, start = pos + 1), sheet, char))
232
236
  }
233
237
  }
238
+ if (depth > 0) throw Error("Unclosed block")
234
239
  },
235
240
  toString(min) {
236
241
  if (min) this.min = min
@@ -238,25 +243,4 @@ CSSStyleSheet.prototype = {
238
243
  }
239
244
  }
240
245
 
241
- function selectorSplit(text) {
242
- for (var char, inQuote, depth = 0, start = 0, pos = 0, len = text.length, out = []; pos < len; ) {
243
- char = text[pos++]
244
- if (char === "\\") {
245
- pos++
246
- } else if (inQuote) {
247
- if (char === inQuote) inQuote = ""
248
- } else if (char === "'" || char === "\"") {
249
- inQuote = char
250
- } else if (char === "(" || char === "[") {
251
- depth++
252
- } else if (char === ")" || char === "]") {
253
- depth--
254
- } else if (char === "," && depth === 0) {
255
- out.push(text.slice(start, (start = pos) - 1).trim())
256
- }
257
- }
258
- out.push(text.slice(start).trim())
259
- return out
260
- }
261
-
262
246
 
package/dom.js CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  /*! litejs.com/MIT-LICENSE.txt */
3
3
 
4
+ "use strict"
5
+
4
6
  var boolAttrs = {
5
7
  async:1, autoplay:1, loop:1, checked:1, defer:1, disabled:1, muted:1, multiple:1, nomodule:1, playsinline:1, readonly:1, required:1, selected:1
6
8
  }
@@ -19,8 +21,9 @@ var boolAttrs = {
19
21
  , rawTextElements = { SCRIPT: /<(?=\/script)/i, STYLE: /<(?=\/style)/i }
20
22
  , rawTextEscape = { SCRIPT: /<(?=\/script|!--)/ig, STYLE: /<(?=\/style|!--)/ig }
21
23
  , hasOwn = voidElements.hasOwnProperty
22
- , { selectorSplit, CSSStyleDeclaration, CSSStyleSheet } = require("./css.js")
24
+ , { CSSStyleDeclaration, CSSStyleSheet } = require("./css.js")
23
25
  , selector = require("./selector.js")
26
+ , cssEscape = sel => ("" + sel).replace(/[^a-zA-Z0-9_\u00A0-\uFFFF-]/g, "\\$&").replace(/^(-?)([0-9])/, "$1\\3$2 ")
24
27
  , Node = {
25
28
  ELEMENT_NODE: 1,
26
29
  TEXT_NODE: 3,
@@ -44,9 +47,12 @@ var boolAttrs = {
44
47
  },
45
48
  set textContent(text) {
46
49
  if (this.nodeType === 3 || this.nodeType === 8) this.data = text
47
- else replaceChildren.call(this, this.ownerDocument.createTextNode(
48
- rawTextEscape[this.tagName] ? text.replace(rawTextEscape[this.tagName], "<\\") : text
49
- ))
50
+ else {
51
+ removeChilds(this)
52
+ this.appendChild(this.ownerDocument.createTextNode(
53
+ rawTextEscape[this.tagName] ? text.replace(rawTextEscape[this.tagName], "<\\") : text
54
+ ))
55
+ }
50
56
  },
51
57
  get firstChild() {
52
58
  return this.childNodes && this.childNodes[0] || null
@@ -96,29 +102,34 @@ var boolAttrs = {
96
102
  )
97
103
  }
98
104
  }
99
- replaceChildren.call(node, frag)
105
+ removeChilds(node)
106
+ node.appendChild(frag)
100
107
 
101
108
  function setAttr(_, name, value, q, qvalue) {
102
109
  child.setAttribute(name, (q ? qvalue : value || "").replace(unescRe, unescFn))
103
110
  }
104
111
  },
105
- get outerHTML() {
106
- return this.toString()
107
- },
108
- set outerHTML(html) {
109
- var frag = this.ownerDocument.createDocumentFragment()
110
- frag.innerHTML = html
111
- this.parentNode.replaceChild(frag, this)
112
- },
113
- get sheet() {
114
- return makeSheet(this)
115
- },
116
112
  get style() {
117
113
  return this._style || (this._style = CSSStyleDeclaration(this.getAttribute("style") || ""))
118
114
  },
119
115
  set style(value) {
120
116
  this.style.cssText = value
121
117
  },
118
+ appendChild(el) {
119
+ return this.insertBefore(el)
120
+ },
121
+ cloneNode(deep) {
122
+ var node = this
123
+ , clone = new node.constructor(node.tagName || node.data)
124
+ clone.ownerDocument = node.ownerDocument
125
+
126
+ mergeAttributes(node, clone)
127
+
128
+ if (deep && node.hasChildNodes()) {
129
+ node.childNodes.forEach(child => clone.appendChild(child.cloneNode(deep)))
130
+ }
131
+ return clone
132
+ },
122
133
  contains(el) {
123
134
  for (; el; el = el.parentNode) if (el === this) return true
124
135
  return false
@@ -126,12 +137,6 @@ var boolAttrs = {
126
137
  hasChildNodes() {
127
138
  return !!this.firstChild
128
139
  },
129
- getElementById(id) {
130
- return selector.find(this, "#" + id, 1)
131
- },
132
- appendChild(el) {
133
- return this.insertBefore(el)
134
- },
135
140
  insertBefore(el, ref) {
136
141
  var node = this
137
142
  , childs = node.childNodes
@@ -164,18 +169,6 @@ var boolAttrs = {
164
169
  this.insertBefore(el, ref)
165
170
  return this.removeChild(ref)
166
171
  },
167
- cloneNode(deep) {
168
- var node = this
169
- , clone = new node.constructor(node.tagName || node.data)
170
- clone.ownerDocument = node.ownerDocument
171
-
172
- mergeAttributes(node, clone)
173
-
174
- if (deep && node.hasChildNodes()) {
175
- node.childNodes.forEach(child => clone.appendChild(child.cloneNode(deep)))
176
- }
177
- return clone
178
- },
179
172
  querySelector(sel) {
180
173
  return selector.find(this, sel, 1)
181
174
  },
@@ -202,7 +195,18 @@ var boolAttrs = {
202
195
  get previousElementSibling() {
203
196
  return getSibling(this, -1, 1)
204
197
  },
205
- replaceChildren: replaceChildren,
198
+ get outerHTML() {
199
+ return this.toString()
200
+ },
201
+ set outerHTML(html) {
202
+ var frag = this.ownerDocument.createDocumentFragment()
203
+ frag.innerHTML = html
204
+ this.parentNode.replaceChild(frag, this)
205
+ },
206
+ replaceChildren() {
207
+ removeChilds(this)
208
+ for (var i = 0, l = arguments.length; i < l; ) this.insertBefore(arguments[i++])
209
+ },
206
210
  hasAttribute(name) {
207
211
  return this.attributes.getNamedItem(name) != null
208
212
  },
@@ -235,18 +239,18 @@ var boolAttrs = {
235
239
  "&sect;": "§", "&sup2;": "²", "&sup3;": "³", "&yen;": "¥"
236
240
  }
237
241
 
238
- Object.keys(boolAttrs).forEach(addGetter, { isBool: true, readonly: "readOnly" })
239
- numAttrs.split(" ").forEach(addGetter, { isNum: true })
240
- strAttrs.split(" ").forEach(addGetter, { "for": "htmlFor", "class": "className" })
242
+ Object.keys(boolAttrs).forEach(key => addGetter(key, { isBool: true, readonly: "readOnly" }))
243
+ numAttrs.split(" ").forEach(key => addGetter(key, { isNum: true }))
244
+ strAttrs.split(" ").forEach(key => addGetter(key, { "for": "htmlFor", "class": "className" }))
241
245
 
242
- function addGetter(key) {
246
+ function addGetter(key, opts) {
243
247
  var attr = key.toLowerCase()
244
- Object.defineProperty(Element, this[key] || key, {
248
+ Object.defineProperty(Element, opts[key] || key, {
245
249
  configurable: true,
246
250
  enumerable: true,
247
251
  get: (
248
- this.isBool ? function() { return this.hasAttribute(attr) } :
249
- this.isNum ? function() { return +this.getAttribute(attr) || 0 } :
252
+ opts.isBool ? function() { return this.hasAttribute(attr) } :
253
+ opts.isNum ? function() { return +this.getAttribute(attr) || 0 } :
250
254
  function() { return this.getAttribute(attr) || "" }
251
255
  ),
252
256
  set(value) {
@@ -263,7 +267,7 @@ function addGetter(key) {
263
267
 
264
268
  function Attr(node, name, value) {
265
269
  this.ownerElement = node
266
- this.name = name.toLowerCase()
270
+ this.name = name
267
271
  this.value = "" + value
268
272
  }
269
273
 
@@ -295,7 +299,7 @@ NamedNodeMap.prototype = {
295
299
  },
296
300
  setNamedItem(attr) {
297
301
  var oldAttr = this.getNamedItem(attr.name)
298
- this[attr.name] = attr
302
+ this[attr.name.toLowerCase()] = attr
299
303
  return oldAttr
300
304
  },
301
305
  toString(minify) {
@@ -315,6 +319,7 @@ NamedNodeMap.prototype = {
315
319
  if (!quotedAttrRe.test(value)) return name + "=" + value
316
320
  if (value.split("\"").length > value.split("'").length) return name + "='" + value.replace(/'/g, "&#39;") + "'"
317
321
  }
322
+ name = loName
318
323
  }
319
324
  return name + "=\"" + value.replace(/"/g, "&quot;") + "\""
320
325
  }).filter(Boolean).join(" ")
@@ -339,16 +344,25 @@ function HTMLElement(tag) {
339
344
  }
340
345
 
341
346
  extendNode(HTMLElement, Element, {
347
+ localName: null,
348
+ namespaceURI: "http://www.w3.org/1999/xhtml",
342
349
  nodeType: 1,
343
- matches(sel) {
344
- return selector.matches(this, sel)
350
+ tagName: null,
351
+ get sheet() {
352
+ return makeSheet(this)
353
+ },
354
+ blur() {
355
+ this.ownerDocument.activeElement = null
345
356
  },
346
357
  closest(sel) {
347
358
  return selector.closest(this, sel)
348
359
  },
349
- namespaceURI: "http://www.w3.org/1999/xhtml",
350
- localName: null,
351
- tagName: null,
360
+ focus() {
361
+ this.ownerDocument.activeElement = this
362
+ },
363
+ matches(sel) {
364
+ return selector.matches(this, sel)
365
+ },
352
366
  toString(minify) {
353
367
  var attrs = this.attributes.toString(minify)
354
368
  , isXml = this.ownerDocument.contentType === "application/xml"
@@ -436,7 +450,10 @@ extendNode(Document, Element, {
436
450
  createTextNode: own(Text),
437
451
  createComment: own(Comment),
438
452
  createDocumentType: own(DocumentType), //Should be document.implementation.createDocumentType(name, publicId, systemId)
439
- createDocumentFragment: own(DocumentFragment)
453
+ createDocumentFragment: own(DocumentFragment),
454
+ getElementById(id) {
455
+ return selector.find(this, "#" + id, 1)
456
+ }
440
457
  })
441
458
 
442
459
  function DOMParser() {}
@@ -470,9 +487,9 @@ function extendNode(obj, extras) {
470
487
  obj.prototype.constructor = obj
471
488
  }
472
489
 
473
- function replaceChildren() {
474
- for (var arr = this.childNodes, i = 0, l = arr.length; i < l; ) arr[i++].parentNode = null
475
- for (i = arr.length = 0, l = arguments.length; i < l; ) this.insertBefore(arguments[i++])
490
+ function removeChilds(node) {
491
+ node.childNodes.forEach(child => child.parentNode = null)
492
+ node.childNodes.length = 0
476
493
  }
477
494
 
478
495
  function getElement(childs, index, step, type) {
@@ -505,7 +522,8 @@ function mergeAttributes(source, target) {
505
522
  exports.document = new Document()
506
523
  exports.entities = entities
507
524
  exports.mergeAttributes = mergeAttributes
508
- exports.selectorSplit = selectorSplit
525
+ exports.selectorSplit = selector.selectorSplit
526
+ exports.cssEscape = cssEscape
509
527
  exports.CSSStyleDeclaration = CSSStyleDeclaration
510
528
  exports.CSSStyleSheet = CSSStyleSheet
511
529
  exports.DOMParser = DOMParser
package/net.js CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  /*! litejs.com/MIT-LICENSE.txt */
3
3
 
4
+ "use strict"
5
+
4
6
  var DOM = require(".")
5
7
  , URL = require("url").URL
6
8
  , parser = new DOM.DOMParser()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/dom",
3
- "version": "25.1.0",
3
+ "version": "25.6.0",
4
4
  "description": "A small DOM library for server-side testing, rendering, and handling of HTML files",
5
5
  "license": "MIT",
6
6
  "author": "Lauri Rooden <lauri@rooden.ee>",
package/selector.js CHANGED
@@ -1,114 +1,119 @@
1
1
 
2
-
3
2
  /*! litejs.com/MIT-LICENSE.txt */
4
3
 
5
-
6
- !function(exports) {
7
- var selectorCache = {
8
- "": function() {}
9
- }
10
- , selectorRe = /([.#:[])([-\w]+)(?:\(((?:[^()]|\([^)]+\))+?)\)|([~^$*|]?)=(("|')(?:\\.|[^\\])*?\6|[-\w]+))?]?/g
11
- , selectorLastRe = /([\s>+~]*)(?:("|')(?:\\.|[^\\])*?\2|\((?:[^()]|\([^()]+\))+?\)|~=|[^'"()\s>+~])+$/
12
- , selectorSplitRe = /\s*,\s*(?=(?:[^'"()]|"(?:\\.|[^\\"])*?"|'(?:\\.|[^\\'])*?'|\((?:[^()]|\([^()]+\))+?\))+$)/
13
- , selectorMap = {
14
- "contains": "_.textContent.indexOf(v)>-1",
15
- "empty": "!_.lastChild",
16
- "enabled": "!m(_,':disabled')",
17
- "first-child": "(a=_.parentNode)&&a.firstChild==_",
18
- "first-of-type": "!p(_,_.tagName)",
19
- "is": "m(_,v)",
20
- "lang": "m(c(_,'[lang]'),'[lang|='+v+']')",
21
- "last-child": "(a=_.parentNode)&&a.lastChild==_",
22
- "last-of-type": "!n(_,_.tagName)",
23
- "link": "m(_,'a[href]')",
24
- "not": "!m(_,v)",
25
- "nth-child": "(a=2,'odd'==v?b=1:'even'==v?b=0:a=1 in(v=v.split('n'))?(b=v[1],v[0]):(b=v[0],0),v=_.parentNode.childNodes,v=1+v.indexOf(_),0==a?v==b:('-'==a||0==(v-b)%a)&&(0<a||v<=b))",
26
- "only-child": "(a=_.parentNode)&&a.firstChild==a.lastChild",
27
- "only-of-type": "!p(_,_.tagName)&&!n(_,_.tagName)",
28
- "optional": "!m(_,':required')",
29
- "root": "(a=_.parentNode)&&!a.tagName",
30
- ".": "~_.className.split(/\\s+/).indexOf(a)",
31
- "#": "_.id==a",
32
- "^": "!a.indexOf(v)",
33
- "|": "a.split('-')[0]==v",
34
- "$": "a.slice(-v.length)==v",
35
- "~": "~a.split(/\\s+/).indexOf(v)",
36
- "*": "~a.indexOf(v)",
37
- ">>": "m(_.parentNode,v)",
38
- "++": "m(_.previousSibling,v)",
39
- "~~": "p(_,v)",
40
- "": "c(_.parentNode,v)"
41
- }
42
- , closest = exports.closest = walk.bind(exports, "parentNode", 1)
43
-
44
-
45
- selectorMap["nth-last-child"] = selectorMap["nth-child"].replace("1+", "v.length-")
46
-
47
- function selectorFn(str) {
48
- if (str != null && typeof str !== "string") throw Error("Invalid selector")
49
- return selectorCache[str || ""] ||
50
- (selectorCache[str] = Function("m,c,n,p", "return function(_,v,a,b){return " +
51
- str.split(selectorSplitRe).map(function(sel) {
52
- var relation, from
53
- , rules = ["_&&_.nodeType==1"]
54
- , parentSel = sel.replace(selectorLastRe, function(_, _rel, a, start) {
55
- from = start + _rel.length
56
- relation = _rel.trim()
57
- return ""
58
- })
59
- , tag = sel.slice(from).replace(selectorRe, function(_, op, key, subSel, fn, val, quotation) {
60
- rules.push(
61
- "((v='" +
62
- (subSel || (quotation ? val.slice(1, -1) : val) || "").replace(/[\\']/g, "\\$&") +
63
- "'),(a='" + key + "'),1)"
64
- ,
65
- selectorMap[op == ":" ? key : op] ||
66
- "(a=_.getAttribute(a))" +
67
- (fn ? "&&" + selectorMap[fn] : val ? "==v" : "!==null")
68
- )
69
- return ""
70
- })
71
-
72
- if (tag && tag != "*") rules[0] += "&&_.tagName==(_.namespaceURI?'" + tag.toUpperCase() + "':'" + tag + "')"
73
- if (parentSel) rules.push("(v='" + parentSel + "')", selectorMap[relation + relation])
74
- return rules.join("&&")
75
- }).join("||") + "}"
76
- )(matches, closest, next, prev))
77
- }
78
-
79
-
80
- function walk(next, first, el, sel, nextFn) {
81
- sel = selectorFn(sel)
82
- for (var out = []; el; el = el[next] || nextFn && nextFn(el)) if (sel(el)) {
83
- if (first) return el
84
- out.push(el)
4
+ "use strict"
5
+
6
+ exports.find = find
7
+ exports.selectorSplit = selectorSplit
8
+
9
+ var selectorCache = {
10
+ "": () => {}
11
+ }
12
+ , selectorRe = /([.#:[])([-\w]+)(?:\(((?:[^()]|\([^)]+\))+?)\)|([~^$*|]?)=(("|')(?:\\.|[^\\])*?\6|[-\w]+))?]?/g
13
+ , selectorLastRe = /([\s>+~]*)(?:("|')(?:\\.|[^\\])*?\2|\((?:[^()]|\([^()]+\))+?\)|~=|[^'"()\s>+~])+$/
14
+ , selectorMap = exports.selectorMap = {
15
+ "contains": "_.textContent.indexOf(v)>-1",
16
+ "empty": "!_.lastChild",
17
+ "enabled": "!m(_,':disabled')",
18
+ "first-child": "(a=_.parentNode)&&a.firstChild==_",
19
+ "first-of-type": "!p(_,_.tagName)",
20
+ "is": "m(_,v)",
21
+ "lang": "m(c(_,'[lang]'),'[lang|='+v+']')",
22
+ "last-child": "(a=_.parentNode)&&a.lastChild==_",
23
+ "last-of-type": "!n(_,_.tagName)",
24
+ "link": "m(_,'a[href]')",
25
+ "not": "!m(_,v)",
26
+ "nth-child": "(a=2,'odd'==v?b=1:'even'==v?b=0:a=1 in(v=v.split('n'))?(b=v[1],v[0]):(b=v[0],0),v=_.parentNode.childNodes,v=1+v.indexOf(_),0==a?v==b:('-'==a||0==(v-b)%a)&&(0<a||v<=b))",
27
+ "only-child": "(a=_.parentNode)&&a.firstChild==a.lastChild",
28
+ "only-of-type": "!p(_,_.tagName)&&!n(_,_.tagName)",
29
+ "optional": "!m(_,':required')",
30
+ "root": "(a=_.parentNode)&&!a.tagName",
31
+ ".": "~_.className.split(/\\s+/).indexOf(a)",
32
+ "#": "_.id==a",
33
+ "^": "!a.indexOf(v)",
34
+ "|": "a.split('-')[0]==v",
35
+ "$": "a.slice(-v.length)==v",
36
+ "~": "~a.split(/\\s+/).indexOf(v)",
37
+ "*": "~a.indexOf(v)",
38
+ ">>": "m(_.parentNode,v)",
39
+ "++": "m(_.previousElementSibling,v)",
40
+ "~~": "p(_,v)",
41
+ "": "c(_.parentNode,v)"
42
+ }
43
+ , closest = exports.closest = walk.bind(exports, "parentNode", 1)
44
+ , matches = exports.matches = (el, sel) => !!selectorFn(sel)(el)
45
+ , next = exports.next = (el, sel) => walk("nextSibling", 1, el.nextSibling, sel)
46
+ , prev = exports.prev = (el, sel) => walk("previousSibling", 1, el.previousSibling, sel)
47
+
48
+
49
+ selectorMap["nth-last-child"] = selectorMap["nth-child"].replace("1+", "v.length-")
50
+
51
+ function selectorFn(str) {
52
+ if (str != null && typeof str !== "string") throw Error("Invalid selector")
53
+ return selectorCache[str || ""] ||
54
+ (selectorCache[str] = Function("m,c,n,p", "return (_,v,a,b)=>" +
55
+ selectorSplit(str).map(sel => {
56
+ var relation, from
57
+ , rules = ["_&&_.nodeType==1"]
58
+ , parentSel = sel.replace(selectorLastRe, (_, _rel, a, start) => {
59
+ from = start + _rel.length
60
+ relation = _rel.trim()
61
+ return ""
62
+ })
63
+ , tag = sel.slice(from).replace(selectorRe, (_, op, key, subSel, fn, val, quotation) => {
64
+ rules.push(
65
+ "((v='" +
66
+ (subSel || (quotation ? val.slice(1, -1) : val) || "").replace(/[\\']/g, "\\$&") +
67
+ "'),(a='" + key + "'),1)"
68
+ ,
69
+ selectorMap[op == ":" ? key : op] ||
70
+ "(a=_.getAttribute(a))" +
71
+ (fn ? "&&" + selectorMap[fn] : val ? "==v" : "!==null")
72
+ )
73
+ return ""
74
+ })
75
+
76
+ if (tag && tag != "*") rules[0] += "&&_.tagName==(_.namespaceURI?'" + tag.toUpperCase() + "':'" + tag + "')"
77
+ if (parentSel) rules.push("(v='" + parentSel + "')", selectorMap[relation + relation])
78
+ return rules.join("&&")
79
+ }).join("||")
80
+ )(matches, closest, next, prev))
81
+ }
82
+
83
+ function selectorSplit(text) {
84
+ for (var char, inQuote, depth = 0, start = 0, pos = 0, len = text.length, out = []; pos < len; ) {
85
+ char = text[pos++]
86
+ if (char === "\\") {
87
+ pos++
88
+ } else if (inQuote) {
89
+ if (char === inQuote) inQuote = ""
90
+ } else if (char === "'" || char === "\"") {
91
+ inQuote = char
92
+ } else if (char === "(" || char === "[") {
93
+ depth++
94
+ } else if (char === ")" || char === "]") {
95
+ depth--
96
+ } else if (char === "," && depth === 0) {
97
+ out.push(text.slice(start, (start = pos) - 1).trim())
85
98
  }
86
- return first ? null : out
87
99
  }
88
-
89
- function find(node, sel, first) {
90
- return walk("firstChild", first, node.firstChild, sel, function(el) {
91
- for (var next = el.nextSibling; !next && ((el = el.parentNode) !== node); ) next = el.nextSibling
92
- return next
93
- })
100
+ out.push(text.slice(start).trim())
101
+ return out
102
+ }
103
+
104
+ function walk(attr, first, el, sel, nextFn) {
105
+ sel = selectorFn(sel)
106
+ for (var out = []; el; el = el[attr] || nextFn && nextFn(el)) if (sel(el)) {
107
+ if (first) return el
108
+ out.push(el)
94
109
  }
95
-
96
- function matches(el, sel) {
97
- return !!selectorFn(sel)(el)
98
- }
99
-
100
- function next(el, sel) {
101
- return walk("nextSibling", 1, el.nextSibling, sel)
102
- }
103
-
104
- function prev(el, sel) {
105
- return walk("previousSibling", 1, el.previousSibling, sel)
106
- }
107
-
108
- exports.find = find
109
- exports.matches = matches
110
- exports.next = next
111
- exports.prev = prev
112
- exports.selectorMap = selectorMap
113
- }(this) // jshint ignore:line
110
+ return first ? null : out
111
+ }
112
+
113
+ function find(node, sel, first) {
114
+ return walk("firstChild", first, node.firstChild, sel, (el, pos) => {
115
+ for (pos = el.nextSibling; !pos && ((el = el.parentNode) !== node); ) pos = el.nextSibling
116
+ return pos
117
+ })
118
+ }
114
119
 
package/interactive.js DELETED
@@ -1,18 +0,0 @@
1
-
2
-
3
- /*! litejs.com/MIT-LICENSE.txt */
4
-
5
-
6
- var DOM = module.exports = require(".")
7
- , HTMLElementExtra = {
8
- focus() {
9
- this.ownerDocument.activeElement = this
10
- },
11
- blur() {
12
- this.ownerDocument.activeElement = null
13
- }
14
- }
15
-
16
- Object.assign(DOM.HTMLElement.prototype, HTMLElementExtra)
17
-
18
-