xl-public-utils 1.0.4 → 1.0.5

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/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "outDir": "./types" // 可选,定义.d.ts文件输出目录
7
+ },
8
+ "include": ["src/*.mjs"] // 指定包含的 JavaScript 文件路径
9
+ }
@@ -0,0 +1,106 @@
1
+ export function datamatrix(opts: any, dwg: any): any;
2
+ export function qrcode(opts: any, dwg: any): any;
3
+ export function raw(bcid: any, text: any, options: any): true | any[];
4
+ declare namespace _default {
5
+ export { ToCanvas as toCanvas };
6
+ export { ToSVG as toSVG };
7
+ export { Render as render };
8
+ export { ToRaw as raw };
9
+ export { DrawingCanvas as drawingCanvas };
10
+ export { DrawingSVG as drawingSVG };
11
+ export { FixupOptions as fixupOptions };
12
+ export { LoadFont as loadFont };
13
+ export { FontLib };
14
+ export { BWIPJS_VERSION };
15
+ export { BWIPP_VERSION };
16
+ }
17
+ export default _default;
18
+ declare function ToCanvas(cvs: any, opts: any): any;
19
+ declare function ToSVG(opts: any): any;
20
+ declare function Render(options: any, drawing: any): any;
21
+ declare function LoadFont(...args: any[]): any;
22
+ declare function DrawingCanvas(canvas: any, maybe: any): {
23
+ setopts(options: any): void;
24
+ scale: (sx: any, sy: any) => any[];
25
+ measure: (str: any, font: any, fwidth: any, fheight: any) => {
26
+ width: number;
27
+ ascent: number;
28
+ descent: number;
29
+ };
30
+ init: (width: any, height: any) => void;
31
+ line: (x0: any, y0: any, x1: any, y1: any, lw: any, rgb: any) => void;
32
+ polygon: (pts: any) => void;
33
+ hexagon: (pts: any, rgb: any) => void;
34
+ ellipse: (x: any, y: any, rx: any, ry: any, ccw: any) => void;
35
+ fill: (rgb: any) => void;
36
+ clip: (polys: any) => void;
37
+ unclip: () => void;
38
+ text: (x: any, y: any, str: any, rgb: any, font: any) => void;
39
+ end: () => void;
40
+ };
41
+ declare function DrawingSVG(): {
42
+ setopts(options: any): void;
43
+ scale(sx: any, sy: any): void;
44
+ measure(str: any, font: any, fwidth: any, fheight: any): {
45
+ width: number;
46
+ ascent: number;
47
+ descent: number;
48
+ };
49
+ init(width: any, height: any): void;
50
+ line(x0: any, y0: any, x1: any, y1: any, lw: any, rgb: any): void;
51
+ polygon(pts: any): void;
52
+ hexagon(pts: any, rgb: any): void;
53
+ ellipse(x: any, y: any, rx: any, ry: any, ccw: any): void;
54
+ fill(rgb: any): void;
55
+ clip: (polys: any) => void;
56
+ unclip: () => void;
57
+ text(x: any, y: any, str: any, rgb: any, font: any): void;
58
+ end(): string;
59
+ };
60
+ export const BWIPJS_VERSION: "4.5.1 (2024-08-12)";
61
+ import { BWIPP_VERSION } from './bwipp.mjs';
62
+ declare function ToRaw(bcid: any, text: any, options: any, ...args: any[]): true | any[];
63
+ declare function FixupOptions(opts: any): any;
64
+ declare namespace FontLib {
65
+ export { lookup };
66
+ export { monochrome };
67
+ export { getglyph };
68
+ export { getpaths };
69
+ export { loadFont };
70
+ }
71
+ declare function lookup(name: any): any;
72
+ declare function monochrome(mono: any): void;
73
+ declare function getglyph(fontid: any, charcode: any, width: any, height: any): any;
74
+ declare function getpaths(fontid: any, charcode: any, width: any, height: any): ({
75
+ type: string;
76
+ x: number;
77
+ y: number;
78
+ cx?: undefined;
79
+ cy?: undefined;
80
+ cx1?: undefined;
81
+ cy1?: undefined;
82
+ cx2?: undefined;
83
+ cy2?: undefined;
84
+ } | {
85
+ type: string;
86
+ x: number;
87
+ y: number;
88
+ cx: number;
89
+ cy: number;
90
+ cx1?: undefined;
91
+ cy1?: undefined;
92
+ cx2?: undefined;
93
+ cy2?: undefined;
94
+ } | {
95
+ type: string;
96
+ x: number;
97
+ y: number;
98
+ cx1: number;
99
+ cy1: number;
100
+ cx2: number;
101
+ cy2: number;
102
+ cx?: undefined;
103
+ cy?: undefined;
104
+ })[];
105
+ declare function loadFont(name: any, ...args: any[]): number;
106
+ export { ToCanvas as toCanvas, ToSVG as toSVG, Render as render, LoadFont as loadFont, DrawingCanvas as drawingCanvas, DrawingSVG as drawingSVG, BWIPP_VERSION };
@@ -0,0 +1,5 @@
1
+ export function bwipp_datamatrix(): void;
2
+ export function bwipp_qrcode(): void;
3
+ export function bwipp_lookup(symbol: any): typeof bwipp_qrcode;
4
+ export function bwipp_encode(bwipjs: any, encoder: any, text: any, opts: any, dontdraw: any): true | any[];
5
+ export var BWIPP_VERSION: string;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @typedef {Object} AttrOption
3
+ * @property {number[]} [colors] 颜色数组
4
+ * @property {number[]} [generics] 属性数组
5
+ * @property {number[]} [normals] 法向量数组
6
+ */
7
+ /**
8
+ * 将数据进行压缩
9
+ * @param {number[]} vertices 网格点
10
+ * @param {number[]} faces 网格面,必须是三角化之后的面,每连续的三个点索引标识一个面
11
+ * @param {number} byteLength=14 byteLength 压缩率
12
+ * @param {AttrOption} [attr] 其他需要压缩的属性
13
+ * @returns {Int8Array} 压缩之后的DRC数据
14
+ */
15
+ export function enCodeMeshByVF(vertices: number[], faces: number[], byteLength?: number, attr?: AttrOption): Int8Array;
16
+ /**
17
+ * 使用drc压缩点
18
+ * @param {vec3[] | number[]} points 点数组
19
+ * @returns {Int8Array} 压缩之后的drc data
20
+ */
21
+ export function enCodePointCloud(points: vec3[] | number[]): Int8Array;
22
+ /**
23
+ * 解压drc格式的点云数据
24
+ * @param {ArrayBuffer} byteArray drc点数据
25
+ * @returns {Float32Array} 点数组
26
+ */
27
+ export function decodePointCloud(byteArray: ArrayBuffer): Float32Array;
28
+ /**
29
+ * @typedef {Object} DrcMeshData
30
+ * @property {Uint32Array} faces 网格面数组
31
+ * @property {Float32Array} vertices 网格点数组
32
+ * @property {Float32Array} [colors] 颜色数组
33
+ * @property {Float32Array} [generics] 属性数组
34
+ * @property {Float32Array} [normals] 法向量数组
35
+ */
36
+ /**
37
+ * 解压drc格式的网格数据
38
+ * @param {ArrayBuffer} byteArray drc网格数据
39
+ * @returns {DrcMeshData} 网格数据
40
+ */
41
+ export function decodeDrcBufferArray(byteArray: ArrayBuffer): DrcMeshData;
42
+ /**
43
+ * @typedef {Object} Decoder
44
+ */
45
+ /**
46
+ * 输入一个Drc数据,反会对应的解压器
47
+ * @param {ArrayBuffer} arrayBuffer 输入的数据
48
+ * @returns {Decoder} drc解压类
49
+ */
50
+ export function decodeBuffer(arrayBuffer: ArrayBuffer): Decoder;
51
+ /**
52
+ * 获取decoder中的属性
53
+ * @param {Decoder} dracoGeometry DRC Decoder
54
+ * @param {number} attributeId 需要获取的属性id
55
+ * @returns {Float32Array} 对应decoder中的属性
56
+ */
57
+ export function getDracoAttributeAsFloat32Array(dracoGeometry: Decoder, attributeId: number): Float32Array;
58
+ /**
59
+ * 将点数据使用drc压缩处理为 base64 string
60
+ * @param {vec3[] | number[]} points 点数据
61
+ * @returns {string} drc压缩之后的base64数据
62
+ */
63
+ export function enCloudPointTobase64(points: vec3[] | number[]): string;
64
+ /**
65
+ * @typedef {Object} Mesh
66
+ * @property {number[][]} vertices 点信息
67
+ * @property {number[][]} faces 面信息
68
+ */
69
+ /**
70
+ * 使用drc压缩网格信息
71
+ * @param {Mesh | vtkPolyData} mesh
72
+ * @param {number} byteLength=14 压缩率
73
+ * @param {AttrOption} [attr] 其他需要压缩的属性
74
+ * @returns {Int8Array} 压缩之后的DRC数据
75
+ */
76
+ export function enCodeMesh(mesh: Mesh | vtkPolyData, byteLength?: number, attr?: AttrOption): Int8Array;
77
+ /**
78
+ * 初始化Draco文件
79
+ */
80
+ export function initDrcCoder(): void;
81
+ export type AttrOption = {
82
+ /**
83
+ * 颜色数组
84
+ */
85
+ colors?: number[];
86
+ /**
87
+ * 属性数组
88
+ */
89
+ generics?: number[];
90
+ /**
91
+ * 法向量数组
92
+ */
93
+ normals?: number[];
94
+ };
95
+ export type DrcMeshData = {
96
+ /**
97
+ * 网格面数组
98
+ */
99
+ faces: Uint32Array;
100
+ /**
101
+ * 网格点数组
102
+ */
103
+ vertices: Float32Array;
104
+ /**
105
+ * 颜色数组
106
+ */
107
+ colors?: Float32Array;
108
+ /**
109
+ * 属性数组
110
+ */
111
+ generics?: Float32Array;
112
+ /**
113
+ * 法向量数组
114
+ */
115
+ normals?: Float32Array;
116
+ };
117
+ export type Decoder = any;
118
+ export type Mesh = {
119
+ /**
120
+ * 点信息
121
+ */
122
+ vertices: number[][];
123
+ /**
124
+ * 面信息
125
+ */
126
+ faces: number[][];
127
+ };
128
+ import { vec3 } from "gl-matrix";
129
+ import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
@@ -0,0 +1,16 @@
1
+ import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
2
+ /**
3
+ * 将polyData转换为ply文件
4
+ * @param {vtkPolyData} polyData 需要导出的polydata
5
+ * @param {'ascii' | 'binary'} format 导出文件格式
6
+ * @param {0 | 1} dataByteOrder=0 字节序,默认为0, 0为大端模式, 1小端模式
7
+ * @param {string[]} headerComments=[] 文件头描述
8
+ * @param {string} textureFileName='' header描述文件名
9
+ * @param {['u', 'v']} textureCoordinatesName=['u', 'v'] header添加u和v
10
+ * @param {boolean} withNormals=false 是否需要法向量
11
+ * @param {boolean} withUVs=false 是否需要UV
12
+ * @param {boolean} withColors=false 是否需要Colors
13
+ * @param {boolean} withColors=true 面使用点索引
14
+ * @returns {string | DataView} 返回文件内容
15
+ */
16
+ export function writePLY(polyData: vtkPolyData, format: "ascii" | "binary", dataByteOrder?: 0 | 1, headerComments?: string[], textureFileName?: string, textureCoordinatesName?: ["u", "v"], withNormals?: boolean, withUVs?: boolean, withColors?: boolean, withIndices?: boolean): string | DataView;
@@ -0,0 +1,20 @@
1
+ import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
2
+
3
+ /**
4
+ * 导出stl模型的时候 需要离散点 防止被认为是同一个点 精度到e-7就够了
5
+ * @param {number[]} points 网格点
6
+ */
7
+ export function dispersedPoints2Stl(points: number[]): void;
8
+ /**
9
+ * 获取网格的BinarySTL文件类容
10
+ * @param {vtkPolyData} polydata 网格
11
+ * @param {boolean} colorMagic=false 颜色
12
+ * @returns {Blob} 网格的BinarySTL文件内容
13
+ */
14
+ export function exportBinarySTL(polydata: vtkPolyData, colorMagic?: boolean): Blob;
15
+ /**
16
+ * 获取网格的AsciiSTL文件类容
17
+ * @param {vtkPolyData} polydata 网格
18
+ * @returns {string} 网格的asciiSTL文件内容
19
+ */
20
+ export function exportAsciiSTL(polydata: vtkPolyData): string;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @typedef {Object} QrCodeOptions
3
+ * @property {'qrcode' | 'dataMatrix'} bcid='qrcode' - 二维码类型,具体支持请查看文档
4
+ * @property {number} width=1056 - 最终图片宽度
5
+ * @property {number} height=342 - 最终图片高度
6
+ * @property {number} qrcodeW=300 - 二维码宽度
7
+ * @property {number} qrcodeH=300 - 二维码高度
8
+ * @property {boolean} addText=true - 是否在右侧添加文字
9
+ * @property {number} top=10 - 顶部距离
10
+ * @property {number} left=10 - 左侧距离
11
+ * @property {number} lineHeight=1 - 文字行高,换行后下一行文字的y位置计算为fontSize * lineHeight
12
+ * @property {number} fontSize=60 - 文字大小
13
+ * @property {string} fontFamily='黑体' - 字体类型
14
+ * @property {string} bgColor='#fff' - 背景颜色
15
+ * @property {number} textLeftMargin=20 - 文字距离二维码间隔
16
+ * @property {boolean} fontWeight=700 - 字体加粗
17
+ * @property {string} textColor='#000' - 字体颜色
18
+ * @property {string} textContent - 右侧文字内容
19
+ */
20
+ /**
21
+ * 生成一个二维码图片,可以在二维码右侧添加二维码文字内容信息
22
+ * @param {string} content 二维码内容
23
+ * @param {QrCodeOptions} options 图片参数
24
+ * @returns {string | false} 返回图片的base64
25
+ */
26
+ export function generateQRCodeWithText(content: string, options?: QrCodeOptions): string | false;
27
+ export type QrCodeOptions = {
28
+ /**
29
+ * ='qrcode' - 二维码类型,具体支持请查看文档
30
+ */
31
+ bcid: "qrcode" | "dataMatrix";
32
+ /**
33
+ * =1056 - 最终图片宽度
34
+ */
35
+ width: number;
36
+ /**
37
+ * =342 - 最终图片高度
38
+ */
39
+ height: number;
40
+ /**
41
+ * =300 - 二维码宽度
42
+ */
43
+ qrcodeW: number;
44
+ /**
45
+ * =300 - 二维码高度
46
+ */
47
+ qrcodeH: number;
48
+ /**
49
+ * =true - 是否在右侧添加文字
50
+ */
51
+ addText: boolean;
52
+ /**
53
+ * =10 - 顶部距离
54
+ */
55
+ top: number;
56
+ /**
57
+ * =10 - 左侧距离
58
+ */
59
+ left: number;
60
+ /**
61
+ * =1 - 文字行高,换行后下一行文字的y位置计算为fontSize * lineHeight
62
+ */
63
+ lineHeight: number;
64
+ /**
65
+ * =60 - 文字大小
66
+ */
67
+ fontSize: number;
68
+ /**
69
+ * ='黑体' - 字体类型
70
+ */
71
+ fontFamily: string;
72
+ /**
73
+ * ='#fff' - 背景颜色
74
+ */
75
+ bgColor: string;
76
+ /**
77
+ * =20 - 文字距离二维码间隔
78
+ */
79
+ textLeftMargin: number;
80
+ /**
81
+ * =700 - 字体加粗
82
+ */
83
+ fontWeight: boolean;
84
+ /**
85
+ * ='#000' - 字体颜色
86
+ */
87
+ textColor: string;
88
+ /**
89
+ * - 右侧文字内容
90
+ */
91
+ textContent: string;
92
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 获取当前屏幕分辨率(百分制,默认100)
3
+ * @returns {number} 当前屏幕分辨率
4
+ */
5
+ export function getRatio(): number;
6
+ /**
7
+ * 将Base64转换为ArrayBuffer
8
+ * @param {string} base64String
9
+ * @returns {ArrayBuffer} base64的ArrayBuffer
10
+ */
11
+ export function base64ToArrayBuffer(base64String: string): ArrayBuffer;
12
+ /**
13
+ * 将Int8Array转换为Base64格式的字符串
14
+ * @param {Int8Array} int8
15
+ * @returns {string} base64格式的字符串
16
+ */
17
+ export function int8ArrayToBase64(int8: Int8Array): string;
18
+ /**
19
+ * 将ArrayBuffer转换为Base64格式的字符串
20
+ * @param {ArrayBuffer} outputBuffer
21
+ * @returns {string} base64格式的字符串
22
+ */
23
+ export function arrayBufferToBase64(outputBuffer: ArrayBuffer): string;
24
+ /**
25
+ * 获取当前屏幕分辨率(百分制,默认100)
26
+ * @returns {number} 当前屏幕分辨率
27
+ */
28
+ export function detectZoom(): number;