feat(sign): 支持多位置签名并优化坐标识别与模板版本校验

This commit is contained in:
xy
2026-09-30 18:14:22 +08:00
parent 69825dfa0a
commit e5f0a5ec97
17 changed files with 622 additions and 229 deletions
@@ -230,3 +230,52 @@ export async function fetchSignatureDataUrl(artifact: SigningArtifact): Promise<
return ''
}
}
/** Restore each position from the lossless evidence sheet; legacy images remain supported. */
export async function fetchSignatureImages(
artifact: SigningArtifact,
): Promise<Record<string, string>> {
const source = await fetchSignatureDataUrl(artifact)
if (!source) return {}
const entries = artifact.metadata.signatures
if (!Array.isArray(entries))
return { [String(artifact.metadata.signatureFieldId || 'signature')]: source }
if (!entries.length) return {}
const image = new Image()
image.src = source
await image.decode()
const result: Record<string, string> = {}
for (const entry of entries) {
if (!entry || typeof entry !== 'object') continue
const { field, sourceX, sourceY, imageWidth, imageHeight } = entry
if (
typeof field?.id !== 'string' ||
![sourceX, sourceY, imageWidth, imageHeight].every(Number.isInteger) ||
sourceX < 0 ||
sourceY < 0 ||
imageWidth <= 0 ||
imageHeight <= 0 ||
sourceX + imageWidth > image.naturalWidth ||
sourceY + imageHeight > image.naturalHeight
)
continue
const canvas = document.createElement('canvas')
canvas.width = imageWidth
canvas.height = imageHeight
const context = canvas.getContext('2d')
if (!context) continue
context.drawImage(
image,
sourceX,
sourceY,
imageWidth,
imageHeight,
0,
0,
imageWidth,
imageHeight,
)
result[field.id] = canvas.toDataURL('image/png')
}
return result
}