checkboxland
Advanced tools
Comparing version 1.0.4 to 1.1.0
export class Checkboxland { | ||
constructor(props = {}) { | ||
if (typeof props.fillValue !== 'undefined') _checkForValidValue(props.fillValue); | ||
this.displayEl = document.querySelector(props.selector || '#checkboxland'); | ||
@@ -8,3 +9,5 @@ this.dimensions = _textDimensionsToArray(props.dimensions || '8x8'); // The data object. Don't access this directly. Use methods like getData() and setData() instead. | ||
this._data = _getEmptyMatrix(this.dimensions[0], this.dimensions[1]); | ||
this._data = this.getEmptyMatrix({ | ||
fillValue: props.fillValue || 0 | ||
}); | ||
@@ -15,21 +18,38 @@ _createInitialCheckboxDisplay(this.displayEl, this._data); | ||
getCheckboxValue(x, y) { | ||
// @todo: needs a isWithinDisplay check. | ||
const isWithinDisplay = x >= 0 && y >= 0 && x < this.dimensions[0] && y < this.dimensions[1]; | ||
if (!isWithinDisplay) { | ||
throw new Error(`The location (x: ${x}, y: ${y}) is outside of this checkbox display`); | ||
} | ||
return this._data[y][x]; | ||
} | ||
setCheckboxValue(x, y, value) { | ||
const isValueValid = value === 0 || value === 1; | ||
const isWithinDisplay = typeof this._data[y] !== 'undefined' && typeof this._data[y][x] !== 'undefined'; | ||
setCheckboxValue(x, y, newValue) { | ||
const isWithinDisplay = x >= 0 && y >= 0 && x < this.dimensions[0] && y < this.dimensions[1]; | ||
if (!isValueValid) { | ||
throw new Error(`${value} is not a valid checkbox value`); | ||
} | ||
_checkForValidValue(newValue); | ||
if (!isWithinDisplay) return; | ||
this._data[y][x] = value; // We can assume the checkboxEl exists because it's within the display. | ||
this._data[y][x] = newValue; // We can assume the checkboxEl exists because it's within the display. | ||
const checkboxEl = this.displayEl.children[y].children[x]; | ||
const isCellChecked = Boolean(value); | ||
if (checkboxEl.checked === isCellChecked) return; | ||
checkboxEl.checked = isCellChecked; | ||
const checkboxEl = this.displayEl.children[y].children[x]; // Handle indeterminate newValues | ||
if (newValue === 2) { | ||
if (checkboxEl.indeterminate) return; | ||
checkboxEl.indeterminate = true; // The indeterminate state masks the checked state, so we always | ||
// uncheck indeterminate checkboxes to prevent weird state combinations. | ||
checkboxEl.checked = false; | ||
} // Handle non-indeterminate newValues | ||
else { | ||
// Remove any previously set indeterminate values. | ||
if (checkboxEl.indeterminate) { | ||
checkboxEl.indeterminate = false; | ||
} // If the checkbox value matches, then we don't need to update it. | ||
if (checkboxEl.checked === Boolean(newValue)) return; | ||
checkboxEl.checked = Boolean(newValue); | ||
} | ||
} | ||
@@ -43,22 +63,70 @@ | ||
setData(data) { | ||
data.forEach((rowData, rowIndex) => { | ||
rowData.forEach((cellValue, cellIndex) => { | ||
this.setCheckboxValue(cellIndex, rowIndex, cellValue); | ||
}); | ||
}); | ||
setData(data, options = {}) { | ||
const { | ||
x = 0, | ||
y = 0, | ||
fillValue | ||
} = options; | ||
const isFillValueProvided = typeof fillValue !== 'undefined'; | ||
const colNum = this.dimensions[0]; | ||
const rowNum = this.dimensions[1]; | ||
_checkForValidMatrix(data); | ||
for (let rowIndex = 0; rowIndex < rowNum; rowIndex++) { | ||
for (let colIndex = 0; colIndex < colNum; colIndex++) { | ||
let isBeforeStartingXPos = colIndex < x; | ||
let isBeforeStartingYPos = rowIndex < y; | ||
let isBeyondProvidedXPlusData = colIndex >= x + data[0].length; | ||
let isBeyondProvidedYPlusData = rowIndex >= y + data.length; | ||
let isOutsideOfProvidedData = isBeforeStartingXPos || isBeforeStartingYPos || isBeyondProvidedXPlusData || isBeyondProvidedYPlusData; | ||
if (isOutsideOfProvidedData && !isFillValueProvided) continue; | ||
let valueToSet = isOutsideOfProvidedData ? fillValue : data[rowIndex - y][colIndex - x]; | ||
this.setCheckboxValue(colIndex, rowIndex, valueToSet); | ||
} | ||
} | ||
} | ||
clearData() { | ||
const emptyMatrix = _getEmptyMatrix(this.dimensions[0], this.dimensions[1]); | ||
const emptyMatrix = this.getEmptyMatrix(); | ||
this.setData(emptyMatrix); | ||
} // This kind of method makes more sense as a plugin but I needed to | ||
// use it in the core library anyways so I decided to expose it here. | ||
this.setData(emptyMatrix); | ||
getEmptyMatrix(options = {}) { | ||
const { | ||
fillValue = 0, | ||
width = this.dimensions[0], | ||
height = this.dimensions[1] | ||
} = options; | ||
const matrix = []; | ||
for (let i = 0; i < height; i++) { | ||
matrix[i] = []; | ||
for (let j = 0; j < width; j++) { | ||
matrix[i][j] = fillValue; | ||
} | ||
} | ||
return matrix; | ||
} | ||
static extend(pluginObj = {}) { | ||
if (!pluginObj.name || !pluginObj.exec) { | ||
const { | ||
name, | ||
exec, | ||
cleanUp | ||
} = pluginObj; | ||
if (!name || !exec) { | ||
throw new Error('Your plugin must have a "name" and an "exec" function.'); | ||
} | ||
this.prototype[pluginObj.name] = pluginObj.exec; | ||
if (cleanUp) { | ||
exec.cleanUp = cleanUp; | ||
} | ||
this.prototype[name] = exec; | ||
} | ||
@@ -68,14 +136,10 @@ | ||
function _getEmptyMatrix(width, height) { | ||
const matrix = []; | ||
function _checkForValidValue(value) { | ||
if (value === 0 || value === 1 || value === 2) return; | ||
throw new Error(`${value} is not a valid checkbox value.`); | ||
} | ||
for (let i = 0; i < height; i++) { | ||
matrix[i] = []; | ||
for (let j = 0; j < width; j++) { | ||
matrix[i][j] = 0; | ||
} | ||
} | ||
return matrix; | ||
function _checkForValidMatrix(matrix) { | ||
if (Array.isArray(matrix) && Array.isArray(matrix[0])) return; | ||
throw new Error(`${matrix} is not a valid matrix.`); | ||
} | ||
@@ -102,2 +166,4 @@ | ||
const checkboxEl = document.createElement('input'); | ||
const indeterminateVal = cellData === 2 ? true : false; | ||
const checkedVal = indeterminateVal ? false : Boolean(cellData); | ||
checkboxEl.style.margin = 0; | ||
@@ -107,2 +173,4 @@ checkboxEl.style.verticalAlign = 'top'; | ||
checkboxEl.tabIndex = '-1'; | ||
checkboxEl.checked = checkedVal; | ||
checkboxEl.indeterminate = indeterminateVal; | ||
rowEl.appendChild(checkboxEl); | ||
@@ -109,0 +177,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
let intervalId; | ||
function marquee(newData, options = {}) { | ||
@@ -12,3 +14,3 @@ const { | ||
let currentIteration = 1; | ||
const intervalId = setInterval(() => { | ||
intervalId = setInterval(() => { | ||
const currentData = this.getData(); | ||
@@ -51,5 +53,10 @@ | ||
function cleanUp() { | ||
clearInterval(intervalId); | ||
} | ||
export default { | ||
name: 'marquee', | ||
exec: marquee | ||
exec: marquee, | ||
cleanUp: cleanUp | ||
}; |
import { fiveBySeven } from './font-5x7.js'; | ||
function print(text, options = {}) { | ||
const { | ||
dataOnly = false, | ||
font = fiveBySeven, | ||
x = 0, | ||
y = 0, | ||
fillValue | ||
} = options; | ||
const isFillValueProvided = typeof fillValue !== 'undefined'; | ||
const textArray = text.split(''); | ||
const font = options.font || fiveBySeven; | ||
const dataMatrix = textArray.reduce((matrix, currentChar) => { | ||
const textMatrix = textArray.reduce((matrix, currentChar) => { | ||
const currentCharacterMatrix = font[currentChar]; | ||
return _matrixConcat(matrix, currentCharacterMatrix); | ||
}, []); | ||
}, []); // Handle an edge-case where an empty string produces an empty | ||
// array instead of an empty matrix (which is what we'd prefer). | ||
if (options.dataOnly) { | ||
if (textMatrix.length === 0) { | ||
textMatrix.push([]); | ||
} | ||
if (dataOnly) { | ||
if (!isFillValueProvided) return textMatrix; | ||
let dataMatrix = this.getEmptyMatrix({ | ||
fillValue | ||
}); | ||
textMatrix.forEach((rowData, rowIndex) => { | ||
rowData.forEach((cellValue, cellIndex) => { | ||
dataMatrix[rowIndex + y][cellIndex + x] = cellValue; | ||
}); | ||
}); | ||
return dataMatrix; | ||
} | ||
this.setData(dataMatrix); | ||
this.setData(textMatrix, { | ||
x, | ||
y, | ||
fillValue | ||
}); | ||
} // HELPER FUNCTIONS | ||
@@ -17,0 +42,0 @@ |
@@ -0,1 +1,3 @@ | ||
let intervalId; | ||
function transitionWipe(newData, options = {}) { | ||
@@ -12,3 +14,3 @@ const { | ||
let currentIteration = 1; | ||
const intervalId = setInterval(() => { | ||
intervalId = setInterval(() => { | ||
let leadingEdgeIndex, writingEdgeIndex; | ||
@@ -52,5 +54,10 @@ | ||
function cleanUp() { | ||
clearInterval(intervalId); | ||
} | ||
export default { | ||
name: 'transitionWipe', | ||
exec: transitionWipe | ||
exec: transitionWipe, | ||
cleanUp: cleanUp | ||
}; |
@@ -8,6 +8,7 @@ export class Checkboxland { | ||
getCheckboxValue(x: any, y: any): any; | ||
setCheckboxValue(x: any, y: any, value: any): void; | ||
setCheckboxValue(x: any, y: any, newValue: any): void; | ||
getData(): any[][]; | ||
setData(data: any): void; | ||
setData(data: any, options?: {}): void; | ||
clearData(): void; | ||
getEmptyMatrix(options?: {}): any[][]; | ||
} |
declare namespace _default { | ||
export const name: string; | ||
export { marquee as exec }; | ||
export { cleanUp }; | ||
} | ||
export default _default; | ||
declare function marquee(newData: any, options?: {}): void; | ||
declare function cleanUp(): void; |
export const fiveBySeven: { | ||
'0': number[][]; | ||
'1': number[][]; | ||
'2': number[][]; | ||
'3': number[][]; | ||
'4': number[][]; | ||
'5': number[][]; | ||
'6': number[][]; | ||
'7': number[][]; | ||
'8': number[][]; | ||
'9': number[][]; | ||
0: number[][]; | ||
1: number[][]; | ||
2: number[][]; | ||
3: number[][]; | ||
4: number[][]; | ||
5: number[][]; | ||
6: number[][]; | ||
7: number[][]; | ||
8: number[][]; | ||
9: number[][]; | ||
':': number[][]; | ||
' ': number[][]; | ||
'A': number[][]; | ||
'B': number[][]; | ||
'C': number[][]; | ||
'D': number[][]; | ||
'E': number[][]; | ||
'F': number[][]; | ||
'G': number[][]; | ||
'H': number[][]; | ||
'I': number[][]; | ||
'J': number[][]; | ||
'K': number[][]; | ||
'L': number[][]; | ||
'M': number[][]; | ||
'N': number[][]; | ||
'O': number[][]; | ||
'P': number[][]; | ||
'Q': number[][]; | ||
'R': number[][]; | ||
'S': number[][]; | ||
'T': number[][]; | ||
'U': number[][]; | ||
'V': number[][]; | ||
'W': number[][]; | ||
'X': number[][]; | ||
'Y': number[][]; | ||
'Z': number[][]; | ||
'a': number[][]; | ||
'b': number[][]; | ||
'c': number[][]; | ||
'd': number[][]; | ||
'e': number[][]; | ||
'f': number[][]; | ||
'g': number[][]; | ||
'h': number[][]; | ||
'i': number[][]; | ||
'j': number[][]; | ||
'k': number[][]; | ||
'l': number[][]; | ||
'm': number[][]; | ||
'n': number[][]; | ||
'o': number[][]; | ||
'p': number[][]; | ||
'q': number[][]; | ||
'r': number[][]; | ||
's': number[][]; | ||
't': number[][]; | ||
'u': number[][]; | ||
'v': number[][]; | ||
'w': number[][]; | ||
'x': number[][]; | ||
'y': number[][]; | ||
'z': number[][]; | ||
A: number[][]; | ||
B: number[][]; | ||
C: number[][]; | ||
D: number[][]; | ||
E: number[][]; | ||
F: number[][]; | ||
G: number[][]; | ||
H: number[][]; | ||
I: number[][]; | ||
J: number[][]; | ||
K: number[][]; | ||
L: number[][]; | ||
M: number[][]; | ||
N: number[][]; | ||
O: number[][]; | ||
P: number[][]; | ||
Q: number[][]; | ||
R: number[][]; | ||
S: number[][]; | ||
T: number[][]; | ||
U: number[][]; | ||
V: number[][]; | ||
W: number[][]; | ||
X: number[][]; | ||
Y: number[][]; | ||
Z: number[][]; | ||
a: number[][]; | ||
b: number[][]; | ||
c: number[][]; | ||
d: number[][]; | ||
e: number[][]; | ||
f: number[][]; | ||
g: number[][]; | ||
h: number[][]; | ||
i: number[][]; | ||
j: number[][]; | ||
k: number[][]; | ||
l: number[][]; | ||
m: number[][]; | ||
n: number[][]; | ||
o: number[][]; | ||
p: number[][]; | ||
q: number[][]; | ||
r: number[][]; | ||
s: number[][]; | ||
t: number[][]; | ||
u: number[][]; | ||
v: number[][]; | ||
w: number[][]; | ||
x: number[][]; | ||
y: number[][]; | ||
z: number[][]; | ||
'`': number[][]; | ||
@@ -71,3 +71,3 @@ '~': number[][]; | ||
'#': number[][]; | ||
'$': number[][]; | ||
$: number[][]; | ||
'%': number[][]; | ||
@@ -80,3 +80,3 @@ '^': number[][]; | ||
'-': number[][]; | ||
'_': number[][]; | ||
_: number[][]; | ||
'+': number[][]; | ||
@@ -83,0 +83,0 @@ '=': number[][]; |
declare namespace _default { | ||
export const name: string; | ||
export { transitionWipe as exec }; | ||
export { cleanUp }; | ||
} | ||
export default _default; | ||
declare function transitionWipe(newData: any, options?: {}): void; | ||
declare function cleanUp(): void; |
class Checkboxland { | ||
constructor(props = {}) { | ||
if (typeof props.fillValue !== 'undefined') _checkForValidValue(props.fillValue); | ||
this.displayEl = document.querySelector(props.selector || '#checkboxland'); | ||
@@ -8,3 +9,5 @@ this.dimensions = _textDimensionsToArray(props.dimensions || '8x8'); // The data object. Don't access this directly. Use methods like getData() and setData() instead. | ||
this._data = _getEmptyMatrix(this.dimensions[0], this.dimensions[1]); | ||
this._data = this.getEmptyMatrix({ | ||
fillValue: props.fillValue || 0 | ||
}); | ||
@@ -15,21 +18,38 @@ _createInitialCheckboxDisplay(this.displayEl, this._data); | ||
getCheckboxValue(x, y) { | ||
// @todo: needs a isWithinDisplay check. | ||
const isWithinDisplay = x >= 0 && y >= 0 && x < this.dimensions[0] && y < this.dimensions[1]; | ||
if (!isWithinDisplay) { | ||
throw new Error(`The location (x: ${x}, y: ${y}) is outside of this checkbox display`); | ||
} | ||
return this._data[y][x]; | ||
} | ||
setCheckboxValue(x, y, value) { | ||
const isValueValid = value === 0 || value === 1; | ||
const isWithinDisplay = typeof this._data[y] !== 'undefined' && typeof this._data[y][x] !== 'undefined'; | ||
setCheckboxValue(x, y, newValue) { | ||
const isWithinDisplay = x >= 0 && y >= 0 && x < this.dimensions[0] && y < this.dimensions[1]; | ||
if (!isValueValid) { | ||
throw new Error(`${value} is not a valid checkbox value`); | ||
} | ||
_checkForValidValue(newValue); | ||
if (!isWithinDisplay) return; | ||
this._data[y][x] = value; // We can assume the checkboxEl exists because it's within the display. | ||
this._data[y][x] = newValue; // We can assume the checkboxEl exists because it's within the display. | ||
const checkboxEl = this.displayEl.children[y].children[x]; | ||
const isCellChecked = Boolean(value); | ||
if (checkboxEl.checked === isCellChecked) return; | ||
checkboxEl.checked = isCellChecked; | ||
const checkboxEl = this.displayEl.children[y].children[x]; // Handle indeterminate newValues | ||
if (newValue === 2) { | ||
if (checkboxEl.indeterminate) return; | ||
checkboxEl.indeterminate = true; // The indeterminate state masks the checked state, so we always | ||
// uncheck indeterminate checkboxes to prevent weird state combinations. | ||
checkboxEl.checked = false; | ||
} // Handle non-indeterminate newValues | ||
else { | ||
// Remove any previously set indeterminate values. | ||
if (checkboxEl.indeterminate) { | ||
checkboxEl.indeterminate = false; | ||
} // If the checkbox value matches, then we don't need to update it. | ||
if (checkboxEl.checked === Boolean(newValue)) return; | ||
checkboxEl.checked = Boolean(newValue); | ||
} | ||
} | ||
@@ -43,22 +63,70 @@ | ||
setData(data) { | ||
data.forEach((rowData, rowIndex) => { | ||
rowData.forEach((cellValue, cellIndex) => { | ||
this.setCheckboxValue(cellIndex, rowIndex, cellValue); | ||
}); | ||
}); | ||
setData(data, options = {}) { | ||
const { | ||
x = 0, | ||
y = 0, | ||
fillValue | ||
} = options; | ||
const isFillValueProvided = typeof fillValue !== 'undefined'; | ||
const colNum = this.dimensions[0]; | ||
const rowNum = this.dimensions[1]; | ||
_checkForValidMatrix(data); | ||
for (let rowIndex = 0; rowIndex < rowNum; rowIndex++) { | ||
for (let colIndex = 0; colIndex < colNum; colIndex++) { | ||
let isBeforeStartingXPos = colIndex < x; | ||
let isBeforeStartingYPos = rowIndex < y; | ||
let isBeyondProvidedXPlusData = colIndex >= x + data[0].length; | ||
let isBeyondProvidedYPlusData = rowIndex >= y + data.length; | ||
let isOutsideOfProvidedData = isBeforeStartingXPos || isBeforeStartingYPos || isBeyondProvidedXPlusData || isBeyondProvidedYPlusData; | ||
if (isOutsideOfProvidedData && !isFillValueProvided) continue; | ||
let valueToSet = isOutsideOfProvidedData ? fillValue : data[rowIndex - y][colIndex - x]; | ||
this.setCheckboxValue(colIndex, rowIndex, valueToSet); | ||
} | ||
} | ||
} | ||
clearData() { | ||
const emptyMatrix = _getEmptyMatrix(this.dimensions[0], this.dimensions[1]); | ||
const emptyMatrix = this.getEmptyMatrix(); | ||
this.setData(emptyMatrix); | ||
} // This kind of method makes more sense as a plugin but I needed to | ||
// use it in the core library anyways so I decided to expose it here. | ||
this.setData(emptyMatrix); | ||
getEmptyMatrix(options = {}) { | ||
const { | ||
fillValue = 0, | ||
width = this.dimensions[0], | ||
height = this.dimensions[1] | ||
} = options; | ||
const matrix = []; | ||
for (let i = 0; i < height; i++) { | ||
matrix[i] = []; | ||
for (let j = 0; j < width; j++) { | ||
matrix[i][j] = fillValue; | ||
} | ||
} | ||
return matrix; | ||
} | ||
static extend(pluginObj = {}) { | ||
if (!pluginObj.name || !pluginObj.exec) { | ||
const { | ||
name, | ||
exec, | ||
cleanUp | ||
} = pluginObj; | ||
if (!name || !exec) { | ||
throw new Error('Your plugin must have a "name" and an "exec" function.'); | ||
} | ||
this.prototype[pluginObj.name] = pluginObj.exec; | ||
if (cleanUp) { | ||
exec.cleanUp = cleanUp; | ||
} | ||
this.prototype[name] = exec; | ||
} | ||
@@ -68,14 +136,10 @@ | ||
function _getEmptyMatrix(width, height) { | ||
const matrix = []; | ||
function _checkForValidValue(value) { | ||
if (value === 0 || value === 1 || value === 2) return; | ||
throw new Error(`${value} is not a valid checkbox value.`); | ||
} | ||
for (let i = 0; i < height; i++) { | ||
matrix[i] = []; | ||
for (let j = 0; j < width; j++) { | ||
matrix[i][j] = 0; | ||
} | ||
} | ||
return matrix; | ||
function _checkForValidMatrix(matrix) { | ||
if (Array.isArray(matrix) && Array.isArray(matrix[0])) return; | ||
throw new Error(`${matrix} is not a valid matrix.`); | ||
} | ||
@@ -102,2 +166,4 @@ | ||
const checkboxEl = document.createElement('input'); | ||
const indeterminateVal = cellData === 2 ? true : false; | ||
const checkedVal = indeterminateVal ? false : Boolean(cellData); | ||
checkboxEl.style.margin = 0; | ||
@@ -107,2 +173,4 @@ checkboxEl.style.verticalAlign = 'top'; | ||
checkboxEl.tabIndex = '-1'; | ||
checkboxEl.checked = checkedVal; | ||
checkboxEl.indeterminate = indeterminateVal; | ||
rowEl.appendChild(checkboxEl); | ||
@@ -213,14 +281,39 @@ }); | ||
function print(text, options = {}) { | ||
const { | ||
dataOnly = false, | ||
font = fiveBySeven, | ||
x = 0, | ||
y = 0, | ||
fillValue | ||
} = options; | ||
const isFillValueProvided = typeof fillValue !== 'undefined'; | ||
const textArray = text.split(''); | ||
const font = options.font || fiveBySeven; | ||
const dataMatrix = textArray.reduce((matrix, currentChar) => { | ||
const textMatrix = textArray.reduce((matrix, currentChar) => { | ||
const currentCharacterMatrix = font[currentChar]; | ||
return _matrixConcat(matrix, currentCharacterMatrix); | ||
}, []); | ||
}, []); // Handle an edge-case where an empty string produces an empty | ||
// array instead of an empty matrix (which is what we'd prefer). | ||
if (options.dataOnly) { | ||
if (textMatrix.length === 0) { | ||
textMatrix.push([]); | ||
} | ||
if (dataOnly) { | ||
if (!isFillValueProvided) return textMatrix; | ||
let dataMatrix = this.getEmptyMatrix({ | ||
fillValue | ||
}); | ||
textMatrix.forEach((rowData, rowIndex) => { | ||
rowData.forEach((cellValue, cellIndex) => { | ||
dataMatrix[rowIndex + y][cellIndex + x] = cellValue; | ||
}); | ||
}); | ||
return dataMatrix; | ||
} | ||
this.setData(dataMatrix); | ||
this.setData(textMatrix, { | ||
x, | ||
y, | ||
fillValue | ||
}); | ||
} // HELPER FUNCTIONS | ||
@@ -245,2 +338,4 @@ | ||
let intervalId; | ||
function marquee(newData, options = {}) { | ||
@@ -257,3 +352,3 @@ const { | ||
let currentIteration = 1; | ||
const intervalId = setInterval(() => { | ||
intervalId = setInterval(() => { | ||
const currentData = this.getData(); | ||
@@ -292,7 +387,14 @@ | ||
function cleanUp() { | ||
clearInterval(intervalId); | ||
} | ||
var marquee$1 = { | ||
name: 'marquee', | ||
exec: marquee | ||
exec: marquee, | ||
cleanUp: cleanUp | ||
}; | ||
let intervalId$1; | ||
function transitionWipe(newData, options = {}) { | ||
@@ -309,3 +411,3 @@ const { | ||
let currentIteration = 1; | ||
const intervalId = setInterval(() => { | ||
intervalId$1 = setInterval(() => { | ||
let leadingEdgeIndex, writingEdgeIndex; | ||
@@ -341,3 +443,3 @@ | ||
if (currentIteration === totalIterations) { | ||
clearInterval(intervalId); | ||
clearInterval(intervalId$1); | ||
callback(); | ||
@@ -350,5 +452,10 @@ } else { | ||
function cleanUp$1() { | ||
clearInterval(intervalId$1); | ||
} | ||
var transitionWipe$1 = { | ||
name: 'transitionWipe', | ||
exec: transitionWipe | ||
exec: transitionWipe, | ||
cleanUp: cleanUp$1 | ||
}; | ||
@@ -355,0 +462,0 @@ |
@@ -1,2 +0,2 @@ | ||
class Checkboxland{constructor(t={}){this.displayEl=document.querySelector(t.selector||"#checkboxland"),this.dimensions=_textDimensionsToArray(t.dimensions||"8x8"),this._data=_getEmptyMatrix(this.dimensions[0],this.dimensions[1]),_createInitialCheckboxDisplay(this.displayEl,this._data)}getCheckboxValue(t,e){return this._data[e][t]}setCheckboxValue(t,e,n){const i=0===n||1===n,a=void 0!==this._data[e]&&void 0!==this._data[e][t];if(!i)throw new Error(`${n} is not a valid checkbox value`);if(!a)return;this._data[e][t]=n;const r=this.displayEl.children[e].children[t],s=Boolean(n);r.checked!==s&&(r.checked=s)}getData(){return this._data.map(t=>t.slice())}setData(t){t.forEach((t,e)=>{t.forEach((t,n)=>{this.setCheckboxValue(n,e,t)})})}clearData(){const t=_getEmptyMatrix(this.dimensions[0],this.dimensions[1]);this.setData(t)}static extend(t={}){if(!t.name||!t.exec)throw new Error('Your plugin must have a "name" and an "exec" function.');this.prototype[t.name]=t.exec}}function _getEmptyMatrix(t,e){const n=[];for(let i=0;i<e;i++){n[i]=[];for(let e=0;e<t;e++)n[i][e]=0}return n}function _textDimensionsToArray(t){const e="The dimensions you provided are invalid.";if("string"!=typeof t)throw new Error(e);const n=t.split("x").map(t=>Number(t));if(!(2===n.length&&!isNaN(n[0])&&!isNaN(n[0])))throw new Error(e);return t.split("x").map(t=>Number(t))}function _createInitialCheckboxDisplay(t,e){t.innerHTML="",t.style.overflowX="auto",t.setAttribute("aria-hidden",!0),e.forEach(e=>{const n=document.createElement("div");n.style.lineHeight=.75,n.style.whiteSpace="nowrap",e.forEach(t=>{const e=document.createElement("input");e.style.margin=0,e.style.verticalAlign="top",e.type="checkbox",e.tabIndex="-1",n.appendChild(e)}),t.appendChild(n)})}const fiveBySeven={0:[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,1,1],[1,0,1,0,1],[1,1,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],1:[[0,1,0],[1,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[1,1,1]],2:[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],3:[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],4:[[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[0,0,0,0,1],[0,0,0,0,1]],5:[[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],6:[[0,0,1,1,0],[0,1,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],7:[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[0,1,0,0,0],[0,1,0,0,0]],8:[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],9:[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,1,1,0,0]],":":[[0],[1],[0],[0],[0],[1],[0]]," ":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,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,1,0,0],[0,1,0,0,0],[1,1,1,1,1]],"`":[[1,0,0],[0,1,0],[0,0,1],[0,0,0],[0,0,0],[0,0,0],[0,0,0]],"~":[[0,0,0,0,0],[0,0,0,0,0],[0,1,0,0,0],[1,0,1,0,1],[0,0,0,1,0],[0,0,0,0,0],[0,0,0,0,0]],"!":[[1],[1],[1],[1],[1],[0],[1]],"@":[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,1,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[0,1,1,1,0]],"#":[[0,1,0,1,0],[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0]],$:[[0,0,1,0,0],[0,1,1,1,1],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[1,1,1,1,0],[0,0,1,0,0]],"%":[[1,1,0,0,1],[1,1,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,1,1],[1,0,0,1,1]],"^":[[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"&":[[0,1,1,0,0],[1,0,0,1,0],[1,0,1,0,0],[0,1,0,0,0],[1,0,1,0,1],[1,0,0,1,0],[1,1,1,0,1]],"*":[[0,0,0,0,0],[0,0,1,0,0],[1,0,1,0,1],[0,1,1,1,0],[1,0,1,0,1],[0,0,1,0,0],[0,0,0,0,0]],"(":[[0,0,1],[0,1,0],[1,0,0],[1,0,0],[1,0,0],[0,1,0],[0,0,1]],")":[[1,0,0],[0,1,0],[0,0,1],[0,0,1],[0,0,1],[0,1,0],[1,0,0]],"-":[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],_:[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1]],"+":[[0,0,0,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0]],"=":[[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0]],"[":[[1,1,1],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,1,1]],"]":[[1,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1],[1,1,1]],"{":[[0,0,1],[0,1,0],[0,1,0],[1,0,0],[0,1,0],[0,1,0],[0,0,1]],"}":[[1,0,0],[0,1,0],[0,1,0],[0,0,1],[0,1,0],[0,1,0],[1,0,0]],"|":[[1],[1],[1],[1],[1],[1],[1]],"\\":[[1,0,0],[1,0,0],[0,1,0],[0,1,0],[0,1,0],[0,0,1],[0,0,1]],"/":[[0,0,1],[0,0,1],[0,1,0],[0,1,0],[0,1,0],[1,0,0],[1,0,0]],";":[[0,0],[0,1],[0,1],[0,0],[0,0],[0,1],[1,0]],'"':[[1,0,1],[1,0,1],[1,0,1],[0,0,0],[0,0,0],[0,0,0],[0,0,0]],"'":[[1,1],[0,1],[1,0],[0,0],[0,0],[0,0],[0,0]],",":[[0,0],[0,0],[0,0],[0,0],[1,1],[0,1],[1,0]],".":[[0],[0],[0],[0],[0],[0],[1]],"<":[[0,0,0],[0,0,1],[0,1,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0]],">":[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,0],[1,0,0],[0,0,0]],"?":[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0]]};function print(t,e={}){const n=t.split(""),i=e.font||fiveBySeven,a=n.reduce((t,e)=>{return _matrixConcat(t,i[e])},[]);if(e.dataOnly)return a;this.setData(a)}function _matrixConcat(t,e){if(0===t.length)return e;const n=[];return t.forEach((t,i)=>{n.push(t.concat([0]).concat(e[i]))}),n}var print$1={name:"print",exec:print};function marquee(t,e={}){const{interval:n=200,repeat:i=!1,fillValue:a=0,callback:r=(()=>{})}=e,s=this.dimensions[1],o=this.dimensions[0],l=o+t[0].length;let c=1;const h=setInterval(()=>{const e=this.getData();for(let n=0;n<s;n++)for(let i=0;i<o;i++){if(i+1===o){const e=c-(o-i),r=t[n]?void 0===t[n][e]?a:t[n][e]:a;this.setCheckboxValue(i,n,r)}else this.setCheckboxValue(i,n,e[n][i+1])}c===l?i?c=1:(clearInterval(h),r()):c++},n)}var marquee$1={name:"marquee",exec:marquee};function transitionWipe(t,e={}){const{interval:n=200,fillValue:i=0,direction:a="ltr",callback:r=(()=>{})}=e,s=this.dimensions[1],o=this.dimensions[0],l=o+1;let c=1;const h=setInterval(()=>{let e,n;switch(a){case"ltr":n=(e=c-1)-1;break;case"rtl":n=(e=o-c)+1}for(let a=0;a<s;a++)for(let r=0;r<o;r++)if(r===e)this.setCheckboxValue(r,a,1);else if(r===n){let e=t[a]?void 0===t[a][r]?i:t[a][r]:i;this.setCheckboxValue(r,a,e)}c===l?(clearInterval(h),r()):c++},n)}var transitionWipe$1={name:"transitionWipe",exec:transitionWipe};function dataUtils(t,e,n){return{invert:invert,pad:pad}[t](e,n)}function invert(t){return t.map(t=>t.map(t=>t?0:1))}function pad(t,e={}){const n=Number.isInteger(e.all),i=n?e.all:e.top,a=n?e.all:e.right,r=n?e.all:e.bottom,s=n?e.all:e.left;let o=t.map(t=>{let e=t;return s&&(e=[...Array(s).fill(0),...e]),a&&(e=[...e,...Array(a).fill(0)]),e});const l=o[0].length,c=(t,e)=>{const n=[];for(let i=0;i<t;i++)n.push(Array(e).fill(0));return n};return i&&(o=[...c(i,l),...o]),r&&(o=[...o,...c(r,l)]),o}var dataUtils$1={name:"dataUtils",exec:dataUtils};Checkboxland.extend(print$1),Checkboxland.extend(marquee$1),Checkboxland.extend(transitionWipe$1),Checkboxland.extend(dataUtils$1);export{Checkboxland}; | ||
class Checkboxland{constructor(e={}){void 0!==e.fillValue&&_checkForValidValue(e.fillValue),this.displayEl=document.querySelector(e.selector||"#checkboxland"),this.dimensions=_textDimensionsToArray(e.dimensions||"8x8"),this._data=this.getEmptyMatrix({fillValue:e.fillValue||0}),_createInitialCheckboxDisplay(this.displayEl,this._data)}getCheckboxValue(e,t){if(!(e>=0&&t>=0&&e<this.dimensions[0]&&t<this.dimensions[1]))throw new Error(`The location (x: ${e}, y: ${t}) is outside of this checkbox display`);return this._data[t][e]}setCheckboxValue(e,t,i){const n=e>=0&&t>=0&&e<this.dimensions[0]&&t<this.dimensions[1];if(_checkForValidValue(i),!n)return;this._data[t][e]=i;const a=this.displayEl.children[t].children[e];if(2===i){if(a.indeterminate)return;a.indeterminate=!0,a.checked=!1}else{if(a.indeterminate&&(a.indeterminate=!1),a.checked===Boolean(i))return;a.checked=Boolean(i)}}getData(){return this._data.map(e=>e.slice())}setData(e,t={}){const{x:i=0,y:n=0,fillValue:a}=t,r=void 0!==a,l=this.dimensions[0],o=this.dimensions[1];_checkForValidMatrix(e);for(let t=0;t<o;t++)for(let o=0;o<l;o++){let l=o<i,s=t<n,c=o>=i+e[0].length,h=t>=n+e.length,d=l||s||c||h;if(d&&!r)continue;let u=d?a:e[t-n][o-i];this.setCheckboxValue(o,t,u)}}clearData(){const e=this.getEmptyMatrix();this.setData(e)}getEmptyMatrix(e={}){const{fillValue:t=0,width:i=this.dimensions[0],height:n=this.dimensions[1]}=e,a=[];for(let e=0;e<n;e++){a[e]=[];for(let n=0;n<i;n++)a[e][n]=t}return a}static extend(e={}){const{name:t,exec:i,cleanUp:n}=e;if(!t||!i)throw new Error('Your plugin must have a "name" and an "exec" function.');n&&(i.cleanUp=n),this.prototype[t]=i}}function _checkForValidValue(e){if(0!==e&&1!==e&&2!==e)throw new Error(`${e} is not a valid checkbox value.`)}function _checkForValidMatrix(e){if(!Array.isArray(e)||!Array.isArray(e[0]))throw new Error(`${e} is not a valid matrix.`)}function _textDimensionsToArray(e){const t="The dimensions you provided are invalid.";if("string"!=typeof e)throw new Error(t);const i=e.split("x").map(e=>Number(e));if(!(2===i.length&&!isNaN(i[0])&&!isNaN(i[0])))throw new Error(t);return e.split("x").map(e=>Number(e))}function _createInitialCheckboxDisplay(e,t){e.innerHTML="",e.style.overflowX="auto",e.setAttribute("aria-hidden",!0),t.forEach(t=>{const i=document.createElement("div");i.style.lineHeight=.75,i.style.whiteSpace="nowrap",t.forEach(e=>{const t=document.createElement("input"),n=2===e,a=!n&&Boolean(e);t.style.margin=0,t.style.verticalAlign="top",t.type="checkbox",t.tabIndex="-1",t.checked=a,t.indeterminate=n,i.appendChild(t)}),e.appendChild(i)})}const fiveBySeven={0:[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,1,1],[1,0,1,0,1],[1,1,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],1:[[0,1,0],[1,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[1,1,1]],2:[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],3:[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],4:[[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[0,0,0,0,1],[0,0,0,0,1]],5:[[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],6:[[0,0,1,1,0],[0,1,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],7:[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[0,1,0,0,0],[0,1,0,0,0]],8:[[0,1,1,1,0],[1,0,0,0,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0,0,0,0,0],[0,0,0,0,0],[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1]],y:[[0,0,0,0,0],[0,0,0,0,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[0,1,1,1,0]],z:[[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,1,1,1,1]],"`":[[1,0,0],[0,1,0],[0,0,1],[0,0,0],[0,0,0],[0,0,0],[0,0,0]],"~":[[0,0,0,0,0],[0,0,0,0,0],[0,1,0,0,0],[1,0,1,0,1],[0,0,0,1,0],[0,0,0,0,0],[0,0,0,0,0]],"!":[[1],[1],[1],[1],[1],[0],[1]],"@":[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,1,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[0,1,1,1,0]],"#":[[0,1,0,1,0],[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0]],$:[[0,0,1,0,0],[0,1,1,1,1],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[1,1,1,1,0],[0,0,1,0,0]],"%":[[1,1,0,0,1],[1,1,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,1,1],[1,0,0,1,1]],"^":[[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"&":[[0,1,1,0,0],[1,0,0,1,0],[1,0,1,0,0],[0,1,0,0,0],[1,0,1,0,1],[1,0,0,1,0],[1,1,1,0,1]],"*":[[0,0,0,0,0],[0,0,1,0,0],[1,0,1,0,1],[0,1,1,1,0],[1,0,1,0,1],[0,0,1,0,0],[0,0,0,0,0]],"(":[[0,0,1],[0,1,0],[1,0,0],[1,0,0],[1,0,0],[0,1,0],[0,0,1]],")":[[1,0,0],[0,1,0],[0,0,1],[0,0,1],[0,0,1],[0,1,0],[1,0,0]],"-":[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],_:[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1]],"+":[[0,0,0,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0]],"=":[[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0]],"[":[[1,1,1],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,1,1]],"]":[[1,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1],[1,1,1]],"{":[[0,0,1],[0,1,0],[0,1,0],[1,0,0],[0,1,0],[0,1,0],[0,0,1]],"}":[[1,0,0],[0,1,0],[0,1,0],[0,0,1],[0,1,0],[0,1,0],[1,0,0]],"|":[[1],[1],[1],[1],[1],[1],[1]],"\\":[[1,0,0],[1,0,0],[0,1,0],[0,1,0],[0,1,0],[0,0,1],[0,0,1]],"/":[[0,0,1],[0,0,1],[0,1,0],[0,1,0],[0,1,0],[1,0,0],[1,0,0]],";":[[0,0],[0,1],[0,1],[0,0],[0,0],[0,1],[1,0]],'"':[[1,0,1],[1,0,1],[1,0,1],[0,0,0],[0,0,0],[0,0,0],[0,0,0]],"'":[[1,1],[0,1],[1,0],[0,0],[0,0],[0,0],[0,0]],",":[[0,0],[0,0],[0,0],[0,0],[1,1],[0,1],[1,0]],".":[[0],[0],[0],[0],[0],[0],[1]],"<":[[0,0,0],[0,0,1],[0,1,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0]],">":[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,0],[1,0,0],[0,0,0]],"?":[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0]]};function print(e,t={}){const{dataOnly:i=!1,font:n=fiveBySeven,x:a=0,y:r=0,fillValue:l}=t,o=void 0!==l,s=e.split("").reduce((e,t)=>{return _matrixConcat(e,n[t])},[]);if(0===s.length&&s.push([]),i){if(!o)return s;let e=this.getEmptyMatrix({fillValue:l});return s.forEach((t,i)=>{t.forEach((t,n)=>{e[i+r][n+a]=t})}),e}this.setData(s,{x:a,y:r,fillValue:l})}function _matrixConcat(e,t){if(0===e.length)return t;const i=[];return e.forEach((e,n)=>{i.push(e.concat([0]).concat(t[n]))}),i}var print$1={name:"print",exec:print};let intervalId;function marquee(e,t={}){const{interval:i=200,repeat:n=!1,fillValue:a=0,callback:r=(()=>{})}=t,l=this.dimensions[1],o=this.dimensions[0],s=o+e[0].length;let c=1;intervalId=setInterval(()=>{const t=this.getData();for(let i=0;i<l;i++)for(let n=0;n<o;n++){if(n+1===o){const t=c-(o-n),r=e[i]?void 0===e[i][t]?a:e[i][t]:a;this.setCheckboxValue(n,i,r)}else this.setCheckboxValue(n,i,t[i][n+1])}c===s?n?c=1:(clearInterval(intervalId),r()):c++},i)}function cleanUp(){clearInterval(intervalId)}var marquee$1={name:"marquee",exec:marquee,cleanUp:cleanUp};let intervalId$1;function transitionWipe(e,t={}){const{interval:i=200,fillValue:n=0,direction:a="ltr",callback:r=(()=>{})}=t,l=this.dimensions[1],o=this.dimensions[0],s=o+1;let c=1;intervalId$1=setInterval(()=>{let t,i;switch(a){case"ltr":i=(t=c-1)-1;break;case"rtl":i=(t=o-c)+1}for(let a=0;a<l;a++)for(let r=0;r<o;r++)if(r===t)this.setCheckboxValue(r,a,1);else if(r===i){let t=e[a]?void 0===e[a][r]?n:e[a][r]:n;this.setCheckboxValue(r,a,t)}c===s?(clearInterval(intervalId$1),r()):c++},i)}function cleanUp$1(){clearInterval(intervalId$1)}var transitionWipe$1={name:"transitionWipe",exec:transitionWipe,cleanUp:cleanUp$1};function dataUtils(e,t,i){return{invert:invert,pad:pad}[e](t,i)}function invert(e){return e.map(e=>e.map(e=>e?0:1))}function pad(e,t={}){const i=Number.isInteger(t.all),n=i?t.all:t.top,a=i?t.all:t.right,r=i?t.all:t.bottom,l=i?t.all:t.left;let o=e.map(e=>{let t=e;return l&&(t=[...Array(l).fill(0),...t]),a&&(t=[...t,...Array(a).fill(0)]),t});const s=o[0].length,c=(e,t)=>{const i=[];for(let n=0;n<e;n++)i.push(Array(t).fill(0));return i};return n&&(o=[...c(n,s),...o]),r&&(o=[...o,...c(r,s)]),o}var dataUtils$1={name:"dataUtils",exec:dataUtils};Checkboxland.extend(print$1),Checkboxland.extend(marquee$1),Checkboxland.extend(transitionWipe$1),Checkboxland.extend(dataUtils$1);export{Checkboxland}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "checkboxland", | ||
"description": "Render anything as HTML checkboxes", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -26,5 +26,5 @@ "files": [ | ||
"@pika/plugin-standard-pkg": "^0.9.2", | ||
"http-server": "^0.12.1", | ||
"http-server": "^0.12.3", | ||
"pika-plugin-minify": "^0.1.0", | ||
"typescript": "^3.7.5" | ||
"typescript": "^3.9.5" | ||
}, | ||
@@ -31,0 +31,0 @@ "esnext": "dist-src/index.js", |
@@ -5,4 +5,6 @@ # Checkboxland | ||
Checkboxland is a JavaScript library for rendering things as HTML checkboxes, and embedding them in a webpage. | ||
<img src="docs/img/checkboxland-banner.png" alt="a grid of checkboxes displaying the words 'Welcome to Checkboxland" /> | ||
Checkboxland is a JavaScript library for rendering anything as HTML checkboxes. | ||
You can use it to display animations, text, and arbitrary data. It also supports plugins, so you can build more powerful APIs on top of it. | ||
@@ -48,4 +50,15 @@ | ||
## Contributing | ||
Checkboxland is designed to be extendable. If you want to add a feature, first ask yourself if it could be done as an external plugin. | ||
If you contribution requires a change to the core library, follow these steps: | ||
1. Fork/Clone the repo. | ||
2. Make your changes on a feature branch. | ||
3. Run the docs site locally (`npm run dev`) to confirm that the demos still work as expected. | ||
4. Submit a Pull Request. | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
172128
1184
63