commit a78c2ce1c73c3d1a1d15d603636461a33da0480b Author: clfreville2 Date: Tue Oct 31 18:31:52 2023 +0100 Initial commit diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..fc3f00e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,10 @@ +kind: pipeline +name: default +type: docker + +steps: + - name: build + image: node:20-alpine + commands: + - yarn install + - yarn build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96d4dde --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# Locks +package-lock.json +yarn.lock +pnpm-lock.yaml diff --git a/index.html b/index.html new file mode 100644 index 0000000..472e05f --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + Digicode + + + +
+
+
+
+
+
+
+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..1fceae1 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "digicode", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "devDependencies": { + "typescript": "^5.0.2", + "vite": "^4.4.5" + } +} diff --git a/src/digicode.ts b/src/digicode.ts new file mode 100644 index 0000000..0669a74 --- /dev/null +++ b/src/digicode.ts @@ -0,0 +1,34 @@ +import './style.css' + +const code = '1234'; + +const display = document.getElementById('display') as HTMLDivElement; +const light = document.getElementById('light') as HTMLDivElement; +const keypad = document.getElementById('keypad') as HTMLDivElement; + +function resetCode() { + display.innerText = ''; + light.classList.remove('is-success', 'is-error'); +} + +function composeDigit(digit: number) { + const output = display.innerText + digit.toString(); + display.innerText = output; + if (!code.startsWith(output)) { + light.classList.add('is-error'); + setTimeout(resetCode, 1000) + return; + } + if (code === output) { + light.classList.add('is-success'); + return; + } +} + +for (let i = 1; i < 11; i++) { + const digit = i % 10; + const button = document.createElement('button'); + button.innerText = digit.toString(); + button.onclick = () => composeDigit(digit); + keypad.appendChild(button); +} diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..e709dcb --- /dev/null +++ b/src/style.css @@ -0,0 +1,96 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button, #light { + background-color: #f9f9f9; + } +} + +#output { + display: flex; +} +#display { + flex-grow: 1; +} + +#light { + width: 24px; + height: 24px; + border-radius: 50%; + background-color: #1a1a1a; +} +#light.is-error { + background-color: #fd3838; +} +#light.is-success { + background-color: #46fd46; +} + +#keypad { + display: grid; + grid-template-columns: repeat(3, 1fr); +} + +#keypad > button:last-child { + grid-column: 2; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +}