Skip to content

Commit

Permalink
feat: update package about full.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hqer927 committed Nov 11, 2024
1 parent 921fefa commit 91b7095
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 78 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "5.1.6",
"vite": "^4.4.1",
"white-web-sdk": "^2.16.51"
"vite": "^4.4.1"
},
"pnpm": {
"overrides": {
"@netless/window-manager": "^0.4.75",
"@netless/appliance-plugin": "1.1.2"
"@netless/appliance-plugin": "1.1.2",
"white-web-sdk": "^2.16.51"
},
"peerDependencyRules": {
"ignoreMissing": [
Expand Down
50 changes: 19 additions & 31 deletions packages/buildtool/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function build({
plugins: [
esbuildPlugin([], {
"@netless/fastboard-core": "@netless/fastboard-core/lite",
"@netless/fastboard-ui": "@netless/fastboard-ui/lite",
// "@netless/fastboard-ui": "@netless/fastboard-ui/lite",
}),
],
external: [/^[@a-z]/],
Expand Down Expand Up @@ -148,7 +148,7 @@ export async function build({
}

start = Date.now();
await dts.build(main, "dist/index.d.ts", { exclude: ["svelte", "svelte/internal", "./lite"] });
await dts.build(main, "dist/index.d.ts", { exclude: ["svelte", "svelte/internal", "./lite", "./full"] });
console.log("Built dist/index.d.ts in", Date.now() - start + "ms");

// Generate dist/lite.d.ts
Expand All @@ -166,8 +166,8 @@ export async function build({
console.log("Built dist/lite.d.ts in", Date.now() - start + "ms");
}

// Build dist/index.global.ts
const esbuildGlobalPlugin = (external, alias = {}) => ({
// Build dist/full.js
const esbuildFullPlugin = (external, alias = {}) => ({
name: "esbuild",
async load(id) {
const { outputFiles } = await esbuild.build({
Expand All @@ -176,7 +176,7 @@ export async function build({
format: "esm",
// The filename here does not really matter, because
// rollup will then merge sourcemaps and get the original input filename.
outfile: id.replace(/\.tsx?$/, ".global.js"),
outfile: id.replace(/\.tsx?$/, ".js"),
sourcemap: true,
write: false,
target: ["es2017"],
Expand All @@ -189,13 +189,15 @@ export async function build({
__VERSION__: JSON.stringify(version),
},
alias,
external: name.endsWith("-core") ? Object.keys({
...(external && external.reduce((acc, cur) => ((acc[cur] = true), acc), {})),
}) : Object.keys({
...dependencies,
...peerDependencies,
...(external && external.reduce((acc, cur) => ((acc[cur] = true), acc), {})),
}),
external: name.endsWith("-core")
? Object.keys({
...(external && external.reduce((acc, cur) => ((acc[cur] = true), acc), {})),
})
: Object.keys({
...dependencies,
...peerDependencies,
...(external && external.reduce((acc, cur) => ((acc[cur] = true), acc), {})),
}),
});
let code, map;
for (const { path, text } of outputFiles) {
Expand All @@ -205,25 +207,13 @@ export async function build({
return { code, map };
},
});

{
const start = Date.now();
// const bundle = await rollup.rollup({
// input: main,
// plugins: [esbuildGlobalPlugin()],
// external: [/^[@a-z]/],
// });
// const iife = bundle.write({
// file: "dist/index.global.js",
// format: "iife",
// name: `${name[0].toUpperCase()}${name.slice(1)}`,
// });
start = Date.now();
if (!name.endsWith("-ui")) {
const bundle = await rollup.rollup({
input: main,
input: name.endsWith("-core") ? "src/full.ts" : main,
plugins: [
esbuildGlobalPlugin([], {
esbuildFullPlugin([], {
"@netless/fastboard-core": "@netless/fastboard-core/full",
"@netless/fastboard-ui": "@netless/fastboard-ui/full",
}),
],
external: [/^[@a-z]/],
Expand All @@ -247,10 +237,9 @@ export async function build({
await bundle.close();
console.log("Built dist/full.{js|mjs} in", Date.now() - start + "ms");
}

start = Date.now();
if (name.endsWith("-core")) {
await dts.build("src/index.ts", "dist/full.d.ts", { exclude: ["svelte", "svelte/internal"] });
await dts.build("src/full.ts", "dist/full.d.ts", { exclude: ["svelte", "svelte/internal"] });
console.log("Built dist/full.d.ts in", Date.now() - start + "ms");
} else {
let code = fs.readFileSync("dist/index.d.ts", "utf-8");
Expand All @@ -259,5 +248,4 @@ export async function build({
fs.writeFileSync("dist/full.d.ts", code);
console.log("Built dist/full.d.ts in", Date.now() - start + "ms");
}

}
5 changes: 5 additions & 0 deletions packages/fastboard-core/full.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
declare global {
interface Window {
global: any;
}
}
export * from "./dist/full";
22 changes: 15 additions & 7 deletions packages/fastboard-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"main": "src/index.ts",
"exports": {
".": "./src/index.ts",
"./lite": "./src/lite.ts"
"./lite": "./src/lite.ts",
"./full": "./src/full.ts"
},
"files": [
"src",
"dist",
"lite.d.ts"
"lite.d.ts",
"full.d.ts"
],
"repository": "netless-io/fastboard",
"scripts": {
Expand All @@ -19,17 +21,19 @@
"build": "buildtool"
},
"dependencies": {
"@netless/app-slide": "^0.2.39",
"@netless/app-slide": "^0.2.61",
"@netless/synced-store": "^2.0.7"
},
"peerDependencies": {
"@netless/appliance-plugin": ">=1.1.1",
"@netless/window-manager": ">=0.4.0",
"white-web-sdk": ">=2.16.0"
"jspdf": ">=2.5.1",
"@netless/appliance-plugin": ">=1.1.2",
"@netless/window-manager": ">=0.4.75",
"white-web-sdk": ">=2.16.51"
},
"devDependencies": {
"@netless/buildtool": "workspace:*",
"white-web-sdk": "^2.16.51"
"white-web-sdk": "^2.16.51",
"jspdf": "^2.5.1"
},
"publishConfig": {
"main": "dist/index.js",
Expand All @@ -43,6 +47,10 @@
"./lite": {
"types": "./dist/lite.d.ts",
"default": "./dist/lite.mjs"
},
"./full": {
"types": "./dist/full.d.ts",
"default": "./dist/full.mjs"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/fastboard-core/src/full.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
if (typeof window !== "undefined") {
(window as any).global = (window as any).global || {};
}
export * from "./lite";
export * from "./behaviors";
16 changes: 8 additions & 8 deletions packages/fastboard-core/src/impl/FastboardApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,14 @@ export async function createFastboard<TEventData extends Record<string, any> = a
if (room.isWritable && ((room as any).floatBarOptions as FloatBarOptions)?.colors.length) {
const colors = (room as any).floatBarOptions?.colors;
const length = colors.length;
(room as any).getRoomMembers().map((c:RoomMember)=>{
const index = c.memberId % length;
const color = colors[index];
manager.mainView.setMemberState({
strokeColor: color,
textColor: color,
});
})
(room as any).getRoomMembers().map((c: RoomMember) => {
const index = c.memberId % length;
const color = colors[index];
manager.mainView.setMemberState({
strokeColor: color,
textColor: color,
});
});
}
manager.mainView.setCameraBound({
minContentMode: contentModeScale(0.3),
Expand Down
7 changes: 6 additions & 1 deletion packages/fastboard-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"files": [
"src",
"dist",
"lite.d.ts"
"lite.d.ts",
"full.d.ts"
],
"repository": "netless-io/fastboard",
"scripts": {
Expand Down Expand Up @@ -42,6 +43,10 @@
"./lite": {
"types": "./dist/lite.d.ts",
"default": "./dist/lite.mjs"
},
"./full": {
"types": "./dist/full.d.ts",
"default": "./dist/full.mjs"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function tooltip(text: string, hotkey?: HotKey) {
return outer;
}


export function rgbToHex(r: number, g: number, b: number) {
const hex = ((r << 16) + (g << 8) + b).toString(16).padStart(6, "0");
return "#" + hex;
Expand All @@ -44,4 +43,4 @@ export function hexToRgb(hex: string): Color {
const b = parseInt(hex.slice(4, 6), 16);

return [r, g, b];
}
}
4 changes: 2 additions & 2 deletions packages/fastboard-ui/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export function createUI(app?: FastboardApp | null, div?: Element): UI {
let colors: Color[] | undefined;

if (app?.manager && app.manager.room) {
const floatBarOptions = ((app.manager.room as any).floatBarOptions) as { colors?: Color[] };
const floatBarOptions = (app.manager.room as any).floatBarOptions as { colors?: Color[] };
if (floatBarOptions.colors) {
colors = (floatBarOptions.colors) as Color[];
colors = floatBarOptions.colors as Color[];
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/fastboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"files": [
"src",
"dist",
"lite.d.ts"
"lite.d.ts",
"full.d.ts"
],
"repository": "netless-io/fastboard",
"scripts": {
Expand Down Expand Up @@ -35,6 +36,10 @@
"./lite": {
"types": "./dist/lite.d.ts",
"default": "./dist/lite.mjs"
},
"./full": {
"types": "./dist/full.d.ts",
"default": "./dist/full.mjs"
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/fastboard/test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ register({
src: "https://cdn.jsdelivr.net/npm/@netless/[email protected]",
name: "NetlessAppPDFjs",
appOptions: {
pdfjsLib: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.min.mjs',
workerSrc: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.worker.min.mjs'
}
pdfjsLib: "https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.min.mjs",
workerSrc: "https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.worker.min.mjs",
},
});
createFastboard({
sdkConfig: {
Expand All @@ -38,12 +38,12 @@ createFastboard({
},
joinRoom: {
uid: genUID(),
uuid: import.meta.env.VITE_ROOM_UUID || "586594d09dad11efacd4a7a764beb2c4",
uuid: import.meta.env.VITE_ROOM_UUID || "b76630509f1211ef835aff90209b1830",
useNativeClipboard: true,
floatBar: true,
roomToken:
import.meta.env.VITE_ROOM_TOKEN ||
"NETLESSROOM_YWs9VWtNUk92M1JIN2I2Z284dCZleHBpcmVBdD0xNzMxMTQxNzMxMTYzJm5vbmNlPTU4ODI5MmIwLTlkYWQtMTFlZi05NmE5LWFiMzg4NjE4OThhZiZyb2xlPTEmc2lnPTc0MmMwNmY0MmM0NzVjZjI2YTNkODE1ZTA1ODlmODU4ZGQyNzI1NWEwMmVjNWFmODkyYjg0NzgzMjBjNDVkODcmdXVpZD01ODY1OTRkMDlkYWQxMWVmYWNkNGE3YTc2NGJlYjJjNA",
"NETLESSROOM_YWs9VWtNUk92M1JIN2I2Z284dCZleHBpcmVBdD0xNzMxMjk1MjIwODQ2Jm5vbmNlPWI3N2Q4OGUwLTlmMTItMTFlZi05NmE5LWFiMzg4NjE4OThhZiZyb2xlPTEmc2lnPTMyYzc0NmI0YWM4NGUwYjgyMTg5ZWRhMWUzYmE3YWNhNzc1YTE1OGQ2YTExNjUyODlmNWE0ZDljM2I1ZjllNzAmdXVpZD1iNzY2MzA1MDlmMTIxMWVmODM1YWZmOTAyMDliMTgzMA",
},
managerConfig: {
cursor: true,
Expand Down
Loading

0 comments on commit 91b7095

Please sign in to comment.