@supermousejs/icon 2.0.0 → 2.0.2
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 +18 -0
- package/README.md +29 -0
- package/package.json +3 -3
- package/src/index.ts +51 -51
- package/tsconfig.json +17 -17
- package/vite.config.ts +25 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @supermousejs/icon
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ae219a0: Update READMEs with correct link to documentation
|
|
8
|
+
- Updated dependencies [ae219a0]
|
|
9
|
+
- @supermousejs/utils@2.0.2
|
|
10
|
+
- @supermousejs/core@2.0.2
|
|
11
|
+
|
|
12
|
+
## 2.0.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Add minimal README.md files to packages
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @supermousejs/utils@2.0.1
|
|
19
|
+
- @supermousejs/core@2.0.1
|
|
20
|
+
|
|
3
21
|
## 2.0.0
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
# @supermousejs/icon
|
|
3
|
+
|
|
4
|
+
Renders a static SVG icon at the cursor position. Useful for custom pointers.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @supermousejs/icon
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { Supermouse } from '@supermousejs/core';
|
|
16
|
+
import { Icon } from '@supermousejs/icon';
|
|
17
|
+
|
|
18
|
+
const app = new Supermouse();
|
|
19
|
+
|
|
20
|
+
app.use(Icon({
|
|
21
|
+
svg: '<svg>...</svg>', // Your SVG string
|
|
22
|
+
size: 24,
|
|
23
|
+
color: 'black'
|
|
24
|
+
}));
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
Full documentation and interactive playground available at [supermouse](https://supermouse.vercel.app) or [check out the repo](https://github.com/Whitestar14/supermouse-js).
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/icon",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@supermousejs/core": "2.0.
|
|
9
|
-
"@supermousejs/utils": "2.0.
|
|
8
|
+
"@supermousejs/core": "2.0.2",
|
|
9
|
+
"@supermousejs/utils": "2.0.2"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {},
|
|
12
12
|
"peerDependencies": {},
|
package/src/index.ts
CHANGED
|
@@ -1,52 +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);
|
|
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
52
|
};
|
package/tsconfig.json
CHANGED
|
@@ -1,18 +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
|
-
}
|
|
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
18
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,26 +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 })]
|
|
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
26
|
});
|