arky-sdk 0.3.85 → 0.3.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1712,164 +1712,8 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1712
1712
  }
1713
1713
  }
1714
1714
 
1715
- // src/utils/time.ts
1716
- function formatTime(ts, tz) {
1717
- return new Date(ts * 1e3).toLocaleTimeString([], {
1718
- hour: "2-digit",
1719
- minute: "2-digit",
1720
- timeZone: tz
1721
- });
1722
- }
1723
- function formatSlotTime(from, to, tz) {
1724
- return `${formatTime(from, tz)} \u2013 ${formatTime(to, tz)}`;
1725
- }
1726
- function getTzOffset(date, tz) {
1727
- const utc = new Date(date.toLocaleString("en-US", { timeZone: "UTC" }));
1728
- const local = new Date(date.toLocaleString("en-US", { timeZone: tz }));
1729
- return (utc.getTime() - local.getTime()) / 6e4;
1730
- }
1731
- function toUtcTimestamp(year, month, day, mins, tz) {
1732
- const midnight = new Date(Date.UTC(year, month - 1, day));
1733
- const offset = getTzOffset(midnight, tz);
1734
- return Math.floor(midnight.getTime() / 1e3) + (mins + offset) * 60;
1735
- }
1736
- function formatDateDisplay(dateStr, tz) {
1737
- if (!dateStr) return "";
1738
- const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
1739
- return date.toLocaleDateString("en-US", {
1740
- weekday: "short",
1741
- month: "short",
1742
- day: "numeric",
1743
- timeZone: tz
1744
- });
1745
- }
1746
- function getIsoDate(date, tz) {
1747
- return date.toLocaleDateString("en-CA", { timeZone: tz });
1748
- }
1749
- function parseIsoDate(isoDate) {
1750
- const [year, month, day] = isoDate.split("-").map(Number);
1751
- return { year, month, day };
1752
- }
1753
-
1754
- // src/utils/slots.ts
1755
- function getTotalDuration(durations) {
1756
- return durations.reduce((sum, d) => sum + d.duration, 0);
1757
- }
1758
- function isBlocked(from, to, timeline, limit) {
1759
- const before = timeline.filter((p) => p.timestamp <= from).sort((a, b) => b.timestamp - a.timestamp);
1760
- if (before.length > 0 && before[0].concurrent >= limit) return true;
1761
- for (const p of timeline) {
1762
- if (p.timestamp >= from && p.timestamp < to && p.concurrent >= limit) {
1763
- return true;
1764
- }
1765
- }
1766
- return false;
1767
- }
1768
- function getWorkingHoursForDate(wt, date, tz) {
1769
- if (!wt) return [];
1770
- const dayName = date.toLocaleDateString("en-US", { weekday: "long", timeZone: tz }).toLowerCase();
1771
- const m = date.getMonth() + 1;
1772
- const d = date.getDate();
1773
- const ts = Math.floor(date.getTime() / 1e3);
1774
- const specific = wt.specificDates?.find((s) => s.date === ts);
1775
- if (specific) return specific.workingHours || [];
1776
- const outcast = wt.outcastDates?.find((o) => o.month === m && o.day === d);
1777
- if (outcast) return outcast.workingHours || [];
1778
- return wt.workingDays?.find((w) => w.day === dayName)?.workingHours || [];
1779
- }
1780
- function computeSlotsForDate(opts) {
1781
- const { providers, date, durations, timezone, slotInterval } = opts;
1782
- const total = getTotalDuration(durations);
1783
- const interval = slotInterval || total;
1784
- const slots = [];
1785
- const nowTs = Math.floor(Date.now() / 1e3);
1786
- const today = /* @__PURE__ */ new Date();
1787
- today.setHours(0, 0, 0, 0);
1788
- if (date < today) return [];
1789
- const [year, month, day] = date.toLocaleDateString("en-CA", { timeZone: timezone }).split("-").map(Number);
1790
- for (const provider of providers) {
1791
- const workingHours = getWorkingHoursForDate(provider.workingTime, date, timezone);
1792
- for (const wh of workingHours) {
1793
- for (let m = wh.from; m + total <= wh.to; m += interval) {
1794
- const from = toUtcTimestamp(year, month, day, m, timezone);
1795
- const to = from + total * 60;
1796
- if (from < nowTs) continue;
1797
- if (!isBlocked(from, to, provider.timeline, provider.concurrentLimit)) {
1798
- slots.push({ from, to, providerId: provider.id });
1799
- }
1800
- }
1801
- }
1802
- }
1803
- return slots.sort((a, b) => a.from - b.from);
1804
- }
1805
- function hasAvailableSlots(opts) {
1806
- return computeSlotsForDate(opts).length > 0;
1807
- }
1808
- function buildCalendar(opts) {
1809
- const {
1810
- currentMonth,
1811
- selectedDate,
1812
- startDate,
1813
- endDate,
1814
- providers,
1815
- selectedProvider,
1816
- durations,
1817
- timezone,
1818
- isMultiDay
1819
- } = opts;
1820
- const year = currentMonth.getFullYear();
1821
- const month = currentMonth.getMonth();
1822
- const first = new Date(year, month, 1);
1823
- const last = new Date(year, month + 1, 0);
1824
- const today = /* @__PURE__ */ new Date();
1825
- today.setHours(0, 0, 0, 0);
1826
- const cells = [];
1827
- const pad = (first.getDay() + 6) % 7;
1828
- for (let i = 0; i < pad; i++) {
1829
- cells.push({
1830
- date: /* @__PURE__ */ new Date(0),
1831
- iso: "",
1832
- available: false,
1833
- isSelected: false,
1834
- isInRange: false,
1835
- isToday: false,
1836
- blank: true
1837
- });
1838
- }
1839
- const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1840
- for (let d = 1; d <= last.getDate(); d++) {
1841
- const date = new Date(year, month, d);
1842
- const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1843
- const available = activeProviders.length > 0 && hasAvailableSlots({ providers: activeProviders, date, durations, timezone });
1844
- const isToday = date.getTime() === today.getTime();
1845
- let isSelected = false;
1846
- let isInRange = false;
1847
- if (isMultiDay) {
1848
- isSelected = iso === startDate || iso === endDate;
1849
- if (startDate && endDate) {
1850
- isInRange = iso > startDate && iso < endDate;
1851
- }
1852
- } else {
1853
- isSelected = iso === selectedDate;
1854
- }
1855
- cells.push({
1856
- date,
1857
- iso,
1858
- available,
1859
- isSelected,
1860
- isInRange,
1861
- isToday,
1862
- blank: false
1863
- });
1864
- }
1865
- return cells;
1866
- }
1867
- function getMonthYear(date) {
1868
- return date.toLocaleDateString("en-US", { month: "long", year: "numeric" });
1869
- }
1870
-
1871
1715
  // src/index.ts
1872
- var SDK_VERSION = "0.3.85";
1716
+ var SDK_VERSION = "0.3.88";
1873
1717
  var SUPPORTED_FRAMEWORKS = [
1874
1718
  "astro",
1875
1719
  "react",
@@ -1970,23 +1814,7 @@ async function createArkySDK(config) {
1970
1814
  // SVG utilities
1971
1815
  getSvgContentForAstro,
1972
1816
  fetchSvgContent,
1973
- injectSvgIntoElement,
1974
- // Time utilities
1975
- formatTime,
1976
- formatSlotTime,
1977
- getTzOffset,
1978
- toUtcTimestamp,
1979
- formatDateDisplay,
1980
- getIsoDate,
1981
- parseIsoDate,
1982
- // Slot computation utilities
1983
- computeSlotsForDate,
1984
- hasAvailableSlots,
1985
- buildCalendar,
1986
- getMonthYear,
1987
- getTotalDuration,
1988
- isBlocked,
1989
- getWorkingHoursForDate
1817
+ injectSvgIntoElement
1990
1818
  }
1991
1819
  };
1992
1820
  return sdk;