@hailin-zheng/editor-core 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controls/Canvas.d.ts +2 -5
- package/controls/Node.d.ts +15 -0
- package/controls/Text.d.ts +3 -2
- package/controls/ViewPaint.d.ts +9 -0
- package/index-cjs.js +151 -886
- package/index-cjs.js.map +1 -1
- package/index.js +150 -886
- package/index.js.map +1 -1
- package/med_editor/framework/paragraph-arrange.d.ts +4 -0
- package/med_editor/texteditor.d.ts +2 -4
- package/package.json +1 -1
- package/timeline/TimeLineControl.d.ts +46 -0
- package/timeline/TimeValueGridControl.d.ts +96 -0
- package/timeline/TimelineConfig.d.ts +67 -0
- package/timeline/TimelineScrollbar.d.ts +25 -0
- package/timeline/TimelineStatus.d.ts +61 -0
- package/timeline/TimelineTick.d.ts +63 -0
- package/timeline/example.d.ts +2 -0
- package/timeline/timezone.d.ts +0 -2
package/index-cjs.js
CHANGED
@@ -6,6 +6,7 @@ var nanoid = require('nanoid');
|
|
6
6
|
var moment = require('moment');
|
7
7
|
var acor = require('acorn');
|
8
8
|
var astring = require('astring');
|
9
|
+
var estraverse = require('estraverse');
|
9
10
|
var bwipjs = require('bwip-js');
|
10
11
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
@@ -30,6 +31,7 @@ function _interopNamespace(e) {
|
|
30
31
|
|
31
32
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
32
33
|
var acor__namespace = /*#__PURE__*/_interopNamespace(acor);
|
34
|
+
var estraverse__namespace = /*#__PURE__*/_interopNamespace(estraverse);
|
33
35
|
var bwipjs__default = /*#__PURE__*/_interopDefaultLegacy(bwipjs);
|
34
36
|
|
35
37
|
/**
|
@@ -2708,814 +2710,9 @@ class DataDecorateRenderObject extends LeafRenderObject {
|
|
2708
2710
|
}
|
2709
2711
|
}
|
2710
2712
|
|
2711
|
-
/*
|
2712
|
-
Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
|
2713
|
-
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
2714
|
-
|
2715
|
-
Redistribution and use in source and binary forms, with or without
|
2716
|
-
modification, are permitted provided that the following conditions are met:
|
2717
|
-
|
2718
|
-
* Redistributions of source code must retain the above copyright
|
2719
|
-
notice, this list of conditions and the following disclaimer.
|
2720
|
-
* Redistributions in binary form must reproduce the above copyright
|
2721
|
-
notice, this list of conditions and the following disclaimer in the
|
2722
|
-
documentation and/or other materials provided with the distribution.
|
2723
|
-
|
2724
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
2725
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
2726
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2727
|
-
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
2728
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2729
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2730
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
2731
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2732
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
2733
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2734
|
-
*/
|
2735
|
-
/*jslint vars:false, bitwise:true*/
|
2736
|
-
/*jshint indent:4*/
|
2737
|
-
/*global exports:true*/
|
2738
|
-
(function clone(exports) {
|
2739
|
-
|
2740
|
-
var Syntax,
|
2741
|
-
VisitorOption,
|
2742
|
-
VisitorKeys,
|
2743
|
-
BREAK,
|
2744
|
-
SKIP,
|
2745
|
-
REMOVE;
|
2746
|
-
|
2747
|
-
function deepCopy(obj) {
|
2748
|
-
var ret = {}, key, val;
|
2749
|
-
for (key in obj) {
|
2750
|
-
if (obj.hasOwnProperty(key)) {
|
2751
|
-
val = obj[key];
|
2752
|
-
if (typeof val === 'object' && val !== null) {
|
2753
|
-
ret[key] = deepCopy(val);
|
2754
|
-
} else {
|
2755
|
-
ret[key] = val;
|
2756
|
-
}
|
2757
|
-
}
|
2758
|
-
}
|
2759
|
-
return ret;
|
2760
|
-
}
|
2761
|
-
|
2762
|
-
// based on LLVM libc++ upper_bound / lower_bound
|
2763
|
-
// MIT License
|
2764
|
-
|
2765
|
-
function upperBound(array, func) {
|
2766
|
-
var diff, len, i, current;
|
2767
|
-
|
2768
|
-
len = array.length;
|
2769
|
-
i = 0;
|
2770
|
-
|
2771
|
-
while (len) {
|
2772
|
-
diff = len >>> 1;
|
2773
|
-
current = i + diff;
|
2774
|
-
if (func(array[current])) {
|
2775
|
-
len = diff;
|
2776
|
-
} else {
|
2777
|
-
i = current + 1;
|
2778
|
-
len -= diff + 1;
|
2779
|
-
}
|
2780
|
-
}
|
2781
|
-
return i;
|
2782
|
-
}
|
2783
|
-
|
2784
|
-
Syntax = {
|
2785
|
-
AssignmentExpression: 'AssignmentExpression',
|
2786
|
-
AssignmentPattern: 'AssignmentPattern',
|
2787
|
-
ArrayExpression: 'ArrayExpression',
|
2788
|
-
ArrayPattern: 'ArrayPattern',
|
2789
|
-
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
2790
|
-
AwaitExpression: 'AwaitExpression', // CAUTION: It's deferred to ES7.
|
2791
|
-
BlockStatement: 'BlockStatement',
|
2792
|
-
BinaryExpression: 'BinaryExpression',
|
2793
|
-
BreakStatement: 'BreakStatement',
|
2794
|
-
CallExpression: 'CallExpression',
|
2795
|
-
CatchClause: 'CatchClause',
|
2796
|
-
ChainExpression: 'ChainExpression',
|
2797
|
-
ClassBody: 'ClassBody',
|
2798
|
-
ClassDeclaration: 'ClassDeclaration',
|
2799
|
-
ClassExpression: 'ClassExpression',
|
2800
|
-
ComprehensionBlock: 'ComprehensionBlock', // CAUTION: It's deferred to ES7.
|
2801
|
-
ComprehensionExpression: 'ComprehensionExpression', // CAUTION: It's deferred to ES7.
|
2802
|
-
ConditionalExpression: 'ConditionalExpression',
|
2803
|
-
ContinueStatement: 'ContinueStatement',
|
2804
|
-
DebuggerStatement: 'DebuggerStatement',
|
2805
|
-
DirectiveStatement: 'DirectiveStatement',
|
2806
|
-
DoWhileStatement: 'DoWhileStatement',
|
2807
|
-
EmptyStatement: 'EmptyStatement',
|
2808
|
-
ExportAllDeclaration: 'ExportAllDeclaration',
|
2809
|
-
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
2810
|
-
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
2811
|
-
ExportSpecifier: 'ExportSpecifier',
|
2812
|
-
ExpressionStatement: 'ExpressionStatement',
|
2813
|
-
ForStatement: 'ForStatement',
|
2814
|
-
ForInStatement: 'ForInStatement',
|
2815
|
-
ForOfStatement: 'ForOfStatement',
|
2816
|
-
FunctionDeclaration: 'FunctionDeclaration',
|
2817
|
-
FunctionExpression: 'FunctionExpression',
|
2818
|
-
GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
|
2819
|
-
Identifier: 'Identifier',
|
2820
|
-
IfStatement: 'IfStatement',
|
2821
|
-
ImportExpression: 'ImportExpression',
|
2822
|
-
ImportDeclaration: 'ImportDeclaration',
|
2823
|
-
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
2824
|
-
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
2825
|
-
ImportSpecifier: 'ImportSpecifier',
|
2826
|
-
Literal: 'Literal',
|
2827
|
-
LabeledStatement: 'LabeledStatement',
|
2828
|
-
LogicalExpression: 'LogicalExpression',
|
2829
|
-
MemberExpression: 'MemberExpression',
|
2830
|
-
MetaProperty: 'MetaProperty',
|
2831
|
-
MethodDefinition: 'MethodDefinition',
|
2832
|
-
ModuleSpecifier: 'ModuleSpecifier',
|
2833
|
-
NewExpression: 'NewExpression',
|
2834
|
-
ObjectExpression: 'ObjectExpression',
|
2835
|
-
ObjectPattern: 'ObjectPattern',
|
2836
|
-
PrivateIdentifier: 'PrivateIdentifier',
|
2837
|
-
Program: 'Program',
|
2838
|
-
Property: 'Property',
|
2839
|
-
PropertyDefinition: 'PropertyDefinition',
|
2840
|
-
RestElement: 'RestElement',
|
2841
|
-
ReturnStatement: 'ReturnStatement',
|
2842
|
-
SequenceExpression: 'SequenceExpression',
|
2843
|
-
SpreadElement: 'SpreadElement',
|
2844
|
-
Super: 'Super',
|
2845
|
-
SwitchStatement: 'SwitchStatement',
|
2846
|
-
SwitchCase: 'SwitchCase',
|
2847
|
-
TaggedTemplateExpression: 'TaggedTemplateExpression',
|
2848
|
-
TemplateElement: 'TemplateElement',
|
2849
|
-
TemplateLiteral: 'TemplateLiteral',
|
2850
|
-
ThisExpression: 'ThisExpression',
|
2851
|
-
ThrowStatement: 'ThrowStatement',
|
2852
|
-
TryStatement: 'TryStatement',
|
2853
|
-
UnaryExpression: 'UnaryExpression',
|
2854
|
-
UpdateExpression: 'UpdateExpression',
|
2855
|
-
VariableDeclaration: 'VariableDeclaration',
|
2856
|
-
VariableDeclarator: 'VariableDeclarator',
|
2857
|
-
WhileStatement: 'WhileStatement',
|
2858
|
-
WithStatement: 'WithStatement',
|
2859
|
-
YieldExpression: 'YieldExpression'
|
2860
|
-
};
|
2861
|
-
|
2862
|
-
VisitorKeys = {
|
2863
|
-
AssignmentExpression: ['left', 'right'],
|
2864
|
-
AssignmentPattern: ['left', 'right'],
|
2865
|
-
ArrayExpression: ['elements'],
|
2866
|
-
ArrayPattern: ['elements'],
|
2867
|
-
ArrowFunctionExpression: ['params', 'body'],
|
2868
|
-
AwaitExpression: ['argument'], // CAUTION: It's deferred to ES7.
|
2869
|
-
BlockStatement: ['body'],
|
2870
|
-
BinaryExpression: ['left', 'right'],
|
2871
|
-
BreakStatement: ['label'],
|
2872
|
-
CallExpression: ['callee', 'arguments'],
|
2873
|
-
CatchClause: ['param', 'body'],
|
2874
|
-
ChainExpression: ['expression'],
|
2875
|
-
ClassBody: ['body'],
|
2876
|
-
ClassDeclaration: ['id', 'superClass', 'body'],
|
2877
|
-
ClassExpression: ['id', 'superClass', 'body'],
|
2878
|
-
ComprehensionBlock: ['left', 'right'], // CAUTION: It's deferred to ES7.
|
2879
|
-
ComprehensionExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
|
2880
|
-
ConditionalExpression: ['test', 'consequent', 'alternate'],
|
2881
|
-
ContinueStatement: ['label'],
|
2882
|
-
DebuggerStatement: [],
|
2883
|
-
DirectiveStatement: [],
|
2884
|
-
DoWhileStatement: ['body', 'test'],
|
2885
|
-
EmptyStatement: [],
|
2886
|
-
ExportAllDeclaration: ['source'],
|
2887
|
-
ExportDefaultDeclaration: ['declaration'],
|
2888
|
-
ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
|
2889
|
-
ExportSpecifier: ['exported', 'local'],
|
2890
|
-
ExpressionStatement: ['expression'],
|
2891
|
-
ForStatement: ['init', 'test', 'update', 'body'],
|
2892
|
-
ForInStatement: ['left', 'right', 'body'],
|
2893
|
-
ForOfStatement: ['left', 'right', 'body'],
|
2894
|
-
FunctionDeclaration: ['id', 'params', 'body'],
|
2895
|
-
FunctionExpression: ['id', 'params', 'body'],
|
2896
|
-
GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
|
2897
|
-
Identifier: [],
|
2898
|
-
IfStatement: ['test', 'consequent', 'alternate'],
|
2899
|
-
ImportExpression: ['source'],
|
2900
|
-
ImportDeclaration: ['specifiers', 'source'],
|
2901
|
-
ImportDefaultSpecifier: ['local'],
|
2902
|
-
ImportNamespaceSpecifier: ['local'],
|
2903
|
-
ImportSpecifier: ['imported', 'local'],
|
2904
|
-
Literal: [],
|
2905
|
-
LabeledStatement: ['label', 'body'],
|
2906
|
-
LogicalExpression: ['left', 'right'],
|
2907
|
-
MemberExpression: ['object', 'property'],
|
2908
|
-
MetaProperty: ['meta', 'property'],
|
2909
|
-
MethodDefinition: ['key', 'value'],
|
2910
|
-
ModuleSpecifier: [],
|
2911
|
-
NewExpression: ['callee', 'arguments'],
|
2912
|
-
ObjectExpression: ['properties'],
|
2913
|
-
ObjectPattern: ['properties'],
|
2914
|
-
PrivateIdentifier: [],
|
2915
|
-
Program: ['body'],
|
2916
|
-
Property: ['key', 'value'],
|
2917
|
-
PropertyDefinition: ['key', 'value'],
|
2918
|
-
RestElement: [ 'argument' ],
|
2919
|
-
ReturnStatement: ['argument'],
|
2920
|
-
SequenceExpression: ['expressions'],
|
2921
|
-
SpreadElement: ['argument'],
|
2922
|
-
Super: [],
|
2923
|
-
SwitchStatement: ['discriminant', 'cases'],
|
2924
|
-
SwitchCase: ['test', 'consequent'],
|
2925
|
-
TaggedTemplateExpression: ['tag', 'quasi'],
|
2926
|
-
TemplateElement: [],
|
2927
|
-
TemplateLiteral: ['quasis', 'expressions'],
|
2928
|
-
ThisExpression: [],
|
2929
|
-
ThrowStatement: ['argument'],
|
2930
|
-
TryStatement: ['block', 'handler', 'finalizer'],
|
2931
|
-
UnaryExpression: ['argument'],
|
2932
|
-
UpdateExpression: ['argument'],
|
2933
|
-
VariableDeclaration: ['declarations'],
|
2934
|
-
VariableDeclarator: ['id', 'init'],
|
2935
|
-
WhileStatement: ['test', 'body'],
|
2936
|
-
WithStatement: ['object', 'body'],
|
2937
|
-
YieldExpression: ['argument']
|
2938
|
-
};
|
2939
|
-
|
2940
|
-
// unique id
|
2941
|
-
BREAK = {};
|
2942
|
-
SKIP = {};
|
2943
|
-
REMOVE = {};
|
2944
|
-
|
2945
|
-
VisitorOption = {
|
2946
|
-
Break: BREAK,
|
2947
|
-
Skip: SKIP,
|
2948
|
-
Remove: REMOVE
|
2949
|
-
};
|
2950
|
-
|
2951
|
-
function Reference(parent, key) {
|
2952
|
-
this.parent = parent;
|
2953
|
-
this.key = key;
|
2954
|
-
}
|
2955
|
-
|
2956
|
-
Reference.prototype.replace = function replace(node) {
|
2957
|
-
this.parent[this.key] = node;
|
2958
|
-
};
|
2959
|
-
|
2960
|
-
Reference.prototype.remove = function remove() {
|
2961
|
-
if (Array.isArray(this.parent)) {
|
2962
|
-
this.parent.splice(this.key, 1);
|
2963
|
-
return true;
|
2964
|
-
} else {
|
2965
|
-
this.replace(null);
|
2966
|
-
return false;
|
2967
|
-
}
|
2968
|
-
};
|
2969
|
-
|
2970
|
-
function Element(node, path, wrap, ref) {
|
2971
|
-
this.node = node;
|
2972
|
-
this.path = path;
|
2973
|
-
this.wrap = wrap;
|
2974
|
-
this.ref = ref;
|
2975
|
-
}
|
2976
|
-
|
2977
|
-
function Controller() { }
|
2978
|
-
|
2979
|
-
// API:
|
2980
|
-
// return property path array from root to current node
|
2981
|
-
Controller.prototype.path = function path() {
|
2982
|
-
var i, iz, j, jz, result, element;
|
2983
|
-
|
2984
|
-
function addToPath(result, path) {
|
2985
|
-
if (Array.isArray(path)) {
|
2986
|
-
for (j = 0, jz = path.length; j < jz; ++j) {
|
2987
|
-
result.push(path[j]);
|
2988
|
-
}
|
2989
|
-
} else {
|
2990
|
-
result.push(path);
|
2991
|
-
}
|
2992
|
-
}
|
2993
|
-
|
2994
|
-
// root node
|
2995
|
-
if (!this.__current.path) {
|
2996
|
-
return null;
|
2997
|
-
}
|
2998
|
-
|
2999
|
-
// first node is sentinel, second node is root element
|
3000
|
-
result = [];
|
3001
|
-
for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
|
3002
|
-
element = this.__leavelist[i];
|
3003
|
-
addToPath(result, element.path);
|
3004
|
-
}
|
3005
|
-
addToPath(result, this.__current.path);
|
3006
|
-
return result;
|
3007
|
-
};
|
3008
|
-
|
3009
|
-
// API:
|
3010
|
-
// return type of current node
|
3011
|
-
Controller.prototype.type = function () {
|
3012
|
-
var node = this.current();
|
3013
|
-
return node.type || this.__current.wrap;
|
3014
|
-
};
|
3015
|
-
|
3016
|
-
// API:
|
3017
|
-
// return array of parent elements
|
3018
|
-
Controller.prototype.parents = function parents() {
|
3019
|
-
var i, iz, result;
|
3020
|
-
|
3021
|
-
// first node is sentinel
|
3022
|
-
result = [];
|
3023
|
-
for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
|
3024
|
-
result.push(this.__leavelist[i].node);
|
3025
|
-
}
|
3026
|
-
|
3027
|
-
return result;
|
3028
|
-
};
|
3029
|
-
|
3030
|
-
// API:
|
3031
|
-
// return current node
|
3032
|
-
Controller.prototype.current = function current() {
|
3033
|
-
return this.__current.node;
|
3034
|
-
};
|
3035
|
-
|
3036
|
-
Controller.prototype.__execute = function __execute(callback, element) {
|
3037
|
-
var previous, result;
|
3038
|
-
|
3039
|
-
result = undefined;
|
3040
|
-
|
3041
|
-
previous = this.__current;
|
3042
|
-
this.__current = element;
|
3043
|
-
this.__state = null;
|
3044
|
-
if (callback) {
|
3045
|
-
result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
|
3046
|
-
}
|
3047
|
-
this.__current = previous;
|
3048
|
-
|
3049
|
-
return result;
|
3050
|
-
};
|
3051
|
-
|
3052
|
-
// API:
|
3053
|
-
// notify control skip / break
|
3054
|
-
Controller.prototype.notify = function notify(flag) {
|
3055
|
-
this.__state = flag;
|
3056
|
-
};
|
3057
|
-
|
3058
|
-
// API:
|
3059
|
-
// skip child nodes of current node
|
3060
|
-
Controller.prototype.skip = function () {
|
3061
|
-
this.notify(SKIP);
|
3062
|
-
};
|
3063
|
-
|
3064
|
-
// API:
|
3065
|
-
// break traversals
|
3066
|
-
Controller.prototype['break'] = function () {
|
3067
|
-
this.notify(BREAK);
|
3068
|
-
};
|
3069
|
-
|
3070
|
-
// API:
|
3071
|
-
// remove node
|
3072
|
-
Controller.prototype.remove = function () {
|
3073
|
-
this.notify(REMOVE);
|
3074
|
-
};
|
3075
|
-
|
3076
|
-
Controller.prototype.__initialize = function(root, visitor) {
|
3077
|
-
this.visitor = visitor;
|
3078
|
-
this.root = root;
|
3079
|
-
this.__worklist = [];
|
3080
|
-
this.__leavelist = [];
|
3081
|
-
this.__current = null;
|
3082
|
-
this.__state = null;
|
3083
|
-
this.__fallback = null;
|
3084
|
-
if (visitor.fallback === 'iteration') {
|
3085
|
-
this.__fallback = Object.keys;
|
3086
|
-
} else if (typeof visitor.fallback === 'function') {
|
3087
|
-
this.__fallback = visitor.fallback;
|
3088
|
-
}
|
3089
|
-
|
3090
|
-
this.__keys = VisitorKeys;
|
3091
|
-
if (visitor.keys) {
|
3092
|
-
this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
|
3093
|
-
}
|
3094
|
-
};
|
3095
|
-
|
3096
|
-
function isNode(node) {
|
3097
|
-
if (node == null) {
|
3098
|
-
return false;
|
3099
|
-
}
|
3100
|
-
return typeof node === 'object' && typeof node.type === 'string';
|
3101
|
-
}
|
3102
|
-
|
3103
|
-
function isProperty(nodeType, key) {
|
3104
|
-
return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
|
3105
|
-
}
|
3106
|
-
|
3107
|
-
function candidateExistsInLeaveList(leavelist, candidate) {
|
3108
|
-
for (var i = leavelist.length - 1; i >= 0; --i) {
|
3109
|
-
if (leavelist[i].node === candidate) {
|
3110
|
-
return true;
|
3111
|
-
}
|
3112
|
-
}
|
3113
|
-
return false;
|
3114
|
-
}
|
3115
|
-
|
3116
|
-
Controller.prototype.traverse = function traverse(root, visitor) {
|
3117
|
-
var worklist,
|
3118
|
-
leavelist,
|
3119
|
-
element,
|
3120
|
-
node,
|
3121
|
-
nodeType,
|
3122
|
-
ret,
|
3123
|
-
key,
|
3124
|
-
current,
|
3125
|
-
current2,
|
3126
|
-
candidates,
|
3127
|
-
candidate,
|
3128
|
-
sentinel;
|
3129
|
-
|
3130
|
-
this.__initialize(root, visitor);
|
3131
|
-
|
3132
|
-
sentinel = {};
|
3133
|
-
|
3134
|
-
// reference
|
3135
|
-
worklist = this.__worklist;
|
3136
|
-
leavelist = this.__leavelist;
|
3137
|
-
|
3138
|
-
// initialize
|
3139
|
-
worklist.push(new Element(root, null, null, null));
|
3140
|
-
leavelist.push(new Element(null, null, null, null));
|
3141
|
-
|
3142
|
-
while (worklist.length) {
|
3143
|
-
element = worklist.pop();
|
3144
|
-
|
3145
|
-
if (element === sentinel) {
|
3146
|
-
element = leavelist.pop();
|
3147
|
-
|
3148
|
-
ret = this.__execute(visitor.leave, element);
|
3149
|
-
|
3150
|
-
if (this.__state === BREAK || ret === BREAK) {
|
3151
|
-
return;
|
3152
|
-
}
|
3153
|
-
continue;
|
3154
|
-
}
|
3155
|
-
|
3156
|
-
if (element.node) {
|
3157
|
-
|
3158
|
-
ret = this.__execute(visitor.enter, element);
|
3159
|
-
|
3160
|
-
if (this.__state === BREAK || ret === BREAK) {
|
3161
|
-
return;
|
3162
|
-
}
|
3163
|
-
|
3164
|
-
worklist.push(sentinel);
|
3165
|
-
leavelist.push(element);
|
3166
|
-
|
3167
|
-
if (this.__state === SKIP || ret === SKIP) {
|
3168
|
-
continue;
|
3169
|
-
}
|
3170
|
-
|
3171
|
-
node = element.node;
|
3172
|
-
nodeType = node.type || element.wrap;
|
3173
|
-
candidates = this.__keys[nodeType];
|
3174
|
-
if (!candidates) {
|
3175
|
-
if (this.__fallback) {
|
3176
|
-
candidates = this.__fallback(node);
|
3177
|
-
} else {
|
3178
|
-
throw new Error('Unknown node type ' + nodeType + '.');
|
3179
|
-
}
|
3180
|
-
}
|
3181
|
-
|
3182
|
-
current = candidates.length;
|
3183
|
-
while ((current -= 1) >= 0) {
|
3184
|
-
key = candidates[current];
|
3185
|
-
candidate = node[key];
|
3186
|
-
if (!candidate) {
|
3187
|
-
continue;
|
3188
|
-
}
|
3189
|
-
|
3190
|
-
if (Array.isArray(candidate)) {
|
3191
|
-
current2 = candidate.length;
|
3192
|
-
while ((current2 -= 1) >= 0) {
|
3193
|
-
if (!candidate[current2]) {
|
3194
|
-
continue;
|
3195
|
-
}
|
3196
|
-
|
3197
|
-
if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
|
3198
|
-
continue;
|
3199
|
-
}
|
3200
|
-
|
3201
|
-
if (isProperty(nodeType, candidates[current])) {
|
3202
|
-
element = new Element(candidate[current2], [key, current2], 'Property', null);
|
3203
|
-
} else if (isNode(candidate[current2])) {
|
3204
|
-
element = new Element(candidate[current2], [key, current2], null, null);
|
3205
|
-
} else {
|
3206
|
-
continue;
|
3207
|
-
}
|
3208
|
-
worklist.push(element);
|
3209
|
-
}
|
3210
|
-
} else if (isNode(candidate)) {
|
3211
|
-
if (candidateExistsInLeaveList(leavelist, candidate)) {
|
3212
|
-
continue;
|
3213
|
-
}
|
3214
|
-
|
3215
|
-
worklist.push(new Element(candidate, key, null, null));
|
3216
|
-
}
|
3217
|
-
}
|
3218
|
-
}
|
3219
|
-
}
|
3220
|
-
};
|
3221
|
-
|
3222
|
-
Controller.prototype.replace = function replace(root, visitor) {
|
3223
|
-
var worklist,
|
3224
|
-
leavelist,
|
3225
|
-
node,
|
3226
|
-
nodeType,
|
3227
|
-
target,
|
3228
|
-
element,
|
3229
|
-
current,
|
3230
|
-
current2,
|
3231
|
-
candidates,
|
3232
|
-
candidate,
|
3233
|
-
sentinel,
|
3234
|
-
outer,
|
3235
|
-
key;
|
3236
|
-
|
3237
|
-
function removeElem(element) {
|
3238
|
-
var i,
|
3239
|
-
key,
|
3240
|
-
nextElem,
|
3241
|
-
parent;
|
3242
|
-
|
3243
|
-
if (element.ref.remove()) {
|
3244
|
-
// When the reference is an element of an array.
|
3245
|
-
key = element.ref.key;
|
3246
|
-
parent = element.ref.parent;
|
3247
|
-
|
3248
|
-
// If removed from array, then decrease following items' keys.
|
3249
|
-
i = worklist.length;
|
3250
|
-
while (i--) {
|
3251
|
-
nextElem = worklist[i];
|
3252
|
-
if (nextElem.ref && nextElem.ref.parent === parent) {
|
3253
|
-
if (nextElem.ref.key < key) {
|
3254
|
-
break;
|
3255
|
-
}
|
3256
|
-
--nextElem.ref.key;
|
3257
|
-
}
|
3258
|
-
}
|
3259
|
-
}
|
3260
|
-
}
|
3261
|
-
|
3262
|
-
this.__initialize(root, visitor);
|
3263
|
-
|
3264
|
-
sentinel = {};
|
3265
|
-
|
3266
|
-
// reference
|
3267
|
-
worklist = this.__worklist;
|
3268
|
-
leavelist = this.__leavelist;
|
3269
|
-
|
3270
|
-
// initialize
|
3271
|
-
outer = {
|
3272
|
-
root: root
|
3273
|
-
};
|
3274
|
-
element = new Element(root, null, null, new Reference(outer, 'root'));
|
3275
|
-
worklist.push(element);
|
3276
|
-
leavelist.push(element);
|
3277
|
-
|
3278
|
-
while (worklist.length) {
|
3279
|
-
element = worklist.pop();
|
3280
|
-
|
3281
|
-
if (element === sentinel) {
|
3282
|
-
element = leavelist.pop();
|
3283
|
-
|
3284
|
-
target = this.__execute(visitor.leave, element);
|
3285
|
-
|
3286
|
-
// node may be replaced with null,
|
3287
|
-
// so distinguish between undefined and null in this place
|
3288
|
-
if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
|
3289
|
-
// replace
|
3290
|
-
element.ref.replace(target);
|
3291
|
-
}
|
3292
|
-
|
3293
|
-
if (this.__state === REMOVE || target === REMOVE) {
|
3294
|
-
removeElem(element);
|
3295
|
-
}
|
3296
|
-
|
3297
|
-
if (this.__state === BREAK || target === BREAK) {
|
3298
|
-
return outer.root;
|
3299
|
-
}
|
3300
|
-
continue;
|
3301
|
-
}
|
3302
|
-
|
3303
|
-
target = this.__execute(visitor.enter, element);
|
3304
|
-
|
3305
|
-
// node may be replaced with null,
|
3306
|
-
// so distinguish between undefined and null in this place
|
3307
|
-
if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
|
3308
|
-
// replace
|
3309
|
-
element.ref.replace(target);
|
3310
|
-
element.node = target;
|
3311
|
-
}
|
3312
|
-
|
3313
|
-
if (this.__state === REMOVE || target === REMOVE) {
|
3314
|
-
removeElem(element);
|
3315
|
-
element.node = null;
|
3316
|
-
}
|
3317
|
-
|
3318
|
-
if (this.__state === BREAK || target === BREAK) {
|
3319
|
-
return outer.root;
|
3320
|
-
}
|
3321
|
-
|
3322
|
-
// node may be null
|
3323
|
-
node = element.node;
|
3324
|
-
if (!node) {
|
3325
|
-
continue;
|
3326
|
-
}
|
3327
|
-
|
3328
|
-
worklist.push(sentinel);
|
3329
|
-
leavelist.push(element);
|
3330
|
-
|
3331
|
-
if (this.__state === SKIP || target === SKIP) {
|
3332
|
-
continue;
|
3333
|
-
}
|
3334
|
-
|
3335
|
-
nodeType = node.type || element.wrap;
|
3336
|
-
candidates = this.__keys[nodeType];
|
3337
|
-
if (!candidates) {
|
3338
|
-
if (this.__fallback) {
|
3339
|
-
candidates = this.__fallback(node);
|
3340
|
-
} else {
|
3341
|
-
throw new Error('Unknown node type ' + nodeType + '.');
|
3342
|
-
}
|
3343
|
-
}
|
3344
|
-
|
3345
|
-
current = candidates.length;
|
3346
|
-
while ((current -= 1) >= 0) {
|
3347
|
-
key = candidates[current];
|
3348
|
-
candidate = node[key];
|
3349
|
-
if (!candidate) {
|
3350
|
-
continue;
|
3351
|
-
}
|
3352
|
-
|
3353
|
-
if (Array.isArray(candidate)) {
|
3354
|
-
current2 = candidate.length;
|
3355
|
-
while ((current2 -= 1) >= 0) {
|
3356
|
-
if (!candidate[current2]) {
|
3357
|
-
continue;
|
3358
|
-
}
|
3359
|
-
if (isProperty(nodeType, candidates[current])) {
|
3360
|
-
element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
|
3361
|
-
} else if (isNode(candidate[current2])) {
|
3362
|
-
element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
|
3363
|
-
} else {
|
3364
|
-
continue;
|
3365
|
-
}
|
3366
|
-
worklist.push(element);
|
3367
|
-
}
|
3368
|
-
} else if (isNode(candidate)) {
|
3369
|
-
worklist.push(new Element(candidate, key, null, new Reference(node, key)));
|
3370
|
-
}
|
3371
|
-
}
|
3372
|
-
}
|
3373
|
-
|
3374
|
-
return outer.root;
|
3375
|
-
};
|
3376
|
-
|
3377
|
-
function traverse(root, visitor) {
|
3378
|
-
var controller = new Controller();
|
3379
|
-
return controller.traverse(root, visitor);
|
3380
|
-
}
|
3381
|
-
|
3382
|
-
function replace(root, visitor) {
|
3383
|
-
var controller = new Controller();
|
3384
|
-
return controller.replace(root, visitor);
|
3385
|
-
}
|
3386
|
-
|
3387
|
-
function extendCommentRange(comment, tokens) {
|
3388
|
-
var target;
|
3389
|
-
|
3390
|
-
target = upperBound(tokens, function search(token) {
|
3391
|
-
return token.range[0] > comment.range[0];
|
3392
|
-
});
|
3393
|
-
|
3394
|
-
comment.extendedRange = [comment.range[0], comment.range[1]];
|
3395
|
-
|
3396
|
-
if (target !== tokens.length) {
|
3397
|
-
comment.extendedRange[1] = tokens[target].range[0];
|
3398
|
-
}
|
3399
|
-
|
3400
|
-
target -= 1;
|
3401
|
-
if (target >= 0) {
|
3402
|
-
comment.extendedRange[0] = tokens[target].range[1];
|
3403
|
-
}
|
3404
|
-
|
3405
|
-
return comment;
|
3406
|
-
}
|
3407
|
-
|
3408
|
-
function attachComments(tree, providedComments, tokens) {
|
3409
|
-
// At first, we should calculate extended comment ranges.
|
3410
|
-
var comments = [], comment, len, i, cursor;
|
3411
|
-
|
3412
|
-
if (!tree.range) {
|
3413
|
-
throw new Error('attachComments needs range information');
|
3414
|
-
}
|
3415
|
-
|
3416
|
-
// tokens array is empty, we attach comments to tree as 'leadingComments'
|
3417
|
-
if (!tokens.length) {
|
3418
|
-
if (providedComments.length) {
|
3419
|
-
for (i = 0, len = providedComments.length; i < len; i += 1) {
|
3420
|
-
comment = deepCopy(providedComments[i]);
|
3421
|
-
comment.extendedRange = [0, tree.range[0]];
|
3422
|
-
comments.push(comment);
|
3423
|
-
}
|
3424
|
-
tree.leadingComments = comments;
|
3425
|
-
}
|
3426
|
-
return tree;
|
3427
|
-
}
|
3428
|
-
|
3429
|
-
for (i = 0, len = providedComments.length; i < len; i += 1) {
|
3430
|
-
comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
|
3431
|
-
}
|
3432
|
-
|
3433
|
-
// This is based on John Freeman's implementation.
|
3434
|
-
cursor = 0;
|
3435
|
-
traverse(tree, {
|
3436
|
-
enter: function (node) {
|
3437
|
-
var comment;
|
3438
|
-
|
3439
|
-
while (cursor < comments.length) {
|
3440
|
-
comment = comments[cursor];
|
3441
|
-
if (comment.extendedRange[1] > node.range[0]) {
|
3442
|
-
break;
|
3443
|
-
}
|
3444
|
-
|
3445
|
-
if (comment.extendedRange[1] === node.range[0]) {
|
3446
|
-
if (!node.leadingComments) {
|
3447
|
-
node.leadingComments = [];
|
3448
|
-
}
|
3449
|
-
node.leadingComments.push(comment);
|
3450
|
-
comments.splice(cursor, 1);
|
3451
|
-
} else {
|
3452
|
-
cursor += 1;
|
3453
|
-
}
|
3454
|
-
}
|
3455
|
-
|
3456
|
-
// already out of owned node
|
3457
|
-
if (cursor === comments.length) {
|
3458
|
-
return VisitorOption.Break;
|
3459
|
-
}
|
3460
|
-
|
3461
|
-
if (comments[cursor].extendedRange[0] > node.range[1]) {
|
3462
|
-
return VisitorOption.Skip;
|
3463
|
-
}
|
3464
|
-
}
|
3465
|
-
});
|
3466
|
-
|
3467
|
-
cursor = 0;
|
3468
|
-
traverse(tree, {
|
3469
|
-
leave: function (node) {
|
3470
|
-
var comment;
|
3471
|
-
|
3472
|
-
while (cursor < comments.length) {
|
3473
|
-
comment = comments[cursor];
|
3474
|
-
if (node.range[1] < comment.extendedRange[0]) {
|
3475
|
-
break;
|
3476
|
-
}
|
3477
|
-
|
3478
|
-
if (node.range[1] === comment.extendedRange[0]) {
|
3479
|
-
if (!node.trailingComments) {
|
3480
|
-
node.trailingComments = [];
|
3481
|
-
}
|
3482
|
-
node.trailingComments.push(comment);
|
3483
|
-
comments.splice(cursor, 1);
|
3484
|
-
} else {
|
3485
|
-
cursor += 1;
|
3486
|
-
}
|
3487
|
-
}
|
3488
|
-
|
3489
|
-
// already out of owned node
|
3490
|
-
if (cursor === comments.length) {
|
3491
|
-
return VisitorOption.Break;
|
3492
|
-
}
|
3493
|
-
|
3494
|
-
if (comments[cursor].extendedRange[0] > node.range[1]) {
|
3495
|
-
return VisitorOption.Skip;
|
3496
|
-
}
|
3497
|
-
}
|
3498
|
-
});
|
3499
|
-
|
3500
|
-
return tree;
|
3501
|
-
}
|
3502
|
-
|
3503
|
-
exports.Syntax = Syntax;
|
3504
|
-
exports.traverse = traverse;
|
3505
|
-
exports.replace = replace;
|
3506
|
-
exports.attachComments = attachComments;
|
3507
|
-
exports.VisitorKeys = VisitorKeys;
|
3508
|
-
exports.VisitorOption = VisitorOption;
|
3509
|
-
exports.Controller = Controller;
|
3510
|
-
exports.cloneEnvironment = function () { return clone({}); };
|
3511
|
-
|
3512
|
-
return exports;
|
3513
|
-
}(exports));
|
3514
|
-
/* vim: set sw=4 ts=4 et tw=80 : */
|
3515
|
-
|
3516
2713
|
function parser(code) {
|
3517
2714
|
const node = acor__namespace.parse(code, { ecmaVersion: 'latest' });
|
3518
|
-
|
2715
|
+
estraverse__namespace.traverse(node, {
|
3519
2716
|
enter: (child, parent) => {
|
3520
2717
|
if (child.type === 'Identifier') {
|
3521
2718
|
const identifierName = child['name'];
|
@@ -3525,7 +2722,7 @@ function parser(code) {
|
|
3525
2722
|
}
|
3526
2723
|
}
|
3527
2724
|
});
|
3528
|
-
|
2725
|
+
estraverse__namespace.replace(node, {
|
3529
2726
|
leave: (child) => {
|
3530
2727
|
//函数调用
|
3531
2728
|
if (child.type == 'CallExpression') {
|
@@ -5064,7 +4261,6 @@ class TableUtil {
|
|
5064
4261
|
if (!ss.startControl) {
|
5065
4262
|
return;
|
5066
4263
|
}
|
5067
|
-
ss.clear();
|
5068
4264
|
const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
|
5069
4265
|
if (!startCell?.parent) {
|
5070
4266
|
throw new Error('parent is null');
|
@@ -5075,6 +4271,7 @@ class TableUtil {
|
|
5075
4271
|
if (tb.length === 0) {
|
5076
4272
|
tb.remove();
|
5077
4273
|
}
|
4274
|
+
ss.clear();
|
5078
4275
|
}
|
5079
4276
|
/**
|
5080
4277
|
* 移除光标所在的当前列
|
@@ -11996,6 +11193,7 @@ class ParagraphMeasure {
|
|
11996
11193
|
*/
|
11997
11194
|
measureParagraph(p, limitWidth) {
|
11998
11195
|
ElementUtil.fixParagraphContent(p);
|
11196
|
+
this.verifyPara(p, limitWidth);
|
11999
11197
|
p.cacheRender = null;
|
12000
11198
|
const paraModels = [];
|
12001
11199
|
let currRenderLine;
|
@@ -12116,6 +11314,17 @@ class ParagraphMeasure {
|
|
12116
11314
|
}
|
12117
11315
|
return paraRenders;
|
12118
11316
|
}
|
11317
|
+
/**
|
11318
|
+
* 校验当前段落属性
|
11319
|
+
*/
|
11320
|
+
verifyPara(p, limitWidth) {
|
11321
|
+
if (p.props.indent > 0 && p.props.indent + 20 > limitWidth) {
|
11322
|
+
p.props.indent = limitWidth - 20;
|
11323
|
+
}
|
11324
|
+
if (p.props.hanging > 0 && p.props.hanging + 20 > limitWidth) {
|
11325
|
+
p.props.hanging = limitWidth - 20;
|
11326
|
+
}
|
11327
|
+
}
|
12119
11328
|
/**
|
12120
11329
|
* 获取段落行布局横向坐标起始位置,被段落text-align影响
|
12121
11330
|
*/
|
@@ -17952,6 +17161,10 @@ var ModifyFlag;
|
|
17952
17161
|
class NodeCore {
|
17953
17162
|
enableClip = true;
|
17954
17163
|
pointEvent = true;
|
17164
|
+
allowHitTest = false;
|
17165
|
+
hitTest(hitPos, currPos) {
|
17166
|
+
return false;
|
17167
|
+
}
|
17955
17168
|
get enable() {
|
17956
17169
|
return this._enable;
|
17957
17170
|
}
|
@@ -18281,6 +17494,9 @@ class NodeItems extends NodeCore {
|
|
18281
17494
|
eventMap = new WeakMap();
|
18282
17495
|
absoluteItems = false;
|
18283
17496
|
containerPropName;
|
17497
|
+
constructor() {
|
17498
|
+
super();
|
17499
|
+
}
|
18284
17500
|
addChild(control, index = -1) {
|
18285
17501
|
if (this.containerPropName) {
|
18286
17502
|
this[this.containerPropName].addChild(control, index);
|
@@ -18352,6 +17568,33 @@ class NodeItems extends NodeCore {
|
|
18352
17568
|
return this.controls.length;
|
18353
17569
|
}
|
18354
17570
|
}
|
17571
|
+
/**
|
17572
|
+
* 子内容采用绝对定位的容器
|
17573
|
+
*/
|
17574
|
+
class AbsolutePanel extends NodeItems {
|
17575
|
+
constructor() {
|
17576
|
+
super();
|
17577
|
+
this.absoluteItems = true;
|
17578
|
+
}
|
17579
|
+
measureOverride(e, availableSize) {
|
17580
|
+
this.controls.forEach(item => {
|
17581
|
+
item.measure(e, availableSize);
|
17582
|
+
});
|
17583
|
+
return super.measureOverride(e, availableSize);
|
17584
|
+
}
|
17585
|
+
arrangeOverride(e, finalSize) {
|
17586
|
+
this.controls.forEach(item => {
|
17587
|
+
const itemRect = {
|
17588
|
+
x: item.x,
|
17589
|
+
y: item.y,
|
17590
|
+
width: item.desiredSize.width,
|
17591
|
+
height: item.desiredSize.height
|
17592
|
+
};
|
17593
|
+
item.arrange(e, itemRect);
|
17594
|
+
});
|
17595
|
+
return super.arrangeOverride(e, finalSize);
|
17596
|
+
}
|
17597
|
+
}
|
18355
17598
|
let currentActiveAppContext = null;
|
18356
17599
|
function getCurrentActiveAppContext() {
|
18357
17600
|
return currentActiveAppContext;
|
@@ -18469,7 +17712,7 @@ function drawBorderline(node, renderCtx) {
|
|
18469
17712
|
if (!node.border) {
|
18470
17713
|
return;
|
18471
17714
|
}
|
18472
|
-
let { x, y,
|
17715
|
+
let { finalRect: { x, y, width, height } } = node;
|
18473
17716
|
const ctx = renderCtx.ctx;
|
18474
17717
|
ctx.save();
|
18475
17718
|
ctx.fillStyle = node.borderColor;
|
@@ -19033,7 +18276,7 @@ class NodeEvent {
|
|
19033
18276
|
};
|
19034
18277
|
mouseleaveRenders.forEach(item => {
|
19035
18278
|
onMouseoutEvent.target = item;
|
19036
|
-
invokeEvent(onMouseoutEvent, '
|
18279
|
+
invokeEvent(onMouseoutEvent, 'mouseout', item, false);
|
19037
18280
|
});
|
19038
18281
|
const onMouseoverEvent = {
|
19039
18282
|
pos: this.appState.pos,
|
@@ -19199,7 +18442,8 @@ class NodeEvent {
|
|
19199
18442
|
width: width,
|
19200
18443
|
height: height
|
19201
18444
|
};
|
19202
|
-
|
18445
|
+
const hitTest = node.allowHitTest ? node.hitTest(hitPos, currRect) : isInsideRectByPosition(currRect, hitPos);
|
18446
|
+
if (hitTest) {
|
19203
18447
|
//有边框和内边距,所以在计算子节点的时候,需要考虑
|
19204
18448
|
const innerPos = {
|
19205
18449
|
x: currRect.x + node.border + node.padding,
|
@@ -19361,6 +18605,13 @@ class ViewPaint {
|
|
19361
18605
|
this.drawHoriLine(x, y, width, textProps.color, 1);
|
19362
18606
|
}
|
19363
18607
|
}
|
18608
|
+
drawText2(text, textProps, x, y) {
|
18609
|
+
this.ctx.save();
|
18610
|
+
this.ctx.fillStyle = textProps.color;
|
18611
|
+
this.ctx.font = `${textProps.fontSize}px ${textProps.fontName}`;
|
18612
|
+
this.ctx.fillText(text, x, y + textProps.fontSize / 7);
|
18613
|
+
this.ctx.restore();
|
18614
|
+
}
|
19364
18615
|
fillCircular(x, y, r, color = 'black') {
|
19365
18616
|
this.ctx.save();
|
19366
18617
|
this.ctx.beginPath();
|
@@ -19375,6 +18626,10 @@ class ViewPaint {
|
|
19375
18626
|
const textMeasure = this.ctx.measureText(text);
|
19376
18627
|
return { width: textMeasure.width, height: textProps.fontSize };
|
19377
18628
|
}
|
18629
|
+
measureText2(text, font) {
|
18630
|
+
this.ctx.font = font.fontSize + 'px ' + font.fontName;
|
18631
|
+
return this.ctx.measureText(text).width;
|
18632
|
+
}
|
19378
18633
|
measureTextUnits(units, textProps) {
|
19379
18634
|
this.ctx.font = textProps.getFont();
|
19380
18635
|
const letterSpace = textProps.letterSpace ?? 0;
|
@@ -19791,6 +19046,11 @@ class SurfaceView extends NodeItems {
|
|
19791
19046
|
* 如果有默认宽度限制,而且支持换行显示,则内容高度等于多行累计高度
|
19792
19047
|
*/
|
19793
19048
|
class LabelNode extends TextBase {
|
19049
|
+
constructor() {
|
19050
|
+
super();
|
19051
|
+
this.border = 1;
|
19052
|
+
this.borderColor = '#000';
|
19053
|
+
}
|
19794
19054
|
_textWrapping = 'no';
|
19795
19055
|
get textWrapping() {
|
19796
19056
|
return this._textWrapping;
|
@@ -19800,34 +19060,54 @@ class LabelNode extends TextBase {
|
|
19800
19060
|
this._textWrapping = value;
|
19801
19061
|
}
|
19802
19062
|
cacheTextRect;
|
19803
|
-
textUnits
|
19063
|
+
//private textUnits!: Array<TextUnits>;
|
19064
|
+
lines = [];
|
19804
19065
|
measureOverride(e, availableSize) {
|
19805
|
-
|
19806
|
-
this.
|
19807
|
-
|
19066
|
+
this.getTextProps();
|
19067
|
+
this.lines = this.getMuiltLines(this.text, e);
|
19068
|
+
// this.textUnits = this.text.split('').map<TextUnits>(char => ({char, actualSize: 0, sourceSize: 0}));
|
19069
|
+
// e.render.measureTextUnits(this.textUnits, textProps);
|
19808
19070
|
//没有宽度限制,测量横向排列的尺寸大小,此时不需要考虑换行
|
19809
|
-
if (Number.isNaN(this._width)) {
|
19810
|
-
|
19811
|
-
|
19812
|
-
|
19813
|
-
|
19814
|
-
|
19815
|
-
|
19816
|
-
|
19817
|
-
|
19818
|
-
}
|
19819
|
-
|
19071
|
+
// if (Number.isNaN(this._width)) {
|
19072
|
+
// // return {
|
19073
|
+
// // width: this.lines[0].textUnits.reduce((prev, curr) => {
|
19074
|
+
// // return prev + curr.sourceSize
|
19075
|
+
// // }, 0), height: this.fontSize
|
19076
|
+
// // };
|
19077
|
+
// return this.measureTextRect(this.lines, {
|
19078
|
+
// width: availableSize.width,
|
19079
|
+
// height: this.getPercentHeight(availableSize.height)
|
19080
|
+
// });
|
19081
|
+
// }
|
19082
|
+
// if (this._textWrapping === 'no') {
|
19083
|
+
// return {width: this.getPercentWidth(availableSize.width), height: this.fontSize};
|
19084
|
+
// }
|
19085
|
+
return this.measureTextRect(this.lines, {
|
19820
19086
|
width: availableSize.width,
|
19821
19087
|
height: this.getPercentHeight(availableSize.height)
|
19822
19088
|
});
|
19823
19089
|
}
|
19824
|
-
|
19825
|
-
|
19826
|
-
|
19827
|
-
|
19828
|
-
|
19829
|
-
|
19090
|
+
getMuiltLines(text, e) {
|
19091
|
+
const lineRects = [];
|
19092
|
+
const lines = this.text.split('\r\n');
|
19093
|
+
for (let i = 0; i < lines.length; i++) {
|
19094
|
+
const units = lines[i].split('').map(char => ({ char, actualSize: 0, sourceSize: 0 }));
|
19095
|
+
e.render.measureTextUnits(units, this.getTextProps());
|
19096
|
+
lineRects.push({ textUnits: units });
|
19830
19097
|
}
|
19098
|
+
return lineRects;
|
19099
|
+
}
|
19100
|
+
arrangeOverride(e, finalSize) {
|
19101
|
+
// if (!Number.isNaN(this._width) && this._textWrapping === 'wrap') {
|
19102
|
+
// this.measureTextRect(this.lines, {
|
19103
|
+
// width: finalSize.width,
|
19104
|
+
// height: finalSize.height
|
19105
|
+
// });
|
19106
|
+
// }
|
19107
|
+
this.measureTextRect(this.lines, {
|
19108
|
+
width: finalSize.width,
|
19109
|
+
height: finalSize.height
|
19110
|
+
});
|
19831
19111
|
return super.arrangeOverride(e, finalSize);
|
19832
19112
|
}
|
19833
19113
|
getTextProps() {
|
@@ -19837,54 +19117,56 @@ class LabelNode extends TextBase {
|
|
19837
19117
|
textProps.color = this.color ?? '#000';
|
19838
19118
|
return textProps;
|
19839
19119
|
}
|
19840
|
-
measureTextRect(
|
19841
|
-
const sumWidth = textUnits.reduce((prev, curr) => {
|
19842
|
-
return curr.sourceSize + prev;
|
19843
|
-
}, 0);
|
19120
|
+
measureTextRect(lines, availableSize, final = false) {
|
19844
19121
|
//总宽度大于可用宽度,换行计算
|
19845
19122
|
const cacheLines = [];
|
19846
19123
|
const { width: limitWidth, height: limitHeight } = availableSize;
|
19847
|
-
let
|
19848
|
-
|
19849
|
-
|
19850
|
-
|
19851
|
-
|
19852
|
-
|
19853
|
-
|
19854
|
-
|
19855
|
-
|
19856
|
-
|
19857
|
-
|
19858
|
-
|
19124
|
+
for (let i = 0; i < lines.length; i++) {
|
19125
|
+
const lineText = lines[i];
|
19126
|
+
let line = { lineUnits: [], x: 0, y: 0, width: 0, height: 0 };
|
19127
|
+
cacheLines.push(line);
|
19128
|
+
for (let j = 0; j < lineText.textUnits.length; j++) {
|
19129
|
+
const unit = lineText.textUnits[j];
|
19130
|
+
//至少每行一个字符
|
19131
|
+
if (line.lineUnits.length > 0 && line.width + unit.sourceSize > limitWidth) {
|
19132
|
+
line = { lineUnits: [], x: 0, y: 0, width: 0, height: 0 };
|
19133
|
+
cacheLines.push(line);
|
19134
|
+
}
|
19135
|
+
line.lineUnits.push(unit);
|
19136
|
+
line.width += unit.sourceSize;
|
19137
|
+
line.height = this.fontSize;
|
19138
|
+
}
|
19859
19139
|
}
|
19860
19140
|
let contentHeight = 0;
|
19141
|
+
let maxLineWidth = 0;
|
19861
19142
|
cacheLines.forEach(line => {
|
19862
19143
|
line.y = contentHeight;
|
19863
19144
|
contentHeight += line.height;
|
19145
|
+
maxLineWidth = Math.max(line.width, maxLineWidth);
|
19864
19146
|
});
|
19865
19147
|
//期望高度
|
19866
19148
|
let desiredHeight = final ? limitHeight : contentHeight;
|
19867
19149
|
this.cacheTextRect = {
|
19868
19150
|
lines: cacheLines,
|
19869
|
-
width:
|
19151
|
+
width: maxLineWidth,
|
19870
19152
|
height: contentHeight,
|
19871
19153
|
desiredHeight,
|
19872
19154
|
desiredWidth: limitWidth
|
19873
19155
|
};
|
19874
19156
|
return {
|
19875
|
-
width:
|
19157
|
+
width: maxLineWidth,
|
19876
19158
|
height: desiredHeight
|
19877
19159
|
};
|
19878
19160
|
}
|
19879
19161
|
render(e) {
|
19880
|
-
const textProp = new TextProps();
|
19881
|
-
textProp.fontName = this.fontName;
|
19882
|
-
textProp.fontSize = this.fontSize;
|
19883
|
-
textProp.color = this.color;
|
19884
|
-
if (this.textWrapping === 'no' || Number.isNaN(this._width)) {
|
19885
|
-
|
19886
|
-
|
19887
|
-
}
|
19162
|
+
// const textProp = new TextProps();
|
19163
|
+
// textProp.fontName = this.fontName;
|
19164
|
+
// textProp.fontSize = this.fontSize;
|
19165
|
+
// textProp.color = this.color;
|
19166
|
+
// if (this.textWrapping === 'no' || Number.isNaN(this._width)) {
|
19167
|
+
// e.render.drawText(this.text, textProp, 0, 0, this.finalRect.width, textProp.fontSize);
|
19168
|
+
// return;
|
19169
|
+
// }
|
19888
19170
|
for (let i = 0; i < this.cacheTextRect.lines.length; i++) {
|
19889
19171
|
const line = this.cacheTextRect.lines[i];
|
19890
19172
|
this.drawLine(e, line);
|
@@ -19900,7 +19182,7 @@ class LabelNode extends TextBase {
|
|
19900
19182
|
render.tran(() => {
|
19901
19183
|
const textProps = this.getTextProps();
|
19902
19184
|
render.ctx.font = textProps.getFont();
|
19903
|
-
render.drawText(line.lineUnits.join(''), textProps, 0, line.y, line.width, line.height);
|
19185
|
+
render.drawText(line.lineUnits.map(item => item.char).join(''), textProps, 0, line.y, line.width, line.height);
|
19904
19186
|
});
|
19905
19187
|
}
|
19906
19188
|
}
|
@@ -20150,8 +19432,8 @@ class ScrollView extends NodeItems {
|
|
20150
19432
|
});
|
20151
19433
|
this.addEventListener('wheel', evt => {
|
20152
19434
|
const { deltaY, deltaX } = evt;
|
20153
|
-
this.horBar.updateScrollByCurrent(deltaX
|
20154
|
-
this.verBar.updateScrollByCurrent(deltaX
|
19435
|
+
this.horBar.updateScrollByCurrent(deltaX, deltaY);
|
19436
|
+
this.verBar.updateScrollByCurrent(deltaX, deltaY);
|
20155
19437
|
});
|
20156
19438
|
}
|
20157
19439
|
scrollTo(x, y) {
|
@@ -20870,7 +20152,7 @@ function pointInPoly(pt, poly) {
|
|
20870
20152
|
* 1.在单页模式下,文档最小宽度为单个文档宽度+合适的外边距
|
20871
20153
|
* 2.在多页模式下,文档最小宽度为单个文档宽度+合适的外边距
|
20872
20154
|
*/
|
20873
|
-
class CanvasTextEditor extends
|
20155
|
+
class CanvasTextEditor extends AbsolutePanel {
|
20874
20156
|
editCanvas;
|
20875
20157
|
editInput;
|
20876
20158
|
contentCtx;
|
@@ -21797,6 +21079,13 @@ class CanvasTextEditor extends NodeItems {
|
|
21797
21079
|
const win = new Window();
|
21798
21080
|
win.width = 1000;
|
21799
21081
|
win.height = 800;
|
21082
|
+
//win.content.addChild(timelineScrollbar)
|
21083
|
+
const rule2 = new RuleControl(this.docCtx);
|
21084
|
+
this.rule = rule2;
|
21085
|
+
rule2.width = 700;
|
21086
|
+
rule2.height = 30;
|
21087
|
+
rule2.x = 20;
|
21088
|
+
rule2.y = 500;
|
21800
21089
|
const surface = new SurfaceView(this.editCanvas, this.editInput);
|
21801
21090
|
this.surfaceView = surface;
|
21802
21091
|
surface.width = 1000;
|
@@ -21808,12 +21097,6 @@ class CanvasTextEditor extends NodeItems {
|
|
21808
21097
|
this.resetViewer();
|
21809
21098
|
});
|
21810
21099
|
surface.addChild(scrollView);
|
21811
|
-
const rule2 = new RuleControl(this.docCtx);
|
21812
|
-
this.rule = rule2;
|
21813
|
-
rule2.width = 700;
|
21814
|
-
rule2.height = 30;
|
21815
|
-
rule2.x = 20;
|
21816
|
-
rule2.y = 500;
|
21817
21100
|
surface.addChild(rule2);
|
21818
21101
|
//surface.addChild(win);
|
21819
21102
|
surface.start();
|
@@ -21888,24 +21171,6 @@ class CanvasTextEditor extends NodeItems {
|
|
21888
21171
|
appCtx.root.setInputPosition(caretPos);
|
21889
21172
|
}
|
21890
21173
|
}
|
21891
|
-
measureOverride(e, availableSize) {
|
21892
|
-
this.controls.forEach(item => {
|
21893
|
-
item.measure(e, availableSize);
|
21894
|
-
});
|
21895
|
-
return super.measureOverride(e, availableSize);
|
21896
|
-
}
|
21897
|
-
arrangeOverride(e, finalSize) {
|
21898
|
-
this.controls.forEach(item => {
|
21899
|
-
const itemRect = {
|
21900
|
-
x: item.x,
|
21901
|
-
y: item.y,
|
21902
|
-
width: item.desiredSize.width,
|
21903
|
-
height: item.desiredSize.height
|
21904
|
-
};
|
21905
|
-
item.arrange(e, itemRect);
|
21906
|
-
});
|
21907
|
-
return super.arrangeOverride(e, finalSize);
|
21908
|
-
}
|
21909
21174
|
}
|
21910
21175
|
|
21911
21176
|
/**
|