@manyducks.co/dolla 2.0.0-alpha.60 → 2.0.0-alpha.62

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.
Files changed (53) hide show
  1. package/dist/core/context.d.ts +23 -6
  2. package/dist/core/context.test.d.ts +1 -0
  3. package/dist/core/index.d.ts +6 -5
  4. package/dist/core/logger.test.d.ts +0 -0
  5. package/dist/core/markup.d.ts +12 -39
  6. package/dist/core/markup.test.d.ts +0 -0
  7. package/dist/core/mount.test.d.ts +0 -0
  8. package/dist/core/nodes/_markup.d.ts +36 -0
  9. package/dist/core/nodes/dom.d.ts +5 -6
  10. package/dist/core/nodes/dynamic.d.ts +6 -13
  11. package/dist/core/nodes/{html.d.ts → element.d.ts} +9 -8
  12. package/dist/core/nodes/portal.d.ts +6 -7
  13. package/dist/core/nodes/repeat.d.ts +8 -6
  14. package/dist/core/nodes/view.d.ts +6 -5
  15. package/dist/core/ref.test.d.ts +1 -0
  16. package/dist/core/signals.d.ts +17 -2
  17. package/dist/core/views/default-crash-view.d.ts +5 -2
  18. package/dist/core/views/for.d.ts +23 -0
  19. package/dist/core/views/show.d.ts +26 -0
  20. package/dist/hooks/index.d.ts +64 -0
  21. package/dist/hooks/index.test.d.ts +1 -0
  22. package/dist/hooks.js +69 -0
  23. package/dist/hooks.js.map +1 -0
  24. package/dist/i18n.js +49 -49
  25. package/dist/i18n.js.map +1 -1
  26. package/dist/index.js +61 -58
  27. package/dist/index.js.map +1 -1
  28. package/dist/jsx-dev-runtime.js +1 -1
  29. package/dist/jsx-runtime.js +1 -1
  30. package/dist/logger-Bl496yfY.js +91 -0
  31. package/dist/logger-Bl496yfY.js.map +1 -0
  32. package/dist/markup-UzKSsawX.js +1037 -0
  33. package/dist/markup-UzKSsawX.js.map +1 -0
  34. package/dist/ref-BD79iqlg.js +15 -0
  35. package/dist/ref-BD79iqlg.js.map +1 -0
  36. package/dist/router/router.d.ts +33 -18
  37. package/dist/{router-BpuJQ6OA.js → router-BXBX8lnO.js} +217 -190
  38. package/dist/router-BXBX8lnO.js.map +1 -0
  39. package/dist/router.js +1 -1
  40. package/dist/signals-gCwiIe5X.js +450 -0
  41. package/dist/signals-gCwiIe5X.js.map +1 -0
  42. package/dist/types.d.ts +1 -1
  43. package/docs/hooks.md +211 -0
  44. package/docs/i18n.md +1 -1
  45. package/notes/scratch.md +23 -1
  46. package/package.json +5 -1
  47. package/vite.config.js +1 -0
  48. package/dist/core/symbols.d.ts +0 -2
  49. package/dist/logger-MPwl-Xqu.js +0 -524
  50. package/dist/logger-MPwl-Xqu.js.map +0 -1
  51. package/dist/markup-BGlfQYQk.js +0 -996
  52. package/dist/markup-BGlfQYQk.js.map +0 -1
  53. package/dist/router-BpuJQ6OA.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/core/ref.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["const EMPTY_REF = Symbol(\"Ref.EMPTY\");\n\n/**\n * A hybrid getter/setter function that stores the last value it was called with.\n * Guarantees a value is held at runtime by throwing an error if no value is set.\n */\nexport interface Ref<T> {\n /**\n * Returns the currently stored value of the ref, or throws an error if no value has been set.\n */\n (): T;\n\n /**\n * Stores a new value to the ref and returns that value.\n */\n (value: T): T;\n}\n\n/**\n * Creates a Ref.\n */\nexport function ref<T>(value?: T): Ref<T>;\n\nexport function ref(value = EMPTY_REF) {\n return function () {\n if (arguments.length === 0) {\n if (value === EMPTY_REF) {\n throw new Error(`Ref getter was called, but ref has no value! Be sure to set your refs before accessing them.`);\n }\n } else if (arguments.length === 1) {\n value = arguments[0];\n } else {\n throw new Error(`Ref called with too many arguments. Expected 0 or 1 arguments.`);\n }\n\n return value;\n };\n}\n","import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport type CrashViewProps = {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n};\n\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewInstance } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewInstance(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewInstance(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["EMPTY_REF","ref","value","DefaultCrashView","props","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","unmount","ViewInstance","LifecycleEvent","Router","MOUNT","UNMOUNT"],"mappings":";;;;;;AAAA,MAAMA,IAAY,OAAO,WAAW;AAuBpB,SAAAC,EAAIC,IAAQF,GAAW;AACrC,SAAO,WAAY;AACb,QAAA,UAAU,WAAW;AACvB,UAAIE,MAAUF;AACN,cAAA,IAAI,M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AA,CACvB;AAAA,UACDA,EAAM,MAAM;AAAA,QAAA;AAAA,MACd,CACD;AAAA,MACDC,EAAE,KAAK,EAAE,UAAU,8CAA+C,CAAA;AAAA,IAAA;AAAA,EACpE,CACD;AACH;AC1EA,IAAIE,IAAY;AAgBM,eAAAC,EAAMC,GAAWC,GAAsBC,GAA4C;AAGvG,MAFiBC,EAAA,SAASF,GAAa,mEAAmE,GAEtGH;AACI,UAAA,IAAI,MAAM,iCAAiC;AAG/C,MAAAM,GACAC,GACAC,KAAYJ,KAAA,gBAAAA,EAAS,cAAaR;AAEtC,QAAMa,KAAcL,KAAA,gBAAAA,EAAS,YAAW,IAAIM,EAAQ,KAAK;AAEzD,EAAAC,EAAc,CAACd,MAAU;AACvB,IAAIG,KACMY,EAAA,GAIV,IAAIC,EAAaJ,GAAaD,GAAWX,CAAK,EAAE,MAAMM,CAAW;AAAA,EAAA,CAClE,GAEOO,EAAA,KAAKD,GAAaK,EAAe,UAAU,GAE/CZ,aAAgBa,KAETR,IAAAL,GACTI,IAAW,MAAMC,EAAOS,CAAK,EAAEb,GAAaM,CAAW,KAEvDH,IAAW,IAAIO,EAAaJ,GAAaP,GAAM,CAAA,CAAE,GAEnDI,EAAS,MAAMH,CAAW,GACdH,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,SAAS;AAElD,iBAAeF,IAAU;AACvB,IAAKZ,MAEGU,EAAA,KAAKD,GAAaK,EAAe,YAAY,GAErDR,EAAS,QAAQ,EAAK,GAClBC,KACI,MAAAA,EAAOU,CAAO,EAAE,GAEZjB,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,WAAW;AAAA,EAAA;AAG/C,SAAAF;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../src/core/views/for.ts","../src/core/views/show.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { type Key, RepeatNode } from \"../nodes/repeat\";\nimport { type Signal } from \"../signals\";\n\nexport interface ForProps<T> {\n /**\n * An array of items to render.\n */\n each: Signal<T[]>;\n /**\n * A function to extract a unique key that identifies each item.\n * If no `key` function is passed, object identity (===) will be used.\n */\n key?: (item: T, index: number) => Key;\n /**\n * A render function. Takes the item and its index in signal form and returns something to display for each item.\n */\n children: ($item: Signal<T>, $index: Signal<number>, ctx: Context) => Renderable;\n}\n\nconst defaultKeyFn = (x: any) => x;\n\n/**\n *\n */\nexport function For<T>(props: ForProps<T>, context: Context) {\n return new RepeatNode(context, props.each, props.key ?? defaultKeyFn, props.children);\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { DynamicNode } from \"../nodes/dynamic\";\nimport { get, type Signal } from \"../signals\";\n\nexport interface ShowProps {\n /**\n * If present, children will be rendered only when this signal holds a truthy value.\n */\n when?: Signal<any>;\n\n /**\n * If present, children will be rendered only when this signal holds a falsy value.\n */\n unless?: Signal<any>;\n\n /**\n * Content to render if conditions permit.\n */\n children: Renderable;\n\n /**\n * Content to render when conditions don't permit `children` to render.\n */\n fallback?: Renderable;\n}\n\n/**\n * Conditionally display children.\n */\nexport function Show(props: ShowProps, context: Context) {\n return new DynamicNode(context, () => {\n let shouldShow = true;\n\n if (props.when != null && props.unless != null) {\n shouldShow = get(props.when) && !get(props.unless);\n } else if (props.when != null) {\n shouldShow = get(props.when);\n } else if (props.unless != null) {\n shouldShow = !get(props.unless);\n }\n\n if (shouldShow) {\n return props.children;\n } else {\n return props.fallback;\n }\n });\n}\n","import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewNode(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewNode(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["defaultKeyFn","x","For","props","context","RepeatNode","Show","DynamicNode","shouldShow","get","DefaultCrashView","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","unmount","ViewNode","LifecycleEvent","Router","MOUNT","UNMOUNT"],"mappings":";;;;;;;;;AAqBA,MAAMA,IAAe,CAACC,MAAWA;AAKjB,SAAAC,EAAOC,GAAoBC,GAAkB;AACpD,SAAA,IAAIC,EAAWD,GAASD,EAAM,MAAMA,EAAM,OAAOH,GAAcG,EAAM,QAAQ;AACtF;ACEgB,SAAAG,EAAKH,GAAkBC,GAAkB;AAChD,SAAA,IAAIG,EAAYH,GAAS,MAAM;AACpC,QAAII,IAAa;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.js";
1
+ import { d as n } from "./markup-UzKSsawX.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function u(e, r, t, o, a, i) {
4
4
  return new n(e, t != null ? { ...r, key: t } : r);
@@ -1,4 +1,4 @@
1
- import { b as u } from "./markup-BGlfQYQk.js";
1
+ import { d as u } from "./markup-UzKSsawX.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function o(t, n, r) {
4
4
  return new u(t, r != null ? { ...n, key: r } : n);
@@ -0,0 +1,91 @@
1
+ import { b as i } from "./typeChecking-CbltMOUt.js";
2
+ import { g as w, u as m, j as o, n as b, k as v } from "./signals-gCwiIe5X.js";
3
+ let s = "production";
4
+ function h() {
5
+ return s;
6
+ }
7
+ function k(r) {
8
+ s = r;
9
+ }
10
+ let g = {
11
+ info: "development",
12
+ log: "development",
13
+ warn: "development",
14
+ error: !0
15
+ }, d = o("*,-dolla.*"), f = [], u = !1;
16
+ function x(r) {
17
+ return f.push(r), function() {
18
+ f.splice(f.indexOf(r), 1);
19
+ };
20
+ }
21
+ function y(r, e) {
22
+ const t = (e == null ? void 0 : e.console) ?? L(), l = (a) => {
23
+ let c = m(r);
24
+ if (g[a] === !1 || i(g[a]) && g[a] !== h() || !d(c))
25
+ return b;
26
+ {
27
+ let n = `%c${c}`;
28
+ return e != null && e.tag ? e.tagName ? n += ` %c[${e.tagName}: %c${e.tag}%c]` : n += ` %c[%c${e.tag}%c]` : n += "%c%c%c", t[a].bind(
29
+ t,
30
+ n,
31
+ `color:${v(n)};font-weight:bold`,
32
+ "color:#777",
33
+ "color:#aaa",
34
+ "color:#777"
35
+ );
36
+ }
37
+ };
38
+ return {
39
+ get info() {
40
+ return l("info");
41
+ },
42
+ get log() {
43
+ return l("log");
44
+ },
45
+ get warn() {
46
+ return l("warn");
47
+ },
48
+ get error() {
49
+ return l("error");
50
+ },
51
+ crash(a) {
52
+ if (!u) {
53
+ u = !0;
54
+ const c = {
55
+ error: a,
56
+ loggerName: w(r),
57
+ tag: e == null ? void 0 : e.tag,
58
+ tagName: e == null ? void 0 : e.tagName
59
+ };
60
+ for (const n of f)
61
+ n(c);
62
+ throw a;
63
+ }
64
+ return a;
65
+ }
66
+ };
67
+ }
68
+ function C(r) {
69
+ d = o(r);
70
+ }
71
+ function E(r) {
72
+ for (const e in r) {
73
+ const t = r[e];
74
+ t && (g[e] = t);
75
+ }
76
+ }
77
+ function L() {
78
+ if (typeof window < "u" && window.console)
79
+ return window.console;
80
+ if (typeof global < "u" && global.console)
81
+ return global.console;
82
+ }
83
+ export {
84
+ C as a,
85
+ E as b,
86
+ y as c,
87
+ h as g,
88
+ x as o,
89
+ k as s
90
+ };
91
+ //# sourceMappingURL=logger-Bl496yfY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-Bl496yfY.js","sources":["../src/core/env.ts","../src/core/logger.ts"],"sourcesContent":["import type { Env } from \"../types\";\n\nlet currentEnv = \"production\";\n\nexport function getEnv() {\n return currentEnv;\n}\n\nexport function setEnv(value: Env) {\n currentEnv = value;\n}\n","import { isString } from \"../typeChecking.js\";\nimport type { Env } from \"../types.js\";\nimport { createMatcher, noOp, okhash, type MatcherFunction } from \"../utils.js\";\nimport { getEnv } from \"./env.js\";\nimport { get, untracked, type MaybeSignal } from \"./signals.js\";\n\nexport interface LogLevels {\n info: boolean | Env;\n log: boolean | Env;\n warn: boolean | Env;\n error: boolean | Env;\n}\n\nexport interface Logger {\n info(...args: any[]): void;\n log(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n crash(error: Error): Error;\n}\n\nexport interface LoggerOptions {\n /**\n * Tag value to print with logs.\n */\n tag?: string;\n\n /**\n * Label for tag value. Will be printed without a label if not specified.\n */\n tagName?: string;\n\n /**\n * Console object to use for logging (mostly for testing). Uses window.console by default.\n */\n console?: any;\n}\n\nexport interface LoggerCrashProps {\n error: Error;\n loggerName: string;\n tag?: string;\n tagName?: string;\n}\n\nlet levels: LogLevels = {\n info: \"development\",\n log: \"development\",\n warn: \"development\",\n error: true,\n};\nlet match: MatcherFunction = createMatcher(\"*,-dolla.*\");\nlet crashListeners: ((context: LoggerCrashProps) => void)[] = [];\nlet isCrashed = false;\n\n/**\n * Listen for logged crashes.\n */\nexport function onLoggerCrash(listener: (context: LoggerCrashProps) => void) {\n crashListeners.push(listener);\n\n return function cancel() {\n crashListeners.splice(crashListeners.indexOf(listener), 1);\n };\n}\n\nexport function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger {\n const _console = options?.console ?? _getDefaultConsole();\n\n const bind = (method: keyof LogLevels) => {\n let _name = untracked(name);\n if (levels[method] === false || (isString(levels[method]) && levels[method] !== getEnv()) || !match(_name)) {\n return noOp;\n } else {\n let label = `%c${_name}`;\n if (options?.tag) {\n if (options.tagName) {\n label += ` %c[${options.tagName}: %c${options.tag}%c]`;\n } else {\n label += ` %c[%c${options.tag}%c]`;\n }\n } else {\n label += `%c%c%c`;\n }\n return _console[method].bind(\n _console,\n label,\n `color:${okhash(label)};font-weight:bold`,\n `color:#777`,\n `color:#aaa`,\n `color:#777`,\n );\n }\n };\n\n return {\n get info() {\n return bind(\"info\");\n },\n get log() {\n return bind(\"log\");\n },\n get warn() {\n return bind(\"warn\");\n },\n get error() {\n return bind(\"error\");\n },\n crash(error: Error) {\n if (!isCrashed) {\n isCrashed = true;\n const ctx: LoggerCrashProps = {\n error,\n loggerName: get(name),\n tag: options?.tag,\n tagName: options?.tagName,\n };\n\n for (const listener of crashListeners) {\n listener(ctx);\n }\n\n throw error;\n }\n\n return error;\n },\n };\n}\n\nexport function setLogFilter(filter: string | RegExp) {\n match = createMatcher(filter);\n}\n\nexport function setLogLevels(options: Partial<LogLevels>) {\n for (const key in options) {\n const value = options[key as keyof LogLevels];\n if (value) {\n levels[key as keyof LogLevels] = value;\n }\n }\n}\n\nfunction _getDefaultConsole() {\n if (typeof window !== \"undefined\" && window.console) {\n return window.console;\n }\n if (typeof global !== \"undefined\" && global.console) {\n return global.console;\n }\n}\n"],"names":["currentEnv","getEnv","setEnv","value","levels","match","createMatcher","crashListeners","isCrashed","onLoggerCrash","listener","createLogger","name","options","_console","_getDefaultConsole","bind","method","_name","untracked","isString","noOp","label","okhash","error","ctx","get","setLogFilter","filter","setLogLevels","key"],"mappings":";;AAEA,IAAIA,IAAa;AAEV,SAASC,IAAS;AAChB,SAAAD;AACT;AAEO,SAASE,EAAOC,GAAY;AACpB,EAAAH,IAAAG;AACf;ACmCA,IAAIC,IAAoB;AAAA,EACtB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AACT,GACIC,IAAyBC,EAAc,YAAY,GACnDC,IAA0D,CAAC,GAC3DC,IAAY;AAKT,SAASC,EAAcC,GAA+C;AAC3E,SAAAH,EAAe,KAAKG,CAAQ,GAErB,WAAkB;AACvB,IAAAH,EAAe,OAAOA,EAAe,QAAQG,CAAQ,GAAG,CAAC;AAAA,EAC3D;AACF;AAEgB,SAAAC,EAAaC,GAA2BC,GAAiC;AACjF,QAAAC,KAAWD,KAAA,gBAAAA,EAAS,YAAWE,EAAmB,GAElDC,IAAO,CAACC,MAA4B;AACpC,QAAAC,IAAQC,EAAUP,CAAI;AAC1B,QAAIR,EAAOa,CAAM,MAAM,MAAUG,EAAShB,EAAOa,CAAM,CAAC,KAAKb,EAAOa,CAAM,MAAMhB,OAAa,CAACI,EAAMa,CAAK;AAChG,aAAAG;AACF;AACD,UAAAC,IAAQ,KAAKJ,CAAK;AACtB,aAAIL,KAAA,QAAAA,EAAS,MACPA,EAAQ,UACVS,KAAS,OAAOT,EAAQ,OAAO,OAAOA,EAAQ,GAAG,QAExCS,KAAA,SAAST,EAAQ,GAAG,QAGtBS,KAAA,UAEJR,EAASG,CAAM,EAAE;AAAA,QACtBH;AAAA,QACAQ;AAAA,QACA,SAASC,EAAOD,CAAK,CAAC;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ;AAEO,SAAA;AAAA,IACL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