@react5/dom-jsx 0.1.8 → 0.1.10

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/README.md CHANGED
@@ -54,7 +54,7 @@ type instead, call the component directly or call `jsx(Modal, null)` /
54
54
 
55
55
  ## Runtime behavior
56
56
 
57
- Intrinsic JSX tags become DOM elements. `class` sets `className`, `style` accepts a style object, DOM properties are assigned when available, boolean attributes use presence semantics, and `onClick`-style function props become event listeners. Text, nested nodes, arrays, fragments, and function components are supported; `null`, `undefined`, and boolean children are ignored.
57
+ Intrinsic JSX tags become DOM elements. Prefer `className` over `class`, while both supported. `class` sets `className`, `style` accepts a style object, DOM properties are assigned when available, boolean attributes use presence semantics, and `onClick`-style function props become event listeners. Text, nested nodes, arrays, fragments, and function components are supported; `null`, `undefined`, and boolean children are ignored.
58
58
 
59
59
  Compound event props require camel casing, such as `onMouseEnter`, `onMouseLeave`,
60
60
  `onFocusIn`, `onFocusOut`, `onKeyDown`, and `onAnimationEnd`.
@@ -69,6 +69,16 @@ import { jsx, jsxs, jsxDEV, Fragment } from '@react5/dom-jsx/jsx-dev-runtime'
69
69
 
70
70
  `@react5/dom-jsx/jsx-runtime` also re-exports the same names and is what the TypeScript/Vite JSX transform imports automatically; `@react5/dom-jsx` is the shorter path for importing helpers like `createRef` directly in your own code.
71
71
 
72
+ ### SVG
73
+
74
+ Use `svge()` function to load raw svg. With vite use raw import:
75
+
76
+ ```ts
77
+ import iconSvg from "./assets/icon.svg?raw"
78
+ const icon = svge(iconSvg)
79
+ <div>{icon}</div>
80
+ ```
81
+
72
82
  ### Refs
73
83
 
74
84
  Capture the created DOM node without a later `querySelector` call using `createRef` or a callback ref:
@@ -79,7 +89,7 @@ import { createRef } from '@react5/dom-jsx'
79
89
  const inputRef = createRef<HTMLInputElement>()
80
90
  const form = (
81
91
  <form>
82
- <input class="action-form__input" ref={inputRef} />
92
+ <input className="action-form__input" ref={inputRef} />
83
93
  </form>
84
94
  ) as HTMLFormElement
85
95
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{Fragment as r,createContext as m,createRef as o,dispose as t,jsx as e,jsxs as i,onCleanup as j,onDispose as p,useContext as s}from"./jsx-runtime.js";export{r as Fragment,m as createContext,o as createRef,t as dispose,e as jsx,i as jsxs,j as onCleanup,p as onDispose,s as useContext};
1
+ import{Fragment as r,createContext as m,createRef as o,dispose as t,jsx as e,jsxs as i,onCleanup as j,onDispose as p,svge as s,useContext as x}from"./jsx-runtime.js";export{r as Fragment,m as createContext,o as createRef,t as dispose,e as jsx,i as jsxs,j as onCleanup,p as onDispose,s as svge,x as useContext};
@@ -22,6 +22,7 @@ export type Ref<T> = {
22
22
  } | ((el: T) => void);
23
23
  export type ElementProps<T extends HTMLElement> = Partial<Omit<T, 'children' | 'style' | 'className'>> & EventProps<T> & {
24
24
  class?: string;
25
+ className?: string;
25
26
  style?: Partial<CSSStyleDeclaration>;
26
27
  children?: unknown;
27
28
  ref?: Ref<T>;
@@ -53,4 +54,5 @@ export declare function jsx<P, R extends Node>(tag: (props: P) => R, props: {} e
53
54
  export declare function jsx(tag: string, props: Props | null, _key?: string | number): Node;
54
55
  export declare const jsxs: typeof jsx;
55
56
  export declare function Fragment(props: Props): DocumentFragment;
57
+ export declare function svge(markup: string): SVGSVGElement;
56
58
  export {};
@@ -1 +1 @@
1
- function e(){return{current:null}}var t=/* @__PURE__ */new WeakMap;function n(e){const n=[],o={Provider({value:e,children:t}){if("function"!=typeof t)throw new TypeError("Context Provider expects a single function child: {() => ...}");n.push(e);try{const e=t();if(e instanceof Node)return e;const n=document.createDocumentFragment();return m(n,e),n}finally{n.pop()}}};return t.set(o,{defaultValue:e,stack:n}),o}function o(e){const n=t.get(e);if(!n)throw new TypeError("useContext expects a context created by createContext");const{defaultValue:o,stack:r}=n;return r.length>0?r[r.length-1]:o}var r=/* @__PURE__ */new WeakMap,c=[];function s(e,t){const n=r.get(e);n?n.push(t):r.set(e,[t])}function i(e,t){s(e,()=>t())}function f(e){const t=c[c.length-1];if(!t)throw new Error("onCleanup must be called while a component is rendering; use onDispose(node, fn) instead");t.cleanups.push(e)}function u(e){const t=[];if(l(e,t),1===t.length)throw t[0];if(t.length>1)throw new AggregateError(t,"Multiple cleanups failed during dispose")}function l(e,t){for(const r of Array.from(e.childNodes))l(r,t);const n=r.get(e);if(n){r.delete(e);for(let e=n.length-1;e>=0;e--)try{n[e](t)}catch(o){t.push(o)}}}function a(e,t){for(let o=e.length-1;o>=0;o--)try{e[o]()}catch(n){t.push(n)}}function d(e,t){if(e instanceof Node)t.push(e);else if(Array.isArray(e))for(const n of e)d(n,t)}function p(e,t){const n={cleanups:[],rendered:[]};let o;c.push(n);try{o=e(t)}catch(f){throw c.pop(),function(e,t){const n=[],o=[...e.rendered];for(const r of Object.values(t))d(r,o);for(const r of o)r.isConnected||l(r,n);a(e.cleanups,n)}(n,t),f}c.pop();let r=[o];if(o instanceof DocumentFragment&&(!o.firstChild&&n.cleanups.length>0&&o.appendChild(document.createComment("")),r=Array.from(o.childNodes)),n.cleanups.length>0)if(1===r.length)for(const c of n.cleanups)i(r[0],c);else{let e=r.length;for(const t of r)s(t,t=>{0===--e&&a(n.cleanups,t)})}return c[c.length-1]?.rendered.push(...r),o}function h(e,t,n){return function(e,t){const n=t??{};if("function"==typeof e)return p(e,n);const o=document.createElement(e);for(const[c,s]of Object.entries(n))if("children"!==c&&"ref"!==c)if(c.startsWith("on")&&"function"==typeof s)o.addEventListener(c.slice(2).toLowerCase(),s);else if("class"!==c){if("style"===c&&s&&"object"==typeof s)Object.assign(o.style,s);else if(null!=s)if(c.includes("-"))o.setAttribute(c,String(s));else{if(c in o){if(!1===s)continue;try{o[c]=s;continue}catch{}}o.setAttribute(c,!0===s?"":String(s))}}else o.className=String(s??"");m(o,n.children);const r=n.ref;"function"==typeof r?r(o):r&&(r.current=o);return o}(e,t)}var g=h;function y(e){const t=document.createDocumentFragment();return m(t,e.children),t}function m(e,t){if(Array.isArray(t))for(const n of t)m(e,n);else t instanceof Node?e.appendChild(t):null!=t&&!1!==t&&!0!==t&&e.appendChild(document.createTextNode(String(t)))}export{y as Fragment,n as createContext,e as createRef,u as dispose,h as jsx,g as jsxs,f as onCleanup,i as onDispose,o as useContext};
1
+ function e(){return{current:null}}var t=/* @__PURE__ */new WeakMap;function n(e){const n=[],r={Provider({value:e,children:t}){if("function"!=typeof t)throw new TypeError("Context Provider expects a single function child: {() => ...}");n.push(e);try{const e=t();if(e instanceof Node)return e;const n=document.createDocumentFragment();return y(n,e),n}finally{n.pop()}}};return t.set(r,{defaultValue:e,stack:n}),r}function r(e){const n=t.get(e);if(!n)throw new TypeError("useContext expects a context created by createContext");const{defaultValue:r,stack:o}=n;return o.length>0?o[o.length-1]:r}var o=/* @__PURE__ */new WeakMap,c=[];function s(e,t){const n=o.get(e);n?n.push(t):o.set(e,[t])}function i(e,t){s(e,()=>t())}function a(e){const t=c[c.length-1];if(!t)throw new Error("onCleanup must be called while a component is rendering; use onDispose(node, fn) instead");t.cleanups.push(e)}function u(e){const t=[];if(f(e,t),1===t.length)throw t[0];if(t.length>1)throw new AggregateError(t,"Multiple cleanups failed during dispose")}function f(e,t){for(const o of Array.from(e.childNodes))f(o,t);const n=o.get(e);if(n){o.delete(e);for(let e=n.length-1;e>=0;e--)try{n[e](t)}catch(r){t.push(r)}}}function l(e,t){for(let r=e.length-1;r>=0;r--)try{e[r]()}catch(n){t.push(n)}}function d(e,t){if(e instanceof Node)t.push(e);else if(Array.isArray(e))for(const n of e)d(n,t)}function p(e,t){const n={cleanups:[],rendered:[]};let r;c.push(n);try{r=e(t)}catch(a){throw c.pop(),function(e,t){const n=[],r=[...e.rendered];for(const o of Object.values(t))d(o,r);for(const o of r)o.isConnected||f(o,n);l(e.cleanups,n)}(n,t),a}c.pop();let o=[r];if(r instanceof DocumentFragment&&(!r.firstChild&&n.cleanups.length>0&&r.appendChild(document.createComment("")),o=Array.from(r.childNodes)),n.cleanups.length>0)if(1===o.length)for(const c of n.cleanups)i(o[0],c);else{let e=o.length;for(const t of o)s(t,t=>{0===--e&&l(n.cleanups,t)})}return c[c.length-1]?.rendered.push(...o),r}function h(e,t,n){return function(e,t){const n=t??{};if("function"==typeof e)return p(e,n);const r=document.createElement(e);void 0===n.class&&void 0===n.className||(r.className=String(n.className??n.class??""));for(const[c,s]of Object.entries(n))if("children"!==c&&"ref"!==c)if(c.startsWith("on")&&"function"==typeof s)r.addEventListener(c.slice(2).toLowerCase(),s);else if("class"!==c&&"className"!==c)if("style"===c&&s&&"object"==typeof s)Object.assign(r.style,s);else if(null!=s)if(c.includes("-"))r.setAttribute(c,String(s));else{if(c in r){if(!1===s)continue;try{r[c]=s;continue}catch{}}r.setAttribute(c,!0===s?"":String(s))}y(r,n.children);const o=n.ref;"function"==typeof o?o(r):o&&(o.current=r);return r}(e,t)}var g=h;function m(e){const t=document.createDocumentFragment();return y(t,e.children),t}function y(e,t){if(Array.isArray(t))for(const n of t)y(e,n);else t instanceof Node?e.appendChild(t):null!=t&&!1!==t&&!0!==t&&e.appendChild(document.createTextNode(String(t)))}function w(e){const t=(new DOMParser).parseFromString(e,"image/svg+xml").documentElement;if("parsererror"===t.nodeName||"http://www.w3.org/2000/svg"!==t.namespaceURI)throw new Error(`svge: failed to parse SVG markup: ${e}`);const n=document.importNode(t,!0);return n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),n}export{m as Fragment,n as createContext,e as createRef,u as dispose,h as jsx,g as jsxs,a as onCleanup,i as onDispose,w as svge,r as useContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react5/dom-jsx",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "JSX runtime for vanilla TS/JS projects.",
5
5
  "keywords": [
6
6
  "JSX"