diff --git a/package.json b/package.json index 23a5bcc..b659f5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@micro-lc/post-channel", - "version": "0.2.0-rc2", + "version": "0.2.0-rc3", "type": "module", "main": "dist/cjs/index.cjs", "module": "dist/es/index.js", diff --git a/src/index.ts b/src/index.ts index 8c7f450..78d67d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,6 +57,12 @@ const isPostChannelMessage = (message: MessageEvent): message is MessageEventWit && 'content' in data } +const generateDarkColorHex = () => { + let color = '#' + for (let i = 0; i < 3; i++) { color += (`0${Math.floor(Math.random() * Math.pow(16, 2) / 2).toString(16)}`).slice(-2) } + return color +} + class PostChannel { private static __generateId = () => { if (window) { @@ -80,6 +86,7 @@ class PostChannel { private __write$: Observable private __synack$: Observable private __user$: Observable + private __colors: {bg: string; fg: string} private __connect(period: number) { /** @@ -202,6 +209,12 @@ class PostChannel { this.__okToWrite = new ReplaySubject(1) this.__write$ = this.__okToWrite.pipe(take(1)) + const color = generateDarkColorHex() + this.__colors = { + bg: `${color}22`, + fg: color, + } + // period cannot be zero! this.__connect( opts?.period ? opts.period : 10 @@ -237,6 +250,10 @@ class PostChannel { return this.__instance } + get colors() { + return this.__colors + } + /** * signals readiness on listening and cannot fail but keeps hanging * if not resolved