Skip to content

Support custom iconpacks - #21

Merged
remcohaszing merged 23 commits into
remcohaszing:mainfrom
constja:feat/custom-icon-packs
Feb 19, 2026
Merged

remcohaszing merged 23 commits into
remcohaszing:mainfrom
constja:feat/custom-icon-packs

Conversation

@constja

@constja constja commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Add possibility to register resolved icon packs on mermaid.

  • Added a snapshot test case that uses an icon pack
  • Created a typescript definition for sync loader (couldn't reuse the SyncIconLoader interface, since it's not exported)
  • Added reference in the documentation

solves [#17]

@remcohaszing remcohaszing left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have some remarks, but overall this work is amazing ❤️

Comment thread src/mermaid-isomorphic.ts Outdated
@@ -1,3 +1,4 @@
import type { IconifyJSON } from '@iconify/types'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you take the needed type from mermaid? That case we won’t need an explicit dependency on @iconify/types

Bonus points if you can get the Mermaid team to export this type upstream.

@constja constja Jan 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried but as you can see here nothing is exported. Only a union type of Sync + Async Loader

Also it's just a dev dependency. I think this way it would neither end up in the distributed package nor would it show up in the npm-graph

@constja constja Jan 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be ok with accepting this for now + I will create a PR with mermaid and adjust it afterwards?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait,.. got an Idea.

@constja constja Jan 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export type IconPack = Extract<
  Parameters<typeof mermaid.registerIconPacks>[0][number],
  {
    /**
     * Include only sync interface
     */
    icons: unknown
  }
>

OK or too hacky?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s give the Mermaid folks a couple of days to merge mermaid-js/mermaid#7352. If they won’t, we’ll figure out some clever way to get it.

Comment thread src/mermaid-isomorphic.ts Outdated
Comment thread src/mermaid-isomorphic.ts
Comment thread src/test.ts Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
@constja
constja requested a review from remcohaszing January 28, 2026 12:31
remcohaszing added a commit to remcohaszing/mermaid that referenced this pull request Jan 28, 2026
We want to use `SyncIconLoader` in `mermaid-isomorphic`.

See remcohaszing/mermaid-isomorphic#21
remcohaszing added a commit to remcohaszing/mermaid that referenced this pull request Jan 28, 2026
We want to use `SyncIconLoader` in `mermaid-isomorphic`.

See remcohaszing/mermaid-isomorphic#21
Comment thread src/mermaid-isomorphic.ts
Comment thread src/mermaid-isomorphic.ts Outdated
@@ -1,3 +1,4 @@
import type { IconifyJSON } from '@iconify/types'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s give the Mermaid folks a couple of days to merge mermaid-js/mermaid#7352. If they won’t, we’ll figure out some clever way to get it.

Comment thread README.md Outdated
Co-authored-by: Remco Haszing <remcohaszing@gmail.com>
@constja

constja commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Actually it looks like custom icons don’t use fonts, right? So then the order doesn’t matter.

I've played around a little and you can basically insert anything into the chart. It could be a SVG that uses a specific font - but It seems the order doesn't make a difference.

test.ts
    async 'custom-font-iterable.svg'(file) {
      const renderer = createMermaidRenderer()
      const results = await renderer([String(file)], {
        css: [irishGrover, irishGrover],
        mermaidConfig: { fontFamily: '"Irish Grover"' },
        iconPacks: [
          {
            name: 'custom-icons',
            icons: {
              prefix: 'custom-icons',
              icons: {
                alien: {
                  body: `<g>
                  <rect style="fill: #087ebf; stroke-width: 0px" height="80" width="500" />
                  <text
                    style="fill: #fff; font-family: Irish Grover; font-size: 67.75px"
                    transform="translate(21.16 64.67)"
                  >
                    <tspan y="65" x="15">C</tspan>
                  </text>
                </g>`,
                  width: 80,
                  height: 80
                }
              }
            }
          }
        ]
      })

      return testFixtureResults(results)
    },

Creates this png

png custom-font-iterable

@constja

constja commented Feb 2, 2026

Copy link
Copy Markdown
Contributor Author

OK seems that mermaid has merged it, now we just need to wait till they release?

@remcohaszing

Copy link
Copy Markdown
Owner

Yep, now we wait.

@constja

constja commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

Could we add my workaround and change it once they release?

@constja

constja commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

I've regenerated the fixtures and merged main, so there are no conflicts :)

@codecov

codecov Bot commented Feb 19, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@remcohaszing

Copy link
Copy Markdown
Owner

Yeah, waiting for upstream to release that is taking too long. I’ll merge this as-is.

Thank you for your contribution! ❤️

@remcohaszing
remcohaszing merged commit dd472f8 into remcohaszing:main Feb 19, 2026
14 checks passed
@constja
constja deleted the feat/custom-icon-packs branch February 20, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants