@pfern/elements 0.1.11 → 0.2.1
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/LICENSE +11 -11
- package/README.md +292 -62
- package/elements.js +4 -1942
- package/env.d.ts +24 -0
- package/mathml.js +1 -0
- package/package.json +20 -23
- package/src/core/elements.js +513 -0
- package/src/core/events.js +143 -0
- package/src/core/props.js +183 -0
- package/src/core/tags.js +225 -0
- package/src/core/tick.js +116 -0
- package/src/core/types.js +696 -0
- package/src/helpers.js +73 -0
- package/src/html.js +996 -0
- package/src/mathml.js +340 -0
- package/src/router.js +51 -0
- package/src/ssr.js +173 -0
- package/src/svg.js +407 -0
- package/types/elements.d.ts +4 -1394
- package/types/mathml.d.ts +1 -0
- package/types/src/core/elements.d.ts +29 -0
- package/types/src/core/events.d.ts +15 -0
- package/types/src/core/props.d.ts +9 -0
- package/types/src/core/tags.d.ts +4 -0
- package/types/src/core/tick.d.ts +5 -0
- package/types/src/core/types.d.ts +507 -0
- package/types/src/helpers.d.ts +5 -0
- package/types/src/html.d.ts +802 -0
- package/types/src/mathml.d.ts +264 -0
- package/types/src/router.d.ts +4 -0
- package/types/src/ssr.d.ts +3 -0
- package/types/src/svg.d.ts +348 -0
package/src/helpers.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enable additional debug warnings.
|
|
3
|
+
*
|
|
4
|
+
* Set `process.env.ELEMENTSJS_DEBUG=true` (or `NODE_ENV=development`) to enable
|
|
5
|
+
* warnings for common mistakes like passive event handler returns.
|
|
6
|
+
*/
|
|
7
|
+
export { DEBUG } from './core/elements.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a recursive pure function so it participates in replacement updates.
|
|
11
|
+
*
|
|
12
|
+
* Call the returned function again with new arguments to compute the next UI.
|
|
13
|
+
*
|
|
14
|
+
* @template {any[]} Args
|
|
15
|
+
* @param {(...args: Args) => any[]} fn
|
|
16
|
+
* @returns {(...args: Args) => any[]}
|
|
17
|
+
*/
|
|
18
|
+
export { component } from './core/elements.js'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A map of all HTML/SVG tag helpers (plus `fragment`).
|
|
22
|
+
*/
|
|
23
|
+
export { elements } from './core/elements.js'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Render a vnode into the DOM.
|
|
27
|
+
*
|
|
28
|
+
* This is typically called once on page load. After that, events that return
|
|
29
|
+
* vnodes perform replacement updates automatically.
|
|
30
|
+
*
|
|
31
|
+
* @param {any[]} vtree
|
|
32
|
+
* @param {HTMLElement | null} [container]
|
|
33
|
+
*/
|
|
34
|
+
export { render } from './core/elements.js'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Serialize a vnode tree to an HTML string (SSR/SSG).
|
|
38
|
+
*
|
|
39
|
+
* This is the “stringification” counterpart to `render()`: it walks the same
|
|
40
|
+
* declarative vnode arrays and produces static HTML for build-time prerendering
|
|
41
|
+
* or server-side rendering.
|
|
42
|
+
*
|
|
43
|
+
* @param {*} vnode
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
export { toHtmlString } from './ssr.js'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Navigate to a URL path and update the window history object.
|
|
50
|
+
*
|
|
51
|
+
* This dispatches a `popstate` event after updating history so router-style
|
|
52
|
+
* apps can react without additional plumbing.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} [path]
|
|
55
|
+
* @param {{ replace?: boolean }} [options]
|
|
56
|
+
*/
|
|
57
|
+
export const navigate = (path, { replace = false } = {}) => {
|
|
58
|
+
if (typeof window === 'undefined') return
|
|
59
|
+
|
|
60
|
+
const url = new URL(path, window.location.origin)
|
|
61
|
+
const isSame =
|
|
62
|
+
url.pathname === window.location.pathname
|
|
63
|
+
&& url.search === window.location.search
|
|
64
|
+
&& url.hash === window.location.hash
|
|
65
|
+
|
|
66
|
+
if (isSame) return
|
|
67
|
+
|
|
68
|
+
const fn = replace ? 'replaceState' : 'pushState'
|
|
69
|
+
window.history[fn]({}, '', url)
|
|
70
|
+
|
|
71
|
+
try { window.dispatchEvent(new PopStateEvent('popstate')) }
|
|
72
|
+
catch { window.dispatchEvent(new Event('popstate')) }
|
|
73
|
+
}
|