Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
.DS_Store
node_modules
apps/*/dist

# IDE
.idea/
.vscode/

# Package managers
.pnpm-store/
.yarn/
.npm/

# Build artifacts
dist/
*.log
*.tsbuildinfo

# OS
Thumbs.db
7 changes: 7 additions & 0 deletions apps/angular-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# angular-example

## 0.0.6

### Patch Changes

- Initial Angular example
19 changes: 19 additions & 0 deletions apps/angular-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Angular Example - Web Haptics</title>
<style>
body {
margin: 0;
font-family: system-ui, -apple-system, sans-serif;
}
</style>
</head>
<body>
<app-root></app-root>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions apps/angular-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "angular-example",
"private": true,
"version": "0.0.6",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@angular/common": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"rxjs": "^7.8.0",
"tslib": "^2.6.0",
"web-haptics": "workspace:*",
"zone.js": "^0.14.0"
},
"devDependencies": {
"@analogjs/vite-plugin-angular": "^1.0.0",
"@angular-devkit/build-angular": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/compiler-cli": "^17.0.0",
"typescript": "~5.4.0",
"vite": "^7.3.1"
}
}
24 changes: 24 additions & 0 deletions apps/angular-example/src/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from "@angular/core";
import { injectWebHaptics } from "web-haptics/angular";

@Component({
selector: "app-root",
standalone: true,
template: `
<div class="container">
<button (click)="haptics.trigger()">Tap me</button>
</div>
`,
styles: `
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-size: 2rem;
}
`,
})
export class AppComponent {
haptics = injectWebHaptics();
}
5 changes: 5 additions & 0 deletions apps/angular-example/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "zone.js";
import { bootstrapApplication } from "@angular/platform-browser";
import { AppComponent } from "./app.component";

bootstrapApplication(AppComponent).catch((err) => console.error(err));
13 changes: 13 additions & 0 deletions apps/angular-example/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist/out-tsc",
"types": []
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.ts"
]
}
18 changes: 18 additions & 0 deletions apps/angular-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
16 changes: 16 additions & 0 deletions apps/angular-example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "vite";
import angular from "@analogjs/vite-plugin-angular";
import path from "path";

export default defineConfig({
plugins: [
angular({
tsconfig: path.resolve(__dirname, "tsconfig.app.json"),
}),
],
resolve: {
alias: {
"web-haptics/angular": path.resolve(__dirname, "../../packages/web-haptics/dist/angular/index.mjs"),
},
},
});
15 changes: 13 additions & 2 deletions packages/web-haptics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"types": "./dist/svelte/index.d.ts",
"import": "./dist/svelte/index.mjs",
"require": "./dist/svelte/index.js"
},
"./angular": {
"types": "./dist/angular/index.d.ts",
"import": "./dist/angular/index.mjs",
"require": "./dist/angular/index.js"
}
},
"publishConfig": {
Expand All @@ -54,6 +59,7 @@
"react",
"vue",
"svelte",
"angular",
"typescript"
],
"bugs": {
Expand All @@ -71,7 +77,8 @@
"react": ">=18",
"react-dom": ">=18",
"vue": ">=3",
"svelte": ">=4"
"svelte": ">=4",
"@angular/core": ">=17"
},
"peerDependenciesMeta": {
"react": {
Expand All @@ -85,6 +92,9 @@
},
"svelte": {
"optional": true
},
"@angular/core": {
"optional": true
}
},
"devDependencies": {
Expand All @@ -106,6 +116,7 @@
"svelte": "^4.0.0",
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"vue": "^3.3.0"
"vue": "^3.3.0",
"@angular/core": "^17.0.0"
}
}
1 change: 1 addition & 0 deletions packages/web-haptics/src/angular/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { injectWebHaptics } from "./inject-web-haptics";
28 changes: 28 additions & 0 deletions packages/web-haptics/src/angular/inject-web-haptics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { inject, DestroyRef, afterNextRender } from "@angular/core";
import { WebHaptics } from "../lib/web-haptics";
import type {
HapticInput,
TriggerOptions,
WebHapticsOptions,
} from "../lib/web-haptics/types";

export function injectWebHaptics(options?: WebHapticsOptions) {
const destroyRef = inject(DestroyRef);
let instance: WebHaptics | null = null;

afterNextRender(() => {
instance = new WebHaptics(options);
});

destroyRef.onDestroy(() => {
instance?.destroy();
instance = null;
});

const trigger = (input?: HapticInput, options?: TriggerOptions) =>
instance?.trigger(input, options);
const cancel = () => instance?.cancel();
const isSupported = WebHaptics.isSupported;

return { trigger, cancel, isSupported };
}
8 changes: 8 additions & 0 deletions packages/web-haptics/src/angular/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type {
Vibration,
HapticPattern,
HapticPreset,
HapticInput,
TriggerOptions,
WebHapticsOptions,
} from "../lib/web-haptics/types";
12 changes: 12 additions & 0 deletions packages/web-haptics/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ export default defineConfig((options) => [
external: ["svelte"],
minify: !options.watch,
},
// Angular
{
entry: {
"angular/index": "src/angular/index.ts",
},
format: ["cjs", "esm"],
dts: true,
sourcemap: false,
target: "es2022",
external: ["@angular/core"],
minify: !options.watch,
},
]);
Loading