neobiz 4.7.2 → 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.
- package/example/async_components.v.js +88 -0
- package/example/basic_syntax.v.js +86 -22
- package/example/control_flow.v.js +89 -54
- package/example/fromString.v.js +63 -20
- package/example/interact_withDOM.v.js +79 -10
- package/example/loop_and_Array.v.js +94 -46
- package/example/style.v.js +118 -24
- package/f.js +19 -0
- package/index.d.ts +145 -0
- package/index.js +1726 -20
- package/index2.js +859 -0
- package/indexw.js +21 -0
- package/package.json +1 -1
- package/readme.md +518 -534
- package/readme_v4.md +735 -0
- package/example/boolean_attributes.js +0 -17
- package/example/explicit-tag.v..js +0 -16
- package/example/innerText&html.v.js +0 -15
- package/example/multi_tag.v.js +0 -13
- package/example/orderChild.v.js +0 -15
- /package/{browser.js → browser_v4.js} +0 -0
package/example/style.v.js
CHANGED
|
@@ -1,28 +1,122 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
1
|
import "../index.js";
|
|
4
2
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
}.render
|
|
13
|
-
);
|
|
3
|
+
// Configure output for clean snippet inspection
|
|
4
|
+
renderOption({
|
|
5
|
+
nodoctype: true,
|
|
6
|
+
pretty: true,
|
|
7
|
+
indentSize: 2,
|
|
8
|
+
});
|
|
14
9
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// 1. INLINE CSS (`.cssText`)
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Converts a camelCase JS object into an inline `style="..."` attribute string
|
|
14
|
+
const inlineStyleExample = {
|
|
15
|
+
h1: {
|
|
16
|
+
text: "Inline Styled Heading",
|
|
18
17
|
style: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
18
|
+
color: "#1B73F8",
|
|
19
|
+
fontSize: "24px",
|
|
20
|
+
borderBottom: "2px solid #e2e8f0",
|
|
21
|
+
paddingBottom: "8px",
|
|
22
|
+
}.cssText,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
console.log("--- 1. Inline CSS (`.cssText`) ---");
|
|
27
|
+
console.log(inlineStyleExample._render);
|
|
28
|
+
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// 2. GLOBAL `<style>` BLOCKS & REUSABLE MIXINS (`.css`)
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Supports nested selectors, pseudo-classes, and `@media` queries
|
|
33
|
+
const flexCenter = (direction = "row") => ({
|
|
34
|
+
display: "flex",
|
|
35
|
+
justifyContent: "center",
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
flexDirection: direction,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const globalStyles = {
|
|
41
|
+
body: {
|
|
42
|
+
margin: "0",
|
|
43
|
+
fontFamily: "system-ui, sans-serif",
|
|
44
|
+
},
|
|
45
|
+
".container": {
|
|
46
|
+
...flexCenter("column"),
|
|
47
|
+
minHeight: "100vh",
|
|
48
|
+
padding: "16px",
|
|
49
|
+
},
|
|
50
|
+
".btn": {
|
|
51
|
+
padding: "10px 20px",
|
|
52
|
+
backgroundColor: "#0f172a",
|
|
53
|
+
color: "#ffffff",
|
|
54
|
+
border: "none",
|
|
55
|
+
borderRadius: "6px",
|
|
56
|
+
},
|
|
57
|
+
"@media (max-width: 600px)": {
|
|
58
|
+
".btn": {
|
|
59
|
+
width: "100%",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Mutate style rules dynamically before rendering
|
|
65
|
+
globalStyles.body.backgroundColor = "#f8fafc";
|
|
66
|
+
|
|
67
|
+
const globalStyleExample = {
|
|
68
|
+
style: globalStyles.css,
|
|
69
|
+
"div.container": {
|
|
70
|
+
"button.btn": { text: "Global Styled Button" },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
console.log("\n--- 2. Global `<style>` Block (`.css`) ---");
|
|
75
|
+
console.log(globalStyleExample._render);
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// 3. AUTO-SCOPED COMPONENT CSS (`.regStyle()` & `.scope()`)
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Isolates styles to the target component and its descendants using `[data-nb-s]`.
|
|
81
|
+
// Use `self` or `:host` to style the root element itself.
|
|
82
|
+
|
|
83
|
+
({
|
|
84
|
+
self: {
|
|
85
|
+
border: "1px solid #cbd5e1",
|
|
86
|
+
borderRadius: "10px",
|
|
87
|
+
padding: "16px",
|
|
88
|
+
backgroundColor: "#ffffff",
|
|
89
|
+
},
|
|
90
|
+
h2: {
|
|
91
|
+
margin: "0 0 8px 0",
|
|
92
|
+
color: "#0f172a",
|
|
93
|
+
},
|
|
94
|
+
p: {
|
|
95
|
+
color: "#475569",
|
|
96
|
+
},
|
|
97
|
+
"button:hover": {
|
|
98
|
+
backgroundColor: "#2563eb",
|
|
99
|
+
color: "#ffffff",
|
|
100
|
+
},
|
|
101
|
+
}).regStyle("card-widget");
|
|
102
|
+
|
|
103
|
+
const CardWidget = (title, description) => ({
|
|
104
|
+
div: {
|
|
105
|
+
h2: { text: title },
|
|
106
|
+
p: { text: description },
|
|
107
|
+
button: { text: "Read More" },
|
|
108
|
+
},
|
|
109
|
+
}).scope("card-widget");
|
|
110
|
+
|
|
111
|
+
// Even when rendered multiple times, the scoped `<style>` tag is emitted only once
|
|
112
|
+
const scopedStyleExample = {
|
|
113
|
+
section: {
|
|
114
|
+
$: [
|
|
115
|
+
CardWidget("Card One", "Scoped styles do not leak outside this component."),
|
|
116
|
+
CardWidget("Card Two", "Shares the exact same deduplicated <style> block."),
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
console.log("\n--- 3. Auto-Scoped CSS (`.regStyle()` & `.scope()`) ---");
|
|
122
|
+
console.log(scopedStyleExample._render);
|
package/f.js
ADDED
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;
|