Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public sourceChanged(): void {
const canvasElement = document.getElementById('canvas');
try {
const superSampling = window.devicePixelRatio || 1;
const scale = superSampling * Math.exp(this.zoomLevel / 10);
nomnoml.draw(canvasElement, this.source, scale);
this.positionCanvas(canvasElement, superSampling, this.offset);
} catch (e) {
console.log(e); // tslint:disable-line
}
}
build() {
const files = fs.readdirSync(nomnomlSourceDir);
while (files.length > 0) {
const file = path.resolve(nomnomlSourceDir, files.shift());
const basename = path.basename(file, 'txt');
if (/.nomnoml/.test(basename)) {
const fileContents = fs.readFileSync(file, 'utf-8');
const generated = nomnoml.renderSvg(fileContents);
const newFilePath = path.join(docImageDir, basename) + 'svg';
const outFile = fs.createWriteStream(newFilePath);
console.log(`wrote file ${newFilePath}`);
outFile.write(generated);
}
}
}
};
function convert () {
const source = data.toString(encoding)
if (source === '') {
return
}
console.log(nomnoml.renderSvg(source))
}
function renderNomnoml(source, target) {
var canvas =
new Canvas(CONSTANTS.DIAGRAM_WIDTH, CONSTANTS.DIAGRAM_HEIGHT);
nomnoml.draw(canvas, source, 1.0);
canvas.pngStream().pipe(fs.createWriteStream(target));
}
async files(): Promise {
return JSON.parse(localStorage['nomnoml.file_index'] || '[]') as FileEntry[]
}
async read(name: string): Promise {
async insert(name: string, source: string): Promise {
var entry: FileEntry = {
date: (new Date()).toISOString(),
collaborators: [],
name: name,
revision: 0,
}
var index = await this.files()
if (!nomnoml.skanaar.find(index, e => e.name === name)) {
index.push(entry)
index.sort((a,b) => a.name.localeCompare(b.name))
localStorage['nomnoml.file_index'] = JSON.stringify(index)
}
localStorage[this.prefix+name] = source
}
async save(name: string, source: string): Promise {
async files(): Promise {
return JSON.parse(localStorage['nomnoml.file_index'] || '[]') as FileEntry[]
}
async read(name: string): Promise { return this.source }
files(): FileEntry[] {
return JSON.parse(localStorage['nomnoml.file_index'] || '[]') as FileEntry[]
}
setFiles(index: FileEntry[]): void {
async files(): Promise {
return JSON.parse(localStorage['nomnoml.file_index'] || '[]') as FileEntry[]
}
async read(name: string): Promise { return localStorage[this.storageKey] }
private generateDiagram( text: string ): string {
let svg : string;
let backgroundColor : string = undefined;
try {
svg = nomnoml.renderSvg( text );
let result = /\#bgColor\:\s?(\S*)/.exec( text );
if( result && result[ 1 ] )
backgroundColor = result[ 1 ];
} catch( exception ){
return this.errorSnippet( exception );
}
return `
<div style="width: 100%; height: 100%; overflow: scroll;">
${ svg }
</div>