labellife-design-tool 2.5.0 → 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.
@@ -426,6 +426,12 @@ function t(key, defaultValue) {
426
426
  return defaultValue || key;
427
427
  }
428
428
 
429
+ // ── Backend API base URL (used by background-panel.js's Unsplash proxy calls) ─
430
+ var _apiBaseUrl = '';
431
+ function getApiBaseUrl() {
432
+ return _apiBaseUrl;
433
+ }
434
+
429
435
  // ── Input Fields Dialog Config ───────────────────────────────────────
430
436
  var INPUT_FIELDS_CONFIG_KEY = '__labellife_input_fields_config__';
431
437
  if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
@@ -1010,6 +1016,33 @@ var TextSection = {
1010
1016
  Panel: TextPanelContent
1011
1017
  };
1012
1018
 
1019
+ // src/side-panel/unsplash-api.js
1020
+ //
1021
+ // Pure, framework-free URL helpers for the Unsplash background search, proxied through the
1022
+ // labellife backend (see labellifeBackendRepo's UnsplashBackgroundSearchView /
1023
+ // UnsplashTrackDownloadView). Deliberately has no internal imports so it can be unit-tested
1024
+ // with plain `node`, following the same convention as ./fonts.js.
1025
+
1026
+ var UNSPLASH_UTM_SOURCE = 'labellife';
1027
+ function buildUnsplashSearchUrl(apiBaseUrl, query) {
1028
+ var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1029
+ var perPage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 20;
1030
+ var trimmed = query && String(query).trim();
1031
+ var q = trimmed || 'gradient';
1032
+ return "".concat(apiBaseUrl, "/api/polotno/unsplash/search/?query=").concat(encodeURIComponent(q), "&per_page=").concat(perPage, "&page=").concat(page);
1033
+ }
1034
+ function buildUnsplashTrackDownloadUrl(apiBaseUrl) {
1035
+ return "".concat(apiBaseUrl, "/api/polotno/unsplash/track-download/");
1036
+ }
1037
+
1038
+ // Unsplash API Guidelines require attribution links back to unsplash.com and to the
1039
+ // photographer's profile to carry UTM params identifying this app.
1040
+ function withUnsplashAttribution(url) {
1041
+ if (!url) return url;
1042
+ var separator = url.includes('?') ? '&' : '?';
1043
+ return "".concat(url).concat(separator, "utm_source=").concat(encodeURIComponent(UNSPLASH_UTM_SOURCE), "&utm_medium=referral");
1044
+ }
1045
+
1013
1046
  function hsvToRgb(h, s, v) {
1014
1047
  var i = Math.floor(h / 60) % 6;
1015
1048
  var f = h / 60 - Math.floor(h / 60);
@@ -1085,8 +1118,6 @@ function hueToColor(h) {
1085
1118
 
1086
1119
  // ─── Constants ───────────────────────────────────────────────────────
1087
1120
 
1088
- var UNSPLASH_KEY = 'zwiE802FyRjTmLhZjXqW';
1089
- var UNSPLASH_BASE = 'https://api.polotno.com/api/get-unsplash';
1090
1121
  var SWATCH_COLORS = ['#ffffff', '#1a237e', '#ff6d00', '#2e7d32', '#fdd835', '#9c27b0'];
1091
1122
  var PICKER_PRESETS = ['#f44336', '#ff9800', '#ffeb3b', '#4caf50', '#2196f3', '#9c27b0', '#00bcd4', '#8bc34a', '#cddc39', '#000000', '#607d8b', '#ffffff'];
1092
1123
  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";
@@ -1684,7 +1715,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1684
1715
  _context.p = 2;
1685
1716
  q = query || 'gradient';
1686
1717
  _context.n = 3;
1687
- return fetch("".concat(UNSPLASH_BASE, "?query=").concat(encodeURIComponent(q), "&per_page=20&page=").concat(pg, "&KEY=").concat(UNSPLASH_KEY));
1718
+ return fetch(buildUnsplashSearchUrl(getApiBaseUrl(), q, pg, 20));
1688
1719
  case 3:
1689
1720
  res = _context.v;
1690
1721
  _context.n = 4;
@@ -1916,7 +1947,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1916
1947
  color: '#888'
1917
1948
  },
1918
1949
  children: ["Photos by", ' ', /*#__PURE__*/jsxRuntime.jsx("a", {
1919
- href: "https://unsplash.com",
1950
+ href: withUnsplashAttribution('https://unsplash.com'),
1920
1951
  target: "_blank",
1921
1952
  rel: "noopener noreferrer",
1922
1953
  style: {
@@ -1932,16 +1963,33 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1932
1963
  gap: 1
1933
1964
  },
1934
1965
  children: photos.map(function (photo, idx) {
1935
- var _photo$urls, _photo$urls2;
1966
+ var _photo$urls, _photo$urls2, _photo$user, _photo$user2;
1936
1967
  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;
1937
1968
  if (!thumb) return null;
1938
- return /*#__PURE__*/jsxRuntime.jsx(material.Box, {
1969
+ var photographerName = (_photo$user = photo.user) === null || _photo$user === void 0 ? void 0 : _photo$user.name;
1970
+ 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);
1971
+ return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
1939
1972
  onClick: function onClick() {
1940
- var _photo$urls3, _photo$urls4;
1973
+ var _photo$urls3, _photo$urls4, _photo$links;
1941
1974
  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;
1942
- if (url) setBackground(url);
1975
+ if (!url) return;
1976
+ setBackground(url);
1977
+ // Unsplash API Guidelines require registering a "download" whenever a photo is used.
1978
+ // Best-effort: don't block or fail background-setting if this ping fails.
1979
+ if ((_photo$links = photo.links) !== null && _photo$links !== void 0 && _photo$links.download_location) {
1980
+ fetch(buildUnsplashTrackDownloadUrl(getApiBaseUrl()), {
1981
+ method: 'POST',
1982
+ headers: {
1983
+ 'Content-Type': 'application/json'
1984
+ },
1985
+ body: JSON.stringify({
1986
+ download_location: photo.links.download_location
1987
+ })
1988
+ })["catch"](function () {});
1989
+ }
1943
1990
  },
1944
1991
  sx: {
1992
+ position: 'relative',
1945
1993
  cursor: 'pointer',
1946
1994
  borderRadius: '8px',
1947
1995
  overflow: 'hidden',
@@ -1951,7 +1999,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1951
1999
  },
1952
2000
  transition: 'opacity 0.15s'
1953
2001
  },
1954
- children: /*#__PURE__*/jsxRuntime.jsx("img", {
2002
+ children: [/*#__PURE__*/jsxRuntime.jsx("img", {
1955
2003
  src: thumb,
1956
2004
  alt: photo.alt_description || 'Background',
1957
2005
  style: {
@@ -1961,7 +2009,32 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1961
2009
  display: 'block'
1962
2010
  },
1963
2011
  loading: "lazy"
1964
- })
2012
+ }), photographerName && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
2013
+ variant: "caption",
2014
+ component: "a",
2015
+ href: photographerUrl || undefined,
2016
+ target: "_blank",
2017
+ rel: "noopener noreferrer",
2018
+ onClick: function onClick(e) {
2019
+ return e.stopPropagation();
2020
+ },
2021
+ sx: {
2022
+ position: 'absolute',
2023
+ left: 0,
2024
+ right: 0,
2025
+ bottom: 0,
2026
+ px: 0.75,
2027
+ py: 0.25,
2028
+ fontSize: 10,
2029
+ color: '#fff',
2030
+ textDecoration: 'none',
2031
+ background: 'linear-gradient(to top, rgba(0,0,0,0.55), transparent)',
2032
+ whiteSpace: 'nowrap',
2033
+ overflow: 'hidden',
2034
+ textOverflow: 'ellipsis'
2035
+ },
2036
+ children: photographerName
2037
+ })]
1965
2038
  }, photo.id || idx);
1966
2039
  })
1967
2040
  }), hasMore && /*#__PURE__*/jsxRuntime.jsx(material.Box, {