Millennium icon indicating copy to clipboard operation
Millennium copied to clipboard

[Feature] Better plugin CSS injection

Open shdwmtr opened this issue 1 year ago • 1 comments

Before Requesting

  • [X] I found no existing issue matching my feature request
  • [X] This request is related to Millennium, and not a request for a specific theme/addon

Describe the feature you'd like!

A better way to inject CSS into windows without having to manage CSS files on disk

Anything else?

POC:

import styles from './styles.css';
Millennium.insertStyles(document /* the window to inject into */, styles);

Here we statically rollup CSS into the dist JavaScript instead of leaving it on disk, and having to move it into steamui during runtime.

shdwmtr avatar Dec 15 '24 06:12 shdwmtr

Opted for a better implementation with constSysfsExpr, more documentation will follow soon.

As of now:

interface FileInfo {
    content: string;
    filePath: string;
    fileName: string;
}
interface SingleFileExprProps {
    basePath?: string;
    encoding?: BufferEncoding;
}
interface MultiFileExprProps {
    basePath?: string;
    include?: string;
    encoding?: BufferEncoding;
}
/**
 * @brief Create a compile time filesystem expression.
 * This function will evaluate a file path at compile time, and embed a files content statically into the bundle.
 */
declare const constSysfsExpr: {
    (fileName: string, props: SingleFileExprProps): FileInfo;
    (props: MultiFileExprProps): FileInfo[];
};

Example usage

import { constSysfsExpr } from '@steambrew/client';

const asset1 = constSysfsExpr('file1.txt', {
	basePath: './assets',
	encoding: 'utf8',
});

console.log('asset1', asset1); // file content

const allAssets = constSysfsExpr({
	basePath: './assets',
	include: '*.txt',
	encoding: 'utf8',
});

console.log('all assets', allAssets); // array of file contents

Requires

"@steambrew/api": "^5.2.4",
"@steambrew/client": "^5.2.4",
"@steambrew/ttc": "^2.4.2",
"@steambrew/webkit": "^5.2.4",

shdwmtr avatar Apr 27 '25 17:04 shdwmtr