@x-cmd/draw 0.5.0 → 0.5.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/dist/client.d.ts +4 -2
- package/dist/client.js +23 -5
- package/dist/draw-client.iife.js +51 -0
- package/dist/draw-echarts.iife.js +1 -0
- package/dist/echarts-client.d.ts +34 -0
- package/dist/echarts-client.js +109 -0
- package/dist/render/echarts-ssr.d.ts +4 -0
- package/dist/render/echarts-ssr.js +3 -2
- package/dist/render/gantt.js +38 -32
- package/dist/render/gantt2.js +10 -7
- package/dist/render/globe-proj.d.ts +2 -1
- package/dist/render/hbar-spec.js +25 -15
- package/dist/render/svg.d.ts +10 -0
- package/dist/render/svg.js +12 -0
- package/package.json +8 -3
package/dist/client.d.ts
CHANGED
|
@@ -35,8 +35,10 @@ export declare function renderDiagramTo(el: Element, params: URLSearchParams | s
|
|
|
35
35
|
*
|
|
36
36
|
* 后加的元素也会被画上(MutationObserver)—— 报告是动态生成的时候用得上。
|
|
37
37
|
*/
|
|
38
|
-
export declare function autoRender(root?: ParentNode
|
|
39
|
-
|
|
38
|
+
export declare function autoRender(root?: ParentNode, opts?: {
|
|
39
|
+
lazy?: boolean;
|
|
40
|
+
}): number;
|
|
41
|
+
export { renderEarthGlobe, earthSceneFromUrl, type EarthScene, type EarthOpts, type EarthNode, type EarthLink, } from './render/globe-earth.js';
|
|
40
42
|
export { projectScene, DEFAULT_CAMERA, type Camera, type Scene } from './render/scene3d.js';
|
|
41
43
|
export { WORLD_COUNTRIES, WORLD_YEAR, type WorldCountry } from './world-data.js';
|
|
42
44
|
export { parseAbc, beatsOf, pitchInfo, type AbcTune } from './render/abc-parse.js';
|
package/dist/client.js
CHANGED
|
@@ -225,12 +225,13 @@ export function renderDiagramTo(el, params, base = 'https://draw.invalid/') {
|
|
|
225
225
|
*
|
|
226
226
|
* 后加的元素也会被画上(MutationObserver)—— 报告是动态生成的时候用得上。
|
|
227
227
|
*/
|
|
228
|
-
export function autoRender(root = typeof document !== 'undefined' ? document : undefined) {
|
|
228
|
+
export function autoRender(root = typeof document !== 'undefined' ? document : undefined, opts) {
|
|
229
229
|
if (typeof document === 'undefined')
|
|
230
230
|
return 0;
|
|
231
231
|
const scope = root ?? document;
|
|
232
|
+
const lazy = !!opts?.lazy;
|
|
232
233
|
let n = 0;
|
|
233
|
-
|
|
234
|
+
const draw = (el) => {
|
|
234
235
|
const src = el.getAttribute('data-draw');
|
|
235
236
|
if (!src || el.getAttribute('data-drawed') === '1')
|
|
236
237
|
return;
|
|
@@ -243,12 +244,29 @@ export function autoRender(root = typeof document !== 'undefined' ? document : u
|
|
|
243
244
|
// 画不出来就在元素上留一句说明,别让整页静默少一张图
|
|
244
245
|
el.textContent = `[draw] ${e instanceof Error ? e.message : String(e)}`;
|
|
245
246
|
}
|
|
246
|
-
}
|
|
247
|
+
};
|
|
248
|
+
const all = Array.from(scope.querySelectorAll('[data-draw]'));
|
|
249
|
+
if (!lazy || typeof IntersectionObserver === 'undefined') {
|
|
250
|
+
all.forEach(draw);
|
|
251
|
+
return n;
|
|
252
|
+
}
|
|
253
|
+
// 懒画:**进视口才画** —— 一页几十张图时一次画完会卡住主线程
|
|
254
|
+
const io = new IntersectionObserver((entries) => {
|
|
255
|
+
for (const e of entries) {
|
|
256
|
+
if (!e.isIntersecting)
|
|
257
|
+
continue;
|
|
258
|
+
draw(e.target);
|
|
259
|
+
io.unobserve(e.target);
|
|
260
|
+
}
|
|
261
|
+
}, { rootMargin: '200px' });
|
|
262
|
+
all.forEach((el) => { if (el.getAttribute('data-drawed') !== '1')
|
|
263
|
+
io.observe(el); });
|
|
247
264
|
return n;
|
|
248
265
|
}
|
|
249
266
|
/** 浏览器里自动跑一遍(引了脚本就出图,不用再调一次) */
|
|
250
267
|
if (typeof document !== 'undefined') {
|
|
251
|
-
|
|
268
|
+
// **懒画**是缺省:进视口才画 ⇒ 一页几十张图也不会卡住主线程
|
|
269
|
+
const boot = () => { autoRender(document, { lazy: true }); };
|
|
252
270
|
if (document.readyState === 'loading')
|
|
253
271
|
document.addEventListener('DOMContentLoaded', boot);
|
|
254
272
|
else
|
|
@@ -261,7 +279,7 @@ if (typeof document !== 'undefined') {
|
|
|
261
279
|
}
|
|
262
280
|
// 球面那几样(地球仪/三维架构图)浏览器端也要用 ⇒ 从这里一并导出,
|
|
263
281
|
// 免得宿主为了它们去引整个 source 入口(那一族要外部库,浏览器包扛不住)
|
|
264
|
-
export { renderEarthGlobe, earthSceneFromUrl } from './render/globe-earth.js';
|
|
282
|
+
export { renderEarthGlobe, earthSceneFromUrl, } from './render/globe-earth.js';
|
|
265
283
|
export { projectScene, DEFAULT_CAMERA } from './render/scene3d.js';
|
|
266
284
|
export { WORLD_COUNTRIES, WORLD_YEAR } from './world-data.js';
|
|
267
285
|
export { parseAbc, beatsOf, pitchInfo } from './render/abc-parse.js';
|