From 2f642a660753595cb14601ea2f78cc1885360fad Mon Sep 17 00:00:00 2001 From: Werner Stein Date: Wed, 18 Nov 2026 10:27:48 +0000 Subject: [PATCH 1/6] feat(notation): add the Orbit64 V2 state token for sizes 2 to 15 Orbit64Token.res writes and reads the V2 color framed token through the facelet bridge. Tokens of sizes 2, 3, 4, 6 and 7 equal the V1 strings. Co-Authored-By: Claude Sonnet 5.5 --- src/cube/notation/Orbit64Token.res | 57 +++++++++++++++++++++++++++++ src/cube/notation/Orbit64Token.resi | 4 ++ src/cube/notation/orbit64Token.ts | 19 ++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/cube/notation/Orbit64Token.res create mode 100644 src/cube/notation/Orbit64Token.resi create mode 100644 src/cube/notation/orbit64Token.ts diff --git a/src/cube/notation/Orbit64Token.res b/src/cube/notation/Orbit64Token.res new file mode 100644 index 00000000..e15e72e5 --- /dev/null +++ b/src/cube/notation/Orbit64Token.res @@ -0,0 +1,57 @@ +// The Orbit64 state token of the app: V2, color model, framed pose, for cubes +// of size 2..15. A framed color token keeps the whole-cube orientation, so a +// cube read from the facelets round-trips with its orientation. Tokens of the +// V1 format of sizes 2, 3, 4, 6 and 7 are the same strings. Format: +// FORMAT-V2.md of flix-orbit64 (Apache-2.0); the codec is in Orbit64V2.res and +// Orbit64V2Facelets.res. + +let minSize = 2 +let maxSize = 15 + +// The V1 token of a 5x5 cube had 43 characters; V2 does not read it. It is +// still recognized as a token so the reader can say why it is refused. +let legacyFiveWidth = 43 + +let tokenPattern = RegExp.fromString("^[A-Za-z0-9_-]+$") + +let sizeOfFacelets = text => { + let compact = text->String.replaceAllRegExp(/\s+/g, "") + let perFace = String.length(compact) / 6 + let n = perFace->Int.toFloat->Math.sqrt->Int.fromFloat + String.length(compact) == 6 * perFace && n * n == perFace && n >= minSize && n <= maxSize + ? Some(n) + : None +} + +let framedColorId = n => + Orbit64V2.entries + ->Array.find(entry => entry.n == n && entry.model == Color && entry.pose == Framed) + ->Option.map(entry => entry.id) + +// True for a token of a registered V2 length, and for the V1 5x5 length. +@genType +let looksLikeToken = input => { + let token = String.trim(input) + tokenPattern->RegExp.test(token) && + (String.length(token) == legacyFiveWidth || + Orbit64V2.entries->Array.some(entry => entry.length == String.length(token))) +} + +// The token of a cube given as facelets (six blocks in U R F D L B order, +// letters U R F D L B), or null when the facelets are no reachable cube. +@genType +let encodeState = facelets => + sizeOfFacelets(facelets) + ->Option.flatMap(framedColorId) + ->Option.flatMap(id => + Orbit64V2Facelets.encodeFacelets(id, facelets)->Result.mapOr(None, token => Some(token)) + ) + ->Null.fromOption + +// The facelets a token shows, or null when it is no color-model V2 token. +@genType +let decodeState = token => + switch Orbit64V2Facelets.decodeFacelets(String.trim(token)) { + | Ok({entry, facelets}) if entry.model == Color => Some(facelets) + | _ => None + }->Null.fromOption diff --git a/src/cube/notation/Orbit64Token.resi b/src/cube/notation/Orbit64Token.resi new file mode 100644 index 00000000..c4f2685e --- /dev/null +++ b/src/cube/notation/Orbit64Token.resi @@ -0,0 +1,4 @@ +// The Orbit64 state token of the app: V2, color model, framed pose, 2x2-15x15. +@genType let looksLikeToken: string => bool +@genType let encodeState: string => Null.t +@genType let decodeState: string => Null.t diff --git a/src/cube/notation/orbit64Token.ts b/src/cube/notation/orbit64Token.ts new file mode 100644 index 00000000..8fe06c49 --- /dev/null +++ b/src/cube/notation/orbit64Token.ts @@ -0,0 +1,19 @@ +// Orbit64 state tokens of the app (V2, color model, framed pose) for cubes of +// size 2..15: typed entry point for the ReScript module (Orbit64Token.res). +import { + decodeState, + encodeState, + looksLikeToken, +} from './Orbit64Token.gen' + +export function looksLikeOrbit64Token(input: string): boolean { + return looksLikeToken(input) +} + +export function encodeOrbit64Token(facelets: string): string | null { + return encodeState(facelets) +} + +export function decodeOrbit64Token(token: string): string | null { + return decodeState(token) +} From 065131293dbe4db763afa71a84b6960f8de6234b Mon Sep 17 00:00:00 2001 From: Werner Stein Date: Wed, 18 Nov 2026 10:28:46 +0000 Subject: [PATCH 2/6] feat(app): show and read the Orbit64 V2 token for sizes 2 to 15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The notation card writes a token for every size, the typed-input reader decodes V2 tokens, and the texts say 2×2–15×15. The UI-layer tests round-trip token and facelets for every size. Co-Authored-By: Claude Sonnet 5.5 --- docs/user-guide.md | 2 +- src/client/manualFaceletInput.tsx | 2 +- src/client/notationCard.tsx | 12 +++- src/core/capture/CaptureFlow.res | 6 +- src/cube/notation/orbit64Token.ts | 6 +- test/captureFlow.test.ts | 4 +- test/orbit64Token.test.ts | 105 ++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 test/orbit64Token.test.ts diff --git a/docs/user-guide.md b/docs/user-guide.md index 4792c00e..b0854abe 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -168,5 +168,5 @@ Typing facelets never changes the format the notation panel shows: that is the set on the settings page. Input made only of R and B letters fits both formats and is read in that saved format. The notation panel can also copy an [Orbit64.Net](https://github.com/wstein/flix-orbit64/blob/main/FORMAT.md#spaced-facelet-reference-vectors) -compact state token for 2×2–7×7. Paste facelets or a state token into **Type +compact state token (format V2) for 2×2–15×15. Paste facelets or a state token into **Type colors**; move and algorithm tokens are separate formats and are not accepted. diff --git a/src/client/manualFaceletInput.tsx b/src/client/manualFaceletInput.tsx index 725b1b5d..3f290cdd 100644 --- a/src/client/manualFaceletInput.tsx +++ b/src/client/manualFaceletInput.tsx @@ -21,7 +21,7 @@ export function ManualFaceletInput({

{`6 blocks of ${size * size} letters in U R F D L B order, space-separated - face letters (U, R, F, D, L, B: the face each sticker's color matches when solved) or colors (W, O, G, R, B, Y). The format is detected.`}{' '} - You can also paste an Orbit64 2×2–7×7 state token. + You can also paste an Orbit64 2×2–15×15 state token.