@ug666/ui-core 0.3.0-beta.1 → 0.3.0-beta.2

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 (49) hide show
  1. package/dist/THIRD_PARTY_NOTICES.txt +98 -0
  2. package/dist/calendar.d.ts +26 -0
  3. package/dist/calendar.d.ts.map +1 -0
  4. package/dist/chunk-5S74COKZ.js +256 -0
  5. package/dist/chunk-5S74COKZ.js.map +1 -0
  6. package/dist/color.d.ts +17 -0
  7. package/dist/color.d.ts.map +1 -0
  8. package/dist/date-picker-modes.d.ts +16 -0
  9. package/dist/date-picker-modes.d.ts.map +1 -0
  10. package/dist/date-range.d.ts +9 -0
  11. package/dist/date-range.d.ts.map +1 -0
  12. package/dist/date-time.d.ts +43 -0
  13. package/dist/date-time.d.ts.map +1 -0
  14. package/dist/form-state.d.ts +30 -0
  15. package/dist/form-state.d.ts.map +1 -0
  16. package/dist/form-validation.d.ts +2 -1
  17. package/dist/form-validation.d.ts.map +1 -1
  18. package/dist/image-preview.d.ts +8 -0
  19. package/dist/image-preview.d.ts.map +1 -0
  20. package/dist/index.cjs +1061 -2
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +15 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +790 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/rating.d.ts +6 -0
  27. package/dist/rating.d.ts.map +1 -0
  28. package/dist/selection-list.d.ts +31 -0
  29. package/dist/selection-list.d.ts.map +1 -0
  30. package/dist/table-layout.d.ts +20 -0
  31. package/dist/table-layout.d.ts.map +1 -0
  32. package/dist/table-structure.d.ts +29 -0
  33. package/dist/table-structure.d.ts.map +1 -0
  34. package/dist/theme.cjs +231 -2
  35. package/dist/theme.cjs.map +1 -1
  36. package/dist/theme.d.ts +47 -0
  37. package/dist/theme.d.ts.map +1 -1
  38. package/dist/theme.js +22 -3
  39. package/dist/tree-check.d.ts +23 -0
  40. package/dist/tree-check.d.ts.map +1 -0
  41. package/dist/tree-drag.d.ts +8 -0
  42. package/dist/tree-drag.d.ts.map +1 -0
  43. package/dist/tree-path.d.ts +29 -0
  44. package/dist/tree-path.d.ts.map +1 -0
  45. package/dist/tree-table.d.ts +21 -0
  46. package/dist/tree-table.d.ts.map +1 -0
  47. package/package.json +3 -3
  48. package/dist/chunk-S4DT6FOD.js +0 -35
  49. package/dist/chunk-S4DT6FOD.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use client"
1
2
  "use strict";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,18 +21,188 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
21
  // src/index.ts
21
22
  var index_exports = {};
22
23
  __export(index_exports, {
24
+ addCalendarDays: () => addCalendarDays,
25
+ addCalendarMonths: () => addCalendarMonths,
26
+ applyUGThemeProfile: () => applyUGThemeProfile,
27
+ buildCalendarMonth: () => buildCalendarMonth,
28
+ buildCalendarWeekdays: () => buildCalendarWeekdays,
29
+ buildTimeSelectOptions: () => buildTimeSelectOptions,
30
+ calendarDateKey: () => calendarDateKey,
31
+ canDropTreeNode: () => canDropTreeNode,
32
+ compareCalendarDates: () => compareCalendarDates,
23
33
  countTextCharacters: () => countTextCharacters,
34
+ createFormFieldArray: () => createFormFieldArray,
24
35
  createUGThemeValue: () => createUGThemeValue,
36
+ datePickerModeKey: () => datePickerModeKey,
37
+ defaultUGNavigationColors: () => defaultUGNavigationColors,
25
38
  defaultUGTheme: () => defaultUGTheme,
39
+ defaultUGThemeConfiguratorOptions: () => defaultUGThemeConfiguratorOptions,
40
+ defaultUGThemeNavigationColors: () => defaultUGThemeNavigationColors,
41
+ defaultUGThemeProfiles: () => defaultUGThemeProfiles,
26
42
  encodeSelectValue: () => encodeSelectValue,
43
+ filterSelectionListOptions: () => filterSelectionListOptions,
44
+ findTreeNodePath: () => findTreeNodePath,
45
+ formatCalendarDay: () => formatCalendarDay,
46
+ formatCalendarMonth: () => formatCalendarMonth,
47
+ formatColorHex: () => formatColorHex,
48
+ formatTimeValue: () => formatTimeValue,
49
+ getAvailableTimeValues: () => getAvailableTimeValues,
50
+ getCalendarRangePosition: () => getCalendarRangePosition,
51
+ getFormPath: () => getFormPath,
52
+ getFormPaths: () => getFormPaths,
53
+ getImagePreviewLayout: () => getImagePreviewLayout,
54
+ getRatingKeyboardValue: () => getRatingKeyboardValue,
55
+ getSelectionListScope: () => getSelectionListScope,
56
+ getTableColumnFixed: () => getTableColumnFixed,
57
+ getTableColumnStyle: () => getTableColumnStyle,
58
+ getTableSpanGrid: () => getTableSpanGrid,
59
+ getTableStructure: () => getTableStructure,
60
+ getTimeColumnChoices: () => getTimeColumnChoices,
61
+ getTreeCheckState: () => getTreeCheckState,
62
+ groupSelectionListOptions: () => groupSelectionListOptions,
27
63
  isEmptyFormValue: () => isEmptyFormValue,
64
+ isFormPathActive: () => isFormPathActive,
65
+ isFormPathWithin: () => isFormPathWithin,
66
+ isFormValueEqual: () => isFormValueEqual,
67
+ isSameCalendarDay: () => isSameCalendarDay,
68
+ isUGThemeProfileModified: () => isUGThemeProfileModified,
69
+ isValidCalendarDate: () => isValidCalendarDate,
70
+ isoWeekStart: () => isoWeekStart,
28
71
  limitTextByCount: () => limitTextByCount,
72
+ localDateTimeKey: () => localDateTimeKey,
73
+ moveTableColumn: () => moveTableColumn,
74
+ normalizeCalendarDate: () => normalizeCalendarDate,
75
+ normalizeFormPath: () => normalizeFormPath,
76
+ normalizeRatingMax: () => normalizeRatingMax,
77
+ normalizeRatingValue: () => normalizeRatingValue,
29
78
  normalizeSelectKeys: () => normalizeSelectKeys,
30
- validateFormValue: () => validateFormValue
79
+ parseCalendarDateKey: () => parseCalendarDateKey,
80
+ parseCalendarRange: () => parseCalendarRange,
81
+ parseColorHex: () => parseColorHex,
82
+ parseDatePickerModeKey: () => parseDatePickerModeKey,
83
+ parseLocalDateTimeValue: () => parseLocalDateTimeValue,
84
+ parseTimeValue: () => parseTimeValue,
85
+ projectTreeTableRows: () => projectTreeTableRows,
86
+ resolveTableFixedColumns: () => resolveTableFixedColumns,
87
+ resolveUGNavigationColors: () => resolveUGNavigationColors,
88
+ resolveUGNavigationPalette: () => resolveUGNavigationPalette,
89
+ setFormPath: () => setFormPath,
90
+ startOfCalendarMonth: () => startOfCalendarMonth,
91
+ tableColumnLength: () => tableColumnLength,
92
+ toggleTreeCheckedKey: () => toggleTreeCheckedKey,
93
+ ugThemeProfileFields: () => ugThemeProfileFields,
94
+ updateSelectionListScope: () => updateSelectionListScope,
95
+ validateDatePickerModeValue: () => validateDatePickerModeValue,
96
+ validateDateRangeShortcut: () => validateDateRangeShortcut,
97
+ validateDateTimeRangeValue: () => validateDateTimeRangeValue,
98
+ validateDateTimeValue: () => validateDateTimeValue,
99
+ validateDateValue: () => validateDateValue,
100
+ validateFormValue: () => validateFormValue,
101
+ validateTimeRangeValue: () => validateTimeRangeValue,
102
+ validateTimeValue: () => validateTimeValue
31
103
  });
32
104
  module.exports = __toCommonJS(index_exports);
33
105
 
34
106
  // src/theme.ts
107
+ var defaultUGThemeNavigationColors = {
108
+ default: {
109
+ light: {
110
+ background: "#ffffff",
111
+ text: "#475569",
112
+ activeBackground: "#ecf5ff",
113
+ activeText: "#1d4ed8",
114
+ hoverBackground: "#f1f5f9"
115
+ },
116
+ dark: {
117
+ background: "#151c28",
118
+ text: "#cbd5e1",
119
+ activeBackground: "#3178c2",
120
+ activeText: "#ffffff",
121
+ hoverBackground: "#293442"
122
+ }
123
+ },
124
+ minimal: {
125
+ light: {
126
+ background: "#ffffff",
127
+ text: "#334155",
128
+ activeBackground: "#e0f2fe",
129
+ activeText: "#0369a1",
130
+ hoverBackground: "#f8fafc"
131
+ },
132
+ dark: {
133
+ background: "#111827",
134
+ text: "#d1d5db",
135
+ activeBackground: "#164e63",
136
+ activeText: "#ecfeff",
137
+ hoverBackground: "#1f2937"
138
+ }
139
+ },
140
+ mecha: {
141
+ light: {
142
+ background: "#eef2f6",
143
+ text: "#334155",
144
+ activeBackground: "#cffafe",
145
+ activeText: "#0e7490",
146
+ hoverBackground: "#e2e8f0"
147
+ },
148
+ dark: {
149
+ background: "#0b1220",
150
+ text: "#cbd5e1",
151
+ activeBackground: "#155e75",
152
+ activeText: "#ecfeff",
153
+ hoverBackground: "#172033"
154
+ }
155
+ }
156
+ };
157
+ var defaultUGNavigationColors = defaultUGThemeNavigationColors.default;
158
+ function resolveUGNavigationPalette(mode, prefersDark = false) {
159
+ if (mode === "dark") return "dark";
160
+ if (mode === "light") return "light";
161
+ return prefersDark ? "dark" : "light";
162
+ }
163
+ var defaultUGAccentNavigationColors = {
164
+ cyan: {
165
+ light: { activeBackground: "#cffafe", activeText: "#0e7490" },
166
+ dark: { activeBackground: "#0e7490", activeText: "#ecfeff" }
167
+ },
168
+ blue: {
169
+ light: { activeBackground: "#dbeafe", activeText: "#1d4ed8" },
170
+ dark: { activeBackground: "#1d4ed8", activeText: "#eff6ff" }
171
+ },
172
+ violet: {
173
+ light: { activeBackground: "#ede9fe", activeText: "#6d28d9" },
174
+ dark: { activeBackground: "#6d28d9", activeText: "#f5f3ff" }
175
+ },
176
+ emerald: {
177
+ light: { activeBackground: "#d1fae5", activeText: "#047857" },
178
+ dark: { activeBackground: "#047857", activeText: "#ecfdf5" }
179
+ },
180
+ rose: {
181
+ light: { activeBackground: "#ffe4e6", activeText: "#be123c" },
182
+ dark: { activeBackground: "#be123c", activeText: "#fff1f2" }
183
+ }
184
+ };
185
+ function resolveUGNavigationColors(preset, palette, overrides, accent = "theme") {
186
+ if (overrides) return overrides;
187
+ const themeColors = preset in defaultUGThemeNavigationColors ? defaultUGThemeNavigationColors[preset] : defaultUGThemeNavigationColors.default;
188
+ const resolvedColors = themeColors[palette];
189
+ if (accent in defaultUGAccentNavigationColors) {
190
+ return {
191
+ ...resolvedColors,
192
+ ...defaultUGAccentNavigationColors[accent][palette]
193
+ };
194
+ }
195
+ return resolvedColors;
196
+ }
197
+ var ugThemeProfileFields = [
198
+ "density",
199
+ "radius",
200
+ "shadow",
201
+ "font",
202
+ "contrast",
203
+ "motion",
204
+ "background"
205
+ ];
35
206
  var defaultUGTheme = {
36
207
  preset: "default",
37
208
  mode: "system",
@@ -45,6 +216,111 @@ var defaultUGTheme = {
45
216
  background: "grid",
46
217
  accent: "theme"
47
218
  };
219
+ var defaultUGThemeProfiles = [
220
+ {
221
+ id: "balanced",
222
+ label: "\u5747\u8861",
223
+ description: "\u8212\u9002\u3001\u6E05\u6670\uFF0C\u9002\u5408\u65E5\u5E38\u901A\u7528\u64CD\u4F5C\u3002",
224
+ value: {
225
+ density: "comfortable",
226
+ radius: "default",
227
+ shadow: "standard",
228
+ font: "system",
229
+ contrast: "standard",
230
+ motion: "standard",
231
+ background: "plain"
232
+ }
233
+ },
234
+ {
235
+ id: "efficient",
236
+ label: "\u9AD8\u6548",
237
+ description: "\u7D27\u51D1\u3001\u5229\u843D\uFF0C\u9002\u5408\u9AD8\u9891\u64CD\u4F5C\u548C\u6570\u636E\u5DE5\u4F5C\u3002",
238
+ value: {
239
+ density: "compact",
240
+ radius: "sharp",
241
+ shadow: "flat",
242
+ font: "compact",
243
+ contrast: "strong",
244
+ motion: "reduced",
245
+ background: "plain"
246
+ }
247
+ },
248
+ {
249
+ id: "readable",
250
+ label: "\u6613\u8BFB",
251
+ description: "\u5BBD\u677E\u3001\u6E05\u6670\uFF0C\u9002\u5408\u957F\u65F6\u95F4\u9605\u8BFB\u548C\u4F4E\u523A\u6FC0\u64CD\u4F5C\u3002",
252
+ value: {
253
+ density: "spacious",
254
+ radius: "soft",
255
+ shadow: "standard",
256
+ font: "readable",
257
+ contrast: "strong",
258
+ motion: "reduced",
259
+ background: "plain"
260
+ }
261
+ }
262
+ ];
263
+ var defaultUGThemeConfiguratorOptions = {
264
+ presets: [
265
+ { value: "default", label: "\u9ED8\u8BA4", description: "\u5747\u8861\u7684\u8FB9\u754C\u3001\u5C42\u6B21\u4E0E\u4FE1\u606F\u5BC6\u5EA6\u3002" },
266
+ { value: "minimal", label: "\u7B80\u6D01", description: "\u51CF\u5C11\u88C5\u9970\uFF0C\u8BA9\u5185\u5BB9\u6210\u4E3A\u89C6\u89C9\u4E2D\u5FC3\u3002" },
267
+ { value: "mecha", label: "\u673A\u68B0", description: "\u786C\u6717\u8FB9\u754C\u4E0E\u7D27\u51D1\u7684\u63A7\u5236\u53F0\u8282\u594F\u3002" }
268
+ ],
269
+ modes: [
270
+ { value: "system", label: "\u8DDF\u968F\u7CFB\u7EDF", description: "\u81EA\u52A8\u5339\u914D\u8BBE\u5907\u5916\u89C2\u3002" },
271
+ { value: "light", label: "\u4EAE\u8272", description: "\u59CB\u7EC8\u4F7F\u7528\u4EAE\u8272\u754C\u9762\u3002" },
272
+ { value: "dark", label: "\u6697\u8272", description: "\u59CB\u7EC8\u4F7F\u7528\u6697\u8272\u754C\u9762\u3002" }
273
+ ],
274
+ surfaces: [
275
+ { value: "workspace", label: "\u5DE5\u4F5C\u533A" },
276
+ { value: "showcase", label: "\u5C55\u793A\u9875" },
277
+ { value: "auth", label: "\u8BA4\u8BC1\u9875" },
278
+ { value: "content", label: "\u5185\u5BB9\u9875" }
279
+ ],
280
+ densities: [
281
+ { value: "comfortable", label: "\u8212\u9002" },
282
+ { value: "compact", label: "\u7D27\u51D1" },
283
+ { value: "spacious", label: "\u5BBD\u677E" }
284
+ ],
285
+ radii: [
286
+ { value: "sharp", label: "\u5229\u843D" },
287
+ { value: "default", label: "\u9ED8\u8BA4" },
288
+ { value: "soft", label: "\u67D4\u548C" }
289
+ ],
290
+ shadows: [
291
+ { value: "flat", label: "\u5E73\u9762" },
292
+ { value: "standard", label: "\u6807\u51C6" },
293
+ { value: "layered", label: "\u5C42\u6B21" }
294
+ ],
295
+ fonts: [
296
+ { value: "system", label: "\u7CFB\u7EDF" },
297
+ { value: "readable", label: "\u6613\u8BFB" },
298
+ { value: "compact", label: "\u7D27\u51D1" }
299
+ ],
300
+ contrasts: [
301
+ { value: "soft", label: "\u67D4\u548C" },
302
+ { value: "standard", label: "\u6807\u51C6" },
303
+ { value: "strong", label: "\u6E05\u6670" }
304
+ ],
305
+ motions: [
306
+ { value: "reduced", label: "\u51CF\u5C11" },
307
+ { value: "standard", label: "\u6807\u51C6" },
308
+ { value: "lively", label: "\u7075\u52A8" }
309
+ ],
310
+ backgrounds: [
311
+ { value: "plain", label: "\u7EAF\u51C0" },
312
+ { value: "grid", label: "\u7F51\u683C" },
313
+ { value: "soft", label: "\u67D4\u5149" }
314
+ ],
315
+ accents: [
316
+ { value: "theme", label: "\u4E3B\u9898\u9ED8\u8BA4" },
317
+ { value: "cyan", label: "UG \u9752" },
318
+ { value: "blue", label: "\u6D77\u84DD" },
319
+ { value: "violet", label: "\u7D2B\u6676" },
320
+ { value: "emerald", label: "\u677E\u7EFF" },
321
+ { value: "rose", label: "\u73AB\u7EA2" }
322
+ ]
323
+ };
48
324
  function createUGThemeValue(parent, overrides) {
49
325
  return {
50
326
  preset: overrides.preset ?? parent.preset,
@@ -60,12 +336,19 @@ function createUGThemeValue(parent, overrides) {
60
336
  accent: overrides.accent ?? parent.accent
61
337
  };
62
338
  }
339
+ function applyUGThemeProfile(current, profile) {
340
+ return createUGThemeValue(current, profile.value);
341
+ }
342
+ function isUGThemeProfileModified(current, profile) {
343
+ return ugThemeProfileFields.some((field) => current[field] !== profile.value[field]);
344
+ }
63
345
 
64
346
  // src/form-validation.ts
65
347
  function isEmptyFormValue(value) {
66
348
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
67
349
  }
68
350
  function hasTrigger(rule, trigger) {
351
+ if (trigger === "submit") return true;
69
352
  if (!rule.trigger) return true;
70
353
  return Array.isArray(rule.trigger) ? rule.trigger.includes(trigger) : rule.trigger === trigger;
71
354
  }
@@ -167,15 +450,791 @@ function limitTextByCount(value, maxLength, counter) {
167
450
  }
168
451
  return characters.slice(0, low).join("");
169
452
  }
453
+
454
+ // src/calendar.ts
455
+ function isValidCalendarDate(value) {
456
+ return value instanceof Date && Number.isFinite(value.getTime());
457
+ }
458
+ function normalizeCalendarDate(value, fallback = /* @__PURE__ */ new Date()) {
459
+ const source = isValidCalendarDate(value) ? value : fallback;
460
+ return localCalendarDate(source.getFullYear(), source.getMonth(), source.getDate());
461
+ }
462
+ function localCalendarDate(year, month, day) {
463
+ const date = /* @__PURE__ */ new Date(0);
464
+ date.setFullYear(year, month, day);
465
+ date.setHours(0, 0, 0, 0);
466
+ return date;
467
+ }
468
+ function startOfCalendarMonth(value) {
469
+ return localCalendarDate(value.getFullYear(), value.getMonth(), 1);
470
+ }
471
+ function addCalendarDays(value, amount) {
472
+ return localCalendarDate(value.getFullYear(), value.getMonth(), value.getDate() + amount);
473
+ }
474
+ function addCalendarMonths(value, amount) {
475
+ return localCalendarDate(value.getFullYear(), value.getMonth() + amount, 1);
476
+ }
477
+ function calendarDateKey(value) {
478
+ const month = `${value.getMonth() + 1}`.padStart(2, "0");
479
+ const day = `${value.getDate()}`.padStart(2, "0");
480
+ return `${`${value.getFullYear()}`.padStart(4, "0")}-${month}-${day}`;
481
+ }
482
+ function compareCalendarDates(left, right) {
483
+ const leftTime = normalizeCalendarDate(left).getTime();
484
+ const rightTime = normalizeCalendarDate(right).getTime();
485
+ return leftTime === rightTime ? 0 : leftTime < rightTime ? -1 : 1;
486
+ }
487
+ function isSameCalendarDay(left, right) {
488
+ return isValidCalendarDate(left) && isValidCalendarDate(right) && left.getFullYear() === right.getFullYear() && left.getMonth() === right.getMonth() && left.getDate() === right.getDate();
489
+ }
490
+ function buildCalendarMonth(month, weekStartsOn = 1) {
491
+ const firstDay = startOfCalendarMonth(month);
492
+ const offset = (firstDay.getDay() - weekStartsOn + 7) % 7;
493
+ const gridStart = addCalendarDays(firstDay, -offset);
494
+ const today = normalizeCalendarDate(/* @__PURE__ */ new Date());
495
+ return Array.from({ length: 42 }, (_, index) => {
496
+ const date = addCalendarDays(gridStart, index);
497
+ return {
498
+ date,
499
+ key: calendarDateKey(date),
500
+ day: date.getDate(),
501
+ outside: date.getMonth() !== firstDay.getMonth(),
502
+ today: isSameCalendarDay(date, today)
503
+ };
504
+ });
505
+ }
506
+ function buildCalendarWeekdays(locale = "zh-CN", weekStartsOn = 1) {
507
+ let formatter;
508
+ try {
509
+ formatter = new Intl.DateTimeFormat(locale, { weekday: "short" });
510
+ } catch {
511
+ formatter = new Intl.DateTimeFormat("zh-CN", { weekday: "short" });
512
+ }
513
+ const sunday = new Date(2026, 0, 4);
514
+ return Array.from({ length: 7 }, (_, index) => formatter.format(addCalendarDays(sunday, weekStartsOn + index)));
515
+ }
516
+ function formatCalendarMonth(value, locale = "zh-CN") {
517
+ try {
518
+ return new Intl.DateTimeFormat(locale, { year: "numeric", month: "long" }).format(value);
519
+ } catch {
520
+ return new Intl.DateTimeFormat("zh-CN", { year: "numeric", month: "long" }).format(value);
521
+ }
522
+ }
523
+ function formatCalendarDay(value, locale = "zh-CN") {
524
+ try {
525
+ return new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric", weekday: "long" }).format(value);
526
+ } catch {
527
+ return new Intl.DateTimeFormat("zh-CN", { year: "numeric", month: "long", day: "numeric", weekday: "long" }).format(value);
528
+ }
529
+ }
530
+
531
+ // src/date-range.ts
532
+ function parseCalendarDateKey(value) {
533
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
534
+ if (!match) return null;
535
+ const year = Number(match[1]);
536
+ const month = Number(match[2]) - 1;
537
+ const day = Number(match[3]);
538
+ const date = /* @__PURE__ */ new Date(0);
539
+ date.setFullYear(year, month, day);
540
+ date.setHours(0, 0, 0, 0);
541
+ return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day ? date : null;
542
+ }
543
+ function parseCalendarRange(value) {
544
+ return [parseCalendarDateKey(value[0]), parseCalendarDateKey(value[1])];
545
+ }
546
+ function getCalendarRangePosition(date, range) {
547
+ if (!range) return void 0;
548
+ const [start, end] = range;
549
+ if (isSameCalendarDay(date, start) && isSameCalendarDay(date, end)) return "single";
550
+ if (isSameCalendarDay(date, start)) return "start";
551
+ if (isSameCalendarDay(date, end)) return "end";
552
+ if (start && end && compareCalendarDates(date, start) > 0 && compareCalendarDates(date, end) < 0) return "middle";
553
+ return void 0;
554
+ }
555
+
556
+ // src/tree-path.ts
557
+ function findTreeNodePath(items, key) {
558
+ if (key === void 0) return [];
559
+ for (const node of items) {
560
+ if (node.key === key) return [node];
561
+ const path = findTreeNodePath(node.children ?? [], key);
562
+ if (path.length > 0) return [node, ...path];
563
+ }
564
+ return [];
565
+ }
566
+
567
+ // src/selection-list.ts
568
+ function normalizeSearch(value) {
569
+ return value.normalize("NFKC").toLocaleLowerCase().trim();
570
+ }
571
+ function filterSelectionListOptions(options, query = "") {
572
+ const seen = /* @__PURE__ */ new Set();
573
+ const search = normalizeSearch(query);
574
+ return options.filter((option) => {
575
+ if (seen.has(option.id)) return false;
576
+ seen.add(option.id);
577
+ return !search || [option.id, option.label, option.group ?? "", option.description ?? ""].some((text) => normalizeSearch(text).includes(search));
578
+ });
579
+ }
580
+ function groupSelectionListOptions(options) {
581
+ const groups = /* @__PURE__ */ new Map();
582
+ for (const option of options) {
583
+ const key = option.group === void 0 ? "ungrouped" : `group:${option.group}`;
584
+ const group = groups.get(key) ?? { key, label: option.group ?? "\u5176\u4ED6", options: [] };
585
+ group.options.push(option);
586
+ groups.set(key, group);
587
+ }
588
+ return [...groups.values()];
589
+ }
590
+ function getSelectionListScope(options, selected) {
591
+ const available = options.filter((option) => !option.disabled);
592
+ const ids = new Set(selected);
593
+ const selectedCount = available.filter((option) => ids.has(option.id)).length;
594
+ return {
595
+ total: options.length,
596
+ available: available.length,
597
+ disabled: options.length - available.length,
598
+ selected: options.filter((option) => ids.has(option.id)).length,
599
+ checked: available.length > 0 && selectedCount === available.length,
600
+ indeterminate: selectedCount > 0 && selectedCount < available.length
601
+ };
602
+ }
603
+ function updateSelectionListScope(selected, options, checked) {
604
+ const scope = new Set(options.filter((option) => !option.disabled).map((option) => option.id));
605
+ if (!checked) return selected.filter((id) => !scope.has(id));
606
+ return [.../* @__PURE__ */ new Set([...selected, ...scope])];
607
+ }
608
+
609
+ // src/color.ts
610
+ var clamp = (value, max) => Math.min(max, Math.max(0, Number.isFinite(value) ? value : 0));
611
+ function parseColorHex(value) {
612
+ const input = value.trim();
613
+ if (!/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(input)) return void 0;
614
+ const hex = input.length <= 5 ? input.slice(1).split("").map((part) => part + part).join("") : input.slice(1);
615
+ const [r, g, b] = [0, 2, 4].map((offset) => Number.parseInt(hex.slice(offset, offset + 2), 16) / 255);
616
+ const max = Math.max(r, g, b);
617
+ const min = Math.min(r, g, b);
618
+ const d = max - min;
619
+ let h = 0;
620
+ if (d !== 0) {
621
+ if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
622
+ else if (max === g) h = (b - r) / d + 2;
623
+ else h = (r - g) / d + 4;
624
+ h *= 60;
625
+ }
626
+ return { h, s: max === 0 ? 0 : d / max * 100, v: max * 100, a: hex.length === 8 ? Number.parseInt(hex.slice(6), 16) / 255 : 1 };
627
+ }
628
+ function formatColorHex(color, alpha = false) {
629
+ const h = clamp(color.h, 360) % 360 / 60;
630
+ const s = clamp(color.s, 100) / 100;
631
+ const v = clamp(color.v, 100) / 100;
632
+ const i = Math.floor(h);
633
+ const f = h - i;
634
+ const p = v * (1 - s);
635
+ const q = v * (1 - f * s);
636
+ const t = v * (1 - (1 - f) * s);
637
+ const channels = [[v, q, p, p, t, v][i], [t, v, v, q, p, p][i], [p, p, t, v, v, q][i]];
638
+ if (alpha) channels.push(clamp(color.a, 1));
639
+ return "#" + channels.map((value) => Math.round(value * 255).toString(16).padStart(2, "0")).join("").toUpperCase();
640
+ }
641
+
642
+ // src/date-time.ts
643
+ function parseTimeValue(value, showSeconds = false) {
644
+ const match = (showSeconds ? /^(\d{2}):(\d{2}):(\d{2})$/ : /^(\d{2}):(\d{2})$/).exec(value ?? "");
645
+ if (!match) return null;
646
+ const [hours, minutes, seconds] = [Number(match[1]), Number(match[2]), Number(match[3] ?? 0)];
647
+ return hours < 24 && minutes < 60 && seconds < 60 ? hours * 3600 + minutes * 60 + seconds : null;
648
+ }
649
+ function formatTimeValue(seconds, showSeconds = false) {
650
+ if (!Number.isInteger(seconds) || seconds < 0 || seconds >= 86400) return "";
651
+ const parts = [Math.floor(seconds / 3600), Math.floor(seconds / 60) % 60];
652
+ if (showSeconds) parts.push(seconds % 60);
653
+ return parts.map((part) => String(part).padStart(2, "0")).join(":");
654
+ }
655
+ function validateDateValue(value, options = {}) {
656
+ if (value === "") return void 0;
657
+ const date = parseCalendarDateKey(value);
658
+ if (!date) return "\u8BF7\u8F93\u5165\u6709\u6548\u65E5\u671F\uFF0C\u683C\u5F0F\u4E3A YYYY-MM-DD";
659
+ const min = parseCalendarDateKey(options.min);
660
+ const max = parseCalendarDateKey(options.max);
661
+ if (min && date < min) return `\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E ${options.min}`;
662
+ if (max && date > max) return `\u65E5\u671F\u4E0D\u80FD\u665A\u4E8E ${options.max}`;
663
+ if (options.disabledDate?.(date)) return "\u8BE5\u65E5\u671F\u4E0D\u53EF\u9009\u62E9";
664
+ return void 0;
665
+ }
666
+ function validateTimeValue(value, options = {}) {
667
+ if (value === "") return void 0;
668
+ const seconds = parseTimeValue(value, options.showSeconds);
669
+ const format = options.showSeconds ? "HH:mm:ss" : "HH:mm";
670
+ if (seconds === null) return `\u8BF7\u8F93\u5165\u6709\u6548\u65F6\u95F4\uFF0C\u683C\u5F0F\u4E3A ${format}`;
671
+ const min = parseTimeValue(options.min, options.showSeconds);
672
+ const max = parseTimeValue(options.max, options.showSeconds);
673
+ if (min !== null && seconds < min) return `\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E ${options.min}`;
674
+ if (max !== null && seconds > max) return `\u65F6\u95F4\u4E0D\u80FD\u665A\u4E8E ${options.max}`;
675
+ if (options.disabledTime?.(value)) return "\u8BE5\u65F6\u95F4\u4E0D\u53EF\u9009\u62E9";
676
+ return void 0;
677
+ }
678
+ function parseLocalDateTimeValue(value, showSeconds = false) {
679
+ const parts = value.split(" ");
680
+ if (parts.length !== 2) return null;
681
+ const date = parseCalendarDateKey(parts[0]);
682
+ return date && parseTimeValue(parts[1], showSeconds) !== null ? { date, time: parts[1] } : null;
683
+ }
684
+ function validateDateTimeValue(value, options = {}) {
685
+ if (value === "") return void 0;
686
+ const parsed = parseLocalDateTimeValue(value, options.showSeconds);
687
+ if (!parsed) return `\u8BF7\u8F93\u5165\u6709\u6548\u65E5\u671F\u65F6\u95F4\uFF0C\u683C\u5F0F\u4E3A YYYY-MM-DD ${options.showSeconds ? "HH:mm:ss" : "HH:mm"}`;
688
+ if (parseLocalDateTimeValue(options.min ?? "", options.showSeconds) && value < options.min) return `\u65E5\u671F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E ${options.min}`;
689
+ if (parseLocalDateTimeValue(options.max ?? "", options.showSeconds) && value > options.max) return `\u65E5\u671F\u65F6\u95F4\u4E0D\u80FD\u665A\u4E8E ${options.max}`;
690
+ if (options.disabledDate?.(parsed.date)) return "\u8BE5\u65E5\u671F\u4E0D\u53EF\u9009\u62E9";
691
+ if (options.disabledTime?.(value)) return "\u8BE5\u65F6\u95F4\u4E0D\u53EF\u9009\u62E9";
692
+ return void 0;
693
+ }
694
+ function validateTimeRangeValue(value, options = {}) {
695
+ if (!value[0] && !value[1]) return void 0;
696
+ if (!value[0] || !value[1]) return "\u8BF7\u586B\u5199\u5B8C\u6574\u7684\u5F00\u59CB\u548C\u7ED3\u675F\u65F6\u95F4";
697
+ const error = validateTimeValue(value[0], options) ?? validateTimeValue(value[1], options);
698
+ if (error) return error;
699
+ return parseTimeValue(value[0], options.showSeconds) > parseTimeValue(value[1], options.showSeconds) ? "\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65F6\u95F4" : void 0;
700
+ }
701
+ function buildTimeSelectOptions(start = "09:00", end = "18:00", step = "00:30", constraints = {}) {
702
+ const first = parseTimeValue(start);
703
+ const last = parseTimeValue(end);
704
+ const increment = parseTimeValue(step);
705
+ if (first === null || last === null || increment === null || increment <= 0 || first > last) return [];
706
+ const options = [];
707
+ for (let seconds = first; seconds <= last; seconds += increment) {
708
+ const value = formatTimeValue(seconds);
709
+ options.push({ value, label: value, disabled: Boolean(validateTimeValue(value, { ...constraints, showSeconds: false })) });
710
+ }
711
+ return options;
712
+ }
713
+ function getAvailableTimeValues(options = {}) {
714
+ const increment = options.showSeconds ? 1 : 60;
715
+ const min = parseTimeValue(options.min, options.showSeconds) ?? 0;
716
+ const max = parseTimeValue(options.max, options.showSeconds) ?? 86399;
717
+ const values = [];
718
+ for (let value = Math.ceil(min / increment) * increment; value <= max; value += increment) {
719
+ if (!options.disabledTime?.(formatTimeValue(value, options.showSeconds))) values.push(value);
720
+ }
721
+ return values;
722
+ }
723
+ function getTimeColumnChoices(available, current, unit) {
724
+ const divisor = unit === "hour" ? 3600 : unit === "minute" ? 60 : 1;
725
+ const count = unit === "hour" ? 24 : 60;
726
+ const currentUnit = Math.floor(current / divisor) % count;
727
+ const nearest = Array.from({ length: count });
728
+ for (const value of available) {
729
+ const index = Math.floor(value / divisor) % count;
730
+ const previous = nearest[index];
731
+ const target = current + (index - currentUnit) * divisor;
732
+ if (previous === void 0 || Math.abs(value - target) < Math.abs(previous - target)) nearest[index] = value;
733
+ }
734
+ return Array.from({ length: count }, (_, index) => {
735
+ return { label: String(index).padStart(2, "0"), value: index, time: nearest[index], disabled: nearest[index] === void 0 };
736
+ });
737
+ }
738
+ function localDateTimeKey(date, time) {
739
+ return `${calendarDateKey(date)} ${time}`;
740
+ }
741
+
742
+ // src/tree-check.ts
743
+ function getTreeCheckState(items, keys, strict = false) {
744
+ const seed = new Set(keys);
745
+ const known = /* @__PURE__ */ new Set();
746
+ const disabledKeys = [];
747
+ const checkedNodeKeys = [];
748
+ const halfCheckedKeys = [];
749
+ const leaves = [];
750
+ function visit(node, parentDisabled, parentChecked) {
751
+ known.add(node.key);
752
+ const disabled2 = Boolean(node.disabled || !strict && parentDisabled);
753
+ if (disabled2) disabledKeys.push(node.key);
754
+ if (strict) {
755
+ if (seed.has(node.key)) checkedNodeKeys.push(node.key);
756
+ node.children?.forEach((child) => visit(child, disabled2, false));
757
+ return { total: disabled2 ? 0 : 1, checked: seed.has(node.key) ? 1 : 0 };
758
+ }
759
+ const selected = parentChecked || seed.has(node.key);
760
+ if (!node.children?.length) {
761
+ if (seed.has(node.key) || !disabled2 && selected) checkedNodeKeys.push(node.key);
762
+ if (!disabled2 && selected) leaves.push(node.key);
763
+ return { total: disabled2 ? 0 : 1, checked: !disabled2 && selected ? 1 : 0 };
764
+ }
765
+ const coverage = node.children.map((child) => visit(child, disabled2, !disabled2 && selected)).reduce((sum, child) => ({ total: sum.total + child.total, checked: sum.checked + child.checked }), { total: 0, checked: 0 });
766
+ if (disabled2 ? seed.has(node.key) : coverage.total > 0 && coverage.checked === coverage.total) checkedNodeKeys.push(node.key);
767
+ else if (!disabled2 && coverage.checked > 0) halfCheckedKeys.push(node.key);
768
+ return coverage;
769
+ }
770
+ items.forEach((node) => visit(node, false, false));
771
+ const disabled = new Set(disabledKeys);
772
+ return { checkedKeys: strict ? [...seed] : [.../* @__PURE__ */ new Set([...keys.filter((key) => !known.has(key) || disabled.has(key)), ...leaves])], checkedNodeKeys, halfCheckedKeys, disabledKeys };
773
+ }
774
+ function toggleTreeCheckedKey(items, keys, key, checked, strict = false) {
775
+ const state = getTreeCheckState(items, keys, strict);
776
+ const disabled = new Set(state.disabledKeys);
777
+ if (disabled.has(key)) return state;
778
+ const find = (nodes) => {
779
+ for (const node2 of nodes) {
780
+ if (node2.key === key) return node2;
781
+ const child = find(node2.children ?? []);
782
+ if (child) return child;
783
+ }
784
+ };
785
+ const node = find(items);
786
+ if (!node) return state;
787
+ const next = new Set(state.checkedKeys);
788
+ function update(item) {
789
+ if (disabled.has(item.key)) return;
790
+ if (!strict && item.children?.length) {
791
+ item.children.forEach(update);
792
+ return;
793
+ }
794
+ if (checked) next.add(item.key);
795
+ else next.delete(item.key);
796
+ }
797
+ update(node);
798
+ return getTreeCheckState(items, [...next], strict);
799
+ }
800
+
801
+ // src/rating.ts
802
+ function normalizeRatingMax(max) {
803
+ return Number.isFinite(max) ? Math.min(100, Math.max(1, Math.floor(max))) : 5;
804
+ }
805
+ function normalizeRatingValue(value, max, precision = 1) {
806
+ if (!Number.isFinite(value)) return 0;
807
+ return Math.min(normalizeRatingMax(max), Math.max(0, Math.floor((value ?? 0) / precision) * precision));
808
+ }
809
+ function getRatingKeyboardValue(value, key, max, precision = 1, allowClear = false) {
810
+ const limit = normalizeRatingMax(max);
811
+ if (key === "Home") return precision;
812
+ if (key === "End") return limit;
813
+ if (allowClear && (key === "Delete" || key === "Backspace")) return 0;
814
+ if (key === "ArrowUp" || key === "ArrowRight") return Math.min(limit, value + precision);
815
+ if (key === "ArrowDown" || key === "ArrowLeft") return Math.max(allowClear ? 0 : precision, value - precision);
816
+ return void 0;
817
+ }
818
+
819
+ // src/image-preview.ts
820
+ function getImagePreviewLayout(width, height, viewportWidth, viewportHeight, zoom = 1, rotation = 0) {
821
+ const valid = [width, height, viewportWidth, viewportHeight, zoom].every((value) => Number.isFinite(value) && value > 0);
822
+ if (!valid) return { width: 0, height: 0, canvasWidth: Math.max(0, viewportWidth || 0), canvasHeight: Math.max(0, viewportHeight || 0) };
823
+ const scale = Math.min(1, viewportWidth / width, viewportHeight / height) * Math.max(0.25, Math.min(4, zoom));
824
+ const imageWidth = width * scale;
825
+ const imageHeight = height * scale;
826
+ const swap = Math.abs(Math.round(rotation / 90)) % 2 === 1;
827
+ return { width: imageWidth, height: imageHeight, canvasWidth: Math.max(viewportWidth, swap ? imageHeight : imageWidth), canvasHeight: Math.max(viewportHeight, swap ? imageWidth : imageHeight) };
828
+ }
829
+
830
+ // src/table-layout.ts
831
+ function getTableColumnFixed(column) {
832
+ return column.fixed === true ? "left" : column.fixed || void 0;
833
+ }
834
+ function tableColumnLength(value) {
835
+ if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? `${value}px` : void 0;
836
+ return value?.trim() || void 0;
837
+ }
838
+ function resolveTableFixedColumns(columns, widths, regionWidth, priorityIndex, contentWindow = 160) {
839
+ if (!Number.isFinite(regionWidth) || regionWidth <= 0) return [...columns];
840
+ const retained = /* @__PURE__ */ new Set();
841
+ const widthAt = (index) => Number.isFinite(widths[index]) ? Math.max(0, widths[index]) : 0;
842
+ let occupied = 0;
843
+ const budget = Math.max(0, regionWidth - contentWindow);
844
+ const attempt = (index) => {
845
+ if (retained.has(index)) return;
846
+ const width = widthAt(index);
847
+ if (occupied + width <= budget) {
848
+ retained.add(index);
849
+ occupied += width;
850
+ }
851
+ };
852
+ if (priorityIndex !== void 0 && getTableColumnFixed(columns[priorityIndex] ?? {})) attempt(priorityIndex);
853
+ for (let index = columns.length - 1; index >= 0; index--) if (getTableColumnFixed(columns[index]) === "right") attempt(index);
854
+ for (let index = 0; index < columns.length; index++) if (getTableColumnFixed(columns[index]) === "left") attempt(index);
855
+ return columns.map((column, index) => retained.has(index) ? column : { ...column, fixed: void 0 });
856
+ }
857
+ function getTableColumnStyle(columns, index, widths = []) {
858
+ const column = columns[index] ?? {};
859
+ const fixed = getTableColumnFixed(column);
860
+ const siblings = columns.map((item, position) => ({ item, position })).filter(({ item, position }) => getTableColumnFixed(item) === fixed && (fixed === "left" ? position < index : position > index));
861
+ const offset = siblings.map(({ item, position }) => widths[position] !== void 0 ? `${widths[position]}px` : tableColumnLength(item.width ?? item.minWidth) ?? "0px");
862
+ return {
863
+ width: tableColumnLength(column.width),
864
+ minWidth: tableColumnLength(column.minWidth),
865
+ textAlign: column.align,
866
+ "--ug-table-fixed-offset": fixed ? offset.length ? `calc(${offset.join(" + ")})` : "0px" : void 0
867
+ };
868
+ }
869
+
870
+ // src/tree-table.ts
871
+ function projectTreeTableRows(roots, options) {
872
+ const rows = [];
873
+ const visibleRows = [];
874
+ const expandableIds = [];
875
+ const known = /* @__PURE__ */ new Set();
876
+ const pending = roots.map((record) => ({ record, depth: 0, parentId: void 0, visible: true })).reverse();
877
+ while (pending.length) {
878
+ const entry = pending.pop();
879
+ const rawId = options.getRowId(entry.record);
880
+ if (rawId === void 0 || rawId === null || String(rawId) === "") throw new Error("UGTreeTable \u7684\u6BCF\u6761\u8BB0\u5F55\u5FC5\u987B\u6709\u975E\u7A7A\u7A33\u5B9A\u6807\u8BC6");
881
+ const id = String(rawId);
882
+ if (known.has(id)) throw new Error(`UGTreeTable \u7684\u8BB0\u5F55\u6807\u8BC6\u5FC5\u987B\u552F\u4E00\u4E14\u65E0\u73AF\uFF1A${id}`);
883
+ known.add(id);
884
+ const children = options.getChildren(entry.record) ?? [];
885
+ const expanded = Boolean(children.length && (options.expandedIds?.has(id) ?? options.defaultExpandAll));
886
+ const row = { id, record: entry.record, parentId: entry.parentId, depth: entry.depth, hasChildren: children.length > 0, expanded };
887
+ rows.push(row);
888
+ if (entry.visible) visibleRows.push(row);
889
+ if (children.length) expandableIds.push(id);
890
+ for (let index = children.length - 1; index >= 0; index--) pending.push({ record: children[index], depth: entry.depth + 1, parentId: id, visible: entry.visible && expanded });
891
+ }
892
+ return { rows, visibleRows, expandableIds };
893
+ }
894
+
895
+ // src/table-structure.ts
896
+ function getTableStructure(columns, order = []) {
897
+ const rank = new Map(order.map((id, index) => [id, index]));
898
+ const ids = /* @__PURE__ */ new Set();
899
+ let depth = 1;
900
+ const walk = (nodes, level) => [...nodes].sort((left, right) => (rank.get(left.id) ?? Infinity) - (rank.get(right.id) ?? Infinity)).map((column) => {
901
+ if (!column.id || ids.has(column.id)) throw new Error("UGDataTable \u7684\u5217 id \u5FC5\u987B\u975E\u7A7A\u4E14\u5168\u5C40\u552F\u4E00");
902
+ ids.add(column.id);
903
+ depth = Math.max(depth, level);
904
+ return column.children?.length ? { ...column, children: walk(column.children, level + 1) } : column;
905
+ });
906
+ const ordered = walk(columns, 1);
907
+ const headers = Array.from({ length: depth }, () => []);
908
+ const leaves = [];
909
+ const canonicalOrder = [];
910
+ const project = (nodes, level, parentId) => {
911
+ for (const column of nodes) {
912
+ canonicalOrder.push(column.id);
913
+ const children = column.children;
914
+ const leafIndex = leaves.length;
915
+ if (children?.length) project(children, level + 1, column.id);
916
+ else leaves.push(column);
917
+ headers[level - 1].push({ column, leafIndex, colSpan: leaves.length - leafIndex, rowSpan: children?.length ? 1 : depth - level + 1, parentId, siblingIds: nodes.map((node) => node.id) });
918
+ }
919
+ };
920
+ project(ordered, 1);
921
+ return { columns: ordered, leaves, headers, order: canonicalOrder };
922
+ }
923
+ function moveTableColumn(columns, order, source, target, after = false) {
924
+ const structure = getTableStructure(columns, order);
925
+ const cell = structure.headers.flat().find((item) => item.column.id === source);
926
+ if (!cell || source === target || !cell.siblingIds.includes(target)) return structure.order;
927
+ const next = structure.order.filter((id) => id !== source);
928
+ next.splice(next.indexOf(target) + (after ? 1 : 0), 0, source);
929
+ return getTableStructure(columns, next).order;
930
+ }
931
+ function getTableSpanGrid(rows, columns, span) {
932
+ const grid = Array.from({ length: rows }, () => Array.from({ length: columns }, () => ({ rowSpan: 0, colSpan: 0 })));
933
+ const occupied = /* @__PURE__ */ new Set();
934
+ const normalize = (value, max) => value === 0 ? 0 : Number.isSafeInteger(value) && value > 0 ? Math.min(value, max) : 1;
935
+ for (let row = 0; row < rows; row++) for (let column = 0; column < columns; column++) {
936
+ if (occupied.has(`${row}:${column}`)) continue;
937
+ const requested = span?.(row, column);
938
+ let rowSpan = normalize(requested?.rowSpan, rows - row);
939
+ let colSpan = normalize(requested?.colSpan, columns - column);
940
+ if (!rowSpan || !colSpan) continue;
941
+ let overlap = false;
942
+ for (let r = row; r < row + rowSpan; r++) for (let c = column; c < column + colSpan; c++) if (occupied.has(`${r}:${c}`)) overlap = true;
943
+ if (overlap) {
944
+ rowSpan = 1;
945
+ colSpan = 1;
946
+ }
947
+ grid[row][column] = { rowSpan, colSpan };
948
+ for (let r = row; r < row + rowSpan; r++) for (let c = column; c < column + colSpan; c++) occupied.add(`${r}:${c}`);
949
+ }
950
+ return grid;
951
+ }
952
+
953
+ // src/date-picker-modes.ts
954
+ var pad = (value, size = 2) => String(value).padStart(size, "0");
955
+ function localDate(year, month = 0, day = 1) {
956
+ const date = /* @__PURE__ */ new Date(0);
957
+ date.setFullYear(year, month, day);
958
+ date.setHours(0, 0, 0, 0);
959
+ return date;
960
+ }
961
+ function isoWeekStart(date) {
962
+ const start = localDate(date.getFullYear(), date.getMonth(), date.getDate());
963
+ start.setDate(start.getDate() - (start.getDay() + 6) % 7);
964
+ return start;
965
+ }
966
+ function datePickerModeKey(date, mode) {
967
+ if (mode === "year") return pad(date.getFullYear(), 4);
968
+ if (mode === "month") return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}`;
969
+ if (mode === "week") {
970
+ const start = isoWeekStart(date);
971
+ const thursday = new Date(start);
972
+ thursday.setDate(start.getDate() + 3);
973
+ const year = thursday.getFullYear();
974
+ const first = isoWeekStart(localDate(year, 0, 4));
975
+ return `${pad(year, 4)}-W${pad(Math.round((start.getTime() - first.getTime()) / 6048e5) + 1)}`;
976
+ }
977
+ return calendarDateKey(date);
978
+ }
979
+ function parseDatePickerModeKey(value, mode) {
980
+ if (mode === "date" || mode === "multiple") return parseCalendarDateKey(value);
981
+ if (mode === "year") return /^\d{4}$/.test(value) ? parseCalendarDateKey(`${value}-01-01`) : null;
982
+ if (mode === "month") return /^\d{4}-\d{2}$/.test(value) ? parseCalendarDateKey(`${value}-01`) : null;
983
+ const match = /^(\d{4})-W(\d{2})$/.exec(value);
984
+ if (!match || Number(match[2]) < 1 || Number(match[2]) > 53) return null;
985
+ const start = isoWeekStart(localDate(Number(match[1]), 0, 4));
986
+ start.setDate(start.getDate() + (Number(match[2]) - 1) * 7);
987
+ return datePickerModeKey(start, "week") === value ? start : null;
988
+ }
989
+ function validateDatePickerModeValue(value, mode = "date", policy = {}) {
990
+ if (!value) return void 0;
991
+ if (mode === "multiple") {
992
+ const values = value.split(",").map((part) => part.trim());
993
+ if (values.some((part) => !part)) return "\u8BF7\u4F7F\u7528\u9017\u53F7\u5206\u9694\u5B8C\u6574\u65E5\u671F";
994
+ for (const part of values) {
995
+ const error = validateDatePickerModeValue(part, "date", policy);
996
+ if (error) return error;
997
+ }
998
+ return void 0;
999
+ }
1000
+ const first = parseDatePickerModeKey(value, mode);
1001
+ if (!first) return `\u8BF7\u8F93\u5165\u6709\u6548${mode === "year" ? "\u5E74\u4EFD\uFF0C\u683C\u5F0F\u4E3A YYYY" : mode === "month" ? "\u6708\u4EFD\uFF0C\u683C\u5F0F\u4E3A YYYY-MM" : mode === "week" ? "ISO\u5468\uFF0C\u683C\u5F0F\u4E3A YYYY-Www" : "\u65E5\u671F\uFF0C\u683C\u5F0F\u4E3A YYYY-MM-DD"}`;
1002
+ const last = new Date(first);
1003
+ if (mode === "year") last.setFullYear(first.getFullYear() + 1, 0, 0);
1004
+ if (mode === "month") last.setMonth(first.getMonth() + 1, 0);
1005
+ if (mode === "week") last.setDate(first.getDate() + 6);
1006
+ const min = parseCalendarDateKey(policy.min);
1007
+ const max = parseCalendarDateKey(policy.max);
1008
+ if (min && last < min) return `\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E ${policy.min}`;
1009
+ if (max && first > max) return `\u65E5\u671F\u4E0D\u80FD\u665A\u4E8E ${policy.max}`;
1010
+ if (policy.disabledDate) {
1011
+ const cursor = new Date(min && first < min ? min : first);
1012
+ while (cursor <= last && (!max || cursor <= max)) {
1013
+ if (!policy.disabledDate(new Date(cursor))) return void 0;
1014
+ cursor.setDate(cursor.getDate() + 1);
1015
+ }
1016
+ return "\u8BE5\u65E5\u671F\u533A\u95F4\u4E0D\u53EF\u9009\u62E9";
1017
+ }
1018
+ return void 0;
1019
+ }
1020
+ function validateDateTimeRangeValue(value, policy = {}) {
1021
+ if (!value[0] && !value[1]) return void 0;
1022
+ if (!value[0] || !value[1]) return "\u8BF7\u586B\u5199\u5B8C\u6574\u7684\u5F00\u59CB\u548C\u7ED3\u675F\u65E5\u671F\u65F6\u95F4";
1023
+ return validateDateTimeValue(value[0], policy) ?? validateDateTimeValue(value[1], policy) ?? (value[0] > value[1] ? "\u7ED3\u675F\u65E5\u671F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F\u65F6\u95F4" : void 0);
1024
+ }
1025
+ function validateDateRangeShortcut(value, policy = {}) {
1026
+ if (!value[0] || !value[1]) return "\u5FEB\u6377\u8303\u56F4\u5FC5\u987B\u5305\u542B\u4E24\u4E2A\u5B8C\u6574\u65E5\u671F";
1027
+ return validateDatePickerModeValue(value[0], "date", policy) ?? validateDatePickerModeValue(value[1], "date", policy) ?? (value[0] > value[1] ? "\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F" : void 0);
1028
+ }
1029
+
1030
+ // src/tree-drag.ts
1031
+ function canDropTreeNode(items, source, target) {
1032
+ let drag;
1033
+ let exists = false;
1034
+ const walk = (nodes) => {
1035
+ for (const node of nodes) {
1036
+ if (node.key === source) drag = node;
1037
+ if (node.key === target) exists = true;
1038
+ if (node.children) walk(node.children);
1039
+ }
1040
+ };
1041
+ walk(items);
1042
+ const contains = (node) => node.key === target || Boolean(node.children?.some(contains));
1043
+ return Boolean(drag && exists && !contains(drag));
1044
+ }
1045
+
1046
+ // src/form-state.ts
1047
+ function isFormPathWithin(field, parent) {
1048
+ const name = normalizeFormPath(field), root = normalizeFormPath(parent);
1049
+ return name === root || name.startsWith(`${root}.`);
1050
+ }
1051
+ function normalizeFormPath(path) {
1052
+ if (/\[\d+\](?=[^.\[])/.test(path)) throw new Error("UGForm \u5B57\u6BB5\u8DEF\u5F84\u65E0\u6548");
1053
+ const normalized = path.replace(/\[(\d+)\]/g, ".$1");
1054
+ const parts = normalized.split(".");
1055
+ if (parts.some((part) => !part || /[\[\]]/.test(part) || ["__proto__", "prototype", "constructor"].includes(part))) {
1056
+ throw new Error("UGForm \u5B57\u6BB5\u8DEF\u5F84\u65E0\u6548");
1057
+ }
1058
+ return normalized;
1059
+ }
1060
+ function getFormPath(values, path) {
1061
+ let current = values;
1062
+ for (const key of normalizeFormPath(path).split(".")) {
1063
+ if (!current || typeof current !== "object" || !Object.hasOwn(current, key)) return void 0;
1064
+ current = current[key];
1065
+ }
1066
+ return current;
1067
+ }
1068
+ function isFormPathActive(values, path) {
1069
+ let current = values;
1070
+ for (const key of normalizeFormPath(path).split(".")) {
1071
+ if (Array.isArray(current) && /^\d+$/.test(key) && Number(key) >= current.length) return false;
1072
+ current = current && typeof current === "object" && Object.hasOwn(current, key) ? current[key] : void 0;
1073
+ }
1074
+ return true;
1075
+ }
1076
+ function setFormPath(values, path, value) {
1077
+ const keys = normalizeFormPath(path).split(".");
1078
+ const write = (current, index) => {
1079
+ const key = keys[index];
1080
+ const copy = Array.isArray(current) ? [...current] : current && typeof current === "object" ? { ...current } : /^\d+$/.test(key) ? [] : {};
1081
+ const record = copy;
1082
+ record[key] = index === keys.length - 1 ? value : write(record[key], index + 1);
1083
+ return copy;
1084
+ };
1085
+ return write(values, 0);
1086
+ }
1087
+ function getFormPaths(values, prefix = "") {
1088
+ if (!values || typeof values !== "object" || values instanceof Date) return prefix ? [prefix] : [];
1089
+ const entries = Object.entries(values);
1090
+ if (!entries.length) return prefix ? [prefix] : [];
1091
+ return entries.flatMap(([key, value]) => {
1092
+ const path = prefix ? `${prefix}.${key}` : key;
1093
+ return [path, ...value && typeof value === "object" && !(value instanceof Date) ? getFormPaths(value, path).filter((item) => item !== path) : []];
1094
+ });
1095
+ }
1096
+ function isFormValueEqual(left, right) {
1097
+ if (Object.is(left, right)) return true;
1098
+ if (left instanceof Date && right instanceof Date) return left.getTime() === right.getTime();
1099
+ if (!left || !right || typeof left !== "object" || typeof right !== "object" || Array.isArray(left) !== Array.isArray(right)) return false;
1100
+ if (!Array.isArray(left) && ![Object.prototype, null].includes(Object.getPrototypeOf(left))) return false;
1101
+ if (!Array.isArray(right) && ![Object.prototype, null].includes(Object.getPrototypeOf(right))) return false;
1102
+ const keys = Object.keys(left);
1103
+ return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && isFormValueEqual(left[key], right[key]));
1104
+ }
1105
+ function createFormFieldArray(path, read, write) {
1106
+ const name = normalizeFormPath(path);
1107
+ let sequence = 0;
1108
+ let ids = [];
1109
+ const nextId = () => `${name}-${++sequence}`;
1110
+ function values() {
1111
+ const current = read();
1112
+ if (current !== void 0 && !Array.isArray(current)) throw new Error("UGForm fieldArray \u53EA\u80FD\u7ED1\u5B9A\u6570\u7EC4\u5B57\u6BB5");
1113
+ const result = current ?? [];
1114
+ ids = result.map((_, index) => ids[index] ?? nextId());
1115
+ return result;
1116
+ }
1117
+ const validIndex = (index, length) => Number.isInteger(index) && index >= 0 && index < length;
1118
+ const controller = {
1119
+ get fields() {
1120
+ return values().map((value, index) => ({ id: ids[index], index, name: `${name}.${index}`, value }));
1121
+ },
1122
+ append(value) {
1123
+ controller.insert(values().length, value);
1124
+ },
1125
+ insert(index, value) {
1126
+ const current = values();
1127
+ if (!Number.isInteger(index) || index < 0 || index > current.length) return;
1128
+ const next = [...current];
1129
+ next.splice(index, 0, value);
1130
+ ids.splice(index, 0, nextId());
1131
+ write(next);
1132
+ },
1133
+ remove(index) {
1134
+ const current = values();
1135
+ if (!validIndex(index, current.length)) return;
1136
+ const next = [...current];
1137
+ next.splice(index, 1);
1138
+ ids.splice(index, 1);
1139
+ write(next);
1140
+ },
1141
+ move(from, to) {
1142
+ const current = values();
1143
+ if (!validIndex(from, current.length) || !validIndex(to, current.length) || from === to) return;
1144
+ const next = [...current];
1145
+ next.splice(to, 0, next.splice(from, 1)[0]);
1146
+ ids.splice(to, 0, ids.splice(from, 1)[0]);
1147
+ write(next);
1148
+ },
1149
+ replace(next) {
1150
+ ids = next.map(nextId);
1151
+ write([...next]);
1152
+ }
1153
+ };
1154
+ return { controller, resetIds() {
1155
+ ids = [];
1156
+ } };
1157
+ }
170
1158
  // Annotate the CommonJS export names for ESM import in node:
171
1159
  0 && (module.exports = {
1160
+ addCalendarDays,
1161
+ addCalendarMonths,
1162
+ applyUGThemeProfile,
1163
+ buildCalendarMonth,
1164
+ buildCalendarWeekdays,
1165
+ buildTimeSelectOptions,
1166
+ calendarDateKey,
1167
+ canDropTreeNode,
1168
+ compareCalendarDates,
172
1169
  countTextCharacters,
1170
+ createFormFieldArray,
173
1171
  createUGThemeValue,
1172
+ datePickerModeKey,
1173
+ defaultUGNavigationColors,
174
1174
  defaultUGTheme,
1175
+ defaultUGThemeConfiguratorOptions,
1176
+ defaultUGThemeNavigationColors,
1177
+ defaultUGThemeProfiles,
175
1178
  encodeSelectValue,
1179
+ filterSelectionListOptions,
1180
+ findTreeNodePath,
1181
+ formatCalendarDay,
1182
+ formatCalendarMonth,
1183
+ formatColorHex,
1184
+ formatTimeValue,
1185
+ getAvailableTimeValues,
1186
+ getCalendarRangePosition,
1187
+ getFormPath,
1188
+ getFormPaths,
1189
+ getImagePreviewLayout,
1190
+ getRatingKeyboardValue,
1191
+ getSelectionListScope,
1192
+ getTableColumnFixed,
1193
+ getTableColumnStyle,
1194
+ getTableSpanGrid,
1195
+ getTableStructure,
1196
+ getTimeColumnChoices,
1197
+ getTreeCheckState,
1198
+ groupSelectionListOptions,
176
1199
  isEmptyFormValue,
1200
+ isFormPathActive,
1201
+ isFormPathWithin,
1202
+ isFormValueEqual,
1203
+ isSameCalendarDay,
1204
+ isUGThemeProfileModified,
1205
+ isValidCalendarDate,
1206
+ isoWeekStart,
177
1207
  limitTextByCount,
1208
+ localDateTimeKey,
1209
+ moveTableColumn,
1210
+ normalizeCalendarDate,
1211
+ normalizeFormPath,
1212
+ normalizeRatingMax,
1213
+ normalizeRatingValue,
178
1214
  normalizeSelectKeys,
179
- validateFormValue
1215
+ parseCalendarDateKey,
1216
+ parseCalendarRange,
1217
+ parseColorHex,
1218
+ parseDatePickerModeKey,
1219
+ parseLocalDateTimeValue,
1220
+ parseTimeValue,
1221
+ projectTreeTableRows,
1222
+ resolveTableFixedColumns,
1223
+ resolveUGNavigationColors,
1224
+ resolveUGNavigationPalette,
1225
+ setFormPath,
1226
+ startOfCalendarMonth,
1227
+ tableColumnLength,
1228
+ toggleTreeCheckedKey,
1229
+ ugThemeProfileFields,
1230
+ updateSelectionListScope,
1231
+ validateDatePickerModeValue,
1232
+ validateDateRangeShortcut,
1233
+ validateDateTimeRangeValue,
1234
+ validateDateTimeValue,
1235
+ validateDateValue,
1236
+ validateFormValue,
1237
+ validateTimeRangeValue,
1238
+ validateTimeValue
180
1239
  });
181
1240
  //# sourceMappingURL=index.cjs.map