@zag-js/carousel
Advanced tools
Comparing version 0.0.0-dev-20230221113221 to 0.0.0-dev-20230222120620
@@ -26,47 +26,4 @@ "use strict"; | ||
module.exports = __toCommonJS(carousel_connect_exports); | ||
var import_dom_query2 = require("@zag-js/dom-query"); | ||
// ../../utilities/dom/src/attrs.ts | ||
var dataAttr = (guard) => { | ||
return guard ? "" : void 0; | ||
}; | ||
// ../../utilities/dom/src/query.ts | ||
function isDocument(el) { | ||
return el.nodeType === Node.DOCUMENT_NODE; | ||
} | ||
function isWindow(value) { | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
if (isWindow(el)) | ||
return el.document; | ||
if (isDocument(el)) | ||
return el; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function defineDomHelpers(helpers) { | ||
const dom2 = { | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)), | ||
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement, | ||
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id), | ||
queryById: (ctx, id) => { | ||
const el = dom2.getById(ctx, id); | ||
if (!el) | ||
throw new Error(`Element with id "${id}" not found.`); | ||
return el; | ||
} | ||
}; | ||
return { | ||
...dom2, | ||
...helpers | ||
}; | ||
} | ||
// ../../utilities/dom/src/nodelist.ts | ||
function queryAll(root, selector) { | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
// src/carousel.anatomy.ts | ||
@@ -87,3 +44,4 @@ var import_anatomy = require("@zag-js/anatomy"); | ||
// src/carousel.dom.ts | ||
var dom = defineDomHelpers({ | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
getRootId: (ctx) => `carousel:${ctx.id}`, | ||
@@ -96,3 +54,3 @@ getViewportId: (ctx) => `carousel:${ctx.id}:viewport`, | ||
getSlideGroupEl: (ctx) => dom.queryById(ctx, dom.getSlideGroupId(ctx)), | ||
getSlideEls: (ctx) => queryAll(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
getSlideEls: (ctx) => (0, import_dom_query.queryAll)(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
}); | ||
@@ -169,3 +127,3 @@ | ||
id: dom.getSlideId(state.context, index), | ||
"data-current": dataAttr(sliderState.isCurrent), | ||
"data-current": (0, import_dom_query2.dataAttr)(sliderState.isCurrent), | ||
role: "group", | ||
@@ -172,0 +130,0 @@ "aria-roledescription": "slide", |
@@ -18,6 +18,6 @@ import { MachineContext } from './carousel.types.js'; | ||
}) => HTMLElement | null; | ||
getById: <T = HTMLElement>(ctx: { | ||
getById: <T extends HTMLElement = HTMLElement>(ctx: { | ||
getRootNode?: (() => Node | Document | ShadowRoot) | undefined; | ||
}, id: string) => T | null; | ||
queryById: <T_1 = HTMLElement>(ctx: { | ||
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: { | ||
getRootNode?: (() => Node | Document | ShadowRoot) | undefined; | ||
@@ -24,0 +24,0 @@ }, id: string) => T_1; |
@@ -26,44 +26,4 @@ "use strict"; | ||
module.exports = __toCommonJS(carousel_dom_exports); | ||
// ../../utilities/dom/src/query.ts | ||
function isDocument(el) { | ||
return el.nodeType === Node.DOCUMENT_NODE; | ||
} | ||
function isWindow(value) { | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
if (isWindow(el)) | ||
return el.document; | ||
if (isDocument(el)) | ||
return el; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function defineDomHelpers(helpers) { | ||
const dom2 = { | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)), | ||
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement, | ||
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id), | ||
queryById: (ctx, id) => { | ||
const el = dom2.getById(ctx, id); | ||
if (!el) | ||
throw new Error(`Element with id "${id}" not found.`); | ||
return el; | ||
} | ||
}; | ||
return { | ||
...dom2, | ||
...helpers | ||
}; | ||
} | ||
// ../../utilities/dom/src/nodelist.ts | ||
function queryAll(root, selector) { | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
// src/carousel.dom.ts | ||
var dom = defineDomHelpers({ | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
getRootId: (ctx) => `carousel:${ctx.id}`, | ||
@@ -76,3 +36,3 @@ getViewportId: (ctx) => `carousel:${ctx.id}:viewport`, | ||
getSlideGroupEl: (ctx) => dom.queryById(ctx, dom.getSlideGroupId(ctx)), | ||
getSlideEls: (ctx) => queryAll(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
getSlideEls: (ctx) => (0, import_dom_query.queryAll)(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
}); | ||
@@ -79,0 +39,0 @@ // Annotate the CommonJS export names for ESM import in node: |
@@ -27,76 +27,7 @@ "use strict"; | ||
var import_core = require("@zag-js/core"); | ||
var import_utils = require("@zag-js/utils"); | ||
// ../../utilities/core/src/array.ts | ||
function nextIndex(v, idx, opts = {}) { | ||
const { step = 1, loop = true } = opts; | ||
const next = idx + step; | ||
const len = v.length; | ||
const last = len - 1; | ||
if (idx === -1) | ||
return step > 0 ? 0 : last; | ||
if (next < 0) | ||
return loop ? last : 0; | ||
if (next >= len) | ||
return loop ? 0 : idx > len ? len : idx; | ||
return next; | ||
} | ||
function prevIndex(v, idx, opts = {}) { | ||
const { step = 1, loop = true } = opts; | ||
return nextIndex(v, idx, { step: -step, loop }); | ||
} | ||
// ../../utilities/core/src/guard.ts | ||
var isArray = (v) => Array.isArray(v); | ||
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v)); | ||
// ../../utilities/core/src/object.ts | ||
function compact(obj) { | ||
if (obj === void 0) | ||
return obj; | ||
return Object.fromEntries( | ||
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value]) | ||
); | ||
} | ||
// ../../utilities/dom/src/query.ts | ||
function isDocument(el) { | ||
return el.nodeType === Node.DOCUMENT_NODE; | ||
} | ||
function isWindow(value) { | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
if (isWindow(el)) | ||
return el.document; | ||
if (isDocument(el)) | ||
return el; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function defineDomHelpers(helpers) { | ||
const dom2 = { | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)), | ||
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement, | ||
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id), | ||
queryById: (ctx, id) => { | ||
const el = dom2.getById(ctx, id); | ||
if (!el) | ||
throw new Error(`Element with id "${id}" not found.`); | ||
return el; | ||
} | ||
}; | ||
return { | ||
...dom2, | ||
...helpers | ||
}; | ||
} | ||
// ../../utilities/dom/src/nodelist.ts | ||
function queryAll(root, selector) { | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
// src/carousel.dom.ts | ||
var dom = defineDomHelpers({ | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
getRootId: (ctx) => `carousel:${ctx.id}`, | ||
@@ -109,3 +40,3 @@ getViewportId: (ctx) => `carousel:${ctx.id}:viewport`, | ||
getSlideGroupEl: (ctx) => dom.queryById(ctx, dom.getSlideGroupId(ctx)), | ||
getSlideEls: (ctx) => queryAll(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
getSlideEls: (ctx) => (0, import_dom_query.queryAll)(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
}); | ||
@@ -124,3 +55,3 @@ | ||
function machine(userContext) { | ||
const ctx = compact(userContext); | ||
const ctx = (0, import_utils.compact)(userContext); | ||
return (0, import_core.createMachine)( | ||
@@ -246,6 +177,6 @@ { | ||
setNextIndex(ctx2) { | ||
ctx2.index = nextIndex(ctx2.slideRects, ctx2.index); | ||
ctx2.index = (0, import_utils.nextIndex)(ctx2.slideRects, ctx2.index); | ||
}, | ||
setPreviousIndex(ctx2) { | ||
ctx2.index = prevIndex(ctx2.slideRects, ctx2.index); | ||
ctx2.index = (0, import_utils.prevIndex)(ctx2.slideRects, ctx2.index); | ||
}, | ||
@@ -252,0 +183,0 @@ setScrollSnap(ctx2) { |
@@ -28,78 +28,5 @@ "use strict"; | ||
// ../../utilities/dom/src/attrs.ts | ||
var dataAttr = (guard) => { | ||
return guard ? "" : void 0; | ||
}; | ||
// src/carousel.connect.ts | ||
var import_dom_query2 = require("@zag-js/dom-query"); | ||
// ../../utilities/core/src/array.ts | ||
function nextIndex(v, idx, opts = {}) { | ||
const { step = 1, loop = true } = opts; | ||
const next = idx + step; | ||
const len = v.length; | ||
const last = len - 1; | ||
if (idx === -1) | ||
return step > 0 ? 0 : last; | ||
if (next < 0) | ||
return loop ? last : 0; | ||
if (next >= len) | ||
return loop ? 0 : idx > len ? len : idx; | ||
return next; | ||
} | ||
function prevIndex(v, idx, opts = {}) { | ||
const { step = 1, loop = true } = opts; | ||
return nextIndex(v, idx, { step: -step, loop }); | ||
} | ||
// ../../utilities/core/src/guard.ts | ||
var isArray = (v) => Array.isArray(v); | ||
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v)); | ||
// ../../utilities/core/src/object.ts | ||
function compact(obj) { | ||
if (obj === void 0) | ||
return obj; | ||
return Object.fromEntries( | ||
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value]) | ||
); | ||
} | ||
// ../../utilities/dom/src/query.ts | ||
function isDocument(el) { | ||
return el.nodeType === Node.DOCUMENT_NODE; | ||
} | ||
function isWindow(value) { | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
if (isWindow(el)) | ||
return el.document; | ||
if (isDocument(el)) | ||
return el; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function defineDomHelpers(helpers) { | ||
const dom2 = { | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)), | ||
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement, | ||
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id), | ||
queryById: (ctx, id) => { | ||
const el = dom2.getById(ctx, id); | ||
if (!el) | ||
throw new Error(`Element with id "${id}" not found.`); | ||
return el; | ||
} | ||
}; | ||
return { | ||
...dom2, | ||
...helpers | ||
}; | ||
} | ||
// ../../utilities/dom/src/nodelist.ts | ||
function queryAll(root, selector) { | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
// src/carousel.anatomy.ts | ||
@@ -120,3 +47,4 @@ var import_anatomy = require("@zag-js/anatomy"); | ||
// src/carousel.dom.ts | ||
var dom = defineDomHelpers({ | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
getRootId: (ctx) => `carousel:${ctx.id}`, | ||
@@ -129,3 +57,3 @@ getViewportId: (ctx) => `carousel:${ctx.id}:viewport`, | ||
getSlideGroupEl: (ctx) => dom.queryById(ctx, dom.getSlideGroupId(ctx)), | ||
getSlideEls: (ctx) => queryAll(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
getSlideEls: (ctx) => (0, import_dom_query.queryAll)(dom.getSlideGroupEl(ctx), `[data-part=slide]`) | ||
}); | ||
@@ -202,3 +130,3 @@ | ||
id: dom.getSlideId(state.context, index), | ||
"data-current": dataAttr(sliderState.isCurrent), | ||
"data-current": (0, import_dom_query2.dataAttr)(sliderState.isCurrent), | ||
role: "group", | ||
@@ -253,2 +181,3 @@ "aria-roledescription": "slide", | ||
var import_core = require("@zag-js/core"); | ||
var import_utils = require("@zag-js/utils"); | ||
@@ -266,3 +195,3 @@ // src/carousel.utils.ts | ||
function machine(userContext) { | ||
const ctx = compact(userContext); | ||
const ctx = (0, import_utils.compact)(userContext); | ||
return (0, import_core.createMachine)( | ||
@@ -388,6 +317,6 @@ { | ||
setNextIndex(ctx2) { | ||
ctx2.index = nextIndex(ctx2.slideRects, ctx2.index); | ||
ctx2.index = (0, import_utils.nextIndex)(ctx2.slideRects, ctx2.index); | ||
}, | ||
setPreviousIndex(ctx2) { | ||
ctx2.index = prevIndex(ctx2.slideRects, ctx2.index); | ||
ctx2.index = (0, import_utils.prevIndex)(ctx2.slideRects, ctx2.index); | ||
}, | ||
@@ -394,0 +323,0 @@ setScrollSnap(ctx2) { |
{ | ||
"name": "@zag-js/carousel", | ||
"version": "0.0.0-dev-20230221113221", | ||
"version": "0.0.0-dev-20230222120620", | ||
"description": "Core logic for the carousel widget implemented as a state machine", | ||
@@ -31,9 +31,9 @@ "keywords": [ | ||
"@zag-js/anatomy": "0.1.4", | ||
"@zag-js/core": "0.0.0-dev-20230221113221", | ||
"@zag-js/types": "0.3.4" | ||
"@zag-js/core": "0.0.0-dev-20230222120620", | ||
"@zag-js/types": "0.3.4", | ||
"@zag-js/dom-query": "0.0.0-dev-20230222120620", | ||
"@zag-js/utils": "0.3.3" | ||
}, | ||
"devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/dom-utils": "0.2.4", | ||
"@zag-js/utils": "0.3.3" | ||
"clean-package": "2.2.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "clean-package": "../../../clean-package.config.json", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
47625
5
1354
+ Added@zag-js/utils@0.3.3
+ Added@zag-js/core@0.0.0-dev-20230222120620(transitive)
+ Added@zag-js/dom-query@0.0.0-dev-20230222120620(transitive)
+ Added@zag-js/store@0.0.0-dev-20230222120620(transitive)
+ Added@zag-js/utils@0.3.3(transitive)
- Removed@zag-js/core@0.0.0-dev-20230221113221(transitive)
- Removed@zag-js/store@0.0.0-dev-20230221113221(transitive)