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,241 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { CadError } from "./contracts.js";
|
|
3
|
+
/** R14 CC electrical metadata. Every value retains its original bit range;
|
|
4
|
+
* unlabeled scalar slots are preserved without assigning electrical meaning. */
|
|
5
|
+
class PayloadBits {
|
|
6
|
+
bytes;
|
|
7
|
+
length;
|
|
8
|
+
position = 0;
|
|
9
|
+
constructor(bytes, length) {
|
|
10
|
+
this.bytes = bytes;
|
|
11
|
+
this.length = length;
|
|
12
|
+
}
|
|
13
|
+
bits(count) {
|
|
14
|
+
if (this.position + count > this.length)
|
|
15
|
+
throw new Error('载荷字段越界');
|
|
16
|
+
let value = 0;
|
|
17
|
+
for (let i = 0; i < count; i++) {
|
|
18
|
+
value = value * 2 + ((this.bytes[this.position >> 3] >> (7 - (this.position & 7))) & 1);
|
|
19
|
+
this.position++;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
bytesValue(count) {
|
|
24
|
+
return Buffer.from(Array.from({ length: count }, () => this.bits(8)));
|
|
25
|
+
}
|
|
26
|
+
short() {
|
|
27
|
+
const code = this.bits(2);
|
|
28
|
+
return code === 0
|
|
29
|
+
? this.bytesValue(2).readUInt16LE()
|
|
30
|
+
: code === 1
|
|
31
|
+
? this.bits(8)
|
|
32
|
+
: code === 2
|
|
33
|
+
? 0
|
|
34
|
+
: 256;
|
|
35
|
+
}
|
|
36
|
+
long() {
|
|
37
|
+
const code = this.bits(2);
|
|
38
|
+
if (code === 3)
|
|
39
|
+
throw new Error('无效BL编码');
|
|
40
|
+
return code === 0 ? this.bytesValue(4).readInt32LE() : code === 1 ? this.bits(8) : 0;
|
|
41
|
+
}
|
|
42
|
+
text() {
|
|
43
|
+
const size = this.short();
|
|
44
|
+
if (size > 4096)
|
|
45
|
+
throw new Error('文本长度超过支持范围');
|
|
46
|
+
const value = new TextDecoder('gbk', { fatal: true }).decode(this.bytesValue(size));
|
|
47
|
+
if (/[\u0000-\u0008\u000b-\u001f]/.test(value))
|
|
48
|
+
throw new Error('文本含控制字符');
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const digest = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
53
|
+
const key = (value) => String(value || '').toUpperCase();
|
|
54
|
+
export function parseCcYjInfo(raw) {
|
|
55
|
+
const dataBits = raw.rawBitCount - (raw.objectSize * 8 - raw.bitsize), reader = new PayloadBits(Buffer.from(raw.rawHex, 'hex'), dataBits);
|
|
56
|
+
const fields = [];
|
|
57
|
+
const field = (name, encoding, read) => {
|
|
58
|
+
const bitStart = reader.position, value = read();
|
|
59
|
+
fields.push({ name, encoding, bitStart, bitEnd: reader.position, value });
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
const version = field('version', 'BL', () => reader.long());
|
|
63
|
+
if (version !== 4)
|
|
64
|
+
throw new Error('仅已核验CCYjInfoRec版本4');
|
|
65
|
+
field('catalogCode', 'BL', () => reader.long());
|
|
66
|
+
field('optionCode', 'BL', () => reader.long());
|
|
67
|
+
for (const name of [
|
|
68
|
+
'designation',
|
|
69
|
+
'model',
|
|
70
|
+
'textSlot',
|
|
71
|
+
'description',
|
|
72
|
+
'catalogIdentity',
|
|
73
|
+
'materialCode',
|
|
74
|
+
])
|
|
75
|
+
field(name, 'TV/GBK', () => reader.text());
|
|
76
|
+
// Full consumption across the 13 actual records: 3 BS, 2 BL, B, 2 BS.
|
|
77
|
+
// Their business meaning remains unassigned; no terminal or geometry is derived.
|
|
78
|
+
for (let i = 0; i < 3; i++)
|
|
79
|
+
field('scalar' + (i + 1), 'BS', () => reader.short());
|
|
80
|
+
for (let i = 0; i < 2; i++)
|
|
81
|
+
field('scalar' + (i + 4), 'BL', () => reader.long());
|
|
82
|
+
field('flag', 'B', () => reader.bits(1));
|
|
83
|
+
for (let i = 0; i < 2; i++)
|
|
84
|
+
field('tail' + (i + 1), 'BS', () => reader.short());
|
|
85
|
+
if (reader.position !== reader.length)
|
|
86
|
+
throw new Error('载荷有未消费字段');
|
|
87
|
+
const values = Object.fromEntries(fields.map((f) => [f.name, f.value]));
|
|
88
|
+
if (!values.designation ||
|
|
89
|
+
!values.description ||
|
|
90
|
+
!/^[a-f0-9]{32}$/i.test(String(values.catalogIdentity)))
|
|
91
|
+
throw new Error('元件信息必需字段缺失');
|
|
92
|
+
return {
|
|
93
|
+
format: 'cc-yj-info/1',
|
|
94
|
+
dataBits,
|
|
95
|
+
fields,
|
|
96
|
+
values,
|
|
97
|
+
uninterpretedFields: [
|
|
98
|
+
'catalogCode',
|
|
99
|
+
'optionCode',
|
|
100
|
+
'textSlot',
|
|
101
|
+
'catalogIdentity',
|
|
102
|
+
'materialCode',
|
|
103
|
+
'scalar1',
|
|
104
|
+
'scalar2',
|
|
105
|
+
'scalar3',
|
|
106
|
+
'scalar4',
|
|
107
|
+
'scalar5',
|
|
108
|
+
'flag',
|
|
109
|
+
'tail1',
|
|
110
|
+
'tail2',
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Capture bounded raw records before freeing native memory. Unknown root data
|
|
115
|
+
* stays opaque and retains its original decoder failure; it never authorizes a block. */
|
|
116
|
+
export function captureCcObjects(module, pointer, source, sourceSha256, codepage) {
|
|
117
|
+
if (!module.xdtrace_opaque_objects)
|
|
118
|
+
return [];
|
|
119
|
+
if (source.subarray(0, 6).toString('ascii') !== 'AC1014')
|
|
120
|
+
return [];
|
|
121
|
+
return module
|
|
122
|
+
.xdtrace_opaque_objects(pointer)
|
|
123
|
+
.filter((r) => ['CCYjInfoRec', 'CCJXTRECORD'].includes(r.type))
|
|
124
|
+
.map((raw) => {
|
|
125
|
+
const fail = (message) => {
|
|
126
|
+
throw new CadError('DWG_VENDOR_DATA', message, { type: raw.type, handle: raw.handle });
|
|
127
|
+
};
|
|
128
|
+
if (codepage !== 39)
|
|
129
|
+
fail('当前私有载荷仅核验R14 ANSI936编码');
|
|
130
|
+
if (!raw.owner ||
|
|
131
|
+
raw.owner === '0' ||
|
|
132
|
+
raw.extension !== '0' ||
|
|
133
|
+
raw.eedCount !== 0 ||
|
|
134
|
+
raw.decodeError !== 4 ||
|
|
135
|
+
!Array.isArray(raw.reactors) ||
|
|
136
|
+
raw.reactors.some((r) => r !== raw.owner))
|
|
137
|
+
fail('私有对象公共字段未通过核验');
|
|
138
|
+
if (!Number.isSafeInteger(raw.objectAddress) ||
|
|
139
|
+
!Number.isInteger(raw.objectSize) ||
|
|
140
|
+
raw.objectSize < 1 ||
|
|
141
|
+
raw.objectAddress < 0 ||
|
|
142
|
+
raw.objectAddress + raw.objectSize > source.length ||
|
|
143
|
+
!Number.isInteger(raw.rawBitCount) ||
|
|
144
|
+
raw.rawBitCount < 1 ||
|
|
145
|
+
raw.rawBitCount > raw.objectSize * 8 ||
|
|
146
|
+
!Number.isInteger(raw.bitsize) ||
|
|
147
|
+
raw.bitsize > raw.objectSize * 8 ||
|
|
148
|
+
raw.rawBitCount - (raw.objectSize * 8 - raw.bitsize) < 1 ||
|
|
149
|
+
!/^[a-f0-9]+$/.test(raw.rawHex) ||
|
|
150
|
+
raw.rawHex.length !== Math.ceil(raw.rawBitCount / 8) * 2)
|
|
151
|
+
fail('私有对象位流范围不完整');
|
|
152
|
+
const bytes = Buffer.from(raw.rawHex, 'hex'), original = source.subarray(raw.objectAddress, raw.objectAddress + raw.objectSize), start = raw.objectSize * 8 - raw.rawBitCount;
|
|
153
|
+
// LibreDWG bit_read_bits stores final partial bits in arrival order at bit 0, 1, ...
|
|
154
|
+
for (let i = 0; i < raw.rawBitCount; i++) {
|
|
155
|
+
const last = i >> 3 === bytes.length - 1, shift = last && raw.rawBitCount % 8 ? i % 8 : 7 - (i % 8);
|
|
156
|
+
if (((bytes[i >> 3] >> shift) & 1) !==
|
|
157
|
+
((original[(start + i) >> 3] >> (7 - ((start + i) % 8))) & 1))
|
|
158
|
+
fail('私有对象载荷与原DWG位流不一致');
|
|
159
|
+
}
|
|
160
|
+
let decoded;
|
|
161
|
+
if (raw.type === 'CCYjInfoRec') {
|
|
162
|
+
try {
|
|
163
|
+
decoded = parseCcYjInfo(raw);
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
fail(String(e));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
...raw,
|
|
171
|
+
sourceSha256,
|
|
172
|
+
sourceVersion: 'AC1014',
|
|
173
|
+
codepage,
|
|
174
|
+
executed: false,
|
|
175
|
+
rawSha256: digest(bytes),
|
|
176
|
+
sourceRecordHex: original.toString('hex'),
|
|
177
|
+
sourceRecordSha256: digest(original),
|
|
178
|
+
rawEncoding: 'full bytes MSB-first; final partial byte LSB-first',
|
|
179
|
+
disposition: decoded ? 'retained-data' : 'retained-opaque',
|
|
180
|
+
...(decoded
|
|
181
|
+
? { decoded }
|
|
182
|
+
: {
|
|
183
|
+
semanticStatus: 'needs_review',
|
|
184
|
+
reason: 'CCJXTRECORD载荷含义尚未核验;原始记录完整保留',
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
export function validateCcOwnership(records, model) {
|
|
190
|
+
const dicts = model.objects.DICTIONARY, entities = [
|
|
191
|
+
...model.entities,
|
|
192
|
+
...model.tables.BLOCK_RECORD.entries.flatMap((b) => b.entities),
|
|
193
|
+
];
|
|
194
|
+
for (const record of records.filter((r) => ['CCYjInfoRec', 'CCJXTRECORD'].includes(r.type))) {
|
|
195
|
+
const ownership = [], seen = new Set();
|
|
196
|
+
let child = record.handle, owner = record.owner;
|
|
197
|
+
for (;;) {
|
|
198
|
+
const matches = dicts.filter((d) => key(d.handle) === owner);
|
|
199
|
+
if (!matches.length)
|
|
200
|
+
break;
|
|
201
|
+
const dictionary = matches[0], names = Object.entries(dictionary.entries).filter(([, target]) => key(target) === child);
|
|
202
|
+
if (matches.length !== 1 || seen.has(owner) || seen.size >= 64 || names.length !== 1)
|
|
203
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '私有对象字典链不唯一或循环', {
|
|
204
|
+
handle: record.handle,
|
|
205
|
+
});
|
|
206
|
+
seen.add(owner);
|
|
207
|
+
ownership.push({
|
|
208
|
+
dictionaryHandle: owner,
|
|
209
|
+
ownerHandle: key(dictionary.ownerHandle),
|
|
210
|
+
key: names[0][0],
|
|
211
|
+
childHandle: child,
|
|
212
|
+
hardOwner: dictionary.isHardOwner,
|
|
213
|
+
});
|
|
214
|
+
child = owner;
|
|
215
|
+
owner = key(dictionary.ownerHandle);
|
|
216
|
+
}
|
|
217
|
+
record.ownership = ownership;
|
|
218
|
+
}
|
|
219
|
+
for (const record of records.filter((r) => r.type === 'CCYjInfoRec')) {
|
|
220
|
+
const owner = dicts.find((d) => key(d.handle) === record.owner), entries = owner && Object.entries(owner.entries), insert = owner && entities.find((e) => key(e.handle) === key(owner.ownerHandle));
|
|
221
|
+
if (!owner ||
|
|
222
|
+
entries.length !== 1 ||
|
|
223
|
+
entries[0][0] !== 'YJINFO' ||
|
|
224
|
+
key(entries[0][1]) !== record.handle ||
|
|
225
|
+
!insert ||
|
|
226
|
+
insert.type !== 'INSERT' ||
|
|
227
|
+
key(insert.ownerDictionaryHardId) !== record.owner)
|
|
228
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '元件信息需要唯一YJINFO字典及对应INSERT', {
|
|
229
|
+
handle: record.handle,
|
|
230
|
+
});
|
|
231
|
+
const tags = insert.xdata
|
|
232
|
+
?.filter((x) => x.appName === 'YJDH')
|
|
233
|
+
.flatMap((x) => x.value.filter((v) => v.code === 1000).map((v) => v.value)) || [];
|
|
234
|
+
if (tags.length !== 1 || tags[0] !== record.decoded.values.designation)
|
|
235
|
+
throw new CadError('DWG_VENDOR_OWNERSHIP', '元件信息编号与所属块XDATA不一致', {
|
|
236
|
+
handle: record.handle,
|
|
237
|
+
});
|
|
238
|
+
record.dictionaryKey = 'YJINFO';
|
|
239
|
+
record.attachedTo = key(insert.handle);
|
|
240
|
+
}
|
|
241
|
+
}
|
package/src/xref.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadResourceManifest, validateXrefManifest } from "./resource-manifest.js";
|
|
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 } from "./contracts.js";
|
|
@@ -101,7 +101,7 @@ export async function bindXrefs(root, manifestFile, readback = false) {
|
|
|
101
101
|
}
|
|
102
102
|
await visit(root, undefined, new Set([root.sourcePath]));
|
|
103
103
|
for (const [file, hash] of loaded)
|
|
104
|
-
if (
|
|
104
|
+
if (createHash('sha256').update(readFileSync(file)).digest('hex') !== hash)
|
|
105
105
|
throw new CadError('RESOURCE_CHANGED', '处理期间外部参照发生变化');
|
|
106
106
|
return receipts;
|
|
107
107
|
}
|