orynn 0.5.0 → 0.6.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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { createContext, forwardRef, useContext, useId, useRef, useEffect, useCallback, useMemo, useState, useImperativeHandle, useLayoutEffect, useReducer, memo } from 'react';
1
+ import { createContext, forwardRef, useContext, useId, useRef, useEffect, useCallback, useMemo, useState, useImperativeHandle, useLayoutEffect, useReducer, useSyncExternalStore, memo, isValidElement } from 'react';
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { createPortal } from 'react-dom';
4
- import { Dialog as Dialog$1, Popover as Popover$1, DropdownMenu as DropdownMenu$1, Slot, Label as Label$1, Separator as Separator$1, Switch as Switch$1, Tabs as Tabs$1, Tooltip as Tooltip$1 } from 'radix-ui';
4
+ import { Dialog as Dialog$1, Popover as Popover$1, DropdownMenu as DropdownMenu$1, Accordion as Accordion$1, Slot, Slider as Slider$1, Progress as Progress$1, Toast, Label as Label$1, Separator as Separator$1, Switch as Switch$1, Tabs as Tabs$1, Tooltip as Tooltip$1 } from 'radix-ui';
5
5
 
6
6
  var __typeError = (msg) => {
7
7
  throw TypeError(msg);
@@ -621,7 +621,10 @@ function Popover({
621
621
  left: pos.left,
622
622
  top: pos.top,
623
623
  width: matchWidth ? pos.width : void 0,
624
- minWidth: pos.width,
624
+ // Only pin the min-width to the anchor when we're matching it. With
625
+ // `matchWidth={false}` the panel sizes to its own content, so a wide
626
+ // trigger doesn't stretch it across the screen.
627
+ minWidth: matchWidth ? pos.width : void 0,
625
628
  maxHeight: pos.maxHeight,
626
629
  transform: pos.placement === "top" ? "translateY(-100%)" : void 0
627
630
  },
@@ -796,7 +799,7 @@ function Calendar({
796
799
  onSelect,
797
800
  mode = "single",
798
801
  selectedDates,
799
- range,
802
+ range: range2,
800
803
  previewRange: previewRange2,
801
804
  onHoverDate,
802
805
  minDate,
@@ -815,11 +818,14 @@ function Calendar({
815
818
  precision = "day",
816
819
  fixedWeeks = true,
817
820
  defaultMonth,
818
- numberOfMonths = 1
821
+ numberOfMonths = 1,
822
+ className,
823
+ style,
824
+ fillWidth
819
825
  }) {
820
826
  const panels = Math.max(1, Math.floor(numberOfMonths));
821
827
  const today = startOfDay(/* @__PURE__ */ new Date());
822
- const anchor = value ?? (mode === "range" ? range?.start ?? range?.end ?? null : null) ?? (mode === "multiple" ? selectedDates?.[0] ?? null : null) ?? defaultMonth ?? null;
828
+ const anchor = value ?? (mode === "range" ? range2?.start ?? range2?.end ?? null : null) ?? (mode === "multiple" ? selectedDates?.[0] ?? null : null) ?? defaultMonth ?? null;
823
829
  const initial = anchor ?? clampDate(today, minDate, maxDate);
824
830
  const [nav, setNav] = useState({ y: initial.getFullYear(), m: initial.getMonth() });
825
831
  const [focused, setFocused] = useState(initial);
@@ -980,9 +986,9 @@ function Calendar({
980
986
  if (mode === "multiple") {
981
987
  selected = (selectedDates ?? []).some((x) => isSameDay(x, d));
982
988
  } else if (mode === "range") {
983
- rangeStart = isRangeStart(d, range) || !!previewRange2 && isRangeStart(d, previewRange2);
984
- rangeEnd = isRangeEnd(d, range) || !!previewRange2 && isRangeEnd(d, previewRange2);
985
- inRange = isWithinRange(d, range) || !!previewRange2 && isWithinRange(d, previewRange2);
989
+ rangeStart = isRangeStart(d, range2) || !!previewRange2 && isRangeStart(d, previewRange2);
990
+ rangeEnd = isRangeEnd(d, range2) || !!previewRange2 && isRangeEnd(d, previewRange2);
991
+ inRange = isWithinRange(d, range2) || !!previewRange2 && isWithinRange(d, previewRange2);
986
992
  selected = rangeStart || rangeEnd;
987
993
  } else {
988
994
  selected = isSameDay(d, value);
@@ -1142,10 +1148,12 @@ function Calendar({
1142
1148
  return /* @__PURE__ */ jsxs(
1143
1149
  "div",
1144
1150
  {
1145
- className: "orynn-calendar",
1151
+ className: cx("orynn-calendar", className),
1152
+ style,
1146
1153
  ref: gridRef,
1147
1154
  "data-view": view,
1148
1155
  "data-months": panels > 1 ? panels : void 0,
1156
+ "data-fill": fillWidth || void 0,
1149
1157
  children: [
1150
1158
  header,
1151
1159
  " ",
@@ -1219,7 +1227,7 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1219
1227
  value: valueProp,
1220
1228
  defaultValue,
1221
1229
  onChange,
1222
- format = "yyyy-MM-dd",
1230
+ format = "dd-MMM-yyyy",
1223
1231
  minDate,
1224
1232
  maxDate,
1225
1233
  disabledDates,
@@ -1233,6 +1241,7 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1233
1241
  precision = "day",
1234
1242
  fixedWeeks = true,
1235
1243
  numberOfMonths,
1244
+ calendarWidth,
1236
1245
  showTime = false,
1237
1246
  timeStep = 5,
1238
1247
  defaultMonth,
@@ -1250,7 +1259,7 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1250
1259
  const panelId = `${id}-cal`;
1251
1260
  const withTimePicker = showTime && mode === "single";
1252
1261
  const closeOnSelect = closeOnSelectProp ?? !withTimePicker;
1253
- const fmt = withTimePicker && format === "yyyy-MM-dd" ? "yyyy-MM-dd HH:mm" : format;
1262
+ const fmt = withTimePicker && format === "dd-MMM-yyyy" ? "dd-MMM-yyyy HH:mm" : format;
1254
1263
  const isControlled = valueProp !== void 0;
1255
1264
  const [innerRaw, setInnerRaw] = useState(() => defaultValue ?? null);
1256
1265
  const raw = isControlled ? valueProp : innerRaw;
@@ -1363,9 +1372,9 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1363
1372
  if (closeOnSelect && !inline) closeAndRefocus();
1364
1373
  };
1365
1374
  const setTimeField = (part, n) => {
1366
- const base2 = curDate ?? startOfDay(/* @__PURE__ */ new Date());
1367
- const t = timeParts(base2);
1368
- commit(withTime(base2, { ...t, [part]: n, s: 0 }));
1375
+ const base3 = curDate ?? startOfDay(/* @__PURE__ */ new Date());
1376
+ const t = timeParts(base3);
1377
+ commit(withTime(base3, { ...t, [part]: n, s: 0 }));
1369
1378
  };
1370
1379
  const timeColumn = withTimePicker ? /* @__PURE__ */ jsxs("div", { className: "orynn-datepicker__time", children: [
1371
1380
  /* @__PURE__ */ jsx("span", { className: "orynn-datepicker__time-label", children: "Time" }),
@@ -1393,11 +1402,18 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1393
1402
  )
1394
1403
  ] })
1395
1404
  ] }) : null;
1405
+ const calendarStyle = calendarWidth != null ? {
1406
+ "--orynn-calendar-min-width": typeof calendarWidth === "number" ? `${calendarWidth}px` : calendarWidth
1407
+ } : void 0;
1408
+ const hasExtras = (numberOfMonths ?? 1) > 1 || (presets?.length ?? 0) > 0 || withTimePicker;
1409
+ const fillWidth = inline || !hasExtras;
1396
1410
  const calendar = /* @__PURE__ */ jsx(
1397
1411
  Calendar,
1398
1412
  {
1399
1413
  value: curDate,
1400
1414
  onSelect: select,
1415
+ style: calendarStyle,
1416
+ fillWidth,
1401
1417
  mode,
1402
1418
  selectedDates: mode === "multiple" ? curDates : void 0,
1403
1419
  range: mode === "range" ? curRange : void 0,
@@ -1572,7 +1588,7 @@ var DatePicker = /* @__PURE__ */ forwardRef(
1572
1588
  setOpen(false);
1573
1589
  setGridFocus(false);
1574
1590
  },
1575
- matchWidth: false,
1591
+ matchWidth: fillWidth,
1576
1592
  id: panelId,
1577
1593
  role: "dialog",
1578
1594
  children: cal
@@ -2435,8 +2451,8 @@ var NumberField = /* @__PURE__ */ forwardRef(
2435
2451
  };
2436
2452
  const bump = (dir, mode = "n") => {
2437
2453
  const amount = mode === "l" ? shiftStep ?? step * 10 : mode === "s" ? smallStep ?? step / 10 : step;
2438
- const base2 = value ?? (dir > 0 ? effMin ?? 0 : max ?? 0);
2439
- let next = round(base2 + amount * dir, scale);
2454
+ const base3 = value ?? (dir > 0 ? effMin ?? 0 : max ?? 0);
2455
+ let next = round(base3 + amount * dir, scale);
2440
2456
  if (clampMode !== "none") next = clamp(next, effMin, max);
2441
2457
  else if (!allowNegative && next < 0) next = 0;
2442
2458
  setNumber(next);
@@ -3995,9 +4011,65 @@ function Form(props) {
3995
4011
  }
3996
4012
  );
3997
4013
  }
4014
+ var Accordion = /* @__PURE__ */ forwardRef(
4015
+ function Accordion2({ className, variant = "bordered", size = "md", ...props }, ref) {
4016
+ return /* @__PURE__ */ jsx(
4017
+ Accordion$1.Root,
4018
+ {
4019
+ ref,
4020
+ "data-slot": "accordion",
4021
+ "data-variant": variant,
4022
+ "data-size": size,
4023
+ className: cx("orynn-accordion", className),
4024
+ ...props
4025
+ }
4026
+ );
4027
+ }
4028
+ );
4029
+ var AccordionItem = /* @__PURE__ */ forwardRef(function AccordionItem2({ className, ...props }, ref) {
4030
+ return /* @__PURE__ */ jsx(
4031
+ Accordion$1.Item,
4032
+ {
4033
+ ref,
4034
+ "data-slot": "accordion-item",
4035
+ className: cx("orynn-accordion__item", className),
4036
+ ...props
4037
+ }
4038
+ );
4039
+ });
4040
+ var AccordionTrigger = /* @__PURE__ */ forwardRef(function AccordionTrigger2({ className, children, icon, iconPosition = "end", hideIcon = false, ...props }, ref) {
4041
+ const indicator = hideIcon ? null : /* @__PURE__ */ jsx("span", { className: "orynn-accordion__icon", "data-slot": "accordion-icon", "aria-hidden": "true", children: icon ?? /* @__PURE__ */ jsx(ChevronDownIcon, {}) });
4042
+ return /* @__PURE__ */ jsx(Accordion$1.Header, { className: "orynn-accordion__header", "data-slot": "accordion-header", children: /* @__PURE__ */ jsxs(
4043
+ Accordion$1.Trigger,
4044
+ {
4045
+ ref,
4046
+ "data-slot": "accordion-trigger",
4047
+ "data-icon-position": iconPosition,
4048
+ className: cx("orynn-accordion__trigger", className),
4049
+ ...props,
4050
+ children: [
4051
+ iconPosition === "start" && indicator,
4052
+ /* @__PURE__ */ jsx("span", { className: "orynn-accordion__label", children }),
4053
+ iconPosition === "end" && indicator
4054
+ ]
4055
+ }
4056
+ ) });
4057
+ });
4058
+ var AccordionContent = /* @__PURE__ */ forwardRef(function AccordionContent2({ className, children, ...props }, ref) {
4059
+ return /* @__PURE__ */ jsx(
4060
+ Accordion$1.Content,
4061
+ {
4062
+ ref,
4063
+ "data-slot": "accordion-content",
4064
+ className: cx("orynn-accordion__content", className),
4065
+ ...props,
4066
+ children: /* @__PURE__ */ jsx("div", { className: "orynn-accordion__body", children })
4067
+ }
4068
+ );
4069
+ });
3998
4070
 
3999
4071
  // src/primitives/shared/classes.ts
4000
- var mod = (base2, key, fallback) => key === fallback ? void 0 : `${base2}--${key}`;
4072
+ var mod = (base3, key, fallback) => key === fallback ? void 0 : `${base3}--${key}`;
4001
4073
  function buttonClasses(variant = "default", size = "default") {
4002
4074
  return cx(
4003
4075
  "orynn-button",
@@ -4019,6 +4091,10 @@ var Button = /* @__PURE__ */ forwardRef(function Button2({
4019
4091
  leftIcon,
4020
4092
  rightIcon,
4021
4093
  fullWidth = false,
4094
+ hoverEffect,
4095
+ focusStyle,
4096
+ selected,
4097
+ cursor,
4022
4098
  disabled,
4023
4099
  children,
4024
4100
  ...props
@@ -4029,6 +4105,11 @@ var Button = /* @__PURE__ */ forwardRef(function Button2({
4029
4105
  "data-size": size,
4030
4106
  "data-loading": loading || void 0,
4031
4107
  "data-full-width": fullWidth || void 0,
4108
+ "data-hover-effect": hoverEffect,
4109
+ "data-focus-style": focusStyle,
4110
+ "data-selected": selected || void 0,
4111
+ "data-cursor": cursor,
4112
+ "aria-pressed": selected,
4032
4113
  className: cx(buttonClasses(variant, size), className),
4033
4114
  ...props
4034
4115
  };
@@ -4051,6 +4132,596 @@ var Button = /* @__PURE__ */ forwardRef(function Button2({
4051
4132
  }
4052
4133
  );
4053
4134
  });
4135
+ var toArray2 = (v) => v == null ? void 0 : Array.isArray(v) ? v : [v];
4136
+ var Slider = /* @__PURE__ */ forwardRef(function Slider2({
4137
+ className,
4138
+ value,
4139
+ defaultValue,
4140
+ min = 0,
4141
+ max = 100,
4142
+ step = 1,
4143
+ size = "md",
4144
+ marks,
4145
+ showTicks = false,
4146
+ tooltip = "none",
4147
+ formatValue,
4148
+ orientation = "horizontal",
4149
+ onValueChange,
4150
+ ...props
4151
+ }, ref) {
4152
+ const controlled = value !== void 0;
4153
+ const initial = toArray2(value) ?? toArray2(defaultValue) ?? [min];
4154
+ const [internal, setInternal] = useState(initial);
4155
+ const current = controlled ? toArray2(value) : internal;
4156
+ const handleChange = (next) => {
4157
+ if (!controlled) setInternal(next);
4158
+ onValueChange?.(next);
4159
+ };
4160
+ const fmt = (n) => formatValue ? formatValue(n) : n;
4161
+ const ticks = useMemo(() => {
4162
+ if (!showTicks) return [];
4163
+ const count = Math.floor((max - min) / step);
4164
+ if (count < 1 || count > 60) return [];
4165
+ return Array.from({ length: count + 1 }, (_, i) => min + i * step);
4166
+ }, [showTicks, min, max, step]);
4167
+ const pct = (n) => (n - min) / (max - min) * 100;
4168
+ return /* @__PURE__ */ jsxs(
4169
+ Slider$1.Root,
4170
+ {
4171
+ ref,
4172
+ "data-slot": "slider",
4173
+ "data-size": size,
4174
+ "data-orientation": orientation,
4175
+ "data-tooltip": tooltip === "none" ? void 0 : tooltip,
4176
+ className: cx("orynn-slider", className),
4177
+ min,
4178
+ max,
4179
+ step,
4180
+ orientation,
4181
+ onValueChange: handleChange,
4182
+ ...controlled ? { value: current } : { defaultValue: initial },
4183
+ ...props,
4184
+ children: [
4185
+ /* @__PURE__ */ jsxs(Slider$1.Track, { "data-slot": "slider-track", className: "orynn-slider__track", children: [
4186
+ /* @__PURE__ */ jsx(Slider$1.Range, { "data-slot": "slider-range", className: "orynn-slider__range" }),
4187
+ ticks.map((t) => /* @__PURE__ */ jsx(
4188
+ "span",
4189
+ {
4190
+ className: "orynn-slider__tick",
4191
+ "aria-hidden": "true",
4192
+ style: { insetInlineStart: `${pct(t)}%` }
4193
+ },
4194
+ `tick-${t}`
4195
+ ))
4196
+ ] }),
4197
+ current.map((v, i) => /* @__PURE__ */ jsx(
4198
+ Slider$1.Thumb,
4199
+ {
4200
+ "data-slot": "slider-thumb",
4201
+ className: "orynn-slider__thumb",
4202
+ "aria-label": props["aria-label"] ?? `Value ${i + 1}`,
4203
+ children: tooltip !== "none" && /* @__PURE__ */ jsx("span", { className: "orynn-slider__tooltip", "data-slot": "slider-tooltip", children: fmt(v) })
4204
+ },
4205
+ `thumb-${i}`
4206
+ )),
4207
+ marks && marks.length > 0 && /* @__PURE__ */ jsx("div", { className: "orynn-slider__marks", "aria-hidden": "true", children: marks.map((m) => /* @__PURE__ */ jsxs(
4208
+ "span",
4209
+ {
4210
+ className: "orynn-slider__mark",
4211
+ style: { insetInlineStart: `${pct(m.value)}%` },
4212
+ children: [
4213
+ /* @__PURE__ */ jsx("span", { className: "orynn-slider__mark-dot" }),
4214
+ m.label != null && /* @__PURE__ */ jsx("span", { className: "orynn-slider__mark-label", children: m.label })
4215
+ ]
4216
+ },
4217
+ `mark-${m.value}`
4218
+ )) })
4219
+ ]
4220
+ }
4221
+ );
4222
+ });
4223
+ var CIRCLE_SIZE = { sm: 40, md: 56, lg: 72 };
4224
+ var CIRCLE_STROKE = { sm: 4, md: 5, lg: 6 };
4225
+ var Progress = /* @__PURE__ */ forwardRef(function Progress2({
4226
+ className,
4227
+ value,
4228
+ max = 100,
4229
+ shape = "line",
4230
+ size = "md",
4231
+ variant = "default",
4232
+ showValue = false,
4233
+ label,
4234
+ striped = false,
4235
+ animated = false,
4236
+ radius,
4237
+ circleThickness,
4238
+ circleSize,
4239
+ formatValue,
4240
+ style,
4241
+ ...props
4242
+ }, ref) {
4243
+ const indeterminate = value == null;
4244
+ const clamped = indeterminate ? 0 : Math.min(max, Math.max(0, value));
4245
+ const pct = max > 0 ? clamped / max * 100 : 0;
4246
+ const text = formatValue ? formatValue(clamped, max) : `${Math.round(pct)}%`;
4247
+ const shared = {
4248
+ ref,
4249
+ "data-slot": "progress",
4250
+ "data-shape": shape,
4251
+ "data-size": size,
4252
+ "data-variant": variant,
4253
+ "data-indeterminate": indeterminate || void 0,
4254
+ value: indeterminate ? null : clamped,
4255
+ max,
4256
+ ...props
4257
+ };
4258
+ if (shape === "circle") {
4259
+ const dim = circleSize ?? CIRCLE_SIZE[size];
4260
+ const stroke = circleThickness ?? CIRCLE_STROKE[size];
4261
+ const r = (dim - stroke) / 2;
4262
+ const circ = 2 * Math.PI * r;
4263
+ const offset = indeterminate ? circ * 0.7 : circ * (1 - pct / 100);
4264
+ return /* @__PURE__ */ jsxs(
4265
+ Progress$1.Root,
4266
+ {
4267
+ ...shared,
4268
+ className: cx("orynn-progress", "orynn-progress--circle", className),
4269
+ style: { inlineSize: dim, blockSize: dim, ...style },
4270
+ children: [
4271
+ /* @__PURE__ */ jsxs("svg", { className: "orynn-progress__svg", viewBox: `0 0 ${dim} ${dim}`, "aria-hidden": "true", children: [
4272
+ /* @__PURE__ */ jsx(
4273
+ "circle",
4274
+ {
4275
+ className: "orynn-progress__ring-track",
4276
+ cx: dim / 2,
4277
+ cy: dim / 2,
4278
+ r,
4279
+ fill: "none",
4280
+ strokeWidth: stroke
4281
+ }
4282
+ ),
4283
+ /* @__PURE__ */ jsx(
4284
+ "circle",
4285
+ {
4286
+ className: "orynn-progress__ring",
4287
+ cx: dim / 2,
4288
+ cy: dim / 2,
4289
+ r,
4290
+ fill: "none",
4291
+ strokeWidth: stroke,
4292
+ strokeLinecap: "round",
4293
+ strokeDasharray: circ,
4294
+ strokeDashoffset: offset
4295
+ }
4296
+ )
4297
+ ] }),
4298
+ showValue && !indeterminate && /* @__PURE__ */ jsx("span", { className: "orynn-progress__circle-value", children: text })
4299
+ ]
4300
+ }
4301
+ );
4302
+ }
4303
+ return /* @__PURE__ */ jsxs("div", { className: "orynn-progress__wrap", children: [
4304
+ (label != null || showValue && !indeterminate) && /* @__PURE__ */ jsxs("div", { className: "orynn-progress__meta", children: [
4305
+ label != null && /* @__PURE__ */ jsx("span", { className: "orynn-progress__label", children: label }),
4306
+ showValue && !indeterminate && /* @__PURE__ */ jsx("span", { className: "orynn-progress__value", children: text })
4307
+ ] }),
4308
+ /* @__PURE__ */ jsx(
4309
+ Progress$1.Root,
4310
+ {
4311
+ ...shared,
4312
+ "data-striped": striped || animated || void 0,
4313
+ "data-animated": animated || void 0,
4314
+ className: cx("orynn-progress", className),
4315
+ style: { borderRadius: radius != null ? radius : void 0, ...style },
4316
+ children: /* @__PURE__ */ jsx(
4317
+ Progress$1.Indicator,
4318
+ {
4319
+ className: "orynn-progress__bar",
4320
+ "data-slot": "progress-bar",
4321
+ style: {
4322
+ transform: indeterminate ? void 0 : `translateX(-${100 - pct}%)`
4323
+ }
4324
+ }
4325
+ )
4326
+ }
4327
+ )
4328
+ ] });
4329
+ });
4330
+ var toasts = [];
4331
+ var listeners = /* @__PURE__ */ new Set();
4332
+ var counter = 0;
4333
+ var emit = () => {
4334
+ for (const l of listeners) l(toasts);
4335
+ };
4336
+ var subscribe = (l) => {
4337
+ listeners.add(l);
4338
+ return () => {
4339
+ listeners.delete(l);
4340
+ };
4341
+ };
4342
+ var getSnapshot = () => toasts;
4343
+ var upsert = (record) => {
4344
+ const i = toasts.findIndex((t) => t.id === record.id);
4345
+ toasts = i === -1 ? [...toasts, record] : toasts.map((t) => t.id === record.id ? record : t);
4346
+ emit();
4347
+ };
4348
+ var dismissToast = (id) => {
4349
+ toasts = id == null ? [] : toasts.filter((t) => t.id !== id);
4350
+ emit();
4351
+ };
4352
+ var isMessage = (v) => typeof v === "string" || typeof v === "number" || isValidElement(v);
4353
+ var normalize = (input, extra) => isMessage(input) ? { title: input, ...extra } : { ...input, ...extra };
4354
+ function base2(input, extra) {
4355
+ const opts = normalize(input, extra);
4356
+ const id = opts.id ?? `toast-${++counter}`;
4357
+ upsert({ ...opts, id, createdAt: Date.now() });
4358
+ return id;
4359
+ }
4360
+ var withVariant = (variant) => (message, opts) => base2(message, { ...opts, variant });
4361
+ var toast = base2;
4362
+ toast.success = withVariant("success");
4363
+ toast.error = withVariant("error");
4364
+ toast.warning = withVariant("warning");
4365
+ toast.info = withVariant("info");
4366
+ toast.loading = withVariant("loading");
4367
+ toast.dismiss = dismissToast;
4368
+ toast.promise = (promise, msgs, opts) => {
4369
+ const id = base2(msgs.loading, {
4370
+ ...opts,
4371
+ variant: "loading",
4372
+ duration: Number.POSITIVE_INFINITY
4373
+ });
4374
+ promise.then(
4375
+ (value) => {
4376
+ const m = typeof msgs.success === "function" ? msgs.success(value) : msgs.success;
4377
+ base2(m, { ...opts, id, variant: "success", duration: opts?.duration });
4378
+ },
4379
+ (err) => {
4380
+ const m = typeof msgs.error === "function" ? msgs.error(err) : msgs.error;
4381
+ base2(m, { ...opts, id, variant: "error", duration: opts?.duration });
4382
+ }
4383
+ );
4384
+ return promise;
4385
+ };
4386
+ function AngleIcon() {
4387
+ return /* @__PURE__ */ jsx("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
4388
+ "path",
4389
+ {
4390
+ d: "M12 8v5M12 16h.01M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z",
4391
+ stroke: "currentColor",
4392
+ strokeWidth: "2",
4393
+ strokeLinecap: "round",
4394
+ strokeLinejoin: "round"
4395
+ }
4396
+ ) });
4397
+ }
4398
+ function InfoIcon() {
4399
+ return /* @__PURE__ */ jsxs("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
4400
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "2" }),
4401
+ /* @__PURE__ */ jsx("path", { d: "M12 11v5M12 8h.01", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
4402
+ ] });
4403
+ }
4404
+ function CircleXIcon() {
4405
+ return /* @__PURE__ */ jsxs("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
4406
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "2" }),
4407
+ /* @__PURE__ */ jsx("path", { d: "m15 9-6 6M9 9l6 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
4408
+ ] });
4409
+ }
4410
+ var VARIANT_ICON = {
4411
+ default: null,
4412
+ success: /* @__PURE__ */ jsx(CheckIcon, {}),
4413
+ error: /* @__PURE__ */ jsx(CircleXIcon, {}),
4414
+ warning: /* @__PURE__ */ jsx(AngleIcon, {}),
4415
+ info: /* @__PURE__ */ jsx(InfoIcon, {}),
4416
+ loading: /* @__PURE__ */ jsx(SpinnerIcon, { className: "orynn-spin" })
4417
+ };
4418
+ var SWIPE = {
4419
+ "top-left": "left",
4420
+ "top-center": "up",
4421
+ "top-right": "right",
4422
+ "bottom-left": "left",
4423
+ "bottom-center": "down",
4424
+ "bottom-right": "right"
4425
+ };
4426
+ function ToastItem({
4427
+ record,
4428
+ duration,
4429
+ closeButton
4430
+ }) {
4431
+ const variant = record.variant ?? "default";
4432
+ const icon = record.icon === null ? null : record.icon ?? VARIANT_ICON[variant];
4433
+ const showClose = record.dismissible ?? closeButton;
4434
+ const d = record.duration ?? (variant === "loading" ? Number.POSITIVE_INFINITY : duration);
4435
+ return /* @__PURE__ */ jsxs(
4436
+ Toast.Root,
4437
+ {
4438
+ "data-slot": "toast",
4439
+ "data-variant": variant,
4440
+ className: "orynn-toast",
4441
+ duration: Number.isFinite(d) ? d : 1e9,
4442
+ onOpenChange: (open) => {
4443
+ record.onOpenChange?.(open);
4444
+ if (!open) dismissToast(record.id);
4445
+ },
4446
+ children: [
4447
+ icon != null && /* @__PURE__ */ jsx("span", { className: "orynn-toast__icon", "data-slot": "toast-icon", "aria-hidden": "true", children: icon }),
4448
+ /* @__PURE__ */ jsxs("div", { className: "orynn-toast__content", children: [
4449
+ record.title != null && /* @__PURE__ */ jsx(Toast.Title, { className: "orynn-toast__title", children: record.title }),
4450
+ record.description != null && /* @__PURE__ */ jsx(Toast.Description, { className: "orynn-toast__description", children: record.description })
4451
+ ] }),
4452
+ record.action && /* @__PURE__ */ jsx(
4453
+ Toast.Action,
4454
+ {
4455
+ className: "orynn-toast__action",
4456
+ altText: record.action.altText ?? (typeof record.action.label === "string" ? record.action.label : "Action"),
4457
+ onClick: record.action.onClick,
4458
+ children: record.action.label
4459
+ }
4460
+ ),
4461
+ showClose && /* @__PURE__ */ jsx(
4462
+ Toast.Close,
4463
+ {
4464
+ className: "orynn-toast__close",
4465
+ "aria-label": "Dismiss",
4466
+ "data-slot": "toast-close",
4467
+ children: /* @__PURE__ */ jsx(XIcon, {})
4468
+ }
4469
+ )
4470
+ ]
4471
+ }
4472
+ );
4473
+ }
4474
+ function Toaster({
4475
+ position = "bottom-right",
4476
+ duration = 4e3,
4477
+ visibleToasts = 4,
4478
+ closeButton = true,
4479
+ richColors = false,
4480
+ gap = 12,
4481
+ offset = 24,
4482
+ className
4483
+ }) {
4484
+ const records = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
4485
+ const shown = records.slice(-visibleToasts);
4486
+ const [side] = position.split("-");
4487
+ return /* @__PURE__ */ jsxs(Toast.Provider, { swipeDirection: SWIPE[position], duration, children: [
4488
+ shown.map((record) => /* @__PURE__ */ jsx(ToastItem, { record, duration, closeButton }, record.id)),
4489
+ /* @__PURE__ */ jsx(
4490
+ Toast.Viewport,
4491
+ {
4492
+ "data-slot": "toaster",
4493
+ "data-position": position,
4494
+ "data-rich-colors": richColors || void 0,
4495
+ className: cx("orynn-toaster", className),
4496
+ style: {
4497
+ "--orynn-toaster-gap": `${gap}px`,
4498
+ "--orynn-toaster-offset": `${offset}px`,
4499
+ [side]: `${offset}px`
4500
+ }
4501
+ }
4502
+ )
4503
+ ] });
4504
+ }
4505
+ function useToast() {
4506
+ const toasts2 = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
4507
+ return { toast, dismiss: dismissToast, toasts: toasts2 };
4508
+ }
4509
+
4510
+ // src/primitives/Pagination/use-pagination.ts
4511
+ var range = (start, end) => Array.from({ length: Math.max(0, end - start + 1) }, (_, i) => start + i);
4512
+ function usePagination({
4513
+ page,
4514
+ count,
4515
+ total,
4516
+ pageSize = 10,
4517
+ siblingCount = 1,
4518
+ boundaryCount = 1
4519
+ }) {
4520
+ const pageCount = Math.max(
4521
+ 1,
4522
+ count ?? (total != null ? Math.ceil(total / Math.max(1, pageSize)) : 1)
4523
+ );
4524
+ const current = Math.min(Math.max(1, page), pageCount);
4525
+ const startPages = range(1, Math.min(boundaryCount, pageCount));
4526
+ const endPages = range(Math.max(pageCount - boundaryCount + 1, boundaryCount + 1), pageCount);
4527
+ const siblingsStart = Math.max(
4528
+ Math.min(current - siblingCount, pageCount - boundaryCount - siblingCount * 2 - 1),
4529
+ boundaryCount + 2
4530
+ );
4531
+ const siblingsEnd = Math.min(
4532
+ Math.max(current + siblingCount, boundaryCount + siblingCount * 2 + 2),
4533
+ endPages.length > 0 ? endPages[0] - 2 : pageCount - 1
4534
+ );
4535
+ const slots = [
4536
+ ...startPages,
4537
+ ...siblingsStart > boundaryCount + 2 ? ["ellipsis-start"] : boundaryCount + 1 < pageCount - boundaryCount ? [boundaryCount + 1] : [],
4538
+ ...range(siblingsStart, siblingsEnd),
4539
+ ...siblingsEnd < pageCount - boundaryCount - 1 ? ["ellipsis-end"] : pageCount - boundaryCount > boundaryCount ? [pageCount - boundaryCount] : [],
4540
+ ...endPages
4541
+ ];
4542
+ return {
4543
+ pageCount,
4544
+ page: current,
4545
+ hasPrev: current > 1,
4546
+ hasNext: current < pageCount,
4547
+ slots
4548
+ };
4549
+ }
4550
+ var PaginationContent = /* @__PURE__ */ forwardRef(
4551
+ function PaginationContent2({ className, ...props }, ref) {
4552
+ return /* @__PURE__ */ jsx(
4553
+ "ul",
4554
+ {
4555
+ ref,
4556
+ "data-slot": "pagination-content",
4557
+ className: cx("orynn-pagination__list", className),
4558
+ ...props
4559
+ }
4560
+ );
4561
+ }
4562
+ );
4563
+ var PaginationItem = /* @__PURE__ */ forwardRef(
4564
+ function PaginationItem2({ className, ...props }, ref) {
4565
+ return /* @__PURE__ */ jsx(
4566
+ "li",
4567
+ {
4568
+ ref,
4569
+ "data-slot": "pagination-item",
4570
+ className: cx("orynn-pagination__item", className),
4571
+ ...props
4572
+ }
4573
+ );
4574
+ }
4575
+ );
4576
+ var PaginationLink = /* @__PURE__ */ forwardRef(
4577
+ function PaginationLink2({ className, isActive, size = "md", type, ...props }, ref) {
4578
+ return /* @__PURE__ */ jsx(
4579
+ "button",
4580
+ {
4581
+ ref,
4582
+ type: type ?? "button",
4583
+ "data-slot": "pagination-link",
4584
+ "data-active": isActive || void 0,
4585
+ "data-size": size,
4586
+ "aria-current": isActive ? "page" : void 0,
4587
+ className: cx("orynn-pagination__link", className),
4588
+ ...props
4589
+ }
4590
+ );
4591
+ }
4592
+ );
4593
+ var PaginationEllipsis = /* @__PURE__ */ forwardRef(function PaginationEllipsis2({ className, children, ...props }, ref) {
4594
+ return /* @__PURE__ */ jsx(
4595
+ "span",
4596
+ {
4597
+ ref,
4598
+ "aria-hidden": "true",
4599
+ "data-slot": "pagination-ellipsis",
4600
+ className: cx("orynn-pagination__ellipsis", className),
4601
+ ...props,
4602
+ children: children ?? "\u2026"
4603
+ }
4604
+ );
4605
+ });
4606
+ var Pagination = /* @__PURE__ */ forwardRef(
4607
+ function Pagination2({
4608
+ className,
4609
+ page,
4610
+ count,
4611
+ total,
4612
+ pageSize,
4613
+ siblingCount,
4614
+ boundaryCount,
4615
+ onPageChange,
4616
+ showFirstLast = false,
4617
+ showPrevNext = true,
4618
+ iconOnly = false,
4619
+ size = "md",
4620
+ variant = "outline",
4621
+ disabled = false,
4622
+ labels,
4623
+ prevIcon,
4624
+ nextIcon,
4625
+ ...props
4626
+ }, ref) {
4627
+ const model = usePagination({ page, count, total, pageSize, siblingCount, boundaryCount });
4628
+ const L = {
4629
+ previous: labels?.previous ?? "Previous",
4630
+ next: labels?.next ?? "Next",
4631
+ first: labels?.first ?? "First page",
4632
+ last: labels?.last ?? "Last page",
4633
+ ariaLabel: labels?.ariaLabel ?? "Pagination",
4634
+ page: labels?.page ?? ((n) => `Page ${n}`)
4635
+ };
4636
+ const go = (p) => {
4637
+ if (disabled) return;
4638
+ const next = Math.min(Math.max(1, p), model.pageCount);
4639
+ if (next !== model.page) onPageChange(next);
4640
+ };
4641
+ return /* @__PURE__ */ jsx(
4642
+ "nav",
4643
+ {
4644
+ ref,
4645
+ "aria-label": L.ariaLabel,
4646
+ "data-slot": "pagination",
4647
+ "data-size": size,
4648
+ "data-variant": variant,
4649
+ "data-disabled": disabled || void 0,
4650
+ className: cx("orynn-pagination", className),
4651
+ ...props,
4652
+ children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
4653
+ showFirstLast && /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
4654
+ PaginationLink,
4655
+ {
4656
+ size,
4657
+ "aria-label": L.first,
4658
+ disabled: disabled || !model.hasPrev,
4659
+ onClick: () => go(1),
4660
+ children: [
4661
+ /* @__PURE__ */ jsx(ChevronLeftIcon, {}),
4662
+ /* @__PURE__ */ jsx(ChevronLeftIcon, { style: { marginInlineStart: "-0.65em" } })
4663
+ ]
4664
+ }
4665
+ ) }),
4666
+ showPrevNext && /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
4667
+ PaginationLink,
4668
+ {
4669
+ size,
4670
+ "aria-label": L.previous,
4671
+ disabled: disabled || !model.hasPrev,
4672
+ className: "orynn-pagination__nav",
4673
+ onClick: () => go(model.page - 1),
4674
+ children: [
4675
+ prevIcon ?? /* @__PURE__ */ jsx(ChevronLeftIcon, {}),
4676
+ !iconOnly && /* @__PURE__ */ jsx("span", { className: "orynn-pagination__nav-label", children: L.previous })
4677
+ ]
4678
+ }
4679
+ ) }),
4680
+ model.slots.map(
4681
+ (slot) => typeof slot === "number" ? /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
4682
+ PaginationLink,
4683
+ {
4684
+ size,
4685
+ isActive: slot === model.page,
4686
+ "aria-label": L.page(slot),
4687
+ disabled,
4688
+ onClick: () => go(slot),
4689
+ children: slot
4690
+ }
4691
+ ) }, slot) : /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, slot)
4692
+ ),
4693
+ showPrevNext && /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
4694
+ PaginationLink,
4695
+ {
4696
+ size,
4697
+ "aria-label": L.next,
4698
+ disabled: disabled || !model.hasNext,
4699
+ className: "orynn-pagination__nav",
4700
+ onClick: () => go(model.page + 1),
4701
+ children: [
4702
+ !iconOnly && /* @__PURE__ */ jsx("span", { className: "orynn-pagination__nav-label", children: L.next }),
4703
+ nextIcon ?? /* @__PURE__ */ jsx(ChevronRightIcon, {})
4704
+ ]
4705
+ }
4706
+ ) }),
4707
+ showFirstLast && /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
4708
+ PaginationLink,
4709
+ {
4710
+ size,
4711
+ "aria-label": L.last,
4712
+ disabled: disabled || !model.hasNext,
4713
+ onClick: () => go(model.pageCount),
4714
+ children: [
4715
+ /* @__PURE__ */ jsx(ChevronRightIcon, {}),
4716
+ /* @__PURE__ */ jsx(ChevronRightIcon, { style: { marginInlineStart: "-0.65em" } })
4717
+ ]
4718
+ }
4719
+ ) })
4720
+ ] })
4721
+ }
4722
+ );
4723
+ }
4724
+ );
4054
4725
  var Label = /* @__PURE__ */ forwardRef(function Label2({ className, required, optional, children, ...props }, ref) {
4055
4726
  return /* @__PURE__ */ jsxs(
4056
4727
  Label$1.Root,
@@ -4794,6 +5465,6 @@ function standardSchemaResolver(schema) {
4794
5465
  };
4795
5466
  }
4796
5467
 
4797
- export { Alert, AlertDescription, AlertTitle, Badge, Button, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CheckboxGroup, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPortal, DialogTitle, DialogTrigger, Dropdown, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, FORM_ERROR_KEY, Field, FieldBox, Fieldset, FieldsetView, Form, Input, Label, NumberField, OrynnProvider, Popover2 as Popover, PopoverAnchor, PopoverArrow, PopoverClose, PopoverContent, PopoverTrigger, Radio, RadioGroup, Dropdown as Select, Separator, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeClasses, builtInRules, buttonClasses, createRegistry, createRuleResolver, defaultRegistry, defaultResolver, normalizeConfig, registerField, registerRule, resolveThemeVars, standardSchemaResolver, useFieldsetState, useOrynnTheme, usePortalContainer };
5468
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, Button, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CheckboxGroup, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPortal, DialogTitle, DialogTrigger, Dropdown, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, FORM_ERROR_KEY, Field, FieldBox, Fieldset, FieldsetView, Form, Input, Label, NumberField, OrynnProvider, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, Popover2 as Popover, PopoverAnchor, PopoverArrow, PopoverClose, PopoverContent, PopoverTrigger, Progress, Radio, RadioGroup, Dropdown as Select, Separator, Slider, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeClasses, builtInRules, buttonClasses, createRegistry, createRuleResolver, defaultRegistry, defaultResolver, normalizeConfig, registerField, registerRule, resolveThemeVars, standardSchemaResolver, toast, useFieldsetState, useOrynnTheme, usePagination, usePortalContainer, useToast };
4798
5469
  //# sourceMappingURL=index.js.map
4799
5470
  //# sourceMappingURL=index.js.map