chrome-polish-button 1.0.1

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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -0
  3. package/package.json +21 -0
  4. package/script.js +130 -0
  5. package/style.css +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Drag0nSlay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # chrome-polish-button
2
+
3
+ A high-end **skeuomorphic chrome-style button** with
4
+ ✨ live camera reflection
5
+ ✨ tactile press animation
6
+ ✨ optional click sound
7
+
8
+ Built for modern browsers using **pure JavaScript + CSS**.
9
+
10
+ ---
11
+
12
+ ## ✨ Features
13
+
14
+ - Realistic **chrome / metal button** look
15
+ - **Live camera reflection** using `<canvas>`
16
+ - Smooth **press & highlight animation**
17
+ - Optional **sound feedback**
18
+ - No framework dependency
19
+ - Works with **Vite, React, Vanilla JS**
20
+ - Lightweight & beginner friendly
21
+
22
+ ---
23
+
24
+ ## πŸ“¦ Installation
25
+
26
+ ```bash
27
+ npm install chrome-polish-button
28
+ ```
29
+
30
+ ## πŸš€ Basic Usage (Vanilla / Vite)
31
+ ### 1️. Import the package
32
+ ```bash
33
+ import ChromeTactileButton from "chrome-polish-button";
34
+ import "chrome-polish-button/style.css";
35
+ ```
36
+
37
+ ### 2. Add HTML container
38
+ ```bash
39
+ <div id="my-button"></div>
40
+ ```
41
+
42
+ ### 3. Initialize the button
43
+ ```bash
44
+ new ChromeTactileButton("#my-button", {
45
+ label: "Button" });
46
+ ```
47
+ **πŸŽ‰ That’s it!**
48
+ The button will render inside the container.
49
+
50
+ ## πŸ”Š Using Sound (Optional)
51
+
52
+ For sound support, **add the sound file in your project**, not inside the package.
53
+
54
+ **πŸ“ Vite / Vanilla project structure**
55
+ ```bash
56
+ public/
57
+ └─ click.wav
58
+ ```
59
+
60
+ **🧩 Code**
61
+ ```bash
62
+ new ChromeTactileButton("#my-button", {
63
+ label: "Button",
64
+ soundSrc: "/click.wav" });
65
+ ```
66
+
67
+ > ℹ️ Sound plays only on user interaction (browser autoplay rules).
68
+
69
+ **πŸ“Έ Camera Permission**
70
+
71
+ - The button uses the **front camera** for reflection
72
+ - Browser will ask for permission
73
+ - If permission is denied, the button still works (no crash)
74
+
75
+ **βš™οΈ Configuration Options**
76
+
77
+ | Option | Type | Description |
78
+ | ---------- | ------ | ------------------------------ |
79
+ | `label` | string | Text shown on the button |
80
+ | `soundSrc` | string | Path to click sound (optional) |
81
+
82
+ **Example**
83
+ ```bash
84
+ new ChromeTactileButton("#btn", {
85
+ label: "PUSH",
86
+ soundSrc: "/click.wav" });
87
+ ```
88
+
89
+ **πŸ§ͺ Local Development / Testing**
90
+
91
+ If you want to test local changes without publishing:
92
+ ```bash
93
+ npm link
94
+ ```
95
+
96
+ In the test project:
97
+ ```bash
98
+ npm link chrome-polish-button
99
+ ```
100
+
101
+ **🌐 Browser Support**
102
+
103
+ - Chrome βœ…
104
+ - Edge βœ…
105
+ - Firefox ⚠️ (camera filters may vary)
106
+ - Mobile browsers βœ… (permission required)
107
+
108
+ ## πŸ“„ License
109
+
110
+ [MIT License](LICENSE) Β© Drag0nSlay
111
+
112
+ ## πŸ™Œ Contributing
113
+ Pull requests and suggestions are welcome.
114
+ This project is still evolving πŸš€
115
+
116
+ **⭐ If you like it**
117
+
118
+ Give it a ⭐ on GitHub
119
+ and share feedback on npm!
120
+
121
+ **πŸ”š Notes (for beginners)**
122
+
123
+ - Always import the CSS
124
+ - Place sound files in public/
125
+ - Camera permission is normal
126
+ - This is a **UI effect library**, not a framework
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "chrome-polish-button",
3
+ "version": "1.0.1",
4
+ "description": "A high-end skeuomorphic button with live camera reflection and tactile feedback.",
5
+ "main": "script.js",
6
+ "type": "module",
7
+ "files": [
8
+ "script.js",
9
+ "style.css"
10
+ ],
11
+ "keywords": [
12
+ "ui",
13
+ "button",
14
+ "chrome",
15
+ "skeuomorphism",
16
+ "camera-reflection",
17
+ "tactile"
18
+ ],
19
+ "author": "Drag0nSlay",
20
+ "license": "MIT"
21
+ }
package/script.js ADDED
@@ -0,0 +1,130 @@
1
+ export default class ChromeTactileButton {
2
+ constructor(elementId, options = {}) {
3
+ this.container = document.querySelector(elementId);
4
+ if (!this.container) return;
5
+
6
+ this.config = {
7
+ label: options.label || "PUSH",
8
+ soundSrc: options.soundSrc || null
9
+ };
10
+
11
+ this.highlightX = null;
12
+ this.audio = null;
13
+
14
+ if (this.config.soundSrc) {
15
+ this.audio = new Audio(this.config.soundSrc);
16
+ }
17
+
18
+ this.init();
19
+ }
20
+
21
+ init() {
22
+ this.container.classList.add("chrome-btn-container");
23
+ this.container.innerHTML = `
24
+ <canvas class="chrome-canvas"></canvas>
25
+ <div class="chrome-label">${this.config.label}</div>
26
+ <div class="chrome-fingerprint"></div>
27
+ <div class="chrome-hit-line"></div>
28
+ `;
29
+
30
+ this.canvas = this.container.querySelector(".chrome-canvas");
31
+ this.ctx = this.canvas.getContext("2d");
32
+ this.hitLine = this.container.querySelector(".chrome-hit-line");
33
+ this.fingerprint = this.container.querySelector(".chrome-fingerprint");
34
+
35
+ this.canvas.width = 320;
36
+ this.canvas.height = 140;
37
+
38
+ this.video = document.createElement("video");
39
+ this.video.setAttribute("autoplay", "");
40
+ this.video.setAttribute("muted", "");
41
+ this.video.setAttribute("playsinline", "");
42
+
43
+ this.startCamera();
44
+ this.bindEvents();
45
+ this.animate();
46
+ }
47
+
48
+ async startCamera() {
49
+ try {
50
+ const stream = await navigator.mediaDevices.getUserMedia({
51
+ video: { facingMode: "user" }
52
+ });
53
+ this.video.srcObject = stream;
54
+ await this.video.play();
55
+ } catch (e) {
56
+ console.warn("Camera access denied or unavailable");
57
+ }
58
+ }
59
+
60
+ bindEvents() {
61
+ const getCoords = (e) => {
62
+ const r = this.container.getBoundingClientRect();
63
+ const x = (e.touches ? e.touches[0].clientX : e.clientX) - r.left;
64
+ const y = (e.touches ? e.touches[0].clientY : e.clientY) - r.top;
65
+ return { x, y };
66
+ };
67
+
68
+ this.container.addEventListener("pointermove", (e) => {
69
+ this.highlightX = getCoords(e).x;
70
+ });
71
+
72
+ this.container.addEventListener("pointerdown", (e) => {
73
+ this.container.classList.add("is-pressed");
74
+
75
+ if (this.audio) {
76
+ this.audio.currentTime = 0;
77
+ this.audio.play().catch(() => {});
78
+ }
79
+
80
+ const { x, y } = getCoords(e);
81
+
82
+ this.hitLine.style.left = `${x}px`;
83
+ this.hitLine.classList.remove("active");
84
+ void this.hitLine.offsetWidth;
85
+ this.hitLine.classList.add("active");
86
+
87
+ this.fingerprint.style.left = `${x}px`;
88
+ this.fingerprint.style.top = `${y}px`;
89
+
90
+ this.container.classList.remove("animating-fp");
91
+ void this.container.offsetWidth;
92
+ this.container.classList.add("animating-fp");
93
+ });
94
+
95
+ const release = () => this.container.classList.remove("is-pressed");
96
+ window.addEventListener("pointerup", release);
97
+ window.addEventListener("pointercancel", release);
98
+ }
99
+
100
+ draw() {
101
+ const { ctx, canvas, video, highlightX } = this;
102
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
103
+
104
+ if (video.readyState >= 2) {
105
+ ctx.save();
106
+ ctx.globalAlpha = 0.55;
107
+ ctx.filter =
108
+ "blur(3px) contrast(1.2) brightness(1.1) saturate(1.3)";
109
+ ctx.translate(canvas.width, 0);
110
+ ctx.scale(-1, 1);
111
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
112
+ ctx.restore();
113
+ }
114
+
115
+ if (highlightX !== null) {
116
+ const p = highlightX / canvas.width;
117
+ const g = ctx.createLinearGradient(0, 0, canvas.width, 0);
118
+ g.addColorStop(0, "rgba(255,255,255,0)");
119
+ g.addColorStop(p, "rgba(255,255,255,0.7)");
120
+ g.addColorStop(1, "rgba(255,255,255,0)");
121
+ ctx.fillStyle = g;
122
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
123
+ }
124
+ }
125
+
126
+ animate() {
127
+ this.draw();
128
+ requestAnimationFrame(() => this.animate());
129
+ }
130
+ }
package/style.css ADDED
@@ -0,0 +1,85 @@
1
+ .chrome-btn-container {
2
+ width: 320px;
3
+ height: 140px;
4
+ border-radius: 70px;
5
+ position: relative;
6
+ overflow: hidden;
7
+ cursor: pointer;
8
+
9
+ outline: none;
10
+ -webkit-tap-highlight-color: transparent;
11
+ user-select: none;
12
+ touch-action: manipulation;
13
+
14
+ transition: transform .1s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow .1s ease;
15
+ box-shadow:
16
+ inset 0 6px 12px rgba(255,255,255,.9),
17
+ inset 0 -8px 14px rgba(0,0,0,.25),
18
+ 0 20px 40px rgba(0,0,0,.3);
19
+ z-index: 1;
20
+ }
21
+
22
+ .chrome-btn-container.is-pressed {
23
+ transform: translateY(4px) scale(.97);
24
+ box-shadow:
25
+ inset 0 3px 6px rgba(255,255,255,.6),
26
+ inset 0 -4px 8px rgba(0,0,0,.35),
27
+ 0 8px 18px rgba(0,0,0,.25);
28
+ }
29
+
30
+ .chrome-canvas {
31
+ width: 100%;
32
+ height: 100%;
33
+ display: block;
34
+ background: #ccc;
35
+ }
36
+
37
+ .chrome-label {
38
+ position: absolute;
39
+ inset: 0;
40
+ display: flex;
41
+ justify-content: center;
42
+ align-items: center;
43
+ font-size: 32px;
44
+ font-weight: 700;
45
+ color: #cfcfcf;
46
+ pointer-events: none;
47
+ mix-blend-mode: overlay;
48
+ text-shadow: 1px 1px 2px rgba(255,255,255,.9), -1px -1px 2px rgba(0,0,0,.5);
49
+ }
50
+
51
+ .chrome-fingerprint {
52
+ position: absolute;
53
+ inset: 0;
54
+ background: radial-gradient(circle at center, rgba(255,255,255,0.95), transparent 70%);
55
+ opacity: 0;
56
+ pointer-events: none;
57
+ }
58
+
59
+ .chrome-btn-container.animating-fp .chrome-fingerprint {
60
+ animation: heat-up 5s ease-out forwards;
61
+ }
62
+
63
+ @keyframes heat-up {
64
+ 0% { opacity: 1; filter: blur(0); }
65
+ 100% { opacity: 0; filter: blur(8px); }
66
+ }
67
+
68
+ .chrome-hit-line {
69
+ position: absolute;
70
+ width: 2px;
71
+ height: 100%;
72
+ background: white;
73
+ top: 0;
74
+ opacity: 0;
75
+ pointer-events: none;
76
+ }
77
+
78
+ .chrome-hit-line.active {
79
+ animation: flash 0.4s ease-out;
80
+ }
81
+
82
+ @keyframes flash {
83
+ 0% { opacity: 1; }
84
+ 100% { opacity: 0; }
85
+ }