j20 0.0.1 → 0.0.3

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 ADDED
@@ -0,0 +1,3 @@
1
+ # j20
2
+
3
+ [https://github.com/anuoua/j20](https://github.com/anuoua/j20)
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as csstype from "csstype";
2
- import { Computed, Effect, Signal, computed, effect as effect$1, signal } from "@j20org/signal";
2
+ import { Computed, Effect, Signal, computed, effect as effect$1, signal, untrack } from "@j20org/signal";
3
3
 
4
4
  //#region src/jsx.d.ts
5
5
 
@@ -3466,7 +3466,7 @@ declare const instanceGetElements: (instance: Instance) => Node[];
3466
3466
  declare const instanceDestroy: (parent: Instance, instance: Instance) => void;
3467
3467
  //#endregion
3468
3468
  //#region src/h/createRoot.d.ts
3469
- declare const creatRoot: (boot: () => JSX.Element) => {
3469
+ declare const createRoot: (boot: () => JSX.Element) => {
3470
3470
  element: HTMLElement;
3471
3471
  instance: Instance;
3472
3472
  };
@@ -3483,4 +3483,4 @@ declare const template: (template: string) => (isSvg: boolean) => any;
3483
3483
  //#region src/web-components.d.ts
3484
3484
  declare const registerWebComponent: <C extends WC<any, any>>(Comp: C) => void;
3485
3485
  //#endregion
3486
- export { $, $useContext, AttrValueType, Case, CaseProps, Computed, CustomElement, Default, DefaultProps, Dynamic, DynamicProps, DynamicPropsInner, Effect, FC, For, Fragment, If, IfProps, Instance, ListProps, RefObject, Signal, Switch, SwitchProps, WC, computed, creatRoot, createComponent, createContext, createDom, createElement, createLogicComponent, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, wc };
3486
+ export { $, $useContext, AttrValueType, Case, CaseProps, Computed, CustomElement, Default, DefaultProps, Dynamic, DynamicProps, DynamicPropsInner, Effect, FC, For, Fragment, If, IfProps, Instance, ListProps, RefObject, Signal, Switch, SwitchProps, WC, computed, createComponent, createContext, createDom, createElement, createLogicComponent, createRoot, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, untrack, wc };
package/dist/index.mjs CHANGED
@@ -229,7 +229,7 @@ const isEvent = (eventName) => {
229
229
  return eventName.startsWith("on");
230
230
  };
231
231
  const getEventName = (eventName) => {
232
- return eventName.slice(2).toLocaleLowerCase();
232
+ return eventName.slice(2).toLowerCase();
233
233
  };
234
234
  const getChildren = (propChildren) => {
235
235
  const arr = [];
@@ -257,6 +257,14 @@ const generateId = () => {
257
257
  }
258
258
  return `${overflow}${(count++).toString(32)}`;
259
259
  };
260
+ const styleObjectToString = (style) => {
261
+ let styleString = "";
262
+ for (const key in style) {
263
+ const value = style[key];
264
+ styleString += `${key}: ${value}; `;
265
+ }
266
+ return styleString.trim();
267
+ };
260
268
 
261
269
  //#endregion
262
270
  //#region src/h/createDom.ts
@@ -265,7 +273,10 @@ const update = (node, key, oldValue, newValue) => {
265
273
  node.removeEventListener(getEventName(key), oldValue);
266
274
  node.addEventListener(getEventName(key), newValue);
267
275
  } else if (newValue === false || newValue == null) node.removeAttribute(key);
268
- else node.setAttribute(key, newValue === true ? "" : newValue);
276
+ else {
277
+ const value = key === "style" && typeof newValue === "object" ? styleObjectToString(newValue) : newValue === true ? "" : newValue;
278
+ node.setAttribute(key, value);
279
+ }
269
280
  };
270
281
  const unset = (node, key, oldValue) => {
271
282
  if (isEvent(key)) node.removeEventListener(getEventName(key), oldValue);
@@ -279,7 +290,10 @@ const add = (node, key, newValue) => {
279
290
  newValue.current = null;
280
291
  });
281
292
  newValue.current = node;
282
- } else newValue !== false && newValue != null && node.setAttribute(key, newValue === true ? "" : newValue);
293
+ } else if (newValue !== false && newValue != null) {
294
+ const value = key === "style" && typeof newValue === "object" ? styleObjectToString(newValue) : newValue === true ? "" : newValue;
295
+ node.setAttribute(key, value);
296
+ }
283
297
  };
284
298
  const createDom = (tag, props, children) => {
285
299
  const node = tag;
@@ -339,10 +353,21 @@ const instanceGetElements = (instance) => {
339
353
  const instanceDestroy = (parent, instance) => {
340
354
  const stack$1 = [instance];
341
355
  while (stack$1.length) {
342
- const instance$1 = stack$1.pop();
343
- instance$1.disposes.forEach((dispose) => dispose());
344
- if (instance$1.children) stack$1.push(...instance$1.children);
356
+ const inst = stack$1.pop();
357
+ inst.disposes.forEach((dispose) => {
358
+ try {
359
+ dispose();
360
+ } catch (e) {
361
+ console.error("Error during instance dispose:", e);
362
+ }
363
+ });
364
+ inst.disposes = [];
365
+ if (inst.children) {
366
+ stack$1.push(...inst.children);
367
+ inst.children = [];
368
+ }
345
369
  }
370
+ if (parent && parent.children) parent.children = parent.children.filter((c) => c !== instance);
346
371
  };
347
372
 
348
373
  //#endregion
@@ -851,7 +876,7 @@ const createElement = (tag, props, children) => {
851
876
 
852
877
  //#endregion
853
878
  //#region src/h/createRoot.ts
854
- const creatRoot = (boot) => {
879
+ const createRoot = (boot) => {
855
880
  let [instance, fragment] = instanceCreate(() => boot());
856
881
  return {
857
882
  element: fragment,
@@ -871,13 +896,13 @@ const template = (template$1) => {
871
896
  let dom;
872
897
  return (isSvg) => {
873
898
  if (!dom) {
874
- const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("div");
899
+ const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("template");
875
900
  templateEl.innerHTML = template$1;
876
- dom = templateEl.firstChild;
877
- return dom.cloneNode();
878
- } else return dom.cloneNode();
901
+ dom = isSvg ? templateEl.firstChild : templateEl.content.firstChild;
902
+ }
903
+ return dom.cloneNode();
879
904
  };
880
905
  };
881
906
 
882
907
  //#endregion
883
- export { $, $useContext, Case, Computed, Default, Dynamic, Effect, For, Fragment, If, Signal, Switch, computed, creatRoot, createComponent, createContext, createDom, createElement, createLogicComponent, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, wc };
908
+ export { $, $useContext, Case, Computed, Default, Dynamic, Effect, For, Fragment, If, Signal, Switch, computed, createComponent, createContext, createDom, createElement, createLogicComponent, createRoot, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, untrack, wc };
@@ -1,4 +1,4 @@
1
- import { createElement } from ".";
1
+ import { createElement } from "./index";
2
2
 
3
3
  //#region src/jsx-runtime.ts
4
4
  const h2 = (tag, props, children) => {
@@ -11,11 +11,11 @@ const template = (template$1) => {
11
11
  let dom;
12
12
  return (isSvg) => {
13
13
  if (!dom) {
14
- const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("div");
14
+ const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("template");
15
15
  templateEl.innerHTML = template$1;
16
- dom = templateEl.firstChild;
17
- return dom.cloneNode();
18
- } else return dom.cloneNode();
16
+ dom = isSvg ? templateEl.firstChild : templateEl.content.firstChild;
17
+ }
18
+ return dom.cloneNode();
19
19
  };
20
20
  };
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j20",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "homepage": "https://www.github.com/anuoua/j20",
5
5
  "type": "module",
6
6
  "author": "anuoua",