Skip to content
Merged

Dev #237

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ jobs:
with:
targets: wasm32-unknown-unknown

- name: Install native toolchain for wasm build
if: needs.release-check.outputs.needs_wasm == 'true'
run: |
sudo apt-get update
sudo apt-get install -y clang

- name: Install wasm-pack
if: needs.release-check.outputs.needs_wasm == 'true'
run: cargo install wasm-pack --version 0.14.0 --locked --force
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release-ducjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ jobs:
with:
targets: wasm32-unknown-unknown

- name: Install native toolchain for wasm build
run: |
sudo apt-get update
sudo apt-get install -y clang

- name: Install wasm-pack (pinned 0.14.x)
run: cargo install wasm-pack --version 0.14.0 --locked --force

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release-ducpdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ jobs:
with:
targets: wasm32-unknown-unknown

- name: Install native toolchain for wasm build
run: |
sudo apt-get update
sudo apt-get install -y clang

- name: Install wasm-pack (pinned 0.14.x)
run: cargo install wasm-pack --version 0.14.0 --locked --force

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release-ducsvg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ jobs:
with:
targets: wasm32-unknown-unknown

- name: Install native toolchain for wasm build
run: |
sudo apt-get update
sudo apt-get install -y clang

- name: Install wasm-pack (pinned 0.14.x)
run: cargo install wasm-pack --version 0.14.0 --locked --force

Expand Down
12 changes: 10 additions & 2 deletions packages/ducjs/src/utils/elements/freedrawElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ function buildStrokeOptions(element: DucFreeDrawElement): StrokeOptions {
};
}

const normalizeStrokePressure = (pressure: number | undefined): number => {
if (!Number.isFinite(pressure) || pressure === undefined || pressure <= 0) {
return 0.5;
}

return Math.min(1, Math.max(0.05, pressure));
};

function buildInputPoints(element: DucFreeDrawElement): number[][] {
return element.simulatePressure
? element.points.map(({x, y}, i) => [x.scoped, y.scoped, element.pressures[i]])
: element.points.map(({x, y}) => [x.scoped, y.scoped]);
? element.points.map(({x, y}) => [x.scoped, y.scoped])
: element.points.map(({x, y}, i) => [x.scoped, y.scoped, normalizeStrokePressure(element.pressures[i])]);
}

export function getFreeDrawSvgPath(element: DucFreeDrawElement) {
Expand Down
72 changes: 59 additions & 13 deletions packages/ducjs/src/utils/elements/newElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
DucTableElement,
DucTextElement,
ElementConstructorOpts,
ElementBackground,
ElementStroke,
ElementUpdate,
NonDeleted
} from "../../types/elements";
Expand Down Expand Up @@ -349,11 +351,38 @@ export const newArrowElement = (
elbowed: opts.elbowed ?? true,
});

const withDisabledContentVisibility = <T extends ElementBackground | ElementStroke>(
items: readonly T[] | undefined,
fallback: T,
): T[] => {
const source = items?.length ? items : [fallback];
return source.map((item) => ({
...item,
content: {
...item.content,
visible: false,
},
}));
};

const getMediaElementStyle = (opts: ElementConstructorOpts) => ({
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
});

const getDocumentElementStyle = (opts: ElementConstructorOpts) => ({
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
});

export const newImageElement = (
currentScope: Scope,
opts: Partial<DucImageElement> & ElementConstructorOpts,
): NonDeleted<DucImageElement> => ({
..._newElementBase<DucImageElement>("image", currentScope, opts),
..._newElementBase<DucImageElement>("image", currentScope, {
...opts,
...getMediaElementStyle(opts),
}),
type: "image",
status: opts.status ?? IMAGE_STATUS.PENDING,
fileId: opts.fileId ?? null,
Expand All @@ -375,7 +404,10 @@ export const newDocElement = (
currentScope: Scope,
opts: Partial<DucDocElement> & ElementConstructorOpts,
): NonDeleted<DucDocElement> => ({
..._newElementBase<DucDocElement>("doc", currentScope, opts),
..._newElementBase<DucDocElement>("doc", currentScope, {
...opts,
...getDocumentElementStyle(opts),
}),
type: "doc",
text: opts.text || "",
fileId: opts.fileId ?? null,
Expand All @@ -391,19 +423,32 @@ export const newDocElement = (
export const newPdfElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucPdfElement> => ({
fileId: null,
gridConfig: { columns: 1, gapX: 0, gapY: 0, firstPageAlone: false, scale: 1 },
..._newElementBase<DucPdfElement>("pdf", currentScope, opts),
..._newElementBase<DucPdfElement>("pdf", currentScope, {
...opts,
...getDocumentElementStyle(opts),
}),
type: "pdf",
});

export const newModelElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucModelElement> => ({
modelType: null,
code: null,
thumbnail: null,
fileIds: [],
viewerState: null,
..._newElementBase<DucModelElement>("model", currentScope, opts),
type: 'model',
});
export const newModelElement = (currentScope: Scope, opts: ElementConstructorOpts): NonDeleted<DucModelElement> => {
const modelStyle = {
stroke: withDisabledContentVisibility(opts.stroke as ElementStroke[] | undefined, DEFAULT_ELEMENT_PROPS.stroke),
background: withDisabledContentVisibility(opts.background as ElementBackground[] | undefined, DEFAULT_ELEMENT_PROPS.background),
};

return {
modelType: null,
code: null,
thumbnail: null,
fileIds: [],
viewerState: null,
..._newElementBase<DucModelElement>("model", currentScope, {
...opts,
...modelStyle,
}),
type: 'model',
};
};

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