@tryghost/shade 0.1.0-alpha.0 → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -64
- package/es/components/page-templates/list-page.js +2 -1
- package/es/components/page-templates/list-page.js.map +1 -1
- package/es/components/patterns/gh-chart.js +2 -1
- package/es/components/patterns/gh-chart.js.map +1 -1
- package/es/components/patterns/page-header.js +5 -2
- package/es/components/patterns/page-header.js.map +1 -1
- package/es/components/ui/chart.js +2 -29
- package/es/components/ui/chart.js.map +1 -1
- package/es/components/ui/combobox.js +2 -2
- package/es/components/ui/combobox.js.map +1 -1
- package/es/components/ui/dialog.js +32 -8
- package/es/components/ui/dialog.js.map +1 -1
- package/es/components/ui/time-picker.js +12 -17
- package/es/components/ui/time-picker.js.map +1 -1
- package/es/components/ui/token-field.js +2 -2
- package/es/components/ui/token-field.js.map +1 -1
- package/es/components.js +2 -2
- package/es/index.js +2 -2
- package/es/lib/date-utils.js +151 -0
- package/es/lib/date-utils.js.map +1 -0
- package/es/lib/ds-utils.js +1 -71
- package/es/lib/ds-utils.js.map +1 -1
- package/es/lib/utils.js +2 -1
- package/es/utils.js +2 -1
- package/package.json +4 -3
- package/styles.css +6 -0
- package/types/components/page-templates/list-page.d.ts +2 -1
- package/types/components/page-templates/list-page.d.ts.map +1 -1
- package/types/components/patterns/page-header.d.ts +5 -2
- package/types/components/patterns/page-header.d.ts.map +1 -1
- package/types/components/patterns/share-modal.d.ts +1 -1
- package/types/components/ui/chart.d.ts +1 -17
- package/types/components/ui/chart.d.ts.map +1 -1
- package/types/components/ui/combobox.d.ts.map +1 -1
- package/types/components/ui/dialog.d.ts +11 -2
- package/types/components/ui/dialog.d.ts.map +1 -1
- package/types/components/ui/time-picker.d.ts +6 -3
- package/types/components/ui/time-picker.d.ts.map +1 -1
- package/types/components/ui/token-field.d.ts +2 -2
- package/types/components/ui/token-field.d.ts.map +1 -1
- package/types/lib/date-utils.d.ts +17 -0
- package/types/lib/date-utils.d.ts.map +1 -0
- package/types/lib/ds-utils.d.ts +0 -16
- package/types/lib/ds-utils.d.ts.map +1 -1
- package/types/lib/utils.d.ts +1 -0
- package/types/lib/utils.d.ts.map +1 -1
- package/types/utils.d.ts +2 -1
- package/types/utils.d.ts.map +1 -1
|
@@ -1,25 +1,49 @@
|
|
|
1
1
|
import { cn } from "../../lib/ds-utils.js";
|
|
2
2
|
import { ShadeScope } from "../../shade-scope.js";
|
|
3
3
|
import * as React$1 from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
6
6
|
//#region src/components/ui/dialog.tsx
|
|
7
|
-
var
|
|
7
|
+
var DialogModalContext = React$1.createContext(true);
|
|
8
|
+
var Dialog = ({ modal = true, ...props }) => /* @__PURE__ */ jsx(DialogModalContext.Provider, {
|
|
9
|
+
value: modal,
|
|
10
|
+
children: /* @__PURE__ */ jsx(DialogPrimitive.Root, {
|
|
11
|
+
modal,
|
|
12
|
+
...props
|
|
13
|
+
})
|
|
14
|
+
});
|
|
8
15
|
var DialogTrigger = DialogPrimitive.Trigger;
|
|
9
16
|
var DialogPortal = DialogPrimitive.Portal;
|
|
10
17
|
var DialogClose = DialogPrimitive.Close;
|
|
11
18
|
var DialogOverlay = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(DialogPrimitive.Overlay, {
|
|
12
19
|
ref,
|
|
13
20
|
className: cn("fixed inset-0 z-50 transform-gpu bg-black/30 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0 dark:bg-black/60", className),
|
|
21
|
+
"data-slot": "dialog-overlay",
|
|
14
22
|
...props
|
|
15
23
|
}));
|
|
16
24
|
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
var dialogPanelClassName = "z-50 grid w-full max-w-lg transform-gpu gap-6 bg-surface-elevated-2 p-6 shadow-lg outline-hidden duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95";
|
|
26
|
+
var DialogContent = React$1.forwardRef(({ className, children, scroll = "fixed", ...props }, ref) => {
|
|
27
|
+
const modal = React$1.useContext(DialogModalContext);
|
|
28
|
+
const panel = /* @__PURE__ */ jsx(DialogPrimitive.Content, {
|
|
29
|
+
ref,
|
|
30
|
+
className: cn(scroll === "overlay" ? "pointer-events-auto relative rounded-lg" : "fixed top-[8vmin] left-[50%] translate-x-[-50%] sm:rounded-lg", dialogPanelClassName, className),
|
|
31
|
+
...props,
|
|
32
|
+
children
|
|
33
|
+
});
|
|
34
|
+
const scrollingPanel = /* @__PURE__ */ jsx("div", {
|
|
35
|
+
className: "flex min-h-full items-start justify-center px-4 py-[8vmin]",
|
|
36
|
+
children: panel
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsx(DialogPortal, { children: /* @__PURE__ */ jsx(ShadeScope, { children: scroll === "overlay" ? modal ? /* @__PURE__ */ jsx(DialogOverlay, {
|
|
39
|
+
className: "overflow-y-auto duration-200",
|
|
40
|
+
children: scrollingPanel
|
|
41
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
42
|
+
className: "pointer-events-none fixed inset-0 z-50 overflow-y-auto",
|
|
43
|
+
"data-slot": "dialog-scroller",
|
|
44
|
+
children: scrollingPanel
|
|
45
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(DialogOverlay, {}), panel] }) }) });
|
|
46
|
+
});
|
|
23
47
|
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
24
48
|
var DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
25
49
|
className: cn("flex flex-col gap-y-1.5 text-center sm:text-left", className),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","names":[],"sources":["../../../src/components/ui/dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\n\nimport { cn } from '@/lib/utils';\nimport { ShadeScope } from '@/shade-scope';\n\nconst Dialog = DialogPrimitive.Root;\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={cn(\n 'fixed inset-0 z-50 transform-gpu bg-black/30 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0 dark:bg-black/60',\n className,\n )}\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\
|
|
1
|
+
{"version":3,"file":"dialog.js","names":[],"sources":["../../../src/components/ui/dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\n\nimport { cn } from '@/lib/utils';\nimport { ShadeScope } from '@/shade-scope';\n\n// Radix keeps whether a dialog is modal to itself, and the overlay scroll layout needs to know.\nconst DialogModalContext = React.createContext(true);\n\nconst Dialog = ({ modal = true, ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) => (\n <DialogModalContext.Provider value={modal}>\n <DialogPrimitive.Root modal={modal} {...props} />\n </DialogModalContext.Provider>\n);\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={cn(\n 'fixed inset-0 z-50 transform-gpu bg-black/30 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0 dark:bg-black/60',\n className,\n )}\n data-slot=\"dialog-overlay\"\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\n// The panel itself, shared by both ways a dialog can sit on the page.\nconst dialogPanelClassName =\n 'z-50 grid w-full max-w-lg transform-gpu gap-6 bg-surface-elevated-2 p-6 shadow-lg outline-hidden duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95';\n\nexport interface DialogContentProps extends React.ComponentPropsWithoutRef<\n typeof DialogPrimitive.Content\n> {\n /**\n * How a dialog taller than the window scrolls. `fixed` (the default) pins the dialog near\n * the top of the window, so it needs its own height limit and inner scroll. `overlay` makes\n * the backdrop the scroll container instead: the whole dialog scrolls as one piece, the way\n * a page does.\n */\n scroll?: 'fixed' | 'overlay';\n}\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n DialogContentProps\n>(({ className, children, scroll = 'fixed', ...props }, ref) => {\n const modal = React.useContext(DialogModalContext);\n\n const panel = (\n <DialogPrimitive.Content\n ref={ref}\n className={cn(\n scroll === 'overlay'\n ? 'pointer-events-auto relative rounded-lg'\n : 'fixed top-[8vmin] left-[50%] translate-x-[-50%] sm:rounded-lg',\n dialogPanelClassName,\n className,\n )}\n {...props}\n >\n {children}\n </DialogPrimitive.Content>\n );\n\n // The space around the dialog is padding on this wrapper, not on the scroll container:\n // browsers leave a scroll container's own bottom padding out of what it scrolls, which\n // would leave the dialog flush with the bottom of the window.\n const scrollingPanel = (\n <div className=\"flex min-h-full items-start justify-center px-4 py-[8vmin]\">{panel}</div>\n );\n\n return (\n <DialogPortal>\n <ShadeScope>\n {scroll === 'overlay' ? (\n modal ? (\n // The dialog sits inside the backdrop here, so the backdrop animates as long as the\n // dialog does; otherwise closing unmounts the dialog part-way through its animation.\n <DialogOverlay className=\"overflow-y-auto duration-200\">{scrollingPanel}</DialogOverlay>\n ) : (\n // Radix renders no backdrop for a non-modal dialog, and the page behind stays\n // usable, so this scroll container lets presses beside the dialog through.\n <div\n className=\"pointer-events-none fixed inset-0 z-50 overflow-y-auto\"\n data-slot=\"dialog-scroller\"\n >\n {scrollingPanel}\n </div>\n )\n ) : (\n <>\n <DialogOverlay />\n {panel}\n </>\n )}\n </ShadeScope>\n </DialogPortal>\n );\n});\nDialogContent.displayName = DialogPrimitive.Content.displayName;\n\nconst DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div className={cn('flex flex-col gap-y-1.5 text-center sm:text-left', className)} {...props} />\n);\nDialogHeader.displayName = 'DialogHeader';\n\nconst DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div\n className={cn(\n 'flex flex-col-reverse sm:flex-row sm:items-end sm:justify-end sm:gap-2 [&_button]:min-w-20',\n className,\n )}\n {...props}\n />\n);\nDialogFooter.displayName = 'DialogFooter';\n\nconst DialogTitle = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Title>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn('text-xl leading-none font-semibold tracking-tight', className)}\n {...props}\n />\n));\nDialogTitle.displayName = DialogPrimitive.Title.displayName;\n\nconst DialogDescription = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Description>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn('text-muted-foreground', className)}\n {...props}\n />\n));\nDialogDescription.displayName = DialogPrimitive.Description.displayName;\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n DialogHeader,\n DialogFooter,\n DialogTitle,\n DialogDescription,\n};\n"],"mappings":";;;;;;AAOA,IAAM,qBAAqB,QAAM,cAAc,IAAI;AAEnD,IAAM,UAAU,EAAE,QAAQ,MAAM,GAAG,YACjC,oBAAC,mBAAmB,UAApB;CAA6B,OAAO;WAClC,oBAAC,gBAAgB,MAAjB;EAA6B;EAAO,GAAI;CAAQ,CAAA;AACrB,CAAA;AAG/B,IAAM,gBAAgB,gBAAgB;AAEtC,IAAM,eAAe,gBAAgB;AAErC,IAAM,cAAc,gBAAgB;AAEpC,IAAM,gBAAgB,QAAM,YAGzB,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,SAAjB;CACO;CACL,WAAW,GACT,yLACA,SACF;CACA,aAAU;CACV,GAAI;AACL,CAAA,CACF;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAGpD,IAAM,uBACJ;AAcF,IAAM,gBAAgB,QAAM,YAGzB,EAAE,WAAW,UAAU,SAAS,SAAS,GAAG,SAAS,QAAQ;CAC9D,MAAM,QAAQ,QAAM,WAAW,kBAAkB;CAEjD,MAAM,QACJ,oBAAC,gBAAgB,SAAjB;EACO;EACL,WAAW,GACT,WAAW,YACP,4CACA,iEACJ,sBACA,SACF;EACA,GAAI;EAEH;CACsB,CAAA;CAM3B,MAAM,iBACJ,oBAAC,OAAD;EAAK,WAAU;YAA8D;CAAW,CAAA;CAG1F,OACE,oBAAC,cAAD,EAAA,UACE,oBAAC,YAAD,EAAA,UACG,WAAW,YACV,QAGE,oBAAC,eAAD;EAAe,WAAU;YAAgC;CAA8B,CAAA,IAIvF,oBAAC,OAAD;EACE,WAAU;EACV,aAAU;YAET;CACE,CAAA,IAGP,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,eAAD,CAAgB,CAAA,GACf,KACD,EAAA,CAAA,EAEM,CAAA,EACA,CAAA;AAElB,CAAC;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,IAAM,gBAAgB,EAAE,WAAW,GAAG,YACpC,oBAAC,OAAD;CAAK,WAAW,GAAG,oDAAoD,SAAS;CAAG,GAAI;AAAQ,CAAA;AAEjG,aAAa,cAAc;AAE3B,IAAM,gBAAgB,EAAE,WAAW,GAAG,YACpC,oBAAC,OAAD;CACE,WAAW,GACT,8FACA,SACF;CACA,GAAI;AACL,CAAA;AAEH,aAAa,cAAc;AAE3B,IAAM,cAAc,QAAM,YAGvB,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,OAAjB;CACO;CACL,WAAW,GAAG,qDAAqD,SAAS;CAC5E,GAAI;AACL,CAAA,CACF;AACD,YAAY,cAAc,gBAAgB,MAAM;AAEhD,IAAM,oBAAoB,QAAM,YAG7B,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,aAAjB;CACO;CACL,WAAW,GAAG,yBAAyB,SAAS;CAChD,GAAI;AACL,CAAA,CACF;AACD,kBAAkB,cAAc,gBAAgB,YAAY"}
|
|
@@ -5,26 +5,21 @@ import { forwardRef } from "react";
|
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
//#region src/components/ui/time-picker.tsx
|
|
7
7
|
/** Native, keyboard-accessible time input. Values use HH:mm and remain consumer-owned. */
|
|
8
|
-
var TimePicker = forwardRef(function TimePicker({ className,
|
|
8
|
+
var TimePicker = forwardRef(function TimePicker({ className, prefix, disabled, step = 60, ...props }, ref) {
|
|
9
9
|
return /* @__PURE__ */ jsxs(InputGroup, {
|
|
10
10
|
className: cn("min-w-0", className),
|
|
11
11
|
"data-disabled": disabled,
|
|
12
|
-
children: [
|
|
13
|
-
|
|
14
|
-
/* @__PURE__ */ jsx(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
align: "inline-end",
|
|
24
|
-
className: "text-sm font-normal",
|
|
25
|
-
children: suffix
|
|
26
|
-
}) : null
|
|
27
|
-
]
|
|
12
|
+
children: [/* @__PURE__ */ jsx(InputGroupAddon, {
|
|
13
|
+
className: prefix ? "text-sm font-normal" : void 0,
|
|
14
|
+
children: prefix ?? /* @__PURE__ */ jsx(Clock, { "aria-hidden": "true" })
|
|
15
|
+
}), /* @__PURE__ */ jsx(InputGroupInput, {
|
|
16
|
+
ref,
|
|
17
|
+
className: "min-w-0 appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none",
|
|
18
|
+
disabled,
|
|
19
|
+
step,
|
|
20
|
+
type: "time",
|
|
21
|
+
...props
|
|
22
|
+
})]
|
|
28
23
|
});
|
|
29
24
|
});
|
|
30
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-picker.js","names":[],"sources":["../../../src/components/ui/time-picker.tsx"],"sourcesContent":["import { forwardRef, type ComponentProps, type ReactNode } from 'react';\nimport { Clock } from 'lucide-react';\nimport { InputGroup, InputGroupAddon, InputGroupInput } from '@/components/ui/input-group';\nimport { cn } from '@/lib/utils';\n\nexport interface TimePickerProps extends Omit<ComponentProps<'input'>, 'type' | 'size'> {\n
|
|
1
|
+
{"version":3,"file":"time-picker.js","names":[],"sources":["../../../src/components/ui/time-picker.tsx"],"sourcesContent":["import { forwardRef, type ComponentProps, type ReactNode } from 'react';\nimport { Clock } from 'lucide-react';\nimport { InputGroup, InputGroupAddon, InputGroupInput } from '@/components/ui/input-group';\nimport { cn } from '@/lib/utils';\n\nexport interface TimePickerProps extends Omit<ComponentProps<'input'>, 'type' | 'size' | 'prefix'> {\n /**\n * Optional leading context, such as a timezone abbreviation. It takes the\n * clock icon's place, leaving a 12-hour locale's AM/PM room in narrow fields.\n */\n prefix?: ReactNode;\n}\n\n/** Native, keyboard-accessible time input. Values use HH:mm and remain consumer-owned. */\nexport const TimePicker = forwardRef<HTMLInputElement, TimePickerProps>(function TimePicker(\n { className, prefix, disabled, step = 60, ...props },\n ref,\n) {\n return (\n <InputGroup className={cn('min-w-0', className)} data-disabled={disabled}>\n <InputGroupAddon className={prefix ? 'text-sm font-normal' : undefined}>\n {prefix ?? <Clock aria-hidden=\"true\" />}\n </InputGroupAddon>\n <InputGroupInput\n ref={ref}\n className=\"min-w-0 appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none\"\n disabled={disabled}\n step={step}\n type=\"time\"\n {...props}\n />\n </InputGroup>\n );\n});\n"],"mappings":";;;;;;;AAcA,IAAa,aAAa,WAA8C,SAAS,WAC/E,EAAE,WAAW,QAAQ,UAAU,OAAO,IAAI,GAAG,SAC7C,KACA;CACA,OACE,qBAAC,YAAD;EAAY,WAAW,GAAG,WAAW,SAAS;EAAG,iBAAe;YAAhE,CACE,oBAAC,iBAAD;GAAiB,WAAW,SAAS,wBAAwB,KAAA;aAC1D,UAAU,oBAAC,OAAD,EAAO,eAAY,OAAQ,CAAA;EACvB,CAAA,GACjB,oBAAC,iBAAD;GACO;GACL,WAAU;GACA;GACJ;GACN,MAAK;GACL,GAAI;EACL,CAAA,CACS;;AAEhB,CAAC"}
|
|
@@ -5,8 +5,8 @@ import { inputSurface } from "./input-surface.js";
|
|
|
5
5
|
var tokenFieldClasses = {
|
|
6
6
|
field: cn(inputSurface("within"), "relative flex min-h-(--control-height) w-full cursor-text flex-wrap items-center gap-1 p-0.75 text-control"),
|
|
7
7
|
input: "min-w-20 flex-1 bg-transparent px-2 text-control outline-hidden placeholder:text-muted-foreground",
|
|
8
|
-
chip: "h-6 max-w-full cursor-pointer gap-1 rounded-
|
|
9
|
-
chevron: "pointer-events-none absolute top-[calc((var(--control-height)-var(--spacing)*4)/2)] right-
|
|
8
|
+
chip: "h-auto min-h-6 max-w-full cursor-pointer gap-1 rounded-xl border-transparent px-2 py-0.75 pr-1.5 text-left text-sm leading-4 whitespace-normal",
|
|
9
|
+
chevron: "pointer-events-none absolute top-[calc((var(--control-height)-var(--spacing)*4)/2-1px)] right-1.5 size-4 text-muted-foreground"
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
12
|
export { tokenFieldClasses };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-field.js","names":[],"sources":["../../../src/components/ui/token-field.ts"],"sourcesContent":["import { inputSurface } from '@/components/ui/input-surface';\nimport { cn } from '@/lib/utils';\n\n/** Shared chip density for token inputs such as labels, tags and authors. */\nexport const tokenFieldClasses = {\n field: cn(\n inputSurface('within'),\n 'relative flex min-h-(--control-height) w-full cursor-text flex-wrap items-center gap-1 p-0.75 text-control',\n ),\n input:\n 'min-w-20 flex-1 bg-transparent px-2 text-control outline-hidden placeholder:text-muted-foreground',\n chip: 'h-6 max-w-full cursor-pointer gap-1 rounded-
|
|
1
|
+
{"version":3,"file":"token-field.js","names":[],"sources":["../../../src/components/ui/token-field.ts"],"sourcesContent":["import { inputSurface } from '@/components/ui/input-surface';\nimport { cn } from '@/lib/utils';\n\n/** Shared chip density for token inputs such as labels, tags and authors. */\nexport const tokenFieldClasses = {\n field: cn(\n inputSurface('within'),\n 'relative flex min-h-(--control-height) w-full cursor-text flex-wrap items-center gap-1 p-0.75 text-control',\n ),\n input:\n 'min-w-20 flex-1 bg-transparent px-2 text-control outline-hidden placeholder:text-muted-foreground',\n // 24px on one line; long names wrap.\n chip: 'h-auto min-h-6 max-w-full cursor-pointer gap-1 rounded-xl border-transparent px-2 py-0.75 pr-1.5 text-left text-sm leading-4 whitespace-normal',\n // Matches Select's chevron; offsets start inside the 1px border.\n chevron:\n 'pointer-events-none absolute top-[calc((var(--control-height)-var(--spacing)*4)/2-1px)] right-1.5 size-4 text-muted-foreground',\n} as const;\n"],"mappings":";;;;AAIA,IAAa,oBAAoB;CAC/B,OAAO,GACL,aAAa,QAAQ,GACrB,4GACF;CACA,OACE;CAEF,MAAM;CAEN,SACE;AACJ"}
|
package/es/components.js
CHANGED
|
@@ -8,7 +8,7 @@ import { selectTriggerVariants } from "./components/ui/select-variants.js";
|
|
|
8
8
|
import { inputSurface, inputSurfaceClasses } from "./components/ui/input-surface.js";
|
|
9
9
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue } from "./components/ui/select.js";
|
|
10
10
|
import { Kbd, KbdGroup } from "./components/ui/kbd.js";
|
|
11
|
-
import { AlignedAxisTick, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent
|
|
11
|
+
import { AlignedAxisTick, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent } from "./components/ui/chart.js";
|
|
12
12
|
import { Tabs, TabsContent, TabsDropdownTrigger, TabsList, TabsTrigger, TabsTriggerCount } from "./components/ui/tabs.js";
|
|
13
13
|
import { Calendar, CalendarDayButton } from "./components/ui/calendar.js";
|
|
14
14
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger } from "./components/ui/dialog.js";
|
|
@@ -76,4 +76,4 @@ import { a as TwitterLogo, i as GoogleLogo, n as GhostLogo, o as XLogo, r as Gho
|
|
|
76
76
|
import { TimePicker } from "./components/ui/time-picker.js";
|
|
77
77
|
import { tokenFieldClasses } from "./components/ui/token-field.js";
|
|
78
78
|
import { defaultFilter as commandDefaultFilter } from "cmdk";
|
|
79
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionList, ActionListItem, ActionListItemActions, ActionListItemContent, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlignedAxisTick, AnimatedNumber, Avatar, AvatarFallback, AvatarImage, Badge, Banner, BarChartLoadingIndicator, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, CodeEditor, Combobox, ComboboxContent, ComboboxTrigger, ComboboxValue, Command, CommandCheck, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyField, CopyFieldActions, CopyFieldContent, CopyFieldCopyButton, CopyFieldLabel, CopyFieldValue, DataList, DataListBar, DataListBody, DataListHead, DataListHeader, DataListItemContent, DataListItemValue, DataListItemValueAbs, DataListItemValuePerc, DataListRow,
|
|
79
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionList, ActionListItem, ActionListItemActions, ActionListItemContent, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlignedAxisTick, AnimatedNumber, Avatar, AvatarFallback, AvatarImage, Badge, Banner, BarChartLoadingIndicator, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, CodeEditor, Combobox, ComboboxContent, ComboboxTrigger, ComboboxValue, Command, CommandCheck, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyField, CopyFieldActions, CopyFieldContent, CopyFieldCopyButton, CopyFieldLabel, CopyFieldValue, DataList, DataListBar, DataListBody, DataListHead, DataListHeader, DataListItemContent, DataListItemValue, DataListItemValueAbs, DataListItemValuePerc, DataListRow, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DragIndicator, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Dropzone, EmptyBadge, EmptyCard, EmptyIndicator, FLOATING_SIDEBAR_BUMP, FLOATING_SIDEBAR_CLOSED_FOOTPRINT, FLOATING_SIDEBAR_CLOSED_SIZE, FLOATING_SIDEBAR_DURATION, FLOATING_SIDEBAR_EASE, FLOATING_SIDEBAR_EASE_DURATION, FLOATING_SIDEBAR_INSET, FLOATING_SIDEBAR_OPEN_WIDTH, FLOATING_SIDEBAR_SPRING, FacebookLogo, Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, Flag, FloatingSidebar, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, GhostLogo, GhostOrb, GoogleLogo, HoverCard, HoverCardContent, HoverCardTrigger, IconComponents as Icon, Indicator, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, Kbd, KbdGroup, Label, Link, LoadingIndicator, MultiSelectCombobox, Navbar, NavbarActions, NavbarNavigation, NoValueLabel, NoValueLabelIcon, PageMenu, PageMenuItem, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, PreviewChrome, RadioGroup, RadioGroupItem, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SimplePagination, SimplePaginationNavigation, SimplePaginationNextButton, SimplePaginationPages, SimplePaginationPreviousButton, Skeleton, SkeletonTable, SortableList, StickyFooter, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeadButton, TableHeader, TableRow, Tabs, TabsContent, TabsDropdownTrigger, TabsList, TabsTrigger, TabsTriggerCount, Textarea, TimePicker, Toaster, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TwitterLogo, XLogo, badgeVariants, bannerVariants, buttonVariants, cardVariants, commandDefaultFilter, dropzoneVariants, getFloatingSidebarGapWidth, getFloatingSidebarTiming, imageOverlayButton, imageOverlayButtonClasses, indicatorVariants, inputGroupVariants, inputSurface, inputSurfaceClasses, previewChromeVariants, radioGroupItemVariants, selectTriggerVariants, tabsVariants, tokenFieldClasses, useFormField, useSidebar };
|
package/es/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { Kbd, KbdGroup } from "./components/ui/kbd.js";
|
|
|
21
21
|
import { PageHeader, PageHeaderActionGroup, PageHeaderActionGroupMobileMenu, PageHeaderActionGroupMobileMenuContent, PageHeaderActionGroupMobileMenuTrigger, PageHeaderActionGroupPrimary, PageHeaderActions, PageHeaderBreadcrumb, PageHeaderCount, PageHeaderDescription, PageHeaderLeft, PageHeaderMeta, PageHeaderTitle } from "./components/patterns/page-header.js";
|
|
22
22
|
import { ViewBar, ViewBarActions, ViewBarNav } from "./components/patterns/view-bar.js";
|
|
23
23
|
import { FilterBar } from "./components/patterns/filter-bar.js";
|
|
24
|
-
import { AlignedAxisTick, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent
|
|
24
|
+
import { AlignedAxisTick, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent } from "./components/ui/chart.js";
|
|
25
25
|
import { GhAreaChart, GhCustomTooltipContent } from "./components/patterns/gh-chart.js";
|
|
26
26
|
import { KpiCardHeader, KpiCardHeaderLabel, KpiCardHeaderValue } from "./components/patterns/kpi-card.js";
|
|
27
27
|
import { Tabs, TabsContent, TabsDropdownTrigger, TabsList, TabsTrigger, TabsTriggerCount } from "./components/ui/tabs.js";
|
|
@@ -110,4 +110,4 @@ import { a as TwitterLogo, i as GoogleLogo, n as GhostLogo, o as XLogo, r as Gho
|
|
|
110
110
|
import { TimePicker } from "./components/ui/time-picker.js";
|
|
111
111
|
import { tokenFieldClasses } from "./components/ui/token-field.js";
|
|
112
112
|
import { commandDefaultFilter } from "./components.js";
|
|
113
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionList, ActionListItem, ActionListItemActions, ActionListItemContent, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlignedAxisTick, AnimatedNumber, Avatar, AvatarFallback, AvatarImage, Badge, Banner, BarChartLoadingIndicator, Box, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, CodeEditor, ColorPicker, ColorPickerTrigger, ColorSwatch, ColorSwatchRow, Combobox, ComboboxContent, ComboboxTrigger, ComboboxValue, Command, CommandCheck, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Container, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyField, CopyFieldActions, CopyFieldContent, CopyFieldCopyButton, CopyFieldLabel, CopyFieldValue, DEFAULT_I18N, DEFAULT_OPERATORS, DataList, DataListBar, DataListBody, DataListHead, DataListHeader, DataListItemContent, DataListItemValue, DataListItemValueAbs, DataListItemValuePerc, DataListRow,
|
|
113
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionList, ActionListItem, ActionListItemActions, ActionListItemContent, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlignedAxisTick, AnimatedNumber, Avatar, AvatarFallback, AvatarImage, Badge, Banner, BarChartLoadingIndicator, Box, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, CodeEditor, ColorPicker, ColorPickerTrigger, ColorSwatch, ColorSwatchRow, Combobox, ComboboxContent, ComboboxTrigger, ComboboxValue, Command, CommandCheck, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Container, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyField, CopyFieldActions, CopyFieldContent, CopyFieldCopyButton, CopyFieldLabel, CopyFieldValue, DEFAULT_I18N, DEFAULT_OPERATORS, DataList, DataListBar, DataListBody, DataListHead, DataListHeader, DataListItemContent, DataListItemValue, DataListItemValueAbs, DataListItemValuePerc, DataListRow, DetailPage, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DirtyConfirmDialog, DragIndicator, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Dropzone, EmptyBadge, EmptyCard, EmptyIndicator, ErrorPage, FLOATING_SIDEBAR_BUMP, FLOATING_SIDEBAR_CLOSED_FOOTPRINT, FLOATING_SIDEBAR_CLOSED_SIZE, FLOATING_SIDEBAR_DURATION, FLOATING_SIDEBAR_EASE, FLOATING_SIDEBAR_EASE_DURATION, FLOATING_SIDEBAR_INSET, FLOATING_SIDEBAR_OPEN_WIDTH, FLOATING_SIDEBAR_SPRING, FacebookLogo, Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, FilterBar, FilterDatePicker, FilterSegmentInput, FilterSegmentMultiSelect, FilterSegmentSelect, Filters, FiltersContent, Flag, FloatingSidebar, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, GhAreaChart, GhCustomTooltipContent, GhostLogo, GhostOrb, GoogleLogo, Grid, H1, H2, H3, H4, HTable, HoverCard, HoverCardContent, HoverCardTrigger, IconComponents as Icon, ImageUpload, ImageUploadAction, ImageUploadActions, ImageUploadDropzone, ImageUploadImage, ImageUploadPreview, Indicator, Inline, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, Kbd, KbdGroup, KpiCardHeader, KpiCardHeaderLabel, KpiCardHeaderValue, KpiDropdownButton, KpiTabTrigger, KpiTabValue, Label, Link, ListPage, ListPageBody, ListPageHeader, LoadingIndicator, ModalPage, ModalPageTitle, MultiSelectCombobox, Navbar, NavbarActions, NavbarNavigation, NoValueLabel, NoValueLabelIcon, PageChromeProvider, PageHeader, PageHeaderActionGroup, PageHeaderActionGroupMobileMenu, PageHeaderActionGroupMobileMenuContent, PageHeaderActionGroupMobileMenuTrigger, PageHeaderActionGroupPrimary, PageHeaderActions, PageHeaderBreadcrumb, PageHeaderCount, PageHeaderDescription, PageHeaderLeft, PageHeaderMeta, PageHeaderTitle, PageMenu, PageMenuItem, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, PreviewChrome, RadioGroup, RadioGroupItem, SHADE_TOKEN_NAMES, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SettingGroup, SettingGroupActions, SettingGroupContent, SettingGroupDescription, SettingGroupDetails, SettingGroupHeader, SettingGroupTitle, SettingGroupValue, SettingGroupValueContent, SettingGroupValueTitle, SettingsModal, ShareModal, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SimplePagination, SimplePaginationNavigation, SimplePaginationNextButton, SimplePaginationPages, SimplePaginationPreviousButton, Skeleton, SkeletonTable, SortableList, Stack, StickyFooter, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeadButton, TableHeader, TableRow, Tabs, TabsContent, TabsDropdownTrigger, TabsList, TabsTrigger, TabsTriggerCount, Text, Textarea, TimePicker, Toaster, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TwitterLogo, ViewBar, ViewBarActions, ViewBarNav, XLogo, badgeVariants, bannerVariants, buttonVariants, cardVariants, commandDefaultFilter, createFilter, createFilterGroup, dropzoneVariants, getFloatingSidebarGapWidth, getFloatingSidebarTiming, imageOverlayButton, imageOverlayButtonClasses, imageUploadPreviewVariants, indicatorVariants, inputGroupVariants, inputSurface, inputSurfaceClasses, previewChromeVariants, radioGroupItemVariants, selectTriggerVariants, settingGroupVariants, settingsModalVariants, shadeToken, tabsVariants, tokenFieldClasses, useDirtyConfirmation, useFormField, usePageChrome, useSidebar };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//#region src/lib/date-utils.ts
|
|
2
|
+
var MONTHS = [
|
|
3
|
+
"Jan",
|
|
4
|
+
"Feb",
|
|
5
|
+
"Mar",
|
|
6
|
+
"Apr",
|
|
7
|
+
"May",
|
|
8
|
+
"Jun",
|
|
9
|
+
"Jul",
|
|
10
|
+
"Aug",
|
|
11
|
+
"Sep",
|
|
12
|
+
"Oct",
|
|
13
|
+
"Nov",
|
|
14
|
+
"Dec"
|
|
15
|
+
];
|
|
16
|
+
var DAY_MS = 1440 * 60 * 1e3;
|
|
17
|
+
var INVALID_DATE = "Invalid date";
|
|
18
|
+
var zonedFormatters = /* @__PURE__ */ new Map();
|
|
19
|
+
var getZonedFormatter = (timeZone) => {
|
|
20
|
+
let formatter = zonedFormatters.get(timeZone);
|
|
21
|
+
if (!formatter) {
|
|
22
|
+
try {
|
|
23
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
24
|
+
timeZone,
|
|
25
|
+
hourCycle: "h23",
|
|
26
|
+
year: "numeric",
|
|
27
|
+
month: "numeric",
|
|
28
|
+
day: "numeric",
|
|
29
|
+
hour: "numeric",
|
|
30
|
+
minute: "numeric",
|
|
31
|
+
second: "numeric"
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!(error instanceof RangeError)) throw error;
|
|
35
|
+
formatter = getZonedFormatter("UTC");
|
|
36
|
+
}
|
|
37
|
+
zonedFormatters.set(timeZone, formatter);
|
|
38
|
+
}
|
|
39
|
+
return formatter;
|
|
40
|
+
};
|
|
41
|
+
var getDateTimeParts = (date, timeZone) => {
|
|
42
|
+
if (!timeZone) return {
|
|
43
|
+
year: date.getFullYear(),
|
|
44
|
+
month: date.getMonth(),
|
|
45
|
+
day: date.getDate(),
|
|
46
|
+
hour: date.getHours(),
|
|
47
|
+
minute: date.getMinutes(),
|
|
48
|
+
second: date.getSeconds()
|
|
49
|
+
};
|
|
50
|
+
const parts = getZonedFormatter(timeZone).formatToParts(date);
|
|
51
|
+
const get = (type) => Number(parts.find((part) => part.type === type)?.value);
|
|
52
|
+
return {
|
|
53
|
+
year: get("year"),
|
|
54
|
+
month: get("month") - 1,
|
|
55
|
+
day: get("day"),
|
|
56
|
+
hour: get("hour"),
|
|
57
|
+
minute: get("minute"),
|
|
58
|
+
second: get("second")
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var toUTCTime = ({ year, month, day, hour, minute, second }) => {
|
|
62
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
63
|
+
date.setUTCFullYear(year, month, day);
|
|
64
|
+
date.setUTCHours(hour, minute, second);
|
|
65
|
+
return date.getTime();
|
|
66
|
+
};
|
|
67
|
+
var fromWallClockTime = (parts, timeZone) => {
|
|
68
|
+
if (!timeZone) {
|
|
69
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
70
|
+
date.setFullYear(parts.year, parts.month, parts.day);
|
|
71
|
+
date.setHours(parts.hour, parts.minute, parts.second, 0);
|
|
72
|
+
return date;
|
|
73
|
+
}
|
|
74
|
+
const wallClockTime = toUTCTime(parts);
|
|
75
|
+
const readWallClockTime = (time) => toUTCTime(getDateTimeParts(new Date(time), timeZone));
|
|
76
|
+
const getOffset = (time) => readWallClockTime(time) - time;
|
|
77
|
+
const withOffsetBefore = wallClockTime - getOffset(wallClockTime - DAY_MS);
|
|
78
|
+
const withOffsetAfter = wallClockTime - getOffset(wallClockTime + DAY_MS);
|
|
79
|
+
if (withOffsetBefore === withOffsetAfter) return new Date(withOffsetBefore);
|
|
80
|
+
const occurrences = [withOffsetBefore, withOffsetAfter].filter((time) => readWallClockTime(time) === wallClockTime).sort((a, b) => a - b);
|
|
81
|
+
return new Date(occurrences[0] ?? withOffsetBefore);
|
|
82
|
+
};
|
|
83
|
+
var ISO_EXTENDED_DATE_TIME = /^(?<year>\d{4})-(?<month>\d{2})(?:-(?<day>\d{2})(?:[T ](?<hour>\d{2})(?::(?<minute>\d{2})(?::(?<second>\d{2})(?:[.,]\d+)?)?)?(?<offset>Z|(?<offsetSign>[+-])(?<offsetHours>\d{2}):?(?<offsetMinutes>\d{2})?)?)?)?$/;
|
|
84
|
+
var ISO_BASIC_DATE_TIME = /^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?:[T ](?<hour>\d{2})(?:(?<minute>\d{2})(?:(?<second>\d{2})(?:[.,]\d+)?)?)?(?<offset>Z|(?<offsetSign>[+-])(?<offsetHours>\d{2}):?(?<offsetMinutes>\d{2})?)?)?$/;
|
|
85
|
+
var parseDate = (value, timeZone) => {
|
|
86
|
+
const match = ISO_EXTENDED_DATE_TIME.exec(value) ?? ISO_BASIC_DATE_TIME.exec(value);
|
|
87
|
+
if (!match?.groups) {
|
|
88
|
+
const date = new Date(value);
|
|
89
|
+
return isNaN(date.getTime()) ? null : date;
|
|
90
|
+
}
|
|
91
|
+
const { year, month, day = "1", hour = "0", minute = "0", second = "0", offset, offsetSign, offsetHours = "0", offsetMinutes = "0" } = match.groups;
|
|
92
|
+
const parts = {
|
|
93
|
+
year: Number(year),
|
|
94
|
+
month: Number(month) - 1,
|
|
95
|
+
day: Number(day),
|
|
96
|
+
hour: Number(hour),
|
|
97
|
+
minute: Number(minute),
|
|
98
|
+
second: Number(second)
|
|
99
|
+
};
|
|
100
|
+
const utc = new Date(toUTCTime(parts));
|
|
101
|
+
if (!(utc.getUTCMonth() === parts.month && utc.getUTCDate() === parts.day && utc.getUTCHours() === parts.hour && utc.getUTCMinutes() === parts.minute && utc.getUTCSeconds() === parts.second && Number(offsetHours) < 24 && Number(offsetMinutes) < 60)) return null;
|
|
102
|
+
if (!offset) return fromWallClockTime(parts, timeZone);
|
|
103
|
+
const offsetMs = (Number(offsetHours) * 60 + Number(offsetMinutes)) * 60 * 1e3;
|
|
104
|
+
return new Date(utc.getTime() - (offsetSign === "-" ? -offsetMs : offsetMs));
|
|
105
|
+
};
|
|
106
|
+
var formatTime = ({ hour, minute }) => `${hour % 12 || 12}:${String(minute).padStart(2, "0")}${hour < 12 ? "am" : "pm"}`;
|
|
107
|
+
var formatDate = ({ year, month, day }, timeZone) => {
|
|
108
|
+
const date = `${day} ${MONTHS[month]}`;
|
|
109
|
+
return year === getDateTimeParts(/* @__PURE__ */ new Date(), timeZone).year ? date : `${date} ${year}`;
|
|
110
|
+
};
|
|
111
|
+
var formatDisplayDate = (dateString, timezone) => {
|
|
112
|
+
if (dateString instanceof Date) dateString = dateString.toISOString();
|
|
113
|
+
if (!dateString || dateString.length === 0 || typeof dateString !== "string") return "";
|
|
114
|
+
const timeZone = timezone || "UTC";
|
|
115
|
+
const date = parseDate(dateString, timeZone);
|
|
116
|
+
return date ? formatDate(getDateTimeParts(date, timeZone), timeZone) : INVALID_DATE;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Format a plain time in a given time zone.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* formatDisplayTime('2020-04-20T18:09:12.345Z', 'Africa/Lagos')
|
|
123
|
+
* // 7:09pm
|
|
124
|
+
*/
|
|
125
|
+
var formatDisplayTime = (dateString, timezone) => {
|
|
126
|
+
if (!dateString) return "";
|
|
127
|
+
const timeZone = timezone || "UTC";
|
|
128
|
+
const date = parseDate(dateString, timeZone);
|
|
129
|
+
return date ? formatTime(getDateTimeParts(date, timeZone)) : INVALID_DATE;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Formats a date based on the range, in the browser's time zone
|
|
133
|
+
* - For ranges above 365 days: shows month and year (e.g. "Apr 2025")
|
|
134
|
+
* - For ranges of 91 days or more: shows "Week of [date]"
|
|
135
|
+
* - For other ranges: shows the date in the same format as formatDisplayDate
|
|
136
|
+
*/
|
|
137
|
+
var formatDisplayDateWithRange = (date, range, showHours = false, hoursOnly = false) => {
|
|
138
|
+
if (!date) return "";
|
|
139
|
+
const parsed = parseDate(date);
|
|
140
|
+
if (!parsed) return INVALID_DATE;
|
|
141
|
+
const parts = getDateTimeParts(parsed);
|
|
142
|
+
if (range === 1 && hoursOnly) return formatTime(parts);
|
|
143
|
+
else if (range === 1 && showHours) return `${MONTHS[parts.month]} ${parts.day}, ${formatTime(parts)}`;
|
|
144
|
+
else if (range > 365) return `${MONTHS[parts.month]} ${parts.year}`;
|
|
145
|
+
else if (range >= 91) return `Week of ${formatDate(parts)}`;
|
|
146
|
+
return formatDate(parts);
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
export { formatDisplayDate, formatDisplayDateWithRange, formatDisplayTime };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=date-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-utils.js","names":[],"sources":["../../src/lib/date-utils.ts"],"sourcesContent":["const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\n// Shown for a date that can't be parsed, so it can't be mistaken for a missing date\nconst INVALID_DATE = 'Invalid date';\n\ninterface DateTimeParts {\n year: number;\n month: number;\n day: number;\n hour: number;\n minute: number;\n second: number;\n}\n\nconst zonedFormatters = new Map<string, Intl.DateTimeFormat>();\n\n// A time zone the browser doesn't know falls back to UTC, as it did with moment-timezone\nconst getZonedFormatter = (timeZone: string): Intl.DateTimeFormat => {\n let formatter = zonedFormatters.get(timeZone);\n if (!formatter) {\n try {\n formatter = new Intl.DateTimeFormat('en-US', {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n } catch (error) {\n if (!(error instanceof RangeError)) {\n throw error;\n }\n formatter = getZonedFormatter('UTC');\n }\n zonedFormatters.set(timeZone, formatter);\n }\n return formatter;\n};\n\n// Without a time zone, the parts are in the browser's local time\nconst getDateTimeParts = (date: Date, timeZone?: string): DateTimeParts => {\n if (!timeZone) {\n return {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n hour: date.getHours(),\n minute: date.getMinutes(),\n second: date.getSeconds(),\n };\n }\n\n const parts = getZonedFormatter(timeZone).formatToParts(date);\n const get = (type: Intl.DateTimeFormatPartTypes) =>\n Number(parts.find((part) => part.type === type)?.value);\n\n return {\n year: get('year'),\n month: get('month') - 1,\n day: get('day'),\n hour: get('hour'),\n minute: get('minute'),\n second: get('second'),\n };\n};\n\n// Unlike Date.UTC(), this doesn't read years 0-99 as 1900-1999\nconst toUTCTime = ({ year, month, day, hour, minute, second }: DateTimeParts): number => {\n const date = new Date(0);\n date.setUTCFullYear(year, month, day);\n date.setUTCHours(hour, minute, second);\n return date.getTime();\n};\n\n// Wall-clock time that a time zone skips, such as 2:30am when clocks go forward, moves forward by\n// the gap. Wall-clock time that it repeats reads as the first occurrence. Both match moment-timezone.\nconst fromWallClockTime = (parts: DateTimeParts, timeZone?: string): Date => {\n if (!timeZone) {\n // Local Date setters resolve skipped and repeated times the same way\n const date = new Date(0);\n date.setFullYear(parts.year, parts.month, parts.day);\n date.setHours(parts.hour, parts.minute, parts.second, 0);\n return date;\n }\n\n const wallClockTime = toUTCTime(parts);\n const readWallClockTime = (time: number) => toUTCTime(getDateTimeParts(new Date(time), timeZone));\n const getOffset = (time: number) => readWallClockTime(time) - time;\n\n // The offsets a day either side are the ones in use on each side of any change at this time\n const withOffsetBefore = wallClockTime - getOffset(wallClockTime - DAY_MS);\n const withOffsetAfter = wallClockTime - getOffset(wallClockTime + DAY_MS);\n if (withOffsetBefore === withOffsetAfter) {\n return new Date(withOffsetBefore);\n }\n\n const occurrences = [withOffsetBefore, withOffsetAfter]\n .filter((time) => readWallClockTime(time) === wallClockTime)\n .sort((a, b) => a - b);\n return new Date(occurrences[0] ?? withOffsetBefore);\n};\n\n// ISO 8601 dates and date-times in the forms moment reads, in the extended\n// (`2025-04-15T13:05:00+01:00`) and basic (`20250415T130500+0100`) formats\nconst ISO_EXTENDED_DATE_TIME =\n /^(?<year>\\d{4})-(?<month>\\d{2})(?:-(?<day>\\d{2})(?:[T ](?<hour>\\d{2})(?::(?<minute>\\d{2})(?::(?<second>\\d{2})(?:[.,]\\d+)?)?)?(?<offset>Z|(?<offsetSign>[+-])(?<offsetHours>\\d{2}):?(?<offsetMinutes>\\d{2})?)?)?)?$/;\nconst ISO_BASIC_DATE_TIME =\n /^(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})(?:[T ](?<hour>\\d{2})(?:(?<minute>\\d{2})(?:(?<second>\\d{2})(?:[.,]\\d+)?)?)?(?<offset>Z|(?<offsetSign>[+-])(?<offsetHours>\\d{2}):?(?<offsetMinutes>\\d{2})?)?)?$/;\n\n// An ISO 8601 date or date-time without an offset is wall-clock time in the time zone, as moment\n// reads it. `new Date()` alone would read a date-only string as UTC midnight.\nconst parseDate = (value: string, timeZone?: string): Date | null => {\n const match = ISO_EXTENDED_DATE_TIME.exec(value) ?? ISO_BASIC_DATE_TIME.exec(value);\n if (!match?.groups) {\n const date = new Date(value);\n return isNaN(date.getTime()) ? null : date;\n }\n\n const {\n year,\n month,\n day = '1',\n hour = '0',\n minute = '0',\n second = '0',\n offset,\n offsetSign,\n offsetHours = '0',\n offsetMinutes = '0',\n } = match.groups;\n const parts = {\n year: Number(year),\n month: Number(month) - 1,\n day: Number(day),\n hour: Number(hour),\n minute: Number(minute),\n second: Number(second),\n };\n\n // The formats only check the shape, so reject fields that would roll over, such as 30 February or 24:00\n const utc = new Date(toUTCTime(parts));\n const isValid =\n utc.getUTCMonth() === parts.month &&\n utc.getUTCDate() === parts.day &&\n utc.getUTCHours() === parts.hour &&\n utc.getUTCMinutes() === parts.minute &&\n utc.getUTCSeconds() === parts.second &&\n Number(offsetHours) < 24 &&\n Number(offsetMinutes) < 60;\n if (!isValid) {\n return null;\n }\n\n if (!offset) {\n return fromWallClockTime(parts, timeZone);\n }\n const offsetMs = (Number(offsetHours) * 60 + Number(offsetMinutes)) * 60 * 1000;\n return new Date(utc.getTime() - (offsetSign === '-' ? -offsetMs : offsetMs));\n};\n\n// Result is in the format of `7:09pm`\nconst formatTime = ({ hour, minute }: DateTimeParts): string =>\n `${hour % 12 || 12}:${String(minute).padStart(2, '0')}${hour < 12 ? 'am' : 'pm'}`;\n\n// Result is in the format of `12 Jun 2025`, without the year when it's the current year\nconst formatDate = ({ year, month, day }: DateTimeParts, timeZone?: string): string => {\n const date = `${day} ${MONTHS[month]}`;\n return year === getDateTimeParts(new Date(), timeZone).year ? date : `${date} ${year}`;\n};\n\n// Format date for UI, result is in the format of `12 Jun 2025`\n// Timestamps with an offset are shown in the given time zone, or in UTC without one\nexport const formatDisplayDate = (dateString: string, timezone?: string): string => {\n // If the date is a Date object, convert it to a string\n // @ts-expect-error This should error if dateString is not a string, but for some reason Typescript isn't catching this\n if (dateString instanceof Date) {\n dateString = dateString.toISOString();\n }\n // Fallback to empty string if dateString is an unexpected type. Better to fallback to empty string than to crash the app\n if (!dateString || dateString.length === 0 || typeof dateString !== 'string') {\n return '';\n }\n\n const timeZone = timezone || 'UTC';\n const date = parseDate(dateString, timeZone);\n return date ? formatDate(getDateTimeParts(date, timeZone), timeZone) : INVALID_DATE;\n};\n\n/**\n * Format a plain time in a given time zone.\n *\n * @example\n * formatDisplayTime('2020-04-20T18:09:12.345Z', 'Africa/Lagos')\n * // 7:09pm\n */\nexport const formatDisplayTime = (dateString: string, timezone: string): string => {\n if (!dateString) {\n return '';\n }\n\n const timeZone = timezone || 'UTC';\n const date = parseDate(dateString, timeZone);\n return date ? formatTime(getDateTimeParts(date, timeZone)) : INVALID_DATE;\n};\n\n/**\n * Formats a date based on the range, in the browser's time zone\n * - For ranges above 365 days: shows month and year (e.g. \"Apr 2025\")\n * - For ranges of 91 days or more: shows \"Week of [date]\"\n * - For other ranges: shows the date in the same format as formatDisplayDate\n */\nexport const formatDisplayDateWithRange = (\n date: string,\n range: number,\n showHours: boolean = false,\n hoursOnly: boolean = false,\n): string => {\n if (!date) {\n return '';\n }\n\n const parsed = parseDate(date);\n if (!parsed) {\n return INVALID_DATE;\n }\n const parts = getDateTimeParts(parsed);\n\n if (range === 1 && hoursOnly) {\n return formatTime(parts);\n } else if (range === 1 && showHours) {\n return `${MONTHS[parts.month]} ${parts.day}, ${formatTime(parts)}`;\n } else if (range > 365) {\n return `${MONTHS[parts.month]} ${parts.year}`;\n } else if (range >= 91) {\n return `Week of ${formatDate(parts)}`;\n }\n return formatD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qBAAqB,YAAoB,aAA6B;CACjF,IAAI,CAAC,YACH,OAAO;CAGT,MAAM,WAAW,YAAY;CAC7B,MAAM,OAAO,UAAU,YAAY,QAAQ;CAC3C,OAAO,OAAO,WAAW,iBAAiB,MAAM,QAAQ,CAAC,IAAI;AAC/D;;;;;;;AAQA,IAAa,8BACX,MACA,OACA,YAAqB,OACrB,YAAqB,UACV;CACX,IAAI,CAAC,MACH,OAAO;CAGT,MAAM,SAAS,UAAU,IAAI;CAC7B,IAAI,CAAC,QACH,OAAO;CAET,MAAM,QAAQ,iBAAiB,MAAM;CAErC,IAAI,UAAU,KAAK,WACjB,OAAO,WAAW,KAAK;MAClB,IAAI,UAAU,KAAK,WACxB,OAAO,GAAG,OAAO,MAAM,OAAO,GAAG,MAAM,IAAI,IAAI,WAAW,KAAK;MAC1D,IAAI,QAAQ,KACjB,OAAO,GAAG,OAAO,MAAM,OAAO,GAAG,MAAM;MAClC,IAAI,SAAS,IAClB,OAAO,WAAW,WAAW,KAAK;CAEpC,OAAO,WAAW,KAAK;AACzB"}
|
package/es/lib/ds-utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { clsx } from "clsx";
|
|
2
|
-
import moment from "moment-timezone";
|
|
3
2
|
import { twMerge } from "tailwind-merge";
|
|
4
3
|
//#region src/lib/ds-utils.ts
|
|
5
4
|
function cn(...inputs) {
|
|
@@ -30,62 +29,6 @@ var kebabToPascalCase = (str) => {
|
|
|
30
29
|
const processed = str.replace(/[-_]([a-z0-9])/gi, (_, char) => char.toUpperCase());
|
|
31
30
|
return processed.charAt(0).toUpperCase() + processed.slice(1);
|
|
32
31
|
};
|
|
33
|
-
var formatDisplayDate = (dateString, timezone) => {
|
|
34
|
-
if (dateString instanceof Date) dateString = dateString.toISOString();
|
|
35
|
-
if (!dateString || dateString.length === 0 || typeof dateString !== "string") return "";
|
|
36
|
-
const hasTime = dateString.includes(":");
|
|
37
|
-
const isISOFormat = dateString.includes("T") || dateString.includes("Z");
|
|
38
|
-
let day, month, year, isToday, isCurrentYear;
|
|
39
|
-
if (timezone && isISOFormat) {
|
|
40
|
-
const dateMoment = moment.tz(dateString, timezone);
|
|
41
|
-
const todayMoment = moment.tz(timezone);
|
|
42
|
-
day = dateMoment.date();
|
|
43
|
-
month = dateMoment.month();
|
|
44
|
-
year = dateMoment.year();
|
|
45
|
-
isToday = dateMoment.isSame(todayMoment, "day");
|
|
46
|
-
isCurrentYear = year === todayMoment.year();
|
|
47
|
-
} else {
|
|
48
|
-
const date = new Date(dateString);
|
|
49
|
-
const today = /* @__PURE__ */ new Date();
|
|
50
|
-
if (hasTime && !isISOFormat) {
|
|
51
|
-
day = date.getDate();
|
|
52
|
-
month = date.getMonth();
|
|
53
|
-
year = date.getFullYear();
|
|
54
|
-
isToday = date.toDateString() === today.toDateString();
|
|
55
|
-
isCurrentYear = year === today.getFullYear();
|
|
56
|
-
} else {
|
|
57
|
-
day = date.getUTCDate();
|
|
58
|
-
month = date.getUTCMonth();
|
|
59
|
-
year = date.getUTCFullYear();
|
|
60
|
-
isToday = date.toISOString().slice(0, 10) === today.toISOString().slice(0, 10);
|
|
61
|
-
isCurrentYear = year === today.getUTCFullYear();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const monthName = [
|
|
65
|
-
"Jan",
|
|
66
|
-
"Feb",
|
|
67
|
-
"Mar",
|
|
68
|
-
"Apr",
|
|
69
|
-
"May",
|
|
70
|
-
"Jun",
|
|
71
|
-
"Jul",
|
|
72
|
-
"Aug",
|
|
73
|
-
"Sep",
|
|
74
|
-
"Oct",
|
|
75
|
-
"Nov",
|
|
76
|
-
"Dec"
|
|
77
|
-
][month];
|
|
78
|
-
if (isToday) return `${day} ${monthName}`;
|
|
79
|
-
return isCurrentYear ? `${day} ${monthName}` : `${day} ${monthName} ${year}`;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Format a plain time in a given time zone.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* formatDisplayTime('2020-04-20T18:09:12.345Z', 'Africa/Lagos')
|
|
86
|
-
* // 7:09pm
|
|
87
|
-
*/
|
|
88
|
-
var formatDisplayTime = (dateString, timezone) => moment(dateString).tz(timezone).format("h:mma");
|
|
89
32
|
var formatTimestamp = (timestamp) => {
|
|
90
33
|
const date = new Date(timestamp);
|
|
91
34
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -153,19 +96,6 @@ var stringToHslColor = (str, saturation, lightness) => {
|
|
|
153
96
|
for (let i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
154
97
|
return "hsl(" + hash % 360 + ", " + saturation + "%, " + lightness + "%)";
|
|
155
98
|
};
|
|
156
|
-
/**
|
|
157
|
-
* Formats a date based on the range
|
|
158
|
-
* - For ranges above 365 days: shows month and year (e.g. "Apr 2025")
|
|
159
|
-
* - For ranges above 91 days: shows "Week of [date]"
|
|
160
|
-
* - For other ranges: uses the default formatDisplayDate
|
|
161
|
-
*/
|
|
162
|
-
var formatDisplayDateWithRange = (date, range, showHours = false, hoursOnly = false) => {
|
|
163
|
-
if (range === 1 && hoursOnly) return moment(date).format("h:mma");
|
|
164
|
-
else if (range === 1 && showHours) return moment(date).format("MMM D, h:mma");
|
|
165
|
-
else if (range > 365) return moment(date).format("MMM YYYY");
|
|
166
|
-
else if (range >= 91) return `Week of ${formatDisplayDate(date)}`;
|
|
167
|
-
return formatDisplayDate(date);
|
|
168
|
-
};
|
|
169
99
|
var getYRange = (data) => {
|
|
170
100
|
if (!data.length) return {
|
|
171
101
|
min: 0,
|
|
@@ -209,6 +139,6 @@ var calculateYAxisWidth = (ticks, formatter) => {
|
|
|
209
139
|
return Math.max(20, maxFormattedLength * 8 + 20);
|
|
210
140
|
};
|
|
211
141
|
//#endregion
|
|
212
|
-
export { abbreviateNumber, calculateYAxisWidth, cn, debounce,
|
|
142
|
+
export { abbreviateNumber, calculateYAxisWidth, cn, debounce, formatDuration, formatNumber, formatPercentage, formatTimestamp, getCountryFlag, getScrollParent, getYRange, kebabToPascalCase, stringToHslColor };
|
|
213
143
|
|
|
214
144
|
//# sourceMappingURL=ds-utils.js.map
|
package/es/lib/ds-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ds-utils.js","names":[],"sources":["../../src/lib/ds-utils.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport moment from 'moment-timezone';\nimport { twMerge } from 'tailwind-merge';\n\n/* Generic helper functions\n/* -------------------------------------------------------------------------- */\n\n// Helper to merge Tailwind classes\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n// Helper to debounce a function\nexport function debounce<T extends unknown[]>(\n func: (...args: T) => void,\n wait: number,\n immediate: boolean = false,\n): (...args: T) => void {\n let timeoutId: ReturnType<typeof setTimeout> | null;\n\n return function (this: unknown, ...args: T): void {\n const later = () => {\n timeoutId = null;\n if (!immediate) {\n func.apply(this, args);\n }\n };\n\n const callNow = immediate && !timeoutId;\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(later, wait);\n\n if (callNow) {\n func.apply(this, args);\n }\n };\n}\n\n// Helper to find scroll parent of element\nexport function getScrollParent(node: Node | null): HTMLElement | null {\n if (!node) {\n return null;\n }\n\n if (node instanceof HTMLElement) {\n const overflowY = window.getComputedStyle(node).overflowY;\n const isScrollable = overflowY !== 'visible' && overflowY !== 'hidden';\n\n if (isScrollable && node.scrollHeight >= node.clientHeight) {\n return node;\n }\n }\n\n return getScrollParent(node.parentNode) || document.body;\n}\n\n/* Data formatters\n/* -------------------------------------------------------------------------- */\n\n// Helper to convert kebab-case to PascalCase with numbers\nexport const kebabToPascalCase = (str: string): string => {\n const processed = str.replace(/[-_]([a-z0-9])/gi, (_, char) => char.toUpperCase());\n return processed.charAt(0).toUpperCase() + processed.slice(1);\n};\n\n// Format date for UI, result is in the format of `12 Jun 2025`\n// When timezone is provided, the date will be converted to that timezone before formatting\nexport const formatDisplayDate = (dateString: string, timezone?: string): string => {\n // If the date is a Date object, convert it to a string\n // @ts-expect-error This should error if dateString is not a string, but for some reason Typescript isn't catching this\n if (dateString instanceof Date) {\n dateString = dateString.toISOString();\n }\n // Fallback to empty string if dateString is an unexpected type. Better to fallback to empty string than to crash the app\n if (!dateString || dateString.length === 0 || typeof dateString !== 'string') {\n return '';\n }\n\n // Check if this is a datetime string (contains time) or just a date\n const hasTime = dateString.includes(':');\n const isISOFormat = dateString.includes('T') || dateString.includes('Z');\n\n let day, month, year, isToday, isCurrentYear;\n\n // If timezone is provided and this is an ISO format date, use moment-timezone to convert\n if (timezone && isISOFormat) {\n const dateMoment = moment.tz(dateString, timezone);\n const todayMoment = moment.tz(timezone);\n\n day = dateMoment.date();\n month = dateMoment.month();\n year = dateMoment.year();\n isToday = dateMoment.isSame(todayMoment, 'day');\n isCurrentYear = year === todayMoment.year();\n } else {\n const date = new Date(dateString);\n const today = new Date();\n\n if (hasTime && !isISOFormat) {\n // This is a localized datetime string like \"2025-07-29 19:00:00\"\n // Use local date methods to avoid timezone conversion\n day = date.getDate();\n month = date.getMonth();\n year = date.getFullYear();\n isToday = date.toDateString() === today.toDateString();\n isCurrentYear = year === today.getFullYear();\n } else {\n // This is either a date-only string or an ISO format with timezone (without explicit timezone param)\n // Use UTC methods as before\n day = date.getUTCDate();\n month = date.getUTCMonth();\n year = date.getUTCFullYear();\n isToday = date.toISOString().slice(0, 10) === today.toISOString().slice(0, 10);\n isCurrentYear = year === today.getUTCFullYear();\n }\n }\n\n const months = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n ];\n const monthName = months[month];\n\n if (isToday) {\n return `${day} ${monthName}`;\n }\n\n return isCurrentYear ? `${day} ${monthName}` : `${day} ${monthName} ${year}`;\n};\n\n/**\n * Format a plain time in a given time zone.\n *\n * @example\n * formatDisplayTime('2020-04-20T18:09:12.345Z', 'Africa/Lagos')\n * // 7:09pm\n */\nexport const formatDisplayTime = (dateString: string, timezone: string): string =>\n moment(dateString).tz(timezone).format('h:mma');\n\n// Helper function to format timestamp\nexport const formatTimestamp = (timestamp: string) => {\n const date = new Date(timestamp);\n const now = new Date();\n\n // Handle invalid dates\n if (isNaN(date.getTime())) {\n return 'Unknown';\n }\n\n // Both dates are now in the same timezone context (local)\n // The timestamp from DB is UTC but Date constructor handles the conversion\n const diffMs = now.getTime() - date.getTime();\n\n // Handle negative differences (future dates)\n if (diffMs < 0) {\n return 'Just now';\n }\n\n const diffMins = Math.floor(diffMs / (1000 * 60));\n const diffHours = Math.floor(diffMs / (1000 * 60 * 60));\n const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n\n if (diffMins < 1) {\n return 'Just now';\n } else if (diffMins < 60) {\n return `${diffMins} min ago`;\n } else if (diffHours < 24) {\n return `${diffHours} hr ago`;\n } else if (diffDays === 1) {\n return 'Yesterday';\n } else if (diffDays < 7) {\n return `${diffDays} days ago`;\n } else {\n return date.toLocaleDateString('en-US', {\n month: 'short',\n day: 'numeric',\n year: diffDays > 365 ? 'numeric' : undefined,\n });\n }\n};\n\n// Add thousands indicator to numbers\nexport const formatNumber = (\n value: number,\n options?: Pick<Intl.NumberFormatOptions, 'minimumFractionDigits' | 'maximumFractionDigits'>,\n): string => {\n if (isNaN(value) || !isFinite(value)) {\n return '0';\n }\n\n const formattedValue = options ? value : Math.round(value);\n return new Intl.NumberFormat('en-US', options).format(formattedValue);\n};\n\n// Abbreviate numbers\nexport function abbreviateNumber(number: number): string {\n const num = Number(number);\n\n if (Number.isNaN(num) || !Number.isFinite(number)) {\n return formatNumber(num);\n }\n\n if (num < 0) {\n return `-${abbreviateNumber(-num)}`;\n }\n\n if (num < 1000) {\n return formatNumber(num);\n }\n\n if (num < 1000000) {\n // For thousands: round to nearest 100 for 10.3k, nearest 1000 for 101k\n const roundTo = num < 100000 ? 100 : 1000;\n\n const rounded = Math.round(num / roundTo) * roundTo;\n const abbreviated = rounded / 1000;\n\n if (abbreviated === 1000) {\n return '1M';\n }\n\n const formatted = abbreviated % 1 === 0 ? abbreviated.toString() : abbreviated.toFixed(1);\n return `${formatted}k`;\n }\n\n // For millions: round to nearest 100,000 for 1.1M\n const roundTo = 100000;\n const rounded = Math.round(num / roundTo) * roundTo;\n const abbreviated = rounded / 1000000;\n const formatted = abbreviated % 1 === 0 ? abbreviated.toString() : abbreviated.toFixed(1);\n return `${formatted}M`;\n}\n\n// Format time duration\nexport const formatDuration = (seconds: number): string => {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds % 3600) / 60);\n const remainingSeconds = Math.floor(seconds % 60);\n\n if (hours <= 0) {\n if (minutes <= 0) {\n return `${remainingSeconds}s`;\n }\n return `${minutes}m ${remainingSeconds}s`;\n }\n\n return `${hours}h ${minutes}m ${remainingSeconds}s`;\n};\n\n// Format a fraction to percentage\nexport const formatPercentage = (value: number) => {\n const percentage = value * 100;\n if (percentage === 0) {\n return '0%';\n } else if (percentage < 0.1) {\n return `${percentage.toFixed(2)}%`;\n } else if (percentage < 1) {\n return `${percentage.toFixed(1)}%`;\n }\n const rounded = Math.round(percentage);\n return `${new Intl.NumberFormat('en-US').format(rounded)}%`;\n};\n\n// Converts a country code to corresponding flag emoji\nexport function getCountryFlag(countryCode: string) {\n if (\n !countryCode ||\n countryCode === null ||\n countryCode.toUpperCase() === 'NULL' ||\n countryCode === 'ᴺᵁᴸᴸ' ||\n countryCode === 'ᴺᵁ'\n ) {\n return '🏳️';\n }\n return countryCode\n .toUpperCase()\n .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397));\n}\n\nexport const stringToHslColor = (str: string, saturation: string, lightness: string) => {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash);\n }\n\n const h = hash % 360;\n return 'hsl(' + h + ', ' + saturation + '%, ' + lightness + '%)';\n};\n\n/* Chart formatters\n/* -------------------------------------------------------------------------- */\n\n/**\n * Formats a date based on the range\n * - For ranges above 365 days: shows month and year (e.g. \"Apr 2025\")\n * - For ranges above 91 days: shows \"Week of [date]\"\n * - For other ranges: uses the default formatDisplayDate\n */\nexport const formatDisplayDateWithRange = (\n date: string,\n range: number,\n showHours: boolean = false,\n hoursOnly: boolean = false,\n): string => {\n if (range === 1 && hoursOnly) {\n return moment(date).format('h:mma');\n } else if (range === 1 && showHours) {\n return moment(date).format('MMM D, h:mma');\n } else if (range > 365) {\n return moment(date).format('MMM YYYY');\n } else if (range >= 91) {\n return `Week of ${formatDisplayDate(date)}`;\n }\n return formatDisplayDate(date);\n};\n\nexport const getYRange = (data: { value: number }[]): { min: number; max: number } => {\n if (!data.length) {\n return { min: 0, max: 1 };\n }\n\n const values = data.map((d) => Number(d.value));\n let min = Math.min(...values);\n let max = Math.max(...values);\n\n if (min === max) {\n const value = min;\n return { min: Math.max(0, value - 1), max: value + 1 };\n }\n\n // Use a percentage-based padding (10% of the range)\n const padding = 0.02;\n\n // Add padding and ensure min is not negative\n min = Math.max(0, min - min * padding);\n max = max + max * padding;\n\n const range = max - min;\n\n // Determine the order of magnitude for rounding based on the range\n const rangeMagnitude = Math.floor(Math.log10(range));\n // Always round to at least 10s, but use larger steps for bigger ranges\n // const roundTo = Math.max(10, Math.pow(10, rangeMagnitude));\n const roundTo = Math.pow(10, rangeMagnitude);\n\n // Round min and max to the appropriate precision\n const roundedMax = Math.round(max / roundTo) * roundTo;\n max = roundedMax < max ? Math.ceil(max / roundTo) * roundTo : roundedMax;\n\n const roundedMin = Math.round(min / roundTo) * roundTo;\n min = roundedMin > min ? Math.floor(min / roundTo) * roundTo : roundedMin;\n min = Math.max(0, min);\n\n // Ensure we have a visible range even after rounding\n if (min === max) {\n const midPoint = (min + max) / 2;\n const smallRange = Math.max(Math.abs(midPoint) * padding, roundTo);\n min = Math.max(0, Math.floor(midPoint - smallRange));\n max = Math.ceil(midPoint + smallRange);\n }\n\n // Final safety check to ensure min is never negative\n min = Math.max(0, min);\n\n return { min, max };\n};\n\n// Calculates the width needed for the Y-axis based on the formatted tick values\nexport const calculateYAxisWidth = (\n ticks: number[],\n formatter: (value: number) => string,\n): number => {\n if (!ticks.length) {\n return 40;\n }\n\n // Get the longest formatted tick value\n const maxFormattedLength = Math.max(...ticks.map((tick) => formatter(tick).length));\n\n // Approximate width based on character count (assuming monospace font)\n // Add padding for safety\n const width = Math.max(20, maxFormattedLength * 8 + 20);\n return width;\n};\n"],"mappings":";;;;AAQA,SAAgB,GAAG,GAAG,QAAsB;CAC1C,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAGA,SAAgB,SACd,MACA,MACA,YAAqB,OACC;CACtB,IAAI;CAEJ,OAAO,SAAyB,GAAG,MAAe;EAChD,MAAM,cAAc;GAClB,YAAY;GACZ,IAAI,CAAC,WACH,KAAK,MAAM,MAAM,IAAI;EAEzB;EAEA,MAAM,UAAU,aAAa,CAAC;EAE9B,IAAI,WACF,aAAa,SAAS;EAGxB,YAAY,WAAW,OAAO,IAAI;EAElC,IAAI,SACF,KAAK,MAAM,MAAM,IAAI;CAEzB;AACF;AAGA,SAAgB,gBAAgB,MAAuC;CACrE,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,gBAAgB,aAAa;EAC/B,MAAM,YAAY,OAAO,iBAAiB,IAAI,CAAC,CAAC;EAGhD,IAFqB,cAAc,aAAa,cAAc,YAE1C,KAAK,gBAAgB,KAAK,cAC5C,OAAO;CAEX;CAEA,OAAO,gBAAgB,KAAK,UAAU,KAAK,SAAS;AACtD;AAMA,IAAa,qBAAqB,QAAwB;CACxD,MAAM,YAAY,IAAI,QAAQ,qBAAqB,GAAG,SAAS,KAAK,YAAY,CAAC;CACjF,OAAO,UAAU,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU,MAAM,CAAC;AAC9D;AAIA,IAAa,qBAAqB,YAAoB,aAA8B;CAGlF,IAAI,sBAAsB,MACxB,aAAa,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AAK,MAAM,OAAO,IAAI,UAAU;CAE9D,MAAM,aAAa,KAAK,MAAM,MAAM,OAAO,IAAI;CAC/C,MAAM,aAAa,MAAM,KAAK,MAAM,MAAM,OAAO,IAAI,UAAU;CAC/D,MAAM,KAAK,IAAI,GAAG,GAAG;CAGrB,IAAI,QAAQ,KAAK;EACf,MAAM,YAAY,MAAM,OAAO;EAC/B,MAAM,aAAa,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,SAAS,OAAO;EACjE,MAAM,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,UAAU,CAAC;EACnD,MAAM,KAAK,KAAK,WAAW,UAAU;CACvC;CAGA,MAAM,KAAK,IAAI,GAAG,GAAG;CAErB,OAAO;EAAE;EAAK;CAAI;AACpB;AAGA,IAAa,uBACX,OACA,cACW;CACX,IAAI,CAAC,MAAM,QACT,OAAO;CAIT,MAAM,qBAAqB,KAAK,IAAI,GAAG,MAAM,KAAK,SAAS,UAAU,IAAI,CAAC,CAAC,MAAM,CAAC;CAKlF,OADc,KAAK,IAAI,IAAI,qBAAqB,IAAI,EAC7C;AACT"}
|
|
1
|
+
{"version":3,"file":"ds-utils.js","names":[],"sources":["../../src/lib/ds-utils.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/* Generic helper functions\n/* -------------------------------------------------------------------------- */\n\n// Helper to merge Tailwind classes\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n// Helper to debounce a function\nexport function debounce<T extends unknown[]>(\n func: (...args: T) => void,\n wait: number,\n immediate: boolean = false,\n): (...args: T) => void {\n let timeoutId: ReturnType<typeof setTimeout> | null;\n\n return function (this: unknown, ...args: T): void {\n const later = () => {\n timeoutId = null;\n if (!immediate) {\n func.apply(this, args);\n }\n };\n\n const callNow = immediate && !timeoutId;\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(later, wait);\n\n if (callNow) {\n func.apply(this, args);\n }\n };\n}\n\n// Helper to find scroll parent of element\nexport function getScrollParent(node: Node | null): HTMLElement | null {\n if (!node) {\n return null;\n }\n\n if (node instanceof HTMLElement) {\n const overflowY = window.getComputedStyle(node).overflowY;\n const isScrollable = overflowY !== 'visible' && overflowY !== 'hidden';\n\n if (isScrollable && node.scrollHeight >= node.clientHeight) {\n return node;\n }\n }\n\n return getScrollParent(node.parentNode) || document.body;\n}\n\n/* Data formatters\n/* -------------------------------------------------------------------------- */\n\n// Helper to convert kebab-case to PascalCase with numbers\nexport const kebabToPascalCase = (str: string): string => {\n const processed = str.replace(/[-_]([a-z0-9])/gi, (_, char) => char.toUpperCase());\n return processed.charAt(0).toUpperCase() + processed.slice(1);\n};\n\n// Helper function to format timestamp\nexport const formatTimestamp = (timestamp: string) => {\n const date = new Date(timestamp);\n const now = new Date();\n\n // Handle invalid dates\n if (isNaN(date.getTime())) {\n return 'Unknown';\n }\n\n // Both dates are now in the same timezone context (local)\n // The timestamp from DB is UTC but Date constructor handles the conversion\n const diffMs = now.getTime() - date.getTime();\n\n // Handle negative differences (future dates)\n if (diffMs < 0) {\n return 'Just now';\n }\n\n const diffMins = Math.floor(diffMs / (1000 * 60));\n const diffHours = Math.floor(diffMs / (1000 * 60 * 60));\n const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n\n if (diffMins < 1) {\n return 'Just now';\n } else if (diffMins < 60) {\n return `${diffMins} min ago`;\n } else if (diffHours < 24) {\n return `${diffHours} hr ago`;\n } else if (diffDays === 1) {\n return 'Yesterday';\n } else if (diffDays < 7) {\n return `${diffDays} days ago`;\n } else {\n return date.toLocaleDateString('en-US', {\n month: 'short',\n day: 'numeric',\n year: diffDays > 365 ? 'numeric' : undefined,\n });\n }\n};\n\n// Add thousands indicator to numbers\nexport const formatNumber = (\n value: number,\n options?: Pick<Intl.NumberFormatOptions, 'minimumFractionDigits' | 'maximumFractionDigits'>,\n): string => {\n if (isNaN(value) || !isFinite(value)) {\n return '0';\n }\n\n const formattedValue = options ? value : Math.round(value);\n return new Intl.NumberFormat('en-US', options).format(formattedValue);\n};\n\n// Abbreviate numbers\nexport function abbreviateNumber(number: number): string {\n const num = Number(number);\n\n if (Number.isNaN(num) || !Number.isFinite(number)) {\n return formatNumber(num);\n }\n\n if (num < 0) {\n return `-${abbreviateNumber(-num)}`;\n }\n\n if (num < 1000) {\n return formatNumber(num);\n }\n\n if (num < 1000000) {\n // For thousands: round to nearest 100 for 10.3k, nearest 1000 for 101k\n const roundTo = num < 100000 ? 100 : 1000;\n\n const rounded = Math.round(num / roundTo) * roundTo;\n const abbreviated = rounded / 1000;\n\n if (abbreviated === 1000) {\n return '1M';\n }\n\n const formatted = abbreviated % 1 === 0 ? abbreviated.toString() : abbreviated.toFixed(1);\n return `${formatted}k`;\n }\n\n // For millions: round to nearest 100,000 for 1.1M\n const roundTo = 100000;\n const rounded = Math.round(num / roundTo) * roundTo;\n const abbreviated = rounded / 1000000;\n const formatted = abbreviated % 1 === 0 ? abbreviated.toString() : abbreviated.toFixed(1);\n return `${formatted}M`;\n}\n\n// Format time duration\nexport const formatDuration = (seconds: number): string => {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds % 3600) / 60);\n const remainingSeconds = Math.floor(seconds % 60);\n\n if (hours <= 0) {\n if (minutes <= 0) {\n return `${remainingSeconds}s`;\n }\n return `${minutes}m ${remainingSeconds}s`;\n }\n\n return `${hours}h ${minutes}m ${remainingSeconds}s`;\n};\n\n// Format a fraction to percentage\nexport const formatPercentage = (value: number) => {\n const percentage = value * 100;\n if (percentage === 0) {\n return '0%';\n } else if (percentage < 0.1) {\n return `${percentage.toFixed(2)}%`;\n } else if (percentage < 1) {\n return `${percentage.toFixed(1)}%`;\n }\n const rounded = Math.round(percentage);\n return `${new Intl.NumberFormat('en-US').format(rounded)}%`;\n};\n\n// Converts a country code to corresponding flag emoji\nexport function getCountryFlag(countryCode: string) {\n if (\n !countryCode ||\n countryCode === null ||\n countryCode.toUpperCase() === 'NULL' ||\n countryCode === 'ᴺᵁᴸᴸ' ||\n countryCode === 'ᴺᵁ'\n ) {\n return '🏳️';\n }\n return countryCode\n .toUpperCase()\n .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397));\n}\n\nexport const stringToHslColor = (str: string, saturation: string, lightness: string) => {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash);\n }\n\n const h = hash % 360;\n return 'hsl(' + h + ', ' + saturation + '%, ' + lightness + '%)';\n};\n\n/* Chart formatters\n/* -------------------------------------------------------------------------- */\n\nexport const getYRange = (data: { value: number }[]): { min: number; max: number } => {\n if (!data.length) {\n return { min: 0, max: 1 };\n }\n\n const values = data.map((d) => Number(d.value));\n let min = Math.min(...values);\n let max = Math.max(...values);\n\n if (min === max) {\n const value = min;\n return { min: Math.max(0, value - 1), max: value + 1 };\n }\n\n // Use a percentage-based padding (10% of the range)\n const padding = 0.02;\n\n // Add padding and ensure min is not negative\n min = Math.max(0, min - min * padding);\n max = max + max * padding;\n\n const range = max - min;\n\n // Determine the order of magnitude for rounding based on the range\n const rangeMagnitude = Math.floor(Math.log10(range));\n // Always round to at least 10s, but use larger steps for bigger ranges\n // const roundTo = Math.max(10, Math.pow(10, rangeMagnitude));\n const roundTo = Math.pow(10, rangeMagnitude);\n\n // Round min and max to the appropriate precision\n const roundedMax = Math.round(max / roundTo) * roundTo;\n max = roundedMax < max ? Math.ceil(max / roundTo) * roundTo : roundedMax;\n\n const roundedMin = Math.round(min / roundTo) * roundTo;\n min = roundedMin > min ? Math.floor(min / roundTo) * roundTo : roundedMin;\n min = Math.max(0, min);\n\n // Ensure we have a visible range even after rounding\n if (min === max) {\n const midPoint = (min + max) / 2;\n const smallRange = Math.max(Math.abs(midPoint) * padding, roundTo);\n min = Math.max(0, Math.floor(midPoint - smallRange));\n max = Math.ceil(midPoint + smallRange);\n }\n\n // Final safety check to ensure min is never negative\n min = Math.max(0, min);\n\n return { min, max };\n};\n\n// Calculates the width needed for the Y-axis based on the formatted tick values\nexport const calculateYAxisWidth = (\n ticks: number[],\n formatter: (value: number) => string,\n): number => {\n if (!ticks.length) {\n return 40;\n }\n\n // Get the longest formatted tick value\n const maxFormattedLength = Math.max(...ticks.map((tick) => formatter(tick).length));\n\n // Approximate width based on character count (assuming monospace font)\n // Add padding for safety\n const width = Math.max(20, maxFormattedLength * 8 + 20);\n return width;\n};\n"],"mappings":";;;AAOA,SAAgB,GAAG,GAAG,QAAsB;CAC1C,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAGA,SAAgB,SACd,MACA,MACA,YAAqB,OACC;CACtB,IAAI;CAEJ,OAAO,SAAyB,GAAG,MAAe;EAChD,MAAM,cAAc;GAClB,YAAY;GACZ,IAAI,CAAC,WACH,KAAK,MAAM,MAAM,IAAI;EAEzB;EAEA,MAAM,UAAU,aAAa,CAAC;EAE9B,IAAI,WACF,aAAa,SAAS;EAGxB,YAAY,WAAW,OAAO,IAAI;EAElC,IAAI,SACF,KAAK,MAAM,MAAM,IAAI;CAEzB;AACF;AAGA,SAAgB,gBAAgB,MAAuC;CACrE,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,gBAAgB,aAAa;EAC/B,MAAM,YAAY,OAAO,iBAAiB,IAAI,CAAC,CAAC;EAGhD,IAFqB,cAAc,aAAa,cAAc,YAE1C,KAAK,gBAAgB,KAAK,cAC5C,OAAO;CAEX;CAEA,OAAO,gBAAgB,KAAK,UAAU,KAAK,SAAS;AACtD;AAMA,IAAa,qBAAqB,QAAwB;CACxD,MAAM,YAAY,IAAI,QAAQ,qBAAqB,GAAG,SAAS,KAAK,YAAY,CAAC;CACjF,OAAO,UAAU,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU,MAAM,CAAC;AAC9D;AAGA,IAAa,mBAAmB,cAAsB;CACpD,MAAM,OAAO,IAAI,KAAK,SAAS;CAC/B,MAAM,sBAAM,IAAI,KAAK;CAGrB,IAAI,MAAM,K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,OAAO;CAIT,MAAM,qBAAqB,KAAK,IAAI,GAAG,MAAM,KAAK,SAAS,UAAU,IAAI,CAAC,CAAC,MAAM,CAAC;CAKlF,OADc,KAAK,IAAI,IAAI,qBAAqB,IAAI,EAC7C;AACT"}
|
package/es/lib/utils.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { abbreviateNumber, calculateYAxisWidth, cn, debounce,
|
|
1
|
+
import { abbreviateNumber, calculateYAxisWidth, cn, debounce, formatDuration, formatNumber, formatPercentage, formatTimestamp, getCountryFlag, getScrollParent, getYRange, kebabToPascalCase, stringToHslColor } from "./ds-utils.js";
|
|
2
|
+
import { formatDisplayDate, formatDisplayDateWithRange, formatDisplayTime } from "./date-utils.js";
|
|
2
3
|
export { abbreviateNumber, calculateYAxisWidth, cn, debounce, formatDisplayDate, formatDisplayDateWithRange, formatDisplayTime, formatDuration, formatNumber, formatPercentage, formatTimestamp, getCountryFlag, getScrollParent, getYRange, kebabToPascalCase, stringToHslColor };
|