labellife-design-tool 2.5.0 → 2.5.2

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