Skip to content

Commit

Permalink
[docs] Update Vite sample code.
Browse files Browse the repository at this point in the history
Even Vite 3 still seems to have issues: vitejs/vite#9062 (comment)
  • Loading branch information
lgarron committed Jul 18, 2022
1 parent ae6b384 commit b3d2294
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 100 deletions.
4 changes: 2 additions & 2 deletions docs/cubing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ <h2>Compatibility</h2>
The <code>npm</code> package should work with any modern bundlers and tools. If you are having trouble, <b>make sure your tool is compatible with ES2020 syntax</b>. We recommend using <a href="https://esbuild.github.io/"><code>esbuild</code></a> or tools based on <code>esbuild</code>, and you may find <a href="https://github.com/cubing/cubing-app-template">this project template</a> a helpful start.
</p>
<h3>Known Issues</h3>
<p><a href="https://vitejs.dev/">Vite</a> 3 does not support full ES2020 by default. Use the following config:</p>
<p><a href="https://vitejs.dev/">Vite</a> does not support full ES2020 by default. Use the following config:</p>
<code class="sample">
// vite.config.js<br>
export default {build: {target: "es2020"}};
export default { optimizeDeps: { esbuildOptions: { target: "es2020" } } };
</code>
</section>

Expand Down
26 changes: 13 additions & 13 deletions src/cubing/alg/Alg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { experimentalIs, experimentalIsUnit } from "./is";
import { direct, IterationDirection, reverse } from "./iteration";
import { parseAlg } from "./parse";
import { simplify, SimplifyOptions } from "./traversal";
import { Grouping, Pause } from "./units";
import { LineComment } from "./units/leaves/LineComment";
import { Move } from "./units/leaves/Move";
import { Newline } from "./units/leaves/Newline";
import type { LeafUnit, Unit } from "./units/Unit";
import { Grouping, Pause } from "./alg-nodes";
import { LineComment } from "./alg-nodes/leaves/LineComment";
import { Move } from "./alg-nodes/leaves/Move";
import { Newline } from "./alg-nodes/leaves/Newline";
import type { AlgLeafNode, AlgNode } from "./alg-nodes/AlgNode";
import { warnOnce } from "./warnOnce";

export type FlexibleAlgSource = string | Iterable<Unit> | Alg;
export type FlexibleAlgSource = string | Iterable<AlgNode> | Alg;

// TODO: validate
function toIterable(input?: FlexibleAlgSource): Iterable<Unit> {
function toIterable(input?: FlexibleAlgSource): Iterable<AlgNode> {
if (!input) {
return [];
}
Expand All @@ -34,7 +34,7 @@ function toIterable(input?: FlexibleAlgSource): Iterable<Unit> {
// // return seq.nestedUnits;
// }

const iter = input as Iterable<Unit>;
const iter = input as Iterable<AlgNode>;
if (typeof iter[Symbol.iterator] === "function") {
return iter; // TODO: avoid allocations
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export function experimentalEnsureAlg(alg: FlexibleAlgSource): Alg {
*/
export class Alg extends AlgCommon<Alg> {
// #debugString: string;
#units: Iterable<Unit>; // TODO: freeze?
#units: Iterable<AlgNode>; // TODO: freeze?
constructor(alg?: FlexibleAlgSource) {
super();
this.#units = Array.from(toIterable(alg)); // TODO: can we avoid array-casting?
Expand Down Expand Up @@ -159,7 +159,7 @@ export class Alg extends AlgCommon<Alg> {
*experimentalExpand(
iterDir: IterationDirection = IterationDirection.Forwards,
depth?: number,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
depth ??= Infinity;
for (const unit of direct(this.#units, iterDir)) {
yield* unit.experimentalExpand(iterDir, depth);
Expand Down Expand Up @@ -221,7 +221,7 @@ export class Alg extends AlgCommon<Alg> {
return parseAlg(s);
}

*units(): Generator<Unit> {
*units(): Generator<AlgNode> {
for (const unit of this.#units) {
yield unit;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ export class Alg extends AlgCommon<Alg> {
*/
toString(): string {
let output = "";
let previousVisibleUnit: Unit | null = null;
let previousVisibleUnit: AlgNode | null = null;
for (const unit of this.#units) {
if (previousVisibleUnit) {
output += spaceBetween(previousVisibleUnit, unit);
Expand Down Expand Up @@ -293,7 +293,7 @@ export class Alg extends AlgCommon<Alg> {
}
}

function spaceBetween(u1: Unit, u2: Unit): string {
function spaceBetween(u1: AlgNode, u2: AlgNode): string {
if (u1.is(Newline) || u2.is(Newline)) {
return "";
}
Expand Down
6 changes: 3 additions & 3 deletions src/cubing/alg/AlgBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Alg } from "./Alg";
import type { Unit } from "./units/Unit";
import type { AlgNode } from "./alg-nodes/AlgNode";

/** @category Alg */
export class AlgBuilder {
#units: Unit[] = [];
#units: AlgNode[] = [];

push(u: Unit): void {
push(u: AlgNode): void {
this.#units.push(u);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Move } from "./leaves/Move";
import type { Newline } from "./leaves/Newline";
import type { Pause } from "./leaves/Pause";

export type LeafUnit = Move | LineComment | Newline | Pause;
export type AlgLeafNode = Move | LineComment | Newline | Pause;

/** @category Alg */
export type Unit = LeafUnit | Grouping | Conjugate | Commutator;
export type AlgNode = AlgLeafNode | Grouping | Conjugate | Commutator;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Repeatable } from "../common";
import { IterationDirection, toggleDirection } from "../iteration";
import { MAX_INT, MAX_INT_DESCRIPTION, MIN_INT } from "../limits";
import type { LeafUnit } from "./Unit";
import type { AlgLeafNode } from "./AlgNode";

export class QuantumWithAmount<Q extends Repeatable> {
readonly quantum: Q;
Expand Down Expand Up @@ -45,7 +45,7 @@ export class QuantumWithAmount<Q extends Repeatable> {
*experimentalExpand(
iterDir: IterationDirection,
depth: number,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
const absAmount = Math.abs(this.amount);
const newIterDir = toggleDirection(iterDir, this.amount < 0);
for (let i = 0; i < absAmount; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Alg, experimentalEnsureAlg, FlexibleAlgSource } from "../../Alg";
import { AlgCommon, Comparable } from "../../common";
import { IterationDirection } from "../../iteration";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

/** @category Alg Units */
/** @category Alg Nodes */
export class Commutator extends AlgCommon<Commutator> {
readonly #A: Alg;
readonly #B: Alg;
Expand Down Expand Up @@ -37,7 +37,7 @@ export class Commutator extends AlgCommon<Commutator> {
*experimentalExpand(
iterDir: IterationDirection = IterationDirection.Forwards,
depth?: number,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
depth ??= Infinity;
if (depth === 0) {
yield iterDir === IterationDirection.Forwards ? this : this.invert();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Alg, experimentalEnsureAlg, FlexibleAlgSource } from "../../Alg";
import { AlgCommon, Comparable } from "../../common";
import { IterationDirection } from "../../iteration";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

/** @category Alg Units */
/** @category Alg Nodes */
export class Conjugate extends AlgCommon<Conjugate> {
readonly #A: Alg;
readonly #B: Alg;
Expand Down Expand Up @@ -37,7 +37,7 @@ export class Conjugate extends AlgCommon<Conjugate> {
*experimentalExpand(
iterDir: IterationDirection,
depth?: number,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
depth ??= Infinity;
if (depth === 0) {
yield iterDir === IterationDirection.Forwards ? this : this.invert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IterationDirection } from "../../iteration";
import { Move, QuantumMove } from "../leaves/Move";
import type { Pause } from "../leaves/Pause";
import { QuantumWithAmount } from "../QuantumWithAmount";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

// This is a workaround for `jest`, which doesn't handle cycles of imports inside `cubing/alg`.
// We need to lazy-initialize the reusable quantum moves for Square-1, so we create this wrapper for it.
Expand Down Expand Up @@ -44,7 +44,7 @@ class Square1TupleFormatter {
}
const square1TupleFormatterInstance = new Square1TupleFormatter();

/** @category Alg Units */
/** @category Alg Nodes */
export class Grouping extends AlgCommon<Grouping> {
readonly #quantumWithAmount: QuantumWithAmount<Alg>;
experimentalNISSPlaceholder?: Pause; // TODO: tie this to the alg
Expand Down Expand Up @@ -86,7 +86,7 @@ export class Grouping extends AlgCommon<Grouping> {
*experimentalExpand(
iterDir: IterationDirection = IterationDirection.Forwards,
depth?: number,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
depth ??= Infinity;
if (depth === 0) {
yield iterDir === IterationDirection.Forwards ? this : this.invert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export { Conjugate } from "./containers/Conjugate";
export { Move, QuantumMove } from "./leaves/Move";
export { Newline } from "./leaves/Newline";
export { Pause } from "./leaves/Pause";
export type { Unit } from "./Unit";
import type { AlgNode } from "./AlgNode";

export { AlgNode };
/** @deprecated */
export type Unit = AlgNode;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AlgCommon, Comparable } from "../../common";
import { IterationDirection } from "../../iteration";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

// TODO: hash
// TODO: this conflicts with the HTML `LineComment` class
/** @category Alg Units */
/** @category Alg Nodes */
export class LineComment extends AlgCommon<LineComment> {
readonly #text: string;

Expand Down Expand Up @@ -32,7 +32,7 @@ export class LineComment extends AlgCommon<LineComment> {
*experimentalExpand(
_iterDir: IterationDirection = IterationDirection.Forwards,
_depth: number = Infinity,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
yield this;
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MAX_INT, MAX_INT_DESCRIPTION } from "../../limits";
import { parseMove, parseQuantumMove, transferCharIndex } from "../../parse";
import { warnOnce } from "../../warnOnce";
import { QuantumWithAmount } from "../QuantumWithAmount";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

interface QuantumMoveModifications {
outerLayer?: number;
Expand Down Expand Up @@ -108,7 +108,7 @@ export class QuantumMove extends Comparable {
return this.#innerLayer;
}

experimentalExpand(): Generator<LeafUnit> {
experimentalExpand(): Generator<AlgLeafNode> {
throw new Error(
"experimentalExpand() cannot be called on a `QuantumMove` directly.",
);
Expand All @@ -133,7 +133,7 @@ export interface MoveModifications {
amount?: number;
}

/** @category Alg Units */
/** @category Alg Nodes */
export class Move extends AlgCommon<Move> {
readonly #quantumWithAmount: QuantumWithAmount<QuantumMove>;

Expand Down Expand Up @@ -176,7 +176,7 @@ export class Move extends AlgCommon<Move> {

*experimentalExpand(
iterDir: IterationDirection = IterationDirection.Forwards,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
if (iterDir === IterationDirection.Forwards) {
yield this;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AlgCommon, Comparable } from "../../common";
import { IterationDirection } from "../../iteration";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

/** @category Alg Units */
/** @category Alg Nodes */
export class Newline extends AlgCommon<Newline> {
toString(): string {
return `\n`;
Expand All @@ -19,7 +19,7 @@ export class Newline extends AlgCommon<Newline> {
*experimentalExpand(
_iterDir: IterationDirection = IterationDirection.Forwards,
_depth: number = Infinity,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
yield this;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Grouping } from "..";
import { AlgCommon, Comparable } from "../../common";
import { IterationDirection } from "../../iteration";
import type { LeafUnit } from "../Unit";
import type { AlgLeafNode } from "../AlgNode";

/** @category Alg Units */
/** @category Alg Nodes */
export class Pause extends AlgCommon<Pause> {
experimentalNISSGrouping?: Grouping; // TODO: tie this to the alg

Expand All @@ -22,7 +22,7 @@ export class Pause extends AlgCommon<Pause> {
*experimentalExpand(
_iterDir: IterationDirection = IterationDirection.Forwards,
_depth: number = Infinity,
): Generator<LeafUnit> {
): Generator<AlgLeafNode> {
yield this;
}
}
10 changes: 6 additions & 4 deletions src/cubing/alg/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Alg } from "./Alg";
import type { IterationDirection } from "./iteration";
import type { LeafUnit, Unit } from "./units/Unit";
import type { AlgLeafNode, AlgNode } from "./alg-nodes/AlgNode";

let writeAlgDebugField = false;
export function setAlgDebugField(debug: boolean): void {
Expand All @@ -24,11 +24,11 @@ export interface Repeatable extends Comparable {
experimentalExpand(
iterDir?: IterationDirection,
depth?: number,
): Generator<LeafUnit>;
): Generator<AlgLeafNode>;
}

// Common to algs or units
export abstract class AlgCommon<T extends Alg | Unit>
export abstract class AlgCommon<T extends Alg | AlgNode>
extends Comparable
implements Repeatable
{
Expand All @@ -55,5 +55,7 @@ export abstract class AlgCommon<T extends Alg | Unit>

abstract invert(): T;

abstract experimentalExpand(iterDir: IterationDirection): Generator<LeafUnit>;
abstract experimentalExpand(
iterDir: IterationDirection,
): Generator<AlgLeafNode>;
}
10 changes: 5 additions & 5 deletions src/cubing/alg/example.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// tslint:disable-next-line no-namespace // TODO: nested module

import { Alg } from "./Alg";
import { Grouping } from "./units";
import { Commutator } from "./units/containers/Commutator";
import { Conjugate } from "./units/containers/Conjugate";
import { Move } from "./units/leaves/Move";
import { Pause } from "./units/leaves/Pause";
import { Grouping } from "./alg-nodes";
import { Commutator } from "./alg-nodes/containers/Commutator";
import { Conjugate } from "./alg-nodes/containers/Conjugate";
import { Move } from "./alg-nodes/leaves/Move";
import { Pause } from "./alg-nodes/leaves/Pause";

// eslint-disable-next-line @typescript-eslint/no-namespace
export const Example = {
Expand Down
4 changes: 2 additions & 2 deletions src/cubing/alg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export { AlgBuilder } from "./AlgBuilder";
export { TraversalDownUp, TraversalUp } from "./traversal";
export { Example } from "./example";
export { keyToMove } from "./keyboard";
export * from "./units";
export { MoveModifications } from "./units/leaves/Move";
export * from "./alg-nodes";
export { MoveModifications } from "./alg-nodes/leaves/Move";

export { algCubingNetLink } from "./url";
export type { AlgCubingNetOptions } from "./url";
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/alg/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Move,
Newline,
Pause,
} from "./units";
} from "./alg-nodes";

export function experimentalIs(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/alg/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Move } from "./units/leaves/Move";
import { Move } from "./alg-nodes/leaves/Move";

const cubeKeyMapping: { [key: number]: Move } = {
73: new Move("R"),
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/alg/operation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alg } from "./Alg";
import { experimentalAppendMove } from "./operation";
import { Move } from "./units";
import { Move } from "./alg-nodes";
import "./test/alg-comparison";

describe("operation", () => {
Expand Down

0 comments on commit b3d2294

Please sign in to comment.