nesquick 0.0.14 → 0.0.16

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.
@@ -15,6 +15,7 @@ class NesquickComponent {
15
15
  this._render = _render;
16
16
  this.props = props;
17
17
  this._subscriptions = new State_1.Subscriptions();
18
+ this._xmlns = null;
18
19
  this._children = [];
19
20
  this.props = props;
20
21
  }
@@ -22,11 +23,23 @@ class NesquickComponent {
22
23
  State_1.subscriptions.set(this._subscriptions);
23
24
  if (typeof this._render === "function") {
24
25
  functionizeProps(this.props);
25
- const res = this._render(this.props).render(document);
26
+ const element = this._render(this.props);
27
+ if (this._xmlns) {
28
+ element.inheritXmlns(this._xmlns);
29
+ }
30
+ const res = element.render(document);
26
31
  State_1.subscriptions.reset();
27
32
  return res;
28
33
  }
29
- const element = document.createElement(this._render);
34
+ if (this.props?.xmlns != null) {
35
+ if (typeof this.props.xmlns === "function") {
36
+ this._xmlns = this.props.xmlns();
37
+ }
38
+ else {
39
+ this._xmlns = this.props.xmlns;
40
+ }
41
+ }
42
+ const element = this._xmlns ? document.createElementNS(this._xmlns, this._render) : document.createElement(this._render);
30
43
  if (this.props != null) {
31
44
  this._renderProps(element, this.props);
32
45
  }
@@ -35,9 +48,14 @@ class NesquickComponent {
35
48
  State_1.subscriptions.reset();
36
49
  return element;
37
50
  }
51
+ inheritXmlns(xmlns) {
52
+ if (this.props?.xmlns != null) {
53
+ this._xmlns = xmlns;
54
+ }
55
+ }
38
56
  _renderProps(element, props) {
39
57
  for (const k in props) {
40
- if (k !== "children") {
58
+ if (k !== "children" && k !== "xmlns") {
41
59
  if (typeof props[k] === "function") {
42
60
  if (k.startsWith("on")) {
43
61
  element[k.toLowerCase()] = props[k];
@@ -136,6 +154,9 @@ class NesquickComponent {
136
154
  if (child instanceof NesquickFragment_1.NesquickFragment || Array.isArray(child)) {
137
155
  nesquickChild.component = null;
138
156
  nesquickChild.fragment = Array.isArray(child) ? new NesquickFragment_1.NesquickFragment(child) : child;
157
+ if (this._xmlns) {
158
+ nesquickChild.fragment.inheritXmlns(this._xmlns);
159
+ }
139
160
  const node = nesquickChild.fragment.render(document);
140
161
  const lastChild = node.lastChild;
141
162
  if (nesquickChild.node) {
@@ -149,6 +170,9 @@ class NesquickComponent {
149
170
  else if (child instanceof NesquickComponent) {
150
171
  nesquickChild.component = child;
151
172
  nesquickChild.fragment = null;
173
+ if (this._xmlns) {
174
+ child.inheritXmlns(this._xmlns);
175
+ }
152
176
  const node = child.render(document);
153
177
  if (nesquickChild.node) {
154
178
  parent.replaceChild(node, nesquickChild.node);
@@ -3,6 +3,7 @@ export type Children = Child | Child[];
3
3
  export type ChildFunc = () => Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[];
4
4
  export type ComponentProps = Record<string, any>;
5
5
  export type FunctionComponent<P extends ComponentProps = {}> = (props: P) => NesquickComponent<P>;
6
+ export type VeactDocument = Pick<Document, "createElement" | "createElementNS" | "createTextNode" | "createDocumentFragment" | "createComment">;
6
7
  type NesquickChild = {
7
8
  node: Node | null;
8
9
  } & ({
@@ -21,16 +22,18 @@ export declare class NesquickComponent<P extends ComponentProps = {}> {
21
22
  private _render;
22
23
  protected props: P;
23
24
  private _subscriptions;
25
+ private _xmlns;
24
26
  protected _children: NesquickChild[];
25
27
  constructor(_render: string | FunctionComponent<P>, props: P);
26
- render(document: Document): Node;
28
+ render(document: VeactDocument): Node;
29
+ inheritXmlns(xmlns: string | null): void;
27
30
  private _renderProps;
28
- protected _renderChildren(document: Document, parent: NesquickParent, children?: Children): void;
31
+ protected _renderChildren(document: VeactDocument, parent: NesquickParent, children?: Children): void;
29
32
  protected _pushChild(): NesquickChild;
30
33
  protected _spliceChild(i: number): NesquickChild;
31
34
  protected _swapChilds(parent: NesquickParent, i1: number, i2: number): void;
32
35
  protected _removeChild(i: number): void;
33
- protected _renderChild(document: Document, parent: NesquickParent, nesquickChild: NesquickChild, child: Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[]): void;
36
+ protected _renderChild(document: VeactDocument, parent: NesquickParent, nesquickChild: NesquickChild, child: Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[]): void;
34
37
  dispose(): void;
35
38
  }
36
39
  import { NesquickFragment } from "./NesquickFragment";
@@ -1,12 +1,12 @@
1
1
  import { JSX } from "./jsx-runtime";
2
- import { NesquickComponent, NesquickParent } from "./NesquickComponent";
2
+ import { NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
3
3
  export declare class NesquickFragment extends NesquickComponent<{
4
4
  children: any[];
5
5
  }> implements NesquickParent {
6
6
  private _lastNode;
7
7
  private _fragment;
8
8
  constructor(children: any[]);
9
- render(document: Document): Node;
9
+ render(document: VeactDocument): Node;
10
10
  getDocument(): Document | null;
11
11
  getParent(): Node | null;
12
12
  appendChild(child: Node): void;
@@ -11,14 +11,11 @@ type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R
11
11
  type ComponentProp<T> = T extends {
12
12
  readonly [WrappedFunctionType]?: infer R;
13
13
  } ? (T | R) : T extends (...args: any[]) => any ? T : (T | (() => T));
14
- type UnFunction<T> = T extends {
15
- readonly [WrappedFunctionType]?: infer R;
16
- } ? (T | R) : T;
17
14
  type UserProps<T> = {
18
- [K in keyof T]: K extends "children" ? T[K] : UserProp<T[K]>;
15
+ [K in keyof T]: UserProp<T[K]>;
19
16
  };
20
17
  type JSXProps<T> = keyof T extends never ? {} : {
21
- [K in keyof T]: K extends "children" ? UnFunction<T[K]> : ComponentProp<T[K]>;
18
+ [K in keyof T]: ComponentProp<T[K]>;
22
19
  };
23
20
  export type Generic<T> = T extends (...args: any) => infer R ? R : T;
24
21
  export { UserProps as Props };
@@ -33,9 +30,10 @@ export declare namespace JSX {
33
30
  export type JSXSVGEvent<T extends EventTarget> = {
34
31
  [K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
35
32
  };
36
- export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T> {
33
+ export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
37
34
  [k: string]: any;
38
35
  style?: StyleProps;
36
+ xmlns?: string;
39
37
  }
40
38
  export type StyleProps = {
41
39
  [K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
@@ -1,6 +1,6 @@
1
1
  export declare const viteTransformerPlugin: {
2
2
  name: string;
3
- enforce: string;
3
+ enforce: "pre";
4
4
  transform(code: string, id: string): {
5
5
  code: string;
6
6
  map: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "React-like library with focus on drawing performance",
5
5
  "types": "./lib/types",
6
6
  "main": "./lib",