labellife-design-tool 2.4.6 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -417,6 +417,12 @@ function t(key, defaultValue) {
417
417
  return defaultValue || key;
418
418
  }
419
419
 
420
+ // ── Backend API base URL (used by background-panel.js's Unsplash proxy calls) ─
421
+ var _apiBaseUrl = '';
422
+ function getApiBaseUrl() {
423
+ return _apiBaseUrl;
424
+ }
425
+
420
426
  // ── Input Fields Dialog Config ───────────────────────────────────────
421
427
  var INPUT_FIELDS_CONFIG_KEY = '__labellife_input_fields_config__';
422
428
  if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
@@ -1001,6 +1007,33 @@ var TextSection = {
1001
1007
  Panel: TextPanelContent
1002
1008
  };
1003
1009
 
1010
+ // src/side-panel/unsplash-api.js
1011
+ //
1012
+ // Pure, framework-free URL helpers for the Unsplash background search, proxied through the
1013
+ // labellife backend (see labellifeBackendRepo's UnsplashBackgroundSearchView /
1014
+ // UnsplashTrackDownloadView). Deliberately has no internal imports so it can be unit-tested
1015
+ // with plain `node`, following the same convention as ./fonts.js.
1016
+
1017
+ var UNSPLASH_UTM_SOURCE = 'labellife';
1018
+ function buildUnsplashSearchUrl(apiBaseUrl, query) {
1019
+ var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1020
+ var perPage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 20;
1021
+ var trimmed = query && String(query).trim();
1022
+ var q = trimmed || 'gradient';
1023
+ return "".concat(apiBaseUrl, "/api/polotno/unsplash/search/?query=").concat(encodeURIComponent(q), "&per_page=").concat(perPage, "&page=").concat(page);
1024
+ }
1025
+ function buildUnsplashTrackDownloadUrl(apiBaseUrl) {
1026
+ return "".concat(apiBaseUrl, "/api/polotno/unsplash/track-download/");
1027
+ }
1028
+
1029
+ // Unsplash API Guidelines require attribution links back to unsplash.com and to the
1030
+ // photographer's profile to carry UTM params identifying this app.
1031
+ function withUnsplashAttribution(url) {
1032
+ if (!url) return url;
1033
+ var separator = url.includes('?') ? '&' : '?';
1034
+ return "".concat(url).concat(separator, "utm_source=").concat(encodeURIComponent(UNSPLASH_UTM_SOURCE), "&utm_medium=referral");
1035
+ }
1036
+
1004
1037
  function hsvToRgb(h, s, v) {
1005
1038
  var i = Math.floor(h / 60) % 6;
1006
1039
  var f = h / 60 - Math.floor(h / 60);
@@ -1076,8 +1109,6 @@ function hueToColor(h) {
1076
1109
 
1077
1110
  // ─── Constants ───────────────────────────────────────────────────────
1078
1111
 
1079
- var UNSPLASH_KEY = 'zwiE802FyRjTmLhZjXqW';
1080
- var UNSPLASH_BASE = 'https://api.polotno.com/api/get-unsplash';
1081
1112
  var SWATCH_COLORS = ['#ffffff', '#1a237e', '#ff6d00', '#2e7d32', '#fdd835', '#9c27b0'];
1082
1113
  var PICKER_PRESETS = ['#f44336', '#ff9800', '#ffeb3b', '#4caf50', '#2196f3', '#9c27b0', '#00bcd4', '#8bc34a', '#cddc39', '#000000', '#607d8b', '#ffffff'];
1083
1114
  var CHECKER_SVG = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='8' height='8' fill='%23ccc'/%3E%3Crect x='8' y='8' width='8' height='8' fill='%23ccc'/%3E%3Crect x='8' width='8' height='8' fill='%23fff'/%3E%3Crect y='8' width='8' height='8' fill='%23fff'/%3E%3C/svg%3E";
@@ -1675,7 +1706,7 @@ var BackgroundPanelContent = observer(function (_ref5) {
1675
1706
  _context.p = 2;
1676
1707
  q = query || 'gradient';
1677
1708
  _context.n = 3;
1678
- return fetch("".concat(UNSPLASH_BASE, "?query=").concat(encodeURIComponent(q), "&per_page=20&page=").concat(pg, "&KEY=").concat(UNSPLASH_KEY));
1709
+ return fetch(buildUnsplashSearchUrl(getApiBaseUrl(), q, pg, 20));
1679
1710
  case 3:
1680
1711
  res = _context.v;
1681
1712
  _context.n = 4;
@@ -1907,7 +1938,7 @@ var BackgroundPanelContent = observer(function (_ref5) {
1907
1938
  color: '#888'
1908
1939
  },
1909
1940
  children: ["Photos by", ' ', /*#__PURE__*/jsx("a", {
1910
- href: "https://unsplash.com",
1941
+ href: withUnsplashAttribution('https://unsplash.com'),
1911
1942
  target: "_blank",
1912
1943
  rel: "noopener noreferrer",
1913
1944
  style: {
@@ -1923,16 +1954,33 @@ var BackgroundPanelContent = observer(function (_ref5) {
1923
1954
  gap: 1
1924
1955
  },
1925
1956
  children: photos.map(function (photo, idx) {
1926
- var _photo$urls, _photo$urls2;
1957
+ var _photo$urls, _photo$urls2, _photo$user, _photo$user2;
1927
1958
  var thumb = ((_photo$urls = photo.urls) === null || _photo$urls === void 0 ? void 0 : _photo$urls.small) || ((_photo$urls2 = photo.urls) === null || _photo$urls2 === void 0 ? void 0 : _photo$urls2.thumb) || photo.src;
1928
1959
  if (!thumb) return null;
1929
- return /*#__PURE__*/jsx(Box, {
1960
+ var photographerName = (_photo$user = photo.user) === null || _photo$user === void 0 ? void 0 : _photo$user.name;
1961
+ var photographerUrl = ((_photo$user2 = photo.user) === null || _photo$user2 === void 0 || (_photo$user2 = _photo$user2.links) === null || _photo$user2 === void 0 ? void 0 : _photo$user2.html) && withUnsplashAttribution(photo.user.links.html);
1962
+ return /*#__PURE__*/jsxs(Box, {
1930
1963
  onClick: function onClick() {
1931
- var _photo$urls3, _photo$urls4;
1964
+ var _photo$urls3, _photo$urls4, _photo$links;
1932
1965
  var url = ((_photo$urls3 = photo.urls) === null || _photo$urls3 === void 0 ? void 0 : _photo$urls3.regular) || ((_photo$urls4 = photo.urls) === null || _photo$urls4 === void 0 ? void 0 : _photo$urls4.small) || photo.src;
1933
- if (url) setBackground(url);
1966
+ if (!url) return;
1967
+ setBackground(url);
1968
+ // Unsplash API Guidelines require registering a "download" whenever a photo is used.
1969
+ // Best-effort: don't block or fail background-setting if this ping fails.
1970
+ if ((_photo$links = photo.links) !== null && _photo$links !== void 0 && _photo$links.download_location) {
1971
+ fetch(buildUnsplashTrackDownloadUrl(getApiBaseUrl()), {
1972
+ method: 'POST',
1973
+ headers: {
1974
+ 'Content-Type': 'application/json'
1975
+ },
1976
+ body: JSON.stringify({
1977
+ download_location: photo.links.download_location
1978
+ })
1979
+ })["catch"](function () {});
1980
+ }
1934
1981
  },
1935
1982
  sx: {
1983
+ position: 'relative',
1936
1984
  cursor: 'pointer',
1937
1985
  borderRadius: '8px',
1938
1986
  overflow: 'hidden',
@@ -1942,7 +1990,7 @@ var BackgroundPanelContent = observer(function (_ref5) {
1942
1990
  },
1943
1991
  transition: 'opacity 0.15s'
1944
1992
  },
1945
- children: /*#__PURE__*/jsx("img", {
1993
+ children: [/*#__PURE__*/jsx("img", {
1946
1994
  src: thumb,
1947
1995
  alt: photo.alt_description || 'Background',
1948
1996
  style: {
@@ -1952,7 +2000,32 @@ var BackgroundPanelContent = observer(function (_ref5) {
1952
2000
  display: 'block'
1953
2001
  },
1954
2002
  loading: "lazy"
1955
- })
2003
+ }), photographerName && /*#__PURE__*/jsx(Typography, {
2004
+ variant: "caption",
2005
+ component: "a",
2006
+ href: photographerUrl || undefined,
2007
+ target: "_blank",
2008
+ rel: "noopener noreferrer",
2009
+ onClick: function onClick(e) {
2010
+ return e.stopPropagation();
2011
+ },
2012
+ sx: {
2013
+ position: 'absolute',
2014
+ left: 0,
2015
+ right: 0,
2016
+ bottom: 0,
2017
+ px: 0.75,
2018
+ py: 0.25,
2019
+ fontSize: 10,
2020
+ color: '#fff',
2021
+ textDecoration: 'none',
2022
+ background: 'linear-gradient(to top, rgba(0,0,0,0.55), transparent)',
2023
+ whiteSpace: 'nowrap',
2024
+ overflow: 'hidden',
2025
+ textOverflow: 'ellipsis'
2026
+ },
2027
+ children: photographerName
2028
+ })]
1956
2029
  }, photo.id || idx);
1957
2030
  })
1958
2031
  }), hasMore && /*#__PURE__*/jsx(Box, {