template-replacement 3.3.3 → 3.4.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.
Files changed (56) hide show
  1. package/.editorconfig +8 -0
  2. package/.oxfmtrc.jsonc +7 -0
  3. package/.oxlintrc.json +3 -0
  4. package/README.md +39 -9
  5. package/core/base.ts +54 -55
  6. package/core/general.ts +37 -9
  7. package/core/sign.ts +43 -8
  8. package/dispatcher/general.ts +2 -1
  9. package/dispatcher/sign.ts +2 -1
  10. package/dispatcher/workerGeneral.ts +1 -1
  11. package/dispatcher/workerSign.ts +1 -1
  12. package/dist/base-DQz39fXI.js +249 -0
  13. package/dist/index-oILo_kXG.js +46 -0
  14. package/dist/main/general.js +1334 -1384
  15. package/dist/main/sign.js +1476 -1514
  16. package/dist/replace/general.js +283 -313
  17. package/dist/replace/sign.js +309 -327
  18. package/download/index.ts +13 -13
  19. package/download/stream.ts +29 -28
  20. package/eslint.config.ts +28 -0
  21. package/fileSystem/db/index.ts +25 -25
  22. package/fileSystem/db/indexedDBCache.ts +145 -143
  23. package/fileSystem/index.ts +5 -8
  24. package/fileSystem/interface.ts +4 -5
  25. package/fileSystem/opfs/index.ts +40 -36
  26. package/helper/index.ts +136 -125
  27. package/index.ts +6 -6
  28. package/office/zip.ts +106 -97
  29. package/package.json +14 -8
  30. package/replace/base.ts +203 -222
  31. package/replace/general.ts +44 -24
  32. package/replace/image.ts +88 -90
  33. package/replace/interface.ts +29 -24
  34. package/replace/paramsData.ts +107 -95
  35. package/replace/sign.ts +79 -52
  36. package/task/urlDownloadTask.ts +53 -55
  37. package/temp/index.ts +139 -124
  38. package/temp/interface.ts +8 -8
  39. package/tsconfig.json +1 -1
  40. package/vite.config.ts +11 -14
  41. package/worker/child/agency.ts +49 -41
  42. package/worker/child/base.ts +125 -89
  43. package/worker/child/general.ts +2 -3
  44. package/worker/child/sign.ts +4 -4
  45. package/worker/index.ts +52 -53
  46. package/worker/interface.ts +9 -6
  47. package/worker/main/general.ts +5 -5
  48. package/worker/main/index.ts +191 -66
  49. package/worker/main/sign.ts +5 -5
  50. package/worker/type.ts +16 -15
  51. package/dist/assets/template_replacement_core_wasm_bg.wasm +0 -0
  52. package/dist/assets/template_replacement_sign_core_wasm_bg.wasm +0 -0
  53. package/dist/base-CJv023nf.js +0 -284
  54. package/dist/general.d.ts +0 -1
  55. package/dist/index-tFDVIkZX.js +0 -46
  56. package/dist/sign.d.ts +0 -1
@@ -3,68 +3,66 @@ import file from "../fileSystem"
3
3
  import { hashString } from "../helper"
4
4
 
5
5
  export default class urlDownloadTask {
6
- urls: string[]
7
- downloadProgressListener:((progressEvent: AxiosProgressEvent) => void)[] = []
6
+ urls: string[]
7
+ #downloadProgressListener: ((progressEvent: AxiosProgressEvent) => void)[] = []
8
8
 
9
- constructor(urls: string[]) {
10
- if (urls.constructor !== Array) {
11
- throw new Error("不是可用的链接数组数据")
12
- }
13
- this.urls = urls
9
+ constructor(urls: string[]) {
10
+ if (urls.constructor !== Array) {
11
+ throw new Error('不是可用的链接数组数据')
14
12
  }
13
+ this.urls = urls
14
+ }
15
15
 
16
- start(): Promise<(Blob|undefined)[]> {
17
- const tasks = []
18
- for (const url of this.urls) {
19
- tasks.push(this.getUrlData(url))
20
- }
21
- return Promise.all(tasks)
16
+ start(): Promise<(Blob | undefined)[]> {
17
+ const tasks = []
18
+ for (const url of this.urls) {
19
+ tasks.push(this.getUrlData(url))
22
20
  }
21
+ return Promise.all(tasks)
22
+ }
23
23
 
24
- async getUrlData(url: string): Promise<Blob|undefined> {
25
- const hash = await hashString(url)
26
- const fileObj = file(hash)
27
- const data = await fileObj.read()
28
- if (data.size) {
29
- return data
30
- }
31
- const getData = await this.download(url)
32
- if (!getData) {
33
- return undefined
34
- }
35
- fileObj.write(getData)
36
- return getData
24
+ async getUrlData(url: string): Promise<Blob | undefined> {
25
+ const hash = await hashString(url)
26
+ const fileObj = file(hash)
27
+ const data = await fileObj.read()
28
+ if (data.size) {
29
+ return data
37
30
  }
31
+ const getData = await this.download(url)
32
+ if (!getData) {
33
+ return undefined
34
+ }
35
+ fileObj.write(getData)
36
+ return getData
37
+ }
38
38
 
39
- async download(url: string): Promise<Blob> {
40
- const response = await axios.get(url, {
41
- responseType: 'blob',
42
- onDownloadProgress: (progressEvent: AxiosProgressEvent) => {
43
- for (const fun of this.downloadProgressListener) {
44
- fun(progressEvent)
45
- }
46
- }
47
- })
48
-
49
- const contentDisposition = response.headers['content-disposition']
50
- // 解析文件名
51
- if (contentDisposition) {
52
- const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition)
53
- if (matches != null && matches[1]) {
54
- const filename = matches[1].replace(/['"]/g, '')
55
- return new File(
56
- [response.data],
57
- filename,
58
- {
59
- type: response.headers['content-type'] ?? 'application/octet-stream'
60
- }
61
- )
62
- }
39
+ async download(url: string): Promise<Blob> {
40
+ const response = await axios.get(url, {
41
+ responseType: 'blob',
42
+ onDownloadProgress: (progressEvent: AxiosProgressEvent) => {
43
+ for (const fun of this.#downloadProgressListener) {
44
+ fun(progressEvent)
63
45
  }
64
- return response.data
65
- }
46
+ },
47
+ })
66
48
 
67
- onDownloadProgress(listen: (progressEvent: AxiosProgressEvent) => void) {
68
- this.downloadProgressListener.push(listen)
49
+ const contentDisposition = response.headers['content-disposition']
50
+ // 解析文件名
51
+ if (contentDisposition) {
52
+ const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
53
+ contentDisposition,
54
+ )
55
+ if (matches != null && matches[1]) {
56
+ const filename = matches[1].replace(/['"]/g, '')
57
+ return new File([response.data], filename, {
58
+ type: response.headers['content-type'] ?? 'application/octet-stream',
59
+ })
60
+ }
69
61
  }
70
- }
62
+ return response.data
63
+ }
64
+
65
+ onDownloadProgress(listen: (progressEvent: AxiosProgressEvent) => void) {
66
+ this.#downloadProgressListener.push(listen)
67
+ }
68
+ }
package/temp/index.ts CHANGED
@@ -1,156 +1,171 @@
1
- import { fileTypeByBuffer, fileTypes, getFileNameFromUrl, urlsToFileBlobs } from '../helper'
1
+ import {
2
+ fileTypeByBuffer,
3
+ fileTypes,
4
+ getFileNameFromUrl,
5
+ urlsToFileBlobs,
6
+ } from '../helper'
2
7
  import { TempInterface } from './interface'
3
8
 
4
9
  export type TempImageInfo = {
5
- hash: string,
6
- blob: Blob,
7
- path: string
10
+ hash: string
11
+ blob: Blob
12
+ path: string
8
13
  }
9
14
 
10
15
  export enum status {
11
- waitLoad, //文件待加载
12
- loaded, //文件已加载
13
- replaceFinish, //完成替换
14
- replaceFail, //替换失败
15
- loadFail, //文件加载失败
16
+ waitLoad, //文件待加载
17
+ loaded, //文件已加载
18
+ replaceFinish, //完成替换
19
+ replaceFail, //替换失败
20
+ loadFail, //文件加载失败
16
21
  }
17
22
 
18
23
  //传递的文件信息
19
24
  export type transmitFileInfo = {
20
- name: string,
21
- uint8Array: Uint8Array,
22
- isDecode: boolean,
25
+ name: string
26
+ uint8Array: Uint8Array
27
+ isDecode: boolean
23
28
  }
24
29
 
25
30
  //将传递的文件信息转为模板对象
26
- export function transmitFileInfoToTemp(data: transmitFileInfo) {
27
- if (!data.uint8Array || !data.name) {
28
- throw new Error("模板文件信息错误")
29
- }
30
- const temp = new Temp(undefined, undefined, data.uint8Array, data.name)
31
- temp.isDecode = data.isDecode
32
- return temp
31
+ export function transmitFileInfoToTemp(data: transmitFileInfo): Temp {
32
+ if (!data.uint8Array || !data.name) {
33
+ throw new Error('模板文件信息错误')
34
+ }
35
+ const temp = new Temp(undefined, undefined, data.uint8Array, data.name)
36
+ temp.isDecode = data.isDecode
37
+ return temp
33
38
  }
34
39
 
35
- export default class Temp implements TempInterface{
36
- name: string = ''
37
- blob?: File|Blob
38
- uint8Array?: Uint8Array
39
- url?: string
40
- status = status.waitLoad // 0文件待加载,1文件已加载,2完成替换,3替换失败
41
- isDecode: boolean = false //文件是否被加密
42
-
43
- _output?: File|Blob
44
- _type?: fileTypes
45
-
46
- tempImages: Record<string, TempImageInfo> = {}
47
-
48
- constructor(file?: File|Blob, url?: string, uint8Array?: Uint8Array, name?: string) {
49
- if (uint8Array) {
50
- this.uint8Array = uint8Array
51
- this.setStatus(status.loaded)
52
- }else if (file) {
53
- this.blob = file
54
- this.setStatus(status.loaded)
55
- }else if (url) {
56
- this.url = url
57
- }
58
- if (name) {
59
- this.name = name
60
- }else{
61
- this.name = (file as File)?.name ?? ''
62
- }
63
-
64
- if (!url && !file && !uint8Array) {
65
- throw new Error("缺少文件数据或文件链接")
66
- }
40
+ export default class Temp implements TempInterface {
41
+ name: string = ''
42
+ blob?: File | Blob
43
+ uint8Array?: Uint8Array
44
+ url?: string
45
+ status = status.waitLoad // 0文件待加载,1文件已加载,2完成替换,3替换失败
46
+ isDecode: boolean = false //文件是否需要解密
47
+
48
+ tempImages: Record<string, TempImageInfo> = {}
49
+
50
+ private _output?: File | Blob = undefined
51
+ private _type?: fileTypes = undefined
52
+
53
+ constructor(
54
+ file?: File | Blob,
55
+ url?: string,
56
+ uint8Array?: Uint8Array,
57
+ name?: string,
58
+ ) {
59
+ if (uint8Array) {
60
+ this.uint8Array = uint8Array
61
+ this.setStatus(status.loaded)
62
+ } else if (file) {
63
+ this.blob = file
64
+ this.setStatus(status.loaded)
65
+ } else if (url) {
66
+ this.url = url
67
67
  }
68
-
69
- getName() {
70
- if (this.name) {
71
- return this.name
72
- }
73
- if ((this.blob as File)?.name) {
74
- this.name = (this.blob as File).name
75
- return this.name
76
- }
77
- return this.url ? getFileNameFromUrl(this.url) : ''
68
+ if (name) {
69
+ this.name = name
70
+ } else {
71
+ this.name = (file as File)?.name ?? ''
78
72
  }
79
73
 
80
- async type(): Promise<fileTypes> {
81
- if (this._type) {
82
- return this._type
83
- }
84
- const buffer = await this.getBuffer()
85
- if (buffer) {
86
- this._type = await fileTypeByBuffer(buffer)
87
- }else{
88
- this._type = fileTypes.unknown
89
- }
90
- return this._type
74
+ if (!url && !file && !uint8Array) {
75
+ throw new Error('缺少文件数据或文件链接')
91
76
  }
77
+ }
92
78
 
93
- async getBuffer(): Promise<Uint8Array|undefined>{
94
- if (this.uint8Array) {
95
- return this.uint8Array
96
- }
97
- const blob = await this.getBlob()
98
- if (blob) {
99
- this.uint8Array = new Uint8Array(await blob.arrayBuffer())
100
- }
101
-
102
- return this.uint8Array
79
+ getName() {
80
+ if (this.name) {
81
+ return this.name
103
82
  }
104
-
105
- async getBlob(): Promise<Blob|undefined> {
106
- if (this.blob) {
107
- return this.blob
108
- }
109
- if (!this.blob) {
110
- if (this.uint8Array) {
111
- this.blob = new Blob([ this.uint8Array as BlobPart ])
112
- }else if (this.url) {
113
- const [ blob ] = await urlsToFileBlobs([ this.url ])
114
- if (blob) {
115
- this.blob = blob
116
- }
117
- }
118
- }
119
- if ((this.status === status.waitLoad || this.status === status.loadFail) && this.blob) {
120
- this.setStatus(status.loaded)
121
- }
122
- if (!this.blob) {
123
- this.setStatus(status.loadFail)
124
- }
125
- return this.blob
83
+ if ((this.blob as File)?.name) {
84
+ this.name = (this.blob as File).name
85
+ return this.name
126
86
  }
87
+ return this.url ? getFileNameFromUrl(this.url) : ''
88
+ }
127
89
 
128
- setStatus(status: status): void {
129
- this.status = status
90
+ async type(): Promise<fileTypes> {
91
+ if (this._type) {
92
+ return this._type
130
93
  }
131
-
132
- setOutputFile(file: File|Blob): void {
133
- this._output = file
94
+ const buffer = await this.getBuffer()
95
+ if (buffer) {
96
+ this._type = await fileTypeByBuffer(buffer)
97
+ } else {
98
+ this._type = fileTypes.unknown
134
99
  }
100
+ return this._type
101
+ }
135
102
 
136
- setTempImages(images: Record<string, TempImageInfo>): void {
137
- this.tempImages = images
103
+ async getBuffer(): Promise<Uint8Array | undefined> {
104
+ if (this.uint8Array) {
105
+ return this.uint8Array
138
106
  }
139
-
140
- outputFile(): File|Blob|undefined {
141
- return this._output ?? this.blob
107
+ const blob = await this.getBlob()
108
+ if (blob) {
109
+ this.uint8Array = new Uint8Array(await blob.arrayBuffer())
142
110
  }
143
111
 
144
- async getTransmitFileInfo(): Promise<transmitFileInfo|undefined> {
145
- const uint8Array = this.uint8Array ? this.uint8Array : await this.getBuffer()
146
- if (!uint8Array) {
147
- return undefined
148
- }
149
- this.uint8Array = undefined
150
- return {
151
- name: this.getName(),
152
- uint8Array,
153
- isDecode: this.isDecode,
112
+ return this.uint8Array
113
+ }
114
+
115
+ async getBlob(): Promise<Blob | undefined> {
116
+ if (this.blob) {
117
+ return this.blob
118
+ }
119
+ if (!this.blob) {
120
+ if (this.uint8Array) {
121
+ this.blob = new Blob([this.uint8Array as BlobPart])
122
+ } else if (this.url) {
123
+ const [blob] = await urlsToFileBlobs([this.url])
124
+ if (blob) {
125
+ this.blob = blob
154
126
  }
127
+ }
128
+ }
129
+ if (
130
+ (this.status === status.waitLoad || this.status === status.loadFail) &&
131
+ this.blob
132
+ ) {
133
+ this.setStatus(status.loaded)
134
+ }
135
+ if (!this.blob) {
136
+ this.setStatus(status.loadFail)
137
+ }
138
+ return this.blob
139
+ }
140
+
141
+ setStatus(status: status): void {
142
+ this.status = status
143
+ }
144
+
145
+ setOutputFile(file: File | Blob): void {
146
+ this._output = file
147
+ }
148
+
149
+ setTempImages(images: Record<string, TempImageInfo>): void {
150
+ this.tempImages = images
151
+ }
152
+
153
+ outputFile(): File | Blob | undefined {
154
+ return this._output ?? this.blob
155
+ }
156
+
157
+ async getTransmitFileInfo(): Promise<transmitFileInfo | undefined> {
158
+ const uint8Array = this.uint8Array
159
+ ? this.uint8Array
160
+ : await this.getBuffer()
161
+ if (!uint8Array) {
162
+ return undefined
163
+ }
164
+ this.uint8Array = undefined
165
+ return {
166
+ name: this.getName(),
167
+ uint8Array,
168
+ isDecode: this.isDecode,
155
169
  }
170
+ }
156
171
  }
package/temp/interface.ts CHANGED
@@ -2,17 +2,17 @@ import { status, TempImageInfo } from '.'
2
2
  import { fileTypes } from '../helper'
3
3
 
4
4
  export interface TempInterface {
5
- type(): Promise<fileTypes>
5
+ type(): Promise<fileTypes>
6
6
 
7
- getBuffer(): Promise<Uint8Array|undefined>
7
+ getBuffer(): Promise<Uint8Array | undefined>
8
8
 
9
- getBlob(): Promise<Blob|undefined>
9
+ getBlob(): Promise<Blob | undefined>
10
10
 
11
- setStatus(status: status): void
11
+ setStatus(status: status): void
12
12
 
13
- setOutputFile(file: File|Blob): void
13
+ setOutputFile(file: File | Blob): void
14
14
 
15
- setTempImages(images: Record<string, TempImageInfo>): void
15
+ setTempImages(images: Record<string, TempImageInfo>): void
16
16
 
17
- outputFile(): File|Blob|undefined
18
- }
17
+ outputFile(): File | Blob | undefined
18
+ }
package/tsconfig.json CHANGED
@@ -27,7 +27,7 @@
27
27
  /* Modules */
28
28
  "module": "es2022", /* Specify what module code is generated. */
29
29
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30
+ // "moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
32
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
33
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
package/vite.config.ts CHANGED
@@ -1,26 +1,23 @@
1
- import { defineConfig } from 'vite';
2
- import wasmPack from 'vite-plugin-wasm-pack';
3
- import dts from 'vite-plugin-dts';
1
+ import { defineConfig } from 'vite'
4
2
 
5
3
  export default defineConfig({
6
- plugins: [
7
- wasmPack([], ['template-replacement-sign-core-wasm','template-replacement-core-wasm']),
8
- dts({
9
- entryRoot: './dist',
10
- insertTypesEntry: true,
11
- }),
12
- ],
13
4
  build: {
5
+ target: 'esnext',
14
6
  outDir: './dist',
15
7
  lib: {
16
- entry: ['./worker/main/sign.ts', './worker/main/general.ts', './replace/general.ts', './replace/sign.ts'],
8
+ entry: [
9
+ './worker/main/sign.ts',
10
+ './worker/main/general.ts',
11
+ './replace/general.ts',
12
+ './replace/sign.ts',
13
+ ],
17
14
  name: 'template-replacement',
18
15
  fileName: (format, entryName) => `${entryName}.js`,
19
16
  formats: ['es'],
20
17
  },
21
18
  rollupOptions: {
22
19
  output: {
23
- entryFileNames: (info: { facadeModuleId: string; }) => {
20
+ entryFileNames: (info) => {
24
21
  const modules = info.facadeModuleId?.split('/')
25
22
  if (!modules?.length || modules?.length < 2) {
26
23
  return '[name].js'
@@ -32,5 +29,5 @@ export default defineConfig({
32
29
  },
33
30
  worker: {
34
31
  format: 'es',
35
- }
36
- })
32
+ },
33
+ })
@@ -1,51 +1,56 @@
1
- import image from "../../replace/image";
2
- import ReplaceInterface, { media } from "../../replace/interface";
3
- import paramsData, { mediaData, textData } from "../../replace/paramsData";
4
- import Temp, { transmitFileInfo, transmitFileInfoToTemp } from "../../temp";
1
+ import image from '../../replace/image'
2
+ import ReplaceInterface, { media } from '../../replace/interface'
3
+ import paramsData, { mediaData, textData } from '../../replace/paramsData'
4
+ import Temp, { transmitFileInfo, transmitFileInfoToTemp } from '../../temp'
5
5
 
6
6
  export default class implements ReplaceInterface {
7
- replace: ReplaceInterface
7
+ #replace: ReplaceInterface
8
8
 
9
9
  constructor(replace: ReplaceInterface) {
10
- this.replace = replace
10
+ this.#replace = replace
11
11
  }
12
12
 
13
- addTempFile(tempFile: any) {
14
- tempFile = transmitFileInfoToTemp(tempFile)
15
- return this.replace.addTempFile(tempFile)
13
+ addTempFile(tempFile: transmitFileInfo | Temp): void {
14
+ tempFile = transmitFileInfoToTemp(tempFile as transmitFileInfo)
15
+ return this.#replace.addTempFile(tempFile)
16
16
  }
17
17
 
18
18
  clear() {
19
- return this.replace.clear()
19
+ return this.#replace.clear()
20
20
  }
21
21
 
22
22
  //提取变量
23
- extractVariables(files: Temp[] | undefined): Promise<Record<string, string[]>> {
23
+ extractVariables(
24
+ files: Temp[] | transmitFileInfo[] | undefined,
25
+ ): Promise<Record<string, string[]>> {
24
26
  if (files) {
25
27
  for (const i in files) {
26
28
  files[i] = transmitFileInfoToTemp(files[i] as transmitFileInfo)
27
29
  }
28
30
  }
29
- return this.replace.extractVariables(files)
31
+ return this.#replace.extractVariables(files as Temp[])
30
32
  }
31
33
 
32
34
  //提取媒体
33
- extractMedias(files: Temp[] | undefined): Promise<Record<string, media[]>> {
35
+ extractMedias(files: Temp[] | transmitFileInfo[] | undefined): Promise<Record<string, media[]>> {
34
36
  if (files) {
35
37
  for (const i in files) {
36
38
  files[i] = transmitFileInfoToTemp(files[i] as transmitFileInfo)
37
39
  }
38
40
  }
39
- return this.replace.extractMedias(files)
41
+ return this.#replace.extractMedias(files as Temp[])
40
42
  }
41
43
 
42
44
  //签名方法
43
- sign(data: any): Promise<string> {
44
- return this.replace.sign(data)
45
+ sign(data: unknown): Promise<string> {
46
+ return this.#replace.sign(data)
45
47
  }
46
48
 
47
49
  //执行替换任务
48
- execute(params: paramsData, files: Temp[] | undefined): Promise<Record<string, Uint8Array>> {
50
+ execute(
51
+ params: paramsData,
52
+ files: Temp[] | transmitFileInfo[] | undefined,
53
+ ): Promise<Record<string, Uint8Array>> {
49
54
  if (files) {
50
55
  for (const i in files) {
51
56
  files[i] = transmitFileInfoToTemp(files[i] as transmitFileInfo)
@@ -53,70 +58,73 @@ export default class implements ReplaceInterface {
53
58
  }
54
59
  const text: textData = {}
55
60
  for (const key in params.textData) {
56
- const value = params.textData[key] as Record<keyof image, any>
57
- if (value && value.file instanceof Blob) {
58
- text[key] = new image(value.file)
59
- delete value.file
60
- text[key].setPropertys(value)
61
- }else {
61
+ const value = params.textData[key]
62
+ if (value && (value as image).file instanceof Blob) {
63
+ text[key] = new image((value as image).file)
64
+ delete (value as Record<keyof image, unknown>).file
65
+ text[key].setProperties((value as Record<keyof image, unknown>))
66
+ } else {
62
67
  text[key] = value
63
68
  }
64
69
  }
65
70
 
66
71
  const media: mediaData = {}
67
72
  for (const key in params.mediaData) {
68
- const value = params.mediaData[key] as Record<keyof image, any>
73
+ const value = params.mediaData[key] as Record<keyof image, unknown>
69
74
  if (value && value.file instanceof Blob) {
70
75
  media[key] = new image(value.file)
71
76
  delete value.file
72
- media[key].setPropertys(value)
77
+ media[key].setProperties(value)
73
78
  }
74
79
  }
75
- return this.replace.execute(new paramsData(text, media), files)
80
+ return this.#replace.execute(new paramsData(text, media), files as Temp[])
76
81
  }
77
82
 
78
83
  //执行替换任务(多套参数)
79
- executeMultipleParams(paramsMultiple: paramsData[], files: Temp[] | undefined): Promise<Record<string, Uint8Array>[]> {
84
+ executeMultipleParams(
85
+ paramsMultiple: paramsData[],
86
+ files: Temp[] | undefined,
87
+ ): Promise<Record<string, Uint8Array>[]> {
80
88
  if (files) {
81
89
  for (const i in files) {
82
90
  files[i] = transmitFileInfoToTemp(files[i] as transmitFileInfo)
83
91
  }
84
92
  }
85
- const paramsList= []
93
+ const paramsList = []
86
94
  for (const params of paramsMultiple) {
87
95
  const text: textData = {}
88
96
  for (const key in params.textData) {
89
- const value = params.textData[key] as Record<keyof image, any>
90
- if (value && value.file instanceof Blob) {
91
- text[key] = new image(value.file)
92
- delete value.file
93
- text[key].setPropertys(value)
94
- }else {
97
+ const value = params.textData[key]
98
+ if (value && (value as image).file instanceof Blob) {
99
+ text[key] = new image((value as image).file)
100
+ delete (value as Record<keyof image, unknown>).file
101
+ text[key].setProperties((value as Record<keyof image, unknown>))
102
+ } else {
95
103
  text[key] = value
96
104
  }
97
105
  }
98
106
 
99
107
  const media: mediaData = {}
100
108
  for (const key in params.mediaData) {
101
- const value = params.mediaData[key] as Record<keyof image, any>
109
+ const value = params.mediaData[key] as Record<keyof image, unknown>
102
110
  if (value && value.file instanceof Blob) {
103
111
  media[key] = new image(value.file)
104
112
  delete value.file
105
- media[key].setPropertys(value)
113
+ media[key].setProperties(value)
106
114
  }
107
115
  }
108
116
  paramsList.push(new paramsData(text, media))
109
117
  }
110
- return this.replace.executeMultipleParams(paramsList, files)
118
+ return this.#replace.executeMultipleParams(paramsList, files)
111
119
  }
112
120
 
113
121
  //文件加密
114
122
  fileEncrypt(file: Uint8Array): Promise<Uint8Array> {
115
- return this.replace.fileEncrypt(file)
123
+ return this.#replace.fileEncrypt(file)
116
124
  }
117
125
 
118
126
  //文件批量加密
119
- filesEncrypt(files: (Uint8Array)[]): Promise<(Uint8Array)[]> {
120
- return this.replace.filesEncrypt(files)
127
+ filesEncrypt(files: Uint8Array[]): Promise<Uint8Array[]> {
128
+ return this.#replace.filesEncrypt(files)
121
129
  }
122
- }
130
+ }