arrowjs-aluminum 0.9.0

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 ADDED
@@ -0,0 +1 @@
1
+ # ArrowJS: Aluminum
@@ -0,0 +1,29 @@
1
+ /**
2
+ * An extendable object that can re brendered. In other frameworks, this would be your component
3
+ */
4
+ export default class ArrowElementGenerator {
5
+ readonly type: string;
6
+ protected readonly attributes: {
7
+ [attribute: string]: string | (() => string);
8
+ };
9
+ /**
10
+ * Creates an ArrowElement
11
+ * @param type The underlying type of this element: div, span, etc
12
+ * @param attributes The attributes on this element
13
+ */
14
+ constructor(type: string, attributes?: {
15
+ [attribute: string]: string | (() => string);
16
+ });
17
+ ["new"](contents: string | (() => string), attributes?: {
18
+ add?: {
19
+ [attribute: string]: string | (() => string);
20
+ };
21
+ replace?: {
22
+ [attribute: string]: string | (() => string);
23
+ };
24
+ transform?: {
25
+ [attribute: string]: (previousValue: (string | (() => string))) => string;
26
+ };
27
+ }): import("@arrow-js/core").ArrowTemplate;
28
+ }
29
+ //# sourceMappingURL=ArrowElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrowElement.d.ts","sourceRoot":"","sources":["../src/ArrowElement.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACtC,SAAgB,IAAI,SAAC;IACrB,SAAS,CAAC,QAAQ,CAAC,UAAU;6CAOuC,MAAM;MAP5C;IAE9B;;;;OAIG;gBACS,IAAI,EAAC,MAAM,EAAE,UAAU,GAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;KAAI;IAK/E,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAC,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,EAAE,UAAU,GAAC;QAC7C,GAAG,CAAC,EAAC;YAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;SAAC,CAAC;QAC9C,OAAO,CAAC,EAAC;YAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;SAAC,CAAC;QAClD,SAAS,CAAC,EAAC;YAAC,CAAC,SAAS,EAAC,MAAM,GAAE,CAAC,aAAa,EAAC,CAAC,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAC,KAAG,MAAM,CAAA;SAAC,CAAA;KAAI;CAgBxF"}
@@ -0,0 +1,30 @@
1
+ import { html } from "@arrow-js/core";
2
+ /**
3
+ * An extendable object that can re brendered. In other frameworks, this would be your component
4
+ */
5
+ export default class ArrowElementGenerator {
6
+ type;
7
+ attributes;
8
+ /**
9
+ * Creates an ArrowElement
10
+ * @param type The underlying type of this element: div, span, etc
11
+ * @param attributes The attributes on this element
12
+ */
13
+ constructor(type, attributes = {}) {
14
+ this.type = type;
15
+ this.attributes = attributes;
16
+ }
17
+ ["new"](contents, attributes = {}) {
18
+ let newAttributes = { ...this.attributes };
19
+ if (attributes.replace !== undefined)
20
+ newAttributes = Object.assign(newAttributes, attributes.replace);
21
+ const orderedContents = Object.entries(newAttributes);
22
+ const staticStringContents = [`<${this.type} ` + (orderedContents.length === 0 ? ">" : orderedContents[0][0] + '="'),
23
+ ...orderedContents.slice(1).map(data => `" ${data[0]}="`),
24
+ ...(orderedContents.length > 0 ? ['">'] : []), `</${this.type}>`];
25
+ // @ts-ignore
26
+ staticStringContents.raw = [...staticStringContents];
27
+ return html(staticStringContents, ...[...orderedContents.map(data => data[1]), this.contents]);
28
+ }
29
+ }
30
+ //# sourceMappingURL=ArrowElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrowElement.js","sourceRoot":"","sources":["../src/ArrowElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,O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CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrE,CAAC;CACJ"}
@@ -0,0 +1,78 @@
1
+ import { type ArrowTemplate } from "@arrow-js/core";
2
+ /**
3
+ * A generator for extendable templates that can be rendered. In other frameworks, this would be a "component generator"
4
+ */
5
+ export declare class ArrowElementGenerator<T> {
6
+ readonly type: string;
7
+ protected readonly attributes: {
8
+ [attribute: string]: string | (() => string);
9
+ };
10
+ protected readonly createTransform: (args: T, currentAttributes: {
11
+ [attribute: string]: string | (() => string);
12
+ }) => void;
13
+ /**
14
+ * Creates an ArrowElement
15
+ * @param type The underlying type of this element: div, span, etc
16
+ * @param attributes The attributes on this element
17
+ * @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
18
+ */
19
+ constructor(type: string, attributes: {
20
+ [attribute: string]: string | (() => string);
21
+ }, createTransform: (args: T, currentAttributes: {
22
+ [attribute: string]: string | (() => string);
23
+ }) => void);
24
+ /**
25
+ * Creates a new template from this generator, optionally adding some additional attributes
26
+ * @param contents The contents of this template (the stuff between the tags)
27
+ * @param requiredValue The value you need to pass into this generator, specified when the generator was created (the `createTransform`)
28
+ * @param attributes Additional attributes to add to this template
29
+ * @return A renderable {@link ArrowTemplate}
30
+ */
31
+ create(contents: string | (() => string), requiredValue: T, attributes?: {
32
+ add?: {
33
+ [attribute: string]: string | (() => string);
34
+ };
35
+ replace?: {
36
+ [attribute: string]: string | (() => string);
37
+ };
38
+ transform?: {
39
+ [attribute: string]: (previousValue: (string | undefined | (() => string))) => string;
40
+ };
41
+ }): ArrowTemplate;
42
+ /**
43
+ * Creates a new generator based on this one
44
+ * @param attributes Additional attributes to add to future templates generated by this new generator
45
+ * @param newCreateTransform Takes the `requiredValue` from {@link create} and the attributes of this generator,
46
+ * and applies the `requiredValue` to the attributes
47
+ * @param type The node type of this template. Optional, will inherit from parent if not specified
48
+ * @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
49
+ */
50
+ extend<T2>(attributes: {
51
+ add?: {
52
+ [attribute: string]: string | (() => string);
53
+ };
54
+ replace?: {
55
+ [attribute: string]: string | (() => string);
56
+ };
57
+ transform?: {
58
+ [attribute: string]: (previousValue: (string | undefined | (() => string))) => string;
59
+ };
60
+ }, newCreateTransform: (superTransform: (args: T, currentAttributes: {
61
+ [attribute: string]: string | (() => string);
62
+ }) => void) => (args: T2, currentAttributes: {
63
+ [attribute: string]: string | (() => string);
64
+ }) => void, type?: string): ArrowElementGenerator<T2>;
65
+ }
66
+ /**
67
+ * Creates a new generator
68
+ * @param type The node type of this template
69
+ * @param attributes The attributes to add to all templates made by this generator
70
+ * @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
71
+ * @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
72
+ */
73
+ export default function createGenerator<T>(type: string, attributes: {
74
+ [attribute: string]: string | (() => string);
75
+ }, createTransform?: (args: T, currentAttributes: {
76
+ [attribute: string]: string | (() => string);
77
+ }) => void): ArrowElementGenerator<T>;
78
+ //# sourceMappingURL=ArrowElementGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrowElementGenerator.d.ts","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,EAAO,MAAM,gBAAgB,CAAC;AAsCxD;;GAEG;AACH,qBAAa,qBAAqB,CAAC,CAAC;IAChC,SAAgB,IAAI,SAAC;IACrB,SAAS,CAAC,QAAQ,CAAC,UAAU;6CASuC,MAAM;MAT5C;IAC9B,SAAS,CAAC,QAAQ,CAAC,eAAe,SASA,CAAC,qBAAoB;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;KAAC,KAAG,IAAI,CATnE;IAEnC;;;;;OAKG;gBACS,IAAI,EAAC,MAAM,EAAE,UAAU,EAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,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,CAAC,EAAE,iBAAiB,EAAE;QAC7D,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAA;KAC/C,KAAK,IAAI,KACN,CAAC,IAAI,EAAC,EAAE,EAAE,iBAAiB,EAAC;QACxB,CAAC,SAAS,EAAC,MAAM,GAAG,MAAM,GAAG,CAAC,MAAI,MAAM,CAAC,CAAA;KAC5C,KAAK,IAAI,EACd,IAAI,CAAC,EAAC,MAAM;CAIvB;AAGD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,CAAC,EAAE,IAAI,EAAC,MAAM,EAAE,UAAU,EAAC;IAAC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;CAAC,EACnG,eAAe,GAAE,CAAC,IAAI,EAAC,CAAC,EAAE,iBAAiB,EAAC;IACxC,CAAC,SAAS,EAAC,MAAM,GAAE,MAAM,GAAC,CAAC,MAAI,MAAM,CAAC,CAAA;CACzC,KAAG,IAAa,4BAExB"}
@@ -0,0 +1,94 @@
1
+ import { html } from "@arrow-js/core";
2
+ function extendAttributes(originalAttrs, transformers) {
3
+ const newAttributes = { ...originalAttrs };
4
+ if (transformers.add !== undefined) {
5
+ for (const [attribute, addValue] of Object.entries(transformers.add)) {
6
+ if (newAttributes[attribute] === undefined)
7
+ newAttributes[attribute] = addValue;
8
+ else if (typeof addValue === "string") {
9
+ if (typeof newAttributes[attribute] === "string")
10
+ newAttributes[attribute] += " " + addValue;
11
+ else {
12
+ const old = newAttributes[attribute];
13
+ newAttributes[attribute] = () => old() + " " + addValue;
14
+ }
15
+ }
16
+ else {
17
+ const old = newAttributes[attribute];
18
+ if (typeof old === "function")
19
+ newAttributes[attribute] = () => old() + " " + addValue();
20
+ else
21
+ newAttributes[attribute] = () => addValue() + " " + old;
22
+ }
23
+ }
24
+ }
25
+ if (transformers.replace !== undefined)
26
+ Object.assign(newAttributes, transformers.replace);
27
+ if (transformers.transform !== undefined) {
28
+ for (const [attribute, transformer] of Object.entries(transformers.transform)) {
29
+ newAttributes[attribute] = transformer(newAttributes[attribute]);
30
+ }
31
+ }
32
+ return newAttributes;
33
+ }
34
+ /**
35
+ * A generator for extendable templates that can be rendered. In other frameworks, this would be a "component generator"
36
+ */
37
+ export class ArrowElementGenerator {
38
+ type;
39
+ attributes;
40
+ createTransform;
41
+ /**
42
+ * Creates an ArrowElement
43
+ * @param type The underlying type of this element: div, span, etc
44
+ * @param attributes The attributes on this element
45
+ * @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
46
+ */
47
+ constructor(type, attributes, createTransform) {
48
+ this.type = type;
49
+ this.attributes = attributes;
50
+ this.createTransform = createTransform;
51
+ }
52
+ /**
53
+ * Creates a new template from this generator, optionally adding some additional attributes
54
+ * @param contents The contents of this template (the stuff between the tags)
55
+ * @param requiredValue The value you need to pass into this generator, specified when the generator was created (the `createTransform`)
56
+ * @param attributes Additional attributes to add to this template
57
+ * @return A renderable {@link ArrowTemplate}
58
+ */
59
+ create(contents, requiredValue, attributes = {}) {
60
+ const newAttributes = { ...this.attributes };
61
+ this.createTransform(requiredValue, newAttributes);
62
+ const newerAttributes = extendAttributes(newAttributes, attributes);
63
+ const orderedContents = Object.entries(newerAttributes);
64
+ const staticStringContents = [`<${this.type} ` + (orderedContents.length === 0 ? ">" : orderedContents[0][0] + '="'),
65
+ ...orderedContents.slice(1).map(data => `" ${data[0]}="`),
66
+ ...(orderedContents.length > 0 ? ['">'] : []), `</${this.type}>`];
67
+ // @ts-ignore
68
+ staticStringContents.raw = [...staticStringContents];
69
+ return html(staticStringContents, ...[...orderedContents.map(data => data[1]), contents]);
70
+ }
71
+ /**
72
+ * Creates a new generator based on this one
73
+ * @param attributes Additional attributes to add to future templates generated by this new generator
74
+ * @param newCreateTransform Takes the `requiredValue` from {@link create} and the attributes of this generator,
75
+ * and applies the `requiredValue` to the attributes
76
+ * @param type The node type of this template. Optional, will inherit from parent if not specified
77
+ * @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
78
+ */
79
+ extend(attributes, newCreateTransform, type) {
80
+ return new ArrowElementGenerator(type || this.type, extendAttributes(this.attributes, attributes), newCreateTransform(this.createTransform));
81
+ }
82
+ }
83
+ const defaultGenerator = new ArrowElementGenerator("", {}, () => { });
84
+ /**
85
+ * Creates a new generator
86
+ * @param type The node type of this template
87
+ * @param attributes The attributes to add to all templates made by this generator
88
+ * @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
89
+ * @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
90
+ */
91
+ export default function createGenerator(type, attributes, createTransform = () => { }) {
92
+ return defaultGenerator.extend({ replace: attributes }, () => createTransform, type);
93
+ }
94
+ //# sourceMappingURL=ArrowElementGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrowElementGenerator.js","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAExD,SAAS,gBAAgB,CAAC,aAAsD,EAAC,YAGW;IAExF,MAAM,aAAa,GAAG,EAAC,GAAG,aAAa,EAAC,CAAC;IACzC,IAAG,YAAY,CAAC,GAAG,KAAK,SAAS,EAAC,CAAC;QAC/B,KAAI,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EAAC,CAAC;YACjE,IAAG,aAAa,CAAC,SAAS,CAAC,KAAK,SAAS;gBACrC,aAAa,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;iBACnC,IAAG,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACnC,IAAI,OAAO,aAAa,CAAC,SAAS,CAAC,KAAK,QAAQ;oBAC5C,aAAa,CAAC,SAAS,CAAC,IAAI,GAAG,GAAG,QAAQ,CAAC;qBAC1C,CAAC;oBACF,MAAM,GAAG,GAAG,a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AAC,UAAU,EAAE,UAAU,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IACjJ,CAAC;CACJ;AAED,MAAM,gBAAgB,GAAG,IAAI,qBAAqB,CAAC,EAAE,EAAC,EAAE,EAAE,GAAE,EAAE,GAAC,CAAC,CAAC,CAAC;AAClE;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAI,IAAW,EAAE,UAAmD,EACnG,kBAEW,GAAE,EAAE,GAAC,CAAC;IACrB,OAAO,gBAAgB,CAAC,MAAM,CAAC,EAAC,OAAO,EAAC,UAAU,EAAC,EAAE,GAAE,EAAE,CAAA,eAAe,EAAE,IAAI,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { type ArrowTemplate } from "@arrow-js/core";
2
+ type routeType = {
3
+ [subPath: string]: routeType;
4
+ [getRoute: symbol]: (variables: {
5
+ [variableName: string]: string;
6
+ }) => ArrowTemplate;
7
+ };
8
+ /**
9
+ * A basic router
10
+ */
11
+ export default class Router {
12
+ protected readonly routes: routeType;
13
+ protected readonly route404: ArrowTemplate;
14
+ /**
15
+ * Creates a router
16
+ * @param route404 The template to render if no other path was found. Defaults to "404" text
17
+ */
18
+ constructor(route404?: ArrowTemplate);
19
+ /**
20
+ * Adds a route to this router
21
+ *
22
+ * The `path` can include variables; to do this, prefix some section with ":". When calling {@link getPath} or
23
+ * {@link getPathNo404}, the `variables` object will include the variable.
24
+ *
25
+ * EX: if the route `path/to/:variableName/render` is defined, fetching the location `path/to/someValue/render` will
26
+ * result in\
27
+ * `{ ... variables: { ... variableName: "someValue" } }`
28
+ *
29
+ * @param path The location to render at. Should be of the form `path/to/render`, with no slash at the beginning
30
+ * or end (unless you know what you're doing)
31
+ * @param renderTemplate The template to render at this location
32
+ */
33
+ addRoute(path: string, renderTemplate: (variables: {
34
+ [variableName: string]: string;
35
+ }) => ArrowTemplate): this;
36
+ /**
37
+ * Gets the template to render from the given location. Will default to the 404 path if no path found
38
+ * @param location The location to fetch
39
+ */
40
+ getPath(location: string): ArrowTemplate;
41
+ /**
42
+ * Gets the template to render from the given location. Will return undefined if no path found
43
+ * @param location The location to fetch
44
+ */
45
+ getPathNo404(location: string): ArrowTemplate | undefined;
46
+ }
47
+ /**
48
+ * A router that can manages the web page based on the page's url
49
+ */
50
+ export declare class PageAttachedRouter extends Router {
51
+ protected readonly rootElement: HTMLElement | undefined;
52
+ protected readonly location: import("./utils.js").Ref<string[]>;
53
+ protected readonly transformBeforeRender: (template: ArrowTemplate) => ArrowTemplate;
54
+ /**
55
+ * Creates a page attached router
56
+ * @param attachTo The dom element to attach this router to. Defaults to `document.body`
57
+ * @param route404 The template to render if no other path was found. Defaults to "404" text
58
+ * @param onRender Callback run when the page is rendered
59
+ */
60
+ constructor(attachTo: HTMLElement | undefined, route404?: ArrowTemplate, transformBeforeRender?: (template: ArrowTemplate) => ArrowTemplate);
61
+ /**
62
+ * Rerenders the page (and calls `this.onRender` if it was defined)
63
+ */
64
+ rerender(): void;
65
+ /**
66
+ * Updates the window's `location` and rerenders the page
67
+ * @param newLocation The new url
68
+ * @param replace Whether this new url should replace the current url in history or be a new entry
69
+ * @return If the link leads to a new domain (or starts with [a-z]://)
70
+ */
71
+ redirect(newLocation?: string, replace?: false): boolean;
72
+ }
73
+ export {};
74
+ //# sourceMappingURL=Router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,EAAiB,MAAM,gBAAgB,CAAC;AAIlE,KAAK,SAAS,GAAG;IAAC,CAAC,OAAO,EAAC,MAAM,GAAE,SAAS,CAAC;IAAC,CAAC,QAAQ,EAAC,MAAM,GAAE,CAAC,SAAS,EAAC;QAAC,CAAC,YAAY,EAAC,MAAM,GAAE,MAAM,CAAA;KAAC,KAAG,aAAa,CAAA;CAAC,CAAC;AA8B3H;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACvB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAC,SAAS,CAAI;IACvC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAC,aAAa,CAAC;IAE1C;;;OAGG;gBACS,QAAQ,GAAC,aAAwB;IAI7C;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,IAAI,EAAC,MAAM,EAAE,cAAc,EAAC,CAAC,SAAS,EAAC;QAAC,CAAC,YAAY,EAAC,MAAM,GAAE,MAAM,CAAA;KAAC,KAAG,aAAa;IAc9F;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAC,MAAM;IAGvB;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAC,MAAM;CAU/B;AAGD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,MAAM;IAC1C,SAAS,CAAC,QAAQ,CAAC,WAAW,0BAAC;IAC/B,SAAS,CAAC,QAAQ,CAAC,QAAQ,qCAAqB;IAChD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,aAQ8D,aAAa,KAAG,aAAa,CAR1F;IAEzC;;;;;OAKG;gBACS,QAAQ,EAAC,WAAW,GAAC,SAAS,EAAE,QAAQ,CAAC,EAAC,aAAa,EAAE,qBAAqB,CAAC,EAAC,CAAC,QAAQ,EAAC,aAAa,KAAG,aAAa;IAWnI;;OAEG;IACI,QAAQ;IAaf;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,GAAC,MAA+B,EAAE,OAAO,CAAC,EAAC,KAAK;CAiBvE"}
package/dist/Router.js ADDED
@@ -0,0 +1,156 @@
1
+ import { html, reactive } from "@arrow-js/core";
2
+ import { ref } from "./utils.js";
3
+ const getRouteSymbol = Symbol("getRoute");
4
+ function getPath(routes, subPaths, variables = {}) {
5
+ if (subPaths.length === 0 && routes[getRouteSymbol] !== undefined)
6
+ return { subRoutes: routes, variables };
7
+ //regular path
8
+ if (routes[subPaths[0]] !== undefined) {
9
+ if (routes[subPaths[0]] !== undefined)
10
+ return getPath(routes[subPaths[0]], subPaths.slice(1), { ...variables });
11
+ }
12
+ //variable path
13
+ const toReturn = [];
14
+ for (const key in routes) {
15
+ if (!key.startsWith(":") || routes[key] === undefined)
16
+ continue;
17
+ const maybeRoute = getPath(routes[key], subPaths.slice(1), {
18
+ ...variables,
19
+ [key.slice(1)]: subPaths[0]
20
+ });
21
+ if (maybeRoute instanceof Array)
22
+ toReturn.push(...maybeRoute);
23
+ else if (maybeRoute !== undefined)
24
+ toReturn.push(maybeRoute);
25
+ }
26
+ if (toReturn.length > 0)
27
+ return toReturn;
28
+ }
29
+ const default404 = html `404`;
30
+ /**
31
+ * A basic router
32
+ */
33
+ export default class Router {
34
+ routes = {};
35
+ route404;
36
+ /**
37
+ * Creates a router
38
+ * @param route404 The template to render if no other path was found. Defaults to "404" text
39
+ */
40
+ constructor(route404 = default404) {
41
+ this.route404 = route404;
42
+ }
43
+ /**
44
+ * Adds a route to this router
45
+ *
46
+ * The `path` can include variables; to do this, prefix some section with ":". When calling {@link getPath} or
47
+ * {@link getPathNo404}, the `variables` object will include the variable.
48
+ *
49
+ * EX: if the route `path/to/:variableName/render` is defined, fetching the location `path/to/someValue/render` will
50
+ * result in\
51
+ * `{ ... variables: { ... variableName: "someValue" } }`
52
+ *
53
+ * @param path The location to render at. Should be of the form `path/to/render`, with no slash at the beginning
54
+ * or end (unless you know what you're doing)
55
+ * @param renderTemplate The template to render at this location
56
+ */
57
+ addRoute(path, renderTemplate) {
58
+ const subPaths = path.split("/");
59
+ let position = this.routes;
60
+ for (const nextPos of subPaths) {
61
+ if (position[nextPos] !== undefined)
62
+ position = position[nextPos];
63
+ else
64
+ position = position[nextPos] = {};
65
+ }
66
+ position[getRouteSymbol] = renderTemplate;
67
+ return this;
68
+ }
69
+ /**
70
+ * Gets the template to render from the given location. Will default to the 404 path if no path found
71
+ * @param location The location to fetch
72
+ */
73
+ getPath(location) {
74
+ return this.getPathNo404(location) || this.route404;
75
+ }
76
+ /**
77
+ * Gets the template to render from the given location. Will return undefined if no path found
78
+ * @param location The location to fetch
79
+ */
80
+ getPathNo404(location) {
81
+ const path = getPath(this.routes, location.split("/"));
82
+ if (path instanceof Array) {
83
+ if (path.length === 0)
84
+ return undefined;
85
+ if (path[0].subRoutes[getRouteSymbol] === undefined)
86
+ return undefined;
87
+ return path[0].subRoutes[getRouteSymbol](path[0].variables);
88
+ }
89
+ else if (path !== undefined && path.subRoutes[getRouteSymbol] !== undefined)
90
+ return path.subRoutes[getRouteSymbol](path.variables);
91
+ }
92
+ }
93
+ const differentPage = /^[A-Za-z]+:\/\/.*$/;
94
+ /**
95
+ * A router that can manages the web page based on the page's url
96
+ */
97
+ export class PageAttachedRouter extends Router {
98
+ rootElement;
99
+ location = ref([]);
100
+ transformBeforeRender;
101
+ /**
102
+ * Creates a page attached router
103
+ * @param attachTo The dom element to attach this router to. Defaults to `document.body`
104
+ * @param route404 The template to render if no other path was found. Defaults to "404" text
105
+ * @param onRender Callback run when the page is rendered
106
+ */
107
+ constructor(attachTo, route404, transformBeforeRender) {
108
+ super(route404);
109
+ this.rootElement = attachTo;
110
+ this.transformBeforeRender = transformBeforeRender || (template => template);
111
+ this.location.$on(() => this.rerender());
112
+ window.addEventListener("popstate", e => {
113
+ if (!this.redirect(window.location.pathname))
114
+ e.preventDefault();
115
+ }); //back button handling
116
+ }
117
+ /**
118
+ * Rerenders the page (and calls `this.onRender` if it was defined)
119
+ */
120
+ rerender() {
121
+ // const data = ref(html``);
122
+ const path = this.getPath(this.location.value.join("/"));
123
+ const toRender = html `${path}`;
124
+ // data.value = path;
125
+ if (this.rootElement !== undefined) {
126
+ this.rootElement.replaceChildren();
127
+ html `${this.transformBeforeRender(path)}`(this.rootElement);
128
+ }
129
+ //html`${header}${_ => data.val}${footer}${modalHTML}${toastsHTML}`(document.body);
130
+ }
131
+ /**
132
+ * Updates the window's `location` and rerenders the page
133
+ * @param newLocation The new url
134
+ * @param replace Whether this new url should replace the current url in history or be a new entry
135
+ * @return If the link leads to a new domain (or starts with [a-z]://)
136
+ */
137
+ redirect(newLocation = window.location.pathname, replace) {
138
+ if (newLocation.startsWith("/"))
139
+ this.location.value = newLocation.split("/").slice(1);
140
+ else if (newLocation.match(differentPage) !== null)
141
+ return true;
142
+ else
143
+ this.location.value = this.location.value.concat(newLocation.split("/"));
144
+ // modalContents.val=undefined;
145
+ const newPath = newLocation.split("/");
146
+ if (newPath[0] === "") {
147
+ this.location.value = newPath.slice(1);
148
+ }
149
+ else {
150
+ this.location.value = this.location.value.concat(newPath);
151
+ }
152
+ window.history[replace ? "replaceState" : "pushState"](null, "", "/" + this.location.value.join("/"));
153
+ return false;
154
+ }
155
+ }
156
+ //# sourceMappingURL=Router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.js","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAE/B,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAI1C,SAAS,OAAO,CAAC,MAAgB,EAAE,QAAiB,EAAE,YAA8B,EAAE;IAClF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,SAAS;QAAE,OAAO,EAAC,SAAS,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;IAExG,cAAc;IACd,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,KAAK,SAAS,EAAE,CAAC;QACrC,IAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,KAAK,SAAS;YACjC,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAC,GAAG,SAAS,EAAC,CAAC,CAAC;IACjF,CAAC;IAED,eAAe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,CAAC,CAAC,CAAC,CAAC;aACjF,IAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;;YAC1D,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAE9E,+BAA+B;QAE/B,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACtG,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RouterLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouterLink.d.ts","sourceRoot":"","sources":["../src/RouterLink.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RouterLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouterLink.js","sourceRoot":"","sources":["../src/RouterLink.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Creates a simple watchable value. You can access the value with `.value`\
3
+ * Shortcut for `new Ref(...)`
4
+ * @param defaultValue the default value
5
+ */
6
+ export declare function ref<T>(defaultValue: T): Ref<T>;
7
+ /**
8
+ * A simple watchable value. You can access the value with `.value`
9
+ * @param defaultValue the default value
10
+ */
11
+ export declare class Ref<T> {
12
+ protected readonly internalReactive: import("@arrow-js/core").ReactiveProxy<{
13
+ value: T;
14
+ }>;
15
+ constructor(defaultValue: T);
16
+ get value(): T;
17
+ set value(value: T);
18
+ /**
19
+ * Adds an observer to a given property
20
+ * @param property - The property to watch
21
+ * @param callback - The callback to call when the property changes
22
+ */
23
+ $on(callback: (value: T, oldValue: T) => void): void;
24
+ /**
25
+ * Removes an observer from a given property
26
+ * @param property - The property to stop watching
27
+ * @param callback - The callback to stop calling when the property changes
28
+ */
29
+ $off(callback: (value: T, oldValue: T) => void): void;
30
+ }
31
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAC,CAAC,UAEpC;AACD;;;GAGG;AACH,qBAAa,GAAG,CAAC,CAAC;IACd,SAAS,CAAC,QAAQ,CAAC,gBAAgB;;OAAC;gBACxB,YAAY,EAAC,CAAC;IAG1B,IAAI,KAAK,IAAG,CAAC,CAA4C;IACzD,IAAI,KAAK,CAAC,KAAK,EAAC,CAAC,EAAgD;IAEjE;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,IAAI;IAG7C;;;;OAIG;IACH,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,IAAI;CAGjD"}
package/dist/utils.js ADDED
@@ -0,0 +1,39 @@
1
+ import { reactive } from "@arrow-js/core";
2
+ /**
3
+ * Creates a simple watchable value. You can access the value with `.value`\
4
+ * Shortcut for `new Ref(...)`
5
+ * @param defaultValue the default value
6
+ */
7
+ export function ref(defaultValue) {
8
+ return new Ref(defaultValue);
9
+ }
10
+ /**
11
+ * A simple watchable value. You can access the value with `.value`
12
+ * @param defaultValue the default value
13
+ */
14
+ export class Ref {
15
+ internalReactive;
16
+ constructor(defaultValue) {
17
+ this.internalReactive = reactive({ value: defaultValue });
18
+ }
19
+ get value() { return this.internalReactive.value; }
20
+ set value(value) { this.internalReactive.value = value; }
21
+ /**
22
+ * Adds an observer to a given property
23
+ * @param property - The property to watch
24
+ * @param callback - The callback to call when the property changes
25
+ */
26
+ $on(callback) {
27
+ this.internalReactive.$on("value", callback);
28
+ }
29
+ /**
30
+ * Removes an observer from a given property
31
+ * @param property - The property to stop watching
32
+ * @param callback - The callback to stop calling when the property changes
33
+ */
34
+ $off(callback) {
35
+ this.internalReactive.$on("value", callback);
36
+ }
37
+ }
38
+ //--
39
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAI,YAAc;IACjC,OAAO,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AACD;;;GAGG;AACH,MAAM,OAAO,GAAG;IACO,gBAAgB,CAAC;IACpC,YAAY,YAAc;QACtB,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC,EAAC,KAAK,EAAC,YAAY,EAAC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,KAAM,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAU,CAAC,CAAC,CAAC;IACzD,IAAI,KAAK,CAAC,KAAO,IAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,GAAG,KAAY,CAAC,CAAC,CAAC;IAEjE;;;;OAIG;IACH,GAAG,CAAC,QAAyC;QACzC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAC,QAAyC;QAC1C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CACJ;AAED,IAAI"}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "arrowjs-aluminum",
3
+ "version": "0.9.0",
4
+ "description": "Reactivity without the framework... with the framework",
5
+ "author": "kyfex",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "dependencies": {
9
+ "@arrow-js/core": "^1.0.0-alpha.10"
10
+ },
11
+ "devDependencies": {
12
+ "express": "^5.1.0",
13
+ "typescript": "^5.9.3"
14
+ },
15
+
16
+ "files": ["./dist/*"],
17
+ "homepage": "https://kyfex-uwu.github.io/arrowjs-aluminum/",
18
+ "bugs": {
19
+ "url": "https://github.com/kyfex-uwu/arrowjs-aluminum/issues"
20
+ },
21
+ "engines": {
22
+ "node": ">=14.0.0"
23
+ }
24
+ }