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 crostic-grid mode is used with the crostic-clue mode for a crostic grid and associated clues. In the main grid, cells are numbered and show a letter for the corresponding clue (specified via data-links with the format #|X). Clue answers are numbered, and content is automatically shared between grid and clue. In a crostic grid, typing and arrowing will wrap from one row to the next.


A. Not new
B. Left, on a map
C. Lights, Camera, ____!

See the crostic-grid section for information.

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. This can be expressed either as a property-value pair in a JSON object, or as an attribute with JSON contents.

{ "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 how the cell position is advanced when typing or arrowing. With crossword style (the default), the character navigation direction changes from horizontal to vertical as described in data-text-advance-on-type. With wrap style, typing will always continue in the horizontal direction, and will also will wrap from one side of the grid to the other when typing, backspacing, or arrowing left or right.

Specifies an area to avoid when drawing text in a cell. Options:

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.

Note that the names of these classes will be directly spoken by a screenreader.

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. Five drawing styles are provided: box, dots, dash, offset, 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 the position of the clue labels for inner cells, whether they are automatically generated by data-clue-locations or specfically provided by data-clue-indicators.

Valid values:

To specify the positions for multiple clue labels in a cell, use | characters between the positions.

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 a set of link IDs for all cells not marked with @ in the data-text field. Two cells with the same link ID anywhere on the page will share their values. The format for data-links is a set of IDs with spaces between them. IDs are applied in order to the cells, skipping cells marked with @.

Link IDs are shown in cells according to the data-link-position field. Multiple values can be shown in each cell; separate the individual values for each cell with the | character, and specify multiple positions in the data-link-position field (see that section for an example).

Note that data-extracts is a similar property that uses a separate ID space and provides highlighting. It is perfectly valid for a single cell to use both.


Specifies the position of the link ID labels in the data-links field.

Valid values:

To specify the positions for multiple link ID labels in a cell, use | characters between the positions.

simple ID
multiple labels
stealth

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 #.

Link IDs are shown in cells according to the data-extract-position field. Multiple values can be shown in each cell; separate the individual values for each cell with the | character, and specify multiple positions in the data-extract-position field (see that section for an example).

Note that data-links is a similar property that uses a separate ID space and does not provide highlighting. It is perfectly valid for a single cell to use both.



Specifies the position of the extract labels in the data-extracts field.

Valid values:

To specify the positions for multiple extract labels in a cell, use | characters between the positions.

simple ID
multiple labels
stealth

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 classes that can be used to provide extra formatting for cells. This formatting will not be editable by the solver.

Note that the names of these classes will be directly spoken by a screenreader.

Specifies a class provided by data-extra-style-classes. for each cell. There are two types of values that can be specified per character:

data-extra-styles can be any of the following:

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.

Turns off all screenreader support and leaves a screenreader message saying that this specific puzzle is not suppoerted in a screenreader. Use this option when you are doing something so special that the screenreader will not properly communicate the puzzle. Note that any puzzle options that do not yet have full screenreader support will also cause the puzzle to generate this message.

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.

Specifies a prompt to show to confirm clearing the puzzle when the Reset button is pressed. The text of this option is shown in the dialog. Set to "" to suppress showing a prompt.

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 and the index of the puzzle among all .puzzle-entry objects on the page. When needed, the page portion of the identifier will be either the data-puzzle-page-id property of the body element, or if that is not present the window.location.pathname of 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.