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.
@@ -421,6 +421,17 @@ 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
+ // Window-level singleton, same reasoning as translations/input-fields config above:
426
+ // each Rollup output bundle (index, side-panel, toolbar, canvas...) gets its own copy
427
+ // of this module, so a plain closure variable set from one bundle (e.g. via the host
428
+ // app's top-level `labellife-design-tool/config` import) would never be seen by another
429
+ // bundle (e.g. background-panel.js, built into the side-panel bundle).
430
+ var API_BASE_URL_KEY = '__labellife_api_base_url__';
431
+ function getApiBaseUrl() {
432
+ return typeof window !== 'undefined' && window[API_BASE_URL_KEY] || '';
433
+ }
434
+
424
435
  // ── Input Fields Dialog Config ───────────────────────────────────────
425
436
  var INPUT_FIELDS_CONFIG_KEY = '__labellife_input_fields_config__';
426
437
  if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
@@ -1005,6 +1016,33 @@ var TextSection = {
1005
1016
  Panel: TextPanelContent
1006
1017
  };
1007
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
+
1008
1046
  function hsvToRgb(h, s, v) {
1009
1047
  var i = Math.floor(h / 60) % 6;
1010
1048
  var f = h / 60 - Math.floor(h / 60);
@@ -1080,8 +1118,6 @@ function hueToColor(h) {
1080
1118
 
1081
1119
  // ─── Constants ───────────────────────────────────────────────────────
1082
1120
 
1083
- var UNSPLASH_KEY = 'zwiE802FyRjTmLhZjXqW';
1084
- var UNSPLASH_BASE = 'https://api.polotno.com/api/get-unsplash';
1085
1121
  var SWATCH_COLORS = ['#ffffff', '#1a237e', '#ff6d00', '#2e7d32', '#fdd835', '#9c27b0'];
1086
1122
  var PICKER_PRESETS = ['#f44336', '#ff9800', '#ffeb3b', '#4caf50', '#2196f3', '#9c27b0', '#00bcd4', '#8bc34a', '#cddc39', '#000000', '#607d8b', '#ffffff'];
1087
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";
@@ -1679,7 +1715,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1679
1715
  _context.p = 2;
1680
1716
  q = query || 'gradient';
1681
1717
  _context.n = 3;
1682
- 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));
1683
1719
  case 3:
1684
1720
  res = _context.v;
1685
1721
  _context.n = 4;
@@ -1911,7 +1947,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1911
1947
  color: '#888'
1912
1948
  },
1913
1949
  children: ["Photos by", ' ', /*#__PURE__*/jsxRuntime.jsx("a", {
1914
- href: "https://unsplash.com",
1950
+ href: withUnsplashAttribution('https://unsplash.com'),
1915
1951
  target: "_blank",
1916
1952
  rel: "noopener noreferrer",
1917
1953
  style: {
@@ -1927,16 +1963,33 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1927
1963
  gap: 1
1928
1964
  },
1929
1965
  children: photos.map(function (photo, idx) {
1930
- var _photo$urls, _photo$urls2;
1966
+ var _photo$urls, _photo$urls2, _photo$user, _photo$user2;
1931
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;
1932
1968
  if (!thumb) return null;
1933
- 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, {
1934
1972
  onClick: function onClick() {
1935
- var _photo$urls3, _photo$urls4;
1973
+ var _photo$urls3, _photo$urls4, _photo$links;
1936
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;
1937
- 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
+ }
1938
1990
  },
1939
1991
  sx: {
1992
+ position: 'relative',
1940
1993
  cursor: 'pointer',
1941
1994
  borderRadius: '8px',
1942
1995
  overflow: 'hidden',
@@ -1946,7 +1999,7 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1946
1999
  },
1947
2000
  transition: 'opacity 0.15s'
1948
2001
  },
1949
- children: /*#__PURE__*/jsxRuntime.jsx("img", {
2002
+ children: [/*#__PURE__*/jsxRuntime.jsx("img", {
1950
2003
  src: thumb,
1951
2004
  alt: photo.alt_description || 'Background',
1952
2005
  style: {
@@ -1956,7 +2009,32 @@ var BackgroundPanelContent = mobxReactLite.observer(function (_ref5) {
1956
2009
  display: 'block'
1957
2010
  },
1958
2011
  loading: "lazy"
1959
- })
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
+ })]
1960
2038
  }, photo.id || idx);
1961
2039
  })
1962
2040
  }), hasMore && /*#__PURE__*/jsxRuntime.jsx(material.Box, {