@supermousejs/states 2.3.1 → 2.4.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/README.md +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.mjs +33 -29
- package/dist/index.umd.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @supermousejs/states
|
|
2
2
|
|
|
3
|
-
Logic controller that enables/disables other plugins based on hover attributes
|
|
3
|
+
Logic controller that enables/disables other plugins based on hover attributes
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { SupermousePlugin } from '../packages/core/src';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* State machine plugin.
|
|
5
|
+
*
|
|
6
|
+
* Hovers over `[data-supermouse-state="foo"]` enable the plugin list
|
|
7
|
+
* registered for `"foo"`. Everything else falls back to `default`.
|
|
8
|
+
*
|
|
9
|
+
* Install this **after** all plugins it manages, or initialization will
|
|
10
|
+
* miss plugins that haven't been registered yet.
|
|
11
|
+
*/
|
|
3
12
|
export declare const States: (options: StatesOptions) => SupermousePlugin;
|
|
4
13
|
|
|
5
14
|
export declare interface StatesOptions {
|
|
6
15
|
name?: string;
|
|
7
16
|
isEnabled?: boolean;
|
|
8
|
-
/**
|
|
17
|
+
/** Plugins active when no state attribute is hovered. */
|
|
9
18
|
default: string[];
|
|
10
|
-
/** Map of state names to
|
|
19
|
+
/** Map of state names to plugin names to enable. */
|
|
11
20
|
states: Record<string, string[]>;
|
|
12
|
-
/**
|
|
21
|
+
/** Attribute that triggers a state change. */
|
|
13
22
|
attribute?: string;
|
|
14
23
|
}
|
|
15
24
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import { definePlugin as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
Object.values(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let c = "default", d = !1;
|
|
8
|
-
return f(
|
|
1
|
+
import { definePlugin as g } from "@supermousejs/utils";
|
|
2
|
+
const E = (e) => {
|
|
3
|
+
const u = e.attribute ?? "data-supermouse-state", d = new Set(e.default), r = /* @__PURE__ */ new Set();
|
|
4
|
+
Object.values(e.states).forEach((t) => t.forEach((a) => r.add(a))), e.default.forEach((t) => r.add(t));
|
|
5
|
+
let f = "__UNINITIALIZED__";
|
|
6
|
+
return g(
|
|
9
7
|
{
|
|
10
8
|
name: "states",
|
|
11
|
-
// High priority: Run BEFORE visual plugins so they know if they are enabled/disabled this frame
|
|
12
9
|
priority: -999,
|
|
13
|
-
install(
|
|
14
|
-
|
|
10
|
+
install(t) {
|
|
11
|
+
t.registerHoverTarget(`[${u}]`);
|
|
15
12
|
},
|
|
16
|
-
update(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const t = l.getAttribute(r);
|
|
26
|
-
t && a.states[t] && (s = t);
|
|
13
|
+
update(t) {
|
|
14
|
+
const a = t.state.hoverTarget;
|
|
15
|
+
let n = "default";
|
|
16
|
+
if (a) {
|
|
17
|
+
const s = a.closest(`[${u}]`);
|
|
18
|
+
if (s) {
|
|
19
|
+
const l = s.getAttribute(u);
|
|
20
|
+
l && e.states[l] && (n = l);
|
|
21
|
+
}
|
|
27
22
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (n === f) return;
|
|
24
|
+
const o = n === "default" ? e.default : e.states[n];
|
|
25
|
+
for (const s of r) {
|
|
26
|
+
const l = t.getPlugin(s);
|
|
27
|
+
if (!l) continue;
|
|
28
|
+
const i = o.includes(s), c = l.isEnabled !== !1;
|
|
29
|
+
i && !c && t.enablePlugin(s), !i && c && t.disablePlugin(s);
|
|
30
|
+
}
|
|
31
|
+
f = n;
|
|
32
|
+
},
|
|
33
|
+
destroy(t) {
|
|
34
|
+
for (const a of r) {
|
|
35
|
+
const n = t.getPlugin(a);
|
|
36
|
+
n && d.has(a) && n.isEnabled === !1 && t.enablePlugin(a);
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
|
-
|
|
40
|
+
e
|
|
37
41
|
);
|
|
38
42
|
};
|
|
39
43
|
export {
|
|
40
|
-
|
|
44
|
+
E as States
|
|
41
45
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.SupermouseStates={},u.SupermouseUtils))})(this,(function(u,l){"use strict";const g=t=>{const r=t.attribute??"data-supermouse-state",m=new Set(t.default),f=new Set;Object.values(t.states).forEach(e=>e.forEach(s=>f.add(s))),t.default.forEach(e=>f.add(e));let d="__UNINITIALIZED__";return l.definePlugin({name:"states",priority:-999,install(e){e.registerHoverTarget(`[${r}]`)},update(e){const s=e.state.hoverTarget;let n="default";if(s){const a=s.closest(`[${r}]`);if(a){const i=a.getAttribute(r);i&&t.states[i]&&(n=i)}}if(n===d)return;const S=n==="default"?t.default:t.states[n];for(const a of f){const i=e.getPlugin(a);if(!i)continue;const o=S.includes(a),c=i.isEnabled!==!1;o&&!c&&e.enablePlugin(a),!o&&c&&e.disablePlugin(a)}d=n},destroy(e){for(const s of f){const n=e.getPlugin(s);n&&m.has(s)&&n.isEnabled===!1&&e.enablePlugin(s)}}},t)};u.States=g,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/states",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "Logic controller that enables/disables other plugins based on hover attributes",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist",
|
|
9
10
|
"README.md"
|
|
@@ -12,13 +13,13 @@
|
|
|
12
13
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@supermousejs/utils": "2.
|
|
16
|
+
"@supermousejs/utils": "2.4.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@supermousejs/core": "2.
|
|
19
|
+
"@supermousejs/core": "2.4.0"
|
|
19
20
|
},
|
|
20
21
|
"peerDependencies": {
|
|
21
|
-
"@supermousejs/core": "2.
|
|
22
|
+
"@supermousejs/core": "2.4.0"
|
|
22
23
|
},
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|