template-replacement 3.4.0 → 3.5.0
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/core/base.ts +5 -5
- package/dist/main/general.js +1667 -1737
- package/dist/main/sign.js +1933 -2006
- package/dist/replace/general.js +234 -307
- package/dist/replace/sign.js +275 -351
- package/package.json +4 -4
- package/replace/image.ts +16 -6
- package/replace/sign.ts +8 -17
- package/worker/main/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "template-replacement",
|
|
3
3
|
"description": "模板文件替换",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.0",
|
|
5
5
|
"author": "fushiliang <994301536@qq.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "index.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"fflate": "^0.8.2",
|
|
16
16
|
"file-type": "^19.6.0",
|
|
17
17
|
"streamsaver": "^2.0.6",
|
|
18
|
-
"template-replacement-core-wasm": "^1.
|
|
19
|
-
"template-replacement-sign-core-wasm": "^1.
|
|
18
|
+
"template-replacement-core-wasm": "^1.8.0",
|
|
19
|
+
"template-replacement-sign-core-wasm": "^1.8.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@rollup/pluginutils": "^5.3.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"eslint": "^9.39.2",
|
|
27
27
|
"eslint-plugin-oxlint": "^1.33.0",
|
|
28
28
|
"oxfmt": "^0.16.0",
|
|
29
|
-
"oxlint": "^1.
|
|
29
|
+
"oxlint": "^1.34.0",
|
|
30
30
|
"terser": "^5.44.1",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vite": "^7.3.0"
|
package/replace/image.ts
CHANGED
|
@@ -30,6 +30,15 @@ export type extent = {
|
|
|
30
30
|
cx: number
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
//允许设置的属性
|
|
34
|
+
const allowSetPropertyKeys = new Set([
|
|
35
|
+
'file',
|
|
36
|
+
'id',
|
|
37
|
+
'wpExtent',
|
|
38
|
+
'textWrap',
|
|
39
|
+
'relationship',
|
|
40
|
+
])
|
|
41
|
+
|
|
33
42
|
//图片替换
|
|
34
43
|
export default class image {
|
|
35
44
|
file: Blob
|
|
@@ -59,11 +68,6 @@ export default class image {
|
|
|
59
68
|
this._awaitInitQueue = undefined
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
// async generateId(): Promise<string> {
|
|
63
|
-
// this.id = await generateId(this.file)
|
|
64
|
-
// return this.id
|
|
65
|
-
// }
|
|
66
|
-
|
|
67
71
|
async awaitInit(): Promise<void> {
|
|
68
72
|
if (this._awaitInitQueue) {
|
|
69
73
|
await new Promise((resolve) => {
|
|
@@ -77,7 +81,7 @@ export default class image {
|
|
|
77
81
|
if (this.file.size) {
|
|
78
82
|
try {
|
|
79
83
|
const bitmap = await createImageBitmap(this.file)
|
|
80
|
-
if (this.wpExtent) {
|
|
84
|
+
if (!this.wpExtent) {
|
|
81
85
|
this.setPxExtent(bitmap.width, bitmap.height)
|
|
82
86
|
}
|
|
83
87
|
bitmap.close()
|
|
@@ -113,6 +117,9 @@ export default class image {
|
|
|
113
117
|
await this.awaitInit()
|
|
114
118
|
const data: Record<string, unknown> = {}
|
|
115
119
|
for (const key in this) {
|
|
120
|
+
if (!allowSetPropertyKeys.has(key)) {
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
116
123
|
data[key] = this[key]
|
|
117
124
|
}
|
|
118
125
|
return data
|
|
@@ -120,6 +127,9 @@ export default class image {
|
|
|
120
127
|
|
|
121
128
|
setProperties(data: Record<string, unknown>) {
|
|
122
129
|
for (const key in data) {
|
|
130
|
+
if (!allowSetPropertyKeys.has(key)) {
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
123
133
|
this[key as keyof image] = data[key] as never;
|
|
124
134
|
}
|
|
125
135
|
}
|
package/replace/sign.ts
CHANGED
|
@@ -20,17 +20,14 @@ export default class Sign extends Base {
|
|
|
20
20
|
encode_files: Uint8Array[],
|
|
21
21
|
): Promise<Uint8Array[]> {
|
|
22
22
|
paramsData.add_media = add_media
|
|
23
|
-
const
|
|
23
|
+
const tempFiles = []
|
|
24
24
|
for (const file of files) {
|
|
25
|
-
|
|
25
|
+
tempFiles.push(add_template(file, false))
|
|
26
26
|
}
|
|
27
27
|
for (const file of encode_files) {
|
|
28
|
-
|
|
28
|
+
tempFiles.push(add_template(file, true))
|
|
29
29
|
}
|
|
30
|
-
const [
|
|
31
|
-
Promise.all(addFileTasks),
|
|
32
|
-
paramsData.toReplaceParams(),
|
|
33
|
-
])
|
|
30
|
+
const [variables] = await paramsData.toReplaceParams()
|
|
34
31
|
const encodeData = {
|
|
35
32
|
files: tempFiles,
|
|
36
33
|
variables,
|
|
@@ -59,23 +56,17 @@ export default class Sign extends Base {
|
|
|
59
56
|
}),
|
|
60
57
|
)
|
|
61
58
|
}
|
|
62
|
-
|
|
63
|
-
const addFileTasks: Promise<number>[] = []
|
|
59
|
+
const tempFiles = []
|
|
64
60
|
for (const file of files) {
|
|
65
|
-
|
|
61
|
+
tempFiles.push(add_template(file, false))
|
|
66
62
|
}
|
|
67
63
|
for (const file of encode_files) {
|
|
68
|
-
|
|
64
|
+
tempFiles.push(add_template(file, true))
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
const [tempFiles, variables] = await Promise.all([
|
|
72
|
-
Promise.all(addFileTasks),
|
|
73
|
-
Promise.all(variablesTasks),
|
|
74
|
-
])
|
|
75
|
-
|
|
76
67
|
const encodeData = {
|
|
77
68
|
files: tempFiles,
|
|
78
|
-
variables,
|
|
69
|
+
variables: await Promise.all(variablesTasks),
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
const paramsEncode = await replace_params_encode_multiple_params(encodeData)
|
package/worker/main/index.ts
CHANGED
|
@@ -92,7 +92,7 @@ export default class WorkerReplace implements ReplaceInterface {
|
|
|
92
92
|
|
|
93
93
|
#call<T>(method: allMethodNames, params: unknown[]): Promise<T> {
|
|
94
94
|
const transfer: Transferable[] = []
|
|
95
|
-
|
|
95
|
+
//TODO 处理params中的Transferable对象,但要考虑拆分多个worker处理之后Transferable对象所有权只会被一个worker获取
|
|
96
96
|
for (const param of params) {
|
|
97
97
|
if (param instanceof Array) {
|
|
98
98
|
for (const item of param) {
|