@kylexd/composable-kit 0.0.1
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/README.md +91 -0
- package/dist/composables/useApi.d.ts +78 -0
- package/dist/composables/useCache.d.ts +23 -0
- package/dist/composables/useCookies.d.ts +8 -0
- package/dist/composables/useCountdown.d.ts +31 -0
- package/dist/composables/useCreatedCancelApi.d.ts +41 -0
- package/dist/composables/useDownload.d.ts +5 -0
- package/dist/composables/useDownloadLink.d.ts +22 -0
- package/dist/composables/useForm.d.ts +13 -0
- package/dist/composables/useIsMobile.d.ts +7 -0
- package/dist/composables/useOpenLink.d.ts +8 -0
- package/dist/composables/useParseZod.d.ts +23 -0
- package/dist/composables/usePcHtmlToMobile.d.ts +40 -0
- package/dist/composables/usePopupQueue.d.ts +22 -0
- package/dist/composables/useQrCode.d.ts +6 -0
- package/dist/composables/useRsa.d.ts +6 -0
- package/dist/composables.d.ts +15 -0
- package/dist/composables.js +2 -0
- package/dist/dayjs-BXpdKo4H.js +65 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +5 -0
- package/dist/sdk/useFirebase.d.ts +12 -0
- package/dist/sdk/useIntercom.d.ts +19 -0
- package/dist/sdk/useSalesmartly.d.ts +24 -0
- package/dist/sdk/useTurbolinkSdk.d.ts +30 -0
- package/dist/sdk.d.ts +4 -0
- package/dist/sdk.js +2 -0
- package/dist/tree-Ck3oXYA2.js +332 -0
- package/dist/types/shared.d.ts +11 -0
- package/dist/useRsa-aK-vaZUD.js +739 -0
- package/dist/useTurbolinkSdk-peRMONxI.js +250 -0
- package/dist/utils/copy.d.ts +5 -0
- package/dist/utils/dayjs.d.ts +15 -0
- package/dist/utils/debounce.d.ts +5 -0
- package/dist/utils/deepClone.d.ts +1 -0
- package/dist/utils/encryption.d.ts +11 -0
- package/dist/utils/formatParams.d.ts +4 -0
- package/dist/utils/isNotEmpty.d.ts +1 -0
- package/dist/utils/patterns.d.ts +1 -0
- package/dist/utils/piniaPersistedState.d.ts +15 -0
- package/dist/utils/renderSfc.d.ts +16 -0
- package/dist/utils/singleFlight.d.ts +6 -0
- package/dist/utils/thumbnail.d.ts +13 -0
- package/dist/utils/tree.d.ts +20 -0
- package/dist/utils/typeUtils.d.ts +3 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +3 -0
- package/package.json +135 -0
package/dist/sdk.d.ts
ADDED
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { u as deepClone } from "./dayjs-BXpdKo4H.js";
|
|
2
|
+
import { createApp, h, mergeProps, ref } from "vue";
|
|
3
|
+
import copy from "copy-to-clipboard";
|
|
4
|
+
import CryptoJS from "crypto-js";
|
|
5
|
+
import { destr } from "destr";
|
|
6
|
+
import { createPersistedState } from "pinia-plugin-persistedstate";
|
|
7
|
+
//#region src/utils/copy.ts
|
|
8
|
+
function copyText(text, options) {
|
|
9
|
+
const success = copy(text);
|
|
10
|
+
if (success) options?.onSuccess?.(text);
|
|
11
|
+
else options?.onFail?.(text);
|
|
12
|
+
return success;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/utils/debounce.ts
|
|
16
|
+
function debounce(fn, wait, immediate = false) {
|
|
17
|
+
let timeout = null;
|
|
18
|
+
const debounced = function(...args) {
|
|
19
|
+
const runLater = () => {
|
|
20
|
+
timeout = null;
|
|
21
|
+
if (!immediate) fn.apply(this, args);
|
|
22
|
+
};
|
|
23
|
+
const shouldCallNow = immediate && !timeout;
|
|
24
|
+
if (timeout) clearTimeout(timeout);
|
|
25
|
+
timeout = setTimeout(runLater, wait);
|
|
26
|
+
if (shouldCallNow) fn.apply(this, args);
|
|
27
|
+
};
|
|
28
|
+
debounced.cancel = () => {
|
|
29
|
+
if (timeout) {
|
|
30
|
+
clearTimeout(timeout);
|
|
31
|
+
timeout = null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return debounced;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/utils/encryption.ts
|
|
38
|
+
var defaultKeys = [
|
|
39
|
+
{
|
|
40
|
+
id: "0",
|
|
41
|
+
iv: "x7k9m2p4",
|
|
42
|
+
key: "n5v8h3j6"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "1",
|
|
46
|
+
iv: "q4w9e2r5",
|
|
47
|
+
key: "t6y7u8i9"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "2",
|
|
51
|
+
iv: "a1s2d3f4",
|
|
52
|
+
key: "g5h6j7k8"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "3",
|
|
56
|
+
iv: "z9x8c7v6",
|
|
57
|
+
key: "b4n5m6l7"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "4",
|
|
61
|
+
iv: "p0o9i8u7",
|
|
62
|
+
key: "y6t5r4e3"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "5",
|
|
66
|
+
iv: "m1n2b3v4",
|
|
67
|
+
key: "c5x6z7l8"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "6",
|
|
71
|
+
iv: "k9j8h7g6",
|
|
72
|
+
key: "f5d4s3a2"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: "7",
|
|
76
|
+
iv: "w3e4r5t6",
|
|
77
|
+
key: "y7u8i9o0"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "8",
|
|
81
|
+
iv: "q1w2e3r4",
|
|
82
|
+
key: "t5y6u7i8"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "9",
|
|
86
|
+
iv: "a9s8d7f6",
|
|
87
|
+
key: "g4h5j6k7"
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
var defaultAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
91
|
+
function encrypt(text, keyIndex, options) {
|
|
92
|
+
const { key, letter } = getEncryptionParams(options?.keys ?? defaultKeys, options?.alphabet ?? defaultAlphabet, keyIndex);
|
|
93
|
+
const encryptedArray = encryptCore(text, key);
|
|
94
|
+
const insertPos = Number.parseInt(key.id, 10);
|
|
95
|
+
const arrayWithFlag = new Uint8Array(encryptedArray.length + 1);
|
|
96
|
+
arrayWithFlag.set(encryptedArray.slice(0, insertPos));
|
|
97
|
+
arrayWithFlag[insertPos] = 128;
|
|
98
|
+
arrayWithFlag.set(encryptedArray.slice(insertPos), insertPos + 1);
|
|
99
|
+
const base64String = btoa(String.fromCharCode.apply(null, Array.from(arrayWithFlag)));
|
|
100
|
+
return `${key.id}${letter}${encodeURIComponent(base64String)}`;
|
|
101
|
+
}
|
|
102
|
+
function decrypt(encryptedText, options) {
|
|
103
|
+
const keys = options?.keys ?? defaultKeys;
|
|
104
|
+
const id = Number.parseInt(encryptedText[0], 10);
|
|
105
|
+
const base64String = decodeURIComponent(encryptedText.slice(2));
|
|
106
|
+
const encryptedArray = new Uint8Array(Array.from(atob(base64String), (char) => char.charCodeAt(0)));
|
|
107
|
+
const arrayWithoutFlag = new Uint8Array(encryptedArray.length - 1);
|
|
108
|
+
arrayWithoutFlag.set(encryptedArray.slice(0, id));
|
|
109
|
+
arrayWithoutFlag.set(encryptedArray.slice(id + 1), id);
|
|
110
|
+
const key = keys.find((item) => item.id === id.toString());
|
|
111
|
+
if (!key) throw new Error(`Encryption key '${id}' was not found.`);
|
|
112
|
+
return decryptCore(arrayWithoutFlag, key);
|
|
113
|
+
}
|
|
114
|
+
function getEncryptionParams(keys, alphabet, keyIndex) {
|
|
115
|
+
const finalKeyIndex = keyIndex ?? Math.floor(Math.random() * keys.length);
|
|
116
|
+
if (finalKeyIndex < 0 || finalKeyIndex >= keys.length || !Number.isInteger(finalKeyIndex)) throw new Error(`keyIndex must be an integer between 0 and ${keys.length - 1}`);
|
|
117
|
+
return {
|
|
118
|
+
key: keys[finalKeyIndex],
|
|
119
|
+
letter: keyIndex !== void 0 ? alphabet[finalKeyIndex * 5 % alphabet.length] : alphabet[Math.floor(Math.random() * alphabet.length)]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function encryptCore(text, key) {
|
|
123
|
+
const encrypted = CryptoJS.DES.encrypt(text, CryptoJS.enc.Utf8.parse(key.key), {
|
|
124
|
+
iv: CryptoJS.enc.Utf8.parse(key.iv),
|
|
125
|
+
mode: CryptoJS.mode.CBC,
|
|
126
|
+
padding: CryptoJS.pad.Pkcs7
|
|
127
|
+
});
|
|
128
|
+
const wordArray = CryptoJS.enc.Base64.parse(encrypted.toString());
|
|
129
|
+
const encryptedArray = Array.from(new Uint8Array(wordArray.words.length * 4));
|
|
130
|
+
for (let index = 0; index < wordArray.words.length; index++) {
|
|
131
|
+
const word = wordArray.words[index];
|
|
132
|
+
encryptedArray[index * 4] = word >>> 24 & 255;
|
|
133
|
+
encryptedArray[index * 4 + 1] = word >>> 16 & 255;
|
|
134
|
+
encryptedArray[index * 4 + 2] = word >>> 8 & 255;
|
|
135
|
+
encryptedArray[index * 4 + 3] = word & 255;
|
|
136
|
+
}
|
|
137
|
+
return new Uint8Array(encryptedArray);
|
|
138
|
+
}
|
|
139
|
+
function decryptCore(encryptedArray, key) {
|
|
140
|
+
const base64String = btoa(String.fromCharCode.apply(null, Array.from(encryptedArray)));
|
|
141
|
+
return CryptoJS.DES.decrypt(base64String, CryptoJS.enc.Utf8.parse(key.key), {
|
|
142
|
+
iv: CryptoJS.enc.Utf8.parse(key.iv),
|
|
143
|
+
mode: CryptoJS.mode.CBC,
|
|
144
|
+
padding: CryptoJS.pad.Pkcs7
|
|
145
|
+
}).toString(CryptoJS.enc.Utf8);
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/utils/isNotEmpty.ts
|
|
149
|
+
function isNotEmpty(value) {
|
|
150
|
+
return value !== null && value !== void 0 && value !== "";
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/utils/patterns.ts
|
|
154
|
+
var urlPattern = /(https?):\/\/[^\s/$.?#].[^\s]*/gi;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/utils/piniaPersistedState.ts
|
|
157
|
+
function createVersionedPiniaPersistedState(options) {
|
|
158
|
+
const baseKeyPrefix = options.keyPrefix ?? `__persisted__${options.mode}`;
|
|
159
|
+
const baseKey = `${baseKeyPrefix}__${options.appVersion}`;
|
|
160
|
+
const serializer = options.isProd && options.encodeInProd !== false ? {
|
|
161
|
+
serialize: encodePersistedState,
|
|
162
|
+
deserialize: decodePersistedState
|
|
163
|
+
} : void 0;
|
|
164
|
+
const plugin = createPersistedState({
|
|
165
|
+
key: (id) => `${baseKey}__${id}`,
|
|
166
|
+
serializer
|
|
167
|
+
});
|
|
168
|
+
const getPersistedState = (id) => {
|
|
169
|
+
const rawValue = localStorage.getItem(`${baseKey}__${id}`);
|
|
170
|
+
if (!rawValue) return null;
|
|
171
|
+
return serializer ? serializer.deserialize(rawValue) : JSON.parse(rawValue);
|
|
172
|
+
};
|
|
173
|
+
const removeOldPersistedState = () => {
|
|
174
|
+
Object.keys(localStorage).forEach((key) => {
|
|
175
|
+
if (key.startsWith(baseKeyPrefix) && !key.includes(options.appVersion)) localStorage.removeItem(key);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
plugin,
|
|
180
|
+
getPersistedState,
|
|
181
|
+
removeOldPersistedState
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function encodePersistedState(data) {
|
|
185
|
+
try {
|
|
186
|
+
return JSON.stringify({
|
|
187
|
+
data: btoa(encodeURIComponent(JSON.stringify(data))),
|
|
188
|
+
type: 1
|
|
189
|
+
});
|
|
190
|
+
} catch {
|
|
191
|
+
return JSON.stringify({
|
|
192
|
+
data: null,
|
|
193
|
+
type: 0
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function decodePersistedState(data) {
|
|
198
|
+
const parsed = destr(data);
|
|
199
|
+
if (parsed.type === 1) return destr(decodeURIComponent(atob(parsed.data)));
|
|
200
|
+
return destr(parsed.data);
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/utils/renderSfc.ts
|
|
204
|
+
function renderSFC(sfc, options) {
|
|
205
|
+
const vnodeRef = ref();
|
|
206
|
+
const vnode = () => h(sfc, mergeProps(options?.getProps?.() ?? {}, { ref: vnodeRef }), options?.getSlot?.() ?? {});
|
|
207
|
+
const container = document.createElement("div");
|
|
208
|
+
if (options?.containerId) container.id = options.containerId;
|
|
209
|
+
const app = createApp(vnode);
|
|
210
|
+
options?.install?.(app);
|
|
211
|
+
app.mount(container);
|
|
212
|
+
((typeof options?.to === "string" ? document.querySelector(options.to) : options?.to) ?? document.body).appendChild(container);
|
|
213
|
+
const unmount = () => {
|
|
214
|
+
app.unmount();
|
|
215
|
+
container.remove();
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
vnode,
|
|
219
|
+
container,
|
|
220
|
+
vnodeRef,
|
|
221
|
+
unmount
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/utils/singleFlight.ts
|
|
226
|
+
var singleFlightCache = /* @__PURE__ */ new WeakMap();
|
|
227
|
+
function getOrCreateCache(fn) {
|
|
228
|
+
let cache = singleFlightCache.get(fn);
|
|
229
|
+
if (!cache) {
|
|
230
|
+
cache = /* @__PURE__ */ new Map();
|
|
231
|
+
singleFlightCache.set(fn, cache);
|
|
232
|
+
}
|
|
233
|
+
return cache;
|
|
234
|
+
}
|
|
235
|
+
function singleFlight(fn, options) {
|
|
236
|
+
const params = options?.params ?? [];
|
|
237
|
+
const key = options?.params ? options.keyGenerator ? options.keyGenerator(...params) : JSON.stringify(params) : "__default__";
|
|
238
|
+
const cache = getOrCreateCache(fn);
|
|
239
|
+
let promise = cache.get(key);
|
|
240
|
+
if (!promise) {
|
|
241
|
+
promise = fn(...params).finally(() => cache.delete(key));
|
|
242
|
+
cache.set(key, promise);
|
|
243
|
+
}
|
|
244
|
+
return promise;
|
|
245
|
+
}
|
|
246
|
+
function createSingleFlight(fn, options) {
|
|
247
|
+
return ((...args) => singleFlight(fn, {
|
|
248
|
+
params: args,
|
|
249
|
+
keyGenerator: options?.keyGenerator
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/utils/thumbnail.ts
|
|
254
|
+
var defaultThumbnailOptions = {
|
|
255
|
+
width: 100,
|
|
256
|
+
height: 100,
|
|
257
|
+
format: "webp"
|
|
258
|
+
};
|
|
259
|
+
function getThumbnailUrl(url, options) {
|
|
260
|
+
const finalOptions = {
|
|
261
|
+
...defaultThumbnailOptions,
|
|
262
|
+
...options
|
|
263
|
+
};
|
|
264
|
+
return (options?.isOssUrl ?? ((value) => {
|
|
265
|
+
return (options?.ossOrigins ?? []).some((origin) => value.includes(origin)) || value.includes("oss-");
|
|
266
|
+
}))(url) ? getOssThumbnailUrl(url, finalOptions) : getCdnThumbnailUrl(url, finalOptions);
|
|
267
|
+
}
|
|
268
|
+
function getOssThumbnailUrl(url, options) {
|
|
269
|
+
const params = [`resize,m_fixed,w_${options.width},h_${options.height}`];
|
|
270
|
+
if (options.quality !== void 0) params.push(`quality,Q_${options.quality}`);
|
|
271
|
+
if (options.format) params.push(`format,${options.format}`);
|
|
272
|
+
return `${url}?x-oss-process=image/${params.join("/")}`;
|
|
273
|
+
}
|
|
274
|
+
function getCdnThumbnailUrl(url, options) {
|
|
275
|
+
const params = [`resize,w_${options.width},h_${options.height}`];
|
|
276
|
+
if (options.quality !== void 0) params.push(`quality,${options.quality}`);
|
|
277
|
+
if (options.format) params.push(`format,${options.format}`);
|
|
278
|
+
return `${url}?image_process=${params.join("/")}`;
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/utils/tree.ts
|
|
282
|
+
function listToTreeOptimized(sourceList, options) {
|
|
283
|
+
const list = deepClone(sourceList);
|
|
284
|
+
const { idField, parentIdField, childrenField = "children", rootParentId = null } = options;
|
|
285
|
+
const map = /* @__PURE__ */ new Map();
|
|
286
|
+
const tree = [];
|
|
287
|
+
list.forEach((node) => {
|
|
288
|
+
const nodeId = node[idField];
|
|
289
|
+
if (nodeId === void 0 || nodeId === null) throw new Error(`Node is missing id field '${String(idField)}'.`);
|
|
290
|
+
map.set(nodeId, { ...node });
|
|
291
|
+
});
|
|
292
|
+
list.forEach((node) => {
|
|
293
|
+
const parentId = node[parentIdField];
|
|
294
|
+
const currentNode = map.get(node[idField]);
|
|
295
|
+
if (!currentNode) return;
|
|
296
|
+
if (parentId === rootParentId) {
|
|
297
|
+
tree.push(currentNode);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const parentNode = map.get(parentId);
|
|
301
|
+
if (!parentNode) return;
|
|
302
|
+
if (!parentNode[childrenField]) parentNode[childrenField] = [];
|
|
303
|
+
parentNode[childrenField]?.push(currentNode);
|
|
304
|
+
});
|
|
305
|
+
return tree;
|
|
306
|
+
}
|
|
307
|
+
function treeOptimizedToList(sourceTree, options) {
|
|
308
|
+
const { pidKey, childrenKey = "children", idKey = "id" } = options || {};
|
|
309
|
+
const queue = deepClone(sourceTree).map((node) => ({
|
|
310
|
+
node,
|
|
311
|
+
parentId: void 0
|
|
312
|
+
}));
|
|
313
|
+
const result = [];
|
|
314
|
+
while (queue.length > 0) {
|
|
315
|
+
const { node, parentId } = queue.shift();
|
|
316
|
+
const { [childrenKey]: children, ...rest } = node;
|
|
317
|
+
if (pidKey && parentId !== void 0) rest[pidKey] = parentId;
|
|
318
|
+
result.push(rest);
|
|
319
|
+
if (Array.isArray(children)) {
|
|
320
|
+
const currentId = node[idKey];
|
|
321
|
+
children.forEach((child) => {
|
|
322
|
+
queue.push({
|
|
323
|
+
node: child,
|
|
324
|
+
parentId: currentId
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
export { copyText as _, getThumbnailUrl as a, renderSFC as c, encodePersistedState as d, urlPattern as f, debounce as g, encrypt as h, getOssThumbnailUrl as i, createVersionedPiniaPersistedState as l, decrypt as m, treeOptimizedToList as n, createSingleFlight as o, isNotEmpty as p, getCdnThumbnailUrl as r, singleFlight as s, listToTreeOptimized as t, decodePersistedState as u };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
export type MaybeRef<T> = T | Ref<T>;
|
|
3
|
+
export declare function resolveMaybeRef<T>(value: MaybeRef<T>): T;
|
|
4
|
+
export interface UseSdkUser {
|
|
5
|
+
userId?: string | number;
|
|
6
|
+
userName?: string;
|
|
7
|
+
language?: string;
|
|
8
|
+
level?: string | number;
|
|
9
|
+
email?: string;
|
|
10
|
+
}
|
|
11
|
+
export type UseSdkUserRef<T extends UseSdkUser = UseSdkUser> = MaybeRef<T | null | undefined>;
|