@@ -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+
352378export 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 = (
391423export 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