commit 8a0c95a57764b21aaaef4970481c3d15dd60ae27 Author: Marcin Czenko Date: Tue Oct 29 02:16:26 2024 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a019cf6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.obsidian/publish.json +.obsidian/workspace*.json \ No newline at end of file diff --git a/.obsidian/app.json b/.obsidian/app.json new file mode 100644 index 0000000..5f33603 --- /dev/null +++ b/.obsidian/app.json @@ -0,0 +1,6 @@ +{ + "newFileLocation": "folder", + "newFileFolderPath": "10 Notes", + "attachmentFolderPath": "90 Extras/92 Assets", + "alwaysUpdateLinks": true +} \ No newline at end of file diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.obsidian/appearance.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.obsidian/backlink.json b/.obsidian/backlink.json new file mode 100644 index 0000000..48ee913 --- /dev/null +++ b/.obsidian/backlink.json @@ -0,0 +1,3 @@ +{ + "backlinkInDocument": true +} \ No newline at end of file diff --git a/.obsidian/command-palette.json b/.obsidian/command-palette.json new file mode 100644 index 0000000..d66f43a --- /dev/null +++ b/.obsidian/command-palette.json @@ -0,0 +1,6 @@ +{ + "pinned": [ + "insert-template", + "workspace:toggle-pin" + ] +} \ No newline at end of file diff --git a/.obsidian/community-plugins.json b/.obsidian/community-plugins.json new file mode 100644 index 0000000..bea9e0f --- /dev/null +++ b/.obsidian/community-plugins.json @@ -0,0 +1,6 @@ +[ + "obsidian42-brat", + "query-control", + "calendar", + "nldates-obsidian" +] \ No newline at end of file diff --git a/.obsidian/core-plugins-migration.json b/.obsidian/core-plugins-migration.json new file mode 100644 index 0000000..9ee08f0 --- /dev/null +++ b/.obsidian/core-plugins-migration.json @@ -0,0 +1,30 @@ +{ + "file-explorer": true, + "global-search": true, + "switcher": true, + "graph": true, + "backlink": true, + "canvas": false, + "outgoing-link": true, + "tag-pane": true, + "properties": true, + "page-preview": true, + "daily-notes": true, + "templates": true, + "note-composer": true, + "command-palette": true, + "slash-command": true, + "editor-status": true, + "bookmarks": true, + "markdown-importer": false, + "zk-prefixer": false, + "random-note": false, + "outline": true, + "word-count": true, + "slides": false, + "audio-recorder": false, + "workspaces": false, + "file-recovery": true, + "publish": false, + "sync": false +} \ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json new file mode 100644 index 0000000..f7a4ecb --- /dev/null +++ b/.obsidian/core-plugins.json @@ -0,0 +1,30 @@ +{ + "file-explorer": true, + "global-search": true, + "switcher": true, + "graph": true, + "backlink": true, + "canvas": true, + "outgoing-link": true, + "tag-pane": true, + "properties": true, + "page-preview": true, + "daily-notes": true, + "templates": true, + "note-composer": true, + "command-palette": true, + "slash-command": false, + "editor-status": true, + "bookmarks": true, + "markdown-importer": false, + "zk-prefixer": false, + "random-note": false, + "outline": true, + "word-count": true, + "slides": false, + "audio-recorder": false, + "workspaces": false, + "file-recovery": true, + "publish": true, + "sync": true +} \ No newline at end of file diff --git a/.obsidian/daily-notes.json b/.obsidian/daily-notes.json new file mode 100644 index 0000000..3f1f477 --- /dev/null +++ b/.obsidian/daily-notes.json @@ -0,0 +1,5 @@ +{ + "format": "YYYY-MM-DD, ddd", + "folder": "00 Planner/01 Days", + "autorun": true +} \ No newline at end of file diff --git a/.obsidian/graph.json b/.obsidian/graph.json new file mode 100644 index 0000000..e21a18d --- /dev/null +++ b/.obsidian/graph.json @@ -0,0 +1,22 @@ +{ + "collapse-filter": true, + "search": "", + "showTags": false, + "showAttachments": false, + "hideUnresolved": false, + "showOrphans": true, + "collapse-color-groups": true, + "colorGroups": [], + "collapse-display": true, + "showArrow": false, + "textFadeMultiplier": 0, + "nodeSizeMultiplier": 1, + "lineSizeMultiplier": 1, + "collapse-forces": true, + "centerStrength": 0.518713248970312, + "repelStrength": 10, + "linkStrength": 1, + "linkDistance": 250, + "scale": 1, + "close": false +} \ No newline at end of file diff --git a/.obsidian/hotkeys.json b/.obsidian/hotkeys.json new file mode 100644 index 0000000..a4e4af9 --- /dev/null +++ b/.obsidian/hotkeys.json @@ -0,0 +1,129 @@ +{ + "insert-template": [ + { + "modifiers": [ + "Alt", + "Mod" + ], + "key": "T" + } + ], + "app:go-back": [ + { + "modifiers": [ + "Mod", + "Alt" + ], + "key": "ArrowLeft" + }, + { + "modifiers": [ + "Mod" + ], + "key": "[" + } + ], + "app:go-forward": [ + { + "modifiers": [ + "Mod", + "Alt" + ], + "key": "ArrowRight" + }, + { + "modifiers": [ + "Mod" + ], + "key": "]" + } + ], + "daily-notes": [ + { + "modifiers": [ + "Mod" + ], + "key": "D" + } + ], + "editor:delete-paragraph": [], + "daily-notes:goto-prev": [ + { + "modifiers": [ + "Alt", + "Mod" + ], + "key": "[" + } + ], + "daily-notes:goto-next": [ + { + "modifiers": [ + "Alt", + "Mod" + ], + "key": "]" + } + ], + "editor:toggle-highlight": [ + { + "modifiers": [ + "Mod", + "Shift" + ], + "key": "H" + } + ], + "bookmarks:open": [ + { + "modifiers": [ + "Mod", + "Shift" + ], + "key": "B" + } + ], + "theme:use-dark": [ + { + "modifiers": [ + "Mod", + "Shift" + ], + "key": "-" + } + ], + "theme:use-light": [ + { + "modifiers": [ + "Mod", + "Shift" + ], + "key": "=" + } + ], + "app:toggle-left-sidebar": [ + { + "modifiers": [ + "Ctrl" + ], + "key": "1" + } + ], + "app:toggle-right-sidebar": [ + { + "modifiers": [ + "Ctrl" + ], + "key": "2" + } + ], + "publish:view-changes": [ + { + "modifiers": [ + "Alt", + "Mod" + ], + "key": "P" + } + ] +} \ No newline at end of file diff --git a/.obsidian/plugins/calendar/data.json b/.obsidian/plugins/calendar/data.json new file mode 100644 index 0000000..68cf914 --- /dev/null +++ b/.obsidian/plugins/calendar/data.json @@ -0,0 +1,10 @@ +{ + "shouldConfirmBeforeCreate": true, + "weekStart": "locale", + "wordsPerDot": 250, + "showWeeklyNote": true, + "weeklyNoteFormat": "gggg, [week] ww", + "weeklyNoteTemplate": "", + "weeklyNoteFolder": "00 Planner/02 Weeks", + "localeOverride": "system-default" +} \ No newline at end of file diff --git a/.obsidian/plugins/calendar/main.js b/.obsidian/plugins/calendar/main.js new file mode 100644 index 0000000..ed6cea3 --- /dev/null +++ b/.obsidian/plugins/calendar/main.js @@ -0,0 +1,4459 @@ +'use strict'; + +var obsidian = require('obsidian'); + +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + +var obsidian__default = /*#__PURE__*/_interopDefaultLegacy(obsidian); + +const DEFAULT_WEEK_FORMAT = "gggg-[W]ww"; +const DEFAULT_WORDS_PER_DOT = 250; +const VIEW_TYPE_CALENDAR = "calendar"; +const TRIGGER_ON_OPEN = "calendar:open"; + +const DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD"; +const DEFAULT_WEEKLY_NOTE_FORMAT = "gggg-[W]ww"; +const DEFAULT_MONTHLY_NOTE_FORMAT = "YYYY-MM"; + +function shouldUsePeriodicNotesSettings(periodicity) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = window.app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.[periodicity]?.enabled; +} +/** + * Read the user settings for the `daily-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getDailyNoteSettings() { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const { internalPlugins, plugins } = window.app; + if (shouldUsePeriodicNotesSettings("daily")) { + const { format, folder, template } = plugins.getPlugin("periodic-notes")?.settings?.daily || {}; + return { + format: format || DEFAULT_DAILY_NOTE_FORMAT, + folder: folder?.trim() || "", + template: template?.trim() || "", + }; + } + const { folder, format, template } = internalPlugins.getPluginById("daily-notes")?.instance?.options || {}; + return { + format: format || DEFAULT_DAILY_NOTE_FORMAT, + folder: folder?.trim() || "", + template: template?.trim() || "", + }; + } + catch (err) { + console.info("No custom daily note settings found!", err); + } +} +/** + * Read the user settings for the `weekly-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getWeeklyNoteSettings() { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + const calendarSettings = pluginManager.getPlugin("calendar")?.options; + const periodicNotesSettings = pluginManager.getPlugin("periodic-notes") + ?.settings?.weekly; + if (shouldUsePeriodicNotesSettings("weekly")) { + return { + format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: periodicNotesSettings.folder?.trim() || "", + template: periodicNotesSettings.template?.trim() || "", + }; + } + const settings = calendarSettings || {}; + return { + format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: settings.weeklyNoteFolder?.trim() || "", + template: settings.weeklyNoteTemplate?.trim() || "", + }; + } + catch (err) { + console.info("No custom weekly note settings found!", err); + } +} +/** + * Read the user settings for the `periodic-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getMonthlyNoteSettings() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + try { + const settings = (shouldUsePeriodicNotesSettings("monthly") && + pluginManager.getPlugin("periodic-notes")?.settings?.monthly) || + {}; + return { + format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT, + folder: settings.folder?.trim() || "", + template: settings.template?.trim() || "", + }; + } + catch (err) { + console.info("No custom monthly note settings found!", err); + } +} + +/** + * dateUID is a way of weekly identifying daily/weekly/monthly notes. + * They are prefixed with the granularity to avoid ambiguity. + */ +function getDateUID$1(date, granularity = "day") { + const ts = date.clone().startOf(granularity).format(); + return `${granularity}-${ts}`; +} +function removeEscapedCharacters(format) { + return format.replace(/\[[^\]]*\]/g, ""); // remove everything within brackets +} +/** + * XXX: When parsing dates that contain both week numbers and months, + * Moment choses to ignore the week numbers. For the week dateUID, we + * want the opposite behavior. Strip the MMM from the format to patch. + */ +function isFormatAmbiguous(format, granularity) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + return (/w{1,2}/i.test(cleanFormat) && + (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat))); + } + return false; +} +function getDateFromFile(file, granularity) { + const getSettings = { + day: getDailyNoteSettings, + week: getWeeklyNoteSettings, + month: getMonthlyNoteSettings, + }; + const format = getSettings[granularity]().format.split("/").pop(); + const noteDate = window.moment(file.basename, format, true); + if (!noteDate.isValid()) { + return null; + } + if (isFormatAmbiguous(format, granularity)) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + if (/w{1,2}/i.test(cleanFormat)) { + return window.moment(file.basename, + // If format contains week, remove day & month formatting + format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""), false); + } + } + } + return noteDate; +} + +// Credit: @creationix/path.js +function join(...partSegments) { + // Split the inputs into a list of path commands. + let parts = []; + for (let i = 0, l = partSegments.length; i < l; i++) { + parts = parts.concat(partSegments[i].split("/")); + } + // Interpret the path commands to get the new resolved path. + const newParts = []; + for (let i = 0, l = parts.length; i < l; i++) { + const part = parts[i]; + // Remove leading and trailing slashes + // Also remove "." segments + if (!part || part === ".") + continue; + // Push new path segments. + else + newParts.push(part); + } + // Preserve the initial slash if there was one. + if (parts[0] === "") + newParts.unshift(""); + // Turn back into a single string path. + return newParts.join("/"); +} +async function ensureFolderExists(path) { + const dirs = path.replace(/\\/g, "/").split("/"); + dirs.pop(); // remove basename + if (dirs.length) { + const dir = join(...dirs); + if (!window.app.vault.getAbstractFileByPath(dir)) { + await window.app.vault.createFolder(dir); + } + } +} +async function getNotePath(directory, filename) { + if (!filename.endsWith(".md")) { + filename += ".md"; + } + const path = obsidian__default['default'].normalizePath(join(directory, filename)); + await ensureFolderExists(path); + return path; +} +async function getTemplateInfo(template) { + const { metadataCache, vault } = window.app; + const templatePath = obsidian__default['default'].normalizePath(template); + if (templatePath === "/") { + return Promise.resolve(["", null]); + } + try { + const templateFile = metadataCache.getFirstLinkpathDest(templatePath, ""); + const contents = await vault.cachedRead(templateFile); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const IFoldInfo = window.app.foldManager.load(templateFile); + return [contents, IFoldInfo]; + } + catch (err) { + console.error(`Failed to read the daily note template '${templatePath}'`, err); + new obsidian__default['default'].Notice("Failed to read the daily note template"); + return ["", null]; + } +} + +class DailyNotesFolderMissingError extends Error { +} +/** + * This function mimics the behavior of the daily-notes plugin + * so it will replace {{date}}, {{title}}, and {{time}} with the + * formatted timestamp. + * + * Note: it has an added bonus that it's not 'today' specific. + */ +async function createDailyNote(date) { + const app = window.app; + const { vault } = app; + const moment = window.moment; + const { template, format, folder } = getDailyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*date\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, moment().format("HH:mm")) + .replace(/{{\s*title\s*}}/gi, filename) + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*yesterday\s*}}/gi, date.clone().subtract(1, "day").format(format)) + .replace(/{{\s*tomorrow\s*}}/gi, date.clone().add(1, "d").format(format))); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian__default['default'].Notice("Unable to create new file."); + } +} +function getDailyNote(date, dailyNotes) { + return dailyNotes[getDateUID$1(date, "day")] ?? null; +} +function getAllDailyNotes() { + /** + * Find all daily notes in the daily note folder + */ + const { vault } = window.app; + const { folder } = getDailyNoteSettings(); + const dailyNotesFolder = vault.getAbstractFileByPath(obsidian__default['default'].normalizePath(folder)); + if (!dailyNotesFolder) { + throw new DailyNotesFolderMissingError("Failed to find daily notes folder"); + } + const dailyNotes = {}; + obsidian__default['default'].Vault.recurseChildren(dailyNotesFolder, (note) => { + if (note instanceof obsidian__default['default'].TFile) { + const date = getDateFromFile(note, "day"); + if (date) { + const dateString = getDateUID$1(date, "day"); + dailyNotes[dateString] = note; + } + } + }); + return dailyNotes; +} + +class WeeklyNotesFolderMissingError extends Error { +} +function getDaysOfWeek$1() { + const { moment } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let weekStart = moment.localeData()._week.dow; + const daysOfWeek = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + ]; + while (weekStart) { + daysOfWeek.push(daysOfWeek.shift()); + weekStart--; + } + return daysOfWeek; +} +function getDayOfWeekNumericalValue(dayOfWeekName) { + return getDaysOfWeek$1().indexOf(dayOfWeekName.toLowerCase()); +} +async function createWeeklyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getWeeklyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*title\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) + .replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi, (_, dayOfWeek, momentFormat) => { + const day = getDayOfWeekNumericalValue(dayOfWeek); + return date.weekday(day).format(momentFormat.trim()); + })); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian__default['default'].Notice("Unable to create new file."); + } +} +function getWeeklyNote(date, weeklyNotes) { + return weeklyNotes[getDateUID$1(date, "week")] ?? null; +} +function getAllWeeklyNotes() { + const { vault } = window.app; + const { folder } = getWeeklyNoteSettings(); + const weeklyNotesFolder = vault.getAbstractFileByPath(obsidian__default['default'].normalizePath(folder)); + if (!weeklyNotesFolder) { + throw new WeeklyNotesFolderMissingError("Failed to find weekly notes folder"); + } + const weeklyNotes = {}; + obsidian__default['default'].Vault.recurseChildren(weeklyNotesFolder, (note) => { + if (note instanceof obsidian__default['default'].TFile) { + const date = getDateFromFile(note, "week"); + if (date) { + const dateString = getDateUID$1(date, "week"); + weeklyNotes[dateString] = note; + } + } + }); + return weeklyNotes; +} + +function appHasDailyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"]; + if (dailyNotesPlugin && dailyNotesPlugin.enabled) { + return true; + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.daily?.enabled; +} +var appHasDailyNotesPluginLoaded_1 = appHasDailyNotesPluginLoaded; +var createDailyNote_1 = createDailyNote; +var createWeeklyNote_1 = createWeeklyNote; +var getAllDailyNotes_1 = getAllDailyNotes; +var getAllWeeklyNotes_1 = getAllWeeklyNotes; +var getDailyNote_1 = getDailyNote; +var getDailyNoteSettings_1 = getDailyNoteSettings; +var getDateFromFile_1 = getDateFromFile; +var getDateUID_1$1 = getDateUID$1; +var getWeeklyNote_1 = getWeeklyNote; +var getWeeklyNoteSettings_1 = getWeeklyNoteSettings; + +function noop$1() { } +function run$1(fn) { + return fn(); +} +function blank_object$1() { + return Object.create(null); +} +function run_all$1(fns) { + fns.forEach(run$1); +} +function is_function$1(thing) { + return typeof thing === 'function'; +} +function safe_not_equal$1(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} +function not_equal$1(a, b) { + return a != a ? b == b : a !== b; +} +function is_empty$1(obj) { + return Object.keys(obj).length === 0; +} +function subscribe(store, ...callbacks) { + if (store == null) { + return noop$1; + } + const unsub = store.subscribe(...callbacks); + return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub; +} +function get_store_value(store) { + let value; + subscribe(store, _ => value = _)(); + return value; +} +function component_subscribe(component, store, callback) { + component.$$.on_destroy.push(subscribe(store, callback)); +} +function detach$1(node) { + node.parentNode.removeChild(node); +} +function children$1(element) { + return Array.from(element.childNodes); +} + +let current_component$1; +function set_current_component$1(component) { + current_component$1 = component; +} +function get_current_component$1() { + if (!current_component$1) + throw new Error('Function called outside component initialization'); + return current_component$1; +} +function onDestroy(fn) { + get_current_component$1().$$.on_destroy.push(fn); +} + +const dirty_components$1 = []; +const binding_callbacks$1 = []; +const render_callbacks$1 = []; +const flush_callbacks$1 = []; +const resolved_promise$1 = Promise.resolve(); +let update_scheduled$1 = false; +function schedule_update$1() { + if (!update_scheduled$1) { + update_scheduled$1 = true; + resolved_promise$1.then(flush$1); + } +} +function add_render_callback$1(fn) { + render_callbacks$1.push(fn); +} +function add_flush_callback(fn) { + flush_callbacks$1.push(fn); +} +let flushing$1 = false; +const seen_callbacks$1 = new Set(); +function flush$1() { + if (flushing$1) + return; + flushing$1 = true; + do { + // first, call beforeUpdate functions + // and update components + for (let i = 0; i < dirty_components$1.length; i += 1) { + const component = dirty_components$1[i]; + set_current_component$1(component); + update$1(component.$$); + } + set_current_component$1(null); + dirty_components$1.length = 0; + while (binding_callbacks$1.length) + binding_callbacks$1.pop()(); + // then, once components are updated, call + // afterUpdate functions. This may cause + // subsequent updates... + for (let i = 0; i < render_callbacks$1.length; i += 1) { + const callback = render_callbacks$1[i]; + if (!seen_callbacks$1.has(callback)) { + // ...so guard against infinite loops + seen_callbacks$1.add(callback); + callback(); + } + } + render_callbacks$1.length = 0; + } while (dirty_components$1.length); + while (flush_callbacks$1.length) { + flush_callbacks$1.pop()(); + } + update_scheduled$1 = false; + flushing$1 = false; + seen_callbacks$1.clear(); +} +function update$1($$) { + if ($$.fragment !== null) { + $$.update(); + run_all$1($$.before_update); + const dirty = $$.dirty; + $$.dirty = [-1]; + $$.fragment && $$.fragment.p($$.ctx, dirty); + $$.after_update.forEach(add_render_callback$1); + } +} +const outroing$1 = new Set(); +let outros$1; +function transition_in$1(block, local) { + if (block && block.i) { + outroing$1.delete(block); + block.i(local); + } +} +function transition_out$1(block, local, detach, callback) { + if (block && block.o) { + if (outroing$1.has(block)) + return; + outroing$1.add(block); + outros$1.c.push(() => { + outroing$1.delete(block); + if (callback) { + if (detach) + block.d(1); + callback(); + } + }); + block.o(local); + } +} + +function bind(component, name, callback) { + const index = component.$$.props[name]; + if (index !== undefined) { + component.$$.bound[index] = callback; + callback(component.$$.ctx[index]); + } +} +function create_component$1(block) { + block && block.c(); +} +function mount_component$1(component, target, anchor, customElement) { + const { fragment, on_mount, on_destroy, after_update } = component.$$; + fragment && fragment.m(target, anchor); + if (!customElement) { + // onMount happens before the initial afterUpdate + add_render_callback$1(() => { + const new_on_destroy = on_mount.map(run$1).filter(is_function$1); + if (on_destroy) { + on_destroy.push(...new_on_destroy); + } + else { + // Edge case - component was destroyed immediately, + // most likely as a result of a binding initialising + run_all$1(new_on_destroy); + } + component.$$.on_mount = []; + }); + } + after_update.forEach(add_render_callback$1); +} +function destroy_component$1(component, detaching) { + const $$ = component.$$; + if ($$.fragment !== null) { + run_all$1($$.on_destroy); + $$.fragment && $$.fragment.d(detaching); + // TODO null out other refs, including component.$$ (but need to + // preserve final state?) + $$.on_destroy = $$.fragment = null; + $$.ctx = []; + } +} +function make_dirty$1(component, i) { + if (component.$$.dirty[0] === -1) { + dirty_components$1.push(component); + schedule_update$1(); + component.$$.dirty.fill(0); + } + component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); +} +function init$1(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { + const parent_component = current_component$1; + set_current_component$1(component); + const $$ = component.$$ = { + fragment: null, + ctx: null, + // state + props, + update: noop$1, + not_equal, + bound: blank_object$1(), + // lifecycle + on_mount: [], + on_destroy: [], + on_disconnect: [], + before_update: [], + after_update: [], + context: new Map(parent_component ? parent_component.$$.context : []), + // everything else + callbacks: blank_object$1(), + dirty, + skip_bound: false + }; + let ready = false; + $$.ctx = instance + ? instance(component, options.props || {}, (i, ret, ...rest) => { + const value = rest.length ? rest[0] : ret; + if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { + if (!$$.skip_bound && $$.bound[i]) + $$.bound[i](value); + if (ready) + make_dirty$1(component, i); + } + return ret; + }) + : []; + $$.update(); + ready = true; + run_all$1($$.before_update); + // `false` as a special case of no DOM component + $$.fragment = create_fragment ? create_fragment($$.ctx) : false; + if (options.target) { + if (options.hydrate) { + const nodes = children$1(options.target); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.l(nodes); + nodes.forEach(detach$1); + } + else { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.c(); + } + if (options.intro) + transition_in$1(component.$$.fragment); + mount_component$1(component, options.target, options.anchor, options.customElement); + flush$1(); + } + set_current_component$1(parent_component); +} +/** + * Base class for Svelte components. Used when dev=false. + */ +class SvelteComponent$1 { + $destroy() { + destroy_component$1(this, 1); + this.$destroy = noop$1; + } + $on(type, callback) { + const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); + callbacks.push(callback); + return () => { + const index = callbacks.indexOf(callback); + if (index !== -1) + callbacks.splice(index, 1); + }; + } + $set($$props) { + if (this.$$set && !is_empty$1($$props)) { + this.$$.skip_bound = true; + this.$$set($$props); + this.$$.skip_bound = false; + } + } +} + +const subscriber_queue = []; +/** + * Create a `Writable` store that allows both updating and reading by subscription. + * @param {*=}value initial value + * @param {StartStopNotifier=}start start and stop notifications for subscriptions + */ +function writable(value, start = noop$1) { + let stop; + const subscribers = []; + function set(new_value) { + if (safe_not_equal$1(value, new_value)) { + value = new_value; + if (stop) { // store is ready + const run_queue = !subscriber_queue.length; + for (let i = 0; i < subscribers.length; i += 1) { + const s = subscribers[i]; + s[1](); + subscriber_queue.push(s, value); + } + if (run_queue) { + for (let i = 0; i < subscriber_queue.length; i += 2) { + subscriber_queue[i][0](subscriber_queue[i + 1]); + } + subscriber_queue.length = 0; + } + } + } + } + function update(fn) { + set(fn(value)); + } + function subscribe(run, invalidate = noop$1) { + const subscriber = [run, invalidate]; + subscribers.push(subscriber); + if (subscribers.length === 1) { + stop = start(set) || noop$1; + } + run(value); + return () => { + const index = subscribers.indexOf(subscriber); + if (index !== -1) { + subscribers.splice(index, 1); + } + if (subscribers.length === 0) { + stop(); + stop = null; + } + }; + } + return { set, update, subscribe }; +} + +const weekdays$1 = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", +]; +const defaultSettings = Object.freeze({ + shouldConfirmBeforeCreate: true, + weekStart: "locale", + wordsPerDot: DEFAULT_WORDS_PER_DOT, + showWeeklyNote: false, + weeklyNoteFormat: "", + weeklyNoteTemplate: "", + weeklyNoteFolder: "", + localeOverride: "system-default", +}); +function appHasPeriodicNotesPluginLoaded() { + var _a, _b; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = window.app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) === null || _a === void 0 ? void 0 : _a.weekly) === null || _b === void 0 ? void 0 : _b.enabled); +} +class CalendarSettingsTab extends obsidian.PluginSettingTab { + constructor(app, plugin) { + super(app, plugin); + this.plugin = plugin; + } + display() { + this.containerEl.empty(); + if (!appHasDailyNotesPluginLoaded_1()) { + this.containerEl.createDiv("settings-banner", (banner) => { + banner.createEl("h3", { + text: "⚠️ Daily Notes plugin not enabled", + }); + banner.createEl("p", { + cls: "setting-item-description", + text: "The calendar is best used in conjunction with either the Daily Notes plugin or the Periodic Notes plugin (available in the Community Plugins catalog).", + }); + }); + } + this.containerEl.createEl("h3", { + text: "General Settings", + }); + this.addDotThresholdSetting(); + this.addWeekStartSetting(); + this.addConfirmCreateSetting(); + this.addShowWeeklyNoteSetting(); + if (this.plugin.options.showWeeklyNote && + !appHasPeriodicNotesPluginLoaded()) { + this.containerEl.createEl("h3", { + text: "Weekly Note Settings", + }); + this.containerEl.createEl("p", { + cls: "setting-item-description", + text: "Note: Weekly Note settings are moving. You are encouraged to install the 'Periodic Notes' plugin to keep the functionality in the future.", + }); + this.addWeeklyNoteFormatSetting(); + this.addWeeklyNoteTemplateSetting(); + this.addWeeklyNoteFolderSetting(); + } + this.containerEl.createEl("h3", { + text: "Advanced Settings", + }); + this.addLocaleOverrideSetting(); + } + addDotThresholdSetting() { + new obsidian.Setting(this.containerEl) + .setName("Words per dot") + .setDesc("How many words should be represented by a single dot?") + .addText((textfield) => { + textfield.setPlaceholder(String(DEFAULT_WORDS_PER_DOT)); + textfield.inputEl.type = "number"; + textfield.setValue(String(this.plugin.options.wordsPerDot)); + textfield.onChange(async (value) => { + this.plugin.writeOptions(() => ({ + wordsPerDot: value !== "" ? Number(value) : undefined, + })); + }); + }); + } + addWeekStartSetting() { + const { moment } = window; + const localizedWeekdays = moment.weekdays(); + const localeWeekStartNum = window._bundledLocaleWeekSpec.dow; + const localeWeekStart = moment.weekdays()[localeWeekStartNum]; + new obsidian.Setting(this.containerEl) + .setName("Start week on:") + .setDesc("Choose what day of the week to start. Select 'Locale default' to use the default specified by moment.js") + .addDropdown((dropdown) => { + dropdown.addOption("locale", `Locale default (${localeWeekStart})`); + localizedWeekdays.forEach((day, i) => { + dropdown.addOption(weekdays$1[i], day); + }); + dropdown.setValue(this.plugin.options.weekStart); + dropdown.onChange(async (value) => { + this.plugin.writeOptions(() => ({ + weekStart: value, + })); + }); + }); + } + addConfirmCreateSetting() { + new obsidian.Setting(this.containerEl) + .setName("Confirm before creating new note") + .setDesc("Show a confirmation modal before creating a new note") + .addToggle((toggle) => { + toggle.setValue(this.plugin.options.shouldConfirmBeforeCreate); + toggle.onChange(async (value) => { + this.plugin.writeOptions(() => ({ + shouldConfirmBeforeCreate: value, + })); + }); + }); + } + addShowWeeklyNoteSetting() { + new obsidian.Setting(this.containerEl) + .setName("Show week number") + .setDesc("Enable this to add a column with the week number") + .addToggle((toggle) => { + toggle.setValue(this.plugin.options.showWeeklyNote); + toggle.onChange(async (value) => { + this.plugin.writeOptions(() => ({ showWeeklyNote: value })); + this.display(); // show/hide weekly settings + }); + }); + } + addWeeklyNoteFormatSetting() { + new obsidian.Setting(this.containerEl) + .setName("Weekly note format") + .setDesc("For more syntax help, refer to format reference") + .addText((textfield) => { + textfield.setValue(this.plugin.options.weeklyNoteFormat); + textfield.setPlaceholder(DEFAULT_WEEK_FORMAT); + textfield.onChange(async (value) => { + this.plugin.writeOptions(() => ({ weeklyNoteFormat: value })); + }); + }); + } + addWeeklyNoteTemplateSetting() { + new obsidian.Setting(this.containerEl) + .setName("Weekly note template") + .setDesc("Choose the file you want to use as the template for your weekly notes") + .addText((textfield) => { + textfield.setValue(this.plugin.options.weeklyNoteTemplate); + textfield.onChange(async (value) => { + this.plugin.writeOptions(() => ({ weeklyNoteTemplate: value })); + }); + }); + } + addWeeklyNoteFolderSetting() { + new obsidian.Setting(this.containerEl) + .setName("Weekly note folder") + .setDesc("New weekly notes will be placed here") + .addText((textfield) => { + textfield.setValue(this.plugin.options.weeklyNoteFolder); + textfield.onChange(async (value) => { + this.plugin.writeOptions(() => ({ weeklyNoteFolder: value })); + }); + }); + } + addLocaleOverrideSetting() { + var _a; + const { moment } = window; + const sysLocale = (_a = navigator.language) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + new obsidian.Setting(this.containerEl) + .setName("Override locale:") + .setDesc("Set this if you want to use a locale different from the default") + .addDropdown((dropdown) => { + dropdown.addOption("system-default", `Same as system (${sysLocale})`); + moment.locales().forEach((locale) => { + dropdown.addOption(locale, locale); + }); + dropdown.setValue(this.plugin.options.localeOverride); + dropdown.onChange(async (value) => { + this.plugin.writeOptions(() => ({ + localeOverride: value, + })); + }); + }); + } +} + +const classList = (obj) => { + return Object.entries(obj) + .filter(([_k, v]) => !!v) + .map(([k, _k]) => k); +}; +function clamp(num, lowerBound, upperBound) { + return Math.min(Math.max(lowerBound, num), upperBound); +} +function partition(arr, predicate) { + const pass = []; + const fail = []; + arr.forEach((elem) => { + if (predicate(elem)) { + pass.push(elem); + } + else { + fail.push(elem); + } + }); + return [pass, fail]; +} +/** + * Lookup the dateUID for a given file. It compares the filename + * to the daily and weekly note formats to find a match. + * + * @param file + */ +function getDateUIDFromFile(file) { + if (!file) { + return null; + } + // TODO: I'm not checking the path! + let date = getDateFromFile_1(file, "day"); + if (date) { + return getDateUID_1$1(date, "day"); + } + date = getDateFromFile_1(file, "week"); + if (date) { + return getDateUID_1$1(date, "week"); + } + return null; +} +function getWordCount(text) { + const spaceDelimitedChars = /A-Za-z\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC/ + .source; + const nonSpaceDelimitedWords = /\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u4E00-\u9FD5/ + .source; + const pattern = new RegExp([ + `(?:[0-9]+(?:(?:,|\\.)[0-9]+)*|[\\-${spaceDelimitedChars}])+`, + nonSpaceDelimitedWords, + ].join("|"), "g"); + return (text.match(pattern) || []).length; +} + +function createDailyNotesStore() { + let hasError = false; + const store = writable(null); + return Object.assign({ reindex: () => { + try { + const dailyNotes = getAllDailyNotes_1(); + store.set(dailyNotes); + hasError = false; + } + catch (err) { + if (!hasError) { + // Avoid error being shown multiple times + console.log("[Calendar] Failed to find daily notes folder", err); + } + store.set({}); + hasError = true; + } + } }, store); +} +function createWeeklyNotesStore() { + let hasError = false; + const store = writable(null); + return Object.assign({ reindex: () => { + try { + const weeklyNotes = getAllWeeklyNotes_1(); + store.set(weeklyNotes); + hasError = false; + } + catch (err) { + if (!hasError) { + // Avoid error being shown multiple times + console.log("[Calendar] Failed to find weekly notes folder", err); + } + store.set({}); + hasError = true; + } + } }, store); +} +const settings = writable(defaultSettings); +const dailyNotes = createDailyNotesStore(); +const weeklyNotes = createWeeklyNotesStore(); +function createSelectedFileStore() { + const store = writable(null); + return Object.assign({ setFile: (file) => { + const id = getDateUIDFromFile(file); + store.set(id); + } }, store); +} +const activeFile = createSelectedFileStore(); + +class ConfirmationModal extends obsidian.Modal { + constructor(app, config) { + super(app); + const { cta, onAccept, text, title } = config; + this.contentEl.createEl("h2", { text: title }); + this.contentEl.createEl("p", { text }); + this.contentEl.createDiv("modal-button-container", (buttonsEl) => { + buttonsEl + .createEl("button", { text: "Never mind" }) + .addEventListener("click", () => this.close()); + buttonsEl + .createEl("button", { + cls: "mod-cta", + text: cta, + }) + .addEventListener("click", async (e) => { + await onAccept(e); + this.close(); + }); + }); + } +} +function createConfirmationDialog({ cta, onAccept, text, title, }) { + new ConfirmationModal(window.app, { cta, onAccept, text, title }).open(); +} + +/** + * Create a Daily Note for a given date. + */ +async function tryToCreateDailyNote(date, inNewSplit, settings, cb) { + const { workspace } = window.app; + const { format } = getDailyNoteSettings_1(); + const filename = date.format(format); + const createFile = async () => { + const dailyNote = await createDailyNote_1(date); + const leaf = inNewSplit + ? workspace.splitActiveLeaf() + : workspace.getUnpinnedLeaf(); + await leaf.openFile(dailyNote); + cb === null || cb === void 0 ? void 0 : cb(dailyNote); + }; + if (settings.shouldConfirmBeforeCreate) { + createConfirmationDialog({ + cta: "Create", + onAccept: createFile, + text: `File ${filename} does not exist. Would you like to create it?`, + title: "New Daily Note", + }); + } + else { + await createFile(); + } +} + +/** + * Create a Weekly Note for a given date. + */ +async function tryToCreateWeeklyNote(date, inNewSplit, settings, cb) { + const { workspace } = window.app; + const { format } = getWeeklyNoteSettings_1(); + const filename = date.format(format); + const createFile = async () => { + const dailyNote = await createWeeklyNote_1(date); + const leaf = inNewSplit + ? workspace.splitActiveLeaf() + : workspace.getUnpinnedLeaf(); + await leaf.openFile(dailyNote); + cb === null || cb === void 0 ? void 0 : cb(dailyNote); + }; + if (settings.shouldConfirmBeforeCreate) { + createConfirmationDialog({ + cta: "Create", + onAccept: createFile, + text: `File ${filename} does not exist. Would you like to create it?`, + title: "New Weekly Note", + }); + } + else { + await createFile(); + } +} + +function noop() { } +function assign(tar, src) { + // @ts-ignore + for (const k in src) + tar[k] = src[k]; + return tar; +} +function is_promise(value) { + return value && typeof value === 'object' && typeof value.then === 'function'; +} +function run(fn) { + return fn(); +} +function blank_object() { + return Object.create(null); +} +function run_all(fns) { + fns.forEach(run); +} +function is_function(thing) { + return typeof thing === 'function'; +} +function safe_not_equal(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} +function not_equal(a, b) { + return a != a ? b == b : a !== b; +} +function is_empty(obj) { + return Object.keys(obj).length === 0; +} +function create_slot(definition, ctx, $$scope, fn) { + if (definition) { + const slot_ctx = get_slot_context(definition, ctx, $$scope, fn); + return definition[0](slot_ctx); + } +} +function get_slot_context(definition, ctx, $$scope, fn) { + return definition[1] && fn + ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) + : $$scope.ctx; +} +function get_slot_changes(definition, $$scope, dirty, fn) { + if (definition[2] && fn) { + const lets = definition[2](fn(dirty)); + if ($$scope.dirty === undefined) { + return lets; + } + if (typeof lets === 'object') { + const merged = []; + const len = Math.max($$scope.dirty.length, lets.length); + for (let i = 0; i < len; i += 1) { + merged[i] = $$scope.dirty[i] | lets[i]; + } + return merged; + } + return $$scope.dirty | lets; + } + return $$scope.dirty; +} +function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) { + const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); + if (slot_changes) { + const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); + slot.p(slot_context, slot_changes); + } +} +function null_to_empty(value) { + return value == null ? '' : value; +} + +function append(target, node) { + target.appendChild(node); +} +function insert(target, node, anchor) { + target.insertBefore(node, anchor || null); +} +function detach(node) { + node.parentNode.removeChild(node); +} +function destroy_each(iterations, detaching) { + for (let i = 0; i < iterations.length; i += 1) { + if (iterations[i]) + iterations[i].d(detaching); + } +} +function element(name) { + return document.createElement(name); +} +function svg_element(name) { + return document.createElementNS('http://www.w3.org/2000/svg', name); +} +function text(data) { + return document.createTextNode(data); +} +function space() { + return text(' '); +} +function empty() { + return text(''); +} +function listen(node, event, handler, options) { + node.addEventListener(event, handler, options); + return () => node.removeEventListener(event, handler, options); +} +function attr(node, attribute, value) { + if (value == null) + node.removeAttribute(attribute); + else if (node.getAttribute(attribute) !== value) + node.setAttribute(attribute, value); +} +function set_attributes(node, attributes) { + // @ts-ignore + const descriptors = Object.getOwnPropertyDescriptors(node.__proto__); + for (const key in attributes) { + if (attributes[key] == null) { + node.removeAttribute(key); + } + else if (key === 'style') { + node.style.cssText = attributes[key]; + } + else if (key === '__value') { + node.value = node[key] = attributes[key]; + } + else if (descriptors[key] && descriptors[key].set) { + node[key] = attributes[key]; + } + else { + attr(node, key, attributes[key]); + } + } +} +function children(element) { + return Array.from(element.childNodes); +} +function set_data(text, data) { + data = '' + data; + if (text.wholeText !== data) + text.data = data; +} +function toggle_class(element, name, toggle) { + element.classList[toggle ? 'add' : 'remove'](name); +} + +let current_component; +function set_current_component(component) { + current_component = component; +} +function get_current_component() { + if (!current_component) + throw new Error('Function called outside component initialization'); + return current_component; +} + +const dirty_components = []; +const binding_callbacks = []; +const render_callbacks = []; +const flush_callbacks = []; +const resolved_promise = Promise.resolve(); +let update_scheduled = false; +function schedule_update() { + if (!update_scheduled) { + update_scheduled = true; + resolved_promise.then(flush); + } +} +function add_render_callback(fn) { + render_callbacks.push(fn); +} +let flushing = false; +const seen_callbacks = new Set(); +function flush() { + if (flushing) + return; + flushing = true; + do { + // first, call beforeUpdate functions + // and update components + for (let i = 0; i < dirty_components.length; i += 1) { + const component = dirty_components[i]; + set_current_component(component); + update(component.$$); + } + set_current_component(null); + dirty_components.length = 0; + while (binding_callbacks.length) + binding_callbacks.pop()(); + // then, once components are updated, call + // afterUpdate functions. This may cause + // subsequent updates... + for (let i = 0; i < render_callbacks.length; i += 1) { + const callback = render_callbacks[i]; + if (!seen_callbacks.has(callback)) { + // ...so guard against infinite loops + seen_callbacks.add(callback); + callback(); + } + } + render_callbacks.length = 0; + } while (dirty_components.length); + while (flush_callbacks.length) { + flush_callbacks.pop()(); + } + update_scheduled = false; + flushing = false; + seen_callbacks.clear(); +} +function update($$) { + if ($$.fragment !== null) { + $$.update(); + run_all($$.before_update); + const dirty = $$.dirty; + $$.dirty = [-1]; + $$.fragment && $$.fragment.p($$.ctx, dirty); + $$.after_update.forEach(add_render_callback); + } +} +const outroing = new Set(); +let outros; +function group_outros() { + outros = { + r: 0, + c: [], + p: outros // parent group + }; +} +function check_outros() { + if (!outros.r) { + run_all(outros.c); + } + outros = outros.p; +} +function transition_in(block, local) { + if (block && block.i) { + outroing.delete(block); + block.i(local); + } +} +function transition_out(block, local, detach, callback) { + if (block && block.o) { + if (outroing.has(block)) + return; + outroing.add(block); + outros.c.push(() => { + outroing.delete(block); + if (callback) { + if (detach) + block.d(1); + callback(); + } + }); + block.o(local); + } +} + +function handle_promise(promise, info) { + const token = info.token = {}; + function update(type, index, key, value) { + if (info.token !== token) + return; + info.resolved = value; + let child_ctx = info.ctx; + if (key !== undefined) { + child_ctx = child_ctx.slice(); + child_ctx[key] = value; + } + const block = type && (info.current = type)(child_ctx); + let needs_flush = false; + if (info.block) { + if (info.blocks) { + info.blocks.forEach((block, i) => { + if (i !== index && block) { + group_outros(); + transition_out(block, 1, 1, () => { + if (info.blocks[i] === block) { + info.blocks[i] = null; + } + }); + check_outros(); + } + }); + } + else { + info.block.d(1); + } + block.c(); + transition_in(block, 1); + block.m(info.mount(), info.anchor); + needs_flush = true; + } + info.block = block; + if (info.blocks) + info.blocks[index] = block; + if (needs_flush) { + flush(); + } + } + if (is_promise(promise)) { + const current_component = get_current_component(); + promise.then(value => { + set_current_component(current_component); + update(info.then, 1, info.value, value); + set_current_component(null); + }, error => { + set_current_component(current_component); + update(info.catch, 2, info.error, error); + set_current_component(null); + if (!info.hasCatch) { + throw error; + } + }); + // if we previously had a then/catch block, destroy it + if (info.current !== info.pending) { + update(info.pending, 0); + return true; + } + } + else { + if (info.current !== info.then) { + update(info.then, 1, info.value, promise); + return true; + } + info.resolved = promise; + } +} +function outro_and_destroy_block(block, lookup) { + transition_out(block, 1, 1, () => { + lookup.delete(block.key); + }); +} +function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) { + let o = old_blocks.length; + let n = list.length; + let i = o; + const old_indexes = {}; + while (i--) + old_indexes[old_blocks[i].key] = i; + const new_blocks = []; + const new_lookup = new Map(); + const deltas = new Map(); + i = n; + while (i--) { + const child_ctx = get_context(ctx, list, i); + const key = get_key(child_ctx); + let block = lookup.get(key); + if (!block) { + block = create_each_block(key, child_ctx); + block.c(); + } + else if (dynamic) { + block.p(child_ctx, dirty); + } + new_lookup.set(key, new_blocks[i] = block); + if (key in old_indexes) + deltas.set(key, Math.abs(i - old_indexes[key])); + } + const will_move = new Set(); + const did_move = new Set(); + function insert(block) { + transition_in(block, 1); + block.m(node, next); + lookup.set(block.key, block); + next = block.first; + n--; + } + while (o && n) { + const new_block = new_blocks[n - 1]; + const old_block = old_blocks[o - 1]; + const new_key = new_block.key; + const old_key = old_block.key; + if (new_block === old_block) { + // do nothing + next = new_block.first; + o--; + n--; + } + else if (!new_lookup.has(old_key)) { + // remove old block + destroy(old_block, lookup); + o--; + } + else if (!lookup.has(new_key) || will_move.has(new_key)) { + insert(new_block); + } + else if (did_move.has(old_key)) { + o--; + } + else if (deltas.get(new_key) > deltas.get(old_key)) { + did_move.add(new_key); + insert(new_block); + } + else { + will_move.add(old_key); + o--; + } + } + while (o--) { + const old_block = old_blocks[o]; + if (!new_lookup.has(old_block.key)) + destroy(old_block, lookup); + } + while (n) + insert(new_blocks[n - 1]); + return new_blocks; +} + +function get_spread_update(levels, updates) { + const update = {}; + const to_null_out = {}; + const accounted_for = { $$scope: 1 }; + let i = levels.length; + while (i--) { + const o = levels[i]; + const n = updates[i]; + if (n) { + for (const key in o) { + if (!(key in n)) + to_null_out[key] = 1; + } + for (const key in n) { + if (!accounted_for[key]) { + update[key] = n[key]; + accounted_for[key] = 1; + } + } + levels[i] = n; + } + else { + for (const key in o) { + accounted_for[key] = 1; + } + } + } + for (const key in to_null_out) { + if (!(key in update)) + update[key] = undefined; + } + return update; +} +function get_spread_object(spread_props) { + return typeof spread_props === 'object' && spread_props !== null ? spread_props : {}; +} +function create_component(block) { + block && block.c(); +} +function mount_component(component, target, anchor, customElement) { + const { fragment, on_mount, on_destroy, after_update } = component.$$; + fragment && fragment.m(target, anchor); + if (!customElement) { + // onMount happens before the initial afterUpdate + add_render_callback(() => { + const new_on_destroy = on_mount.map(run).filter(is_function); + if (on_destroy) { + on_destroy.push(...new_on_destroy); + } + else { + // Edge case - component was destroyed immediately, + // most likely as a result of a binding initialising + run_all(new_on_destroy); + } + component.$$.on_mount = []; + }); + } + after_update.forEach(add_render_callback); +} +function destroy_component(component, detaching) { + const $$ = component.$$; + if ($$.fragment !== null) { + run_all($$.on_destroy); + $$.fragment && $$.fragment.d(detaching); + // TODO null out other refs, including component.$$ (but need to + // preserve final state?) + $$.on_destroy = $$.fragment = null; + $$.ctx = []; + } +} +function make_dirty(component, i) { + if (component.$$.dirty[0] === -1) { + dirty_components.push(component); + schedule_update(); + component.$$.dirty.fill(0); + } + component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); +} +function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { + const parent_component = current_component; + set_current_component(component); + const $$ = component.$$ = { + fragment: null, + ctx: null, + // state + props, + update: noop, + not_equal, + bound: blank_object(), + // lifecycle + on_mount: [], + on_destroy: [], + on_disconnect: [], + before_update: [], + after_update: [], + context: new Map(parent_component ? parent_component.$$.context : []), + // everything else + callbacks: blank_object(), + dirty, + skip_bound: false + }; + let ready = false; + $$.ctx = instance + ? instance(component, options.props || {}, (i, ret, ...rest) => { + const value = rest.length ? rest[0] : ret; + if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { + if (!$$.skip_bound && $$.bound[i]) + $$.bound[i](value); + if (ready) + make_dirty(component, i); + } + return ret; + }) + : []; + $$.update(); + ready = true; + run_all($$.before_update); + // `false` as a special case of no DOM component + $$.fragment = create_fragment ? create_fragment($$.ctx) : false; + if (options.target) { + if (options.hydrate) { + const nodes = children(options.target); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.l(nodes); + nodes.forEach(detach); + } + else { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.c(); + } + if (options.intro) + transition_in(component.$$.fragment); + mount_component(component, options.target, options.anchor, options.customElement); + flush(); + } + set_current_component(parent_component); +} +/** + * Base class for Svelte components. Used when dev=false. + */ +class SvelteComponent { + $destroy() { + destroy_component(this, 1); + this.$destroy = noop; + } + $on(type, callback) { + const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); + callbacks.push(callback); + return () => { + const index = callbacks.indexOf(callback); + if (index !== -1) + callbacks.splice(index, 1); + }; + } + $set($$props) { + if (this.$$set && !is_empty($$props)) { + this.$$.skip_bound = true; + this.$$set($$props); + this.$$.skip_bound = false; + } + } +} + +/** + * dateUID is a way of weekly identifying daily/weekly/monthly notes. + * They are prefixed with the granularity to avoid ambiguity. + */ +function getDateUID(date, granularity = "day") { + const ts = date.clone().startOf(granularity).format(); + return `${granularity}-${ts}`; +} +var getDateUID_1 = getDateUID; + +/* src/components/Dot.svelte generated by Svelte v3.35.0 */ + +function add_css$5() { + var style = element("style"); + style.id = "svelte-1widvzq-style"; + style.textContent = ".dot.svelte-1widvzq,.hollow.svelte-1widvzq{display:inline-block;height:6px;width:6px;margin:0 1px}.filled.svelte-1widvzq{fill:var(--color-dot)}.active.filled.svelte-1widvzq{fill:var(--text-on-accent)}.hollow.svelte-1widvzq{fill:none;stroke:var(--color-dot)}.active.hollow.svelte-1widvzq{fill:none;stroke:var(--text-on-accent)}"; + append(document.head, style); +} + +// (14:0) {:else} +function create_else_block$1(ctx) { + let svg; + let circle; + let svg_class_value; + + return { + c() { + svg = svg_element("svg"); + circle = svg_element("circle"); + attr(circle, "cx", "3"); + attr(circle, "cy", "3"); + attr(circle, "r", "2"); + attr(svg, "class", svg_class_value = "" + (null_to_empty(`hollow ${/*className*/ ctx[0]}`) + " svelte-1widvzq")); + attr(svg, "viewBox", "0 0 6 6"); + attr(svg, "xmlns", "http://www.w3.org/2000/svg"); + toggle_class(svg, "active", /*isActive*/ ctx[2]); + }, + m(target, anchor) { + insert(target, svg, anchor); + append(svg, circle); + }, + p(ctx, dirty) { + if (dirty & /*className*/ 1 && svg_class_value !== (svg_class_value = "" + (null_to_empty(`hollow ${/*className*/ ctx[0]}`) + " svelte-1widvzq"))) { + attr(svg, "class", svg_class_value); + } + + if (dirty & /*className, isActive*/ 5) { + toggle_class(svg, "active", /*isActive*/ ctx[2]); + } + }, + d(detaching) { + if (detaching) detach(svg); + } + }; +} + +// (6:0) {#if isFilled} +function create_if_block$2(ctx) { + let svg; + let circle; + let svg_class_value; + + return { + c() { + svg = svg_element("svg"); + circle = svg_element("circle"); + attr(circle, "cx", "3"); + attr(circle, "cy", "3"); + attr(circle, "r", "2"); + attr(svg, "class", svg_class_value = "" + (null_to_empty(`dot filled ${/*className*/ ctx[0]}`) + " svelte-1widvzq")); + attr(svg, "viewBox", "0 0 6 6"); + attr(svg, "xmlns", "http://www.w3.org/2000/svg"); + toggle_class(svg, "active", /*isActive*/ ctx[2]); + }, + m(target, anchor) { + insert(target, svg, anchor); + append(svg, circle); + }, + p(ctx, dirty) { + if (dirty & /*className*/ 1 && svg_class_value !== (svg_class_value = "" + (null_to_empty(`dot filled ${/*className*/ ctx[0]}`) + " svelte-1widvzq"))) { + attr(svg, "class", svg_class_value); + } + + if (dirty & /*className, isActive*/ 5) { + toggle_class(svg, "active", /*isActive*/ ctx[2]); + } + }, + d(detaching) { + if (detaching) detach(svg); + } + }; +} + +function create_fragment$6(ctx) { + let if_block_anchor; + + function select_block_type(ctx, dirty) { + if (/*isFilled*/ ctx[1]) return create_if_block$2; + return create_else_block$1; + } + + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + + return { + c() { + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + }, + p(ctx, [dirty]) { + if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + + if (if_block) { + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } + }, + i: noop, + o: noop, + d(detaching) { + if_block.d(detaching); + if (detaching) detach(if_block_anchor); + } + }; +} + +function instance$6($$self, $$props, $$invalidate) { + let { className = "" } = $$props; + let { isFilled } = $$props; + let { isActive } = $$props; + + $$self.$$set = $$props => { + if ("className" in $$props) $$invalidate(0, className = $$props.className); + if ("isFilled" in $$props) $$invalidate(1, isFilled = $$props.isFilled); + if ("isActive" in $$props) $$invalidate(2, isActive = $$props.isActive); + }; + + return [className, isFilled, isActive]; +} + +class Dot extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-1widvzq-style")) add_css$5(); + init(this, options, instance$6, create_fragment$6, safe_not_equal, { className: 0, isFilled: 1, isActive: 2 }); + } +} + +/* src/components/MetadataResolver.svelte generated by Svelte v3.35.0 */ + +const get_default_slot_changes_1 = dirty => ({}); +const get_default_slot_context_1 = ctx => ({ metadata: null }); +const get_default_slot_changes = dirty => ({ metadata: dirty & /*metadata*/ 1 }); +const get_default_slot_context = ctx => ({ metadata: /*resolvedMeta*/ ctx[3] }); + +// (11:0) {:else} +function create_else_block(ctx) { + let current; + const default_slot_template = /*#slots*/ ctx[2].default; + const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[1], get_default_slot_context_1); + + return { + c() { + if (default_slot) default_slot.c(); + }, + m(target, anchor) { + if (default_slot) { + default_slot.m(target, anchor); + } + + current = true; + }, + p(ctx, dirty) { + if (default_slot) { + if (default_slot.p && dirty & /*$$scope*/ 2) { + update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[1], dirty, get_default_slot_changes_1, get_default_slot_context_1); + } + } + }, + i(local) { + if (current) return; + transition_in(default_slot, local); + current = true; + }, + o(local) { + transition_out(default_slot, local); + current = false; + }, + d(detaching) { + if (default_slot) default_slot.d(detaching); + } + }; +} + +// (7:0) {#if metadata} +function create_if_block$1(ctx) { + let await_block_anchor; + let promise; + let current; + + let info = { + ctx, + current: null, + token: null, + hasCatch: false, + pending: create_pending_block, + then: create_then_block, + catch: create_catch_block, + value: 3, + blocks: [,,,] + }; + + handle_promise(promise = /*metadata*/ ctx[0], info); + + return { + c() { + await_block_anchor = empty(); + info.block.c(); + }, + m(target, anchor) { + insert(target, await_block_anchor, anchor); + info.block.m(target, info.anchor = anchor); + info.mount = () => await_block_anchor.parentNode; + info.anchor = await_block_anchor; + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + info.ctx = ctx; + + if (dirty & /*metadata*/ 1 && promise !== (promise = /*metadata*/ ctx[0]) && handle_promise(promise, info)) ; else { + const child_ctx = ctx.slice(); + child_ctx[3] = info.resolved; + info.block.p(child_ctx, dirty); + } + }, + i(local) { + if (current) return; + transition_in(info.block); + current = true; + }, + o(local) { + for (let i = 0; i < 3; i += 1) { + const block = info.blocks[i]; + transition_out(block); + } + + current = false; + }, + d(detaching) { + if (detaching) detach(await_block_anchor); + info.block.d(detaching); + info.token = null; + info = null; + } + }; +} + +// (1:0) {#if metadata} +function create_catch_block(ctx) { + return { + c: noop, + m: noop, + p: noop, + i: noop, + o: noop, + d: noop + }; +} + +// (8:37) ; export let metadata; {#if metadata} +function create_pending_block(ctx) { + return { + c: noop, + m: noop, + p: noop, + i: noop, + o: noop, + d: noop + }; +} + +function create_fragment$5(ctx) { + let current_block_type_index; + let if_block; + let if_block_anchor; + let current; + const if_block_creators = [create_if_block$1, create_else_block]; + const if_blocks = []; + + function select_block_type(ctx, dirty) { + if (/*metadata*/ ctx[0]) return 0; + return 1; + } + + current_block_type_index = select_block_type(ctx); + if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); + + return { + c() { + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if_blocks[current_block_type_index].m(target, anchor); + insert(target, if_block_anchor, anchor); + current = true; + }, + p(ctx, [dirty]) { + let previous_block_index = current_block_type_index; + current_block_type_index = select_block_type(ctx); + + if (current_block_type_index === previous_block_index) { + if_blocks[current_block_type_index].p(ctx, dirty); + } else { + group_outros(); + + transition_out(if_blocks[previous_block_index], 1, 1, () => { + if_blocks[previous_block_index] = null; + }); + + check_outros(); + if_block = if_blocks[current_block_type_index]; + + if (!if_block) { + if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); + if_block.c(); + } else { + if_block.p(ctx, dirty); + } + + transition_in(if_block, 1); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + }, + i(local) { + if (current) return; + transition_in(if_block); + current = true; + }, + o(local) { + transition_out(if_block); + current = false; + }, + d(detaching) { + if_blocks[current_block_type_index].d(detaching); + if (detaching) detach(if_block_anchor); + } + }; +} + +function instance$5($$self, $$props, $$invalidate) { + let { $$slots: slots = {}, $$scope } = $$props; + + let { metadata } = $$props; + + $$self.$$set = $$props => { + if ("metadata" in $$props) $$invalidate(0, metadata = $$props.metadata); + if ("$$scope" in $$props) $$invalidate(1, $$scope = $$props.$$scope); + }; + + return [metadata, $$scope, slots]; +} + +class MetadataResolver extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$5, create_fragment$5, not_equal, { metadata: 0 }); + } +} + +function isMacOS() { + return navigator.appVersion.indexOf("Mac") !== -1; +} +function isMetaPressed(e) { + return isMacOS() ? e.metaKey : e.ctrlKey; +} +function getDaysOfWeek(..._args) { + return window.moment.weekdaysShort(true); +} +function isWeekend(date) { + return date.isoWeekday() === 6 || date.isoWeekday() === 7; +} +function getStartOfWeek(days) { + return days[0].weekday(0); +} +/** + * Generate a 2D array of daily information to power + * the calendar view. + */ +function getMonth(displayedMonth, ..._args) { + const locale = window.moment().locale(); + const month = []; + let week; + const startOfMonth = displayedMonth.clone().locale(locale).date(1); + const startOffset = startOfMonth.weekday(); + let date = startOfMonth.clone().subtract(startOffset, "days"); + for (let _day = 0; _day < 42; _day++) { + if (_day % 7 === 0) { + week = { + days: [], + weekNum: date.week(), + }; + month.push(week); + } + week.days.push(date); + date = date.clone().add(1, "days"); + } + return month; +} + +/* src/components/Day.svelte generated by Svelte v3.35.0 */ + +function add_css$4() { + var style = element("style"); + style.id = "svelte-q3wqg9-style"; + style.textContent = ".day.svelte-q3wqg9{background-color:var(--color-background-day);border-radius:4px;color:var(--color-text-day);cursor:pointer;font-size:0.8em;height:100%;padding:4px;position:relative;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.day.svelte-q3wqg9:hover{background-color:var(--interactive-hover)}.day.active.svelte-q3wqg9:hover{background-color:var(--interactive-accent-hover)}.adjacent-month.svelte-q3wqg9{opacity:0.25}.today.svelte-q3wqg9{color:var(--color-text-today)}.day.svelte-q3wqg9:active,.active.svelte-q3wqg9,.active.today.svelte-q3wqg9{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-q3wqg9{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}"; + append(document.head, style); +} + +function get_each_context$2(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[11] = list[i]; + return child_ctx; +} + +// (36:8) {#each metadata.dots as dot} +function create_each_block$2(ctx) { + let dot; + let current; + const dot_spread_levels = [/*dot*/ ctx[11]]; + let dot_props = {}; + + for (let i = 0; i < dot_spread_levels.length; i += 1) { + dot_props = assign(dot_props, dot_spread_levels[i]); + } + + dot = new Dot({ props: dot_props }); + + return { + c() { + create_component(dot.$$.fragment); + }, + m(target, anchor) { + mount_component(dot, target, anchor); + current = true; + }, + p(ctx, dirty) { + const dot_changes = (dirty & /*metadata*/ 128) + ? get_spread_update(dot_spread_levels, [get_spread_object(/*dot*/ ctx[11])]) + : {}; + + dot.$set(dot_changes); + }, + i(local) { + if (current) return; + transition_in(dot.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(dot.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(dot, detaching); + } + }; +} + +// (22:2) +function create_default_slot$1(ctx) { + let div1; + let t0_value = /*date*/ ctx[0].format("D") + ""; + let t0; + let t1; + let div0; + let div1_class_value; + let current; + let mounted; + let dispose; + let each_value = /*metadata*/ ctx[7].dots; + let each_blocks = []; + + for (let i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i)); + } + + const out = i => transition_out(each_blocks[i], 1, 1, () => { + each_blocks[i] = null; + }); + + let div1_levels = [ + { + class: div1_class_value = `day ${/*metadata*/ ctx[7].classes.join(" ")}` + }, + /*metadata*/ ctx[7].dataAttributes || {} + ]; + + let div1_data = {}; + + for (let i = 0; i < div1_levels.length; i += 1) { + div1_data = assign(div1_data, div1_levels[i]); + } + + return { + c() { + div1 = element("div"); + t0 = text(t0_value); + t1 = space(); + div0 = element("div"); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + attr(div0, "class", "dot-container svelte-q3wqg9"); + set_attributes(div1, div1_data); + toggle_class(div1, "active", /*selectedId*/ ctx[6] === getDateUID_1(/*date*/ ctx[0], "day")); + toggle_class(div1, "adjacent-month", !/*date*/ ctx[0].isSame(/*displayedMonth*/ ctx[5], "month")); + toggle_class(div1, "today", /*date*/ ctx[0].isSame(/*today*/ ctx[4], "day")); + toggle_class(div1, "svelte-q3wqg9", true); + }, + m(target, anchor) { + insert(target, div1, anchor); + append(div1, t0); + append(div1, t1); + append(div1, div0); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(div0, null); + } + + current = true; + + if (!mounted) { + dispose = [ + listen(div1, "click", function () { + if (is_function(/*onClick*/ ctx[2] && /*click_handler*/ ctx[8])) (/*onClick*/ ctx[2] && /*click_handler*/ ctx[8]).apply(this, arguments); + }), + listen(div1, "contextmenu", function () { + if (is_function(/*onContextMenu*/ ctx[3] && /*contextmenu_handler*/ ctx[9])) (/*onContextMenu*/ ctx[3] && /*contextmenu_handler*/ ctx[9]).apply(this, arguments); + }), + listen(div1, "pointerover", function () { + if (is_function(/*onHover*/ ctx[1] && /*pointerover_handler*/ ctx[10])) (/*onHover*/ ctx[1] && /*pointerover_handler*/ ctx[10]).apply(this, arguments); + }) + ]; + + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if ((!current || dirty & /*date*/ 1) && t0_value !== (t0_value = /*date*/ ctx[0].format("D") + "")) set_data(t0, t0_value); + + if (dirty & /*metadata*/ 128) { + each_value = /*metadata*/ ctx[7].dots; + let i; + + for (i = 0; i < each_value.length; i += 1) { + const child_ctx = get_each_context$2(ctx, each_value, i); + + if (each_blocks[i]) { + each_blocks[i].p(child_ctx, dirty); + transition_in(each_blocks[i], 1); + } else { + each_blocks[i] = create_each_block$2(child_ctx); + each_blocks[i].c(); + transition_in(each_blocks[i], 1); + each_blocks[i].m(div0, null); + } + } + + group_outros(); + + for (i = each_value.length; i < each_blocks.length; i += 1) { + out(i); + } + + check_outros(); + } + + set_attributes(div1, div1_data = get_spread_update(div1_levels, [ + (!current || dirty & /*metadata*/ 128 && div1_class_value !== (div1_class_value = `day ${/*metadata*/ ctx[7].classes.join(" ")}`)) && { class: div1_class_value }, + dirty & /*metadata*/ 128 && (/*metadata*/ ctx[7].dataAttributes || {}) + ])); + + toggle_class(div1, "active", /*selectedId*/ ctx[6] === getDateUID_1(/*date*/ ctx[0], "day")); + toggle_class(div1, "adjacent-month", !/*date*/ ctx[0].isSame(/*displayedMonth*/ ctx[5], "month")); + toggle_class(div1, "today", /*date*/ ctx[0].isSame(/*today*/ ctx[4], "day")); + toggle_class(div1, "svelte-q3wqg9", true); + }, + i(local) { + if (current) return; + + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + + current = true; + }, + o(local) { + each_blocks = each_blocks.filter(Boolean); + + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + + current = false; + }, + d(detaching) { + if (detaching) detach(div1); + destroy_each(each_blocks, detaching); + mounted = false; + run_all(dispose); + } + }; +} + +function create_fragment$4(ctx) { + let td; + let metadataresolver; + let current; + + metadataresolver = new MetadataResolver({ + props: { + metadata: /*metadata*/ ctx[7], + $$slots: { + default: [ + create_default_slot$1, + ({ metadata }) => ({ 7: metadata }), + ({ metadata }) => metadata ? 128 : 0 + ] + }, + $$scope: { ctx } + } + }); + + return { + c() { + td = element("td"); + create_component(metadataresolver.$$.fragment); + }, + m(target, anchor) { + insert(target, td, anchor); + mount_component(metadataresolver, td, null); + current = true; + }, + p(ctx, [dirty]) { + const metadataresolver_changes = {}; + if (dirty & /*metadata*/ 128) metadataresolver_changes.metadata = /*metadata*/ ctx[7]; + + if (dirty & /*$$scope, metadata, selectedId, date, displayedMonth, today, onClick, onContextMenu, onHover*/ 16639) { + metadataresolver_changes.$$scope = { dirty, ctx }; + } + + metadataresolver.$set(metadataresolver_changes); + }, + i(local) { + if (current) return; + transition_in(metadataresolver.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(metadataresolver.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) detach(td); + destroy_component(metadataresolver); + } + }; +} + +function instance$4($$self, $$props, $$invalidate) { + + + let { date } = $$props; + let { metadata } = $$props; + let { onHover } = $$props; + let { onClick } = $$props; + let { onContextMenu } = $$props; + let { today } = $$props; + let { displayedMonth = null } = $$props; + let { selectedId = null } = $$props; + const click_handler = e => onClick(date, isMetaPressed(e)); + const contextmenu_handler = e => onContextMenu(date, e); + const pointerover_handler = e => onHover(date, e.target, isMetaPressed(e)); + + $$self.$$set = $$props => { + if ("date" in $$props) $$invalidate(0, date = $$props.date); + if ("metadata" in $$props) $$invalidate(7, metadata = $$props.metadata); + if ("onHover" in $$props) $$invalidate(1, onHover = $$props.onHover); + if ("onClick" in $$props) $$invalidate(2, onClick = $$props.onClick); + if ("onContextMenu" in $$props) $$invalidate(3, onContextMenu = $$props.onContextMenu); + if ("today" in $$props) $$invalidate(4, today = $$props.today); + if ("displayedMonth" in $$props) $$invalidate(5, displayedMonth = $$props.displayedMonth); + if ("selectedId" in $$props) $$invalidate(6, selectedId = $$props.selectedId); + }; + + return [ + date, + onHover, + onClick, + onContextMenu, + today, + displayedMonth, + selectedId, + metadata, + click_handler, + contextmenu_handler, + pointerover_handler + ]; +} + +class Day extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-q3wqg9-style")) add_css$4(); + + init(this, options, instance$4, create_fragment$4, not_equal, { + date: 0, + metadata: 7, + onHover: 1, + onClick: 2, + onContextMenu: 3, + today: 4, + displayedMonth: 5, + selectedId: 6 + }); + } +} + +/* src/components/Arrow.svelte generated by Svelte v3.35.0 */ + +function add_css$3() { + var style = element("style"); + style.id = "svelte-156w7na-style"; + style.textContent = ".arrow.svelte-156w7na.svelte-156w7na{align-items:center;cursor:pointer;display:flex;justify-content:center;width:24px}.arrow.is-mobile.svelte-156w7na.svelte-156w7na{width:32px}.right.svelte-156w7na.svelte-156w7na{transform:rotate(180deg)}.arrow.svelte-156w7na svg.svelte-156w7na{color:var(--color-arrow);height:16px;width:16px}"; + append(document.head, style); +} + +function create_fragment$3(ctx) { + let div; + let svg; + let path; + let mounted; + let dispose; + + return { + c() { + div = element("div"); + svg = svg_element("svg"); + path = svg_element("path"); + attr(path, "fill", "currentColor"); + attr(path, "d", "M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"); + attr(svg, "focusable", "false"); + attr(svg, "role", "img"); + attr(svg, "xmlns", "http://www.w3.org/2000/svg"); + attr(svg, "viewBox", "0 0 320 512"); + attr(svg, "class", "svelte-156w7na"); + attr(div, "class", "arrow svelte-156w7na"); + attr(div, "aria-label", /*tooltip*/ ctx[1]); + toggle_class(div, "is-mobile", /*isMobile*/ ctx[3]); + toggle_class(div, "right", /*direction*/ ctx[2] === "right"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, svg); + append(svg, path); + + if (!mounted) { + dispose = listen(div, "click", function () { + if (is_function(/*onClick*/ ctx[0])) /*onClick*/ ctx[0].apply(this, arguments); + }); + + mounted = true; + } + }, + p(new_ctx, [dirty]) { + ctx = new_ctx; + + if (dirty & /*tooltip*/ 2) { + attr(div, "aria-label", /*tooltip*/ ctx[1]); + } + + if (dirty & /*direction*/ 4) { + toggle_class(div, "right", /*direction*/ ctx[2] === "right"); + } + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(div); + mounted = false; + dispose(); + } + }; +} + +function instance$3($$self, $$props, $$invalidate) { + let { onClick } = $$props; + let { tooltip } = $$props; + let { direction } = $$props; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let isMobile = window.app.isMobile; + + $$self.$$set = $$props => { + if ("onClick" in $$props) $$invalidate(0, onClick = $$props.onClick); + if ("tooltip" in $$props) $$invalidate(1, tooltip = $$props.tooltip); + if ("direction" in $$props) $$invalidate(2, direction = $$props.direction); + }; + + return [onClick, tooltip, direction, isMobile]; +} + +class Arrow extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-156w7na-style")) add_css$3(); + init(this, options, instance$3, create_fragment$3, safe_not_equal, { onClick: 0, tooltip: 1, direction: 2 }); + } +} + +/* src/components/Nav.svelte generated by Svelte v3.35.0 */ + +function add_css$2() { + var style = element("style"); + style.id = "svelte-1vwr9dd-style"; + style.textContent = ".nav.svelte-1vwr9dd.svelte-1vwr9dd{align-items:center;display:flex;margin:0.6em 0 1em;padding:0 8px;width:100%}.nav.is-mobile.svelte-1vwr9dd.svelte-1vwr9dd{padding:0}.title.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--color-text-title);font-size:1.5em;margin:0}.is-mobile.svelte-1vwr9dd .title.svelte-1vwr9dd{font-size:1.3em}.month.svelte-1vwr9dd.svelte-1vwr9dd{font-weight:500;text-transform:capitalize}.year.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--interactive-accent)}.right-nav.svelte-1vwr9dd.svelte-1vwr9dd{display:flex;justify-content:center;margin-left:auto}.reset-button.svelte-1vwr9dd.svelte-1vwr9dd{cursor:pointer;border-radius:4px;color:var(--text-muted);font-size:0.7em;font-weight:600;letter-spacing:1px;margin:0 4px;padding:0px 4px;text-transform:uppercase}.is-mobile.svelte-1vwr9dd .reset-button.svelte-1vwr9dd{display:none}"; + append(document.head, style); +} + +function create_fragment$2(ctx) { + let div2; + let h3; + let span0; + let t0_value = /*displayedMonth*/ ctx[0].format("MMM") + ""; + let t0; + let t1; + let span1; + let t2_value = /*displayedMonth*/ ctx[0].format("YYYY") + ""; + let t2; + let t3; + let div1; + let arrow0; + let t4; + let div0; + let t6; + let arrow1; + let current; + let mounted; + let dispose; + + arrow0 = new Arrow({ + props: { + direction: "left", + onClick: /*decrementDisplayedMonth*/ ctx[3], + tooltip: "Previous Month" + } + }); + + arrow1 = new Arrow({ + props: { + direction: "right", + onClick: /*incrementDisplayedMonth*/ ctx[2], + tooltip: "Next Month" + } + }); + + return { + c() { + div2 = element("div"); + h3 = element("h3"); + span0 = element("span"); + t0 = text(t0_value); + t1 = space(); + span1 = element("span"); + t2 = text(t2_value); + t3 = space(); + div1 = element("div"); + create_component(arrow0.$$.fragment); + t4 = space(); + div0 = element("div"); + div0.textContent = `${/*todayDisplayStr*/ ctx[4]}`; + t6 = space(); + create_component(arrow1.$$.fragment); + attr(span0, "class", "month svelte-1vwr9dd"); + attr(span1, "class", "year svelte-1vwr9dd"); + attr(h3, "class", "title svelte-1vwr9dd"); + attr(div0, "class", "reset-button svelte-1vwr9dd"); + attr(div1, "class", "right-nav svelte-1vwr9dd"); + attr(div2, "class", "nav svelte-1vwr9dd"); + toggle_class(div2, "is-mobile", /*isMobile*/ ctx[5]); + }, + m(target, anchor) { + insert(target, div2, anchor); + append(div2, h3); + append(h3, span0); + append(span0, t0); + append(h3, t1); + append(h3, span1); + append(span1, t2); + append(div2, t3); + append(div2, div1); + mount_component(arrow0, div1, null); + append(div1, t4); + append(div1, div0); + append(div1, t6); + mount_component(arrow1, div1, null); + current = true; + + if (!mounted) { + dispose = [ + listen(h3, "click", function () { + if (is_function(/*resetDisplayedMonth*/ ctx[1])) /*resetDisplayedMonth*/ ctx[1].apply(this, arguments); + }), + listen(div0, "click", function () { + if (is_function(/*resetDisplayedMonth*/ ctx[1])) /*resetDisplayedMonth*/ ctx[1].apply(this, arguments); + }) + ]; + + mounted = true; + } + }, + p(new_ctx, [dirty]) { + ctx = new_ctx; + if ((!current || dirty & /*displayedMonth*/ 1) && t0_value !== (t0_value = /*displayedMonth*/ ctx[0].format("MMM") + "")) set_data(t0, t0_value); + if ((!current || dirty & /*displayedMonth*/ 1) && t2_value !== (t2_value = /*displayedMonth*/ ctx[0].format("YYYY") + "")) set_data(t2, t2_value); + const arrow0_changes = {}; + if (dirty & /*decrementDisplayedMonth*/ 8) arrow0_changes.onClick = /*decrementDisplayedMonth*/ ctx[3]; + arrow0.$set(arrow0_changes); + const arrow1_changes = {}; + if (dirty & /*incrementDisplayedMonth*/ 4) arrow1_changes.onClick = /*incrementDisplayedMonth*/ ctx[2]; + arrow1.$set(arrow1_changes); + }, + i(local) { + if (current) return; + transition_in(arrow0.$$.fragment, local); + transition_in(arrow1.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(arrow0.$$.fragment, local); + transition_out(arrow1.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) detach(div2); + destroy_component(arrow0); + destroy_component(arrow1); + mounted = false; + run_all(dispose); + } + }; +} + +function instance$2($$self, $$props, $$invalidate) { + + let { displayedMonth } = $$props; + let { today } = $$props; + let { resetDisplayedMonth } = $$props; + let { incrementDisplayedMonth } = $$props; + let { decrementDisplayedMonth } = $$props; + + // Get the word 'Today' but localized to the current language + const todayDisplayStr = today.calendar().split(/\d|\s/)[0]; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let isMobile = window.app.isMobile; + + $$self.$$set = $$props => { + if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth); + if ("today" in $$props) $$invalidate(6, today = $$props.today); + if ("resetDisplayedMonth" in $$props) $$invalidate(1, resetDisplayedMonth = $$props.resetDisplayedMonth); + if ("incrementDisplayedMonth" in $$props) $$invalidate(2, incrementDisplayedMonth = $$props.incrementDisplayedMonth); + if ("decrementDisplayedMonth" in $$props) $$invalidate(3, decrementDisplayedMonth = $$props.decrementDisplayedMonth); + }; + + return [ + displayedMonth, + resetDisplayedMonth, + incrementDisplayedMonth, + decrementDisplayedMonth, + todayDisplayStr, + isMobile, + today + ]; +} + +class Nav extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-1vwr9dd-style")) add_css$2(); + + init(this, options, instance$2, create_fragment$2, safe_not_equal, { + displayedMonth: 0, + today: 6, + resetDisplayedMonth: 1, + incrementDisplayedMonth: 2, + decrementDisplayedMonth: 3 + }); + } +} + +/* src/components/WeekNum.svelte generated by Svelte v3.35.0 */ + +function add_css$1() { + var style = element("style"); + style.id = "svelte-egt0yd-style"; + style.textContent = "td.svelte-egt0yd{border-right:1px solid var(--background-modifier-border)}.week-num.svelte-egt0yd{background-color:var(--color-background-weeknum);border-radius:4px;color:var(--color-text-weeknum);cursor:pointer;font-size:0.65em;height:100%;padding:4px;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.week-num.svelte-egt0yd:hover{background-color:var(--interactive-hover)}.week-num.active.svelte-egt0yd:hover{background-color:var(--interactive-accent-hover)}.active.svelte-egt0yd{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-egt0yd{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}"; + append(document.head, style); +} + +function get_each_context$1(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[11] = list[i]; + return child_ctx; +} + +// (35:8) {#each metadata.dots as dot} +function create_each_block$1(ctx) { + let dot; + let current; + const dot_spread_levels = [/*dot*/ ctx[11]]; + let dot_props = {}; + + for (let i = 0; i < dot_spread_levels.length; i += 1) { + dot_props = assign(dot_props, dot_spread_levels[i]); + } + + dot = new Dot({ props: dot_props }); + + return { + c() { + create_component(dot.$$.fragment); + }, + m(target, anchor) { + mount_component(dot, target, anchor); + current = true; + }, + p(ctx, dirty) { + const dot_changes = (dirty & /*metadata*/ 64) + ? get_spread_update(dot_spread_levels, [get_spread_object(/*dot*/ ctx[11])]) + : {}; + + dot.$set(dot_changes); + }, + i(local) { + if (current) return; + transition_in(dot.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(dot.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(dot, detaching); + } + }; +} + +// (24:2) +function create_default_slot(ctx) { + let div1; + let t0; + let t1; + let div0; + let div1_class_value; + let current; + let mounted; + let dispose; + let each_value = /*metadata*/ ctx[6].dots; + let each_blocks = []; + + for (let i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i)); + } + + const out = i => transition_out(each_blocks[i], 1, 1, () => { + each_blocks[i] = null; + }); + + return { + c() { + div1 = element("div"); + t0 = text(/*weekNum*/ ctx[0]); + t1 = space(); + div0 = element("div"); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + attr(div0, "class", "dot-container svelte-egt0yd"); + attr(div1, "class", div1_class_value = "" + (null_to_empty(`week-num ${/*metadata*/ ctx[6].classes.join(" ")}`) + " svelte-egt0yd")); + toggle_class(div1, "active", /*selectedId*/ ctx[5] === getDateUID_1(/*days*/ ctx[1][0], "week")); + }, + m(target, anchor) { + insert(target, div1, anchor); + append(div1, t0); + append(div1, t1); + append(div1, div0); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(div0, null); + } + + current = true; + + if (!mounted) { + dispose = [ + listen(div1, "click", function () { + if (is_function(/*onClick*/ ctx[3] && /*click_handler*/ ctx[8])) (/*onClick*/ ctx[3] && /*click_handler*/ ctx[8]).apply(this, arguments); + }), + listen(div1, "contextmenu", function () { + if (is_function(/*onContextMenu*/ ctx[4] && /*contextmenu_handler*/ ctx[9])) (/*onContextMenu*/ ctx[4] && /*contextmenu_handler*/ ctx[9]).apply(this, arguments); + }), + listen(div1, "pointerover", function () { + if (is_function(/*onHover*/ ctx[2] && /*pointerover_handler*/ ctx[10])) (/*onHover*/ ctx[2] && /*pointerover_handler*/ ctx[10]).apply(this, arguments); + }) + ]; + + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (!current || dirty & /*weekNum*/ 1) set_data(t0, /*weekNum*/ ctx[0]); + + if (dirty & /*metadata*/ 64) { + each_value = /*metadata*/ ctx[6].dots; + let i; + + for (i = 0; i < each_value.length; i += 1) { + const child_ctx = get_each_context$1(ctx, each_value, i); + + if (each_blocks[i]) { + each_blocks[i].p(child_ctx, dirty); + transition_in(each_blocks[i], 1); + } else { + each_blocks[i] = create_each_block$1(child_ctx); + each_blocks[i].c(); + transition_in(each_blocks[i], 1); + each_blocks[i].m(div0, null); + } + } + + group_outros(); + + for (i = each_value.length; i < each_blocks.length; i += 1) { + out(i); + } + + check_outros(); + } + + if (!current || dirty & /*metadata*/ 64 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`week-num ${/*metadata*/ ctx[6].classes.join(" ")}`) + " svelte-egt0yd"))) { + attr(div1, "class", div1_class_value); + } + + if (dirty & /*metadata, selectedId, getDateUID, days*/ 98) { + toggle_class(div1, "active", /*selectedId*/ ctx[5] === getDateUID_1(/*days*/ ctx[1][0], "week")); + } + }, + i(local) { + if (current) return; + + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + + current = true; + }, + o(local) { + each_blocks = each_blocks.filter(Boolean); + + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + + current = false; + }, + d(detaching) { + if (detaching) detach(div1); + destroy_each(each_blocks, detaching); + mounted = false; + run_all(dispose); + } + }; +} + +function create_fragment$1(ctx) { + let td; + let metadataresolver; + let current; + + metadataresolver = new MetadataResolver({ + props: { + metadata: /*metadata*/ ctx[6], + $$slots: { + default: [ + create_default_slot, + ({ metadata }) => ({ 6: metadata }), + ({ metadata }) => metadata ? 64 : 0 + ] + }, + $$scope: { ctx } + } + }); + + return { + c() { + td = element("td"); + create_component(metadataresolver.$$.fragment); + attr(td, "class", "svelte-egt0yd"); + }, + m(target, anchor) { + insert(target, td, anchor); + mount_component(metadataresolver, td, null); + current = true; + }, + p(ctx, [dirty]) { + const metadataresolver_changes = {}; + if (dirty & /*metadata*/ 64) metadataresolver_changes.metadata = /*metadata*/ ctx[6]; + + if (dirty & /*$$scope, metadata, selectedId, days, onClick, startOfWeek, onContextMenu, onHover, weekNum*/ 16639) { + metadataresolver_changes.$$scope = { dirty, ctx }; + } + + metadataresolver.$set(metadataresolver_changes); + }, + i(local) { + if (current) return; + transition_in(metadataresolver.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(metadataresolver.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) detach(td); + destroy_component(metadataresolver); + } + }; +} + +function instance$1($$self, $$props, $$invalidate) { + + + let { weekNum } = $$props; + let { days } = $$props; + let { metadata } = $$props; + let { onHover } = $$props; + let { onClick } = $$props; + let { onContextMenu } = $$props; + let { selectedId = null } = $$props; + let startOfWeek; + const click_handler = e => onClick(startOfWeek, isMetaPressed(e)); + const contextmenu_handler = e => onContextMenu(days[0], e); + const pointerover_handler = e => onHover(startOfWeek, e.target, isMetaPressed(e)); + + $$self.$$set = $$props => { + if ("weekNum" in $$props) $$invalidate(0, weekNum = $$props.weekNum); + if ("days" in $$props) $$invalidate(1, days = $$props.days); + if ("metadata" in $$props) $$invalidate(6, metadata = $$props.metadata); + if ("onHover" in $$props) $$invalidate(2, onHover = $$props.onHover); + if ("onClick" in $$props) $$invalidate(3, onClick = $$props.onClick); + if ("onContextMenu" in $$props) $$invalidate(4, onContextMenu = $$props.onContextMenu); + if ("selectedId" in $$props) $$invalidate(5, selectedId = $$props.selectedId); + }; + + $$self.$$.update = () => { + if ($$self.$$.dirty & /*days*/ 2) { + $$invalidate(7, startOfWeek = getStartOfWeek(days)); + } + }; + + return [ + weekNum, + days, + onHover, + onClick, + onContextMenu, + selectedId, + metadata, + startOfWeek, + click_handler, + contextmenu_handler, + pointerover_handler + ]; +} + +class WeekNum extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-egt0yd-style")) add_css$1(); + + init(this, options, instance$1, create_fragment$1, not_equal, { + weekNum: 0, + days: 1, + metadata: 6, + onHover: 2, + onClick: 3, + onContextMenu: 4, + selectedId: 5 + }); + } +} + +async function metadataReducer(promisedMetadata) { + const meta = { + dots: [], + classes: [], + dataAttributes: {}, + }; + const metas = await Promise.all(promisedMetadata); + return metas.reduce((acc, meta) => ({ + classes: [...acc.classes, ...(meta.classes || [])], + dataAttributes: Object.assign(acc.dataAttributes, meta.dataAttributes), + dots: [...acc.dots, ...(meta.dots || [])], + }), meta); +} +function getDailyMetadata(sources, date, ..._args) { + return metadataReducer(sources.map((source) => source.getDailyMetadata(date))); +} +function getWeeklyMetadata(sources, date, ..._args) { + return metadataReducer(sources.map((source) => source.getWeeklyMetadata(date))); +} + +/* src/components/Calendar.svelte generated by Svelte v3.35.0 */ + +function add_css() { + var style = element("style"); + style.id = "svelte-pcimu8-style"; + style.textContent = ".container.svelte-pcimu8{--color-background-heading:transparent;--color-background-day:transparent;--color-background-weeknum:transparent;--color-background-weekend:transparent;--color-dot:var(--text-muted);--color-arrow:var(--text-muted);--color-button:var(--text-muted);--color-text-title:var(--text-normal);--color-text-heading:var(--text-muted);--color-text-day:var(--text-normal);--color-text-today:var(--interactive-accent);--color-text-weeknum:var(--text-muted)}.container.svelte-pcimu8{padding:0 8px}.container.is-mobile.svelte-pcimu8{padding:0}th.svelte-pcimu8{text-align:center}.weekend.svelte-pcimu8{background-color:var(--color-background-weekend)}.calendar.svelte-pcimu8{border-collapse:collapse;width:100%}th.svelte-pcimu8{background-color:var(--color-background-heading);color:var(--color-text-heading);font-size:0.6em;letter-spacing:1px;padding:4px;text-transform:uppercase}"; + append(document.head, style); +} + +function get_each_context(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[18] = list[i]; + return child_ctx; +} + +function get_each_context_1(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[21] = list[i]; + return child_ctx; +} + +function get_each_context_2(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[24] = list[i]; + return child_ctx; +} + +function get_each_context_3(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[27] = list[i]; + return child_ctx; +} + +// (55:6) {#if showWeekNums} +function create_if_block_2(ctx) { + let col; + + return { + c() { + col = element("col"); + }, + m(target, anchor) { + insert(target, col, anchor); + }, + d(detaching) { + if (detaching) detach(col); + } + }; +} + +// (58:6) {#each month[1].days as date} +function create_each_block_3(ctx) { + let col; + + return { + c() { + col = element("col"); + attr(col, "class", "svelte-pcimu8"); + toggle_class(col, "weekend", isWeekend(/*date*/ ctx[27])); + }, + m(target, anchor) { + insert(target, col, anchor); + }, + p(ctx, dirty) { + if (dirty & /*isWeekend, month*/ 16384) { + toggle_class(col, "weekend", isWeekend(/*date*/ ctx[27])); + } + }, + d(detaching) { + if (detaching) detach(col); + } + }; +} + +// (64:8) {#if showWeekNums} +function create_if_block_1(ctx) { + let th; + + return { + c() { + th = element("th"); + th.textContent = "W"; + attr(th, "class", "svelte-pcimu8"); + }, + m(target, anchor) { + insert(target, th, anchor); + }, + d(detaching) { + if (detaching) detach(th); + } + }; +} + +// (67:8) {#each daysOfWeek as dayOfWeek} +function create_each_block_2(ctx) { + let th; + let t_value = /*dayOfWeek*/ ctx[24] + ""; + let t; + + return { + c() { + th = element("th"); + t = text(t_value); + attr(th, "class", "svelte-pcimu8"); + }, + m(target, anchor) { + insert(target, th, anchor); + append(th, t); + }, + p(ctx, dirty) { + if (dirty & /*daysOfWeek*/ 32768 && t_value !== (t_value = /*dayOfWeek*/ ctx[24] + "")) set_data(t, t_value); + }, + d(detaching) { + if (detaching) detach(th); + } + }; +} + +// (75:10) {#if showWeekNums} +function create_if_block(ctx) { + let weeknum; + let current; + + const weeknum_spread_levels = [ + /*week*/ ctx[18], + { + metadata: getWeeklyMetadata(/*sources*/ ctx[8], /*week*/ ctx[18].days[0], /*today*/ ctx[10]) + }, + { onClick: /*onClickWeek*/ ctx[7] }, + { + onContextMenu: /*onContextMenuWeek*/ ctx[5] + }, + { onHover: /*onHoverWeek*/ ctx[3] }, + { selectedId: /*selectedId*/ ctx[9] } + ]; + + let weeknum_props = {}; + + for (let i = 0; i < weeknum_spread_levels.length; i += 1) { + weeknum_props = assign(weeknum_props, weeknum_spread_levels[i]); + } + + weeknum = new WeekNum({ props: weeknum_props }); + + return { + c() { + create_component(weeknum.$$.fragment); + }, + m(target, anchor) { + mount_component(weeknum, target, anchor); + current = true; + }, + p(ctx, dirty) { + const weeknum_changes = (dirty & /*month, getWeeklyMetadata, sources, today, onClickWeek, onContextMenuWeek, onHoverWeek, selectedId*/ 18344) + ? get_spread_update(weeknum_spread_levels, [ + dirty & /*month*/ 16384 && get_spread_object(/*week*/ ctx[18]), + dirty & /*getWeeklyMetadata, sources, month, today*/ 17664 && { + metadata: getWeeklyMetadata(/*sources*/ ctx[8], /*week*/ ctx[18].days[0], /*today*/ ctx[10]) + }, + dirty & /*onClickWeek*/ 128 && { onClick: /*onClickWeek*/ ctx[7] }, + dirty & /*onContextMenuWeek*/ 32 && { + onContextMenu: /*onContextMenuWeek*/ ctx[5] + }, + dirty & /*onHoverWeek*/ 8 && { onHover: /*onHoverWeek*/ ctx[3] }, + dirty & /*selectedId*/ 512 && { selectedId: /*selectedId*/ ctx[9] } + ]) + : {}; + + weeknum.$set(weeknum_changes); + }, + i(local) { + if (current) return; + transition_in(weeknum.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(weeknum.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(weeknum, detaching); + } + }; +} + +// (85:10) {#each week.days as day (day.format())} +function create_each_block_1(key_1, ctx) { + let first; + let day; + let current; + + day = new Day({ + props: { + date: /*day*/ ctx[21], + today: /*today*/ ctx[10], + displayedMonth: /*displayedMonth*/ ctx[0], + onClick: /*onClickDay*/ ctx[6], + onContextMenu: /*onContextMenuDay*/ ctx[4], + onHover: /*onHoverDay*/ ctx[2], + metadata: getDailyMetadata(/*sources*/ ctx[8], /*day*/ ctx[21], /*today*/ ctx[10]), + selectedId: /*selectedId*/ ctx[9] + } + }); + + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(day.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(day, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const day_changes = {}; + if (dirty & /*month*/ 16384) day_changes.date = /*day*/ ctx[21]; + if (dirty & /*today*/ 1024) day_changes.today = /*today*/ ctx[10]; + if (dirty & /*displayedMonth*/ 1) day_changes.displayedMonth = /*displayedMonth*/ ctx[0]; + if (dirty & /*onClickDay*/ 64) day_changes.onClick = /*onClickDay*/ ctx[6]; + if (dirty & /*onContextMenuDay*/ 16) day_changes.onContextMenu = /*onContextMenuDay*/ ctx[4]; + if (dirty & /*onHoverDay*/ 4) day_changes.onHover = /*onHoverDay*/ ctx[2]; + if (dirty & /*sources, month, today*/ 17664) day_changes.metadata = getDailyMetadata(/*sources*/ ctx[8], /*day*/ ctx[21], /*today*/ ctx[10]); + if (dirty & /*selectedId*/ 512) day_changes.selectedId = /*selectedId*/ ctx[9]; + day.$set(day_changes); + }, + i(local) { + if (current) return; + transition_in(day.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(day.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) detach(first); + destroy_component(day, detaching); + } + }; +} + +// (73:6) {#each month as week (week.weekNum)} +function create_each_block(key_1, ctx) { + let tr; + let t0; + let each_blocks = []; + let each_1_lookup = new Map(); + let t1; + let current; + let if_block = /*showWeekNums*/ ctx[1] && create_if_block(ctx); + let each_value_1 = /*week*/ ctx[18].days; + const get_key = ctx => /*day*/ ctx[21].format(); + + for (let i = 0; i < each_value_1.length; i += 1) { + let child_ctx = get_each_context_1(ctx, each_value_1, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block_1(key, child_ctx)); + } + + return { + key: key_1, + first: null, + c() { + tr = element("tr"); + if (if_block) if_block.c(); + t0 = space(); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + t1 = space(); + this.first = tr; + }, + m(target, anchor) { + insert(target, tr, anchor); + if (if_block) if_block.m(tr, null); + append(tr, t0); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(tr, null); + } + + append(tr, t1); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + + if (/*showWeekNums*/ ctx[1]) { + if (if_block) { + if_block.p(ctx, dirty); + + if (dirty & /*showWeekNums*/ 2) { + transition_in(if_block, 1); + } + } else { + if_block = create_if_block(ctx); + if_block.c(); + transition_in(if_block, 1); + if_block.m(tr, t0); + } + } else if (if_block) { + group_outros(); + + transition_out(if_block, 1, 1, () => { + if_block = null; + }); + + check_outros(); + } + + if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId*/ 18261) { + each_value_1 = /*week*/ ctx[18].days; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value_1, each_1_lookup, tr, outro_and_destroy_block, create_each_block_1, t1, get_each_context_1); + check_outros(); + } + }, + i(local) { + if (current) return; + transition_in(if_block); + + for (let i = 0; i < each_value_1.length; i += 1) { + transition_in(each_blocks[i]); + } + + current = true; + }, + o(local) { + transition_out(if_block); + + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + + current = false; + }, + d(detaching) { + if (detaching) detach(tr); + if (if_block) if_block.d(); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} + +function create_fragment$7(ctx) { + let div; + let nav; + let t0; + let table; + let colgroup; + let t1; + let t2; + let thead; + let tr; + let t3; + let t4; + let tbody; + let each_blocks = []; + let each2_lookup = new Map(); + let current; + + nav = new Nav({ + props: { + today: /*today*/ ctx[10], + displayedMonth: /*displayedMonth*/ ctx[0], + incrementDisplayedMonth: /*incrementDisplayedMonth*/ ctx[11], + decrementDisplayedMonth: /*decrementDisplayedMonth*/ ctx[12], + resetDisplayedMonth: /*resetDisplayedMonth*/ ctx[13] + } + }); + + let if_block0 = /*showWeekNums*/ ctx[1] && create_if_block_2(); + let each_value_3 = /*month*/ ctx[14][1].days; + let each_blocks_2 = []; + + for (let i = 0; i < each_value_3.length; i += 1) { + each_blocks_2[i] = create_each_block_3(get_each_context_3(ctx, each_value_3, i)); + } + + let if_block1 = /*showWeekNums*/ ctx[1] && create_if_block_1(); + let each_value_2 = /*daysOfWeek*/ ctx[15]; + let each_blocks_1 = []; + + for (let i = 0; i < each_value_2.length; i += 1) { + each_blocks_1[i] = create_each_block_2(get_each_context_2(ctx, each_value_2, i)); + } + + let each_value = /*month*/ ctx[14]; + const get_key = ctx => /*week*/ ctx[18].weekNum; + + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context(ctx, each_value, i); + let key = get_key(child_ctx); + each2_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + } + + return { + c() { + div = element("div"); + create_component(nav.$$.fragment); + t0 = space(); + table = element("table"); + colgroup = element("colgroup"); + if (if_block0) if_block0.c(); + t1 = space(); + + for (let i = 0; i < each_blocks_2.length; i += 1) { + each_blocks_2[i].c(); + } + + t2 = space(); + thead = element("thead"); + tr = element("tr"); + if (if_block1) if_block1.c(); + t3 = space(); + + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + + t4 = space(); + tbody = element("tbody"); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + attr(table, "class", "calendar svelte-pcimu8"); + attr(div, "id", "calendar-container"); + attr(div, "class", "container svelte-pcimu8"); + toggle_class(div, "is-mobile", /*isMobile*/ ctx[16]); + }, + m(target, anchor) { + insert(target, div, anchor); + mount_component(nav, div, null); + append(div, t0); + append(div, table); + append(table, colgroup); + if (if_block0) if_block0.m(colgroup, null); + append(colgroup, t1); + + for (let i = 0; i < each_blocks_2.length; i += 1) { + each_blocks_2[i].m(colgroup, null); + } + + append(table, t2); + append(table, thead); + append(thead, tr); + if (if_block1) if_block1.m(tr, null); + append(tr, t3); + + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].m(tr, null); + } + + append(table, t4); + append(table, tbody); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(tbody, null); + } + + current = true; + }, + p(ctx, [dirty]) { + const nav_changes = {}; + if (dirty & /*today*/ 1024) nav_changes.today = /*today*/ ctx[10]; + if (dirty & /*displayedMonth*/ 1) nav_changes.displayedMonth = /*displayedMonth*/ ctx[0]; + nav.$set(nav_changes); + + if (/*showWeekNums*/ ctx[1]) { + if (if_block0) ; else { + if_block0 = create_if_block_2(); + if_block0.c(); + if_block0.m(colgroup, t1); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + + if (dirty & /*isWeekend, month*/ 16384) { + each_value_3 = /*month*/ ctx[14][1].days; + let i; + + for (i = 0; i < each_value_3.length; i += 1) { + const child_ctx = get_each_context_3(ctx, each_value_3, i); + + if (each_blocks_2[i]) { + each_blocks_2[i].p(child_ctx, dirty); + } else { + each_blocks_2[i] = create_each_block_3(child_ctx); + each_blocks_2[i].c(); + each_blocks_2[i].m(colgroup, null); + } + } + + for (; i < each_blocks_2.length; i += 1) { + each_blocks_2[i].d(1); + } + + each_blocks_2.length = each_value_3.length; + } + + if (/*showWeekNums*/ ctx[1]) { + if (if_block1) ; else { + if_block1 = create_if_block_1(); + if_block1.c(); + if_block1.m(tr, t3); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + + if (dirty & /*daysOfWeek*/ 32768) { + each_value_2 = /*daysOfWeek*/ ctx[15]; + let i; + + for (i = 0; i < each_value_2.length; i += 1) { + const child_ctx = get_each_context_2(ctx, each_value_2, i); + + if (each_blocks_1[i]) { + each_blocks_1[i].p(child_ctx, dirty); + } else { + each_blocks_1[i] = create_each_block_2(child_ctx); + each_blocks_1[i].c(); + each_blocks_1[i].m(tr, null); + } + } + + for (; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(1); + } + + each_blocks_1.length = each_value_2.length; + } + + if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId, getWeeklyMetadata, onClickWeek, onContextMenuWeek, onHoverWeek, showWeekNums*/ 18431) { + each_value = /*month*/ ctx[14]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each2_lookup, tbody, outro_and_destroy_block, create_each_block, null, get_each_context); + check_outros(); + } + }, + i(local) { + if (current) return; + transition_in(nav.$$.fragment, local); + + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + + current = true; + }, + o(local) { + transition_out(nav.$$.fragment, local); + + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + + current = false; + }, + d(detaching) { + if (detaching) detach(div); + destroy_component(nav); + if (if_block0) if_block0.d(); + destroy_each(each_blocks_2, detaching); + if (if_block1) if_block1.d(); + destroy_each(each_blocks_1, detaching); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} + +function instance$7($$self, $$props, $$invalidate) { + + + let { localeData } = $$props; + let { showWeekNums = false } = $$props; + let { onHoverDay } = $$props; + let { onHoverWeek } = $$props; + let { onContextMenuDay } = $$props; + let { onContextMenuWeek } = $$props; + let { onClickDay } = $$props; + let { onClickWeek } = $$props; + let { sources = [] } = $$props; + let { selectedId } = $$props; + let { today = window.moment() } = $$props; + let { displayedMonth = today } = $$props; + let month; + let daysOfWeek; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let isMobile = window.app.isMobile; + + function incrementDisplayedMonth() { + $$invalidate(0, displayedMonth = displayedMonth.clone().add(1, "month")); + } + + function decrementDisplayedMonth() { + $$invalidate(0, displayedMonth = displayedMonth.clone().subtract(1, "month")); + } + + function resetDisplayedMonth() { + $$invalidate(0, displayedMonth = today.clone()); + } + + $$self.$$set = $$props => { + if ("localeData" in $$props) $$invalidate(17, localeData = $$props.localeData); + if ("showWeekNums" in $$props) $$invalidate(1, showWeekNums = $$props.showWeekNums); + if ("onHoverDay" in $$props) $$invalidate(2, onHoverDay = $$props.onHoverDay); + if ("onHoverWeek" in $$props) $$invalidate(3, onHoverWeek = $$props.onHoverWeek); + if ("onContextMenuDay" in $$props) $$invalidate(4, onContextMenuDay = $$props.onContextMenuDay); + if ("onContextMenuWeek" in $$props) $$invalidate(5, onContextMenuWeek = $$props.onContextMenuWeek); + if ("onClickDay" in $$props) $$invalidate(6, onClickDay = $$props.onClickDay); + if ("onClickWeek" in $$props) $$invalidate(7, onClickWeek = $$props.onClickWeek); + if ("sources" in $$props) $$invalidate(8, sources = $$props.sources); + if ("selectedId" in $$props) $$invalidate(9, selectedId = $$props.selectedId); + if ("today" in $$props) $$invalidate(10, today = $$props.today); + if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth); + }; + + $$self.$$.update = () => { + if ($$self.$$.dirty & /*displayedMonth, localeData*/ 131073) { + $$invalidate(14, month = getMonth(displayedMonth, localeData)); + } + + if ($$self.$$.dirty & /*today, localeData*/ 132096) { + $$invalidate(15, daysOfWeek = getDaysOfWeek(today, localeData)); + } + }; + + return [ + displayedMonth, + showWeekNums, + onHoverDay, + onHoverWeek, + onContextMenuDay, + onContextMenuWeek, + onClickDay, + onClickWeek, + sources, + selectedId, + today, + incrementDisplayedMonth, + decrementDisplayedMonth, + resetDisplayedMonth, + month, + daysOfWeek, + isMobile, + localeData + ]; +} + +class Calendar$1 extends SvelteComponent { + constructor(options) { + super(); + if (!document.getElementById("svelte-pcimu8-style")) add_css(); + + init(this, options, instance$7, create_fragment$7, not_equal, { + localeData: 17, + showWeekNums: 1, + onHoverDay: 2, + onHoverWeek: 3, + onContextMenuDay: 4, + onContextMenuWeek: 5, + onClickDay: 6, + onClickWeek: 7, + sources: 8, + selectedId: 9, + today: 10, + displayedMonth: 0, + incrementDisplayedMonth: 11, + decrementDisplayedMonth: 12, + resetDisplayedMonth: 13 + }); + } + + get incrementDisplayedMonth() { + return this.$$.ctx[11]; + } + + get decrementDisplayedMonth() { + return this.$$.ctx[12]; + } + + get resetDisplayedMonth() { + return this.$$.ctx[13]; + } +} + +const langToMomentLocale = { + en: "en-gb", + zh: "zh-cn", + "zh-TW": "zh-tw", + ru: "ru", + ko: "ko", + it: "it", + id: "id", + ro: "ro", + "pt-BR": "pt-br", + cz: "cs", + da: "da", + de: "de", + es: "es", + fr: "fr", + no: "nn", + pl: "pl", + pt: "pt", + tr: "tr", + hi: "hi", + nl: "nl", + ar: "ar", + ja: "ja", +}; +const weekdays = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", +]; +function overrideGlobalMomentWeekStart(weekStart) { + const { moment } = window; + const currentLocale = moment.locale(); + // Save the initial locale weekspec so that we can restore + // it when toggling between the different options in settings. + if (!window._bundledLocaleWeekSpec) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window._bundledLocaleWeekSpec = moment.localeData()._week; + } + if (weekStart === "locale") { + moment.updateLocale(currentLocale, { + week: window._bundledLocaleWeekSpec, + }); + } + else { + moment.updateLocale(currentLocale, { + week: { + dow: weekdays.indexOf(weekStart) || 0, + }, + }); + } +} +/** + * Sets the locale used by the calendar. This allows the calendar to + * default to the user's locale (e.g. Start Week on Sunday/Monday/Friday) + * + * @param localeOverride locale string (e.g. "en-US") + */ +function configureGlobalMomentLocale(localeOverride = "system-default", weekStart = "locale") { + var _a; + const obsidianLang = localStorage.getItem("language") || "en"; + const systemLang = (_a = navigator.language) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + let momentLocale = langToMomentLocale[obsidianLang]; + if (localeOverride !== "system-default") { + momentLocale = localeOverride; + } + else if (systemLang.startsWith(obsidianLang)) { + // If the system locale is more specific (en-gb vs en), use the system locale. + momentLocale = systemLang; + } + const currentLocale = window.moment.locale(momentLocale); + console.debug(`[Calendar] Trying to switch Moment.js global locale to ${momentLocale}, got ${currentLocale}`); + overrideGlobalMomentWeekStart(weekStart); + return currentLocale; +} + +/* src/ui/Calendar.svelte generated by Svelte v3.35.0 */ + +function create_fragment(ctx) { + let calendarbase; + let updating_displayedMonth; + let current; + + function calendarbase_displayedMonth_binding(value) { + /*calendarbase_displayedMonth_binding*/ ctx[12](value); + } + + let calendarbase_props = { + sources: /*sources*/ ctx[1], + today: /*today*/ ctx[9], + onHoverDay: /*onHoverDay*/ ctx[2], + onHoverWeek: /*onHoverWeek*/ ctx[3], + onContextMenuDay: /*onContextMenuDay*/ ctx[6], + onContextMenuWeek: /*onContextMenuWeek*/ ctx[7], + onClickDay: /*onClickDay*/ ctx[4], + onClickWeek: /*onClickWeek*/ ctx[5], + localeData: /*today*/ ctx[9].localeData(), + selectedId: /*$activeFile*/ ctx[10], + showWeekNums: /*$settings*/ ctx[8].showWeeklyNote + }; + + if (/*displayedMonth*/ ctx[0] !== void 0) { + calendarbase_props.displayedMonth = /*displayedMonth*/ ctx[0]; + } + + calendarbase = new Calendar$1({ props: calendarbase_props }); + binding_callbacks$1.push(() => bind(calendarbase, "displayedMonth", calendarbase_displayedMonth_binding)); + + return { + c() { + create_component$1(calendarbase.$$.fragment); + }, + m(target, anchor) { + mount_component$1(calendarbase, target, anchor); + current = true; + }, + p(ctx, [dirty]) { + const calendarbase_changes = {}; + if (dirty & /*sources*/ 2) calendarbase_changes.sources = /*sources*/ ctx[1]; + if (dirty & /*today*/ 512) calendarbase_changes.today = /*today*/ ctx[9]; + if (dirty & /*onHoverDay*/ 4) calendarbase_changes.onHoverDay = /*onHoverDay*/ ctx[2]; + if (dirty & /*onHoverWeek*/ 8) calendarbase_changes.onHoverWeek = /*onHoverWeek*/ ctx[3]; + if (dirty & /*onContextMenuDay*/ 64) calendarbase_changes.onContextMenuDay = /*onContextMenuDay*/ ctx[6]; + if (dirty & /*onContextMenuWeek*/ 128) calendarbase_changes.onContextMenuWeek = /*onContextMenuWeek*/ ctx[7]; + if (dirty & /*onClickDay*/ 16) calendarbase_changes.onClickDay = /*onClickDay*/ ctx[4]; + if (dirty & /*onClickWeek*/ 32) calendarbase_changes.onClickWeek = /*onClickWeek*/ ctx[5]; + if (dirty & /*today*/ 512) calendarbase_changes.localeData = /*today*/ ctx[9].localeData(); + if (dirty & /*$activeFile*/ 1024) calendarbase_changes.selectedId = /*$activeFile*/ ctx[10]; + if (dirty & /*$settings*/ 256) calendarbase_changes.showWeekNums = /*$settings*/ ctx[8].showWeeklyNote; + + if (!updating_displayedMonth && dirty & /*displayedMonth*/ 1) { + updating_displayedMonth = true; + calendarbase_changes.displayedMonth = /*displayedMonth*/ ctx[0]; + add_flush_callback(() => updating_displayedMonth = false); + } + + calendarbase.$set(calendarbase_changes); + }, + i(local) { + if (current) return; + transition_in$1(calendarbase.$$.fragment, local); + current = true; + }, + o(local) { + transition_out$1(calendarbase.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component$1(calendarbase, detaching); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let $settings; + let $activeFile; + component_subscribe($$self, settings, $$value => $$invalidate(8, $settings = $$value)); + component_subscribe($$self, activeFile, $$value => $$invalidate(10, $activeFile = $$value)); + + + let today; + let { displayedMonth = today } = $$props; + let { sources } = $$props; + let { onHoverDay } = $$props; + let { onHoverWeek } = $$props; + let { onClickDay } = $$props; + let { onClickWeek } = $$props; + let { onContextMenuDay } = $$props; + let { onContextMenuWeek } = $$props; + + function tick() { + $$invalidate(9, today = window.moment()); + } + + function getToday(settings) { + configureGlobalMomentLocale(settings.localeOverride, settings.weekStart); + dailyNotes.reindex(); + weeklyNotes.reindex(); + return window.moment(); + } + + // 1 minute heartbeat to keep `today` reflecting the current day + let heartbeat = setInterval( + () => { + tick(); + const isViewingCurrentMonth = displayedMonth.isSame(today, "day"); + + if (isViewingCurrentMonth) { + // if it's midnight on the last day of the month, this will + // update the display to show the new month. + $$invalidate(0, displayedMonth = today); + } + }, + 1000 * 60 + ); + + onDestroy(() => { + clearInterval(heartbeat); + }); + + function calendarbase_displayedMonth_binding(value) { + displayedMonth = value; + $$invalidate(0, displayedMonth); + } + + $$self.$$set = $$props => { + if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth); + if ("sources" in $$props) $$invalidate(1, sources = $$props.sources); + if ("onHoverDay" in $$props) $$invalidate(2, onHoverDay = $$props.onHoverDay); + if ("onHoverWeek" in $$props) $$invalidate(3, onHoverWeek = $$props.onHoverWeek); + if ("onClickDay" in $$props) $$invalidate(4, onClickDay = $$props.onClickDay); + if ("onClickWeek" in $$props) $$invalidate(5, onClickWeek = $$props.onClickWeek); + if ("onContextMenuDay" in $$props) $$invalidate(6, onContextMenuDay = $$props.onContextMenuDay); + if ("onContextMenuWeek" in $$props) $$invalidate(7, onContextMenuWeek = $$props.onContextMenuWeek); + }; + + $$self.$$.update = () => { + if ($$self.$$.dirty & /*$settings*/ 256) { + $$invalidate(9, today = getToday($settings)); + } + }; + + return [ + displayedMonth, + sources, + onHoverDay, + onHoverWeek, + onClickDay, + onClickWeek, + onContextMenuDay, + onContextMenuWeek, + $settings, + today, + $activeFile, + tick, + calendarbase_displayedMonth_binding + ]; +} + +class Calendar extends SvelteComponent$1 { + constructor(options) { + super(); + + init$1(this, options, instance, create_fragment, not_equal$1, { + displayedMonth: 0, + sources: 1, + onHoverDay: 2, + onHoverWeek: 3, + onClickDay: 4, + onClickWeek: 5, + onContextMenuDay: 6, + onContextMenuWeek: 7, + tick: 11 + }); + } + + get tick() { + return this.$$.ctx[11]; + } +} + +function showFileMenu(app, file, position) { + const fileMenu = new obsidian.Menu(app); + fileMenu.addItem((item) => item + .setTitle("Delete") + .setIcon("trash") + .onClick(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + app.fileManager.promptForFileDeletion(file); + })); + app.workspace.trigger("file-menu", fileMenu, file, "calendar-context-menu", null); + fileMenu.showAtPosition(position); +} + +const getStreakClasses = (file) => { + return classList({ + "has-note": !!file, + }); +}; +const streakSource = { + getDailyMetadata: async (date) => { + const file = getDailyNote_1(date, get_store_value(dailyNotes)); + return { + classes: getStreakClasses(file), + dots: [], + }; + }, + getWeeklyMetadata: async (date) => { + const file = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + return { + classes: getStreakClasses(file), + dots: [], + }; + }, +}; + +function getNoteTags(note) { + var _a; + if (!note) { + return []; + } + const { metadataCache } = window.app; + const frontmatter = (_a = metadataCache.getFileCache(note)) === null || _a === void 0 ? void 0 : _a.frontmatter; + const tags = []; + if (frontmatter) { + const frontmatterTags = obsidian.parseFrontMatterTags(frontmatter) || []; + tags.push(...frontmatterTags); + } + // strip the '#' at the beginning + return tags.map((tag) => tag.substring(1)); +} +function getFormattedTagAttributes(note) { + const attrs = {}; + const tags = getNoteTags(note); + const [emojiTags, nonEmojiTags] = partition(tags, (tag) => /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/.test(tag)); + if (nonEmojiTags) { + attrs["data-tags"] = nonEmojiTags.join(" "); + } + if (emojiTags) { + attrs["data-emoji-tag"] = emojiTags[0]; + } + return attrs; +} +const customTagsSource = { + getDailyMetadata: async (date) => { + const file = getDailyNote_1(date, get_store_value(dailyNotes)); + return { + dataAttributes: getFormattedTagAttributes(file), + dots: [], + }; + }, + getWeeklyMetadata: async (date) => { + const file = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + return { + dataAttributes: getFormattedTagAttributes(file), + dots: [], + }; + }, +}; + +async function getNumberOfRemainingTasks(note) { + if (!note) { + return 0; + } + const { vault } = window.app; + const fileContents = await vault.cachedRead(note); + return (fileContents.match(/(-|\*) \[ \]/g) || []).length; +} +async function getDotsForDailyNote$1(dailyNote) { + if (!dailyNote) { + return []; + } + const numTasks = await getNumberOfRemainingTasks(dailyNote); + const dots = []; + if (numTasks) { + dots.push({ + className: "task", + color: "default", + isFilled: false, + }); + } + return dots; +} +const tasksSource = { + getDailyMetadata: async (date) => { + const file = getDailyNote_1(date, get_store_value(dailyNotes)); + const dots = await getDotsForDailyNote$1(file); + return { + dots, + }; + }, + getWeeklyMetadata: async (date) => { + const file = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + const dots = await getDotsForDailyNote$1(file); + return { + dots, + }; + }, +}; + +const NUM_MAX_DOTS = 5; +async function getWordLengthAsDots(note) { + const { wordsPerDot = DEFAULT_WORDS_PER_DOT } = get_store_value(settings); + if (!note || wordsPerDot <= 0) { + return 0; + } + const fileContents = await window.app.vault.cachedRead(note); + const wordCount = getWordCount(fileContents); + const numDots = wordCount / wordsPerDot; + return clamp(Math.floor(numDots), 1, NUM_MAX_DOTS); +} +async function getDotsForDailyNote(dailyNote) { + if (!dailyNote) { + return []; + } + const numSolidDots = await getWordLengthAsDots(dailyNote); + const dots = []; + for (let i = 0; i < numSolidDots; i++) { + dots.push({ + color: "default", + isFilled: true, + }); + } + return dots; +} +const wordCountSource = { + getDailyMetadata: async (date) => { + const file = getDailyNote_1(date, get_store_value(dailyNotes)); + const dots = await getDotsForDailyNote(file); + return { + dots, + }; + }, + getWeeklyMetadata: async (date) => { + const file = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + const dots = await getDotsForDailyNote(file); + return { + dots, + }; + }, +}; + +class CalendarView extends obsidian.ItemView { + constructor(leaf) { + super(leaf); + this.openOrCreateDailyNote = this.openOrCreateDailyNote.bind(this); + this.openOrCreateWeeklyNote = this.openOrCreateWeeklyNote.bind(this); + this.onNoteSettingsUpdate = this.onNoteSettingsUpdate.bind(this); + this.onFileCreated = this.onFileCreated.bind(this); + this.onFileDeleted = this.onFileDeleted.bind(this); + this.onFileModified = this.onFileModified.bind(this); + this.onFileOpen = this.onFileOpen.bind(this); + this.onHoverDay = this.onHoverDay.bind(this); + this.onHoverWeek = this.onHoverWeek.bind(this); + this.onContextMenuDay = this.onContextMenuDay.bind(this); + this.onContextMenuWeek = this.onContextMenuWeek.bind(this); + this.registerEvent( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.app.workspace.on("periodic-notes:settings-updated", this.onNoteSettingsUpdate)); + this.registerEvent(this.app.vault.on("create", this.onFileCreated)); + this.registerEvent(this.app.vault.on("delete", this.onFileDeleted)); + this.registerEvent(this.app.vault.on("modify", this.onFileModified)); + this.registerEvent(this.app.workspace.on("file-open", this.onFileOpen)); + this.settings = null; + settings.subscribe((val) => { + this.settings = val; + // Refresh the calendar if settings change + if (this.calendar) { + this.calendar.tick(); + } + }); + } + getViewType() { + return VIEW_TYPE_CALENDAR; + } + getDisplayText() { + return "Calendar"; + } + getIcon() { + return "calendar-with-checkmark"; + } + onClose() { + if (this.calendar) { + this.calendar.$destroy(); + } + return Promise.resolve(); + } + async onOpen() { + // Integration point: external plugins can listen for `calendar:open` + // to feed in additional sources. + const sources = [ + customTagsSource, + streakSource, + wordCountSource, + tasksSource, + ]; + this.app.workspace.trigger(TRIGGER_ON_OPEN, sources); + this.calendar = new Calendar({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + target: this.contentEl, + props: { + onClickDay: this.openOrCreateDailyNote, + onClickWeek: this.openOrCreateWeeklyNote, + onHoverDay: this.onHoverDay, + onHoverWeek: this.onHoverWeek, + onContextMenuDay: this.onContextMenuDay, + onContextMenuWeek: this.onContextMenuWeek, + sources, + }, + }); + } + onHoverDay(date, targetEl, isMetaPressed) { + if (!isMetaPressed) { + return; + } + const { format } = getDailyNoteSettings_1(); + const note = getDailyNote_1(date, get_store_value(dailyNotes)); + this.app.workspace.trigger("link-hover", this, targetEl, date.format(format), note === null || note === void 0 ? void 0 : note.path); + } + onHoverWeek(date, targetEl, isMetaPressed) { + if (!isMetaPressed) { + return; + } + const note = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + const { format } = getWeeklyNoteSettings_1(); + this.app.workspace.trigger("link-hover", this, targetEl, date.format(format), note === null || note === void 0 ? void 0 : note.path); + } + onContextMenuDay(date, event) { + const note = getDailyNote_1(date, get_store_value(dailyNotes)); + if (!note) { + // If no file exists for a given day, show nothing. + return; + } + showFileMenu(this.app, note, { + x: event.pageX, + y: event.pageY, + }); + } + onContextMenuWeek(date, event) { + const note = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + if (!note) { + // If no file exists for a given day, show nothing. + return; + } + showFileMenu(this.app, note, { + x: event.pageX, + y: event.pageY, + }); + } + onNoteSettingsUpdate() { + dailyNotes.reindex(); + weeklyNotes.reindex(); + this.updateActiveFile(); + } + async onFileDeleted(file) { + if (getDateFromFile_1(file, "day")) { + dailyNotes.reindex(); + this.updateActiveFile(); + } + if (getDateFromFile_1(file, "week")) { + weeklyNotes.reindex(); + this.updateActiveFile(); + } + } + async onFileModified(file) { + const date = getDateFromFile_1(file, "day") || getDateFromFile_1(file, "week"); + if (date && this.calendar) { + this.calendar.tick(); + } + } + onFileCreated(file) { + if (this.app.workspace.layoutReady && this.calendar) { + if (getDateFromFile_1(file, "day")) { + dailyNotes.reindex(); + this.calendar.tick(); + } + if (getDateFromFile_1(file, "week")) { + weeklyNotes.reindex(); + this.calendar.tick(); + } + } + } + onFileOpen(_file) { + if (this.app.workspace.layoutReady) { + this.updateActiveFile(); + } + } + updateActiveFile() { + const { view } = this.app.workspace.activeLeaf; + let file = null; + if (view instanceof obsidian.FileView) { + file = view.file; + } + activeFile.setFile(file); + if (this.calendar) { + this.calendar.tick(); + } + } + revealActiveNote() { + const { moment } = window; + const { activeLeaf } = this.app.workspace; + if (activeLeaf.view instanceof obsidian.FileView) { + // Check to see if the active note is a daily-note + let date = getDateFromFile_1(activeLeaf.view.file, "day"); + if (date) { + this.calendar.$set({ displayedMonth: date }); + return; + } + // Check to see if the active note is a weekly-note + const { format } = getWeeklyNoteSettings_1(); + date = moment(activeLeaf.view.file.basename, format, true); + if (date.isValid()) { + this.calendar.$set({ displayedMonth: date }); + return; + } + } + } + async openOrCreateWeeklyNote(date, inNewSplit) { + const { workspace } = this.app; + const startOfWeek = date.clone().startOf("week"); + const existingFile = getWeeklyNote_1(date, get_store_value(weeklyNotes)); + if (!existingFile) { + // File doesn't exist + tryToCreateWeeklyNote(startOfWeek, inNewSplit, this.settings, (file) => { + activeFile.setFile(file); + }); + return; + } + const leaf = inNewSplit + ? workspace.splitActiveLeaf() + : workspace.getUnpinnedLeaf(); + await leaf.openFile(existingFile); + activeFile.setFile(existingFile); + } + async openOrCreateDailyNote(date, inNewSplit) { + const { workspace } = this.app; + const existingFile = getDailyNote_1(date, get_store_value(dailyNotes)); + if (!existingFile) { + // File doesn't exist + tryToCreateDailyNote(date, inNewSplit, this.settings, (dailyNote) => { + activeFile.setFile(dailyNote); + }); + return; + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const mode = this.app.vault.getConfig("defaultViewMode"); + const leaf = inNewSplit + ? workspace.splitActiveLeaf() + : workspace.getUnpinnedLeaf(); + await leaf.openFile(existingFile, { mode }); + activeFile.setFile(existingFile); + } +} + +class CalendarPlugin extends obsidian.Plugin { + onunload() { + this.app.workspace + .getLeavesOfType(VIEW_TYPE_CALENDAR) + .forEach((leaf) => leaf.detach()); + } + async onload() { + this.register(settings.subscribe((value) => { + this.options = value; + })); + this.registerView(VIEW_TYPE_CALENDAR, (leaf) => (this.view = new CalendarView(leaf))); + this.addCommand({ + id: "show-calendar-view", + name: "Open view", + checkCallback: (checking) => { + if (checking) { + return (this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length === 0); + } + this.initLeaf(); + }, + }); + this.addCommand({ + id: "open-weekly-note", + name: "Open Weekly Note", + checkCallback: (checking) => { + if (checking) { + return !appHasPeriodicNotesPluginLoaded(); + } + this.view.openOrCreateWeeklyNote(window.moment(), false); + }, + }); + this.addCommand({ + id: "reveal-active-note", + name: "Reveal active note", + callback: () => this.view.revealActiveNote(), + }); + await this.loadOptions(); + this.addSettingTab(new CalendarSettingsTab(this.app, this)); + if (this.app.workspace.layoutReady) { + this.initLeaf(); + } + else { + this.registerEvent(this.app.workspace.on("layout-ready", this.initLeaf.bind(this))); + } + } + initLeaf() { + if (this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length) { + return; + } + this.app.workspace.getRightLeaf(false).setViewState({ + type: VIEW_TYPE_CALENDAR, + }); + } + async loadOptions() { + const options = await this.loadData(); + settings.update((old) => { + return Object.assign(Object.assign({}, old), (options || {})); + }); + await this.saveData(this.options); + } + async writeOptions(changeOpts) { + settings.update((old) => (Object.assign(Object.assign({}, old), changeOpts(old)))); + await this.saveData(this.options); + } +} + +module.exports = CalendarPlugin; + +/* nosourcemap */ \ No newline at end of file diff --git a/.obsidian/plugins/calendar/manifest.json b/.obsidian/plugins/calendar/manifest.json new file mode 100644 index 0000000..028bfa5 --- /dev/null +++ b/.obsidian/plugins/calendar/manifest.json @@ -0,0 +1,10 @@ +{ + "id": "calendar", + "name": "Calendar", + "description": "Calendar view of your daily notes", + "version": "1.5.10", + "author": "Liam Cain", + "authorUrl": "https://github.com/liamcain/", + "isDesktopOnly": false, + "minAppVersion": "0.9.11" +} diff --git a/.obsidian/plugins/nldates-obsidian/data.json b/.obsidian/plugins/nldates-obsidian/data.json new file mode 100644 index 0000000..92bafeb --- /dev/null +++ b/.obsidian/plugins/nldates-obsidian/data.json @@ -0,0 +1,12 @@ +{ + "autosuggestToggleLink": true, + "autocompleteTriggerPhrase": "@", + "isAutosuggestEnabled": true, + "format": "YYYY-MM-DD, ddd", + "timeFormat": "HH:mm", + "separator": " ", + "weekStart": "monday", + "modalToggleTime": false, + "modalToggleLink": false, + "modalMomentFormat": "YYYY-MM-DD HH:mm" +} \ No newline at end of file diff --git a/.obsidian/plugins/nldates-obsidian/main.js b/.obsidian/plugins/nldates-obsidian/main.js new file mode 100644 index 0000000..39b7558 --- /dev/null +++ b/.obsidian/plugins/nldates-obsidian/main.js @@ -0,0 +1,9562 @@ +'use strict'; + +var require$$0$1 = require('obsidian'); + +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + +var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1); + +/****************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +} + +function getAugmentedNamespace(n) { + if (n.__esModule) return n; + var a = Object.defineProperty({}, '__esModule', {value: true}); + Object.keys(n).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(n, k); + Object.defineProperty(a, k, d.get ? d : { + enumerable: true, + get: function () { + return n[k]; + } + }); + }); + return a; +} + +var main = {}; + +Object.defineProperty(main, '__esModule', { value: true }); + +var obsidian = require$$0__default["default"]; + +const DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD"; +const DEFAULT_WEEKLY_NOTE_FORMAT = "gggg-[W]ww"; +const DEFAULT_MONTHLY_NOTE_FORMAT = "YYYY-MM"; +const DEFAULT_QUARTERLY_NOTE_FORMAT = "YYYY-[Q]Q"; +const DEFAULT_YEARLY_NOTE_FORMAT = "YYYY"; + +function shouldUsePeriodicNotesSettings(periodicity) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = window.app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.[periodicity]?.enabled; +} +/** + * Read the user settings for the `daily-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getDailyNoteSettings() { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const { internalPlugins, plugins } = window.app; + if (shouldUsePeriodicNotesSettings("daily")) { + const { format, folder, template } = plugins.getPlugin("periodic-notes")?.settings?.daily || {}; + return { + format: format || DEFAULT_DAILY_NOTE_FORMAT, + folder: folder?.trim() || "", + template: template?.trim() || "", + }; + } + const { folder, format, template } = internalPlugins.getPluginById("daily-notes")?.instance?.options || {}; + return { + format: format || DEFAULT_DAILY_NOTE_FORMAT, + folder: folder?.trim() || "", + template: template?.trim() || "", + }; + } + catch (err) { + console.info("No custom daily note settings found!", err); + } +} +/** + * Read the user settings for the `weekly-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getWeeklyNoteSettings() { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + const calendarSettings = pluginManager.getPlugin("calendar")?.options; + const periodicNotesSettings = pluginManager.getPlugin("periodic-notes")?.settings?.weekly; + if (shouldUsePeriodicNotesSettings("weekly")) { + return { + format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: periodicNotesSettings.folder?.trim() || "", + template: periodicNotesSettings.template?.trim() || "", + }; + } + const settings = calendarSettings || {}; + return { + format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: settings.weeklyNoteFolder?.trim() || "", + template: settings.weeklyNoteTemplate?.trim() || "", + }; + } + catch (err) { + console.info("No custom weekly note settings found!", err); + } +} +/** + * Read the user settings for the `periodic-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getMonthlyNoteSettings() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + try { + const settings = (shouldUsePeriodicNotesSettings("monthly") && + pluginManager.getPlugin("periodic-notes")?.settings?.monthly) || + {}; + return { + format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT, + folder: settings.folder?.trim() || "", + template: settings.template?.trim() || "", + }; + } + catch (err) { + console.info("No custom monthly note settings found!", err); + } +} +/** + * Read the user settings for the `periodic-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getQuarterlyNoteSettings() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + try { + const settings = (shouldUsePeriodicNotesSettings("quarterly") && + pluginManager.getPlugin("periodic-notes")?.settings?.quarterly) || + {}; + return { + format: settings.format || DEFAULT_QUARTERLY_NOTE_FORMAT, + folder: settings.folder?.trim() || "", + template: settings.template?.trim() || "", + }; + } + catch (err) { + console.info("No custom quarterly note settings found!", err); + } +} +/** + * Read the user settings for the `periodic-notes` plugin + * to keep behavior of creating a new note in-sync. + */ +function getYearlyNoteSettings() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pluginManager = window.app.plugins; + try { + const settings = (shouldUsePeriodicNotesSettings("yearly") && + pluginManager.getPlugin("periodic-notes")?.settings?.yearly) || + {}; + return { + format: settings.format || DEFAULT_YEARLY_NOTE_FORMAT, + folder: settings.folder?.trim() || "", + template: settings.template?.trim() || "", + }; + } + catch (err) { + console.info("No custom yearly note settings found!", err); + } +} + +// Credit: @creationix/path.js +function join(...partSegments) { + // Split the inputs into a list of path commands. + let parts = []; + for (let i = 0, l = partSegments.length; i < l; i++) { + parts = parts.concat(partSegments[i].split("/")); + } + // Interpret the path commands to get the new resolved path. + const newParts = []; + for (let i = 0, l = parts.length; i < l; i++) { + const part = parts[i]; + // Remove leading and trailing slashes + // Also remove "." segments + if (!part || part === ".") + continue; + // Push new path segments. + else + newParts.push(part); + } + // Preserve the initial slash if there was one. + if (parts[0] === "") + newParts.unshift(""); + // Turn back into a single string path. + return newParts.join("/"); +} +function basename(fullPath) { + let base = fullPath.substring(fullPath.lastIndexOf("/") + 1); + if (base.lastIndexOf(".") != -1) + base = base.substring(0, base.lastIndexOf(".")); + return base; +} +async function ensureFolderExists(path) { + const dirs = path.replace(/\\/g, "/").split("/"); + dirs.pop(); // remove basename + if (dirs.length) { + const dir = join(...dirs); + if (!window.app.vault.getAbstractFileByPath(dir)) { + await window.app.vault.createFolder(dir); + } + } +} +async function getNotePath(directory, filename) { + if (!filename.endsWith(".md")) { + filename += ".md"; + } + const path = obsidian.normalizePath(join(directory, filename)); + await ensureFolderExists(path); + return path; +} +async function getTemplateInfo(template) { + const { metadataCache, vault } = window.app; + const templatePath = obsidian.normalizePath(template); + if (templatePath === "/") { + return Promise.resolve(["", null]); + } + try { + const templateFile = metadataCache.getFirstLinkpathDest(templatePath, ""); + const contents = await vault.cachedRead(templateFile); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const IFoldInfo = window.app.foldManager.load(templateFile); + return [contents, IFoldInfo]; + } + catch (err) { + console.error(`Failed to read the daily note template '${templatePath}'`, err); + new obsidian.Notice("Failed to read the daily note template"); + return ["", null]; + } +} + +/** + * dateUID is a way of weekly identifying daily/weekly/monthly notes. + * They are prefixed with the granularity to avoid ambiguity. + */ +function getDateUID(date, granularity = "day") { + const ts = date.clone().startOf(granularity).format(); + return `${granularity}-${ts}`; +} +function removeEscapedCharacters(format) { + return format.replace(/\[[^\]]*\]/g, ""); // remove everything within brackets +} +/** + * XXX: When parsing dates that contain both week numbers and months, + * Moment choses to ignore the week numbers. For the week dateUID, we + * want the opposite behavior. Strip the MMM from the format to patch. + */ +function isFormatAmbiguous(format, granularity) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + return (/w{1,2}/i.test(cleanFormat) && + (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat))); + } + return false; +} +function getDateFromFile(file, granularity) { + return getDateFromFilename(file.basename, granularity); +} +function getDateFromPath(path, granularity) { + return getDateFromFilename(basename(path), granularity); +} +function getDateFromFilename(filename, granularity) { + const getSettings = { + day: getDailyNoteSettings, + week: getWeeklyNoteSettings, + month: getMonthlyNoteSettings, + quarter: getQuarterlyNoteSettings, + year: getYearlyNoteSettings, + }; + const format = getSettings[granularity]().format.split("/").pop(); + const noteDate = window.moment(filename, format, true); + if (!noteDate.isValid()) { + return null; + } + if (isFormatAmbiguous(format, granularity)) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + if (/w{1,2}/i.test(cleanFormat)) { + return window.moment(filename, + // If format contains week, remove day & month formatting + format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""), false); + } + } + } + return noteDate; +} + +class DailyNotesFolderMissingError extends Error { +} +/** + * This function mimics the behavior of the daily-notes plugin + * so it will replace {{date}}, {{title}}, and {{time}} with the + * formatted timestamp. + * + * Note: it has an added bonus that it's not 'today' specific. + */ +async function createDailyNote(date) { + const app = window.app; + const { vault } = app; + const moment = window.moment; + const { template, format, folder } = getDailyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*date\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, moment().format("HH:mm")) + .replace(/{{\s*title\s*}}/gi, filename) + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*yesterday\s*}}/gi, date.clone().subtract(1, "day").format(format)) + .replace(/{{\s*tomorrow\s*}}/gi, date.clone().add(1, "d").format(format))); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } +} +function getDailyNote(date, dailyNotes) { + return dailyNotes[getDateUID(date, "day")] ?? null; +} +function getAllDailyNotes() { + /** + * Find all daily notes in the daily note folder + */ + const { vault } = window.app; + const { folder } = getDailyNoteSettings(); + const dailyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!dailyNotesFolder) { + throw new DailyNotesFolderMissingError("Failed to find daily notes folder"); + } + const dailyNotes = {}; + obsidian.Vault.recurseChildren(dailyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "day"); + if (date) { + const dateString = getDateUID(date, "day"); + dailyNotes[dateString] = note; + } + } + }); + return dailyNotes; +} + +class WeeklyNotesFolderMissingError extends Error { +} +function getDaysOfWeek() { + const { moment } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let weekStart = moment.localeData()._week.dow; + const daysOfWeek = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + ]; + while (weekStart) { + daysOfWeek.push(daysOfWeek.shift()); + weekStart--; + } + return daysOfWeek; +} +function getDayOfWeekNumericalValue(dayOfWeekName) { + return getDaysOfWeek().indexOf(dayOfWeekName.toLowerCase()); +} +async function createWeeklyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getWeeklyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*title\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) + .replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi, (_, dayOfWeek, momentFormat) => { + const day = getDayOfWeekNumericalValue(dayOfWeek); + return date.weekday(day).format(momentFormat.trim()); + })); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } +} +function getWeeklyNote(date, weeklyNotes) { + return weeklyNotes[getDateUID(date, "week")] ?? null; +} +function getAllWeeklyNotes() { + const weeklyNotes = {}; + if (!appHasWeeklyNotesPluginLoaded()) { + return weeklyNotes; + } + const { vault } = window.app; + const { folder } = getWeeklyNoteSettings(); + const weeklyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!weeklyNotesFolder) { + throw new WeeklyNotesFolderMissingError("Failed to find weekly notes folder"); + } + obsidian.Vault.recurseChildren(weeklyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "week"); + if (date) { + const dateString = getDateUID(date, "week"); + weeklyNotes[dateString] = note; + } + } + }); + return weeklyNotes; +} + +class MonthlyNotesFolderMissingError extends Error { +} +/** + * This function mimics the behavior of the daily-notes plugin + * so it will replace {{date}}, {{title}}, and {{time}} with the + * formatted timestamp. + * + * Note: it has an added bonus that it's not 'today' specific. + */ +async function createMonthlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getMonthlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*date\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) + .replace(/{{\s*title\s*}}/gi, filename)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } +} +function getMonthlyNote(date, monthlyNotes) { + return monthlyNotes[getDateUID(date, "month")] ?? null; +} +function getAllMonthlyNotes() { + const monthlyNotes = {}; + if (!appHasMonthlyNotesPluginLoaded()) { + return monthlyNotes; + } + const { vault } = window.app; + const { folder } = getMonthlyNoteSettings(); + const monthlyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!monthlyNotesFolder) { + throw new MonthlyNotesFolderMissingError("Failed to find monthly notes folder"); + } + obsidian.Vault.recurseChildren(monthlyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "month"); + if (date) { + const dateString = getDateUID(date, "month"); + monthlyNotes[dateString] = note; + } + } + }); + return monthlyNotes; +} + +class QuarterlyNotesFolderMissingError extends Error { +} +/** + * This function mimics the behavior of the daily-notes plugin + * so it will replace {{date}}, {{title}}, and {{time}} with the + * formatted timestamp. + * + * Note: it has an added bonus that it's not 'today' specific. + */ +async function createQuarterlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getQuarterlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*date\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) + .replace(/{{\s*title\s*}}/gi, filename)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } +} +function getQuarterlyNote(date, quarterly) { + return quarterly[getDateUID(date, "quarter")] ?? null; +} +function getAllQuarterlyNotes() { + const quarterly = {}; + if (!appHasQuarterlyNotesPluginLoaded()) { + return quarterly; + } + const { vault } = window.app; + const { folder } = getQuarterlyNoteSettings(); + const quarterlyFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!quarterlyFolder) { + throw new QuarterlyNotesFolderMissingError("Failed to find quarterly notes folder"); + } + obsidian.Vault.recurseChildren(quarterlyFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "quarter"); + if (date) { + const dateString = getDateUID(date, "quarter"); + quarterly[dateString] = note; + } + } + }); + return quarterly; +} + +class YearlyNotesFolderMissingError extends Error { +} +/** + * This function mimics the behavior of the daily-notes plugin + * so it will replace {{date}}, {{title}}, and {{time}} with the + * formatted timestamp. + * + * Note: it has an added bonus that it's not 'today' specific. + */ +async function createYearlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getYearlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents + .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second"), + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }) + .replace(/{{\s*date\s*}}/gi, filename) + .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) + .replace(/{{\s*title\s*}}/gi, filename)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } + catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } +} +function getYearlyNote(date, yearlyNotes) { + return yearlyNotes[getDateUID(date, "year")] ?? null; +} +function getAllYearlyNotes() { + const yearlyNotes = {}; + if (!appHasYearlyNotesPluginLoaded()) { + return yearlyNotes; + } + const { vault } = window.app; + const { folder } = getYearlyNoteSettings(); + const yearlyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!yearlyNotesFolder) { + throw new YearlyNotesFolderMissingError("Failed to find yearly notes folder"); + } + obsidian.Vault.recurseChildren(yearlyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "year"); + if (date) { + const dateString = getDateUID(date, "year"); + yearlyNotes[dateString] = note; + } + } + }); + return yearlyNotes; +} + +function appHasDailyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"]; + if (dailyNotesPlugin && dailyNotesPlugin.enabled) { + return true; + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.daily?.enabled; +} +/** + * XXX: "Weekly Notes" live in either the Calendar plugin or the periodic-notes plugin. + * Check both until the weekly notes feature is removed from the Calendar plugin. + */ +function appHasWeeklyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (app.plugins.getPlugin("calendar")) { + return true; + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.weekly?.enabled; +} +function appHasMonthlyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.monthly?.enabled; +} +function appHasQuarterlyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.quarterly?.enabled; +} +function appHasYearlyNotesPluginLoaded() { + const { app } = window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && periodicNotes.settings?.yearly?.enabled; +} +function getPeriodicNoteSettings(granularity) { + const getSettings = { + day: getDailyNoteSettings, + week: getWeeklyNoteSettings, + month: getMonthlyNoteSettings, + quarter: getQuarterlyNoteSettings, + year: getYearlyNoteSettings, + }[granularity]; + return getSettings(); +} +function createPeriodicNote(granularity, date) { + const createFn = { + day: createDailyNote, + month: createMonthlyNote, + week: createWeeklyNote, + }; + return createFn[granularity](date); +} + +main.DEFAULT_DAILY_NOTE_FORMAT = DEFAULT_DAILY_NOTE_FORMAT; +main.DEFAULT_MONTHLY_NOTE_FORMAT = DEFAULT_MONTHLY_NOTE_FORMAT; +main.DEFAULT_QUARTERLY_NOTE_FORMAT = DEFAULT_QUARTERLY_NOTE_FORMAT; +main.DEFAULT_WEEKLY_NOTE_FORMAT = DEFAULT_WEEKLY_NOTE_FORMAT; +main.DEFAULT_YEARLY_NOTE_FORMAT = DEFAULT_YEARLY_NOTE_FORMAT; +main.appHasDailyNotesPluginLoaded = appHasDailyNotesPluginLoaded; +main.appHasMonthlyNotesPluginLoaded = appHasMonthlyNotesPluginLoaded; +main.appHasQuarterlyNotesPluginLoaded = appHasQuarterlyNotesPluginLoaded; +main.appHasWeeklyNotesPluginLoaded = appHasWeeklyNotesPluginLoaded; +main.appHasYearlyNotesPluginLoaded = appHasYearlyNotesPluginLoaded; +var createDailyNote_1 = main.createDailyNote = createDailyNote; +main.createMonthlyNote = createMonthlyNote; +main.createPeriodicNote = createPeriodicNote; +main.createQuarterlyNote = createQuarterlyNote; +main.createWeeklyNote = createWeeklyNote; +main.createYearlyNote = createYearlyNote; +var getAllDailyNotes_1 = main.getAllDailyNotes = getAllDailyNotes; +main.getAllMonthlyNotes = getAllMonthlyNotes; +main.getAllQuarterlyNotes = getAllQuarterlyNotes; +main.getAllWeeklyNotes = getAllWeeklyNotes; +main.getAllYearlyNotes = getAllYearlyNotes; +var getDailyNote_1 = main.getDailyNote = getDailyNote; +main.getDailyNoteSettings = getDailyNoteSettings; +main.getDateFromFile = getDateFromFile; +main.getDateFromPath = getDateFromPath; +main.getDateUID = getDateUID; +main.getMonthlyNote = getMonthlyNote; +main.getMonthlyNoteSettings = getMonthlyNoteSettings; +main.getPeriodicNoteSettings = getPeriodicNoteSettings; +main.getQuarterlyNote = getQuarterlyNote; +main.getQuarterlyNoteSettings = getQuarterlyNoteSettings; +main.getTemplateInfo = getTemplateInfo; +main.getWeeklyNote = getWeeklyNote; +main.getWeeklyNoteSettings = getWeeklyNoteSettings; +main.getYearlyNote = getYearlyNote; +main.getYearlyNoteSettings = getYearlyNoteSettings; + +const daysOfWeek = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", +]; +function getWordBoundaries(editor) { + const cursor = editor.getCursor(); + const pos = editor.posToOffset(cursor); + const word = editor.cm.state.wordAt(pos); + const wordStart = editor.offsetToPos(word.from); + const wordEnd = editor.offsetToPos(word.to); + return { + from: wordStart, + to: wordEnd, + }; +} +function getSelectedText(editor) { + if (editor.somethingSelected()) { + return editor.getSelection(); + } + else { + const wordBoundaries = getWordBoundaries(editor); + editor.setSelection(wordBoundaries.from, wordBoundaries.to); // TODO check if this needs to be updated/improved + return editor.getSelection(); + } +} +function adjustCursor(editor, cursor, newStr, oldStr) { + const cursorOffset = newStr.length - oldStr.length; + editor.setCursor({ + line: cursor.line, + ch: cursor.ch + cursorOffset, + }); +} +function getFormattedDate(date, format) { + return window.moment(date).format(format); +} +function getLastDayOfMonth(year, month) { + return new Date(year, month, 0).getDate(); +} +function parseTruthy(flag) { + return ["y", "yes", "1", "t", "true"].indexOf(flag.toLowerCase()) >= 0; +} +function getWeekNumber(dayOfWeek) { + return daysOfWeek.indexOf(dayOfWeek); +} +function getLocaleWeekStart() { + // @ts-ignore + const startOfWeek = window.moment.localeData()._week.dow; + return daysOfWeek[startOfWeek]; +} +function generateMarkdownLink(app, subpath, alias) { + const useMarkdownLinks = app.vault.getConfig("useMarkdownLinks"); + const path = require$$0$1.normalizePath(subpath); + if (useMarkdownLinks) { + if (alias) { + return `[${alias}](${path.replace(/ /g, "%20")})`; + } + else { + return `[${subpath}](${path})`; + } + } + else { + if (alias) { + return `[[${path}|${alias}]]`; + } + else { + return `[[${path}]]`; + } + } +} +function getOrCreateDailyNote(date) { + return __awaiter(this, void 0, void 0, function* () { + // Borrowed from the Slated plugin: + // https://github.com/tgrosinger/slated-obsidian/blob/main/src/vault.ts#L17 + const desiredNote = getDailyNote_1(date, getAllDailyNotes_1()); + if (desiredNote) { + return Promise.resolve(desiredNote); + } + return createDailyNote_1(date); + }); +} +function extractTerms$1(dictionary) { + let keys; + if (dictionary instanceof Array) { + keys = [...dictionary]; + } + else if (dictionary instanceof Map) { + keys = Array.from(dictionary.keys()); + } + else { + keys = Object.keys(dictionary); + } + return keys; +} +function matchAnyPattern$1(dictionary) { + const joinedTerms = extractTerms$1(dictionary) + .sort((a, b) => b.length - a.length) + .join("|") + .replace(/\./g, "\\."); + return `(?:${joinedTerms})`; +} +const ORDINAL_WORD_DICTIONARY = { + first: 1, + second: 2, + third: 3, + fourth: 4, + fifth: 5, + sixth: 6, + seventh: 7, + eighth: 8, + ninth: 9, + tenth: 10, + eleventh: 11, + twelfth: 12, + thirteenth: 13, + fourteenth: 14, + fifteenth: 15, + sixteenth: 16, + seventeenth: 17, + eighteenth: 18, + nineteenth: 19, + twentieth: 20, + "twenty first": 21, + "twenty-first": 21, + "twenty second": 22, + "twenty-second": 22, + "twenty third": 23, + "twenty-third": 23, + "twenty fourth": 24, + "twenty-fourth": 24, + "twenty fifth": 25, + "twenty-fifth": 25, + "twenty sixth": 26, + "twenty-sixth": 26, + "twenty seventh": 27, + "twenty-seventh": 27, + "twenty eighth": 28, + "twenty-eighth": 28, + "twenty ninth": 29, + "twenty-ninth": 29, + thirtieth: 30, + "thirty first": 31, + "thirty-first": 31, +}; +const ORDINAL_NUMBER_PATTERN = `(?:${matchAnyPattern$1(ORDINAL_WORD_DICTIONARY)}|[0-9]{1,2}(?:st|nd|rd|th)?)`; +function parseOrdinalNumberPattern(match) { + let num = match.toLowerCase(); + if (ORDINAL_WORD_DICTIONARY[num] !== undefined) { + return ORDINAL_WORD_DICTIONARY[num]; + } + num = num.replace(/(?:st|nd|rd|th)$/i, ""); + return parseInt(num); +} + +class DatePickerModal extends require$$0$1.Modal { + constructor(app, plugin) { + super(app); + this.plugin = plugin; + } + onOpen() { + let previewEl; + let dateInput = ""; + let momentFormat = this.plugin.settings.modalMomentFormat; + let insertAsLink = this.plugin.settings.modalToggleLink; + const getDateStr = () => { + let cleanDateInput = dateInput; + let shouldIncludeAlias = false; + if (dateInput.endsWith("|")) { + shouldIncludeAlias = true; + cleanDateInput = dateInput.slice(0, -1); + } + const parsedDate = this.plugin.parseDate(cleanDateInput || "today"); + let parsedDateString = parsedDate.moment.isValid() + ? parsedDate.moment.format(momentFormat) + : ""; + if (insertAsLink) { + parsedDateString = generateMarkdownLink(this.app, parsedDateString, shouldIncludeAlias ? cleanDateInput : undefined); + } + return parsedDateString; + }; + this.contentEl.createEl("form", {}, (formEl) => { + const dateInputEl = new require$$0$1.Setting(formEl) + .setName("Date") + .setDesc(getDateStr()) + .addText((textEl) => { + textEl.setPlaceholder("Today"); + textEl.onChange((value) => { + dateInput = value; + previewEl.setText(getDateStr()); + }); + window.setTimeout(() => textEl.inputEl.focus(), 10); + }); + previewEl = dateInputEl.descEl; + new require$$0$1.Setting(formEl) + .setName("Date Format") + .setDesc("Moment format to be used") + .addMomentFormat((momentEl) => { + momentEl.setPlaceholder("YYYY-MM-DD HH:mm"); + momentEl.setValue(momentFormat); + momentEl.onChange((value) => { + momentFormat = value.trim() || "YYYY-MM-DD HH:mm"; + this.plugin.settings.modalMomentFormat = momentFormat; + this.plugin.saveSettings(); + previewEl.setText(getDateStr()); + }); + }); + new require$$0$1.Setting(formEl).setName("Add as link?").addToggle((toggleEl) => { + toggleEl.setValue(this.plugin.settings.modalToggleLink).onChange((value) => { + insertAsLink = value; + this.plugin.settings.modalToggleLink = insertAsLink; + this.plugin.saveSettings(); + previewEl.setText(getDateStr()); + }); + }); + formEl.createDiv("modal-button-container", (buttonContainerEl) => { + buttonContainerEl + .createEl("button", { attr: { type: "button" }, text: "Never mind" }) + .addEventListener("click", () => this.close()); + buttonContainerEl.createEl("button", { + attr: { type: "submit" }, + cls: "mod-cta", + text: "Insert Date", + }); + }); + const activeView = this.app.workspace.getActiveViewOfType(require$$0$1.MarkdownView); + const activeEditor = activeView.editor; + formEl.addEventListener("submit", (e) => { + e.preventDefault(); + this.close(); + activeEditor.replaceSelection(getDateStr()); + }); + }); + } +} + +var dist = {}; + +var en$1 = {}; + +var ENTimeUnitWithinFormatParser$1 = {}; + +var constants$7 = {}; + +var pattern = {}; + +Object.defineProperty(pattern, "__esModule", { value: true }); +pattern.matchAnyPattern = pattern.extractTerms = pattern.repeatedTimeunitPattern = void 0; +function repeatedTimeunitPattern(prefix, singleTimeunitPattern) { + const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:"); + return `${prefix}${singleTimeunitPatternNoCapture}\\s{0,5}(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; +} +pattern.repeatedTimeunitPattern = repeatedTimeunitPattern; +function extractTerms(dictionary) { + let keys; + if (dictionary instanceof Array) { + keys = [...dictionary]; + } + else if (dictionary instanceof Map) { + keys = Array.from(dictionary.keys()); + } + else { + keys = Object.keys(dictionary); + } + return keys; +} +pattern.extractTerms = extractTerms; +function matchAnyPattern(dictionary) { + const joinedTerms = extractTerms(dictionary) + .sort((a, b) => b.length - a.length) + .join("|") + .replace(/\./g, "\\."); + return `(?:${joinedTerms})`; +} +pattern.matchAnyPattern = matchAnyPattern; + +var years = {}; + +var SECONDS_A_MINUTE = 60; +var SECONDS_A_HOUR = SECONDS_A_MINUTE * 60; +var SECONDS_A_DAY = SECONDS_A_HOUR * 24; +var SECONDS_A_WEEK = SECONDS_A_DAY * 7; +var MILLISECONDS_A_SECOND = 1e3; +var MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND; +var MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND; +var MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND; +var MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND; // English locales + +var MS = 'millisecond'; +var S = 'second'; +var MIN = 'minute'; +var H = 'hour'; +var D = 'day'; +var W = 'week'; +var M = 'month'; +var Q = 'quarter'; +var Y = 'year'; +var DATE = 'date'; +var FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'; +var INVALID_DATE_STRING = 'Invalid Date'; // regex + +var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?\.?(\d+)?$/; +var REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g; + +// English [en] +// We don't need weekdaysShort, weekdaysMin, monthsShort in en.js locale +var en = { + name: 'en', + weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), + months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_') +}; + +var padStart = function padStart(string, length, pad) { + var s = String(string); + if (!s || s.length >= length) return string; + return "" + Array(length + 1 - s.length).join(pad) + string; +}; + +var padZoneStr = function padZoneStr(instance) { + var negMinutes = -instance.utcOffset(); + var minutes = Math.abs(negMinutes); + var hourOffset = Math.floor(minutes / 60); + var minuteOffset = minutes % 60; + return "" + (negMinutes <= 0 ? '+' : '-') + padStart(hourOffset, 2, '0') + ":" + padStart(minuteOffset, 2, '0'); +}; + +var monthDiff = function monthDiff(a, b) { + // function from moment.js in order to keep the same result + if (a.date() < b.date()) return -monthDiff(b, a); + var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()); + var anchor = a.clone().add(wholeMonthDiff, M); + var c = b - anchor < 0; + var anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), M); + return +(-(wholeMonthDiff + (b - anchor) / (c ? anchor - anchor2 : anchor2 - anchor)) || 0); +}; + +var absFloor = function absFloor(n) { + return n < 0 ? Math.ceil(n) || 0 : Math.floor(n); +}; + +var prettyUnit = function prettyUnit(u) { + var special = { + M: M, + y: Y, + w: W, + d: D, + D: DATE, + h: H, + m: MIN, + s: S, + ms: MS, + Q: Q + }; + return special[u] || String(u || '').toLowerCase().replace(/s$/, ''); +}; + +var isUndefined = function isUndefined(s) { + return s === undefined; +}; + +var U = { + s: padStart, + z: padZoneStr, + m: monthDiff, + a: absFloor, + p: prettyUnit, + u: isUndefined +}; + +var L = 'en'; // global locale + +var Ls = {}; // global loaded locale + +Ls[L] = en; + +var isDayjs = function isDayjs(d) { + return d instanceof Dayjs; +}; // eslint-disable-line no-use-before-define + + +var parseLocale = function parseLocale(preset, object, isLocal) { + var l; + if (!preset) return L; + + if (typeof preset === 'string') { + if (Ls[preset]) { + l = preset; + } + + if (object) { + Ls[preset] = object; + l = preset; + } + } else { + var name = preset.name; + Ls[name] = preset; + l = name; + } + + if (!isLocal && l) L = l; + return l || !isLocal && L; +}; + +var dayjs$1 = function dayjs(date, c) { + if (isDayjs(date)) { + return date.clone(); + } // eslint-disable-next-line no-nested-ternary + + + var cfg = typeof c === 'object' ? c : {}; + cfg.date = date; + cfg.args = arguments; // eslint-disable-line prefer-rest-params + + return new Dayjs(cfg); // eslint-disable-line no-use-before-define +}; + +var wrapper = function wrapper(date, instance) { + return dayjs$1(date, { + locale: instance.$L, + utc: instance.$u, + x: instance.$x, + $offset: instance.$offset // todo: refactor; do not use this.$offset in you code + + }); +}; + +var Utils = U; // for plugin use + +Utils.l = parseLocale; +Utils.i = isDayjs; +Utils.w = wrapper; + +var parseDate = function parseDate(cfg) { + var date = cfg.date, + utc = cfg.utc; + if (date === null) return new Date(NaN); // null is invalid + + if (Utils.u(date)) return new Date(); // today + + if (date instanceof Date) return new Date(date); + + if (typeof date === 'string' && !/Z$/i.test(date)) { + var d = date.match(REGEX_PARSE); + + if (d) { + var m = d[2] - 1 || 0; + var ms = (d[7] || '0').substring(0, 3); + + if (utc) { + return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)); + } + + return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms); + } + } + + return new Date(date); // everything else +}; + +var Dayjs = /*#__PURE__*/function () { + function Dayjs(cfg) { + this.$L = parseLocale(cfg.locale, null, true); + this.parse(cfg); // for plugin + } + + var _proto = Dayjs.prototype; + + _proto.parse = function parse(cfg) { + this.$d = parseDate(cfg); + this.$x = cfg.x || {}; + this.init(); + }; + + _proto.init = function init() { + var $d = this.$d; + this.$y = $d.getFullYear(); + this.$M = $d.getMonth(); + this.$D = $d.getDate(); + this.$W = $d.getDay(); + this.$H = $d.getHours(); + this.$m = $d.getMinutes(); + this.$s = $d.getSeconds(); + this.$ms = $d.getMilliseconds(); + } // eslint-disable-next-line class-methods-use-this + ; + + _proto.$utils = function $utils() { + return Utils; + }; + + _proto.isValid = function isValid() { + return !(this.$d.toString() === INVALID_DATE_STRING); + }; + + _proto.isSame = function isSame(that, units) { + var other = dayjs$1(that); + return this.startOf(units) <= other && other <= this.endOf(units); + }; + + _proto.isAfter = function isAfter(that, units) { + return dayjs$1(that) < this.startOf(units); + }; + + _proto.isBefore = function isBefore(that, units) { + return this.endOf(units) < dayjs$1(that); + }; + + _proto.$g = function $g(input, get, set) { + if (Utils.u(input)) return this[get]; + return this.set(set, input); + }; + + _proto.unix = function unix() { + return Math.floor(this.valueOf() / 1000); + }; + + _proto.valueOf = function valueOf() { + // timezone(hour) * 60 * 60 * 1000 => ms + return this.$d.getTime(); + }; + + _proto.startOf = function startOf(units, _startOf) { + var _this = this; + + // startOf -> endOf + var isStartOf = !Utils.u(_startOf) ? _startOf : true; + var unit = Utils.p(units); + + var instanceFactory = function instanceFactory(d, m) { + var ins = Utils.w(_this.$u ? Date.UTC(_this.$y, m, d) : new Date(_this.$y, m, d), _this); + return isStartOf ? ins : ins.endOf(D); + }; + + var instanceFactorySet = function instanceFactorySet(method, slice) { + var argumentStart = [0, 0, 0, 0]; + var argumentEnd = [23, 59, 59, 999]; + return Utils.w(_this.toDate()[method].apply( // eslint-disable-line prefer-spread + _this.toDate('s'), (isStartOf ? argumentStart : argumentEnd).slice(slice)), _this); + }; + + var $W = this.$W, + $M = this.$M, + $D = this.$D; + var utcPad = "set" + (this.$u ? 'UTC' : ''); + + switch (unit) { + case Y: + return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11); + + case M: + return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1); + + case W: + { + var weekStart = this.$locale().weekStart || 0; + var gap = ($W < weekStart ? $W + 7 : $W) - weekStart; + return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M); + } + + case D: + case DATE: + return instanceFactorySet(utcPad + "Hours", 0); + + case H: + return instanceFactorySet(utcPad + "Minutes", 1); + + case MIN: + return instanceFactorySet(utcPad + "Seconds", 2); + + case S: + return instanceFactorySet(utcPad + "Milliseconds", 3); + + default: + return this.clone(); + } + }; + + _proto.endOf = function endOf(arg) { + return this.startOf(arg, false); + }; + + _proto.$set = function $set(units, _int) { + var _C$D$C$DATE$C$M$C$Y$C; + + // private set + var unit = Utils.p(units); + var utcPad = "set" + (this.$u ? 'UTC' : ''); + var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[D] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[DATE] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[M] = utcPad + "Month", _C$D$C$DATE$C$M$C$Y$C[Y] = utcPad + "FullYear", _C$D$C$DATE$C$M$C$Y$C[H] = utcPad + "Hours", _C$D$C$DATE$C$M$C$Y$C[MIN] = utcPad + "Minutes", _C$D$C$DATE$C$M$C$Y$C[S] = utcPad + "Seconds", _C$D$C$DATE$C$M$C$Y$C[MS] = utcPad + "Milliseconds", _C$D$C$DATE$C$M$C$Y$C)[unit]; + var arg = unit === D ? this.$D + (_int - this.$W) : _int; + + if (unit === M || unit === Y) { + // clone is for badMutable plugin + var date = this.clone().set(DATE, 1); + date.$d[name](arg); + date.init(); + this.$d = date.set(DATE, Math.min(this.$D, date.daysInMonth())).$d; + } else if (name) this.$d[name](arg); + + this.init(); + return this; + }; + + _proto.set = function set(string, _int2) { + return this.clone().$set(string, _int2); + }; + + _proto.get = function get(unit) { + return this[Utils.p(unit)](); + }; + + _proto.add = function add(number, units) { + var _this2 = this, + _C$MIN$C$H$C$S$unit; + + number = Number(number); // eslint-disable-line no-param-reassign + + var unit = Utils.p(units); + + var instanceFactorySet = function instanceFactorySet(n) { + var d = dayjs$1(_this2); + return Utils.w(d.date(d.date() + Math.round(n * number)), _this2); + }; + + if (unit === M) { + return this.set(M, this.$M + number); + } + + if (unit === Y) { + return this.set(Y, this.$y + number); + } + + if (unit === D) { + return instanceFactorySet(1); + } + + if (unit === W) { + return instanceFactorySet(7); + } + + var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[MIN] = MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[H] = MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[S] = MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1; // ms + + var nextTimeStamp = this.$d.getTime() + number * step; + return Utils.w(nextTimeStamp, this); + }; + + _proto.subtract = function subtract(number, string) { + return this.add(number * -1, string); + }; + + _proto.format = function format(formatStr) { + var _this3 = this; + + if (!this.isValid()) return INVALID_DATE_STRING; + var str = formatStr || FORMAT_DEFAULT; + var zoneStr = Utils.z(this); + var locale = this.$locale(); + var $H = this.$H, + $m = this.$m, + $M = this.$M; + var weekdays = locale.weekdays, + months = locale.months, + meridiem = locale.meridiem; + + var getShort = function getShort(arr, index, full, length) { + return arr && (arr[index] || arr(_this3, str)) || full[index].substr(0, length); + }; + + var get$H = function get$H(num) { + return Utils.s($H % 12 || 12, num, '0'); + }; + + var meridiemFunc = meridiem || function (hour, minute, isLowercase) { + var m = hour < 12 ? 'AM' : 'PM'; + return isLowercase ? m.toLowerCase() : m; + }; + + var matches = { + YY: String(this.$y).slice(-2), + YYYY: this.$y, + M: $M + 1, + MM: Utils.s($M + 1, 2, '0'), + MMM: getShort(locale.monthsShort, $M, months, 3), + MMMM: getShort(months, $M), + D: this.$D, + DD: Utils.s(this.$D, 2, '0'), + d: String(this.$W), + dd: getShort(locale.weekdaysMin, this.$W, weekdays, 2), + ddd: getShort(locale.weekdaysShort, this.$W, weekdays, 3), + dddd: weekdays[this.$W], + H: String($H), + HH: Utils.s($H, 2, '0'), + h: get$H(1), + hh: get$H(2), + a: meridiemFunc($H, $m, true), + A: meridiemFunc($H, $m, false), + m: String($m), + mm: Utils.s($m, 2, '0'), + s: String(this.$s), + ss: Utils.s(this.$s, 2, '0'), + SSS: Utils.s(this.$ms, 3, '0'), + Z: zoneStr // 'ZZ' logic below + + }; + return str.replace(REGEX_FORMAT, function (match, $1) { + return $1 || matches[match] || zoneStr.replace(':', ''); + }); // 'ZZ' + }; + + _proto.utcOffset = function utcOffset() { + // Because a bug at FF24, we're rounding the timezone offset around 15 minutes + // https://github.com/moment/moment/pull/1871 + return -Math.round(this.$d.getTimezoneOffset() / 15) * 15; + }; + + _proto.diff = function diff(input, units, _float) { + var _C$Y$C$M$C$Q$C$W$C$D$; + + var unit = Utils.p(units); + var that = dayjs$1(input); + var zoneDelta = (that.utcOffset() - this.utcOffset()) * MILLISECONDS_A_MINUTE; + var diff = this - that; + var result = Utils.m(this, that); + result = (_C$Y$C$M$C$Q$C$W$C$D$ = {}, _C$Y$C$M$C$Q$C$W$C$D$[Y] = result / 12, _C$Y$C$M$C$Q$C$W$C$D$[M] = result, _C$Y$C$M$C$Q$C$W$C$D$[Q] = result / 3, _C$Y$C$M$C$Q$C$W$C$D$[W] = (diff - zoneDelta) / MILLISECONDS_A_WEEK, _C$Y$C$M$C$Q$C$W$C$D$[D] = (diff - zoneDelta) / MILLISECONDS_A_DAY, _C$Y$C$M$C$Q$C$W$C$D$[H] = diff / MILLISECONDS_A_HOUR, _C$Y$C$M$C$Q$C$W$C$D$[MIN] = diff / MILLISECONDS_A_MINUTE, _C$Y$C$M$C$Q$C$W$C$D$[S] = diff / MILLISECONDS_A_SECOND, _C$Y$C$M$C$Q$C$W$C$D$)[unit] || diff; // milliseconds + + return _float ? result : Utils.a(result); + }; + + _proto.daysInMonth = function daysInMonth() { + return this.endOf(M).$D; + }; + + _proto.$locale = function $locale() { + // get locale object + return Ls[this.$L]; + }; + + _proto.locale = function locale(preset, object) { + if (!preset) return this.$L; + var that = this.clone(); + var nextLocaleName = parseLocale(preset, object, true); + if (nextLocaleName) that.$L = nextLocaleName; + return that; + }; + + _proto.clone = function clone() { + return Utils.w(this.$d, this); + }; + + _proto.toDate = function toDate() { + return new Date(this.valueOf()); + }; + + _proto.toJSON = function toJSON() { + return this.isValid() ? this.toISOString() : null; + }; + + _proto.toISOString = function toISOString() { + // ie 8 return + // new Dayjs(this.valueOf() + this.$d.getTimezoneOffset() * 60000) + // .format('YYYY-MM-DDTHH:mm:ss.SSS[Z]') + return this.$d.toISOString(); + }; + + _proto.toString = function toString() { + return this.$d.toUTCString(); + }; + + return Dayjs; +}(); + +var proto = Dayjs.prototype; +dayjs$1.prototype = proto; +[['$ms', MS], ['$s', S], ['$m', MIN], ['$H', H], ['$W', D], ['$M', M], ['$y', Y], ['$D', DATE]].forEach(function (g) { + proto[g[1]] = function (input) { + return this.$g(input, g[0], g[1]); + }; +}); + +dayjs$1.extend = function (plugin, option) { + if (!plugin.$i) { + // install plugin only once + plugin(option, Dayjs, dayjs$1); + plugin.$i = true; + } + + return dayjs$1; +}; + +dayjs$1.locale = parseLocale; +dayjs$1.isDayjs = isDayjs; + +dayjs$1.unix = function (timestamp) { + return dayjs$1(timestamp * 1e3); +}; + +dayjs$1.en = Ls[L]; +dayjs$1.Ls = Ls; +dayjs$1.p = {}; + +var esm = /*#__PURE__*/Object.freeze({ + __proto__: null, + 'default': dayjs$1 +}); + +var require$$0 = /*@__PURE__*/getAugmentedNamespace(esm); + +var __importDefault$I = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(years, "__esModule", { value: true }); +years.findYearClosestToRef = years.findMostLikelyADYear = void 0; +const dayjs_1$s = __importDefault$I(require$$0); +function findMostLikelyADYear(yearNumber) { + if (yearNumber < 100) { + if (yearNumber > 50) { + yearNumber = yearNumber + 1900; + } + else { + yearNumber = yearNumber + 2000; + } + } + return yearNumber; +} +years.findMostLikelyADYear = findMostLikelyADYear; +function findYearClosestToRef(refDate, day, month) { + const refMoment = (0, dayjs_1$s.default)(refDate); + let dateMoment = refMoment; + dateMoment = dateMoment.month(month - 1); + dateMoment = dateMoment.date(day); + dateMoment = dateMoment.year(refMoment.year()); + const nextYear = dateMoment.add(1, "y"); + const lastYear = dateMoment.add(-1, "y"); + if (Math.abs(nextYear.diff(refMoment)) < Math.abs(dateMoment.diff(refMoment))) { + dateMoment = nextYear; + } + else if (Math.abs(lastYear.diff(refMoment)) < Math.abs(dateMoment.diff(refMoment))) { + dateMoment = lastYear; + } + return dateMoment.year(); +} +years.findYearClosestToRef = findYearClosestToRef; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseTimeUnits = exports.TIME_UNITS_PATTERN = exports.parseYear = exports.YEAR_PATTERN = exports.parseOrdinalNumberPattern = exports.ORDINAL_NUMBER_PATTERN = exports.parseNumberPattern = exports.NUMBER_PATTERN = exports.TIME_UNIT_DICTIONARY = exports.ORDINAL_WORD_DICTIONARY = exports.INTEGER_WORD_DICTIONARY = exports.MONTH_DICTIONARY = exports.FULL_MONTH_NAME_DICTIONARY = exports.WEEKDAY_DICTIONARY = void 0; +const pattern_1 = pattern; +const years_1 = years; +exports.WEEKDAY_DICTIONARY = { + sunday: 0, + sun: 0, + "sun.": 0, + monday: 1, + mon: 1, + "mon.": 1, + tuesday: 2, + tue: 2, + "tue.": 2, + wednesday: 3, + wed: 3, + "wed.": 3, + thursday: 4, + thurs: 4, + "thurs.": 4, + thur: 4, + "thur.": 4, + thu: 4, + "thu.": 4, + friday: 5, + fri: 5, + "fri.": 5, + saturday: 6, + sat: 6, + "sat.": 6, +}; +exports.FULL_MONTH_NAME_DICTIONARY = { + january: 1, + february: 2, + march: 3, + april: 4, + may: 5, + june: 6, + july: 7, + august: 8, + september: 9, + october: 10, + november: 11, + december: 12, +}; +exports.MONTH_DICTIONARY = Object.assign(Object.assign({}, exports.FULL_MONTH_NAME_DICTIONARY), { jan: 1, "jan.": 1, feb: 2, "feb.": 2, mar: 3, "mar.": 3, apr: 4, "apr.": 4, jun: 6, "jun.": 6, jul: 7, "jul.": 7, aug: 8, "aug.": 8, sep: 9, "sep.": 9, sept: 9, "sept.": 9, oct: 10, "oct.": 10, nov: 11, "nov.": 11, dec: 12, "dec.": 12 }); +exports.INTEGER_WORD_DICTIONARY = { + one: 1, + two: 2, + three: 3, + four: 4, + five: 5, + six: 6, + seven: 7, + eight: 8, + nine: 9, + ten: 10, + eleven: 11, + twelve: 12, +}; +exports.ORDINAL_WORD_DICTIONARY = { + first: 1, + second: 2, + third: 3, + fourth: 4, + fifth: 5, + sixth: 6, + seventh: 7, + eighth: 8, + ninth: 9, + tenth: 10, + eleventh: 11, + twelfth: 12, + thirteenth: 13, + fourteenth: 14, + fifteenth: 15, + sixteenth: 16, + seventeenth: 17, + eighteenth: 18, + nineteenth: 19, + twentieth: 20, + "twenty first": 21, + "twenty-first": 21, + "twenty second": 22, + "twenty-second": 22, + "twenty third": 23, + "twenty-third": 23, + "twenty fourth": 24, + "twenty-fourth": 24, + "twenty fifth": 25, + "twenty-fifth": 25, + "twenty sixth": 26, + "twenty-sixth": 26, + "twenty seventh": 27, + "twenty-seventh": 27, + "twenty eighth": 28, + "twenty-eighth": 28, + "twenty ninth": 29, + "twenty-ninth": 29, + "thirtieth": 30, + "thirty first": 31, + "thirty-first": 31, +}; +exports.TIME_UNIT_DICTIONARY = { + sec: "second", + second: "second", + seconds: "second", + min: "minute", + mins: "minute", + minute: "minute", + minutes: "minute", + h: "hour", + hr: "hour", + hrs: "hour", + hour: "hour", + hours: "hour", + day: "d", + days: "d", + week: "week", + weeks: "week", + month: "month", + months: "month", + y: "year", + yr: "year", + year: "year", + years: "year", +}; +exports.NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}an?)?|an?\\b(?:\\s{0,2}few)?|few|several|a?\\s{0,2}couple\\s{0,2}(?:of)?)`; +function parseNumberPattern(match) { + const num = match.toLowerCase(); + if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) { + return exports.INTEGER_WORD_DICTIONARY[num]; + } + else if (num === "a" || num === "an") { + return 1; + } + else if (num.match(/few/)) { + return 3; + } + else if (num.match(/half/)) { + return 0.5; + } + else if (num.match(/couple/)) { + return 2; + } + else if (num.match(/several/)) { + return 7; + } + return parseFloat(num); +} +exports.parseNumberPattern = parseNumberPattern; +exports.ORDINAL_NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.ORDINAL_WORD_DICTIONARY)}|[0-9]{1,2}(?:st|nd|rd|th)?)`; +function parseOrdinalNumberPattern(match) { + let num = match.toLowerCase(); + if (exports.ORDINAL_WORD_DICTIONARY[num] !== undefined) { + return exports.ORDINAL_WORD_DICTIONARY[num]; + } + num = num.replace(/(?:st|nd|rd|th)$/i, ""); + return parseInt(num); +} +exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern; +exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`; +function parseYear(match) { + if (/BE/i.test(match)) { + match = match.replace(/BE/i, ""); + return parseInt(match) - 543; + } + if (/BCE?/i.test(match)) { + match = match.replace(/BCE?/i, ""); + return -parseInt(match); + } + if (/(AD|CE)/i.test(match)) { + match = match.replace(/(AD|CE)/i, ""); + return parseInt(match); + } + const rawYearNumber = parseInt(match); + return (0, years_1.findMostLikelyADYear)(rawYearNumber); +} +exports.parseYear = parseYear; +const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,3}(${(0, pattern_1.matchAnyPattern)(exports.TIME_UNIT_DICTIONARY)})`; +const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); +exports.TIME_UNITS_PATTERN = (0, pattern_1.repeatedTimeunitPattern)(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN); +function parseTimeUnits(timeunitText) { + const fragments = {}; + let remainingText = timeunitText; + let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + while (match) { + collectDateTimeFragment(fragments, match); + remainingText = remainingText.substring(match[0].length).trim(); + match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + } + return fragments; +} +exports.parseTimeUnits = parseTimeUnits; +function collectDateTimeFragment(fragments, match) { + const num = parseNumberPattern(match[1]); + const unit = exports.TIME_UNIT_DICTIONARY[match[2].toLowerCase()]; + fragments[unit] = num; +} +}(constants$7)); + +var results = {}; + +var quarterOfYear = {exports: {}}; + +(function (module, exports) { +!function(t,n){module.exports=n();}(commonjsGlobal,function(){var t="month",n="quarter";return function(r,i){var e=i.prototype;e.quarter=function(t){return this.$utils().u(t)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(t-1))};var u=e.add;e.add=function(r,i){return r=Number(r),this.$utils().p(i)===n?this.add(3*r,t):u.bind(this)(r,i)};var s=e.startOf;e.startOf=function(r,i){var e=this.$utils(),u=!!e.u(i)||i;if(e.p(r)===n){var a=this.quarter()-1;return u?this.month(3*a).startOf(t).startOf("day"):this.month(3*a+2).endOf(t).endOf("day")}return s.bind(this)(r,i)};}}); +}(quarterOfYear)); + +var weekday = {exports: {}}; + +(function (module, exports) { +!function(e,t){module.exports=t();}(commonjsGlobal,function(){return function(e,t){t.prototype.weekday=function(e){var t=this.$locale().weekStart||0,n=this.$W,i=(n 31) { + match.index = match.index + match[DATE_GROUP$7].length; + return null; + } + result.start.assign("month", month); + result.start.assign("day", day); + if (match[YEAR_GROUP$c]) { + const yearNumber = (0, constants_2$7.parseYear)(match[YEAR_GROUP$c]); + result.start.assign("year", yearNumber); + } + else { + const year = (0, years_1$9.findYearClosestToRef)(context.refDate, day, month); + result.start.imply("year", year); + } + if (match[DATE_TO_GROUP$5]) { + const endDate = (0, constants_3$3.parseOrdinalNumberPattern)(match[DATE_TO_GROUP$5]); + result.end = result.start.clone(); + result.end.assign("day", endDate); + } + return result; + } +} +ENMonthNameLittleEndianParser$1.default = ENMonthNameLittleEndianParser; + +var ENMonthNameMiddleEndianParser$1 = {}; + +Object.defineProperty(ENMonthNameMiddleEndianParser$1, "__esModule", { value: true }); +const years_1$8 = years; +const constants_1$A = constants$7; +const constants_2$6 = constants$7; +const constants_3$2 = constants$7; +const pattern_1$g = pattern; +const AbstractParserWithWordBoundary_1$P = AbstractParserWithWordBoundary; +const PATTERN$A = new RegExp(`(${(0, pattern_1$g.matchAnyPattern)(constants_1$A.MONTH_DICTIONARY)})` + + "(?:-|/|\\s*,?\\s*)" + + `(${constants_2$6.ORDINAL_NUMBER_PATTERN})(?!\\s*(?:am|pm))\\s*` + + "(?:" + + "(?:to|\\-)\\s*" + + `(${constants_2$6.ORDINAL_NUMBER_PATTERN})\\s*` + + ")?" + + "(?:" + + "(?:-|/|\\s*,?\\s*)" + + `(${constants_3$2.YEAR_PATTERN})` + + ")?" + + "(?=\\W|$)(?!\\:\\d)", "i"); +const MONTH_NAME_GROUP$8 = 1; +const DATE_GROUP$6 = 2; +const DATE_TO_GROUP$4 = 3; +const YEAR_GROUP$b = 4; +class ENMonthNameMiddleEndianParser extends AbstractParserWithWordBoundary_1$P.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$A; + } + innerExtract(context, match) { + const month = constants_1$A.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$8].toLowerCase()]; + const day = (0, constants_2$6.parseOrdinalNumberPattern)(match[DATE_GROUP$6]); + if (day > 31) { + return null; + } + const components = context.createParsingComponents({ + day: day, + month: month, + }); + if (match[YEAR_GROUP$b]) { + const year = (0, constants_3$2.parseYear)(match[YEAR_GROUP$b]); + components.assign("year", year); + } + else { + const year = (0, years_1$8.findYearClosestToRef)(context.refDate, day, month); + components.imply("year", year); + } + if (!match[DATE_TO_GROUP$4]) { + return components; + } + const endDate = (0, constants_2$6.parseOrdinalNumberPattern)(match[DATE_TO_GROUP$4]); + const result = context.createParsingResult(match.index, match[0]); + result.start = components; + result.end = components.clone(); + result.end.assign("day", endDate); + return result; + } +} +ENMonthNameMiddleEndianParser$1.default = ENMonthNameMiddleEndianParser; + +var ENMonthNameParser$1 = {}; + +Object.defineProperty(ENMonthNameParser$1, "__esModule", { value: true }); +const constants_1$z = constants$7; +const years_1$7 = years; +const pattern_1$f = pattern; +const constants_2$5 = constants$7; +const AbstractParserWithWordBoundary_1$O = AbstractParserWithWordBoundary; +const PATTERN$z = new RegExp(`((?:in)\\s*)?` + + `(${(0, pattern_1$f.matchAnyPattern)(constants_1$z.MONTH_DICTIONARY)})` + + `\\s*` + + `(?:` + + `[,-]?\\s*(${constants_2$5.YEAR_PATTERN})?` + + ")?" + + "(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)", "i"); +const PREFIX_GROUP$4 = 1; +const MONTH_NAME_GROUP$7 = 2; +const YEAR_GROUP$a = 3; +class ENMonthNameParser extends AbstractParserWithWordBoundary_1$O.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$z; + } + innerExtract(context, match) { + const monthName = match[MONTH_NAME_GROUP$7].toLowerCase(); + if (match[0].length <= 3 && !constants_1$z.FULL_MONTH_NAME_DICTIONARY[monthName]) { + return null; + } + const result = context.createParsingResult(match.index + (match[PREFIX_GROUP$4] || "").length, match.index + match[0].length); + result.start.imply("day", 1); + const month = constants_1$z.MONTH_DICTIONARY[monthName]; + result.start.assign("month", month); + if (match[YEAR_GROUP$a]) { + const year = (0, constants_2$5.parseYear)(match[YEAR_GROUP$a]); + result.start.assign("year", year); + } + else { + const year = (0, years_1$7.findYearClosestToRef)(context.refDate, 1, month); + result.start.imply("year", year); + } + return result; + } +} +ENMonthNameParser$1.default = ENMonthNameParser; + +var ENCasualYearMonthDayParser$1 = {}; + +Object.defineProperty(ENCasualYearMonthDayParser$1, "__esModule", { value: true }); +const constants_1$y = constants$7; +const pattern_1$e = pattern; +const AbstractParserWithWordBoundary_1$N = AbstractParserWithWordBoundary; +const PATTERN$y = new RegExp(`([0-9]{4})[\\.\\/\\s]` + + `(?:(${(0, pattern_1$e.matchAnyPattern)(constants_1$y.MONTH_DICTIONARY)})|([0-9]{1,2}))[\\.\\/\\s]` + + `([0-9]{1,2})` + + "(?=\\W|$)", "i"); +const YEAR_NUMBER_GROUP$3 = 1; +const MONTH_NAME_GROUP$6 = 2; +const MONTH_NUMBER_GROUP$2 = 3; +const DATE_NUMBER_GROUP$2 = 4; +class ENCasualYearMonthDayParser extends AbstractParserWithWordBoundary_1$N.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$y; + } + innerExtract(context, match) { + const month = match[MONTH_NUMBER_GROUP$2] + ? parseInt(match[MONTH_NUMBER_GROUP$2]) + : constants_1$y.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$6].toLowerCase()]; + if (month < 1 || month > 12) { + return null; + } + const year = parseInt(match[YEAR_NUMBER_GROUP$3]); + const day = parseInt(match[DATE_NUMBER_GROUP$2]); + return { + day: day, + month: month, + year: year, + }; + } +} +ENCasualYearMonthDayParser$1.default = ENCasualYearMonthDayParser; + +var ENSlashMonthFormatParser$1 = {}; + +Object.defineProperty(ENSlashMonthFormatParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$M = AbstractParserWithWordBoundary; +const PATTERN$x = new RegExp("([0-9]|0[1-9]|1[012])/([0-9]{4})" + "", "i"); +const MONTH_GROUP$4 = 1; +const YEAR_GROUP$9 = 2; +class ENSlashMonthFormatParser extends AbstractParserWithWordBoundary_1$M.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$x; + } + innerExtract(context, match) { + const year = parseInt(match[YEAR_GROUP$9]); + const month = parseInt(match[MONTH_GROUP$4]); + return context.createParsingComponents().imply("day", 1).assign("month", month).assign("year", year); + } +} +ENSlashMonthFormatParser$1.default = ENSlashMonthFormatParser; + +var ENTimeExpressionParser$1 = {}; + +var AbstractTimeExpressionParser$1 = {}; + +Object.defineProperty(AbstractTimeExpressionParser$1, "__esModule", { value: true }); +AbstractTimeExpressionParser$1.AbstractTimeExpressionParser = void 0; +const index_1$d = dist; +function primaryTimePattern(primaryPrefix, primarySuffix) { + return new RegExp("(^|\\s|T|\\b)" + + `${primaryPrefix}` + + "(\\d{1,4})" + + "(?:" + + "(?:\\.|\\:|\\:)" + + "(\\d{1,2})" + + "(?:" + + "(?:\\:|\\:)" + + "(\\d{2})" + + "(?:\\.(\\d{1,6}))?" + + ")?" + + ")?" + + "(?:\\s*(a\\.m\\.|p\\.m\\.|am?|pm?))?" + + `${primarySuffix}`, "i"); +} +function followingTimePatten(followingPhase, followingSuffix) { + return new RegExp(`^(${followingPhase})` + + "(\\d{1,4})" + + "(?:" + + "(?:\\.|\\:|\\:)" + + "(\\d{1,2})" + + "(?:" + + "(?:\\.|\\:|\\:)" + + "(\\d{1,2})(?:\\.(\\d{1,6}))?" + + ")?" + + ")?" + + "(?:\\s*(a\\.m\\.|p\\.m\\.|am?|pm?))?" + + `${followingSuffix}`, "i"); +} +const HOUR_GROUP$3 = 2; +const MINUTE_GROUP$3 = 3; +const SECOND_GROUP$3 = 4; +const MILLI_SECOND_GROUP = 5; +const AM_PM_HOUR_GROUP$3 = 6; +class AbstractTimeExpressionParser { + constructor(strictMode = false) { + this.cachedPrimaryPrefix = null; + this.cachedPrimarySuffix = null; + this.cachedPrimaryTimePattern = null; + this.cachedFollowingPhase = null; + this.cachedFollowingSuffix = null; + this.cachedFollowingTimePatten = null; + this.strictMode = strictMode; + } + primarySuffix() { + return "(?=\\W|$)"; + } + followingSuffix() { + return "(?=\\W|$)"; + } + pattern(context) { + return this.getPrimaryTimePatternThroughCache(); + } + extract(context, match) { + const startComponents = this.extractPrimaryTimeComponents(context, match); + if (!startComponents) { + match.index += match[0].length; + return null; + } + const index = match.index + match[1].length; + const text = match[0].substring(match[1].length); + const result = context.createParsingResult(index, text, startComponents); + match.index += match[0].length; + const remainingText = context.text.substring(match.index); + const followingPattern = this.getFollowingTimePatternThroughCache(); + const followingMatch = followingPattern.exec(remainingText); + if (!followingMatch || + followingMatch[0].match(/^\s*([+-])\s*\d{3,4}$/)) { + return this.checkAndReturnWithoutFollowingPattern(result); + } + result.end = this.extractFollowingTimeComponents(context, followingMatch, result); + if (result.end) { + result.text += followingMatch[0]; + } + return this.checkAndReturnWithFollowingPattern(result); + } + extractPrimaryTimeComponents(context, match, strict = false) { + const components = context.createParsingComponents(); + let minute = 0; + let meridiem = null; + let hour = parseInt(match[HOUR_GROUP$3]); + if (hour > 100) { + if (this.strictMode || match[MINUTE_GROUP$3] != null) { + return null; + } + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (hour > 24) { + return null; + } + if (match[MINUTE_GROUP$3] != null) { + if (match[MINUTE_GROUP$3].length == 1 && !match[AM_PM_HOUR_GROUP$3]) { + return null; + } + minute = parseInt(match[MINUTE_GROUP$3]); + } + if (minute >= 60) { + return null; + } + if (hour > 12) { + meridiem = index_1$d.Meridiem.PM; + } + if (match[AM_PM_HOUR_GROUP$3] != null) { + if (hour > 12) + return null; + const ampm = match[AM_PM_HOUR_GROUP$3][0].toLowerCase(); + if (ampm == "a") { + meridiem = index_1$d.Meridiem.AM; + if (hour == 12) { + hour = 0; + } + } + if (ampm == "p") { + meridiem = index_1$d.Meridiem.PM; + if (hour != 12) { + hour += 12; + } + } + } + components.assign("hour", hour); + components.assign("minute", minute); + if (meridiem !== null) { + components.assign("meridiem", meridiem); + } + else { + if (hour < 12) { + components.imply("meridiem", index_1$d.Meridiem.AM); + } + else { + components.imply("meridiem", index_1$d.Meridiem.PM); + } + } + if (match[MILLI_SECOND_GROUP] != null) { + const millisecond = parseInt(match[MILLI_SECOND_GROUP].substring(0, 3)); + if (millisecond >= 1000) + return null; + components.assign("millisecond", millisecond); + } + if (match[SECOND_GROUP$3] != null) { + const second = parseInt(match[SECOND_GROUP$3]); + if (second >= 60) + return null; + components.assign("second", second); + } + return components; + } + extractFollowingTimeComponents(context, match, result) { + const components = context.createParsingComponents(); + if (match[MILLI_SECOND_GROUP] != null) { + const millisecond = parseInt(match[MILLI_SECOND_GROUP].substring(0, 3)); + if (millisecond >= 1000) + return null; + components.assign("millisecond", millisecond); + } + if (match[SECOND_GROUP$3] != null) { + const second = parseInt(match[SECOND_GROUP$3]); + if (second >= 60) + return null; + components.assign("second", second); + } + let hour = parseInt(match[HOUR_GROUP$3]); + let minute = 0; + let meridiem = -1; + if (match[MINUTE_GROUP$3] != null) { + minute = parseInt(match[MINUTE_GROUP$3]); + } + else if (hour > 100) { + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (minute >= 60 || hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = index_1$d.Meridiem.PM; + } + if (match[AM_PM_HOUR_GROUP$3] != null) { + if (hour > 12) { + return null; + } + const ampm = match[AM_PM_HOUR_GROUP$3][0].toLowerCase(); + if (ampm == "a") { + meridiem = index_1$d.Meridiem.AM; + if (hour == 12) { + hour = 0; + if (!components.isCertain("day")) { + components.imply("day", components.get("day") + 1); + } + } + } + if (ampm == "p") { + meridiem = index_1$d.Meridiem.PM; + if (hour != 12) + hour += 12; + } + if (!result.start.isCertain("meridiem")) { + if (meridiem == index_1$d.Meridiem.AM) { + result.start.imply("meridiem", index_1$d.Meridiem.AM); + if (result.start.get("hour") == 12) { + result.start.assign("hour", 0); + } + } + else { + result.start.imply("meridiem", index_1$d.Meridiem.PM); + if (result.start.get("hour") != 12) { + result.start.assign("hour", result.start.get("hour") + 12); + } + } + } + } + components.assign("hour", hour); + components.assign("minute", minute); + if (meridiem >= 0) { + components.assign("meridiem", meridiem); + } + else { + const startAtPM = result.start.isCertain("meridiem") && result.start.get("hour") > 12; + if (startAtPM) { + if (result.start.get("hour") - 12 > hour) { + components.imply("meridiem", index_1$d.Meridiem.AM); + } + else if (hour <= 12) { + components.assign("hour", hour + 12); + components.assign("meridiem", index_1$d.Meridiem.PM); + } + } + else if (hour > 12) { + components.imply("meridiem", index_1$d.Meridiem.PM); + } + else if (hour <= 12) { + components.imply("meridiem", index_1$d.Meridiem.AM); + } + } + if (components.date().getTime() < result.start.date().getTime()) { + components.imply("day", components.get("day") + 1); + } + return components; + } + checkAndReturnWithoutFollowingPattern(result) { + if (result.text.match(/^\d$/)) { + return null; + } + if (result.text.match(/\d[apAP]$/)) { + return null; + } + const endingWithNumbers = result.text.match(/[^\d:.](\d[\d.]+)$/); + if (endingWithNumbers) { + const endingNumbers = endingWithNumbers[1]; + if (this.strictMode) { + return null; + } + if (endingNumbers.includes(".") && !endingNumbers.match(/\d(\.\d{2})+$/)) { + return null; + } + const endingNumberVal = parseInt(endingNumbers); + if (endingNumberVal > 24) { + return null; + } + } + return result; + } + checkAndReturnWithFollowingPattern(result) { + if (result.text.match(/^\d+-\d+$/)) { + return null; + } + const endingWithNumbers = result.text.match(/[^\d:.](\d[\d.]+)\s*-\s*(\d[\d.]+)$/); + if (endingWithNumbers) { + if (this.strictMode) { + return null; + } + const startingNumbers = endingWithNumbers[1]; + const endingNumbers = endingWithNumbers[2]; + if (endingNumbers.includes(".") && !endingNumbers.match(/\d(\.\d{2})+$/)) { + return null; + } + const endingNumberVal = parseInt(endingNumbers); + const startingNumberVal = parseInt(startingNumbers); + if (endingNumberVal > 24 || startingNumberVal > 24) { + return null; + } + } + return result; + } + getPrimaryTimePatternThroughCache() { + const primaryPrefix = this.primaryPrefix(); + const primarySuffix = this.primarySuffix(); + if (this.cachedPrimaryPrefix === primaryPrefix && this.cachedPrimarySuffix === primarySuffix) { + return this.cachedPrimaryTimePattern; + } + this.cachedPrimaryTimePattern = primaryTimePattern(primaryPrefix, primarySuffix); + this.cachedPrimaryPrefix = primaryPrefix; + this.cachedPrimarySuffix = primarySuffix; + return this.cachedPrimaryTimePattern; + } + getFollowingTimePatternThroughCache() { + const followingPhase = this.followingPhase(); + const followingSuffix = this.followingSuffix(); + if (this.cachedFollowingPhase === followingPhase && this.cachedFollowingSuffix === followingSuffix) { + return this.cachedFollowingTimePatten; + } + this.cachedFollowingTimePatten = followingTimePatten(followingPhase, followingSuffix); + this.cachedFollowingPhase = followingPhase; + this.cachedFollowingSuffix = followingSuffix; + return this.cachedFollowingTimePatten; + } +} +AbstractTimeExpressionParser$1.AbstractTimeExpressionParser = AbstractTimeExpressionParser; + +Object.defineProperty(ENTimeExpressionParser$1, "__esModule", { value: true }); +const index_1$c = dist; +const AbstractTimeExpressionParser_1$4 = AbstractTimeExpressionParser$1; +class ENTimeExpressionParser extends AbstractTimeExpressionParser_1$4.AbstractTimeExpressionParser { + constructor(strictMode) { + super(strictMode); + } + followingPhase() { + return "\\s*(?:\\-|\\–|\\~|\\〜|to|\\?)\\s*"; + } + primaryPrefix() { + return "(?:(?:at|from)\\s*)??"; + } + primarySuffix() { + return "(?:\\s*(?:o\\W*clock|at\\s*night|in\\s*the\\s*(?:morning|afternoon)))?(?!/)(?=\\W|$)"; + } + extractPrimaryTimeComponents(context, match) { + const components = super.extractPrimaryTimeComponents(context, match); + if (components) { + if (match[0].endsWith("night")) { + const hour = components.get("hour"); + if (hour >= 6 && hour < 12) { + components.assign("hour", components.get("hour") + 12); + components.assign("meridiem", index_1$c.Meridiem.PM); + } + else if (hour < 6) { + components.assign("meridiem", index_1$c.Meridiem.AM); + } + } + if (match[0].endsWith("afternoon")) { + components.assign("meridiem", index_1$c.Meridiem.PM); + const hour = components.get("hour"); + if (hour >= 0 && hour <= 6) { + components.assign("hour", components.get("hour") + 12); + } + } + if (match[0].endsWith("morning")) { + components.assign("meridiem", index_1$c.Meridiem.AM); + const hour = components.get("hour"); + if (hour < 12) { + components.assign("hour", components.get("hour")); + } + } + } + return components; + } +} +ENTimeExpressionParser$1.default = ENTimeExpressionParser; + +var ENTimeUnitAgoFormatParser$1 = {}; + +var timeunits = {}; + +Object.defineProperty(timeunits, "__esModule", { value: true }); +timeunits.addImpliedTimeUnits = timeunits.reverseTimeUnits = void 0; +function reverseTimeUnits(timeUnits) { + const reversed = {}; + for (const key in timeUnits) { + reversed[key] = -timeUnits[key]; + } + return reversed; +} +timeunits.reverseTimeUnits = reverseTimeUnits; +function addImpliedTimeUnits(components, timeUnits) { + const output = components.clone(); + let date = components.dayjs(); + for (const key in timeUnits) { + date = date.add(timeUnits[key], key); + } + if ("day" in timeUnits || "d" in timeUnits || "week" in timeUnits || "month" in timeUnits || "year" in timeUnits) { + output.imply("day", date.date()); + output.imply("month", date.month() + 1); + output.imply("year", date.year()); + } + if ("second" in timeUnits || "minute" in timeUnits || "hour" in timeUnits) { + output.imply("second", date.second()); + output.imply("minute", date.minute()); + output.imply("hour", date.hour()); + } + return output; +} +timeunits.addImpliedTimeUnits = addImpliedTimeUnits; + +Object.defineProperty(ENTimeUnitAgoFormatParser$1, "__esModule", { value: true }); +const constants_1$x = constants$7; +const results_1$d = results; +const AbstractParserWithWordBoundary_1$L = AbstractParserWithWordBoundary; +const timeunits_1$6 = timeunits; +const PATTERN$w = new RegExp(`(${constants_1$x.TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i"); +const STRICT_PATTERN$3 = new RegExp(`(${constants_1$x.TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i"); +class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1$L.AbstractParserWithWordBoundaryChecking { + constructor(strictMode) { + super(); + this.strictMode = strictMode; + } + innerPattern() { + return this.strictMode ? STRICT_PATTERN$3 : PATTERN$w; + } + innerExtract(context, match) { + const timeUnits = (0, constants_1$x.parseTimeUnits)(match[1]); + const outputTimeUnits = (0, timeunits_1$6.reverseTimeUnits)(timeUnits); + return results_1$d.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits); + } +} +ENTimeUnitAgoFormatParser$1.default = ENTimeUnitAgoFormatParser; + +var ENTimeUnitLaterFormatParser$1 = {}; + +Object.defineProperty(ENTimeUnitLaterFormatParser$1, "__esModule", { value: true }); +const constants_1$w = constants$7; +const results_1$c = results; +const AbstractParserWithWordBoundary_1$K = AbstractParserWithWordBoundary; +const PATTERN$v = new RegExp(`(${constants_1$w.TIME_UNITS_PATTERN})\\s{0,5}(?:later|after|from now|henceforth|forward|out)` + "(?=(?:\\W|$))", "i"); +const STRICT_PATTERN$2 = new RegExp("" + "(" + constants_1$w.TIME_UNITS_PATTERN + ")" + "(later|from now)" + "(?=(?:\\W|$))", "i"); +const GROUP_NUM_TIMEUNITS$1 = 1; +class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1$K.AbstractParserWithWordBoundaryChecking { + constructor(strictMode) { + super(); + this.strictMode = strictMode; + } + innerPattern() { + return this.strictMode ? STRICT_PATTERN$2 : PATTERN$v; + } + innerExtract(context, match) { + const fragments = (0, constants_1$w.parseTimeUnits)(match[GROUP_NUM_TIMEUNITS$1]); + return results_1$c.ParsingComponents.createRelativeFromReference(context.reference, fragments); + } +} +ENTimeUnitLaterFormatParser$1.default = ENTimeUnitLaterFormatParser; + +var ENMergeDateRangeRefiner$1 = {}; + +var AbstractMergeDateRangeRefiner$1 = {}; + +var abstractRefiners = {}; + +Object.defineProperty(abstractRefiners, "__esModule", { value: true }); +abstractRefiners.MergingRefiner = abstractRefiners.Filter = void 0; +class Filter { + refine(context, results) { + return results.filter((r) => this.isValid(context, r)); + } +} +abstractRefiners.Filter = Filter; +class MergingRefiner { + refine(context, results) { + if (results.length < 2) { + return results; + } + const mergedResults = []; + let curResult = results[0]; + let nextResult = null; + for (let i = 1; i < results.length; i++) { + nextResult = results[i]; + const textBetween = context.text.substring(curResult.index + curResult.text.length, nextResult.index); + if (!this.shouldMergeResults(textBetween, curResult, nextResult, context)) { + mergedResults.push(curResult); + curResult = nextResult; + } + else { + const left = curResult; + const right = nextResult; + const mergedResult = this.mergeResults(textBetween, left, right, context); + context.debug(() => { + console.log(`${this.constructor.name} merged ${left} and ${right} into ${mergedResult}`); + }); + curResult = mergedResult; + } + } + if (curResult != null) { + mergedResults.push(curResult); + } + return mergedResults; + } +} +abstractRefiners.MergingRefiner = MergingRefiner; + +Object.defineProperty(AbstractMergeDateRangeRefiner$1, "__esModule", { value: true }); +const abstractRefiners_1$3 = abstractRefiners; +class AbstractMergeDateRangeRefiner extends abstractRefiners_1$3.MergingRefiner { + shouldMergeResults(textBetween, currentResult, nextResult) { + return !currentResult.end && !nextResult.end && textBetween.match(this.patternBetween()) != null; + } + mergeResults(textBetween, fromResult, toResult) { + if (!fromResult.start.isOnlyWeekdayComponent() && !toResult.start.isOnlyWeekdayComponent()) { + toResult.start.getCertainComponents().forEach((key) => { + if (!fromResult.start.isCertain(key)) { + fromResult.start.assign(key, toResult.start.get(key)); + } + }); + fromResult.start.getCertainComponents().forEach((key) => { + if (!toResult.start.isCertain(key)) { + toResult.start.assign(key, fromResult.start.get(key)); + } + }); + } + if (fromResult.start.date().getTime() > toResult.start.date().getTime()) { + let fromMoment = fromResult.start.dayjs(); + let toMoment = toResult.start.dayjs(); + if (fromResult.start.isOnlyWeekdayComponent() && fromMoment.add(-7, "days").isBefore(toMoment)) { + fromMoment = fromMoment.add(-7, "days"); + fromResult.start.imply("day", fromMoment.date()); + fromResult.start.imply("month", fromMoment.month() + 1); + fromResult.start.imply("year", fromMoment.year()); + } + else if (toResult.start.isOnlyWeekdayComponent() && toMoment.add(7, "days").isAfter(fromMoment)) { + toMoment = toMoment.add(7, "days"); + toResult.start.imply("day", toMoment.date()); + toResult.start.imply("month", toMoment.month() + 1); + toResult.start.imply("year", toMoment.year()); + } + else { + [toResult, fromResult] = [fromResult, toResult]; + } + } + const result = fromResult.clone(); + result.start = fromResult.start; + result.end = toResult.start; + result.index = Math.min(fromResult.index, toResult.index); + if (fromResult.index < toResult.index) { + result.text = fromResult.text + textBetween + toResult.text; + } + else { + result.text = toResult.text + textBetween + fromResult.text; + } + return result; + } +} +AbstractMergeDateRangeRefiner$1.default = AbstractMergeDateRangeRefiner; + +var __importDefault$G = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ENMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$7 = __importDefault$G(AbstractMergeDateRangeRefiner$1); +class ENMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$7.default { + patternBetween() { + return /^\s*(to|-)\s*$/i; + } +} +ENMergeDateRangeRefiner$1.default = ENMergeDateRangeRefiner; + +var ENMergeDateTimeRefiner$2 = {}; + +var AbstractMergeDateTimeRefiner = {}; + +var mergingCalculation = {}; + +Object.defineProperty(mergingCalculation, "__esModule", { value: true }); +mergingCalculation.mergeDateTimeComponent = mergingCalculation.mergeDateTimeResult = void 0; +const index_1$b = dist; +function mergeDateTimeResult(dateResult, timeResult) { + const result = dateResult.clone(); + const beginDate = dateResult.start; + const beginTime = timeResult.start; + result.start = mergeDateTimeComponent(beginDate, beginTime); + if (dateResult.end != null || timeResult.end != null) { + const endDate = dateResult.end == null ? dateResult.start : dateResult.end; + const endTime = timeResult.end == null ? timeResult.start : timeResult.end; + const endDateTime = mergeDateTimeComponent(endDate, endTime); + if (dateResult.end == null && endDateTime.date().getTime() < result.start.date().getTime()) { + if (endDateTime.isCertain("day")) { + endDateTime.assign("day", endDateTime.get("day") + 1); + } + else { + endDateTime.imply("day", endDateTime.get("day") + 1); + } + } + result.end = endDateTime; + } + return result; +} +mergingCalculation.mergeDateTimeResult = mergeDateTimeResult; +function mergeDateTimeComponent(dateComponent, timeComponent) { + const dateTimeComponent = dateComponent.clone(); + if (timeComponent.isCertain("hour")) { + dateTimeComponent.assign("hour", timeComponent.get("hour")); + dateTimeComponent.assign("minute", timeComponent.get("minute")); + if (timeComponent.isCertain("second")) { + dateTimeComponent.assign("second", timeComponent.get("second")); + if (timeComponent.isCertain("millisecond")) { + dateTimeComponent.assign("millisecond", timeComponent.get("millisecond")); + } + else { + dateTimeComponent.imply("millisecond", timeComponent.get("millisecond")); + } + } + else { + dateTimeComponent.imply("second", timeComponent.get("second")); + dateTimeComponent.imply("millisecond", timeComponent.get("millisecond")); + } + } + else { + dateTimeComponent.imply("hour", timeComponent.get("hour")); + dateTimeComponent.imply("minute", timeComponent.get("minute")); + dateTimeComponent.imply("second", timeComponent.get("second")); + dateTimeComponent.imply("millisecond", timeComponent.get("millisecond")); + } + if (timeComponent.isCertain("timezoneOffset")) { + dateTimeComponent.assign("timezoneOffset", timeComponent.get("timezoneOffset")); + } + if (timeComponent.isCertain("meridiem")) { + dateTimeComponent.assign("meridiem", timeComponent.get("meridiem")); + } + else if (timeComponent.get("meridiem") != null && dateTimeComponent.get("meridiem") == null) { + dateTimeComponent.imply("meridiem", timeComponent.get("meridiem")); + } + if (dateTimeComponent.get("meridiem") == index_1$b.Meridiem.PM && dateTimeComponent.get("hour") < 12) { + if (timeComponent.isCertain("hour")) { + dateTimeComponent.assign("hour", dateTimeComponent.get("hour") + 12); + } + else { + dateTimeComponent.imply("hour", dateTimeComponent.get("hour") + 12); + } + } + return dateTimeComponent; +} +mergingCalculation.mergeDateTimeComponent = mergeDateTimeComponent; + +Object.defineProperty(AbstractMergeDateTimeRefiner, "__esModule", { value: true }); +const abstractRefiners_1$2 = abstractRefiners; +const mergingCalculation_1 = mergingCalculation; +class ENMergeDateTimeRefiner$1 extends abstractRefiners_1$2.MergingRefiner { + shouldMergeResults(textBetween, currentResult, nextResult) { + return (((currentResult.start.isOnlyDate() && nextResult.start.isOnlyTime()) || + (nextResult.start.isOnlyDate() && currentResult.start.isOnlyTime())) && + textBetween.match(this.patternBetween()) != null); + } + mergeResults(textBetween, currentResult, nextResult) { + const result = currentResult.start.isOnlyDate() + ? (0, mergingCalculation_1.mergeDateTimeResult)(currentResult, nextResult) + : (0, mergingCalculation_1.mergeDateTimeResult)(nextResult, currentResult); + result.index = currentResult.index; + result.text = currentResult.text + textBetween + nextResult.text; + return result; + } +} +AbstractMergeDateTimeRefiner.default = ENMergeDateTimeRefiner$1; + +var __importDefault$F = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ENMergeDateTimeRefiner$2, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$6 = __importDefault$F(AbstractMergeDateTimeRefiner); +class ENMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$6.default { + patternBetween() { + return new RegExp("^\\s*(T|at|after|before|on|of|,|-)?\\s*$"); + } +} +ENMergeDateTimeRefiner$2.default = ENMergeDateTimeRefiner; + +var configurations = {}; + +var ExtractTimezoneAbbrRefiner$1 = {}; + +Object.defineProperty(ExtractTimezoneAbbrRefiner$1, "__esModule", { value: true }); +const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*,?\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i"); +const DEFAULT_TIMEZONE_ABBR_MAP = { + ACDT: 630, + ACST: 570, + ADT: -180, + AEDT: 660, + AEST: 600, + AFT: 270, + AKDT: -480, + AKST: -540, + ALMT: 360, + AMST: -180, + AMT: -240, + ANAST: 720, + ANAT: 720, + AQTT: 300, + ART: -180, + AST: -240, + AWDT: 540, + AWST: 480, + AZOST: 0, + AZOT: -60, + AZST: 300, + AZT: 240, + BNT: 480, + BOT: -240, + BRST: -120, + BRT: -180, + BST: 60, + BTT: 360, + CAST: 480, + CAT: 120, + CCT: 390, + CDT: -300, + CEST: 120, + CET: 60, + CHADT: 825, + CHAST: 765, + CKT: -600, + CLST: -180, + CLT: -240, + COT: -300, + CST: -360, + CVT: -60, + CXT: 420, + ChST: 600, + DAVT: 420, + EASST: -300, + EAST: -360, + EAT: 180, + ECT: -300, + EDT: -240, + EEST: 180, + EET: 120, + EGST: 0, + EGT: -60, + EST: -300, + ET: -300, + FJST: 780, + FJT: 720, + FKST: -180, + FKT: -240, + FNT: -120, + GALT: -360, + GAMT: -540, + GET: 240, + GFT: -180, + GILT: 720, + GMT: 0, + GST: 240, + GYT: -240, + HAA: -180, + HAC: -300, + HADT: -540, + HAE: -240, + HAP: -420, + HAR: -360, + HAST: -600, + HAT: -90, + HAY: -480, + HKT: 480, + HLV: -210, + HNA: -240, + HNC: -360, + HNE: -300, + HNP: -480, + HNR: -420, + HNT: -150, + HNY: -540, + HOVT: 420, + ICT: 420, + IDT: 180, + IOT: 360, + IRDT: 270, + IRKST: 540, + IRKT: 540, + IRST: 210, + IST: 330, + JST: 540, + KGT: 360, + KRAST: 480, + KRAT: 480, + KST: 540, + KUYT: 240, + LHDT: 660, + LHST: 630, + LINT: 840, + MAGST: 720, + MAGT: 720, + MART: -510, + MAWT: 300, + MDT: -360, + MESZ: 120, + MEZ: 60, + MHT: 720, + MMT: 390, + MSD: 240, + MSK: 240, + MST: -420, + MUT: 240, + MVT: 300, + MYT: 480, + NCT: 660, + NDT: -90, + NFT: 690, + NOVST: 420, + NOVT: 360, + NPT: 345, + NST: -150, + NUT: -660, + NZDT: 780, + NZST: 720, + OMSST: 420, + OMST: 420, + PDT: -420, + PET: -300, + PETST: 720, + PETT: 720, + PGT: 600, + PHOT: 780, + PHT: 480, + PKT: 300, + PMDT: -120, + PMST: -180, + PONT: 660, + PST: -480, + PT: -480, + PWT: 540, + PYST: -180, + PYT: -240, + RET: 240, + SAMT: 240, + SAST: 120, + SBT: 660, + SCT: 240, + SGT: 480, + SRT: -180, + SST: -660, + TAHT: -600, + TFT: 300, + TJT: 300, + TKT: 780, + TLT: 540, + TMT: 300, + TVT: 720, + ULAT: 480, + UTC: 0, + UYST: -120, + UYT: -180, + UZT: 300, + VET: -210, + VLAST: 660, + VLAT: 660, + VUT: 660, + WAST: 120, + WAT: 60, + WEST: 60, + WESZ: 60, + WET: 0, + WEZ: 0, + WFT: 720, + WGST: -120, + WGT: -180, + WIB: 420, + WIT: 540, + WITA: 480, + WST: 780, + WT: 0, + YAKST: 600, + YAKT: 600, + YAPT: 600, + YEKST: 360, + YEKT: 360, +}; +class ExtractTimezoneAbbrRefiner { + constructor(timezoneOverrides) { + this.timezone = Object.assign(Object.assign({}, DEFAULT_TIMEZONE_ABBR_MAP), timezoneOverrides); + } + refine(context, results) { + var _a; + const timezoneOverrides = (_a = context.option.timezones) !== null && _a !== void 0 ? _a : {}; + results.forEach((result) => { + var _a, _b; + const suffix = context.text.substring(result.index + result.text.length); + const match = TIMEZONE_NAME_PATTERN.exec(suffix); + if (!match) { + return; + } + const timezoneAbbr = match[1].toUpperCase(); + const extractedTimezoneOffset = (_b = (_a = timezoneOverrides[timezoneAbbr]) !== null && _a !== void 0 ? _a : this.timezone[timezoneAbbr]) !== null && _b !== void 0 ? _b : null; + if (extractedTimezoneOffset === null) { + return; + } + context.debug(() => { + console.log(`Extracting timezone: '${timezoneAbbr}' into : ${extractedTimezoneOffset}`); + }); + const currentTimezoneOffset = result.start.get("timezoneOffset"); + if (currentTimezoneOffset !== null && extractedTimezoneOffset != currentTimezoneOffset) { + if (result.start.isCertain("timezoneOffset")) { + return; + } + if (timezoneAbbr != match[1]) { + return; + } + } + if (result.start.isOnlyDate()) { + if (timezoneAbbr != match[1]) { + return; + } + } + result.text += match[0]; + if (!result.start.isCertain("timezoneOffset")) { + result.start.assign("timezoneOffset", extractedTimezoneOffset); + } + if (result.end != null && !result.end.isCertain("timezoneOffset")) { + result.end.assign("timezoneOffset", extractedTimezoneOffset); + } + }); + return results; + } +} +ExtractTimezoneAbbrRefiner$1.default = ExtractTimezoneAbbrRefiner; + +var ExtractTimezoneOffsetRefiner$1 = {}; + +Object.defineProperty(ExtractTimezoneOffsetRefiner$1, "__esModule", { value: true }); +const TIMEZONE_OFFSET_PATTERN = new RegExp("^\\s*(?:(?:GMT|UTC)\\s?)?([+-])(\\d{1,2})(?::?(\\d{2}))?", "i"); +const TIMEZONE_OFFSET_SIGN_GROUP = 1; +const TIMEZONE_OFFSET_HOUR_OFFSET_GROUP = 2; +const TIMEZONE_OFFSET_MINUTE_OFFSET_GROUP = 3; +class ExtractTimezoneOffsetRefiner { + refine(context, results) { + results.forEach(function (result) { + if (result.start.isCertain("timezoneOffset")) { + return; + } + const suffix = context.text.substring(result.index + result.text.length); + const match = TIMEZONE_OFFSET_PATTERN.exec(suffix); + if (!match) { + return; + } + context.debug(() => { + console.log(`Extracting timezone: '${match[0]}' into : ${result}`); + }); + const hourOffset = parseInt(match[TIMEZONE_OFFSET_HOUR_OFFSET_GROUP]); + const minuteOffset = parseInt(match[TIMEZONE_OFFSET_MINUTE_OFFSET_GROUP] || "0"); + let timezoneOffset = hourOffset * 60 + minuteOffset; + if (match[TIMEZONE_OFFSET_SIGN_GROUP] === "-") { + timezoneOffset = -timezoneOffset; + } + if (result.end != null) { + result.end.assign("timezoneOffset", timezoneOffset); + } + result.start.assign("timezoneOffset", timezoneOffset); + result.text += match[0]; + }); + return results; + } +} +ExtractTimezoneOffsetRefiner$1.default = ExtractTimezoneOffsetRefiner; + +var OverlapRemovalRefiner$1 = {}; + +Object.defineProperty(OverlapRemovalRefiner$1, "__esModule", { value: true }); +class OverlapRemovalRefiner { + refine(context, results) { + if (results.length < 2) { + return results; + } + const filteredResults = []; + let prevResult = results[0]; + for (let i = 1; i < results.length; i++) { + const result = results[i]; + if (result.index < prevResult.index + prevResult.text.length) { + if (result.text.length > prevResult.text.length) { + prevResult = result; + } + } + else { + filteredResults.push(prevResult); + prevResult = result; + } + } + if (prevResult != null) { + filteredResults.push(prevResult); + } + return filteredResults; + } +} +OverlapRemovalRefiner$1.default = OverlapRemovalRefiner; + +var ForwardDateRefiner$1 = {}; + +var __importDefault$E = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ForwardDateRefiner$1, "__esModule", { value: true }); +const dayjs_1$q = __importDefault$E(require$$0); +class ForwardDateRefiner { + refine(context, results) { + if (!context.option.forwardDate) { + return results; + } + results.forEach(function (result) { + let refMoment = (0, dayjs_1$q.default)(context.refDate); + if (result.start.isOnlyDayMonthComponent() && refMoment.isAfter(result.start.dayjs())) { + for (let i = 0; i < 3 && refMoment.isAfter(result.start.dayjs()); i++) { + result.start.imply("year", result.start.get("year") + 1); + context.debug(() => { + console.log(`Forward yearly adjusted for ${result} (${result.start})`); + }); + if (result.end && !result.end.isCertain("year")) { + result.end.imply("year", result.end.get("year") + 1); + context.debug(() => { + console.log(`Forward yearly adjusted for ${result} (${result.end})`); + }); + } + } + } + if (result.start.isOnlyWeekdayComponent() && refMoment.isAfter(result.start.dayjs())) { + if (refMoment.day() >= result.start.get("weekday")) { + refMoment = refMoment.day(result.start.get("weekday") + 7); + } + else { + refMoment = refMoment.day(result.start.get("weekday")); + } + result.start.imply("day", refMoment.date()); + result.start.imply("month", refMoment.month() + 1); + result.start.imply("year", refMoment.year()); + context.debug(() => { + console.log(`Forward weekly adjusted for ${result} (${result.start})`); + }); + if (result.end && result.end.isOnlyWeekdayComponent()) { + if (refMoment.day() > result.end.get("weekday")) { + refMoment = refMoment.day(result.end.get("weekday") + 7); + } + else { + refMoment = refMoment.day(result.end.get("weekday")); + } + result.end.imply("day", refMoment.date()); + result.end.imply("month", refMoment.month() + 1); + result.end.imply("year", refMoment.year()); + context.debug(() => { + console.log(`Forward weekly adjusted for ${result} (${result.end})`); + }); + } + } + }); + return results; + } +} +ForwardDateRefiner$1.default = ForwardDateRefiner; + +var UnlikelyFormatFilter$1 = {}; + +Object.defineProperty(UnlikelyFormatFilter$1, "__esModule", { value: true }); +const abstractRefiners_1$1 = abstractRefiners; +class UnlikelyFormatFilter extends abstractRefiners_1$1.Filter { + constructor(strictMode) { + super(); + this.strictMode = strictMode; + } + isValid(context, result) { + if (result.text.replace(" ", "").match(/^\d*(\.\d*)?$/)) { + context.debug(() => { + console.log(`Removing unlikely result '${result.text}'`); + }); + return false; + } + if (!result.start.isValidDate()) { + context.debug(() => { + console.log(`Removing invalid result: ${result} (${result.start})`); + }); + return false; + } + if (result.end && !result.end.isValidDate()) { + context.debug(() => { + console.log(`Removing invalid result: ${result} (${result.end})`); + }); + return false; + } + if (this.strictMode) { + return this.isStrictModeValid(context, result); + } + return true; + } + isStrictModeValid(context, result) { + if (result.start.isOnlyWeekdayComponent()) { + context.debug(() => { + console.log(`(Strict) Removing weekday only component: ${result} (${result.end})`); + }); + return false; + } + if (result.start.isOnlyTime() && (!result.start.isCertain("hour") || !result.start.isCertain("minute"))) { + context.debug(() => { + console.log(`(Strict) Removing uncertain time component: ${result} (${result.end})`); + }); + return false; + } + return true; + } +} +UnlikelyFormatFilter$1.default = UnlikelyFormatFilter; + +var ISOFormatParser$1 = {}; + +Object.defineProperty(ISOFormatParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$J = AbstractParserWithWordBoundary; +const PATTERN$u = new RegExp("([0-9]{4})\\-([0-9]{1,2})\\-([0-9]{1,2})" + + "(?:T" + + "([0-9]{1,2}):([0-9]{1,2})" + + "(?:" + + ":([0-9]{1,2})(?:\\.(\\d{1,4}))?" + + ")?" + + "(?:" + + "Z|([+-]\\d{2}):?(\\d{2})?" + + ")?" + + ")?" + + "(?=\\W|$)", "i"); +const YEAR_NUMBER_GROUP$2 = 1; +const MONTH_NUMBER_GROUP$1 = 2; +const DATE_NUMBER_GROUP$1 = 3; +const HOUR_NUMBER_GROUP = 4; +const MINUTE_NUMBER_GROUP = 5; +const SECOND_NUMBER_GROUP = 6; +const MILLISECOND_NUMBER_GROUP = 7; +const TZD_HOUR_OFFSET_GROUP = 8; +const TZD_MINUTE_OFFSET_GROUP = 9; +class ISOFormatParser extends AbstractParserWithWordBoundary_1$J.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$u; + } + innerExtract(context, match) { + const components = {}; + components["year"] = parseInt(match[YEAR_NUMBER_GROUP$2]); + components["month"] = parseInt(match[MONTH_NUMBER_GROUP$1]); + components["day"] = parseInt(match[DATE_NUMBER_GROUP$1]); + if (match[HOUR_NUMBER_GROUP] != null) { + components["hour"] = parseInt(match[HOUR_NUMBER_GROUP]); + components["minute"] = parseInt(match[MINUTE_NUMBER_GROUP]); + if (match[SECOND_NUMBER_GROUP] != null) { + components["second"] = parseInt(match[SECOND_NUMBER_GROUP]); + } + if (match[MILLISECOND_NUMBER_GROUP] != null) { + components["millisecond"] = parseInt(match[MILLISECOND_NUMBER_GROUP]); + } + if (match[TZD_HOUR_OFFSET_GROUP] == null) { + components["timezoneOffset"] = 0; + } + else { + const hourOffset = parseInt(match[TZD_HOUR_OFFSET_GROUP]); + let minuteOffset = 0; + if (match[TZD_MINUTE_OFFSET_GROUP] != null) { + minuteOffset = parseInt(match[TZD_MINUTE_OFFSET_GROUP]); + } + let offset = hourOffset * 60; + if (offset < 0) { + offset -= minuteOffset; + } + else { + offset += minuteOffset; + } + components["timezoneOffset"] = offset; + } + } + return components; + } +} +ISOFormatParser$1.default = ISOFormatParser; + +var MergeWeekdayComponentRefiner$1 = {}; + +Object.defineProperty(MergeWeekdayComponentRefiner$1, "__esModule", { value: true }); +const abstractRefiners_1 = abstractRefiners; +class MergeWeekdayComponentRefiner extends abstractRefiners_1.MergingRefiner { + mergeResults(textBetween, currentResult, nextResult) { + const newResult = nextResult.clone(); + newResult.index = currentResult.index; + newResult.text = currentResult.text + textBetween + newResult.text; + newResult.start.assign("weekday", currentResult.start.get("weekday")); + if (newResult.end) { + newResult.end.assign("weekday", currentResult.start.get("weekday")); + } + return newResult; + } + shouldMergeResults(textBetween, currentResult, nextResult) { + const weekdayThenNormalDate = currentResult.start.isOnlyWeekdayComponent() && + !currentResult.start.isCertain("hour") && + nextResult.start.isCertain("day"); + return weekdayThenNormalDate && textBetween.match(/^,?\s*$/) != null; + } +} +MergeWeekdayComponentRefiner$1.default = MergeWeekdayComponentRefiner; + +var __importDefault$D = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(configurations, "__esModule", { value: true }); +configurations.includeCommonConfiguration = void 0; +const ExtractTimezoneAbbrRefiner_1 = __importDefault$D(ExtractTimezoneAbbrRefiner$1); +const ExtractTimezoneOffsetRefiner_1 = __importDefault$D(ExtractTimezoneOffsetRefiner$1); +const OverlapRemovalRefiner_1 = __importDefault$D(OverlapRemovalRefiner$1); +const ForwardDateRefiner_1 = __importDefault$D(ForwardDateRefiner$1); +const UnlikelyFormatFilter_1 = __importDefault$D(UnlikelyFormatFilter$1); +const ISOFormatParser_1 = __importDefault$D(ISOFormatParser$1); +const MergeWeekdayComponentRefiner_1 = __importDefault$D(MergeWeekdayComponentRefiner$1); +function includeCommonConfiguration(configuration, strictMode = false) { + configuration.parsers.unshift(new ISOFormatParser_1.default()); + configuration.refiners.unshift(new MergeWeekdayComponentRefiner_1.default()); + configuration.refiners.unshift(new ExtractTimezoneAbbrRefiner_1.default()); + configuration.refiners.unshift(new ExtractTimezoneOffsetRefiner_1.default()); + configuration.refiners.unshift(new OverlapRemovalRefiner_1.default()); + configuration.refiners.push(new OverlapRemovalRefiner_1.default()); + configuration.refiners.push(new ForwardDateRefiner_1.default()); + configuration.refiners.push(new UnlikelyFormatFilter_1.default(strictMode)); + return configuration; +} +configurations.includeCommonConfiguration = includeCommonConfiguration; + +var ENCasualDateParser$1 = {}; + +var casualReferences = {}; + +var __importDefault$C = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(casualReferences, "__esModule", { value: true }); +casualReferences.tonight = casualReferences.tomorrow = casualReferences.yesterday = casualReferences.today = casualReferences.now = void 0; +const results_1$b = results; +const dayjs_1$p = __importDefault$C(require$$0); +const dayjs_2$8 = dayjs; +const index_1$a = dist; +function now(reference) { + const targetDate = (0, dayjs_1$p.default)(reference.instant); + const component = new results_1$b.ParsingComponents(reference, {}); + (0, dayjs_2$8.assignSimilarDate)(component, targetDate); + (0, dayjs_2$8.assignSimilarTime)(component, targetDate); + if (reference.timezoneOffset !== null) { + component.assign("timezoneOffset", targetDate.utcOffset()); + } + return component; +} +casualReferences.now = now; +function today(reference) { + const targetDate = (0, dayjs_1$p.default)(reference.instant); + const component = new results_1$b.ParsingComponents(reference, {}); + (0, dayjs_2$8.assignSimilarDate)(component, targetDate); + (0, dayjs_2$8.implySimilarTime)(component, targetDate); + return component; +} +casualReferences.today = today; +function yesterday(reference) { + let targetDate = (0, dayjs_1$p.default)(reference.instant); + const component = new results_1$b.ParsingComponents(reference, {}); + targetDate = targetDate.add(-1, "day"); + (0, dayjs_2$8.assignSimilarDate)(component, targetDate); + (0, dayjs_2$8.implySimilarTime)(component, targetDate); + return component; +} +casualReferences.yesterday = yesterday; +function tomorrow(reference) { + const targetDate = (0, dayjs_1$p.default)(reference.instant); + const component = new results_1$b.ParsingComponents(reference, {}); + (0, dayjs_2$8.assignTheNextDay)(component, targetDate); + return component; +} +casualReferences.tomorrow = tomorrow; +function tonight(reference, implyHour = 22) { + const targetDate = (0, dayjs_1$p.default)(reference.instant); + const component = new results_1$b.ParsingComponents(reference, {}); + component.imply("hour", implyHour); + component.imply("meridiem", index_1$a.Meridiem.PM); + (0, dayjs_2$8.assignSimilarDate)(component, targetDate); + return component; +} +casualReferences.tonight = tonight; + +var __createBinding$5 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault$5 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar$5 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$5(result, mod, k); + __setModuleDefault$5(result, mod); + return result; +}; +var __importDefault$B = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ENCasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$o = __importDefault$B(require$$0); +const AbstractParserWithWordBoundary_1$I = AbstractParserWithWordBoundary; +const dayjs_2$7 = dayjs; +const references$5 = __importStar$5(casualReferences); +const PATTERN$t = /(now|today|tonight|tomorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i; +class ENCasualDateParser extends AbstractParserWithWordBoundary_1$I.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return PATTERN$t; + } + innerExtract(context, match) { + let targetDate = (0, dayjs_1$o.default)(context.refDate); + const lowerText = match[0].toLowerCase(); + const component = context.createParsingComponents(); + switch (lowerText) { + case "now": + return references$5.now(context.reference); + case "today": + return references$5.today(context.reference); + case "yesterday": + return references$5.yesterday(context.reference); + case "tomorrow": + case "tmr": + case "tmrw": + return references$5.tomorrow(context.reference); + case "tonight": + return references$5.tonight(context.reference); + default: + if (lowerText.match(/last\s*night/)) { + if (targetDate.hour() > 6) { + targetDate = targetDate.add(-1, "day"); + } + (0, dayjs_2$7.assignSimilarDate)(component, targetDate); + component.imply("hour", 0); + } + break; + } + return component; + } +} +ENCasualDateParser$1.default = ENCasualDateParser; + +var ENCasualTimeParser$1 = {}; + +var __importDefault$A = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ENCasualTimeParser$1, "__esModule", { value: true }); +const index_1$9 = dist; +const AbstractParserWithWordBoundary_1$H = AbstractParserWithWordBoundary; +const dayjs_1$n = __importDefault$A(require$$0); +const dayjs_2$6 = dayjs; +const PATTERN$s = /(?:this)?\s{0,3}(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i; +class ENCasualTimeParser extends AbstractParserWithWordBoundary_1$H.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$s; + } + innerExtract(context, match) { + const targetDate = (0, dayjs_1$n.default)(context.refDate); + const component = context.createParsingComponents(); + switch (match[1].toLowerCase()) { + case "afternoon": + component.imply("meridiem", index_1$9.Meridiem.PM); + component.imply("hour", 15); + break; + case "evening": + case "night": + component.imply("meridiem", index_1$9.Meridiem.PM); + component.imply("hour", 20); + break; + case "midnight": + (0, dayjs_2$6.assignTheNextDay)(component, targetDate); + component.imply("hour", 0); + component.imply("minute", 0); + component.imply("second", 0); + break; + case "morning": + component.imply("meridiem", index_1$9.Meridiem.AM); + component.imply("hour", 6); + break; + case "noon": + component.imply("meridiem", index_1$9.Meridiem.AM); + component.imply("hour", 12); + break; + } + return component; + } +} +ENCasualTimeParser$1.default = ENCasualTimeParser; + +var ENWeekdayParser$1 = {}; + +var weeks = {}; + +var __importDefault$z = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(weeks, "__esModule", { value: true }); +weeks.toDayJSClosestWeekday = weeks.toDayJSWeekday = void 0; +const dayjs_1$m = __importDefault$z(require$$0); +function toDayJSWeekday(refDate, offset, modifier, locale) { + var _a; + if (!modifier) { + return toDayJSClosestWeekday(refDate, offset, locale); + } + let date = (0, dayjs_1$m.default)(refDate).locale("en", locale); + const weekStart = (_a = locale === null || locale === void 0 ? void 0 : locale.weekStart) !== null && _a !== void 0 ? _a : 0; + const weekdayOffset = (7 + offset - weekStart) % 7; + switch (modifier) { + case "this": + date = date.weekday(weekdayOffset); + break; + case "next": + date = date.weekday(weekdayOffset + 7); + break; + case "last": + date = date.weekday(weekdayOffset - 7); + break; + } + return date; +} +weeks.toDayJSWeekday = toDayJSWeekday; +function toDayJSClosestWeekday(refDate, offset, locale) { + var _a; + let date = (0, dayjs_1$m.default)(refDate).locale("en", locale); + const refOffset = date.weekday(); + const weekStart = (_a = locale === null || locale === void 0 ? void 0 : locale.weekStart) !== null && _a !== void 0 ? _a : 0; + const weekdayOffset = (7 + offset - weekStart) % 7; + if (Math.abs(weekdayOffset - 7 - refOffset) < Math.abs(weekdayOffset - refOffset)) { + date = date.weekday(weekdayOffset - 7); + } + else if (Math.abs(weekdayOffset + 7 - refOffset) < Math.abs(weekdayOffset - refOffset)) { + date = date.weekday(weekdayOffset + 7); + } + else { + date = date.weekday(weekdayOffset); + } + return date; +} +weeks.toDayJSClosestWeekday = toDayJSClosestWeekday; + +Object.defineProperty(ENWeekdayParser$1, "__esModule", { value: true }); +const constants_1$v = constants$7; +const pattern_1$d = pattern; +const AbstractParserWithWordBoundary_1$G = AbstractParserWithWordBoundary; +const weeks_1$4 = weeks; +const PATTERN$r = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + + "(?:on\\s*?)?" + + "(?:(this|last|past|next)\\s*)?" + + `(${(0, pattern_1$d.matchAnyPattern)(constants_1$v.WEEKDAY_DICTIONARY)})` + + "(?:\\s*(?:\\,|\\)|\\)))?" + + "(?:\\s*(this|last|past|next)\\s*week)?" + + "(?=\\W|$)", "i"); +const PREFIX_GROUP$3 = 1; +const WEEKDAY_GROUP$4 = 2; +const POSTFIX_GROUP$3 = 3; +class ENWeekdayParser extends AbstractParserWithWordBoundary_1$G.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$r; + } + innerExtract(context, match) { + const dayOfWeek = match[WEEKDAY_GROUP$4].toLowerCase(); + const offset = constants_1$v.WEEKDAY_DICTIONARY[dayOfWeek]; + const prefix = match[PREFIX_GROUP$3]; + const postfix = match[POSTFIX_GROUP$3]; + let modifierWord = prefix || postfix; + modifierWord = modifierWord || ""; + modifierWord = modifierWord.toLowerCase(); + let modifier = null; + if (modifierWord == "last" || modifierWord == "past") { + modifier = "last"; + } + else if (modifierWord == "next") { + modifier = "next"; + } + else if (modifierWord == "this") { + modifier = "this"; + } + const date = (0, weeks_1$4.toDayJSWeekday)(context.refDate, offset, modifier, context.option.locale); + return context + .createParsingComponents() + .assign("weekday", offset) + .imply("day", date.date()) + .imply("month", date.month() + 1) + .imply("year", date.year()); + } +} +ENWeekdayParser$1.default = ENWeekdayParser; + +var ENRelativeDateFormatParser$1 = {}; + +var __importDefault$y = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ENRelativeDateFormatParser$1, "__esModule", { value: true }); +const constants_1$u = constants$7; +const results_1$a = results; +const dayjs_1$l = __importDefault$y(require$$0); +const AbstractParserWithWordBoundary_1$F = AbstractParserWithWordBoundary; +const pattern_1$c = pattern; +const PATTERN$q = new RegExp(`(this|next|last|past)\\s*(${(0, pattern_1$c.matchAnyPattern)(constants_1$u.TIME_UNIT_DICTIONARY)})(?=\\s*)` + "(?=\\W|$)", "i"); +const MODIFIER_WORD_GROUP$1 = 1; +const RELATIVE_WORD_GROUP$1 = 2; +class ENRelativeDateFormatParser extends AbstractParserWithWordBoundary_1$F.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$q; + } + innerExtract(context, match) { + const modifier = match[MODIFIER_WORD_GROUP$1].toLowerCase(); + const unitWord = match[RELATIVE_WORD_GROUP$1].toLowerCase(); + const timeunit = constants_1$u.TIME_UNIT_DICTIONARY[unitWord]; + if (modifier == "next") { + const timeUnits = {}; + timeUnits[timeunit] = 1; + return results_1$a.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } + if (modifier == "last" || modifier == "past") { + const timeUnits = {}; + timeUnits[timeunit] = -1; + return results_1$a.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } + const components = context.createParsingComponents(); + let date = (0, dayjs_1$l.default)(context.reference.instant); + if (unitWord.match(/week/i)) { + date = date.add(-date.get("d"), "d"); + components.imply("day", date.date()); + components.imply("month", date.month() + 1); + components.imply("year", date.year()); + } + else if (unitWord.match(/month/i)) { + date = date.add(-date.date() + 1, "d"); + components.imply("day", date.date()); + components.assign("year", date.year()); + components.assign("month", date.month() + 1); + } + else if (unitWord.match(/year/i)) { + date = date.add(-date.date() + 1, "d"); + date = date.add(-date.month(), "month"); + components.imply("day", date.date()); + components.imply("month", date.month() + 1); + components.assign("year", date.year()); + } + return components; + } +} +ENRelativeDateFormatParser$1.default = ENRelativeDateFormatParser; + +var chrono$1 = {}; + +Object.defineProperty(chrono$1, "__esModule", { value: true }); +chrono$1.ParsingContext = chrono$1.Chrono = void 0; +const results_1$9 = results; +const en_1 = en$1; +class Chrono { + constructor(configuration) { + configuration = configuration || (0, en_1.createCasualConfiguration)(); + this.parsers = [...configuration.parsers]; + this.refiners = [...configuration.refiners]; + } + clone() { + return new Chrono({ + parsers: [...this.parsers], + refiners: [...this.refiners], + }); + } + parseDate(text, referenceDate, option) { + const results = this.parse(text, referenceDate, option); + return results.length > 0 ? results[0].start.date() : null; + } + parse(text, referenceDate, option) { + const context = new ParsingContext(text, referenceDate, option); + let results = []; + this.parsers.forEach((parser) => { + const parsedResults = Chrono.executeParser(context, parser); + results = results.concat(parsedResults); + }); + results.sort((a, b) => { + return a.index - b.index; + }); + this.refiners.forEach(function (refiner) { + results = refiner.refine(context, results); + }); + return results; + } + static executeParser(context, parser) { + const results = []; + const pattern = parser.pattern(context); + const originalText = context.text; + let remainingText = context.text; + let match = pattern.exec(remainingText); + while (match) { + const index = match.index + originalText.length - remainingText.length; + match.index = index; + const result = parser.extract(context, match); + if (!result) { + remainingText = originalText.substring(match.index + 1); + match = pattern.exec(remainingText); + continue; + } + let parsedResult = null; + if (result instanceof results_1$9.ParsingResult) { + parsedResult = result; + } + else if (result instanceof results_1$9.ParsingComponents) { + parsedResult = context.createParsingResult(match.index, match[0]); + parsedResult.start = result; + } + else { + parsedResult = context.createParsingResult(match.index, match[0], result); + } + context.debug(() => console.log(`${parser.constructor.name} extracted result ${parsedResult}`)); + results.push(parsedResult); + remainingText = originalText.substring(index + parsedResult.text.length); + match = pattern.exec(remainingText); + } + return results; + } +} +chrono$1.Chrono = Chrono; +class ParsingContext { + constructor(text, refDate, option) { + this.text = text; + this.reference = new results_1$9.ReferenceWithTimezone(refDate); + this.option = option !== null && option !== void 0 ? option : {}; + this.refDate = this.reference.instant; + } + createParsingComponents(components) { + if (components instanceof results_1$9.ParsingComponents) { + return components; + } + return new results_1$9.ParsingComponents(this.reference, components); + } + createParsingResult(index, textOrEndIndex, startComponents, endComponents) { + const text = typeof textOrEndIndex === "string" ? textOrEndIndex : this.text.substring(index, textOrEndIndex); + const start = startComponents ? this.createParsingComponents(startComponents) : null; + const end = endComponents ? this.createParsingComponents(endComponents) : null; + return new results_1$9.ParsingResult(this.reference, index, text, start, end); + } + debug(block) { + if (this.option.debug) { + if (this.option.debug instanceof Function) { + this.option.debug(block); + } + else { + const handler = this.option.debug; + handler.debug(block); + } + } + } +} +chrono$1.ParsingContext = ParsingContext; + +var SlashDateFormatParser$1 = {}; + +Object.defineProperty(SlashDateFormatParser$1, "__esModule", { value: true }); +const years_1$6 = years; +const PATTERN$p = new RegExp("([^\\d]|^)" + + "([0-3]{0,1}[0-9]{1})[\\/\\.\\-]([0-3]{0,1}[0-9]{1})" + + "(?:[\\/\\.\\-]([0-9]{4}|[0-9]{2}))?" + + "(\\W|$)", "i"); +const OPENING_GROUP = 1; +const ENDING_GROUP = 5; +const FIRST_NUMBERS_GROUP = 2; +const SECOND_NUMBERS_GROUP = 3; +const YEAR_GROUP$8 = 4; +class SlashDateFormatParser { + constructor(littleEndian) { + this.groupNumberMonth = littleEndian ? SECOND_NUMBERS_GROUP : FIRST_NUMBERS_GROUP; + this.groupNumberDay = littleEndian ? FIRST_NUMBERS_GROUP : SECOND_NUMBERS_GROUP; + } + pattern() { + return PATTERN$p; + } + extract(context, match) { + if (match[OPENING_GROUP] == "/" || match[ENDING_GROUP] == "/") { + match.index += match[0].length; + return; + } + const index = match.index + match[OPENING_GROUP].length; + const text = match[0].substr(match[OPENING_GROUP].length, match[0].length - match[OPENING_GROUP].length - match[ENDING_GROUP].length); + if (text.match(/^\d\.\d$/) || text.match(/^\d\.\d{1,2}\.\d{1,2}\s*$/)) { + return; + } + if (!match[YEAR_GROUP$8] && match[0].indexOf("/") < 0) { + return; + } + const result = context.createParsingResult(index, text); + let month = parseInt(match[this.groupNumberMonth]); + let day = parseInt(match[this.groupNumberDay]); + if (month < 1 || month > 12) { + if (month > 12) { + if (day >= 1 && day <= 12 && month <= 31) { + [day, month] = [month, day]; + } + else { + return null; + } + } + } + if (day < 1 || day > 31) { + return null; + } + result.start.assign("day", day); + result.start.assign("month", month); + if (match[YEAR_GROUP$8]) { + const rawYearNumber = parseInt(match[YEAR_GROUP$8]); + const year = (0, years_1$6.findMostLikelyADYear)(rawYearNumber); + result.start.assign("year", year); + } + else { + const year = (0, years_1$6.findYearClosestToRef)(context.refDate, day, month); + result.start.imply("year", year); + } + return result; + } +} +SlashDateFormatParser$1.default = SlashDateFormatParser; + +var ENTimeUnitCasualRelativeFormatParser$1 = {}; + +Object.defineProperty(ENTimeUnitCasualRelativeFormatParser$1, "__esModule", { value: true }); +const constants_1$t = constants$7; +const results_1$8 = results; +const AbstractParserWithWordBoundary_1$E = AbstractParserWithWordBoundary; +const timeunits_1$5 = timeunits; +const PATTERN$o = new RegExp(`(this|last|past|next|\\+|-)\\s*(${constants_1$t.TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); +class ENTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundary_1$E.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$o; + } + innerExtract(context, match) { + const prefix = match[1].toLowerCase(); + let timeUnits = (0, constants_1$t.parseTimeUnits)(match[2]); + switch (prefix) { + case "last": + case "past": + case "-": + timeUnits = (0, timeunits_1$5.reverseTimeUnits)(timeUnits); + break; + } + return results_1$8.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } +} +ENTimeUnitCasualRelativeFormatParser$1.default = ENTimeUnitCasualRelativeFormatParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.GB = exports.strict = exports.casual = void 0; +const ENTimeUnitWithinFormatParser_1 = __importDefault(ENTimeUnitWithinFormatParser$1); +const ENMonthNameLittleEndianParser_1 = __importDefault(ENMonthNameLittleEndianParser$1); +const ENMonthNameMiddleEndianParser_1 = __importDefault(ENMonthNameMiddleEndianParser$1); +const ENMonthNameParser_1 = __importDefault(ENMonthNameParser$1); +const ENCasualYearMonthDayParser_1 = __importDefault(ENCasualYearMonthDayParser$1); +const ENSlashMonthFormatParser_1 = __importDefault(ENSlashMonthFormatParser$1); +const ENTimeExpressionParser_1 = __importDefault(ENTimeExpressionParser$1); +const ENTimeUnitAgoFormatParser_1 = __importDefault(ENTimeUnitAgoFormatParser$1); +const ENTimeUnitLaterFormatParser_1 = __importDefault(ENTimeUnitLaterFormatParser$1); +const ENMergeDateRangeRefiner_1 = __importDefault(ENMergeDateRangeRefiner$1); +const ENMergeDateTimeRefiner_1 = __importDefault(ENMergeDateTimeRefiner$2); +const configurations_1 = configurations; +const ENCasualDateParser_1 = __importDefault(ENCasualDateParser$1); +const ENCasualTimeParser_1 = __importDefault(ENCasualTimeParser$1); +const ENWeekdayParser_1 = __importDefault(ENWeekdayParser$1); +const ENRelativeDateFormatParser_1 = __importDefault(ENRelativeDateFormatParser$1); +const chrono_1 = chrono$1; +const SlashDateFormatParser_1 = __importDefault(SlashDateFormatParser$1); +const ENTimeUnitCasualRelativeFormatParser_1 = __importDefault(ENTimeUnitCasualRelativeFormatParser$1); +exports.casual = new chrono_1.Chrono(createCasualConfiguration(false)); +exports.strict = new chrono_1.Chrono(createConfiguration(true, false)); +exports.GB = new chrono_1.Chrono(createConfiguration(false, true)); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration(littleEndian = false) { + const option = createConfiguration(false, littleEndian); + option.parsers.unshift(new ENCasualDateParser_1.default()); + option.parsers.unshift(new ENCasualTimeParser_1.default()); + option.parsers.unshift(new ENMonthNameParser_1.default()); + option.parsers.unshift(new ENRelativeDateFormatParser_1.default()); + option.parsers.unshift(new ENTimeUnitCasualRelativeFormatParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration(strictMode = true, littleEndian = false) { + return (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new SlashDateFormatParser_1.default(littleEndian), + new ENTimeUnitWithinFormatParser_1.default(), + new ENMonthNameLittleEndianParser_1.default(), + new ENMonthNameMiddleEndianParser_1.default(), + new ENWeekdayParser_1.default(), + new ENCasualYearMonthDayParser_1.default(), + new ENSlashMonthFormatParser_1.default(), + new ENTimeExpressionParser_1.default(strictMode), + new ENTimeUnitAgoFormatParser_1.default(strictMode), + new ENTimeUnitLaterFormatParser_1.default(strictMode), + ], + refiners: [new ENMergeDateTimeRefiner_1.default(), new ENMergeDateRangeRefiner_1.default()], + }, strictMode); +} +exports.createConfiguration = createConfiguration; +}(en$1)); + +var de = {}; + +var DETimeExpressionParser$1 = {}; + +Object.defineProperty(DETimeExpressionParser$1, "__esModule", { value: true }); +const AbstractTimeExpressionParser_1$3 = AbstractTimeExpressionParser$1; +const index_1$8 = dist; +class DETimeExpressionParser extends AbstractTimeExpressionParser_1$3.AbstractTimeExpressionParser { + primaryPrefix() { + return "(?:(?:um|von)\\s*)?"; + } + followingPhase() { + return "\\s*(?:\\-|\\–|\\~|\\〜|bis)\\s*"; + } + primarySuffix() { + return "(?:\\s*uhr)?(?:\\s*(?:morgens|vormittags|nachmittags|abends|nachts))?(?=\\W|$)"; + } + extractPrimaryTimeComponents(context, match) { + const components = super.extractPrimaryTimeComponents(context, match); + if (components) { + if (match[0].endsWith("morgens") || match[0].endsWith("vormittags")) { + components.assign("meridiem", index_1$8.Meridiem.AM); + const hour = components.get("hour"); + if (hour < 12) { + components.assign("hour", components.get("hour")); + } + } + if (match[0].endsWith("nachmittags") || match[0].endsWith("abends") || match[0].endsWith("nachts")) { + components.assign("meridiem", index_1$8.Meridiem.PM); + const hour = components.get("hour"); + if (hour < 12) { + components.assign("hour", components.get("hour") + 12); + } + } + } + return components; + } +} +DETimeExpressionParser$1.default = DETimeExpressionParser; + +var DEWeekdayParser$1 = {}; + +var constants$6 = {}; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseTimeUnits = exports.TIME_UNITS_PATTERN = exports.parseYear = exports.YEAR_PATTERN = exports.parseNumberPattern = exports.NUMBER_PATTERN = exports.TIME_UNIT_DICTIONARY = exports.INTEGER_WORD_DICTIONARY = exports.MONTH_DICTIONARY = exports.WEEKDAY_DICTIONARY = void 0; +const pattern_1 = pattern; +const years_1 = years; +exports.WEEKDAY_DICTIONARY = { + "sonntag": 0, + "so": 0, + "montag": 1, + "mo": 1, + "dienstag": 2, + "di": 2, + "mittwoch": 3, + "mi": 3, + "donnerstag": 4, + "do": 4, + "freitag": 5, + "fr": 5, + "samstag": 6, + "sa": 6, +}; +exports.MONTH_DICTIONARY = { + "januar": 1, + "jan": 1, + "jan.": 1, + "februar": 2, + "feb": 2, + "feb.": 2, + "märz": 3, + "maerz": 3, + "mär": 3, + "mär.": 3, + "mrz": 3, + "mrz.": 3, + "april": 4, + "apr": 4, + "apr.": 4, + "mai": 5, + "juni": 6, + "jun": 6, + "jun.": 6, + "juli": 7, + "jul": 7, + "jul.": 7, + "august": 8, + "aug": 8, + "aug.": 8, + "september": 9, + "sep": 9, + "sep.": 9, + "sept": 9, + "sept.": 9, + "oktober": 10, + "okt": 10, + "okt.": 10, + "november": 11, + "nov": 11, + "nov.": 11, + "dezember": 12, + "dez": 12, + "dez.": 12, +}; +exports.INTEGER_WORD_DICTIONARY = { + "eins": 1, + "zwei": 2, + "drei": 3, + "vier": 4, + "fünf": 5, + "fuenf": 5, + "sechs": 6, + "sieben": 7, + "acht": 8, + "neun": 9, + "zehn": 10, + "elf": 11, + "zwölf": 12, + "zwoelf": 12, +}; +exports.TIME_UNIT_DICTIONARY = { + sec: "second", + second: "second", + seconds: "second", + min: "minute", + mins: "minute", + minute: "minute", + minutes: "minute", + h: "hour", + hr: "hour", + hrs: "hour", + hour: "hour", + hours: "hour", + day: "d", + days: "d", + week: "week", + weeks: "week", + month: "month", + months: "month", + y: "year", + yr: "year", + year: "year", + years: "year", +}; +exports.NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s*an?)?|an?\\b(?:\\s*few)?|few|several|a?\\s*couple\\s*(?:of)?)`; +function parseNumberPattern(match) { + const num = match.toLowerCase(); + if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) { + return exports.INTEGER_WORD_DICTIONARY[num]; + } + else if (num === "a" || num === "an") { + return 1; + } + else if (num.match(/few/)) { + return 3; + } + else if (num.match(/half/)) { + return 0.5; + } + else if (num.match(/couple/)) { + return 2; + } + else if (num.match(/several/)) { + return 7; + } + return parseFloat(num); +} +exports.parseNumberPattern = parseNumberPattern; +exports.YEAR_PATTERN = `(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*C(?:hr)?\\.?)?)`; +function parseYear(match) { + if (/v/i.test(match)) { + return -parseInt(match.replace(/[^0-9]+/gi, "")); + } + if (/n/i.test(match)) { + return parseInt(match.replace(/[^0-9]+/gi, "")); + } + const rawYearNumber = parseInt(match); + return (0, years_1.findMostLikelyADYear)(rawYearNumber); +} +exports.parseYear = parseYear; +const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${(0, pattern_1.matchAnyPattern)(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; +const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); +exports.TIME_UNITS_PATTERN = (0, pattern_1.repeatedTimeunitPattern)("", SINGLE_TIME_UNIT_PATTERN); +function parseTimeUnits(timeunitText) { + const fragments = {}; + let remainingText = timeunitText; + let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + while (match) { + collectDateTimeFragment(fragments, match); + remainingText = remainingText.substring(match[0].length); + match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + } + return fragments; +} +exports.parseTimeUnits = parseTimeUnits; +function collectDateTimeFragment(fragments, match) { + const num = parseNumberPattern(match[1]); + const unit = exports.TIME_UNIT_DICTIONARY[match[2].toLowerCase()]; + fragments[unit] = num; +} +}(constants$6)); + +Object.defineProperty(DEWeekdayParser$1, "__esModule", { value: true }); +const constants_1$s = constants$6; +const pattern_1$b = pattern; +const AbstractParserWithWordBoundary_1$D = AbstractParserWithWordBoundary; +const weeks_1$3 = weeks; +const PATTERN$n = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + + "(?:a[mn]\\s*?)?" + + "(?:(diese[mn]|letzte[mn]|n(?:ä|ae)chste[mn])\\s*)?" + + `(${(0, pattern_1$b.matchAnyPattern)(constants_1$s.WEEKDAY_DICTIONARY)})` + + "(?:\\s*(?:\\,|\\)|\\)))?" + + "(?:\\s*(diese|letzte|n(?:ä|ae)chste)\\s*woche)?" + + "(?=\\W|$)", "i"); +const PREFIX_GROUP$2 = 1; +const SUFFIX_GROUP = 3; +const WEEKDAY_GROUP$3 = 2; +class DEWeekdayParser extends AbstractParserWithWordBoundary_1$D.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$n; + } + innerExtract(context, match) { + const dayOfWeek = match[WEEKDAY_GROUP$3].toLowerCase(); + const offset = constants_1$s.WEEKDAY_DICTIONARY[dayOfWeek]; + const prefix = match[PREFIX_GROUP$2]; + const postfix = match[SUFFIX_GROUP]; + let modifierWord = prefix || postfix; + modifierWord = modifierWord || ""; + modifierWord = modifierWord.toLowerCase(); + let modifier = null; + if (modifierWord.match(/letzte/)) { + modifier = "last"; + } + else if (modifierWord.match(/chste/)) { + modifier = "next"; + } + else if (modifierWord.match(/diese/)) { + modifier = "this"; + } + const date = (0, weeks_1$3.toDayJSWeekday)(context.refDate, offset, modifier); + return context + .createParsingComponents() + .assign("weekday", offset) + .imply("day", date.date()) + .imply("month", date.month() + 1) + .imply("year", date.year()); + } +} +DEWeekdayParser$1.default = DEWeekdayParser; + +var DEMergeDateRangeRefiner$1 = {}; + +var __importDefault$x = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(DEMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$6 = __importDefault$x(AbstractMergeDateRangeRefiner$1); +class DEMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$6.default { + patternBetween() { + return /^\s*(bis(?:\s*(?:am|zum))?|-)\s*$/i; + } +} +DEMergeDateRangeRefiner$1.default = DEMergeDateRangeRefiner; + +var DEMergeDateTimeRefiner$1 = {}; + +var __importDefault$w = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(DEMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$5 = __importDefault$w(AbstractMergeDateTimeRefiner); +class DEMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$5.default { + patternBetween() { + return new RegExp("^\\s*(T|um|am|,|-)?\\s*$"); + } +} +DEMergeDateTimeRefiner$1.default = DEMergeDateTimeRefiner; + +var DECasualDateParser$1 = {}; + +var DECasualTimeParser$1 = {}; + +var __importDefault$v = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(DECasualTimeParser$1, "__esModule", { value: true }); +const dayjs_1$k = __importDefault$v(require$$0); +const index_1$7 = dist; +const AbstractParserWithWordBoundary_1$C = AbstractParserWithWordBoundary; +const dayjs_2$5 = dayjs; +const timeunits_1$4 = timeunits; +class DECasualTimeParser extends AbstractParserWithWordBoundary_1$C.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(diesen)?\s*(morgen|vormittag|mittags?|nachmittag|abend|nacht|mitternacht)(?=\W|$)/i; + } + innerExtract(context, match) { + const targetDate = (0, dayjs_1$k.default)(context.refDate); + const timeKeywordPattern = match[2].toLowerCase(); + const component = context.createParsingComponents(); + (0, dayjs_2$5.implySimilarTime)(component, targetDate); + return DECasualTimeParser.extractTimeComponents(component, timeKeywordPattern); + } + static extractTimeComponents(component, timeKeywordPattern) { + switch (timeKeywordPattern) { + case "morgen": + component.imply("hour", 6); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.AM); + break; + case "vormittag": + component.imply("hour", 9); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.AM); + break; + case "mittag": + case "mittags": + component.imply("hour", 12); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.AM); + break; + case "nachmittag": + component.imply("hour", 15); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.PM); + break; + case "abend": + component.imply("hour", 18); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.PM); + break; + case "nacht": + component.imply("hour", 22); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.PM); + break; + case "mitternacht": + if (component.get("hour") > 1) { + component = (0, timeunits_1$4.addImpliedTimeUnits)(component, { "day": 1 }); + } + component.imply("hour", 0); + component.imply("minute", 0); + component.imply("second", 0); + component.imply("meridiem", index_1$7.Meridiem.AM); + break; + } + return component; + } +} +DECasualTimeParser$1.default = DECasualTimeParser; + +var __createBinding$4 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault$4 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar$4 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$4(result, mod, k); + __setModuleDefault$4(result, mod); + return result; +}; +var __importDefault$u = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(DECasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$j = __importDefault$u(require$$0); +const AbstractParserWithWordBoundary_1$B = AbstractParserWithWordBoundary; +const dayjs_2$4 = dayjs; +const DECasualTimeParser_1 = __importDefault$u(DECasualTimeParser$1); +const references$4 = __importStar$4(casualReferences); +const PATTERN$m = new RegExp(`(jetzt|heute|morgen|übermorgen|uebermorgen|gestern|vorgestern|letzte\\s*nacht)` + + `(?:\\s*(morgen|vormittag|mittags?|nachmittag|abend|nacht|mitternacht))?` + + `(?=\\W|$)`, "i"); +const DATE_GROUP$5 = 1; +const TIME_GROUP = 2; +class DECasualDateParser extends AbstractParserWithWordBoundary_1$B.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return PATTERN$m; + } + innerExtract(context, match) { + let targetDate = (0, dayjs_1$j.default)(context.refDate); + const dateKeyword = (match[DATE_GROUP$5] || "").toLowerCase(); + const timeKeyword = (match[TIME_GROUP] || "").toLowerCase(); + let component = context.createParsingComponents(); + switch (dateKeyword) { + case "jetzt": + component = references$4.now(context.reference); + break; + case "heute": + component = references$4.today(context.reference); + break; + case "morgen": + (0, dayjs_2$4.assignTheNextDay)(component, targetDate); + break; + case "übermorgen": + case "uebermorgen": + targetDate = targetDate.add(1, "day"); + (0, dayjs_2$4.assignTheNextDay)(component, targetDate); + break; + case "gestern": + targetDate = targetDate.add(-1, "day"); + (0, dayjs_2$4.assignSimilarDate)(component, targetDate); + (0, dayjs_2$4.implySimilarTime)(component, targetDate); + break; + case "vorgestern": + targetDate = targetDate.add(-2, "day"); + (0, dayjs_2$4.assignSimilarDate)(component, targetDate); + (0, dayjs_2$4.implySimilarTime)(component, targetDate); + break; + default: + if (dateKeyword.match(/letzte\s*nacht/)) { + if (targetDate.hour() > 6) { + targetDate = targetDate.add(-1, "day"); + } + (0, dayjs_2$4.assignSimilarDate)(component, targetDate); + component.imply("hour", 0); + } + break; + } + if (timeKeyword) { + component = DECasualTimeParser_1.default.extractTimeComponents(component, timeKeyword); + } + return component; + } +} +DECasualDateParser$1.default = DECasualDateParser; + +var DEMonthNameLittleEndianParser$1 = {}; + +Object.defineProperty(DEMonthNameLittleEndianParser$1, "__esModule", { value: true }); +const years_1$5 = years; +const constants_1$r = constants$6; +const constants_2$4 = constants$6; +const pattern_1$a = pattern; +const AbstractParserWithWordBoundary_1$A = AbstractParserWithWordBoundary; +const PATTERN$l = new RegExp("(?:am\\s*?)?" + + "(?:den\\s*?)?" + + `([0-9]{1,2})\\.` + + `(?:\\s*(?:bis(?:\\s*(?:am|zum))?|\\-|\\–|\\s)\\s*([0-9]{1,2})\\.?)?\\s*` + + `(${(0, pattern_1$a.matchAnyPattern)(constants_1$r.MONTH_DICTIONARY)})` + + `(?:(?:-|/|,?\\s*)(${constants_2$4.YEAR_PATTERN}(?![^\\s]\\d)))?` + + `(?=\\W|$)`, "i"); +const DATE_GROUP$4 = 1; +const DATE_TO_GROUP$3 = 2; +const MONTH_NAME_GROUP$5 = 3; +const YEAR_GROUP$7 = 4; +class DEMonthNameLittleEndianParser extends AbstractParserWithWordBoundary_1$A.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$l; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const month = constants_1$r.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$5].toLowerCase()]; + const day = parseInt(match[DATE_GROUP$4]); + if (day > 31) { + match.index = match.index + match[DATE_GROUP$4].length; + return null; + } + result.start.assign("month", month); + result.start.assign("day", day); + if (match[YEAR_GROUP$7]) { + const yearNumber = (0, constants_2$4.parseYear)(match[YEAR_GROUP$7]); + result.start.assign("year", yearNumber); + } + else { + const year = (0, years_1$5.findYearClosestToRef)(context.refDate, day, month); + result.start.imply("year", year); + } + if (match[DATE_TO_GROUP$3]) { + const endDate = parseInt(match[DATE_TO_GROUP$3]); + result.end = result.start.clone(); + result.end.assign("day", endDate); + } + return result; + } +} +DEMonthNameLittleEndianParser$1.default = DEMonthNameLittleEndianParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = void 0; +const configurations_1 = configurations; +const chrono_1 = chrono$1; +const SlashDateFormatParser_1 = __importDefault(SlashDateFormatParser$1); +const ISOFormatParser_1 = __importDefault(ISOFormatParser$1); +const DETimeExpressionParser_1 = __importDefault(DETimeExpressionParser$1); +const DEWeekdayParser_1 = __importDefault(DEWeekdayParser$1); +const DEMergeDateRangeRefiner_1 = __importDefault(DEMergeDateRangeRefiner$1); +const DEMergeDateTimeRefiner_1 = __importDefault(DEMergeDateTimeRefiner$1); +const DECasualDateParser_1 = __importDefault(DECasualDateParser$1); +const DECasualTimeParser_1 = __importDefault(DECasualTimeParser$1); +const DEMonthNameLittleEndianParser_1 = __importDefault(DEMonthNameLittleEndianParser$1); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration(true)); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration(littleEndian = true) { + const option = createConfiguration(false, littleEndian); + option.parsers.unshift(new DECasualTimeParser_1.default()); + option.parsers.unshift(new DECasualDateParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration(strictMode = true, littleEndian = true) { + return (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new ISOFormatParser_1.default(), + new SlashDateFormatParser_1.default(littleEndian), + new DETimeExpressionParser_1.default(), + new DEMonthNameLittleEndianParser_1.default(), + new DEWeekdayParser_1.default(), + ], + refiners: [new DEMergeDateRangeRefiner_1.default(), new DEMergeDateTimeRefiner_1.default()], + }, strictMode); +} +exports.createConfiguration = createConfiguration; +}(de)); + +var fr = {}; + +var FRCasualDateParser$1 = {}; + +var __createBinding$3 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault$3 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar$3 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$3(result, mod, k); + __setModuleDefault$3(result, mod); + return result; +}; +var __importDefault$t = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(FRCasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$i = __importDefault$t(require$$0); +const index_1$6 = dist; +const AbstractParserWithWordBoundary_1$z = AbstractParserWithWordBoundary; +const dayjs_2$3 = dayjs; +const references$3 = __importStar$3(casualReferences); +class FRCasualDateParser extends AbstractParserWithWordBoundary_1$z.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(maintenant|aujourd'hui|demain|hier|cette\s*nuit|la\s*veille)(?=\W|$)/i; + } + innerExtract(context, match) { + let targetDate = (0, dayjs_1$i.default)(context.refDate); + const lowerText = match[0].toLowerCase(); + const component = context.createParsingComponents(); + switch (lowerText) { + case "maintenant": + return references$3.now(context.reference); + case "aujourd'hui": + return references$3.today(context.reference); + case "hier": + return references$3.yesterday(context.reference); + case "demain": + return references$3.tomorrow(context.reference); + default: + if (lowerText.match(/cette\s*nuit/)) { + (0, dayjs_2$3.assignSimilarDate)(component, targetDate); + component.imply("hour", 22); + component.imply("meridiem", index_1$6.Meridiem.PM); + } + else if (lowerText.match(/la\s*veille/)) { + targetDate = targetDate.add(-1, "day"); + (0, dayjs_2$3.assignSimilarDate)(component, targetDate); + component.imply("hour", 0); + } + } + return component; + } +} +FRCasualDateParser$1.default = FRCasualDateParser; + +var FRCasualTimeParser$1 = {}; + +Object.defineProperty(FRCasualTimeParser$1, "__esModule", { value: true }); +const index_1$5 = dist; +const AbstractParserWithWordBoundary_1$y = AbstractParserWithWordBoundary; +class FRCasualTimeParser extends AbstractParserWithWordBoundary_1$y.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(cet?)?\s*(matin|soir|après-midi|aprem|a midi|à minuit)(?=\W|$)/i; + } + innerExtract(context, match) { + const suffixLower = match[2].toLowerCase(); + const component = context.createParsingComponents(); + switch (suffixLower) { + case "après-midi": + case "aprem": + component.imply("hour", 14); + component.imply("minute", 0); + component.imply("meridiem", index_1$5.Meridiem.PM); + break; + case "soir": + component.imply("hour", 18); + component.imply("minute", 0); + component.imply("meridiem", index_1$5.Meridiem.PM); + break; + case "matin": + component.imply("hour", 8); + component.imply("minute", 0); + component.imply("meridiem", index_1$5.Meridiem.AM); + break; + case "a midi": + component.imply("hour", 12); + component.imply("minute", 0); + component.imply("meridiem", index_1$5.Meridiem.AM); + break; + case "à minuit": + component.imply("hour", 0); + component.imply("meridiem", index_1$5.Meridiem.AM); + break; + } + return component; + } +} +FRCasualTimeParser$1.default = FRCasualTimeParser; + +var FRTimeExpressionParser$1 = {}; + +Object.defineProperty(FRTimeExpressionParser$1, "__esModule", { value: true }); +const AbstractTimeExpressionParser_1$2 = AbstractTimeExpressionParser$1; +class FRTimeExpressionParser extends AbstractTimeExpressionParser_1$2.AbstractTimeExpressionParser { + primaryPrefix() { + return "(?:(?:[àa])\\s*)?"; + } + followingPhase() { + return "\\s*(?:\\-|\\–|\\~|\\〜|[àa]|\\?)\\s*"; + } + extractPrimaryTimeComponents(context, match) { + if (match[0].match(/^\s*\d{4}\s*$/)) { + return null; + } + return super.extractPrimaryTimeComponents(context, match); + } +} +FRTimeExpressionParser$1.default = FRTimeExpressionParser; + +var FRMergeDateTimeRefiner$1 = {}; + +var __importDefault$s = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(FRMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$4 = __importDefault$s(AbstractMergeDateTimeRefiner); +class FRMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$4.default { + patternBetween() { + return new RegExp("^\\s*(T|à|a|vers|de|,|-)?\\s*$"); + } +} +FRMergeDateTimeRefiner$1.default = FRMergeDateTimeRefiner; + +var FRMergeDateRangeRefiner$1 = {}; + +var __importDefault$r = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(FRMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$5 = __importDefault$r(AbstractMergeDateRangeRefiner$1); +class FRMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$5.default { + patternBetween() { + return /^\s*(à|a|-)\s*$/i; + } +} +FRMergeDateRangeRefiner$1.default = FRMergeDateRangeRefiner; + +var FRWeekdayParser$1 = {}; + +var constants$5 = {}; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseTimeUnits = exports.TIME_UNITS_PATTERN = exports.parseYear = exports.YEAR_PATTERN = exports.parseOrdinalNumberPattern = exports.ORDINAL_NUMBER_PATTERN = exports.parseNumberPattern = exports.NUMBER_PATTERN = exports.TIME_UNIT_DICTIONARY = exports.INTEGER_WORD_DICTIONARY = exports.MONTH_DICTIONARY = exports.WEEKDAY_DICTIONARY = void 0; +const pattern_1 = pattern; +exports.WEEKDAY_DICTIONARY = { + "dimanche": 0, + "dim": 0, + "lundi": 1, + "lun": 1, + "mardi": 2, + "mar": 2, + "mercredi": 3, + "mer": 3, + "jeudi": 4, + "jeu": 4, + "vendredi": 5, + "ven": 5, + "samedi": 6, + "sam": 6, +}; +exports.MONTH_DICTIONARY = { + "janvier": 1, + "jan": 1, + "jan.": 1, + "février": 2, + "fév": 2, + "fév.": 2, + "fevrier": 2, + "fev": 2, + "fev.": 2, + "mars": 3, + "mar": 3, + "mar.": 3, + "avril": 4, + "avr": 4, + "avr.": 4, + "mai": 5, + "juin": 6, + "jun": 6, + "juillet": 7, + "juil": 7, + "jul": 7, + "jul.": 7, + "août": 8, + "aout": 8, + "septembre": 9, + "sep": 9, + "sep.": 9, + "sept": 9, + "sept.": 9, + "octobre": 10, + "oct": 10, + "oct.": 10, + "novembre": 11, + "nov": 11, + "nov.": 11, + "décembre": 12, + "decembre": 12, + "dec": 12, + "dec.": 12, +}; +exports.INTEGER_WORD_DICTIONARY = { + "un": 1, + "deux": 2, + "trois": 3, + "quatre": 4, + "cinq": 5, + "six": 6, + "sept": 7, + "huit": 8, + "neuf": 9, + "dix": 10, + "onze": 11, + "douze": 12, + "treize": 13, +}; +exports.TIME_UNIT_DICTIONARY = { + "sec": "second", + "seconde": "second", + "secondes": "second", + "min": "minute", + "mins": "minute", + "minute": "minute", + "minutes": "minute", + "h": "hour", + "hr": "hour", + "hrs": "hour", + "heure": "hour", + "heures": "hour", + "jour": "d", + "jours": "d", + "semaine": "week", + "semaines": "week", + "mois": "month", + "trimestre": "quarter", + "trimestres": "quarter", + "ans": "year", + "année": "year", + "années": "year", +}; +exports.NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|une?\\b|quelques?|demi-?)`; +function parseNumberPattern(match) { + const num = match.toLowerCase(); + if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) { + return exports.INTEGER_WORD_DICTIONARY[num]; + } + else if (num === "une" || num === "un") { + return 1; + } + else if (num.match(/quelques?/)) { + return 3; + } + else if (num.match(/demi-?/)) { + return 0.5; + } + return parseFloat(num); +} +exports.parseNumberPattern = parseNumberPattern; +exports.ORDINAL_NUMBER_PATTERN = `(?:[0-9]{1,2}(?:er)?)`; +function parseOrdinalNumberPattern(match) { + let num = match.toLowerCase(); + num = num.replace(/(?:er)$/i, ""); + return parseInt(num); +} +exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern; +exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:AC|AD|p\\.\\s*C(?:hr?)?\\.\\s*n\\.)|[1-2][0-9]{3}|[5-9][0-9])`; +function parseYear(match) { + if (/AC/i.test(match)) { + match = match.replace(/BC/i, ""); + return -parseInt(match); + } + if (/AD/i.test(match) || /C/i.test(match)) { + match = match.replace(/[^\d]+/i, ""); + return parseInt(match); + } + let yearNumber = parseInt(match); + if (yearNumber < 100) { + if (yearNumber > 50) { + yearNumber = yearNumber + 1900; + } + else { + yearNumber = yearNumber + 2000; + } + } + return yearNumber; +} +exports.parseYear = parseYear; +const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${(0, pattern_1.matchAnyPattern)(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; +const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); +exports.TIME_UNITS_PATTERN = (0, pattern_1.repeatedTimeunitPattern)("", SINGLE_TIME_UNIT_PATTERN); +function parseTimeUnits(timeunitText) { + const fragments = {}; + let remainingText = timeunitText; + let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + while (match) { + collectDateTimeFragment(fragments, match); + remainingText = remainingText.substring(match[0].length); + match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + } + return fragments; +} +exports.parseTimeUnits = parseTimeUnits; +function collectDateTimeFragment(fragments, match) { + const num = parseNumberPattern(match[1]); + const unit = exports.TIME_UNIT_DICTIONARY[match[2].toLowerCase()]; + fragments[unit] = num; +} +}(constants$5)); + +Object.defineProperty(FRWeekdayParser$1, "__esModule", { value: true }); +const constants_1$q = constants$5; +const pattern_1$9 = pattern; +const AbstractParserWithWordBoundary_1$x = AbstractParserWithWordBoundary; +const weeks_1$2 = weeks; +const PATTERN$k = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + + "(?:(?:ce)\\s*)?" + + `(${(0, pattern_1$9.matchAnyPattern)(constants_1$q.WEEKDAY_DICTIONARY)})` + + "(?:\\s*(?:\\,|\\)|\\)))?" + + "(?:\\s*(dernier|prochain)\\s*)?" + + "(?=\\W|\\d|$)", "i"); +const WEEKDAY_GROUP$2 = 1; +const POSTFIX_GROUP$2 = 2; +class FRWeekdayParser extends AbstractParserWithWordBoundary_1$x.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$k; + } + innerExtract(context, match) { + const dayOfWeek = match[WEEKDAY_GROUP$2].toLowerCase(); + const offset = constants_1$q.WEEKDAY_DICTIONARY[dayOfWeek]; + if (offset === undefined) { + return null; + } + let suffix = match[POSTFIX_GROUP$2]; + suffix = suffix || ""; + suffix = suffix.toLowerCase(); + let modifier = null; + if (suffix == "dernier") { + modifier = "last"; + } + else if (suffix == "prochain") { + modifier = "next"; + } + const date = (0, weeks_1$2.toDayJSWeekday)(context.refDate, offset, modifier); + return context + .createParsingComponents() + .assign("weekday", offset) + .imply("day", date.date()) + .imply("month", date.month() + 1) + .imply("year", date.year()); + } +} +FRWeekdayParser$1.default = FRWeekdayParser; + +var FRSpecificTimeExpressionParser$1 = {}; + +Object.defineProperty(FRSpecificTimeExpressionParser$1, "__esModule", { value: true }); +const index_1$4 = dist; +const FIRST_REG_PATTERN$2 = new RegExp("(^|\\s|T)" + + "(?:(?:[àa])\\s*)?" + + "(\\d{1,2})(?:h|:)?" + + "(?:(\\d{1,2})(?:m|:)?)?" + + "(?:(\\d{1,2})(?:s|:)?)?" + + "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?))?" + + "(?=\\W|$)", "i"); +const SECOND_REG_PATTERN$2 = new RegExp("^\\s*(\\-|\\–|\\~|\\〜|[àa]|\\?)\\s*" + + "(\\d{1,2})(?:h|:)?" + + "(?:(\\d{1,2})(?:m|:)?)?" + + "(?:(\\d{1,2})(?:s|:)?)?" + + "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?))?" + + "(?=\\W|$)", "i"); +const HOUR_GROUP$2 = 2; +const MINUTE_GROUP$2 = 3; +const SECOND_GROUP$2 = 4; +const AM_PM_HOUR_GROUP$2 = 5; +class FRSpecificTimeExpressionParser { + pattern(context) { + return FIRST_REG_PATTERN$2; + } + extract(context, match) { + const result = context.createParsingResult(match.index + match[1].length, match[0].substring(match[1].length)); + if (result.text.match(/^\d{4}$/)) { + match.index += match[0].length; + return null; + } + result.start = FRSpecificTimeExpressionParser.extractTimeComponent(result.start.clone(), match); + if (!result.start) { + match.index += match[0].length; + return null; + } + const remainingText = context.text.substring(match.index + match[0].length); + const secondMatch = SECOND_REG_PATTERN$2.exec(remainingText); + if (secondMatch) { + result.end = FRSpecificTimeExpressionParser.extractTimeComponent(result.start.clone(), secondMatch); + if (result.end) { + result.text += secondMatch[0]; + } + } + return result; + } + static extractTimeComponent(extractingComponents, match) { + let hour = 0; + let minute = 0; + let meridiem = null; + hour = parseInt(match[HOUR_GROUP$2]); + if (match[MINUTE_GROUP$2] != null) { + minute = parseInt(match[MINUTE_GROUP$2]); + } + if (minute >= 60 || hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = index_1$4.Meridiem.PM; + } + if (match[AM_PM_HOUR_GROUP$2] != null) { + if (hour > 12) + return null; + const ampm = match[AM_PM_HOUR_GROUP$2][0].toLowerCase(); + if (ampm == "a") { + meridiem = index_1$4.Meridiem.AM; + if (hour == 12) { + hour = 0; + } + } + if (ampm == "p") { + meridiem = index_1$4.Meridiem.PM; + if (hour != 12) { + hour += 12; + } + } + } + extractingComponents.assign("hour", hour); + extractingComponents.assign("minute", minute); + if (meridiem !== null) { + extractingComponents.assign("meridiem", meridiem); + } + else { + if (hour < 12) { + extractingComponents.imply("meridiem", index_1$4.Meridiem.AM); + } + else { + extractingComponents.imply("meridiem", index_1$4.Meridiem.PM); + } + } + if (match[SECOND_GROUP$2] != null) { + const second = parseInt(match[SECOND_GROUP$2]); + if (second >= 60) + return null; + extractingComponents.assign("second", second); + } + return extractingComponents; + } +} +FRSpecificTimeExpressionParser$1.default = FRSpecificTimeExpressionParser; + +var FRMonthNameLittleEndianParser$1 = {}; + +Object.defineProperty(FRMonthNameLittleEndianParser$1, "__esModule", { value: true }); +const years_1$4 = years; +const constants_1$p = constants$5; +const constants_2$3 = constants$5; +const constants_3$1 = constants$5; +const pattern_1$8 = pattern; +const AbstractParserWithWordBoundary_1$w = AbstractParserWithWordBoundary; +const PATTERN$j = new RegExp("(?:on\\s*?)?" + + `(${constants_3$1.ORDINAL_NUMBER_PATTERN})` + + `(?:\\s*(?:au|\\-|\\–|jusqu'au?|\\s)\\s*(${constants_3$1.ORDINAL_NUMBER_PATTERN}))?` + + `(?:-|/|\\s*(?:de)?\\s*)` + + `(${(0, pattern_1$8.matchAnyPattern)(constants_1$p.MONTH_DICTIONARY)})` + + `(?:(?:-|/|,?\\s*)(${constants_2$3.YEAR_PATTERN}(?![^\\s]\\d)))?` + + `(?=\\W|$)`, "i"); +const DATE_GROUP$3 = 1; +const DATE_TO_GROUP$2 = 2; +const MONTH_NAME_GROUP$4 = 3; +const YEAR_GROUP$6 = 4; +class FRMonthNameLittleEndianParser extends AbstractParserWithWordBoundary_1$w.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$j; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const month = constants_1$p.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$4].toLowerCase()]; + const day = (0, constants_3$1.parseOrdinalNumberPattern)(match[DATE_GROUP$3]); + if (day > 31) { + match.index = match.index + match[DATE_GROUP$3].length; + return null; + } + result.start.assign("month", month); + result.start.assign("day", day); + if (match[YEAR_GROUP$6]) { + const yearNumber = (0, constants_2$3.parseYear)(match[YEAR_GROUP$6]); + result.start.assign("year", yearNumber); + } + else { + const year = (0, years_1$4.findYearClosestToRef)(context.refDate, day, month); + result.start.imply("year", year); + } + if (match[DATE_TO_GROUP$2]) { + const endDate = (0, constants_3$1.parseOrdinalNumberPattern)(match[DATE_TO_GROUP$2]); + result.end = result.start.clone(); + result.end.assign("day", endDate); + } + return result; + } +} +FRMonthNameLittleEndianParser$1.default = FRMonthNameLittleEndianParser; + +var FRTimeUnitAgoFormatParser$2 = {}; + +Object.defineProperty(FRTimeUnitAgoFormatParser$2, "__esModule", { value: true }); +const constants_1$o = constants$5; +const results_1$7 = results; +const AbstractParserWithWordBoundary_1$v = AbstractParserWithWordBoundary; +const timeunits_1$3 = timeunits; +class FRTimeUnitAgoFormatParser$1 extends AbstractParserWithWordBoundary_1$v.AbstractParserWithWordBoundaryChecking { + constructor() { + super(); + } + innerPattern() { + return new RegExp(`il y a\\s*(${constants_1$o.TIME_UNITS_PATTERN})(?=(?:\\W|$))`, "i"); + } + innerExtract(context, match) { + const timeUnits = (0, constants_1$o.parseTimeUnits)(match[1]); + const outputTimeUnits = (0, timeunits_1$3.reverseTimeUnits)(timeUnits); + return results_1$7.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits); + } +} +FRTimeUnitAgoFormatParser$2.default = FRTimeUnitAgoFormatParser$1; + +var FRTimeUnitWithinFormatParser$1 = {}; + +Object.defineProperty(FRTimeUnitWithinFormatParser$1, "__esModule", { value: true }); +const constants_1$n = constants$5; +const results_1$6 = results; +const AbstractParserWithWordBoundary_1$u = AbstractParserWithWordBoundary; +class FRTimeUnitWithinFormatParser extends AbstractParserWithWordBoundary_1$u.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return new RegExp(`(?:dans|en|pour|pendant)\\s*(${constants_1$n.TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); + } + innerExtract(context, match) { + const timeUnits = (0, constants_1$n.parseTimeUnits)(match[1]); + return results_1$6.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } +} +FRTimeUnitWithinFormatParser$1.default = FRTimeUnitWithinFormatParser; + +var FRTimeUnitRelativeFormatParser = {}; + +Object.defineProperty(FRTimeUnitRelativeFormatParser, "__esModule", { value: true }); +const constants_1$m = constants$5; +const results_1$5 = results; +const AbstractParserWithWordBoundary_1$t = AbstractParserWithWordBoundary; +const timeunits_1$2 = timeunits; +const pattern_1$7 = pattern; +class FRTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1$t.AbstractParserWithWordBoundaryChecking { + constructor() { + super(); + } + innerPattern() { + return new RegExp(`(?:les?|la|l'|du|des?)\\s*` + + `(${constants_1$m.NUMBER_PATTERN})?` + + `(?:\\s*(prochaine?s?|derni[eè]re?s?|pass[ée]e?s?|pr[ée]c[ée]dents?|suivante?s?))?` + + `\\s*(${(0, pattern_1$7.matchAnyPattern)(constants_1$m.TIME_UNIT_DICTIONARY)})` + + `(?:\\s*(prochaine?s?|derni[eè]re?s?|pass[ée]e?s?|pr[ée]c[ée]dents?|suivante?s?))?`, "i"); + } + innerExtract(context, match) { + const num = match[1] ? (0, constants_1$m.parseNumberPattern)(match[1]) : 1; + const unit = constants_1$m.TIME_UNIT_DICTIONARY[match[3].toLowerCase()]; + let timeUnits = {}; + timeUnits[unit] = num; + let modifier = match[2] || match[4] || ""; + modifier = modifier.toLowerCase(); + if (!modifier) { + return; + } + if (/derni[eè]re?s?/.test(modifier) || /pass[ée]e?s?/.test(modifier) || /pr[ée]c[ée]dents?/.test(modifier)) { + timeUnits = (0, timeunits_1$2.reverseTimeUnits)(timeUnits); + } + return results_1$5.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } +} +FRTimeUnitRelativeFormatParser.default = FRTimeUnitAgoFormatParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = void 0; +const configurations_1 = configurations; +const chrono_1 = chrono$1; +const FRCasualDateParser_1 = __importDefault(FRCasualDateParser$1); +const FRCasualTimeParser_1 = __importDefault(FRCasualTimeParser$1); +const SlashDateFormatParser_1 = __importDefault(SlashDateFormatParser$1); +const FRTimeExpressionParser_1 = __importDefault(FRTimeExpressionParser$1); +const FRMergeDateTimeRefiner_1 = __importDefault(FRMergeDateTimeRefiner$1); +const FRMergeDateRangeRefiner_1 = __importDefault(FRMergeDateRangeRefiner$1); +const FRWeekdayParser_1 = __importDefault(FRWeekdayParser$1); +const FRSpecificTimeExpressionParser_1 = __importDefault(FRSpecificTimeExpressionParser$1); +const FRMonthNameLittleEndianParser_1 = __importDefault(FRMonthNameLittleEndianParser$1); +const FRTimeUnitAgoFormatParser_1 = __importDefault(FRTimeUnitAgoFormatParser$2); +const FRTimeUnitWithinFormatParser_1 = __importDefault(FRTimeUnitWithinFormatParser$1); +const FRTimeUnitRelativeFormatParser_1 = __importDefault(FRTimeUnitRelativeFormatParser); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration(true)); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration(littleEndian = true) { + const option = createConfiguration(false, littleEndian); + option.parsers.unshift(new FRCasualDateParser_1.default()); + option.parsers.unshift(new FRCasualTimeParser_1.default()); + option.parsers.unshift(new FRTimeUnitRelativeFormatParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration(strictMode = true, littleEndian = true) { + return (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new SlashDateFormatParser_1.default(littleEndian), + new FRMonthNameLittleEndianParser_1.default(), + new FRTimeExpressionParser_1.default(), + new FRSpecificTimeExpressionParser_1.default(), + new FRTimeUnitAgoFormatParser_1.default(), + new FRTimeUnitWithinFormatParser_1.default(), + new FRWeekdayParser_1.default(), + ], + refiners: [new FRMergeDateTimeRefiner_1.default(), new FRMergeDateRangeRefiner_1.default()], + }, strictMode); +} +exports.createConfiguration = createConfiguration; +}(fr)); + +var ja = {}; + +var JPStandardParser$1 = {}; + +var constants$4 = {}; + +Object.defineProperty(constants$4, "__esModule", { value: true }); +constants$4.toHankaku = void 0; +function toHankaku(text) { + return String(text) + .replace(/\u2019/g, "\u0027") + .replace(/\u201D/g, "\u0022") + .replace(/\u3000/g, "\u0020") + .replace(/\uFFE5/g, "\u00A5") + .replace(/[\uFF01\uFF03-\uFF06\uFF08\uFF09\uFF0C-\uFF19\uFF1C-\uFF1F\uFF21-\uFF3B\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5E]/g, alphaNum); +} +constants$4.toHankaku = toHankaku; +function alphaNum(token) { + return String.fromCharCode(token.charCodeAt(0) - 65248); +} + +var __importDefault$q = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(JPStandardParser$1, "__esModule", { value: true }); +const constants_1$l = constants$4; +const years_1$3 = years; +const dayjs_1$h = __importDefault$q(require$$0); +const PATTERN$i = /(?:(?:([同今本])|((昭和|平成|令和)?([0-90-9]{1,4}|元)))年\s*)?([0-90-9]{1,2})月\s*([0-90-9]{1,2})日/i; +const SPECIAL_YEAR_GROUP = 1; +const TYPICAL_YEAR_GROUP = 2; +const ERA_GROUP = 3; +const YEAR_NUMBER_GROUP$1 = 4; +const MONTH_GROUP$3 = 5; +const DAY_GROUP$3 = 6; +class JPStandardParser { + pattern() { + return PATTERN$i; + } + extract(context, match) { + const month = parseInt((0, constants_1$l.toHankaku)(match[MONTH_GROUP$3])); + const day = parseInt((0, constants_1$l.toHankaku)(match[DAY_GROUP$3])); + const components = context.createParsingComponents({ + day: day, + month: month, + }); + if (match[SPECIAL_YEAR_GROUP] && match[SPECIAL_YEAR_GROUP].match("同|今|本")) { + const moment = (0, dayjs_1$h.default)(context.refDate); + components.assign("year", moment.year()); + } + if (match[TYPICAL_YEAR_GROUP]) { + const yearNumText = match[YEAR_NUMBER_GROUP$1]; + let year = yearNumText == "元" ? 1 : parseInt((0, constants_1$l.toHankaku)(yearNumText)); + if (match[ERA_GROUP] == "令和") { + year += 2018; + } + else if (match[ERA_GROUP] == "平成") { + year += 1988; + } + else if (match[ERA_GROUP] == "昭和") { + year += 1925; + } + components.assign("year", year); + } + else { + const year = (0, years_1$3.findYearClosestToRef)(context.refDate, day, month); + components.imply("year", year); + } + return components; + } +} +JPStandardParser$1.default = JPStandardParser; + +var JPMergeDateRangeRefiner$1 = {}; + +var __importDefault$p = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(JPMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$4 = __importDefault$p(AbstractMergeDateRangeRefiner$1); +class JPMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$4.default { + patternBetween() { + return /^\s*(から|ー|-)\s*$/i; + } +} +JPMergeDateRangeRefiner$1.default = JPMergeDateRangeRefiner; + +var JPCasualDateParser$1 = {}; + +var __createBinding$2 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault$2 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar$2 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$2(result, mod, k); + __setModuleDefault$2(result, mod); + return result; +}; +var __importDefault$o = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(JPCasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$g = __importDefault$o(require$$0); +const index_1$3 = dist; +const references$2 = __importStar$2(casualReferences); +const PATTERN$h = /今日|当日|昨日|明日|今夜|今夕|今晩|今朝/i; +class JPCasualDateParser { + pattern() { + return PATTERN$h; + } + extract(context, match) { + const text = match[0]; + const date = (0, dayjs_1$g.default)(context.refDate); + const components = context.createParsingComponents(); + switch (text) { + case "昨日": + return references$2.yesterday(context.reference); + case "明日": + return references$2.tomorrow(context.reference); + case "今日": + case "当日": + return references$2.today(context.reference); + } + if (text == "今夜" || text == "今夕" || text == "今晩") { + components.imply("hour", 22); + components.assign("meridiem", index_1$3.Meridiem.PM); + } + else if (text.match("今朝")) { + components.imply("hour", 6); + components.assign("meridiem", index_1$3.Meridiem.AM); + } + components.assign("day", date.date()); + components.assign("month", date.month() + 1); + components.assign("year", date.year()); + return components; + } +} +JPCasualDateParser$1.default = JPCasualDateParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = void 0; +const JPStandardParser_1 = __importDefault(JPStandardParser$1); +const JPMergeDateRangeRefiner_1 = __importDefault(JPMergeDateRangeRefiner$1); +const JPCasualDateParser_1 = __importDefault(JPCasualDateParser$1); +const chrono_1 = chrono$1; +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration()); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration() { + const option = createConfiguration(); + option.parsers.unshift(new JPCasualDateParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration() { + return { + parsers: [new JPStandardParser_1.default()], + refiners: [new JPMergeDateRangeRefiner_1.default()], + }; +} +exports.createConfiguration = createConfiguration; +}(ja)); + +var pt = {}; + +var PTWeekdayParser$1 = {}; + +var constants$3 = {}; + +Object.defineProperty(constants$3, "__esModule", { value: true }); +constants$3.parseYear = constants$3.YEAR_PATTERN = constants$3.MONTH_DICTIONARY = constants$3.WEEKDAY_DICTIONARY = void 0; +constants$3.WEEKDAY_DICTIONARY = { + "domingo": 0, + "dom": 0, + "segunda": 1, + "segunda-feira": 1, + "seg": 1, + "terça": 2, + "terça-feira": 2, + "ter": 2, + "quarta": 3, + "quarta-feira": 3, + "qua": 3, + "quinta": 4, + "quinta-feira": 4, + "qui": 4, + "sexta": 5, + "sexta-feira": 5, + "sex": 5, + "sábado": 6, + "sabado": 6, + "sab": 6, +}; +constants$3.MONTH_DICTIONARY = { + "janeiro": 1, + "jan": 1, + "jan.": 1, + "fevereiro": 2, + "fev": 2, + "fev.": 2, + "março": 3, + "mar": 3, + "mar.": 3, + "abril": 4, + "abr": 4, + "abr.": 4, + "maio": 5, + "mai": 5, + "mai.": 5, + "junho": 6, + "jun": 6, + "jun.": 6, + "julho": 7, + "jul": 7, + "jul.": 7, + "agosto": 8, + "ago": 8, + "ago.": 8, + "setembro": 9, + "set": 9, + "set.": 9, + "outubro": 10, + "out": 10, + "out.": 10, + "novembro": 11, + "nov": 11, + "nov.": 11, + "dezembro": 12, + "dez": 12, + "dez.": 12, +}; +constants$3.YEAR_PATTERN = "[0-9]{1,4}(?![^\\s]\\d)(?:\\s*[a|d]\\.?\\s*c\\.?|\\s*a\\.?\\s*d\\.?)?"; +function parseYear(match) { + if (match.match(/^[0-9]{1,4}$/)) { + let yearNumber = parseInt(match); + if (yearNumber < 100) { + if (yearNumber > 50) { + yearNumber = yearNumber + 1900; + } + else { + yearNumber = yearNumber + 2000; + } + } + return yearNumber; + } + if (match.match(/a\.?\s*c\.?/i)) { + match = match.replace(/a\.?\s*c\.?/i, ""); + return -parseInt(match); + } + return parseInt(match); +} +constants$3.parseYear = parseYear; + +Object.defineProperty(PTWeekdayParser$1, "__esModule", { value: true }); +const constants_1$k = constants$3; +const pattern_1$6 = pattern; +const AbstractParserWithWordBoundary_1$s = AbstractParserWithWordBoundary; +const weeks_1$1 = weeks; +const PATTERN$g = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + + "(?:(este|esta|passado|pr[oó]ximo)\\s*)?" + + `(${(0, pattern_1$6.matchAnyPattern)(constants_1$k.WEEKDAY_DICTIONARY)})` + + "(?:\\s*(?:\\,|\\)|\\)))?" + + "(?:\\s*(este|esta|passado|pr[óo]ximo)\\s*semana)?" + + "(?=\\W|\\d|$)", "i"); +const PREFIX_GROUP$1 = 1; +const WEEKDAY_GROUP$1 = 2; +const POSTFIX_GROUP$1 = 3; +class PTWeekdayParser extends AbstractParserWithWordBoundary_1$s.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$g; + } + innerExtract(context, match) { + const dayOfWeek = match[WEEKDAY_GROUP$1].toLowerCase(); + const offset = constants_1$k.WEEKDAY_DICTIONARY[dayOfWeek]; + if (offset === undefined) { + return null; + } + const prefix = match[PREFIX_GROUP$1]; + const postfix = match[POSTFIX_GROUP$1]; + let norm = prefix || postfix || ""; + norm = norm.toLowerCase(); + let modifier = null; + if (norm == "passado") { + modifier = "this"; + } + else if (norm == "próximo" || norm == "proximo") { + modifier = "next"; + } + else if (norm == "este") { + modifier = "this"; + } + const date = (0, weeks_1$1.toDayJSWeekday)(context.refDate, offset, modifier); + return context + .createParsingComponents() + .assign("weekday", offset) + .imply("day", date.date()) + .imply("month", date.month() + 1) + .imply("year", date.year()); + } +} +PTWeekdayParser$1.default = PTWeekdayParser; + +var PTTimeExpressionParser$1 = {}; + +Object.defineProperty(PTTimeExpressionParser$1, "__esModule", { value: true }); +const AbstractTimeExpressionParser_1$1 = AbstractTimeExpressionParser$1; +class PTTimeExpressionParser extends AbstractTimeExpressionParser_1$1.AbstractTimeExpressionParser { + primaryPrefix() { + return "(?:(?:ao?|às?|das|da|de|do)\\s*)?"; + } + followingPhase() { + return "\\s*(?:\\-|\\–|\\~|\\〜|a(?:o)?|\\?)\\s*"; + } +} +PTTimeExpressionParser$1.default = PTTimeExpressionParser; + +var PTMergeDateTimeRefiner$1 = {}; + +var __importDefault$n = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(PTMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$3 = __importDefault$n(AbstractMergeDateTimeRefiner); +class PTMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$3.default { + patternBetween() { + return new RegExp("^\\s*(?:,|à)?\\s*$"); + } +} +PTMergeDateTimeRefiner$1.default = PTMergeDateTimeRefiner; + +var PTMergeDateRangeRefiner$1 = {}; + +var __importDefault$m = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(PTMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$3 = __importDefault$m(AbstractMergeDateRangeRefiner$1); +class PTMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$3.default { + patternBetween() { + return /^\s*(?:-)\s*$/i; + } +} +PTMergeDateRangeRefiner$1.default = PTMergeDateRangeRefiner; + +var PTMonthNameLittleEndianParser$1 = {}; + +Object.defineProperty(PTMonthNameLittleEndianParser$1, "__esModule", { value: true }); +const years_1$2 = years; +const constants_1$j = constants$3; +const constants_2$2 = constants$3; +const pattern_1$5 = pattern; +const AbstractParserWithWordBoundary_1$r = AbstractParserWithWordBoundary; +const PATTERN$f = new RegExp(`([0-9]{1,2})(?:º|ª|°)?` + + "(?:\\s*(?:desde|de|\\-|\\–|ao?|\\s)\\s*([0-9]{1,2})(?:º|ª|°)?)?\\s*(?:de)?\\s*" + + `(?:-|/|\\s*(?:de|,)?\\s*)` + + `(${(0, pattern_1$5.matchAnyPattern)(constants_1$j.MONTH_DICTIONARY)})` + + `(?:\\s*(?:de|,)?\\s*(${constants_2$2.YEAR_PATTERN}))?` + + `(?=\\W|$)`, "i"); +const DATE_GROUP$2 = 1; +const DATE_TO_GROUP$1 = 2; +const MONTH_NAME_GROUP$3 = 3; +const YEAR_GROUP$5 = 4; +class PTMonthNameLittleEndianParser extends AbstractParserWithWordBoundary_1$r.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$f; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const month = constants_1$j.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$3].toLowerCase()]; + const day = parseInt(match[DATE_GROUP$2]); + if (day > 31) { + match.index = match.index + match[DATE_GROUP$2].length; + return null; + } + result.start.assign("month", month); + result.start.assign("day", day); + if (match[YEAR_GROUP$5]) { + const yearNumber = (0, constants_2$2.parseYear)(match[YEAR_GROUP$5]); + result.start.assign("year", yearNumber); + } + else { + const year = (0, years_1$2.findYearClosestToRef)(context.refDate, day, month); + result.start.imply("year", year); + } + if (match[DATE_TO_GROUP$1]) { + const endDate = parseInt(match[DATE_TO_GROUP$1]); + result.end = result.start.clone(); + result.end.assign("day", endDate); + } + return result; + } +} +PTMonthNameLittleEndianParser$1.default = PTMonthNameLittleEndianParser; + +var PTCasualDateParser$1 = {}; + +var __createBinding$1 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault$1 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar$1 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$1(result, mod, k); + __setModuleDefault$1(result, mod); + return result; +}; +Object.defineProperty(PTCasualDateParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$q = AbstractParserWithWordBoundary; +const references$1 = __importStar$1(casualReferences); +class PTCasualDateParser extends AbstractParserWithWordBoundary_1$q.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(agora|hoje|amanha|amanhã|ontem)(?=\W|$)/i; + } + innerExtract(context, match) { + const lowerText = match[0].toLowerCase(); + const component = context.createParsingComponents(); + switch (lowerText) { + case "agora": + return references$1.now(context.reference); + case "hoje": + return references$1.today(context.reference); + case "amanha": + case "amanhã": + return references$1.tomorrow(context.reference); + case "ontem": + return references$1.yesterday(context.reference); + } + return component; + } +} +PTCasualDateParser$1.default = PTCasualDateParser; + +var PTCasualTimeParser$1 = {}; + +var __importDefault$l = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(PTCasualTimeParser$1, "__esModule", { value: true }); +const index_1$2 = dist; +const AbstractParserWithWordBoundary_1$p = AbstractParserWithWordBoundary; +const dayjs_1$f = dayjs; +const dayjs_2$2 = __importDefault$l(require$$0); +class PTCasualTimeParser extends AbstractParserWithWordBoundary_1$p.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return /(?:esta\s*)?(manha|manhã|tarde|meia-noite|meio-dia|noite)(?=\W|$)/i; + } + innerExtract(context, match) { + const targetDate = (0, dayjs_2$2.default)(context.refDate); + const component = context.createParsingComponents(); + switch (match[1].toLowerCase()) { + case "tarde": + component.imply("meridiem", index_1$2.Meridiem.PM); + component.imply("hour", 15); + break; + case "noite": + component.imply("meridiem", index_1$2.Meridiem.PM); + component.imply("hour", 22); + break; + case "manha": + case "manhã": + component.imply("meridiem", index_1$2.Meridiem.AM); + component.imply("hour", 6); + break; + case "meia-noite": + (0, dayjs_1$f.assignTheNextDay)(component, targetDate); + component.imply("hour", 0); + component.imply("minute", 0); + component.imply("second", 0); + break; + case "meio-dia": + component.imply("meridiem", index_1$2.Meridiem.AM); + component.imply("hour", 12); + break; + } + return component; + } +} +PTCasualTimeParser$1.default = PTCasualTimeParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = void 0; +const configurations_1 = configurations; +const chrono_1 = chrono$1; +const SlashDateFormatParser_1 = __importDefault(SlashDateFormatParser$1); +const PTWeekdayParser_1 = __importDefault(PTWeekdayParser$1); +const PTTimeExpressionParser_1 = __importDefault(PTTimeExpressionParser$1); +const PTMergeDateTimeRefiner_1 = __importDefault(PTMergeDateTimeRefiner$1); +const PTMergeDateRangeRefiner_1 = __importDefault(PTMergeDateRangeRefiner$1); +const PTMonthNameLittleEndianParser_1 = __importDefault(PTMonthNameLittleEndianParser$1); +const PTCasualDateParser_1 = __importDefault(PTCasualDateParser$1); +const PTCasualTimeParser_1 = __importDefault(PTCasualTimeParser$1); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration(true)); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration(littleEndian = true) { + const option = createConfiguration(false, littleEndian); + option.parsers.push(new PTCasualDateParser_1.default()); + option.parsers.push(new PTCasualTimeParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration(strictMode = true, littleEndian = true) { + return (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new SlashDateFormatParser_1.default(littleEndian), + new PTWeekdayParser_1.default(), + new PTTimeExpressionParser_1.default(), + new PTMonthNameLittleEndianParser_1.default(), + ], + refiners: [new PTMergeDateTimeRefiner_1.default(), new PTMergeDateRangeRefiner_1.default()], + }, strictMode); +} +exports.createConfiguration = createConfiguration; +}(pt)); + +var nl = {}; + +var NLMergeDateRangeRefiner$1 = {}; + +var __importDefault$k = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(NLMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$2 = __importDefault$k(AbstractMergeDateRangeRefiner$1); +class NLMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$2.default { + patternBetween() { + return /^\s*(tot|-)\s*$/i; + } +} +NLMergeDateRangeRefiner$1.default = NLMergeDateRangeRefiner; + +var NLMergeDateTimeRefiner$1 = {}; + +var __importDefault$j = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(NLMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$2 = __importDefault$j(AbstractMergeDateTimeRefiner); +class NLMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$2.default { + patternBetween() { + return new RegExp("^\\s*(om|na|voor|in de|,|-)?\\s*$"); + } +} +NLMergeDateTimeRefiner$1.default = NLMergeDateTimeRefiner; + +var NLCasualDateParser$1 = {}; + +var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(NLCasualDateParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$o = AbstractParserWithWordBoundary; +const references = __importStar(casualReferences); +class NLCasualDateParser extends AbstractParserWithWordBoundary_1$o.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(nu|vandaag|morgen|morgend|gisteren)(?=\W|$)/i; + } + innerExtract(context, match) { + const lowerText = match[0].toLowerCase(); + const component = context.createParsingComponents(); + switch (lowerText) { + case "nu": + return references.now(context.reference); + case "vandaag": + return references.today(context.reference); + case "morgen": + case "morgend": + return references.tomorrow(context.reference); + case "gisteren": + return references.yesterday(context.reference); + } + return component; + } +} +NLCasualDateParser$1.default = NLCasualDateParser; + +var NLCasualTimeParser$1 = {}; + +var __importDefault$i = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(NLCasualTimeParser$1, "__esModule", { value: true }); +const index_1$1 = dist; +const AbstractParserWithWordBoundary_1$n = AbstractParserWithWordBoundary; +const dayjs_1$e = __importDefault$i(require$$0); +const dayjs_2$1 = dayjs; +const DAY_GROUP$2 = 1; +const MOMENT_GROUP = 2; +class NLCasualTimeParser extends AbstractParserWithWordBoundary_1$n.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return /(deze)?\s*(namiddag|avond|middernacht|ochtend|middag|'s middags|'s avonds|'s ochtends)(?=\W|$)/i; + } + innerExtract(context, match) { + const targetDate = (0, dayjs_1$e.default)(context.refDate); + const component = context.createParsingComponents(); + if (match[DAY_GROUP$2] === "deze") { + component.assign("day", context.refDate.getDate()); + component.assign("month", context.refDate.getMonth() + 1); + component.assign("year", context.refDate.getFullYear()); + } + switch (match[MOMENT_GROUP].toLowerCase()) { + case "namiddag": + case "'s namiddags": + component.imply("meridiem", index_1$1.Meridiem.PM); + component.imply("hour", 15); + break; + case "avond": + case "'s avonds'": + component.imply("meridiem", index_1$1.Meridiem.PM); + component.imply("hour", 20); + break; + case "middernacht": + (0, dayjs_2$1.assignTheNextDay)(component, targetDate); + component.imply("hour", 0); + component.imply("minute", 0); + component.imply("second", 0); + break; + case "ochtend": + case "'s ochtends": + component.imply("meridiem", index_1$1.Meridiem.AM); + component.imply("hour", 6); + break; + case "middag": + case "'s middags": + component.imply("meridiem", index_1$1.Meridiem.AM); + component.imply("hour", 12); + break; + } + return component; + } +} +NLCasualTimeParser$1.default = NLCasualTimeParser; + +var NLTimeUnitWithinFormatParser$1 = {}; + +var constants$2 = {}; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseTimeUnits = exports.TIME_UNITS_PATTERN = exports.parseYear = exports.YEAR_PATTERN = exports.parseOrdinalNumberPattern = exports.ORDINAL_NUMBER_PATTERN = exports.parseNumberPattern = exports.NUMBER_PATTERN = exports.TIME_UNIT_DICTIONARY = exports.ORDINAL_WORD_DICTIONARY = exports.INTEGER_WORD_DICTIONARY = exports.MONTH_DICTIONARY = exports.WEEKDAY_DICTIONARY = void 0; +const pattern_1 = pattern; +const years_1 = years; +exports.WEEKDAY_DICTIONARY = { + zondag: 0, + zon: 0, + "zon.": 0, + zo: 0, + "zo.": 0, + maandag: 1, + ma: 1, + "ma.": 1, + dinsdag: 2, + din: 2, + "din.": 2, + di: 2, + "di.": 2, + woensdag: 3, + woe: 3, + "woe.": 3, + wo: 3, + "wo.": 3, + donderdag: 4, + dond: 4, + "dond.": 4, + do: 4, + "do.": 4, + vrijdag: 5, + vrij: 5, + "vrij.": 5, + vr: 5, + "vr.": 5, + zaterdag: 6, + zat: 6, + "zat.": 6, + "za": 6, + "za.": 6, +}; +exports.MONTH_DICTIONARY = { + januari: 1, + jan: 1, + "jan.": 1, + februari: 2, + feb: 2, + "feb.": 2, + maart: 3, + mar: 3, + "mar.": 3, + april: 4, + apr: 4, + "apr.": 4, + mei: 5, + juni: 6, + jun: 6, + "jun.": 6, + juli: 7, + jul: 7, + "jul.": 7, + augustus: 8, + aug: 8, + "aug.": 8, + september: 9, + sep: 9, + "sep.": 9, + sept: 9, + "sept.": 9, + oktober: 10, + okt: 10, + "okt.": 10, + november: 11, + nov: 11, + "nov.": 11, + december: 12, + dec: 12, + "dec.": 12, +}; +exports.INTEGER_WORD_DICTIONARY = { + een: 1, + twee: 2, + drie: 3, + vier: 4, + vijf: 5, + zes: 6, + zeven: 7, + acht: 8, + negen: 9, + tien: 10, + elf: 11, + twaalf: 12, +}; +exports.ORDINAL_WORD_DICTIONARY = { + eerste: 1, + tweede: 2, + derde: 3, + vierde: 4, + vijfde: 5, + zesde: 6, + zevende: 7, + achtste: 8, + negende: 9, + tiende: 10, + elfde: 11, + twaalfde: 12, + dertiende: 13, + veertiende: 14, + vijftiende: 15, + zestiende: 16, + zeventiende: 17, + achttiende: 18, + negentiende: 19, + twintigste: 20, + "eenentwintigste": 21, + "tweeëntwintigste": 22, + "drieentwintigste": 23, + "vierentwintigste": 24, + "vijfentwintigste": 25, + "zesentwintigste": 26, + "zevenentwintigste": 27, + "achtentwintig": 28, + "negenentwintig": 29, + "dertigste": 30, + "eenendertigste": 31, +}; +exports.TIME_UNIT_DICTIONARY = { + sec: "second", + second: "second", + seconden: "second", + min: "minute", + mins: "minute", + minute: "minute", + minuut: "minute", + minuten: "minute", + minuutje: "minute", + h: "hour", + hr: "hour", + hrs: "hour", + uur: "hour", + u: "hour", + uren: "hour", + dag: "d", + dagen: "d", + week: "week", + weken: "week", + maand: "month", + maanden: "month", + jaar: "year", + jr: "year", + jaren: "year", +}; +exports.NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+[\\.,][0-9]+|halve?|half|paar)`; +function parseNumberPattern(match) { + const num = match.toLowerCase(); + if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) { + return exports.INTEGER_WORD_DICTIONARY[num]; + } + else if (num === "paar") { + return 2; + } + else if (num === "half" || num.match(/halve?/)) { + return 0.5; + } + return parseFloat(num.replace(",", ".")); +} +exports.parseNumberPattern = parseNumberPattern; +exports.ORDINAL_NUMBER_PATTERN = `(?:${(0, pattern_1.matchAnyPattern)(exports.ORDINAL_WORD_DICTIONARY)}|[0-9]{1,2}(?:ste|de)?)`; +function parseOrdinalNumberPattern(match) { + let num = match.toLowerCase(); + if (exports.ORDINAL_WORD_DICTIONARY[num] !== undefined) { + return exports.ORDINAL_WORD_DICTIONARY[num]; + } + num = num.replace(/(?:ste|de)$/i, ""); + return parseInt(num); +} +exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern; +exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:voor Christus|na Christus)|[1-2][0-9]{3}|[5-9][0-9])`; +function parseYear(match) { + if (/voor Christus/i.test(match)) { + match = match.replace(/voor Christus/i, ""); + return -parseInt(match); + } + if (/na Christus/i.test(match)) { + match = match.replace(/na Christus/i, ""); + return parseInt(match); + } + const rawYearNumber = parseInt(match); + return (0, years_1.findMostLikelyADYear)(rawYearNumber); +} +exports.parseYear = parseYear; +const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${(0, pattern_1.matchAnyPattern)(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; +const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); +exports.TIME_UNITS_PATTERN = (0, pattern_1.repeatedTimeunitPattern)(`(?:(?:binnen|in)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); +function parseTimeUnits(timeunitText) { + const fragments = {}; + let remainingText = timeunitText; + let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + while (match) { + collectDateTimeFragment(fragments, match); + remainingText = remainingText.substring(match[0].length); + match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); + } + return fragments; +} +exports.parseTimeUnits = parseTimeUnits; +function collectDateTimeFragment(fragments, match) { + const num = parseNumberPattern(match[1]); + const unit = exports.TIME_UNIT_DICTIONARY[match[2].toLowerCase()]; + fragments[unit] = num; +} +}(constants$2)); + +Object.defineProperty(NLTimeUnitWithinFormatParser$1, "__esModule", { value: true }); +const constants_1$i = constants$2; +const results_1$4 = results; +const AbstractParserWithWordBoundary_1$m = AbstractParserWithWordBoundary; +class NLTimeUnitWithinFormatParser extends AbstractParserWithWordBoundary_1$m.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return new RegExp(`(?:binnen|in|binnen de|voor)\\s*` + "(" + constants_1$i.TIME_UNITS_PATTERN + ")" + `(?=\\W|$)`, "i"); + } + innerExtract(context, match) { + const timeUnits = (0, constants_1$i.parseTimeUnits)(match[1]); + return results_1$4.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } +} +NLTimeUnitWithinFormatParser$1.default = NLTimeUnitWithinFormatParser; + +var NLWeekdayParser$1 = {}; + +Object.defineProperty(NLWeekdayParser$1, "__esModule", { value: true }); +const constants_1$h = constants$2; +const pattern_1$4 = pattern; +const AbstractParserWithWordBoundary_1$l = AbstractParserWithWordBoundary; +const weeks_1 = weeks; +const PATTERN$e = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + + "(?:op\\s*?)?" + + "(?:(deze|vorige|volgende)\\s*(?:week\\s*)?)?" + + `(${(0, pattern_1$4.matchAnyPattern)(constants_1$h.WEEKDAY_DICTIONARY)})` + + "(?=\\W|$)", "i"); +const PREFIX_GROUP = 1; +const WEEKDAY_GROUP = 2; +const POSTFIX_GROUP = 3; +class NLWeekdayParser extends AbstractParserWithWordBoundary_1$l.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$e; + } + innerExtract(context, match) { + const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase(); + const offset = constants_1$h.WEEKDAY_DICTIONARY[dayOfWeek]; + const prefix = match[PREFIX_GROUP]; + const postfix = match[POSTFIX_GROUP]; + let modifierWord = prefix || postfix; + modifierWord = modifierWord || ""; + modifierWord = modifierWord.toLowerCase(); + let modifier = null; + if (modifierWord == "vorige") { + modifier = "last"; + } + else if (modifierWord == "volgende") { + modifier = "next"; + } + else if (modifierWord == "deze") { + modifier = "this"; + } + const date = (0, weeks_1.toDayJSWeekday)(context.refDate, offset, modifier); + return context + .createParsingComponents() + .assign("weekday", offset) + .imply("day", date.date()) + .imply("month", date.month() + 1) + .imply("year", date.year()); + } +} +NLWeekdayParser$1.default = NLWeekdayParser; + +var NLMonthNameMiddleEndianParser$1 = {}; + +Object.defineProperty(NLMonthNameMiddleEndianParser$1, "__esModule", { value: true }); +const years_1$1 = years; +const constants_1$g = constants$2; +const constants_2$1 = constants$2; +const constants_3 = constants$2; +const pattern_1$3 = pattern; +const AbstractParserWithWordBoundary_1$k = AbstractParserWithWordBoundary; +const PATTERN$d = new RegExp("(?:on\\s*?)?" + + `(${constants_2$1.ORDINAL_NUMBER_PATTERN})` + + "(?:\\s*" + + "(?:tot|\\-|\\–|until|through|till|\\s)\\s*" + + `(${constants_2$1.ORDINAL_NUMBER_PATTERN})` + + ")?" + + "(?:-|/|\\s*(?:of)?\\s*)" + + "(" + + (0, pattern_1$3.matchAnyPattern)(constants_1$g.MONTH_DICTIONARY) + + ")" + + "(?:" + + "(?:-|/|,?\\s*)" + + `(${constants_3.YEAR_PATTERN}(?![^\\s]\\d))` + + ")?" + + "(?=\\W|$)", "i"); +const MONTH_NAME_GROUP$2 = 3; +const DATE_GROUP$1 = 1; +const DATE_TO_GROUP = 2; +const YEAR_GROUP$4 = 4; +class NLMonthNameMiddleEndianParser extends AbstractParserWithWordBoundary_1$k.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$d; + } + innerExtract(context, match) { + const month = constants_1$g.MONTH_DICTIONARY[match[MONTH_NAME_GROUP$2].toLowerCase()]; + const day = (0, constants_2$1.parseOrdinalNumberPattern)(match[DATE_GROUP$1]); + if (day > 31) { + match.index = match.index + match[DATE_GROUP$1].length; + return null; + } + const components = context.createParsingComponents({ + day: day, + month: month, + }); + if (match[YEAR_GROUP$4]) { + const year = (0, constants_3.parseYear)(match[YEAR_GROUP$4]); + components.assign("year", year); + } + else { + const year = (0, years_1$1.findYearClosestToRef)(context.refDate, day, month); + components.imply("year", year); + } + if (!match[DATE_TO_GROUP]) { + return components; + } + const endDate = (0, constants_2$1.parseOrdinalNumberPattern)(match[DATE_TO_GROUP]); + const result = context.createParsingResult(match.index, match[0]); + result.start = components; + result.end = components.clone(); + result.end.assign("day", endDate); + return result; + } +} +NLMonthNameMiddleEndianParser$1.default = NLMonthNameMiddleEndianParser; + +var NLMonthNameParser$1 = {}; + +Object.defineProperty(NLMonthNameParser$1, "__esModule", { value: true }); +const constants_1$f = constants$2; +const years_1 = years; +const pattern_1$2 = pattern; +const constants_2 = constants$2; +const AbstractParserWithWordBoundary_1$j = AbstractParserWithWordBoundary; +const PATTERN$c = new RegExp(`(${(0, pattern_1$2.matchAnyPattern)(constants_1$f.MONTH_DICTIONARY)})` + + `\\s*` + + `(?:` + + `[,-]?\\s*(${constants_2.YEAR_PATTERN})?` + + ")?" + + "(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)", "i"); +const MONTH_NAME_GROUP$1 = 1; +const YEAR_GROUP$3 = 2; +class NLMonthNameParser extends AbstractParserWithWordBoundary_1$j.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$c; + } + innerExtract(context, match) { + const components = context.createParsingComponents(); + components.imply("day", 1); + const monthName = match[MONTH_NAME_GROUP$1]; + const month = constants_1$f.MONTH_DICTIONARY[monthName.toLowerCase()]; + components.assign("month", month); + if (match[YEAR_GROUP$3]) { + const year = (0, constants_2.parseYear)(match[YEAR_GROUP$3]); + components.assign("year", year); + } + else { + const year = (0, years_1.findYearClosestToRef)(context.refDate, 1, month); + components.imply("year", year); + } + return components; + } +} +NLMonthNameParser$1.default = NLMonthNameParser; + +var NLSlashMonthFormatParser$1 = {}; + +Object.defineProperty(NLSlashMonthFormatParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$i = AbstractParserWithWordBoundary; +const PATTERN$b = new RegExp("([0-9]|0[1-9]|1[012])/([0-9]{4})" + "", "i"); +const MONTH_GROUP$2 = 1; +const YEAR_GROUP$2 = 2; +class NLSlashMonthFormatParser extends AbstractParserWithWordBoundary_1$i.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$b; + } + innerExtract(context, match) { + const year = parseInt(match[YEAR_GROUP$2]); + const month = parseInt(match[MONTH_GROUP$2]); + return context.createParsingComponents().imply("day", 1).assign("month", month).assign("year", year); + } +} +NLSlashMonthFormatParser$1.default = NLSlashMonthFormatParser; + +var NLTimeExpressionParser$1 = {}; + +Object.defineProperty(NLTimeExpressionParser$1, "__esModule", { value: true }); +const AbstractTimeExpressionParser_1 = AbstractTimeExpressionParser$1; +class NLTimeExpressionParser extends AbstractTimeExpressionParser_1.AbstractTimeExpressionParser { + primaryPrefix() { + return "(?:(?:om)\\s*)?"; + } + followingPhase() { + return "\\s*(?:\\-|\\–|\\~|\\〜|om|\\?)\\s*"; + } + primarySuffix() { + return "(?:\\s*(?:uur))?(?!/)(?=\\W|$)"; + } + extractPrimaryTimeComponents(context, match) { + if (match[0].match(/^\s*\d{4}\s*$/)) { + return null; + } + return super.extractPrimaryTimeComponents(context, match); + } +} +NLTimeExpressionParser$1.default = NLTimeExpressionParser; + +var NLCasualYearMonthDayParser$1 = {}; + +Object.defineProperty(NLCasualYearMonthDayParser$1, "__esModule", { value: true }); +const constants_1$e = constants$2; +const pattern_1$1 = pattern; +const AbstractParserWithWordBoundary_1$h = AbstractParserWithWordBoundary; +const PATTERN$a = new RegExp(`([0-9]{4})[\\.\\/\\s]` + + `(?:(${(0, pattern_1$1.matchAnyPattern)(constants_1$e.MONTH_DICTIONARY)})|([0-9]{1,2}))[\\.\\/\\s]` + + `([0-9]{1,2})` + + "(?=\\W|$)", "i"); +const YEAR_NUMBER_GROUP = 1; +const MONTH_NAME_GROUP = 2; +const MONTH_NUMBER_GROUP = 3; +const DATE_NUMBER_GROUP = 4; +class NLCasualYearMonthDayParser extends AbstractParserWithWordBoundary_1$h.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$a; + } + innerExtract(context, match) { + const month = match[MONTH_NUMBER_GROUP] + ? parseInt(match[MONTH_NUMBER_GROUP]) + : constants_1$e.MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()]; + if (month < 1 || month > 12) { + return null; + } + const year = parseInt(match[YEAR_NUMBER_GROUP]); + const day = parseInt(match[DATE_NUMBER_GROUP]); + return { + day: day, + month: month, + year: year, + }; + } +} +NLCasualYearMonthDayParser$1.default = NLCasualYearMonthDayParser; + +var NLCasualDateTimeParser$1 = {}; + +var __importDefault$h = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(NLCasualDateTimeParser$1, "__esModule", { value: true }); +const AbstractParserWithWordBoundary_1$g = AbstractParserWithWordBoundary; +const index_1 = dist; +const dayjs_1$d = dayjs; +const dayjs_2 = __importDefault$h(require$$0); +const DATE_GROUP = 1; +const TIME_OF_DAY_GROUP = 2; +class NLCasualDateTimeParser extends AbstractParserWithWordBoundary_1$g.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return /(gisteren|morgen|van)(ochtend|middag|namiddag|avond|nacht)(?=\W|$)/i; + } + innerExtract(context, match) { + const dateText = match[DATE_GROUP].toLowerCase(); + const timeText = match[TIME_OF_DAY_GROUP].toLowerCase(); + const component = context.createParsingComponents(); + const targetDate = (0, dayjs_2.default)(context.refDate); + switch (dateText) { + case "gisteren": + (0, dayjs_1$d.assignSimilarDate)(component, targetDate.add(-1, "day")); + break; + case "van": + (0, dayjs_1$d.assignSimilarDate)(component, targetDate); + break; + case "morgen": + (0, dayjs_1$d.assignTheNextDay)(component, targetDate); + break; + } + switch (timeText) { + case "ochtend": + component.imply("meridiem", index_1.Meridiem.AM); + component.imply("hour", 6); + break; + case "middag": + component.imply("meridiem", index_1.Meridiem.AM); + component.imply("hour", 12); + break; + case "namiddag": + component.imply("meridiem", index_1.Meridiem.PM); + component.imply("hour", 15); + break; + case "avond": + component.imply("meridiem", index_1.Meridiem.PM); + component.imply("hour", 20); + break; + } + return component; + } +} +NLCasualDateTimeParser$1.default = NLCasualDateTimeParser; + +var NLTimeUnitCasualRelativeFormatParser$1 = {}; + +Object.defineProperty(NLTimeUnitCasualRelativeFormatParser$1, "__esModule", { value: true }); +const constants_1$d = constants$2; +const results_1$3 = results; +const AbstractParserWithWordBoundary_1$f = AbstractParserWithWordBoundary; +const timeunits_1$1 = timeunits; +const PATTERN$9 = new RegExp(`(deze|vorige|afgelopen|komende|over|\\+|-)\\s*(${constants_1$d.TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); +class NLTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundary_1$f.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$9; + } + innerExtract(context, match) { + const prefix = match[1].toLowerCase(); + let timeUnits = (0, constants_1$d.parseTimeUnits)(match[2]); + switch (prefix) { + case "vorige": + case "afgelopen": + case "-": + timeUnits = (0, timeunits_1$1.reverseTimeUnits)(timeUnits); + break; + } + return results_1$3.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } +} +NLTimeUnitCasualRelativeFormatParser$1.default = NLTimeUnitCasualRelativeFormatParser; + +var NLRelativeDateFormatParser$1 = {}; + +var __importDefault$g = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(NLRelativeDateFormatParser$1, "__esModule", { value: true }); +const constants_1$c = constants$2; +const results_1$2 = results; +const dayjs_1$c = __importDefault$g(require$$0); +const AbstractParserWithWordBoundary_1$e = AbstractParserWithWordBoundary; +const pattern_1 = pattern; +const PATTERN$8 = new RegExp(`(dit|deze|komende|volgend|volgende|afgelopen|vorige)\\s*(${(0, pattern_1.matchAnyPattern)(constants_1$c.TIME_UNIT_DICTIONARY)})(?=\\s*)` + + "(?=\\W|$)", "i"); +const MODIFIER_WORD_GROUP = 1; +const RELATIVE_WORD_GROUP = 2; +class NLRelativeDateFormatParser extends AbstractParserWithWordBoundary_1$e.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$8; + } + innerExtract(context, match) { + const modifier = match[MODIFIER_WORD_GROUP].toLowerCase(); + const unitWord = match[RELATIVE_WORD_GROUP].toLowerCase(); + const timeunit = constants_1$c.TIME_UNIT_DICTIONARY[unitWord]; + if (modifier == "volgend" || modifier == "volgende" || modifier == "komende") { + const timeUnits = {}; + timeUnits[timeunit] = 1; + return results_1$2.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } + if (modifier == "afgelopen" || modifier == "vorige") { + const timeUnits = {}; + timeUnits[timeunit] = -1; + return results_1$2.ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + } + const components = context.createParsingComponents(); + let date = (0, dayjs_1$c.default)(context.reference.instant); + if (unitWord.match(/week/i)) { + date = date.add(-date.get("d"), "d"); + components.imply("day", date.date()); + components.imply("month", date.month() + 1); + components.imply("year", date.year()); + } + else if (unitWord.match(/maand/i)) { + date = date.add(-date.date() + 1, "d"); + components.imply("day", date.date()); + components.assign("year", date.year()); + components.assign("month", date.month() + 1); + } + else if (unitWord.match(/jaar/i)) { + date = date.add(-date.date() + 1, "d"); + date = date.add(-date.month(), "month"); + components.imply("day", date.date()); + components.imply("month", date.month() + 1); + components.assign("year", date.year()); + } + return components; + } +} +NLRelativeDateFormatParser$1.default = NLRelativeDateFormatParser; + +var NLTimeUnitAgoFormatParser$1 = {}; + +Object.defineProperty(NLTimeUnitAgoFormatParser$1, "__esModule", { value: true }); +const constants_1$b = constants$2; +const results_1$1 = results; +const AbstractParserWithWordBoundary_1$d = AbstractParserWithWordBoundary; +const timeunits_1 = timeunits; +const PATTERN$7 = new RegExp("" + "(" + constants_1$b.TIME_UNITS_PATTERN + ")" + "(?:geleden|voor|eerder)(?=(?:\\W|$))", "i"); +const STRICT_PATTERN$1 = new RegExp("" + "(" + constants_1$b.TIME_UNITS_PATTERN + ")" + "geleden(?=(?:\\W|$))", "i"); +class NLTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1$d.AbstractParserWithWordBoundaryChecking { + constructor(strictMode) { + super(); + this.strictMode = strictMode; + } + innerPattern() { + return this.strictMode ? STRICT_PATTERN$1 : PATTERN$7; + } + innerExtract(context, match) { + const timeUnits = (0, constants_1$b.parseTimeUnits)(match[1]); + const outputTimeUnits = (0, timeunits_1.reverseTimeUnits)(timeUnits); + return results_1$1.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits); + } +} +NLTimeUnitAgoFormatParser$1.default = NLTimeUnitAgoFormatParser; + +var NLTimeUnitLaterFormatParser$1 = {}; + +Object.defineProperty(NLTimeUnitLaterFormatParser$1, "__esModule", { value: true }); +const constants_1$a = constants$2; +const results_1 = results; +const AbstractParserWithWordBoundary_1$c = AbstractParserWithWordBoundary; +const PATTERN$6 = new RegExp("" + "(" + constants_1$a.TIME_UNITS_PATTERN + ")" + "(later|na|vanaf nu|voortaan|vooruit|uit)" + "(?=(?:\\W|$))", "i"); +const STRICT_PATTERN = new RegExp("" + "(" + constants_1$a.TIME_UNITS_PATTERN + ")" + "(later|vanaf nu)" + "(?=(?:\\W|$))", "i"); +const GROUP_NUM_TIMEUNITS = 1; +class NLTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1$c.AbstractParserWithWordBoundaryChecking { + constructor(strictMode) { + super(); + this.strictMode = strictMode; + } + innerPattern() { + return this.strictMode ? STRICT_PATTERN : PATTERN$6; + } + innerExtract(context, match) { + const fragments = (0, constants_1$a.parseTimeUnits)(match[GROUP_NUM_TIMEUNITS]); + return results_1.ParsingComponents.createRelativeFromReference(context.reference, fragments); + } +} +NLTimeUnitLaterFormatParser$1.default = NLTimeUnitLaterFormatParser; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = void 0; +const configurations_1 = configurations; +const chrono_1 = chrono$1; +const NLMergeDateRangeRefiner_1 = __importDefault(NLMergeDateRangeRefiner$1); +const NLMergeDateTimeRefiner_1 = __importDefault(NLMergeDateTimeRefiner$1); +const NLCasualDateParser_1 = __importDefault(NLCasualDateParser$1); +const NLCasualTimeParser_1 = __importDefault(NLCasualTimeParser$1); +const SlashDateFormatParser_1 = __importDefault(SlashDateFormatParser$1); +const NLTimeUnitWithinFormatParser_1 = __importDefault(NLTimeUnitWithinFormatParser$1); +const NLWeekdayParser_1 = __importDefault(NLWeekdayParser$1); +const NLMonthNameMiddleEndianParser_1 = __importDefault(NLMonthNameMiddleEndianParser$1); +const NLMonthNameParser_1 = __importDefault(NLMonthNameParser$1); +const NLSlashMonthFormatParser_1 = __importDefault(NLSlashMonthFormatParser$1); +const NLTimeExpressionParser_1 = __importDefault(NLTimeExpressionParser$1); +const NLCasualYearMonthDayParser_1 = __importDefault(NLCasualYearMonthDayParser$1); +const NLCasualDateTimeParser_1 = __importDefault(NLCasualDateTimeParser$1); +const NLTimeUnitCasualRelativeFormatParser_1 = __importDefault(NLTimeUnitCasualRelativeFormatParser$1); +const NLRelativeDateFormatParser_1 = __importDefault(NLRelativeDateFormatParser$1); +const NLTimeUnitAgoFormatParser_1 = __importDefault(NLTimeUnitAgoFormatParser$1); +const NLTimeUnitLaterFormatParser_1 = __importDefault(NLTimeUnitLaterFormatParser$1); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration(true)); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration(littleEndian = true) { + const option = createConfiguration(false, littleEndian); + option.parsers.unshift(new NLCasualDateParser_1.default()); + option.parsers.unshift(new NLCasualTimeParser_1.default()); + option.parsers.unshift(new NLCasualDateTimeParser_1.default()); + option.parsers.unshift(new NLMonthNameParser_1.default()); + option.parsers.unshift(new NLRelativeDateFormatParser_1.default()); + option.parsers.unshift(new NLTimeUnitCasualRelativeFormatParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration(strictMode = true, littleEndian = true) { + return (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new SlashDateFormatParser_1.default(littleEndian), + new NLTimeUnitWithinFormatParser_1.default(), + new NLMonthNameMiddleEndianParser_1.default(), + new NLMonthNameParser_1.default(), + new NLWeekdayParser_1.default(), + new NLCasualYearMonthDayParser_1.default(), + new NLSlashMonthFormatParser_1.default(), + new NLTimeExpressionParser_1.default(strictMode), + new NLTimeUnitAgoFormatParser_1.default(strictMode), + new NLTimeUnitLaterFormatParser_1.default(strictMode), + ], + refiners: [new NLMergeDateTimeRefiner_1.default(), new NLMergeDateRangeRefiner_1.default()], + }, strictMode); +} +exports.createConfiguration = createConfiguration; +}(nl)); + +var zh = {}; + +var hant = {}; + +var ZHHantCasualDateParser$1 = {}; + +var __importDefault$f = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantCasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$b = __importDefault$f(require$$0); +const AbstractParserWithWordBoundary_1$b = AbstractParserWithWordBoundary; +const NOW_GROUP$1 = 1; +const DAY_GROUP_1$3 = 2; +const TIME_GROUP_1$1 = 3; +const TIME_GROUP_2$1 = 4; +const DAY_GROUP_3$3 = 5; +const TIME_GROUP_3$1 = 6; +class ZHHantCasualDateParser extends AbstractParserWithWordBoundary_1$b.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return new RegExp("(而家|立(?:刻|即)|即刻)|" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(早|朝|晚)|" + + "(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(?:日|天)" + + "(?:[\\s|,|,]*)" + + "(?:(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?", "i"); + } + innerExtract(context, match) { + const index = match.index; + const result = context.createParsingResult(index, match[0]); + const refMoment = (0, dayjs_1$b.default)(context.refDate); + let startMoment = refMoment; + if (match[NOW_GROUP$1]) { + result.start.imply("hour", refMoment.hour()); + result.start.imply("minute", refMoment.minute()); + result.start.imply("second", refMoment.second()); + result.start.imply("millisecond", refMoment.millisecond()); + } + else if (match[DAY_GROUP_1$3]) { + const day1 = match[DAY_GROUP_1$3]; + const time1 = match[TIME_GROUP_1$1]; + if (day1 == "明" || day1 == "聽") { + if (refMoment.hour() > 1) { + startMoment = startMoment.add(1, "day"); + } + } + else if (day1 == "昨" || day1 == "尋" || day1 == "琴") { + startMoment = startMoment.add(-1, "day"); + } + else if (day1 == "前") { + startMoment = startMoment.add(-2, "day"); + } + else if (day1 == "大前") { + startMoment = startMoment.add(-3, "day"); + } + else if (day1 == "後") { + startMoment = startMoment.add(2, "day"); + } + else if (day1 == "大後") { + startMoment = startMoment.add(3, "day"); + } + if (time1 == "早" || time1 == "朝") { + result.start.imply("hour", 6); + } + else if (time1 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + } + else if (match[TIME_GROUP_2$1]) { + const timeString2 = match[TIME_GROUP_2$1]; + const time2 = timeString2[0]; + if (time2 == "早" || time2 == "朝" || time2 == "上") { + result.start.imply("hour", 6); + } + else if (time2 == "下" || time2 == "晏") { + result.start.imply("hour", 15); + result.start.imply("meridiem", 1); + } + else if (time2 == "中") { + result.start.imply("hour", 12); + result.start.imply("meridiem", 1); + } + else if (time2 == "夜" || time2 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + else if (time2 == "凌") { + result.start.imply("hour", 0); + } + } + else if (match[DAY_GROUP_3$3]) { + const day3 = match[DAY_GROUP_3$3]; + if (day3 == "明" || day3 == "聽") { + if (refMoment.hour() > 1) { + startMoment = startMoment.add(1, "day"); + } + } + else if (day3 == "昨" || day3 == "尋" || day3 == "琴") { + startMoment = startMoment.add(-1, "day"); + } + else if (day3 == "前") { + startMoment = startMoment.add(-2, "day"); + } + else if (day3 == "大前") { + startMoment = startMoment.add(-3, "day"); + } + else if (day3 == "後") { + startMoment = startMoment.add(2, "day"); + } + else if (day3 == "大後") { + startMoment = startMoment.add(3, "day"); + } + const timeString3 = match[TIME_GROUP_3$1]; + if (timeString3) { + const time3 = timeString3[0]; + if (time3 == "早" || time3 == "朝" || time3 == "上") { + result.start.imply("hour", 6); + } + else if (time3 == "下" || time3 == "晏") { + result.start.imply("hour", 15); + result.start.imply("meridiem", 1); + } + else if (time3 == "中") { + result.start.imply("hour", 12); + result.start.imply("meridiem", 1); + } + else if (time3 == "夜" || time3 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + else if (time3 == "凌") { + result.start.imply("hour", 0); + } + } + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + return result; + } +} +ZHHantCasualDateParser$1.default = ZHHantCasualDateParser; + +var ZHHantDateParser$1 = {}; + +var constants$1 = {}; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.zhStringToYear = exports.zhStringToNumber = exports.WEEKDAY_OFFSET = exports.NUMBER = void 0; +exports.NUMBER = { + "零": 0, + "一": 1, + "二": 2, + "兩": 2, + "三": 3, + "四": 4, + "五": 5, + "六": 6, + "七": 7, + "八": 8, + "九": 9, + "十": 10, + "廿": 20, + "卅": 30, +}; +exports.WEEKDAY_OFFSET = { + "天": 0, + "日": 0, + "一": 1, + "二": 2, + "三": 3, + "四": 4, + "五": 5, + "六": 6, +}; +function zhStringToNumber(text) { + let number = 0; + for (let i = 0; i < text.length; i++) { + const char = text[i]; + if (char === "十") { + number = number === 0 ? exports.NUMBER[char] : number * exports.NUMBER[char]; + } + else { + number += exports.NUMBER[char]; + } + } + return number; +} +exports.zhStringToNumber = zhStringToNumber; +function zhStringToYear(text) { + let string = ""; + for (let i = 0; i < text.length; i++) { + const char = text[i]; + string = string + exports.NUMBER[char]; + } + return parseInt(string); +} +exports.zhStringToYear = zhStringToYear; +}(constants$1)); + +var __importDefault$e = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantDateParser$1, "__esModule", { value: true }); +const dayjs_1$a = __importDefault$e(require$$0); +const AbstractParserWithWordBoundary_1$a = AbstractParserWithWordBoundary; +const constants_1$9 = constants$1; +const YEAR_GROUP$1 = 1; +const MONTH_GROUP$1 = 2; +const DAY_GROUP$1 = 3; +class ZHHantDateParser extends AbstractParserWithWordBoundary_1$a.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return new RegExp("(" + + "\\d{2,4}|" + + "[" + Object.keys(constants_1$9.NUMBER).join("") + "]{4}|" + + "[" + Object.keys(constants_1$9.NUMBER).join("") + "]{2}" + + ")?" + + "(?:\\s*)" + + "(?:年)?" + + "(?:[\\s|,|,]*)" + + "(" + + "\\d{1,2}|" + + "[" + Object.keys(constants_1$9.NUMBER).join("") + "]{1,2}" + + ")" + + "(?:\\s*)" + + "(?:月)" + + "(?:\\s*)" + + "(" + + "\\d{1,2}|" + + "[" + Object.keys(constants_1$9.NUMBER).join("") + "]{1,2}" + + ")?" + + "(?:\\s*)" + + "(?:日|號)?"); + } + innerExtract(context, match) { + const startMoment = (0, dayjs_1$a.default)(context.refDate); + const result = context.createParsingResult(match.index, match[0]); + let month = parseInt(match[MONTH_GROUP$1]); + if (isNaN(month)) + month = (0, constants_1$9.zhStringToNumber)(match[MONTH_GROUP$1]); + result.start.assign("month", month); + if (match[DAY_GROUP$1]) { + let day = parseInt(match[DAY_GROUP$1]); + if (isNaN(day)) + day = (0, constants_1$9.zhStringToNumber)(match[DAY_GROUP$1]); + result.start.assign("day", day); + } + else { + result.start.imply("day", startMoment.date()); + } + if (match[YEAR_GROUP$1]) { + let year = parseInt(match[YEAR_GROUP$1]); + if (isNaN(year)) + year = (0, constants_1$9.zhStringToYear)(match[YEAR_GROUP$1]); + result.start.assign("year", year); + } + else { + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHantDateParser$1.default = ZHHantDateParser; + +var ZHHantDeadlineFormatParser$1 = {}; + +var __importDefault$d = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantDeadlineFormatParser$1, "__esModule", { value: true }); +const dayjs_1$9 = __importDefault$d(require$$0); +const AbstractParserWithWordBoundary_1$9 = AbstractParserWithWordBoundary; +const constants_1$8 = constants$1; +const PATTERN$5 = new RegExp("(\\d+|[" + + Object.keys(constants_1$8.NUMBER).join("") + + "]+|半|幾)(?:\\s*)" + + "(?:個)?" + + "(秒(?:鐘)?|分鐘|小時|鐘|日|天|星期|禮拜|月|年)" + + "(?:(?:之|過)?後|(?:之)?內)", "i"); +const NUMBER_GROUP$1 = 1; +const UNIT_GROUP$1 = 2; +class ZHHantDeadlineFormatParser extends AbstractParserWithWordBoundary_1$9.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$5; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + let number = parseInt(match[NUMBER_GROUP$1]); + if (isNaN(number)) { + number = (0, constants_1$8.zhStringToNumber)(match[NUMBER_GROUP$1]); + } + if (isNaN(number)) { + const string = match[NUMBER_GROUP$1]; + if (string === "幾") { + number = 3; + } + else if (string === "半") { + number = 0.5; + } + else { + return null; + } + } + let date = (0, dayjs_1$9.default)(context.refDate); + const unit = match[UNIT_GROUP$1]; + const unitAbbr = unit[0]; + if (unitAbbr.match(/[日天星禮月年]/)) { + if (unitAbbr == "日" || unitAbbr == "天") { + date = date.add(number, "d"); + } + else if (unitAbbr == "星" || unitAbbr == "禮") { + date = date.add(number * 7, "d"); + } + else if (unitAbbr == "月") { + date = date.add(number, "month"); + } + else if (unitAbbr == "年") { + date = date.add(number, "year"); + } + result.start.assign("year", date.year()); + result.start.assign("month", date.month() + 1); + result.start.assign("day", date.date()); + return result; + } + if (unitAbbr == "秒") { + date = date.add(number, "second"); + } + else if (unitAbbr == "分") { + date = date.add(number, "minute"); + } + else if (unitAbbr == "小" || unitAbbr == "鐘") { + date = date.add(number, "hour"); + } + result.start.imply("year", date.year()); + result.start.imply("month", date.month() + 1); + result.start.imply("day", date.date()); + result.start.assign("hour", date.hour()); + result.start.assign("minute", date.minute()); + result.start.assign("second", date.second()); + return result; + } +} +ZHHantDeadlineFormatParser$1.default = ZHHantDeadlineFormatParser; + +var ZHHantRelationWeekdayParser$1 = {}; + +var __importDefault$c = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantRelationWeekdayParser$1, "__esModule", { value: true }); +const dayjs_1$8 = __importDefault$c(require$$0); +const AbstractParserWithWordBoundary_1$8 = AbstractParserWithWordBoundary; +const constants_1$7 = constants$1; +const PATTERN$4 = new RegExp("(?上|今|下|這|呢)(?:個)?(?:星期|禮拜|週)(?" + Object.keys(constants_1$7.WEEKDAY_OFFSET).join("|") + ")"); +class ZHHantRelationWeekdayParser extends AbstractParserWithWordBoundary_1$8.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$4; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const dayOfWeek = match.groups.weekday; + const offset = constants_1$7.WEEKDAY_OFFSET[dayOfWeek]; + if (offset === undefined) + return null; + let modifier = null; + const prefix = match.groups.prefix; + if (prefix == "上") { + modifier = "last"; + } + else if (prefix == "下") { + modifier = "next"; + } + else if (prefix == "今" || prefix == "這" || prefix == "呢") { + modifier = "this"; + } + let startMoment = (0, dayjs_1$8.default)(context.refDate); + let startMomentFixed = false; + const refOffset = startMoment.day(); + if (modifier == "last" || modifier == "past") { + startMoment = startMoment.day(offset - 7); + startMomentFixed = true; + } + else if (modifier == "next") { + startMoment = startMoment.day(offset + 7); + startMomentFixed = true; + } + else if (modifier == "this") { + startMoment = startMoment.day(offset); + } + else { + if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset - 7); + } + else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset + 7); + } + else { + startMoment = startMoment.day(offset); + } + } + result.start.assign("weekday", offset); + if (startMomentFixed) { + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHantRelationWeekdayParser$1.default = ZHHantRelationWeekdayParser; + +var ZHHantTimeExpressionParser$1 = {}; + +var __importDefault$b = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantTimeExpressionParser$1, "__esModule", { value: true }); +const dayjs_1$7 = __importDefault$b(require$$0); +const AbstractParserWithWordBoundary_1$7 = AbstractParserWithWordBoundary; +const constants_1$6 = constants$1; +const FIRST_REG_PATTERN$1 = new RegExp("(?:由|從|自)?" + + "(?:" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(早|朝|晚)|" + + "(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(?:日|天)" + + "(?:[\\s,,]*)" + + "(?:(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" + + ")?" + + "(?:[\\s,,]*)" + + "(?:(\\d+|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)(?:\\s*)(?:點|時|:|:)" + + "(?:\\s*)" + + "(\\d+|半|正|整|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)?(?:\\s*)(?:分|:|:)?" + + "(?:\\s*)" + + "(\\d+|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)?(?:\\s*)(?:秒)?)" + + "(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i"); +const SECOND_REG_PATTERN$1 = new RegExp("(?:^\\s*(?:到|至|\\-|\\–|\\~|\\〜)\\s*)" + + "(?:" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(早|朝|晚)|" + + "(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|後|大後|聽|昨|尋|琴)(?:日|天)" + + "(?:[\\s,,]*)" + + "(?:(上(?:午|晝)|朝(?:早)|早(?:上)|下(?:午|晝)|晏(?:晝)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" + + ")?" + + "(?:[\\s,,]*)" + + "(?:(\\d+|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)(?:\\s*)(?:點|時|:|:)" + + "(?:\\s*)" + + "(\\d+|半|正|整|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)?(?:\\s*)(?:分|:|:)?" + + "(?:\\s*)" + + "(\\d+|[" + + Object.keys(constants_1$6.NUMBER).join("") + + "]+)?(?:\\s*)(?:秒)?)" + + "(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i"); +const DAY_GROUP_1$2 = 1; +const ZH_AM_PM_HOUR_GROUP_1$1 = 2; +const ZH_AM_PM_HOUR_GROUP_2$1 = 3; +const DAY_GROUP_3$2 = 4; +const ZH_AM_PM_HOUR_GROUP_3$1 = 5; +const HOUR_GROUP$1 = 6; +const MINUTE_GROUP$1 = 7; +const SECOND_GROUP$1 = 8; +const AM_PM_HOUR_GROUP$1 = 9; +class ZHHantTimeExpressionParser extends AbstractParserWithWordBoundary_1$7.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return FIRST_REG_PATTERN$1; + } + innerExtract(context, match) { + if (match.index > 0 && context.text[match.index - 1].match(/\w/)) { + return null; + } + const refMoment = (0, dayjs_1$7.default)(context.refDate); + const result = context.createParsingResult(match.index, match[0]); + const startMoment = refMoment.clone(); + if (match[DAY_GROUP_1$2]) { + var day1 = match[DAY_GROUP_1$2]; + if (day1 == "明" || day1 == "聽") { + if (refMoment.hour() > 1) { + startMoment.add(1, "day"); + } + } + else if (day1 == "昨" || day1 == "尋" || day1 == "琴") { + startMoment.add(-1, "day"); + } + else if (day1 == "前") { + startMoment.add(-2, "day"); + } + else if (day1 == "大前") { + startMoment.add(-3, "day"); + } + else if (day1 == "後") { + startMoment.add(2, "day"); + } + else if (day1 == "大後") { + startMoment.add(3, "day"); + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else if (match[DAY_GROUP_3$2]) { + var day3 = match[DAY_GROUP_3$2]; + if (day3 == "明" || day3 == "聽") { + startMoment.add(1, "day"); + } + else if (day3 == "昨" || day3 == "尋" || day3 == "琴") { + startMoment.add(-1, "day"); + } + else if (day3 == "前") { + startMoment.add(-2, "day"); + } + else if (day3 == "大前") { + startMoment.add(-3, "day"); + } + else if (day3 == "後") { + startMoment.add(2, "day"); + } + else if (day3 == "大後") { + startMoment.add(3, "day"); + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + let hour = 0; + let minute = 0; + let meridiem = -1; + if (match[SECOND_GROUP$1]) { + var second = parseInt(match[SECOND_GROUP$1]); + if (isNaN(second)) { + second = (0, constants_1$6.zhStringToNumber)(match[SECOND_GROUP$1]); + } + if (second >= 60) + return null; + result.start.assign("second", second); + } + hour = parseInt(match[HOUR_GROUP$1]); + if (isNaN(hour)) { + hour = (0, constants_1$6.zhStringToNumber)(match[HOUR_GROUP$1]); + } + if (match[MINUTE_GROUP$1]) { + if (match[MINUTE_GROUP$1] == "半") { + minute = 30; + } + else if (match[MINUTE_GROUP$1] == "正" || match[MINUTE_GROUP$1] == "整") { + minute = 0; + } + else { + minute = parseInt(match[MINUTE_GROUP$1]); + if (isNaN(minute)) { + minute = (0, constants_1$6.zhStringToNumber)(match[MINUTE_GROUP$1]); + } + } + } + else if (hour > 100) { + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (minute >= 60) { + return null; + } + if (hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = 1; + } + if (match[AM_PM_HOUR_GROUP$1]) { + if (hour > 12) + return null; + var ampm = match[AM_PM_HOUR_GROUP$1][0].toLowerCase(); + if (ampm == "a") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + if (ampm == "p") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_1$1]) { + var zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1$1]; + var zhAMPM1 = zhAMPMString1[0]; + if (zhAMPM1 == "朝" || zhAMPM1 == "早") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM1 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_2$1]) { + var zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2$1]; + var zhAMPM2 = zhAMPMString2[0]; + if (zhAMPM2 == "上" || zhAMPM2 == "朝" || zhAMPM2 == "早" || zhAMPM2 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM2 == "下" || zhAMPM2 == "晏" || zhAMPM2 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_3$1]) { + var zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3$1]; + var zhAMPM3 = zhAMPMString3[0]; + if (zhAMPM3 == "上" || zhAMPM3 == "朝" || zhAMPM3 == "早" || zhAMPM3 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM3 == "下" || zhAMPM3 == "晏" || zhAMPM3 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + result.start.assign("hour", hour); + result.start.assign("minute", minute); + if (meridiem >= 0) { + result.start.assign("meridiem", meridiem); + } + else { + if (hour < 12) { + result.start.imply("meridiem", 0); + } + else { + result.start.imply("meridiem", 1); + } + } + match = SECOND_REG_PATTERN$1.exec(context.text.substring(result.index + result.text.length)); + if (!match) { + if (result.text.match(/^\d+$/)) { + return null; + } + return result; + } + const endMoment = startMoment.clone(); + result.end = context.createParsingComponents(); + if (match[DAY_GROUP_1$2]) { + var day1 = match[DAY_GROUP_1$2]; + if (day1 == "明" || day1 == "聽") { + if (refMoment.hour() > 1) { + endMoment.add(1, "day"); + } + } + else if (day1 == "昨" || day1 == "尋" || day1 == "琴") { + endMoment.add(-1, "day"); + } + else if (day1 == "前") { + endMoment.add(-2, "day"); + } + else if (day1 == "大前") { + endMoment.add(-3, "day"); + } + else if (day1 == "後") { + endMoment.add(2, "day"); + } + else if (day1 == "大後") { + endMoment.add(3, "day"); + } + result.end.assign("day", endMoment.date()); + result.end.assign("month", endMoment.month() + 1); + result.end.assign("year", endMoment.year()); + } + else if (match[DAY_GROUP_3$2]) { + var day3 = match[DAY_GROUP_3$2]; + if (day3 == "明" || day3 == "聽") { + endMoment.add(1, "day"); + } + else if (day3 == "昨" || day3 == "尋" || day3 == "琴") { + endMoment.add(-1, "day"); + } + else if (day3 == "前") { + endMoment.add(-2, "day"); + } + else if (day3 == "大前") { + endMoment.add(-3, "day"); + } + else if (day3 == "後") { + endMoment.add(2, "day"); + } + else if (day3 == "大後") { + endMoment.add(3, "day"); + } + result.end.assign("day", endMoment.date()); + result.end.assign("month", endMoment.month() + 1); + result.end.assign("year", endMoment.year()); + } + else { + result.end.imply("day", endMoment.date()); + result.end.imply("month", endMoment.month() + 1); + result.end.imply("year", endMoment.year()); + } + hour = 0; + minute = 0; + meridiem = -1; + if (match[SECOND_GROUP$1]) { + var second = parseInt(match[SECOND_GROUP$1]); + if (isNaN(second)) { + second = (0, constants_1$6.zhStringToNumber)(match[SECOND_GROUP$1]); + } + if (second >= 60) + return null; + result.end.assign("second", second); + } + hour = parseInt(match[HOUR_GROUP$1]); + if (isNaN(hour)) { + hour = (0, constants_1$6.zhStringToNumber)(match[HOUR_GROUP$1]); + } + if (match[MINUTE_GROUP$1]) { + if (match[MINUTE_GROUP$1] == "半") { + minute = 30; + } + else if (match[MINUTE_GROUP$1] == "正" || match[MINUTE_GROUP$1] == "整") { + minute = 0; + } + else { + minute = parseInt(match[MINUTE_GROUP$1]); + if (isNaN(minute)) { + minute = (0, constants_1$6.zhStringToNumber)(match[MINUTE_GROUP$1]); + } + } + } + else if (hour > 100) { + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (minute >= 60) { + return null; + } + if (hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = 1; + } + if (match[AM_PM_HOUR_GROUP$1]) { + if (hour > 12) + return null; + var ampm = match[AM_PM_HOUR_GROUP$1][0].toLowerCase(); + if (ampm == "a") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + if (ampm == "p") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + if (!result.start.isCertain("meridiem")) { + if (meridiem == 0) { + result.start.imply("meridiem", 0); + if (result.start.get("hour") == 12) { + result.start.assign("hour", 0); + } + } + else { + result.start.imply("meridiem", 1); + if (result.start.get("hour") != 12) { + result.start.assign("hour", result.start.get("hour") + 12); + } + } + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_1$1]) { + var zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1$1]; + var zhAMPM1 = zhAMPMString1[0]; + if (zhAMPM1 == "朝" || zhAMPM1 == "早") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM1 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_2$1]) { + var zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2$1]; + var zhAMPM2 = zhAMPMString2[0]; + if (zhAMPM2 == "上" || zhAMPM2 == "朝" || zhAMPM2 == "早" || zhAMPM2 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM2 == "下" || zhAMPM2 == "晏" || zhAMPM2 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_3$1]) { + var zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3$1]; + var zhAMPM3 = zhAMPMString3[0]; + if (zhAMPM3 == "上" || zhAMPM3 == "朝" || zhAMPM3 == "早" || zhAMPM3 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM3 == "下" || zhAMPM3 == "晏" || zhAMPM3 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + result.text = result.text + match[0]; + result.end.assign("hour", hour); + result.end.assign("minute", minute); + if (meridiem >= 0) { + result.end.assign("meridiem", meridiem); + } + else { + const startAtPM = result.start.isCertain("meridiem") && result.start.get("meridiem") == 1; + if (startAtPM && result.start.get("hour") > hour) { + result.end.imply("meridiem", 0); + } + else if (hour > 12) { + result.end.imply("meridiem", 1); + } + } + if (result.end.date().getTime() < result.start.date().getTime()) { + result.end.imply("day", result.end.get("day") + 1); + } + return result; + } +} +ZHHantTimeExpressionParser$1.default = ZHHantTimeExpressionParser; + +var ZHHantWeekdayParser$1 = {}; + +var __importDefault$a = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantWeekdayParser$1, "__esModule", { value: true }); +const dayjs_1$6 = __importDefault$a(require$$0); +const AbstractParserWithWordBoundary_1$6 = AbstractParserWithWordBoundary; +const constants_1$5 = constants$1; +const PATTERN$3 = new RegExp("(?:星期|禮拜|週)(?" + Object.keys(constants_1$5.WEEKDAY_OFFSET).join("|") + ")"); +class ZHHantWeekdayParser extends AbstractParserWithWordBoundary_1$6.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$3; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const dayOfWeek = match.groups.weekday; + const offset = constants_1$5.WEEKDAY_OFFSET[dayOfWeek]; + if (offset === undefined) + return null; + let startMoment = (0, dayjs_1$6.default)(context.refDate); + const refOffset = startMoment.day(); + if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset - 7); + } + else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset + 7); + } + else { + startMoment = startMoment.day(offset); + } + result.start.assign("weekday", offset); + { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHantWeekdayParser$1.default = ZHHantWeekdayParser; + +var ZHHantMergeDateRangeRefiner$1 = {}; + +var __importDefault$9 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1$1 = __importDefault$9(AbstractMergeDateRangeRefiner$1); +class ZHHantMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1$1.default { + patternBetween() { + return /^\s*(至|到|\-|\~|~|-|ー)\s*$/i; + } +} +ZHHantMergeDateRangeRefiner$1.default = ZHHantMergeDateRangeRefiner; + +var ZHHantMergeDateTimeRefiner$1 = {}; + +var __importDefault$8 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHantMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1$1 = __importDefault$8(AbstractMergeDateTimeRefiner); +class ZHHantMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1$1.default { + patternBetween() { + return /^\s*$/i; + } +} +ZHHantMergeDateTimeRefiner$1.default = ZHHantMergeDateTimeRefiner; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = exports.hant = void 0; +const chrono_1 = chrono$1; +const ExtractTimezoneOffsetRefiner_1 = __importDefault(ExtractTimezoneOffsetRefiner$1); +const configurations_1 = configurations; +const ZHHantCasualDateParser_1 = __importDefault(ZHHantCasualDateParser$1); +const ZHHantDateParser_1 = __importDefault(ZHHantDateParser$1); +const ZHHantDeadlineFormatParser_1 = __importDefault(ZHHantDeadlineFormatParser$1); +const ZHHantRelationWeekdayParser_1 = __importDefault(ZHHantRelationWeekdayParser$1); +const ZHHantTimeExpressionParser_1 = __importDefault(ZHHantTimeExpressionParser$1); +const ZHHantWeekdayParser_1 = __importDefault(ZHHantWeekdayParser$1); +const ZHHantMergeDateRangeRefiner_1 = __importDefault(ZHHantMergeDateRangeRefiner$1); +const ZHHantMergeDateTimeRefiner_1 = __importDefault(ZHHantMergeDateTimeRefiner$1); +exports.hant = new chrono_1.Chrono(createCasualConfiguration()); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration()); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration() { + const option = createConfiguration(); + option.parsers.unshift(new ZHHantCasualDateParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration() { + const configuration = (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new ZHHantDateParser_1.default(), + new ZHHantRelationWeekdayParser_1.default(), + new ZHHantWeekdayParser_1.default(), + new ZHHantTimeExpressionParser_1.default(), + new ZHHantDeadlineFormatParser_1.default(), + ], + refiners: [new ZHHantMergeDateRangeRefiner_1.default(), new ZHHantMergeDateTimeRefiner_1.default()], + }); + configuration.refiners = configuration.refiners.filter((refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner_1.default)); + return configuration; +} +exports.createConfiguration = createConfiguration; +}(hant)); + +var hans = {}; + +var ZHHansCasualDateParser$1 = {}; + +var __importDefault$7 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansCasualDateParser$1, "__esModule", { value: true }); +const dayjs_1$5 = __importDefault$7(require$$0); +const AbstractParserWithWordBoundary_1$5 = AbstractParserWithWordBoundary; +const NOW_GROUP = 1; +const DAY_GROUP_1$1 = 2; +const TIME_GROUP_1 = 3; +const TIME_GROUP_2 = 4; +const DAY_GROUP_3$1 = 5; +const TIME_GROUP_3 = 6; +class ZHHansCasualDateParser extends AbstractParserWithWordBoundary_1$5.AbstractParserWithWordBoundaryChecking { + innerPattern(context) { + return new RegExp("(现在|立(?:刻|即)|即刻)|" + + "(今|明|前|大前|后|大后|昨)(早|晚)|" + + "(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|后|大后|昨)(?:日|天)" + + "(?:[\\s|,|,]*)" + + "(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?", "i"); + } + innerExtract(context, match) { + const index = match.index; + const result = context.createParsingResult(index, match[0]); + const refMoment = (0, dayjs_1$5.default)(context.refDate); + let startMoment = refMoment; + if (match[NOW_GROUP]) { + result.start.imply("hour", refMoment.hour()); + result.start.imply("minute", refMoment.minute()); + result.start.imply("second", refMoment.second()); + result.start.imply("millisecond", refMoment.millisecond()); + } + else if (match[DAY_GROUP_1$1]) { + const day1 = match[DAY_GROUP_1$1]; + const time1 = match[TIME_GROUP_1]; + if (day1 == "明") { + if (refMoment.hour() > 1) { + startMoment = startMoment.add(1, "day"); + } + } + else if (day1 == "昨") { + startMoment = startMoment.add(-1, "day"); + } + else if (day1 == "前") { + startMoment = startMoment.add(-2, "day"); + } + else if (day1 == "大前") { + startMoment = startMoment.add(-3, "day"); + } + else if (day1 == "后") { + startMoment = startMoment.add(2, "day"); + } + else if (day1 == "大后") { + startMoment = startMoment.add(3, "day"); + } + if (time1 == "早") { + result.start.imply("hour", 6); + } + else if (time1 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + } + else if (match[TIME_GROUP_2]) { + const timeString2 = match[TIME_GROUP_2]; + const time2 = timeString2[0]; + if (time2 == "早" || time2 == "上") { + result.start.imply("hour", 6); + } + else if (time2 == "下") { + result.start.imply("hour", 15); + result.start.imply("meridiem", 1); + } + else if (time2 == "中") { + result.start.imply("hour", 12); + result.start.imply("meridiem", 1); + } + else if (time2 == "夜" || time2 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + else if (time2 == "凌") { + result.start.imply("hour", 0); + } + } + else if (match[DAY_GROUP_3$1]) { + const day3 = match[DAY_GROUP_3$1]; + if (day3 == "明") { + if (refMoment.hour() > 1) { + startMoment = startMoment.add(1, "day"); + } + } + else if (day3 == "昨") { + startMoment = startMoment.add(-1, "day"); + } + else if (day3 == "前") { + startMoment = startMoment.add(-2, "day"); + } + else if (day3 == "大前") { + startMoment = startMoment.add(-3, "day"); + } + else if (day3 == "后") { + startMoment = startMoment.add(2, "day"); + } + else if (day3 == "大后") { + startMoment = startMoment.add(3, "day"); + } + const timeString3 = match[TIME_GROUP_3]; + if (timeString3) { + const time3 = timeString3[0]; + if (time3 == "早" || time3 == "上") { + result.start.imply("hour", 6); + } + else if (time3 == "下") { + result.start.imply("hour", 15); + result.start.imply("meridiem", 1); + } + else if (time3 == "中") { + result.start.imply("hour", 12); + result.start.imply("meridiem", 1); + } + else if (time3 == "夜" || time3 == "晚") { + result.start.imply("hour", 22); + result.start.imply("meridiem", 1); + } + else if (time3 == "凌") { + result.start.imply("hour", 0); + } + } + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + return result; + } +} +ZHHansCasualDateParser$1.default = ZHHansCasualDateParser; + +var ZHHansDateParser$1 = {}; + +var constants = {}; + +(function (exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.zhStringToYear = exports.zhStringToNumber = exports.WEEKDAY_OFFSET = exports.NUMBER = void 0; +exports.NUMBER = { + "零": 0, + "〇": 0, + "一": 1, + "二": 2, + "两": 2, + "三": 3, + "四": 4, + "五": 5, + "六": 6, + "七": 7, + "八": 8, + "九": 9, + "十": 10, +}; +exports.WEEKDAY_OFFSET = { + "天": 0, + "日": 0, + "一": 1, + "二": 2, + "三": 3, + "四": 4, + "五": 5, + "六": 6, +}; +function zhStringToNumber(text) { + let number = 0; + for (let i = 0; i < text.length; i++) { + const char = text[i]; + if (char === "十") { + number = number === 0 ? exports.NUMBER[char] : number * exports.NUMBER[char]; + } + else { + number += exports.NUMBER[char]; + } + } + return number; +} +exports.zhStringToNumber = zhStringToNumber; +function zhStringToYear(text) { + let string = ""; + for (let i = 0; i < text.length; i++) { + const char = text[i]; + string = string + exports.NUMBER[char]; + } + return parseInt(string); +} +exports.zhStringToYear = zhStringToYear; +}(constants)); + +var __importDefault$6 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansDateParser$1, "__esModule", { value: true }); +const dayjs_1$4 = __importDefault$6(require$$0); +const AbstractParserWithWordBoundary_1$4 = AbstractParserWithWordBoundary; +const constants_1$4 = constants; +const YEAR_GROUP = 1; +const MONTH_GROUP = 2; +const DAY_GROUP = 3; +class ZHHansDateParser extends AbstractParserWithWordBoundary_1$4.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return new RegExp("(" + + "\\d{2,4}|" + + "[" + + Object.keys(constants_1$4.NUMBER).join("") + + "]{4}|" + + "[" + + Object.keys(constants_1$4.NUMBER).join("") + + "]{2}" + + ")?" + + "(?:\\s*)" + + "(?:年)?" + + "(?:[\\s|,|,]*)" + + "(" + + "\\d{1,2}|" + + "[" + + Object.keys(constants_1$4.NUMBER).join("") + + "]{1,3}" + + ")" + + "(?:\\s*)" + + "(?:月)" + + "(?:\\s*)" + + "(" + + "\\d{1,2}|" + + "[" + + Object.keys(constants_1$4.NUMBER).join("") + + "]{1,3}" + + ")?" + + "(?:\\s*)" + + "(?:日|号)?"); + } + innerExtract(context, match) { + const startMoment = (0, dayjs_1$4.default)(context.refDate); + const result = context.createParsingResult(match.index, match[0]); + let month = parseInt(match[MONTH_GROUP]); + if (isNaN(month)) + month = (0, constants_1$4.zhStringToNumber)(match[MONTH_GROUP]); + result.start.assign("month", month); + if (match[DAY_GROUP]) { + let day = parseInt(match[DAY_GROUP]); + if (isNaN(day)) + day = (0, constants_1$4.zhStringToNumber)(match[DAY_GROUP]); + result.start.assign("day", day); + } + else { + result.start.imply("day", startMoment.date()); + } + if (match[YEAR_GROUP]) { + let year = parseInt(match[YEAR_GROUP]); + if (isNaN(year)) + year = (0, constants_1$4.zhStringToYear)(match[YEAR_GROUP]); + result.start.assign("year", year); + } + else { + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHansDateParser$1.default = ZHHansDateParser; + +var ZHHansDeadlineFormatParser$1 = {}; + +var __importDefault$5 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansDeadlineFormatParser$1, "__esModule", { value: true }); +const dayjs_1$3 = __importDefault$5(require$$0); +const AbstractParserWithWordBoundary_1$3 = AbstractParserWithWordBoundary; +const constants_1$3 = constants; +const PATTERN$2 = new RegExp("(\\d+|[" + + Object.keys(constants_1$3.NUMBER).join("") + + "]+|半|几)(?:\\s*)" + + "(?:个)?" + + "(秒(?:钟)?|分钟|小时|钟|日|天|星期|礼拜|月|年)" + + "(?:(?:之|过)?后|(?:之)?内)", "i"); +const NUMBER_GROUP = 1; +const UNIT_GROUP = 2; +class ZHHansDeadlineFormatParser extends AbstractParserWithWordBoundary_1$3.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$2; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + let number = parseInt(match[NUMBER_GROUP]); + if (isNaN(number)) { + number = (0, constants_1$3.zhStringToNumber)(match[NUMBER_GROUP]); + } + if (isNaN(number)) { + const string = match[NUMBER_GROUP]; + if (string === "几") { + number = 3; + } + else if (string === "半") { + number = 0.5; + } + else { + return null; + } + } + let date = (0, dayjs_1$3.default)(context.refDate); + const unit = match[UNIT_GROUP]; + const unitAbbr = unit[0]; + if (unitAbbr.match(/[日天星礼月年]/)) { + if (unitAbbr == "日" || unitAbbr == "天") { + date = date.add(number, "d"); + } + else if (unitAbbr == "星" || unitAbbr == "礼") { + date = date.add(number * 7, "d"); + } + else if (unitAbbr == "月") { + date = date.add(number, "month"); + } + else if (unitAbbr == "年") { + date = date.add(number, "year"); + } + result.start.assign("year", date.year()); + result.start.assign("month", date.month() + 1); + result.start.assign("day", date.date()); + return result; + } + if (unitAbbr == "秒") { + date = date.add(number, "second"); + } + else if (unitAbbr == "分") { + date = date.add(number, "minute"); + } + else if (unitAbbr == "小" || unitAbbr == "钟") { + date = date.add(number, "hour"); + } + result.start.imply("year", date.year()); + result.start.imply("month", date.month() + 1); + result.start.imply("day", date.date()); + result.start.assign("hour", date.hour()); + result.start.assign("minute", date.minute()); + result.start.assign("second", date.second()); + return result; + } +} +ZHHansDeadlineFormatParser$1.default = ZHHansDeadlineFormatParser; + +var ZHHansRelationWeekdayParser$1 = {}; + +var __importDefault$4 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansRelationWeekdayParser$1, "__esModule", { value: true }); +const dayjs_1$2 = __importDefault$4(require$$0); +const AbstractParserWithWordBoundary_1$2 = AbstractParserWithWordBoundary; +const constants_1$2 = constants; +const PATTERN$1 = new RegExp("(?上|下|这)(?:个)?(?:星期|礼拜|周)(?" + Object.keys(constants_1$2.WEEKDAY_OFFSET).join("|") + ")"); +class ZHHansRelationWeekdayParser extends AbstractParserWithWordBoundary_1$2.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN$1; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const dayOfWeek = match.groups.weekday; + const offset = constants_1$2.WEEKDAY_OFFSET[dayOfWeek]; + if (offset === undefined) + return null; + let modifier = null; + const prefix = match.groups.prefix; + if (prefix == "上") { + modifier = "last"; + } + else if (prefix == "下") { + modifier = "next"; + } + else if (prefix == "这") { + modifier = "this"; + } + let startMoment = (0, dayjs_1$2.default)(context.refDate); + let startMomentFixed = false; + const refOffset = startMoment.day(); + if (modifier == "last" || modifier == "past") { + startMoment = startMoment.day(offset - 7); + startMomentFixed = true; + } + else if (modifier == "next") { + startMoment = startMoment.day(offset + 7); + startMomentFixed = true; + } + else if (modifier == "this") { + startMoment = startMoment.day(offset); + } + else { + if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset - 7); + } + else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset + 7); + } + else { + startMoment = startMoment.day(offset); + } + } + result.start.assign("weekday", offset); + if (startMomentFixed) { + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHansRelationWeekdayParser$1.default = ZHHansRelationWeekdayParser; + +var ZHHansTimeExpressionParser$1 = {}; + +var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansTimeExpressionParser$1, "__esModule", { value: true }); +const dayjs_1$1 = __importDefault$3(require$$0); +const AbstractParserWithWordBoundary_1$1 = AbstractParserWithWordBoundary; +const constants_1$1 = constants; +const FIRST_REG_PATTERN = new RegExp("(?:从|自)?" + + "(?:" + + "(今|明|前|大前|后|大后|昨)(早|朝|晚)|" + + "(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|后|大后|昨)(?:日|天)" + + "(?:[\\s,,]*)" + + "(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" + + ")?" + + "(?:[\\s,,]*)" + + "(?:(\\d+|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)(?:\\s*)(?:点|时|:|:)" + + "(?:\\s*)" + + "(\\d+|半|正|整|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)?(?:\\s*)(?:分|:|:)?" + + "(?:\\s*)" + + "(\\d+|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)?(?:\\s*)(?:秒)?)" + + "(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i"); +const SECOND_REG_PATTERN = new RegExp("(?:^\\s*(?:到|至|\\-|\\–|\\~|\\〜)\\s*)" + + "(?:" + + "(今|明|前|大前|后|大后|昨)(早|朝|晚)|" + + "(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" + + "(今|明|前|大前|后|大后|昨)(?:日|天)" + + "(?:[\\s,,]*)" + + "(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" + + ")?" + + "(?:[\\s,,]*)" + + "(?:(\\d+|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)(?:\\s*)(?:点|时|:|:)" + + "(?:\\s*)" + + "(\\d+|半|正|整|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)?(?:\\s*)(?:分|:|:)?" + + "(?:\\s*)" + + "(\\d+|[" + + Object.keys(constants_1$1.NUMBER).join("") + + "]+)?(?:\\s*)(?:秒)?)" + + "(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i"); +const DAY_GROUP_1 = 1; +const ZH_AM_PM_HOUR_GROUP_1 = 2; +const ZH_AM_PM_HOUR_GROUP_2 = 3; +const DAY_GROUP_3 = 4; +const ZH_AM_PM_HOUR_GROUP_3 = 5; +const HOUR_GROUP = 6; +const MINUTE_GROUP = 7; +const SECOND_GROUP = 8; +const AM_PM_HOUR_GROUP = 9; +class ZHHansTimeExpressionParser extends AbstractParserWithWordBoundary_1$1.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return FIRST_REG_PATTERN; + } + innerExtract(context, match) { + if (match.index > 0 && context.text[match.index - 1].match(/\w/)) { + return null; + } + const refMoment = (0, dayjs_1$1.default)(context.refDate); + const result = context.createParsingResult(match.index, match[0]); + const startMoment = refMoment.clone(); + if (match[DAY_GROUP_1]) { + const day1 = match[DAY_GROUP_1]; + if (day1 == "明") { + if (refMoment.hour() > 1) { + startMoment.add(1, "day"); + } + } + else if (day1 == "昨") { + startMoment.add(-1, "day"); + } + else if (day1 == "前") { + startMoment.add(-2, "day"); + } + else if (day1 == "大前") { + startMoment.add(-3, "day"); + } + else if (day1 == "后") { + startMoment.add(2, "day"); + } + else if (day1 == "大后") { + startMoment.add(3, "day"); + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else if (match[DAY_GROUP_3]) { + const day3 = match[DAY_GROUP_3]; + if (day3 == "明") { + startMoment.add(1, "day"); + } + else if (day3 == "昨") { + startMoment.add(-1, "day"); + } + else if (day3 == "前") { + startMoment.add(-2, "day"); + } + else if (day3 == "大前") { + startMoment.add(-3, "day"); + } + else if (day3 == "后") { + startMoment.add(2, "day"); + } + else if (day3 == "大后") { + startMoment.add(3, "day"); + } + result.start.assign("day", startMoment.date()); + result.start.assign("month", startMoment.month() + 1); + result.start.assign("year", startMoment.year()); + } + else { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + let hour = 0; + let minute = 0; + let meridiem = -1; + if (match[SECOND_GROUP]) { + let second = parseInt(match[SECOND_GROUP]); + if (isNaN(second)) { + second = (0, constants_1$1.zhStringToNumber)(match[SECOND_GROUP]); + } + if (second >= 60) + return null; + result.start.assign("second", second); + } + hour = parseInt(match[HOUR_GROUP]); + if (isNaN(hour)) { + hour = (0, constants_1$1.zhStringToNumber)(match[HOUR_GROUP]); + } + if (match[MINUTE_GROUP]) { + if (match[MINUTE_GROUP] == "半") { + minute = 30; + } + else if (match[MINUTE_GROUP] == "正" || match[MINUTE_GROUP] == "整") { + minute = 0; + } + else { + minute = parseInt(match[MINUTE_GROUP]); + if (isNaN(minute)) { + minute = (0, constants_1$1.zhStringToNumber)(match[MINUTE_GROUP]); + } + } + } + else if (hour > 100) { + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (minute >= 60) { + return null; + } + if (hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = 1; + } + if (match[AM_PM_HOUR_GROUP]) { + if (hour > 12) + return null; + const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase(); + if (ampm == "a") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + if (ampm == "p") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_1]) { + const zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1]; + const zhAMPM1 = zhAMPMString1[0]; + if (zhAMPM1 == "早") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM1 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_2]) { + const zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2]; + const zhAMPM2 = zhAMPMString2[0]; + if (zhAMPM2 == "上" || zhAMPM2 == "早" || zhAMPM2 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM2 == "下" || zhAMPM2 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_3]) { + const zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3]; + const zhAMPM3 = zhAMPMString3[0]; + if (zhAMPM3 == "上" || zhAMPM3 == "早" || zhAMPM3 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM3 == "下" || zhAMPM3 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + result.start.assign("hour", hour); + result.start.assign("minute", minute); + if (meridiem >= 0) { + result.start.assign("meridiem", meridiem); + } + else { + if (hour < 12) { + result.start.imply("meridiem", 0); + } + else { + result.start.imply("meridiem", 1); + } + } + match = SECOND_REG_PATTERN.exec(context.text.substring(result.index + result.text.length)); + if (!match) { + if (result.text.match(/^\d+$/)) { + return null; + } + return result; + } + const endMoment = startMoment.clone(); + result.end = context.createParsingComponents(); + if (match[DAY_GROUP_1]) { + const day1 = match[DAY_GROUP_1]; + if (day1 == "明") { + if (refMoment.hour() > 1) { + endMoment.add(1, "day"); + } + } + else if (day1 == "昨") { + endMoment.add(-1, "day"); + } + else if (day1 == "前") { + endMoment.add(-2, "day"); + } + else if (day1 == "大前") { + endMoment.add(-3, "day"); + } + else if (day1 == "后") { + endMoment.add(2, "day"); + } + else if (day1 == "大后") { + endMoment.add(3, "day"); + } + result.end.assign("day", endMoment.date()); + result.end.assign("month", endMoment.month() + 1); + result.end.assign("year", endMoment.year()); + } + else if (match[DAY_GROUP_3]) { + const day3 = match[DAY_GROUP_3]; + if (day3 == "明") { + endMoment.add(1, "day"); + } + else if (day3 == "昨") { + endMoment.add(-1, "day"); + } + else if (day3 == "前") { + endMoment.add(-2, "day"); + } + else if (day3 == "大前") { + endMoment.add(-3, "day"); + } + else if (day3 == "后") { + endMoment.add(2, "day"); + } + else if (day3 == "大后") { + endMoment.add(3, "day"); + } + result.end.assign("day", endMoment.date()); + result.end.assign("month", endMoment.month() + 1); + result.end.assign("year", endMoment.year()); + } + else { + result.end.imply("day", endMoment.date()); + result.end.imply("month", endMoment.month() + 1); + result.end.imply("year", endMoment.year()); + } + hour = 0; + minute = 0; + meridiem = -1; + if (match[SECOND_GROUP]) { + let second = parseInt(match[SECOND_GROUP]); + if (isNaN(second)) { + second = (0, constants_1$1.zhStringToNumber)(match[SECOND_GROUP]); + } + if (second >= 60) + return null; + result.end.assign("second", second); + } + hour = parseInt(match[HOUR_GROUP]); + if (isNaN(hour)) { + hour = (0, constants_1$1.zhStringToNumber)(match[HOUR_GROUP]); + } + if (match[MINUTE_GROUP]) { + if (match[MINUTE_GROUP] == "半") { + minute = 30; + } + else if (match[MINUTE_GROUP] == "正" || match[MINUTE_GROUP] == "整") { + minute = 0; + } + else { + minute = parseInt(match[MINUTE_GROUP]); + if (isNaN(minute)) { + minute = (0, constants_1$1.zhStringToNumber)(match[MINUTE_GROUP]); + } + } + } + else if (hour > 100) { + minute = hour % 100; + hour = Math.floor(hour / 100); + } + if (minute >= 60) { + return null; + } + if (hour > 24) { + return null; + } + if (hour >= 12) { + meridiem = 1; + } + if (match[AM_PM_HOUR_GROUP]) { + if (hour > 12) + return null; + const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase(); + if (ampm == "a") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + if (ampm == "p") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + if (!result.start.isCertain("meridiem")) { + if (meridiem == 0) { + result.start.imply("meridiem", 0); + if (result.start.get("hour") == 12) { + result.start.assign("hour", 0); + } + } + else { + result.start.imply("meridiem", 1); + if (result.start.get("hour") != 12) { + result.start.assign("hour", result.start.get("hour") + 12); + } + } + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_1]) { + const zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1]; + const zhAMPM1 = zhAMPMString1[0]; + if (zhAMPM1 == "早") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM1 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_2]) { + const zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2]; + const zhAMPM2 = zhAMPMString2[0]; + if (zhAMPM2 == "上" || zhAMPM2 == "早" || zhAMPM2 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM2 == "下" || zhAMPM2 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + else if (match[ZH_AM_PM_HOUR_GROUP_3]) { + const zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3]; + const zhAMPM3 = zhAMPMString3[0]; + if (zhAMPM3 == "上" || zhAMPM3 == "早" || zhAMPM3 == "凌") { + meridiem = 0; + if (hour == 12) + hour = 0; + } + else if (zhAMPM3 == "下" || zhAMPM3 == "晚") { + meridiem = 1; + if (hour != 12) + hour += 12; + } + } + result.text = result.text + match[0]; + result.end.assign("hour", hour); + result.end.assign("minute", minute); + if (meridiem >= 0) { + result.end.assign("meridiem", meridiem); + } + else { + const startAtPM = result.start.isCertain("meridiem") && result.start.get("meridiem") == 1; + if (startAtPM && result.start.get("hour") > hour) { + result.end.imply("meridiem", 0); + } + else if (hour > 12) { + result.end.imply("meridiem", 1); + } + } + if (result.end.date().getTime() < result.start.date().getTime()) { + result.end.imply("day", result.end.get("day") + 1); + } + return result; + } +} +ZHHansTimeExpressionParser$1.default = ZHHansTimeExpressionParser; + +var ZHHansWeekdayParser$1 = {}; + +var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansWeekdayParser$1, "__esModule", { value: true }); +const dayjs_1 = __importDefault$2(require$$0); +const AbstractParserWithWordBoundary_1 = AbstractParserWithWordBoundary; +const constants_1 = constants; +const PATTERN = new RegExp("(?:星期|礼拜|周)(?" + Object.keys(constants_1.WEEKDAY_OFFSET).join("|") + ")"); +class ZHHansWeekdayParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking { + innerPattern() { + return PATTERN; + } + innerExtract(context, match) { + const result = context.createParsingResult(match.index, match[0]); + const dayOfWeek = match.groups.weekday; + const offset = constants_1.WEEKDAY_OFFSET[dayOfWeek]; + if (offset === undefined) + return null; + let startMoment = (0, dayjs_1.default)(context.refDate); + const refOffset = startMoment.day(); + if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset - 7); + } + else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) { + startMoment = startMoment.day(offset + 7); + } + else { + startMoment = startMoment.day(offset); + } + result.start.assign("weekday", offset); + { + result.start.imply("day", startMoment.date()); + result.start.imply("month", startMoment.month() + 1); + result.start.imply("year", startMoment.year()); + } + return result; + } +} +ZHHansWeekdayParser$1.default = ZHHansWeekdayParser; + +var ZHHansMergeDateRangeRefiner$1 = {}; + +var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansMergeDateRangeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateRangeRefiner_1 = __importDefault$1(AbstractMergeDateRangeRefiner$1); +class ZHHansMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1.default { + patternBetween() { + return /^\s*(至|到|-|~|~|-|ー)\s*$/i; + } +} +ZHHansMergeDateRangeRefiner$1.default = ZHHansMergeDateRangeRefiner; + +var ZHHansMergeDateTimeRefiner$1 = {}; + +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(ZHHansMergeDateTimeRefiner$1, "__esModule", { value: true }); +const AbstractMergeDateTimeRefiner_1 = __importDefault(AbstractMergeDateTimeRefiner); +class ZHHansMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1.default { + patternBetween() { + return /^\s*$/i; + } +} +ZHHansMergeDateTimeRefiner$1.default = ZHHansMergeDateTimeRefiner; + +(function (exports) { +var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = exports.hans = void 0; +const chrono_1 = chrono$1; +const ExtractTimezoneOffsetRefiner_1 = __importDefault(ExtractTimezoneOffsetRefiner$1); +const configurations_1 = configurations; +const ZHHansCasualDateParser_1 = __importDefault(ZHHansCasualDateParser$1); +const ZHHansDateParser_1 = __importDefault(ZHHansDateParser$1); +const ZHHansDeadlineFormatParser_1 = __importDefault(ZHHansDeadlineFormatParser$1); +const ZHHansRelationWeekdayParser_1 = __importDefault(ZHHansRelationWeekdayParser$1); +const ZHHansTimeExpressionParser_1 = __importDefault(ZHHansTimeExpressionParser$1); +const ZHHansWeekdayParser_1 = __importDefault(ZHHansWeekdayParser$1); +const ZHHansMergeDateRangeRefiner_1 = __importDefault(ZHHansMergeDateRangeRefiner$1); +const ZHHansMergeDateTimeRefiner_1 = __importDefault(ZHHansMergeDateTimeRefiner$1); +exports.hans = new chrono_1.Chrono(createCasualConfiguration()); +exports.casual = new chrono_1.Chrono(createCasualConfiguration()); +exports.strict = new chrono_1.Chrono(createConfiguration()); +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +function createCasualConfiguration() { + const option = createConfiguration(); + option.parsers.unshift(new ZHHansCasualDateParser_1.default()); + return option; +} +exports.createCasualConfiguration = createCasualConfiguration; +function createConfiguration() { + const configuration = (0, configurations_1.includeCommonConfiguration)({ + parsers: [ + new ZHHansDateParser_1.default(), + new ZHHansRelationWeekdayParser_1.default(), + new ZHHansWeekdayParser_1.default(), + new ZHHansTimeExpressionParser_1.default(), + new ZHHansDeadlineFormatParser_1.default(), + ], + refiners: [new ZHHansMergeDateRangeRefiner_1.default(), new ZHHansMergeDateTimeRefiner_1.default()], + }); + configuration.refiners = configuration.refiners.filter((refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner_1.default)); + return configuration; +} +exports.createConfiguration = createConfiguration; +}(hans)); + +(function (exports) { +var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hans = void 0; +__exportStar(hant, exports); +var hans_1 = hans; +Object.defineProperty(exports, "hans", { enumerable: true, get: function () { return hans_1.hans; } }); +}(zh)); + +(function (exports) { +var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseDate = exports.parse = exports.casual = exports.strict = exports.zh = exports.nl = exports.pt = exports.ja = exports.fr = exports.de = exports.Meridiem = exports.Chrono = exports.en = void 0; +const en = __importStar(en$1); +exports.en = en; +const chrono_1 = chrono$1; +Object.defineProperty(exports, "Chrono", { enumerable: true, get: function () { return chrono_1.Chrono; } }); +(function (Meridiem) { + Meridiem[Meridiem["AM"] = 0] = "AM"; + Meridiem[Meridiem["PM"] = 1] = "PM"; +})(exports.Meridiem || (exports.Meridiem = {})); +const de$1 = __importStar(de); +exports.de = de$1; +const fr$1 = __importStar(fr); +exports.fr = fr$1; +const ja$1 = __importStar(ja); +exports.ja = ja$1; +const pt$1 = __importStar(pt); +exports.pt = pt$1; +const nl$1 = __importStar(nl); +exports.nl = nl$1; +const zh$1 = __importStar(zh); +exports.zh = zh$1; +exports.strict = en.strict; +exports.casual = en.casual; +function parse(text, ref, option) { + return exports.casual.parse(text, ref, option); +} +exports.parse = parse; +function parseDate(text, ref, option) { + return exports.casual.parseDate(text, ref, option); +} +exports.parseDate = parseDate; +}(dist)); + +var chrono = /*@__PURE__*/getDefaultExportFromCjs(dist); + +function getLocalizedChrono() { + const locale = window.moment.locale(); + switch (locale) { + case "en-gb": + return new dist.Chrono(chrono.en.createCasualConfiguration(true)); + default: + return new dist.Chrono(chrono.en.createCasualConfiguration(false)); + } +} +function getConfiguredChrono() { + const localizedChrono = getLocalizedChrono(); + localizedChrono.parsers.push({ + pattern: () => { + return /\bChristmas\b/i; + }, + extract: () => { + return { + day: 25, + month: 12, + }; + }, + }); + localizedChrono.parsers.push({ + pattern: () => new RegExp(ORDINAL_NUMBER_PATTERN), + extract: (_context, match) => { + return { + day: parseOrdinalNumberPattern(match[0]), + month: window.moment().month(), + }; + }, + }); + return localizedChrono; +} +class NLDParser { + constructor() { + this.chrono = getConfiguredChrono(); + } + getParsedDate(selectedText, weekStartPreference) { + var _a; + const parser = this.chrono; + const initialParse = parser.parse(selectedText); + const weekdayIsCertain = (_a = initialParse[0]) === null || _a === void 0 ? void 0 : _a.start.isCertain("weekday"); + const weekStart = weekStartPreference === "locale-default" + ? getLocaleWeekStart() + : weekStartPreference; + const locale = { + weekStart: getWeekNumber(weekStart), + }; + const thisDateMatch = selectedText.match(/this\s([\w]+)/i); + const nextDateMatch = selectedText.match(/next\s([\w]+)/i); + const lastDayOfMatch = selectedText.match(/(last day of|end of)\s*([^\n\r]*)/i); + const midOf = selectedText.match(/mid\s([\w]+)/i); + const referenceDate = weekdayIsCertain + ? window.moment().weekday(0).toDate() + : new Date(); + if (thisDateMatch && thisDateMatch[1] === "week") { + return parser.parseDate(`this ${weekStart}`, referenceDate); + } + if (nextDateMatch && nextDateMatch[1] === "week") { + return parser.parseDate(`next ${weekStart}`, referenceDate, { + forwardDate: true, + }); + } + if (nextDateMatch && nextDateMatch[1] === "month") { + const thisMonth = parser.parseDate("this month", new Date(), { + forwardDate: true, + }); + return parser.parseDate(selectedText, thisMonth, { + forwardDate: true, + }); + } + if (nextDateMatch && nextDateMatch[1] === "year") { + const thisYear = parser.parseDate("this year", new Date(), { + forwardDate: true, + }); + return parser.parseDate(selectedText, thisYear, { + forwardDate: true, + }); + } + if (lastDayOfMatch) { + const tempDate = parser.parse(lastDayOfMatch[2]); + const year = tempDate[0].start.get("year"); + const month = tempDate[0].start.get("month"); + const lastDay = getLastDayOfMonth(year, month); + return parser.parseDate(`${year}-${month}-${lastDay}`, new Date(), { + forwardDate: true, + }); + } + if (midOf) { + return parser.parseDate(`${midOf[1]} 15th`, new Date(), { + forwardDate: true, + }); + } + return parser.parseDate(selectedText, referenceDate, { locale }); + } +} + +const DEFAULT_SETTINGS = { + autosuggestToggleLink: true, + autocompleteTriggerPhrase: "@", + isAutosuggestEnabled: true, + format: "YYYY-MM-DD", + timeFormat: "HH:mm", + separator: " ", + weekStart: "locale-default", + modalToggleTime: false, + modalToggleLink: false, + modalMomentFormat: "YYYY-MM-DD HH:mm", +}; +const weekdays = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", +]; +class NLDSettingsTab extends require$$0$1.PluginSettingTab { + constructor(app, plugin) { + super(app, plugin); + this.plugin = plugin; + } + display() { + const { containerEl } = this; + const localizedWeekdays = window.moment.weekdays(); + const localeWeekStart = getLocaleWeekStart(); + containerEl.empty(); + containerEl.createEl("h2", { + text: "Natural Language Dates", + }); + containerEl.createEl("h3", { + text: "Parser settings", + }); + new require$$0$1.Setting(containerEl) + .setName("Date format") + .setDesc("Output format for parsed dates") + .addMomentFormat((text) => text + .setDefaultFormat("YYYY-MM-DD") + .setValue(this.plugin.settings.format) + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.format = value || "YYYY-MM-DD"; + yield this.plugin.saveSettings(); + }))); + new require$$0$1.Setting(containerEl) + .setName("Week starts on") + .setDesc("Which day to consider as the start of the week") + .addDropdown((dropdown) => { + dropdown.addOption("locale-default", `Locale default (${localeWeekStart})`); + localizedWeekdays.forEach((day, i) => { + dropdown.addOption(weekdays[i], day); + }); + dropdown.setValue(this.plugin.settings.weekStart.toLowerCase()); + dropdown.onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.weekStart = value; + yield this.plugin.saveSettings(); + })); + }); + containerEl.createEl("h3", { + text: "Hotkey formatting settings", + }); + new require$$0$1.Setting(containerEl) + .setName("Time format") + .setDesc("Format for the hotkeys that include the current time") + .addMomentFormat((text) => text + .setDefaultFormat("HH:mm") + .setValue(this.plugin.settings.timeFormat) + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.timeFormat = value || "HH:mm"; + yield this.plugin.saveSettings(); + }))); + new require$$0$1.Setting(containerEl) + .setName("Separator") + .setDesc("Separator between date and time for entries that have both") + .addText((text) => text + .setPlaceholder("Separator is empty") + .setValue(this.plugin.settings.separator) + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.separator = value; + yield this.plugin.saveSettings(); + }))); + containerEl.createEl("h3", { + text: "Date Autosuggest", + }); + new require$$0$1.Setting(containerEl) + .setName("Enable date autosuggest") + .setDesc(`Input dates with natural language. Open the suggest menu with ${this.plugin.settings.autocompleteTriggerPhrase}`) + .addToggle((toggle) => toggle + .setValue(this.plugin.settings.isAutosuggestEnabled) + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.isAutosuggestEnabled = value; + yield this.plugin.saveSettings(); + }))); + new require$$0$1.Setting(containerEl) + .setName("Add dates as link?") + .setDesc("If enabled, dates created via autosuggest will be wrapped in [[wikilinks]]") + .addToggle((toggle) => toggle + .setValue(this.plugin.settings.autosuggestToggleLink) + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.autosuggestToggleLink = value; + yield this.plugin.saveSettings(); + }))); + new require$$0$1.Setting(containerEl) + .setName("Trigger phrase") + .setDesc("Character(s) that will cause the date autosuggest to open") + .addMomentFormat((text) => text + .setPlaceholder(DEFAULT_SETTINGS.autocompleteTriggerPhrase) + .setValue(this.plugin.settings.autocompleteTriggerPhrase || "@") + .onChange((value) => __awaiter(this, void 0, void 0, function* () { + this.plugin.settings.autocompleteTriggerPhrase = value.trim(); + yield this.plugin.saveSettings(); + }))); + } +} + +class DateSuggest extends require$$0$1.EditorSuggest { + constructor(app, plugin) { + super(app); + this.app = app; + this.plugin = plugin; + // @ts-ignore + this.scope.register(["Shift"], "Enter", (evt) => { + // @ts-ignore + this.suggestions.useSelectedItem(evt); + return false; + }); + if (this.plugin.settings.autosuggestToggleLink) { + this.setInstructions([{ command: "Shift", purpose: "Keep text as alias" }]); + } + } + getSuggestions(context) { + const suggestions = this.getDateSuggestions(context); + if (suggestions.length) { + return suggestions; + } + // catch-all if there are no matches + return [{ label: context.query }]; + } + getDateSuggestions(context) { + if (context.query.match(/^time/)) { + return ["now", "+15 minutes", "+1 hour", "-15 minutes", "-1 hour"] + .map((val) => ({ label: `time:${val}` })) + .filter((item) => item.label.toLowerCase().startsWith(context.query)); + } + if (context.query.match(/(next|last|this)/i)) { + const reference = context.query.match(/(next|last|this)/i)[1]; + return [ + "week", + "month", + "year", + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ] + .map((val) => ({ label: `${reference} ${val}` })) + .filter((items) => items.label.toLowerCase().startsWith(context.query)); + } + const relativeDate = context.query.match(/^in ([+-]?\d+)/i) || context.query.match(/^([+-]?\d+)/i); + if (relativeDate) { + const timeDelta = relativeDate[1]; + return [ + { label: `in ${timeDelta} minutes` }, + { label: `in ${timeDelta} hours` }, + { label: `in ${timeDelta} days` }, + { label: `in ${timeDelta} weeks` }, + { label: `in ${timeDelta} months` }, + { label: `${timeDelta} days ago` }, + { label: `${timeDelta} weeks ago` }, + { label: `${timeDelta} months ago` }, + ].filter((items) => items.label.toLowerCase().startsWith(context.query)); + } + return [{ label: "Today" }, { label: "Yesterday" }, { label: "Tomorrow" }].filter((items) => items.label.toLowerCase().startsWith(context.query)); + } + renderSuggestion(suggestion, el) { + el.setText(suggestion.label); + } + selectSuggestion(suggestion, event) { + const { editor } = this.context; + const includeAlias = event.shiftKey; + let dateStr = ""; + let makeIntoLink = this.plugin.settings.autosuggestToggleLink; + if (suggestion.label.startsWith("time:")) { + const timePart = suggestion.label.substring(5); + dateStr = this.plugin.parseTime(timePart).formattedString; + makeIntoLink = false; + } + else { + dateStr = this.plugin.parseDate(suggestion.label).formattedString; + } + if (makeIntoLink) { + dateStr = generateMarkdownLink(this.app, dateStr, includeAlias ? suggestion.label : undefined); + } + editor.replaceRange(dateStr, this.context.start, this.context.end); + } + onTrigger(cursor, editor, file) { + var _a; + if (!this.plugin.settings.isAutosuggestEnabled) { + return null; + } + const triggerPhrase = this.plugin.settings.autocompleteTriggerPhrase; + const startPos = ((_a = this.context) === null || _a === void 0 ? void 0 : _a.start) || { + line: cursor.line, + ch: cursor.ch - triggerPhrase.length, + }; + if (!editor.getRange(startPos, cursor).startsWith(triggerPhrase)) { + return null; + } + const precedingChar = editor.getRange({ + line: startPos.line, + ch: startPos.ch - 1, + }, startPos); + // Short-circuit if `@` as a part of a word (e.g. part of an email address) + if (precedingChar && /[`a-zA-Z0-9]/.test(precedingChar)) { + return null; + } + return { + start: startPos, + end: cursor, + query: editor.getRange(startPos, cursor).substring(triggerPhrase.length), + }; + } +} + +function getParseCommand(plugin, mode) { + const { workspace } = plugin.app; + const activeView = workspace.getActiveViewOfType(require$$0$1.MarkdownView); + // The active view might not be a markdown view + if (!activeView) { + return; + } + const editor = activeView.editor; + const cursor = editor.getCursor(); + const selectedText = getSelectedText(editor); + const date = plugin.parseDate(selectedText); + if (!date.moment.isValid()) { + // Do nothing + editor.setCursor({ + line: cursor.line, + ch: cursor.ch, + }); + return; + } + //mode == "replace" + let newStr = `[[${date.formattedString}]]`; + if (mode == "link") { + newStr = `[${selectedText}](${date.formattedString})`; + } + else if (mode == "clean") { + newStr = `${date.formattedString}`; + } + else if (mode == "time") { + const time = plugin.parseTime(selectedText); + newStr = `${time.formattedString}`; + } + editor.replaceSelection(newStr); + adjustCursor(editor, cursor, newStr, selectedText); + editor.focus(); +} +function insertMomentCommand(plugin, date, format) { + const { workspace } = plugin.app; + const activeView = workspace.getActiveViewOfType(require$$0$1.MarkdownView); + if (activeView) { + // The active view might not be a markdown view + const editor = activeView.editor; + editor.replaceSelection(window.moment(date).format(format)); + } +} +function getNowCommand(plugin) { + const format = `${plugin.settings.format}${plugin.settings.separator}${plugin.settings.timeFormat}`; + const date = new Date(); + insertMomentCommand(plugin, date, format); +} +function getCurrentDateCommand(plugin) { + const format = plugin.settings.format; + const date = new Date(); + insertMomentCommand(plugin, date, format); +} +function getCurrentTimeCommand(plugin) { + const format = plugin.settings.timeFormat; + const date = new Date(); + insertMomentCommand(plugin, date, format); +} + +class NaturalLanguageDates extends require$$0$1.Plugin { + onload() { + return __awaiter(this, void 0, void 0, function* () { + yield this.loadSettings(); + this.addCommand({ + id: "nlp-dates", + name: "Parse natural language date", + callback: () => getParseCommand(this, "replace"), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-dates-link", + name: "Parse natural language date (as link)", + callback: () => getParseCommand(this, "link"), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-date-clean", + name: "Parse natural language date (as plain text)", + callback: () => getParseCommand(this, "clean"), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-parse-time", + name: "Parse natural language time", + callback: () => getParseCommand(this, "time"), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-now", + name: "Insert the current date and time", + callback: () => getNowCommand(this), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-today", + name: "Insert the current date", + callback: () => getCurrentDateCommand(this), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-time", + name: "Insert the current time", + callback: () => getCurrentTimeCommand(this), + hotkeys: [], + }); + this.addCommand({ + id: "nlp-picker", + name: "Date picker", + checkCallback: (checking) => { + if (checking) { + return !!this.app.workspace.getActiveViewOfType(require$$0$1.MarkdownView); + } + new DatePickerModal(this.app, this).open(); + }, + hotkeys: [], + }); + this.addSettingTab(new NLDSettingsTab(this.app, this)); + this.registerObsidianProtocolHandler("nldates", this.actionHandler.bind(this)); + this.registerEditorSuggest(new DateSuggest(this.app, this)); + this.app.workspace.onLayoutReady(() => { + // initialize the parser when layout is ready so that the correct locale is used + this.parser = new NLDParser(); + }); + }); + } + onunload() { + console.log("Unloading natural language date parser plugin"); + } + loadSettings() { + return __awaiter(this, void 0, void 0, function* () { + this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData()); + }); + } + saveSettings() { + return __awaiter(this, void 0, void 0, function* () { + yield this.saveData(this.settings); + }); + } + /* + @param dateString: A string that contains a date in natural language, e.g. today, tomorrow, next week + @param format: A string that contains the formatting string for a Moment + @returns NLDResult: An object containing the date, a cloned Moment and the formatted string. + */ + parse(dateString, format) { + const date = this.parser.getParsedDate(dateString, this.settings.weekStart); + const formattedString = getFormattedDate(date, format); + if (formattedString === "Invalid date") { + console.debug("Input date " + dateString + " can't be parsed by nldates"); + } + return { + formattedString, + date, + moment: window.moment(date), + }; + } + /* + @param dateString: A string that contains a date in natural language, e.g. today, tomorrow, next week + @returns NLDResult: An object containing the date, a cloned Moment and the formatted string. + */ + parseDate(dateString) { + return this.parse(dateString, this.settings.format); + } + parseTime(dateString) { + return this.parse(dateString, this.settings.timeFormat); + } + actionHandler(params) { + return __awaiter(this, void 0, void 0, function* () { + const { workspace } = this.app; + const date = this.parseDate(params.day); + const newPane = parseTruthy(params.newPane || "yes"); + if (date.moment.isValid()) { + const dailyNote = yield getOrCreateDailyNote(date.moment); + workspace.getLeaf(newPane).openFile(dailyNote); + } + }); + } +} + +module.exports = NaturalLanguageDates; + + +/* nosourcemap */ \ No newline at end of file diff --git a/.obsidian/plugins/nldates-obsidian/manifest.json b/.obsidian/plugins/nldates-obsidian/manifest.json new file mode 100644 index 0000000..ef47c07 --- /dev/null +++ b/.obsidian/plugins/nldates-obsidian/manifest.json @@ -0,0 +1,10 @@ +{ + "id": "nldates-obsidian", + "name": "Natural Language Dates", + "description": "Create date-links based on natural language", + "version": "0.6.2", + "author": "Argentina Ortega Sainz", + "authorUrl": "https://argentinaos.com/", + "isDesktopOnly": false, + "minAppVersion": "1.0.0" +} diff --git a/.obsidian/plugins/obsidian42-brat/data.json b/.obsidian/plugins/obsidian42-brat/data.json new file mode 100644 index 0000000..cbcf2e4 --- /dev/null +++ b/.obsidian/plugins/obsidian42-brat/data.json @@ -0,0 +1,16 @@ +{ + "pluginList": [ + "reply2za/obsidian-query-control" + ], + "pluginSubListFrozenVersion": [], + "themesList": [], + "updateAtStartup": true, + "updateThemesAtStartup": true, + "enableAfterInstall": true, + "loggingEnabled": false, + "loggingPath": "BRAT-log", + "loggingVerboseEnabled": false, + "debuggingMode": false, + "notificationsEnabled": true, + "personalAccessToken": "" +} \ No newline at end of file diff --git a/.obsidian/plugins/obsidian42-brat/main.js b/.obsidian/plugins/obsidian42-brat/main.js new file mode 100644 index 0000000..9f4007f --- /dev/null +++ b/.obsidian/plugins/obsidian42-brat/main.js @@ -0,0 +1,2422 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __commonJS = (cb, mod) => function __require() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// node_modules/obsidian-daily-notes-interface/dist/main.js +var require_main = __commonJS({ + "node_modules/obsidian-daily-notes-interface/dist/main.js"(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var obsidian = require("obsidian"); + var DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD"; + var DEFAULT_WEEKLY_NOTE_FORMAT = "gggg-[W]ww"; + var DEFAULT_MONTHLY_NOTE_FORMAT = "YYYY-MM"; + var DEFAULT_QUARTERLY_NOTE_FORMAT = "YYYY-[Q]Q"; + var DEFAULT_YEARLY_NOTE_FORMAT = "YYYY"; + function shouldUsePeriodicNotesSettings(periodicity) { + var _a, _b; + const periodicNotes = window.app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a[periodicity]) == null ? void 0 : _b.enabled); + } + function getDailyNoteSettings2() { + var _a, _b, _c, _d; + try { + const { internalPlugins, plugins } = window.app; + if (shouldUsePeriodicNotesSettings("daily")) { + const { format: format2, folder: folder2, template: template2 } = ((_b = (_a = plugins.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.daily) || {}; + return { + format: format2 || DEFAULT_DAILY_NOTE_FORMAT, + folder: (folder2 == null ? void 0 : folder2.trim()) || "", + template: (template2 == null ? void 0 : template2.trim()) || "" + }; + } + const { folder, format, template } = ((_d = (_c = internalPlugins.getPluginById("daily-notes")) == null ? void 0 : _c.instance) == null ? void 0 : _d.options) || {}; + return { + format: format || DEFAULT_DAILY_NOTE_FORMAT, + folder: (folder == null ? void 0 : folder.trim()) || "", + template: (template == null ? void 0 : template.trim()) || "" + }; + } catch (err) { + console.info("No custom daily note settings found!", err); + } + } + function getWeeklyNoteSettings() { + var _a, _b, _c, _d, _e, _f, _g; + try { + const pluginManager = window.app.plugins; + const calendarSettings = (_a = pluginManager.getPlugin("calendar")) == null ? void 0 : _a.options; + const periodicNotesSettings = (_c = (_b = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _b.settings) == null ? void 0 : _c.weekly; + if (shouldUsePeriodicNotesSettings("weekly")) { + return { + format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: ((_d = periodicNotesSettings.folder) == null ? void 0 : _d.trim()) || "", + template: ((_e = periodicNotesSettings.template) == null ? void 0 : _e.trim()) || "" + }; + } + const settings = calendarSettings || {}; + return { + format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT, + folder: ((_f = settings.weeklyNoteFolder) == null ? void 0 : _f.trim()) || "", + template: ((_g = settings.weeklyNoteTemplate) == null ? void 0 : _g.trim()) || "" + }; + } catch (err) { + console.info("No custom weekly note settings found!", err); + } + } + function getMonthlyNoteSettings() { + var _a, _b, _c, _d; + const pluginManager = window.app.plugins; + try { + const settings = shouldUsePeriodicNotesSettings("monthly") && ((_b = (_a = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.monthly) || {}; + return { + format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT, + folder: ((_c = settings.folder) == null ? void 0 : _c.trim()) || "", + template: ((_d = settings.template) == null ? void 0 : _d.trim()) || "" + }; + } catch (err) { + console.info("No custom monthly note settings found!", err); + } + } + function getQuarterlyNoteSettings() { + var _a, _b, _c, _d; + const pluginManager = window.app.plugins; + try { + const settings = shouldUsePeriodicNotesSettings("quarterly") && ((_b = (_a = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.quarterly) || {}; + return { + format: settings.format || DEFAULT_QUARTERLY_NOTE_FORMAT, + folder: ((_c = settings.folder) == null ? void 0 : _c.trim()) || "", + template: ((_d = settings.template) == null ? void 0 : _d.trim()) || "" + }; + } catch (err) { + console.info("No custom quarterly note settings found!", err); + } + } + function getYearlyNoteSettings() { + var _a, _b, _c, _d; + const pluginManager = window.app.plugins; + try { + const settings = shouldUsePeriodicNotesSettings("yearly") && ((_b = (_a = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.yearly) || {}; + return { + format: settings.format || DEFAULT_YEARLY_NOTE_FORMAT, + folder: ((_c = settings.folder) == null ? void 0 : _c.trim()) || "", + template: ((_d = settings.template) == null ? void 0 : _d.trim()) || "" + }; + } catch (err) { + console.info("No custom yearly note settings found!", err); + } + } + function join(...partSegments) { + let parts = []; + for (let i = 0, l = partSegments.length; i < l; i++) { + parts = parts.concat(partSegments[i].split("/")); + } + const newParts = []; + for (let i = 0, l = parts.length; i < l; i++) { + const part = parts[i]; + if (!part || part === ".") + continue; + else + newParts.push(part); + } + if (parts[0] === "") + newParts.unshift(""); + return newParts.join("/"); + } + function basename(fullPath) { + let base = fullPath.substring(fullPath.lastIndexOf("/") + 1); + if (base.lastIndexOf(".") != -1) + base = base.substring(0, base.lastIndexOf(".")); + return base; + } + async function ensureFolderExists(path) { + const dirs = path.replace(/\\/g, "/").split("/"); + dirs.pop(); + if (dirs.length) { + const dir = join(...dirs); + if (!window.app.vault.getAbstractFileByPath(dir)) { + await window.app.vault.createFolder(dir); + } + } + } + async function getNotePath(directory, filename) { + if (!filename.endsWith(".md")) { + filename += ".md"; + } + const path = obsidian.normalizePath(join(directory, filename)); + await ensureFolderExists(path); + return path; + } + async function getTemplateInfo(template) { + const { metadataCache, vault } = window.app; + const templatePath = obsidian.normalizePath(template); + if (templatePath === "/") { + return Promise.resolve(["", null]); + } + try { + const templateFile = metadataCache.getFirstLinkpathDest(templatePath, ""); + const contents = await vault.cachedRead(templateFile); + const IFoldInfo = window.app.foldManager.load(templateFile); + return [contents, IFoldInfo]; + } catch (err) { + console.error(`Failed to read the daily note template '${templatePath}'`, err); + new obsidian.Notice("Failed to read the daily note template"); + return ["", null]; + } + } + function getDateUID(date, granularity = "day") { + const ts = date.clone().startOf(granularity).format(); + return `${granularity}-${ts}`; + } + function removeEscapedCharacters(format) { + return format.replace(/\[[^\]]*\]/g, ""); + } + function isFormatAmbiguous(format, granularity) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + return /w{1,2}/i.test(cleanFormat) && (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat)); + } + return false; + } + function getDateFromFile(file, granularity) { + return getDateFromFilename(file.basename, granularity); + } + function getDateFromPath(path, granularity) { + return getDateFromFilename(basename(path), granularity); + } + function getDateFromFilename(filename, granularity) { + const getSettings = { + day: getDailyNoteSettings2, + week: getWeeklyNoteSettings, + month: getMonthlyNoteSettings, + quarter: getQuarterlyNoteSettings, + year: getYearlyNoteSettings + }; + const format = getSettings[granularity]().format.split("/").pop(); + const noteDate = window.moment(filename, format, true); + if (!noteDate.isValid()) { + return null; + } + if (isFormatAmbiguous(format, granularity)) { + if (granularity === "week") { + const cleanFormat = removeEscapedCharacters(format); + if (/w{1,2}/i.test(cleanFormat)) { + return window.moment( + filename, + // If format contains week, remove day & month formatting + format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""), + false + ); + } + } + } + return noteDate; + } + var DailyNotesFolderMissingError = class extends Error { + }; + async function createDailyNote(date) { + const app = window.app; + const { vault } = app; + const moment2 = window.moment; + const { template, format, folder } = getDailyNoteSettings2(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, moment2().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename).replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = moment2(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second") + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }).replace(/{{\s*yesterday\s*}}/gi, date.clone().subtract(1, "day").format(format)).replace(/{{\s*tomorrow\s*}}/gi, date.clone().add(1, "d").format(format))); + app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } + } + function getDailyNote(date, dailyNotes) { + var _a; + return (_a = dailyNotes[getDateUID(date, "day")]) != null ? _a : null; + } + function getAllDailyNotes() { + const { vault } = window.app; + const { folder } = getDailyNoteSettings2(); + const dailyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!dailyNotesFolder) { + throw new DailyNotesFolderMissingError("Failed to find daily notes folder"); + } + const dailyNotes = {}; + obsidian.Vault.recurseChildren(dailyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "day"); + if (date) { + const dateString = getDateUID(date, "day"); + dailyNotes[dateString] = note; + } + } + }); + return dailyNotes; + } + var WeeklyNotesFolderMissingError = class extends Error { + }; + function getDaysOfWeek() { + const { moment: moment2 } = window; + let weekStart = moment2.localeData()._week.dow; + const daysOfWeek = [ + "sunday", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday" + ]; + while (weekStart) { + daysOfWeek.push(daysOfWeek.shift()); + weekStart--; + } + return daysOfWeek; + } + function getDayOfWeekNumericalValue(dayOfWeekName) { + return getDaysOfWeek().indexOf(dayOfWeekName.toLowerCase()); + } + async function createWeeklyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getWeeklyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second") + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }).replace(/{{\s*title\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi, (_, dayOfWeek, momentFormat) => { + const day = getDayOfWeekNumericalValue(dayOfWeek); + return date.weekday(day).format(momentFormat.trim()); + })); + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } + } + function getWeeklyNote(date, weeklyNotes) { + var _a; + return (_a = weeklyNotes[getDateUID(date, "week")]) != null ? _a : null; + } + function getAllWeeklyNotes() { + const weeklyNotes = {}; + if (!appHasWeeklyNotesPluginLoaded()) { + return weeklyNotes; + } + const { vault } = window.app; + const { folder } = getWeeklyNoteSettings(); + const weeklyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!weeklyNotesFolder) { + throw new WeeklyNotesFolderMissingError("Failed to find weekly notes folder"); + } + obsidian.Vault.recurseChildren(weeklyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "week"); + if (date) { + const dateString = getDateUID(date, "week"); + weeklyNotes[dateString] = note; + } + } + }); + return weeklyNotes; + } + var MonthlyNotesFolderMissingError = class extends Error { + }; + async function createMonthlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getMonthlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second") + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }).replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename)); + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } + } + function getMonthlyNote(date, monthlyNotes) { + var _a; + return (_a = monthlyNotes[getDateUID(date, "month")]) != null ? _a : null; + } + function getAllMonthlyNotes() { + const monthlyNotes = {}; + if (!appHasMonthlyNotesPluginLoaded()) { + return monthlyNotes; + } + const { vault } = window.app; + const { folder } = getMonthlyNoteSettings(); + const monthlyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!monthlyNotesFolder) { + throw new MonthlyNotesFolderMissingError("Failed to find monthly notes folder"); + } + obsidian.Vault.recurseChildren(monthlyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "month"); + if (date) { + const dateString = getDateUID(date, "month"); + monthlyNotes[dateString] = note; + } + } + }); + return monthlyNotes; + } + var QuarterlyNotesFolderMissingError = class extends Error { + }; + async function createQuarterlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getQuarterlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second") + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }).replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename)); + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } + } + function getQuarterlyNote(date, quarterly) { + var _a; + return (_a = quarterly[getDateUID(date, "quarter")]) != null ? _a : null; + } + function getAllQuarterlyNotes() { + const quarterly = {}; + if (!appHasQuarterlyNotesPluginLoaded()) { + return quarterly; + } + const { vault } = window.app; + const { folder } = getQuarterlyNoteSettings(); + const quarterlyFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!quarterlyFolder) { + throw new QuarterlyNotesFolderMissingError("Failed to find quarterly notes folder"); + } + obsidian.Vault.recurseChildren(quarterlyFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "quarter"); + if (date) { + const dateString = getDateUID(date, "quarter"); + quarterly[dateString] = note; + } + } + }); + return quarterly; + } + var YearlyNotesFolderMissingError = class extends Error { + }; + async function createYearlyNote(date) { + const { vault } = window.app; + const { template, format, folder } = getYearlyNoteSettings(); + const [templateContents, IFoldInfo] = await getTemplateInfo(template); + const filename = date.format(format); + const normalizedPath = await getNotePath(folder, filename); + try { + const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => { + const now = window.moment(); + const currentDate = date.clone().set({ + hour: now.get("hour"), + minute: now.get("minute"), + second: now.get("second") + }); + if (calc) { + currentDate.add(parseInt(timeDelta, 10), unit); + } + if (momentFormat) { + return currentDate.format(momentFormat.substring(1).trim()); + } + return currentDate.format(format); + }).replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename)); + window.app.foldManager.save(createdFile, IFoldInfo); + return createdFile; + } catch (err) { + console.error(`Failed to create file: '${normalizedPath}'`, err); + new obsidian.Notice("Unable to create new file."); + } + } + function getYearlyNote(date, yearlyNotes) { + var _a; + return (_a = yearlyNotes[getDateUID(date, "year")]) != null ? _a : null; + } + function getAllYearlyNotes() { + const yearlyNotes = {}; + if (!appHasYearlyNotesPluginLoaded()) { + return yearlyNotes; + } + const { vault } = window.app; + const { folder } = getYearlyNoteSettings(); + const yearlyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder)); + if (!yearlyNotesFolder) { + throw new YearlyNotesFolderMissingError("Failed to find yearly notes folder"); + } + obsidian.Vault.recurseChildren(yearlyNotesFolder, (note) => { + if (note instanceof obsidian.TFile) { + const date = getDateFromFile(note, "year"); + if (date) { + const dateString = getDateUID(date, "year"); + yearlyNotes[dateString] = note; + } + } + }); + return yearlyNotes; + } + function appHasDailyNotesPluginLoaded() { + var _a, _b; + const { app } = window; + const dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"]; + if (dailyNotesPlugin && dailyNotesPlugin.enabled) { + return true; + } + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.daily) == null ? void 0 : _b.enabled); + } + function appHasWeeklyNotesPluginLoaded() { + var _a, _b; + const { app } = window; + if (app.plugins.getPlugin("calendar")) { + return true; + } + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.weekly) == null ? void 0 : _b.enabled); + } + function appHasMonthlyNotesPluginLoaded() { + var _a, _b; + const { app } = window; + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.monthly) == null ? void 0 : _b.enabled); + } + function appHasQuarterlyNotesPluginLoaded() { + var _a, _b; + const { app } = window; + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.quarterly) == null ? void 0 : _b.enabled); + } + function appHasYearlyNotesPluginLoaded() { + var _a, _b; + const { app } = window; + const periodicNotes = app.plugins.getPlugin("periodic-notes"); + return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.yearly) == null ? void 0 : _b.enabled); + } + function getPeriodicNoteSettings(granularity) { + const getSettings = { + day: getDailyNoteSettings2, + week: getWeeklyNoteSettings, + month: getMonthlyNoteSettings, + quarter: getQuarterlyNoteSettings, + year: getYearlyNoteSettings + }[granularity]; + return getSettings(); + } + function createPeriodicNote(granularity, date) { + const createFn = { + day: createDailyNote, + month: createMonthlyNote, + week: createWeeklyNote + }; + return createFn[granularity](date); + } + exports.DEFAULT_DAILY_NOTE_FORMAT = DEFAULT_DAILY_NOTE_FORMAT; + exports.DEFAULT_MONTHLY_NOTE_FORMAT = DEFAULT_MONTHLY_NOTE_FORMAT; + exports.DEFAULT_QUARTERLY_NOTE_FORMAT = DEFAULT_QUARTERLY_NOTE_FORMAT; + exports.DEFAULT_WEEKLY_NOTE_FORMAT = DEFAULT_WEEKLY_NOTE_FORMAT; + exports.DEFAULT_YEARLY_NOTE_FORMAT = DEFAULT_YEARLY_NOTE_FORMAT; + exports.appHasDailyNotesPluginLoaded = appHasDailyNotesPluginLoaded; + exports.appHasMonthlyNotesPluginLoaded = appHasMonthlyNotesPluginLoaded; + exports.appHasQuarterlyNotesPluginLoaded = appHasQuarterlyNotesPluginLoaded; + exports.appHasWeeklyNotesPluginLoaded = appHasWeeklyNotesPluginLoaded; + exports.appHasYearlyNotesPluginLoaded = appHasYearlyNotesPluginLoaded; + exports.createDailyNote = createDailyNote; + exports.createMonthlyNote = createMonthlyNote; + exports.createPeriodicNote = createPeriodicNote; + exports.createQuarterlyNote = createQuarterlyNote; + exports.createWeeklyNote = createWeeklyNote; + exports.createYearlyNote = createYearlyNote; + exports.getAllDailyNotes = getAllDailyNotes; + exports.getAllMonthlyNotes = getAllMonthlyNotes; + exports.getAllQuarterlyNotes = getAllQuarterlyNotes; + exports.getAllWeeklyNotes = getAllWeeklyNotes; + exports.getAllYearlyNotes = getAllYearlyNotes; + exports.getDailyNote = getDailyNote; + exports.getDailyNoteSettings = getDailyNoteSettings2; + exports.getDateFromFile = getDateFromFile; + exports.getDateFromPath = getDateFromPath; + exports.getDateUID = getDateUID; + exports.getMonthlyNote = getMonthlyNote; + exports.getMonthlyNoteSettings = getMonthlyNoteSettings; + exports.getPeriodicNoteSettings = getPeriodicNoteSettings; + exports.getQuarterlyNote = getQuarterlyNote; + exports.getQuarterlyNoteSettings = getQuarterlyNoteSettings; + exports.getTemplateInfo = getTemplateInfo; + exports.getWeeklyNote = getWeeklyNote; + exports.getWeeklyNoteSettings = getWeeklyNoteSettings; + exports.getYearlyNote = getYearlyNote; + exports.getYearlyNoteSettings = getYearlyNoteSettings; + } +}); + +// src/main.ts +var main_exports = {}; +__export(main_exports, { + default: () => ThePlugin +}); +module.exports = __toCommonJS(main_exports); +var import_obsidian11 = require("obsidian"); + +// src/ui/SettingsTab.ts +var import_obsidian5 = require("obsidian"); + +// src/features/themes.ts +var import_obsidian3 = require("obsidian"); + +// src/features/githubUtils.ts +var import_obsidian = require("obsidian"); +var GITHUB_RAW_USERCONTENT_PATH = "https://raw.githubusercontent.com/"; +var isPrivateRepo = async (repository, debugLogging = true, personalAccessToken = "") => { + const URL2 = `https://api.github.com/repos/${repository}`; + try { + const response = await (0, import_obsidian.request)({ + url: URL2, + headers: personalAccessToken ? { + Authorization: `Token ${personalAccessToken}` + } : {} + }); + const data = await JSON.parse(response); + return data.private; + } catch (e) { + if (debugLogging) console.log("error in isPrivateRepo", URL2, e); + return false; + } +}; +var grabReleaseFileFromRepository = async (repository, version, fileName, debugLogging = true, personalAccessToken = "") => { + try { + const isPrivate = await isPrivateRepo(repository, debugLogging, personalAccessToken); + if (isPrivate) { + const URL2 = `https://api.github.com/repos/${repository}/releases`; + const response = await (0, import_obsidian.request)({ + url: URL2, + headers: { + Authorization: `Token ${personalAccessToken}` + } + }); + const data = await JSON.parse(response); + const release = data.find((release2) => release2.tag_name === version); + if (!release) { + return null; + } + const asset = release.assets.find( + (asset2) => asset2.name === fileName + ); + if (!asset) { + return null; + } + const download = await (0, import_obsidian.request)({ + url: asset.url, + headers: { + Authorization: `Token ${personalAccessToken}`, + Accept: "application/octet-stream" + } + }); + return download === "Not Found" || download === `{"error":"Not Found"}` ? null : download; + } else { + const URL2 = `https://github.com/${repository}/releases/download/${version}/${fileName}`; + const download = await (0, import_obsidian.request)({ + url: URL2, + headers: personalAccessToken ? { + Authorization: `Token ${personalAccessToken}` + } : {} + }); + return download === "Not Found" || download === `{"error":"Not Found"}` ? null : download; + } + } catch (error) { + if (debugLogging) console.log("error in grabReleaseFileFromRepository", URL, error); + return null; + } +}; +var grabManifestJsonFromRepository = async (repositoryPath, rootManifest = true, debugLogging = true, personalAccessToken = "") => { + const manifestJsonPath = GITHUB_RAW_USERCONTENT_PATH + repositoryPath + (rootManifest ? "/HEAD/manifest.json" : "/HEAD/manifest-beta.json"); + if (debugLogging) + console.log("grabManifestJsonFromRepository manifestJsonPath", manifestJsonPath); + const isTokenValid = async (token) => { + try { + await (0, import_obsidian.request)({ + url: "https://api.github.com/user", + method: "GET", + headers: { + "Authorization": `token ${token}`, + "User-Agent": "request", + "accept": "application/vnd.github.v3+json" + } + }); + return true; + } catch (error) { + if (debugLogging) console.log("Token validation error:", error); + return false; + } + }; + let tokenValid = false; + if (personalAccessToken) { + tokenValid = await isTokenValid(personalAccessToken); + if (debugLogging) console.log("Token valid:", tokenValid); + } + try { + const response = await (0, import_obsidian.request)({ + url: manifestJsonPath, + headers: tokenValid ? { + Authorization: `Token ${personalAccessToken}` + } : {} + }); + if (debugLogging) console.log("grabManifestJsonFromRepository response", response); + return response === "404: Not Found" ? null : await JSON.parse(response); + } catch (error) { + if (error !== "Error: Request failed, status 404" && debugLogging) { + console.log( + `error in grabManifestJsonFromRepository for ${manifestJsonPath}`, + error + ); + } + return null; + } +}; +var grabCommmunityPluginList = async (debugLogging = true) => { + const pluginListUrl = `https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-plugins.json`; + try { + const response = await (0, import_obsidian.request)({ url: pluginListUrl }); + return response === "404: Not Found" ? null : await JSON.parse(response); + } catch (error) { + if (debugLogging) console.log("error in grabCommmunityPluginList", error); + return null; + } +}; +var grabCommmunityThemesList = async (debugLogging = true) => { + const themesUrl = `https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json`; + try { + const response = await (0, import_obsidian.request)({ url: themesUrl }); + return response === "404: Not Found" ? null : await JSON.parse(response); + } catch (error) { + if (debugLogging) console.log("error in grabCommmunityThemesList", error); + return null; + } +}; +var grabCommmunityThemeCssFile = async (repositoryPath, betaVersion = false, debugLogging) => { + const themesUrl = `https://raw.githubusercontent.com/${repositoryPath}/HEAD/theme${betaVersion ? "-beta" : ""}.css`; + try { + const response = await (0, import_obsidian.request)({ url: themesUrl }); + return response === "404: Not Found" ? null : response; + } catch (error) { + if (debugLogging) console.log("error in grabCommmunityThemeCssFile", error); + return null; + } +}; +var grabCommmunityThemeManifestFile = async (repositoryPath, debugLogging = true) => { + const themesUrl = `https://raw.githubusercontent.com/${repositoryPath}/HEAD/manifest.json`; + try { + const response = await (0, import_obsidian.request)({ url: themesUrl }); + return response === "404: Not Found" ? null : response; + } catch (error) { + if (debugLogging) console.log("error in grabCommmunityThemeManifestFile", error); + return null; + } +}; +var checksum = (str) => { + let sum = 0; + for (let i = 0; i < str.length; i++) { + sum += str.charCodeAt(i); + } + return sum; +}; +var checksumForString = (str) => { + return checksum(str).toString(); +}; +var grabChecksumOfThemeCssFile = async (repositoryPath, betaVersion, debugLogging) => { + const themeCss = await grabCommmunityThemeCssFile( + repositoryPath, + betaVersion, + debugLogging + ); + return themeCss ? checksumForString(themeCss) : "0"; +}; +var grabLastCommitInfoForFile = async (repositoryPath, path, debugLogging = true) => { + const url = `https://api.github.com/repos/${repositoryPath}/commits?path=${path}&page=1&per_page=1`; + try { + const response = await (0, import_obsidian.request)({ url }); + return response === "404: Not Found" ? null : JSON.parse(response); + } catch (error) { + if (debugLogging) console.log("error in grabLastCommitInfoForAFile", error); + return null; + } +}; +var grabLastCommitDateForFile = async (repositoryPath, path) => { + var _a; + const test = await grabLastCommitInfoForFile(repositoryPath, path); + if (test && test.length > 0 && ((_a = test[0].commit.committer) == null ? void 0 : _a.date)) { + return test[0].commit.committer.date; + } else { + return ""; + } +}; + +// src/settings.ts +var DEFAULT_SETTINGS = { + pluginList: [], + pluginSubListFrozenVersion: [], + themesList: [], + updateAtStartup: true, + updateThemesAtStartup: true, + enableAfterInstall: true, + loggingEnabled: false, + loggingPath: "BRAT-log", + loggingVerboseEnabled: false, + debuggingMode: false, + notificationsEnabled: true, + personalAccessToken: "" +}; +function addBetaPluginToList(plugin, repositoryPath, specifyVersion = "") { + let save = false; + if (!plugin.settings.pluginList.contains(repositoryPath)) { + plugin.settings.pluginList.unshift(repositoryPath); + save = true; + } + if (specifyVersion !== "" && plugin.settings.pluginSubListFrozenVersion.filter((x) => x.repo === repositoryPath).length === 0) { + plugin.settings.pluginSubListFrozenVersion.unshift({ + repo: repositoryPath, + version: specifyVersion + }); + save = true; + } + if (save) { + void plugin.saveSettings(); + } +} +function existBetaPluginInList(plugin, repositoryPath) { + return plugin.settings.pluginList.contains(repositoryPath); +} +function addBetaThemeToList(plugin, repositoryPath, themeCss) { + const newTheme = { + repo: repositoryPath, + lastUpdate: checksumForString(themeCss) + }; + plugin.settings.themesList.unshift(newTheme); + void plugin.saveSettings(); +} +function existBetaThemeinInList(plugin, repositoryPath) { + const testIfThemExists = plugin.settings.themesList.find( + (t) => t.repo === repositoryPath + ); + return testIfThemExists ? true : false; +} +function updateBetaThemeLastUpdateChecksum(plugin, repositoryPath, checksum2) { + plugin.settings.themesList.forEach((t) => { + if (t.repo === repositoryPath) { + t.lastUpdate = checksum2; + void plugin.saveSettings(); + } + }); +} + +// src/utils/notifications.ts +var import_obsidian2 = require("obsidian"); +function toastMessage(plugin, msg, timeoutInSeconds = 10, contextMenuCallback) { + if (!plugin.settings.notificationsEnabled) return; + const additionalInfo = contextMenuCallback ? import_obsidian2.Platform.isDesktop ? "(click=dismiss, right-click=Info)" : "(click=dismiss)" : ""; + const newNotice = new import_obsidian2.Notice( + `BRAT +${msg} +${additionalInfo}`, + timeoutInSeconds * 1e3 + ); + if (contextMenuCallback) + newNotice.noticeEl.oncontextmenu = () => { + contextMenuCallback(); + }; +} + +// src/utils/internetconnection.ts +async function isConnectedToInternet() { + try { + const online = await fetch("https://obsidian.md/?" + Math.random()); + return online.status >= 200 && online.status < 300; + } catch (err) { + return false; + } +} + +// src/features/themes.ts +var themeSave = async (plugin, cssGithubRepository, newInstall) => { + let themeCss = await grabCommmunityThemeCssFile( + cssGithubRepository, + true, + plugin.settings.debuggingMode + ); + if (!themeCss) + themeCss = await grabCommmunityThemeCssFile( + cssGithubRepository, + false, + plugin.settings.debuggingMode + ); + if (!themeCss) { + toastMessage( + plugin, + "There is no theme.css or theme-beta.css file in the root path of this repository, so there is no theme to install." + ); + return false; + } + const themeManifest = await grabCommmunityThemeManifestFile( + cssGithubRepository, + plugin.settings.debuggingMode + ); + if (!themeManifest) { + toastMessage( + plugin, + "There is no manifest.json file in the root path of this repository, so theme cannot be installed." + ); + return false; + } + const manifestInfo = await JSON.parse(themeManifest); + const themeTargetFolderPath = (0, import_obsidian3.normalizePath)(themesRootPath(plugin) + manifestInfo.name); + const { adapter } = plugin.app.vault; + if (!await adapter.exists(themeTargetFolderPath)) + await adapter.mkdir(themeTargetFolderPath); + await adapter.write((0, import_obsidian3.normalizePath)(themeTargetFolderPath + "/theme.css"), themeCss); + await adapter.write( + (0, import_obsidian3.normalizePath)(themeTargetFolderPath + "/manifest.json"), + themeManifest + ); + updateBetaThemeLastUpdateChecksum( + plugin, + cssGithubRepository, + checksumForString(themeCss) + ); + let msg = ``; + if (newInstall) { + addBetaThemeToList(plugin, cssGithubRepository, themeCss); + msg = `${manifestInfo.name} theme installed from ${cssGithubRepository}. `; + setTimeout(() => { + plugin.app.customCss.setTheme(manifestInfo.name); + }, 500); + } else { + msg = `${manifestInfo.name} theme updated from ${cssGithubRepository}.`; + } + void plugin.log(msg + `[Theme Info](https://github.com/${cssGithubRepository})`, false); + toastMessage(plugin, msg, 20, () => { + window.open(`https://github.com/${cssGithubRepository}`); + }); + return true; +}; +var themesCheckAndUpdates = async (plugin, showInfo) => { + if (!await isConnectedToInternet()) { + console.log("BRAT: No internet detected."); + return; + } + let newNotice; + const msg1 = `Checking for beta theme updates STARTED`; + await plugin.log(msg1, true); + if (showInfo && plugin.settings.notificationsEnabled) + newNotice = new import_obsidian3.Notice(`BRAT +${msg1}`, 3e4); + for (const t of plugin.settings.themesList) { + let lastUpdateOnline = await grabChecksumOfThemeCssFile( + t.repo, + true, + plugin.settings.debuggingMode + ); + if (lastUpdateOnline === "0") + lastUpdateOnline = await grabChecksumOfThemeCssFile( + t.repo, + false, + plugin.settings.debuggingMode + ); + console.log("BRAT: lastUpdateOnline", lastUpdateOnline); + if (lastUpdateOnline !== t.lastUpdate) await themeSave(plugin, t.repo, false); + } + const msg2 = `Checking for beta theme updates COMPLETED`; + (async () => { + await plugin.log(msg2, true); + })(); + if (showInfo) { + if (plugin.settings.notificationsEnabled && newNotice) newNotice.hide(); + toastMessage(plugin, msg2); + } +}; +var themeDelete = (plugin, cssGithubRepository) => { + plugin.settings.themesList = plugin.settings.themesList.filter( + (t) => t.repo !== cssGithubRepository + ); + void plugin.saveSettings(); + const msg = `Removed ${cssGithubRepository} from BRAT themes list and will no longer be updated. However, the theme files still exist in the vault. To remove them, go into Settings > Appearance and remove the theme.`; + void plugin.log(msg, true); + toastMessage(plugin, msg); +}; +var themesRootPath = (plugin) => { + return (0, import_obsidian3.normalizePath)(plugin.app.vault.configDir + "/themes") + "/"; +}; + +// src/ui/AddNewTheme.ts +var import_obsidian4 = require("obsidian"); + +// src/ui/Promotional.ts +var promotionalLinks = (containerEl, settingsTab = true) => { + const linksDiv = containerEl.createEl("div"); + linksDiv.style.float = "right"; + if (!settingsTab) { + linksDiv.style.padding = "10px"; + linksDiv.style.paddingLeft = "15px"; + linksDiv.style.paddingRight = "15px"; + } else { + linksDiv.style.padding = "15px"; + linksDiv.style.paddingLeft = "15px"; + linksDiv.style.paddingRight = "15px"; + linksDiv.style.marginLeft = "15px"; + } + const twitterSpan = linksDiv.createDiv("coffee"); + twitterSpan.addClass("ex-twitter-span"); + twitterSpan.style.paddingLeft = "10px"; + const captionText = twitterSpan.createDiv(); + captionText.innerText = "Learn more about my work at:"; + twitterSpan.appendChild(captionText); + const twitterLink = twitterSpan.createEl("a", { href: "https://tfthacker.com" }); + twitterLink.innerText = "https://tfthacker.com"; + return linksDiv; +}; + +// src/ui/AddNewTheme.ts +var AddNewTheme = class extends import_obsidian4.Modal { + constructor(plugin, openSettingsTabAfterwards = false) { + super(plugin.app); + this.plugin = plugin; + this.address = ""; + this.openSettingsTabAfterwards = openSettingsTabAfterwards; + } + async submitForm() { + if (this.address === "") return; + const scrubbedAddress = this.address.replace("https://github.com/", ""); + if (existBetaThemeinInList(this.plugin, scrubbedAddress)) { + toastMessage(this.plugin, `This theme is already in the list for beta testing`, 10); + return; + } + if (await themeSave(this.plugin, scrubbedAddress, true)) { + this.close(); + } + } + onOpen() { + this.contentEl.createEl("h4", { text: "Github repository for beta theme:" }); + this.contentEl.createEl("form", {}, (formEl) => { + formEl.addClass("brat-modal"); + new import_obsidian4.Setting(formEl).addText((textEl) => { + textEl.setPlaceholder( + "Repository (example: https://github.com/GitubUserName/repository-name" + ); + textEl.setValue(this.address); + textEl.onChange((value) => { + this.address = value.trim(); + }); + textEl.inputEl.addEventListener("keydown", (e) => { + if (e.key === "Enter" && this.address !== " ") { + e.preventDefault(); + void this.submitForm(); + } + }); + textEl.inputEl.style.width = "100%"; + window.setTimeout(() => { + const title = document.querySelector(".setting-item-info"); + if (title) title.remove(); + textEl.inputEl.focus(); + }, 10); + }); + formEl.createDiv("modal-button-container", (buttonContainerEl) => { + buttonContainerEl.createEl("button", { attr: { type: "button" }, text: "Never mind" }).addEventListener("click", () => { + this.close(); + }); + buttonContainerEl.createEl("button", { + attr: { type: "submit" }, + cls: "mod-cta", + text: "Add Theme" + }); + }); + const newDiv = formEl.createDiv(); + newDiv.style.borderTop = "1px solid #ccc"; + newDiv.style.marginTop = "30px"; + const byTfThacker = newDiv.createSpan(); + byTfThacker.innerHTML = "BRAT by TFTHacker"; + byTfThacker.style.fontStyle = "italic"; + newDiv.appendChild(byTfThacker); + promotionalLinks(newDiv, false); + window.setTimeout(() => { + const title = formEl.querySelectorAll(".brat-modal .setting-item-info"); + title.forEach((titleEl) => { + titleEl.remove(); + }); + }, 50); + formEl.addEventListener("submit", (e) => { + e.preventDefault(); + if (this.address !== "") void this.submitForm(); + }); + }); + } + onClose() { + if (this.openSettingsTabAfterwards) { + this.plugin.app.setting.open(); + this.plugin.app.setting.openTabById(this.plugin.APP_ID); + } + } +}; + +// src/ui/SettingsTab.ts +var createLink = (githubResource, optionalText) => { + const newLink = new DocumentFragment(); + const linkElement = document.createElement("a"); + linkElement.textContent = githubResource; + linkElement.href = `https://github.com/${githubResource}`; + newLink.appendChild(linkElement); + if (optionalText) { + const textNode = document.createTextNode(optionalText); + newLink.appendChild(textNode); + } + return newLink; +}; +var BratSettingsTab = class extends import_obsidian5.PluginSettingTab { + constructor(app, plugin) { + super(app, plugin); + this.plugin = plugin; + } + display() { + const { containerEl } = this; + containerEl.empty(); + new import_obsidian5.Setting(containerEl).setName("Auto-enable plugins after installation").setDesc( + 'If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.' + ).addToggle((cb) => { + cb.setValue(this.plugin.settings.enableAfterInstall); + cb.onChange(async (value) => { + this.plugin.settings.enableAfterInstall = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Auto-update plugins at startup").setDesc( + "If enabled all beta plugins will be checked for updates each time Obsidian starts. Note: this does not update frozen version plugins." + ).addToggle((cb) => { + cb.setValue(this.plugin.settings.updateAtStartup); + cb.onChange(async (value) => { + this.plugin.settings.updateAtStartup = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Auto-update themes at startup").setDesc( + "If enabled all beta themes will be checked for updates each time Obsidian starts." + ).addToggle((cb) => { + cb.setValue(this.plugin.settings.updateThemesAtStartup); + cb.onChange(async (value) => { + this.plugin.settings.updateThemesAtStartup = value; + await this.plugin.saveSettings(); + }); + }); + promotionalLinks(containerEl, true); + containerEl.createEl("hr"); + containerEl.createEl("h2", { text: "Beta Plugin List" }); + containerEl.createEl("div", { + text: `The following is a list of beta plugins added via the command palette "Add a beta plugin for testing" or "Add a beta plugin with frozen version for testing". A frozen version is a specific release of a plugin based on its releease tag. ` + }); + containerEl.createEl("p"); + containerEl.createEl("div", { + text: `Click the x button next to a plugin to remove it from the list.` + }); + containerEl.createEl("p"); + containerEl.createEl("span").createEl("b", { text: "Note: " }); + containerEl.createSpan({ + text: "This does not delete the plugin, this should be done from the Community Plugins tab in Settings." + }); + new import_obsidian5.Setting(containerEl).addButton((cb) => { + cb.setButtonText("Add Beta plugin"); + cb.onClick(() => { + this.plugin.app.setting.close(); + this.plugin.betaPlugins.displayAddNewPluginModal(true, false); + }); + }); + const pluginSubListFrozenVersionNames = new Set( + this.plugin.settings.pluginSubListFrozenVersion.map((x) => x.repo) + ); + for (const bp of this.plugin.settings.pluginList) { + if (pluginSubListFrozenVersionNames.has(bp)) { + continue; + } + new import_obsidian5.Setting(containerEl).setName(createLink(bp)).addButton((btn) => { + btn.setIcon("cross"); + btn.setTooltip("Delete this beta plugin"); + btn.onClick(() => { + if (btn.buttonEl.textContent === "") + btn.setButtonText("Click once more to confirm removal"); + else { + const { buttonEl } = btn; + const { parentElement } = buttonEl; + if (parentElement == null ? void 0 : parentElement.parentElement) { + parentElement.parentElement.remove(); + this.plugin.betaPlugins.deletePlugin(bp); + } + } + }); + }); + } + new import_obsidian5.Setting(containerEl).addButton((cb) => { + cb.setButtonText("Add Beta plugin with frozen version"); + cb.onClick(() => { + this.plugin.app.setting.close(); + this.plugin.betaPlugins.displayAddNewPluginModal(true, true); + }); + }); + for (const bp of this.plugin.settings.pluginSubListFrozenVersion) { + new import_obsidian5.Setting(containerEl).setName(createLink(bp.repo, ` (version ${bp.version})`)).addButton((btn) => { + btn.setIcon("cross"); + btn.setTooltip("Delete this beta plugin"); + btn.onClick(() => { + if (btn.buttonEl.textContent === "") + btn.setButtonText("Click once more to confirm removal"); + else { + const { buttonEl } = btn; + const { parentElement } = buttonEl; + if (parentElement == null ? void 0 : parentElement.parentElement) { + parentElement.parentElement.remove(); + this.plugin.betaPlugins.deletePlugin(bp.repo); + } + } + }); + }); + } + containerEl.createEl("h2", { text: "Beta Themes List" }); + new import_obsidian5.Setting(containerEl).addButton((cb) => { + cb.setButtonText("Add Beta Theme"); + cb.onClick(() => { + this.plugin.app.setting.close(); + new AddNewTheme(this.plugin).open(); + }); + }); + for (const bp of this.plugin.settings.themesList) { + new import_obsidian5.Setting(containerEl).setName(createLink(bp.repo)).addButton((btn) => { + btn.setIcon("cross"); + btn.setTooltip("Delete this beta theme"); + btn.onClick(() => { + if (btn.buttonEl.textContent === "") + btn.setButtonText("Click once more to confirm removal"); + else { + const { buttonEl } = btn; + const { parentElement } = buttonEl; + if (parentElement == null ? void 0 : parentElement.parentElement) { + parentElement.parentElement.remove(); + themeDelete(this.plugin, bp.repo); + } + } + }); + }); + } + containerEl.createEl("h2", { text: "Monitoring" }); + new import_obsidian5.Setting(containerEl).setName("Enable Notifications").setDesc( + "BRAT will provide popup notifications for its various activities. Turn this off means no notifications from BRAT." + ).addToggle((cb) => { + cb.setValue(this.plugin.settings.notificationsEnabled); + cb.onChange(async (value) => { + this.plugin.settings.notificationsEnabled = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Enable Logging").setDesc("Plugin updates will be logged to a file in the log file.").addToggle((cb) => { + cb.setValue(this.plugin.settings.loggingEnabled); + cb.onChange(async (value) => { + this.plugin.settings.loggingEnabled = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(this.containerEl).setName("BRAT Log File Location").setDesc("Logs will be saved to this file. Don't add .md to the file name.").addSearch((cb) => { + cb.setPlaceholder("Example: BRAT-log").setValue(this.plugin.settings.loggingPath).onChange(async (newFolder) => { + this.plugin.settings.loggingPath = newFolder; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Enable Verbose Logging").setDesc("Get a lot more information in the log.").addToggle((cb) => { + cb.setValue(this.plugin.settings.loggingVerboseEnabled); + cb.onChange(async (value) => { + this.plugin.settings.loggingVerboseEnabled = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Debugging Mode").setDesc( + "Atomic Bomb level console logging. Can be used for troubleshoting and development." + ).addToggle((cb) => { + cb.setValue(this.plugin.settings.debuggingMode); + cb.onChange(async (value) => { + this.plugin.settings.debuggingMode = value; + await this.plugin.saveSettings(); + }); + }); + new import_obsidian5.Setting(containerEl).setName("Personal Access Token").setDesc( + "If you need to access private repositories, enter the personal access token here." + ).addText((text) => { + var _a; + text.setPlaceholder("Enter your personal access token").setValue((_a = this.plugin.settings.personalAccessToken) != null ? _a : "").onChange(async (value) => { + this.plugin.settings.personalAccessToken = value; + await this.plugin.saveSettings(); + }); + }); + } +}; + +// src/ui/AddNewPluginModal.ts +var import_obsidian6 = require("obsidian"); +var AddNewPluginModal = class extends import_obsidian6.Modal { + constructor(plugin, betaPlugins, openSettingsTabAfterwards = false, useFrozenVersion = false) { + super(plugin.app); + this.plugin = plugin; + this.betaPlugins = betaPlugins; + this.address = ""; + this.openSettingsTabAfterwards = openSettingsTabAfterwards; + this.useFrozenVersion = useFrozenVersion; + this.enableAfterInstall = plugin.settings.enableAfterInstall; + this.version = ""; + } + async submitForm() { + if (this.address === "") return; + let scrubbedAddress = this.address.replace("https://github.com/", ""); + if (scrubbedAddress.endsWith(".git")) scrubbedAddress = scrubbedAddress.slice(0, -4); + if (existBetaPluginInList(this.plugin, scrubbedAddress)) { + toastMessage( + this.plugin, + `This plugin is already in the list for beta testing`, + 10 + ); + return; + } + const result = await this.betaPlugins.addPlugin( + scrubbedAddress, + false, + false, + false, + this.version, + false, + this.enableAfterInstall + ); + if (result) { + this.close(); + } + } + onOpen() { + this.contentEl.createEl("h4", { text: "Github repository for beta plugin:" }); + this.contentEl.createEl("form", {}, (formEl) => { + formEl.addClass("brat-modal"); + new import_obsidian6.Setting(formEl).addText((textEl) => { + textEl.setPlaceholder( + "Repository (example: https://github.com/GitubUserName/repository-name)" + ); + textEl.setValue(this.address); + textEl.onChange((value) => { + this.address = value.trim(); + }); + textEl.inputEl.addEventListener("keydown", (e) => { + if (e.key === "Enter" && this.address !== " ") { + if (this.useFrozenVersion && this.version !== "" || !this.useFrozenVersion) { + e.preventDefault(); + void this.submitForm(); + } + } + }); + textEl.inputEl.style.width = "100%"; + }); + if (this.useFrozenVersion) { + new import_obsidian6.Setting(formEl).addText((textEl) => { + textEl.setPlaceholder("Specify the release version tag (example: 1.0.0)"); + textEl.onChange((value) => { + this.version = value.trim(); + }); + textEl.inputEl.style.width = "100%"; + }); + } + formEl.createDiv("modal-button-container", (buttonContainerEl) => { + buttonContainerEl.createEl( + "label", + { + cls: "mod-checkbox" + }, + (labelEl) => { + const checkboxEl = labelEl.createEl("input", { + attr: { tabindex: -1 }, + type: "checkbox" + }); + checkboxEl.checked = this.enableAfterInstall; + checkboxEl.addEventListener("click", () => { + this.enableAfterInstall = checkboxEl.checked; + }); + labelEl.appendText("Enable after installing the plugin"); + } + ); + buttonContainerEl.createEl("button", { attr: { type: "button" }, text: "Never mind" }).addEventListener("click", () => { + this.close(); + }); + buttonContainerEl.createEl("button", { + attr: { type: "submit" }, + cls: "mod-cta", + text: "Add Plugin" + }); + }); + const newDiv = formEl.createDiv(); + newDiv.style.borderTop = "1px solid #ccc"; + newDiv.style.marginTop = "30px"; + const byTfThacker = newDiv.createSpan(); + byTfThacker.innerHTML = "BRAT by TFTHacker"; + byTfThacker.style.fontStyle = "italic"; + newDiv.appendChild(byTfThacker); + promotionalLinks(newDiv, false); + window.setTimeout(() => { + const title = formEl.querySelectorAll(".brat-modal .setting-item-info"); + title.forEach((titleEl) => { + titleEl.remove(); + }); + }, 50); + formEl.addEventListener("submit", (e) => { + e.preventDefault(); + if (this.address !== "") { + if (this.useFrozenVersion && this.version !== "" || !this.useFrozenVersion) { + void this.submitForm(); + } + } + }); + }); + } + onClose() { + if (this.openSettingsTabAfterwards) { + this.plugin.app.setting.open(); + this.plugin.app.setting.openTabById(this.plugin.APP_ID); + } + } +}; + +// src/features/BetaPlugins.ts +var import_obsidian7 = require("obsidian"); +var BetaPlugins = class { + constructor(plugin) { + this.plugin = plugin; + } + /** + * opens the AddNewPluginModal to get info for a new beta plugin + * @param openSettingsTabAfterwards - will open settings screen afterwards. Used when this command is called from settings tab + * @param useFrozenVersion - install the plugin using frozen version. + */ + displayAddNewPluginModal(openSettingsTabAfterwards = false, useFrozenVersion = false) { + const newPlugin = new AddNewPluginModal( + this.plugin, + this, + openSettingsTabAfterwards, + useFrozenVersion + ); + newPlugin.open(); + } + /** + * Validates that a GitHub repository is plugin + * + * @param repositoryPath - GithubUser/RepositoryName (example: TfThacker/obsidian42-brat) + * @param getBetaManifest - test the beta version of the manifest, not at the root + * @param false - [false description] + * @param reportIssues - will display notices as it finds issues + * + * @returns the manifest file if found, or null if its incomplete + */ + async validateRepository(repositoryPath, getBetaManifest = false, reportIssues = false) { + const noticeTimeout = 15; + const manifestJson = await grabManifestJsonFromRepository( + repositoryPath, + !getBetaManifest, + this.plugin.settings.debuggingMode, + this.plugin.settings.personalAccessToken + ); + if (!manifestJson) { + if (reportIssues) { + toastMessage( + this.plugin, + `${repositoryPath} +This does not seem to be an obsidian plugin, as there is no manifest.json file.`, + noticeTimeout + ); + console.error( + "BRAT: validateRepository", + repositoryPath, + getBetaManifest, + reportIssues + ); + } + return null; + } + if (!("id" in manifestJson)) { + if (reportIssues) + toastMessage( + this.plugin, + `${repositoryPath} +The plugin id attribute for the release is missing from the manifest file`, + noticeTimeout + ); + return null; + } + if (!("version" in manifestJson)) { + if (reportIssues) + toastMessage( + this.plugin, + `${repositoryPath} +The version attribute for the release is missing from the manifest file`, + noticeTimeout + ); + return null; + } + return manifestJson; + } + /** + * Gets all the release files based on the version number in the manifest + * + * @param repositoryPath - path to the GitHub repository + * @param manifest - manifest file + * @param getManifest - grab the remote manifest file + * @param specifyVersion - grab the specified version if set + * + * @returns all relase files as strings based on the ReleaseFiles interaface + */ + async getAllReleaseFiles(repositoryPath, manifest, getManifest, specifyVersion = "") { + const version = specifyVersion === "" ? manifest.version : specifyVersion; + const reallyGetManifestOrNot = getManifest || specifyVersion !== ""; + console.log({ reallyGetManifestOrNot, version }); + return { + mainJs: await grabReleaseFileFromRepository( + repositoryPath, + version, + "main.js", + this.plugin.settings.debuggingMode, + this.plugin.settings.personalAccessToken + ), + manifest: reallyGetManifestOrNot ? await grabReleaseFileFromRepository( + repositoryPath, + version, + "manifest.json", + this.plugin.settings.debuggingMode, + this.plugin.settings.personalAccessToken + ) : "", + styles: await grabReleaseFileFromRepository( + repositoryPath, + version, + "styles.css", + this.plugin.settings.debuggingMode, + this.plugin.settings.personalAccessToken + ) + }; + } + /** + * Writes the plugin release files to the local obsidian .plugins folder + * + * @param betaPluginId - the id of the plugin (not the repository path) + * @param relFiles - release file as strings, based on the ReleaseFiles interface + * + */ + async writeReleaseFilesToPluginFolder(betaPluginId, relFiles) { + var _a, _b; + const pluginTargetFolderPath = (0, import_obsidian7.normalizePath)(this.plugin.app.vault.configDir + "/plugins/" + betaPluginId) + "/"; + const { adapter } = this.plugin.app.vault; + if (!await adapter.exists(pluginTargetFolderPath) || !await adapter.exists(pluginTargetFolderPath + "manifest.json")) { + await adapter.mkdir(pluginTargetFolderPath); + } + await adapter.write(pluginTargetFolderPath + "main.js", (_a = relFiles.mainJs) != null ? _a : ""); + await adapter.write( + pluginTargetFolderPath + "manifest.json", + (_b = relFiles.manifest) != null ? _b : "" + ); + if (relFiles.styles) + await adapter.write(pluginTargetFolderPath + "styles.css", relFiles.styles); + } + /** + * Primary function for adding a new beta plugin to Obsidian. + * Also this function is used for updating existing plugins. + * + * @param repositoryPath - path to GitHub repository formated as USERNAME/repository + * @param updatePluginFiles - true if this is just an update not an install + * @param seeIfUpdatedOnly - if true, and updatePluginFiles true, will just check for updates, but not do the update. will report to user that there is a new plugin + * @param reportIfNotUpdted - if true, report if an update has not succed + * @param specifyVersion - if not empty, need to install a specified version instead of the value in manifest-beta.json + * @param forceReinstall - if true, will force a reinstall of the plugin, even if it is already installed + * + * @returns true if succeeds + */ + async addPlugin(repositoryPath, updatePluginFiles = false, seeIfUpdatedOnly = false, reportIfNotUpdted = false, specifyVersion = "", forceReinstall = false, enableAfterInstall = this.plugin.settings.enableAfterInstall) { + if (this.plugin.settings.debuggingMode) + console.log( + "BRAT: addPlugin", + repositoryPath, + updatePluginFiles, + seeIfUpdatedOnly, + reportIfNotUpdted, + specifyVersion, + forceReinstall, + enableAfterInstall + ); + const noticeTimeout = 10; + let primaryManifest = await this.validateRepository(repositoryPath, true, false); + const usingBetaManifest = primaryManifest ? true : false; + if (!usingBetaManifest) + primaryManifest = await this.validateRepository(repositoryPath, false, true); + if (primaryManifest === null) { + const msg = `${repositoryPath} +A manifest.json or manifest-beta.json file does not exist in the root directory of the repository. This plugin cannot be installed.`; + await this.plugin.log(msg, true); + toastMessage(this.plugin, msg, noticeTimeout); + return false; + } + if (!Object.hasOwn(primaryManifest, "version")) { + const msg = `${repositoryPath} +The manifest${usingBetaManifest ? "-beta" : ""}.json file in the root directory of the repository does not have a version number in the file. This plugin cannot be installed.`; + await this.plugin.log(msg, true); + toastMessage(this.plugin, msg, noticeTimeout); + return false; + } + if (!Object.hasOwn(primaryManifest, "minAppVersion")) { + if (!(0, import_obsidian7.requireApiVersion)(primaryManifest.minAppVersion)) { + const msg = `Plugin: ${repositoryPath} + +The manifest${usingBetaManifest ? "-beta" : ""}.json for this plugin indicates that the Obsidian version of the app needs to be ${primaryManifest.minAppVersion}, but this installation of Obsidian is ${import_obsidian7.apiVersion}. + +You will need to update your Obsidian to use this plugin or contact the plugin developer for more information.`; + await this.plugin.log(msg, true); + toastMessage(this.plugin, msg, 30); + return false; + } + } + const getRelease = async () => { + const rFiles = await this.getAllReleaseFiles( + repositoryPath, + // @ts-expect-error typescript will complain that this can be null, but in this case it won't be + primaryManifest, + usingBetaManifest, + specifyVersion + ); + console.log("rFiles", rFiles); + if (usingBetaManifest || rFiles.manifest === "") + rFiles.manifest = JSON.stringify(primaryManifest); + if (this.plugin.settings.debuggingMode) + console.log("BRAT: rFiles.manifest", usingBetaManifest, rFiles); + if (rFiles.mainJs === null) { + const msg = `${repositoryPath} +The release is not complete and cannot be download. main.js is missing from the Release`; + await this.plugin.log(msg, true); + toastMessage(this.plugin, msg, noticeTimeout); + return null; + } + return rFiles; + }; + if (!updatePluginFiles || forceReinstall) { + const releaseFiles = await getRelease(); + if (releaseFiles === null) return false; + await this.writeReleaseFilesToPluginFolder(primaryManifest.id, releaseFiles); + if (!forceReinstall) + addBetaPluginToList(this.plugin, repositoryPath, specifyVersion); + if (enableAfterInstall) { + const { plugins } = this.plugin.app; + const pluginTargetFolderPath = (0, import_obsidian7.normalizePath)( + plugins.getPluginFolder() + "/" + primaryManifest.id + ); + await plugins.loadManifest(pluginTargetFolderPath); + await plugins.enablePluginAndSave(primaryManifest.id); + } + await this.plugin.app.plugins.loadManifests(); + if (forceReinstall) { + await this.reloadPlugin(primaryManifest.id); + await this.plugin.log(`${repositoryPath} reinstalled`, true); + toastMessage( + this.plugin, + `${repositoryPath} +Plugin has been reinstalled and reloaded.`, + noticeTimeout + ); + } else { + const versionText = specifyVersion === "" ? "" : ` (version: ${specifyVersion})`; + let msg = `${repositoryPath}${versionText} +The plugin has been registered with BRAT.`; + if (!enableAfterInstall) { + msg += " You may still need to enable it the Community Plugin List."; + } + await this.plugin.log(msg, true); + toastMessage(this.plugin, msg, noticeTimeout); + } + } else { + const pluginTargetFolderPath = this.plugin.app.vault.configDir + "/plugins/" + primaryManifest.id + "/"; + let localManifestContents = ""; + try { + localManifestContents = await this.plugin.app.vault.adapter.read( + pluginTargetFolderPath + "manifest.json" + ); + } catch (e) { + if (e.errno === -4058 || e.errno === -2) { + await this.addPlugin( + repositoryPath, + false, + usingBetaManifest, + false, + specifyVersion + ); + return true; + } else + console.log( + "BRAT - Local Manifest Load", + primaryManifest.id, + JSON.stringify(e, null, 2) + ); + } + if (specifyVersion !== "" || this.plugin.settings.pluginSubListFrozenVersion.map((x) => x.repo).includes(repositoryPath)) { + toastMessage( + this.plugin, + `The version of ${repositoryPath} is frozen, not updating.`, + 3 + ); + return false; + } + const localManifestJson = await JSON.parse( + localManifestContents + ); + if (localManifestJson.version !== primaryManifest.version) { + const releaseFiles = await getRelease(); + if (releaseFiles === null) return false; + if (seeIfUpdatedOnly) { + const msg = `There is an update available for ${primaryManifest.id} from version ${localManifestJson.version} to ${primaryManifest.version}. `; + await this.plugin.log( + msg + `[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`, + true + ); + toastMessage(this.plugin, msg, 30, () => { + if (primaryManifest) { + window.open( + `https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version}` + ); + } + }); + } else { + await this.writeReleaseFilesToPluginFolder(primaryManifest.id, releaseFiles); + await this.plugin.app.plugins.loadManifests(); + await this.reloadPlugin(primaryManifest.id); + const msg = `${primaryManifest.id} +Plugin has been updated from version ${localManifestJson.version} to ${primaryManifest.version}. `; + await this.plugin.log( + msg + `[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`, + true + ); + toastMessage(this.plugin, msg, 30, () => { + if (primaryManifest) { + window.open( + `https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version}` + ); + } + }); + } + } else if (reportIfNotUpdted) + toastMessage(this.plugin, `No update available for ${repositoryPath}`, 3); + } + return true; + } + /** + * reloads a plugin (assuming it has been enabled by user) + * pjeby, Thanks Bro https://github.com/pjeby/hot-reload/blob/master/main.js + * + * @param pluginName - name of plugin + * + */ + async reloadPlugin(pluginName) { + const { plugins } = this.plugin.app; + try { + await plugins.disablePlugin(pluginName); + await plugins.enablePlugin(pluginName); + } catch (e) { + if (this.plugin.settings.debuggingMode) console.log("reload plugin", e); + } + } + /** + * updates a beta plugin + * + * @param repositoryPath - repository path on GitHub + * @param onlyCheckDontUpdate - only looks for update + * + */ + async updatePlugin(repositoryPath, onlyCheckDontUpdate = false, reportIfNotUpdted = false, forceReinstall = false) { + const result = await this.addPlugin( + repositoryPath, + true, + onlyCheckDontUpdate, + reportIfNotUpdted, + "", + forceReinstall + ); + if (!result && !onlyCheckDontUpdate) + toastMessage(this.plugin, `${repositoryPath} +Update of plugin failed.`); + return result; + } + /** + * walks through the list of plugins without frozen version and performs an update + * + * @param showInfo - should this with a started/completed message - useful when ran from CP + * + */ + async checkForPluginUpdatesAndInstallUpdates(showInfo = false, onlyCheckDontUpdate = false) { + if (!await isConnectedToInternet()) { + console.log("BRAT: No internet detected."); + return; + } + let newNotice; + const msg1 = `Checking for plugin updates STARTED`; + await this.plugin.log(msg1, true); + if (showInfo && this.plugin.settings.notificationsEnabled) + newNotice = new import_obsidian7.Notice(`BRAT +${msg1}`, 3e4); + const pluginSubListFrozenVersionNames = new Set( + this.plugin.settings.pluginSubListFrozenVersion.map((f) => f.repo) + ); + for (const bp of this.plugin.settings.pluginList) { + if (pluginSubListFrozenVersionNames.has(bp)) { + continue; + } + await this.updatePlugin(bp, onlyCheckDontUpdate); + } + const msg2 = `Checking for plugin updates COMPLETED`; + await this.plugin.log(msg2, true); + if (showInfo) { + if (newNotice) { + newNotice.hide(); + } + toastMessage(this.plugin, msg2, 10); + } + } + /** + * Removes the beta plugin from the list of beta plugins (does not delete them from disk) + * + * @param betaPluginID - repository path + * + */ + deletePlugin(repositoryPath) { + const msg = `Removed ${repositoryPath} from BRAT plugin list`; + void this.plugin.log(msg, true); + this.plugin.settings.pluginList = this.plugin.settings.pluginList.filter( + (b) => b !== repositoryPath + ); + this.plugin.settings.pluginSubListFrozenVersion = this.plugin.settings.pluginSubListFrozenVersion.filter( + (b) => b.repo !== repositoryPath + ); + void this.plugin.saveSettings(); + } + /** + * Returns a list of plugins that are currently enabled or currently disabled + * + * @param enabled - true for enabled plugins, false for disabled plutings + * + * @returns manifests of plugins + */ + getEnabledDisabledPlugins(enabled) { + const pl = this.plugin.app.plugins; + const manifests = Object.values(pl.manifests); + const enabledPlugins = Object.values(pl.plugins).map( + (p) => p.manifest + ); + return enabled ? manifests.filter( + (manifest) => enabledPlugins.find((pluginName) => manifest.id === pluginName.id) + ) : manifests.filter( + (manifest) => !enabledPlugins.find((pluginName) => manifest.id === pluginName.id) + ); + } +}; + +// src/ui/icons.ts +var import_obsidian8 = require("obsidian"); +function addIcons() { + (0, import_obsidian8.addIcon)( + "BratIcon", + `` + ); +} + +// src/utils/logging.ts +var import_obsidian9 = require("obsidian"); +var import_obsidian_daily_notes_interface = __toESM(require_main()); +async function logger(plugin, textToLog, verboseLoggingOn = false) { + if (plugin.settings.debuggingMode) console.log("BRAT: " + textToLog); + if (plugin.settings.loggingEnabled) { + if (!plugin.settings.loggingVerboseEnabled && verboseLoggingOn) { + return; + } else { + const fileName = plugin.settings.loggingPath + ".md"; + const dateOutput = "[[" + (0, import_obsidian9.moment)().format((0, import_obsidian_daily_notes_interface.getDailyNoteSettings)().format).toString() + "]] " + (0, import_obsidian9.moment)().format("HH:mm"); + const os = window.require("os"); + const machineName = import_obsidian9.Platform.isDesktop ? os.hostname() : "MOBILE"; + let output = dateOutput + " " + machineName + " " + textToLog.replace("\n", " ") + "\n\n"; + if (await plugin.app.vault.adapter.exists(fileName)) { + const fileContents = await plugin.app.vault.adapter.read(fileName); + output = output + fileContents; + const file = plugin.app.vault.getAbstractFileByPath(fileName); + await plugin.app.vault.modify(file, output); + } else await plugin.app.vault.create(fileName, output); + } + } +} + +// src/ui/GenericFuzzySuggester.ts +var import_obsidian10 = require("obsidian"); +var GenericFuzzySuggester = class extends import_obsidian10.FuzzySuggestModal { + constructor(plugin) { + super(plugin.app); + this.data = []; + this.scope.register(["Shift"], "Enter", (evt) => { + this.enterTrigger(evt); + }); + this.scope.register(["Ctrl"], "Enter", (evt) => { + this.enterTrigger(evt); + }); + } + setSuggesterData(suggesterData) { + this.data = suggesterData; + } + display(callBack) { + this.callbackFunction = callBack; + this.open(); + } + getItems() { + return this.data; + } + getItemText(item) { + return item.display; + } + onChooseItem() { + return; + } + renderSuggestion(item, el) { + el.createEl("div", { text: item.item.display }); + } + enterTrigger(evt) { + var _a; + const selectedText = (_a = document.querySelector(".suggestion-item.is-selected div")) == null ? void 0 : _a.textContent; + const item = this.data.find((i) => i.display === selectedText); + if (item) { + this.invokeCallback(item, evt); + this.close(); + } + } + onChooseSuggestion(item, evt) { + this.invokeCallback(item.item, evt); + } + invokeCallback(item, evt) { + if (typeof this.callbackFunction === "function") { + this.callbackFunction(item, evt); + } + } +}; + +// src/ui/PluginCommands.ts +var PluginCommands = class { + constructor(plugin) { + this.bratCommands = [ + { + id: "BRAT-AddBetaPlugin", + icon: "BratIcon", + name: "Plugins: Add a beta plugin for testing", + showInRibbon: true, + callback: () => { + this.plugin.betaPlugins.displayAddNewPluginModal(false, false); + } + }, + { + id: "BRAT-AddBetaPluginWithFrozenVersion", + icon: "BratIcon", + name: "Plugins: Add a beta plugin with frozen version based on a release tag", + showInRibbon: true, + callback: () => { + this.plugin.betaPlugins.displayAddNewPluginModal(false, true); + } + }, + { + id: "BRAT-checkForUpdatesAndUpdate", + icon: "BratIcon", + name: "Plugins: Check for updates to all beta plugins and UPDATE", + showInRibbon: true, + callback: async () => { + await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(true, false); + } + }, + { + id: "BRAT-checkForUpdatesAndDontUpdate", + icon: "BratIcon", + name: "Plugins: Only check for updates to beta plugins, but don't Update", + showInRibbon: true, + callback: async () => { + await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(true, true); + } + }, + { + id: "BRAT-updateOnePlugin", + icon: "BratIcon", + name: "Plugins: Choose a single plugin version to update", + showInRibbon: true, + callback: () => { + const pluginSubListFrozenVersionNames = new Set( + this.plugin.settings.pluginSubListFrozenVersion.map((f) => f.repo) + ); + const pluginList = Object.values(this.plugin.settings.pluginList).filter((f) => !pluginSubListFrozenVersionNames.has(f)).map((m) => { + return { display: m, info: m }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(pluginList); + gfs.display((results) => { + const msg = `Checking for updates for ${results.info}`; + void this.plugin.log(msg, true); + toastMessage(this.plugin, ` +${msg}`, 3); + void this.plugin.betaPlugins.updatePlugin(results.info, false, true); + }); + } + }, + { + id: "BRAT-reinstallOnePlugin", + icon: "BratIcon", + name: "Plugins: Choose a single plugin to reinstall", + showInRibbon: true, + callback: () => { + const pluginSubListFrozenVersionNames = new Set( + this.plugin.settings.pluginSubListFrozenVersion.map((f) => f.repo) + ); + const pluginList = Object.values(this.plugin.settings.pluginList).filter((f) => !pluginSubListFrozenVersionNames.has(f)).map((m) => { + return { display: m, info: m }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(pluginList); + gfs.display((results) => { + const msg = `Reinstalling ${results.info}`; + toastMessage(this.plugin, ` +${msg}`, 3); + void this.plugin.log(msg, true); + void this.plugin.betaPlugins.updatePlugin( + results.info, + false, + false, + true + ); + }); + } + }, + { + id: "BRAT-restartPlugin", + icon: "BratIcon", + name: "Plugins: Restart a plugin that is already installed", + showInRibbon: true, + callback: () => { + const pluginList = Object.values( + this.plugin.app.plugins.manifests + ).map((m) => { + return { display: m.id, info: m.id }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(pluginList); + gfs.display((results) => { + toastMessage( + this.plugin, + `${results.info} +Plugin reloading .....`, + 5 + ); + void this.plugin.betaPlugins.reloadPlugin(results.info); + }); + } + }, + { + id: "BRAT-disablePlugin", + icon: "BratIcon", + name: "Plugins: Disable a plugin - toggle it off", + showInRibbon: true, + callback: () => { + const pluginList = this.plugin.betaPlugins.getEnabledDisabledPlugins(true).map((manifest) => { + return { display: `${manifest.name} (${manifest.id})`, info: manifest.id }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(pluginList); + gfs.display((results) => { + void this.plugin.log(`${results.display} plugin disabled`, false); + if (this.plugin.settings.debuggingMode) console.log(results.info); + void this.plugin.app.plugins.disablePluginAndSave(results.info); + }); + } + }, + { + id: "BRAT-enablePlugin", + icon: "BratIcon", + name: "Plugins: Enable a plugin - toggle it on", + showInRibbon: true, + callback: () => { + const pluginList = this.plugin.betaPlugins.getEnabledDisabledPlugins(false).map((manifest) => { + return { display: `${manifest.name} (${manifest.id})`, info: manifest.id }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(pluginList); + gfs.display((results) => { + void this.plugin.log(`${results.display} plugin enabled`, false); + void this.plugin.app.plugins.enablePluginAndSave(results.info); + }); + } + }, + { + id: "BRAT-openGitHubZRepository", + icon: "BratIcon", + name: "Plugins: Open the GitHub repository for a plugin", + showInRibbon: true, + callback: async () => { + const communityPlugins = await grabCommmunityPluginList( + this.plugin.settings.debuggingMode + ); + if (communityPlugins) { + const communityPluginList = Object.values( + communityPlugins + ).map((p) => { + return { display: `Plugin: ${p.name} (${p.repo})`, info: p.repo }; + }); + const bratList = Object.values( + this.plugin.settings.pluginList + ).map((p) => { + return { display: "BRAT: " + p, info: p }; + }); + communityPluginList.forEach((si) => bratList.push(si)); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(bratList); + gfs.display((results) => { + if (results.info) window.open(`https://github.com/${results.info}`); + }); + } + } + }, + { + id: "BRAT-openGitHubRepoTheme", + icon: "BratIcon", + name: "Themes: Open the GitHub repository for a theme (appearance)", + showInRibbon: true, + callback: async () => { + const communityTheme = await grabCommmunityThemesList( + this.plugin.settings.debuggingMode + ); + if (communityTheme) { + const communityThemeList = Object.values(communityTheme).map( + (p) => { + return { display: `Theme: ${p.name} (${p.repo})`, info: p.repo }; + } + ); + const gfs = new GenericFuzzySuggester(this.plugin); + gfs.setSuggesterData(communityThemeList); + gfs.display((results) => { + if (results.info) window.open(`https://github.com/${results.info}`); + }); + } + } + }, + { + id: "BRAT-opentPluginSettings", + icon: "BratIcon", + name: "Plugins: Open Plugin Settings Tab", + showInRibbon: true, + callback: () => { + const settings = this.plugin.app.setting; + const listOfPluginSettingsTabs = Object.values( + settings.pluginTabs + ).map((t) => { + return { display: "Plugin: " + t.name, info: t.id }; + }); + const gfs = new GenericFuzzySuggester(this.plugin); + const listOfCoreSettingsTabs = Object.values( + settings.settingTabs + ).map((t) => { + return { display: "Core: " + t.name, info: t.id }; + }); + listOfPluginSettingsTabs.forEach((si) => listOfCoreSettingsTabs.push(si)); + gfs.setSuggesterData(listOfCoreSettingsTabs); + gfs.display((results) => { + settings.open(); + settings.openTabById(results.info); + }); + } + }, + { + id: "BRAT-GrabBetaTheme", + icon: "BratIcon", + name: "Themes: Grab a beta theme for testing from a Github repository", + showInRibbon: true, + callback: () => { + new AddNewTheme(this.plugin).open(); + } + }, + { + id: "BRAT-updateBetaThemes", + icon: "BratIcon", + name: "Themes: Update beta themes", + showInRibbon: true, + callback: async () => { + await themesCheckAndUpdates(this.plugin, true); + } + }, + { + id: "BRAT-allCommands", + icon: "BratIcon", + name: "All Commands list", + showInRibbon: false, + callback: () => { + this.ribbonDisplayCommands(); + } + } + ]; + this.plugin = plugin; + this.bratCommands.forEach((item) => { + this.plugin.addCommand({ + id: item.id, + name: item.name, + icon: item.icon, + callback: () => { + item.callback(); + } + }); + }); + } + ribbonDisplayCommands() { + const bratCommandList = []; + this.bratCommands.forEach((cmd) => { + if (cmd.showInRibbon) + bratCommandList.push({ display: cmd.name, info: cmd.callback }); + }); + const gfs = new GenericFuzzySuggester(this.plugin); + const settings = this.plugin.app.setting; + const listOfCoreSettingsTabs = Object.values( + settings.settingTabs + ).map((t) => { + return { + display: "Core: " + t.name, + info: () => { + settings.open(); + settings.openTabById(t.id); + } + }; + }); + const listOfPluginSettingsTabs = Object.values( + settings.pluginTabs + ).map((t) => { + return { + display: "Plugin: " + t.name, + info: () => { + settings.open(); + settings.openTabById(t.id); + } + }; + }); + bratCommandList.push({ + display: "---- Core Plugin Settings ----", + info: () => { + this.ribbonDisplayCommands(); + } + }); + listOfCoreSettingsTabs.forEach((si) => bratCommandList.push(si)); + bratCommandList.push({ + display: "---- Plugin Settings ----", + info: () => { + this.ribbonDisplayCommands(); + } + }); + listOfPluginSettingsTabs.forEach((si) => bratCommandList.push(si)); + gfs.setSuggesterData(bratCommandList); + gfs.display((results) => { + if (typeof results.info === "function") { + results.info(); + } + }); + } +}; + +// src/utils/BratAPI.ts +var BratAPI = class { + constructor(plugin) { + this.console = (logDescription, ...outputs) => { + console.log("BRAT: " + logDescription, ...outputs); + }; + this.themes = { + themeseCheckAndUpates: async (showInfo) => { + await themesCheckAndUpdates(this.plugin, showInfo); + }, + themeInstallTheme: async (cssGithubRepository) => { + const scrubbedAddress = cssGithubRepository.replace("https://github.com/", ""); + await themeSave(this.plugin, scrubbedAddress, true); + }, + themesDelete: (cssGithubRepository) => { + const scrubbedAddress = cssGithubRepository.replace("https://github.com/", ""); + themeDelete(this.plugin, scrubbedAddress); + }, + grabCommmunityThemeCssFile: async (repositoryPath, betaVersion = false) => { + return await grabCommmunityThemeCssFile( + repositoryPath, + betaVersion, + this.plugin.settings.debuggingMode + ); + }, + grabChecksumOfThemeCssFile: async (repositoryPath, betaVersion = false) => { + return await grabChecksumOfThemeCssFile( + repositoryPath, + betaVersion, + this.plugin.settings.debuggingMode + ); + }, + grabLastCommitDateForFile: async (repositoryPath, path) => { + return await grabLastCommitDateForFile(repositoryPath, path); + } + }; + this.plugin = plugin; + } +}; + +// src/main.ts +var ThePlugin = class extends import_obsidian11.Plugin { + constructor() { + super(...arguments); + this.APP_NAME = "BRAT"; + this.APP_ID = "obsidian42-brat"; + this.settings = DEFAULT_SETTINGS; + this.betaPlugins = new BetaPlugins(this); + this.commands = new PluginCommands(this); + this.bratApi = new BratAPI(this); + this.obsidianProtocolHandler = (params) => { + if (!params.plugin && !params.theme) { + toastMessage(this, `Could not locate the repository from the URL.`, 10); + return; + } + for (const which of ["plugin", "theme"]) { + if (params[which]) { + const modal = which === "plugin" ? new AddNewPluginModal(this, this.betaPlugins) : new AddNewTheme(this); + modal.address = params[which]; + modal.open(); + return; + } + } + }; + } + onload() { + console.log("loading " + this.APP_NAME); + this.loadSettings().then(() => { + this.addSettingTab(new BratSettingsTab(this.app, this)); + addIcons(); + this.showRibbonButton(); + this.registerObsidianProtocolHandler("brat", this.obsidianProtocolHandler); + this.app.workspace.onLayoutReady(() => { + if (this.settings.updateAtStartup) { + setTimeout(() => { + void this.betaPlugins.checkForPluginUpdatesAndInstallUpdates(false); + }, 6e4); + } + if (this.settings.updateThemesAtStartup) { + setTimeout(() => { + void themesCheckAndUpdates(this, false); + }, 12e4); + } + setTimeout(() => { + window.bratAPI = this.bratApi; + }, 500); + }); + }).catch((error) => { + console.error("Failed to load settings:", error); + }); + } + showRibbonButton() { + this.addRibbonIcon("BratIcon", "BRAT", () => { + this.commands.ribbonDisplayCommands(); + }); + } + async log(textToLog, verbose = false) { + await logger(this, textToLog, verbose); + } + onunload() { + console.log("unloading " + this.APP_NAME); + } + async loadSettings() { + this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + } + async saveSettings() { + await this.saveData(this.settings); + } +}; + +/* nosourcemap */ \ No newline at end of file diff --git a/.obsidian/plugins/obsidian42-brat/manifest.json b/.obsidian/plugins/obsidian42-brat/manifest.json new file mode 100644 index 0000000..2701b29 --- /dev/null +++ b/.obsidian/plugins/obsidian42-brat/manifest.json @@ -0,0 +1,15 @@ +{ + "id": "obsidian42-brat", + "name": "BRAT", + "version": "1.0.3", + "minAppVersion": "1.4.16", + "description": "Easily install a beta version of a plugin for testing.", + "author": "TfTHacker", + "authorUrl": "https://github.com/TfTHacker/obsidian42-brat", + "helpUrl": "https://tfthacker.com/BRAT", + "isDesktopOnly": false, + "fundingUrl": { + "Buy Me a Coffee": "https://bit.ly/o42-kofi", + "Visit my site": "https://tfthacker.com" + } +} \ No newline at end of file diff --git a/.obsidian/plugins/obsidian42-brat/styles.css b/.obsidian/plugins/obsidian42-brat/styles.css new file mode 100644 index 0000000..596067a --- /dev/null +++ b/.obsidian/plugins/obsidian42-brat/styles.css @@ -0,0 +1,3 @@ +.brat-modal .modal-button-container { + margin-top: 5px !important; +} diff --git a/.obsidian/plugins/query-control/data.json b/.obsidian/plugins/query-control/data.json new file mode 100644 index 0000000..883eb3f --- /dev/null +++ b/.obsidian/plugins/query-control/data.json @@ -0,0 +1,8 @@ +{ + "defaultCollapse": true, + "defaultShowContext": false, + "defaultHideTitle": true, + "defaultHideResults": false, + "defaultRenderMarkdown": true, + "defaultSortOrder": "2" +} \ No newline at end of file diff --git a/.obsidian/plugins/query-control/main.js b/.obsidian/plugins/query-control/main.js new file mode 100644 index 0000000..92cf5c3 --- /dev/null +++ b/.obsidian/plugins/query-control/main.js @@ -0,0 +1,12 @@ +/* +THIS IS A GENERATED/BUNDLED FILE BY ESBUILD +if you want to view the source, please visit the github repository of this plugin +*/ + +var N=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var U=(l,h)=>{for(var r in h)N(l,r,{get:h[r],enumerable:!0})},X=(l,h,r,e)=>{if(h&&typeof h=="object"||typeof h=="function")for(let n of W(h))!G.call(l,n)&&n!==r&&N(l,n,{get:()=>h[n],enumerable:!(e=j(h,n))||e.enumerable});return l};var Y=l=>X(N({},"__esModule",{value:!0}),l);var v=(l,h,r)=>new Promise((e,n)=>{var s=i=>{try{o(r.next(i))}catch(a){n(a)}},t=i=>{try{o(r.throw(i))}catch(a){n(a)}},o=i=>i.done?e(i.value):Promise.resolve(i.value).then(s,t);o((r=r.apply(l,h)).next())});var ee={};U(ee,{default:()=>L});module.exports=Y(ee);function k(l,h){let r=Object.keys(h).map(e=>J(l,e,h[e]));return r.length===1?r[0]:function(){r.forEach(e=>e())}}function J(l,h,r){let e=l[h],n=l.hasOwnProperty(h),s=n?e:function(){return Object.getPrototypeOf(l)[h].apply(this,arguments)},t=r(s);return e&&Object.setPrototypeOf(t,e),Object.setPrototypeOf(o,t),l[h]=o,i;function o(...a){return t===s&&l[h]===o&&i(),t.apply(this,a)}function i(){l[h]===o&&(n?l[h]=s:delete l[h]),t!==s&&(t=s,Object.setPrototypeOf(o,e||Function))}}var p=require("obsidian");var V=require("obsidian");var B=class extends V.MarkdownRenderer{constructor(r,e,n){super(r,e);this.app=r,this.match=n,this.subpath="",this.indent="",this.filePath=this.match.parentDom.path,this.file=this.match.parentDom.file,this.renderer.previewEl.onNodeInserted(()=>(this.updateOptions(),this.renderer.onResize()))}updateOptions(){let r=this.app.vault.getConfig("readableLineLength");this.renderer.previewEl.toggleClass("is-readable-line-width",r);let e=this.app.vault.getConfig("foldHeading");this.renderer.previewEl.toggleClass("allow-fold-headings",e);let n=this.app.vault.getConfig("foldIndent");this.renderer.previewEl.toggleClass("allow-fold-lists",n),this.renderer.previewEl.toggleClass("rtl",this.app.vault.getConfig("rightToLeft")),e||this.renderer.unfoldAllHeadings(),n||this.renderer.unfoldAllLists(),this.renderer.previewEl.toggleClass("show-frontmatter",this.app.vault.getConfig("showFrontmatter"));let s=this.app.vault.getConfig("tabSize");this.renderer.previewEl.style.tabSize=String(s),this.renderer.rerender()}onRenderComplete(){}getFile(){return this.match.parent.file}edit(r){return v(this,null,function*(){var a;this.renderer.set(r);let e=yield this.app.vault.cachedRead(this.file),s=(a=e.slice(this.match.start,this.match.end).match(/^\s+/g))==null?void 0:a.first();s&&(r=r.replace(/^/gm,s));let t=e.slice(0,this.match.start),o=e.slice(this.match.end,this.match.parent.content.length);var i=t+r+o;this.app.vault.modify(this.file,i)})}};var b=require("obsidian");var M=i18next.t.bind(i18next);var I={defaultCollapse:!1,defaultShowContext:!1,defaultHideTitle:!1,defaultHideResults:!1,defaultRenderMarkdown:!1,defaultSortOrder:"alphabetical"},R=[{key:"alphabetical",label:M("plugins.file-explorer.label-sort-a-to-z")},{key:"alphabeticalReverse",label:M("plugins.file-explorer.label-sort-z-to-a")},{key:"byModifiedTime",label:M("plugins.file-explorer.label-sort-new-to-old")},{key:"byModifiedTimeReverse",label:M("plugins.file-explorer.label-sort-old-to-new")},{key:"byCreatedTime",label:M("plugins.file-explorer.label-sort-created-new-to-old")},{key:"byCreatedTimeReverse",label:M("plugins.file-explorer.label-sort-created-old-to-new")}],H=class extends b.PluginSettingTab{constructor(r,e){super(r,e);this.plugin=e}hide(){}display(){let{containerEl:r}=this;r.empty(),new b.Setting(r).setName("Collapse query results by default").addToggle(e=>e.setValue(this.plugin.settings.defaultCollapse).onChange(n=>{this.plugin.settings.defaultCollapse=n,this.plugin.saveSettings()})),new b.Setting(r).setName("Show additional query result context by default").addToggle(e=>e.setValue(this.plugin.settings.defaultShowContext).onChange(n=>{this.plugin.settings.defaultShowContext=n,this.plugin.saveSettings()})),new b.Setting(r).setName("Hide query title by default").addToggle(e=>e.setValue(this.plugin.settings.defaultHideTitle).onChange(n=>{this.plugin.settings.defaultHideTitle=n,this.plugin.saveSettings()})),new b.Setting(r).setName("Hide query results by default").addToggle(e=>e.setValue(this.plugin.settings.defaultHideResults).onChange(n=>{this.plugin.settings.defaultHideResults=n,this.plugin.saveSettings()})),new b.Setting(r).setName("Render results as Markdown by default").addToggle(e=>e.setValue(this.plugin.settings.defaultRenderMarkdown).onChange(n=>{this.plugin.settings.defaultRenderMarkdown=n,this.plugin.saveSettings()})),new b.Setting(r).setName("Default query result sort order").addDropdown(e=>{e.addOptions(R),e.setValue(this.plugin.settings.defaultSortOrder),e.onChange(n=>v(this,null,function*(){this.plugin.settings.defaultSortOrder=n,yield this.plugin.saveSettings()}))})}};function $(l,h,r,e,n){let s=document.getElementById("query-control-sort-tooltip");if(s){s.remove();return}let t=document.createElement("div");t.classList.add("query-control-sort-tooltip");let o=h.getBoundingClientRect();t.style.top=`${o.bottom+window.scrollY+5}px`,t.style.left=`${o.left+window.scrollX}px`,l.forEach(u=>{let f=document.createElement("div");if(f.classList.add("query-control-sort-option"),f.textContent=u.label,u.key===e){f.setAttribute("aria-current","true");let C=document.createElement("span");C.textContent="\u2714\uFE0F",C.classList.add("query-control-sort-option-checkmark"),f.appendChild(C)}f.addEventListener("click",()=>{r(u.key),t.remove()}),t.appendChild(f)}),document.body.appendChild(t);let i=()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("touchstart",c,!0),document.removeEventListener("click",c,!0),document.removeEventListener("keydown",g,!0),n.workspace.off("active-leaf-change",a)},a=()=>{t.parentElement&&(t.remove(),i())},c=u=>{!t.contains(u.target)&&!h.contains(u.target)&&(t.remove(),i())},g=u=>{t.remove(),i()};document.addEventListener("mousedown",c,!0),document.addEventListener("touchstart",c,!0),document.addEventListener("click",c),document.addEventListener("keydown",g,!0),n.workspace.on("active-leaf-change",a)}var Z=!1;var F=new WeakMap,L=class extends p.Plugin{onload(){return v(this,null,function*(){yield this.loadSettings();let r=this;this.registerSettingsTab(),this.register(k(this.app.viewRegistry.constructor.prototype,{registerView(n){return function(s,t,...o){return r.app.workspace.trigger("view-registered",s,t),n.call(this,s,t,...o)}}}));let e;if(!this.app.workspace.layoutReady){let n=this.app.workspace.on("view-registered",(t,o)=>{if(t!=="search")return;this.app.workspace.offref(n);let i=new p.WorkspaceLeaf(r.app),a=o(i);r.patchNativeSearch(a);let c=k(p.Modal.prototype,{open(g){return function(...u){r.SearchResultsExport=this.constructor}}});a.onCopyResultsClick(new MouseEvent(null)),c()}),s=this.app.workspace.on("view-registered",(t,o)=>{if(t!=="backlink")return;this.app.workspace.offref(s);let i=new p.WorkspaceLeaf(r.app),a=o(i);r.SearchHeaderDOM=a.backlink.headerDom.constructor})}this.register(e=k(p.Component.prototype,{addChild(n){return function(s,...t){try{if(!r.isSearchPatched&&s instanceof p.Component&&s.hasOwnProperty("searchQuery")&&s.hasOwnProperty("sourcePath")&&s.hasOwnProperty("dom")){let i=s;r.patchSearchView(i),r.isSearchPatched=!0}if(s instanceof p.Component&&s.hasOwnProperty("backlinkDom")){let i=s;F.set(i.backlinkDom.el.closest(".backlink-pane"),s),r.isBacklinksPatched||(r.patchBacklinksView(i),r.isBacklinksPatched=!0)}}catch(i){console.error("Error in Component.addChild around patch:",i)}return n.call(this,s,...t)}}}))})}loadSettings(){return v(this,null,function*(){this.settings=Object.assign({},I,yield this.loadData())})}saveSettings(){return v(this,null,function*(){yield this.saveData(this.settings)})}registerSettingsTab(){this.settingsTab=new H(this.app,this),this.addSettingTab(this.settingsTab)}getSearchHeader(){var n,s,t;let r=(n=this.app.workspace.getLeavesOfType("backlink"))==null?void 0:n.first();r==null||r.loadIfDeferred();let e=(t=(s=r==null?void 0:r.view)==null?void 0:s.backlink)==null?void 0:t.headerDom;return e==null?void 0:e.constructor}onunload(){Z&&console.log("EmbeddedQueryControlPlugin: onunload")}patchNativeSearch(r){let e=this;this.register(k(r.constructor.prototype,{onResize(n){return function(...s){var o;let t=(o=this.dom.vChildren)==null?void 0:o._children;return this.dom.el.clientWidth===0?(t.forEach(i=>{i.setCollapse(!0,!1)}),this.dom.hidden=!0):this.dom.hidden&&(this.dom.hidden=!1,setTimeout(()=>{t.forEach(i=>{i.setCollapse(this.dom.collapseAll,!1)})},100)),n.call(this,...s)}},stopSearch(n){return function(...s){let t=n.call(this,...s);return this.renderComponent&&(this.renderComponent.unload(),this.renderComponent=new p.Component),t}},addChild(n){return function(...s){var o;try{if(!this.patched){this.renderComponent||(this.renderComponent=new p.Component,this.renderComponent.load()),this.patched=!0,this.dom.parent=this,e.patchSearchResultDOM(this.dom.constructor),this.setRenderMarkdown=function(a){var g,u;let c=(g=this.dom.vChildren)==null?void 0:g._children;this.dom.renderMarkdown=a,c.forEach(f=>{f.renderContentMatches()}),this.dom.infinityScroll.invalidateAll(),this.dom.childrenEl.toggleClass("cm-preview-code-block",a),this.dom.childrenEl.toggleClass("is-rendered",a),(u=this.renderMarkdownButtonEl)==null||u.toggleClass("is-active",a)},this.renderMarkdownButtonEl=(o=this.headerDom)==null?void 0:o.addNavButton("reading-glasses","Render Markdown",()=>this.setRenderMarkdown(!this.dom.renderMarkdown));let i={renderMarkdown:e.settings.defaultRenderMarkdown};this.settings||(this.settings={}),Object.entries(i).forEach(([a,c])=>{this.settings.hasOwnProperty(a)?a==="sort"&&!R.hasOwnProperty(this.settings.sort)&&(this.settings[a]=c):this.settings[a]=c}),this.setRenderMarkdown(this.settings.renderMarkdown)}}catch(i){console.error("Error in searchView.addChild around patch:",i)}return n.call(this,...s)}}}))}patchSearchResultDOM(r){let e=this,n=k(r.prototype,{addResult(s){return function(...t){n();let o=s.call(this,...t),i=o.constructor;return e.isSearchResultItemPatched||e.patchSearchResultItem(i),o}}});this.register(n),this.register(k(r.prototype,{startLoader(s){return function(...t){var i,a,c,g,u,f;try{let C=this.el.closest(".backlink-pane"),x=F.get(C);if(C&&x&&(x.patched||K(this,e,C,x)),!((a=(i=this.parent)==null?void 0:i.searchParamsContainerEl)!=null&&a.patched)&&((g=(c=this.el)==null?void 0:c.parentElement)==null?void 0:g.getAttribute("data-type"))==="search"&&(this.parent.searchParamsContainerEl.patched=!0,new p.Setting(this.parent.searchParamsContainerEl).setName("Render Markdown").setClass("mod-toggle").addToggle(O=>{O.setValue(e.settings.defaultRenderMarkdown),O.onChange(E=>{var T;this.renderMarkdown=E,((T=this.vChildren)==null?void 0:T._children).forEach(d=>{d.renderContentMatches()}),this.infinityScroll.invalidateAll(),this.childrenEl.toggleClass("cm-preview-code-block",E),this.childrenEl.toggleClass("is-rendered",E)})})),!this.patched&&((u=this.el.parentElement)==null?void 0:u.hasClass("internal-query"))){let O=e.SearchHeaderDOM?e.SearchHeaderDOM:e.getSearchHeader();if(!O){console.error("Error: _SearchHeaderDOM is undefined. Cannot create headerDom.");return}if((f=this.el)!=null&&f.closest(".internal-query")){this.patched=!0;let E=this.el.parentElement.querySelector(".internal-query-header");this.setExtraContext=function(d){var w;let y=(w=this.vChildren)==null?void 0:w._children;this.extraContext=d,this.extraContextButtonEl.toggleClass("is-active",d),y.forEach(m=>{m.setExtraContext(d)}),this.infinityScroll.invalidateAll()},this.setTitleDisplay=function(d){this.showTitle=d,this.showTitleButtonEl.toggleClass("is-active",d),E.toggleClass("is-hidden",d)},this.setResultsDisplay=function(d){this.showResults=d,this.showResultsButtonEl.toggleClass("is-active",d),this.el.toggleClass("is-hidden",d)},this.setRenderMarkdown=function(d){var w;this.renderMarkdown=d,((w=this.vChildren)==null?void 0:w._children).forEach(m=>{m.renderContentMatches()}),this.infinityScroll.invalidateAll(),this.childrenEl.toggleClass("cm-preview-code-block",d),this.childrenEl.toggleClass("is-rendered",d),this.renderMarkdownButtonEl.toggleClass("is-active",d)},this.setCollapseAll=function(d){var w;let y=(w=this.vChildren)==null?void 0:w._children;this.collapseAllButtonEl.toggleClass("is-active",d),this.collapseAll=d,y.forEach(m=>{m.setCollapse(d,!1)}),this.infinityScroll.invalidateAll()},this.setSortOrder=d=>{this.sortOrder=d,this.changed(),this.infinityScroll.invalidateAll()},this.onCopyResultsClick=d=>v(this,null,function*(){var A,P;d.preventDefault();let y=[],w=(A=this.vChildren)==null?void 0:A._children;for(let D of w){let Q=D.file.path,q="",z=(P=D.vChildren)==null?void 0:P._children;for(let _ of z)q+=_.parent.content.substring(_.start,_.end)+` +`;y.push(`## ${Q} +${q}`)}let m=y.join(` +`);try{yield navigator.clipboard.writeText(m),new p.Notice("Search results copied to clipboard.")}catch(D){console.error("Failed to copy search results:",D),new p.Notice("Failed to copy search results.")}});let S=this.headerDom=new O(this.app,this.el.parentElement);E.insertAdjacentElement("afterend",S.navHeaderEl),this.collapseAllButtonEl=S.addNavButton("bullet-list",M("plugins.search.label-collapse-results"),d=>(d.stopPropagation(),this.setCollapseAll(!this.collapseAll))),this.extraContextButtonEl=S.addNavButton("expand-vertically",M("plugins.search.label-more-context"),d=>(d.stopPropagation(),this.setExtraContext(!this.extraContext))),this.showSortButtonEl=S.addNavButton("arrow-up-narrow-wide","Sort",d=>{d.stopPropagation();let y=R.map(m=>m.key),w=m=>{if(y.includes(m)){this.sortOrder=m;let P=`Sort (${R.find(D=>D.key===m).label})`;this.showSortButtonEl.setAttribute("aria-label",P),this.setSortOrder(m)}else console.error(`Invalid sort option: ${m}`)};$(R,this.showSortButtonEl,w,this.sortOrder,this.app)}),this.showTitleButtonEl=S.addNavButton("strikethrough-glyph","Hide title",d=>(d.stopPropagation(),this.setTitleDisplay(!this.showTitle))),this.showResultsButtonEl=S.addNavButton("minus-with-circle","Hide results",d=>(d.stopPropagation(),this.setResultsDisplay(!this.showResults))),this.renderMarkdownButtonEl=S.addNavButton("reading-glasses","Render Markdown",d=>(d.stopPropagation(),this.setRenderMarkdown(!this.renderMarkdown))),S.addNavButton("documents","Copy results",this.onCopyResultsClick.bind(this));let T={title:e.settings.defaultHideResults,collapsed:e.settings.defaultCollapse,context:e.settings.defaultShowContext,hideTitle:e.settings.defaultHideTitle,hideResults:e.settings.defaultHideResults,renderMarkdown:e.settings.defaultRenderMarkdown,sort:e.settings.defaultSortOrder};this.settings||(this.settings={}),Object.entries(T).forEach(([d,y])=>{this.settings.hasOwnProperty(d)?d==="sort"&&!R.hasOwnProperty(this.settings.sort)&&(this.settings[d]=y):this.settings[d]=y}),this.setExtraContext(this.settings.context),this.sortOrder=this.settings.sort,this.setCollapseAll(this.settings.collapsed),this.setTitleDisplay(this.settings.hideTitle),this.setRenderMarkdown(this.settings.renderMarkdown),this.setResultsDisplay(this.settings.hideResults)}}}catch(C){console.error("Error in SearchResultDOM.startLoader around patch:",C)}return s.call(this,...t)}}}))}patchSearchResultItem(r){this.isSearchResultItemPatched=!0;let e=this,n=k(r.prototype,{onResultClick(s){return function(t,o,...i){if(!(t.target instanceof HTMLElement&&(t.target.hasClass("internal-link")||t.target.hasClass("task-list-item-checkbox")||t.target.hasClass("admonition-title-content"))))return s.call(this,t,o,...i)}},renderContentMatches(s){return function(...t){var a;let o=s.call(this,...t),i=(a=this.vChildren)==null?void 0:a._children;if(!e.isSearchResultItemMatchPatched&&i.length){let c=i.first().constructor;e.patchSearchResultItemMatch(c)}return o}}});e.register(n)}patchSearchResultItemMatch(r){this.isSearchResultItemMatchPatched=!0;let e=this;e.register(k(r.prototype,{render(n){return function(...s){var c;let t=this.parentDom,o=t.content.substring(this.start,this.end).replace("```query","\\`\\`\\`query"),i=(c=o.match(/^\s+/g))==null?void 0:c.first();i&&(o=o.replace(new RegExp(`^${i}`,"gm"),""));let a=t.parent.parent;if(a&&t.parent.renderMarkdown){let g=a==null?void 0:a.renderComponent;this.el.empty();let u=new B(e.app,this.el,this);u.onRenderComplete=()=>{var f;(f=t==null?void 0:t.parent)==null||f.infinityScroll.measure(t,this)},g.addChild(u),u.renderer.set(o)}else return n.call(this,...s)}}}))}patchSearchView(r){let e=r.constructor,n=r.dom.constructor;this.register(k(e.prototype,{onunload(s){return function(...t){return this.renderComponent&&(this.renderComponent.unload(),this.dom=null,this.queue=null,this.renderComponent=null,this._children=null,this.containerEl=null),s.call(this,...t)}},onload(s){return function(...t){try{this.renderComponent||(this.renderComponent=new p.Component,this.renderComponent.load()),this.dom.parent=this;let i=this.containerEl.parentElement.querySelector(".internal-query-header"),a=this.query.matchAll(new RegExp("^(?collapsed|context|hideTitle|renderMarkdown|hideResults|sort|title):\\s*(?.+?)$","gm")),c={};for(let g of a){let u=g.groups.value.toLowerCase();(u==="true"||u==="false")&&(g.groups.value=u==="true"),c[g.groups.key]=g.groups.value}this.query=this.query.replace(/^((collapsed|context|hideTitle|renderMarkdown|hideResults|sort|title):.+?)$/gm,"").trim(),i.setText(c.title||this.query),this.dom.settings=c}catch(i){console.error("Error in EmbeddedSearch.onload:",i)}return s.call(this,...t)}}})),this.patchSearchResultDOM(n)}patchBacklinksView(r){let e=r.constructor,n=r.backlinkDom.constructor;this.register(k(e.prototype,{onunload(s){return function(...t){return this.renderComponent&&(this.renderComponent.unload(),this.dom=null,this.queue=null,this.renderComponent=null,this._children=null,this.containerEl=null),s.call(this,...t)}},onload(s){return function(...t){try{this.renderComponent||(this.renderComponent=new p.Component,this.renderComponent.load()),this.backlinkDom.parent=this,this.unlinkedDom.parent=this;let i={};this.dom.settings=i}catch(i){console.error("Error in Backlink.onload:",i)}return s.call(this,...t)}}})),this.patchSearchResultDOM(n)}};function K(l,h,r,e){if(e){e.patched=!0,l.setRenderMarkdown=function(s){[e.backlinkDom,e.unlinkedDom].forEach(o=>{var a;o.renderMarkdown=s,((a=o.vChildren)==null?void 0:a._children).forEach(c=>{c.renderContentMatches()}),o.infinityScroll.invalidateAll(),o.childrenEl.toggleClass("cm-preview-code-block",s),o.childrenEl.toggleClass("is-rendered",s)}),this.renderMarkdownButtonEl.toggleClass("is-active",s)},l.onCopyResultsClick=s=>v(this,null,function*(){var a,c;s.stopPropagation(),s.preventDefault();let t=[],o=[e.backlinkDom,e.unlinkedDom];for(let g of o){let u=(a=g.vChildren)==null?void 0:a._children;for(let f of u){let C=f.file.path,x="",O=(c=f.vChildren)==null?void 0:c._children;for(let E of O)x+=E.parent.content.substring(E.start,E.end)+` +`;t.push(`## ${C} +${x}`)}}let i=t.join(` +`);try{yield navigator.clipboard.writeText(i)}catch(g){console.error("Failed to copy backlinks:",g),new p.Notice("Failed to copy backlinks.")}}),l.renderMarkdownButtonEl=e.headerDom.addNavButton("reading-glasses","Render Markdown",s=>(s.stopPropagation(),l.setRenderMarkdown(!l.renderMarkdown))),e.headerDom.addNavButton("documents","Copy results",l.onCopyResultsClick.bind(l));let n={title:h.settings.defaultHideResults,collapsed:h.settings.defaultCollapse,context:h.settings.defaultShowContext,hideTitle:h.settings.defaultHideTitle,hideResults:h.settings.defaultHideResults,renderMarkdown:h.settings.defaultRenderMarkdown,sort:h.settings.defaultSortOrder};l.settings||(l.settings={}),Object.entries(n).forEach(([s,t])=>{l.settings.hasOwnProperty(s)?s==="sort"&&!R.hasOwnProperty(l.settings.sort)&&(l.settings[s]=t):l.settings[s]=t}),e.setExtraContext(l.settings.context),e.sortOrder=l.settings.sort,e.setCollapseAll(l.settings.collapsed),l.setRenderMarkdown(l.settings.renderMarkdown)}} diff --git a/.obsidian/plugins/query-control/manifest.json b/.obsidian/plugins/query-control/manifest.json new file mode 100644 index 0000000..6a46289 --- /dev/null +++ b/.obsidian/plugins/query-control/manifest.json @@ -0,0 +1 @@ +{"id":"query-control","name":"Query Control","version":"0.7.9","minAppVersion":"1.7.2","description":"An experimental Obsidian plugin that adds additional control to queries","author":"NothingIsLost & reply2za","authorUrl":"https://github.com/reply2za/obsidian-query-control","isDesktopOnly":false} \ No newline at end of file diff --git a/.obsidian/plugins/query-control/styles.css b/.obsidian/plugins/query-control/styles.css new file mode 100644 index 0000000..83e1bcb --- /dev/null +++ b/.obsidian/plugins/query-control/styles.css @@ -0,0 +1,66 @@ +.workspace-leaf-content[data-type="markdown"] .internal-query .nav-header { + margin-top: 0; /* works around issues with minimal theme */ +} + +.workspace-leaf-content[data-type="markdown"] .internal-query .nav-header .nav-buttons-container { + position: unset; /* works around issues with minimal theme */ + justify-content: center; /* works around issues with minimal theme */ +} + +.workspace-leaf-content[data-type="markdown"] .internal-query .is-hidden { + display: none; +} + +.search-results-children.is-rendered .search-result-file-match { + white-space: normal; +} + +.search-results-children.is-rendered { + padding: 0; +} + +.search-results-children.is-rendered .search-result-file-matches .markdown-preview-view { + padding: 0; +} + +.search-results-children.is-rendered .search-result-file-matches .markdown-preview-section { + max-width: 100%; +} + +.search-results-children.is-rendered .task-list-item-checkbox { + vertical-align: unset; +} + +.search-results-children.is-rendered ul { + padding-inline-start: 40px; + margin-block-end: 0; + margin-block-start: 0; +} + +.cm-preview-code-block.is-rendered .markdown-preview-view { + height: inherit; +} + +.query-control-sort-tooltip { + position: absolute; + background: #333; + color: #fff; + border-radius: 4px; + padding: 5px; + z-index: 1000; +} + +.query-control-sort-option { + padding: 5px; + cursor: pointer; +} + +.query-control-sort-option:hover { + background: #555; +} + +.query-control-sort-option-checkmark { + color: #fff; + margin-left: 10px; + font-size: 1em; +} diff --git a/.obsidian/templates.json b/.obsidian/templates.json new file mode 100644 index 0000000..9d40ed7 --- /dev/null +++ b/.obsidian/templates.json @@ -0,0 +1,4 @@ +{ + "folder": "90 Extras/91 Templates", + "dateFormat": "YYYY-MM-DD, ddd" +} \ No newline at end of file diff --git a/.obsidian/types.json b/.obsidian/types.json new file mode 100644 index 0000000..52ff7cf --- /dev/null +++ b/.obsidian/types.json @@ -0,0 +1,13 @@ +{ + "types": { + "aliases": "aliases", + "cssclasses": "multitext", + "tags": "tags", + "url": "multitext", + "author": "text", + "finished": "checkbox", + "finished-date": "text", + "related-to": "multitext", + "authors": "multitext" + } +} \ No newline at end of file diff --git a/00 Planner/01 Days/2024-10-27, Sun.md b/00 Planner/01 Days/2024-10-27, Sun.md new file mode 100644 index 0000000..e69de29 diff --git a/00 Planner/01 Days/2024-10-28, Mon.md b/00 Planner/01 Days/2024-10-28, Mon.md new file mode 100644 index 0000000..e69de29 diff --git a/00 Planner/01 Days/2024-10-29, Tue.md b/00 Planner/01 Days/2024-10-29, Tue.md new file mode 100644 index 0000000..e69de29 diff --git a/10 Notes/BitTorrent Clients Usage Statistics.md b/10 Notes/BitTorrent Clients Usage Statistics.md new file mode 100644 index 0000000..0902d58 --- /dev/null +++ b/10 Notes/BitTorrent Clients Usage Statistics.md @@ -0,0 +1,17 @@ +--- +tags: + - bittorrent +--- + +Below is the quick summary generated by ChatGPT. The following data source has been indicated when generating this summary: + +1. https://vpnalert.com/resources/torrenting-statistics/ +2. https://torrentfreak.com/bittorrent-surges-to-150-million-monthly-users-120109/ + +As of 2024, the popularity of BitTorrent clients can be quantified through various statistics, primarily focused on user counts and traffic. Here’s a breakdown of some of the leading clients: + +1. **uTorrent and BitTorrent**: These two clients, owned by the same company, collectively have around **150 million active monthly users**. uTorrent alone is particularly popular and widely used worldwide, especially in countries like Russia, India, and the United States. +2. **qBittorrent**: This open-source client is another popular choice, especially among users looking for an ad-free experience. qBittorrent receives around **6 million visits monthly**, with most users coming from countries like China, the United States, and Russia. It’s particularly popular with younger users, with over 35% of its visitors aged 25-34 . +3. [[Deluge (BitTorrent)]]: Although smaller, Deluge remains popular with an estimated **272,800 monthly visitors**. The majority of its users are from the United States, Brazil, and France. It attracts a similar age demographic as other clients, with a strong preference among those aged 25-34 . + +These numbers highlight the reach and usage patterns of the most popular BitTorrent clients. While uTorrent and BitTorrent dominate in terms of sheer volume, qBittorrent has a dedicated user base that values its open-source and ad-free nature, and Deluge maintains a smaller but loyal following. \ No newline at end of file diff --git a/10 Notes/BitTorrent chapter from book P2P and Grids to Services on the Web.md b/10 Notes/BitTorrent chapter from book P2P and Grids to Services on the Web.md new file mode 100644 index 0000000..fd5117f --- /dev/null +++ b/10 Notes/BitTorrent chapter from book P2P and Grids to Services on the Web.md @@ -0,0 +1,9 @@ +--- +tags: + - book +authors: + - Ian J. Taylor and Andrew B. Harrison +link: https://link.springer.com/chapter/10.1007/978-1-84800-123-7_13 +related-to: +--- +Poor graphics, expensive (around €30,-). \ No newline at end of file diff --git a/10 Notes/Codex-BitTorrent Integration Intro.md b/10 Notes/Codex-BitTorrent Integration Intro.md new file mode 100644 index 0000000..433ceb8 --- /dev/null +++ b/10 Notes/Codex-BitTorrent Integration Intro.md @@ -0,0 +1,45 @@ +--- +tags: + - bittorrent +--- + +Let's gather some background data about [[Learn BitTorrent]] clients. This is something that ChatGPT is quite good at so I compiled a bit of data you can easily check for yourself. If something looks funky, please feel free to adjust and clarify, but just for having quick check of where we are, it seems to be a reasonable overview. I also saw @Giuliano Mega immediately jumping into [[Deluge (BitTorrent)]] (also @Mark sees that as a good start), so for my personal conviction we are diving into the right thing I wanted to have some arguments on why - however short and imprecise it is not. + +The most popular BitTorrent clients as of recent years include: + +1. **qBittorrent** + 1. Open-source and ad-free, qBittorrent is a favorite among users looking for a lightweight yet powerful client. + 2. It offers features like torrent prioritization, scheduling, and built-in search. +2. **uTorrent (µTorrent)** + 1. A widely used client, µTorrent is known for its small size and ease of use. + 2. While it’s feature-rich, the free version has ads, and some users prefer alternatives due to concerns about bundled software. +3. **BitTorrent** + 1. The official client from BitTorrent Inc., it shares many similarities with µTorrent since the same company owns both. + 2. It’s user-friendly and offers both free and paid versions with additional features. +4. **[[Deluge (BitTorrent)]]** + 1. An open-source client known for its extensive plugin support, making it highly customizable. + 2. It has a simple interface and is available for Windows, macOS, and Linux. +5. **Transmission** + 1. Lightweight and open-source, Transmission is especially popular on macOS and Linux. + 2. It has a minimalistic interface and can be controlled via the command line or a web interface. +6. **Tixati** + 1. A lesser-known option but well-regarded for being fast and powerful. + 2. It’s free, ad-free, and has detailed information on torrent health and peers. +7. **BiglyBT** + 1. An offshoot of the once-popular Vuze, BiglyBT is open-source and ad-free. + 2. It offers features like Swarm Merging, web torrent support, and remote management. + +Each client has its own set of features, and the best one often depends on your specific needs, such as platform compatibility, desire for a lightweight interface, or preference for open-source software. + +See also: +- [[BitTorrent Clients Usage Statistics]] +- [[Is BitTorrent Open Source?]] + +### Is BitTorrent Open Source? + +No, the official BitTorrent clients (uTorrent and BitTorrent) are not open source. These clients are owned by Rainberry, Inc. (formerly BitTorrent, Inc.), and they are proprietary software. While they are widely available in free versions, they include ads and may have bundled software, which has led some users to seek open-source alternatives like qBittorrent and Deluge, which offer similar functionalities without ads or bundled software. + +If you’re specifically looking for open-source BitTorrent clients, options like qBittorrent, Transmission, and Deluge are popular choices within the open-source community. These alternatives provide greater transparency, customization, and freedom from ads, which appeal to users who prioritize these aspects. + +Most of the stats come from the site https://vpnalert.com/resources/torrenting-statistics/. + diff --git a/10 Notes/Comparison of BitTorrent clients.md b/10 Notes/Comparison of BitTorrent clients.md new file mode 100644 index 0000000..e43ea7c --- /dev/null +++ b/10 Notes/Comparison of BitTorrent clients.md @@ -0,0 +1,15 @@ +--- +tags: + - bittorrent +--- +On Wikipedia we can get a decent overview of [[Learn BitTorrent]] clients: https://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients. + +> It should be noted here, that Wikipedia sources are often quite outdated. + +From this comparative, it does feel appropriate to further constraint our research to the following three clients: + +- [[qBittorrent]] +- [[Transmission]] +- [[Deluge (BitTorrent)]] + +All clients have similar capabilities and provide a similar set of features. Looking at look-and-feel of the website, Transmission looks the most attractive. If I would be a regular, non-dirty-hacker user, I would be attracted by [[Transmission]]. Other clients feel to me more niche, yet I would put [[qBitTorrent]] on the second position. [[Deluge (BitTorrent)]], still potentially attractive, with significantly lower user-base, being quite feature complete, still looks a bit ”hackie”. Both [[Deluge (BitTorrent)]] and [[qBittorrent]] depend on [[libtorrent]], while [[Transmission]] is using its own BitTorrent protocol implementation. \ No newline at end of file diff --git a/10 Notes/Deluge (BitTorrent).md b/10 Notes/Deluge (BitTorrent).md new file mode 100644 index 0000000..f7f6643 --- /dev/null +++ b/10 Notes/Deluge (BitTorrent).md @@ -0,0 +1,26 @@ +--- +tags: + - bittorrent +--- +Deluge is a [[Learn BitTorrent]] client. + +Official link: https://deluge-torrent.org. +Git: https://git.deluge-torrent.org/deluge (they are not on GitHub!) + +At [https://deluge-torrent.org/about/](https://deluge-torrent.org/about/) we can read that Deluge is able to run on headless machines with the user-interfaces being able to connect remotely from any platform. + +From @Giuliano Mega: + +I'm also finding that the python bindings are incomplete and expose only a subset of the API btw one way to approach the integration would be by going top down on how Deluge uses libtorrent and then looking at the minimum needed to get it running. The Deluge core is actually a lot simpler than I expected I think this may be less effort than trying to build the entire API from scratch on top of Codex e.g. if we can get enough to run the Deluge daemon on top of Codex, then all the rest (GTK UI, Web UI) sort of works… Other links: + +- simple experiment setup: [https://github.com/gmega/bt-experiment](https://github.com/gmega/bt-experiment) +- Deluge fork with instrumentation for metrics: [https://github.com/gmega/deluge](https://github.com/gmega/deluge) +- some notes on libtorrent: [https://hackmd.io/NhVe1A5HT92NALDufacuiA](https://hackmd.io/NhVe1A5HT92NALDufacuiA) +- how to setup a dev env with Deluge + libtorrent: [https://hackmd.io/ESDTgprbSPmViMxc5yKTiQ](https://hackmd.io/ESDTgprbSPmViMxc5yKTiQ) + +Related: + +- [https://github.com/codex-storage/nim-codex/issues/959](https://github.com/codex-storage/nim-codex/issues/959) - **Codex/BitTorrent integration** +- [https://github.com/codex-storage/nim-codex/issues/951](https://github.com/codex-storage/nim-codex/issues/951) - **Control BitTorrent** +- [Libtorrent and Deluge from sources](https://hackmd.io/ESDTgprbSPmViMxc5yKTiQ) +- [controlling Deluge using its RPC interface](https://github.com/gmega/bt-experiment/blob/c6af36b349f0211df69781233d387de229d68f62/experiment.py#L91) \ No newline at end of file diff --git a/10 Notes/Hot-Keys.md b/10 Notes/Hot-Keys.md new file mode 100644 index 0000000..88f7ecb --- /dev/null +++ b/10 Notes/Hot-Keys.md @@ -0,0 +1,14 @@ +If you decide to use the included `.obsidian` folder, the following Hot-Keys are defined: + +- Insert template: `cmd + alt + t` +- Navigate back: `cmd + [` +- Navigate forward: `cmd + ]` +- Open today's daily note: `cmd + d` +- Open previous daily note: `cmd + alt + [` +- Open next daily note: `cmd + alt + ]` +- Highlight: `cmd + shift + h` +- Show Bookmarks: `cmd + shift + b` +- Dark mode: `cmd + shift + -` +- Light Mode: `cmd + shift + =` +- Toggle left panel: `ctrl + 1` +- Toggle right panel: `ctrl + 2` diff --git a/10 Notes/Inbox.md b/10 Notes/Inbox.md new file mode 100644 index 0000000..aefbe47 --- /dev/null +++ b/10 Notes/Inbox.md @@ -0,0 +1 @@ +Unrelated notes... \ No newline at end of file diff --git a/10 Notes/Incentives Build Robustness in BitTorrent.md b/10 Notes/Incentives Build Robustness in BitTorrent.md new file mode 100644 index 0000000..d3389ee --- /dev/null +++ b/10 Notes/Incentives Build Robustness in BitTorrent.md @@ -0,0 +1,12 @@ +--- +tags: + - paper +authors: + - Bram Cohen +link: https://stuker.com/wp-content/uploads/import/i-1fd3ae7c5502dfddfe8b2c7acdefaa5e-bittorrentecon.pdf +related-to: + - "[[Learn BitTorrent]]" +--- +Original "BitTorrent" paper by [[Bram Cohen]]. + +![[i-1fd3ae7c5502dfddfe8b2c7acdefaa5e-bittorrentecon.pdf]] \ No newline at end of file diff --git a/10 Notes/Installed plugins.md b/10 Notes/Installed plugins.md new file mode 100644 index 0000000..cc33843 --- /dev/null +++ b/10 Notes/Installed plugins.md @@ -0,0 +1,8 @@ +If you decide to use the included `.obsidian` folder, the following the following plugins are assumed: + +- [BRAT](obsidian://show-plugin?id=obsidian42-brat) +- [Calendar](obsidian://show-plugin?id=calendar) +- [Natural Language Dates](obsidian://show-plugin?id=nldates-obsidian) +- [Query Control](https://github.com/reply2za/obsidian-query-control): installed via above mentioned [BRAT](obsidian://show-plugin?id=obsidian42-brat) plugin. + +> Notice: you do not need any plugins. They are just for convenience. \ No newline at end of file diff --git a/10 Notes/Is BitTorrent Open Source?.md b/10 Notes/Is BitTorrent Open Source?.md new file mode 100644 index 0000000..07762ba --- /dev/null +++ b/10 Notes/Is BitTorrent Open Source?.md @@ -0,0 +1,11 @@ +--- +tags: + - bittorrent +--- +No, the official BitTorrent clients (uTorrent and BitTorrent) are not open source. These clients are owned by Rainberry, Inc. (formerly BitTorrent, Inc.), and they are proprietary software. While they are widely available in free versions, they include ads and may have bundled software, which has led some users to seek open-source alternatives like qBittorrent and Deluge, which offer similar functionalities without ads or bundled software. + +If you’re specifically looking for open-source BitTorrent clients, options like qBittorrent, Transmission, and Deluge are popular choices within the open-source community. These alternatives provide greater transparency, customization, and freedom from ads, which appeal to users who prioritize these aspects. + +Most of the stats come from the site https://vpnalert.com/resources/torrenting-statistics/. + +Related: [[BitTorrent Clients Usage Statistics]]. \ No newline at end of file diff --git a/10 Notes/Learn BitTorrent.md b/10 Notes/Learn BitTorrent.md new file mode 100644 index 0000000..08aeffa --- /dev/null +++ b/10 Notes/Learn BitTorrent.md @@ -0,0 +1,40 @@ +--- +tags: + - bittorrent +urls: + - https://www.bittorrent.org + - https://www.bittorrent.com +--- +In order to imagine, what do we mean by *BitTorrent - Codex Integration*, we need to gain some basic understanding of BitTorrent. This is no time nor space to create a comprehensive introduction to BitTorrent here (we need to learn it as we go), so, here I just gathered some resources I use to understand the protocol, and by doing it to understand what does it mean for Codex to integrate with BitTorrent clients. + +### Specs + +BitTorrent spec is build incrementally from so called [BitTorrent Enhancement Proposals (BEPs)](http://bittorrent.org/beps/bep_0000.html). Each BEP adds something to the BitTorrent Protocol. The most important BEPs to study in order to get a good initial grip on the BitTorrent protocol are: + +- [BEP3 - The BitTorrent Protocol Specification](http://bittorrent.org/beps/bep_0003.html) +- [BEP5 - DHT Protocol](http://bittorrent.org/beps/bep_0005.html) +- [BEP9 - Extension for Peers to Send Metadata Files](http://bittorrent.org/beps/bep_0009.html) +- [BEP10 -Extension Protocol](http://bittorrent.org/beps/bep_0010.html) +- [BEP23 - Tracker Returns Compact Peer Lists](http://bittorrent.org/beps/bep_0023.html) +- [BEP29 - uTorrent transport protocol](http://bittorrent.org/beps/bep_0029.html) + +### Papers + +Selection of some more important BitTorrent papers: + +1. [[Incentives Build Robustness in BitTorrent]] +2. [[The Bittorrent P2P File-Sharing System - Measurements And Analysis]] + +### Books + +Not so many decent books about the BitTorrent protocol. You can find some *publications* from Springer and occasionally IEEE that focus on some aspects of BitTorrent or its performance. + +Below some recommendations: + +1. [[The World of Peer-to-Peer (P2P)]]. Community book, free. +2. [[BitTorrent chapter from book P2P and Grids to Services on the Web]]. + + +### BitTorrent Token + +Not sure how to categorise this, especially it is just in the area of the BitTorrent ambitions. Yet, clearly, they want to be on the same market as we are: [Whitepaper](https://www.bittorrent.com/btt/btt-docs/BitTorrent_(BTT)_White_Paper_v0.8.7_Feb_2019.pdf). diff --git a/10 Notes/Obsidian - hotkeys.md b/10 Notes/Obsidian - hotkeys.md new file mode 100644 index 0000000..6229a89 --- /dev/null +++ b/10 Notes/Obsidian - hotkeys.md @@ -0,0 +1,14 @@ +Lista skrótów klawiszowych: + +- Insert template (wstaw szablon): `cmd + alt + t` +- Navigate back (wstecz): `cmd + [` +- Navigate forward (do przodu): `cmd + ]` +- Open today's daily note (otwórz dzisiejszą notatkę): `cmd + d` +- Open previous daily note (otwórz wcześniejszą notatkę w dzienniku): `cmd + alt + [` +- Open next daily note (otwórz późniejszą notatkę w dzienniku): `cmd + alt + ]` +- Highlight: `cmd + shift + h` +- Show Bookmarks (pokaż ulubione): `cmd + shift + b` +- Dark mode: `cmd + shift + -` +- Light Mode: `cmd + shift + =` +- Toggle left pannel: `ctrl + 1` +- Toggle right pannel: `ctrl + 2` \ No newline at end of file diff --git a/10 Notes/Panic.md b/10 Notes/Panic.md new file mode 100644 index 0000000..db32054 --- /dev/null +++ b/10 Notes/Panic.md @@ -0,0 +1,2 @@ +Author of [[The World of Peer-to-Peer (P2P)]]. +See: https://en.wikibooks.org/wiki/User%3APanic2k4 diff --git a/10 Notes/The Bittorrent P2P File-Sharing System - Measurements And Analysis.md b/10 Notes/The Bittorrent P2P File-Sharing System - Measurements And Analysis.md new file mode 100644 index 0000000..634778f --- /dev/null +++ b/10 Notes/The Bittorrent P2P File-Sharing System - Measurements And Analysis.md @@ -0,0 +1,12 @@ +--- +tags: + - paper +authors: + - J.A. Pouwelse, P . Garbacki, D.H.J. Epema, H.J. Sips +link: http://nil.csail.mit.edu/6.824/2015/papers/pouwelse-btmeasure.pdf +related-to: + - "[[Learn BitTorrent]]" +--- +Paper from the creators of the [[Tribler]] protocol. + +![[pouwelse-btmeasure.pdf]] \ No newline at end of file diff --git a/10 Notes/The World of Peer-to-Peer (P2P).md b/10 Notes/The World of Peer-to-Peer (P2P).md new file mode 100644 index 0000000..504cad4 --- /dev/null +++ b/10 Notes/The World of Peer-to-Peer (P2P).md @@ -0,0 +1,15 @@ +--- +tags: + - book +authors: + - "[[Panic]]" +related-to: + - "[[Learn BitTorrent]]" +url: + - https://en.wikibooks.org/wiki/The_World_of_Peer-to-Peer_(P2P) +--- +From this book we are particularly interested in the chapter [2.15 BitTorrent](https://en.wikibooks.org/wiki/The_World_of_Peer-to-Peer_(P2P)/Networks_and_Protocols/BitTorrent). + +I have included the complete PDF of that book here: + +![[The_World_of_Peer-to-Peer.pdf]] diff --git a/10 Notes/ToDos.md b/10 Notes/ToDos.md new file mode 100644 index 0000000..e69de29 diff --git a/10 Notes/Transmission.md b/10 Notes/Transmission.md new file mode 100644 index 0000000..07887c8 --- /dev/null +++ b/10 Notes/Transmission.md @@ -0,0 +1,14 @@ +--- +tags: + - bittorrent +--- +Offcial URL: https://transmissionbt.com +Repository: https://github.com/transmission/transmission + +[[Learn BitTorrent]] client. One of the three popular clients, the other are [[Deluge (BitTorrent)]] and [[qBittorrent]], with the most attractive looking website. Comparing to the other two, Transmission does not depend on [[libtorrent]], but rather has its own implementation of the BitTorrent protocol. + +> As noted in GitHub’s REDME, [Transmission's documentation](https://github.com/transmission/transmission/blob/main/docs/README.md) is currently out-of-date, but the team has recently begun a new project to update it and is looking for volunteers. If you're interested, please feel free to submit pull requests! + +It supports all major OS and has a native macos support. + +The latest release is from 30 May 2024. diff --git a/10 Notes/Tribler.md b/10 Notes/Tribler.md new file mode 100644 index 0000000..08cb9b8 --- /dev/null +++ b/10 Notes/Tribler.md @@ -0,0 +1,6 @@ +--- +link: https://www.tribler.org/index.html +--- +This is a protocol based on [[Learn BitTorrent]]. Created at the [[University of Delft]] in the frame of the [[I-Share]] project I was part of as a Ph.D. student (2004-2009). + +Read more: https://www.tribler.org/about.html. diff --git a/10 Notes/libtorrent.md b/10 Notes/libtorrent.md new file mode 100644 index 0000000..ae0a359 --- /dev/null +++ b/10 Notes/libtorrent.md @@ -0,0 +1,14 @@ +--- +tags: + - bittorrent +--- +Open Source BitTorrent library. + +Link: http://www.libtorrent.org/. +Repository: https://github.com/arvidn/libtorrent + +Used by [[Deluge (BitTorrent)]] and [[qBittorrent]]. + +Languages: + +![[Pasted image 20241023160207.png]] \ No newline at end of file diff --git a/10 Notes/qBittorrent.md b/10 Notes/qBittorrent.md new file mode 100644 index 0000000..df786e9 --- /dev/null +++ b/10 Notes/qBittorrent.md @@ -0,0 +1,18 @@ +--- +tags: + - bittorrent +--- +[[Learn BitTorrent]] client. + +From Wikipedia: + +> **qBittorrent** is a [cross-platform](https://en.wikipedia.org/wiki/Cross-platform "Cross-platform") [free and open-source](https://en.wikipedia.org/wiki/Free_and_open-source "Free and open-source") [BitTorrent client](https://en.wikipedia.org/wiki/BitTorrent_client "BitTorrent client")written in [native](https://en.wikipedia.org/wiki/Native_application "Native application") [C++](https://en.wikipedia.org/wiki/C%2B%2B "C++"). It relies on [Boost](https://en.wikipedia.org/wiki/Boost_(C%2B%2B_libraries) "Boost (C++ libraries)"), [OpenSSL](https://en.wikipedia.org/wiki/OpenSSL "OpenSSL"), [zlib](https://en.wikipedia.org/wiki/Zlib "Zlib"), [Qt](https://en.wikipedia.org/wiki/Qt_(software) "Qt (software)") 6 toolkit and the [libtorrent](https://en.wikipedia.org/wiki/Libtorrent "Libtorrent")-rasterbar library (for the torrent back-end), with an optional search engine written in [Python](https://en.wikipedia.org/wiki/Python_(programming_language) "Python (programming language)").[8](https://en.wikipedia.org/wiki/QBittorrent#cite_note-8)[9](https://en.wikipedia.org/wiki/QBittorrent#cite_note-9). + +Note about macOS support: + +> The macOS version is **barely supported,** because we don't have active macOS developers/contributors. +> The project is in need of macOS developers. If you are a macOS developer willing to help, just go to our bug tracker for a list of macOS related issues. Or try to fix bugs that you yourself have discovered and annoy you. + +Languages: + +![[Pasted image 20241023155058.png]] \ No newline at end of file diff --git a/90 Extras/91 Templates/Book.md b/90 Extras/91 Templates/Book.md new file mode 100644 index 0000000..cc42eb7 --- /dev/null +++ b/90 Extras/91 Templates/Book.md @@ -0,0 +1,7 @@ +--- +tags: + - book +authors: +link: +related-to: +--- diff --git a/90 Extras/91 Templates/Tweet.md b/90 Extras/91 Templates/Tweet.md new file mode 100644 index 0000000..f79c48b --- /dev/null +++ b/90 Extras/91 Templates/Tweet.md @@ -0,0 +1,7 @@ +--- +tags: + - tweet +author: +link: +related-to: +--- diff --git a/90 Extras/92 Assets/Pasted image 20241023155058.png b/90 Extras/92 Assets/Pasted image 20241023155058.png new file mode 100644 index 0000000..8467241 Binary files /dev/null and b/90 Extras/92 Assets/Pasted image 20241023155058.png differ diff --git a/90 Extras/92 Assets/Pasted image 20241023155332.png b/90 Extras/92 Assets/Pasted image 20241023155332.png new file mode 100644 index 0000000..8467241 Binary files /dev/null and b/90 Extras/92 Assets/Pasted image 20241023155332.png differ diff --git a/90 Extras/92 Assets/Pasted image 20241023160207.png b/90 Extras/92 Assets/Pasted image 20241023160207.png new file mode 100644 index 0000000..5ae9ff7 Binary files /dev/null and b/90 Extras/92 Assets/Pasted image 20241023160207.png differ diff --git a/90 Extras/92 Assets/The_World_of_Peer-to-Peer.pdf b/90 Extras/92 Assets/The_World_of_Peer-to-Peer.pdf new file mode 100644 index 0000000..56ea952 Binary files /dev/null and b/90 Extras/92 Assets/The_World_of_Peer-to-Peer.pdf differ diff --git a/90 Extras/92 Assets/i-1fd3ae7c5502dfddfe8b2c7acdefaa5e-bittorrentecon.pdf b/90 Extras/92 Assets/i-1fd3ae7c5502dfddfe8b2c7acdefaa5e-bittorrentecon.pdf new file mode 100644 index 0000000..06ae156 Binary files /dev/null and b/90 Extras/92 Assets/i-1fd3ae7c5502dfddfe8b2c7acdefaa5e-bittorrentecon.pdf differ diff --git a/90 Extras/92 Assets/pouwelse-btmeasure.pdf b/90 Extras/92 Assets/pouwelse-btmeasure.pdf new file mode 100644 index 0000000..fa7f393 Binary files /dev/null and b/90 Extras/92 Assets/pouwelse-btmeasure.pdf differ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3336f23 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +``` +MIT License + +Copyright (c) [2024] [Marcin Czenko] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..624e495 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +--- +tags: + - bittorrent +--- +## BitTorrent/Codex Integration + +In this repository your will find a complete documentation of our BitTorrent/Codex investigation. + +### Objectives + +I was trying to answer the following questions: + +1. [[How BitTorrent/Codex integration may look like? ]] +2. [[What are existing (open source) BitTorrent clients?]] +3. [[What are the challenges ahead and how big the effort would be?]] + +Answering those three questions should give us answer to the big ultimate question: [[Is it all worth it?]] + +Getting there in short time is not easy, especially without recent hands-on experience with the BitTorrent protocol. Thus in this quest, the following actions are being taken: + +1. Identity [[Learn BitTorrent | the best resources to learn BitTorrent protocol]], to get some intuition about the protocol. This is mostly to answer the question number (1) above. +2. [[Comparison of BitTorrent clients | Compare existing BitTorrent clients]], trying to focus on those that are open sourced. We want to learn about their market share, how do they look and feel, and how easy would it be to work with their codebase. +3. Chose one of the client, and try to cat it through and learn how easy is to do what we think we want to do. What are the obstacles, and unexpected difficulties? This is the major part of our investigation. + +### Obsidian + +This repository is also a complete [Obsidian](https://obsidian.md) vault. You can open it on your computer in the [Obsidian App](https://obsidian.md/download) and have a complete snapshot of everything I have captured when working on the subject. Comparing to bloated [Notion](https://www.notion.so), which is a great tool for procrastination rather than a tool for capturing knowledge, Obsidian let's you capture the knowledge quickly and with excellent overview of how different topic connect to each other. And in the end - all are just Markdown files. + +The vault includes the `.obsidian` folder, but does not include publishing settings, and workspace configuration as those are personal and change every time you open the vault. If you want to have the full control over your Obsidian look and full, your own [[Hot-Keys|hot-keys]], [[Installed plugins|plugins]], etc, your can delete `.obsidian` or replace it with your own. + +### Published site + +For the duration of the project, I am also publishing the documentation at [https://publish.obsidian.md/bittorrent](https://publish.obsidian.md/bittorrent). +This will be removed after conclusion has been reached.