@dintero/discounts-web-sdk 0.2.5 → 0.2.7

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.
@@ -37,14 +37,14 @@ const addStyles = (elem, styles, theme) => {
37
37
  // "styled components" light
38
38
  styles.forEach(cssFn => {
39
39
  // get class name from hash
40
- const className = 'dintero-deals-' + hash(cssFn('dintero-deals', theme));
40
+ const className = "dintero-deals-" + hash(cssFn("dintero-deals", theme));
41
41
  addClass(elem, className);
42
42
  // add style tag to DOM if not exists
43
43
  const hit = document.querySelector(`[data-css-hash=${className}]`);
44
44
  if (!hit) {
45
- const style = document.createElement('style');
45
+ const style = document.createElement("style");
46
46
  style.innerHTML = cssFn(className, theme);
47
- style.setAttribute('data-css-hash', className);
47
+ style.setAttribute("data-css-hash", className);
48
48
  document.head.appendChild(style);
49
49
  }
50
50
  });
@@ -63,7 +63,7 @@ const addEventListeners = (elem, handlers) => {
63
63
  const no = {
64
64
  rewards: {
65
65
  discount_item_quantity: {
66
- three_for_two: '3 for 2',
66
+ three_for_two: "3 for 2",
67
67
  generic: "Kjøp {{require}} betal for {{payFor}}"
68
68
  },
69
69
  discount_amount: "{{monetaryAmount}} rabatt"
@@ -89,8 +89,8 @@ const t = (translateString, values) => {
89
89
  const matches = translateString.match(findValuesRegex) || [];
90
90
  const _values = values || {};
91
91
  return matches.reduce((interpolated, match) => {
92
- const key = match.replace('{{', '').replace('}}', '');
93
- const value = _values[key] || '';
92
+ const key = match.replace("{{", "").replace("}}", "");
93
+ const value = _values[key] || "";
94
94
  return interpolated.replace(match, value);
95
95
  }, translateString);
96
96
  };
@@ -99,19 +99,19 @@ const monetaryString = (amount, configuration, options) => {
99
99
  const opt = options || {};
100
100
  const amountString = amount.toString();
101
101
  const dotIndex = amountString.length - configuration.currency.exponent;
102
- const beforeDot = amountString.slice(0, dotIndex) || '0';
102
+ const beforeDot = amountString.slice(0, dotIndex) || "0";
103
103
  const afterDot = amountString.slice(dotIndex);
104
- const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + '.' + afterDot;
105
- if (opt.variant === 'short' && afterDot === '00') {
106
- return beforeDot + ',-';
104
+ const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + "." + afterDot;
105
+ if (opt.variant === "short" && afterDot === "00") {
106
+ return beforeDot + ",-";
107
107
  }
108
108
  if (!opt.currency) {
109
109
  return exponentAmount;
110
110
  }
111
- if (configuration.currency.position === 'prefix') {
112
- return configuration.currency.value + ' ' + exponentAmount;
111
+ if (configuration.currency.position === "prefix") {
112
+ return configuration.currency.value + " " + exponentAmount;
113
113
  }
114
- return exponentAmount + ' ' + configuration.currency.value;
114
+ return exponentAmount + " " + configuration.currency.value;
115
115
  };
116
116
  const padZero = value => {
117
117
  if (value < 10) {
@@ -122,11 +122,11 @@ const padZero = value => {
122
122
  const dateString = (isoString, configuration) => {
123
123
  try {
124
124
  const date = new Date(isoString);
125
- if (configuration.language === 'no') {
125
+ if (configuration.language === "no") {
126
126
  const dd = padZero(date.getDate());
127
127
  const mm = padZero(date.getMonth() + 1);
128
128
  const yyyy = date.getFullYear();
129
- return [dd, mm, yyyy].join('.');
129
+ return [dd, mm, yyyy].join(".");
130
130
  }
131
131
  return new Intl.DateTimeFormat().format(date);
132
132
  } catch (e) {
@@ -152,7 +152,7 @@ const normalize = className => `
152
152
  }
153
153
  `;
154
154
 
155
- const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
155
+ const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === "webshop");
156
156
  const discountStyle = (className, theme) => `
157
157
  @keyframes appear {
158
158
  from {
@@ -568,7 +568,7 @@ const createLoading = configuration => {
568
568
 
569
569
  var pkg = {
570
570
  name: "@dintero/discounts-web-sdk",
571
- version: "0.2.5",
571
+ version: "0.2.7",
572
572
  description: "Dintero Discounts SDK for web frontends",
573
573
  main: "dist/dintero-discounts-web-sdk.cjs.js",
574
574
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -582,6 +582,7 @@ var pkg = {
582
582
  test: "vitest --dom",
583
583
  watch: "preconstruct watch",
584
584
  build: "preconstruct build",
585
+ lint: "prettier --cache --log-level warn -c --config .prettierrc.yml .",
585
586
  prepublishOnly: "yarn build",
586
587
  "semantic-release": "semantic-release"
587
588
  },
@@ -597,25 +598,25 @@ var pkg = {
597
598
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
598
599
  },
599
600
  devDependencies: {
600
- "@babel/core": "7.13.0",
601
- "@babel/preset-typescript": "7.13.0",
602
- "@preconstruct/cli": "2.8.1",
601
+ "@babel/core": "7.23.9",
602
+ "@babel/preset-typescript": "7.23.3",
603
+ "@preconstruct/cli": "2.8.3",
603
604
  "@semantic-release/git": "10.0.1",
604
- "happy-dom": "12.9.0",
605
- prettier: "3.0.3",
606
- "semantic-release": "22.0.5",
607
- typescript: "5.2.2",
608
- vitest: "0.34.6"
605
+ "happy-dom": "13.3.8",
606
+ prettier: "3.2.5",
607
+ "semantic-release": "23.0.2",
608
+ typescript: "5.3.3",
609
+ vitest: "1.3.1"
609
610
  }
610
611
  };
611
612
 
612
613
  const defaultConfig = {
613
- language: 'no',
614
+ language: "no",
614
615
  version: pkg?.version || "SNAPSHOT",
615
- linkTarget: '_self',
616
+ linkTarget: "_self",
616
617
  currency: {
617
- value: 'Kr',
618
- position: 'suffix',
618
+ value: "Kr",
619
+ position: "suffix",
619
620
  exponent: 2
620
621
  },
621
622
  theme: {
@@ -701,8 +702,8 @@ const renderDeals = (configuration, discounts) => {
701
702
  const elem = createDiscount(discount, configuration);
702
703
  const webShopLink = findWebshopLink(discount);
703
704
  if (webShopLink) {
704
- elem.setAttribute('target', configuration?.linkTarget || '_self');
705
- elem.setAttribute('href', webShopLink.href);
705
+ elem.setAttribute("target", configuration?.linkTarget || "_self");
706
+ elem.setAttribute("href", webShopLink.href);
706
707
  }
707
708
  wrapper.appendChild(elem);
708
709
  });
@@ -37,14 +37,14 @@ const addStyles = (elem, styles, theme) => {
37
37
  // "styled components" light
38
38
  styles.forEach(cssFn => {
39
39
  // get class name from hash
40
- const className = 'dintero-deals-' + hash(cssFn('dintero-deals', theme));
40
+ const className = "dintero-deals-" + hash(cssFn("dintero-deals", theme));
41
41
  addClass(elem, className);
42
42
  // add style tag to DOM if not exists
43
43
  const hit = document.querySelector(`[data-css-hash=${className}]`);
44
44
  if (!hit) {
45
- const style = document.createElement('style');
45
+ const style = document.createElement("style");
46
46
  style.innerHTML = cssFn(className, theme);
47
- style.setAttribute('data-css-hash', className);
47
+ style.setAttribute("data-css-hash", className);
48
48
  document.head.appendChild(style);
49
49
  }
50
50
  });
@@ -63,7 +63,7 @@ const addEventListeners = (elem, handlers) => {
63
63
  const no = {
64
64
  rewards: {
65
65
  discount_item_quantity: {
66
- three_for_two: '3 for 2',
66
+ three_for_two: "3 for 2",
67
67
  generic: "Kjøp {{require}} betal for {{payFor}}"
68
68
  },
69
69
  discount_amount: "{{monetaryAmount}} rabatt"
@@ -89,8 +89,8 @@ const t = (translateString, values) => {
89
89
  const matches = translateString.match(findValuesRegex) || [];
90
90
  const _values = values || {};
91
91
  return matches.reduce((interpolated, match) => {
92
- const key = match.replace('{{', '').replace('}}', '');
93
- const value = _values[key] || '';
92
+ const key = match.replace("{{", "").replace("}}", "");
93
+ const value = _values[key] || "";
94
94
  return interpolated.replace(match, value);
95
95
  }, translateString);
96
96
  };
@@ -99,19 +99,19 @@ const monetaryString = (amount, configuration, options) => {
99
99
  const opt = options || {};
100
100
  const amountString = amount.toString();
101
101
  const dotIndex = amountString.length - configuration.currency.exponent;
102
- const beforeDot = amountString.slice(0, dotIndex) || '0';
102
+ const beforeDot = amountString.slice(0, dotIndex) || "0";
103
103
  const afterDot = amountString.slice(dotIndex);
104
- const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + '.' + afterDot;
105
- if (opt.variant === 'short' && afterDot === '00') {
106
- return beforeDot + ',-';
104
+ const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + "." + afterDot;
105
+ if (opt.variant === "short" && afterDot === "00") {
106
+ return beforeDot + ",-";
107
107
  }
108
108
  if (!opt.currency) {
109
109
  return exponentAmount;
110
110
  }
111
- if (configuration.currency.position === 'prefix') {
112
- return configuration.currency.value + ' ' + exponentAmount;
111
+ if (configuration.currency.position === "prefix") {
112
+ return configuration.currency.value + " " + exponentAmount;
113
113
  }
114
- return exponentAmount + ' ' + configuration.currency.value;
114
+ return exponentAmount + " " + configuration.currency.value;
115
115
  };
116
116
  const padZero = value => {
117
117
  if (value < 10) {
@@ -122,11 +122,11 @@ const padZero = value => {
122
122
  const dateString = (isoString, configuration) => {
123
123
  try {
124
124
  const date = new Date(isoString);
125
- if (configuration.language === 'no') {
125
+ if (configuration.language === "no") {
126
126
  const dd = padZero(date.getDate());
127
127
  const mm = padZero(date.getMonth() + 1);
128
128
  const yyyy = date.getFullYear();
129
- return [dd, mm, yyyy].join('.');
129
+ return [dd, mm, yyyy].join(".");
130
130
  }
131
131
  return new Intl.DateTimeFormat().format(date);
132
132
  } catch (e) {
@@ -152,7 +152,7 @@ const normalize = className => `
152
152
  }
153
153
  `;
154
154
 
155
- const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
155
+ const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === "webshop");
156
156
  const discountStyle = (className, theme) => `
157
157
  @keyframes appear {
158
158
  from {
@@ -568,7 +568,7 @@ const createLoading = configuration => {
568
568
 
569
569
  var pkg = {
570
570
  name: "@dintero/discounts-web-sdk",
571
- version: "0.2.5",
571
+ version: "0.2.7",
572
572
  description: "Dintero Discounts SDK for web frontends",
573
573
  main: "dist/dintero-discounts-web-sdk.cjs.js",
574
574
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -582,6 +582,7 @@ var pkg = {
582
582
  test: "vitest --dom",
583
583
  watch: "preconstruct watch",
584
584
  build: "preconstruct build",
585
+ lint: "prettier --cache --log-level warn -c --config .prettierrc.yml .",
585
586
  prepublishOnly: "yarn build",
586
587
  "semantic-release": "semantic-release"
587
588
  },
@@ -597,25 +598,25 @@ var pkg = {
597
598
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
598
599
  },
599
600
  devDependencies: {
600
- "@babel/core": "7.13.0",
601
- "@babel/preset-typescript": "7.13.0",
602
- "@preconstruct/cli": "2.8.1",
601
+ "@babel/core": "7.23.9",
602
+ "@babel/preset-typescript": "7.23.3",
603
+ "@preconstruct/cli": "2.8.3",
603
604
  "@semantic-release/git": "10.0.1",
604
- "happy-dom": "12.9.0",
605
- prettier: "3.0.3",
606
- "semantic-release": "22.0.5",
607
- typescript: "5.2.2",
608
- vitest: "0.34.6"
605
+ "happy-dom": "13.3.8",
606
+ prettier: "3.2.5",
607
+ "semantic-release": "23.0.2",
608
+ typescript: "5.3.3",
609
+ vitest: "1.3.1"
609
610
  }
610
611
  };
611
612
 
612
613
  const defaultConfig = {
613
- language: 'no',
614
+ language: "no",
614
615
  version: pkg?.version || "SNAPSHOT",
615
- linkTarget: '_self',
616
+ linkTarget: "_self",
616
617
  currency: {
617
- value: 'Kr',
618
- position: 'suffix',
618
+ value: "Kr",
619
+ position: "suffix",
619
620
  exponent: 2
620
621
  },
621
622
  theme: {
@@ -701,8 +702,8 @@ const renderDeals = (configuration, discounts) => {
701
702
  const elem = createDiscount(discount, configuration);
702
703
  const webShopLink = findWebshopLink(discount);
703
704
  if (webShopLink) {
704
- elem.setAttribute('target', configuration?.linkTarget || '_self');
705
- elem.setAttribute('href', webShopLink.href);
705
+ elem.setAttribute("target", configuration?.linkTarget || "_self");
706
+ elem.setAttribute("href", webShopLink.href);
706
707
  }
707
708
  wrapper.appendChild(elem);
708
709
  });
@@ -33,14 +33,14 @@ const addStyles = (elem, styles, theme) => {
33
33
  // "styled components" light
34
34
  styles.forEach(cssFn => {
35
35
  // get class name from hash
36
- const className = 'dintero-deals-' + hash(cssFn('dintero-deals', theme));
36
+ const className = "dintero-deals-" + hash(cssFn("dintero-deals", theme));
37
37
  addClass(elem, className);
38
38
  // add style tag to DOM if not exists
39
39
  const hit = document.querySelector(`[data-css-hash=${className}]`);
40
40
  if (!hit) {
41
- const style = document.createElement('style');
41
+ const style = document.createElement("style");
42
42
  style.innerHTML = cssFn(className, theme);
43
- style.setAttribute('data-css-hash', className);
43
+ style.setAttribute("data-css-hash", className);
44
44
  document.head.appendChild(style);
45
45
  }
46
46
  });
@@ -59,7 +59,7 @@ const addEventListeners = (elem, handlers) => {
59
59
  const no = {
60
60
  rewards: {
61
61
  discount_item_quantity: {
62
- three_for_two: '3 for 2',
62
+ three_for_two: "3 for 2",
63
63
  generic: "Kjøp {{require}} betal for {{payFor}}"
64
64
  },
65
65
  discount_amount: "{{monetaryAmount}} rabatt"
@@ -85,8 +85,8 @@ const t = (translateString, values) => {
85
85
  const matches = translateString.match(findValuesRegex) || [];
86
86
  const _values = values || {};
87
87
  return matches.reduce((interpolated, match) => {
88
- const key = match.replace('{{', '').replace('}}', '');
89
- const value = _values[key] || '';
88
+ const key = match.replace("{{", "").replace("}}", "");
89
+ const value = _values[key] || "";
90
90
  return interpolated.replace(match, value);
91
91
  }, translateString);
92
92
  };
@@ -95,19 +95,19 @@ const monetaryString = (amount, configuration, options) => {
95
95
  const opt = options || {};
96
96
  const amountString = amount.toString();
97
97
  const dotIndex = amountString.length - configuration.currency.exponent;
98
- const beforeDot = amountString.slice(0, dotIndex) || '0';
98
+ const beforeDot = amountString.slice(0, dotIndex) || "0";
99
99
  const afterDot = amountString.slice(dotIndex);
100
- const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + '.' + afterDot;
101
- if (opt.variant === 'short' && afterDot === '00') {
102
- return beforeDot + ',-';
100
+ const exponentAmount = afterDot == "00" && !opt.decimal ? beforeDot : beforeDot + "." + afterDot;
101
+ if (opt.variant === "short" && afterDot === "00") {
102
+ return beforeDot + ",-";
103
103
  }
104
104
  if (!opt.currency) {
105
105
  return exponentAmount;
106
106
  }
107
- if (configuration.currency.position === 'prefix') {
108
- return configuration.currency.value + ' ' + exponentAmount;
107
+ if (configuration.currency.position === "prefix") {
108
+ return configuration.currency.value + " " + exponentAmount;
109
109
  }
110
- return exponentAmount + ' ' + configuration.currency.value;
110
+ return exponentAmount + " " + configuration.currency.value;
111
111
  };
112
112
  const padZero = value => {
113
113
  if (value < 10) {
@@ -118,11 +118,11 @@ const padZero = value => {
118
118
  const dateString = (isoString, configuration) => {
119
119
  try {
120
120
  const date = new Date(isoString);
121
- if (configuration.language === 'no') {
121
+ if (configuration.language === "no") {
122
122
  const dd = padZero(date.getDate());
123
123
  const mm = padZero(date.getMonth() + 1);
124
124
  const yyyy = date.getFullYear();
125
- return [dd, mm, yyyy].join('.');
125
+ return [dd, mm, yyyy].join(".");
126
126
  }
127
127
  return new Intl.DateTimeFormat().format(date);
128
128
  } catch (e) {
@@ -148,7 +148,7 @@ const normalize = className => `
148
148
  }
149
149
  `;
150
150
 
151
- const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
151
+ const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === "webshop");
152
152
  const discountStyle = (className, theme) => `
153
153
  @keyframes appear {
154
154
  from {
@@ -564,7 +564,7 @@ const createLoading = configuration => {
564
564
 
565
565
  var pkg = {
566
566
  name: "@dintero/discounts-web-sdk",
567
- version: "0.2.5",
567
+ version: "0.2.7",
568
568
  description: "Dintero Discounts SDK for web frontends",
569
569
  main: "dist/dintero-discounts-web-sdk.cjs.js",
570
570
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -578,6 +578,7 @@ var pkg = {
578
578
  test: "vitest --dom",
579
579
  watch: "preconstruct watch",
580
580
  build: "preconstruct build",
581
+ lint: "prettier --cache --log-level warn -c --config .prettierrc.yml .",
581
582
  prepublishOnly: "yarn build",
582
583
  "semantic-release": "semantic-release"
583
584
  },
@@ -593,25 +594,25 @@ var pkg = {
593
594
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
594
595
  },
595
596
  devDependencies: {
596
- "@babel/core": "7.13.0",
597
- "@babel/preset-typescript": "7.13.0",
598
- "@preconstruct/cli": "2.8.1",
597
+ "@babel/core": "7.23.9",
598
+ "@babel/preset-typescript": "7.23.3",
599
+ "@preconstruct/cli": "2.8.3",
599
600
  "@semantic-release/git": "10.0.1",
600
- "happy-dom": "12.9.0",
601
- prettier: "3.0.3",
602
- "semantic-release": "22.0.5",
603
- typescript: "5.2.2",
604
- vitest: "0.34.6"
601
+ "happy-dom": "13.3.8",
602
+ prettier: "3.2.5",
603
+ "semantic-release": "23.0.2",
604
+ typescript: "5.3.3",
605
+ vitest: "1.3.1"
605
606
  }
606
607
  };
607
608
 
608
609
  const defaultConfig = {
609
- language: 'no',
610
+ language: "no",
610
611
  version: pkg?.version || "SNAPSHOT",
611
- linkTarget: '_self',
612
+ linkTarget: "_self",
612
613
  currency: {
613
- value: 'Kr',
614
- position: 'suffix',
614
+ value: "Kr",
615
+ position: "suffix",
615
616
  exponent: 2
616
617
  },
617
618
  theme: {
@@ -697,8 +698,8 @@ const renderDeals = (configuration, discounts) => {
697
698
  const elem = createDiscount(discount, configuration);
698
699
  const webShopLink = findWebshopLink(discount);
699
700
  if (webShopLink) {
700
- elem.setAttribute('target', configuration?.linkTarget || '_self');
701
- elem.setAttribute('href', webShopLink.href);
701
+ elem.setAttribute("target", configuration?.linkTarget || "_self");
702
+ elem.setAttribute("href", webShopLink.href);
702
703
  }
703
704
  wrapper.appendChild(elem);
704
705
  });
@@ -1,2 +1,2 @@
1
- !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).discounts={})}(this,(function(n){"use strict";const e=n=>{const e=document.createElement(n.tag);return n.attributes&&r(e,n.attributes),n.handlers&&i(e,n.handlers),n.styles&&t(e,n.styles,n.theme),n.innerHTML&&(e.innerHTML=n.innerHTML),e},t=(n,e,t)=>{e.forEach((e=>{const r="dintero-deals-"+(n=>{let e=0;for(var t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e&=e;return e.toString(36)})(e("dintero-deals",t));((n,e)=>{n.className.split(" ").includes(e)||(n.className=n.className+" "+e)})(n,r);if(!document.querySelector(`[data-css-hash=${r}]`)){const n=document.createElement("style");n.innerHTML=e(r,t),n.setAttribute("data-css-hash",r),document.head.appendChild(n)}}))},r=(n,e)=>{Object.keys(e).forEach((t=>{n.setAttribute(t,e[t])}))},i=(n,e)=>{Object.keys(e).forEach((t=>{n.addEventListener(t,e[t])}))},a={no:{rewards:{discount_item_quantity:{three_for_two:"3 for 2",generic:"Kjøp {{require}} betal for {{payFor}}"},discount_amount:"{{monetaryAmount}} rabatt"},limitations:{discount_reward_usage:"Antall: <strong>{{discount_reward_usage}}</strong>",discount_repeat_usage:"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>"},requirements:{purchase_from:"Tilbudet starter <strong>{{purchase_from}}</strong>",purchase_to:"Tilbudet utgår <strong>{{purchase_to}}</strong>"},errors:{fetch:"⚠️ <br/>En feil oppstod under lasting av tilbud..."}}},o=/(\{\{)[^}]*(\}\})/g,s=(n,e)=>{const t=n.match(o)||[],r=e||{};return t.reduce(((n,e)=>{const t=e.replace("{{","").replace("}}",""),i=r[t]||"";return n.replace(e,i)}),n)},d=(n,e,t)=>{const r=t||{},i=n.toString(),a=i.length-e.currency.exponent,o=i.slice(0,a)||"0",s=i.slice(a),d="00"!=s||r.decimal?o+"."+s:o;return"short"===r.variant&&"00"===s?o+",-":r.currency?"prefix"===e.currency.position?e.currency.value+" "+d:d+" "+e.currency.value:d},c=n=>n<10?`0${n}`:n.toString(),u=(n,e)=>{try{const t=new Date(n);if("no"===e.language){const n=c(t.getDate()),e=c(t.getMonth()+1);return[n,e,t.getFullYear()].join(".")}return(new Intl.DateTimeFormat).format(t)}catch(e){return n.substr(0,10)}},p=n=>`\n.${n} {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n outline: none;\n border: none;\n box-shadow: none;\n line-height: auto;\n background: transparent;\n opacity: 1;\n border-radius: 0;\n display: block;\n position: relative;\n font-weight: normal;\n}\n`,l=n=>n.links&&n.links.find((n=>n.rel&&"webshop"===n.rel)),m=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${e.borderRadius};\n text-align: center;\n padding-top: 5px;\n padding-bottom: 105px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 1em;\n margin: 5px 20px;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n color: inherit;\n text-decoration: none;\n}\n\n@media screen and (max-width: 679px) {\n .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,h=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,g=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,f=(n,e)=>`\n.${n} {\n position: absolute;\n bottom: 60px;\n left: -20px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: 0 ${e.borderRadius} ${e.borderRadius} 0;\n padding: 5px 0;\n background: ${e?.secondary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n bottom: -10px;\n left: 0;\n border-color: transparent;\n border-style: solid;\n border-width: 0 20px 10px 0;\n border-right-color: ${e.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,b=(n,e)=>`\n.${n} {\n position: absolute;\n right: -20px;\n bottom: 15px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: ${e.borderRadius} 0 0 ${e.borderRadius};\n padding: 5px 0;\n background: ${e?.primary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n right: 0;\n bottom: -10px;\n border-color: transparent;\n border-style: solid;\n border-width: 10px 20px 0 0;\n border-top-color: ${e.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,y=n=>`\n.${n} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`,x=n=>`\n.${n} {\n margin-top: 0;\n}`,w=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,_=(n,t)=>{const r=((n,e)=>{const t=a[e.language];if("discount_item_new_price"===n.reward.type)return d(n.reward.value,e,{variant:"short"});if("discount_percent"===n.reward.type)return n.reward.value+"%";if("discount_item_quantity"===n.reward.type){if(3===n.requirement.item.quantity&&1===n.reward.value)return t.rewards.discount_item_quantity.three_for_two;{const e=n.requirement.item.quantity,r=n.requirement.item.quantity-n.reward.value;return s(t.rewards.discount_item_quantity.generic,{require:e,payFor:r})}}if("discount_amount"===n.reward.type){const r=d(n.reward.value,e,{decimal:!1});return s(t.rewards.discount_amount,{monetaryAmount:r})}return"discount_item_percent"===n.reward.type?n.reward.value+"%":""})(n,t);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[b]})},$=(n,t)=>{const r=e({tag:l(n)?"a":"div",styles:[p,m],theme:t.theme}),i=((n,t)=>{const r=(n=>n&&n.metadata&&n.metadata.label||void 0)(n);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[f]})})(n,t),o=_(n,t),d=(n=>{const t=e({tag:"div",styles:[p,h]}),r=n.links.find((n=>["medium_discount_image","thumbnail_discount_image".includes(n.rel)])),i=r&&e({tag:"img",attributes:{src:r.href,alt:n.name,loading:"lazy"},styles:[p,g]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[y]}),b=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[x]}),$=n.description&&e({tag:"p",innerHTML:n.description}),v=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,w]});return[n.limitation.discount_reward_usage&&-1!==n.limitation.discount_reward_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_reward_usage,{discount_reward_usage:n.limitation.discount_reward_usage})}),n.limitation.discount_repeat_usage&&-1!==n.limitation.discount_repeat_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_repeat_usage,{discount_repeat_usage:n.limitation.discount_repeat_usage})}),new Date(n.requirement.purchase_from||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_from,{purchase_from:u(n.requirement.purchase_from,t)})}),new Date(n.requirement.purchase_to||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_to,{purchase_to:u(n.requirement.purchase_to,t)})})].filter((n=>n)).forEach((n=>i.appendChild(n))),i})(n,t);return[i,o,d,c,b,$,v].filter((n=>n)).forEach((n=>r.appendChild(n))),r},v=(n,e)=>{const t=new Headers;return Object.entries({...n,"Dintero-System-Name":"deals-web-sdk","Dintero-System-Version":e.version}).forEach((([n,e])=>{t.append(n,e)})),t},k=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=v({Authorization:`Basic ${e}`,"content-type":"application/json"},n),r=JSON.stringify({grant_type:"client_credentials",audience:`${n.api.url}/v1/accounts/${n.api.account}`});return window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/auth/token`,{method:"POST",headers:t,body:r}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})(n).then((e=>{const t=v({Authorization:`${e.token_type} ${e.access_token}`},n);return n.api.discountId?window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules/${n.api.discountId}`,{headers:t}).then((n=>{if(200===n.status)return n.json().then((n=>[n]));throw new Error("Authentication failed")})):window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules?limit=${n.api.limit}`,{headers:t}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})),T=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: 3px;\n text-align: center;\n padding-top: 65px;\n padding-bottom: 70px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 14px;\n margin: 5px auto;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`,q=(n,e)=>`\n.${n} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${n}:after {\n content: " ";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #000;\n border-color: rgba(0,0,0,0.2) transparent rgba(0,0,0,0.2) transparent;\n animation: loading 0.6s linear infinite;\n}\n\n@keyframes loading {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n`;const M={language:"no",version:"0.2.5",linkTarget:"_self",currency:{value:"Kr",position:"suffix",exponent:2},theme:{background:"#fff",primary:"#333",secondary:"#333",color:"inherit",borderRadius:"2px",fontSize:"inherit"},api:{account:"",key:"",secret:"",url:"https://api.dintero.com",limit:50}},z=(n,e)=>`\n.${n} {\n display: flex;\n flex-flow: wrap;\n align-items: stretch;\n justify-content: center;\n position: relative;\n font-weight: normal;\n width: 100%;\n font-size: ${e.fontSize};\n color: ${e.color};\n}`,E=(n,t)=>{const r=e({tag:"div",styles:[p,z],theme:n.theme});return t.forEach((e=>{const t=$(e,n),i=l(e);i&&(t.setAttribute("target",n?.linkTarget||"_self"),t.setAttribute("href",i.href)),r.appendChild(t)})),n.container.appendChild(r),{destroy:()=>{n.container.removeChild(r)}}};n.embed=async n=>{const t=(r=M,i=n,{...r,...i,currency:{...r.currency,...i.currency},theme:{...r.theme,...i.theme},api:{...r.api,...i.api}});var r,i;if(!t.container||!t.container.appendChild)throw console.error("Invalid configuration"),new Error("Invalid configuration");if(t.discounts)return E(t,t.discounts);{const r=(n=>e({tag:"div",styles:[p,q],theme:n.theme}))(t);try{n.container.appendChild(r);const e=await k(t);return t.container.removeChild(r),E(t,e)}catch(i){n.container.removeChild(r);const o=(n=>{const t=a[n.language];return e({tag:"div",styles:[p,T],theme:n.theme,innerHTML:t.errors.fetch})})(t);return t.container.appendChild(o),{destroy:()=>{n.container.removeChild(o)}}}}},Object.defineProperty(n,"__esModule",{value:!0})}));
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).discounts={})}(this,(function(n){"use strict";const e=n=>{const e=document.createElement(n.tag);return n.attributes&&r(e,n.attributes),n.handlers&&i(e,n.handlers),n.styles&&t(e,n.styles,n.theme),n.innerHTML&&(e.innerHTML=n.innerHTML),e},t=(n,e,t)=>{e.forEach((e=>{const r="dintero-deals-"+(n=>{let e=0;for(var t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e&=e;return e.toString(36)})(e("dintero-deals",t));((n,e)=>{n.className.split(" ").includes(e)||(n.className=n.className+" "+e)})(n,r);if(!document.querySelector(`[data-css-hash=${r}]`)){const n=document.createElement("style");n.innerHTML=e(r,t),n.setAttribute("data-css-hash",r),document.head.appendChild(n)}}))},r=(n,e)=>{Object.keys(e).forEach((t=>{n.setAttribute(t,e[t])}))},i=(n,e)=>{Object.keys(e).forEach((t=>{n.addEventListener(t,e[t])}))},a={no:{rewards:{discount_item_quantity:{three_for_two:"3 for 2",generic:"Kjøp {{require}} betal for {{payFor}}"},discount_amount:"{{monetaryAmount}} rabatt"},limitations:{discount_reward_usage:"Antall: <strong>{{discount_reward_usage}}</strong>",discount_repeat_usage:"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>"},requirements:{purchase_from:"Tilbudet starter <strong>{{purchase_from}}</strong>",purchase_to:"Tilbudet utgår <strong>{{purchase_to}}</strong>"},errors:{fetch:"⚠️ <br/>En feil oppstod under lasting av tilbud..."}}},o=/(\{\{)[^}]*(\}\})/g,s=(n,e)=>{const t=n.match(o)||[],r=e||{};return t.reduce(((n,e)=>{const t=e.replace("{{","").replace("}}",""),i=r[t]||"";return n.replace(e,i)}),n)},d=(n,e,t)=>{const r=t||{},i=n.toString(),a=i.length-e.currency.exponent,o=i.slice(0,a)||"0",s=i.slice(a),d="00"!=s||r.decimal?o+"."+s:o;return"short"===r.variant&&"00"===s?o+",-":r.currency?"prefix"===e.currency.position?e.currency.value+" "+d:d+" "+e.currency.value:d},c=n=>n<10?`0${n}`:n.toString(),u=(n,e)=>{try{const t=new Date(n);if("no"===e.language){const n=c(t.getDate()),e=c(t.getMonth()+1);return[n,e,t.getFullYear()].join(".")}return(new Intl.DateTimeFormat).format(t)}catch(e){return n.substr(0,10)}},p=n=>`\n.${n} {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n outline: none;\n border: none;\n box-shadow: none;\n line-height: auto;\n background: transparent;\n opacity: 1;\n border-radius: 0;\n display: block;\n position: relative;\n font-weight: normal;\n}\n`,l=n=>n.links&&n.links.find((n=>n.rel&&"webshop"===n.rel)),m=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${e.borderRadius};\n text-align: center;\n padding-top: 5px;\n padding-bottom: 105px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 1em;\n margin: 5px 20px;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n color: inherit;\n text-decoration: none;\n}\n\n@media screen and (max-width: 679px) {\n .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,h=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,g=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,f=(n,e)=>`\n.${n} {\n position: absolute;\n bottom: 60px;\n left: -20px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: 0 ${e.borderRadius} ${e.borderRadius} 0;\n padding: 5px 0;\n background: ${e?.secondary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n bottom: -10px;\n left: 0;\n border-color: transparent;\n border-style: solid;\n border-width: 0 20px 10px 0;\n border-right-color: ${e.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,b=(n,e)=>`\n.${n} {\n position: absolute;\n right: -20px;\n bottom: 15px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: ${e.borderRadius} 0 0 ${e.borderRadius};\n padding: 5px 0;\n background: ${e?.primary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n right: 0;\n bottom: -10px;\n border-color: transparent;\n border-style: solid;\n border-width: 10px 20px 0 0;\n border-top-color: ${e.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,y=n=>`\n.${n} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`,x=n=>`\n.${n} {\n margin-top: 0;\n}`,w=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,_=(n,t)=>{const r=((n,e)=>{const t=a[e.language];if("discount_item_new_price"===n.reward.type)return d(n.reward.value,e,{variant:"short"});if("discount_percent"===n.reward.type)return n.reward.value+"%";if("discount_item_quantity"===n.reward.type){if(3===n.requirement.item.quantity&&1===n.reward.value)return t.rewards.discount_item_quantity.three_for_two;{const e=n.requirement.item.quantity,r=n.requirement.item.quantity-n.reward.value;return s(t.rewards.discount_item_quantity.generic,{require:e,payFor:r})}}if("discount_amount"===n.reward.type){const r=d(n.reward.value,e,{decimal:!1});return s(t.rewards.discount_amount,{monetaryAmount:r})}return"discount_item_percent"===n.reward.type?n.reward.value+"%":""})(n,t);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[b]})},$=(n,t)=>{const r=e({tag:l(n)?"a":"div",styles:[p,m],theme:t.theme}),i=((n,t)=>{const r=(n=>n&&n.metadata&&n.metadata.label||void 0)(n);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[f]})})(n,t),o=_(n,t),d=(n=>{const t=e({tag:"div",styles:[p,h]}),r=n.links.find((n=>["medium_discount_image","thumbnail_discount_image".includes(n.rel)])),i=r&&e({tag:"img",attributes:{src:r.href,alt:n.name,loading:"lazy"},styles:[p,g]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[y]}),b=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[x]}),$=n.description&&e({tag:"p",innerHTML:n.description}),v=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,w]});return[n.limitation.discount_reward_usage&&-1!==n.limitation.discount_reward_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_reward_usage,{discount_reward_usage:n.limitation.discount_reward_usage})}),n.limitation.discount_repeat_usage&&-1!==n.limitation.discount_repeat_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_repeat_usage,{discount_repeat_usage:n.limitation.discount_repeat_usage})}),new Date(n.requirement.purchase_from||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_from,{purchase_from:u(n.requirement.purchase_from,t)})}),new Date(n.requirement.purchase_to||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_to,{purchase_to:u(n.requirement.purchase_to,t)})})].filter((n=>n)).forEach((n=>i.appendChild(n))),i})(n,t);return[i,o,d,c,b,$,v].filter((n=>n)).forEach((n=>r.appendChild(n))),r},v=(n,e)=>{const t=new Headers;return Object.entries({...n,"Dintero-System-Name":"deals-web-sdk","Dintero-System-Version":e.version}).forEach((([n,e])=>{t.append(n,e)})),t},k=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=v({Authorization:`Basic ${e}`,"content-type":"application/json"},n),r=JSON.stringify({grant_type:"client_credentials",audience:`${n.api.url}/v1/accounts/${n.api.account}`});return window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/auth/token`,{method:"POST",headers:t,body:r}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})(n).then((e=>{const t=v({Authorization:`${e.token_type} ${e.access_token}`},n);return n.api.discountId?window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules/${n.api.discountId}`,{headers:t}).then((n=>{if(200===n.status)return n.json().then((n=>[n]));throw new Error("Authentication failed")})):window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules?limit=${n.api.limit}`,{headers:t}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})),T=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: 3px;\n text-align: center;\n padding-top: 65px;\n padding-bottom: 70px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 14px;\n margin: 5px auto;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`,q=(n,e)=>`\n.${n} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${n}:after {\n content: " ";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #000;\n border-color: rgba(0,0,0,0.2) transparent rgba(0,0,0,0.2) transparent;\n animation: loading 0.6s linear infinite;\n}\n\n@keyframes loading {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n`;const M={language:"no",version:"0.2.7",linkTarget:"_self",currency:{value:"Kr",position:"suffix",exponent:2},theme:{background:"#fff",primary:"#333",secondary:"#333",color:"inherit",borderRadius:"2px",fontSize:"inherit"},api:{account:"",key:"",secret:"",url:"https://api.dintero.com",limit:50}},z=(n,e)=>`\n.${n} {\n display: flex;\n flex-flow: wrap;\n align-items: stretch;\n justify-content: center;\n position: relative;\n font-weight: normal;\n width: 100%;\n font-size: ${e.fontSize};\n color: ${e.color};\n}`,E=(n,t)=>{const r=e({tag:"div",styles:[p,z],theme:n.theme});return t.forEach((e=>{const t=$(e,n),i=l(e);i&&(t.setAttribute("target",n?.linkTarget||"_self"),t.setAttribute("href",i.href)),r.appendChild(t)})),n.container.appendChild(r),{destroy:()=>{n.container.removeChild(r)}}};n.embed=async n=>{const t=(r=M,i=n,{...r,...i,currency:{...r.currency,...i.currency},theme:{...r.theme,...i.theme},api:{...r.api,...i.api}});var r,i;if(!t.container||!t.container.appendChild)throw console.error("Invalid configuration"),new Error("Invalid configuration");if(t.discounts)return E(t,t.discounts);{const r=(n=>e({tag:"div",styles:[p,q],theme:n.theme}))(t);try{n.container.appendChild(r);const e=await k(t);return t.container.removeChild(r),E(t,e)}catch(i){n.container.removeChild(r);const o=(n=>{const t=a[n.language];return e({tag:"div",styles:[p,T],theme:n.theme,innerHTML:t.errors.fetch})})(t);return t.container.appendChild(o),{destroy:()=>{n.container.removeChild(o)}}}}},Object.defineProperty(n,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=dintero-discounts-web-sdk.umd.min.js.map