@vef-framework/core 1.0.100 → 1.0.101

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