From 8215ab73e5e86af65a0a34dc2e470b83513859f7 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Thu, 28 Dec 2023 10:09:09 +0800 Subject: [PATCH] :sparkles: Passing options such of cdn --- src/index.ts | 12 +++++++----- src/provider/provider.ts | 12 +++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 085641b..773f515 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import {RENDER_CLASS} from "./constant"; import {ProviderFactory} from "./provider/provider"; class HaloJs { - public static renderHalo = (src: string, fontCDN: string = null): string => { + public static renderHalo = (src: string, cdn: string = null): string => { // Load Font let fontStyle = document.getElementById("halo-render-font-face"); if (!fontStyle) { @@ -11,9 +11,9 @@ class HaloJs { fontStyle.id = "halo-render-font-face" fontStyle.innerHTML = `@font-face { font-family: 'iconfont'; - src: url('${fontCDN || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'), - url('${fontCDN || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'), - url('${fontCDN || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype'); + src: url('${cdn || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'), + url('${cdn || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'), + url('${cdn || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype'); } ` document.getElementsByTagName("head")[0].append(fontStyle) @@ -23,7 +23,9 @@ class HaloJs { const type = line[0] line.splice(0, 1) const content = line.join("\n") - return ProviderFactory.getFactory().process(type, content) + return ProviderFactory.getFactory().process(type, content, { + cdn: cdn || "." + }) } } diff --git a/src/provider/provider.ts b/src/provider/provider.ts index de5b10a..21bfb1b 100644 --- a/src/provider/provider.ts +++ b/src/provider/provider.ts @@ -3,7 +3,7 @@ import {ProviderList} from "./provider-list"; export declare interface Provider { check: (type: string) => boolean - process: (type:string,content: string) => string + process: (type:string,content: string, options: IOptions) => string } export class ProviderFactory { @@ -14,11 +14,13 @@ export class ProviderFactory { this.providers = providers; } - process(type: string, content: string) { + process(type: string, content: string, options: IOptions = { + cdn: "." + }) { let html = "

Invalid Type!

" this.providers.forEach(provider => { if (provider.check(type)) { - html = provider.process(type, content) + html = provider.process(type, content, options) return } }) @@ -32,3 +34,7 @@ export class ProviderFactory { return this.manager } } + +export interface IOptions { + cdn: string; +}