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

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 +23 -6
  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 +153 -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 +20 -5
  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 +2 -2
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;
@@ -18845,6 +18872,9 @@ class RichText extends Graphic {
18845
18872
  application.graphicService.updateHTMLTextAABBBounds(attribute, richtextTheme, aabbBounds);
18846
18873
  }
18847
18874
  application.graphicService.transformAABBBounds(attribute, aabbBounds, richtextTheme, false, this);
18875
+ if (aabbBounds.width() === 0 && aabbBounds.height() === 0) {
18876
+ aabbBounds.clear();
18877
+ }
18848
18878
  return aabbBounds;
18849
18879
  }
18850
18880
  needUpdateTags(keys) {
@@ -20105,7 +20135,7 @@ class DefaultBaseBackgroundRenderContribution {
20105
20135
  }
20106
20136
  drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, options) {
20107
20137
  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;
20138
+ 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
20139
  if (!background) {
20110
20140
  return;
20111
20141
  }
@@ -20128,6 +20158,7 @@ class DefaultBaseBackgroundRenderContribution {
20128
20158
  this.doDrawImage(context, res.data, b, {
20129
20159
  backgroundMode,
20130
20160
  backgroundFit,
20161
+ backgroundKeepAspectRatio,
20131
20162
  backgroundScale,
20132
20163
  backgroundOffsetX,
20133
20164
  backgroundOffsetY
@@ -20147,14 +20178,20 @@ class DefaultBaseBackgroundRenderContribution {
20147
20178
  }
20148
20179
  }
20149
20180
  doDrawImage(context, data, b, params) {
20150
- const { backgroundMode, backgroundFit, backgroundScale = 1, backgroundOffsetX = 0, backgroundOffsetY = 0 } = params;
20181
+ const { backgroundMode, backgroundFit, backgroundKeepAspectRatio, backgroundScale = 1, backgroundOffsetX = 0, backgroundOffsetY = 0 } = params;
20151
20182
  const targetW = b.width();
20152
20183
  const targetH = b.height();
20153
20184
  let w = targetW;
20154
20185
  let h = targetH;
20155
20186
  if (backgroundMode === 'no-repeat') {
20156
20187
  if (backgroundFit) {
20157
- context.drawImage(data, b.x1, b.y1, b.width(), b.height());
20188
+ if (!backgroundKeepAspectRatio) {
20189
+ context.drawImage(data, b.x1, b.y1, b.width(), b.height());
20190
+ }
20191
+ else {
20192
+ const maxScale = Math.max(targetW / data.width, targetH / data.height);
20193
+ context.drawImage(data, b.x1 + backgroundOffsetX, b.y1 + backgroundOffsetY, data.width * maxScale * backgroundScale, data.height * maxScale * backgroundScale);
20194
+ }
20158
20195
  }
20159
20196
  else {
20160
20197
  const resW = data.width * backgroundScale;
@@ -20523,7 +20560,7 @@ class DefaultGroupBackgroundRenderContribution extends DefaultBaseBackgroundRend
20523
20560
  this.time = BaseRenderContributionTime.beforeFillStroke;
20524
20561
  }
20525
20562
  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;
20563
+ const { background, backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundKeepAspectRatio = graphicAttribute.backgroundKeepAspectRatio, backgroundScale = graphicAttribute.backgroundScale, backgroundOffsetX = graphicAttribute.backgroundOffsetX, backgroundOffsetY = graphicAttribute.backgroundOffsetY } = graphic.attribute;
20527
20564
  if (!background) {
20528
20565
  return;
20529
20566
  }
@@ -20538,6 +20575,7 @@ class DefaultGroupBackgroundRenderContribution extends DefaultBaseBackgroundRend
20538
20575
  this.doDrawImage(context, res.data, b, {
20539
20576
  backgroundMode,
20540
20577
  backgroundFit,
20578
+ backgroundKeepAspectRatio,
20541
20579
  backgroundScale,
20542
20580
  backgroundOffsetX,
20543
20581
  backgroundOffsetY
@@ -22441,7 +22479,7 @@ class DefaultTextBackgroundRenderContribution extends DefaultBaseBackgroundRende
22441
22479
  }
22442
22480
  drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb) {
22443
22481
  var _a, _c, _d, _e, _f, _g, _h, _j, _k, _l;
22444
- const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit } = graphic.attribute;
22482
+ const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit, backgroundKeepAspectRatio = graphicAttribute.backgroundKeepAspectRatio } = graphic.attribute;
22445
22483
  let { background } = graphic.attribute;
22446
22484
  if (!background) {
22447
22485
  return;
@@ -22498,7 +22536,7 @@ class DefaultTextBackgroundRenderContribution extends DefaultBaseBackgroundRende
22498
22536
  context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true);
22499
22537
  }
22500
22538
  context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);
22501
- this.doDrawImage(context, res.data, b, { backgroundMode, backgroundFit });
22539
+ this.doDrawImage(context, res.data, b, { backgroundMode, backgroundFit, backgroundKeepAspectRatio });
22502
22540
  context.highPerformanceRestore();
22503
22541
  context.setTransformForCurrent();
22504
22542
  }
@@ -24096,6 +24134,9 @@ let DefaultDrawContribution = class DefaultDrawContribution {
24096
24134
  this.backupDirtyBounds = new Bounds();
24097
24135
  this.global = application.global;
24098
24136
  this.layerService = application.layerService;
24137
+ if (!isArray(this.contributions)) {
24138
+ this.contributions = [this.contributions];
24139
+ }
24099
24140
  this.init();
24100
24141
  }
24101
24142
  init() {
@@ -27040,8 +27081,9 @@ class EditModule {
27040
27081
  application.global.addEventListener('keydown', this.handleKeyDown);
27041
27082
  }
27042
27083
  parseCompositionStr(configIdx) {
27084
+ var _a;
27043
27085
  const { textConfig = [] } = this.currRt.attribute;
27044
- const lastConfig = textConfig[configIdx];
27086
+ const lastConfig = (_a = textConfig[configIdx]) !== null && _a !== void 0 ? _a : {};
27045
27087
  textConfig.splice(configIdx, 1);
27046
27088
  const text = lastConfig.text;
27047
27089
  const textList = text ? Array.from(text.toString()) : [];
@@ -27121,18 +27163,23 @@ class Selection {
27121
27163
  }
27122
27164
  return (_a = config[Math.min(idx, config.length - 1)][key]) !== null && _a !== void 0 ? _a : this.rt.attribute[key];
27123
27165
  }
27124
- getFormat(key) {
27125
- return this.getAllFormat(key)[0];
27166
+ getFormat(key, supportOutAttr = false) {
27167
+ return this.getAllFormat(key, supportOutAttr)[0];
27126
27168
  }
27127
- getAllFormat(key) {
27169
+ getAllFormat(key, supportOutAttr = false) {
27170
+ var _a, _b, _c, _d;
27128
27171
  const valSet = new Set();
27129
27172
  const minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx);
27130
27173
  const maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
27131
27174
  if (minCursorIdx === maxCursorIdx) {
27132
- return [this._getFormat(key, minCursorIdx)];
27175
+ return supportOutAttr
27176
+ ? [(_a = this._getFormat(key, minCursorIdx)) !== null && _a !== void 0 ? _a : ((_b = this.rt) === null || _b === void 0 ? void 0 : _b.attribute)[key]]
27177
+ : [this._getFormat(key, minCursorIdx)];
27133
27178
  }
27134
27179
  for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
27135
- const val = this._getFormat(key, i);
27180
+ const val = supportOutAttr
27181
+ ? (_c = this._getFormat(key, i)) !== null && _c !== void 0 ? _c : ((_d = this.rt) === null || _d === void 0 ? void 0 : _d.attribute)[key]
27182
+ : this._getFormat(key, i);
27136
27183
  val && valSet.add(val);
27137
27184
  }
27138
27185
  return Array.from(valSet.values());
@@ -27197,10 +27244,10 @@ class RichTextEditPlugin {
27197
27244
  if (this.copyToClipboard(e)) {
27198
27245
  return;
27199
27246
  }
27200
- if (this.fullSelection(e)) {
27247
+ if (this.fullSelectionKeyHandler(e)) {
27201
27248
  return;
27202
27249
  }
27203
- if (this.directKey(e)) {
27250
+ if (this.directKeyHandler(e)) {
27204
27251
  return;
27205
27252
  }
27206
27253
  };
@@ -27238,7 +27285,7 @@ class RichTextEditPlugin {
27238
27285
  }
27239
27286
  this.currRt = e.target;
27240
27287
  this.handleEnter(e);
27241
- e.target.once('pointerleave', this.handleLeave);
27288
+ e.target.once('pointerleave', this.handleLeave, { capture: true });
27242
27289
  this.tryShowSelection(e, false);
27243
27290
  };
27244
27291
  this.handleEnter = (e) => {
@@ -27332,11 +27379,11 @@ class RichTextEditPlugin {
27332
27379
  activate(context) {
27333
27380
  this.pluginService = context;
27334
27381
  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);
27382
+ context.stage.on('pointermove', this.handleMove, { capture: true });
27383
+ context.stage.on('pointerdown', this.handlePointerDown, { capture: true });
27384
+ context.stage.on('pointerup', this.handlePointerUp, { capture: true });
27385
+ context.stage.on('pointerleave', this.handlePointerUp, { capture: true });
27386
+ context.stage.on('dblclick', this.handleDBLClick, { capture: true });
27340
27387
  application.global.addEventListener('keydown', this.handleKeyDown);
27341
27388
  this.editModule.onInput(this.handleInput);
27342
27389
  this.editModule.onChange(this.handleChange);
@@ -27380,26 +27427,32 @@ class RichTextEditPlugin {
27380
27427
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt);
27381
27428
  this._tryShowSelection(pos, cache);
27382
27429
  }
27383
- fullSelection(e) {
27430
+ fullSelection() {
27431
+ const currRt = this.currRt;
27432
+ if (!currRt) {
27433
+ return;
27434
+ }
27435
+ const cache = currRt.getFrameCache();
27436
+ if (!cache) {
27437
+ return;
27438
+ }
27439
+ const { lines } = cache;
27440
+ if (!(lines.length && lines[0].paragraphs.length)) {
27441
+ return;
27442
+ }
27443
+ const totalCursorCount = lines.reduce((total, line) => total + line.paragraphs.length, 0) - 1;
27444
+ this.selectionRange(-0.1, totalCursorCount + 0.1);
27445
+ }
27446
+ fullSelectionKeyHandler(e) {
27384
27447
  if ((application.global.isMacOS() && e.metaKey && e.key === 'a') ||
27385
27448
  (!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);
27449
+ this.fullSelection();
27397
27450
  e.preventDefault();
27398
27451
  return true;
27399
27452
  }
27400
27453
  return false;
27401
27454
  }
27402
- directKey(e) {
27455
+ directKeyHandler(e) {
27403
27456
  if (!(e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'ArrowLeft' || e.key === 'ArrowRight')) {
27404
27457
  return false;
27405
27458
  }
@@ -27497,7 +27550,7 @@ class RichTextEditPlugin {
27497
27550
  const placeholder = shadowRoot.getElementsByType('richtext')[0];
27498
27551
  placeholder && shadowRoot.removeChild(placeholder);
27499
27552
  }
27500
- const { textConfig, editOptions } = this.currRt.attribute;
27553
+ const { textConfig, editOptions = {} } = this.currRt.attribute;
27501
27554
  if (textConfig && textConfig.length) {
27502
27555
  return;
27503
27556
  }
@@ -27516,9 +27569,16 @@ class RichTextEditPlugin {
27516
27569
  if (placeholderFontSize) {
27517
27570
  textConfigItem.fontSize = placeholderFontSize;
27518
27571
  }
27519
- this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, angle: 0, _debug_bounds: false, textConfig: [textConfigItem] }));
27572
+ 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
27573
  shadow.add(this.shadowPlaceHolder);
27521
27574
  }
27575
+ getRichTextAABBBounds(rt) {
27576
+ const { attribute } = rt;
27577
+ if (!attribute.textConfig.length) {
27578
+ return getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), { x: attribute.x, y: attribute.y, textAlign: attribute.textAlign, boundsMode: 'accurate' }));
27579
+ }
27580
+ return rt.AABBBounds;
27581
+ }
27522
27582
  tryShowInputBounds() {
27523
27583
  if (!(this.currRt && this.focusing)) {
27524
27584
  return;
@@ -27528,19 +27588,15 @@ class RichTextEditPlugin {
27528
27588
  if (!editOptions || !boundsStrokeWhenInput) {
27529
27589
  return;
27530
27590
  }
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
- }
27591
+ const b = this.getRichTextAABBBounds(this.currRt);
27592
+ const height = b.height();
27593
+ const width = b.width();
27538
27594
  this.shadowBounds = this.shadowBounds || createRect({});
27539
27595
  this.shadowBounds.setAttributes({
27540
27596
  x: 0,
27541
27597
  y: 0,
27542
- width: b.width(),
27543
- height: h,
27598
+ width,
27599
+ height,
27544
27600
  fill: false,
27545
27601
  stroke: boundsStrokeWhenInput,
27546
27602
  lineWidth: 1,
@@ -27549,6 +27605,7 @@ class RichTextEditPlugin {
27549
27605
  const shadow = this.getShadow(this.currRt);
27550
27606
  shadow.add(this.shadowBounds);
27551
27607
  this.offsetLineBgAndShadowBounds();
27608
+ this.offsetShadowRoot();
27552
27609
  }
27553
27610
  trySyncPlaceholderToTextConfig() {
27554
27611
  if (!this.currRt) {
@@ -27558,7 +27615,7 @@ class RichTextEditPlugin {
27558
27615
  if (textConfig && textConfig.length) {
27559
27616
  return;
27560
27617
  }
27561
- if (!(editOptions && editOptions.placeholder)) {
27618
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) {
27562
27619
  return;
27563
27620
  }
27564
27621
  const { placeholder } = editOptions;
@@ -27569,13 +27626,16 @@ class RichTextEditPlugin {
27569
27626
  });
27570
27627
  }
27571
27628
  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);
27629
+ context.stage.off('pointermove', this.handleMove, { capture: true });
27630
+ context.stage.off('pointerdown', this.handlePointerDown, { capture: true });
27631
+ context.stage.off('pointerup', this.handlePointerUp, { capture: true });
27632
+ context.stage.off('pointerleave', this.handlePointerUp, { capture: true });
27633
+ context.stage.off('dblclick', this.handleDBLClick, { capture: true });
27577
27634
  application.global.addEventListener('keydown', this.handleKeyDown);
27578
27635
  }
27636
+ stopPropagation(e) {
27637
+ e.stopPropagation();
27638
+ }
27579
27639
  onFocus(e, data) {
27580
27640
  this.updateCbs && this.updateCbs.forEach(cb => cb('beforeOnfocus', this));
27581
27641
  this.deFocus(false);
@@ -27591,8 +27651,11 @@ class RichTextEditPlugin {
27591
27651
  if (!cache) {
27592
27652
  return;
27593
27653
  }
27594
- this.computeGlobalDelta(cache);
27595
- shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
27654
+ const { editOptions = {} } = this.currRt.attribute;
27655
+ if (editOptions.stopPropagation) {
27656
+ target.addEventListener('*', this.stopPropagation);
27657
+ }
27658
+ this.offsetShadowRoot(target);
27596
27659
  if (!this.editLine) {
27597
27660
  const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });
27598
27661
  this.addAnimateToLine(line);
@@ -27624,6 +27687,23 @@ class RichTextEditPlugin {
27624
27687
  this.tryShowInputBounds();
27625
27688
  this.currRt.addUpdateBoundTag();
27626
27689
  }
27690
+ offsetShadowRoot(rt) {
27691
+ rt = rt || this.currRt;
27692
+ if (!rt) {
27693
+ return;
27694
+ }
27695
+ const shadowRoot = this.getShadow(rt);
27696
+ if (!shadowRoot) {
27697
+ return;
27698
+ }
27699
+ const cache = rt.getFrameCache();
27700
+ if (!cache) {
27701
+ return;
27702
+ }
27703
+ this.computeGlobalDelta(cache);
27704
+ shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
27705
+ this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({ dx: -this.deltaX, dy: -this.deltaY });
27706
+ }
27627
27707
  offsetLineBgAndShadowBounds() {
27628
27708
  const rt = this.currRt;
27629
27709
  const { textBaseline } = rt.attribute;
@@ -27654,6 +27734,10 @@ class RichTextEditPlugin {
27654
27734
  if (!target) {
27655
27735
  return;
27656
27736
  }
27737
+ const { editOptions = {} } = target.attribute;
27738
+ if (editOptions.stopPropagation) {
27739
+ target.removeEventListener('*', this.stopPropagation);
27740
+ }
27657
27741
  if (trulyDeFocus) {
27658
27742
  this.trySyncPlaceholderToTextConfig();
27659
27743
  target.detachShadow();
@@ -27891,6 +27975,9 @@ class RichTextEditPlugin {
27891
27975
  computeGlobalDelta(cache) {
27892
27976
  this.deltaX = 0;
27893
27977
  this.deltaY = 0;
27978
+ if (cache.lines.length === 0 && this.shadowPlaceHolder) {
27979
+ cache = this.shadowPlaceHolder.getFrameCache();
27980
+ }
27894
27981
  const height = cache.height;
27895
27982
  const actualHeight = cache.actualHeight;
27896
27983
  const width = cache.lines.reduce((w, item) => Math.max(w, item.actualWidth), 0);
@@ -27941,6 +28028,7 @@ class RichTextEditPlugin {
27941
28028
  out.x += left;
27942
28029
  out.y += top;
27943
28030
  this.offsetLineBgAndShadowBounds();
28031
+ this.offsetShadowRoot();
27944
28032
  this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
27945
28033
  }
27946
28034
  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,CA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AAI,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,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,CAAC;QACzC,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,MAAkC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,iCAAiC,EAAE,CAAC;QAE5D,MAAM,sBAAsB,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAErD,MAAM,CAAC,QAAQ,CACb,sBAAsB,CAAC,YAA+B,EACtD,sBAAsB,CAAC,cAAc,EACrC,sBAAsB,CAAC,eAAe,EACtC,sBAAsB,CAAC,cAAmC,CAC3D,CAAC;IACJ,CAAC;IAED,GAAG,CAAI,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AAC,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 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
  }