Skip to content

Commit cd062f9

Browse files
committed
Merge branch 'release/v0.15.1'
2 parents 3aaf176 + 8fca01f commit cd062f9

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zeed-dom",
33
"type": "module",
4-
"version": "0.15.0",
4+
"version": "0.15.1",
55
"description": "🌱 Lightweight offline DOM",
66
"author": {
77
"name": "Dirk Holtwick",

src/htmlparser.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNv
5454
height: 100px;">Test</div>`) as VHTMLDocument
5555
const node = dom.querySelector('#elem')
5656
expect(node).not.toBeNull()
57+
expect(node?.style.length).toEqual(3)
58+
expect(node?.style.getPropertyValue('width')).toEqual('200px')
5759
expect(node?.style).toMatchInlineSnapshot(`
5860
{
5961
"background-image": "url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNy41LjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAzMTQ3IDIwMDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMxNDcgMjAwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGc)",
6062
"backgroundImage": "url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNy41LjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAzMTQ3IDIwMDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMxNDcgMjAwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGc)",
63+
"getPropertyValue": [Function],
6164
"height": "100px",
65+
"length": 3,
6266
"width": "200px",
6367
}
6468
`)

src/vdom.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,16 @@ interface Attr {
351351
value: string
352352
}
353353

354+
export type VElementStyle = Record<string, string> & {
355+
get length(): number
356+
getPropertyValue: (name: string) => any
357+
}
358+
354359
export class VElement extends VNodeQuery {
355360
_originalTagName: string
356361
_nodeName: string
357362
_attributes: Record<string, string>
358-
_styles: Record<string, string> | undefined
363+
_styles: VElementStyle | undefined
359364
_dataset: Record<string, string> | undefined
360365

361366
get nodeType() {
@@ -429,9 +434,13 @@ export class VElement extends VNodeQuery {
429434
}
430435

431436
/// See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
432-
get style() {
437+
get style(): VElementStyle {
433438
if (this._styles == null) {
434-
const styles = Object.assign({}, DEFAULTS[this.tagName.toLowerCase()] || {})
439+
// const styles = Object.assign({}, DEFAULTS[this.tagName.toLowerCase()] || {})
440+
441+
const styles: Record<string, string> = {}
442+
let count = 0
443+
435444
const styleString = this.getAttribute('style')
436445
if (styleString) {
437446
let m: string[] | null
@@ -441,15 +450,26 @@ export class VElement extends VNodeQuery {
441450

442451
// eslint-disable-next-line no-cond-assign
443452
while ((m = re.exec(styleString))) {
453+
++count
444454
const name = m[1]
445455
const value = m[2].trim()
446456
styles[name] = value
447457
styles[toCamelCase(name)] = value
448458
}
449459
}
450-
this._styles = styles
460+
this._styles = {
461+
get length(): number {
462+
return count
463+
},
464+
getPropertyValue(name: string) {
465+
return styles[name]
466+
},
467+
468+
...DEFAULTS[this.tagName.toLowerCase()],
469+
...styles,
470+
}
451471
}
452-
return this._styles
472+
return this._styles!
453473
}
454474

455475
/// See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

0 commit comments

Comments
 (0)