zelos-recad 0.1.0 → 0.2.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/README.md +18 -5
- package/UPSTREAM-LICENSE +21 -21
- package/build-info.json +26 -0
- package/mcp/index.js +2 -1
- package/package.json +22 -10
- package/protocol/src/bundle.d.ts +7 -1
- package/protocol/src/contracts.d.ts +18 -6
- package/protocol/src/contracts.js +20 -7
- package/protocol/src/native-evidence.d.ts +20 -0
- package/service/app.js +4 -2
- package/service/options.d.ts +2 -1
- package/service/options.js +2 -1
- package/shared/build-identity.d.mts +6 -0
- package/shared/build-identity.mjs +63 -0
- package/shared/client.d.mts +1 -0
- package/shared/client.mjs +9 -0
- package/shared/command.d.mts +1 -0
- package/shared/command.mjs +22 -4
- package/shared/contracts/src/paths.d.ts +3 -0
- package/shared/contracts/src/paths.js +31 -0
- package/shared/mcp.d.mts +1 -0
- package/shared/service-storage/src/capacity.d.ts +36 -0
- package/shared/service-storage/src/capacity.js +71 -0
- package/shared/service-storage/src/consumption.d.ts +15 -0
- package/shared/service-storage/src/consumption.js +27 -0
- package/shared/service-storage/src/documents.d.ts +43 -0
- package/shared/service-storage/src/documents.js +210 -0
- package/shared/service-storage/src/downloads.d.ts +10 -0
- package/shared/service-storage/src/downloads.js +58 -0
- package/shared/service-storage/src/files.d.ts +18 -0
- package/shared/service-storage/src/files.js +118 -0
- package/shared/service-storage/src/footprint.d.ts +14 -0
- package/shared/service-storage/src/footprint.js +72 -0
- package/shared/service-storage/src/process-temp.d.ts +22 -0
- package/shared/service-storage/src/process-temp.js +181 -0
- package/shared/service-storage/src/quota.d.ts +30 -0
- package/shared/service-storage/src/quota.js +166 -0
- package/shared/service-storage/src/retention.d.ts +38 -0
- package/shared/service-storage/src/retention.js +148 -0
- package/shared/service-storage/src/staging.d.ts +15 -0
- package/shared/service-storage/src/staging.js +116 -0
- package/source/README.md +1 -3
- package/source/mcp/index.ts +2 -1
- package/source/package.json +4 -2
- package/source/protocol/src/contracts.ts +20 -7
- package/source/protocol/src/native-evidence.ts +21 -0
- package/source/rebuild.mjs +12 -4
- package/source/service/app.ts +6 -2
- package/source/service/options.ts +3 -2
- package/source/shared/build-identity.d.mts +6 -0
- package/source/shared/build-identity.mjs +63 -0
- package/source/shared/client.d.mts +1 -0
- package/source/shared/client.mjs +9 -0
- package/source/shared/command.d.mts +1 -0
- package/source/shared/command.mjs +22 -4
- package/source/shared/contracts/src/paths.ts +33 -0
- package/source/shared/mcp.d.mts +1 -0
- package/source/shared/service-storage/src/capacity.ts +101 -0
- package/source/shared/service-storage/src/consumption.ts +45 -0
- package/source/shared/service-storage/src/documents.ts +262 -0
- package/source/shared/service-storage/src/downloads.ts +62 -0
- package/source/shared/service-storage/src/files.ts +135 -0
- package/source/shared/service-storage/src/footprint.ts +78 -0
- package/source/shared/service-storage/src/process-temp.ts +205 -0
- package/source/shared/service-storage/src/quota.ts +198 -0
- package/source/shared/service-storage/src/retention.ts +180 -0
- package/source/shared/service-storage/src/staging.ts +106 -0
- package/source/src/application-objects.ts +2 -2
- package/source/src/assets.ts +15 -0
- package/source/src/block-clip.ts +1 -1
- package/source/src/block-metadata.ts +12 -5
- package/source/src/build-info.ts +15 -0
- package/source/src/cad-engine.ts +18 -8
- package/source/src/command.ts +2 -2
- package/source/src/constraints.ts +2 -2
- package/source/src/conversion.ts +2 -0
- package/source/src/dwg-fallback.ts +2 -0
- package/source/src/dwg.ts +7 -0
- package/source/src/dxf-export.ts +3 -3
- package/source/src/dxf.ts +7 -4
- package/source/src/native-evidence.ts +33 -1
- package/source/src/native-segmented-path.ts +22 -35
- package/source/src/point-dictionaries.ts +65 -0
- package/source/src/readback.ts +7 -6
- package/source/src/reader.ts +19 -10
- package/source/src/render-operation.ts +39 -7
- package/source/src/runner.ts +5 -4
- package/source/src/runtime/documents.ts +23 -142
- package/source/src/runtime/index.ts +71 -17
- package/source/src/runtime/jobs.ts +176 -153
- package/source/src/runtime/managed-worker.ts +37 -0
- package/source/src/runtime/storage-policy.ts +39 -0
- package/source/src/runtime/storage.ts +9 -44
- package/source/src/source-scene.ts +125 -23
- package/source/src/text/glyphs.ts +63 -0
- package/source/src/text/ink-bounds.ts +7 -36
- package/source/src/text/scene-geometry.ts +92 -0
- package/source/src/text/source-fonts.ts +31 -0
- package/source/src/vendor-object-data.ts +265 -0
- package/source/src/xref.ts +4 -3
- package/source/tsconfig.json +4 -2
- package/src/application-objects.js +2 -2
- package/src/assets.d.ts +9 -0
- package/src/assets.js +14 -0
- package/src/block-clip.js +1 -1
- package/src/block-metadata.js +11 -5
- package/src/build-info.d.ts +2 -0
- package/src/build-info.js +14 -0
- package/src/cad-engine.js +19 -8
- package/src/command.js +2 -2
- package/src/constraints.js +2 -2
- package/src/conversion.d.ts +2 -0
- package/src/conversion.js +2 -0
- package/src/dwg-fallback.d.ts +1 -0
- package/src/dwg-fallback.js +2 -0
- package/src/dwg.d.ts +3 -0
- package/src/dwg.js +7 -0
- package/src/dxf-export.js +3 -3
- package/src/dxf.d.ts +14 -1
- package/src/dxf.js +7 -3
- package/src/native-evidence.d.ts +33 -1
- package/src/native-evidence.js +33 -0
- package/src/native-segmented-path.js +1 -3
- package/src/point-dictionaries.d.ts +12 -0
- package/src/point-dictionaries.js +88 -0
- package/src/readback.d.ts +12 -4
- package/src/readback.js +7 -6
- package/src/reader.d.ts +12 -1
- package/src/reader.js +22 -11
- package/src/render-operation.js +36 -7
- package/src/runner.js +5 -4
- package/src/runtime/documents.d.ts +8 -20
- package/src/runtime/documents.js +17 -116
- package/src/runtime/index.d.ts +41 -4
- package/src/runtime/index.js +72 -18
- package/src/runtime/jobs.d.ts +21 -2
- package/src/runtime/jobs.js +120 -100
- package/src/runtime/managed-worker.d.ts +8 -0
- package/src/runtime/managed-worker.js +29 -0
- package/src/runtime/storage-policy.d.ts +25 -0
- package/src/runtime/storage-policy.js +29 -0
- package/src/runtime/storage.d.ts +1 -7
- package/src/runtime/storage.js +1 -38
- package/src/source-scene.d.ts +4 -2
- package/src/source-scene.js +136 -20
- package/src/text/glyphs.d.ts +12 -0
- package/src/text/glyphs.js +53 -0
- package/src/text/ink-bounds.d.ts +2 -1
- package/src/text/ink-bounds.js +6 -34
- package/src/text/scene-geometry.d.ts +21 -0
- package/src/text/scene-geometry.js +70 -0
- package/src/text/source-fonts.d.ts +7 -0
- package/src/text/source-fonts.js +30 -0
- package/src/vendor-object-data.d.ts +19 -0
- package/src/vendor-object-data.js +241 -0
- package/src/xref.js +3 -3
- package/vendor/libredwg/COPYING +674 -674
- package/vendor/libredwg/Dockerfile +2 -0
- package/vendor/libredwg/README.md +41 -28
- package/vendor/libredwg/build-local.sh +1 -1
- package/vendor/libredwg/libredwg-web.wasm +0 -0
- package/vendor/libredwg/manifest.json +5 -3
- package/vendor/libredwg/opaque-object-binding.patch +29 -0
- package/vendor/libredwg/rebuild.mjs +2 -1
- package/source/service/README.md +0 -152
- package/source/src/text/UPSTREAM.md +0 -26
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { CadError } from './contracts.ts'
|
|
3
|
+
|
|
4
|
+
/** R14 CC electrical metadata. Every value retains its original bit range;
|
|
5
|
+
* unlabeled scalar slots are preserved without assigning electrical meaning. */
|
|
6
|
+
class PayloadBits {
|
|
7
|
+
position = 0
|
|
8
|
+
constructor(
|
|
9
|
+
readonly bytes: Buffer,
|
|
10
|
+
readonly length: number,
|
|
11
|
+
) {}
|
|
12
|
+
bits(count: number) {
|
|
13
|
+
if (this.position + count > this.length) throw new Error('载荷字段越界')
|
|
14
|
+
let value = 0
|
|
15
|
+
for (let i = 0; i < count; i++) {
|
|
16
|
+
value = value * 2 + ((this.bytes[this.position >> 3]! >> (7 - (this.position & 7))) & 1)
|
|
17
|
+
this.position++
|
|
18
|
+
}
|
|
19
|
+
return value
|
|
20
|
+
}
|
|
21
|
+
bytesValue(count: number) {
|
|
22
|
+
return Buffer.from(Array.from({ length: count }, () => this.bits(8)))
|
|
23
|
+
}
|
|
24
|
+
short() {
|
|
25
|
+
const code = this.bits(2)
|
|
26
|
+
return code === 0
|
|
27
|
+
? this.bytesValue(2).readUInt16LE()
|
|
28
|
+
: code === 1
|
|
29
|
+
? this.bits(8)
|
|
30
|
+
: code === 2
|
|
31
|
+
? 0
|
|
32
|
+
: 256
|
|
33
|
+
}
|
|
34
|
+
long() {
|
|
35
|
+
const code = this.bits(2)
|
|
36
|
+
if (code === 3) throw new Error('无效BL编码')
|
|
37
|
+
return code === 0 ? this.bytesValue(4).readInt32LE() : code === 1 ? this.bits(8) : 0
|
|
38
|
+
}
|
|
39
|
+
text() {
|
|
40
|
+
const size = this.short()
|
|
41
|
+
if (size > 4096) throw new Error('文本长度超过支持范围')
|
|
42
|
+
const value = new TextDecoder('gbk', { fatal: true }).decode(this.bytesValue(size))
|
|
43
|
+
if (/[\u0000-\u0008\u000b-\u001f]/.test(value)) throw new Error('文本含控制字符')
|
|
44
|
+
return value
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const digest = (bytes: Buffer) => createHash('sha256').update(bytes).digest('hex')
|
|
48
|
+
const key = (value: unknown) => String(value || '').toUpperCase()
|
|
49
|
+
|
|
50
|
+
export function parseCcYjInfo(raw: any) {
|
|
51
|
+
const dataBits = raw.rawBitCount - (raw.objectSize * 8 - raw.bitsize),
|
|
52
|
+
reader = new PayloadBits(Buffer.from(raw.rawHex, 'hex'), dataBits)
|
|
53
|
+
const fields: {
|
|
54
|
+
name: string
|
|
55
|
+
encoding: string
|
|
56
|
+
bitStart: number
|
|
57
|
+
bitEnd: number
|
|
58
|
+
value: unknown
|
|
59
|
+
}[] = []
|
|
60
|
+
const field = (name: string, encoding: string, read: () => unknown) => {
|
|
61
|
+
const bitStart = reader.position,
|
|
62
|
+
value = read()
|
|
63
|
+
fields.push({ name, encoding, bitStart, bitEnd: reader.position, value })
|
|
64
|
+
return value
|
|
65
|
+
}
|
|
66
|
+
const version = field('version', 'BL', () => reader.long())
|
|
67
|
+
if (version !== 4) throw new Error('仅已核验CCYjInfoRec版本4')
|
|
68
|
+
field('catalogCode', 'BL', () => reader.long())
|
|
69
|
+
field('optionCode', 'BL', () => reader.long())
|
|
70
|
+
for (const name of [
|
|
71
|
+
'designation',
|
|
72
|
+
'model',
|
|
73
|
+
'textSlot',
|
|
74
|
+
'description',
|
|
75
|
+
'catalogIdentity',
|
|
76
|
+
'materialCode',
|
|
77
|
+
])
|
|
78
|
+
field(name, 'TV/GBK', () => reader.text())
|
|
79
|
+
// Full consumption across the 13 actual records: 3 BS, 2 BL, B, 2 BS.
|
|
80
|
+
// Their business meaning remains unassigned; no terminal or geometry is derived.
|
|
81
|
+
for (let i = 0; i < 3; i++) field('scalar' + (i + 1), 'BS', () => reader.short())
|
|
82
|
+
for (let i = 0; i < 2; i++) field('scalar' + (i + 4), 'BL', () => reader.long())
|
|
83
|
+
field('flag', 'B', () => reader.bits(1))
|
|
84
|
+
for (let i = 0; i < 2; i++) field('tail' + (i + 1), 'BS', () => reader.short())
|
|
85
|
+
if (reader.position !== reader.length) throw new Error('载荷有未消费字段')
|
|
86
|
+
const values = Object.fromEntries(fields.map((f) => [f.name, f.value]))
|
|
87
|
+
if (
|
|
88
|
+
!values.designation ||
|
|
89
|
+
!values.description ||
|
|
90
|
+
!/^[a-f0-9]{32}$/i.test(String(values.catalogIdentity))
|
|
91
|
+
)
|
|
92
|
+
throw new Error('元件信息必需字段缺失')
|
|
93
|
+
return {
|
|
94
|
+
format: 'cc-yj-info/1' as const,
|
|
95
|
+
dataBits,
|
|
96
|
+
fields,
|
|
97
|
+
values,
|
|
98
|
+
uninterpretedFields: [
|
|
99
|
+
'catalogCode',
|
|
100
|
+
'optionCode',
|
|
101
|
+
'textSlot',
|
|
102
|
+
'catalogIdentity',
|
|
103
|
+
'materialCode',
|
|
104
|
+
'scalar1',
|
|
105
|
+
'scalar2',
|
|
106
|
+
'scalar3',
|
|
107
|
+
'scalar4',
|
|
108
|
+
'scalar5',
|
|
109
|
+
'flag',
|
|
110
|
+
'tail1',
|
|
111
|
+
'tail2',
|
|
112
|
+
],
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Capture bounded raw records before freeing native memory. Unknown root data
|
|
117
|
+
* stays opaque and retains its original decoder failure; it never authorizes a block. */
|
|
118
|
+
export function captureCcObjects(
|
|
119
|
+
module: any,
|
|
120
|
+
pointer: number,
|
|
121
|
+
source: Buffer,
|
|
122
|
+
sourceSha256: string,
|
|
123
|
+
codepage: number,
|
|
124
|
+
) {
|
|
125
|
+
if (!module.xdtrace_opaque_objects) return []
|
|
126
|
+
if (source.subarray(0, 6).toString('ascii') !== 'AC1014') return []
|
|
127
|
+
return module
|
|
128
|
+
.xdtrace_opaque_objects(pointer)
|
|
129
|
+
.filter((r: any) => ['CCYjInfoRec', 'CCJXTRECORD'].includes(r.type))
|
|
130
|
+
.map((raw: any) => {
|
|
131
|
+
const fail = (message: string): never => {
|
|
132
|
+
throw new CadError('DWG_VENDOR_DATA', message, { type: raw.type, handle: raw.handle })
|
|
133
|
+
}
|
|
134
|
+
if (codepage !== 39) fail('当前私有载荷仅核验R14 ANSI936编码')
|
|
135
|
+
if (
|
|
136
|
+
!raw.owner ||
|
|
137
|
+
raw.owner === '0' ||
|
|
138
|
+
raw.extension !== '0' ||
|
|
139
|
+
raw.eedCount !== 0 ||
|
|
140
|
+
raw.decodeError !== 4 ||
|
|
141
|
+
!Array.isArray(raw.reactors) ||
|
|
142
|
+
raw.reactors.some((r: string) => r !== raw.owner)
|
|
143
|
+
)
|
|
144
|
+
fail('私有对象公共字段未通过核验')
|
|
145
|
+
if (
|
|
146
|
+
!Number.isSafeInteger(raw.objectAddress) ||
|
|
147
|
+
!Number.isInteger(raw.objectSize) ||
|
|
148
|
+
raw.objectSize < 1 ||
|
|
149
|
+
raw.objectAddress < 0 ||
|
|
150
|
+
raw.objectAddress + raw.objectSize > source.length ||
|
|
151
|
+
!Number.isInteger(raw.rawBitCount) ||
|
|
152
|
+
raw.rawBitCount < 1 ||
|
|
153
|
+
raw.rawBitCount > raw.objectSize * 8 ||
|
|
154
|
+
!Number.isInteger(raw.bitsize) ||
|
|
155
|
+
raw.bitsize > raw.objectSize * 8 ||
|
|
156
|
+
raw.rawBitCount - (raw.objectSize * 8 - raw.bitsize) < 1 ||
|
|
157
|
+
!/^[a-f0-9]+$/.test(raw.rawHex) ||
|
|
158
|
+
raw.rawHex.length !== Math.ceil(raw.rawBitCount / 8) * 2
|
|
159
|
+
)
|
|
160
|
+
fail('私有对象位流范围不完整')
|
|
161
|
+
const bytes = Buffer.from(raw.rawHex, 'hex'),
|
|
162
|
+
original = source.subarray(raw.objectAddress, raw.objectAddress + raw.objectSize),
|
|
163
|
+
start = raw.objectSize * 8 - raw.rawBitCount
|
|
164
|
+
// LibreDWG bit_read_bits stores final partial bits in arrival order at bit 0, 1, ...
|
|
165
|
+
for (let i = 0; i < raw.rawBitCount; i++) {
|
|
166
|
+
const last = i >> 3 === bytes.length - 1,
|
|
167
|
+
shift = last && raw.rawBitCount % 8 ? i % 8 : 7 - (i % 8)
|
|
168
|
+
if (
|
|
169
|
+
((bytes[i >> 3]! >> shift) & 1) !==
|
|
170
|
+
((original[(start + i) >> 3]! >> (7 - ((start + i) % 8))) & 1)
|
|
171
|
+
)
|
|
172
|
+
fail('私有对象载荷与原DWG位流不一致')
|
|
173
|
+
}
|
|
174
|
+
let decoded: ReturnType<typeof parseCcYjInfo> | undefined
|
|
175
|
+
if (raw.type === 'CCYjInfoRec') {
|
|
176
|
+
try {
|
|
177
|
+
decoded = parseCcYjInfo(raw)
|
|
178
|
+
} catch (e) {
|
|
179
|
+
fail(String(e))
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
...raw,
|
|
184
|
+
sourceSha256,
|
|
185
|
+
sourceVersion: 'AC1014',
|
|
186
|
+
codepage,
|
|
187
|
+
executed: false,
|
|
188
|
+
rawSha256: digest(bytes),
|
|
189
|
+
sourceRecordHex: original.toString('hex'),
|
|
190
|
+
sourceRecordSha256: digest(original),
|
|
191
|
+
rawEncoding: 'full bytes MSB-first; final partial byte LSB-first',
|
|
192
|
+
disposition: decoded ? 'retained-data' : 'retained-opaque',
|
|
193
|
+
...(decoded
|
|
194
|
+
? { decoded }
|
|
195
|
+
: {
|
|
196
|
+
semanticStatus: 'needs_review',
|
|
197
|
+
reason: 'CCJXTRECORD载荷含义尚未核验;原始记录完整保留',
|
|
198
|
+
}),
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function validateCcOwnership(records: any[], model: any) {
|
|
204
|
+
const dicts = model.objects.DICTIONARY,
|
|
205
|
+
entities = [
|
|
206
|
+
...model.entities,
|
|
207
|
+
...model.tables.BLOCK_RECORD.entries.flatMap((b: any) => b.entities),
|
|
208
|
+
]
|
|
209
|
+
for (const record of records.filter((r) => ['CCYjInfoRec', 'CCJXTRECORD'].includes(r.type))) {
|
|
210
|
+
const ownership = [],
|
|
211
|
+
seen = new Set<string>()
|
|
212
|
+
let child = record.handle,
|
|
213
|
+
owner = record.owner
|
|
214
|
+
for (;;) {
|
|
215
|
+
const matches = dicts.filter((d: any) => key(d.handle) === owner)
|
|
216
|
+
if (!matches.length) break
|
|
217
|
+
const dictionary = matches[0],
|
|
218
|
+
names = Object.entries(dictionary.entries).filter(([, target]) => key(target) === child)
|
|
219
|
+
if (matches.length !== 1 || seen.has(owner) || seen.size >= 64 || names.length !== 1)
|
|
220
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '私有对象字典链不唯一或循环', {
|
|
221
|
+
handle: record.handle,
|
|
222
|
+
})
|
|
223
|
+
seen.add(owner)
|
|
224
|
+
ownership.push({
|
|
225
|
+
dictionaryHandle: owner,
|
|
226
|
+
ownerHandle: key(dictionary.ownerHandle),
|
|
227
|
+
key: names[0]![0],
|
|
228
|
+
childHandle: child,
|
|
229
|
+
hardOwner: dictionary.isHardOwner,
|
|
230
|
+
})
|
|
231
|
+
child = owner
|
|
232
|
+
owner = key(dictionary.ownerHandle)
|
|
233
|
+
}
|
|
234
|
+
record.ownership = ownership
|
|
235
|
+
}
|
|
236
|
+
for (const record of records.filter((r) => r.type === 'CCYjInfoRec')) {
|
|
237
|
+
const owner = dicts.find((d: any) => key(d.handle) === record.owner),
|
|
238
|
+
entries = owner && Object.entries(owner.entries),
|
|
239
|
+
insert = owner && entities.find((e: any) => key(e.handle) === key(owner.ownerHandle))
|
|
240
|
+
if (
|
|
241
|
+
!owner ||
|
|
242
|
+
entries.length !== 1 ||
|
|
243
|
+
entries[0][0] !== 'YJINFO' ||
|
|
244
|
+
key(entries[0][1]) !== record.handle ||
|
|
245
|
+
!insert ||
|
|
246
|
+
insert.type !== 'INSERT' ||
|
|
247
|
+
key(insert.ownerDictionaryHardId) !== record.owner
|
|
248
|
+
)
|
|
249
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '元件信息需要唯一YJINFO字典及对应INSERT', {
|
|
250
|
+
handle: record.handle,
|
|
251
|
+
})
|
|
252
|
+
const tags =
|
|
253
|
+
insert.xdata
|
|
254
|
+
?.filter((x: any) => x.appName === 'YJDH')
|
|
255
|
+
.flatMap((x: any) =>
|
|
256
|
+
x.value.filter((v: any) => v.code === 1000).map((v: any) => v.value),
|
|
257
|
+
) || []
|
|
258
|
+
if (tags.length !== 1 || tags[0] !== record.decoded.values.designation)
|
|
259
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '元件信息编号与所属块XDATA不一致', {
|
|
260
|
+
handle: record.handle,
|
|
261
|
+
})
|
|
262
|
+
record.dictionaryKey = 'YJINFO'
|
|
263
|
+
record.attachedTo = key(insert.handle)
|
|
264
|
+
}
|
|
265
|
+
}
|
package/source/src/xref.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadResourceManifest, validateXrefManifest } from './resource-manifest.ts'
|
|
2
|
-
import { statSync } from 'node:fs'
|
|
3
|
-
import {
|
|
2
|
+
import { readFileSync, statSync } from 'node:fs'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { createRequire } from 'node:module'
|
|
6
6
|
import { CadError, resourceSchema } from './contracts.ts'
|
|
@@ -144,7 +144,8 @@ export async function bindXrefs(root: Drawing, manifestFile?: string, readback =
|
|
|
144
144
|
}
|
|
145
145
|
await visit(root, undefined, new Set([root.sourcePath]))
|
|
146
146
|
for (const [file, hash] of loaded)
|
|
147
|
-
if (
|
|
147
|
+
if (createHash('sha256').update(readFileSync(file)).digest('hex') !== hash)
|
|
148
|
+
throw new CadError('RESOURCE_CHANGED', '处理期间外部参照发生变化')
|
|
148
149
|
return receipts
|
|
149
150
|
}
|
|
150
151
|
|
package/source/tsconfig.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2023",
|
|
4
|
+
"newLine": "lf",
|
|
4
5
|
"module": "NodeNext",
|
|
5
6
|
"moduleResolution": "NodeNext",
|
|
6
7
|
"strict": true,
|
|
@@ -21,7 +22,8 @@
|
|
|
21
22
|
"include": [
|
|
22
23
|
"src/**/*.ts",
|
|
23
24
|
"service/**/*.ts",
|
|
24
|
-
"protocol
|
|
25
|
-
"mcp/**/*.ts"
|
|
25
|
+
"protocol/**/*.ts",
|
|
26
|
+
"mcp/**/*.ts",
|
|
27
|
+
"shared/**/*.ts"
|
|
26
28
|
]
|
|
27
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
2
|
import { CadError } from "./contracts.js";
|
|
3
3
|
/** Retain application data without executing AutoLISP. Tianzheng configuration
|
|
4
4
|
* is an explicit omission; other unknown object classes still fail natively. */
|
|
@@ -34,7 +34,7 @@ export function captureApplicationObjects(module, pointer, sourceSha256) {
|
|
|
34
34
|
...record,
|
|
35
35
|
sourceSha256,
|
|
36
36
|
executed: false,
|
|
37
|
-
rawSha256: sha256(Buffer.from(record.rawHex, 'hex')),
|
|
37
|
+
rawSha256: createHash('sha256').update(Buffer.from(record.rawHex, 'hex')).digest('hex'),
|
|
38
38
|
};
|
|
39
39
|
});
|
|
40
40
|
}
|
package/src/assets.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { getRecadBuildInfo } from './build-info.js';
|
|
2
|
+
/** Installed resource locations; callers keep their data and Python environment outside the package. */
|
|
3
|
+
export declare function getRecadAssets(): {
|
|
4
|
+
fontsDir: string;
|
|
5
|
+
fontManifest: string;
|
|
6
|
+
substitutions: string;
|
|
7
|
+
requirements: string;
|
|
8
|
+
decoderManifest: string;
|
|
9
|
+
};
|
package/src/assets.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { moduleRoot } from "./runtime-paths.js";
|
|
3
|
+
export { getRecadBuildInfo } from "./build-info.js";
|
|
4
|
+
/** Installed resource locations; callers keep their data and Python environment outside the package. */
|
|
5
|
+
export function getRecadAssets() {
|
|
6
|
+
const fontsDir = path.join(moduleRoot, 'assets', 'fonts');
|
|
7
|
+
return {
|
|
8
|
+
fontsDir,
|
|
9
|
+
fontManifest: path.join(fontsDir, 'manifest.json'),
|
|
10
|
+
substitutions: path.join(fontsDir, 'substitutions.json'),
|
|
11
|
+
requirements: path.join(moduleRoot, 'requirements.txt'),
|
|
12
|
+
decoderManifest: path.join(moduleRoot, 'vendor', 'libredwg', 'manifest.json'),
|
|
13
|
+
};
|
|
14
|
+
}
|
package/src/block-clip.js
CHANGED
|
@@ -205,7 +205,7 @@ export function adaptBlockClips(records, clips, extended, frame, readback, metad
|
|
|
205
205
|
continue;
|
|
206
206
|
const raw = clips.get(id);
|
|
207
207
|
const passive = metadata.get(id);
|
|
208
|
-
if (passive && readback)
|
|
208
|
+
if (passive && readback && (passive.records.length || passive.savedRepresentation || passive.filter))
|
|
209
209
|
throw new CadError('READBACK_BLOCK_METADATA', '最终交付不能保留尚无法独立重放的业务扩展记录:' + id);
|
|
210
210
|
if (!raw && passive && !passive.filter)
|
|
211
211
|
continue;
|
package/src/block-metadata.js
CHANGED
|
@@ -35,7 +35,7 @@ function classify(inserts, objects) {
|
|
|
35
35
|
root.type !== 'DICTIONARY' ||
|
|
36
36
|
key(root.owner) !== key(handle) ||
|
|
37
37
|
root.extension ||
|
|
38
|
-
!root.entries
|
|
38
|
+
!Array.isArray(root.entries) ||
|
|
39
39
|
root.entries.length > 128)
|
|
40
40
|
continue;
|
|
41
41
|
const names = new Set(), refs = new Set();
|
|
@@ -53,9 +53,9 @@ function classify(inserts, objects) {
|
|
|
53
53
|
filter = id;
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
if ((!metadataNames.has(name) && record?.type !== 'VLO-VL') ||
|
|
56
|
+
if ((!metadataNames.has(name) && record?.type !== 'VLO-VL' && !(name === 'YJINFO' && record?.type === 'CCYjInfoRec')) ||
|
|
57
57
|
!record ||
|
|
58
|
-
!['XRECORD', 'VLO-VL'].includes(record.type) ||
|
|
58
|
+
!['XRECORD', 'VLO-VL', 'CCYjInfoRec'].includes(record.type) ||
|
|
59
59
|
key(record.owner) !== key(dictionary) ||
|
|
60
60
|
record.extension ||
|
|
61
61
|
!Array.isArray(record.data) ||
|
|
@@ -91,13 +91,17 @@ function classify(inserts, objects) {
|
|
|
91
91
|
filters.set(key(handle), filter);
|
|
92
92
|
// A filter must still be validated independently, even with known siblings.
|
|
93
93
|
// Only wholly passive dictionaries can authorize an INSERT without a clip.
|
|
94
|
-
if (records.length)
|
|
94
|
+
if (records.length || root.entries.length === 0)
|
|
95
95
|
metadata.set(key(handle), { dictionary: key(dictionary), records, filter });
|
|
96
96
|
}
|
|
97
97
|
return { metadata, filters };
|
|
98
98
|
}
|
|
99
99
|
export function dwgBlockMetadata(model, inserts, extendedObjects, applicationObjects = [], useSavedRepresentation = false) {
|
|
100
100
|
const objects = [
|
|
101
|
+
...applicationObjects.filter(r => r.type === 'CCYjInfoRec' && r.disposition === 'retained-data' && r.decoded?.format === 'cc-yj-info/1').map(r => ({
|
|
102
|
+
type: r.type, handle: r.handle, owner: r.owner, extension: r.extension !== '0',
|
|
103
|
+
data: r.decoded.fields.map((field) => ({ code: typeof field.value === 'string' ? 1 : 90, value: field.value })),
|
|
104
|
+
})),
|
|
101
105
|
...applicationObjects
|
|
102
106
|
.filter((r) => r.type === 'VLO-VL' && r.disposition === 'retained-data')
|
|
103
107
|
.map((r) => ({
|
|
@@ -213,7 +217,9 @@ export function dxfBlockMetadata(records) {
|
|
|
213
217
|
: 'INVALID',
|
|
214
218
|
],
|
|
215
219
|
]
|
|
216
|
-
: [])
|
|
220
|
+
: [350, 360].includes(p.code) && r.pairs[i - 1]?.code !== 3
|
|
221
|
+
? [['INVALID', p.value]]
|
|
222
|
+
: [])
|
|
217
223
|
: undefined,
|
|
218
224
|
data: data?.map(({ code, value }) => ({ code, value })),
|
|
219
225
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { buildIdentity } from '../shared/build-identity.mjs';
|
|
4
|
+
import { moduleRoot } from "./runtime-paths.js";
|
|
5
|
+
let cached;
|
|
6
|
+
export function getRecadBuildInfo() {
|
|
7
|
+
if (!cached) {
|
|
8
|
+
const file = path.join(moduleRoot, 'build-info.json');
|
|
9
|
+
const value = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : buildIdentity(moduleRoot);
|
|
10
|
+
Object.freeze(value.dependencies);
|
|
11
|
+
cached = Object.freeze(value);
|
|
12
|
+
}
|
|
13
|
+
return cached;
|
|
14
|
+
}
|
package/src/cad-engine.js
CHANGED
|
@@ -14,6 +14,7 @@ import { adaptLeaders } from "./leader.js";
|
|
|
14
14
|
import { adaptEmbeddedMText } from "./embedded-mtext.js";
|
|
15
15
|
import { hashFile, writeJson } from "./io.js";
|
|
16
16
|
import { renderCad } from "./render-operation.js";
|
|
17
|
+
import { getRecadBuildInfo } from "./build-info.js";
|
|
17
18
|
// Deliberately conservative until entity-specific visual regression coverage grows.
|
|
18
19
|
const supported = new Set([
|
|
19
20
|
'LINE',
|
|
@@ -43,7 +44,7 @@ export async function runCad(options) {
|
|
|
43
44
|
const started = performance.now();
|
|
44
45
|
const request = requestSchema.parse(options.request);
|
|
45
46
|
const recover = options.recovery === 'best-effort' && request.operation !== 'readback';
|
|
46
|
-
const drawing = await readDrawing(options.source, recover, request.operation === 'scene');
|
|
47
|
+
const drawing = await readDrawing(options.source, recover, request.operation === 'scene', request.operation === 'source-records');
|
|
47
48
|
if (request.operation === 'layouts') {
|
|
48
49
|
const db = drawing.db;
|
|
49
50
|
const spaces = drawingSpaces(db);
|
|
@@ -53,6 +54,7 @@ export async function runCad(options) {
|
|
|
53
54
|
format: 'XDTrace.RecadResult',
|
|
54
55
|
version: 1,
|
|
55
56
|
operation: 'layouts',
|
|
57
|
+
build: getRecadBuildInfo(),
|
|
56
58
|
status: 'inspected',
|
|
57
59
|
sourceSha256: drawing.sourceSha256,
|
|
58
60
|
spaces,
|
|
@@ -186,6 +188,7 @@ export async function runCad(options) {
|
|
|
186
188
|
.filter(([handle]) => activeHandles.has(handle))
|
|
187
189
|
.map(([handle, data]) => ({ handle, ...data })),
|
|
188
190
|
engine: capabilities.dependencies,
|
|
191
|
+
build: getRecadBuildInfo(),
|
|
189
192
|
runtime: { node: process.version, platform: process.platform },
|
|
190
193
|
layout: selection.selected.name,
|
|
191
194
|
spaces: selection.spaces,
|
|
@@ -230,7 +233,7 @@ export async function runCad(options) {
|
|
|
230
233
|
omissions: [
|
|
231
234
|
...unsupportedOmissions,
|
|
232
235
|
...drawing.decodeIssues
|
|
233
|
-
.filter((r) => r.quarantined)
|
|
236
|
+
.filter((r) => r.quarantined && !r.retainedApplicationData)
|
|
234
237
|
.map((r) => ({
|
|
235
238
|
...r,
|
|
236
239
|
sourceSha256,
|
|
@@ -271,21 +274,29 @@ export async function runCad(options) {
|
|
|
271
274
|
artifacts: [],
|
|
272
275
|
verification: { independentCadVerification: false, productionReplacementReady: false },
|
|
273
276
|
};
|
|
274
|
-
if (request.operation === 'readback') {
|
|
275
|
-
if (isDwg)
|
|
277
|
+
if (request.operation === 'readback' || request.operation === 'source-records') {
|
|
278
|
+
if (isDwg && request.operation === 'readback')
|
|
276
279
|
throw new CadError('READBACK_FORMAT', '最终交付核验要求 DXF 输入');
|
|
277
|
-
if (missing.length || warnings.length)
|
|
280
|
+
if ((request.operation === 'readback' ? missing : relevantMissing).length || warnings.length)
|
|
278
281
|
throw new CadError('READBACK_LOSS', '独立重读存在未读取或未支持内容', { missing, warnings });
|
|
279
282
|
for (const style of db.tables.textStyleTable.newIterator()) {
|
|
280
283
|
const font = dxf?.styleFonts.get(String(style.objectId).toUpperCase());
|
|
281
284
|
if (font !== undefined)
|
|
282
285
|
style.fileName = font;
|
|
283
286
|
// DXF STYLE reader stores code 50 in degrees; its writer expects radians.
|
|
284
|
-
|
|
287
|
+
if (!isDwg)
|
|
288
|
+
style.obliquingAngle = (style.obliquingAngle * Math.PI) / 180;
|
|
285
289
|
}
|
|
286
|
-
|
|
290
|
+
if (dxf)
|
|
291
|
+
adaptTextMasks(records, dxf.mtext);
|
|
287
292
|
const file = path.join(options.output, 'readback.json');
|
|
288
|
-
writeJson(file,
|
|
293
|
+
writeJson(file, {
|
|
294
|
+
...readbackSnapshot(db, sourceSha256, dxf?.textSize ?? 2.5, request.operation === 'source-records' ? { block: model, blocks: scope.blocks, layout: selection.selected.name } : undefined),
|
|
295
|
+
...(request.operation === 'source-records' && drawing.applicationObjects.length
|
|
296
|
+
? { applicationObjects: drawing.applicationObjects, blockMetadata: report.blockMetadata } : {}),
|
|
297
|
+
...(request.operation === 'source-records' && drawing.pointDictionaries.length
|
|
298
|
+
? { pointDictionaries: drawing.pointDictionaries } : {}),
|
|
299
|
+
});
|
|
289
300
|
report.status = 'readback';
|
|
290
301
|
report.artifacts.push({
|
|
291
302
|
name: 'readback.json',
|
package/src/command.js
CHANGED
|
@@ -7,13 +7,13 @@ import { createRecadRuntime } from "./runtime/index.js";
|
|
|
7
7
|
import { prepareRecadRuntime } from "./setup.js";
|
|
8
8
|
import { mkdir } from 'node:fs/promises';
|
|
9
9
|
await runDocumentCommand({
|
|
10
|
-
engine: 'recad', startMcp: startRecadMcp,
|
|
10
|
+
engine: 'recad', defaultPorts: { serve: 18771, mcp: 18773 }, startMcp: startRecadMcp,
|
|
11
11
|
async serve(options) {
|
|
12
12
|
if (!['127.0.0.1', 'localhost', '::1'].includes(options.host) && !options.token)
|
|
13
13
|
throw new Error('Set RECAD_TOKEN for external listening');
|
|
14
14
|
const app = createRecadApp({ ...await recadOptions(options), token: options.token });
|
|
15
15
|
try {
|
|
16
|
-
const address = await app.listen({ host: options.host, port: options.port
|
|
16
|
+
const address = await app.listen({ host: options.host, port: options.port });
|
|
17
17
|
return { address, close: () => app.close() };
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
package/src/constraints.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
2
|
import { CadError } from "./contracts.js";
|
|
3
3
|
/** These graphs describe the saved entities. We retain and check the graph;
|
|
4
4
|
* changing parameters or solving constraints is outside the printing API. */
|
|
@@ -63,7 +63,7 @@ export function captureConstraintGroups(module, pointer, sourceSha256, allowSave
|
|
|
63
63
|
evaluation: 'saved-geometry',
|
|
64
64
|
solverExecuted: false,
|
|
65
65
|
requiresEvaluation: group.geometryStatus !== 0,
|
|
66
|
-
rawSha256: sha256(Buffer.from(group.rawHex, 'hex')),
|
|
66
|
+
rawSha256: createHash('sha256').update(Buffer.from(group.rawHex, 'hex')).digest('hex'),
|
|
67
67
|
};
|
|
68
68
|
});
|
|
69
69
|
}
|
package/src/dwg-fallback.d.ts
CHANGED
package/src/dwg-fallback.js
CHANGED
|
@@ -5,7 +5,9 @@ export const drawingArtifacts = [
|
|
|
5
5
|
'print-plan.json',
|
|
6
6
|
'readback.json',
|
|
7
7
|
'scene.json',
|
|
8
|
+
'font-resources.json',
|
|
8
9
|
];
|
|
10
|
+
export const isDrawingArtifact = (name) => drawingArtifacts.includes(name) || /^font-[a-f0-9]{64}\.(ttf|otf|shx)$/.test(name);
|
|
9
11
|
export function cadErrorRecord(error) {
|
|
10
12
|
const e = error;
|
|
11
13
|
return {
|
package/src/dwg.d.ts
CHANGED
|
@@ -19,6 +19,9 @@ export declare function readDwgBytes(lib: any, bytes: ArrayBuffer, module?: any,
|
|
|
19
19
|
* TYPE_MINSERT. Reuse that path without ever casting the different native
|
|
20
20
|
* MINSERT struct to INSERT (their attribute pointers have different offsets). */
|
|
21
21
|
export declare function convertDwgWithArrays(lib: any, pointer: number, quarantined?: any[]): any;
|
|
22
|
+
/** R14 and earlier have no layer plotflag field. The decoder's zero-filled
|
|
23
|
+
* slot is not an authored no-plot decision; that flag was introduced in R2000. */
|
|
24
|
+
export declare function normalizeDwgLayerPlotFlags(model: any, version: string): void;
|
|
22
25
|
/** The pinned JS converter exposes DWG lineweight enum indices, whereas the
|
|
23
26
|
* data model expects DXF hundredths of a millimetre (and negative sentinels). */
|
|
24
27
|
export declare function normalizeDwgLineweights(model: any): void;
|
package/src/dwg.js
CHANGED
|
@@ -153,6 +153,13 @@ export function convertDwgWithArrays(lib, pointer, quarantined = []) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
+
/** R14 and earlier have no layer plotflag field. The decoder's zero-filled
|
|
157
|
+
* slot is not an authored no-plot decision; that flag was introduced in R2000. */
|
|
158
|
+
export function normalizeDwgLayerPlotFlags(model, version) {
|
|
159
|
+
if (/^AC10\d{2}$/.test(version) && Number(version.slice(2)) < 1015)
|
|
160
|
+
for (const layer of model.tables.LAYER.entries)
|
|
161
|
+
layer.plotFlag = 1;
|
|
162
|
+
}
|
|
156
163
|
/** The pinned JS converter exposes DWG lineweight enum indices, whereas the
|
|
157
164
|
* data model expects DXF hundredths of a millimetre (and negative sentinels). */
|
|
158
165
|
export function normalizeDwgLineweights(model) {
|
package/src/dxf-export.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import {
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
3
|
import { CadError, CAD_INPUT_LIMITS } from "./contracts.js";
|
|
4
4
|
import { createDwgDecoder, dwgErrorFlags, readDwgBytes } from "./dwg.js";
|
|
5
5
|
import { captureConstraintGroups } from "./constraints.js";
|
|
@@ -338,7 +338,7 @@ export async function createNativeDxfCandidate(bytes, diagnostic = false, allowS
|
|
|
338
338
|
const { lib, module, manifest } = await createDwgDecoder();
|
|
339
339
|
const buffer = Uint8Array.from(bytes).buffer;
|
|
340
340
|
const decoded = readDwgBytes(lib, buffer, module, false);
|
|
341
|
-
const sourceSha256 = sha256(bytes);
|
|
341
|
+
const sourceSha256 = createHash('sha256').update(bytes).digest('hex');
|
|
342
342
|
const decode = {
|
|
343
343
|
code: decoded.error,
|
|
344
344
|
flags: dwgErrorFlags(decoded.error),
|
|
@@ -377,7 +377,7 @@ export async function createNativeDxfCandidate(bytes, diagnostic = false, allowS
|
|
|
377
377
|
report: {
|
|
378
378
|
status: decode.code ? 'diagnostic-only' : 'candidate',
|
|
379
379
|
sourceSha256,
|
|
380
|
-
outputSha256: sha256(normalized.bytes),
|
|
380
|
+
outputSha256: createHash('sha256').update(normalized.bytes).digest('hex'),
|
|
381
381
|
decoderRevision: manifest.revision,
|
|
382
382
|
decode,
|
|
383
383
|
constraintGroups,
|
package/src/dxf.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { TextImportFields, MTextImportFields } from './text/imports.js';
|
|
2
2
|
import type { RasterSource } from './raster-image.js';
|
|
3
|
+
type Pair = {
|
|
4
|
+
code: number;
|
|
5
|
+
value: string;
|
|
6
|
+
line: number;
|
|
7
|
+
rawValue?: string;
|
|
8
|
+
};
|
|
9
|
+
type Record = {
|
|
10
|
+
type: string;
|
|
11
|
+
pairs: Pair[];
|
|
12
|
+
section: string;
|
|
13
|
+
};
|
|
3
14
|
/** Validate the DXF envelope and retain source fields omitted by the upstream
|
|
4
15
|
* reader. Changes are confined to its in-memory adapter copy. */
|
|
5
|
-
export declare function inspectDxf(bytes: Buffer): {
|
|
16
|
+
export declare function inspectDxf(bytes: Buffer, retainPointDictionaries?: boolean): {
|
|
17
|
+
pointDictionaryRecords: Record[] | undefined;
|
|
6
18
|
blockMetadata: Map<string, import("./block-metadata.js").BlockMetadata>;
|
|
7
19
|
blockClips: Map<string, import("./block-clip.js").BlockClip>;
|
|
8
20
|
xrefSettings: {
|
|
@@ -40,3 +52,4 @@ export declare function inspectDxf(bytes: Buffer): {
|
|
|
40
52
|
textVerticalAlignments: Map<string, number>;
|
|
41
53
|
mtext: Map<string, MTextImportFields>;
|
|
42
54
|
};
|
|
55
|
+
export {};
|