@fuzdev/fuz_ui 0.191.4 → 0.193.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/dist/ApiIndex.svelte +3 -3
- package/dist/ApiModule.svelte +2 -2
- package/dist/ApiModulesList.svelte +3 -3
- package/dist/ColorSchemeInput.svelte +6 -6
- package/dist/ContextmenuLinkEntry.svelte +1 -1
- package/dist/ContextmenuRoot.svelte +10 -10
- package/dist/ContextmenuRootForSafariCompatibility.svelte +19 -19
- package/dist/ContextmenuSeparator.svelte +3 -3
- package/dist/ContextmenuSubmenu.svelte +3 -3
- package/dist/CopyToClipboard.svelte +3 -3
- package/dist/DeclarationLink.svelte +1 -1
- package/dist/Dialog.svelte +16 -16
- package/dist/Docs.svelte +12 -12
- package/dist/DocsFooter.svelte +2 -2
- package/dist/DocsList.svelte +7 -7
- package/dist/DocsMenu.svelte +4 -4
- package/dist/DocsMenu.svelte.d.ts.map +1 -1
- package/dist/DocsPageLinks.svelte +4 -4
- package/dist/DocsPrimaryNav.svelte +2 -2
- package/dist/DocsSecondaryNav.svelte +4 -4
- package/dist/DocsTertiaryNav.svelte +13 -13
- package/dist/DocsTertiaryNav.svelte.d.ts +1 -1
- package/dist/GithubLink.svelte +1 -1
- package/dist/Hashlink.svelte +2 -2
- package/dist/HueInput.svelte +5 -5
- package/dist/LibraryDetail.svelte +8 -8
- package/dist/LibrarySummary.svelte +4 -4
- package/dist/MdnLink.svelte +1 -1
- package/dist/ModuleLink.svelte +1 -1
- package/dist/PasteFromClipboard.svelte +1 -1
- package/dist/PendingAnimation.svelte +2 -2
- package/dist/PendingButton.svelte +2 -2
- package/dist/ProjectLinks.svelte +4 -4
- package/dist/Teleport.svelte +2 -2
- package/dist/ThemeInput.svelte +5 -5
- package/dist/TomeContent.svelte +3 -3
- package/dist/TomeHeader.svelte +15 -14
- package/dist/TomeHeader.svelte.d.ts.map +1 -1
- package/dist/TomeLink.svelte +13 -6
- package/dist/TomeLink.svelte.d.ts +1 -1
- package/dist/TomeLink.svelte.d.ts.map +1 -1
- package/dist/TomeSection.svelte +1 -1
- package/dist/TomeSectionHeader.svelte +3 -3
- package/dist/api_search.svelte.js +2 -2
- package/dist/contextmenu_state.svelte.d.ts.map +1 -1
- package/dist/contextmenu_state.svelte.js +11 -10
- package/dist/csp.d.ts +81 -90
- package/dist/csp.d.ts.map +1 -1
- package/dist/csp.js +145 -163
- package/dist/csp_of_fuzdev.d.ts +13 -3
- package/dist/csp_of_fuzdev.d.ts.map +1 -1
- package/dist/csp_of_fuzdev.js +23 -7
- package/dist/dimensions.svelte.d.ts.map +1 -1
- package/dist/dimensions.svelte.js +2 -2
- package/dist/library.svelte.d.ts +1 -1
- package/dist/library_generate.js +1 -1
- package/dist/style_variable_helpers.svelte.d.ts.map +1 -1
- package/dist/style_variable_helpers.svelte.js +1 -1
- package/dist/theme_state.svelte.d.ts.map +1 -1
- package/dist/theme_state.svelte.js +2 -2
- package/dist/tome.d.ts +8 -3
- package/dist/tome.d.ts.map +1 -1
- package/dist/tome.js +24 -8
- package/dist/tsdoc_helpers.d.ts +9 -0
- package/dist/tsdoc_helpers.d.ts.map +1 -1
- package/dist/tsdoc_helpers.js +15 -5
- package/package.json +5 -5
- package/src/lib/api_search.svelte.ts +2 -2
- package/src/lib/contextmenu_state.svelte.ts +11 -10
- package/src/lib/csp.ts +224 -258
- package/src/lib/csp_of_fuzdev.ts +24 -8
- package/src/lib/dimensions.svelte.ts +2 -2
- package/src/lib/library_generate.ts +1 -1
- package/src/lib/style_variable_helpers.svelte.ts +1 -1
- package/src/lib/theme_state.svelte.ts +2 -2
- package/src/lib/tome.ts +25 -8
- package/src/lib/tsdoc_helpers.ts +18 -7
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
62
|
<header>
|
|
63
|
-
<svelte:element this={final_tag} {...rest} class:
|
|
63
|
+
<svelte:element this={final_tag} {...rest} class:tome-section-header={true}>
|
|
64
64
|
<div class="flex:1">
|
|
65
65
|
{#if children}
|
|
66
66
|
{@render children()}
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
</header>
|
|
74
74
|
|
|
75
75
|
<style>
|
|
76
|
-
.
|
|
76
|
+
.tome-section-header {
|
|
77
77
|
position: relative;
|
|
78
78
|
display: flex;
|
|
79
79
|
align-items: center;
|
|
80
80
|
justify-content: space-between;
|
|
81
81
|
}
|
|
82
82
|
/* TODO @many how can this be done composably? currently using `:global` at usage site - ideally we'd continue to use :hover instead of JS */
|
|
83
|
-
.
|
|
83
|
+
.tome-section-header:hover :global(.hashlink) {
|
|
84
84
|
opacity: 1;
|
|
85
85
|
}
|
|
86
86
|
</style>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Creates unified search state for the API index page (modules and declarations).
|
|
3
3
|
*/
|
|
4
4
|
export const create_api_search = (library) => {
|
|
5
|
-
let query = $state('');
|
|
5
|
+
let query = $state.raw('');
|
|
6
6
|
// Module filtering
|
|
7
7
|
const all_modules = $derived(library.modules_sorted);
|
|
8
8
|
const filtered_modules = $derived.by(() => {
|
|
@@ -50,7 +50,7 @@ export const create_api_search = (library) => {
|
|
|
50
50
|
* Creates search state for module-specific declaration lists.
|
|
51
51
|
*/
|
|
52
52
|
export const create_module_declaration_search = (declarations) => {
|
|
53
|
-
let query = $state('');
|
|
53
|
+
let query = $state.raw('');
|
|
54
54
|
const all = $derived(declarations);
|
|
55
55
|
const filtered = $derived.by(() => {
|
|
56
56
|
const trimmed_query = query.trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextmenu_state.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/contextmenu_state.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,OAAO,EAAC,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAGvD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,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U,EAChC,GAAG,MAAM,EACT,GAAG,MAAM,EACT,aAAa,gBAAgB,EAC7B,UAAU,sBAAsB,KAC9B,OA8BF,CAAC;AAmDF,eAAO,MAAM,mBAAmB;2CAAwB,gBAAgB;4BAAhB,gBAAgB;uBAAhB,gBAAgB,WAAhB,gBAAgB;CAAG,CAAC;AAE5E,eAAO,MAAM,2BAA2B;;;;CAAiC,CAAC;AAE1E,eAAO,MAAM,8BAA8B;;;CAAyC,CAAC;AAKrF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GAAI,YAAY,MAAM,OAAO,KAAG,IAuBzE,CAAC"}
|
|
@@ -10,9 +10,9 @@ export class EntryState {
|
|
|
10
10
|
menu;
|
|
11
11
|
run;
|
|
12
12
|
disabled;
|
|
13
|
-
selected = $state(false);
|
|
14
|
-
pending = $state(false);
|
|
15
|
-
error_message = $state(null);
|
|
13
|
+
selected = $state.raw(false);
|
|
14
|
+
pending = $state.raw(false);
|
|
15
|
+
error_message = $state.raw(null);
|
|
16
16
|
promise = $state.raw(null);
|
|
17
17
|
constructor(menu, run, disabled = () => false) {
|
|
18
18
|
this.menu = menu;
|
|
@@ -24,7 +24,7 @@ export class SubmenuState {
|
|
|
24
24
|
is_menu = true;
|
|
25
25
|
menu;
|
|
26
26
|
depth;
|
|
27
|
-
selected = $state(false);
|
|
27
|
+
selected = $state.raw(false);
|
|
28
28
|
items = $state.raw([]);
|
|
29
29
|
constructor(menu, depth) {
|
|
30
30
|
this.menu = menu;
|
|
@@ -51,11 +51,11 @@ export class ContextmenuState {
|
|
|
51
51
|
*/
|
|
52
52
|
has_custom_layout;
|
|
53
53
|
// State for external consumers.
|
|
54
|
-
opened = $state(false);
|
|
55
|
-
x = $state(0);
|
|
56
|
-
y = $state(0);
|
|
54
|
+
opened = $state.raw(false);
|
|
55
|
+
x = $state.raw(0);
|
|
56
|
+
y = $state.raw(0);
|
|
57
57
|
params = $state.raw([]);
|
|
58
|
-
error = $state();
|
|
58
|
+
error = $state.raw();
|
|
59
59
|
// These arrays use immutable updates (reassignment, not mutation).
|
|
60
60
|
// If you need reactivity, use `$contextmenu` in a reactive statement to react to all changes, and
|
|
61
61
|
// then access the immutable `contextmenu.root_menu` and `contextmenu.selections`.
|
|
@@ -213,7 +213,7 @@ export class ContextmenuState {
|
|
|
213
213
|
do {
|
|
214
214
|
i.selected = true;
|
|
215
215
|
new_selections.unshift(i);
|
|
216
|
-
} while ((i = i.menu) && i.menu);
|
|
216
|
+
} while ((i = i.menu) && i.menu);
|
|
217
217
|
this.selections = new_selections;
|
|
218
218
|
}
|
|
219
219
|
collapse_selected() {
|
|
@@ -259,6 +259,8 @@ export class ContextmenuState {
|
|
|
259
259
|
}
|
|
260
260
|
select_last() {
|
|
261
261
|
const { items } = this.selections.at(-1)?.menu ?? this.root_menu;
|
|
262
|
+
if (!items.length)
|
|
263
|
+
return;
|
|
262
264
|
this.select(items.at(-1));
|
|
263
265
|
}
|
|
264
266
|
/**
|
|
@@ -339,7 +341,6 @@ export const contextmenu_open = (target, x, y, contextmenu, options) => {
|
|
|
339
341
|
// `navigator.vibrate()` works with `ContextmenuRoot` but gets blocked by some browsers
|
|
340
342
|
// when used with `ContextmenuRootForSafariCompatibility` because its longpress
|
|
341
343
|
// workaround triggers from a timeout rather than a direct user interaction.
|
|
342
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
343
344
|
if (BROWSER && vibrate && navigator.vibrate) {
|
|
344
345
|
navigator.vibrate(CONTEXTMENU_OPEN_VIBRATE_DURATION);
|
|
345
346
|
}
|
package/dist/csp.d.ts
CHANGED
|
@@ -1,121 +1,112 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Defined } from '@fuzdev/fuz_util/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Per-directive map of source arrays — accepted as `extend` layer entries.
|
|
4
|
+
* Excludes directives like `'upgrade-insecure-requests'` (boolean) that can't be appended to.
|
|
5
|
+
*/
|
|
6
|
+
export type CspDirectiveSourcesMap = {
|
|
7
|
+
[K in CspDirective as CspDirectives[K] extends ReadonlyArray<any> ? K : never]?: CspDirectives[K];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Options for `create_csp_directives`.
|
|
11
|
+
*
|
|
12
|
+
* The pipeline runs in three stages:
|
|
13
|
+
* 1. `replace_defaults` sets the starting state (defaults to `csp_directive_value_defaults`).
|
|
14
|
+
* 2. `extend` appends sources per directive, layered left to right.
|
|
15
|
+
* 3. `overrides` replaces or removes per-directive values as a final pass.
|
|
16
|
+
*/
|
|
2
17
|
export interface CreateCspDirectivesOptions {
|
|
3
18
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
19
|
+
* Starting values per directive — *wholesale replaces* the library defaults.
|
|
20
|
+
*
|
|
21
|
+
* - Omitted: uses `csp_directive_value_defaults` (the curated library defaults).
|
|
22
|
+
* - Provided: exactly the directives you list, nothing else inherited.
|
|
23
|
+
* Anything not listed is **absent** from the starting state — including security defaults
|
|
24
|
+
* like `default-src: 'none'`. To tweak a single directive while keeping the rest, use
|
|
25
|
+
* `extend` (to append) or `overrides` (to replace per-key) instead.
|
|
26
|
+
* - `{}`: starts blank with no directives.
|
|
27
|
+
*
|
|
28
|
+
* `null` is not accepted (top-level or per-key) — omit the option to use library defaults,
|
|
29
|
+
* pass `{}` to start blank, or use `overrides` to remove a specific directive.
|
|
30
|
+
*
|
|
31
|
+
* Per-key `undefined` is treated as omitted (no-op).
|
|
6
32
|
*/
|
|
7
|
-
|
|
8
|
-
[K in CspDirective]?: CspDirectiveValue<K> | null | ((value: CspDirectiveValue<K>) => CspDirectiveValue<K> | null);
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Sources to include based on their trust levels.
|
|
12
|
-
*/
|
|
13
|
-
trusted_sources?: Array<CspSourceSpec>;
|
|
33
|
+
replace_defaults?: Partial<typeof csp_directive_value_defaults>;
|
|
14
34
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
35
|
+
* Sources to append per directive, layered left to right.
|
|
36
|
+
* Each entry is a partial map; values append to the result of `replace_defaults` and prior entries.
|
|
37
|
+
* Values are deduplicated within and across layers.
|
|
38
|
+
*
|
|
39
|
+
* Only array-typed directives can be extended (boolean directives like `upgrade-insecure-requests`
|
|
40
|
+
* are excluded by the type). Throws if any entry attempts to extend a directive whose current
|
|
41
|
+
* value is `['none']` — use `replace_defaults` or `overrides` to opt into default-deny directives.
|
|
42
|
+
*
|
|
43
|
+
* Per-key `undefined` is treated as omitted (no-op) — supports conditional patterns like
|
|
44
|
+
* `{'connect-src': is_prod ? [API_URL] : undefined}`. Per-key `null` throws — `extend` only
|
|
45
|
+
* appends; use `overrides: { 'X': null }` to remove a directive.
|
|
17
46
|
*/
|
|
18
|
-
|
|
47
|
+
extend?: ReadonlyArray<CspDirectiveSourcesMap>;
|
|
19
48
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
49
|
+
* Final-pass per-directive overrides. Replaces the directive value or removes it entirely.
|
|
50
|
+
* Pass `null` to remove a directive from the output.
|
|
51
|
+
*
|
|
52
|
+
* Highest precedence — wins over `replace_defaults` and `extend`.
|
|
53
|
+
*
|
|
54
|
+
* Per-key `undefined` is treated as omitted (no-op) — distinct from `null`, which removes.
|
|
23
55
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* merging with `required_trust_defaults_base` (or replacing if that directive is null in the base).
|
|
28
|
-
*/
|
|
29
|
-
required_trust_defaults?: Partial<typeof csp_directive_required_trust_defaults>;
|
|
30
|
-
/**
|
|
31
|
-
* Base values for directive trust requirements.
|
|
32
|
-
* Set to `null` or `{}` to start with no trust requirements.
|
|
33
|
-
* Defaults to `csp_directive_required_trust_defaults`.
|
|
34
|
-
*/
|
|
35
|
-
required_trust_defaults_base?: Partial<typeof csp_directive_required_trust_defaults> | null;
|
|
56
|
+
overrides?: {
|
|
57
|
+
[K in CspDirective]?: CspDirectiveValue<K> | null;
|
|
58
|
+
};
|
|
36
59
|
}
|
|
37
60
|
/**
|
|
38
|
-
*
|
|
39
|
-
* and maps to the `KitConfig` `directives` option.
|
|
40
|
-
* The goal is to provide an ergonomic, modern, and safe API
|
|
41
|
-
* for Content Security Policy (CSP) creation
|
|
42
|
-
* that's simple to write and audit, and isn't error-prone.
|
|
61
|
+
* Builds a CSP directives map for use with SvelteKit's `kit.csp.directives` option.
|
|
43
62
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
63
|
+
* Restrictive by default; opt into specific permissions via `extend` (append) or
|
|
64
|
+
* `overrides` (replace). Designed to read as an audit log: every user-added source
|
|
65
|
+
* is named at exactly one site in the source code. Library defaults are inherited
|
|
66
|
+
* unless you opt out via `replace_defaults`.
|
|
67
|
+
*
|
|
68
|
+
* Validation:
|
|
69
|
+
* - Unknown directive keys throw.
|
|
70
|
+
* - Extending a `['none']` directive throws (use `replace_defaults`/`overrides` to opt in).
|
|
71
|
+
* - `null` for `replace_defaults` (top-level or per-key) throws — omit the option for library
|
|
72
|
+
* defaults, pass `{}` to start blank, or use `overrides` to remove a specific directive.
|
|
73
|
+
* - `null` per-key in `extend` throws (use `overrides` for removal).
|
|
74
|
+
* - `undefined` per-key is treated as omitted in all three stages.
|
|
75
|
+
* - Non-object entries in `extend` (`null`, `undefined`, primitives) throw with a friendly error.
|
|
76
|
+
* - Output is validated to ensure `'none'` never appears alongside other tokens,
|
|
77
|
+
* that no directive ends up with an empty array (use `['none']` to forbid all),
|
|
78
|
+
* and that every source array contains only strings.
|
|
79
|
+
*
|
|
80
|
+
* Things like rendering to a string are out of scope and left to SvelteKit.
|
|
46
81
|
*/
|
|
47
|
-
export declare
|
|
82
|
+
export declare const create_csp_directives: (options?: CreateCspDirectivesOptions) => CspDirectives;
|
|
48
83
|
export type CspDirective = keyof CspDirectives;
|
|
49
84
|
export declare const parse_csp_directive: (directive: unknown) => CspDirective | null;
|
|
50
85
|
export type CspDirectiveValue<T extends CspDirective> = Defined<CspDirectives[T]>;
|
|
51
|
-
export declare const
|
|
52
|
-
/**
|
|
53
|
-
* Numeric values for CSP trust levels. See `csp_trust_levels`.
|
|
54
|
-
* Lower is less trusted.
|
|
55
|
-
* Includes `undefined` in the type for safety.
|
|
56
|
-
*/
|
|
57
|
-
export declare const csp_trust_level_value: Record<CspTrustLevel, number | undefined>;
|
|
86
|
+
export declare const COLOR_SCHEME_SCRIPT_HASH = "sha256-QOxqn7EUzb3ydF9SALJoJGWSvywW9R0AfTDSenB83Z8=";
|
|
58
87
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
88
|
+
* The library CSP directive defaults — directives enabled out of the box.
|
|
89
|
+
* Prioritizes safety but loosens around media and styles, relying on defense-in-depth.
|
|
90
|
+
* WASM compile is allowed (`'wasm-unsafe-eval'` on `script-src` and `worker-src`); `eval` is not.
|
|
62
91
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* - `medium` – Content that may affect layout, styling, or embed external browsing contexts,
|
|
66
|
-
* but cannot directly run code in the page's JS execution environment or
|
|
67
|
-
* perform other high-risk actions. Examples: `style-src`, `frame-src`, `frame-ancestors`.
|
|
68
|
-
* - `high` – Sources that can execute code in the page's context or open powerful network
|
|
69
|
-
* channels. Examples: `script-src`, `connect-src`, `child-src`.
|
|
70
|
-
* - `null` – No trust. This is used for directives that don't support sources.
|
|
92
|
+
* Directives not listed here (`report-to`, `require-trusted-types-for`, `trusted-types`,
|
|
93
|
+
* `sandbox`) are intentionally absent by default — opt in via `replace_defaults` or `overrides`.
|
|
71
94
|
*
|
|
95
|
+
* Customizable via `CreateCspDirectivesOptions.replace_defaults`.
|
|
72
96
|
*/
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
export declare const parse_csp_trust_level: (trust: unknown) => CspTrustLevel | null;
|
|
78
|
-
export interface CspSourceSpec {
|
|
79
|
-
source: CspSource;
|
|
80
|
-
trust?: CspTrustLevel;
|
|
81
|
-
directives?: Array<CspDirective>;
|
|
82
|
-
}
|
|
97
|
+
export declare const csp_directive_value_defaults: Partial<{
|
|
98
|
+
[K in CspDirective]: CspDirectiveValue<K>;
|
|
99
|
+
}>;
|
|
83
100
|
export interface CspDirectiveSpec {
|
|
84
101
|
name: CspDirective;
|
|
85
102
|
fallback: Array<CspDirective> | null;
|
|
86
103
|
fallback_of: Array<CspDirective> | null;
|
|
87
104
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Determines if a granted trust level is sufficient to satisfy a required trust level.
|
|
90
|
-
*
|
|
91
|
-
* Trust levels have the following hierarchy:
|
|
92
|
-
* - 'high' sources can be used in high, medium, and low trust directives (highest privilege)
|
|
93
|
-
* - 'medium' sources can be used in medium and low trust directives
|
|
94
|
-
* - 'low' sources can only be used in low trust directives (lowest privilege)
|
|
95
|
-
*/
|
|
96
|
-
export declare const is_csp_trusted: (required_trust: CspTrustLevel | null | undefined, granted_trust: CspTrustLevel | null | undefined) => boolean;
|
|
97
|
-
export declare const COLOR_SCHEME_SCRIPT_HASH = "sha256-QOxqn7EUzb3ydF9SALJoJGWSvywW9R0AfTDSenB83Z8=";
|
|
98
|
-
/**
|
|
99
|
-
* The base CSP directive defaults.
|
|
100
|
-
* Prioritizes safety but loosens around media and styles, relying on defense-in-depth.
|
|
101
|
-
* Customizable via `CreateCspDirectivesOptions`.
|
|
102
|
-
*/
|
|
103
|
-
export declare const csp_directive_value_defaults: Record<CspDirective, CspDirectiveValue<CspDirective> | null>;
|
|
104
|
-
/**
|
|
105
|
-
* Sources that meet this trust requirement are included for it by default.
|
|
106
|
-
* If null, no trusted sources are added to the directive automatically.
|
|
107
|
-
* Directives that don't support sources or default to `['none']` are null.
|
|
108
|
-
*
|
|
109
|
-
* Feedback is welcome, please see the issues - https://github.com/fuzdev/fuz_ui/issues
|
|
110
|
-
*/
|
|
111
|
-
export declare const csp_directive_required_trust_defaults: Record<CspDirective, CspTrustLevel | null>;
|
|
112
105
|
/**
|
|
113
106
|
* Static data descriptors for the CSP directives.
|
|
114
107
|
* Fuz excludes deprecated directives, so those are intentionally omitted,
|
|
115
108
|
* but any newer missing directives are bugs.
|
|
116
109
|
*
|
|
117
|
-
* Could be co-located but is currently here to keep that module smaller.
|
|
118
|
-
*
|
|
119
110
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy}
|
|
120
111
|
*/
|
|
121
112
|
export declare const csp_directive_specs: Array<CspDirectiveSpec>;
|
package/dist/csp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/csp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/csp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAIvD;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;KACnC,CAAC,IAAI,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CACjG,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;;;;;;;;;;;;;OAcG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC,OAAO,4BAA4B,CAAC,CAAC;IAEhE;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAE/C;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE;SACV,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI;KACjD,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAS,0BA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