seerbit-svelte
Version:
Seerbit Svelte SDK
493 lines (474 loc) • 14.1 kB
JavaScript
function noop() { }
function assign(tar, src) {
// @ts-ignore
for (const k in src)
tar[k] = src[k];
return tar;
}
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function append(target, node) {
target.appendChild(node);
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
node.parentNode.removeChild(node);
}
function element(name) {
return document.createElement(name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(' ');
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function set_attributes(node, attributes) {
// @ts-ignore
const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
for (const key in attributes) {
if (attributes[key] == null) {
node.removeAttribute(key);
}
else if (key === 'style') {
node.style.cssText = attributes[key];
}
else if (descriptors[key] && descriptors[key].set) {
node[key] = attributes[key];
}
else {
attr(node, key, attributes[key]);
}
}
}
function children(element) {
return Array.from(element.childNodes);
}
function set_data(text, data) {
data = '' + data;
if (text.data !== data)
text.data = data;
}
function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
}
let current_component;
function set_current_component(component) {
current_component = component;
}
const dirty_components = [];
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
let flushing = false;
const seen_callbacks = new Set();
function flush() {
if (flushing)
return;
flushing = true;
do {
// first, call beforeUpdate functions
// and update components
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
update(component.$$);
}
dirty_components.length = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
flushing = false;
seen_callbacks.clear();
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
const outroing = new Set();
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function get_spread_update(levels, updates) {
const update = {};
const to_null_out = {};
const accounted_for = { $$scope: 1 };
let i = levels.length;
while (i--) {
const o = levels[i];
const n = updates[i];
if (n) {
for (const key in o) {
if (!(key in n))
to_null_out[key] = 1;
}
for (const key in n) {
if (!accounted_for[key]) {
update[key] = n[key];
accounted_for[key] = 1;
}
}
levels[i] = n;
}
else {
for (const key in o) {
accounted_for[key] = 1;
}
}
}
for (const key in to_null_out) {
if (!(key in update))
update[key] = undefined;
}
return update;
}
function mount_component(component, target, anchor) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = on_mount.map(run).filter(is_function);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const prop_values = options.props || {};
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : []),
// everything else
callbacks: blank_object(),
dirty
};
let ready = false;
$$.ctx = instance
? instance(component, prop_values, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if ($$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
})
: [];
$$.update();
ready = true;
run_all($$.before_update);
// `false` as a special case of no DOM component
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(children(options.target));
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor);
flush();
}
set_current_component(parent_component);
}
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set() {
// overridden by instance, if it has props
}
}
/* src/lib/seerbitSvelte.svelte generated by Svelte v3.18.2 */
function add_css() {
var style = element("style");
style.id = "svelte-6yttu-style";
style.textContent = ".btn-seerbit-checkout.svelte-6yttu{cursor:pointer;transition:background-color 0.3s ease}";
append(document.head, style);
}
function create_fragment(ctx) {
let script;
let script_src_value;
let t0;
let body;
let button;
let t1;
let dispose;
let button_levels = [{ class: "btn-seerbit-checkout" }, /*buttonStyle*/ ctx[1]];
let button_data = {};
for (let i = 0; i < button_levels.length; i += 1) {
button_data = assign(button_data, button_levels[i]);
}
return {
c() {
script = element("script");
t0 = space();
body = element("body");
button = element("button");
t1 = text(/*buttonText*/ ctx[0]);
document.title = "SeerBit Checkout";
if (script.src !== (script_src_value = "https://checkout.seerbitapi.com/api/v2/seerbit.js")) attr(script, "src", script_src_value);
set_attributes(button, button_data);
toggle_class(button, "svelte-6yttu", true);
},
m(target, anchor) {
append(document.head, script);
insert(target, t0, anchor);
insert(target, body, anchor);
append(body, button);
append(button, t1);
dispose = listen(button, "click", /*paywithSeerbit*/ ctx[2]);
},
p(ctx, [dirty]) {
if (dirty & /*buttonText*/ 1) set_data(t1, /*buttonText*/ ctx[0]);
set_attributes(button, get_spread_update(button_levels, [
{ class: "btn-seerbit-checkout" },
dirty & /*buttonStyle*/ 2 && /*buttonStyle*/ ctx[1]
]));
toggle_class(button, "svelte-6yttu", true);
},
i: noop,
o: noop,
d(detaching) {
detach(script);
if (detaching) detach(t0);
if (detaching) detach(body);
dispose();
}
};
}
function instance($$self, $$props, $$invalidate) {
let { public_key } = $$props;
let { tranref } = $$props;
let { currency } = $$props;
let { country } = $$props;
let { amount } = $$props;
let { email } = $$props;
let { mobile_no } = $$props;
let { productId } = $$props;
let { description } = $$props;
let { setAmountByCustomer } = $$props;
let { full_name } = $$props;
let { tokenize } = $$props;
let { planId } = $$props;
let { pocketReference } = $$props;
let { vendorId } = $$props;
let { customization } = $$props;
let { buttonText } = $$props;
let { buttonStyle } = $$props;
let { onSuccess } = $$props;
let { close } = $$props;
function paywithSeerbit() {
SeerbitPay(
{
public_key,
tranref,
currency,
country,
amount,
email,
mobile_no,
productId,
description,
setAmountByCustomer,
full_name,
tokenize,
planId,
pocketReference,
vendorId,
customization
},
onSuccess,
close
);
}
$$self.$set = $$props => {
if ("public_key" in $$props) $$invalidate(3, public_key = $$props.public_key);
if ("tranref" in $$props) $$invalidate(4, tranref = $$props.tranref);
if ("currency" in $$props) $$invalidate(5, currency = $$props.currency);
if ("country" in $$props) $$invalidate(6, country = $$props.country);
if ("amount" in $$props) $$invalidate(7, amount = $$props.amount);
if ("email" in $$props) $$invalidate(8, email = $$props.email);
if ("mobile_no" in $$props) $$invalidate(9, mobile_no = $$props.mobile_no);
if ("productId" in $$props) $$invalidate(10, productId = $$props.productId);
if ("description" in $$props) $$invalidate(11, description = $$props.description);
if ("setAmountByCustomer" in $$props) $$invalidate(12, setAmountByCustomer = $$props.setAmountByCustomer);
if ("full_name" in $$props) $$invalidate(13, full_name = $$props.full_name);
if ("tokenize" in $$props) $$invalidate(14, tokenize = $$props.tokenize);
if ("planId" in $$props) $$invalidate(15, planId = $$props.planId);
if ("pocketReference" in $$props) $$invalidate(16, pocketReference = $$props.pocketReference);
if ("vendorId" in $$props) $$invalidate(17, vendorId = $$props.vendorId);
if ("customization" in $$props) $$invalidate(18, customization = $$props.customization);
if ("buttonText" in $$props) $$invalidate(0, buttonText = $$props.buttonText);
if ("buttonStyle" in $$props) $$invalidate(1, buttonStyle = $$props.buttonStyle);
if ("onSuccess" in $$props) $$invalidate(19, onSuccess = $$props.onSuccess);
if ("close" in $$props) $$invalidate(20, close = $$props.close);
};
return [
buttonText,
buttonStyle,
paywithSeerbit,
public_key,
tranref,
currency,
country,
amount,
email,
mobile_no,
productId,
description,
setAmountByCustomer,
full_name,
tokenize,
planId,
pocketReference,
vendorId,
customization,
onSuccess,
close
];
}
class SeerbitSvelte extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-6yttu-style")) add_css();
init(this, options, instance, create_fragment, safe_not_equal, {
public_key: 3,
tranref: 4,
currency: 5,
country: 6,
amount: 7,
email: 8,
mobile_no: 9,
productId: 10,
description: 11,
setAmountByCustomer: 12,
full_name: 13,
tokenize: 14,
planId: 15,
pocketReference: 16,
vendorId: 17,
customization: 18,
buttonText: 0,
buttonStyle: 1,
onSuccess: 19,
close: 20
});
}
}
export default SeerbitSvelte;