@folklore/ads 0.0.80 → 0.0.81

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 (3) hide show
  1. package/dist/cjs.js +67 -83
  2. package/dist/es.js +2 -2
  3. package/package.json +6 -6
package/dist/cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var PropTypes = require('prop-types');
6
4
  var classNames = require('classnames');
7
5
  var isFunction = require('lodash/isFunction');
@@ -18,31 +16,17 @@ var utils = require('@folklore/utils');
18
16
  var hooks = require('@folklore/hooks');
19
17
  var tracking = require('@folklore/tracking');
20
18
 
21
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
-
23
- var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
24
- var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
25
- var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
26
- var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
27
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
- var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
29
- var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
30
- var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
31
- var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
32
- var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
33
- var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
34
-
35
- const adPath = PropTypes__default["default"].string;
36
- const adSize = PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), PropTypes__default["default"].arrayOf(PropTypes__default["default"].string), PropTypes__default["default"].string, PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), PropTypes__default["default"].arrayOf(PropTypes__default["default"].string), PropTypes__default["default"].string]))]);
37
- const adSizeMapping = PropTypes__default["default"].arrayOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), adSize])));
38
- const adViewports = PropTypes__default["default"].objectOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number));
39
- const adSlot = PropTypes__default["default"].shape({
19
+ const adPath = PropTypes.string;
20
+ const adSize = PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.arrayOf(PropTypes.string), PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.arrayOf(PropTypes.string), PropTypes.string]))]);
21
+ const adSizeMapping = PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), adSize])));
22
+ const adViewports = PropTypes.objectOf(PropTypes.arrayOf(PropTypes.number));
23
+ const adSlot = PropTypes.shape({
40
24
  size: adSize,
41
- sizeMapping: PropTypes__default["default"].objectOf(adSize)
25
+ sizeMapping: PropTypes.objectOf(adSize)
42
26
  });
43
- const adSlots = PropTypes__default["default"].objectOf(adSlot);
44
- const adTargeting = PropTypes__default["default"].shape({
45
- domain: PropTypes__default["default"].string
27
+ const adSlots = PropTypes.objectOf(adSlot);
28
+ const adTargeting = PropTypes.shape({
29
+ domain: PropTypes.string
46
30
  });
47
31
 
48
32
  var propTypes$4 = /*#__PURE__*/Object.freeze({
@@ -50,15 +34,15 @@ var propTypes$4 = /*#__PURE__*/Object.freeze({
50
34
  adPath: adPath,
51
35
  adSize: adSize,
52
36
  adSizeMapping: adSizeMapping,
53
- adViewports: adViewports,
54
37
  adSlot: adSlot,
55
38
  adSlots: adSlots,
56
- adTargeting: adTargeting
39
+ adTargeting: adTargeting,
40
+ adViewports: adViewports
57
41
  });
58
42
 
59
43
  const getAdSizes = sizes => {
60
- if (isArray__default["default"](sizes)) {
61
- return uniqBy__default["default"](isArray__default["default"](sizes[0]) || sizes[0] === 'fluid' ? sizes.filter(size => size !== 'fluid').reduce((allSizes, size) => [...allSizes, ...getAdSizes(size)], []) : [sizes].filter(size => size !== 'fluid'), size => size.join('x'));
44
+ if (isArray(sizes)) {
45
+ return uniqBy(isArray(sizes[0]) || sizes[0] === 'fluid' ? sizes.filter(size => size !== 'fluid').reduce((allSizes, size) => [...allSizes, ...getAdSizes(size)], []) : [sizes].filter(size => size !== 'fluid'), size => size.join('x'));
62
46
  }
63
47
  return sizes.split('x').map(it => parseInt(it, 10));
64
48
  };
@@ -70,11 +54,11 @@ const getMinimumAdSize = sizes => getAdSizes(sizes).reduce((minimumSize, size) =
70
54
  height: Infinity
71
55
  });
72
56
  const sizeFitsInViewport = (size, viewport) => size === 'fluid' && viewport[0] > 600 || size !== 'fluid' && (viewport[0] === 0 || size[0] <= viewport[0]) && (viewport[1] === 0 || size[1] <= viewport[1]);
73
- const getSortedViewports = viewports => sortBy__default["default"](Object.keys(viewports).map(name => ({
57
+ const getSortedViewports = viewports => sortBy(Object.keys(viewports).map(name => ({
74
58
  name,
75
59
  size: viewports[name]
76
60
  })), [viewport => viewport.size[0]]).reverse();
77
- const buildSizeMappingFromViewports = (sizeMapping, viewports) => isObject__default["default"](sizeMapping) && !isArray__default["default"](sizeMapping) ? getSortedViewports(viewports).reduce((newSizeMapping, _ref) => {
61
+ const buildSizeMappingFromViewports = (sizeMapping, viewports) => isObject(sizeMapping) && !isArray(sizeMapping) ? getSortedViewports(viewports).reduce((newSizeMapping, _ref) => {
78
62
  let {
79
63
  name,
80
64
  size: viewPortSize
@@ -99,7 +83,7 @@ const getSizeMappingFromSlot = (_ref3, viewports) => {
99
83
  return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
100
84
  };
101
85
 
102
- class AdSlot extends EventEmitter__default["default"] {
86
+ class AdSlot extends EventEmitter {
103
87
  constructor(id, path, size) {
104
88
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
105
89
  super();
@@ -276,8 +260,8 @@ class AdSlot extends EventEmitter__default["default"] {
276
260
  }
277
261
 
278
262
  /* globals refreshDisabledLineItems: [] */
279
- const debug$1 = createDebug__default["default"]('folklore:ads');
280
- class AdsManager extends EventEmitter__default["default"] {
263
+ const debug$1 = createDebug('folklore:ads');
264
+ class AdsManager extends EventEmitter {
281
265
  // static index = 0;
282
266
 
283
267
  // static createAdId() {
@@ -444,7 +428,7 @@ class AdsManager extends EventEmitter__default["default"] {
444
428
  renderSlot.setRenderEvent(event);
445
429
  }
446
430
  const lineItems = typeof window !== 'undefined' ? window.refreshDisabledLineItems || [] : [];
447
- if (isArray__default["default"](lineItems) && lineItems.indexOf(lineItemId) > -1) {
431
+ if (isArray(lineItems) && lineItems.indexOf(lineItemId) > -1) {
448
432
  renderSlot.setRefreshDisabled();
449
433
  }
450
434
  if (event.isEmpty) {
@@ -566,7 +550,7 @@ class AdsManager extends EventEmitter__default["default"] {
566
550
  const {
567
551
  googletag
568
552
  } = this;
569
- const slot = isObject__default["default"](id) ? id : this.slots.find(it => it.getElementId() === id) || null;
553
+ const slot = isObject(id) ? id : this.slots.find(it => it.getElementId() === id) || null;
570
554
  if (slot === null || slot.isDestroyed()) {
571
555
  return;
572
556
  }
@@ -585,7 +569,7 @@ class AdsManager extends EventEmitter__default["default"] {
585
569
  const {
586
570
  googletag
587
571
  } = this;
588
- const slot = isObject__default["default"](id) ? id : this.slots.find(it => it.getElementId() === id) || null;
572
+ const slot = isObject(id) ? id : this.slots.find(it => it.getElementId() === id) || null;
589
573
  if (slot === null || slot.isDestroyed() || slot.isRefreshDisabled()) {
590
574
  return;
591
575
  }
@@ -603,7 +587,7 @@ class AdsManager extends EventEmitter__default["default"] {
603
587
  const {
604
588
  googletag
605
589
  } = this;
606
- const slots = ids.map(id => isObject__default["default"](id) ? id : this.slots.find(it => !it.isDestroyed() && it.getElementId() === id) || null).filter(it => it !== null).map(it => it.getAdSlot());
590
+ const slots = ids.map(id => isObject(id) ? id : this.slots.find(it => !it.isDestroyed() && it.getElementId() === id) || null).filter(it => it !== null).map(it => it.getAdSlot());
607
591
  if (slots.length === 0) {
608
592
  return;
609
593
  }
@@ -670,28 +654,28 @@ const slots = {
670
654
  };
671
655
 
672
656
  /* eslint-disable react/jsx-props-no-spreading */
673
- const AdsContext = /*#__PURE__*/React__default["default"].createContext({
657
+ const AdsContext = /*#__PURE__*/React.createContext({
674
658
  ready: false
675
659
  });
676
660
  const useAdsContext = () => React.useContext(AdsContext);
677
661
  const propTypes$3 = {
678
- children: PropTypes__default["default"].node.isRequired,
679
- defaultSlotPath: PropTypes__default["default"].string,
680
- slotsPath: PropTypes__default["default"].objectOf(PropTypes__default["default"].string),
681
- disableSingleRequest: PropTypes__default["default"].bool,
682
- disableVideoAds: PropTypes__default["default"].bool,
683
- disableLazyLoad: PropTypes__default["default"].bool,
684
- autoInit: PropTypes__default["default"].bool,
685
- resizeDebounceDelay: PropTypes__default["default"].number,
686
- refreshOnResize: PropTypes__default["default"].bool,
687
- mobileScaling: PropTypes__default["default"].number,
688
- renderMarginPercent: PropTypes__default["default"].number,
689
- fetchMarginPercent: PropTypes__default["default"].number,
662
+ children: PropTypes.node.isRequired,
663
+ defaultSlotPath: PropTypes.string,
664
+ slotsPath: PropTypes.objectOf(PropTypes.string),
665
+ disableSingleRequest: PropTypes.bool,
666
+ disableVideoAds: PropTypes.bool,
667
+ disableLazyLoad: PropTypes.bool,
668
+ autoInit: PropTypes.bool,
669
+ resizeDebounceDelay: PropTypes.number,
670
+ refreshOnResize: PropTypes.bool,
671
+ mobileScaling: PropTypes.number,
672
+ renderMarginPercent: PropTypes.number,
673
+ fetchMarginPercent: PropTypes.number,
690
674
  slots: adSlots,
691
675
  viewports: adViewports,
692
- richAdComponents: PropTypes__default["default"].objectOf(PropTypes__default["default"].elementType),
693
- disabled: PropTypes__default["default"].bool,
694
- disableTracking: PropTypes__default["default"].bool
676
+ richAdComponents: PropTypes.objectOf(PropTypes.elementType),
677
+ disabled: PropTypes.bool,
678
+ disableTracking: PropTypes.bool
695
679
  };
696
680
  const defaultProps$3 = {
697
681
  defaultSlotPath: null,
@@ -770,7 +754,7 @@ function AdsProvider(_ref) {
770
754
  }
771
755
  }, [ads, autoInit]);
772
756
  React.useEffect(() => {
773
- const onResize = debounce__default["default"](() => ads.refreshAllSlots(), resizeDebounceDelay);
757
+ const onResize = debounce(() => ads.refreshAllSlots(), resizeDebounceDelay);
774
758
  if (refreshOnResize) {
775
759
  window.addEventListener('resize', onResize);
776
760
  }
@@ -811,13 +795,13 @@ function AdsProvider(_ref) {
811
795
  AdsProvider.propTypes = propTypes$3;
812
796
  AdsProvider.defaultProps = defaultProps$3;
813
797
 
814
- const AdsTargetingContext = /*#__PURE__*/React__default["default"].createContext(null);
798
+ const AdsTargetingContext = /*#__PURE__*/React.createContext(null);
815
799
  const useAdsTargeting = () => React.useContext(AdsTargetingContext);
816
800
  const propTypes$2 = {
817
- children: PropTypes__default["default"].node.isRequired,
801
+ children: PropTypes.node.isRequired,
818
802
  // eslint-disable-next-line react/forbid-prop-types
819
- targeting: PropTypes__default["default"].object,
820
- replace: PropTypes__default["default"].bool
803
+ targeting: PropTypes.object,
804
+ replace: PropTypes.bool
821
805
  };
822
806
  const defaultProps$2 = {
823
807
  targeting: {
@@ -846,8 +830,8 @@ AdsTargetingProvider.defaultProps = defaultProps$2;
846
830
 
847
831
  /* eslint-disable react/jsx-props-no-spreading */
848
832
  const propTypes$1 = {
849
- richAd: PropTypes__default["default"].shape({
850
- type: PropTypes__default["default"].string.isRequired
833
+ richAd: PropTypes.shape({
834
+ type: PropTypes.string.isRequired
851
835
  }).isRequired
852
836
  };
853
837
  const defaultProps$1 = {};
@@ -1065,7 +1049,7 @@ function useAd(path, size) {
1065
1049
  };
1066
1050
  }
1067
1051
 
1068
- const debug = createDebug__default["default"]('folklore:ads');
1052
+ const debug = createDebug('folklore:ads');
1069
1053
  function parseRichAd(data) {
1070
1054
  let richAd = null;
1071
1055
  try {
@@ -1112,27 +1096,27 @@ function useRichAd(containerRef, id, opts) {
1112
1096
  }
1113
1097
 
1114
1098
  const propTypes = {
1115
- slot: PropTypes__default["default"].string.isRequired,
1099
+ slot: PropTypes.string.isRequired,
1116
1100
  path: adPath,
1117
1101
  size: adSize,
1118
1102
  sizeMapping: adSizeMapping,
1119
1103
  targeting: adTargeting,
1120
- refreshInterval: PropTypes__default["default"].number,
1121
- alwaysRender: PropTypes__default["default"].bool,
1122
- disabled: PropTypes__default["default"].bool,
1123
- disableTracking: PropTypes__default["default"].bool,
1124
- shouldKeepSize: PropTypes__default["default"].bool,
1125
- withoutStyle: PropTypes__default["default"].bool,
1126
- withoutMinimumSize: PropTypes__default["default"].bool,
1127
- className: PropTypes__default["default"].string,
1128
- emptyClassName: PropTypes__default["default"].string,
1129
- adClassName: PropTypes__default["default"].string,
1130
- richAdClassName: PropTypes__default["default"].string,
1131
- richAdIframeClassName: PropTypes__default["default"].string,
1132
- onRender: PropTypes__default["default"].func,
1133
- onDestroy: PropTypes__default["default"].func,
1134
- onRichAd: PropTypes__default["default"].func,
1135
- slotRef: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object])
1104
+ refreshInterval: PropTypes.number,
1105
+ alwaysRender: PropTypes.bool,
1106
+ disabled: PropTypes.bool,
1107
+ disableTracking: PropTypes.bool,
1108
+ shouldKeepSize: PropTypes.bool,
1109
+ withoutStyle: PropTypes.bool,
1110
+ withoutMinimumSize: PropTypes.bool,
1111
+ className: PropTypes.string,
1112
+ emptyClassName: PropTypes.string,
1113
+ adClassName: PropTypes.string,
1114
+ richAdClassName: PropTypes.string,
1115
+ richAdIframeClassName: PropTypes.string,
1116
+ onRender: PropTypes.func,
1117
+ onDestroy: PropTypes.func,
1118
+ onRichAd: PropTypes.func,
1119
+ slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
1136
1120
  };
1137
1121
  const defaultProps = {
1138
1122
  path: null,
@@ -1279,9 +1263,9 @@ function Ad(_ref) {
1279
1263
  const richAd = useRichAd(adContainerRef, id, {
1280
1264
  onRichAd
1281
1265
  });
1282
- if (slotRef !== null && isFunction__default["default"](slotRef)) {
1266
+ if (slotRef !== null && isFunction(slotRef)) {
1283
1267
  slotRef(slotObject);
1284
- } else if (slotRef !== null && isObject__default["default"](slotRef)) {
1268
+ } else if (slotRef !== null && isObject(slotRef)) {
1285
1269
  // eslint-disable-next-line no-param-reassign
1286
1270
  slotRef.current = slotObject;
1287
1271
  }
@@ -1322,7 +1306,7 @@ function Ad(_ref) {
1322
1306
  }
1323
1307
  return /*#__PURE__*/jsxRuntime.jsx("div", {
1324
1308
  id: id !== null ? `${id}-container` : null,
1325
- className: classNames__default["default"]([className, {
1309
+ className: classNames([className, {
1326
1310
  [emptyClassName]: emptyClassName !== null && isEmpty
1327
1311
  }]),
1328
1312
  style: !withoutStyle ? containerStyle : null,
@@ -1336,7 +1320,7 @@ function Ad(_ref) {
1336
1320
  ref: adContainerRef,
1337
1321
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1338
1322
  id: id,
1339
- className: classNames__default["default"]([{
1323
+ className: classNames([{
1340
1324
  [richAdIframeClassName]: richAdIframeClassName !== null && isRendered && richAd !== null
1341
1325
  }])
1342
1326
  }), isRendered && richAd !== null ? /*#__PURE__*/jsxRuntime.jsx(RichAd, {
package/dist/es.js CHANGED
@@ -32,10 +32,10 @@ var propTypes$4 = /*#__PURE__*/Object.freeze({
32
32
  adPath: adPath,
33
33
  adSize: adSize,
34
34
  adSizeMapping: adSizeMapping,
35
- adViewports: adViewports,
36
35
  adSlot: adSlot,
37
36
  adSlots: adSlots,
38
- adTargeting: adTargeting
37
+ adTargeting: adTargeting,
38
+ adViewports: adViewports
39
39
  });
40
40
 
41
41
  const getAdSizes = sizes => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "Ads library",
5
5
  "keywords": [
6
6
  "javascript",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "scripts": {
36
36
  "clean": "rm -rf dist",
37
- "build": "rollup --config ../../rollup.config.js",
37
+ "build": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
38
38
  "prepare": "npm run clean && npm run build"
39
39
  },
40
40
  "devDependencies": {
@@ -50,11 +50,11 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "336b221bfe2d1bc6a39c79e0d9cedc3621a7c9d6",
53
+ "gitHead": "c13ef70b8126b3182b3e3365f34f9231fa9b1535",
54
54
  "dependencies": {
55
- "@folklore/hooks": "^0.0.65",
56
- "@folklore/tracking": "^0.0.25",
57
- "@folklore/utils": "^0.1.1",
55
+ "@folklore/hooks": "^0.0.66",
56
+ "@folklore/tracking": "^0.0.26",
57
+ "@folklore/utils": "^0.1.2",
58
58
  "classnames": "^2.5.1",
59
59
  "debug": "^4.3.4",
60
60
  "lodash": "^4.17.21",