-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.ts
145 lines (127 loc) · 3.89 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { ParseMode } from "./xdparser2"
export type CrosswordJSON = {
/** Info to display about the Crossword */
meta: {
title: string
author: string
editor: string
date: string
splitCharacter?: string
} & Record<string, string>
/** 2 dimensional array of tiles */
tiles: Tile[][]
/** Derived clue info with positioning for the xword */
clues: {
across: Clue[]
down: Clue[]
}
/** Anything which lives in the notes section */
notes: string
/** A sparse array of pre-filled letters */
start?: string[][]
/** A Key : Value list of rebus tiles */
rebuses: Record<string, string>
/** An after the puzzle is done question */
metapuzzle?: {
clue: string
answer: string
}
/** Aesthetics */
design?: {
/** CSS-like selectors */
styles: Record<string, any>
/** A sparse array of strings for where the design elements should exist */
positions: string[][]
}
/** Info generated during parse which can be passed when
* figuring out what is under the cursor. There is an argument in xdToJSON
* which will have this info included in the results. */
editorInfo?: EditorInfo
/** A summary of the parse */
report: {
/** Did we parse successfully */
success: boolean
/** Errors are 'this syntax is wrong' */
errors: Report[]
/** Lint warnings which are general 'hey should you be doing this?' */
warnings: Report[]
}
}
export type Report =
| { type: "syntax"; position: Position; length: number; message: string }
| {
type: "clue_msg"
position: Position
length: number
clueNum: number | unknown
clueType: "across" | "down" | unknown
message: string
}
export type EditorInfo = {
/** Positioning for the blocks of xd content */
sections: Array<{ startLine: number; endLine: number; type: ParseMode }>
/** The original lines which were separated by '/n' so you can work directly
* against the input instead of keeping a potentially outdated reference to the text */
lines: string[]
}
export type Direction = "UP" | "DOWN" | "LEFT" | "RIGHT"
export type Tile = LetterTile | BlankTile | RebusTile
export interface LetterTile {
letter: string
type: "letter"
clues?: {
across?: number
down?: number
}
}
export interface RebusTile {
word: string
symbol: string
type: "rebus"
clues?: {
across?: number
down?: number
}
}
interface BlankTile {
type: "blank"
}
export interface Position {
col: number
index: number
}
// Inline elements to handle when rendering clues
export type MDClueComponent =
| [type: "text", text: string]
| [type: "italics", text: string]
| [type: "bold", text: string]
| [type: "strike", text: string]
| [type: "link", text: string, to: string]
export interface Clue {
/** The "clue" as it were */
body: string
/** The body as a set of inline markdown components, not a full markdown processor, but a simple enough heuristic */
bodyMD?: MDClueComponent[]
/** The number, whether it is across or down is handled back at 'clues' */
number: number
/** The string after the "~"" - if the clue has a split character than this will not be included */
answer: string
/** Filled in metadata giving the location of the first char on the grid */
position: Position
/** tiles that the clue is composed of */
tiles: Tile[]
/** If an answer contains a split character, then this would include the indexes where it was used */
splits?: number[]
/** Duplicating a clue and using a meta suffix (e.g. "A23~Hint. A shot to the heart" )
* would add to { "hint": " A shot to the heart" } to the metadata.
*/
metadata?: Record<string, string>
}
export interface Cursor {
/** What tile is selected */
position: Position
/** The direction they are writing */
direction: CursorDirection
}
export type CursorDirection = "down" | "across"
export type ClueState = "empty" | "partial" | "incorrect" | "correct"