Puzzle.js Reference: Options

Note: while Puzzle.js puzzles store their state locally (via localStorage), that behavior is inhibited on this page to make it easiest to see exactly what markup produces exactly what result.

Options Model

Puzzle.js puzzles are configured by a wide variety of options. These options can be set in three ways:

Modes

Remember that a mode is nothing more than an amalgamation of property values. As such, every characteristic of a mode can be overridden.

The default mode is always included, and names all options that can be defined.

The linear mode is used for single lines of text. Boxes are drawn only around editable characters.

The crossword mode builds crosswords with automatic clue numbering.

The notext mode prevents text input in the cells.

The sudoku mode makes a 9x9 grid with 3x3 regions. Characters are constrained to digits, which can be toggled on and off.

The pathpaint mode allows dragging (or shift-arrowing) between cells to draw paths and propagate fills.

The trains mode allows dragging (or shift-arrowing) between cells to create train tracks.

The slitherlink mode allows dragging (or shift-arrowing) between dots to draw edges.

The spokes mode allows dragging (or shift-arrowing) between cells to draw intersecting lines. The primary difference between spokes and paths are that spokes can emanate from any (or all) 8 directions from within any cell, allowing them to appear to intersect or cross existing spokes.

{ "data-spokes": [ "......'", ".*-*-*.", "..`.X|.", ".*.*.*.", "..'.`|.", ".*.*.*.", "'......" ] }

The slant mode is a specialized version of spokes that only allows drawing in diagonal directions.

The bridges mode is another specialized version of spokes that cycles through single and then double spokes.

The solution mode turns off all input, so that a solution can be displayed.

Options

The starting text for the puzzle cells. data-text can be any of the following:

Characters are written into the puzzle cells, with the following characters getting special treatment:

A cell can also be given contents that are larger than a single character, using data-text-replacements.

A way to replace a single character in the data-text option with a string of any length.

Currently, the only way to specify this option is with a JSON object using its key-value features.

{ "data-text-replacements": { "E": "11", "T": "13", "S": "17", "N": "19", "W": "23" } }

The set of valid characters that can be provided in text input. Set it to "" to reject all text input.

Sets shift key behavior when typing letters. There are two types of behavior:

Acts as if the Shift key is always pressed, yielding data-text-shift-key behavior on every keystroke even if Shift is not actually pressed.

Provides a string of characters forming the solution for the puzzle. Useful when the data-text option includes special characters that otherwise make it impossible to put the entire solution there.

data-text-solution can be any of the following:

Specifies whether the cell advances/retreats when typing and/or pressing backspace. When set, clicking a cell or pressing Space changes the character navigation direction from horizontal to vertical (unless there is only one row or column of text).

Specifies a set of classes that can be used to provide background fills for cells. By default, clicking a cell will cycle through these classes.

Specifies a background fill for each cell based on the classes provided by data-fill-classes. There are two types of values that can be specified per character:

data-fills can be any of the following:

Specifies whether click/spacebar on a cell will cycle through the available fills specified in data-fill-classes. The default behavior is to cycle, but the pathpaint mode does not use the cycling behavior.

Specifies a set of interior paths between cells.

data-paths can be any of the following:

data-paths also has two types of specification:

{ "data-paths": [ ".|...|.", ".*.*.*.", ".|...|.", "-*-*-*-", ".|...|.", ".*.*.*.", ".|...|." ] }

Specifies the maximum number of path directions that can emanate from a cell. If left blank, then all directions are allowed. If the value is 1, then cells can be paired but longer chains will not be possible. If the value is 2, then chains of any length can be drawn. All other numeric values are also allowed, if you have a use for them.

Specifies the way the path is drawn. Three drawing styles are provided: straight, curved, and track.

If the value ends in .svg, it is assumed to be a custom svg file for rendering paths and the svg is located with a file path relative to the puzzle page. See more information in the Styling Reference.

Specifies a set of exterior edges between cells.

data-edges can be any of the following:

data-edges also has two types of specification:

{ "data-edges": [ "|------", "|*.*.*.", "|-----|", ".*.*.*|", "|-----|", "|*.*.*.", "|------" ] }

Specifies the way the edges and bounding box are drawn. Four drawing styles are provided: box, dots, dash, and none.

If the value ends in .svg, it is assumed to be a custom svg file for rendering edges and the svg is located with a file path relative to the puzzle page. See more information in the Styling Reference.

{ "data-edges": [ "|------", "|*.*.*.", "|-----|", ".*.*.*|", "|-----|", "|*.*.*.", "|------" ] }

Specifies an initial set of spokes between cells.

data-spokes can be any of the following:

Either way, the lines must represent a (2m+1) by (2n+1) grid where the centers are represented by any character (though * is a good idea) and spoke segments are represented by:

{ "data-spokes": [ "......'", ".*-*-*.", "..`.X|.", ".*.*.*.", "..'.`|.", ".*.*.*.", "'......" ] }

Specifies the maximum number of spokes that can emanate from a cell. If left blank, then all directions are allowed. If the value is 1, then cells can be paired but longer chains will not be possible. If the value is 2, then chains of any length can be drawn. All other numeric values are also allowed, if you have a use for them.

Limits the directions spokes can be drawn from. The default value of * allows all directions. If a value of + is used, only cardinal directions are allowed. If a value of x is used, only diagonal directions are allowed.

The amount of different types of spokes to cycle through each time a spoke is drawn, similar to the way data-fill-cycle operates. The default value of 1 draws a single spoke and then erases it when drawn again. The value of 2 will draw over a single spoke with a double spoke, which is provided in the default spoke svg files, then erases it when drawn over again. Up to 15 levels are supported, but anything beyond the cardinal directional double spokes require custom svg files.

Specifies the way the spokes are drawn. Two drawing styles are provided: solid and dash.

If the value ends in .svg, it is assumed to be a custom svg file for rendering spokes and the svg is located with a file path relative to the puzzle page. See more information in the Styling Reference.

{ "data-spokes": [ "......'", ".*-*-*.", "..`.X|.", ".*.*.*.", "..'.`|.", ".*.*.*.", "'......" ] }

Clue numbers are the numbers that go in the upper left corner of crossword cells, KenKen cells, etc.

This property has three formats:

If the puzzle contains an element with a class of crossword-clues across or crossword-clues down, li clues within an ol element will be synchronized with the clue numbers.

Across
  1. Dad
  2. Home for lions
  3. Not off
Down
  1. Ink-based writing device
  2. English article
  3. Haircut

Clue indicators are the text (usually numbers) that go in the upper left corner of crossword cells, KenKen cells, etc.

This property has two formats:

Specifies clues along the top of the puzzle. Clues for each column are separated by | characters, and multiple clues per column are separated by spaces.

Specifies clues along the bottom of the puzzle. Clues for each column are separated by | characters, and multiple clues per column are separated by spaces.

Specifies clues along the left of the puzzle. Clues for each row are separated by | characters, and multiple clues per column are separated by spaces.

Specifies clues along the right of the puzzle. Clues for each row are separated by | characters, and multiple clues per column are separated by spaces.

Specifies whether a dragging operation will continue to paint cells with the fill from the cell that was originally clicked.

Specifies whether a dragging operation will draw an interior path between cells.

Specifies whether a dragging operation will draw an exterior edge between vertices.

When edge drawing is available, a new focus model is added to support the vertices. If cell focus and vertex focus are both available, you can switch between the two models by pressing the . key.

Specifies whether a dragging operation will draw spokes between cells.

Specifies whether cells with original contents are selectable with bounding boxes or not.

Specifies a set of extract codes for all cells marked with a # in the data-text field. Two cells with the same code anywhere on the page will share their values, permitting the extraction of letters from a puzzle into an answer phrase.

The format for data-extracts is a set of codes, with spaces between them. Each code is applied to the next occurrence of #.



Turns off all mouse and keyboard input for the puzzle. Useful for solutions, samples, and scenarios with multiple puzzle layers on top of each other.

Displays buttons below the puzzle, allowing for discovery of all the features provided by the interactive solver. The About button in particular shows mouse and keyboard controls for all behaviors permitted by the options chosen.

Allows for a specifically-named identifier to be used for the puzzle, both for saved state in localStorage and for co-op scenarios. When not present, the identifier will be constructed from the page URL and the index of the puzzle among all .puzzle-entry objects on the page.

Allows for a specifically-named identifier to be used for the team, to facilitate co-op scenarios. This can be set programmatically, and can be left blank if the whole world is on the same team.

Allows for a specifically-named identifier to be used for the team member, to facilitate co-op scenarios. This can be set programmatically, and can be left blank if no player-specific information is needed.

Breaking Changes

data-state-key has been renamed to data-puzzle-id since it is now used for multiple scenarios.