@open-tender/store 0.5.0 → 0.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.
@@ -0,0 +1,190 @@
1
+ import { __assign } from "tslib";
2
+ export var remsToPixels = function (rems, ratio) {
3
+ var pixels = parseFloat(rems.replace('rem', '')) * 10;
4
+ var adjustedPixels = pixels * ratio;
5
+ var noZeroes = parseFloat(adjustedPixels.toFixed(2)).toString();
6
+ return noZeroes === '0' ? '0' : "".concat(noZeroes, "px");
7
+ };
8
+ export var remsToNumber = function (rems) {
9
+ return parseInt((parseFloat(rems.replace('rem', '')) * 10).toString(), 10);
10
+ };
11
+ var makeLineHeight = function (lineHeight, fontSize, ratio) {
12
+ var size = parseInt(fontSize.replace('px', ''));
13
+ return "".concat((ratio * parseFloat(lineHeight.toString()) * size).toFixed(3), "px");
14
+ };
15
+ var makeLineHeights = function (sizes, lineHeight, ratio) {
16
+ return Object.entries(sizes).reduce(function (obj, _a) {
17
+ var _b;
18
+ var size = _a[0], fontSize = _a[1];
19
+ return __assign(__assign({}, obj), (_b = {}, _b[size] = makeLineHeight(lineHeight, fontSize, ratio), _b));
20
+ }, {});
21
+ };
22
+ var fontSizesToPixels = function (object, ratio) {
23
+ return Object.entries(object).reduce(function (obj, _a) {
24
+ var _b;
25
+ var key = _a[0], value = _a[1];
26
+ return __assign(__assign({}, obj), (_b = {}, _b[key] = remsToPixels(value, ratio), _b));
27
+ }, {});
28
+ };
29
+ var layoutToPixels = function (object, ratio) {
30
+ return Object.entries(object).reduce(function (obj, _a) {
31
+ var _b;
32
+ var key = _a[0], value = _a[1];
33
+ return __assign(__assign({}, obj), (_b = {}, _b[key] = remsToPixels(value, ratio), _b));
34
+ }, {});
35
+ };
36
+ var paddingToPixels = function (padding, ratio) {
37
+ var _a = padding.split(' '), top = _a[0], horizontal = _a[1], bottom = _a[2];
38
+ var topPx = remsToPixels(top, ratio);
39
+ var horizontalPx = remsToPixels(horizontal, ratio);
40
+ var bottomPx = remsToPixels(bottom, ratio);
41
+ return "".concat(topPx, " ").concat(horizontalPx, " ").concat(bottomPx);
42
+ };
43
+ var buttonToPixels = function (button, ratio) {
44
+ return __assign(__assign({}, button), { borderRadius: remsToPixels(button.borderRadius, ratio), borderWidth: remsToPixels(button.borderWidth, ratio), borderWidthApp: button.borderWidthApp
45
+ ? remsToPixels(button.borderWidthApp, ratio)
46
+ : remsToPixels(button.borderWidth, ratio), fontSize: button.fontSize ? remsToPixels(button.fontSize, ratio) : null, letterSpacing: button.letterSpacing
47
+ ? remsToPixels(button.letterSpacing, ratio)
48
+ : null, padding: button.padding ? paddingToPixels(button.padding, ratio) : null });
49
+ };
50
+ var buttonLargeToPixels = function (button, ratio) {
51
+ var largeButton = buttonToPixels(button, ratio);
52
+ return __assign(__assign({}, largeButton), { subtitleFontSizeMobile: button.subtitleFontSizeMobile
53
+ ? remsToPixels(button.subtitleFontSizeMobile, ratio)
54
+ : null, subtitleMarginTopMobile: button.subtitleMarginTopMobile
55
+ ? remsToPixels(button.subtitleMarginTopMobile, ratio)
56
+ : null, titleFontSizeMobile: button.titleFontSizeMobile
57
+ ? remsToPixels(button.titleFontSizeMobile, ratio)
58
+ : null, titleMarginLeftMobile: button.titleMarginLeftMobile
59
+ ? remsToPixels(button.titleMarginLeftMobile, ratio)
60
+ : null });
61
+ };
62
+ var makeButtons = function (buttons, ratio) {
63
+ var sizes = Object.entries(buttons.sizes).reduce(function (obj, _a) {
64
+ var _b;
65
+ var key = _a[0], value = _a[1];
66
+ return __assign(__assign({}, obj), (_b = {}, _b[key] = key === 'large'
67
+ ? buttonLargeToPixels(value, ratio)
68
+ : buttonToPixels(value, ratio), _b));
69
+ }, {});
70
+ return __assign(__assign({}, buttons), { sizes: sizes });
71
+ };
72
+ var makeFont = function (font, sizes, ratio) {
73
+ var fontStyle = __assign(__assign({}, font), { letterSpacing: remsToPixels(font.letterSpacing, ratio), lineHeights: makeLineHeights(sizes, font.lineHeight, ratio) });
74
+ if (!font.fontSize) {
75
+ return fontStyle;
76
+ }
77
+ var fontSize = remsToPixels(font.fontSize, ratio);
78
+ var lineHeight = makeLineHeight(font.lineHeight, fontSize, ratio);
79
+ return __assign(__assign({}, fontStyle), { fontSize: fontSize, lineHeight: lineHeight });
80
+ };
81
+ var makeFonts = function (fonts, lineHeight, ratio) {
82
+ var sizes = fontSizesToPixels(fonts.sizes, ratio);
83
+ var lineHeights = makeLineHeights(sizes, lineHeight, ratio);
84
+ var headline = makeFont(fonts.headline, sizes, ratio);
85
+ var headings = makeFont(fonts.headings, sizes, ratio);
86
+ var body = makeFont(fonts.body, sizes, ratio);
87
+ var preface = makeFont(fonts.preface, sizes, ratio);
88
+ return __assign(__assign({}, fonts), { headline: headline, headings: headings, body: body, preface: preface, sizes: sizes, lineHeights: lineHeights });
89
+ };
90
+ var makeBorder = function (border, ratio) {
91
+ return __assign(__assign({}, border), { radius: remsToPixels(border.radius, ratio), radiusSmall: remsToPixels(border.radiusSmall, ratio), width: remsToPixels(border.width, ratio), widthApp: remsToPixels(border.widthApp, ratio) });
92
+ };
93
+ var makeLabel = function (label, ratio) {
94
+ var _a = label.padding.split(' '), vertical = _a[0], horizontal = _a[1];
95
+ return {
96
+ fontSize: remsToPixels(label.fontSize, ratio),
97
+ fontSizeMobile: remsToPixels(label.fontSizeMobile, ratio),
98
+ left: remsToPixels(label.left, ratio),
99
+ offset: remsToPixels(label.offset, ratio),
100
+ padding: "".concat(remsToPixels(vertical, ratio), " ").concat(remsToPixels(horizontal, ratio)),
101
+ top: remsToPixels(label.top, ratio)
102
+ };
103
+ };
104
+ var makeInputs = function (inputs, ratio) {
105
+ var _a = inputs.padding.split(' '), vertical = _a[0], horizontal = _a[1];
106
+ return __assign(__assign({}, inputs), { borderWidth: remsToPixels(inputs.borderWidth, ratio), borderWidthApp: remsToPixels(inputs.borderWidthApp, ratio), fontSize: remsToPixels(inputs.fontSize, ratio), fontSizeMobile: remsToPixels(inputs.fontSizeMobile, ratio), iconLeft: remsToPixels(inputs.iconLeft, ratio), iconPadding: remsToPixels(inputs.iconPadding, ratio), label: makeLabel(inputs.label, ratio), letterSpacing: remsToPixels(inputs.letterSpacing, ratio), lineHeight: makeLineHeight(inputs.lineHeight, inputs.fontSize, ratio), lineHeightMobile: makeLineHeight(inputs.lineHeight, inputs.fontSizeMobile, ratio), padding: "".concat(remsToPixels(vertical, ratio), " ").concat(remsToPixels(horizontal, ratio)), paddingBottom: remsToPixels(inputs.paddingBottom, ratio), paddingBottomActive: remsToPixels(inputs.paddingBottomActive, ratio), paddingHorizontal: remsToPixels(inputs.paddingHorizontal, ratio), paddingTop: remsToPixels(inputs.paddingTop, ratio), paddingTopActive: remsToPixels(inputs.paddingTopActive, ratio), paddingVertical: remsToPixels(inputs.paddingVertical, ratio), radius: remsToPixels(inputs.radius, ratio), selectPaddingBottom: remsToPixels(inputs.selectPaddingBottom, ratio), selectSize: remsToPixels(inputs.selectSize, ratio), selectSizeMobile: remsToPixels(inputs.selectSizeMobile, ratio) });
107
+ };
108
+ var makeCounts = function (counts, ratio) {
109
+ var alerts = counts.alerts, quantity = counts.quantity;
110
+ return {
111
+ alerts: __assign(__assign({}, alerts), { borderWidth: remsToPixels(alerts.borderWidth, ratio), borderWidthApp: remsToPixels(alerts.borderWidthApp, ratio), fontSize: remsToPixels(alerts.fontSize, ratio), fontSizeMobile: remsToPixels(alerts.fontSizeMobile, ratio), paddingBottom: remsToPixels(alerts.paddingBottom, ratio), paddingTop: remsToPixels(alerts.paddingTop, ratio) }),
112
+ quantity: __assign(__assign({}, quantity), { fontSize: remsToPixels(quantity.fontSize, ratio), fontSizeMobile: remsToPixels(quantity.fontSizeMobile, ratio), paddingBottom: remsToPixels(quantity.paddingBottom, ratio), paddingTop: remsToPixels(quantity.paddingTop, ratio) })
113
+ };
114
+ };
115
+ var makeCards = function (cards, ratio) {
116
+ var box = cards.default, form = cards.form, menuItem = cards.menuItem, modifier = cards.modifier;
117
+ return {
118
+ default: __assign(__assign({}, box), { borderRadius: remsToPixels(box.borderRadius, ratio), borderWidth: remsToPixels(box.borderWidth, ratio), borderWidthApp: remsToPixels(box.borderWidthApp, ratio) }),
119
+ form: __assign(__assign({}, form), { borderRadius: remsToPixels(form.borderRadius, ratio), borderWidth: remsToPixels(form.borderWidth, ratio), borderWidthApp: remsToPixels(form.borderWidthApp, ratio) }),
120
+ menuItem: __assign(__assign({}, menuItem), { borderRadius: remsToPixels(menuItem.borderRadius, ratio), borderWidth: remsToPixels(menuItem.borderWidth, ratio), borderWidthApp: remsToPixels(menuItem.borderWidthApp, ratio) }),
121
+ modifier: __assign(__assign({}, modifier), { borderRadius: remsToPixels(modifier.borderRadius, ratio), borderWidth: remsToPixels(modifier.borderWidth, ratio), borderWidthApp: remsToPixels(modifier.borderWidthApp, ratio) })
122
+ };
123
+ };
124
+ var makeItem = function (item, ratio) {
125
+ return __assign(__assign({}, item), { imageMaxHeight: remsToPixels(item.imageMaxHeight, ratio), imageMinHeight: remsToPixels(item.imageMinHeight, ratio), imagePadding: remsToPixels(item.imagePadding, ratio), maxWidth: remsToPixels(item.maxWidth, ratio), padding: remsToPixels(item.padding, ratio) });
126
+ };
127
+ var makeItems = function (item, ratio) {
128
+ var desktop = item.desktop, mobile = item.mobile;
129
+ return {
130
+ desktop: makeItem(desktop, ratio),
131
+ mobile: makeItem(mobile, ratio)
132
+ };
133
+ };
134
+ var makeWelcome = function (welcome, ratio) {
135
+ var titleSize = remsToPixels(welcome.titleSize, ratio);
136
+ var subtitleSize = remsToPixels(welcome.subtitleSize, ratio);
137
+ return {
138
+ textAlign: welcome.textAlign,
139
+ marginTop: remsToPixels(welcome.marginTop, ratio),
140
+ marginBottom: remsToPixels(welcome.marginBottom, ratio),
141
+ titleMarginLeft: remsToPixels(welcome.titleMarginLeft, ratio),
142
+ titleSize: titleSize,
143
+ titleLineHeight: makeLineHeight(welcome.titleLineHeight, titleSize, ratio),
144
+ subtitleSize: subtitleSize,
145
+ subtitleLineHeight: makeLineHeight(welcome.subtitleLineHeight, subtitleSize, ratio),
146
+ subtitleMarginTop: remsToPixels(welcome.subtitleMarginTop, ratio)
147
+ };
148
+ };
149
+ var makeWelcomes = function (welcomes, ratio) {
150
+ var desktop = welcomes.desktop, mobile = welcomes.mobile;
151
+ return {
152
+ desktop: makeWelcome(desktop, ratio),
153
+ mobile: makeWelcome(mobile, ratio)
154
+ };
155
+ };
156
+ var DEFAULT_WIDTH = 390;
157
+ var DEFAULT_HEIGHT = 844;
158
+ var makeRatio = function (width, height) {
159
+ return (width * height) / (DEFAULT_WIDTH * DEFAULT_HEIGHT);
160
+ };
161
+ export var decorateTheme = function (theme, dimensions, responsive) {
162
+ if (responsive === void 0) { responsive = true; }
163
+ var width = dimensions.width, height = dimensions.height;
164
+ var ratio = responsive ? makeRatio(width, height) : 1.0;
165
+ var border = makeBorder(theme.border, ratio);
166
+ var buttons = makeButtons(theme.buttons, ratio);
167
+ var cards = makeCards(theme.cards, ratio);
168
+ var counts = makeCounts(theme.counts, ratio);
169
+ var fonts = makeFonts(theme.fonts, theme.lineHeight, ratio);
170
+ var inputs = makeInputs(theme.inputs, ratio);
171
+ var item = makeItems(theme.item, ratio);
172
+ var layout = layoutToPixels(theme.layout, ratio);
173
+ var lineHeight = makeLineHeight(theme.lineHeight, fonts.sizes.main, ratio);
174
+ var welcome = makeWelcomes(theme.welcome, ratio);
175
+ return __assign(__assign({}, theme), { border: border, buttons: buttons, cards: cards, counts: counts, fonts: fonts, inputs: inputs, item: item, lineHeight: lineHeight, layout: layout, welcome: welcome });
176
+ };
177
+ export function hexToRgbA(hex, opacity) {
178
+ var c;
179
+ if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
180
+ c = hex.substring(1).split('');
181
+ if (c.length === 3) {
182
+ c = [c[0], c[0], c[1], c[1], c[2], c[2]];
183
+ }
184
+ c = '0x' + c.join('');
185
+ return ('rgba(' +
186
+ [(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') +
187
+ ",".concat(opacity, ")"));
188
+ }
189
+ return null;
190
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/store",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",