@lichta/event-calendar 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/index.cjs +87 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zeforc Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @lichta/event-calendar
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@lichta/event-calendar)
|
|
4
|
+
|
|
5
|
+
Plugin/Adapter tích hợp lịch âm Việt Nam (LichTa) vào thư viện [EventCalendar](https://github.com/vkurko/calendar).
|
|
6
|
+
|
|
7
|
+
## Cài đặt
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @lichta/event-calendar @event-calendar/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Cách sử dụng cơ bản
|
|
14
|
+
|
|
15
|
+
Bạn chỉ cần bọc cấu hình gốc của EventCalendar bằng hàm `injectLunarDates`. Adapter sẽ tự động tính toán và tiêm (inject) ngày âm lịch vào các ô ngày trên giao diện lịch.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import Calendar from '@event-calendar/core';
|
|
19
|
+
import DayGrid from '@event-calendar/day-grid';
|
|
20
|
+
import { injectLunarDates } from '@lichta/event-calendar';
|
|
21
|
+
|
|
22
|
+
const calendarOptions = injectLunarDates({
|
|
23
|
+
target: document.getElementById('calendar'),
|
|
24
|
+
plugins: [DayGrid],
|
|
25
|
+
options: {
|
|
26
|
+
view: 'dayGridMonth'
|
|
27
|
+
// ... các options gốc của EventCalendar
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let calendar = new Calendar(calendarOptions);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Tùy chọn giao diện (Options)
|
|
35
|
+
|
|
36
|
+
Hàm `injectLunarDates(options, pluginOptions)` nhận đối số thứ hai để cấu hình giao diện cho ngày âm lịch:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const calendarOptions = injectLunarDates(baseOptions, {
|
|
40
|
+
// Chỉ hiển thị tháng khi là mùng 1 (vd: "1/4" thay vì "1")
|
|
41
|
+
monthOnFirstDayOnly: false,
|
|
42
|
+
|
|
43
|
+
// Hiển thị "(Nhuận)" cho các tháng nhuận âm lịch
|
|
44
|
+
showLeapMonth: true,
|
|
45
|
+
|
|
46
|
+
// Hiển thị Can Chi khi hover chuột vào (Tooltip)
|
|
47
|
+
showTooltip: true,
|
|
48
|
+
|
|
49
|
+
// Tùy chỉnh màu chữ
|
|
50
|
+
color: '#888',
|
|
51
|
+
|
|
52
|
+
// Tùy chỉnh class CSS (hữu ích khi dùng Tailwind)
|
|
53
|
+
className: 'lichta-ec-lunar',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Tùy chỉnh hoàn toàn bằng hàm `render`
|
|
58
|
+
|
|
59
|
+
Nếu bạn muốn kiểm soát hoàn toàn mã HTML của phần hiển thị ngày âm lịch, hãy sử dụng thuộc tính `render`:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const calendarOptions = injectLunarDates(baseOptions, {
|
|
63
|
+
render: (lunarDate) => {
|
|
64
|
+
return `<div class="custom-lunar">
|
|
65
|
+
🌙 ${lunarDate.day}/${lunarDate.month}
|
|
66
|
+
</div>`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Phụ thuộc (Dependencies)
|
|
72
|
+
- **@lichta/core**: workspace dependency (tự động cài kèm)
|
|
73
|
+
- **@event-calendar/core**: ^3.0.0 (peer dependency)
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[MIT](./LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
injectLunarDates: () => injectLunarDates
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_core = require("@lichta/core");
|
|
27
|
+
function injectLunarDates(options, pluginOptions = {}) {
|
|
28
|
+
const originalDayCellContent = options.dayCellContent;
|
|
29
|
+
const {
|
|
30
|
+
monthOnFirstDayOnly = false,
|
|
31
|
+
showLeapMonth = true,
|
|
32
|
+
showTooltip = true,
|
|
33
|
+
color = "#888",
|
|
34
|
+
className = "lichta-ec-lunar",
|
|
35
|
+
render
|
|
36
|
+
} = pluginOptions;
|
|
37
|
+
options.dayCellContent = function(arg) {
|
|
38
|
+
const date = arg.date;
|
|
39
|
+
const day = date.getDate();
|
|
40
|
+
const month = date.getMonth() + 1;
|
|
41
|
+
const year = date.getFullYear();
|
|
42
|
+
const lunar = import_core.LichTa.toLunar(day, month, year);
|
|
43
|
+
let customLunarHtml = "";
|
|
44
|
+
if (render) {
|
|
45
|
+
customLunarHtml = render(lunar);
|
|
46
|
+
} else {
|
|
47
|
+
let lunarText = `${lunar.day}`;
|
|
48
|
+
if (!monthOnFirstDayOnly || lunar.day === 1) {
|
|
49
|
+
lunarText = `${lunar.day}/${lunar.month}`;
|
|
50
|
+
}
|
|
51
|
+
if (showLeapMonth && lunar.isLeap) {
|
|
52
|
+
lunarText += " (Nhu\u1EADn)";
|
|
53
|
+
}
|
|
54
|
+
let tooltipAttr = "";
|
|
55
|
+
if (showTooltip) {
|
|
56
|
+
const canChi = (0, import_core.getDayCanChi)(lunar.jd);
|
|
57
|
+
tooltipAttr = `title="Ng\xE0y ${canChi}"`;
|
|
58
|
+
}
|
|
59
|
+
customLunarHtml = `<div class="${className}" style="font-size: 0.8em; color: ${color}; margin-top: 2px;" ${tooltipAttr}>${lunarText}</div>`;
|
|
60
|
+
}
|
|
61
|
+
let originalContent = "";
|
|
62
|
+
if (originalDayCellContent) {
|
|
63
|
+
const orig = typeof originalDayCellContent === "function" ? originalDayCellContent(arg) : originalDayCellContent;
|
|
64
|
+
if (orig?.html) {
|
|
65
|
+
originalContent = orig.html;
|
|
66
|
+
} else {
|
|
67
|
+
originalContent = orig;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
originalContent = `<div class="ec-day-head">${day}</div>`;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
html: `
|
|
74
|
+
<div class="lichta-ec-cell" style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
|
|
75
|
+
${originalContent}
|
|
76
|
+
${customLunarHtml}
|
|
77
|
+
</div>
|
|
78
|
+
`
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
injectLunarDates
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { LichTa, getDayCanChi } from '@lichta/core';\nimport type { LunarDate } from '@lichta/core';\n\nexport interface LichTaOptions {\n /**\n * Chỉ hiển thị tháng khi là mùng 1 âm lịch (ví dụ: \"1/4\" thay vì \"1\").\n * Mặc định: false\n */\n monthOnFirstDayOnly?: boolean;\n\n /**\n * Hiển thị chữ \"Nhuận\" nếu rơi vào tháng nhuận âm lịch.\n * Mặc định: true\n */\n showLeapMonth?: boolean;\n\n /**\n * Hiển thị Can Chi của ngày khi hover chuột vào (Tooltip).\n * Mặc định: true\n */\n showTooltip?: boolean;\n\n /**\n * Màu chữ tùy chỉnh cho ngày âm lịch.\n * Mặc định: '#888'\n */\n color?: string;\n\n /**\n * Class CSS tùy chỉnh cho thẻ div chứa ngày âm lịch.\n */\n className?: string;\n\n /**\n * Tùy chọn render HTML nâng cao. Nếu được truyền vào, plugin sẽ dùng kết quả \n * của hàm này thay vì template mặc định.\n */\n render?: (lunar: LunarDate) => string;\n}\n\n/**\n * Attaches LichTa lunar dates to EventCalendar options.\n * Modifies the provided calendar options or returns a new config object.\n */\nexport function injectLunarDates(options: any, pluginOptions: LichTaOptions = {}) {\n const originalDayCellContent = options.dayCellContent;\n\n // Lấy các options với giá trị mặc định\n const {\n monthOnFirstDayOnly = false,\n showLeapMonth = true,\n showTooltip = true,\n color = '#888',\n className = 'lichta-ec-lunar',\n render\n } = pluginOptions;\n\n options.dayCellContent = function (arg: any) {\n const date = arg.date;\n const day = date.getDate();\n const month = date.getMonth() + 1;\n const year = date.getFullYear();\n\n // 1. Lấy dữ liệu Âm Lịch\n const lunar = LichTa.toLunar(day, month, year);\n\n // 2. Tạo nội dung ngày Âm Lịch\n let customLunarHtml = '';\n\n if (render) {\n // Nếu người dùng có hàm render riêng\n customLunarHtml = render(lunar);\n } else {\n // Logic render mặc định\n let lunarText = `${lunar.day}`;\n \n // Hiển thị tháng theo điều kiện\n if (!monthOnFirstDayOnly || lunar.day === 1) {\n lunarText = `${lunar.day}/${lunar.month}`;\n }\n\n // Thêm nhãn Nhuận\n if (showLeapMonth && lunar.isLeap) {\n lunarText += ' (Nhuận)';\n }\n\n // Thêm Tooltip Can Chi\n let tooltipAttr = '';\n if (showTooltip) {\n const canChi = getDayCanChi(lunar.jd);\n tooltipAttr = `title=\"Ngày ${canChi}\"`;\n }\n\n customLunarHtml = `<div class=\"${className}\" style=\"font-size: 0.8em; color: ${color}; margin-top: 2px;\" ${tooltipAttr}>${lunarText}</div>`;\n }\n\n // 3. Giữ nguyên nội dung của EventCalendar (hoặc nội dung custom trước đó)\n let originalContent = '';\n if (originalDayCellContent) {\n const orig = typeof originalDayCellContent === 'function' ? originalDayCellContent(arg) : originalDayCellContent;\n if (orig?.html) {\n originalContent = orig.html;\n } else {\n originalContent = orig; \n }\n } else {\n // Thẻ HTML mặc định của ô ngày trong EventCalendar\n originalContent = `<div class=\"ec-day-head\">${day}</div>`;\n }\n\n // 4. Trộn hai thẻ lại với nhau\n return {\n html: `\n <div class=\"lichta-ec-cell\" style=\"display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;\">\n ${originalContent}\n ${customLunarHtml}\n </div>\n `\n };\n };\n\n return options;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqC;AA4C9B,SAAS,iBAAiB,SAAc,gBAA+B,CAAC,GAAG;AAChF,QAAM,yBAAyB,QAAQ;AAGvC,QAAM;AAAA,IACJ,sBAAsB;AAAA,IACtB,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,EACF,IAAI;AAEJ,UAAQ,iBAAiB,SAAU,KAAU;AAC3C,UAAM,OAAO,IAAI;AACjB,UAAM,MAAM,KAAK,QAAQ;AACzB,UAAM,QAAQ,KAAK,SAAS,IAAI;AAChC,UAAM,OAAO,KAAK,YAAY;AAG9B,UAAM,QAAQ,mBAAO,QAAQ,KAAK,OAAO,IAAI;AAG7C,QAAI,kBAAkB;AAEtB,QAAI,QAAQ;AAEV,wBAAkB,OAAO,KAAK;AAAA,IAChC,OAAO;AAEL,UAAI,YAAY,GAAG,MAAM,GAAG;AAG5B,UAAI,CAAC,uBAAuB,MAAM,QAAQ,GAAG;AAC3C,oBAAY,GAAG,MAAM,GAAG,IAAI,MAAM,KAAK;AAAA,MACzC;AAGA,UAAI,iBAAiB,MAAM,QAAQ;AACjC,qBAAa;AAAA,MACf;AAGA,UAAI,cAAc;AAClB,UAAI,aAAa;AACf,cAAM,aAAS,0BAAa,MAAM,EAAE;AACpC,sBAAc,kBAAe,MAAM;AAAA,MACrC;AAEA,wBAAkB,eAAe,SAAS,qCAAqC,KAAK,uBAAuB,WAAW,IAAI,SAAS;AAAA,IACrI;AAGA,QAAI,kBAAkB;AACtB,QAAI,wBAAwB;AAC1B,YAAM,OAAO,OAAO,2BAA2B,aAAa,uBAAuB,GAAG,IAAI;AAC1F,UAAI,MAAM,MAAM;AACd,0BAAkB,KAAK;AAAA,MACzB,OAAO;AACL,0BAAkB;AAAA,MACpB;AAAA,IACF,OAAO;AAEJ,wBAAkB,4BAA4B,GAAG;AAAA,IACpD;AAGA,WAAO;AAAA,MACL,MAAM;AAAA;AAAA,YAEA,eAAe;AAAA,YACf,eAAe;AAAA;AAAA;AAAA,IAGvB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LunarDate } from '@lichta/core';
|
|
2
|
+
|
|
3
|
+
interface LichTaOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Chỉ hiển thị tháng khi là mùng 1 âm lịch (ví dụ: "1/4" thay vì "1").
|
|
6
|
+
* Mặc định: false
|
|
7
|
+
*/
|
|
8
|
+
monthOnFirstDayOnly?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Hiển thị chữ "Nhuận" nếu rơi vào tháng nhuận âm lịch.
|
|
11
|
+
* Mặc định: true
|
|
12
|
+
*/
|
|
13
|
+
showLeapMonth?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Hiển thị Can Chi của ngày khi hover chuột vào (Tooltip).
|
|
16
|
+
* Mặc định: true
|
|
17
|
+
*/
|
|
18
|
+
showTooltip?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Màu chữ tùy chỉnh cho ngày âm lịch.
|
|
21
|
+
* Mặc định: '#888'
|
|
22
|
+
*/
|
|
23
|
+
color?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Class CSS tùy chỉnh cho thẻ div chứa ngày âm lịch.
|
|
26
|
+
*/
|
|
27
|
+
className?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Tùy chọn render HTML nâng cao. Nếu được truyền vào, plugin sẽ dùng kết quả
|
|
30
|
+
* của hàm này thay vì template mặc định.
|
|
31
|
+
*/
|
|
32
|
+
render?: (lunar: LunarDate) => string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Attaches LichTa lunar dates to EventCalendar options.
|
|
36
|
+
* Modifies the provided calendar options or returns a new config object.
|
|
37
|
+
*/
|
|
38
|
+
declare function injectLunarDates(options: any, pluginOptions?: LichTaOptions): any;
|
|
39
|
+
|
|
40
|
+
export { type LichTaOptions, injectLunarDates };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LunarDate } from '@lichta/core';
|
|
2
|
+
|
|
3
|
+
interface LichTaOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Chỉ hiển thị tháng khi là mùng 1 âm lịch (ví dụ: "1/4" thay vì "1").
|
|
6
|
+
* Mặc định: false
|
|
7
|
+
*/
|
|
8
|
+
monthOnFirstDayOnly?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Hiển thị chữ "Nhuận" nếu rơi vào tháng nhuận âm lịch.
|
|
11
|
+
* Mặc định: true
|
|
12
|
+
*/
|
|
13
|
+
showLeapMonth?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Hiển thị Can Chi của ngày khi hover chuột vào (Tooltip).
|
|
16
|
+
* Mặc định: true
|
|
17
|
+
*/
|
|
18
|
+
showTooltip?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Màu chữ tùy chỉnh cho ngày âm lịch.
|
|
21
|
+
* Mặc định: '#888'
|
|
22
|
+
*/
|
|
23
|
+
color?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Class CSS tùy chỉnh cho thẻ div chứa ngày âm lịch.
|
|
26
|
+
*/
|
|
27
|
+
className?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Tùy chọn render HTML nâng cao. Nếu được truyền vào, plugin sẽ dùng kết quả
|
|
30
|
+
* của hàm này thay vì template mặc định.
|
|
31
|
+
*/
|
|
32
|
+
render?: (lunar: LunarDate) => string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Attaches LichTa lunar dates to EventCalendar options.
|
|
36
|
+
* Modifies the provided calendar options or returns a new config object.
|
|
37
|
+
*/
|
|
38
|
+
declare function injectLunarDates(options: any, pluginOptions?: LichTaOptions): any;
|
|
39
|
+
|
|
40
|
+
export { type LichTaOptions, injectLunarDates };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { LichTa, getDayCanChi } from "@lichta/core";
|
|
3
|
+
function injectLunarDates(options, pluginOptions = {}) {
|
|
4
|
+
const originalDayCellContent = options.dayCellContent;
|
|
5
|
+
const {
|
|
6
|
+
monthOnFirstDayOnly = false,
|
|
7
|
+
showLeapMonth = true,
|
|
8
|
+
showTooltip = true,
|
|
9
|
+
color = "#888",
|
|
10
|
+
className = "lichta-ec-lunar",
|
|
11
|
+
render
|
|
12
|
+
} = pluginOptions;
|
|
13
|
+
options.dayCellContent = function(arg) {
|
|
14
|
+
const date = arg.date;
|
|
15
|
+
const day = date.getDate();
|
|
16
|
+
const month = date.getMonth() + 1;
|
|
17
|
+
const year = date.getFullYear();
|
|
18
|
+
const lunar = LichTa.toLunar(day, month, year);
|
|
19
|
+
let customLunarHtml = "";
|
|
20
|
+
if (render) {
|
|
21
|
+
customLunarHtml = render(lunar);
|
|
22
|
+
} else {
|
|
23
|
+
let lunarText = `${lunar.day}`;
|
|
24
|
+
if (!monthOnFirstDayOnly || lunar.day === 1) {
|
|
25
|
+
lunarText = `${lunar.day}/${lunar.month}`;
|
|
26
|
+
}
|
|
27
|
+
if (showLeapMonth && lunar.isLeap) {
|
|
28
|
+
lunarText += " (Nhu\u1EADn)";
|
|
29
|
+
}
|
|
30
|
+
let tooltipAttr = "";
|
|
31
|
+
if (showTooltip) {
|
|
32
|
+
const canChi = getDayCanChi(lunar.jd);
|
|
33
|
+
tooltipAttr = `title="Ng\xE0y ${canChi}"`;
|
|
34
|
+
}
|
|
35
|
+
customLunarHtml = `<div class="${className}" style="font-size: 0.8em; color: ${color}; margin-top: 2px;" ${tooltipAttr}>${lunarText}</div>`;
|
|
36
|
+
}
|
|
37
|
+
let originalContent = "";
|
|
38
|
+
if (originalDayCellContent) {
|
|
39
|
+
const orig = typeof originalDayCellContent === "function" ? originalDayCellContent(arg) : originalDayCellContent;
|
|
40
|
+
if (orig?.html) {
|
|
41
|
+
originalContent = orig.html;
|
|
42
|
+
} else {
|
|
43
|
+
originalContent = orig;
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
originalContent = `<div class="ec-day-head">${day}</div>`;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
html: `
|
|
50
|
+
<div class="lichta-ec-cell" style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
|
|
51
|
+
${originalContent}
|
|
52
|
+
${customLunarHtml}
|
|
53
|
+
</div>
|
|
54
|
+
`
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
return options;
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
injectLunarDates
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { LichTa, getDayCanChi } from '@lichta/core';\nimport type { LunarDate } from '@lichta/core';\n\nexport interface LichTaOptions {\n /**\n * Chỉ hiển thị tháng khi là mùng 1 âm lịch (ví dụ: \"1/4\" thay vì \"1\").\n * Mặc định: false\n */\n monthOnFirstDayOnly?: boolean;\n\n /**\n * Hiển thị chữ \"Nhuận\" nếu rơi vào tháng nhuận âm lịch.\n * Mặc định: true\n */\n showLeapMonth?: boolean;\n\n /**\n * Hiển thị Can Chi của ngày khi hover chuột vào (Tooltip).\n * Mặc định: true\n */\n showTooltip?: boolean;\n\n /**\n * Màu chữ tùy chỉnh cho ngày âm lịch.\n * Mặc định: '#888'\n */\n color?: string;\n\n /**\n * Class CSS tùy chỉnh cho thẻ div chứa ngày âm lịch.\n */\n className?: string;\n\n /**\n * Tùy chọn render HTML nâng cao. Nếu được truyền vào, plugin sẽ dùng kết quả \n * của hàm này thay vì template mặc định.\n */\n render?: (lunar: LunarDate) => string;\n}\n\n/**\n * Attaches LichTa lunar dates to EventCalendar options.\n * Modifies the provided calendar options or returns a new config object.\n */\nexport function injectLunarDates(options: any, pluginOptions: LichTaOptions = {}) {\n const originalDayCellContent = options.dayCellContent;\n\n // Lấy các options với giá trị mặc định\n const {\n monthOnFirstDayOnly = false,\n showLeapMonth = true,\n showTooltip = true,\n color = '#888',\n className = 'lichta-ec-lunar',\n render\n } = pluginOptions;\n\n options.dayCellContent = function (arg: any) {\n const date = arg.date;\n const day = date.getDate();\n const month = date.getMonth() + 1;\n const year = date.getFullYear();\n\n // 1. Lấy dữ liệu Âm Lịch\n const lunar = LichTa.toLunar(day, month, year);\n\n // 2. Tạo nội dung ngày Âm Lịch\n let customLunarHtml = '';\n\n if (render) {\n // Nếu người dùng có hàm render riêng\n customLunarHtml = render(lunar);\n } else {\n // Logic render mặc định\n let lunarText = `${lunar.day}`;\n \n // Hiển thị tháng theo điều kiện\n if (!monthOnFirstDayOnly || lunar.day === 1) {\n lunarText = `${lunar.day}/${lunar.month}`;\n }\n\n // Thêm nhãn Nhuận\n if (showLeapMonth && lunar.isLeap) {\n lunarText += ' (Nhuận)';\n }\n\n // Thêm Tooltip Can Chi\n let tooltipAttr = '';\n if (showTooltip) {\n const canChi = getDayCanChi(lunar.jd);\n tooltipAttr = `title=\"Ngày ${canChi}\"`;\n }\n\n customLunarHtml = `<div class=\"${className}\" style=\"font-size: 0.8em; color: ${color}; margin-top: 2px;\" ${tooltipAttr}>${lunarText}</div>`;\n }\n\n // 3. Giữ nguyên nội dung của EventCalendar (hoặc nội dung custom trước đó)\n let originalContent = '';\n if (originalDayCellContent) {\n const orig = typeof originalDayCellContent === 'function' ? originalDayCellContent(arg) : originalDayCellContent;\n if (orig?.html) {\n originalContent = orig.html;\n } else {\n originalContent = orig; \n }\n } else {\n // Thẻ HTML mặc định của ô ngày trong EventCalendar\n originalContent = `<div class=\"ec-day-head\">${day}</div>`;\n }\n\n // 4. Trộn hai thẻ lại với nhau\n return {\n html: `\n <div class=\"lichta-ec-cell\" style=\"display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;\">\n ${originalContent}\n ${customLunarHtml}\n </div>\n `\n };\n };\n\n return options;\n}\n"],"mappings":";AAAA,SAAS,QAAQ,oBAAoB;AA4C9B,SAAS,iBAAiB,SAAc,gBAA+B,CAAC,GAAG;AAChF,QAAM,yBAAyB,QAAQ;AAGvC,QAAM;AAAA,IACJ,sBAAsB;AAAA,IACtB,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,EACF,IAAI;AAEJ,UAAQ,iBAAiB,SAAU,KAAU;AAC3C,UAAM,OAAO,IAAI;AACjB,UAAM,MAAM,KAAK,QAAQ;AACzB,UAAM,QAAQ,KAAK,SAAS,IAAI;AAChC,UAAM,OAAO,KAAK,YAAY;AAG9B,UAAM,QAAQ,OAAO,QAAQ,KAAK,OAAO,IAAI;AAG7C,QAAI,kBAAkB;AAEtB,QAAI,QAAQ;AAEV,wBAAkB,OAAO,KAAK;AAAA,IAChC,OAAO;AAEL,UAAI,YAAY,GAAG,MAAM,GAAG;AAG5B,UAAI,CAAC,uBAAuB,MAAM,QAAQ,GAAG;AAC3C,oBAAY,GAAG,MAAM,GAAG,IAAI,MAAM,KAAK;AAAA,MACzC;AAGA,UAAI,iBAAiB,MAAM,QAAQ;AACjC,qBAAa;AAAA,MACf;AAGA,UAAI,cAAc;AAClB,UAAI,aAAa;AACf,cAAM,SAAS,aAAa,MAAM,EAAE;AACpC,sBAAc,kBAAe,MAAM;AAAA,MACrC;AAEA,wBAAkB,eAAe,SAAS,qCAAqC,KAAK,uBAAuB,WAAW,IAAI,SAAS;AAAA,IACrI;AAGA,QAAI,kBAAkB;AACtB,QAAI,wBAAwB;AAC1B,YAAM,OAAO,OAAO,2BAA2B,aAAa,uBAAuB,GAAG,IAAI;AAC1F,UAAI,MAAM,MAAM;AACd,0BAAkB,KAAK;AAAA,MACzB,OAAO;AACL,0BAAkB;AAAA,MACpB;AAAA,IACF,OAAO;AAEJ,wBAAkB,4BAA4B,GAAG;AAAA,IACpD;AAGA,WAAO;AAAA,MACL,MAAM;AAAA;AAAA,YAEA,eAAe;AAAA,YACf,eAAe;AAAA;AAAA;AAAA,IAGvB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lichta/event-calendar",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "EventCalendar adapter for LichTa",
|
|
5
|
+
"author": "Zeforc Labs | Stridev",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@lichta/core": "2.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@event-calendar/core": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@event-calendar/core": "^3.0.0",
|
|
30
|
+
"typescript": "^6.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup"
|
|
34
|
+
}
|
|
35
|
+
}
|