@formulaxjs/kity-runtime 0.1.0 → 0.3.0

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.
Files changed (47) hide show
  1. package/README.md +3 -4
  2. package/dist/{chunk-EKIJQ64F.js → chunk-AOMNUFFB.js} +73 -19
  3. package/dist/chunk-AOMNUFFB.js.map +1 -0
  4. package/dist/index.cjs +389 -131
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.global.js +369 -160
  7. package/dist/index.global.js.map +1 -1
  8. package/dist/index.js +186 -54
  9. package/dist/index.js.map +1 -1
  10. package/dist/{install-ARHGHFNJ.js → install-TIZBWEFU.js} +62 -45
  11. package/dist/install-TIZBWEFU.js.map +1 -0
  12. package/dist/{start-GQH6XUBI.js → start-LTYA5XON.js} +2 -2
  13. package/package.json +9 -5
  14. package/public/assets/images/scrollbar/custom/bar-bg.png +0 -0
  15. package/public/assets/images/scrollbar/custom/bar.png +0 -0
  16. package/public/assets/images/scrollbar/custom/bg.png +0 -0
  17. package/public/assets/images/scrollbar/custom/bottom.png +0 -0
  18. package/public/assets/images/scrollbar/custom/btn.png +0 -0
  19. package/public/assets/images/scrollbar/custom/down.png +0 -0
  20. package/public/assets/images/scrollbar/custom/top.png +0 -0
  21. package/public/assets/images/scrollbar/custom/up.png +0 -0
  22. package/public/assets/images/scrollbar/edit/bar-bg.png +0 -0
  23. package/public/assets/images/scrollbar/edit/bar-left.png +0 -0
  24. package/public/assets/images/scrollbar/edit/bar-right.png +0 -0
  25. package/public/assets/images/scrollbar/edit/thumb-bg.png +0 -0
  26. package/public/assets/images/scrollbar/edit/thumb-left.png +0 -0
  27. package/public/assets/images/scrollbar/edit/thumb-right.png +0 -0
  28. package/public/assets/images/toolbar/btn.png +0 -0
  29. package/public/assets/images/toolbar/other.png +0 -0
  30. package/public/assets/styles/base.css +47 -0
  31. package/public/assets/styles/editor.css +3 -0
  32. package/public/assets/styles/page.css +12 -0
  33. package/public/assets/styles/scrollbar.css +78 -0
  34. package/public/assets/styles/ui.css +593 -0
  35. package/public/assets/theme/default/fui.css +540 -0
  36. package/public/assets/theme/default/images/close.png +0 -0
  37. package/public/assets/theme/default/images/down.png +0 -0
  38. package/public/assets/theme/default/images/open.png +0 -0
  39. package/public/assets/theme/default/images/up.png +0 -0
  40. package/public/resource/KF_AMS_BB.woff +0 -0
  41. package/public/resource/KF_AMS_CAL.woff +0 -0
  42. package/public/resource/KF_AMS_FRAK.woff +0 -0
  43. package/public/resource/KF_AMS_MAIN.woff +0 -0
  44. package/public/resource/KF_AMS_ROMAN.woff +0 -0
  45. package/dist/chunk-EKIJQ64F.js.map +0 -1
  46. package/dist/install-ARHGHFNJ.js.map +0 -1
  47. /package/dist/{start-GQH6XUBI.js.map → start-LTYA5XON.js.map} +0 -0
package/dist/index.js CHANGED
@@ -6,6 +6,10 @@ import {
6
6
  delegateEvent,
7
7
  getClassList,
8
8
  getRectBox,
9
+ kityAssetManifest,
10
+ kityFontAssets,
11
+ kityStyleAssets,
12
+ kityToolbarAssets,
9
13
  legacyBaseUtils,
10
14
  legacyBoxType,
11
15
  legacyEleType,
@@ -18,15 +22,13 @@ import {
18
22
  legacyOtherPosition,
19
23
  legacySysconf,
20
24
  legacyUiDef,
25
+ legacyUiUtils,
21
26
  normalizeMouseEvent,
22
27
  publish,
23
28
  setToolbarAssetUrls,
24
29
  subscribe,
25
30
  utils_default
26
- } from "./chunk-EKIJQ64F.js";
27
-
28
- // src/create-editor.ts
29
- import { kityAssetManifest } from "@formulaxjs/kity-assets";
31
+ } from "./chunk-AOMNUFFB.js";
30
32
 
31
33
  // src/vendor/char-position.ts
32
34
  var legacyCharPosition = {
@@ -3405,6 +3407,80 @@ function installKityRuntime(targetWindow = window) {
3405
3407
  targetWindow.kity = kity;
3406
3408
  }
3407
3409
 
3410
+ // src/perf.ts
3411
+ function getPerfHost() {
3412
+ return globalThis;
3413
+ }
3414
+ function getPerfState() {
3415
+ const host = getPerfHost();
3416
+ host.__FORMULAX_PERF_STATE__ ??= {
3417
+ reportedMeasureCount: 0,
3418
+ reportScheduled: false
3419
+ };
3420
+ return host.__FORMULAX_PERF_STATE__;
3421
+ }
3422
+ function hasPerfSupport() {
3423
+ return typeof performance !== "undefined" && typeof performance.mark === "function" && typeof performance.measure === "function" && typeof performance.getEntriesByType === "function";
3424
+ }
3425
+ function isPerfDebugEnabled() {
3426
+ return getPerfHost().__FORMULAX_PERF__ === true;
3427
+ }
3428
+ function schedulePerfReport() {
3429
+ if (!hasPerfSupport() || !isPerfDebugEnabled()) {
3430
+ return;
3431
+ }
3432
+ const state = getPerfState();
3433
+ if (state.reportScheduled) {
3434
+ return;
3435
+ }
3436
+ state.reportScheduled = true;
3437
+ queueMicrotask(() => {
3438
+ state.reportScheduled = false;
3439
+ const entries = performance.getEntriesByType("measure").filter((entry) => entry.name.startsWith("fx:")).sort((left, right) => left.startTime - right.startTime);
3440
+ const nextEntries = entries.slice(state.reportedMeasureCount);
3441
+ state.reportedMeasureCount = entries.length;
3442
+ if (!nextEntries.length) {
3443
+ return;
3444
+ }
3445
+ console.table(nextEntries.map((entry) => ({
3446
+ name: entry.name,
3447
+ duration: Number(entry.duration.toFixed(2)),
3448
+ startTime: Number(entry.startTime.toFixed(2))
3449
+ })));
3450
+ });
3451
+ }
3452
+ function markFormulaXPerf(name) {
3453
+ if (!hasPerfSupport()) {
3454
+ return null;
3455
+ }
3456
+ const markName = `${name}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
3457
+ performance.mark(markName);
3458
+ return markName;
3459
+ }
3460
+ function measureFormulaXPerf(name, startMark, endMark) {
3461
+ if (!hasPerfSupport() || !startMark) {
3462
+ return null;
3463
+ }
3464
+ const resolvedEndMark = endMark ?? markFormulaXPerf(`${name}:end`);
3465
+ if (!resolvedEndMark) {
3466
+ return null;
3467
+ }
3468
+ performance.measure(name, startMark, resolvedEndMark);
3469
+ schedulePerfReport();
3470
+ return resolvedEndMark;
3471
+ }
3472
+ function clearFormulaXPerfMarks(...marks) {
3473
+ if (!hasPerfSupport()) {
3474
+ return;
3475
+ }
3476
+ for (const mark of marks) {
3477
+ if (!mark) {
3478
+ continue;
3479
+ }
3480
+ performance.clearMarks(mark);
3481
+ }
3482
+ }
3483
+
3408
3484
  // src/create-editor.ts
3409
3485
  var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
3410
3486
  var DEFAULT_EDITOR_HEIGHT = "auto";
@@ -3444,13 +3520,14 @@ function resolveEditorAssets(assets) {
3444
3520
  }
3445
3521
  function ensureKityStylesheet(doc, href) {
3446
3522
  if (doc.getElementById(KITY_STYLE_ID)) {
3447
- return;
3523
+ return false;
3448
3524
  }
3449
3525
  const link = doc.createElement("link");
3450
3526
  link.id = KITY_STYLE_ID;
3451
3527
  link.rel = "stylesheet";
3452
3528
  link.href = href;
3453
3529
  doc.head.appendChild(link);
3530
+ return true;
3454
3531
  }
3455
3532
  function hydrateLegacyKf(runtimeWindow) {
3456
3533
  const requireFormula = runtimeWindow.__kityFormulaRequire__;
@@ -3498,7 +3575,7 @@ function installLegacyRuntime(runtimeWindow) {
3498
3575
  kity: runtimeWindow.kity,
3499
3576
  otherPosition: legacyOtherPosition,
3500
3577
  uiDef: legacyUiDef,
3501
- uiUtils: createLegacyUiUtils()
3578
+ uiUtils: legacyUiUtils
3502
3579
  };
3503
3580
  }
3504
3581
  async function ensureKityRuntime() {
@@ -3506,64 +3583,114 @@ async function ensureKityRuntime() {
3506
3583
  return runtimePromise;
3507
3584
  }
3508
3585
  runtimePromise = (async () => {
3586
+ const runtimeTotalStart = markFormulaXPerf("fx:kity-runtime:total");
3509
3587
  const runtimeWindow = window;
3510
3588
  runtimeWindow.kf = runtimeWindow.kf ?? {};
3511
3589
  installKityRuntime(runtimeWindow);
3512
- const { installLegacyKityFormulaRuntime } = await import("./install-ARHGHFNJ.js");
3513
- installLegacyKityFormulaRuntime(runtimeWindow);
3514
- hydrateLegacyKf(runtimeWindow);
3515
- const { installLegacyParserRuntime } = await import("./install-HKCG5NWK.js");
3516
- installLegacyParserRuntime(runtimeWindow);
3517
- installLegacyRuntime(runtimeWindow);
3518
- const { installKityEditorStart } = await import("./start-GQH6XUBI.js");
3519
- installKityEditorStart(runtimeWindow);
3590
+ try {
3591
+ const formulaImportStart = markFormulaXPerf("fx:kity-runtime:formula-import");
3592
+ const { installLegacyKityFormulaRuntime } = await import("./install-TIZBWEFU.js");
3593
+ const formulaImportEnd = markFormulaXPerf("fx:kity-runtime:formula-import:end");
3594
+ measureFormulaXPerf("fx:kity-runtime:formula-import", formulaImportStart, formulaImportEnd);
3595
+ clearFormulaXPerfMarks(formulaImportStart, formulaImportEnd);
3596
+ const formulaInstallStart = markFormulaXPerf("fx:kity-runtime:formula-install");
3597
+ installLegacyKityFormulaRuntime(runtimeWindow);
3598
+ hydrateLegacyKf(runtimeWindow);
3599
+ const formulaInstallEnd = markFormulaXPerf("fx:kity-runtime:formula-install:end");
3600
+ measureFormulaXPerf("fx:kity-runtime:formula-install", formulaInstallStart, formulaInstallEnd);
3601
+ clearFormulaXPerfMarks(formulaInstallStart, formulaInstallEnd);
3602
+ const parserImportStart = markFormulaXPerf("fx:kity-runtime:parser-import");
3603
+ const { installLegacyParserRuntime } = await import("./install-HKCG5NWK.js");
3604
+ const parserImportEnd = markFormulaXPerf("fx:kity-runtime:parser-import:end");
3605
+ measureFormulaXPerf("fx:kity-runtime:parser-import", parserImportStart, parserImportEnd);
3606
+ clearFormulaXPerfMarks(parserImportStart, parserImportEnd);
3607
+ const parserInstallStart = markFormulaXPerf("fx:kity-runtime:parser-install");
3608
+ installLegacyParserRuntime(runtimeWindow);
3609
+ const parserInstallEnd = markFormulaXPerf("fx:kity-runtime:parser-install:end");
3610
+ measureFormulaXPerf("fx:kity-runtime:parser-install", parserInstallStart, parserInstallEnd);
3611
+ clearFormulaXPerfMarks(parserInstallStart, parserInstallEnd);
3612
+ installLegacyRuntime(runtimeWindow);
3613
+ const bootImportStart = markFormulaXPerf("fx:kity-runtime:boot-import");
3614
+ const { installKityEditorStart } = await import("./start-LTYA5XON.js");
3615
+ const bootImportEnd = markFormulaXPerf("fx:kity-runtime:boot-import:end");
3616
+ measureFormulaXPerf("fx:kity-runtime:boot-import", bootImportStart, bootImportEnd);
3617
+ clearFormulaXPerfMarks(bootImportStart, bootImportEnd);
3618
+ const bootInstallStart = markFormulaXPerf("fx:kity-runtime:boot-install");
3619
+ installKityEditorStart(runtimeWindow);
3620
+ const bootInstallEnd = markFormulaXPerf("fx:kity-runtime:boot-install:end");
3621
+ measureFormulaXPerf("fx:kity-runtime:boot-install", bootInstallStart, bootInstallEnd);
3622
+ clearFormulaXPerfMarks(bootInstallStart, bootInstallEnd);
3623
+ } finally {
3624
+ const runtimeTotalEnd = markFormulaXPerf("fx:kity-runtime:total:end");
3625
+ measureFormulaXPerf("fx:kity-runtime:total", runtimeTotalStart, runtimeTotalEnd);
3626
+ clearFormulaXPerfMarks(runtimeTotalStart, runtimeTotalEnd);
3627
+ }
3520
3628
  })();
3521
3629
  return runtimePromise;
3522
3630
  }
3523
3631
  async function createKityEditor(container, options = {}) {
3632
+ const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
3524
3633
  const fontsize = options.render?.fontsize ?? 40;
3525
3634
  const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
3526
3635
  const assets = resolveEditorAssets(options.assets);
3527
- ensureKityStylesheet(document, assets.styles.editor);
3528
- setToolbarAssetUrls(assets.toolbar);
3529
- await ensureKityRuntime();
3530
- const runtimeWindow = window;
3531
- if (!runtimeWindow.kf?.EditorFactory) {
3532
- throw new Error("Kity editor runtime did not initialize");
3533
- }
3534
- container.innerHTML = "";
3535
- const host = document.createElement("div");
3536
- host.className = "kf-editor";
3537
- host.style.width = "100%";
3538
- host.style.height = editorHeight;
3539
- container.appendChild(host);
3540
- const factory = runtimeWindow.kf.EditorFactory.create(host, {
3541
- render: {
3542
- fontsize
3543
- },
3544
- resource: {
3545
- path: "",
3546
- fonts: assets.fonts
3547
- }
3548
- });
3549
- return {
3550
- ready: factory.ready.bind(factory),
3551
- execCommand(name, value) {
3552
- factory.ready(function execWhenReady() {
3553
- this.execCommand(name, value);
3554
- });
3555
- },
3556
- focus() {
3557
- factory.ready(function focusWhenReady() {
3558
- this.execCommand("focus");
3559
- });
3560
- },
3561
- destroy() {
3562
- container.innerHTML = "";
3563
- },
3564
- host,
3565
- raw: factory
3566
- };
3636
+ try {
3637
+ const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
3638
+ if (stylesheetInserted) {
3639
+ const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
3640
+ measureFormulaXPerf("fx:kity-css:link-inserted", createEditorStart, stylesheetInsertedMark);
3641
+ clearFormulaXPerfMarks(stylesheetInsertedMark);
3642
+ }
3643
+ setToolbarAssetUrls(assets.toolbar);
3644
+ await ensureKityRuntime();
3645
+ const runtimeReadyMark = markFormulaXPerf("fx:kity-runtime:ready-for-editor");
3646
+ measureFormulaXPerf("fx:kity-runtime:ready-for-editor", createEditorStart, runtimeReadyMark);
3647
+ clearFormulaXPerfMarks(runtimeReadyMark);
3648
+ const runtimeWindow = window;
3649
+ if (!runtimeWindow.kf?.EditorFactory) {
3650
+ throw new Error("Kity editor runtime did not initialize");
3651
+ }
3652
+ container.innerHTML = "";
3653
+ const host = document.createElement("div");
3654
+ host.className = "kf-editor";
3655
+ host.style.width = "100%";
3656
+ host.style.height = editorHeight;
3657
+ container.appendChild(host);
3658
+ const factoryCreateStart = markFormulaXPerf("fx:kity-editor-factory:create");
3659
+ const factory = runtimeWindow.kf.EditorFactory.create(host, {
3660
+ render: {
3661
+ fontsize
3662
+ },
3663
+ resource: {
3664
+ path: "",
3665
+ fonts: assets.fonts
3666
+ }
3667
+ });
3668
+ const factoryCreateEnd = markFormulaXPerf("fx:kity-editor-factory:create:end");
3669
+ measureFormulaXPerf("fx:kity-editor-factory:create", factoryCreateStart, factoryCreateEnd);
3670
+ clearFormulaXPerfMarks(factoryCreateStart, factoryCreateEnd);
3671
+ return {
3672
+ ready: factory.ready.bind(factory),
3673
+ execCommand(name, value) {
3674
+ factory.ready(function execWhenReady() {
3675
+ this.execCommand(name, value);
3676
+ });
3677
+ },
3678
+ focus() {
3679
+ factory.ready(function focusWhenReady() {
3680
+ this.execCommand("focus");
3681
+ });
3682
+ },
3683
+ destroy() {
3684
+ container.innerHTML = "";
3685
+ },
3686
+ host,
3687
+ raw: factory
3688
+ };
3689
+ } finally {
3690
+ const createEditorEnd = markFormulaXPerf("fx:create-kity-editor:total:end");
3691
+ measureFormulaXPerf("fx:create-kity-editor:total", createEditorStart, createEditorEnd);
3692
+ clearFormulaXPerfMarks(createEditorStart, createEditorEnd);
3693
+ }
3567
3694
  }
3568
3695
  async function mountKityEditor(container, options = {}) {
3569
3696
  const editor = await createKityEditor(container, options);
@@ -3632,6 +3759,10 @@ export {
3632
3759
  getClassList,
3633
3760
  getRectBox,
3634
3761
  installLegacyKityData,
3762
+ kityAssetManifest,
3763
+ kityFontAssets,
3764
+ kityStyleAssets,
3765
+ kityToolbarAssets,
3635
3766
  legacyBaseUtils,
3636
3767
  legacyBoxType,
3637
3768
  legacyCommonUtils,
@@ -3644,6 +3775,7 @@ export {
3644
3775
  legacyKfExtDef,
3645
3776
  legacySysconf,
3646
3777
  legacyUiDef,
3778
+ legacyUiUtils,
3647
3779
  mountKityEditor,
3648
3780
  normalizeMouseEvent,
3649
3781
  publish,