@joewinke/jatui 0.1.28 → 0.1.29
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/LICENSE +21 -0
- package/dist/actions/collapse.js +15 -29
- package/dist/actions/listNav.js +108 -137
- package/dist/actions/railNav.js +72 -89
- package/dist/components/markup.js +59 -62
- package/dist/components/session-nav/transcriptModel.js +49 -66
- package/dist/data/emojis.js +4 -4
- package/dist/stores/confirmDialog.svelte.js +5 -5
- package/dist/stores/inputDialog.svelte.js +5 -5
- package/dist/types/booking.js +4 -4
- package/dist/types/comments.js +2 -2
- package/dist/types/messaging.js +3 -3
- package/dist/types/pipeline.js +2 -2
- package/dist/utils/currency.js +2 -4
- package/dist/utils/daisyuiColors.js +25 -27
- package/dist/utils/dateFormatters.js +44 -44
- package/dist/utils/googleMapsLoader.js +46 -100
- package/dist/utils/mentionParser.js +30 -30
- package/dist/utils/phone.js +21 -27
- package/dist/utils/phoneFormat.js +9 -9
- package/dist/utils/taskUtils.js +1 -1
- package/package.json +6 -4
|
@@ -22,17 +22,6 @@
|
|
|
22
22
|
* transcript shows just the headline by default and the body is
|
|
23
23
|
* a drill-down. This is what keeps the left column readable.
|
|
24
24
|
*/
|
|
25
|
-
var __assign = (this && this.__assign) || function () {
|
|
26
|
-
__assign = Object.assign || function(t) {
|
|
27
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
28
|
-
s = arguments[i];
|
|
29
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
30
|
-
t[p] = s[p];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
return __assign.apply(this, arguments);
|
|
35
|
-
};
|
|
36
25
|
export function rawTypeToState(raw) {
|
|
37
26
|
switch (raw) {
|
|
38
27
|
case 'needs_input':
|
|
@@ -48,28 +37,27 @@ export function rawTypeToState(raw) {
|
|
|
48
37
|
}
|
|
49
38
|
/** Detect a `jat-signal <type> '<json>'` invocation in a tool-call body. */
|
|
50
39
|
function parseSignalBody(body) {
|
|
51
|
-
|
|
40
|
+
const m = body.match(/jat-signal\s+(starting|working|needs_input|review|completing|complete|completed|paused|idle)\b/);
|
|
52
41
|
if (!m)
|
|
53
42
|
return null;
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
let label = '';
|
|
44
|
+
const pick = body.match(/"(?:approach|question|reviewFocus|currentStep|summary|reason|taskTitle)"\s*:\s*"([^"]{3,90})/);
|
|
56
45
|
if (pick)
|
|
57
46
|
label = pick[1];
|
|
58
|
-
return { rawType: m[1], label
|
|
47
|
+
return { rawType: m[1], label };
|
|
59
48
|
}
|
|
60
49
|
/** Build the linked model from rendered transcript lines. */
|
|
61
50
|
export function buildLinkedSession(lines) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
const items = [];
|
|
52
|
+
const emits = [];
|
|
53
|
+
let cur = null;
|
|
54
|
+
const flush = () => {
|
|
66
55
|
if (cur) {
|
|
67
|
-
items.push(
|
|
56
|
+
items.push({ id: items.length, ...cur, signalId: null });
|
|
68
57
|
cur = null;
|
|
69
58
|
}
|
|
70
59
|
};
|
|
71
|
-
for (
|
|
72
|
-
var line = lines_1[_i];
|
|
60
|
+
for (const line of lines) {
|
|
73
61
|
if (!line.trim()) {
|
|
74
62
|
flush();
|
|
75
63
|
continue;
|
|
@@ -80,8 +68,8 @@ export function buildLinkedSession(lines) {
|
|
|
80
68
|
continue;
|
|
81
69
|
}
|
|
82
70
|
if (line.startsWith('⏺ ')) {
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
const body = line.slice(2);
|
|
72
|
+
const sig = parseSignalBody(body);
|
|
85
73
|
if (sig) {
|
|
86
74
|
// signal emission = boundary; consume it, don't render as an item
|
|
87
75
|
flush();
|
|
@@ -93,7 +81,7 @@ export function buildLinkedSession(lines) {
|
|
|
93
81
|
continue;
|
|
94
82
|
}
|
|
95
83
|
if (line.startsWith(' ⎿ ')) {
|
|
96
|
-
|
|
84
|
+
const body = line.slice(4);
|
|
97
85
|
if (cur) {
|
|
98
86
|
cur.detail.push(body);
|
|
99
87
|
cur.srcLines++;
|
|
@@ -102,7 +90,7 @@ export function buildLinkedSession(lines) {
|
|
|
102
90
|
}
|
|
103
91
|
if (line.startsWith(' ')) {
|
|
104
92
|
// continuation: tool detail for actions, prose for prompt/assistant
|
|
105
|
-
|
|
93
|
+
const body = line.trimStart();
|
|
106
94
|
if (cur && cur.kind === 'action') {
|
|
107
95
|
cur.detail.push(body);
|
|
108
96
|
cur.srcLines++;
|
|
@@ -125,21 +113,21 @@ export function buildLinkedSession(lines) {
|
|
|
125
113
|
}
|
|
126
114
|
flush();
|
|
127
115
|
// Build signal nodes from emission boundaries.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
emits.forEach(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (
|
|
116
|
+
const signals = [];
|
|
117
|
+
let prevBoundary = -1;
|
|
118
|
+
emits.forEach((e, i) => {
|
|
119
|
+
const rowStart = Math.max(0, prevBoundary + 1);
|
|
120
|
+
const rowEnd = Math.max(rowStart, e.afterIdx);
|
|
121
|
+
let lineCount = 0;
|
|
122
|
+
for (let k = rowStart; k <= rowEnd && k < items.length; k++)
|
|
135
123
|
lineCount += items[k].srcLines;
|
|
136
124
|
signals.push({
|
|
137
|
-
id:
|
|
125
|
+
id: `sig-${i}`,
|
|
138
126
|
state: rawTypeToState(e.rawType),
|
|
139
127
|
rawType: e.rawType,
|
|
140
128
|
label: e.label,
|
|
141
|
-
rowStart
|
|
142
|
-
rowEnd
|
|
129
|
+
rowStart,
|
|
130
|
+
rowEnd,
|
|
143
131
|
lineCount: Math.max(1, lineCount),
|
|
144
132
|
// No WorkBlock substrate data in the raw-lines path
|
|
145
133
|
blockId: null,
|
|
@@ -151,13 +139,12 @@ export function buildLinkedSession(lines) {
|
|
|
151
139
|
});
|
|
152
140
|
prevBoundary = e.afterIdx;
|
|
153
141
|
});
|
|
154
|
-
for (
|
|
155
|
-
|
|
156
|
-
for (var k = sig.rowStart; k <= sig.rowEnd && k < items.length; k++) {
|
|
142
|
+
for (const sig of signals) {
|
|
143
|
+
for (let k = sig.rowStart; k <= sig.rowEnd && k < items.length; k++) {
|
|
157
144
|
items[k].signalId = sig.id;
|
|
158
145
|
}
|
|
159
146
|
}
|
|
160
|
-
return { items
|
|
147
|
+
return { items, signals };
|
|
161
148
|
}
|
|
162
149
|
/**
|
|
163
150
|
* Build a LinkedSession from the WorkBlock substrate (B1).
|
|
@@ -175,49 +162,45 @@ export function buildLinkedSession(lines) {
|
|
|
175
162
|
*/
|
|
176
163
|
export function buildLinkedSessionFromWork(blocks, items) {
|
|
177
164
|
// Map WorkTranscriptItem → TranscriptItem (blockId → signalId mapping happens after)
|
|
178
|
-
|
|
165
|
+
const transcriptItems = items.map((it) => ({
|
|
179
166
|
id: it.id,
|
|
180
167
|
kind: it.kind,
|
|
181
168
|
headline: it.headline,
|
|
182
169
|
detail: it.detail,
|
|
183
170
|
srcLines: it.srcLines,
|
|
184
171
|
signalId: null // filled in below
|
|
185
|
-
})
|
|
172
|
+
}));
|
|
186
173
|
// Map WorkBlock → SignalNode
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
linesRemoved: (_c = blk.linesRemoved) !== null && _c !== void 0 ? _c : 0
|
|
204
|
-
});
|
|
205
|
-
});
|
|
174
|
+
const signals = blocks.map((blk) => ({
|
|
175
|
+
id: blk.id,
|
|
176
|
+
state: rawTypeToState(blk.signal.type),
|
|
177
|
+
rawType: blk.signal.type,
|
|
178
|
+
label: blk.signal.label,
|
|
179
|
+
rowStart: blk.itemRange.start,
|
|
180
|
+
rowEnd: blk.itemRange.end,
|
|
181
|
+
lineCount: blk.lineCount,
|
|
182
|
+
// WorkBlock substrate fields
|
|
183
|
+
blockId: blk.id,
|
|
184
|
+
summary: blk.summary,
|
|
185
|
+
filesTouched: blk.filesTouched,
|
|
186
|
+
commits: blk.commits ?? [],
|
|
187
|
+
linesAdded: blk.linesAdded ?? 0,
|
|
188
|
+
linesRemoved: blk.linesRemoved ?? 0
|
|
189
|
+
}));
|
|
206
190
|
// Assign signalId to transcript items via block ownership
|
|
207
|
-
for (
|
|
208
|
-
|
|
209
|
-
for (var k = sig.rowStart; k <= sig.rowEnd && k < transcriptItems.length; k++) {
|
|
191
|
+
for (const sig of signals) {
|
|
192
|
+
for (let k = sig.rowStart; k <= sig.rowEnd && k < transcriptItems.length; k++) {
|
|
210
193
|
transcriptItems[k].signalId = sig.id;
|
|
211
194
|
}
|
|
212
195
|
}
|
|
213
|
-
return { items: transcriptItems, signals
|
|
196
|
+
return { items: transcriptItems, signals };
|
|
214
197
|
}
|
|
215
198
|
/**
|
|
216
199
|
* A baked, realistic sample so /sankey always demos beautifully even with no live
|
|
217
200
|
* session. Authored as raw transcript lines with real `jat-signal` calls, so it
|
|
218
201
|
* flows through the EXACT same parser as live data.
|
|
219
202
|
*/
|
|
220
|
-
export
|
|
203
|
+
export const SAMPLE_TRANSCRIPT_LINES = [
|
|
221
204
|
'',
|
|
222
205
|
'› /jat:start GentleCoast jat-7h2k',
|
|
223
206
|
'⏺ Bash(get-current-session-id)',
|
package/dist/data/emojis.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Each emoji has a character and searchable name.
|
|
4
4
|
* Based on Unicode CLDR emoji ordering, minus most flags.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export const EMOJI_DATA = [
|
|
7
7
|
{
|
|
8
8
|
label: 'Smileys & Emotion',
|
|
9
9
|
emojis: [
|
|
@@ -1186,11 +1186,11 @@ export var EMOJI_DATA = [
|
|
|
1186
1186
|
},
|
|
1187
1187
|
];
|
|
1188
1188
|
/** Flat array of all emojis for search */
|
|
1189
|
-
export
|
|
1189
|
+
export const ALL_EMOJIS = EMOJI_DATA.flatMap((g) => g.emojis);
|
|
1190
1190
|
/** Search emojis by name, returns matching entries */
|
|
1191
1191
|
export function searchEmojis(query) {
|
|
1192
1192
|
if (!query.trim())
|
|
1193
1193
|
return [];
|
|
1194
|
-
|
|
1195
|
-
return ALL_EMOJIS.filter(
|
|
1194
|
+
const terms = query.toLowerCase().split(/\s+/);
|
|
1195
|
+
return ALL_EMOJIS.filter((e) => terms.every((t) => e.name.includes(t)));
|
|
1196
1196
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Global promise-based confirm dialog.
|
|
3
3
|
* Usage: const ok = await showConfirm({ title: '...', body: '...' })
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
let pending = $state(null);
|
|
6
6
|
export function getPending() {
|
|
7
7
|
return pending;
|
|
8
8
|
}
|
|
@@ -11,21 +11,21 @@ export function showConfirm(options) {
|
|
|
11
11
|
if (pending) {
|
|
12
12
|
pending.resolve(false);
|
|
13
13
|
}
|
|
14
|
-
return new Promise(
|
|
15
|
-
pending = { options
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
pending = { options, resolve };
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
export function confirmDialog() {
|
|
19
19
|
if (!pending)
|
|
20
20
|
return;
|
|
21
|
-
|
|
21
|
+
const p = pending;
|
|
22
22
|
pending = null;
|
|
23
23
|
p.resolve(true);
|
|
24
24
|
}
|
|
25
25
|
export function cancelDialog() {
|
|
26
26
|
if (!pending)
|
|
27
27
|
return;
|
|
28
|
-
|
|
28
|
+
const p = pending;
|
|
29
29
|
pending = null;
|
|
30
30
|
p.resolve(false);
|
|
31
31
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Usage: const value = await showInput({ title: '...', placeholder: '...' })
|
|
4
4
|
* Returns the typed string if confirmed, null if cancelled.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
let pending = $state(null);
|
|
7
7
|
export function getPendingInput() {
|
|
8
8
|
return pending;
|
|
9
9
|
}
|
|
@@ -12,21 +12,21 @@ export function showInput(options) {
|
|
|
12
12
|
if (pending) {
|
|
13
13
|
pending.resolve(null);
|
|
14
14
|
}
|
|
15
|
-
return new Promise(
|
|
16
|
-
pending = { options
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
pending = { options, resolve };
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
export function submitInput(value) {
|
|
20
20
|
if (!pending)
|
|
21
21
|
return;
|
|
22
|
-
|
|
22
|
+
const p = pending;
|
|
23
23
|
pending = null;
|
|
24
24
|
p.resolve(value);
|
|
25
25
|
}
|
|
26
26
|
export function cancelInput() {
|
|
27
27
|
if (!pending)
|
|
28
28
|
return;
|
|
29
|
-
|
|
29
|
+
const p = pending;
|
|
30
30
|
pending = null;
|
|
31
31
|
p.resolve(null);
|
|
32
32
|
}
|
package/dist/types/booking.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Booking System Types
|
|
2
2
|
// Generic types for scheduling/booking UI components
|
|
3
3
|
// Day of week helpers
|
|
4
|
-
export
|
|
4
|
+
export const DAYS_OF_WEEK = [
|
|
5
5
|
'Sunday',
|
|
6
6
|
'Monday',
|
|
7
7
|
'Tuesday',
|
|
@@ -10,14 +10,14 @@ export var DAYS_OF_WEEK = [
|
|
|
10
10
|
'Friday',
|
|
11
11
|
'Saturday'
|
|
12
12
|
];
|
|
13
|
-
export
|
|
13
|
+
export const DAYS_SHORT = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
14
14
|
// Location type display
|
|
15
|
-
export
|
|
15
|
+
export const LOCATION_LABELS = {
|
|
16
16
|
remote: 'Video Call',
|
|
17
17
|
phone: 'Phone Call',
|
|
18
18
|
in_person: 'In Person'
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export const LOCATION_ICONS = {
|
|
21
21
|
remote: 'video',
|
|
22
22
|
phone: 'phone',
|
|
23
23
|
in_person: 'map-pin'
|
package/dist/types/comments.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// Threading is ONE level deep on the data side: a comment is either
|
|
7
7
|
// top-level (`parent_id === null`) or a single-level reply. The UI renders
|
|
8
8
|
// this as two visual levels (a comment and its replies).
|
|
9
|
-
export
|
|
9
|
+
export const COMMENT_ENTITY_TYPES = [
|
|
10
10
|
'project',
|
|
11
11
|
'invoice',
|
|
12
12
|
'contract',
|
|
@@ -16,7 +16,7 @@ export var COMMENT_ENTITY_TYPES = [
|
|
|
16
16
|
'milestone',
|
|
17
17
|
'contract_term'
|
|
18
18
|
];
|
|
19
|
-
export
|
|
19
|
+
export const COMMENT_VISIBILITIES = [
|
|
20
20
|
'internal',
|
|
21
21
|
'client'
|
|
22
22
|
];
|
package/dist/types/messaging.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Messaging System Types
|
|
2
2
|
// Generic types for messaging UI components — no framework or backend dependencies
|
|
3
3
|
// ─── Emoji Data Constants ─────────────────────────────────────────────
|
|
4
|
-
export
|
|
4
|
+
export const EMOJI_CATEGORIES = [
|
|
5
5
|
{ id: 'search', name: 'Search', icon: '🔍', description: 'Search results' },
|
|
6
6
|
{
|
|
7
7
|
id: 'frequently_used',
|
|
@@ -59,7 +59,7 @@ export var EMOJI_CATEGORIES = [
|
|
|
59
59
|
description: 'Organization custom emojis'
|
|
60
60
|
}
|
|
61
61
|
];
|
|
62
|
-
export
|
|
62
|
+
export const SKIN_TONES = [
|
|
63
63
|
{ id: 'default', name: 'Default', unicode: '', preview: '👋' },
|
|
64
64
|
{ id: 'light', name: 'Light', unicode: '🏻', preview: '👋🏻' },
|
|
65
65
|
{ id: 'medium-light', name: 'Medium Light', unicode: '🏼', preview: '👋🏼' },
|
|
@@ -68,7 +68,7 @@ export var SKIN_TONES = [
|
|
|
68
68
|
{ id: 'dark', name: 'Dark', unicode: '🏿', preview: '👋🏿' }
|
|
69
69
|
];
|
|
70
70
|
// Default quick-reaction emojis (used when no user preferences available)
|
|
71
|
-
export
|
|
71
|
+
export const DEFAULT_QUICK_REACTIONS = [
|
|
72
72
|
{
|
|
73
73
|
unicode: '👍',
|
|
74
74
|
name: 'Thumbs Up',
|
package/dist/types/pipeline.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// ─── Core Stage/Column Types ───
|
|
2
2
|
// ─── Defaults ───
|
|
3
|
-
export
|
|
3
|
+
export const DEFAULT_DRAG_CONFIG = {
|
|
4
4
|
enabled: true,
|
|
5
5
|
flipDurationMs: 200,
|
|
6
6
|
dropTargetClass: 'outline-dashed outline-2 outline-base-content/20'
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export const DEFAULT_PIPELINE_CONFIG = {
|
|
9
9
|
views: ['kanban'],
|
|
10
10
|
defaultView: 'kanban',
|
|
11
11
|
drag: DEFAULT_DRAG_CONFIG,
|
package/dist/utils/currency.js
CHANGED
|
@@ -5,12 +5,10 @@
|
|
|
5
5
|
* Format a number as USD currency string.
|
|
6
6
|
* Override locale/currency by passing options.
|
|
7
7
|
*/
|
|
8
|
-
export function formatCurrency(amount, locale, currency) {
|
|
9
|
-
if (locale === void 0) { locale = 'en-US'; }
|
|
10
|
-
if (currency === void 0) { currency = 'USD'; }
|
|
8
|
+
export function formatCurrency(amount, locale = 'en-US', currency = 'USD') {
|
|
11
9
|
return new Intl.NumberFormat(locale, {
|
|
12
10
|
style: 'currency',
|
|
13
|
-
currency
|
|
11
|
+
currency,
|
|
14
12
|
minimumFractionDigits: 2,
|
|
15
13
|
maximumFractionDigits: 2
|
|
16
14
|
}).format(amount);
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* Reads --color-* custom properties at runtime so any custom DaisyUI theme
|
|
5
5
|
* works correctly. SSR-safe: falls back to transparent/black when window is absent.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let colorCache = new Map();
|
|
8
|
+
let themeObserver = null;
|
|
9
9
|
function resolveViaDOM(colorName) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const el = document.documentElement;
|
|
11
|
+
const raw = getComputedStyle(el).getPropertyValue(`--color-${colorName}`).trim();
|
|
12
12
|
if (raw)
|
|
13
13
|
return raw;
|
|
14
14
|
// DaisyUI v4 used shortened oklch channel vars (e.g. --p); try that form
|
|
15
|
-
|
|
15
|
+
const shortMap = {
|
|
16
16
|
primary: '--p',
|
|
17
17
|
'primary-content': '--pc',
|
|
18
18
|
secondary: '--s',
|
|
@@ -34,11 +34,11 @@ function resolveViaDOM(colorName) {
|
|
|
34
34
|
error: '--er',
|
|
35
35
|
'error-content': '--erc',
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
const shortVar = shortMap[colorName];
|
|
38
38
|
if (shortVar) {
|
|
39
|
-
|
|
39
|
+
const shortRaw = getComputedStyle(el).getPropertyValue(shortVar).trim();
|
|
40
40
|
if (shortRaw)
|
|
41
|
-
return
|
|
41
|
+
return `oklch(${shortRaw})`;
|
|
42
42
|
}
|
|
43
43
|
return 'oklch(0.5 0 0)';
|
|
44
44
|
}
|
|
@@ -52,25 +52,23 @@ export function getDaisyUIColor(colorName) {
|
|
|
52
52
|
if (colorCache.has(colorName)) {
|
|
53
53
|
return colorCache.get(colorName);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
const resolved = resolveViaDOM(colorName);
|
|
56
56
|
colorCache.set(colorName, resolved);
|
|
57
57
|
return resolved;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Create a lighter version of a color using color-mix (works with hex and oklch).
|
|
61
61
|
*/
|
|
62
|
-
export function lightenColor(color, amount) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return "color-mix(in oklch, white ".concat(pct, "%, ").concat(color, ")");
|
|
62
|
+
export function lightenColor(color, amount = 0.2) {
|
|
63
|
+
const pct = Math.round(amount * 100);
|
|
64
|
+
return `color-mix(in oklch, white ${pct}%, ${color})`;
|
|
66
65
|
}
|
|
67
66
|
/**
|
|
68
67
|
* Create a darker version of a color using color-mix.
|
|
69
68
|
*/
|
|
70
|
-
export function darkenColor(color, amount) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return "color-mix(in oklch, black ".concat(pct, "%, ").concat(color, ")");
|
|
69
|
+
export function darkenColor(color, amount = 0.2) {
|
|
70
|
+
const pct = Math.round(amount * 100);
|
|
71
|
+
return `color-mix(in oklch, black ${pct}%, ${color})`;
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
74
|
* Setup theme change detection.
|
|
@@ -80,9 +78,9 @@ export function watchThemeChanges(onThemeChange) {
|
|
|
80
78
|
if (themeObserver) {
|
|
81
79
|
themeObserver.disconnect();
|
|
82
80
|
}
|
|
83
|
-
themeObserver = new MutationObserver(
|
|
84
|
-
|
|
85
|
-
mutations.forEach(
|
|
81
|
+
themeObserver = new MutationObserver((mutations) => {
|
|
82
|
+
let themeChanged = false;
|
|
83
|
+
mutations.forEach((mutation) => {
|
|
86
84
|
if (mutation.type === 'attributes' &&
|
|
87
85
|
(mutation.attributeName === 'data-theme' ||
|
|
88
86
|
mutation.attributeName === 'class')) {
|
|
@@ -100,7 +98,7 @@ export function watchThemeChanges(onThemeChange) {
|
|
|
100
98
|
attributes: true,
|
|
101
99
|
attributeFilter: ['data-theme', 'class'],
|
|
102
100
|
});
|
|
103
|
-
return
|
|
101
|
+
return () => {
|
|
104
102
|
if (themeObserver) {
|
|
105
103
|
themeObserver.disconnect();
|
|
106
104
|
themeObserver = null;
|
|
@@ -114,25 +112,25 @@ export function watchThemeChanges(onThemeChange) {
|
|
|
114
112
|
export function isDarkTheme() {
|
|
115
113
|
if (typeof window === 'undefined')
|
|
116
114
|
return false;
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
const baseContent = getDaisyUIColor('base-content');
|
|
116
|
+
const base100 = getDaisyUIColor('base-100');
|
|
119
117
|
return getLuminance(baseContent) > getLuminance(base100);
|
|
120
118
|
}
|
|
121
119
|
function getLuminance(color) {
|
|
122
120
|
// Resolve via a temporary off-screen canvas pixel
|
|
123
|
-
|
|
121
|
+
const canvas = document.createElement('canvas');
|
|
124
122
|
canvas.width = 1;
|
|
125
123
|
canvas.height = 1;
|
|
126
|
-
|
|
124
|
+
const ctx = canvas.getContext('2d');
|
|
127
125
|
if (!ctx)
|
|
128
126
|
return 0.5;
|
|
129
127
|
try {
|
|
130
128
|
ctx.fillStyle = color;
|
|
131
129
|
ctx.fillRect(0, 0, 1, 1);
|
|
132
|
-
|
|
130
|
+
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
|
|
133
131
|
return (r * 299 + g * 587 + b * 114) / (1000 * 255);
|
|
134
132
|
}
|
|
135
|
-
catch
|
|
133
|
+
catch {
|
|
136
134
|
return 0.5;
|
|
137
135
|
}
|
|
138
136
|
}
|