@ngrok/mantle 0.53.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alert-dialog.js +1 -1
- package/dist/{chunk-4MGNTF6Q.js → chunk-BK5H6ZXB.js} +2 -2
- package/dist/chunk-N6ZW2CVT.js +99 -0
- package/dist/chunk-N6ZW2CVT.js.map +1 -0
- package/dist/dialog.js +1 -1
- package/dist/icons.js +1 -1
- package/dist/sheet.js +1 -1
- package/dist/theme.d.ts +23 -3
- package/dist/theme.js +1 -1
- package/dist/toast.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-WB5DRE27.js +0 -34
- package/dist/chunk-WB5DRE27.js.map +0 -1
- /package/dist/{chunk-4MGNTF6Q.js.map → chunk-BK5H6ZXB.js.map} +0 -0
package/dist/alert-dialog.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as y,b as A,c as u,d,e as D,f as C,g as P,h as v}from"./chunk-VIKPHWPP.js";import{d as c}from"./chunk-
|
|
1
|
+
import{a as y,b as A,c as u,d,e as D,f as C,g as P,h as v}from"./chunk-VIKPHWPP.js";import{d as c}from"./chunk-BK5H6ZXB.js";import"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";import{a as m}from"./chunk-T5U5KWUW.js";import"./chunk-4LSFAAZW.js";import"./chunk-72TJUKMV.js";import"./chunk-3C5O3AQA.js";import"./chunk-I6T6YV2L.js";import{a as g}from"./chunk-NPTDRQT5.js";import{a}from"./chunk-AZ56JGNY.js";import{InfoIcon as H}from"@phosphor-icons/react/Info";import{WarningIcon as k}from"@phosphor-icons/react/Warning";import{Slot as f}from"@radix-ui/react-slot";import{createContext as M,forwardRef as n,useContext as $,useMemo as q}from"react";import E from"tiny-invariant";import{jsx as i,jsxs as J}from"react/jsx-runtime";var x=M(null);function N(){let t=$(x);return E(t,"AlertDialog child component used outside of AlertDialog parent!"),t}function h({priority:t,...e}){let o=q(()=>({priority:t}),[t]);return i(x.Provider,{value:o,children:i(y,{...e})})}h.displayName="AlertDialog";var R=A;R.displayName="AlertDialogTrigger";var b=u;b.displayName="AlertDialogPortal";var W=n(({className:t,...e},o)=>i(D,{className:a("data-state-open:animate-in data-state-closed:animate-out data-state-closed:fade-out-0 data-state-open:fade-in-0 bg-overlay fixed inset-0 z-50 backdrop-blur-xs",t),...e,ref:o}));W.displayName="AlertDialogOverlay";var I=n(({className:t,onInteractOutside:e,onPointerDownOutside:o,preferredWidth:l="max-w-md",...r},p)=>J(b,{children:[i(W,{}),i("div",{className:"fixed inset-4 z-50 flex items-center justify-center",children:i(C,{ref:p,className:a("flex w-full flex-1 flex-col items-center gap-4 sm:flex-row sm:items-start","outline-hidden focus-within:outline-hidden","p-6","border-dialog bg-dialog rounded-xl border shadow-lg transition-transform 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",l,t),onInteractOutside:s=>{c(s),e?.(s)},onPointerDownOutside:s=>{c(s),o?.(s)},...r})})]}));I.displayName="AlertDialogContent";var O=n(({asChild:t=!1,className:e,...o},l)=>i(t?f:"div",{className:a("flex-1 space-y-4",e),ref:l,...o}));O.displayName="AlertDialogBody";var w=n(({asChild:t=!1,className:e,...o},l)=>i(t?f:"div",{className:a("flex flex-col space-y-2 text-center sm:text-start",e),...o}));w.displayName="AlertDialogHeader";var B=n(({asChild:t=!1,className:e,...o},l)=>i(t?f:"div",{className:a("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...o}));B.displayName="AlertDialogFooter";var T=n(({className:t,...e},o)=>i(P,{ref:o,className:a("text-strong text-center text-lg font-medium sm:text-start",t),...e}));T.displayName="AlertDialogTitle";var z=n(({className:t,...e},o)=>i(v,{ref:o,className:a("text-body text-center text-sm font-normal sm:text-start",t),...e}));z.displayName="AlertDialogDescription";var S=n(({appearance:t="filled",...e},o)=>{let l=N(),r="default";return l.priority==="danger"&&(r="danger"),i(m,{appearance:t,priority:r,ref:o,...e})});S.displayName="AlertDialogAction";var j=n(({appearance:t="outlined",className:e,priority:o="neutral",...l},r)=>i(d,{asChild:!0,children:i(m,{appearance:t,className:a("mt-2 sm:mt-0",e),priority:o,ref:r,...l})}));j.displayName="AlertDialogCancel";var V=n(({className:t,svg:e,...o},l)=>{let r=N(),p=r.priority==="danger"?"text-danger-600":"text-accent-600",s=r.priority==="danger"?i(k,{}):i(H,{});return i(g,{ref:l,className:a("size-12 sm:size-7",p,t),svg:e??s,...o})});V.displayName="AlertDialogIcon";var F=d;F.displayName="AlertDialogClose";var G={Root:h,Action:S,Body:O,Cancel:j,Close:F,Content:I,Description:z,Footer:B,Header:w,Icon:V,Title:T,Trigger:R};export{G as AlertDialog};
|
|
2
2
|
//# sourceMappingURL=alert-dialog.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{l as y}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{l as y}from"./chunk-N6ZW2CVT.js";import{a as p}from"./chunk-I6T6YV2L.js";import{a as n}from"./chunk-AZ56JGNY.js";import{CheckCircleIcon as x}from"@phosphor-icons/react/CheckCircle";import{InfoIcon as w}from"@phosphor-icons/react/Info";import{WarningIcon as A}from"@phosphor-icons/react/Warning";import{WarningDiamondIcon as I}from"@phosphor-icons/react/WarningDiamond";import{Slot as l}from"@radix-ui/react-slot";import{createContext as P,forwardRef as d,useContext as f}from"react";import*as c from"sonner";import{jsx as r,jsxs as k}from"react/jsx-runtime";var N=({className:t,containerAriaLabel:o,dir:e,duration_ms:s=4e3,position:i="top-center",style:a})=>{let m=y();return r(c.Toaster,{className:n("toaster overlay-prompt pointer-events-auto *:duration-200",t),containerAriaLabel:o,dir:e,duration:s,gap:12,position:i??"top-center",style:a,theme:m,toastOptions:{unstyled:!0}})};N.displayName="Toaster";var g=P("");function z(t,o){return c.toast.custom(e=>r(g.Provider,{value:e,children:t}),{duration:o?.duration_ms,...o?.id?{id:o.id}:{},unstyled:!0})}var T=P({priority:"info"}),v=d(({asChild:t,children:o,className:e,priority:s,...i},a)=>{let m=t?l:"div";return r(T.Provider,{value:{priority:s},children:k(m,{className:n("relative flex items-start gap-2 text-sm","p-3 pl-[0.9375rem]","bg-popover high-contrast:border-popover rounded rounded-r-[0.3125rem] border border-gray-500/35 shadow-lg",e),ref:a,...i,children:[r(S,{priority:s}),o]})})});v.displayName="Toast";var h=d(({className:t,svg:o,...e},s)=>{let i=f(T);switch(i.priority){case"danger":return r(p,{className:n("text-danger-600",t),ref:s,svg:o??r(A,{weight:"fill"}),...e});case"warning":return r(p,{className:n("text-warning-600",t),ref:s,svg:o??r(I,{weight:"fill"}),...e});case"success":return r(p,{className:n("text-success-600",t),ref:s,svg:o??r(x,{weight:"fill"}),...e});case"info":return r(p,{className:n("text-accent-600",t),ref:s,svg:r(w,{weight:"fill"}),...e});default:throw new Error(`Unreachable Case: ${i.priority}`)}});h.displayName="ToastIcon";var C=d(({asChild:t,className:o,onClick:e,...s},i)=>{let a=f(g);return r(t?l:"button",{className:n("shrink-0","data-[icon-button]:-mr-0.5 data-[icon-button]:-mt-0.5 data-[icon-button]:rounded-xs",o),onClick:u=>{e?.(u),!u.defaultPrevented&&c.toast.dismiss(a)},ref:i,...s})});C.displayName="ToastAction";var b=d(({asChild:t,className:o,...e},s)=>r(t?l:"p",{className:n("text-strong flex-1 text-sm font-body",o),ref:s,...e}));b.displayName="ToastMessage";var F={Root:v,Action:C,Icon:h,Message:b};function U(t){t.target instanceof Element&&t.target.closest(".overlay-prompt")&&t.preventDefault()}var R={info:"bg-accent-600",warning:"bg-warning-600",success:"bg-success-600",danger:"bg-danger-600"};function S({className:t,priority:o,...e}){return r("div",{"aria-hidden":!0,className:n("z-1 absolute -inset-px right-auto w-1.5 rounded-l",R[o],t),...e})}export{N as a,z as b,F as c,U as d};
|
|
2
|
+
//# sourceMappingURL=chunk-BK5H6ZXB.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import{a as T}from"./chunk-6J7D73WA.js";import{Fragment as x,jsx as a,jsxs as C}from"react/jsx-runtime";var S="https://assets.ngrok.com",D=`${S}/fonts`,F=["/euclid-square/EuclidSquare-Regular-WebS.woff","/euclid-square/EuclidSquare-RegularItalic-WebS.woff","/euclid-square/EuclidSquare-Medium-WebS.woff","/euclid-square/EuclidSquare-Semibold-WebS.woff","/euclid-square/EuclidSquare-MediumItalic-WebS.woff","/ibm-plex-mono/IBMPlexMono-Text.woff","/ibm-plex-mono/IBMPlexMono-TextItalic.woff","/ibm-plex-mono/IBMPlexMono-SemiBold.woff","/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff"],H=e=>`${D}${e}`,g=({includeNunitoSans:e=!1})=>C(x,{children:[a("link",{rel:"preconnect",href:S}),F.map(t=>a("link",{rel:"preload",href:H(t),as:"font",type:"font/woff",crossOrigin:"anonymous"},t)),e&&a(O,{})]});g.displayName="PreloadFonts";function O(){return C(x,{children:[a("link",{rel:"preconnect",href:"https://fonts.googleapis.com"}),a("link",{rel:"preconnect",href:"https://fonts.gstatic.com",crossOrigin:"anonymous"}),a("link",{href:"https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000&display=swap",rel:"stylesheet"})]})}import M from"clsx";import{createContext as L,useContext as E,useEffect as P,useMemo as I,useState as $}from"react";import N from"tiny-invariant";import{Fragment as K,jsx as k,jsxs as A}from"react/jsx-runtime";var c="(prefers-color-scheme: dark)",l="(prefers-contrast: more)",y=["light","dark","light-high-contrast","dark-high-contrast"],b=["system",...y],te=e=>e;function R(e){return typeof e!="string"?!1:b.includes(e)}var oe=e=>e;function q(e){return typeof e!="string"?!1:y.includes(e)}var f="mantle-ui-theme",W=["system",()=>null],v=L(W),d=()=>typeof window<"u";function _(e,t){if(d())try{let o=new Date;o.setFullYear(o.getFullYear()+1);let{hostname:s,protocol:r}=window.location,i=s==="ngrok.com"||s.endsWith(".ngrok.com")?"; domain=.ngrok.com":"",n=r==="https:"?"; Secure":"";document.cookie=`${e}=${encodeURIComponent(t)}; expires=${o.toUTCString()}; path=/${i}; SameSite=Lax${n}`}catch{}}function p(e,t="system"){let o=t??"system";if(d()){let s=null;try{let i=document.cookie.split(";").find(n=>n.trim().startsWith(`${e}=`));if(i){let n=i.trim().substring(e.length+1);s=n?decodeURIComponent(n):null}}catch{}return R(s)?s:o}return o}function V({children:e,defaultTheme:t="system",storageKey:o=f}){let[s,r]=$(()=>{let n=p(o,t);return u(n),n});P(()=>{let n=p(o,t);r(n),u(n)},[t,o]),P(()=>{let n=window.matchMedia(c),m=window.matchMedia(l),h=()=>{p(o,t)==="system"&&u("system")};return n.addEventListener("change",h),m.addEventListener("change",h),()=>{n.removeEventListener("change",h),m.removeEventListener("change",h)}},[t,o]);let i=I(()=>[s,n=>{_(o,n),r(n),u(n)}],[o,s]);return k(v.Provider,{value:i,children:e})}V.displayName="ThemeProvider";function ne(){let e=E(v);return N(e,"useTheme must be used within a ThemeProvider"),e}function u(e){if(!d())return;let t=window.document.documentElement;t.classList.remove(...b);let o=window.matchMedia(c).matches,s=window.matchMedia(l).matches,r=w(e,{prefersDarkMode:o,prefersHighContrast:s});t.classList.add(r),t.dataset.appliedTheme=r,t.dataset.theme=e}function se(){if(!d())return{appliedTheme:void 0,theme:void 0};let e=window.document.documentElement,t=R(e.dataset.theme)?e.dataset.theme:void 0;return{appliedTheme:q(e.dataset.appliedTheme)?e.dataset.appliedTheme:void 0,theme:t}}function w(e,{prefersDarkMode:t,prefersHighContrast:o}){return e==="system"?Y({prefersDarkMode:t,prefersHighContrast:o}):e}function re(){let e=E(v),t=e!=null?e[0]:"system",o=T(c),s=T(l);return w(t,{prefersDarkMode:o,prefersHighContrast:s})}function Y({prefersDarkMode:e,prefersHighContrast:t}){return t?e?"dark-high-contrast":"light-high-contrast":e?"dark":"light"}function B(e){let{defaultTheme:t="system",storageKey:o=f}=e??{};return`
|
|
2
|
+
(function() {
|
|
3
|
+
const RESOLVED = ${JSON.stringify(y)};
|
|
4
|
+
const DEF = "${t}";
|
|
5
|
+
const KEY = "${o}";
|
|
6
|
+
const doc = document, root = doc.documentElement;
|
|
7
|
+
|
|
8
|
+
function isTheme(v) {
|
|
9
|
+
return typeof v === "string" && (v === "system" || RESOLVED.indexOf(v) > -1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function readCookie(name){
|
|
13
|
+
// Efficient single-pass cookie lookup: "; name=value"
|
|
14
|
+
const all = "; " + doc.cookie, token = "; " + name + "=";
|
|
15
|
+
const startIdx = all.indexOf(token);
|
|
16
|
+
if (startIdx < 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const endIdx = all.indexOf(";", startIdx + token.length);
|
|
20
|
+
const rawValue = all.slice(startIdx + token.length, endIdx < 0 ? void 0 : endIdx) || null;
|
|
21
|
+
try {
|
|
22
|
+
return rawValue ? decodeURIComponent(rawValue) : null;
|
|
23
|
+
} catch(_) {
|
|
24
|
+
return rawValue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function writeCookie(name, val) {
|
|
29
|
+
try {
|
|
30
|
+
const expires = new Date();
|
|
31
|
+
expires.setFullYear(expires.getFullYear() + 1);
|
|
32
|
+
const hostname = location.hostname;
|
|
33
|
+
const protocol = location.protocol;
|
|
34
|
+
const isDotNgrok = (hostname === "ngrok.com" || hostname.endsWith(".ngrok.com"));
|
|
35
|
+
const domain = isDotNgrok ? "; domain=.ngrok.com" : "";
|
|
36
|
+
const secure = protocol === "https:" ? "; Secure" : "";
|
|
37
|
+
doc.cookie = name + "=" + encodeURIComponent(val) + "; expires=" + expires.toUTCString() + "; path=/" + domain + "; SameSite=Lax" + secure;
|
|
38
|
+
} catch(_) {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 1) Read preference: cookie first, fallback to localStorage (migration support)
|
|
42
|
+
let cookieTheme = null, lsTheme = null, storedTheme = null;
|
|
43
|
+
try {
|
|
44
|
+
cookieTheme = readCookie(KEY);
|
|
45
|
+
} catch(_) {}
|
|
46
|
+
|
|
47
|
+
if (isTheme(cookieTheme)) {
|
|
48
|
+
storedTheme = cookieTheme;
|
|
49
|
+
} else {
|
|
50
|
+
try {
|
|
51
|
+
lsTheme = window.localStorage && window.localStorage.getItem(KEY);
|
|
52
|
+
} catch(_) {}
|
|
53
|
+
if (isTheme(lsTheme)) {
|
|
54
|
+
storedTheme = lsTheme;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const preference = isTheme(storedTheme) ? storedTheme : DEF;
|
|
59
|
+
|
|
60
|
+
// 2) Resolve only when needed to avoid unnecessary media queries
|
|
61
|
+
let resolvedTheme = preference;
|
|
62
|
+
if (preference === "system") {
|
|
63
|
+
const isDark = matchMedia("${c}").matches;
|
|
64
|
+
const isHighContrast = matchMedia("${l}").matches;
|
|
65
|
+
resolvedTheme = isHighContrast
|
|
66
|
+
? (isDark ? "dark-high-contrast" : "light-high-contrast")
|
|
67
|
+
: (isDark ? "dark" : "light");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 3) Only touch DOM if we actually need to change something (SSR optimization)
|
|
71
|
+
if (root.dataset.appliedTheme !== resolvedTheme || root.dataset.theme !== preference) {
|
|
72
|
+
// Remove all theme classes, add the correct one
|
|
73
|
+
for (let i = 0; i < RESOLVED.length; i++) {
|
|
74
|
+
root.classList.remove(RESOLVED[i]);
|
|
75
|
+
}
|
|
76
|
+
root.classList.add(resolvedTheme);
|
|
77
|
+
root.dataset.appliedTheme = resolvedTheme;
|
|
78
|
+
root.dataset.theme = preference;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 4) Defer persistence/migration to keep the hot path read-only
|
|
82
|
+
const hadValidCookie = isTheme(cookieTheme);
|
|
83
|
+
(window.requestIdleCallback || setTimeout)(function() {
|
|
84
|
+
try{
|
|
85
|
+
// Migrate from localStorage to cookies if needed
|
|
86
|
+
if (isTheme(lsTheme)) {
|
|
87
|
+
writeCookie(KEY, lsTheme);
|
|
88
|
+
try {
|
|
89
|
+
window.localStorage.removeItem(KEY);
|
|
90
|
+
} catch(_) {}
|
|
91
|
+
} else if (!hadValidCookie) {
|
|
92
|
+
// Set default cookie if none existed
|
|
93
|
+
writeCookie(KEY, preference);
|
|
94
|
+
}
|
|
95
|
+
} catch (_) {}
|
|
96
|
+
}, 0);
|
|
97
|
+
})();
|
|
98
|
+
`.trim()}var U=({defaultTheme:e="system",includeNunitoSans:t=!1,nonce:o,storageKey:s=f})=>A(K,{children:[k("script",{dangerouslySetInnerHTML:{__html:B({defaultTheme:e,storageKey:s})},nonce:o}),k(g,{includeNunitoSans:t})]});U.displayName="MantleThemeHeadContent";function ie(e){let{className:t="",defaultTheme:o="system",storageKey:s=f}=e??{};return I(()=>{if(!d())return{className:M(t),"data-applied-theme":"system","data-theme":"system"};let r=window.matchMedia(c).matches,i=window.matchMedia(l).matches,n=p(s,o),m=w(n,{prefersDarkMode:r,prefersHighContrast:i});return{className:M(t,m),"data-applied-theme":m,"data-theme":n}},[t,o,s])}export{g as a,y as b,b as c,te as d,R as e,oe as f,q as g,V as h,ne as i,u as j,se as k,re as l,B as m,U as n,ie as o};
|
|
99
|
+
//# sourceMappingURL=chunk-N6ZW2CVT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/theme/preload-fonts.tsx","../src/components/theme/theme-provider.tsx"],"sourcesContent":["const cdnOrigin = \"https://assets.ngrok.com\";\nconst cdnBase = `${cdnOrigin}/fonts`;\n\nconst fonts = [\n\t\"/euclid-square/EuclidSquare-Regular-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-RegularItalic-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-Medium-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-Semibold-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-MediumItalic-WebS.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-Text.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-TextItalic.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-SemiBold.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff\",\n] as const;\n\ntype Font = (typeof fonts)[number];\n\nconst fontHref = <T extends Font = Font>(font: T) =>\n\t`${cdnBase}${font}` as const;\n\ntype Props = {\n\t/**\n\t * If set, will also preload and include the optional Nunito Sans font from Google Fonts.\n\t * @default false\n\t */\n\tincludeNunitoSans?: boolean;\n};\n\n/**\n * Preload custom fonts used in the theme.\n *\n * @see https://mantle.ngrok.com/components/theme-provider#api-preload-fonts\n *\n * @example\n * ```tsx\n * <PreloadFonts includeNunitoSans />\n * ```\n */\nconst PreloadFonts = ({ includeNunitoSans = false }: Props) => (\n\t<>\n\t\t<link rel=\"preconnect\" href={cdnOrigin} />\n\t\t{fonts.map((font) => (\n\t\t\t<link\n\t\t\t\tkey={font}\n\t\t\t\trel=\"preload\"\n\t\t\t\thref={fontHref(font)}\n\t\t\t\tas=\"font\"\n\t\t\t\ttype=\"font/woff\"\n\t\t\t\tcrossOrigin=\"anonymous\"\n\t\t\t/>\n\t\t))}\n\t\t{includeNunitoSans && <NunitoSans />}\n\t</>\n);\nPreloadFonts.displayName = \"PreloadFonts\";\n\nexport {\n\t//,\n\tPreloadFonts,\n};\n\nfunction NunitoSans() {\n\treturn (\n\t\t<>\n\t\t\t<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n\t\t\t<link\n\t\t\t\trel=\"preconnect\"\n\t\t\t\thref=\"https://fonts.gstatic.com\"\n\t\t\t\tcrossOrigin=\"anonymous\"\n\t\t\t/>\n\t\t\t<link\n\t\t\t\thref=\"https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000&display=swap\"\n\t\t\t\trel=\"stylesheet\"\n\t\t\t/>\n\t\t</>\n\t);\n}\n","\"use client\";\n\nimport clsx from \"clsx\";\nimport type { ComponentProps, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport invariant from \"tiny-invariant\";\nimport { useMatchesMediaQuery } from \"../../hooks/use-matches-media-query.js\";\nimport { PreloadFonts } from \"./preload-fonts.js\";\n\n/**\n * prefersDarkModeMediaQuery is the media query used to detect if the user prefers dark mode.\n */\nconst prefersDarkModeMediaQuery = \"(prefers-color-scheme: dark)\";\n\n/**\n * prefersHighContrastMediaQuery is the media query used to detect if the user prefers high contrast mode.\n */\nconst prefersHighContrastMediaQuery = \"(prefers-contrast: more)\";\n\n/**\n * resolvedThemes is a tuple of valid themes that have been resolved from \"system\" to a specific theme.\n */\nconst resolvedThemes = [\n\t\"light\",\n\t\"dark\",\n\t\"light-high-contrast\",\n\t\"dark-high-contrast\",\n] as const;\n\n/**\n * ResolvedTheme is a type that represents a theme that has been resolved from \"system\" to a specific theme.\n */\ntype ResolvedTheme = (typeof resolvedThemes)[number];\n\n/**\n * themes is a tuple of valid themes.\n */\nconst themes = [\"system\", ...resolvedThemes] as const;\n\n/**\n * Theme is a string literal type that represents a valid theme.\n */\ntype Theme = (typeof themes)[number];\n\n/**\n * $theme is a helper which translates the Theme type into a string literal type.\n */\nconst $theme = <T extends Theme = Theme>(value: T) => value;\n\n/**\n * Type predicate that checks if a value is a valid theme.\n */\nfunction isTheme(value: unknown): value is Theme {\n\tif (typeof value !== \"string\") {\n\t\treturn false;\n\t}\n\n\treturn themes.includes(value as Theme);\n}\n\n/**\n * $resolvedTheme is a helper which translates the ResolvedTheme type into a string literal type.\n */\nconst $resolvedTheme = <T extends ResolvedTheme = ResolvedTheme>(value: T) =>\n\tvalue;\n\n/**\n * Type predicate that checks if a value is a valid resolved theme.\n */\nfunction isResolvedTheme(value: unknown): value is ResolvedTheme {\n\tif (typeof value !== \"string\") {\n\t\treturn false;\n\t}\n\n\treturn resolvedThemes.includes(value as ResolvedTheme);\n}\n\n/**\n * DEFAULT_STORAGE_KEY is the default key used to store the theme in cookies.\n */\nconst DEFAULT_STORAGE_KEY = \"mantle-ui-theme\";\n\n/**\n * ThemeProviderState is the shape of the state returned by the ThemeProviderContext.\n */\ntype ThemeProviderState = [theme: Theme, setTheme: (theme: Theme) => void];\n\n/**\n * Initial state for the ThemeProviderContext.\n */\nconst initialState: ThemeProviderState = [\"system\", () => null];\n\n/**\n * ThemeProviderContext is a React Context that provides the current theme and a function to set the theme.\n */\nconst ThemeProviderContext = createContext<ThemeProviderState | null>(\n\tinitialState,\n);\n\n/**\n * isBrowser returns true if the code is running in a browser environment.\n */\nconst isBrowser = () => typeof window !== \"undefined\";\n\n/**\n * Sets a cookie with appropriate domain for the current hostname.\n * Uses .ngrok.com for ngrok domains, otherwise no domain (current domain only).\n */\nfunction setCookie(name: string, value: string) {\n\tif (!isBrowser()) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst expires = new Date();\n\t\texpires.setFullYear(expires.getFullYear() + 1); // 1 year expiration\n\n\t\t// Only set .ngrok.com domain for ngrok domains, otherwise let it default to current domain\n\t\tconst { hostname, protocol } = window.location;\n\t\tconst domainAttribute =\n\t\t\thostname === \"ngrok.com\" || hostname.endsWith(\".ngrok.com\")\n\t\t\t\t? \"; domain=.ngrok.com\"\n\t\t\t\t: \"\";\n\t\tconst secureAttribute = protocol === \"https:\" ? \"; Secure\" : \"\";\n\n\t\tdocument.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/${domainAttribute}; SameSite=Lax${secureAttribute}`;\n\t} catch (_) {\n\t\t// silently swallow errors\n\t}\n}\n\n/**\n * Gets the stored theme from cookies or returns the default theme if no theme is stored.\n */\nfunction getStoredTheme(storageKey: string, defaultTheme: Theme = \"system\") {\n\tconst fallbackTheme = defaultTheme ?? \"system\";\n\tif (isBrowser()) {\n\t\tlet storedTheme: string | null = null;\n\t\ttry {\n\t\t\tconst cookies = document.cookie.split(\";\");\n\t\t\tconst themeCookie = cookies.find((cookie) =>\n\t\t\t\tcookie.trim().startsWith(`${storageKey}=`),\n\t\t\t);\n\t\t\tif (themeCookie) {\n\t\t\t\tconst cookieValue = themeCookie.trim().substring(storageKey.length + 1);\n\t\t\t\tstoredTheme = cookieValue ? decodeURIComponent(cookieValue) : null;\n\t\t\t}\n\t\t} catch (_) {}\n\t\treturn isTheme(storedTheme) ? storedTheme : fallbackTheme;\n\t}\n\treturn fallbackTheme;\n}\n\n/**\n * Props for the {@link ThemeProvider} component.\n */\ntype ThemeProviderProps = PropsWithChildren & {\n\t/**\n\t * The initial theme to apply if no value is found in storage.\n\t *\n\t * Possible values {@link themes}:\n\t * - `\"system\"` – follow the user’s system preferences (default).\n\t * - `\"light\"` – force light mode.\n\t * - `\"dark\"` – force dark mode.\n\t * - `\"light-high-contrast\"` – light mode with increased contrast.\n\t * - `\"dark-high-contrast\"` – dark mode with increased contrast.\n\t */\n\tdefaultTheme?: Theme;\n\n\t/**\n\t * The key used to persist the selected theme in cookies or storage.\n\t *\n\t * Defaults to `\"theme\"` (or the {@link DEFAULT_STORAGE_KEY} constant).\n\t * Useful if you need to isolate theme settings across multiple apps\n\t * or contexts.\n\t */\n\tstorageKey?: string;\n};\n\n/**\n * ThemeProvider is a React Context Provider that provides the current theme and a function to set the theme.\n *\n * @see https://mantle.ngrok.com/components/theme-provider#api-theme-provider\n *\n * @example\n * ```tsx\n * <ThemeProvider defaultTheme=\"system\" storageKey=\"app-theme\">\n * <App />\n * </ThemeProvider>\n * ```\n */\nfunction ThemeProvider({\n\tchildren,\n\tdefaultTheme = \"system\",\n\tstorageKey = DEFAULT_STORAGE_KEY,\n}: ThemeProviderProps) {\n\tconst [theme, setTheme] = useState<Theme>(() => {\n\t\tconst initialTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tapplyTheme(initialTheme);\n\t\treturn initialTheme;\n\t});\n\n\tuseEffect(() => {\n\t\tconst storedTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tsetTheme(storedTheme);\n\t\tapplyTheme(storedTheme);\n\t}, [defaultTheme, storageKey]);\n\n\tuseEffect(() => {\n\t\tconst prefersDarkMql = window.matchMedia(prefersDarkModeMediaQuery);\n\t\tconst prefersHighContrastMql = window.matchMedia(\n\t\t\tprefersHighContrastMediaQuery,\n\t\t);\n\n\t\tconst onChange = () => {\n\t\t\tconst storedTheme = getStoredTheme(storageKey, defaultTheme);\n\n\t\t\t// If the stored theme is not \"system\", then the user has explicitly set a theme and we should not\n\t\t\t// automatically change the theme when the user's system preferences change.\n\t\t\tif (storedTheme !== \"system\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tapplyTheme(\"system\");\n\t\t};\n\n\t\tprefersDarkMql.addEventListener(\"change\", onChange);\n\t\tprefersHighContrastMql.addEventListener(\"change\", onChange);\n\n\t\treturn () => {\n\t\t\tprefersDarkMql.removeEventListener(\"change\", onChange);\n\t\t\tprefersHighContrastMql.removeEventListener(\"change\", onChange);\n\t\t};\n\t}, [defaultTheme, storageKey]);\n\n\tconst value: ThemeProviderState = useMemo(\n\t\t() => [\n\t\t\ttheme,\n\t\t\t(theme: Theme) => {\n\t\t\t\tsetCookie(storageKey, theme);\n\t\t\t\tsetTheme(theme);\n\t\t\t\tapplyTheme(theme);\n\t\t\t},\n\t\t],\n\t\t[storageKey, theme],\n\t);\n\n\treturn (\n\t\t<ThemeProviderContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ThemeProviderContext.Provider>\n\t);\n}\nThemeProvider.displayName = \"ThemeProvider\";\n\n/**\n * useTheme returns the current theme and a function to set the theme.\n *\n * @note This function will throw an error if used outside of a ThemeProvider context tree.\n */\nfunction useTheme() {\n\tconst context = useContext(ThemeProviderContext);\n\n\tinvariant(context, \"useTheme must be used within a ThemeProvider\");\n\n\treturn context;\n}\n\n/**\n * Applies the given theme to the `<html>` element.\n */\nfunction applyTheme(theme: Theme) {\n\tif (!isBrowser()) {\n\t\treturn;\n\t}\n\n\tconst htmlElement = window.document.documentElement;\n\thtmlElement.classList.remove(...themes);\n\tconst prefersDarkMode = window.matchMedia(prefersDarkModeMediaQuery).matches;\n\tconst prefersHighContrast = window.matchMedia(\n\t\tprefersHighContrastMediaQuery,\n\t).matches;\n\tconst newTheme = resolveTheme(theme, {\n\t\tprefersDarkMode,\n\t\tprefersHighContrast,\n\t});\n\thtmlElement.classList.add(newTheme);\n\thtmlElement.dataset.appliedTheme = newTheme;\n\thtmlElement.dataset.theme = theme;\n}\n\n/**\n * Read the theme and applied theme from the `<html>` element.\n */\nfunction readThemeFromHtmlElement() {\n\tif (!isBrowser()) {\n\t\treturn {\n\t\t\tappliedTheme: undefined,\n\t\t\ttheme: undefined,\n\t\t};\n\t}\n\n\tconst htmlElement = window.document.documentElement;\n\tconst theme = isTheme(htmlElement.dataset.theme)\n\t\t? htmlElement.dataset.theme\n\t\t: undefined;\n\tconst appliedTheme = isResolvedTheme(htmlElement.dataset.appliedTheme)\n\t\t? htmlElement.dataset.appliedTheme\n\t\t: undefined;\n\n\treturn {\n\t\tappliedTheme,\n\t\ttheme,\n\t};\n}\n\n/**\n * If the theme is \"system\", it will resolve the theme based on the user's media query preferences, otherwise it will return the theme as is.\n * This will mirror the result that gets applied to the <html> element.\n */\nfunction resolveTheme(\n\ttheme: Theme,\n\t{\n\t\tprefersDarkMode,\n\t\tprefersHighContrast,\n\t}: { prefersDarkMode: boolean; prefersHighContrast: boolean },\n) {\n\tif (theme === \"system\") {\n\t\treturn determineThemeFromMediaQuery({\n\t\t\tprefersDarkMode,\n\t\t\tprefersHighContrast,\n\t\t});\n\t}\n\n\treturn theme;\n}\n\n/**\n * If the theme is \"system\", it will resolve the theme based on the user's media query preferences, otherwise it will return the theme as is.\n * This will mirror the result that gets applied to the <html> element.\n */\nfunction useAppliedTheme() {\n\tconst themeContext = useContext(ThemeProviderContext);\n\tconst theme = themeContext != null ? themeContext[0] : \"system\";\n\n\tconst prefersDarkMode = useMatchesMediaQuery(prefersDarkModeMediaQuery);\n\tconst prefersHighContrast = useMatchesMediaQuery(\n\t\tprefersHighContrastMediaQuery,\n\t);\n\n\treturn resolveTheme(theme, { prefersDarkMode, prefersHighContrast });\n}\n\n/**\n * determineThemeFromMediaQuery returns the theme that should be used based on the user's media query preferences.\n * @private\n *\n * @example\n * ```tsx\n * const theme = determineThemeFromMediaQuery({\n * prefersDarkMode: true,\n * prefersHighContrast: false\n * });\n * // Returns: \"dark\"\n *\n * const themeWithContrast = determineThemeFromMediaQuery({\n * prefersDarkMode: false,\n * prefersHighContrast: true\n * });\n * // Returns: \"light-high-contrast\"\n * ```\n */\nexport function determineThemeFromMediaQuery({\n\tprefersDarkMode,\n\tprefersHighContrast,\n}: {\n\tprefersDarkMode: boolean;\n\tprefersHighContrast: boolean;\n}): ResolvedTheme {\n\tif (prefersHighContrast) {\n\t\treturn prefersDarkMode ? \"dark-high-contrast\" : \"light-high-contrast\";\n\t}\n\n\treturn prefersDarkMode ? \"dark\" : \"light\";\n}\n\ntype PreventWrongThemeFlashScriptContentOptions = {\n\tdefaultTheme?: Theme;\n\tstorageKey?: string;\n};\n\n/**\n * preventWrongThemeFlashScriptContent generates a script that prevents the wrong theme from flashing on initial page load.\n * It checks cookies for a stored theme, and if none is found, it sets the default theme.\n * It also applies the correct theme to the `<html>` element based on the user's media query preferences.\n */\nfunction preventWrongThemeFlashScriptContent(\n\toptions?: PreventWrongThemeFlashScriptContentOptions,\n) {\n\tconst { defaultTheme = \"system\", storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions ?? {};\n\n\t// Only resolved themes are ever applied as classes\n\tconst resolved = resolvedThemes;\n\n\treturn `\n(function() {\n\tconst RESOLVED = ${JSON.stringify(resolved)};\n\tconst DEF = \"${defaultTheme}\";\n\tconst KEY = \"${storageKey}\";\n\tconst doc = document, root = doc.documentElement;\n\n\tfunction isTheme(v) {\n\t\treturn typeof v === \"string\" && (v === \"system\" || RESOLVED.indexOf(v) > -1);\n\t}\n\n\tfunction readCookie(name){\n\t\t// Efficient single-pass cookie lookup: \"; name=value\"\n\t\tconst all = \"; \" + doc.cookie, token = \"; \" + name + \"=\";\n\t\tconst startIdx = all.indexOf(token);\n\t\tif (startIdx < 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst endIdx = all.indexOf(\";\", startIdx + token.length);\n\t\tconst rawValue = all.slice(startIdx + token.length, endIdx < 0 ? void 0 : endIdx) || null;\n\t\ttry { \n\t\t\treturn rawValue ? decodeURIComponent(rawValue) : null;\n\t\t} catch(_) { \n\t\t\treturn rawValue;\n\t\t}\n\t}\n\n\tfunction writeCookie(name, val) {\n\t\ttry {\n\t\t\tconst expires = new Date(); \n\t\t\texpires.setFullYear(expires.getFullYear() + 1);\n\t\t\tconst hostname = location.hostname;\n\t\t\tconst protocol = location.protocol;\n\t\t\tconst isDotNgrok = (hostname === \"ngrok.com\" || hostname.endsWith(\".ngrok.com\"));\n\t\t\tconst domain = isDotNgrok ? \"; domain=.ngrok.com\" : \"\";\n\t\t\tconst secure = protocol === \"https:\" ? \"; Secure\" : \"\";\n\t\t\tdoc.cookie = name + \"=\" + encodeURIComponent(val) + \"; expires=\" + expires.toUTCString() + \"; path=/\" + domain + \"; SameSite=Lax\" + secure;\n\t\t} catch(_) {}\n\t}\n\n\t// 1) Read preference: cookie first, fallback to localStorage (migration support)\n\tlet cookieTheme = null, lsTheme = null, storedTheme = null;\n\ttry { \n\t\tcookieTheme = readCookie(KEY);\n\t} catch(_) {}\n\t\n\tif (isTheme(cookieTheme)) { \n\t\tstoredTheme = cookieTheme;\n\t} else {\n\t\ttry { \n\t\t\tlsTheme = window.localStorage && window.localStorage.getItem(KEY);\n\t\t} catch(_) {}\n\t\tif (isTheme(lsTheme)) {\n\t\t\tstoredTheme = lsTheme;\n\t\t}\n\t}\n\n\tconst preference = isTheme(storedTheme) ? storedTheme : DEF;\n\n\t// 2) Resolve only when needed to avoid unnecessary media queries\n\tlet resolvedTheme = preference;\n\tif (preference === \"system\") {\n\t\tconst isDark = matchMedia(\"${prefersDarkModeMediaQuery}\").matches;\n\t\tconst isHighContrast = matchMedia(\"${prefersHighContrastMediaQuery}\").matches;\n\t\tresolvedTheme = isHighContrast \n\t\t\t? (isDark ? \"dark-high-contrast\" : \"light-high-contrast\")\n\t\t\t: (isDark ? \"dark\" : \"light\");\n\t}\n\n\t// 3) Only touch DOM if we actually need to change something (SSR optimization)\n\tif (root.dataset.appliedTheme !== resolvedTheme || root.dataset.theme !== preference) {\n\t\t// Remove all theme classes, add the correct one\n\t\tfor (let i = 0; i < RESOLVED.length; i++) {\n\t\t\troot.classList.remove(RESOLVED[i]);\n\t\t}\n\t\troot.classList.add(resolvedTheme);\n\t\troot.dataset.appliedTheme = resolvedTheme;\n\t\troot.dataset.theme = preference;\n\t}\n\n\t// 4) Defer persistence/migration to keep the hot path read-only\n\tconst hadValidCookie = isTheme(cookieTheme);\n\t(window.requestIdleCallback || setTimeout)(function() {\n\t\ttry{\n\t\t\t// Migrate from localStorage to cookies if needed\n\t\t\tif (isTheme(lsTheme)) {\n\t\t\t\twriteCookie(KEY, lsTheme);\n\t\t\t\ttry { \n\t\t\t\t\twindow.localStorage.removeItem(KEY);\n\t\t\t\t} catch(_) {}\n\t\t\t} else if (!hadValidCookie) {\n\t\t\t\t// Set default cookie if none existed\n\t\t\t\twriteCookie(KEY, preference);\n\t\t\t}\n\t\t} catch (_) {}\n\t}, 0);\n})();\n`.trim();\n}\n\ntype MantleThemeHeadContentProps = {\n\t/**\n\t * The default theme to use if no theme is stored in cookies.\n\t * @default \"system\"\n\t */\n\tdefaultTheme?: Theme;\n\t/**\n\t * An optional CSP nonce to allowlist this inline script. Using this can help\n\t * you to avoid using the CSP `unsafe-inline` directive, which disables\n\t * XSS protection and would allowlist all inline scripts or styles.\n\t *\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce\n\t */\n\tnonce?: string;\n\t/**\n\t * The key used to store the theme in cookies.\n\t * @default \"mantle-ui-theme\"\n\t */\n\tstorageKey?: string;\n} & ComponentProps<typeof PreloadFonts>;\n\n/**\n * MantleThemeHeadContent is a React component that renders a script to prevent\n * Flash of Unstyled Content (FOUC), or the wrong theme from flashing on initial\n * page load.\n *\n * Render as high as possible in the <head> element.\n */\nconst MantleThemeHeadContent = ({\n\tdefaultTheme = \"system\",\n\tincludeNunitoSans = false,\n\tnonce,\n\tstorageKey = DEFAULT_STORAGE_KEY,\n}: MantleThemeHeadContentProps) => (\n\t<>\n\t\t<script\n\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t__html: preventWrongThemeFlashScriptContent({\n\t\t\t\t\tdefaultTheme,\n\t\t\t\t\tstorageKey,\n\t\t\t\t}),\n\t\t\t}}\n\t\t\tnonce={nonce}\n\t\t/>\n\t\t<PreloadFonts includeNunitoSans={includeNunitoSans} />\n\t</>\n);\nMantleThemeHeadContent.displayName = \"MantleThemeHeadContent\";\n\ntype InitialThemeProps = {\n\tclassName: string;\n\t\"data-applied-theme\": Omit<Theme, \"system\">;\n\t\"data-theme\": Theme;\n};\n\n/**\n * useInitialHtmlThemeProps returns the initial props that should be applied to the <html> element to prevent react hydration errors.\n */\nfunction useInitialHtmlThemeProps(props?: {\n\tclassName?: string;\n\tdefaultTheme?: Theme;\n\tstorageKey?: string;\n}): InitialThemeProps {\n\tconst {\n\t\tclassName = \"\",\n\t\tdefaultTheme = \"system\",\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = props ?? {};\n\n\treturn useMemo(() => {\n\t\tif (!isBrowser()) {\n\t\t\treturn {\n\t\t\t\tclassName: clsx(className),\n\t\t\t\t\"data-applied-theme\": \"system\",\n\t\t\t\t\"data-theme\": \"system\",\n\t\t\t};\n\t\t}\n\n\t\tconst prefersDarkMode = window.matchMedia(\n\t\t\tprefersDarkModeMediaQuery,\n\t\t).matches;\n\t\tconst prefersHighContrast = window.matchMedia(\n\t\t\tprefersHighContrastMediaQuery,\n\t\t).matches;\n\t\tconst initialTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tconst resolvedTheme = resolveTheme(initialTheme, {\n\t\t\tprefersDarkMode,\n\t\t\tprefersHighContrast,\n\t\t});\n\n\t\treturn {\n\t\t\tclassName: clsx(className, resolvedTheme),\n\t\t\t\"data-applied-theme\": resolvedTheme,\n\t\t\t\"data-theme\": initialTheme,\n\t\t};\n\t}, [className, defaultTheme, storageKey]);\n}\n\nexport {\n\t//,\n\t$resolvedTheme,\n\t$theme,\n\tapplyTheme,\n\tisResolvedTheme,\n\tisTheme,\n\tMantleThemeHeadContent,\n\tpreventWrongThemeFlashScriptContent,\n\treadThemeFromHtmlElement,\n\tresolvedThemes,\n\tThemeProvider,\n\tthemes,\n\tuseAppliedTheme,\n\tuseInitialHtmlThemeProps,\n\tuseTheme,\n};\n\nexport type {\n\t//,\n\tResolvedTheme,\n\tTheme,\n\tThemeProviderProps,\n};\n"],"mappings":"wCAuCC,mBAAAA,EACC,OAAAC,EADD,QAAAC,MAAA,oBAvCD,IAAMC,EAAY,2BACZC,EAAU,GAAGD,CAAS,SAEtBE,EAAQ,CACb,gDACA,sDACA,+CACA,iDACA,qDACA,uCACA,6CACA,2CACA,gDACD,EAIMC,EAAmCC,GACxC,GAAGH,CAAO,GAAGG,CAAI,GAoBZC,EAAe,CAAC,CAAE,kBAAAC,EAAoB,EAAM,IACjDP,EAAAF,EAAA,CACC,UAAAC,EAAC,QAAK,IAAI,aAAa,KAAME,EAAW,EACvCE,EAAM,IAAKE,GACXN,EAAC,QAEA,IAAI,UACJ,KAAMK,EAASC,CAAI,EACnB,GAAG,OACH,KAAK,YACL,YAAY,aALPA,CAMN,CACA,EACAE,GAAqBR,EAACS,EAAA,EAAW,GACnC,EAEDF,EAAa,YAAc,eAO3B,SAASG,GAAa,CACrB,OACCC,EAAAC,EAAA,CACC,UAAAC,EAAC,QAAK,IAAI,aAAa,KAAK,+BAA+B,EAC3DA,EAAC,QACA,IAAI,aACJ,KAAK,4BACL,YAAY,YACb,EACAA,EAAC,QACA,KAAK,uHACL,IAAI,aACL,GACD,CAEF,CC1EA,OAAOC,MAAU,OAEjB,OAAS,iBAAAC,EAAe,cAA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BAWrC,SAASI,GAAyBC,EAIZ,CACrB,GAAM,CACL,UAAAC,EAAY,GACZ,aAAAxC,EAAe,SACf,WAAAD,EAAab,CACd,EAAIqD,GAAS,CAAC,EAEd,OAAOtB,EAAQ,IAAM,CACpB,GAAI,CAAC3B,EAAU,EACd,MAAO,CACN,UAAWmD,EAAKD,CAAS,EACzB,qBAAsB,SACtB,aAAc,QACf,EAGD,IAAMjB,EAAkB,OAAO,WAC9B9C,CACD,EAAE,QACI+C,EAAsB,OAAO,WAClC9C,CACD,EAAE,QACIiC,EAAeb,EAAeC,EAAYC,CAAY,EACtD0C,EAAgBhB,EAAaf,EAAc,CAChD,gBAAAY,EACA,oBAAAC,CACD,CAAC,EAED,MAAO,CACN,UAAWiB,EAAKD,EAAWE,CAAa,EACxC,qBAAsBA,EACtB,aAAc/B,CACf,CACD,EAAG,CAAC6B,EAAWxC,EAAcD,CAAU,CAAC,CACzC","names":["Fragment","jsx","jsxs","cdnOrigin","cdnBase","fonts","fontHref","font","PreloadFonts","includeNunitoSans","NunitoSans","NunitoSans","jsxs","Fragment","jsx","clsx","createContext","useContext","useEffect","useMemo","useState","invariant","Fragment","jsx","jsxs","prefersDarkModeMediaQuery","prefersHighContrastMediaQuery","resolvedThemes","themes","$theme","value","isTheme","$resolvedTheme","isResolvedTheme","DEFAULT_STORAGE_KEY","initialState","ThemeProviderContext","createContext","isBrowser","setCookie","name","expires","hostname","protocol","domainAttribute","secureAttribute","getStoredTheme","storageKey","defaultTheme","fallbackTheme","storedTheme","themeCookie","cookie","cookieValue","ThemeProvider","children","theme","setTheme","useState","initialTheme","applyTheme","useEffect","prefersDarkMql","prefersHighContrastMql","onChange","useMemo","useTheme","context","useContext","invariant","htmlElement","prefersDarkMode","prefersHighContrast","newTheme","resolveTheme","readThemeFromHtmlElement","determineThemeFromMediaQuery","useAppliedTheme","themeContext","useMatchesMediaQuery","preventWrongThemeFlashScriptContent","options","MantleThemeHeadContent","includeNunitoSans","nonce","PreloadFonts","useInitialHtmlThemeProps","props","className","clsx","resolvedTheme"]}
|
package/dist/dialog.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as f,b as D,c as P,d as m,e as v,f as y,g as u,h as C,i as k}from"./chunk-VIKPHWPP.js";import{d as p}from"./chunk-
|
|
1
|
+
import{a as f,b as D,c as P,d as m,e as v,f as y,g as u,h as C,i as k}from"./chunk-VIKPHWPP.js";import{d as p}from"./chunk-BK5H6ZXB.js";import"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";import{c}from"./chunk-XTCU7MXB.js";import"./chunk-4LSFAAZW.js";import"./chunk-72TJUKMV.js";import"./chunk-3C5O3AQA.js";import"./chunk-I6T6YV2L.js";import"./chunk-NPTDRQT5.js";import{a}from"./chunk-AZ56JGNY.js";import{XIcon as F}from"@phosphor-icons/react/X";import{forwardRef as n}from"react";import{jsx as e,jsxs as j}from"react/jsx-runtime";var x=f;x.displayName="Dialog";var N=D;N.displayName="DialogTrigger";var d=P;d.displayName="DialogPortal";var b=m;b.displayName="DialogClose";var g=n(({className:o,...t},i)=>e(v,{ref:i,className:a("bg-overlay data-state-closed:animate-out data-state-closed:fade-out-0 data-state-open:animate-in data-state-open:fade-in-0 fixed inset-0 z-50 backdrop-blur-xs",o),...t}));g.displayName="DialogOverlay";var h=n(({children:o,className:t,onInteractOutside:i,onPointerDownOutside:l,preferredWidth:s="max-w-lg",...W},z)=>j(d,{children:[e(g,{}),e("div",{className:"fixed inset-4 z-50 flex items-center justify-center",children:e(y,{className:a("flex max-h-full w-full flex-1 flex-col","outline-hidden focus-within:outline-hidden","border-dialog bg-dialog rounded-xl border shadow-lg transition-transform 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",s,t),onInteractOutside:r=>{p(r),i?.(r)},onPointerDownOutside:r=>{p(r),l?.(r)},ref:z,...W,children:o})})]}));h.displayName="DialogContent";var R=({className:o,children:t,...i})=>e("div",{className:a("border-dialog-muted text-strong relative flex shrink-0 items-center justify-between gap-2 border-b px-6 py-4","has-[.icon-button]:pr-4",o),...i,children:t});R.displayName="DialogHeader";var w=({size:o="md",type:t="button",label:i="Close Dialog",appearance:l="ghost",...s})=>e(m,{asChild:!0,children:e(c,{appearance:l,icon:e(F,{}),label:i,size:o,type:t,...s})});w.displayName="DialogCloseIconButton";var I=({className:o,...t})=>e("div",{className:a("scrollbar text-body flex-1 overflow-y-auto p-6",o),...t});I.displayName="DialogBody";var B=({className:o,...t})=>e("div",{className:a("border-dialog-muted flex shrink-0 flex-row-reverse gap-2 border-t px-6 py-4",o),...t});B.displayName="DialogFooter";var O=n(({className:o,...t},i)=>e(u,{ref:i,className:a("text-strong truncate text-lg font-medium",o),...t}));O.displayName="DialogTitle";var T=n(({className:o,...t},i)=>e(C,{ref:i,className:a("text-muted",o),...t}));T.displayName="DialogDescription";var H={Root:x,Body:I,Close:b,CloseIconButton:w,Content:h,Description:T,Footer:B,Header:R,Overlay:g,Portal:d,Title:O,Trigger:N};export{H as Dialog,k as isDialogOverlayTarget};
|
|
2
2
|
//# sourceMappingURL=dialog.js.map
|
package/dist/icons.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as h}from"./chunk-W2YQRWR5.js";import{a as s}from"./chunk-2PHWBRBD.js";import"./chunk-GYPSB3OK.js";import{l as m}from"./chunk-
|
|
1
|
+
import{a as h}from"./chunk-W2YQRWR5.js";import{a as s}from"./chunk-2PHWBRBD.js";import"./chunk-GYPSB3OK.js";import{l as m}from"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";import{DesktopIcon as u}from"@phosphor-icons/react/Desktop";import{MoonIcon as n}from"@phosphor-icons/react/Moon";import{SunIcon as c}from"@phosphor-icons/react/Sun";import{jsx as t}from"react/jsx-runtime";function i(o){let e=m();return t(r,{theme:e,...o})}i.displayName="AutoThemeIcon";function r({theme:o,...e}){switch(o){case"system":return t(u,{...e});case"light":return t(c,{...e});case"dark":return t(n,{...e});case"light-high-contrast":return t(c,{...e,weight:"fill"});case"dark-high-contrast":return t(n,{...e,weight:"fill"})}}r.displayName="ThemeIcon";export{i as AutoThemeIcon,s as SortIcon,r as ThemeIcon,h as TrafficPolicyFileIcon};
|
|
2
2
|
//# sourceMappingURL=icons.js.map
|
package/dist/sheet.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u,b as v,c as S,d as m,e as p,f as d,g as h,h as f}from"./chunk-VIKPHWPP.js";import{d as c}from"./chunk-
|
|
1
|
+
import{a as u,b as v,c as S,d as m,e as p,f as d,g as h,h as f}from"./chunk-VIKPHWPP.js";import{d as c}from"./chunk-BK5H6ZXB.js";import"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";import{c as y}from"./chunk-XTCU7MXB.js";import"./chunk-4LSFAAZW.js";import"./chunk-72TJUKMV.js";import"./chunk-3C5O3AQA.js";import"./chunk-I6T6YV2L.js";import"./chunk-NPTDRQT5.js";import{a}from"./chunk-AZ56JGNY.js";import{XIcon as W}from"@phosphor-icons/react/X";import{cva as E}from"class-variance-authority";import{forwardRef as s}from"react";import{jsx as o,jsxs as z}from"react/jsx-runtime";var P=u;P.displayName="Sheet";var C=v;C.displayName="SheetTrigger";var g=m;g.displayName="SheetClose";var N=S;N.displayName="SheetPortal";var b=s(({className:e,...t},i)=>o(p,{className:a("bg-overlay data-state-closed:animate-out data-state-closed:fade-out-0 data-state-open:animate-in data-state-open:fade-in-0 fixed inset-0 z-40 backdrop-blur-xs",e),...t,ref:i}));b.displayName=p.displayName;var V=E("bg-dialog border-dialog inset-y-0 h-full w-full fixed z-40 flex flex-col shadow-lg outline-hidden transition ease-in-out focus-within:outline-hidden data-state-closed:duration-100 data-state-closed:animate-out data-state-open:duration-100 data-state-open:animate-in",{variants:{side:{left:"data-state-closed:slide-out-to-left data-state-open:slide-in-from-left left-0 border-r",right:"data-state-closed:slide-out-to-right data-state-open:slide-in-from-right right-0 border-l"}},defaultVariants:{side:"right"}}),x=s(({children:e,className:t,onInteractOutside:i,onPointerDownOutside:r,preferredWidth:l="sm:max-w-[30rem]",side:B="right",...O},A)=>z(N,{children:[o(b,{}),o(d,{className:a(V({side:B}),l,t),onInteractOutside:n=>{c(n),i?.(n)},onPointerDownOutside:n=>{c(n),r?.(n)},ref:A,...O,children:e})]}));x.displayName=d.displayName;var T=({size:e="md",type:t="button",label:i="Close Sheet",appearance:r="ghost",...l})=>o(m,{asChild:!0,children:o(y,{appearance:r,icon:o(W,{}),label:i,size:e,type:t,...l})});T.displayName="SheetCloseIconButton";var R=({className:e,...t})=>o("div",{className:a("scrollbar text-body flex-1 overflow-y-auto p-6",e),...t});R.displayName="SheetBody";var H=({className:e,...t})=>o("div",{className:a("border-dialog-muted flex shrink-0 flex-col gap-2 border-b py-4 pl-6 pr-4","has-[.icon-button]:pr-4",e),...t});H.displayName="SheetHeader";var D=({className:e,...t})=>o("div",{className:a("border-dialog-muted flex shrink-0 justify-end gap-2 border-t px-6 py-2.5",e),...t});D.displayName="SheetFooter";var L=s(({className:e,...t},i)=>o(h,{ref:i,className:a("text-strong flex-1 truncate text-lg font-medium",e),...t}));L.displayName=h.displayName;var M=s(({children:e,className:t,...i},r)=>o("div",{className:a("flex items-center justify-between gap-2",t),...i,ref:r,children:e}));M.displayName="SheetTitleGroup";var I=s(({className:e,...t},i)=>o(f,{ref:i,className:a("text-body text-sm",e),...t}));I.displayName=f.displayName;var w=s(({children:e,className:t,...i},r)=>o("div",{className:a("flex h-full items-center gap-2",t),...i,ref:r,children:e}));w.displayName="SheetActions";var k={Root:P,Actions:w,Body:R,Close:g,CloseIconButton:T,Content:x,Description:I,Footer:D,Header:H,Title:L,TitleGroup:M,Trigger:C};export{k as Sheet};
|
|
2
2
|
//# sourceMappingURL=sheet.js.map
|
package/dist/theme.d.ts
CHANGED
|
@@ -59,8 +59,28 @@ declare function isResolvedTheme(value: unknown): value is ResolvedTheme;
|
|
|
59
59
|
* ThemeProviderState is the shape of the state returned by the ThemeProviderContext.
|
|
60
60
|
*/
|
|
61
61
|
type ThemeProviderState = [theme: Theme, setTheme: (theme: Theme) => void];
|
|
62
|
+
/**
|
|
63
|
+
* Props for the {@link ThemeProvider} component.
|
|
64
|
+
*/
|
|
62
65
|
type ThemeProviderProps = PropsWithChildren & {
|
|
66
|
+
/**
|
|
67
|
+
* The initial theme to apply if no value is found in storage.
|
|
68
|
+
*
|
|
69
|
+
* Possible values {@link themes}:
|
|
70
|
+
* - `"system"` – follow the user’s system preferences (default).
|
|
71
|
+
* - `"light"` – force light mode.
|
|
72
|
+
* - `"dark"` – force dark mode.
|
|
73
|
+
* - `"light-high-contrast"` – light mode with increased contrast.
|
|
74
|
+
* - `"dark-high-contrast"` – dark mode with increased contrast.
|
|
75
|
+
*/
|
|
63
76
|
defaultTheme?: Theme;
|
|
77
|
+
/**
|
|
78
|
+
* The key used to persist the selected theme in cookies or storage.
|
|
79
|
+
*
|
|
80
|
+
* Defaults to `"theme"` (or the {@link DEFAULT_STORAGE_KEY} constant).
|
|
81
|
+
* Useful if you need to isolate theme settings across multiple apps
|
|
82
|
+
* or contexts.
|
|
83
|
+
*/
|
|
64
84
|
storageKey?: string;
|
|
65
85
|
};
|
|
66
86
|
/**
|
|
@@ -107,13 +127,13 @@ type PreventWrongThemeFlashScriptContentOptions = {
|
|
|
107
127
|
};
|
|
108
128
|
/**
|
|
109
129
|
* preventWrongThemeFlashScriptContent generates a script that prevents the wrong theme from flashing on initial page load.
|
|
110
|
-
* It checks
|
|
130
|
+
* It checks cookies for a stored theme, and if none is found, it sets the default theme.
|
|
111
131
|
* It also applies the correct theme to the `<html>` element based on the user's media query preferences.
|
|
112
132
|
*/
|
|
113
133
|
declare function preventWrongThemeFlashScriptContent(options?: PreventWrongThemeFlashScriptContentOptions): string;
|
|
114
134
|
type MantleThemeHeadContentProps = {
|
|
115
135
|
/**
|
|
116
|
-
* The default theme to use if no theme is stored in
|
|
136
|
+
* The default theme to use if no theme is stored in cookies.
|
|
117
137
|
* @default "system"
|
|
118
138
|
*/
|
|
119
139
|
defaultTheme?: Theme;
|
|
@@ -126,7 +146,7 @@ type MantleThemeHeadContentProps = {
|
|
|
126
146
|
*/
|
|
127
147
|
nonce?: string;
|
|
128
148
|
/**
|
|
129
|
-
* The key used to store the theme in
|
|
149
|
+
* The key used to store the theme in cookies.
|
|
130
150
|
* @default "mantle-ui-theme"
|
|
131
151
|
*/
|
|
132
152
|
storageKey?: string;
|
package/dist/theme.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,b as m,c as r,d as o,e as t,f as h,g as s,h as T,i as p,j as l,k as d,l as n,m as i,n as a,o as v}from"./chunk-
|
|
1
|
+
import{a as e,b as m,c as r,d as o,e as t,f as h,g as s,h as T,i as p,j as l,k as d,l as n,m as i,n as a,o as v}from"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";export{h as $resolvedTheme,o as $theme,a as MantleThemeHeadContent,e as PreloadFonts,T as ThemeProvider,l as applyTheme,s as isResolvedTheme,t as isTheme,i as preventWrongThemeFlashScriptContent,d as readThemeFromHtmlElement,m as resolvedThemes,r as themes,n as useAppliedTheme,v as useInitialHtmlThemeProps,p as useTheme};
|
|
2
2
|
//# sourceMappingURL=theme.js.map
|
package/dist/toast.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o,b as t,c as r}from"./chunk-
|
|
1
|
+
import{a as o,b as t,c as r}from"./chunk-BK5H6ZXB.js";import"./chunk-N6ZW2CVT.js";import"./chunk-6J7D73WA.js";import"./chunk-I6T6YV2L.js";import"./chunk-NPTDRQT5.js";import"./chunk-AZ56JGNY.js";export{r as Toast,o as Toaster,t as makeToast};
|
|
2
2
|
//# sourceMappingURL=toast.js.map
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "mantle is ngrok's UI library and design system.",
|
|
4
4
|
"author": "ngrok",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.54.0",
|
|
7
7
|
"homepage": "https://mantle.ngrok.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/prismjs": "1.26.5",
|
|
59
59
|
"@types/react": "18.3.24",
|
|
60
60
|
"@types/react-dom": "18.3.7",
|
|
61
|
-
"browserslist": "4.26.
|
|
61
|
+
"browserslist": "4.26.2",
|
|
62
62
|
"date-fns": "4.1.0",
|
|
63
63
|
"jsdom": "27.0.0",
|
|
64
64
|
"react": "18.3.1",
|
package/dist/chunk-WB5DRE27.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import{a as T}from"./chunk-6J7D73WA.js";import{Fragment as M,jsx as i,jsxs as k}from"react/jsx-runtime";var P="https://assets.ngrok.com",F=`${P}/fonts`,N=["/euclid-square/EuclidSquare-Regular-WebS.woff","/euclid-square/EuclidSquare-RegularItalic-WebS.woff","/euclid-square/EuclidSquare-Medium-WebS.woff","/euclid-square/EuclidSquare-Semibold-WebS.woff","/euclid-square/EuclidSquare-MediumItalic-WebS.woff","/ibm-plex-mono/IBMPlexMono-Text.woff","/ibm-plex-mono/IBMPlexMono-TextItalic.woff","/ibm-plex-mono/IBMPlexMono-SemiBold.woff","/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff"],q=e=>`${F}${e}`,g=({includeNunitoSans:e=!1})=>k(M,{children:[i("link",{rel:"preconnect",href:P}),N.map(t=>i("link",{rel:"preload",href:q(t),as:"font",type:"font/woff",crossOrigin:"anonymous"},t)),e&&i(R,{})]});g.displayName="PreloadFonts";function R(){return k(M,{children:[i("link",{rel:"preconnect",href:"https://fonts.googleapis.com"}),i("link",{rel:"preconnect",href:"https://fonts.gstatic.com",crossOrigin:"anonymous"}),i("link",{href:"https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000&display=swap",rel:"stylesheet"})]})}import b from"clsx";import{createContext as $,useContext as E,useEffect as C,useMemo as x,useState as D}from"react";import L from"tiny-invariant";import{Fragment as z,jsx as y,jsxs as G}from"react/jsx-runtime";var m="(prefers-color-scheme: dark)",l="(prefers-contrast: more)",H=["light","dark","light-high-contrast","dark-high-contrast"],w=["system",...H],ee=e=>e;function I(e){return typeof e!="string"?!1:w.includes(e)}var te=e=>e;function W(e){return typeof e!="string"?!1:H.includes(e)}var u="mantle-ui-theme",B=["system",()=>null],v=$(B),p=()=>typeof window<"u";function d(e,t="system"){let n=t??"system";if(p()){let o=null;try{o="localStorage"in window?window.localStorage.getItem(e):null}catch{}return I(o)?o:n}return n}function O({children:e,defaultTheme:t="system",storageKey:n=u}){let[o,r]=D(()=>{let s=d(n,t);return c(s),s});C(()=>{let s=d(n,t);r(s),c(s)},[t,n]),C(()=>{let s=window.matchMedia(m),a=window.matchMedia(l),h=()=>{d(n,t)==="system"&&c("system")};return s.addEventListener("change",h),a.addEventListener("change",h),()=>{s.removeEventListener("change",h),a.removeEventListener("change",h)}},[t,n]);let f=x(()=>[o,s=>{try{"localStorage"in window&&window.localStorage.setItem(n,s)}catch{}r(s),c(s)}],[n,o]);return y(v.Provider,{value:f,children:e})}O.displayName="ThemeProvider";function ne(){let e=E(v);return L(e,"useTheme must be used within a ThemeProvider"),e}function c(e){if(!p())return;let t=window.document.documentElement;t.classList.remove(...w);let n=window.matchMedia(m).matches,o=window.matchMedia(l).matches,r=S(e,{prefersDarkMode:n,prefersHighContrast:o});t.classList.add(r),t.dataset.appliedTheme=r,t.dataset.theme=e}function oe(){if(!p())return{appliedTheme:void 0,theme:void 0};let e=window.document.documentElement,t=I(e.dataset.theme)?e.dataset.theme:void 0;return{appliedTheme:W(e.dataset.appliedTheme)?e.dataset.appliedTheme:void 0,theme:t}}function S(e,{prefersDarkMode:t,prefersHighContrast:n}){return e==="system"?_({prefersDarkMode:t,prefersHighContrast:n}):e}function se(){let e=E(v),t=e!=null?e[0]:"system",n=T(m),o=T(l);return S(t,{prefersDarkMode:n,prefersHighContrast:o})}function _({prefersDarkMode:e,prefersHighContrast:t}){return t?e?"dark-high-contrast":"light-high-contrast":e?"dark":"light"}function Q(e){let{defaultTheme:t="system",storageKey:n=u}=e??{};return`
|
|
2
|
-
(function() {
|
|
3
|
-
const themes = ${JSON.stringify(w)};
|
|
4
|
-
const isTheme = (value) => typeof value === "string" && themes.includes(value);
|
|
5
|
-
const fallbackTheme = "${t}" ?? "system";
|
|
6
|
-
let maybeStoredTheme = null;
|
|
7
|
-
try {
|
|
8
|
-
maybeStoredTheme = "localStorage" in window ? window.localStorage.getItem("${n}") : null;
|
|
9
|
-
} catch (_) {}
|
|
10
|
-
const hasStoredTheme = isTheme(maybeStoredTheme);
|
|
11
|
-
if (!hasStoredTheme && "localStorage" in window) {
|
|
12
|
-
try {
|
|
13
|
-
window.localStorage.setItem("${n}", fallbackTheme);
|
|
14
|
-
} catch (_) {}
|
|
15
|
-
}
|
|
16
|
-
const themePreference = hasStoredTheme ? maybeStoredTheme : fallbackTheme;
|
|
17
|
-
const prefersDarkMode = window.matchMedia("${m}").matches;
|
|
18
|
-
const prefersHighContrast = window.matchMedia("${l}").matches;
|
|
19
|
-
let initialTheme = themePreference;
|
|
20
|
-
if (initialTheme === "system") {
|
|
21
|
-
if (prefersHighContrast) {
|
|
22
|
-
initialTheme = prefersDarkMode ? "dark-high-contrast" : "light-high-contrast";
|
|
23
|
-
} else {
|
|
24
|
-
initialTheme = prefersDarkMode ? "dark" : "light";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const htmlElement = document.documentElement;
|
|
28
|
-
htmlElement.classList.remove(...themes);
|
|
29
|
-
htmlElement.classList.add(initialTheme);
|
|
30
|
-
htmlElement.dataset.appliedTheme = initialTheme;
|
|
31
|
-
htmlElement.dataset.theme = themePreference;
|
|
32
|
-
})();
|
|
33
|
-
`.trim()}var A=({defaultTheme:e="system",includeNunitoSans:t=!1,nonce:n,storageKey:o=u})=>G(z,{children:[y("script",{dangerouslySetInnerHTML:{__html:Q({defaultTheme:e,storageKey:o})},nonce:n}),y(g,{includeNunitoSans:t})]});A.displayName="MantleThemeHeadContent";function re(e){let{className:t="",defaultTheme:n="system",storageKey:o=u}=e??{};return x(()=>{if(!p())return{className:b(t),"data-applied-theme":"system","data-theme":"system"};let r=window.matchMedia(m).matches,f=window.matchMedia(l).matches,s=d(o,n),a=S(s,{prefersDarkMode:r,prefersHighContrast:f});return{className:b(t,a),"data-applied-theme":a,"data-theme":s}},[t,n,o])}export{g as a,H as b,w as c,ee as d,I as e,te as f,W as g,O as h,ne as i,c as j,oe as k,se as l,Q as m,A as n,re as o};
|
|
34
|
-
//# sourceMappingURL=chunk-WB5DRE27.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/theme/preload-fonts.tsx","../src/components/theme/theme-provider.tsx"],"sourcesContent":["const cdnOrigin = \"https://assets.ngrok.com\";\nconst cdnBase = `${cdnOrigin}/fonts`;\n\nconst fonts = [\n\t\"/euclid-square/EuclidSquare-Regular-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-RegularItalic-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-Medium-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-Semibold-WebS.woff\",\n\t\"/euclid-square/EuclidSquare-MediumItalic-WebS.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-Text.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-TextItalic.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-SemiBold.woff\",\n\t\"/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff\",\n] as const;\n\ntype Font = (typeof fonts)[number];\n\nconst fontHref = <T extends Font = Font>(font: T) =>\n\t`${cdnBase}${font}` as const;\n\ntype Props = {\n\t/**\n\t * If set, will also preload and include the optional Nunito Sans font from Google Fonts.\n\t * @default false\n\t */\n\tincludeNunitoSans?: boolean;\n};\n\n/**\n * Preload custom fonts used in the theme.\n *\n * @see https://mantle.ngrok.com/components/theme-provider#api-preload-fonts\n *\n * @example\n * ```tsx\n * <PreloadFonts includeNunitoSans />\n * ```\n */\nconst PreloadFonts = ({ includeNunitoSans = false }: Props) => (\n\t<>\n\t\t<link rel=\"preconnect\" href={cdnOrigin} />\n\t\t{fonts.map((font) => (\n\t\t\t<link\n\t\t\t\tkey={font}\n\t\t\t\trel=\"preload\"\n\t\t\t\thref={fontHref(font)}\n\t\t\t\tas=\"font\"\n\t\t\t\ttype=\"font/woff\"\n\t\t\t\tcrossOrigin=\"anonymous\"\n\t\t\t/>\n\t\t))}\n\t\t{includeNunitoSans && <NunitoSans />}\n\t</>\n);\nPreloadFonts.displayName = \"PreloadFonts\";\n\nexport {\n\t//,\n\tPreloadFonts,\n};\n\nfunction NunitoSans() {\n\treturn (\n\t\t<>\n\t\t\t<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n\t\t\t<link\n\t\t\t\trel=\"preconnect\"\n\t\t\t\thref=\"https://fonts.gstatic.com\"\n\t\t\t\tcrossOrigin=\"anonymous\"\n\t\t\t/>\n\t\t\t<link\n\t\t\t\thref=\"https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000&display=swap\"\n\t\t\t\trel=\"stylesheet\"\n\t\t\t/>\n\t\t</>\n\t);\n}\n","\"use client\";\n\nimport clsx from \"clsx\";\nimport type { ComponentProps, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport invariant from \"tiny-invariant\";\nimport { useMatchesMediaQuery } from \"../../hooks/use-matches-media-query.js\";\nimport { PreloadFonts } from \"./preload-fonts.js\";\n\n/**\n * prefersDarkModeMediaQuery is the media query used to detect if the user prefers dark mode.\n */\nconst prefersDarkModeMediaQuery = \"(prefers-color-scheme: dark)\";\n\n/**\n * prefersHighContrastMediaQuery is the media query used to detect if the user prefers high contrast mode.\n */\nconst prefersHighContrastMediaQuery = \"(prefers-contrast: more)\";\n\n/**\n * resolvedThemes is a tuple of valid themes that have been resolved from \"system\" to a specific theme.\n */\nconst resolvedThemes = [\n\t\"light\",\n\t\"dark\",\n\t\"light-high-contrast\",\n\t\"dark-high-contrast\",\n] as const;\n\n/**\n * ResolvedTheme is a type that represents a theme that has been resolved from \"system\" to a specific theme.\n */\ntype ResolvedTheme = (typeof resolvedThemes)[number];\n\n/**\n * themes is a tuple of valid themes.\n */\nconst themes = [\"system\", ...resolvedThemes] as const;\n\n/**\n * Theme is a string literal type that represents a valid theme.\n */\ntype Theme = (typeof themes)[number];\n\n/**\n * $theme is a helper which translates the Theme type into a string literal type.\n */\nconst $theme = <T extends Theme = Theme>(value: T) => value;\n\n/**\n * Type predicate that checks if a value is a valid theme.\n */\nfunction isTheme(value: unknown): value is Theme {\n\tif (typeof value !== \"string\") {\n\t\treturn false;\n\t}\n\n\treturn themes.includes(value as Theme);\n}\n\n/**\n * $resolvedTheme is a helper which translates the ResolvedTheme type into a string literal type.\n */\nconst $resolvedTheme = <T extends ResolvedTheme = ResolvedTheme>(value: T) =>\n\tvalue;\n\n/**\n * Type predicate that checks if a value is a valid resolved theme.\n */\nfunction isResolvedTheme(value: unknown): value is ResolvedTheme {\n\tif (typeof value !== \"string\") {\n\t\treturn false;\n\t}\n\n\treturn resolvedThemes.includes(value as ResolvedTheme);\n}\n\n/**\n * DEFAULT_STORAGE_KEY is the default key used to store the theme in localStorage.\n */\nconst DEFAULT_STORAGE_KEY = \"mantle-ui-theme\";\n\n/**\n * ThemeProviderState is the shape of the state returned by the ThemeProviderContext.\n */\ntype ThemeProviderState = [theme: Theme, setTheme: (theme: Theme) => void];\n\n/**\n * Initial state for the ThemeProviderContext.\n */\nconst initialState: ThemeProviderState = [\"system\", () => null];\n\n/**\n * ThemeProviderContext is a React Context that provides the current theme and a function to set the theme.\n */\nconst ThemeProviderContext = createContext<ThemeProviderState | null>(\n\tinitialState,\n);\n\n/**\n * isBrowser returns true if the code is running in a browser environment.\n */\nconst isBrowser = () => typeof window !== \"undefined\";\n\n/**\n * Gets the stored theme from localStorage or returns the default theme if no theme is stored.\n */\nfunction getStoredTheme(storageKey: string, defaultTheme: Theme = \"system\") {\n\tconst fallbackTheme = defaultTheme ?? \"system\";\n\tif (isBrowser()) {\n\t\tlet storedTheme: string | null = null;\n\t\ttry {\n\t\t\tstoredTheme =\n\t\t\t\t\"localStorage\" in window\n\t\t\t\t\t? window.localStorage.getItem(storageKey)\n\t\t\t\t\t: null;\n\t\t} catch (_) {}\n\t\treturn isTheme(storedTheme) ? storedTheme : fallbackTheme;\n\t}\n\treturn fallbackTheme;\n}\n\ntype ThemeProviderProps = PropsWithChildren & {\n\tdefaultTheme?: Theme;\n\tstorageKey?: string;\n};\n\n/**\n * ThemeProvider is a React Context Provider that provides the current theme and a function to set the theme.\n *\n * @see https://mantle.ngrok.com/components/theme-provider#api-theme-provider\n *\n * @example\n * ```tsx\n * <ThemeProvider defaultTheme=\"system\" storageKey=\"app-theme\">\n * <App />\n * </ThemeProvider>\n * ```\n */\nfunction ThemeProvider({\n\tchildren,\n\tdefaultTheme = \"system\",\n\tstorageKey = DEFAULT_STORAGE_KEY,\n}: ThemeProviderProps) {\n\tconst [theme, setTheme] = useState<Theme>(() => {\n\t\tconst initialTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tapplyTheme(initialTheme);\n\t\treturn initialTheme;\n\t});\n\n\tuseEffect(() => {\n\t\tconst storedTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tsetTheme(storedTheme);\n\t\tapplyTheme(storedTheme);\n\t}, [defaultTheme, storageKey]);\n\n\tuseEffect(() => {\n\t\tconst prefersDarkMql = window.matchMedia(prefersDarkModeMediaQuery);\n\t\tconst prefersHighContrastMql = window.matchMedia(\n\t\t\tprefersHighContrastMediaQuery,\n\t\t);\n\n\t\tconst onChange = () => {\n\t\t\tconst storedTheme = getStoredTheme(storageKey, defaultTheme);\n\n\t\t\t// If the stored theme is not \"system\", then the user has explicitly set a theme and we should not\n\t\t\t// automatically change the theme when the user's system preferences change.\n\t\t\tif (storedTheme !== \"system\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tapplyTheme(\"system\");\n\t\t};\n\n\t\tprefersDarkMql.addEventListener(\"change\", onChange);\n\t\tprefersHighContrastMql.addEventListener(\"change\", onChange);\n\n\t\treturn () => {\n\t\t\tprefersDarkMql.removeEventListener(\"change\", onChange);\n\t\t\tprefersHighContrastMql.removeEventListener(\"change\", onChange);\n\t\t};\n\t}, [defaultTheme, storageKey]);\n\n\tconst value: ThemeProviderState = useMemo(\n\t\t() => [\n\t\t\ttheme,\n\t\t\t(theme: Theme) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (\"localStorage\" in window) {\n\t\t\t\t\t\twindow.localStorage.setItem(storageKey, theme);\n\t\t\t\t\t}\n\t\t\t\t} catch (_) {}\n\t\t\t\tsetTheme(theme);\n\t\t\t\tapplyTheme(theme);\n\t\t\t},\n\t\t],\n\t\t[storageKey, theme],\n\t);\n\n\treturn (\n\t\t<ThemeProviderContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ThemeProviderContext.Provider>\n\t);\n}\nThemeProvider.displayName = \"ThemeProvider\";\n\n/**\n * useTheme returns the current theme and a function to set the theme.\n *\n * @note This function will throw an error if used outside of a ThemeProvider context tree.\n */\nfunction useTheme() {\n\tconst context = useContext(ThemeProviderContext);\n\n\tinvariant(context, \"useTheme must be used within a ThemeProvider\");\n\n\treturn context;\n}\n\n/**\n * Applies the given theme to the `<html>` element.\n */\nfunction applyTheme(theme: Theme) {\n\tif (!isBrowser()) {\n\t\treturn;\n\t}\n\n\tconst htmlElement = window.document.documentElement;\n\thtmlElement.classList.remove(...themes);\n\tconst prefersDarkMode = window.matchMedia(prefersDarkModeMediaQuery).matches;\n\tconst prefersHighContrast = window.matchMedia(\n\t\tprefersHighContrastMediaQuery,\n\t).matches;\n\tconst newTheme = resolveTheme(theme, {\n\t\tprefersDarkMode,\n\t\tprefersHighContrast,\n\t});\n\thtmlElement.classList.add(newTheme);\n\thtmlElement.dataset.appliedTheme = newTheme;\n\thtmlElement.dataset.theme = theme;\n}\n\n/**\n * Read the theme and applied theme from the `<html>` element.\n */\nfunction readThemeFromHtmlElement() {\n\tif (!isBrowser()) {\n\t\treturn {\n\t\t\tappliedTheme: undefined,\n\t\t\ttheme: undefined,\n\t\t};\n\t}\n\n\tconst htmlElement = window.document.documentElement;\n\tconst theme = isTheme(htmlElement.dataset.theme)\n\t\t? htmlElement.dataset.theme\n\t\t: undefined;\n\tconst appliedTheme = isResolvedTheme(htmlElement.dataset.appliedTheme)\n\t\t? htmlElement.dataset.appliedTheme\n\t\t: undefined;\n\n\treturn {\n\t\tappliedTheme,\n\t\ttheme,\n\t};\n}\n\n/**\n * If the theme is \"system\", it will resolve the theme based on the user's media query preferences, otherwise it will return the theme as is.\n * This will mirror the result that gets applied to the <html> element.\n */\nfunction resolveTheme(\n\ttheme: Theme,\n\t{\n\t\tprefersDarkMode,\n\t\tprefersHighContrast,\n\t}: { prefersDarkMode: boolean; prefersHighContrast: boolean },\n) {\n\tif (theme === \"system\") {\n\t\treturn determineThemeFromMediaQuery({\n\t\t\tprefersDarkMode,\n\t\t\tprefersHighContrast,\n\t\t});\n\t}\n\n\treturn theme;\n}\n\n/**\n * If the theme is \"system\", it will resolve the theme based on the user's media query preferences, otherwise it will return the theme as is.\n * This will mirror the result that gets applied to the <html> element.\n */\nfunction useAppliedTheme() {\n\tconst themeContext = useContext(ThemeProviderContext);\n\tconst theme = themeContext != null ? themeContext[0] : \"system\";\n\n\tconst prefersDarkMode = useMatchesMediaQuery(prefersDarkModeMediaQuery);\n\tconst prefersHighContrast = useMatchesMediaQuery(\n\t\tprefersHighContrastMediaQuery,\n\t);\n\n\treturn resolveTheme(theme, { prefersDarkMode, prefersHighContrast });\n}\n\n/**\n * determineThemeFromMediaQuery returns the theme that should be used based on the user's media query preferences.\n * @private\n *\n * @example\n * ```tsx\n * const theme = determineThemeFromMediaQuery({\n * prefersDarkMode: true,\n * prefersHighContrast: false\n * });\n * // Returns: \"dark\"\n *\n * const themeWithContrast = determineThemeFromMediaQuery({\n * prefersDarkMode: false,\n * prefersHighContrast: true\n * });\n * // Returns: \"light-high-contrast\"\n * ```\n */\nexport function determineThemeFromMediaQuery({\n\tprefersDarkMode,\n\tprefersHighContrast,\n}: {\n\tprefersDarkMode: boolean;\n\tprefersHighContrast: boolean;\n}): ResolvedTheme {\n\tif (prefersHighContrast) {\n\t\treturn prefersDarkMode ? \"dark-high-contrast\" : \"light-high-contrast\";\n\t}\n\n\treturn prefersDarkMode ? \"dark\" : \"light\";\n}\n\ntype PreventWrongThemeFlashScriptContentOptions = {\n\tdefaultTheme?: Theme;\n\tstorageKey?: string;\n};\n\n/**\n * preventWrongThemeFlashScriptContent generates a script that prevents the wrong theme from flashing on initial page load.\n * It checks localStorage for a stored theme, and if none is found, it sets the default theme.\n * It also applies the correct theme to the `<html>` element based on the user's media query preferences.\n */\nfunction preventWrongThemeFlashScriptContent(\n\toptions?: PreventWrongThemeFlashScriptContentOptions,\n) {\n\tconst { defaultTheme = \"system\", storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions ?? {};\n\n\treturn `\n(function() {\n\tconst themes = ${JSON.stringify(themes)};\n\tconst isTheme = (value) => typeof value === \"string\" && themes.includes(value);\n\tconst fallbackTheme = \"${defaultTheme}\" ?? \"system\";\n\tlet maybeStoredTheme = null;\n\ttry {\n\t\tmaybeStoredTheme = \"localStorage\" in window ? window.localStorage.getItem(\"${storageKey}\") : null;\n\t} catch (_) {}\n\tconst hasStoredTheme = isTheme(maybeStoredTheme);\n\tif (!hasStoredTheme && \"localStorage\" in window) {\n\t\ttry {\n\t\t\twindow.localStorage.setItem(\"${storageKey}\", fallbackTheme);\n\t\t} catch (_) {}\n\t}\n\tconst themePreference = hasStoredTheme ? maybeStoredTheme : fallbackTheme;\n\tconst prefersDarkMode = window.matchMedia(\"${prefersDarkModeMediaQuery}\").matches;\n\tconst prefersHighContrast = window.matchMedia(\"${prefersHighContrastMediaQuery}\").matches;\n\tlet initialTheme = themePreference;\n\tif (initialTheme === \"system\") {\n\t\tif (prefersHighContrast) {\n\t\t\tinitialTheme = prefersDarkMode ? \"dark-high-contrast\" : \"light-high-contrast\";\n\t\t} else {\n\t\t\tinitialTheme = prefersDarkMode ? \"dark\" : \"light\";\n\t\t}\n\t}\n\tconst htmlElement = document.documentElement;\n\thtmlElement.classList.remove(...themes);\n\thtmlElement.classList.add(initialTheme);\n\thtmlElement.dataset.appliedTheme = initialTheme;\n\thtmlElement.dataset.theme = themePreference;\n})();\n`.trim();\n}\n\ntype MantleThemeHeadContentProps = {\n\t/**\n\t * The default theme to use if no theme is stored in localStorage.\n\t * @default \"system\"\n\t */\n\tdefaultTheme?: Theme;\n\t/**\n\t * An optional CSP nonce to allowlist this inline script. Using this can help\n\t * you to avoid using the CSP `unsafe-inline` directive, which disables\n\t * XSS protection and would allowlist all inline scripts or styles.\n\t *\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce\n\t */\n\tnonce?: string;\n\t/**\n\t * The key used to store the theme in localStorage.\n\t * @default \"mantle-ui-theme\"\n\t */\n\tstorageKey?: string;\n} & ComponentProps<typeof PreloadFonts>;\n\n/**\n * MantleThemeHeadContent is a React component that renders a script to prevent\n * Flash of Unstyled Content (FOUC), or the wrong theme from flashing on initial\n * page load.\n *\n * Render as high as possible in the <head> element.\n */\nconst MantleThemeHeadContent = ({\n\tdefaultTheme = \"system\",\n\tincludeNunitoSans = false,\n\tnonce,\n\tstorageKey = DEFAULT_STORAGE_KEY,\n}: MantleThemeHeadContentProps) => (\n\t<>\n\t\t<script\n\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t__html: preventWrongThemeFlashScriptContent({\n\t\t\t\t\tdefaultTheme,\n\t\t\t\t\tstorageKey,\n\t\t\t\t}),\n\t\t\t}}\n\t\t\tnonce={nonce}\n\t\t/>\n\t\t<PreloadFonts includeNunitoSans={includeNunitoSans} />\n\t</>\n);\nMantleThemeHeadContent.displayName = \"MantleThemeHeadContent\";\n\ntype InitialThemeProps = {\n\tclassName: string;\n\t\"data-applied-theme\": Omit<Theme, \"system\">;\n\t\"data-theme\": Theme;\n};\n\n/**\n * useInitialHtmlThemeProps returns the initial props that should be applied to the <html> element to prevent react hydration errors.\n */\nfunction useInitialHtmlThemeProps(props?: {\n\tclassName?: string;\n\tdefaultTheme?: Theme;\n\tstorageKey?: string;\n}): InitialThemeProps {\n\tconst {\n\t\tclassName = \"\",\n\t\tdefaultTheme = \"system\",\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = props ?? {};\n\n\treturn useMemo(() => {\n\t\tif (!isBrowser()) {\n\t\t\treturn {\n\t\t\t\tclassName: clsx(className),\n\t\t\t\t\"data-applied-theme\": \"system\",\n\t\t\t\t\"data-theme\": \"system\",\n\t\t\t};\n\t\t}\n\n\t\tconst prefersDarkMode = window.matchMedia(\n\t\t\tprefersDarkModeMediaQuery,\n\t\t).matches;\n\t\tconst prefersHighContrast = window.matchMedia(\n\t\t\tprefersHighContrastMediaQuery,\n\t\t).matches;\n\t\tconst initialTheme = getStoredTheme(storageKey, defaultTheme);\n\t\tconst reolvedTheme = resolveTheme(initialTheme, {\n\t\t\tprefersDarkMode,\n\t\t\tprefersHighContrast,\n\t\t});\n\n\t\treturn {\n\t\t\tclassName: clsx(className, reolvedTheme),\n\t\t\t\"data-applied-theme\": reolvedTheme,\n\t\t\t\"data-theme\": initialTheme,\n\t\t};\n\t}, [className, defaultTheme, storageKey]);\n}\n\nexport {\n\t//,\n\t$resolvedTheme,\n\t$theme,\n\tapplyTheme,\n\tisResolvedTheme,\n\tisTheme,\n\tMantleThemeHeadContent,\n\tpreventWrongThemeFlashScriptContent,\n\treadThemeFromHtmlElement,\n\tresolvedThemes,\n\tThemeProvider,\n\tthemes,\n\tuseAppliedTheme,\n\tuseInitialHtmlThemeProps,\n\tuseTheme,\n};\n\nexport type {\n\t//,\n\tResolved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B,EAAQ,IAAM,CACpB,GAAI,CAACjB,EAAU,EACd,MAAO,CACN,UAAWyC,EAAKD,CAAS,EACzB,qBAAsB,SACtB,aAAc,QACf,EAGD,IAAMjB,EAAkB,OAAO,WAC9BpC,CACD,EAAE,QACIqC,EAAsB,OAAO,WAClCpC,CACD,EAAE,QACIuB,EAAeV,EAAeC,EAAYC,CAAY,EACtDuC,EAAehB,EAAaf,EAAc,CAC/C,gBAAAY,EACA,oBAAAC,CACD,CAAC,EAED,MAAO,CACN,UAAWiB,EAAKD,EAAWE,CAAY,EACvC,qBAAsBA,EACtB,aAAc/B,CACf,CACD,EAAG,CAAC6B,EAAWrC,EAAcD,CAAU,CAAC,CACzC","names":["Fragment","jsx","jsxs","cdnOrigin","cdnBase","fonts","fontHref","font","PreloadFonts","includeNunitoSans","NunitoSans","NunitoSans","jsxs","Fragment","jsx","clsx","createContext","useContext","useEffect","useMemo","useState","invariant","Fragment","jsx","jsxs","prefersDarkModeMediaQuery","prefersHighContrastMediaQuery","resolvedThemes","themes","$theme","value","isTheme","$resolvedTheme","isResolvedTheme","DEFAULT_STORAGE_KEY","initialState","ThemeProviderContext","createContext","isBrowser","getStoredTheme","storageKey","defaultTheme","fallbackTheme","storedTheme","ThemeProvider","children","theme","setTheme","useState","initialTheme","applyTheme","useEffect","prefersDarkMql","prefersHighContrastMql","onChange","useMemo","useTheme","context","useContext","invariant","htmlElement","prefersDarkMode","prefersHighContrast","newTheme","resolveTheme","readThemeFromHtmlElement","determineThemeFromMediaQuery","useAppliedTheme","themeContext","useMatchesMediaQuery","preventWrongThemeFlashScriptContent","options","MantleThemeHeadContent","includeNunitoSans","nonce","PreloadFonts","useInitialHtmlThemeProps","props","className","clsx","reolvedTheme"]}
|
|
File without changes
|