From 622953ad45d53adcf8e92d695ac9a6b7ee039c70 Mon Sep 17 00:00:00 2001 From: Gamaliel Garcia <46827955+EGAMAGZ@users.noreply.github.com> Date: Tue, 21 May 2024 18:00:25 -0600 Subject: [PATCH 1/5] chore(example): Removed paska-ovo jsr package to import locally instead --- example/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/example/package.json b/example/package.json index c2fb55f..dad23f3 100644 --- a/example/package.json +++ b/example/package.json @@ -13,7 +13,6 @@ "@astrojs/check": "^0.5.10", "@astrojs/preact": "^3.2.0", "@astrojs/tailwind": "^5.1.0", - "@egamagz/paska-ovo": "npm:@jsr/egamagz__paska-ovo@^0.1.2", "@preact/signals": "^1.2.3", "@preact/signals-core": "^1.6.0", "@tabler/icons-preact": "^3.3.0", From c6aa4071c1dd672a563935ef5af67073b1ef2a83 Mon Sep 17 00:00:00 2001 From: Gamaliel Garcia <46827955+EGAMAGZ@users.noreply.github.com> Date: Tue, 21 May 2024 18:55:50 -0600 Subject: [PATCH 2/5] refactor: Removed unnecesary validations --- src/paska-ovo.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/paska-ovo.ts b/src/paska-ovo.ts index 9cde53e..265723e 100644 --- a/src/paska-ovo.ts +++ b/src/paska-ovo.ts @@ -112,19 +112,14 @@ export class PaskaOvo { * @param {EasterEgg[]} easterEggs - List of easter eggs to trigger. */ private handleKeyEvent(event: KeyboardEvent, easterEggs: EasterEgg[]) { - if (easterEggs.length === 0) { - return; - } - const { key } = event; - - easterEggs.forEach((easterEgg) => { + for (const easterEgg of easterEggs) { const actualCodePosition = this.easterEggState[easterEgg.tag] || 0; const actualCode = easterEgg.code[actualCodePosition]; if (key !== actualCode) { this.easterEggState[easterEgg.tag] = 0; - return; + continue; } const nextCodePosition = actualCodePosition + 1; @@ -136,7 +131,7 @@ export class PaskaOvo { } else { this.easterEggState[easterEgg.tag] = nextCodePosition; } - }); + } } /** From 4c445988c534d812dea0b2a81780e6cbd9b3f158 Mon Sep 17 00:00:00 2001 From: Gamaliel Garcia <46827955+EGAMAGZ@users.noreply.github.com> Date: Tue, 21 May 2024 18:56:39 -0600 Subject: [PATCH 3/5] fix(example): Favicon didn't show up --- example/package-lock.json | 7 ------- example/src/layouts/Layout.astro | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 20b3c68..0974ba3 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -11,7 +11,6 @@ "@astrojs/check": "^0.5.10", "@astrojs/preact": "^3.2.0", "@astrojs/tailwind": "^5.1.0", - "@egamagz/paska-ovo": "npm:@jsr/egamagz__paska-ovo@^0.1.2", "@preact/signals": "^1.2.3", "@preact/signals-core": "^1.6.0", "@tabler/icons-preact": "^3.3.0", @@ -555,12 +554,6 @@ "node": ">=6.9.0" } }, - "node_modules/@egamagz/paska-ovo": { - "name": "@jsr/egamagz__paska-ovo", - "version": "0.1.2", - "resolved": "https://npm.jsr.io/~/10/@jsr/egamagz__paska-ovo/0.1.2.tgz", - "integrity": "sha512-Gzo8p+r4UxlPG9Dt9p9SePLfEL9o6Jtpzq2Hovhp5vfB2bWSNzsoBhquuGKdnYUrOQXzsG1AaXzxxodGd8Fn5w==" - }, "node_modules/@emmetio/abbreviation": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/@emmetio/abbreviation/-/abbreviation-2.3.3.tgz", diff --git a/example/src/layouts/Layout.astro b/example/src/layouts/Layout.astro index 6223b6d..5981487 100644 --- a/example/src/layouts/Layout.astro +++ b/example/src/layouts/Layout.astro @@ -1,7 +1,7 @@
- + Date: Tue, 21 May 2024 19:04:19 -0600 Subject: [PATCH 4/5] feat(example): Added easter egg that overlaps most of it with the konami code --- example/src/components/EasterEgg.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/components/EasterEgg.tsx b/example/src/components/EasterEgg.tsx index 0cea684..faa382b 100644 --- a/example/src/components/EasterEgg.tsx +++ b/example/src/components/EasterEgg.tsx @@ -32,6 +32,13 @@ export default function EasterEgg() { }, tag: "Konami" }) + .addCode({ + code: ["up", "up", "down", "down", "left", "right", "left", "right", "b", "a", "c"], + onFound: () => { + alert("Nothing to show here... Sorry :(") + }, + tag: "Konami+C" + }) .addCode({ code: ["a", "w", "e", "s", "o", "m", "e"], onFound: () => { From fad905b3efd58e07b99c4b8411ce7d0fb26c5bf2 Mon Sep 17 00:00:00 2001 From: Gamaliel Garcia <46827955+EGAMAGZ@users.noreply.github.com> Date: Tue, 21 May 2024 21:35:35 -0600 Subject: [PATCH 5/5] doc: Improved documentation, making clear the nomenclature of the navigation and control keys used for eastereggs codes --- src/types.ts | 44 ++++++++++++++++++++++++++++++++++++++++++- src/util/constants.ts | 1 - 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index 5e6ef4e..f032c2b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,10 +7,52 @@ /** * Type with the properties of an easter egg. * + * @example + * A simple easter egg: + * ```typescript + * import { EasterEgg } from "@egamagz/paska-ovo"; + * + * const easterEgg: EasterEgg = { + * code: ["up", "up", "down", "down", "left", "right", "left", "right", "b", "a"], + * onFound: () => { + * // Do something when the easter egg is found + * }, + * tag: "Konami", + * } + * ``` + * + * @example + * An easter egg with a duration: + * ```typescript + * const easterEgg: EasterEgg = { + * code: ["up", "right", "down", "left"], + * onFound: () => { + * // Do something when the easter egg is found + * }, + * onFinish() { + * // Do something when the duration of the easter egg is over + * }, + * duration: 1000, + * tag: "Barrel Roll" + * } + * ``` */ export type EasterEgg = { /** - * Sequence of keys that will trigger the easter egg. + * Key sequence that will activate the easter egg. The code can contain + * letters (which will only be detected as lowercase), numbers and navigation + * and control keys. The navigation and control keys are indicated by the following nomenclature: + * * `up`: `ArrowUp` + * * `down`: `ArrowDown` + * * `left`: `ArrowLeft` + * * `right`: `ArrowRight` + * * `enter`: `Enter` + * * `space`: `Space` + * * `ctrl`: `Control` + * * `alt`: `Alt` + * * `tab`: `Tab` + * * `esc`: `Escape` + * * `slash`: `/` */ code: string[], /** diff --git a/src/util/constants.ts b/src/util/constants.ts index a427dcf..85c877c 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -21,4 +21,3 @@ export const SPECIAL_KEYS: Record