@wener/common 2.0.5 → 2.0.6

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 (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,2 +1,2 @@
1
- export { fromQwen3VlBbox2d, toQwen3VlBbox2d } from "./utils.js";
1
+ export { fromQwen3VlBbox2d, toQwen3VlBbox2d } from './utils.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -5,13 +5,13 @@
5
5
  * @param bbox Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000
6
6
  * @returns Absolute pixel coordinates [x1, y1, x2, y2]
7
7
  */ export function fromQwen3VlBbox2d({ width, height }, bbox) {
8
- const [x1, y1, x2, y2] = bbox;
9
- return [
10
- Math.floor(x1 / 1000 * width),
11
- Math.floor(y1 / 1000 * height),
12
- Math.floor(x2 / 1000 * width),
13
- Math.floor(y2 / 1000 * height)
14
- ];
8
+ const [x1, y1, x2, y2] = bbox;
9
+ return [
10
+ Math.floor((x1 / 1000) * width),
11
+ Math.floor((y1 / 1000) * height),
12
+ Math.floor((x2 / 1000) * width),
13
+ Math.floor((y2 / 1000) * height),
14
+ ];
15
15
  }
16
16
  /**
17
17
  * Convert absolute pixel coordinates to Qwen3V format bbox (0-1000 range)
@@ -19,13 +19,13 @@
19
19
  * @param bbox Absolute pixel coordinates [x1, y1, x2, y2]
20
20
  * @returns Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000
21
21
  */ export function toQwen3VlBbox2d({ width, height }, bbox) {
22
- const [x1, y1, x2, y2] = bbox;
23
- return [
24
- Math.round(x1 / width * 1000),
25
- Math.round(y1 / height * 1000),
26
- Math.round(x2 / width * 1000),
27
- Math.round(y2 / height * 1000)
28
- ];
22
+ const [x1, y1, x2, y2] = bbox;
23
+ return [
24
+ Math.round((x1 / width) * 1000),
25
+ Math.round((y1 / height) * 1000),
26
+ Math.round((x2 / width) * 1000),
27
+ Math.round((y2 / height) * 1000),
28
+ ];
29
29
  }
30
30
 
31
- //# sourceMappingURL=utils.js.map
31
+ //# sourceMappingURL=utils.js.map
@@ -1,28 +1,28 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod';
2
2
  // based on DocLayout-YOLO
3
3
  export const DocLayoutElementType = Object.freeze({
4
- Title: 'Title',
5
- PlainText: 'PlainText',
6
- Abandon: 'Abandon',
7
- Figure: 'Figure',
8
- FigureCaption: 'FigureCaption',
9
- Table: 'Table',
10
- TableCaption: 'TableCaption',
11
- TableFootnote: 'TableFootnote',
12
- IsolateFormula: 'IsolateFormula',
13
- FormulaCaption: 'FormulaCaption'
4
+ Title: 'Title',
5
+ PlainText: 'PlainText',
6
+ Abandon: 'Abandon',
7
+ Figure: 'Figure',
8
+ FigureCaption: 'FigureCaption',
9
+ Table: 'Table',
10
+ TableCaption: 'TableCaption',
11
+ TableFootnote: 'TableFootnote',
12
+ IsolateFormula: 'IsolateFormula',
13
+ FormulaCaption: 'FormulaCaption',
14
14
  });
15
15
  export const DocLayoutElementTypeSchema = z.union([
16
- z.literal(DocLayoutElementType.Title).describe('标题'),
17
- z.literal(DocLayoutElementType.PlainText).describe('纯文本'),
18
- z.literal(DocLayoutElementType.Abandon).describe('废弃'),
19
- z.literal(DocLayoutElementType.Figure).describe('图片'),
20
- z.literal(DocLayoutElementType.FigureCaption).describe('图片说明'),
21
- z.literal(DocLayoutElementType.Table).describe('表格'),
22
- z.literal(DocLayoutElementType.TableCaption).describe('表格标题'),
23
- z.literal(DocLayoutElementType.TableFootnote).describe('表格脚注'),
24
- z.literal(DocLayoutElementType.IsolateFormula).describe('独立公式'),
25
- z.literal(DocLayoutElementType.FormulaCaption).describe('公式说明')
16
+ z.literal(DocLayoutElementType.Title).describe('标题'),
17
+ z.literal(DocLayoutElementType.PlainText).describe('纯文本'),
18
+ z.literal(DocLayoutElementType.Abandon).describe('废弃'),
19
+ z.literal(DocLayoutElementType.Figure).describe('图片'),
20
+ z.literal(DocLayoutElementType.FigureCaption).describe('图片说明'),
21
+ z.literal(DocLayoutElementType.Table).describe('表格'),
22
+ z.literal(DocLayoutElementType.TableCaption).describe('表格标题'),
23
+ z.literal(DocLayoutElementType.TableFootnote).describe('表格脚注'),
24
+ z.literal(DocLayoutElementType.IsolateFormula).describe('独立公式'),
25
+ z.literal(DocLayoutElementType.FormulaCaption).describe('公式说明'),
26
26
  ]);
27
27
 
28
- //# sourceMappingURL=DocLayoutElementTypeSchema.js.map
28
+ //# sourceMappingURL=DocLayoutElementTypeSchema.js.map
@@ -1,50 +1,66 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod';
2
2
  export const ImageAnnotationSchema = z.looseObject({
3
- id: z.string().optional(),
4
- title: z.string().trim().optional().describe('标题'),
5
- description: z.string().trim().optional().describe('描述'),
6
- type: z.string().trim().optional().describe('类型'),
7
- // 内容字段
8
- text: z.string().optional().describe('文本内容'),
9
- markdown: z.string().optional().describe('Markdown 内容'),
10
- csv: z.string().optional().describe('CSV 内容'),
11
- html: z.string().optional().describe('HTML 内容'),
12
- data: z.any().optional().describe('任意数据'),
13
- // 定位信息
14
- field: z.string().trim().optional().describe('目标字段'),
15
- file: z.string().trim().optional().describe('源文件'),
16
- page: z.coerce.number().int().nonnegative().optional().describe('页码'),
17
- // 几何/边界框信息
18
- bbox: z.array(z.number()).optional().describe('边界框'),
19
- xywh: z.array(z.number()).length(4, {
20
- error: 'xywh 必须包含4个数字 [x, y, width, height]'
21
- }).optional().describe('XYWH'),
22
- xyxy: z.array(z.number()).length(4, {
23
- error: 'xyxy 必须包含4个数字 [x1, y1, x2, y2]'
24
- }).optional().describe('XYXY'),
25
- polygon: z.array(z.number().array()).optional().describe('Polygon'),
26
- x: z.coerce.number().optional().describe('X 坐标'),
27
- y: z.coerce.number().optional().describe('Y 坐标'),
28
- w: z.coerce.number().nonnegative().optional().describe('宽度'),
29
- h: z.coerce.number().nonnegative().optional().describe('高度'),
30
- label: z.string().trim().optional().describe('标签'),
31
- confidence: z.coerce.number().min(0).max(1).optional().describe('置信度'),
32
- score: z.coerce.number().optional().describe('原始分数'),
33
- classes: z.array(z.object({
34
- label: z.string().nonempty({
35
- error: '分类标签不能为空'
36
- }).describe('分类标签'),
37
- confidence: z.coerce.number().min(0).max(1).optional().describe('分类置信度 (0-1)'),
38
- score: z.coerce.number().optional().describe('分类原始分数')
39
- })).optional().describe('多分类结果'),
40
- // 元数据和标签
41
- tags: z.array(z.string()).optional().describe('标签'),
42
- metadata: z.record(z.string(), z.any()).optional().describe('元数据'),
43
- attributes: z.record(z.string(), z.any()).optional().describe('属性'),
44
- properties: z.record(z.string(), z.any()).optional().describe('属性'),
45
- get annotations () {
46
- return z.array(ImageAnnotationSchema).optional().describe('子注释');
47
- }
3
+ id: z.string().optional(),
4
+ title: z.string().trim().optional().describe('标题'),
5
+ description: z.string().trim().optional().describe('描述'),
6
+ type: z.string().trim().optional().describe('类型'),
7
+ // 内容字段
8
+ text: z.string().optional().describe('文本内容'),
9
+ markdown: z.string().optional().describe('Markdown 内容'),
10
+ csv: z.string().optional().describe('CSV 内容'),
11
+ html: z.string().optional().describe('HTML 内容'),
12
+ data: z.any().optional().describe('任意数据'),
13
+ // 定位信息
14
+ field: z.string().trim().optional().describe('目标字段'),
15
+ file: z.string().trim().optional().describe('源文件'),
16
+ page: z.coerce.number().int().nonnegative().optional().describe('页码'),
17
+ // 几何/边界框信息
18
+ bbox: z.array(z.number()).optional().describe('边界框'),
19
+ xywh: z
20
+ .array(z.number())
21
+ .length(4, {
22
+ error: 'xywh 必须包含4个数字 [x, y, width, height]',
23
+ })
24
+ .optional()
25
+ .describe('XYWH'),
26
+ xyxy: z
27
+ .array(z.number())
28
+ .length(4, {
29
+ error: 'xyxy 必须包含4个数字 [x1, y1, x2, y2]',
30
+ })
31
+ .optional()
32
+ .describe('XYXY'),
33
+ polygon: z.array(z.number().array()).optional().describe('Polygon'),
34
+ x: z.coerce.number().optional().describe('X 坐标'),
35
+ y: z.coerce.number().optional().describe('Y 坐标'),
36
+ w: z.coerce.number().nonnegative().optional().describe('宽度'),
37
+ h: z.coerce.number().nonnegative().optional().describe('高度'),
38
+ label: z.string().trim().optional().describe('标签'),
39
+ confidence: z.coerce.number().min(0).max(1).optional().describe('置信度'),
40
+ score: z.coerce.number().optional().describe('原始分数'),
41
+ classes: z
42
+ .array(
43
+ z.object({
44
+ label: z
45
+ .string()
46
+ .nonempty({
47
+ error: '分类标签不能为空',
48
+ })
49
+ .describe('分类标签'),
50
+ confidence: z.coerce.number().min(0).max(1).optional().describe('分类置信度 (0-1)'),
51
+ score: z.coerce.number().optional().describe('分类原始分数'),
52
+ }),
53
+ )
54
+ .optional()
55
+ .describe('多分类结果'),
56
+ // 元数据和标签
57
+ tags: z.array(z.string()).optional().describe('标签'),
58
+ metadata: z.record(z.string(), z.any()).optional().describe('元数据'),
59
+ attributes: z.record(z.string(), z.any()).optional().describe('属性'),
60
+ properties: z.record(z.string(), z.any()).optional().describe('属性'),
61
+ get annotations() {
62
+ return z.array(ImageAnnotationSchema).optional().describe('子注释');
63
+ },
48
64
  });
49
65
 
50
- //# sourceMappingURL=ImageAnnotationSchema.js.map
66
+ //# sourceMappingURL=ImageAnnotationSchema.js.map
@@ -1,3 +1,3 @@
1
- export { ImageAnnotationSchema } from "./ImageAnnotationSchema.js";
2
- export { resolveImageAnnotation } from "./resolveImageAnnotation.js";
1
+ export { ImageAnnotationSchema } from './ImageAnnotationSchema.js';
2
+ export { resolveImageAnnotation } from './resolveImageAnnotation.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1,105 +1,91 @@
1
1
  export { resolveImageAnnotation };
2
2
  function resolveImageAnnotation(input) {
3
- const normalize = (input, { path = [], level = 0 } = {})=>{
4
- input.id ||= path.join('.') || 'ROOT';
5
- input.annotations ||= [];
6
- input.tags ||= [];
7
- input.attributes ||= {};
8
- input.metadata ||= {};
9
- if (!input.csv && input.html?.includes('<table') && globalThis.DOMParser) {
10
- const parser = new DOMParser();
11
- const doc = parser.parseFromString(input.html, 'text/html');
12
- const table = doc.querySelector('table');
13
- if (table) {
14
- const rows = Array.from(table.querySelectorAll('tr'));
15
- input.data = rows.map((row)=>Array.from(row.querySelectorAll('td')).map((td)=>td.textContent?.trim() || ''));
16
- }
17
- }
18
- input.annotations.forEach((v, i)=>normalize(v, {
19
- path: [
20
- ...path,
21
- i
22
- ],
23
- level: level + 1
24
- }));
25
- resolveBBox(input);
26
- // can get bbox from annotations
27
- let first = input.annotations.find((v)=>v.xyxy)?.xyxy;
28
- if (!input.xyxy && first) {
29
- const xyxy = input.annotations.reduce((acc, v)=>{
30
- if (!v.xyxy) return acc;
31
- return [
32
- Math.min(acc[0], v.xyxy[0]),
33
- Math.min(acc[1], v.xyxy[1]),
34
- Math.max(acc[2], v.xyxy[2]),
35
- Math.max(acc[3], v.xyxy[3])
36
- ];
37
- }, first);
38
- input.xyxy = xyxy;
39
- input.xywh = xyxy2xywh(xyxy);
40
- }
41
- };
42
- const out = input;
43
- normalize(out);
44
- // out.annotations.forEach((v) => norm(v));
45
- // only merge for root node
46
- if (!out.markdown) {
47
- out.markdown = out.annotations.map((v)=>v.markdown).join('\n');
48
- out.markdown ||= undefined;
49
- }
50
- if (!out.text) {
51
- out.text = out.annotations.map((v)=>v.text).join('\n');
52
- out.text ||= undefined;
53
- }
54
- // fallback
55
- out.text ||= out.markdown;
56
- out.markdown ||= out.text;
57
- return out;
3
+ const normalize = (input, { path = [], level = 0 } = {}) => {
4
+ input.id ||= path.join('.') || 'ROOT';
5
+ input.annotations ||= [];
6
+ input.tags ||= [];
7
+ input.attributes ||= {};
8
+ input.metadata ||= {};
9
+ if (!input.csv && input.html?.includes('<table') && globalThis.DOMParser) {
10
+ const parser = new DOMParser();
11
+ const doc = parser.parseFromString(input.html, 'text/html');
12
+ const table = doc.querySelector('table');
13
+ if (table) {
14
+ const rows = Array.from(table.querySelectorAll('tr'));
15
+ input.data = rows.map((row) =>
16
+ Array.from(row.querySelectorAll('td')).map((td) => td.textContent?.trim() || ''),
17
+ );
18
+ }
19
+ }
20
+ input.annotations.forEach((v, i) =>
21
+ normalize(v, {
22
+ path: [...path, i],
23
+ level: level + 1,
24
+ }),
25
+ );
26
+ resolveBBox(input);
27
+ // can get bbox from annotations
28
+ let first = input.annotations.find((v) => v.xyxy)?.xyxy;
29
+ if (!input.xyxy && first) {
30
+ const xyxy = input.annotations.reduce((acc, v) => {
31
+ if (!v.xyxy) return acc;
32
+ return [
33
+ Math.min(acc[0], v.xyxy[0]),
34
+ Math.min(acc[1], v.xyxy[1]),
35
+ Math.max(acc[2], v.xyxy[2]),
36
+ Math.max(acc[3], v.xyxy[3]),
37
+ ];
38
+ }, first);
39
+ input.xyxy = xyxy;
40
+ input.xywh = xyxy2xywh(xyxy);
41
+ }
42
+ };
43
+ const out = input;
44
+ normalize(out);
45
+ // out.annotations.forEach((v) => norm(v));
46
+ // only merge for root node
47
+ if (!out.markdown) {
48
+ out.markdown = out.annotations.map((v) => v.markdown).join('\n');
49
+ out.markdown ||= undefined;
50
+ }
51
+ if (!out.text) {
52
+ out.text = out.annotations.map((v) => v.text).join('\n');
53
+ out.text ||= undefined;
54
+ }
55
+ // fallback
56
+ out.text ||= out.markdown;
57
+ out.markdown ||= out.text;
58
+ return out;
58
59
  }
59
60
  function xywh2xyxy(input) {
60
- if (!input) return;
61
- const [x, y, w, h] = input;
62
- return [
63
- x,
64
- y,
65
- x + w,
66
- y + h
67
- ];
61
+ if (!input) return;
62
+ const [x, y, w, h] = input;
63
+ return [x, y, x + w, y + h];
68
64
  }
69
65
  function xyxy2xywh(input) {
70
- if (!input) return;
71
- const [x1, y1, x2, y2] = input;
72
- return [
73
- x1,
74
- y1,
75
- x2 - x1,
76
- y2 - y1
77
- ];
66
+ if (!input) return;
67
+ const [x1, y1, x2, y2] = input;
68
+ return [x1, y1, x2 - x1, y2 - y1];
78
69
  }
79
70
  function resolveBBox(input) {
80
- let { x, y, w, h } = input;
81
- let isNil = (v)=>v === undefined || v === null;
82
- if (isNil(x) && input.xywh?.length) {
83
- [x, y, w, h] = input.xywh;
84
- }
85
- if (isNil(x) && input.xyxy?.length) {
86
- [x, y, w, h] = xyxy2xywh(input.xyxy);
87
- }
88
- if (!isNil(x)) {
89
- input.xywh ||= [
90
- x,
91
- y,
92
- w,
93
- h
94
- ];
95
- input.xyxy ||= xywh2xyxy(input.xywh);
96
- input.x = x;
97
- input.y = y;
98
- input.w = w;
99
- input.h = h;
100
- return input;
101
- }
102
- return;
71
+ let { x, y, w, h } = input;
72
+ let isNil = (v) => v === undefined || v === null;
73
+ if (isNil(x) && input.xywh?.length) {
74
+ [x, y, w, h] = input.xywh;
75
+ }
76
+ if (isNil(x) && input.xyxy?.length) {
77
+ [x, y, w, h] = xyxy2xywh(input.xyxy);
78
+ }
79
+ if (!isNil(x)) {
80
+ input.xywh ||= [x, y, w, h];
81
+ input.xyxy ||= xywh2xyxy(input.xywh);
82
+ input.x = x;
83
+ input.y = y;
84
+ input.w = w;
85
+ input.h = h;
86
+ return input;
87
+ }
88
+ return;
103
89
  }
104
90
 
105
- //# sourceMappingURL=resolveImageAnnotation.js.map
91
+ //# sourceMappingURL=resolveImageAnnotation.js.map
@@ -1,48 +1,62 @@
1
- import { z } from "zod/v4";
2
- import { SexType, SexTypeSchema } from "../foundation/schema/index.js";
3
- import { Mod11 } from "./Mod11.js";
4
- export const ChineseResidentIdNoRegex = /^(?<division>[1-9]\d{5})(?<year>(18|19|20)\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\d|3[01])(?<sequence>\d{3})(?<checkDigit>[0-9Xx])$/;
5
- export const ParsedChineseResidentIdNoSchema = z.object({
6
- raw: z.string().regex(ChineseResidentIdNoRegex, "\u65E0\u6548\u768418\u4F4D\u8EAB\u4EFD\u8BC1\u53F7\u7801\u683C\u5F0F").describe("\u8EAB\u4EFD\u8BC1\u53F7\u7801"),
7
- addressCode: z.string().length(6).describe("\u5730\u5740\u7801 "),
8
- birthDate: z.iso.date().describe("\u51FA\u751F\u65E5\u671F"),
9
- sequence: z.int().max(999).min(0).describe("\u987A\u5E8F\u7801"),
10
- checkDigit: z.int().min(0).max(10).describe("\u6821\u9A8C\u7801"),
11
- sex: SexTypeSchema.describe("\u6027\u522B"),
12
- age: z.number().optional(),
13
- valid: z.boolean().optional().describe("\u662F\u5426\u6709\u6548")
14
- }).describe("\u5C45\u6C11\u8EAB\u4EFD\u8BC1\u53F7\u7801\u89E3\u6790\u5185\u5BB9");
1
+ import { z } from 'zod/v4';
2
+ import { SexType, SexTypeSchema } from '../foundation/schema/index.js';
3
+ import { Mod11 } from './Mod11.js';
4
+ export const ChineseResidentIdNoRegex =
5
+ /^(?<division>[1-9]\d{5})(?<year>(18|19|20)\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\d|3[01])(?<sequence>\d{3})(?<checkDigit>[0-9Xx])$/;
6
+ export const ParsedChineseResidentIdNoSchema = z
7
+ .object({
8
+ raw: z
9
+ .string()
10
+ .regex(ChineseResidentIdNoRegex, '\u65E0\u6548\u768418\u4F4D\u8EAB\u4EFD\u8BC1\u53F7\u7801\u683C\u5F0F')
11
+ .describe('\u8EAB\u4EFD\u8BC1\u53F7\u7801'),
12
+ addressCode: z.string().length(6).describe('\u5730\u5740\u7801 '),
13
+ birthDate: z.iso.date().describe('\u51FA\u751F\u65E5\u671F'),
14
+ sequence: z.int().max(999).min(0).describe('\u987A\u5E8F\u7801'),
15
+ checkDigit: z.int().min(0).max(10).describe('\u6821\u9A8C\u7801'),
16
+ sex: SexTypeSchema.describe('\u6027\u522B'),
17
+ age: z.number().optional(),
18
+ valid: z.boolean().optional().describe('\u662F\u5426\u6709\u6548'),
19
+ })
20
+ .describe('\u5C45\u6C11\u8EAB\u4EFD\u8BC1\u53F7\u7801\u89E3\u6790\u5185\u5BB9');
15
21
  export function parseChineseResidentIdNo(idNo) {
16
- const reg = ChineseResidentIdNoRegex;
17
- const match = idNo.match(reg);
18
- if (!match || !match.groups) {
19
- return undefined;
20
- }
21
- const { division, year, month, day, sequence, checkDigit } = match.groups;
22
- let seq = parseInt(sequence, 10);
23
- return {
24
- raw: idNo,
25
- addressCode: division,
26
- birthDate: `${year}-${month}-${day}`,
27
- sequence: seq,
28
- checkDigit: checkDigit.toUpperCase() === "X" ? 10 : parseInt(checkDigit, 10),
29
- sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
30
- age: new Date().getFullYear() - parseInt(year, 10),
31
- valid: Mod11.validate(idNo)
32
- };
22
+ const reg = ChineseResidentIdNoRegex;
23
+ const match = idNo.match(reg);
24
+ if (!match || !match.groups) {
25
+ return undefined;
26
+ }
27
+ const { division, year, month, day, sequence, checkDigit } = match.groups;
28
+ let seq = parseInt(sequence, 10);
29
+ return {
30
+ raw: idNo,
31
+ addressCode: division,
32
+ birthDate: `${year}-${month}-${day}`,
33
+ sequence: seq,
34
+ checkDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit, 10),
35
+ sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
36
+ age: new Date().getFullYear() - parseInt(year, 10),
37
+ valid: Mod11.validate(idNo),
38
+ };
33
39
  }
34
40
  export function formatChineseResidentIdNo({ addressCode, birthDate, sequence, checkDigit }) {
35
- const date = typeof birthDate === "string" ? birthDate.replace(/-/g, "") : `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, "0")}${String(birthDate.getDate()).padStart(2, "0")}`;
36
- const seq = String(sequence).padStart(3, "0");
37
- const major = `${addressCode}${date}${seq}`;
38
- const check = typeof checkDigit === "number" ? checkDigit === 10 ? "X" : String(checkDigit) : checkDigit?.toUpperCase() || Mod11.compute(major);
39
- return `${major}${check}`;
41
+ const date =
42
+ typeof birthDate === 'string'
43
+ ? birthDate.replace(/-/g, '')
44
+ : `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, '0')}${String(birthDate.getDate()).padStart(2, '0')}`;
45
+ const seq = String(sequence).padStart(3, '0');
46
+ const major = `${addressCode}${date}${seq}`;
47
+ const check =
48
+ typeof checkDigit === 'number'
49
+ ? checkDigit === 10
50
+ ? 'X'
51
+ : String(checkDigit)
52
+ : checkDigit?.toUpperCase() || Mod11.compute(major);
53
+ return `${major}${check}`;
40
54
  }
41
- (function (ChineseResidentIdNo) {
42
- ChineseResidentIdNo.regex = ChineseResidentIdNoRegex;
43
- ChineseResidentIdNo.parse = parseChineseResidentIdNo;
44
- ChineseResidentIdNo.format = formatChineseResidentIdNo;
45
- ChineseResidentIdNo.ResultSchema = ParsedChineseResidentIdNoSchema;
55
+ ((ChineseResidentIdNo) => {
56
+ ChineseResidentIdNo.regex = ChineseResidentIdNoRegex;
57
+ ChineseResidentIdNo.parse = parseChineseResidentIdNo;
58
+ ChineseResidentIdNo.format = formatChineseResidentIdNo;
59
+ ChineseResidentIdNo.ResultSchema = ParsedChineseResidentIdNoSchema;
46
60
  })(ChineseResidentIdNo || (ChineseResidentIdNo = {}));
47
61
  export var ChineseResidentIdNo;
48
62
  //# sourceMappingURL=ChineseResidentIdNo.js.map
@@ -1 +1,6 @@
1
- export { ChineseResidentIdNoRegex as regex, parseChineseResidentIdNo as parse, formatChineseResidentIdNo as format, ParsedChineseResidentIdNoSchema as ResultSchema } from "./ChineseResidentIdNo.js";
1
+ export {
2
+ ChineseResidentIdNoRegex as regex,
3
+ formatChineseResidentIdNo as format,
4
+ ParsedChineseResidentIdNoSchema as ResultSchema,
5
+ parseChineseResidentIdNo as parse,
6
+ } from './ChineseResidentIdNo.js';
@@ -1,22 +1,23 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ChineseResidentIdNo } from "./index.js";
3
- describe("ChineseResidentIdNo", function () {
4
- it("should parse", function () {
5
- for (var _i = 0, _iter = [
6
- "11010519491231002X"
7
- ]; _i < _iter.length; _i++) {
8
- var a = _iter[_i];
9
- var out = ChineseResidentIdNo.parse(a);
10
- expect(out).toBeTruthy();
11
- expect(ChineseResidentIdNo.format(out)).toBe(a);
12
- expect(out).toMatchSnapshot();
13
- }
14
- });
15
- it("should format with partial", function () {
16
- expect(ChineseResidentIdNo.format({
17
- addressCode: "110105",
18
- birthDate: new Date("1949-12-31"),
19
- sequence: 2
20
- })).toBe("11010519491231002X");
21
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ChineseResidentIdNo } from './index.js';
3
+
4
+ describe('ChineseResidentIdNo', () => {
5
+ it('should parse', () => {
6
+ for (var _i = 0, _iter = ['11010519491231002X']; _i < _iter.length; _i++) {
7
+ var a = _iter[_i];
8
+ var out = ChineseResidentIdNo.parse(a);
9
+ expect(out).toBeTruthy();
10
+ expect(ChineseResidentIdNo.format(out)).toBe(a);
11
+ expect(out).toMatchSnapshot();
12
+ }
13
+ });
14
+ it('should format with partial', () => {
15
+ expect(
16
+ ChineseResidentIdNo.format({
17
+ addressCode: '110105',
18
+ birthDate: new Date('1949-12-31'),
19
+ sequence: 2,
20
+ }),
21
+ ).toBe('11010519491231002X');
22
+ });
22
23
  });