guess-the-year-web-component 1.0.3 → 2.0.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/README.md CHANGED
@@ -32,11 +32,17 @@ The guess-the-year element accepts parameters to control it's behaviour:
32
32
  * `impact` : fetch incidents had this impact(s). Reference https://swagger.tee-e.com for a list of supported emotions.
33
33
  * `no-image-src` : what image should be shown when an incident's image is broken. Use a url or base64 encoded image
34
34
  * `report-broken-images` : report broken images back to the server so that they can be repaired
35
- * `delay` : the time (in seconds) waited before the first tip is displayed and the time between the tips
35
+ * `hint-interval-length` : the time (in seconds) waited before the first tip is displayed and the time between the tips
36
+ * `max-hints` : the maximum amount of hints that will be displayed
37
+ * `auto-focus` : set the focus on the answer input element
38
+ * `max-tries` : maximum number of tries before the game stops
39
+ * `show-duration` : display the amount of seconds that it took to answer correctly
40
+ * `show-feedback` : display a feedback input field at the top right of the component
36
41
 
37
42
 
38
43
  ### Adjust the styling
39
44
  The guess-the-year element accepts css parameters to specify (significant parts of) it's styling:
45
+ * `--guess-the-year-font-family` : the font of the tile
40
46
  * `--guess-the-year-title-color` : the text color of the title of the tile
41
47
  * `--guess-the-year-title-background-color`: the background color of the title of the tile
42
48
  * `--guess-the-year-title-font-size` : the font size of the title text of the tile
@@ -45,12 +51,15 @@ The guess-the-year element accepts css parameters to specify (significant parts
45
51
  * `--guess-the-year-text-font-size` : the size of the title text of the tile
46
52
  * `--guess-the-year-text-max-height` : the maximum height of the text of the tile
47
53
  * `--guess-the-year-background-color` : the color of the background of the tile
48
- * `--guess-the-year-image-min-height` : the minimum height of the image
49
- * `--guess-the-year-image-max-height` : the maximum height of the image
54
+ * `--guess-the-year-tile-min-height` : the minimum height of the tile
55
+ * `--guess-the-year-tile-max-height` : the maximum height of the tile
50
56
  * `--guess-the-year-ruler-color` : the color of the ruler that is displayed between two incidents vertically
51
57
  * `--guess-the-year-icon-color` : the color of the incident's category icon
52
58
  * `--guess-the-year-attribution-font-size` : the font size of the list of attributions / sources
53
59
  * `--guess-the-year-attribution-font-color` : the font color of the list of attributions / sources
60
+ * `--guess-the-year-solution-color` : the color of the solution
61
+ * `--guess-the-year-hint-title-background-color` : color of hint title
62
+ * `--guess-the-year-hint-text-background-color` : color of hint text
54
63
 
55
64
  ## Development
56
65
  Fetch all packages: `npm ci`
@@ -64,4 +73,10 @@ Version the application: `npm version major|minor|patch`
64
73
  Build the application: `npm run build:prod`
65
74
  Logon at npmjs.org: `npm login`
66
75
  Publish the application: `npm publish`
67
- Fix access tokens in npmjs.org in case of 403
76
+ Fix access tokens in npmjs.org in case of 403
77
+
78
+ ## Runtime
79
+ Needs permissions for:
80
+ * attribute-yearplusmonth
81
+ * filter-seed
82
+ * filter-maxlasted
@@ -1,6 +1,8 @@
1
1
  import { LitElement, PropertyValues, TemplateResult } from 'lit';
2
2
  import { Incident } from './lib/Incident';
3
3
  export declare class GuessTheYear extends LitElement {
4
+ private _startTime;
5
+ private _endTime;
4
6
  private _uuid;
5
7
  private sources;
6
8
  private _loading;
@@ -17,15 +19,23 @@ export declare class GuessTheYear extends LitElement {
17
19
  to: string;
18
20
  limit: string;
19
21
  shuffle: boolean;
22
+ showDuration: boolean;
23
+ showFeedback: boolean;
20
24
  noImageSrc: string;
21
25
  suppressImages: boolean;
22
- hintIntervalSecs: string;
23
- maxAmountHints: string;
26
+ autoFocus: boolean;
27
+ hintIntervalSecs: number;
28
+ maxHints: number;
29
+ maxTries: number;
24
30
  private _incident;
25
31
  private _hint;
26
- private _answerToDisplay;
32
+ private _solution;
33
+ private _displaySolution;
34
+ private _answeredCorrectly;
35
+ private _tries;
36
+ private _answer;
27
37
  private _apiService;
28
- private _interval;
38
+ private _intervalHandler;
29
39
  private _intervalsPassed;
30
40
  private i18n;
31
41
  static styles: import("lit").CSSResult;
@@ -33,12 +43,19 @@ export declare class GuessTheYear extends LitElement {
33
43
  connectedCallback(): void;
34
44
  disconnectedCallback(): void;
35
45
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
46
+ colorElement(element: any, color: string): void;
36
47
  firstUpdated(changedProperties: PropertyValues): void;
37
48
  shouldUpdate(changedProperties: PropertyValues): boolean;
38
49
  update(changedProperties: PropertyValues): void;
39
50
  updated(changedProperties: PropertyValues): void;
40
51
  render(): TemplateResult<1>;
41
- renderAnswer(year: Number): TemplateResult;
52
+ setupNewGame(): Promise<void>;
53
+ renderRefreshButton(): TemplateResult;
54
+ renderFeedbackPossibility(): TemplateResult;
55
+ renderSubmitPossibility(): TemplateResult;
56
+ renderTries(): TemplateResult;
57
+ renderTheSolution(): TemplateResult;
58
+ renderTheDuration(): TemplateResult;
42
59
  renderTiles(incident: Incident | undefined): TemplateResult<1> | "";
43
60
  private _tileShouldDisplayAnImage;
44
61
  renderTile(incident: Incident): TemplateResult;
@@ -1 +1 @@
1
- {"version":3,"file":"guess-the-year.d.ts","sourceRoot":"","sources":["../src/guess-the-year.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAK5E,OAAO,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;AAMtD,qBACa,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAAS;IAEzB,IAAI,OAAO,IAIQ,OAAO,CAFzB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAGD,UAAU,EAAE,MAAM,CAA2B;IAG7C,kBAAkB,EAAE,OAAO,CAAS;IAGpC,IAAI,EAAE,MAAM,CAAM;IAGlB,OAAO,EAAE,MAAM,CAAM;IAGrB,QAAQ,EAAE,MAAM,CAAM;IAGtB,OAAO,EAAE,MAAM,CAAM;IAGrB,MAAM,EAAE,MAAM,CAAM;IAGpB,IAAI,EAAE,MAAM,CAAM;IAGlB,EAAE,EAAE,MAAM,CAAM;IAGhB,KAAK,E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BAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;IASrD,OAAO,CAAC,iBAAiB;IA6BzB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,cAAc;IAW1D,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;IAQnD,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;IAWnD,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;IAQzD,aAAa,IAAI,cAAc;IAU/B,OAAO,CAAC,cAAc,CAkBnB;IAEH,qBAAqB,QAAS,KAAK,uBA6BjC;CACH;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,YAAY,CAAC;KAChC;CACF"}
@@ -6,13 +6,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { LitElement, css, html } from 'lit';
8
8
  import { customElement, property, state } from 'lit/decorators.js';
9
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
9
10
  import { Task } from '@lit/task';
10
11
  const { setTimeout } = window;
11
12
  import { Categories } from './lib/Incident';
12
- import { NoImageImg } from './lib/Icon';
13
+ import { NoImageImg, RefreshIconSVG } from './lib/Icon';
13
14
  import { ApiService } from './lib/ApiService';
14
15
  import { Util } from './lib/Util';
15
16
  import { i18nFactory } from './lib/i18n/i18n';
17
+ const GREEN = '#07d207';
18
+ const RED = '#ec3737';
19
+ const BLACK = '#000';
16
20
  let GuessTheYear = class GuessTheYear extends LitElement {
17
21
  get loading() {
18
22
  return this._loading;
@@ -22,6 +26,8 @@ let GuessTheYear = class GuessTheYear extends LitElement {
22
26
  }
23
27
  constructor() {
24
28
  super();
29
+ this._startTime = new Date();
30
+ this._endTime = new Date();
25
31
  this._uuid = Math.random();
26
32
  this.sources = [];
27
33
  this._loading = false;
@@ -36,25 +42,32 @@ let GuessTheYear = class GuessTheYear extends LitElement {
36
42
  this.to = '';
37
43
  this.limit = '';
38
44
  this.shuffle = false;
45
+ this.showDuration = false;
46
+ this.showFeedback = false;
39
47
  this.noImageSrc = '';
40
48
  this.suppressImages = false;
41
- this.hintIntervalSecs = '7';
42
- this.maxAmountHints = '3';
49
+ this.autoFocus = false;
50
+ this.hintIntervalSecs = 7;
51
+ this.maxHints = 3;
52
+ this.maxTries = 1;
43
53
  this._incident = undefined;
44
54
  this._hint = undefined;
45
- this._answerToDisplay = undefined;
55
+ this._solution = undefined;
56
+ this._displaySolution = false;
57
+ this._answeredCorrectly = false;
58
+ this._tries = 0;
59
+ // _answer is stored as string because it will be entered character for character
60
+ this._answer = '';
46
61
  this._apiService = new ApiService(this.teeeApiUrl);
47
62
  this._intervalsPassed = 0;
48
63
  this.i18n = i18nFactory('nl-nl');
49
64
  this._incidentsTask = new Task(this, {
50
- task: async ([country, category, emotion, impact, date, from, to,]) => {
65
+ task: async ([]) => {
51
66
  console.debug('incidentsTask');
52
67
  if (!this.loading) {
53
68
  this.loading = true;
54
- const response = await this._apiService.fetchOneIncident(country, category, emotion, impact, date, from, to, '1');
69
+ await this.setupNewGame();
55
70
  this.loading = false;
56
- this._incident = response.incident;
57
- this.sources = response.sources;
58
71
  }
59
72
  },
60
73
  args: () => [
@@ -82,7 +95,7 @@ let GuessTheYear = class GuessTheYear extends LitElement {
82
95
  // Assume we show only one incident.
83
96
  if (this.reportBrokenImages) {
84
97
  if (this._incident) {
85
- this._apiService.postDataQualityFeedback(this._incident.id, 'image', targetImage.src, 'image url is broken');
98
+ this._apiService.postAttributeQualityFeedback(this._incident.id, 'image', targetImage.src, 'image url is broken');
86
99
  }
87
100
  }
88
101
  // wait a bit before setting the image
@@ -96,38 +109,63 @@ let GuessTheYear = class GuessTheYear extends LitElement {
96
109
  connectedCallback() {
97
110
  console.debug('connectedCallback');
98
111
  super.connectedCallback();
99
- this._interval = setInterval(async () => {
100
- var _a;
101
- const year = Number((((_a = this._incident) === null || _a === void 0 ? void 0 : _a.yearplusmonth) || '').substring(0, 4));
102
- this._intervalsPassed += 1;
103
- if (this._intervalsPassed <= Number(this.maxAmountHints)) {
104
- console.log(`${new Date().getTime()} - ${this._uuid} (${this._intervalsPassed}): get hint for year ${year}`);
105
- const response = await this._apiService.fetchOneIncident(this.country, Util.shuffleArray(Categories).shift(), undefined,
106
- // 'moderate,substantial,large,major',
107
- undefined, '', `${year}-01-01`, `${year}-12-31`, undefined);
108
- this._hint = response.incident;
109
- }
110
- else {
111
- this._hint = undefined;
112
- setTimeout(() => {
113
- this._answerToDisplay = year;
114
- }, Number(this.hintIntervalSecs) * 1000);
115
- clearInterval(this._interval);
116
- }
117
- }, Number(this.hintIntervalSecs) * 1000);
118
112
  }
119
113
  disconnectedCallback() {
120
114
  console.debug('disconnectedCallback');
121
115
  super.disconnectedCallback();
122
- clearInterval(this._interval);
116
+ clearInterval(this._intervalHandler);
123
117
  }
124
118
  attributeChangedCallback(name, _old, value) {
125
119
  console.debug('attributeChangedCallback: ', name, _old, value);
126
120
  super.attributeChangedCallback(name, _old, value);
127
121
  }
122
+ colorElement(element, color) {
123
+ var _a, _b;
124
+ (_b = (_a = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(element)) === null || _b === void 0 ? void 0 : _b.style.setProperty('color', color);
125
+ }
128
126
  firstUpdated(changedProperties) {
127
+ var _a, _b, _c, _d, _e, _f;
129
128
  console.debug('firstUpdated');
130
129
  super.firstUpdated(changedProperties);
130
+ // handle answer events
131
+ if ((_a = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#answer')) {
132
+ (_c = (_b = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#answer')) === null || _c === void 0 ? void 0 : _c.addEventListener('input', (event) => {
133
+ var _a;
134
+ this._answer = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value;
135
+ // Display the answer when 4 characters have been inputted.
136
+ if (this._answer.length === 4) {
137
+ this._answeredCorrectly = Number(this._answer) === Number(this._solution);
138
+ if (this._answeredCorrectly) {
139
+ this._displaySolution = true;
140
+ this.colorElement('#answer', GREEN);
141
+ }
142
+ else {
143
+ this.colorElement('#answer', RED);
144
+ }
145
+ this._tries -= 1;
146
+ if (this._tries <= 0) {
147
+ this._displaySolution = true;
148
+ }
149
+ if (this._displaySolution) {
150
+ this._endTime = new Date();
151
+ }
152
+ }
153
+ });
154
+ }
155
+ // handle feedback events
156
+ if ((_d = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector('#feedback')) {
157
+ (_f = (_e = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _e === void 0 ? void 0 : _e.querySelector('#feedback')) === null || _f === void 0 ? void 0 : _f.addEventListener('change', (event) => {
158
+ const element = event === null || event === void 0 ? void 0 : event.target;
159
+ const feedback = element === null || element === void 0 ? void 0 : element.value;
160
+ element.value = this.i18n.translate('sending') + '...';
161
+ setTimeout(() => {
162
+ element.value = '';
163
+ }, 1000);
164
+ if (this._incident) {
165
+ this._apiService.postIncidentQualityFeedback(this._incident.id, feedback);
166
+ }
167
+ });
168
+ }
131
169
  }
132
170
  shouldUpdate(changedProperties) {
133
171
  console.debug('shouldUpdate');
@@ -145,19 +183,97 @@ let GuessTheYear = class GuessTheYear extends LitElement {
145
183
  console.debug('render');
146
184
  return html `
147
185
  <div class="guess-the-year-container">
186
+ ${this.renderRefreshButton()}
148
187
  ${this._incidentsTask.render({
149
188
  pending: () => html `Loading data...`,
150
189
  complete: () => html `${this.renderTiles(this._incident)}`,
151
190
  })}
152
- ${this.renderSources()}
191
+ ${this.renderSubmitPossibility()}
192
+ ${this.renderFeedbackPossibility()}
153
193
  ${this.renderHintTile(this._hint)}
154
- ${this.renderAnswer(this._answerToDisplay || 0)}
194
+ ${this.renderTheSolution()}
195
+ ${this.renderSources()}
155
196
  </div>
156
197
  `;
157
198
  }
158
- renderAnswer(year) {
159
- if (year) {
160
- return html `<div class="answer">${year}</div>`;
199
+ async setupNewGame() {
200
+ var _a, _b;
201
+ console.log('new game!');
202
+ this._incident = undefined;
203
+ this._hint = undefined;
204
+ const response = await this._apiService.fetchOneIncident(this.country, this.category, this.emotion, this.impact, this.date, this.from, this.to, '40');
205
+ this._startTime = new Date();
206
+ this._endTime = new Date();
207
+ this._incident = response.incident;
208
+ this.sources = response.sources;
209
+ this._tries = this.maxTries;
210
+ this._solution = Number((((_a = response.incident) === null || _a === void 0 ? void 0 : _a.yearplusmonth) || '').substring(0, 4));
211
+ this._displaySolution = false;
212
+ this._intervalsPassed = 0;
213
+ this._answer = '';
214
+ this.colorElement('#answer', BLACK);
215
+ const answerInputElement = (_b = this === null || this === void 0 ? void 0 : this.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#answer');
216
+ if (answerInputElement) {
217
+ answerInputElement.value = '';
218
+ if (this.autoFocus) {
219
+ answerInputElement.focus();
220
+ }
221
+ }
222
+ clearInterval(this._intervalHandler);
223
+ this._intervalHandler = setInterval(async () => {
224
+ this._intervalsPassed += 1;
225
+ if (this._intervalsPassed <= this.maxHints) {
226
+ console.log(`${new Date().getTime()} - ${this._uuid} (${this._intervalsPassed}): get hint for year ${this._solution}`);
227
+ const response = await this._apiService.fetchOneIncident(this.country, Util.shuffleArray(Categories).shift(), undefined, undefined, '', `${this._solution}-01-01`, `${this._solution}-12-31`, undefined);
228
+ this._hint = response.incident;
229
+ }
230
+ else {
231
+ this._hint = undefined;
232
+ this._displaySolution = true;
233
+ clearInterval(this._intervalHandler);
234
+ }
235
+ }, this.hintIntervalSecs * 1000);
236
+ this.requestUpdate();
237
+ }
238
+ renderRefreshButton() {
239
+ return html `<div class="refresh" id="refresh" @click="${this.setupNewGame}"><span>${unsafeHTML(RefreshIconSVG)}</span></div>`;
240
+ }
241
+ renderFeedbackPossibility() {
242
+ if (this.showFeedback) {
243
+ return html `<div class="feedback-possibility">
244
+ <input type="text" id="feedback" size="15" placeholder="${this.i18n.translate('your-feedback')}"/>
245
+ </div>`;
246
+ }
247
+ else {
248
+ return html ``;
249
+ }
250
+ }
251
+ renderSubmitPossibility() {
252
+ return html `<div class="submit-possibility">
253
+ <input type="text" id="answer" size="15" ?disabled=${this._displaySolution} placeholder="${this.i18n.translate('your-answer')}"/>
254
+ ${this.renderTries()}
255
+ </div>`;
256
+ }
257
+ renderTries() {
258
+ const i18nKey = this._tries > 1 ? 'tries-left' : 'try-left';
259
+ if (this._tries && !this._displaySolution) {
260
+ return html `<span class="tries">${this.i18n.translate(i18nKey).replace('__TRIES__', '' + this._tries)}</span>`;
261
+ }
262
+ return html ``;
263
+ }
264
+ renderTheSolution() {
265
+ if (this._displaySolution) {
266
+ return html `<div class="solution">${this._solution}</div>
267
+ ${this.renderTheDuration()}
268
+ `;
269
+ }
270
+ return html ``;
271
+ }
272
+ renderTheDuration() {
273
+ const duration = Math.round(new Date(this._endTime.getTime() - this._startTime.getTime()).getTime() / 1000);
274
+ const i18nKey = duration > 1 ? 'in-x-seconds' : 'in-one-second';
275
+ if (this.showDuration && this._answeredCorrectly) {
276
+ return html `<div class="timer">${this.i18n.translate(i18nKey).replace('__SECONDS__', '' + duration)}</div>`;
161
277
  }
162
278
  return html ``;
163
279
  }
@@ -249,7 +365,7 @@ let GuessTheYear = class GuessTheYear extends LitElement {
249
365
  renderTileTextContent(incident) {
250
366
  console.debug('renderTileTextContent');
251
367
  if (incident.text) {
252
- return html `<p>${incident.text}</p>`;
368
+ return html `<p class="hint-text">${incident.text}</p>`;
253
369
  }
254
370
  return html ``;
255
371
  }
@@ -263,7 +379,7 @@ let GuessTheYear = class GuessTheYear extends LitElement {
263
379
  `;
264
380
  }
265
381
  };
266
- GuessTheYear.styles = css `
382
+ GuessTheYear.styles = css `
267
383
  :host {
268
384
  color: var(--guess-the-year-text-color, black);
269
385
  background: var(--guess-the-year-background-color, white);
@@ -278,6 +394,8 @@ GuessTheYear.styles = css `
278
394
  margin: 0;
279
395
  padding: 0;
280
396
  background-color: var(--guess-the-year-background-color);
397
+ min-height: var(--guess-the-year-tile-min-height, 375px);
398
+ max-height: var(--guess-the-year-tile-max-height, 70vh);
281
399
  }
282
400
 
283
401
  .guess-the-year-hint-tile {
@@ -289,6 +407,12 @@ GuessTheYear.styles = css `
289
407
  margin: auto;
290
408
  }
291
409
 
410
+ div.feedback-possibility {
411
+ position: absolute;
412
+ top: 2px;
413
+ right: 4px;
414
+ }
415
+
292
416
  .guess-the-year-hint-tile h1.title {
293
417
  background-color: var(
294
418
  --guess-the-year-hint-title-background-color,
@@ -296,15 +420,51 @@ GuessTheYear.styles = css `
296
420
  );
297
421
  }
298
422
 
299
- div.answer {
423
+ .guess-the-year-hint-tile .hint-text {
424
+ background-color: var(
425
+ --guess-the-year-hint-text-background-color,
426
+ #bebbd8e3
427
+ );
428
+ max-height: 40vh;
429
+ overflow: scroll;
430
+ }
431
+
432
+ div.solution {
300
433
  position: absolute;
301
- top: 50%;
302
- bottom: 0;
434
+ inset: 50% 0px 0px;
435
+ font-size: 70pt;
436
+ color: var(--guess-the-year-solution-color, #b768cf);
437
+ font-weight: bold;
438
+ text-shadow: 2px 2px #0000009e;
439
+ }
440
+
441
+ div.timer {
442
+ font-size: x-small;
443
+ }
444
+
445
+ div.submit-possibility {
303
446
  left: 0;
304
447
  right: 0;
305
- font-size: 100pt;
306
- color: white;
307
- font-weight: bold;
448
+ margin: 2px;
449
+ }
450
+
451
+ div.submit-possibility input {
452
+ font-size: 14pt;
453
+ font-family: var(--guess-the-year-font-family, courier);
454
+ text-align: center;
455
+ line-height: 1.5;
456
+ }
457
+
458
+ div.refresh {
459
+ position: absolute;
460
+ top: 0;
461
+ left: 0;
462
+ z-index: 1;
463
+ width: 32px;
464
+ }
465
+
466
+ span.tries {
467
+ font-size: 8pt;
308
468
  }
309
469
 
310
470
  h1 {
@@ -331,10 +491,10 @@ GuessTheYear.styles = css `
331
491
  padding: 0;
332
492
  display: block;
333
493
  width: 100%;
334
- min-height: var(--guess-the-year-image-min-height, 375px);
335
- max-height: var(--guess-the-year-image-max-height, 70vh);
336
494
  object-fit: cover;
337
495
  object-position: center;
496
+ min-height: var(--guess-the-year-tile-min-height, 375px);
497
+ max-height: var(--guess-the-year-tile-max-height, 70vh);
338
498
  }
339
499
 
340
500
  p {
@@ -423,6 +583,12 @@ __decorate([
423
583
  __decorate([
424
584
  property({ type: Boolean })
425
585
  ], GuessTheYear.prototype, "shuffle", void 0);
586
+ __decorate([
587
+ property({ type: Boolean, attribute: 'show-duration' })
588
+ ], GuessTheYear.prototype, "showDuration", void 0);
589
+ __decorate([
590
+ property({ type: Boolean, attribute: 'show-feedback' })
591
+ ], GuessTheYear.prototype, "showFeedback", void 0);
426
592
  __decorate([
427
593
  property({ type: String, attribute: 'no-image-src' })
428
594
  ], GuessTheYear.prototype, "noImageSrc", void 0);
@@ -430,11 +596,17 @@ __decorate([
430
596
  property({ type: Boolean, attribute: 'suppress-images' })
431
597
  ], GuessTheYear.prototype, "suppressImages", void 0);
432
598
  __decorate([
433
- property({ type: String, attribute: 'hint-interval-length' })
599
+ property({ type: Boolean, attribute: 'auto-focus' })
600
+ ], GuessTheYear.prototype, "autoFocus", void 0);
601
+ __decorate([
602
+ property({ type: Number, attribute: 'hint-interval-length' })
434
603
  ], GuessTheYear.prototype, "hintIntervalSecs", void 0);
435
604
  __decorate([
436
- property({ type: String, attribute: 'max-amount-hints' })
437
- ], GuessTheYear.prototype, "maxAmountHints", void 0);
605
+ property({ type: Number, attribute: 'max-hints' })
606
+ ], GuessTheYear.prototype, "maxHints", void 0);
607
+ __decorate([
608
+ property({ type: Number, attribute: 'max-tries' })
609
+ ], GuessTheYear.prototype, "maxTries", void 0);
438
610
  __decorate([
439
611
  state()
440
612
  ], GuessTheYear.prototype, "_incident", void 0);
@@ -443,7 +615,16 @@ __decorate([
443
615
  ], GuessTheYear.prototype, "_hint", void 0);
444
616
  __decorate([
445
617
  state()
446
- ], GuessTheYear.prototype, "_answerToDisplay", void 0);
618
+ ], GuessTheYear.prototype, "_solution", void 0);
619
+ __decorate([
620
+ state()
621
+ ], GuessTheYear.prototype, "_displaySolution", void 0);
622
+ __decorate([
623
+ state()
624
+ ], GuessTheYear.prototype, "_answeredCorrectly", void 0);
625
+ __decorate([
626
+ state()
627
+ ], GuessTheYear.prototype, "_tries", void 0);
447
628
  GuessTheYear = __decorate([
448
629
  customElement('guess-the-year')
449
630
  ], GuessTheYear);