@mborecki/find-words 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/find-words.cjs.js +25 -0
- package/dist/cjs/index-CpayB0Bf.js +3284 -0
- package/dist/cjs/index.cjs.js +18 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/mb-find-words_2.cjs.entry.js +235 -0
- package/dist/collection/collection-manifest.json +13 -0
- package/dist/collection/components/find-words/board.js +265 -0
- package/dist/collection/components/find-words/find-words.css +113 -0
- package/dist/collection/components/find-words/find-words.js +193 -0
- package/dist/collection/components/find-words/types.js +1 -0
- package/dist/collection/index.js +10 -0
- package/dist/collection/utils/utils.js +14 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/mb-find-words-board.d.ts +11 -0
- package/dist/components/mb-find-words-board.js +1 -0
- package/dist/components/mb-find-words.d.ts +11 -0
- package/dist/components/mb-find-words.js +1 -0
- package/dist/components/p-CttCbs-b.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/find-words.js +21 -0
- package/dist/esm/index-tKuUvMLJ.js +3276 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/mb-find-words_2.entry.js +232 -0
- package/dist/find-words/find-words.esm.js +1 -0
- package/dist/find-words/index.esm.js +1 -0
- package/dist/find-words/p-DQuL1Twl.js +1 -0
- package/dist/find-words/p-a991c10e.entry.js +1 -0
- package/dist/find-words/p-tKuUvMLJ.js +2 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/find-words/board.d.ts +24 -0
- package/dist/types/components/find-words/find-words.d.ts +23 -0
- package/dist/types/components/find-words/types.d.ts +9 -0
- package/dist/types/components.d.ts +105 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/stencil-public-runtime.d.ts +1839 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +52 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function areSiblings(index1, index2, width) {
|
|
4
|
+
if (width < 1) {
|
|
5
|
+
throw new Error("Board width must be positive");
|
|
6
|
+
}
|
|
7
|
+
if (index1 === index2)
|
|
8
|
+
return false;
|
|
9
|
+
const row1 = Math.floor(index1 / width);
|
|
10
|
+
const row2 = Math.floor(index2 / width);
|
|
11
|
+
const col1 = index1 % width;
|
|
12
|
+
const col2 = index2 % width;
|
|
13
|
+
const d1 = Math.abs(row1 - row2);
|
|
14
|
+
const d2 = Math.abs(col1 - col2);
|
|
15
|
+
return d1 <= 1 && d2 <= 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.areSiblings = areSiblings;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-CpayB0Bf.js');
|
|
4
|
+
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
|
+
|
|
6
|
+
const defineCustomElements = async (win, options) => {
|
|
7
|
+
if (typeof window === 'undefined') return undefined;
|
|
8
|
+
await appGlobals.globalScripts();
|
|
9
|
+
return index.bootstrapLazy([["mb-find-words_2.cjs",[[513,"mb-find-words",{"init":[4],"board":[16],"isInitialized":[32],"answers":[32],"currentSelected":[32],"isSelectionCorrect":[32],"initGame":[64]},[[0,"selectedChanged","onSelectedChanged"]],{"board":[{"watchBoard":0}],"isSelectionCorrect":[{"watchIsDuringCorrect":0}],"currentSelected":[{"watchCurrentSelected":0}]}],[512,"mb-find-words-board",{"letters":[1],"width":[2],"isSelectionCorrect":[4,"is-selection-correct"],"selectedCells":[32],"path":[32],"resetSelection":[64],"setSelectionAsCorrect":[64]},null,{"selectedCells":[{"buildPolyline":0},{"emitSelectedChanged":0}]}]]]], options);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.setNonce = index.setNonce;
|
|
13
|
+
exports.defineCustomElements = defineCustomElements;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-CpayB0Bf.js');
|
|
4
|
+
var index$1 = require('./index.cjs.js');
|
|
5
|
+
|
|
6
|
+
const findWordsCss = () => `:host{display:block;--_mb-default-font:Verdana, Geneva, Tahoma, sans-serif;--_mb-font:var(--mb-font, var(--_mb-default-font));--_mb-color:var(--mb-color, black);--_mb-background:var(--mb-background, white);--_mb-board-font-family:var(--mb-board-font-family, var(--_mb-font));--_mb-answers-font-family:var(--mb-answers-font-family, var(--_mb-font));--_mb-preview-font-family:var(--mb-preview-font-family, var(--_mb-font))}.main{display:grid;grid-template-columns:1fr;grid-template-areas:"preview" "board" "answers";grid-template-rows:min-content 80vw min-content}@media (min-width: 576px){.main{grid-template-columns:1fr 1fr;grid-template-areas:"answers preview" "answers board";grid-template-rows:min-content minmax(300px, 80vh)}}.answers{grid-area:answers;font-family:var(--_mb-answers-font-family)}.answers ul{list-style:none;font-size:22px;text-transform:uppercase}.answer--found{text-decoration:line-through;color:green}.preview{grid-area:preview;min-height:1.5em;font-family:var(--_mb-preview-font-family);text-transform:uppercase;font-size:30px;text-align:center}.preview--correct{color:green}.board{display:grid;place-content:center;overflow:hidden;position:relative;grid-area:board;font-family:var(--_mb-board-font-family);container-type:size}mb-find-words-board{display:block;aspect-ratio:1;width:min(100cqh, 100cqw)}.grid{position:relative;display:grid;grid-template-columns:repeat(var(--grid-width, 6), 1fr);touch-action:none}.grid svg{display:block;position:absolute;width:100%;height:100%;top:0;left:0;right:0;bottom:0;pointer-events:none;z-index:-1}.grid svg polyline,.grid svg path{stroke:lightskyblue;fill:none;stroke-width:40px;stroke-linecap:round;stroke-linejoin:round;transition:all 0.3s}.cell{display:grid;aspect-ratio:1;place-content:center;container-type:size;user-select:none}.cell__inner{font-size:80cqh;text-transform:uppercase}.cell--selected{font-weight:bold}.cell--selected.cell--correct{color:green}`;
|
|
7
|
+
|
|
8
|
+
const MbFindWords = class {
|
|
9
|
+
constructor(hostRef) {
|
|
10
|
+
index.registerInstance(this, hostRef);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
init = true;
|
|
16
|
+
board;
|
|
17
|
+
boardData;
|
|
18
|
+
boardEl;
|
|
19
|
+
isInitialized = false;
|
|
20
|
+
answers = [];
|
|
21
|
+
currentSelected = '';
|
|
22
|
+
componentWillLoad() {
|
|
23
|
+
console.log('componentDidLoad', this.init);
|
|
24
|
+
if (this.init && this.board) {
|
|
25
|
+
this.initGame();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
watchBoard() {
|
|
29
|
+
if (this.init) {
|
|
30
|
+
this.initGame();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async initGame(board = this.board) {
|
|
34
|
+
if (!board) {
|
|
35
|
+
throw new Error('Missing board definition');
|
|
36
|
+
}
|
|
37
|
+
this.boardData = board;
|
|
38
|
+
console.log('initGame', this.boardData);
|
|
39
|
+
this.initAnswers();
|
|
40
|
+
this.isInitialized = true;
|
|
41
|
+
}
|
|
42
|
+
initAnswers() {
|
|
43
|
+
this.answers = this.boardData.answers.map(a => {
|
|
44
|
+
return {
|
|
45
|
+
value: a,
|
|
46
|
+
found: false
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
onSelectedChanged(event) {
|
|
51
|
+
this.currentSelected = event.detail;
|
|
52
|
+
}
|
|
53
|
+
isSelectionCorrect = false;
|
|
54
|
+
watchIsDuringCorrect(value) {
|
|
55
|
+
if (value) {
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
this.boardEl?.resetSelection();
|
|
58
|
+
this.isSelectionCorrect = false;
|
|
59
|
+
}, 1000);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
watchCurrentSelected(value) {
|
|
63
|
+
const matchingAnswer = this.answers.find(a => {
|
|
64
|
+
return a.value.toLowerCase() === value.toLowerCase();
|
|
65
|
+
});
|
|
66
|
+
if (matchingAnswer) {
|
|
67
|
+
console.log('znalezione!');
|
|
68
|
+
this.answers = this.answers.map(a => a === matchingAnswer ? { ...a, found: true } : a);
|
|
69
|
+
this.isSelectionCorrect = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
render() {
|
|
73
|
+
return index.h("div", { key: 'eee958199c326614530edf1e642f6b0791091a02' }, this.isInitialized
|
|
74
|
+
? index.h("div", { part: "main", class: "main" }, index.h("div", { part: "answers", class: "answers" }, index.h("ul", null, this.answers.map(a => {
|
|
75
|
+
return index.h("li", { key: a.value, class: { "answer--found": a.found } }, a.value);
|
|
76
|
+
}))), index.h("div", { part: "preview", class: {
|
|
77
|
+
preview: true,
|
|
78
|
+
'preview--correct': this.isSelectionCorrect
|
|
79
|
+
} }, index.h("span", null, "\u00A0"), this.currentSelected), index.h("div", { class: "board" }, index.h("mb-find-words-board", { part: "board", isSelectionCorrect: this.isSelectionCorrect, ref: (el) => this.boardEl = el, letters: this.boardData.letters, width: this.boardData.width })))
|
|
80
|
+
: index.h("div", null, "\u0141adowanie..."));
|
|
81
|
+
}
|
|
82
|
+
static get watchers() { return {
|
|
83
|
+
"board": [{
|
|
84
|
+
"watchBoard": 0
|
|
85
|
+
}],
|
|
86
|
+
"isSelectionCorrect": [{
|
|
87
|
+
"watchIsDuringCorrect": 0
|
|
88
|
+
}],
|
|
89
|
+
"currentSelected": [{
|
|
90
|
+
"watchCurrentSelected": 0
|
|
91
|
+
}]
|
|
92
|
+
}; }
|
|
93
|
+
};
|
|
94
|
+
MbFindWords.style = findWordsCss();
|
|
95
|
+
|
|
96
|
+
const BoardComponent = class {
|
|
97
|
+
constructor(hostRef) {
|
|
98
|
+
index.registerInstance(this, hostRef);
|
|
99
|
+
this.selectedChanged = index.createEvent(this, "selectedChanged");
|
|
100
|
+
}
|
|
101
|
+
letters = '';
|
|
102
|
+
width = 1;
|
|
103
|
+
isSelectionCorrect = false;
|
|
104
|
+
get el() { return index.getElement(this); }
|
|
105
|
+
cellEls = [];
|
|
106
|
+
componentDidLoad() {
|
|
107
|
+
this.cellEls = Array.from(this.el.querySelectorAll('.cell'));
|
|
108
|
+
}
|
|
109
|
+
onCellClicked(index) {
|
|
110
|
+
this.selectCell(index);
|
|
111
|
+
}
|
|
112
|
+
onCellEntered(event, index) {
|
|
113
|
+
if (event.buttons === 1 || event.pointerType === 'touch') {
|
|
114
|
+
this.selectCell(index);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
selectCell(index) {
|
|
118
|
+
if (this.isSelectionCorrect)
|
|
119
|
+
return;
|
|
120
|
+
if (this.head === null) {
|
|
121
|
+
this.head = index;
|
|
122
|
+
this.selectedCells = [index];
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (this.selectedCells.includes(index)) {
|
|
126
|
+
const indexInWord = this.selectedCells.findIndex(x => x === index);
|
|
127
|
+
this.selectedCells = this.selectedCells.slice(0, indexInWord + 1);
|
|
128
|
+
this.head = index;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (index$1.areSiblings(this.head, index, this.width)) {
|
|
132
|
+
this.head = index;
|
|
133
|
+
this.selectedCells = [...this.selectedCells, index];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
this.resetSelection();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async resetSelection() {
|
|
140
|
+
this.selectedCells = [];
|
|
141
|
+
this.head = null;
|
|
142
|
+
}
|
|
143
|
+
async setSelectionAsCorrect() {
|
|
144
|
+
this.isSelectionCorrect = true;
|
|
145
|
+
}
|
|
146
|
+
selectedCells = [];
|
|
147
|
+
head = null;
|
|
148
|
+
path = '';
|
|
149
|
+
buildPolyline(selectedCells) {
|
|
150
|
+
if (selectedCells.length === 0)
|
|
151
|
+
return this.setPoliline([]);
|
|
152
|
+
if (selectedCells.length === 1) {
|
|
153
|
+
const point = this.cellCenterPosition(selectedCells[0]);
|
|
154
|
+
this.setPoliline([point]);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const points = selectedCells.map((index) => this.cellCenterPosition(index));
|
|
158
|
+
this.setPoliline(points);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
setPoliline(points) {
|
|
162
|
+
if (points.length === 0) {
|
|
163
|
+
this.path = '';
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const lastPoint = points[points.length - 1];
|
|
167
|
+
const filledLine = [
|
|
168
|
+
...points,
|
|
169
|
+
...Array(this.letters.length - points.length).fill([...lastPoint])
|
|
170
|
+
];
|
|
171
|
+
this.path = filledLine.reduce((result, point, index) => {
|
|
172
|
+
if (index === 0) {
|
|
173
|
+
return `M ${point[0]} ${point[1]} `;
|
|
174
|
+
}
|
|
175
|
+
return result + `L ${point[0]} ${point[1]}`;
|
|
176
|
+
}, '');
|
|
177
|
+
}
|
|
178
|
+
cellCenterPosition(index) {
|
|
179
|
+
const hostRect = this.el.getBoundingClientRect();
|
|
180
|
+
if (!this.cellEls[index])
|
|
181
|
+
return [0, 0];
|
|
182
|
+
const el = this.cellEls[index];
|
|
183
|
+
const elRect = el.getBoundingClientRect();
|
|
184
|
+
return [
|
|
185
|
+
(elRect.x + elRect.width / 2) - hostRect.x,
|
|
186
|
+
(elRect.y + elRect.height / 2) - hostRect.y
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
selectedChanged;
|
|
190
|
+
emitSelectedChanged() {
|
|
191
|
+
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
192
|
+
this.selectedChanged.emit(data);
|
|
193
|
+
}
|
|
194
|
+
handleTouchEvents(event) {
|
|
195
|
+
if (event.pointerType !== 'touch')
|
|
196
|
+
return;
|
|
197
|
+
const cellIndex = this.cellEls.findIndex(el => {
|
|
198
|
+
const rect = el.getBoundingClientRect();
|
|
199
|
+
const margin = rect.width * .2;
|
|
200
|
+
return ((rect.x + margin) < event.x) &&
|
|
201
|
+
((rect.y + margin) < event.y) &&
|
|
202
|
+
(event.x < (rect.right - margin)) &&
|
|
203
|
+
(event.y < (rect.bottom - margin));
|
|
204
|
+
});
|
|
205
|
+
if (cellIndex >= 0) {
|
|
206
|
+
this.selectCell(cellIndex);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
render() {
|
|
210
|
+
return index.h("div", { key: 'b8805e0252a0e6c5c5be4eaf58706488a4d94e81', class: {
|
|
211
|
+
"grid": true
|
|
212
|
+
}, style: { "--grid-width": `${this.width}` }, onPointerMove: (event) => this.handleTouchEvents(event) }, index.h("svg", { key: '2b9af43e52c23db96f8e73da079799d6b7a766e2' }, index.h("path", { key: '5ff2ac1961a3527d31c8ec9c0fa5587d96b4b9cf', d: this.path })), this.letters.split('').map((letter, index$1) => {
|
|
213
|
+
const isSelected = this.selectedCells.includes(index$1);
|
|
214
|
+
return index.h("div", { class: {
|
|
215
|
+
"cell": true,
|
|
216
|
+
"cell--selected": isSelected,
|
|
217
|
+
"cell--correct": this.isSelectionCorrect
|
|
218
|
+
}, part: "cell", key: index$1 }, index.h("div", { class: "cell__inner", onPointerDown: () => this.onCellClicked(index$1), onPointerEnter: (event) => this.onCellEntered(event, index$1), onKeyDown: (event) => {
|
|
219
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
220
|
+
this.onCellClicked(index$1);
|
|
221
|
+
}
|
|
222
|
+
}, role: "button", tabindex: "0", "aria-label": `Letter ${letter}, ${isSelected ? 'selected' : 'not selected'}` }, letter));
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
static get watchers() { return {
|
|
226
|
+
"selectedCells": [{
|
|
227
|
+
"buildPolyline": 0
|
|
228
|
+
}, {
|
|
229
|
+
"emitSelectedChanged": 0
|
|
230
|
+
}]
|
|
231
|
+
}; }
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
exports.mb_find_words = MbFindWords;
|
|
235
|
+
exports.mb_find_words_board = BoardComponent;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
import { areSiblings } from "../../utils/utils";
|
|
3
|
+
export class BoardComponent {
|
|
4
|
+
letters = '';
|
|
5
|
+
width = 1;
|
|
6
|
+
isSelectionCorrect = false;
|
|
7
|
+
el;
|
|
8
|
+
cellEls = [];
|
|
9
|
+
componentDidLoad() {
|
|
10
|
+
this.cellEls = Array.from(this.el.querySelectorAll('.cell'));
|
|
11
|
+
}
|
|
12
|
+
onCellClicked(index) {
|
|
13
|
+
this.selectCell(index);
|
|
14
|
+
}
|
|
15
|
+
onCellEntered(event, index) {
|
|
16
|
+
if (event.buttons === 1 || event.pointerType === 'touch') {
|
|
17
|
+
this.selectCell(index);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
selectCell(index) {
|
|
21
|
+
if (this.isSelectionCorrect)
|
|
22
|
+
return;
|
|
23
|
+
if (this.head === null) {
|
|
24
|
+
this.head = index;
|
|
25
|
+
this.selectedCells = [index];
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (this.selectedCells.includes(index)) {
|
|
29
|
+
const indexInWord = this.selectedCells.findIndex(x => x === index);
|
|
30
|
+
this.selectedCells = this.selectedCells.slice(0, indexInWord + 1);
|
|
31
|
+
this.head = index;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (areSiblings(this.head, index, this.width)) {
|
|
35
|
+
this.head = index;
|
|
36
|
+
this.selectedCells = [...this.selectedCells, index];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.resetSelection();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async resetSelection() {
|
|
43
|
+
this.selectedCells = [];
|
|
44
|
+
this.head = null;
|
|
45
|
+
}
|
|
46
|
+
async setSelectionAsCorrect() {
|
|
47
|
+
this.isSelectionCorrect = true;
|
|
48
|
+
}
|
|
49
|
+
selectedCells = [];
|
|
50
|
+
head = null;
|
|
51
|
+
path = '';
|
|
52
|
+
buildPolyline(selectedCells) {
|
|
53
|
+
if (selectedCells.length === 0)
|
|
54
|
+
return this.setPoliline([]);
|
|
55
|
+
if (selectedCells.length === 1) {
|
|
56
|
+
const point = this.cellCenterPosition(selectedCells[0]);
|
|
57
|
+
this.setPoliline([point]);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const points = selectedCells.map((index) => this.cellCenterPosition(index));
|
|
61
|
+
this.setPoliline(points);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
setPoliline(points) {
|
|
65
|
+
if (points.length === 0) {
|
|
66
|
+
this.path = '';
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const lastPoint = points[points.length - 1];
|
|
70
|
+
const filledLine = [
|
|
71
|
+
...points,
|
|
72
|
+
...Array(this.letters.length - points.length).fill([...lastPoint])
|
|
73
|
+
];
|
|
74
|
+
this.path = filledLine.reduce((result, point, index) => {
|
|
75
|
+
if (index === 0) {
|
|
76
|
+
return `M ${point[0]} ${point[1]} `;
|
|
77
|
+
}
|
|
78
|
+
return result + `L ${point[0]} ${point[1]}`;
|
|
79
|
+
}, '');
|
|
80
|
+
}
|
|
81
|
+
cellCenterPosition(index) {
|
|
82
|
+
const hostRect = this.el.getBoundingClientRect();
|
|
83
|
+
if (!this.cellEls[index])
|
|
84
|
+
return [0, 0];
|
|
85
|
+
const el = this.cellEls[index];
|
|
86
|
+
const elRect = el.getBoundingClientRect();
|
|
87
|
+
return [
|
|
88
|
+
(elRect.x + elRect.width / 2) - hostRect.x,
|
|
89
|
+
(elRect.y + elRect.height / 2) - hostRect.y
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
selectedChanged;
|
|
93
|
+
emitSelectedChanged() {
|
|
94
|
+
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
95
|
+
this.selectedChanged.emit(data);
|
|
96
|
+
}
|
|
97
|
+
handleTouchEvents(event) {
|
|
98
|
+
if (event.pointerType !== 'touch')
|
|
99
|
+
return;
|
|
100
|
+
const cellIndex = this.cellEls.findIndex(el => {
|
|
101
|
+
const rect = el.getBoundingClientRect();
|
|
102
|
+
const margin = rect.width * .2;
|
|
103
|
+
return ((rect.x + margin) < event.x) &&
|
|
104
|
+
((rect.y + margin) < event.y) &&
|
|
105
|
+
(event.x < (rect.right - margin)) &&
|
|
106
|
+
(event.y < (rect.bottom - margin));
|
|
107
|
+
});
|
|
108
|
+
if (cellIndex >= 0) {
|
|
109
|
+
this.selectCell(cellIndex);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
render() {
|
|
113
|
+
return h("div", { key: 'b8805e0252a0e6c5c5be4eaf58706488a4d94e81', class: {
|
|
114
|
+
"grid": true
|
|
115
|
+
}, style: { "--grid-width": `${this.width}` }, onPointerMove: (event) => this.handleTouchEvents(event) }, h("svg", { key: '2b9af43e52c23db96f8e73da079799d6b7a766e2' }, h("path", { key: '5ff2ac1961a3527d31c8ec9c0fa5587d96b4b9cf', d: this.path })), this.letters.split('').map((letter, index) => {
|
|
116
|
+
const isSelected = this.selectedCells.includes(index);
|
|
117
|
+
return h("div", { class: {
|
|
118
|
+
"cell": true,
|
|
119
|
+
"cell--selected": isSelected,
|
|
120
|
+
"cell--correct": this.isSelectionCorrect
|
|
121
|
+
}, part: "cell", key: index }, h("div", { class: "cell__inner", onPointerDown: () => this.onCellClicked(index), onPointerEnter: (event) => this.onCellEntered(event, index), onKeyDown: (event) => {
|
|
122
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
123
|
+
this.onCellClicked(index);
|
|
124
|
+
}
|
|
125
|
+
}, role: "button", tabindex: "0", "aria-label": `Letter ${letter}, ${isSelected ? 'selected' : 'not selected'}` }, letter));
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
static get is() { return "mb-find-words-board"; }
|
|
129
|
+
static get properties() {
|
|
130
|
+
return {
|
|
131
|
+
"letters": {
|
|
132
|
+
"type": "string",
|
|
133
|
+
"mutable": false,
|
|
134
|
+
"complexType": {
|
|
135
|
+
"original": "string",
|
|
136
|
+
"resolved": "string",
|
|
137
|
+
"references": {}
|
|
138
|
+
},
|
|
139
|
+
"required": false,
|
|
140
|
+
"optional": false,
|
|
141
|
+
"docs": {
|
|
142
|
+
"tags": [],
|
|
143
|
+
"text": ""
|
|
144
|
+
},
|
|
145
|
+
"getter": false,
|
|
146
|
+
"setter": false,
|
|
147
|
+
"reflect": false,
|
|
148
|
+
"attribute": "letters",
|
|
149
|
+
"defaultValue": "''"
|
|
150
|
+
},
|
|
151
|
+
"width": {
|
|
152
|
+
"type": "number",
|
|
153
|
+
"mutable": false,
|
|
154
|
+
"complexType": {
|
|
155
|
+
"original": "number",
|
|
156
|
+
"resolved": "number",
|
|
157
|
+
"references": {}
|
|
158
|
+
},
|
|
159
|
+
"required": false,
|
|
160
|
+
"optional": false,
|
|
161
|
+
"docs": {
|
|
162
|
+
"tags": [],
|
|
163
|
+
"text": ""
|
|
164
|
+
},
|
|
165
|
+
"getter": false,
|
|
166
|
+
"setter": false,
|
|
167
|
+
"reflect": false,
|
|
168
|
+
"attribute": "width",
|
|
169
|
+
"defaultValue": "1"
|
|
170
|
+
},
|
|
171
|
+
"isSelectionCorrect": {
|
|
172
|
+
"type": "boolean",
|
|
173
|
+
"mutable": false,
|
|
174
|
+
"complexType": {
|
|
175
|
+
"original": "boolean",
|
|
176
|
+
"resolved": "boolean",
|
|
177
|
+
"references": {}
|
|
178
|
+
},
|
|
179
|
+
"required": false,
|
|
180
|
+
"optional": false,
|
|
181
|
+
"docs": {
|
|
182
|
+
"tags": [],
|
|
183
|
+
"text": ""
|
|
184
|
+
},
|
|
185
|
+
"getter": false,
|
|
186
|
+
"setter": false,
|
|
187
|
+
"reflect": false,
|
|
188
|
+
"attribute": "is-selection-correct",
|
|
189
|
+
"defaultValue": "false"
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
static get states() {
|
|
194
|
+
return {
|
|
195
|
+
"selectedCells": {},
|
|
196
|
+
"path": {}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
static get events() {
|
|
200
|
+
return [{
|
|
201
|
+
"method": "selectedChanged",
|
|
202
|
+
"name": "selectedChanged",
|
|
203
|
+
"bubbles": true,
|
|
204
|
+
"cancelable": true,
|
|
205
|
+
"composed": true,
|
|
206
|
+
"docs": {
|
|
207
|
+
"tags": [],
|
|
208
|
+
"text": ""
|
|
209
|
+
},
|
|
210
|
+
"complexType": {
|
|
211
|
+
"original": "string",
|
|
212
|
+
"resolved": "string",
|
|
213
|
+
"references": {}
|
|
214
|
+
}
|
|
215
|
+
}];
|
|
216
|
+
}
|
|
217
|
+
static get methods() {
|
|
218
|
+
return {
|
|
219
|
+
"resetSelection": {
|
|
220
|
+
"complexType": {
|
|
221
|
+
"signature": "() => Promise<void>",
|
|
222
|
+
"parameters": [],
|
|
223
|
+
"references": {
|
|
224
|
+
"Promise": {
|
|
225
|
+
"location": "global",
|
|
226
|
+
"id": "global::Promise"
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
"return": "Promise<void>"
|
|
230
|
+
},
|
|
231
|
+
"docs": {
|
|
232
|
+
"text": "",
|
|
233
|
+
"tags": []
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
"setSelectionAsCorrect": {
|
|
237
|
+
"complexType": {
|
|
238
|
+
"signature": "() => Promise<void>",
|
|
239
|
+
"parameters": [],
|
|
240
|
+
"references": {
|
|
241
|
+
"Promise": {
|
|
242
|
+
"location": "global",
|
|
243
|
+
"id": "global::Promise"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"return": "Promise<void>"
|
|
247
|
+
},
|
|
248
|
+
"docs": {
|
|
249
|
+
"text": "",
|
|
250
|
+
"tags": []
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
static get elementRef() { return "el"; }
|
|
256
|
+
static get watchers() {
|
|
257
|
+
return [{
|
|
258
|
+
"propName": "selectedCells",
|
|
259
|
+
"methodName": "buildPolyline"
|
|
260
|
+
}, {
|
|
261
|
+
"propName": "selectedCells",
|
|
262
|
+
"methodName": "emitSelectedChanged"
|
|
263
|
+
}];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
--_mb-default-font: Verdana, Geneva, Tahoma, sans-serif;
|
|
4
|
+
--_mb-font: var(--mb-font, var(--_mb-default-font));
|
|
5
|
+
--_mb-color: var(--mb-color, black);
|
|
6
|
+
--_mb-background: var(--mb-background, white);
|
|
7
|
+
--_mb-board-font-family: var(--mb-board-font-family, var(--_mb-font));
|
|
8
|
+
--_mb-answers-font-family: var(--mb-answers-font-family, var(--_mb-font));
|
|
9
|
+
--_mb-preview-font-family: var(--mb-preview-font-family, var(--_mb-font));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.main {
|
|
13
|
+
display: grid;
|
|
14
|
+
grid-template-columns: 1fr;
|
|
15
|
+
grid-template-areas: "preview" "board" "answers";
|
|
16
|
+
grid-template-rows: min-content 80vw min-content;
|
|
17
|
+
}
|
|
18
|
+
@media (min-width: 576px) {
|
|
19
|
+
.main {
|
|
20
|
+
grid-template-columns: 1fr 1fr;
|
|
21
|
+
grid-template-areas: "answers preview" "answers board";
|
|
22
|
+
grid-template-rows: min-content minmax(300px, 80vh);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.answers {
|
|
27
|
+
grid-area: answers;
|
|
28
|
+
font-family: var(--_mb-answers-font-family);
|
|
29
|
+
}
|
|
30
|
+
.answers ul {
|
|
31
|
+
list-style: none;
|
|
32
|
+
font-size: 22px;
|
|
33
|
+
text-transform: uppercase;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.answer--found {
|
|
37
|
+
text-decoration: line-through;
|
|
38
|
+
color: green;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.preview {
|
|
42
|
+
grid-area: preview;
|
|
43
|
+
min-height: 1.5em;
|
|
44
|
+
font-family: var(--_mb-preview-font-family);
|
|
45
|
+
text-transform: uppercase;
|
|
46
|
+
font-size: 30px;
|
|
47
|
+
text-align: center;
|
|
48
|
+
}
|
|
49
|
+
.preview--correct {
|
|
50
|
+
color: green;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.board {
|
|
54
|
+
display: grid;
|
|
55
|
+
place-content: center;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
position: relative;
|
|
58
|
+
grid-area: board;
|
|
59
|
+
font-family: var(--_mb-board-font-family);
|
|
60
|
+
container-type: size;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
mb-find-words-board {
|
|
64
|
+
display: block;
|
|
65
|
+
aspect-ratio: 1;
|
|
66
|
+
width: min(100cqh, 100cqw);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.grid {
|
|
70
|
+
position: relative;
|
|
71
|
+
display: grid;
|
|
72
|
+
grid-template-columns: repeat(var(--grid-width, 6), 1fr);
|
|
73
|
+
touch-action: none;
|
|
74
|
+
}
|
|
75
|
+
.grid svg {
|
|
76
|
+
display: block;
|
|
77
|
+
position: absolute;
|
|
78
|
+
width: 100%;
|
|
79
|
+
height: 100%;
|
|
80
|
+
top: 0;
|
|
81
|
+
left: 0;
|
|
82
|
+
right: 0;
|
|
83
|
+
bottom: 0;
|
|
84
|
+
pointer-events: none;
|
|
85
|
+
z-index: -1;
|
|
86
|
+
}
|
|
87
|
+
.grid svg polyline,
|
|
88
|
+
.grid svg path {
|
|
89
|
+
stroke: lightskyblue;
|
|
90
|
+
fill: none;
|
|
91
|
+
stroke-width: 40px;
|
|
92
|
+
stroke-linecap: round;
|
|
93
|
+
stroke-linejoin: round;
|
|
94
|
+
transition: all 0.3s;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.cell {
|
|
98
|
+
display: grid;
|
|
99
|
+
aspect-ratio: 1;
|
|
100
|
+
place-content: center;
|
|
101
|
+
container-type: size;
|
|
102
|
+
user-select: none;
|
|
103
|
+
}
|
|
104
|
+
.cell__inner {
|
|
105
|
+
font-size: 80cqh;
|
|
106
|
+
text-transform: uppercase;
|
|
107
|
+
}
|
|
108
|
+
.cell--selected {
|
|
109
|
+
font-weight: bold;
|
|
110
|
+
}
|
|
111
|
+
.cell--selected.cell--correct {
|
|
112
|
+
color: green;
|
|
113
|
+
}
|