@supermousejs/text 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 +13 -0
- package/LICENSE.md +21 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +31 -0
- package/dist/index.umd.js +1 -0
- package/meta.json +15 -0
- package/package.json +26 -0
- package/src/index.ts +60 -0
- package/tsconfig.json +18 -0
- package/vite.config.ts +22 -0
package/CHANGELOG.md
ADDED
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SupermousePlugin } from '../../core/src/index.ts';
|
|
2
|
+
|
|
3
|
+
declare const Text_2: (options?: TextOptions) => SupermousePlugin;
|
|
4
|
+
export { Text_2 as Text }
|
|
5
|
+
|
|
6
|
+
export declare interface TextOptions {
|
|
7
|
+
name?: string;
|
|
8
|
+
isEnabled?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
offset?: [number, number];
|
|
11
|
+
duration?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { }
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { definePlugin as f, dom as e, Easings as p, Layers as u } from "@supermousejs/utils";
|
|
2
|
+
const y = (s = {}) => {
|
|
3
|
+
const r = s.className || "supermouse-text", [c, i] = s.offset || [0, 24], l = s.duration || 200;
|
|
4
|
+
let a;
|
|
5
|
+
return f({
|
|
6
|
+
name: "text",
|
|
7
|
+
selector: "[data-supermouse-text]",
|
|
8
|
+
create: () => {
|
|
9
|
+
const t = e.createActor("div");
|
|
10
|
+
return e.applyStyles(t, {
|
|
11
|
+
zIndex: u.OVERLAY,
|
|
12
|
+
opacity: "0",
|
|
13
|
+
transition: `opacity ${l}ms ${p.SMOOTH}`,
|
|
14
|
+
whiteSpace: "nowrap",
|
|
15
|
+
pointerEvents: "none"
|
|
16
|
+
}), t.classList.add(...r.split(" ").filter(Boolean)), a = document.createElement("span"), t.appendChild(a), e.setTransform(t, -100, -100), t;
|
|
17
|
+
},
|
|
18
|
+
update: (t, o) => {
|
|
19
|
+
const n = t.state.interaction.text;
|
|
20
|
+
if (t.state.isHover && n) {
|
|
21
|
+
a.innerText = n, e.setStyle(o, "opacity", "1");
|
|
22
|
+
const { x: d, y: m } = t.state.smooth;
|
|
23
|
+
e.setTransform(o, d + c, m + i);
|
|
24
|
+
} else
|
|
25
|
+
e.setStyle(o, "opacity", "0");
|
|
26
|
+
}
|
|
27
|
+
}, s);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
y as Text
|
|
31
|
+
};
|
|
@@ -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.SupermouseText={},o.SupermouseUtils))})(this,(function(o,e){"use strict";const d=(s={})=>{const i=s.className||"supermouse-text",[c,m]=s.offset||[0,24],f=s.duration||200;let n;return e.definePlugin({name:"text",selector:"[data-supermouse-text]",create:()=>{const t=e.dom.createActor("div");return e.dom.applyStyles(t,{zIndex:e.Layers.OVERLAY,opacity:"0",transition:`opacity ${f}ms ${e.Easings.SMOOTH}`,whiteSpace:"nowrap",pointerEvents:"none"}),t.classList.add(...i.split(" ").filter(Boolean)),n=document.createElement("span"),t.appendChild(n),e.dom.setTransform(t,-100,-100),t},update:(t,r)=>{const a=t.state.interaction.text;if(t.state.isHover&&a){n.innerText=a,e.dom.setStyle(r,"opacity","1");const{x:u,y:p}=t.state.smooth;e.dom.setTransform(r,u+c,p+m)}else e.dom.setStyle(r,"opacity","0")}},s)};o.Text=d,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/meta.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"id": "text",
|
|
4
|
+
"name": "Text",
|
|
5
|
+
"package": "@supermousejs/text",
|
|
6
|
+
"description": "Injects contextual text bubbles near the cursor on interaction.",
|
|
7
|
+
"code": "app.use(Text({ font: 'Mono' }));",
|
|
8
|
+
"recipeId": "text-cursor",
|
|
9
|
+
"icon": "text",
|
|
10
|
+
"options": [
|
|
11
|
+
{ "name": "className", "type": "string", "default": "'supermouse-text'", "description": "CSS class added to container.", "reactive": false },
|
|
12
|
+
{ "name": "offset", "type": "[number, number]", "default": "[0, 24]", "description": "X/Y offset from cursor.", "reactive": false },
|
|
13
|
+
{ "name": "duration", "type": "number", "default": "200", "description": "Fade transition time in ms.", "reactive": false }
|
|
14
|
+
]
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@supermousejs/text",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@supermousejs/core": "2.0.0",
|
|
6
|
+
"@supermousejs/utils": "2.0.0"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.umd.js",
|
|
9
|
+
"module": "dist/index.mjs",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"peerDependencies": {},
|
|
12
|
+
"devDependencies": {},
|
|
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,60 @@
|
|
|
1
|
+
import { definePlugin, dom, Layers, Easings } from '@supermousejs/utils';
|
|
2
|
+
|
|
3
|
+
export interface TextOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
isEnabled?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
offset?: [number, number];
|
|
8
|
+
duration?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Text = (options: TextOptions = {}) => {
|
|
12
|
+
const className = options.className || 'supermouse-text';
|
|
13
|
+
const [offX, offY] = options.offset || [0, 24];
|
|
14
|
+
const duration = options.duration || 200;
|
|
15
|
+
|
|
16
|
+
let textNode: HTMLSpanElement;
|
|
17
|
+
|
|
18
|
+
return definePlugin<HTMLDivElement, TextOptions>({
|
|
19
|
+
name: 'text',
|
|
20
|
+
selector: '[data-supermouse-text]',
|
|
21
|
+
|
|
22
|
+
create: () => {
|
|
23
|
+
const el = dom.createActor('div') as HTMLDivElement;
|
|
24
|
+
|
|
25
|
+
dom.applyStyles(el, {
|
|
26
|
+
zIndex: Layers.OVERLAY,
|
|
27
|
+
opacity: '0',
|
|
28
|
+
transition: `opacity ${duration}ms ${Easings.SMOOTH}`,
|
|
29
|
+
whiteSpace: 'nowrap',
|
|
30
|
+
pointerEvents: 'none'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (className) {
|
|
34
|
+
el.classList.add(...className.split(' ').filter(Boolean));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
textNode = document.createElement('span');
|
|
38
|
+
el.appendChild(textNode);
|
|
39
|
+
|
|
40
|
+
dom.setTransform(el, -100, -100);
|
|
41
|
+
return el;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
update: (app, el) => {
|
|
45
|
+
// Use pre-parsed interaction data instead of querying DOM
|
|
46
|
+
const text = app.state.interaction.text;
|
|
47
|
+
|
|
48
|
+
if (app.state.isHover && text) {
|
|
49
|
+
textNode.innerText = text;
|
|
50
|
+
dom.setStyle(el, 'opacity', '1');
|
|
51
|
+
|
|
52
|
+
// Dynamic position based on pointer
|
|
53
|
+
const { x, y } = app.state.smooth;
|
|
54
|
+
dom.setTransform(el, x + offX, y + offY);
|
|
55
|
+
} else {
|
|
56
|
+
dom.setStyle(el, 'opacity', '0');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, options);
|
|
60
|
+
};
|
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,22 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import dts from 'vite-plugin-dts';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
build: {
|
|
7
|
+
lib: {
|
|
8
|
+
entry: path.resolve(__dirname, 'src/index.ts'),
|
|
9
|
+
name: 'SupermouseText',
|
|
10
|
+
fileName: (format) => format === 'es' ? 'index.mjs' : 'index.umd.js',
|
|
11
|
+
},
|
|
12
|
+
rollupOptions: {
|
|
13
|
+
external: ['@supermousejs/core', '@supermousejs/utils'],
|
|
14
|
+
output: {
|
|
15
|
+
globals: {
|
|
16
|
+
'@supermousejs/core': 'SupermouseCore'
|
|
17
|
+
, '@supermousejs/utils': 'SupermouseUtils'}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
plugins: [dts({ rollupTypes: true })]
|
|
22
|
+
});
|