@supermousejs/icon 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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @supermousejs/icon
2
+
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Initial v2.0.0 release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @supermousejs/utils@2.0.0
13
+ - @supermousejs/core@2.0.0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sijibomi Olusunmbola
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.
@@ -0,0 +1,20 @@
1
+ import { SupermousePlugin } from '../../core/src/index.ts';
2
+ import { ValueOrGetter } from '../../core/src/index.ts';
3
+
4
+ export declare const Icon: (options: IconOptions) => SupermousePlugin;
5
+
6
+ export declare interface IconOptions {
7
+ name?: string;
8
+ isEnabled?: boolean;
9
+ /** SVG Content String */
10
+ svg: string;
11
+ /** Size in pixels (default 24) */
12
+ size?: ValueOrGetter<number>;
13
+ /** CSS Color (default black) */
14
+ color?: ValueOrGetter<string>;
15
+ opacity?: ValueOrGetter<number>;
16
+ /** Offset [x, y] from cursor center */
17
+ offset?: [number, number];
18
+ }
19
+
20
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ import { normalize as o, definePlugin as g, dom as s, Layers as d } from "@supermousejs/utils";
2
+ const x = (e) => {
3
+ const n = o(e.size, 24), l = o(e.opacity, 1), y = o(e.color, "black"), [a, i] = e.offset || [0, 0];
4
+ return g({
5
+ name: e.name || "icon",
6
+ create: () => {
7
+ const t = s.createActor("div");
8
+ return t.style.zIndex = d.CURSOR, t.style.display = "flex", t.style.alignItems = "center", t.style.justifyContent = "center", t.innerHTML = e.svg, t;
9
+ },
10
+ styles: {
11
+ color: "color"
12
+ },
13
+ update: (t, c) => {
14
+ const r = n(t.state);
15
+ s.setStyle(c, "width", `${r}px`), s.setStyle(c, "height", `${r}px`), s.setStyle(c, "opacity", String(l(t.state))), s.setStyle(c, "color", y(t.state));
16
+ const { x: f, y: m } = t.state.smooth;
17
+ s.setTransform(c, f + a, m + i, 0);
18
+ }
19
+ }, e);
20
+ };
21
+ export {
22
+ x as Icon
23
+ };
@@ -0,0 +1 @@
1
+ (function(o,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],e):(o=typeof globalThis<"u"?globalThis:o||self,e(o.SupermouseIcon={},o.SupermouseUtils))})(this,(function(o,e){"use strict";const c=n=>{const d=e.normalize(n.size,24),f=e.normalize(n.opacity,1),i=e.normalize(n.color,"black"),[m,y]=n.offset||[0,0];return e.definePlugin({name:n.name||"icon",create:()=>{const t=e.dom.createActor("div");return t.style.zIndex=e.Layers.CURSOR,t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.innerHTML=n.svg,t},styles:{color:"color"},update:(t,s)=>{const r=d(t.state);e.dom.setStyle(s,"width",`${r}px`),e.dom.setStyle(s,"height",`${r}px`),e.dom.setStyle(s,"opacity",String(f(t.state))),e.dom.setStyle(s,"color",i(t.state));const{x:a,y:l}=t.state.smooth;e.dom.setTransform(s,a+m,l+y,0)}},n)};o.Icon=c,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
package/meta.json ADDED
@@ -0,0 +1,16 @@
1
+
2
+ {
3
+ "id": "icon",
4
+ "name": "Icon",
5
+ "package": "@supermousejs/icon",
6
+ "description": "Renders a static SVG icon at the cursor position.",
7
+ "code": "app.use(Icon({ svg: '<svg>...</svg>', size: 24 }));",
8
+ "icon": "context",
9
+ "options": [
10
+ { "name": "svg", "type": "string", "default": "undefined", "description": "SVG content string. (Required)", "reactive": false },
11
+ { "name": "size", "type": "number", "default": "24", "description": "Size of the icon container.", "reactive": true },
12
+ { "name": "color", "type": "string", "default": "'black'", "description": "CSS color (currentColor).", "reactive": true },
13
+ { "name": "opacity", "type": "number", "default": "1", "description": "Opacity level (0-1).", "reactive": true },
14
+ { "name": "offset", "type": "[number, number]", "default": "[0, 0]", "description": "Fixed [x, y] offset from cursor center.", "reactive": false }
15
+ ]
16
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@supermousejs/icon",
3
+ "version": "2.0.0",
4
+ "main": "dist/index.umd.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "@supermousejs/core": "2.0.0",
9
+ "@supermousejs/utils": "2.0.0"
10
+ },
11
+ "devDependencies": {},
12
+ "peerDependencies": {},
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.umd.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "vite build"
25
+ }
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { ValueOrGetter } from '@supermousejs/core';
2
+ import { definePlugin, normalize, dom, Layers } from '@supermousejs/utils';
3
+
4
+ export interface IconOptions {
5
+ name?: string;
6
+ isEnabled?: boolean;
7
+ /** SVG Content String */
8
+ svg: string;
9
+ /** Size in pixels (default 24) */
10
+ size?: ValueOrGetter<number>;
11
+ /** CSS Color (default black) */
12
+ color?: ValueOrGetter<string>;
13
+ opacity?: ValueOrGetter<number>;
14
+ /** Offset [x, y] from cursor center */
15
+ offset?: [number, number];
16
+ }
17
+
18
+ export const Icon = (options: IconOptions) => {
19
+ const getSize = normalize(options.size, 24);
20
+ const getOpacity = normalize(options.opacity, 1);
21
+ const getColor = normalize(options.color, 'black');
22
+ const [offX, offY] = options.offset || [0, 0];
23
+
24
+ return definePlugin<HTMLDivElement, IconOptions>({
25
+ name: options.name || 'icon',
26
+
27
+ create: () => {
28
+ const el = dom.createActor('div') as HTMLDivElement;
29
+ el.style.zIndex = Layers.CURSOR;
30
+ el.style.display = 'flex';
31
+ el.style.alignItems = 'center';
32
+ el.style.justifyContent = 'center';
33
+ el.innerHTML = options.svg;
34
+ return el;
35
+ },
36
+
37
+ styles: {
38
+ color: 'color'
39
+ },
40
+
41
+ update: (app, el) => {
42
+ const size = getSize(app.state);
43
+ dom.setStyle(el, 'width', `${size}px`);
44
+ dom.setStyle(el, 'height', `${size}px`);
45
+ dom.setStyle(el, 'opacity', String(getOpacity(app.state)));
46
+ dom.setStyle(el, 'color', getColor(app.state));
47
+
48
+ const { x, y } = app.state.smooth;
49
+ dom.setTransform(el, x + offX, y + offY, 0);
50
+ }
51
+ }, options);
52
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "include": [
4
+ "src"
5
+ ],
6
+ "compilerOptions": {
7
+ "outDir": "dist",
8
+ "baseUrl": ".",
9
+ "paths": {
10
+ "@supermousejs/core": [
11
+ "../core/src/index.ts"
12
+ ],
13
+ "@supermousejs/utils": [
14
+ "../utils/src/index.ts"
15
+ ]
16
+ }
17
+ }
18
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'vite';
2
+ import dts from 'vite-plugin-dts';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ export default defineConfig({
10
+ build: {
11
+ lib: {
12
+ entry: path.resolve(__dirname, 'src/index.ts'),
13
+ name: 'SupermouseIcon',
14
+ fileName: (format) => format === 'es' ? 'index.mjs' : 'index.umd.js',
15
+ },
16
+ rollupOptions: {
17
+ external: ['@supermousejs/core', '@supermousejs/utils'],
18
+ output: {
19
+ globals: {
20
+ '@supermousejs/core': 'SupermouseCore'
21
+ , '@supermousejs/utils': 'SupermouseUtils'}
22
+ }
23
+ }
24
+ },
25
+ plugins: [dts({ rollupTypes: true })]
26
+ });