@breakside/jskit 2022.22.2 → 2022.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/Frameworks/DOM.jsframework/Info.json +2 -2
  2. package/Frameworks/DOM.jsframework/JS/XMLSerializer.js +9 -4
  3. package/Frameworks/DOM.jsframework/io.breakside.JSKit.DOM-bundle.js +2 -2
  4. package/Frameworks/DOM.jsframework/sources.json +10 -3
  5. package/Frameworks/FontKit.jsframework/Info.json +2 -2
  6. package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
  7. package/Frameworks/FontKit.jsframework/sources.json +34 -2
  8. package/Frameworks/Foundation.jsframework/Info.json +2 -2
  9. package/Frameworks/Foundation.jsframework/JS/JSAttributedString.js +347 -25
  10. package/Frameworks/Foundation.jsframework/JS/JSFont.js +39 -15
  11. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor+HTML.js +8 -0
  12. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor.js +105 -27
  13. package/Frameworks/Foundation.jsframework/JS/JSParagraphStyle.js +71 -0
  14. package/Frameworks/Foundation.jsframework/JS/JSTextAttachment.js +1 -1
  15. package/Frameworks/Foundation.jsframework/JS/JSTextContainer.js +56 -29
  16. package/Frameworks/Foundation.jsframework/JS/JSTextFrame.js +2 -32
  17. package/Frameworks/Foundation.jsframework/JS/JSTextFramesetter.js +125 -22
  18. package/Frameworks/Foundation.jsframework/JS/JSTextLayoutManager.js +11 -3
  19. package/Frameworks/Foundation.jsframework/JS/JSTextLine.js +4 -3
  20. package/Frameworks/Foundation.jsframework/JS/JSTextRun.js +5 -3
  21. package/Frameworks/Foundation.jsframework/JS/JSTextTypesetter.js +41 -25
  22. package/Frameworks/Foundation.jsframework/JS/String+JS.js +69 -0
  23. package/Frameworks/Foundation.jsframework/JS/UnicodeChar.js +8 -0
  24. package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
  25. package/Frameworks/Foundation.jsframework/sources.json +170 -8
  26. package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
  27. package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
  28. package/Frameworks/SecurityKit.jsframework/sources.json +43 -2
  29. package/Info.json +2 -2
  30. package/Node/Builder.js +20 -9
  31. package/Node/FrameworkBuilder.js +22 -2
  32. package/Node/Project.js +22 -2
  33. package/Node/io.breakside.jskit-bundle.js +2 -2
  34. package/Node/jskit +8 -7
  35. package/Root/Frameworks/APIKit/Info.yaml +1 -1
  36. package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
  37. package/Root/Frameworks/AuthKit/Info.yaml +1 -1
  38. package/Root/Frameworks/CSSOM/Info.yaml +1 -1
  39. package/Root/Frameworks/ChartKit/CHAxis.js +5 -5
  40. package/Root/Frameworks/ChartKit/CHPieChart.js +1 -1
  41. package/Root/Frameworks/ChartKit/Info.yaml +1 -1
  42. package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
  43. package/Root/Frameworks/DBKit/Info.yaml +1 -1
  44. package/Root/Frameworks/DOM/Info.yaml +1 -1
  45. package/Root/Frameworks/DOM/XMLSerializer.js +9 -4
  46. package/Root/Frameworks/Dispatch/Info.yaml +1 -1
  47. package/Root/Frameworks/FontKit/Info.yaml +1 -1
  48. package/Root/Frameworks/Foundation/Info.yaml +1 -1
  49. package/Root/Frameworks/Foundation/JSAttributedString.js +347 -25
  50. package/Root/Frameworks/Foundation/JSFont.js +39 -15
  51. package/Root/Frameworks/Foundation/JSFontDescriptor+HTML.js +8 -0
  52. package/Root/Frameworks/Foundation/JSFontDescriptor.js +105 -27
  53. package/Root/Frameworks/Foundation/JSParagraphStyle.js +71 -0
  54. package/Root/Frameworks/Foundation/JSTextAttachment.js +1 -1
  55. package/Root/Frameworks/Foundation/JSTextContainer.js +56 -29
  56. package/Root/Frameworks/Foundation/JSTextFrame.js +2 -32
  57. package/Root/Frameworks/Foundation/JSTextFramesetter.js +125 -22
  58. package/Root/Frameworks/Foundation/JSTextLayoutManager.js +11 -3
  59. package/Root/Frameworks/Foundation/JSTextLine.js +4 -3
  60. package/Root/Frameworks/Foundation/JSTextRun.js +5 -3
  61. package/Root/Frameworks/Foundation/JSTextTypesetter.js +41 -25
  62. package/Root/Frameworks/Foundation/String+JS.js +69 -0
  63. package/Root/Frameworks/Foundation/UnicodeChar.js +8 -0
  64. package/Root/Frameworks/ImageKit/Info.yaml +1 -1
  65. package/Root/Frameworks/MediaKit/Info.yaml +1 -1
  66. package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
  67. package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
  68. package/Root/Frameworks/PDFKit/Info.yaml +1 -1
  69. package/Root/Frameworks/QRKit/Info.yaml +1 -1
  70. package/Root/Frameworks/SearchKit/Info.yaml +1 -1
  71. package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
  72. package/Root/Frameworks/ServerKit/Info.yaml +1 -1
  73. package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
  74. package/Root/Frameworks/TestKit/Info.yaml +1 -1
  75. package/Root/Frameworks/UIKit/Info.yaml +1 -1
  76. package/Root/Frameworks/UIKit/UIHTMLContentEditableTextInputManager.js +36 -0
  77. package/Root/Frameworks/UIKit/UIHTMLDisplayServer.js +1 -1
  78. package/Root/Frameworks/UIKit/UIHTMLTextField.js +1 -1
  79. package/Root/Frameworks/UIKit/UIHTMLTextFrame.js +19 -91
  80. package/Root/Frameworks/UIKit/UIHTMLTextFramesetter.js +52 -9
  81. package/Root/Frameworks/UIKit/UIHTMLTextLine.js +95 -30
  82. package/Root/Frameworks/UIKit/UIHTMLTextRun.js +22 -9
  83. package/Root/Frameworks/UIKit/UIHTMLTextTypesetter.js +334 -459
  84. package/Root/Frameworks/UIKit/UIHTMLWindowServer.js +16 -0
  85. package/Root/Frameworks/UIKit/UILabel.js +43 -10
  86. package/Root/Frameworks/UIKit/UIScrollView.js +12 -0
  87. package/Root/Frameworks/UIKit/UISegmentedControl.js +6 -6
  88. package/Root/Frameworks/UIKit/UITextAttachmentView.js +1 -1
  89. package/Root/Frameworks/UIKit/UITextEditor.js +210 -25
  90. package/Root/Frameworks/UIKit/UITextField.js +58 -31
  91. package/Root/Frameworks/UIKit/UITextInput.js +3 -1
  92. package/Root/Frameworks/UIKit/UITextInputManager.js +2 -2
  93. package/Root/Frameworks/UIKit/UITextLayer.js +39 -26
  94. package/Root/Frameworks/UIKit/UITokenField.js +4 -4
  95. package/Root/Frameworks/UIKit/UIView.js +3 -1
  96. package/Root/Frameworks/UIKit/UIWindow.js +16 -3
  97. package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
  98. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.DOM",
4
- "JSBundleVersion": "2022.22.2",
4
+ "JSBundleVersion": "2022.24.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
@@ -9,5 +9,5 @@
9
9
  "node": "DOM+Node.js"
10
10
  },
11
11
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
12
- "GitRevision": "a302ede5223899a33db877d1cba370054efd6902"
12
+ "GitRevision": "384e6ac71d317262e4518508066ab61322409ba2"
13
13
  }
@@ -113,10 +113,15 @@ XMLSerializer.prototype = {
113
113
  str += " " + node.name;
114
114
  }
115
115
  if (node.publicId.length > 0){
116
- str += " " + node.publicId;
117
- }
118
- if (node.systemId.length > 0){
119
- str += " " + node.systemId;
116
+ value = node.publicId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
117
+ str += ' PUBLIC "%s"'.sprintf(value);
118
+ if (node.systemId.length > 0){
119
+ value = node.systemId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
120
+ str += ' "%s"'.sprintf(value);
121
+ }
122
+ }else if (node.systemId.length > 0){
123
+ value = node.systemId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
124
+ str += ' SYSTEM "%s"'.sprintf(value);
120
125
  }
121
126
  str += ">\n";
122
127
  }
@@ -3,7 +3,7 @@ JSBundle.bundles['io.breakside.JSKit.DOM'] = {
3
3
  "Info": {
4
4
  "JSBundleType": "framework",
5
5
  "JSBundleIdentifier": "io.breakside.JSKit.DOM",
6
- "JSBundleVersion": "2022.22.2",
6
+ "JSBundleVersion": "2022.24.0",
7
7
  "JSDevelopmentLanguage": "en",
8
8
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
9
9
  "JSBundleEnvironments": {
@@ -11,7 +11,7 @@ JSBundle.bundles['io.breakside.JSKit.DOM'] = {
11
11
  "node": "DOM+Node.js"
12
12
  },
13
13
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
14
- "GitRevision": "a302ede5223899a33db877d1cba370054efd6902"
14
+ "GitRevision": "384e6ac71d317262e4518508066ab61322409ba2"
15
15
  },
16
16
  "Resources": [],
17
17
  "ResourceLookup": {
@@ -4,14 +4,16 @@
4
4
  "files": [
5
5
  "DOM.js"
6
6
  ],
7
- "features": []
7
+ "features": [],
8
+ "globals": []
8
9
  },
9
10
  "html": {
10
11
  "frameworks": [],
11
12
  "files": [
12
13
  "DOM+HTML.js"
13
14
  ],
14
- "features": []
15
+ "features": [],
16
+ "globals": []
15
17
  },
16
18
  "node": {
17
19
  "frameworks": [
@@ -33,6 +35,11 @@
33
35
  "XMLSerializer.js",
34
36
  "DOM+Node.js"
35
37
  ],
36
- "features": []
38
+ "features": [],
39
+ "globals": [
40
+ "DOM",
41
+ "DOMParser",
42
+ "XMLSerializer"
43
+ ]
37
44
  }
38
45
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.FontKit",
4
- "JSBundleVersion": "2022.22.2",
4
+ "JSBundleVersion": "2022.24.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
8
8
  "html": "FontKit+HTML.js"
9
9
  },
10
10
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
11
- "GitRevision": "a302ede5223899a33db877d1cba370054efd6902"
11
+ "GitRevision": "384e6ac71d317262e4518508066ab61322409ba2"
12
12
  }
@@ -3,14 +3,14 @@ JSBundle.bundles['io.breakside.JSKit.FontKit'] = {
3
3
  "Info": {
4
4
  "JSBundleType": "framework",
5
5
  "JSBundleIdentifier": "io.breakside.JSKit.FontKit",
6
- "JSBundleVersion": "2022.22.2",
6
+ "JSBundleVersion": "2022.24.0",
7
7
  "JSDevelopmentLanguage": "en",
8
8
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
9
9
  "JSBundleEnvironments": {
10
10
  "html": "FontKit+HTML.js"
11
11
  },
12
12
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
13
- "GitRevision": "a302ede5223899a33db877d1cba370054efd6902"
13
+ "GitRevision": "384e6ac71d317262e4518508066ab61322409ba2"
14
14
  },
15
15
  "Resources": [],
16
16
  "ResourceLookup": {
@@ -12,7 +12,38 @@
12
12
  "FNTFontDescriptor.js",
13
13
  "FontKit.js"
14
14
  ],
15
- "features": []
15
+ "features": [],
16
+ "globals": [
17
+ "FNTOpenTypeFont",
18
+ "FNTOpenTypeFontTable",
19
+ "FNTOpenTypeFontTableHead",
20
+ "FNTOpenTypeFontTableName",
21
+ "FNTOpenTypeFontTableHhea",
22
+ "FNTOpenTypeFontTableHmtx",
23
+ "FNTOpenTypeFontTableCmap",
24
+ "FNTOpenTypeFontTableOS2",
25
+ "FNTOpenTypeFontTableMaxp",
26
+ "FNTOpenTypeFontTablePost",
27
+ "FNTOpenTypeFontTableCFF",
28
+ "FNTOpenTypeFontTableGlyf",
29
+ "FNTOpenTypeFontTableLoca",
30
+ "FNTOpenTypeFontCmap",
31
+ "FNTOpenTypeFontCmapNull",
32
+ "FNTOpenTypeFontCmap0",
33
+ "FNTOpenTypeFontCmap4",
34
+ "FNTOpenTypeFontCmap6",
35
+ "FNTOpenTypeFontCmap10",
36
+ "FNTOpenTypeFontCmap12",
37
+ "FNTOpenTypeFontCmap13",
38
+ "FNTOpenTypeGlyph",
39
+ "FNTOpenTypeSimpleGlyph",
40
+ "FNTOpenTypeCompoundGlyph",
41
+ "FNTOpenTypeConstructor",
42
+ "FNTType1Font",
43
+ "FNTAdobeNamesToUnicode",
44
+ "FNTCompactFontFormat",
45
+ "FNTFontDescriptor"
46
+ ]
16
47
  },
17
48
  "html": {
18
49
  "frameworks": [],
@@ -20,6 +51,7 @@
20
51
  "FNTFontDescriptor+HTML.js",
21
52
  "FontKit+HTML.js"
22
53
  ],
23
- "features": []
54
+ "features": [],
55
+ "globals": []
24
56
  }
25
57
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.Foundation",
4
- "JSBundleVersion": "2022.22.2",
4
+ "JSBundleVersion": "2022.24.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
@@ -9,5 +9,5 @@
9
9
  "node": "Foundation+Node.js"
10
10
  },
11
11
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
12
- "GitRevision": "a302ede5223899a33db877d1cba370054efd6902"
12
+ "GitRevision": "384e6ac71d317262e4518508066ab61322409ba2"
13
13
  }
@@ -16,6 +16,8 @@
16
16
  // #import "Javascript.js"
17
17
  // #import "JSObject.js"
18
18
  // #import "JSTextAttachment.js"
19
+ // #import "JSFont.js"
20
+ // #import "JSColor.js"
19
21
  'use strict';
20
22
 
21
23
  (function(){
@@ -40,6 +42,137 @@ JSClass("JSAttributedString", JSObject, {
40
42
  this._runs = [run];
41
43
  },
42
44
 
45
+ initFromDictionary: function(dictionary){
46
+ this._string = typeof(dictionary.string) === "string" ? dictionary.string : "";
47
+ this._runs = [];
48
+ var i, l;
49
+ var runDictionary;
50
+ var run;
51
+ var attributes;
52
+ var name;
53
+ var location = 0;
54
+ var length;
55
+ var maxLength = this._string.length;
56
+ var decodeAttribute = function(name, value){
57
+ switch (name){
58
+ case JSAttributedString.Attribute.font:
59
+ return JSAttributedString.AttributeDecoder.font(value);
60
+ case JSAttributedString.Attribute.textColor:
61
+ case JSAttributedString.Attribute.backgroundColor:
62
+ return JSAttributedString.AttributeDecoder.color(value);
63
+ case JSAttributedString.Attribute.link:
64
+ return JSAttributedString.AttributeDecoder.url(value);
65
+ case JSAttributedString.Attribute.cursor:
66
+ return JSAttributedString.AttributeDecoder.skip(value);
67
+ case JSAttributedString.Attribute.attachment:
68
+ // TODO:
69
+ return JSAttributedString.AttributeDecoder.skip(value);
70
+ case JSAttributedString.Attribute.maskCharacter:
71
+ case JSAttributedString.Attribute.paragraphStyleName:
72
+ return JSAttributedString.AttributeDecoder.string(value);
73
+ case JSAttributedString.Attribute.bold:
74
+ case JSAttributedString.Attribute.italic:
75
+ case JSAttributedString.Attribute.underline:
76
+ case JSAttributedString.Attribute.strike:
77
+ return JSAttributedString.AttributeDecoder.boolean(value);
78
+ case JSAttributedString.Attribute.lineHeightMultiple:
79
+ case JSAttributedString.Attribute.lineSpacing:
80
+ case JSAttributedString.Attribute.paragraphSpacing:
81
+ case JSAttributedString.Attribute.beforeParagraphSpacing:
82
+ case JSAttributedString.Attribute.firstLineHeadIndent:
83
+ case JSAttributedString.Attribute.headIndent:
84
+ case JSAttributedString.Attribute.tailIndent:
85
+ case JSAttributedString.Attribute.minimumLineHeight:
86
+ return JSAttributedString.AttributeDecoder.number(value);
87
+ case JSAttributedString.Attribute.textAlignment:
88
+ return JSAttributedString.AttributeDecoder.enumValue(JSTextAlignment)(value);
89
+ case JSAttributedString.Attribute.lineBreakMode:
90
+ return JSAttributedString.AttributeDecoder.enumName(JSLineBreakMode)(value);
91
+ default:
92
+ return value;
93
+ }
94
+
95
+ };
96
+ if (dictionary.runs instanceof Array){
97
+ for (i = 0, l = dictionary.runs.length; i < l && maxLength > 0; ++i){
98
+ runDictionary = dictionary.runs[i];
99
+ attributes = {};
100
+ length = typeof(runDictionary.length) === "number" ? Math.min(maxLength, Math.floor(runDictionary.length)) : 0;
101
+ if (length > 0 && typeof(runDictionary.attributes) === "object"){
102
+ for (name in runDictionary.attributes){
103
+ attributes[name] = decodeAttribute(name, runDictionary.attributes[name]);
104
+ }
105
+ this._runs.push(JSAttributedStringRun(JSRange(location, length), attributes));
106
+ }
107
+ location += length;
108
+ maxLength -= length;
109
+ }
110
+ }
111
+ if (maxLength > 0){
112
+ this._runs.push(JSAttributedStringRun(JSRange(location, maxLength), {}));
113
+ }
114
+ if (this._runs.length === 0){
115
+ this._runs.push(JSAttributedStringRun(JSRange(0, 0), {}));
116
+ }
117
+ },
118
+
119
+ dictionaryRepresentation: function(){
120
+ var dictionary = {
121
+ string: this._string,
122
+ runs: []
123
+ };
124
+ var i, l;
125
+ var run;
126
+ var name;
127
+ var runDictionary;
128
+ var encodeAttribute = function(name, value){
129
+ switch (name){
130
+ case JSAttributedString.Attribute.font:
131
+ return JSAttributedString.AttributeEncoder.font(value);
132
+ case JSAttributedString.Attribute.textColor:
133
+ case JSAttributedString.Attribute.backgroundColor:
134
+ return JSAttributedString.AttributeEncoder.color(value);
135
+ case JSAttributedString.Attribute.link:
136
+ return JSAttributedString.AttributeEncoder.url(value);
137
+ case JSAttributedString.Attribute.cursor:
138
+ return JSAttributedString.Attribute.Encoder.skip(value);
139
+ case JSAttributedString.Attribute.attachment:
140
+ // TODO:
141
+ return JSAttributedString.Attribute.Encoder.skip(value);
142
+ case JSAttributedString.Attribute.bold:
143
+ case JSAttributedString.Attribute.italic:
144
+ case JSAttributedString.Attribute.underline:
145
+ case JSAttributedString.Attribute.strike:
146
+ case JSAttributedString.Attribute.lineHeightMultiple:
147
+ case JSAttributedString.Attribute.minimumLineHeight:
148
+ case JSAttributedString.Attribute.lineSpacing:
149
+ case JSAttributedString.Attribute.paragraphSpacing:
150
+ case JSAttributedString.Attribute.beforeParagraphSpacing:
151
+ case JSAttributedString.Attribute.firstLineHeadIndent:
152
+ case JSAttributedString.Attribute.headIndent:
153
+ case JSAttributedString.Attribute.tailIndent:
154
+ case JSAttributedString.Attribute.textAlignment:
155
+ case JSAttributedString.Attribute.lineBreakMode:
156
+ case JSAttributedString.Attribute.maskCharacter:
157
+ case JSAttributedString.Attribute.paragraphStyleName:
158
+ default:
159
+ return value;
160
+ }
161
+ };
162
+ for (i = 0, l = this._runs.length; i < l; ++i){
163
+ run = this._runs[i];
164
+ runDictionary = {
165
+ length: run.range.length,
166
+ attributes: {}
167
+ };
168
+ for (name in run.attributes){
169
+ runDictionary.attributes[name] = encodeAttribute(name, run.attributes[name]);
170
+ }
171
+ dictionary.runs.push(runDictionary);
172
+ }
173
+ return dictionary;
174
+ },
175
+
43
176
  initWithAttributedString: function(attributedString, defaultAttributes){
44
177
  this._string = attributedString.string;
45
178
  this._runs = [];
@@ -213,6 +346,8 @@ JSClass("JSAttributedString", JSObject, {
213
346
  }
214
347
  this._fixRunsAtIndex(runIndex);
215
348
  this._fixRunsAtIndex(runRange.location);
349
+ this._fixParagraphAttributesAtIndex(range.location);
350
+ this._fixParagraphAttributesAtIndex(range.location + attributedString.string.length);
216
351
  },
217
352
 
218
353
  // MARK: - Attribute mutations
@@ -294,6 +429,44 @@ JSClass("JSAttributedString", JSObject, {
294
429
  return new JSAttributedStringRunIterator(this, index);
295
430
  },
296
431
 
432
+ longestRangeOfAttributeAtIndex: function(attributeName, index){
433
+ return this.longestRangeOfAttributesAtIndex([attributeName], index);
434
+ },
435
+
436
+ longestRangeOfAttributesAtIndex: function(attributeNames, index){
437
+ var runIndex = this._runIndexForStringIndex(index);
438
+ var run = this._runs[runIndex];
439
+ var range = JSRange(run.range);
440
+ var attributes = {};
441
+ var i, l;
442
+ for (i = 0, l = attributeNames.length; i < l; ++i){
443
+ attributes[attributeNames[i]] = run.attributes[attributeNames[i]];
444
+ }
445
+ i = runIndex - 1;
446
+ while (i >= 0){
447
+ run = this._runs[i];
448
+ if (run.containsEqualAttributes(attributes)){
449
+ range.length = range.end - run.range.location;
450
+ range.location = run.range.location;
451
+ }else{
452
+ break;
453
+ }
454
+ --i;
455
+ }
456
+ i = runIndex + 1;
457
+ l = this._runs.length;
458
+ while (i < l){
459
+ run = this._runs[i];
460
+ if (run.containsEqualAttributes(attributes)){
461
+ range.length = run.range.end - range.location;
462
+ }else{
463
+ break;
464
+ }
465
+ ++i;
466
+ }
467
+ return range;
468
+ },
469
+
297
470
  // MARK: - Formatting
298
471
 
299
472
  replaceFormat: function(){
@@ -339,7 +512,7 @@ JSClass("JSAttributedString", JSObject, {
339
512
  var runA;
340
513
  for (var runIndex = lastRunIndex - 1; runIndex >= expandedRunRange.location; --runIndex){
341
514
  runA = this._runs[runIndex];
342
- if (runA.hasIdenticalAttributes(runB)){
515
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
343
516
  this._runs.splice(runIndex, 1);
344
517
  runB.range.location = runA.range.location;
345
518
  runB.range.length += runA.range.length;
@@ -358,12 +531,50 @@ JSClass("JSAttributedString", JSObject, {
358
531
  }
359
532
  var runA = this._runs[runIndex - 1];
360
533
  var runB = this._runs[runIndex];
361
- if (runA.hasIdenticalAttributes(runB)){
534
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
362
535
  this._runs.splice(runIndex, 1);
363
536
  runA.range.length += runB.range.length;
364
537
  }
365
538
  },
366
539
 
540
+ _fixParagraphAttributesAtIndex: function(index){
541
+ if (index >= this._string.length){
542
+ return;
543
+ }
544
+ var paragraphRange = this._string.rangeForParagraphAtIndex(index);
545
+ var runIndex = this._runIndexForStringIndex(paragraphRange.location);
546
+ var run = this._runs[runIndex];
547
+ var paragraphAttributes = run.attributes;
548
+ var copy;
549
+ var i, l;
550
+ var attribute;
551
+ var value;
552
+ while (run.range.end < paragraphRange.end && runIndex < this._runs.length){
553
+ run = this._runs[runIndex];
554
+ if (!run.containsEqualParagraphAttributes(paragraphAttributes)){
555
+ if (run.range.end > paragraphRange.end){
556
+ copy = JSAttributedStringRun(JSRange(paragraphRange.end, run.range.end - paragraphRange.end), run.attributes);
557
+ this._runs.splice(runIndex + 1, 0, copy);
558
+ run.range.length -= copy.range.length;
559
+ }
560
+ for (i = 0, l = JSAttributedString.paragraphAttributes.length; i < l; ++i){
561
+ attribute = JSAttributedString.paragraphAttributes[i];
562
+ if (attribute in paragraphAttributes){
563
+ run.attributes[attribute] = paragraphAttributes[attribute];
564
+ }else{
565
+ delete run.attributes[attribute];
566
+ }
567
+ }
568
+ if (this._runs[runIndex - 1].onlyContainsEqualAttributes(run.attributes)){
569
+ this._runs[runIndex - 1].range.length += run.range.length;
570
+ this._runs.splice(runIndex, 1);
571
+ --runIndex;
572
+ }
573
+ }
574
+ ++runIndex;
575
+ }
576
+ },
577
+
367
578
  _rangeOfRunsPreparedForChangeInStringRange: function(range){
368
579
  var firstRunIndex = this._splitRunAtIndex(range.location);
369
580
  if (range.length > 0){
@@ -434,13 +645,84 @@ JSAttributedString.Attribute = {
434
645
  underline: "underline",
435
646
  strike: "strike",
436
647
  attachment: "attachment",
437
- lineHeight: "lineHeight",
438
- lineSpacing: "lineSpacing",
439
- textAlignment: "textAlignment",
440
- lineBreakMode: "lineBreakMode",
441
648
  maskCharacter: "maskCharacter",
442
649
  cursor: "cursor",
443
- link: "link"
650
+ link: "link",
651
+
652
+ // Paragraph
653
+ paragraphStyleName: "paragraphStyleName",
654
+ textAlignment: "textAlignment",
655
+ lineBreakMode: "lineBreakMode",
656
+ minimumLineHeight: "minimumLineHeight",
657
+ lineHeightMultiple: "lineHeightMultiple",
658
+ lineSpacing: "lineSpacing",
659
+ paragraphSpacing: "paragraphSpacing",
660
+ beforeParagraphSpacing: "beforeParagraphSpacing",
661
+ firstLineHeadIndent: "firstLineHeadIndent",
662
+ headIndent: "headIndent",
663
+ tailIndent: "tailIndent",
664
+ };
665
+
666
+ JSAttributedString.paragraphAttributes = [
667
+ JSAttributedString.Attribute.paragraphStyleName,
668
+ JSAttributedString.Attribute.textAlignment,
669
+ JSAttributedString.Attribute.lineBreakMode,
670
+ JSAttributedString.Attribute.minimumLineHeight,
671
+ JSAttributedString.Attribute.lineHeightMultiple,
672
+ JSAttributedString.Attribute.lineSpacing,
673
+ JSAttributedString.Attribute.paragraphSpacing,
674
+ JSAttributedString.Attribute.beforeParagraphSpacing,
675
+ JSAttributedString.Attribute.firstLineHeadIndent,
676
+ JSAttributedString.Attribute.headIndent,
677
+ JSAttributedString.Attribute.tailIndent
678
+ ];
679
+
680
+ JSAttributedString.AttributeEncoder = {
681
+ skip: function(value){ return undefined; },
682
+ identity: function(value){ return value; },
683
+ dataBase64: function(value){ return value.base64StringRepresentation(); },
684
+ dataBase64URL: function(value){ return value.base64URLStringRepresentation(); },
685
+ dataHex: function(value){ return value.hexStringRepresentation(); },
686
+ url: function(value){ return value.encodedString; },
687
+ font: function(value){ return value.dictionaryRepresentation(); },
688
+ color: function(value){ return value.dictionaryRepresentation(); },
689
+ enumName: function(obj){
690
+ return function(value){
691
+ for (var name in obj){
692
+ if (obj[name] === value){
693
+ return name;
694
+ }
695
+ }
696
+ };
697
+ }
698
+ };
699
+
700
+ JSAttributedString.AttributeDecoder = {
701
+ skip: function(value){ return undefined; },
702
+ identity: function(value){ return value; },
703
+ dataBase64: function(value){ return value.dataByDecodingBase64(); },
704
+ dataBase64URL: function(value){ return value.dataByDecodingBase64URL(); },
705
+ dataHex: function(value){ return value.dataByDecodingHex(); },
706
+ url: function(value){ return JSURL.initWithString(value); },
707
+ font: function(value){ return JSFont.initFromDictionary(value); },
708
+ color: function(value){ return JSColor.initFromDictionary(value); },
709
+ boolean: function(value){ return typeof(value) === "boolean" ? value : undefined; },
710
+ number: function(value){ return typeof(value) === "number" ? value : undefined; },
711
+ string: function(value){ return typeof(value) === "string" ? value : undefined; },
712
+ enumName: function(obj){
713
+ return function(value){
714
+ return obj[value];
715
+ };
716
+ },
717
+ enumValue: function(obj){
718
+ return function(value){
719
+ for (var name in obj){
720
+ if (obj[name] === value){
721
+ return value;
722
+ }
723
+ }
724
+ };
725
+ }
444
726
  };
445
727
 
446
728
  JSAttributedString.SpecialCharacter = {
@@ -471,30 +753,70 @@ function JSAttributedStringRun(range, attributes){
471
753
 
472
754
  JSAttributedStringRun.prototype = {
473
755
 
474
- hasIdenticalAttributes: function(other){
756
+ containsEqualAttributes: function(attributes){
475
757
  var attribute;
476
758
  var a, b;
477
- for (attribute in this.attributes){
478
- if (attribute in other.attributes){
479
- a = this.attributes[attribute];
480
- b = other.attributes[attribute];
481
- if (a.isEqual){
482
- if (!a.isEqual(b)){
483
- return false;
484
- }
485
- }else if (b.isEqual){
486
- if (!b.isEqual(a)){
487
- return false;
488
- }
489
- }else if (a != b){
759
+ for (attribute in attributes){
760
+ a = attributes[attribute];
761
+ b = this.attributes[attribute];
762
+ if (a === undefined){
763
+ if (!!b){
490
764
  return false;
491
765
  }
492
- }else{
766
+ }else if (a === null){
767
+ if (b !== null && b !== undefined){
768
+ return false;
769
+ }
770
+ }else if (a.isEqual){
771
+ if (b === null || b === undefined){
772
+ return false;
773
+ }
774
+ if (!a.isEqual(b)){
775
+ return false;
776
+ }
777
+ }else if (a != b){
493
778
  return false;
494
779
  }
495
780
  }
496
- for (attribute in other.attributes){
497
- if (!(attribute in this.attributes)){
781
+ return true;
782
+ },
783
+
784
+ onlyContainsEqualAttributes: function(attributes){
785
+ if (!this.containsEqualAttributes(attributes)){
786
+ return false;
787
+ }
788
+ var attribute;
789
+ for (attribute in this.attributes){
790
+ if (!(attribute in attributes)){
791
+ return false;
792
+ }
793
+ }
794
+ return true;
795
+ },
796
+
797
+ containsEqualParagraphAttributes: function(attributes){
798
+ var attribute;
799
+ var a, b;
800
+ for (var i = 0, l = JSAttributedString.paragraphAttributes.length; i < l; ++i){
801
+ attribute = JSAttributedString.paragraphAttributes[i];
802
+ a = attributes[attribute];
803
+ b = this.attributes[attribute];
804
+ if (a === undefined){
805
+ if (!!b){
806
+ return false;
807
+ }
808
+ }else if (a === null){
809
+ if (b !== null && b !== undefined){
810
+ return false;
811
+ }
812
+ }else if (a.isEqual){
813
+ if (b === null || b === undefined){
814
+ return false;
815
+ }
816
+ if (!a.isEqual(b)){
817
+ return false;
818
+ }
819
+ }else if (a != b){
498
820
  return false;
499
821
  }
500
822
  }
@@ -571,7 +893,7 @@ Object.defineProperties(JSAttributedStringRunIterator.prototype, {
571
893
  return null;
572
894
  }
573
895
  var run = this._attributedString._runs[this._runIndex];
574
- if (run.range.length === 1 && this._attributedString.charCodeAt(run.range.location) === JSAttributedString.SpecialCharacter.attachment){
896
+ if (run.range.length === 1 && this._attributedString.string.charCodeAt(run.range.location) === JSAttributedString.SpecialCharacter.attachment){
575
897
  return run.attributes[JSAttributedString.Attribute.attachment];
576
898
  }
577
899
  return null;