@plaso-infi/whiteboard-sdk 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.eslintrc.cjs +39 -0
  2. package/dist/cjs/AgoraRTC_N-production-56cec5fa.js +2 -0
  3. package/dist/cjs/hls-658579eb-4a33810b.js +1 -0
  4. package/dist/cjs/index-7d60a2b0.js +121 -0
  5. package/dist/cjs/index-918b6bd8-fbf67194.js +1 -0
  6. package/dist/cjs/index.css +18326 -0
  7. package/dist/cjs/index.d.ts +112 -0
  8. package/dist/cjs/index.js +1 -0
  9. package/dist/cjs/pdf_lib-b7d912c0-b81151a9.js +15 -0
  10. package/dist/esm/AgoraRTC_N-production-b8daf022.js +2 -0
  11. package/dist/esm/hls-658579eb-85afd34e.js +1 -0
  12. package/dist/esm/index-78998076.js +121 -0
  13. package/dist/esm/index-918b6bd8-b63ab80f.js +1 -0
  14. package/dist/esm/index.css +18326 -0
  15. package/dist/esm/index.d.ts +112 -0
  16. package/dist/esm/index.js +1 -0
  17. package/dist/esm/pdf_lib-b7d912c0-ee79af87.js +15 -0
  18. package/package.json +74 -0
  19. package/postcss.config.cjs +3 -0
  20. package/rollup.config.mjs +75 -0
  21. package/src/components/errorBoundary/errorBoundary.tsx +27 -0
  22. package/src/components/errorBoundary/index.ts +1 -0
  23. package/src/components/index.ts +1 -0
  24. package/src/fixtures/index.ts +1 -0
  25. package/src/fixtures/sdk_status.ts +5 -0
  26. package/src/index.ts +5 -0
  27. package/src/instance.ts +105 -0
  28. package/src/localdemo/demo.tsx +29 -0
  29. package/src/localdemo/index.html +13 -0
  30. package/src/localdemo/styles.module.less +5 -0
  31. package/src/sdk.ts +21 -0
  32. package/src/types/event.ts +7 -0
  33. package/src/types/global.d.ts +27 -0
  34. package/src/types/index.ts +2 -0
  35. package/src/types/sdk.ts +128 -0
  36. package/src/upime/index.ts +1 -0
  37. package/src/upime/upime.tsx +86 -0
  38. package/src/utils/asyncWork.ts +31 -0
  39. package/src/utils/avatar.ts +71 -0
  40. package/src/utils/common.ts +30 -0
  41. package/src/utils/event.ts +46 -0
  42. package/src/utils/index.ts +4 -0
  43. package/tsconfig.json +24 -0
  44. package/vite.config.ts +40 -0
@@ -0,0 +1,71 @@
1
+ export type drawNoImageAvatarParamsT = {
2
+ userId?: string | number;
3
+ text: string;
4
+ imgUrl?: string;
5
+ bgColor?: string;
6
+ };
7
+
8
+ const DEFAULT_COVER_COLOR = ['#eea5a5', '#f5cd83', '#9abaee', '#74c5e6', '#54d1c0'];
9
+ export function GetDefaultColor(relyString: string | number) {
10
+ let number;
11
+ if (typeof relyString === 'string') {
12
+ number = relyString.match(/(\d|[a-f]|[A-F])/g)?.join('') || '0';
13
+ } else {
14
+ number = relyString;
15
+ }
16
+ if (number) {
17
+ return DEFAULT_COVER_COLOR[parseInt(number, 16) % DEFAULT_COVER_COLOR.length];
18
+ } else {
19
+ return '#ccc';
20
+ }
21
+ }
22
+
23
+ const avatarSize = {
24
+ w: 128,
25
+ h: 128,
26
+ };
27
+
28
+ function drawText(text: string, bgColor: string): string {
29
+ const canvasDOM = document.createElement('canvas');
30
+ canvasDOM.width = avatarSize.w;
31
+ canvasDOM.height = avatarSize.h;
32
+ const ctx = canvasDOM.getContext('2d') as CanvasRenderingContext2D;
33
+ ctx.fillStyle = bgColor;
34
+ ctx.fillRect(0, 0, avatarSize.w, avatarSize.h);
35
+ ctx.font = '64px Arial';
36
+ ctx.textAlign = 'center';
37
+ ctx.fillStyle = '#fff';
38
+ ctx.fillText(text[0], 64, 88);
39
+ return canvasDOM.toDataURL();
40
+ }
41
+
42
+ /**
43
+ * 绘制头像
44
+ * @param param0
45
+ * @returns
46
+ */
47
+ export function drawNoImageAvatar({
48
+ userId = '',
49
+ text = '',
50
+ imgUrl = '',
51
+ bgColor = '',
52
+ }: drawNoImageAvatarParamsT) {
53
+ return new Promise<string>(resolve => {
54
+ const getDefaultAvatar = () => {
55
+ const curBgColor = bgColor || GetDefaultColor(userId);
56
+ resolve(drawText(text, curBgColor));
57
+ };
58
+ if (!imgUrl) {
59
+ getDefaultAvatar();
60
+ } else {
61
+ const imgDOM = document.createElement('img');
62
+ imgDOM.onload = () => {
63
+ resolve(imgUrl);
64
+ };
65
+ imgDOM.onerror = () => {
66
+ getDefaultAvatar();
67
+ };
68
+ imgDOM.src = imgUrl;
69
+ }
70
+ });
71
+ }
@@ -0,0 +1,30 @@
1
+ export const delay = (t: number) => new Promise(res => setTimeout(res, t));
2
+
3
+ /** 最基本的 debounce 实现 */
4
+ export function debounce<T extends (...args: any[]) => any>(fn: T, time: number) {
5
+ let timer: ReturnType<typeof setTimeout> | null = null;
6
+ return (...args: Parameters<T>): ReturnType<T> => {
7
+ let res: any;
8
+ if (timer) {
9
+ clearTimeout(timer);
10
+ }
11
+ timer = setTimeout(() => {
12
+ res = fn(...args);
13
+ }, time);
14
+ return res;
15
+ };
16
+ }
17
+
18
+ /** 最基本的 throttle 实现 */
19
+ export function throttle<T extends (...args: any[]) => any>(fn: T, time: number) {
20
+ let lastTime = 0;
21
+ return (...args: Parameters<T>): ReturnType<T> => {
22
+ const now = Date.now();
23
+ let res: any;
24
+ if (now - lastTime >= time) {
25
+ res = fn(...args);
26
+ lastTime = Date.now();
27
+ }
28
+ return res;
29
+ };
30
+ }
@@ -0,0 +1,46 @@
1
+ import type { EventManagerT, eventHandler } from '@/types';
2
+
3
+ type Listener<E = any> = {
4
+ cb: eventHandler<E>;
5
+ once: boolean;
6
+ };
7
+
8
+ export class EventManager<ET = any> implements EventManagerT<ET> {
9
+ private _t: { [p in keyof ET]?: Array<Listener<ET[p]>> } = {};
10
+
11
+ private addListener<T extends keyof ET>(topic: T, cb: eventHandler<ET[T]>, once = false) {
12
+ const topics = this._t;
13
+ let topicList = topics[topic];
14
+ if (!topicList) {
15
+ topics[topic] = topicList = [];
16
+ }
17
+ const one = { cb, once };
18
+ topicList.push(one);
19
+ return function unsub(): void {
20
+ const topicList = topics[topic];
21
+ if (!topicList) return;
22
+ topics[topic] = topicList.filter(o => o !== one);
23
+ };
24
+ }
25
+
26
+ subscribe<T extends keyof ET>(topic: T, cb: eventHandler<ET[T]>) {
27
+ return this.addListener(topic, cb);
28
+ }
29
+
30
+ unsubscribe<T extends keyof ET>(topic: T, cb: eventHandler<ET[T]>) {
31
+ const listeners = this._t[topic];
32
+ this._t[topic] = listeners?.filter(l => l.cb === cb);
33
+ }
34
+
35
+ once<T extends keyof ET>(topic: T, cb: eventHandler<ET[T]>) {
36
+ return this.addListener(topic, cb, true);
37
+ }
38
+
39
+ publish<T extends keyof ET>(topic: T, evt: ET[T]) {
40
+ const topics = this._t;
41
+ const topicList = topics[topic];
42
+ if (!topicList) return;
43
+ topics[topic] = topicList.filter(listener => !listener.once);
44
+ topicList.forEach(listener => listener.cb(evt));
45
+ }
46
+ }
@@ -0,0 +1,4 @@
1
+ export * from './asyncWork';
2
+ export * from './common';
3
+ export * from './event';
4
+ export * from './avatar';
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "jsx": "react",
5
+ "experimentalDecorators": true,
6
+ "module": "esnext",
7
+ "moduleResolution": "node",
8
+ "baseUrl": "./",
9
+ "paths": {
10
+ "@/*": ["./src/*"]
11
+ },
12
+ "useUnknownInCatchVariables": false,
13
+ "allowJs": true,
14
+ "sourceMap": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "esModuleInterop": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "resolveJsonModule": true,
19
+ "strict": true,
20
+ "noImplicitAny": false,
21
+ "skipLibCheck": true
22
+ },
23
+ "include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.tsx"]
24
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from 'vite';
2
+ import path from 'path';
3
+ import react from '@vitejs/plugin-react';
4
+ import commonjs from '@rollup/plugin-commonjs';
5
+
6
+ export default defineConfig(({}) => {
7
+ return {
8
+ mode: 'development',
9
+ root: path.resolve(__dirname, 'src/demo'),
10
+ base: '',
11
+ define: {},
12
+ server: {
13
+ host: '0.0.0.0',
14
+ port: 3000,
15
+ proxy: {},
16
+ },
17
+ resolve: {
18
+ alias: [
19
+ {
20
+ find: '@',
21
+ replacement: path.resolve(__dirname, 'src'),
22
+ },
23
+ ],
24
+ extensions: ['.js', '.ts', '.jsx', '.tsx', '.json'],
25
+ },
26
+ plugins: [
27
+ react({
28
+ include: '**/*.{jsx,tsx}',
29
+ }),
30
+ commonjs(),
31
+ ],
32
+ css: {
33
+ preprocessorOptions: {
34
+ less: {
35
+ javascriptEnabled: true,
36
+ },
37
+ },
38
+ },
39
+ };
40
+ });