@litejs/dom 26.2.0 → 26.3.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.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/css.js +4 -1
  3. package/dom.js +38 -0
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -64,7 +64,7 @@ Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
64
64
  run tests `npm install; npm test`.
65
65
 
66
66
 
67
- > Copyright (c) 2014-2025 Lauri Rooden <lauri@rooden.ee>
67
+ > Copyright (c) 2014-2026 Lauri Rooden <lauri@rooden.ee>
68
68
  [MIT License](https://litejs.com/MIT-LICENSE.txt) |
69
69
  [GitHub repo](https://github.com/litejs/dom) |
70
70
  [npm package](https://npmjs.org/package/@litejs/dom) |
package/css.js CHANGED
@@ -59,7 +59,10 @@ var URL = global.URL || require("url").URL
59
59
  }
60
60
  }
61
61
  , toUrl = (dir) => new URL((dir || ".").replace(/\/+$/, "") + "/", "file:///").href
62
- , read = (root, url, baseURI, enc = "utf8") => require("fs").readFileSync(new URL(url, new URL((baseURI || ".") + "/", new URL((root || ".").replace(/\/+$/, "") + "/", "file:///" + process.cwd() + "/"))).pathname.split(/[+#]/)[0], enc)
62
+ , read = (root, url, baseURI, enc = "utf8") => require("fs").readFileSync(
63
+ new URL(url, new URL((baseURI || ".") + "/", new URL((root || ".").replace(/\/+$/, "") + "/", "file:///" + process.cwd() + "/"))).pathname.replace(/^\/(?=\w:)|[+#].*/, ""),
64
+ enc
65
+ )
63
66
  , plugins = exports.plugins = {
64
67
  "data-uri": function(root, baseURI, v) {
65
68
  var { DOMParser } = require("./dom.js")
package/dom.js CHANGED
@@ -19,6 +19,7 @@ var boolAttrs = {
19
19
  , svgVoidElements = {
20
20
  circle:1, ellipse:1, image:1, line:1, path:1, polygon:1, polyline:1, rect:1, stop:1, use:1,
21
21
  }
22
+ , listeners = new WeakMap()
22
23
  , rawTextElements = { SCRIPT: /<(?=\/script)/i, STYLE: /<(?=\/style)/i }
23
24
  , rawTextEscape = { SCRIPT: /<(?=\/script|!--)/ig, STYLE: /<(?=\/style|!--)/ig }
24
25
  , hasOwn = voidElements.hasOwnProperty
@@ -319,6 +320,18 @@ function Attr(node, name, value) {
319
320
  this.value = "" + value
320
321
  }
321
322
 
323
+ function Event(type, opts) {
324
+ Object.assign(this, {type, bubbles: false, cancelable: false, defaultPrevented: false}, opts)
325
+ }
326
+ Event.prototype = {
327
+ stopPropagation() {
328
+ this.bubbles = false
329
+ },
330
+ preventDefault() {
331
+ if (this.cancelable) this.defaultPrevented = true
332
+ }
333
+ }
334
+
322
335
  function NamedNodeMap(node) {
323
336
  Object.defineProperties(this, {
324
337
  length: { get() { return this.names().length } },
@@ -398,15 +411,39 @@ extendNode(HTMLElement, Element, {
398
411
  namespaceURI: "http://www.w3.org/1999/xhtml",
399
412
  nodeType: 1,
400
413
  tagName: null,
414
+ get elements() {
415
+ return this.tagName === "FORM" ? selector.find(this, "input,select,textarea,button") : undefined
416
+ },
401
417
  get sheet() {
402
418
  return makeSheet(this)
403
419
  },
404
420
  blur() {
405
421
  this.ownerDocument.activeElement = this.ownerDocument.body || null
406
422
  },
423
+ click() {
424
+ this.dispatchEvent(new Event("click", { bubbles: true, cancelable: true }))
425
+ },
407
426
  closest(sel) {
408
427
  return selector.closest(this, sel)
409
428
  },
429
+ addEventListener(type, fn) {
430
+ var map = listeners.get(this)
431
+ if (!map) listeners.set(this, map = {})
432
+ ;(map[type] || (map[type] = [])).push(fn)
433
+ },
434
+ dispatchEvent(ev) {
435
+ if (!ev.target) ev.target = this
436
+ var fns = (listeners.get(this) || {})[ev.type]
437
+ if (fns) fns.forEach(function(fn) { fn.call(this, ev) }, this)
438
+ if (ev.bubbles && this.parentNode && this.parentNode.dispatchEvent) {
439
+ this.parentNode.dispatchEvent(ev)
440
+ }
441
+ },
442
+ removeEventListener(type, fn) {
443
+ var fns = (listeners.get(this) || {})[type]
444
+ , i = fns ? fns.indexOf(fn) : -1
445
+ if (i > -1) fns.splice(i, 1)
446
+ },
410
447
  focus() {
411
448
  this.ownerDocument.activeElement = this
412
449
  },
@@ -571,6 +608,7 @@ exports.CSSStyleSheet = CSSStyleSheet
571
608
  exports.DOMParser = DOMParser
572
609
  exports.Document = Document
573
610
  exports.DocumentFragment = DocumentFragment
611
+ exports.Event = Event
574
612
  exports.HTMLElement = HTMLElement
575
613
  exports.Node = Node
576
614
  exports.XMLSerializer = XMLSerializer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/dom",
3
- "version": "26.2.0",
3
+ "version": "26.3.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>",
@@ -29,6 +29,6 @@
29
29
  "url": "https://github.com/litejs/dom.git"
30
30
  },
31
31
  "devDependencies": {
32
- "@litejs/cli": "25.1.0"
32
+ "@litejs/cli": "26.3.0"
33
33
  }
34
34
  }