@master/css-binding-wasm-compiler 0.0.0-stage → 3.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/dist/index.js ADDED
@@ -0,0 +1,95 @@
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_compiler_bg.wasm", import.meta.url);
6
+ async function importGeneratedModule() {
7
+ return await import("./artifacts/mastercss_binding_wasm_compiler.js");
8
+ }
9
+ async function resolveWasmInput(input) {
10
+ return input || defaultWasmURL;
11
+ }
12
+ function sameInput(left, right) {
13
+ return left === right || String(left) === String(right);
14
+ }
15
+ async function initializeModule(module, input) {
16
+ const initializedInput = initializedInputs.get(module);
17
+ if (initializedInput !== void 0) {
18
+ if (!sameInput(initializedInput, input)) throw new MasterCSSError({
19
+ code: "WASM_INPUT_CONFLICT",
20
+ domain: "binding",
21
+ message: "A Master CSS compiler Wasm module cannot be initialized with two different inputs."
22
+ });
23
+ return module;
24
+ }
25
+ await module.default({ module_or_path: input });
26
+ initializedInputs.set(module, input);
27
+ compilerBindingInfo(module);
28
+ return module;
29
+ }
30
+ async function initCompilerWasm(options = {}) {
31
+ try {
32
+ if (options.module) {
33
+ const module = options.module;
34
+ return await initializeModule(module, await resolveWasmInput(options.input));
35
+ }
36
+ if (options.input !== void 0) return await initializeModule(await importGeneratedModule(), await resolveWasmInput(options.input));
37
+ modulePromise ??= importGeneratedModule().then(async (module) => initializeModule(module, await resolveWasmInput(defaultWasmURL))).catch((cause) => {
38
+ modulePromise = void 0;
39
+ throw cause;
40
+ });
41
+ return await modulePromise;
42
+ } catch (cause) {
43
+ if (cause instanceof MasterCSSError) throw cause;
44
+ throw new MasterCSSError({
45
+ code: "WASM_LOAD_FAILED",
46
+ domain: "binding",
47
+ message: cause instanceof Error ? cause.message : "Cannot load the Master CSS compiler Wasm artifact."
48
+ }, { cause });
49
+ }
50
+ }
51
+ function compilerBindingInfo(module) {
52
+ return module.bindingInfo();
53
+ }
54
+ async function createCompilerWasmSession(options = {}) {
55
+ const module = await initCompilerWasm(options);
56
+ return {
57
+ info: compilerBindingInfo(module),
58
+ compareProjectSnapshots: (request) => module.compareProjectSnapshots(request),
59
+ inspectCSS: (source) => module.inspectCSS(source),
60
+ compileNativeCSS: (source, compileOptions) => module.compileNativeCSS(source, compileOptions),
61
+ compileCSSDirectives: (source, compileOptions) => module.compileCSSDirectives(source, compileOptions),
62
+ analyzeCSSDependencies: (source) => module.analyzeCSSDependencies(source),
63
+ analyzeStandaloneDirectives: (source) => module.analyzeStandaloneDirectives(source),
64
+ mergeCSSExtractionPolicies: (policies) => module.mergeCSSExtractionPolicies(policies),
65
+ filterCSSExtractionCandidates: (candidates, blocklist) => module.filterCSSExtractionCandidates(candidates, blocklist),
66
+ compileManifestInput: (input, compileOptions) => module.compileManifestInput(input, compileOptions),
67
+ lowerCSSDirectives: (request, compileOptions) => module.lowerCSSDirectives(request, compileOptions),
68
+ normalizeManifestForJSON: (manifest) => module.normalizeManifestForJSON(manifest),
69
+ normalizeDefaultManifestForJSON: (manifest) => module.normalizeDefaultManifestForJSON(manifest),
70
+ compileDefaultPresetManifest: (request) => module.compileDefaultPresetManifest(request),
71
+ resolveCSSImportGraph: (request) => module.resolveCSSImportGraph(request),
72
+ resolveCSSStylesheetGraph: (request) => module.resolveCSSStylesheetGraph(request),
73
+ prepareCSSStylesheetBundle: (request) => module.prepareCSSStylesheetBundle(request),
74
+ renderCSSStylesheetBundle: (request) => module.renderCSSStylesheetBundle(request),
75
+ compileCSSStylesheetGraph: (request) => JSON.parse(module.compileCSSStylesheetGraph(JSON.stringify(request)))
76
+ };
77
+ }
78
+ async function createCompilerRenderSession(manifestJSON, emittedGlobalsJSON, options = {}) {
79
+ const session = new (await (initCompilerWasm(options))).CompilerRenderSession(manifestJSON, emittedGlobalsJSON);
80
+ let disposed = false;
81
+ return {
82
+ nativeDeclarationCandidates: (classNames) => session.nativeDeclarationCandidates(classNames),
83
+ ensureClasses: (classNames) => session.ensureClasses(classNames),
84
+ ensureStylesheetResources: (nativeCSS) => session.ensureStylesheetResources(nativeCSS),
85
+ emittedGlobals: () => session.emittedGlobals(),
86
+ snapshot: () => session.snapshot(),
87
+ dispose() {
88
+ if (disposed) return;
89
+ disposed = true;
90
+ session.dispose();
91
+ session.free();
92
+ }
93
+ };
94
+ }
95
+ export { createCompilerRenderSession, createCompilerWasmSession, initCompilerWasm };
@@ -0,0 +1,3 @@
1
+ import { MasterCSSWasmCompilerLoadOptions, MasterCSSWasmCompilerLoadOptions as MasterCSSWasmCompilerLoadOptions$1 } from "./provider.js";
2
+ declare function createMasterCSSCompilerWasmProvider(options?: MasterCSSWasmCompilerLoadOptions$1): Promise<object>;
3
+ export { type MasterCSSWasmCompilerLoadOptions, createMasterCSSCompilerWasmProvider };
@@ -0,0 +1,21 @@
1
+ import { createMasterCSSCompilerWasmProvider as createMasterCSSCompilerWasmProvider$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_compiler_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 createMasterCSSCompilerWasmProvider(options = {}) {
19
+ return await createMasterCSSCompilerWasmProvider$1(await withNodeWasmInput(options));
20
+ }
21
+ export { createMasterCSSCompilerWasmProvider };
@@ -0,0 +1,7 @@
1
+ type MasterCSSWasmCompilerInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
2
+ interface MasterCSSWasmCompilerLoadOptions {
3
+ readonly module?: object;
4
+ readonly input?: MasterCSSWasmCompilerInput;
5
+ }
6
+ declare function createMasterCSSCompilerWasmProvider(options?: MasterCSSWasmCompilerLoadOptions): Promise<object>;
7
+ export { MasterCSSWasmCompilerInput, MasterCSSWasmCompilerLoadOptions, createMasterCSSCompilerWasmProvider };
@@ -0,0 +1,11 @@
1
+ import { createCompilerRenderSession, createCompilerWasmSession, initCompilerWasm } from "./index.js";
2
+ // src/provider.ts
3
+ async function createMasterCSSCompilerWasmProvider(options = {}) {
4
+ const module = await initCompilerWasm(options);
5
+ return Object.freeze({
6
+ info: module.bindingInfo(),
7
+ createSession: () => createCompilerWasmSession(options),
8
+ createRenderSession: (manifestJSON, emittedGlobalsJSON) => createCompilerRenderSession(manifestJSON, emittedGlobalsJSON, options)
9
+ });
10
+ }
11
+ export { createMasterCSSCompilerWasmProvider };
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
- "name": "@master/css-binding-wasm-compiler",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@master/css-binding-wasm-compiler",
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 compiler",
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 compiler Wasm binding provider.",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/master-co/css.git",
20
+ "directory": "packages/binding-wasm-compiler"
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_compiler_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": "3.0.0"
44
+ },
45
+ "version": "3.0.0",
46
+ "gitHead": "a5da5f2d73901082314a082d5213fd18e11ad48b"
47
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.