@breakside/jskit 2022.22.3 → 2022.23.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 (49) 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/FontKit.jsframework/Info.json +2 -2
  5. package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
  6. package/Frameworks/Foundation.jsframework/Info.json +2 -2
  7. package/Frameworks/Foundation.jsframework/JS/JSAttributedString.js +144 -0
  8. package/Frameworks/Foundation.jsframework/JS/JSFont.js +39 -15
  9. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor+HTML.js +8 -0
  10. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor.js +105 -27
  11. package/Frameworks/Foundation.jsframework/JS/String+JS.js +34 -0
  12. package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
  13. package/Frameworks/Foundation.jsframework/sources.json +23 -22
  14. package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
  15. package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
  16. package/Info.json +2 -2
  17. package/Node/io.breakside.jskit-bundle.js +2 -2
  18. package/Node/jskit +7 -7
  19. package/Root/Frameworks/APIKit/Info.yaml +1 -1
  20. package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
  21. package/Root/Frameworks/AuthKit/Info.yaml +1 -1
  22. package/Root/Frameworks/CSSOM/Info.yaml +1 -1
  23. package/Root/Frameworks/ChartKit/Info.yaml +1 -1
  24. package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
  25. package/Root/Frameworks/DBKit/Info.yaml +1 -1
  26. package/Root/Frameworks/DOM/Info.yaml +1 -1
  27. package/Root/Frameworks/DOM/XMLSerializer.js +9 -4
  28. package/Root/Frameworks/Dispatch/Info.yaml +1 -1
  29. package/Root/Frameworks/FontKit/Info.yaml +1 -1
  30. package/Root/Frameworks/Foundation/Info.yaml +1 -1
  31. package/Root/Frameworks/Foundation/JSAttributedString.js +144 -0
  32. package/Root/Frameworks/Foundation/JSFont.js +39 -15
  33. package/Root/Frameworks/Foundation/JSFontDescriptor+HTML.js +8 -0
  34. package/Root/Frameworks/Foundation/JSFontDescriptor.js +105 -27
  35. package/Root/Frameworks/Foundation/String+JS.js +34 -0
  36. package/Root/Frameworks/ImageKit/Info.yaml +1 -1
  37. package/Root/Frameworks/MediaKit/Info.yaml +1 -1
  38. package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
  39. package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
  40. package/Root/Frameworks/PDFKit/Info.yaml +1 -1
  41. package/Root/Frameworks/QRKit/Info.yaml +1 -1
  42. package/Root/Frameworks/SearchKit/Info.yaml +1 -1
  43. package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
  44. package/Root/Frameworks/ServerKit/Info.yaml +1 -1
  45. package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
  46. package/Root/Frameworks/TestKit/Info.yaml +1 -1
  47. package/Root/Frameworks/UIKit/Info.yaml +1 -1
  48. package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
  49. 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.3",
4
+ "JSBundleVersion": "2022.23.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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
12
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
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.3",
6
+ "JSBundleVersion": "2022.23.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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
14
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
15
15
  },
16
16
  "Resources": [],
17
17
  "ResourceLookup": {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.FontKit",
4
- "JSBundleVersion": "2022.22.3",
4
+ "JSBundleVersion": "2022.23.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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
11
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
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.3",
6
+ "JSBundleVersion": "2022.23.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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
13
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
14
14
  },
15
15
  "Resources": [],
16
16
  "ResourceLookup": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.Foundation",
4
- "JSBundleVersion": "2022.22.3",
4
+ "JSBundleVersion": "2022.23.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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
12
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
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,123 @@ 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
+ return JSAttributedString.AttributeDecoder.string(value);
72
+ case JSAttributedString.Attribute.bold:
73
+ case JSAttributedString.Attribute.italic:
74
+ case JSAttributedString.Attribute.underline:
75
+ case JSAttributedString.Attribute.strike:
76
+ return JSAttributedString.AttributeDecoder.boolean(value);
77
+ case JSAttributedString.Attribute.lineHeight:
78
+ case JSAttributedString.Attribute.lineSpacing:
79
+ return JSAttributedString.AttributeDecoder.number(value);
80
+ case JSAttributedString.Attribute.textAlignment:
81
+ // TODO: validate
82
+ case JSAttributedString.Attribute.lineBreakMode:
83
+ // TODO: validate
84
+ default:
85
+ return value;
86
+ }
87
+
88
+ };
89
+ if (dictionary.runs instanceof Array){
90
+ for (i = 0, l = dictionary.runs.length; i < l && maxLength > 0; ++i){
91
+ runDictionary = dictionary.runs[i];
92
+ attributes = {};
93
+ length = typeof(runDictionary.length) === "number" ? Math.min(maxLength, Math.floor(runDictionary.length)) : 0;
94
+ if (length > 0 && typeof(runDictionary.attributes) === "object"){
95
+ for (name in runDictionary.attributes){
96
+ attributes[name] = decodeAttribute(name, runDictionary.attributes[name]);
97
+ }
98
+ this._runs.push(JSAttributedStringRun(JSRange(location, length), attributes));
99
+ }
100
+ location += length;
101
+ maxLength -= length;
102
+ }
103
+ }
104
+ if (maxLength > 0){
105
+ this._runs.push(JSAttributedStringRun(JSRange(location, maxLength), {}));
106
+ }
107
+ if (this._runs.length === 0){
108
+ this._runs.push(JSAttributedStringRun(JSRange(0, 0), {}));
109
+ }
110
+ },
111
+
112
+ dictionaryRepresentation: function(){
113
+ var dictionary = {
114
+ string: this._string,
115
+ runs: []
116
+ };
117
+ var i, l;
118
+ var run;
119
+ var name;
120
+ var runDictionary;
121
+ var encodeAttribute = function(name, value){
122
+ switch (name){
123
+ case JSAttributedString.Attribute.font:
124
+ return JSAttributedString.AttributeEncoder.font(value);
125
+ case JSAttributedString.Attribute.textColor:
126
+ case JSAttributedString.Attribute.backgroundColor:
127
+ return JSAttributedString.AttributeEncoder.color(value);
128
+ case JSAttributedString.Attribute.link:
129
+ return JSAttributedString.AttributeEncoder.url(value);
130
+ case JSAttributedString.Attribute.cursor:
131
+ return JSAttributedString.Attribute.Encoder.skip(value);
132
+ case JSAttributedString.Attribute.attachment:
133
+ // TODO:
134
+ return JSAttributedString.Attribute.Encoder.skip(value);
135
+ case JSAttributedString.Attribute.bold:
136
+ case JSAttributedString.Attribute.italic:
137
+ case JSAttributedString.Attribute.underline:
138
+ case JSAttributedString.Attribute.strike:
139
+ case JSAttributedString.Attribute.lineHeight:
140
+ case JSAttributedString.Attribute.lineSpacing:
141
+ case JSAttributedString.Attribute.textAlignment:
142
+ case JSAttributedString.Attribute.lineBreakMode:
143
+ case JSAttributedString.Attribute.maskCharacter:
144
+ default:
145
+ return value;
146
+ }
147
+ };
148
+ for (i = 0, l = this._runs.length; i < l; ++i){
149
+ run = this._runs[i];
150
+ runDictionary = {
151
+ length: run.range.length,
152
+ attributes: {}
153
+ };
154
+ for (name in run.attributes){
155
+ runDictionary.attributes[name] = encodeAttribute(name, run.attributes[name]);
156
+ }
157
+ dictionary.runs.push(runDictionary);
158
+ }
159
+ return dictionary;
160
+ },
161
+
43
162
  initWithAttributedString: function(attributedString, defaultAttributes){
44
163
  this._string = attributedString.string;
45
164
  this._runs = [];
@@ -481,6 +600,31 @@ JSAttributedString.Attribute = {
481
600
  link: "link"
482
601
  };
483
602
 
603
+ JSAttributedString.AttributeEncoder = {
604
+ skip: function(value){ return undefined; },
605
+ identity: function(value){ return value; },
606
+ dataBase64: function(value){ return value.base64StringRepresentation(); },
607
+ dataBase64URL: function(value){ return value.base64URLStringRepresentation(); },
608
+ dataHex: function(value){ return value.hexStringRepresentation(); },
609
+ url: function(value){ return value.encodedString; },
610
+ font: function(value){ return value.dictionaryRepresentation(); },
611
+ color: function(value){ return value.dictionaryRepresentation(); },
612
+ };
613
+
614
+ JSAttributedString.AttributeDecoder = {
615
+ skip: function(value){ return undefined; },
616
+ identity: function(value){ return value; },
617
+ dataBase64: function(value){ return value.dataByDecodingBase64(); },
618
+ dataBase64URL: function(value){ return value.dataByDecodingBase64URL(); },
619
+ dataHex: function(value){ return value.dataByDecodingHex(); },
620
+ url: function(value){ return JSURL.initWithString(value); },
621
+ font: function(value){ return JSFont.initFromDictionary(value); },
622
+ color: function(value){ return JSColor.initFromDictionary(value); },
623
+ boolean: function(value){ return typeof(value) === "boolean" ? value : undefined; },
624
+ number: function(value){ return typeof(value) === "number" ? value : undefined; },
625
+ string: function(value){ return typeof(value) === "string" ? value : undefined; },
626
+ };
627
+
484
628
  JSAttributedString.SpecialCharacter = {
485
629
  attachment: 0xFFFC,
486
630
  attachmentUTF16: "\uFFFC"
@@ -49,7 +49,7 @@ JSClass("JSFont", JSObject, {
49
49
  var weight;
50
50
  var style;
51
51
  var size;
52
- var defaults = JSFont._systemFontDescriptor;
52
+ var defaults = JSFontDescriptor.system;
53
53
  // if ('descriptor' in values){
54
54
  // values = values.descriptor;
55
55
  // }
@@ -78,7 +78,7 @@ JSClass("JSFont", JSObject, {
78
78
  size = JSFont.Size.normal;
79
79
  }
80
80
  if (family){
81
- var descriptor = JSResourceFontDescriptor.descriptorWithFamily(family, weight, style);
81
+ var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight, style);
82
82
  if (descriptor !== null){
83
83
  return JSFont.initWithDescriptor(descriptor, size);
84
84
  }
@@ -86,6 +86,30 @@ JSClass("JSFont", JSObject, {
86
86
  return null;
87
87
  },
88
88
 
89
+ initFromDictionary: function(dictionary){
90
+ var descriptor = JSFontDescriptor.descriptorWithFamily(dictionary.family, dictionary.weight, dictionary.style);
91
+ if (descriptor === null){
92
+ if (dictionary.url){
93
+ descriptor = JSURLFontDescriptor.initWithURL(JSURL.initWithString(dictionary.url), dictionary.family, dictionary.weight, dictionary.style);
94
+ JSFontDescriptor.registerDescriptor(descriptor);
95
+ }
96
+ }
97
+ if (descriptor !== null){
98
+ return JSFont.initWithDescriptor(descriptor, dictionary.size);
99
+ }
100
+ return null;
101
+ },
102
+
103
+ dictionaryRepresentation: function(){
104
+ return {
105
+ url: this.descriptor instanceof JSURLFontDescriptor ? this._descriptor.url : undefined,
106
+ family: this._descriptor.family,
107
+ weight: this._descriptor.weight,
108
+ style: this._descriptor.style,
109
+ size: this.pointSize
110
+ };
111
+ },
112
+
89
113
  getFullName: function(){
90
114
  return this._descriptor.name;
91
115
  },
@@ -187,7 +211,7 @@ JSClass("JSFont", JSObject, {
187
211
  });
188
212
 
189
213
  JSFont.fontWithFamily = function(family, pointSize, weight, style){
190
- var descriptor = JSResourceFontDescriptor.descriptorWithFamily(family, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
214
+ var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
191
215
  return JSFont.initWithDescriptor(descriptor, pointSize);
192
216
  };
193
217
 
@@ -204,12 +228,12 @@ JSFont.registerBundleFonts = function(bundle){
204
228
 
205
229
  JSFont._registerFontResource = function(bundle, metadata){
206
230
  var descriptor = JSResourceFontDescriptor.initWithMetadata(bundle, metadata);
231
+ JSFontDescriptor.registerDescriptor(descriptor);
207
232
  return descriptor;
208
233
  };
209
234
 
210
- JSFont._systemFontDescriptor = null;
211
-
212
- JSFont.registerSystemFontResource = function(name){
235
+ JSFont.registerSystemFontResource = function(name, bundle){
236
+ bundle = bundle || JSBundle.mainBundle;
213
237
  var ext;
214
238
  var extIndex = name.lastIndexOf('.');
215
239
  var i, l;
@@ -221,33 +245,33 @@ JSFont.registerSystemFontResource = function(name){
221
245
  extGuessed = true;
222
246
  ext = "ttf";
223
247
  }
224
- var metadata = JSBundle.mainBundle.metadataForResourceName(name, ext);
248
+ var metadata = bundle.metadataForResourceName(name, ext);
225
249
  if (extGuessed && metadata === null){
226
250
  ext = "otf";
227
- metadata = JSBundle.mainBundle.metadataForResourceName(name, ext);
251
+ metadata = bundle.metadataForResourceName(name, ext);
228
252
  }
229
- this._systemFontDescriptor = JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier];
253
+ JSFontDescriptor.system = JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier];
230
254
  };
231
255
 
232
256
  JSFont.registerSystemFont = function(familyName, weight, style){
233
- this._systemFontDescriptor = JSResourceFontDescriptor.descriptorWithFamily(familyName, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
257
+ JSFontDescriptor.system = JSFontDescriptor.descriptorWithFamily(familyName, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
234
258
  };
235
259
 
236
260
  JSFont.registerSystemFontDescriptor = function(descriptor){
237
- this._systemFontDescriptor = descriptor;
261
+ JSFontDescriptor.system = descriptor;
238
262
  };
239
263
 
240
264
  JSFont.unregisterAllFonts = function(){
241
- JSResourceFontDescriptor.descriptorsByFamily = {};
265
+ JSFontDescriptor.descriptorsByFamily = {};
242
266
  JSResourceFontDescriptor.descriptorsByName = {};
243
- this._systemFontDescriptor = null;
267
+ JSFontDescriptor.system = null;
244
268
  };
245
269
 
246
270
  JSFont.systemFontOfSize = function(pointSize){
247
- if (this._systemFontDescriptor === null){
271
+ if (JSFontDescriptor.system === null){
248
272
  return null;
249
273
  }
250
- return JSFont.initWithDescriptor(this._systemFontDescriptor, pointSize);
274
+ return JSFont.initWithDescriptor(JSFontDescriptor.system, pointSize);
251
275
  };
252
276
 
253
277
  JSFont.Size = {
@@ -94,4 +94,12 @@ JSDataFontDescriptor.definePropertiesFromExtensions({
94
94
 
95
95
  });
96
96
 
97
+ JSURLFontDescriptor.definePropertiesFromExtensions({
98
+
99
+ htmlURLString: function(){
100
+ return this.url.encodedString;
101
+ }
102
+
103
+ });
104
+
97
105
  })();
@@ -18,6 +18,8 @@
18
18
  // #import "UnicodeChar.js"
19
19
  // #import "Zlib.js"
20
20
  // #import "CoreTypes.js"
21
+ // #import "JSURLSession.js"
22
+ /* global JSFont */
21
23
  'use strict';
22
24
 
23
25
  (function(){
@@ -38,11 +40,11 @@ JSClass("JSFontDescriptor", JSObject, {
38
40
  unitsPerEM: JSReadOnlyProperty('_unitsPerEM', 0),
39
41
 
40
42
  descriptorWithWeight: function(weight){
41
- return this;
43
+ return JSFontDescriptor.descriptorWithFamily(this.family, weight, this.style) || this;
42
44
  },
43
45
 
44
46
  descriptorWithStyle: function(style){
45
- return this;
47
+ return JSFontDescriptor.descriptorWithFamily(this.family, this.weight, style) || this;
46
48
  },
47
49
 
48
50
  glyphForCharacter: function(character){
@@ -89,6 +91,29 @@ JSClass("JSFontDescriptor", JSObject, {
89
91
 
90
92
  });
91
93
 
94
+ JSFontDescriptor.system = null;
95
+
96
+ JSFontDescriptor.descriptorsByFamily = {
97
+ };
98
+
99
+ JSFontDescriptor.registerDescriptor = function(descriptor){
100
+ if (!(descriptor._family in JSFontDescriptor.descriptorsByFamily)){
101
+ JSFontDescriptor.descriptorsByFamily[descriptor._family] = {};
102
+ }
103
+ if (!(descriptor._weight in JSFontDescriptor.descriptorsByFamily[descriptor._family])){
104
+ JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight] = {};
105
+ }
106
+ if (!(descriptor._style in JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight])){
107
+ JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight][descriptor._style] = descriptor;
108
+ }
109
+ };
110
+
111
+ JSFontDescriptor.descriptorWithFamily = function(family, weight, style){
112
+ var weights = JSFontDescriptor.descriptorsByFamily[family] || {};
113
+ var styles = weights[weight] || {};
114
+ return styles[style] || null;
115
+ };
116
+
92
117
  JSClass("JSDataFontDescriptor", JSFontDescriptor, {
93
118
 
94
119
  data: null,
@@ -131,23 +156,6 @@ JSClass("JSResourceFontDescriptor", JSFontDescriptor, {
131
156
  widths: null,
132
157
  };
133
158
  JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier] = this;
134
- if (!(this._family in JSResourceFontDescriptor.descriptorsByFamily)){
135
- JSResourceFontDescriptor.descriptorsByFamily[this._family] = {};
136
- }
137
- if (!(this._weight in JSResourceFontDescriptor.descriptorsByFamily[this._family])){
138
- JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight] = {};
139
- }
140
- if (!(this._style in JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight])){
141
- JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight][this._style] = this;
142
- }
143
- },
144
-
145
- descriptorWithWeight: function(weight){
146
- return JSResourceFontDescriptor.descriptorWithFamily(this.family, weight, this.style) || this;
147
- },
148
-
149
- descriptorWithStyle: function(style){
150
- return JSResourceFontDescriptor.descriptorWithFamily(this.family, this.weight, style) || this;
151
159
  },
152
160
 
153
161
  glyphForCharacter: function(character){
@@ -228,17 +236,87 @@ JSClass("JSResourceFontDescriptor", JSFontDescriptor, {
228
236
 
229
237
  });
230
238
 
231
- JSResourceFontDescriptor.descriptorWithFamily = function(family, weight, style){
232
- var weights = JSResourceFontDescriptor.descriptorsByFamily[family] || {};
233
- var styles = weights[weight] || {};
234
- return styles[style];
239
+ JSResourceFontDescriptor.descriptorsByName = {
235
240
  };
236
241
 
237
- JSResourceFontDescriptor.descriptorsByFamily = {
238
- };
242
+ JSClass("JSURLFontDescriptor", JSFontDescriptor, {
239
243
 
240
- JSResourceFontDescriptor.descriptorsByName = {
241
- };
244
+ url: null,
245
+
246
+ initWithURL: function(url, family, weight, style){
247
+ this.url = url;
248
+ this._family = family;
249
+ this._weight = weight;
250
+ this._style = style;
251
+ this._postScriptName = "%s-%s".sprintf(family.replace(" ", ""), this.face.replce(" ", ""));
252
+ // this._ascender
253
+ // this._descender
254
+ // this._unitsPerEM
255
+ },
256
+
257
+ getData: function(completion, target){
258
+ if (!completion){
259
+ completion = Promise.completion(Promise.rejectNonNullSecondArgument);
260
+ }
261
+ var session = JSURLSession.shared;
262
+ var task = session.dataTaskWithURL(this.url, function(error){
263
+ if (error !== null){
264
+ completion.call(target, null, error);
265
+ return;
266
+ }
267
+ try{
268
+ task.response.assertSuccess();
269
+ }catch (e){
270
+ completion.call(target, null, e);
271
+ return;
272
+ }
273
+ completion.call(target, task.response.data, null);
274
+ });
275
+ task.resume();
276
+ return completion.promise;
277
+ },
278
+
279
+ face: JSLazyInitProperty(function(){
280
+ if (this.weight === JSFont.Weight.regular){
281
+ if (this.style === JSFont.Style.italic){
282
+ return "Italic";
283
+ }
284
+ return "Regular";
285
+ }
286
+ var name = "";
287
+ switch (this.weight){
288
+ case JSFont.Weight.ultraLight:
289
+ name = "UltraLight";
290
+ break;
291
+ case JSFont.Weight.thin:
292
+ name = "Thin";
293
+ break;
294
+ case JSFont.Weight.light:
295
+ name = "Light";
296
+ break;
297
+ case JSFont.Weight.medium:
298
+ name = "Medium";
299
+ break;
300
+ case JSFont.Weight.semibold:
301
+ name = "SemiBold";
302
+ break;
303
+ case JSFont.Weight.bold:
304
+ name = "Bold";
305
+ break;
306
+ case JSFont.Weight.heavy:
307
+ name = "Heavy";
308
+ break;
309
+ case JSFont.Weight.black:
310
+ name = "Black";
311
+ break;
312
+ }
313
+ if (this.style === JSFont.Style.italic){
314
+ name += " Italic";
315
+ }
316
+ return name;
317
+ }),
318
+
319
+ });
242
320
 
243
321
  var CMap = function(format, data){
244
322
  if (this === undefined){
@@ -359,6 +359,34 @@ Object.defineProperties(String.prototype, {
359
359
  }
360
360
  },
361
361
 
362
+ utf16be: {
363
+ configurable: true,
364
+ enumerable: false,
365
+ value: function String_utf16be(){
366
+ var utf16 = JSData.initWithLength(this.length * 2);
367
+ var dataView = utf16.dataView();
368
+ var j = 0;
369
+ for (var i = 0, l = this.length; i < l; ++i, j += 2){
370
+ dataView.setUint16(j, this.charCodeAt(i));
371
+ }
372
+ return utf16;
373
+ }
374
+ },
375
+
376
+ utf16le: {
377
+ configurable: true,
378
+ enumerable: false,
379
+ value: function String_utf16le(){
380
+ var utf16 = JSData.initWithLength(this.length * 2);
381
+ var dataView = utf16.dataView();
382
+ var j = 0;
383
+ for (var i = 0, l = this.length; i < l; ++i, j += 2){
384
+ dataView.setUint16(j, this.charCodeAt(i), true);
385
+ }
386
+ return utf16;
387
+ }
388
+ },
389
+
362
390
  latin1: {
363
391
  enumerable: false,
364
392
  value: function String_latin1(){
@@ -387,6 +415,12 @@ Object.defineProperties(String.prototype, {
387
415
  if (encoding == String.Encoding.latin1){
388
416
  return this.latin1();
389
417
  }
418
+ if (encoding == String.Encoding.utf16be){
419
+ return this.utf16be();
420
+ }
421
+ if (encoding == String.Encoding.utf16le){
422
+ return this.utf16le();
423
+ }
390
424
  return null;
391
425
  }
392
426
  },
@@ -3,7 +3,7 @@ JSBundle.bundles['io.breakside.JSKit.Foundation'] = {
3
3
  "Info": {
4
4
  "JSBundleType": "framework",
5
5
  "JSBundleIdentifier": "io.breakside.JSKit.Foundation",
6
- "JSBundleVersion": "2022.22.3",
6
+ "JSBundleVersion": "2022.23.0",
7
7
  "JSDevelopmentLanguage": "en",
8
8
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
9
9
  "JSBundleEnvironments": {
@@ -11,7 +11,7 @@ JSBundle.bundles['io.breakside.JSKit.Foundation'] = {
11
11
  "node": "Foundation+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": "6f0b376edf61fbea02fd94b92f86de9e17d3b716"
14
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
15
15
  },
16
16
  "Resources": [
17
17
  {