Skip to content

Commit

Permalink
Migrate to Svelte v2
Browse files Browse the repository at this point in the history
  • Loading branch information
joshnuss committed Apr 3, 2024
1 parent 2375ab8 commit 2da4bd7
Show file tree
Hide file tree
Showing 150 changed files with 7,010 additions and 3 deletions.
19 changes: 19 additions & 0 deletions .vercel/output/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": 3,
"routes": [
{
"src": "/_app/immutable/.+",
"headers": {
"cache-control": "public, immutable, max-age=31536000"
}
},
{
"handle": "filesystem"
},
{
"src": "/.*",
"dest": "/render"
}
],
"overrides": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { c as create_ssr_component, a as setContext } from "./index2.js";
import { r as register } from "./util.js";
const Elements = create_ssr_component(($$result, $$props, $$bindings, slots) => {
let appearance;
let { stripe } = $$props;
let { mode = void 0 } = $$props;
let { theme = "stripe" } = $$props;
let { variables = {} } = $$props;
let { rules = {} } = $$props;
let { labels = "above" } = $$props;
let { loader = "auto" } = $$props;
let { fonts = [] } = $$props;
let { locale = "auto" } = $$props;
let { currency = void 0 } = $$props;
let { amount = void 0 } = $$props;
let { clientSecret = void 0 } = $$props;
let { elements = null } = $$props;
if ($$props.stripe === void 0 && $$bindings.stripe && stripe !== void 0)
$$bindings.stripe(stripe);
if ($$props.mode === void 0 && $$bindings.mode && mode !== void 0)
$$bindings.mode(mode);
if ($$props.theme === void 0 && $$bindings.theme && theme !== void 0)
$$bindings.theme(theme);
if ($$props.variables === void 0 && $$bindings.variables && variables !== void 0)
$$bindings.variables(variables);
if ($$props.rules === void 0 && $$bindings.rules && rules !== void 0)
$$bindings.rules(rules);
if ($$props.labels === void 0 && $$bindings.labels && labels !== void 0)
$$bindings.labels(labels);
if ($$props.loader === void 0 && $$bindings.loader && loader !== void 0)
$$bindings.loader(loader);
if ($$props.fonts === void 0 && $$bindings.fonts && fonts !== void 0)
$$bindings.fonts(fonts);
if ($$props.locale === void 0 && $$bindings.locale && locale !== void 0)
$$bindings.locale(locale);
if ($$props.currency === void 0 && $$bindings.currency && currency !== void 0)
$$bindings.currency(currency);
if ($$props.amount === void 0 && $$bindings.amount && amount !== void 0)
$$bindings.amount(amount);
if ($$props.clientSecret === void 0 && $$bindings.clientSecret && clientSecret !== void 0)
$$bindings.clientSecret(clientSecret);
if ($$props.elements === void 0 && $$bindings.elements && elements !== void 0)
$$bindings.elements(elements);
appearance = { theme, variables, rules, labels };
{
if (stripe && !elements) {
elements = stripe.elements({
mode,
currency,
amount,
appearance,
clientSecret,
fonts,
loader,
locale
});
register(stripe);
setContext("stripe", { stripe, elements });
}
}
{
if (elements) {
elements.update({ appearance, locale });
}
}
return `${stripe && elements ? `${slots.default ? slots.default({}) : ``}` : ``}`;
});
export {
Elements as E
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
class HttpError {
/**
* @param {number} status
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
*/
constructor(status, body) {
this.status = status;
if (typeof body === "string") {
this.body = { message: body };
} else if (body) {
this.body = body;
} else {
this.body = { message: `Error: ${status}` };
}
}
toString() {
return JSON.stringify(this.body);
}
}
class Redirect {
/**
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
* @param {string} location
*/
constructor(status, location) {
this.status = status;
this.location = location;
}
}
class ActionFailure {
/**
* @param {number} status
* @param {T} [data]
*/
constructor(status, data) {
this.status = status;
this.data = data;
}
}
function error(status, body) {
if (isNaN(status) || status < 400 || status > 599) {
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
}
return new HttpError(status, body);
}
function redirect(status, location) {
if (isNaN(status) || status < 300 || status > 308) {
throw new Error("Invalid status code");
}
return new Redirect(status, location.toString());
}
function json(data, init) {
const body = JSON.stringify(data);
const headers = new Headers(init?.headers);
if (!headers.has("content-length")) {
headers.set("content-length", encoder.encode(body).byteLength.toString());
}
if (!headers.has("content-type")) {
headers.set("content-type", "application/json");
}
return new Response(body, {
...init,
headers
});
}
const encoder = new TextEncoder();
function text(body, init) {
const headers = new Headers(init?.headers);
if (!headers.has("content-length")) {
const encoded = encoder.encode(body);
headers.set("content-length", encoded.byteLength.toString());
return new Response(encoded, {
...init,
headers
});
}
return new Response(body, {
...init,
headers
});
}
export {
ActionFailure as A,
HttpError as H,
Redirect as R,
error as e,
json as j,
redirect as r,
text as t
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
function noop() {
}
function run(fn) {
return fn();
}
function blank_object() {
return /* @__PURE__ */ Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function");
}
function subscribe(store, ...callbacks) {
if (store == null) {
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
const e = document.createEvent("CustomEvent");
e.initCustomEvent(type, bubbles, cancelable, detail);
return e;
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error("Function called outside component initialization");
return current_component;
}
function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}
function createEventDispatcher() {
const component = get_current_component();
return (type, detail, { cancelable = false } = {}) => {
const callbacks = component.$$.callbacks[type];
if (callbacks) {
const event = custom_event(type, detail, { cancelable });
callbacks.slice().forEach((fn) => {
fn.call(component, event);
});
return !event.defaultPrevented;
}
return true;
};
}
function setContext(key, context) {
get_current_component().$$.context.set(key, context);
return context;
}
function getContext(key) {
return get_current_component().$$.context.get(key);
}
const ATTR_REGEX = /[&"]/g;
const CONTENT_REGEX = /[&<]/g;
function escape(value, is_attr = false) {
const str = String(value);
const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
pattern.lastIndex = 0;
let escaped = "";
let last = 0;
while (pattern.test(str)) {
const i = pattern.lastIndex - 1;
const ch = str[i];
escaped += str.substring(last, i) + (ch === "&" ? "&amp;" : ch === '"' ? "&quot;" : "&lt;");
last = i + 1;
}
return escaped + str.substring(last);
}
const missing_component = {
$$render: () => ""
};
function validate_component(component, name) {
if (!component || !component.$$render) {
if (name === "svelte:component")
name += " this={...}";
throw new Error(`<${name}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix a <${name}>.`);
}
return component;
}
let on_destroy;
function create_ssr_component(fn) {
function $$render(result, props, bindings, slots, context) {
const parent_component = current_component;
const $$ = {
on_destroy,
context: new Map(context || (parent_component ? parent_component.$$.context : [])),
// these will be immediately discarded
on_mount: [],
before_update: [],
after_update: [],
callbacks: blank_object()
};
set_current_component({ $$ });
const html = fn(result, props, bindings, slots);
set_current_component(parent_component);
return html;
}
return {
render: (props = {}, { $$slots = {}, context = /* @__PURE__ */ new Map() } = {}) => {
on_destroy = [];
const result = { title: "", head: "", css: /* @__PURE__ */ new Set() };
const html = $$render(result, props, {}, $$slots, context);
run_all(on_destroy);
return {
html,
css: {
code: Array.from(result.css).map((css) => css.code).join("\n"),
map: null
// TODO
},
head: result.title + result.head
};
},
$$render
};
}
function add_attribute(name, value, boolean) {
if (value == null || boolean && !value)
return "";
const assignment = boolean && value === true ? "" : `="${escape(value, true)}"`;
return ` ${name}${assignment}`;
}
export {
setContext as a,
subscribe as b,
create_ssr_component as c,
add_attribute as d,
escape as e,
createEventDispatcher as f,
getContext as g,
missing_component as m,
noop as n,
onDestroy as o,
safe_not_equal as s,
validate_component as v
};
Loading

0 comments on commit 2da4bd7

Please sign in to comment.