@magicfeedback/native 1.2.5-beta.3 → 1.2.5-beta.4

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.
package/README.md CHANGED
@@ -255,22 +255,22 @@ Feel free to adapt and expand upon the provided styles to match your desired des
255
255
  ```css
256
256
  /* Overall container for the feedback form */
257
257
  .magicfeedback-container {
258
- /* ... add your container styles here ... */
258
+ /* ... add your container styles here ... */
259
259
  }
260
260
 
261
261
  /* Main form element */
262
262
  .magicfeedback-form {
263
- /* ... add your form styles here ... */
263
+ /* ... add your form styles here ... */
264
264
  }
265
265
 
266
266
  /* Section for questions */
267
267
  .magicfeedback-questions {
268
- /* ... add your questions section styles here ... */
268
+ /* ... add your questions section styles here ... */
269
269
  }
270
270
 
271
271
  /* Section for div */
272
272
  .magicfeedback-div {
273
- /* ... add your generic div styles here ... */
273
+ /* ... add your generic div styles here ... */
274
274
  }
275
275
 
276
276
  /* Generic styles for various input elements */
@@ -292,19 +292,40 @@ Feel free to adapt and expand upon the provided styles to match your desired des
292
292
  .magicfeedback-number,
293
293
  .magicfeedback-longtext,
294
294
  .magicfeedback-text {
295
- /* ... add your generic input styles here ... */
295
+ /* ... add your generic input styles here ... */
296
+ }
297
+
298
+ .magicfeedback-skip-container {
299
+ /* ... add your skip container styles here ... */
300
+ }
301
+
302
+ .magicfeedback-skip{
303
+ /* ... add your skip button styles here ... */
296
304
  }
297
305
 
298
306
  .magicfeedback-image {
299
- /* ... add your image styles here ... */
307
+ /* ... add your image styles here ... */
300
308
  }
301
309
 
302
310
  /* Specific styles for individual input types */
303
311
  .magicfeedback-radio-container,
304
312
  .magicfeedback-boolean-container,
305
313
  .magicfeedback-consent-container,
306
- .magicfeedback-checkbox-container {
307
- /* ... add styles for radio/checkbox containers ... */
314
+ .magicfeedback-checkbox-container,
315
+ .magicfeedback-longtext-container{
316
+ /* ... add styles for radio/checkbox containers ... */
317
+ }
318
+
319
+ .magicfeedback-rating-placeholder {
320
+ /* ... add your rating placeholder styles here ... */
321
+ }
322
+
323
+ .magicfeedback-rating-placeholder-min {
324
+ /* ... add your rating placeholder min styles here ... */
325
+ }
326
+
327
+ .magicfeedback-rating-placeholder-max {
328
+ /* ... add your rating placeholder max styles here ... */
308
329
  }
309
330
 
310
331
  .magicfeedback-rating-image1,
@@ -316,87 +337,115 @@ Feel free to adapt and expand upon the provided styles to match your desired des
316
337
  .magicfeedback-rating-image7,
317
338
  .magicfeedback-rating-image8,
318
339
  .magicfeedback-rating-image9,
319
- .magicfeedback-rating-image10 {
320
- /* ... add styles for rating images ... */
340
+ .magicfeedback-rating-image10,
341
+ .magicfeedback-rating-image-extra {
342
+ /* ... add styles for rating images ... */
321
343
  }
322
344
 
323
345
  /* Section for number rating */
324
346
  .magicfeedback-rating-number-container {
325
- /* ... add your number rating container styles here ... */
347
+ /* ... add your number rating container styles here ... */
348
+ }
349
+
350
+ .magicfeedback-rating-number-placeholder {
351
+ /* ... add your number rating placeholder styles here ... */
352
+ }
353
+
354
+ .magicfeedback-rating-number-placeholder-min {
355
+ /* ... add your number rating placeholder min styles here ... */
356
+ }
357
+
358
+ .magicfeedback-rating-number-placeholder-max {
359
+ /* ... add your number rating placeholder max styles here ... */
326
360
  }
327
361
 
328
362
  .magicfeedback-rating-number-option {
329
- /* ... add your number rating option styles here ... */
363
+ /* ... add your number rating option styles here ... */
330
364
  }
331
365
 
332
366
  .magicfeedback-rating-number-option-label-container {
333
- /* ... add your number rating option label container styles here ... */
367
+ /* ... add your number rating option label container styles here ... */
334
368
  }
335
369
 
336
370
 
337
371
  /* Section for star rating */
338
372
  .magicfeedback-rating-star {
339
- /* ... add your star rating container styles here ... */
373
+ /* ... add your star rating container styles here ... */
340
374
  }
341
375
 
342
376
  .magicfeedback-rating-star-container {
343
- /* ... add your star rating styles here ... */
377
+ /* ... add your star rating styles here ... */
344
378
  }
345
379
 
346
380
  .magicfeedback-rating-star-option {
347
- /* ... add your star rating option styles here ... */
381
+ /* ... add your star rating option styles here ... */
348
382
  }
349
383
 
350
384
  .magicfeedback-rating-star-selected {
351
- /* ... add your star rating selected styles here ... */
385
+ /* ... add your star rating selected styles here ... */
352
386
  }
353
387
 
354
388
  /* Section for multiple choice image */
355
- .magicfeedback-multiple-choice-image{
356
- /* ... add your multiple choice image container styles here ... */
389
+ .magicfeedback-multiple-choice-image {
390
+ /* ... add your multiple choice image container styles here ... */
357
391
  }
358
392
 
359
393
  .magicfeedback-multiple-choice-image-container {
360
- /* ... add your multiple choice image styles here ... */
394
+ /* ... add your multiple choice image styles here ... */
361
395
  }
362
396
 
363
397
  .magicfeedback-multiple-choice-image-option {
364
- /* ... add your multiple choice image option styles here ... */
398
+ /* ... add your multiple choice image option styles here ... */
365
399
  }
366
400
 
367
401
  .magicfeedback-image-option-label-container {
368
- /* ... add your multiple choice image option label container styles here ... */
402
+ /* ... add your multiple choice image option label container styles here ... */
369
403
  }
370
404
 
371
405
  .magicfeedback-multiple-choice-image-label {
372
- /* ... add your multiple choice image label styles here ... */
406
+ /* ... add your multiple choice image label styles here ... */
373
407
  }
408
+
374
409
  .magicfeedback-multiple-choice-image-input {
375
- /* ... add your multiple choice image input styles here ... */
410
+ /* ... add your multiple choice image input styles here ... */
376
411
  }
412
+
377
413
  .magicfeedback-multiple-choice-image-image {
378
- /* ... add your multiple choice image image styles here ... */
414
+ /* ... add your multiple choice image image styles here ... */
379
415
  }
380
416
 
381
417
 
382
418
  /* Action buttons container */
383
419
  .magicfeedback-action-container {
384
- /* ... add your action button container styles here ... */
420
+ /* ... add your action button container styles here ... */
385
421
  }
386
422
 
387
423
  /* Submit button */
388
424
  .magicfeedback-submit {
389
- /* ... add your submit button styles here ... */
425
+ /* ... add your submit button styles here ... */
390
426
  }
391
427
 
392
428
  /* Back button */
393
429
  .magicfeedback-back {
394
- /* ... add your back button styles here ... */
430
+ /* ... add your back button styles here ... */
431
+ }
432
+
433
+ /* Start message */
434
+ .magicfeedback-start-message-container {
435
+ /* ... add your start message container styles here ... */
436
+ }
437
+
438
+ .magicfeedback-start-message {
439
+ /* ... add your start message styles here ... */
440
+ }
441
+
442
+ .magicfeedback-start-message-button {
443
+ /* ... add your start message button styles here ... */
395
444
  }
396
445
 
397
446
  /* Success message (if applicable) */
398
447
  .magicfeedback-success {
399
- /* ... add your success message styles here ... */
448
+ /* ... add your success message styles here ... */
400
449
  }
401
450
  ```
402
451
 
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,a=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,a="Symbol"in e&&"iterator"in Symbol,s="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return a&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function m(e){var t=new FileReader,i=f(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:n&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(m)}),this.text=function(){var e,t,i,a=p(this);if(a)return a;if(this._bodyBlob)return e=this._bodyBlob,i=f(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),a=0;a<t.length;a++)i[a]=String.fromCharCode(t[a]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},a&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,a,s=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(a=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(a)>-1?a:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),a=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(a),decodeURIComponent(s))}})),t}function E(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},b.call(v.prototype),b.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var e=new E(null,{status:0,statusText:""});return e.type="error",e};var w=[301,302,303,307,308];E.redirect=function(e,t){if(-1===w.indexOf(t))throw new RangeError("Invalid status code");return new E(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function x(e,i){return new Promise((function(a,n){var r=new v(e,i);if(r.signal&&r.signal.aborted)return n(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),a=i.shift().trim();if(a){var s=i.join(":").trim();t.append(a,s)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var s="response"in o?o.response:o.responseText;a(new E(s,i))},o.onerror=function(){n(new TypeError("Network request failed"))},o.ontimeout=function(){n(new TypeError("Network request failed"))},o.onabort=function(){n(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&s&&(o.responseType="blob"),r.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",c),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",c)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=h,e.Request=v,e.Response=E),t.Headers=h,t.Request=v,t.Response=E,t.fetch=x,Object.defineProperty(t,"__esModule",{value:!0})}({})}(a),a.fetch.ponyfill=!0,delete a.fetch.polyfill;var s=a;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=a(i(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),r=i(5),o=i(341),c=i(290);t.default=function(){const e=new n.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,r=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:s,privateKey:d,completed:r,id:c,feedback:n};try{const e=yield(0,o.sendFeedback)(a,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,a){return i||t.err("No appID provided"),a||t.err("No publicKey provided"),new s.Form(e,i,a)}}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),r=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return a(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const a=localStorage.getItem(`magicfeedback-${this.appId}`);if(a&&new Date(JSON.parse(a).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(a),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),a.appendChild(s),this.formOptionsConfig.addButton){const e=(0,r.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,r.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var s;return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));r&&(this.id=r,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,error:r?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=e.type,s=e.classList[0],r={key:e.name,value:[]},o="magicfeedback-consent"===s?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){r.value.push(o);const e=t.findIndex((e=>e.key===r.key));-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}break;default:if(""!==o){if("email"===a){if(!(0,n.validateEmail)(o)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[o]})}r.value.push(o);const e=t.findIndex((e=>e.key===r.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const a=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(a,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return a(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,s,n,o;return a(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const a=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",n="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const r=[];return t.forEach((t=>{var o,c;if((null===(c=null===(o=null==t?void 0:t.questionType)||void 0===o?void 0:o.conf)||void 0===c?void 0:c.length)>0){let a=document.createElement("div");a.classList.add("magicfeedback-div"),console.log(t),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,n).forEach((e=>{a.appendChild(e)})),r.push(a)}else{const e=function(e,t,i){const{id:n,title:r,type:o,ref:c,require:d,value:l,defaultValue:u,assets:h}=e;let p,f,m=document.createElement("div");switch(m.classList.add("magicfeedback-div"),o){case"TEXT":p=document.createElement("input"),p.type="text",p.placeholder="slim"===t?s(r,i):`${h.placeholder||a.placeholder.answer(i||"en")}`,f="magicfeedback-text";break;case"LONGTEXT":p=document.createElement("textarea"),p.rows=3,p.placeholder="slim"===t?s(r,i):`${h.placeholder||a.placeholder.answer(i||"en")}`,f="magicfeedback-longtext";break;case"NUMBER":p=document.createElement("input"),p.type="number",p.placeholder="slim"===t?s(r,i):`${h.placeholder||a.placeholder.number(i||"en")}`,f="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),p.max=l[l.length-1],p.min=l[0],p.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":p=document.createElement("div"),f="magicfeedback-"+("MULTIPLECHOICE"===o?"checkbox":"radio"),h.extraOption&&l.push(h.extraOptionText),l.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===o?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${c}-${t}`,s.type="MULTIPLECHOICE"===o?"checkbox":"radio",s.name=c,s.value=e,s.classList.add(f),s.classList.add("magicfeedback-input"),e===u&&(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${c}-${t}`,h.extraOption&&e===h.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${c}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(s),i.appendChild(a),p.appendChild(i),h.extraOption&&e===h.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${c}`,e.name=`extra-option-${c}`,e.style.display="none",p.appendChild(e)}}));break;case"BOOLEAN":p=document.createElement("div"),f="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${c}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${c}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${c}-${i}`,n.type="radio",n.name=c,n.value=t,n.classList.add(f),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",a.appendChild(n),a.appendChild(s),e.appendChild(a)})),p.appendChild(e);break;case"RATING_EMOJI":p=document.createElement("div"),f="magicfeedback-rating";const g=document.createElement("div");g.classList.add("magicfeedback-rating-container");const b=h.max?Number(h.max):5,y=h.min?Number(h.min):1,v=document.createElement("div");if(v.classList.add("magicfeedback-rating-placeholder"),v.style.display="flex",v.style.justifyContent="space-between",v.style.width="90%",v.style.margin="auto",h.minPlaceholder){const e=document.createElement("span");e.textContent=h.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",v.appendChild(e)}if(h.maxPlaceholder){const e=document.createElement("span");e.textContent=h.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",v.appendChild(e)}for(let e=y;e<=b;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${c}-${e}`,s.className=`rating-image${e}`,0===y&&10===b)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===y&&5===b)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(b-y)*(e-y));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(f),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),i.appendChild(a),t.appendChild(i),g.appendChild(t)}if(h.extraOption&&h.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${c}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${c}-extra`,i.textContent=h.extraOptionText;const a=document.createElement("img");a.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",a.alt=`face-${c}-extra`,a.className="rating-image-extra";const s=document.createElement("input");s.id=`rating-${c}-extra`,s.type="radio",s.name=c,s.value="-",s.classList.add(f),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(a),t.appendChild(i),e.appendChild(t),g.appendChild(e)}p.appendChild(v),p.appendChild(g);break;case"RATING_NUMBER":p=document.createElement("div"),f="magicfeedback-rating-number";const k=document.createElement("div");k.classList.add("magicfeedback-rating-number-container");const E=h.max?Number(h.max):5,w=h.min?Number(h.min):1,x=document.createElement("div");if(x.classList.add("magicfeedback-rating-number-placeholder"),x.style.display="flex",x.style.justifyContent="space-between",x.style.width="90%",x.style.margin="auto",h.minPlaceholder){const e=document.createElement("span");e.textContent=h.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}if(h.maxPlaceholder){const e=document.createElement("span");e.textContent=h.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}for(let e=w;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${c}-${e}`,s.type="radio",s.name=c,s.value=e.toString(),s.classList.add(f),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),k.appendChild(t)}if(h.extraOption&&h.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${c}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${c}-extra`,i.textContent=h.extraOptionText;const a=document.createElement("input");a.id=`rating-${c}-extra`,a.type="radio",a.name=c,a.value="-",a.classList.add(f),a.classList.add("magicfeedback-input"),t.appendChild(a),t.appendChild(i),e.appendChild(t),k.appendChild(e)}p.appendChild(x),p.appendChild(k);break;case"RATING_STAR":p=document.createElement("div"),f="magicfeedback-rating-star";const C=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let a=1;a<=5;a++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${a}`,n.type="radio",n.name=e,n.value=a.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),s.appendChild(n);const r=document.createElement("label");r.htmlFor=`rating-${e}-${a}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",s.appendChild(r),i.appendChild(s)}return i}(c);p.appendChild(C);break;case"MULTIPLECHOISE_IMAGE":p=document.createElement("div"),f="magicfeedback-multiple-choice-image";const L=document.createElement("div");L.classList.add("magicfeedback-multiple-choice-image-container"),L.style.display="flex",L.style.flexDirection="row",L.style.flexWrap="wrap",L.style.justifyContent="center";const O=l.length;let S=1,I=1;switch(O){case 1:case 2:case 3:S=O,I=1;break;case 4:case 5:case 6:I=2,S=Math.ceil(O/2);break;default:I=3,S=Math.ceil(O/3)}const _=void 0!==h.addTitle&&h.addTitle;l.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/S}% - 10px)`,s.style.height=`calc( ${100/I}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=a,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${c}-${t}`,o.type="radio",o.name=c,o.value=a,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",n.appendChild(o),n.appendChild(d),_&&n.appendChild(r),s.appendChild(n),L.appendChild(s)}catch(e){console.error(e)}})),p.appendChild(L);break;case"SELECT":p=document.createElement("select"),f="magicfeedback-select";const T=document.createElement("option");T.value="",T.text="slim"===t?s(r,i):u||"Select an option",T.disabled=!0,T.selected=!0,p.appendChild(T),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,p.appendChild(t)}));break;case"DATE":p=document.createElement("input"),p.type="date",p.required=d,p.placeholder="slim"===t?s(r,i):`${h.placeholder||a.placeholder.date(i||"en")}`,f="magicfeedback-date";break;case"CONSENT":p=document.createElement("input"),f="magicfeedback-consent",p.type="checkbox",p.id=`magicfeedback-${n}`,p.name=c,p.value="true",p.required=d,p.classList.add("magicfeedback-consent"),p.classList.add("magicfeedback-input");break;case"EMAIL":p=document.createElement("input"),p.type="email",p.required=d,p.placeholder="slim"===t?s(r,i):`${h.placeholder||"you@example.com"}`,f="magicfeedback-email";break;case"PASSWORD":p=document.createElement("input"),p.type="password",p.required=d,p.placeholder="slim"===t?s(r,i):`${h.placeholder||a.placeholder.password(i||"en")}`,f="magicfeedback-password";break;default:return m}p.id=`magicfeedback-${n}`,p.setAttribute("name",c),p.classList.add(f),void 0!==u&&(p.value=u),["RADIO","MULTIPLECHOICE"].includes(o)||(p.classList.add("magicfeedback-input"),p.required=d);const g=document.createElement("label");if(g.setAttribute("for",`magicfeedback-${n}`),g.textContent=s(r,i),g.classList.add("magicfeedback-label"),["CONSENT"].includes(o))m.classList.add("magicfeedback-consent-container"),m.appendChild(p),m.appendChild(g);else{if("slim"!==t&&(m.appendChild(g),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",m.appendChild(e)}m.appendChild(p)}return m}(t,i,n);r.push(e)}})),r},t.renderActions=function(e="",t,i="Submit",a="Back",s="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=a||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(o),n.appendChild(r),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.textContent=e;const r=document.createElement("button");return r.id="magicfeedback-start-message-button",r.classList.add("magicfeedback-start-message-button"),r.textContent=a,r.addEventListener("click",(()=>t())),s.appendChild(n),i&&s.appendChild(r),s}},341:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=s(i(98)),r=s(i(147)),o=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":r.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield a.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield a.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.3","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(a){var s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.exports}(607).default;var e,t}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,a=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,a="Symbol"in e&&"iterator"in Symbol,s="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return a&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function m(e){var t=new FileReader,i=f(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:n&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(m)}),this.text=function(){var e,t,i,a=p(this);if(a)return a;if(this._bodyBlob)return e=this._bodyBlob,i=f(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),a=0;a<t.length;a++)i[a]=String.fromCharCode(t[a]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},a&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,a,s=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(a=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(a)>-1?a:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),a=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(a),decodeURIComponent(s))}})),t}function E(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},b.call(v.prototype),b.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var e=new E(null,{status:0,statusText:""});return e.type="error",e};var w=[301,302,303,307,308];E.redirect=function(e,t){if(-1===w.indexOf(t))throw new RangeError("Invalid status code");return new E(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function x(e,i){return new Promise((function(a,n){var r=new v(e,i);if(r.signal&&r.signal.aborted)return n(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),a=i.shift().trim();if(a){var s=i.join(":").trim();t.append(a,s)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var s="response"in o?o.response:o.responseText;a(new E(s,i))},o.onerror=function(){n(new TypeError("Network request failed"))},o.ontimeout=function(){n(new TypeError("Network request failed"))},o.onabort=function(){n(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&s&&(o.responseType="blob"),r.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",c),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",c)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=h,e.Request=v,e.Response=E),t.Headers=h,t.Request=v,t.Response=E,t.fetch=x,Object.defineProperty(t,"__esModule",{value:!0})}({})}(a),a.fetch.ponyfill=!0,delete a.fetch.polyfill;var s=a;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=a(i(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),r=i(5),o=i(341),c=i(290);t.default=function(){const e=new n.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,r=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:s,privateKey:d,completed:r,id:c,feedback:n};try{const e=yield(0,o.sendFeedback)(a,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,a){return i||t.err("No appID provided"),a||t.err("No publicKey provided"),new s.Form(e,i,a)}}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),r=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return a(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const a=localStorage.getItem(`magicfeedback-${this.appId}`);if(a&&new Date(JSON.parse(a).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(a),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),a.appendChild(s),this.formOptionsConfig.addButton){const e=(0,r.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,r.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var s;return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));r&&(this.id=r,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,error:r?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;const a=e.querySelectorAll(".magicfeedback-input");console.log(a),a.forEach((e=>{console.log(e);const a=e.type,s=e.classList[0],r={key:e.name,value:[]},o="magicfeedback-consent"===s?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){r.value.push(o);const e=t.findIndex((e=>e.key===r.key));-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}break;default:if(""!==o){if("email"===a){if(!(0,n.validateEmail)(o)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[o]})}r.value.push(o);const e=t.findIndex((e=>e.key===r.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const a=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(a,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return a(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,s,n,o;return a(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const a=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",n="en",r){if(!t)throw new Error("[MagicFeedback] No questions provided");const o=[];return t.forEach((t=>{var c,d;if((null===(d=null===(c=null==t?void 0:t.questionType)||void 0===c?void 0:c.conf)||void 0===d?void 0:d.length)>0){let a=document.createElement("div");a.classList.add("magicfeedback-div"),console.log(t),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,n,r).forEach((e=>{a.appendChild(e)})),o.push(a)}else{const e=function(e,t,i,n){const{id:r,title:o,type:c,ref:d,require:l,value:u,defaultValue:h,assets:p}=e;let f,m,g=document.createElement("div");switch(g.classList.add("magicfeedback-div"),c){case"TEXT":f=document.createElement("input"),f.type="text",f.placeholder="slim"===t?s(o,i):`${p.placeholder||a.placeholder.answer(i||"en")}`,m="magicfeedback-text";break;case"LONGTEXT":f=document.createElement("textarea"),f.rows=3,f.maxLength=300,f.placeholder="slim"===t?s(o,i):a.placeholder.answer(i||"en"),m="magicfeedback-longtext";break;case"NUMBER":f=document.createElement("input"),f.type="number",f.placeholder="slim"===t?s(o,i):`${p.placeholder||a.placeholder.number(i||"en")}`,m="magicfeedback-number",u.length&&(u.sort(((e,t)=>Number(e)-Number(t))),f.max=u[u.length-1],f.min=u[0],f.value=u[0]);break;case"RADIO":case"MULTIPLECHOICE":f=document.createElement("div"),m="magicfeedback-"+("MULTIPLECHOICE"===c?"checkbox":"radio"),p.extraOption&&u.push(p.extraOptionText),u.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===c?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${d}-${t}`,s.type="MULTIPLECHOICE"===c?"checkbox":"radio",s.name=d,s.value=e,s.classList.add(m),s.classList.add("magicfeedback-input"),e===h&&(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${d}-${t}`,p.extraOption&&e===p.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${d}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(s),i.appendChild(a),f.appendChild(i),p.extraOption&&e===p.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${d}`,e.name=`extra-option-${d}`,e.style.display="none",f.appendChild(e)}}));break;case"BOOLEAN":f=document.createElement("div"),m="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(p.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${d}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${d}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${d}-${i}`,n.type="radio",n.name=d,n.value=t,n.classList.add(m),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",a.appendChild(n),a.appendChild(s),e.appendChild(a)})),f.appendChild(e);break;case"RATING_EMOJI":f=document.createElement("div"),m="magicfeedback-rating";const n=document.createElement("div");n.classList.add("magicfeedback-rating-container");const b=p.max?Number(p.max):5,y=p.min?Number(p.min):1,v=document.createElement("div");if(v.classList.add("magicfeedback-rating-placeholder"),v.style.display="flex",v.style.justifyContent="space-between",v.style.width="90%",v.style.margin="auto",p.minPlaceholder){const e=document.createElement("span");e.textContent=p.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",v.appendChild(e)}if(p.maxPlaceholder){const e=document.createElement("span");e.textContent=p.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",v.appendChild(e)}for(let e=y;e<=b;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${d}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${d}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${d}-${e}`,s.className=`rating-image${e}`,0===y&&10===b)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===y&&5===b)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(b-y)*(e-y));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const r=document.createElement("input");r.id=`rating-${d}-${e}`,r.type="radio",r.name=d,r.value=e.toString(),r.classList.add(m),r.classList.add("magicfeedback-input"),i.appendChild(r),i.appendChild(s),i.appendChild(a),t.appendChild(i),n.appendChild(t)}if(p.extraOption&&p.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${d}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${d}-extra`,i.textContent=p.extraOptionText;const a=document.createElement("img");a.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",a.alt=`face-${d}-extra`,a.className="magicfeedback-rating-image-extra";const s=document.createElement("input");s.id=`rating-${d}-extra`,s.type="radio",s.name=d,s.value="-",s.classList.add(m),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(a),t.appendChild(i),e.appendChild(t),n.appendChild(e)}f.appendChild(v),f.appendChild(n);break;case"RATING_NUMBER":f=document.createElement("div"),m="magicfeedback-rating-number";const k=document.createElement("div");k.classList.add("magicfeedback-rating-number-container");const E=p.max?Number(p.max):5,w=p.min?Number(p.min):1,x=document.createElement("div");if(x.classList.add("magicfeedback-rating-number-placeholder"),x.style.display="flex",x.style.justifyContent="space-between",x.style.width="90%",x.style.margin="auto",p.minPlaceholder){const e=document.createElement("span");e.textContent=p.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}if(p.maxPlaceholder){const e=document.createElement("span");e.textContent=p.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}for(let e=w;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${d}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${d}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${d}-${e}`,s.type="radio",s.name=d,s.value=e.toString(),s.classList.add(m),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),k.appendChild(t)}if(p.extraOption&&p.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${d}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${d}-extra`,i.textContent=p.extraOptionText;const a=document.createElement("input");a.id=`rating-${d}-extra`,a.type="radio",a.name=d,a.value="-",a.classList.add(m),a.classList.add("magicfeedback-input"),t.appendChild(a),t.appendChild(i),e.appendChild(t),k.appendChild(e)}f.appendChild(x),f.appendChild(k);break;case"RATING_STAR":f=document.createElement("div"),m="magicfeedback-rating-star";const C=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let a=1;a<=5;a++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${a}`,n.type="radio",n.name=e,n.value=a.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),s.appendChild(n);const r=document.createElement("label");r.htmlFor=`rating-${e}-${a}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",s.appendChild(r),i.appendChild(s)}return i}(d);f.appendChild(C);break;case"MULTIPLECHOISE_IMAGE":f=document.createElement("div"),m="magicfeedback-multiple-choice-image";const L=document.createElement("div");L.classList.add("magicfeedback-multiple-choice-image-container"),L.style.display="flex",L.style.flexDirection="row",L.style.flexWrap="wrap",L.style.justifyContent="center";const O=u.length;let S=1,I=1;switch(O){case 1:case 2:case 3:S=O,I=1;break;case 4:case 5:case 6:I=2,S=Math.ceil(O/2);break;default:I=3,S=Math.ceil(O/3)}const T=void 0!==p.addTitle&&p.addTitle;u.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/S}% - 10px)`,s.style.height=`calc( ${100/I}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${d}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=a,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${d}-${t}`,o.type="radio",o.name=d,o.value=a,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input");const c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=i,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.width="100%",c.style.height="100%",c.style.margin="auto",n.appendChild(o),n.appendChild(c),T&&n.appendChild(r),s.appendChild(n),L.appendChild(s)}catch(e){console.error(e)}})),f.appendChild(L);break;case"SELECT":f=document.createElement("select"),m="magicfeedback-select";const _=document.createElement("option");_.value="",_.text="slim"===t?s(o,i):h||"Select an option",_.disabled=!0,_.selected=!0,f.appendChild(_),u.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,f.appendChild(t)}));break;case"DATE":f=document.createElement("input"),f.type="date",f.required=l,f.placeholder="slim"===t?s(o,i):`${p.placeholder||a.placeholder.date(i||"en")}`,m="magicfeedback-date";break;case"CONSENT":f=document.createElement("input"),m="magicfeedback-consent",f.type="checkbox",f.id=`magicfeedback-${r}`,f.name=d,f.value="true",f.required=l,f.classList.add("magicfeedback-consent"),f.classList.add("magicfeedback-input");break;case"EMAIL":f=document.createElement("input"),f.type="email",f.required=l,f.placeholder="slim"===t?s(o,i):`${p.placeholder||"you@example.com"}`,m="magicfeedback-email";break;case"PASSWORD":f=document.createElement("input"),f.type="password",f.required=l,f.placeholder="slim"===t?s(o,i):`${p.placeholder||a.placeholder.password(i||"en")}`,m="magicfeedback-password";break;default:return g}f.id=`magicfeedback-${r}`,f.setAttribute("name",d),f.classList.add(m),void 0!==h&&(f.value=h),["RADIO","MULTIPLECHOICE"].includes(c)||(f.classList.add("magicfeedback-input"),f.required=l);const b=document.createElement("label");if(b.setAttribute("for",`magicfeedback-${r}`),b.textContent=s(o,i),b.classList.add("magicfeedback-label"),["CONSENT"].includes(c))g.classList.add("magicfeedback-consent-container"),g.appendChild(f),g.appendChild(b);else{if("slim"!==t&&(g.appendChild(b),void 0!==(null==p?void 0:p.general)&&""!==(null==p?void 0:p.general))){const e=document.createElement("img");e.src=p.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",g.appendChild(e)}if("LONGTEXT"===c){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",f.addEventListener("input",(()=>{e.textContent=`${f.value.length}/300`})),g.appendChild(f),g.appendChild(e),p.extraOption&&p.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.style.display="flex",e.style.justifyContent="space-between";const t=document.createElement("button");t.textContent=p.extraOptionText,t.classList.add("magicfeedback-skip"),t.style.cursor="pointer",t.type="button",t.addEventListener("click",(()=>{f.value="-",n&&n()})),e.appendChild(t),g.appendChild(e)}}else g.appendChild(f)}return g}(t,i,n,r);o.push(e)}})),o},t.renderActions=function(e="",t,i="Submit",a="Back",s="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=a||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(o),n.appendChild(r),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.textContent=e;const r=document.createElement("button");return r.id="magicfeedback-start-message-button",r.classList.add("magicfeedback-start-message-button"),r.textContent=a,r.addEventListener("click",(()=>t())),s.appendChild(n),i&&s.appendChild(r),s}},341:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=s(i(98)),r=s(i(147)),o=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":r.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield a.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield a.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.4","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(a){var s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.exports}(607).default;var e,t}));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,a){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(a(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=a(954),n=a(712),o=a(5),r=a(341),c=a(290);t.default=function(){const e=new n.Config;let t;return{init:function(a){(null==a?void 0:a.debug)&&e.set("debug",null==a?void 0:a.debug),e.set("url",(null==a?void 0:a.env)&&"dev"===(null==a?void 0:a.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(a,s,n,o=!0,c,d){return i(this,void 0,void 0,(function*(){a||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const i=e.get("url"),l={integration:a,publicKey:s,privateKey:d,completed:o,id:c,feedback:n};try{const e=yield(0,r.sendFeedback)(i,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(a,i){return a||t.err("No appID provided"),i||t.err("No publicKey provided"),new s.Form(e,a,i)}}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=a(5),n=a(341),o=a(183);t.Form=class{constructor(e,t,a){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=a,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var a;return i(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,a,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(a=this.formData)||void 0===a?void 0:a.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,a;try{this.questions.sort(((e,t)=>e.position-t.position));let i=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),i.appendChild(s),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),a=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(a)}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,a){var s;return i(this,void 0,void 0,(function*(){const i=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{a&&(this.feedback.profile=[...this.feedback.profile,...a]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));o&&(this.id=o,yield this.processNextQuestion(i,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let a=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const i=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(i){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===i){if(!(0,n.validateEmail)(r)){this.log.err("Invalid email"),a=!0;break}this.feedback.profile.push({key:"email",value:[r]})}o.value.push(r);const e=t.findIndex((e=>e.key===o.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}}})),this.feedback.answers=a?[]:t}pushAnswers(e=!1){var t,a;return i(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(a=this.questionInProcess)||void 0===a?void 0:a.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(i,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return i(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),a={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,a,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var a,s,n,r;return i(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(a=this.formData)||void 0===a?void 0:a.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const a=yield this.callFollowUpQuestion(this.questionInProcess);if(a){this.questionInProcess=a;const e=(0,o.renderQuestions)([a],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:a,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,a)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const i=a(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,a="standard",n="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const o=[];return t.forEach((t=>{var r,c;if((null===(c=null===(r=null==t?void 0:t.questionType)||void 0===r?void 0:r.conf)||void 0===c?void 0:c.length)>0){let i=document.createElement("div");i.classList.add("magicfeedback-div"),console.log(t),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,a,n).forEach((e=>{i.appendChild(e)})),o.push(i)}else{const e=function(e,t,a){const{id:n,title:o,type:r,ref:c,require:d,value:l,defaultValue:u,assets:p}=e;let h,m,f=document.createElement("div");switch(f.classList.add("magicfeedback-div"),r){case"TEXT":h=document.createElement("input"),h.type="text",h.placeholder="slim"===t?s(o,a):`${p.placeholder||i.placeholder.answer(a||"en")}`,m="magicfeedback-text";break;case"LONGTEXT":h=document.createElement("textarea"),h.rows=3,h.placeholder="slim"===t?s(o,a):`${p.placeholder||i.placeholder.answer(a||"en")}`,m="magicfeedback-longtext";break;case"NUMBER":h=document.createElement("input"),h.type="number",h.placeholder="slim"===t?s(o,a):`${p.placeholder||i.placeholder.number(a||"en")}`,m="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),h.max=l[l.length-1],h.min=l[0],h.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":h=document.createElement("div"),m="magicfeedback-"+("MULTIPLECHOICE"===r?"checkbox":"radio"),p.extraOption&&l.push(p.extraOptionText),l.forEach(((e,t)=>{const a=document.createElement("div");a.classList.add(`magicfeedback-${"MULTIPLECHOICE"===r?"checkbox":"radio"}-container`);const i=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${c}-${t}`,s.type="MULTIPLECHOICE"===r?"checkbox":"radio",s.name=c,s.value=e,s.classList.add(m),s.classList.add("magicfeedback-input"),e===u&&(s.checked=!0),i.textContent=e,i.htmlFor=`rating-${c}-${t}`,p.extraOption&&e===p.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${c}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),a.appendChild(s),a.appendChild(i),h.appendChild(a),p.extraOption&&e===p.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${c}`,e.name=`extra-option-${c}`,e.style.display="none",h.appendChild(e)}}));break;case"BOOLEAN":h=document.createElement("div"),m="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(p.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(a)).forEach(((t,a)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${c}-${a}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${c}-${a}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${c}-${a}`,n.type="radio",n.name=c,n.value=t,n.classList.add(m),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",i.appendChild(n),i.appendChild(s),e.appendChild(i)})),h.appendChild(e);break;case"RATING_EMOJI":h=document.createElement("div"),m="magicfeedback-rating";const g=document.createElement("div");g.classList.add("magicfeedback-rating-container");const b=p.max?Number(p.max):5,v=p.min?Number(p.min):1,k=document.createElement("div");if(k.classList.add("magicfeedback-rating-placeholder"),k.style.display="flex",k.style.justifyContent="space-between",k.style.width="90%",k.style.margin="auto",p.minPlaceholder){const e=document.createElement("span");e.textContent=p.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",k.appendChild(e)}if(p.maxPlaceholder){const e=document.createElement("span");e.textContent=p.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",k.appendChild(e)}for(let e=v;e<=b;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${c}-${e}`,s.className=`rating-image${e}`,0===v&&10===b)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===v&&5===b)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(b-v)*(e-v));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(m),n.classList.add("magicfeedback-input"),a.appendChild(n),a.appendChild(s),a.appendChild(i),t.appendChild(a),g.appendChild(t)}if(p.extraOption&&p.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${c}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-extra`,a.textContent=p.extraOptionText;const i=document.createElement("img");i.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",i.alt=`face-${c}-extra`,i.className="rating-image-extra";const s=document.createElement("input");s.id=`rating-${c}-extra`,s.type="radio",s.name=c,s.value="-",s.classList.add(m),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(i),t.appendChild(a),e.appendChild(t),g.appendChild(e)}h.appendChild(k),h.appendChild(g);break;case"RATING_NUMBER":h=document.createElement("div"),m="magicfeedback-rating-number";const y=document.createElement("div");y.classList.add("magicfeedback-rating-number-container");const E=p.max?Number(p.max):5,C=p.min?Number(p.min):1,w=document.createElement("div");if(w.classList.add("magicfeedback-rating-number-placeholder"),w.style.display="flex",w.style.justifyContent="space-between",w.style.width="90%",w.style.margin="auto",p.minPlaceholder){const e=document.createElement("span");e.textContent=p.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}if(p.maxPlaceholder){const e=document.createElement("span");e.textContent=p.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}for(let e=C;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${c}-${e}`,s.type="radio",s.name=c,s.value=e.toString(),s.classList.add(m),s.classList.add("magicfeedback-input"),a.appendChild(s),a.appendChild(i),t.appendChild(a),y.appendChild(t)}if(p.extraOption&&p.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${c}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-extra`,a.textContent=p.extraOptionText;const i=document.createElement("input");i.id=`rating-${c}-extra`,i.type="radio",i.name=c,i.value="-",i.classList.add(m),i.classList.add("magicfeedback-input"),t.appendChild(i),t.appendChild(a),e.appendChild(t),y.appendChild(e)}h.appendChild(w),h.appendChild(y);break;case"RATING_STAR":h=document.createElement("div"),m="magicfeedback-rating-star";const x=function(e){const t="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container");for(let i=1;i<=5;i++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${i}`,n.type="radio",n.name=e,n.value=i.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let a=0;a<e.length;a++)a+1<=Number(n.value)?e[a].classList.contains(t)||e[a].classList.add(t):e[a].classList.contains(t)&&e[a].classList.remove(t)})),s.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${i}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",s.appendChild(o),a.appendChild(s)}return a}(c);h.appendChild(x);break;case"MULTIPLECHOISE_IMAGE":h=document.createElement("div"),m="magicfeedback-multiple-choice-image";const L=document.createElement("div");L.classList.add("magicfeedback-multiple-choice-image-container"),L.style.display="flex",L.style.flexDirection="row",L.style.flexWrap="wrap",L.style.justifyContent="center";const S=l.length;let O=1,I=1;switch(S){case 1:case 2:case 3:O=S,I=1;break;case 4:case 5:case 6:I=2,O=Math.ceil(S/2);break;default:I=3,O=Math.ceil(S/3)}const $=void 0!==p.addTitle&&p.addTitle;l.forEach((e=>{try{const{position:t,url:a,value:i}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/O}% - 10px)`,s.style.height=`calc( ${100/I}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=i,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${c}-${t}`,r.type="radio",r.name=c,r.value=i,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=a,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",n.appendChild(r),n.appendChild(d),$&&n.appendChild(o),s.appendChild(n),L.appendChild(s)}catch(e){console.error(e)}})),h.appendChild(L);break;case"SELECT":h=document.createElement("select"),m="magicfeedback-select";const N=document.createElement("option");N.value="",N.text="slim"===t?s(o,a):u||"Select an option",N.disabled=!0,N.selected=!0,h.appendChild(N),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,h.appendChild(t)}));break;case"DATE":h=document.createElement("input"),h.type="date",h.required=d,h.placeholder="slim"===t?s(o,a):`${p.placeholder||i.placeholder.date(a||"en")}`,m="magicfeedback-date";break;case"CONSENT":h=document.createElement("input"),m="magicfeedback-consent",h.type="checkbox",h.id=`magicfeedback-${n}`,h.name=c,h.value="true",h.required=d,h.classList.add("magicfeedback-consent"),h.classList.add("magicfeedback-input");break;case"EMAIL":h=document.createElement("input"),h.type="email",h.required=d,h.placeholder="slim"===t?s(o,a):`${p.placeholder||"you@example.com"}`,m="magicfeedback-email";break;case"PASSWORD":h=document.createElement("input"),h.type="password",h.required=d,h.placeholder="slim"===t?s(o,a):`${p.placeholder||i.placeholder.password(a||"en")}`,m="magicfeedback-password";break;default:return f}h.id=`magicfeedback-${n}`,h.setAttribute("name",c),h.classList.add(m),void 0!==u&&(h.value=u),["RADIO","MULTIPLECHOICE"].includes(r)||(h.classList.add("magicfeedback-input"),h.required=d);const g=document.createElement("label");if(g.setAttribute("for",`magicfeedback-${n}`),g.textContent=s(o,a),g.classList.add("magicfeedback-label"),["CONSENT"].includes(r))f.classList.add("magicfeedback-consent-container"),f.appendChild(h),f.appendChild(g);else{if("slim"!==t&&(f.appendChild(g),void 0!==(null==p?void 0:p.general)&&""!==(null==p?void 0:p.general))){const e=document.createElement("img");e.src=p.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",f.appendChild(e)}f.appendChild(h)}return f}(t,a,n);o.push(e)}})),o},t.renderActions=function(e="",t,a="Submit",i="Back",s="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?s||"Next":a||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=i||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(r),n.appendChild(o),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,a=!1,i="Go!"){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.textContent=e;const o=document.createElement("button");return o.id="magicfeedback-start-message-button",o.classList.add("magicfeedback-start-message-button"),o.textContent=i,o.addEventListener("click",(()=>t())),s.appendChild(n),a&&s.appendChild(o),s}},341:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=s(a(31)),o=s(a(147)),r=a(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,a,s){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,a),{method:"GET",headers:c});if(i.ok){const e=yield i.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,i.status,i.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,a,s){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.app(t,a),{method:"GET",headers:c});if(i.ok){const e=yield i.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,i.status,i.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,a){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(i.ok)return a.log(`Form ${t.integration} submitted successfully!`),(yield i.json()).sessionId;throw a.err(`Failed to submit form ${t.integration}:`,i.status,i.statusText),new Error(i.statusText)}catch(e){return a.err(e),""}}))},t.getFollowUpQuestion=function(e,t,a){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(i.ok)return a.log(`Received follow up question for form ${t.integration}`),(yield i.json())||"";throw a.err(`Failed to get follow up question for form ${t.integration}:`,i.status,i.statusText),new Error(i.statusText)}catch(e){return a.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.3","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},a=function a(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,a),n.exports}(607);return a.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,a){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(a(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=a(954),n=a(712),o=a(5),r=a(341),c=a(290);t.default=function(){const e=new n.Config;let t;return{init:function(a){(null==a?void 0:a.debug)&&e.set("debug",null==a?void 0:a.debug),e.set("url",(null==a?void 0:a.env)&&"dev"===(null==a?void 0:a.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(a,s,n,o=!0,c,d){return i(this,void 0,void 0,(function*(){a||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const i=e.get("url"),l={integration:a,publicKey:s,privateKey:d,completed:o,id:c,feedback:n};try{const e=yield(0,r.sendFeedback)(i,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(a,i){return a||t.err("No appID provided"),i||t.err("No publicKey provided"),new s.Form(e,a,i)}}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=a(5),n=a(341),o=a(183);t.Form=class{constructor(e,t,a){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=a,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var a;return i(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,a,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(a=this.formData)||void 0===a?void 0:a.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,a;try{this.questions.sort(((e,t)=>e.position-t.position));let i=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),i.appendChild(s),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),a=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(a)}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,a){var s;return i(this,void 0,void 0,(function*(){const i=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{a&&(this.feedback.profile=[...this.feedback.profile,...a]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));o&&(this.id=o,yield this.processNextQuestion(i,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let a=!1;const i=e.querySelectorAll(".magicfeedback-input");console.log(i),i.forEach((e=>{console.log(e);const i=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(i){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===i){if(!(0,n.validateEmail)(r)){this.log.err("Invalid email"),a=!0;break}this.feedback.profile.push({key:"email",value:[r]})}o.value.push(r);const e=t.findIndex((e=>e.key===o.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}}})),this.feedback.answers=a?[]:t}pushAnswers(e=!1){var t,a;return i(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(a=this.questionInProcess)||void 0===a?void 0:a.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(i,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return i(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),a={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,a,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var a,s,n,r;return i(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(a=this.formData)||void 0===a?void 0:a.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const a=yield this.callFollowUpQuestion(this.questionInProcess);if(a){this.questionInProcess=a;const e=(0,o.renderQuestions)([a],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:a,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,a)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const i=a(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,a="standard",n="en",o){if(!t)throw new Error("[MagicFeedback] No questions provided");const r=[];return t.forEach((t=>{var c,d;if((null===(d=null===(c=null==t?void 0:t.questionType)||void 0===c?void 0:c.conf)||void 0===d?void 0:d.length)>0){let i=document.createElement("div");i.classList.add("magicfeedback-div"),console.log(t),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,a,n,o).forEach((e=>{i.appendChild(e)})),r.push(i)}else{const e=function(e,t,a,n){const{id:o,title:r,type:c,ref:d,require:l,value:u,defaultValue:p,assets:h}=e;let m,f,g=document.createElement("div");switch(g.classList.add("magicfeedback-div"),c){case"TEXT":m=document.createElement("input"),m.type="text",m.placeholder="slim"===t?s(r,a):`${h.placeholder||i.placeholder.answer(a||"en")}`,f="magicfeedback-text";break;case"LONGTEXT":m=document.createElement("textarea"),m.rows=3,m.maxLength=300,m.placeholder="slim"===t?s(r,a):i.placeholder.answer(a||"en"),f="magicfeedback-longtext";break;case"NUMBER":m=document.createElement("input"),m.type="number",m.placeholder="slim"===t?s(r,a):`${h.placeholder||i.placeholder.number(a||"en")}`,f="magicfeedback-number",u.length&&(u.sort(((e,t)=>Number(e)-Number(t))),m.max=u[u.length-1],m.min=u[0],m.value=u[0]);break;case"RADIO":case"MULTIPLECHOICE":m=document.createElement("div"),f="magicfeedback-"+("MULTIPLECHOICE"===c?"checkbox":"radio"),h.extraOption&&u.push(h.extraOptionText),u.forEach(((e,t)=>{const a=document.createElement("div");a.classList.add(`magicfeedback-${"MULTIPLECHOICE"===c?"checkbox":"radio"}-container`);const i=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${d}-${t}`,s.type="MULTIPLECHOICE"===c?"checkbox":"radio",s.name=d,s.value=e,s.classList.add(f),s.classList.add("magicfeedback-input"),e===p&&(s.checked=!0),i.textContent=e,i.htmlFor=`rating-${d}-${t}`,h.extraOption&&e===h.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${d}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),a.appendChild(s),a.appendChild(i),m.appendChild(a),h.extraOption&&e===h.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${d}`,e.name=`extra-option-${d}`,e.style.display="none",m.appendChild(e)}}));break;case"BOOLEAN":m=document.createElement("div"),f="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(a)).forEach(((t,a)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${d}-${a}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${d}-${a}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${d}-${a}`,n.type="radio",n.name=d,n.value=t,n.classList.add(f),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",i.appendChild(n),i.appendChild(s),e.appendChild(i)})),m.appendChild(e);break;case"RATING_EMOJI":m=document.createElement("div"),f="magicfeedback-rating";const n=document.createElement("div");n.classList.add("magicfeedback-rating-container");const b=h.max?Number(h.max):5,v=h.min?Number(h.min):1,k=document.createElement("div");if(k.classList.add("magicfeedback-rating-placeholder"),k.style.display="flex",k.style.justifyContent="space-between",k.style.width="90%",k.style.margin="auto",h.minPlaceholder){const e=document.createElement("span");e.textContent=h.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",k.appendChild(e)}if(h.maxPlaceholder){const e=document.createElement("span");e.textContent=h.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",k.appendChild(e)}for(let e=v;e<=b;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const a=document.createElement("label");a.htmlFor=`rating-${d}-${e}`,a.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${d}-${e}`,i.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${d}-${e}`,s.className=`rating-image${e}`,0===v&&10===b)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===v&&5===b)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(b-v)*(e-v));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const o=document.createElement("input");o.id=`rating-${d}-${e}`,o.type="radio",o.name=d,o.value=e.toString(),o.classList.add(f),o.classList.add("magicfeedback-input"),a.appendChild(o),a.appendChild(s),a.appendChild(i),t.appendChild(a),n.appendChild(t)}if(h.extraOption&&h.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${d}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${d}-extra`,a.textContent=h.extraOptionText;const i=document.createElement("img");i.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",i.alt=`face-${d}-extra`,i.className="magicfeedback-rating-image-extra";const s=document.createElement("input");s.id=`rating-${d}-extra`,s.type="radio",s.name=d,s.value="-",s.classList.add(f),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(i),t.appendChild(a),e.appendChild(t),n.appendChild(e)}m.appendChild(k),m.appendChild(n);break;case"RATING_NUMBER":m=document.createElement("div"),f="magicfeedback-rating-number";const y=document.createElement("div");y.classList.add("magicfeedback-rating-number-container");const E=h.max?Number(h.max):5,C=h.min?Number(h.min):1,x=document.createElement("div");if(x.classList.add("magicfeedback-rating-number-placeholder"),x.style.display="flex",x.style.justifyContent="space-between",x.style.width="90%",x.style.margin="auto",h.minPlaceholder){const e=document.createElement("span");e.textContent=h.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}if(h.maxPlaceholder){const e=document.createElement("span");e.textContent=h.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",x.appendChild(e)}for(let e=C;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");a.htmlFor=`rating-${d}-${e}`,a.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${d}-${e}`,i.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${d}-${e}`,s.type="radio",s.name=d,s.value=e.toString(),s.classList.add(f),s.classList.add("magicfeedback-input"),a.appendChild(s),a.appendChild(i),t.appendChild(a),y.appendChild(t)}if(h.extraOption&&h.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${d}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${d}-extra`,a.textContent=h.extraOptionText;const i=document.createElement("input");i.id=`rating-${d}-extra`,i.type="radio",i.name=d,i.value="-",i.classList.add(f),i.classList.add("magicfeedback-input"),t.appendChild(i),t.appendChild(a),e.appendChild(t),y.appendChild(e)}m.appendChild(x),m.appendChild(y);break;case"RATING_STAR":m=document.createElement("div"),f="magicfeedback-rating-star";const w=function(e){const t="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container");for(let i=1;i<=5;i++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${i}`,n.type="radio",n.name=e,n.value=i.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let a=0;a<e.length;a++)a+1<=Number(n.value)?e[a].classList.contains(t)||e[a].classList.add(t):e[a].classList.contains(t)&&e[a].classList.remove(t)})),s.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${i}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",s.appendChild(o),a.appendChild(s)}return a}(d);m.appendChild(w);break;case"MULTIPLECHOISE_IMAGE":m=document.createElement("div"),f="magicfeedback-multiple-choice-image";const L=document.createElement("div");L.classList.add("magicfeedback-multiple-choice-image-container"),L.style.display="flex",L.style.flexDirection="row",L.style.flexWrap="wrap",L.style.justifyContent="center";const S=u.length;let O=1,I=1;switch(S){case 1:case 2:case 3:O=S,I=1;break;case 4:case 5:case 6:I=2,O=Math.ceil(S/2);break;default:I=3,O=Math.ceil(S/3)}const $=void 0!==h.addTitle&&h.addTitle;u.forEach((e=>{try{const{position:t,url:a,value:i}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/O}% - 10px)`,s.style.height=`calc( ${100/I}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${d}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=i,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${d}-${t}`,r.type="radio",r.name=d,r.value=i,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=a,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.width="100%",c.style.height="100%",c.style.margin="auto",n.appendChild(r),n.appendChild(c),$&&n.appendChild(o),s.appendChild(n),L.appendChild(s)}catch(e){console.error(e)}})),m.appendChild(L);break;case"SELECT":m=document.createElement("select"),f="magicfeedback-select";const N=document.createElement("option");N.value="",N.text="slim"===t?s(r,a):p||"Select an option",N.disabled=!0,N.selected=!0,m.appendChild(N),u.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,m.appendChild(t)}));break;case"DATE":m=document.createElement("input"),m.type="date",m.required=l,m.placeholder="slim"===t?s(r,a):`${h.placeholder||i.placeholder.date(a||"en")}`,f="magicfeedback-date";break;case"CONSENT":m=document.createElement("input"),f="magicfeedback-consent",m.type="checkbox",m.id=`magicfeedback-${o}`,m.name=d,m.value="true",m.required=l,m.classList.add("magicfeedback-consent"),m.classList.add("magicfeedback-input");break;case"EMAIL":m=document.createElement("input"),m.type="email",m.required=l,m.placeholder="slim"===t?s(r,a):`${h.placeholder||"you@example.com"}`,f="magicfeedback-email";break;case"PASSWORD":m=document.createElement("input"),m.type="password",m.required=l,m.placeholder="slim"===t?s(r,a):`${h.placeholder||i.placeholder.password(a||"en")}`,f="magicfeedback-password";break;default:return g}m.id=`magicfeedback-${o}`,m.setAttribute("name",d),m.classList.add(f),void 0!==p&&(m.value=p),["RADIO","MULTIPLECHOICE"].includes(c)||(m.classList.add("magicfeedback-input"),m.required=l);const b=document.createElement("label");if(b.setAttribute("for",`magicfeedback-${o}`),b.textContent=s(r,a),b.classList.add("magicfeedback-label"),["CONSENT"].includes(c))g.classList.add("magicfeedback-consent-container"),g.appendChild(m),g.appendChild(b);else{if("slim"!==t&&(g.appendChild(b),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",g.appendChild(e)}if("LONGTEXT"===c){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",m.addEventListener("input",(()=>{e.textContent=`${m.value.length}/300`})),g.appendChild(m),g.appendChild(e),h.extraOption&&h.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.style.display="flex",e.style.justifyContent="space-between";const t=document.createElement("button");t.textContent=h.extraOptionText,t.classList.add("magicfeedback-skip"),t.style.cursor="pointer",t.type="button",t.addEventListener("click",(()=>{m.value="-",n&&n()})),e.appendChild(t),g.appendChild(e)}}else g.appendChild(m)}return g}(t,a,n,o);r.push(e)}})),r},t.renderActions=function(e="",t,a="Submit",i="Back",s="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?s||"Next":a||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=i||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(r),n.appendChild(o),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,a=!1,i="Go!"){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.textContent=e;const o=document.createElement("button");return o.id="magicfeedback-start-message-button",o.classList.add("magicfeedback-start-message-button"),o.textContent=i,o.addEventListener("click",(()=>t())),s.appendChild(n),a&&s.appendChild(o),s}},341:function(e,t,a){var i=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))((function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function r(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,r)}c((i=i.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=s(a(31)),o=s(a(147)),r=a(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,a,s){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,a),{method:"GET",headers:c});if(i.ok){const e=yield i.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,i.status,i.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,a,s){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.app(t,a),{method:"GET",headers:c});if(i.ok){const e=yield i.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,i.status,i.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,a){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(i.ok)return a.log(`Form ${t.integration} submitted successfully!`),(yield i.json()).sessionId;throw a.err(`Failed to submit form ${t.integration}:`,i.status,i.statusText),new Error(i.statusText)}catch(e){return a.err(e),""}}))},t.getFollowUpQuestion=function(e,t,a){return i(this,void 0,void 0,(function*(){try{const i=yield(0,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(i.ok)return a.log(`Received follow up question for form ${t.integration}`),(yield i.json())||"";throw a.err(`Failed to get follow up question for form ${t.integration}:`,i.status,i.statusText),new Error(i.statusText)}catch(e){return a.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.4","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},a=function a(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,a),n.exports}(607);return a.default})()));
@@ -1,5 +1,5 @@
1
1
  import { NativeQuestion } from "../models/types";
2
- export declare function renderQuestions(appQuestions: NativeQuestion[], format?: string, language?: string): HTMLElement[];
2
+ export declare function renderQuestions(appQuestions: NativeQuestion[], format?: string, language?: string, send?: () => void): HTMLElement[];
3
3
  export declare function renderActions(identity: string | undefined, backAction: () => void, sendButtonText?: string, backButtonText?: string, nextButtonText?: string): HTMLElement;
4
4
  export declare function renderError(error: string): HTMLElement;
5
5
  export declare function renderSuccess(success: string): HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "1.2.5-beta.3",
3
+ "version": "1.2.5-beta.4",
4
4
  "main": "./dist/magicfeedback-sdk.node.js",
5
5
  "browser": "./dist/magicfeedback-sdk.browser.js",
6
6
  "types": "./dist/types/src/index.d.ts",