ducjs 3.0.0 → 3.0.3

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 CHANGED
@@ -1,3 +1,5 @@
1
+ # ducjs
2
+
1
3
  <p align="center">
2
4
  <br/>
3
5
  <a href="https://duc.ducflair.com" target="_blank"><img width="256px" src="https://raw.githubusercontent.com/ducflair/assets/refs/heads/main/src/duc/duc-extended.png" /></a>
@@ -10,9 +12,6 @@
10
12
  </p>
11
13
  </p>
12
14
 
13
-
14
- # ducjs
15
-
16
15
  The `ducjs` package offers comprehensive TypeScript types and helper functions to work effortlessly with the `duc` CAD file format. Built with SQLite and optimized for performance, this package enables you to parse, validate, and manipulate `duc` files with ease.
17
16
 
18
17
  ## Documentation
@@ -65,7 +65,13 @@ export class LazyExternalFileStore {
65
65
  const result = wasmGetExternalFile(this.buffer, fileId);
66
66
  if (!result)
67
67
  return null;
68
- return result;
68
+ // WASM returns DucExternalFileEntry { key, value: DucExternalFileData }.
69
+ // Unwrap to get the actual file data.
70
+ const entry = result;
71
+ if (entry.value && typeof entry.value === "object") {
72
+ return entry.value;
73
+ }
74
+ return entry;
69
75
  }
70
76
  /** Fetch file data and return a copy of the data buffer (safe for transfer). */
71
77
  getFileDataCopy(fileId) {
@@ -49,10 +49,15 @@ export const restoreFiles = (importedFiles) => {
49
49
  const files = importedFiles;
50
50
  for (const key in files) {
51
51
  if (Object.prototype.hasOwnProperty.call(files, key)) {
52
- const fileData = files[key];
52
+ let fileData = files[key];
53
53
  if (!fileData || typeof fileData !== "object") {
54
54
  continue;
55
55
  }
56
+ // Handle the nested DucExternalFileEntry structure { key, value: { ... } }
57
+ // produced by Rust serde or legacy exports.
58
+ if (fileData.value && typeof fileData.value === "object") {
59
+ fileData = fileData.value;
60
+ }
56
61
  const id = isValidExternalFileId(fileData.id);
57
62
  const mimeType = isValidString(fileData.mimeType);
58
63
  const created = isFiniteNumber(fileData.created)
@@ -805,6 +810,9 @@ export const isValidUint8Array = (value) => {
805
810
  if (value instanceof Uint8Array) {
806
811
  return value.byteLength > 0 ? value : undefined;
807
812
  }
813
+ if (value instanceof ArrayBuffer) {
814
+ return value.byteLength > 0 ? new Uint8Array(value) : undefined;
815
+ }
808
816
  if (typeof value === "string") {
809
817
  let base64String = value;
810
818
  if (value.startsWith("data:")) {
@@ -9,7 +9,7 @@ export declare const MAX_ZOOM = 1e+32;
9
9
  export declare const NEUTRAL_SCOPE: SupportedMeasures;
10
10
  export declare const metricMeasures: readonly ["qm", "rm", "ym", "zm", "am", "fm", "pm", "Å", "nm", "µm", "mm", "cm", "dm", "m", "dam", "hm", "km", "Mm", "Gm", "Tm", "Pm", "Em", "Zm", "Ym", "Rm", "Qm"];
11
11
  export type MetricMeasure = typeof metricMeasures[number];
12
- export declare const imperialMeasures: readonly ["th", "ln", "in", "h", "ft", "yd", "rd", "ch", "fur", "mi", "lea"];
12
+ export declare const imperialMeasures: readonly ["µin", "th", "mil", "ln", "in", "h", "ft", "yd", "rd", "ch", "fur", "mi", "lea", "au", "ly", "pc"];
13
13
  export type ImperialMeasure = typeof imperialMeasures[number];
14
14
  export type SupportedMeasures = MetricMeasure | ImperialMeasure;
15
15
  export type CombinedMeasure = SupportedMeasures;
@@ -32,7 +32,9 @@ export const metricMeasures = [
32
32
  'Qm', // Quettameter
33
33
  ];
34
34
  export const imperialMeasures = [
35
- 'th', // Thou/mil
35
+ 'µin', // Microinches
36
+ 'th', // Thou
37
+ 'mil', // Mils
36
38
  'ln', // Line
37
39
  'in', // Inches
38
40
  'h', // Hand
@@ -43,6 +45,9 @@ export const imperialMeasures = [
43
45
  'fur', // Furlongs
44
46
  'mi', // Miles
45
47
  'lea', // Leagues
48
+ 'au', // Astronomical Unit
49
+ 'ly', // Light Year
50
+ 'pc', // Parsec
46
51
  ];
47
52
  // Define metric units - exponents represent powers of 10
48
53
  export const metricUnits = [
@@ -76,17 +81,22 @@ export const metricUnits = [
76
81
  // Define imperial units - exponents are now relative to meter as the base unit
77
82
  // These values are log10 of their meter equivalents
78
83
  export const imperialUnits = [
79
- { prefix: 'th', unit: 'thou', full: 'thou', exponent: -4.595 }, // log10(0.0000254) ≈ -4.595
80
- { prefix: 'ln', unit: 'line', full: 'line', exponent: -2.674 }, // log10(0.00211667) ≈ -2.674
81
- { prefix: 'in', unit: 'inch', full: 'inch', exponent: -1.595 }, // log10(0.0254) ≈ -1.595
82
- { prefix: 'h', unit: 'hand', full: 'hand', exponent: -0.993 }, // log10(0.1016) ≈ -0.993
83
- { prefix: 'ft', unit: 'foot', full: 'foot', exponent: -0.516 }, // log10(0.3048) ≈ -0.516
84
- { prefix: 'yd', unit: 'yard', full: 'yard', exponent: -0.039 }, // log10(0.9144) ≈ -0.039
85
- { prefix: 'rd', unit: 'rod', full: 'rod', exponent: 0.701 }, // log10(5.0292) ≈ 0.701
86
- { prefix: 'ch', unit: 'chain', full: 'chain', exponent: 1.304 }, // log10(20.1168) ≈ 1.304
87
- { prefix: 'fur', unit: 'furlong', full: 'furlong', exponent: 2.304 }, // log10(201.168) ≈ 2.304
88
- { prefix: 'mi', unit: 'mile', full: 'mile', exponent: 3.207 }, // log10(1609.344) ≈ 3.207
89
- { prefix: 'lea', unit: 'league', full: 'league', exponent: 3.684 } // log10(4828.032) ≈ 3.684
84
+ { prefix: 'µin', unit: 'microinch', full: 'microinch', exponent: -7.595 }, // log10(2.54e-8)
85
+ { prefix: 'th', unit: 'thou', full: 'thou', exponent: -4.595 }, // log10(0.0000254)
86
+ { prefix: 'mil', unit: 'mil', full: 'mil', exponent: -4.595 }, // log10(0.0000254)
87
+ { prefix: 'ln', unit: 'line', full: 'line', exponent: -2.674 }, // log10(0.00211667)
88
+ { prefix: 'in', unit: 'inch', full: 'inch', exponent: -1.595 }, // log10(0.0254)
89
+ { prefix: 'h', unit: 'hand', full: 'hand', exponent: -0.993 }, // log10(0.1016)
90
+ { prefix: 'ft', unit: 'foot', full: 'foot', exponent: -0.516 }, // log10(0.3048)
91
+ { prefix: 'yd', unit: 'yard', full: 'yard', exponent: -0.039 }, // log10(0.9144)
92
+ { prefix: 'rd', unit: 'rod', full: 'rod', exponent: 0.701 }, // log10(5.0292)
93
+ { prefix: 'ch', unit: 'chain', full: 'chain', exponent: 1.304 }, // log10(20.1168)
94
+ { prefix: 'fur', unit: 'furlong', full: 'furlong', exponent: 2.304 }, // log10(201.168)
95
+ { prefix: 'mi', unit: 'mile', full: 'mile', exponent: 3.207 }, // log10(1609.344)
96
+ { prefix: 'lea', unit: 'league', full: 'league', exponent: 3.684 }, // log10(4828.032)
97
+ { prefix: 'au', unit: 'au', full: 'Astronomical Unit', exponent: 11.175 }, // log10(1.496e11)
98
+ { prefix: 'ly', unit: 'ly', full: 'Light Year', exponent: 15.976 }, // log10(9.461e15)
99
+ { prefix: 'pc', unit: 'pc', full: 'Parsec', exponent: 16.489 }, // log10(3.086e16)
90
100
  ];
91
101
  // Scale factors for unit conversions - using meter as the base unit
92
102
  export const ScaleFactors = {
@@ -118,7 +128,9 @@ export const ScaleFactors = {
118
128
  Rm: 1e27,
119
129
  Qm: 1e30,
120
130
  // Imperial scales
121
- th: 0.0000254, // 0.001 inch
131
+ 'µin': 2.54e-8, // Microinch
132
+ th: 0.0000254, // Thou (0.001 inch)
133
+ mil: 0.0000254, // Mil (same as Thou)
122
134
  ln: 0.00211667, // 1/12 inch
123
135
  in: 0.0254,
124
136
  h: 0.1016, // 4 inches
@@ -129,6 +141,9 @@ export const ScaleFactors = {
129
141
  fur: 201.168,
130
142
  mi: 1609.344,
131
143
  lea: 4828.032, // 3 miles
144
+ au: 149597870700, // Astronomical Unit
145
+ ly: 9460730472580800, // Light Year
146
+ pc: 30856775814913670, // Parsec
132
147
  };
133
148
  /**
134
149
  * Determines if a measure belongs to the metric system.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "3.0.0",
3
+ "version": "3.0.3",
4
4
  "description": "The duc 2D CAD file format is a cornerstone of our advanced design system, conceived to cater to professionals seeking precision and efficiency in their design work.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -53,6 +53,7 @@
53
53
  },
54
54
  "files": [
55
55
  "dist",
56
+ "pkg",
56
57
  "README.md"
57
58
  ],
58
59
  "publishConfig": {