@react-scad/core 0.1.19 → 0.1.20
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/dist/log.d.ts +1 -0
- package/dist/log.js +10 -1
- package/dist/primitives/circle.js +2 -1
- package/dist/primitives/cube.js +2 -2
- package/dist/primitives/cylinder.js +2 -1
- package/dist/primitives/linear-extrude.js +4 -4
- package/dist/primitives/rotate-extrude.js +2 -1
- package/dist/primitives/sphere.js +2 -1
- package/dist/primitives/square.js +2 -2
- package/dist/runtime/root.js +1 -0
- package/dist/serialize/index.js +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +16 -7
- package/package.json +1 -1
package/dist/log.d.ts
CHANGED
package/dist/log.js
CHANGED
|
@@ -16,6 +16,11 @@ const PAD = " ";
|
|
|
16
16
|
function line(msg) {
|
|
17
17
|
console.log(msg);
|
|
18
18
|
}
|
|
19
|
+
function formatSize(bytes) {
|
|
20
|
+
if (bytes >= 1024)
|
|
21
|
+
return `${(bytes / 1024).toFixed(2)} kB`;
|
|
22
|
+
return `${bytes} B`;
|
|
23
|
+
}
|
|
19
24
|
export const log = {
|
|
20
25
|
banner() {
|
|
21
26
|
line(`${PAD}${c.cyan("◆")} ${c.bold(TOOL_NAME)} ${c.dim(VERSION)} ${c.dim("-")} ${c.dim("Ctrl+C to exit")}`);
|
|
@@ -24,11 +29,15 @@ export const log = {
|
|
|
24
29
|
line(`${PAD}${c.dim("○")} ${c.dim(msg)}`);
|
|
25
30
|
},
|
|
26
31
|
complete(ms) {
|
|
27
|
-
|
|
32
|
+
const sec = (ms / 1000).toFixed(2);
|
|
33
|
+
line(`${PAD}${c.green("✓")} ${c.green("Done")} ${c.dim(`in ${sec}s`)}`);
|
|
28
34
|
},
|
|
29
35
|
outputPath(path) {
|
|
30
36
|
line(`${PAD}${c.dim("→")} ${c.cyan(path)}`);
|
|
31
37
|
},
|
|
38
|
+
fileSize(bytes) {
|
|
39
|
+
line(`${PAD}${c.dim("+")} ${c.dim(formatSize(bytes))}`);
|
|
40
|
+
},
|
|
32
41
|
stop() {
|
|
33
42
|
line(`${PAD}${c.dim("Stopped.")}`);
|
|
34
43
|
},
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { formatScadExpr } from "../utils.js";
|
|
2
3
|
import { Primitive } from "./primitive.js";
|
|
3
4
|
export const Circle = (props) => React.createElement(Primitive, { ...props, type: "circle" });
|
|
4
5
|
Circle.displayName = "Circle";
|
|
5
6
|
export function serialize(node, _indent, _ctx) {
|
|
6
7
|
const rVal = node.r ?? 1;
|
|
7
8
|
const dVal = node.d;
|
|
8
|
-
let args = dVal != null ? `d = ${
|
|
9
|
+
let args = dVal != null ? `d = ${formatScadExpr(dVal)}` : `r = ${formatScadExpr(rVal)}`;
|
|
9
10
|
if (node.$fn != null)
|
|
10
11
|
args += `, $fn = ${node.$fn}`;
|
|
11
12
|
return `circle(${args});`;
|
package/dist/primitives/cube.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { formatVec3 } from "../utils.js";
|
|
2
|
+
import { formatScadExpr, formatVec3 } from "../utils.js";
|
|
3
3
|
import { Primitive } from "./primitive.js";
|
|
4
4
|
export const Cube = (props) => React.createElement(Primitive, { ...props, type: "cube" });
|
|
5
5
|
Cube.displayName = "Cube";
|
|
6
6
|
export function serialize(node, _indent, _ctx) {
|
|
7
7
|
const s = typeof node.size === "number"
|
|
8
|
-
?
|
|
8
|
+
? formatScadExpr(node.size)
|
|
9
9
|
: typeof node.size === "string"
|
|
10
10
|
? node.size
|
|
11
11
|
: formatVec3(node.size);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { formatScadExpr } from "../utils.js";
|
|
2
3
|
import { Primitive } from "./primitive.js";
|
|
3
4
|
export const Cylinder = (props) => React.createElement(Primitive, { ...props, type: "cylinder" });
|
|
4
5
|
Cylinder.displayName = "Cylinder";
|
|
5
6
|
export function serialize(node, _indent, _ctx) {
|
|
6
|
-
let args = `h = ${
|
|
7
|
+
let args = `h = ${formatScadExpr(node.h)}, r1 = ${formatScadExpr(node.r1)}, r2 = ${formatScadExpr(node.r2)}`;
|
|
7
8
|
if (node.$fn != null)
|
|
8
9
|
args += `, $fn = ${node.$fn}`;
|
|
9
10
|
return `cylinder(${args});`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { formatVec2 } from "../utils.js";
|
|
2
|
+
import { formatScadExpr, formatVec2 } from "../utils.js";
|
|
3
3
|
import { Primitive } from "./primitive.js";
|
|
4
4
|
export const LinearExtrude = (props) => React.createElement(Primitive, { ...props, type: "linear_extrude" });
|
|
5
5
|
LinearExtrude.displayName = "LinearExtrude";
|
|
@@ -7,15 +7,15 @@ function formatScale(scale) {
|
|
|
7
7
|
if (scale == null)
|
|
8
8
|
return undefined;
|
|
9
9
|
if (typeof scale === "number" || typeof scale === "string")
|
|
10
|
-
return
|
|
10
|
+
return formatScadExpr(scale);
|
|
11
11
|
return formatVec2(scale);
|
|
12
12
|
}
|
|
13
13
|
export function serialize(node, indent, ctx) {
|
|
14
|
-
const parts = [`height = ${
|
|
14
|
+
const parts = [`height = ${formatScadExpr(node.height)}`];
|
|
15
15
|
if (node.center === true)
|
|
16
16
|
parts.push("center = true");
|
|
17
17
|
if (node.twist != null)
|
|
18
|
-
parts.push(`twist = ${
|
|
18
|
+
parts.push(`twist = ${formatScadExpr(node.twist)}`);
|
|
19
19
|
const scaleStr = formatScale(node.scale);
|
|
20
20
|
if (scaleStr != null)
|
|
21
21
|
parts.push(`scale = ${scaleStr}`);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { formatScadExpr } from "../utils.js";
|
|
2
3
|
import { Primitive } from "./primitive.js";
|
|
3
4
|
export const RotateExtrude = (props) => React.createElement(Primitive, { ...props, type: "rotate_extrude" });
|
|
4
5
|
RotateExtrude.displayName = "RotateExtrude";
|
|
5
6
|
export function serialize(node, indent, ctx) {
|
|
6
7
|
const parts = [];
|
|
7
8
|
if (node.angle != null)
|
|
8
|
-
parts.push(`angle = ${
|
|
9
|
+
parts.push(`angle = ${formatScadExpr(node.angle)}`);
|
|
9
10
|
if (node.convexity != null)
|
|
10
11
|
parts.push(`convexity = ${node.convexity}`);
|
|
11
12
|
if (node.$fn != null)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { formatScadExpr } from "../utils.js";
|
|
2
3
|
import { Primitive } from "./primitive.js";
|
|
3
4
|
export const Sphere = (props) => React.createElement(Primitive, { ...props, type: "sphere" });
|
|
4
5
|
Sphere.displayName = "Sphere";
|
|
5
6
|
export function serialize(node, _indent, _ctx) {
|
|
6
7
|
const rVal = node.r ?? 1;
|
|
7
8
|
const dVal = node.d;
|
|
8
|
-
let args = dVal != null ? `d = ${
|
|
9
|
+
let args = dVal != null ? `d = ${formatScadExpr(dVal)}` : `r = ${formatScadExpr(rVal)}`;
|
|
9
10
|
if (node.$fn != null)
|
|
10
11
|
args += `, $fn = ${node.$fn}`;
|
|
11
12
|
return `sphere(${args});`;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { formatVec2 } from "../utils.js";
|
|
2
|
+
import { formatScadExpr, formatVec2 } from "../utils.js";
|
|
3
3
|
import { Primitive } from "./primitive.js";
|
|
4
4
|
export const Square = (props) => React.createElement(Primitive, { ...props, type: "square" });
|
|
5
5
|
Square.displayName = "Square";
|
|
6
6
|
export function serialize(node, _indent, _ctx) {
|
|
7
7
|
const s = typeof node.size === "number"
|
|
8
|
-
?
|
|
8
|
+
? formatScadExpr(node.size)
|
|
9
9
|
: typeof node.size === "string"
|
|
10
10
|
? node.size
|
|
11
11
|
: formatVec2(node.size);
|
package/dist/runtime/root.js
CHANGED
package/dist/serialize/index.js
CHANGED
|
@@ -76,6 +76,8 @@ export function toScad(container) {
|
|
|
76
76
|
const ctx = {
|
|
77
77
|
serializeNode: (n, i) => serializeNode(n, i, ctx),
|
|
78
78
|
};
|
|
79
|
-
const body = container.children
|
|
79
|
+
const body = container.children
|
|
80
|
+
.map((n) => serializeNode(n, "", ctx))
|
|
81
|
+
.join("\n\n");
|
|
80
82
|
return body ? `${CREDIT}\n\n${body}` : CREDIT;
|
|
81
83
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Vec2, Vec3 } from "./types.js";
|
|
1
|
+
import type { ScadExpr, Vec2, Vec3 } from "./types.js";
|
|
2
|
+
export declare function formatNumber(n: number): string;
|
|
3
|
+
export declare function formatScadExpr(x: ScadExpr): string;
|
|
2
4
|
export declare function formatVec2(v: Vec2): string;
|
|
3
5
|
export declare function formatVec3(v: Vec3): string;
|
|
4
6
|
export declare function formatPoints2D(points: [number, number][]): string;
|
package/dist/utils.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
|
+
export function formatNumber(n) {
|
|
2
|
+
if (Number.isInteger(n))
|
|
3
|
+
return String(n);
|
|
4
|
+
const s = n.toFixed(6);
|
|
5
|
+
return s.replace(/\.?0+$/, "");
|
|
6
|
+
}
|
|
7
|
+
export function formatScadExpr(x) {
|
|
8
|
+
return typeof x === "number" ? formatNumber(x) : x;
|
|
9
|
+
}
|
|
1
10
|
export function formatVec2(v) {
|
|
2
11
|
if (typeof v === "number" || typeof v === "string")
|
|
3
|
-
return
|
|
4
|
-
return `[${
|
|
12
|
+
return formatScadExpr(v);
|
|
13
|
+
return `[${formatScadExpr(v[0])}, ${formatScadExpr(v[1])}]`;
|
|
5
14
|
}
|
|
6
15
|
export function formatVec3(v) {
|
|
7
16
|
if (typeof v === "number" || typeof v === "string")
|
|
8
|
-
return
|
|
9
|
-
return `[${
|
|
17
|
+
return formatScadExpr(v);
|
|
18
|
+
return `[${formatScadExpr(v[0])}, ${formatScadExpr(v[1])}, ${formatScadExpr(v[2])}]`;
|
|
10
19
|
}
|
|
11
20
|
export function formatPoints2D(points) {
|
|
12
|
-
return `[${points.map((p) => `[${p[0]}, ${p[1]}]`).join(", ")}]`;
|
|
21
|
+
return `[${points.map((p) => `[${formatNumber(p[0])}, ${formatNumber(p[1])}]`).join(", ")}]`;
|
|
13
22
|
}
|
|
14
23
|
export function formatPoints3D(points) {
|
|
15
|
-
return `[${points.map((p) => `[${p[0]}, ${p[1]}, ${p[2]}]`).join(", ")}]`;
|
|
24
|
+
return `[${points.map((p) => `[${formatNumber(p[0])}, ${formatNumber(p[1])}, ${formatNumber(p[2])}]`).join(", ")}]`;
|
|
16
25
|
}
|
|
17
26
|
export function formatFaces(faces) {
|
|
18
|
-
return `[${faces.map((f) => `[${f.join(", ")}]`).join(", ")}]`;
|
|
27
|
+
return `[${faces.map((f) => `[${f.map(formatNumber).join(", ")}]`).join(", ")}]`;
|
|
19
28
|
}
|