@@ -64,41 +64,6 @@ function recommendedLibraries() {
64
64
html : ( ) => import ( "https://cdn.jsdelivr.net/npm/htl/+esm" ) . then ( ( htl ) => htl . html ) ,
65
65
svg : ( ) => import ( "https://cdn.jsdelivr.net/npm/htl/+esm" ) . then ( ( htl ) => htl . svg ) ,
66
66
Plot : ( ) => import ( "https://cdn.jsdelivr.net/npm/@observablehq/plot/+esm" ) ,
67
- dot : async ( ) => {
68
- // TODO Incorporate this into the standard library.
69
- const viz = await import ( "https://cdn.jsdelivr.net/npm/@viz-js/viz/+esm" ) . then ( ( { instance} ) => instance ( ) ) ;
70
- return function dot ( strings ) {
71
- let string = strings [ 0 ] + "" ;
72
- let i = 0 ;
73
- let n = arguments . length ;
74
- while ( ++ i < n ) string += arguments [ i ] + "" + strings [ i ] ;
75
- const svg = viz . renderSVGElement ( string , {
76
- graphAttributes : {
77
- bgcolor : "none"
78
- } ,
79
- nodeAttributes : {
80
- color : "#00000101" ,
81
- fontcolor : "#00000101" ,
82
- fontname : "var(--sans-serif)" ,
83
- fontsize : "12"
84
- } ,
85
- edgeAttributes : {
86
- color : "#00000101"
87
- }
88
- } ) ;
89
- for ( const e of svg . querySelectorAll ( "[stroke='#000001'][stroke-opacity='0.003922']" ) ) {
90
- e . setAttribute ( "stroke" , "currentColor" ) ;
91
- e . removeAttribute ( "stroke-opacity" ) ;
92
- }
93
- for ( const e of svg . querySelectorAll ( "[fill='#000001'][fill-opacity='0.003922']" ) ) {
94
- e . setAttribute ( "fill" , "currentColor" ) ;
95
- e . removeAttribute ( "fill-opacity" ) ;
96
- }
97
- svg . remove ( ) ;
98
- svg . style = "max-width: 100%; height: auto;" ;
99
- return svg ;
100
- } ;
101
- } ,
102
67
Inputs : ( ) => {
103
68
// TODO Observable Inputs needs to include the CSS in the dist folder
104
69
// published to npm, and we should replace the __ns__ namespace with
@@ -109,7 +74,60 @@ function recommendedLibraries() {
109
74
link . href = "https://cdn.jsdelivr.net/gh/observablehq/inputs/src/style.css" ;
110
75
document . head . append ( link ) ;
111
76
return inputs ;
77
+ } ,
78
+ dot,
79
+ mermaid
80
+ } ;
81
+ }
82
+
83
+ // TODO Incorporate this into the standard library.
84
+ async function dot ( ) {
85
+ const { instance} = await import ( "https://cdn.jsdelivr.net/npm/@viz-js/viz/+esm" ) ;
86
+ const viz = await instance ( ) ;
87
+ return function dot ( strings ) {
88
+ let string = strings [ 0 ] + "" ;
89
+ let i = 0 ;
90
+ let n = arguments . length ;
91
+ while ( ++ i < n ) string += arguments [ i ] + "" + strings [ i ] ;
92
+ const svg = viz . renderSVGElement ( string , {
93
+ graphAttributes : {
94
+ bgcolor : "none"
95
+ } ,
96
+ nodeAttributes : {
97
+ color : "#00000101" ,
98
+ fontcolor : "#00000101" ,
99
+ fontname : "var(--sans-serif)" ,
100
+ fontsize : "12"
101
+ } ,
102
+ edgeAttributes : {
103
+ color : "#00000101"
104
+ }
105
+ } ) ;
106
+ for ( const e of svg . querySelectorAll ( "[stroke='#000001'][stroke-opacity='0.003922']" ) ) {
107
+ e . setAttribute ( "stroke" , "currentColor" ) ;
108
+ e . removeAttribute ( "stroke-opacity" ) ;
112
109
}
110
+ for ( const e of svg . querySelectorAll ( "[fill='#000001'][fill-opacity='0.003922']" ) ) {
111
+ e . setAttribute ( "fill" , "currentColor" ) ;
112
+ e . removeAttribute ( "fill-opacity" ) ;
113
+ }
114
+ svg . remove ( ) ;
115
+ svg . style = "max-width: 100%; height: auto;" ;
116
+ return svg ;
117
+ } ;
118
+ }
119
+
120
+ // TODO Incorporate this into the standard library.
121
+ async function mermaid ( ) {
122
+ let nextId = 0 ;
123
+ const { default : mer } = await import ( "https://cdn.jsdelivr.net/npm/mermaid/+esm" ) ;
124
+ mer . initialize ( { startOnLoad : false , securityLevel : "loose" , theme : "neutral" } ) ;
125
+ return async function mermaid ( ) {
126
+ const div = document . createElement ( "div" ) ;
127
+ div . innerHTML = ( await mer . render ( `mermaid-${ ++ nextId } ` , String . raw . apply ( String , arguments ) ) ) . svg ;
128
+ const svg = div . firstChild ;
129
+ svg . remove ( ) ;
130
+ return svg ;
113
131
} ;
114
132
}
115
133
0 commit comments