Skip to content

Commit 7c8157c

Browse files
authored
Merge pull request #237 from ducflair/dev
Dev
2 parents 4ec9458 + 59f128e commit 7c8157c

7 files changed

Lines changed: 395 additions & 120 deletions

File tree

.github/workflows/pr-checks.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ jobs:
202202
with:
203203
targets: wasm32-unknown-unknown
204204

205-
- name: Install native toolchain for wasm build
206-
if: needs.release-check.outputs.needs_wasm == 'true'
207-
run: |
208-
sudo apt-get update
209-
sudo apt-get install -y clang
210-
211205
- name: Install wasm-pack
212206
if: needs.release-check.outputs.needs_wasm == 'true'
213207
run: cargo install wasm-pack --version 0.14.0 --locked --force

.github/workflows/release-ducjs.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ jobs:
4141
with:
4242
targets: wasm32-unknown-unknown
4343

44-
- name: Install native toolchain for wasm build
45-
run: |
46-
sudo apt-get update
47-
sudo apt-get install -y clang
48-
4944
- name: Install wasm-pack (pinned 0.14.x)
5045
run: cargo install wasm-pack --version 0.14.0 --locked --force
5146

.github/workflows/release-ducpdf.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ jobs:
4141
with:
4242
targets: wasm32-unknown-unknown
4343

44-
- name: Install native toolchain for wasm build
45-
run: |
46-
sudo apt-get update
47-
sudo apt-get install -y clang
48-
4944
- name: Install wasm-pack (pinned 0.14.x)
5045
run: cargo install wasm-pack --version 0.14.0 --locked --force
5146

.github/workflows/release-ducsvg.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ jobs:
4141
with:
4242
targets: wasm32-unknown-unknown
4343

44-
- name: Install native toolchain for wasm build
45-
run: |
46-
sudo apt-get update
47-
sudo apt-get install -y clang
48-
4944
- name: Install wasm-pack (pinned 0.14.x)
5045
run: cargo install wasm-pack --version 0.14.0 --locked --force
5146

packages/ducjs/src/utils/elements/freedrawElement.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ function buildStrokeOptions(element: DucFreeDrawElement): StrokeOptions {
4646
};
4747
}
4848

49+
const normalizeStrokePressure = (pressure: number | undefined): number => {
50+
if (!Number.isFinite(pressure) || pressure === undefined || pressure <= 0) {
51+
return 0.5;
52+
}
53+
54+
return Math.min(1, Math.max(0.05, pressure));
55+
};
56+
4957
function buildInputPoints(element: DucFreeDrawElement): number[][] {
5058
return element.simulatePressure
51-
? element.points.map(({x, y}, i) => [x.scoped, y.scoped, element.pressures[i]])
52-
: element.points.map(({x, y}) => [x.scoped, y.scoped]);
59+
? element.points.map(({x, y}) => [x.scoped, y.scoped])
60+
: element.points.map(({x, y}, i) => [x.scoped, y.scoped, normalizeStrokePressure(element.pressures[i])]);
5361
}
5462

5563
export function getFreeDrawSvgPath(element: DucFreeDrawElement) {

packages/ducjs/src/utils/elements/newElement.ts

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
DucTableElement,
2525
DucTextElement,
2626
ElementConstructorOpts,
27+
ElementBackground,
28+
ElementStroke,
2729
ElementUpdate,
2830
NonDeleted
2931
} from "../../types/elements";
@@ -349,11 +351,38 @@ export const newArrowElement = (
349351
elbowed: opts.elbowed ?? true,
350352
});
351353

354+
const withDisabledContentVisibility = <T extends ElementBackground | ElementStroke>(
355+
items: readonly T[] | undefined,
356+
fallback: T,
357+
): T[] => {
358+
const source = items?.length ? items : [fallback];
359+
return source.map((item) => ({
360+
...item,
361+
content: {
362+
...item.content,
363+
visible: false,
364+
},
365+
}));
366+
};
367+
368+
const getMediaElementStyle = (opts: ElementConstructorOpts) => ({
369+
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
370+
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
371+
});
372+
373+
const getDocumentElementStyle = (opts: ElementConstructorOpts) => ({
374+
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
375+
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
376+
});
377+
352378
export const newImageElement = (
353379
currentScope: Scope,
354380
opts: Partial<DucImageElement> & ElementConstructorOpts,
355381
): NonDeleted<DucImageElement> => ({
356-
..._newElementBase<DucImageElement>("image", currentScope, opts),
382+
..._newElementBase<DucImageElement>("image", currentScope, {
383+
...opts,
384+
...getMediaElementStyle(opts),
385+
}),
357386
type: "image",
358387
status: opts.status ?? IMAGE_STATUS.PENDING,
359388
fileId: opts.fileId ?? null,
@@ -375,7 +404,10 @@ export const newDocElement = (
375404
currentScope: Scope,
376405
opts: Partial<DucDocElement> & ElementConstructorOpts,
377406
): NonDeleted<DucDocElement> => ({
378-
..._newElementBase<DucDocElement>("doc", currentScope, opts),
407+
..._newElementBase<DucDocElement>("doc", currentScope, {
408+
...opts,
409+
...getDocumentElementStyle(opts),
410+
}),
379411
type: "doc",
380412
text: opts.text || "",
381413
fileId: opts.fileId ?? null,
@@ -391,19 +423,32 @@ export const newDocElement = (
391423
export const newPdfElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucPdfElement> => ({
392424
fileId: null,
393425
gridConfig: { columns: 1, gapX: 0, gapY: 0, firstPageAlone: false, scale: 1 },
394-
..._newElementBase<DucPdfElement>("pdf", currentScope, opts),
426+
..._newElementBase<DucPdfElement>("pdf", currentScope, {
427+
...opts,
428+
...getDocumentElementStyle(opts),
429+
}),
395430
type: "pdf",
396431
});
397432

398-
export const newModelElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucModelElement> => ({
399-
modelType: null,
400-
code: null,
401-
thumbnail: null,
402-
fileIds: [],
403-
viewerState: null,
404-
..._newElementBase<DucModelElement>("model", currentScope, opts),
405-
type: 'model',
406-
});
433+
export const newModelElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucModelElement> => {
434+
const modelStyle = {
435+
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
436+
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
437+
};
438+
439+
return {
440+
modelType: null,
441+
code: null,
442+
thumbnail: null,
443+
fileIds: [],
444+
viewerState: null,
445+
..._newElementBase<DucModelElement>("model", currentScope, {
446+
...opts,
447+
...modelStyle,
448+
}),
449+
type: 'model',
450+
};
451+
};
407452

408453
// Simplified deep clone for the purpose of cloning DucElement.
409454
//
@@ -456,7 +501,8 @@ const _deepCopyElement = (val: any, depth: number = 0) => {
456501
// we're not cloning non-array & non-plain-object objects because we
457502
// don't support them on excalidraw elements yet. If we do, we need to make
458503
// sure we start cloning them, so let's warn about it.
459-
if (import.meta.env.DEV) {
504+
const importMetaEnv = (import.meta as unknown as { env?: { DEV?: boolean } }).env;
505+
if (importMetaEnv?.DEV) {
460506
if (
461507
objectType !== "[object Object]" &&
462508
objectType !== "[object Array]" &&

0 commit comments

Comments
 (0)