hazo_ui 2.17.0 → 3.0.1

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.cjs CHANGED
@@ -7687,6 +7687,200 @@ function useErrorDisplay() {
7687
7687
  const clearError = React25.useCallback(() => setRaw(null), []);
7688
7688
  return { error, setError, clearError };
7689
7689
  }
7690
+ function useDebounce(value, delayMs) {
7691
+ const [debounced_value, set_debounced_value] = React25.useState(value);
7692
+ React25.useEffect(() => {
7693
+ const timer = setTimeout(() => {
7694
+ set_debounced_value(value);
7695
+ }, delayMs);
7696
+ return () => clearTimeout(timer);
7697
+ }, [value, delayMs]);
7698
+ return debounced_value;
7699
+ }
7700
+ function useCopyToClipboard() {
7701
+ const [copied, set_copied] = React25.useState(false);
7702
+ const copy = React25.useCallback(async (text) => {
7703
+ if (typeof navigator === "undefined" || !navigator.clipboard) {
7704
+ return;
7705
+ }
7706
+ try {
7707
+ await navigator.clipboard.writeText(text);
7708
+ set_copied(true);
7709
+ setTimeout(() => set_copied(false), 2e3);
7710
+ } catch {
7711
+ }
7712
+ }, []);
7713
+ return { copied, copy };
7714
+ }
7715
+
7716
+ // src/hooks/use_is_mobile.ts
7717
+ var DEFAULT_BREAKPOINT_PX = 768;
7718
+ function useIsMobile(breakpointPx = DEFAULT_BREAKPOINT_PX) {
7719
+ return useMediaQuery(`(max-width: ${breakpointPx - 1}px)`);
7720
+ }
7721
+ function useViewport(breakpoint = DEFAULT_BREAKPOINT_PX) {
7722
+ return useIsMobile(breakpoint);
7723
+ }
7724
+ function useLocalStorage(key, initialValue) {
7725
+ const read_stored = () => {
7726
+ if (typeof window === "undefined") return initialValue;
7727
+ try {
7728
+ const raw = window.localStorage.getItem(key);
7729
+ return raw !== null ? JSON.parse(raw) : initialValue;
7730
+ } catch {
7731
+ return initialValue;
7732
+ }
7733
+ };
7734
+ const [stored_value, set_stored_value] = React25.useState(read_stored);
7735
+ const set_value = React25.useCallback(
7736
+ (value) => {
7737
+ set_stored_value((prev) => {
7738
+ const next = typeof value === "function" ? value(prev) : value;
7739
+ try {
7740
+ if (typeof window !== "undefined") {
7741
+ window.localStorage.setItem(key, JSON.stringify(next));
7742
+ }
7743
+ } catch {
7744
+ }
7745
+ return next;
7746
+ });
7747
+ },
7748
+ [key]
7749
+ );
7750
+ return [stored_value, set_value];
7751
+ }
7752
+ function useSessionStorage(key, initialValue) {
7753
+ const read_stored = () => {
7754
+ if (typeof window === "undefined") return initialValue;
7755
+ try {
7756
+ const raw = window.sessionStorage.getItem(key);
7757
+ return raw !== null ? JSON.parse(raw) : initialValue;
7758
+ } catch {
7759
+ return initialValue;
7760
+ }
7761
+ };
7762
+ const [stored_value, set_stored_value] = React25.useState(read_stored);
7763
+ const set_value = React25.useCallback(
7764
+ (value) => {
7765
+ set_stored_value((prev) => {
7766
+ const next = typeof value === "function" ? value(prev) : value;
7767
+ try {
7768
+ if (typeof window !== "undefined") {
7769
+ window.sessionStorage.setItem(key, JSON.stringify(next));
7770
+ }
7771
+ } catch {
7772
+ }
7773
+ return next;
7774
+ });
7775
+ },
7776
+ [key]
7777
+ );
7778
+ return [stored_value, set_value];
7779
+ }
7780
+ function useClickOutside(ref, handler) {
7781
+ React25.useEffect(() => {
7782
+ if (typeof document === "undefined") return;
7783
+ const handle_event = (event) => {
7784
+ const target = event.target;
7785
+ if (!ref.current || !target) return;
7786
+ if (!ref.current.contains(target)) {
7787
+ handler();
7788
+ }
7789
+ };
7790
+ document.addEventListener("mousedown", handle_event);
7791
+ document.addEventListener("touchstart", handle_event);
7792
+ return () => {
7793
+ document.removeEventListener("mousedown", handle_event);
7794
+ document.removeEventListener("touchstart", handle_event);
7795
+ };
7796
+ }, [ref, handler]);
7797
+ }
7798
+ function useWakeLock() {
7799
+ const supported = typeof navigator !== "undefined" && "wakeLock" in navigator;
7800
+ const sentinel_ref = React25.useRef(null);
7801
+ const [acquired, set_acquired] = React25.useState(false);
7802
+ const request = React25.useCallback(async () => {
7803
+ if (!supported || sentinel_ref.current) return;
7804
+ try {
7805
+ const sentinel = await navigator.wakeLock.request("screen");
7806
+ sentinel.addEventListener("release", () => {
7807
+ sentinel_ref.current = null;
7808
+ set_acquired(false);
7809
+ });
7810
+ sentinel_ref.current = sentinel;
7811
+ set_acquired(true);
7812
+ } catch {
7813
+ }
7814
+ }, [supported]);
7815
+ const release = React25.useCallback(async () => {
7816
+ if (!sentinel_ref.current) return;
7817
+ try {
7818
+ await sentinel_ref.current.release();
7819
+ } catch {
7820
+ } finally {
7821
+ sentinel_ref.current = null;
7822
+ set_acquired(false);
7823
+ }
7824
+ }, []);
7825
+ React25.useEffect(() => {
7826
+ if (typeof document === "undefined") return;
7827
+ const handle_visibility = () => {
7828
+ if (document.visibilityState === "visible" && acquired && !sentinel_ref.current) {
7829
+ void request();
7830
+ }
7831
+ };
7832
+ document.addEventListener("visibilitychange", handle_visibility);
7833
+ return () => document.removeEventListener("visibilitychange", handle_visibility);
7834
+ }, [acquired, request]);
7835
+ React25.useEffect(() => {
7836
+ return () => {
7837
+ if (sentinel_ref.current) {
7838
+ void sentinel_ref.current.release().catch(() => void 0);
7839
+ sentinel_ref.current = null;
7840
+ }
7841
+ };
7842
+ }, []);
7843
+ return { supported, acquired, request, release };
7844
+ }
7845
+ function useFullscreen(elementRef) {
7846
+ const [is_fullscreen, set_is_fullscreen] = React25.useState(false);
7847
+ React25.useEffect(() => {
7848
+ if (typeof document === "undefined") return;
7849
+ const handle_change = () => {
7850
+ set_is_fullscreen(!!document.fullscreenElement);
7851
+ };
7852
+ document.addEventListener("fullscreenchange", handle_change);
7853
+ set_is_fullscreen(!!document.fullscreenElement);
7854
+ return () => document.removeEventListener("fullscreenchange", handle_change);
7855
+ }, []);
7856
+ const get_target = React25.useCallback(() => {
7857
+ return elementRef?.current ?? document.documentElement;
7858
+ }, [elementRef]);
7859
+ const enter = React25.useCallback(async () => {
7860
+ if (typeof document === "undefined" || !document.documentElement.requestFullscreen) return;
7861
+ if (document.fullscreenElement) return;
7862
+ try {
7863
+ await get_target().requestFullscreen();
7864
+ } catch {
7865
+ }
7866
+ }, [get_target]);
7867
+ const exit = React25.useCallback(async () => {
7868
+ if (typeof document === "undefined") return;
7869
+ if (!document.fullscreenElement) return;
7870
+ try {
7871
+ await document.exitFullscreen();
7872
+ } catch {
7873
+ }
7874
+ }, []);
7875
+ const toggle = React25.useCallback(async () => {
7876
+ if (document.fullscreenElement) {
7877
+ await exit();
7878
+ } else {
7879
+ await enter();
7880
+ }
7881
+ }, [enter, exit]);
7882
+ return { isFullscreen: is_fullscreen, enter, exit, toggle };
7883
+ }
7690
7884
  function KanbanCard({
7691
7885
  item,
7692
7886
  renderCard,
@@ -10104,6 +10298,291 @@ function DateRangeSelector({
10104
10298
  );
10105
10299
  }
10106
10300
 
10301
+ // src/assets/celebration-chime.mp3
10302
+ var celebration_chime_default = "data:text/plain;charset=utf-8,";
10303
+ var CELEBRATION_GRADIENT = "linear-gradient(135deg, #667eea 0%, #764ba2 100%)";
10304
+ var CARD_SIZE = 1080;
10305
+ var PREVIEW_SIZE = 400;
10306
+ var CARD_SCALE = PREVIEW_SIZE / CARD_SIZE;
10307
+ var _enqueue = null;
10308
+ function celebrate(payload) {
10309
+ if (!_enqueue) {
10310
+ if (process.env.NODE_ENV !== "production") {
10311
+ console.warn(
10312
+ "[hazo_ui] celebrate() called before <CelebrationProvider /> was mounted"
10313
+ );
10314
+ }
10315
+ return;
10316
+ }
10317
+ _enqueue(payload);
10318
+ }
10319
+ function CelebrationProvider({ children }) {
10320
+ const [queue, set_queue] = React25__namespace.useState([]);
10321
+ const enqueue = React25__namespace.useCallback((payload) => {
10322
+ const storage_key = `hazo_ui_celebration_${payload.id}`;
10323
+ if (typeof window !== "undefined" && sessionStorage.getItem(storage_key)) {
10324
+ return;
10325
+ }
10326
+ set_queue((q) => [...q, payload]);
10327
+ }, []);
10328
+ React25__namespace.useEffect(() => {
10329
+ _enqueue = enqueue;
10330
+ return () => {
10331
+ _enqueue = null;
10332
+ };
10333
+ }, [enqueue]);
10334
+ const handle_close = React25__namespace.useCallback(() => {
10335
+ set_queue((q) => q.slice(1));
10336
+ }, []);
10337
+ const current = queue[0] ?? null;
10338
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10339
+ children,
10340
+ current && /* @__PURE__ */ jsxRuntime.jsx(
10341
+ CelebrationModalInner,
10342
+ {
10343
+ payload: current,
10344
+ onClose: handle_close
10345
+ },
10346
+ current.id
10347
+ )
10348
+ ] });
10349
+ }
10350
+ function CelebrationModalInner({
10351
+ payload,
10352
+ onClose
10353
+ }) {
10354
+ const {
10355
+ id,
10356
+ title,
10357
+ subtitle,
10358
+ shareableCard,
10359
+ autoDismiss = true,
10360
+ autoDismissDelay = 8e3,
10361
+ audioChime = false
10362
+ } = payload;
10363
+ const [visible, set_visible] = React25__namespace.useState(true);
10364
+ const [is_downloading, set_is_downloading] = React25__namespace.useState(false);
10365
+ const canvas_ref = React25__namespace.useRef(null);
10366
+ const card_ref = React25__namespace.useRef(null);
10367
+ React25__namespace.useEffect(() => {
10368
+ sessionStorage.setItem(`hazo_ui_celebration_${id}`, "1");
10369
+ }, [id]);
10370
+ React25__namespace.useEffect(() => {
10371
+ if (!canvas_ref.current) return;
10372
+ let confetti_instance = null;
10373
+ import('canvas-confetti').then(({ default: confetti }) => {
10374
+ if (!canvas_ref.current) return;
10375
+ confetti_instance = confetti.create(canvas_ref.current, { resize: true });
10376
+ confetti_instance({
10377
+ particleCount: 120,
10378
+ spread: 70,
10379
+ origin: { y: 0.5 },
10380
+ colors: ["#667eea", "#764ba2", "#f6d365", "#fda085", "#84fab0"]
10381
+ });
10382
+ });
10383
+ return () => {
10384
+ confetti_instance?.reset();
10385
+ };
10386
+ }, []);
10387
+ React25__namespace.useEffect(() => {
10388
+ if (!audioChime) return;
10389
+ const audio = new Audio(celebration_chime_default);
10390
+ audio.play().catch(() => {
10391
+ });
10392
+ }, [audioChime]);
10393
+ React25__namespace.useEffect(() => {
10394
+ if (!autoDismiss) return;
10395
+ const timer = window.setTimeout(close_modal, autoDismissDelay);
10396
+ return () => window.clearTimeout(timer);
10397
+ }, [autoDismiss, autoDismissDelay]);
10398
+ React25__namespace.useEffect(() => {
10399
+ const on_key = (e) => {
10400
+ if (e.key === "Escape") close_modal();
10401
+ };
10402
+ document.addEventListener("keydown", on_key);
10403
+ return () => document.removeEventListener("keydown", on_key);
10404
+ }, []);
10405
+ function close_modal() {
10406
+ set_visible(false);
10407
+ setTimeout(onClose, 150);
10408
+ }
10409
+ async function handle_download() {
10410
+ if (!card_ref.current) return;
10411
+ set_is_downloading(true);
10412
+ try {
10413
+ const { toPng } = await import('html-to-image');
10414
+ const data_url = await toPng(card_ref.current, {
10415
+ width: CARD_SIZE,
10416
+ height: CARD_SIZE
10417
+ });
10418
+ const a = document.createElement("a");
10419
+ a.download = `${id}.png`;
10420
+ a.href = data_url;
10421
+ a.click();
10422
+ } catch (err) {
10423
+ console.error("[hazo_ui] CelebrationModal: download failed", err);
10424
+ } finally {
10425
+ set_is_downloading(false);
10426
+ }
10427
+ }
10428
+ async function handle_share() {
10429
+ if (!card_ref.current || !navigator.share) return;
10430
+ try {
10431
+ const { toPng } = await import('html-to-image');
10432
+ const data_url = await toPng(card_ref.current, {
10433
+ width: CARD_SIZE,
10434
+ height: CARD_SIZE
10435
+ });
10436
+ const blob = await fetch(data_url).then((r) => r.blob());
10437
+ await navigator.share({
10438
+ files: [new File([blob], `${id}.png`, { type: "image/png" })]
10439
+ });
10440
+ } catch (err) {
10441
+ console.error("[hazo_ui] CelebrationModal: share failed", err);
10442
+ }
10443
+ }
10444
+ async function handle_copy() {
10445
+ if (!card_ref.current) return;
10446
+ try {
10447
+ const { toPng } = await import('html-to-image');
10448
+ const data_url = await toPng(card_ref.current, {
10449
+ width: CARD_SIZE,
10450
+ height: CARD_SIZE
10451
+ });
10452
+ const blob = await fetch(data_url).then((r) => r.blob());
10453
+ await navigator.clipboard.write([
10454
+ new ClipboardItem({ "image/png": blob })
10455
+ ]);
10456
+ } catch (err) {
10457
+ console.error("[hazo_ui] CelebrationModal: copy failed", err);
10458
+ }
10459
+ }
10460
+ const resolved_caption = shareableCard?.caption ?? subtitle;
10461
+ const card_bg = shareableCard?.background ?? CELEBRATION_GRADIENT;
10462
+ const can_share = typeof navigator !== "undefined" && "share" in navigator;
10463
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10464
+ "div",
10465
+ {
10466
+ className: cn(
10467
+ "cls_celebration_modal_overlay",
10468
+ "fixed inset-0 z-50 flex items-center justify-center",
10469
+ "bg-black/30 backdrop-blur-sm",
10470
+ "transition-opacity duration-150",
10471
+ visible ? "opacity-100" : "opacity-0 pointer-events-none"
10472
+ ),
10473
+ onClick: close_modal,
10474
+ children: [
10475
+ /* @__PURE__ */ jsxRuntime.jsx(
10476
+ "canvas",
10477
+ {
10478
+ ref: canvas_ref,
10479
+ className: "cls_celebration_confetti_canvas absolute inset-0 w-full h-full pointer-events-none"
10480
+ }
10481
+ ),
10482
+ /* @__PURE__ */ jsxRuntime.jsxs(
10483
+ "div",
10484
+ {
10485
+ className: cn(
10486
+ "cls_celebration_modal_card",
10487
+ "relative bg-white rounded-2xl shadow-2xl",
10488
+ "flex flex-col items-center overflow-hidden",
10489
+ "transition-transform duration-150",
10490
+ visible ? "scale-100" : "scale-95"
10491
+ ),
10492
+ style: { width: 480, maxWidth: "95vw" },
10493
+ onClick: (e) => e.stopPropagation(),
10494
+ children: [
10495
+ /* @__PURE__ */ jsxRuntime.jsx(
10496
+ "button",
10497
+ {
10498
+ className: "cls_celebration_close_btn absolute top-3 right-3 z-10 p-1.5 rounded-full hover:bg-black/10 transition-colors",
10499
+ onClick: close_modal,
10500
+ "aria-label": "Close celebration",
10501
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4 text-gray-600" })
10502
+ }
10503
+ ),
10504
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cls_celebration_header px-8 pt-8 pb-5 text-center", children: [
10505
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "cls_celebration_title text-2xl font-bold text-gray-900", children: title }),
10506
+ subtitle && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cls_celebration_subtitle mt-1.5 text-sm text-gray-500 leading-relaxed", children: subtitle })
10507
+ ] }),
10508
+ shareableCard && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10509
+ /* @__PURE__ */ jsxRuntime.jsx(
10510
+ "div",
10511
+ {
10512
+ className: "cls_celebration_card_preview_wrapper overflow-hidden rounded-lg mx-8",
10513
+ style: { width: PREVIEW_SIZE, height: PREVIEW_SIZE },
10514
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
10515
+ "div",
10516
+ {
10517
+ ref: card_ref,
10518
+ className: "cls_celebration_card_inner",
10519
+ style: {
10520
+ width: CARD_SIZE,
10521
+ height: CARD_SIZE,
10522
+ transform: `scale(${CARD_SCALE})`,
10523
+ transformOrigin: "top left",
10524
+ background: card_bg,
10525
+ display: "flex",
10526
+ flexDirection: "column",
10527
+ alignItems: "center",
10528
+ justifyContent: "center",
10529
+ padding: 80,
10530
+ boxSizing: "border-box"
10531
+ },
10532
+ children: [
10533
+ shareableCard.foreground,
10534
+ resolved_caption && /* @__PURE__ */ jsxRuntime.jsx(
10535
+ "p",
10536
+ {
10537
+ style: {
10538
+ marginTop: 32,
10539
+ fontSize: 36,
10540
+ color: "white",
10541
+ textAlign: "center",
10542
+ fontWeight: 600,
10543
+ lineHeight: 1.3
10544
+ },
10545
+ children: resolved_caption
10546
+ }
10547
+ )
10548
+ ]
10549
+ }
10550
+ )
10551
+ }
10552
+ ),
10553
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cls_celebration_card_actions flex flex-wrap gap-2 px-8 py-5", children: [
10554
+ /* @__PURE__ */ jsxRuntime.jsxs(
10555
+ Button,
10556
+ {
10557
+ className: "cls_celebration_download_btn",
10558
+ size: "sm",
10559
+ onClick: handle_download,
10560
+ disabled: is_downloading,
10561
+ children: [
10562
+ is_downloading ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-3.5 w-3.5 mr-1.5 animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-3.5 w-3.5 mr-1.5" }),
10563
+ "Download PNG"
10564
+ ]
10565
+ }
10566
+ ),
10567
+ can_share && /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", onClick: handle_share, children: [
10568
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Share2, { className: "h-3.5 w-3.5 mr-1.5" }),
10569
+ "Share"
10570
+ ] }),
10571
+ /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", onClick: handle_copy, children: [
10572
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-3.5 w-3.5 mr-1.5" }),
10573
+ "Copy image"
10574
+ ] })
10575
+ ] })
10576
+ ] }),
10577
+ !shareableCard && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cls_celebration_footer pb-8", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "sm", onClick: close_modal, children: "Dismiss" }) })
10578
+ ]
10579
+ }
10580
+ )
10581
+ ]
10582
+ }
10583
+ );
10584
+ }
10585
+
10107
10586
  Object.defineProperty(exports, "rawToast", {
10108
10587
  enumerable: true,
10109
10588
  get: function () { return sonner.toast; }
@@ -10128,6 +10607,7 @@ exports.Button = Button;
10128
10607
  exports.ButtonGroup = ButtonGroup;
10129
10608
  exports.ButtonGroupSeparator = ButtonGroupSeparator;
10130
10609
  exports.ButtonGroupText = ButtonGroupText;
10610
+ exports.CELEBRATION_GRADIENT = CELEBRATION_GRADIENT;
10131
10611
  exports.Calendar = Calendar;
10132
10612
  exports.Card = Card;
10133
10613
  exports.CardContent = CardContent;
@@ -10135,6 +10615,7 @@ exports.CardDescription = CardDescription;
10135
10615
  exports.CardFooter = CardFooter;
10136
10616
  exports.CardHeader = CardHeader;
10137
10617
  exports.CardTitle = CardTitle;
10618
+ exports.CelebrationProvider = CelebrationProvider;
10138
10619
  exports.Checkbox = Checkbox;
10139
10620
  exports.Collapsible = Collapsible;
10140
10621
  exports.CollapsibleContent = CollapsibleContent2;
@@ -10260,6 +10741,7 @@ exports.TooltipProvider = TooltipProvider;
10260
10741
  exports.TooltipTrigger = TooltipTrigger;
10261
10742
  exports.applyKanbanFilter = applyKanbanFilter;
10262
10743
  exports.buttonGroupVariants = buttonGroupVariants;
10744
+ exports.celebrate = celebrate;
10263
10745
  exports.create_command_suggestion_extension = create_command_suggestion_extension;
10264
10746
  exports.errorToast = errorToast;
10265
10747
  exports.format_num = format_num;
@@ -10272,8 +10754,17 @@ exports.set_hazo_ui_config = set_hazo_ui_config;
10272
10754
  exports.successToast = successToast;
10273
10755
  exports.text_to_tiptap_content = text_to_tiptap_content;
10274
10756
  exports.toggleVariants = toggleVariants;
10757
+ exports.useClickOutside = useClickOutside;
10758
+ exports.useCopyToClipboard = useCopyToClipboard;
10759
+ exports.useDebounce = useDebounce;
10275
10760
  exports.useErrorDisplay = useErrorDisplay;
10761
+ exports.useFullscreen = useFullscreen;
10762
+ exports.useIsMobile = useIsMobile;
10276
10763
  exports.useLoadingState = useLoadingState;
10764
+ exports.useLocalStorage = useLocalStorage;
10277
10765
  exports.useMediaQuery = useMediaQuery;
10766
+ exports.useSessionStorage = useSessionStorage;
10767
+ exports.useViewport = useViewport;
10768
+ exports.useWakeLock = useWakeLock;
10278
10769
  //# sourceMappingURL=index.cjs.map
10279
10770
  //# sourceMappingURL=index.cjs.map