From 9d74e1679915cc0c5f56413879276fc43b093892 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 14 Jan 2026 15:47:00 +0100 Subject: load css by text --- css.js | 19 +++++++++++++------ index.js | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/css.js b/css.js index 9dbf4b0..782bd7b 100644 --- a/css.js +++ b/css.js @@ -1,12 +1,19 @@ - -async function load_sheet(url) { - const response = await fetch(url); - const content = await response.text(); +async function load_text(content) { const sheet = new CSSStyleSheet(); await sheet.replace(content); return sheet; } -export async function css(base, ...urls) { - return await Promise.all(urls.map(url => load_sheet(new URL(url, base)))) +async function load_file(url) { + const response = await fetch(url); + const content = await response.text(); + return await load_text(content); +} + +export async function sheet(...contents) { + return await Promise.all(contents.map(text => load_text(text))); +} + +export async function file(base, ...urls) { + return await Promise.all(urls.map(url => load_file(new URL(url, base)))) } diff --git a/index.js b/index.js index 06f7e94..92e2174 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -export { css } from './css.js'; +export * as css from './css.js'; export * as theme from './theme.js'; export * as element from './element/index.js' -- cgit v1.2.3-70-g09d2