diff --git a/bin/modular-svg b/bin/modular-svg index 477b203..2c67736 100755 --- a/bin/modular-svg +++ b/bin/modular-svg @@ -2,7 +2,12 @@ import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; -import { buildSceneFromJson, solveLayout, layoutToSvg, validate } from "../src/index.ts"; +import { + buildSceneFromJson, + layoutToSvg, + solveLayout, + validate, +} from "../src/index.ts"; async function readInput(arg) { diff --git a/src/examples.spec.ts b/examples/examples.spec.ts similarity index 77% rename from src/examples.spec.ts rename to examples/examples.spec.ts index 7085ce7..92db615 100644 --- a/src/examples.spec.ts +++ b/examples/examples.spec.ts @@ -2,10 +2,9 @@ import { readdirSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; -import { validate } from "./parser"; +import { validate } from "../src/parser"; -const base = dirname(fileURLToPath(import.meta.url)); -const examplesDir = join(base, "../examples"); +const examplesDir = dirname(fileURLToPath(import.meta.url)); describe("example json files", () => { for (const file of readdirSync(examplesDir)) { diff --git a/src/builder.ts b/src/builder.ts index 90ff67f..908036e 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1,5 +1,8 @@ // Helper functions to build JSON scene descriptions in a Bluefish-like style -import { buildSceneFromJson, layoutToSvg, solveLayout } from "./index"; + +import { layoutToSvg } from "./output"; +import { buildSceneFromJson } from "./parser"; +import { solveLayout } from "./solver"; let counter = 0; function uid(prefix: string): string { diff --git a/src/index.ts b/src/index.ts index 65f18b2..0617323 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,4 @@ export * from "./builder"; -export { - AlignXCenter, - AlignXCenterTo, - AlignXLeft, - AlignXRight, - AlignYBottom, - AlignYCenter, - AlignYTop, - BackgroundOp, - DistributeX, - DistributeY, - type LayoutOperator, - type NodeRecord, - type StackAlignment, - type StackChild, - StackH as StackHOp, - StackV as StackVOp, -} from "./operators"; export * from "./output"; export * from "./parser"; export * from "./solver"; diff --git a/src/output.spec.ts b/src/output.spec.ts index 10ca85b..4b3c624 100644 --- a/src/output.spec.ts +++ b/src/output.spec.ts @@ -1,7 +1,6 @@ import { describe, expect, it } from "vitest"; -import type { NodeRecord } from "./operators"; import { layoutToSvg } from "./output"; -import type { LayoutResult } from "./solver"; +import type { LayoutResult, NodeRecord } from "./solver"; describe("layoutToSvg", () => { it("creates an svg sized to fit all boxes", () => { diff --git a/src/output.ts b/src/output.ts index beba6b7..5dde302 100644 --- a/src/output.ts +++ b/src/output.ts @@ -1,5 +1,4 @@ -import type { NodeRecord } from "./operators"; -import type { LayoutResult } from "./solver"; +import type { LayoutResult, NodeRecord } from "./solver"; export function xml( tag: string, diff --git a/src/parser.ts b/src/parser.ts index 62d8917..995f156 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -7,7 +7,7 @@ import type { NodeRecord, StackAlignment, StackChild, -} from "./operators"; +} from "./solver/operators"; import { AlignXCenter, AlignXCenterTo, @@ -21,7 +21,7 @@ import { DistributeY, StackH, StackV, -} from "./operators"; +} from "./solver/operators"; export type JsonScene = { nodes: NodeRecord[]; operators: LayoutOperator[] }; type AnyNode = { diff --git a/src/align.spec.ts b/src/solver/align.spec.ts similarity index 94% rename from src/align.spec.ts rename to src/solver/align.spec.ts index b26d9d9..d839aa9 100644 --- a/src/align.spec.ts +++ b/src/solver/align.spec.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; +import { solveLayout } from "."; import type { LayoutOperator, NodeRecord } from "./operators"; import { AlignXLeft } from "./operators"; -import { solveLayout } from "./solver"; describe("Align operator", () => { it("aligns multiple nodes to the leftmost X", () => { diff --git a/src/distribute.spec.ts b/src/solver/distribute.spec.ts similarity index 94% rename from src/distribute.spec.ts rename to src/solver/distribute.spec.ts index 8e76cc6..c3b1b5f 100644 --- a/src/distribute.spec.ts +++ b/src/solver/distribute.spec.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; +import { solveLayout } from "."; import type { LayoutOperator, NodeRecord } from "./operators"; import { DistributeX } from "./operators"; -import { solveLayout } from "./solver"; describe("Distribute operator", () => { it("distributes points evenly", () => { diff --git a/src/solver/index.ts b/src/solver/index.ts new file mode 100644 index 0000000..050612c --- /dev/null +++ b/src/solver/index.ts @@ -0,0 +1,19 @@ +export { + AlignXCenter, + AlignXCenterTo, + AlignXLeft, + AlignXRight, + AlignYBottom, + AlignYCenter, + AlignYTop, + BackgroundOp, + DistributeX, + DistributeY, + type LayoutOperator, + type NodeRecord, + type StackAlignment, + type StackChild, + StackH as StackHOp, + StackV as StackVOp, +} from "./operators"; +export * from "./solver"; diff --git a/src/operators.ts b/src/solver/operators.ts similarity index 100% rename from src/operators.ts rename to src/solver/operators.ts diff --git a/src/property.spec.ts b/src/solver/property.spec.ts similarity index 97% rename from src/property.spec.ts rename to src/solver/property.spec.ts index 35ed896..818584c 100644 --- a/src/property.spec.ts +++ b/src/solver/property.spec.ts @@ -1,8 +1,8 @@ import fc from "fast-check"; import { describe, it } from "vitest"; +import { solveLayout } from "."; import type { LayoutOperator, NodeRecord } from "./operators"; import { AlignXLeft, DistributeX } from "./operators"; -import { solveLayout } from "./solver"; describe("property based primitives", () => { it("align left sets all x to min", () => { diff --git a/src/solver.ts b/src/solver/solver.ts similarity index 96% rename from src/solver.ts rename to src/solver/solver.ts index 44a901e..a029162 100644 --- a/src/solver.ts +++ b/src/solver/solver.ts @@ -1,4 +1,4 @@ -import type { LayoutOperator, NodeRecord } from "./operators"; +import type { LayoutOperator, NodeRecord } from "."; export type Scene = { nodes: NodeRecord[]; diff --git a/src/stack.spec.ts b/src/solver/stack.spec.ts similarity index 96% rename from src/stack.spec.ts rename to src/solver/stack.spec.ts index fb661bb..7d5dfd3 100644 --- a/src/stack.spec.ts +++ b/src/solver/stack.spec.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; +import { solveLayout } from "."; import type { LayoutOperator, NodeRecord } from "./operators"; import { StackV } from "./operators"; -import { solveLayout } from "./solver"; describe("Stack operator", () => { it("stacks children vertically with spacing and centers them", () => {