dlsjs 0.1.25 → 1.0.3

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/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -1,33 +0,0 @@
1
- /**
2
- * 是否在移动端
3
- */
4
- export function isMobileDevice() {
5
- // 常见的移动端User-Agent正则表达式
6
- const mobileUserAgent = /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
7
-
8
- return mobileUserAgent.test(navigator.userAgent);
9
- }
10
-
11
- /**
12
- * 复制文本到剪贴板
13
- * 当处于安全模式下(localhost或https下)使用navigator.clipboard.writeText()添加
14
- * 否则使用更高兼容模式document.execCommand('Copy'),模拟选中复制,但有几率受到dom聚焦情况影响
15
- * @param value
16
- * @param text
17
- * @return Promise<>
18
- */
19
- export function copyText(value) {
20
- if(navigator.clipboard) {
21
- return navigator.clipboard.writeText(value)
22
- }else {
23
- const tempInput = document.createElement('input')
24
- document.body.appendChild(tempInput)
25
- tempInput.value = value
26
- tempInput.select()
27
- document.execCommand('Copy')
28
- document.body.removeChild(tempInput)
29
- return Promise.resolve()
30
- }
31
- }
32
-
33
- export default {isMobileDevice, copyText}
@@ -1,29 +0,0 @@
1
- // 此处代码来自文心一言的回答
2
- export function toggleFullscreen() {
3
- const elem = document.documentElement; // 你可以选择任何HTML元素使其全屏
4
- if (isFullscreenActive()) {
5
- exitFullscreen();
6
- } else {
7
- requestFullscreen(elem);
8
- }
9
- }
10
-
11
- export function requestFullscreen(element) {
12
- if (element.requestFullscreen) {
13
- element.requestFullscreen();
14
- }
15
- }
16
-
17
- export function exitFullscreen() {
18
- if (document.exitFullscreen) {
19
- document.exitFullscreen();
20
- }
21
- }
22
-
23
- export function isFullscreenActive() {
24
- return !!document.fullscreenElement
25
- }
26
-
27
- export default {
28
- toggleFullscreen, requestFullscreen, exitFullscreen, isFullscreenActive
29
- }
@@ -1,339 +0,0 @@
1
- /**
2
- * 平铺结构转树形结构
3
- * @param list
4
- * @param extendProps
5
- */
6
- import {isType} from "./Judgment";
7
- import {clone, uniqBy} from "ramda";
8
-
9
- /**
10
- * 列表转树(高性能版,适配100W+数据)
11
- * @param {Array} list - 原始列表数据
12
- * @param {Object} extendProps - 自定义属性映射 {id: 'id', children: 'children', parentId: 'parentId'}
13
- * @returns {Array} 树形结构数据
14
- */
15
- export function list2Tree (list, extendProps = {}) {
16
- // 1. 配置默认属性映射,兼容自定义字段
17
- const props = {
18
- id: 'id',
19
- children: 'children',
20
- parentId: 'parentId',
21
- useConcat: false, // 保留原有配置,实际优化后无需concat
22
- ...extendProps
23
- };
24
-
25
- // 校验数据结构
26
- if(list[0] && !list[0].hasOwnProperty('id')) {
27
- console.warn('数据非标准,未找到唯一标识字段,直接返回')
28
- return list
29
- }
30
-
31
- const { id: idKey, children: childrenKey, parentId: parentIdKey, useConcat } = props;
32
-
33
- // 2. 构建ID到节点的哈希映射(O(n)),同时初始化children数组
34
- const nodeMap = new Map();
35
- const rootNodes = []; // 存储根节点(parentId为空/0/不存在的节点)
36
-
37
- // 第一次遍历:初始化映射和children,O(n)
38
- for (const node of list) {
39
- const nodeId = node[idKey];
40
- // 初始化children数组(避免后续判断undefined)
41
- if (!node[childrenKey]) {
42
- node[childrenKey] = [];
43
- }
44
- // 将节点存入Map,方便后续快速查找父节点
45
- nodeMap.set(nodeId, node);
46
- }
47
-
48
- // 第二次遍历:关联父子节点,O(n)
49
- for (const node of list) {
50
- const parentId = node[parentIdKey];
51
- const parentNode = nodeMap.get(parentId);
52
-
53
- if (parentNode) {
54
- // 有父节点:添加到父节点的children中
55
- if (useConcat && Array.isArray(parentNode[childrenKey])) {
56
- parentNode[childrenKey] = parentNode[childrenKey].concat(node);
57
- } else {
58
- parentNode[childrenKey].push(node);
59
- }
60
- } else {
61
- // 无父节点:归为根节点(parentId为空/0/不存在)
62
- rootNodes.push(node);
63
- }
64
- }
65
-
66
- // 3. 清理空children(可选,保持和原逻辑一致)
67
- for (const node of list) {
68
- if (Array.isArray(node[childrenKey]) && node[childrenKey].length === 0) {
69
- delete node[childrenKey];
70
- }
71
- }
72
-
73
- return rootNodes;
74
- }
75
-
76
- /**
77
- * 为list添加_parentIds属性,属性为不含自身的数组,顺序从最外层开始
78
- * @param list
79
- */
80
- export function setParentIds4List(list) {
81
- list.forEach(data => {
82
- let parentIds = []
83
- let nextParentId = data.parentId
84
- while (nextParentId) {
85
- parentIds.push(nextParentId)
86
- let parentNode = list.find(item => item.id === nextParentId)
87
- if(parentNode) nextParentId = parentNode.parentId
88
- else nextParentId = null
89
- }
90
- data._parentIds = parentIds.reverse()
91
- })
92
- }
93
-
94
- /**
95
- * 查找树上的点
96
- */
97
- export function treeFind(treeLike, func) {
98
- let tree = []
99
- if(isType('Array', treeLike)) {
100
- tree = treeLike
101
- }else if(isType('Object', treeLike)) {
102
- tree = [treeLike]
103
- }
104
- for(let item of tree) {
105
- if(func(item)) {
106
- return item
107
- }
108
- }
109
- for(let item of tree) {
110
- if(item?.children) {
111
- const nextMatch = treeFind(item.children, func)
112
- if(nextMatch) return nextMatch
113
- }
114
- }
115
- return null
116
- }
117
-
118
- /**
119
- * 查找节点的父级
120
- * @param tree
121
- * @param func
122
- * @param parent
123
- */
124
- export function treeFindParent(tree, func, parent) {
125
- for(let item of tree) {
126
- if(func(item)) {
127
- return parent
128
- }
129
- }
130
- for(let item of tree) {
131
- if(item.children) {
132
- const res = treeFindParent(item.children, func, item)
133
- if(res) return res
134
- }
135
- }
136
- return null
137
- }
138
-
139
- /**
140
- * 修改树上的点
141
- */
142
- export function treeMap(treeLike, func) {
143
- let tree = []
144
- if(isType('Array', treeLike)) {
145
- tree = treeLike
146
- }else if(isType('Object', treeLike)) {
147
- tree = [treeLike]
148
- }
149
- const newTree = []
150
- for(let index in tree) {
151
- let item = tree[index]
152
- newTree[index] = func(item)
153
- if(item.children?.length) {
154
- newTree[index].children = treeMap(item.children, func)
155
- }
156
- }
157
- return newTree
158
- }
159
-
160
- /**
161
- * 遍历树上的点
162
- */
163
- export function treeForEach(treeLike, func) {
164
- let tree = []
165
- if(isType('Array', treeLike)) {
166
- tree = treeLike
167
- }else if(isType('Object', treeLike)) {
168
- tree = [treeLike]
169
- }
170
- for(let index in tree) {
171
- let item = tree[index]
172
- func(item)
173
- if(item.children?.length) {
174
- treeForEach(item.children, func)
175
- }
176
- }
177
- }
178
-
179
- /**
180
- * 删除树上的点,首个匹配
181
- */
182
- export function treeDel(tree, func) {
183
- let parent = treeFindParent(tree, func, {children: tree})
184
- let index = parent.children.findIndex(func)
185
- return parent.children.splice(Number(index), 1)
186
- }
187
-
188
- /**
189
- * 寻找叶子对象
190
- * @param obj
191
- * @param leafKey
192
- */
193
- export function findLeaf(obj, leafKey) {
194
- if(obj?.hasOwnProperty && obj.hasOwnProperty(leafKey) || obj[leafKey]) {
195
- return findLeaf(obj[leafKey], leafKey)
196
- }else {
197
- return obj
198
- }
199
- }
200
-
201
- export function forkProp(obj, leafKey, propName) {
202
- if(obj?.hasOwnProperty && obj.hasOwnProperty(propName)) {
203
- return obj[propName]
204
- }else if(obj?.hasOwnProperty && obj.hasOwnProperty(leafKey) || obj[leafKey]) {
205
- return forkProp(obj[leafKey], leafKey, propName)
206
- }else {
207
- return null
208
- }
209
- }
210
-
211
- /**
212
- * 维表转树
213
- * @param dimList 平铺维表
214
- * @param dimLink 维表关联关系 e.g.['市','区县','乡镇']
215
- * @param dimMap 维表关联映射字段 e.g.{'市': {propFieldName: 'code1', textFieldName: 'name1'}, '区': {propFieldName: 'code2', textFieldName: 'name2'}, '乡镇': {propFieldName: 'code3', textFieldName: 'name3'}}
216
- */
217
- export function dim2Tree(dimList, dimLink, dimMap) {
218
- let list = dim2List(dimList, dimLink, dimMap)
219
- return list2Tree(list);
220
- }
221
-
222
- export function dim2List(dimList, dimLink, dimMap) {
223
- let filedSort = [];
224
- if (dimLink.length) {
225
- for (let propName of dimLink) {
226
- if (!propName) continue;
227
- let match = dimMap[propName]
228
- filedSort.push(match);
229
- }
230
- }
231
- let dataTreeOrg = [];
232
- for (let r of dimList) {
233
- for (let linkIndexStr in filedSort) {
234
- let linkIndex = Number(linkIndexStr)
235
- let node = { id: '', parentId: '', label: '' };
236
- for (let i = 0; i <= linkIndex; i++) {
237
- node.id += r[filedSort[i].propFieldName];
238
- if (linkIndex > 0 && i > 0) node.parentId += r[filedSort[i - 1].propFieldName];
239
- }
240
- if (linkIndex == 0) node.parentId = '-1';
241
- node.label = r[filedSort[linkIndex].textFieldName];
242
- node.value = r[filedSort[linkIndex].propFieldName];
243
- dataTreeOrg.push(node);
244
- }
245
- }
246
- return uniqBy(item => item.id, dataTreeOrg);
247
- }
248
-
249
- /**
250
- * 树筛选(包含父节点)
251
- * @param treeLike
252
- * @param func
253
- */
254
- export function treeFilter(treeLike, func) {
255
- const list = tree2List(treeLike)
256
- setParentIds4List(list)
257
- const res = list.filter(func)
258
- const resParentIds = res.map(item => item._parentIds).flat()
259
- const resIds = res.map(item => item.id)
260
- const res2 = list.filter(item => resParentIds.includes(item.id) || resIds.includes(item.id))
261
- return list2Tree(res2)
262
- }
263
-
264
- /**
265
- * 树转平铺
266
- * @param treeLike
267
- * @param list
268
- */
269
- export function tree2List(treeLike, list = []) {
270
- let tree = []
271
- if(isType('Array', treeLike)) {
272
- tree = treeLike
273
- }else if(isType('Object', treeLike)) {
274
- tree = [treeLike]
275
- }
276
- for(let item of tree) {
277
- list.push(item)
278
- if(item.children?.length) {
279
- tree2List(item.children, list)
280
- }
281
- }
282
- return list
283
- }
284
-
285
- /**
286
- * 裁剪树形结构到指定层级(高性能版,不裁剪原始树,返回一颗新树)
287
- * @param {Array} treeLike - 原始树形结构数据
288
- * @param {number} level - 要保留的层级(从1开始,level=1保留根节点,level=2保留根+一级子节点,以此类推)
289
- * @returns {Array} 裁剪后的指定层级节点列表
290
- */
291
- export function treeCutLevel(treeLike, level) {
292
- // 边界值处理:层级≤0 返回空,层级=1 直接返回根节点(浅拷贝避免修改原数据)
293
- if (level <= 0) return [];
294
- if (level === 1) {
295
- // 只保留根节点,浅拷贝根节点(删除children),不影响原数据
296
- return treeLike.map(node => {
297
- const newNode = { ...node }; // 浅拷贝当前节点
298
- delete newNode.children; // 移除子节点,只保留当前层级
299
- return newNode;
300
- });
301
- }
302
-
303
- // 初始化:当前处理的层级节点列表(初始为根节点)
304
- let currentLevelNodes = [...treeLike]; // 浅拷贝当前层级节点,不修改原数组
305
- // 存储最终要返回的目标层级节点
306
- let targetNodes = [];
307
-
308
- // 遍历到指定层级(从第2层开始,到level层结束)
309
- for (let currentLevel = 2; currentLevel <= level; currentLevel++) {
310
- // 收集下一层的所有节点
311
- const nextLevelNodes = [];
312
-
313
- for (const node of currentLevelNodes) {
314
- // 只处理有children的节点
315
- if (node.children && node.children.length > 0) {
316
- if (currentLevel === level) {
317
- // 到达目标层级:浅拷贝当前子节点,删除其children后加入结果
318
- const cutNodes = node.children.map(child => {
319
- const newChild = { ...child };
320
- delete newChild.children;
321
- return newChild;
322
- });
323
- targetNodes.push(...cutNodes);
324
- } else {
325
- // 未到目标层级:收集子节点,继续遍历下一层
326
- nextLevelNodes.push(...node.children);
327
- }
328
- }
329
- }
330
-
331
- // 更新当前层级节点为下一层
332
- currentLevelNodes = nextLevelNodes;
333
-
334
- // 提前终止:如果下一层没有节点,无需继续循环
335
- if (currentLevelNodes.length === 0) break;
336
- }
337
-
338
- return targetNodes;
339
- }
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>
package/vite.config.js DELETED
@@ -1,106 +0,0 @@
1
- // vite.config.js
2
- import { defineConfig } from 'vite';
3
- import { resolve } from 'path';
4
- import { readdirSync, statSync } from 'fs';
5
-
6
- // 自动获取所有源文件,用于生成对应的类型声明映射
7
- function getSourceFiles(dir, base = '') {
8
- const results = [];
9
- const items = readdirSync(dir);
10
-
11
- for (const item of items) {
12
- const fullPath = resolve(dir, item);
13
- const relativePath = base ? `${base}/${item}` : item;
14
-
15
- if (statSync(fullPath).isDirectory()) {
16
- results.push(...getSourceFiles(fullPath, relativePath));
17
- } else if (item.endsWith('.js')) {
18
- results.push(relativePath.replace(/\\/g, '/'));
19
- }
20
- }
21
-
22
- return results;
23
- }
24
-
25
- export default defineConfig({
26
- build: {
27
- lib: {
28
- // 入口文件
29
- entry: resolve(__dirname, 'src/core/index.js'),
30
- // UMD格式的全局变量名
31
- name: 'dlsjs',
32
- // 输出文件名格式
33
- fileName: (format) => {
34
- if (format === 'es') return 'dlsjs.esm.js';
35
- if (format === 'umd') return 'dlsjs.umd.js';
36
- if (format === 'iife') return 'dlsjs.iife.js';
37
- return `dlsjs.${format}.js`;
38
- },
39
- // 输出格式
40
- formats: ['es', 'umd', 'cjs']
41
- },
42
- // 核心配置:将目标设置为 ES5
43
- target: 'es2015', // 或更保守的 'es5'、'es2020'
44
- // 生成sourcemap便于调试
45
- sourcemap: true,
46
- // 清空输出目录
47
- emptyOutDir: true,
48
- rollupOptions: {
49
- // 外部化依赖,不打包进库
50
- external: [],
51
- output: {
52
- // 为UMD格式提供全局变量名
53
- globals: {},
54
- // 保留导出结构
55
- preserveModules: false,
56
- // 生成导出的ES模块
57
- exports: 'named'
58
- }
59
- }
60
- },
61
- // 开发服务器配置
62
- server: {
63
- port: 3000,
64
- open: true
65
- },
66
- // 插件配置
67
- plugins: [
68
- // 自定义插件:构建完成后处理类型声明文件
69
- {
70
- name: 'copy-types',
71
- closeBundle() {
72
- const fs = require('fs');
73
- const path = require('path');
74
-
75
- // 复制types目录到dist目录
76
- const typesDir = path.resolve(__dirname, 'types');
77
- const distTypesDir = path.resolve(__dirname, 'dist/types');
78
-
79
- function copyDir(src, dest) {
80
- if (!fs.existsSync(dest)) {
81
- fs.mkdirSync(dest, { recursive: true });
82
- }
83
-
84
- const items = fs.readdirSync(src);
85
-
86
- for (const item of items) {
87
- const srcPath = path.join(src, item);
88
- const destPath = path.join(dest, item);
89
- const stat = fs.statSync(srcPath);
90
-
91
- if (stat.isDirectory()) {
92
- copyDir(srcPath, destPath);
93
- } else if (item.endsWith('.d.ts')) {
94
- fs.copyFileSync(srcPath, destPath);
95
- }
96
- }
97
- }
98
-
99
- if (fs.existsSync(typesDir)) {
100
- copyDir(typesDir, distTypesDir);
101
- console.log('✓ Type declaration files copied to dist/types/');
102
- }
103
- }
104
- }
105
- ]
106
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes