Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/modular-svg
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions src/examples.spec.ts → examples/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 4 additions & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
18 changes: 0 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 1 addition & 2 deletions src/output.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
3 changes: 1 addition & 2 deletions src/output.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
NodeRecord,
StackAlignment,
StackChild,
} from "./operators";
} from "./solver/operators";
import {
AlignXCenter,
AlignXCenterTo,
Expand All @@ -21,7 +21,7 @@ import {
DistributeY,
StackH,
StackV,
} from "./operators";
} from "./solver/operators";

export type JsonScene = { nodes: NodeRecord[]; operators: LayoutOperator[] };
type AnyNode = {
Expand Down
2 changes: 1 addition & 1 deletion src/align.spec.ts → src/solver/align.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/distribute.spec.ts → src/solver/distribute.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
19 changes: 19 additions & 0 deletions src/solver/index.ts
Original file line number Diff line number Diff line change
@@ -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";
File renamed without changes.
2 changes: 1 addition & 1 deletion src/property.spec.ts → src/solver/property.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/solver.ts → src/solver/solver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LayoutOperator, NodeRecord } from "./operators";
import type { LayoutOperator, NodeRecord } from ".";

export type Scene = {
nodes: NodeRecord[];
Expand Down
2 changes: 1 addition & 1 deletion src/stack.spec.ts → src/solver/stack.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down