@vef-framework/core 1.0.101 → 1.0.103

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.
@@ -1,35 +1 @@
1
- /*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.569Z, made by Venus. */
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
-
6
- const reactQuery = require('@tanstack/react-query');
7
-
8
- function createQueryClient(options) {
9
- const staleTime = options?.staleTime ?? Infinity;
10
- const gcTime = options?.gcTime ?? 10 * 60 * 1e3;
11
- return new reactQuery.QueryClient({
12
- defaultOptions: {
13
- queries: {
14
- networkMode: "always",
15
- staleTime,
16
- gcTime,
17
- retry: false,
18
- structuralSharing: true,
19
- throwOnError: false,
20
- refetchOnMount: false,
21
- refetchOnReconnect: true,
22
- refetchOnWindowFocus: true
23
- },
24
- mutations: {
25
- networkMode: "always",
26
- gcTime: staleTime,
27
- retry: false,
28
- throwOnError: false
29
- }
30
- }
31
- });
32
- }
33
-
34
- exports.createQueryClient = createQueryClient;
35
- /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
1
+ "use strict";/*! VefFramework version: 1.0.103, build time: 2025-03-07T17:03:51.390Z, made by Venus. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const reactQuery=require("@tanstack/react-query");function createQueryClient(options){const staleTime=options?.staleTime??1/0,gcTime=options?.gcTime??10*60*1e3;return new reactQuery.QueryClient({defaultOptions:{queries:{networkMode:"always",staleTime,gcTime,retry:!1,structuralSharing:!0,throwOnError:!1,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!0},mutations:{networkMode:"always",gcTime:staleTime,retry:!1,throwOnError:!1}}})}exports.createQueryClient=createQueryClient;/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -1,249 +1 @@
1
- /*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.569Z, made by Venus. */
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
-
6
- const shared = require('@vef-framework/shared');
7
- const axios = require('axios');
8
- const qs = require('qs');
9
-
10
- var __typeError = (msg) => {
11
- throw TypeError(msg);
12
- };
13
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
14
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
15
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
16
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
17
- var _axiosInstance;
18
- const pathParamRegex = /\{\w+\}/;
19
- class RequestClient {
20
- constructor(options) {
21
- this.options = options;
22
- /**
23
- * The axios instance.
24
- */
25
- __privateAdd(this, _axiosInstance);
26
- const {
27
- baseUrl,
28
- timeout,
29
- getAccessToken,
30
- successCode = 0,
31
- unauthorizedCode = 1e3,
32
- accessDeniedCode = 1002,
33
- tokenExpiredCode = 1001,
34
- onUnauthorized,
35
- onAccessDenied
36
- } = options;
37
- __privateSet(this, _axiosInstance, axios.create({
38
- baseURL: baseUrl,
39
- timeout: timeout ?? 1e3 * 30,
40
- headers: {
41
- "Content-Type": "application/json"
42
- },
43
- paramsSerializer: (params) => qs.stringify(
44
- params,
45
- {
46
- arrayFormat: "repeat",
47
- skipNulls: true,
48
- charset: "utf-8"
49
- }
50
- ),
51
- responseType: "json",
52
- validateStatus: () => true
53
- }));
54
- __privateGet(this, _axiosInstance).interceptors.request.use((config) => {
55
- const token = getAccessToken?.();
56
- if (token) {
57
- config.headers.Authorization = `Bearer ${token}`;
58
- }
59
- const { url } = config;
60
- if (url && pathParamRegex.test(url)) {
61
- config.url = url.replace(pathParamRegex, (_, key) => {
62
- const value = config.params?.[key];
63
- if (shared.isNullish(value)) {
64
- throw new Error(`Path parameter ${key} is nil`);
65
- }
66
- return value;
67
- });
68
- }
69
- return config;
70
- });
71
- __privateGet(this, _axiosInstance).interceptors.response.use(
72
- async (response) => {
73
- const { code, message } = response.data;
74
- if (code === successCode) {
75
- return response;
76
- } else if (code === unauthorizedCode) {
77
- await onUnauthorized?.();
78
- } else if (code === tokenExpiredCode) {
79
- shared.showInfoMessage("登录已失效");
80
- await onUnauthorized?.();
81
- } else if (code === accessDeniedCode) {
82
- shared.showWarningMessage(`${message},请联系管理员为您开通`);
83
- await onAccessDenied?.();
84
- } else {
85
- shared.showWarningMessage(message);
86
- }
87
- throw new shared.VefError(code, message);
88
- },
89
- (error) => {
90
- if (error instanceof axios.CanceledError) {
91
- return Promise.reject(error);
92
- }
93
- const { response, message } = error;
94
- if (response?.data) {
95
- const errorMessage = `处理请求响应信息异常:${message ?? "无"}`;
96
- return Promise.reject(new shared.VefError(response.status, errorMessage));
97
- } else {
98
- let errorMessage = message ?? (shared.isString(error) ? error : "");
99
- if (errorMessage === "Network Error") {
100
- errorMessage = "接口连接异常可能原因:网络不通或存在跨域问题。";
101
- } else if (errorMessage.includes("timeout")) {
102
- errorMessage = "接口请求超时";
103
- } else if (errorMessage.includes("Request failed with status code")) {
104
- const code = message.substring(message.length - 3);
105
- errorMessage = `接口状态码异常:${code}`;
106
- } else {
107
- errorMessage = "接口未知异常";
108
- }
109
- shared.showErrorMessage(errorMessage);
110
- return Promise.reject(new shared.VefError(-1, errorMessage));
111
- }
112
- }
113
- );
114
- }
115
- /**
116
- * Perform a GET request.
117
- *
118
- * @param url - The url.
119
- * @param options - The request options.
120
- * @returns The response data promise.
121
- */
122
- async get(url, options) {
123
- const response = await __privateGet(this, _axiosInstance).get(url, {
124
- params: options?.params,
125
- signal: options?.signal
126
- });
127
- return response.data;
128
- }
129
- /**
130
- * Perform a POST request.
131
- *
132
- * @param url - The url.
133
- * @param data - The request data.
134
- * @param options - The request options.
135
- * @returns The response data promise.
136
- */
137
- async post(url, data, options) {
138
- const response = await __privateGet(this, _axiosInstance).post(url, data, {
139
- params: options?.params,
140
- signal: options?.signal
141
- });
142
- return response.data;
143
- }
144
- /**
145
- * Perform a PUT request.
146
- *
147
- * @param url - The url.
148
- * @param data - The request data.
149
- * @param options - The request options.
150
- * @returns The response data promise.
151
- */
152
- async put(url, data, options) {
153
- const response = await __privateGet(this, _axiosInstance).put(url, data, {
154
- params: options?.params,
155
- signal: options?.signal
156
- });
157
- return response.data;
158
- }
159
- /**
160
- * Perform a DELETE request.
161
- *
162
- * @param url - The url.
163
- * @param options - The request options.
164
- * @returns The response data promise.
165
- */
166
- async delete(url, options) {
167
- const response = await __privateGet(this, _axiosInstance).delete(url, {
168
- params: options?.params,
169
- signal: options?.signal
170
- });
171
- return response.data;
172
- }
173
- /**
174
- * Perform a file upload request.
175
- *
176
- * @param url - The url.
177
- * @param data - The file data.
178
- * @param options - The request options.
179
- * @returns The response data promise.
180
- */
181
- async upload(url, data, options) {
182
- const response = await __privateGet(this, _axiosInstance).postForm(
183
- url,
184
- data,
185
- {
186
- params: options?.params,
187
- signal: options?.signal,
188
- onUploadProgress: shared.isFunction(options?.onProgress) ? (progressEvent) => {
189
- const total = progressEvent.lengthComputable ? progressEvent.total ?? 0 : 0;
190
- const { loaded } = progressEvent;
191
- const percent = Math.round(loaded / total * 100);
192
- options.onProgress?.(percent);
193
- } : void 0
194
- }
195
- );
196
- return response.data;
197
- }
198
- /**
199
- * Perform a file download request.
200
- *
201
- * @param url - The url.
202
- * @param options - The request options.
203
- */
204
- async download(url, options) {
205
- const { data, headers } = await __privateGet(this, _axiosInstance).get(
206
- url,
207
- {
208
- params: options?.params,
209
- responseType: "blob",
210
- onDownloadProgress: shared.isFunction(options?.onProgress) ? (progressEvent) => {
211
- const total = progressEvent.lengthComputable ? progressEvent.total ?? 0 : 0;
212
- const { loaded } = progressEvent;
213
- const percent = Math.round(loaded / total * 100);
214
- options.onProgress?.(percent);
215
- } : void 0
216
- }
217
- );
218
- let response = null;
219
- try {
220
- response = JSON.parse(await data.text());
221
- } catch {
222
- }
223
- if (response && response.code !== 0) {
224
- throw new shared.VefError(response.code, response.message);
225
- }
226
- const contentDisposition = headers.get("content-disposition");
227
- if (shared.isString(contentDisposition)) {
228
- const fileNameRegex = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/;
229
- const matches = fileNameRegex.exec(contentDisposition);
230
- if (matches && matches.groups) {
231
- const { name } = matches.groups;
232
- const fileName = decodeURIComponent(name);
233
- const a = document.createElement("a");
234
- a.href = URL.createObjectURL(data);
235
- a.download = shared.isFunction(options?.fileName) ? options.fileName(fileName) : options?.fileName ?? fileName;
236
- a.click();
237
- URL.revokeObjectURL(a.href);
238
- }
239
- }
240
- }
241
- }
242
- _axiosInstance = new WeakMap();
243
- function createRequestClient(options) {
244
- return Object.freeze(new RequestClient(options));
245
- }
246
-
247
- exports.RequestClient = RequestClient;
248
- exports.createRequestClient = createRequestClient;
249
- /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
1
+ "use strict";/*! VefFramework version: 1.0.103, build time: 2025-03-07T17:03:51.390Z, made by Venus. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const shared=require("@vef-framework/shared"),axios=require("axios"),qs=require("qs");var __typeError=msg=>{throw TypeError(msg)},__accessCheck=(obj,member,msg)=>member.has(obj)||__typeError("Cannot "+msg),__privateGet=(obj,member,getter)=>(__accessCheck(obj,member,"read from private field"),getter?getter.call(obj):member.get(obj)),__privateAdd=(obj,member,value)=>member.has(obj)?__typeError("Cannot add the same private member more than once"):member instanceof WeakSet?member.add(obj):member.set(obj,value),__privateSet=(obj,member,value,setter)=>(__accessCheck(obj,member,"write to private field"),setter?setter.call(obj,value):member.set(obj,value),value),_axiosInstance;const pathParamRegex=/\{\w+\}/;class RequestClient{constructor(options){this.options=options,__privateAdd(this,_axiosInstance);const{baseUrl,timeout,getAccessToken,successCode=0,unauthorizedCode=1e3,accessDeniedCode=1002,tokenExpiredCode=1001,onUnauthorized,onAccessDenied}=options;__privateSet(this,_axiosInstance,axios.create({baseURL:baseUrl,timeout:timeout??1e3*30,headers:{"Content-Type":"application/json"},paramsSerializer:params=>qs.stringify(params,{arrayFormat:"repeat",skipNulls:!0,charset:"utf-8"}),responseType:"json",validateStatus:()=>!0})),__privateGet(this,_axiosInstance).interceptors.request.use(config=>{const token=getAccessToken?.();token&&(config.headers.Authorization=`Bearer ${token}`);const{url}=config;return url&&pathParamRegex.test(url)&&(config.url=url.replace(pathParamRegex,(_,key)=>{const value=config.params?.[key];if(shared.isNullish(value))throw new Error(`Path parameter ${key} is nil`);return value})),config}),__privateGet(this,_axiosInstance).interceptors.response.use(async response=>{const{code,message}=response.data;if(code===successCode)return response;throw code===unauthorizedCode?await onUnauthorized?.():code===tokenExpiredCode?(shared.showInfoMessage("登录已失效"),await onUnauthorized?.()):code===accessDeniedCode?(shared.showWarningMessage(`${message},请联系管理员为您开通`),await onAccessDenied?.()):shared.showWarningMessage(message),new shared.VefError(code,message)},error=>{if(error instanceof axios.CanceledError)return Promise.reject(error);const{response,message}=error;if(response?.data){const errorMessage=`处理请求响应信息异常:${message??"无"}`;return Promise.reject(new shared.VefError(response.status,errorMessage))}else{let errorMessage=message??(shared.isString(error)?error:"");return errorMessage==="Network Error"?errorMessage="接口连接异常可能原因:网络不通或存在跨域问题。":errorMessage.includes("timeout")?errorMessage="接口请求超时":errorMessage.includes("Request failed with status code")?errorMessage=`接口状态码异常:${message.substring(message.length-3)}`:errorMessage="接口未知异常",shared.showErrorMessage(errorMessage),Promise.reject(new shared.VefError(-1,errorMessage))}})}async get(url,options){return(await __privateGet(this,_axiosInstance).get(url,{params:options?.params,signal:options?.signal})).data}async post(url,data,options){return(await __privateGet(this,_axiosInstance).post(url,data,{params:options?.params,signal:options?.signal})).data}async put(url,data,options){return(await __privateGet(this,_axiosInstance).put(url,data,{params:options?.params,signal:options?.signal})).data}async delete(url,options){return(await __privateGet(this,_axiosInstance).delete(url,{params:options?.params,signal:options?.signal})).data}async upload(url,data,options){return(await __privateGet(this,_axiosInstance).postForm(url,data,{params:options?.params,signal:options?.signal,onUploadProgress:shared.isFunction(options?.onProgress)?progressEvent=>{const total=progressEvent.lengthComputable?progressEvent.total??0:0,{loaded}=progressEvent,percent=Math.round(loaded/total*100);options.onProgress?.(percent)}:void 0})).data}async download(url,options){const{data,headers}=await __privateGet(this,_axiosInstance).get(url,{params:options?.params,responseType:"blob",onDownloadProgress:shared.isFunction(options?.onProgress)?progressEvent=>{const total=progressEvent.lengthComputable?progressEvent.total??0:0,{loaded}=progressEvent,percent=Math.round(loaded/total*100);options.onProgress?.(percent)}:void 0});let response=null;try{response=JSON.parse(await data.text())}catch{}if(response&&response.code!==0)throw new shared.VefError(response.code,response.message);const contentDisposition=headers.get("content-disposition");if(shared.isString(contentDisposition)){const matches=/filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/.exec(contentDisposition);if(matches&&matches.groups){const{name}=matches.groups,fileName=decodeURIComponent(name),a=document.createElement("a");a.href=URL.createObjectURL(data),a.download=shared.isFunction(options?.fileName)?options.fileName(fileName):options?.fileName??fileName,a.click(),URL.revokeObjectURL(a.href)}}}}_axiosInstance=new WeakMap;function createRequestClient(options){return Object.freeze(new RequestClient(options))}exports.RequestClient=RequestClient,exports.createRequestClient=createRequestClient;/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -1,41 +1 @@
1
- /*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.569Z, made by Venus. */
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
-
6
- const shared = require('@vef-framework/shared');
7
- const react = require('react');
8
-
9
- const Context = react.createContext(null);
10
- const AuthContextProvider = ({
11
- permissionChecker,
12
- children
13
- }) => {
14
- const authContext = react.useMemo(() => ({
15
- checkPermission: (token) => {
16
- if (!permissionChecker) {
17
- return true;
18
- }
19
- if (shared.isString(token)) {
20
- return permissionChecker(token);
21
- }
22
- return permissionChecker(token.key);
23
- }
24
- }), [permissionChecker]);
25
- return react.createElement(
26
- Context.Provider,
27
- { value: authContext },
28
- children
29
- );
30
- };
31
- function useAuthContext() {
32
- const context = react.useContext(Context);
33
- if (context === null) {
34
- throw new shared.VefError(-1, "useAuthContext must be used within a AuthContextProvider");
35
- }
36
- return context;
37
- }
38
-
39
- exports.AuthContextProvider = AuthContextProvider;
40
- exports.useAuthContext = useAuthContext;
41
- /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
1
+ "use strict";/*! VefFramework version: 1.0.103, build time: 2025-03-07T17:03:51.390Z, made by Venus. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const shared=require("@vef-framework/shared"),react=require("react"),Context=react.createContext(null),AuthContextProvider=({permissionChecker,children})=>{const authContext=react.useMemo(()=>({checkPermission:token=>permissionChecker?shared.isString(token)?permissionChecker(token):permissionChecker(token.key):!0}),[permissionChecker]);return react.createElement(Context.Provider,{value:authContext},children)};function useAuthContext(){const context=react.useContext(Context);if(context===null)throw new shared.VefError(-1,"useAuthContext must be used within a AuthContextProvider");return context}exports.AuthContextProvider=AuthContextProvider,exports.useAuthContext=useAuthContext;/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -1,12 +1 @@
1
- /*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.569Z, made by Venus. */
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
-
6
- const authContext = require('./auth-context.cjs');
7
-
8
-
9
-
10
- exports.AuthContextProvider = authContext.AuthContextProvider;
11
- exports.useAuthContext = authContext.useAuthContext;
12
- /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
1
+ "use strict";/*! VefFramework version: 1.0.103, build time: 2025-03-07T17:03:51.390Z, made by Venus. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const authContext=require("./auth-context.cjs");exports.AuthContextProvider=authContext.AuthContextProvider,exports.useAuthContext=authContext.useAuthContext;/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -1,304 +1 @@
1
- /*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.569Z, made by Venus. */
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
-
6
- const helpers = require('./helpers.cjs');
7
-
8
- function compile(expr) {
9
- let provideTokens;
10
- const requirements = /* @__PURE__ */ new Set();
11
- const x = function expand(operand, tokens) {
12
- return typeof operand === "function" ? operand(tokens) : operand;
13
- };
14
- const operatorRegistry = [
15
- {
16
- "&&": (l, r, t) => x(l, t) && x(r, t),
17
- "||": (l, r, t) => x(l, t) || x(r, t)
18
- },
19
- {
20
- "===": (l, r, t) => !!(x(l, t) === x(r, t)),
21
- "!==": (l, r, t) => !!(x(l, t) !== x(r, t)),
22
- // eslint-disable-next-line eqeqeq
23
- "==": (l, r, t) => !!(x(l, t) == x(r, t)),
24
- // eslint-disable-next-line eqeqeq
25
- "!=": (l, r, t) => !!(x(l, t) != x(r, t)),
26
- ">=": (l, r, t) => !!(x(l, t) >= x(r, t)),
27
- "<=": (l, r, t) => !!(x(l, t) <= x(r, t)),
28
- ">": (l, r, t) => !!(x(l, t) > x(r, t)),
29
- "<": (l, r, t) => !!(x(l, t) < x(r, t))
30
- },
31
- {
32
- "+": (l, r, t) => x(l, t) + x(r, t),
33
- "-": (l, r, t) => x(l, t) - x(r, t)
34
- },
35
- {
36
- "*": (l, r, t) => x(l, t) * x(r, t),
37
- "/": (l, r, t) => x(l, t) / x(r, t),
38
- "%": (l, r, t) => x(l, t) % x(r, t)
39
- }
40
- ];
41
- const operatorSymbols = operatorRegistry.reduce((s, g) => s.concat(Object.keys(g)), []);
42
- const operatorChars = new Set(operatorSymbols.map((key) => key.charAt(0)));
43
- function getOp(symbols, char, p, expression) {
44
- const candidates = symbols.filter((s) => s.startsWith(char));
45
- if (!candidates.length) {
46
- return false;
47
- }
48
- return candidates.find((symbol) => {
49
- if (expression.length >= p + symbol.length) {
50
- const nextChars = expression.substring(p, p + symbol.length);
51
- if (nextChars === symbol) {
52
- return symbol;
53
- }
54
- }
55
- return false;
56
- });
57
- }
58
- function getStep(p, expression, direction = 1) {
59
- let next = direction ? expression.substring(p + 1).trim() : expression.substring(0, p).trim();
60
- if (!next.length) {
61
- return -1;
62
- }
63
- if (!direction) {
64
- const reversed = next.split("").reverse();
65
- const start = reversed.findIndex((char2) => operatorChars.has(char2));
66
- next = reversed.slice(start).join("");
67
- }
68
- const [char] = next;
69
- return operatorRegistry.findIndex((operators) => {
70
- const symbols = Object.keys(operators);
71
- return !!getOp(symbols, char, 0, next);
72
- });
73
- }
74
- function getTail(pos, expression) {
75
- let tail = "";
76
- const { length } = expression;
77
- let depth = 0;
78
- for (let p = pos; p < length; p++) {
79
- const char = expression.charAt(p);
80
- if (char === "(") {
81
- depth++;
82
- } else if (char === ")") {
83
- depth--;
84
- } else if (depth === 0 && char === " ") {
85
- continue;
86
- }
87
- if (depth === 0 && getOp(operatorSymbols, char, p, expression)) {
88
- return [tail, p - 1];
89
- } else {
90
- tail += char;
91
- }
92
- }
93
- return [tail, expression.length - 1];
94
- }
95
- function compileExpr(expression, step = 0) {
96
- const operators = operatorRegistry[step];
97
- const { length } = expression;
98
- const symbols = Object.keys(operators);
99
- let depth = 0;
100
- let quote = false;
101
- let op = null;
102
- let operand = "";
103
- let left = null;
104
- let operation;
105
- let lastChar;
106
- let char = "";
107
- let parenthetical = "";
108
- let parenQuote = "";
109
- let startP = 0;
110
- const addTo = (depth2, char2) => {
111
- if (depth2) {
112
- parenthetical += char2;
113
- } else {
114
- operand += char2;
115
- }
116
- };
117
- for (let p = 0; p < length; p++) {
118
- lastChar = char;
119
- char = expression.charAt(p);
120
- if ((char === "'" || char === '"') && lastChar !== "\\" && (depth === 0 && !quote || depth && !parenQuote)) {
121
- if (depth) {
122
- parenQuote = char;
123
- } else {
124
- quote = char;
125
- }
126
- addTo(depth, char);
127
- continue;
128
- } else if (quote && (char !== quote || lastChar === "\\") || parenQuote && (char !== parenQuote || lastChar === "\\")) {
129
- addTo(depth, char);
130
- continue;
131
- } else if (quote === char) {
132
- quote = false;
133
- addTo(depth, char);
134
- continue;
135
- } else if (parenQuote === char) {
136
- parenQuote = false;
137
- addTo(depth, char);
138
- continue;
139
- } else if (char === " ") {
140
- continue;
141
- } else if (char === "(") {
142
- if (depth === 0) {
143
- startP = p;
144
- } else {
145
- parenthetical += char;
146
- }
147
- depth++;
148
- } else if (char === ")") {
149
- depth--;
150
- if (depth === 0) {
151
- const fn = typeof operand === "string" && operand.startsWith("$") ? operand : void 0;
152
- const hasTail = fn && expression.charAt(p + 1) === ".";
153
- let tail = "";
154
- if (hasTail) {
155
- [tail, p] = getTail(p + 2, expression);
156
- }
157
- const lStep = op ? step : getStep(startP, expression, 0);
158
- const rStep = getStep(p, expression);
159
- if (lStep === -1 && rStep === -1) {
160
- operand = evaluate(parenthetical, -1, fn, tail);
161
- if (typeof operand === "string") {
162
- operand = parenthetical;
163
- }
164
- } else if (op && (lStep >= rStep || rStep === -1) && step === lStep) {
165
- left = op.bind(null, evaluate(parenthetical, -1, fn, tail));
166
- op = null;
167
- operand = "";
168
- } else if (rStep > lStep && step === rStep) {
169
- operand = evaluate(parenthetical, -1, fn, tail);
170
- } else {
171
- operand += `(${parenthetical})${hasTail ? `.${tail}` : ""}`;
172
- }
173
- parenthetical = "";
174
- } else {
175
- parenthetical += char;
176
- }
177
- } else if (depth === 0 && (operation = getOp(symbols, char, p, expression))) {
178
- if (p === 0) {
179
- console.error(103, [operation, expression]);
180
- }
181
- p += operation.length - 1;
182
- if (p === expression.length - 1) {
183
- console.error(104, [operation, expression]);
184
- }
185
- if (!op) {
186
- if (left) {
187
- op = operators[operation].bind(null, evaluate(left, step));
188
- left = null;
189
- } else {
190
- op = operators[operation].bind(null, evaluate(operand, step));
191
- operand = "";
192
- }
193
- } else if (operand) {
194
- left = op.bind(null, evaluate(operand, step));
195
- op = operators[operation].bind(null, left);
196
- operand = "";
197
- }
198
- continue;
199
- } else {
200
- addTo(depth, char);
201
- }
202
- }
203
- if (operand && op) {
204
- op = op.bind(null, evaluate(operand, step));
205
- }
206
- op = !op && left ? left : op;
207
- if (!op && operand) {
208
- op = (v, t) => typeof v === "function" ? v(t) : v;
209
- op = op.bind(null, evaluate(operand, step));
210
- }
211
- if (!op && !operand) {
212
- console.error(105, expression);
213
- }
214
- return op;
215
- }
216
- function evaluate(operand, step, fnToken, tail) {
217
- if (fnToken) {
218
- const fn = evaluate(fnToken, operatorRegistry.length);
219
- let userFuncReturn;
220
- let tailCall = tail ? compile(`$${tail}`) : false;
221
- if (typeof fn === "function") {
222
- const args = helpers.parseArgs(String(operand)).map(
223
- (arg) => evaluate(arg, -1)
224
- );
225
- return (tokens) => {
226
- const userFunc = fn(tokens);
227
- if (typeof userFunc !== "function") {
228
- console.warn(150, fnToken);
229
- return userFunc;
230
- }
231
- userFuncReturn = userFunc(
232
- ...args.map(
233
- (arg) => typeof arg === "function" ? arg(tokens) : arg
234
- )
235
- );
236
- if (tailCall) {
237
- tailCall = tailCall.provide((subTokens) => {
238
- const rootTokens = provideTokens(subTokens);
239
- const t = subTokens.reduce(
240
- (tokenSet, token) => {
241
- const isTail = token === tail || tail?.startsWith(`${token}(`);
242
- if (isTail) {
243
- const value = helpers.getAt(userFuncReturn, token);
244
- tokenSet[token] = () => value;
245
- } else {
246
- tokenSet[token] = rootTokens[token];
247
- }
248
- return tokenSet;
249
- },
250
- {}
251
- );
252
- return t;
253
- });
254
- }
255
- return tailCall ? tailCall() : userFuncReturn;
256
- };
257
- }
258
- } else if (typeof operand === "string") {
259
- if (operand === "true") {
260
- return true;
261
- }
262
- if (operand === "false") {
263
- return false;
264
- }
265
- if (operand === "undefined") {
266
- return void 0;
267
- }
268
- if (helpers.isQuotedString(operand)) {
269
- return helpers.rmEscapes(operand.substring(1, operand.length - 1));
270
- }
271
- if (!Number.isNaN(+operand)) {
272
- return Number(operand);
273
- }
274
- if (step < operatorRegistry.length - 1) {
275
- return compileExpr(operand, step + 1);
276
- } else {
277
- if (operand.startsWith("$")) {
278
- const cleaned = operand.substring(1);
279
- requirements.add(cleaned);
280
- return function getToken(tokens) {
281
- return cleaned in tokens ? tokens[cleaned]() : void 0;
282
- };
283
- }
284
- return operand;
285
- }
286
- }
287
- return operand;
288
- }
289
- const compiled = compileExpr(expr);
290
- const identifiers = Array.from(requirements);
291
- function provide(callback) {
292
- provideTokens = callback;
293
- return Object.assign(
294
- compiled.bind(null, callback(identifiers)),
295
- { provide }
296
- );
297
- }
298
- return Object.assign(compiled, {
299
- provide
300
- });
301
- }
302
-
303
- exports.compile = compile;
304
- /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
1
+ "use strict";/*! VefFramework version: 1.0.103, build time: 2025-03-07T17:03:51.390Z, made by Venus. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const helpers=require("./helpers.cjs");function compile(expr){let provideTokens;const requirements=new Set,x=function(operand,tokens){return typeof operand=="function"?operand(tokens):operand},operatorRegistry=[{"&&":(l,r,t)=>x(l,t)&&x(r,t),"||":(l,r,t)=>x(l,t)||x(r,t)},{"===":(l,r,t)=>x(l,t)===x(r,t),"!==":(l,r,t)=>x(l,t)!==x(r,t),"==":(l,r,t)=>x(l,t)==x(r,t),"!=":(l,r,t)=>x(l,t)!=x(r,t),">=":(l,r,t)=>x(l,t)>=x(r,t),"<=":(l,r,t)=>x(l,t)<=x(r,t),">":(l,r,t)=>x(l,t)>x(r,t),"<":(l,r,t)=>x(l,t)<x(r,t)},{"+":(l,r,t)=>x(l,t)+x(r,t),"-":(l,r,t)=>x(l,t)-x(r,t)},{"*":(l,r,t)=>x(l,t)*x(r,t),"/":(l,r,t)=>x(l,t)/x(r,t),"%":(l,r,t)=>x(l,t)%x(r,t)}],operatorSymbols=operatorRegistry.reduce((s,g)=>s.concat(Object.keys(g)),[]),operatorChars=new Set(operatorSymbols.map(key=>key.charAt(0)));function getOp(symbols,char,p,expression){const candidates=symbols.filter(s=>s.startsWith(char));return candidates.length?candidates.find(symbol=>expression.length>=p+symbol.length&&expression.substring(p,p+symbol.length)===symbol?symbol:!1):!1}function getStep(p,expression,direction=1){let next=direction?expression.substring(p+1).trim():expression.substring(0,p).trim();if(!next.length)return-1;if(!direction){const reversed=next.split("").reverse(),start=reversed.findIndex(char2=>operatorChars.has(char2));next=reversed.slice(start).join("")}const[char]=next;return operatorRegistry.findIndex(operators=>{const symbols=Object.keys(operators);return!!getOp(symbols,char,0,next)})}function getTail(pos,expression){let tail="";const{length}=expression;let depth=0;for(let p=pos;p<length;p++){const char=expression.charAt(p);if(char==="(")depth++;else if(char===")")depth--;else if(depth===0&&char===" ")continue;if(depth===0&&getOp(operatorSymbols,char,p,expression))return[tail,p-1];tail+=char}return[tail,expression.length-1]}function compileExpr(expression,step=0){const operators=operatorRegistry[step],{length}=expression,symbols=Object.keys(operators);let depth=0,quote=!1,op=null,operand="",left=null,operation,lastChar,char="",parenthetical="",parenQuote="",startP=0;const addTo=(depth2,char2)=>{depth2?parenthetical+=char2:operand+=char2};for(let p=0;p<length;p++)if(lastChar=char,char=expression.charAt(p),(char==="'"||char==='"')&&lastChar!=="\\"&&(depth===0&&!quote||depth&&!parenQuote)){depth?parenQuote=char:quote=char,addTo(depth,char);continue}else if(quote&&(char!==quote||lastChar==="\\")||parenQuote&&(char!==parenQuote||lastChar==="\\")){addTo(depth,char);continue}else if(quote===char){quote=!1,addTo(depth,char);continue}else if(parenQuote===char){parenQuote=!1,addTo(depth,char);continue}else{if(char===" ")continue;if(char==="(")depth===0?startP=p:parenthetical+=char,depth++;else if(char===")")if(depth--,depth===0){const fn=typeof operand=="string"&&operand.startsWith("$")?operand:void 0,hasTail=fn&&expression.charAt(p+1)===".";let tail="";hasTail&&([tail,p]=getTail(p+2,expression));const lStep=op?step:getStep(startP,expression,0),rStep=getStep(p,expression);lStep===-1&&rStep===-1?(operand=evaluate(parenthetical,-1,fn,tail),typeof operand=="string"&&(operand=parenthetical)):op&&(lStep>=rStep||rStep===-1)&&step===lStep?(left=op.bind(null,evaluate(parenthetical,-1,fn,tail)),op=null,operand=""):rStep>lStep&&step===rStep?operand=evaluate(parenthetical,-1,fn,tail):operand+=`(${parenthetical})${hasTail?`.${tail}`:""}`,parenthetical=""}else parenthetical+=char;else if(depth===0&&(operation=getOp(symbols,char,p,expression))){p===0&&console.error(103,[operation,expression]),p+=operation.length-1,p===expression.length-1&&console.error(104,[operation,expression]),op?operand&&(left=op.bind(null,evaluate(operand,step)),op=operators[operation].bind(null,left),operand=""):left?(op=operators[operation].bind(null,evaluate(left,step)),left=null):(op=operators[operation].bind(null,evaluate(operand,step)),operand="");continue}else addTo(depth,char)}return operand&&op&&(op=op.bind(null,evaluate(operand,step))),op=!op&&left?left:op,!op&&operand&&(op=(v,t)=>typeof v=="function"?v(t):v,op=op.bind(null,evaluate(operand,step))),!op&&!operand&&console.error(105,expression),op}function evaluate(operand,step,fnToken,tail){if(fnToken){const fn=evaluate(fnToken,operatorRegistry.length);let userFuncReturn,tailCall=tail?compile(`$${tail}`):!1;if(typeof fn=="function"){const args=helpers.parseArgs(String(operand)).map(arg=>evaluate(arg,-1));return tokens=>{const userFunc=fn(tokens);return typeof userFunc!="function"?(console.warn(150,fnToken),userFunc):(userFuncReturn=userFunc(...args.map(arg=>typeof arg=="function"?arg(tokens):arg)),tailCall&&(tailCall=tailCall.provide(subTokens=>{const rootTokens=provideTokens(subTokens);return subTokens.reduce((tokenSet,token)=>{if(token===tail||tail?.startsWith(`${token}(`)){const value=helpers.getAt(userFuncReturn,token);tokenSet[token]=()=>value}else tokenSet[token]=rootTokens[token];return tokenSet},{})})),tailCall?tailCall():userFuncReturn)}}}else if(typeof operand=="string"){if(operand==="true")return!0;if(operand==="false")return!1;if(operand==="undefined")return;if(helpers.isQuotedString(operand))return helpers.rmEscapes(operand.substring(1,operand.length-1));if(!Number.isNaN(+operand))return Number(operand);if(step<operatorRegistry.length-1)return compileExpr(operand,step+1);if(operand.startsWith("$")){const cleaned=operand.substring(1);return requirements.add(cleaned),function(tokens){return cleaned in tokens?tokens[cleaned]():void 0}}return operand}return operand}const compiled=compileExpr(expr),identifiers=Array.from(requirements);function provide(callback){return provideTokens=callback,Object.assign(compiled.bind(null,callback(identifiers)),{provide})}return Object.assign(compiled,{provide})}exports.compile=compile;/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */