@micromag/element-background 0.3.531 → 0.3.547

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.
Files changed (2) hide show
  1. package/package.json +5 -6
  2. package/lib/index.js +0 -284
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-background",
3
- "version": "0.3.531",
3
+ "version": "0.3.547",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -30,11 +30,10 @@
30
30
  }
31
31
  ],
32
32
  "license": "ISC",
33
- "main": "lib/index.js",
33
+ "type": "module",
34
34
  "module": "es/index.js",
35
35
  "exports": {
36
36
  ".": {
37
- "require": "./lib/index.js",
38
37
  "import": "./es/index.js"
39
38
  },
40
39
  "./assets/css/styles": "./assets/css/styles.css",
@@ -59,8 +58,8 @@
59
58
  "dependencies": {
60
59
  "@babel/runtime": "^7.13.10",
61
60
  "@folklore/size": "^0.1.20",
62
- "@micromag/core": "^0.3.531",
63
- "@micromag/element-video": "^0.3.531",
61
+ "@micromag/core": "^0.3.547",
62
+ "@micromag/element-video": "^0.3.547",
64
63
  "classnames": "^2.2.6",
65
64
  "lodash": "^4.17.21",
66
65
  "prop-types": "^15.7.2",
@@ -71,5 +70,5 @@
71
70
  "access": "public",
72
71
  "registry": "https://registry.npmjs.org/"
73
72
  },
74
- "gitHead": "e3a59c467ad33528b38eb4badd78b6ed0e38a3a6"
73
+ "gitHead": "3c2f5904ce61fcfa61f673c38c2a5ec56e9e2b07"
75
74
  }
package/lib/index.js DELETED
@@ -1,284 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
6
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
7
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
8
- var classNames = require('classnames');
9
- var PropTypes = require('prop-types');
10
- var React = require('react');
11
- var core = require('@micromag/core');
12
- var utils = require('@micromag/core/utils');
13
- var size = require('@folklore/size');
14
- var Video = require('@micromag/element-video');
15
-
16
- var styles = {"layers":"micromag-element-background-layers","layer":"micromag-element-background-layer","videoContainer":"micromag-element-background-videoContainer","video":"micromag-element-background-video","container":"micromag-element-background-container","right":"micromag-element-background-right","background":"micromag-element-background-background","bottom":"micromag-element-background-bottom"};
17
-
18
- var propTypes$1 = {
19
- width: PropTypes.number,
20
- height: PropTypes.number,
21
- resolution: PropTypes.number,
22
- fit: PropTypes.oneOf(['contain', 'cover']),
23
- horizontalAlign: PropTypes.string,
24
- verticalAlign: PropTypes.string,
25
- repeat: PropTypes.bool,
26
- color: core.PropTypes.color,
27
- media: PropTypes.oneOfType([core.PropTypes.imageMedia, core.PropTypes.videoMedia]),
28
- mediaRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
29
- // eslint-disable-next-line react/forbid-prop-types
30
- current: PropTypes.any
31
- })]),
32
- className: PropTypes.string,
33
- playing: PropTypes.bool,
34
- muted: PropTypes.bool,
35
- children: PropTypes.node,
36
- loadingMode: PropTypes.string,
37
- shouldLoad: PropTypes.bool,
38
- onPlayError: PropTypes.func,
39
- withoutVideo: PropTypes.bool,
40
- forceMuted: PropTypes.bool
41
- };
42
- var defaultProps$1 = {
43
- width: null,
44
- height: null,
45
- resolution: 1,
46
- fit: null,
47
- horizontalAlign: 'center',
48
- verticalAlign: 'center',
49
- repeat: false,
50
- color: null,
51
- media: null,
52
- mediaRef: null,
53
- className: null,
54
- playing: false,
55
- muted: false,
56
- children: null,
57
- loadingMode: 'lazy',
58
- shouldLoad: true,
59
- onPlayError: null,
60
- withoutVideo: false,
61
- forceMuted: false
62
- };
63
- var Background = function Background(_ref) {
64
- var width = _ref.width,
65
- height = _ref.height,
66
- resolution = _ref.resolution,
67
- fit = _ref.fit,
68
- horizontalAlign = _ref.horizontalAlign,
69
- verticalAlign = _ref.verticalAlign,
70
- repeat = _ref.repeat,
71
- color = _ref.color,
72
- media = _ref.media,
73
- mediaRef = _ref.mediaRef,
74
- className = _ref.className,
75
- playing = _ref.playing,
76
- muted = _ref.muted,
77
- children = _ref.children,
78
- loadingMode = _ref.loadingMode,
79
- shouldLoad = _ref.shouldLoad,
80
- onPlayError = _ref.onPlayError,
81
- withoutVideo = _ref.withoutVideo,
82
- forceMuted = _ref.forceMuted;
83
- var _ref2 = media || {},
84
- _ref2$type = _ref2.type,
85
- mediaType = _ref2$type === void 0 ? null : _ref2$type,
86
- _ref2$metadata = _ref2.metadata,
87
- mediaMetadata = _ref2$metadata === void 0 ? null : _ref2$metadata,
88
- mediaThumbnailUrl = _ref2.thumbnail_url;
89
- var _ref3 = mediaMetadata || {},
90
- _ref3$width = _ref3.width,
91
- mediaWidth = _ref3$width === void 0 ? 0 : _ref3$width,
92
- _ref3$height = _ref3.height,
93
- mediaHeight = _ref3$height === void 0 ? 0 : _ref3$height;
94
- var isVideo = mediaType === 'video';
95
- var isImage = mediaType === 'image';
96
-
97
- // Lazy load
98
- var newShouldLoad = shouldLoad || loadingMode !== 'lazy';
99
- var wasLoadedRef = React.useRef(newShouldLoad);
100
- if (newShouldLoad && !wasLoadedRef.current) {
101
- wasLoadedRef.current = newShouldLoad;
102
- }
103
- var finalShouldLoad = wasLoadedRef.current;
104
-
105
- // color
106
- var containerStyle = _objectSpread({
107
- width: width,
108
- height: height
109
- }, utils.getStyleFromColor(color));
110
-
111
- // image
112
- if (media !== null && (isImage || isVideo && (!shouldLoad || withoutVideo))) {
113
- var finalUrl = utils.getOptimalImageUrl(isVideo ? {
114
- url: mediaThumbnailUrl
115
- } : media, width, height, {
116
- resolution: resolution
117
- });
118
- containerStyle.backgroundImage = finalUrl !== null && finalShouldLoad ? "url(\"".concat(finalUrl, "\")") : null;
119
- containerStyle.backgroundRepeat = repeat && !isVideo ? 'repeat' : 'no-repeat';
120
- containerStyle.backgroundPosition = [horizontalAlign, verticalAlign].join(' ');
121
- if (fit !== null) {
122
- containerStyle.backgroundSize = fit;
123
- } else if (!repeat || isVideo) {
124
- containerStyle.backgroundSize = 'cover';
125
- }
126
- }
127
-
128
- // video
129
- var videoContainerStyle = {};
130
- if (isVideo && shouldLoad) {
131
- if (width > 0 && height > 0) {
132
- var _getSizeWithinBounds = size.getSizeWithinBounds(mediaWidth, mediaHeight, width, height, {
133
- cover: fit === 'cover' || fit === null
134
- }),
135
- _getSizeWithinBounds$ = _getSizeWithinBounds.width,
136
- videoWidth = _getSizeWithinBounds$ === void 0 ? 0 : _getSizeWithinBounds$,
137
- _getSizeWithinBounds$2 = _getSizeWithinBounds.height,
138
- videoHeight = _getSizeWithinBounds$2 === void 0 ? 0 : _getSizeWithinBounds$2;
139
- videoContainerStyle.width = videoWidth;
140
- videoContainerStyle.height = videoHeight;
141
- videoContainerStyle.left = -(videoWidth - width) / 2;
142
- videoContainerStyle.top = -(videoHeight - height) / 2;
143
- } else {
144
- videoContainerStyle.objectFit = 'cover';
145
- }
146
- }
147
- return /*#__PURE__*/React.createElement("div", {
148
- className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
149
- style: containerStyle
150
- }, isVideo && shouldLoad && !withoutVideo ? /*#__PURE__*/React.createElement("div", {
151
- className: styles.videoContainer,
152
- style: videoContainerStyle
153
- }, /*#__PURE__*/React.createElement(Video, {
154
- className: styles.video,
155
- media: media,
156
- mediaRef: !forceMuted ? mediaRef : null,
157
- paused: !playing,
158
- muted: muted || forceMuted,
159
- shouldLoad: shouldLoad,
160
- onPlayError: onPlayError,
161
- disablePictureInPicture: true,
162
- autoPlay: true,
163
- loop: true,
164
- withPoster: true,
165
- focusable: false
166
- })) : null, /*#__PURE__*/React.createElement("div", {
167
- className: styles.content
168
- }, children));
169
- };
170
- Background.propTypes = propTypes$1;
171
- Background.defaultProps = defaultProps$1;
172
- var Background$1 = Background;
173
-
174
- var _excluded = ["horizontalAlign", "verticalAlign"];
175
- var propTypes = {
176
- width: PropTypes.number,
177
- height: PropTypes.number,
178
- resolution: PropTypes.number,
179
- background: PropTypes.oneOfType([core.PropTypes.backgroundElement, PropTypes.arrayOf(core.PropTypes.backgroundElement)]),
180
- playing: PropTypes.bool,
181
- muted: PropTypes.bool,
182
- children: PropTypes.node,
183
- className: PropTypes.string,
184
- layerClassName: PropTypes.string,
185
- backgroundClassName: PropTypes.string,
186
- loadingMode: PropTypes.string,
187
- mediaRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
188
- // eslint-disable-next-line react/forbid-prop-types
189
- current: PropTypes.any
190
- })]),
191
- shouldLoad: PropTypes.bool,
192
- withoutVideo: PropTypes.bool,
193
- onPlayError: PropTypes.bool
194
- };
195
- var defaultProps = {
196
- width: null,
197
- height: null,
198
- resolution: 1,
199
- background: [],
200
- playing: false,
201
- muted: false,
202
- children: null,
203
- className: null,
204
- layerClassName: null,
205
- backgroundClassName: null,
206
- loadingMode: 'lazy',
207
- mediaRef: null,
208
- shouldLoad: true,
209
- withoutVideo: false,
210
- onPlayError: null
211
- };
212
- var BackgroundLayers = function BackgroundLayers(_ref) {
213
- var width = _ref.width,
214
- height = _ref.height,
215
- resolution = _ref.resolution,
216
- background = _ref.background,
217
- playing = _ref.playing,
218
- muted = _ref.muted,
219
- children = _ref.children,
220
- className = _ref.className,
221
- layerClassName = _ref.layerClassName,
222
- backgroundClassName = _ref.backgroundClassName,
223
- loadingMode = _ref.loadingMode,
224
- mediaRef = _ref.mediaRef,
225
- shouldLoad = _ref.shouldLoad,
226
- withoutVideo = _ref.withoutVideo,
227
- onPlayError = _ref.onPlayError;
228
- var hasSize = width > 0 && height > 0;
229
- var layers = React.useMemo(function () {
230
- return utils.getLayersFromBackground(background);
231
- }, [background]);
232
- var maxZIndex = layers.length;
233
- if (layers.length === 0) {
234
- return null;
235
- }
236
-
237
- // color
238
- var containerStyle = _objectSpread({}, hasSize ? {
239
- width: width,
240
- height: height
241
- } : null);
242
- return /*#__PURE__*/React.createElement("div", {
243
- className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
244
- style: containerStyle
245
- }, /*#__PURE__*/React.createElement("div", {
246
- className: styles.layers
247
- }, layers.map(function (_ref3, index) {
248
- var _ref3$horizontalAlign = _ref3.horizontalAlign,
249
- horizontalAlign = _ref3$horizontalAlign === void 0 ? undefined : _ref3$horizontalAlign,
250
- _ref3$verticalAlign = _ref3.verticalAlign,
251
- verticalAlign = _ref3$verticalAlign === void 0 ? undefined : _ref3$verticalAlign,
252
- layer = _objectWithoutProperties(_ref3, _excluded);
253
- return /*#__PURE__*/React.createElement("div", {
254
- key: "background-".concat(index),
255
- className: classNames([styles.layer, _defineProperty(_defineProperty(_defineProperty({}, styles.bottom, verticalAlign === 'bottom'), styles.right, horizontalAlign === 'right'), layerClassName, layerClassName !== null)]),
256
- style: {
257
- zIndex: maxZIndex - index
258
- }
259
- }, /*#__PURE__*/React.createElement(Background$1, Object.assign({
260
- width: width,
261
- height: height,
262
- resolution: resolution,
263
- className: classNames([styles.background, _defineProperty({}, backgroundClassName, backgroundClassName !== null)]),
264
- playing: playing,
265
- muted: muted,
266
- horizontalAlign: horizontalAlign,
267
- verticalAlign: verticalAlign,
268
- loadingMode: loadingMode,
269
- shouldLoad: shouldLoad,
270
- mediaRef: mediaRef,
271
- withoutVideo: withoutVideo,
272
- onPlayError: onPlayError
273
- }, layer)));
274
- })), /*#__PURE__*/React.createElement("div", {
275
- className: styles.content
276
- }, children));
277
- };
278
- BackgroundLayers.propTypes = propTypes;
279
- BackgroundLayers.defaultProps = defaultProps;
280
- var BackgroundLayers$1 = BackgroundLayers;
281
-
282
- exports.Background = Background$1;
283
- exports.BackgroundLayers = BackgroundLayers$1;
284
- exports.default = BackgroundLayers$1;