site-libsoc/Server/public/js/components/auth-component.js

230 lines
7.3 KiB
JavaScript

(function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
import { S as SvelteElement, i as init, a as attribute_to_object, b as insert_dev, s as safe_not_equal, d as dispatch_dev, v as validate_slots, c as setContext, o as onMount, g as getContext, e as globals, f as element, h as space, n as noop, j as add_location, k as attr_dev, l as append_dev, m as listen_dev, p as detach_dev, r as run_all, q as binding_callbacks } from './index-998178c7.js';
import { sendText } from '../../../../../../../../../js/libraries/serverTools.js';
import * as AuthTools from '../../../../../../../../../js/libraries/authTools.js';
import '../../../../../../../../../js/components/login-component.js';
import '../../../../../../../../../js/components/signup-component.js';
/* src\auth\auth-component.svelte generated by Svelte v3.52.0 */
const { console: console_1 } = globals;
const file = "src\\auth\\auth-component.svelte";
function create_fragment(ctx) {
let div2;
let div0;
let login_component;
let t0;
let signup_component;
let t1;
let div1;
let span;
let mounted;
let dispose;
const block = {
c: function create() {
div2 = element("div");
div0 = element("div");
login_component = element("login-component");
t0 = space();
signup_component = element("signup-component");
t1 = space();
div1 = element("div");
span = element("span");
span.textContent = "OR";
this.c = noop;
add_location(login_component, file, 59, 8, 1652);
add_location(signup_component, file, 60, 8, 1791);
attr_dev(div0, "id", "auth-grid-group");
add_location(div0, file, 58, 4, 1616);
add_location(span, file, 63, 8, 1983);
attr_dev(div1, "id", "auth-or");
attr_dev(div1, "class", "pane");
add_location(div1, file, 62, 4, 1942);
attr_dev(div2, "id", "auth-group");
add_location(div2, file, 57, 0, 1589);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
insert_dev(target, div2, anchor);
append_dev(div2, div0);
append_dev(div0, login_component);
/*login_component_binding*/ ctx[3](login_component);
append_dev(div0, t0);
append_dev(div0, signup_component);
/*signup_component_binding*/ ctx[5](signup_component);
append_dev(div2, t1);
append_dev(div2, div1);
append_dev(div1, span);
if (!mounted) {
dispose = [
listen_dev(login_component, "click", /*click_handler*/ ctx[4], false, false, false),
listen_dev(login_component, "keydown", keydown_handler, false, false, false),
listen_dev(signup_component, "click", /*click_handler_1*/ ctx[6], false, false, false),
listen_dev(signup_component, "keydown", keydown_handler_1, false, false, false)
];
mounted = true;
}
},
p: noop,
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) detach_dev(div2);
/*login_component_binding*/ ctx[3](null);
/*signup_component_binding*/ ctx[5](null);
mounted = false;
run_all(dispose);
}
};
dispatch_dev("SvelteRegisterBlock", {
block,
id: create_fragment.name,
type: "component",
source: "",
ctx
});
return block;
}
const keydown_handler = () => "";
const keydown_handler_1 = () => "";
function instance($$self, $$props, $$invalidate) {
let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('auth-component', slots, []);
AuthTools.redirectLogged();
let loginComponent;
let signupComponent;
let context = { googleInit: false };
setContext("auth", context);
function switchFocus(component) {
if (component == loginComponent) {
$$invalidate(0, loginComponent.focused = true, loginComponent);
$$invalidate(1, signupComponent.focused = false, signupComponent);
} else {
$$invalidate(0, loginComponent.focused = false, loginComponent);
$$invalidate(1, signupComponent.focused = true, signupComponent);
}
}
function callbackGoogle(data) {
console.log(data);
sendText("/signup-google", data.credential, response => AuthTools.processLoginResponse(response, context.msgs, context.remember.checked));
}
function initGoogle() {
if (typeof google != 'undefined') {
google.accounts.id.initialize({
client_id: '93612176787-sr8qjqem4e3kok4msrnj8s1illt85a9g.apps.googleusercontent.com',
callback: callbackGoogle,
auto_select: true,
context: "signin"
});
context.googleInit = true;
} else {
setTimeout(initGoogle, 100);
}
}
initGoogle();
const writable_props = [];
Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console_1.warn(`<auth-component> was created with unknown prop '${key}'`);
});
function login_component_binding($$value) {
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
loginComponent = $$value;
$$invalidate(0, loginComponent);
});
}
const click_handler = () => switchFocus(loginComponent);
function signup_component_binding($$value) {
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
signupComponent = $$value;
$$invalidate(1, signupComponent);
});
}
const click_handler_1 = () => switchFocus(signupComponent);
$$self.$capture_state = () => ({
onMount,
setContext,
getContext,
sendText,
AuthTools,
loginComponent,
signupComponent,
context,
switchFocus,
callbackGoogle,
initGoogle
});
$$self.$inject_state = $$props => {
if ('loginComponent' in $$props) $$invalidate(0, loginComponent = $$props.loginComponent);
if ('signupComponent' in $$props) $$invalidate(1, signupComponent = $$props.signupComponent);
if ('context' in $$props) context = $$props.context;
};
if ($$props && "$$inject" in $$props) {
$$self.$inject_state($$props.$$inject);
}
return [
loginComponent,
signupComponent,
switchFocus,
login_component_binding,
click_handler,
signup_component_binding,
click_handler_1
];
}
class Auth_component extends SvelteElement {
constructor(options) {
super();
this.shadowRoot.innerHTML = `<style>@import '/css/common.css';span{font-size:1.4rem;font-family:var(--sans-serif,sans-serif)}#auth-group{margin:auto;width:auto;margin-bottom:3rem}#auth-grid-group{display:grid;grid-template-columns:30rem 30rem;justify-content:center;gap:1.37rem;width:100%}#auth-or{display:flex;position:absolute;margin:auto;top:40%;left:50%;transform:translate(-50%, -50%);width:5.4rem;height:5.4rem;border-radius:6.8rem;background-color:white;align-items:center;justify-content:center;font-family:var(--sans-serif,sans-serif);font-weight:500}@media only screen and (max-width: 1200px){#auth-grid-group{display:grid;grid-template-columns:30rem;grid-template-rows:auto auto;justify-content:center;gap:1.37rem;width:100%}#auth-or{top:46.4rem}#auth-group{margin-top:2rem;margin-bottom:3rem}}</style>`;
init(
this,
{
target: this.shadowRoot,
props: attribute_to_object(this.attributes),
customElement: true
},
instance,
create_fragment,
safe_not_equal,
{},
null
);
if (options) {
if (options.target) {
insert_dev(options.target, this, options.anchor);
}
}
}
}
customElements.define("auth-component", Auth_component);
export { Auth_component as default };