@zigrivers/surface-adapter-svelte 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 +22 -0
- package/README.md +15 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +213 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ken Allred
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Surface Svelte Adapter
|
|
2
|
+
|
|
3
|
+
Svelte adapter for Surface audits.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @zigrivers/surface-adapter-svelte
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
See the repository README for usage and release guidance: https://github.com/zigrivers/surface#readme
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FrameworkAdapter, SourceFileRef, ComponentMap } from '@zigrivers/surface-core/interfaces';
|
|
2
|
+
import { Result, SurfaceError } from '@zigrivers/surface-core';
|
|
3
|
+
|
|
4
|
+
declare const SVELTE_ADAPTER_ID = "svelte";
|
|
5
|
+
interface SvelteFrameworkAdapter extends FrameworkAdapter {
|
|
6
|
+
readonly id: typeof SVELTE_ADAPTER_ID;
|
|
7
|
+
introspect(source: SourceFileRef): Promise<Result<ComponentMap, SurfaceError>>;
|
|
8
|
+
}
|
|
9
|
+
declare function createSvelteAdapter(): SvelteFrameworkAdapter;
|
|
10
|
+
|
|
11
|
+
export { SVELTE_ADAPTER_ID, type SvelteFrameworkAdapter, createSvelteAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { basename } from "path";
|
|
3
|
+
import { createSurfaceError } from "@zigrivers/surface-core";
|
|
4
|
+
import { parse } from "svelte/compiler";
|
|
5
|
+
var SVELTE_ADAPTER_ID = "svelte";
|
|
6
|
+
var NULL_REPLACEMENT_CHARACTER = "\uFFFD";
|
|
7
|
+
var SUPPORTED_EXTENSIONS = [".svelte"];
|
|
8
|
+
var COMPONENT_ATTRIBUTES = ["data-component", "data-surface-component"];
|
|
9
|
+
var SELECTOR_ATTRIBUTES = ["data-testid", "role", "aria-label"];
|
|
10
|
+
function createSvelteAdapter() {
|
|
11
|
+
return {
|
|
12
|
+
id: SVELTE_ADAPTER_ID,
|
|
13
|
+
supports: (file) => SUPPORTED_EXTENSIONS.some((extension) => file.toLowerCase().endsWith(extension)),
|
|
14
|
+
introspect(source) {
|
|
15
|
+
if (!isSourceFileRef(source)) {
|
|
16
|
+
return Promise.resolve(
|
|
17
|
+
err(
|
|
18
|
+
createSurfaceError("step_failed", "SourceFileRef requires string path and contents.")
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return Promise.resolve(ok({ entries: introspectSvelteSource(source) }));
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
return Promise.resolve(
|
|
26
|
+
err(
|
|
27
|
+
createSurfaceError("step_failed", "Failed to introspect Svelte source.", {
|
|
28
|
+
cause
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function ok(value) {
|
|
37
|
+
return { ok: true, value };
|
|
38
|
+
}
|
|
39
|
+
function err(error) {
|
|
40
|
+
return { ok: false, error };
|
|
41
|
+
}
|
|
42
|
+
function isSourceFileRef(source) {
|
|
43
|
+
if (typeof source !== "object" || source === null) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const candidate = source;
|
|
47
|
+
return typeof candidate.path === "string" && typeof candidate.contents === "string";
|
|
48
|
+
}
|
|
49
|
+
function introspectSvelteSource(source) {
|
|
50
|
+
const root = parse(source.contents, { filename: source.path, modern: true });
|
|
51
|
+
const fragment = recordValue(root)?.fragment;
|
|
52
|
+
const details = collectComponentDetails(fragment);
|
|
53
|
+
const entries = /* @__PURE__ */ new Map();
|
|
54
|
+
const component = componentNameFromPath(source.path);
|
|
55
|
+
mergeEntry(entries, source.path, component, details.selectors);
|
|
56
|
+
for (const reference of details.references) {
|
|
57
|
+
mergeEntry(entries, source.path, reference.component, [reference.selector]);
|
|
58
|
+
}
|
|
59
|
+
return [...entries.values()].map((entry) => ({
|
|
60
|
+
...entry,
|
|
61
|
+
selectors: [...new Set(entry.selectors)].sort(compareStableStrings)
|
|
62
|
+
})).sort((left, right) => compareStableStrings(left.component, right.component));
|
|
63
|
+
}
|
|
64
|
+
function collectComponentDetails(root) {
|
|
65
|
+
const references = [];
|
|
66
|
+
const selectors = [];
|
|
67
|
+
walkSvelteNodes(root, (node) => {
|
|
68
|
+
references.push(...markerReferencesFor(node));
|
|
69
|
+
selectors.push(...selectorsForSvelteNode(node));
|
|
70
|
+
});
|
|
71
|
+
return { references, selectors };
|
|
72
|
+
}
|
|
73
|
+
function walkSvelteNodes(root, visit) {
|
|
74
|
+
const pending = [root];
|
|
75
|
+
while (pending.length > 0) {
|
|
76
|
+
const value = pending.pop();
|
|
77
|
+
const node = recordValue(value);
|
|
78
|
+
if (node === void 0) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
visit(node);
|
|
82
|
+
pending.push(...nodesForFragment(node.fragment));
|
|
83
|
+
pending.push(...nodesForFragment(node));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function nodesForFragment(value) {
|
|
87
|
+
const fragment = recordValue(value);
|
|
88
|
+
const nodes = fragment?.nodes;
|
|
89
|
+
return Array.isArray(nodes) ? nodes : [];
|
|
90
|
+
}
|
|
91
|
+
function mergeEntry(entries, file, component, selectors) {
|
|
92
|
+
const key = `${file}\0${component}`;
|
|
93
|
+
const existing = entries.get(key);
|
|
94
|
+
entries.set(
|
|
95
|
+
key,
|
|
96
|
+
existing === void 0 ? { component, file, selectors: [...selectors] } : { ...existing, selectors: [...existing.selectors, ...selectors] }
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function markerReferencesFor(node) {
|
|
100
|
+
return COMPONENT_ATTRIBUTES.flatMap((attribute) => {
|
|
101
|
+
const rawValue = svelteStringAttribute(node, attribute);
|
|
102
|
+
const component = sanitizeComponentName(rawValue);
|
|
103
|
+
return component === void 0 || !isComponentName(component) ? [] : [{ component, selector: `[${attribute}="${escapeCssString(rawValue ?? "")}"]` }];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function selectorsForSvelteNode(node) {
|
|
107
|
+
const elementName = stringValue(node.name);
|
|
108
|
+
if (elementName === void 0) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const selectors = [];
|
|
112
|
+
for (const attribute of COMPONENT_ATTRIBUTES) {
|
|
113
|
+
const value = svelteStringAttribute(node, attribute);
|
|
114
|
+
if (value !== void 0 && value.trim().length > 0) {
|
|
115
|
+
selectors.push(`[${attribute}="${escapeCssString(value)}"]`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const id = svelteStringAttribute(node, "id");
|
|
119
|
+
if (id !== void 0 && id.trim().length > 0) {
|
|
120
|
+
selectors.push(`[id="${escapeCssString(id)}"]`);
|
|
121
|
+
}
|
|
122
|
+
for (const attribute of SELECTOR_ATTRIBUTES) {
|
|
123
|
+
const value = svelteStringAttribute(node, attribute);
|
|
124
|
+
if (value !== void 0 && value.trim().length > 0) {
|
|
125
|
+
selectors.push(`[${attribute}="${escapeCssString(value)}"]`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (node.type === "Component" && isComponentName(elementName)) {
|
|
129
|
+
selectors.push(`svelte:${elementName}`);
|
|
130
|
+
}
|
|
131
|
+
if (node.type === "SvelteComponent") {
|
|
132
|
+
const expressionName = identifierName(node.expression);
|
|
133
|
+
if (expressionName !== void 0 && isComponentName(expressionName)) {
|
|
134
|
+
selectors.push(`svelte:${expressionName}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (selectors.length > 0) {
|
|
138
|
+
return selectors;
|
|
139
|
+
}
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
function svelteStringAttribute(node, name) {
|
|
143
|
+
const attribute = nodeAttributes(node).find((candidate) => candidate.name === name);
|
|
144
|
+
const value = attribute?.value;
|
|
145
|
+
if (value === true) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
if (typeof value === "string") {
|
|
149
|
+
return normalizeNullCharacters(value);
|
|
150
|
+
}
|
|
151
|
+
if (!Array.isArray(value) || value.length !== 1) {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
const valueNode = recordValue(value[0]);
|
|
155
|
+
if (valueNode?.type !== "Text") {
|
|
156
|
+
return void 0;
|
|
157
|
+
}
|
|
158
|
+
return stringValue(valueNode.data) ?? stringValue(valueNode.raw);
|
|
159
|
+
}
|
|
160
|
+
function nodeAttributes(node) {
|
|
161
|
+
return Array.isArray(node.attributes) ? node.attributes.filter(isRecord) : [];
|
|
162
|
+
}
|
|
163
|
+
function componentNameFromPath(path) {
|
|
164
|
+
const withoutExtension = basename(path).replace(/\.svelte$/iu, "");
|
|
165
|
+
const normalized = withoutExtension.split(/[^a-z0-9]+/iu).filter((part) => part.length > 0).map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
|
|
166
|
+
return normalized.length === 0 ? "Component" : normalized;
|
|
167
|
+
}
|
|
168
|
+
function identifierName(value) {
|
|
169
|
+
const node = recordValue(value);
|
|
170
|
+
return node?.type === "Identifier" ? stringValue(node.name) : void 0;
|
|
171
|
+
}
|
|
172
|
+
function compareStableStrings(left, right) {
|
|
173
|
+
if (left < right) {
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
return left > right ? 1 : 0;
|
|
177
|
+
}
|
|
178
|
+
function isComponentName(value) {
|
|
179
|
+
return /^[A-Z][A-Za-z0-9_]*$/u.test(value);
|
|
180
|
+
}
|
|
181
|
+
function sanitizeComponentName(value) {
|
|
182
|
+
const component = value === void 0 ? void 0 : normalizeNullCharacters(value).trim();
|
|
183
|
+
return component === void 0 || component.length === 0 ? void 0 : component;
|
|
184
|
+
}
|
|
185
|
+
function normalizeNullCharacters(value) {
|
|
186
|
+
return value.replaceAll("\0", NULL_REPLACEMENT_CHARACTER);
|
|
187
|
+
}
|
|
188
|
+
function escapeCssString(value) {
|
|
189
|
+
return Array.from(normalizeNullCharacters(value), (character) => {
|
|
190
|
+
const codePoint = character.codePointAt(0);
|
|
191
|
+
if (codePoint >= 1 && codePoint <= 31 || codePoint === 127) {
|
|
192
|
+
return `\\${codePoint.toString(16)} `;
|
|
193
|
+
}
|
|
194
|
+
if (character === '"' || character === "\\") {
|
|
195
|
+
return `\\${character}`;
|
|
196
|
+
}
|
|
197
|
+
return character;
|
|
198
|
+
}).join("");
|
|
199
|
+
}
|
|
200
|
+
function stringValue(value) {
|
|
201
|
+
return typeof value === "string" ? value : void 0;
|
|
202
|
+
}
|
|
203
|
+
function recordValue(value) {
|
|
204
|
+
return isRecord(value) ? value : void 0;
|
|
205
|
+
}
|
|
206
|
+
function isRecord(value) {
|
|
207
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
SVELTE_ADAPTER_ID,
|
|
211
|
+
createSvelteAdapter
|
|
212
|
+
};
|
|
213
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { basename } from \"node:path\";\n\nimport type {\n ComponentMap,\n ComponentMapEntry,\n FrameworkAdapter,\n SourceFileRef,\n} from \"@zigrivers/surface-core/interfaces\";\nimport { createSurfaceError, type Result, type SurfaceError } from \"@zigrivers/surface-core\";\nimport { parse } from \"svelte/compiler\";\n\nexport const SVELTE_ADAPTER_ID = \"svelte\";\n\nconst NULL_REPLACEMENT_CHARACTER = \"\\uFFFD\";\nconst SUPPORTED_EXTENSIONS = [\".svelte\"] as const;\nconst COMPONENT_ATTRIBUTES = [\"data-component\", \"data-surface-component\"] as const;\nconst SELECTOR_ATTRIBUTES = [\"data-testid\", \"role\", \"aria-label\"] as const;\n\ntype AstNode = Readonly<Record<string, unknown>>;\ntype ComponentReference = { readonly component: string; readonly selector: string };\ntype ComponentDetails = {\n readonly references: readonly ComponentReference[];\n readonly selectors: readonly string[];\n};\n\nexport interface SvelteFrameworkAdapter extends FrameworkAdapter {\n readonly id: typeof SVELTE_ADAPTER_ID;\n introspect(source: SourceFileRef): Promise<Result<ComponentMap, SurfaceError>>;\n}\n\nexport function createSvelteAdapter(): SvelteFrameworkAdapter {\n return {\n id: SVELTE_ADAPTER_ID,\n supports: (file: string) =>\n SUPPORTED_EXTENSIONS.some((extension) => file.toLowerCase().endsWith(extension)),\n introspect(source: SourceFileRef) {\n if (!isSourceFileRef(source)) {\n return Promise.resolve(\n err(\n createSurfaceError(\"step_failed\", \"SourceFileRef requires string path and contents.\"),\n ),\n );\n }\n\n try {\n return Promise.resolve(ok({ entries: introspectSvelteSource(source) }));\n } catch (cause) {\n return Promise.resolve(\n err(\n createSurfaceError(\"step_failed\", \"Failed to introspect Svelte source.\", {\n cause,\n }),\n ),\n );\n }\n },\n };\n}\n\nfunction ok<T>(value: T): Result<T, SurfaceError> {\n return { ok: true, value };\n}\n\nfunction err(error: SurfaceError): Result<never, SurfaceError> {\n return { ok: false, error };\n}\n\nfunction isSourceFileRef(source: unknown): source is SourceFileRef {\n if (typeof source !== \"object\" || source === null) {\n return false;\n }\n\n const candidate = source as { readonly path?: unknown; readonly contents?: unknown };\n\n return typeof candidate.path === \"string\" && typeof candidate.contents === \"string\";\n}\n\nfunction introspectSvelteSource(source: SourceFileRef): ComponentMapEntry[] {\n const root = parse(source.contents, { filename: source.path, modern: true }) as unknown;\n const fragment = recordValue(root)?.fragment;\n const details = collectComponentDetails(fragment);\n const entries = new Map<string, ComponentMapEntry>();\n const component = componentNameFromPath(source.path);\n\n mergeEntry(entries, source.path, component, details.selectors);\n\n for (const reference of details.references) {\n mergeEntry(entries, source.path, reference.component, [reference.selector]);\n }\n\n return [...entries.values()]\n .map((entry) => ({\n ...entry,\n selectors: [...new Set(entry.selectors)].sort(compareStableStrings),\n }))\n .sort((left, right) => compareStableStrings(left.component, right.component));\n}\n\nfunction collectComponentDetails(root: unknown): ComponentDetails {\n const references: ComponentReference[] = [];\n const selectors: string[] = [];\n\n walkSvelteNodes(root, (node) => {\n references.push(...markerReferencesFor(node));\n selectors.push(...selectorsForSvelteNode(node));\n });\n\n return { references, selectors };\n}\n\nfunction walkSvelteNodes(root: unknown, visit: (node: AstNode) => void): void {\n const pending: unknown[] = [root];\n\n while (pending.length > 0) {\n const value = pending.pop();\n const node = recordValue(value);\n\n if (node === undefined) {\n continue;\n }\n\n visit(node);\n pending.push(...nodesForFragment(node.fragment));\n pending.push(...nodesForFragment(node));\n }\n}\n\nfunction nodesForFragment(value: unknown): readonly unknown[] {\n const fragment = recordValue(value);\n const nodes = fragment?.nodes;\n\n return Array.isArray(nodes) ? nodes : [];\n}\n\nfunction mergeEntry(\n entries: Map<string, ComponentMapEntry>,\n file: string,\n component: string,\n selectors: readonly string[],\n): void {\n const key = `${file}\\0${component}`;\n const existing = entries.get(key);\n\n entries.set(\n key,\n existing === undefined\n ? { component, file, selectors: [...selectors] }\n : { ...existing, selectors: [...existing.selectors, ...selectors] },\n );\n}\n\nfunction markerReferencesFor(node: AstNode): ComponentReference[] {\n return COMPONENT_ATTRIBUTES.flatMap((attribute) => {\n const rawValue = svelteStringAttribute(node, attribute);\n const component = sanitizeComponentName(rawValue);\n\n return component === undefined || !isComponentName(component)\n ? []\n : [{ component, selector: `[${attribute}=\"${escapeCssString(rawValue ?? \"\")}\"]` }];\n });\n}\n\nfunction selectorsForSvelteNode(node: AstNode): string[] {\n const elementName = stringValue(node.name);\n\n if (elementName === undefined) {\n return [];\n }\n\n const selectors: string[] = [];\n\n for (const attribute of COMPONENT_ATTRIBUTES) {\n const value = svelteStringAttribute(node, attribute);\n\n if (value !== undefined && value.trim().length > 0) {\n selectors.push(`[${attribute}=\"${escapeCssString(value)}\"]`);\n }\n }\n\n const id = svelteStringAttribute(node, \"id\");\n\n if (id !== undefined && id.trim().length > 0) {\n selectors.push(`[id=\"${escapeCssString(id)}\"]`);\n }\n\n for (const attribute of SELECTOR_ATTRIBUTES) {\n const value = svelteStringAttribute(node, attribute);\n\n if (value !== undefined && value.trim().length > 0) {\n selectors.push(`[${attribute}=\"${escapeCssString(value)}\"]`);\n }\n }\n\n if (node.type === \"Component\" && isComponentName(elementName)) {\n selectors.push(`svelte:${elementName}`);\n }\n\n if (node.type === \"SvelteComponent\") {\n const expressionName = identifierName(node.expression);\n\n if (expressionName !== undefined && isComponentName(expressionName)) {\n selectors.push(`svelte:${expressionName}`);\n }\n }\n\n if (selectors.length > 0) {\n return selectors;\n }\n\n return [];\n}\n\nfunction svelteStringAttribute(node: AstNode, name: string): string | undefined {\n const attribute = nodeAttributes(node).find((candidate) => candidate.name === name);\n const value = attribute?.value;\n\n if (value === true) {\n return \"\";\n }\n\n if (typeof value === \"string\") {\n return normalizeNullCharacters(value);\n }\n\n if (!Array.isArray(value) || value.length !== 1) {\n return undefined;\n }\n\n const valueNode = recordValue(value[0]);\n\n if (valueNode?.type !== \"Text\") {\n return undefined;\n }\n\n return stringValue(valueNode.data) ?? stringValue(valueNode.raw);\n}\n\nfunction nodeAttributes(node: AstNode): readonly AstNode[] {\n return Array.isArray(node.attributes) ? node.attributes.filter(isRecord) : [];\n}\n\nfunction componentNameFromPath(path: string): string {\n const withoutExtension = basename(path).replace(/\\.svelte$/iu, \"\");\n const normalized = withoutExtension\n .split(/[^a-z0-9]+/iu)\n .filter((part) => part.length > 0)\n .map((part) => part[0]?.toUpperCase() + part.slice(1))\n .join(\"\");\n\n return normalized.length === 0 ? \"Component\" : normalized;\n}\n\nfunction identifierName(value: unknown): string | undefined {\n const node = recordValue(value);\n\n return node?.type === \"Identifier\" ? stringValue(node.name) : undefined;\n}\n\nfunction compareStableStrings(left: string, right: string): number {\n if (left < right) {\n return -1;\n }\n\n return left > right ? 1 : 0;\n}\n\nfunction isComponentName(value: string): boolean {\n return /^[A-Z][A-Za-z0-9_]*$/u.test(value);\n}\n\nfunction sanitizeComponentName(value: string | undefined): string | undefined {\n const component = value === undefined ? undefined : normalizeNullCharacters(value).trim();\n\n return component === undefined || component.length === 0 ? undefined : component;\n}\n\nfunction normalizeNullCharacters(value: string): string {\n return value.replaceAll(\"\\0\", NULL_REPLACEMENT_CHARACTER);\n}\n\nfunction escapeCssString(value: string): string {\n return Array.from(normalizeNullCharacters(value), (character) => {\n const codePoint = character.codePointAt(0)!;\n\n if ((codePoint >= 1 && codePoint <= 0x1f) || codePoint === 0x7f) {\n return `\\\\${codePoint.toString(16)} `;\n }\n\n if (character === '\"' || character === \"\\\\\") {\n return `\\\\${character}`;\n }\n\n return character;\n }).join(\"\");\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nfunction recordValue(value: unknown): AstNode | undefined {\n return isRecord(value) ? value : undefined;\n}\n\nfunction isRecord(value: unknown): value is AstNode {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAQzB,SAAS,0BAA0D;AACnE,SAAS,aAAa;AAEf,IAAM,oBAAoB;AAEjC,IAAM,6BAA6B;AACnC,IAAM,uBAAuB,CAAC,SAAS;AACvC,IAAM,uBAAuB,CAAC,kBAAkB,wBAAwB;AACxE,IAAM,sBAAsB,CAAC,eAAe,QAAQ,YAAY;AAczD,SAAS,sBAA8C;AAC5D,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,UAAU,CAAC,SACT,qBAAqB,KAAK,CAAC,cAAc,KAAK,YAAY,EAAE,SAAS,SAAS,CAAC;AAAA,IACjF,WAAW,QAAuB;AAChC,UAAI,CAAC,gBAAgB,MAAM,GAAG;AAC5B,eAAO,QAAQ;AAAA,UACb;AAAA,YACE,mBAAmB,eAAe,kDAAkD;AAAA,UACtF;AAAA,QACF;AAAA,MACF;AAEA,UAAI;AACF,eAAO,QAAQ,QAAQ,GAAG,EAAE,SAAS,uBAAuB,MAAM,EAAE,CAAC,CAAC;AAAA,MACxE,SAAS,OAAO;AACd,eAAO,QAAQ;AAAA,UACb;AAAA,YACE,mBAAmB,eAAe,uCAAuC;AAAA,cACvE;AAAA,YACF,CAAC;AA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9C,SAAO,MAAM,KAAK,wBAAwB,KAAK,GAAG,CAAC,cAAc;AAC/D,UAAM,YAAY,UAAU,YAAY,CAAC;AAEzC,QAAK,aAAa,KAAK,aAAa,MAAS,cAAc,KAAM;AAC/D,aAAO,KAAK,UAAU,SAAS,EAAE,CAAC;AAAA,IACpC;AAEA,QAAI,cAAc,OAAO,cAAc,MAAM;AAC3C,aAAO,KAAK,SAAS;AAAA,IACvB;AAEA,WAAO;AAAA,EACT,CAAC,EAAE,KAAK,EAAE;AACZ;AAEA,SAAS,YAAY,OAAoC;AACvD,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,YAAY,OAAqC;AACxD,SAAO,SAAS,KAAK,IAAI,QAAQ;AACnC;AAEA,SAAS,SAAS,OAAkC;AAClD,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zigrivers/surface-adapter-svelte",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"svelte": "^5.0.0",
|
|
20
|
+
"@zigrivers/surface-core": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.13.0",
|
|
24
|
+
"eslint": "^9.39.4",
|
|
25
|
+
"tsup": "^8.5.1",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"vitest": "^4.0.14"
|
|
28
|
+
},
|
|
29
|
+
"description": "Svelte adapter for Surface audits",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"homepage": "https://github.com/zigrivers/surface#readme",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/zigrivers/surface.git",
|
|
35
|
+
"directory": "packages/adapters/svelte"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/zigrivers/surface/issues"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"surface",
|
|
42
|
+
"adapter",
|
|
43
|
+
"svelte"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": true
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"build:smoke": "node scripts/build-smoke.mjs",
|
|
52
|
+
"clean": "node scripts/clean.mjs",
|
|
53
|
+
"lint": "eslint src",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|