@master/css-binding-wasm-tooling 0.0.0-stage → 2.0.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/artifacts/mastercss_binding_wasm_tooling.d.ts +195 -0
- package/artifacts/mastercss_binding_wasm_tooling.js +1331 -0
- package/artifacts/mastercss_binding_wasm_tooling_bg.wasm +0 -0
- package/artifacts/mastercss_binding_wasm_tooling_bg.wasm.d.ts +75 -0
- package/dist/artifacts/mastercss_binding_wasm_tooling.js +1098 -0
- package/dist/index.js +126 -0
- package/dist/provider-node.d.ts +3 -0
- package/dist/provider-node.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +44 -0
- package/package.json +46 -5
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { MasterCSSError } from "@master/css-schema";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
let modulePromise;
|
|
4
|
+
const initializedInputs = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const defaultWasmURL = new URL("../artifacts/mastercss_binding_wasm_tooling_bg.wasm", import.meta.url);
|
|
6
|
+
function sameInput(left, right) {
|
|
7
|
+
return left === right || String(left) === String(right);
|
|
8
|
+
}
|
|
9
|
+
async function initializeModule(module, input) {
|
|
10
|
+
const initializedInput = initializedInputs.get(module);
|
|
11
|
+
if (initializedInput !== void 0) {
|
|
12
|
+
if (!sameInput(initializedInput, input)) throw new MasterCSSError({
|
|
13
|
+
code: "WASM_INPUT_CONFLICT",
|
|
14
|
+
domain: "binding",
|
|
15
|
+
message: "A Master CSS tooling Wasm module cannot be initialized with two different inputs."
|
|
16
|
+
});
|
|
17
|
+
return module;
|
|
18
|
+
}
|
|
19
|
+
await module.default({ module_or_path: input });
|
|
20
|
+
initializedInputs.set(module, input);
|
|
21
|
+
return module;
|
|
22
|
+
}
|
|
23
|
+
async function importGeneratedModule() {
|
|
24
|
+
return await import("./artifacts/mastercss_binding_wasm_tooling.js");
|
|
25
|
+
}
|
|
26
|
+
async function initToolingWasm(options = {}) {
|
|
27
|
+
try {
|
|
28
|
+
if (options.module) {
|
|
29
|
+
const module = options.module;
|
|
30
|
+
return await initializeModule(module, options.input || defaultWasmURL);
|
|
31
|
+
}
|
|
32
|
+
if (options.input !== void 0) return await initializeModule(await importGeneratedModule(), options.input);
|
|
33
|
+
modulePromise ??= importGeneratedModule().then((module) => initializeModule(module, defaultWasmURL)).catch((cause) => {
|
|
34
|
+
modulePromise = void 0;
|
|
35
|
+
throw cause;
|
|
36
|
+
});
|
|
37
|
+
return await modulePromise;
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
if (cause instanceof MasterCSSError) throw cause;
|
|
40
|
+
throw new MasterCSSError({
|
|
41
|
+
code: "WASM_LOAD_FAILED",
|
|
42
|
+
domain: "binding",
|
|
43
|
+
message: cause instanceof Error ? cause.message : "Cannot load the Master CSS tooling Wasm artifact."
|
|
44
|
+
}, { cause });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function createToolingScannerSession(manifestJSON, options = {}) {
|
|
48
|
+
const session = new (await (initToolingWasm(options))).ToolingScannerSession(manifestJSON);
|
|
49
|
+
return {
|
|
50
|
+
scan: (source, content) => session.scan(source, content),
|
|
51
|
+
extractCandidates: (source, content, options = {}) => session.extractCandidates(source, content, options),
|
|
52
|
+
collectCandidates: (candidates) => session.collectCandidates(candidates),
|
|
53
|
+
filterCandidates: (candidates, blocklist) => session.filterCandidates(candidates, blocklist),
|
|
54
|
+
scanCandidates: (source, content, candidates, blocklist, options = {}) => session.scanCandidates(source, content, candidates, blocklist, options),
|
|
55
|
+
removeSource: (source, options = {}) => session.removeSource(source, options),
|
|
56
|
+
reconcileSources: (owner, inputs) => session.reconcileSources(owner, inputs),
|
|
57
|
+
removeOwner: (owner) => session.removeOwner(owner),
|
|
58
|
+
ensureClasses: (classNames) => session.ensureClasses(classNames),
|
|
59
|
+
registerNativeClasses: (owner, classNames) => session.registerNativeClasses(owner, classNames),
|
|
60
|
+
reset: () => session.reset(),
|
|
61
|
+
state: () => session.state(),
|
|
62
|
+
dispose() {
|
|
63
|
+
session.dispose();
|
|
64
|
+
session.free();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function createToolingValidatorSession(manifestJSON, options = {}) {
|
|
69
|
+
const session = new (await (initToolingWasm(options))).ToolingValidatorSession(manifestJSON);
|
|
70
|
+
return {
|
|
71
|
+
nativeDeclarationCandidates: (classNames) => session.nativeDeclarationCandidates(classNames),
|
|
72
|
+
generateClasses: (classNames, nativeSupport) => session.generateClasses(classNames, nativeSupport),
|
|
73
|
+
dispose() {
|
|
74
|
+
session.dispose();
|
|
75
|
+
session.free();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function createToolingInspectionReport(input, options = {}) {
|
|
80
|
+
return (await initToolingWasm(options)).createInspectionReport(input);
|
|
81
|
+
}
|
|
82
|
+
async function createToolingLanguageSession(manifestJSON, options = {}) {
|
|
83
|
+
const session = new (await (initToolingWasm(options))).ToolingLanguageSession(manifestJSON);
|
|
84
|
+
return {
|
|
85
|
+
prepareDocument: (request) => session.prepareDocument(request),
|
|
86
|
+
finishDocument: (id, support) => session.finishDocument(id, support),
|
|
87
|
+
cancelDocument: (id) => session.cancelDocument(id),
|
|
88
|
+
analyzeDocument: (request) => session.analyzeDocument(request),
|
|
89
|
+
formatDirectives: (request) => session.formatDirectives(request),
|
|
90
|
+
nativeDeclarationCompletion: (request) => session.nativeDeclarationCompletion(request),
|
|
91
|
+
nativeDeclarationCandidates: (classNames) => session.nativeDeclarationCandidates(classNames),
|
|
92
|
+
classifyClassNames: (classNames, nativeSupport) => session.classifyClassNames(classNames, nativeSupport || []),
|
|
93
|
+
inspectClassName: (className, nativeSupport, mode) => session.inspectClassName(className, nativeSupport || [], mode),
|
|
94
|
+
tokenFamilies: () => session.tokenFamilies(),
|
|
95
|
+
completionIndex: () => session.completionIndex(),
|
|
96
|
+
colorPresentation: (colorToken) => session.colorPresentation(colorToken),
|
|
97
|
+
colorTokens: (candidates) => session.colorTokens(candidates),
|
|
98
|
+
dispose() {
|
|
99
|
+
session.dispose();
|
|
100
|
+
session.free();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function createToolingLintSession(manifestJSON, options = {}) {
|
|
105
|
+
const session = new (await (initToolingWasm(options))).ToolingLintSession(manifestJSON);
|
|
106
|
+
return {
|
|
107
|
+
inspectDesignSystem: (request) => session.inspectDesignSystem(JSON.stringify(request)),
|
|
108
|
+
suggestClasses: (declarations) => {
|
|
109
|
+
if (typeof session.suggestClasses !== "function") throw new Error("The Wasm binding does not support suggestClasses. Rebuild or update the Master CSS binding to match the tooling package.");
|
|
110
|
+
return session.suggestClasses(declarations);
|
|
111
|
+
},
|
|
112
|
+
nativeDeclarationCandidates: (classNames) => session.nativeDeclarationCandidates(classNames),
|
|
113
|
+
resolveValidation: (batch, ruleErrors) => session.resolveValidation(batch, ruleErrors),
|
|
114
|
+
canonicalClassNames: (classNames, nativeSupport, options) => session.canonicalClassNames(classNames, nativeSupport, options),
|
|
115
|
+
canonicalClassGroups: (classNames, nativeSupport, options) => session.canonicalClassGroups(classNames, nativeSupport, options),
|
|
116
|
+
rawValueCandidates: (classNames, nativeSupport, invalidGeneratedClasses) => session.rawValueCandidates(classNames, nativeSupport, invalidGeneratedClasses),
|
|
117
|
+
analyze: (classNames, nativeSupport, invalidGeneratedClasses) => session.analyze(classNames, nativeSupport, invalidGeneratedClasses),
|
|
118
|
+
analyzeClassList: (classList, classNames, nativeSupport, invalidGeneratedClasses) => session.analyzeClassList(classList, classNames, nativeSupport, invalidGeneratedClasses),
|
|
119
|
+
analyzeClassListPolicy: (requestJSON) => session.analyzeClassListPolicy(requestJSON),
|
|
120
|
+
dispose() {
|
|
121
|
+
session.dispose();
|
|
122
|
+
session.free();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export { createToolingInspectionReport, createToolingLanguageSession, createToolingLintSession, createToolingScannerSession, createToolingValidatorSession, initToolingWasm };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MasterCSSWasmToolingLoadOptions, MasterCSSWasmToolingLoadOptions as MasterCSSWasmToolingLoadOptions$1 } from "./provider.js";
|
|
2
|
+
declare function createMasterCSSToolingWasmProvider(options?: MasterCSSWasmToolingLoadOptions$1): Promise<object>;
|
|
3
|
+
export { type MasterCSSWasmToolingLoadOptions, createMasterCSSToolingWasmProvider };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createMasterCSSToolingWasmProvider as createMasterCSSToolingWasmProvider$1 } from "./provider.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
// src/provider-node.ts
|
|
4
|
+
const defaultWasmURL = new URL("../artifacts/mastercss_binding_wasm_tooling_bg.wasm", import.meta.url);
|
|
5
|
+
function resolveFileURL(input) {
|
|
6
|
+
if (input instanceof URL) return input.protocol === "file:" ? input : void 0;
|
|
7
|
+
if (typeof input !== "string" || !input.startsWith("file:")) return;
|
|
8
|
+
return new URL(input);
|
|
9
|
+
}
|
|
10
|
+
async function withNodeWasmInput(options) {
|
|
11
|
+
const fileURL = options.input === void 0 ? defaultWasmURL : resolveFileURL(options.input);
|
|
12
|
+
if (!fileURL) return options;
|
|
13
|
+
return {
|
|
14
|
+
...options,
|
|
15
|
+
input: new Uint8Array(await readFile(fileURL))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async function createMasterCSSToolingWasmProvider(options = {}) {
|
|
19
|
+
return await createMasterCSSToolingWasmProvider$1(await withNodeWasmInput(options));
|
|
20
|
+
}
|
|
21
|
+
export { createMasterCSSToolingWasmProvider };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type MasterCSSWasmToolingInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
2
|
+
interface MasterCSSWasmToolingLoadOptions {
|
|
3
|
+
readonly module?: object;
|
|
4
|
+
readonly input?: MasterCSSWasmToolingInput;
|
|
5
|
+
}
|
|
6
|
+
declare function createMasterCSSToolingWasmProvider(options?: MasterCSSWasmToolingLoadOptions): Promise<object>;
|
|
7
|
+
export { MasterCSSWasmToolingInput, MasterCSSWasmToolingLoadOptions, createMasterCSSToolingWasmProvider };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createToolingInspectionReport, createToolingLanguageSession, createToolingLintSession, createToolingScannerSession, createToolingValidatorSession, initToolingWasm } from "./index.js";
|
|
2
|
+
// src/provider.ts
|
|
3
|
+
async function createMasterCSSToolingWasmProvider(options = {}) {
|
|
4
|
+
const module = await initToolingWasm(options);
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
info: module.bindingInfo(),
|
|
7
|
+
async createLexerSession() {
|
|
8
|
+
const session = new module.ToolingLexerSession();
|
|
9
|
+
let disposed = false;
|
|
10
|
+
return Object.freeze({
|
|
11
|
+
analyze: (request) => session.analyze(request),
|
|
12
|
+
dispose() {
|
|
13
|
+
if (disposed) return;
|
|
14
|
+
disposed = true;
|
|
15
|
+
session.dispose();
|
|
16
|
+
session.free();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
async createSourceSession() {
|
|
21
|
+
const session = new module.ToolingSourceSession();
|
|
22
|
+
let disposed = false;
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
extract: (request) => session.extract(request),
|
|
25
|
+
dispose() {
|
|
26
|
+
if (disposed) return;
|
|
27
|
+
disposed = true;
|
|
28
|
+
session.dispose();
|
|
29
|
+
session.free();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
createScannerSession: (manifestJSON) => createToolingScannerSession(manifestJSON, options),
|
|
34
|
+
createValidatorSession: (manifestJSON) => createToolingValidatorSession(manifestJSON, options),
|
|
35
|
+
createLanguageSession: (manifestJSON) => createToolingLanguageSession(manifestJSON, options),
|
|
36
|
+
createLintSession: (manifestJSON) => createToolingLintSession(manifestJSON, options),
|
|
37
|
+
createInspectionReport: (input) => createToolingInspectionReport(input, options),
|
|
38
|
+
extractClassCandidates: (content) => module.extractClassCandidates(content),
|
|
39
|
+
extractOxcClasses: (source, content) => module.extractOxcClasses(source, content),
|
|
40
|
+
extractHTMLClasses: (source, content) => module.extractHTMLClasses(source, content),
|
|
41
|
+
extractAstroClasses: (source, content) => module.extractAstroClasses(source, content)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export { createMasterCSSToolingWasmProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
2
|
+
"name": "@master/css-binding-wasm-tooling",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": "^24"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "bun --bun tsdown --config ../../shared/tsdown-package.config.ts",
|
|
9
|
+
"build:artifacts": "cargo xtask build-wasm tooling",
|
|
10
|
+
"dev": "bun --bun tsdown --config ../../shared/tsdown-package.config.ts --watch",
|
|
11
|
+
"test": "bun --bun vitest run",
|
|
12
|
+
"type-check": "bun --bun tsc -b tsconfig.typecheck.json",
|
|
13
|
+
"lint": "bun --bun eslint"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"description": "Internal Master CSS tooling Wasm binding provider.",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/master-co/css.git",
|
|
20
|
+
"directory": "packages/binding-wasm-tooling"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"types": "./dist/provider.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/provider.d.ts",
|
|
27
|
+
"browser": "./dist/provider.js",
|
|
28
|
+
"node": "./dist/provider-node.js",
|
|
29
|
+
"import": "./dist/provider.js",
|
|
30
|
+
"default": "./dist/provider.js"
|
|
31
|
+
},
|
|
32
|
+
"./wasm": "./artifacts/mastercss_binding_wasm_tooling_bg.wasm"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"artifacts"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@master/css-schema": "2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"version": "2.0.0",
|
|
46
|
+
"gitHead": "6bf9adc4432b67e62613caea59d3b554711b4d54"
|
|
47
|
+
}
|
package/README.md
DELETED