Skip to content

Commit

Permalink
refactor(core/style): improve code comments a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Dec 28, 2023
1 parent 8cb0278 commit 2e8df8a
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/core/style.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// @ts-check
// Module core/style
// Inserts the CSS that ReSpec uses into the document.
//
// IMPORTANT NOTE
// To add you own styles, create a plugin that declares the css as a dependency
// and create a build of your new ReSpec profile.
//
// CONFIGURATION
// - noReSpecCSS: if you're using a profile that loads this module but you don't want
// the style, set this to true
import css from "../styles/respec.css.js";
// The purpose of this module is to insert the default ReSpec CSS into the document.
// If you don't want to use the default ReSpec CSS, set the `noReSpecCSS` configuration
// option to `true`. If you want to use your own styles, create a ReSpec profile that
// includes your own styles and sets the `noReSpecCSS` configuration option to `true`.

/**
* Module Name.
* @type {string}
*/
export const name = "core/style";

// Opportunistically inserts the style, with the chance to reduce some FOUC
import css from "../styles/respec.css.js";

// Opportunistically inserts the style to reduce some FOUC.
/** @type {HTMLStyleElement} */
const styleElement = insertStyle();

/**
* Inserts the ReSpec CSS as a `style` element into the document's `head`.
* @return {HTMLStyleElement} The `style` element that was inserted.
*/
function insertStyle() {
const styleElement = document.createElement("style");
styleElement.id = "respec-mainstyle";
Expand All @@ -24,6 +28,10 @@ function insertStyle() {
return styleElement;
}

/**
* Removes the ReSpec CSS if the `noReSpecCSS` configuration option is `true`.
* @param {object} conf The document configuration object.
*/
export function run(conf) {
if (conf.noReSpecCSS) {
styleElement.remove();
Expand Down

0 comments on commit 2e8df8a

Please sign in to comment.