@veryfront/ext-css-lightning 0.1.1186 → 0.1.1189

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/esm/deno.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ declare namespace _default {
2
+ let name: string;
3
+ let version: string;
4
+ let exports: string;
5
+ namespace veryfront {
6
+ let extension: boolean;
7
+ let activation: string;
8
+ namespace contracts {
9
+ let provides: string[];
10
+ }
11
+ let capabilities: ({
12
+ type: string;
13
+ keys: string[];
14
+ } | {
15
+ type: string;
16
+ keys?: undefined;
17
+ })[];
18
+ }
19
+ let imports: {
20
+ browserslist: string;
21
+ lightningcss: string;
22
+ "@std/assert": string;
23
+ "@std/testing/bdd": string;
24
+ "veryfront/extensions": string;
25
+ "veryfront/extensions/css": string;
26
+ };
27
+ namespace tasks {
28
+ let test: string;
29
+ }
30
+ }
31
+ export default _default;
32
+ //# sourceMappingURL=deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../src/deno.js"],"names":[],"mappings":""}
package/esm/deno.js ADDED
@@ -0,0 +1,35 @@
1
+ export default {
2
+ "name": "@veryfront/ext-css-lightning",
3
+ "version": "0.1.0",
4
+ "exports": "./src/index.ts",
5
+ "veryfront": {
6
+ "extension": true,
7
+ "activation": "explicit",
8
+ "contracts": {
9
+ "provides": ["CSSOptimizationEngine"]
10
+ },
11
+ "capabilities": [
12
+ {
13
+ "type": "env:read",
14
+ "keys": [
15
+ "CSS_TRANSFORMER_WASM",
16
+ "BROWSERSLIST_DISABLE_CACHE",
17
+ "BROWSERSLIST_IGNORE_OLD_DATA",
18
+ "BROWSERSLIST_TRACE_WARNING"
19
+ ]
20
+ },
21
+ { "type": "native:ffi" }
22
+ ]
23
+ },
24
+ "imports": {
25
+ "browserslist": "npm:browserslist@4.28.7",
26
+ "lightningcss": "npm:lightningcss@1.29.2",
27
+ "@std/assert": "jsr:@std/assert@1.0.19",
28
+ "@std/testing/bdd": "jsr:@std/testing@1.0.17/bdd",
29
+ "veryfront/extensions": "../../src/extensions/types.ts",
30
+ "veryfront/extensions/css": "../../src/extensions/css/index.ts"
31
+ },
32
+ "tasks": {
33
+ "test": "deno test --no-lock --allow-env=CSS_TRANSFORMER_WASM,BROWSERSLIST_DISABLE_CACHE,BROWSERSLIST_IGNORE_OLD_DATA,BROWSERSLIST_TRACE_WARNING --allow-ffi src/"
34
+ }
35
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Lightning CSS and Browserslist implementation of CSSOptimizationEngine.
3
+ *
4
+ * @module extensions/ext-css-lightning
5
+ */
6
+ import "../_dnt.polyfills.js";
7
+ import type { ExtensionFactory } from "veryfront/extensions";
8
+ import { type CSSOptimizationEngine, type CSSOptimizationRequest, type CSSOptimizationResult } from "veryfront/extensions/css";
9
+ export interface LightningCSSOptimizationConfig {
10
+ /** Browserslist expressions resolved once when the extension is created. */
11
+ readonly browserQueries?: readonly string[];
12
+ }
13
+ /** Parser-backed CSS optimizer provided by this extension. */
14
+ export declare class LightningCSSOptimizationEngine implements CSSOptimizationEngine {
15
+ #private;
16
+ readonly cacheIdentity: string;
17
+ constructor(config?: LightningCSSOptimizationConfig);
18
+ optimize(request: CSSOptimizationRequest): CSSOptimizationResult;
19
+ }
20
+ declare const extCSSLightning: ExtensionFactory;
21
+ export default extCSSLightning;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAE3B,MAAM,0BAA0B,CAAC;AA0ClC,MAAM,WAAW,8BAA8B;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAwbD,8DAA8D;AAC9D,qBAAa,8BAA+B,YAAW,qBAAqB;;IAC1E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAGnB,MAAM,GAAE,8BAAmC;IAqBvD,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,qBAAqB;CAqCjE;AAED,QAAA,MAAM,eAAe,EAAE,gBA2BtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,439 @@
1
+ /**
2
+ * Lightning CSS and Browserslist implementation of CSSOptimizationEngine.
3
+ *
4
+ * @module extensions/ext-css-lightning
5
+ */
6
+ import "../_dnt.polyfills.js";
7
+ import { createHash } from "node:crypto";
8
+ import process from "node:process";
9
+ import { CSSOptimizationEngineName, MAX_CSS_OPTIMIZATION_ENGINE_IDENTITY_CHARACTERS, } from "veryfront/extensions/css";
10
+ import browserslist from "browserslist";
11
+ import { browserslistToTargets, transform } from "lightningcss";
12
+ import extensionPackage from "../deno.js";
13
+ import { isWellFormedString } from "./is-well-formed-string.js";
14
+ const MAX_BROWSER_QUERIES = 32;
15
+ const MAX_BROWSER_QUERY_CHARACTERS = 256;
16
+ const MAX_RESOLVED_BROWSERS = 4_096;
17
+ const MAX_SOURCE_PATH_CHARACTERS = 4_096;
18
+ const ENGINE_SEMANTICS_VERSION = "veryfront.css-lightning.v3";
19
+ const apply = Reflect.apply;
20
+ const arrayIsArray = Array.isArray;
21
+ const freeze = Object.freeze;
22
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
23
+ const getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
24
+ const getPrototypeOf = Object.getPrototypeOf;
25
+ const hasOwn = Object.hasOwn;
26
+ const ownKeys = Reflect.ownKeys;
27
+ const createObject = Object.create;
28
+ const defineProperty = Object.defineProperty;
29
+ const arrayPush = Array.prototype.push;
30
+ const arraySort = Array.prototype.sort;
31
+ const arrayJoin = Array.prototype.join;
32
+ const encodeText = TextEncoder.prototype.encode;
33
+ const decodeText = TextDecoder.prototype.decode;
34
+ const normalizeString = String.prototype.normalize;
35
+ const trimString = String.prototype.trim;
36
+ const charCodeAtString = String.prototype.charCodeAt;
37
+ const executeRegularExpression = RegExp.prototype.exec;
38
+ const stringifyJSON = JSON.stringify;
39
+ const isSafeInteger = Number.isSafeInteger;
40
+ const isArrayBufferView = ArrayBuffer.isView;
41
+ const objectToString = Object.prototype.toString;
42
+ const ObjectPrototype = Object.prototype;
43
+ const encoder = new TextEncoder();
44
+ const decoder = new TextDecoder("utf-8", { fatal: true });
45
+ const EXACT_NPM_SPECIFIER = /^npm:(?:@[^/]+\/)?[^@/]+@([^@/]+)$/;
46
+ const INEXACT_VERSION_CHARACTER = /[~^*<>=|\s]/u;
47
+ const TARGET_NAME = /^[a-z][a-z0-9_]*$/;
48
+ function descriptorValue(object, property, label) {
49
+ const descriptor = getOwnPropertyDescriptor(object, property);
50
+ if (descriptor === undefined || !hasOwn(descriptor, "value")) {
51
+ throw new TypeError(`${label} must be an own data property`);
52
+ }
53
+ return descriptor.value;
54
+ }
55
+ function dataPropertyValue(descriptors, property, label) {
56
+ const descriptor = descriptors[property];
57
+ if (descriptor === undefined || !hasOwn(descriptor, "value")) {
58
+ throw new TypeError(`${label} must be a data property`);
59
+ }
60
+ return descriptor.value;
61
+ }
62
+ function exactNpmVersion(value, dependency) {
63
+ if (typeof value !== "string") {
64
+ throw new TypeError(`${dependency} dependency must use an exact npm version`);
65
+ }
66
+ const match = apply(executeRegularExpression, EXACT_NPM_SPECIFIER, [value]);
67
+ if (match?.[1] === undefined ||
68
+ apply(executeRegularExpression, INEXACT_VERSION_CHARACTER, [match[1]]) !==
69
+ null) {
70
+ throw new TypeError(`${dependency} dependency must use an exact npm version`);
71
+ }
72
+ return match[1];
73
+ }
74
+ const extensionVersion = descriptorValue(extensionPackage, "version", "ext-css-lightning version");
75
+ const extensionImports = descriptorValue(extensionPackage, "imports", "ext-css-lightning imports");
76
+ if (typeof extensionVersion !== "string" ||
77
+ typeof extensionImports !== "object" ||
78
+ extensionImports === null ||
79
+ arrayIsArray(extensionImports)) {
80
+ throw new TypeError("ext-css-lightning manifest is invalid");
81
+ }
82
+ const lightningCSSVersion = exactNpmVersion(descriptorValue(extensionImports, "lightningcss", "lightningcss import"), "lightningcss");
83
+ const browserslistVersion = exactNpmVersion(descriptorValue(extensionImports, "browserslist", "browserslist import"), "browserslist");
84
+ const hashPrototype = getPrototypeOf(createHash("sha256"));
85
+ const updateHashValue = descriptorValue(hashPrototype, "update", "Hash.update");
86
+ const digestHashValue = descriptorValue(hashPrototype, "digest", "Hash.digest");
87
+ if (typeof updateHashValue !== "function" ||
88
+ typeof digestHashValue !== "function") {
89
+ throw new TypeError("SHA-256 implementation is unavailable");
90
+ }
91
+ const updateHash = updateHashValue;
92
+ const digestHash = digestHashValue;
93
+ function sha256(value) {
94
+ const hash = createHash("sha256");
95
+ apply(updateHash, hash, [value, "utf8"]);
96
+ return apply(digestHash, hash, ["hex"]);
97
+ }
98
+ function hasControlOrLineSeparator(value) {
99
+ for (let index = 0; index < value.length; index++) {
100
+ const code = apply(charCodeAtString, value, [index]);
101
+ if (code <= 0x1f ||
102
+ (code >= 0x7f && code <= 0x9f) ||
103
+ code === 0x2028 ||
104
+ code === 0x2029) {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ function frozenResolvedConfig(browserQueries) {
111
+ const config = createObject(null);
112
+ defineProperty(config, "browserQueries", {
113
+ value: browserQueries,
114
+ enumerable: true,
115
+ });
116
+ return freeze(config);
117
+ }
118
+ function snapshotBrowserQueries(value) {
119
+ if (value === undefined)
120
+ return undefined;
121
+ let isArray;
122
+ try {
123
+ isArray = arrayIsArray(value);
124
+ }
125
+ catch (cause) {
126
+ throw new TypeError("ext-css-lightning browserQueries could not be inspected", { cause });
127
+ }
128
+ if (!isArray) {
129
+ throw new TypeError("ext-css-lightning browserQueries must be an array");
130
+ }
131
+ let descriptors;
132
+ try {
133
+ descriptors = getOwnPropertyDescriptors(value);
134
+ }
135
+ catch (cause) {
136
+ throw new TypeError("ext-css-lightning browserQueries could not be inspected", { cause });
137
+ }
138
+ const length = dataPropertyValue(descriptors, "length", "ext-css-lightning browserQueries length");
139
+ if (!isSafeInteger(length) ||
140
+ length < 1 ||
141
+ length > MAX_BROWSER_QUERIES ||
142
+ ownKeys(descriptors).length !== length + 1) {
143
+ throw new TypeError("ext-css-lightning browserQueries must be a bounded dense array");
144
+ }
145
+ const queries = [];
146
+ for (let index = 0; index < length; index++) {
147
+ const descriptor = descriptors[String(index)];
148
+ if (descriptor === undefined ||
149
+ !hasOwn(descriptor, "value") ||
150
+ descriptor.enumerable !== true) {
151
+ throw new TypeError("ext-css-lightning browserQueries must contain data-property strings");
152
+ }
153
+ const query = descriptor.value;
154
+ if (typeof query !== "string" ||
155
+ query.length === 0 ||
156
+ query.length > MAX_BROWSER_QUERY_CHARACTERS ||
157
+ !isWellFormedString(query) ||
158
+ apply(normalizeString, query, ["NFC"]) !== query ||
159
+ apply(trimString, query, []) !== query ||
160
+ hasControlOrLineSeparator(query)) {
161
+ throw new TypeError("ext-css-lightning browserQueries must contain canonical bounded strings");
162
+ }
163
+ apply(arrayPush, queries, [query]);
164
+ }
165
+ return freeze(queries);
166
+ }
167
+ function readConfig(value) {
168
+ if (value === undefined)
169
+ return frozenResolvedConfig(undefined);
170
+ let valueIsArray;
171
+ try {
172
+ valueIsArray = arrayIsArray(value);
173
+ }
174
+ catch (cause) {
175
+ throw new TypeError("ext-css-lightning config could not be inspected", {
176
+ cause,
177
+ });
178
+ }
179
+ if (typeof value !== "object" || value === null || valueIsArray) {
180
+ throw new TypeError("ext-css-lightning config must be an object");
181
+ }
182
+ let descriptors;
183
+ let prototype;
184
+ try {
185
+ prototype = getPrototypeOf(value);
186
+ descriptors = getOwnPropertyDescriptors(value);
187
+ }
188
+ catch (cause) {
189
+ throw new TypeError("ext-css-lightning config could not be inspected", {
190
+ cause,
191
+ });
192
+ }
193
+ if (prototype !== ObjectPrototype && prototype !== null) {
194
+ throw new TypeError("ext-css-lightning config must not inherit configuration");
195
+ }
196
+ const keys = ownKeys(descriptors);
197
+ if (keys.length > 1 || (keys.length === 1 && keys[0] !== "browserQueries")) {
198
+ throw new TypeError("ext-css-lightning config contains unsupported properties");
199
+ }
200
+ const descriptor = descriptors.browserQueries;
201
+ if (descriptor !== undefined && !hasOwn(descriptor, "value")) {
202
+ throw new TypeError("ext-css-lightning browserQueries must be a data property");
203
+ }
204
+ return frozenResolvedConfig(snapshotBrowserQueries(descriptor?.value));
205
+ }
206
+ function copyStrings(values) {
207
+ const copy = [];
208
+ for (let index = 0; index < values.length; index++) {
209
+ apply(arrayPush, copy, [values[index]]);
210
+ }
211
+ return copy;
212
+ }
213
+ function createIsolatedBrowserQueryOptions() {
214
+ return {
215
+ path: false,
216
+ stats: createObject(null),
217
+ dangerousExtend: false,
218
+ };
219
+ }
220
+ function rejectExternalBrowserQuerySources(queries) {
221
+ const parsed = browserslist.parse(copyStrings(queries), createIsolatedBrowserQueryOptions());
222
+ if (!arrayIsArray(parsed) || parsed.length > MAX_BROWSER_QUERIES * 4) {
223
+ throw new TypeError("CSS browser queries produced an invalid parse result");
224
+ }
225
+ for (let index = 0; index < parsed.length; index++) {
226
+ const type = parsed[index]?.type;
227
+ if (type === "browserslist_config" ||
228
+ type === "extends" ||
229
+ type === "popularity_in_config_stats" ||
230
+ type === "cover_config") {
231
+ throw new TypeError("CSS browser queries must not load external configuration or statistics");
232
+ }
233
+ }
234
+ }
235
+ function snapshotResolvedTargets(value) {
236
+ if (typeof value !== "object" || value === null || arrayIsArray(value)) {
237
+ throw new TypeError("Lightning CSS returned invalid browser targets");
238
+ }
239
+ const descriptors = getOwnPropertyDescriptors(value);
240
+ const keys = ownKeys(descriptors);
241
+ if (keys.length === 0 || keys.length > 128) {
242
+ throw new TypeError("Lightning CSS returned invalid browser targets");
243
+ }
244
+ for (let index = 0; index < keys.length; index++) {
245
+ if (typeof keys[index] !== "string") {
246
+ throw new TypeError("Lightning CSS returned invalid browser targets");
247
+ }
248
+ }
249
+ apply(arraySort, keys, []);
250
+ const targets = createObject(null);
251
+ for (let index = 0; index < keys.length; index++) {
252
+ const key = keys[index];
253
+ const descriptor = descriptors[key];
254
+ if (apply(executeRegularExpression, TARGET_NAME, [key]) === null ||
255
+ !hasOwn(descriptor, "value")) {
256
+ throw new TypeError("Lightning CSS returned invalid browser targets");
257
+ }
258
+ const version = descriptor.value;
259
+ if (!isSafeInteger(version) ||
260
+ version < 0 ||
261
+ version > 0xff_ffff) {
262
+ throw new TypeError("Lightning CSS returned invalid browser targets");
263
+ }
264
+ defineProperty(targets, key, {
265
+ value: version,
266
+ enumerable: true,
267
+ });
268
+ }
269
+ return freeze(targets);
270
+ }
271
+ function datasetIdentity() {
272
+ const serialized = apply(stringifyJSON, JSON, [{
273
+ data: browserslist.data,
274
+ defaults: browserslist.defaults,
275
+ nodeVersions: browserslist.nodeVersions,
276
+ usage: browserslist.usage.global,
277
+ versionAliases: browserslist.versionAliases,
278
+ }]);
279
+ if (typeof serialized !== "string") {
280
+ throw new TypeError("Browserslist dataset could not be identified");
281
+ }
282
+ return sha256(serialized);
283
+ }
284
+ const defaultBrowserQueries = snapshotBrowserQueries(browserslist.defaults);
285
+ const loadedDatasetIdentity = datasetIdentity();
286
+ const loadedRuntimeFlavor = process.env.CSS_TRANSFORMER_WASM
287
+ ? "wasm"
288
+ : `native:${process.platform}:${process.arch}`;
289
+ function resolveBrowserTargets(queries) {
290
+ const selectedQueries = queries ?? defaultBrowserQueries;
291
+ rejectExternalBrowserQuerySources(selectedQueries);
292
+ const browsers = browserslist(copyStrings(selectedQueries), createIsolatedBrowserQueryOptions());
293
+ if (!arrayIsArray(browsers) ||
294
+ browsers.length === 0 ||
295
+ browsers.length > MAX_RESOLVED_BROWSERS) {
296
+ throw new TypeError("CSS browser queries resolved to no bounded browser targets");
297
+ }
298
+ const targets = snapshotResolvedTargets(browserslistToTargets(browsers));
299
+ const identityParts = [`dataset=${loadedDatasetIdentity}`];
300
+ const targetKeys = ownKeys(targets);
301
+ apply(arraySort, targetKeys, []);
302
+ for (let index = 0; index < targetKeys.length; index++) {
303
+ const name = targetKeys[index];
304
+ apply(arrayPush, identityParts, [`${name}=${targets[name]}`]);
305
+ }
306
+ return freeze({
307
+ targets,
308
+ identity: sha256(apply(arrayJoin, identityParts, ["\n"])),
309
+ });
310
+ }
311
+ function snapshotRequest(request) {
312
+ if (typeof request !== "object" || request === null || arrayIsArray(request)) {
313
+ throw new TypeError("CSS optimization request must be an object");
314
+ }
315
+ const descriptors = getOwnPropertyDescriptors(request);
316
+ const keys = ownKeys(descriptors);
317
+ if (keys.length !== 4 ||
318
+ !hasOwn(descriptors, "css") ||
319
+ !hasOwn(descriptors, "sourcePath") ||
320
+ !hasOwn(descriptors, "minify") ||
321
+ !hasOwn(descriptors, "sourceMap")) {
322
+ throw new TypeError("CSS optimization request has an invalid shape");
323
+ }
324
+ for (let index = 0; index < keys.length; index++) {
325
+ if (keys[index] !== "css" &&
326
+ keys[index] !== "sourcePath" &&
327
+ keys[index] !== "minify" &&
328
+ keys[index] !== "sourceMap") {
329
+ throw new TypeError("CSS optimization request has an invalid shape");
330
+ }
331
+ }
332
+ const css = dataPropertyValue(descriptors, "css", "CSS optimization css");
333
+ const sourcePath = dataPropertyValue(descriptors, "sourcePath", "CSS optimization sourcePath");
334
+ const minify = dataPropertyValue(descriptors, "minify", "CSS optimization minify");
335
+ const sourceMap = dataPropertyValue(descriptors, "sourceMap", "CSS optimization sourceMap");
336
+ if (typeof css !== "string" || !isWellFormedString(css)) {
337
+ throw new TypeError("CSS optimization css must be a well-formed string");
338
+ }
339
+ if (typeof sourcePath !== "string" ||
340
+ sourcePath.length === 0 ||
341
+ sourcePath.length > MAX_SOURCE_PATH_CHARACTERS ||
342
+ !isWellFormedString(sourcePath) ||
343
+ apply(normalizeString, sourcePath, ["NFC"]) !== sourcePath ||
344
+ hasControlOrLineSeparator(sourcePath)) {
345
+ throw new TypeError("CSS optimization sourcePath must be a canonical path");
346
+ }
347
+ if (typeof minify !== "boolean" || typeof sourceMap !== "boolean") {
348
+ throw new TypeError("CSS optimization flags must be booleans");
349
+ }
350
+ return freeze({ css, sourcePath, minify, sourceMap });
351
+ }
352
+ function isByteView(value) {
353
+ return isArrayBufferView(value) &&
354
+ apply(objectToString, value, []) === "[object Uint8Array]";
355
+ }
356
+ /** Parser-backed CSS optimizer provided by this extension. */
357
+ export class LightningCSSOptimizationEngine {
358
+ cacheIdentity;
359
+ #targets;
360
+ constructor(config = {}) {
361
+ const resolved = resolveBrowserTargets(readConfig(config).browserQueries);
362
+ this.#targets = resolved.targets;
363
+ const identityParts = [
364
+ ENGINE_SEMANTICS_VERSION,
365
+ `ext-css-lightning@${extensionVersion}`,
366
+ `lightningcss@${lightningCSSVersion}`,
367
+ `browserslist@${browserslistVersion}`,
368
+ loadedRuntimeFlavor,
369
+ `targets+data=${resolved.identity}`,
370
+ ];
371
+ this.cacheIdentity = apply(arrayJoin, identityParts, [";"]);
372
+ if (this.cacheIdentity.length >
373
+ MAX_CSS_OPTIMIZATION_ENGINE_IDENTITY_CHARACTERS) {
374
+ throw new TypeError("ext-css-lightning cache identity exceeds the core limit");
375
+ }
376
+ freeze(this);
377
+ }
378
+ optimize(request) {
379
+ const input = snapshotRequest(request);
380
+ const result = transform({
381
+ filename: input.sourcePath,
382
+ code: apply(encodeText, encoder, [input.css]),
383
+ minify: input.minify,
384
+ sourceMap: input.sourceMap,
385
+ targets: this.#targets,
386
+ analyzeDependencies: false,
387
+ });
388
+ const descriptors = getOwnPropertyDescriptors(result);
389
+ const code = dataPropertyValue(descriptors, "code", "Lightning CSS code");
390
+ const mapDescriptor = descriptors.map;
391
+ if (mapDescriptor !== undefined && !hasOwn(mapDescriptor, "value")) {
392
+ throw new TypeError("Lightning CSS source map must be a data property");
393
+ }
394
+ const map = mapDescriptor?.value;
395
+ if (!isByteView(code)) {
396
+ throw new TypeError("Lightning CSS returned invalid output bytes");
397
+ }
398
+ if (input.sourceMap && !isByteView(map)) {
399
+ throw new TypeError("Lightning CSS did not return the requested source map");
400
+ }
401
+ if (!input.sourceMap && map !== undefined && map !== null) {
402
+ throw new TypeError("Lightning CSS returned an unrequested source map");
403
+ }
404
+ const css = apply(decodeText, decoder, [code]);
405
+ if (map === undefined || map === null)
406
+ return freeze({ css });
407
+ return freeze({
408
+ css,
409
+ sourceMap: apply(decodeText, decoder, [map]),
410
+ });
411
+ }
412
+ }
413
+ const extCSSLightning = (config) => {
414
+ const engine = new LightningCSSOptimizationEngine(readConfig(config));
415
+ return {
416
+ name: "ext-css-lightning",
417
+ version: extensionVersion,
418
+ contracts: {
419
+ provides: ["CSSOptimizationEngine"],
420
+ },
421
+ capabilities: [
422
+ {
423
+ type: "env:read",
424
+ keys: [
425
+ "CSS_TRANSFORMER_WASM",
426
+ "BROWSERSLIST_DISABLE_CACHE",
427
+ "BROWSERSLIST_IGNORE_OLD_DATA",
428
+ "BROWSERSLIST_TRACE_WARNING",
429
+ ],
430
+ },
431
+ { type: "native:ffi" },
432
+ ],
433
+ setup(ctx) {
434
+ ctx.provide(CSSOptimizationEngineName, engine);
435
+ ctx.logger.debug(`[ext-css-lightning] ${CSSOptimizationEngineName} registered`);
436
+ },
437
+ };
438
+ };
439
+ export default extCSSLightning;
@@ -0,0 +1,3 @@
1
+ /** Local UTF-16 well-formedness check independent of mutable host methods. */
2
+ export declare function isWellFormedString(value: string): boolean;
3
+ //# sourceMappingURL=is-well-formed-string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-well-formed-string.d.ts","sourceRoot":"","sources":["../../src/src/is-well-formed-string.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAK9E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAazD"}
@@ -0,0 +1,20 @@
1
+ /** Local UTF-16 well-formedness check independent of mutable host methods. */
2
+ const apply = Reflect.apply;
3
+ const stringCharCodeAt = String.prototype.charCodeAt;
4
+ export function isWellFormedString(value) {
5
+ for (let index = 0; index < value.length; index++) {
6
+ const codeUnit = apply(stringCharCodeAt, value, [index]);
7
+ if (codeUnit >= 0xD800 && codeUnit <= 0xDBFF) {
8
+ index++;
9
+ if (index >= value.length)
10
+ return false;
11
+ const trailingCodeUnit = apply(stringCharCodeAt, value, [index]);
12
+ if (trailingCodeUnit < 0xDC00 || trailingCodeUnit > 0xDFFF)
13
+ return false;
14
+ }
15
+ else if (codeUnit >= 0xDC00 && codeUnit <= 0xDFFF) {
16
+ return false;
17
+ }
18
+ }
19
+ return true;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfront/ext-css-lightning",
3
- "version": "0.1.1186",
3
+ "version": "0.1.1189",
4
4
  "description": "Veryfront first-party extension package for ext-css-lightning",
5
5
  "keywords": [
6
6
  "veryfront",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "scripts": {},
29
29
  "engines": {
30
- "node": ">=18.0.0"
30
+ "node": ">=22.3.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
@@ -60,7 +60,7 @@
60
60
  "lightningcss": "1.29.2"
61
61
  },
62
62
  "peerDependencies": {
63
- "veryfront": "^0.1.1186"
63
+ "veryfront": "^0.1.1189"
64
64
  },
65
65
  "type": "module",
66
66
  "types": "./esm/src/index.d.ts",