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