├── .editorconfig
├── .gitignore
├── README.md
├── angular.json
├── e2e
├── protractor.conf.js
├── src
│ ├── app.e2e-spec.ts
│ └── app.po.ts
└── tsconfig.e2e.json
├── ngsw-config.json
├── package.json
├── src
├── app
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── finished-dialog
│ │ ├── finished-dialog.component.html
│ │ └── finished-dialog.component.ts
│ ├── format-time.pipe.ts
│ ├── generator.worker.js
│ └── sudoku
│ │ ├── grid
│ │ ├── grid.component.html
│ │ ├── grid.component.scss
│ │ └── grid.component.ts
│ │ ├── sudoku.component.html
│ │ ├── sudoku.component.scss
│ │ ├── sudoku.component.ts
│ │ └── sudoku.ts
├── assets
│ ├── .gitkeep
│ └── icons
│ │ ├── apple-touch-icon.png
│ │ ├── icon-128x128.png
│ │ ├── icon-144x144.png
│ │ ├── icon-152x152.png
│ │ ├── icon-192x192.png
│ │ ├── icon-384x384.png
│ │ ├── icon-512x512.png
│ │ ├── icon-72x72.png
│ │ └── icon-96x96.png
├── browserslist
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── karma.conf.js
├── main.ts
├── manifest.json
├── polyfills.ts
├── styles.scss
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── tslint.json
├── tsconfig.json
├── tslint.json
├── webpack.config.js
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ngSudoku
2 |
3 | A simple Sudoku app, built with Angular and Angular Material.
4 |
5 | Makes use of `@jlguenego/sudoku-generator` for generating the Sudoku grids.
6 |
7 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.1.1.
8 |
9 | ## Development server
10 |
11 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
12 |
13 | ## Code scaffolding
14 |
15 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
16 |
17 | ## Build
18 |
19 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
20 |
21 | ## Running unit tests
22 |
23 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
24 |
25 | ## Running end-to-end tests
26 |
27 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
28 |
29 | ## Further help
30 |
31 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
32 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "ng-sudoku": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "su",
11 | "schematics": {
12 | "@schematics/angular:component": {
13 | "styleext": "scss"
14 | }
15 | },
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/ng-sudoku",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "src/tsconfig.app.json",
25 | "assets": [
26 | "src/favicon.ico",
27 | "src/assets",
28 | "src/manifest.json"
29 | ],
30 | "styles": [
31 | "src/styles.scss"
32 | ],
33 | "scripts": [
34 | { "input": "dist/generator.worker.js", "lazy": true }
35 | ]
36 | },
37 | "configurations": {
38 | "production": {
39 | "fileReplacements": [
40 | {
41 | "replace": "src/environments/environment.ts",
42 | "with": "src/environments/environment.prod.ts"
43 | }
44 | ],
45 | "optimization": true,
46 | "outputHashing": "all",
47 | "sourceMap": false,
48 | "extractCss": true,
49 | "namedChunks": false,
50 | "aot": true,
51 | "extractLicenses": true,
52 | "vendorChunk": false,
53 | "buildOptimizer": true,
54 | "serviceWorker": true
55 | }
56 | }
57 | },
58 | "serve": {
59 | "builder": "@angular-devkit/build-angular:dev-server",
60 | "options": {
61 | "browserTarget": "ng-sudoku:build",
62 | "disableHostCheck": true,
63 | "host": "0.0.0.0"
64 | },
65 | "configurations": {
66 | "production": {
67 | "browserTarget": "ng-sudoku:build:production"
68 | }
69 | }
70 | },
71 | "extract-i18n": {
72 | "builder": "@angular-devkit/build-angular:extract-i18n",
73 | "options": {
74 | "browserTarget": "ng-sudoku:build"
75 | }
76 | },
77 | "test": {
78 | "builder": "@angular-devkit/build-angular:karma",
79 | "options": {
80 | "main": "src/test.ts",
81 | "polyfills": "src/polyfills.ts",
82 | "tsConfig": "src/tsconfig.spec.json",
83 | "karmaConfig": "src/karma.conf.js",
84 | "styles": [
85 | "src/styles.scss"
86 | ],
87 | "scripts": [],
88 | "assets": [
89 | "src/favicon.ico",
90 | "src/assets",
91 | "src/manifest.json"
92 | ]
93 | }
94 | },
95 | "lint": {
96 | "builder": "@angular-devkit/build-angular:tslint",
97 | "options": {
98 | "tsConfig": [
99 | "src/tsconfig.app.json",
100 | "src/tsconfig.spec.json"
101 | ],
102 | "exclude": [
103 | "**/node_modules/**"
104 | ]
105 | }
106 | }
107 | }
108 | },
109 | "ng-sudoku-e2e": {
110 | "root": "e2e/",
111 | "projectType": "application",
112 | "architect": {
113 | "e2e": {
114 | "builder": "@angular-devkit/build-angular:protractor",
115 | "options": {
116 | "protractorConfig": "e2e/protractor.conf.js",
117 | "devServerTarget": "ng-sudoku:serve"
118 | },
119 | "configurations": {
120 | "production": {
121 | "devServerTarget": "ng-sudoku:serve:production"
122 | }
123 | }
124 | },
125 | "lint": {
126 | "builder": "@angular-devkit/build-angular:tslint",
127 | "options": {
128 | "tsConfig": "e2e/tsconfig.e2e.json",
129 | "exclude": [
130 | "**/node_modules/**"
131 | ]
132 | }
133 | }
134 | }
135 | },
136 | "sudoku-generator": {
137 | "root": "",
138 | "projectType": "library",
139 | "architect": {
140 | "build": {
141 | "builder": "@angular-devkit/build-webpack:webpack",
142 | "options": {
143 | "webpackConfig": "webpack.config.js"
144 | }
145 | }
146 | }
147 | }
148 | },
149 | "defaultProject": "ng-sudoku"
150 | }
151 |
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to ng-sudoku!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('su-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/ngsw-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "index": "/index.html",
3 | "assetGroups": [{
4 | "name": "app",
5 | "installMode": "prefetch",
6 | "resources": {
7 | "files": [
8 | "/favicon.ico",
9 | "/index.html",
10 | "/*.css",
11 | "/*.js"
12 | ]
13 | }
14 | }, {
15 | "name": "assets",
16 | "installMode": "lazy",
17 | "updateMode": "prefetch",
18 | "resources": {
19 | "files": [
20 | "/assets/**"
21 | ]
22 | }
23 | }]
24 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ng-sudoku",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng run sudoku-generator:build && ng serve",
7 | "build": "ng run sudoku-generator:build && ng build",
8 | "build:pages": "ng run sudoku-generator:build && ng build --prod --base-href 'https://dirkluijk.github.io/ng-sudoku/'",
9 | "test": "ng test",
10 | "lint": "ng lint",
11 | "e2e": "ng e2e"
12 | },
13 | "private": true,
14 | "dependencies": {
15 | "@angular-devkit/build-webpack": "^0.7.3",
16 | "@angular/animations": "^6.1.2",
17 | "@angular/cdk": "^6.4.3",
18 | "@angular/common": "^6.1.0",
19 | "@angular/compiler": "^6.1.0",
20 | "@angular/core": "^6.1.0",
21 | "@angular/forms": "^6.1.0",
22 | "@angular/http": "^6.1.0",
23 | "@angular/material": "^6.4.3",
24 | "@angular/platform-browser": "^6.1.0",
25 | "@angular/platform-browser-dynamic": "^6.1.0",
26 | "@angular/pwa": "0.6.8",
27 | "@angular/router": "^6.1.0",
28 | "@angular/service-worker": "6.0.*",
29 | "@jlguenego/sudoku-generator": "^1.0.7",
30 | "core-js": "^2.5.4",
31 | "rxjs": "^6.0.0",
32 | "zone.js": "~0.8.26"
33 | },
34 | "devDependencies": {
35 | "@angular-devkit/build-angular": "~0.7.0",
36 | "@angular/cli": "~6.1.1",
37 | "@angular/compiler-cli": "^6.1.0",
38 | "@angular/language-service": "^6.1.0",
39 | "@types/jasmine": "~2.8.6",
40 | "@types/jasminewd2": "~2.0.3",
41 | "@types/node": "~8.9.4",
42 | "codelyzer": "~4.2.1",
43 | "jasmine-core": "~2.99.1",
44 | "jasmine-spec-reporter": "~4.2.1",
45 | "karma": "~1.7.1",
46 | "karma-chrome-launcher": "~2.2.0",
47 | "karma-coverage-istanbul-reporter": "~2.0.0",
48 | "karma-jasmine": "~1.1.1",
49 | "karma-jasmine-html-reporter": "^0.2.2",
50 | "protractor": "~5.3.0",
51 | "ts-node": "~5.0.1",
52 | "tslint": "~5.9.1",
53 | "typescript": "~2.7.2"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ngSudoku
8 |
9 |
10 |
11 |
12 | Easy
13 | Moderate
14 | Hard
15 | Expert
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
Generating a new game for you...
24 |
25 |
26 |
27 |
28 |
29 | {{ elapsedTime | formatTime }}
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 | mat-toolbar {
2 | position: sticky;
3 | top: 0;
4 | z-index: 2;
5 | box-shadow: 0 3px 5px -1px rgba(0,0,0,.2), 0 6px 10px 0 rgba(0,0,0,.14), 0 1px 18px 0 rgba(0,0,0,.12);
6 | margin-bottom: 16px;
7 |
8 | .left, .center, .right {
9 | display: flex;
10 | flex: 1;
11 | }
12 |
13 | .left {
14 | justify-content: flex-start;
15 | }
16 |
17 | .center {
18 | justify-content: center;
19 | }
20 |
21 | .right {
22 | justify-content: flex-end;
23 | }
24 |
25 | mat-select {
26 | text-align: right;
27 | font-size: 14px;
28 | }
29 | }
30 |
31 | main {
32 | max-width: 400px;
33 | margin: 0 auto;
34 | padding: 16px;
35 | }
36 |
37 | .spinner-container {
38 | display: flex;
39 | flex-direction: column;
40 | align-items: center;
41 | justify-content: center;
42 |
43 | mat-spinner {
44 | margin-bottom: 32px;
45 | }
46 | }
47 |
48 | .time {
49 | text-align: center;
50 | margin: 16px;
51 | font-weight: bold;
52 | }
53 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Subscription, timer } from 'rxjs';
3 |
4 | import { Sudoku } from './sudoku/sudoku';
5 | import { MatDialog } from '@angular/material';
6 | import { FinishedDialogComponent } from './finished-dialog/finished-dialog.component';
7 |
8 | export type Difficulty = 'easy' | 'moderate' | 'hard' | 'expert';
9 |
10 | @Component({
11 | selector: 'su-root',
12 | templateUrl: './app.component.html',
13 | styleUrls: ['./app.component.scss']
14 | })
15 | export class AppComponent implements OnInit {
16 | sudoku: Sudoku;
17 | elapsedTime: number;
18 | difficulty: Difficulty = 'easy';
19 |
20 | private timerSubscription: Subscription;
21 |
22 | constructor(private dialog: MatDialog) {}
23 |
24 | ngOnInit(): void {
25 | this.generate();
26 | }
27 |
28 | generate(): void {
29 | this.sudoku = undefined;
30 |
31 | const worker = new Worker('generator.worker.js');
32 |
33 | worker.postMessage(this.numberOfEmptyFields);
34 |
35 | worker.onmessage = (event) => {
36 | const { solution, masked } = event.data;
37 |
38 | this.sudoku = solution.map(row => row.map(number => ({answer: number})));
39 |
40 | masked.forEach((row, rowIndex) => {
41 | row.forEach((value, colIndex) => {
42 | this.sudoku[rowIndex][colIndex].value = value === 0 ? undefined : value;
43 | this.sudoku[rowIndex][colIndex].readonly = value !== 0;
44 | });
45 | });
46 |
47 | this.startTimer();
48 |
49 | worker.terminate();
50 | };
51 | }
52 |
53 | onGameFinished() {
54 | this.dialog
55 | .open(FinishedDialogComponent, {data: {time: this.elapsedTime}})
56 | .afterClosed()
57 | .subscribe(() => this.generate());
58 | }
59 |
60 | private get numberOfEmptyFields(): number {
61 | switch (this.difficulty) {
62 | case 'easy':
63 | return 35;
64 | case 'moderate':
65 | return 45;
66 | case 'hard':
67 | return 52;
68 | case 'expert':
69 | return 58;
70 | }
71 | }
72 |
73 | private startTimer(): void {
74 | if (this.timerSubscription) {
75 | this.timerSubscription.unsubscribe();
76 | }
77 |
78 | this.timerSubscription = timer(0, 1000).subscribe(time => this.elapsedTime = time);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3 | import { FormsModule } from '@angular/forms';
4 | import { ServiceWorkerModule } from '@angular/service-worker';
5 | import {
6 | MatButtonModule,
7 | MatCardModule,
8 | MatDialogModule,
9 | MatIconModule,
10 | MatProgressSpinnerModule,
11 | MatSelectModule,
12 | MatToolbarModule
13 | } from '@angular/material';
14 |
15 | import { environment } from '../environments/environment';
16 |
17 | import { AppComponent } from './app.component';
18 | import { SudokuComponent } from './sudoku/sudoku.component';
19 | import { FormatTimePipe } from './format-time.pipe';
20 | import { GridComponent } from './sudoku/grid/grid.component';
21 | import { FinishedDialogComponent } from './finished-dialog/finished-dialog.component';
22 |
23 | @NgModule({
24 | declarations: [
25 | AppComponent,
26 | SudokuComponent,
27 | FormatTimePipe,
28 | GridComponent,
29 | FinishedDialogComponent,
30 | ],
31 | imports: [
32 | BrowserAnimationsModule,
33 | MatToolbarModule,
34 | MatButtonModule,
35 | MatSelectModule,
36 | MatIconModule,
37 | MatDialogModule,
38 | MatCardModule,
39 | MatProgressSpinnerModule,
40 | FormsModule,
41 | ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production })
42 | ],
43 | providers: [],
44 | entryComponents: [FinishedDialogComponent],
45 | bootstrap: [AppComponent]
46 | })
47 | export class AppModule { }
48 |
--------------------------------------------------------------------------------
/src/app/finished-dialog/finished-dialog.component.html:
--------------------------------------------------------------------------------
1 | Well done!
2 |
3 |
4 | You finished the game in {{ time | formatTime }} minutes.
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/app/finished-dialog/finished-dialog.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Inject } from '@angular/core';
2 | import { MAT_DIALOG_DATA } from '@angular/material';
3 |
4 | @Component({
5 | selector: 'su-finished-dialog',
6 | templateUrl: './finished-dialog.component.html'
7 | })
8 | export class FinishedDialogComponent {
9 | time: number;
10 |
11 | constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
12 | this.time = data.time;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/app/format-time.pipe.ts:
--------------------------------------------------------------------------------
1 | import { Pipe, PipeTransform } from '@angular/core';
2 |
3 | @Pipe({
4 | name: 'formatTime'
5 | })
6 | export class FormatTimePipe implements PipeTransform {
7 |
8 | transform(value: number): string {
9 | const seconds = value % 60;
10 | const minutes = Math.floor(value / 60);
11 |
12 | return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/app/generator.worker.js:
--------------------------------------------------------------------------------
1 | import { SudokuSolver } from '@jlguenego/sudoku-generator';
2 |
3 | onmessage = function(e) {
4 | const solution = SudokuSolver.generate();
5 | const masked = SudokuSolver.carve(solution, e.data);
6 |
7 | postMessage({
8 | solution: solution,
9 | masked: masked
10 | });
11 | };
12 |
--------------------------------------------------------------------------------
/src/app/sudoku/grid/grid.component.html:
--------------------------------------------------------------------------------
1 |
2 |
14 |
{{ field.value }}
15 |
0">
16 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/app/sudoku/grid/grid.component.scss:
--------------------------------------------------------------------------------
1 | $border-color: #3f51b5;
2 | $active-color: #b7c4ff;
3 | $highlight-row-color: #e8e8e8;
4 | $highlight-col-color: #e8e8e8;
5 | $highlight-same-color: #cacaca;
6 | $text-color: #3f51b5;
7 | $text-color--readonly: #000;
8 |
9 | :host {
10 | background: $border-color;
11 | border: 1px solid $border-color;
12 | display: grid;
13 | grid-template-columns: repeat(9, 1fr);
14 | grid-column-gap: 1px;
15 | grid-row-gap: 1px;
16 | color: $text-color;
17 | }
18 |
19 | .cell {
20 | background: white;
21 | position: relative;
22 | cursor: pointer;
23 |
24 | &.readonly {
25 | color: $text-color--readonly;
26 | }
27 |
28 | &.highlight-row {
29 | background: $highlight-row-color;
30 | }
31 |
32 | &.highlight-col {
33 | background: $highlight-col-color;
34 | }
35 |
36 | &.highlight-same {
37 | background: $highlight-same-color;
38 | }
39 |
40 | &.active {
41 | background: $active-color;
42 | }
43 |
44 | &:after {
45 | content: '';
46 | display: block;
47 | padding-top: 100%;
48 | width: 100%;
49 | }
50 |
51 | &.top {
52 | border-top: 1px solid $border-color;
53 | }
54 |
55 | &.bottom {
56 | border-bottom: 1px solid $border-color;
57 | }
58 |
59 | &.left {
60 | border-left: 1px solid $border-color;
61 | }
62 |
63 | &.right {
64 | border-right: 1px solid $border-color;
65 | }
66 |
67 | .value {
68 | position: absolute;
69 | top: 0;
70 | bottom: 0;
71 | left: 0;
72 | right: 0;
73 | width: 100%;
74 | font-size: 20px;
75 | cursor: pointer;
76 | display: flex;
77 | justify-content: center;
78 | align-items: center;
79 | }
80 |
81 | .note {
82 | position: absolute;
83 | top: 0;
84 | bottom: 0;
85 | left: 0;
86 | right: 0;
87 | font-size: 10px;
88 | padding: 0 2px;
89 | display: flex;
90 | line-height: normal;
91 | }
92 |
93 | .note-1,
94 | .note-2,
95 | .note-3 {
96 | align-items: flex-start;
97 | }
98 |
99 | .note-4,
100 | .note-5,
101 | .note-6 {
102 | align-items: center;
103 | }
104 |
105 | .note-7,
106 | .note-8,
107 | .note-9 {
108 | align-items: flex-end;
109 | }
110 |
111 | .note-1,
112 | .note-4,
113 | .note-7 {
114 | justify-content: flex-start;
115 | }
116 |
117 | .note-2,
118 | .note-5,
119 | .note-8 {
120 | justify-content: center;
121 | }
122 |
123 | .note-3,
124 | .note-6,
125 | .note-9 {
126 | justify-content: flex-end;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/app/sudoku/grid/grid.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output } from '@angular/core';
2 | import { Sudoku, SudokuField } from '../sudoku';
3 |
4 | @Component({
5 | selector: 'su-grid',
6 | templateUrl: './grid.component.html',
7 | styleUrls: ['./grid.component.scss']
8 | })
9 | export class GridComponent {
10 | @Input() sudoku: Sudoku;
11 | @Input() activeField?: SudokuField;
12 |
13 | @Output() activeFieldChange = new EventEmitter();
14 |
15 | onFieldClick(field: SudokuField): void {
16 | this.activeField = this.activeField === field ? undefined : field;
17 | this.activeFieldChange.emit(this.activeField);
18 | }
19 |
20 | get currentRow(): number {
21 | return this.sudoku.findIndex(row => row.indexOf(this.activeField) !== -1);
22 | }
23 |
24 | get currentCol(): number {
25 | if (!this.activeField || this.currentRow === -1) {
26 | return -1;
27 | }
28 |
29 | return this.sudoku[this.currentRow].indexOf(this.activeField);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/sudoku/sudoku.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
12 |
16 |
17 |
18 |
19 |
25 |
26 |
--------------------------------------------------------------------------------
/src/app/sudoku/sudoku.component.scss:
--------------------------------------------------------------------------------
1 | .options {
2 | display: flex;
3 | margin: 8px -8px;
4 |
5 | button {
6 | flex: 1;
7 | margin: 8px;
8 |
9 | &.active {
10 | background: #83c8ef;
11 | }
12 | }
13 | }
14 |
15 | .controls {
16 | display: flex;
17 |
18 | button {
19 | flex: 1;
20 | min-width: 0;
21 | text-align: center;
22 | font-size: x-large;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/app/sudoku/sudoku.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
2 | import { Sudoku, SudokuField } from './sudoku';
3 |
4 | const between = (newValue: number, min: number, max: number) => {
5 | return Math.min(Math.max(newValue, min), max);
6 | };
7 |
8 | interface NumberButton {
9 | number: number;
10 | disabled?: boolean;
11 | }
12 |
13 | @Component({
14 | selector: 'su-sudoku',
15 | templateUrl: './sudoku.component.html',
16 | styleUrls: ['./sudoku.component.scss']
17 | })
18 | export class SudokuComponent implements OnChanges {
19 | @Input() sudoku: Sudoku;
20 | @Output() finish = new EventEmitter();
21 |
22 | noteMode = false;
23 | activeField?: SudokuField;
24 |
25 | numberButtons: NumberButton[] = [
26 | {number: 1},
27 | {number: 2},
28 | {number: 3},
29 | {number: 4},
30 | {number: 5},
31 | {number: 6},
32 | {number: 7},
33 | {number: 8},
34 | {number: 9}
35 | ];
36 |
37 | ngOnChanges(changes: SimpleChanges): void {
38 | if (changes.soduku) {
39 | this.activeField = undefined;
40 | this.checkNumbers();
41 | }
42 | }
43 |
44 | @HostListener('window:keydown.space') onSpace() {
45 | this.noteMode = !this.noteMode;
46 | }
47 |
48 | @HostListener('window:keydown.arrowUp') onArrowUp(): void {
49 | this.moveFocus(0, -1);
50 | }
51 |
52 | @HostListener('window:keydown.arrowDown') onArrowDown(): void {
53 | this.moveFocus(0, 1);
54 | }
55 |
56 | @HostListener('window:keydown.arrowLeft') onArrowLeft(): void {
57 | this.moveFocus(-1, 0);
58 | }
59 |
60 | @HostListener('window:keydown.arrowRight') onArrowRight(): void {
61 | this.moveFocus(1, 0);
62 | }
63 |
64 | @HostListener('window:keydown.backspace') onBackspace(): void {
65 | this.erase();
66 | }
67 |
68 | @HostListener('window:keydown', ['$event'])
69 | onKeyDown(event: KeyboardEvent) {
70 | const number = parseInt(event.key, 10);
71 |
72 | if (!this.activeField || isNaN(number) || number < 1 || number > 9) {
73 | return;
74 | }
75 |
76 | this.insertNumber(number);
77 | }
78 |
79 | erase() {
80 | if (this.activeField && !this.activeField.readonly) {
81 | this.activeField.notes = [];
82 | this.activeField.value = undefined;
83 | }
84 | }
85 |
86 | hint() {
87 | if (this.activeField && !this.activeField.readonly) {
88 | this.activeField.value = this.activeField.answer;
89 |
90 | this.cleanNotes();
91 | this.checkNumbers();
92 | this.checkFinished();
93 | }
94 | }
95 |
96 | insertNumber(number: number) {
97 | const field = this.activeField;
98 |
99 | if (this.noteMode && !field.value) {
100 | if (!field.notes) {
101 | this.activeField.notes = [];
102 | }
103 | if (!field.notes.find(i => i === number)) {
104 | field.notes = field.notes.concat(number);
105 | } else {
106 | field.notes = field.notes.filter(i => i !== number);
107 | }
108 | } else if (!this.noteMode && !field.readonly) {
109 | field.value = number;
110 |
111 | this.cleanNotes();
112 | this.checkNumbers();
113 | this.checkFinished();
114 | }
115 | }
116 |
117 | get currentRow(): number {
118 | return this.sudoku.findIndex(row => row.indexOf(this.activeField) !== -1);
119 | }
120 |
121 | get currentCol(): number {
122 | if (!this.activeField || this.currentRow === -1) {
123 | return -1;
124 | }
125 |
126 | return this.sudoku[this.currentRow].indexOf(this.activeField);
127 | }
128 |
129 | private moveFocus(relativeCol = 0, relativeRow = 0): void {
130 | if (!this.activeField) {
131 | return;
132 | }
133 |
134 | const newRow = between(this.currentRow + relativeRow, 0, 8);
135 | const newCol = between(this.currentCol + relativeCol, 0, 8);
136 |
137 | this.activeField = this.sudoku[newRow][newCol];
138 | }
139 |
140 | private cleanNotes(): void {
141 | const removeNote = (field: SudokuField) => {
142 | field.notes = field.notes ? field.notes.filter(n => n !== this.activeField.value) : [];
143 | };
144 |
145 | this.sudoku[this.currentRow].forEach(field => removeNote(field));
146 | this.sudoku.forEach(row => removeNote(row[this.currentCol]));
147 |
148 | // also within square...
149 | const firstCol = this.currentCol - this.currentCol % 3;
150 | const firstRow = this.currentRow - this.currentRow % 3;
151 |
152 | [0, 1, 2].forEach(rowOffset => {
153 | [0, 1, 2].forEach(colOffset => {
154 | removeNote(this.sudoku[firstRow + rowOffset][firstCol + colOffset]);
155 | });
156 | });
157 | }
158 |
159 | private checkNumbers(): void {
160 | const countNumber = i => this.sudoku.reduce((sum, row) => sum + row.filter(f => f.value === i).length, 0);
161 |
162 | this.numberButtons.forEach(button => {
163 | button.disabled = countNumber(button.number) >= 9;
164 | });
165 | }
166 |
167 | private checkFinished(): void {
168 | if (this.finished) {
169 | this.finish.emit();
170 | }
171 | }
172 |
173 | private get finished(): boolean {
174 | return this.sudoku.every(row => row.every(field => field.value === field.answer));
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/src/app/sudoku/sudoku.ts:
--------------------------------------------------------------------------------
1 | export type Sudoku = SudokuField[][];
2 |
3 | export interface SudokuField {
4 | value?: number;
5 | notes?: number[];
6 | answer: number;
7 | readonly?: boolean;
8 | }
9 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/icons/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/apple-touch-icon.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-128x128.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-144x144.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-152x152.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-192x192.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-384x384.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-384x384.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-512x512.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-72x72.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/assets/icons/icon-96x96.png
--------------------------------------------------------------------------------
/src/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed
5 | > 0.5%
6 | last 2 versions
7 | Firefox ESR
8 | not dead
9 | # IE 9-11
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * In development mode, to ignore zone related error stack frames such as
11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
12 | * import the following file, but please comment it out in production mode
13 | * because it will have performance impact when throw error
14 | */
15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
16 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dirkluijk/ng-sudoku/0b4e8702ba19e81ca6685273f88340de44859eb1/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ngSudoku
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage'),
20 | reports: ['html', 'lcovonly'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .then(() => {
13 | if ('serviceWorker' in navigator && environment.production) {
14 | navigator.serviceWorker.register('./ngsw-worker.js');
15 | }
16 | })
17 | .catch(err => console.log(err));
18 |
--------------------------------------------------------------------------------
/src/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngSudoku",
3 | "short_name": "ngSudoku",
4 | "theme_color": "#3f51b5",
5 | "background_color": "#fafafa",
6 | "display": "standalone",
7 | "start_url": "index.html",
8 | "icons": [
9 | {
10 | "src": "assets/icons/icon-72x72.png",
11 | "sizes": "72x72",
12 | "type": "image/png"
13 | },
14 | {
15 | "src": "assets/icons/icon-96x96.png",
16 | "sizes": "96x96",
17 | "type": "image/png"
18 | },
19 | {
20 | "src": "assets/icons/icon-128x128.png",
21 | "sizes": "128x128",
22 | "type": "image/png"
23 | },
24 | {
25 | "src": "assets/icons/icon-144x144.png",
26 | "sizes": "144x144",
27 | "type": "image/png"
28 | },
29 | {
30 | "src": "assets/icons/icon-152x152.png",
31 | "sizes": "152x152",
32 | "type": "image/png"
33 | },
34 | {
35 | "src": "assets/icons/icon-192x192.png",
36 | "sizes": "192x192",
37 | "type": "image/png"
38 | },
39 | {
40 | "src": "assets/icons/icon-384x384.png",
41 | "sizes": "384x384",
42 | "type": "image/png"
43 | },
44 | {
45 | "src": "assets/icons/icon-512x512.png",
46 | "sizes": "512x512",
47 | "type": "image/png"
48 | }
49 | ]
50 | }
51 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Web Animations `@angular/platform-browser/animations`
51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
53 | **/
54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
55 |
56 | /**
57 | * By default, zone.js will patch all possible macroTask and DomEvents
58 | * user can disable parts of macroTask/DomEvents patch by setting following flags
59 | */
60 |
61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
64 |
65 | /*
66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
68 | */
69 | // (window as any).__Zone_enable_cross_context_check = true;
70 |
71 | /***************************************************************************************************
72 | * Zone JS is required by default for Angular itself.
73 | */
74 | import 'zone.js/dist/zone'; // Included with Angular CLI.
75 |
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | @import "~@angular/material/prebuilt-themes/indigo-pink.css";
3 |
4 | body {
5 | padding: 0;
6 | margin: 0;
7 | font-family: Roboto,"Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
8 | color: #3f51b5;
9 | }
10 |
11 | button {
12 | outline: none;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": []
6 | },
7 | "exclude": [
8 | "src/test.ts",
9 | "**/*.spec.ts"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "test.ts",
12 | "polyfills.ts"
13 | ],
14 | "include": [
15 | "**/*.spec.ts",
16 | "**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "su",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "su",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "module": "es2015",
9 | "moduleResolution": "node",
10 | "emitDecoratorMetadata": true,
11 | "experimentalDecorators": true,
12 | "target": "es5",
13 | "typeRoots": [
14 | "node_modules/@types"
15 | ],
16 | "lib": [
17 | "es2017",
18 | "dom"
19 | ]
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-shadowed-variable": true,
69 | "no-string-literal": false,
70 | "no-string-throw": true,
71 | "no-switch-case-fall-through": true,
72 | "no-trailing-whitespace": true,
73 | "no-unnecessary-initializer": true,
74 | "no-unused-expression": true,
75 | "no-use-before-declare": true,
76 | "no-var-keyword": true,
77 | "object-literal-sort-keys": false,
78 | "one-line": [
79 | true,
80 | "check-open-brace",
81 | "check-catch",
82 | "check-else",
83 | "check-whitespace"
84 | ],
85 | "prefer-const": true,
86 | "quotemark": [
87 | true,
88 | "single"
89 | ],
90 | "radix": true,
91 | "semicolon": [
92 | true,
93 | "always"
94 | ],
95 | "triple-equals": [
96 | true,
97 | "allow-null-check"
98 | ],
99 | "typedef-whitespace": [
100 | true,
101 | {
102 | "call-signature": "nospace",
103 | "index-signature": "nospace",
104 | "parameter": "nospace",
105 | "property-declaration": "nospace",
106 | "variable-declaration": "nospace"
107 | }
108 | ],
109 | "unified-signatures": true,
110 | "variable-name": false,
111 | "whitespace": [
112 | true,
113 | "check-branch",
114 | "check-decl",
115 | "check-operator",
116 | "check-separator",
117 | "check-type"
118 | ],
119 | "no-output-on-prefix": true,
120 | "use-input-property-decorator": true,
121 | "use-output-property-decorator": true,
122 | "use-host-property-decorator": true,
123 | "no-input-rename": true,
124 | "no-output-rename": true,
125 | "use-life-cycle-interface": true,
126 | "use-pipe-transform-interface": true,
127 | "component-class-suffix": true,
128 | "directive-class-suffix": true
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | const config = {
4 | entry: './src/app/generator.worker.js',
5 | mode: 'production',
6 | output: {
7 | path: path.resolve(__dirname, 'dist'),
8 | filename: 'generator.worker.js'
9 | }
10 | };
11 |
12 | module.exports = config;
13 |
--------------------------------------------------------------------------------