Skip to content

Commit

Permalink
Merge branch 'release/v0.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Dec 15, 2023
2 parents 4f179aa + 60185f3 commit b80dc42
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 295 deletions.
43 changes: 43 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml"
]
}
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({
ignores: ['dist', '**/dist/**', 'node_modules', '**/node_modules/**', 'build', '**/build/**', 'tmp', '**/tmp/**', 'demos', '**/demos/**', 'coverage', '**/coverage/**', '_archive', '**/_archive/**', '*.spec.*', '**/*.spec.*/**', 'vitest.config.ts', '**/vitest.config.ts/**', '*.md', '**/*.md/**', '*.yml', '**/*.yml/**'],
})
6 changes: 4 additions & 2 deletions examples/auto-jsx/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-console */
'use strict'
exports.__esModule = true
const dom = (<ol className="projects">
const dom = (
<ol className="projects">
<li>hostic</li>
<li>hostic-dom</li>
</ol>)
</ol>
)
console.log(dom)
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed-dom",
"type": "module",
"version": "0.10.11",
"version": "0.11.0",
"description": "🌱 Lightweight offline DOM",
"author": {
"name": "Dirk Holtwick",
Expand Down Expand Up @@ -68,15 +68,15 @@
"css-what": "^6.1.0"
},
"devDependencies": {
"@antfu/eslint-config": "^0.43.1",
"@antfu/ni": "^0.21.8",
"@types/node": "^20.8.4",
"@vitest/coverage-v8": "^0.34.6",
"@antfu/eslint-config": "^2.4.5",
"@antfu/ni": "^0.21.12",
"@types/node": "^20.10.4",
"@vitest/coverage-v8": "^1.0.4",
"c8": "^8.0.1",
"eslint": "^8.51.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vitest": "^0.34.6"
"eslint": "^8.55.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vite": "^5.0.9",
"vitest": "^1.0.4"
}
}
140 changes: 128 additions & 12 deletions src/encoding-he.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
/* eslint-disable ts/ban-ts-comment */
// @ts-nocheck

import { hasOwn } from './utils'
Expand Down Expand Up @@ -3822,17 +3822,133 @@ const decodeMapNumeric = {
159: '\u0178',
}
const invalidReferenceCodePoints = [
1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 64976, 64977, 64978, 64979, 64980,
64981, 64982, 64983, 64984, 64985, 64986, 64987, 64988, 64989, 64990, 64991,
64992, 64993, 64994, 64995, 64996, 64997, 64998, 64999, 65000, 65001, 65002,
65003, 65004, 65005, 65006, 65007, 65534, 65535, 131070, 131071, 196606,
196607, 262142, 262143, 327678, 327679, 393214, 393215, 458750, 458751,
524286, 524287, 589822, 589823, 655358, 655359, 720894, 720895, 786430,
786431, 851966, 851967, 917502, 917503, 983038, 983039, 1048574, 1048575,
1114110, 1114111,
1,
2,
3,
4,
5,
6,
7,
8,
11,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
127,
128,
129,
130,
131,
132,
133,
134,
135,
136,
137,
138,
139,
140,
141,
142,
143,
144,
145,
146,
147,
148,
149,
150,
151,
152,
153,
154,
155,
156,
157,
158,
159,
64976,
64977,
64978,
64979,
64980,
64981,
64982,
64983,
64984,
64985,
64986,
64987,
64988,
64989,
64990,
64991,
64992,
64993,
64994,
64995,
64996,
64997,
64998,
64999,
65000,
65001,
65002,
65003,
65004,
65005,
65006,
65007,
65534,
65535,
131070,
131071,
196606,
196607,
262142,
262143,
327678,
327679,
393214,
393215,
458750,
458751,
524286,
524287,
589822,
589823,
655358,
655359,
720894,
720895,
786430,
786431,
851966,
851967,
917502,
917503,
983038,
983039,
1048574,
1048575,
1114110,
1114111,
]

/* -------------------------------------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions src/encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { escapeHTML } from "."
import { escapeHTML } from '.'

describe("encoding", () => {
it("should encoding", () => {
expect(escapeHTML("</")).toEqual("&lt;/")
expect(escapeHTML("<and> &")).toEqual("&lt;and&gt; &amp;")
describe('encoding', () => {
it('should encoding', () => {
expect(escapeHTML('</')).toEqual('&lt;/')
expect(escapeHTML('<and> &')).toEqual('&lt;and&gt; &amp;')
})
})
2 changes: 2 additions & 0 deletions src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export function escapeHTML(text: string) {
.replace(/>/g, '&gt;')
.replace(/'/g, '&apos;')
.replace(/"/g, '&quot;')
.replace(/\xA0/g, '&nbsp;')
.replace(/\xAD/g, '&shy;')
}

// encode(text, {
Expand Down
26 changes: 13 additions & 13 deletions src/h.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved.

import { hArgumentParser } from "./h"
import { hArgumentParser } from './h'

describe("h", () => {
it("should flatten", () => {
let values = hArgumentParser("div", ["a", ["b", ["c", "d"], "e"]])
describe('h', () => {
it('should flatten', () => {
const values = hArgumentParser('div', ['a', ['b', ['c', 'd'], 'e']])
expect(values).toEqual({
attrs: {},
children: ["a", "b", "c", "d", "e"],
tag: "div",
children: ['a', 'b', 'c', 'd', 'e'],
tag: 'div',
})
})

it("should handle attrs", () => {
let values = hArgumentParser(
"div",
it('should handle attrs', () => {
const values = hArgumentParser(
'div',
{
attrs: {
a: 1,
Expand All @@ -23,8 +23,8 @@ describe("h", () => {
c: 3,
d: 4,
},
"a",
"b"
'a',
'b',
)
expect(values).toEqual({
attrs: {
Expand All @@ -33,8 +33,8 @@ describe("h", () => {
c: 3,
d: 4,
},
children: ["a", "b"],
tag: "div",
children: ['a', 'b'],
tag: 'div',
})
})
})
36 changes: 18 additions & 18 deletions src/html.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// Copyright (c) 2020 Dirk Holtwick. All rights reserved. https://holtwick.de/copyright
/** @jsx h */

import { html as h, CDATA } from "./html"
import { CDATA, html as h } from './html'

describe("HTML", () => {
it("should generate a string", () => {
let s = h("a", { href: "example.com" }, "Welcome & Hello &amp; Ciao")
describe('hTML', () => {
it('should generate a string', () => {
const s = h('a', { href: 'example.com' }, 'Welcome & Hello &amp; Ciao')
expect(s).toEqual(
'<a href="example.com">Welcome &amp; Hello &amp;amp; Ciao</a>'
'<a href="example.com">Welcome &amp; Hello &amp;amp; Ciao</a>',
) // the second & is correct, because plain string should be unescaped
})

it("should nest", () => {
let s = h("a", { href: "example.com" }, h("hr"), h("b", {}, "Welcome"))
it('should nest', () => {
const s = h('a', { href: 'example.com' }, h('hr'), h('b', {}, 'Welcome'))
expect(s).toEqual('<a href="example.com"><hr><b>Welcome</b></a>')
})

it("should use JSX", () => {
let spread = {
title: "Hello",
id: "greeting",
it('should use JSX', () => {
const spread = {
title: 'Hello',
id: 'greeting',
}
let s = (
const s = (
<a href="example.com" x="x" hidden={false} {...spread}>
<hr myCaseSensitiveAttribute="1" />
{null && "This is invisible"}
{null && 'This is invisible'}
<b>Welcome</b>
</a>
)

expect(s).toEqual(
'<a href="example.com" x="x" title="Hello" id="greeting"><hr myCaseSensitiveAttribute="1"><b>Welcome</b></a>'
'<a href="example.com" x="x" title="Hello" id="greeting"><hr myCaseSensitiveAttribute="1"><b>Welcome</b></a>',
)
})

it("should keep cdata", () => {
let s = <cdata>{"<b>Do not escape! & </b>"}</cdata>
it('should keep cdata', () => {
const s = <cdata>{'<b>Do not escape! & </b>'}</cdata>
expect(s).toMatchInlineSnapshot(`"<![CDATA[<b>Do not escape! & </b>]]>"`)

let s2 = <div>{CDATA("<b>Do not escape! & </b>")}</div>
const s2 = <div>{CDATA('<b>Do not escape! & </b>')}</div>
expect(s2).toMatchInlineSnapshot(
`"<div><![CDATA[<b>Do not escape! & </b>]]></div>"`
`"<div><![CDATA[<b>Do not escape! & </b>]]></div>"`,
)
})
})
4 changes: 2 additions & 2 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function markup(
const hasChildren = !(
(typeof children === 'string' && children === '')
|| (Array.isArray(children)
&& (children.length === 0
|| (children.length === 1 && children[0] === '')))
&& (children.length === 0
|| (children.length === 1 && children[0] === '')))
|| children == null
)

Expand Down
Loading

0 comments on commit b80dc42

Please sign in to comment.