@zag-js/avatar 0.10.1 → 0.10.3

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.
@@ -1,6 +1,3 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
2
-
3
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "image" | "fallback">;
4
- declare const parts: Record<"root" | "image" | "fallback", _zag_js_anatomy.AnatomyPart>;
5
-
6
- export { anatomy, parts };
1
+ import type { AnatomyInstance, AnatomyPart } from '@zag-js/anatomy';
2
+ export declare const anatomy: AnatomyInstance<"image" | "root" | "fallback">;
3
+ export declare const parts: Record<"image" | "root" | "fallback", AnatomyPart>;
@@ -1,34 +1,11 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/avatar.anatomy.ts
21
- var avatar_anatomy_exports = {};
22
- __export(avatar_anatomy_exports, {
23
- anatomy: () => anatomy,
24
- parts: () => parts
25
- });
26
- module.exports = __toCommonJS(avatar_anatomy_exports);
27
- var import_anatomy = require("@zag-js/anatomy");
28
- var anatomy = (0, import_anatomy.createAnatomy)("avatar").parts("root", "image", "fallback");
29
- var parts = anatomy.build();
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- anatomy,
33
- parts
34
- });
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const anatomy$1 = require('@zag-js/anatomy');
6
+
7
+ const anatomy = anatomy$1.createAnatomy("avatar").parts("root", "image", "fallback");
8
+ const parts = anatomy.build();
9
+
10
+ exports.anatomy = anatomy;
11
+ exports.parts = parts;
@@ -1,8 +1,6 @@
1
- import {
2
- anatomy,
3
- parts
4
- } from "./chunk-LM2Q4YBK.mjs";
5
- export {
6
- anatomy,
7
- parts
8
- };
1
+ import { createAnatomy } from '@zag-js/anatomy';
2
+
3
+ const anatomy = createAnatomy("avatar").parts("root", "image", "fallback");
4
+ const parts = anatomy.build();
5
+
6
+ export { anatomy, parts };
@@ -1,8 +1,6 @@
1
- import { PropTypes, NormalizeProps } from '@zag-js/types';
2
- import { State, Send } from './avatar.types.js';
3
- import '@zag-js/core';
4
-
5
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
1
+ import { NormalizeProps, type PropTypes } from "@zag-js/types";
2
+ import { Send, State } from "./avatar.types";
3
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
6
4
  /**
7
5
  * Whether the image is loaded.
8
6
  */
@@ -27,5 +25,3 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
27
25
  imageProps: T["img"];
28
26
  fallbackProps: T["element"];
29
27
  };
30
-
31
- export { connect };
@@ -1,46 +1,11 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/avatar.connect.ts
21
- var avatar_connect_exports = {};
22
- __export(avatar_connect_exports, {
23
- connect: () => connect
24
- });
25
- module.exports = __toCommonJS(avatar_connect_exports);
26
- var import_dom_query2 = require("@zag-js/dom-query");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
27
4
 
28
- // src/avatar.anatomy.ts
29
- var import_anatomy = require("@zag-js/anatomy");
30
- var anatomy = (0, import_anatomy.createAnatomy)("avatar").parts("root", "image", "fallback");
31
- var parts = anatomy.build();
5
+ const domQuery = require('@zag-js/dom-query');
6
+ const avatar_anatomy = require('./avatar.anatomy.js');
7
+ const avatar_dom = require('./avatar.dom.js');
32
8
 
33
- // src/avatar.dom.ts
34
- var import_dom_query = require("@zag-js/dom-query");
35
- var dom = (0, import_dom_query.createScope)({
36
- getRootId: (ctx) => `avatar:${ctx.id}`,
37
- getImageId: (ctx) => `avatar:${ctx.id}:image`,
38
- getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
39
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
40
- getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
41
- });
42
-
43
- // src/avatar.connect.ts
44
9
  function connect(state, send, normalize) {
45
10
  const isLoaded = state.matches("loaded");
46
11
  const showFallback = !isLoaded;
@@ -72,8 +37,8 @@ function connect(state, send, normalize) {
72
37
  send({ type: "IMG.ERROR", src: "api" });
73
38
  },
74
39
  rootProps: normalize.element({
75
- ...parts.root.attrs,
76
- id: dom.getRootId(state.context),
40
+ ...avatar_anatomy.parts.root.attrs,
41
+ id: avatar_dom.dom.getRootId(state.context),
77
42
  style: {
78
43
  display: "grid",
79
44
  gridTemplateRows: "1fr 1fr",
@@ -81,9 +46,9 @@ function connect(state, send, normalize) {
81
46
  }
82
47
  }),
83
48
  imageProps: normalize.img({
84
- ...parts.image.attrs,
85
- id: dom.getImageId(state.context),
86
- "data-loaded": (0, import_dom_query2.dataAttr)(isLoaded),
49
+ ...avatar_anatomy.parts.image.attrs,
50
+ id: avatar_dom.dom.getImageId(state.context),
51
+ "data-loaded": domQuery.dataAttr(isLoaded),
87
52
  onLoad() {
88
53
  send({ type: "IMG.LOADED", src: "element" });
89
54
  },
@@ -96,8 +61,8 @@ function connect(state, send, normalize) {
96
61
  }
97
62
  }),
98
63
  fallbackProps: normalize.element({
99
- ...parts.fallback.attrs,
100
- id: dom.getFallbackId(state.context),
64
+ ...avatar_anatomy.parts.fallback.attrs,
65
+ id: avatar_dom.dom.getFallbackId(state.context),
101
66
  hidden: !showFallback,
102
67
  style: {
103
68
  gridArea: "1 / 1 / 2 / 2"
@@ -105,7 +70,5 @@ function connect(state, send, normalize) {
105
70
  })
106
71
  };
107
72
  }
108
- // Annotate the CommonJS export names for ESM import in node:
109
- 0 && (module.exports = {
110
- connect
111
- });
73
+
74
+ exports.connect = connect;
@@ -1,8 +1,70 @@
1
- import {
2
- connect
3
- } from "./chunk-KGWU4KVZ.mjs";
4
- import "./chunk-LM2Q4YBK.mjs";
5
- import "./chunk-ORAGSSGY.mjs";
6
- export {
7
- connect
8
- };
1
+ import { dataAttr } from '@zag-js/dom-query';
2
+ import { parts } from './avatar.anatomy.mjs';
3
+ import { dom } from './avatar.dom.mjs';
4
+
5
+ function connect(state, send, normalize) {
6
+ const isLoaded = state.matches("loaded");
7
+ const showFallback = !isLoaded;
8
+ return {
9
+ /**
10
+ * Whether the image is loaded.
11
+ */
12
+ isLoaded,
13
+ /**
14
+ * Whether the fallback is shown.
15
+ */
16
+ showFallback,
17
+ /**
18
+ * Function to set new src.
19
+ */
20
+ setSrc(src) {
21
+ send({ type: "SRC.SET", src });
22
+ },
23
+ /**
24
+ * Function to set loaded state.
25
+ */
26
+ setLoaded() {
27
+ send({ type: "IMG.LOADED", src: "api" });
28
+ },
29
+ /**
30
+ * Function to set error state.
31
+ */
32
+ setError() {
33
+ send({ type: "IMG.ERROR", src: "api" });
34
+ },
35
+ rootProps: normalize.element({
36
+ ...parts.root.attrs,
37
+ id: dom.getRootId(state.context),
38
+ style: {
39
+ display: "grid",
40
+ gridTemplateRows: "1fr 1fr",
41
+ overflow: "hidden"
42
+ }
43
+ }),
44
+ imageProps: normalize.img({
45
+ ...parts.image.attrs,
46
+ id: dom.getImageId(state.context),
47
+ "data-loaded": dataAttr(isLoaded),
48
+ onLoad() {
49
+ send({ type: "IMG.LOADED", src: "element" });
50
+ },
51
+ onError() {
52
+ send({ type: "IMG.ERROR", src: "element" });
53
+ },
54
+ style: {
55
+ gridArea: "1 / 1 / 2 / 2",
56
+ visibility: !isLoaded ? "hidden" : void 0
57
+ }
58
+ }),
59
+ fallbackProps: normalize.element({
60
+ ...parts.fallback.attrs,
61
+ id: dom.getFallbackId(state.context),
62
+ hidden: !showFallback,
63
+ style: {
64
+ gridArea: "1 / 1 / 2 / 2"
65
+ }
66
+ })
67
+ };
68
+ }
69
+
70
+ export { connect };
@@ -1,32 +1,27 @@
1
- import { MachineContext } from './avatar.types.js';
2
- import '@zag-js/core';
3
- import '@zag-js/types';
4
-
5
- declare const dom: {
1
+ import type { MachineContext as Ctx } from "./avatar.types";
2
+ export declare const dom: {
6
3
  getRootNode: (ctx: {
7
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
8
- }) => Document | ShadowRoot;
4
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
5
+ }) => ShadowRoot | Document;
9
6
  getDoc: (ctx: {
10
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
7
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
11
8
  }) => Document;
12
9
  getWin: (ctx: {
13
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
10
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
14
11
  }) => Window & typeof globalThis;
15
12
  getActiveElement: (ctx: {
16
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
13
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
17
14
  }) => HTMLElement | null;
18
15
  getById: <T extends HTMLElement = HTMLElement>(ctx: {
19
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
16
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
20
17
  }, id: string) => T | null;
21
18
  queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
22
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
19
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
23
20
  }, id: string) => T_1;
24
21
  } & {
25
- getRootId: (ctx: MachineContext) => string;
26
- getImageId: (ctx: MachineContext) => string;
27
- getFallbackId: (ctx: MachineContext) => string;
28
- getRootEl: (ctx: MachineContext) => HTMLElement | null;
29
- getImageEl: (ctx: MachineContext) => HTMLImageElement | null;
22
+ getRootId: (ctx: Ctx) => string;
23
+ getImageId: (ctx: Ctx) => string;
24
+ getFallbackId: (ctx: Ctx) => string;
25
+ getRootEl: (ctx: Ctx) => HTMLElement | null;
26
+ getImageEl: (ctx: Ctx) => HTMLImageElement | null;
30
27
  };
31
-
32
- export { dom };
@@ -1,37 +1,15 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/avatar.dom.ts
21
- var avatar_dom_exports = {};
22
- __export(avatar_dom_exports, {
23
- dom: () => dom
24
- });
25
- module.exports = __toCommonJS(avatar_dom_exports);
26
- var import_dom_query = require("@zag-js/dom-query");
27
- var dom = (0, import_dom_query.createScope)({
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const domQuery = require('@zag-js/dom-query');
6
+
7
+ const dom = domQuery.createScope({
28
8
  getRootId: (ctx) => `avatar:${ctx.id}`,
29
9
  getImageId: (ctx) => `avatar:${ctx.id}:image`,
30
10
  getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
31
11
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
32
12
  getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
33
13
  });
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- dom
37
- });
14
+
15
+ exports.dom = dom;
@@ -1,6 +1,11 @@
1
- import {
2
- dom
3
- } from "./chunk-ORAGSSGY.mjs";
4
- export {
5
- dom
6
- };
1
+ import { createScope } from '@zag-js/dom-query';
2
+
3
+ const dom = createScope({
4
+ getRootId: (ctx) => `avatar:${ctx.id}`,
5
+ getImageId: (ctx) => `avatar:${ctx.id}:image`,
6
+ getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
7
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
8
+ getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
9
+ });
10
+
11
+ export { dom };
@@ -1,7 +1,3 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { UserDefinedContext, MachineContext, MachineState } from './avatar.types.js';
3
- import '@zag-js/types';
4
-
5
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
6
-
7
- export { machine };
1
+ import type { Machine, StateMachine } from '@zag-js/core';
2
+ import { MachineContext, MachineState, UserDefinedContext } from "./avatar.types";
3
+ export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
@@ -1,46 +1,15 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/avatar.machine.ts
21
- var avatar_machine_exports = {};
22
- __export(avatar_machine_exports, {
23
- machine: () => machine
24
- });
25
- module.exports = __toCommonJS(avatar_machine_exports);
26
- var import_core = require("@zag-js/core");
27
- var import_utils = require("@zag-js/utils");
28
- var import_mutation_observer = require("@zag-js/mutation-observer");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
29
4
 
30
- // src/avatar.dom.ts
31
- var import_dom_query = require("@zag-js/dom-query");
32
- var dom = (0, import_dom_query.createScope)({
33
- getRootId: (ctx) => `avatar:${ctx.id}`,
34
- getImageId: (ctx) => `avatar:${ctx.id}:image`,
35
- getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
36
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
37
- getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
38
- });
5
+ const core = require('@zag-js/core');
6
+ const utils = require('@zag-js/utils');
7
+ const mutationObserver = require('@zag-js/mutation-observer');
8
+ const avatar_dom = require('./avatar.dom.js');
39
9
 
40
- // src/avatar.machine.ts
41
10
  function machine(userContext) {
42
- const ctx = (0, import_utils.compact)(userContext);
43
- return (0, import_core.createMachine)(
11
+ const ctx = utils.compact(userContext);
12
+ return core.createMachine(
44
13
  {
45
14
  id: "avatar",
46
15
  initial: "loading",
@@ -86,14 +55,14 @@ function machine(userContext) {
86
55
  {
87
56
  activities: {
88
57
  trackSrcChange(ctx2, _evt, { send }) {
89
- const img = dom.getImageEl(ctx2);
90
- return (0, import_mutation_observer.observeAttributes)(img, ["src", "srcset"], () => {
58
+ const img = avatar_dom.dom.getImageEl(ctx2);
59
+ return mutationObserver.observeAttributes(img, ["src", "srcset"], () => {
91
60
  send({ type: "SRC.CHANGE" });
92
61
  });
93
62
  },
94
63
  trackImageRemoval(ctx2, _evt, { send }) {
95
- const rootEl = dom.getRootEl(ctx2);
96
- return (0, import_mutation_observer.observeChildren)(rootEl, (records) => {
64
+ const rootEl = avatar_dom.dom.getRootEl(ctx2);
65
+ return mutationObserver.observeChildren(rootEl, (records) => {
97
66
  const removedNodes = Array.from(records[0].removedNodes);
98
67
  const removed = removedNodes.find((node) => node.matches("[data-scope=avatar][data-part=image]"));
99
68
  if (removed) {
@@ -110,7 +79,7 @@ function machine(userContext) {
110
79
  ctx2.onError?.();
111
80
  },
112
81
  checkImgStatus(ctx2, _evt, { send }) {
113
- const img = dom.getImageEl(ctx2);
82
+ const img = avatar_dom.dom.getImageEl(ctx2);
114
83
  if (img?.complete) {
115
84
  send({ type: "IMG.LOADED", src: "ssr" });
116
85
  }
@@ -119,7 +88,5 @@ function machine(userContext) {
119
88
  }
120
89
  );
121
90
  }
122
- // Annotate the CommonJS export names for ESM import in node:
123
- 0 && (module.exports = {
124
- machine
125
- });
91
+
92
+ exports.machine = machine;
@@ -1,7 +1,88 @@
1
- import {
2
- machine
3
- } from "./chunk-SKBVPI7R.mjs";
4
- import "./chunk-ORAGSSGY.mjs";
5
- export {
6
- machine
7
- };
1
+ import { createMachine } from '@zag-js/core';
2
+ import { compact } from '@zag-js/utils';
3
+ import { observeAttributes, observeChildren } from '@zag-js/mutation-observer';
4
+ import { dom } from './avatar.dom.mjs';
5
+
6
+ function machine(userContext) {
7
+ const ctx = compact(userContext);
8
+ return createMachine(
9
+ {
10
+ id: "avatar",
11
+ initial: "loading",
12
+ activities: ["trackImageRemoval"],
13
+ context: ctx,
14
+ on: {
15
+ "SRC.CHANGE": {
16
+ target: "loading"
17
+ },
18
+ "IMG.UNMOUNT": {
19
+ target: "error"
20
+ }
21
+ },
22
+ states: {
23
+ loading: {
24
+ activities: ["trackSrcChange"],
25
+ entry: ["checkImgStatus"],
26
+ on: {
27
+ "IMG.LOADED": {
28
+ target: "loaded",
29
+ actions: ["invokeOnLoad"]
30
+ },
31
+ "IMG.ERROR": {
32
+ target: "error",
33
+ actions: ["invokeOnError"]
34
+ }
35
+ }
36
+ },
37
+ error: {
38
+ activities: ["trackSrcChange"],
39
+ on: {
40
+ "IMG.LOADED": {
41
+ target: "loaded",
42
+ actions: ["invokeOnLoad"]
43
+ }
44
+ }
45
+ },
46
+ loaded: {
47
+ activities: ["trackSrcChange"]
48
+ }
49
+ }
50
+ },
51
+ {
52
+ activities: {
53
+ trackSrcChange(ctx2, _evt, { send }) {
54
+ const img = dom.getImageEl(ctx2);
55
+ return observeAttributes(img, ["src", "srcset"], () => {
56
+ send({ type: "SRC.CHANGE" });
57
+ });
58
+ },
59
+ trackImageRemoval(ctx2, _evt, { send }) {
60
+ const rootEl = dom.getRootEl(ctx2);
61
+ return observeChildren(rootEl, (records) => {
62
+ const removedNodes = Array.from(records[0].removedNodes);
63
+ const removed = removedNodes.find((node) => node.matches("[data-scope=avatar][data-part=image]"));
64
+ if (removed) {
65
+ send({ type: "IMG.UNMOUNT" });
66
+ }
67
+ });
68
+ }
69
+ },
70
+ actions: {
71
+ invokeOnLoad(ctx2) {
72
+ ctx2.onLoad?.();
73
+ },
74
+ invokeOnError(ctx2) {
75
+ ctx2.onError?.();
76
+ },
77
+ checkImgStatus(ctx2, _evt, { send }) {
78
+ const img = dom.getImageEl(ctx2);
79
+ if (img?.complete) {
80
+ send({ type: "IMG.LOADED", src: "ssr" });
81
+ }
82
+ }
83
+ }
84
+ }
85
+ );
86
+ }
87
+
88
+ export { machine };
@@ -1,18 +1,16 @@
1
- import { StateMachine } from '@zag-js/core';
2
- import { RequiredBy, CommonProperties, Context } from '@zag-js/types';
3
-
1
+ import type { StateMachine as S } from "@zag-js/core";
2
+ import type { CommonProperties, Context, RequiredBy } from "@zag-js/types";
4
3
  type PublicContext = CommonProperties & {
5
4
  onLoad?: () => void;
6
5
  onError?: () => void;
7
6
  };
8
7
  type PrivateContext = Context<{}>;
9
8
  type ComputedContext = Readonly<{}>;
10
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
11
- type MachineContext = PublicContext & PrivateContext & ComputedContext;
12
- type MachineState = {
9
+ export type UserDefinedContext = RequiredBy<PublicContext, "id">;
10
+ export type MachineContext = PublicContext & PrivateContext & ComputedContext;
11
+ export type MachineState = {
13
12
  value: "loading" | "error" | "loaded";
14
13
  };
15
- type State = StateMachine.State<MachineContext, MachineState>;
16
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
17
-
18
- export { MachineContext, MachineState, Send, State, UserDefinedContext };
14
+ export type State = S.State<MachineContext, MachineState>;
15
+ export type Send = S.Send<S.AnyEventObject>;
16
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { connect } from './avatar.connect.js';
2
- export { machine } from './avatar.machine.js';
3
- export { UserDefinedContext as Context } from './avatar.types.js';
4
- import '@zag-js/types';
5
- import '@zag-js/core';
1
+ export { anatomy } from "./avatar.anatomy";
2
+ export { connect } from "./avatar.connect";
3
+ export { machine } from "./avatar.machine";
4
+ export type { UserDefinedContext as Context } from "./avatar.types";
package/dist/index.js CHANGED
@@ -1,201 +1,13 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- connect: () => connect,
24
- machine: () => machine
25
- });
26
- module.exports = __toCommonJS(src_exports);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
27
4
 
28
- // src/avatar.connect.ts
29
- var import_dom_query2 = require("@zag-js/dom-query");
5
+ const avatar_anatomy = require('./avatar.anatomy.js');
6
+ const avatar_connect = require('./avatar.connect.js');
7
+ const avatar_machine = require('./avatar.machine.js');
30
8
 
31
- // src/avatar.anatomy.ts
32
- var import_anatomy = require("@zag-js/anatomy");
33
- var anatomy = (0, import_anatomy.createAnatomy)("avatar").parts("root", "image", "fallback");
34
- var parts = anatomy.build();
35
9
 
36
- // src/avatar.dom.ts
37
- var import_dom_query = require("@zag-js/dom-query");
38
- var dom = (0, import_dom_query.createScope)({
39
- getRootId: (ctx) => `avatar:${ctx.id}`,
40
- getImageId: (ctx) => `avatar:${ctx.id}:image`,
41
- getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
42
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
43
- getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
44
- });
45
10
 
46
- // src/avatar.connect.ts
47
- function connect(state, send, normalize) {
48
- const isLoaded = state.matches("loaded");
49
- const showFallback = !isLoaded;
50
- return {
51
- /**
52
- * Whether the image is loaded.
53
- */
54
- isLoaded,
55
- /**
56
- * Whether the fallback is shown.
57
- */
58
- showFallback,
59
- /**
60
- * Function to set new src.
61
- */
62
- setSrc(src) {
63
- send({ type: "SRC.SET", src });
64
- },
65
- /**
66
- * Function to set loaded state.
67
- */
68
- setLoaded() {
69
- send({ type: "IMG.LOADED", src: "api" });
70
- },
71
- /**
72
- * Function to set error state.
73
- */
74
- setError() {
75
- send({ type: "IMG.ERROR", src: "api" });
76
- },
77
- rootProps: normalize.element({
78
- ...parts.root.attrs,
79
- id: dom.getRootId(state.context),
80
- style: {
81
- display: "grid",
82
- gridTemplateRows: "1fr 1fr",
83
- overflow: "hidden"
84
- }
85
- }),
86
- imageProps: normalize.img({
87
- ...parts.image.attrs,
88
- id: dom.getImageId(state.context),
89
- "data-loaded": (0, import_dom_query2.dataAttr)(isLoaded),
90
- onLoad() {
91
- send({ type: "IMG.LOADED", src: "element" });
92
- },
93
- onError() {
94
- send({ type: "IMG.ERROR", src: "element" });
95
- },
96
- style: {
97
- gridArea: "1 / 1 / 2 / 2",
98
- visibility: !isLoaded ? "hidden" : void 0
99
- }
100
- }),
101
- fallbackProps: normalize.element({
102
- ...parts.fallback.attrs,
103
- id: dom.getFallbackId(state.context),
104
- hidden: !showFallback,
105
- style: {
106
- gridArea: "1 / 1 / 2 / 2"
107
- }
108
- })
109
- };
110
- }
111
-
112
- // src/avatar.machine.ts
113
- var import_core = require("@zag-js/core");
114
- var import_utils = require("@zag-js/utils");
115
- var import_mutation_observer = require("@zag-js/mutation-observer");
116
- function machine(userContext) {
117
- const ctx = (0, import_utils.compact)(userContext);
118
- return (0, import_core.createMachine)(
119
- {
120
- id: "avatar",
121
- initial: "loading",
122
- activities: ["trackImageRemoval"],
123
- context: ctx,
124
- on: {
125
- "SRC.CHANGE": {
126
- target: "loading"
127
- },
128
- "IMG.UNMOUNT": {
129
- target: "error"
130
- }
131
- },
132
- states: {
133
- loading: {
134
- activities: ["trackSrcChange"],
135
- entry: ["checkImgStatus"],
136
- on: {
137
- "IMG.LOADED": {
138
- target: "loaded",
139
- actions: ["invokeOnLoad"]
140
- },
141
- "IMG.ERROR": {
142
- target: "error",
143
- actions: ["invokeOnError"]
144
- }
145
- }
146
- },
147
- error: {
148
- activities: ["trackSrcChange"],
149
- on: {
150
- "IMG.LOADED": {
151
- target: "loaded",
152
- actions: ["invokeOnLoad"]
153
- }
154
- }
155
- },
156
- loaded: {
157
- activities: ["trackSrcChange"]
158
- }
159
- }
160
- },
161
- {
162
- activities: {
163
- trackSrcChange(ctx2, _evt, { send }) {
164
- const img = dom.getImageEl(ctx2);
165
- return (0, import_mutation_observer.observeAttributes)(img, ["src", "srcset"], () => {
166
- send({ type: "SRC.CHANGE" });
167
- });
168
- },
169
- trackImageRemoval(ctx2, _evt, { send }) {
170
- const rootEl = dom.getRootEl(ctx2);
171
- return (0, import_mutation_observer.observeChildren)(rootEl, (records) => {
172
- const removedNodes = Array.from(records[0].removedNodes);
173
- const removed = removedNodes.find((node) => node.matches("[data-scope=avatar][data-part=image]"));
174
- if (removed) {
175
- send({ type: "IMG.UNMOUNT" });
176
- }
177
- });
178
- }
179
- },
180
- actions: {
181
- invokeOnLoad(ctx2) {
182
- ctx2.onLoad?.();
183
- },
184
- invokeOnError(ctx2) {
185
- ctx2.onError?.();
186
- },
187
- checkImgStatus(ctx2, _evt, { send }) {
188
- const img = dom.getImageEl(ctx2);
189
- if (img?.complete) {
190
- send({ type: "IMG.LOADED", src: "ssr" });
191
- }
192
- }
193
- }
194
- }
195
- );
196
- }
197
- // Annotate the CommonJS export names for ESM import in node:
198
- 0 && (module.exports = {
199
- connect,
200
- machine
201
- });
11
+ exports.anatomy = avatar_anatomy.anatomy;
12
+ exports.connect = avatar_connect.connect;
13
+ exports.machine = avatar_machine.machine;
package/dist/index.mjs CHANGED
@@ -1,12 +1,3 @@
1
- import {
2
- connect
3
- } from "./chunk-KGWU4KVZ.mjs";
4
- import "./chunk-LM2Q4YBK.mjs";
5
- import {
6
- machine
7
- } from "./chunk-SKBVPI7R.mjs";
8
- import "./chunk-ORAGSSGY.mjs";
9
- export {
10
- connect,
11
- machine
12
- };
1
+ export { anatomy } from './avatar.anatomy.mjs';
2
+ export { connect } from './avatar.connect.mjs';
3
+ export { machine } from './avatar.machine.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/avatar",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Core logic for the avatar widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -28,12 +28,12 @@
28
28
  "url": "https://github.com/chakra-ui/zag/issues"
29
29
  },
30
30
  "dependencies": {
31
- "@zag-js/anatomy": "0.10.1",
32
- "@zag-js/mutation-observer": "0.10.1",
33
- "@zag-js/core": "0.10.1",
34
- "@zag-js/dom-query": "0.10.1",
35
- "@zag-js/utils": "0.10.1",
36
- "@zag-js/types": "0.10.1"
31
+ "@zag-js/anatomy": "0.10.3",
32
+ "@zag-js/mutation-observer": "0.10.3",
33
+ "@zag-js/core": "0.10.3",
34
+ "@zag-js/dom-query": "0.10.3",
35
+ "@zag-js/utils": "0.10.3",
36
+ "@zag-js/types": "0.10.3"
37
37
  },
38
38
  "devDependencies": {
39
39
  "clean-package": "2.2.0"
@@ -50,13 +50,8 @@
50
50
  "./package.json": "./package.json"
51
51
  },
52
52
  "scripts": {
53
- "build-fast": "tsup src",
54
- "start": "pnpm build --watch",
55
- "build": "tsup src --dts",
56
- "test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
53
+ "build": "vite build -c ../../../vite.config.ts",
57
54
  "lint": "eslint src --ext .ts,.tsx",
58
- "test-ci": "pnpm test --ci --runInBand",
59
- "test-watch": "pnpm test --watch -u",
60
55
  "typecheck": "tsc --noEmit"
61
56
  }
62
57
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { anatomy } from "./avatar.anatomy"
1
2
  export { connect } from "./avatar.connect"
2
3
  export { machine } from "./avatar.machine"
3
4
  export type { UserDefinedContext as Context } from "./avatar.types"
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/avatar.types.ts
17
- var avatar_types_exports = {};
18
- module.exports = __toCommonJS(avatar_types_exports);
File without changes
@@ -1,77 +0,0 @@
1
- import {
2
- parts
3
- } from "./chunk-LM2Q4YBK.mjs";
4
- import {
5
- dom
6
- } from "./chunk-ORAGSSGY.mjs";
7
-
8
- // src/avatar.connect.ts
9
- import { dataAttr } from "@zag-js/dom-query";
10
- function connect(state, send, normalize) {
11
- const isLoaded = state.matches("loaded");
12
- const showFallback = !isLoaded;
13
- return {
14
- /**
15
- * Whether the image is loaded.
16
- */
17
- isLoaded,
18
- /**
19
- * Whether the fallback is shown.
20
- */
21
- showFallback,
22
- /**
23
- * Function to set new src.
24
- */
25
- setSrc(src) {
26
- send({ type: "SRC.SET", src });
27
- },
28
- /**
29
- * Function to set loaded state.
30
- */
31
- setLoaded() {
32
- send({ type: "IMG.LOADED", src: "api" });
33
- },
34
- /**
35
- * Function to set error state.
36
- */
37
- setError() {
38
- send({ type: "IMG.ERROR", src: "api" });
39
- },
40
- rootProps: normalize.element({
41
- ...parts.root.attrs,
42
- id: dom.getRootId(state.context),
43
- style: {
44
- display: "grid",
45
- gridTemplateRows: "1fr 1fr",
46
- overflow: "hidden"
47
- }
48
- }),
49
- imageProps: normalize.img({
50
- ...parts.image.attrs,
51
- id: dom.getImageId(state.context),
52
- "data-loaded": dataAttr(isLoaded),
53
- onLoad() {
54
- send({ type: "IMG.LOADED", src: "element" });
55
- },
56
- onError() {
57
- send({ type: "IMG.ERROR", src: "element" });
58
- },
59
- style: {
60
- gridArea: "1 / 1 / 2 / 2",
61
- visibility: !isLoaded ? "hidden" : void 0
62
- }
63
- }),
64
- fallbackProps: normalize.element({
65
- ...parts.fallback.attrs,
66
- id: dom.getFallbackId(state.context),
67
- hidden: !showFallback,
68
- style: {
69
- gridArea: "1 / 1 / 2 / 2"
70
- }
71
- })
72
- };
73
- }
74
-
75
- export {
76
- connect
77
- };
@@ -1,9 +0,0 @@
1
- // src/avatar.anatomy.ts
2
- import { createAnatomy } from "@zag-js/anatomy";
3
- var anatomy = createAnatomy("avatar").parts("root", "image", "fallback");
4
- var parts = anatomy.build();
5
-
6
- export {
7
- anatomy,
8
- parts
9
- };
@@ -1,13 +0,0 @@
1
- // src/avatar.dom.ts
2
- import { createScope } from "@zag-js/dom-query";
3
- var dom = createScope({
4
- getRootId: (ctx) => `avatar:${ctx.id}`,
5
- getImageId: (ctx) => `avatar:${ctx.id}:image`,
6
- getFallbackId: (ctx) => `avatar:${ctx.id}:fallback`,
7
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
8
- getImageEl: (ctx) => dom.getById(ctx, dom.getImageId(ctx))
9
- });
10
-
11
- export {
12
- dom
13
- };
@@ -1,93 +0,0 @@
1
- import {
2
- dom
3
- } from "./chunk-ORAGSSGY.mjs";
4
-
5
- // src/avatar.machine.ts
6
- import { createMachine } from "@zag-js/core";
7
- import { compact } from "@zag-js/utils";
8
- import { observeAttributes, observeChildren } from "@zag-js/mutation-observer";
9
- function machine(userContext) {
10
- const ctx = compact(userContext);
11
- return createMachine(
12
- {
13
- id: "avatar",
14
- initial: "loading",
15
- activities: ["trackImageRemoval"],
16
- context: ctx,
17
- on: {
18
- "SRC.CHANGE": {
19
- target: "loading"
20
- },
21
- "IMG.UNMOUNT": {
22
- target: "error"
23
- }
24
- },
25
- states: {
26
- loading: {
27
- activities: ["trackSrcChange"],
28
- entry: ["checkImgStatus"],
29
- on: {
30
- "IMG.LOADED": {
31
- target: "loaded",
32
- actions: ["invokeOnLoad"]
33
- },
34
- "IMG.ERROR": {
35
- target: "error",
36
- actions: ["invokeOnError"]
37
- }
38
- }
39
- },
40
- error: {
41
- activities: ["trackSrcChange"],
42
- on: {
43
- "IMG.LOADED": {
44
- target: "loaded",
45
- actions: ["invokeOnLoad"]
46
- }
47
- }
48
- },
49
- loaded: {
50
- activities: ["trackSrcChange"]
51
- }
52
- }
53
- },
54
- {
55
- activities: {
56
- trackSrcChange(ctx2, _evt, { send }) {
57
- const img = dom.getImageEl(ctx2);
58
- return observeAttributes(img, ["src", "srcset"], () => {
59
- send({ type: "SRC.CHANGE" });
60
- });
61
- },
62
- trackImageRemoval(ctx2, _evt, { send }) {
63
- const rootEl = dom.getRootEl(ctx2);
64
- return observeChildren(rootEl, (records) => {
65
- const removedNodes = Array.from(records[0].removedNodes);
66
- const removed = removedNodes.find((node) => node.matches("[data-scope=avatar][data-part=image]"));
67
- if (removed) {
68
- send({ type: "IMG.UNMOUNT" });
69
- }
70
- });
71
- }
72
- },
73
- actions: {
74
- invokeOnLoad(ctx2) {
75
- ctx2.onLoad?.();
76
- },
77
- invokeOnError(ctx2) {
78
- ctx2.onError?.();
79
- },
80
- checkImgStatus(ctx2, _evt, { send }) {
81
- const img = dom.getImageEl(ctx2);
82
- if (img?.complete) {
83
- send({ type: "IMG.LOADED", src: "ssr" });
84
- }
85
- }
86
- }
87
- }
88
- );
89
- }
90
-
91
- export {
92
- machine
93
- };