@file-viewer/eda-layout 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,30 @@
1
+ # @file-viewer/eda-layout
2
+
3
+ Framework-neutral EDA layout inspection engine for Flyfish File Viewer. It exposes pure TypeScript APIs for standard GDSII record parsing, GDSII WebGL draw-batch generation, readable OASIS text-fixture parsing, and real binary OASIS upgrade boundaries without any UI dependency.
4
+
5
+ ```ts
6
+ import {
7
+ parseGdsLayout,
8
+ parseOasisTextLayout,
9
+ createEdaLayoutWebglBatch,
10
+ inspectOasisLayout,
11
+ } from '@file-viewer/eda-layout'
12
+
13
+ const layout = parseGdsLayout(new Uint8Array(buffer))
14
+ const batch = layout ? createEdaLayoutWebglBatch(layout) : undefined
15
+ const oasisFixture = parseOasisTextLayout(new Uint8Array(buffer))
16
+ const oasis = inspectOasisLayout(new Uint8Array(buffer))
17
+ ```
18
+
19
+ ## Scope
20
+
21
+ - `parseGdsLayout()` reads standard GDSII stream records and returns structures, boundaries, paths, text labels, references, bounds, and warnings.
22
+ - `parseOasisTextLayout()` reads the project's OASIS-like text fixture format and returns the same read-only preview model, keeping demos and parser regression tests visually meaningful.
23
+ - `createEdaLayoutWebglBatch()` normalizes GDSII boundaries, paths, labels, and references into triangle / line / point typed arrays for UI renderers or custom WebGL layers.
24
+ - `inspectOasisLayout()` detects real binary OASIS files and keeps full repetition expansion / geometry rendering behind a dedicated WASM/WebGL engine boundary.
25
+ - No Vue, React, Web Component, or DOM dependency.
26
+ - `@file-viewer/renderer-eda` turns this engine output into the user-facing preview UI.
27
+
28
+ ## Roadmap
29
+
30
+ GDSII now has browser WebGL batch output. `@file-viewer/renderer-eda` automatically uses a WebGL canvas for larger element sets and keeps SVG as the fallback for small layouts or browsers without WebGL. The readable OASIS text fixture keeps OAS/OASIS routing, layout UI, and browser smoke tests visually meaningful; industrial SEMI binary OASIS preview still needs a low-level record parser, repetition expansion, hierarchical cell navigation, incremental parsing, and tiled rendering. This package is the stable place to integrate a future KLayout/gdstk/OpenAccess-style WASM engine or a dedicated WebGL tile renderer.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @file-viewer/eda-layout
2
+
3
+ Flyfish File Viewer 的独立 EDA 版图内核包。它只提供框架无关的 TypeScript API,当前负责标准 GDSII 记录解析、GDSII WebGL 绘制批次生成、OASIS 可读文本夹具解析和真实二进制 OASIS 检测边界,不包含任何 UI 组件。
4
+
5
+ ```ts
6
+ import {
7
+ parseGdsLayout,
8
+ parseOasisTextLayout,
9
+ createEdaLayoutWebglBatch,
10
+ inspectOasisLayout,
11
+ } from '@file-viewer/eda-layout'
12
+
13
+ const layout = parseGdsLayout(new Uint8Array(buffer))
14
+ const batch = layout ? createEdaLayoutWebglBatch(layout) : undefined
15
+ const oasisFixture = parseOasisTextLayout(new Uint8Array(buffer))
16
+ const oasis = inspectOasisLayout(new Uint8Array(buffer))
17
+ ```
18
+
19
+ ## 定位
20
+
21
+ - `parseGdsLayout()` 解析标准 GDSII stream record,输出 structure、boundary、path、text、reference、bounds 等只读预览模型。
22
+ - `parseOasisTextLayout()` 解析项目内可读 OASIS 文本夹具,输出和 GDSII 相同的只读预览模型,用于 demo、文档和后续 parser 回归。
23
+ - `createEdaLayoutWebglBatch()` 把 GDSII boundary/path/text/reference 归一化为 triangle / line / point typed arrays,供 UI renderer 或业务自研 WebGL 层消费。
24
+ - `inspectOasisLayout()` 识别真实二进制 OASIS 文件边界,并把完整 OASIS 几何展开留给独立 WASM/WebGL 内核演进。
25
+ - 不依赖 Vue、React、Web Component 或 DOM,可独立发布、独立回归。
26
+ - `@file-viewer/renderer-eda` 负责把本包输出转换为可视化 UI。
27
+
28
+ ## 后续路线
29
+
30
+ GDSII 已具备浏览器 WebGL 批次输出能力,`@file-viewer/renderer-eda` 会在元素较多时自动使用 WebGL canvas,SVG 保留为小文件和不支持 WebGL 环境的回退。可读 OASIS 文本夹具用于保证 OAS/OASIS 路由、版图 UI 和 smoke 测试能真实出图;真实 SEMI 二进制 OASIS 的完整工业级浏览仍需要低层 record parser、重复结构展开、层级 cell 导航和大文件增量渲染,本包是后续接入 KLayout/gdstk/OpenAccess 类 WASM 内核或自研 WebGL tile renderer 的稳定入口。
@@ -0,0 +1,65 @@
1
+ export type EdaLayoutFormat = 'gdsii' | 'oasis';
2
+ export interface EdaPoint {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export interface EdaLayoutElement {
7
+ kind: 'boundary' | 'path' | 'text' | 'sref' | 'aref';
8
+ structure: string;
9
+ layer?: number;
10
+ datatype?: number;
11
+ text?: string;
12
+ reference?: string;
13
+ width?: number;
14
+ xy: EdaPoint[];
15
+ }
16
+ export interface EdaLayoutBounds {
17
+ minX: number;
18
+ minY: number;
19
+ maxX: number;
20
+ maxY: number;
21
+ }
22
+ export interface EdaLayoutPreview {
23
+ format: EdaLayoutFormat;
24
+ libraryName?: string;
25
+ userUnit?: number;
26
+ databaseUnit?: number;
27
+ structureCount: number;
28
+ structures: string[];
29
+ elements: EdaLayoutElement[];
30
+ bounds?: EdaLayoutBounds;
31
+ warnings: string[];
32
+ }
33
+ export interface EdaOasisInspection {
34
+ format: 'oasis';
35
+ magicFound: boolean;
36
+ byteLength: number;
37
+ warnings: string[];
38
+ }
39
+ export interface EdaLayoutWebglLabel {
40
+ text: string;
41
+ layer?: number;
42
+ x: number;
43
+ y: number;
44
+ clipX: number;
45
+ clipY: number;
46
+ }
47
+ export interface EdaLayoutWebglBatch {
48
+ format: 'gdsii';
49
+ elementCount: number;
50
+ triangleVertices: Float32Array;
51
+ lineVertices: Float32Array;
52
+ pointVertices: Float32Array;
53
+ labels: readonly EdaLayoutWebglLabel[];
54
+ bounds?: EdaLayoutBounds;
55
+ warnings: readonly string[];
56
+ }
57
+ export interface CreateEdaLayoutWebglBatchOptions {
58
+ maxElements?: number;
59
+ maxLabels?: number;
60
+ palette?: readonly string[];
61
+ }
62
+ export declare const parseGdsLayout: (bytes: Uint8Array) => EdaLayoutPreview | undefined;
63
+ export declare const parseOasisTextLayout: (bytes: Uint8Array) => EdaLayoutPreview | undefined;
64
+ export declare const createEdaLayoutWebglBatch: (layout: EdaLayoutPreview, options?: CreateEdaLayoutWebglBatchOptions) => EdaLayoutWebglBatch;
65
+ export declare const inspectOasisLayout: (bytes: Uint8Array) => EdaOasisInspection;
package/dist/index.js ADDED
@@ -0,0 +1,510 @@
1
+ const MAX_LAYOUT_ELEMENTS = 2500;
2
+ const GDS_RECORD = {
3
+ BGNLIB: 0x01,
4
+ LIBNAME: 0x02,
5
+ UNITS: 0x03,
6
+ BGNSTR: 0x05,
7
+ STRNAME: 0x06,
8
+ ENDSTR: 0x07,
9
+ BOUNDARY: 0x08,
10
+ PATH: 0x09,
11
+ SREF: 0x0a,
12
+ AREF: 0x0b,
13
+ TEXT: 0x0c,
14
+ LAYER: 0x0d,
15
+ DATATYPE: 0x0e,
16
+ WIDTH: 0x0f,
17
+ XY: 0x10,
18
+ ENDEL: 0x11,
19
+ SNAME: 0x12,
20
+ COLROW: 0x13,
21
+ TEXTTYPE: 0x16,
22
+ STRING: 0x19,
23
+ };
24
+ const DEFAULT_WEBGL_PALETTE = [
25
+ '#5eead4',
26
+ '#93c5fd',
27
+ '#c4b5fd',
28
+ '#f9a8d4',
29
+ '#fde68a',
30
+ '#86efac',
31
+ '#fdba74',
32
+ '#67e8f9',
33
+ ];
34
+ const cleanupText = (text) => {
35
+ return text
36
+ .replace(/\u0000/g, '')
37
+ .replace(/[^\S\r\n]+/g, ' ')
38
+ .replace(/\r\n/g, '\n')
39
+ .trim();
40
+ };
41
+ const readGdsInt16 = (bytes, offset) => {
42
+ const value = (bytes[offset] << 8) | bytes[offset + 1];
43
+ return value & 0x8000 ? value - 0x10000 : value;
44
+ };
45
+ const readGdsInt32 = (bytes, offset) => {
46
+ const value = ((bytes[offset] << 24)
47
+ | (bytes[offset + 1] << 16)
48
+ | (bytes[offset + 2] << 8)
49
+ | bytes[offset + 3]);
50
+ return value | 0;
51
+ };
52
+ const readGdsString = (bytes, offset, length) => {
53
+ return cleanupText(new TextDecoder('utf-8', { fatal: false })
54
+ .decode(bytes.slice(offset, offset + length))
55
+ .replace(/\u0000+$/g, ''));
56
+ };
57
+ const isMostlyPrintableText = (bytes) => {
58
+ const sample = bytes.slice(0, Math.min(bytes.length, 4096));
59
+ if (!sample.length) {
60
+ return false;
61
+ }
62
+ let printable = 0;
63
+ for (const byte of sample) {
64
+ if (byte === 9 || byte === 10 || byte === 13 || (byte >= 32 && byte <= 126)) {
65
+ printable += 1;
66
+ }
67
+ }
68
+ return printable / sample.length > 0.9;
69
+ };
70
+ const parseNumberToken = (value) => {
71
+ const parsed = Number(value);
72
+ return Number.isFinite(parsed) ? parsed : undefined;
73
+ };
74
+ const parseQuotedText = (line) => {
75
+ var _a;
76
+ return ((_a = line.match(/"([^"]+)"/)) === null || _a === void 0 ? void 0 : _a[1]) || line.split(/\s+/).slice(3).join(' ');
77
+ };
78
+ const readGdsReal8 = (bytes, offset) => {
79
+ const first = bytes[offset];
80
+ if (!first) {
81
+ return 0;
82
+ }
83
+ const sign = first & 0x80 ? -1 : 1;
84
+ const exponent = (first & 0x7f) - 64;
85
+ let mantissa = 0;
86
+ for (let index = 1; index < 8; index += 1) {
87
+ mantissa += bytes[offset + index] / (256 ** index);
88
+ }
89
+ return sign * mantissa * (16 ** exponent);
90
+ };
91
+ const readGdsPoints = (bytes, offset, length) => {
92
+ const points = [];
93
+ for (let cursor = offset; cursor + 7 < offset + length; cursor += 8) {
94
+ points.push({
95
+ x: readGdsInt32(bytes, cursor),
96
+ y: readGdsInt32(bytes, cursor + 4),
97
+ });
98
+ }
99
+ return points;
100
+ };
101
+ const updateLayoutBounds = (bounds, points) => {
102
+ let next = bounds;
103
+ points.forEach(point => {
104
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) {
105
+ return;
106
+ }
107
+ if (!next) {
108
+ next = { minX: point.x, minY: point.y, maxX: point.x, maxY: point.y };
109
+ return;
110
+ }
111
+ next.minX = Math.min(next.minX, point.x);
112
+ next.minY = Math.min(next.minY, point.y);
113
+ next.maxX = Math.max(next.maxX, point.x);
114
+ next.maxY = Math.max(next.maxY, point.y);
115
+ });
116
+ return next;
117
+ };
118
+ const normalizeHexColor = (value) => {
119
+ const normalized = value.trim().replace(/^#/, '');
120
+ if (/^[0-9a-f]{3}$/i.test(normalized)) {
121
+ return normalized.split('').map(part => `${part}${part}`).join('');
122
+ }
123
+ return /^[0-9a-f]{6}$/i.test(normalized) ? normalized : '5eead4';
124
+ };
125
+ const colorForLayer = (layer, palette) => {
126
+ const normalizedLayer = Number.isFinite(layer) ? Math.abs(Number(layer)) : 0;
127
+ const color = normalizeHexColor(palette[normalizedLayer % palette.length] || DEFAULT_WEBGL_PALETTE[0]);
128
+ return {
129
+ r: parseInt(color.slice(0, 2), 16) / 255,
130
+ g: parseInt(color.slice(2, 4), 16) / 255,
131
+ b: parseInt(color.slice(4, 6), 16) / 255,
132
+ };
133
+ };
134
+ const withoutClosingPoint = (points) => {
135
+ if (points.length < 2) {
136
+ return [...points];
137
+ }
138
+ const first = points[0];
139
+ const last = points[points.length - 1];
140
+ return first.x === last.x && first.y === last.y ? points.slice(0, -1) : [...points];
141
+ };
142
+ export const parseGdsLayout = (bytes) => {
143
+ const structures = [];
144
+ const elements = [];
145
+ const warnings = [];
146
+ let libraryName = '';
147
+ let userUnit;
148
+ let databaseUnit;
149
+ let currentStructure = '';
150
+ let currentElement = null;
151
+ let bounds;
152
+ const pushElement = () => {
153
+ if (!currentElement || !currentElement.xy.length) {
154
+ currentElement = null;
155
+ return;
156
+ }
157
+ if (elements.length < MAX_LAYOUT_ELEMENTS) {
158
+ elements.push(currentElement);
159
+ bounds = updateLayoutBounds(bounds, currentElement.xy);
160
+ }
161
+ else if (!warnings.length) {
162
+ warnings.push(`Layout contains more than ${MAX_LAYOUT_ELEMENTS} elements; only the first ${MAX_LAYOUT_ELEMENTS} are rendered to protect browser memory.`);
163
+ }
164
+ currentElement = null;
165
+ };
166
+ for (let offset = 0; offset + 3 < bytes.length;) {
167
+ const length = (bytes[offset] << 8) | bytes[offset + 1];
168
+ const recordType = bytes[offset + 2];
169
+ if (length < 4 || offset + length > bytes.length) {
170
+ warnings.push(`GDSII record has an invalid length at offset ${offset}; geometry parsing stopped safely.`);
171
+ break;
172
+ }
173
+ const dataOffset = offset + 4;
174
+ const dataLength = length - 4;
175
+ switch (recordType) {
176
+ case GDS_RECORD.BGNLIB:
177
+ currentStructure = '';
178
+ break;
179
+ case GDS_RECORD.LIBNAME:
180
+ libraryName = readGdsString(bytes, dataOffset, dataLength);
181
+ break;
182
+ case GDS_RECORD.UNITS:
183
+ if (dataLength >= 16) {
184
+ userUnit = readGdsReal8(bytes, dataOffset);
185
+ databaseUnit = readGdsReal8(bytes, dataOffset + 8);
186
+ }
187
+ break;
188
+ case GDS_RECORD.BGNSTR:
189
+ pushElement();
190
+ currentStructure = '';
191
+ break;
192
+ case GDS_RECORD.STRNAME:
193
+ currentStructure = readGdsString(bytes, dataOffset, dataLength);
194
+ if (currentStructure && !structures.includes(currentStructure)) {
195
+ structures.push(currentStructure);
196
+ }
197
+ break;
198
+ case GDS_RECORD.ENDSTR:
199
+ pushElement();
200
+ currentStructure = '';
201
+ break;
202
+ case GDS_RECORD.BOUNDARY:
203
+ pushElement();
204
+ currentElement = { kind: 'boundary', structure: currentStructure || 'STRUCTURE', xy: [] };
205
+ break;
206
+ case GDS_RECORD.PATH:
207
+ pushElement();
208
+ currentElement = { kind: 'path', structure: currentStructure || 'STRUCTURE', xy: [] };
209
+ break;
210
+ case GDS_RECORD.TEXT:
211
+ pushElement();
212
+ currentElement = { kind: 'text', structure: currentStructure || 'STRUCTURE', xy: [] };
213
+ break;
214
+ case GDS_RECORD.SREF:
215
+ pushElement();
216
+ currentElement = { kind: 'sref', structure: currentStructure || 'STRUCTURE', xy: [] };
217
+ break;
218
+ case GDS_RECORD.AREF:
219
+ pushElement();
220
+ currentElement = { kind: 'aref', structure: currentStructure || 'STRUCTURE', xy: [] };
221
+ break;
222
+ case GDS_RECORD.LAYER:
223
+ if (currentElement && dataLength >= 2) {
224
+ currentElement.layer = readGdsInt16(bytes, dataOffset);
225
+ }
226
+ break;
227
+ case GDS_RECORD.DATATYPE:
228
+ case GDS_RECORD.TEXTTYPE:
229
+ if (currentElement && dataLength >= 2) {
230
+ currentElement.datatype = readGdsInt16(bytes, dataOffset);
231
+ }
232
+ break;
233
+ case GDS_RECORD.WIDTH:
234
+ if (currentElement && dataLength >= 4) {
235
+ currentElement.width = Math.abs(readGdsInt32(bytes, dataOffset));
236
+ }
237
+ break;
238
+ case GDS_RECORD.XY:
239
+ if (currentElement) {
240
+ currentElement.xy = readGdsPoints(bytes, dataOffset, dataLength);
241
+ }
242
+ break;
243
+ case GDS_RECORD.SNAME:
244
+ if (currentElement) {
245
+ currentElement.reference = readGdsString(bytes, dataOffset, dataLength);
246
+ }
247
+ break;
248
+ case GDS_RECORD.STRING:
249
+ if (currentElement) {
250
+ currentElement.text = readGdsString(bytes, dataOffset, dataLength);
251
+ }
252
+ break;
253
+ case GDS_RECORD.COLROW:
254
+ if (currentElement && dataLength >= 4) {
255
+ currentElement.text = `${currentElement.text || ''} ${readGdsInt16(bytes, dataOffset)}x${readGdsInt16(bytes, dataOffset + 2)}`.trim();
256
+ }
257
+ break;
258
+ case GDS_RECORD.ENDEL:
259
+ pushElement();
260
+ break;
261
+ default:
262
+ break;
263
+ }
264
+ offset += length;
265
+ }
266
+ pushElement();
267
+ if (!structures.length && !elements.length && !libraryName) {
268
+ return undefined;
269
+ }
270
+ return {
271
+ format: 'gdsii',
272
+ libraryName,
273
+ userUnit,
274
+ databaseUnit,
275
+ structureCount: structures.length,
276
+ structures,
277
+ elements,
278
+ bounds,
279
+ warnings,
280
+ };
281
+ };
282
+ export const parseOasisTextLayout = (bytes) => {
283
+ if (!isMostlyPrintableText(bytes)) {
284
+ return undefined;
285
+ }
286
+ const text = new TextDecoder('utf-8', { fatal: false }).decode(bytes);
287
+ if (!/%SEMI-OASIS/i.test(text) && !/\bOASIS\b/i.test(text)) {
288
+ return undefined;
289
+ }
290
+ const structures = [];
291
+ const elements = [];
292
+ const warnings = [
293
+ 'Parsed an ASCII OASIS-like structure fixture. Full SEMI binary OASIS geometry requires the dedicated layout kernel path.',
294
+ ];
295
+ const state = { structure: 'TOP' };
296
+ let userUnit;
297
+ let bounds;
298
+ const pushElement = (element) => {
299
+ elements.push(element);
300
+ bounds = updateLayoutBounds(bounds, element.xy);
301
+ };
302
+ text.split(/\r?\n/).forEach(rawLine => {
303
+ const line = rawLine.trim();
304
+ if (!line || line.startsWith('#')) {
305
+ return;
306
+ }
307
+ const parts = line.split(/\s+/);
308
+ const command = (parts[0] || '').toUpperCase();
309
+ if (command === 'START') {
310
+ const unitMatch = line.match(/\bunit=([0-9.eE+-]+)/);
311
+ userUnit = parseNumberToken(unitMatch === null || unitMatch === void 0 ? void 0 : unitMatch[1]);
312
+ return;
313
+ }
314
+ if (command === 'CELL') {
315
+ state.structure = parts[1] || `CELL_${structures.length + 1}`;
316
+ if (!structures.includes(state.structure)) {
317
+ structures.push(state.structure);
318
+ }
319
+ return;
320
+ }
321
+ if (command === 'LAYER') {
322
+ state.layer = parseNumberToken(parts[1]);
323
+ const datatypeIndex = parts.findIndex(part => part.toUpperCase() === 'DATATYPE');
324
+ state.datatype = parseNumberToken(parts[datatypeIndex + 1]);
325
+ return;
326
+ }
327
+ if (command === 'RECT') {
328
+ const x = parseNumberToken(parts[1]);
329
+ const y = parseNumberToken(parts[2]);
330
+ const width = parseNumberToken(parts[3]);
331
+ const height = parseNumberToken(parts[4]);
332
+ if ([x, y, width, height].some(value => value === undefined)) {
333
+ warnings.push(`Skipped malformed RECT record: ${line}`);
334
+ return;
335
+ }
336
+ pushElement({
337
+ kind: 'boundary',
338
+ structure: state.structure,
339
+ layer: state.layer,
340
+ datatype: state.datatype,
341
+ xy: [
342
+ { x: x, y: y },
343
+ { x: x + width, y: y },
344
+ { x: x + width, y: y + height },
345
+ { x: x, y: y + height },
346
+ { x: x, y: y },
347
+ ],
348
+ });
349
+ return;
350
+ }
351
+ if (command === 'PATH' || command === 'POLYGON') {
352
+ const values = parts.slice(1).map(parseNumberToken);
353
+ if (values.length < 4 || values.some(value => value === undefined)) {
354
+ warnings.push(`Skipped malformed ${command} record: ${line}`);
355
+ return;
356
+ }
357
+ const xy = [];
358
+ for (let index = 0; index + 1 < values.length; index += 2) {
359
+ xy.push({ x: values[index], y: values[index + 1] });
360
+ }
361
+ if (command === 'POLYGON' && xy.length >= 3) {
362
+ xy.push({ ...xy[0] });
363
+ }
364
+ pushElement({
365
+ kind: command === 'PATH' ? 'path' : 'boundary',
366
+ structure: state.structure,
367
+ layer: state.layer,
368
+ datatype: state.datatype,
369
+ xy,
370
+ });
371
+ return;
372
+ }
373
+ if (command === 'TEXT') {
374
+ const x = parseNumberToken(parts[1]);
375
+ const y = parseNumberToken(parts[2]);
376
+ if (x === undefined || y === undefined) {
377
+ warnings.push(`Skipped malformed TEXT record: ${line}`);
378
+ return;
379
+ }
380
+ pushElement({
381
+ kind: 'text',
382
+ structure: state.structure,
383
+ layer: state.layer,
384
+ datatype: state.datatype,
385
+ text: cleanupText(parseQuotedText(line)),
386
+ xy: [{ x, y }],
387
+ });
388
+ }
389
+ });
390
+ if (!elements.length && !structures.length) {
391
+ return undefined;
392
+ }
393
+ return {
394
+ format: 'oasis',
395
+ libraryName: 'OASIS text fixture',
396
+ userUnit,
397
+ structureCount: structures.length || 1,
398
+ structures: structures.length ? structures : [state.structure],
399
+ elements,
400
+ bounds,
401
+ warnings,
402
+ };
403
+ };
404
+ export const createEdaLayoutWebglBatch = (layout, options = {}) => {
405
+ var _a, _b, _c;
406
+ const warnings = [];
407
+ const triangleVertices = [];
408
+ const lineVertices = [];
409
+ const pointVertices = [];
410
+ const labels = [];
411
+ const palette = ((_a = options.palette) === null || _a === void 0 ? void 0 : _a.length) ? options.palette : DEFAULT_WEBGL_PALETTE;
412
+ const maxElements = (_b = options.maxElements) !== null && _b !== void 0 ? _b : 18000;
413
+ const maxLabels = (_c = options.maxLabels) !== null && _c !== void 0 ? _c : 600;
414
+ const bounds = layout.bounds;
415
+ if (layout.format !== 'gdsii' || !bounds) {
416
+ return {
417
+ format: 'gdsii',
418
+ elementCount: 0,
419
+ triangleVertices: new Float32Array(),
420
+ lineVertices: new Float32Array(),
421
+ pointVertices: new Float32Array(),
422
+ labels,
423
+ bounds,
424
+ warnings: ['WebGL batches are currently generated for parsed GDSII geometry only.'],
425
+ };
426
+ }
427
+ const rawWidth = Math.max(1, bounds.maxX - bounds.minX);
428
+ const rawHeight = Math.max(1, bounds.maxY - bounds.minY);
429
+ const toClip = (point) => ({
430
+ x: ((point.x - bounds.minX) / rawWidth) * 2 - 1,
431
+ y: ((point.y - bounds.minY) / rawHeight) * 2 - 1,
432
+ });
433
+ const pushVertex = (target, point, color) => {
434
+ const mapped = toClip(point);
435
+ target.push(mapped.x, mapped.y, color.r, color.g, color.b);
436
+ };
437
+ const pushLine = (from, to, color) => {
438
+ pushVertex(lineVertices, from, color);
439
+ pushVertex(lineVertices, to, color);
440
+ };
441
+ const elements = layout.elements.slice(0, maxElements);
442
+ if (layout.elements.length > maxElements) {
443
+ warnings.push(`Layout contains ${layout.elements.length} elements; WebGL preview batched the first ${maxElements} elements to protect browser memory.`);
444
+ }
445
+ elements.forEach(element => {
446
+ const color = colorForLayer(element.layer, palette);
447
+ const points = withoutClosingPoint(element.xy);
448
+ if ((element.kind === 'boundary' || element.kind === 'aref') && points.length >= 3) {
449
+ for (let index = 1; index < points.length - 1; index += 1) {
450
+ pushVertex(triangleVertices, points[0], color);
451
+ pushVertex(triangleVertices, points[index], color);
452
+ pushVertex(triangleVertices, points[index + 1], color);
453
+ }
454
+ for (let index = 0; index < points.length; index += 1) {
455
+ pushLine(points[index], points[(index + 1) % points.length], color);
456
+ }
457
+ return;
458
+ }
459
+ if (element.kind === 'path' && points.length >= 2) {
460
+ for (let index = 0; index < points.length - 1; index += 1) {
461
+ pushLine(points[index], points[index + 1], color);
462
+ }
463
+ return;
464
+ }
465
+ const anchor = points[0];
466
+ if (!anchor) {
467
+ return;
468
+ }
469
+ pushVertex(pointVertices, anchor, color);
470
+ const label = element.text || element.reference;
471
+ if (label && labels.length < maxLabels) {
472
+ const mapped = toClip(anchor);
473
+ labels.push({
474
+ text: label,
475
+ layer: element.layer,
476
+ x: anchor.x,
477
+ y: anchor.y,
478
+ clipX: mapped.x,
479
+ clipY: mapped.y,
480
+ });
481
+ }
482
+ });
483
+ if (labels.length >= maxLabels) {
484
+ warnings.push(`Only the first ${maxLabels} layout labels are shown in the WebGL overlay.`);
485
+ }
486
+ return {
487
+ format: 'gdsii',
488
+ elementCount: elements.length,
489
+ triangleVertices: new Float32Array(triangleVertices),
490
+ lineVertices: new Float32Array(lineVertices),
491
+ pointVertices: new Float32Array(pointVertices),
492
+ labels,
493
+ bounds,
494
+ warnings,
495
+ };
496
+ };
497
+ export const inspectOasisLayout = (bytes) => {
498
+ const header = new TextDecoder('ascii', { fatal: false }).decode(bytes.slice(0, Math.min(24, bytes.length)));
499
+ const magicFound = header.includes('OASIS');
500
+ return {
501
+ format: 'oasis',
502
+ magicFound,
503
+ byteLength: bytes.byteLength,
504
+ warnings: [
505
+ magicFound
506
+ ? 'OASIS header detected. Full cell repetition expansion and geometry rendering is reserved for the dedicated WASM/WebGL layout engine boundary.'
507
+ : 'OASIS header was not detected in the first bytes. The file may be wrapped, compressed, encrypted, or use a proprietary exchange container.',
508
+ ],
509
+ };
510
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@file-viewer/eda-layout",
3
+ "version": "2.0.11",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Pure TypeScript EDA layout inspection engine for Flyfish File Viewer with GDSII quick preview primitives and OASIS upgrade boundaries.",
7
+ "keywords": [
8
+ "file-viewer",
9
+ "eda",
10
+ "layout",
11
+ "gds",
12
+ "gdsii",
13
+ "oasis",
14
+ "wasm",
15
+ "document-preview",
16
+ "file-preview",
17
+ "self-hosted"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public",
21
+ "registry": "https://registry.npmjs.org/"
22
+ },
23
+ "author": {
24
+ "name": "Wangyu",
25
+ "email": "wybaby168@gmail.com"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/flyfish-dev/eda-layout.git",
30
+ "directory": "packages/renderers/eda-layout"
31
+ },
32
+ "homepage": "https://doc.file-viewer.app/guide/format-fidelity",
33
+ "bugs": {
34
+ "url": "https://github.com/flyfish-dev/eda-layout/issues"
35
+ },
36
+ "funding": {
37
+ "type": "individual",
38
+ "url": "https://dev.flyfish.group/shop"
39
+ },
40
+ "main": "./dist/index.js",
41
+ "module": "./dist/index.js",
42
+ "types": "./dist/index.d.ts",
43
+ "exports": {
44
+ ".": {
45
+ "types": "./dist/index.d.ts",
46
+ "import": "./dist/index.js",
47
+ "default": "./dist/index.js"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "README.md",
54
+ "README.en.md",
55
+ "LICENSE"
56
+ ],
57
+ "devDependencies": {
58
+ "typescript": "^6.0.3"
59
+ },
60
+ "license": "Apache-2.0",
61
+ "scripts": {
62
+ "build": "tsc -b tsconfig.json",
63
+ "type-check": "tsc -b tsconfig.json"
64
+ }
65
+ }