@cloud-print/uni-utils 1.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 +3 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +151 -0
- package/dist/index.d.mts +151 -0
- package/dist/index.mjs +1 -0
- package/package.json +70 -0
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=function(e){return e.LOW=`low`,e.MEDIUM=`medium`,e.HIGH=`high`,e}({});function t(e){let{windowWidth:t}=uni.getWindowInfo();return 750/t*e}function n(e){let{windowWidth:t}=uni.getWindowInfo();return t/750*e}function r(e,t=`rpx`){return`${e}${t}`}function i({to:e,from:t,sources:n}){let r=e/t;return n.map(e=>e*r)}function a({targetRpx:e,base:t=`width`,widthPx:n,heightPx:r}){let i=t===`width`?e/n:e/r,a=e=>e*i;return{width:a(n),height:a(r),px:a,ratio:i}}function o(e,t){return Math.round(e/25.4*t)}function s(e,t,n){return{width:o(e,n),height:o(t,n)}}function c(e){let[t,n]=i({from:210,to:e,sources:[210,297]});return{width:t,height:n}}exports.A4_HEIGHT=297,exports.A4_WIDTH=210,exports.DeviceLevel=e,exports.addUnit=r,exports.getA4Size=c,exports.getDpiSize=s,exports.mmToPx=o,exports.px2rpx=t,exports.resize=i,exports.rpx2px=n,exports.transform=a;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
export declare enum DeviceLevel {
|
|
3
|
+
LOW = "low",
|
|
4
|
+
MEDIUM = "medium",
|
|
5
|
+
HIGH = "high"
|
|
6
|
+
}
|
|
7
|
+
/** 设备性能评测各维度归一化得分(0~1,越高越好) */
|
|
8
|
+
export interface DevicePerfDimensionScores {
|
|
9
|
+
benchmark?: number;
|
|
10
|
+
memory?: number;
|
|
11
|
+
system?: number;
|
|
12
|
+
}
|
|
13
|
+
/** 设备性能评测快照,便于调试与上报 */
|
|
14
|
+
export interface DevicePerfMetrics {
|
|
15
|
+
platform: string;
|
|
16
|
+
benchmarkLevel?: number;
|
|
17
|
+
memoryMb?: number;
|
|
18
|
+
systemMajor?: number;
|
|
19
|
+
scores: DevicePerfDimensionScores;
|
|
20
|
+
/** 加权综合得分 0~1 */
|
|
21
|
+
compositeScore: number;
|
|
22
|
+
level: DeviceLevel;
|
|
23
|
+
}
|
|
24
|
+
export interface Dimension {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
export interface OSSImageInfo {
|
|
29
|
+
/**
|
|
30
|
+
* 图片文件大小,单位为 Byte。
|
|
31
|
+
*/
|
|
32
|
+
fileSize: number;
|
|
33
|
+
/**
|
|
34
|
+
* 图片格式,例如 jpg、png、gif。
|
|
35
|
+
*/
|
|
36
|
+
format: string;
|
|
37
|
+
/**
|
|
38
|
+
* 图片的帧数。
|
|
39
|
+
*/
|
|
40
|
+
frameCount: number;
|
|
41
|
+
/**
|
|
42
|
+
* 图片高度,单位为像素。
|
|
43
|
+
*/
|
|
44
|
+
imageHeight: number;
|
|
45
|
+
/**
|
|
46
|
+
* 图片宽度,单位为像素。
|
|
47
|
+
*/
|
|
48
|
+
imageWidth: number;
|
|
49
|
+
/**
|
|
50
|
+
* 分辨率单位。仅当图片自身携带分辨率元数据时返回。
|
|
51
|
+
*/
|
|
52
|
+
resolutionUnit?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 水平分辨率,以分数形式返回,例如 1/1、96/1。仅当图片自身携带分辨率元数据时返回。
|
|
55
|
+
*/
|
|
56
|
+
xResolution?: string;
|
|
57
|
+
/**
|
|
58
|
+
* 垂直分辨率,以分数形式返回,例如 1/1、96/1。仅当图片自身携带分辨率元数据时返回。
|
|
59
|
+
*/
|
|
60
|
+
yResolution?: string;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/helpers/a4.d.ts
|
|
64
|
+
export declare const A4_WIDTH = 210;
|
|
65
|
+
export declare const A4_HEIGHT = 297;
|
|
66
|
+
export declare function getA4Size(to: number): {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/helpers/unit.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* px 转换为 rpx
|
|
74
|
+
* @param px px 值
|
|
75
|
+
* @returns rpx 值
|
|
76
|
+
*/
|
|
77
|
+
export declare function px2rpx(px: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* rpx 转换为 px
|
|
80
|
+
* @param rpx rpx 值
|
|
81
|
+
* @returns px 值
|
|
82
|
+
*/
|
|
83
|
+
export declare function rpx2px(rpx: number): number;
|
|
84
|
+
/**
|
|
85
|
+
* 添加单位
|
|
86
|
+
* @param value 值
|
|
87
|
+
* @param unit 单位
|
|
88
|
+
* @returns 添加单位后的值
|
|
89
|
+
*/
|
|
90
|
+
export declare function addUnit(value: number, unit?: string): string;
|
|
91
|
+
interface ResizeOption {
|
|
92
|
+
to: number;
|
|
93
|
+
from: number;
|
|
94
|
+
sources: number[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 根据比例尺转换
|
|
98
|
+
* @param option {ResizeOption}
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare function resize({ to, from, sources }: ResizeOption): number[];
|
|
102
|
+
interface TransformOptions {
|
|
103
|
+
/**
|
|
104
|
+
* 目标尺寸(rpx)
|
|
105
|
+
*/
|
|
106
|
+
targetRpx: number;
|
|
107
|
+
/**
|
|
108
|
+
* 基础尺寸,默认宽度
|
|
109
|
+
*/
|
|
110
|
+
base?: "width" | "height";
|
|
111
|
+
/**
|
|
112
|
+
* 宽度(px)
|
|
113
|
+
*/
|
|
114
|
+
widthPx: number;
|
|
115
|
+
/**
|
|
116
|
+
* 高度(px)
|
|
117
|
+
*/
|
|
118
|
+
heightPx: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 转换尺寸
|
|
122
|
+
* 将宽高(px)按目标尺寸(rpx)等比转换为宽高(rpx)
|
|
123
|
+
* @param options
|
|
124
|
+
* @returns
|
|
125
|
+
* @deprecated 请使用 resize 代替
|
|
126
|
+
*/
|
|
127
|
+
export declare function transform({ targetRpx, base, widthPx, heightPx }: TransformOptions): {
|
|
128
|
+
width: number;
|
|
129
|
+
height: number;
|
|
130
|
+
px: (value: number) => number;
|
|
131
|
+
ratio: number;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* 毫米转像素
|
|
135
|
+
* @param mm 毫米
|
|
136
|
+
* @param dpi DPI
|
|
137
|
+
* @returns 像素
|
|
138
|
+
*/
|
|
139
|
+
export declare function mmToPx(mm: number, dpi: number): number;
|
|
140
|
+
/**
|
|
141
|
+
* 根据毫米和DPI计算尺寸(px)
|
|
142
|
+
* @param width 宽度(mm)
|
|
143
|
+
* @param height 高度(mm)
|
|
144
|
+
* @param dpi DPI
|
|
145
|
+
* @returns 尺寸(px)
|
|
146
|
+
*/
|
|
147
|
+
export declare function getDpiSize(width: number, height: number, dpi: number): {
|
|
148
|
+
width: number;
|
|
149
|
+
height: number;
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
export declare enum DeviceLevel {
|
|
3
|
+
LOW = "low",
|
|
4
|
+
MEDIUM = "medium",
|
|
5
|
+
HIGH = "high"
|
|
6
|
+
}
|
|
7
|
+
/** 设备性能评测各维度归一化得分(0~1,越高越好) */
|
|
8
|
+
export interface DevicePerfDimensionScores {
|
|
9
|
+
benchmark?: number;
|
|
10
|
+
memory?: number;
|
|
11
|
+
system?: number;
|
|
12
|
+
}
|
|
13
|
+
/** 设备性能评测快照,便于调试与上报 */
|
|
14
|
+
export interface DevicePerfMetrics {
|
|
15
|
+
platform: string;
|
|
16
|
+
benchmarkLevel?: number;
|
|
17
|
+
memoryMb?: number;
|
|
18
|
+
systemMajor?: number;
|
|
19
|
+
scores: DevicePerfDimensionScores;
|
|
20
|
+
/** 加权综合得分 0~1 */
|
|
21
|
+
compositeScore: number;
|
|
22
|
+
level: DeviceLevel;
|
|
23
|
+
}
|
|
24
|
+
export interface Dimension {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
export interface OSSImageInfo {
|
|
29
|
+
/**
|
|
30
|
+
* 图片文件大小,单位为 Byte。
|
|
31
|
+
*/
|
|
32
|
+
fileSize: number;
|
|
33
|
+
/**
|
|
34
|
+
* 图片格式,例如 jpg、png、gif。
|
|
35
|
+
*/
|
|
36
|
+
format: string;
|
|
37
|
+
/**
|
|
38
|
+
* 图片的帧数。
|
|
39
|
+
*/
|
|
40
|
+
frameCount: number;
|
|
41
|
+
/**
|
|
42
|
+
* 图片高度,单位为像素。
|
|
43
|
+
*/
|
|
44
|
+
imageHeight: number;
|
|
45
|
+
/**
|
|
46
|
+
* 图片宽度,单位为像素。
|
|
47
|
+
*/
|
|
48
|
+
imageWidth: number;
|
|
49
|
+
/**
|
|
50
|
+
* 分辨率单位。仅当图片自身携带分辨率元数据时返回。
|
|
51
|
+
*/
|
|
52
|
+
resolutionUnit?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 水平分辨率,以分数形式返回,例如 1/1、96/1。仅当图片自身携带分辨率元数据时返回。
|
|
55
|
+
*/
|
|
56
|
+
xResolution?: string;
|
|
57
|
+
/**
|
|
58
|
+
* 垂直分辨率,以分数形式返回,例如 1/1、96/1。仅当图片自身携带分辨率元数据时返回。
|
|
59
|
+
*/
|
|
60
|
+
yResolution?: string;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/helpers/a4.d.ts
|
|
64
|
+
export declare const A4_WIDTH = 210;
|
|
65
|
+
export declare const A4_HEIGHT = 297;
|
|
66
|
+
export declare function getA4Size(to: number): {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/helpers/unit.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* px 转换为 rpx
|
|
74
|
+
* @param px px 值
|
|
75
|
+
* @returns rpx 值
|
|
76
|
+
*/
|
|
77
|
+
export declare function px2rpx(px: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* rpx 转换为 px
|
|
80
|
+
* @param rpx rpx 值
|
|
81
|
+
* @returns px 值
|
|
82
|
+
*/
|
|
83
|
+
export declare function rpx2px(rpx: number): number;
|
|
84
|
+
/**
|
|
85
|
+
* 添加单位
|
|
86
|
+
* @param value 值
|
|
87
|
+
* @param unit 单位
|
|
88
|
+
* @returns 添加单位后的值
|
|
89
|
+
*/
|
|
90
|
+
export declare function addUnit(value: number, unit?: string): string;
|
|
91
|
+
interface ResizeOption {
|
|
92
|
+
to: number;
|
|
93
|
+
from: number;
|
|
94
|
+
sources: number[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 根据比例尺转换
|
|
98
|
+
* @param option {ResizeOption}
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare function resize({ to, from, sources }: ResizeOption): number[];
|
|
102
|
+
interface TransformOptions {
|
|
103
|
+
/**
|
|
104
|
+
* 目标尺寸(rpx)
|
|
105
|
+
*/
|
|
106
|
+
targetRpx: number;
|
|
107
|
+
/**
|
|
108
|
+
* 基础尺寸,默认宽度
|
|
109
|
+
*/
|
|
110
|
+
base?: "width" | "height";
|
|
111
|
+
/**
|
|
112
|
+
* 宽度(px)
|
|
113
|
+
*/
|
|
114
|
+
widthPx: number;
|
|
115
|
+
/**
|
|
116
|
+
* 高度(px)
|
|
117
|
+
*/
|
|
118
|
+
heightPx: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 转换尺寸
|
|
122
|
+
* 将宽高(px)按目标尺寸(rpx)等比转换为宽高(rpx)
|
|
123
|
+
* @param options
|
|
124
|
+
* @returns
|
|
125
|
+
* @deprecated 请使用 resize 代替
|
|
126
|
+
*/
|
|
127
|
+
export declare function transform({ targetRpx, base, widthPx, heightPx }: TransformOptions): {
|
|
128
|
+
width: number;
|
|
129
|
+
height: number;
|
|
130
|
+
px: (value: number) => number;
|
|
131
|
+
ratio: number;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* 毫米转像素
|
|
135
|
+
* @param mm 毫米
|
|
136
|
+
* @param dpi DPI
|
|
137
|
+
* @returns 像素
|
|
138
|
+
*/
|
|
139
|
+
export declare function mmToPx(mm: number, dpi: number): number;
|
|
140
|
+
/**
|
|
141
|
+
* 根据毫米和DPI计算尺寸(px)
|
|
142
|
+
* @param width 宽度(mm)
|
|
143
|
+
* @param height 高度(mm)
|
|
144
|
+
* @param dpi DPI
|
|
145
|
+
* @returns 尺寸(px)
|
|
146
|
+
*/
|
|
147
|
+
export declare function getDpiSize(width: number, height: number, dpi: number): {
|
|
148
|
+
width: number;
|
|
149
|
+
height: number;
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=function(e){return e.LOW=`low`,e.MEDIUM=`medium`,e.HIGH=`high`,e}({});function t(e){let{windowWidth:t}=uni.getWindowInfo();return 750/t*e}function n(e){let{windowWidth:t}=uni.getWindowInfo();return t/750*e}function r(e,t=`rpx`){return`${e}${t}`}function i({to:e,from:t,sources:n}){let r=e/t;return n.map(e=>e*r)}function a({targetRpx:e,base:t=`width`,widthPx:n,heightPx:r}){let i=t===`width`?e/n:e/r,a=e=>e*i;return{width:a(n),height:a(r),px:a,ratio:i}}function o(e,t){return Math.round(e/25.4*t)}function s(e,t,n){return{width:o(e,n),height:o(t,n)}}const c=210,l=297;function u(e){let[t,n]=i({from:210,to:e,sources:[210,297]});return{width:t,height:n}}export{l as A4_HEIGHT,c as A4_WIDTH,e as DeviceLevel,r as addUnit,u as getA4Size,s as getDpiSize,o as mmToPx,t as px2rpx,i as resize,n as rpx2px,a as transform};
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloud-print/uni-utils",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "uniapp 云打印项目工具库",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsdown",
|
|
7
|
+
"release:patch": "npx release-it --increment patch",
|
|
8
|
+
"release:minor": "npx release-it --increment minor",
|
|
9
|
+
"release:major": "npx release-it --increment major"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"uniapp",
|
|
13
|
+
"cloud-print",
|
|
14
|
+
"utils"
|
|
15
|
+
],
|
|
16
|
+
"author": "@cloud-print",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"packageManager": "pnpm@10.30.3",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": {
|
|
22
|
+
"import": "./dist/index.d.mts",
|
|
23
|
+
"require": "./dist/index.d.cts"
|
|
24
|
+
},
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@biomejs/biome": "^2.5.13",
|
|
37
|
+
"@tsconfig/node26": "^26.0.1",
|
|
38
|
+
"@types/node": "^26.5.0",
|
|
39
|
+
"tsdown": "^0.23.0",
|
|
40
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
41
|
+
"release-it": "^19.0.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@dcloudio/types": "^3.4.32",
|
|
45
|
+
"typescript": "^4.8.0 || ^5.0.0 || ^6.0.0",
|
|
46
|
+
"vue": "^3.2.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
},
|
|
52
|
+
"release-it": {
|
|
53
|
+
"git": {
|
|
54
|
+
"commitMessage": "chore: release v${version}",
|
|
55
|
+
"tagName": "v${version}"
|
|
56
|
+
},
|
|
57
|
+
"github": {
|
|
58
|
+
"release": false
|
|
59
|
+
},
|
|
60
|
+
"npm": {
|
|
61
|
+
"publish": true
|
|
62
|
+
},
|
|
63
|
+
"plugins": {
|
|
64
|
+
"@release-it/conventional-changelog": {
|
|
65
|
+
"preset": "angular",
|
|
66
|
+
"infile": "changelog.md"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|