labellife-design-tool 2.5.7 → 2.7.0

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.
@@ -38,6 +38,20 @@ function _asyncToGenerator(n) {
38
38
  });
39
39
  };
40
40
  }
41
+ function _classCallCheck(a, n) {
42
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
43
+ }
44
+ function _defineProperties(e, r) {
45
+ for (var t = 0; t < r.length; t++) {
46
+ var o = r[t];
47
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
48
+ }
49
+ }
50
+ function _createClass(e, r, t) {
51
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
52
+ writable: false
53
+ }), e;
54
+ }
41
55
  function _createForOfIteratorHelper(r, e) {
42
56
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
43
57
  if (!t) {
@@ -108,7 +122,10 @@ function _iterableToArrayLimit(r, l) {
108
122
  f = true,
109
123
  o = false;
110
124
  try {
111
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
125
+ if (i = (t = t.call(r)).next, 0 === l) {
126
+ if (Object(t) !== t) return;
127
+ f = !1;
128
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
112
129
  } catch (r) {
113
130
  o = true, n = r;
114
131
  } finally {
@@ -882,6 +899,22 @@ var TextElement = Shape.named('TextElement').props({
882
899
  return {
883
900
  toggleEditMode: function toggleEditMode(editing) {
884
901
  self._editModeEnabled = editing !== undefined ? editing : !self._editModeEnabled;
902
+ },
903
+ // Ends an inline text edit. The canvas editor writes the text on every keystroke
904
+ // without recording a history state, so the finished edit is committed here (once,
905
+ // and only when the text really changed). That makes it undoable and lets the
906
+ // activity log see it.
907
+ finishEdit: function finishEdit(_ref) {
908
+ var text = _ref.text,
909
+ originalText = _ref.originalText;
910
+ self.text = text;
911
+ self._editModeEnabled = false;
912
+ if (text === originalText) return;
913
+ try {
914
+ getRoot(self).history.addUndoState();
915
+ } catch (e) {
916
+ console.warn('Text edit: failed to record history state', e);
917
+ }
885
918
  }
886
919
  };
887
920
  });
@@ -1447,10 +1480,20 @@ var History = types.model('History', {
1447
1480
  self.history.splice(0, self.history.length - 100);
1448
1481
  self.undoIdx = self.history.length - 1;
1449
1482
  }
1483
+ self._notifyActivity('onCommit', stateToSave);
1450
1484
  } catch (e) {
1451
1485
  console.warn('History: failed to save state', e);
1452
1486
  }
1453
1487
  },
1488
+ // Feeds the plain-English activity log; it must never break editing.
1489
+ _notifyActivity: function _notifyActivity(method, snapshot) {
1490
+ try {
1491
+ var tracker = getRoot(self)._activity;
1492
+ if (tracker) tracker[method](snapshot);
1493
+ } catch (e) {
1494
+ console.warn('Activity log: failed to update', e);
1495
+ }
1496
+ },
1454
1497
  _restoreState: function _restoreState(state) {
1455
1498
  if (!state) return;
1456
1499
  self._ignoring = true;
@@ -1509,11 +1552,13 @@ var History = types.model('History', {
1509
1552
  if (!self.canUndo) return;
1510
1553
  self.undoIdx -= 1;
1511
1554
  self._restoreState(self.history[self.undoIdx]);
1555
+ self._notifyActivity('undone', self.history[self.undoIdx]);
1512
1556
  },
1513
1557
  redo: function redo() {
1514
1558
  if (!self.canRedo) return;
1515
1559
  self.undoIdx += 1;
1516
1560
  self._restoreState(self.history[self.undoIdx]);
1561
+ self._notifyActivity('redone', self.history[self.undoIdx]);
1517
1562
  },
1518
1563
  clear: function clear() {
1519
1564
  self.history.clear();
@@ -1608,6 +1653,742 @@ function buildFontFaceCss(customFont) {
1608
1653
  }).join('\n');
1609
1654
  }
1610
1655
 
1656
+ // src/model/activity-log.js
1657
+ //
1658
+ // Turns what the user does into plain English sentences. Pure functions on
1659
+ // plain snapshot objects: no MST, no React, so it runs under plain node tests.
1660
+ // Never writes image data or URLs into a sentence.
1661
+
1662
+ var DEFAULT_OPTIONS = {
1663
+ includeTextContent: true,
1664
+ maxTextLength: 40,
1665
+ maxEntries: 300,
1666
+ maxSentenceLength: 200,
1667
+ mergeWindowMs: 1500
1668
+ };
1669
+ function clip(text, max) {
1670
+ var s = String(text == null ? '' : text);
1671
+ return s.length > max ? "".concat(s.slice(0, max), "\u2026") : s;
1672
+ }
1673
+ function imageSource(src) {
1674
+ var s = String(src || '');
1675
+ if (s.startsWith('data:') || s.startsWith('blob:')) return 'uploaded';
1676
+ if (s.toLowerCase().includes('unsplash')) return 'stock photo';
1677
+ return '';
1678
+ }
1679
+ function describeElement(el) {
1680
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
1681
+ var type = el && el.type;
1682
+ switch (type) {
1683
+ case 'text':
1684
+ {
1685
+ var text = el.text == null ? '' : String(el.text);
1686
+ if (!opts.includeTextContent || !text) return 'the text';
1687
+ return "the text \"".concat(clip(text, opts.maxTextLength), "\"");
1688
+ }
1689
+ case 'image':
1690
+ return 'the image';
1691
+ case 'figure':
1692
+ return el.subType ? "the shape (".concat(el.subType, ")") : 'the shape';
1693
+ case 'line':
1694
+ return 'the line';
1695
+ case 'group':
1696
+ return 'the group';
1697
+ case 'svg':
1698
+ return 'the graphic';
1699
+ default:
1700
+ return 'the element';
1701
+ }
1702
+ }
1703
+
1704
+ // ── Start, final and popup sentences ────────────────────────────────
1705
+
1706
+ var MAX_LISTED_TEXTS = 5;
1707
+ var HIDDEN_VALUE = '(value hidden)';
1708
+ function walk(children, fn) {
1709
+ (children || []).forEach(function (child) {
1710
+ if (!child) return;
1711
+ fn(child);
1712
+ if (child.children) walk(child.children, fn);
1713
+ });
1714
+ }
1715
+ function allElements(snapshot) {
1716
+ var out = [];
1717
+ (snapshot && snapshot.pages || []).forEach(function (page) {
1718
+ return walk(page && page.children, function (el) {
1719
+ return out.push(el);
1720
+ });
1721
+ });
1722
+ return out;
1723
+ }
1724
+ var num = function num(n) {
1725
+ return String(Number.isFinite(+n) ? +(+n).toFixed(2) : n);
1726
+ };
1727
+ function describeSize(snapshot) {
1728
+ var s = snapshot || {};
1729
+ return "".concat(num(s.width), " x ").concat(num(s.height), " ").concat(s.unit || 'px');
1730
+ }
1731
+ var plural = function plural(n, word) {
1732
+ return "".concat(n, " ").concat(word).concat(n === 1 ? '' : 's');
1733
+ };
1734
+ var COUNTED = [['text', 'text'], ['image', 'image'], ['figure', 'shape'], ['line', 'line'], ['svg', 'graphic']];
1735
+ function countParts(elements) {
1736
+ return COUNTED.map(function (_ref) {
1737
+ var _ref2 = _slicedToArray(_ref, 2),
1738
+ type = _ref2[0],
1739
+ word = _ref2[1];
1740
+ return [elements.filter(function (e) {
1741
+ return e.type === type;
1742
+ }).length, word];
1743
+ }).filter(function (_ref3) {
1744
+ var _ref4 = _slicedToArray(_ref3, 1),
1745
+ n = _ref4[0];
1746
+ return n > 0;
1747
+ }).map(function (_ref5) {
1748
+ var _ref6 = _slicedToArray(_ref5, 2),
1749
+ n = _ref6[0],
1750
+ word = _ref6[1];
1751
+ return plural(n, word);
1752
+ });
1753
+ }
1754
+ function joinWithAnd(parts) {
1755
+ if (parts.length <= 1) return parts.join('');
1756
+ return "".concat(parts.slice(0, -1).join(', '), " and ").concat(parts[parts.length - 1]);
1757
+ }
1758
+ function variableName(el) {
1759
+ var custom = el && el.custom || {};
1760
+ return custom.variableName || custom.promptText || 'the field';
1761
+ }
1762
+ function describeStart(snapshot) {
1763
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
1764
+ var elements = allElements(snapshot);
1765
+ var size = describeSize(snapshot);
1766
+ if (elements.length === 0) return ["Started from a blank label, ".concat(size, ".")];
1767
+ var parts = countParts(elements);
1768
+ var texts = elements.filter(function (e) {
1769
+ return e.type === 'text' && e.text;
1770
+ });
1771
+ if (opts.includeTextContent && texts.length && parts[0].endsWith(texts.length === 1 ? ' text' : ' texts')) {
1772
+ var listed = texts.slice(0, MAX_LISTED_TEXTS).map(function (e) {
1773
+ return "\"".concat(clip(e.text, opts.maxTextLength), "\"");
1774
+ }).join(', ');
1775
+ parts[0] = "".concat(parts[0], " (").concat(listed, ")");
1776
+ }
1777
+ var pages = (snapshot && snapshot.pages || []).length || 1;
1778
+ var sentences = ["Started from a template, ".concat(size, ", ").concat(plural(pages, 'page'), ", with ").concat(joinWithAnd(parts), ".")];
1779
+ var vars = elements.filter(function (e) {
1780
+ return e.custom && e.custom.inputField;
1781
+ });
1782
+ if (vars.length) {
1783
+ var named = vars.map(function (e) {
1784
+ return "\"".concat(variableName(e), "\" (").concat(e.custom.inputType || 'text', ")");
1785
+ }).join(', ');
1786
+ sentences.push("The template asked for ".concat(plural(vars.length, 'variable'), ": ").concat(named, "."));
1787
+ }
1788
+ return sentences;
1789
+ }
1790
+ function describeFinal(snapshot) {
1791
+ var parts = countParts(allElements(snapshot));
1792
+ return "Final label: ".concat([].concat(_toConsumableArray(parts.length ? parts : ['empty']), [describeSize(snapshot)]).join(', '), ".");
1793
+ }
1794
+ function describePopup() {
1795
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1796
+ action = _ref7.action,
1797
+ field = _ref7.field,
1798
+ value = _ref7.value;
1799
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
1800
+ if (action === 'finish') return 'User finished the variable questions.';
1801
+ var custom = field && field.custom || {};
1802
+ var name = variableName(field);
1803
+ var shown = function shown(v) {
1804
+ return opts.includeTextContent ? clip(v, opts.maxTextLength) : HIDDEN_VALUE;
1805
+ };
1806
+ switch (action) {
1807
+ case 'skip':
1808
+ return custom.removeIfSkipped ? "User skipped variable \"".concat(name, "\"; the element was removed from the label.") : "User skipped variable \"".concat(name, "\".");
1809
+ case 'back':
1810
+ return "User went back to change variable \"".concat(name, "\".");
1811
+ case 'submit':
1812
+ break;
1813
+ default:
1814
+ return "User answered variable \"".concat(name, "\".");
1815
+ }
1816
+ switch (custom.inputType) {
1817
+ case 'radio':
1818
+ {
1819
+ var isOption = Array.isArray(custom.options) && custom.options.includes(value);
1820
+ return isOption ? "User chose \"".concat(shown(value), "\" for variable \"").concat(name, "\".") : "User typed their own answer \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
1821
+ }
1822
+ case 'list':
1823
+ {
1824
+ var picked = String(value == null ? '' : value).split(', ').filter(Boolean).map(function (v) {
1825
+ return "\"".concat(shown(v), "\"");
1826
+ }).join(', ');
1827
+ return "User selected ".concat(picked, " for variable \"").concat(name, "\".");
1828
+ }
1829
+ case 'date':
1830
+ return "User picked the date \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
1831
+ case 'integer':
1832
+ return "User entered the number ".concat(shown(value), " for variable \"").concat(name, "\".");
1833
+ case 'image':
1834
+ return "User uploaded an image for variable \"".concat(name, "\".");
1835
+ default:
1836
+ return "User entered \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
1837
+ }
1838
+ }
1839
+
1840
+ // ── Diff: snapshot → sentences ──────────────────────────────────────
1841
+
1842
+ var words = function words(prop) {
1843
+ return String(prop).replace(/([A-Z])/g, ' $1').toLowerCase().trim();
1844
+ };
1845
+ var _short = function _short(v) {
1846
+ var s = String(v == null ? '' : v);
1847
+ return "".concat(s.length, ":").concat(s.slice(0, 40));
1848
+ };
1849
+ var isLocked = function isLocked(el) {
1850
+ return el.draggable === false && el.resizable === false && el.contentEditable === false && el.styleEditable === false;
1851
+ };
1852
+ var quotedText = function quotedText(el, n, opts) {
1853
+ return opts.includeTextContent && el.text ? "\"".concat(clip(el.text, opts.maxTextLength), "\"") : n;
1854
+ };
1855
+
1856
+ // One row per property group: how to read its value, and how to word the change.
1857
+ // A new property is one new row. `render(ctx)` returns (from, to) => sentence so a
1858
+ // merged entry can be re-worded with its first `from` and last `to`.
1859
+ var ROWS = [{
1860
+ key: 'text',
1861
+ props: ['text'],
1862
+ render: function render(_ref8) {
1863
+ var opts = _ref8.opts;
1864
+ return function (f, t) {
1865
+ return opts.includeTextContent ? "Changed the text \"".concat(clip(f, opts.maxTextLength), "\" to \"").concat(clip(t, opts.maxTextLength), "\".") : 'Changed the text.';
1866
+ };
1867
+ }
1868
+ }, {
1869
+ key: 'fontFamily',
1870
+ props: ['fontFamily'],
1871
+ render: function render(_ref9) {
1872
+ var n = _ref9.n;
1873
+ return function (f, t) {
1874
+ return "Changed the font of ".concat(n, " to ").concat(t, ".");
1875
+ };
1876
+ }
1877
+ }, {
1878
+ key: 'fontSize',
1879
+ props: ['fontSize'],
1880
+ render: function render(_ref0) {
1881
+ var n = _ref0.n;
1882
+ return function (f, t) {
1883
+ return "Changed the font size of ".concat(n, " from ").concat(f, " to ").concat(t, ".");
1884
+ };
1885
+ }
1886
+ }, {
1887
+ key: 'fill',
1888
+ props: ['fill'],
1889
+ render: function render(_ref1) {
1890
+ var n = _ref1.n;
1891
+ return function (f, t) {
1892
+ return "Changed the colour of ".concat(n, " to ").concat(t, ".");
1893
+ };
1894
+ }
1895
+ }, {
1896
+ key: 'position',
1897
+ props: ['x', 'y'],
1898
+ render: function render(_ref10) {
1899
+ var n = _ref10.n;
1900
+ return function () {
1901
+ return "Moved ".concat(n, ".");
1902
+ };
1903
+ }
1904
+ }, {
1905
+ key: 'size',
1906
+ props: ['width', 'height'],
1907
+ render: function render(_ref11) {
1908
+ var n = _ref11.n;
1909
+ return function () {
1910
+ return "Resized ".concat(n, ".");
1911
+ };
1912
+ }
1913
+ }, {
1914
+ key: 'rotation',
1915
+ props: ['rotation'],
1916
+ render: function render(_ref12) {
1917
+ var n = _ref12.n;
1918
+ return function (f, t) {
1919
+ return "Rotated ".concat(n, " to ").concat(t, " degrees.");
1920
+ };
1921
+ }
1922
+ }, {
1923
+ key: 'visible',
1924
+ props: ['visible'],
1925
+ render: function render(_ref13) {
1926
+ var n = _ref13.n;
1927
+ return function (f, t) {
1928
+ return t ? "Showed ".concat(n, ".") : "Hid ".concat(n, ".");
1929
+ };
1930
+ }
1931
+ }, {
1932
+ key: 'lock',
1933
+ props: ['draggable', 'resizable', 'contentEditable', 'styleEditable'],
1934
+ value: isLocked,
1935
+ render: function render(_ref14) {
1936
+ var n = _ref14.n;
1937
+ return function (f, t) {
1938
+ return t ? "Locked ".concat(n, ".") : "Unlocked ".concat(n, ".");
1939
+ };
1940
+ }
1941
+ }, {
1942
+ key: 'crop',
1943
+ props: ['cropX', 'cropY', 'cropWidth', 'cropHeight'],
1944
+ render: function render(_ref15) {
1945
+ var n = _ref15.n;
1946
+ return function () {
1947
+ return "Cropped ".concat(n, ".");
1948
+ };
1949
+ }
1950
+ }, {
1951
+ key: 'clipSrc',
1952
+ props: ['clipSrc'],
1953
+ render: function render(_ref16) {
1954
+ var n = _ref16.n;
1955
+ return function (f, t) {
1956
+ return t ? "Applied a mask to ".concat(n, ".") : "Removed the mask from ".concat(n, ".");
1957
+ };
1958
+ }
1959
+ }, {
1960
+ key: 'curveEnabled',
1961
+ props: ['curveEnabled'],
1962
+ render: function render(_ref17) {
1963
+ var n = _ref17.n,
1964
+ next = _ref17.next,
1965
+ opts = _ref17.opts;
1966
+ return function (f, t) {
1967
+ return t ? "Applied curved text to ".concat(quotedText(next, n, opts), ".") : "Removed the curve from ".concat(n, ".");
1968
+ };
1969
+ }
1970
+ }, {
1971
+ key: 'shadowEnabled',
1972
+ props: ['shadowEnabled'],
1973
+ render: function render(_ref18) {
1974
+ var n = _ref18.n;
1975
+ return function (f, t) {
1976
+ return t ? "Added a shadow to ".concat(n, ".") : "Removed the shadow from ".concat(n, ".");
1977
+ };
1978
+ }
1979
+ }, {
1980
+ key: 'grayscaleEnabled',
1981
+ props: ['grayscaleEnabled'],
1982
+ render: function render(_ref19) {
1983
+ var n = _ref19.n;
1984
+ return function (f, t) {
1985
+ return t ? "Made ".concat(n, " grayscale.") : "Removed the grayscale from ".concat(n, ".");
1986
+ };
1987
+ }
1988
+ }, {
1989
+ key: 'src',
1990
+ props: ['src'],
1991
+ value: function value(el) {
1992
+ return _short(el.src);
1993
+ },
1994
+ render: function render(_ref20) {
1995
+ var n = _ref20.n,
1996
+ next = _ref20.next;
1997
+ return function () {
1998
+ var source = imageSource(next.src);
1999
+ var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
2000
+ return "Replaced ".concat(n).concat(note, ".");
2001
+ };
2002
+ }
2003
+ }];
2004
+ var HANDLED = new Set(['id', 'type', 'custom', 'children'].concat(_toConsumableArray(ROWS.flatMap(function (r) {
2005
+ return r.props;
2006
+ }))));
2007
+ function rowValue(row, el) {
2008
+ if (row.value) return row.value(el);
2009
+ return row.props.length === 1 ? el[row.props[0]] : row.props.map(function (p) {
2010
+ return el[p];
2011
+ }).join(',');
2012
+ }
2013
+ function indexSnapshot(snapshot) {
2014
+ var pages = new Map();
2015
+ var elements = new Map();
2016
+ var orders = new Map();
2017
+ (snapshot && snapshot.pages || []).forEach(function (page) {
2018
+ if (!page) return;
2019
+ pages.set(page.id, page);
2020
+ var _visit = function visit(children, parentId) {
2021
+ orders.set(parentId, (children || []).filter(Boolean).map(function (c) {
2022
+ return c.id;
2023
+ }));
2024
+ (children || []).forEach(function (child) {
2025
+ if (!child) return;
2026
+ elements.set(child.id, {
2027
+ el: child,
2028
+ parentId: parentId
2029
+ });
2030
+ if (child.children) _visit(child.children, child.id);
2031
+ });
2032
+ };
2033
+ _visit(page.children, page.id);
2034
+ });
2035
+ return {
2036
+ pages: pages,
2037
+ elements: elements,
2038
+ orders: orders
2039
+ };
2040
+ }
2041
+ function indefinite(el, opts) {
2042
+ switch (el.type) {
2043
+ case 'text':
2044
+ return opts.includeTextContent && el.text ? "a text \"".concat(clip(el.text, opts.maxTextLength), "\"") : 'a text';
2045
+ case 'image':
2046
+ {
2047
+ var source = imageSource(el.src);
2048
+ var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
2049
+ return "an image".concat(note);
2050
+ }
2051
+ case 'figure':
2052
+ return el.subType ? "a shape (".concat(el.subType, ")") : 'a shape';
2053
+ case 'line':
2054
+ return 'a line';
2055
+ case 'group':
2056
+ return 'a group';
2057
+ case 'svg':
2058
+ return 'a graphic';
2059
+ default:
2060
+ return 'an element';
2061
+ }
2062
+ }
2063
+ var BACKGROUND_IMAGE = /^(https?:|data:|blob:|url\()/;
2064
+ function diffToEntries(prev, next) {
2065
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS;
2066
+ if (!prev || !next) return [];
2067
+ var a = indexSnapshot(prev);
2068
+ var b = indexSnapshot(next);
2069
+ var out = [];
2070
+
2071
+ // Label size
2072
+ var sizeFrom = describeSize(prev);
2073
+ var sizeTo = describeSize(next);
2074
+ if (sizeFrom !== sizeTo) {
2075
+ out.push({
2076
+ key: 'label:size',
2077
+ from: sizeFrom,
2078
+ to: sizeTo,
2079
+ render: function render(f, t) {
2080
+ return "Changed the label size from ".concat(f, " to ").concat(t, ".");
2081
+ },
2082
+ sentence: "Changed the label size from ".concat(sizeFrom, " to ").concat(sizeTo, ".")
2083
+ });
2084
+ }
2085
+
2086
+ // Pages
2087
+ var addedPages = new Set(_toConsumableArray(b.pages.keys()).filter(function (id) {
2088
+ return !a.pages.has(id);
2089
+ }));
2090
+ var removedPages = new Set(_toConsumableArray(a.pages.keys()).filter(function (id) {
2091
+ return !b.pages.has(id);
2092
+ }));
2093
+ addedPages.forEach(function (id) {
2094
+ return out.push({
2095
+ key: "".concat(id, ":added"),
2096
+ sentence: 'Added a page.'
2097
+ });
2098
+ });
2099
+ removedPages.forEach(function (id) {
2100
+ return out.push({
2101
+ key: "".concat(id, ":removed"),
2102
+ sentence: 'Removed a page.'
2103
+ });
2104
+ });
2105
+
2106
+ // Added and removed elements (only the top of an added/removed subtree)
2107
+ var added = new Set(_toConsumableArray(b.elements.keys()).filter(function (id) {
2108
+ return !a.elements.has(id);
2109
+ }));
2110
+ var removed = new Set(_toConsumableArray(a.elements.keys()).filter(function (id) {
2111
+ return !b.elements.has(id);
2112
+ }));
2113
+ added.forEach(function (id) {
2114
+ var _b$elements$get = b.elements.get(id),
2115
+ el = _b$elements$get.el,
2116
+ parentId = _b$elements$get.parentId;
2117
+ if (added.has(parentId) || addedPages.has(parentId)) return;
2118
+ out.push({
2119
+ key: "".concat(id, ":added"),
2120
+ sentence: "Added ".concat(indefinite(el, opts), ".")
2121
+ });
2122
+ });
2123
+ removed.forEach(function (id) {
2124
+ var _a$elements$get = a.elements.get(id),
2125
+ el = _a$elements$get.el,
2126
+ parentId = _a$elements$get.parentId;
2127
+ if (removed.has(parentId) || removedPages.has(parentId)) return;
2128
+ out.push({
2129
+ key: "".concat(id, ":removed"),
2130
+ sentence: "Removed ".concat(describeElement(el, opts), ".")
2131
+ });
2132
+ });
2133
+
2134
+ // Changed elements
2135
+ b.elements.forEach(function (_ref21, id) {
2136
+ var nextEl = _ref21.el;
2137
+ var before = a.elements.get(id);
2138
+ if (!before) return;
2139
+ var prevEl = before.el;
2140
+ var ctx = {
2141
+ n: describeElement(nextEl, opts),
2142
+ prev: prevEl,
2143
+ next: nextEl,
2144
+ opts: opts
2145
+ };
2146
+ ROWS.forEach(function (row) {
2147
+ var from = rowValue(row, prevEl);
2148
+ var to = rowValue(row, nextEl);
2149
+ if (from === to || from === undefined && to === undefined) return;
2150
+ var render = row.render(ctx);
2151
+ out.push({
2152
+ key: "".concat(id, ":").concat(row.key),
2153
+ from: from,
2154
+ to: to,
2155
+ render: render,
2156
+ sentence: render(from, to)
2157
+ });
2158
+ });
2159
+ var props = new Set([].concat(_toConsumableArray(Object.keys(prevEl)), _toConsumableArray(Object.keys(nextEl))));
2160
+ props.forEach(function (prop) {
2161
+ if (HANDLED.has(prop)) return;
2162
+ var from = JSON.stringify(prevEl[prop]);
2163
+ var to = JSON.stringify(nextEl[prop]);
2164
+ if (from === to) return;
2165
+ out.push({
2166
+ key: "".concat(id, ":").concat(prop),
2167
+ from: from,
2168
+ to: to,
2169
+ sentence: "Changed the ".concat(words(prop), " of ").concat(ctx.n, ".")
2170
+ });
2171
+ });
2172
+ });
2173
+
2174
+ // Layer order within each parent, for elements present before and after
2175
+ b.orders.forEach(function (nextIds, parentId) {
2176
+ var prevIds = a.orders.get(parentId);
2177
+ if (!prevIds) return;
2178
+ var common = new Set(nextIds.filter(function (id) {
2179
+ return prevIds.includes(id);
2180
+ }));
2181
+ var pOrder = prevIds.filter(function (id) {
2182
+ return common.has(id);
2183
+ });
2184
+ var nOrder = nextIds.filter(function (id) {
2185
+ return common.has(id);
2186
+ });
2187
+ if (pOrder.join('|') === nOrder.join('|')) return;
2188
+ var mover = nOrder.find(function (c) {
2189
+ var p = pOrder.filter(function (id) {
2190
+ return id !== c;
2191
+ }).join('|');
2192
+ var n = nOrder.filter(function (id) {
2193
+ return id !== c;
2194
+ }).join('|');
2195
+ return p === n;
2196
+ });
2197
+ if (!mover) {
2198
+ out.push({
2199
+ key: "".concat(parentId, ":order"),
2200
+ sentence: 'Changed the layer order.'
2201
+ });
2202
+ return;
2203
+ }
2204
+ var name = describeElement(b.elements.get(mover).el, opts);
2205
+ var pos = nOrder.indexOf(mover);
2206
+ var sentence = pos === nOrder.length - 1 ? "Brought ".concat(name, " to the front.") : pos === 0 ? "Sent ".concat(name, " to the back.") : "Changed the layer order of ".concat(name, ".");
2207
+ out.push({
2208
+ key: "".concat(mover, ":order"),
2209
+ sentence: sentence
2210
+ });
2211
+ });
2212
+
2213
+ // Page background
2214
+ b.pages.forEach(function (page, id) {
2215
+ var before = a.pages.get(id);
2216
+ if (!before) return;
2217
+ var from = before.background || '';
2218
+ var to = page.background || '';
2219
+ if (from === to) return;
2220
+ var sentence = !to ? 'Removed the background.' : BACKGROUND_IMAGE.test(to) ? 'Set an image as the background.' : "Changed the background colour to ".concat(to, ".");
2221
+ out.push({
2222
+ key: "".concat(id, ":background"),
2223
+ sentence: sentence
2224
+ });
2225
+ });
2226
+ return out;
2227
+ }
2228
+
2229
+ // ── Tracker: keeps the log, merges quick repeats, caps the size ─────
2230
+
2231
+ var ActivityTracker = /*#__PURE__*/function () {
2232
+ function ActivityTracker() {
2233
+ var getOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
2234
+ return DEFAULT_OPTIONS;
2235
+ };
2236
+ var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now;
2237
+ _classCallCheck(this, ActivityTracker);
2238
+ this._getOptions = getOptions;
2239
+ this._now = now;
2240
+ this.clear();
2241
+ }
2242
+ return _createClass(ActivityTracker, [{
2243
+ key: "_opts",
2244
+ get: function get() {
2245
+ return _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), this._getOptions() || {});
2246
+ }
2247
+ }, {
2248
+ key: "clear",
2249
+ value: function clear() {
2250
+ this._start = [];
2251
+ this._actions = [];
2252
+ this._dropped = false;
2253
+ this._baseline = null;
2254
+ }
2255
+ }, {
2256
+ key: "reset",
2257
+ value: function reset(snapshot) {
2258
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2259
+ this.clear();
2260
+ if (!snapshot) return;
2261
+ this._baseline = snapshot;
2262
+ this._start = [].concat(_toConsumableArray(describeStart(snapshot, this._opts)), _toConsumableArray(extra));
2263
+ }
2264
+ }, {
2265
+ key: "rebaseline",
2266
+ value: function rebaseline(snapshot) {
2267
+ if (snapshot) this._baseline = snapshot;
2268
+ }
2269
+
2270
+ // The canvas sometimes rewrites an element by itself (e.g. re-measuring a text's height once a
2271
+ // font has loaded). That is not something the user did, so fold it into the baseline for just
2272
+ // that element: the next commit then won't report it, and the user's own pending changes stay.
2273
+ }, {
2274
+ key: "patchBaseline",
2275
+ value: function patchBaseline(id, attrs) {
2276
+ if (!id || !this._baseline) return;
2277
+ var _patch = function patch(children) {
2278
+ return (children || []).map(function (child) {
2279
+ if (!child) return child;
2280
+ if (child.id === id) return _objectSpread2(_objectSpread2({}, child), attrs);
2281
+ return child.children ? _objectSpread2(_objectSpread2({}, child), {}, {
2282
+ children: _patch(child.children)
2283
+ }) : child;
2284
+ });
2285
+ };
2286
+ this._baseline = _objectSpread2(_objectSpread2({}, this._baseline), {}, {
2287
+ pages: (this._baseline.pages || []).map(function (page) {
2288
+ return page ? _objectSpread2(_objectSpread2({}, page), {}, {
2289
+ children: _patch(page.children)
2290
+ }) : page;
2291
+ })
2292
+ });
2293
+ }
2294
+ }, {
2295
+ key: "onCommit",
2296
+ value: function onCommit(snapshot) {
2297
+ var _this = this;
2298
+ if (!snapshot) return;
2299
+ var previous = this._baseline;
2300
+ this._baseline = snapshot;
2301
+ if (!previous) return;
2302
+ diffToEntries(previous, snapshot, this._opts).forEach(function (entry) {
2303
+ return _this._add(entry);
2304
+ });
2305
+ }
2306
+ }, {
2307
+ key: "record",
2308
+ value: function record(sentence, key) {
2309
+ this._add({
2310
+ key: key,
2311
+ sentence: String(sentence)
2312
+ });
2313
+ }
2314
+ }, {
2315
+ key: "undone",
2316
+ value: function undone(snapshot) {
2317
+ this._add({
2318
+ sentence: 'Undid the last change.'
2319
+ });
2320
+ this.rebaseline(snapshot);
2321
+ }
2322
+ }, {
2323
+ key: "redone",
2324
+ value: function redone(snapshot) {
2325
+ this._add({
2326
+ sentence: 'Redid the last change.'
2327
+ });
2328
+ this.rebaseline(snapshot);
2329
+ }
2330
+ }, {
2331
+ key: "getLog",
2332
+ value: function getLog(finalSnapshot) {
2333
+ var maxSentenceLength = this._opts.maxSentenceLength;
2334
+ var lines = _toConsumableArray(this._start);
2335
+ if (this._dropped) lines.push('Earlier actions were left out.');
2336
+ this._actions.forEach(function (a) {
2337
+ return lines.push(a.sentence);
2338
+ });
2339
+ if (finalSnapshot) lines.push(describeFinal(finalSnapshot));
2340
+ return lines.map(function (line) {
2341
+ return clip(line, maxSentenceLength);
2342
+ });
2343
+ }
2344
+ }, {
2345
+ key: "_add",
2346
+ value: function _add(entry) {
2347
+ var at = this._now();
2348
+ var last = this._actions[this._actions.length - 1];
2349
+ var _this$_opts = this._opts,
2350
+ mergeWindowMs = _this$_opts.mergeWindowMs,
2351
+ maxEntries = _this$_opts.maxEntries;
2352
+ if (entry.key && last && last.key === entry.key && at - last.at <= mergeWindowMs) {
2353
+ if (entry.render && last.render) {
2354
+ if (last.from === entry.to) {
2355
+ this._actions.pop();
2356
+ return;
2357
+ }
2358
+ this._actions[this._actions.length - 1] = _objectSpread2(_objectSpread2({}, entry), {}, {
2359
+ from: last.from,
2360
+ at: at,
2361
+ sentence: entry.render(last.from, entry.to)
2362
+ });
2363
+ } else {
2364
+ this._actions[this._actions.length - 1] = _objectSpread2(_objectSpread2({}, entry), {}, {
2365
+ at: at
2366
+ });
2367
+ }
2368
+ return;
2369
+ }
2370
+ this._actions.push(_objectSpread2(_objectSpread2({}, entry), {}, {
2371
+ at: at
2372
+ }));
2373
+ if (this._actions.length > maxEntries) {
2374
+ this._actions.shift();
2375
+ this._dropped = true;
2376
+ }
2377
+ }
2378
+ }]);
2379
+ }();
2380
+
2381
+ // ── Options singleton ───────────────────────────────────────────────
2382
+ // Window-level, like the other config: each Rollup output bundle gets its own
2383
+ // copy of this module, so a closure variable set from one would never be seen
2384
+ // by another.
2385
+
2386
+ var OPTIONS_KEY = '__labellife_activity_log_options__';
2387
+ function getActivityLogOptions() {
2388
+ var set = typeof window !== 'undefined' && window[OPTIONS_KEY] || {};
2389
+ return _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), set);
2390
+ }
2391
+
1611
2392
  var _excluded = ["mimeType", "quality", "dpi", "dpiMetadata"],
1612
2393
  _excluded2 = ["mimeType", "quality"],
1613
2394
  _excluded3 = ["fileName"],
@@ -1724,7 +2505,9 @@ var Store = types.model('Store', {
1724
2505
  // incremented after each font load to trigger canvas re-render
1725
2506
  _pendingInputFields: [],
1726
2507
  // elements awaiting user input after loadJSON
1727
- customFonts: [] // host-injected custom font catalog: [{ name, variants: [{weight,style,file}] }]
2508
+ customFonts: [],
2509
+ // host-injected custom font catalog: [{ name, variants: [{weight,style,file}] }]
2510
+ _activity: new ActivityTracker(getActivityLogOptions) // plain-English log of what the user did
1728
2511
  };
1729
2512
  }).views(function (self) {
1730
2513
  return {
@@ -1885,6 +2668,8 @@ var Store = types.model('Store', {
1885
2668
  if (self.pages.length > 0 && !self._activePageId) {
1886
2669
  self._activePageId = self.pages[0].id;
1887
2670
  }
2671
+ // A store that never loads a template still needs a baseline for the activity log.
2672
+ self._resetActivity();
1888
2673
  },
1889
2674
  set: function set(attrs) {
1890
2675
  for (var _i2 = 0, _Object$entries2 = Object.entries(attrs); _i2 < _Object$entries2.length; _i2++) {
@@ -2545,6 +3330,7 @@ var Store = types.model('Store', {
2545
3330
  self.history.clear();
2546
3331
  self.history.addUndoState();
2547
3332
  }
3333
+ self._resetActivity();
2548
3334
 
2549
3335
  // Auto-load fonts referenced in text elements
2550
3336
  self._autoLoadFonts(data);
@@ -2569,6 +3355,67 @@ var Store = types.model('Store', {
2569
3355
  self.history.clear();
2570
3356
  self.history.addUndoState();
2571
3357
  }
3358
+ self._resetActivity();
3359
+ },
3360
+ // ── Activity log: plain-English record of what the user did ─────
3361
+ _activitySnapshot: function _activitySnapshot() {
3362
+ var snapshot = _objectSpread2({}, getSnapshot(self));
3363
+ delete snapshot.history;
3364
+ return snapshot;
3365
+ },
3366
+ _resetActivity: function _resetActivity() {
3367
+ try {
3368
+ self._activity.reset(self._activitySnapshot());
3369
+ } catch (e) {
3370
+ console.warn('Activity log: failed to reset', e);
3371
+ }
3372
+ },
3373
+ getActivityLog: function getActivityLog() {
3374
+ try {
3375
+ return self._activity.getLog(self._activitySnapshot());
3376
+ } catch (e) {
3377
+ console.warn('Activity log: failed to read', e);
3378
+ return [];
3379
+ }
3380
+ },
3381
+ recordActivity: function recordActivity(sentence) {
3382
+ try {
3383
+ self._activity.record(sentence);
3384
+ } catch (e) {
3385
+ console.warn('Activity log: failed to record', e);
3386
+ }
3387
+ },
3388
+ // For changes the canvas makes by itself (not the user): keeps them out of the log.
3389
+ syncActivityBaseline: function syncActivityBaseline(id, attrs) {
3390
+ try {
3391
+ self._activity.patchBaseline(id, attrs);
3392
+ } catch (e) {
3393
+ console.warn('Activity log: failed to sync baseline', e);
3394
+ }
3395
+ },
3396
+ clearActivityLog: function clearActivityLog() {
3397
+ // Keep the baseline at the current state so the next change is still logged.
3398
+ self._activity.clear();
3399
+ self._activity.rebaseline(self._activitySnapshot());
3400
+ },
3401
+ // Called by the input-fields popup. Logs the answer, then re-baselines so the
3402
+ // change it wrote into the element is not logged a second time.
3403
+ logPopupAnswer: function logPopupAnswer() {
3404
+ var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
3405
+ action = _ref11.action,
3406
+ field = _ref11.field,
3407
+ value = _ref11.value;
3408
+ try {
3409
+ // 'finish' can arrive twice (answer handler and a host dialog's onComplete): key it so it merges.
3410
+ self._activity.record(describePopup({
3411
+ action: action,
3412
+ field: field,
3413
+ value: value
3414
+ }, getActivityLogOptions()), action === 'finish' ? 'popup:finish' : undefined);
3415
+ self._activity.rebaseline(self._activitySnapshot());
3416
+ } catch (e) {
3417
+ console.warn('Activity log: failed to record popup answer', e);
3418
+ }
2572
3419
  },
2573
3420
  addFont: function addFont(font) {
2574
3421
  var existing = self.fonts.find(function (f) {
@@ -2793,11 +3640,11 @@ var Store = types.model('Store', {
2793
3640
  };
2794
3641
  });
2795
3642
  function createStore() {
2796
- var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2797
- _ref11$key = _ref11.key,
2798
- key = _ref11$key === void 0 ? '' : _ref11$key,
2799
- _ref11$showCredit = _ref11.showCredit,
2800
- showCredit = _ref11$showCredit === void 0 ? false : _ref11$showCredit;
3643
+ var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
3644
+ _ref12$key = _ref12.key,
3645
+ key = _ref12$key === void 0 ? '' : _ref12$key,
3646
+ _ref12$showCredit = _ref12.showCredit,
3647
+ showCredit = _ref12$showCredit === void 0 ? false : _ref12$showCredit;
2801
3648
  var store = Store.create({});
2802
3649
  store._initConfig(key, showCredit);
2803
3650
  return store;