@helpscout/artboard
Version:
A tool kit for React UI development and design
116 lines • 3.4 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var LOCAL_STORAGE_KEY = '__HSDS_ARTBOARD__';
exports.defaultProps = {
__debug: false,
alignHorizontally: 'center',
alignVertically: 'center',
darkMode: false,
defaultHeight: 280,
defaultWidth: 400,
padding: 0,
posX: 0,
posY: 0,
showGuides: false,
showBoxInspector: false,
showInterface: false,
snapshots: [],
withCenterGuides: false,
withResponsiveHeight: false,
withResponsiveWidth: false,
zoomLevel: 1,
};
function getNextArtboardSize(state, action) {
var _a = action.payload, nextWidth = _a.artboardWidth, nextHeight = _a.artboardHeight;
var artboardWidth = state.artboardWidth, artboardHeight = state.artboardHeight, zoomLevel = state.zoomLevel;
var computedNextWidth = (nextWidth - artboardWidth) / zoomLevel;
var computedNextHeight = (nextHeight - artboardHeight) / zoomLevel;
var updatedWidth = artboardWidth + computedNextWidth;
var updatedHeight = artboardHeight + computedNextHeight;
return {
artboardWidth: updatedWidth,
artboardHeight: updatedHeight,
};
}
exports.getNextArtboardSize = getNextArtboardSize;
function getArtboardNameFromProps(props) {
if (!props)
return '';
return props.id || props.name || '';
}
exports.getArtboardNameFromProps = getArtboardNameFromProps;
function loadState() {
try {
var serializedState = localStorage.getItem(LOCAL_STORAGE_KEY);
if (serializedState === null) {
// Save the initial state, if not defined
saveState({});
return {};
}
return JSON.parse(serializedState);
}
catch (err) {
return {};
}
}
exports.loadState = loadState;
function saveState(state) {
if (state === void 0) { state = {}; }
if (!state)
return undefined;
try {
var serializedState = JSON.stringify(state);
localStorage.setItem(LOCAL_STORAGE_KEY, serializedState);
return undefined;
}
catch (err) {
return undefined;
}
}
exports.saveState = saveState;
function loadSessionState(id) {
if (!id)
return {};
try {
var localState = loadState();
if (!localState || !localState[id]) {
// Save the initial state, if not defined
saveSessionState(id, {});
return {};
}
return localState[id];
}
catch (err) {
return {};
}
}
exports.loadSessionState = loadSessionState;
function saveSessionState(id, state) {
var _a;
if (!id)
return undefined;
try {
var localState = loadState();
if (!localState)
return undefined;
var nextState = __assign({}, localState, (_a = {}, _a[id] = state, _a));
saveState(nextState);
return undefined;
}
catch (err) {
return undefined;
}
}
exports.saveSessionState = saveSessionState;
//# sourceMappingURL=Artboard.utils.js.map