@supermousejs/states 2.3.1 → 2.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @supermousejs/states
2
2
 
3
- Logic controller that enables/disables other plugins based on hover attributes. The plugin names listed in `default` and `states` must match the registered `plugin.name` values you use in your app.
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
- /** The default state (active when nothing else is hovered). */
17
+ /** Plugins active when no state attribute is hovered. */
9
18
  default: string[];
10
- /** Map of state names to lists of plugin names to enable. */
19
+ /** Map of state names to plugin names to enable. */
11
20
  states: Record<string, string[]>;
12
- /** CSS selector attribute to trigger state change. Default 'data-supermouse-state'. */
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 f } from "@supermousejs/utils";
2
- const v = (a) => {
3
- const r = a.attribute || "data-supermouse-state", i = /* @__PURE__ */ new Set(), u = new Set(a.default);
4
- Object.values(a.states).forEach((e) => {
5
- e.forEach((l) => i.add(l));
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(e) {
14
- e.registerHoverTarget(`[${r}]`);
10
+ install(t) {
11
+ t.registerHoverTarget(`[${u}]`);
15
12
  },
16
- update(e) {
17
- d || (i.forEach((t) => {
18
- u.has(t) || e.disablePlugin(t);
19
- }), u.forEach((t) => {
20
- e.enablePlugin(t);
21
- }), d = !0);
22
- const l = e.state.hoverTarget;
23
- let s = "default";
24
- if (l && l.hasAttribute(r)) {
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 (s !== c) {
29
- const t = s === "default" ? a.default : a.states[s];
30
- (/* @__PURE__ */ new Set([...u, ...i])).forEach((n) => {
31
- t.includes(n) ? e.enablePlugin(n) : e.disablePlugin(n);
32
- }), c = s;
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
- a
40
+ e
37
41
  );
38
42
  };
39
43
  export {
40
- v as States
44
+ E as States
41
45
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s.SupermouseStates={},s.SupermouseUtils))})(this,(function(s,i){"use strict";const h=u=>{const n=u.attribute||"data-supermouse-state",r=new Set,d=new Set(u.default);Object.values(u.states).forEach(t=>{t.forEach(a=>r.add(a))});let o="default",c=!1;return i.definePlugin({name:"states",priority:-999,install(t){t.registerHoverTarget(`[${n}]`)},update(t){c||(r.forEach(e=>{d.has(e)||t.disablePlugin(e)}),d.forEach(e=>{t.enablePlugin(e)}),c=!0);const a=t.state.hoverTarget;let l="default";if(a&&a.hasAttribute(n)){const e=a.getAttribute(n);e&&u.states[e]&&(l=e)}if(l!==o){const e=l==="default"?u.default:u.states[l];new Set([...d,...r]).forEach(f=>{e.includes(f)?t.enablePlugin(f):t.disablePlugin(f)}),o=l}}},u)};s.States=h,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
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.1",
3
+ "version": "2.4.1",
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,18 +13,18 @@
12
13
  "url": "https://github.com/Whitestar14/supermouse-js",
13
14
  "license": "MIT",
14
15
  "dependencies": {
15
- "@supermousejs/utils": "2.3.1"
16
+ "@supermousejs/utils": "2.4.1"
16
17
  },
17
18
  "devDependencies": {
18
- "@supermousejs/core": "2.3.0"
19
+ "@supermousejs/core": "2.4.1"
19
20
  },
20
21
  "peerDependencies": {
21
- "@supermousejs/core": "2.3.0"
22
+ "@supermousejs/core": "2.4.1"
22
23
  },
23
24
  "repository": {
24
25
  "type": "git",
25
26
  "url": "git+https://github.com/Whitestar14/supermouse-js.git",
26
- "directory": "packages/core"
27
+ "directory": "packages/states"
27
28
  },
28
29
  "bugs": {
29
30
  "url": "https://github.com/Whitestar14/supermouse-js/issues"