nv-basic-bw 1.0.15 → 1.0.16

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.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * UI/UX 测试工具库 - 下载与批量拍照模块
3
+ * ---- 给元素拍摄的照片数量巨大 需要和后端的 照片比对 服务配合工作
4
+ *
5
+ */
6
+
7
+ /** * 下载任务的结果接收器
8
+ */
9
+ export interface DownloadReceiver {
10
+ succs: string[];
11
+ /** 错误列表:[url, 错误堆栈/原因] */
12
+ fails: [string, string][];
13
+ }
14
+
15
+ /**
16
+ * 将 Blob 数据保存到指定文件目录
17
+ * @param blob 图像或文件数据
18
+ * @param name 文件名
19
+ * @param dir 目录句柄(FileSystemDirectoryHandle),若不传则触发弹窗让用户选择
20
+ * @returns [是否成功, 错误原因/堆栈]
21
+ */
22
+ export function save_blob(
23
+ blob: Blob,
24
+ name: string,
25
+ dir?: FileSystemDirectoryHandle
26
+ ): Promise<[boolean, string | null]>;
27
+
28
+ /**
29
+ * 下载指定 URL 并保存到本地目录
30
+ * @param url 下载地址,支持 string 或 [url, ext_name]
31
+ * @param dirHandle 目录句柄
32
+ * @param name 自定义文件名,若不传则自动生成前缀名
33
+ * @param recv 结果接收器
34
+ */
35
+ export function fetch_save(
36
+ url: string | [string, string],
37
+ dirHandle?: FileSystemDirectoryHandle,
38
+ name?: string,
39
+ recv?: DownloadReceiver
40
+ ): Promise<void>;
41
+
42
+ /**
43
+ * 批量下载页面中类似图片的资源(通过 CSS、IMG 标签等搜集)
44
+ * @param fltr 元素过滤器
45
+ */
46
+ export function dnld_img_like(
47
+ fltr?: (el: HTMLElement) => boolean
48
+ ): Promise<DownloadReceiver>;
49
+
50
+ /**
51
+ * 【UI/UX 测试核心】批量扫描元素并拍摄像素级照片
52
+ * 自动滚动并捕获指定范围内的元素,静默保存到指定文件夹
53
+ * * @param rt 扫描的根节点,默认为 document.body
54
+ * @param min_width 宽度阈值,小于此宽度的元素将被忽略
55
+ * @param min_height 高度阈值,小于此高度的元素将被忽略
56
+ * @param fltr 自定义过滤函数
57
+ */
58
+ export function take_photo_for_all_eles(
59
+ rt?: Node | HTMLElement,
60
+ min_width?: number,
61
+ min_height?: number,
62
+ fltr?: (el: HTMLElement) => boolean
63
+ ): Promise<void>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * ⚠️ 性能警告 (PERFORMANCE WARNING):
3
+ * 本模块使用深度遍历 (DFS) 算法,执行效率较低。
4
+ * 仅设计用于 UI/UX 自动化测试、爬虫脚本或低频交互场景。
5
+ * 严禁在高性能生产环境、高频渲染循环或大规模 DOM 树中作为常规选择器使用。
6
+ */
7
+
8
+ /** DOM 树摘要信息接口 */
9
+ export interface DOMSummary {
10
+ tags: string[];
11
+ keys: string[];
12
+ vals: string[];
13
+ txts: string[];
14
+ cmts: string[];
15
+ }
16
+
17
+ /** 筛选器函数类型,支持同步和异步 */
18
+ export type ElementFilterFn = (el: Node | HTMLElement, depth: number) => boolean | Promise<boolean>;
19
+
20
+ /**
21
+ * 路径精确匹配获取(层级子节点)
22
+ * @param root 根节点
23
+ * @param tags 标签名数组,如 ['div', 'span', 'a']
24
+ */
25
+ export function plget(root: HTMLElement, tags: string[]): HTMLElement[];
26
+
27
+ /**
28
+ * 路径模糊匹配获取(深度后代节点)
29
+ * @param root 根节点
30
+ * @param tags 标签名数组序列
31
+ */
32
+ export function plinget(root: HTMLElement | Document, tags: string[]): HTMLElement[];
33
+
34
+ /**
35
+ * 核心筛选函数:根据特殊 DSL 语法或正则表达式筛选元素
36
+ * * 语法糖说明:
37
+ * - `#id`: 匹配 ID
38
+ * - `.class`: 匹配 Class
39
+ * - `!tag`: 匹配可点击的元素(排除 meta/style 等)
40
+ * - `@match`: 匹配属性值中包含 URL 且 URL 包含 match 的元素
41
+ * - `-data`: 匹配 data- 属性名包含 data 的值集合 (返回对象)
42
+ * - `?:attr`: 匹配包含指定属性名的元素
43
+ * - `:?val`: 匹配属性值包含指定字符串的元素
44
+ * - `*`: 返回 DOM 摘要 (summary)
45
+ * - `&match`: 匹配并返回绝对路径 URL 列表
46
+ * - `//comment`: 匹配注释内容
47
+ * - `tag/tag`: 路径筛选
48
+ */
49
+ export function filter(
50
+ rt: HTMLElement | Document,
51
+ o: string | RegExp | ElementFilterFn,
52
+ is_leaf?: (el: Node) => boolean
53
+ ): Promise<HTMLElement[] | DOMSummary | Record<string, any[]> | string[]>;
54
+
55
+ /**
56
+ * 基于正则表达式匹配标签名或属性名的元素
57
+ */
58
+ export function filter_on_tag_or_attr_key_with_rgx(
59
+ rt: HTMLElement | Document,
60
+ o: RegExp,
61
+ is_leaf?: (el: Node) => boolean
62
+ ): Promise<HTMLElement[]>;
63
+
64
+ /**
65
+ * 增强型 document 代理对象 ($)
66
+ * 支持通过属性直接调用 DSL 筛选,例如:
67
+ * await $.div; // 获取所有 div
68
+ * await $['.btn-save']; // 获取所有 class 包含 btn-save 的元素
69
+ * await $['#main']; // 获取 ID 为 main 的元素
70
+ */
71
+ export const $: any;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * nvison (ison) - 极致宽松的 JSON-like 解析器
3
+ * * 🛠 核心定位:
4
+ * 1. 专门处理“非标准”、“格式错误”的类 JSON 文本。
5
+ * 2. 支持注释、引用、大数、多种进制及自定义分隔符。
6
+ * 3. 容错率极高,会自动丢弃无法解析的残缺部分,而非抛出异常。
7
+ * * ⚠️ 性能提示:
8
+ * 逐字符解析,速度慢。适合 <1M 的配置文件,不建议处理超大规模数据。
9
+ * UI 测试脚本 极其重要,因为测试脚本往往是由非开发人员维护的,手误率极高。
10
+ */
11
+
12
+ /** * 解析配置选项
13
+ */
14
+ export interface IsonOptions {
15
+ /** 启用哈希(#)定义与引用(&)功能。性能开销较大,但在处理复杂拓扑配置时非常有用。 */
16
+ enable_ref?: boolean;
17
+ /** 字符编码,默认 'utf8' */
18
+ encoding?: string;
19
+ }
20
+
21
+ /** * 后序遍历(Post-DFS)产生的项
22
+ * [键名, 对应的值] - 若为数组元素,键名通常为 Symbol(empty)
23
+ */
24
+ export type IsonEntry = [string | symbol, any];
25
+
26
+ /**
27
+ * 将 Ison 字符串直接解析为 JS 对象
28
+ * @example ison.parse_from_str("[1 2 3, abc:def]") -> [1, 2, 3, {abc: 'def'}]
29
+ */
30
+ export function parse_from_str(s: string, opt?: IsonOptions): any;
31
+
32
+ /**
33
+ * 从文件读取并解析
34
+ */
35
+ export function parse_from_file(fn: string, opt?: IsonOptions): any;
36
+
37
+ /**
38
+ * 以后序 DFS 顺序生成数据流(同步)
39
+ * 适合在内存中逐步构建或过滤大型配置项
40
+ */
41
+ export function* gen_from_str(s: string, opt?: IsonOptions): Generator<IsonEntry>;
42
+ export function* gen_from_file(fn: string, opt?: IsonOptions): Generator<IsonEntry>;
43
+
44
+ /**
45
+ * 异步生成器
46
+ * 配合 V15+ 的流式特性,支持异步处理
47
+ */
48
+ export function agen_from_file(fn: string, opt?: IsonOptions): AsyncGenerator<IsonEntry>;
49
+
50
+ /** * 全局配置对象 - 允许运行时动态扩展 DSL 语法
51
+ * @example
52
+ * ison.CFG.commas.add("。"); // 支持中文句号作为分隔符
53
+ * ison.CFG.array_blks.add("【", "】"); // 支持中文方括号
54
+ */
55
+ export const CFG: {
56
+ readonly fixed: {
57
+ hash: '#';
58
+ ref: '&';
59
+ tmpl_quote: '`';
60
+ slash: '/';
61
+ asterisk: '*';
62
+ line_comment: '//';
63
+ blk_comments: [string, string];
64
+ };
65
+ obj_blks: Map<string, string>;
66
+ array_blks: Map<string, string>;
67
+ quotes: Set<string>;
68
+ commas: Set<string>;
69
+ colons: Set<string>;
70
+ readonly reserved: string[];
71
+ };
72
+
73
+ /** 内部使用的占位符,用于标识无 key 的数组项 */
74
+ export const EMPTY: unique symbol;
75
+
76
+ /** 默认配置字典 */
77
+ export const OPT_DICT: IsonOptions;
package/README/nd.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ * 节点遍历工具库类型定义
3
+ * ---- its SLOW, just for test massive ui-elements generated by AI
4
+ * ---- for production , should use c++ version graph-tree, do NOT use DOM
5
+ *
6
+ */
7
+
8
+ /** 遍历回调函数定义:返回 true 可终止遍历 */
9
+ export type VisitorCallback = (node: Node, rel_depth: number) => void | boolean | Promise<void | boolean>;
10
+
11
+ /** 叶子节点判定函数定义 */
12
+ export type LeafPredicate = (node: Node) => boolean;
13
+
14
+ /**
15
+ * 获取节点的绝对深度
16
+ */
17
+ export function get_depth(node: Node | null): number;
18
+
19
+ /**
20
+ * 获取指定层级的祖先节点
21
+ * @param node 当前节点
22
+ * @param which 向上查找的层数 (which > 0)
23
+ */
24
+ export function get_ance(node: Node, which: number): Node | null;
25
+
26
+ /**
27
+ * 获取根节点 (最顶层的父节点)
28
+ */
29
+ export function get_rt(node: Node): Node;
30
+
31
+ /**
32
+ * 默认的叶子节点判定逻辑 (无子节点即为叶子)
33
+ */
34
+ export const is_topo_leaf: LeafPredicate;
35
+
36
+ /**
37
+ * 获取最右下方的后代节点
38
+ * @returns [最右节点, 相对深度]
39
+ */
40
+ export function get_drmost(node: Node, is_leaf?: LeafPredicate): [Node, number];
41
+
42
+ /**
43
+ * 获取最左下方的后代节点
44
+ * @returns [最左节点, 相对深度]
45
+ */
46
+ export function get_dlmost(node: Node, is_leaf?: LeafPredicate): [Node, number];
47
+
48
+ /**
49
+ * 查找第一个拥有右兄弟节点的祖先的右兄弟
50
+ */
51
+ export function find_rb_of_fst_ance_has_rb(node: Node, rel_depth: number): [Node | null, number];
52
+
53
+ /**
54
+ * 查找第一个拥有左兄弟节点的祖先的左兄弟
55
+ */
56
+ export function find_lb_of_fst_ance_has_lb(node: Node, rel_depth: number): [Node | null, number];
57
+
58
+ /**
59
+ * 深度优先遍历 (SDFS)
60
+ */
61
+ export function editonly_sdfs_for_each(rt: Node, cb?: VisitorCallback, is_leaf?: LeafPredicate): Promise<void>;
62
+
63
+ /**
64
+ * 逆序深度优先遍历 (RSDFS)
65
+ */
66
+ export function editonly_rsdfs_for_each(rt: Node, cb?: VisitorCallback, is_leaf?: LeafPredicate): Promise<void>;
67
+
68
+ /**
69
+ * 结尾深度优先遍历 (EDFS)
70
+ */
71
+ export function editonly_edfs_for_each(rt: Node, cb?: VisitorCallback, is_leaf?: LeafPredicate): Promise<void>;
72
+
73
+ /**
74
+ * 逆向结尾深度优先遍历 (REDFS)
75
+ */
76
+ export function editonly_redfs_for_each(rt: Node, cb?: VisitorCallback, is_leaf?: LeafPredicate): Promise<void>;
77
+
78
+ /**
79
+ * 标准双向访问器遍历 (进入和离开皆有回调)
80
+ * @param rt 根节点
81
+ * @param exit_cb 离开节点时的回调 (clos 状态)
82
+ * @param enter_cb 进入节点时的回调 (open 状态)
83
+ * @param is_leaf 叶子判定
84
+ */
85
+ export function visit(
86
+ rt: Node,
87
+ exit_cb?: VisitorCallback,
88
+ enter_cb?: VisitorCallback,
89
+ is_leaf?: LeafPredicate
90
+ ): Promise<void>;
91
+
92
+ /**
93
+ * 逆向双向访问器遍历
94
+ * @param rt 根节点
95
+ * @param exit_cb 离开节点时的回调 (clos 状态)
96
+ * @param enter_cb 进入节点时的回调 (open 状态)
97
+ * @param is_leaf 叶子判定
98
+ */
99
+ export function rvisit(
100
+ rt: Node,
101
+ exit_cb?: VisitorCallback,
102
+ enter_cb?: VisitorCallback,
103
+ is_leaf?: LeafPredicate
104
+ ): Promise<void>;
package/README/ui.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * UI 工具库类型定义 - 提供消息通知、对话框、图片处理及元素截图功能
3
+ * ---- UGLY simple ui tool for DEBUG and TEST
4
+ */
5
+
6
+ /** 消息通知类型 */
7
+ export type AlertType = 'success' | 'error' | 'warning' | 'loading' | 'info';
8
+
9
+ /** 画布转换目标格式 */
10
+ export type CanvasConvertFormat = 'b64' | 'url' | 'u8a' | 'ab' | 'img' | 'blob';
11
+
12
+ /**
13
+ * 消息通知管理类
14
+ */
15
+ export class SimpleAlert {
16
+ /** 存储当前活跃的任务及其定时器 */
17
+ private tasks: Record<string, {
18
+ init_timer?: number;
19
+ duration_timer?: number;
20
+ ele?: HTMLDivElement;
21
+ }>;
22
+
23
+ /** 删除指定标识的通知 */
24
+ del(src: string): void;
25
+
26
+ /** 添加或更新通知 */
27
+ add(
28
+ src: string,
29
+ message: string,
30
+ type?: AlertType,
31
+ duration?: number,
32
+ init_delay?: number
33
+ ): void;
34
+ }
35
+
36
+ /** 创建一个新的 SimpleAlert 实例 */
37
+ export function creat_simple_alert(): SimpleAlert;
38
+
39
+ /** 全局便捷调用:显示简单通知 */
40
+ export function simple_alert(
41
+ src: string,
42
+ message: string,
43
+ type?: AlertType,
44
+ duration?: number,
45
+ init_delay?: number
46
+ ): void;
47
+
48
+ /** 全局便捷调用:取消简单通知 */
49
+ export function cancel_simple_alert(src: string): void;
50
+
51
+ /**
52
+ * 弹出确认/取消对话框
53
+ * @param title 对话框标题
54
+ * @param cb 回调函数 (type 为 true 代表点击确认,false 为取消)
55
+ * @param zindex 悬浮层级
56
+ * @returns 返回对话框的 HTMLElement 引用
57
+ */
58
+ export function simple_confirm_cancel(
59
+ title: string,
60
+ cb?: (type: boolean, el: HTMLDivElement) => void | Promise<void>,
61
+ zindex?: number
62
+ ): Promise<HTMLDivElement>;
63
+
64
+ /**
65
+ * 显示图片预览遮罩弹窗
66
+ * 支持拖拽、保存截图和关闭
67
+ * @param imgData 图片数据,支持 Promise、URL 字符串或 HTMLImageElement
68
+ */
69
+ export function show_img_modal(
70
+ imgData: Promise<any> | string | HTMLImageElement
71
+ ): Promise<void>;
72
+
73
+ /**
74
+ * 将 Canvas 转换为指定格式
75
+ * @param canvas 画布元素
76
+ * @param format 目标格式类型
77
+ */
78
+ export function convert_canvas<T extends CanvasConvertFormat>(
79
+ canvas: HTMLCanvasElement,
80
+ format: T
81
+ ): Promise<T extends 'b64' | 'url' ? string : (T extends 'img' ? HTMLImageElement : (T extends 'u8a' ? Uint8Array : (T extends 'ab' ? ArrayBuffer : Blob)))>;
82
+
83
+ /**
84
+ * 【核心功能】将指定的 HTMLElement 捕获为图片
85
+ * 包含高亮反馈动画,完成后自动弹出预览(若未指定 format)或返回指定格式数据
86
+ * @param element 要截图的元素
87
+ * @param format 返回格式,若不传则直接弹出预览模态框
88
+ */
89
+ export function ele2img(
90
+ element: HTMLElement,
91
+ format?: CanvasConvertFormat
92
+ ): Promise<any | void>;
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+
2
+ nv-basic-bw
3
+ =======================
4
+ - this pkg is for ui/ux debug, NOT for production
5
+
6
+
7
+
8
+ install
9
+ =======
10
+ - npm install nv-basic-bw
11
+
12
+ splitted
13
+ --------
14
+
15
+ - [npm install xxx](https://www.npmjs.com/package/xxx)
16
+
17
+ usage
18
+ =====
19
+
20
+ const { } = require("nv-basic-bw");
21
+
22
+
23
+ example
24
+ -------
25
+
26
+ ### 0
27
+
28
+
29
+ #### 0_0
30
+
31
+ #### 0_1
32
+
33
+
34
+ ### 1
35
+
36
+ #### 1_0
37
+
38
+ #### 1_1
39
+
40
+
41
+ METHODS
42
+ ========
43
+
44
+
45
+ APIS
46
+ =======
47
+
48
+
49
+ LICENSE
50
+ =======
51
+ - ISC
52
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-basic-bw",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"