From 605a0042fb9f3af70bcae29923792c1cb63f2537 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Thu, 16 May 2024 14:43:32 +0200 Subject: [PATCH] fix: JSX.IntrinsicElements definitions --- env.d.ts | 6 ++++++ package.json | 8 +++++--- src/encoding.spec.ts | 2 +- src/encoding.ts | 2 +- src/h.spec.ts | 2 -- src/h.ts | 2 -- src/html.ts | 2 -- src/htmlparser.ts | 4 ++-- src/index.browser.ts | 2 +- src/index.node.ts | 2 -- src/jsx-intrinsicelements.ts | 8 ++++++++ src/jsx-runtime.ts | 2 ++ src/serialize-markdown.spec.tsx | 2 -- src/serialize-markdown.ts | 2 +- src/serialize-plaintext.ts | 2 +- src/serialize-safehtml.spec.ts | 2 -- src/tidy.spec.tsx | 2 -- src/tidy.ts | 2 -- src/utils.spec.ts | 2 -- src/utils.ts | 2 -- src/vcss.spec.tsx | 1 - src/vcss.ts | 2 -- src/vdom.ts | 2 +- src/xml.ts | 3 +-- 24 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 env.d.ts create mode 100644 src/jsx-intrinsicelements.ts diff --git a/env.d.ts b/env.d.ts new file mode 100644 index 0000000..db7de5e --- /dev/null +++ b/env.d.ts @@ -0,0 +1,6 @@ +declare namespace JSX { + /** See https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements */ + interface IntrinsicElements { + [elemName: string]: any + } +} diff --git a/package.json b/package.json index 7dbe5cc..9f48208 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,11 @@ "main": "dist/index.node.cjs", "module": "dist/index.browser.js", "typings": "dist/index.node.d.ts", + "types": "dist/index.node.d.ts", "files": [ "dist", - "jsx-runtime" + "jsx-runtime", + "env.d.ts" ], "engines": { "node": ">=14.13.1" @@ -70,9 +72,9 @@ "entities": "^4.5.0" }, "devDependencies": { - "@antfu/eslint-config": "^2.17.0", + "@antfu/eslint-config": "^2.18.0", "@antfu/ni": "^0.21.12", - "@types/node": "^20.12.11", + "@types/node": "^20.12.12", "@vitest/coverage-v8": "^1.6.0", "c8": "^9.1.0", "eslint": "^9.2.0", diff --git a/src/encoding.spec.ts b/src/encoding.spec.ts index 96cd25b..fb6fcaf 100644 --- a/src/encoding.spec.ts +++ b/src/encoding.spec.ts @@ -6,7 +6,7 @@ describe('encoding', () => { expect(escapeHTML(' &')).toEqual('<and> &') }) - it("should decode", () => { + it('should decode', () => { expect(unescapeHTML('& : ©')).toEqual('& : ©') }) }) diff --git a/src/encoding.ts b/src/encoding.ts index 2aa4042..c7cc844 100644 --- a/src/encoding.ts +++ b/src/encoding.ts @@ -1,5 +1,5 @@ // import { decode } from './encoding-he' -import { decodeHTML as decode} from 'entities' +import { decodeHTML as decode } from 'entities' export function escapeHTML(text: string) { return text diff --git a/src/h.spec.ts b/src/h.spec.ts index 063b387..f626e15 100644 --- a/src/h.spec.ts +++ b/src/h.spec.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { hArgumentParser } from './h' describe('h', () => { diff --git a/src/h.ts b/src/h.ts index 37ac930..f6ab388 100644 --- a/src/h.ts +++ b/src/h.ts @@ -1,5 +1,3 @@ -// Copyright (c) 2020 Dirk Holtwick. All rights reserved. https://holtwick.de/copyright - import type { VDocument, VDocumentFragment, VElement } from './vdom' /* diff --git a/src/html.ts b/src/html.ts index 98ae32e..529eba8 100644 --- a/src/html.ts +++ b/src/html.ts @@ -1,5 +1,3 @@ -// Copyright (c) 2020 Dirk Holtwick. All rights reserved. https://holtwick.de/copyright - // Special cases: // 1. is an element that is not printed out, can be used to create a list of elements // 2. Attribute name '__' gets transformed to ':' for namespace emulation diff --git a/src/htmlparser.ts b/src/htmlparser.ts index ae785b3..b6ab7f1 100644 --- a/src/htmlparser.ts +++ b/src/htmlparser.ts @@ -6,13 +6,13 @@ // 2. and then \s*=\s* // 3. and value can be "value" | 'value' | value // 4. 2 and 3 are optional -const attrRe = /([^=\s]+)(\s*=\s*(("([^"]*)")|('([^']*)')|[^>\s]+))?/gm +const attrRe = /([^=\s]+)(\s*=\s*(("([^"]*)")|('([^']*)')|[^>\s]+))?/g const endTagRe = /^<\/([^>\s]+)[^>]*>/m // start tag, like // 1. must start with or > -const startTagRe = /^<([^>\s\/]+)((\s+[^=>\s]+(\s*=\s*(("[^"]*")|('[^']*')|[^>\s]+))?)*)\s*\/?\s*>/m +const startTagRe = /^<([^>\s/]+)((\s+[^=>\s]+(\s*=\s*(("[^"]*")|('[^']*')|[^>\s]+))?)*)\s*(?:\/\s*)?>/m const selfCloseTagRe = /\s*\/\s*>\s*$/m /** diff --git a/src/index.browser.ts b/src/index.browser.ts index 32bad4b..e1c6ff5 100644 --- a/src/index.browser.ts +++ b/src/index.browser.ts @@ -1,4 +1,4 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. +export * from './jsx-intrinsicelements' export * from './vdom' export * from './h' diff --git a/src/index.node.ts b/src/index.node.ts index fa260c2..6141714 100644 --- a/src/index.node.ts +++ b/src/index.node.ts @@ -1,4 +1,2 @@ -// (C)opyright 2023 Dirk Holtwick, holtwick.it. All rights reserved. - export * from './index.browser' export { handleHTMLFile } from './node' diff --git a/src/jsx-intrinsicelements.ts b/src/jsx-intrinsicelements.ts new file mode 100644 index 0000000..9ed84fe --- /dev/null +++ b/src/jsx-intrinsicelements.ts @@ -0,0 +1,8 @@ +/* eslint-disable ts/no-namespace */ + +export declare namespace JSX { + /** See https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements */ + interface IntrinsicElements { + [elemName: string]: any + } +} diff --git a/src/jsx-runtime.ts b/src/jsx-runtime.ts index 65cdec7..181dce4 100644 --- a/src/jsx-runtime.ts +++ b/src/jsx-runtime.ts @@ -1,5 +1,7 @@ import { h } from './html' +export * from './jsx-intrinsicelements' + // See // https://esbuild.github.io/api/#jsx-import-source // https://www.typescriptlang.org/tsconfig/#jsxImportSource diff --git a/src/serialize-markdown.spec.tsx b/src/serialize-markdown.spec.tsx index 7438460..f51472e 100644 --- a/src/serialize-markdown.spec.tsx +++ b/src/serialize-markdown.spec.tsx @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { serializeMarkdown } from './serialize-markdown' import { serializePlaintext } from './serialize-plaintext' import { createHTMLDocument, h } from './vdom' diff --git a/src/serialize-markdown.ts b/src/serialize-markdown.ts index 15bc515..6beaeac 100644 --- a/src/serialize-markdown.ts +++ b/src/serialize-markdown.ts @@ -65,5 +65,5 @@ function serialize(node: VNode | VElement, context: SerializeContext = { } export function serializeMarkdown(node: VNode): string { - return `${serialize(node).replace(/\n\n+/gim, '\n\n').trim()}\n` + return `${serialize(node).replace(/\n{2,}/g, '\n\n').trim()}\n` } diff --git a/src/serialize-plaintext.ts b/src/serialize-plaintext.ts index 28bcffb..be4ac6f 100644 --- a/src/serialize-plaintext.ts +++ b/src/serialize-plaintext.ts @@ -43,5 +43,5 @@ function serialize(node: VNode | VElement, context: SerializeContext = { } export function serializePlaintext(node: VNode): string { - return `${serialize(node).replace(/\n\n+/gim, '\n\n').trim()}\n` + return `${serialize(node).replace(/\n{2,}/g, '\n\n').trim()}\n` } diff --git a/src/serialize-safehtml.spec.ts b/src/serialize-safehtml.spec.ts index 575fb49..9d4f84a 100644 --- a/src/serialize-safehtml.spec.ts +++ b/src/serialize-safehtml.spec.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { serializeSafeHTML } from './serialize-safehtml' import { parseHTML } from './vdomparser' diff --git a/src/tidy.spec.tsx b/src/tidy.spec.tsx index 18dc630..3f87efb 100644 --- a/src/tidy.spec.tsx +++ b/src/tidy.spec.tsx @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { tidyDOM } from './tidy' import { createHTMLDocument, h } from './vdom' diff --git a/src/tidy.ts b/src/tidy.ts index bc599d4..fcf1e65 100644 --- a/src/tidy.ts +++ b/src/tidy.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import type { VDocument } from './vdom' import { VNode, VTextNode } from './vdom' diff --git a/src/utils.spec.ts b/src/utils.spec.ts index 838b0cd..9c186c1 100644 --- a/src/utils.spec.ts +++ b/src/utils.spec.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { removeBodyContainer } from './utils' import { createHTMLDocument } from './vdom' diff --git a/src/utils.ts b/src/utils.ts index 2e27e07..03dba61 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import type { VNodeQuery } from './vdom' import { VDocumentFragment } from './vdom' diff --git a/src/vcss.spec.tsx b/src/vcss.spec.tsx index 8315d46..02dec78 100644 --- a/src/vcss.spec.tsx +++ b/src/vcss.spec.tsx @@ -1,4 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. import { matchSelector } from './vcss' import { createHTMLDocument, h } from './vdom' diff --git a/src/vcss.ts b/src/vcss.ts index a10eac3..51a5239 100644 --- a/src/vcss.ts +++ b/src/vcss.ts @@ -1,5 +1,3 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - import { parse } from 'css-what' import type { VElement } from './vdom' diff --git a/src/vdom.ts b/src/vdom.ts index 778cf4f..7800261 100644 --- a/src/vdom.ts +++ b/src/vdom.ts @@ -32,7 +32,7 @@ const DEFAULTS = { } as any function toCamelCase(s: string): string { - return s.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (_m, chr) => chr.toUpperCase()) + return s.toLowerCase().replace(/[^a-z0-9]+(.)/gi, (_m, chr) => chr.toUpperCase()) } export class VNode { diff --git a/src/xml.ts b/src/xml.ts index a95234c..2a80438 100644 --- a/src/xml.ts +++ b/src/xml.ts @@ -1,5 +1,4 @@ -// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. - +import './jsx-runtime' import { hArgumentParser } from './h' import { markup } from './html'