Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit f43b3bb

Browse files
committed
copy external package files to local path
1 parent f3eb4c4 commit f43b3bb

8 files changed

+176
-15
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "pixi-richtext",
33
"version": "1.0.17",
44
"description": "A Rich Text solution for PixiJS using SDF.",
5-
"main": "dist/pixi.richtext.umd.js",
6-
"broswer": "dist/pixi.richtext.umd.js",
5+
"main": "dist/pixi.richtext.es5.js",
6+
"browser": "dist/pixi.richtext.umd.js",
77
"module": "dist/pixi.richtext.es5.js",
88
"scripts": {
99
"build": "BABEL_ENV=production rollup -c rollup.config.js",

rollup.config.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ const BANNER = `
1414
<%= pkg.name %> - v<%= pkg.version %>
1515
Compiled <%= moment().format() %>
1616
17+
@author <%= pkg.author %>
18+
19+
@license <%= pkg.license %>
1720
<%= pkg.name %> is licensed under the MIT License.
1821
http://www.opensource.org/licenses/mit-license
1922
`;
2023

2124
export default {
2225
input: `src/index.js`,
2326
output: [
24-
{ file: pkg.main, name: 'PIXI.RichText', format: 'umd' },
25-
{ file: pkg.module, format: 'es' },
27+
{ file: pkg.browser, name: 'PIXI.RichText', format: 'umd', sourcemap: true },
28+
{ file: pkg.module, format: 'es', sourcemap: true },
2629
],
27-
sourcemap: true,
2830
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
2931
external: ['pixi.js', 'pixi-gl-core'],
3032
globals: {
@@ -52,8 +54,7 @@ export default {
5254
// which external modules to include in the bundle
5355
// https://github.com/rollup/rollup-plugin-node-resolve#usage
5456
resolve({
55-
browser: true,
56-
preferBuiltins: false
57+
// browser: true
5758
}),
5859

5960
license({

src/lib/RichText.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// const PIXI = require('pixi.js');
2-
import PIXI from 'pixi.js';
2+
// import * as PIXI from 'pixi.js';
33
import { parseRichText } from './utils';
44
import TextStyle from './TextStyle';
55
import { getSDFConfig } from './SDFCache';

src/lib/RichTextRenderer.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// import ObjectRenderer from 'pixi.js/lib/core/renderers/webgl/utils/ObjectRenderer';
22
// import WebGLRenderer from 'pixi.js/lib/core/renderers/webgl/WebGLRenderer';
33
// const PIXI = require('pixi.js');
4-
import PIXI from 'pixi.js';
4+
// import * as PIXI from 'pixi.js';
55
const ObjectRenderer = PIXI.ObjectRenderer;
66
const WebGLRenderer = PIXI.WebGLRenderer;
7-
import createIndicesForQuads from 'pixi.js/lib/core/utils/createIndicesForQuads';
87
import generateMultiTextureShader from './generateMultiTextureShader';
9-
import checkMaxIfStatmentsInShader from 'pixi.js/lib/core/renderers/webgl/utils/checkMaxIfStatmentsInShader';
10-
import Buffer from 'pixi.js/lib/core/sprites/webgl/BatchBuffer';
11-
import settings from 'pixi.js/lib/core/settings';
8+
import createIndicesForQuads from './pixi-source/createIndicesForQuads';
9+
import checkMaxIfStatmentsInShader from './pixi-source/checkMaxIfStatmentsInShader';
10+
import BatchBuffer from './pixi-source/BatchBuffer';
11+
// import settings from 'pixi.js/lib/core/settings';
1212
// import glCore from 'pixi-gl-core';
1313
import bitTwiddle from 'bit-twiddle';
1414

1515
const glCore = PIXI.glCore;
16+
const settings = PIXI.settings;
1617

1718
let TICK = 0;
1819
let TEXTURE_TICK = 0;
@@ -64,7 +65,7 @@ export default class RichTextRenderer extends ObjectRenderer
6465
this.buffers = [];
6566
for (let i = 1; i <= bitTwiddle.nextPow2(this.size); i *= 2)
6667
{
67-
this.buffers.push(new Buffer(i * 4 * this.vertByteSize));
68+
this.buffers.push(new BatchBuffer(i * 4 * this.vertByteSize));
6869
}
6970

7071
/**

src/lib/generateMultiTextureShader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import Shader from '../../Shader';
22
// const PIXI = require('pixi.js');
3-
import PIXI from 'pixi.js';
3+
// import * as PIXI from 'pixi.js';
44
const Shader = PIXI.Shader;
55
// import { readFileSync } from 'fs';
66
// import { join } from 'path';

src/lib/pixi-source/BatchBuffer.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// pixi.js/lib/core/sprites/webgl/BatchBuffer
2+
3+
/**
4+
* @class
5+
* @memberof PIXI
6+
*/
7+
export default class Buffer
8+
{
9+
/**
10+
* @param {number} size - The size of the buffer in bytes.
11+
*/
12+
constructor(size)
13+
{
14+
this.vertices = new ArrayBuffer(size);
15+
16+
/**
17+
* View on the vertices as a Float32Array for positions
18+
*
19+
* @member {Float32Array}
20+
*/
21+
this.float32View = new Float32Array(this.vertices);
22+
23+
/**
24+
* View on the vertices as a Uint32Array for uvs
25+
*
26+
* @member {Float32Array}
27+
*/
28+
this.uint32View = new Uint32Array(this.vertices);
29+
}
30+
31+
/**
32+
* Destroys the buffer.
33+
*
34+
*/
35+
destroy()
36+
{
37+
this.vertices = null;
38+
this.positions = null;
39+
this.uvs = null;
40+
this.colors = null;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// pixi.js/lib/core/renderers/webgl/utils/checkMaxIfStatmentsInShader
2+
3+
const glCore = PIXI.glCore;
4+
5+
const fragTemplate = [
6+
'precision mediump float;',
7+
'void main(void){',
8+
'float test = 0.1;',
9+
'%forloop%',
10+
'gl_FragColor = vec4(0.0);',
11+
'}',
12+
].join('\n');
13+
14+
export default function checkMaxIfStatmentsInShader(maxIfs, gl)
15+
{
16+
const createTempContext = !gl;
17+
18+
// @if DEBUG
19+
if (maxIfs === 0)
20+
{
21+
throw new Error('Invalid value of `0` passed to `checkMaxIfStatementsInShader`');
22+
}
23+
// @endif
24+
25+
if (createTempContext)
26+
{
27+
const tinyCanvas = document.createElement('canvas');
28+
29+
tinyCanvas.width = 1;
30+
tinyCanvas.height = 1;
31+
32+
gl = glCore.createContext(tinyCanvas);
33+
}
34+
35+
const shader = gl.createShader(gl.FRAGMENT_SHADER);
36+
37+
while (true) // eslint-disable-line no-constant-condition
38+
{
39+
const fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs));
40+
41+
gl.shaderSource(shader, fragmentSrc);
42+
gl.compileShader(shader);
43+
44+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
45+
{
46+
maxIfs = (maxIfs / 2) | 0;
47+
}
48+
else
49+
{
50+
// valid!
51+
break;
52+
}
53+
}
54+
55+
if (createTempContext)
56+
{
57+
// get rid of context
58+
if (gl.getExtension('WEBGL_lose_context'))
59+
{
60+
gl.getExtension('WEBGL_lose_context').loseContext();
61+
}
62+
}
63+
64+
return maxIfs;
65+
}
66+
67+
function generateIfTestSrc(maxIfs)
68+
{
69+
let src = '';
70+
71+
for (let i = 0; i < maxIfs; ++i)
72+
{
73+
if (i > 0)
74+
{
75+
src += '\nelse ';
76+
}
77+
78+
if (i < maxIfs - 1)
79+
{
80+
src += `if(test == ${i}.0){}`;
81+
}
82+
}
83+
84+
return src;
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// createIndicesForQuads
2+
3+
/**
4+
* Generic Mask Stack data structure
5+
*
6+
* @memberof PIXI
7+
* @function createIndicesForQuads
8+
* @private
9+
* @param {number} size - Number of quads
10+
* @return {Uint16Array} indices
11+
*/
12+
export default function createIndicesForQuads(size)
13+
{
14+
// the total number of indices in our array, there are 6 points per quad.
15+
16+
const totalIndices = size * 6;
17+
18+
const indices = new Uint16Array(totalIndices);
19+
20+
// fill the indices with the quads to draw
21+
for (let i = 0, j = 0; i < totalIndices; i += 6, j += 4)
22+
{
23+
indices[i + 0] = j + 0;
24+
indices[i + 1] = j + 1;
25+
indices[i + 2] = j + 2;
26+
indices[i + 3] = j + 0;
27+
indices[i + 4] = j + 2;
28+
indices[i + 5] = j + 3;
29+
}
30+
31+
return indices;
32+
}

0 commit comments

Comments
 (0)