@samline/drawer 2.0.0 → 2.0.2

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.
@@ -1312,6 +1312,30 @@ function getNextHandleState({ isDragging, preventCycle, shouldCancelInteraction,
1312
1312
  };
1313
1313
  }
1314
1314
 
1315
+ function isElementLike(target) {
1316
+ const element = target;
1317
+ return Boolean(element && typeof element.getAttribute === 'function' && typeof element.hasAttribute === 'function' && typeof element.closest === 'function');
1318
+ }
1319
+ function getDragTargetMetadata(target) {
1320
+ var _ref;
1321
+ const targetElement = isElementLike(target) ? target : null;
1322
+ const ancestors = [];
1323
+ let element = targetElement;
1324
+ while(element){
1325
+ ancestors.push({
1326
+ scrollHeight: element.scrollHeight,
1327
+ clientHeight: element.clientHeight,
1328
+ scrollTop: element.scrollTop,
1329
+ role: element.getAttribute('role')
1330
+ });
1331
+ element = element.parentElement;
1332
+ }
1333
+ return {
1334
+ targetTagName: (_ref = targetElement == null ? void 0 : targetElement.tagName) != null ? _ref : '',
1335
+ hasNoDragAttribute: (targetElement == null ? void 0 : targetElement.hasAttribute('data-drawer-no-drag')) || Boolean(targetElement == null ? void 0 : targetElement.closest('[data-drawer-no-drag]')),
1336
+ ancestors
1337
+ };
1338
+ }
1315
1339
  function getDragPermission({ targetTagName, hasNoDragAttribute, direction, timeSinceOpenMs, swipeAmount, hasHighlightedText, timeSinceLastPreventedMs, scrollLockTimeout, isDraggingInDirection, ancestors }) {
1316
1340
  if (targetTagName === 'SELECT' || hasNoDragAttribute) {
1317
1341
  return {
@@ -1474,6 +1498,24 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1474
1498
  noBodyStyles,
1475
1499
  autoFocus
1476
1500
  });
1501
+ React__default.useEffect(()=>{
1502
+ var _drawerRef_current;
1503
+ if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
1504
+ return;
1505
+ }
1506
+ const activeElement = document.activeElement;
1507
+ if (!(activeElement instanceof HTMLElement)) {
1508
+ return;
1509
+ }
1510
+ if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElement)) || activeElement.closest('[data-drawer]')) {
1511
+ return;
1512
+ }
1513
+ activeElement.blur();
1514
+ }, [
1515
+ autoFocus,
1516
+ isOpen,
1517
+ modal
1518
+ ]);
1477
1519
  function getScale() {
1478
1520
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
1479
1521
  }
@@ -1497,24 +1539,12 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1497
1539
  }
1498
1540
  function shouldDrag(el, isDraggingInDirection) {
1499
1541
  var _window_getSelection;
1500
- let element = el;
1501
1542
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
1502
1543
  const date = new Date();
1503
- const ancestors = [];
1504
- // Keep climbing up the DOM tree as long as there's a parent
1505
- while(element){
1506
- ancestors.push({
1507
- scrollHeight: element.scrollHeight,
1508
- clientHeight: element.clientHeight,
1509
- scrollTop: element.scrollTop,
1510
- role: element.getAttribute('role')
1511
- });
1512
- // Move up to the parent element
1513
- element = element.parentNode;
1514
- }
1544
+ const { targetTagName, hasNoDragAttribute, ancestors } = getDragTargetMetadata(el);
1515
1545
  const result = getDragPermission({
1516
- targetTagName: el.tagName,
1517
- hasNoDragAttribute: el.hasAttribute('data-drawer-no-drag') || Boolean(el.closest('[data-drawer-no-drag]')),
1546
+ targetTagName,
1547
+ hasNoDragAttribute,
1518
1548
  direction,
1519
1549
  timeSinceOpenMs: openTime.current ? date.getTime() - openTime.current.getTime() : null,
1520
1550
  swipeAmount,
@@ -2157,6 +2187,17 @@ function getParentNestedVisualState({ direction, viewportSize, hasOpenChild, per
2157
2187
  };
2158
2188
  }
2159
2189
 
2190
+ const VISUALLY_HIDDEN_STYLE = {
2191
+ position: 'absolute',
2192
+ width: '1px',
2193
+ height: '1px',
2194
+ padding: 0,
2195
+ margin: '-1px',
2196
+ overflow: 'hidden',
2197
+ clip: 'rect(0, 0, 0, 0)',
2198
+ whiteSpace: 'nowrap',
2199
+ border: 0
2200
+ };
2160
2201
  function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, internalOnReleaseChange) {
2161
2202
  const { id: _id, parentId: _parentId, onDragChange, onReleaseChange, ...drawerOptions } = options;
2162
2203
  const baseProps = {
@@ -2186,7 +2227,7 @@ function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, i
2186
2227
  fadeFromIndex: undefined
2187
2228
  };
2188
2229
  }
2189
- function VanillaNode({ value }) {
2230
+ function VanillaNode({ value, dataAttribute }) {
2190
2231
  const ref = React__default.useRef(null);
2191
2232
  React__default.useEffect(()=>{
2192
2233
  const element = ref.current;
@@ -2212,14 +2253,17 @@ function VanillaNode({ value }) {
2212
2253
  return null;
2213
2254
  }
2214
2255
  return /*#__PURE__*/ React__default.createElement("div", {
2215
- "data-drawer-vanilla-node": "",
2256
+ ...dataAttribute ? {
2257
+ [dataAttribute]: ''
2258
+ } : {},
2216
2259
  ref: ref
2217
2260
  });
2218
2261
  }
2219
2262
  function VanillaDrawerRenderer({ options, open, onOpenChange, onDragChange, onReleaseChange }) {
2220
- const { mountElement: _mountElement, triggerElement: _triggerElement, triggerText, showHandle, handleClassName, title, description, content, overlayClassName, contentClassName, ...drawerOptions } = options;
2263
+ const { mountElement: _mountElement, triggerElement: _triggerElement, triggerText, showHandle, handleClassName, ariaLabel, ariaLabelledBy, ariaDescribedBy, title, titleVisuallyHidden, description, descriptionVisuallyHidden, content, overlayClassName, contentClassName, ...drawerOptions } = options;
2221
2264
  const rootProps = toReactDrawerProps(drawerOptions, open, onOpenChange, onDragChange, onReleaseChange);
2222
2265
  const shouldRenderHandle = Boolean(drawerOptions.handleOnly || showHandle);
2266
+ const shouldRenderVanillaContent = title != null || description != null || content != null;
2223
2267
  return /*#__PURE__*/ React__default.createElement(Drawer.Root, rootProps, triggerText ? /*#__PURE__*/ React__default.createElement(Drawer.Trigger, {
2224
2268
  asChild: true
2225
2269
  }, /*#__PURE__*/ React__default.createElement("button", {
@@ -2228,16 +2272,26 @@ function VanillaDrawerRenderer({ options, open, onOpenChange, onDragChange, onRe
2228
2272
  }, triggerText)) : null, /*#__PURE__*/ React__default.createElement(Drawer.Portal, null, /*#__PURE__*/ React__default.createElement(Drawer.Overlay, {
2229
2273
  className: overlayClassName
2230
2274
  }), /*#__PURE__*/ React__default.createElement(Drawer.Content, {
2231
- className: contentClassName
2275
+ className: contentClassName,
2276
+ "aria-label": title == null ? ariaLabel : undefined,
2277
+ "aria-labelledby": title == null ? ariaLabelledBy : undefined,
2278
+ "aria-describedby": description == null ? ariaDescribedBy : undefined
2232
2279
  }, shouldRenderHandle ? /*#__PURE__*/ React__default.createElement(Drawer.Handle, {
2233
2280
  className: handleClassName
2234
- }) : null, title != null ? /*#__PURE__*/ React__default.createElement(Drawer.Title, null, /*#__PURE__*/ React__default.createElement(VanillaNode, {
2281
+ }) : null, shouldRenderVanillaContent ? /*#__PURE__*/ React__default.createElement("div", {
2282
+ "data-drawer-vanilla-node": ""
2283
+ }, title != null ? /*#__PURE__*/ React__default.createElement(Drawer.Title, {
2284
+ style: titleVisuallyHidden ? VISUALLY_HIDDEN_STYLE : undefined
2285
+ }, /*#__PURE__*/ React__default.createElement(VanillaNode, {
2235
2286
  value: title
2236
- })) : null, description != null ? /*#__PURE__*/ React__default.createElement(Drawer.Description, null, /*#__PURE__*/ React__default.createElement(VanillaNode, {
2287
+ })) : null, description != null ? /*#__PURE__*/ React__default.createElement(Drawer.Description, {
2288
+ style: descriptionVisuallyHidden ? VISUALLY_HIDDEN_STYLE : undefined
2289
+ }, /*#__PURE__*/ React__default.createElement(VanillaNode, {
2237
2290
  value: description
2238
2291
  })) : null, /*#__PURE__*/ React__default.createElement(VanillaNode, {
2239
- value: content
2240
- }))));
2292
+ value: content,
2293
+ dataAttribute: "data-drawer-vanilla-body"
2294
+ })) : null)));
2241
2295
  }
2242
2296
 
2243
2297
  function canUseDOM$1() {
@@ -1311,6 +1311,30 @@ function getNextHandleState({ isDragging, preventCycle, shouldCancelInteraction,
1311
1311
  };
1312
1312
  }
1313
1313
 
1314
+ function isElementLike(target) {
1315
+ const element = target;
1316
+ return Boolean(element && typeof element.getAttribute === 'function' && typeof element.hasAttribute === 'function' && typeof element.closest === 'function');
1317
+ }
1318
+ function getDragTargetMetadata(target) {
1319
+ var _ref;
1320
+ const targetElement = isElementLike(target) ? target : null;
1321
+ const ancestors = [];
1322
+ let element = targetElement;
1323
+ while(element){
1324
+ ancestors.push({
1325
+ scrollHeight: element.scrollHeight,
1326
+ clientHeight: element.clientHeight,
1327
+ scrollTop: element.scrollTop,
1328
+ role: element.getAttribute('role')
1329
+ });
1330
+ element = element.parentElement;
1331
+ }
1332
+ return {
1333
+ targetTagName: (_ref = targetElement == null ? void 0 : targetElement.tagName) != null ? _ref : '',
1334
+ hasNoDragAttribute: (targetElement == null ? void 0 : targetElement.hasAttribute('data-drawer-no-drag')) || Boolean(targetElement == null ? void 0 : targetElement.closest('[data-drawer-no-drag]')),
1335
+ ancestors
1336
+ };
1337
+ }
1314
1338
  function getDragPermission({ targetTagName, hasNoDragAttribute, direction, timeSinceOpenMs, swipeAmount, hasHighlightedText, timeSinceLastPreventedMs, scrollLockTimeout, isDraggingInDirection, ancestors }) {
1315
1339
  if (targetTagName === 'SELECT' || hasNoDragAttribute) {
1316
1340
  return {
@@ -1473,6 +1497,24 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1473
1497
  noBodyStyles,
1474
1498
  autoFocus
1475
1499
  });
1500
+ React__default.useEffect(()=>{
1501
+ var _drawerRef_current;
1502
+ if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
1503
+ return;
1504
+ }
1505
+ const activeElement = document.activeElement;
1506
+ if (!(activeElement instanceof HTMLElement)) {
1507
+ return;
1508
+ }
1509
+ if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElement)) || activeElement.closest('[data-drawer]')) {
1510
+ return;
1511
+ }
1512
+ activeElement.blur();
1513
+ }, [
1514
+ autoFocus,
1515
+ isOpen,
1516
+ modal
1517
+ ]);
1476
1518
  function getScale() {
1477
1519
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
1478
1520
  }
@@ -1496,24 +1538,12 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1496
1538
  }
1497
1539
  function shouldDrag(el, isDraggingInDirection) {
1498
1540
  var _window_getSelection;
1499
- let element = el;
1500
1541
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
1501
1542
  const date = new Date();
1502
- const ancestors = [];
1503
- // Keep climbing up the DOM tree as long as there's a parent
1504
- while(element){
1505
- ancestors.push({
1506
- scrollHeight: element.scrollHeight,
1507
- clientHeight: element.clientHeight,
1508
- scrollTop: element.scrollTop,
1509
- role: element.getAttribute('role')
1510
- });
1511
- // Move up to the parent element
1512
- element = element.parentNode;
1513
- }
1543
+ const { targetTagName, hasNoDragAttribute, ancestors } = getDragTargetMetadata(el);
1514
1544
  const result = getDragPermission({
1515
- targetTagName: el.tagName,
1516
- hasNoDragAttribute: el.hasAttribute('data-drawer-no-drag') || Boolean(el.closest('[data-drawer-no-drag]')),
1545
+ targetTagName,
1546
+ hasNoDragAttribute,
1517
1547
  direction,
1518
1548
  timeSinceOpenMs: openTime.current ? date.getTime() - openTime.current.getTime() : null,
1519
1549
  swipeAmount,
@@ -1331,6 +1331,30 @@ function getNextHandleState({ isDragging, preventCycle, shouldCancelInteraction,
1331
1331
  };
1332
1332
  }
1333
1333
 
1334
+ function isElementLike(target) {
1335
+ const element = target;
1336
+ return Boolean(element && typeof element.getAttribute === 'function' && typeof element.hasAttribute === 'function' && typeof element.closest === 'function');
1337
+ }
1338
+ function getDragTargetMetadata(target) {
1339
+ var _ref;
1340
+ const targetElement = isElementLike(target) ? target : null;
1341
+ const ancestors = [];
1342
+ let element = targetElement;
1343
+ while(element){
1344
+ ancestors.push({
1345
+ scrollHeight: element.scrollHeight,
1346
+ clientHeight: element.clientHeight,
1347
+ scrollTop: element.scrollTop,
1348
+ role: element.getAttribute('role')
1349
+ });
1350
+ element = element.parentElement;
1351
+ }
1352
+ return {
1353
+ targetTagName: (_ref = targetElement == null ? void 0 : targetElement.tagName) != null ? _ref : '',
1354
+ hasNoDragAttribute: (targetElement == null ? void 0 : targetElement.hasAttribute('data-drawer-no-drag')) || Boolean(targetElement == null ? void 0 : targetElement.closest('[data-drawer-no-drag]')),
1355
+ ancestors
1356
+ };
1357
+ }
1334
1358
  function getDragPermission({ targetTagName, hasNoDragAttribute, direction, timeSinceOpenMs, swipeAmount, hasHighlightedText, timeSinceLastPreventedMs, scrollLockTimeout, isDraggingInDirection, ancestors }) {
1335
1359
  if (targetTagName === 'SELECT' || hasNoDragAttribute) {
1336
1360
  return {
@@ -1493,6 +1517,24 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1493
1517
  noBodyStyles,
1494
1518
  autoFocus
1495
1519
  });
1520
+ React__namespace.default.useEffect(()=>{
1521
+ var _drawerRef_current;
1522
+ if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
1523
+ return;
1524
+ }
1525
+ const activeElement = document.activeElement;
1526
+ if (!(activeElement instanceof HTMLElement)) {
1527
+ return;
1528
+ }
1529
+ if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElement)) || activeElement.closest('[data-drawer]')) {
1530
+ return;
1531
+ }
1532
+ activeElement.blur();
1533
+ }, [
1534
+ autoFocus,
1535
+ isOpen,
1536
+ modal
1537
+ ]);
1496
1538
  function getScale() {
1497
1539
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
1498
1540
  }
@@ -1516,24 +1558,12 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1516
1558
  }
1517
1559
  function shouldDrag(el, isDraggingInDirection) {
1518
1560
  var _window_getSelection;
1519
- let element = el;
1520
1561
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
1521
1562
  const date = new Date();
1522
- const ancestors = [];
1523
- // Keep climbing up the DOM tree as long as there's a parent
1524
- while(element){
1525
- ancestors.push({
1526
- scrollHeight: element.scrollHeight,
1527
- clientHeight: element.clientHeight,
1528
- scrollTop: element.scrollTop,
1529
- role: element.getAttribute('role')
1530
- });
1531
- // Move up to the parent element
1532
- element = element.parentNode;
1533
- }
1563
+ const { targetTagName, hasNoDragAttribute, ancestors } = getDragTargetMetadata(el);
1534
1564
  const result = getDragPermission({
1535
- targetTagName: el.tagName,
1536
- hasNoDragAttribute: el.hasAttribute('data-drawer-no-drag') || Boolean(el.closest('[data-drawer-no-drag]')),
1565
+ targetTagName,
1566
+ hasNoDragAttribute,
1537
1567
  direction,
1538
1568
  timeSinceOpenMs: openTime.current ? date.getTime() - openTime.current.getTime() : null,
1539
1569
  swipeAmount,
@@ -27871,6 +27871,31 @@ function getNextHandleState({
27871
27871
  }
27872
27872
 
27873
27873
  // src/runtime/drag-policy.ts
27874
+ function isElementLike(target) {
27875
+ const element = target;
27876
+ return Boolean(
27877
+ element && typeof element.getAttribute === "function" && typeof element.hasAttribute === "function" && typeof element.closest === "function"
27878
+ );
27879
+ }
27880
+ function getDragTargetMetadata(target) {
27881
+ const targetElement = isElementLike(target) ? target : null;
27882
+ const ancestors = [];
27883
+ let element = targetElement;
27884
+ while (element) {
27885
+ ancestors.push({
27886
+ scrollHeight: element.scrollHeight,
27887
+ clientHeight: element.clientHeight,
27888
+ scrollTop: element.scrollTop,
27889
+ role: element.getAttribute("role")
27890
+ });
27891
+ element = element.parentElement;
27892
+ }
27893
+ return {
27894
+ targetTagName: targetElement?.tagName ?? "",
27895
+ hasNoDragAttribute: targetElement?.hasAttribute("data-drawer-no-drag") || Boolean(targetElement?.closest("[data-drawer-no-drag]")),
27896
+ ancestors
27897
+ };
27898
+ }
27874
27899
  function getDragPermission({
27875
27900
  targetTagName,
27876
27901
  hasNoDragAttribute,
@@ -28051,6 +28076,19 @@ function Root2({
28051
28076
  noBodyStyles,
28052
28077
  autoFocus
28053
28078
  });
28079
+ import_react9.default.useEffect(() => {
28080
+ if (!isOpen || !modal || autoFocus || typeof document === "undefined") {
28081
+ return;
28082
+ }
28083
+ const activeElement = document.activeElement;
28084
+ if (!(activeElement instanceof HTMLElement)) {
28085
+ return;
28086
+ }
28087
+ if (drawerRef.current?.contains(activeElement) || activeElement.closest("[data-drawer]")) {
28088
+ return;
28089
+ }
28090
+ activeElement.blur();
28091
+ }, [autoFocus, isOpen, modal]);
28054
28092
  function getScale() {
28055
28093
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
28056
28094
  }
@@ -28068,22 +28106,12 @@ function Root2({
28068
28106
  pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
28069
28107
  }
28070
28108
  function shouldDrag(el, isDraggingInDirection) {
28071
- let element = el;
28072
28109
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
28073
28110
  const date = /* @__PURE__ */ new Date();
28074
- const ancestors = [];
28075
- while (element) {
28076
- ancestors.push({
28077
- scrollHeight: element.scrollHeight,
28078
- clientHeight: element.clientHeight,
28079
- scrollTop: element.scrollTop,
28080
- role: element.getAttribute("role")
28081
- });
28082
- element = element.parentNode;
28083
- }
28111
+ const { targetTagName, hasNoDragAttribute, ancestors } = getDragTargetMetadata(el);
28084
28112
  const result = getDragPermission({
28085
- targetTagName: el.tagName,
28086
- hasNoDragAttribute: el.hasAttribute("data-drawer-no-drag") || Boolean(el.closest("[data-drawer-no-drag]")),
28113
+ targetTagName,
28114
+ hasNoDragAttribute,
28087
28115
  direction,
28088
28116
  timeSinceOpenMs: openTime.current ? date.getTime() - openTime.current.getTime() : null,
28089
28117
  swipeAmount,
@@ -28712,6 +28740,17 @@ var Drawer = {
28712
28740
  };
28713
28741
 
28714
28742
  // src/vanilla/render.tsx
28743
+ var VISUALLY_HIDDEN_STYLE = {
28744
+ position: "absolute",
28745
+ width: "1px",
28746
+ height: "1px",
28747
+ padding: 0,
28748
+ margin: "-1px",
28749
+ overflow: "hidden",
28750
+ clip: "rect(0, 0, 0, 0)",
28751
+ whiteSpace: "nowrap",
28752
+ border: 0
28753
+ };
28715
28754
  function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, internalOnReleaseChange) {
28716
28755
  const { id: _id, parentId: _parentId, onDragChange, onReleaseChange, ...drawerOptions } = options;
28717
28756
  const baseProps = {
@@ -28740,7 +28779,7 @@ function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, i
28740
28779
  fadeFromIndex: void 0
28741
28780
  };
28742
28781
  }
28743
- function VanillaNode({ value }) {
28782
+ function VanillaNode({ value, dataAttribute }) {
28744
28783
  const ref = import_react10.default.useRef(null);
28745
28784
  import_react10.default.useEffect(() => {
28746
28785
  const element = ref.current;
@@ -28763,7 +28802,7 @@ function VanillaNode({ value }) {
28763
28802
  if (value == null) {
28764
28803
  return null;
28765
28804
  }
28766
- return /* @__PURE__ */ import_react10.default.createElement("div", { "data-drawer-vanilla-node": "", ref });
28805
+ return /* @__PURE__ */ import_react10.default.createElement("div", { ...dataAttribute ? { [dataAttribute]: "" } : {}, ref });
28767
28806
  }
28768
28807
  function VanillaDrawerRenderer({
28769
28808
  options,
@@ -28778,8 +28817,13 @@ function VanillaDrawerRenderer({
28778
28817
  triggerText,
28779
28818
  showHandle,
28780
28819
  handleClassName,
28820
+ ariaLabel,
28821
+ ariaLabelledBy,
28822
+ ariaDescribedBy,
28781
28823
  title,
28824
+ titleVisuallyHidden,
28782
28825
  description,
28826
+ descriptionVisuallyHidden,
28783
28827
  content,
28784
28828
  overlayClassName,
28785
28829
  contentClassName,
@@ -28787,7 +28831,18 @@ function VanillaDrawerRenderer({
28787
28831
  } = options;
28788
28832
  const rootProps = toReactDrawerProps(drawerOptions, open, onOpenChange, onDragChange, onReleaseChange);
28789
28833
  const shouldRenderHandle = Boolean(drawerOptions.handleOnly || showHandle);
28790
- return /* @__PURE__ */ import_react10.default.createElement(Drawer.Root, { ...rootProps }, triggerText ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Trigger, { asChild: true }, /* @__PURE__ */ import_react10.default.createElement("button", { type: "button", "data-drawer-vanilla-trigger": "" }, triggerText)) : null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Portal, null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Overlay, { className: overlayClassName }), /* @__PURE__ */ import_react10.default.createElement(Drawer.Content, { className: contentClassName }, shouldRenderHandle ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Handle, { className: handleClassName }) : null, title != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Title, null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: title })) : null, description != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Description, null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: description })) : null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: content }))));
28834
+ const shouldRenderVanillaContent = title != null || description != null || content != null;
28835
+ return /* @__PURE__ */ import_react10.default.createElement(Drawer.Root, { ...rootProps }, triggerText ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Trigger, { asChild: true }, /* @__PURE__ */ import_react10.default.createElement("button", { type: "button", "data-drawer-vanilla-trigger": "" }, triggerText)) : null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Portal, null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Overlay, { className: overlayClassName }), /* @__PURE__ */ import_react10.default.createElement(
28836
+ Drawer.Content,
28837
+ {
28838
+ className: contentClassName,
28839
+ "aria-label": title == null ? ariaLabel : void 0,
28840
+ "aria-labelledby": title == null ? ariaLabelledBy : void 0,
28841
+ "aria-describedby": description == null ? ariaDescribedBy : void 0
28842
+ },
28843
+ shouldRenderHandle ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Handle, { className: handleClassName }) : null,
28844
+ shouldRenderVanillaContent ? /* @__PURE__ */ import_react10.default.createElement("div", { "data-drawer-vanilla-node": "" }, title != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Title, { style: titleVisuallyHidden ? VISUALLY_HIDDEN_STYLE : void 0 }, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: title })) : null, description != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Description, { style: descriptionVisuallyHidden ? VISUALLY_HIDDEN_STYLE : void 0 }, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: description })) : null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: content, dataAttribute: "data-drawer-vanilla-body" })) : null
28845
+ )));
28791
28846
  }
28792
28847
 
28793
28848
  // src/vanilla/host.tsx
@@ -27843,6 +27843,31 @@ function getNextHandleState({
27843
27843
  }
27844
27844
 
27845
27845
  // src/runtime/drag-policy.ts
27846
+ function isElementLike(target) {
27847
+ const element = target;
27848
+ return Boolean(
27849
+ element && typeof element.getAttribute === "function" && typeof element.hasAttribute === "function" && typeof element.closest === "function"
27850
+ );
27851
+ }
27852
+ function getDragTargetMetadata(target) {
27853
+ const targetElement = isElementLike(target) ? target : null;
27854
+ const ancestors = [];
27855
+ let element = targetElement;
27856
+ while (element) {
27857
+ ancestors.push({
27858
+ scrollHeight: element.scrollHeight,
27859
+ clientHeight: element.clientHeight,
27860
+ scrollTop: element.scrollTop,
27861
+ role: element.getAttribute("role")
27862
+ });
27863
+ element = element.parentElement;
27864
+ }
27865
+ return {
27866
+ targetTagName: targetElement?.tagName ?? "",
27867
+ hasNoDragAttribute: targetElement?.hasAttribute("data-drawer-no-drag") || Boolean(targetElement?.closest("[data-drawer-no-drag]")),
27868
+ ancestors
27869
+ };
27870
+ }
27846
27871
  function getDragPermission({
27847
27872
  targetTagName,
27848
27873
  hasNoDragAttribute,
@@ -28023,6 +28048,19 @@ function Root2({
28023
28048
  noBodyStyles,
28024
28049
  autoFocus
28025
28050
  });
28051
+ import_react9.default.useEffect(() => {
28052
+ if (!isOpen || !modal || autoFocus || typeof document === "undefined") {
28053
+ return;
28054
+ }
28055
+ const activeElement = document.activeElement;
28056
+ if (!(activeElement instanceof HTMLElement)) {
28057
+ return;
28058
+ }
28059
+ if (drawerRef.current?.contains(activeElement) || activeElement.closest("[data-drawer]")) {
28060
+ return;
28061
+ }
28062
+ activeElement.blur();
28063
+ }, [autoFocus, isOpen, modal]);
28026
28064
  function getScale() {
28027
28065
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
28028
28066
  }
@@ -28040,22 +28078,12 @@ function Root2({
28040
28078
  pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
28041
28079
  }
28042
28080
  function shouldDrag(el, isDraggingInDirection) {
28043
- let element = el;
28044
28081
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
28045
28082
  const date = /* @__PURE__ */ new Date();
28046
- const ancestors = [];
28047
- while (element) {
28048
- ancestors.push({
28049
- scrollHeight: element.scrollHeight,
28050
- clientHeight: element.clientHeight,
28051
- scrollTop: element.scrollTop,
28052
- role: element.getAttribute("role")
28053
- });
28054
- element = element.parentNode;
28055
- }
28083
+ const { targetTagName, hasNoDragAttribute, ancestors } = getDragTargetMetadata(el);
28056
28084
  const result = getDragPermission({
28057
- targetTagName: el.tagName,
28058
- hasNoDragAttribute: el.hasAttribute("data-drawer-no-drag") || Boolean(el.closest("[data-drawer-no-drag]")),
28085
+ targetTagName,
28086
+ hasNoDragAttribute,
28059
28087
  direction,
28060
28088
  timeSinceOpenMs: openTime.current ? date.getTime() - openTime.current.getTime() : null,
28061
28089
  swipeAmount,
@@ -28684,6 +28712,17 @@ var Drawer = {
28684
28712
  };
28685
28713
 
28686
28714
  // src/vanilla/render.tsx
28715
+ var VISUALLY_HIDDEN_STYLE = {
28716
+ position: "absolute",
28717
+ width: "1px",
28718
+ height: "1px",
28719
+ padding: 0,
28720
+ margin: "-1px",
28721
+ overflow: "hidden",
28722
+ clip: "rect(0, 0, 0, 0)",
28723
+ whiteSpace: "nowrap",
28724
+ border: 0
28725
+ };
28687
28726
  function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, internalOnReleaseChange) {
28688
28727
  const { id: _id, parentId: _parentId, onDragChange, onReleaseChange, ...drawerOptions } = options;
28689
28728
  const baseProps = {
@@ -28712,7 +28751,7 @@ function toReactDrawerProps(options, open, onOpenChange, internalOnDragChange, i
28712
28751
  fadeFromIndex: void 0
28713
28752
  };
28714
28753
  }
28715
- function VanillaNode({ value }) {
28754
+ function VanillaNode({ value, dataAttribute }) {
28716
28755
  const ref = import_react10.default.useRef(null);
28717
28756
  import_react10.default.useEffect(() => {
28718
28757
  const element = ref.current;
@@ -28735,7 +28774,7 @@ function VanillaNode({ value }) {
28735
28774
  if (value == null) {
28736
28775
  return null;
28737
28776
  }
28738
- return /* @__PURE__ */ import_react10.default.createElement("div", { "data-drawer-vanilla-node": "", ref });
28777
+ return /* @__PURE__ */ import_react10.default.createElement("div", { ...dataAttribute ? { [dataAttribute]: "" } : {}, ref });
28739
28778
  }
28740
28779
  function VanillaDrawerRenderer({
28741
28780
  options,
@@ -28750,8 +28789,13 @@ function VanillaDrawerRenderer({
28750
28789
  triggerText,
28751
28790
  showHandle,
28752
28791
  handleClassName,
28792
+ ariaLabel,
28793
+ ariaLabelledBy,
28794
+ ariaDescribedBy,
28753
28795
  title,
28796
+ titleVisuallyHidden,
28754
28797
  description,
28798
+ descriptionVisuallyHidden,
28755
28799
  content,
28756
28800
  overlayClassName,
28757
28801
  contentClassName,
@@ -28759,7 +28803,18 @@ function VanillaDrawerRenderer({
28759
28803
  } = options;
28760
28804
  const rootProps = toReactDrawerProps(drawerOptions, open, onOpenChange, onDragChange, onReleaseChange);
28761
28805
  const shouldRenderHandle = Boolean(drawerOptions.handleOnly || showHandle);
28762
- return /* @__PURE__ */ import_react10.default.createElement(Drawer.Root, { ...rootProps }, triggerText ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Trigger, { asChild: true }, /* @__PURE__ */ import_react10.default.createElement("button", { type: "button", "data-drawer-vanilla-trigger": "" }, triggerText)) : null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Portal, null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Overlay, { className: overlayClassName }), /* @__PURE__ */ import_react10.default.createElement(Drawer.Content, { className: contentClassName }, shouldRenderHandle ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Handle, { className: handleClassName }) : null, title != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Title, null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: title })) : null, description != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Description, null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: description })) : null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: content }))));
28806
+ const shouldRenderVanillaContent = title != null || description != null || content != null;
28807
+ return /* @__PURE__ */ import_react10.default.createElement(Drawer.Root, { ...rootProps }, triggerText ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Trigger, { asChild: true }, /* @__PURE__ */ import_react10.default.createElement("button", { type: "button", "data-drawer-vanilla-trigger": "" }, triggerText)) : null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Portal, null, /* @__PURE__ */ import_react10.default.createElement(Drawer.Overlay, { className: overlayClassName }), /* @__PURE__ */ import_react10.default.createElement(
28808
+ Drawer.Content,
28809
+ {
28810
+ className: contentClassName,
28811
+ "aria-label": title == null ? ariaLabel : void 0,
28812
+ "aria-labelledby": title == null ? ariaLabelledBy : void 0,
28813
+ "aria-describedby": description == null ? ariaDescribedBy : void 0
28814
+ },
28815
+ shouldRenderHandle ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Handle, { className: handleClassName }) : null,
28816
+ shouldRenderVanillaContent ? /* @__PURE__ */ import_react10.default.createElement("div", { "data-drawer-vanilla-node": "" }, title != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Title, { style: titleVisuallyHidden ? VISUALLY_HIDDEN_STYLE : void 0 }, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: title })) : null, description != null ? /* @__PURE__ */ import_react10.default.createElement(Drawer.Description, { style: descriptionVisuallyHidden ? VISUALLY_HIDDEN_STYLE : void 0 }, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: description })) : null, /* @__PURE__ */ import_react10.default.createElement(VanillaNode, { value: content, dataAttribute: "data-drawer-vanilla-body" })) : null
28817
+ )));
28763
28818
  }
28764
28819
 
28765
28820
  // src/vanilla/host.tsx