x_ite
Version:
X_ITE X3D Browser, view and manipulate X3D, VRML, glTF and other 3D sources in HTML.
1,451 lines (1,181 loc) • 551 kB
JavaScript
/* X_ITE v12.2.3 */
const __X_ITE_X3D__ = window [Symbol .for ("X_ITE.X3D-12.2.3")];
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 254:
/***/ ((module) => {
module.exports = __X_ITE_X3D__ .jquery;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/************************************************************************/
// UNUSED EXPORTS: default
;// external "__X_ITE_X3D__ .Components"
const external_X_ITE_X3D_Components_namespaceObject = __X_ITE_X3D__ .Components;
var external_X_ITE_X3D_Components_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Components_namespaceObject);
;// external "__X_ITE_X3D__ .Fields"
const external_X_ITE_X3D_Fields_namespaceObject = __X_ITE_X3D__ .Fields;
var external_X_ITE_X3D_Fields_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Fields_namespaceObject);
;// external "__X_ITE_X3D__ .X3DFieldDefinition"
const external_X_ITE_X3D_X3DFieldDefinition_namespaceObject = __X_ITE_X3D__ .X3DFieldDefinition;
var external_X_ITE_X3D_X3DFieldDefinition_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_X3DFieldDefinition_namespaceObject);
;// external "__X_ITE_X3D__ .FieldDefinitionArray"
const external_X_ITE_X3D_FieldDefinitionArray_namespaceObject = __X_ITE_X3D__ .FieldDefinitionArray;
var external_X_ITE_X3D_FieldDefinitionArray_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_FieldDefinitionArray_namespaceObject);
;// external "__X_ITE_X3D__ .X3DNode"
const external_X_ITE_X3D_X3DNode_namespaceObject = __X_ITE_X3D__ .X3DNode;
var external_X_ITE_X3D_X3DNode_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_X3DNode_namespaceObject);
;// external "__X_ITE_X3D__ .X3DUrlObject"
const external_X_ITE_X3D_X3DUrlObject_namespaceObject = __X_ITE_X3D__ .X3DUrlObject;
var external_X_ITE_X3D_X3DUrlObject_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_X3DUrlObject_namespaceObject);
;// external "__X_ITE_X3D__ .Namespace"
const external_X_ITE_X3D_Namespace_namespaceObject = __X_ITE_X3D__ .Namespace;
var external_X_ITE_X3D_Namespace_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Namespace_namespaceObject);
;// ./src/x_ite/Browser/Text/TextAlignment.js
let i = 0;
const TextAlignment =
{
BEGIN: ++ i,
FIRST: ++ i,
MIDDLE: ++ i,
END: ++ i,
};
const __default__ = TextAlignment;
;
/* harmony default export */ const Text_TextAlignment = (external_X_ITE_X3D_Namespace_default().add ("TextAlignment", __default__));
;// external "__X_ITE_X3D__ .X3DConstants"
const external_X_ITE_X3D_X3DConstants_namespaceObject = __X_ITE_X3D__ .X3DConstants;
var external_X_ITE_X3D_X3DConstants_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_X3DConstants_namespaceObject);
;// external "__X_ITE_X3D__ .URLs"
const external_X_ITE_X3D_URLs_namespaceObject = __X_ITE_X3D__ .URLs;
var external_X_ITE_X3D_URLs_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_URLs_namespaceObject);
;// ./src/x_ite/Components/Text/X3DFontStyleNode.js
/* provided dependency */ var $ = __webpack_require__(254);
/*
* Font paths for default SERIF, SANS and TYPEWRITER families.
*/
const Fonts = new Map ([
["SERIF", new Map ([
["PLAIN", external_X_ITE_X3D_URLs_default().getFontsURL ("Droid/DroidSerif-Regular.woff2")],
["ITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Droid/DroidSerif-Italic.woff2")],
["BOLD", external_X_ITE_X3D_URLs_default().getFontsURL ("Droid/DroidSerif-Bold.woff2")],
["BOLDITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Droid/DroidSerif-BoldItalic.woff2")],
])],
["SANS", new Map ([
["PLAIN", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/Ubuntu-R.woff2")],
["ITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/Ubuntu-RI.woff2")],
["BOLD", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/Ubuntu-B.woff2")],
["BOLDITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/Ubuntu-BI.woff2")],
])],
["TYPEWRITER", new Map ([
["PLAIN", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/UbuntuMono-R.woff2")],
["ITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/UbuntuMono-RI.woff2")],
["BOLD", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/UbuntuMono-B.woff2")],
["BOLDITALIC", external_X_ITE_X3D_URLs_default().getFontsURL ("Ubuntu/UbuntuMono-BI.woff2")],
])],
]);
function X3DFontStyleNode (executionContext)
{
// To be of type X3DUrlObject ensures that it will work inside StaticGroup
// and legacy implementation of load URLs over family field.
external_X_ITE_X3D_X3DNode_default().call (this, executionContext);
external_X_ITE_X3D_X3DUrlObject_default().call (this, executionContext);
this .addType ((external_X_ITE_X3D_X3DConstants_default()).X3DFontStyleNode);
this .addChildObjects ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "description", new (external_X_ITE_X3D_Fields_default()).SFString (),
(external_X_ITE_X3D_X3DConstants_default()).inputOutput, "url", new (external_X_ITE_X3D_Fields_default()).MFString (),
(external_X_ITE_X3D_X3DConstants_default()).inputOutput, "load", new (external_X_ITE_X3D_Fields_default()).SFBool (true),
(external_X_ITE_X3D_X3DConstants_default()).inputOutput, "autoRefresh", new (external_X_ITE_X3D_Fields_default()).SFTime (0),
(external_X_ITE_X3D_X3DConstants_default()).inputOutput, "autoRefreshTimeLimit", new (external_X_ITE_X3D_Fields_default()).SFTime (3600));
this .alignments = [ ];
}
Object .assign (Object .setPrototypeOf (X3DFontStyleNode .prototype, (external_X_ITE_X3D_X3DNode_default()).prototype),
(external_X_ITE_X3D_X3DUrlObject_default()).prototype,
{
initialize ()
{
external_X_ITE_X3D_X3DNode_default().prototype .initialize .call (this);
external_X_ITE_X3D_X3DUrlObject_default().prototype .initialize .call (this);
this ._family .addInterest ("set_url__", this);
this ._style .addInterest ("set_url__", this);
this ._justify .addInterest ("set_justify__", this);
// Don't call set_style__.
this .set_justify__ ();
this .requestImmediateLoad () .catch (Function .prototype);
},
set_justify__ ()
{
const majorNormal = this ._horizontal .getValue () ? this ._leftToRight .getValue () : this ._topToBottom .getValue ();
this .alignments [0] = this ._justify .length > 0
? this .getAlignment (0, majorNormal)
: majorNormal ? Text_TextAlignment .BEGIN : Text_TextAlignment .END;
const minorNormal = this ._horizontal .getValue () ? this ._topToBottom .getValue () : this ._leftToRight .getValue ();
this .alignments [1] = this ._justify .length > 1
? this .getAlignment (1, minorNormal)
: minorNormal ? Text_TextAlignment .FIRST : Text_TextAlignment .END;
},
getAllowEmptyUrl ()
{
return true;
},
getFont ()
{
return this .font;
},
getDefaultFont (fontFamily, fontStyle)
{
const family = Fonts .get (fontFamily);
return family ?.get (fontStyle) ?? family ?.get ("PLAIN");
},
getMajorAlignment ()
{
return this .alignments [0];
},
getMinorAlignment ()
{
return this .alignments [1];
},
getAlignment (index, normal)
{
if (normal)
{
// Return for west-european normal alignment.
switch (this ._justify [index])
{
case "FIRST": return Text_TextAlignment .FIRST;
case "BEGIN": return Text_TextAlignment .BEGIN;
case "MIDDLE": return Text_TextAlignment .MIDDLE;
case "END": return Text_TextAlignment .END;
}
}
else
{
// Return appropriate alignment if topToBottom or leftToRight are FALSE.
switch (this ._justify [index])
{
case "FIRST": return Text_TextAlignment .END;
case "BEGIN": return Text_TextAlignment .END;
case "MIDDLE": return Text_TextAlignment .MIDDLE;
case "END": return Text_TextAlignment .BEGIN;
}
}
return index ? Text_TextAlignment .FIRST : Text_TextAlignment .BEGIN;
},
async loadData ()
{
// Wait for FontLibrary nodes to be setuped or changed.
await $.sleep (0);
// Add default font to family array.
const
browser = this .getBrowser (),
executionContext = this .getExecutionContext (),
family = this ._family .copy (),
fontStyle = this ._style .getValue ();
family .push ("SERIF");
this .font = null;
for (const fontFamily of family)
{
// Try to get default font at first to protect these font families.
const defaultFont = this .getDefaultFont (fontFamily, fontStyle);
if (defaultFont)
{
const font = await browser .loadFont (new URL (defaultFont), true);
if (font)
{
this .font = font;
break;
}
}
// Try to get font from family names.
const font = await browser .getFont (executionContext, fontFamily, fontStyle);
if (font)
{
this .font = font;
break;
}
// DEPRECIATED: Try to get font by URL.
const fileURL = new URL (fontFamily, executionContext .getBaseURL ());
if (fileURL .protocol === "data:" || fileURL .pathname .match (/\.(?:woff2|woff|otf|ttf)$/i))
{
if (executionContext .getSpecificationVersion () >= 4.1)
console .warn (`Loading a font file via family field is depreciated, please use new FontLibrary node instead.`);
const font = await browser .loadFont (fileURL, this .getCache ());
if (font)
{
this .font = font;
break;
}
}
else
{
console .warn (`Couldn't find font family '${fontFamily}' with style '${fontStyle}'.`);
}
}
this .setLoadState (this .font ? (external_X_ITE_X3D_X3DConstants_default()).COMPLETE_STATE : (external_X_ITE_X3D_X3DConstants_default()).FAILED_STATE);
this .addNodeEvent ();
},
dispose ()
{
external_X_ITE_X3D_X3DUrlObject_default().prototype .dispose .call (this);
external_X_ITE_X3D_X3DNode_default().prototype .dispose .call (this);
},
});
Object .defineProperties (X3DFontStyleNode, external_X_ITE_X3D_X3DNode_default().getStaticProperties ("X3DFontStyleNode", "Text", 1));
const X3DFontStyleNode_default_ = X3DFontStyleNode;
;
/* harmony default export */ const Text_X3DFontStyleNode = (external_X_ITE_X3D_Namespace_default().add ("X3DFontStyleNode", X3DFontStyleNode_default_));
;// external "__X_ITE_X3D__ .PrimitiveQuality"
const external_X_ITE_X3D_PrimitiveQuality_namespaceObject = __X_ITE_X3D__ .PrimitiveQuality;
var external_X_ITE_X3D_PrimitiveQuality_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_PrimitiveQuality_namespaceObject);
;// external "__X_ITE_X3D__ .TextCompression"
const external_X_ITE_X3D_TextCompression_namespaceObject = __X_ITE_X3D__ .TextCompression;
var external_X_ITE_X3D_TextCompression_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_TextCompression_namespaceObject);
;// external "__X_ITE_X3D__ .Box2"
const external_X_ITE_X3D_Box2_namespaceObject = __X_ITE_X3D__ .Box2;
var external_X_ITE_X3D_Box2_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Box2_namespaceObject);
;// external "__X_ITE_X3D__ .Box3"
const external_X_ITE_X3D_Box3_namespaceObject = __X_ITE_X3D__ .Box3;
var external_X_ITE_X3D_Box3_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Box3_namespaceObject);
;// external "__X_ITE_X3D__ .Vector2"
const external_X_ITE_X3D_Vector2_namespaceObject = __X_ITE_X3D__ .Vector2;
var external_X_ITE_X3D_Vector2_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Vector2_namespaceObject);
;// external "__X_ITE_X3D__ .Vector3"
const external_X_ITE_X3D_Vector3_namespaceObject = __X_ITE_X3D__ .Vector3;
var external_X_ITE_X3D_Vector3_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Vector3_namespaceObject);
;// external "__X_ITE_X3D__ .Matrix3"
const external_X_ITE_X3D_Matrix3_namespaceObject = __X_ITE_X3D__ .Matrix3;
var external_X_ITE_X3D_Matrix3_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Matrix3_namespaceObject);
;// ./src/x_ite/Browser/Text/X3DTextGeometry.js
const
bbox = new (external_X_ITE_X3D_Box2_default()) (),
lineBBox = new (external_X_ITE_X3D_Box2_default()) (),
min = new (external_X_ITE_X3D_Vector2_default()) (),
max = new (external_X_ITE_X3D_Vector2_default()) (),
glyphMin = new (external_X_ITE_X3D_Vector2_default()) (),
glyphMax = new (external_X_ITE_X3D_Vector2_default()) (),
min3 = new (external_X_ITE_X3D_Vector3_default()) (),
max3 = new (external_X_ITE_X3D_Vector3_default()) (),
size = new (external_X_ITE_X3D_Vector2_default()) (),
center = new (external_X_ITE_X3D_Vector2_default()) (),
size1_2 = new (external_X_ITE_X3D_Vector2_default()) (),
translation1 = new (external_X_ITE_X3D_Vector2_default()) (),
translation2 = new (external_X_ITE_X3D_Vector2_default()) (),
lineBound = new (external_X_ITE_X3D_Vector2_default()) (),
origin = new (external_X_ITE_X3D_Vector3_default()) (),
box2 = new (external_X_ITE_X3D_Box2_default()) (),
zero2 = new (external_X_ITE_X3D_Vector2_default()) (),
zero3 = new (external_X_ITE_X3D_Vector3_default()) ();
function X3DTextGeometry (text, fontStyle)
{
this .browser = text .getBrowser ();
this .text = text;
this .fontStyle = fontStyle;
this .glyphs = [ ];
this .minorAlignment = new (external_X_ITE_X3D_Vector2_default()) ();
this .lineIndices = [ ];
this .translations = [ ];
this .charSpacings = [ ];
this .scales = [ ];
this .bearing = new (external_X_ITE_X3D_Vector2_default()) ();
this .bbox = new (external_X_ITE_X3D_Box3_default()) ();
}
Object .assign (X3DTextGeometry .prototype,
{
getBrowser ()
{
return this .browser;
},
getText ()
{
return this .text;
},
getFontStyle ()
{
return this .fontStyle;
},
getGlyphs ()
{
return this .glyphs;
},
getMinorAlignment ()
{
return this .minorAlignment;
},
getTranslations ()
{
return this .translations;
},
getCharSpacings ()
{
return this .charSpacings;
},
getScales ()
{
return this .scales;
},
getBearing ()
{
return this .bearing;
},
getBBox ()
{
return this .bbox;
},
update ()
{
const
text = this .text,
fontStyle = this .fontStyle,
numLines = text ._string .length;
text ._lineBounds .length = numLines;
this .glyphs .length = 0;
if (numLines === 0 || !fontStyle .getFont ())
{
text ._origin .setValue (zero3);
text ._textBounds .setValue (zero2);
this .bbox .set ();
return;
}
if (fontStyle ._horizontal .getValue ())
{
this .resizeArray (this .translations, numLines);
this .lineIndices .length = 0;
this .charSpacings .length = numLines;
this .scales .length = numLines;
this .horizontal (text, fontStyle);
}
else
{
const
string = text ._string,
numChars = string .reduce ((p, c) => p + c .length, 0);
this .resizeArray (this .translations, numChars);
this .lineIndices .length = numChars;
this .charSpacings .length = numLines;
this .scales .length = numLines;
this .vertical (text, fontStyle);
}
},
resizeArray (array, size)
{
// Resize array in grow only fashion.
for (let i = array .length; i < size; ++ i)
array .push (new (external_X_ITE_X3D_Vector2_default()) ());
array .length = size;
},
horizontal (text, fontStyle)
{
const
font = fontStyle .getFont (),
string = text ._string,
numLines = string .length,
maxExtent = Math .max (0, text ._maxExtent .getValue ()),
topToBottom = fontStyle ._topToBottom .getValue (),
scale = fontStyle .getScale (),
contentScale = fontStyle .getContentScale (),
spacing = fontStyle ._spacing .getValue (),
textCompression = this .getBrowser () .getBrowserOptions () .getTextCompression ();
bbox .set ();
// Calculate bboxes.
const
first = topToBottom ? 0 : numLines - 1,
last = topToBottom ? numLines : -1,
step = topToBottom ? 1 : -1;
for (let l = first, ll = 0; l !== last; l += step, ++ ll)
{
const line = string [l];
// Get line extents.
const glyphs = this .getHorizontalLineExtents (fontStyle, line, min, max, ll);
size .assign (max) .subtract (min);
// Calculate charSpacing and lineBounds.
const
length = text .getLength (l) * contentScale,
w = size .x * scale;
let charSpacing = 0;
lineBound .set (w, ll == 0 ? max .y - font .descender / font .unitsPerEm * scale : spacing);
if (length)
{
if (textCompression === (external_X_ITE_X3D_TextCompression_default()).CHAR_SPACING && glyphs .length > 1)
charSpacing = (length - lineBound .x) / (glyphs .length - 1);
lineBound .x = length;
size .x = length / scale;
}
this .charSpacings [ll] = charSpacing;
this .scales [ll] = textCompression === (external_X_ITE_X3D_TextCompression_default()).SCALING ? lineBound .x / w : 1;
text ._lineBounds [l] = lineBound;
// Calculate line translation.
switch (fontStyle .getMajorAlignment ())
{
case Text_TextAlignment .BEGIN:
case Text_TextAlignment .FIRST:
this .translations [ll] .set (0, -ll * spacing);
break;
case Text_TextAlignment .MIDDLE:
this .translations [ll] .set (-min .x - size .x / 2, -ll * spacing);
break;
case Text_TextAlignment .END:
this .translations [ll] .set (-min .x - size .x, -ll * spacing);
break;
}
this .translations [ll] .multiply (scale);
// Calculate center.
center .assign (min) .add (size1_2 .assign (size) .divide (2));
// Add bbox.
bbox .add (box2 .set (size .multiply (scale), center .multiply (scale) .add (this .translations [ll])));
}
if (maxExtent)
{
const extent = text ._lineBounds .reduce ((p, c) => Math .max (p, c .x), 0);
if (extent > maxExtent)
{
const s = (maxExtent * contentScale) / extent;
switch (textCompression)
{
case (external_X_ITE_X3D_TextCompression_default()).CHAR_SPACING:
{
for (const i of this .charSpacings .keys ())
{
if (text ._string [i] .length < 2)
continue;
this .charSpacings [i] -= (text ._lineBounds [i] .x - text ._lineBounds [i] .x * s)
/ (text ._string [i] .length - 1);
}
break;
}
case (external_X_ITE_X3D_TextCompression_default()).SCALING:
{
for (const i of this .scales .keys ())
this .scales [i] *= s;
break;
}
}
for (const i of this .translations .keys ())
this .translations [i] .x *= s;
for (const i of text ._lineBounds .keys ())
text ._lineBounds [i] .x *= s;
bbox .multRight (new (external_X_ITE_X3D_Matrix3_default()) (s,0,0, 0,1,0, 0,0,0));
}
}
//console .log ("size", bbox .size, "center", bbox .center);
// Get text extents.
bbox .getExtents (min, max);
size .assign (max) .subtract (min);
// Calculate text position
text ._textBounds = size;
this .bearing .set (0, -max .y);
switch (fontStyle .getMinorAlignment ())
{
case Text_TextAlignment .BEGIN:
this .minorAlignment .assign (this .bearing);
break;
case Text_TextAlignment .FIRST:
this .minorAlignment .set (0);
break;
case Text_TextAlignment .MIDDLE:
this .minorAlignment .set (0, size .y / 2 - max .y);
break;
case Text_TextAlignment .END:
this .minorAlignment .set (0, (numLines - 1) * spacing * scale);
break;
}
// Translate bbox by minorAlignment.
min .add (this .minorAlignment);
max .add (this .minorAlignment);
// The value of the origin field represents the upper left corner of the textBounds.
text ._origin .setValue (origin .set (min .x, max .y, 0));
this .bbox .setExtents (min3 .set (min .x, min .y, 0),
max3 .set (max .x, max .y, 0));
},
vertical (text, fontStyle)
{
const
font = fontStyle .getFont (),
string = text ._string,
numLines = string .length,
maxExtent = Math .max (0, text ._maxExtent .getValue ()),
leftToRight = fontStyle ._leftToRight .getValue (),
topToBottom = fontStyle ._topToBottom .getValue (),
scale = fontStyle .getScale (),
contentScale = fontStyle .getContentScale (),
spacing = fontStyle ._spacing .getValue (),
primitiveQuality = this .getBrowser () .getBrowserOptions () .getPrimitiveQuality (),
textCompression = this .getBrowser () .getBrowserOptions () .getTextCompression ();
bbox .set ();
// Calculate bboxes.
const
firstL = leftToRight ? 0 : numLines - 1,
lastL = leftToRight ? numLines : -1,
stepL = leftToRight ? 1 : -1;
let t = 0; // Translation index
for (let l = firstL; l !== lastL; l += stepL)
{
const glyphs = this .stringToGlyphs (font, string [l], true, l);
const
t0 = t,
numChars = glyphs .length;
// Calculate line bbox
lineBBox .set ();
const
firstG = topToBottom ? 0 : numChars - 1,
lastG = topToBottom ? numChars : -1,
stepG = topToBottom ? 1 : -1;
for (let g = firstG; g !== lastG; g += stepG, ++ t)
{
const glyph = glyphs [g];
// Get glyph extents.
this .getGlyphExtents (font, glyph, primitiveQuality, min, max);
size .assign (max) .subtract (min);
// Calculate glyph translation
const glyphNumber = topToBottom ? g : numChars - g - 1;
this .lineIndices [t] = l;
this .translations [t] .set ((spacing - size .x - min .x) / 2, -glyphNumber);
// Calculate center.
center .assign (min) .add (size1_2 .assign (size) .divide (2)) .add (this .translations [t]);
// Add bbox.
lineBBox .add (box2 .set (size, center));
}
// Get line extents.
lineBBox .getExtents (min, max);
size .assign (max) .subtract (min);
// Calculate charSpacing and lineBounds.
const
lineNumber = leftToRight ? l : numLines - l - 1,
padding = (spacing - size .x) / 2,
length = text .getLength (l) * contentScale;
let charSpacing = 0;
lineBound .set (l === 0 ? spacing - padding : spacing, numChars ? size .y : 0) .multiply (scale);
const h = lineBound .y;
if (length)
{
switch (textCompression)
{
case (external_X_ITE_X3D_TextCompression_default()).CHAR_SPACING:
{
if (glyphs .length > 1)
charSpacing = (length - lineBound .y) / (glyphs .length - 1);
break;
}
case (external_X_ITE_X3D_TextCompression_default()).SCALING:
{
if (fontStyle .getMajorAlignment () === Text_TextAlignment .MIDDLE)
max .y += (length - lineBound .y) / 2;
break;
}
}
lineBound .y = length;
size .y = length / scale;
min .y = max .y - size .y;
}
this .charSpacings [l] = charSpacing;
this .scales [l] = textCompression === (external_X_ITE_X3D_TextCompression_default()).SCALING ? lineBound .y / h : 1;
text ._lineBounds [l] = lineBound;
// Calculate line translation.
switch (fontStyle .getMajorAlignment ())
{
case Text_TextAlignment .BEGIN:
case Text_TextAlignment .FIRST:
translation2 .assign (translation1 .set (lineNumber * spacing, -max .y));
break;
case Text_TextAlignment .MIDDLE:
translation2 .assign (translation1 .set (lineNumber * spacing, (size .y / 2 - max .y)));
break;
case Text_TextAlignment .END:
{
translation1 .set (lineNumber * spacing, (size .y / this .scales [l] - max .y));
translation2 .set (lineNumber * spacing, (size .y - max .y));
break;
}
}
// Calculate glyph translation
for (let tt = t0; tt < t; ++ tt)
this .translations [tt] .add (translation1) .multiply (scale);
// Calculate center.
center .assign (min) .add (size1_2 .assign (size) .divide (2));
// Add bbox.
bbox .add (box2 .set (size .multiply (scale), center .add (translation2) .multiply (scale)));
}
if (maxExtent)
{
const extent = text ._lineBounds .reduce ((p, c) => Math .max (p, c .y), 0);
if (extent > maxExtent)
{
const s = (maxExtent * contentScale) / extent;
switch (textCompression)
{
case (external_X_ITE_X3D_TextCompression_default()).CHAR_SPACING:
{
for (const i of this .charSpacings .keys ())
{
if (text ._string [i] .length < 2)
continue;
this .charSpacings [i] -= (text ._lineBounds [i] .y - text ._lineBounds [i] .y * s)
/ (text ._string [i] .length - 1);
}
switch (fontStyle .getMajorAlignment ())
{
case Text_TextAlignment .MIDDLE:
{
for (const t of this .translations .keys ())
{
const l = this .lineIndices [t];
this .translations [t] .y -= (text ._lineBounds [l] .y - text ._lineBounds [l] .y * s) / 2;
}
break;
}
case Text_TextAlignment .END:
{
for (const t of this .translations .keys ())
{
const l = this .lineIndices [t];
this .translations [t] .y -= (text ._lineBounds [l] .y - text ._lineBounds [l] .y * s);
}
break;
}
}
break;
}
case (external_X_ITE_X3D_TextCompression_default()).SCALING:
{
for (const i of this .scales .keys ())
this .scales [i] *= s;
break;
}
}
for (const i of text ._lineBounds .keys ())
text ._lineBounds [i] .y *= s;
bbox .multRight (new (external_X_ITE_X3D_Matrix3_default()) (1,0,0, 0,s,0, 0,0,0));
}
}
// Get text extents.
bbox .getExtents (min, max);
size .assign (max) .subtract (min);
// Calculate text position
text ._textBounds = size;
switch (fontStyle .getMajorAlignment ())
{
case Text_TextAlignment .BEGIN:
case Text_TextAlignment .FIRST:
this .bearing .set (-min .x, max .y);
break;
case Text_TextAlignment .MIDDLE:
this .bearing .set (-min .x, 0);
break;
case Text_TextAlignment .END:
this .bearing .set (-min .x, min .y);
break;
}
switch (fontStyle .getMinorAlignment ())
{
case Text_TextAlignment .BEGIN:
case Text_TextAlignment .FIRST:
this .minorAlignment .set (-min .x, 0);
break;
case Text_TextAlignment .MIDDLE:
this .minorAlignment .set (-min .x - size .x / 2, 0);
break;
case Text_TextAlignment .END:
this .minorAlignment .set (-min .x - size .x, 0);
break;
}
// Translate bbox by minorAlignment.
min .add (this .minorAlignment);
max .add (this .minorAlignment);
// The value of the origin field represents the upper left corner of the textBounds.
text ._origin .setValue (origin .set (min .x, max .y, 0));
this .bbox .setExtents (min3 .set (min .x, min .y, 0),
max3 .set (max .x, max .y, 0));
},
stringToGlyphs (font, line, normal, lineNumber)
{
const glyphs = this .glyphs [lineNumber]
?? (this .glyphs [lineNumber] = [ ]);
glyphs .length = line .length;
const
first = normal ? 0 : line .length - 1,
last = normal ? line .length : -1,
step = normal ? 1 : -1;
for (let c = first, g = 0; c !== last; c += step, ++ g)
glyphs [g] = font .charToGlyph (line [c]);
return glyphs;
},
getHorizontalLineExtents (fontStyle, line, min, max, lineNumber)
{
const
font = fontStyle .getFont (),
normal = fontStyle ._horizontal .getValue () ? fontStyle ._leftToRight .getValue () : fontStyle ._topToBottom .getValue (),
glyphs = this .stringToGlyphs (font, line, normal, lineNumber),
numGlyphs = glyphs .length,
primitiveQuality = this .getBrowser () .getBrowserOptions () .getPrimitiveQuality ();
let
xMin = 0,
xMax = 0,
yMin = Number .POSITIVE_INFINITY,
yMax = Number .NEGATIVE_INFINITY;
for (let g = 0; g < numGlyphs; ++ g)
{
const
glyph = glyphs [g],
nextGlyph = glyphs [g + 1],
kerning = nextGlyph ? font .getKerningValue (glyph, nextGlyph) : 0;
this .getGlyphExtents (font, glyph, primitiveQuality, glyphMin, glyphMax);
xMax += g < numGlyphs - 1 ? glyph .advanceWidth + kerning : glyphMax .x * font .unitsPerEm;
yMin = Math .min (yMin, glyphMin .y);
yMax = Math .max (yMax, glyphMax .y);
}
if (glyphs .length)
{
this .getGlyphExtents (font, glyphs [0], primitiveQuality, glyphMin, glyphMax);
xMin = glyphMin .x;
}
else
{
yMin = 0;
yMax = 0;
}
min .set (xMin, yMin);
max .set (xMax / font .unitsPerEm, yMax);
switch (fontStyle .getMajorAlignment ())
{
case Text_TextAlignment .BEGIN:
case Text_TextAlignment .FIRST:
min .x = 0;
break;
}
return glyphs;
},
traverse (type, renderObject)
{ },
});
const X3DTextGeometry_default_ = X3DTextGeometry;
;
/* harmony default export */ const Text_X3DTextGeometry = (external_X_ITE_X3D_Namespace_default().add ("X3DTextGeometry", X3DTextGeometry_default_));
;// external "__X_ITE_X3D__ .Matrix4"
const external_X_ITE_X3D_Matrix4_namespaceObject = __X_ITE_X3D__ .Matrix4;
var external_X_ITE_X3D_Matrix4_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Matrix4_namespaceObject);
;// external "__X_ITE_X3D__ .Bezier"
const external_X_ITE_X3D_Bezier_namespaceObject = __X_ITE_X3D__ .Bezier;
var external_X_ITE_X3D_Bezier_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_Bezier_namespaceObject);
;// external "__X_ITE_X3D__ .libtess"
const external_X_ITE_X3D_libtess_namespaceObject = __X_ITE_X3D__ .libtess;
var external_X_ITE_X3D_libtess_default = /*#__PURE__*/__webpack_require__.n(external_X_ITE_X3D_libtess_namespaceObject);
;// ./src/x_ite/Browser/Text/PolygonText.js
const _glyphCache = Symbol ();
function PolygonText (text, fontStyle)
{
Text_X3DTextGeometry .call (this, text, fontStyle);
text .setTransparent (false);
}
Object .assign (Object .setPrototypeOf (PolygonText .prototype, Text_X3DTextGeometry .prototype),
{
getMatrix ()
{
return (external_X_ITE_X3D_Matrix4_default()).IDENTITY;
},
build: (() =>
{
const
min = new (external_X_ITE_X3D_Vector3_default()) (),
max = new (external_X_ITE_X3D_Vector3_default()) ();
return function ()
{
const
fontStyle = this .getFontStyle (),
font = fontStyle .getFont ();
if (!font)
return;
const
text = this .getText (),
glyphs = this .getGlyphs (),
minorAlignment = this .getMinorAlignment (),
translations = this .getTranslations (),
charSpacings = this .getCharSpacings (),
scales = this .getScales (),
size = fontStyle .getScale (),
spacing = fontStyle ._spacing .getValue (),
origin = text ._origin .getValue (),
sizeUnitsPerEm = size / font .unitsPerEm,
primitiveQuality = this .getBrowser () .getBrowserOptions () .getPrimitiveQuality (),
texCoordArray = text .getTexCoords (),
normalArray = text .getNormals (),
vertexArray = text .getVertices ();
// Set texCoords.
text .getMultiTexCoords () .push (texCoordArray);
this .getBBox () .getExtents (min, max);
text .getMin () .assign (min);
text .getMax () .assign (max);
if (fontStyle ._horizontal .getValue ())
{
for (let l = 0, length = glyphs .length; l < length; ++ l)
{
const
line = glyphs [l],
translation = translations [l],
charSpacing = charSpacings [l],
scale = scales [l];
let advanceWidth = 0;
for (let g = 0, gl = line .length; g < gl; ++ g)
{
const
glyph = line [g],
glyphVertices = this .getGlyphGeometry (font, glyph, primitiveQuality),
xOffset = minorAlignment .x + translation .x + advanceWidth * scale + g * charSpacing,
yOffset = minorAlignment .y + translation .y;
for (const { x: glyphX, y: glyphY } of glyphVertices)
{
const
x = glyphX * size * scale + xOffset,
y = glyphY * size + yOffset;
texCoordArray .push ((x - origin .x) / spacing, (y - origin .y) / spacing, 0, 1);
normalArray .push (0, 0, 1);
vertexArray .push (x, y, 0, 1);
}
// Calculate advanceWidth.
let kerning = 0;
if (g + 1 < line .length)
kerning = font .getKerningValue (glyph, line [g + 1]);
advanceWidth += (glyph .advanceWidth + kerning) * sizeUnitsPerEm;
}
}
}
else
{
const
leftToRight = fontStyle ._leftToRight .getValue (),
topToBottom = fontStyle ._topToBottom .getValue (),
first = leftToRight ? 0 : text ._string .length - 1,
last = leftToRight ? text ._string .length : -1,
step = leftToRight ? 1 : -1;
for (let l = first, t = 0; l !== last; l += step)
{
const
line = glyphs [l],
numChars = line .length,
firstG = topToBottom ? 0 : numChars - 1,
lastG = topToBottom ? numChars : -1,
stepG = topToBottom ? 1 : -1,
charSpacing = charSpacings [l],
scale = scales [l];
for (let g = firstG; g !== lastG; g += stepG, ++ t)
{
const
translation = translations [t],
glyphVertices = this .getGlyphGeometry (font, line [g], primitiveQuality);
for (const { x: glyphX, y: glyphY } of glyphVertices)
{
const
glyphNumber = topToBottom ? g : numChars - g - 1,
x = glyphX * size + minorAlignment .x + translation .x,
y = glyphY * size * scale + minorAlignment .y + translation .y * scale - glyphNumber * charSpacing;
texCoordArray .push ((x - origin .x) / spacing, (y - origin .y) / spacing, 0, 1);
normalArray .push (0, 0, 1);
vertexArray .push (x, y, 0, 1);
}
}
}
}
};
})(),
getGlyph (font, primitiveQuality, glyphIndex)
{
const
cachedFont = font [_glyphCache] ??= [ ],
cachedQuality = cachedFont [primitiveQuality] ??= [ ],
cachedGlyph = cachedQuality [glyphIndex] ??= { };
return cachedGlyph;
},
getGlyphExtents (font, glyph, primitiveQuality, min, max)
{
const
glyphCache = this .getGlyph (font, primitiveQuality, glyph .index),
extents = glyphCache .extents;
if (extents)
{
min .assign (extents .min);
max .assign (extents .max);
}
else
{
const vertices = this .getGlyphGeometry (font, glyph, primitiveQuality);
if (vertices .length)
{
min .assign (vertices [0]) .min (... vertices);
max .assign (vertices [0]) .max (... vertices);
}
else
{
min .set (0);
max .set (0);
}
const extents = glyphCache .extents = { };
extents .min = min .copy ();
extents .max = max .copy ();
}
},
getGlyphGeometry (font, glyph, primitiveQuality)
{
const glyphCache = this .getGlyph (font, primitiveQuality, glyph .index);
return glyphCache .geometry ??= this .createGlyphGeometry (glyph, primitiveQuality);
},
createGlyphGeometry (glyph, primitiveQuality)
{
// Get contours for the current glyph.
const
steps = this .getBezierSteps (primitiveQuality),
path = glyph .getPath (0, 0, 1),
contours = [ ],
vertices = [ ];
let
points = [ ],
x = 0,
y = 0;
// Fix add missing Z command, to make sure the last contour is added.
path .commands .push ({ type: "Z" });
for (const { type, x1, y1, x2, y2, x: cx, y: cy } of path .commands)
{
switch (type)
{
case "M": // Start
case "Z": // End
{
if (points .length > 2)
contours .push (points);
points = [ ];
if (type === "M")
points .push (new (external_X_ITE_X3D_Vector3_default()) (cx, -cy, 0));
break;
}
case "L": // Linear
{
points .push (new (external_X_ITE_X3D_Vector3_default()) (cx, -cy, 0));
break;
}
case "Q": // Quadric
{
external_X_ITE_X3D_Bezier_default().quadric (x, -y, 0, x1, -y1, 0, cx, -cy, 0, steps, points);
break;
}
case "C": // Cubic
{
external_X_ITE_X3D_Bezier_default().cubic (x, -y, 0, x1, -y1, 0, x2, -y2, 0, cx, -cy, 0, steps, points);
break;
}
default:
continue;
}
x = cx;
y = cy;
}
return this .triangulatePolygon (contours, vertices);
},
getBezierSteps (primitiveQuality)
{
switch (primitiveQuality)
{
case (external_X_ITE_X3D_PrimitiveQuality_default()).LOW:
return 3;
case (external_X_ITE_X3D_PrimitiveQuality_default()).HIGH:
return 7;
default:
return 5;
}
},
triangulatePolygon: (() =>
{
// Function called for each vertex of tessellator output.
function vertexCallback (point, triangles)
{
triangles .push (point);
}
function combineCallback (coords, data, weight)
{
return new (external_X_ITE_X3D_Vector3_default()) (... coords);
}
const tessy = new (external_X_ITE_X3D_libtess_default()).GluTesselator ();
tessy .gluTessCallback ((external_X_ITE_X3D_libtess_default()).gluEnum .GLU_TESS_VERTEX_DATA, vertexCallback);
tessy .gluTessCallback ((external_X_ITE_X3D_libtess_default()).gluEnum .GLU_TESS_COMBINE, combineCallback);
tessy .gluTessProperty ((external_X_ITE_X3D_libtess_default()).gluEnum .GLU_TESS_WINDING_RULE, (external_X_ITE_X3D_libtess_default()).windingRule .GLU_TESS_WINDING_NONZERO);
tessy .gluTessNormal (0, 0, 1);
return function (contours, triangles)
{
tessy .gluTessBeginPolygon (triangles);
for (const points of contours)
{
tessy .gluTessBeginContour ();
for (const point of points)
tessy .gluTessVertex (point, point);
tessy .gluTessEndContour ();
}
tessy .gluTessEndPolygon ();
return triangles;
};
})(),
displaySimple (gl, renderContext)
{ },
display (gl, renderContext)
{ },
transformLine (line)
{ },
transformMatrix (matrix)
{ },
});
const PolygonText_default_ = PolygonText;
;
/* harmony default export */ const Text_PolygonText = (external_X_ITE_X3D_Namespace_default().add ("PolygonText", PolygonText_default_));
;// ./src/x_ite/Components/Text/FontStyle.js
function FontStyle (executionContext)
{
Text_X3DFontStyleNode .call (this, executionContext);
this .addType ((external_X_ITE_X3D_X3DConstants_default()).FontStyle);
// Units
this ._size .setUnit ("length");
}
Object .assign (Object .setPrototypeOf (FontStyle .prototype, Text_X3DFontStyleNode .prototype),
{
getTextGeometry (text)
{
return new Text_PolygonText (text, this);
},
getScale ()
{
return this ._size .getValue ();
},
getContentScale ()
{
return 1;
},
});
Object .defineProperties (FontStyle,
{
... external_X_ITE_X3D_X3DNode_default().getStaticProperties ("FontStyle", "Text", 1, "fontStyle", "2.0"),
fieldDefinitions:
{
value: new (external_X_ITE_X3D_FieldDefinitionArray_default()) ([
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "metadata", new (external_X_ITE_X3D_Fields_default()).SFNode ()),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "language", new (external_X_ITE_X3D_Fields_default()).SFString ()),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "family", new (external_X_ITE_X3D_Fields_default()).MFString ("SERIF")),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "style", new (external_X_ITE_X3D_Fields_default()).SFString ("PLAIN")),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "size", new (external_X_ITE_X3D_Fields_default()).SFFloat (1)),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "spacing", new (external_X_ITE_X3D_Fields_default()).SFFloat (1)),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "horizontal", new (external_X_ITE_X3D_Fields_default()).SFBool (true)),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "leftToRight", new (external_X_ITE_X3D_Fields_default()).SFBool (true)),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "topToBottom", new (external_X_ITE_X3D_Fields_default()).SFBool (true)),
new (external_X_ITE_X3D_X3DFieldDefinition_default()) ((external_X_ITE_X3D_X3DConstants_default()).inputOutput, "justify", new (external_X_ITE_X3D_Fields_default()).MFString ("BEGIN")),
]),
enumerable: true,
},
});
const FontStyle_default_ = FontStyle;
;
/* harmony default export */ const Text_FontStyle = (external_X_ITE_X3D_Namespace_default().add ("FontStyle", FontStyle_default_));
;// ./src/lib/opentype/opentype.mjs
// src/tiny-inflate@1.0.3.esm.mjs
var TINF_OK = 0;
var TINF_DATA_ERROR = -3;
function Tree() {
this.table = new Uint16Array(16);
this.trans = new Uint16Array(288);
}
function Data(source, dest) {
this.source = source;
this.sourceIndex = 0;
this.tag = 0;
this.bitcount = 0;
this.dest = dest;
this.destLen = 0;
this.ltree = new Tree();
this.dtree = new Tree();
}
var sltree = new Tree();
var sdtree = new Tree();
var length_bits = new Uint8Array(30);
var length_base = new Uint16Array(30);
var dist_bits = new Uint8Array(30);
var dist_base = new Uint16Array(30);
var clcidx = new Uint8Array([
16,
17,
18,
0,
8,
7,
9,
6,
10,
5,
11,
4,
12,
3,
13,
2,
14,
1,
15
]);
var code_tree = new Tree();
var lengths = new Uint8Array(288 + 32);
function tinf_build_bits_base(bits, base, delta, first) {
var i, sum;
for (i = 0; i < delta; ++i) bits[i] = 0;
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta | 0;
for (sum = first, i = 0; i < 30; ++i) {
base[i] = sum;
sum += 1 << bits[i];
}
}
function tinf_build_fixed_trees(lt, dt) {
var i;