@pickaxeproject/react 3.6.0 → 3.6.1
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.
- package/dist/cjs/common/docx/helpers.js +1 -0
- package/dist/cjs/common/docx/index.js +1 -0
- package/dist/cjs/common/docx/types.js +1 -0
- package/dist/cjs/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/cjs/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/src/common/docx/helpers.d.ts +104 -0
- package/dist/cjs/src/common/docx/index.d.ts +28 -0
- package/dist/cjs/src/common/docx/types.d.ts +66 -0
- package/dist/esm/common/docx/helpers.js +1 -0
- package/dist/esm/common/docx/index.js +1 -0
- package/dist/esm/common/docx/types.js +1 -0
- package/dist/esm/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/esm/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/src/common/docx/helpers.d.ts +104 -0
- package/dist/esm/src/common/docx/index.d.ts +28 -0
- package/dist/esm/src/common/docx/types.d.ts +66 -0
- package/package.json +5 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Paragraph, TextRun, Table } from "docx";
|
|
2
|
+
import { Style, TableData, HeadingConfig, ListItemConfig } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Processes a heading line and returns appropriate paragraph formatting and a bookmark ID
|
|
5
|
+
* @param line - The heading line to process
|
|
6
|
+
* @param config - The heading configuration
|
|
7
|
+
* @param style - The style configuration
|
|
8
|
+
* @param documentType - The document type
|
|
9
|
+
* @returns An object containing the processed paragraph and its bookmark ID
|
|
10
|
+
*/
|
|
11
|
+
export declare function processHeading(line: string, config: HeadingConfig, style: Style, _: "document" | "report"): {
|
|
12
|
+
paragraph: Paragraph;
|
|
13
|
+
bookmarkId: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Processes a table and returns table formatting
|
|
17
|
+
* @param tableData - The table data
|
|
18
|
+
* @param documentType - The document type
|
|
19
|
+
* @returns The processed table
|
|
20
|
+
*/
|
|
21
|
+
export declare function processTable(tableData: TableData, documentType: "document" | "report"): Table;
|
|
22
|
+
/**
|
|
23
|
+
* Processes a list item and returns appropriate paragraph formatting
|
|
24
|
+
* @param config - The list item configuration
|
|
25
|
+
* @param style - The style configuration
|
|
26
|
+
* @returns The processed paragraph
|
|
27
|
+
*/
|
|
28
|
+
export declare function processListItem(config: ListItemConfig, style: Style): Paragraph;
|
|
29
|
+
/**
|
|
30
|
+
* Processes a blockquote and returns appropriate paragraph formatting
|
|
31
|
+
* @param text - The blockquote text
|
|
32
|
+
* @param style - The style configuration
|
|
33
|
+
* @returns The processed paragraph
|
|
34
|
+
*/
|
|
35
|
+
export declare function processBlockquote(text: string, style: Style): Paragraph;
|
|
36
|
+
/**
|
|
37
|
+
* Processes a comment and returns appropriate paragraph formatting
|
|
38
|
+
* @param text - The comment text
|
|
39
|
+
* @param style - The style configuration
|
|
40
|
+
* @returns The processed paragraph
|
|
41
|
+
*/
|
|
42
|
+
export declare function processComment(text: string, style: Style): Paragraph;
|
|
43
|
+
/**
|
|
44
|
+
* Processes formatted text (bold/italic/inline-code) and returns an array of TextRun objects
|
|
45
|
+
* @param line - The line to process
|
|
46
|
+
* @param style - The style configuration
|
|
47
|
+
* @returns An array of TextRun objects
|
|
48
|
+
*/
|
|
49
|
+
export declare function processFormattedText(line: string, style?: Style): TextRun[];
|
|
50
|
+
/**
|
|
51
|
+
* Collects tables from markdown lines
|
|
52
|
+
* @param lines - The markdown lines
|
|
53
|
+
* @returns An array of table data
|
|
54
|
+
*/
|
|
55
|
+
export declare function collectTables(lines: string[]): TableData[];
|
|
56
|
+
/**
|
|
57
|
+
* Processes inline code and returns a TextRun object
|
|
58
|
+
* @param code - The inline code text
|
|
59
|
+
* @param style - The style configuration
|
|
60
|
+
* @returns A TextRun object
|
|
61
|
+
*/
|
|
62
|
+
export declare function processInlineCode(code: string, style?: Style): TextRun;
|
|
63
|
+
/**
|
|
64
|
+
* Processes a code block and returns appropriate paragraph formatting
|
|
65
|
+
* @param code - The code block text
|
|
66
|
+
* @param language - The programming language (optional)
|
|
67
|
+
* @param style - The style configuration
|
|
68
|
+
* @returns The processed paragraph
|
|
69
|
+
*/
|
|
70
|
+
export declare function processCodeBlock(code: string, language: string | undefined, style: Style): Paragraph;
|
|
71
|
+
/**
|
|
72
|
+
* Processes a link and returns appropriate text run
|
|
73
|
+
*/
|
|
74
|
+
export declare function processLink(text: string, _: string): TextRun;
|
|
75
|
+
/**
|
|
76
|
+
* Processes a link and returns a paragraph with hyperlink
|
|
77
|
+
* @param text - The link text
|
|
78
|
+
* @param url - The link URL
|
|
79
|
+
* @param style - The style configuration
|
|
80
|
+
* @returns The processed paragraph with hyperlink
|
|
81
|
+
*/
|
|
82
|
+
export declare function processLinkParagraph(text: string, url: string, style: Style): Paragraph;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a simple link paragraph
|
|
85
|
+
* @param text - The link text
|
|
86
|
+
* @param url - The URL to link to
|
|
87
|
+
* @returns A paragraph with a hyperlink
|
|
88
|
+
*/
|
|
89
|
+
export declare function createLinkParagraph(text: string, url: string): Paragraph;
|
|
90
|
+
/**
|
|
91
|
+
* Processes an image and returns appropriate paragraph
|
|
92
|
+
* @param altText - The alt text
|
|
93
|
+
* @param imageUrl - The image URL
|
|
94
|
+
* @param style - The style configuration
|
|
95
|
+
* @returns The processed paragraph
|
|
96
|
+
*/
|
|
97
|
+
export declare function processImage(altText: string, imageUrl: string, style: Style): Promise<Paragraph[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Processes a paragraph and returns appropriate paragraph formatting
|
|
100
|
+
* @param text - The paragraph text
|
|
101
|
+
* @param style - The style configuration
|
|
102
|
+
* @returns The processed paragraph
|
|
103
|
+
*/
|
|
104
|
+
export declare function processParagraph(text: string, style: Style): Paragraph;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Options } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for markdown conversion errors
|
|
4
|
+
* @extends Error
|
|
5
|
+
* @param message - The error message
|
|
6
|
+
* @param context - The context of the error
|
|
7
|
+
*/
|
|
8
|
+
export declare class MarkdownConversionError extends Error {
|
|
9
|
+
context?: any;
|
|
10
|
+
constructor(message: string, context?: any);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Convert Markdown to Docx
|
|
14
|
+
* @param markdown - The Markdown string to convert
|
|
15
|
+
* @param options - The options for the conversion
|
|
16
|
+
* @returns A Promise that resolves to a Blob containing the Docx file
|
|
17
|
+
* @throws {MarkdownConversionError} If conversion fails
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertMarkdownToDocx(markdown: string, options?: Options): Promise<Blob>;
|
|
20
|
+
/**
|
|
21
|
+
* Downloads a DOCX file in the browser environment
|
|
22
|
+
* @param blob - The Blob containing the DOCX file data
|
|
23
|
+
* @param filename - The name to save the file as (defaults to "document.docx")
|
|
24
|
+
* @throws {Error} If the function is called outside browser environment
|
|
25
|
+
* @throws {Error} If invalid blob or filename is provided
|
|
26
|
+
* @throws {Error} If file save fails
|
|
27
|
+
*/
|
|
28
|
+
export declare function downloadDocx(blob: Blob, filename?: string): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface Style {
|
|
2
|
+
titleSize: number;
|
|
3
|
+
headingSpacing: number;
|
|
4
|
+
paragraphSpacing: number;
|
|
5
|
+
lineSpacing: number;
|
|
6
|
+
heading1Size?: number;
|
|
7
|
+
heading2Size?: number;
|
|
8
|
+
heading3Size?: number;
|
|
9
|
+
heading4Size?: number;
|
|
10
|
+
heading5Size?: number;
|
|
11
|
+
paragraphSize?: number;
|
|
12
|
+
listItemSize?: number;
|
|
13
|
+
codeBlockSize?: number;
|
|
14
|
+
blockquoteSize?: number;
|
|
15
|
+
tocFontSize?: number;
|
|
16
|
+
tocHeading1FontSize?: number;
|
|
17
|
+
tocHeading2FontSize?: number;
|
|
18
|
+
tocHeading3FontSize?: number;
|
|
19
|
+
tocHeading4FontSize?: number;
|
|
20
|
+
tocHeading5FontSize?: number;
|
|
21
|
+
tocHeading1Bold?: boolean;
|
|
22
|
+
tocHeading2Bold?: boolean;
|
|
23
|
+
tocHeading3Bold?: boolean;
|
|
24
|
+
tocHeading4Bold?: boolean;
|
|
25
|
+
tocHeading5Bold?: boolean;
|
|
26
|
+
tocHeading1Italic?: boolean;
|
|
27
|
+
tocHeading2Italic?: boolean;
|
|
28
|
+
tocHeading3Italic?: boolean;
|
|
29
|
+
tocHeading4Italic?: boolean;
|
|
30
|
+
tocHeading5Italic?: boolean;
|
|
31
|
+
paragraphAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
32
|
+
headingAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
33
|
+
heading1Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
34
|
+
heading2Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
35
|
+
heading3Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
36
|
+
heading4Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
37
|
+
heading5Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
38
|
+
blockquoteAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
|
|
39
|
+
}
|
|
40
|
+
export interface Options {
|
|
41
|
+
documentType?: "document" | "report";
|
|
42
|
+
style?: Style;
|
|
43
|
+
}
|
|
44
|
+
export interface TableData {
|
|
45
|
+
headers: string[];
|
|
46
|
+
rows: string[][];
|
|
47
|
+
}
|
|
48
|
+
export interface ProcessedContent {
|
|
49
|
+
children: any[];
|
|
50
|
+
skipLines: number;
|
|
51
|
+
}
|
|
52
|
+
export interface HeadingConfig {
|
|
53
|
+
level: number;
|
|
54
|
+
size: number;
|
|
55
|
+
style?: string;
|
|
56
|
+
alignment?: any;
|
|
57
|
+
}
|
|
58
|
+
export interface ListItemConfig {
|
|
59
|
+
text: string;
|
|
60
|
+
boldText?: string;
|
|
61
|
+
isNumbered?: boolean;
|
|
62
|
+
listNumber?: number;
|
|
63
|
+
sequenceId?: number;
|
|
64
|
+
}
|
|
65
|
+
export declare const defaultStyle: Style;
|
|
66
|
+
export declare const headingConfigs: Record<number, HeadingConfig>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as e}from"../../_virtual/_tslib.js";import{AlignmentType as n,Paragraph as t,Bookmark as i,TextRun as r,Table as a,WidthType as l,TableRow as o,TableCell as c,TableLayoutType as g,BorderStyle as s,ExternalHyperlink as p,ImageRun as h}from"docx";function d(e,a,l,o){const c=e.replace(new RegExp(`^#{${a.level}} `),""),g=a.level,s=`_Toc_${function(e){let n=e.replace(/[^a-zA-Z0-9_\s]/g,"").replace(/\s+/g,"_");return/^[a-zA-Z_]/.test(n)||(n="_"+n),n.substring(0,40)}(c.replace(/\*\*/g,"").replace(/\*/g,""))}_${Date.now()}`;let p,h=l.titleSize;1===g&&l.heading1Size?h=l.heading1Size:2===g&&l.heading2Size?h=l.heading2Size:3===g&&l.heading3Size?h=l.heading3Size:4===g&&l.heading4Size?h=l.heading4Size:5===g&&l.heading5Size?h=l.heading5Size:g>1&&(h=l.titleSize-4*(g-1)),1===g&&l.heading1Alignment?p=n[l.heading1Alignment]:2===g&&l.heading2Alignment?p=n[l.heading2Alignment]:3===g&&l.heading3Alignment?p=n[l.heading3Alignment]:4===g&&l.heading4Alignment?p=n[l.heading4Alignment]:5===g&&l.heading5Alignment?p=n[l.heading5Alignment]:l.headingAlignment&&(p=n[l.headingAlignment]);const d=function(e,n){const t=[];let i="",a=!1,l=!1,o=-1,c=-1;for(let g=0;g<e.length;g++)if("\\"===e[g]&&g+1<e.length){const n=e[g+1];if("*"===n||"\\"===n){i+=n,g++;continue}i+=e[g]}else g+1<e.length&&"*"===e[g]&&"*"===e[g+1]?(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n})),i=""),o=a?-1:g,a=!a,g++):"*"!==e[g]||0!==g&&"*"===e[g-1]||g!==e.length-1&&"*"===e[g+1]?i+=e[g]:(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n})),i=""),c=l?-1:g,l=!l);if(i){if(a&&o>=0){i="**"+i,a=!1}if(l&&c>=0){i="*"+i,l=!1}i.trim()&&t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n}))}0===t.length&&t.push(new r({text:"",color:"000000",size:n,bold:!0}));return t}(c,h);return{paragraph:new t({children:[new i({id:s,children:d})],heading:g,spacing:{before:1===a.level?2*l.headingSpacing:l.headingSpacing,after:l.headingSpacing/2},alignment:p,style:`Heading${g}`}),bookmarkId:s}}function f(e,i){return new a({width:{size:100,type:l.PERCENTAGE},rows:[new o({tableHeader:!0,children:e.headers.map((e=>new c({children:[new t({alignment:n.CENTER,style:"Strong",children:[new r({text:e,bold:!0,color:"000000"})]})],shading:{fill:"report"===i?"DDDDDD":"F2F2F2"}})))}),...e.rows.map((e=>new o({children:e.map((e=>new c({children:[new t({children:[new r({text:e,color:"000000"})]})]})))})))],layout:g.FIXED,margins:{top:100,bottom:100,left:100,right:100}})}function u(e,n){const i=w(e.text,n);if(e.boldText&&i.push(new r({text:"\n",size:n.listItemSize||24}),new r({text:e.boldText,bold:!0,color:"000000",size:n.listItemSize||24})),e.isNumbered){const r=`numbered-list-${e.sequenceId||1}`;return new t({children:i,numbering:{reference:r,level:0},spacing:{before:n.paragraphSpacing/2,after:n.paragraphSpacing/2}})}return new t({children:i,bullet:{level:0},spacing:{before:n.paragraphSpacing/2,after:n.paragraphSpacing/2}})}function m(e,i){let a;if(i.blockquoteAlignment)switch(i.blockquoteAlignment){case"LEFT":a=n.LEFT;break;case"CENTER":a=n.CENTER;break;case"RIGHT":a=n.RIGHT;break;case"JUSTIFIED":a=n.JUSTIFIED;break;default:a=void 0}return new t({children:[new r({text:e,italics:!0,color:"000000",size:i.blockquoteSize||24})],indent:{left:720},spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing},border:{left:{style:s.SINGLE,size:3,color:"AAAAAA"}},alignment:a})}function S(e,n){return new t({children:[new r({text:"Comment: "+e,italics:!0,color:"666666"})],spacing:{before:n.paragraphSpacing,after:n.paragraphSpacing}})}function w(e,n){const t=[];let i="",a=!1,l=!1,o=!1,c=-1,g=-1;for(let s=0;s<e.length;s++)if("\\"===e[s]&&s+1<e.length){const n=e[s+1];if("*"===n||"`"===n||"\\"===n){i+=n,s++;continue}i+=e[s]}else"`"!==e[s]||o?"`"===e[s]&&o?(i&&(t.push(b(i,n)),i=""),o=!1):o?i+=e[s]:s+1<e.length&&"*"===e[s]&&"*"===e[s+1]?(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),c=a?-1:s,a=!a,s++):"*"!==e[s]||0!==s&&"*"===e[s-1]||s!==e.length-1&&"*"===e[s+1]?i+=e[s]:(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),g=l?-1:s,l=!l):(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),o=!0);if(i){if(a&&c>=0){i="**"+i,a=!1}if(l&&g>=0){i="*"+i,l=!1}o&&(i="`"+i),i.trim()&&t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24}))}return 0===t.length&&t.push(new r({text:"",color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),t}function z(e){const n=[];for(let t=0;t<e.length;t++){const i=e[t];if(i.trim().startsWith("|")&&t+1<e.length&&/^\s*\|(?:\s*:?-+:?\s*\|)+\s*$/.test(e[t+1])){const r=i.split("|").filter(Boolean).map((e=>e.trim())),a=[];let l=t+2;for(;l<e.length&&e[l].trim().startsWith("|");){const n=e[l].split("|").filter(Boolean).map((e=>e.trim()));a.push(n),l++}n.push({headers:r,rows:a})}}return n}function b(e,n){return new r({text:e,font:"Courier New",size:(null==n?void 0:n.paragraphSize)?n.paragraphSize-2:20,color:"444444",shading:{fill:"F5F5F5"}})}function E(e,n,i){const a=e.split("\n"),l=[];return n&&l.push(new r({text:n,font:"Courier New",size:i.codeBlockSize||18,color:"666666",bold:!0}),new r({text:"\n",font:"Courier New",size:i.codeBlockSize||18,break:1})),a.forEach(((e,n)=>{var t;const o=(null===(t=e.match(/^\s*/))||void 0===t?void 0:t[0].length)||0,c=" ".repeat(o)+e.slice(o);l.push(new r({text:c,font:"Courier New",size:i.codeBlockSize||20,color:"444444"})),n<a.length-1&&l.push(new r({text:"\n",font:"Courier New",size:i.codeBlockSize||20,break:1}))})),new t({children:l,spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing,line:360,lineRule:"exact"},shading:{fill:"F5F5F5"},border:{top:{style:s.SINGLE,size:1,color:"DDDDDD"},bottom:{style:s.SINGLE,size:1,color:"DDDDDD"},left:{style:s.SINGLE,size:1,color:"DDDDDD"},right:{style:s.SINGLE,size:1,color:"DDDDDD"}},indent:{left:360}})}function D(e,n,i){const a=new p({children:[new r({text:e,color:"0000FF",underline:{type:"single"}})],link:n});return new t({children:[a],spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing}})}function x(i,a,l){return e(this,void 0,void 0,(function*(){try{console.log(`Starting image processing for URL: ${a}`);const e=yield fetch(a);if(console.log(`Fetch response status: ${e.status}`),!e.ok)throw new Error(`Failed to fetch image: ${e.status} ${e.statusText}`);const i=yield e.arrayBuffer();console.log(`ArrayBuffer size: ${i.byteLength} bytes`);const r=Buffer.from(i);return console.log(`Buffer size: ${r.length} bytes`),[new t({children:[new h({data:r,transformation:{width:200,height:200},type:"jpg"})],alignment:n.CENTER,spacing:{before:l.paragraphSpacing,after:l.paragraphSpacing}})]}catch(e){return console.error("Error in processImage:",e),console.error("Error stack:",e instanceof Error?e.stack:"No stack available"),[new t({children:[new r({text:`[Image could not be displayed: ${i}]`,italics:!0,color:"FF0000"})],alignment:n.CENTER})]}}))}function A(e,i){const r=w(e,i),a=i.paragraphAlignment?"CENTER"===i.paragraphAlignment?n.CENTER:"RIGHT"===i.paragraphAlignment?n.RIGHT:"JUSTIFIED"===i.paragraphAlignment?n.JUSTIFIED:n.LEFT:n.LEFT;console.log(`Paragraph alignment: ${a}, Style alignment: ${i.paragraphAlignment}`);const l="JUSTIFIED"===i.paragraphAlignment?{left:0,right:0}:void 0;return new t({children:r,spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing,line:240*i.lineSpacing},alignment:a,indent:l})}export{z as collectTables,m as processBlockquote,E as processCodeBlock,S as processComment,w as processFormattedText,d as processHeading,x as processImage,b as processInlineCode,D as processLinkParagraph,u as processListItem,A as processParagraph,f as processTable};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as e}from"../../_virtual/_tslib.js";import{Paragraph as n,PageBreak as t,TextRun as i,AlignmentType as o,InternalHyperlink as r,LevelFormat as a,Document as s,PageOrientation as l,Footer as c,PageNumber as d,Packer as g}from"docx";import p from"file-saver";import{headingConfigs as h}from"./types.js";import{collectTables as u,processCodeBlock as m,processHeading as f,processTable as b,processListItem as w,processBlockquote as S,processComment as v,processImage as z,processLinkParagraph as E,processParagraph as H}from"./helpers.js";const F={titleSize:32,headingSpacing:240,paragraphSpacing:240,lineSpacing:1.15,paragraphAlignment:"LEFT"},x={documentType:"document",style:F};class k extends Error{constructor(e,n){super(e),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="MarkdownConversionError"}}function T(p,T=x){return e(this,void 0,void 0,(function*(){try{const{style:e=F,documentType:x="document"}=T,k=[],y=[],N=p.split("\n");let $,W=!1,C=[],O=1,I=!1,B=0,L=!1,R="",q=0;const j=u(N);for(let r=0;r<N.length;r++)try{const a=N[r],s=a.trim();if(!s){L&&(R+="\n"),W&&(k.push(...C),C=[],W=!1,O=1,I=!1),k.push(new n({}));continue}if("\\pagebreak"===s){W&&(k.push(...C),C=[],W=!1,O=1,I=!1),k.push(new n({children:[new t]}));continue}if(/^\s*---\s*$/.test(s)){W&&(k.push(...C),C=[],W=!1,O=1,I=!1);continue}if("[TOC]"===s){W&&(k.push(...C),C=[],W=!1);const e=new n({});e.__isTocPlaceholder=!0,k.push(e);continue}if(s.startsWith("```")){L?(L=!1,k.push(m(R.trim(),$,e)),R="",$=void 0):(L=!0,$=s.slice(3).trim()||void 0,R="");continue}if(L){R+=(R?"\n":"")+a;continue}if(s.startsWith("#")){const n=s.match(/^#+/);if(n){const t=n[0].length;if(t>=1&&t<=5){W&&(k.push(...C),C=[],W=!1);const n=s.substring(t).trim(),i=Object.assign(Object.assign({},h[t]),{alignment:h[t].alignment||e.headingAlignment}),{paragraph:o,bookmarkId:r}=f(s,i,e,x);y.push({text:n,level:t,bookmarkId:r}),k.push(o);continue}console.warn(`Warning: Heading level ${t} is not supported. Converting to regular paragraph.`)}}if(s.startsWith("|")&&s.endsWith("|")&&r+1<N.length&&(/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(N[r+1])||r+2<N.length&&/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(N[r+2]))&&(W&&(k.push(...C),C=[],W=!1),q<j.length))try{k.push(b(j[q],x));r+=2+j[q].rows.length-1,q++;continue}catch(e){console.warn(`Warning: Failed to process table at line ${r+1}. Converting to regular text.`),k.push(new n({children:[new i({text:s.replace(/\|/g,"").trim(),color:"000000"})]}));continue}if(s.startsWith("- ")||s.startsWith("* ")){I&&(O=1,I=!1),W=!0;const n=s.replace(/^[\s-*]+/,"").trim();let t="";r+1<N.length&&N[r+1].trim().startsWith("**")&&N[r+1].trim().endsWith("**")&&(t=N[r+1].trim().slice(2,-2),r++),C.push(w({text:n,boldText:t},e));continue}if(/^\s*\d+\.\s/.test(s)){I&&W||(B++,O=1,I=!0),W=!0;const n=s.replace(/^\s*\d+\.\s/,"").trim();let t="";r+1<N.length&&N[r+1].trim().startsWith("**")&&N[r+1].trim().endsWith("**")&&(t=N[r+1].trim().slice(2,-2),r++),C.push(w({text:n,boldText:t,isNumbered:!0,listNumber:O,sequenceId:B},e)),O++;continue}if(s.startsWith("> ")){W&&(k.push(...C),C=[],W=!1);const n=s.replace(/^>\s*/,"").trim();k.push(S(n,e));continue}if(s.startsWith("COMMENT:")){W&&(k.push(...C),C=[],W=!1);const n=s.replace(/^COMMENT:\s*/,"").trim();k.push(v(n,e));continue}const l=s.match(/!\[([^\]]*)\]\(([^)]+)\)/);if(l){const[t,r,a]=l;console.log(`Found image in markdown: ${a}`);try{console.log(`Starting image processing for: ${a}`);const n=yield z(r,a,e);console.log(`Successfully processed image, adding ${n.length} paragraphs`),k.push(...n)}catch(e){console.error(`Error in image processing: ${e instanceof Error?e.message:String(e)}`),k.push(new n({children:[new i({text:`[Image could not be loaded: ${r}]`,italics:!0,color:"FF0000"})],alignment:o.CENTER}))}continue}const c=s.match(/^(?!.*!\[).*\[([^\]]+)\]\(([^)]+)\)/);if(c){const[n,t,i]=c;k.push(E(t,i,e));continue}if(!W){try{k.push(H(s,e))}catch(t){console.warn(`Warning: Failed to process text formatting at line ${r+1}: ${t instanceof Error?t.message:String(t)}. Using plain text.`),k.push(new n({children:[new i({text:s,color:"000000",size:e.paragraphSize||24})],spacing:{before:e.paragraphSpacing,after:e.paragraphSpacing,line:240*e.lineSpacing},alignment:e.paragraphAlignment?o[e.paragraphAlignment]:void 0}))}continue}}catch(e){console.warn(`Warning: Failed to process line ${r+1}: ${e instanceof Error?e.message:"Unknown error"}. Skipping line.`);continue}L&&R&&k.push(m(R.trim(),$,e)),W&&C.length>0&&k.push(...C);const A=[];y.length>0&&(A.push(new n({text:"Table of Contents",heading:"Heading1",alignment:o.CENTER,spacing:{after:240}})),y.forEach((t=>{let o,a=!1,s=!1;switch(t.level){case 1:o=e.tocHeading1FontSize||e.tocFontSize,a=void 0===e.tocHeading1Bold||e.tocHeading1Bold,s=e.tocHeading1Italic||!1;break;case 2:o=e.tocHeading2FontSize||e.tocFontSize,a=void 0!==e.tocHeading2Bold&&e.tocHeading2Bold,s=e.tocHeading2Italic||!1;break;case 3:o=e.tocHeading3FontSize||e.tocFontSize,a=e.tocHeading3Bold||!1,s=e.tocHeading3Italic||!1;break;case 4:o=e.tocHeading4FontSize||e.tocFontSize,a=e.tocHeading4Bold||!1,s=e.tocHeading4Italic||!1;break;case 5:o=e.tocHeading5FontSize||e.tocFontSize,a=e.tocHeading5Bold||!1,s=e.tocHeading5Italic||!1;break;default:o=e.tocFontSize}o||(o=e.paragraphSize?e.paragraphSize-2*(t.level-1):24-2*(t.level-1)),A.push(new n({children:[new r({anchor:t.bookmarkId,children:[new i({text:t.text,size:o,bold:a,italics:s})]})],indent:{left:400*(t.level-1)},spacing:{after:120}}))})));const M=[];let _=!1;k.forEach((e=>{!0===e.__isTocPlaceholder?A.length>0&&!_?(M.push(...A),_=!0):console.warn("TOC placeholder found, but no headings collected or TOC already inserted."):M.push(e)}));const U=[];for(let e=1;e<=B;e++)U.push({reference:`numbered-list-${e}`,levels:[{level:0,format:a.DECIMAL,text:"%1.",alignment:o.LEFT,style:{paragraph:{indent:{left:720,hanging:260}}}}]});const P=new s({numbering:{config:U},sections:[{properties:{page:{margin:{top:1440,right:1080,bottom:1440,left:1080},size:{orientation:l.PORTRAIT}}},footers:{default:new c({children:[new n({alignment:o.CENTER,children:[new i({children:[d.CURRENT]})]})]})},children:M}],styles:{paragraphStyles:[{id:"Title",name:"Title",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{after:240,line:240*e.lineSpacing},alignment:o.CENTER}},{id:"Heading1",name:"Heading 1",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{before:360,after:240},outlineLevel:1}},{id:"Heading2",name:"Heading 2",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-4,bold:!0,color:"000000"},paragraph:{spacing:{before:320,after:160},outlineLevel:2}},{id:"Heading3",name:"Heading 3",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-8,bold:!0,color:"000000"},paragraph:{spacing:{before:280,after:120},outlineLevel:3}},{id:"Heading4",name:"Heading 4",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-12,bold:!0,color:"000000"},paragraph:{spacing:{before:240,after:120},outlineLevel:4}},{id:"Heading5",name:"Heading 5",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-16,bold:!0,color:"000000"},paragraph:{spacing:{before:220,after:100},outlineLevel:5}},{id:"Strong",name:"Strong",run:{bold:!0}}]}});return yield g.toBlob(P)}catch(e){if(e instanceof k)throw e;throw new k(`Failed to convert markdown to docx: ${e instanceof Error?e.message:"Unknown error"}`,{originalError:e})}}))}function y(e,n="document.docx"){if("undefined"==typeof window)throw new Error("This function can only be used in browser environments");if(!(e instanceof Blob))throw new Error("Invalid blob provided");if(!n||"string"!=typeof n)throw new Error("Invalid filename provided");try{p(e,n)}catch(e){throw console.error("Failed to save file:",e),new Error(`Failed to save file: ${e instanceof Error?e.message:"Unknown error"}`)}}export{k as MarkdownConversionError,T as convertMarkdownToDocx,y as downloadDocx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={1:{level:1,size:0,style:"Title"},2:{level:2,size:0,style:"Heading2"},3:{level:3,size:0},4:{level:4,size:0},5:{level:5,size:0}};export{e as headingConfigs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useMemo as i,useEffect as a}from"react";import{useArtifactContext as l}from"../hooks/useArtifactContext.js";import{usePickaxeContext as c}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useScroll as s}from"../../Scroll/hooks/useScroll.js";import{useArtifact as d}from"../hooks/useArtifact.js";import{useReactToPrint as p}from"react-to-print";import{PickaxeMarkdown as m}from"../../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as u}from"../../../common/PickaxeMarkdown/Renderer.js";import{Prism as v}from"react-syntax-highlighter";import{convertMarkdownToDocx as f,downloadDocx as y}from"@mohtasham/md-to-docx";import g from"../../Scroll/ScrollLockView.js";import x from"../../../../Icons/x.svg.js";import h from"../../../../Icons/save.svg.js";import b from"../../../../Icons/expand.svg.js";import C from"../../../../Icons/shrink.svg.js";import w from"../../../common/PickaxeCopyButton.js";import k from"../../../../Core/ScrollArea.js";import j from"../../../../Core/TipContainer.js";import F from"../MermaidRenderer.js";import O from"./SaveMenu.js";import T from"./ViewOptions.js";import A from"csv-to-markdown-table";import S from"../../../../../common/cn.js";const D="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",E=E=>{var N,B,L,z;const{artifacts:M,currentPopupType:R,currentArtifact:$,setCurrentArtifact:W}=l(),{onLoadArtifact:H}=d(),{styles:P,colors:I,translations:_}=c(),[U,V]=n("code"),X=r(),q=r(null),G=r(null),J=p({contentRef:X}),{scrollContainerRef:K,scrollStartSession:Q,scrollToBottom:Y,scrollEndSession:Z}=s({auto:"code"===U}),ee=null!==(B=null===(N=E.styling)||void 0===N?void 0:N.styles)&&void 0!==B?B:P,oe=null!==(z=null===(L=E.styling)||void 0===L?void 0:L.colors)&&void 0!==z?z:I,te=i((()=>{var e,o,t,n,r;if(!E.artifact&&!$)return null;const i=null!==(o=null===(e=E.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==$?void 0:$.id,a=null!==(n=null===(t=E.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==$?void 0:$.version;return null!==(r=M.find((e=>e.id===i&&e.version===a)))&&void 0!==r?r:null}),[$,M,E.artifact]),ne=i((()=>te&&"text/csv"===te.type?A(te.content,",",!0):null),[te]),re=i((()=>(oe.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==oe?void 0:oe.secondaryText]),ie=i((()=>{const e=E.artifact&&(null==$?void 0:$.id)===E.artifact.id&&(null==$?void 0:$.version)===E.artifact.version;return"inline"===E.type&&("inline-form"===R?!!$:e)}),[$,R,E.type,E.artifact]);a((()=>{e(void 0,void 0,void 0,(function*(){"inline"===E.type&&E.artifact&&(M.some((e=>E.artifact&&e.id===E.artifact.id&&e.version===E.artifact.version))||H({id:E.artifact.id,version:E.artifact.version}))}))}),[M,E.type,E.artifact]),a((()=>{if("application/vnd.pxe.code"===(null==te?void 0:te.type)&&V("code"),"finished"!==(null==te?void 0:te.status))return V("code"),Q(),void Y();Z(),"application/vnd.pxe.code"!==te.type&&V("render")}),[null==te?void 0:te.status,null==te?void 0:te.type]),a((()=>{var e;!G.current||"text/html"!==(null==te?void 0:te.type)&&"application/vnd.pxe.react"!==(null==te?void 0:te.type)||null===(e=G.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===te.type?"HTML_CODE":"REACT_CODE",content:te.content},D)}),[null==te?void 0:te.content,null==te?void 0:te.type]);const ae=()=>e(void 0,void 0,void 0,(function*(){if(!te)return;const e=U;"code"===e&&(V("render"),yield new Promise((e=>setTimeout(e,50)))),J(),"code"===e&&V(e)})),le=()=>e(void 0,void 0,void 0,(function*(){if(!te)return;const e=yield f(te.content);y(e,`${te.title}.docx`)})),ce=o=>e(void 0,void 0,void 0,(function*(){var e;if(!te)return;let t={mimeType:"text/plain",extension:".txt"};switch(o){case"text/markdown":t={mimeType:"text/markdown",extension:".md"};break;case"text/html":t={mimeType:"text/html",extension:".html"};break;case"text/csv":t={mimeType:"text/csv",extension:".csv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":t={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":t={mimeType:`application/${te.programmingLanguage||"text"};charset=utf-8`,extension:`.${te.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":t={mimeType:"text/typescript",extension:".tsx"};break;default:t={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===te.type){const o=U;"code"===o&&(V("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=q.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&V(o)}const r=new Blob([null!=n?n:te.content],{type:t.mimeType}),i=URL.createObjectURL(r);try{const e=document.createElement("a");e.href=i,e.download=`${te.title}${t.extension}`,e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(i)}}));return te?o("div",Object.assign({className:S("pxe-artifact-renderer flex flex-col","inline"===E.type&&!ie&&"min-h-[320px] mb-6",E.className),style:Object.assign(Object.assign({backgroundColor:oe.secondary,color:oe.secondaryText},"auto"!==R&&{borderRadius:ee.cornerRadius}),E.style)},{children:[o("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[o("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(ie||!R.startsWith("inline"))&&t(T,{type:te.type,view:U,colors:oe,onChange:V}),t("p",Object.assign({className:"font-semilight truncate text-xl"},{children:te.title}))]})),o("div",Object.assign({className:"flex items-center gap-3"},{children:[(ie||!R.startsWith("inline"))&&t(O,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:te,colors:oe,onDownload:ce,onSaveAsPDF:ae,onSaveAsDOCX:le},{children:t("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==_?void 0:_["save-as"])||"Save as"}))})),t("button",Object.assign({style:{color:oe.secondaryText},onClick:()=>{"inline"!==E.type||!E.artifact||ie?W(null):W({id:E.artifact.id,version:E.artifact.version})}},{children:"inline"===E.type?t(ie?C:b,{className:"w-6 h-6 shrink-0"}):t(x,{className:"w-6 h-6 shrink-0"})}))]}))]})),t("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o(k,Object.assign({ref:K,innerClassName:"flex-grow w-full"},{children:["render"===U&&"application/vnd.pxe.code"!==te.type?t("div",Object.assign({ref:X,className:S("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===te.type&&"p-0","text/html"===te.type&&"p-0","text/csv"===te.type&&"p-0")},{children:"text/markdown"===te.type||"text/csv"===te.type||"image/svg+xml"===te.type?t(m,Object.assign({theme:ee.theme,colors:oe},{children:t(u,{value:null!=ne?ne:te.content,className:S("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===te.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===te.type?t(F,{ref:q,id:`mermaid-${te.id}-${te.version}`,data:te.content}):"text/html"===te.type||"application/vnd.pxe.react"===te.type?t("iframe",Object.assign({ref:G,title:te.title,src:`${D}/${"text/html"===te.type?"html":"react"}?theme=${re?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==oe?void 0:oe.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const o=e.target;setTimeout((()=>{var e;try{null===(e=o.contentWindow)||void 0===e||e.postMessage({type:"text/html"===te.type?"HTML_CODE":"REACT_CODE",content:te.content},D)}catch(e){console.error("Error sending message to iframe:",e)}}),100),Y()}},{children:"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t(v,Object.assign({PreTag:"div",language:"text/markdown"===te.type?"markdown":"text/html"===te.type||"image/svg+xml"===te.type?"xml":"application/vnd.pxe.react"===te.type?"typescript":te.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==oe?void 0:oe.secondaryText},re&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==oe?void 0:oe.secondaryText},re&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==oe?void 0:oe.secondary}),':not(pre) > code[class*="language-"]':{background:null==oe?void 0:oe.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==oe?void 0:oe.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!re&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==oe?void 0:oe.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:te.content})),t(g,{})]}))})),"inline"===E.type&&!ie&&o("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t(j,Object.assign({id:`artifact-copy-${te.id}-${te.version}`,tip:(null==_?void 0:_.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:oe.secondary,color:oe.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(w,{color:oe.secondaryText,text:te.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t(j,Object.assign({id:`artifact-save-${te.id}-${te.version}`,tip:(null==_?void 0:_.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:oe.secondary,color:oe.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(O,Object.assign({data:te,colors:oe,onDownload:ce,onSaveAsPDF:ae,onSaveAsDOCX:le},{children:t("button",Object.assign({style:{color:oe.secondaryText}},{children:t(h,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};export{E as default};
|
|
1
|
+
import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useMemo as i,useEffect as a}from"react";import{useArtifactContext as l}from"../hooks/useArtifactContext.js";import{usePickaxeContext as c}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useScroll as s}from"../../Scroll/hooks/useScroll.js";import{useArtifact as d}from"../hooks/useArtifact.js";import{useReactToPrint as p}from"react-to-print";import{PickaxeMarkdown as m}from"../../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as u}from"../../../common/PickaxeMarkdown/Renderer.js";import{Prism as v}from"react-syntax-highlighter";import{convertMarkdownToDocx as f,downloadDocx as g}from"../../../../../common/docx/index.js";import x from"file-saver";import y from"../../Scroll/ScrollLockView.js";import h from"../../../../Icons/x.svg.js";import b from"../../../../Icons/save.svg.js";import C from"../../../../Icons/expand.svg.js";import w from"../../../../Icons/shrink.svg.js";import k from"../../../common/PickaxeCopyButton.js";import j from"../../../../Core/ScrollArea.js";import F from"../../../../Core/TipContainer.js";import T from"../MermaidRenderer.js";import O from"./SaveMenu.js";import A from"./ViewOptions.js";import S from"csv-to-markdown-table";import D from"../../../../../common/cn.js";const E="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",N=N=>{var B,z,M,$;const{artifacts:L,currentPopupType:W,currentArtifact:R,setCurrentArtifact:H}=l(),{onLoadArtifact:P}=d(),{styles:I,colors:_,translations:V}=c(),[X,q]=n("code"),G=r(),J=r(null),K=r(null),Q=p({contentRef:G}),{scrollContainerRef:U,scrollStartSession:Y,scrollToBottom:Z,scrollEndSession:ee}=s({auto:"code"===X}),oe=null!==(z=null===(B=N.styling)||void 0===B?void 0:B.styles)&&void 0!==z?z:I,te=null!==($=null===(M=N.styling)||void 0===M?void 0:M.colors)&&void 0!==$?$:_,ne=i((()=>{var e,o,t,n,r;if(!N.artifact&&!R)return null;const i=null!==(o=null===(e=N.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==R?void 0:R.id,a=null!==(n=null===(t=N.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==R?void 0:R.version;return null!==(r=L.find((e=>e.id===i&&e.version===a)))&&void 0!==r?r:null}),[R,L,N.artifact]),re=i((()=>ne&&"text/csv"===ne.type?S(ne.content,",",!0):null),[ne]),ie=i((()=>(te.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==te?void 0:te.secondaryText]),ae=i((()=>{const e=N.artifact&&(null==R?void 0:R.id)===N.artifact.id&&(null==R?void 0:R.version)===N.artifact.version;return"inline"===N.type&&("inline-form"===W?!!R:e)}),[R,W,N.type,N.artifact]);a((()=>{e(void 0,void 0,void 0,(function*(){"inline"===N.type&&N.artifact&&(L.some((e=>N.artifact&&e.id===N.artifact.id&&e.version===N.artifact.version))||P({id:N.artifact.id,version:N.artifact.version}))}))}),[L,N.type,N.artifact]),a((()=>{if("application/vnd.pxe.code"===(null==ne?void 0:ne.type)&&q("code"),"finished"!==(null==ne?void 0:ne.status))return q("code"),Y(),void Z();ee(),"application/vnd.pxe.code"!==ne.type&&q("render")}),[null==ne?void 0:ne.status,null==ne?void 0:ne.type]),a((()=>{var e;!K.current||"text/html"!==(null==ne?void 0:ne.type)&&"application/vnd.pxe.react"!==(null==ne?void 0:ne.type)||null===(e=K.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ne.type?"HTML_CODE":"REACT_CODE",content:ne.content},E)}),[null==ne?void 0:ne.content,null==ne?void 0:ne.type]);const le=()=>e(void 0,void 0,void 0,(function*(){if(!ne)return;const e=X;"code"===e&&(q("render"),yield new Promise((e=>setTimeout(e,50)))),Q(),"code"===e&&q(e)})),ce=()=>e(void 0,void 0,void 0,(function*(){if(!ne)return;const e=yield f(ne.content);g(e,`${ne.title}.docx`)})),se=o=>e(void 0,void 0,void 0,(function*(){var e;if(!ne)return;let t={mimeType:"text/plain",extension:".txt"};switch(o){case"text/markdown":t={mimeType:"text/markdown",extension:".md"};break;case"text/html":t={mimeType:"text/html",extension:".html"};break;case"text/csv":t={mimeType:"text/csv",extension:".csv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":t={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":t={mimeType:`application/${ne.programmingLanguage||"text"};charset=utf-8`,extension:`.${ne.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":t={mimeType:"text/typescript",extension:".tsx"};break;default:t={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ne.type){const o=X;"code"===o&&(q("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=J.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&q(o)}const r=new Blob([null!=n?n:ne.content],{type:t.mimeType});x(r,`${ne.title}${t.extension}`)}));return ne?o("div",Object.assign({className:D("pxe-artifact-renderer flex flex-col","inline"===N.type&&!ae&&"min-h-[320px] mb-6",N.className),style:Object.assign(Object.assign({backgroundColor:te.secondary,color:te.secondaryText},"auto"!==W&&{borderRadius:oe.cornerRadius}),N.style)},{children:[o("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[o("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(ae||!W.startsWith("inline"))&&t(A,{type:ne.type,view:X,colors:te,onChange:q}),t("p",Object.assign({className:"font-semilight truncate text-xl"},{children:ne.title}))]})),o("div",Object.assign({className:"flex items-center gap-3"},{children:[(ae||!W.startsWith("inline"))&&t(O,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:ne,colors:te,onDownload:se,onSaveAsPDF:le,onSaveAsDOCX:ce},{children:t("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==V?void 0:V["save-as"])||"Save as"}))})),t("button",Object.assign({style:{color:te.secondaryText},onClick:()=>{"inline"!==N.type||!N.artifact||ae?H(null):H({id:N.artifact.id,version:N.artifact.version})}},{children:"inline"===N.type?t(ae?w:C,{className:"w-6 h-6 shrink-0"}):t(h,{className:"w-6 h-6 shrink-0"})}))]}))]})),t("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o(j,Object.assign({ref:U,innerClassName:"flex-grow w-full"},{children:["render"===X&&"application/vnd.pxe.code"!==ne.type?t("div",Object.assign({ref:G,className:D("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===ne.type&&"p-0","text/html"===ne.type&&"p-0","text/csv"===ne.type&&"p-0")},{children:"text/markdown"===ne.type||"text/csv"===ne.type||"image/svg+xml"===ne.type?t(m,Object.assign({theme:oe.theme,colors:te},{children:t(u,{value:null!=re?re:ne.content,className:D("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===ne.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ne.type?t(T,{ref:J,id:`mermaid-${ne.id}-${ne.version}`,data:ne.content}):"text/html"===ne.type||"application/vnd.pxe.react"===ne.type?t("iframe",Object.assign({ref:K,title:ne.title,src:`${E}/${"text/html"===ne.type?"html":"react"}?theme=${ie?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==te?void 0:te.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const o=e.target;setTimeout((()=>{var e;try{null===(e=o.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ne.type?"HTML_CODE":"REACT_CODE",content:ne.content},E)}catch(e){console.error("Error sending message to iframe:",e)}}),100),Z()}},{children:"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t(v,Object.assign({PreTag:"div",language:"text/markdown"===ne.type?"markdown":"text/html"===ne.type||"image/svg+xml"===ne.type?"xml":"application/vnd.pxe.react"===ne.type?"typescript":ne.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==te?void 0:te.secondaryText},ie&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==te?void 0:te.secondaryText},ie&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==te?void 0:te.secondary}),':not(pre) > code[class*="language-"]':{background:null==te?void 0:te.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==te?void 0:te.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ie&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==te?void 0:te.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:ne.content})),t(y,{})]}))})),"inline"===N.type&&!ae&&o("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t(F,Object.assign({id:`artifact-copy-${ne.id}-${ne.version}`,tip:(null==V?void 0:V.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(k,{color:te.secondaryText,text:ne.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t(F,Object.assign({id:`artifact-save-${ne.id}-${ne.version}`,tip:(null==V?void 0:V.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(O,Object.assign({data:ne,colors:te,onDownload:se,onSaveAsPDF:le,onSaveAsDOCX:ce},{children:t("button",Object.assign({style:{color:te.secondaryText}},{children:t(b,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};export{N as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{commonjsGlobal as t}from"../../../../../_virtual/_commonjsHelpers.js";import{__module as e}from"../../../../../_virtual/cose-base2.js";import{__require as r}from"../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js";var i;function o(){return i||(i=1,t=e,e.exports,o=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},t.exports=o(r())),e.exports;var t,o}e.exports;export{o as __require};
|
|
1
|
+
import{commonjsGlobal as t}from"../../../../../_virtual/_commonjsHelpers.js";import{__module as e}from"../../../../../_virtual/cose-base.js";import{__require as r}from"../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js";var i;function o(){return i||(i=1,t=e,e.exports,o=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},t.exports=o(r())),e.exports;var t,o}e.exports;export{o as __require};
|