UNPKG

@malga-checkout/core

Version:
1 lines 2.13 kB
import{g as e,f as t}from"./p-626f6dad.js";const o=e=>!("isConnected"in e)||e.isConnected,n=(()=>{let e;return(...t)=>{e&&clearTimeout(e),e=setTimeout((()=>{e=0,(e=>{for(let t of e.keys())e.set(t,e.get(t).filter(o))})(...t)}),2e3)}})(),s=(o,s)=>{const r=((e,t=((e,t)=>e!==t))=>{let o=new Map(Object.entries(null!=e?e:{}));const n={dispose:[],get:[],set:[],reset:[]},s=()=>{o=new Map(Object.entries(null!=e?e:{})),n.reset.forEach((e=>e()))},r=e=>(n.get.forEach((t=>t(e))),o.get(e)),a=(e,s)=>{const r=o.get(e);t(s,r,e)&&(o.set(e,s),n.set.forEach((t=>t(e,s,r))))},c="undefined"==typeof Proxy?{}:new Proxy(e,{get:(e,t)=>r(t),ownKeys:()=>Array.from(o.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(e,t)=>o.has(t),set:(e,t,o)=>(a(t,o),!0)}),i=(e,t)=>(n[e].push(t),()=>{((e,t)=>{const o=e.indexOf(t);o>=0&&(e[o]=e[e.length-1],e.length--)})(n[e],t)});return{state:c,get:r,set:a,on:i,onChange:(t,o)=>{const n=i("set",((e,n)=>{e===t&&o(n)})),s=i("reset",(()=>o(e[t])));return()=>{n(),s()}},use:(...e)=>{const t=e.reduce(((e,t)=>(t.set&&e.push(i("set",t.set)),t.get&&e.push(i("get",t.get)),t.reset&&e.push(i("reset",t.reset)),t.dispose&&e.push(i("dispose",t.dispose)),e)),[]);return()=>t.forEach((e=>e()))},dispose:()=>{n.dispose.forEach((e=>e())),s()},reset:s,forceUpdate:e=>{const t=o.get(e);n.set.forEach((o=>o(e,t,t)))}}})(o,s);return r.use((()=>{if("function"!=typeof e)return{};const o=new Map;return{dispose:()=>o.clear(),get:t=>{const n=e();n&&((e,t,o)=>{const n=e.get(t);n?n.includes(o)||n.push(o):e.set(t,[o])})(o,t,n)},set:e=>{const s=o.get(e);s&&o.set(e,s.filter(t)),n(o)},reset:()=>{o.forEach((e=>e.forEach(t))),n(o)}}})()),r},{state:r}=s({clientId:"",publicKey:"",sessionId:"",merchantId:"",automaticallyGeneratedIdempotencyKey:!0,idempotencyKey:"",locale:void 0,sandbox:!1,debug:!1,dialogConfig:{show:!0},paymentMethods:{pix:void 0,credit:void 0,boleto:void 0,nupay:void 0,drip:void 0},transactionConfig:{statementDescriptor:"",amount:0,description:"",orderId:"",customerId:"",currency:"BRL",capture:!1,customer:null,paymentFlowMetadata:null,splitRules:null},appInfo:void 0});export{s as c,r as s}