@curvenote/cli-plugin
Version:
MyST Plugins for Curvenote
79 lines (78 loc) • 3.39 kB
JavaScript
import { u } from 'unist-builder';
import { makePlaceholder, validateStringOptions } from '../../utils.js';
// TODO: talk to package manager
const VIZARR_URL = 'https://curvenote.github.io/widgets/widgets/vizarr-viewer.js';
export const zarrViewer = {
name: 'zarr',
doc: 'Embed a Zarr image viewer',
arg: {
type: String,
required: true,
doc: 'A URL to the Zarr file',
},
options: {
class: {
type: String,
required: false,
doc: 'Tailwind classes to apply to the container element',
},
styles: {
type: String,
required: false,
doc: 'URL to the CSS file',
},
viewer: {
type: String,
required: false,
doc: 'The viewer to use (default: "vizarr")',
},
height: {
type: String,
required: false,
doc: 'The height of the embedded viewer container set via style',
},
},
validate(data, vfile) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
// TODO: validate the URL for the esm
validateStringOptions(vfile, 'arg', data.arg);
if ((_a = data.options) === null || _a === void 0 ? void 0 : _a.class)
validateStringOptions(vfile, 'class', (_b = data.options) === null || _b === void 0 ? void 0 : _b.class);
if ((_c = data.options) === null || _c === void 0 ? void 0 : _c.veiwer)
validateStringOptions(vfile, 'viewer', (_d = data.options) === null || _d === void 0 ? void 0 : _d.viewer);
if ((_e = data.options) === null || _e === void 0 ? void 0 : _e.height)
validateStringOptions(vfile, 'height', (_f = data.options) === null || _f === void 0 ? void 0 : _f.height);
if (!((_g = data.options) === null || _g === void 0 ? void 0 : _g.viewer) &&
((_j = (_h = data.options) === null || _h === void 0 ? void 0 : _h.viewer) !== null && _j !== void 0 ? _j : '').length > 0 &&
((_k = data.options) === null || _k === void 0 ? void 0 : _k.viewer) !== 'vizarr') {
vfile.message(`Invalid viewer supplied: ${(_l = data.options) === null || _l === void 0 ? void 0 : _l.viewer}.`);
}
return data;
},
run(data, _vfile, _opts) {
var _a, _b, _c, _d, _e, _f;
const viewer = (_b = (_a = data.options) === null || _a === void 0 ? void 0 : _a.viewer) !== null && _b !== void 0 ? _b : 'vizarr';
let viewerUrl = VIZARR_URL; // default
switch (viewer) {
case 'vizarr':
default:
viewerUrl = VIZARR_URL;
}
console.log('viewerUrl', viewerUrl);
console.log('data.arg', data.arg);
const block = u('block', {
kind: 'any:bundle',
data: {
import: viewerUrl,
class: (_d = (_c = data.options) === null || _c === void 0 ? void 0 : _c.class) !== null && _d !== void 0 ? _d : '',
styles: '',
json: {
directive: 'zarr',
source: data.arg,
height: (_f = (_e = data.options) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : '600px',
},
},
}, makePlaceholder(data, data.arg));
return [block];
},
};