w-flowchart 1.0.1 → 1.0.2

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/src/p9/gen.mjs CHANGED
@@ -13,12 +13,19 @@ import { pkgScript, pkgText } from '../common/pkg.mjs'
13
13
  const __dir = dirname(fileURLToPath(import.meta.url))
14
14
  // React / ReactDOM / @xyflow/react(UMD)/ @dagrejs/dagre 由本機 node_modules 內聯注入(取代 esm.sh, 斷網環境可用)
15
15
  // replace 用函式形式回傳, 避免庫碼內 $ 序列被當作替換樣板
16
- const html = fs.readFileSync(`${__dir}/page9.html`, 'utf8')
17
- .replace('/*__XYFLOW_CSS__*/', () => pkgText('@xyflow/react/dist/style.css'))
18
- .replace('/*__REACT_JS__*/', () => pkgScript('react/umd/react.production.min.js'))
19
- .replace('/*__REACT_DOM_JS__*/', () => pkgScript('react-dom/umd/react-dom.production.min.js'))
20
- .replace('/*__XYFLOW_JS__*/', () => pkgScript('@xyflow/react/dist/umd/index.js'))
21
- .replace('/*__DAGRE_JS__*/', () => pkgScript('@dagrejs/dagre/dist/dagre.min.js'))
16
+ // 首次呼叫才讀檔組頁(延遲載入): 模組層即讀會令「僅用其他產線」的載入方也付出讀檔成本
17
+ let _html = null
18
+ function getHtml() {
19
+ if (_html === null) {
20
+ _html = fs.readFileSync(`${__dir}/page9.html`, 'utf8')
21
+ .replace('/*__XYFLOW_CSS__*/', () => pkgText('@xyflow/react/dist/style.css'))
22
+ .replace('/*__REACT_JS__*/', () => pkgScript('react/umd/react.production.min.js'))
23
+ .replace('/*__REACT_DOM_JS__*/', () => pkgScript('react-dom/umd/react-dom.production.min.js'))
24
+ .replace('/*__XYFLOW_JS__*/', () => pkgScript('@xyflow/react/dist/umd/index.js'))
25
+ .replace('/*__DAGRE_JS__*/', () => pkgScript('@dagrejs/dagre/dist/dagre.min.js'))
26
+ }
27
+ return _html
28
+ }
22
29
 
23
30
  // 正規化數據 → page9.html renderFig spec
24
31
  // 標籤「不預折」, 原樣傳入, 由 page9.html 量測 div(max-width + overflow-wrap)自然折行:
@@ -47,7 +54,7 @@ export async function genPng(data, opt = {}) {
47
54
  const errs = []
48
55
  page.on('pageerror', e => errs.push(e.message))
49
56
  page.on('console', m => { if (m.type() === 'error') errs.push('c:' + m.text().slice(0, 200)) })
50
- await page.setContent(html, { waitUntil: 'load' })
57
+ await page.setContent(getHtml(), { waitUntil: 'load' })
51
58
  await page.waitForFunction(() => document.title === 'READY' || document.title === 'FAIL', { timeout: 60000 }).catch(() => {})
52
59
  const boot = await page.evaluate(() => ({ t: document.title, err: window.__err }))
53
60
  if (boot.t !== 'READY') throw new Error('BOOT FAIL :: ' + boot.err + ' | ' + errs.slice(0, 6).join(' | '))