@visactor/vrender-core 0.22.0-vstory.12 → 0.22.0-vstory.14

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 (70) hide show
  1. package/cjs/common/inversify/annotation/optional.d.ts +2 -0
  2. package/cjs/common/inversify/annotation/optional.js +14 -0
  3. package/cjs/common/inversify/annotation/optional.js.map +1 -0
  4. package/cjs/common/inversify/container.js +9 -6
  5. package/cjs/common/inversify/container.js.map +1 -1
  6. package/cjs/core/contributions/textMeasure/AtextMeasure.js +10 -0
  7. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  8. package/cjs/graphic/bounds.d.ts +2 -2
  9. package/cjs/graphic/bounds.js.map +1 -1
  10. package/cjs/graphic/config.js +1 -0
  11. package/cjs/graphic/config.js.map +1 -1
  12. package/cjs/graphic/richtext.d.ts +1 -1
  13. package/cjs/graphic/richtext.js +22 -5
  14. package/cjs/graphic/richtext.js.map +1 -1
  15. package/cjs/interface/graphic/richText.d.ts +1 -0
  16. package/cjs/interface/graphic/richText.js.map +1 -1
  17. package/cjs/interface/graphic.d.ts +1 -0
  18. package/cjs/interface/graphic.js.map +1 -1
  19. package/cjs/plugins/builtin-plugin/edit-module.js +2 -1
  20. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  21. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +8 -4
  22. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +124 -81
  23. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  24. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  25. package/cjs/render/contributions/render/contributions/base-contribution-render.js +7 -3
  26. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  27. package/cjs/render/contributions/render/contributions/group-contribution-render.js +2 -1
  28. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  29. package/cjs/render/contributions/render/contributions/text-contribution-render.js +3 -2
  30. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  31. package/cjs/render/contributions/render/draw-contribution.js +1 -0
  32. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  33. package/cjs/resource-loader/loader.d.ts +2 -2
  34. package/cjs/resource-loader/loader.js.map +1 -1
  35. package/dist/index.es.js +150 -65
  36. package/es/common/inversify/annotation/optional.d.ts +2 -0
  37. package/es/common/inversify/annotation/optional.js +12 -0
  38. package/es/common/inversify/annotation/optional.js.map +1 -0
  39. package/es/common/inversify/container.js +9 -6
  40. package/es/common/inversify/container.js.map +1 -1
  41. package/es/core/contributions/textMeasure/AtextMeasure.js +10 -0
  42. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  43. package/es/graphic/bounds.d.ts +2 -2
  44. package/es/graphic/bounds.js.map +1 -1
  45. package/es/graphic/config.js +1 -0
  46. package/es/graphic/config.js.map +1 -1
  47. package/es/graphic/richtext.d.ts +1 -1
  48. package/es/graphic/richtext.js +19 -4
  49. package/es/graphic/richtext.js.map +1 -1
  50. package/es/interface/graphic/richText.d.ts +1 -0
  51. package/es/interface/graphic/richText.js.map +1 -1
  52. package/es/interface/graphic.d.ts +1 -0
  53. package/es/interface/graphic.js.map +1 -1
  54. package/es/plugins/builtin-plugin/edit-module.js +2 -1
  55. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  56. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +8 -4
  57. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +124 -81
  58. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  59. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  60. package/es/render/contributions/render/contributions/base-contribution-render.js +7 -3
  61. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  62. package/es/render/contributions/render/contributions/group-contribution-render.js +2 -1
  63. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  64. package/es/render/contributions/render/contributions/text-contribution-render.js +3 -2
  65. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  66. package/es/render/contributions/render/draw-contribution.js +3 -2
  67. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  68. package/es/resource-loader/loader.d.ts +2 -2
  69. package/es/resource-loader/loader.js.map +1 -1
  70. package/package.json +1 -1
package/dist/index.es.js CHANGED
@@ -607,15 +607,17 @@ class Container {
607
607
  serviceIdentifier: injectIdentifier,
608
608
  constructorArgsMetadata
609
609
  };
610
- const bindings = this._bindingDictionary.get(injectIdentifier).filter(b => {
610
+ const bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter(b => {
611
611
  return b.constraint(target);
612
612
  });
613
- const request = {
614
- injectIdentifier,
615
- metadata: constructorArgsMetadata,
616
- bindings
617
- };
618
- arr.push(request);
613
+ if (bindings.length) {
614
+ const request = {
615
+ injectIdentifier,
616
+ metadata: constructorArgsMetadata,
617
+ bindings: bindings
618
+ };
619
+ arr.push(request);
620
+ }
619
621
  }
620
622
  return arr;
621
623
  }
@@ -3286,7 +3288,7 @@ const DefaultTextStyle = {
3286
3288
  const DefaultPickStyle = {
3287
3289
  pickStrokeBuffer: 0
3288
3290
  };
3289
- const DefaultStyle = Object.assign(Object.assign(Object.assign(Object.assign({ forceBoundsWidth: undefined, forceBoundsHeight: undefined, opacity: 1, background: null, autoAnimateTexture: false, textureRatio: 0, textureOptions: null, backgroundOpacity: 1, backgroundCornerRadius: 0, texture: null, textureColor: 'black', textureSize: 10, texturePadding: 2, backgroundMode: 'no-repeat', backgroundFit: true, backgroundClip: true, backgroundScale: 1, backgroundOffsetX: 0, backgroundOffsetY: 0, blur: 0, filter: '', cursor: null, html: null, react: null }, DefaultFillStyle), DefaultStrokeStyle), DefaultLayout), DefaultPickStyle);
3291
+ const DefaultStyle = Object.assign(Object.assign(Object.assign(Object.assign({ forceBoundsWidth: undefined, forceBoundsHeight: undefined, opacity: 1, background: null, autoAnimateTexture: false, textureRatio: 0, textureOptions: null, backgroundOpacity: 1, backgroundCornerRadius: 0, texture: null, textureColor: 'black', textureSize: 10, texturePadding: 2, backgroundMode: 'no-repeat', backgroundFit: true, backgroundKeepAspectRatio: false, backgroundClip: true, backgroundScale: 1, backgroundOffsetX: 0, backgroundOffsetY: 0, blur: 0, filter: '', cursor: null, html: null, react: null }, DefaultFillStyle), DefaultStrokeStyle), DefaultLayout), DefaultPickStyle);
3290
3292
  const DefaultConnectAttribute = {
3291
3293
  connectedType: 'none',
3292
3294
  connectedStyle: {},
@@ -3981,6 +3983,9 @@ let ATextMeasure = class ATextMeasure {
3981
3983
  metrics.actualBoundingBoxDescent == null ||
3982
3984
  metrics.fontBoundingBoxAscent == null ||
3983
3985
  metrics.fontBoundingBoxDescent == null) {
3986
+ metrics = {
3987
+ width: metrics.width
3988
+ };
3984
3989
  const { ascent, descent } = this.measureTextBoundADscentEstimate(options);
3985
3990
  metrics.actualBoundingBoxAscent = ascent;
3986
3991
  metrics.actualBoundingBoxDescent = descent;
@@ -3988,6 +3993,13 @@ let ATextMeasure = class ATextMeasure {
3988
3993
  metrics.fontBoundingBoxDescent = descent;
3989
3994
  }
3990
3995
  if (metrics.actualBoundingBoxLeft == null || metrics.actualBoundingBoxRight == null) {
3996
+ metrics = {
3997
+ width: metrics.width,
3998
+ actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
3999
+ actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
4000
+ fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
4001
+ fontBoundingBoxDescent: metrics.fontBoundingBoxDescent
4002
+ };
3991
4003
  const { left, right } = this.measureTextBoundLeftRightEstimate(options);
3992
4004
  metrics.actualBoundingBoxLeft = left;
3993
4005
  metrics.actualBoundingBoxRight = right;
@@ -18618,6 +18630,13 @@ class Wrapper {
18618
18630
  }
18619
18631
  }
18620
18632
 
18633
+ let supportIntl = false;
18634
+ try {
18635
+ supportIntl = Intl && typeof Intl.Segmenter === 'function';
18636
+ }
18637
+ catch (e) {
18638
+ supportIntl = false;
18639
+ }
18621
18640
  const RICHTEXT_UPDATE_TAG_KEY = [
18622
18641
  'width',
18623
18642
  'height',
@@ -18778,6 +18797,14 @@ class RichText extends Graphic {
18778
18797
  !(item.text && isString(item.text) && RichText.splitText(item.text).length > 1));
18779
18798
  }
18780
18799
  static splitText(text) {
18800
+ if (supportIntl) {
18801
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
18802
+ const segments = [];
18803
+ for (const { segment } of segmenter.segment(text)) {
18804
+ segments.push(segment);
18805
+ }
18806
+ return segments;
18807
+ }
18781
18808
  return Array.from(text);
18782
18809
  }
18783
18810
  static TransformTextConfig2SingleCharacter(textConfig) {
@@ -18797,8 +18824,8 @@ class RichText extends Graphic {
18797
18824
  return tc;
18798
18825
  }
18799
18826
  updateAABBBounds(attribute, richtextTheme, aabbBounds) {
18800
- var _a, _b;
18801
- const { width = richtextTheme.width, height = richtextTheme.height, maxWidth = richtextTheme.maxWidth, maxHeight = richtextTheme.maxHeight, textAlign = richtextTheme.textAlign, textBaseline = richtextTheme.textBaseline, editOptions } = attribute;
18827
+ var _a, _b, _c, _d;
18828
+ const { width = richtextTheme.width, height = richtextTheme.height, maxWidth = richtextTheme.maxWidth, maxHeight = richtextTheme.maxHeight, textAlign = richtextTheme.textAlign, verticalDirection = (_b = (_a = attribute.textBaseline) !== null && _a !== void 0 ? _a : richtextTheme.textBaseline) !== null && _b !== void 0 ? _b : richtextTheme.verticalDirection, editOptions } = attribute;
18802
18829
  if (width > 0 && height > 0) {
18803
18830
  aabbBounds.set(0, 0, width, height);
18804
18831
  }
@@ -18811,12 +18838,12 @@ class RichText extends Graphic {
18811
18838
  contentWidth = typeof maxWidth === 'number' && contentWidth > maxWidth ? maxWidth : contentWidth || 0;
18812
18839
  aabbBounds.set(0, 0, contentWidth, contentHeight);
18813
18840
  }
18814
- if (editOptions && editOptions.keepHeightWhileEmpty && !aabbBounds.height() && !((_a = attribute.textConfig) === null || _a === void 0 ? void 0 : _a.length)) {
18815
- aabbBounds.y2 = aabbBounds.y1 + ((_b = attribute.fontSize) !== null && _b !== void 0 ? _b : 12);
18841
+ if (editOptions && editOptions.keepHeightWhileEmpty && !aabbBounds.height() && !((_c = attribute.textConfig) === null || _c === void 0 ? void 0 : _c.length)) {
18842
+ aabbBounds.y2 = aabbBounds.y1 + ((_d = attribute.fontSize) !== null && _d !== void 0 ? _d : 12);
18816
18843
  aabbBounds.x2 = aabbBounds.x1 + 2;
18817
18844
  }
18818
18845
  let deltaY = 0;
18819
- switch (textBaseline) {
18846
+ switch (verticalDirection) {
18820
18847
  case 'top':
18821
18848
  deltaY = 0;
18822
18849
  break;
@@ -20105,7 +20132,7 @@ class DefaultBaseBackgroundRenderContribution {
20105
20132
  }
20106
20133
  drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, options) {
20107
20134
  var _a;
20108
- const { background, backgroundOpacity = (_a = graphic.attribute.fillOpacity) !== null && _a !== void 0 ? _a : graphicAttribute.backgroundOpacity, opacity = graphicAttribute.opacity, backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundScale = graphicAttribute.backgroundScale, backgroundOffsetX = graphicAttribute.backgroundOffsetX, backgroundOffsetY = graphicAttribute.backgroundOffsetY, backgroundClip = graphicAttribute.backgroundClip } = graphic.attribute;
20135
+ const { background, backgroundOpacity = (_a = graphic.attribute.fillOpacity) !== null && _a !== void 0 ? _a : graphicAttribute.backgroundOpacity, opacity = graphicAttribute.opacity, backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundKeepAspectRatio = graphicAttribute.backgroundKeepAspectRatio, backgroundScale = graphicAttribute.backgroundScale, backgroundOffsetX = graphicAttribute.backgroundOffsetX, backgroundOffsetY = graphicAttribute.backgroundOffsetY, backgroundClip = graphicAttribute.backgroundClip } = graphic.attribute;
20109
20136
  if (!background) {
20110
20137
  return;
20111
20138
  }
@@ -20128,6 +20155,7 @@ class DefaultBaseBackgroundRenderContribution {
20128
20155
  this.doDrawImage(context, res.data, b, {
20129
20156
  backgroundMode,
20130
20157
  backgroundFit,
20158
+ backgroundKeepAspectRatio,
20131
20159
  backgroundScale,
20132
20160
  backgroundOffsetX,
20133
20161
  backgroundOffsetY
@@ -20147,14 +20175,20 @@ class DefaultBaseBackgroundRenderContribution {
20147
20175
  }
20148
20176
  }
20149
20177
  doDrawImage(context, data, b, params) {
20150
- const { backgroundMode, backgroundFit, backgroundScale = 1, backgroundOffsetX = 0, backgroundOffsetY = 0 } = params;
20178
+ const { backgroundMode, backgroundFit, backgroundKeepAspectRatio, backgroundScale = 1, backgroundOffsetX = 0, backgroundOffsetY = 0 } = params;
20151
20179
  const targetW = b.width();
20152
20180
  const targetH = b.height();
20153
20181
  let w = targetW;
20154
20182
  let h = targetH;
20155
20183
  if (backgroundMode === 'no-repeat') {
20156
20184
  if (backgroundFit) {
20157
- context.drawImage(data, b.x1, b.y1, b.width(), b.height());
20185
+ if (!backgroundKeepAspectRatio) {
20186
+ context.drawImage(data, b.x1, b.y1, b.width(), b.height());
20187
+ }
20188
+ else {
20189
+ const maxScale = Math.max(targetW / data.width, targetH / data.height);
20190
+ context.drawImage(data, b.x1 + backgroundOffsetX, b.y1 + backgroundOffsetY, data.width * maxScale * backgroundScale, data.height * maxScale * backgroundScale);
20191
+ }
20158
20192
  }
20159
20193
  else {
20160
20194
  const resW = data.width * backgroundScale;
@@ -20523,7 +20557,7 @@ class DefaultGroupBackgroundRenderContribution extends DefaultBaseBackgroundRend
20523
20557
  this.time = BaseRenderContributionTime.beforeFillStroke;
20524
20558
  }
20525
20559
  drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb) {
20526
- const { background, backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundScale = graphicAttribute.backgroundScale, backgroundOffsetX = graphicAttribute.backgroundOffsetX, backgroundOffsetY = graphicAttribute.backgroundOffsetY } = graphic.attribute;
20560
+ const { background, backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundKeepAspectRatio = graphicAttribute.backgroundKeepAspectRatio, backgroundScale = graphicAttribute.backgroundScale, backgroundOffsetX = graphicAttribute.backgroundOffsetX, backgroundOffsetY = graphicAttribute.backgroundOffsetY } = graphic.attribute;
20527
20561
  if (!background) {
20528
20562
  return;
20529
20563
  }
@@ -20538,6 +20572,7 @@ class DefaultGroupBackgroundRenderContribution extends DefaultBaseBackgroundRend
20538
20572
  this.doDrawImage(context, res.data, b, {
20539
20573
  backgroundMode,
20540
20574
  backgroundFit,
20575
+ backgroundKeepAspectRatio,
20541
20576
  backgroundScale,
20542
20577
  backgroundOffsetX,
20543
20578
  backgroundOffsetY
@@ -22441,7 +22476,7 @@ class DefaultTextBackgroundRenderContribution extends DefaultBaseBackgroundRende
22441
22476
  }
22442
22477
  drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb) {
22443
22478
  var _a, _c, _d, _e, _f, _g, _h, _j, _k, _l;
22444
- const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit } = graphic.attribute;
22479
+ const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundKeepAspectRatio = graphicAttribute.backgroundKeepAspectRatio } = graphic.attribute;
22445
22480
  let { background } = graphic.attribute;
22446
22481
  if (!background) {
22447
22482
  return;
@@ -22498,7 +22533,7 @@ class DefaultTextBackgroundRenderContribution extends DefaultBaseBackgroundRende
22498
22533
  context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true);
22499
22534
  }
22500
22535
  context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);
22501
- this.doDrawImage(context, res.data, b, { backgroundMode, backgroundFit });
22536
+ this.doDrawImage(context, res.data, b, { backgroundMode, backgroundFit, backgroundKeepAspectRatio });
22502
22537
  context.highPerformanceRestore();
22503
22538
  context.setTransformForCurrent();
22504
22539
  }
@@ -24096,6 +24131,9 @@ let DefaultDrawContribution = class DefaultDrawContribution {
24096
24131
  this.backupDirtyBounds = new Bounds();
24097
24132
  this.global = application.global;
24098
24133
  this.layerService = application.layerService;
24134
+ if (!isArray(this.contributions)) {
24135
+ this.contributions = [this.contributions];
24136
+ }
24099
24137
  this.init();
24100
24138
  }
24101
24139
  init() {
@@ -27040,8 +27078,9 @@ class EditModule {
27040
27078
  application.global.addEventListener('keydown', this.handleKeyDown);
27041
27079
  }
27042
27080
  parseCompositionStr(configIdx) {
27081
+ var _a;
27043
27082
  const { textConfig = [] } = this.currRt.attribute;
27044
- const lastConfig = textConfig[configIdx];
27083
+ const lastConfig = (_a = textConfig[configIdx]) !== null && _a !== void 0 ? _a : {};
27045
27084
  textConfig.splice(configIdx, 1);
27046
27085
  const text = lastConfig.text;
27047
27086
  const textList = text ? Array.from(text.toString()) : [];
@@ -27121,18 +27160,23 @@ class Selection {
27121
27160
  }
27122
27161
  return (_a = config[Math.min(idx, config.length - 1)][key]) !== null && _a !== void 0 ? _a : this.rt.attribute[key];
27123
27162
  }
27124
- getFormat(key) {
27125
- return this.getAllFormat(key)[0];
27163
+ getFormat(key, supportOutAttr = false) {
27164
+ return this.getAllFormat(key, supportOutAttr)[0];
27126
27165
  }
27127
- getAllFormat(key) {
27166
+ getAllFormat(key, supportOutAttr = false) {
27167
+ var _a, _b, _c, _d;
27128
27168
  const valSet = new Set();
27129
27169
  const minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx);
27130
27170
  const maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
27131
27171
  if (minCursorIdx === maxCursorIdx) {
27132
- return [this._getFormat(key, minCursorIdx)];
27172
+ return supportOutAttr
27173
+ ? [(_a = this._getFormat(key, minCursorIdx)) !== null && _a !== void 0 ? _a : ((_b = this.rt) === null || _b === void 0 ? void 0 : _b.attribute)[key]]
27174
+ : [this._getFormat(key, minCursorIdx)];
27133
27175
  }
27134
27176
  for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
27135
- const val = this._getFormat(key, i);
27177
+ const val = supportOutAttr
27178
+ ? (_c = this._getFormat(key, i)) !== null && _c !== void 0 ? _c : ((_d = this.rt) === null || _d === void 0 ? void 0 : _d.attribute)[key]
27179
+ : this._getFormat(key, i);
27136
27180
  val && valSet.add(val);
27137
27181
  }
27138
27182
  return Array.from(valSet.values());
@@ -27197,10 +27241,10 @@ class RichTextEditPlugin {
27197
27241
  if (this.copyToClipboard(e)) {
27198
27242
  return;
27199
27243
  }
27200
- if (this.fullSelection(e)) {
27244
+ if (this.fullSelectionKeyHandler(e)) {
27201
27245
  return;
27202
27246
  }
27203
- if (this.directKey(e)) {
27247
+ if (this.directKeyHandler(e)) {
27204
27248
  return;
27205
27249
  }
27206
27250
  };
@@ -27238,7 +27282,7 @@ class RichTextEditPlugin {
27238
27282
  }
27239
27283
  this.currRt = e.target;
27240
27284
  this.handleEnter(e);
27241
- e.target.once('pointerleave', this.handleLeave);
27285
+ e.target.once('pointerleave', this.handleLeave, { capture: true });
27242
27286
  this.tryShowSelection(e, false);
27243
27287
  };
27244
27288
  this.handleEnter = (e) => {
@@ -27332,11 +27376,11 @@ class RichTextEditPlugin {
27332
27376
  activate(context) {
27333
27377
  this.pluginService = context;
27334
27378
  this.editModule = new EditModule();
27335
- context.stage.on('pointermove', this.handleMove);
27336
- context.stage.on('pointerdown', this.handlePointerDown);
27337
- context.stage.on('pointerup', this.handlePointerUp);
27338
- context.stage.on('pointerleave', this.handlePointerUp);
27339
- context.stage.on('dblclick', this.handleDBLClick);
27379
+ context.stage.on('pointermove', this.handleMove, { capture: true });
27380
+ context.stage.on('pointerdown', this.handlePointerDown, { capture: true });
27381
+ context.stage.on('pointerup', this.handlePointerUp, { capture: true });
27382
+ context.stage.on('pointerleave', this.handlePointerUp, { capture: true });
27383
+ context.stage.on('dblclick', this.handleDBLClick, { capture: true });
27340
27384
  application.global.addEventListener('keydown', this.handleKeyDown);
27341
27385
  this.editModule.onInput(this.handleInput);
27342
27386
  this.editModule.onChange(this.handleChange);
@@ -27380,26 +27424,32 @@ class RichTextEditPlugin {
27380
27424
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt);
27381
27425
  this._tryShowSelection(pos, cache);
27382
27426
  }
27383
- fullSelection(e) {
27427
+ fullSelection() {
27428
+ const currRt = this.currRt;
27429
+ if (!currRt) {
27430
+ return;
27431
+ }
27432
+ const cache = currRt.getFrameCache();
27433
+ if (!cache) {
27434
+ return;
27435
+ }
27436
+ const { lines } = cache;
27437
+ if (!(lines.length && lines[0].paragraphs.length)) {
27438
+ return;
27439
+ }
27440
+ const totalCursorCount = lines.reduce((total, line) => total + line.paragraphs.length, 0) - 1;
27441
+ this.selectionRange(-0.1, totalCursorCount + 0.1);
27442
+ }
27443
+ fullSelectionKeyHandler(e) {
27384
27444
  if ((application.global.isMacOS() && e.metaKey && e.key === 'a') ||
27385
27445
  (!application.global.isMacOS() && e.ctrlKey && e.key === 'a')) {
27386
- const currRt = this.currRt;
27387
- if (!currRt) {
27388
- return;
27389
- }
27390
- const cache = currRt.getFrameCache();
27391
- if (!cache) {
27392
- return;
27393
- }
27394
- const { lines } = cache;
27395
- const totalCursorCount = lines.reduce((total, line) => total + line.paragraphs.length, 0) - 1;
27396
- this.selectionRange(-0.1, totalCursorCount + 0.1);
27446
+ this.fullSelection();
27397
27447
  e.preventDefault();
27398
27448
  return true;
27399
27449
  }
27400
27450
  return false;
27401
27451
  }
27402
- directKey(e) {
27452
+ directKeyHandler(e) {
27403
27453
  if (!(e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'ArrowLeft' || e.key === 'ArrowRight')) {
27404
27454
  return false;
27405
27455
  }
@@ -27497,7 +27547,7 @@ class RichTextEditPlugin {
27497
27547
  const placeholder = shadowRoot.getElementsByType('richtext')[0];
27498
27548
  placeholder && shadowRoot.removeChild(placeholder);
27499
27549
  }
27500
- const { textConfig, editOptions } = this.currRt.attribute;
27550
+ const { textConfig, editOptions = {} } = this.currRt.attribute;
27501
27551
  if (textConfig && textConfig.length) {
27502
27552
  return;
27503
27553
  }
@@ -27516,9 +27566,16 @@ class RichTextEditPlugin {
27516
27566
  if (placeholderFontSize) {
27517
27567
  textConfigItem.fontSize = placeholderFontSize;
27518
27568
  }
27519
- this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, angle: 0, _debug_bounds: false, textConfig: [textConfigItem] }));
27569
+ this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, dx: -this.deltaX, dy: -this.deltaY, angle: 0, textConfig: [textConfigItem] }));
27520
27570
  shadow.add(this.shadowPlaceHolder);
27521
27571
  }
27572
+ getRichTextAABBBounds(rt) {
27573
+ const { attribute } = rt;
27574
+ if (!attribute.textConfig.length) {
27575
+ return getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), { x: attribute.x, y: attribute.y, textAlign: attribute.textAlign, boundsMode: 'accurate' }));
27576
+ }
27577
+ return rt.AABBBounds;
27578
+ }
27522
27579
  tryShowInputBounds() {
27523
27580
  if (!(this.currRt && this.focusing)) {
27524
27581
  return;
@@ -27528,19 +27585,15 @@ class RichTextEditPlugin {
27528
27585
  if (!editOptions || !boundsStrokeWhenInput) {
27529
27586
  return;
27530
27587
  }
27531
- const { attribute } = this.currRt;
27532
- const b = this.currRt.AABBBounds;
27533
- let h = b.height();
27534
- if (!attribute.textConfig.length && this.editLine) {
27535
- const { points } = this.editLine.attribute;
27536
- h = points[1].y - points[0].y;
27537
- }
27588
+ const b = this.getRichTextAABBBounds(this.currRt);
27589
+ const height = b.height();
27590
+ const width = b.width();
27538
27591
  this.shadowBounds = this.shadowBounds || createRect({});
27539
27592
  this.shadowBounds.setAttributes({
27540
27593
  x: 0,
27541
27594
  y: 0,
27542
- width: b.width(),
27543
- height: h,
27595
+ width,
27596
+ height,
27544
27597
  fill: false,
27545
27598
  stroke: boundsStrokeWhenInput,
27546
27599
  lineWidth: 1,
@@ -27549,6 +27602,7 @@ class RichTextEditPlugin {
27549
27602
  const shadow = this.getShadow(this.currRt);
27550
27603
  shadow.add(this.shadowBounds);
27551
27604
  this.offsetLineBgAndShadowBounds();
27605
+ this.offsetShadowRoot();
27552
27606
  }
27553
27607
  trySyncPlaceholderToTextConfig() {
27554
27608
  if (!this.currRt) {
@@ -27558,7 +27612,7 @@ class RichTextEditPlugin {
27558
27612
  if (textConfig && textConfig.length) {
27559
27613
  return;
27560
27614
  }
27561
- if (!(editOptions && editOptions.placeholder)) {
27615
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) {
27562
27616
  return;
27563
27617
  }
27564
27618
  const { placeholder } = editOptions;
@@ -27569,13 +27623,16 @@ class RichTextEditPlugin {
27569
27623
  });
27570
27624
  }
27571
27625
  deactivate(context) {
27572
- context.stage.off('pointermove', this.handleMove);
27573
- context.stage.off('pointerdown', this.handlePointerDown);
27574
- context.stage.off('pointerup', this.handlePointerUp);
27575
- context.stage.off('pointerleave', this.handlePointerUp);
27576
- context.stage.off('dblclick', this.handleDBLClick);
27626
+ context.stage.off('pointermove', this.handleMove, { capture: true });
27627
+ context.stage.off('pointerdown', this.handlePointerDown, { capture: true });
27628
+ context.stage.off('pointerup', this.handlePointerUp, { capture: true });
27629
+ context.stage.off('pointerleave', this.handlePointerUp, { capture: true });
27630
+ context.stage.off('dblclick', this.handleDBLClick, { capture: true });
27577
27631
  application.global.addEventListener('keydown', this.handleKeyDown);
27578
27632
  }
27633
+ stopPropagation(e) {
27634
+ e.stopPropagation();
27635
+ }
27579
27636
  onFocus(e, data) {
27580
27637
  this.updateCbs && this.updateCbs.forEach(cb => cb('beforeOnfocus', this));
27581
27638
  this.deFocus(false);
@@ -27591,8 +27648,11 @@ class RichTextEditPlugin {
27591
27648
  if (!cache) {
27592
27649
  return;
27593
27650
  }
27594
- this.computeGlobalDelta(cache);
27595
- shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
27651
+ const { editOptions = {} } = this.currRt.attribute;
27652
+ if (editOptions.stopPropagation) {
27653
+ target.addEventListener('*', this.stopPropagation);
27654
+ }
27655
+ this.offsetShadowRoot(target);
27596
27656
  if (!this.editLine) {
27597
27657
  const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });
27598
27658
  this.addAnimateToLine(line);
@@ -27624,6 +27684,23 @@ class RichTextEditPlugin {
27624
27684
  this.tryShowInputBounds();
27625
27685
  this.currRt.addUpdateBoundTag();
27626
27686
  }
27687
+ offsetShadowRoot(rt) {
27688
+ rt = rt || this.currRt;
27689
+ if (!rt) {
27690
+ return;
27691
+ }
27692
+ const shadowRoot = this.getShadow(rt);
27693
+ if (!shadowRoot) {
27694
+ return;
27695
+ }
27696
+ const cache = rt.getFrameCache();
27697
+ if (!cache) {
27698
+ return;
27699
+ }
27700
+ this.computeGlobalDelta(cache);
27701
+ shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
27702
+ this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({ dx: -this.deltaX, dy: -this.deltaY });
27703
+ }
27627
27704
  offsetLineBgAndShadowBounds() {
27628
27705
  const rt = this.currRt;
27629
27706
  const { textBaseline } = rt.attribute;
@@ -27654,6 +27731,10 @@ class RichTextEditPlugin {
27654
27731
  if (!target) {
27655
27732
  return;
27656
27733
  }
27734
+ const { editOptions = {} } = target.attribute;
27735
+ if (editOptions.stopPropagation) {
27736
+ target.removeEventListener('*', this.stopPropagation);
27737
+ }
27657
27738
  if (trulyDeFocus) {
27658
27739
  this.trySyncPlaceholderToTextConfig();
27659
27740
  target.detachShadow();
@@ -27891,6 +27972,9 @@ class RichTextEditPlugin {
27891
27972
  computeGlobalDelta(cache) {
27892
27973
  this.deltaX = 0;
27893
27974
  this.deltaY = 0;
27975
+ if (cache.lines.length === 0 && this.shadowPlaceHolder) {
27976
+ cache = this.shadowPlaceHolder.getFrameCache();
27977
+ }
27894
27978
  const height = cache.height;
27895
27979
  const actualHeight = cache.actualHeight;
27896
27980
  const width = cache.lines.reduce((w, item) => Math.max(w, item.actualWidth), 0);
@@ -27941,6 +28025,7 @@ class RichTextEditPlugin {
27941
28025
  out.x += left;
27942
28026
  out.y += top;
27943
28027
  this.offsetLineBgAndShadowBounds();
28028
+ this.offsetShadowRoot();
27944
28029
  this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
27945
28030
  }
27946
28031
  computedCursorPosByEvent(e, cache) {
@@ -0,0 +1,2 @@
1
+ declare function optional(): <T>(target: import("./inject_base").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number) => void;
2
+ export { optional };
@@ -0,0 +1,12 @@
1
+ import { Metadata } from "../meta-data";
2
+
3
+ import { OPTIONAL_TAG } from "../metadata_keys";
4
+
5
+ import { createTaggedDecorator } from "./inject_base";
6
+
7
+ function optional() {
8
+ return createTaggedDecorator(new Metadata(OPTIONAL_TAG, !0));
9
+ }
10
+
11
+ export { optional };
12
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/inversify/annotation/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,SAAS,QAAQ;IACf,OAAO,qBAAqB,CAAC,IAAI,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","file":"optional.js","sourcesContent":["import { Metadata } from '../meta-data';\nimport { OPTIONAL_TAG } from '../metadata_keys';\nimport { createTaggedDecorator } from './inject_base';\n\nfunction optional() {\n return createTaggedDecorator(new Metadata(OPTIONAL_TAG, true));\n}\n\nexport { optional };\n"]}
@@ -102,12 +102,15 @@ export class Container {
102
102
  }, injectIdentifier = metadata.inject || metadata.multiInject, target = {
103
103
  serviceIdentifier: injectIdentifier,
104
104
  constructorArgsMetadata: constructorArgsMetadata
105
- }, request = {
106
- injectIdentifier: injectIdentifier,
107
- metadata: constructorArgsMetadata,
108
- bindings: this._bindingDictionary.get(injectIdentifier).filter((b => b.constraint(target)))
109
- };
110
- arr.push(request);
105
+ }, bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter((b => b.constraint(target)));
106
+ if (bindings.length) {
107
+ const request = {
108
+ injectIdentifier: injectIdentifier,
109
+ metadata: constructorArgsMetadata,
110
+ bindings: bindings
111
+ };
112
+ arr.push(request);
113
+ }
111
114
  }
112
115
  return arr;
113
116
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/common/inversify/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAgB7D,MAAM,OAAO,SAAS;IAMpB,YAAY,gBAA8C;QACxD,MAAM,OAAO,GAAG,gBAAgB,IAAI,EAAE,CAAC;QACvC,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,gBAAgB,CAAC,SAAS,CAAC;QAE1E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,kBAAkB,EAAE,CA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ACrB,OAAO,OAAO,CAAC,KAAK,CAAC;SACtB;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACrD,CAAC;IAEO,eAAe,CAAI,MAA6B,EAAE,aAA8B;QACtF,IAAI,aAAa,CAAC,MAAM,EAAE;YACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACtD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC;YACpC,OAAO,GAAG,CAAC;SACZ;QACD,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,gBAAgB,CAAC,aAA8B;QACrD,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACjC,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAChC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBACpE,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,OAAyB,EAAE,MAAW;QACzD,IAAI,OAAO,CAAC,KAAK,KAAK,gBAAgB,CAAC,SAAS,EAAE;YAChD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;CACF","file":"container.js","sourcesContent":["import { Generator } from '../generator';\nimport { Binding } from './binding';\nimport type { interfaces } from './interfaces';\nimport { BindingScopeEnum, BindingTypeEnum } from './literal_types';\nimport { Metadata } from './meta-data';\nimport { INJECT_TAG, MULTI_INJECT_TAG, NAMED_TAG } from './metadata_keys';\nimport { MetadataReader } from './metadata_reader';\nimport { BindingToSyntax } from './syntax/binding_to_syntax';\n\ninterface IChildRequest {\n injectIdentifier: any;\n metadata: interfaces.Metadata<unknown>[];\n bindings: Binding<unknown>[];\n}\n\ninterface GetArgs<T> {\n avoidConstraints: boolean;\n isMultiInject: boolean;\n serviceIdentifier: interfaces.ServiceIdentifier<T>;\n key: string | symbol;\n value: any;\n}\n\nexport class Container {\n id: number;\n readonly options: interfaces.ContainerOptions;\n private _bindingDictionary: Map<any, Binding<unknown>[]>;\n private _metadataReader: interfaces.MetadataReader;\n\n constructor(containerOptions?: interfaces.ContainerOptions) {\n const options = containerOptions || {};\n options.defaultScope = options.defaultScope || BindingScopeEnum.Transient;\n // console.log(this);\n this.options = options;\n this.id = Generator.GenAutoIncrementId();\n this._bindingDictionary = new Map();\n this._metadataReader = new MetadataReader();\n }\n\n load(module: interfaces.ContainerModule) {\n const getHelpers = this._getContainerModuleHelpersFactory();\n\n const containerModuleHelpers = getHelpers(module.id);\n\n module.registry(\n containerModuleHelpers.bindFunction as interfaces.Bind,\n containerModuleHelpers.unbindFunction,\n containerModuleHelpers.isboundFunction,\n containerModuleHelpers.rebindFunction as interfaces.Rebind\n );\n }\n\n get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false);\n\n return this._get<T>(getArgs) as T;\n }\n\n getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T[] {\n const getArgs = this._getAllArgs(serviceIdentifier);\n\n return this._get<T>(getArgs) as T[];\n }\n\n getTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);\n\n return this._get<T>(getArgs) as T;\n }\n\n getNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T {\n return this.getTagged<T>(serviceIdentifier, NAMED_TAG, named);\n }\n\n isBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean {\n return this._bindingDictionary.has(serviceIdentifier);\n }\n\n // Registers a type binding\n bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n const scope = this.options.defaultScope;\n const binding = new Binding<T>(serviceIdentifier, scope);\n const list = this._bindingDictionary.get(serviceIdentifier) || [];\n list.push(binding);\n this._bindingDictionary.set(serviceIdentifier, list);\n return new BindingToSyntax<T>(binding);\n }\n\n unbind(serviceIdentifier: interfaces.ServiceIdentifier): void {\n this._bindingDictionary.delete(serviceIdentifier);\n }\n\n rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n this.unbind(serviceIdentifier);\n return this.bind(serviceIdentifier);\n }\n\n private _getContainerModuleHelpersFactory() {\n const setModuleId = (\n bindingToSyntax: interfaces.BindingToSyntax<unknown>,\n moduleId: interfaces.ContainerModuleBase['id']\n ) => {\n // TODO: Implement an internal type `_BindingToSyntax<T>` wherein this member\n // can be public. Let `BindingToSyntax<T>` be the presentational type that\n // depends on it, and does not expose this member as public.\n (\n bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } }\n )._binding.moduleId = moduleId;\n };\n\n const getBindFunction =\n <T>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.bind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n\n const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.unbind(serviceIdentifier);\n };\n\n const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return null as any;\n // return this.unbindAsync(serviceIdentifier);\n };\n\n const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.isBound(serviceIdentifier);\n };\n\n const getRebindFunction =\n <T = unknown>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.rebind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n return (mId: interfaces.ContainerModuleBase['id']) => ({\n bindFunction: getBindFunction(mId),\n isboundFunction: getIsboundFunction(),\n rebindFunction: getRebindFunction(mId),\n unbindFunction: getUnbindFunction(),\n unbindAsyncFunction: getUnbindAsyncFunction()\n });\n }\n\n private _getNotAllArgs<T>(\n serviceIdentifier: interfaces.ServiceIdentifier<T>,\n isMultiInject: boolean,\n key?: string | number | symbol | undefined,\n value?: unknown\n ): any {\n return {\n avoidConstraints: false,\n isMultiInject,\n serviceIdentifier,\n key,\n value\n };\n }\n\n private _getAllArgs<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): any {\n return {\n avoidConstraints: true,\n isMultiInject: true,\n serviceIdentifier\n };\n }\n\n private _get<T>(getArgs: GetArgs<T>): T | T[] {\n const result: T[] = [];\n const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => {\n return b.constraint(getArgs as any);\n }) as Binding<T>[];\n bindings.forEach(binding => {\n result.push(this._resolveFromBinding<T>(binding));\n });\n\n return !getArgs.isMultiInject && result.length === 1 ? result[0] : result;\n }\n\n private _getChildRequest(binding: Binding<unknown>) {\n const constr = binding.implementationType;\n const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr as any);\n const keys = Object.keys(userGeneratedMetadata);\n const arr = [];\n for (let i = 0; i < keys.length; i++) {\n const constructorArgsMetadata = userGeneratedMetadata[i];\n const targetMetadataMap = {};\n constructorArgsMetadata.forEach(md => {\n targetMetadataMap[md.key] = md.value;\n });\n const metadata = {\n inject: targetMetadataMap[INJECT_TAG],\n multiInject: targetMetadataMap[MULTI_INJECT_TAG]\n };\n const injectIdentifier = metadata.inject || metadata.multiInject;\n const target = {\n serviceIdentifier: injectIdentifier,\n constructorArgsMetadata\n };\n const bindings = this._bindingDictionary.get(injectIdentifier).filter(b => {\n return b.constraint(target as any);\n });\n const request = {\n injectIdentifier,\n metadata: constructorArgsMetadata,\n bindings\n };\n\n arr.push(request);\n }\n\n return arr;\n }\n\n private _resolveFromBinding<T>(binding: Binding<T>): T {\n const result = this._getResolvedFromBinding<T>(binding);\n\n this._saveToScope(binding, result);\n\n return result;\n }\n\n private _getResolvedFromBinding<T>(binding: Binding<T>) {\n let result: T;\n switch (binding.type) {\n case BindingTypeEnum.ConstantValue:\n case BindingTypeEnum.Function:\n result = binding.cache as T;\n break;\n case BindingTypeEnum.Instance:\n result = this._resolveInstance<T>(binding, binding.implementationType as interfaces.Newable<T>);\n break;\n default:\n result = binding.dynamicValue({ container: this } as any);\n }\n\n return result;\n }\n\n private _resolveInstance<T>(binding: Binding<T>, constr: interfaces.Newable<T>): T {\n if (binding.activated) {\n return binding.cache;\n }\n\n const childRequests = this._getChildRequest(binding);\n return this._createInstance(constr, childRequests);\n }\n\n private _createInstance<T>(constr: interfaces.Newable<T>, childRequests: IChildRequest[]) {\n if (childRequests.length) {\n const resolved = this._resolveRequests(childRequests);\n const obj = new constr(...resolved);\n return obj;\n }\n const obj = new constr();\n return obj;\n }\n\n private _resolveRequests(childRequests: IChildRequest[]): any[] {\n return childRequests.map(request => {\n return request.bindings.length > 1\n ? request.bindings.map(binding => this._resolveFromBinding(binding))\n : this._resolveFromBinding(request.bindings[0]);\n });\n }\n\n private _saveToScope(binding: Binding<unknown>, result: any) {\n if (binding.scope === BindingScopeEnum.Singleton) {\n binding.cache = result;\n binding.activated = true;\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/common/inversify/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,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,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBACpE,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,OAAyB,EAAE,MAAW;QACzD,IAAI,OAAO,CAAC,KAAK,KAAK,gBAAgB,CAAC,SAAS,EAAE;YAChD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;CACF","file":"container.js","sourcesContent":["import { Generator } from '../generator';\nimport { Binding } from './binding';\nimport type { interfaces } from './interfaces';\nimport { BindingScopeEnum, BindingTypeEnum } from './literal_types';\nimport { Metadata } from './meta-data';\nimport { INJECT_TAG, MULTI_INJECT_TAG, NAMED_TAG } from './metadata_keys';\nimport { MetadataReader } from './metadata_reader';\nimport { BindingToSyntax } from './syntax/binding_to_syntax';\n\ninterface IChildRequest {\n injectIdentifier: any;\n metadata: interfaces.Metadata<unknown>[];\n bindings: Binding<unknown>[];\n}\n\ninterface GetArgs<T> {\n avoidConstraints: boolean;\n isMultiInject: boolean;\n serviceIdentifier: interfaces.ServiceIdentifier<T>;\n key: string | symbol;\n value: any;\n}\n\nexport class Container {\n id: number;\n readonly options: interfaces.ContainerOptions;\n private _bindingDictionary: Map<any, Binding<unknown>[]>;\n private _metadataReader: interfaces.MetadataReader;\n\n constructor(containerOptions?: interfaces.ContainerOptions) {\n const options = containerOptions || {};\n options.defaultScope = options.defaultScope || BindingScopeEnum.Transient;\n // console.log(this);\n this.options = options;\n this.id = Generator.GenAutoIncrementId();\n this._bindingDictionary = new Map();\n this._metadataReader = new MetadataReader();\n }\n\n load(module: interfaces.ContainerModule) {\n const getHelpers = this._getContainerModuleHelpersFactory();\n\n const containerModuleHelpers = getHelpers(module.id);\n\n module.registry(\n containerModuleHelpers.bindFunction as interfaces.Bind,\n containerModuleHelpers.unbindFunction,\n containerModuleHelpers.isboundFunction,\n containerModuleHelpers.rebindFunction as interfaces.Rebind\n );\n }\n\n get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false);\n\n return this._get<T>(getArgs) as T;\n }\n\n getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T[] {\n const getArgs = this._getAllArgs(serviceIdentifier);\n\n return this._get<T>(getArgs) as T[];\n }\n\n getTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);\n\n return this._get<T>(getArgs) as T;\n }\n\n getNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T {\n return this.getTagged<T>(serviceIdentifier, NAMED_TAG, named);\n }\n\n isBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean {\n return this._bindingDictionary.has(serviceIdentifier);\n }\n\n // Registers a type binding\n bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n const scope = this.options.defaultScope;\n const binding = new Binding<T>(serviceIdentifier, scope);\n const list = this._bindingDictionary.get(serviceIdentifier) || [];\n list.push(binding);\n this._bindingDictionary.set(serviceIdentifier, list);\n return new BindingToSyntax<T>(binding);\n }\n\n unbind(serviceIdentifier: interfaces.ServiceIdentifier): void {\n this._bindingDictionary.delete(serviceIdentifier);\n }\n\n rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n this.unbind(serviceIdentifier);\n return this.bind(serviceIdentifier);\n }\n\n private _getContainerModuleHelpersFactory() {\n const setModuleId = (\n bindingToSyntax: interfaces.BindingToSyntax<unknown>,\n moduleId: interfaces.ContainerModuleBase['id']\n ) => {\n // TODO: Implement an internal type `_BindingToSyntax<T>` wherein this member\n // can be public. Let `BindingToSyntax<T>` be the presentational type that\n // depends on it, and does not expose this member as public.\n (\n bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } }\n )._binding.moduleId = moduleId;\n };\n\n const getBindFunction =\n <T>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.bind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n\n const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.unbind(serviceIdentifier);\n };\n\n const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return null as any;\n // return this.unbindAsync(serviceIdentifier);\n };\n\n const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.isBound(serviceIdentifier);\n };\n\n const getRebindFunction =\n <T = unknown>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.rebind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n return (mId: interfaces.ContainerModuleBase['id']) => ({\n bindFunction: getBindFunction(mId),\n isboundFunction: getIsboundFunction(),\n rebindFunction: getRebindFunction(mId),\n unbindFunction: getUnbindFunction(),\n unbindAsyncFunction: getUnbindAsyncFunction()\n });\n }\n\n private _getNotAllArgs<T>(\n serviceIdentifier: interfaces.ServiceIdentifier<T>,\n isMultiInject: boolean,\n key?: string | number | symbol | undefined,\n value?: unknown\n ): any {\n return {\n avoidConstraints: false,\n isMultiInject,\n serviceIdentifier,\n key,\n value\n };\n }\n\n private _getAllArgs<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): any {\n return {\n avoidConstraints: true,\n isMultiInject: true,\n serviceIdentifier\n };\n }\n\n private _get<T>(getArgs: GetArgs<T>): T | T[] {\n const result: T[] = [];\n const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => {\n return b.constraint(getArgs as any);\n }) as Binding<T>[];\n bindings.forEach(binding => {\n result.push(this._resolveFromBinding<T>(binding));\n });\n\n return !getArgs.isMultiInject && result.length === 1 ? result[0] : result;\n }\n\n private _getChildRequest(binding: Binding<unknown>) {\n const constr = binding.implementationType;\n const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr as any);\n const keys = Object.keys(userGeneratedMetadata);\n const arr = [];\n for (let i = 0; i < keys.length; i++) {\n const constructorArgsMetadata = userGeneratedMetadata[i];\n const targetMetadataMap = {};\n constructorArgsMetadata.forEach(md => {\n targetMetadataMap[md.key] = md.value;\n });\n const metadata = {\n inject: targetMetadataMap[INJECT_TAG],\n multiInject: targetMetadataMap[MULTI_INJECT_TAG]\n };\n const injectIdentifier = metadata.inject || metadata.multiInject;\n const target = {\n serviceIdentifier: injectIdentifier,\n constructorArgsMetadata\n };\n const bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter(b => {\n return b.constraint(target as any);\n });\n if (bindings.length) {\n const request = {\n injectIdentifier,\n metadata: constructorArgsMetadata,\n bindings: bindings\n };\n\n arr.push(request);\n }\n }\n\n return arr;\n }\n\n private _resolveFromBinding<T>(binding: Binding<T>): T {\n const result = this._getResolvedFromBinding<T>(binding);\n\n this._saveToScope(binding, result);\n\n return result;\n }\n\n private _getResolvedFromBinding<T>(binding: Binding<T>) {\n let result: T;\n switch (binding.type) {\n case BindingTypeEnum.ConstantValue:\n case BindingTypeEnum.Function:\n result = binding.cache as T;\n break;\n case BindingTypeEnum.Instance:\n result = this._resolveInstance<T>(binding, binding.implementationType as interfaces.Newable<T>);\n break;\n default:\n result = binding.dynamicValue({ container: this } as any);\n }\n\n return result;\n }\n\n private _resolveInstance<T>(binding: Binding<T>, constr: interfaces.Newable<T>): T {\n if (binding.activated) {\n return binding.cache;\n }\n\n const childRequests = this._getChildRequest(binding);\n return this._createInstance(constr, childRequests);\n }\n\n private _createInstance<T>(constr: interfaces.Newable<T>, childRequests: IChildRequest[]) {\n if (childRequests.length) {\n const resolved = this._resolveRequests(childRequests);\n const obj = new constr(...resolved);\n return obj;\n }\n const obj = new constr();\n return obj;\n }\n\n private _resolveRequests(childRequests: IChildRequest[]): any[] {\n return childRequests.map(request => {\n return request.bindings.length > 1\n ? request.bindings.map(binding => this._resolveFromBinding(binding))\n : this._resolveFromBinding(request.bindings[0]);\n });\n }\n\n private _saveToScope(binding: Binding<unknown>, result: any) {\n if (binding.scope === BindingScopeEnum.Singleton) {\n binding.cache = result;\n binding.activated = true;\n }\n }\n}\n"]}
@@ -30,11 +30,21 @@ let ATextMeasure = class {
30
30
  }
31
31
  compatibleMetrics(metrics, options) {
32
32
  if (null == metrics.actualBoundingBoxAscent || null == metrics.actualBoundingBoxDescent || null == metrics.fontBoundingBoxAscent || null == metrics.fontBoundingBoxDescent) {
33
+ metrics = {
34
+ width: metrics.width
35
+ };
33
36
  const {ascent: ascent, descent: descent} = this.measureTextBoundADscentEstimate(options);
34
37
  metrics.actualBoundingBoxAscent = ascent, metrics.actualBoundingBoxDescent = descent,
35
38
  metrics.fontBoundingBoxAscent = ascent, metrics.fontBoundingBoxDescent = descent;
36
39
  }
37
40
  if (null == metrics.actualBoundingBoxLeft || null == metrics.actualBoundingBoxRight) {
41
+ metrics = {
42
+ width: metrics.width,
43
+ actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
44
+ actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
45
+ fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
46
+ fontBoundingBoxDescent: metrics.fontBoundingBoxDescent
47
+ };
38
48
  const {left: left, right: right} = this.measureTextBoundLeftRightEstimate(options);
39
49
  metrics.actualBoundingBoxLeft = left, metrics.actualBoundingBoxRight = right;
40
50
  }