ngx-touch-keyboard 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 ADDED
@@ -0,0 +1,86 @@
1
+ # AngularTouchKeyboard
2
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
3
+ [![npm version](https://badge.fury.io/js/ngx-touch-keyboard.svg)](http://badge.fury.io/js/ngx-touch-keyboard)
4
+
5
+ ## What is this?
6
+ Virtual Keyboard for Angular applications.
7
+
8
+ <img src="src/assets/images/angularTouchKeyboard.png" alt="angular touch keyboard"/>
9
+
10
+ ## Demo
11
+ https://mohsen77sk.github.io/angular-touch-keyboard/
12
+
13
+ ## Install
14
+
15
+ ### Step 1: Install ngx-touch-keyboard
16
+ ```sh
17
+ $ npm install ngx-touch-keyboard
18
+ ```
19
+
20
+ ### Step 2: Import the module
21
+ Add `ngxTouchKeyboardModule` as an import in your app's root NgModule.
22
+ ```typescript
23
+ import { ngxTouchKeyboardModule } from 'ngx-touch-keyboard';
24
+ @NgModule({
25
+ ...
26
+ imports: [
27
+ ...
28
+ ngxTouchKeyboardModule,
29
+ ],
30
+ ...
31
+ })
32
+ export class AppModule { }
33
+ ```
34
+
35
+ ## Usage
36
+ Simple usage example
37
+ ```html
38
+ <input
39
+ type="text"
40
+ ngxTouchKeyboard
41
+ #touchKeyboard="ngxTouchKeyboard"
42
+ (focus)="touchKeyboard.openPanel()"
43
+ />
44
+ ```
45
+ Material usage example
46
+ ```html
47
+ <mat-form-field>
48
+ <mat-label>Default</mat-label>
49
+ <input
50
+ matInput
51
+ type="text"
52
+ ngxTouchKeyboard
53
+ #touchKeyboard="ngxTouchKeyboard"
54
+ />
55
+ <button
56
+ mat-icon-button
57
+ matSuffix
58
+ type="button"
59
+ (click)="touchKeyboard.togglePanel()"
60
+ >
61
+ <mat-icon> keyboard </mat-icon>
62
+ </button>
63
+ </mat-form-field>
64
+ ```
65
+ ### Methods
66
+
67
+ | Methods | Description |
68
+ | --- | --- |
69
+ | `openPanel` | Open keyboard panel |
70
+ | `closePanel` | Close keyboard panel |
71
+ | `togglePanel` | Toggle keyboard panel |
72
+
73
+ ### Layouts
74
+
75
+ | inputmode | screenshot |
76
+ | --- | --- |
77
+ | `inputmode='text'` | <img src="src/assets/images/text.png" alt="angular touch keyboard" width="260"/> |
78
+ | `inputmode='search'` | <img src="src/assets/images/search.png" alt="angular touch keyboard" width="260"/> |
79
+ | `inputmode='email'` | <img src="src/assets/images/email.png" alt="angular touch keyboard" width="260"/> |
80
+ | `inputmode='url'` | <img src="src/assets/images/url.png" alt="angular touch keyboard" width="260"/> |
81
+ | `inputmode='numeric'` | <img src="src/assets/images/number.png" alt="angular touch keyboard" width="260"/> |
82
+ | `inputmode='decimal'` | <img src="src/assets/images/decimal.png" alt="angular touch keyboard" width="260"/> |
83
+ | `inputmode='tel'` | <img src="src/assets/images/tel.png" alt="angular touch keyboard" width="260"/> |
84
+
85
+ ## License
86
+ [The MIT License (MIT)](LICENSE)
package/karma.conf.js ADDED
@@ -0,0 +1,44 @@
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'),
13
+ require('@angular-devkit/build-angular/plugins/karma')
14
+ ],
15
+ client: {
16
+ jasmine: {
17
+ // you can add configuration options for Jasmine here
18
+ // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+ // for example, you can disable the random execution with `random: false`
20
+ // or set a specific seed with `seed: 4321`
21
+ },
22
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+ },
24
+ jasmineHtmlReporter: {
25
+ suppressAll: true // removes the duplicated traces
26
+ },
27
+ coverageReporter: {
28
+ dir: require('path').join(__dirname, '../../coverage/ngx-touch-keyboard'),
29
+ subdir: '.',
30
+ reporters: [
31
+ { type: 'html' },
32
+ { type: 'text-summary' }
33
+ ]
34
+ },
35
+ reporters: ['progress', 'kjhtml'],
36
+ port: 9876,
37
+ colors: true,
38
+ logLevel: config.LOG_INFO,
39
+ autoWatch: true,
40
+ browsers: ['Chrome'],
41
+ singleRun: false,
42
+ restartOnFileChange: true
43
+ });
44
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/ngx-touch-keyboard",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "ngx-touch-keyboard",
3
+ "version": "2.0.0",
4
+ "description": "Virtual Keyboard for Angular applications",
5
+ "peerDependencies": {
6
+ "@angular/common": ">=10.0.0",
7
+ "@angular/core": ">=10.0.0",
8
+ "@angular/cdk": ">=10.0.0"
9
+ },
10
+ "dependencies": {
11
+ "tslib": "^2.3.0"
12
+ },
13
+ "private": false,
14
+ "keywords": [
15
+ "Angular",
16
+ "Material",
17
+ "Touch",
18
+ "Virtual",
19
+ "Keyboard",
20
+ "onscreen"
21
+ ],
22
+ "author": {
23
+ "name": "Mohsen Sohrabi",
24
+ "url": "https://github.com/mohsen77sk"
25
+ },
26
+ "homepage": "https://github.com/mohsen77sk/angular-touch-keyboard#readme",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/mohsen77sk/angular-touch-keyboard.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/mohsen77sk/angular-touch-keyboard/issues"
33
+ },
34
+ "license": "MIT"
35
+ }
@@ -0,0 +1,132 @@
1
+ import { KeyboardLayout, KeyboardDisplay } from './layouts.type';
2
+
3
+ export const getDefaultLayout = (): KeyboardLayout => {
4
+ return {
5
+ text_default: [
6
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
7
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
8
+ ['{shift}', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '{backspace}'],
9
+ ['{numbers}', '{space}', '{ent}'],
10
+ ],
11
+ text_shift: [
12
+ ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
13
+ ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
14
+ ['{shift}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '{backspace}'],
15
+ ['{numbers}', '{space}', '{ent}'],
16
+ ],
17
+ text_numbers: [
18
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
19
+ ['-', '/', ':', ';', '(', ')', '$', '&', '@', '"'],
20
+ ['{extends}', '.', ',', '?', '!', "'", '{backspace}'],
21
+ ['{abc}', '{space}', '{ent}'],
22
+ ],
23
+ text_extends: [
24
+ ['[', ']', '{', '}', '#', '%', '^', '*', '+', '='],
25
+ ['_', '\\', '|', '~', '<', '>', '€', '£', '¥', '•'],
26
+ ['{numbers}', '.', ',', '?', '!', "'", '{backspace}'],
27
+ ['{abc}', '{space}', '{ent}'],
28
+ ],
29
+ search_default: [
30
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
31
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
32
+ ['{shift}', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '{backspace}'],
33
+ ['{numbers}', '{space}', '{ent}'],
34
+ ],
35
+ search_shift: [
36
+ ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
37
+ ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
38
+ ['{shift}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '{backspace}'],
39
+ ['{numbers}', '{space}', '{ent}'],
40
+ ],
41
+ search_numbers: [
42
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
43
+ ['-', '/', ':', ';', '(', ')', '$', '&', '@', '"'],
44
+ ['{extends}', '.', ',', '?', '!', "'", '{backspace}'],
45
+ ['{abc}', '{space}', '{ent}'],
46
+ ],
47
+ search_extends: [
48
+ ['[', ']', '{', '}', '#', '%', '^', '*', '+', '='],
49
+ ['_', '\\', '|', '~', '<', '>', '€', '£', '¥', '•'],
50
+ ['{numbers}', '.', ',', '?', '!', "'", '{backspace}'],
51
+ ['{abc}', '{space}', '{ent}'],
52
+ ],
53
+ email_default: [
54
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
55
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
56
+ ['{shift}', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '{backspace}'],
57
+ ['{numbers}', '@', '{space}', '.', '{ent}'],
58
+ ],
59
+ email_shift: [
60
+ ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
61
+ ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
62
+ ['{shift}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '{backspace}'],
63
+ ['{numbers}', '@', '{space}', '.', '{ent}'],
64
+ ],
65
+ email_numbers: [
66
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
67
+ ['$', '!', '~', '&', '=', '#', '[', ']'],
68
+ ['{extends}', '.', '_', '-', '+', '{backspace}'],
69
+ ['{abc}', '@', '{space}', '.', '{ent}'],
70
+ ],
71
+ email_extends: [
72
+ ['`', '|', '{', '}', '?', '%', '^', '*', '/', "'"],
73
+ ['$', '!', '~', '&', '=', '#', '[', ']'],
74
+ ['{numbers}', '.', '_', '-', '+', '{backspace}'],
75
+ ['{abc}', '@', '{space}', '.', '{ent}'],
76
+ ],
77
+ url_default: [
78
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
79
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
80
+ ['{shift}', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '{backspace}'],
81
+ ['{numbers}', '/', '.com', '.', '{ent}'],
82
+ ],
83
+ url_shift: [
84
+ ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
85
+ ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
86
+ ['{shift}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '{backspace}'],
87
+ ['{numbers}', '/', '.com', '.', '{ent}'],
88
+ ],
89
+ url_numbers: [
90
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
91
+ ['@', '&', '%', '?', ',', '=', '[', ']'],
92
+ ['{extends}', '_', ':', '-', '+', '{backspace}'],
93
+ ['{abc}', '/', '.com', '.', '{ent}'],
94
+ ],
95
+ url_extends: [
96
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
97
+ ['*', '$', '#', '!', "'", '^', '[', ']'],
98
+ ['{numbers}', '~', ';', '(', ')', '{backspace}'],
99
+ ['{abc}', '/', '.com', '.', '{ent}'],
100
+ ],
101
+ numeric_default: [
102
+ ['1', '2', '3'],
103
+ ['4', '5', '6'],
104
+ ['7', '8', '9'],
105
+ ['0', '{backspace}'],
106
+ ],
107
+ decimal_default: [
108
+ ['1', '2', '3'],
109
+ ['4', '5', '6'],
110
+ ['7', '8', '9'],
111
+ ['.', '0', '{backspace}'],
112
+ ],
113
+ tel_default: [
114
+ ['1', '2', '3', '*'],
115
+ ['4', '5', '6', '#'],
116
+ ['7', '8', '9', '+'],
117
+ ['0', '{backspace}'],
118
+ ],
119
+ };
120
+ };
121
+
122
+ export const getDefaultDisplay = (): KeyboardDisplay => {
123
+ return {
124
+ '{shift}': '⇧',
125
+ '{backspace}': '⌫',
126
+ '{abc}': 'ABC',
127
+ '{numbers}': '123',
128
+ '{extends}': '#+=',
129
+ '{ent}': 'return',
130
+ '{space}': ' ',
131
+ };
132
+ };
@@ -0,0 +1,7 @@
1
+ export interface KeyboardLayout {
2
+ [key: string]: Array<Array<string>>;
3
+ }
4
+
5
+ export interface KeyboardDisplay {
6
+ [key: string]: string;
7
+ }
@@ -0,0 +1,26 @@
1
+ <div dir="ltr" class="touch-keyboard" [ngClass]="'layout-' + layoutName">
2
+ <ng-container
3
+ *ngFor="
4
+ let row of layout[layoutMode + '_' + layoutName];
5
+ let rowIndex = index
6
+ "
7
+ >
8
+ <div class="touch-keyboard-row">
9
+ <ng-container *ngFor="let key of row; let keyIndex = index">
10
+ <button
11
+ [name]="key"
12
+ class="touch-keyboard-key"
13
+ [ngClass]="[getButtonClass(key)]"
14
+ [attr.data-layout]="layoutName"
15
+ (pointerdown)="
16
+ handleButtonClicked(key, $event); handleButtonMouseDown(key, $event)
17
+ "
18
+ (pointerup)="handleButtonMouseUp(key, $event)"
19
+ (pointercancel)="handleButtonMouseUp(key, $event)"
20
+ >
21
+ {{ getButtonDisplayName(key) }}
22
+ </button>
23
+ </ng-container>
24
+ </div>
25
+ </ng-container>
26
+ </div>
@@ -0,0 +1,103 @@
1
+ :root {
2
+ --touch-keyboard-text: #27272a;
3
+ --touch-keyboard-background: rgba(238, 238, 238, 0.87);
4
+ --touch-keyboard-button: rgba(255, 255, 255, 0.96);
5
+ --touch-keyboard-button-fn: rgba(255, 255, 255, 0.5);
6
+ --touch-keyboard-button-active: rgba(0, 0, 0, 0.04);
7
+ }
8
+
9
+ .dark {
10
+ --touch-keyboard-text: #ffffff;
11
+ --touch-keyboard-background: rgba(33, 33, 33, 0.87);
12
+ --touch-keyboard-button: rgba(66, 66, 66, 0.96);
13
+ --touch-keyboard-button-fn: rgba(66, 66, 66, 0.5);
14
+ --touch-keyboard-button-active: rgba(255, 255, 255, 0.2);
15
+ }
16
+
17
+ ngx-touch-keyboard {
18
+ width: 100%;
19
+ padding: 0.25rem;
20
+ padding-bottom: 0.375rem;
21
+ border-radius: 0.375rem;
22
+ touch-action: manipulation;
23
+ -webkit-user-select: none;
24
+ -moz-user-select: none;
25
+ -ms-user-select: none;
26
+ user-select: none;
27
+ display: flex;
28
+ justify-content: center;
29
+ backdrop-filter: blur(8px);
30
+ background-color: var(--touch-keyboard-background);
31
+ box-shadow: 0px 3px 1px -2px rgb(0 0 0 / 20%),
32
+ 0px 2px 2px 0px rgb(0 0 0 / 14%), 0px 1px 5px 0px rgb(0 0 0 / 12%);
33
+ }
34
+
35
+ .touch-keyboard {
36
+ flex: 1 1 auto;
37
+ max-width: 860px;
38
+
39
+ .touch-keyboard-row {
40
+ display: flex;
41
+ flex-direction: row;
42
+
43
+ &:not(:last-child) {
44
+ margin-bottom: 0.25rem;
45
+ }
46
+ }
47
+
48
+ .touch-keyboard-key {
49
+ width: 20px;
50
+ box-sizing: border-box;
51
+ position: relative;
52
+ -webkit-user-select: none;
53
+ user-select: none;
54
+ cursor: pointer;
55
+ outline: none;
56
+ border: none;
57
+ text-align: center;
58
+ margin: 0;
59
+ line-height: 32px;
60
+ padding: 0.25rem;
61
+ border-radius: 0.375rem;
62
+ font-size: 14px;
63
+ font-weight: 500;
64
+ display: flex;
65
+ flex-grow: 1;
66
+ align-items: center;
67
+ justify-content: center;
68
+ color: var(--touch-keyboard-text);
69
+ background-color: var(--touch-keyboard-button);
70
+ box-shadow: 0px 3px 1px -2px rgb(0 0 0 / 20%),
71
+ 0px 2px 2px 0px rgb(0 0 0 / 14%), 0px 1px 5px 0px rgb(0 0 0 / 12%);
72
+
73
+ &.function-key:not(.space-key) {
74
+ background-color: var(--touch-keyboard-button-fn);
75
+ }
76
+
77
+ &.active {
78
+ background-color: var(--touch-keyboard-button-active) !important;
79
+ }
80
+
81
+ &.ent-key,
82
+ &.abc-key,
83
+ &.numbers-key,
84
+ &.extends-key {
85
+ max-width: 8rem;
86
+ }
87
+
88
+ &.space-key {
89
+ min-width: 50%;
90
+ }
91
+
92
+ &[data-layout="numeric"],
93
+ &[data-layout="decimal"],
94
+ &[data-layout="tel"] {
95
+ width: 33%;
96
+ max-width: none;
97
+ }
98
+
99
+ &:not(:last-child) {
100
+ margin-right: 0.25rem;
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { NgxTouchKeyboardComponent } from './ngx-touch-keyboard.component';
4
+
5
+ describe('NgxTouchKeyboardComponent', () => {
6
+ let component: NgxTouchKeyboardComponent;
7
+ let fixture: ComponentFixture<NgxTouchKeyboardComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [NgxTouchKeyboardComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(NgxTouchKeyboardComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });