@ckeditor/ckeditor5-dev-utils
Version:
Utils for CKEditor 5 development tools packages.
37 lines (34 loc) • 1.21 kB
JavaScript
import { Buffer } from 'node:buffer';
import { transform } from 'lightningcss';
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* Transforms editor styles using Lightning CSS.
*/
function ckLightningCssLoader(source, map) {
try {
const loaderOptions = this.getOptions ? this.getOptions() : this.query || {};
const lightningCssOptions = loaderOptions.lightningCssOptions || {};
let inputSourceMap;
if (typeof map === 'string') {
inputSourceMap = map;
}
else if (map) {
inputSourceMap = JSON.stringify(map);
}
const result = transform({
...lightningCssOptions,
filename: this.resourcePath,
code: Buffer.from(source),
inputSourceMap
});
const sourceMap = result.map ? JSON.parse(Buffer.from(result.map).toString()) : undefined;
this.callback(null, Buffer.from(result.code).toString(), sourceMap);
}
catch (error) {
this.callback(error instanceof Error ? error : new Error(String(error)));
}
}
export { ckLightningCssLoader as default };