@gramlot/gramlot 0.3.37 → 0.3.39

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 (132) hide show
  1. package/dist/components/audio/__init__.py +1 -1
  2. package/dist/components/audio/assets/collection.js +4 -3
  3. package/dist/components/audio/assets/index.js +1 -1
  4. package/dist/components/charts/__init__.py +2 -2
  5. package/dist/components/charts/assets/collection.js +3 -28
  6. package/dist/components/charts/assets/index.js +1 -1
  7. package/dist/components/charts/assets/libraries/chunks/chunk-LVZ6SHV2.js +1 -0
  8. package/dist/components/charts/assets/{modules/echarts.esm.min-VHLRZDVQ.js → libraries/echarts.js} +1 -1
  9. package/dist/components/charts/assets/{modules/plotly.min-SSDU2DOH.js → libraries/plotly.js} +1 -1
  10. package/dist/components/charts/assets/{modules/uPlot.esm-Q2UYUQHJ.js → libraries/uplot.js} +1 -1
  11. package/dist/components/charts/assets/libraries/uplotStyle.js +1 -0
  12. package/dist/components/charts/assets/{modules/vega.module-Y5CWNSZO.js → libraries/vega.js} +1 -1
  13. package/dist/components/chat/__init__.py +1 -1
  14. package/dist/components/chat/assets/collection.js +4 -9
  15. package/dist/components/chat/assets/index.js +1 -1
  16. package/dist/components/drawing/__init__.py +1 -1
  17. package/dist/components/drawing/assets/collection.js +4 -7
  18. package/dist/components/drawing/assets/index.js +1 -1
  19. package/dist/components/drawing/grammar.json +75 -0
  20. package/dist/components/editors/__init__.py +2 -2
  21. package/dist/components/editors/assets/collection.js +9 -7
  22. package/dist/components/editors/assets/index.js +1 -1
  23. package/dist/components/editors/assets/libraries/chunks/chunk-4TTZUUSG.js +1 -0
  24. package/dist/components/editors/assets/libraries/chunks/chunk-QRHUDCCH.js +1 -0
  25. package/dist/components/editors/assets/libraries/chunks/chunk-XGS3SDSL.js +1 -0
  26. package/dist/components/editors/assets/{modules/code-mirror-engine-RWQTR5G5.js → libraries/codemirror.js} +2 -2
  27. package/dist/components/editors/assets/{modules/jodit-engine-CXRSFV47.js → libraries/jodit.js} +292 -292
  28. package/dist/components/editors/assets/libraries/markdownIt.js +1 -0
  29. package/dist/components/editors/assets/{modules/prose-mirror-engine-DQEAEIMV.js → libraries/prosemirror.js} +1 -1
  30. package/dist/components/editors/assets/{modules/xterm-UBEXZEYY.js → libraries/xterm.js} +1 -1
  31. package/dist/components/editors/assets/{modules/addon-fit-L6JK4OJX.js → libraries/xtermFit.js} +1 -1
  32. package/dist/components/editors/assets/{modules/xterm-BF3OSWRI.js → libraries/xtermStyle.js} +1 -1
  33. package/dist/components/grid/__init__.py +2 -2
  34. package/dist/components/grid/assets/collection.js +4 -286
  35. package/dist/components/grid/assets/index.js +1 -1
  36. package/dist/components/grid/assets/{modules/browser-Y2BRNI3P.js → libraries/writeExcelFile.js} +1 -1
  37. package/dist/components/grouplets/__init__.py +2 -2
  38. package/dist/components/grouplets/assets/collection.js +5 -185
  39. package/dist/components/grouplets/assets/index.js +1 -1
  40. package/dist/components/grouplets/assets/libraries/markdownIt.js +1 -0
  41. package/dist/components/inputs/__init__.py +1 -1
  42. package/dist/components/inputs/assets/collection.js +22 -65
  43. package/dist/components/inputs/assets/index.js +1 -1
  44. package/dist/components/layout/__init__.py +1 -1
  45. package/dist/components/layout/assets/collection.js +14 -218
  46. package/dist/components/layout/assets/index.js +1 -1
  47. package/dist/components/layout/grammar.json +146 -1
  48. package/dist/components/selection_trial/__init__.py +1 -1
  49. package/dist/components/selection_trial/assets/collection.js +2 -4
  50. package/dist/components/selection_trial/assets/index.js +1 -1
  51. package/dist/components/tree/__init__.py +1 -1
  52. package/dist/components/tree/assets/collection.js +5 -31
  53. package/dist/components/tree/assets/index.js +1 -1
  54. package/dist/components/typst/__init__.py +2 -2
  55. package/dist/components/typst/assets/collection.js +3 -3
  56. package/dist/components/typst/assets/index.js +1 -1
  57. package/dist/components/typst/assets/libraries/typst.js +4 -0
  58. package/dist/components/uploads/__init__.py +1 -1
  59. package/dist/components/uploads/assets/collection.js +6 -40
  60. package/dist/components/uploads/assets/index.js +1 -1
  61. package/dist/components/uploads/grammar.json +15 -0
  62. package/dist/declared-collections.js +1 -1
  63. package/dist/gramlot.js +23518 -5533
  64. package/dist/gramlot.min.js +915 -50
  65. package/dist/libraries.json +10 -1
  66. package/dist/standard-collections.js +1 -1
  67. package/dist/standard-grammar.js +3 -0
  68. package/package.json +3 -2
  69. package/src/bootstrap.js +6 -0
  70. package/src/build-plugins.d.ts +9 -0
  71. package/src/build-plugins.js +59 -0
  72. package/src/bundled-collections.js +25 -0
  73. package/src/components/attachment-manager.js +1 -1
  74. package/src/components/border-container.js +1 -1
  75. package/src/components/chart-fields.js +1 -1
  76. package/src/components/chart-pane.js +2 -1
  77. package/src/components/chart-renderer.js +1 -1
  78. package/src/components/chart-type-data.js +1 -1
  79. package/src/components/charts.js +1 -1
  80. package/src/components/chat.js +1 -1
  81. package/src/components/check-box-text.js +1 -1
  82. package/src/components/check-box-tree.js +1 -1
  83. package/src/components/choice-editor.js +1 -1
  84. package/src/components/database-choices.js +1 -1
  85. package/src/components/drawing.js +10 -4
  86. package/src/components/editing-status.js +1 -1
  87. package/src/components/grid-cell-editor.js +3 -1
  88. package/src/components/grid-column-filters.js +2 -1
  89. package/src/components/grid-selection.js +1 -1
  90. package/src/components/grid-structure.js +1 -1
  91. package/src/components/grid-tools.js +1 -1
  92. package/src/components/grid.js +1 -1
  93. package/src/components/grouplet-card.js +2 -1
  94. package/src/components/html-preview.js +2 -1
  95. package/src/components/image-crop-dialog.js +44 -4
  96. package/src/components/image-rectangle-selection.js +128 -0
  97. package/src/components/image-uploader.js +2 -1
  98. package/src/components/index.js +1 -0
  99. package/src/components/jodit-engine.js +1 -1
  100. package/src/components/markdown-document.js +1 -1
  101. package/src/components/tray-geometry.js +35 -0
  102. package/src/components/tray-pane.js +50 -7
  103. package/src/components/tree.js +2 -1
  104. package/src/components/upload-engine.js +1 -1
  105. package/src/components/uploader.js +1 -1
  106. package/src/components/validation.js +1 -1
  107. package/src/components/window-surface.js +122 -18
  108. package/src/components/windows.js +3 -2
  109. package/src/experiments/selection-transfer.js +2 -1
  110. package/src/experiments/selection-trial.js +1 -1
  111. package/src/experiments/window-selection.js +1 -1
  112. package/src/handlers/source-handler.d.ts +3 -0
  113. package/src/handlers/source-handler.js +18 -1
  114. package/src/index.d.ts +5 -0
  115. package/src/index.js +4 -0
  116. package/src/libraries.js +4 -1
  117. package/src/server/gramlot-server.d.ts +4 -0
  118. package/src/server/gramlot-server.js +16 -1
  119. package/src/shared-modules.js +28 -1
  120. package/src/view/html.js +8 -1
  121. package/dist/components/charts/assets/modules/chunk-USZCUBTC.js +0 -1
  122. package/dist/components/charts/assets/modules/uPlot.min-XXHNQFXH.js +0 -1
  123. package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +0 -1
  124. package/dist/components/editors/assets/modules/chunk-AU4HFPIY.js +0 -1
  125. package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +0 -1
  126. package/dist/components/grid/assets/modules/chunk-BLMUM44K.js +0 -1
  127. package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +0 -1
  128. package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +0 -1
  129. package/dist/components/typst/assets/modules/chunk-BLMUM44K.js +0 -1
  130. package/dist/components/typst/assets/modules/typst-client-JHC6UVYG.js +0 -4
  131. /package/dist/components/charts/assets/{modules/echarts-gl.min-N6L67H2M.js → libraries/echartsGl.js} +0 -0
  132. /package/dist/components/editors/assets/{modules/chunk-YSGSC7KM.js → libraries/chunks/chunk-TSYAHRZC.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.3.37",
3
+ "version": "0.3.39",
4
4
  "description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "@codemirror/lang-sql": "^6.10.0",
28
28
  "@codemirror/lang-xml": "^6.1.0",
29
29
  "@codemirror/language": "^6.13.1",
30
- "@codemirror/lint": "^6.9.7",
30
+ "@codemirror/lint": "^6.9.8",
31
31
  "@codemirror/search": "^6.7.2",
32
32
  "@codemirror/state": "^6.7.6",
33
33
  "@codemirror/view": "^6.43.15",
@@ -69,6 +69,7 @@
69
69
  ".": "./src/index.js",
70
70
  "./server": "./src/server/index.js",
71
71
  "./runtime": "./dist/gramlot.js",
72
+ "./build-plugins": "./src/build-plugins.js",
72
73
  "./markdown": "./src/markdown.js",
73
74
  "./page": "./src/server/page.js",
74
75
  "./gramlot-server": "./src/server/gramlot-server.js",
package/src/bootstrap.js CHANGED
@@ -7,12 +7,15 @@
7
7
  import {Gramlot} from './gramlot.js';
8
8
  import {LogicRegistry} from './binding/logic.js';
9
9
  import {ServerAdapter} from './server-adapter.js';
10
+ import {bundledCollections} from './bundled-collections.js';
10
11
 
11
12
  /**
12
13
  * The browser start of one page (source plan §4.12). The server writes
13
14
  * `await new PageBootstrap({config, resources}).run()` into the bootstrap HTML;
14
15
  * `resources` is `{css: [url], js: [{url, group}]}`, already in load order and
15
16
  * with the mount prefix, with `collections` and `serverAdapter` when the server has them.
17
+ * A collection record of the runtime bundle (`bundledCollections`) is not imported; any other collection is
18
+ * imported before the page starts.
16
19
  */
17
20
  export class PageBootstrap {
18
21
  constructor({config, resources, document = globalThis.document}) {
@@ -62,6 +65,7 @@ export class PageBootstrap {
62
65
  } catch(error) { throw new Error(`${url}: import failed: ${error.message}`, {cause:error}); }
63
66
  });
64
67
  const names = new Set();
68
+ const bundled = new Map(bundledCollections.map(collection => [collection.name, collection]));
65
69
  const collectionImports = (resources.collections ?? []).map(async record => {
66
70
  if (!record || typeof record !== 'object' || Object.keys(record).sort().join(',') !== 'buildId,name,url' ||
67
71
  typeof record.name !== 'string' || typeof record.url !== 'string' ||
@@ -70,6 +74,8 @@ export class PageBootstrap {
70
74
  }
71
75
  names.add(record.name);
72
76
  const {name,url,buildId} = record;
77
+ // The runtime carries this collection: its artifact reads it from the runtime.
78
+ if (bundled.has(name)) return bundled.get(name);
73
79
  let module;
74
80
  try { module = await import(new URL(url, document.baseURI).href); }
75
81
  catch(error) { throw new Error(`${name}: collection import failed: ${error.message}`, {cause:error}); }
@@ -0,0 +1,9 @@
1
+ /** An esbuild plugin: name and setup, as esbuild declares `Plugin`. */
2
+ export interface BuildPlugin {
3
+ readonly name: string;
4
+ setup(build: unknown): void;
5
+ }
6
+ /** Replaces big.js and @xmldom/xmldom with modules whose classes throw when constructed. */
7
+ export const absentPackagePlugin: BuildPlugin;
8
+ /** Makes the dynamic import of a third-party library of a component external as `@gramlot/libraries/<name>`. */
9
+ export const libraryPlugin: BuildPlugin;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * esbuild plugins of the browser runtime build (`scripts/runtime-options.mjs`), exported as
3
+ * `@gramlot/gramlot/build-plugins` for a host that bundles the core sources for the browser, such as
4
+ * gramlot-serverless: the bundle then keeps the third-party libraries of components out, as the runtime
5
+ * does, and replaces the packages the browser runtime does not ship. Node only.
6
+ */
7
+ import {fileURLToPath} from 'node:url';
8
+ import {libraries} from './libraries.js';
9
+
10
+ /**
11
+ * Packages that `@genrojs/bag` and `@genrojs/tytx` import and the browser runtime does not ship
12
+ * (gramlot-org/gramlot#84). `@genrojs/tytx` imports big.js beside decimal.js and selects decimal.js,
13
+ * the `Decimal` of Gramlot. Both libraries parse XML with the native `DOMParser` of the window and use
14
+ * @xmldom/xmldom only where no `DOMParser` exists: Node and the serverless Web Worker, which bundle the
15
+ * core sources and keep both packages. The browser runtime replaces each package with a module whose
16
+ * classes throw when constructed.
17
+ */
18
+ const absentPackages = {
19
+ 'big.js': "export default class Big { constructor() { throw new Error('The Gramlot browser runtime has no big.js: decimals use decimal.js'); } }",
20
+ '@xmldom/xmldom': "const absent = () => { throw new Error('The Gramlot browser runtime has no @xmldom/xmldom: XML uses the native DOMParser'); };\n" +
21
+ 'export class DOMParser { constructor() { absent(); } }\nexport class XMLSerializer { constructor() { absent(); } }',
22
+ };
23
+
24
+ const srcDirectory = fileURLToPath(new URL('.', import.meta.url)).replace(/\/$/, '');
25
+
26
+ export const absentPackagePlugin = {
27
+ name: 'absent-package',
28
+ setup(build) {
29
+ const filter = new RegExp(`^(${Object.keys(absentPackages).map(name => name.replace(/[./]/g, '\\$&')).join('|')})$`);
30
+ build.onResolve({filter}, args => ({path: args.path, namespace: 'absent-package'}));
31
+ build.onLoad({filter: /.*/, namespace: 'absent-package'}, args => ({contents: absentPackages[args.path], loader: 'js'}));
32
+ },
33
+ };
34
+
35
+ /**
36
+ * The import of a third-party library on first use in the collections the runtime carries
37
+ * (`bundledCollections`): `loadLibrary` imports `@gramlot/libraries/<name>`, which the import map of the
38
+ * bootstrap resolves to the module of the library in the artifact of its collection (GC-325 §160). The
39
+ * runtime bundle holds no third-party library of a component.
40
+ */
41
+ export const libraryPlugin = {
42
+ name: 'library-module',
43
+ setup(build) {
44
+ let files = null;
45
+ build.onResolve({filter: /.*/}, async args => {
46
+ if (args.kind !== 'dynamic-import' || args.pluginData?.library) return undefined;
47
+ files ??= Promise.all(Object.entries(libraries).map(async ([name, library]) => {
48
+ const resolved = await build.resolve(library.local, {kind: 'dynamic-import', resolveDir: srcDirectory,
49
+ importer: srcDirectory + '/libraries.js', pluginData: {library: true}});
50
+ if (resolved.errors.length) throw new Error(`Library ${name}: cannot resolve ${library.local}`);
51
+ return [resolved.path, name];
52
+ })).then(entries => new Map(entries));
53
+ const target = await build.resolve(args.path, {kind: args.kind, importer: args.importer,
54
+ resolveDir: args.resolveDir, pluginData: {library: true}});
55
+ const name = (await files).get(target.path);
56
+ return name === undefined ? undefined : {path: `@gramlot/libraries/${name}`, external: true};
57
+ });
58
+ },
59
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The standard collections, carried by the runtime bundle (owner direction, gramlot-org/gramlot#82).
3
+ *
4
+ * A page loads the runtime file and no file of a standard collection. The bundle holds no third-party
5
+ * package: a library a component needs (ECharts, Plotly, Vega, uPlot, CodeMirror, Jodit, ProseMirror,
6
+ * xterm, write-excel-file, markdown-it) loads on first use through `loadLibrary` from the module
7
+ * `@gramlot/libraries/<name>` (GC-325 §160). The prepared artifact of a bundled collection reads the
8
+ * collection from the runtime (`sharedModules`), so a page holds one copy of it.
9
+ *
10
+ * @module
11
+ */
12
+ import inputs from './components/inputs.js';
13
+ import layout from './components/layout.js';
14
+ import tree from './components/tree.js';
15
+ import grid from './components/grid.js';
16
+ import editors from './components/editors.js';
17
+ import grouplets from './components/grouplets.js';
18
+ import chat from './components/chat.js';
19
+ import charts from './components/charts.js';
20
+ import audio from './components/audio.js';
21
+ import drawing from './components/drawing.js';
22
+ import uploads from './components/uploads.js';
23
+
24
+ export const bundledCollections = Object.freeze([inputs, layout, tree, grid, editors, grouplets, chat, charts, audio, drawing,
25
+ uploads]);
@@ -1,5 +1,5 @@
1
1
  /** Application-owned attachment operations, composed with the shared upload queue. */
2
- import {Bag} from '@gramlot/gramlot';
2
+ import {Bag} from '@genrojs/bag';
3
3
  import {toTytx} from '@genrojs/tytx';
4
4
  import {defineComponent} from './registry.js';
5
5
  import {Container} from './container.js';
@@ -3,7 +3,7 @@ import {defineComponent} from './registry.js';
3
3
  import {Container} from './container.js';
4
4
  import {WindowSurface} from './window-surface.js';
5
5
  import {SVG_NS} from '../renderer/attributes.js';
6
- import {createDOMPurify} from '@gramlot/gramlot';
6
+ import createDOMPurify from 'dompurify';
7
7
 
8
8
  const SIDES = ['top', 'bottom', 'left', 'right'];
9
9
  const REGIONS = [...SIDES, 'center'];
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {defineComponent} from '@gramlot/gramlot/components';
3
3
  import {randomId} from '../random-id.js';
4
4
  import {Container} from './container.js';
@@ -1,4 +1,5 @@
1
- import {Bag,fromTytx,toTytx} from '@gramlot/gramlot';
1
+ import {fromTytx, toTytx} from '@genrojs/tytx';
2
+ import {Bag} from '@genrojs/bag';
2
3
  import {defineComponent} from './registry.js';
3
4
  import {Container} from './container.js';
4
5
  import {randomId} from '../random-id.js';
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {chartType} from './chart-types/index.js';
3
3
  import {requireChartCapability} from './chart-engines/index.js';
4
4
  import {checkChartSyntax} from './chart-syntax.js';
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
 
3
3
  /** Cell and caption reading shared by the funnel, radar, parallel, heatmap, sankey, candlestick, boxplot, treemap and sunburst builders. */
4
4
 
@@ -1,7 +1,7 @@
1
1
  import {ChartTimeView,timeLabel} from './chart-time.js';
2
2
  import {ChartTimeline} from './chart-timeline.js';
3
3
  import {ChartPane} from './chart-pane.js';
4
- import {Bag} from '@gramlot/gramlot';
4
+ import {Bag} from '@genrojs/bag';
5
5
  import {collectionKey} from '../stores/bag-collection-store.js';
6
6
  import {defineCollection, defineComponent} from '@gramlot/gramlot/components';
7
7
  import {Container} from './container.js';
@@ -9,7 +9,7 @@ export const ChatMessages = defineComponent({
9
9
  super();
10
10
  const style = this.ownerDocument.createElement('style');
11
11
  style.textContent = `:host{height:100%;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
12
- .control-box{padding:20px max(20px,calc((100% - 880px)/2))}
12
+ .control-box{padding:var(--gramlot-chat-padding,20px max(20px,calc((100% - 880px)/2)))}
13
13
  ::slotted(article){box-sizing:border-box;margin:0 0 24px;padding:16px 20px;border-radius:18px;
14
14
  line-height:1.6;overflow-wrap:anywhere;background:var(--gramlot-chat-assistant-background,
15
15
  color-mix(in srgb,var(--gramlot-surface-subtle,#eee) 88%,#628099))}
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {parseChoices} from './choices.js';
3
3
  import {positionPopup} from './popup.js';
4
4
  import {CheckBoxTree} from './check-box-tree.js';
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
 
3
3
  /** Identity/caption projection only. The shared tree owns checks and lazy propagation. */
4
4
  export class CheckBoxTree {
@@ -2,7 +2,7 @@ import {NativeControl} from './bases.js';
2
2
  import {parseChoices} from './choices.js';
3
3
  import {choiceFieldStyles} from './choice-field-styles.js';
4
4
  import {positionPopup} from './popup.js';
5
- import {Bag} from '@gramlot/gramlot';
5
+ import {Bag} from '@genrojs/bag';
6
6
 
7
7
  /** Shared suggestions: constrained controls commit codes; comboBox commits text. */
8
8
  export function ChoiceEditor(HTMLElement) {
@@ -1,4 +1,4 @@
1
- import {createDOMPurify} from '@gramlot/gramlot';
1
+ import createDOMPurify from 'dompurify';
2
2
 
3
3
  /** Database suggestions share the choice editor and the ordinary data RPC. */
4
4
  export const databaseParameters = {
@@ -1,4 +1,5 @@
1
- import {Bag, sourceTarget} from '@gramlot/gramlot';
1
+ import {sourceTarget} from '@genrojs/builders';
2
+ import {Bag} from '@genrojs/bag';
2
3
  import inputs from './inputs.js';
3
4
  import layout from './layout.js';
4
5
  import {defineCollection, defineComponent} from './registry.js';
@@ -11,7 +12,9 @@ import {SVG_NS} from '../renderer/attributes.js';
11
12
  export const DrawingPane = defineComponent({
12
13
  name:'drawingPane', tag:'gramlot-drawing-pane', base:Container, sourceContext:true, subTags:'*',
13
14
  parameters:{image:{dtype:'T',nullable:true,default:null,binding:'read'},
14
- annotations:{dtype:'X',binding:'read'}},
15
+ annotations:{dtype:'X',binding:'read'},
16
+ // Without an image: the surface ratio (width/height) of a 1000 units high surface; toolbar=false omits the tool menu.
17
+ aspectRatio:{dtype:'R',nullable:true,default:null,binding:'read'},toolbar:{dtype:'B',default:true,binding:'read'}},
15
18
  implementation:Base => class extends Base {
16
19
  // The annotations are read at the address of the `annotations` pointer at each use; the
17
20
  // tool state lives in the node's private Data area and is observed through a router registration.
@@ -23,7 +26,7 @@ export const DrawingPane = defineComponent({
23
26
  const style=d.createElement('style');
24
27
  style.textContent=`:host{display:block;height:100%;min-height:0}.control-box{height:100%;display:flex;flex-direction:row;min-height:0;position:relative}
25
28
  slot{display:contents} ::slotted(gramlot-menu){flex:0 0 56px;box-sizing:border-box;padding:6px;background:var(--gramlot-surface,Canvas);border-right:1px solid var(--gramlot-border-control,#a8b2bf);overflow:hidden}
26
- .canvas{display:block;flex:1;width:0;height:100%;min-width:0;min-height:0;background:var(--gramlot-surface-subtle,#eee);touch-action:none;user-select:none}
29
+ .canvas{display:block;flex:1;width:0;height:100%;min-width:0;min-height:0;background:var(--gramlot-drawing-background,var(--gramlot-surface-subtle,#eee));touch-action:none;user-select:none}
27
30
  .text-editor{position:absolute;z-index:2;min-width:120px;padding:2px 4px;border:1px solid #3977bc;border-radius:3px;background:white;color:#222;box-shadow:0 2px 8px #0003}
28
31
  .text-editor[hidden]{display:none}.shape{cursor:pointer}.selected{stroke:#1683ff}.selected [data-text-hit]{stroke:#3977bc;stroke-width:1;stroke-dasharray:4 3}`;
29
32
  this.shadowRoot.append(style);this.control.replaceChildren();
@@ -75,7 +78,7 @@ export const DrawingPane = defineComponent({
75
78
  const url=this.parameters.image;
76
79
  if(url!==this.#url){
77
80
  this.#url=url;this.#gesture=null;
78
- if(!url){this.#dimensions=[1000,1000];this.#render();}
81
+ if(!url){this.#dimensions=this.#surface();this.#render();}
79
82
  else {
80
83
  this.#dimensions=null;this.#render();
81
84
  this.#image.onload=()=>{if(this.#url!==url)return;this.#dimensions=[this.#image.naturalWidth,this.#image.naturalHeight];this.#render();};
@@ -83,8 +86,10 @@ export const DrawingPane = defineComponent({
83
86
  this.#image.src=url;
84
87
  }
85
88
  }
89
+ else if(!url)this.#dimensions=this.#surface();
86
90
  this.#render();
87
91
  }
92
+ #surface(){const ratio=this.parameters.aspectRatio;return ratio>0?[1000*ratio,1000]:[1000,1000];}
88
93
  #makeToolbar(){
89
94
  if(this.#built)return;
90
95
  const node=this.context.sourceNode,builder=node.rootBuilder;
@@ -94,6 +99,7 @@ export const DrawingPane = defineComponent({
94
99
  if(!(this.#state('tool')&&this.#state('color')&&this.#state('size')))
95
100
  node.data.setItem(this.#statePath,new Bag({tool:'select',color:'#dd2222',size:3}));
96
101
  this.#tool=this.#state('tool');this.#lastColor=this.#state('color');this.#lastSize=this.#state('size');
102
+ if(this.parameters.toolbar===false){this.#built=true;return;}
97
103
  const fragment=new builder.source.constructor(null,builder),root=builder.wrapSource(fragment);
98
104
  const bar=root.menu({node_label:'bar',presentation:'bar',orientation:'vertical',labelPosition:'tooltip',iconSize:20,aria_label:'Image annotations'});
99
105
  sourceTarget(bar)._internal.drawingController=this;
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {defineComponent} from './registry.js';
3
3
  import {Container} from './container.js';
4
4
  import {SVG_NS} from '../renderer/attributes.js';
@@ -1,4 +1,6 @@
1
- import {Bag, sourceTarget, toTytx} from '@gramlot/gramlot';
1
+ import {toTytx} from '@genrojs/tytx';
2
+ import {sourceTarget} from '@genrojs/builders';
3
+ import {Bag} from '@genrojs/bag';
2
4
  import {pointerTransform} from '@genrojs/builders';
3
5
 
4
6
  /**
@@ -1,4 +1,5 @@
1
- import {Bag, sourceTarget} from '@gramlot/gramlot';
1
+ import {sourceTarget} from '@genrojs/builders';
2
+ import {Bag} from '@genrojs/bag';
2
3
  import {positionPopup} from './popup.js';
3
4
  import {cellText} from './grid-rows.js';
4
5
  import {SVG_NS} from '../renderer/attributes.js';
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
 
3
3
  export const SELECTION_MODES = Object.freeze(['none', 'single', 'multi']);
4
4
 
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {formulaDefinitions} from './grid-formulas.js';
3
3
 
4
4
  const TYPES = new Set(['T', 'B', 'L', 'R', 'N', 'D', 'H', 'DHZ']);
@@ -1,4 +1,4 @@
1
- import {Bag} from '@gramlot/gramlot';
1
+ import {Bag} from '@genrojs/bag';
2
2
  import {loadLibrary} from '../libraries.js';
3
3
  import {isDecimal} from '@genrojs/tytx';
4
4
  import {GridRows} from './grid-rows.js';
@@ -1,5 +1,5 @@
1
1
  import {GridColumnFilters} from './grid-column-filters.js';
2
- import {Bag} from '@gramlot/gramlot';
2
+ import {Bag} from '@genrojs/bag';
3
3
  import {SVG_NS} from '../renderer/attributes.js';
4
4
  import {defineComponent, ComponentCollection} from './registry.js';
5
5
  import {Container} from './container.js';
@@ -3,6 +3,7 @@ import {defineComponent} from './registry.js';
3
3
  import {Container} from './container.js';
4
4
  import {labelboxContent} from '../view/labelbox.js';
5
5
  import {positionPopup} from './popup.js';
6
+ import {loadLibrary} from '../libraries.js';
6
7
 
7
8
  export const GroupletCard = defineComponent({
8
9
  name: 'groupletCard', tag: 'gramlot-grouplet-card', base: Container,
@@ -360,7 +361,7 @@ export const GroupletCard = defineComponent({
360
361
  this.docButton.setAttribute('aria-label', `Guide for ${this.parameters.title || 'card'}`);
361
362
  this.docTitle.textContent = this.parameters.title || 'Card guide';
362
363
  if (this.#docEvents && !this.#markdown && !this.docReady) {
363
- this.docReady = import('./markdown-document.js').then(module => {
364
+ this.docReady = loadLibrary('markdownIt', this.ownerDocument, () => import('./markdown-document.js')).then(module => {
364
365
  this.#markdown = module.markdownRenderer;
365
366
  if (this.isConnected && this.#docEvents) this.refreshDoc();
366
367
  });
@@ -1,5 +1,6 @@
1
1
  import {defineComponent} from './registry.js';
2
2
  import {projectParameters} from './parameters.js';
3
+ import {loadLibrary} from '../libraries.js';
3
4
 
4
5
  function PreviewElement(HTMLElement) {
5
6
  return class extends HTMLElement {
@@ -36,7 +37,7 @@ export const MarkdownPreview=defineComponent({name:'markdownPreview',tag:'gramlo
36
37
  render() {
37
38
  if (this.#renderDocument) {super.render();return;}
38
39
  if (this.ready) return;
39
- this.ready=import('./markdown-document.js').then(module=>{
40
+ this.ready=loadLibrary('markdownIt',this.ownerDocument,()=>import('./markdown-document.js')).then(module=>{
40
41
  this.#renderDocument=module.renderMarkdownDocument;
41
42
  if(this.isConnected) this.render();
42
43
  });
@@ -1,9 +1,14 @@
1
- /** Private, reusable framing dialog. It returns a Blob and never replaces the source. */
1
+ /**
2
+ * Private, reusable framing dialog. It returns a Blob and never replaces the source. The Crop control switches to
3
+ * a rectangle selection on the whole image (ImageRectangleSelection); Apply frames the selected area and returns
4
+ * to the frame, rotation 0.
5
+ */
2
6
  import {ImageCropSession} from './image-crop.js';
7
+ import {ImageRectangleSelection, RECTANGLE_SELECTION_STYLE} from './image-rectangle-selection.js';
3
8
 
4
9
  export class ImageCropDialog {
5
10
  #document; #image; #session; #options; #dialog; #frameImage; #minZoom; #maxZoom;
6
- #resolve; #settled = false; #events; #frame; #points = new Map(); #gesture; #trackpadGesture;
11
+ #resolve; #settled = false; #events; #frame; #points = new Map(); #gesture; #trackpadGesture; #selection = null;
7
12
  constructor({data, path, document, original, image, sourceWidth, sourceHeight, width, height,
8
13
  x = 0, y = 0, zoom = 1, rotate = 0, outputWidth, outputHeight, type, quality}) {
9
14
  this.#document = document;
@@ -49,6 +54,11 @@ export class ImageCropDialog {
49
54
  .gramlot-image-crop-dialog button.primary{background:var(--gramlot-action,#3766b5);border-color:var(--gramlot-action,#3766b5);color:#fff}
50
55
  .gramlot-image-crop-dialog button:disabled{opacity:.55;cursor:default}
51
56
  .gramlot-image-crop-dialog [role=alert]:not(:empty){color:var(--gramlot-error,#ae2020);margin-top:.75rem}
57
+ .gramlot-image-crop-dialog.cropping{width:min(100vw - 2rem, 760px)}
58
+ .gramlot-image-crop-dialog [hidden]{display:none}
59
+ .gramlot-image-crop-dialog .crop-rectangle-view{height:min(60vh, 460px);padding:0 24px}
60
+ .gramlot-image-crop-dialog .crop-crop-handle{cursor:pointer;font-size:18px}
61
+ ${RECTANGLE_SELECTION_STYLE}
52
62
  @media(max-width:380px){.gramlot-image-crop-dialog{width:calc(100vw - 8px);max-width:calc(100vw - 8px)}
53
63
  .gramlot-image-crop-dialog .crop-heading,.gramlot-image-crop-dialog .crop-body{padding-left:8px;padding-right:8px}
54
64
  .gramlot-image-crop-dialog .crop-actions{padding:12px 8px}}
@@ -75,11 +85,14 @@ export class ImageCropDialog {
75
85
  };
76
86
  const rotateHandle = handle('rotate','Rotate image','↻');
77
87
  const zoomHandle = handle('zoom','Zoom image','↘');
88
+ // Crop is a command, not a drag gesture: it has no data-crop-handle.
89
+ const cropHandle = handle('crop','Crop: select an area on the whole image','⬚');
90
+ delete cropHandle.dataset.cropHandle;
78
91
  const viewport = document.createElement('div'); viewport.className = 'crop-viewport'; viewport.append(frame);
79
92
  const position = document.createElement('div'); position.className = 'crop-position';
80
93
  position.style.width = `${width + 42}px`;
81
94
  const handles = document.createElement('div'); handles.className = 'crop-handles';
82
- handles.append(rotateHandle,zoomHandle); position.append(viewport,handles);
95
+ handles.append(rotateHandle,zoomHandle,cropHandle); position.append(viewport,handles);
83
96
  const hint = document.createElement('p'); hint.className = 'crop-help';
84
97
  hint.textContent = 'Drag to move · pinch to zoom';
85
98
  const body = document.createElement('div'); body.className = 'crop-body'; body.append(position);
@@ -89,7 +102,21 @@ export class ImageCropDialog {
89
102
  const cancel = document.createElement('button'); cancel.type = 'button'; cancel.textContent = 'Cancel';
90
103
  const confirm = document.createElement('button'); confirm.type = 'button'; confirm.textContent = 'Confirm'; confirm.className = 'primary';
91
104
  const buttons = document.createElement('div'); buttons.className = 'crop-action-buttons'; buttons.append(reset,cancel,confirm);
92
- actions.append(hint,buttons); body.append(error); dialog.append(style,heading,body,actions);
105
+ actions.append(hint,buttons); body.append(error);
106
+ // The Crop view: the rectangle selection and its own actions, in place of the frame and the dialog actions.
107
+ const rectangleView = document.createElement('div'); rectangleView.className = 'crop-rectangle-view'; rectangleView.hidden = true;
108
+ const rectangleActions = document.createElement('div'); rectangleActions.className = 'crop-actions'; rectangleActions.hidden = true;
109
+ const rectangleHint = document.createElement('p'); rectangleHint.className = 'crop-help'; rectangleHint.textContent = 'Drag the area or its handles';
110
+ const back = document.createElement('button'); back.type = 'button'; back.textContent = 'Back';
111
+ const apply = document.createElement('button'); apply.type = 'button'; apply.textContent = 'Apply'; apply.className = 'primary';
112
+ const rectangleButtons = document.createElement('div'); rectangleButtons.className = 'crop-action-buttons'; rectangleButtons.append(back,apply);
113
+ rectangleActions.append(rectangleHint,rectangleButtons);
114
+ dialog.append(style,heading,body,actions,rectangleView,rectangleActions);
115
+ const showRectangle = shown => {
116
+ dialog.classList.toggle('cropping', shown);
117
+ body.hidden = shown; actions.hidden = shown; rectangleView.hidden = !shown; rectangleActions.hidden = !shown;
118
+ subtitle.textContent = shown ? 'Select the area to keep.' : 'Move and adjust the image within the frame.';
119
+ };
93
120
  this.#events = new document.defaultView.AbortController();
94
121
  const listen = {signal:this.#events.signal};
95
122
  frame.addEventListener('pointerdown', event => this.#down(event), listen);
@@ -124,6 +151,19 @@ export class ImageCropDialog {
124
151
  this.#session.setTransform(value); this.#paint();
125
152
  }, listen);
126
153
  reset.addEventListener('click', () => { this.#cancelGesture(); this.#session.reset(); this.#paint(); }, listen);
154
+ cropHandle.addEventListener('click', () => {
155
+ this.#cancelGesture();
156
+ this.#selection ??= new ImageRectangleSelection({document,image,sourceWidth,sourceHeight,width,height,signal:this.#events.signal});
157
+ if (!this.#selection.element.isConnected) rectangleView.append(this.#selection.element);
158
+ showRectangle(true);
159
+ this.#selection.show(this.#session.transform);
160
+ this.#selection.element.querySelector('.crop-selection').focus();
161
+ }, listen);
162
+ back.addEventListener('click', () => { showRectangle(false); this.#frame.focus(); }, listen);
163
+ apply.addEventListener('click', () => {
164
+ this.#session.setTransform(this.#selection.transform); this.#paint();
165
+ showRectangle(false); this.#frame.focus();
166
+ }, listen);
127
167
  cancel.addEventListener('click', () => this.cancel(), listen);
128
168
  dialog.addEventListener('cancel', event => { event.preventDefault(); this.cancel(); }, listen);
129
169
  dialog.addEventListener('close', () => { if (!this.#settled) this.cancel(); }, listen);
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Private rectangle selection of the image crop dialog (its Crop view): the whole image fits the element and a
3
+ * dashed rectangle with eight handles selects the area. The rectangle keeps the frame aspect ratio (width/height)
4
+ * and stays inside the image. It reads and returns the frame transform: the area a width x height frame shows
5
+ * with x, y and zoom, rotation 0.
6
+ */
7
+ const HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
8
+ const MIN_SIDE = 16;
9
+
10
+ export const RECTANGLE_SELECTION_STYLE = `
11
+ .gramlot-crop-rectangle{position:relative;width:100%;height:100%;background:#1d2733;border-radius:8px;overflow:hidden}
12
+ .gramlot-crop-rectangle .crop-stage{position:absolute;touch-action:none;user-select:none}
13
+ .gramlot-crop-rectangle .crop-stage img{display:block;width:100%;height:100%;pointer-events:none}
14
+ .gramlot-crop-rectangle .crop-selection{position:absolute;border:2px dashed #fff;outline:1px solid #0009;box-shadow:0 0 0 9999px #0008;cursor:move}
15
+ .gramlot-crop-rectangle .crop-selection:focus-visible{outline:2px solid var(--gramlot-focus-ring,#3766b5)}
16
+ .gramlot-crop-rectangle .crop-selection span{position:absolute;width:12px;height:12px;margin:-6px;background:#fff;border:1px solid #1d2733;border-radius:2px}
17
+ .gramlot-crop-rectangle [data-handle=nw],.gramlot-crop-rectangle [data-handle=se]{cursor:nwse-resize}
18
+ .gramlot-crop-rectangle [data-handle=ne],.gramlot-crop-rectangle [data-handle=sw]{cursor:nesw-resize}
19
+ .gramlot-crop-rectangle [data-handle=n],.gramlot-crop-rectangle [data-handle=s]{cursor:ns-resize}
20
+ .gramlot-crop-rectangle [data-handle=e],.gramlot-crop-rectangle [data-handle=w]{cursor:ew-resize}`;
21
+
22
+ export class ImageRectangleSelection {
23
+ #options; #stage; #selection; #rect; #initial; #scale = 1; #drag = null; #observer = null;
24
+ constructor({document, image, sourceWidth, sourceHeight, width, height, signal}) {
25
+ this.#options = {width, height, sourceWidth, sourceHeight};
26
+ const element = this.element = document.createElement('div');
27
+ element.className = 'gramlot-crop-rectangle';
28
+ const stage = this.#stage = document.createElement('div'); stage.className = 'crop-stage';
29
+ const picture = document.createElement('img'); picture.src = image.src; picture.alt = ''; picture.draggable = false;
30
+ const selection = this.#selection = document.createElement('div'); selection.className = 'crop-selection';
31
+ selection.tabIndex = 0; selection.setAttribute('role', 'group'); selection.setAttribute('aria-label', 'Crop area');
32
+ selection.setAttribute('aria-description', 'Drag to move, drag a handle to resize. Arrow keys move the area.');
33
+ for (const name of HANDLES) {
34
+ const handle = document.createElement('span'); handle.dataset.handle = name;
35
+ Object.assign(handle.style, {left: name.includes('w') ? '0' : name.includes('e') ? '100%' : '50%',
36
+ top: name.includes('n') ? '0' : name.includes('s') ? '100%' : '50%'});
37
+ selection.append(handle);
38
+ }
39
+ stage.append(picture, selection); element.append(stage);
40
+ const listen = {signal};
41
+ selection.addEventListener('pointerdown', event => this.#down(event), listen);
42
+ selection.addEventListener('pointermove', event => this.#move(event), listen);
43
+ for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) selection.addEventListener(type, event => this.#up(event), listen);
44
+ selection.addEventListener('keydown', event => {
45
+ const delta = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]}[event.key];
46
+ if (!delta) return;
47
+ event.preventDefault();
48
+ const step = (event.shiftKey ? 10 : 1) / this.#scale;
49
+ this.#setRect({...this.#rect, x: this.#rect.x + delta[0] * step, y: this.#rect.y + delta[1] * step});
50
+ }, listen);
51
+ this.#observer = new document.defaultView.ResizeObserver(() => this.layout());
52
+ this.#observer.observe(element);
53
+ signal.addEventListener('abort', () => this.#observer.disconnect());
54
+ }
55
+ /** Show the area of a frame transform; Reset returns to it. */
56
+ show(transform) {
57
+ this.#rect = this.#initial = this.#fit(this.#rectFromTransform(transform));
58
+ this.layout();
59
+ }
60
+ reset() { this.#setRect(this.#initial); }
61
+ /** The frame transform (rotation 0) that shows the selected area in the width x height frame. */
62
+ get transform() {
63
+ const {x, y, w} = this.#rect, {width, height, sourceWidth, sourceHeight} = this.#options;
64
+ const zoom = width / w, h = w * height / width;
65
+ return {x: -zoom * (x + w / 2 - sourceWidth / 2), y: -zoom * (y + h / 2 - sourceHeight / 2), zoom, rotate: 0};
66
+ }
67
+ #rectFromTransform({x, y, zoom}) {
68
+ const {width, height, sourceWidth, sourceHeight} = this.#options;
69
+ const w = width / zoom, h = height / zoom;
70
+ return {x: sourceWidth / 2 - x / zoom - w / 2, y: sourceHeight / 2 - y / zoom - h / 2, w, h};
71
+ }
72
+ /** Keep the rectangle inside the image with the frame aspect ratio and at least MIN_SIDE source pixels. */
73
+ #fit({x, y, w}) {
74
+ const {width, height, sourceWidth, sourceHeight} = this.#options, ratio = width / height;
75
+ w = Math.max(MIN_SIDE, Math.min(w, sourceWidth, sourceHeight * ratio));
76
+ const h = w / ratio;
77
+ return {x: Math.max(0, Math.min(x, sourceWidth - w)), y: Math.max(0, Math.min(y, sourceHeight - h)), w, h};
78
+ }
79
+ #setRect(rect) { this.#rect = this.#fit(rect); this.#paint(); }
80
+ /** Fit the whole image in the element, centered. */
81
+ layout() {
82
+ const box = this.element.getBoundingClientRect(), {sourceWidth, sourceHeight} = this.#options;
83
+ if (!box.width || !box.height || !this.#rect) return;
84
+ this.#scale = Math.min(box.width / sourceWidth, box.height / sourceHeight);
85
+ const w = sourceWidth * this.#scale, h = sourceHeight * this.#scale;
86
+ Object.assign(this.#stage.style, {width: `${w}px`, height: `${h}px`, left: `${(box.width - w) / 2}px`, top: `${(box.height - h) / 2}px`});
87
+ this.#paint();
88
+ }
89
+ #paint() {
90
+ const {x, y, w, h} = this.#rect, s = this.#scale;
91
+ Object.assign(this.#selection.style, {left: `${x * s}px`, top: `${y * s}px`, width: `${w * s}px`, height: `${h * s}px`});
92
+ }
93
+ #down(event) {
94
+ if (event.button !== 0 || this.#drag) return;
95
+ event.preventDefault();
96
+ this.#selection.setPointerCapture(event.pointerId);
97
+ this.#drag = {id: event.pointerId, handle: event.target.dataset.handle ?? null, x: event.clientX, y: event.clientY, rect: {...this.#rect}};
98
+ }
99
+ #move(event) {
100
+ const drag = this.#drag;
101
+ if (!drag || drag.id !== event.pointerId) return;
102
+ event.preventDefault();
103
+ const dx = (event.clientX - drag.x) / this.#scale, dy = (event.clientY - drag.y) / this.#scale, base = drag.rect;
104
+ if (!drag.handle) { this.#setRect({...base, x: base.x + dx, y: base.y + dy}); return; }
105
+ const {width, height, sourceWidth, sourceHeight} = this.#options, ratio = width / height, handle = drag.handle;
106
+ // The new width from the dragged side; the height follows the ratio; the opposite side or corner stays.
107
+ let w = base.w;
108
+ if (handle.includes('e')) w = base.w + dx;
109
+ else if (handle.includes('w')) w = base.w - dx;
110
+ if (handle === 'n' || handle === 's') w = (base.h + (handle === 's' ? dy : -dy)) * ratio;
111
+ else if (handle.length === 2) {
112
+ // A corner follows the direction moved further.
113
+ const vertical = (base.h + (handle.includes('s') ? dy : -dy)) * ratio;
114
+ if (Math.abs(vertical - base.w) > Math.abs(w - base.w)) w = vertical;
115
+ }
116
+ w = Math.max(MIN_SIDE, Math.min(w, sourceWidth, sourceHeight * ratio));
117
+ const h = w / ratio;
118
+ const x = handle.includes('w') ? base.x + base.w - w : handle.includes('e') ? base.x : base.x + (base.w - w) / 2;
119
+ const y = handle.includes('n') ? base.y + base.h - h : handle.includes('s') ? base.y : base.y + (base.h - h) / 2;
120
+ this.#setRect({x, y, w});
121
+ }
122
+ #up(event) {
123
+ if (!this.#drag || this.#drag.id !== event.pointerId) return;
124
+ if (event.type === 'pointerup') this.#move(event);
125
+ if (this.#selection.hasPointerCapture(event.pointerId)) this.#selection.releasePointerCapture(event.pointerId);
126
+ this.#drag = null;
127
+ }
128
+ }