@flare-engine/deep-links 0.1.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.d.mts +112 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +237 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +205 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Grzegorz Otto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @flare-engine/deep-links
|
|
2
|
+
|
|
3
|
+
URL → scene + params routing with pluggable platform sources. `DeepLinkRouter` supports literal segments, `:param` captures, and a trailing `*` wildcard binding the rest into `params.rest`. `DeepLinkManager` wires a `DeepLinkSource` (web `popstate` / native `Linking` / in-memory) to a router; first-match wins.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/deep-links
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { DeepLinkRouter, DeepLinkManager, createNativeSource, parseUrl } from '@flare-engine/deep-links';
|
|
15
|
+
|
|
16
|
+
const router = new DeepLinkRouter()
|
|
17
|
+
.register('/zone/:id', 'play')
|
|
18
|
+
.register('/shop', 'shop');
|
|
19
|
+
|
|
20
|
+
const manager = new DeepLinkManager(router, createNativeSource(Linking));
|
|
21
|
+
manager.onMatch.add((m) => sceneManager.go(m.scene, m.params));
|
|
22
|
+
manager.start();
|
|
23
|
+
|
|
24
|
+
// or stateless:
|
|
25
|
+
parseUrl('flare://game/zone/4?from=shop');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
See [API spec](../../docs/design/api-specs.md#flare-enginedeep-links--6kb-raw) and [skill reference](../../.github/skills/flare-deep-links/SKILL.md).
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Signal } from '@flare-engine/events';
|
|
2
|
+
|
|
3
|
+
type ParamValue = string;
|
|
4
|
+
type Params = Record<string, ParamValue>;
|
|
5
|
+
interface DeepLinkMatch {
|
|
6
|
+
/** Scene or target id associated with the matched route. */
|
|
7
|
+
scene: string;
|
|
8
|
+
/** Parsed path + query parameters. Path params take precedence. */
|
|
9
|
+
params: Params;
|
|
10
|
+
/** Original URL the match was performed against. */
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse a `scheme://host/path?query` or `/path?query` URL into its path
|
|
16
|
+
* segments and query params. Returns `null` if the input is malformed.
|
|
17
|
+
*
|
|
18
|
+
* This is intentionally minimal: it does not validate scheme, does not decode
|
|
19
|
+
* fragments, and ignores username/password.
|
|
20
|
+
*/
|
|
21
|
+
interface ParsedUrl {
|
|
22
|
+
scheme: string | null;
|
|
23
|
+
host: string | null;
|
|
24
|
+
segments: string[];
|
|
25
|
+
query: Params;
|
|
26
|
+
}
|
|
27
|
+
declare function parseUrl(url: string): ParsedUrl | null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Route pattern like `/bench/:id` or `/shop/:category/:item`. Segments
|
|
31
|
+
* starting with `:` are captured; literal segments must match exactly.
|
|
32
|
+
* The `*` segment matches the remainder of the path into a `rest` param.
|
|
33
|
+
*/
|
|
34
|
+
interface RouteDefinition {
|
|
35
|
+
pattern: string;
|
|
36
|
+
scene: string;
|
|
37
|
+
}
|
|
38
|
+
declare class DeepLinkRouter {
|
|
39
|
+
private routes;
|
|
40
|
+
register(pattern: string, scene: string): this;
|
|
41
|
+
registerAll(defs: readonly RouteDefinition[]): this;
|
|
42
|
+
match(url: string): DeepLinkMatch | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Platform adapter that surfaces incoming URLs to the router. Web ships a
|
|
47
|
+
* history-based adapter; RN consumers pass one that wires `Linking`.
|
|
48
|
+
*/
|
|
49
|
+
interface DeepLinkSource {
|
|
50
|
+
/** Current URL if the platform exposes one (e.g., `window.location.href`). */
|
|
51
|
+
getInitialUrl(): Promise<string | null> | string | null;
|
|
52
|
+
/** Register a handler for future URL updates; returns an unsubscribe. */
|
|
53
|
+
subscribe(handler: (url: string) => void): () => void;
|
|
54
|
+
}
|
|
55
|
+
interface DeepLinkManagerOptions {
|
|
56
|
+
router: DeepLinkRouter;
|
|
57
|
+
source: DeepLinkSource;
|
|
58
|
+
}
|
|
59
|
+
declare class DeepLinkManager {
|
|
60
|
+
readonly onMatch: Signal<DeepLinkMatch>;
|
|
61
|
+
readonly onUnmatched: Signal<string>;
|
|
62
|
+
private readonly router;
|
|
63
|
+
private readonly source;
|
|
64
|
+
private unsubscribe;
|
|
65
|
+
private _current;
|
|
66
|
+
constructor(options: DeepLinkManagerOptions);
|
|
67
|
+
get current(): DeepLinkMatch | null;
|
|
68
|
+
start(): Promise<void>;
|
|
69
|
+
stop(): void;
|
|
70
|
+
handle(url: string): DeepLinkMatch | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* In-memory source useful for tests and for host apps that want to push URLs
|
|
75
|
+
* manually (e.g., from a notification handler).
|
|
76
|
+
*/
|
|
77
|
+
declare function createMemorySource(initialUrl?: string | null): DeepLinkSource & {
|
|
78
|
+
push(url: string): void;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Minimal shape of the globals a web browser exposes. Defined locally so
|
|
82
|
+
* we don't pull in DOM lib types across the monorepo.
|
|
83
|
+
*/
|
|
84
|
+
interface WebWindowLike {
|
|
85
|
+
location: {
|
|
86
|
+
href: string;
|
|
87
|
+
};
|
|
88
|
+
addEventListener: (type: string, listener: () => void) => void;
|
|
89
|
+
removeEventListener: (type: string, listener: () => void) => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Web `popstate` + `location.href` adapter. Call `notify(url)` after any
|
|
93
|
+
* programmatic `history.pushState` if you want the manager to react.
|
|
94
|
+
*/
|
|
95
|
+
declare function createWebSource(win: WebWindowLike): DeepLinkSource & {
|
|
96
|
+
notify(url: string): void;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Minimal shape of the React Native `Linking` module. Passing this lets the
|
|
100
|
+
* host wire deep links on iOS/Android without this package depending on RN.
|
|
101
|
+
*/
|
|
102
|
+
interface LinkingLike {
|
|
103
|
+
getInitialURL(): Promise<string | null>;
|
|
104
|
+
addEventListener(type: 'url', handler: (event: {
|
|
105
|
+
url: string;
|
|
106
|
+
}) => void): {
|
|
107
|
+
remove: () => void;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
declare function createNativeSource(linking: LinkingLike): DeepLinkSource;
|
|
111
|
+
|
|
112
|
+
export { DeepLinkManager, type DeepLinkManagerOptions, type DeepLinkMatch, DeepLinkRouter, type DeepLinkSource, type LinkingLike, type ParamValue, type Params, type ParsedUrl, type RouteDefinition, createMemorySource, createNativeSource, createWebSource, parseUrl };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Signal } from '@flare-engine/events';
|
|
2
|
+
|
|
3
|
+
type ParamValue = string;
|
|
4
|
+
type Params = Record<string, ParamValue>;
|
|
5
|
+
interface DeepLinkMatch {
|
|
6
|
+
/** Scene or target id associated with the matched route. */
|
|
7
|
+
scene: string;
|
|
8
|
+
/** Parsed path + query parameters. Path params take precedence. */
|
|
9
|
+
params: Params;
|
|
10
|
+
/** Original URL the match was performed against. */
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse a `scheme://host/path?query` or `/path?query` URL into its path
|
|
16
|
+
* segments and query params. Returns `null` if the input is malformed.
|
|
17
|
+
*
|
|
18
|
+
* This is intentionally minimal: it does not validate scheme, does not decode
|
|
19
|
+
* fragments, and ignores username/password.
|
|
20
|
+
*/
|
|
21
|
+
interface ParsedUrl {
|
|
22
|
+
scheme: string | null;
|
|
23
|
+
host: string | null;
|
|
24
|
+
segments: string[];
|
|
25
|
+
query: Params;
|
|
26
|
+
}
|
|
27
|
+
declare function parseUrl(url: string): ParsedUrl | null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Route pattern like `/bench/:id` or `/shop/:category/:item`. Segments
|
|
31
|
+
* starting with `:` are captured; literal segments must match exactly.
|
|
32
|
+
* The `*` segment matches the remainder of the path into a `rest` param.
|
|
33
|
+
*/
|
|
34
|
+
interface RouteDefinition {
|
|
35
|
+
pattern: string;
|
|
36
|
+
scene: string;
|
|
37
|
+
}
|
|
38
|
+
declare class DeepLinkRouter {
|
|
39
|
+
private routes;
|
|
40
|
+
register(pattern: string, scene: string): this;
|
|
41
|
+
registerAll(defs: readonly RouteDefinition[]): this;
|
|
42
|
+
match(url: string): DeepLinkMatch | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Platform adapter that surfaces incoming URLs to the router. Web ships a
|
|
47
|
+
* history-based adapter; RN consumers pass one that wires `Linking`.
|
|
48
|
+
*/
|
|
49
|
+
interface DeepLinkSource {
|
|
50
|
+
/** Current URL if the platform exposes one (e.g., `window.location.href`). */
|
|
51
|
+
getInitialUrl(): Promise<string | null> | string | null;
|
|
52
|
+
/** Register a handler for future URL updates; returns an unsubscribe. */
|
|
53
|
+
subscribe(handler: (url: string) => void): () => void;
|
|
54
|
+
}
|
|
55
|
+
interface DeepLinkManagerOptions {
|
|
56
|
+
router: DeepLinkRouter;
|
|
57
|
+
source: DeepLinkSource;
|
|
58
|
+
}
|
|
59
|
+
declare class DeepLinkManager {
|
|
60
|
+
readonly onMatch: Signal<DeepLinkMatch>;
|
|
61
|
+
readonly onUnmatched: Signal<string>;
|
|
62
|
+
private readonly router;
|
|
63
|
+
private readonly source;
|
|
64
|
+
private unsubscribe;
|
|
65
|
+
private _current;
|
|
66
|
+
constructor(options: DeepLinkManagerOptions);
|
|
67
|
+
get current(): DeepLinkMatch | null;
|
|
68
|
+
start(): Promise<void>;
|
|
69
|
+
stop(): void;
|
|
70
|
+
handle(url: string): DeepLinkMatch | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* In-memory source useful for tests and for host apps that want to push URLs
|
|
75
|
+
* manually (e.g., from a notification handler).
|
|
76
|
+
*/
|
|
77
|
+
declare function createMemorySource(initialUrl?: string | null): DeepLinkSource & {
|
|
78
|
+
push(url: string): void;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Minimal shape of the globals a web browser exposes. Defined locally so
|
|
82
|
+
* we don't pull in DOM lib types across the monorepo.
|
|
83
|
+
*/
|
|
84
|
+
interface WebWindowLike {
|
|
85
|
+
location: {
|
|
86
|
+
href: string;
|
|
87
|
+
};
|
|
88
|
+
addEventListener: (type: string, listener: () => void) => void;
|
|
89
|
+
removeEventListener: (type: string, listener: () => void) => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Web `popstate` + `location.href` adapter. Call `notify(url)` after any
|
|
93
|
+
* programmatic `history.pushState` if you want the manager to react.
|
|
94
|
+
*/
|
|
95
|
+
declare function createWebSource(win: WebWindowLike): DeepLinkSource & {
|
|
96
|
+
notify(url: string): void;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Minimal shape of the React Native `Linking` module. Passing this lets the
|
|
100
|
+
* host wire deep links on iOS/Android without this package depending on RN.
|
|
101
|
+
*/
|
|
102
|
+
interface LinkingLike {
|
|
103
|
+
getInitialURL(): Promise<string | null>;
|
|
104
|
+
addEventListener(type: 'url', handler: (event: {
|
|
105
|
+
url: string;
|
|
106
|
+
}) => void): {
|
|
107
|
+
remove: () => void;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
declare function createNativeSource(linking: LinkingLike): DeepLinkSource;
|
|
111
|
+
|
|
112
|
+
export { DeepLinkManager, type DeepLinkManagerOptions, type DeepLinkMatch, DeepLinkRouter, type DeepLinkSource, type LinkingLike, type ParamValue, type Params, type ParsedUrl, type RouteDefinition, createMemorySource, createNativeSource, createWebSource, parseUrl };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DeepLinkManager: () => DeepLinkManager,
|
|
24
|
+
DeepLinkRouter: () => DeepLinkRouter,
|
|
25
|
+
createMemorySource: () => createMemorySource,
|
|
26
|
+
createNativeSource: () => createNativeSource,
|
|
27
|
+
createWebSource: () => createWebSource,
|
|
28
|
+
parseUrl: () => parseUrl
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/parse.ts
|
|
33
|
+
function parseUrl(url) {
|
|
34
|
+
if (typeof url !== "string" || url.length === 0) return null;
|
|
35
|
+
let rest = url;
|
|
36
|
+
let scheme = null;
|
|
37
|
+
let host = null;
|
|
38
|
+
const schemeIdx = rest.indexOf("://");
|
|
39
|
+
if (schemeIdx !== -1) {
|
|
40
|
+
scheme = rest.slice(0, schemeIdx);
|
|
41
|
+
rest = rest.slice(schemeIdx + 3);
|
|
42
|
+
const slashIdx = rest.indexOf("/");
|
|
43
|
+
if (slashIdx === -1) {
|
|
44
|
+
host = rest;
|
|
45
|
+
rest = "/";
|
|
46
|
+
} else {
|
|
47
|
+
host = rest.slice(0, slashIdx);
|
|
48
|
+
rest = rest.slice(slashIdx);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const hashIdx = rest.indexOf("#");
|
|
52
|
+
if (hashIdx !== -1) rest = rest.slice(0, hashIdx);
|
|
53
|
+
let path = rest;
|
|
54
|
+
let queryStr = "";
|
|
55
|
+
const qIdx = rest.indexOf("?");
|
|
56
|
+
if (qIdx !== -1) {
|
|
57
|
+
path = rest.slice(0, qIdx);
|
|
58
|
+
queryStr = rest.slice(qIdx + 1);
|
|
59
|
+
}
|
|
60
|
+
const segments = path.split("/").filter((s) => s.length > 0).map(safeDecode);
|
|
61
|
+
const query = {};
|
|
62
|
+
if (queryStr.length > 0) {
|
|
63
|
+
for (const pair of queryStr.split("&")) {
|
|
64
|
+
if (pair.length === 0) continue;
|
|
65
|
+
const eq = pair.indexOf("=");
|
|
66
|
+
const rawKey = eq === -1 ? pair : pair.slice(0, eq);
|
|
67
|
+
const rawVal = eq === -1 ? "" : pair.slice(eq + 1);
|
|
68
|
+
const key = safeDecode(rawKey);
|
|
69
|
+
if (key.length === 0) continue;
|
|
70
|
+
query[key] = safeDecode(rawVal);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { scheme, host, segments, query };
|
|
74
|
+
}
|
|
75
|
+
function safeDecode(s) {
|
|
76
|
+
try {
|
|
77
|
+
return decodeURIComponent(s.replace(/\+/g, "%20"));
|
|
78
|
+
} catch {
|
|
79
|
+
return s;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/router.ts
|
|
84
|
+
var DeepLinkRouter = class {
|
|
85
|
+
routes = [];
|
|
86
|
+
register(pattern, scene) {
|
|
87
|
+
this.routes.push({ scene, segments: compile(pattern) });
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
registerAll(defs) {
|
|
91
|
+
for (const def of defs) this.register(def.pattern, def.scene);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
match(url) {
|
|
95
|
+
const parsed = parseUrl(url);
|
|
96
|
+
if (!parsed) return null;
|
|
97
|
+
for (const route of this.routes) {
|
|
98
|
+
const params = tryMatch(route, parsed.segments);
|
|
99
|
+
if (!params) continue;
|
|
100
|
+
const combined = { ...parsed.query, ...params };
|
|
101
|
+
return { scene: route.scene, params: combined, url };
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function compile(pattern) {
|
|
107
|
+
return pattern.split("/").filter((s) => s.length > 0).map((s) => {
|
|
108
|
+
if (s === "*") return { wildcard: true };
|
|
109
|
+
if (s.startsWith(":")) return { param: s.slice(1) };
|
|
110
|
+
return { literal: s };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function tryMatch(route, segs) {
|
|
114
|
+
const out = {};
|
|
115
|
+
const segCount = route.segments.length;
|
|
116
|
+
for (let i = 0; i < segCount; i++) {
|
|
117
|
+
const def = route.segments[i];
|
|
118
|
+
if (!def) return null;
|
|
119
|
+
if (def.wildcard) {
|
|
120
|
+
out.rest = segs.slice(i).join("/");
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
const actual = segs[i];
|
|
124
|
+
if (actual === void 0) return null;
|
|
125
|
+
if (def.literal !== void 0) {
|
|
126
|
+
if (def.literal !== actual) return null;
|
|
127
|
+
} else if (def.param !== void 0) {
|
|
128
|
+
out[def.param] = actual;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (segs.length !== segCount) return null;
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/manager.ts
|
|
136
|
+
var import_events = require("@flare-engine/events");
|
|
137
|
+
var DeepLinkManager = class {
|
|
138
|
+
onMatch = new import_events.Signal();
|
|
139
|
+
onUnmatched = new import_events.Signal();
|
|
140
|
+
router;
|
|
141
|
+
source;
|
|
142
|
+
unsubscribe = null;
|
|
143
|
+
_current = null;
|
|
144
|
+
constructor(options) {
|
|
145
|
+
this.router = options.router;
|
|
146
|
+
this.source = options.source;
|
|
147
|
+
}
|
|
148
|
+
get current() {
|
|
149
|
+
return this._current;
|
|
150
|
+
}
|
|
151
|
+
async start() {
|
|
152
|
+
if (this.unsubscribe) return;
|
|
153
|
+
this.unsubscribe = this.source.subscribe((url) => this.handle(url));
|
|
154
|
+
const initial = await Promise.resolve(this.source.getInitialUrl());
|
|
155
|
+
if (initial) this.handle(initial);
|
|
156
|
+
}
|
|
157
|
+
stop() {
|
|
158
|
+
if (this.unsubscribe) {
|
|
159
|
+
this.unsubscribe();
|
|
160
|
+
this.unsubscribe = null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
handle(url) {
|
|
164
|
+
const match = this.router.match(url);
|
|
165
|
+
if (!match) {
|
|
166
|
+
this.onUnmatched.emit(url);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
this._current = match;
|
|
170
|
+
this.onMatch.emit(match);
|
|
171
|
+
return match;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/sources.ts
|
|
176
|
+
function createMemorySource(initialUrl = null) {
|
|
177
|
+
let initial = initialUrl;
|
|
178
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
179
|
+
return {
|
|
180
|
+
getInitialUrl() {
|
|
181
|
+
const v = initial;
|
|
182
|
+
initial = null;
|
|
183
|
+
return v;
|
|
184
|
+
},
|
|
185
|
+
subscribe(handler) {
|
|
186
|
+
listeners.add(handler);
|
|
187
|
+
return () => listeners.delete(handler);
|
|
188
|
+
},
|
|
189
|
+
push(url) {
|
|
190
|
+
for (const l of listeners) l(url);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function createWebSource(win) {
|
|
195
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
196
|
+
const onPop = () => {
|
|
197
|
+
const href = win.location.href;
|
|
198
|
+
for (const l of listeners) l(href);
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
getInitialUrl() {
|
|
202
|
+
return win.location.href;
|
|
203
|
+
},
|
|
204
|
+
subscribe(handler) {
|
|
205
|
+
listeners.add(handler);
|
|
206
|
+
win.addEventListener("popstate", onPop);
|
|
207
|
+
return () => {
|
|
208
|
+
listeners.delete(handler);
|
|
209
|
+
win.removeEventListener("popstate", onPop);
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
notify(url) {
|
|
213
|
+
for (const l of listeners) l(url);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function createNativeSource(linking) {
|
|
218
|
+
return {
|
|
219
|
+
getInitialUrl() {
|
|
220
|
+
return linking.getInitialURL();
|
|
221
|
+
},
|
|
222
|
+
subscribe(handler) {
|
|
223
|
+
const sub = linking.addEventListener("url", (e) => handler(e.url));
|
|
224
|
+
return () => sub.remove();
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
DeepLinkManager,
|
|
231
|
+
DeepLinkRouter,
|
|
232
|
+
createMemorySource,
|
|
233
|
+
createNativeSource,
|
|
234
|
+
createWebSource,
|
|
235
|
+
parseUrl
|
|
236
|
+
});
|
|
237
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/parse.ts","../src/router.ts","../src/manager.ts","../src/sources.ts"],"sourcesContent":["export type { DeepLinkMatch, Params, ParamValue } from './types.js';\nexport { parseUrl, type ParsedUrl } from './parse.js';\nexport { DeepLinkRouter, type RouteDefinition } from './router.js';\nexport {\n DeepLinkManager,\n type DeepLinkManagerOptions,\n type DeepLinkSource,\n} from './manager.js';\nexport {\n createMemorySource,\n createWebSource,\n createNativeSource,\n type LinkingLike,\n} from './sources.js';\n","import type { Params } from './types.js';\n\n/**\n * Parse a `scheme://host/path?query` or `/path?query` URL into its path\n * segments and query params. Returns `null` if the input is malformed.\n *\n * This is intentionally minimal: it does not validate scheme, does not decode\n * fragments, and ignores username/password.\n */\nexport interface ParsedUrl {\n scheme: string | null;\n host: string | null;\n segments: string[];\n query: Params;\n}\n\nexport function parseUrl(url: string): ParsedUrl | null {\n if (typeof url !== 'string' || url.length === 0) return null;\n let rest = url;\n let scheme: string | null = null;\n let host: string | null = null;\n\n const schemeIdx = rest.indexOf('://');\n if (schemeIdx !== -1) {\n scheme = rest.slice(0, schemeIdx);\n rest = rest.slice(schemeIdx + 3);\n const slashIdx = rest.indexOf('/');\n if (slashIdx === -1) {\n host = rest;\n rest = '/';\n } else {\n host = rest.slice(0, slashIdx);\n rest = rest.slice(slashIdx);\n }\n }\n\n // Strip fragment.\n const hashIdx = rest.indexOf('#');\n if (hashIdx !== -1) rest = rest.slice(0, hashIdx);\n\n let path = rest;\n let queryStr = '';\n const qIdx = rest.indexOf('?');\n if (qIdx !== -1) {\n path = rest.slice(0, qIdx);\n queryStr = rest.slice(qIdx + 1);\n }\n\n const segments = path\n .split('/')\n .filter((s) => s.length > 0)\n .map(safeDecode);\n const query: Params = {};\n if (queryStr.length > 0) {\n for (const pair of queryStr.split('&')) {\n if (pair.length === 0) continue;\n const eq = pair.indexOf('=');\n const rawKey = eq === -1 ? pair : pair.slice(0, eq);\n const rawVal = eq === -1 ? '' : pair.slice(eq + 1);\n const key = safeDecode(rawKey);\n if (key.length === 0) continue;\n query[key] = safeDecode(rawVal);\n }\n }\n\n return { scheme, host, segments, query };\n}\n\nfunction safeDecode(s: string): string {\n try {\n return decodeURIComponent(s.replace(/\\+/g, '%20'));\n } catch {\n return s;\n }\n}\n","import { parseUrl } from './parse.js';\nimport type { DeepLinkMatch, Params } from './types.js';\n\n/**\n * Route pattern like `/bench/:id` or `/shop/:category/:item`. Segments\n * starting with `:` are captured; literal segments must match exactly.\n * The `*` segment matches the remainder of the path into a `rest` param.\n */\nexport interface RouteDefinition {\n pattern: string;\n scene: string;\n}\n\ninterface CompiledRoute {\n scene: string;\n segments: Array<{ literal?: string; param?: string; wildcard?: boolean }>;\n}\n\nexport class DeepLinkRouter {\n private routes: CompiledRoute[] = [];\n\n register(pattern: string, scene: string): this {\n this.routes.push({ scene, segments: compile(pattern) });\n return this;\n }\n\n registerAll(defs: readonly RouteDefinition[]): this {\n for (const def of defs) this.register(def.pattern, def.scene);\n return this;\n }\n\n match(url: string): DeepLinkMatch | null {\n const parsed = parseUrl(url);\n if (!parsed) return null;\n for (const route of this.routes) {\n const params = tryMatch(route, parsed.segments);\n if (!params) continue;\n const combined: Params = { ...parsed.query, ...params };\n return { scene: route.scene, params: combined, url };\n }\n return null;\n }\n}\n\nfunction compile(pattern: string): CompiledRoute['segments'] {\n return pattern\n .split('/')\n .filter((s) => s.length > 0)\n .map((s) => {\n if (s === '*') return { wildcard: true };\n if (s.startsWith(':')) return { param: s.slice(1) };\n return { literal: s };\n });\n}\n\nfunction tryMatch(route: CompiledRoute, segs: readonly string[]): Params | null {\n const out: Params = {};\n const segCount = route.segments.length;\n for (let i = 0; i < segCount; i++) {\n const def = route.segments[i];\n if (!def) return null;\n if (def.wildcard) {\n out.rest = segs.slice(i).join('/');\n return out;\n }\n const actual = segs[i];\n if (actual === undefined) return null;\n if (def.literal !== undefined) {\n if (def.literal !== actual) return null;\n } else if (def.param !== undefined) {\n out[def.param] = actual;\n }\n }\n if (segs.length !== segCount) return null;\n return out;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { DeepLinkRouter } from './router.js';\nimport type { DeepLinkMatch } from './types.js';\n\n/**\n * Platform adapter that surfaces incoming URLs to the router. Web ships a\n * history-based adapter; RN consumers pass one that wires `Linking`.\n */\nexport interface DeepLinkSource {\n /** Current URL if the platform exposes one (e.g., `window.location.href`). */\n getInitialUrl(): Promise<string | null> | string | null;\n /** Register a handler for future URL updates; returns an unsubscribe. */\n subscribe(handler: (url: string) => void): () => void;\n}\n\nexport interface DeepLinkManagerOptions {\n router: DeepLinkRouter;\n source: DeepLinkSource;\n}\n\nexport class DeepLinkManager {\n readonly onMatch = new Signal<DeepLinkMatch>();\n readonly onUnmatched = new Signal<string>();\n private readonly router: DeepLinkRouter;\n private readonly source: DeepLinkSource;\n private unsubscribe: (() => void) | null = null;\n private _current: DeepLinkMatch | null = null;\n\n constructor(options: DeepLinkManagerOptions) {\n this.router = options.router;\n this.source = options.source;\n }\n\n get current(): DeepLinkMatch | null {\n return this._current;\n }\n\n async start(): Promise<void> {\n if (this.unsubscribe) return;\n this.unsubscribe = this.source.subscribe((url) => this.handle(url));\n const initial = await Promise.resolve(this.source.getInitialUrl());\n if (initial) this.handle(initial);\n }\n\n stop(): void {\n if (this.unsubscribe) {\n this.unsubscribe();\n this.unsubscribe = null;\n }\n }\n\n handle(url: string): DeepLinkMatch | null {\n const match = this.router.match(url);\n if (!match) {\n this.onUnmatched.emit(url);\n return null;\n }\n this._current = match;\n this.onMatch.emit(match);\n return match;\n }\n}\n","import type { DeepLinkSource } from './manager.js';\n\n/**\n * In-memory source useful for tests and for host apps that want to push URLs\n * manually (e.g., from a notification handler).\n */\nexport function createMemorySource(initialUrl: string | null = null): DeepLinkSource & {\n push(url: string): void;\n} {\n let initial = initialUrl;\n const listeners = new Set<(url: string) => void>();\n return {\n getInitialUrl() {\n const v = initial;\n initial = null;\n return v;\n },\n subscribe(handler) {\n listeners.add(handler);\n return () => listeners.delete(handler);\n },\n push(url: string) {\n for (const l of listeners) l(url);\n },\n };\n}\n\n/**\n * Minimal shape of the globals a web browser exposes. Defined locally so\n * we don't pull in DOM lib types across the monorepo.\n */\ninterface WebWindowLike {\n location: { href: string };\n addEventListener: (type: string, listener: () => void) => void;\n removeEventListener: (type: string, listener: () => void) => void;\n}\n\n/**\n * Web `popstate` + `location.href` adapter. Call `notify(url)` after any\n * programmatic `history.pushState` if you want the manager to react.\n */\nexport function createWebSource(win: WebWindowLike): DeepLinkSource & {\n notify(url: string): void;\n} {\n const listeners = new Set<(url: string) => void>();\n const onPop = (): void => {\n const href = win.location.href;\n for (const l of listeners) l(href);\n };\n return {\n getInitialUrl() {\n return win.location.href;\n },\n subscribe(handler) {\n listeners.add(handler);\n win.addEventListener('popstate', onPop);\n return () => {\n listeners.delete(handler);\n win.removeEventListener('popstate', onPop);\n };\n },\n notify(url: string) {\n for (const l of listeners) l(url);\n },\n };\n}\n\n/**\n * Minimal shape of the React Native `Linking` module. Passing this lets the\n * host wire deep links on iOS/Android without this package depending on RN.\n */\nexport interface LinkingLike {\n getInitialURL(): Promise<string | null>;\n addEventListener(type: 'url', handler: (event: { url: string }) => void): { remove: () => void };\n}\n\nexport function createNativeSource(linking: LinkingLike): DeepLinkSource {\n return {\n getInitialUrl() {\n return linking.getInitialURL();\n },\n subscribe(handler) {\n const sub = linking.addEventListener('url', (e) => handler(e.url));\n return () => sub.remove();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBO,SAAS,SAAS,KAA+B;AACtD,MAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,EAAG,QAAO;AACxD,MAAI,OAAO;AACX,MAAI,SAAwB;AAC5B,MAAI,OAAsB;AAE1B,QAAM,YAAY,KAAK,QAAQ,KAAK;AACpC,MAAI,cAAc,IAAI;AACpB,aAAS,KAAK,MAAM,GAAG,SAAS;AAChC,WAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,UAAM,WAAW,KAAK,QAAQ,GAAG;AACjC,QAAI,aAAa,IAAI;AACnB,aAAO;AACP,aAAO;AAAA,IACT,OAAO;AACL,aAAO,KAAK,MAAM,GAAG,QAAQ;AAC7B,aAAO,KAAK,MAAM,QAAQ;AAAA,IAC5B;AAAA,EACF;AAGA,QAAM,UAAU,KAAK,QAAQ,GAAG;AAChC,MAAI,YAAY,GAAI,QAAO,KAAK,MAAM,GAAG,OAAO;AAEhD,MAAI,OAAO;AACX,MAAI,WAAW;AACf,QAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B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AAgB;AACd,aAAO,IAAI,SAAS;AAAA,IACtB;AAAA,IACA,UAAU,SAAS;AACjB,gBAAU,IAAI,OAAO;AACrB,UAAI,iBAAiB,YAAY,KAAK;AACtC,aAAO,MAAM;AACX,kBAAU,OAAO,OAAO;AACxB,YAAI,oBAAoB,YAAY,KAAK;AAAA,MAC3C;AAAA,IACF;AAAA,IACA,OAAO,KAAa;AAClB,iBAAW,KAAK,UAAW,GAAE,GAAG;AAAA,IAClC;AAAA,EACF;AACF;AAWO,SAAS,mBAAmB,SAAsC;AACvE,SAAO;AAAA,IACL,gBAAgB;AACd,aAAO,QAAQ,cAAc;AAAA,IAC/B;AAAA,IACA,UAAU,SAAS;AACjB,YAAM,MAAM,QAAQ,iBAAiB,OAAO,CAAC,MAAM,QAAQ,EAAE,GAAG,CAAC;AACjE,aAAO,MAAM,IAAI,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// src/parse.ts
|
|
2
|
+
function parseUrl(url) {
|
|
3
|
+
if (typeof url !== "string" || url.length === 0) return null;
|
|
4
|
+
let rest = url;
|
|
5
|
+
let scheme = null;
|
|
6
|
+
let host = null;
|
|
7
|
+
const schemeIdx = rest.indexOf("://");
|
|
8
|
+
if (schemeIdx !== -1) {
|
|
9
|
+
scheme = rest.slice(0, schemeIdx);
|
|
10
|
+
rest = rest.slice(schemeIdx + 3);
|
|
11
|
+
const slashIdx = rest.indexOf("/");
|
|
12
|
+
if (slashIdx === -1) {
|
|
13
|
+
host = rest;
|
|
14
|
+
rest = "/";
|
|
15
|
+
} else {
|
|
16
|
+
host = rest.slice(0, slashIdx);
|
|
17
|
+
rest = rest.slice(slashIdx);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const hashIdx = rest.indexOf("#");
|
|
21
|
+
if (hashIdx !== -1) rest = rest.slice(0, hashIdx);
|
|
22
|
+
let path = rest;
|
|
23
|
+
let queryStr = "";
|
|
24
|
+
const qIdx = rest.indexOf("?");
|
|
25
|
+
if (qIdx !== -1) {
|
|
26
|
+
path = rest.slice(0, qIdx);
|
|
27
|
+
queryStr = rest.slice(qIdx + 1);
|
|
28
|
+
}
|
|
29
|
+
const segments = path.split("/").filter((s) => s.length > 0).map(safeDecode);
|
|
30
|
+
const query = {};
|
|
31
|
+
if (queryStr.length > 0) {
|
|
32
|
+
for (const pair of queryStr.split("&")) {
|
|
33
|
+
if (pair.length === 0) continue;
|
|
34
|
+
const eq = pair.indexOf("=");
|
|
35
|
+
const rawKey = eq === -1 ? pair : pair.slice(0, eq);
|
|
36
|
+
const rawVal = eq === -1 ? "" : pair.slice(eq + 1);
|
|
37
|
+
const key = safeDecode(rawKey);
|
|
38
|
+
if (key.length === 0) continue;
|
|
39
|
+
query[key] = safeDecode(rawVal);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { scheme, host, segments, query };
|
|
43
|
+
}
|
|
44
|
+
function safeDecode(s) {
|
|
45
|
+
try {
|
|
46
|
+
return decodeURIComponent(s.replace(/\+/g, "%20"));
|
|
47
|
+
} catch {
|
|
48
|
+
return s;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/router.ts
|
|
53
|
+
var DeepLinkRouter = class {
|
|
54
|
+
routes = [];
|
|
55
|
+
register(pattern, scene) {
|
|
56
|
+
this.routes.push({ scene, segments: compile(pattern) });
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
registerAll(defs) {
|
|
60
|
+
for (const def of defs) this.register(def.pattern, def.scene);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
match(url) {
|
|
64
|
+
const parsed = parseUrl(url);
|
|
65
|
+
if (!parsed) return null;
|
|
66
|
+
for (const route of this.routes) {
|
|
67
|
+
const params = tryMatch(route, parsed.segments);
|
|
68
|
+
if (!params) continue;
|
|
69
|
+
const combined = { ...parsed.query, ...params };
|
|
70
|
+
return { scene: route.scene, params: combined, url };
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function compile(pattern) {
|
|
76
|
+
return pattern.split("/").filter((s) => s.length > 0).map((s) => {
|
|
77
|
+
if (s === "*") return { wildcard: true };
|
|
78
|
+
if (s.startsWith(":")) return { param: s.slice(1) };
|
|
79
|
+
return { literal: s };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function tryMatch(route, segs) {
|
|
83
|
+
const out = {};
|
|
84
|
+
const segCount = route.segments.length;
|
|
85
|
+
for (let i = 0; i < segCount; i++) {
|
|
86
|
+
const def = route.segments[i];
|
|
87
|
+
if (!def) return null;
|
|
88
|
+
if (def.wildcard) {
|
|
89
|
+
out.rest = segs.slice(i).join("/");
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
const actual = segs[i];
|
|
93
|
+
if (actual === void 0) return null;
|
|
94
|
+
if (def.literal !== void 0) {
|
|
95
|
+
if (def.literal !== actual) return null;
|
|
96
|
+
} else if (def.param !== void 0) {
|
|
97
|
+
out[def.param] = actual;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (segs.length !== segCount) return null;
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/manager.ts
|
|
105
|
+
import { Signal } from "@flare-engine/events";
|
|
106
|
+
var DeepLinkManager = class {
|
|
107
|
+
onMatch = new Signal();
|
|
108
|
+
onUnmatched = new Signal();
|
|
109
|
+
router;
|
|
110
|
+
source;
|
|
111
|
+
unsubscribe = null;
|
|
112
|
+
_current = null;
|
|
113
|
+
constructor(options) {
|
|
114
|
+
this.router = options.router;
|
|
115
|
+
this.source = options.source;
|
|
116
|
+
}
|
|
117
|
+
get current() {
|
|
118
|
+
return this._current;
|
|
119
|
+
}
|
|
120
|
+
async start() {
|
|
121
|
+
if (this.unsubscribe) return;
|
|
122
|
+
this.unsubscribe = this.source.subscribe((url) => this.handle(url));
|
|
123
|
+
const initial = await Promise.resolve(this.source.getInitialUrl());
|
|
124
|
+
if (initial) this.handle(initial);
|
|
125
|
+
}
|
|
126
|
+
stop() {
|
|
127
|
+
if (this.unsubscribe) {
|
|
128
|
+
this.unsubscribe();
|
|
129
|
+
this.unsubscribe = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
handle(url) {
|
|
133
|
+
const match = this.router.match(url);
|
|
134
|
+
if (!match) {
|
|
135
|
+
this.onUnmatched.emit(url);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
this._current = match;
|
|
139
|
+
this.onMatch.emit(match);
|
|
140
|
+
return match;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/sources.ts
|
|
145
|
+
function createMemorySource(initialUrl = null) {
|
|
146
|
+
let initial = initialUrl;
|
|
147
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
148
|
+
return {
|
|
149
|
+
getInitialUrl() {
|
|
150
|
+
const v = initial;
|
|
151
|
+
initial = null;
|
|
152
|
+
return v;
|
|
153
|
+
},
|
|
154
|
+
subscribe(handler) {
|
|
155
|
+
listeners.add(handler);
|
|
156
|
+
return () => listeners.delete(handler);
|
|
157
|
+
},
|
|
158
|
+
push(url) {
|
|
159
|
+
for (const l of listeners) l(url);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function createWebSource(win) {
|
|
164
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
165
|
+
const onPop = () => {
|
|
166
|
+
const href = win.location.href;
|
|
167
|
+
for (const l of listeners) l(href);
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
getInitialUrl() {
|
|
171
|
+
return win.location.href;
|
|
172
|
+
},
|
|
173
|
+
subscribe(handler) {
|
|
174
|
+
listeners.add(handler);
|
|
175
|
+
win.addEventListener("popstate", onPop);
|
|
176
|
+
return () => {
|
|
177
|
+
listeners.delete(handler);
|
|
178
|
+
win.removeEventListener("popstate", onPop);
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
notify(url) {
|
|
182
|
+
for (const l of listeners) l(url);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function createNativeSource(linking) {
|
|
187
|
+
return {
|
|
188
|
+
getInitialUrl() {
|
|
189
|
+
return linking.getInitialURL();
|
|
190
|
+
},
|
|
191
|
+
subscribe(handler) {
|
|
192
|
+
const sub = linking.addEventListener("url", (e) => handler(e.url));
|
|
193
|
+
return () => sub.remove();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export {
|
|
198
|
+
DeepLinkManager,
|
|
199
|
+
DeepLinkRouter,
|
|
200
|
+
createMemorySource,
|
|
201
|
+
createNativeSource,
|
|
202
|
+
createWebSource,
|
|
203
|
+
parseUrl
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts","../src/router.ts","../src/manager.ts","../src/sources.ts"],"sourcesContent":["import type { Params } from './types.js';\n\n/**\n * Parse a `scheme://host/path?query` or `/path?query` URL into its path\n * segments and query params. Returns `null` if the input is malformed.\n *\n * This is intentionally minimal: it does not validate scheme, does not decode\n * fragments, and ignores username/password.\n */\nexport interface ParsedUrl {\n scheme: string | null;\n host: string | null;\n segments: string[];\n query: Params;\n}\n\nexport function parseUrl(url: string): ParsedUrl | null {\n if (typeof url !== 'string' || url.length === 0) return null;\n let rest = url;\n let scheme: string | null = null;\n let host: string | null = null;\n\n const schemeIdx = rest.indexOf('://');\n if (schemeIdx !== -1) {\n scheme = rest.slice(0, schemeIdx);\n rest = rest.slice(schemeIdx + 3);\n const slashIdx = rest.indexOf('/');\n if (slashIdx === -1) {\n host = rest;\n rest = '/';\n } else {\n host = rest.slice(0, slashIdx);\n rest = rest.slice(slashIdx);\n }\n }\n\n // Strip fragment.\n const hashIdx = rest.indexOf('#');\n if (hashIdx !== -1) rest = rest.slice(0, hashIdx);\n\n let path = rest;\n let queryStr = '';\n const qIdx = rest.indexOf('?');\n if (qIdx !== -1) {\n path = rest.slice(0, qIdx);\n queryStr = rest.slice(qIdx + 1);\n }\n\n const segments = path\n .split('/')\n .filter((s) => s.length > 0)\n .map(safeDecode);\n const query: Params = {};\n if (queryStr.length > 0) {\n for (const pair of queryStr.split('&')) {\n if (pair.length === 0) continue;\n const eq = pair.indexOf('=');\n const rawKey = eq === -1 ? pair : pair.slice(0, eq);\n const rawVal = eq === -1 ? '' : pair.slice(eq + 1);\n const key = safeDecode(rawKey);\n if (key.length === 0) continue;\n query[key] = safeDecode(rawVal);\n }\n }\n\n return { scheme, host, segments, query };\n}\n\nfunction safeDecode(s: string): string {\n try {\n return decodeURIComponent(s.replace(/\\+/g, '%20'));\n } catch {\n return s;\n }\n}\n","import { parseUrl } from './parse.js';\nimport type { DeepLinkMatch, Params } from './types.js';\n\n/**\n * Route pattern like `/bench/:id` or `/shop/:category/:item`. Segments\n * starting with `:` are captured; literal segments must match exactly.\n * The `*` segment matches the remainder of the path into a `rest` param.\n */\nexport interface RouteDefinition {\n pattern: string;\n scene: string;\n}\n\ninterface CompiledRoute {\n scene: string;\n segments: Array<{ literal?: string; param?: string; wildcard?: boolean }>;\n}\n\nexport class DeepLinkRouter {\n private routes: CompiledRoute[] = [];\n\n register(pattern: string, scene: string): this {\n this.routes.push({ scene, segments: compile(pattern) });\n return this;\n }\n\n registerAll(defs: readonly RouteDefinition[]): this {\n for (const def of defs) this.register(def.pattern, def.scene);\n return this;\n }\n\n match(url: string): DeepLinkMatch | null {\n const parsed = parseUrl(url);\n if (!parsed) return null;\n for (const route of this.routes) {\n const params = tryMatch(route, parsed.segments);\n if (!params) continue;\n const combined: Params = { ...parsed.query, ...params };\n return { scene: route.scene, params: combined, url };\n }\n return null;\n }\n}\n\nfunction compile(pattern: string): CompiledRoute['segments'] {\n return pattern\n .split('/')\n .filter((s) => s.length > 0)\n .map((s) => {\n if (s === '*') return { wildcard: true };\n if (s.startsWith(':')) return { param: s.slice(1) };\n return { literal: s };\n });\n}\n\nfunction tryMatch(route: CompiledRoute, segs: readonly string[]): Params | null {\n const out: Params = {};\n const segCount = route.segments.length;\n for (let i = 0; i < segCount; i++) {\n const def = route.segments[i];\n if (!def) return null;\n if (def.wildcard) {\n out.rest = segs.slice(i).join('/');\n return out;\n }\n const actual = segs[i];\n if (actual === undefined) return null;\n if (def.literal !== undefined) {\n if (def.literal !== actual) return null;\n } else if (def.param !== undefined) {\n out[def.param] = actual;\n }\n }\n if (segs.length !== segCount) return null;\n return out;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { DeepLinkRouter } from './router.js';\nimport type { DeepLinkMatch } from './types.js';\n\n/**\n * Platform adapter that surfaces incoming URLs to the router. Web ships a\n * history-based adapter; RN consumers pass one that wires `Linking`.\n */\nexport interface DeepLinkSource {\n /** Current URL if the platform exposes one (e.g., `window.location.href`). */\n getInitialUrl(): Promise<string | null> | string | null;\n /** Register a handler for future URL updates; returns an unsubscribe. */\n subscribe(handler: (url: string) => void): () => void;\n}\n\nexport interface DeepLinkManagerOptions {\n router: DeepLinkRouter;\n source: DeepLinkSource;\n}\n\nexport class DeepLinkManager {\n readonly onMatch = new Signal<DeepLinkMatch>();\n readonly onUnmatched = new Signal<string>();\n private readonly router: DeepLinkRouter;\n private readonly source: DeepLinkSource;\n private unsubscribe: (() => void) | null = null;\n private _current: DeepLinkMatch | null = null;\n\n constructor(options: DeepLinkManagerOptions) {\n this.router = options.router;\n this.source = options.source;\n }\n\n get current(): DeepLinkMatch | null {\n return this._current;\n }\n\n async start(): Promise<void> {\n if (this.unsubscribe) return;\n this.unsubscribe = this.source.subscribe((url) => this.handle(url));\n const initial = await Promise.resolve(this.source.getInitialUrl());\n if (initial) this.handle(initial);\n }\n\n stop(): void {\n if (this.unsubscribe) {\n this.unsubscribe();\n this.unsubscribe = null;\n }\n }\n\n handle(url: string): DeepLinkMatch | null {\n const match = this.router.match(url);\n if (!match) {\n this.onUnmatched.emit(url);\n return null;\n }\n this._current = match;\n this.onMatch.emit(match);\n return match;\n }\n}\n","import type { DeepLinkSource } from './manager.js';\n\n/**\n * In-memory source useful for tests and for host apps that want to push URLs\n * manually (e.g., from a notification handler).\n */\nexport function createMemorySource(initialUrl: string | null = null): DeepLinkSource & {\n push(url: string): void;\n} {\n let initial = initialUrl;\n const listeners = new Set<(url: string) => void>();\n return {\n getInitialUrl() {\n const v = initial;\n initial = null;\n return v;\n },\n subscribe(handler) {\n listeners.add(handler);\n return () => listeners.delete(handler);\n },\n push(url: string) {\n for (const l of listeners) l(url);\n },\n };\n}\n\n/**\n * Minimal shape of the globals a web browser exposes. Defined locally so\n * we don't pull in DOM lib types across the monorepo.\n */\ninterface WebWindowLike {\n location: { href: string };\n addEventListener: (type: string, listener: () => void) => void;\n removeEventListener: (type: string, listener: () => void) => void;\n}\n\n/**\n * Web `popstate` + `location.href` adapter. Call `notify(url)` after any\n * programmatic `history.pushState` if you want the manager to react.\n */\nexport function createWebSource(win: WebWindowLike): DeepLinkSource & {\n notify(url: string): void;\n} {\n const listeners = new Set<(url: string) => void>();\n const onPop = (): void => {\n const href = win.location.href;\n for (const l of listeners) l(href);\n };\n return {\n getInitialUrl() {\n return win.location.href;\n },\n subscribe(handler) {\n listeners.add(handler);\n win.addEventListener('popstate', onPop);\n return () => {\n listeners.delete(handler);\n win.removeEventListener('popstate', onPop);\n };\n },\n notify(url: string) {\n for (const l of listeners) l(url);\n },\n };\n}\n\n/**\n * Minimal shape of the React Native `Linking` module. Passing this lets the\n * host wire deep links on iOS/Android without this package depending on RN.\n */\nexport interface LinkingLike {\n getInitialURL(): Promise<string | null>;\n addEventListener(type: 'url', handler: (event: { url: string }) => void): { remove: () => void };\n}\n\nexport function createNativeSource(linking: LinkingLike): DeepLinkSource {\n return {\n getInitialUrl() {\n return linking.getInitialURL();\n },\n subscribe(handler) {\n const sub = linking.addEventListener('url', (e) => handler(e.url));\n return () => sub.remove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}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flare-engine/deep-links",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "URL → scene+params router with web history + native Linking adapters",
|
|
5
|
+
"keywords": ["flare-engine", "deep-links", "router", "url"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Grzegorz Otto",
|
|
8
|
+
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/grzott/flare-engine/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/grzott/flare-engine.git",
|
|
15
|
+
"directory": "packages/deep-links"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"lint": "biome check src/",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@flare-engine/events": "^0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "restricted",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|