Git Product home page Git Product logo

Comments (2)

mgmeyers avatar mgmeyers commented on May 24, 2024

This is a great idea. It could even be built into the UI of the plugin as sort of a wizard. Something like:

  1. Select the CSS file you'd like to generate a config for
  2. Define any class toggles
  3. The plugin can the display a list of all CSS variables and allow the user to select a type, output format, write a description, etc
  4. Allow the user to add headings/section and drag and drop to arrange everything

This would be a big task, but could really improve the usability of the style-settings plugin

from obsidian-style-settings.

metruzanca avatar metruzanca commented on May 24, 2024

I was actually thinking of making something similar to this before I found style-settings. Based on this css-tricks article I wrote this snippet, which might come in handy for building out this feature:

function getCSSVars() {
  const cssVarFilter = propName => propName.trim().indexOf("--") === 0;
  const sheetToDictionary = sheet => {
    let dict = {};
    for (const rule of [...sheet.cssRules]) {
      if (rule.type === 1) {
        const props = [...rule.style].filter(cssVarFilter);
        for (const propName of props) {
          const key = propName.trim()
          if (dict[key] === undefined) {
            dict[key] = [];
          }
          dict[key].push(rule.style.getPropertyValue(propName).trim())
        }
      }
    }
    return dict;
  };

  return [...document.styleSheets]
    .map(sheetToDictionary)
    .filter(dict => Object.entries(dict).length > 0)
}

Its an improved version of the code from the article, for every stylesheet it creates a map of variables and the values being set to them. Since variables can be set and then changed, I'm storing all their possible values in an array and so we'll end up with a key and all values ever assigned to that key.

The issues with this approach is its hard to identify the stylesheets. The only accurate way is to look at the content of the sheets. Though it seems like the second sheet is always obsidian's main stylesheet, the fourth is always the theme + snippets (sadly these are merged together).

Idk if this would help, I salvaged this from a trashed plugin prototype from earlier today before I found this plugin.

from obsidian-style-settings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.