Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"build": "vite build && pwsh post-build.ps1 && publint",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json --noEmit",
"test": "vitest",
"test": "vitest run",
"test:watch": "vitest",
"test:ci": "npx playwright install chromium && vitest"
},
"devDependencies": {
Expand Down
21 changes: 16 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import { buildPiece } from "@collagejs/svelte";
import Imo from "./lib/Imo.svelte";
import { cssMountFactory } from "@collagejs/vite-css/ex";
import { CssFactory } from "@collagejs/vite-css/ex";
import type { ImoUiFactoryOptions } from "./types.js";
import { getInitialImoUiFactoryOptions } from "./shared/options.js";
import { initImoUiOptions } from "./lib/state/imoUiOptions";
import type { CorePiece } from "@collagejs/core";

const cssMount = cssMountFactory('index');
// Edge case where import.meta.url ends up in a chunk because some module imports from this file, and for
// import.meta.url to work without changes, it needs to stay in the chunk named after the entry file.
// TODO: Take some time to figure out a module graph that allows the use of CssFactory in a module that is not
// imported by any other module. That should make this edge case disappear.
const url = import.meta.url;
let base = url.substring(0, url.lastIndexOf("/") + 1);
if (base.endsWith("/assets/")) {
base = base.substring(0, base.length - "assets/".length);
}
const css = new CssFactory(base + 'index.js');

export async function imoUiFactory(options?: ImoUiFactoryOptions): Promise<CorePiece<{}>> {
const initialOptions = await getInitialImoUiFactoryOptions(options);
const mountFn = initialOptions?.base ? cssMount.bind({ base: initialOptions.base }) : cssMount;
const { mount, relocate } = css.instantiate();
initImoUiOptions(initialOptions.ui);
const corePiece = buildPiece(Imo);
return {
mount: [mountFn, corePiece.mount],
update: corePiece.update,
...corePiece,
mount: [mount, corePiece.mount],
// TODO: Once buildPiece()'s type is fixed, the ! operator should not be needed here.
relocate: [relocate, corePiece.relocate!],
};
}
1 change: 0 additions & 1 deletion src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const defaultImPostingOptions: Required<ImPostingOptions> = {
* Default IMO UI factory options.
*/
export const defaultImoUiFactoryOptions: RequiredImoUiFactoryOptions = {
base: '',
shadow: true,
ui: {
theme: 'system',
Expand Down
6 changes: 0 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ export type ImoUiOptions = {
* Options that can be specified when creating the `@collagejs/imo` UI *CollageJS* piece.
*/
export type ImoUiFactoryOptions = {
/**
* Base URL for CSS assets. This value overrides Vite's base if specified.
*
* **TIP**: Use it when serving the *CollageJS* piece from a different origin than the main page.
*/
base?: string;
/**
* Whether to mount the *CollageJS* piece inside a shadow DOM root.
*/
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
enabled: true,
provider: playwright(),
instances: [
{ browser: 'chromium' }, // can also be 'firefox' or 'webkit'
{ browser: 'chromium', headless: true }, // can also be 'firefox' or 'webkit'
],
},
},
Expand Down
Loading