@@ -55,6 +55,11 @@ function escapeHtml(str) {
5555 . replace ( / ' / g, ''' ) ;
5656}
5757
58+ // Library version (update when changing public shortcode behavior)
59+ const CRS_VERSION = '0.1.0' ;
60+ // Export version for external use (e.g., in layouts via require) and add as global data below
61+ module . exports . CRS_VERSION = CRS_VERSION ;
62+
5863// Validation helper (stateless)
5964function validateCrid ( id ) {
6065 if ( typeof id !== 'string' ) return { ok : false , message : 'crid must be a string' } ;
@@ -385,6 +390,10 @@ class Report {
385390}
386391
387392module . exports = function ( eleventyConfig ) {
393+ // Provide version to all templates as 'crmapVersion'
394+ if ( eleventyConfig . addGlobalData ) {
395+ eleventyConfig . addGlobalData ( 'crmapVersion' , CRS_VERSION ) ;
396+ }
388397 // Usage: SECOND ARGUMENT IS OPTIONAL JSON OPTIONS STRING.
389398 // {% crmap 'path/to/file.cr' %} -> defaults (auto crid, details true, z 0, auto caption)
390399 // {% crmap 'path/to/file.cr' '{}' % } -> same as defaults
@@ -497,7 +506,7 @@ module.exports = function (eleventyConfig) {
497506
498507 // <class = "cr-report" is used as a marker to include css/js in layout!
499508
500- return `<script>window.crids = ${ JSON . stringify ( Array . from ( pageState . crids ) ) } ;<\/script >\n` +
509+ return `<!-- crmap generated by crs.js version ${ CRS_VERSION } -- >\n` +
501510 `<figure class=\"cr-report\" data-crid=\"${ crid } \">` +
502511 `<div class=\"cr-svg-wrapper\">${ svg } </div>` +
503512 ( caption ? `<figcaption class=\"cr-caption\">${ escapeHtml ( caption ) } </figcaption>` : '' ) +
@@ -512,14 +521,14 @@ module.exports = function (eleventyConfig) {
512521 // Shortcode to output region details container for a given crid
513522
514523 eleventyConfig . addShortcode ( 'crmap_rdetails' , function ( crid , placeholder = null ) {
515- // Access per-page state
516- let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
517- let useCrid = crid ;
518- if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
524+ // Access per-page state
525+ let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
526+ let useCrid = crid ;
527+ if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
519528 if ( ! useCrid ) return '<div class="cr-error" style="color:#a00">crmap_rdetails: missing crid (no crmap rendered yet)</div>' ;
520- const v = validateCrid ( useCrid . toString ( ) ) ;
529+ const v = validateCrid ( useCrid . toString ( ) ) ;
521530 if ( ! v . ok ) return `<div class=\"cr-error\" style=\"color:#a00\">${ v . message } </div>` ;
522- if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
531+ if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
523532 return `<div class=\"cr-error\" style=\"color:#a00\">Unknown crid '${ useCrid } ' (render map first)</div>` ;
524533 }
525534 if ( placeholder === null || placeholder === true ) {
@@ -533,13 +542,13 @@ module.exports = function (eleventyConfig) {
533542 // Shortcode to output unit details container for a given crid
534543
535544 eleventyConfig . addShortcode ( 'crmap_udetails' , function ( crid , placeholder = null ) {
536- let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
537- let useCrid = crid ;
538- if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
545+ let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
546+ let useCrid = crid ;
547+ if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
539548 if ( ! useCrid ) return '<div class="cr-error" style="color:#a00">crmap_udetails: missing crid (no crmap rendered yet)</div>' ;
540- const v = validateCrid ( useCrid . toString ( ) ) ;
549+ const v = validateCrid ( useCrid . toString ( ) ) ;
541550 if ( ! v . ok ) return `<div class=\"cr-error\" style=\"color:#a00\">${ v . message } </div>` ;
542- if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
551+ if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
543552 return `<div class=\"cr-error\" style=\"color:#a00\">Unknown crid '${ useCrid } ' (render map first)</div>` ;
544553 }
545554 if ( placeholder === null || placeholder === true ) {
@@ -553,13 +562,13 @@ module.exports = function (eleventyConfig) {
553562 // Shortcode to output unit commands container for a given crid
554563
555564 eleventyConfig . addShortcode ( 'crmap_commands' , function ( crid , placeholder = null ) {
556- let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
557- let useCrid = crid ;
558- if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
565+ let pageState = this && this . ctx ? this . ctx . _crmapState : null ;
566+ let useCrid = crid ;
567+ if ( ! useCrid && pageState ) useCrid = pageState . lastCrid ;
559568 if ( ! useCrid ) return '<div class="cr-error" style="color:#a00">crmap_commands: missing crid (no crmap rendered yet)</div>' ;
560- const v = validateCrid ( useCrid . toString ( ) ) ;
569+ const v = validateCrid ( useCrid . toString ( ) ) ;
561570 if ( ! v . ok ) return `<div class=\"cr-error\" style=\"color:#a00\">${ v . message } </div>` ;
562- if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
571+ if ( ! pageState || ! pageState . crids . has ( useCrid . toString ( ) ) ) {
563572 return `<div class=\"cr-error\" style=\"color:#a00\">Unknown crid '${ useCrid } ' (render map first)</div>` ;
564573 }
565574 if ( placeholder === null || placeholder === true ) {
0 commit comments