-
Notifications
You must be signed in to change notification settings - Fork 754
Expand file tree
/
Copy pathshared.ts
More file actions
54 lines (49 loc) · 1.63 KB
/
Copy pathshared.ts
File metadata and controls
54 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { ComponentChildren, VNode } from "preact";
import { BUILD_ID } from "@fresh/build-id";
import { assetInternal, assetSrcSetInternal } from "./shared_internal.tsx";
/**
* Returns true when the current runtime is the browser and false otherwise. This is used for guard runtime-dependent code.
* Shorthand for the following:
* `typeof document !== "undefined"`
*
* @example
* ```
* if (IS_BROWSER) {
* alert('This is running in the browser!');
* } else {
* console.log('This code is running on the server, no access to window or alert');
* }
* ```
*
* Without this guard, alert pauses the server until return is pressed in the console.
*/
export const IS_BROWSER = typeof document !== "undefined";
/**
* Create a "locked" asset path. This differs from a plain path in that it is
* specific to the current version of the application, and as such can be safely
* served with a very long cache lifetime (1 year).
*/
export function asset(path: string): string {
return assetInternal(path, BUILD_ID);
}
/** Apply the `asset` function to urls in a `srcset` attribute. */
export function assetSrcSet(srcset: string): string {
return assetSrcSetInternal(srcset, BUILD_ID);
}
export interface PartialProps {
children?: ComponentChildren;
/**
* The name of the partial. This value must be unique across partials.
*/
name: string;
/**
* Define how the new HTML should be applied.
* @default {"replace"}
*/
mode?: "replace" | "prepend" | "append";
}
export function Partial(props: PartialProps): VNode {
// deno-lint-ignore no-explicit-any
return props.children as any;
}
Partial.displayName = "Partial";