@file-viewer/eda-orcad 2.0.11

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/LICENSE ADDED
@@ -0,0 +1,160 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work by
47
+ the copyright owner or by an individual or Legal Entity authorized to submit on
48
+ behalf of the copyright owner. For the purposes of this definition, "submitted"
49
+ means any form of electronic, verbal, or written communication sent to the
50
+ Licensor or its representatives, including but not limited to communication on
51
+ electronic mailing lists, source code control systems, and issue tracking systems
52
+ that are managed by, or on behalf of, the Licensor for the purpose of discussing
53
+ and improving the Work, but excluding communication that is conspicuously marked
54
+ or otherwise designated in writing by the copyright owner as "Not a
55
+ Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
+ license to make, have made, use, offer to sell, sell, import, and otherwise
72
+ transfer the Work, where such license applies only to those patent claims
73
+ licensable by such Contributor that are necessarily infringed by their
74
+ Contribution(s) alone or by combination of their Contribution(s) with the Work to
75
+ which such Contribution(s) was submitted. If You institute patent litigation
76
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
77
+ alleging that the Work or a Contribution incorporated within the Work
78
+ constitutes direct or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate as of the date
80
+ such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
83
+ Derivative Works thereof in any medium, with or without modifications, and in
84
+ Source or Object form, provided that You meet the following conditions:
85
+
86
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
87
+ this License; and
88
+
89
+ (b) You must cause any modified files to carry prominent notices stating that
90
+ You changed the files; and
91
+
92
+ (c) You must retain, in the Source form of any Derivative Works that You
93
+ distribute, all copyright, patent, trademark, and attribution notices from the
94
+ Source form of the Work, excluding those notices that do not pertain to any part
95
+ of the Derivative Works; and
96
+
97
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
+ any Derivative Works that You distribute must include a readable copy of the
99
+ attribution notices contained within such NOTICE file, excluding those notices
100
+ that do not pertain to any part of the Derivative Works, in at least one of the
101
+ following places: within a NOTICE text file distributed as part of the Derivative
102
+ Works; within the Source form or documentation, if provided along with the
103
+ Derivative Works; or, within a display generated by the Derivative Works, if and
104
+ wherever such third-party notices normally appear. The contents of the NOTICE
105
+ file are for informational purposes only and do not modify the License. You may
106
+ add Your own attribution notices within Derivative Works that You distribute,
107
+ alongside or as an addendum to the NOTICE text from the Work, provided that such
108
+ additional attribution notices cannot be construed as modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
+ KIND, either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations and/or
151
+ rights consistent with this License. However, in accepting such obligations, You
152
+ may act only on Your own behalf and on Your sole responsibility, not on behalf of
153
+ any other Contributor, and only if You agree to indemnify, defend, and hold each
154
+ Contributor harmless for any liability incurred by, or claims asserted against,
155
+ such Contributor by reason of your accepting any such warranty or additional
156
+ liability.
157
+
158
+ END OF TERMS AND CONDITIONS
159
+
160
+ Copyright 2026 Flyfish Viewer
package/README.en.md ADDED
@@ -0,0 +1,26 @@
1
+ # @file-viewer/eda-orcad
2
+
3
+ Framework-neutral OrCAD / Allegro binary inspection helpers for Flyfish File Viewer. It provides CFB/OLE2 detection, safe text sampling, hex preview, and string extraction primitives without any UI dependency.
4
+
5
+ ```ts
6
+ import {
7
+ isOrcadCompoundFile,
8
+ collectOrcadStrings,
9
+ decodeOrcadSample,
10
+ } from '@file-viewer/eda-orcad'
11
+
12
+ const bytes = new Uint8Array(buffer)
13
+ const isCfb = isOrcadCompoundFile(bytes)
14
+ const strings = collectOrcadStrings([bytes])
15
+ const sample = decodeOrcadSample(bytes)
16
+ ```
17
+
18
+ ## Scope
19
+
20
+ - Used by `.olb`, `.dra`, `.psm`, `.pad`, and related OrCAD / Allegro proprietary binaries for structural indexing and safe fallback preview.
21
+ - No UI framework and no DOM dependency.
22
+ - Full symbol / footprint geometry parsing remains a separate C++ WASM or staged TypeScript porting path based on OpenOrCadParser / OpenAllegroParser style engines.
23
+
24
+ ## Why This Package Exists
25
+
26
+ The public OrCAD / Allegro file format surface is limited. Keeping binary inspection and future WASM parser boundaries in a separate package lets `@file-viewer/renderer-eda` stay focused on presentation while the engine evolves independently.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @file-viewer/eda-orcad
2
+
3
+ Flyfish File Viewer 的独立 OrCAD / Allegro 二进制检查内核包。它提供 CFB/OLE2 检测、安全文本采样、十六进制预览和字符串抽取等底层能力,不包含 UI。
4
+
5
+ ```ts
6
+ import {
7
+ isOrcadCompoundFile,
8
+ collectOrcadStrings,
9
+ decodeOrcadSample,
10
+ } from '@file-viewer/eda-orcad'
11
+
12
+ const bytes = new Uint8Array(buffer)
13
+ const isCfb = isOrcadCompoundFile(bytes)
14
+ const strings = collectOrcadStrings([bytes])
15
+ const sample = decodeOrcadSample(bytes)
16
+ ```
17
+
18
+ ## 定位
19
+
20
+ - 当前用于 `.olb`、`.dra`、`.psm`、`.pad` 等 OrCAD / Allegro 私有二进制文件的结构索引和安全退化预览。
21
+ - 不依赖 UI 框架,不依赖 DOM,可独立发布、独立回归。
22
+ - 完整符号/封装几何解析会继续沿 OpenOrCadParser / OpenAllegroParser 的 C++ WASM 或 TypeScript 分阶段移植路线推进。
23
+
24
+ ## 为什么单独拆包
25
+
26
+ OrCAD / Allegro 文件格式公开资料有限,强行把 parser 混进 UI renderer 会让后续维护越来越难。本包把二进制检查和后续 WASM 内核边界固定下来,`@file-viewer/renderer-eda` 只负责展示。
@@ -0,0 +1,9 @@
1
+ export declare const ORCAD_CFB_MAGIC: readonly [208, 207, 17, 224, 161, 177, 26, 225];
2
+ export declare const isOrcadCompoundFile: (bytes: Uint8Array) => boolean;
3
+ export declare const cleanupOrcadText: (text: string) => string;
4
+ export declare const looksLikeOrcadText: (bytes: Uint8Array) => boolean;
5
+ export declare const decodeOrcadSample: (bytes: Uint8Array) => string;
6
+ export declare const createOrcadHexPreview: (bytes: Uint8Array) => string;
7
+ export declare const extractOrcadAsciiStrings: (bytes: Uint8Array) => string[];
8
+ export declare const extractOrcadUtf16Strings: (bytes: Uint8Array) => string[];
9
+ export declare const collectOrcadStrings: (chunks: Uint8Array[], maxStrings?: number) => string[];
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ export const ORCAD_CFB_MAGIC = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];
2
+ const MAX_SAMPLE_BYTES = 4096;
3
+ const MAX_HEX_BYTES = 192;
4
+ export const isOrcadCompoundFile = (bytes) => {
5
+ return ORCAD_CFB_MAGIC.every((value, index) => bytes[index] === value);
6
+ };
7
+ export const cleanupOrcadText = (text) => {
8
+ return text
9
+ .replace(/\u0000/g, '')
10
+ .replace(/[^\S\r\n]+/g, ' ')
11
+ .replace(/\r\n/g, '\n')
12
+ .trim();
13
+ };
14
+ export const looksLikeOrcadText = (bytes) => {
15
+ if (!bytes.length) {
16
+ return false;
17
+ }
18
+ const sample = bytes.slice(0, Math.min(bytes.length, MAX_SAMPLE_BYTES));
19
+ let printable = 0;
20
+ let zeroBytes = 0;
21
+ for (const byte of sample) {
22
+ if (byte === 0) {
23
+ zeroBytes += 1;
24
+ }
25
+ if (byte === 9 || byte === 10 || byte === 13 || (byte >= 32 && byte <= 126) || byte >= 0x80) {
26
+ printable += 1;
27
+ }
28
+ }
29
+ return printable / sample.length > 0.82 || zeroBytes / sample.length > 0.25;
30
+ };
31
+ export const decodeOrcadSample = (bytes) => {
32
+ const sample = bytes.slice(0, Math.min(bytes.length, MAX_SAMPLE_BYTES));
33
+ if (!sample.length) {
34
+ return '';
35
+ }
36
+ try {
37
+ let zeroOdd = 0;
38
+ let zeroEven = 0;
39
+ for (let index = 0; index < sample.length; index += 1) {
40
+ if (sample[index] !== 0) {
41
+ continue;
42
+ }
43
+ if (index % 2 === 0) {
44
+ zeroEven += 1;
45
+ }
46
+ else {
47
+ zeroOdd += 1;
48
+ }
49
+ }
50
+ const decoder = zeroOdd > sample.length / 5 && zeroOdd > zeroEven * 2
51
+ ? new TextDecoder('utf-16le', { fatal: false })
52
+ : new TextDecoder('utf-8', { fatal: false });
53
+ return cleanupOrcadText(decoder.decode(sample));
54
+ }
55
+ catch {
56
+ return '';
57
+ }
58
+ };
59
+ export const createOrcadHexPreview = (bytes) => {
60
+ const sample = bytes.slice(0, Math.min(bytes.length, MAX_HEX_BYTES));
61
+ const lines = [];
62
+ for (let offset = 0; offset < sample.length; offset += 16) {
63
+ const row = sample.slice(offset, offset + 16);
64
+ const hex = Array.from(row).map(byte => byte.toString(16).padStart(2, '0')).join(' ');
65
+ const ascii = Array.from(row)
66
+ .map(byte => byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : '.')
67
+ .join('');
68
+ lines.push(`${offset.toString(16).padStart(8, '0')} ${hex.padEnd(47)} ${ascii}`);
69
+ }
70
+ return lines.join('\n');
71
+ };
72
+ export const extractOrcadAsciiStrings = (bytes) => {
73
+ const result = [];
74
+ let current = '';
75
+ for (const byte of bytes) {
76
+ if (byte >= 32 && byte <= 126) {
77
+ current += String.fromCharCode(byte);
78
+ continue;
79
+ }
80
+ if (current.length >= 4) {
81
+ result.push(current);
82
+ }
83
+ current = '';
84
+ }
85
+ if (current.length >= 4) {
86
+ result.push(current);
87
+ }
88
+ return result;
89
+ };
90
+ export const extractOrcadUtf16Strings = (bytes) => {
91
+ const result = [];
92
+ let current = '';
93
+ for (let index = 0; index + 1 < bytes.length; index += 2) {
94
+ const low = bytes[index];
95
+ const high = bytes[index + 1];
96
+ if (high === 0 && low >= 32 && low <= 126) {
97
+ current += String.fromCharCode(low);
98
+ continue;
99
+ }
100
+ if (current.length >= 4) {
101
+ result.push(current);
102
+ }
103
+ current = '';
104
+ }
105
+ if (current.length >= 4) {
106
+ result.push(current);
107
+ }
108
+ return result;
109
+ };
110
+ export const collectOrcadStrings = (chunks, maxStrings = 180) => {
111
+ const seen = new Set();
112
+ const result = [];
113
+ chunks.forEach(chunk => {
114
+ const candidates = [...extractOrcadAsciiStrings(chunk), ...extractOrcadUtf16Strings(chunk)];
115
+ candidates.forEach(item => {
116
+ const cleaned = cleanupOrcadText(item);
117
+ if (!cleaned || cleaned.length < 4 || seen.has(cleaned) || result.length >= maxStrings) {
118
+ return;
119
+ }
120
+ seen.add(cleaned);
121
+ result.push(cleaned);
122
+ });
123
+ });
124
+ return result;
125
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@file-viewer/eda-orcad",
3
+ "version": "2.0.11",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Pure TypeScript OrCAD and Allegro binary inspection helpers for Flyfish File Viewer with CFB detection and safe string extraction.",
7
+ "keywords": [
8
+ "file-viewer",
9
+ "eda",
10
+ "orcad",
11
+ "allegro",
12
+ "olb",
13
+ "dra",
14
+ "psm",
15
+ "pad",
16
+ "wasm",
17
+ "document-preview",
18
+ "file-preview",
19
+ "self-hosted"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
25
+ "author": {
26
+ "name": "Wangyu",
27
+ "email": "wybaby168@gmail.com"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/flyfish-dev/eda-orcad.git",
32
+ "directory": "packages/renderers/eda-orcad"
33
+ },
34
+ "homepage": "https://doc.file-viewer.app/guide/format-fidelity",
35
+ "bugs": {
36
+ "url": "https://github.com/flyfish-dev/eda-orcad/issues"
37
+ },
38
+ "funding": {
39
+ "type": "individual",
40
+ "url": "https://dev.flyfish.group/shop"
41
+ },
42
+ "main": "./dist/index.js",
43
+ "module": "./dist/index.js",
44
+ "types": "./dist/index.d.ts",
45
+ "exports": {
46
+ ".": {
47
+ "types": "./dist/index.d.ts",
48
+ "import": "./dist/index.js",
49
+ "default": "./dist/index.js"
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "README.md",
56
+ "README.en.md",
57
+ "LICENSE"
58
+ ],
59
+ "devDependencies": {
60
+ "typescript": "^6.0.3"
61
+ },
62
+ "license": "Apache-2.0",
63
+ "scripts": {
64
+ "build": "tsc -b tsconfig.json",
65
+ "type-check": "tsc -b tsconfig.json"
66
+ }
67
+ }