{"_id":"@akcodeworks/svelte-listen","_rev":"3-3da6bb9df81788e3b04f247ad75904bf","name":"@akcodeworks/svelte-listen","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@akcodeworks/svelte-listen","version":"0.0.1","keywords":["svelte"],"author":{"name":"akcodeworks"},"license":"MIT","_id":"@akcodeworks/svelte-listen@0.0.1","maintainers":[{"name":"agillispie","email":"akcoding9154@gmail.com"}],"homepage":"https://github.com/akcodeworks/svelte-listen#readme","bugs":{"url":"https://github.com/akcodeworks/svelte-listen/issues"},"dist":{"shasum":"85ae3cb1abff0298002fd7babc7b9153e1bc5680","tarball":"https://registry.npmjs.org/@akcodeworks/svelte-listen/-/svelte-listen-0.0.1.tgz","fileCount":8,"integrity":"sha512-ZAThkD1UQ6DoTuHKYz3gUO24wX/HGZ2+u3xijPAaihkHgTklRBDVJBmbUaRHRVJz2veiR5SylsKpeTC7Oe0RpQ==","signatures":[{"sig":"MEQCIGsNIKrEug1ik9BCmaj1v+yb1sypG6Xm24/VktuLZU8LAiBV7Mqibm0RYEzaUGHlRtYS1DPQle7ESqLZijoZ6x6u6g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9577},"type":"module","types":"./dist/index.d.ts","svelte":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","svelte":"./dist/index.js"}},"scripts":{"dev":"vite dev","lint":"prettier --check . && eslint .","test":"npm run test:unit -- --run","build":"vite build && npm run prepack","check":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json","format":"prettier --write .","prepack":"svelte-kit sync && svelte-package && publint","prepare":"svelte-kit sync || echo ''","preview":"vite preview","test:unit":"vitest","check:watch":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"},"_npmUser":{"name":"agillispie","email":"akcoding9154@gmail.com"},"repository":{"url":"git+https://github.com/akcodeworks/svelte-listen.git","type":"git"},"_npmVersion":"11.2.0","description":"A SvelteKit action to listen to events outside of an element.","directories":{},"sideEffects":["**/*.css"],"_nodeVersion":"22.13.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^7.2.2","eslint":"^9.39.1","svelte":"^5.43.8","vitest":"^4.0.10","globals":"^16.5.0","publint":"^0.3.15","prettier":"^3.6.2","@eslint/js":"^9.39.1","playwright":"^1.56.1","typescript":"^5.9.3","@types/node":"^22","svelte-check":"^4.3.4","@sveltejs/kit":"^2.48.5","@eslint/compat":"^1.4.0","@sveltejs/package":"^2.5.6","typescript-eslint":"^8.47.0","eslint-plugin-svelte":"^3.13.0","vitest-browser-svelte":"^2.0.1","@sveltejs/adapter-auto":"^7.0.0","eslint-config-prettier":"^10.1.8","prettier-plugin-svelte":"^3.4.0","@vitest/browser-playwright":"^4.0.10","@sveltejs/vite-plugin-svelte":"^6.2.1"},"peerDependencies":{"svelte":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/svelte-listen_0.0.1_1764551129066_0.7344725306191164","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-12-01T01:05:28.924Z","modified":"2025-12-01T21:58:49.003Z","0.0.1":"2025-12-01T01:05:29.313Z"},"bugs":{"url":"https://github.com/akcodeworks/svelte-listen/issues"},"author":{"name":"akcodeworks"},"license":"MIT","homepage":"https://github.com/akcodeworks/svelte-listen#readme","keywords":["svelte"],"repository":{"url":"git+https://github.com/akcodeworks/svelte-listen.git","type":"git"},"description":"A SvelteKit action to listen to events outside of an element.","maintainers":[{"email":"agillispie90@gmail.com","name":"iatrophobic"}],"readme":"# svelte-listen\n\nA tiny Svelte 5 attachment for keyboard shortcuts. Bind global key combos with a single `{@attach ...}` and get automatic cleanup.\n\n- Works with the new `{@attach ...}` syntax\n- Adds/removes the window `keydown` listener automatically\n- Shortcut strings look like `Ctrl+Shift+K`\n- Fully typed with helper shortcut types\n\n## Installation\n\n```sh\nnpm install @akcodeworks/svelte-listen\n# pnpm add @akcodeworks/svelte-listen\n# yarn add @akcodeworks/svelte-listen\n```\n\nPeer dependency: `svelte@^5.0.0`.\n\n## Quick start\n\n```svelte\n<script lang=\"ts\">\n  import { listener } from '@akcodeworks/svelte-listen';\n</script>\n\n<button\n  {@attach listener({\n    Enter: (e) => {\n      e.preventDefault();\n      console.log('Pressed Enter anywhere');\n    },\n    'Ctrl+Shift+K': () => console.log('Pressed Ctrl+Shift+K')\n  })}\n>\n  Press me\n</button>\n```\n\nThe attachment will:\n\n- Register a global `keydown` listener for any shortcuts you specify.\n- Clean everything up automatically when the element is destroyed.\n\n## Shortcut syntax\n\nShortcut keys use the `KeyboardEvent.key` names and a `+`-separated list of modifiers:\n\n- Single key: `\"Escape\"`, `\"K\"`, `\"F2\"`, `\"ArrowUp\"`\n- With modifiers: `\"Ctrl+K\"`, `\"Alt+ArrowDown\"`, `\"Ctrl+Shift+L\"`\n\nUse uppercase letters for single-character keys; the helper normalizes casing for you.\n\n## API\n\n`listener<T extends HTMLElement>(shortcuts?: ShortcutHandlers): Attachment<T>`\n\n- `shortcuts`: A map of `ShortcutString` to handler.\n- Returns a Svelte attachment that can be used with `{@attach ...}` on any element. The element reference is unused but required by Svelte's `{@attach ...}` contract.\n\nTypes are exported for convenience:\n\n```ts\nimport type { ShortcutString, KeyboardEventKey, ShortcutHandlers } from '@akcodeworks/svelte-listen';\n```\n\n## Development\n\n- Install deps: `npm install`\n- Run the demo app: `npm run dev -- --open`\n- Tests: `npm test`\n- Lint/format: `npm run lint` and `npm run format`\n- Build package: `npm run build` (runs `svelte-package` and `publint`)\n\n## Notes\n\n- Keyboard shortcuts are bound at `window` level on `keydown`.\n- Call `event.preventDefault()` inside your shortcut handler if you need to suppress the browser default for that key combo.\n","readmeFilename":"README.md"}