UNPKG

@angular-package/prism

Version:
102 lines 3.11 kB
import { ChangeDetectorRef, ElementRef, Input, Injectable, ViewChild } from '@angular/core'; import * as _ from 'lodash-es'; import { PrismInterface } from './prism.interface'; import { CallbackType } from './prism.type'; import { PrismService } from './prism.service'; export class PrismHoodClass { constructor(changeDetectorRef, prismService) { this.changeDetectorRef = changeDetectorRef; this.prismService = prismService; this.ready = false; this._async = false; } set cd(cd) { this._cd = cd; if (this.ready === true) { this.__properties = cd; } } get cd() { return this._cd; } set async(async) { this._async = async; } get async() { return this._async; } set callback(callback) { this._callback = callback; } get callback() { return this._callback; } set code(code) { this._code = code; if (this.ready) { if (this.__properties.code === true) { this.highlightElement({ code, language: this.language }); } } } get code() { return this._code; } set hooks(hooks) { this._hooks = hooks; if (hooks instanceof Object) { _.forEach(hooks, (element, key) => { this.prismService.hooks().add(key, element); }); } this.highlightElement({ code: this.code, language: this.language }); } get hooks() { return this._hooks; } set language(language) { if (language) { if (typeof (language) === 'string') { this._language = language; this.highlightElement({ code: this.code, language }); } else { throw new Error(`Property \`language\` should be \`string\` instead of provided \`${typeof (language)}\``); } } else { throw new Error('Missing property `language`.'); } } get language() { return this._language; } highlightElement(result) { if (this.ready === true) { this.prismService.highlight(this.el, { async: this.async, callback: this.callback, code: result.code, interpolation: this.interpolation }); } } } PrismHoodClass.decorators = [ { type: Injectable }, ]; PrismHoodClass.ctorParameters = () => [ { type: ChangeDetectorRef, }, { type: PrismService, }, ]; PrismHoodClass.propDecorators = { "el": [{ type: ViewChild, args: ['el', { read: ElementRef },] },], "cd": [{ type: Input, args: ['cd',] },], "async": [{ type: Input, args: ['async',] },], "callback": [{ type: Input, args: ['callback',] },], "code": [{ type: Input, args: ['code',] },], "hooks": [{ type: Input, args: ['hooks',] },], "language": [{ type: Input, args: ['language',] },], "interpolation": [{ type: Input, args: ['interpolation',] },], }; //# sourceMappingURL=prism.class.js.map