├── .gitignore ├── README.md ├── hooks ├── index.js ├── useOutBlur.ts └── useMouseGradient.ts ├── tsconfig.json ├── package.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | .idea/ 4 | package-lock.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # use-actions 2 | Ready to use Svelte use actions 3 | -------------------------------------------------------------------------------- /hooks/index.js: -------------------------------------------------------------------------------- 1 | import {useOutBlur} from "./useOutBlur"; 2 | import {mouseGradient} from "./useMouseGradient"; 3 | 4 | export {useOutBlur, mouseGradient}; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "outDir": "./dist", 5 | "module": "commonjs", 6 | "target": "ES2015", 7 | "lib": ["ES2015", "DOM"], 8 | "sourceMap": true 9 | } 10 | } -------------------------------------------------------------------------------- /hooks/useOutBlur.ts: -------------------------------------------------------------------------------- 1 | export function useOutBlur(node: HTMLElement) { 2 | document.addEventListener('click', function (event: EventTarget | any) { 3 | if (node) { 4 | const isClickInsideElement = node.contains(event.target); 5 | if (!isClickInsideElement) { 6 | node.dispatchEvent( 7 | new CustomEvent('outblur') 8 | ); 9 | } 10 | } 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@friendofsvelte/use-actions", 3 | "version": "0.0.1-dev.1", 4 | "description": "Ready to use Svelte use actions", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "scripts": { 8 | "build": "tsc", 9 | "prepare": "npm run build" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/friendofsvelte/use-actions.git" 14 | }, 15 | "keywords": [ 16 | "svelte", 17 | "svelte", 18 | "use", 19 | "hooks", 20 | "use", 21 | "actions" 22 | ], 23 | "author": "Bishwas Bhandari", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/friendofsvelte/use-actions/issues" 27 | }, 28 | "homepage": "https://github.com/friendofsvelte/use-actions#readme", 29 | "dependencies": { 30 | "svelte": "^4.2.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hooks/useMouseGradient.ts: -------------------------------------------------------------------------------- 1 | type MountGradientOptions = { color?: string; size?: number; bgColor?: string }; 2 | 3 | export function mouseGradient( 4 | node: HTMLElement, 5 | options: MountGradientOptions = { 6 | color: 'rgba(1, 255, 225, 0)', 7 | size: 450, 8 | bgColor: 'rgb(12, 10, 9)' 9 | } 10 | ) { 11 | function update(event: MouseEvent) { 12 | node.style.background = `radial-gradient(${options.size}px circle at 13 | ${event.pageX - node.getBoundingClientRect().left}px ${ 14 | event.pageY - node.getBoundingClientRect().top 15 | }px, 16 | ${options.color}, ${options.bgColor})`; 17 | } 18 | 19 | function remove() { 20 | node.style.background = ``; 21 | node.style.removeProperty('outline'); 22 | } 23 | 24 | node.addEventListener('mousemove', update); 25 | node.addEventListener('mouseout', remove); 26 | return { 27 | destroy() { 28 | node.removeEventListener('mousemove', update); 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Friend Of Svelte 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. 22 | --------------------------------------------------------------------------------