neobiz 5.0.1 → 5.1.0

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.
Files changed (5) hide show
  1. package/f.js +19 -0
  2. package/index.d.ts +145 -0
  3. package/index.js +1726 -1
  4. package/package.json +1 -1
  5. package/readme.md +18 -0
package/f.js ADDED
@@ -0,0 +1,19 @@
1
+ import "./index.js";
2
+ const data = {
3
+ html: {
4
+ body: {
5
+ style: {
6
+ fontSize: "5rem"
7
+ },
8
+ script: {
9
+ id: "hero"
10
+ }
11
+ }
12
+ }
13
+ }
14
+
15
+ data.query("#hero", el => {
16
+ el.text = "you found me!"
17
+ })
18
+
19
+ console.log(data._render)
package/index.d.ts ADDED
@@ -0,0 +1,145 @@
1
+ export interface RenderOptions {
2
+ camelCase?: boolean;
3
+ once?: boolean;
4
+ nodoctype?: boolean;
5
+ ignoreTag?: boolean;
6
+ prefixTag?: string | false;
7
+ prefixAttr?: string | false;
8
+ pretty?: boolean;
9
+ indentSize?: number;
10
+ }
11
+
12
+ export interface DirectiveContext {
13
+ attrs: string[];
14
+ children: string[];
15
+ tagName: string;
16
+ node: NeobizNode;
17
+ element?: Element;
18
+ escapeHtml: (val: unknown) => string;
19
+ }
20
+
21
+ export type DirectiveHandler = (value: any, ctx: DirectiveContext) => void;
22
+ export type ClassValue = string | false | null | undefined | Record<string, boolean> | ClassValue[];
23
+ export type StyleObject = Record<string, string | number | Record<string, any>>;
24
+
25
+ export interface NeobizNode {
26
+ tag?: string;
27
+ id?: string;
28
+ class?: ClassValue;
29
+ style?: string | StyleObject;
30
+ text?: string | number | boolean | NeobizNode | NeobizNode[] | ((item?: any, index?: number) => any);
31
+ html?: string | (() => void) | NeobizNode | NeobizNode[] | ((item?: any, index?: number) => any);
32
+ when?: any;
33
+ elseIf?: any;
34
+ else?: boolean;
35
+ switch?: string | number;
36
+ cases?: Record<string, NeobizNode | false | null>;
37
+ each?: any[] | number;
38
+ bind?: Record<string, any> | ((item?: any, index?: number) => Record<string, any>);
39
+ fallback?: NeobizNode | ((err: unknown) => NeobizNode);
40
+ onError?: (err: unknown) => void;
41
+ cache?: boolean | string | number;
42
+ noprefix?: boolean;
43
+ nopAttr?: boolean;
44
+ $head?: NeobizNode | NeobizNode[];
45
+ $comment?: string;
46
+ $?: NeobizNode | NeobizNode[];
47
+ [key: string]: any;
48
+ }
49
+
50
+ export interface NeobizAPI {
51
+ readonly Null: symbol;
52
+ renderOption(opt: RenderOptions): void;
53
+ render(node: NeobizNode | NeobizNode[], opts?: RenderOptions): string;
54
+ renderAsync(node: NeobizNode | NeobizNode[], opts?: RenderOptions): Promise<string>;
55
+ renderStream(node: NeobizNode | NeobizNode[], opts?: RenderOptions): ReadableStream<string>;
56
+ query<T extends NeobizNode | NeobizNode[]>(node: T, selector: string, callback: (el: NeobizNode) => void): T;
57
+ repulse(html: string): NeobizNode;
58
+ addDirective(name: string, handler: DirectiveHandler): void;
59
+ removeDirective(name: string): void;
60
+ clearCache(key?: string | number): void;
61
+ regStyle<T extends StyleObject>(name: string, styleObj: T): T;
62
+ scope<T extends NeobizNode | NeobizNode[]>(node: T, name: string): T;
63
+ reg<T extends NeobizNode>(name: string, obj: T): T;
64
+ regm<T extends NeobizNode>(name: string, obj: T): T;
65
+ unreg(name: string): boolean;
66
+ load(name: string): NeobizNode | null;
67
+ css(styleObj: StyleObject): { text: string };
68
+ cssText(styleObj: StyleObject): string;
69
+ alter<T>(obj: T, callback: (target: T) => void): T;
70
+ mount(node: NeobizNode | NeobizNode[], target: Element | string): Element;
71
+ }
72
+
73
+ declare global {
74
+ const Neobiz: NeobizAPI;
75
+ const Null: symbol;
76
+ function renderOption(opt: RenderOptions): void;
77
+ function addDirective(name: string, handler: DirectiveHandler): void;
78
+ function removeDirective(name: string): void;
79
+ function clearCache(key?: string | number): void;
80
+ function load(name: string): NeobizNode | null;
81
+ function unreg(name: string): boolean;
82
+
83
+ interface Object {
84
+ readonly Null: symbol;
85
+ readonly _render: string;
86
+ readonly _renderAsync: Promise<string>;
87
+ readonly _renderStream: ReadableStream<string>;
88
+ readonly css: { text: string };
89
+ readonly cssText: string;
90
+ renderOption(opt: RenderOptions): void;
91
+ addDirective(name: string, handler: DirectiveHandler): void;
92
+ removeDirective(name: string): void;
93
+ clearCache(key?: string | number): void;
94
+ regStyle(name: string): this;
95
+ scope(name: string): this;
96
+ query(selector: string, callback: (node: NeobizNode) => void): this;
97
+ mount(target: Element | string): this;
98
+ reg(name: string): this;
99
+ regm(name: string): this;
100
+ unreg(name: string): boolean;
101
+ load(name: string): NeobizNode | null;
102
+ alter(callback: (obj: this) => void): this;
103
+ }
104
+
105
+ interface String {
106
+ readonly repulse: NeobizNode;
107
+ }
108
+
109
+ interface Array<T> {
110
+ range(len: number, start?: number): number[];
111
+ }
112
+
113
+ interface Document {
114
+ query(selector: string, callback: (el: Element) => void): this;
115
+ }
116
+
117
+ interface Element {
118
+ htmlObj: NeobizNode | NeobizNode[];
119
+ query(selector: string, callback: (el: Element) => void): this;
120
+ appendObj(obj: NeobizNode | NeobizNode[]): this;
121
+ mountObj(obj: NeobizNode | NeobizNode[]): Element;
122
+ }
123
+ }
124
+
125
+ export const Null: symbol;
126
+ export const renderOption: NeobizAPI["renderOption"];
127
+ export const render: NeobizAPI["render"];
128
+ export const renderAsync: NeobizAPI["renderAsync"];
129
+ export const renderStream: NeobizAPI["renderStream"];
130
+ export const query: NeobizAPI["query"];
131
+ export const repulse: NeobizAPI["repulse"];
132
+ export const addDirective: NeobizAPI["addDirective"];
133
+ export const removeDirective: NeobizAPI["removeDirective"];
134
+ export const clearCache: NeobizAPI["clearCache"];
135
+ export const regStyle: NeobizAPI["regStyle"];
136
+ export const scope: NeobizAPI["scope"];
137
+ export const reg: NeobizAPI["reg"];
138
+ export const regm: NeobizAPI["regm"];
139
+ export const unreg: NeobizAPI["unreg"];
140
+ export const load: NeobizAPI["load"];
141
+ export const css: NeobizAPI["css"];
142
+ export const cssText: NeobizAPI["cssText"];
143
+ export const alter: NeobizAPI["alter"];
144
+ export const mount: NeobizAPI["mount"];
145
+ export default Neobiz;