chocola 1.3.3 → 1.3.4
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/chocola-1.3.3.tgz +0 -0
- package/compiler/component-processor.js +13 -11
- package/package.json +1 -1
- package/types/index.js +0 -135
|
Binary file
|
|
@@ -31,22 +31,24 @@ export function processComponentElement(
|
|
|
31
31
|
if (instance && instance.body) {
|
|
32
32
|
let body = instance.body;
|
|
33
33
|
body = body.replace(
|
|
34
|
-
/(?<!\b(?:if|del-if)=)\{
|
|
34
|
+
/(?<!\b(?:if|del-if)=)\{(\w+)\}/g,
|
|
35
35
|
(_, key) => ctx[key] || ""
|
|
36
36
|
);
|
|
37
37
|
const fragment = JSDOM.fragment(body);
|
|
38
38
|
const children = Array.from(fragment.querySelectorAll("*"));
|
|
39
39
|
children.forEach(child => {
|
|
40
|
-
if
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
["if", "del-if"].forEach(statement => {
|
|
41
|
+
const statAtt = child.getAttribute(statement);
|
|
42
|
+
if (!statAtt) return;
|
|
43
|
+
const expr = statAtt.slice(1, -1);
|
|
44
|
+
const fn = new Function("ctx", `return ctx.${expr} === true || ctx.${expr} === '{true}'`);
|
|
45
|
+
if (!fn(ctx)) {
|
|
46
|
+
if (statement === "if") child.style.display = "none";
|
|
47
|
+
if (statement === "del-if") child.remove();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
child.removeAttribute(statement);
|
|
51
|
+
});
|
|
50
52
|
});
|
|
51
53
|
const firstChild = fragment.firstChild;
|
|
52
54
|
|
package/package.json
CHANGED
package/types/index.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const iconsType = "home" | "search" | "menu" | "settings" | "favorite" | "account_circle" | "shopping_cart" | "notifications" | "info" | "help" | "exit_to_app" | "check_circle" | "close" | "edit" | "delete" | "add" | "arrow_back" | "arrow_forward" | "play_arrow" | "pause" | "stop" | "camera_alt" | "photo" | "alarm" | "event" | "attach_file" | "print" | "share" | "cloud" | "cloud_upload" | "cloud_download" | "lock" | "lock_open" | "visibility" | "visibility_off" | "phone" | "email" | "map" | "place" | "directions" | "train" | "directions_car" | "directions_bike" | "school" | "work" | "lightbulb" | "battery_full" | "battery_std" | "wifi" | "bluetooth";
|
|
2
|
-
const iconsArray = [
|
|
3
|
-
"home", "search", "menu", "settings", "favorite", "account_circle",
|
|
4
|
-
"shopping_cart", "notifications", "info", "help", "exit_to_app",
|
|
5
|
-
"check_circle", "close", "edit", "delete", "add", "arrow_back",
|
|
6
|
-
"arrow_forward", "play_arrow", "pause", "stop", "camera_alt",
|
|
7
|
-
"photo", "alarm", "event", "attach_file", "print", "share",
|
|
8
|
-
"cloud", "cloud_upload", "cloud_download", "lock", "lock_open",
|
|
9
|
-
"visibility", "visibility_off", "phone", "email", "map", "place",
|
|
10
|
-
"directions", "train", "directions_car", "directions_bike", "school",
|
|
11
|
-
"work", "lightbulb", "battery_full", "battery_std", "wifi", "bluetooth"
|
|
12
|
-
];
|
|
13
|
-
/**
|
|
14
|
-
* An instrinsic object that contains chocola types
|
|
15
|
-
*/
|
|
16
|
-
const ct = {};
|
|
17
|
-
/**
|
|
18
|
-
* Creates an interface for the component static context
|
|
19
|
-
* @param {object} ctxInterface
|
|
20
|
-
*/
|
|
21
|
-
ct.defCtx = (ctxInterface) => {
|
|
22
|
-
if (!ctxInterface) return undefined;
|
|
23
|
-
if (typeof ctxInterface !== "object") return;
|
|
24
|
-
return ctxInterface;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
ct.Number = class Number {
|
|
28
|
-
/**
|
|
29
|
-
* @param {number} value
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
constructor(value) {
|
|
33
|
-
if (!value) return undefined;
|
|
34
|
-
if (typeof value !== "number") return;
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @param {number} min
|
|
39
|
-
* @param {number} max
|
|
40
|
-
* @returns {number}
|
|
41
|
-
*/
|
|
42
|
-
clamp(min, max) {
|
|
43
|
-
return Math.min(Math.max(this.value, min), max);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @param {number} min
|
|
47
|
-
* @returns {number}
|
|
48
|
-
*/
|
|
49
|
-
min(min) {
|
|
50
|
-
return Math.min(this.value, min);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @param {number} max
|
|
54
|
-
* @returns {number}
|
|
55
|
-
*/
|
|
56
|
-
max(max) {
|
|
57
|
-
return Math.max(this.value, max);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @param {number} value
|
|
62
|
-
*/
|
|
63
|
-
ct.Float = (value) => {
|
|
64
|
-
if (!value) return undefined;
|
|
65
|
-
if (Number.isInteger(value)) return;
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @param {number} value
|
|
70
|
-
*/
|
|
71
|
-
ct.Int = (value) => {
|
|
72
|
-
if (!value) return undefined;
|
|
73
|
-
if (!Number.isInteger(value)) return;
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @param {string} value
|
|
78
|
-
*/
|
|
79
|
-
ct.String = (value) => {
|
|
80
|
-
if (!value) return undefined;
|
|
81
|
-
if (typeof value !== "string") return;
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @param {boolean} value
|
|
86
|
-
*/
|
|
87
|
-
ct.Boolean = (value) => {
|
|
88
|
-
if (value === null) return undefined;
|
|
89
|
-
if (typeof value !== "boolean") return;
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @param {object} value
|
|
94
|
-
*/
|
|
95
|
-
ct.Object = (value) => {
|
|
96
|
-
if (!value) return undefined;
|
|
97
|
-
if (typeof value !== "object") return;
|
|
98
|
-
return value;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @param {function} value
|
|
102
|
-
*/
|
|
103
|
-
ct.Function = (value) => {
|
|
104
|
-
if (!value) return undefined;
|
|
105
|
-
if (typeof value !== "function") return;
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @param {symbol} value
|
|
110
|
-
*/
|
|
111
|
-
ct.Symbol = (value) => {
|
|
112
|
-
if (!value) return undefined;
|
|
113
|
-
if (typeof value !== "symbol") return;
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @param {URLPattern | "none"} value
|
|
118
|
-
*/
|
|
119
|
-
ct.Url = (value) => {
|
|
120
|
-
if (!value) return undefined;
|
|
121
|
-
if (!value.startsWith("http://") || !value.startsWith("https://")) return;
|
|
122
|
-
return value;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
* @param {"home" | "search" | "menu" | "settings" | "favorite" | "account_circle" | "shopping_cart" | "notifications" | "info" | "help" | "exit_to_app" | "check_circle" | "close" | "edit" | "delete" | "add" | "arrow_back" | "arrow_forward" | "play_arrow" | "pause" | "stop" | "camera_alt" | "photo" | "alarm" | "event" | "attach_file" | "print" | "share" | "cloud" | "cloud_upload" | "cloud_download" | "lock" | "lock_open" | "visibility" | "visibility_off" | "phone" | "email" | "map" | "place" | "directions" | "train" | "directions_car" | "directions_bike" | "school" | "work" | "lightbulb" | "battery_full" | "battery_std" | "wifi" | "bluetooth"} value
|
|
127
|
-
* @returns
|
|
128
|
-
*/
|
|
129
|
-
ct.Icon = (value) => {
|
|
130
|
-
if (!value) return "help";
|
|
131
|
-
if (!iconsArray.includes(value)) return "help";
|
|
132
|
-
return value;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export default ct;
|