@epxing/utils 0.0.0-stage → 5.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +602 -0
- package/README.md +22 -2
- package/dist/_vendor/.pnpm/jsencrypt@3.5.4/_vendor/jsencrypt/bin/jsencrypt.min.js +1691 -0
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/jsencrypt.min.js +31 -0
- package/dist/_virtual/jsencrypt.min2.js +4 -0
- package/dist/_virtual/preload-helper.js +88 -0
- package/dist/assets/ai-BBFn3QRy.png +0 -0
- package/dist/assets/ai_import-BxQ7Ohn6.png +0 -0
- package/dist/assets/app-DBNIokDP.png +0 -0
- package/dist/assets/approval-DGcBv-re.png +0 -0
- package/dist/assets/create_market_system-BH__UVbt.png +0 -0
- package/dist/assets/create_system-irg--ePh.png +0 -0
- package/dist/assets/custom-C-ujlHz1.png +0 -0
- package/dist/assets/default-icon-2193FMjv.png +0 -0
- package/dist/assets/ex_link-4fYPd9nh.png +0 -0
- package/dist/assets/excel-BYqRm2Y8.png +0 -0
- package/dist/assets/folder-CFVsNbjj.png +0 -0
- package/dist/assets/form-DD9HV-jN.png +0 -0
- package/dist/assets/import-tfKWbWVS.png +0 -0
- package/dist/assets/meta-Qorpi70B.png +0 -0
- package/dist/assets/module-DQrs7VAS.png +0 -0
- package/dist/assets/null-B2An29h4.png +0 -0
- package/dist/assets/option-CG02tIgh.svg +1 -0
- package/dist/assets/photo-uscRzRXF.png +0 -0
- package/dist/assets/process-Dcndu9m2.png +0 -0
- package/dist/assets/rule-DcYhYse0.png +0 -0
- package/dist/assets/service-CLYLpPl3.png +0 -0
- package/dist/assets/single_file-B3TJtJli.png +0 -0
- package/dist/assets/snapshot-history-BsVY9cVj.png +0 -0
- package/dist/assets/snapshot-manual-DBRfFHYI.png +0 -0
- package/dist/assets/snapshot-realtime-DjHnJI6C.png +0 -0
- package/dist/assets/staff-Bn_-_00l.png +0 -0
- package/dist/assets/sync_append-Bm8mtvZs.png +0 -0
- package/dist/assets/sync_append_update-DzjxqJ_U.png +0 -0
- package/dist/assets/sync_loading-D7LoNPFP.png +0 -0
- package/dist/assets/sync_replace-Cbbzz327.png +0 -0
- package/dist/assets/sync_update-Birao6Cr.png +0 -0
- package/dist/assets/userRole-D1LAdM6N.png +0 -0
- package/dist/assets/user_bg-BFHtaZjz.png +0 -0
- package/dist/src/Config.js +25 -0
- package/dist/src/asset-images.js +125 -0
- package/dist/src/assets/images/add.png.js +4 -0
- package/dist/src/assets/images/ai-button.png.js +4 -0
- package/dist/src/assets/images/ai.png.js +4 -0
- package/dist/src/assets/images/ai_import.png.js +4 -0
- package/dist/src/assets/images/app.png.js +4 -0
- package/dist/src/assets/images/approval.png.js +4 -0
- package/dist/src/assets/images/book.png.js +4 -0
- package/dist/src/assets/images/canvas-editor/alignment.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/arrow-left.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/arrow-right.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/block.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/bold.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/catalog.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/center.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/checkbox.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/close.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/codeblock.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/color.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/control.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/date.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/exit-fullscreen.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/format.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/highlight.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/hyperlink.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/image.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/italic.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/justify.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/latex.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/left.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-dot-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-large-gap.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-small-gap.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-double.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-single.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-wavy.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/list.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/option.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-break.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-mode.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-scale-add.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-scale-minus.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/painter.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-direction.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-margin.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-size.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/print.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/radio.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/redo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/request-fullscreen.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/right.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/row-margin.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/search.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/separator.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/signature-undo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/signature.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/size-add.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/size-minus.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/strikeout.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/subscript.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/superscript.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/table.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/title.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/trash.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/underline.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/undo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/watermark.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/word-tool.svg.js +4 -0
- package/dist/src/assets/images/clear.png.js +4 -0
- package/dist/src/assets/images/create_market_system.png.js +4 -0
- package/dist/src/assets/images/create_system.png.js +4 -0
- package/dist/src/assets/images/custom.png.js +4 -0
- package/dist/src/assets/images/default-icon.png.js +4 -0
- package/dist/src/assets/images/ex_link.png.js +4 -0
- package/dist/src/assets/images/excel.png.js +4 -0
- package/dist/src/assets/images/file.png.js +4 -0
- package/dist/src/assets/images/folder.png.js +4 -0
- package/dist/src/assets/images/hall/form.png.js +4 -0
- package/dist/src/assets/images/hall/meta.png.js +4 -0
- package/dist/src/assets/images/hall/process.png.js +4 -0
- package/dist/src/assets/images/hall/rule.png.js +4 -0
- package/dist/src/assets/images/hall/service.png.js +4 -0
- package/dist/src/assets/images/hall/userRole.png.js +4 -0
- package/dist/src/assets/images/hr.png.js +4 -0
- package/dist/src/assets/images/import.png.js +4 -0
- package/dist/src/assets/images/jian.png.js +4 -0
- package/dist/src/assets/images/module.png.js +4 -0
- package/dist/src/assets/images/null.png.js +4 -0
- package/dist/src/assets/images/photo.png.js +4 -0
- package/dist/src/assets/images/qq.png.js +4 -0
- package/dist/src/assets/images/robot.png.js +4 -0
- package/dist/src/assets/images/single_file.png.js +4 -0
- package/dist/src/assets/images/snapshot-history.png.js +4 -0
- package/dist/src/assets/images/snapshot-manual.png.js +4 -0
- package/dist/src/assets/images/snapshot-realtime.png.js +4 -0
- package/dist/src/assets/images/staff.png.js +4 -0
- package/dist/src/assets/images/switch_app.png.js +4 -0
- package/dist/src/assets/images/sync_append.png.js +4 -0
- package/dist/src/assets/images/sync_append_update.png.js +4 -0
- package/dist/src/assets/images/sync_loading.png.js +4 -0
- package/dist/src/assets/images/sync_replace.png.js +4 -0
- package/dist/src/assets/images/sync_update.png.js +4 -0
- package/dist/src/assets/images/user_bg.png.js +4 -0
- package/dist/src/assets/images/weixin.png.js +4 -0
- package/dist/src/chart-config-update.js +17 -0
- package/dist/src/chart-data-adapters.js +112 -0
- package/dist/src/chart-option-override.js +128 -0
- package/dist/src/chart-option-paths.js +64 -0
- package/dist/src/chart-registry.js +46 -0
- package/dist/src/chart-render-host.js +57 -0
- package/dist/src/chart-request-broker.js +176 -0
- package/dist/src/chartTheme.js +683 -0
- package/dist/src/collection.js +25 -0
- package/dist/src/date-helper.js +60 -0
- package/dist/src/dom-helper.js +22 -0
- package/dist/src/eval-with.js +14 -0
- package/dist/src/fieldFactory.js +5 -0
- package/dist/src/formula.js +365 -0
- package/dist/src/hljs-lite.js +29 -0
- package/dist/src/index.js +24 -0
- package/dist/src/lazy-jsencrypt.js +13 -0
- package/dist/src/legacy.js +25 -0
- package/dist/src/locale.js +88 -0
- package/dist/src/menu-open.js +43 -0
- package/dist/src/mermaid.js +79 -0
- package/dist/src/meta.js +4 -0
- package/dist/src/mobile-chart-appearance.js +148 -0
- package/dist/src/moment-compat.js +558 -0
- package/dist/src/nav-history.js +184 -0
- package/dist/src/page.js +116 -0
- package/dist/src/pdf.viewer.js +4 -0
- package/dist/src/placeholder.js +64 -0
- package/dist/src/public.js +49 -0
- package/dist/src/security.js +26 -0
- package/dist/src/storage.js +107 -0
- package/dist/src/token-storage.js +108 -0
- package/dist/src/util.js +4 -0
- package/package.json +109 -3
- package/src/Config.js +25 -0
- package/src/asset-images.js +16 -0
- package/src/chart-config-update.js +16 -0
- package/src/chart-data-adapters.js +106 -0
- package/src/chart-option-override.js +126 -0
- package/src/chart-option-paths.js +63 -0
- package/src/chart-registry.js +41 -0
- package/src/chart-render-host.js +56 -0
- package/src/chart-request-broker.js +171 -0
- package/src/chartTheme.js +711 -0
- package/src/collection.js +28 -0
- package/src/date-helper.js +72 -0
- package/src/dom-helper.js +26 -0
- package/src/eval-with.js +21 -0
- package/src/fieldFactory.js +3 -0
- package/src/formula.js +362 -0
- package/src/hljs-lite.js +41 -0
- package/src/index.js +2 -0
- package/src/lazy-jsencrypt.js +36 -0
- package/src/legacy.js +29 -0
- package/src/locale.js +104 -0
- package/src/menu-open.js +72 -0
- package/src/mermaid.js +115 -0
- package/src/meta.js +2 -0
- package/src/mobile-chart-appearance.js +147 -0
- package/src/moment-compat.d.ts +91 -0
- package/src/moment-compat.js +744 -0
- package/src/nav-history.js +274 -0
- package/src/page.js +129 -0
- package/src/pdf.viewer.js +2 -0
- package/src/placeholder.js +107 -0
- package/src/public.js +11 -0
- package/src/security.js +29 -0
- package/src/storage.js +135 -0
- package/src/token-storage.js +120 -0
- package/src/util.js +2 -0
- package/types/Config.d.ts +4 -0
- package/types/collection.d.ts +40 -0
- package/types/date-helper.d.ts +11 -0
- package/types/date-time.d.ts +2 -0
- package/types/date.d.ts +1 -0
- package/types/dom-helper.d.ts +3 -0
- package/types/dom.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/moment-compat.d.ts +91 -0
- package/types/page.d.ts +56 -0
- package/types/placeholder.d.ts +42 -0
- package/types/public.d.ts +10 -0
- package/types/storage.d.ts +31 -0
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import "dayjs/locale/zh-cn.js";
|
|
3
|
+
import relativeTime from "dayjs/plugin/relativeTime.js";
|
|
4
|
+
import duration from "dayjs/plugin/duration.js";
|
|
5
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
6
|
+
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
7
|
+
import localizedFormat from "dayjs/plugin/localizedFormat.js";
|
|
8
|
+
import calendarPlugin from "dayjs/plugin/calendar.js";
|
|
9
|
+
import objectSupport from "dayjs/plugin/objectSupport.js";
|
|
10
|
+
import arraySupport from "dayjs/plugin/arraySupport.js";
|
|
11
|
+
import utcPlugin from "dayjs/plugin/utc.js";
|
|
12
|
+
import minMax from "dayjs/plugin/minMax.js";
|
|
13
|
+
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
|
|
14
|
+
import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";
|
|
15
|
+
import isBetween from "dayjs/plugin/isBetween.js";
|
|
16
|
+
import isLeapYear from "dayjs/plugin/isLeapYear.js";
|
|
17
|
+
import weekOfYear from "dayjs/plugin/weekOfYear.js";
|
|
18
|
+
import isoWeek from "dayjs/plugin/isoWeek.js";
|
|
19
|
+
import quarterOfYear from "dayjs/plugin/quarterOfYear.js";
|
|
20
|
+
import dayOfYear from "dayjs/plugin/dayOfYear.js";
|
|
21
|
+
import weekday from "dayjs/plugin/weekday.js";
|
|
22
|
+
import toArray from "dayjs/plugin/toArray.js";
|
|
23
|
+
import toObject from "dayjs/plugin/toObject.js";
|
|
24
|
+
for (const p of [
|
|
25
|
+
relativeTime,
|
|
26
|
+
duration,
|
|
27
|
+
customParseFormat,
|
|
28
|
+
advancedFormat,
|
|
29
|
+
localizedFormat,
|
|
30
|
+
calendarPlugin,
|
|
31
|
+
arraySupport,
|
|
32
|
+
utcPlugin,
|
|
33
|
+
minMax,
|
|
34
|
+
isSameOrBefore,
|
|
35
|
+
isSameOrAfter,
|
|
36
|
+
isBetween,
|
|
37
|
+
isLeapYear,
|
|
38
|
+
weekOfYear,
|
|
39
|
+
isoWeek,
|
|
40
|
+
quarterOfYear,
|
|
41
|
+
dayOfYear,
|
|
42
|
+
weekday,
|
|
43
|
+
toArray,
|
|
44
|
+
toObject,
|
|
45
|
+
objectSupport
|
|
46
|
+
]) {
|
|
47
|
+
dayjs.extend(p);
|
|
48
|
+
}
|
|
49
|
+
dayjs.locale("zh-cn");
|
|
50
|
+
dayjs.Ls["zh-cn"].relativeTime.future = "%s后";
|
|
51
|
+
dayjs.Ls["zh-cn"].meridiem = (hour, minute) => {
|
|
52
|
+
const hm = hour * 100 + minute;
|
|
53
|
+
if (hm < 600) return "凌晨";
|
|
54
|
+
if (hm < 900) return "早上";
|
|
55
|
+
if (hm < 1130) return "上午";
|
|
56
|
+
if (hm < 1230) return "中午";
|
|
57
|
+
if (hm < 1800) return "下午";
|
|
58
|
+
return "晚上";
|
|
59
|
+
};
|
|
60
|
+
dayjs.Ls["zh-cn"].calendar = {
|
|
61
|
+
sameDay: "[今天]LT",
|
|
62
|
+
nextDay: "[明天]LT",
|
|
63
|
+
nextWeek(now) {
|
|
64
|
+
return this.format(now.week() !== this.week() ? "[下]dddLT" : "[本]dddLT");
|
|
65
|
+
},
|
|
66
|
+
lastDay: "[昨天]LT",
|
|
67
|
+
lastWeek(now) {
|
|
68
|
+
return this.format(this.week() !== now.week() ? "[上]dddLT" : "[本]dddLT");
|
|
69
|
+
},
|
|
70
|
+
sameElse: "L"
|
|
71
|
+
};
|
|
72
|
+
const READ_METHODS = [
|
|
73
|
+
"format",
|
|
74
|
+
"valueOf",
|
|
75
|
+
"unix",
|
|
76
|
+
"toDate",
|
|
77
|
+
"toISOString",
|
|
78
|
+
"toJSON",
|
|
79
|
+
"toString",
|
|
80
|
+
"toArray",
|
|
81
|
+
"toObject",
|
|
82
|
+
"diff",
|
|
83
|
+
"isValid",
|
|
84
|
+
"isBefore",
|
|
85
|
+
"isAfter",
|
|
86
|
+
"isSame",
|
|
87
|
+
"isSameOrBefore",
|
|
88
|
+
"isSameOrAfter",
|
|
89
|
+
"isBetween",
|
|
90
|
+
"isLeapYear",
|
|
91
|
+
"daysInMonth",
|
|
92
|
+
"clone",
|
|
93
|
+
"get",
|
|
94
|
+
"from",
|
|
95
|
+
"to",
|
|
96
|
+
"fromNow",
|
|
97
|
+
"toNow",
|
|
98
|
+
"utcOffset",
|
|
99
|
+
"weekday",
|
|
100
|
+
"isoWeekday",
|
|
101
|
+
// `calendar` 是本仓自己的页面 JS 编写指南(.claude/skills/epx-frame-web/tools/Moment日期.md)
|
|
102
|
+
// 教过的写法,漏了它等于指南里的示例一跑就抛错。
|
|
103
|
+
"calendar"
|
|
104
|
+
];
|
|
105
|
+
const WRITE_METHODS = [
|
|
106
|
+
"add",
|
|
107
|
+
"subtract",
|
|
108
|
+
"startOf",
|
|
109
|
+
"endOf",
|
|
110
|
+
"set",
|
|
111
|
+
"local",
|
|
112
|
+
"utc",
|
|
113
|
+
"locale",
|
|
114
|
+
"year",
|
|
115
|
+
"month",
|
|
116
|
+
"date",
|
|
117
|
+
"day",
|
|
118
|
+
"hour",
|
|
119
|
+
"minute",
|
|
120
|
+
"second",
|
|
121
|
+
"millisecond",
|
|
122
|
+
"quarter",
|
|
123
|
+
"week",
|
|
124
|
+
"isoWeek",
|
|
125
|
+
"dayOfYear"
|
|
126
|
+
];
|
|
127
|
+
const DUAL_METHODS = /* @__PURE__ */ new Set([
|
|
128
|
+
"locale",
|
|
129
|
+
"year",
|
|
130
|
+
"month",
|
|
131
|
+
"date",
|
|
132
|
+
"day",
|
|
133
|
+
"hour",
|
|
134
|
+
"minute",
|
|
135
|
+
"second",
|
|
136
|
+
"millisecond",
|
|
137
|
+
"quarter",
|
|
138
|
+
"week",
|
|
139
|
+
"isoWeek",
|
|
140
|
+
"dayOfYear"
|
|
141
|
+
]);
|
|
142
|
+
const PASSTHROUGH = /* @__PURE__ */ new Set([
|
|
143
|
+
"then",
|
|
144
|
+
"nodeType",
|
|
145
|
+
"tagName",
|
|
146
|
+
"length",
|
|
147
|
+
"name",
|
|
148
|
+
"constructor",
|
|
149
|
+
"hasOwnProperty",
|
|
150
|
+
"isPrototypeOf",
|
|
151
|
+
"propertyIsEnumerable",
|
|
152
|
+
"__v_isRef",
|
|
153
|
+
"__v_isReactive",
|
|
154
|
+
"__v_isReadonly",
|
|
155
|
+
"__v_raw",
|
|
156
|
+
"__v_skip",
|
|
157
|
+
"_isAMomentObject",
|
|
158
|
+
"_d",
|
|
159
|
+
"$$typeof"
|
|
160
|
+
]);
|
|
161
|
+
class MomentLike {
|
|
162
|
+
constructor(d) {
|
|
163
|
+
this._d = d;
|
|
164
|
+
this.__v_skip = true;
|
|
165
|
+
this._isAMomentObject = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function wrapMaybe(v) {
|
|
169
|
+
return dayjs.isDayjs(v) ? createMoment(v) : v;
|
|
170
|
+
}
|
|
171
|
+
function unwrapMaybe(v) {
|
|
172
|
+
return v && v._d ? v._d : v;
|
|
173
|
+
}
|
|
174
|
+
for (const name of READ_METHODS) {
|
|
175
|
+
MomentLike.prototype[name] = function(...args) {
|
|
176
|
+
return wrapMaybe(this._d[name](...args.map(unwrapMaybe)));
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const INVALID = "Invalid date";
|
|
180
|
+
const INVALID_FALLBACKS = {
|
|
181
|
+
toISOString: null,
|
|
182
|
+
isoWeekday: NaN,
|
|
183
|
+
calendar: INVALID,
|
|
184
|
+
from: INVALID,
|
|
185
|
+
to: INVALID,
|
|
186
|
+
fromNow: INVALID,
|
|
187
|
+
toNow: INVALID
|
|
188
|
+
};
|
|
189
|
+
const CHECKS_ARG = /* @__PURE__ */ new Set(["from", "to"]);
|
|
190
|
+
for (const [name, fallback] of Object.entries(INVALID_FALLBACKS)) {
|
|
191
|
+
const raw = MomentLike.prototype[name];
|
|
192
|
+
MomentLike.prototype[name] = function(...args) {
|
|
193
|
+
if (!this._d.isValid()) return fallback;
|
|
194
|
+
if (CHECKS_ARG.has(name) && args[0] !== void 0) {
|
|
195
|
+
const other = unwrapMaybe(args[0]);
|
|
196
|
+
if (!dayjs(other).isValid()) return fallback;
|
|
197
|
+
}
|
|
198
|
+
return raw.apply(this, args);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const UNSUPPORTED_FORMAT_TOKENS = [
|
|
202
|
+
"DDDo",
|
|
203
|
+
"DDDD",
|
|
204
|
+
"DDD",
|
|
205
|
+
"Mo",
|
|
206
|
+
"Qo",
|
|
207
|
+
"do",
|
|
208
|
+
"Wo",
|
|
209
|
+
"gggg",
|
|
210
|
+
"gg",
|
|
211
|
+
"GG",
|
|
212
|
+
"NN",
|
|
213
|
+
"N",
|
|
214
|
+
"zz",
|
|
215
|
+
"z",
|
|
216
|
+
"E",
|
|
217
|
+
"e"
|
|
218
|
+
];
|
|
219
|
+
const FORMAT_SCAN_RE = new RegExp(
|
|
220
|
+
["\\[[^\\]]*\\]", "LTS", "GGGG", ...UNSUPPORTED_FORMAT_TOKENS, "S+", "y{1,4}"].join("|"),
|
|
221
|
+
"g"
|
|
222
|
+
);
|
|
223
|
+
function preprocessFormat(fmt, ms, year) {
|
|
224
|
+
if (typeof fmt !== "string") return fmt;
|
|
225
|
+
return fmt.replace(FORMAT_SCAN_RE, (seg) => {
|
|
226
|
+
if (seg[0] === "[" || seg === "LTS" || seg === "GGGG") return seg;
|
|
227
|
+
if (seg[0] === "S") {
|
|
228
|
+
if (seg.length === 3) return seg;
|
|
229
|
+
if (seg.length === 1) return String(Math.floor(ms / 100));
|
|
230
|
+
if (seg.length === 2) return String(Math.floor(ms / 10)).padStart(2, "0");
|
|
231
|
+
return String(ms).padStart(3, "0").padEnd(seg.length, "0");
|
|
232
|
+
}
|
|
233
|
+
if (seg[0] === "y") {
|
|
234
|
+
const sign = year < 0 ? "-" : "";
|
|
235
|
+
return sign + String(Math.abs(year)).padStart(seg.length, "0");
|
|
236
|
+
}
|
|
237
|
+
throw new Error(
|
|
238
|
+
`[epx-moment] format 串里的 \`${seg}\` 不在兼容层覆盖范围内。
|
|
239
|
+
本平台已从 moment 迁移到 dayjs,$moment 是一层兼容 shim。
|
|
240
|
+
dayjs 对这个 token 会静默给出错值(或抛一个读不懂的内部错),所以这里主动拦下——
|
|
241
|
+
想输出字面量 "${seg}" 请写成 [${seg}](方括号是 moment/dayjs 通用的转义)。
|
|
242
|
+
确实需要这个 token 请补进 packages/utils/src/moment-compat.js;
|
|
243
|
+
临时可用 $moment(x).toDate() 拿到原生 Date 自行处理。`
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
MomentLike.prototype.format = function(fmt) {
|
|
248
|
+
if (!this._d.isValid()) return INVALID;
|
|
249
|
+
return this._d.format(preprocessFormat(fmt, this._d.millisecond(), this._d.year()));
|
|
250
|
+
};
|
|
251
|
+
MomentLike.prototype.toString = function() {
|
|
252
|
+
if (!this._d.isValid()) return INVALID;
|
|
253
|
+
return this._d.locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
|
|
254
|
+
};
|
|
255
|
+
for (const name of WRITE_METHODS) {
|
|
256
|
+
MomentLike.prototype[name] = function(...args) {
|
|
257
|
+
if (DUAL_METHODS.has(name) && args.length === 0) return this._d[name]();
|
|
258
|
+
this._d = this._d[name](...args.map(unwrapMaybe));
|
|
259
|
+
return this;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const UNIT_ALIASES = {
|
|
263
|
+
D: "date",
|
|
264
|
+
dates: "date",
|
|
265
|
+
date: "date",
|
|
266
|
+
d: "day",
|
|
267
|
+
days: "day",
|
|
268
|
+
day: "day",
|
|
269
|
+
e: "weekday",
|
|
270
|
+
weekdays: "weekday",
|
|
271
|
+
weekday: "weekday",
|
|
272
|
+
E: "isoWeekday",
|
|
273
|
+
isoweekdays: "isoWeekday",
|
|
274
|
+
isoweekday: "isoWeekday",
|
|
275
|
+
DDD: "dayOfYear",
|
|
276
|
+
dayofyears: "dayOfYear",
|
|
277
|
+
dayofyear: "dayOfYear",
|
|
278
|
+
h: "hour",
|
|
279
|
+
hours: "hour",
|
|
280
|
+
hour: "hour",
|
|
281
|
+
ms: "millisecond",
|
|
282
|
+
milliseconds: "millisecond",
|
|
283
|
+
millisecond: "millisecond",
|
|
284
|
+
m: "minute",
|
|
285
|
+
minutes: "minute",
|
|
286
|
+
minute: "minute",
|
|
287
|
+
M: "month",
|
|
288
|
+
months: "month",
|
|
289
|
+
month: "month",
|
|
290
|
+
Q: "quarter",
|
|
291
|
+
quarters: "quarter",
|
|
292
|
+
quarter: "quarter",
|
|
293
|
+
s: "second",
|
|
294
|
+
seconds: "second",
|
|
295
|
+
second: "second",
|
|
296
|
+
w: "week",
|
|
297
|
+
weeks: "week",
|
|
298
|
+
week: "week",
|
|
299
|
+
W: "isoWeek",
|
|
300
|
+
isoweeks: "isoWeek",
|
|
301
|
+
isoweek: "isoWeek",
|
|
302
|
+
y: "year",
|
|
303
|
+
years: "year",
|
|
304
|
+
year: "year"
|
|
305
|
+
};
|
|
306
|
+
const UNIT_PRIORITY = {
|
|
307
|
+
year: 1,
|
|
308
|
+
dayOfYear: 4,
|
|
309
|
+
week: 5,
|
|
310
|
+
isoWeek: 5,
|
|
311
|
+
quarter: 7,
|
|
312
|
+
month: 8,
|
|
313
|
+
date: 9,
|
|
314
|
+
day: 11,
|
|
315
|
+
weekday: 11,
|
|
316
|
+
isoWeekday: 11,
|
|
317
|
+
hour: 13,
|
|
318
|
+
minute: 14,
|
|
319
|
+
second: 15,
|
|
320
|
+
millisecond: 16
|
|
321
|
+
};
|
|
322
|
+
const UNIT_SETTER = {
|
|
323
|
+
year: (d, v) => d.year(v),
|
|
324
|
+
month: (d, v) => d.month(v),
|
|
325
|
+
date: (d, v) => d.date(v),
|
|
326
|
+
day: (d, v) => d.day(v),
|
|
327
|
+
weekday: (d, v) => d.weekday(v),
|
|
328
|
+
isoWeekday: (d, v) => d.isoWeekday(v),
|
|
329
|
+
hour: (d, v) => d.hour(v),
|
|
330
|
+
minute: (d, v) => d.minute(v),
|
|
331
|
+
second: (d, v) => d.second(v),
|
|
332
|
+
millisecond: (d, v) => d.millisecond(v),
|
|
333
|
+
quarter: (d, v) => d.quarter(v),
|
|
334
|
+
week: (d, v) => d.week(v),
|
|
335
|
+
isoWeek: (d, v) => d.isoWeek(v),
|
|
336
|
+
dayOfYear: (d, v) => d.dayOfYear(v)
|
|
337
|
+
};
|
|
338
|
+
MomentLike.prototype.set = function(unit, value) {
|
|
339
|
+
if (unit === null || typeof unit !== "object") {
|
|
340
|
+
this._d = this._d.set(unit, value);
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
const pending = [];
|
|
344
|
+
for (const key of Object.keys(unit)) {
|
|
345
|
+
const u = UNIT_ALIASES[key] || UNIT_ALIASES[String(key).toLowerCase()];
|
|
346
|
+
if (u) pending.push([u, unit[key]]);
|
|
347
|
+
}
|
|
348
|
+
pending.sort((a, b) => UNIT_PRIORITY[a[0]] - UNIT_PRIORITY[b[0]]);
|
|
349
|
+
for (const [u, v] of pending) this._d = UNIT_SETTER[u](this._d, v);
|
|
350
|
+
return this;
|
|
351
|
+
};
|
|
352
|
+
const ALLOWED = /* @__PURE__ */ new Set([...READ_METHODS, ...WRITE_METHODS]);
|
|
353
|
+
function createMoment(input, ...rest) {
|
|
354
|
+
let d;
|
|
355
|
+
if (arguments.length === 0) d = dayjs();
|
|
356
|
+
else if (input && input._d) d = input._d;
|
|
357
|
+
else if (dayjs.isDayjs(input)) d = input;
|
|
358
|
+
else d = dayjs(input, ...rest);
|
|
359
|
+
const inst = new MomentLike(d);
|
|
360
|
+
return new Proxy(inst, {
|
|
361
|
+
get(target, prop, receiver) {
|
|
362
|
+
if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
|
|
363
|
+
if (ALLOWED.has(prop) || PASSTHROUGH.has(prop) || Object.prototype.hasOwnProperty.call(target, prop)) {
|
|
364
|
+
return Reflect.get(target, prop, receiver);
|
|
365
|
+
}
|
|
366
|
+
throw new Error(
|
|
367
|
+
`[epx-moment] \`$moment(...).${prop}\` 不在兼容层覆盖范围内。
|
|
368
|
+
本平台已从 moment 迁移到 dayjs,$moment 是一层兼容 shim。
|
|
369
|
+
需要这个 API 请补进 packages/utils/src/moment-compat.js;
|
|
370
|
+
临时可用 $moment(x).toDate() 拿到原生 Date 自行处理。`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const DURATION_THRESHOLDS = { ss: 44, s: 45, m: 45, h: 22, d: 26, M: 11 };
|
|
376
|
+
const daysToMonths = (days) => days * 4800 / 146097;
|
|
377
|
+
const monthsToDays = (months) => months * 146097 / 4800;
|
|
378
|
+
function durationBuckets(d) {
|
|
379
|
+
const b = d.$d || {};
|
|
380
|
+
const ms = d.$ms || 0;
|
|
381
|
+
const exact = !b.days && !b.hours && !b.minutes && !b.seconds && !b.milliseconds && !b.weeks && (b.years || b.months);
|
|
382
|
+
return exact ? { ms: 0, months: (b.years || 0) * 12 + (b.months || 0) } : { ms, months: 0 };
|
|
383
|
+
}
|
|
384
|
+
function durationAs(d, unit) {
|
|
385
|
+
const { ms, months } = durationBuckets(d);
|
|
386
|
+
if (unit === "month" || unit === "quarter" || unit === "year") {
|
|
387
|
+
const m = months + daysToMonths(ms / 864e5);
|
|
388
|
+
return unit === "month" ? m : unit === "quarter" ? m / 3 : m / 12;
|
|
389
|
+
}
|
|
390
|
+
const days = Math.round(monthsToDays(months));
|
|
391
|
+
switch (unit) {
|
|
392
|
+
case "week":
|
|
393
|
+
return days / 7 + ms / 6048e5;
|
|
394
|
+
case "day":
|
|
395
|
+
return days + ms / 864e5;
|
|
396
|
+
case "hour":
|
|
397
|
+
return days * 24 + ms / 36e5;
|
|
398
|
+
case "minute":
|
|
399
|
+
return days * 1440 + ms / 6e4;
|
|
400
|
+
case "second":
|
|
401
|
+
return days * 86400 + ms / 1e3;
|
|
402
|
+
case "millisecond":
|
|
403
|
+
return Math.floor(days * 864e5) + ms;
|
|
404
|
+
// ⚠️ 不要把这个 default 写成"当毫秒处理"——那就是本次要消灭的那种静默错值
|
|
405
|
+
// (`as('bogus')` 会安静地返回一个毫秒数)。moment 在这里也是抛 `Unknown unit`。
|
|
406
|
+
default:
|
|
407
|
+
throw new Error(
|
|
408
|
+
`[epx-moment] \`$moment.duration(...).as('${unit}')\` 的单位无法识别。
|
|
409
|
+
可用单位:ms/s/m/h/d/w/M/Q/y(或它们的完整名,大小写敏感:M=月、m=分钟)。`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const DURATION_UNITS = {
|
|
414
|
+
ms: "millisecond",
|
|
415
|
+
millisecond: "millisecond",
|
|
416
|
+
milliseconds: "millisecond",
|
|
417
|
+
s: "second",
|
|
418
|
+
second: "second",
|
|
419
|
+
seconds: "second",
|
|
420
|
+
m: "minute",
|
|
421
|
+
minute: "minute",
|
|
422
|
+
minutes: "minute",
|
|
423
|
+
h: "hour",
|
|
424
|
+
hour: "hour",
|
|
425
|
+
hours: "hour",
|
|
426
|
+
d: "day",
|
|
427
|
+
day: "day",
|
|
428
|
+
days: "day",
|
|
429
|
+
w: "week",
|
|
430
|
+
week: "week",
|
|
431
|
+
weeks: "week",
|
|
432
|
+
M: "month",
|
|
433
|
+
month: "month",
|
|
434
|
+
months: "month",
|
|
435
|
+
Q: "quarter",
|
|
436
|
+
quarter: "quarter",
|
|
437
|
+
quarters: "quarter",
|
|
438
|
+
y: "year",
|
|
439
|
+
year: "year",
|
|
440
|
+
years: "year"
|
|
441
|
+
};
|
|
442
|
+
const normalizeDurationUnit = (u) => typeof u === "string" && (DURATION_UNITS[u] || DURATION_UNITS[u.toLowerCase()]) || u;
|
|
443
|
+
const AS_METHODS = {
|
|
444
|
+
asMilliseconds: "millisecond",
|
|
445
|
+
asSeconds: "second",
|
|
446
|
+
asMinutes: "minute",
|
|
447
|
+
asHours: "hour",
|
|
448
|
+
asDays: "day",
|
|
449
|
+
asWeeks: "week",
|
|
450
|
+
asMonths: "month",
|
|
451
|
+
asQuarters: "quarter",
|
|
452
|
+
asYears: "year"
|
|
453
|
+
};
|
|
454
|
+
function classifyDuration(d) {
|
|
455
|
+
const abs = Math.abs(d.$ms || 0);
|
|
456
|
+
const t = DURATION_THRESHOLDS;
|
|
457
|
+
const seconds = Math.round(abs / 1e3);
|
|
458
|
+
const minutes = Math.round(abs / 6e4);
|
|
459
|
+
const hours = Math.round(abs / 36e5);
|
|
460
|
+
const days = Math.round(abs / 864e5);
|
|
461
|
+
const monthsExact = Math.abs(durationAs(d, "month"));
|
|
462
|
+
const months = Math.round(monthsExact);
|
|
463
|
+
const years = Math.round(monthsExact / 12);
|
|
464
|
+
return seconds <= t.ss && ["s", seconds] || seconds < t.s && ["ss", seconds] || minutes <= 1 && ["m", 1] || minutes < t.m && ["mm", minutes] || hours <= 1 && ["h", 1] || hours < t.h && ["hh", hours] || days <= 1 && ["d", 1] || days < t.d && ["dd", days] || months <= 1 && ["M", 1] || months < t.M && ["MM", months] || years <= 1 && ["y", 1] || ["yy", years];
|
|
465
|
+
}
|
|
466
|
+
function humanizeDuration(d, withSuffix) {
|
|
467
|
+
const [key, count] = classifyDuration(d);
|
|
468
|
+
const rt = dayjs.Ls[d.$l].relativeTime;
|
|
469
|
+
const text = rt[key].replace("%d", count);
|
|
470
|
+
if (!withSuffix) return text;
|
|
471
|
+
return ((d.$ms || 0) > 0 ? rt.future : rt.past).replace("%s", text);
|
|
472
|
+
}
|
|
473
|
+
function patchDuration(d) {
|
|
474
|
+
if (d.__patched) return d;
|
|
475
|
+
d.__patched = true;
|
|
476
|
+
d.humanize = (withSuffix) => humanizeDuration(d, withSuffix);
|
|
477
|
+
d.as = (unit) => durationAs(d, normalizeDurationUnit(unit));
|
|
478
|
+
for (const [name, unit] of Object.entries(AS_METHODS)) d[name] = () => durationAs(d, unit);
|
|
479
|
+
for (const name of ["add", "subtract", "clone", "locale"]) {
|
|
480
|
+
const raw = d[name].bind(d);
|
|
481
|
+
d[name] = (...args) => patchDuration(raw(...args));
|
|
482
|
+
}
|
|
483
|
+
return d;
|
|
484
|
+
}
|
|
485
|
+
const QUARTER_KEYS = ["Q", "quarter", "quarters"];
|
|
486
|
+
function normalizeDurationArgs(args) {
|
|
487
|
+
const [input, unit] = args;
|
|
488
|
+
if (normalizeDurationUnit(unit) === "quarter") return [(input ?? 0) * 3, "M"];
|
|
489
|
+
if (input && typeof input === "object" && !(input instanceof Date) && !Array.isArray(input)) {
|
|
490
|
+
const q = QUARTER_KEYS.reduce((sum, k) => sum + (input[k] || 0), 0);
|
|
491
|
+
if (q) {
|
|
492
|
+
const rest = { ...input };
|
|
493
|
+
for (const k of QUARTER_KEYS) delete rest[k];
|
|
494
|
+
return [{ ...rest, months: (rest.months || 0) + q * 3 }, ...args.slice(1)];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return [input ?? 0, ...args.slice(1)];
|
|
498
|
+
}
|
|
499
|
+
createMoment.duration = (...args) => patchDuration(dayjs.duration(...normalizeDurationArgs(args)));
|
|
500
|
+
createMoment.locale = (...args) => dayjs.locale(...args);
|
|
501
|
+
createMoment.isMoment = (v) => !!(v && v._isAMomentObject === true);
|
|
502
|
+
createMoment.unix = (sec) => createMoment(dayjs.unix(sec));
|
|
503
|
+
createMoment.utc = (...args) => createMoment(dayjs.utc(...args));
|
|
504
|
+
createMoment.max = (...args) => createMoment(dayjs.max(args.flat().map(unwrapMaybe)));
|
|
505
|
+
createMoment.min = (...args) => createMoment(dayjs.min(args.flat().map(unwrapMaybe)));
|
|
506
|
+
const STATIC_ALLOWED = /* @__PURE__ */ new Set(["duration", "locale", "isMoment", "unix", "max", "min", "utc"]);
|
|
507
|
+
const STATIC_PASSTHROUGH = /* @__PURE__ */ new Set([
|
|
508
|
+
"name",
|
|
509
|
+
"length",
|
|
510
|
+
"prototype",
|
|
511
|
+
"call",
|
|
512
|
+
"apply",
|
|
513
|
+
"bind",
|
|
514
|
+
"toString",
|
|
515
|
+
"valueOf",
|
|
516
|
+
"constructor",
|
|
517
|
+
"hasOwnProperty",
|
|
518
|
+
"isPrototypeOf",
|
|
519
|
+
"propertyIsEnumerable",
|
|
520
|
+
"then",
|
|
521
|
+
"toJSON",
|
|
522
|
+
"default",
|
|
523
|
+
"__esModule",
|
|
524
|
+
"nodeType",
|
|
525
|
+
"tagName",
|
|
526
|
+
"$$typeof",
|
|
527
|
+
"__v_isRef",
|
|
528
|
+
"__v_isReactive",
|
|
529
|
+
"__v_isReadonly",
|
|
530
|
+
"__v_raw",
|
|
531
|
+
"__v_skip",
|
|
532
|
+
"_isAMomentObject"
|
|
533
|
+
]);
|
|
534
|
+
const momentCompat = new Proxy(createMoment, {
|
|
535
|
+
get(target, prop, receiver) {
|
|
536
|
+
if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
|
|
537
|
+
if (STATIC_ALLOWED.has(prop) || STATIC_PASSTHROUGH.has(prop)) {
|
|
538
|
+
return Reflect.get(target, prop, receiver);
|
|
539
|
+
}
|
|
540
|
+
throw new Error(
|
|
541
|
+
`[epx-moment] \`$moment.${prop}\` 不在兼容层覆盖范围内。
|
|
542
|
+
本平台已从 moment 迁移到 dayjs,$moment 是一层兼容 shim。
|
|
543
|
+
静态面只覆盖 ${[...STATIC_ALLOWED].join(" / ")}。
|
|
544
|
+
需要这个 API 请补进 packages/utils/src/moment-compat.js;
|
|
545
|
+
临时可用 $moment(x).toDate() 拿到原生 Date 自行处理。`
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
export {
|
|
550
|
+
DUAL_METHODS,
|
|
551
|
+
PASSTHROUGH,
|
|
552
|
+
READ_METHODS,
|
|
553
|
+
UNSUPPORTED_FORMAT_TOKENS,
|
|
554
|
+
WRITE_METHODS,
|
|
555
|
+
momentCompat as createMoment,
|
|
556
|
+
momentCompat as default,
|
|
557
|
+
preprocessFormat
|
|
558
|
+
};
|