@mborecki/find-words 0.0.1 → 0.1.0
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/find-words.cjs.js +2 -2
- package/dist/cjs/{index-CpayB0Bf.js → index-B_cfy353.js} +37 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mb-find-words_2.cjs.entry.js +56 -44
- package/dist/collection/components/find-words/board.js +63 -42
- package/dist/collection/components/find-words/find-words.css +31 -8
- package/dist/collection/components/find-words/find-words.js +25 -3
- package/dist/components/index.js +1 -1
- package/dist/components/mb-find-words-board.js +1 -1
- package/dist/components/mb-find-words.js +1 -1
- package/dist/components/p-CPj9RcpU.js +1 -0
- package/dist/esm/find-words.js +3 -3
- package/dist/esm/{index-tKuUvMLJ.js → index-6nWpPHXl.js} +37 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mb-find-words_2.entry.js +56 -44
- package/dist/find-words/find-words.esm.js +1 -1
- package/dist/find-words/{p-tKuUvMLJ.js → p-6nWpPHXl.js} +2 -2
- package/dist/find-words/p-d972a06e.entry.js +1 -0
- package/dist/types/components/find-words/board.d.ts +10 -10
- package/dist/types/components/find-words/find-words.d.ts +1 -0
- package/dist/types/components.d.ts +9 -0
- package/package.json +2 -2
- package/dist/components/p-CttCbs-b.js +0 -1
- package/dist/find-words/p-a991c10e.entry.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-B_cfy353.js');
|
|
4
4
|
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
5
|
|
|
6
6
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -19,7 +19,7 @@ var patchBrowser = () => {
|
|
|
19
19
|
|
|
20
20
|
patchBrowser().then(async (options) => {
|
|
21
21
|
await appGlobals.globalScripts();
|
|
22
|
-
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"],"
|
|
22
|
+
return index.bootstrapLazy([["mb-find-words_2.cjs",[[513,"mb-find-words",{"init":[4],"board":[16],"hideAnswers":[4,"hide-answers"],"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"],"savedPaths":[32],"selectedCells":[32],"resetSelection":[64],"setSelectionAsCorrect":[64],"savePath":[64]},null,{"selectedCells":[{"emitSelectedChanged":0}]}]]]], options);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
exports.setNonce = index.setNonce;
|
|
@@ -2089,6 +2089,13 @@ var h = (nodeName, vnodeData, ...children) => {
|
|
|
2089
2089
|
}
|
|
2090
2090
|
}
|
|
2091
2091
|
}
|
|
2092
|
+
if (typeof nodeName === "function") {
|
|
2093
|
+
return nodeName(
|
|
2094
|
+
vnodeData === null ? {} : vnodeData,
|
|
2095
|
+
vNodeChildren,
|
|
2096
|
+
vdomFnUtils
|
|
2097
|
+
);
|
|
2098
|
+
}
|
|
2092
2099
|
const vnode = newVNode(nodeName, null);
|
|
2093
2100
|
vnode.$attrs$ = vnodeData;
|
|
2094
2101
|
if (vNodeChildren.length > 0) {
|
|
@@ -2117,6 +2124,36 @@ var newVNode = (tag, text) => {
|
|
|
2117
2124
|
};
|
|
2118
2125
|
var Host = {};
|
|
2119
2126
|
var isHost = (node) => node && node.$tag$ === Host;
|
|
2127
|
+
var vdomFnUtils = {
|
|
2128
|
+
forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
|
2129
|
+
map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate)
|
|
2130
|
+
};
|
|
2131
|
+
var convertToPublic = (node) => ({
|
|
2132
|
+
vattrs: node.$attrs$,
|
|
2133
|
+
vchildren: node.$children$,
|
|
2134
|
+
vkey: node.$key$,
|
|
2135
|
+
vname: node.$name$,
|
|
2136
|
+
vtag: node.$tag$,
|
|
2137
|
+
vtext: node.$text$
|
|
2138
|
+
});
|
|
2139
|
+
var convertToPrivate = (node) => {
|
|
2140
|
+
if (typeof node.vtag === "function") {
|
|
2141
|
+
const vnodeData = { ...node.vattrs };
|
|
2142
|
+
if (node.vkey) {
|
|
2143
|
+
vnodeData.key = node.vkey;
|
|
2144
|
+
}
|
|
2145
|
+
if (node.vname) {
|
|
2146
|
+
vnodeData.name = node.vname;
|
|
2147
|
+
}
|
|
2148
|
+
return h(node.vtag, vnodeData, ...node.vchildren || []);
|
|
2149
|
+
}
|
|
2150
|
+
const vnode = newVNode(node.vtag, node.vtext);
|
|
2151
|
+
vnode.$attrs$ = node.vattrs;
|
|
2152
|
+
vnode.$children$ = node.vchildren;
|
|
2153
|
+
vnode.$key$ = node.vkey;
|
|
2154
|
+
vnode.$name$ = node.vname;
|
|
2155
|
+
return vnode;
|
|
2156
|
+
};
|
|
2120
2157
|
var createSupportsRuleRe = (selector) => {
|
|
2121
2158
|
const safeSelector2 = escapeRegExpSpecialCharacters(selector);
|
|
2122
2159
|
return new RegExp(
|
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-B_cfy353.js');
|
|
4
4
|
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
5
|
|
|
6
6
|
const defineCustomElements = async (win, options) => {
|
|
7
7
|
if (typeof window === 'undefined') return undefined;
|
|
8
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"],"
|
|
9
|
+
return index.bootstrapLazy([["mb-find-words_2.cjs",[[513,"mb-find-words",{"init":[4],"board":[16],"hideAnswers":[4,"hide-answers"],"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"],"savedPaths":[32],"selectedCells":[32],"resetSelection":[64],"setSelectionAsCorrect":[64],"savePath":[64]},null,{"selectedCells":[{"emitSelectedChanged":0}]}]]]], options);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
exports.setNonce = index.setNonce;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-B_cfy353.js');
|
|
4
4
|
var index$1 = require('./index.cjs.js');
|
|
5
5
|
|
|
6
|
-
const findWordsCss = () => `:host{display:
|
|
6
|
+
const findWordsCss = () => `:host{box-sizing:border-box;display:grid;place-content:center;width:100%;height:100%;container-type:size;--_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));--_mb-select-line-color:var(--mb-select-line-color, red);--_mb-select-line-width:var(--mb-select-line-width, 40px)}[part=main]{display:grid;grid-template-columns:1fr;grid-template-areas:"preview" "board" "answers";grid-template-rows:min-content 1fr min-content;width:min(100cqw, 100cqh / var(--aspect, 1));height:min(100cqw * var(--aspect, 1), 100cqh);color:var(--_mb-color);background:var(--_mb-background)}[part=main].no-answers{grid-template-areas:"preview" "board";grid-template-rows:min-content 1fr}@media (min-width: 576px){[part=main]{grid-template-columns:1fr 1fr;grid-template-areas:"answers preview" "answers board";grid-template-rows:min-content minmax(300px, 80vh)}[part=main].no-answers{grid-template-columns:1fr;grid-template-areas:"preview" "board";grid-template-rows:min-content 1fr}}.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:start 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}.grid svg polyline,.grid svg path{stroke:var(--_mb-select-line-color);fill:none;stroke-width:var(--_mb-select-line-width);stroke-linecap:round;stroke-linejoin:round;transition:all 0.3s}.grid svg.saved{--_mb-select-line-color:#ddd}.cell{display:grid;aspect-ratio:1;place-content:center;container-type:size;user-select:none;z-index:1}.cell__inner{font-size:80cqh;text-transform:uppercase}.cell--selected{font-weight:bold}.cell--selected.cell--correct{color:green}`;
|
|
7
7
|
|
|
8
8
|
const MbFindWords = class {
|
|
9
9
|
constructor(hostRef) {
|
|
@@ -14,6 +14,7 @@ const MbFindWords = class {
|
|
|
14
14
|
*/
|
|
15
15
|
init = true;
|
|
16
16
|
board;
|
|
17
|
+
hideAnswers = false;
|
|
17
18
|
boardData;
|
|
18
19
|
boardEl;
|
|
19
20
|
isInitialized = false;
|
|
@@ -67,17 +68,18 @@ const MbFindWords = class {
|
|
|
67
68
|
console.log('znalezione!');
|
|
68
69
|
this.answers = this.answers.map(a => a === matchingAnswer ? { ...a, found: true } : a);
|
|
69
70
|
this.isSelectionCorrect = true;
|
|
71
|
+
this.boardEl?.savePath();
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
render() {
|
|
73
|
-
return
|
|
74
|
-
? index.h("div", { part: "main", class:
|
|
75
|
+
return this.isInitialized
|
|
76
|
+
? index.h("div", { part: "main", class: { 'no-answers': this.hideAnswers } }, this.hideAnswers ? '' : index.h("div", { part: "answers", class: "answers" }, index.h("ul", null, this.answers.map(a => {
|
|
75
77
|
return index.h("li", { key: a.value, class: { "answer--found": a.found } }, a.value);
|
|
76
78
|
}))), index.h("div", { part: "preview", class: {
|
|
77
79
|
preview: true,
|
|
78
80
|
'preview--correct': this.isSelectionCorrect
|
|
79
81
|
} }, 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...")
|
|
82
|
+
: index.h("div", null, "\u0141adowanie...");
|
|
81
83
|
}
|
|
82
84
|
static get watchers() { return {
|
|
83
85
|
"board": [{
|
|
@@ -101,7 +103,28 @@ const BoardComponent = class {
|
|
|
101
103
|
letters = '';
|
|
102
104
|
width = 1;
|
|
103
105
|
isSelectionCorrect = false;
|
|
106
|
+
selectedChanged;
|
|
104
107
|
get el() { return index.getElement(this); }
|
|
108
|
+
savedPaths = [];
|
|
109
|
+
selectedCells = [];
|
|
110
|
+
emitSelectedChanged() {
|
|
111
|
+
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
112
|
+
this.selectedChanged.emit(data);
|
|
113
|
+
}
|
|
114
|
+
async resetSelection() {
|
|
115
|
+
this.selectedCells = [];
|
|
116
|
+
this.head = null;
|
|
117
|
+
}
|
|
118
|
+
async setSelectionAsCorrect() {
|
|
119
|
+
this.isSelectionCorrect = true;
|
|
120
|
+
}
|
|
121
|
+
savePath() {
|
|
122
|
+
this.savedPaths = [
|
|
123
|
+
...this.savedPaths,
|
|
124
|
+
[...this.selectedCells]
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
head = null;
|
|
105
128
|
cellEls = [];
|
|
106
129
|
componentDidLoad() {
|
|
107
130
|
this.cellEls = Array.from(this.el.querySelectorAll('.cell'));
|
|
@@ -136,44 +159,17 @@ const BoardComponent = class {
|
|
|
136
159
|
this.resetSelection();
|
|
137
160
|
}
|
|
138
161
|
}
|
|
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
162
|
buildPolyline(selectedCells) {
|
|
150
163
|
if (selectedCells.length === 0)
|
|
151
|
-
return
|
|
164
|
+
return [];
|
|
152
165
|
if (selectedCells.length === 1) {
|
|
153
166
|
const point = this.cellCenterPosition(selectedCells[0]);
|
|
154
|
-
|
|
167
|
+
return [point];
|
|
155
168
|
}
|
|
156
169
|
else {
|
|
157
170
|
const points = selectedCells.map((index) => this.cellCenterPosition(index));
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
setPoliline(points) {
|
|
162
|
-
if (points.length === 0) {
|
|
163
|
-
this.path = '';
|
|
164
|
-
return;
|
|
171
|
+
return points;
|
|
165
172
|
}
|
|
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
173
|
}
|
|
178
174
|
cellCenterPosition(index) {
|
|
179
175
|
const hostRect = this.el.getBoundingClientRect();
|
|
@@ -186,11 +182,6 @@ const BoardComponent = class {
|
|
|
186
182
|
(elRect.y + elRect.height / 2) - hostRect.y
|
|
187
183
|
];
|
|
188
184
|
}
|
|
189
|
-
selectedChanged;
|
|
190
|
-
emitSelectedChanged() {
|
|
191
|
-
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
192
|
-
this.selectedChanged.emit(data);
|
|
193
|
-
}
|
|
194
185
|
handleTouchEvents(event) {
|
|
195
186
|
if (event.pointerType !== 'touch')
|
|
196
187
|
return;
|
|
@@ -207,9 +198,11 @@ const BoardComponent = class {
|
|
|
207
198
|
}
|
|
208
199
|
}
|
|
209
200
|
render() {
|
|
210
|
-
return index.h("div", { key: '
|
|
201
|
+
return index.h("div", { key: '9d51872a06146b8fba79aa8809837c39caaf50b6', class: {
|
|
211
202
|
"grid": true
|
|
212
|
-
}, style: {
|
|
203
|
+
}, style: {
|
|
204
|
+
"--grid-width": `${this.width}`
|
|
205
|
+
}, onPointerMove: (event) => this.handleTouchEvents(event) }, index.h(PathsSVG, { key: '1bd0de6f34ca28ee2f772d5ac50dc9a705aeed58', maxSize: this.letters.length, cl: "active", paths: [this.buildPolyline(this.selectedCells)] }), index.h(PathsSVG, { key: '2da096e16d933dc01fe7b184b4eb22db271d5464', maxSize: this.letters.length, cl: "saved", paths: this.savedPaths.map(p => this.buildPolyline(p)) }), this.letters.split('').map((letter, index$1) => {
|
|
213
206
|
const isSelected = this.selectedCells.includes(index$1);
|
|
214
207
|
return index.h("div", { class: {
|
|
215
208
|
"cell": true,
|
|
@@ -224,12 +217,31 @@ const BoardComponent = class {
|
|
|
224
217
|
}
|
|
225
218
|
static get watchers() { return {
|
|
226
219
|
"selectedCells": [{
|
|
227
|
-
"buildPolyline": 0
|
|
228
|
-
}, {
|
|
229
220
|
"emitSelectedChanged": 0
|
|
230
221
|
}]
|
|
231
222
|
}; }
|
|
232
223
|
};
|
|
224
|
+
function PathsSVG({ paths, maxSize, cl }) {
|
|
225
|
+
const data = paths.map(points => {
|
|
226
|
+
if (points.length === 0) {
|
|
227
|
+
return '';
|
|
228
|
+
}
|
|
229
|
+
const lastPoint = points[points.length - 1];
|
|
230
|
+
const filledLine = [
|
|
231
|
+
...points,
|
|
232
|
+
...Array(maxSize - points.length).fill([...lastPoint])
|
|
233
|
+
];
|
|
234
|
+
return filledLine.reduce((result, point, index) => {
|
|
235
|
+
if (index === 0) {
|
|
236
|
+
return `M ${point[0]} ${point[1]} `;
|
|
237
|
+
}
|
|
238
|
+
return result + `L ${point[0]} ${point[1]}`;
|
|
239
|
+
}, '');
|
|
240
|
+
});
|
|
241
|
+
return index.h("svg", { class: cl }, data.map(path => {
|
|
242
|
+
return index.h("path", { d: path });
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
233
245
|
|
|
234
246
|
exports.mb_find_words = MbFindWords;
|
|
235
247
|
exports.mb_find_words_board = BoardComponent;
|
|
@@ -4,7 +4,28 @@ export class BoardComponent {
|
|
|
4
4
|
letters = '';
|
|
5
5
|
width = 1;
|
|
6
6
|
isSelectionCorrect = false;
|
|
7
|
+
selectedChanged;
|
|
7
8
|
el;
|
|
9
|
+
savedPaths = [];
|
|
10
|
+
selectedCells = [];
|
|
11
|
+
emitSelectedChanged() {
|
|
12
|
+
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
13
|
+
this.selectedChanged.emit(data);
|
|
14
|
+
}
|
|
15
|
+
async resetSelection() {
|
|
16
|
+
this.selectedCells = [];
|
|
17
|
+
this.head = null;
|
|
18
|
+
}
|
|
19
|
+
async setSelectionAsCorrect() {
|
|
20
|
+
this.isSelectionCorrect = true;
|
|
21
|
+
}
|
|
22
|
+
savePath() {
|
|
23
|
+
this.savedPaths = [
|
|
24
|
+
...this.savedPaths,
|
|
25
|
+
[...this.selectedCells]
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
head = null;
|
|
8
29
|
cellEls = [];
|
|
9
30
|
componentDidLoad() {
|
|
10
31
|
this.cellEls = Array.from(this.el.querySelectorAll('.cell'));
|
|
@@ -39,45 +60,18 @@ export class BoardComponent {
|
|
|
39
60
|
this.resetSelection();
|
|
40
61
|
}
|
|
41
62
|
}
|
|
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
63
|
buildPolyline(selectedCells) {
|
|
53
64
|
if (selectedCells.length === 0)
|
|
54
|
-
return
|
|
65
|
+
return [];
|
|
55
66
|
if (selectedCells.length === 1) {
|
|
56
67
|
const point = this.cellCenterPosition(selectedCells[0]);
|
|
57
|
-
|
|
68
|
+
return [point];
|
|
58
69
|
}
|
|
59
70
|
else {
|
|
60
71
|
const points = selectedCells.map((index) => this.cellCenterPosition(index));
|
|
61
|
-
|
|
72
|
+
return points;
|
|
62
73
|
}
|
|
63
74
|
}
|
|
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
75
|
cellCenterPosition(index) {
|
|
82
76
|
const hostRect = this.el.getBoundingClientRect();
|
|
83
77
|
if (!this.cellEls[index])
|
|
@@ -89,11 +83,6 @@ export class BoardComponent {
|
|
|
89
83
|
(elRect.y + elRect.height / 2) - hostRect.y
|
|
90
84
|
];
|
|
91
85
|
}
|
|
92
|
-
selectedChanged;
|
|
93
|
-
emitSelectedChanged() {
|
|
94
|
-
const data = this.selectedCells.map(i => this.letters[i]).join('');
|
|
95
|
-
this.selectedChanged.emit(data);
|
|
96
|
-
}
|
|
97
86
|
handleTouchEvents(event) {
|
|
98
87
|
if (event.pointerType !== 'touch')
|
|
99
88
|
return;
|
|
@@ -110,9 +99,11 @@ export class BoardComponent {
|
|
|
110
99
|
}
|
|
111
100
|
}
|
|
112
101
|
render() {
|
|
113
|
-
return h("div", { key: '
|
|
102
|
+
return h("div", { key: '9d51872a06146b8fba79aa8809837c39caaf50b6', class: {
|
|
114
103
|
"grid": true
|
|
115
|
-
}, style: {
|
|
104
|
+
}, style: {
|
|
105
|
+
"--grid-width": `${this.width}`
|
|
106
|
+
}, onPointerMove: (event) => this.handleTouchEvents(event) }, h(PathsSVG, { key: '1bd0de6f34ca28ee2f772d5ac50dc9a705aeed58', maxSize: this.letters.length, cl: "active", paths: [this.buildPolyline(this.selectedCells)] }), h(PathsSVG, { key: '2da096e16d933dc01fe7b184b4eb22db271d5464', maxSize: this.letters.length, cl: "saved", paths: this.savedPaths.map(p => this.buildPolyline(p)) }), this.letters.split('').map((letter, index) => {
|
|
116
107
|
const isSelected = this.selectedCells.includes(index);
|
|
117
108
|
return h("div", { class: {
|
|
118
109
|
"cell": true,
|
|
@@ -192,8 +183,8 @@ export class BoardComponent {
|
|
|
192
183
|
}
|
|
193
184
|
static get states() {
|
|
194
185
|
return {
|
|
195
|
-
"
|
|
196
|
-
"
|
|
186
|
+
"savedPaths": {},
|
|
187
|
+
"selectedCells": {}
|
|
197
188
|
};
|
|
198
189
|
}
|
|
199
190
|
static get events() {
|
|
@@ -249,17 +240,47 @@ export class BoardComponent {
|
|
|
249
240
|
"text": "",
|
|
250
241
|
"tags": []
|
|
251
242
|
}
|
|
243
|
+
},
|
|
244
|
+
"savePath": {
|
|
245
|
+
"complexType": {
|
|
246
|
+
"signature": "() => Promise<void>",
|
|
247
|
+
"parameters": [],
|
|
248
|
+
"references": {},
|
|
249
|
+
"return": "Promise<void>"
|
|
250
|
+
},
|
|
251
|
+
"docs": {
|
|
252
|
+
"text": "",
|
|
253
|
+
"tags": []
|
|
254
|
+
}
|
|
252
255
|
}
|
|
253
256
|
};
|
|
254
257
|
}
|
|
255
258
|
static get elementRef() { return "el"; }
|
|
256
259
|
static get watchers() {
|
|
257
260
|
return [{
|
|
258
|
-
"propName": "selectedCells",
|
|
259
|
-
"methodName": "buildPolyline"
|
|
260
|
-
}, {
|
|
261
261
|
"propName": "selectedCells",
|
|
262
262
|
"methodName": "emitSelectedChanged"
|
|
263
263
|
}];
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
|
+
function PathsSVG({ paths, maxSize, cl }) {
|
|
267
|
+
const data = paths.map(points => {
|
|
268
|
+
if (points.length === 0) {
|
|
269
|
+
return '';
|
|
270
|
+
}
|
|
271
|
+
const lastPoint = points[points.length - 1];
|
|
272
|
+
const filledLine = [
|
|
273
|
+
...points,
|
|
274
|
+
...Array(maxSize - points.length).fill([...lastPoint])
|
|
275
|
+
];
|
|
276
|
+
return filledLine.reduce((result, point, index) => {
|
|
277
|
+
if (index === 0) {
|
|
278
|
+
return `M ${point[0]} ${point[1]} `;
|
|
279
|
+
}
|
|
280
|
+
return result + `L ${point[0]} ${point[1]}`;
|
|
281
|
+
}, '');
|
|
282
|
+
});
|
|
283
|
+
return h("svg", { class: cl }, data.map(path => {
|
|
284
|
+
return h("path", { d: path });
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
:host {
|
|
2
|
-
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
display: grid;
|
|
4
|
+
place-content: center;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
container-type: size;
|
|
3
8
|
--_mb-default-font: Verdana, Geneva, Tahoma, sans-serif;
|
|
4
9
|
--_mb-font: var(--mb-font, var(--_mb-default-font));
|
|
5
10
|
--_mb-color: var(--mb-color, black);
|
|
@@ -7,20 +12,35 @@
|
|
|
7
12
|
--_mb-board-font-family: var(--mb-board-font-family, var(--_mb-font));
|
|
8
13
|
--_mb-answers-font-family: var(--mb-answers-font-family, var(--_mb-font));
|
|
9
14
|
--_mb-preview-font-family: var(--mb-preview-font-family, var(--_mb-font));
|
|
15
|
+
--_mb-select-line-color: var(--mb-select-line-color, red);
|
|
16
|
+
--_mb-select-line-width: var(--mb-select-line-width, 40px);
|
|
10
17
|
}
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
[part=main] {
|
|
13
20
|
display: grid;
|
|
14
21
|
grid-template-columns: 1fr;
|
|
15
22
|
grid-template-areas: "preview" "board" "answers";
|
|
16
|
-
grid-template-rows: min-content
|
|
23
|
+
grid-template-rows: min-content 1fr min-content;
|
|
24
|
+
width: min(100cqw, 100cqh / var(--aspect, 1));
|
|
25
|
+
height: min(100cqw * var(--aspect, 1), 100cqh);
|
|
26
|
+
color: var(--_mb-color);
|
|
27
|
+
background: var(--_mb-background);
|
|
28
|
+
}
|
|
29
|
+
[part=main].no-answers {
|
|
30
|
+
grid-template-areas: "preview" "board";
|
|
31
|
+
grid-template-rows: min-content 1fr;
|
|
17
32
|
}
|
|
18
33
|
@media (min-width: 576px) {
|
|
19
|
-
|
|
34
|
+
[part=main] {
|
|
20
35
|
grid-template-columns: 1fr 1fr;
|
|
21
36
|
grid-template-areas: "answers preview" "answers board";
|
|
22
37
|
grid-template-rows: min-content minmax(300px, 80vh);
|
|
23
38
|
}
|
|
39
|
+
[part=main].no-answers {
|
|
40
|
+
grid-template-columns: 1fr;
|
|
41
|
+
grid-template-areas: "preview" "board";
|
|
42
|
+
grid-template-rows: min-content 1fr;
|
|
43
|
+
}
|
|
24
44
|
}
|
|
25
45
|
|
|
26
46
|
.answers {
|
|
@@ -52,7 +72,7 @@
|
|
|
52
72
|
|
|
53
73
|
.board {
|
|
54
74
|
display: grid;
|
|
55
|
-
place-content: center;
|
|
75
|
+
place-content: start center;
|
|
56
76
|
overflow: hidden;
|
|
57
77
|
position: relative;
|
|
58
78
|
grid-area: board;
|
|
@@ -82,17 +102,19 @@ mb-find-words-board {
|
|
|
82
102
|
right: 0;
|
|
83
103
|
bottom: 0;
|
|
84
104
|
pointer-events: none;
|
|
85
|
-
z-index: -1;
|
|
86
105
|
}
|
|
87
106
|
.grid svg polyline,
|
|
88
107
|
.grid svg path {
|
|
89
|
-
stroke:
|
|
108
|
+
stroke: var(--_mb-select-line-color);
|
|
90
109
|
fill: none;
|
|
91
|
-
stroke-width:
|
|
110
|
+
stroke-width: var(--_mb-select-line-width);
|
|
92
111
|
stroke-linecap: round;
|
|
93
112
|
stroke-linejoin: round;
|
|
94
113
|
transition: all 0.3s;
|
|
95
114
|
}
|
|
115
|
+
.grid svg.saved {
|
|
116
|
+
--_mb-select-line-color: #ddd;
|
|
117
|
+
}
|
|
96
118
|
|
|
97
119
|
.cell {
|
|
98
120
|
display: grid;
|
|
@@ -100,6 +122,7 @@ mb-find-words-board {
|
|
|
100
122
|
place-content: center;
|
|
101
123
|
container-type: size;
|
|
102
124
|
user-select: none;
|
|
125
|
+
z-index: 1;
|
|
103
126
|
}
|
|
104
127
|
.cell__inner {
|
|
105
128
|
font-size: 80cqh;
|
|
@@ -5,6 +5,7 @@ export class MbFindWords {
|
|
|
5
5
|
*/
|
|
6
6
|
init = true;
|
|
7
7
|
board;
|
|
8
|
+
hideAnswers = false;
|
|
8
9
|
boardData;
|
|
9
10
|
boardEl;
|
|
10
11
|
isInitialized = false;
|
|
@@ -58,17 +59,18 @@ export class MbFindWords {
|
|
|
58
59
|
console.log('znalezione!');
|
|
59
60
|
this.answers = this.answers.map(a => a === matchingAnswer ? { ...a, found: true } : a);
|
|
60
61
|
this.isSelectionCorrect = true;
|
|
62
|
+
this.boardEl?.savePath();
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
render() {
|
|
64
|
-
return
|
|
65
|
-
? h("div", { part: "main", class:
|
|
66
|
+
return this.isInitialized
|
|
67
|
+
? h("div", { part: "main", class: { 'no-answers': this.hideAnswers } }, this.hideAnswers ? '' : h("div", { part: "answers", class: "answers" }, h("ul", null, this.answers.map(a => {
|
|
66
68
|
return h("li", { key: a.value, class: { "answer--found": a.found } }, a.value);
|
|
67
69
|
}))), h("div", { part: "preview", class: {
|
|
68
70
|
preview: true,
|
|
69
71
|
'preview--correct': this.isSelectionCorrect
|
|
70
72
|
} }, h("span", null, "\u00A0"), this.currentSelected), h("div", { class: "board" }, h("mb-find-words-board", { part: "board", isSelectionCorrect: this.isSelectionCorrect, ref: (el) => this.boardEl = el, letters: this.boardData.letters, width: this.boardData.width })))
|
|
71
|
-
: h("div", null, "\u0141adowanie...")
|
|
73
|
+
: h("div", null, "\u0141adowanie...");
|
|
72
74
|
}
|
|
73
75
|
static get is() { return "mb-find-words"; }
|
|
74
76
|
static get encapsulation() { return "shadow"; }
|
|
@@ -127,6 +129,26 @@ export class MbFindWords {
|
|
|
127
129
|
},
|
|
128
130
|
"getter": false,
|
|
129
131
|
"setter": false
|
|
132
|
+
},
|
|
133
|
+
"hideAnswers": {
|
|
134
|
+
"type": "boolean",
|
|
135
|
+
"mutable": false,
|
|
136
|
+
"complexType": {
|
|
137
|
+
"original": "boolean",
|
|
138
|
+
"resolved": "boolean",
|
|
139
|
+
"references": {}
|
|
140
|
+
},
|
|
141
|
+
"required": false,
|
|
142
|
+
"optional": false,
|
|
143
|
+
"docs": {
|
|
144
|
+
"tags": [],
|
|
145
|
+
"text": ""
|
|
146
|
+
},
|
|
147
|
+
"getter": false,
|
|
148
|
+
"setter": false,
|
|
149
|
+
"reflect": false,
|
|
150
|
+
"attribute": "hide-answers",
|
|
151
|
+
"defaultValue": "false"
|
|
130
152
|
}
|
|
131
153
|
};
|
|
132
154
|
}
|